@api-client/core 0.14.6 → 0.14.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/src/amf/ApiSchemaValues.js.map +1 -1
- package/build/src/modeling/ApiModel.d.ts +27 -17
- package/build/src/modeling/ApiModel.d.ts.map +1 -1
- package/build/src/modeling/ApiModel.js +69 -20
- package/build/src/modeling/ApiModel.js.map +1 -1
- package/build/src/modeling/DataDomain.d.ts +34 -20
- package/build/src/modeling/DataDomain.d.ts.map +1 -1
- package/build/src/modeling/DataDomain.js +64 -24
- package/build/src/modeling/DataDomain.js.map +1 -1
- package/build/src/modeling/DependentModel.d.ts +26 -0
- package/build/src/modeling/DependentModel.d.ts.map +1 -0
- package/build/src/modeling/DependentModel.js +23 -0
- package/build/src/modeling/DependentModel.js.map +1 -0
- package/build/src/modeling/types.d.ts +2 -0
- package/build/src/modeling/types.d.ts.map +1 -1
- package/build/src/modeling/types.js.map +1 -1
- package/build/src/models/store/Backend.d.ts +0 -168
- package/build/src/models/store/Backend.d.ts.map +1 -1
- package/build/src/models/store/Backend.js +1 -12
- package/build/src/models/store/Backend.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/data/models/example-generator-api.json +16 -16
- package/package.json +1 -1
- package/src/amf/ApiSchemaValues.ts +1 -1
- package/src/modeling/ApiModel.ts +74 -31
- package/src/modeling/DataDomain.ts +65 -35
- package/src/modeling/DependentModel.ts +36 -0
- package/src/modeling/types.ts +2 -0
- package/src/models/store/Backend.ts +0 -176
- package/tests/unit/modeling/api_model.spec.ts +17 -15
- package/tests/unit/modeling/data_domain_foreign.spec.ts +172 -39
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiSchemaValues.js","sourceRoot":"","sources":["../../../src/amf/ApiSchemaValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM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AAS,CAAC,IAAI;gBACvB,OAAO,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAClD,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ;gBAC3B,OAAO,eAAe,CAAC,kBAAkB,CAAC,KAAwB,EAAE,MAAM,CAAC,CAAA;YAC7E,KAAK,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY;gBAC1C,OAAO,eAAe,CAAC,sBAAsB,CAAC,KAAwB,CAAC,CAAA;YACzE;gBACE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QACxB,CAAC;IACH,CAAC","sourcesContent":["import { Types } from '@pawel-up/data-mock/Types.js'\nimport { Person } from '@pawel-up/data-mock/Person.js'\nimport { Lorem } from '@pawel-up/data-mock/Lorem.js'\nimport { Time } from '@pawel-up/data-mock/Time.js'\nimport { AmfNamespace as ns } from './definitions/Namespace.js'\nimport { JsonDataNodeGenerator } from './data-node/JsonDataNodeGenerator.js'\nimport { parseBooleanInput, parseNumberInput, readTypedValue } from './Utils.js'\nimport { IApiParameter } from './definitions/Api.js'\nimport {\n IApiAnyShape,\n IApiArrayNode,\n IApiArrayShape,\n IApiDataExample,\n IApiScalarNode,\n IApiScalarShape,\n IShapeUnion,\n} from './definitions/Shapes.js'\nimport { ILoremWordInit, ITypeHashInit, ITypeNumberInit } from '@pawel-up/data-mock/types.js'\n\nexport interface IApiSchemaReadOptions {\n /**\n * Whether the value should be read only when the required property is set.\n */\n requiredOnly?: boolean\n /**\n * Whether to read the examples to generate the value.\n */\n fromExamples?: boolean\n}\n\n/**\n * A utility class with helper functions to read values from a schema definition\n */\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class ApiSchemaValues {\n static types = new Types()\n static person = new Person()\n static lorem = new Lorem()\n /**\n * Reads the value to be set on an input. This is for Scalar shapes only.\n *\n * @returns The value to set on the input. Note, it is not cast to the type.\n */\n static readInputValue(\n parameter: IApiParameter,\n schema: IApiScalarShape,\n opts: IApiSchemaReadOptions = {}\n ): string | number | boolean | null | undefined {\n const { required } = parameter\n const { defaultValueStr, values } = schema\n if (!required && opts.requiredOnly === true) {\n return undefined\n }\n if (defaultValueStr) {\n return ApiSchemaValues.readTypedValue(defaultValueStr, schema.dataType)\n }\n if (Array.isArray(values) && values.length) {\n const firstEnum = values[0] as IApiScalarNode\n return ApiSchemaValues.readTypedValue(firstEnum.value, firstEnum.dataType)\n }\n if (opts.fromExamples) {\n let examples: IApiDataExample[] | undefined\n if (Array.isArray(parameter.examples) && parameter.examples.length) {\n // just in case when an ApiParameter was passed.\n examples = parameter.examples.filter((i) => typeof i !== 'string')\n } else if (Array.isArray(schema.examples) && schema.examples.length) {\n examples = schema.examples\n }\n if (examples && examples.length) {\n return ApiSchemaValues.inputValueFromExamples(examples)\n }\n }\n return ApiSchemaValues.generateDefaultValue(schema)\n }\n\n /**\n * @param parameter The parameter that has the array schema.\n * @param schema The final schema to use to read the data from.\n */\n static readInputValues(parameter: IApiParameter, schema: IShapeUnion, opts: IApiSchemaReadOptions = {}): unknown[] {\n if (!parameter.required && opts.requiredOnly === true) {\n // for a non required array items just skip showing example values\n // as they are not crucial to make an HTTP request.\n return []\n }\n const { defaultValue } = schema\n if (defaultValue) {\n const gen = new JsonDataNodeGenerator()\n const result = gen.processNode(defaultValue)\n if (Array.isArray(result)) {\n return result\n }\n }\n const anySchema = schema as IApiAnyShape\n if (opts.fromExamples) {\n let examples: IApiDataExample[] | undefined\n if (Array.isArray(parameter.examples) && parameter.examples.length) {\n // just in case when an ApiParameter was passed.\n examples = parameter.examples.filter((i) => typeof i !== 'string')\n } else if (Array.isArray(anySchema.examples) && anySchema.examples.length) {\n examples = anySchema.examples\n }\n return ApiSchemaValues.arrayValuesFromExamples(examples)\n }\n return []\n }\n\n /**\n * Reads the value for the form input(s) from examples.\n */\n static inputValueFromExamples(examples: IApiDataExample[]): string | number | boolean | null | undefined {\n if (!Array.isArray(examples) || !examples.length) {\n return undefined\n }\n const [example] = examples\n const { structuredValue } = example\n if (!structuredValue) {\n return undefined\n }\n if (structuredValue.types.includes(ns.aml.vocabularies.data.Scalar)) {\n const value = structuredValue as IApiScalarNode\n return ApiSchemaValues.readTypedValue(value.value, value.dataType)\n }\n return undefined\n }\n\n /**\n * Reads the array value from examples.\n * @param examples Examples set on an array item.\n */\n static arrayValuesFromExamples(examples?: IApiDataExample[]): (string | number | boolean | null | undefined)[] {\n const result: (string | number | boolean | null | undefined)[] = []\n if (!Array.isArray(examples) || !examples.length) {\n return result\n }\n const [example] = examples\n if (!example.structuredValue || !example.structuredValue.types.includes(ns.aml.vocabularies.data.Array)) {\n return result\n }\n const value = example.structuredValue as IApiArrayNode\n const { members } = value\n if (!Array.isArray(members) || !members.length) {\n return result\n }\n members.forEach((item) => {\n const scalar = item as IApiScalarNode\n if (!scalar.value) {\n return\n }\n const typedValue = ApiSchemaValues.readTypedValue(scalar.value, scalar.dataType)\n if (typeof value !== 'undefined' && value !== null) {\n result.push(typedValue)\n }\n })\n return result\n }\n\n /**\n * Generates a default value from the schema type.\n * For booleans it returns `false`, for numbers `0`, nulls `null`, etc.\n * It does not generate a value for `string` types!\n */\n static generateDefaultValue(schema: IApiScalarShape): string | number | boolean | null | undefined {\n const { dataType } = schema\n return this.defaultValue(dataType)\n }\n\n /**\n * Generates a default value from the schema type.\n * For booleans it returns `false`, for numbers `0`, nulls `null`, etc.\n * It does not generate a value for `string` types!\n */\n static generateMockedValue(schema: IApiScalarShape): string | number | boolean | null | undefined {\n const { dataType } = schema\n switch (dataType) {\n case ns.w3.xmlSchema.string:\n return this.generateStringValue(schema)\n // XML schema, for DataNode\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n return this.generateNumberValue(schema)\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return this.types.boolean()\n case ns.aml.vocabularies.shapes.nil:\n case ns.w3.xmlSchema.nil:\n return null\n case ns.w3.xmlSchema.date:\n return new Time().dateOnly()\n case ns.w3.xmlSchema.dateTime:\n return new Time().dateTime((schema.format === 'date-time' ? 'rfc3339' : schema.format) as 'rfc3339' | 'rfc2616')\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return new Time().dateTimeOnly()\n case ns.w3.xmlSchema.time:\n return new Time().timeOnly()\n default:\n return undefined\n }\n }\n\n static defaultValue(dataType?: string): string | number | boolean | null | undefined {\n switch (dataType) {\n case ns.w3.xmlSchema.string:\n return ''\n // XML schema, for DataNode\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n return 0\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return false\n case ns.aml.vocabularies.shapes.nil:\n case ns.w3.xmlSchema.nil:\n return null\n case ns.w3.xmlSchema.date:\n return ''\n case ns.w3.xmlSchema.dateTime:\n return ''\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return ''\n case ns.w3.xmlSchema.time:\n return ''\n default:\n return undefined\n }\n }\n\n /**\n * Generates a random number value given the schema definition for a number scalar.\n */\n static generateNumberValue(schema: IApiScalarShape): number {\n const { minimum, maximum, format, multipleOf } = schema\n const init: ITypeNumberInit = {}\n if (typeof minimum === 'number') {\n init.min = minimum\n }\n if (typeof maximum === 'number') {\n init.max = maximum\n }\n let generator: ((init?: number | ITypeNumberInit | undefined) => number) | undefined\n if (format && ['float', 'double'].includes(format)) {\n generator = this.types.float.bind(this.types)\n } else if (format && ['uint32', 'uint64', 'fixed32', 'fixed64'].includes(format)) {\n // these are unsigned numbers, make sure the generate anything above 0\n init.min = 0\n if (init.max && init.max < 0) {\n delete init.max\n }\n }\n\n if (!generator) {\n // by default generate an integer\n generator = this.types.number.bind(this.types)\n }\n if (typeof multipleOf === 'number') {\n init.precision = multipleOf\n }\n return generator(init)\n }\n\n static generateStringValue(schema: IApiScalarShape): string {\n const { minLength, maxLength, name = '', format } = schema\n const lowerName = name.toLowerCase()\n // we employ some heuristics to generate content based on the property name.\n if (lowerName === 'description') {\n return this.lorem.paragraph()\n }\n if (format === 'uuid') {\n return this.types.uuid()\n }\n if (lowerName === 'id') {\n const init: ITypeHashInit = { length: 12 }\n const hasMin = typeof minLength === 'number'\n if (hasMin) {\n init.length = minLength\n } else if (!hasMin && typeof maxLength === 'number') {\n init.length = maxLength\n }\n return this.types.hash(init)\n }\n if (['name', 'fullname'].includes(lowerName)) {\n return this.person.name()\n }\n if (lowerName === 'firstname') {\n return this.person.firstName()\n }\n if (lowerName === 'lastname') {\n return this.person.lastName()\n }\n // if (['zip', 'postcode', 'postalcode', 'zipcode'].includes(lowerName)) {\n // return this.mocking.word\n // }\n\n const init: ILoremWordInit = {}\n const hasMin = typeof minLength === 'number'\n if (hasMin) {\n init.length = minLength\n } else if (!hasMin && typeof maxLength === 'number') {\n init.length = maxLength\n }\n\n return this.lorem.word(init)\n }\n\n /**\n * Casts the `value` to the corresponding data type\n * @param type The w3 schema type\n */\n static readTypedValue(value: unknown, type?: string): string | number | boolean | null | undefined {\n return readTypedValue(value, type)\n }\n\n /**\n * @param schemaType Data type encoded in the parameter schema.\n * @returns One of the HTML input element type values.\n */\n static readInputType(schemaType: string): 'number' | 'boolean' | 'date' | 'time' | 'datetime-local' | 'text' {\n switch (schemaType) {\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n return 'number'\n case ns.w3.xmlSchema.date:\n return 'date'\n case ns.w3.xmlSchema.time:\n return 'time'\n case ns.w3.xmlSchema.dateTime:\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return 'datetime-local'\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return 'boolean'\n default:\n return 'text'\n }\n }\n\n /**\n * Processes a value that should be a number.\n */\n static parseNumberInput(value: unknown, defaultValue?: number): number | undefined {\n return parseNumberInput(value, defaultValue)\n }\n\n /**\n * Processes a value that should be a number.\n */\n static parseBooleanInput(value: unknown, defaultValue?: boolean): boolean | undefined {\n return parseBooleanInput(value, defaultValue)\n }\n\n /**\n * Processes a value that should be a date formatted as yyyy-MM-dd.\n */\n static parseDateOnlyInput(value: unknown): string | undefined {\n const d = new Date(value as string | number)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n const result = d.toJSON()\n const timeSeparator = result.indexOf('T')\n return result.substring(0, timeSeparator)\n }\n\n /**\n * Processes a value that should be a date formatted as hh:mm:ss.\n */\n static parseTimeOnlyInput(input: unknown): string | undefined {\n const value = String(input).trim()\n if (/^\\d\\d:\\d\\d$/.test(value)) {\n return `${value}:00`\n }\n if (/^\\d\\d:\\d\\d:\\d\\d$/.test(value)) {\n return value\n }\n return undefined\n }\n\n /**\n * Processes a value that should be a date formatted in one of the supported formats:\n * - rfc3339 (default): 2016-02-28T16:41:41.090Z\n * - rfc2616: Sun, 28 Feb 2016 16:41:41 GMT\n */\n static parseDateTimeInput(value: string | number, format = 'rfc3339'): string | undefined {\n const d = new Date(value)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n if (format === 'rfc2616') {\n return d.toUTCString()\n }\n // OAS has the `date-time` format describing rfc3339.\n if (['rfc3339', 'date-time'].includes(format)) {\n return d.toISOString()\n }\n return undefined\n }\n\n /**\n * Processes a value that should be a date formatted as yyyy-MM-ddThh:mm\n */\n static parseDateTimeOnlyInput(value: string | number): string | undefined {\n const d = new Date(value)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n const jsonDate = d.toJSON() // \"yyyy-MM-ddThh:mm:ss.090Z\"\n const dot = jsonDate.indexOf('.')\n return jsonDate.substring(0, dot)\n }\n\n /**\n * Parses the the value according to array schema value.\n */\n static parseArrayInput(value: unknown, schema: IApiArrayShape): string | number | boolean | null | undefined {\n const { items } = schema\n if (!items) {\n return String(value)\n }\n return ApiSchemaValues.parseUserInput(value, items)\n }\n\n /**\n * Parses the user entered value according to the schema definition.\n */\n static parseUserInput(value: unknown, schema: IShapeUnion): string | number | boolean | null | undefined {\n if (!schema || value === undefined || value === null) {\n return value as null | undefined\n }\n const { types } = schema\n if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {\n return ApiSchemaValues.parseScalarInput(value, schema as IApiScalarShape)\n }\n if (\n types.includes(ns.aml.vocabularies.shapes.ArrayShape) ||\n types.includes(ns.aml.vocabularies.shapes.MatrixShape)\n ) {\n return ApiSchemaValues.parseArrayInput(value, schema as IApiArrayShape)\n }\n return value as string | number | boolean\n }\n\n /**\n * Parses the user entered value as scalar value.\n */\n static parseScalarInput(value: unknown, schema: IApiScalarShape): string | number | boolean | null | undefined {\n return this.parseScalar(value, schema.dataType, schema.format)\n }\n\n static parseScalar(value: unknown, dataType?: string, format?: string): string | number | boolean | null | undefined {\n switch (dataType) {\n // AML shapes, for Shape\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n return ApiSchemaValues.parseNumberInput(value)\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return ApiSchemaValues.parseBooleanInput(value)\n case ns.w3.xmlSchema.date:\n return ApiSchemaValues.parseDateOnlyInput(value)\n case ns.w3.xmlSchema.time:\n return ApiSchemaValues.parseTimeOnlyInput(value)\n case ns.w3.xmlSchema.dateTime:\n return ApiSchemaValues.parseDateTimeInput(value as string | number, format)\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return ApiSchemaValues.parseDateTimeOnlyInput(value as string | number)\n default:\n return String(value)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ApiSchemaValues.js","sourceRoot":"","sources":["../../../src/amf/ApiSchemaValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAA;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAClD,OAAO,EAAE,YAAY,IAAI,EAAE,EAAE,MAAM,4BAA4B,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAC5E,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAwBhF;;GAEG;AACH,kEAAkE;AAClE,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;IAC1B,MAAM,CAAC,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA;IAC5B,MAAM,CAAC,KAAK,GAAG,IAAI,KAAK,EAAE,CAAA;IAC1B;;;;OAIG;IACH,MAAM,CAAC,cAAc,CACnB,SAAwB,EACxB,MAAuB,EACvB,OAA8B,EAAE;QAEhC,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAA;QAC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AAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC;YAC3B,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC;YAC1B,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM;gBACzB,OAAO,eAAe,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;YAChD,KAAK,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC;YACxC,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO;gBAC1B,OAAO,eAAe,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;YACjD,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI;gBACvB,OAAO,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAClD,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,IAAI;gBACvB,OAAO,eAAe,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAA;YAClD,KAAK,EAAE,CAAC,EAAE,CAAC,SAAS,CAAC,QAAQ;gBAC3B,OAAO,eAAe,CAAC,kBAAkB,CAAC,KAAwB,EAAE,MAAM,CAAC,CAAA;YAC7E,KAAK,EAAE,CAAC,GAAG,CAAC,YAAY,CAAC,MAAM,CAAC,YAAY;gBAC1C,OAAO,eAAe,CAAC,sBAAsB,CAAC,KAAwB,CAAC,CAAA;YACzE;gBACE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;QACxB,CAAC;IACH,CAAC","sourcesContent":["import { Types } from '@pawel-up/data-mock/Types.js'\nimport { Person } from '@pawel-up/data-mock/Person.js'\nimport { Lorem } from '@pawel-up/data-mock/Lorem.js'\nimport { Time } from '@pawel-up/data-mock/Time.js'\nimport { AmfNamespace as ns } from './definitions/Namespace.js'\nimport { JsonDataNodeGenerator } from './data-node/JsonDataNodeGenerator.js'\nimport { parseBooleanInput, parseNumberInput, readTypedValue } from './Utils.js'\nimport { IApiParameter } from './definitions/Api.js'\nimport {\n IApiAnyShape,\n IApiArrayNode,\n IApiArrayShape,\n IApiDataExample,\n IApiScalarNode,\n IApiScalarShape,\n IShapeUnion,\n} from './definitions/Shapes.js'\nimport type { ILoremWordInit, ITypeHashInit, ITypeNumberInit } from '@pawel-up/data-mock/types.js'\n\nexport interface IApiSchemaReadOptions {\n /**\n * Whether the value should be read only when the required property is set.\n */\n requiredOnly?: boolean\n /**\n * Whether to read the examples to generate the value.\n */\n fromExamples?: boolean\n}\n\n/**\n * A utility class with helper functions to read values from a schema definition\n */\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class ApiSchemaValues {\n static types = new Types()\n static person = new Person()\n static lorem = new Lorem()\n /**\n * Reads the value to be set on an input. This is for Scalar shapes only.\n *\n * @returns The value to set on the input. Note, it is not cast to the type.\n */\n static readInputValue(\n parameter: IApiParameter,\n schema: IApiScalarShape,\n opts: IApiSchemaReadOptions = {}\n ): string | number | boolean | null | undefined {\n const { required } = parameter\n const { defaultValueStr, values } = schema\n if (!required && opts.requiredOnly === true) {\n return undefined\n }\n if (defaultValueStr) {\n return ApiSchemaValues.readTypedValue(defaultValueStr, schema.dataType)\n }\n if (Array.isArray(values) && values.length) {\n const firstEnum = values[0] as IApiScalarNode\n return ApiSchemaValues.readTypedValue(firstEnum.value, firstEnum.dataType)\n }\n if (opts.fromExamples) {\n let examples: IApiDataExample[] | undefined\n if (Array.isArray(parameter.examples) && parameter.examples.length) {\n // just in case when an ApiParameter was passed.\n examples = parameter.examples.filter((i) => typeof i !== 'string')\n } else if (Array.isArray(schema.examples) && schema.examples.length) {\n examples = schema.examples\n }\n if (examples && examples.length) {\n return ApiSchemaValues.inputValueFromExamples(examples)\n }\n }\n return ApiSchemaValues.generateDefaultValue(schema)\n }\n\n /**\n * @param parameter The parameter that has the array schema.\n * @param schema The final schema to use to read the data from.\n */\n static readInputValues(parameter: IApiParameter, schema: IShapeUnion, opts: IApiSchemaReadOptions = {}): unknown[] {\n if (!parameter.required && opts.requiredOnly === true) {\n // for a non required array items just skip showing example values\n // as they are not crucial to make an HTTP request.\n return []\n }\n const { defaultValue } = schema\n if (defaultValue) {\n const gen = new JsonDataNodeGenerator()\n const result = gen.processNode(defaultValue)\n if (Array.isArray(result)) {\n return result\n }\n }\n const anySchema = schema as IApiAnyShape\n if (opts.fromExamples) {\n let examples: IApiDataExample[] | undefined\n if (Array.isArray(parameter.examples) && parameter.examples.length) {\n // just in case when an ApiParameter was passed.\n examples = parameter.examples.filter((i) => typeof i !== 'string')\n } else if (Array.isArray(anySchema.examples) && anySchema.examples.length) {\n examples = anySchema.examples\n }\n return ApiSchemaValues.arrayValuesFromExamples(examples)\n }\n return []\n }\n\n /**\n * Reads the value for the form input(s) from examples.\n */\n static inputValueFromExamples(examples: IApiDataExample[]): string | number | boolean | null | undefined {\n if (!Array.isArray(examples) || !examples.length) {\n return undefined\n }\n const [example] = examples\n const { structuredValue } = example\n if (!structuredValue) {\n return undefined\n }\n if (structuredValue.types.includes(ns.aml.vocabularies.data.Scalar)) {\n const value = structuredValue as IApiScalarNode\n return ApiSchemaValues.readTypedValue(value.value, value.dataType)\n }\n return undefined\n }\n\n /**\n * Reads the array value from examples.\n * @param examples Examples set on an array item.\n */\n static arrayValuesFromExamples(examples?: IApiDataExample[]): (string | number | boolean | null | undefined)[] {\n const result: (string | number | boolean | null | undefined)[] = []\n if (!Array.isArray(examples) || !examples.length) {\n return result\n }\n const [example] = examples\n if (!example.structuredValue || !example.structuredValue.types.includes(ns.aml.vocabularies.data.Array)) {\n return result\n }\n const value = example.structuredValue as IApiArrayNode\n const { members } = value\n if (!Array.isArray(members) || !members.length) {\n return result\n }\n members.forEach((item) => {\n const scalar = item as IApiScalarNode\n if (!scalar.value) {\n return\n }\n const typedValue = ApiSchemaValues.readTypedValue(scalar.value, scalar.dataType)\n if (typeof value !== 'undefined' && value !== null) {\n result.push(typedValue)\n }\n })\n return result\n }\n\n /**\n * Generates a default value from the schema type.\n * For booleans it returns `false`, for numbers `0`, nulls `null`, etc.\n * It does not generate a value for `string` types!\n */\n static generateDefaultValue(schema: IApiScalarShape): string | number | boolean | null | undefined {\n const { dataType } = schema\n return this.defaultValue(dataType)\n }\n\n /**\n * Generates a default value from the schema type.\n * For booleans it returns `false`, for numbers `0`, nulls `null`, etc.\n * It does not generate a value for `string` types!\n */\n static generateMockedValue(schema: IApiScalarShape): string | number | boolean | null | undefined {\n const { dataType } = schema\n switch (dataType) {\n case ns.w3.xmlSchema.string:\n return this.generateStringValue(schema)\n // XML schema, for DataNode\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n return this.generateNumberValue(schema)\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return this.types.boolean()\n case ns.aml.vocabularies.shapes.nil:\n case ns.w3.xmlSchema.nil:\n return null\n case ns.w3.xmlSchema.date:\n return new Time().dateOnly()\n case ns.w3.xmlSchema.dateTime:\n return new Time().dateTime((schema.format === 'date-time' ? 'rfc3339' : schema.format) as 'rfc3339' | 'rfc2616')\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return new Time().dateTimeOnly()\n case ns.w3.xmlSchema.time:\n return new Time().timeOnly()\n default:\n return undefined\n }\n }\n\n static defaultValue(dataType?: string): string | number | boolean | null | undefined {\n switch (dataType) {\n case ns.w3.xmlSchema.string:\n return ''\n // XML schema, for DataNode\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n return 0\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return false\n case ns.aml.vocabularies.shapes.nil:\n case ns.w3.xmlSchema.nil:\n return null\n case ns.w3.xmlSchema.date:\n return ''\n case ns.w3.xmlSchema.dateTime:\n return ''\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return ''\n case ns.w3.xmlSchema.time:\n return ''\n default:\n return undefined\n }\n }\n\n /**\n * Generates a random number value given the schema definition for a number scalar.\n */\n static generateNumberValue(schema: IApiScalarShape): number {\n const { minimum, maximum, format, multipleOf } = schema\n const init: ITypeNumberInit = {}\n if (typeof minimum === 'number') {\n init.min = minimum\n }\n if (typeof maximum === 'number') {\n init.max = maximum\n }\n let generator: ((init?: number | ITypeNumberInit | undefined) => number) | undefined\n if (format && ['float', 'double'].includes(format)) {\n generator = this.types.float.bind(this.types)\n } else if (format && ['uint32', 'uint64', 'fixed32', 'fixed64'].includes(format)) {\n // these are unsigned numbers, make sure the generate anything above 0\n init.min = 0\n if (init.max && init.max < 0) {\n delete init.max\n }\n }\n\n if (!generator) {\n // by default generate an integer\n generator = this.types.number.bind(this.types)\n }\n if (typeof multipleOf === 'number') {\n init.precision = multipleOf\n }\n return generator(init)\n }\n\n static generateStringValue(schema: IApiScalarShape): string {\n const { minLength, maxLength, name = '', format } = schema\n const lowerName = name.toLowerCase()\n // we employ some heuristics to generate content based on the property name.\n if (lowerName === 'description') {\n return this.lorem.paragraph()\n }\n if (format === 'uuid') {\n return this.types.uuid()\n }\n if (lowerName === 'id') {\n const init: ITypeHashInit = { length: 12 }\n const hasMin = typeof minLength === 'number'\n if (hasMin) {\n init.length = minLength\n } else if (!hasMin && typeof maxLength === 'number') {\n init.length = maxLength\n }\n return this.types.hash(init)\n }\n if (['name', 'fullname'].includes(lowerName)) {\n return this.person.name()\n }\n if (lowerName === 'firstname') {\n return this.person.firstName()\n }\n if (lowerName === 'lastname') {\n return this.person.lastName()\n }\n // if (['zip', 'postcode', 'postalcode', 'zipcode'].includes(lowerName)) {\n // return this.mocking.word\n // }\n\n const init: ILoremWordInit = {}\n const hasMin = typeof minLength === 'number'\n if (hasMin) {\n init.length = minLength\n } else if (!hasMin && typeof maxLength === 'number') {\n init.length = maxLength\n }\n\n return this.lorem.word(init)\n }\n\n /**\n * Casts the `value` to the corresponding data type\n * @param type The w3 schema type\n */\n static readTypedValue(value: unknown, type?: string): string | number | boolean | null | undefined {\n return readTypedValue(value, type)\n }\n\n /**\n * @param schemaType Data type encoded in the parameter schema.\n * @returns One of the HTML input element type values.\n */\n static readInputType(schemaType: string): 'number' | 'boolean' | 'date' | 'time' | 'datetime-local' | 'text' {\n switch (schemaType) {\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n return 'number'\n case ns.w3.xmlSchema.date:\n return 'date'\n case ns.w3.xmlSchema.time:\n return 'time'\n case ns.w3.xmlSchema.dateTime:\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return 'datetime-local'\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return 'boolean'\n default:\n return 'text'\n }\n }\n\n /**\n * Processes a value that should be a number.\n */\n static parseNumberInput(value: unknown, defaultValue?: number): number | undefined {\n return parseNumberInput(value, defaultValue)\n }\n\n /**\n * Processes a value that should be a number.\n */\n static parseBooleanInput(value: unknown, defaultValue?: boolean): boolean | undefined {\n return parseBooleanInput(value, defaultValue)\n }\n\n /**\n * Processes a value that should be a date formatted as yyyy-MM-dd.\n */\n static parseDateOnlyInput(value: unknown): string | undefined {\n const d = new Date(value as string | number)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n const result = d.toJSON()\n const timeSeparator = result.indexOf('T')\n return result.substring(0, timeSeparator)\n }\n\n /**\n * Processes a value that should be a date formatted as hh:mm:ss.\n */\n static parseTimeOnlyInput(input: unknown): string | undefined {\n const value = String(input).trim()\n if (/^\\d\\d:\\d\\d$/.test(value)) {\n return `${value}:00`\n }\n if (/^\\d\\d:\\d\\d:\\d\\d$/.test(value)) {\n return value\n }\n return undefined\n }\n\n /**\n * Processes a value that should be a date formatted in one of the supported formats:\n * - rfc3339 (default): 2016-02-28T16:41:41.090Z\n * - rfc2616: Sun, 28 Feb 2016 16:41:41 GMT\n */\n static parseDateTimeInput(value: string | number, format = 'rfc3339'): string | undefined {\n const d = new Date(value)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n if (format === 'rfc2616') {\n return d.toUTCString()\n }\n // OAS has the `date-time` format describing rfc3339.\n if (['rfc3339', 'date-time'].includes(format)) {\n return d.toISOString()\n }\n return undefined\n }\n\n /**\n * Processes a value that should be a date formatted as yyyy-MM-ddThh:mm\n */\n static parseDateTimeOnlyInput(value: string | number): string | undefined {\n const d = new Date(value)\n if (Number.isNaN(d.getTime())) {\n return undefined\n }\n const jsonDate = d.toJSON() // \"yyyy-MM-ddThh:mm:ss.090Z\"\n const dot = jsonDate.indexOf('.')\n return jsonDate.substring(0, dot)\n }\n\n /**\n * Parses the the value according to array schema value.\n */\n static parseArrayInput(value: unknown, schema: IApiArrayShape): string | number | boolean | null | undefined {\n const { items } = schema\n if (!items) {\n return String(value)\n }\n return ApiSchemaValues.parseUserInput(value, items)\n }\n\n /**\n * Parses the user entered value according to the schema definition.\n */\n static parseUserInput(value: unknown, schema: IShapeUnion): string | number | boolean | null | undefined {\n if (!schema || value === undefined || value === null) {\n return value as null | undefined\n }\n const { types } = schema\n if (types.includes(ns.aml.vocabularies.shapes.ScalarShape)) {\n return ApiSchemaValues.parseScalarInput(value, schema as IApiScalarShape)\n }\n if (\n types.includes(ns.aml.vocabularies.shapes.ArrayShape) ||\n types.includes(ns.aml.vocabularies.shapes.MatrixShape)\n ) {\n return ApiSchemaValues.parseArrayInput(value, schema as IApiArrayShape)\n }\n return value as string | number | boolean\n }\n\n /**\n * Parses the user entered value as scalar value.\n */\n static parseScalarInput(value: unknown, schema: IApiScalarShape): string | number | boolean | null | undefined {\n return this.parseScalar(value, schema.dataType, schema.format)\n }\n\n static parseScalar(value: unknown, dataType?: string, format?: string): string | number | boolean | null | undefined {\n switch (dataType) {\n // AML shapes, for Shape\n case ns.aml.vocabularies.shapes.number:\n case ns.aml.vocabularies.shapes.integer:\n case ns.aml.vocabularies.shapes.float:\n case ns.aml.vocabularies.shapes.long:\n case ns.aml.vocabularies.shapes.double:\n case ns.w3.xmlSchema.number:\n case ns.w3.xmlSchema.integer:\n case ns.w3.xmlSchema.float:\n case ns.w3.xmlSchema.long:\n case ns.w3.xmlSchema.double:\n return ApiSchemaValues.parseNumberInput(value)\n case ns.aml.vocabularies.shapes.boolean:\n case ns.w3.xmlSchema.boolean:\n return ApiSchemaValues.parseBooleanInput(value)\n case ns.w3.xmlSchema.date:\n return ApiSchemaValues.parseDateOnlyInput(value)\n case ns.w3.xmlSchema.time:\n return ApiSchemaValues.parseTimeOnlyInput(value)\n case ns.w3.xmlSchema.dateTime:\n return ApiSchemaValues.parseDateTimeInput(value as string | number, format)\n case ns.aml.vocabularies.shapes.dateTimeOnly:\n return ApiSchemaValues.parseDateTimeOnlyInput(value as string | number)\n default:\n return String(value)\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ApiModelKind } from '../models/kinds.js';
|
|
2
2
|
import { type IThing, Thing } from '../models/Thing.js';
|
|
3
|
-
import type { AccessRule, AuthenticationConfiguration, AuthorizationConfiguration, ExposedEntity,
|
|
4
|
-
import { DataDomain
|
|
5
|
-
|
|
3
|
+
import type { AccessRule, AuthenticationConfiguration, AuthorizationConfiguration, ExposedEntity, RateLimitingConfiguration, SessionConfiguration } from './types.js';
|
|
4
|
+
import { DataDomain } from './DataDomain.js';
|
|
5
|
+
import { DependentModel, type DomainDependency, type DependentModelSchema } from './DependentModel.js';
|
|
6
|
+
export interface ApiModelSchema extends DependentModelSchema {
|
|
6
7
|
/**
|
|
7
8
|
* The data domain kind recognizable by the ecosystem.
|
|
8
9
|
*/
|
|
@@ -23,11 +24,6 @@ export interface ApiModelSchema {
|
|
|
23
24
|
* This property is required to publish the API.
|
|
24
25
|
*/
|
|
25
26
|
userKey?: string;
|
|
26
|
-
/**
|
|
27
|
-
* Reference to the stable, version-controlled data definition from the
|
|
28
|
-
* Data Catalog. When not set, the model cannot be published.
|
|
29
|
-
*/
|
|
30
|
-
domain?: ForeignDomainDependency;
|
|
31
27
|
/**
|
|
32
28
|
* Configuration for how users prove their identity.
|
|
33
29
|
* The API model is invalid if this is not set.
|
|
@@ -63,7 +59,7 @@ export interface ApiModelSchema {
|
|
|
63
59
|
*/
|
|
64
60
|
rateLimiting?: RateLimitingConfiguration;
|
|
65
61
|
}
|
|
66
|
-
export declare class ApiModel extends
|
|
62
|
+
export declare class ApiModel extends DependentModel {
|
|
67
63
|
#private;
|
|
68
64
|
/**
|
|
69
65
|
* The data domain kind recognizable by the ecosystem.
|
|
@@ -85,11 +81,6 @@ export declare class ApiModel extends EventTarget {
|
|
|
85
81
|
* This property is required to publish the API.
|
|
86
82
|
*/
|
|
87
83
|
userKey?: string;
|
|
88
|
-
/**
|
|
89
|
-
* Reference to the stable, version-controlled data definition from the
|
|
90
|
-
* Data Catalog. When not set, the model cannot be published.
|
|
91
|
-
*/
|
|
92
|
-
domain?: ForeignDomainDependency;
|
|
93
84
|
/**
|
|
94
85
|
* Configuration for how users prove their identity.
|
|
95
86
|
* The API model is invalid if this is not set.
|
|
@@ -125,11 +116,16 @@ export declare class ApiModel extends EventTarget {
|
|
|
125
116
|
*/
|
|
126
117
|
rateLimiting?: RateLimitingConfiguration;
|
|
127
118
|
/**
|
|
128
|
-
* A
|
|
119
|
+
* A convenience getter that returns the DataDomain associated with this API model.
|
|
120
|
+
* Since the API model can have only one DataDomain,
|
|
121
|
+
* this getter returns the first dependency in the list.
|
|
122
|
+
*
|
|
123
|
+
* The parent interface `DependentModel` allows for multiple dependencies,
|
|
124
|
+
* to unify the dependency management across different models.
|
|
129
125
|
*/
|
|
130
|
-
|
|
126
|
+
get domain(): DataDomain | undefined;
|
|
131
127
|
static createSchema(input?: Partial<ApiModelSchema>): ApiModelSchema;
|
|
132
|
-
constructor(state?: Partial<ApiModelSchema>, domain?:
|
|
128
|
+
constructor(state?: Partial<ApiModelSchema>, domain?: DomainDependency);
|
|
133
129
|
toJSON(): ApiModelSchema;
|
|
134
130
|
/**
|
|
135
131
|
* This function is used internally by all domain elements to notify that something has changed.
|
|
@@ -155,5 +151,19 @@ export declare class ApiModel extends EventTarget {
|
|
|
155
151
|
* @returns The exposed entity or undefined if not found.
|
|
156
152
|
*/
|
|
157
153
|
getExposedEntity(entityKey: string): ExposedEntity | undefined;
|
|
154
|
+
/**
|
|
155
|
+
* Clears the API model for a new entity change.
|
|
156
|
+
* This method resets the dependencies, exposes, userKey,
|
|
157
|
+
* authentication, authorization, and session properties.
|
|
158
|
+
*/
|
|
159
|
+
cleanForEntityChange(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Attaches a DataDomain to this API model.
|
|
162
|
+
* This method clears any existing dependencies and sets the new domain.
|
|
163
|
+
*
|
|
164
|
+
* @param domain The DataDomain to attach to this API model.
|
|
165
|
+
* @throws Error if the domain does not have a version set in its info.
|
|
166
|
+
*/
|
|
167
|
+
attachDataDomain(domain: DataDomain): void;
|
|
158
168
|
}
|
|
159
169
|
//# sourceMappingURL=ApiModel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiModel.d.ts","sourceRoot":"","sources":["../../../src/modeling/ApiModel.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"ApiModel.d.ts","sourceRoot":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C,EAAE,2BAA2B,CAAA;IAE5C;;;OAGG;IACH,aAAa,CAAC,EAAE,0BAA0B,CAAA;IAE1C;;;OAGG;IACH,OAAO,CAAC,EAAE,oBAAoB,CAAA;IAC9B;;;OAGG;IACH,OAAO,EAAE,aAAa,EAAE,CAAA;IACxB;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,UAAU,EAAE,CAAA;IACzB;;;OAGG;IACH,YAAY,CAAC,EAAE,yBAAyB,CAAA;IAgBxC;;;;;;;OAOG;IACH,IAAI,MAAM,IAAI,UAAU,GAAG,SAAS,CAMnC;IAED,MAAM,CAAC,YAAY,CAAC,KAAK,GAAE,OAAO,CAAC,cAAc,CAAM,GAAG,cAAc;gBAiC5D,KAAK,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC,EAAE,gBAAgB;IAyCtE,MAAM,IAAI,cAAc;IA+BxB;;;;OAIG;IACH,YAAY;IAYZ;;;;;OAKG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa;IAc9C;;;OAGG;IACH,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IAOrC;;;;OAIG;IACH,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS;IAI9D;;;;OAIG;IACH,oBAAoB,IAAI,IAAI;IAkB5B;;;;;;OAMG;IACH,gBAAgB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;CAS3C"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { nanoid } from '../nanoid.js';
|
|
2
|
-
import { ApiModelKind } from '../models/kinds.js';
|
|
2
|
+
import { ApiModelKind, DataDomainKind } from '../models/kinds.js';
|
|
3
3
|
import { Thing } from '../models/Thing.js';
|
|
4
4
|
import { DataDomain } from './DataDomain.js';
|
|
5
|
-
|
|
5
|
+
import { DependentModel } from './DependentModel.js';
|
|
6
|
+
export class ApiModel extends DependentModel {
|
|
6
7
|
/**
|
|
7
8
|
* The data domain kind recognizable by the ecosystem.
|
|
8
9
|
*/
|
|
@@ -23,11 +24,6 @@ export class ApiModel extends EventTarget {
|
|
|
23
24
|
* This property is required to publish the API.
|
|
24
25
|
*/
|
|
25
26
|
userKey;
|
|
26
|
-
/**
|
|
27
|
-
* Reference to the stable, version-controlled data definition from the
|
|
28
|
-
* Data Catalog. When not set, the model cannot be published.
|
|
29
|
-
*/
|
|
30
|
-
domain;
|
|
31
27
|
/**
|
|
32
28
|
* Configuration for how users prove their identity.
|
|
33
29
|
* The API model is invalid if this is not set.
|
|
@@ -75,9 +71,20 @@ export class ApiModel extends EventTarget {
|
|
|
75
71
|
*/
|
|
76
72
|
#notifying = false;
|
|
77
73
|
/**
|
|
78
|
-
* A
|
|
74
|
+
* A convenience getter that returns the DataDomain associated with this API model.
|
|
75
|
+
* Since the API model can have only one DataDomain,
|
|
76
|
+
* this getter returns the first dependency in the list.
|
|
77
|
+
*
|
|
78
|
+
* The parent interface `DependentModel` allows for multiple dependencies,
|
|
79
|
+
* to unify the dependency management across different models.
|
|
79
80
|
*/
|
|
80
|
-
|
|
81
|
+
get domain() {
|
|
82
|
+
if (this.dependencyList.length === 0) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
const domain = this.dependencyList[0];
|
|
86
|
+
return this.dependencies.get(domain.key);
|
|
87
|
+
}
|
|
81
88
|
static createSchema(input = {}) {
|
|
82
89
|
const { key = nanoid(), exposes = [] } = input;
|
|
83
90
|
const info = Thing.fromJSON(input.info, { name: 'Unnamed API' }).toJSON();
|
|
@@ -90,8 +97,8 @@ export class ApiModel extends EventTarget {
|
|
|
90
97
|
if (input.userKey) {
|
|
91
98
|
result.userKey = input.userKey;
|
|
92
99
|
}
|
|
93
|
-
if (input.
|
|
94
|
-
result.
|
|
100
|
+
if (input.dependencyList) {
|
|
101
|
+
result.dependencyList = structuredClone(input.dependencyList);
|
|
95
102
|
}
|
|
96
103
|
if (input.authentication) {
|
|
97
104
|
result.authentication = input.authentication;
|
|
@@ -111,15 +118,22 @@ export class ApiModel extends EventTarget {
|
|
|
111
118
|
return result;
|
|
112
119
|
}
|
|
113
120
|
constructor(state, domain) {
|
|
114
|
-
super();
|
|
115
121
|
const init = ApiModel.createSchema(state);
|
|
122
|
+
const instances = [];
|
|
123
|
+
if (domain instanceof DataDomain) {
|
|
124
|
+
instances.push(domain);
|
|
125
|
+
}
|
|
126
|
+
else if (typeof domain === 'object' && domain.kind === DataDomainKind) {
|
|
127
|
+
instances.push(new DataDomain(domain));
|
|
128
|
+
}
|
|
129
|
+
else if (domain) {
|
|
130
|
+
throw new Error(`Invalid domain provided. Expected a DataDomain instance or schema.`);
|
|
131
|
+
}
|
|
132
|
+
super(init.dependencyList, instances);
|
|
116
133
|
this.kind = init.kind;
|
|
117
134
|
this.key = init.key;
|
|
118
135
|
this.info = new Thing(init.info);
|
|
119
136
|
this.userKey = init.userKey;
|
|
120
|
-
if (init.domain) {
|
|
121
|
-
this.domain = structuredClone(init.domain);
|
|
122
|
-
}
|
|
123
137
|
if (init.authentication) {
|
|
124
138
|
this.authentication = structuredClone(init.authentication);
|
|
125
139
|
}
|
|
@@ -141,9 +155,6 @@ export class ApiModel extends EventTarget {
|
|
|
141
155
|
if (init.rateLimiting) {
|
|
142
156
|
this.rateLimiting = structuredClone(init.rateLimiting);
|
|
143
157
|
}
|
|
144
|
-
if (domain) {
|
|
145
|
-
this.dataDomain = new DataDomain(domain);
|
|
146
|
-
}
|
|
147
158
|
this.#initializing = false;
|
|
148
159
|
this.info.addEventListener('change', () => {
|
|
149
160
|
this.notifyChange();
|
|
@@ -159,8 +170,8 @@ export class ApiModel extends EventTarget {
|
|
|
159
170
|
if (this.userKey) {
|
|
160
171
|
result.userKey = this.userKey;
|
|
161
172
|
}
|
|
162
|
-
if (this.
|
|
163
|
-
result.
|
|
173
|
+
if (this.dependencyList.length > 0) {
|
|
174
|
+
result.dependencyList = structuredClone(this.dependencyList);
|
|
164
175
|
}
|
|
165
176
|
if (this.authentication) {
|
|
166
177
|
result.authentication = structuredClone(this.authentication);
|
|
@@ -233,5 +244,43 @@ export class ApiModel extends EventTarget {
|
|
|
233
244
|
getExposedEntity(entityKey) {
|
|
234
245
|
return this.exposes.find((e) => e.key === entityKey);
|
|
235
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Clears the API model for a new entity change.
|
|
249
|
+
* This method resets the dependencies, exposes, userKey,
|
|
250
|
+
* authentication, authorization, and session properties.
|
|
251
|
+
*/
|
|
252
|
+
cleanForEntityChange() {
|
|
253
|
+
this.dependencies.clear();
|
|
254
|
+
this.dependencyList = [];
|
|
255
|
+
this.exposes = [];
|
|
256
|
+
this.userKey = undefined;
|
|
257
|
+
if (this.session) {
|
|
258
|
+
this.session.properties = [];
|
|
259
|
+
}
|
|
260
|
+
if (this.authentication && this.authentication.strategy === 'UsernamePassword') {
|
|
261
|
+
const typed = this.authentication;
|
|
262
|
+
typed.passwordKey = undefined;
|
|
263
|
+
}
|
|
264
|
+
if (this.authorization && this.authorization.strategy == 'RBAC') {
|
|
265
|
+
const typed = this.authorization;
|
|
266
|
+
typed.roleKey = '';
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Attaches a DataDomain to this API model.
|
|
271
|
+
* This method clears any existing dependencies and sets the new domain.
|
|
272
|
+
*
|
|
273
|
+
* @param domain The DataDomain to attach to this API model.
|
|
274
|
+
* @throws Error if the domain does not have a version set in its info.
|
|
275
|
+
*/
|
|
276
|
+
attachDataDomain(domain) {
|
|
277
|
+
if (!domain.info.version) {
|
|
278
|
+
throw new Error(`Cannot attach DataDomain without a version. Please set the version in the domain info.`);
|
|
279
|
+
}
|
|
280
|
+
this.cleanForEntityChange();
|
|
281
|
+
this.dependencies.set(domain.key, domain);
|
|
282
|
+
this.dependencyList = [{ key: domain.key, version: domain.info.version }];
|
|
283
|
+
this.notifyChange();
|
|
284
|
+
}
|
|
236
285
|
}
|
|
237
286
|
//# sourceMappingURL=ApiModel.js.map
|
|
@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\nimport { type IThing, Thing } from '../models/Thing.js'\nimport type {\n AccessRule,\n AuthenticationConfiguration,\n AuthorizationConfiguration,\n ExposedEntity,\n ForeignDomainDependency,\n RateLimitingConfiguration,\n SessionConfiguration,\n} from './types.js'\nimport { DataDomain, type DataDomainSchema } from './DataDomain.js'\n\nexport interface ApiModelSchema {\n /**\n * The data domain kind recognizable by the ecosystem.\n */\n kind: typeof ApiModelKind\n /**\n * The unique key of the data domain schema.\n * This is a stable identifier that does not change across versions.\n */\n key: string\n /**\n * Contains the name, display name, description, and the version of the data domain schema.\n */\n info: IThing\n\n /**\n * The designated Data Entity that represents a \"User\".\n * This entity must be marked with the \"User\" semantic in the Data Modeler.\n *\n * This property is required to publish the API.\n */\n userKey?: string\n\n /**\n * Reference to the stable, version-controlled data definition from the\n * Data Catalog. When not set, the model cannot be published.\n */\n domain?: ForeignDomainDependency\n\n /**\n * Configuration for how users prove their identity.\n * The API model is invalid if this is not set.\n */\n authentication?: AuthenticationConfiguration\n\n /**\n * Configuration for what authenticated users are allowed to do.\n * The API model is invalid if this is not set.\n */\n authorization?: AuthorizationConfiguration\n\n /**\n * Configuration for the transport and payload of the user session.\n * The API model is invalid if this is not set.\n */\n session?: SessionConfiguration\n /**\n * The specific subset of Data Entities to be exposed by this API.\n * These are the entities that are included in the data domain schema.\n */\n exposes: ExposedEntity[]\n\n /**\n * Optional array of access rules that define the access control policies\n * for the API. These rules are used to enforce security and permissions\n * on the exposed entities.\n *\n * These rules apply to all exposed entities and actions. An API action\n * can declare its own access rules, which will override these.\n */\n accessRule?: AccessRule[]\n /**\n * Optional configuration for API-wide rate limiting and throttling.\n * Defines rules to protect the API from overuse.\n */\n rateLimiting?: RateLimitingConfiguration\n}\n\nexport class ApiModel extends EventTarget {\n /**\n * The data domain kind recognizable by the ecosystem.\n */\n kind: typeof ApiModelKind\n /**\n * The unique key of the data domain schema.\n * This is a stable identifier that does not change across versions.\n */\n key: string\n\n /**\n * The description of the domain property.\n */\n info: Thing\n /**\n * The designated Data Entity that represents a \"User\".\n * This entity must be marked with the \"User\" semantic in the Data Modeler.\n *\n * This property is required to publish the API.\n */\n userKey?: string\n\n /**\n * Reference to the stable, version-controlled data definition from the\n * Data Catalog. When not set, the model cannot be published.\n */\n domain?: ForeignDomainDependency\n\n /**\n * Configuration for how users prove their identity.\n * The API model is invalid if this is not set.\n */\n authentication?: AuthenticationConfiguration\n\n /**\n * Configuration for what authenticated users are allowed to do.\n * The API model is invalid if this is not set.\n */\n authorization?: AuthorizationConfiguration\n\n /**\n * Configuration for the transport and payload of the user session.\n * The API model is invalid if this is not set.\n */\n session?: SessionConfiguration\n /**\n * The specific subset of Data Entities to be exposed by this API.\n * These are the entities that are included in the data domain schema.\n */\n exposes: ExposedEntity[]\n /**\n * Optional array of access rules that define the access control policies\n * for the API. These rules are used to enforce security and permissions\n * on the exposed entities.\n *\n * These rules apply to all exposed entities and actions. An API action\n * can declare its own access rules, which will override these.\n */\n accessRule?: AccessRule[]\n /**\n * Optional configuration for API-wide rate limiting and throttling.\n * Defines rules to protect the API from overuse.\n */\n rateLimiting?: RateLimitingConfiguration\n\n /**\n * When the initializing flag is set to true,\n * the domain is not notified of changes.\n */\n #initializing = true\n\n /**\n * When the notifying flag is set to true,\n * the domain is pending a notification.\n * No other notifications will be sent until\n * the current notification is sent.\n */\n #notifying = false\n\n /**\n * A reference to the published data domain.\n */\n dataDomain?: DataDomain\n\n static createSchema(input: Partial<ApiModelSchema> = {}): ApiModelSchema {\n const { key = nanoid(), exposes = [] } = input\n const info = Thing.fromJSON(input.info, { name: 'Unnamed API' }).toJSON()\n const result: ApiModelSchema = {\n kind: ApiModelKind,\n key,\n info,\n exposes,\n }\n if (input.userKey) {\n result.userKey = input.userKey\n }\n if (input.domain) {\n result.domain = input.domain\n }\n if (input.authentication) {\n result.authentication = input.authentication\n }\n if (input.authorization) {\n result.authorization = input.authorization\n }\n if (input.session) {\n result.session = input.session\n }\n if (input.accessRule) {\n result.accessRule = input.accessRule\n }\n if (input.rateLimiting) {\n result.rateLimiting = input.rateLimiting\n }\n return result\n }\n\n constructor(state?: Partial<ApiModelSchema>, domain?: DataDomainSchema) {\n super()\n const init = ApiModel.createSchema(state)\n this.kind = init.kind\n this.key = init.key\n this.info = new Thing(init.info)\n this.userKey = init.userKey\n if (init.domain) {\n this.domain = structuredClone(init.domain)\n }\n if (init.authentication) {\n this.authentication = structuredClone(init.authentication)\n }\n if (init.authorization) {\n this.authorization = structuredClone(init.authorization)\n }\n if (init.session) {\n this.session = structuredClone(init.session)\n }\n if (Array.isArray(init.exposes)) {\n this.exposes = structuredClone(init.exposes)\n } else {\n this.exposes = []\n }\n if (init.accessRule) {\n this.accessRule = structuredClone(init.accessRule)\n }\n if (init.rateLimiting) {\n this.rateLimiting = structuredClone(init.rateLimiting)\n }\n if (domain) {\n this.dataDomain = new DataDomain(domain)\n }\n this.#initializing = false\n this.info.addEventListener('change', () => {\n this.notifyChange()\n })\n }\n\n toJSON(): ApiModelSchema {\n const result: ApiModelSchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n exposes: structuredClone(this.exposes),\n }\n if (this.userKey) {\n result.userKey = this.userKey\n }\n if (this.domain) {\n result.domain = structuredClone(this.domain)\n }\n if (this.authentication) {\n result.authentication = structuredClone(this.authentication)\n }\n if (this.authorization) {\n result.authorization = structuredClone(this.authorization)\n }\n if (this.session) {\n result.session = structuredClone(this.session)\n }\n if (this.accessRule) {\n result.accessRule = structuredClone(this.accessRule)\n }\n if (this.rateLimiting) {\n result.rateLimiting = structuredClone(this.rateLimiting)\n }\n return result\n }\n\n /**\n * This function is used internally by all domain elements to notify that something has changed.\n * Since we want to notify listeners after the operation commits, we use microtask\n * to ensure that the event is dispatched after the current operation.\n */\n notifyChange() {\n if (this.#notifying || this.#initializing) {\n return\n }\n this.#notifying = true\n queueMicrotask(() => {\n this.#notifying = false\n const event = new Event('change')\n this.dispatchEvent(event)\n })\n }\n\n /**\n * Exposes a new entity in the API model.\n * If the entity already exists, it returns the existing one.\n * @param entityKey The key of the entity to expose.\n * @returns The exposed entity.\n */\n exposeEntity(entityKey: string): ExposedEntity {\n const existing = this.exposes.find((e) => e.key === entityKey)\n if (existing) {\n return existing\n }\n const newEntity: ExposedEntity = {\n key: entityKey,\n actions: [],\n }\n this.exposes.push(newEntity)\n this.notifyChange()\n return newEntity\n }\n\n /**\n * Removes an entity from the API model.\n * @param entityKey The key of the entity to remove.\n */\n removeEntity(entityKey: string): void {\n const index = this.exposes.findIndex((e) => e.key === entityKey)\n if (index !== -1) {\n this.exposes.splice(index, 1)\n this.notifyChange()\n }\n }\n /**\n * Returns the exposed entity by its key.\n * @param entityKey The key of the entity to find.\n * @returns The exposed entity or undefined if not found.\n */\n getExposedEntity(entityKey: string): ExposedEntity | undefined {\n return this.exposes.find((e) => e.key === entityKey)\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ApiModel.js","sourceRoot":"","sources":["../../../src/modeling/ApiModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACjE,OAAO,EAAe,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAWvD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAoD,MAAM,qBAAqB,CAAA;AAgEtG,MAAM,OAAO,QAAS,SAAQ,cAAc;IAC1C;;OAEG;IACH,IAAI,CAAqB;IACzB;;;OAGG;IACH,GAAG,CAAQ;IAEX;;OAEG;IACH,IAAI,CAAO;IACX;;;;;OAKG;IACH,OAAO,CAAS;IAEhB;;;OAGG;IACH,cAAc,CAA8B;IAE5C;;;OAGG;IACH,aAAa,CAA6B;IAE1C;;;OAGG;IACH,OAAO,CAAuB;IAC9B;;;OAGG;IACH,OAAO,CAAiB;IACxB;;;;;;;OAOG;IACH,UAAU,CAAe;IACzB;;;OAGG;IACH,Y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IAAI,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAA;QAC9B,CAAC;QACD,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,CAAC,cAAc,CAAC,QAAQ,KAAK,kBAAkB,EAAE,CAAC;YAC/E,MAAM,KAAK,GAAG,IAAI,CAAC,cAA+C,CAAA;YAClE,KAAK,CAAC,WAAW,GAAG,SAAS,CAAA;QAC/B,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,QAAQ,IAAI,MAAM,EAAE,CAAC;YAChE,MAAM,KAAK,GAAG,IAAI,CAAC,aAAwC,CAAA;YAC3D,KAAK,CAAC,OAAO,GAAG,EAAE,CAAA;QACpB,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACH,gBAAgB,CAAC,MAAkB;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,wFAAwF,CAAC,CAAA;QAC3G,CAAC;QACD,IAAI,CAAC,oBAAoB,EAAE,CAAA;QAC3B,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACzC,IAAI,CAAC,cAAc,GAAG,CAAC,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAA;QACzE,IAAI,CAAC,YAAY,EAAE,CAAA;IACrB,CAAC;CACF","sourcesContent":["import { nanoid } from '../nanoid.js'\nimport { ApiModelKind, DataDomainKind } from '../models/kinds.js'\nimport { type IThing, Thing } from '../models/Thing.js'\nimport type {\n AccessRule,\n AuthenticationConfiguration,\n AuthorizationConfiguration,\n ExposedEntity,\n RateLimitingConfiguration,\n RolesBasedAccessControl,\n SessionConfiguration,\n UsernamePasswordConfiguration,\n} from './types.js'\nimport { DataDomain } from './DataDomain.js'\nimport { DependentModel, type DomainDependency, type DependentModelSchema } from './DependentModel.js'\n\nexport interface ApiModelSchema extends DependentModelSchema {\n /**\n * The data domain kind recognizable by the ecosystem.\n */\n kind: typeof ApiModelKind\n /**\n * The unique key of the data domain schema.\n * This is a stable identifier that does not change across versions.\n */\n key: string\n /**\n * Contains the name, display name, description, and the version of the data domain schema.\n */\n info: IThing\n\n /**\n * The designated Data Entity that represents a \"User\".\n * This entity must be marked with the \"User\" semantic in the Data Modeler.\n *\n * This property is required to publish the API.\n */\n userKey?: string\n\n /**\n * Configuration for how users prove their identity.\n * The API model is invalid if this is not set.\n */\n authentication?: AuthenticationConfiguration\n\n /**\n * Configuration for what authenticated users are allowed to do.\n * The API model is invalid if this is not set.\n */\n authorization?: AuthorizationConfiguration\n\n /**\n * Configuration for the transport and payload of the user session.\n * The API model is invalid if this is not set.\n */\n session?: SessionConfiguration\n /**\n * The specific subset of Data Entities to be exposed by this API.\n * These are the entities that are included in the data domain schema.\n */\n exposes: ExposedEntity[]\n\n /**\n * Optional array of access rules that define the access control policies\n * for the API. These rules are used to enforce security and permissions\n * on the exposed entities.\n *\n * These rules apply to all exposed entities and actions. An API action\n * can declare its own access rules, which will override these.\n */\n accessRule?: AccessRule[]\n /**\n * Optional configuration for API-wide rate limiting and throttling.\n * Defines rules to protect the API from overuse.\n */\n rateLimiting?: RateLimitingConfiguration\n}\n\nexport class ApiModel extends DependentModel {\n /**\n * The data domain kind recognizable by the ecosystem.\n */\n kind: typeof ApiModelKind\n /**\n * The unique key of the data domain schema.\n * This is a stable identifier that does not change across versions.\n */\n key: string\n\n /**\n * The description of the domain property.\n */\n info: Thing\n /**\n * The designated Data Entity that represents a \"User\".\n * This entity must be marked with the \"User\" semantic in the Data Modeler.\n *\n * This property is required to publish the API.\n */\n userKey?: string\n\n /**\n * Configuration for how users prove their identity.\n * The API model is invalid if this is not set.\n */\n authentication?: AuthenticationConfiguration\n\n /**\n * Configuration for what authenticated users are allowed to do.\n * The API model is invalid if this is not set.\n */\n authorization?: AuthorizationConfiguration\n\n /**\n * Configuration for the transport and payload of the user session.\n * The API model is invalid if this is not set.\n */\n session?: SessionConfiguration\n /**\n * The specific subset of Data Entities to be exposed by this API.\n * These are the entities that are included in the data domain schema.\n */\n exposes: ExposedEntity[]\n /**\n * Optional array of access rules that define the access control policies\n * for the API. These rules are used to enforce security and permissions\n * on the exposed entities.\n *\n * These rules apply to all exposed entities and actions. An API action\n * can declare its own access rules, which will override these.\n */\n accessRule?: AccessRule[]\n /**\n * Optional configuration for API-wide rate limiting and throttling.\n * Defines rules to protect the API from overuse.\n */\n rateLimiting?: RateLimitingConfiguration\n\n /**\n * When the initializing flag is set to true,\n * the domain is not notified of changes.\n */\n #initializing = true\n\n /**\n * When the notifying flag is set to true,\n * the domain is pending a notification.\n * No other notifications will be sent until\n * the current notification is sent.\n */\n #notifying = false\n\n /**\n * A convenience getter that returns the DataDomain associated with this API model.\n * Since the API model can have only one DataDomain,\n * this getter returns the first dependency in the list.\n *\n * The parent interface `DependentModel` allows for multiple dependencies,\n * to unify the dependency management across different models.\n */\n get domain(): DataDomain | undefined {\n if (this.dependencyList.length === 0) {\n return undefined\n }\n const domain = this.dependencyList[0]\n return this.dependencies.get(domain.key)\n }\n\n static createSchema(input: Partial<ApiModelSchema> = {}): ApiModelSchema {\n const { key = nanoid(), exposes = [] } = input\n const info = Thing.fromJSON(input.info, { name: 'Unnamed API' }).toJSON()\n const result: ApiModelSchema = {\n kind: ApiModelKind,\n key,\n info,\n exposes,\n }\n if (input.userKey) {\n result.userKey = input.userKey\n }\n if (input.dependencyList) {\n result.dependencyList = structuredClone(input.dependencyList)\n }\n if (input.authentication) {\n result.authentication = input.authentication\n }\n if (input.authorization) {\n result.authorization = input.authorization\n }\n if (input.session) {\n result.session = input.session\n }\n if (input.accessRule) {\n result.accessRule = input.accessRule\n }\n if (input.rateLimiting) {\n result.rateLimiting = input.rateLimiting\n }\n return result\n }\n\n constructor(state?: Partial<ApiModelSchema>, domain?: DomainDependency) {\n const init = ApiModel.createSchema(state)\n const instances: DataDomain[] = []\n if (domain instanceof DataDomain) {\n instances.push(domain)\n } else if (typeof domain === 'object' && domain.kind === DataDomainKind) {\n instances.push(new DataDomain(domain))\n } else if (domain) {\n throw new Error(`Invalid domain provided. Expected a DataDomain instance or schema.`)\n }\n super(init.dependencyList, instances)\n this.kind = init.kind\n this.key = init.key\n this.info = new Thing(init.info)\n this.userKey = init.userKey\n if (init.authentication) {\n this.authentication = structuredClone(init.authentication)\n }\n if (init.authorization) {\n this.authorization = structuredClone(init.authorization)\n }\n if (init.session) {\n this.session = structuredClone(init.session)\n }\n if (Array.isArray(init.exposes)) {\n this.exposes = structuredClone(init.exposes)\n } else {\n this.exposes = []\n }\n if (init.accessRule) {\n this.accessRule = structuredClone(init.accessRule)\n }\n if (init.rateLimiting) {\n this.rateLimiting = structuredClone(init.rateLimiting)\n }\n this.#initializing = false\n this.info.addEventListener('change', () => {\n this.notifyChange()\n })\n }\n\n toJSON(): ApiModelSchema {\n const result: ApiModelSchema = {\n kind: this.kind,\n key: this.key,\n info: this.info.toJSON(),\n exposes: structuredClone(this.exposes),\n }\n if (this.userKey) {\n result.userKey = this.userKey\n }\n if (this.dependencyList.length > 0) {\n result.dependencyList = structuredClone(this.dependencyList)\n }\n if (this.authentication) {\n result.authentication = structuredClone(this.authentication)\n }\n if (this.authorization) {\n result.authorization = structuredClone(this.authorization)\n }\n if (this.session) {\n result.session = structuredClone(this.session)\n }\n if (this.accessRule) {\n result.accessRule = structuredClone(this.accessRule)\n }\n if (this.rateLimiting) {\n result.rateLimiting = structuredClone(this.rateLimiting)\n }\n return result\n }\n\n /**\n * This function is used internally by all domain elements to notify that something has changed.\n * Since we want to notify listeners after the operation commits, we use microtask\n * to ensure that the event is dispatched after the current operation.\n */\n notifyChange() {\n if (this.#notifying || this.#initializing) {\n return\n }\n this.#notifying = true\n queueMicrotask(() => {\n this.#notifying = false\n const event = new Event('change')\n this.dispatchEvent(event)\n })\n }\n\n /**\n * Exposes a new entity in the API model.\n * If the entity already exists, it returns the existing one.\n * @param entityKey The key of the entity to expose.\n * @returns The exposed entity.\n */\n exposeEntity(entityKey: string): ExposedEntity {\n const existing = this.exposes.find((e) => e.key === entityKey)\n if (existing) {\n return existing\n }\n const newEntity: ExposedEntity = {\n key: entityKey,\n actions: [],\n }\n this.exposes.push(newEntity)\n this.notifyChange()\n return newEntity\n }\n\n /**\n * Removes an entity from the API model.\n * @param entityKey The key of the entity to remove.\n */\n removeEntity(entityKey: string): void {\n const index = this.exposes.findIndex((e) => e.key === entityKey)\n if (index !== -1) {\n this.exposes.splice(index, 1)\n this.notifyChange()\n }\n }\n /**\n * Returns the exposed entity by its key.\n * @param entityKey The key of the entity to find.\n * @returns The exposed entity or undefined if not found.\n */\n getExposedEntity(entityKey: string): ExposedEntity | undefined {\n return this.exposes.find((e) => e.key === entityKey)\n }\n\n /**\n * Clears the API model for a new entity change.\n * This method resets the dependencies, exposes, userKey,\n * authentication, authorization, and session properties.\n */\n cleanForEntityChange(): void {\n this.dependencies.clear()\n this.dependencyList = []\n this.exposes = []\n this.userKey = undefined\n if (this.session) {\n this.session.properties = []\n }\n if (this.authentication && this.authentication.strategy === 'UsernamePassword') {\n const typed = this.authentication as UsernamePasswordConfiguration\n typed.passwordKey = undefined\n }\n if (this.authorization && this.authorization.strategy == 'RBAC') {\n const typed = this.authorization as RolesBasedAccessControl\n typed.roleKey = ''\n }\n }\n\n /**\n * Attaches a DataDomain to this API model.\n * This method clears any existing dependencies and sets the new domain.\n *\n * @param domain The DataDomain to attach to this API model.\n * @throws Error if the domain does not have a version set in its info.\n */\n attachDataDomain(domain: DataDomain): void {\n if (!domain.info.version) {\n throw new Error(`Cannot attach DataDomain without a version. Please set the version in the domain info.`)\n }\n this.cleanForEntityChange()\n this.dependencies.set(domain.key, domain)\n this.dependencyList = [{ key: domain.key, version: domain.info.version }]\n this.notifyChange()\n }\n}\n"]}
|