@api-client/core 0.18.7 → 0.18.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.
@@ -68,6 +68,10 @@ export declare class JsonSchemaImporter {
68
68
  * Helper for entity creation, can be extended for custom logic.
69
69
  */
70
70
  private createEntity;
71
+ /**
72
+ * Generates a meaningful name for inline entities based on their parent context.
73
+ */
74
+ private generateInlineEntityName;
71
75
  /**
72
76
  * Populates a DomainEntity with its properties, associations, and parent relationships.
73
77
  */
@@ -1 +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,E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,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,EAAE,cAAc,EAAE,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IA4F5F,OAAO,CAAC,MAAM;IAYd;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAuBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IA6BpB;;OAEG;IACH,OAAO,CAAC,wBAAwB;IAehC;;OAEG;IACH,OAAO,CAAC,cAAc;IAgBtB;;;OAGG;IACH,OAAO,CAAC,YAAY;IAgDpB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAsF3B;;OAEG;IACH,OAAO,CAAC,2BAA2B;IAyEnC;;OAEG;IACH,OAAO,CAAC,oBAAoB;IA0D5B;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAuE/B,OAAO,CAAC,kBAAkB;CAgG3B"}
@@ -1,5 +1,6 @@
1
1
  import { DomainProperty } from '../DomainProperty.js';
2
2
  import { sanitizeInput, toDatabaseColumnName, toDatabaseTableName } from '../helpers/database.js';
3
+ import { nanoid } from '../../nanoid.js';
3
4
  /**
4
5
  * Imports JSON Schema definitions into a DataDomain.
5
6
  *
@@ -38,31 +39,47 @@ export class JsonSchemaImporter {
38
39
  // Build a flat map of all definitions and $id-indexed schemas
39
40
  const definitionMap = new Map();
40
41
  const idMap = new Map();
42
+ const processedSchemas = new Set(); // Track processed schema objects to avoid duplicates
41
43
  for (const schema of schemas) {
42
44
  // Add $id mapping if present
43
45
  if (schema.contents.$id) {
44
46
  idMap.set(schema.contents.$id, schema.contents);
47
+ // Add the entire schema to the definitions maps as well as they can be referenced by other schemas.
48
+ definitionMap.set(schema.contents.$id, schema.contents);
45
49
  }
46
50
  // Add the schema itself by its path
47
51
  definitionMap.set(schema.path, schema.contents);
48
52
  // Add all definitions inside this schema
49
- const defs = (schema.contents.definitions ||
50
- schema.contents.$defs);
51
- if (defs) {
52
- for (const [defName, defSchema] of Object.entries(defs)) {
53
+ const definitions = schema.contents.definitions;
54
+ const defs = schema.contents.$defs;
55
+ if (definitions) {
56
+ for (const [defName, defSchema] of Object.entries(definitions)) {
53
57
  if (typeof defSchema === 'object') {
54
- // Use a JSON pointer for the key
58
+ // Use a JSON pointer for the key - include both full path and short form
55
59
  definitionMap.set(`${schema.path}#/definitions/${defName}`, defSchema);
56
- // Also allow lookup by just #/definitions/defName for single-file schemas
57
60
  definitionMap.set(`#/definitions/${defName}`, defSchema);
58
61
  }
59
62
  }
60
63
  }
64
+ if (defs) {
65
+ for (const [defName, defSchema] of Object.entries(defs)) {
66
+ if (typeof defSchema === 'object') {
67
+ // Use a JSON pointer for the key - include both full path and short form
68
+ definitionMap.set(`${schema.path}#/$defs/${defName}`, defSchema);
69
+ definitionMap.set(`#/$defs/${defName}`, defSchema);
70
+ }
71
+ }
72
+ }
61
73
  }
62
74
  // == Pass 1: Create all entities ==
63
75
  for (const [key, schema] of definitionMap.entries()) {
76
+ // Skip if this schema object has already been processed
77
+ if (processedSchemas.has(schema)) {
78
+ continue;
79
+ }
64
80
  if (typeof schema === 'object' && schema.type === 'object') {
65
81
  this.createEntity(key, schema, key);
82
+ processedSchemas.add(schema);
66
83
  }
67
84
  else if (this.isEnum(schema)) {
68
85
  this.enums.set(key, schema);
@@ -73,10 +90,15 @@ export class JsonSchemaImporter {
73
90
  }
74
91
  // Also create entities for all $id-indexed schemas if not already present
75
92
  for (const [id, schema] of idMap.entries()) {
93
+ // Skip if this schema object has already been processed
94
+ if (processedSchemas.has(schema)) {
95
+ continue;
96
+ }
76
97
  if (!this.refMap.has(id) && typeof schema === 'object' && schema.type === 'object') {
77
98
  this.createEntity(id, schema, id);
99
+ processedSchemas.add(schema);
78
100
  }
79
- else if (this.isEnum(schema)) {
101
+ else if (this.isEnum(schema) && !this.enums.has(id)) {
80
102
  this.enums.set(id, schema);
81
103
  }
82
104
  else {
@@ -120,10 +142,10 @@ export class JsonSchemaImporter {
120
142
  return definitionMap.get(refPath);
121
143
  if (idMap.has(refPath))
122
144
  return idMap.get(refPath);
123
- // Try to resolve #/definitions/Name from any schema
124
- if (refPath.startsWith('#/definitions/')) {
145
+ // Try to resolve #/definitions/Name or #/$defs/Name from any schema
146
+ if (refPath.startsWith('#/definitions/') || refPath.startsWith('#/$defs/')) {
125
147
  for (const [key, schema] of definitionMap.entries()) {
126
- if (key.endsWith(refPath))
148
+ if (key === refPath)
127
149
  return schema;
128
150
  }
129
151
  }
@@ -140,7 +162,16 @@ export class JsonSchemaImporter {
140
162
  * Helper for entity creation, can be extended for custom logic.
141
163
  */
142
164
  createEntity(name, schema, refPath) {
143
- const fixedName = schema.title || name;
165
+ let fixedName = schema.title || name;
166
+ // Extract just the definition name from JSON pointers (both short and full paths)
167
+ if (name.includes('#/definitions/')) {
168
+ const parts = name.split('#/definitions/');
169
+ fixedName = schema.title || parts[parts.length - 1];
170
+ }
171
+ else if (name.includes('#/$defs/')) {
172
+ const parts = name.split('#/$defs/');
173
+ fixedName = schema.title || parts[parts.length - 1];
174
+ }
144
175
  const cleanName = toDatabaseTableName(fixedName, 'untitled_entity');
145
176
  const entity = this.model.addEntity({
146
177
  info: {
@@ -157,6 +188,21 @@ export class JsonSchemaImporter {
157
188
  this.refMap.set(refPath, entity.key);
158
189
  return entity;
159
190
  }
191
+ /**
192
+ * Generates a meaningful name for inline entities based on their parent context.
193
+ */
194
+ generateInlineEntityName(parentEntityKey, propName, schema) {
195
+ // Try to use the schema title first
196
+ if (schema.title) {
197
+ return toDatabaseTableName(schema.title, 'untitled_entity');
198
+ }
199
+ // Find the parent entity to create a meaningful name
200
+ const parentEntity = this.domain.findEntity(parentEntityKey);
201
+ const parentName = parentEntity?.info.name || 'unknown';
202
+ // Create a name like "User_Address" or "Order_ShippingInfo"
203
+ const combinedName = `${parentName}_${propName}`;
204
+ return toDatabaseTableName(combinedName, 'untitled_entity');
205
+ }
160
206
  /**
161
207
  * Populates a DomainEntity with its properties, associations, and parent relationships.
162
208
  */
@@ -223,7 +269,7 @@ export class JsonSchemaImporter {
223
269
  * Recursively analyzes a schema definition to find all contained primitive types and `$ref`s.
224
270
  * It's used to understand the nature of a property (is it a primitive, an association, or a mix).
225
271
  */
226
- collectTypesAndRefs(schema) {
272
+ collectTypesAndRefs(schema, parentEntityKey, propName) {
227
273
  const collected = { refs: new Set(), types: new Set(), isArray: false };
228
274
  if (typeof schema !== 'object') {
229
275
  return collected;
@@ -239,11 +285,22 @@ export class JsonSchemaImporter {
239
285
  collected.types.add(t);
240
286
  }
241
287
  }
288
+ // Handle inline object types by creating entities immediately
289
+ if (schema.type === 'object' && schema.properties && parentEntityKey && propName) {
290
+ // Create an entity for this inline object immediately
291
+ const inlineEntityName = this.generateInlineEntityName(parentEntityKey, propName, schema);
292
+ const inlineEntity = this.createEntity(inlineEntityName, schema, inlineEntityName);
293
+ // Populate it immediately since we have the schema
294
+ this.populateEntity(inlineEntity, schema);
295
+ // Add a reference to it so it gets treated as an association
296
+ collected.refs.add(inlineEntityName);
297
+ return collected;
298
+ }
242
299
  if (schema.type === 'array') {
243
300
  collected.isArray = true;
244
301
  if (typeof schema.items === 'object') {
245
- // Recurse into items
246
- const itemInfo = this.collectTypesAndRefs(Array.isArray(schema.items) ? schema.items[0] : schema.items);
302
+ // Recurse into items - pass along parent context for inline objects in arrays
303
+ const itemInfo = this.collectTypesAndRefs(Array.isArray(schema.items) ? schema.items[0] : schema.items, parentEntityKey, propName ? `${propName}_item` : undefined);
247
304
  itemInfo.refs.forEach((r) => collected.refs.add(r));
248
305
  itemInfo.types.forEach((t) => collected.types.add(t));
249
306
  }
@@ -252,7 +309,7 @@ export class JsonSchemaImporter {
252
309
  const choices = schema.anyOf || schema.oneOf;
253
310
  if (choices) {
254
311
  for (const choice of choices) {
255
- const choiceInfo = this.collectTypesAndRefs(choice);
312
+ const choiceInfo = this.collectTypesAndRefs(choice, parentEntityKey);
256
313
  choiceInfo.refs.forEach((r) => collected.refs.add(r));
257
314
  choiceInfo.types.forEach((t) => collected.types.add(t));
258
315
  if (choiceInfo.isArray) {
@@ -260,6 +317,19 @@ export class JsonSchemaImporter {
260
317
  }
261
318
  }
262
319
  }
320
+ if (schema.enum) {
321
+ // If the schema has an enum, we treat it as a string type with specific values.
322
+ collected.types.add('string');
323
+ // consider the following schema: `"enum": ["one", "two", "three"]`
324
+ const id = nanoid(8);
325
+ this.enums.set(id, {
326
+ type: 'string',
327
+ oneOf: schema.enum.map((value) => ({
328
+ const: String(value), // Ensure enum values are strings
329
+ })),
330
+ });
331
+ collected.refs.add(id); // Add the enum reference
332
+ }
263
333
  return collected;
264
334
  }
265
335
  /**
@@ -267,7 +337,9 @@ export class JsonSchemaImporter {
267
337
  */
268
338
  createPropertyOrAssociation(entity, propName, propSchema, isRequired) {
269
339
  // Analyze the property schema to understand its composition (primitives, refs, arrays).
270
- const analysis = this.collectTypesAndRefs(propSchema);
340
+ // Pass entity context to collectTypesAndRefs for inline object handling
341
+ const analysis = this.collectTypesAndRefs(propSchema, entity.key, propName);
342
+ // console.log(`Analyzing property '${propName}' in entity '${entity.info.name}':`, analysis, propSchema)
271
343
  // Case 1: If the property has `$ref` to an enum, we treat it as a DomainProperty.
272
344
  if (analysis.refs.size === 1 && this.enums.has([...analysis.refs][0])) {
273
345
  const prop = this.createEnumProperty(propName, propSchema, this.enums.get([...analysis.refs][0]), entity.info.name);
@@ -517,6 +589,7 @@ export class JsonSchemaImporter {
517
589
  }
518
590
  }
519
591
  if (Object.keys(schema).length > 0) {
592
+ // console.log(`Creating enum property '${propName}' with schema:`, schema)
520
593
  prop.schema = schema;
521
594
  }
522
595
  return prop;
@@ -1 +1 @@
1
- {"version":3,"file":"JsonSchemaImporter.js","sourceRoot":"","sources":["../../../../src/modeling/importers/JsonSchemaImporter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAA6B,MAAM,sBAAsB,CAAA;AAIhF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAqCjG;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAY;IAClB,KAAK,CAAc;IACnB,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IAClC,QAAQ,GAAoB,EAAE,CAAA;IAC9B,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAA;IAE9C,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,SAAiB;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,CAAC,CAAA;QAChE,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;QACnB,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QAClB,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;IACpB,CAAC;IAED;;OAEG;IACK,MAAM,CAAC,KAAyB,EAAE,OAAe,EAAE,QAAiB;QAC1E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAA;IAClD,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,MAAM,CAAC,OAAyB,EAAE,SAAiB;QAC9D,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAE1B,8DAA8D;QAC9D,MAAM,aAAa,GAAG,IAAI,GAAG,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,CAAA;YAChB,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;oBACnD,IAAI,CAAC,MAAM,CACT,SAAS,EACT,+BAA+B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6CAA6C,EAChG,GAAG,eAAe,IAAI,QAAQ,EAAE,CACjC,CAAA;oBACD,SAAQ;gBACV,CAAC;gBACD,IAAI,OAAQ,IAAoB,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACpD,IAAI,CAAC,MAAM,CACT,SAAS,EACT,6BAA6B,IAAI,CAAC,SAAS,CAAE,IAAoB,CAAC,KAAK,CAAC,sBAAsB,EAC9F,GAAG,eAAe,IAAI,QAAQ,EAAE,CACjC,CAAA;oBACD,SAAQ;gBACV,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE,IAAoB,CAAC,KAAe,CAAC,CAAA;YACzD,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import type { JSONSchema7, JSONSchema7Definition, JSONSchema7TypeName } from 'json-schema'\nimport { DataDomain } from '../DataDomain.js'\nimport { DomainModel } from '../DomainModel.js'\nimport { DomainEntity } from '../DomainEntity.js'\nimport { DomainProperty, type DomainPropertySchema } from '../DomainProperty.js'\nimport type { PropertySchema } from '../types.js'\nimport type { PropertyWebBindings } from '../Bindings.js'\nimport type { DomainPropertyFormat, DomainPropertyType } from '../DataFormat.js'\nimport { sanitizeInput, toDatabaseColumnName, toDatabaseTableName } from '../helpers/database.js'\n\n/**\n * Represents a single message (info, warning, or error) generated during the import process.\n */\nexport interface ImportMessage {\n level: 'warning' | 'info'\n message: string\n location?: string\n}\n\n/**\n * A report containing the result of the import process, including the created model\n * and any non-blocking messages.\n */\nexport interface JsonImportReport {\n /**\n * An array of messages generated during the import process.\n * These can include warnings, info messages, or other non-blocking notifications.\n */\n messages: ImportMessage[]\n /**\n * The model that was created during the import.\n */\n model: DomainModel\n}\n\n/**\n * A structure to hold in-memory JSON schema files for browser-based import.\n */\nexport interface InMemorySchema {\n /** A virtual path or identifier for the schema, used in `$ref` values. */\n path: string\n /** The parsed content of the JSON schema file. */\n contents: JSONSchema7\n}\n\n/**\n * Imports JSON Schema definitions into a DataDomain.\n *\n * This class parses a root JSON Schema file, bundles all its dependencies,\n * and translates the object definitions into DomainEntity instances within a specified DomainModel.\n */\nexport class JsonSchemaImporter {\n private domain: DataDomain\n private model!: DomainModel\n private refMap = new Map<string, string>()\n private messages: ImportMessage[] = []\n private enums = new Map<string, JSONSchema7>()\n\n constructor(domain: DataDomain) {\n this.domain = domain\n }\n\n /**\n * Resets the internal state for a new import operation.\n */\n private resetState(modelName: string) {\n this.model = this.domain.addModel({ info: { name: modelName } })\n this.refMap.clear()\n this.enums.clear()\n this.messages = []\n }\n\n /**\n * Centralized reporting for warnings and info messages.\n */\n private report(level: 'warning' | 'info', message: string, location?: string): void {\n this.messages.push({ level, message, location })\n }\n\n /**\n * Main import method: orchestrates schema bundling, entity creation, and population.\n */\n public async import(schemas: InMemorySchema[], modelName: string): Promise<JsonImportReport> {\n this.resetState(modelName)\n\n // Build a flat map of all definitions and $id-indexed schemas\n const definitionMap = new Map<string, JSONSchema7>()\n const idMap = new Map<string, JSONSchema7>()\n for (const schema of schemas) {\n // Add $id mapping if present\n if (schema.contents.$id) {\n idMap.set(schema.contents.$id, schema.contents)\n }\n // Add the schema itself by its path\n definitionMap.set(schema.path, schema.contents)\n // Add all definitions inside this schema\n const defs = (schema.contents.definitions ||\n (schema.contents as unknown as { $defs: Record<string, JSONSchema7Definition> }).$defs) as\n | Record<string, JSONSchema7Definition>\n | undefined\n if (defs) {\n for (const [defName, defSchema] of Object.entries(defs)) {\n if (typeof defSchema === 'object') {\n // Use a JSON pointer for the key\n definitionMap.set(`${schema.path}#/definitions/${defName}`, defSchema as JSONSchema7)\n // Also allow lookup by just #/definitions/defName for single-file schemas\n definitionMap.set(`#/definitions/${defName}`, defSchema as JSONSchema7)\n }\n }\n }\n }\n\n // == Pass 1: Create all entities ==\n for (const [key, schema] of definitionMap.entries()) {\n if (typeof schema === 'object' && schema.type === 'object') {\n this.createEntity(key, schema, key)\n } else if (this.isEnum(schema)) {\n this.enums.set(key, schema)\n } else {\n this.report('warning', `Skipping non-object schema at ${key}`, key)\n }\n }\n // Also create entities for all $id-indexed schemas if not already present\n for (const [id, schema] of idMap.entries()) {\n if (!this.refMap.has(id) && typeof schema === 'object' && schema.type === 'object') {\n this.createEntity(id, schema, id)\n } else if (this.isEnum(schema)) {\n this.enums.set(id, schema)\n } else {\n this.report('warning', `Skipping non-object schema at ${id}`, id)\n }\n }\n\n // == Pass 2: Populate entities ==\n for (const [refPath, entityKey] of this.refMap.entries()) {\n const entity = this.domain.findEntity(entityKey)\n if (!entity) {\n this.report('warning', `Entity not found: ${entityKey}`, refPath)\n continue\n }\n const schema = this.resolveSchemaRef(refPath, definitionMap, idMap)\n if (!schema) {\n this.report('warning', `Schema not found for ref: ${refPath}`, refPath)\n continue\n }\n this.populateEntity(entity, schema)\n }\n\n return { model: this.model, messages: this.messages }\n }\n\n private isEnum(schema: JSONSchema7): boolean {\n if (schema.type !== 'string') {\n // I might be wrong about it, but I think enums are only for strings\n return false\n }\n if (!Array.isArray(schema.oneOf)) {\n return false\n }\n const notConst = schema.oneOf.find((s) => typeof s !== 'object' || !('const' in s))\n return !notConst // If all schemas in oneOf have 'const', it's an enum\n }\n\n /**\n * Resolves a schema reference from the flat definition/id maps.\n * Supports #/definitions/..., $id, or direct path keys.\n */\n private resolveSchemaRef(\n refPath: string,\n definitionMap: Map<string, JSONSchema7>,\n idMap: Map<string, JSONSchema7>\n ): JSONSchema7 | undefined {\n // Try direct match\n if (definitionMap.has(refPath)) return definitionMap.get(refPath)\n if (idMap.has(refPath)) return idMap.get(refPath)\n // Try to resolve #/definitions/Name from any schema\n if (refPath.startsWith('#/definitions/')) {\n for (const [key, schema] of definitionMap.entries()) {\n if (key.endsWith(refPath)) return schema\n }\n }\n // Try to resolve by $id fragment\n if (refPath.startsWith('#')) {\n for (const [id, schema] of idMap.entries()) {\n if (id.endsWith(refPath)) return schema\n }\n }\n return undefined\n }\n\n /**\n * Helper for entity creation, can be extended for custom logic.\n */\n private createEntity(name: string, schema: JSONSchema7, refPath: string): DomainEntity {\n const fixedName = schema.title || name\n const cleanName = toDatabaseTableName(fixedName, 'untitled_entity')\n const entity = this.model.addEntity({\n info: {\n name: cleanName,\n displayName: fixedName,\n },\n })\n if (fixedName !== cleanName) {\n entity.info.displayName = fixedName // Keep original title for display\n }\n if (schema.description) {\n entity.info.description = schema.description\n }\n this.refMap.set(refPath, entity.key)\n return entity\n }\n\n /**\n * Populates a DomainEntity with its properties, associations, and parent relationships.\n */\n private populateEntity(entity: DomainEntity, schema: JSONSchema7): void {\n const properties = schema.properties || {}\n const required = new Set(schema.required || [])\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n if (typeof propSchema === 'object') {\n this.createPropertyOrAssociation(entity, propName, propSchema, required.has(propName))\n }\n }\n\n // Handle 'allOf' for inheritance and composition.\n if (schema.allOf) {\n this.processAllOf(entity, schema.allOf)\n }\n }\n\n /**\n * Processes the `allOf` keyword, which can contain references (for inheritance)\n * or inline schemas (for composition/mixins).\n */\n private processAllOf(entity: DomainEntity, allOfSchemas: JSONSchema7Definition[]): void {\n allOfSchemas.forEach((subSchema, index) => {\n if (typeof subSchema !== 'object') {\n return\n }\n // Case 1: It's a reference to another entity (standard inheritance).\n if (subSchema.$ref) {\n // Try to resolve the referenced entity by $ref (could be #/definitions/..., $id, or path)\n const parentKey = this.refMap.get(subSchema.$ref)\n if (parentKey) {\n try {\n entity.addParent(parentKey)\n } catch (e) {\n this.report(\n 'warning',\n `Could not add parent ${parentKey} to ${entity.key}: ${(e as Error).message}`,\n entity.key\n )\n }\n } else {\n this.report('warning', `Could not resolve parent reference: ${subSchema.$ref}`, entity.key)\n }\n return\n }\n // Case 2: It's an inline schema to be mixed in.\n // const mixinKey = `${entity.key}_mixin_${index}`\n const mixinName = subSchema.title || `${entity.info.name} Mixin ${index + 1}`\n const mixinEntity = this.model.addEntity({\n // key: mixinKey,\n info: {\n name: mixinName,\n description:\n subSchema.description ||\n `Auto-generated mixin entity from an 'allOf' clause in the schema for '${entity.info.name}'. This entity is not intended for direct use.`,\n },\n })\n this.populateEntity(mixinEntity, subSchema)\n try {\n entity.addParent(mixinEntity.key)\n } catch (e) {\n this.report(\n 'warning',\n `Could not add mixin parent ${mixinEntity.key} to ${entity.key}: ${(e as Error).message}`,\n entity.key\n )\n }\n })\n }\n /**\n * Recursively analyzes a schema definition to find all contained primitive types and `$ref`s.\n * It's used to understand the nature of a property (is it a primitive, an association, or a mix).\n */\n private collectTypesAndRefs(schema: JSONSchema7Definition): {\n refs: Set<string>\n types: Set<JSONSchema7TypeName>\n isArray: boolean\n } {\n const collected = { refs: new Set<string>(), types: new Set<JSONSchema7TypeName>(), isArray: false }\n\n if (typeof schema !== 'object') {\n return collected\n }\n\n if (schema.$ref) {\n collected.refs.add(schema.$ref)\n return collected\n }\n\n if (schema.type) {\n const types = Array.isArray(schema.type) ? schema.type : [schema.type]\n for (const t of types) {\n if (t !== 'null') collected.types.add(t)\n }\n }\n\n if (schema.type === 'array') {\n collected.isArray = true\n if (typeof schema.items === 'object') {\n // Recurse into items\n const itemInfo = this.collectTypesAndRefs(Array.isArray(schema.items) ? schema.items[0] : schema.items)\n itemInfo.refs.forEach((r) => collected.refs.add(r))\n itemInfo.types.forEach((t) => collected.types.add(t))\n }\n return collected\n }\n\n const choices = schema.anyOf || schema.oneOf\n if (choices) {\n for (const choice of choices) {\n const choiceInfo = this.collectTypesAndRefs(choice)\n choiceInfo.refs.forEach((r) => collected.refs.add(r))\n choiceInfo.types.forEach((t) => collected.types.add(t))\n if (choiceInfo.isArray) {\n collected.isArray = true\n }\n }\n }\n\n return collected\n }\n\n /**\n * Determines whether to create a DomainProperty or a DomainAssociation for a given schema property.\n */\n private createPropertyOrAssociation(\n entity: DomainEntity,\n propName: string,\n propSchema: JSONSchema7,\n isRequired: boolean\n ): void {\n // Analyze the property schema to understand its composition (primitives, refs, arrays).\n const analysis = this.collectTypesAndRefs(propSchema)\n\n // Case 1: If the property has `$ref` to an enum, we treat it as a DomainProperty.\n if (analysis.refs.size === 1 && this.enums.has([...analysis.refs][0])) {\n const prop = this.createEnumProperty(\n propName,\n propSchema,\n this.enums.get([...analysis.refs][0]) as JSONSchema7,\n entity.info.name as string\n )\n if (prop) {\n prop.multiple = analysis.isArray\n // console.log(`Adding enum property '${propName}' to entity '${entity.info.name}'`, prop.toJSON())\n entity.addProperty(prop.toJSON())\n }\n return\n }\n\n // Case 2: If any `$ref` was found, we treat it as an Association.\n if (analysis.refs.size > 0) {\n const sanitizedName = toDatabaseColumnName(propName, 'untitled_association')\n const assoc = entity.addAssociation({}, { info: { name: sanitizedName } })\n if (sanitizedName !== propName) {\n assoc.info.displayName = propName // Keep original name for display\n }\n if (propSchema.description) {\n assoc.info.description = propSchema.description\n }\n assoc.required = isRequired\n assoc.multiple = analysis.isArray\n for (const ref of analysis.refs) {\n const targetKey = this.refMap.get(ref)\n if (targetKey) {\n assoc.addTarget(targetKey)\n }\n }\n if (analysis.types.size > 0) {\n this.report(\n 'warning',\n `Property '${propName}' has a mix of reference and primitive types. Only the reference(s) will be used to create an association. The primitive types (${[\n ...analysis.types,\n ].join(', ')}) are ignored.`,\n entity.key\n )\n }\n return\n }\n // Case 3: No `$ref`s found, only primitive types. We treat it as a DomainProperty.\n if (analysis.types.size > 0) {\n // We need to create a temporary schema object to pass to createDomainProperty,\n // as it expects a single schema. We'll use the first detected type.\n const tempSchema: JSONSchema7 = {\n ...propSchema,\n // Pass the collected types to be resolved by mapJsonTypeToDomainType\n type: [...analysis.types],\n }\n const prop = this.createDomainProperty(entity.key, propName, tempSchema, isRequired)\n if (prop) {\n prop.multiple = analysis.isArray\n entity.addProperty(prop.toJSON())\n }\n return\n }\n }\n\n /**\n * Creates and configures a DomainProperty based on a JSON schema property definition.\n */\n private createDomainProperty(\n parentEntityKey: string,\n propName: string,\n propSchema: JSONSchema7,\n isRequired: boolean\n ): DomainProperty | null {\n const typeInfo = this.mapJsonTypeToDomainType(propSchema.type, propSchema, `${parentEntityKey}.${propName}`)\n if (!typeInfo) return null\n const sanitizedName = toDatabaseColumnName(propName, 'untitled_property')\n const propertyInit: Partial<DomainPropertySchema> = {\n info: { name: sanitizedName, description: propSchema.description },\n type: typeInfo.type,\n required: isRequired,\n }\n\n // Use the constructor that doesn't add to the graph immediately.\n const prop = new DomainProperty(this.domain, parentEntityKey, propertyInit)\n if (sanitizedName !== propName) {\n prop.info.displayName = propName // Keep original name for display\n }\n\n const schema: PropertySchema = {}\n const webBindings: PropertyWebBindings = {}\n\n if (propSchema.pattern) schema.pattern = propSchema.pattern\n if (propSchema.enum) schema.enum = propSchema.enum.map(String)\n if (propSchema.default !== undefined) schema.defaultValue = { type: 'literal', value: String(propSchema.default) }\n\n if (typeInfo.type === 'string') {\n if (typeof propSchema.minLength === 'number') schema.minimum = propSchema.minLength\n if (typeof propSchema.maxLength === 'number') schema.maximum = propSchema.maxLength\n } else if (typeInfo.type === 'number') {\n if (typeof propSchema.minimum === 'number') schema.minimum = propSchema.minimum\n if (typeof propSchema.maximum === 'number') schema.maximum = propSchema.maximum\n if (typeof propSchema.exclusiveMinimum === 'number') {\n schema.minimum = propSchema.exclusiveMinimum\n schema.exclusiveMinimum = true\n }\n if (typeof propSchema.exclusiveMaximum === 'number') {\n schema.maximum = propSchema.exclusiveMaximum\n schema.exclusiveMaximum = true\n }\n if (typeof propSchema.multipleOf === 'number') schema.multipleOf = propSchema.multipleOf\n if (typeInfo.format) {\n webBindings.format = typeInfo.format\n }\n }\n\n if (Object.keys(schema).length > 0) {\n prop.schema = schema\n }\n if (Object.keys(webBindings).length > 0) {\n prop.bindings = [{ type: 'web', schema: webBindings }]\n }\n\n return prop\n }\n\n /**\n * Maps a JSON Schema type to a DomainPropertyType.\n */\n private mapJsonTypeToDomainType(\n jsonType: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined,\n schema: JSONSchema7,\n location?: string\n ): { type: DomainPropertyType; format?: DomainPropertyFormat } | null {\n if (!jsonType) {\n return null\n }\n\n if (Array.isArray(jsonType)) {\n const nonNullTypes = jsonType.filter((t) => t !== 'null')\n if (nonNullTypes.length === 0) {\n return null\n }\n if (nonNullTypes.length === 2 && nonNullTypes.includes('array')) {\n const nonArrayType = nonNullTypes.filter((t) => t !== 'array')[0]\n return this.mapJsonTypeToDomainType(nonArrayType, schema, location)\n }\n if (nonNullTypes.length > 1) {\n this.report(\n 'warning',\n `Property has a union of primitive types: [${nonNullTypes.join(', ')}]. The importer will use the first type ('${nonNullTypes[0]}').`,\n location\n )\n }\n // Pick the first non-null type from the union.\n return this.mapJsonTypeToDomainType(nonNullTypes[0], schema, location)\n }\n\n if (jsonType === 'string') {\n // JSON Schema has the `format` property which can specify more about the string type.\n // We need to decide how to handle these formats.\n const choices = schema.anyOf || schema.oneOf\n if (Array.isArray(choices)) {\n // If we have a list of choices, we need to pick one.\n const formats: string[] = []\n for (const choice of choices) {\n const typed = choice as JSONSchema7\n if (typed.format) {\n formats.push(typed.format)\n }\n }\n // we will list dates from the most specific to the least specific\n if (formats.includes('date-time')) {\n return { type: 'datetime' }\n }\n if (formats.includes('date')) {\n return { type: 'date' }\n }\n if (formats.includes('time')) {\n return { type: 'time' }\n }\n }\n // If no specific format is found, we default to string.\n return { type: 'string' }\n }\n\n switch (jsonType) {\n case 'number':\n return { type: 'number', format: 'double' }\n case 'integer':\n return { type: 'number', format: 'int64' }\n case 'boolean':\n return { type: 'boolean' }\n // JSON Schema's 'object' and 'array' are handled as associations or multi-valued properties.\n // Other types like 'null' are handled by making the property not required.\n default:\n return null\n }\n }\n\n private createEnumProperty(\n propName: string,\n propSchema: JSONSchema7,\n enumSchema: JSONSchema7,\n parentEntityKey: string\n ): DomainProperty | null {\n const description = propSchema.description ?? enumSchema.description\n const typeInfo = this.mapJsonTypeToDomainType(enumSchema.type, enumSchema, `${parentEntityKey}.${propName}`)\n if (!typeInfo) return null\n\n const sanitizedName = toDatabaseColumnName(propName)\n const propertyInit: Partial<DomainPropertySchema> = {\n info: { name: sanitizedName },\n type: typeInfo.type,\n // required: isRequired,\n required: false,\n }\n\n // Use the constructor that doesn't add to the graph immediately.\n const prop = new DomainProperty(this.domain, parentEntityKey, propertyInit)\n if (sanitizedName !== propName) {\n prop.info.displayName = propName // Keep original name for display\n }\n if (description) {\n prop.info.description = sanitizeInput(description)\n }\n\n const schema: PropertySchema = {}\n\n const pattern = propSchema.pattern ?? enumSchema.pattern\n if (pattern) {\n schema.pattern = pattern\n }\n const defaultValue = propSchema.default ?? enumSchema.default\n if (defaultValue !== undefined) {\n schema.defaultValue = { type: 'literal', value: String(defaultValue) }\n }\n\n if (typeInfo.type === 'string') {\n const minLength = propSchema.minLength ?? enumSchema.minLength\n const maxLength = propSchema.maxLength ?? enumSchema.maxLength\n if (minLength !== undefined) schema.minimum = minLength\n if (maxLength !== undefined) schema.maximum = maxLength\n } else if (typeInfo.type === 'number') {\n const minimum = propSchema.minimum ?? enumSchema.minimum\n const maximum = propSchema.maximum ?? enumSchema.maximum\n if (minimum !== undefined) {\n schema.minimum = minimum\n }\n if (maximum !== undefined) {\n schema.maximum = maximum\n }\n const exclusiveMinimum = propSchema.exclusiveMinimum ?? enumSchema.exclusiveMinimum\n const exclusiveMaximum = propSchema.exclusiveMaximum ?? enumSchema.exclusiveMaximum\n if (typeof exclusiveMinimum === 'number') {\n schema.minimum = exclusiveMinimum\n schema.exclusiveMinimum = true\n }\n if (typeof exclusiveMaximum === 'number') {\n schema.maximum = exclusiveMaximum\n schema.exclusiveMaximum = true\n }\n const multipleOf = propSchema.multipleOf ?? enumSchema.multipleOf\n if (typeof multipleOf === 'number') {\n schema.multipleOf = multipleOf\n }\n }\n if (enumSchema.oneOf && Array.isArray(enumSchema.oneOf)) {\n schema.enum = []\n for (const item of enumSchema.oneOf) {\n if (typeof item !== 'object' || !('const' in item)) {\n this.report(\n 'warning',\n `Invalid enum item in oneOf: ${JSON.stringify(item)}. Expected an object with 'const' property.`,\n `${parentEntityKey}.${propName}`\n )\n continue\n }\n if (typeof (item as JSONSchema7).const !== 'string') {\n this.report(\n 'warning',\n `Invalid enum const value: ${JSON.stringify((item as JSONSchema7).const)}. Expected a string.`,\n `${parentEntityKey}.${propName}`\n )\n continue\n }\n schema.enum.push((item as JSONSchema7).const as string)\n }\n }\n\n if (Object.keys(schema).length > 0) {\n prop.schema = schema\n }\n return prop\n }\n}\n"]}
1
+ {"version":3,"file":"JsonSchemaImporter.js","sourceRoot":"","sources":["../../../../src/modeling/importers/JsonSchemaImporter.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAA6B,MAAM,sBAAsB,CAAA;AAIhF,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AACjG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAqCxC;;;;;GAKG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAY;IAClB,KAAK,CAAc;IACnB,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAA;IAClC,QAAQ,GAAoB,EAAE,CAAA;IAC9B,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAA;IAE9C,YAAY,MAAkB;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACK,UAAU,CAAC,SAAiB;QAClC,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,I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AK,CAAC,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACxD,MAAM,CAAC,IAAI,GAAG,EAAE,CAAA;YAChB,KAAK,MAAM,IAAI,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;gBACpC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,CAAC,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC;oBACnD,IAAI,CAAC,MAAM,CACT,SAAS,EACT,+BAA+B,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,6CAA6C,EAChG,GAAG,eAAe,IAAI,QAAQ,EAAE,CACjC,CAAA;oBACD,SAAQ;gBACV,CAAC;gBACD,IAAI,OAAQ,IAAoB,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;oBACpD,IAAI,CAAC,MAAM,CACT,SAAS,EACT,6BAA6B,IAAI,CAAC,SAAS,CAAE,IAAoB,CAAC,KAAK,CAAC,sBAAsB,EAC9F,GAAG,eAAe,IAAI,QAAQ,EAAE,CACjC,CAAA;oBACD,SAAQ;gBACV,CAAC;gBACD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAE,IAAoB,CAAC,KAAe,CAAC,CAAA;YACzD,CAAC;QACH,CAAC;QAED,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACnC,2EAA2E;YAC3E,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACtB,CAAC;QACD,OAAO,IAAI,CAAA;IACb,CAAC;CACF","sourcesContent":["import type { JSONSchema7, JSONSchema7Definition, JSONSchema7TypeName } from 'json-schema'\nimport { DataDomain } from '../DataDomain.js'\nimport { DomainModel } from '../DomainModel.js'\nimport { DomainEntity } from '../DomainEntity.js'\nimport { DomainProperty, type DomainPropertySchema } from '../DomainProperty.js'\nimport type { PropertySchema } from '../types.js'\nimport type { PropertyWebBindings } from '../Bindings.js'\nimport type { DomainPropertyFormat, DomainPropertyType } from '../DataFormat.js'\nimport { sanitizeInput, toDatabaseColumnName, toDatabaseTableName } from '../helpers/database.js'\nimport { nanoid } from '../../nanoid.js'\n\n/**\n * Represents a single message (info, warning, or error) generated during the import process.\n */\nexport interface ImportMessage {\n level: 'warning' | 'info'\n message: string\n location?: string\n}\n\n/**\n * A report containing the result of the import process, including the created model\n * and any non-blocking messages.\n */\nexport interface JsonImportReport {\n /**\n * An array of messages generated during the import process.\n * These can include warnings, info messages, or other non-blocking notifications.\n */\n messages: ImportMessage[]\n /**\n * The model that was created during the import.\n */\n model: DomainModel\n}\n\n/**\n * A structure to hold in-memory JSON schema files for browser-based import.\n */\nexport interface InMemorySchema {\n /** A virtual path or identifier for the schema, used in `$ref` values. */\n path: string\n /** The parsed content of the JSON schema file. */\n contents: JSONSchema7\n}\n\n/**\n * Imports JSON Schema definitions into a DataDomain.\n *\n * This class parses a root JSON Schema file, bundles all its dependencies,\n * and translates the object definitions into DomainEntity instances within a specified DomainModel.\n */\nexport class JsonSchemaImporter {\n private domain: DataDomain\n private model!: DomainModel\n private refMap = new Map<string, string>()\n private messages: ImportMessage[] = []\n private enums = new Map<string, JSONSchema7>()\n\n constructor(domain: DataDomain) {\n this.domain = domain\n }\n\n /**\n * Resets the internal state for a new import operation.\n */\n private resetState(modelName: string) {\n this.model = this.domain.addModel({ info: { name: modelName } })\n this.refMap.clear()\n this.enums.clear()\n this.messages = []\n }\n\n /**\n * Centralized reporting for warnings and info messages.\n */\n private report(level: 'warning' | 'info', message: string, location?: string): void {\n this.messages.push({ level, message, location })\n }\n\n /**\n * Main import method: orchestrates schema bundling, entity creation, and population.\n */\n public async import(schemas: InMemorySchema[], modelName: string): Promise<JsonImportReport> {\n this.resetState(modelName)\n\n // Build a flat map of all definitions and $id-indexed schemas\n const definitionMap = new Map<string, JSONSchema7>()\n const idMap = new Map<string, JSONSchema7>()\n const processedSchemas = new Set<JSONSchema7>() // Track processed schema objects to avoid duplicates\n\n for (const schema of schemas) {\n // Add $id mapping if present\n if (schema.contents.$id) {\n idMap.set(schema.contents.$id, schema.contents)\n // Add the entire schema to the definitions maps as well as they can be referenced by other schemas.\n definitionMap.set(schema.contents.$id, schema.contents)\n }\n // Add the schema itself by its path\n definitionMap.set(schema.path, schema.contents)\n // Add all definitions inside this schema\n const definitions = schema.contents.definitions\n const defs = (schema.contents as unknown as { $defs: Record<string, JSONSchema7Definition> }).$defs\n\n if (definitions) {\n for (const [defName, defSchema] of Object.entries(definitions)) {\n if (typeof defSchema === 'object') {\n // Use a JSON pointer for the key - include both full path and short form\n definitionMap.set(`${schema.path}#/definitions/${defName}`, defSchema as JSONSchema7)\n definitionMap.set(`#/definitions/${defName}`, defSchema as JSONSchema7)\n }\n }\n }\n\n if (defs) {\n for (const [defName, defSchema] of Object.entries(defs)) {\n if (typeof defSchema === 'object') {\n // Use a JSON pointer for the key - include both full path and short form\n definitionMap.set(`${schema.path}#/$defs/${defName}`, defSchema as JSONSchema7)\n definitionMap.set(`#/$defs/${defName}`, defSchema as JSONSchema7)\n }\n }\n }\n }\n\n // == Pass 1: Create all entities ==\n for (const [key, schema] of definitionMap.entries()) {\n // Skip if this schema object has already been processed\n if (processedSchemas.has(schema)) {\n continue\n }\n\n if (typeof schema === 'object' && schema.type === 'object') {\n this.createEntity(key, schema, key)\n processedSchemas.add(schema)\n } else if (this.isEnum(schema)) {\n this.enums.set(key, schema)\n } else {\n this.report('warning', `Skipping non-object schema at ${key}`, key)\n }\n }\n // Also create entities for all $id-indexed schemas if not already present\n for (const [id, schema] of idMap.entries()) {\n // Skip if this schema object has already been processed\n if (processedSchemas.has(schema)) {\n continue\n }\n\n if (!this.refMap.has(id) && typeof schema === 'object' && schema.type === 'object') {\n this.createEntity(id, schema, id)\n processedSchemas.add(schema)\n } else if (this.isEnum(schema) && !this.enums.has(id)) {\n this.enums.set(id, schema)\n } else {\n this.report('warning', `Skipping non-object schema at ${id}`, id)\n }\n }\n // == Pass 2: Populate entities ==\n for (const [refPath, entityKey] of this.refMap.entries()) {\n const entity = this.domain.findEntity(entityKey)\n if (!entity) {\n this.report('warning', `Entity not found: ${entityKey}`, refPath)\n continue\n }\n const schema = this.resolveSchemaRef(refPath, definitionMap, idMap)\n if (!schema) {\n this.report('warning', `Schema not found for ref: ${refPath}`, refPath)\n continue\n }\n this.populateEntity(entity, schema)\n }\n\n return { model: this.model, messages: this.messages }\n }\n\n private isEnum(schema: JSONSchema7): boolean {\n if (schema.type !== 'string') {\n // I might be wrong about it, but I think enums are only for strings\n return false\n }\n if (!Array.isArray(schema.oneOf)) {\n return false\n }\n const notConst = schema.oneOf.find((s) => typeof s !== 'object' || !('const' in s))\n return !notConst // If all schemas in oneOf have 'const', it's an enum\n }\n\n /**\n * Resolves a schema reference from the flat definition/id maps.\n * Supports #/definitions/..., $id, or direct path keys.\n */\n private resolveSchemaRef(\n refPath: string,\n definitionMap: Map<string, JSONSchema7>,\n idMap: Map<string, JSONSchema7>\n ): JSONSchema7 | undefined {\n // Try direct match\n if (definitionMap.has(refPath)) return definitionMap.get(refPath)\n if (idMap.has(refPath)) return idMap.get(refPath)\n // Try to resolve #/definitions/Name or #/$defs/Name from any schema\n if (refPath.startsWith('#/definitions/') || refPath.startsWith('#/$defs/')) {\n for (const [key, schema] of definitionMap.entries()) {\n if (key === refPath) return schema\n }\n }\n // Try to resolve by $id fragment\n if (refPath.startsWith('#')) {\n for (const [id, schema] of idMap.entries()) {\n if (id.endsWith(refPath)) return schema\n }\n }\n return undefined\n }\n\n /**\n * Helper for entity creation, can be extended for custom logic.\n */\n private createEntity(name: string, schema: JSONSchema7, refPath: string): DomainEntity {\n let fixedName = schema.title || name\n\n // Extract just the definition name from JSON pointers (both short and full paths)\n if (name.includes('#/definitions/')) {\n const parts = name.split('#/definitions/')\n fixedName = schema.title || parts[parts.length - 1]\n } else if (name.includes('#/$defs/')) {\n const parts = name.split('#/$defs/')\n fixedName = schema.title || parts[parts.length - 1]\n }\n\n const cleanName = toDatabaseTableName(fixedName, 'untitled_entity')\n const entity = this.model.addEntity({\n info: {\n name: cleanName,\n displayName: fixedName,\n },\n })\n if (fixedName !== cleanName) {\n entity.info.displayName = fixedName // Keep original title for display\n }\n if (schema.description) {\n entity.info.description = schema.description\n }\n this.refMap.set(refPath, entity.key)\n return entity\n }\n\n /**\n * Generates a meaningful name for inline entities based on their parent context.\n */\n private generateInlineEntityName(parentEntityKey: string, propName: string, schema: JSONSchema7): string {\n // Try to use the schema title first\n if (schema.title) {\n return toDatabaseTableName(schema.title, 'untitled_entity')\n }\n\n // Find the parent entity to create a meaningful name\n const parentEntity = this.domain.findEntity(parentEntityKey)\n const parentName = parentEntity?.info.name || 'unknown'\n\n // Create a name like \"User_Address\" or \"Order_ShippingInfo\"\n const combinedName = `${parentName}_${propName}`\n return toDatabaseTableName(combinedName, 'untitled_entity')\n }\n\n /**\n * Populates a DomainEntity with its properties, associations, and parent relationships.\n */\n private populateEntity(entity: DomainEntity, schema: JSONSchema7): void {\n const properties = schema.properties || {}\n const required = new Set(schema.required || [])\n\n for (const [propName, propSchema] of Object.entries(properties)) {\n if (typeof propSchema === 'object') {\n this.createPropertyOrAssociation(entity, propName, propSchema, required.has(propName))\n }\n }\n\n // Handle 'allOf' for inheritance and composition.\n if (schema.allOf) {\n this.processAllOf(entity, schema.allOf)\n }\n }\n\n /**\n * Processes the `allOf` keyword, which can contain references (for inheritance)\n * or inline schemas (for composition/mixins).\n */\n private processAllOf(entity: DomainEntity, allOfSchemas: JSONSchema7Definition[]): void {\n allOfSchemas.forEach((subSchema, index) => {\n if (typeof subSchema !== 'object') {\n return\n }\n // Case 1: It's a reference to another entity (standard inheritance).\n if (subSchema.$ref) {\n // Try to resolve the referenced entity by $ref (could be #/definitions/..., $id, or path)\n const parentKey = this.refMap.get(subSchema.$ref)\n if (parentKey) {\n try {\n entity.addParent(parentKey)\n } catch (e) {\n this.report(\n 'warning',\n `Could not add parent ${parentKey} to ${entity.key}: ${(e as Error).message}`,\n entity.key\n )\n }\n } else {\n this.report('warning', `Could not resolve parent reference: ${subSchema.$ref}`, entity.key)\n }\n return\n }\n // Case 2: It's an inline schema to be mixed in.\n // const mixinKey = `${entity.key}_mixin_${index}`\n const mixinName = subSchema.title || `${entity.info.name} Mixin ${index + 1}`\n const mixinEntity = this.model.addEntity({\n // key: mixinKey,\n info: {\n name: mixinName,\n description:\n subSchema.description ||\n `Auto-generated mixin entity from an 'allOf' clause in the schema for '${entity.info.name}'. This entity is not intended for direct use.`,\n },\n })\n this.populateEntity(mixinEntity, subSchema)\n try {\n entity.addParent(mixinEntity.key)\n } catch (e) {\n this.report(\n 'warning',\n `Could not add mixin parent ${mixinEntity.key} to ${entity.key}: ${(e as Error).message}`,\n entity.key\n )\n }\n })\n }\n /**\n * Recursively analyzes a schema definition to find all contained primitive types and `$ref`s.\n * It's used to understand the nature of a property (is it a primitive, an association, or a mix).\n */\n private collectTypesAndRefs(\n schema: JSONSchema7Definition,\n parentEntityKey?: string,\n propName?: string\n ): {\n refs: Set<string>\n types: Set<JSONSchema7TypeName>\n isArray: boolean\n } {\n const collected = { refs: new Set<string>(), types: new Set<JSONSchema7TypeName>(), isArray: false }\n\n if (typeof schema !== 'object') {\n return collected\n }\n\n if (schema.$ref) {\n collected.refs.add(schema.$ref)\n return collected\n }\n\n if (schema.type) {\n const types = Array.isArray(schema.type) ? schema.type : [schema.type]\n for (const t of types) {\n if (t !== 'null') collected.types.add(t)\n }\n }\n\n // Handle inline object types by creating entities immediately\n if (schema.type === 'object' && schema.properties && parentEntityKey && propName) {\n // Create an entity for this inline object immediately\n const inlineEntityName = this.generateInlineEntityName(parentEntityKey, propName, schema)\n const inlineEntity = this.createEntity(inlineEntityName, schema, inlineEntityName)\n\n // Populate it immediately since we have the schema\n this.populateEntity(inlineEntity, schema)\n\n // Add a reference to it so it gets treated as an association\n collected.refs.add(inlineEntityName)\n\n return collected\n }\n\n if (schema.type === 'array') {\n collected.isArray = true\n if (typeof schema.items === 'object') {\n // Recurse into items - pass along parent context for inline objects in arrays\n const itemInfo = this.collectTypesAndRefs(\n Array.isArray(schema.items) ? schema.items[0] : schema.items,\n parentEntityKey,\n propName ? `${propName}_item` : undefined\n )\n itemInfo.refs.forEach((r) => collected.refs.add(r))\n itemInfo.types.forEach((t) => collected.types.add(t))\n }\n return collected\n }\n\n const choices = schema.anyOf || schema.oneOf\n if (choices) {\n for (const choice of choices) {\n const choiceInfo = this.collectTypesAndRefs(choice, parentEntityKey)\n choiceInfo.refs.forEach((r) => collected.refs.add(r))\n choiceInfo.types.forEach((t) => collected.types.add(t))\n if (choiceInfo.isArray) {\n collected.isArray = true\n }\n }\n }\n\n if (schema.enum) {\n // If the schema has an enum, we treat it as a string type with specific values.\n collected.types.add('string')\n // consider the following schema: `\"enum\": [\"one\", \"two\", \"three\"]`\n const id = nanoid(8)\n this.enums.set(id, {\n type: 'string',\n oneOf: schema.enum.map((value) => ({\n const: String(value), // Ensure enum values are strings\n })),\n })\n collected.refs.add(id) // Add the enum reference\n }\n\n return collected\n }\n\n /**\n * Determines whether to create a DomainProperty or a DomainAssociation for a given schema property.\n */\n private createPropertyOrAssociation(\n entity: DomainEntity,\n propName: string,\n propSchema: JSONSchema7,\n isRequired: boolean\n ): void {\n // Analyze the property schema to understand its composition (primitives, refs, arrays).\n // Pass entity context to collectTypesAndRefs for inline object handling\n const analysis = this.collectTypesAndRefs(propSchema, entity.key, propName)\n // console.log(`Analyzing property '${propName}' in entity '${entity.info.name}':`, analysis, propSchema)\n // Case 1: If the property has `$ref` to an enum, we treat it as a DomainProperty.\n if (analysis.refs.size === 1 && this.enums.has([...analysis.refs][0])) {\n const prop = this.createEnumProperty(\n propName,\n propSchema,\n this.enums.get([...analysis.refs][0]) as JSONSchema7,\n entity.info.name as string\n )\n if (prop) {\n prop.multiple = analysis.isArray\n // console.log(`Adding enum property '${propName}' to entity '${entity.info.name}'`, prop.toJSON())\n entity.addProperty(prop.toJSON())\n }\n return\n }\n\n // Case 2: If any `$ref` was found, we treat it as an Association.\n if (analysis.refs.size > 0) {\n const sanitizedName = toDatabaseColumnName(propName, 'untitled_association')\n const assoc = entity.addAssociation({}, { info: { name: sanitizedName } })\n if (sanitizedName !== propName) {\n assoc.info.displayName = propName // Keep original name for display\n }\n if (propSchema.description) {\n assoc.info.description = propSchema.description\n }\n assoc.required = isRequired\n assoc.multiple = analysis.isArray\n for (const ref of analysis.refs) {\n const targetKey = this.refMap.get(ref)\n if (targetKey) {\n assoc.addTarget(targetKey)\n }\n }\n if (analysis.types.size > 0) {\n this.report(\n 'warning',\n `Property '${propName}' has a mix of reference and primitive types. Only the reference(s) will be used to create an association. The primitive types (${[\n ...analysis.types,\n ].join(', ')}) are ignored.`,\n entity.key\n )\n }\n return\n }\n // Case 3: No `$ref`s found, only primitive types. We treat it as a DomainProperty.\n if (analysis.types.size > 0) {\n // We need to create a temporary schema object to pass to createDomainProperty,\n // as it expects a single schema. We'll use the first detected type.\n const tempSchema: JSONSchema7 = {\n ...propSchema,\n // Pass the collected types to be resolved by mapJsonTypeToDomainType\n type: [...analysis.types],\n }\n const prop = this.createDomainProperty(entity.key, propName, tempSchema, isRequired)\n if (prop) {\n prop.multiple = analysis.isArray\n entity.addProperty(prop.toJSON())\n }\n return\n }\n }\n\n /**\n * Creates and configures a DomainProperty based on a JSON schema property definition.\n */\n private createDomainProperty(\n parentEntityKey: string,\n propName: string,\n propSchema: JSONSchema7,\n isRequired: boolean\n ): DomainProperty | null {\n const typeInfo = this.mapJsonTypeToDomainType(propSchema.type, propSchema, `${parentEntityKey}.${propName}`)\n if (!typeInfo) return null\n const sanitizedName = toDatabaseColumnName(propName, 'untitled_property')\n const propertyInit: Partial<DomainPropertySchema> = {\n info: { name: sanitizedName, description: propSchema.description },\n type: typeInfo.type,\n required: isRequired,\n }\n\n // Use the constructor that doesn't add to the graph immediately.\n const prop = new DomainProperty(this.domain, parentEntityKey, propertyInit)\n if (sanitizedName !== propName) {\n prop.info.displayName = propName // Keep original name for display\n }\n\n const schema: PropertySchema = {}\n const webBindings: PropertyWebBindings = {}\n\n if (propSchema.pattern) schema.pattern = propSchema.pattern\n if (propSchema.enum) schema.enum = propSchema.enum.map(String)\n if (propSchema.default !== undefined) schema.defaultValue = { type: 'literal', value: String(propSchema.default) }\n\n if (typeInfo.type === 'string') {\n if (typeof propSchema.minLength === 'number') schema.minimum = propSchema.minLength\n if (typeof propSchema.maxLength === 'number') schema.maximum = propSchema.maxLength\n } else if (typeInfo.type === 'number') {\n if (typeof propSchema.minimum === 'number') schema.minimum = propSchema.minimum\n if (typeof propSchema.maximum === 'number') schema.maximum = propSchema.maximum\n if (typeof propSchema.exclusiveMinimum === 'number') {\n schema.minimum = propSchema.exclusiveMinimum\n schema.exclusiveMinimum = true\n }\n if (typeof propSchema.exclusiveMaximum === 'number') {\n schema.maximum = propSchema.exclusiveMaximum\n schema.exclusiveMaximum = true\n }\n if (typeof propSchema.multipleOf === 'number') schema.multipleOf = propSchema.multipleOf\n if (typeInfo.format) {\n webBindings.format = typeInfo.format\n }\n }\n\n if (Object.keys(schema).length > 0) {\n prop.schema = schema\n }\n if (Object.keys(webBindings).length > 0) {\n prop.bindings = [{ type: 'web', schema: webBindings }]\n }\n\n return prop\n }\n\n /**\n * Maps a JSON Schema type to a DomainPropertyType.\n */\n private mapJsonTypeToDomainType(\n jsonType: JSONSchema7TypeName | JSONSchema7TypeName[] | undefined,\n schema: JSONSchema7,\n location?: string\n ): { type: DomainPropertyType; format?: DomainPropertyFormat } | null {\n if (!jsonType) {\n return null\n }\n\n if (Array.isArray(jsonType)) {\n const nonNullTypes = jsonType.filter((t) => t !== 'null')\n if (nonNullTypes.length === 0) {\n return null\n }\n if (nonNullTypes.length === 2 && nonNullTypes.includes('array')) {\n const nonArrayType = nonNullTypes.filter((t) => t !== 'array')[0]\n return this.mapJsonTypeToDomainType(nonArrayType, schema, location)\n }\n if (nonNullTypes.length > 1) {\n this.report(\n 'warning',\n `Property has a union of primitive types: [${nonNullTypes.join(', ')}]. The importer will use the first type ('${nonNullTypes[0]}').`,\n location\n )\n }\n // Pick the first non-null type from the union.\n return this.mapJsonTypeToDomainType(nonNullTypes[0], schema, location)\n }\n\n if (jsonType === 'string') {\n // JSON Schema has the `format` property which can specify more about the string type.\n // We need to decide how to handle these formats.\n const choices = schema.anyOf || schema.oneOf\n if (Array.isArray(choices)) {\n // If we have a list of choices, we need to pick one.\n const formats: string[] = []\n for (const choice of choices) {\n const typed = choice as JSONSchema7\n if (typed.format) {\n formats.push(typed.format)\n }\n }\n // we will list dates from the most specific to the least specific\n if (formats.includes('date-time')) {\n return { type: 'datetime' }\n }\n if (formats.includes('date')) {\n return { type: 'date' }\n }\n if (formats.includes('time')) {\n return { type: 'time' }\n }\n }\n // If no specific format is found, we default to string.\n return { type: 'string' }\n }\n\n switch (jsonType) {\n case 'number':\n return { type: 'number', format: 'double' }\n case 'integer':\n return { type: 'number', format: 'int64' }\n case 'boolean':\n return { type: 'boolean' }\n // JSON Schema's 'object' and 'array' are handled as associations or multi-valued properties.\n // Other types like 'null' are handled by making the property not required.\n default:\n return null\n }\n }\n\n private createEnumProperty(\n propName: string,\n propSchema: JSONSchema7,\n enumSchema: JSONSchema7,\n parentEntityKey: string\n ): DomainProperty | null {\n const description = propSchema.description ?? enumSchema.description\n const typeInfo = this.mapJsonTypeToDomainType(enumSchema.type, enumSchema, `${parentEntityKey}.${propName}`)\n if (!typeInfo) return null\n\n const sanitizedName = toDatabaseColumnName(propName)\n const propertyInit: Partial<DomainPropertySchema> = {\n info: { name: sanitizedName },\n type: typeInfo.type,\n // required: isRequired,\n required: false,\n }\n\n // Use the constructor that doesn't add to the graph immediately.\n const prop = new DomainProperty(this.domain, parentEntityKey, propertyInit)\n if (sanitizedName !== propName) {\n prop.info.displayName = propName // Keep original name for display\n }\n if (description) {\n prop.info.description = sanitizeInput(description)\n }\n\n const schema: PropertySchema = {}\n\n const pattern = propSchema.pattern ?? enumSchema.pattern\n if (pattern) {\n schema.pattern = pattern\n }\n const defaultValue = propSchema.default ?? enumSchema.default\n if (defaultValue !== undefined) {\n schema.defaultValue = { type: 'literal', value: String(defaultValue) }\n }\n\n if (typeInfo.type === 'string') {\n const minLength = propSchema.minLength ?? enumSchema.minLength\n const maxLength = propSchema.maxLength ?? enumSchema.maxLength\n if (minLength !== undefined) schema.minimum = minLength\n if (maxLength !== undefined) schema.maximum = maxLength\n } else if (typeInfo.type === 'number') {\n const minimum = propSchema.minimum ?? enumSchema.minimum\n const maximum = propSchema.maximum ?? enumSchema.maximum\n if (minimum !== undefined) {\n schema.minimum = minimum\n }\n if (maximum !== undefined) {\n schema.maximum = maximum\n }\n const exclusiveMinimum = propSchema.exclusiveMinimum ?? enumSchema.exclusiveMinimum\n const exclusiveMaximum = propSchema.exclusiveMaximum ?? enumSchema.exclusiveMaximum\n if (typeof exclusiveMinimum === 'number') {\n schema.minimum = exclusiveMinimum\n schema.exclusiveMinimum = true\n }\n if (typeof exclusiveMaximum === 'number') {\n schema.maximum = exclusiveMaximum\n schema.exclusiveMaximum = true\n }\n const multipleOf = propSchema.multipleOf ?? enumSchema.multipleOf\n if (typeof multipleOf === 'number') {\n schema.multipleOf = multipleOf\n }\n }\n if (enumSchema.oneOf && Array.isArray(enumSchema.oneOf)) {\n schema.enum = []\n for (const item of enumSchema.oneOf) {\n if (typeof item !== 'object' || !('const' in item)) {\n this.report(\n 'warning',\n `Invalid enum item in oneOf: ${JSON.stringify(item)}. Expected an object with 'const' property.`,\n `${parentEntityKey}.${propName}`\n )\n continue\n }\n if (typeof (item as JSONSchema7).const !== 'string') {\n this.report(\n 'warning',\n `Invalid enum const value: ${JSON.stringify((item as JSONSchema7).const)}. Expected a string.`,\n `${parentEntityKey}.${propName}`\n )\n continue\n }\n schema.enum.push((item as JSONSchema7).const as string)\n }\n }\n\n if (Object.keys(schema).length > 0) {\n // console.log(`Creating enum property '${propName}' with schema:`, schema)\n prop.schema = schema\n }\n return prop\n }\n}\n"]}