@api-client/core 0.18.4 → 0.18.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import DOMPurify from 'dompurify';
2
+ declare let instance: typeof DOMPurify;
3
+ export default instance;
4
+ //# sourceMappingURL=dom_purify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom_purify.d.ts","sourceRoot":"","sources":["../../../src/lib/dom_purify.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,QAAA,IAAI,QAAQ,EAAE,OAAO,SAAS,CAAA;AAsB9B,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,23 @@
1
+ import DOMPurify from 'dompurify';
2
+ let instance;
3
+ function isNodeJsEnvironment() {
4
+ return (
5
+ // eslint-disable-next-line no-restricted-globals
6
+ typeof process !== 'undefined' &&
7
+ // eslint-disable-next-line no-restricted-globals
8
+ typeof process.versions !== 'undefined' &&
9
+ // eslint-disable-next-line no-restricted-globals
10
+ typeof process.versions.node !== 'undefined');
11
+ }
12
+ if (isNodeJsEnvironment()) {
13
+ const { JSDOM } = await import('jsdom');
14
+ const { window } = new JSDOM('<!DOCTYPE html>');
15
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16
+ // @ts-ignore
17
+ instance = DOMPurify(window);
18
+ }
19
+ else {
20
+ instance = DOMPurify;
21
+ }
22
+ export default instance;
23
+ //# sourceMappingURL=dom_purify.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dom_purify.js","sourceRoot":"","sources":["../../../src/lib/dom_purify.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,WAAW,CAAA;AAEjC,IAAI,QAA0B,CAAA;AAE9B,SAAS,mBAAmB;IAC1B,OAAO;IACL,iDAAiD;IACjD,OAAO,OAAO,KAAK,WAAW;QAC9B,iDAAiD;QACjD,OAAO,OAAO,CAAC,QAAQ,KAAK,WAAW;QACvC,iDAAiD;QACjD,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,KAAK,WAAW,CAC7C,CAAA;AACH,CAAC;AACD,IAAI,mBAAmB,EAAE,EAAE,CAAC;IAC1B,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,CAAA;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;IAC/C,6DAA6D;IAC7D,aAAa;IACb,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC;KAAM,CAAC;IACN,QAAQ,GAAG,SAAS,CAAA;AACtB,CAAC;AAED,eAAe,QAAQ,CAAA","sourcesContent":["import DOMPurify from 'dompurify'\n\nlet instance: typeof DOMPurify\n\nfunction isNodeJsEnvironment(): boolean {\n return (\n // eslint-disable-next-line no-restricted-globals\n typeof process !== 'undefined' &&\n // eslint-disable-next-line no-restricted-globals\n typeof process.versions !== 'undefined' &&\n // eslint-disable-next-line no-restricted-globals\n typeof process.versions.node !== 'undefined'\n )\n}\nif (isNodeJsEnvironment()) {\n const { JSDOM } = await import('jsdom')\n const { window } = new JSDOM('<!DOCTYPE html>')\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n instance = DOMPurify(window)\n} else {\n instance = DOMPurify\n}\n\nexport default instance\n"]}
@@ -1,7 +1,7 @@
1
- import DOMPurify from 'isomorphic-dompurify';
2
1
  import { snakeCase } from '@pawel-up/jexl/string.js';
2
+ import DOMPurify from '../../lib/dom_purify.js';
3
3
  export function sanitizeInput(input) {
4
- return DOMPurify.isSupported ? DOMPurify.sanitize(input) : input;
4
+ return DOMPurify.sanitize(input);
5
5
  }
6
6
  /**
7
7
  * Converts a string into a sanitized, database column friendly name.
@@ -1 +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"]}
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../../../src/modeling/helpers/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,SAAS,MAAM,yBAAyB,CAAA;AAE/C,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,OAAO,SAAS,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAClC,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 { snakeCase } from '@pawel-up/jexl/string.js'\nimport DOMPurify from '../../lib/dom_purify.js'\n\nexport function sanitizeInput(input: string): string {\n return DOMPurify.sanitize(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"]}
@@ -1,5 +1,7 @@
1
1
  import { type CSVOptions, type ParseResult } from '@pawel-up/csv';
2
2
  import type { DataDomain } from '../DataDomain.js';
3
+ import type { DomainEntity } from '../DomainEntity.js';
4
+ import type { DomainModel } from '../DomainModel.js';
3
5
  export type { CSVOptions, ParseResult };
4
6
  /**
5
7
  * Imports CSV data into a DataDomain.
@@ -31,6 +33,9 @@ export declare class CsvImporter {
31
33
  * @param modelName The name to be used for the created `DomainModel` and `DomainEntity`.
32
34
  * @returns A promise that resolves when the import is complete.
33
35
  */
34
- import(data: ParseResult, modelName: string): Promise<void>;
36
+ import(data: ParseResult, modelName: string): Promise<{
37
+ entity: DomainEntity;
38
+ model: DomainModel;
39
+ }>;
35
40
  }
36
41
  //# sourceMappingURL=CsvImporter.d.ts.map
@@ -1 +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"}
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;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAEpD,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;QAAE,MAAM,EAAE,YAAY,CAAC;QAAC,KAAK,EAAE,WAAW,CAAA;KAAE,CAAC;CA2CjH"}
@@ -76,6 +76,7 @@ export class CsvImporter {
76
76
  prop.info.displayName = sn;
77
77
  }
78
78
  }
79
+ return { entity, model };
79
80
  }
80
81
  }
81
82
  //# sourceMappingURL=CsvImporter.js.map
@@ -1 +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,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AAO,CAAC,CAAC,CAAC,QAAQ;yBAClD;qBACF;iBACF,CAAA;YACH,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,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"]}
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;AAOjG;;;;;GAKG;A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BAC1B,IAAI;aACL,CAAA;YACD,IAAI,MAAM,EAAE,CAAC;gBACX,MAAM,CAAC,QAAQ,GAAG;oBAChB;wBACE,IAAI,EAAE,KAAK;wBACX,MAAM,EAAE;4BACN,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ;yBAClD;qBACF;iBACF,CAAA;YACH,CAAC;YACD,MAAM,UAAU,GAAG,IAAI,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;QACD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,CAAA;IAC1B,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'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport type { DomainModel } from '../DomainModel.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<{ entity: DomainEntity; model: DomainModel }> {\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 return { entity, model }\n }\n}\n"]}