> For the complete documentation index, see [llms.txt](/llms.txt)

# GS2-Enhance Deploy/CDK Reference

The template format used when creating stacks with GS2-Deploy, and implementation examples of template output in various languages using CDK




## Entities

Resources managed by the Deploy operation

### Namespace

Namespace

A Namespace allows multiple independent instances of the same service within a single project by separating data spaces and usage contexts.
Each GS2 service is managed on a per-namespace basis. Even when using the same service, if the Namespace differs, the data is treated as a completely independent data space.

Therefore, you must create a Namespace before you can start using each service.

#### Request

Resource creation and update requests

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓|  |  ~ 128 chars | Namespace name<br>Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.). |
| description | string |  | |  |  ~ 1024 chars | Description |
| transactionSettingV2 | [TransactionSettingV2](#transactionsettingv2) |  | |  |  | Transaction Setting (V2)<br>Decides how the transactions this Namespace issues are executed. There are only two things to set: the GS2-Distributor Namespace that executes them, and whether the actions in a transaction run one at a time -- so that a later action can build on what an earlier one wrote -- or all at once for a shorter response time.<br>Set this on a new Namespace. `transactionSetting`, the obsolete setting it replaces, is used only while this is unset. |
| enhanceScript | [ScriptSetting](#scriptsetting) |  | |  |  | Script setting to be executed at the time of enhancement<br>Script Trigger Reference - [`enhance`](../script/#enhance) |
| logSetting | [LogSetting](#logsetting) |  | |  |  | Log Output Setting<br>Configuration for outputting log data of enhancement operations to GS2-Log. By specifying a GS2-Log Namespace, API request and response logs for enhancement and limit break operations can be collected. |

#### GetAttr

Resource creation results that can be retrieved using the [!GetAttr](/articles/tech/deploy/#getattr) tag

| | Type | Description |
| --- | --- | --- |
| Item | [Namespace](../sdk#namespace) | Namespace created

#### Implementation Example




**GS2-Deploy(YAML)**
```yaml

Type: GS2::Enhance::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSettingV2: null
  EnhanceScript: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001

```

**Go**
```go

import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/enhance"
)


SampleStack := core.NewStack()
enhance.NewNamespace(
    &SampleStack,
    "namespace-0001",
    enhance.NamespaceOptions{
        LogSetting: &core.LogSetting{
            LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
        },
    },
)

println(SampleStack.Yaml())  // Generate Template

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Enhance\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Enhance\Model\Options\NamespaceOptions(
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.enhance.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.enhance.model.options.NamespaceOptions()
                        .withLogSetting(new io.gs2.cdk.core.model.LogSetting(
                            "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                        ))
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Enhance.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Enhance.Model.Options.NamespaceOptions
            {
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

```

**TypeScript**
```typescript

import core from "@/gs2cdk/core";
import enhance from "@/gs2cdk/enhance";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new enhance.model.Namespace(
            this,
            "namespace-0001",
            {
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template

```

**Python**
```python

from gs2_cdk import Stack, core, enhance

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        enhance.Namespace(
            stack=self,
            name='namespace-0001',
            options=enhance.NamespaceOptions(
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template

```


### TransactionSettingV2

Transaction Setting (V2)

Transaction Setting (V2) decides how the transactions issued by a Namespace are executed.

There are only two things to set:

- `distributorNamespaceId`: the GS2-Distributor Namespace used to execute the transaction
- `enableParallelExecution`: whether the actions in a transaction run one at a time or all at once

Whichever you choose, the transaction is executed by the server the moment it is issued, and it succeeds or fails as a whole: when an action fails, the actions that already ran are undone with it and nothing is left applied. Everything else about how a transaction runs is fixed to the recommended configuration, so there is nothing else to set.

Running the actions one at a time (the default, `enableParallelExecution` is `false`) lets each action work on top of what the actions before it wrote. The actions run in verify, consume, acquire order, and this is what lets you:

- update the same row from more than one action in a single transaction, which fails when they run all at once
- read what an earlier action wrote, including from List and Query and from inside a nested transaction
- use `%{Gs2Xxx:ActionName.path[0].field}` to feed the result of an earlier verify or consume action into the parameters of a later verify, consume or acquire action

In exchange, the response time is the sum of the time taken by each action, and a transaction may contain at most 20 actions. The order within each phase is decided by the action name and then by the target resource, so you cannot choose the execution order by rearranging the actions in the request, and execution stops at the first action that fails.

Running the actions all at once (`enableParallelExecution` is `true`) executes them in parallel against a single snapshot of the data, so the response time is that of the slowest single action and there is no limit on the number of actions.

In exchange, an action cannot see what the other actions wrote, and two actions that write the same row fail the transaction with `database:transaction:same.resource` (400), so choose this only when you can guarantee that no two actions in the same transaction write the same data. `%{...}` may reference only the results of an earlier phase (verify, then consume, then acquire); a reference to an action in the same phase is left unresolved, and a phase that contains `%{...}` waits for the earlier phases to complete, which lengthens the response time by that amount.

Transaction Setting is the obsolete setting that Transaction Setting (V2) replaces, kept for Namespaces created before Transaction Setting (V2) existed. It applies only while Transaction Setting (V2) is unset, and setting Transaction Setting (V2) supersedes it. Three behaviours it allowed are deliberately not offered here: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, and folding acquire actions into GS2-JobQueue.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| distributorNamespaceId | string |  |  | "grn:gs2:{region}:{ownerId}:distributor:default" |  ~ 1024 chars | GS2-Distributor Namespace GRN used to execute transactions |
| enableParallelExecution | bool |  |  | false |  | Whether to execute the actions in parallel instead of sequentially |

### ScriptSetting

Script Setting

In GS2, you can associate custom scripts with microservice events and execute them.
This model holds the settings for triggering script execution.

There are two main ways to execute a script: synchronous execution and asynchronous execution.
Because synchronous execution blocks processing until the script finishes executing,
you can use the script result to stop the API execution or control the API response.

In contrast, asynchronous execution does not block processing until the script has finished executing.
However, because the script result cannot be used to stop the API execution or modify the API response,
asynchronous execution does not affect the API response flow and is generally recommended.

There are two types of asynchronous execution methods: GS2-Script and Amazon EventBridge.
By using Amazon EventBridge, you can write processing in languages other than Lua.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| triggerScriptId | string |  |  |  |  ~ 1024 chars | GS2-Script script GRN executed synchronously when the API is executed<br>Must be specified in GRN format starting with "grn:gs2:". |
| doneTriggerTargetType | string (enum)<br>enum {<br>"none",<br>"gs2_script",<br>"aws"<br>}<br> |  |  | "none" |  | Asynchronous script execution method<br>Specifies the type of script to use for asynchronous execution.<br>You can choose from "Do not use an asynchronous execution script (none)", "Use GS2-Script (gs2_script)", and "Use Amazon EventBridge (aws)".none: None / gs2_script: GS2-Script / aws: Amazon EventBridge /  |
| doneTriggerScriptId | string | {doneTriggerTargetType} == "gs2_script" |  |  |  ~ 1024 chars | GS2-Script script GRN for asynchronous execution<br>Must be specified in GRN format starting with "grn:gs2:".<br>* Enabled only if doneTriggerTargetType is "gs2_script" |
| doneTriggerQueueNamespaceId | string | {doneTriggerTargetType} == "gs2_script" |  |  |  ~ 1024 chars | GS2-JobQueue Namespace GRN used to execute asynchronous scripts<br>If you want to execute asynchronous execution scripts via GS2-JobQueue instead of executing them directly, specify the GS2-JobQueue Namespace GRN.<br>GS2-JobQueue is generally not required unless you have a specific reason to use it.<br>* Enabled only if doneTriggerTargetType is "gs2_script" |

### LogSetting

Log Output Setting

Log Output Setting defines how log data is exported. This type holds the GS2-Log Namespace identifier (Namespace ID), which is used to export log data.
Specify the GS2-Log Namespace where log data is collected and stored in the GRN format for the Log Namespace ID (loggingNamespaceId).
Configuring this setting ensures that log data for API requests and responses occurring within the specified Namespace is output to the target GS2-Log Namespace.
GS2-Log provides real-time logs that can be used for system monitoring, analysis, debugging, and other operational purposes.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| loggingNamespaceId | string |  | ✓ |  |  ~ 1024 chars | GS2-Log Namespace GRN to output logs<br>Must be specified in GRN format starting with "grn:gs2:". |

### TransactionSetting

Transaction Setting

Transaction Setting is obsolete: Transaction Setting (V2) replaces it. It is kept for Namespaces created before Transaction Setting (V2) existed, applies only while Transaction Setting (V2) is unset, and should not be chosen for a new Namespace.

It exposes each part of transaction execution as a separate field -- AutoRun, AtomicCommit, asynchronous execution using GS2-Distributor, batch application of script results, asynchronous processing of acquire actions via GS2-JobQueue, and sequential execution -- so combinations other than the recommended one can be built. Transaction Setting (V2) is that recommended combination expressed as a single setting. Keep using Transaction Setting only on a Namespace that already depends on a behaviour Transaction Setting (V2) does not offer: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, or folding acquire actions into GS2-JobQueue.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| enableAutoRun | bool |  |  | false |  | Whether to automatically execute issued transactions on the server side |
| enableAtomicCommit | bool | {enableAutoRun} == true |  | false |  | Whether to commit transactions atomically<br>* Enabled only if enableAutoRun is true |
| transactionUseDistributor | bool | {enableAtomicCommit} == true |  | false |  | Whether to execute transactions asynchronously<br>* Enabled only if enableAtomicCommit is true |
| commitScriptResultInUseDistributor | bool | {transactionUseDistributor} == true |  | false |  | Whether to execute the commit processing of the script result asynchronously<br>* Enabled only if transactionUseDistributor is true |
| acquireActionUseJobQueue | bool | {enableAtomicCommit} == true |  | false |  | Whether to use GS2-JobQueue to execute the acquire action<br>* Enabled only if enableAtomicCommit is true |
| enableSequentialExecution | bool | {enableAtomicCommit} == true |  | false |  | Whether to execute the actions of an atomic commit sequentially so that multiple actions may update the same row<br>* Enabled only if enableAtomicCommit is true |
| distributorNamespaceId | string |  |  | "grn:gs2:{region}:{ownerId}:distributor:default" |  ~ 1024 chars | GS2-Distributor Namespace GRN used to execute transactions |
| queueNamespaceId | string |  |  | "grn:gs2:{region}:{ownerId}:queue:default" |  ~ 1024 chars | GS2-JobQueue Namespace GRN used to execute transactions |

---

### CurrentRateMaster

Currently active Rate Model master data

This master data defines the Rate Models currently active within the Namespace.
GS2 uses JSON format files for master data management.
By uploading the file, the settings can actually be reflected on the server.

To create JSON files, we provide a master data editor within the management console.
Additionally, you can utilize the service by creating tools more suited to game operations and exporting JSON files in the appropriate format.
**ℹ️ Note**

Please refer to [GS2-Enhance Master Data Reference](api_reference/enhance/master_data/) for the JSON file format.

#### Request

Resource creation and update requests

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| namespaceName | string |  | ✓|  |  ~ 128 chars | Namespace name<br>Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.). |
| mode | string (enum)<br>enum {<br>"direct",<br>"preUpload"<br>}<br> |  | | "direct" |  | Update modedirect: Directly update master data / preUpload: Upload master data and then update /  |
| settings | string | {mode} == "direct" | ✓*|  |  ~ 5242880 bytes (5MB) | Master Data<br>* Required if mode is "direct" |
| uploadToken | string | {mode} == "preUpload" | ✓*|  |  ~ 1024 chars | Token obtained by pre-upload<br>Used to apply the uploaded master data.<br>* Required if mode is "preUpload" |

#### GetAttr

Resource creation results that can be retrieved using the [!GetAttr](/articles/tech/deploy/#getattr) tag

| | Type | Description |
| --- | --- | --- |
| Item | [CurrentRateMaster](../sdk#currentratemaster) | Updated master data of the currently active Rate Models

#### Implementation Example




**GS2-Deploy(YAML)**
```yaml

Type: GS2::Enhance::CurrentRateMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2020-08-22",
    "rateModels": [
      {
        "name": "character-friendly",
        "targetInventoryModelId": "grn:inventory:character",
        "acquireExperienceSuffix": ":friendly",
        "materialInventoryModelId": "grn:inventory:sweet",
        "experienceModelId": "grn:experience:friendly",
        "metadata": "CHARACTER_FRIENDLY",
        "acquireExperienceHierarchy": [
          "taste"
        ],
        "bonusRates": [
          {
            "rate": 1,
            "weight": 90
          }
        ]
      },
      {
        "name": "character-level",
        "targetInventoryModelId": "grn:inventory:character",
        "acquireExperienceSuffix": ":level",
        "materialInventoryModelId": "grn:inventory:material",
        "experienceModelId": "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
        "metadata": "CHARACTER_LEVEL",
        "acquireExperienceHierarchy": [
          "experience"
        ],
        "bonusRates": [
          {
            "rate": 1,
            "weight": 90
          },
          {
            "rate": 1.5,
            "weight": 9
          },
          {
            "rate": 2,
            "weight": 1
          }
        ]
      }
    ],
    "unleashRateModels": [
    ]
  }
  UploadToken: null

```

**Go**
```go

import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/enhance"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
enhance.NewNamespace(
    &SampleStack,
    "namespace-0001",
    enhance.NamespaceOptions{},
).MasterData(
    []enhance.RateModel{
        enhance.NewRateModel(
            "character-friendly",
            "grn:inventory:character",
            ":friendly",
            "grn:inventory:sweet",
            "grn:experience:friendly",
            enhance.RateModelOptions{
                Metadata: pointy.String("CHARACTER_FRIENDLY"),
                AcquireExperienceHierarchy: []string{
                    "taste",
                },
                BonusRates: []enhance.BonusRate{
                    enhance.NewBonusRate(
                        1,
                        90,
                        enhance.BonusRateOptions{},
                    ),
                },
            },
        ),
        enhance.NewRateModel(
            "character-level",
            "grn:inventory:character",
            ":level",
            "grn:inventory:material",
            "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
            enhance.RateModelOptions{
                Metadata: pointy.String("CHARACTER_LEVEL"),
                AcquireExperienceHierarchy: []string{
                    "experience",
                },
                BonusRates: []enhance.BonusRate{
                    enhance.NewBonusRate(
                        1,
                        90,
                        enhance.BonusRateOptions{},
                    ),
                    enhance.NewBonusRate(
                        1.5,
                        9,
                        enhance.BonusRateOptions{},
                    ),
                    enhance.NewBonusRate(
                        2,
                        1,
                        enhance.BonusRateOptions{},
                    ),
                },
            },
        ),
    },
    []enhance.UnleashRateModel{
    },
)

println(SampleStack.Yaml())  // Generate Template

```

**PHP**
```php

class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Enhance\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Enhance\Model\RateModel(
                    name:"character-friendly",
                    targetInventoryModelId:"grn:inventory:character",
                    acquireExperienceSuffix:":friendly",
                    materialInventoryModelId:"grn:inventory:sweet",
                    experienceModelId:"grn:experience:friendly",
                    options: new \Gs2Cdk\Enhance\Model\Options\RateModelOptions(
                        metadata:"CHARACTER_FRIENDLY",
                        acquireExperienceHierarchy:[
                            "taste",
                        ],
                        bonusRates:[
                            new \Gs2Cdk\Enhance\Model\BonusRate(
                                rate: 1,
                                weight: 90,
                            ),
                        ]
                    )
                ),
                new \Gs2Cdk\Enhance\Model\RateModel(
                    name:"character-level",
                    targetInventoryModelId:"grn:inventory:character",
                    acquireExperienceSuffix:":level",
                    materialInventoryModelId:"grn:inventory:material",
                    experienceModelId:"grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
                    options: new \Gs2Cdk\Enhance\Model\Options\RateModelOptions(
                        metadata:"CHARACTER_LEVEL",
                        acquireExperienceHierarchy:[
                            "experience",
                        ],
                        bonusRates:[
                            new \Gs2Cdk\Enhance\Model\BonusRate(
                                rate: 1,
                                weight: 90,
                            ),
                            new \Gs2Cdk\Enhance\Model\BonusRate(
                                rate: 1.5,
                                weight: 9,
                            ),
                            new \Gs2Cdk\Enhance\Model\BonusRate(
                                rate: 2,
                                weight: 1,
                            ),
                        ]
                    )
                )
            ],
            [
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template

```

**Java**
```java

class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.enhance.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.enhance.model.RateModel(
                    "character-friendly",
                    "grn:inventory:character",
                    ":friendly",
                    "grn:inventory:sweet",
                    "grn:experience:friendly",
                    new io.gs2.cdk.enhance.model.options.RateModelOptions()
                        .withMetadata("CHARACTER_FRIENDLY")
                        .withAcquireExperienceHierarchy(Arrays.asList(
                            "taste"
                        ))
                        .withBonusRates(Arrays.asList(
                            new io.gs2.cdk.enhance.model.BonusRate(
                                1f,
                                90
                            )
                        ))
                ),
                new io.gs2.cdk.enhance.model.RateModel(
                    "character-level",
                    "grn:inventory:character",
                    ":level",
                    "grn:inventory:material",
                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
                    new io.gs2.cdk.enhance.model.options.RateModelOptions()
                        .withMetadata("CHARACTER_LEVEL")
                        .withAcquireExperienceHierarchy(Arrays.asList(
                            "experience"
                        ))
                        .withBonusRates(Arrays.asList(
                            new io.gs2.cdk.enhance.model.BonusRate(
                                1f,
                                90
                            ),
                            new io.gs2.cdk.enhance.model.BonusRate(
                                1.5f,
                                9
                            ),
                            new io.gs2.cdk.enhance.model.BonusRate(
                                2f,
                                1
                            )
                        ))
                )
            ),
            Arrays.asList(
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template

```

**C#**
```csharp

public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Enhance.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Enhance.Model.RateModel[] {
                new Gs2Cdk.Gs2Enhance.Model.RateModel(
                    name: "character-friendly",
                    targetInventoryModelId: "grn:inventory:character",
                    acquireExperienceSuffix: ":friendly",
                    materialInventoryModelId: "grn:inventory:sweet",
                    experienceModelId: "grn:experience:friendly",
                    options: new Gs2Cdk.Gs2Enhance.Model.Options.RateModelOptions
                    {
                        metadata = "CHARACTER_FRIENDLY",
                        acquireExperienceHierarchy = new string[]
                        {
                            "taste"
                        },
                        bonusRates = new Gs2Cdk.Gs2Enhance.Model.BonusRate[]
                        {
                            new Gs2Cdk.Gs2Enhance.Model.BonusRate(
                                rate: 1f,
                                weight: 90
                            )
                        }
                    }
                ),
                new Gs2Cdk.Gs2Enhance.Model.RateModel(
                    name: "character-level",
                    targetInventoryModelId: "grn:inventory:character",
                    acquireExperienceSuffix: ":level",
                    materialInventoryModelId: "grn:inventory:material",
                    experienceModelId: "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
                    options: new Gs2Cdk.Gs2Enhance.Model.Options.RateModelOptions
                    {
                        metadata = "CHARACTER_LEVEL",
                        acquireExperienceHierarchy = new string[]
                        {
                            "experience"
                        },
                        bonusRates = new Gs2Cdk.Gs2Enhance.Model.BonusRate[]
                        {
                            new Gs2Cdk.Gs2Enhance.Model.BonusRate(
                                rate: 1f,
                                weight: 90
                            ),
                            new Gs2Cdk.Gs2Enhance.Model.BonusRate(
                                rate: 1.5f,
                                weight: 9
                            ),
                            new Gs2Cdk.Gs2Enhance.Model.BonusRate(
                                rate: 2f,
                                weight: 1
                            )
                        }
                    }
                )
            },
            new Gs2Cdk.Gs2Enhance.Model.UnleashRateModel[] {
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template

```

**TypeScript**
```typescript

import core from "@/gs2cdk/core";
import enhance from "@/gs2cdk/enhance";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new enhance.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new enhance.model.RateModel(
                    "character-friendly",
                    "grn:inventory:character",
                    ":friendly",
                    "grn:inventory:sweet",
                    "grn:experience:friendly",
                    {
                        metadata: "CHARACTER_FRIENDLY",
                        acquireExperienceHierarchy: [
                            "taste",
                        ],
                        bonusRates: [
                            new enhance.model.BonusRate(
                                1,
                                90
                            ),
                        ]
                    }
                ),
                new enhance.model.RateModel(
                    "character-level",
                    "grn:inventory:character",
                    ":level",
                    "grn:inventory:material",
                    "grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level",
                    {
                        metadata: "CHARACTER_LEVEL",
                        acquireExperienceHierarchy: [
                            "experience",
                        ],
                        bonusRates: [
                            new enhance.model.BonusRate(
                                1,
                                90
                            ),
                            new enhance.model.BonusRate(
                                1.5,
                                9
                            ),
                            new enhance.model.BonusRate(
                                2,
                                1
                            ),
                        ]
                    }
                )
            ],
            [
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template

```

**Python**
```python

from gs2_cdk import Stack, core, enhance

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        enhance.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            rate_models=[
                enhance.RateModel(
                    name='character-friendly',
                    target_inventory_model_id='grn:inventory:character',
                    acquire_experience_suffix=':friendly',
                    material_inventory_model_id='grn:inventory:sweet',
                    experience_model_id='grn:experience:friendly',
                    options=enhance.RateModelOptions(
                        metadata = 'CHARACTER_FRIENDLY',
                        acquire_experience_hierarchy = [
                            'taste',
                        ],
                        bonus_rates = [
                            enhance.BonusRate(
                                rate=1,
                                weight=90,        
                            ),
                        ]
                    ),
                ),
                enhance.RateModel(
                    name='character-level',
                    target_inventory_model_id='grn:inventory:character',
                    acquire_experience_suffix=':level',
                    material_inventory_model_id='grn:inventory:material',
                    experience_model_id='grn:gs2:ap-northeast-1:YourOwnerId:experience:namespace-0001:model:level',
                    options=enhance.RateModelOptions(
                        metadata = 'CHARACTER_LEVEL',
                        acquire_experience_hierarchy = [
                            'experience',
                        ],
                        bonus_rates = [
                            enhance.BonusRate(
                                rate=1,
                                weight=90,        
                            ),
                            enhance.BonusRate(
                                rate=1.5,
                                weight=9,        
                            ),
                            enhance.BonusRate(
                                rate=2,
                                weight=1,        
                            ),
                        ]
                    ),
                ),
            ],
            unleash_rate_models=[
            ],
        )

print(SampleStack().yaml())  # Generate Template

```


### RateModel

Enhancement Rate Model

The enhancement rate is data that defines the materials used for enhancement and the target of enhancement.

Both material data and enhancement target data must be managed in GS2-Inventory.
The experience value obtained from the enhancement is recorded in GS2-Inventory metadata in JSON format.
Here, it is necessary to describe at which level of the metadata the experience value is stored.

A correction value can be applied to the amount of experience value that can be obtained with a certain probability of `great success` during enhancement.
The probability of that draw is also defined in this entity.

`targetInventoryModelId` specifies the inventory model that holds the items to be enhanced, and `materialInventoryModelId` the inventory model that holds the items usable as material.
These can be separate inventory models, so an arrangement in which characters are the target and enhancement-only items are the material is possible.

The experience each material grants is written in the metadata of its item model, and `acquireExperienceHierarchy` tells GS2-Enhance where in that JSON it is stored.
For a structure such as `{ "aaa": { "bbb": { "experienceValue": 100 } } }`, specify `[ "aaa", "bbb", "experienceValue" ]`. Up to 10 levels can be specified.

The gained experience is added to GS2-Experience, on the experience model specified by `experienceModelId`.
The property ID it is added to is the property ID of the target item with `acquireExperienceSuffix` appended, so a single item can hold several kinds of experience, such as `level` for the character level and `like` for affection.

`bonusRates` defines a weighted draw over the bonus multipliers applied to the gained experience.
Each entry holds a multiplier (1.5 meaning 150%) and a draw weight, one entry is chosen by weighted draw on each enhancement, and up to 1,000 entries can be registered.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| rateModelId | string |  | * |  |  ~ 1024 chars | Enhancement Rate Model GRN<br>* Set automatically by the server |
| name | string |  | ✓ |  |  ~ 128 chars | Enhancement Rate Model name<br>Unique Enhancement Rate Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.). |
| description | string |  |  |  |  ~ 1024 chars | Description |
| metadata | string |  |  |  |  ~ 2048 chars | Metadata<br>Arbitrary values can be set in the metadata.<br>Since they do not affect GS2’s behavior, they can be used to store information used in the game. |
| targetInventoryModelId | string |  | ✓ |  |  ~ 1024 chars | GS2-Inventory Inventory Model GRN usable for enhancement targets<br>Specifies the GS2-Inventory inventory model that holds the items eligible for enhancement. The item to be enhanced must belong to this inventory model. |
| acquireExperienceSuffix | string |  | ✓ |  |  ~ 1024 chars | Suffix to be assigned to the property ID that stores the experience value obtained from GS2-Experience<br>A string appended to the item's property ID to form the GS2-Experience property ID where experience is stored. This allows the same item to have multiple experience types (e.g., "level" for character level, "like" for affinity). |
| materialInventoryModelId | string |  | ✓ |  |  ~ 1024 chars | GS2-Inventory Inventory Model GRN usable as enhancement material<br>Specifies the GS2-Inventory inventory model that holds the items usable as enhancement materials. The experience value each material provides is defined in the item model's metadata using the JSON hierarchy specified by acquireExperienceHierarchy. |
| acquireExperienceHierarchy | List&lt;string&gt; |  |  |  | 0 ~ 10 items | Hierarchical structure of JSON data defining acquisition experience values to be stored in ItemModel metadata<br>GS2-Enhance features a mechanism that works in conjunction with GS2-Inventory to perform enhancements. It sets the experience value when used as enhancement material in JSON format within the ItemModel metadata.<br>For example, to define metadata with a structure like: { “aaa”: { “bbb”: { “experienceValue”: 100 } } } Specify it as: [ “aaa”, ‘bbb’, “experienceValue” ]<br>Details are explained in the [Microservices Introduction / GS2-Enhance](/microservices/enhance/#enhancement-rate) section. |
| experienceModelId | string |  | ✓ |  |  ~ 1024 chars | GS2-Experience Experience Model GRN gained as a result of enhancement<br>Specifies the GS2-Experience experience model where the experience points obtained from enhancement are recorded. The experience is added to the property identified by combining the target item's property ID with the acquireExperienceSuffix. |
| bonusRates | [List&lt;BonusRate&gt;](#bonusrate) |  |  |  | 0 ~ 1000 items | Experience gain bonus<br>Defines a weighted lottery for bonus experience multipliers during enhancement. Each entry specifies a multiplier (e.g., 1.5 for 150%) and a draw weight. When enhancement is performed, one entry is selected by weighted lottery to determine whether a "great success" bonus applies to the experience gained. |

### BonusRate

Experience Gain Bonus

Defines a single entry in the weighted lottery for determining the experience bonus multiplier during enhancement. By configuring multiple entries with different rates and weights, you can implement "great success" or "super success" mechanics with controlled probabilities.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| rate | float |  |  | 1.0 | 0 ~ 10000 | Experience bonus multiplier (1.0 = no bonus)<br>The multiplier applied to the base experience value when this entry is drawn. A value of 1.0 means normal enhancement with no bonus, 1.5 means 150% experience (great success), 2.0 means 200% experience (super success), and so on. |
| weight | int |  |  | 1 | 0 ~ 2147483645 | Lottery weight<br>The relative weight used in the weighted lottery when selecting the bonus rate. Higher values increase the probability of this bonus rate being selected. The actual probability is this weight divided by the sum of all weights in the bonus rate list. |

### UnleashRateModel

Unleash Rate Model

Defines the conditions for limit breaking (unleashing) items.

A limit break here is an enhancement that raises the grade managed by GS2-Grade by consuming duplicates of the same item as material.
Raising the grade raises the rank cap on the GS2-Experience side, which lets the target be grown to a higher level.

`targetInventoryModelId` specifies the GS2-Inventory inventory model that holds the items eligible for a limit break.
Both the item being unleashed and the duplicates consumed as material must belong to this inventory model.
`gradeModelId` specifies the GS2-Grade grade model that tracks the grade of the target item; the grade is raised by 1 on a successful limit break.

`gradeEntries` defines, for each grade, how many duplicates must be consumed to reach it, and between 1 and 1,000 entries can be registered.
Setting, for example, 1 duplicate for grade 1 and 3 duplicates for grade 2 lets you control the cost of each limit break step individually.

A resource consumed as material is discarded together with whatever it held.
Even when the material holds experience or other resources, they are not carried over to the target, so convert them into a resource for handover beforehand if that is required.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| unleashRateModelId | string |  | * |  |  ~ 1024 chars | Unleash Rate Model GRN<br>* Set automatically by the server |
| name | string |  | ✓ |  |  ~ 128 chars | Unleash Rate Model name<br>Unique Unleash Rate Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.). |
| description | string |  |  |  |  ~ 1024 chars | Description |
| metadata | string |  |  |  |  ~ 2048 chars | Metadata<br>Arbitrary values can be set in the metadata.<br>Since they do not affect GS2’s behavior, they can be used to store information used in the game. |
| targetInventoryModelId | string |  | ✓ |  |  ~ 1024 chars | GS2-Inventory Inventory Model GRN usable for unleash targets<br>Specifies the GS2-Inventory inventory model that holds the items eligible for limit breaking. The item to be unleashed and the duplicate items consumed as material must both belong to this inventory model. |
| gradeModelId | string |  | ✓ |  |  ~ 1024 chars | Grade Model GRN<br>Specifies the GS2-Grade grade model that tracks the limit break level of the target item. When a limit break is successfully performed, the item's grade is incremented in this grade model. |
| groupKeyHierarchy | List&lt;string&gt; |  |  | [] | 0 ~ 10 items | Hierarchy of the JSON data that stores the group key in the ItemModel metadata<br>The group key classifies item models, such as the equipment slot, and is used by recipes to compare materials with the target.<br>For metadata with a structure like { "unleash": { "group": "weapon" } }, specify [ "unleash", "group" ].<br>The value must be a string. Required when a recipe uses "Same Group" or targetGroupKeys. |
| gradeEntries | [List&lt;UnleashRateEntryModel&gt;](#unleashrateentrymodel) |  | ✓ |  | 1 ~ 1000 items | List of Grade Entry<br>Defines the material cost for each grade level of the limit break. Each entry maps a grade value to the number of duplicate items that must be consumed to reach that grade. For example, grade 1 might require 1 duplicate, grade 2 might require 3 duplicates, and so on. |

### UnleashRateEntryModel

Unleash Rate Entry Model

Defines the material cost for a single grade level in a limit break progression. Each entry specifies which grade value it applies to and how many duplicate items of the same type must be consumed to achieve that grade.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| gradeValue | long |  | ✓ |  | 1 ~ 1000 | Target grade<br>The grade value that this entry defines the cost for. When performing a limit break to this grade level, the number of items specified by needCount will be consumed. |
| type | string (enum)<br>enum {<br>"simple",<br>"recipe"<br>}<br> |  |  | "simple" |  | Type of material condition<br>"Simple (simple)" consumes needCount duplicates of the same item model as the target. This is the conventional behavior.<br>"Recipe (recipe)" lets the player choose one of the recipes, and consumes the materials defined by the chosen recipe.simple: Simple / recipe: Recipe /  |
| needCount | int | {type} == "simple" | ✓* |  | 1 ~ 1000 | How many items of the same type to consume<br>The number of duplicate items that must be consumed to perform the limit break to the target grade. These items are of the same item model as the item being unleashed.<br>* Required if type is "simple" |
| recipes | [List&lt;UnleashRecipe&gt;](#unleashrecipe) | {type} == "recipe" | ✓* |  | 1 ~ 10 items | Recipes<br>Used when type is "Recipe". The player chooses one of these recipes when executing an unleash.<br>* Required if type is "recipe" |

### UnleashRecipe

Unleash Recipe

One way to raise the grade by one step. When a grade entry has several recipes, the player chooses one of them, and all the materials of the chosen recipe are required.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓ |  |  ~ 128 chars | Recipe name<br>A name unique within the grade entry. The player specifies the recipe by this name when executing an unleash. |
| metadata | string |  |  |  |  ~ 2048 chars | Metadata<br>Arbitrary values can be set in the metadata.<br>Since they do not affect GS2's behavior, they can be used to store information used in the game. |
| targetGroupKeys | List&lt;string&gt; |  |  | [] | 0 ~ 10 items | Group keys of the targets this recipe can be used for<br>When empty, the recipe can be used for any target.<br>When set, the recipe can be used only when the group key of the target's item model is included. The group key is read from the item model metadata using groupKeyHierarchy of the Unleash Rate Model. |
| materials | [List&lt;UnleashMaterial&gt;](#unleashmaterial) |  | ✓ |  | 1 ~ 10 items | Materials required by this recipe<br>All the materials are consumed when this recipe is used. |

### UnleashMaterial

Unleash Material

Defines one kind of material required by a recipe.
"Individual (individual)" consumes item sets chosen by the player, such as duplicate equipment.
"Quantity (quantity)" consumes a quantity of an item decided by the setting, such as a general-purpose enhancement material.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| name | string |  | ✓ |  |  ~ 128 chars | Material name<br>A name unique within the recipe. When executing an unleash, the player specifies the item sets for each individual material by this name. |
| materialType | string (enum)<br>enum {<br>"individual",<br>"quantity"<br>}<br> |  | ✓ |  |  | Type of material<br>"Individual (individual)" consumes item sets chosen by the player.<br>"Quantity (quantity)" consumes a quantity of an item decided by the setting.individual: Individual / quantity: Quantity /  |
| individualSetting | [UnleashIndividualMaterialSetting](#unleashindividualmaterialsetting) | {materialType} == "individual" | ✓* |  |  | Individual material setting<br>Used when materialType is "Individual".<br>* Required if materialType is "individual" |
| quantitySetting | [UnleashQuantityMaterialSetting](#unleashquantitymaterialsetting) | {materialType} == "quantity" | ✓* |  |  | Quantity material setting<br>Used when materialType is "Quantity".<br>* Required if materialType is "quantity" |

### UnleashIndividualMaterialSetting

Individual Material Setting

Defines a material that is consumed as individual item sets, such as a duplicate piece of equipment.
The player chooses which item sets to consume, and each chosen item set must belong to the same inventory model as the item being unleashed.
Because each individual can have its own grade in GS2-Grade, the grade of the material can also be made a condition.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| matchType | string (enum)<br>enum {<br>"sameItem",<br>"sameGroup"<br>}<br> |  | ✓ |  |  | How the material is matched against the target<br>"Same Item (sameItem)" accepts only item sets of the same item model as the target.<br>"Same Group (sameGroup)" accepts item sets whose item model has the same group key as the target's item model. The group key is read from the item model metadata using groupKeyHierarchy of the Unleash Rate Model.sameItem: Same Item / sameGroup: Same Group /  |
| gradeCondition | string (enum)<br>enum {<br>"any",<br>"sameAsTarget",<br>"equal"<br>}<br> |  |  | "any" |  | Grade condition of the material<br>"Any (any)" does not check the grade of the material.<br>"Same as Target (sameAsTarget)" requires the material to have the same grade as the target's current grade.<br>"Equal (equal)" requires the material to have the grade specified by gradeValue.<br>The grade is verified in the transaction with GS2-Grade, using the grade model of the Unleash Rate Model.any: Any / sameAsTarget: Same as Target / equal: Equal /  |
| gradeValue | long | {gradeCondition} == "equal" | ✓* |  | 0 ~ 1000 | Grade the material must have<br>Used when gradeCondition is "Equal".<br>* Required if gradeCondition is "equal" |
| count | int |  | ✓ |  | 1 ~ 1000 | Number of item sets to consume<br>The number of item sets the player must specify for this material. Each item set is consumed by one. |

### UnleashQuantityMaterialSetting

Quantity Material Setting

Defines a material that is consumed by quantity, such as a general-purpose enhancement material.
The player does not choose the item; the item model to consume is decided by this setting, and the specified quantity is consumed.
Both GS2-Inventory standard inventories and simple inventories can be used.

|  | Type | Condition | Required | Default | Value Limits | Description |
| --- | --- | --- | --- | --- | --- | --- |
| matchType | string (enum)<br>enum {<br>"sameGroup",<br>"specified"<br>}<br> |  | ✓ |  |  | How the item model to consume is decided<br>"Same Group (sameGroup)" consumes the item model in materialInventoryModelId whose group key is the same as the target's item model. Exactly one item model must have that group key.<br>"Specified (specified)" consumes the item model specified by itemModelId.sameGroup: Same Group / specified: Specified /  |
| materialInventoryModelId | string | {matchType} == "sameGroup" | ✓* |  |  ~ 1024 chars | GS2-Inventory inventory model GRN to search for the material<br>Used when matchType is "Same Group". A simple inventory model GRN can also be specified.<br>* Required if matchType is "sameGroup" |
| itemModelId | string | {matchType} == "specified" | ✓* |  |  ~ 1024 chars | GS2-Inventory item model GRN to consume<br>Used when matchType is "Specified". A simple item model GRN can also be specified.<br>* Required if matchType is "specified" |
| count | int |  | ✓ |  | 1 ~ 2147483645 | Quantity to consume |

---



