@api-client/core 0.14.1 → 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/browser.d.ts +1 -1
- package/build/src/browser.d.ts.map +1 -1
- package/build/src/browser.js.map +1 -1
- package/build/src/index.d.ts +1 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js.map +1 -1
- package/build/src/modeling/DomainAssociation.d.ts +35 -0
- package/build/src/modeling/DomainAssociation.d.ts.map +1 -1
- package/build/src/modeling/DomainAssociation.js +42 -5
- package/build/src/modeling/DomainAssociation.js.map +1 -1
- package/build/src/modeling/Semantics.d.ts +8 -0
- package/build/src/modeling/Semantics.d.ts.map +1 -1
- package/build/src/modeling/Semantics.js +15 -0
- package/build/src/modeling/Semantics.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/APIC-187.json +3 -3
- package/data/models/APIC-188.json +3 -3
- package/data/models/APIC-233.json +1 -1
- package/data/models/APIC-391.json +2 -2
- package/data/models/APIC-483.json +1 -1
- package/data/models/APIC-487.json +1 -1
- package/data/models/APIC-655.json +1 -1
- package/data/models/APIC-689.json +1 -1
- package/data/models/APIC-690.json +5 -5
- package/data/models/SE-10469.json +1 -1
- package/data/models/SE-13092.json +5 -5
- package/data/models/SE-22063.json +12 -2
- package/data/models/amf-helper-api.json +154 -14
- package/data/models/arc-demo-api.json +95 -15
- package/data/models/async-api.json +1 -1
- package/data/models/example-generator-api.json +366 -26
- package/data/models/expanded-api.json +1 -1
- package/data/models/flattened-api.json +1 -1
- package/data/models/multiple-servers.json +1 -1
- package/data/models/oas-3-api.json +1 -1
- package/data/models/oas-date.json +1 -1
- package/data/models/oas-types.json +1 -1
- package/data/models/oas-unions.json +1 -1
- package/data/models/petstore.json +1 -1
- package/data/models/raml-date.json +1 -1
- package/data/models/recursive.json +1 -1
- package/data/models/schema-api.json +62 -2
- package/data/models/secured-api.json +16 -16
- package/data/models/tracked-to-linked.json +4 -4
- package/package.json +2 -2
- package/src/modeling/DomainAssociation.ts +56 -0
- package/src/modeling/Semantics.ts +17 -0
- package/tests/unit/modeling/domain_asociation.spec.ts +92 -2
- package/tests/unit/modeling/semantics.spec.ts +149 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DomainAssociation.js","sourceRoot":"","sources":["../../../src/modeling/DomainAssociation.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI/D,OAAO,EAA4B,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAErF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAA+C,MAAM,gBAAgB,CAAA;AA8ClH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;IACU,iBAAiB;sBAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;iBAAvC,iBAAkB,SAAQ,WAAa;;;gCASjD,cAAc,EAAE;oCAKhB,QAAQ,EAAE;oCAKV,QAAQ,EAAE;kCAMV,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;oCASxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;mCAYxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;qCAKxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YA1CP,iKAAS,IAAI,6BAAJ,IAAI,mFAAO;YAK1B,6KAAS,QAAQ,6BAAR,QAAQ,2FAAq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AS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,CAAC,EAAE,CAAC,CAAA;YACnE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,QAAQ,CAAA;YAClC,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC/B,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;QAC5B,CAAC;QAED;;;WAGG;QACH,cAAc,CAAC,UAAwB;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;YAClE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBAC/B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;QAED;;;;WAIG;QACH,WAAW,CAAC,UAAwB;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;QACxD,CAAC;;;SAlbU,iBAAiB","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from './observed.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DomainAttributeAttribute, DomainAttributeAttributes } from './DataFormat.js'\nimport type { AssociationTarget, DomainGraphEdge } from './types.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport { DataSemantics, isAssociationSemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\nexport interface DomainAssociationSchema extends DomainElementSchema {\n kind: typeof DomainAssociationKind\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: AssociationBinding[]\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The semantics applied to this association.\n * This is a list of applied semantics that can be used to\n * describe the association in more detail.\n */\n semantics?: AppliedDataSemantic[]\n}\n\n/**\n * Represents an association between entities in a data domain.\n *\n * A `DomainAssociation` defines a relationship between a\n * `DomainEntity` and one or more other entities. It specifies\n * how entities are connected and can represent various types\n * of relationships, such as one-to-one, one-to-many, or\n * many-to-many.\n *\n * **Key Features:**\n *\n * - **Target Entities:** Specifies the entities that are\n * the target of the association.\n * - **Cardinality:** Defines whether the association is\n * single-valued or multi-valued (e.g., one-to-one vs.\n * one-to-many).\n * - **Required Status:** Indicates whether the association\n * is mandatory or optional.\n * - **Schema Customization:** Allows defining a custom\n * schema for the association, overriding the default\n * schema derived from the target entities.\n * - **Bindings:** Supports defining how the association is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Foreign Namespaces:** Can target entities in other\n * namespaces, enabling cross-namespace relationships.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainAssociation` is\n * through the `DomainEntity.addAssociation()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userModel = dataDomain.addModel({ key: 'userModel' });\n * const userEntity = userModel.addEntity({ key: 'user' });\n * const addressEntity = userModel.addEntity({ key: 'address' });\n * // Add an association from User to Address\n * const addressAssociation = userEntity.addAssociation();\n * addressAssociation.addTarget(addressEntity);\n * ```\n */\nexport class DomainAssociation extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainAssociationKind\n\n /**\n * The description of the association namespace.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data association is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data association allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * The schema allowing to translate the model into a\n * specific format (like JSON, RAML, XML, etc.)\n */\n @observed({ deep: true }) accessor schema: IApiAssociationShape | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: AssociationBinding[]\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n @observed({ deep: true }) accessor targets: AssociationTarget[]\n\n /**\n * Semantics applied to this association.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * Creates a full data association schema with defaults.\n *\n * @param input The partial data association schema.\n * @returns The data association schema.\n */\n static createSchema(input: Partial<DomainAssociationSchema> = {}): DomainAssociationSchema {\n const { key = nanoid(), semantics = [] } = input\n const info = Thing.fromJSON(input.info, { name: 'new_association' }).toJSON()\n const result: DomainAssociationSchema = {\n kind: DomainAssociationKind,\n key,\n info,\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (input.schema) {\n result.schema = structuredClone(input.schema)\n }\n if (typeof input.multiple === 'boolean') {\n result.multiple = input.multiple\n }\n if (typeof input.required === 'boolean') {\n result.required = input.required\n }\n if (Array.isArray(input.bindings)) {\n result.bindings = input.bindings.map((i) => structuredClone(i))\n }\n if (Array.isArray(input.targets)) {\n result.targets = input.targets.map((i) => ({ ...i }))\n }\n return result\n }\n\n /**\n * Creates a new data association instance.\n *\n * You probably want to use the `DomainEntity.addAssociation()` method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial data association schema.\n */\n constructor(root: DataDomain, parent: string, input?: Partial<DomainAssociationSchema>) {\n const init = DomainAssociation.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainAssociationKind\n this.info = new Thing(init.info)\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n }\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n if (Array.isArray(init.targets)) {\n this.targets = init.targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n }\n\n /**\n * Generates a JSON representation of the association.\n *\n * @returns A plain object representation of the `DomainAssociation`.\n */\n toJSON(): DomainAssociationSchema {\n const result: DomainAssociationSchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.targets) && this.targets.length) {\n result.targets = toRaw(this, this.targets)?.map((i) => ({ ...i }))\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n *\n * @returns The parent `DomainEntity` or undefined if not found.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Removes this property from the parent entity.\n *\n * This method removes the association from the parent\n * entity's list of associations.\n *\n * @example\n * ```typescript\n * association.remove();\n * ```\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeAssociation(this.key)\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n *\n * @returns The schema object.\n * @example\n * ```typescript\n * const schema = association.ensureSchema();\n * ```\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Checks whether the passed value is one of the supported\n * data property attributes.\n *\n * @param value The value to test\n * @returns True when the passed value is one of the\n * supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainAttributeAttributes.includes(value as DomainAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings\n * definition.\n *\n * @returns The web binding definition\n * @example\n * ```typescript\n * const webBindings = association.getWebBinding();\n * webBindings.hidden = true;\n * ```\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n this.domain.notifyChange()\n }\n return object.schema as AssociationWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was\n * created.\n *\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n * @example\n * ```typescript\n * const webBindings = association.readBinding('web');\n * if (webBindings) {\n * // ...\n * }\n * ```\n */\n readBinding(type: 'web' | 'protobuf'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema || undefined\n }\n\n /**\n * Adds a target entity to the association.\n *\n * If the entity comes from another namespace then it is\n * set as a foreign entity.\n *\n * @param entity - The `DomainEntity` instance to add.\n * @example\n * ```typescript\n * association.addTarget(addressEntity);\n * ```\n */\n addTarget(entity: DomainEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `DomainEntity` definition or just\n * its key.\n * @param namespace - The key of the foreign namespace this\n * entity belongs to. Do not set this value for local\n * entities.\n * @example\n * ```typescript\n * association.addTarget('address', 'foreignNamespace');\n * ```\n */\n addTarget(entity: string, namespace?: string): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param init The key of an entity, its instance, or schema.\n * @param namespace - The key of the foreign namespace this\n * entity belongs to. Do not set this value for local entities.\n */\n addTarget(init: string | DomainEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n if (init.domain.key !== this.root.key) {\n namespace = init.domain.key\n }\n }\n if (this.targets.some((i) => i.key === key && i.domain === namespace)) {\n const message = `Target ${key} already exists.`\n throw new Error(message)\n }\n if (namespace && !this.root.dependencies.has(namespace)) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.domain = namespace\n }\n this.targets.push(info)\n const targetKey = namespace ? `${namespace}:${key}` : key\n const label: DomainGraphEdge = {\n type: 'association',\n }\n if (namespace) {\n label.domain = namespace\n label.foreign = true\n }\n // We need to associate the target with the association\n // in the graph. This way, when looking for associations\n // on a target entities we can easily locate the\n // association.\n this.root.graph.setEdge(this.key, targetKey, label)\n // this.root.notifyChange()\n }\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or\n * schema.\n * @example\n * ```typescript\n * association.removeTarget(addressEntity);\n * ```\n */\n removeTarget(init: string | DomainEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.splice(index, 1)\n // this.root.notifyChange()\n }\n this.root.graph.removeEdge(this.key, key)\n }\n\n /**\n * Lists all target entities of this association.\n *\n * @returns A generator that yields each target\n * `DomainEntity`.\n * @example\n * ```typescript\n * for (const target of association.listTargets()) {\n * console.log(target.key);\n * }\n * ```\n */\n *listTargets(): Generator<DomainEntity> {\n for (const target of this.targets) {\n const { key, domain } = target\n const targetKey = domain ? `${domain}:${key}` : key\n const entity = this.root.graph.node(targetKey) as DomainEntity | undefined\n if (entity) {\n yield entity\n }\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.associationProperty(this)\n }\n\n /**\n * Adds or updates a semantic to the association.\n * @param semantic The semantic to add to the association.\n * @throws Error if the semantic is not an association semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isAssociationSemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an association semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the association.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the association has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"DomainAssociation.js","sourceRoot":"","sources":["../../../src/modeling/DomainAssociation.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,eAAe,CAAA;AAI/D,OAAO,EAA4B,yBAAyB,EAAE,MAAM,iBAAiB,CAAA;AAErF,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,aAAa,EAAE,qBAAqB,EAA+C,MAAM,gBAAgB,CAAA;AA0ElH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;IACU,iBAAiB;sBAAS,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAvC,iBAAkB,SAAQ,WAAa;;;gCASjD,cAAc,EAAE;oCAKhB,QAAQ,EAAE;oCAKV,QAAQ,EAAE;kCAMV,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;oCASxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;mCAYxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;qCAKxB,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;oCAKxB,QAAQ,EAAE;oCAKV,QAAQ,EAAE;YApDO,iKAAS,IAAI,6BAAJ,IAAI,mFAAO;YAK1B,6KAAS,QAAQ,6BAAR,QAAQ,2FAAqB;YAKtC,6KAAS,QAAQ,6BAAR,QA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AS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC/B,CAAC;YACD,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;QAC5B,CAAC;QAED;;;WAGG;QACH,cAAc,CAAC,UAAwB;YACrC,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;YAClE,IAAI,KAAK,IAAI,CAAC,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBAC/B,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;QAED;;;;WAIG;QACH,WAAW,CAAC,UAAwB;YAClC,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,UAAU,CAAC,CAAA;QACxD,CAAC;;;SA9cU,iBAAiB","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from './observed.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { IApiAssociationShape, IApiPropertyShape } from '../amf/definitions/Shapes.js'\nimport type { AssociationBinding, AssociationBindings, AssociationWebBindings } from './Bindings.js'\nimport { DomainAttributeAttribute, DomainAttributeAttributes } from './DataFormat.js'\nimport type { AssociationTarget, DomainGraphEdge } from './types.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport { DataSemantics, isAssociationSemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\n/**\n * Defines the behavior when a parent entity in an association is deleted.\n *\n * - `restrict`: Prevents the deletion of a parent entity if it has any associated child entities.\n * The generated API should return a clear and specific error message (e.g., 409 Conflict).\n * - _Example_: Do not allow a Department to be deleted if it still has Employees.\n * - `cascade`: Automatically deletes all associated child entities when the parent entity is deleted.\n * - _Example_: Deleting a User will also delete all their associated Posts and Comments.\n * - `setNull`: Sets the foreign key of the associated child entities to NULL. This is only valid if the\n * association property on the child entity is nullable.\n * - _Example_: When a `Project` is deleted, the `project_id` on associated `Tasks` is set to NULL,\n * making them unassigned but not deleting them.\n * - `doNothing`: No action is taken on the associated child entities when the parent entity is deleted.\n * - _Example_: Deleting a `Category` does not affect associated `Products`, which remain in the database\n * but may become orphaned.\n * This is useful when the association is optional or when child entities should not be deleted\n * or modified upon the deletion of a parent entity.\n */\nexport type OnDeleteRule = 'restrict' | 'cascade' | 'setNull' | 'doNothing'\n\nexport interface DomainAssociationSchema extends DomainElementSchema {\n kind: typeof DomainAssociationKind\n /**\n * The data association description.\n */\n info: IThing\n /**\n * Wether the data association is required.\n */\n required?: boolean\n /**\n * Whether the data association allows multiple items.\n */\n multiple?: boolean\n /**\n * The schema allowing to translate the model into a specific format (like JSON, RAML, XML, etc.)\n *\n * When this is defined then it is used as the schema. When this is not defined it uses\n * referenced entities schemas. Note, changes in the referenced entities may not be propagated\n * to schemas altered by the user.\n */\n schema?: IApiAssociationShape\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n bindings?: AssociationBinding[]\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n targets?: AssociationTarget[]\n /**\n * The semantics applied to this association.\n * This is a list of applied semantics that can be used to\n * describe the association in more detail.\n */\n semantics?: AppliedDataSemantic[]\n /**\n * Defines the behavior when a parent entity in an association is deleted.\n */\n onDelete?: OnDeleteRule\n /**\n * Whether the association is read-only.\n */\n readOnly?: boolean\n}\n\n/**\n * Represents an association between entities in a data domain.\n *\n * A `DomainAssociation` defines a relationship between a\n * `DomainEntity` and one or more other entities. It specifies\n * how entities are connected and can represent various types\n * of relationships, such as one-to-one, one-to-many, or\n * many-to-many.\n *\n * **Key Features:**\n *\n * - **Target Entities:** Specifies the entities that are\n * the target of the association.\n * - **Cardinality:** Defines whether the association is\n * single-valued or multi-valued (e.g., one-to-one vs.\n * one-to-many).\n * - **Required Status:** Indicates whether the association\n * is mandatory or optional.\n * - **Schema Customization:** Allows defining a custom\n * schema for the association, overriding the default\n * schema derived from the target entities.\n * - **Bindings:** Supports defining how the association is\n * represented in different formats (e.g., web APIs,\n * protocol buffers).\n * - **Foreign Namespaces:** Can target entities in other\n * namespaces, enabling cross-namespace relationships.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainAssociation` is\n * through the `DomainEntity.addAssociation()` method.\n *\n * **Example:**\n *\n * ```typescript\n * const dataDomain = new DataDomain();\n * const userModel = dataDomain.addModel({ key: 'userModel' });\n * const userEntity = userModel.addEntity({ key: 'user' });\n * const addressEntity = userModel.addEntity({ key: 'address' });\n * // Add an association from User to Address\n * const addressAssociation = userEntity.addAssociation();\n * addressAssociation.addTarget(addressEntity);\n * ```\n */\nexport class DomainAssociation extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainAssociationKind\n\n /**\n * The description of the association namespace.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Wether the data association is required.\n */\n @observed() accessor required: boolean | undefined\n\n /**\n * Whether the data association allows multiple items.\n */\n @observed() accessor multiple: boolean | undefined\n\n /**\n * The schema allowing to translate the model into a\n * specific format (like JSON, RAML, XML, etc.)\n */\n @observed({ deep: true }) accessor schema: IApiAssociationShape | undefined\n\n /**\n * The list of bindings for this property.\n *\n * A binding defines a translation from a data model to a specific format.\n * For example allows to define properties required to generate AMF shape and therefore RAML/OAS shapes for web APIs\n * or a protocol buffer schema.\n */\n @observed({ deep: true }) accessor bindings: AssociationBinding[]\n\n /**\n * The key of the parent entity.\n */\n protected parent: string\n\n /**\n * The list of keys associated with the entity through this association.\n * An association without a target is considered invalid and discarded when processing the values.\n * When multiple associations are set then we are dealing with an union.\n */\n @observed({ deep: true }) accessor targets: AssociationTarget[]\n\n /**\n * Semantics applied to this association.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * Defines the behavior when a parent entity in an association is deleted.\n */\n @observed() accessor onDelete: OnDeleteRule | undefined\n\n /**\n * Whether the association is read-only.\n */\n @observed() accessor readOnly: boolean | undefined\n\n /**\n * Creates a full data association schema with defaults.\n *\n * @param input The partial data association schema.\n * @returns The data association schema.\n */\n static createSchema(input: Partial<DomainAssociationSchema> = {}): DomainAssociationSchema {\n const { key = nanoid(), semantics = [] } = input\n const info = Thing.fromJSON(input.info, { name: 'new_association' }).toJSON()\n const result: DomainAssociationSchema = {\n kind: DomainAssociationKind,\n key,\n info,\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (input.onDelete) {\n result.onDelete = input.onDelete\n }\n if (typeof input.readOnly === 'boolean') {\n result.readOnly = input.readOnly\n }\n if (input.schema) {\n result.schema = structuredClone(input.schema)\n }\n if (typeof input.multiple === 'boolean') {\n result.multiple = input.multiple\n }\n if (typeof input.required === 'boolean') {\n result.required = input.required\n }\n if (Array.isArray(input.bindings)) {\n result.bindings = input.bindings.map((i) => structuredClone(i))\n }\n if (Array.isArray(input.targets)) {\n result.targets = input.targets.map((i) => ({ ...i }))\n }\n return result\n }\n\n /**\n * Creates a new data association instance.\n *\n * You probably want to use the `DomainEntity.addAssociation()` method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param parent The key of the parent entity.\n * @param input The partial data association schema.\n */\n constructor(root: DataDomain, parent: string, input?: Partial<DomainAssociationSchema>) {\n const init = DomainAssociation.createSchema(input)\n super(root, init.key)\n this.parent = parent\n this.kind = DomainAssociationKind\n this.info = new Thing(init.info)\n if (init.schema) {\n this.schema = structuredClone(init.schema)\n }\n if (typeof init.multiple === 'boolean') {\n this.multiple = init.multiple\n }\n if (typeof init.required === 'boolean') {\n this.required = init.required\n }\n if (Array.isArray(init.bindings)) {\n this.bindings = init.bindings.map((i) => structuredClone(i))\n } else {\n this.bindings = []\n }\n if (Array.isArray(init.targets)) {\n this.targets = init.targets.map((i) => ({ ...i }))\n } else {\n this.targets = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n if (init.onDelete) {\n this.onDelete = init.onDelete\n }\n if (typeof init.readOnly === 'boolean') {\n this.readOnly = init.readOnly\n }\n }\n\n /**\n * Generates a JSON representation of the association.\n *\n * @returns A plain object representation of the `DomainAssociation`.\n */\n toJSON(): DomainAssociationSchema {\n const result: DomainAssociationSchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (this.schema) {\n result.schema = structuredClone(toRaw(this, this.schema))\n }\n if (typeof this.multiple === 'boolean') {\n result.multiple = this.multiple\n }\n if (typeof this.required === 'boolean') {\n result.required = this.required\n }\n if (Array.isArray(this.bindings) && this.bindings.length) {\n result.bindings = toRaw(this, this.bindings)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.targets) && this.targets.length) {\n result.targets = toRaw(this, this.targets)?.map((i) => ({ ...i }))\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (this.onDelete) {\n result.onDelete = this.onDelete\n }\n if (typeof this.readOnly === 'boolean' && this.readOnly) {\n result.readOnly = this.readOnly\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property exist.\n *\n * @returns The parent `DomainEntity` or undefined if not found.\n */\n getParentInstance(): DomainEntity | undefined {\n return this.root.graph.node(this.parent) as DomainEntity | undefined\n }\n\n /**\n * Removes this property from the parent entity.\n *\n * This method removes the association from the parent\n * entity's list of associations.\n *\n * @example\n * ```typescript\n * association.remove();\n * ```\n */\n remove(): void {\n const parent = this.getParentInstance()\n parent?.removeAssociation(this.key)\n }\n\n /**\n * Creates the `schema` object if missing and returns it.\n *\n * @returns The schema object.\n * @example\n * ```typescript\n * const schema = association.ensureSchema();\n * ```\n */\n ensureSchema(): IApiAssociationShape {\n if (!this.schema) {\n this.schema = {}\n }\n return this.schema\n }\n\n /**\n * Checks whether the passed value is one of the supported\n * data property attributes.\n *\n * @param value The value to test\n * @returns True when the passed value is one of the\n * supported data property attributes.\n */\n static isValidAttribute(value: unknown): value is DomainAttributeAttribute {\n if (typeof value !== 'string') {\n return false\n }\n return DomainAttributeAttributes.includes(value as DomainAttributeAttribute)\n }\n\n /**\n * Creates if not existing and returns web bindings\n * definition.\n *\n * @returns The web binding definition\n * @example\n * ```typescript\n * const webBindings = association.getWebBinding();\n * webBindings.hidden = true;\n * ```\n */\n getWebBinding(): AssociationWebBindings {\n let object = this.bindings.find((i) => i.type === 'web') as AssociationBinding | undefined\n if (!object) {\n object = { type: 'web', schema: {} } as AssociationBinding\n this.bindings.push(object)\n this.domain.notifyChange()\n }\n return object.schema as AssociationWebBindings\n }\n\n /**\n * Returns the schema value of the binding, if any was\n * created.\n *\n * @param type The type of the binding to read.\n * @returns The binding schema, if any\n * @example\n * ```typescript\n * const webBindings = association.readBinding('web');\n * if (webBindings) {\n * // ...\n * }\n * ```\n */\n readBinding(type: 'web' | 'protobuf'): AssociationBindings | undefined {\n const item = this.bindings.find((i) => i.type === type) as AssociationBinding\n return item?.schema || undefined\n }\n\n /**\n * Adds a target entity to the association.\n *\n * If the entity comes from another namespace then it is\n * set as a foreign entity.\n *\n * @param entity - The `DomainEntity` instance to add.\n * @example\n * ```typescript\n * association.addTarget(addressEntity);\n * ```\n */\n addTarget(entity: DomainEntity): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param entity - The `DomainEntity` definition or just\n * its key.\n * @param namespace - The key of the foreign namespace this\n * entity belongs to. Do not set this value for local\n * entities.\n * @example\n * ```typescript\n * association.addTarget('address', 'foreignNamespace');\n * ```\n */\n addTarget(entity: string, namespace?: string): void\n\n /**\n * Adds a target entity to the association.\n *\n * @param init The key of an entity, its instance, or schema.\n * @param namespace - The key of the foreign namespace this\n * entity belongs to. Do not set this value for local entities.\n */\n addTarget(init: string | DomainEntity, namespace?: string): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n if (init.domain.key !== this.root.key) {\n namespace = init.domain.key\n }\n }\n if (this.targets.some((i) => i.key === key && i.domain === namespace)) {\n const message = `Target ${key} already exists.`\n throw new Error(message)\n }\n if (namespace && !this.root.dependencies.has(namespace)) {\n throw new Error(`Foreign namespace \"${namespace}\" does not exist.`)\n }\n const info: AssociationTarget = {\n key,\n }\n if (namespace) {\n info.domain = namespace\n }\n this.targets.push(info)\n const targetKey = namespace ? `${namespace}:${key}` : key\n const label: DomainGraphEdge = {\n type: 'association',\n }\n if (namespace) {\n label.domain = namespace\n label.foreign = true\n }\n // We need to associate the target with the association\n // in the graph. This way, when looking for associations\n // on a target entities we can easily locate the\n // association.\n this.root.graph.setEdge(this.key, targetKey, label)\n // this.root.notifyChange()\n }\n\n /**\n * Removes a target entity from the targets list.\n *\n * @param init The key of an entity, its instance, or\n * schema.\n * @example\n * ```typescript\n * association.removeTarget(addressEntity);\n * ```\n */\n removeTarget(init: string | DomainEntity): void {\n let key: string\n if (typeof init === 'string') {\n key = init\n } else {\n key = init.key\n }\n const index = this.targets.findIndex((i) => i.key === key)\n if (index >= 0) {\n this.targets.splice(index, 1)\n // this.root.notifyChange()\n }\n this.root.graph.removeEdge(this.key, key)\n }\n\n /**\n * Lists all target entities of this association.\n *\n * @returns A generator that yields each target\n * `DomainEntity`.\n * @example\n * ```typescript\n * for (const target of association.listTargets()) {\n * console.log(target.key);\n * }\n * ```\n */\n *listTargets(): Generator<DomainEntity> {\n for (const target of this.targets) {\n const { key, domain } = target\n const targetKey = domain ? `${domain}:${key}` : key\n const entity = this.root.graph.node(targetKey) as DomainEntity | undefined\n if (entity) {\n yield entity\n }\n }\n }\n\n /**\n * Creates a Property Shape of AMF.\n * The property itself is auto-generated. If the `schema` is defined then it is used\n * as the `range` of the property. Otherwise basic shape is generated for the range.\n *\n * This is a preferred way of reading the AMF shape as this synchronizes changed\n * data properties with the shape definition.\n *\n * @returns AMF property shape definition.\n */\n toApiShape(): IApiPropertyShape {\n const serializer = new ShapeGenerator()\n return serializer.associationProperty(this)\n }\n\n /**\n * Adds or updates a semantic to the association.\n * @param semantic The semantic to add to the association.\n * @throws Error if the semantic is not an association semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isAssociationSemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an association semantic.`)\n }\n const index = this.semantics.findIndex((s) => s.id === semantic.id)\n if (index >= 0) {\n this.semantics[index] = semantic\n } else {\n this.semantics.push(semantic)\n }\n this.domain.notifyChange()\n }\n\n /**\n * Removes a semantic from the association.\n * @param semanticId The ID of the semantic to remove.\n */\n removeSemantic(semanticId: SemanticType): void {\n const index = this.semantics.findIndex((s) => s.id === semanticId)\n if (index >= 0) {\n this.semantics.splice(index, 1)\n this.domain.notifyChange()\n }\n }\n\n /**\n * Checks if the association has a specific semantic.\n * @param semanticId The ID of the semantic to check.\n * @returns True if the semantic is present, false otherwise.\n */\n hasSemantic(semanticId: SemanticType): boolean {\n return this.semantics.some((s) => s.id === semanticId)\n }\n}\n"]}
|
|
@@ -13,6 +13,14 @@ export declare enum SemanticType {
|
|
|
13
13
|
DeletedTimestamp = "https://apinow.app/semantics/properties/#DeletedTimestamp",
|
|
14
14
|
DeletedFlag = "https://apinow.app/semantics/properties/#DeletedFlag",
|
|
15
15
|
PublicUniqueName = "https://apinow.app/semantics/properties/#PublicUniqueName",
|
|
16
|
+
/**
|
|
17
|
+
* Designates a Data Property as the `role` of a user within the system.
|
|
18
|
+
* This is used to define the user's permissions and access levels.
|
|
19
|
+
* For example, a user with the role of "admin" would have elevated permissions
|
|
20
|
+
* compared to a user with the role of "guest".
|
|
21
|
+
* Roles are defined on the entity as enums, or as a string property with a controlled vocabulary.
|
|
22
|
+
*/
|
|
23
|
+
UserRole = "https://apinow.app/semantics/entities/#UserRole",
|
|
16
24
|
ResourceOwnerIdentifier = "https://apinow.app/semantics/associations/#ResourceOwnerIdentifier"
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Semantics.d.ts","sourceRoot":"","sources":["../../../src/modeling/Semantics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Semantics.d.ts","sourceRoot":"","sources":["../../../src/modeling/Semantics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAEzD;;;GAGG;AACH,oBAAY,YAAY;IAEtB;;OAEG;IACH,IAAI,gDAAgD;IAGpD,gBAAgB,8DAA8D;IAC9E,gBAAgB,8DAA8D;IAC9E,gBAAgB,8DAA8D;IAC9E,WAAW,yDAAyD;IACpE,gBAAgB,8DAA8D;IAC9E;;;;;;OAMG;IACH,QAAQ,oDAAoD;IAE5D,uBAAuB,uEAAuE;CAC/F;AAED;;GAEG;AACH,oBAAY,aAAa;IACvB,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,WAAW,gBAAgB;CAC5B;AAED;;;;;GAKG;AACH,UAAU,gBAAgB;IACxB;;OAEG;IACH,EAAE,EAAE,YAAY,CAAA;IAChB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB;;OAEG;IACH,KAAK,EAAE,aAAa,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,KAAK,EAAE,aAAa,CAAC,MAAM,CAAA;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,KAAK,EAAE,aAAa,CAAC,QAAQ,CAAA;IAC7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,CAAA;CAC3C;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,gBAAgB;IAC3D,KAAK,EAAE,aAAa,CAAC,WAAW,CAAA;CACjC;AAED;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,UAAU,YAAY,KAAG,QAAQ,IAAI,cAC7B,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,YAAY,KAAG,QAAQ,IAAI,gBAC7B,CAAA;AAE3C;;GAEG;AACH,eAAO,MAAM,qBAAqB,GAAI,UAAU,YAAY,KAAG,QAAQ,IAAI,mBAC7B,CAAA;AAE9C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,gBAAgB,GAAG,mBAAmB,CAAA;AAElF;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,YAAY,EAAE,YAAY,CA2D5D,CAAA;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,EAAE,EAAE,YAAY,CAAA;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACjC"}
|
|
@@ -15,6 +15,14 @@ export var SemanticType;
|
|
|
15
15
|
SemanticType["DeletedTimestamp"] = "https://apinow.app/semantics/properties/#DeletedTimestamp";
|
|
16
16
|
SemanticType["DeletedFlag"] = "https://apinow.app/semantics/properties/#DeletedFlag";
|
|
17
17
|
SemanticType["PublicUniqueName"] = "https://apinow.app/semantics/properties/#PublicUniqueName";
|
|
18
|
+
/**
|
|
19
|
+
* Designates a Data Property as the `role` of a user within the system.
|
|
20
|
+
* This is used to define the user's permissions and access levels.
|
|
21
|
+
* For example, a user with the role of "admin" would have elevated permissions
|
|
22
|
+
* compared to a user with the role of "guest".
|
|
23
|
+
* Roles are defined on the entity as enums, or as a string property with a controlled vocabulary.
|
|
24
|
+
*/
|
|
25
|
+
SemanticType["UserRole"] = "https://apinow.app/semantics/entities/#UserRole";
|
|
18
26
|
// Association-Level Semantics
|
|
19
27
|
SemanticType["ResourceOwnerIdentifier"] = "https://apinow.app/semantics/associations/#ResourceOwnerIdentifier";
|
|
20
28
|
})(SemanticType || (SemanticType = {}));
|
|
@@ -93,5 +101,12 @@ export const DataSemantics = {
|
|
|
93
101
|
description: 'A user-friendly, unique public identifier for a resource, often used in URLs.',
|
|
94
102
|
applicableDataTypes: ['string'],
|
|
95
103
|
},
|
|
104
|
+
[SemanticType.UserRole]: {
|
|
105
|
+
id: SemanticType.UserRole,
|
|
106
|
+
displayName: 'User Role Field',
|
|
107
|
+
scope: SemanticScope.Property,
|
|
108
|
+
description: 'A text field that is recognized by the runtime as a role of a user in the API. Used with the role-based authorization strategy.',
|
|
109
|
+
applicableDataTypes: ['string'],
|
|
110
|
+
},
|
|
96
111
|
};
|
|
97
112
|
//# sourceMappingURL=Semantics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Semantics.js","sourceRoot":"","sources":["../../../src/modeling/Semantics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Semantics.js","sourceRoot":"","sources":["../../../src/modeling/Semantics.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,CAAN,IAAY,YAuBX;AAvBD,WAAY,YAAY;IACtB,yBAAyB;IACzB;;OAEG;IACH,oEAAoD,CAAA;IAEpD,2BAA2B;IAC3B,8FAA8E,CAAA;IAC9E,8FAA8E,CAAA;IAC9E,8FAA8E,CAAA;IAC9E,oFAAoE,CAAA;IACpE,8FAA8E,CAAA;IAC9E;;;;;;OAMG;IACH,4EAA4D,CAAA;IAC5D,8BAA8B;IAC9B,8GAA8F,CAAA;AAChG,CAAC,EAvBW,YAAY,KAAZ,YAAY,QAuBvB;AAED;;GAEG;AACH,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,sCAAq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AAE,YAAY,CAAC,gBAAgB;QACjC,WAAW,EAAE,uBAAuB;QACpC,KAAK,EAAE,aAAa,CAAC,QAAQ;QAC7B,WAAW,EAAE,uEAAuE;QACpF,mBAAmB,EAAE,CAAC,UAAU,CAAC;KAClC;IACD,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE;QAC1B,EAAE,EAAE,YAAY,CAAC,WAAW;QAC5B,WAAW,EAAE,kBAAkB;QAC/B,KAAK,EAAE,aAAa,CAAC,QAAQ;QAC7B,WAAW,EAAE,qFAAqF;QAClG,mBAAmB,EAAE,CAAC,SAAS,CAAC;KACjC;IACD,CAAC,YAAY,CAAC,uBAAuB,CAAC,EAAE;QACtC,EAAE,EAAE,YAAY,CAAC,uBAAuB;QACxC,WAAW,EAAE,2BAA2B;QACxC,KAAK,EAAE,aAAa,CAAC,WAAW;QAChC,WAAW,EAAE,wFAAwF;KACtG;IACD,CAAC,YAAY,CAAC,gBAAgB,CAAC,EAAE;QAC/B,EAAE,EAAE,YAAY,CAAC,gBAAgB;QACjC,WAAW,EAAE,2BAA2B;QACxC,KAAK,EAAE,aAAa,CAAC,QAAQ;QAC7B,WAAW,EAAE,+EAA+E;QAC5F,mBAAmB,EAAE,CAAC,QAAQ,CAAC;KAChC;IACD,CAAC,YAAY,CAAC,QAAQ,CAAC,EAAE;QACvB,EAAE,EAAE,YAAY,CAAC,QAAQ;QACzB,WAAW,EAAE,iBAAiB;QAC9B,KAAK,EAAE,aAAa,CAAC,QAAQ;QAC7B,WAAW,EACT,iIAAiI;QACnI,mBAAmB,EAAE,CAAC,QAAQ,CAAC;KAChC;CACF,CAAA","sourcesContent":["/* eslint-disable max-len */\nimport type { DomainPropertyType } from './DataFormat.js'\n\n/**\n * Defines the names for all available data semantics.\n * Using a string enum makes it easy to add or remove semantics in a single place.\n */\nexport enum SemanticType {\n // Entity-Level Semantics\n /**\n * Designates a Data Entity that represents users of the system.\n */\n User = 'https://apinow.app/semantics/entities/#User',\n\n // Property-Level Semantics\n CreatedTimestamp = 'https://apinow.app/semantics/properties/#CreatedTimestamp',\n UpdatedTimestamp = 'https://apinow.app/semantics/properties/#UpdatedTimestamp',\n DeletedTimestamp = 'https://apinow.app/semantics/properties/#DeletedTimestamp',\n DeletedFlag = 'https://apinow.app/semantics/properties/#DeletedFlag',\n PublicUniqueName = 'https://apinow.app/semantics/properties/#PublicUniqueName',\n /**\n * Designates a Data Property as the `role` of a user within the system.\n * This is used to define the user's permissions and access levels.\n * For example, a user with the role of \"admin\" would have elevated permissions\n * compared to a user with the role of \"guest\".\n * Roles are defined on the entity as enums, or as a string property with a controlled vocabulary.\n */\n UserRole = 'https://apinow.app/semantics/entities/#UserRole',\n // Association-Level Semantics\n ResourceOwnerIdentifier = 'https://apinow.app/semantics/associations/#ResourceOwnerIdentifier',\n}\n\n/**\n * Defines the scope at which a semantic can be applied.\n */\nexport enum SemanticScope {\n Entity = 'Entity',\n Property = 'Property',\n Association = 'Association',\n}\n\n/**\n * A base interface for all Data Semantics, containing common properties.\n * A semantic is an annotation applied to a Data Entity, Property, or Association\n * to provide additional context or constraints.\n * This interface is extended by more specific semantic types.\n */\ninterface BaseDataSemantic {\n /**\n * A unique identifier for the semantic definition.\n */\n id: SemanticType\n /**\n * A human-readable name for the semantic.\n */\n displayName: string\n /**\n * A description of the semantic's purpose and impact.\n */\n description: string\n /**\n * Specifies whether the semantic applies to an Entity, Property, or Association.\n */\n scope: SemanticScope\n}\n\n/**\n * Represents a semantic that can be applied to an entire Data Entity.\n */\nexport interface EntitySemantic extends BaseDataSemantic {\n scope: SemanticScope.Entity\n}\n\n/**\n * Represents a semantic that can be applied to a single property.\n */\nexport interface PropertySemantic extends BaseDataSemantic {\n scope: SemanticScope.Property\n /**\n * Optional array of data types this semantic can be applied to.\n * Enforces constraints, e.g., DeletedTimestamp on a DateTime property.\n */\n applicableDataTypes?: DomainPropertyType[]\n}\n\n/**\n * Represents a semantic that can be applied to an association between entities.\n */\nexport interface AssociationSemantic extends BaseDataSemantic {\n scope: SemanticScope.Association\n}\n\n/**\n * A type guard to check if a semantic is an EntitySemantic.\n */\nexport const isEntitySemantic = (semantic: DataSemantic): semantic is EntitySemantic =>\n semantic.scope === SemanticScope.Entity\n\n/**\n * A type guard to check if a semantic is a PropertySemantic.\n */\nexport const isPropertySemantic = (semantic: DataSemantic): semantic is PropertySemantic =>\n semantic.scope === SemanticScope.Property\n\n/**\n * A type guard to check if a semantic is a AssociationSemantic.\n */\nexport const isAssociationSemantic = (semantic: DataSemantic): semantic is AssociationSemantic =>\n semantic.scope === SemanticScope.Association\n\n/**\n * Union type for any kind of data semantic\n */\nexport type DataSemantic = EntitySemantic | PropertySemantic | AssociationSemantic\n\n/**\n * A map to store the definitions of all available data semantics.\n * This acts as a central registry for the application.\n */\nexport const DataSemantics: Record<SemanticType, DataSemantic> = {\n // Entity-Level Definitions\n [SemanticType.User]: {\n id: SemanticType.User,\n displayName: 'User Entity',\n scope: SemanticScope.Entity,\n description: 'Designates an entity that represents system users, crucial for authentication and authorization.',\n },\n\n // Property-Level Definitions\n [SemanticType.CreatedTimestamp]: {\n id: SemanticType.CreatedTimestamp,\n displayName: 'Creation Timestamp',\n scope: SemanticScope.Property,\n description: \"Marks a field as the one that contains the object's creation timestamp.\",\n applicableDataTypes: ['datetime'],\n },\n [SemanticType.UpdatedTimestamp]: {\n id: SemanticType.UpdatedTimestamp,\n displayName: 'Update Timestamp',\n scope: SemanticScope.Property,\n description: \"Marks a field as the field that contains object's last modification timestamp.\",\n applicableDataTypes: ['datetime'],\n },\n [SemanticType.DeletedTimestamp]: {\n id: SemanticType.DeletedTimestamp,\n displayName: 'Soft Delete Timestamp',\n scope: SemanticScope.Property,\n description: \"Marks a field as the field that contains object's deletion timestamp.\",\n applicableDataTypes: ['datetime'],\n },\n [SemanticType.DeletedFlag]: {\n id: SemanticType.DeletedFlag,\n displayName: 'Soft Delete Flag',\n scope: SemanticScope.Property,\n description: 'A boolean property that marks the object as deleted without physically removing it.',\n applicableDataTypes: ['boolean'],\n },\n [SemanticType.ResourceOwnerIdentifier]: {\n id: SemanticType.ResourceOwnerIdentifier,\n displayName: 'Resource Owner Identifier',\n scope: SemanticScope.Association,\n description: 'Links a resource to a \"User\" entity instance, indicating ownership for access control.',\n },\n [SemanticType.PublicUniqueName]: {\n id: SemanticType.PublicUniqueName,\n displayName: 'Public Unique Name (Slug)',\n scope: SemanticScope.Property,\n description: 'A user-friendly, unique public identifier for a resource, often used in URLs.',\n applicableDataTypes: ['string'],\n },\n [SemanticType.UserRole]: {\n id: SemanticType.UserRole,\n displayName: 'User Role Field',\n scope: SemanticScope.Property,\n description:\n 'A text field that is recognized by the runtime as a role of a user in the API. Used with the role-based authorization strategy.',\n applicableDataTypes: ['string'],\n },\n}\n\n/**\n * Represents the application of a data semantic to a specific\n * entity or property within a user's data model.\n */\nexport interface AppliedDataSemantic {\n /**\n * The unique identifier of the semantic being applied.\n */\n id: SemanticType\n\n /**\n * Optional configuration or values specific to this application.\n */\n config?: Record<string, unknown>\n}\n"]}
|