UNPKG

@aitianyu.cn/tianyu-store

Version:
41 lines 1.77 kB
"use strict"; /**@format */ Object.defineProperty(exports, "__esModule", { value: true }); exports.newInstanceId = exports.generateInstanceId = void 0; const types_1 = require("@aitianyu.cn/types"); const InstanceIdImpl_1 = require("./store/impl/InstanceIdImpl"); /** * Function to generate a new instance id from a parent instance id * * @param parentOrStoreType the parent instance id, or new story type of instance id * @param storeTypeOrEntityId store type for child instace id of parent instance, or the entity id of new instance id * @param entityId entity id for child instance id of parent instance * @returns return a new generated instance id */ function generateInstanceId(parentOrStoreType, storeTypeOrEntityId, entityId) { // if the parent instance id is not provided, to create a new store instance id with no parent if (typeof parentOrStoreType === "string") { return new InstanceIdImpl_1.InstanceIdImpl([ { storeType: parentOrStoreType, entityId: storeTypeOrEntityId, }, ]); } const instanceStructure = parentOrStoreType.structure(); entityId = entityId || (0, types_1.guid)(); instanceStructure.push({ storeType: storeTypeOrEntityId, entityId }); return new InstanceIdImpl_1.InstanceIdImpl(instanceStructure); } exports.generateInstanceId = generateInstanceId; /** * Function to craete a instance id from provided string * * @param instanceId instance id string * @returns return a new instance id which equals to given string */ function newInstanceId(instanceId) { return new InstanceIdImpl_1.InstanceIdImpl(instanceId); } exports.newInstanceId = newInstanceId; //# sourceMappingURL=InstanceId.js.map