GS2-Inventory 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

TypeConditionRequiredDefaultValue LimitsDescription
namestring
~ 128 charsNamespace name
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
descriptionstring~ 1024 charsDescription
transactionSettingV2TransactionSettingV2Transaction Setting (V2)
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.
Set this on a new Namespace. transactionSetting, the obsolete setting it replaces, is used only while this is unset.
acquireScriptScriptSettingScript setting to be executed when an Items is acquired
Script Trigger Reference - acquire
overflowScriptScriptSettingScript setting to execute when unable to obtain due to reaching the acquisition limit
Script Trigger Reference - overflowDone
consumeScriptScriptSettingScript setting to be executed when consuming Items
Script Trigger Reference - consume
simpleItemAcquireScriptScriptSettingScript setting to be executed when acquiring Simple Items
Script Trigger Reference - simpleItemAcquire
simpleItemConsumeScriptScriptSettingScript setting to be executed when consuming Simple Items
Script Trigger Reference - simpleItemConsume
bigItemAcquireScriptScriptSettingScript setting to be executed when acquiring Big Items
Script Trigger Reference - bigItemAcquire
bigItemConsumeScriptScriptSettingScript setting to be executed when consuming Big Items
Script Trigger Reference - bigItemConsume
logSettingLogSettingLog Output Setting
Specifies the GS2-Log Namespace for outputting API request and response logs of inventory operations. Useful for tracking item acquisition, consumption, and capacity changes for debugging and analytics.

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

TypeDescription
ItemNamespaceNamespace created

Implementation Example

Type: GS2::Inventory::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSettingV2: null
  AcquireScript: null
  OverflowScript: null
  ConsumeScript: null
  SimpleItemAcquireScript: null
  SimpleItemConsumeScript: null
  BigItemAcquireScript: null
  BigItemConsumeScript: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/inventory"
)


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

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Inventory\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Inventory\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
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.inventory.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.inventory.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
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Inventory.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Inventory.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
import core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new inventory.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
from gs2_cdk import Stack, core, inventory

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        inventory.Namespace(
            stack=self,
            name='namespace-0001',
            options=inventory.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.

TypeConditionRequiredDefaultValue LimitsDescription
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor Namespace GRN used to execute transactions
enableParallelExecutionboolfalseWhether 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.

TypeConditionRequiredDefaultValue LimitsDescription
triggerScriptIdstring~ 1024 charsGS2-Script script GRN executed synchronously when the API is executed
Must be specified in GRN format starting with “grn:gs2:”.
doneTriggerTargetTypestring (enum)
enum {
  “none”,
  “gs2_script”,
  “aws”
}
“none”Asynchronous script execution method
Specifies the type of script to use for asynchronous execution.
You can choose from “Do not use an asynchronous execution script (none)”, “Use GS2-Script (gs2_script)”, and “Use Amazon EventBridge (aws)”.
DefinitionDescription
noneNone
gs2_scriptGS2-Script
awsAmazon EventBridge
doneTriggerScriptIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsGS2-Script script GRN for asynchronous execution
Must be specified in GRN format starting with “grn:gs2:”.
* Enabled only if doneTriggerTargetType is “gs2_script”
doneTriggerQueueNamespaceIdstring{doneTriggerTargetType} == “gs2_script”~ 1024 charsGS2-JobQueue Namespace GRN used to execute asynchronous scripts
If you want to execute asynchronous execution scripts via GS2-JobQueue instead of executing them directly, specify the GS2-JobQueue Namespace GRN.
GS2-JobQueue is generally not required unless you have a specific reason to use it.
* 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.

TypeConditionRequiredDefaultValue LimitsDescription
loggingNamespaceIdstring
~ 1024 charsGS2-Log Namespace GRN to output logs
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.

TypeConditionRequiredDefaultValue LimitsDescription
enableAutoRunboolfalseWhether to automatically execute issued transactions on the server side
enableAtomicCommitbool{enableAutoRun} == truefalseWhether to commit transactions atomically
* Enabled only if enableAutoRun is true
transactionUseDistributorbool{enableAtomicCommit} == truefalseWhether to execute transactions asynchronously
* Enabled only if enableAtomicCommit is true
commitScriptResultInUseDistributorbool{transactionUseDistributor} == truefalseWhether to execute the commit processing of the script result asynchronously
* Enabled only if transactionUseDistributor is true
acquireActionUseJobQueuebool{enableAtomicCommit} == truefalseWhether to use GS2-JobQueue to execute the acquire action
* Enabled only if enableAtomicCommit is true
enableSequentialExecutionbool{enableAtomicCommit} == truefalseWhether to execute the actions of an atomic commit sequentially so that multiple actions may update the same row
* Enabled only if enableAtomicCommit is true
distributorNamespaceIdstring“grn:gs2:{region}:{ownerId}:distributor:default”~ 1024 charsGS2-Distributor Namespace GRN used to execute transactions
queueNamespaceIdstring“grn:gs2:{region}:{ownerId}:queue:default”~ 1024 charsGS2-JobQueue Namespace GRN used to execute transactions

CurrentItemModelMaster

Currently active Item Model master data

This master data defines the Item Models currently active within the Namespace. GS2 uses JSON format files for managing master data. By uploading these files, you can apply the master data to the server.

To create JSON files, GS2 provides a master data editor within the management console. Additionally, you can create tools better suited for game operations and export JSON files in the appropriate format.

Request

Resource creation and update requests

TypeConditionRequiredDefaultValue LimitsDescription
namespaceNamestring
~ 128 charsNamespace name
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
modestring (enum)
enum {
  “direct”,
  “preUpload”
}
“direct”Update mode
DefinitionDescription
directDirectly update master data
preUploadUpload master data and then update
settingsstring{mode} == “direct”
✓*
~ 5242880 bytes (5MB)Master Data
* Required if mode is “direct”
uploadTokenstring{mode} == “preUpload”
✓*
~ 1024 charsToken obtained by pre-upload
Used to apply the uploaded master data.
* Required if mode is “preUpload”

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

TypeDescription
ItemCurrentItemModelMasterUpdated master data of the currently active Item Models

Implementation Example

Type: GS2::Inventory::CurrentItemModelMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2019-02-05",
    "inventoryModels": [
      {
        "name": "item",
        "initialCapacity": 100,
        "maxCapacity": 999,
        "itemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001",
            "stackingLimit": 99,
            "allowMultipleStacks": false,
            "sortValue": 1
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002",
            "stackingLimit": 49,
            "allowMultipleStacks": true,
            "sortValue": 2
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003",
            "stackingLimit": 9,
            "allowMultipleStacks": false,
            "sortValue": 3
          }
        ],
        "metadata": "INVENTORY_ITEM"
      },
      {
        "name": "character",
        "initialCapacity": 50,
        "maxCapacity": 99,
        "itemModels": [
          {
            "name": "character-0001",
            "metadata": "CHARACTER_0001",
            "stackingLimit": 99,
            "allowMultipleStacks": false,
            "sortValue": 1
          },
          {
            "name": "character-0002",
            "metadata": "CHARACTER_0002",
            "stackingLimit": 49,
            "allowMultipleStacks": true,
            "sortValue": 2
          },
          {
            "name": "character-0003",
            "metadata": "CHARACTER_0003",
            "stackingLimit": 9,
            "allowMultipleStacks": false,
            "sortValue": 3
          }
        ],
        "metadata": "INVENTORY_CHARACTER"
      }
    ],
    "simpleInventoryModels": [
      {
        "name": "item",
        "simpleItemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001"
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002"
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003"
          }
        ],
        "metadata": "INVENTORY_ITEM"
      }
    ],
    "bigInventoryModels": [
      {
        "name": "item",
        "bigItemModels": [
          {
            "name": "item-0001",
            "metadata": "ITEM_0001"
          },
          {
            "name": "item-0002",
            "metadata": "ITEM_0002"
          },
          {
            "name": "item-0003",
            "metadata": "ITEM_0003"
          }
        ],
        "metadata": "INVENTORY_ITEM"
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/inventory"
    "github.com/openlyinc/pointy"
)


SampleStack := core.NewStack()
inventory.NewNamespace(
    &SampleStack,
    "namespace-0001",
    inventory.NamespaceOptions{},
).MasterData(
    []inventory.InventoryModel{
        inventory.NewInventoryModel(
            "item",
            100,
            999,
            []inventory.ItemModel{
                inventory.NewItemModel(
                    "item-0001",
                    99,
                    false,
                    1,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewItemModel(
                    "item-0002",
                    49,
                    true,
                    2,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewItemModel(
                    "item-0003",
                    9,
                    false,
                    3,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.InventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
        inventory.NewInventoryModel(
            "character",
            50,
            99,
            []inventory.ItemModel{
                inventory.NewItemModel(
                    "character-0001",
                    99,
                    false,
                    1,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0001"),
                    },
                ),
                inventory.NewItemModel(
                    "character-0002",
                    49,
                    true,
                    2,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0002"),
                    },
                ),
                inventory.NewItemModel(
                    "character-0003",
                    9,
                    false,
                    3,
                    inventory.ItemModelOptions{
                        Metadata: pointy.String("CHARACTER_0003"),
                    },
                ),
            },
            inventory.InventoryModelOptions{
                Metadata: pointy.String("INVENTORY_CHARACTER"),
            },
        ),
    },
    []inventory.SimpleInventoryModel{
        inventory.NewSimpleInventoryModel(
            "item",
            []inventory.SimpleItemModel{
                inventory.NewSimpleItemModel(
                    "item-0001",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewSimpleItemModel(
                    "item-0002",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewSimpleItemModel(
                    "item-0003",
                    inventory.SimpleItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.SimpleInventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
    },
    []inventory.BigInventoryModel{
        inventory.NewBigInventoryModel(
            "item",
            []inventory.BigItemModel{
                inventory.NewBigItemModel(
                    "item-0001",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0001"),
                    },
                ),
                inventory.NewBigItemModel(
                    "item-0002",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0002"),
                    },
                ),
                inventory.NewBigItemModel(
                    "item-0003",
                    inventory.BigItemModelOptions{
                        Metadata: pointy.String("ITEM_0003"),
                    },
                ),
            },
            inventory.BigInventoryModelOptions{
                Metadata: pointy.String("INVENTORY_ITEM"),
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Inventory\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Inventory\Model\InventoryModel(
                    name:"item",
                    initialCapacity:100,
                    maxCapacity:999,
                    itemModels:[
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0001",
                            stackingLimit: 99,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0001",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0002",
                            stackingLimit: 49,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0002",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "item-0003",
                            stackingLimit: 9,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "ITEM_0003",
                            ),
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                ),
                new \Gs2Cdk\Inventory\Model\InventoryModel(
                    name:"character",
                    initialCapacity:50,
                    maxCapacity:99,
                    itemModels:[
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0001",
                            stackingLimit: 99,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0001",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0002",
                            stackingLimit: 49,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0002",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\ItemModel(
                            name: "character-0003",
                            stackingLimit: 9,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new \Gs2Cdk\Inventory\Model\Options\ItemModelOptions(
                                metadata: "CHARACTER_0003",
                            ),
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\InventoryModelOptions(
                        metadata:"INVENTORY_CHARACTER"
                    )
                )
            ],
            [
                new \Gs2Cdk\Inventory\Model\SimpleInventoryModel(
                    name:"item",
                    simpleItemModels:[
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0001",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0001",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0002",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0002",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\SimpleItemModel(
                            name: "item-0003",
                            options: new \Gs2Cdk\Inventory\Model\Options\SimpleItemModelOptions(
                                metadata: "ITEM_0003",
                            ),
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\SimpleInventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                )
            ],
            [
                new \Gs2Cdk\Inventory\Model\BigInventoryModel(
                    name:"item",
                    bigItemModels:[
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0001",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0001",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0002",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0002",
                            ),
                        ),
                        new \Gs2Cdk\Inventory\Model\BigItemModel(
                            name: "item-0003",
                            options: new \Gs2Cdk\Inventory\Model\Options\BigItemModelOptions(
                                metadata: "ITEM_0003",
                            ),
                        ),
                    ],
                    options: new \Gs2Cdk\Inventory\Model\Options\BigInventoryModelOptions(
                        metadata:"INVENTORY_ITEM"
                    )
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.inventory.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.inventory.model.InventoryModel(
                    "item",
                    100,
                    999,
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0001",
                            99L,
                            false,
                            1,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0002",
                            49L,
                            true,
                            2,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "item-0003",
                            9L,
                            false,
                            3,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                ),
                new io.gs2.cdk.inventory.model.InventoryModel(
                    "character",
                    50,
                    99,
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0001",
                            99L,
                            false,
                            1,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0001")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0002",
                            49L,
                            true,
                            2,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0002")
                        ),
                        new io.gs2.cdk.inventory.model.ItemModel(
                            "character-0003",
                            9L,
                            false,
                            3,
                            new io.gs2.cdk.inventory.model.options.ItemModelOptions()
                                .withMetadata("CHARACTER_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.InventoryModelOptions()
                        .withMetadata("INVENTORY_CHARACTER")
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.inventory.model.SimpleInventoryModel(
                    "item",
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0001",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0002",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.SimpleItemModel(
                            "item-0003",
                            new io.gs2.cdk.inventory.model.options.SimpleItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.SimpleInventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.inventory.model.BigInventoryModel(
                    "item",
                    Arrays.asList(
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0001",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0001")
                        ),
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0002",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0002")
                        ),
                        new io.gs2.cdk.inventory.model.BigItemModel(
                            "item-0003",
                            new io.gs2.cdk.inventory.model.options.BigItemModelOptions()
                                .withMetadata("ITEM_0003")
                        )
                    ),
                    new io.gs2.cdk.inventory.model.options.BigInventoryModelOptions()
                        .withMetadata("INVENTORY_ITEM")
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Inventory.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Inventory.Model.InventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
                    name: "item",
                    initialCapacity: 100,
                    maxCapacity: 999,
                    itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0001",
                            stackingLimit: 99L,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0002",
                            stackingLimit: 49L,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "item-0003",
                            stackingLimit: 9L,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                ),
                new Gs2Cdk.Gs2Inventory.Model.InventoryModel(
                    name: "character",
                    initialCapacity: 50,
                    maxCapacity: 99,
                    itemModels: new Gs2Cdk.Gs2Inventory.Model.ItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0001",
                            stackingLimit: 99L,
                            allowMultipleStacks: false,
                            sortValue: 1,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0002",
                            stackingLimit: 49L,
                            allowMultipleStacks: true,
                            sortValue: 2,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.ItemModel(
                            name: "character-0003",
                            stackingLimit: 9L,
                            allowMultipleStacks: false,
                            sortValue: 3,
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.ItemModelOptions
                            {
                                metadata = "CHARACTER_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.InventoryModelOptions
                    {
                        metadata = "INVENTORY_CHARACTER"
                    }
                )
            },
            new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.SimpleInventoryModel(
                    name: "item",
                    simpleItemModels: new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0001",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0002",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.SimpleItemModel(
                            name: "item-0003",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.SimpleInventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                )
            },
            new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel[] {
                new Gs2Cdk.Gs2Inventory.Model.BigInventoryModel(
                    name: "item",
                    bigItemModels: new Gs2Cdk.Gs2Inventory.Model.BigItemModel[]
                    {
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0001",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0001"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0002",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0002"
                            }
                        ),
                        new Gs2Cdk.Gs2Inventory.Model.BigItemModel(
                            name: "item-0003",
                            options: new Gs2Cdk.Gs2Inventory.Model.Options.BigItemModelOptions
                            {
                                metadata = "ITEM_0003"
                            }
                        )
                    },
                    options: new Gs2Cdk.Gs2Inventory.Model.Options.BigInventoryModelOptions
                    {
                        metadata = "INVENTORY_ITEM"
                    }
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import inventory from "@/gs2cdk/inventory";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new inventory.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new inventory.model.InventoryModel(
                    "item",
                    100,
                    999,
                    [
                        new inventory.model.ItemModel(
                            "item-0001",
                            99,
                            false,
                            1,
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "item-0002",
                            49,
                            true,
                            2,
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "item-0003",
                            9,
                            false,
                            3,
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                ),
                new inventory.model.InventoryModel(
                    "character",
                    50,
                    99,
                    [
                        new inventory.model.ItemModel(
                            "character-0001",
                            99,
                            false,
                            1,
                            {
                                metadata: "CHARACTER_0001"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "character-0002",
                            49,
                            true,
                            2,
                            {
                                metadata: "CHARACTER_0002"
                            }
                        ),
                        new inventory.model.ItemModel(
                            "character-0003",
                            9,
                            false,
                            3,
                            {
                                metadata: "CHARACTER_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_CHARACTER"
                    }
                )
            ],
            [
                new inventory.model.SimpleInventoryModel(
                    "item",
                    [
                        new inventory.model.SimpleItemModel(
                            "item-0001",
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.SimpleItemModel(
                            "item-0002",
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.SimpleItemModel(
                            "item-0003",
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                )
            ],
            [
                new inventory.model.BigInventoryModel(
                    "item",
                    [
                        new inventory.model.BigItemModel(
                            "item-0001",
                            {
                                metadata: "ITEM_0001"
                            }
                        ),
                        new inventory.model.BigItemModel(
                            "item-0002",
                            {
                                metadata: "ITEM_0002"
                            }
                        ),
                        new inventory.model.BigItemModel(
                            "item-0003",
                            {
                                metadata: "ITEM_0003"
                            }
                        ),
                    ],
                    {
                        metadata: "INVENTORY_ITEM"
                    }
                )
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, inventory

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        inventory.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            inventory_models=[
                inventory.InventoryModel(
                    name='item',
                    initial_capacity=100,
                    max_capacity=999,
                    item_models=[
                        inventory.ItemModel(
                            name='item-0001',
                            stacking_limit=99,
                            allow_multiple_stacks=False,
                            sort_value=1,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.ItemModel(
                            name='item-0002',
                            stacking_limit=49,
                            allow_multiple_stacks=True,
                            sort_value=2,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.ItemModel(
                            name='item-0003',
                            stacking_limit=9,
                            allow_multiple_stacks=False,
                            sort_value=3,
                            options=inventory.ItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.InventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
                inventory.InventoryModel(
                    name='character',
                    initial_capacity=50,
                    max_capacity=99,
                    item_models=[
                        inventory.ItemModel(
                            name='character-0001',
                            stacking_limit=99,
                            allow_multiple_stacks=False,
                            sort_value=1,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0001',
                            ),
                        ),
                        inventory.ItemModel(
                            name='character-0002',
                            stacking_limit=49,
                            allow_multiple_stacks=True,
                            sort_value=2,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0002',
                            ),
                        ),
                        inventory.ItemModel(
                            name='character-0003',
                            stacking_limit=9,
                            allow_multiple_stacks=False,
                            sort_value=3,
                            options=inventory.ItemModelOptions(
                                metadata='CHARACTER_0003',
                            ),
                        ),
                    ],
                    options=inventory.InventoryModelOptions(
                        metadata = 'INVENTORY_CHARACTER'
                    ),
                ),
            ],
            simple_inventory_models=[
                inventory.SimpleInventoryModel(
                    name='item',
                    simple_item_models=[
                        inventory.SimpleItemModel(
                            name='item-0001',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.SimpleItemModel(
                            name='item-0002',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.SimpleItemModel(
                            name='item-0003',
                            options=inventory.SimpleItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.SimpleInventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
            ],
            big_inventory_models=[
                inventory.BigInventoryModel(
                    name='item',
                    big_item_models=[
                        inventory.BigItemModel(
                            name='item-0001',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0001',
                            ),
                        ),
                        inventory.BigItemModel(
                            name='item-0002',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0002',
                            ),
                        ),
                        inventory.BigItemModel(
                            name='item-0003',
                            options=inventory.BigItemModelOptions(
                                metadata='ITEM_0003',
                            ),
                        ),
                    ],
                    options=inventory.BigInventoryModelOptions(
                        metadata = 'INVENTORY_ITEM'
                    ),
                ),
            ],
        )

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

InventoryModel

Inventory Model

Inventory is like a bag that stores items owned by game players. Inventory can have a set capacity and cannot be owned beyond its capacity.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsInventory Model GRN
* Set automatically by the server
namestring
~ 128 charsInventory Model name
Unique Inventory Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
initialCapacityint
0 ~ 2147483646Initial Capacity
The number of inventory slots available to a user when the inventory is first created. Each slot can hold one item stack. Users can expand their capacity up to maxCapacity through gameplay actions.
maxCapacityint
0 ~ 2147483646Maximum Capacity
The upper limit of inventory slots that a user can expand to. Capacity cannot be increased beyond this value. When all slots are occupied and items cannot be stacked further, acquisition attempts will fail unless the overflow script handles the excess.
protectReferencedItembool?falseProtect Referenced Items
When enabled, item sets that have references registered (via the referenceOf mechanism) cannot be consumed or deleted. This prevents items that are in use by other systems (e.g., equipped gear, items bound to formations) from being accidentally removed.
itemModelsList<ItemModel>[]1 ~ 1000 itemsList of Item Models
The item types that can be stored in this inventory. Each item model defines the stacking and acquisition behavior for one type of item. Up to 1000 item models per inventory model.

ItemModel

Item Model

Items can be held in groups within a single inventory slot, such as Potion ×99. This grouping of multiple items into one slot is called “stacking,” and a maximum stack size can be set for each item.

The behavior when the stack limit is reached can also be set for each item. Specifically, you can choose one of the following:

  • Add a new inventory slot to allow further acquisition
  • Prevent further acquisition once the limit is reached
TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsItem Model GRN
* Set automatically by the server
namestring
~ 128 charsItem Model name
Unique Item Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
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.
Details are explained in the Microservices Introduction / GS2-Enhance section.
stackingLimitlong
1 ~ 9223372036854775805Maximum Stackable Quantity
The maximum number of this item that can be held in a single inventory slot (stack). When this limit is reached, the behavior depends on the allowMultipleStacks setting: either a new slot is allocated or further acquisition is blocked.
allowMultipleStacksbool
Allow Multiple Stacks
When enabled, if the stacking limit is reached, a new inventory slot is automatically allocated to store additional quantities of this item (consuming additional capacity). When disabled, acquisition is blocked once the stacking limit is reached in the existing slot.
sortValueint
0 ~ 2147483646Display Order
A numeric value used to sort items within the inventory for display purposes. Lower values are displayed first. This value is also copied to ItemSet records to enable consistent ordering of possessed items.

SimpleInventoryModel

Simple Inventory Model

In a normal InventoryModel, you could limit the amount of items that could be stored in your inventory. Simple Inventory, however, has no such functionality and simply stores the number of items in the inventory.

However, the Simple Inventory provides APIs that allow increasing or decreasing multiple items in a single operation.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsSimple Inventory Model GRN
* Set automatically by the server
namestring
~ 128 charsSimple Inventory Model name
Unique Simple Inventory Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
simpleItemModelsList<SimpleItemModel>[]1 ~ 1000 itemsList of Simple Item Models
The item types that can be stored in this simple inventory. Unlike standard inventory, simple items have no stacking limits or capacity constraints. Up to 1000 item models per simple inventory model.

SimpleItemModel

Simple Item Model

ItemModel allowed setting a maximum stackable quantity, enabling implementation where items exceeding a certain number could be split into multiple stacks. SimpleItem does not have such a function and simply stores the number of items in the possession of the item.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsSimple Item Model GRN
* Set automatically by the server
namestring
~ 128 charsSimple Item Model name
Unique Simple Item Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.

BigInventoryModel

Big Inventory Model

In the normal InventoryModel and SimpleInventoryModel, the number of items that can be stored in the inventory is limited to the range of int64. In inflationary games, you may need a wider range of values.

In the Big Inventory Model, the number of items that can be stored in the inventory can have an integer value of 1024 digits.

TypeConditionRequiredDefaultValue LimitsDescription
inventoryModelIdstring
*
~ 1024 charsBig Inventory Model GRN
* Set automatically by the server
namestring
~ 128 charsBig Inventory Model name
Unique Big Inventory Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
bigItemModelsList<BigItemModel>[]1 ~ 1000 itemsList of Big Item Models
The item types that can be stored in this big inventory. Each big item model can hold quantities represented as integer strings up to 1024 digits. Up to 1000 item models per big inventory model.

BigItemModel

Big Item Model

The Big Item Model defines items stored in a Big Inventory Model. Big Items can hold quantities that exceed the range of int64.

TypeConditionRequiredDefaultValue LimitsDescription
itemModelIdstring
*
~ 1024 charsBig Item Model GRN
* Set automatically by the server
namestring
~ 128 charsBig Item Model name
Unique Big Item Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadatastring~ 2048 charsMetadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.