@api-client/core 0.18.3 → 0.18.4

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 (25) hide show
  1. package/build/src/modeling/helpers/database.d.ts +24 -0
  2. package/build/src/modeling/helpers/database.d.ts.map +1 -0
  3. package/build/src/modeling/helpers/database.js +42 -0
  4. package/build/src/modeling/helpers/database.js.map +1 -0
  5. package/build/src/modeling/importers/CsvImporter.d.ts +36 -0
  6. package/build/src/modeling/importers/CsvImporter.d.ts.map +1 -0
  7. package/build/src/modeling/importers/CsvImporter.js +81 -0
  8. package/build/src/modeling/importers/CsvImporter.js.map +1 -0
  9. package/build/src/modeling/importers/ImporterException.d.ts +10 -0
  10. package/build/src/modeling/importers/ImporterException.d.ts.map +1 -0
  11. package/build/src/modeling/importers/ImporterException.js +10 -0
  12. package/build/src/modeling/importers/ImporterException.js.map +1 -0
  13. package/build/src/modeling/importers/JsonSchemaImporter.d.ts +99 -0
  14. package/build/src/modeling/importers/JsonSchemaImporter.d.ts.map +1 -0
  15. package/build/src/modeling/importers/JsonSchemaImporter.js +525 -0
  16. package/build/src/modeling/importers/JsonSchemaImporter.js.map +1 -0
  17. package/build/tsconfig.tsbuildinfo +1 -1
  18. package/data/models/example-generator-api.json +13 -13
  19. package/package.json +5 -2
  20. package/src/modeling/helpers/database.ts +48 -0
  21. package/src/modeling/importers/CsvImporter.ts +88 -0
  22. package/src/modeling/importers/ImporterException.ts +10 -0
  23. package/src/modeling/importers/JsonSchemaImporter.ts +642 -0
  24. package/tests/unit/modeling/importers/csv_importer.spec.ts +189 -0
  25. package/tests/unit/modeling/importers/json_schema_importer.spec.ts +451 -0
@@ -0,0 +1,24 @@
1
+ export declare function sanitizeInput(input: string): string;
2
+ /**
3
+ * Converts a string into a sanitized, database column friendly name.
4
+ * - Sanitizes the input using DOMPurify.
5
+ * - Converts to lowercase.
6
+ * - Replaces spaces and multiple underscores with a single underscore.
7
+ * - Removes any characters that are not alphanumeric or underscore.
8
+ *
9
+ * @param inputName The string to format.
10
+ * @returns A database column friendly name.
11
+ */
12
+ export declare function toDatabaseColumnName(inputName: string, defaultName?: string): string;
13
+ /**
14
+ * Converts a string into a sanitized, database table friendly name.
15
+ * - Sanitizes the input using DOMPurify.
16
+ * - Converts to lowercase.
17
+ * - Replaces spaces and multiple underscores with a single underscore.
18
+ * - Removes any characters that are not alphanumeric or underscore.
19
+ *
20
+ * @param inputName The string to format.
21
+ * @returns A database table friendly name.
22
+ */
23
+ export declare function toDatabaseTableName(inputName: string, defaultName?: string): string;
24
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../../../src/modeling/helpers/database.ts"],"names":[],"mappings":"AAGA,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,SAAoB,GAAG,MAAM,CAiB/F;AACD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,SAAmB,GAAG,MAAM,CAE7F"}
@@ -0,0 +1,42 @@
1
+ import DOMPurify from 'isomorphic-dompurify';
2
+ import { snakeCase } from '@pawel-up/jexl/string.js';
3
+ export function sanitizeInput(input) {
4
+ return DOMPurify.isSupported ? DOMPurify.sanitize(input) : input;
5
+ }
6
+ /**
7
+ * Converts a string into a sanitized, database column friendly name.
8
+ * - Sanitizes the input using DOMPurify.
9
+ * - Converts to lowercase.
10
+ * - Replaces spaces and multiple underscores with a single underscore.
11
+ * - Removes any characters that are not alphanumeric or underscore.
12
+ *
13
+ * @param inputName The string to format.
14
+ * @returns A database column friendly name.
15
+ */
16
+ export function toDatabaseColumnName(inputName, defaultName = 'untitled_column') {
17
+ // 1. Sanitize
18
+ let name = sanitizeInput(inputName);
19
+ // 2. Convert to lowercase
20
+ name = snakeCase(name);
21
+ // 3. Replace spaces and multiple hyphens/underscores with a single underscore
22
+ name = name.replace(/[\s-]+/g, '_');
23
+ // 4. Remove any characters that are not alphanumeric or underscore
24
+ name = name.replace(/[^a-z0-9_]/g, '');
25
+ // 5. Ensure it doesn't start or end with an underscore (optional, but good practice)
26
+ name = name.replace(/^_+|_+$/g, '');
27
+ return name || defaultName;
28
+ }
29
+ /**
30
+ * Converts a string into a sanitized, database table friendly name.
31
+ * - Sanitizes the input using DOMPurify.
32
+ * - Converts to lowercase.
33
+ * - Replaces spaces and multiple underscores with a single underscore.
34
+ * - Removes any characters that are not alphanumeric or underscore.
35
+ *
36
+ * @param inputName The string to format.
37
+ * @returns A database table friendly name.
38
+ */
39
+ export function toDatabaseTableName(inputName, defaultName = 'untitled_table') {
40
+ return toDatabaseColumnName(inputName, defaultName);
41
+ }
42
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../../../src/modeling/helpers/database.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEpD,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAA;AAClE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB,EAAE,WAAW,GAAG,iBAAiB;IACrF,cAAc;IACd,IAAI,IAAI,GAAG,aAAa,CAAC,SAAS,CAAC,CAAA;IAEnC,0BAA0B;IAC1B,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAEtB,8EAA8E;IAC9E,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;IAEnC,mEAAmE;IACnE,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAA;IAEtC,qFAAqF;IACrF,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;IAEnC,OAAO,IAAI,IAAI,WAAW,CAAA;AAC5B,CAAC;AACD;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,SAAiB,EAAE,WAAW,GAAG,gBAAgB;IACnF,OAAO,oBAAoB,CAAC,SAAS,EAAE,WAAW,CAAC,CAAA;AACrD,CAAC","sourcesContent":["import DOMPurify from 'isomorphic-dompurify'\nimport { snakeCase } from '@pawel-up/jexl/string.js'\n\nexport function sanitizeInput(input: string): string {\n return DOMPurify.isSupported ? DOMPurify.sanitize(input) : input\n}\n\n/**\n * Converts a string into a sanitized, database column friendly name.\n * - Sanitizes the input using DOMPurify.\n * - Converts to lowercase.\n * - Replaces spaces and multiple underscores with a single underscore.\n * - Removes any characters that are not alphanumeric or underscore.\n *\n * @param inputName The string to format.\n * @returns A database column friendly name.\n */\nexport function toDatabaseColumnName(inputName: string, defaultName = 'untitled_column'): string {\n // 1. Sanitize\n let name = sanitizeInput(inputName)\n\n // 2. Convert to lowercase\n name = snakeCase(name)\n\n // 3. Replace spaces and multiple hyphens/underscores with a single underscore\n name = name.replace(/[\\s-]+/g, '_')\n\n // 4. Remove any characters that are not alphanumeric or underscore\n name = name.replace(/[^a-z0-9_]/g, '')\n\n // 5. Ensure it doesn't start or end with an underscore (optional, but good practice)\n name = name.replace(/^_+|_+$/g, '')\n\n return name || defaultName\n}\n/**\n * Converts a string into a sanitized, database table friendly name.\n * - Sanitizes the input using DOMPurify.\n * - Converts to lowercase.\n * - Replaces spaces and multiple underscores with a single underscore.\n * - Removes any characters that are not alphanumeric or underscore.\n *\n * @param inputName The string to format.\n * @returns A database table friendly name.\n */\nexport function toDatabaseTableName(inputName: string, defaultName = 'untitled_table'): string {\n return toDatabaseColumnName(inputName, defaultName)\n}\n"]}
@@ -0,0 +1,36 @@
1
+ import { type CSVOptions, type ParseResult } from '@pawel-up/csv';
2
+ import type { DataDomain } from '../DataDomain.js';
3
+ export type { CSVOptions, ParseResult };
4
+ /**
5
+ * Imports CSV data into a DataDomain.
6
+ *
7
+ * This class parses CSV files and translates the column definitions into DomainProperty instances
8
+ * within a specified DomainModel and DomainEntity.
9
+ */
10
+ export declare class CsvImporter {
11
+ private parser;
12
+ private domain;
13
+ /**
14
+ * Creates an instance of CsvImporter.
15
+ * @param domain The DataDomain to which the imported data will be added.
16
+ * @param options Optional CSV parsing options.
17
+ */
18
+ constructor(domain: DataDomain, options?: CSVOptions);
19
+ /**
20
+ * Parses a CSV file or string to extract its structure and data.
21
+ * This is a wrapper around the underlying CSV parser.
22
+ * @param csv The CSV content to parse, as a File object or a string.
23
+ * @returns A promise that resolves with the parsed result.
24
+ */
25
+ parse(csv: File | string): Promise<ParseResult>;
26
+ /**
27
+ * Imports the parsed CSV data structure into the domain as a new model and entity.
28
+ * It creates a `DomainEntity` where each column from the CSV is represented as a `DomainProperty`.
29
+ * The first row of data is used to provide an example value for each property.
30
+ * @param data The result from the `parse` method, containing the CSV structure and values.
31
+ * @param modelName The name to be used for the created `DomainModel` and `DomainEntity`.
32
+ * @returns A promise that resolves when the import is complete.
33
+ */
34
+ import(data: ParseResult, modelName: string): Promise<void>;
35
+ }
36
+ //# sourceMappingURL=CsvImporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CsvImporter.d.ts","sourceRoot":"","sources":["../../../../src/modeling/importers/CsvImporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAa,KAAK,WAAW,EAAE,MAAM,eAAe,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAIlD,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,CAAA;AAEvC;;;;;GAKG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAW;IACzB,OAAO,CAAC,MAAM,CAAY;IAE1B;;;;OAIG;gBACS,MAAM,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,UAAU;IAKpD;;;;;OAKG;IACI,KAAK,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAItD;;;;;;;OAOG;IACU,MAAM,CAAC,IAAI,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA0CzE"}
@@ -0,0 +1,81 @@
1
+ import { CSVParser } from '@pawel-up/csv';
2
+ import { sanitizeInput, toDatabaseColumnName, toDatabaseTableName } from '../helpers/database.js';
3
+ /**
4
+ * Imports CSV data into a DataDomain.
5
+ *
6
+ * This class parses CSV files and translates the column definitions into DomainProperty instances
7
+ * within a specified DomainModel and DomainEntity.
8
+ */
9
+ export class CsvImporter {
10
+ parser;
11
+ domain;
12
+ /**
13
+ * Creates an instance of CsvImporter.
14
+ * @param domain The DataDomain to which the imported data will be added.
15
+ * @param options Optional CSV parsing options.
16
+ */
17
+ constructor(domain, options) {
18
+ this.parser = new CSVParser(options);
19
+ this.domain = domain;
20
+ }
21
+ /**
22
+ * Parses a CSV file or string to extract its structure and data.
23
+ * This is a wrapper around the underlying CSV parser.
24
+ * @param csv The CSV content to parse, as a File object or a string.
25
+ * @returns A promise that resolves with the parsed result.
26
+ */
27
+ parse(csv) {
28
+ return this.parser.parse(csv);
29
+ }
30
+ /**
31
+ * Imports the parsed CSV data structure into the domain as a new model and entity.
32
+ * It creates a `DomainEntity` where each column from the CSV is represented as a `DomainProperty`.
33
+ * The first row of data is used to provide an example value for each property.
34
+ * @param data The result from the `parse` method, containing the CSV structure and values.
35
+ * @param modelName The name to be used for the created `DomainModel` and `DomainEntity`.
36
+ * @returns A promise that resolves when the import is complete.
37
+ */
38
+ async import(data, modelName) {
39
+ const name = toDatabaseTableName(modelName, 'imported_cvs_data');
40
+ const model = this.domain.addModel({ info: { name } });
41
+ const entity = model.addEntity({ info: { name } });
42
+ const sanitizedInputName = sanitizeInput(modelName);
43
+ if (name !== sanitizedInputName) {
44
+ model.info.displayName = sanitizedInputName;
45
+ entity.info.displayName = sanitizedInputName;
46
+ }
47
+ for (const row of data.format) {
48
+ const { index, name, type, format } = row;
49
+ const columnName = toDatabaseColumnName(name, `column_${index}`);
50
+ const schema = {
51
+ info: { name: columnName },
52
+ type,
53
+ };
54
+ if (format) {
55
+ schema.bindings = [
56
+ {
57
+ type: 'web',
58
+ schema: {
59
+ format: format === 'integer' ? 'int64' : 'double',
60
+ },
61
+ },
62
+ ];
63
+ }
64
+ const exampleRow = data.values[0];
65
+ if (Array.isArray(exampleRow) && exampleRow[index]) {
66
+ const value = exampleRow[index];
67
+ if (value !== undefined && value !== null) {
68
+ schema.schema = {
69
+ examples: [sanitizeInput(String(value))],
70
+ };
71
+ }
72
+ }
73
+ const prop = entity.addProperty(schema);
74
+ const sn = sanitizeInput(name);
75
+ if (sn !== columnName) {
76
+ prop.info.displayName = sn;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ //# sourceMappingURL=CsvImporter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CsvImporter.js","sourceRoot":"","sources":["../../../../src/modeling/importers/CsvImporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,SAAS,EAAoB,MAAM,eAAe,CAAA;AAE5E,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAKjG;;;;;GAKG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAW;IACjB,MAAM,CAAY;IAE1B;;;;OAIG;IACH,YAAY,MAAkB,EAAE,OAAoB;QAClD,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC,OAAO,CAAC,CAAA;QACpC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,GAAkB;QAC7B,OAAO,IAAI,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CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;YACjC,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;gBACnD,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;gBAC/B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBAC1C,MAAM,CAAC,MAAM,GAAG;wBACd,QAAQ,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;qBACzC,CAAA;gBACH,CAAC;YACH,CAAC;YACD,MAAM,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAA;YACvC,MAAM,EAAE,GAAG,aAAa,CAAC,IAAI,CAAC,CAAA;YAC9B,IAAI,EAAE,KAAK,UAAU,EAAE,CAAC;gBACtB,IAAI,CAAC,IAAI,CAAC,WAAW,GAAG,EAAE,CAAA;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;CACF","sourcesContent":["import { type CSVOptions, CSVParser, type ParseResult } from '@pawel-up/csv'\nimport type { DataDomain } from '../DataDomain.js'\nimport { sanitizeInput, toDatabaseColumnName, toDatabaseTableName } from '../helpers/database.js'\nimport type { DomainPropertySchema } from '../DomainProperty.js'\n\nexport type { CSVOptions, ParseResult }\n\n/**\n * Imports CSV data into a DataDomain.\n *\n * This class parses CSV files and translates the column definitions into DomainProperty instances\n * within a specified DomainModel and DomainEntity.\n */\nexport class CsvImporter {\n private parser: CSVParser\n private domain: DataDomain\n\n /**\n * Creates an instance of CsvImporter.\n * @param domain The DataDomain to which the imported data will be added.\n * @param options Optional CSV parsing options.\n */\n constructor(domain: DataDomain, options?: CSVOptions) {\n this.parser = new CSVParser(options)\n this.domain = domain\n }\n\n /**\n * Parses a CSV file or string to extract its structure and data.\n * This is a wrapper around the underlying CSV parser.\n * @param csv The CSV content to parse, as a File object or a string.\n * @returns A promise that resolves with the parsed result.\n */\n public parse(csv: File | string): Promise<ParseResult> {\n return this.parser.parse(csv)\n }\n\n /**\n * Imports the parsed CSV data structure into the domain as a new model and entity.\n * It creates a `DomainEntity` where each column from the CSV is represented as a `DomainProperty`.\n * The first row of data is used to provide an example value for each property.\n * @param data The result from the `parse` method, containing the CSV structure and values.\n * @param modelName The name to be used for the created `DomainModel` and `DomainEntity`.\n * @returns A promise that resolves when the import is complete.\n */\n public async import(data: ParseResult, modelName: string): Promise<void> {\n const name = toDatabaseTableName(modelName, 'imported_cvs_data')\n const model = this.domain.addModel({ info: { name } })\n const entity = model.addEntity({ info: { name } })\n const sanitizedInputName = sanitizeInput(modelName)\n if (name !== sanitizedInputName) {\n model.info.displayName = sanitizedInputName\n entity.info.displayName = sanitizedInputName\n }\n for (const row of data.format) {\n const { index, name, type, format } = row\n const columnName = toDatabaseColumnName(name, `column_${index}`)\n const schema: Partial<DomainPropertySchema> = {\n info: { name: columnName },\n type,\n }\n if (format) {\n schema.bindings = [\n {\n type: 'web',\n schema: {\n format: format === 'integer' ? 'int64' : 'double',\n },\n },\n ]\n }\n const exampleRow = data.values[0]\n if (Array.isArray(exampleRow) && exampleRow[index]) {\n const value = exampleRow[index]\n if (value !== undefined && value !== null) {\n schema.schema = {\n examples: [sanitizeInput(String(value))],\n }\n }\n }\n const prop = entity.addProperty(schema)\n const sn = sanitizeInput(name)\n if (sn !== columnName) {\n prop.info.displayName = sn\n }\n }\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { Exception } from '../../exceptions/exception.js';
2
+ /**
3
+ * An exception thrown during the JSON Schema import process when an
4
+ * unrecoverable error occurs.
5
+ */
6
+ export declare class ImporterException extends Exception {
7
+ static code: string;
8
+ static status: number;
9
+ }
10
+ //# sourceMappingURL=ImporterException.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImporterException.d.ts","sourceRoot":"","sources":["../../../../src/modeling/importers/ImporterException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAEzD;;;GAGG;AACH,qBAAa,iBAAkB,SAAQ,SAAS;IAC9C,OAAgB,IAAI,SAAuB;IAC3C,OAAgB,MAAM,SAAM;CAC7B"}
@@ -0,0 +1,10 @@
1
+ import { Exception } from '../../exceptions/exception.js';
2
+ /**
3
+ * An exception thrown during the JSON Schema import process when an
4
+ * unrecoverable error occurs.
5
+ */
6
+ export class ImporterException extends Exception {
7
+ static code = 'E_IMPORTER_FAILURE';
8
+ static status = 400; // Bad Request, as it's likely due to invalid input schemas
9
+ }
10
+ //# sourceMappingURL=ImporterException.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImporterException.js","sourceRoot":"","sources":["../../../../src/modeling/importers/ImporterException.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAEzD;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,SAAS;IAC9C,MAAM,CAAU,IAAI,GAAG,oBAAoB,CAAA;IAC3C,MAAM,CAAU,MAAM,GAAG,GAAG,CAAA,CAAC,2DAA2D","sourcesContent":["import { Exception } from '../../exceptions/exception.js'\n\n/**\n * An exception thrown during the JSON Schema import process when an\n * unrecoverable error occurs.\n */\nexport class ImporterException extends Exception {\n static override code = 'E_IMPORTER_FAILURE'\n static override status = 400 // Bad Request, as it's likely due to invalid input schemas\n}\n"]}
@@ -0,0 +1,99 @@
1
+ import type { JSONSchema7 } from 'json-schema';
2
+ import { DataDomain } from '../DataDomain.js';
3
+ import { DomainModel } from '../DomainModel.js';
4
+ /**
5
+ * Represents a single message (info, warning, or error) generated during the import process.
6
+ */
7
+ export interface ImportMessage {
8
+ level: 'warning' | 'info';
9
+ message: string;
10
+ location?: string;
11
+ }
12
+ /**
13
+ * A report containing the result of the import process, including the created model
14
+ * and any non-blocking messages.
15
+ */
16
+ export interface JsonImportReport {
17
+ /**
18
+ * An array of messages generated during the import process.
19
+ * These can include warnings, info messages, or other non-blocking notifications.
20
+ */
21
+ messages: ImportMessage[];
22
+ /**
23
+ * The model that was created during the import.
24
+ */
25
+ model: DomainModel;
26
+ }
27
+ /**
28
+ * A structure to hold in-memory JSON schema files for browser-based import.
29
+ */
30
+ export interface InMemorySchema {
31
+ /** A virtual path or identifier for the schema, used in `$ref` values. */
32
+ path: string;
33
+ /** The parsed content of the JSON schema file. */
34
+ contents: JSONSchema7;
35
+ }
36
+ /**
37
+ * Imports JSON Schema definitions into a DataDomain.
38
+ *
39
+ * This class parses a root JSON Schema file, bundles all its dependencies,
40
+ * and translates the object definitions into DomainEntity instances within a specified DomainModel.
41
+ */
42
+ export declare class JsonSchemaImporter {
43
+ private domain;
44
+ private model;
45
+ private refMap;
46
+ private messages;
47
+ private enums;
48
+ constructor(domain: DataDomain);
49
+ /**
50
+ * Resets the internal state for a new import operation.
51
+ */
52
+ private resetState;
53
+ /**
54
+ * Centralized reporting for warnings and info messages.
55
+ */
56
+ private report;
57
+ /**
58
+ * Main import method: orchestrates schema bundling, entity creation, and population.
59
+ */
60
+ import(schemas: InMemorySchema[], modelName: string): Promise<JsonImportReport>;
61
+ private isEnum;
62
+ /**
63
+ * Resolves a schema reference from the flat definition/id maps.
64
+ * Supports #/definitions/..., $id, or direct path keys.
65
+ */
66
+ private resolveSchemaRef;
67
+ /**
68
+ * Helper for entity creation, can be extended for custom logic.
69
+ */
70
+ private createEntity;
71
+ /**
72
+ * Populates a DomainEntity with its properties, associations, and parent relationships.
73
+ */
74
+ private populateEntity;
75
+ /**
76
+ * Processes the `allOf` keyword, which can contain references (for inheritance)
77
+ * or inline schemas (for composition/mixins).
78
+ */
79
+ private processAllOf;
80
+ /**
81
+ * Recursively analyzes a schema definition to find all contained primitive types and `$ref`s.
82
+ * It's used to understand the nature of a property (is it a primitive, an association, or a mix).
83
+ */
84
+ private collectTypesAndRefs;
85
+ /**
86
+ * Determines whether to create a DomainProperty or a DomainAssociation for a given schema property.
87
+ */
88
+ private createPropertyOrAssociation;
89
+ /**
90
+ * Creates and configures a DomainProperty based on a JSON schema property definition.
91
+ */
92
+ private createDomainProperty;
93
+ /**
94
+ * Maps a JSON Schema type to a DomainPropertyType.
95
+ */
96
+ private mapJsonTypeToDomainType;
97
+ private createEnumProperty;
98
+ }
99
+ //# sourceMappingURL=JsonSchemaImporter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonSchemaImporter.d.ts","sourceRoot":"","sources":["../../../../src/modeling/importers/JsonSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAA8C,MAAM,aAAa,CAAA;AAC1F,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAQ/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,GAAG,MAAM,CAAA;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,QAAQ,EAAE,aAAa,EAAE,CAAA;IACzB;;OAEG;IACH,KAAK,EAAE,WAAW,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,IAAI,EAAE,MAAM,CAAA;IACZ,kDAAkD;IAClD,QAAQ,EAAE,WAAW,CAAA;CACtB;AAED;;;;;GAKG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAY;IAC1B,OAAO,CAAC,KAAK,CAAc;IAC3B,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,KAAK,CAAiC;gBAElC,MAAM,EAAE,UAAU;IAI9B;;OAEG;IACH,OAAO,CAAC,UAAU;IAOlB;;OAEG;IACH,OAAO,CAAC,MAAM;IAId;;OAEG;IACU,MAAM,CAAC,OAAO,EA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