@api-client/core 0.20.4 → 0.20.6

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.
Files changed (33) hide show
  1. package/build/src/modeling/ApiModel.d.ts.map +1 -1
  2. package/build/src/modeling/ApiModel.js +9 -2
  3. package/build/src/modeling/ApiModel.js.map +1 -1
  4. package/build/src/modeling/DataDomain.d.ts +9 -3
  5. package/build/src/modeling/DataDomain.d.ts.map +1 -1
  6. package/build/src/modeling/DataDomain.js +25 -6
  7. package/build/src/modeling/DataDomain.js.map +1 -1
  8. package/build/src/modeling/DependentModel.d.ts +4 -0
  9. package/build/src/modeling/DependentModel.d.ts.map +1 -1
  10. package/build/src/modeling/DependentModel.js.map +1 -1
  11. package/build/src/modeling/DomainEntity.d.ts +20 -0
  12. package/build/src/modeling/DomainEntity.d.ts.map +1 -1
  13. package/build/src/modeling/DomainEntity.js +93 -0
  14. package/build/src/modeling/DomainEntity.js.map +1 -1
  15. package/build/src/modeling/RuntimeApiModel.d.ts +22 -0
  16. package/build/src/modeling/RuntimeApiModel.d.ts.map +1 -1
  17. package/build/src/modeling/RuntimeApiModel.js +102 -1
  18. package/build/src/modeling/RuntimeApiModel.js.map +1 -1
  19. package/build/src/modeling/types.d.ts +20 -20
  20. package/build/src/modeling/types.d.ts.map +1 -1
  21. package/build/src/modeling/types.js.map +1 -1
  22. package/build/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +1 -1
  24. package/src/modeling/ApiModel.ts +8 -2
  25. package/src/modeling/DataDomain.ts +27 -7
  26. package/src/modeling/DependentModel.ts +4 -0
  27. package/src/modeling/DomainEntity.ts +100 -0
  28. package/src/modeling/RuntimeApiModel.ts +124 -2
  29. package/src/modeling/types.ts +21 -20
  30. package/tests/unit/modeling/RuntimeApiModel.spec.ts +91 -0
  31. package/tests/unit/modeling/data_domain_entities.spec.ts +56 -0
  32. package/tests/unit/modeling/data_domain_serialization.spec.ts +11 -11
  33. package/tests/unit/modeling/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ACX,CAAC;YAED,OAAO,OAAO,CAAA;QAChB,CAAC;;;SAl3BU,YAAY","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind, DomainEntityKind, DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type ThingSchema, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from '../decorators/observed.js'\nimport type { Shapes, IShapeRenderOptions } from '@api-client/amf-core'\nimport { ApiSchemaGenerator } from '@api-client/amf-core'\nimport { DomainProperty, type DomainPropertySchema } from './DomainProperty.js'\nimport { RemovePropertyException } from '../exceptions/remove_property_exception.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport type { DomainModel } from './DomainModel.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport { ValidationError } from '../exceptions/validation_error.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { DataSemantics, isEntitySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\nexport interface EntityOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'property' | 'association'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainEntitySchema extends DomainElementSchema {\n kind: typeof DomainEntityKind\n /**\n * The domain entity description.\n */\n info: ThingSchema\n\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n\n /**\n * The semantics applied to this entity.\n * This is a list of applied semantics that can be used to\n * describe the entity in more detail.\n */\n semantics?: AppliedDataSemantic[]\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n fields?: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents an entity within a data domain model.\n *\n * A `DomainEntity` defines a structured data type,\n * containing properties and associations. It's a\n * fundamental building block for modeling complex data\n * structures.\n *\n * **Key Features:**\n *\n * - **Properties:** Defines the data elements (fields) within the entity.\n * - **Associations:** Defines relationships to other entities.\n * - **Inheritance:** Supports inheriting properties and associations from parent entities.\n * - **Metadata:** Supports tags, semantics, and deprecation status.\n * - **AMF Shape Generation:** Can be serialized to an AMF (API Modeling Framework) shape.\n * - **Example Generation:** Can generate example databased on its schema.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainEntity` is through\n * the `DomainModel.addEntity()` 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 * ```\n *\n * Entity Validation Rules:\n *\n * - **Primary Key:** An entity must have a primary key selected. This can come from a parent\n * entity or be defined in the current entity.\n * - **Parent Entity:** The parent entity must exist in the graph.\n * - **Circular Dependency:** Adding a parent entity that creates a circular dependency is not allowed.\n * - **Unique Parent:** An entity cannot have the same parent more than once.\n * - **Property Shadowing:** A property can shadow a parent property. This means that if a property\n * with the same key exists in both the parent and child entity, the child property will take precedence.\n * - **Association Shadowing:** An association can shadow a parent association. This means that if an\n * association with the same key exists in both the parent and child entity,\n * the child association will take precedence.\n * - **Property Resolution:** When the same property exists more than one parent and the child entity,\n * doesn't explicitly define the property, then:\n * - The last parent entity (iterating from the first entity to the last) that has the property\n * will be used as the source of the property.\n * - **Association Resolution:** When the same association exists more than one parent and the child entity,\n * doesn't explicitly define the association, then:\n * - The last parent entity (iterating from the first entity to the last) that has the association\n * will be used as the source of the association.\n * - **Minimum Required Properties:** An entity must have at least one property defined. Entities without properties\n * are ignored in the system.\n * - **Entity Name**:\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a SQL database. This means that the name must be unique\n * within the data domain and cannot contain special characters.\n * - **Association Targets:** An association must have a target entity defined.\n * This means that the association must point to at least one entity.\n */\nexport class DomainEntity extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainEntityKind\n\n /**\n * The description of the domain entity.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Optional general purpose tags for the UI.\n */\n @observed({ deep: true }) accessor tags: string[]\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n accessor fields: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data entity schema with defaults.\n *\n * @param input The partial data entity schema.\n * @returns The data entity schema.\n */\n static createSchema(input: Partial<DomainEntitySchema> = {}): DomainEntitySchema {\n const { key = nanoid(), tags, semantics, fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'new_entity' }).toJSON()\n const result: DomainEntitySchema = {\n kind: DomainEntityKind,\n key,\n info,\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n return result\n }\n\n /**\n * Creates a new domain entity instance.\n *\n * You probably want to use the `DomainModel.addEntity()`\n * method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial domain entity schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainEntitySchema>) {\n const init = DomainEntity.createSchema(input)\n super(root, init.key)\n this.kind = DomainEntityKind\n this.info = new Thing(init.info)\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n }\n }\n\n /**\n * Generates a JSON representation of the entity.\n *\n * @returns A plain object representation of the `DomainEntity`.\n */\n toJSON(): DomainEntitySchema {\n const result: DomainEntitySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...(toRaw(this, this.tags) as string[])]\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property\n * exist.\n *\n * @returns The parent `DomainModel` or undefined if not found.\n * @example\n * ```typescript\n * const parent = entity.getParentInstance();\n * if (parent) {\n * console.log(parent.key);\n * }\n * ```\n */\n getParentInstance(): DomainModel | undefined {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return undefined\n }\n return this.root.graph.node(parentKey) as DomainModel | undefined\n }\n\n /**\n * Adds a property to this entity.\n *\n * @param property The partial property schema.\n * @returns The created `DomainProperty` instance.\n * @example\n * ```typescript\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * })\n * ```\n */\n addProperty(property?: Partial<DomainPropertySchema>): DomainProperty {\n if (property && property.key && this.root.graph.hasNode(property.key)) {\n throw new Error(`Trying to add a property ${property.key}, but it already exists`)\n }\n const instance = new DomainProperty(this.root, this.key, property)\n this.root.graph.setNode(instance.key, instance)\n this.root.graph.setEdge(this.key, instance.key, { type: 'property' })\n this.fields.push({\n type: 'property',\n key: instance.key,\n })\n this.root.notifyChange()\n return instance\n }\n\n /**\n * Removes a property from this entity.\n *\n * @param key The key of the property to remove.\n * @throws {RemovePropertyException} When the property does not exist.\n * @example\n * ```typescript\n * entity.removeProperty('name')\n * ```\n */\n removeProperty(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't exist`)\n }\n const prop = this.root.graph.node(key) as DomainProperty\n if (prop.getParentInstance() !== this) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't belong to this entity`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listProperties()`.\n */\n get properties(): Generator<DomainProperty> {\n return this.listProperties()\n }\n\n /**\n * Lists all properties of this entity.\n *\n * Note, it accounts for the order of the properties as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainProperty`.\n * @example\n * ```typescript\n * for (const property of entity.listProperties()) {\n * console.log(property.key);\n * }\n * ```\n */\n *listProperties(): Generator<DomainProperty> {\n for (const { key, type } of this.fields) {\n if (type !== 'property') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainPropertyKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Collects a list of all properties that affect this entity,\n * including all inherited from parents properties as well as\n * this entity's properties.\n *\n * The resulting list already accounts for a property override.\n * A property overrides another property if it is lower in the\n * inheritance chain. As such, a property defined on this entity\n * always overrides previously defined entities.\n * @returns The iterator over the list of all properties.\n */\n withInheritedProperties(): MapIterator<DomainProperty> {\n const cache = new Map<string, DomainProperty>()\n const parents = this.listAllParents('up')\n for (const parent of parents) {\n for (const prop of parent.properties) {\n if (!prop.info.name) {\n continue\n }\n // We want to override the previously set property\n // so the last definition wins.\n cache.set(prop.info.name, prop)\n }\n }\n for (const prop of this.properties) {\n if (!prop.info.name) {\n continue\n }\n cache.set(prop.info.name, prop)\n }\n return cache.values()\n }\n\n /**\n * Checks if this entity has any properties.\n *\n * @returns True if the entity has properties.\n * @example\n * ```typescript\n * if (entity.hasProperties()) {\n * // ...\n * }\n * ```\n */\n hasProperties(): boolean {\n return this.fields.some((item) => item.type === 'property')\n }\n\n /**\n * A shortcut to `listParents()`.\n */\n get parents(): Generator<DomainEntity> {\n return this.listParents()\n }\n\n /**\n * Lists all parent entities of this entity (only the first level).\n *\n * @returns A generator that yields each parent `DomainEntity`.\n * @example\n * ```typescript\n * for (const parent of entity.listParents()) {\n * console.log(parent.key);\n * }\n * ```\n */\n *listParents(): Generator<DomainEntity> {\n for (const edge of this.root.graph.outEdges(this.key)) {\n const value = this.root.graph.edge(edge)\n if (!value || value.type !== 'parent') {\n continue\n }\n const parent = this.root.graph.node(edge.w) as DomainEntity\n if (parent) {\n yield parent\n }\n }\n }\n\n /**\n * Lists all parent entities recursively.\n *\n * @param direction The direction of the traversal. 'up' (default) lists from immediate parents up to the oldest.\n * 'down' lists from the oldest parents down to the immediate parents.\n * @returns An array of parent `DomainEntity` instances, ordered according to the requested traversal direction.\n */\n listAllParents(direction: 'up' | 'down' = 'up'): DomainEntity[] {\n const visited = new Set<string>()\n const parents: DomainEntity[] = []\n const queue: DomainEntity[] = [...this.listParents()]\n\n let index = 0\n while (index < queue.length) {\n const parent = queue[index++]\n if (!visited.has(parent.key)) {\n visited.add(parent.key)\n parents.push(parent)\n queue.push(...parent.listParents())\n }\n }\n\n if (direction === 'down') {\n parents.reverse()\n }\n\n return parents\n }\n\n /**\n * Adds a parent to this entity.\n *\n * @param key The key of the parent entity.\n * @param domain The key of the foreign domain the parent belongs to.\n * @returns `this` for chaining.\n * @throws ValidationError When the parent does not exist or a circular dependency is detected.\n * @example\n * ```typescript\n * entity.addParent('baseEntity');\n * ```\n */\n addParent(key: string, domain?: string): this {\n const effectiveKey = this.domain.buildReferenceKey(key, domain)\n // Prevent adding self as parent\n if (effectiveKey === this.key) {\n const message = 'Entity cannot be a parent of itself'\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n const { graph } = this.root\n if (!graph.hasNode(effectiveKey)) {\n let message = `Entity with key \"${key}\" not found`\n if (domain) {\n message += ` in domain \"${domain}\"`\n }\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'required',\n },\n ],\n { message }\n )\n }\n // Check for circular inheritance\n if (this.hasCircularParent(effectiveKey)) {\n const message = `Circular inheritance detected. Cannot add ${key} as a parent`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n if (graph.outEdges(this.key, effectiveKey).next().value) {\n const message = `Parent ${key} already exists`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'unique',\n },\n ],\n { message }\n )\n }\n // Parents are associated through graph edges.\n // Otherwise it would collide with the parent model.\n if (domain) {\n graph.setEdge(this.key, effectiveKey, { type: 'parent', domain, foreign: true })\n } else {\n graph.setEdge(this.key, effectiveKey, { type: 'parent' })\n }\n this.root.notifyChange()\n return this\n }\n\n /**\n * Removes a parent from this entity.\n *\n * @param key The key of the parent entity to remove.\n * @param domain Optional domain key if the parent belongs to a foreign domain.\n * @returns `this` for chaining.\n * @throws Error When the parent does not exist.\n * @example\n * ```typescript\n * // Remove local parent\n * entity.removeParent('baseEntity');\n *\n * // Remove foreign domain parent\n * entity.removeParent('baseEntity', 'externalDomain');\n * ```\n */\n removeParent(key: string, domain?: string): this {\n const { graph } = this.root\n const effectiveKey = this.domain.buildReferenceKey(key, domain)\n\n if (!graph.hasEdge(this.key, effectiveKey)) {\n let message = `Trying to remove a parent ${key} from ${this.key}, but it doesn't exist`\n if (domain) {\n message = `Trying to remove a foreign parent ${key} from domain \"${domain}\" from ${this.key}, but it doesn't exist`\n }\n throw new Error(message)\n }\n\n // Verify it's actually a parent edge\n const edge = graph.edge(this.key, effectiveKey)\n if (!edge || edge.type !== 'parent') {\n let message = `Edge between ${this.key} and ${key} exists but is not a parent relationship`\n if (domain) {\n message = `Edge between ${this.key} and ${key} in domain \"${domain}\" exists but is not a parent relationship`\n }\n throw new Error(message)\n }\n\n graph.removeEdge(this.key, effectiveKey)\n this.root.notifyChange()\n return this\n }\n\n /**\n * Checks if this entity has any parents.\n *\n * @returns True if the entity has parents.\n * @example\n * ```typescript\n * if (entity.hasParents()) {\n * // ...\n * }\n * ```\n */\n hasParents(): boolean {\n for (const edge of this.root.graph.outEdges(this.key)) {\n if (this.root.graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n return false\n }\n\n /**\n * Checks if the passed entity has a circular parent\n * relationship when attempting to add a new parent.\n *\n * @param key The key of the parent being added.\n * @returns True if adding this parent would create a\n * circular relationship.\n */\n hasCircularParent(key: string): boolean {\n const { graph } = this.root\n\n // Check if new parent is one of the children.\n for (const edge of graph.outEdges(key, this.key)) {\n if (graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n\n // check if this entity is in parents chain.\n let current: DomainEntity | undefined = graph.node(key) as DomainEntity | undefined\n while (current) {\n if (current.key === this.key) {\n return true\n }\n const parents = [...current.listParents()]\n if (parents.length === 0) {\n break\n }\n // Assuming single inheritance\n // TODO: Update this to check for multiple parents.\n current = parents[0]\n }\n\n return false\n }\n\n /**\n * Creates breadcrumbs from this entity to the root\n * namespace.\n *\n * @returns An array of `FileBreadcrumb` instances.\n * @example\n * ```typescript\n * const breadcrumbs = entity.breadcrumbs();\n * console.log(breadcrumbs);\n * ```\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed entity'),\n kind: DomainEntityKind,\n })\n const model = this.getParentInstance()\n if (model) {\n result.push({\n key: model.key,\n kind: model.kind,\n name: model.info.getLabel('Unnamed model'),\n })\n let parent: DataDomain | DomainNamespace = model.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.getLabel('Unnamed namespace'),\n })\n const typed = parent as DomainNamespace\n parent = typed.getParentInstance()\n }\n }\n result.push({\n key: this.root.key,\n name: this.root.info.getLabel('Unnamed data domain'),\n kind: this.root.kind,\n })\n return result.reverse()\n }\n\n /**\n * Adds an association to this entity.\n *\n * Add rules:\n * - If the target is specified, it has to exist in the graph.\n * - The association targets can be local or foreign.\n *\n * Please note that you can't just add targets to the association schema.\n * This function manipulates the graph to insert the required metadata.\n *\n * @param input The partial association schema.\n * @returns The created `DomainAssociation` instance.\n * @throws Error When the target entity does not exist.\n * @example\n * ```typescript\n * const association = entity.addAssociation({ info: { name: 'Address' }, targets: [{ key: 'address' }] });\n * ```\n */\n addAssociation(input: Partial<DomainAssociationSchema> = {}): DomainAssociation {\n const { graph } = this.root\n\n // clean up any target information from the input\n // so we won't break the graph and the app.\n const inputCopy = { ...input }\n const targets = inputCopy.targets\n delete inputCopy.targets\n\n const hasTargets = Array.isArray(targets) && targets.length\n if (hasTargets) {\n for (const target of targets) {\n if (target.domain && target.key) {\n // target is foreign\n const foreignKey = `${target.domain}:${target.key}`\n if (!graph.hasNode(foreignKey)) {\n throw new Error(`Foreign entity ${foreignKey} not found`)\n }\n } else if (target.key) {\n if (!graph.hasNode(target.key)) {\n throw new Error(`Target entity ${target.key} not found`)\n }\n }\n }\n }\n\n const item = new DomainAssociation(this.root, this.key, inputCopy)\n graph.setNode(item.key, item)\n graph.setEdge(this.key, item.key, { type: 'association' })\n if (hasTargets) {\n for (const target of targets) {\n item.addTarget(target.key, target.domain)\n }\n }\n this.fields.push({ type: 'association', key: item.key })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an association from this entity.\n *\n * @param key The key of the association to remove.\n * @throws Error When the association does not exist.\n * @example\n * ```typescript\n * entity.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): void {\n if (!this.root.graph.hasEdge(this.key, key)) {\n throw new Error(`Unable to find a connection between this entity and the ${key} association`)\n }\n const edge = this.root.graph.edge(this.key, key)\n if (!edge || edge.type !== 'association') {\n throw new Error(`Association ${key} does not exist`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listAssociations()`.\n */\n get associations(): Generator<DomainAssociation> {\n return this.listAssociations()\n }\n\n /**\n * Lists all associations of this entity.\n *\n * The order of the associations is defined in the `fields` array.\n *\n * @returns A generator that yields each\n * `DomainAssociation`.\n * @example\n * ```typescript\n * for (const association of entity.listAssociations()) {\n * console.log(association.key);\n * }\n * ```\n */\n *listAssociations(): Generator<DomainAssociation> {\n for (const { key, type } of this.fields) {\n if (type !== 'association') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainAssociationKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any associations.\n *\n * @returns True if the entity has associations.\n * @example\n * ```typescript\n * if (entity.hasAssociations()) {\n * // ...\n * }\n * ```\n */\n hasAssociations(): boolean {\n return this.fields.some((item) => item.type === 'association')\n }\n\n /**\n * Lists all fields (properties and associations) of this entity.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of entity.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainAssociation | DomainProperty> {\n for (const { key } of this.fields) {\n const node = this.root.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainAssociationKind || node.kind === DomainPropertyKind) {\n yield node\n }\n }\n }\n\n /**\n * Checks if this entity has any fields (properties or associations).\n *\n * @returns True if the entity has fields.\n * @example\n * ```typescript\n * if (entity.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Creates an AMF's data Shape.\n *\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(): Shapes.IShapeUnion {\n const serializer = new ShapeGenerator()\n return serializer.entity(this)\n }\n\n /**\n * Reads the schema of the Entity and generates an example for it.\n *\n * @param mime The mime type of the example.\n * @param opts The example generation options.\n * @returns The generated example.\n * @example\n * ```typescript\n * const example = entity.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n const shape = this.toApiShape()\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Checks whether the entity is a child of the given namespace or data model.\n * The relationship doesn't have to be direct, as long as the entity\n * is in the hierarchy it will return true.\n *\n * @param key The key of the parent to check.\n * @returns True if this entity is a child of the given namespace or data model.\n */\n isChildOf(key: string): boolean {\n if (this.key === key) {\n return false\n }\n const parent = this.getParentInstance()\n if (!parent) {\n return false\n }\n if (parent.key === key) {\n return true\n }\n return parent.isChildOf(key)\n }\n\n /**\n * Finds the primary key property of this entity.\n * @returns The primary key property of this entity or undefined if not found.\n */\n primaryKey(): DomainProperty | undefined {\n for (const property of this.properties) {\n if (property.primary) {\n return property\n }\n }\n let property: DomainProperty | undefined\n for (const parent of this.listParents()) {\n const prop = parent.primaryKey()\n if (prop) {\n // According to the validation rules, the last parent\n // that has the property will be used as the source of\n // the property.\n // In the future, we may add a schema definition to the entity that\n // will explicitly define which property to use.\n property = prop\n }\n }\n return property\n }\n\n /**\n * Adds or updates a semantic to the entity.\n * @param semantic The semantic to add to the entity.\n * @throws Error if the semantic is not an entity semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isEntitySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an entity 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 entity.\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 entity 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 /**\n * Generates a unique name by appending a number to the base name.\n * @param baseName The base name to make unique.\n * @returns A unique name within the current entity.\n */\n generateUniqueName(baseName: string): string {\n const existingNames = new Set<string>()\n for (const field of this.listFields()) {\n if (field.info.name) {\n existingNames.add(field.info.name)\n }\n }\n\n let counter = 2\n let newName = `${baseName}_copy`\n while (existingNames.has(newName)) {\n newName = `${baseName}_copy_${counter}`\n counter++\n }\n\n return newName\n }\n}\n"]}
1
+ {"version":3,"file":"DomainEntity.js","sourceRoot":"","sources":["../../../src/modeling/DomainEntity.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAChG,OAAO,EAAE,aAAa,EAA4B,MAAM,oBAAoB,CAAA;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAoB,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC5D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAE3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AACzD,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAA;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,4CAA4C,CAAA;AACpF,OAAO,EAAE,iBAAiB,EAA2B,MAAM,wBAAwB,CAAA;AAInF,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,gBAA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AAK,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC,CAAA;YAChD,IAAI,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACvB,IAAI,CAAC,kBAAkB,GAAG,MAAM,CAAA;YAClC,CAAC;YACD,OAAO,MAAM,CAAA;QACf,CAAC;QAED;;;;WAIG;QACH,kBAAkB,CAAC,QAAgB;YACjC,MAAM,aAAa,GAAG,IAAI,GAAG,EAAU,CAAA;YACvC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;gBACtC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;oBACpB,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACpC,CAAC;YACH,CAAC;YAED,IAAI,OAAO,GAAG,CAAC,CAAA;YACf,IAAI,OAAO,GAAG,GAAG,QAAQ,OAAO,CAAA;YAChC,OAAO,aAAa,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;gBAClC,OAAO,GAAG,GAAG,QAAQ,SAAS,OAAO,EAAE,CAAA;gBACvC,OAAO,EAAE,CAAA;YACX,CAAC;YAED,OAAO,OAAO,CAAA;QAChB,CAAC;;;SAt9BU,YAAY","sourcesContent":["import type { DataDomain } from './DataDomain.js'\nimport { DomainAssociationKind, DomainEntityKind, DomainPropertyKind } from '../models/kinds.js'\nimport { DomainElement, type DomainElementSchema } from './DomainElement.js'\nimport { nanoid } from '../nanoid.js'\nimport { type ThingSchema, Thing } from '../models/Thing.js'\nimport { observed, retargetChange, toRaw } from '../decorators/observed.js'\nimport type { Shapes, IShapeRenderOptions } from '@api-client/amf-core'\nimport { ApiSchemaGenerator } from '@api-client/amf-core'\nimport { DomainProperty, type DomainPropertySchema } from './DomainProperty.js'\nimport { RemovePropertyException } from '../exceptions/remove_property_exception.js'\nimport { DomainAssociation, DomainAssociationSchema } from './DomainAssociation.js'\nimport type { FileBreadcrumb } from '../models/store/File.js'\nimport type { DomainModel } from './DomainModel.js'\nimport type { DomainNamespace } from './DomainNamespace.js'\nimport { ValidationError } from '../exceptions/validation_error.js'\nimport { ShapeGenerator } from './amf/ShapeGenerator.js'\nimport { removeGraphNode } from './GraphUtils.js'\nimport { DataSemantics, isEntitySemantic, type SemanticType, type AppliedDataSemantic } from './Semantics.js'\n\nexport interface EntityOrderedItem {\n /**\n * The type of the ordered item.\n */\n type: 'property' | 'association'\n\n /**\n * The key of the ordered item.\n */\n key: string\n}\n\nexport interface DomainEntitySchema extends DomainElementSchema {\n kind: typeof DomainEntityKind\n /**\n * The domain entity description.\n */\n info: ThingSchema\n\n /**\n * Optional general purpose tags for the UI.\n */\n tags?: string[]\n\n /**\n * The semantics applied to this entity.\n * This is a list of applied semantics that can be used to\n * describe the entity in more detail.\n */\n semantics?: AppliedDataSemantic[]\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n fields?: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n deprecated?: boolean\n}\n\n/**\n * Represents an entity within a data domain model.\n *\n * A `DomainEntity` defines a structured data type,\n * containing properties and associations. It's a\n * fundamental building block for modeling complex data\n * structures.\n *\n * **Key Features:**\n *\n * - **Properties:** Defines the data elements (fields) within the entity.\n * - **Associations:** Defines relationships to other entities.\n * - **Inheritance:** Supports inheriting properties and associations from parent entities.\n * - **Metadata:** Supports tags, semantics, and deprecation status.\n * - **AMF Shape Generation:** Can be serialized to an AMF (API Modeling Framework) shape.\n * - **Example Generation:** Can generate example databased on its schema.\n *\n * **Usage:**\n *\n * The preferred way to create a `DomainEntity` is through\n * the `DomainModel.addEntity()` 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 * ```\n *\n * Entity Validation Rules:\n *\n * - **Primary Key:** An entity must have a primary key selected. This can come from a parent\n * entity or be defined in the current entity.\n * - **Parent Entity:** The parent entity must exist in the graph.\n * - **Circular Dependency:** Adding a parent entity that creates a circular dependency is not allowed.\n * - **Unique Parent:** An entity cannot have the same parent more than once.\n * - **Property Shadowing:** A property can shadow a parent property. This means that if a property\n * with the same key exists in both the parent and child entity, the child property will take precedence.\n * - **Association Shadowing:** An association can shadow a parent association. This means that if an\n * association with the same key exists in both the parent and child entity,\n * the child association will take precedence.\n * - **Property Resolution:** When the same property exists more than one parent and the child entity,\n * doesn't explicitly define the property, then:\n * - The last parent entity (iterating from the first entity to the last) that has the property\n * will be used as the source of the property.\n * - **Association Resolution:** When the same association exists more than one parent and the child entity,\n * doesn't explicitly define the association, then:\n * - The last parent entity (iterating from the first entity to the last) that has the association\n * will be used as the source of the association.\n * - **Minimum Required Properties:** An entity must have at least one property defined. Entities without properties\n * are ignored in the system.\n * - **Entity Name**:\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a SQL database. This means that the name must be unique\n * within the data domain and cannot contain special characters.\n * - **Association Targets:** An association must have a target entity defined.\n * This means that the association must point to at least one entity.\n */\nexport class DomainEntity extends DomainElement {\n /**\n * The kind of the domain element.\n */\n override kind: typeof DomainEntityKind\n\n /**\n * Cached inherited properties.\n */\n #inheritedPropertiesCache?: DomainProperty[]\n\n /**\n * Cached parent entities arrays.\n */\n #allParentsCache?: Record<'up' | 'down', DomainEntity[]>\n\n /**\n * Cached inherited associations.\n */\n #inheritedAssociationsCache?: DomainAssociation[]\n\n /**\n * Cached semantics across the inheritance chain.\n */\n #allSemanticsCache?: AppliedDataSemantic[]\n\n /**\n * The description of the domain entity.\n */\n @retargetChange() accessor info: Thing\n\n /**\n * Optional general purpose tags for the UI.\n */\n @observed({ deep: true }) accessor tags: string[]\n\n /**\n * Semantics applied to this property.\n */\n @observed({ deep: true }) accessor semantics: AppliedDataSemantic[] = []\n\n /**\n * The ordered list of fields (properties and associations) in the schema.\n * These only keep references to the properties and associations.\n * The order of the fields is important as it defines the order of the\n * properties in the schema.\n */\n accessor fields: EntityOrderedItem[]\n\n /**\n * Whether this entity is deprecated.\n */\n @observed() accessor deprecated: boolean | undefined\n\n /**\n * Creates a full data entity schema with defaults.\n *\n * @param input The partial data entity schema.\n * @returns The data entity schema.\n */\n static createSchema(input: Partial<DomainEntitySchema> = {}): DomainEntitySchema {\n const { key = nanoid(), tags, semantics, fields, deprecated } = input\n const info = Thing.fromJSON(input.info, { name: 'new_entity' }).toJSON()\n const result: DomainEntitySchema = {\n kind: DomainEntityKind,\n key,\n info,\n }\n if (Array.isArray(tags)) {\n result.tags = [...tags]\n }\n if (Array.isArray(semantics)) {\n result.semantics = [...semantics]\n }\n if (Array.isArray(fields)) {\n result.fields = [...fields]\n }\n if (typeof deprecated === 'boolean') {\n result.deprecated = deprecated\n }\n return result\n }\n\n /**\n * Creates a new domain entity instance.\n *\n * You probably want to use the `DomainModel.addEntity()`\n * method instead.\n *\n * @param root A reference to the root DataDomain instance.\n * @param input The partial domain entity schema.\n */\n constructor(root: DataDomain, input?: Partial<DomainEntitySchema>) {\n const init = DomainEntity.createSchema(input)\n super(root, init.key)\n this.kind = DomainEntityKind\n this.info = new Thing(init.info)\n if (Array.isArray(init.tags)) {\n this.tags = [...init.tags]\n } else {\n this.tags = []\n }\n if (Array.isArray(init.semantics)) {\n this.semantics = init.semantics.map((item) => structuredClone(item))\n } else {\n this.semantics = []\n }\n if (Array.isArray(init.fields)) {\n this.fields = [...init.fields]\n } else {\n this.fields = []\n }\n if (typeof init.deprecated === 'boolean') {\n this.deprecated = init.deprecated\n }\n }\n\n /**\n * Generates a JSON representation of the entity.\n *\n * @returns A plain object representation of the `DomainEntity`.\n */\n toJSON(): DomainEntitySchema {\n const result: DomainEntitySchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n }\n if (Array.isArray(this.fields) && this.fields.length) {\n result.fields = [...this.fields]\n }\n if (Array.isArray(this.semantics) && this.semantics.length) {\n result.semantics = toRaw(this, this.semantics)?.map((i) => structuredClone(i))\n }\n if (Array.isArray(this.tags) && this.tags.length) {\n result.tags = [...(toRaw(this, this.tags) as string[])]\n }\n if (typeof this.deprecated === 'boolean') {\n result.deprecated = this.deprecated\n }\n return result\n }\n\n /**\n * Returns a parent data entity where this data property\n * exist.\n *\n * @returns The parent `DomainModel` or undefined if not found.\n * @example\n * ```typescript\n * const parent = entity.getParentInstance();\n * if (parent) {\n * console.log(parent.key);\n * }\n * ```\n */\n getParentInstance(): DomainModel | undefined {\n const parentKey = this.root.graph.parent(this.key)\n if (!parentKey) {\n return undefined\n }\n return this.root.graph.node(parentKey) as DomainModel | undefined\n }\n\n /**\n * Adds a property to this entity.\n *\n * @param property The partial property schema.\n * @returns The created `DomainProperty` instance.\n * @example\n * ```typescript\n * const property = entity.addProperty({\n * key: 'name',\n * type: 'string',\n * required: true,\n * })\n * ```\n */\n addProperty(property?: Partial<DomainPropertySchema>): DomainProperty {\n if (property && property.key && this.root.graph.hasNode(property.key)) {\n throw new Error(`Trying to add a property ${property.key}, but it already exists`)\n }\n const instance = new DomainProperty(this.root, this.key, property)\n this.root.graph.setNode(instance.key, instance)\n this.root.graph.setEdge(this.key, instance.key, { type: 'property' })\n this.fields.push({\n type: 'property',\n key: instance.key,\n })\n this.root.notifyChange()\n return instance\n }\n\n /**\n * Removes a property from this entity.\n *\n * @param key The key of the property to remove.\n * @throws {RemovePropertyException} When the property does not exist.\n * @example\n * ```typescript\n * entity.removeProperty('name')\n * ```\n */\n removeProperty(key: string): void {\n if (!this.root.graph.hasNode(key)) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't exist`)\n }\n const prop = this.root.graph.node(key) as DomainProperty\n if (prop.getParentInstance() !== this) {\n throw new RemovePropertyException(`Trying to remove the ${key} property, but it doesn't belong to this entity`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listProperties()`.\n */\n get properties(): Generator<DomainProperty> {\n return this.listProperties()\n }\n\n /**\n * Lists all properties of this entity.\n *\n * Note, it accounts for the order of the properties as\n * defined in the `fields` array.\n *\n * @returns A generator that yields each `DomainProperty`.\n * @example\n * ```typescript\n * for (const property of entity.listProperties()) {\n * console.log(property.key);\n * }\n * ```\n */\n *listProperties(): Generator<DomainProperty> {\n for (const { key, type } of this.fields) {\n if (type !== 'property') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainPropertyKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Collects a list of all properties that affect this entity,\n * including all inherited from parents properties as well as\n * this entity's properties.\n *\n * The resulting list already accounts for a property override.\n * A property overrides another property if it is lower in the\n * inheritance chain. As such, a property defined on this entity\n * always overrides previously defined entities.\n * @returns The iterator over the list of all properties.\n */\n withInheritedProperties(): MapIterator<DomainProperty> {\n if (this.root.readOnly && this.#inheritedPropertiesCache) {\n return this.#inheritedPropertiesCache.values()\n }\n const cache = new Map<string, DomainProperty>()\n const parents = this.listAllParents('up')\n for (const parent of parents) {\n for (const prop of parent.properties) {\n if (!prop.info.name) {\n continue\n }\n // We want to override the previously set property\n // so the last definition wins.\n cache.set(prop.info.name, prop)\n }\n }\n for (const prop of this.properties) {\n if (!prop.info.name) {\n continue\n }\n cache.set(prop.info.name, prop)\n }\n if (this.root.readOnly) {\n this.#inheritedPropertiesCache = Array.from(cache.values())\n }\n return cache.values()\n }\n\n /**\n * Checks if this entity has any properties.\n *\n * @returns True if the entity has properties.\n * @example\n * ```typescript\n * if (entity.hasProperties()) {\n * // ...\n * }\n * ```\n */\n hasProperties(): boolean {\n return this.fields.some((item) => item.type === 'property')\n }\n\n /**\n * A shortcut to `listParents()`.\n */\n get parents(): Generator<DomainEntity> {\n return this.listParents()\n }\n\n /**\n * Lists all parent entities of this entity (only the first level).\n *\n * @returns A generator that yields each parent `DomainEntity`.\n * @example\n * ```typescript\n * for (const parent of entity.listParents()) {\n * console.log(parent.key);\n * }\n * ```\n */\n *listParents(): Generator<DomainEntity> {\n for (const edge of this.root.graph.outEdges(this.key)) {\n const value = this.root.graph.edge(edge)\n if (!value || value.type !== 'parent') {\n continue\n }\n const parent = this.root.graph.node(edge.w) as DomainEntity\n if (parent) {\n yield parent\n }\n }\n }\n\n /**\n * Lists all parent entities recursively.\n *\n * @param direction The direction of the traversal. 'up' (default) lists from immediate parents up to the oldest.\n * 'down' lists from the oldest parents down to the immediate parents.\n * @returns An array of parent `DomainEntity` instances, ordered according to the requested traversal direction.\n */\n listAllParents(direction: 'up' | 'down' = 'up'): DomainEntity[] {\n if (this.root.readOnly && this.#allParentsCache?.[direction]) {\n return this.#allParentsCache[direction]\n }\n const visited = new Set<string>()\n const parents: DomainEntity[] = []\n const queue: DomainEntity[] = [...this.listParents()]\n\n let index = 0\n while (index < queue.length) {\n const parent = queue[index++]\n if (!visited.has(parent.key)) {\n visited.add(parent.key)\n parents.push(parent)\n queue.push(...parent.listParents())\n }\n }\n\n if (direction === 'down') {\n parents.reverse()\n }\n\n if (this.root.readOnly) {\n if (!this.#allParentsCache) {\n this.#allParentsCache = {} as Record<'up' | 'down', DomainEntity[]>\n }\n this.#allParentsCache[direction] = parents\n }\n\n return parents\n }\n\n /**\n * Adds a parent to this entity.\n *\n * @param key The key of the parent entity.\n * @param domain The key of the foreign domain the parent belongs to.\n * @returns `this` for chaining.\n * @throws ValidationError When the parent does not exist or a circular dependency is detected.\n * @example\n * ```typescript\n * entity.addParent('baseEntity');\n * ```\n */\n addParent(key: string, domain?: string): this {\n const effectiveKey = this.domain.buildReferenceKey(key, domain)\n // Prevent adding self as parent\n if (effectiveKey === this.key) {\n const message = 'Entity cannot be a parent of itself'\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n const { graph } = this.root\n if (!graph.hasNode(effectiveKey)) {\n let message = `Entity with key \"${key}\" not found`\n if (domain) {\n message += ` in domain \"${domain}\"`\n }\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'required',\n },\n ],\n { message }\n )\n }\n // Check for circular inheritance\n if (this.hasCircularParent(effectiveKey)) {\n const message = `Circular inheritance detected. Cannot add ${key} as a parent`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'circular',\n },\n ],\n { message }\n )\n }\n if (graph.outEdges(this.key, effectiveKey).next().value) {\n const message = `Parent ${key} already exists`\n throw new ValidationError(\n [\n {\n field: 'parents',\n message,\n rule: 'unique',\n },\n ],\n { message }\n )\n }\n // Parents are associated through graph edges.\n // Otherwise it would collide with the parent model.\n if (domain) {\n graph.setEdge(this.key, effectiveKey, { type: 'parent', domain, foreign: true })\n } else {\n graph.setEdge(this.key, effectiveKey, { type: 'parent' })\n }\n this.root.notifyChange()\n return this\n }\n\n /**\n * Removes a parent from this entity.\n *\n * @param key The key of the parent entity to remove.\n * @param domain Optional domain key if the parent belongs to a foreign domain.\n * @returns `this` for chaining.\n * @throws Error When the parent does not exist.\n * @example\n * ```typescript\n * // Remove local parent\n * entity.removeParent('baseEntity');\n *\n * // Remove foreign domain parent\n * entity.removeParent('baseEntity', 'externalDomain');\n * ```\n */\n removeParent(key: string, domain?: string): this {\n const { graph } = this.root\n const effectiveKey = this.domain.buildReferenceKey(key, domain)\n\n if (!graph.hasEdge(this.key, effectiveKey)) {\n let message = `Trying to remove a parent ${key} from ${this.key}, but it doesn't exist`\n if (domain) {\n message = `Trying to remove a foreign parent ${key} from domain \"${domain}\" from ${this.key}, but it doesn't exist`\n }\n throw new Error(message)\n }\n\n // Verify it's actually a parent edge\n const edge = graph.edge(this.key, effectiveKey)\n if (!edge || edge.type !== 'parent') {\n let message = `Edge between ${this.key} and ${key} exists but is not a parent relationship`\n if (domain) {\n message = `Edge between ${this.key} and ${key} in domain \"${domain}\" exists but is not a parent relationship`\n }\n throw new Error(message)\n }\n\n graph.removeEdge(this.key, effectiveKey)\n this.root.notifyChange()\n return this\n }\n\n /**\n * Checks if this entity has any parents.\n *\n * @returns True if the entity has parents.\n * @example\n * ```typescript\n * if (entity.hasParents()) {\n * // ...\n * }\n * ```\n */\n hasParents(): boolean {\n for (const edge of this.root.graph.outEdges(this.key)) {\n if (this.root.graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n return false\n }\n\n /**\n * Checks if the passed entity has a circular parent\n * relationship when attempting to add a new parent.\n *\n * @param key The key of the parent being added.\n * @returns True if adding this parent would create a\n * circular relationship.\n */\n hasCircularParent(key: string): boolean {\n const { graph } = this.root\n\n // Check if new parent is one of the children.\n for (const edge of graph.outEdges(key, this.key)) {\n if (graph.edge(edge)?.type === 'parent') {\n return true\n }\n }\n\n // check if this entity is in parents chain.\n let current: DomainEntity | undefined = graph.node(key) as DomainEntity | undefined\n while (current) {\n if (current.key === this.key) {\n return true\n }\n const parents = [...current.listParents()]\n if (parents.length === 0) {\n break\n }\n // Assuming single inheritance\n // TODO: Update this to check for multiple parents.\n current = parents[0]\n }\n\n return false\n }\n\n /**\n * Creates breadcrumbs from this entity to the root\n * namespace.\n *\n * @returns An array of `FileBreadcrumb` instances.\n * @example\n * ```typescript\n * const breadcrumbs = entity.breadcrumbs();\n * console.log(breadcrumbs);\n * ```\n */\n breadcrumbs(): FileBreadcrumb[] {\n const result: FileBreadcrumb[] = []\n result.push({\n key: this.key,\n name: this.info.getLabel('Unnamed entity'),\n kind: DomainEntityKind,\n })\n const model = this.getParentInstance()\n if (model) {\n result.push({\n key: model.key,\n kind: model.kind,\n name: model.info.getLabel('Unnamed model'),\n })\n let parent: DataDomain | DomainNamespace = model.getParentInstance()\n while (parent && parent !== this.root) {\n result.push({\n key: parent.key,\n kind: parent.kind,\n name: parent.info.getLabel('Unnamed namespace'),\n })\n const typed = parent as DomainNamespace\n parent = typed.getParentInstance()\n }\n }\n result.push({\n key: this.root.key,\n name: this.root.info.getLabel('Unnamed data domain'),\n kind: this.root.kind,\n })\n return result.reverse()\n }\n\n /**\n * Adds an association to this entity.\n *\n * Add rules:\n * - If the target is specified, it has to exist in the graph.\n * - The association targets can be local or foreign.\n *\n * Please note that you can't just add targets to the association schema.\n * This function manipulates the graph to insert the required metadata.\n *\n * @param input The partial association schema.\n * @returns The created `DomainAssociation` instance.\n * @throws Error When the target entity does not exist.\n * @example\n * ```typescript\n * const association = entity.addAssociation({ info: { name: 'Address' }, targets: [{ key: 'address' }] });\n * ```\n */\n addAssociation(input: Partial<DomainAssociationSchema> = {}): DomainAssociation {\n const { graph } = this.root\n\n // clean up any target information from the input\n // so we won't break the graph and the app.\n const inputCopy = { ...input }\n const targets = inputCopy.targets\n delete inputCopy.targets\n\n const hasTargets = Array.isArray(targets) && targets.length\n if (hasTargets) {\n for (const target of targets) {\n if (target.domain && target.key) {\n // target is foreign\n const foreignKey = `${target.domain}:${target.key}`\n if (!graph.hasNode(foreignKey)) {\n throw new Error(`Foreign entity ${foreignKey} not found`)\n }\n } else if (target.key) {\n if (!graph.hasNode(target.key)) {\n throw new Error(`Target entity ${target.key} not found`)\n }\n }\n }\n }\n\n const item = new DomainAssociation(this.root, this.key, inputCopy)\n graph.setNode(item.key, item)\n graph.setEdge(this.key, item.key, { type: 'association' })\n if (hasTargets) {\n for (const target of targets) {\n item.addTarget(target.key, target.domain)\n }\n }\n this.fields.push({ type: 'association', key: item.key })\n this.root.notifyChange()\n return item\n }\n\n /**\n * Removes an association from this entity.\n *\n * @param key The key of the association to remove.\n * @throws Error When the association does not exist.\n * @example\n * ```typescript\n * entity.removeAssociation('address');\n * ```\n */\n removeAssociation(key: string): void {\n if (!this.root.graph.hasEdge(this.key, key)) {\n throw new Error(`Unable to find a connection between this entity and the ${key} association`)\n }\n const edge = this.root.graph.edge(this.key, key)\n if (!edge || edge.type !== 'association') {\n throw new Error(`Association ${key} does not exist`)\n }\n removeGraphNode(this.root.graph, key)\n this.removeField(key)\n this.root.notifyChange()\n }\n\n /**\n * A shortcut to `listAssociations()`.\n */\n get associations(): Generator<DomainAssociation> {\n return this.listAssociations()\n }\n\n /**\n * Lists all associations of this entity.\n *\n * The order of the associations is defined in the `fields` array.\n *\n * @returns A generator that yields each\n * `DomainAssociation`.\n * @example\n * ```typescript\n * for (const association of entity.listAssociations()) {\n * console.log(association.key);\n * }\n * ```\n */\n *listAssociations(): Generator<DomainAssociation> {\n for (const { key, type } of this.fields) {\n if (type !== 'association') {\n continue\n }\n const node = this.root.graph.node(key)\n if (!node || node.kind !== DomainAssociationKind) {\n continue\n }\n yield node\n }\n }\n\n /**\n * Checks if this entity has any associations.\n *\n * @returns True if the entity has associations.\n * @example\n * ```typescript\n * if (entity.hasAssociations()) {\n * // ...\n * }\n * ```\n */\n hasAssociations(): boolean {\n return this.fields.some((item) => item.type === 'association')\n }\n\n /**\n * Lists all fields (properties and associations) of this entity.\n *\n * @returns A generator that yields each `DomainAssociation` or `DomainProperty`.\n * @example\n * ```typescript\n * for (const field of entity.listFields()) {\n * console.log(field.key);\n * }\n * ```\n */\n *listFields(): Generator<DomainAssociation | DomainProperty> {\n for (const { key } of this.fields) {\n const node = this.root.graph.node(key)\n if (!node) {\n continue\n }\n if (node.kind === DomainAssociationKind || node.kind === DomainPropertyKind) {\n yield node\n }\n }\n }\n\n /**\n * Checks if this entity has any fields (properties or associations).\n *\n * @returns True if the entity has fields.\n * @example\n * ```typescript\n * if (entity.hasFields()) {\n * // ...\n * }\n * ```\n */\n hasFields(): boolean {\n return this.fields.length > 0\n }\n\n private removeField(key: string): void {\n this.fields = this.fields.filter((item) => item.key !== key)\n }\n\n /**\n * Creates an AMF's data Shape.\n *\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(): Shapes.IShapeUnion {\n const serializer = new ShapeGenerator()\n return serializer.entity(this)\n }\n\n /**\n * Reads the schema of the Entity and generates an example for it.\n *\n * @param mime The mime type of the example.\n * @param opts The example generation options.\n * @returns The generated example.\n * @example\n * ```typescript\n * const example = entity.toExample('application/json');\n * console.log(example);\n * ```\n */\n toExample(mime: string, opts: IShapeRenderOptions = {}): string | number | boolean | null | undefined {\n const shape = this.toApiShape()\n const generator = new ApiSchemaGenerator(mime, {\n renderExamples: opts.renderExamples ?? true,\n renderMocked: opts.renderMocked ?? true,\n renderOptional: opts.renderOptional ?? true,\n selectedUnions: opts.selectedUnions,\n })\n return generator.generate(shape)\n }\n\n /**\n * Checks whether the entity is a child of the given namespace or data model.\n * The relationship doesn't have to be direct, as long as the entity\n * is in the hierarchy it will return true.\n *\n * @param key The key of the parent to check.\n * @returns True if this entity is a child of the given namespace or data model.\n */\n isChildOf(key: string): boolean {\n if (this.key === key) {\n return false\n }\n const parent = this.getParentInstance()\n if (!parent) {\n return false\n }\n if (parent.key === key) {\n return true\n }\n return parent.isChildOf(key)\n }\n\n /**\n * Finds the primary key property of this entity.\n * @returns The primary key property of this entity or undefined if not found.\n */\n primaryKey(): DomainProperty | undefined {\n for (const property of this.properties) {\n if (property.primary) {\n return property\n }\n }\n let property: DomainProperty | undefined\n for (const parent of this.listParents()) {\n const prop = parent.primaryKey()\n if (prop) {\n // According to the validation rules, the last parent\n // that has the property will be used as the source of\n // the property.\n // In the future, we may add a schema definition to the entity that\n // will explicitly define which property to use.\n property = prop\n }\n }\n return property\n }\n\n /**\n * Adds or updates a semantic to the entity.\n * @param semantic The semantic to add to the entity.\n * @throws Error if the semantic is not an entity semantic.\n */\n addSemantic(semantic: AppliedDataSemantic): void {\n const sem = DataSemantics[semantic.id]\n if (!isEntitySemantic(sem)) {\n throw new Error(`Invalid semantic type: ${semantic.id}. Expected an entity 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 entity.\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 entity 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 /**\n * Collects a list of all associations that affect this entity,\n * including all inherited from parents associations as well as\n * this entity's associations.\n *\n * The resulting list already accounts for an association override.\n * An association overrides another association if it is lower in the\n * inheritance chain. As such, an association defined on this entity\n * always overrides previously defined entities.\n * @returns The iterator over the list of all associations.\n */\n withInheritedAssociations(): MapIterator<DomainAssociation> {\n if (this.root.readOnly && this.#inheritedAssociationsCache) {\n return this.#inheritedAssociationsCache.values()\n }\n const cache = new Map<string, DomainAssociation>()\n const parents = this.listAllParents('up')\n for (const parent of parents) {\n for (const assoc of parent.associations) {\n if (!assoc.info.name) {\n continue\n }\n cache.set(assoc.info.name, assoc)\n }\n }\n for (const assoc of this.associations) {\n if (!assoc.info.name) {\n continue\n }\n cache.set(assoc.info.name, assoc)\n }\n if (this.root.readOnly) {\n this.#inheritedAssociationsCache = Array.from(cache.values())\n }\n return cache.values()\n }\n\n /**\n * Lists all semantics applied to this entity and its inherited parents.\n * Semantics from this entity overwrite those inherited from parents.\n *\n * @returns An array of applied semantics.\n */\n listAllSemantics(): AppliedDataSemantic[] {\n if (this.root.readOnly && this.#allSemanticsCache) {\n return this.#allSemanticsCache\n }\n const semanticsMap = new Map<SemanticType, AppliedDataSemantic>()\n const parents = this.listAllParents('up')\n for (const parent of parents) {\n for (const semantic of parent.semantics) {\n semanticsMap.set(semantic.id, semantic)\n }\n }\n for (const semantic of this.semantics) {\n semanticsMap.set(semantic.id, semantic)\n }\n const result = Array.from(semanticsMap.values())\n if (this.root.readOnly) {\n this.#allSemanticsCache = result\n }\n return result\n }\n\n /**\n * Generates a unique name by appending a number to the base name.\n * @param baseName The base name to make unique.\n * @returns A unique name within the current entity.\n */\n generateUniqueName(baseName: string): string {\n const existingNames = new Set<string>()\n for (const field of this.listFields()) {\n if (field.info.name) {\n existingNames.add(field.info.name)\n }\n }\n\n let counter = 2\n let newName = `${baseName}_copy`\n while (existingNames.has(newName)) {\n newName = `${baseName}_copy_${counter}`\n counter++\n }\n\n return newName\n }\n}\n"]}
@@ -5,6 +5,8 @@ import type { ExposedEntity } from './ExposedEntity.js';
5
5
  import type { Action } from './actions/Action.js';
6
6
  import type { DomainEntity } from './DomainEntity.js';
7
7
  import type { DomainProperty } from './DomainProperty.js';
8
+ import type { DomainAssociation } from './DomainAssociation.js';
9
+ import { SemanticType } from './Semantics.js';
8
10
  import { AccessRule } from './rules/AccessRule.js';
9
11
  /**
10
12
  * Identifies a specific exposed entity and its action kind.
@@ -71,6 +73,26 @@ export declare class RuntimeApiModel extends ApiModel {
71
73
  * Note, it creates a copy of the cached map to prevent modification of the internal state.
72
74
  */
73
75
  get sessionProperties(): ReadonlyMap<string, DomainProperty>;
76
+ /**
77
+ * Returns a readonly map of properties with semantics.
78
+ * Note, it creates a copy of the cached map to prevent modification of the internal state.
79
+ */
80
+ get semanticPropertiesCache(): ReadonlyMap<DomainEntity, DomainProperty[]>;
81
+ /**
82
+ * Returns properties for a specific entity that have a specific semantic type.
83
+ * Provides O(1) lookup using the precomputed cache.
84
+ */
85
+ getPropertiesBySemantic(entity: DomainEntity, semanticType: SemanticType): DomainProperty[];
86
+ /**
87
+ * Returns a readonly map of associations with semantics.
88
+ * Note, it creates a copy of the cached map to prevent modification of the internal state.
89
+ */
90
+ get semanticAssociationsCache(): ReadonlyMap<DomainEntity, DomainAssociation[]>;
91
+ /**
92
+ * Returns associations for a specific entity that have a specific semantic type.
93
+ * Provides O(1) lookup using the precomputed cache.
94
+ */
95
+ getAssociationsBySemantic(entity: DomainEntity, semanticType: SemanticType): DomainAssociation[];
74
96
  constructor(schema: RuntimeApiModelSchema, domainSchema: DataDomainSchema);
75
97
  /**
76
98
  * Looks up the corresponding exposed entity and action for a given request.
@@ -1 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A;CACtB;AAED;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,QAAQ;;IAY3C;;OAEG;IACH,cAAc,EAAE;QACd,IAAI,CAAC,EAAE,YAAY,CAAA;KACpB,CAAK;IAEN;;OAEG;IACH,gBAAgB,EAAE;QAChB,QAAQ,CAAC,EAAE,cAAc,CAAA;QACzB,QAAQ,CAAC,EAAE,cAAc,CAAA;QACzB,IAAI,CAAC,EAAE,cAAc,CAAA;KACtB,CAAK;IAYN;;;OAGG;IACH,IAAW,iBAAiB,IAAI,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAElE;IAsBD;;;OAGG;IACH,IAAW,uBAAuB,IAAI,WAAW,CAAC,YAAY,EAAE,cAAc,EAAE,CAAC,CAEhF;IAED;;;OAGG;IACI,uBAAuB,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,GAAG,cAAc,EAAE;IAKlG;;;OAGG;IACH,IAAW,yBAAyB,IAAI,WAAW,CAAC,YAAY,EAAE,iBAAiB,EAAE,CAAC,CAErF;IAED;;;OAGG;IACI,yBAAyB,CAAC,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,GAAG,iBAAiB,EAAE;gBAK3F,MAAM,EAAE,qBAAqB,EAAE,YAAY,EAAE,gBAAgB;IAuNzE;;;;;;OAMG;IACH,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS;IA0C7E;;OAEG;IACH,iBAAiB,CAAC,MAAM,EAAE,qBAAqB,GAAG,gBAAgB;IASzD,MAAM,IAAI,qBAAqB;CAazC"}
@@ -40,6 +40,52 @@ export class RuntimeApiModel extends ApiModel {
40
40
  get sessionProperties() {
41
41
  return new Map(this.#sessionProperties);
42
42
  }
43
+ /**
44
+ * Cached properties that have at least one semantic, grouped by their entity.
45
+ */
46
+ #semanticPropertiesCache = new Map();
47
+ /**
48
+ * Cached properties that have at least one semantic, grouped by their entity and then by SemanticType.
49
+ */
50
+ #propertiesBySemanticCache = new Map();
51
+ /**
52
+ * Cached associations that have at least one semantic, grouped by their entity.
53
+ */
54
+ #semanticAssociationsCache = new Map();
55
+ /**
56
+ * Cached associations that have at least one semantic, grouped by their entity and then by SemanticType.
57
+ */
58
+ #associationsBySemanticCache = new Map();
59
+ /**
60
+ * Returns a readonly map of properties with semantics.
61
+ * Note, it creates a copy of the cached map to prevent modification of the internal state.
62
+ */
63
+ get semanticPropertiesCache() {
64
+ return new Map(this.#semanticPropertiesCache);
65
+ }
66
+ /**
67
+ * Returns properties for a specific entity that have a specific semantic type.
68
+ * Provides O(1) lookup using the precomputed cache.
69
+ */
70
+ getPropertiesBySemantic(entity, semanticType) {
71
+ const semanticMap = this.#propertiesBySemanticCache.get(entity);
72
+ return semanticMap?.get(semanticType) || [];
73
+ }
74
+ /**
75
+ * Returns a readonly map of associations with semantics.
76
+ * Note, it creates a copy of the cached map to prevent modification of the internal state.
77
+ */
78
+ get semanticAssociationsCache() {
79
+ return new Map(this.#semanticAssociationsCache);
80
+ }
81
+ /**
82
+ * Returns associations for a specific entity that have a specific semantic type.
83
+ * Provides O(1) lookup using the precomputed cache.
84
+ */
85
+ getAssociationsBySemantic(entity, semanticType) {
86
+ const semanticMap = this.#associationsBySemanticCache.get(entity);
87
+ return semanticMap?.get(semanticType) || [];
88
+ }
43
89
  constructor(schema, domainSchema) {
44
90
  super(schema, domainSchema);
45
91
  if (schema.routingMap) {
@@ -48,6 +94,7 @@ export class RuntimeApiModel extends ApiModel {
48
94
  this.#cacheEntitiesAndProperties();
49
95
  this.#precomputeAccessRules();
50
96
  this.#precomputeSessionProperties();
97
+ this.#precomputeSemanticProperties();
51
98
  }
52
99
  #precomputeSessionProperties() {
53
100
  if (!this.session || !this.domain) {
@@ -61,6 +108,60 @@ export class RuntimeApiModel extends ApiModel {
61
108
  this.#sessionProperties.set(prop.key, domainProperty);
62
109
  }
63
110
  }
111
+ #precomputeSemanticProperties() {
112
+ if (!this.domain) {
113
+ return;
114
+ }
115
+ const processEntity = (entity) => {
116
+ if (this.#semanticPropertiesCache.has(entity)) {
117
+ return;
118
+ }
119
+ const propertiesWithSemantics = [];
120
+ const semanticPropsMap = new Map();
121
+ for (const prop of entity.withInheritedProperties()) {
122
+ if (Array.isArray(prop.semantics) && prop.semantics.length > 0) {
123
+ propertiesWithSemantics.push(prop);
124
+ for (const semantic of prop.semantics) {
125
+ let propsForSemantic = semanticPropsMap.get(semantic.id);
126
+ if (!propsForSemantic) {
127
+ propsForSemantic = [];
128
+ semanticPropsMap.set(semantic.id, propsForSemantic);
129
+ }
130
+ propsForSemantic.push(prop);
131
+ }
132
+ }
133
+ }
134
+ if (propertiesWithSemantics.length > 0) {
135
+ this.#semanticPropertiesCache.set(entity, propertiesWithSemantics);
136
+ this.#propertiesBySemanticCache.set(entity, semanticPropsMap);
137
+ }
138
+ const associationsWithSemantics = [];
139
+ const semanticAssocMap = new Map();
140
+ for (const assoc of entity.withInheritedAssociations()) {
141
+ if (Array.isArray(assoc.semantics) && assoc.semantics.length > 0) {
142
+ associationsWithSemantics.push(assoc);
143
+ for (const semantic of assoc.semantics) {
144
+ let assocForSemantic = semanticAssocMap.get(semantic.id);
145
+ if (!assocForSemantic) {
146
+ assocForSemantic = [];
147
+ semanticAssocMap.set(semantic.id, assocForSemantic);
148
+ }
149
+ assocForSemantic.push(assoc);
150
+ }
151
+ }
152
+ }
153
+ if (associationsWithSemantics.length > 0) {
154
+ this.#semanticAssociationsCache.set(entity, associationsWithSemantics);
155
+ this.#associationsBySemanticCache.set(entity, semanticAssocMap);
156
+ }
157
+ };
158
+ for (const entity of this.domain.listEntities()) {
159
+ processEntity(entity);
160
+ }
161
+ for (const entity of this.domain.listAllForeignEntities()) {
162
+ processEntity(entity);
163
+ }
164
+ }
64
165
  #precomputeAccessRules() {
65
166
  for (const entity of this.exposes.values()) {
66
167
  for (const action of entity.actions) {
@@ -143,7 +244,7 @@ export class RuntimeApiModel extends ApiModel {
143
244
  return;
144
245
  }
145
246
  this.cachedEntities.user = userEntity;
146
- for (const prop of userEntity.properties) {
247
+ for (const prop of userEntity.withInheritedProperties()) {
147
248
  if (prop.hasSemantic(SemanticType.Username)) {
148
249
  this.cachedProperties.username = prop;
149
250
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RuntimeApiModel.js","sourceRoot":"","sources":["../../../src/modeling/RuntimeApiModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAmB,MAAM,mBAAmB,CAAA;AACvE,OAAO,EAAE,QAAQ,EAAuB,MAAM,eAAe,CAAA;AAK7D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAG7C,OAAO,EAAc,wBAAwB,EAAE,MAAM,uBAAuB,CAAA;AAC5E,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAkDtD;;;GAGG;AACH,MAAM,OAAO,eAAgB,SAAQ,QAAQ;IAC3C;;;OAGG;IACH,OAAO,GAAG,IAAI,GAAG,EAA0B,CAAA;IAE3C;;OAEG;IACH,YAAY,GAAG,IAAI,OAAO,EAAiC,CAAA;IAE3D;;OAEG;IACH,cAAc,GAEV,EAAE,CAAA;IAEN;;OAEG;IACH,gBAAgB,GAIZ,EAAE,CAAA;IAEN;;OAEG;IACH,iBAAiB,GAAG,IAAI,OAAO,EAA4B,CAAA;IAE3D;;OAEG;IACM,kBAAkB,GAAG,IAAI,GAAG,EAA0B,CAAA;IAE/D;;;OAGG;IACH,IAAW,iBAAiB;QAC1B,OAAO,IAAI,GAAG,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAA;IACzC,CAAC;IAED,YAAY,MAA6B,EAAE,YAA8B;QACvE,KAAK,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;QAE3B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAA;QAC3C,CAAC;QAED,IAAI,C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ApiModel.js'\nimport type { DataDomainSchema } from './DataDomain.js'\nimport type { ActionKind } from './actions/index.js'\nimport type { ExposedEntity } from './ExposedEntity.js'\nimport type { Action } from './actions/Action.js'\nimport { SemanticType } from './Semantics.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { DomainProperty } from './DomainProperty.js'\nimport { AccessRule, AccessRuleExecutionPhase } from './rules/AccessRule.js'\nimport { Exception } from '../exceptions/exception.js'\n\n/**\n * Identifies a specific exposed entity and its action kind.\n */\nexport interface RouteLookup {\n exposedEntityKey: string\n actionKind: ActionKind\n}\n\n/**\n * A routing definition mapping a path to an action lookup.\n */\nexport interface RouteDefinition {\n path: string\n lookup: RouteLookup\n}\n\n/**\n * A map of HTTP methods to their route definitions.\n */\nexport type RoutingMap = Record<string, RouteDefinition[]>\n\n/**\n * Schema for an API Model optimized for runtime routing.\n */\nexport interface RuntimeApiModelSchema extends ApiModelSchema {\n routingMap: RoutingMap\n}\n\nexport interface RuntimeResolvedAction {\n exposure: ExposedEntity\n entity: DomainEntity\n action: Action\n params: Record<string, string>\n}\n\nexport type RuleEvaluator = (rule: AccessRule) => Promise<boolean | undefined> | boolean | undefined\n\nexport interface PhaseRules {\n permissionRules: AccessRule[]\n mandatoryRules: AccessRule[]\n}\n\nexport interface ActionRulesCache {\n preFetch: PhaseRules\n fetch: PhaseRules\n postFetch: PhaseRules\n}\n\n/**\n * An optimized API Model subclass designed for fast runtime lookups.\n * It pre-compiles the RoutingMap into a radix tree for O(log N) or faster endpoint resolution.\n */\nexport class RuntimeApiModel extends ApiModel {\n /**\n * The parsed radix tree for fast routing.\n * Method -> ParsedRoutes\n */\n #routes = new Map<string, RouteToken[][]>()\n\n /**\n * Quick map from matchit parsed route format to our RouteDefinition for returning results\n */\n #definitions = new WeakMap<RouteToken[], RouteDefinition>()\n\n /**\n * Cached references to commonly used entities for fast runtime lookup.\n */\n cachedEntities: {\n user?: DomainEntity\n } = {}\n\n /**\n * Cached references to commonly used properties for fast runtime lookup.\n */\n cachedProperties: {\n username?: DomainProperty\n password?: DomainProperty\n role?: DomainProperty\n } = {}\n\n /**\n * Cached access rules for each action to avoid runtime computation overhead.\n */\n #actionRulesCache = new WeakMap<Action, ActionRulesCache>()\n\n /**\n * Cached session properties for fast runtime lookup.\n */\n readonly #sessionProperties = new Map<string, DomainProperty>()\n\n /**\n * Returns a readonly map of session properties.\n * Note, it creates a copy of the cached map to prevent modification of the internal state.\n */\n public get sessionProperties(): ReadonlyMap<string, DomainProperty> {\n return new Map(this.#sessionProperties)\n }\n\n constructor(schema: RuntimeApiModelSchema, domainSchema: DataDomainSchema) {\n super(schema, domainSchema)\n\n if (schema.routingMap) {\n this.#initializeRouter(schema.routingMap)\n }\n\n this.#cacheEntitiesAndProperties()\n this.#precomputeAccessRules()\n this.#precomputeSessionProperties()\n }\n\n #precomputeSessionProperties(): void {\n if (!this.session || !this.domain) {\n return\n }\n for (const prop of this.session.properties) {\n const domainProperty = this.domain.findProperty(prop.key, prop.domain)\n if (!domainProperty) {\n throw new Exception(`Session property ${prop.key} not found in domain`)\n }\n this.#sessionProperties.set(prop.key, domainProperty)\n }\n }\n\n #precomputeAccessRules(): void {\n for (const entity of this.exposes.values()) {\n for (const action of entity.actions) {\n this.#actionRulesCache.set(action, this.#computeEffectiveRules(action, entity))\n }\n }\n }\n\n #computeEffectiveRules(action: Action, entity: ExposedEntity): ActionRulesCache {\n const hierarchy: AccessRule[][] = []\n\n if (action.accessRule && action.accessRule.length > 0) {\n hierarchy.push(action.accessRule)\n }\n\n let currentEntity: ExposedEntity | undefined = entity\n while (currentEntity) {\n if (currentEntity.accessRule && currentEntity.accessRule.length > 0) {\n hierarchy.push(currentEntity.accessRule)\n }\n currentEntity = currentEntity.parent ? this.exposes.get(currentEntity.parent.key) : undefined\n }\n\n if (this.accessRule && this.accessRule.length > 0) {\n hierarchy.push(this.accessRule)\n }\n\n const result: ActionRulesCache = {\n preFetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n fetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n postFetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n }\n\n const seenTypes = new Set<string>()\n\n for (const rulesLevel of hierarchy) {\n const typesInThisLevel = new Set<string>()\n for (const rule of rulesLevel) {\n const phase = rule.metadata[action.kind as keyof typeof rule.metadata]\n\n // If the rule does not specify an execution phase for this action kind, it is not evaluated\n if (!phase) {\n continue\n }\n\n // Shadowing: If a rule of the same type was defined closer to the action, ignore this one.\n if (seenTypes.has(rule.type)) {\n continue\n }\n typesInThisLevel.add(rule.type)\n\n let bucket\n if (phase === AccessRuleExecutionPhase.POST_FETCH) {\n bucket = result.postFetch\n } else if (phase === AccessRuleExecutionPhase.FETCH) {\n bucket = result.fetch\n } else {\n bucket = result.preFetch\n }\n\n if (rule.mandatory) {\n bucket.mandatoryRules.push(rule)\n } else {\n bucket.permissionRules.push(rule)\n }\n }\n for (const type of typesInThisLevel) {\n seenTypes.add(type)\n }\n }\n\n return result\n }\n\n #cacheEntitiesAndProperties(): void {\n if (!this.user || !this.domain) {\n return\n }\n\n const userEntity = this.domain.findEntity(this.user.key, this.user.domain)\n if (!userEntity) {\n return\n }\n\n this.cachedEntities.user = userEntity\n\n for (const prop of userEntity.properties) {\n if (prop.hasSemantic(SemanticType.Username)) {\n this.cachedProperties.username = prop\n }\n if (prop.hasSemantic(SemanticType.Password)) {\n this.cachedProperties.password = prop\n }\n if (prop.hasSemantic(SemanticType.UserRole)) {\n this.cachedProperties.role = prop\n }\n }\n }\n\n #initializeRouter(routingMap: RoutingMap): void {\n for (const [method, definitions] of Object.entries(routingMap)) {\n const parsedRoutes = []\n for (const def of definitions) {\n // matchit's parse() transforms a route string into an object representation.\n // It expects `:param` syntax, while our API models use OpenAPI `{param}` syntax.\n const matchitPath = def.path.replace(/\\{([^}]+)\\}/g, ':$1')\n const parsed = parse(matchitPath)\n this.#definitions.set(parsed, def)\n parsedRoutes.push(parsed)\n }\n this.#routes.set(method.toUpperCase(), parsedRoutes)\n }\n }\n\n /**\n * Looks up the corresponding exposed entity and action for a given request.\n *\n * @param method The HTTP method (e.g., 'GET', 'POST').\n * @param path The request path (e.g., '/users/123').\n * @returns An object with the entity, action, and extracted path parameters if a match is found.\n */\n lookupAction(method: string, path: string): RuntimeResolvedAction | undefined {\n const parsedRoutes = this.#routes.get(method.toUpperCase())\n if (!parsedRoutes) {\n return undefined\n }\n\n // `match` returns the matching parsed route (which is an array of segments), or empty array if no match\n const matchedRoute = match(path, parsedRoutes)\n if (!matchedRoute || matchedRoute.length === 0) {\n return undefined\n }\n\n const def = this.#definitions.get(matchedRoute)\n if (!def) {\n return undefined\n }\n\n const params = exec(path, matchedRoute)\n\n const exposure = this.exposes.get(def.lookup.exposedEntityKey)\n if (!exposure) {\n throw new Exception('Missing exposure ' + def.lookup.exposedEntityKey, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n const action = exposure.actions.find((a) => a.kind === def.lookup.actionKind)\n if (!action) {\n throw new Exception('Missing action ' + def.lookup.actionKind, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n const entity = this.domain?.findEntity(exposure.entity.key, exposure.entity.domain)\n if (!entity) {\n throw new Exception('Missing entity ' + exposure.entity.key, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n return {\n exposure,\n entity,\n action,\n params,\n }\n }\n\n /**\n * Retrieves the precomputed and shadowed effective rules for a given action.\n */\n getEffectiveRules(action: RuntimeResolvedAction): ActionRulesCache {\n let cachedRules = this.#actionRulesCache.get(action.action)\n if (!cachedRules) {\n cachedRules = this.#computeEffectiveRules(action.action, action.exposure)\n this.#actionRulesCache.set(action.action, cachedRules)\n }\n return cachedRules\n }\n\n override toJSON(): RuntimeApiModelSchema {\n const base = super.toJSON() as RuntimeApiModelSchema\n\n const routingMap: RoutingMap = {}\n for (const [method, parsedRoutes] of this.#routes.entries()) {\n routingMap[method] = parsedRoutes.map((pr) => this.#definitions.get(pr) as RouteDefinition)\n }\n\n return {\n ...base,\n routingMap,\n }\n }\n}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B,WAAW,GAAG,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAA;YACzE,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QACxD,CAAC;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;IAEQ,MAAM;QACb,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAA2B,CAAA;QAEpD,MAAM,UAAU,GAAe,EAAE,CAAA;QACjC,KAAK,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC;YAC5D,UAAU,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAoB,CAAC,CAAA;QAC7F,CAAC;QAED,OAAO;YACL,GAAG,IAAI;YACP,UAAU;SACX,CAAA;IACH,CAAC;CACF","sourcesContent":["import { match, parse, exec, type RouteToken } from '@poppinss/matchit'\nimport { ApiModel, type ApiModelSchema } from './ApiModel.js'\nimport type { DataDomainSchema } from './DataDomain.js'\nimport type { ActionKind } from './actions/index.js'\nimport type { ExposedEntity } from './ExposedEntity.js'\nimport type { Action } from './actions/Action.js'\nimport type { DomainEntity } from './DomainEntity.js'\nimport type { DomainProperty } from './DomainProperty.js'\nimport type { DomainAssociation } from './DomainAssociation.js'\nimport { SemanticType } from './Semantics.js'\nimport { AccessRule, AccessRuleExecutionPhase } from './rules/AccessRule.js'\nimport { Exception } from '../exceptions/exception.js'\n\n/**\n * Identifies a specific exposed entity and its action kind.\n */\nexport interface RouteLookup {\n exposedEntityKey: string\n actionKind: ActionKind\n}\n\n/**\n * A routing definition mapping a path to an action lookup.\n */\nexport interface RouteDefinition {\n path: string\n lookup: RouteLookup\n}\n\n/**\n * A map of HTTP methods to their route definitions.\n */\nexport type RoutingMap = Record<string, RouteDefinition[]>\n\n/**\n * Schema for an API Model optimized for runtime routing.\n */\nexport interface RuntimeApiModelSchema extends ApiModelSchema {\n routingMap: RoutingMap\n}\n\nexport interface RuntimeResolvedAction {\n exposure: ExposedEntity\n entity: DomainEntity\n action: Action\n params: Record<string, string>\n}\n\nexport type RuleEvaluator = (rule: AccessRule) => Promise<boolean | undefined> | boolean | undefined\n\nexport interface PhaseRules {\n permissionRules: AccessRule[]\n mandatoryRules: AccessRule[]\n}\n\nexport interface ActionRulesCache {\n preFetch: PhaseRules\n fetch: PhaseRules\n postFetch: PhaseRules\n}\n\n/**\n * An optimized API Model subclass designed for fast runtime lookups.\n * It pre-compiles the RoutingMap into a radix tree for O(log N) or faster endpoint resolution.\n */\nexport class RuntimeApiModel extends ApiModel {\n /**\n * The parsed radix tree for fast routing.\n * Method -> ParsedRoutes\n */\n #routes = new Map<string, RouteToken[][]>()\n\n /**\n * Quick map from matchit parsed route format to our RouteDefinition for returning results\n */\n #definitions = new WeakMap<RouteToken[], RouteDefinition>()\n\n /**\n * Cached references to commonly used entities for fast runtime lookup.\n */\n cachedEntities: {\n user?: DomainEntity\n } = {}\n\n /**\n * Cached references to commonly used properties for fast runtime lookup.\n */\n cachedProperties: {\n username?: DomainProperty\n password?: DomainProperty\n role?: DomainProperty\n } = {}\n\n /**\n * Cached access rules for each action to avoid runtime computation overhead.\n */\n #actionRulesCache = new WeakMap<Action, ActionRulesCache>()\n\n /**\n * Cached session properties for fast runtime lookup.\n */\n readonly #sessionProperties = new Map<string, DomainProperty>()\n\n /**\n * Returns a readonly map of session properties.\n * Note, it creates a copy of the cached map to prevent modification of the internal state.\n */\n public get sessionProperties(): ReadonlyMap<string, DomainProperty> {\n return new Map(this.#sessionProperties)\n }\n\n /**\n * Cached properties that have at least one semantic, grouped by their entity.\n */\n readonly #semanticPropertiesCache = new Map<DomainEntity, DomainProperty[]>()\n\n /**\n * Cached properties that have at least one semantic, grouped by their entity and then by SemanticType.\n */\n readonly #propertiesBySemanticCache = new Map<DomainEntity, Map<SemanticType, DomainProperty[]>>()\n\n /**\n * Cached associations that have at least one semantic, grouped by their entity.\n */\n readonly #semanticAssociationsCache = new Map<DomainEntity, DomainAssociation[]>()\n\n /**\n * Cached associations that have at least one semantic, grouped by their entity and then by SemanticType.\n */\n readonly #associationsBySemanticCache = new Map<DomainEntity, Map<SemanticType, DomainAssociation[]>>()\n\n /**\n * Returns a readonly map of properties with semantics.\n * Note, it creates a copy of the cached map to prevent modification of the internal state.\n */\n public get semanticPropertiesCache(): ReadonlyMap<DomainEntity, DomainProperty[]> {\n return new Map(this.#semanticPropertiesCache)\n }\n\n /**\n * Returns properties for a specific entity that have a specific semantic type.\n * Provides O(1) lookup using the precomputed cache.\n */\n public getPropertiesBySemantic(entity: DomainEntity, semanticType: SemanticType): DomainProperty[] {\n const semanticMap = this.#propertiesBySemanticCache.get(entity)\n return semanticMap?.get(semanticType) || []\n }\n\n /**\n * Returns a readonly map of associations with semantics.\n * Note, it creates a copy of the cached map to prevent modification of the internal state.\n */\n public get semanticAssociationsCache(): ReadonlyMap<DomainEntity, DomainAssociation[]> {\n return new Map(this.#semanticAssociationsCache)\n }\n\n /**\n * Returns associations for a specific entity that have a specific semantic type.\n * Provides O(1) lookup using the precomputed cache.\n */\n public getAssociationsBySemantic(entity: DomainEntity, semanticType: SemanticType): DomainAssociation[] {\n const semanticMap = this.#associationsBySemanticCache.get(entity)\n return semanticMap?.get(semanticType) || []\n }\n\n constructor(schema: RuntimeApiModelSchema, domainSchema: DataDomainSchema) {\n super(schema, domainSchema)\n\n if (schema.routingMap) {\n this.#initializeRouter(schema.routingMap)\n }\n\n this.#cacheEntitiesAndProperties()\n this.#precomputeAccessRules()\n this.#precomputeSessionProperties()\n this.#precomputeSemanticProperties()\n }\n\n #precomputeSessionProperties(): void {\n if (!this.session || !this.domain) {\n return\n }\n for (const prop of this.session.properties) {\n const domainProperty = this.domain.findProperty(prop.key, prop.domain)\n if (!domainProperty) {\n throw new Exception(`Session property ${prop.key} not found in domain`)\n }\n this.#sessionProperties.set(prop.key, domainProperty)\n }\n }\n\n #precomputeSemanticProperties(): void {\n if (!this.domain) {\n return\n }\n\n const processEntity = (entity: DomainEntity) => {\n if (this.#semanticPropertiesCache.has(entity)) {\n return\n }\n\n const propertiesWithSemantics: DomainProperty[] = []\n const semanticPropsMap = new Map<SemanticType, DomainProperty[]>()\n\n for (const prop of entity.withInheritedProperties()) {\n if (Array.isArray(prop.semantics) && prop.semantics.length > 0) {\n propertiesWithSemantics.push(prop)\n\n for (const semantic of prop.semantics) {\n let propsForSemantic = semanticPropsMap.get(semantic.id)\n if (!propsForSemantic) {\n propsForSemantic = []\n semanticPropsMap.set(semantic.id, propsForSemantic)\n }\n propsForSemantic.push(prop)\n }\n }\n }\n\n if (propertiesWithSemantics.length > 0) {\n this.#semanticPropertiesCache.set(entity, propertiesWithSemantics)\n this.#propertiesBySemanticCache.set(entity, semanticPropsMap)\n }\n\n const associationsWithSemantics: DomainAssociation[] = []\n const semanticAssocMap = new Map<SemanticType, DomainAssociation[]>()\n\n for (const assoc of entity.withInheritedAssociations()) {\n if (Array.isArray(assoc.semantics) && assoc.semantics.length > 0) {\n associationsWithSemantics.push(assoc)\n\n for (const semantic of assoc.semantics) {\n let assocForSemantic = semanticAssocMap.get(semantic.id)\n if (!assocForSemantic) {\n assocForSemantic = []\n semanticAssocMap.set(semantic.id, assocForSemantic)\n }\n assocForSemantic.push(assoc)\n }\n }\n }\n\n if (associationsWithSemantics.length > 0) {\n this.#semanticAssociationsCache.set(entity, associationsWithSemantics)\n this.#associationsBySemanticCache.set(entity, semanticAssocMap)\n }\n }\n\n for (const entity of this.domain.listEntities()) {\n processEntity(entity)\n }\n\n for (const entity of this.domain.listAllForeignEntities()) {\n processEntity(entity)\n }\n }\n\n #precomputeAccessRules(): void {\n for (const entity of this.exposes.values()) {\n for (const action of entity.actions) {\n this.#actionRulesCache.set(action, this.#computeEffectiveRules(action, entity))\n }\n }\n }\n\n #computeEffectiveRules(action: Action, entity: ExposedEntity): ActionRulesCache {\n const hierarchy: AccessRule[][] = []\n\n if (action.accessRule && action.accessRule.length > 0) {\n hierarchy.push(action.accessRule)\n }\n\n let currentEntity: ExposedEntity | undefined = entity\n while (currentEntity) {\n if (currentEntity.accessRule && currentEntity.accessRule.length > 0) {\n hierarchy.push(currentEntity.accessRule)\n }\n currentEntity = currentEntity.parent ? this.exposes.get(currentEntity.parent.key) : undefined\n }\n\n if (this.accessRule && this.accessRule.length > 0) {\n hierarchy.push(this.accessRule)\n }\n\n const result: ActionRulesCache = {\n preFetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n fetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n postFetch: {\n permissionRules: [],\n mandatoryRules: [],\n },\n }\n\n const seenTypes = new Set<string>()\n\n for (const rulesLevel of hierarchy) {\n const typesInThisLevel = new Set<string>()\n for (const rule of rulesLevel) {\n const phase = rule.metadata[action.kind as keyof typeof rule.metadata]\n\n // If the rule does not specify an execution phase for this action kind, it is not evaluated\n if (!phase) {\n continue\n }\n\n // Shadowing: If a rule of the same type was defined closer to the action, ignore this one.\n if (seenTypes.has(rule.type)) {\n continue\n }\n typesInThisLevel.add(rule.type)\n\n let bucket\n if (phase === AccessRuleExecutionPhase.POST_FETCH) {\n bucket = result.postFetch\n } else if (phase === AccessRuleExecutionPhase.FETCH) {\n bucket = result.fetch\n } else {\n bucket = result.preFetch\n }\n\n if (rule.mandatory) {\n bucket.mandatoryRules.push(rule)\n } else {\n bucket.permissionRules.push(rule)\n }\n }\n for (const type of typesInThisLevel) {\n seenTypes.add(type)\n }\n }\n\n return result\n }\n\n #cacheEntitiesAndProperties(): void {\n if (!this.user || !this.domain) {\n return\n }\n\n const userEntity = this.domain.findEntity(this.user.key, this.user.domain)\n if (!userEntity) {\n return\n }\n\n this.cachedEntities.user = userEntity\n\n for (const prop of userEntity.withInheritedProperties()) {\n if (prop.hasSemantic(SemanticType.Username)) {\n this.cachedProperties.username = prop\n }\n if (prop.hasSemantic(SemanticType.Password)) {\n this.cachedProperties.password = prop\n }\n if (prop.hasSemantic(SemanticType.UserRole)) {\n this.cachedProperties.role = prop\n }\n }\n }\n\n #initializeRouter(routingMap: RoutingMap): void {\n for (const [method, definitions] of Object.entries(routingMap)) {\n const parsedRoutes = []\n for (const def of definitions) {\n // matchit's parse() transforms a route string into an object representation.\n // It expects `:param` syntax, while our API models use OpenAPI `{param}` syntax.\n const matchitPath = def.path.replace(/\\{([^}]+)\\}/g, ':$1')\n const parsed = parse(matchitPath)\n this.#definitions.set(parsed, def)\n parsedRoutes.push(parsed)\n }\n this.#routes.set(method.toUpperCase(), parsedRoutes)\n }\n }\n\n /**\n * Looks up the corresponding exposed entity and action for a given request.\n *\n * @param method The HTTP method (e.g., 'GET', 'POST').\n * @param path The request path (e.g., '/users/123').\n * @returns An object with the entity, action, and extracted path parameters if a match is found.\n */\n lookupAction(method: string, path: string): RuntimeResolvedAction | undefined {\n const parsedRoutes = this.#routes.get(method.toUpperCase())\n if (!parsedRoutes) {\n return undefined\n }\n\n // `match` returns the matching parsed route (which is an array of segments), or empty array if no match\n const matchedRoute = match(path, parsedRoutes)\n if (!matchedRoute || matchedRoute.length === 0) {\n return undefined\n }\n\n const def = this.#definitions.get(matchedRoute)\n if (!def) {\n return undefined\n }\n\n const params = exec(path, matchedRoute)\n\n const exposure = this.exposes.get(def.lookup.exposedEntityKey)\n if (!exposure) {\n throw new Exception('Missing exposure ' + def.lookup.exposedEntityKey, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n const action = exposure.actions.find((a) => a.kind === def.lookup.actionKind)\n if (!action) {\n throw new Exception('Missing action ' + def.lookup.actionKind, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n const entity = this.domain?.findEntity(exposure.entity.key, exposure.entity.domain)\n if (!entity) {\n throw new Exception('Missing entity ' + exposure.entity.key, { code: 'API_MODEL_ERROR', status: 500 })\n }\n\n return {\n exposure,\n entity,\n action,\n params,\n }\n }\n\n /**\n * Retrieves the precomputed and shadowed effective rules for a given action.\n */\n getEffectiveRules(action: RuntimeResolvedAction): ActionRulesCache {\n let cachedRules = this.#actionRulesCache.get(action.action)\n if (!cachedRules) {\n cachedRules = this.#computeEffectiveRules(action.action, action.exposure)\n this.#actionRulesCache.set(action.action, cachedRules)\n }\n return cachedRules\n }\n\n override toJSON(): RuntimeApiModelSchema {\n const base = super.toJSON() as RuntimeApiModelSchema\n\n const routingMap: RoutingMap = {}\n for (const [method, parsedRoutes] of this.#routes.entries()) {\n routingMap[method] = parsedRoutes.map((pr) => this.#definitions.get(pr) as RouteDefinition)\n }\n\n return {\n ...base,\n routingMap,\n }\n }\n}\n"]}
@@ -127,31 +127,16 @@ export type FunctionGeneratorConfig = StringDefaultRandomGenerator;
127
127
  */
128
128
  export interface StringDefaultRandomGenerator {
129
129
  /**
130
- * When set the `max` and `min` are used.
131
- * Otherwise a random string of fixed length (the `fixed` property) is generated.
130
+ * When set to true, the random string will have a fixed length defined by the `length` property.
131
+ * Otherwise, the length will be a random number between the property's schema `minimum` and `maximum`.
132
132
  */
133
- varyingLength?: boolean;
134
- /**
135
- * The minimum length of the random string.
136
- *
137
- * When not specified, it defaults to `10`.
138
- * The `varyingLength` must be `true` to use this property.
139
- */
140
- min?: number;
141
- /**
142
- * The maximum length of the random string.
143
- *
144
- * When not specified, it defaults to `30`.
145
- * The `varyingLength` must be `true` to use this property.
146
- */
147
- max?: number;
133
+ isFixed?: boolean;
148
134
  /**
149
135
  * The fixed length of the random string.
150
136
  *
151
- * When not specified, it defaults to `10`.
152
- * The `varyingLength` must be `false` to use this property.
137
+ * The `isFixed` must be `true` to use this property.
153
138
  */
154
- fixed?: number;
139
+ length?: number;
155
140
  /**
156
141
  * The prefix to add to the random string.
157
142
  * The prefix adds to the length of the random string.
@@ -899,5 +884,20 @@ export interface AssociationSchema {
899
884
  */
900
885
  unionType?: 'allOf' | 'anyOf' | 'oneOf' | 'not';
901
886
  }
887
+ /**
888
+ * Options used when initializing a DataDomain.
889
+ */
890
+ export interface DataDomainOptions {
891
+ /**
892
+ * The mode used during deserialization to control error tolerance.
893
+ * 'strict' throws errors on invalid references. 'lenient' collects them.
894
+ */
895
+ mode?: DeserializationMode;
896
+ /**
897
+ * Whether the DataDomain is in read-only mode, which makes it immutable
898
+ * and enables internal caching optimizations.
899
+ */
900
+ readOnly?: boolean;
901
+ }
902
902
  export {};
903
903
  //# sourceMappingURL=types.d.ts.map