From a58c707de0e7535004b91134dc022a96dcdc23a2 Mon Sep 17 00:00:00 2001 From: lastlink Date: Sat, 6 Jul 2024 07:09:34 -0400 Subject: [PATCH 1/2] enum support and comment support --- src/nosql-ts.ts | 98 +------------ src/nosql.ts | 97 +------------ src/utils/constants.ts | 16 ++- src/utils/nosqlUtils.ts | 292 +++++++++++++++++++++++++++++++++++++-- src/utils/sharedUtils.ts | 82 ++++++++++- 5 files changed, 381 insertions(+), 204 deletions(-) diff --git a/src/nosql-ts.ts b/src/nosql-ts.ts index 89a406a..cd81035 100644 --- a/src/nosql-ts.ts +++ b/src/nosql-ts.ts @@ -8,7 +8,7 @@ import { convertTypeScriptToCoreTypes } from "core-types-ts/dist/lib/ts-to-core- import { convertCoreTypesToTypeScript } from "core-types-ts"; import { GetColumnQuantifiers, RemoveNameQuantifiers, dbTypeEnds, getDbLabel, getMermaidDiagramDb } from "./utils/sharedUtils"; import { pluginVersion } from "./utils/constants"; -import { dbToOpenApi } from "./utils/nosqlUtils"; +import { ConvertOpenApiToDatabaseModel, dbToOpenApi, GeneratePropertyModel } from "./utils/nosqlUtils"; declare const window: Customwindow; @@ -281,7 +281,9 @@ export interface Child { const data = JSON.parse(text); const { data: doc } = convertOpenApiToCoreTypes( data ); const { data: jsonSchema } = convertCoreTypesToJsonSchema( doc ); - openApi = jsonSchemaDocumentToOpenApi( jsonSchema, openApiOptions ); + // was losing format option, just going to check if exception thrown here + jsonSchemaDocumentToOpenApi( jsonSchema, openApiOptions ); + openApi = data; } else if(type == "ts"){ // serialize typescript classes to openapi spec const { data: doc } = convertTypeScriptToCoreTypes( text ); @@ -290,81 +292,7 @@ export interface Child { } const schemas = openApi?.components?.schemas; if(schemas){ - const models: DatabaseModel = { - Dialect: "nosql", - TableList: [], - PrimaryKeyList: [], - ForeignKeyList: [], - }; - - for (const key in schemas) { - if (Object.prototype.hasOwnProperty.call(schemas, key)) { - const schema = schemas[key] as JSONSchema4; - const tableModel: TableModel = { - Name: dbTypeEnds(key), - Properties: [], - }; - for (const propertyKey in schema.properties) { - if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { - const property = schema.properties[propertyKey]; - const propertyModel: PropertyModel = GeneratePropertyModel(key, propertyKey, property); - if(propertyModel.ColumnProperties.includes("object") || - propertyModel.ColumnProperties.includes("array")) { - let refName: string| null | undefined= null; - if(property.$ref) { - refName = property.$ref.split("/").pop(); - } else if(property.items && typeof property.items == "object") { - refName = (property.items as JSONSchema4).$ref?.split("/").pop(); - } - if(refName) { - - const primaryKeyModel: ForeignKeyModel = { - PrimaryKeyTableName: dbTypeEnds(key), - ReferencesTableName: dbTypeEnds(refName), - PrimaryKeyName: dbTypeEnds(propertyKey), - // should just point to first property in uml table - ReferencesPropertyName: "", - IsDestination: false - }; - const foreignKeyModel: ForeignKeyModel = { - ReferencesTableName: dbTypeEnds(key), - PrimaryKeyTableName: dbTypeEnds(refName), - ReferencesPropertyName: dbTypeEnds(propertyKey), - // should just point to first property in uml table - PrimaryKeyName: "", - IsDestination: true - }; - models.ForeignKeyList.push(foreignKeyModel); - models.ForeignKeyList.push(primaryKeyModel); - propertyModel.IsForeignKey = true; - } - } - - tableModel.Properties.push(propertyModel); - } - } - - models.TableList.push(tableModel); - } - } - for (let i = 0; i < models.ForeignKeyList.length; i++) { - const fk = models.ForeignKeyList[i]; - if(!fk.ReferencesPropertyName){ - // match to first entry - const property = models.TableList.find(t => t.Name == fk.ReferencesTableName)?.Properties[0]; - if(property){ - models.ForeignKeyList[i].ReferencesPropertyName = property.Name; - } - } - if(!fk.PrimaryKeyName){ - // match to first entry - const property = models.TableList.find(t => t.Name == fk.PrimaryKeyTableName)?.Properties[0]; - if(property){ - models.ForeignKeyList[i].PrimaryKeyName = property.Name; - } - } - - } + const models = ConvertOpenApiToDatabaseModel(schemas); foreignKeyList = models.ForeignKeyList; primaryKeyList = models.PrimaryKeyList; tableList = models.TableList; @@ -562,20 +490,4 @@ export interface Child { } } }); -// TODO: may need to make recursive for when schema property items is array -function GeneratePropertyModel(tableName: string, propertyName: string, property: JSONSchema4): PropertyModel { - let columnProperties = (property.type ?? "object").toString(); - if(property.nullable) { - columnProperties += " nullable"; - } - const result: PropertyModel = { - Name: dbTypeEnds(propertyName), - IsPrimaryKey: false, - IsForeignKey: false, - ColumnProperties: columnProperties, - TableName: dbTypeEnds(tableName), - ForeignKey: [], - }; - return result; -} diff --git a/src/nosql.ts b/src/nosql.ts index c820322..867e2fa 100644 --- a/src/nosql.ts +++ b/src/nosql.ts @@ -6,7 +6,7 @@ import { convertCoreTypesToJsonSchema, convertOpenApiToCoreTypes, jsonSchemaDocu import { JsonSchemaDocumentToOpenApiOptions, PartialOpenApiSchema } from "openapi-json-schema"; import { GetColumnQuantifiers, RemoveNameQuantifiers, dbTypeEnds, getDbLabel, getMermaidDiagramDb } from "./utils/sharedUtils"; import { pluginVersion } from "./utils/constants"; -import { dbToOpenApi } from "./utils/nosqlUtils"; +import { ConvertOpenApiToDatabaseModel, dbToOpenApi, GeneratePropertyModel } from "./utils/nosqlUtils"; declare const window: Customwindow; @@ -248,87 +248,16 @@ Draw.loadPlugin(function(ui) { const data = JSON.parse(text); const { data: doc } = convertOpenApiToCoreTypes( data ); const { data: jsonSchema } = convertCoreTypesToJsonSchema( doc ); - openApi = jsonSchemaDocumentToOpenApi( jsonSchema, openApiOptions ); + // was losing format option, just going to check if exception thrown here + jsonSchemaDocumentToOpenApi( jsonSchema, openApiOptions ); + openApi = data; } else { throw new Error(`type:${type} is not supported`); } const schemas = openApi?.components?.schemas; if(schemas){ - const models: DatabaseModel = { - Dialect: "nosql", - TableList: [], - PrimaryKeyList: [], - ForeignKeyList: [], - }; + const models = ConvertOpenApiToDatabaseModel(schemas); - for (const key in schemas) { - if (Object.prototype.hasOwnProperty.call(schemas, key)) { - const schema = schemas[key] as JSONSchema4; - const tableModel: TableModel = { - Name: dbTypeEnds(key), - Properties: [], - }; - for (const propertyKey in schema.properties) { - if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { - const property = schema.properties[propertyKey]; - const propertyModel: PropertyModel = GeneratePropertyModel(key, propertyKey, property); - if(propertyModel.ColumnProperties.includes("object") || - propertyModel.ColumnProperties.includes("array")) { - let refName: string| null | undefined= null; - if(property.$ref) { - refName = property.$ref.split("/").pop(); - } else if(property.items && typeof property.items == "object") { - refName = (property.items as JSONSchema4).$ref?.split("/").pop(); - } - if(refName) { - - const primaryKeyModel: ForeignKeyModel = { - PrimaryKeyTableName: dbTypeEnds(key), - ReferencesTableName: dbTypeEnds(refName), - PrimaryKeyName: dbTypeEnds(propertyKey), - // should just point to first property in uml table - ReferencesPropertyName: "", - IsDestination: false - }; - const foreignKeyModel: ForeignKeyModel = { - ReferencesTableName: dbTypeEnds(key), - PrimaryKeyTableName: dbTypeEnds(refName), - ReferencesPropertyName: dbTypeEnds(propertyKey), - // should just point to first property in uml table - PrimaryKeyName: "", - IsDestination: true - }; - models.ForeignKeyList.push(foreignKeyModel); - models.ForeignKeyList.push(primaryKeyModel); - propertyModel.IsForeignKey = true; - } - } - - tableModel.Properties.push(propertyModel); - } - } - - models.TableList.push(tableModel); - } - } - for (let i = 0; i < models.ForeignKeyList.length; i++) { - const fk = models.ForeignKeyList[i]; - if(!fk.ReferencesPropertyName){ - // match to first entry - const property = models.TableList.find(t => t.Name == fk.ReferencesTableName)?.Properties[0]; - if(property){ - models.ForeignKeyList[i].ReferencesPropertyName = property.Name; - } - } - if(!fk.PrimaryKeyName){ - // match to first entry - const property = models.TableList.find(t => t.Name == fk.PrimaryKeyTableName)?.Properties[0]; - if(property){ - models.ForeignKeyList[i].PrimaryKeyName = property.Name; - } - } - - } foreignKeyList = models.ForeignKeyList; primaryKeyList = models.PrimaryKeyList; tableList = models.TableList; @@ -509,20 +438,4 @@ Draw.loadPlugin(function(ui) { } } }); -// TODO: may need to make recursive for when schema property items is array -function GeneratePropertyModel(tableName: string, propertyName: string, property: JSONSchema4): PropertyModel { - let columnProperties = (property.type ?? "object").toString(); - if(property.nullable) { - columnProperties += " nullable"; - } - const result: PropertyModel = { - Name: dbTypeEnds(propertyName), - IsPrimaryKey: false, - IsForeignKey: false, - ColumnProperties: columnProperties, - TableName: dbTypeEnds(tableName), - ForeignKey: [], - }; - return result; -} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index cc8840a..fbb94c3 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,3 +1,15 @@ +import { ColumnQuantifiers } from "../types/sql-plugin-types"; - // export sql methods - export const pluginVersion = ""; \ No newline at end of file +// export sql methods +export const pluginVersion = ""; + +export const commentColumnQuantifiers: ColumnQuantifiers = { + Start: "/**", + End: "*/", +}; + +export const formatKeyword = "@format"; + +export const enumKeyword = "enum"; + +export const validEnumTypes = ["string", "number", "integer", "boolean"]; \ No newline at end of file diff --git a/src/utils/nosqlUtils.ts b/src/utils/nosqlUtils.ts index 60cafa5..a7a637f 100644 --- a/src/utils/nosqlUtils.ts +++ b/src/utils/nosqlUtils.ts @@ -1,8 +1,21 @@ import { DbDefinition } from "@funktechno/little-mermaid-2-the-sql/lib/src/types"; -import { PartialOpenApiSchema } from "openapi-json-schema"; -import { pluginVersion } from "./constants"; +import { + OpenApiSchemaTypeDefinition, + PartialOpenApiSchema, +} from "openapi-json-schema"; +import { commentColumnQuantifiers, enumKeyword, formatKeyword, pluginVersion, validEnumTypes } from "./constants"; import { JSONSchema4, JSONSchema4TypeName } from "json-schema"; -import { DatabaseModelResult } from "../types/sql-plugin-types"; +import { + ColumnQuantifiers, + DatabaseModelResult, +} from "../types/sql-plugin-types"; +import { dbTypeEnds, generateComment, getCommentIndexes, getDbLabel } from "./sharedUtils"; +import { + DatabaseModel, + ForeignKeyModel, + PropertyModel, + TableModel, +} from "@funktechno/sqlsimpleparser/lib/types"; /** * convert db to openapi @@ -27,32 +40,281 @@ export function dbToOpenApi(db: DatabaseModelResult): PartialOpenApiSchema { const entities = db.getEntities(); for (const key in entities) { if (Object.prototype.hasOwnProperty.call(entities, key)) { + let schemaKey = key; const entity = entities[key]; - if (schema[key]) { + let commentIndexes = getCommentIndexes(key); + let description = ""; + let formatValue = ""; + if(commentIndexes.start > -1 && commentIndexes.end > -1) { + + let result = schemaKey.toString().trim(); + commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex= commentIndexes.end; + schemaKey = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex).trim(); + if (result.indexOf(formatKeyword) !== -1) { + const formatIndex = result.indexOf(formatKeyword); + formatValue = result.substring( + formatIndex + formatKeyword.length + ).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + } + if (schema[schemaKey]) { continue; } - schema[key] = { + schema[schemaKey] = { type: "object", - title: key, + title: schemaKey, additionalProperties: false, properties: {}, }; + if(description) { + schema[schemaKey].description = description.trim(); + } + if(formatValue) { + schema[schemaKey].format = formatValue.trim(); + } for (let p = 0; p < entity.attributes.length; p++) { const attribute = entity.attributes[p]; - const propName = attribute.attributeName; - if (!propName || schema[key].properties[propName]) { + const propName = attribute.attributeName.trim(); + if (!propName || schema[schemaKey].properties[propName]) { continue; } - const attType = attribute.attributeType?.split(" ") ?? []; - const property: JSONSchema4 = { - title: `${key}.${propName}`, - nullable: attribute.attributeType?.includes("nullable") ?? false, - type: (attType[0] ?? "string") as JSONSchema4TypeName, - }; - schema[key].properties[attribute.attributeName!] = property; + // TODO: trim double spaces + const attType = attribute.attributeType?.trim().split(" ") ?? []; + // check if enum + let isEnum = false; + let type = (attType[0] ?? "string") as JSONSchema4TypeName; + if (propName.indexOf(enumKeyword) !== -1) { + const splitPropName = propName.split(" "); + if ( + splitPropName.length == 2 && + validEnumTypes.indexOf(splitPropName[0]) !== -1 && + splitPropName[1] == enumKeyword + ) { + isEnum = true; + type = splitPropName[0] as JSONSchema4TypeName; + } + } + // extract desciption /** asdf */ + let description = ""; + let formatValue = ""; + let enumValues: any[] | null = null; + if ( + attribute.attributeType?.includes(commentColumnQuantifiers.Start) && + attribute.attributeType?.includes(commentColumnQuantifiers.End) + ) { + let result = attribute.attributeType; + const commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex= commentIndexes.end; + const enumRaw = result.substring(0, commentIndexes.beforeStart).trim(); + if (enumRaw) { + try { + enumValues = JSON.parse(enumRaw); + } catch (error) { + console.log( + `Error parsing raw enum values: ${enumRaw} Message: ${JSON.stringify( + error + )}` + ); + } + } + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(formatKeyword) !== -1) { + const formatIndex = result.indexOf(formatKeyword); + formatValue = result + .substring(formatIndex + formatKeyword.length) + .trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } + if (isEnum) { + if (schema[schemaKey].enum) continue; + if (enumValues) { + schema[schemaKey].enum = enumValues; + } + if (description) { + schema[schemaKey].description = description.trim(); + } + if (formatValue) { + schema[schemaKey].format = formatValue.trim(); + } + schema[schemaKey].type = type; + } else { + const property: JSONSchema4 = { + title: `${key}.${propName}`, + nullable: attribute.attributeType?.includes("nullable") ?? false, + type: type, + }; + if (description) { + property.description = description.trim(); + } + if (formatValue) { + property.format = formatValue.trim(); + } + schema[schemaKey].properties[attribute.attributeName!] = property; + } + } + if (Object.keys(schema[schemaKey].properties).length === 0) { + delete schema[schemaKey].properties; } } } result.components!.schemas = schema; return result; } + +// TODO: may need to make recursive for when schema property items is array +export function GeneratePropertyModel( + tableName: string, + propertyName: string, + property: JSONSchema4 +): PropertyModel { + let columnProperties = (property.type ?? "object").toString(); + if (property.enum) { + columnProperties = `${JSON.stringify(property.enum)}`; + } else if (property.nullable) { + columnProperties += " nullable"; + } + const description = generateComment(property.description, property.format); + if (description) { + columnProperties += ` ${description}`; + } + const result: PropertyModel = { + Name: dbTypeEnds(propertyName), + IsPrimaryKey: false, + IsForeignKey: false, + ColumnProperties: columnProperties, + TableName: dbTypeEnds(tableName), + ForeignKey: [], + }; + return result; +} + +export function ConvertOpenApiToDatabaseModel( + schemas: Record +): DatabaseModel { + const models: DatabaseModel = { + Dialect: "nosql", + TableList: [], + PrimaryKeyList: [], + ForeignKeyList: [], + }; + for (const key in schemas) { + if (Object.prototype.hasOwnProperty.call(schemas, key)) { + const schema = schemas[key] as JSONSchema4; + const tableModel: TableModel = { + Name: dbTypeEnds(key), + Properties: [], + }; + if (schema.enum) { + const enumList = schema.enum; + // serialize to string enum [values] + const propertyKey = `${schema.type} enum`; + const property: JSONSchema4 = { + enum: enumList, + }; + if (schema.description) { + property.description = schema.description; + } + if (schema.format) { + property.format = schema.format; + } + const propertyModel: PropertyModel = GeneratePropertyModel( + key, + propertyKey, + property + ); + tableModel.Properties.push(propertyModel); + } else { + const comment = generateComment(schema.description, schema.format); + if (comment) { + tableModel.Name += ` ${comment}`; + } + } + // schema level comments? should these be in a row or table name? + for (const propertyKey in schema.properties) { + if ( + Object.prototype.hasOwnProperty.call(schema.properties, propertyKey) + ) { + const property = schema.properties[propertyKey]; + const propertyModel: PropertyModel = GeneratePropertyModel( + key, + propertyKey, + property + ); + if ( + propertyModel.ColumnProperties.includes("object") || + propertyModel.ColumnProperties.includes("array") + ) { + let refName: string | null | undefined = null; + if (property.$ref) { + refName = property.$ref.split("/").pop(); + } else if (property.items && typeof property.items == "object") { + refName = (property.items as JSONSchema4).$ref?.split("/").pop(); + } + if (refName) { + const primaryKeyModel: ForeignKeyModel = { + PrimaryKeyTableName: dbTypeEnds(key), + ReferencesTableName: dbTypeEnds(refName), + PrimaryKeyName: dbTypeEnds(propertyKey), + // should just point to first property in uml table + ReferencesPropertyName: "", + IsDestination: false, + }; + const foreignKeyModel: ForeignKeyModel = { + ReferencesTableName: dbTypeEnds(key), + PrimaryKeyTableName: dbTypeEnds(refName), + ReferencesPropertyName: dbTypeEnds(propertyKey), + // should just point to first property in uml table + PrimaryKeyName: "", + IsDestination: true, + }; + models.ForeignKeyList.push(foreignKeyModel); + models.ForeignKeyList.push(primaryKeyModel); + propertyModel.IsForeignKey = true; + } + } + + tableModel.Properties.push(propertyModel); + } + } + + models.TableList.push(tableModel); + } + } + for (let i = 0; i < models.ForeignKeyList.length; i++) { + const fk = models.ForeignKeyList[i]; + if (!fk.ReferencesPropertyName) { + // match to first entry + const property = models.TableList.find( + (t) => t.Name == fk.ReferencesTableName + )?.Properties[0]; + if (property) { + models.ForeignKeyList[i].ReferencesPropertyName = property.Name; + } + } + if (!fk.PrimaryKeyName) { + // match to first entry + const property = models.TableList.find( + (t) => t.Name == fk.PrimaryKeyTableName + )?.Properties[0]; + if (property) { + models.ForeignKeyList[i].PrimaryKeyName = property.Name; + } + } + } + + return models; +} diff --git a/src/utils/sharedUtils.ts b/src/utils/sharedUtils.ts index 6e5bfd1..bf3863d 100644 --- a/src/utils/sharedUtils.ts +++ b/src/utils/sharedUtils.ts @@ -1,5 +1,6 @@ import { DbDefinition, DbRelationshipDefinition } from "@funktechno/little-mermaid-2-the-sql/lib/src/types"; import { ColumnQuantifiers, DatabaseModelResult, TableAttribute, TableEntity } from "../types/sql-plugin-types"; +import { commentColumnQuantifiers, formatKeyword } from "./constants"; /** * return text quantifiers for dialect @@ -86,6 +87,36 @@ export function getDbLabel( } +export function entityName(description?: string, format?: string): string { + let result = ""; + if (description) { + result += `${description}`; + } + if (format) { + result += ` @format ${format}`; + } + if(result){ + result = result.trim(); + result = `/** ${result} */`; + } + return result; +} + +export function getCommentIndexes(result: string) { + let hasComment = false; + if(result.indexOf(commentColumnQuantifiers.Start) !== -1 && result.indexOf(commentColumnQuantifiers.End) !== -1){ + hasComment = true; + } + const beforeIndex = hasComment ? result.indexOf(commentColumnQuantifiers.Start) : -1; + const firstSpaceIndex = hasComment ? result.indexOf(commentColumnQuantifiers.Start) + commentColumnQuantifiers.Start.length : -1; + const lastSpaceIndex = hasComment ? result.indexOf(commentColumnQuantifiers.End) -1 : -1; + + return { + beforeStart: beforeIndex, + start: firstSpaceIndex, + end: lastSpaceIndex + }; +} /** * generate db from drawio graph models * @param ui @@ -98,16 +129,48 @@ export function getMermaidDiagramDb(ui: DrawioUI, type: "mysql" | "sqlserver" | // only difference is entities is an array rather than object to allow duplicate tables const entities: Record = {}; const relationships: DbRelationshipDefinition[] = []; + // TODO: support for ts and openapi enum // build models for (const key in model.cells) { if (Object.hasOwnProperty.call(model.cells, key)) { const mxcell = model.cells[key]; if(mxcell.mxObjectId.indexOf("mxCell") !== -1) { if(mxcell.style && mxcell.style.trim().startsWith("swimlane;")){ + let entityName = mxcell.value.toString(); + let description = ""; + let formatValue = ""; + if ( + entityName?.includes(commentColumnQuantifiers.Start) && + entityName?.includes(commentColumnQuantifiers.End) + ) { + let result = entityName.toString(); + const commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex= commentIndexes.end; + entityName = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(formatKeyword) !== -1) { + const formatIndex = result.indexOf(formatKeyword); + formatValue = result.substring( + formatIndex + formatKeyword.length + ).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } const entity: TableEntity = { - name: RemoveNameQuantifiers(mxcell.value), + name: RemoveNameQuantifiers(entityName), attributes: [] as TableAttribute[], }; + const comment = generateComment(description, formatValue); + if(comment){ + entity.name += comment; + } + // const comment = for (let c = 0; c < mxcell.children.length; c++) { const col = mxcell.children[c]; if(col.mxObjectId.indexOf("mxCell") !== -1) { @@ -292,4 +355,19 @@ export function GenerateDatabaseModel(entities: Record, rel const db:DatabaseModelResult = new DatabaseModel(entities, relationships); return db; -} \ No newline at end of file +} + +export function generateComment(description?: string, formatValue?: string) { + let result = ""; + if (description) { + result += `${description}`; + } + if (formatValue) { + result += ` @format ${formatValue}`; + } + if(result){ + result = result.trim(); + result = `${commentColumnQuantifiers.Start} ${result} ${commentColumnQuantifiers.End}`; + } + return result; +} From 46f4e99202748b36b47dc728f8aec447e295ad3e Mon Sep 17 00:00:00 2001 From: lastlink Date: Sat, 6 Jul 2024 07:11:23 -0400 Subject: [PATCH 2/2] 0.0.5 release --- dist/nosql-ts.js | 507 +++++++++++++++++++++++++++++++------------ dist/nosql-ts.min.js | 12 +- dist/nosql.js | 507 +++++++++++++++++++++++++++++++------------ dist/nosql.min.js | 6 +- dist/sql.js | 96 +++++++- package.json | 2 +- 6 files changed, 834 insertions(+), 296 deletions(-) diff --git a/dist/nosql-ts.js b/dist/nosql-ts.js index 7f0bc45..e93bbe4 100644 --- a/dist/nosql-ts.js +++ b/dist/nosql-ts.js @@ -200852,9 +200852,10 @@ const ts_to_core_types_1 = require("core-types-ts/dist/lib/ts-to-core-types"); const core_types_ts_1 = require("core-types-ts"); const sharedUtils_1 = require("./utils/sharedUtils"); const constants_1 = require("./utils/constants"); +const nosqlUtils_1 = require("./utils/nosqlUtils"); /** * SQL Tools Plugin for importing and exporting typescript interfaces. - * Version: 0.0.4 + * Version: 0.0.5 */ Draw.loadPlugin(function (ui) { //Create Base div @@ -200887,7 +200888,7 @@ Draw.loadPlugin(function (ui) { function generateNoSql(type) { // get diagram model const db = (0, sharedUtils_1.getMermaidDiagramDb)(ui, type); - const openapi = dbToOpenApi(db); + const openapi = (0, nosqlUtils_1.dbToOpenApi)(db); let result = ""; if (type == "ts") { const { data: doc } = (0, core_types_json_schema_1.convertOpenApiToCoreTypes)(openapi); @@ -200901,59 +200902,6 @@ Draw.loadPlugin(function (ui) { sqlInputGenSQL.value = result; } ; - /** - * convert db to openapi - * @param db - * @returns - */ - function dbToOpenApi(db) { - var _a, _b, _c, _d, _e; - const result = { - openapi: "3.0.0", - info: { - // drawio file name? - title: "drawio nosql export", - version: constants_1.pluginVersion, - "x-comment": "Generated by from drawio uml using plugin nosql" - }, - paths: {}, - components: { - schemas: {} - } - }; - const schema = {}; - const entities = db.getEntities(); - for (const key in entities) { - if (Object.prototype.hasOwnProperty.call(entities, key)) { - const entity = entities[key]; - if (schema[key]) { - continue; - } - schema[key] = { - type: "object", - title: key, - additionalProperties: false, - properties: {} - }; - for (let p = 0; p < entity.attributes.length; p++) { - const attribute = entity.attributes[p]; - const propName = attribute.attributeName; - if (!propName || schema[key].properties[propName]) { - continue; - } - const attType = (_b = (_a = attribute.attributeType) === null || _a === void 0 ? void 0 : _a.split(" ")) !== null && _b !== void 0 ? _b : []; - const property = { - title: `${key}.${propName}`, - nullable: (_d = (_c = attribute.attributeType) === null || _c === void 0 ? void 0 : _c.includes("nullable")) !== null && _d !== void 0 ? _d : false, - type: ((_e = attType[0]) !== null && _e !== void 0 ? _e : "string") - }; - schema[key].properties[attribute.attributeName] = property; - } - } - } - result.components.schemas = schema; - return result; - } mxUtils.br(divGenSQL); const resetBtnGenSQL = mxUtils.button(mxResources.get("reset"), function () { sqlInputGenSQL.value = sqlExportDefault; @@ -201119,11 +201067,10 @@ export interface Child { tableCell.insert(rowCell); tableCell.geometry.height += 26; } - rowCell = rowCell; } ; function parseFromInput(text, type) { - var _a, _b, _c, _d; + var _a; // reset values cells = []; tableCell = null; @@ -201139,7 +201086,9 @@ export interface Child { const data = JSON.parse(text); const { data: doc } = (0, core_types_json_schema_1.convertOpenApiToCoreTypes)(data); const { data: jsonSchema } = (0, core_types_json_schema_1.convertCoreTypesToJsonSchema)(doc); - openApi = (0, core_types_json_schema_1.jsonSchemaDocumentToOpenApi)(jsonSchema, openApiOptions); + // was losing format option, just going to check if exception thrown here + (0, core_types_json_schema_1.jsonSchemaDocumentToOpenApi)(jsonSchema, openApiOptions); + openApi = data; } else if (type == "ts") { // serialize typescript classes to openapi spec @@ -201149,77 +201098,7 @@ export interface Child { } const schemas = (_a = openApi === null || openApi === void 0 ? void 0 : openApi.components) === null || _a === void 0 ? void 0 : _a.schemas; if (schemas) { - const models = { - Dialect: "nosql", - TableList: [], - PrimaryKeyList: [], - ForeignKeyList: [], - }; - for (const key in schemas) { - if (Object.prototype.hasOwnProperty.call(schemas, key)) { - const schema = schemas[key]; - const tableModel = { - Name: (0, sharedUtils_1.dbTypeEnds)(key), - Properties: [], - }; - for (const propertyKey in schema.properties) { - if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { - const property = schema.properties[propertyKey]; - const propertyModel = GeneratePropertyModel(key, propertyKey, property); - if (propertyModel.ColumnProperties.includes("object") || - propertyModel.ColumnProperties.includes("array")) { - let refName = null; - if (property.$ref) { - refName = property.$ref.split("/").pop(); - } - else if (property.items && typeof property.items == "object") { - refName = (_b = property.items.$ref) === null || _b === void 0 ? void 0 : _b.split("/").pop(); - } - if (refName) { - const primaryKeyModel = { - PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(key), - ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(refName), - PrimaryKeyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), - // should just point to first property in uml table - ReferencesPropertyName: "", - IsDestination: false - }; - const foreignKeyModel = { - ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(key), - PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(refName), - ReferencesPropertyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), - // should just point to first property in uml table - PrimaryKeyName: "", - IsDestination: true - }; - models.ForeignKeyList.push(foreignKeyModel); - models.ForeignKeyList.push(primaryKeyModel); - propertyModel.IsForeignKey = true; - } - } - tableModel.Properties.push(propertyModel); - } - } - models.TableList.push(tableModel); - } - } - for (let i = 0; i < models.ForeignKeyList.length; i++) { - const fk = models.ForeignKeyList[i]; - if (!fk.ReferencesPropertyName) { - // match to first entry - const property = (_c = models.TableList.find(t => t.Name == fk.ReferencesTableName)) === null || _c === void 0 ? void 0 : _c.Properties[0]; - if (property) { - models.ForeignKeyList[i].ReferencesPropertyName = property.Name; - } - } - if (!fk.PrimaryKeyName) { - // match to first entry - const property = (_d = models.TableList.find(t => t.Name == fk.PrimaryKeyTableName)) === null || _d === void 0 ? void 0 : _d.Properties[0]; - if (property) { - models.ForeignKeyList[i].PrimaryKeyName = property.Name; - } - } - } + const models = (0, nosqlUtils_1.ConvertOpenApiToDatabaseModel)(schemas); foreignKeyList = models.ForeignKeyList; primaryKeyList = models.PrimaryKeyList; tableList = models.TableList; @@ -201395,13 +201274,192 @@ export interface Child { } } }); + +},{"./utils/constants":49,"./utils/nosqlUtils":50,"./utils/sharedUtils":51,"core-types-json-schema":2,"core-types-ts":25,"core-types-ts/dist/lib/ts-to-core-types":29}],49:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.validEnumTypes = exports.enumKeyword = exports.formatKeyword = exports.commentColumnQuantifiers = exports.pluginVersion = void 0; +// export sql methods +exports.pluginVersion = "0.0.5"; +exports.commentColumnQuantifiers = { + Start: "/**", + End: "*/", +}; +exports.formatKeyword = "@format"; +exports.enumKeyword = "enum"; +exports.validEnumTypes = ["string", "number", "integer", "boolean"]; + +},{}],50:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.dbToOpenApi = dbToOpenApi; +exports.GeneratePropertyModel = GeneratePropertyModel; +exports.ConvertOpenApiToDatabaseModel = ConvertOpenApiToDatabaseModel; +const constants_1 = require("./constants"); +const sharedUtils_1 = require("./sharedUtils"); +/** + * convert db to openapi + * @param db + * @returns + */ +function dbToOpenApi(db) { + var _a, _b, _c, _d, _e, _f, _g; + const result = { + openapi: "3.0.0", + info: { + // drawio file name? + title: "drawio nosql export", + version: constants_1.pluginVersion, + "x-comment": "Generated by from drawio uml using plugin nosql", + }, + paths: {}, + components: { + schemas: {}, + }, + }; + const schema = {}; + const entities = db.getEntities(); + for (const key in entities) { + if (Object.prototype.hasOwnProperty.call(entities, key)) { + let schemaKey = key; + const entity = entities[key]; + let commentIndexes = (0, sharedUtils_1.getCommentIndexes)(key); + let description = ""; + let formatValue = ""; + if (commentIndexes.start > -1 && commentIndexes.end > -1) { + let result = schemaKey.toString().trim(); + commentIndexes = (0, sharedUtils_1.getCommentIndexes)(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + schemaKey = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex).trim(); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result.substring(formatIndex + constants_1.formatKeyword.length).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + } + if (schema[schemaKey]) { + continue; + } + schema[schemaKey] = { + type: "object", + title: schemaKey, + additionalProperties: false, + properties: {}, + }; + if (description) { + schema[schemaKey].description = description.trim(); + } + if (formatValue) { + schema[schemaKey].format = formatValue.trim(); + } + for (let p = 0; p < entity.attributes.length; p++) { + const attribute = entity.attributes[p]; + const propName = attribute.attributeName.trim(); + if (!propName || schema[schemaKey].properties[propName]) { + continue; + } + // TODO: trim double spaces + const attType = (_b = (_a = attribute.attributeType) === null || _a === void 0 ? void 0 : _a.trim().split(" ")) !== null && _b !== void 0 ? _b : []; + // check if enum + let isEnum = false; + let type = ((_c = attType[0]) !== null && _c !== void 0 ? _c : "string"); + if (propName.indexOf(constants_1.enumKeyword) !== -1) { + const splitPropName = propName.split(" "); + if (splitPropName.length == 2 && + constants_1.validEnumTypes.indexOf(splitPropName[0]) !== -1 && + splitPropName[1] == constants_1.enumKeyword) { + isEnum = true; + type = splitPropName[0]; + } + } + // extract desciption /** asdf */ + let description = ""; + let formatValue = ""; + let enumValues = null; + if (((_d = attribute.attributeType) === null || _d === void 0 ? void 0 : _d.includes(constants_1.commentColumnQuantifiers.Start)) && + ((_e = attribute.attributeType) === null || _e === void 0 ? void 0 : _e.includes(constants_1.commentColumnQuantifiers.End))) { + let result = attribute.attributeType; + const commentIndexes = (0, sharedUtils_1.getCommentIndexes)(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + const enumRaw = result.substring(0, commentIndexes.beforeStart).trim(); + if (enumRaw) { + try { + enumValues = JSON.parse(enumRaw); + } + catch (error) { + console.log(`Error parsing raw enum values: ${enumRaw} Message: ${JSON.stringify(error)}`); + } + } + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result + .substring(formatIndex + constants_1.formatKeyword.length) + .trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } + if (isEnum) { + if (schema[schemaKey].enum) + continue; + if (enumValues) { + schema[schemaKey].enum = enumValues; + } + if (description) { + schema[schemaKey].description = description.trim(); + } + if (formatValue) { + schema[schemaKey].format = formatValue.trim(); + } + schema[schemaKey].type = type; + } + else { + const property = { + title: `${key}.${propName}`, + nullable: (_g = (_f = attribute.attributeType) === null || _f === void 0 ? void 0 : _f.includes("nullable")) !== null && _g !== void 0 ? _g : false, + type: type, + }; + if (description) { + property.description = description.trim(); + } + if (formatValue) { + property.format = formatValue.trim(); + } + schema[schemaKey].properties[attribute.attributeName] = property; + } + } + if (Object.keys(schema[schemaKey].properties).length === 0) { + delete schema[schemaKey].properties; + } + } + } + result.components.schemas = schema; + return result; +} // TODO: may need to make recursive for when schema property items is array function GeneratePropertyModel(tableName, propertyName, property) { var _a; let columnProperties = ((_a = property.type) !== null && _a !== void 0 ? _a : "object").toString(); - if (property.nullable) { + if (property.enum) { + columnProperties = `${JSON.stringify(property.enum)}`; + } + else if (property.nullable) { columnProperties += " nullable"; } + const description = (0, sharedUtils_1.generateComment)(property.description, property.format); + if (description) { + columnProperties += ` ${description}`; + } const result = { Name: (0, sharedUtils_1.dbTypeEnds)(propertyName), IsPrimaryKey: false, @@ -201412,15 +201470,106 @@ function GeneratePropertyModel(tableName, propertyName, property) { }; return result; } +function ConvertOpenApiToDatabaseModel(schemas) { + var _a, _b, _c; + const models = { + Dialect: "nosql", + TableList: [], + PrimaryKeyList: [], + ForeignKeyList: [], + }; + for (const key in schemas) { + if (Object.prototype.hasOwnProperty.call(schemas, key)) { + const schema = schemas[key]; + const tableModel = { + Name: (0, sharedUtils_1.dbTypeEnds)(key), + Properties: [], + }; + if (schema.enum) { + const enumList = schema.enum; + // serialize to string enum [values] + const propertyKey = `${schema.type} enum`; + const property = { + enum: enumList, + }; + if (schema.description) { + property.description = schema.description; + } + if (schema.format) { + property.format = schema.format; + } + const propertyModel = GeneratePropertyModel(key, propertyKey, property); + tableModel.Properties.push(propertyModel); + } + else { + const comment = (0, sharedUtils_1.generateComment)(schema.description, schema.format); + if (comment) { + tableModel.Name += ` ${comment}`; + } + } + // schema level comments? should these be in a row or table name? + for (const propertyKey in schema.properties) { + if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { + const property = schema.properties[propertyKey]; + const propertyModel = GeneratePropertyModel(key, propertyKey, property); + if (propertyModel.ColumnProperties.includes("object") || + propertyModel.ColumnProperties.includes("array")) { + let refName = null; + if (property.$ref) { + refName = property.$ref.split("/").pop(); + } + else if (property.items && typeof property.items == "object") { + refName = (_a = property.items.$ref) === null || _a === void 0 ? void 0 : _a.split("/").pop(); + } + if (refName) { + const primaryKeyModel = { + PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(key), + ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(refName), + PrimaryKeyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), + // should just point to first property in uml table + ReferencesPropertyName: "", + IsDestination: false, + }; + const foreignKeyModel = { + ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(key), + PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(refName), + ReferencesPropertyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), + // should just point to first property in uml table + PrimaryKeyName: "", + IsDestination: true, + }; + models.ForeignKeyList.push(foreignKeyModel); + models.ForeignKeyList.push(primaryKeyModel); + propertyModel.IsForeignKey = true; + } + } + tableModel.Properties.push(propertyModel); + } + } + models.TableList.push(tableModel); + } + } + for (let i = 0; i < models.ForeignKeyList.length; i++) { + const fk = models.ForeignKeyList[i]; + if (!fk.ReferencesPropertyName) { + // match to first entry + const property = (_b = models.TableList.find((t) => t.Name == fk.ReferencesTableName)) === null || _b === void 0 ? void 0 : _b.Properties[0]; + if (property) { + models.ForeignKeyList[i].ReferencesPropertyName = property.Name; + } + } + if (!fk.PrimaryKeyName) { + // match to first entry + const property = (_c = models.TableList.find((t) => t.Name == fk.PrimaryKeyTableName)) === null || _c === void 0 ? void 0 : _c.Properties[0]; + if (property) { + models.ForeignKeyList[i].PrimaryKeyName = property.Name; + } + } + } + return models; +} -},{"./utils/constants":49,"./utils/sharedUtils":50,"core-types-json-schema":2,"core-types-ts":25,"core-types-ts/dist/lib/ts-to-core-types":29}],49:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.pluginVersion = void 0; -// export sql methods -exports.pluginVersion = "0.0.4"; - -},{}],50:[function(require,module,exports){ +},{"./constants":49,"./sharedUtils":51}],51:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetColumnQuantifiers = GetColumnQuantifiers; @@ -201428,7 +201577,12 @@ exports.removeHtml = removeHtml; exports.dbTypeEnds = dbTypeEnds; exports.RemoveNameQuantifiers = RemoveNameQuantifiers; exports.getDbLabel = getDbLabel; +exports.entityName = entityName; +exports.getCommentIndexes = getCommentIndexes; exports.getMermaidDiagramDb = getMermaidDiagramDb; +exports.GenerateDatabaseModel = GenerateDatabaseModel; +exports.generateComment = generateComment; +const constants_1 = require("./constants"); /** * return text quantifiers for dialect * @returns json @@ -201494,6 +201648,34 @@ function getDbLabel(label, columnQuantifiers) { }; return attribute; } +function entityName(description, format) { + let result = ""; + if (description) { + result += `${description}`; + } + if (format) { + result += ` @format ${format}`; + } + if (result) { + result = result.trim(); + result = `/** ${result} */`; + } + return result; +} +function getCommentIndexes(result) { + let hasComment = false; + if (result.indexOf(constants_1.commentColumnQuantifiers.Start) !== -1 && result.indexOf(constants_1.commentColumnQuantifiers.End) !== -1) { + hasComment = true; + } + const beforeIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) : -1; + const firstSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) + constants_1.commentColumnQuantifiers.Start.length : -1; + const lastSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.End) - 1 : -1; + return { + beforeStart: beforeIndex, + start: firstSpaceIndex, + end: lastSpaceIndex + }; +} /** * generate db from drawio graph models * @param ui @@ -201506,16 +201688,43 @@ function getMermaidDiagramDb(ui, type) { // only difference is entities is an array rather than object to allow duplicate tables const entities = {}; const relationships = []; + // TODO: support for ts and openapi enum // build models for (const key in model.cells) { if (Object.hasOwnProperty.call(model.cells, key)) { const mxcell = model.cells[key]; if (mxcell.mxObjectId.indexOf("mxCell") !== -1) { if (mxcell.style && mxcell.style.trim().startsWith("swimlane;")) { + let entityName = mxcell.value.toString(); + let description = ""; + let formatValue = ""; + if ((entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.Start)) && + (entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.End))) { + let result = entityName.toString(); + const commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + entityName = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result.substring(formatIndex + constants_1.formatKeyword.length).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } const entity = { - name: RemoveNameQuantifiers(mxcell.value), + name: RemoveNameQuantifiers(entityName), attributes: [], }; + const comment = generateComment(description, formatValue); + if (comment) { + entity.name += comment; + } + // const comment = for (let c = 0; c < mxcell.children.length; c++) { const col = mxcell.children[c]; if (col.mxObjectId.indexOf("mxCell") !== -1) { @@ -201669,6 +201878,10 @@ function getMermaidDiagramDb(ui, type) { } } } + const db = GenerateDatabaseModel(entities, relationships); + return db; +} +function GenerateDatabaseModel(entities, relationships) { class DatabaseModel { constructor(entities, relationships) { this.entities = entities; @@ -201684,5 +201897,19 @@ function getMermaidDiagramDb(ui, type) { const db = new DatabaseModel(entities, relationships); return db; } +function generateComment(description, formatValue) { + let result = ""; + if (description) { + result += `${description}`; + } + if (formatValue) { + result += ` @format ${formatValue}`; + } + if (result) { + result = result.trim(); + result = `${constants_1.commentColumnQuantifiers.Start} ${result} ${constants_1.commentColumnQuantifiers.End}`; + } + return result; +} -},{}]},{},[48]); +},{"./constants":49}]},{},[48]); diff --git a/dist/nosql-ts.min.js b/dist/nosql-ts.min.js index a34142b..106d2af 100644 --- a/dist/nosql-ts.min.js +++ b/dist/nosql-ts.min.js @@ -347,17 +347,17 @@ Projects:: `;let t=0;r=e=>{n=(n+=` Project '${e.projectName}' (${A1e[e.projectKind]}) ${t} `)+e.filesToString(!0)+"\n-----------------------------------------------\n",t++};this.projectService.externalProjects.forEach(r),this.projectService.configuredProjects.forEach(r),this.projectService.inferredProjects.forEach(r)}}this.logger.msg(n,"Err")}send(e){"event"!==e.type||this.canUseEvents?this.writeMessage(e):this.logger.hasLevel(3)&&this.logger.info("Session does not support events: ignored event: "+uW(e))}writeMessage(e){e=ive(e,this.logger,this.byteLength,this.host.newLine);null!=er&&er.logEvent("Response message size: "+e.length),this.host.write(e)}event(e,t){this.send(ove(t,e))}doOutput(n,i,e,t,r){i={seq:0,type:"response",command:i,request_seq:e,success:t,performanceData:this.performanceData};if(t){let r;if(i3(n))i.body=n,r=n.metadata,delete n.metadata;else if("object"==typeof n)if(n.metadata){let{metadata:e,...t}=n;i.body=t,r=e}else i.body=n;else i.body=n;r&&(i.metadata=r)}else Y4.assert(void 0===n);r&&(i.message=r),this.send(i)}semanticCheck(e,t){null!=Z4&&Z4.push(Z4.Phase.Session,"semanticCheck",{file:e,configFilePath:t.canonicalConfigFilePath});var r=Yye(t,e)?Z0e:t.getLanguageService().getSemanticDiagnostics(e).filter(e=>!!e.file);this.sendDiagnosticsEvent(e,t,r,"semanticDiag"),null!=Z4&&Z4.pop()}syntacticCheck(e,t){null!=Z4&&Z4.push(Z4.Phase.Session,"syntacticCheck",{file:e,configFilePath:t.canonicalConfigFilePath}),this.sendDiagnosticsEvent(e,t,t.getLanguageService().getSyntacticDiagnostics(e),"syntaxDiag"),null!=Z4&&Z4.pop()}suggestionCheck(e,t){null!=Z4&&Z4.push(Z4.Phase.Session,"suggestionCheck",{file:e,configFilePath:t.canonicalConfigFilePath}),this.sendDiagnosticsEvent(e,t,t.getLanguageService().getSuggestionDiagnostics(e),"suggestionDiag"),null!=Z4&&Z4.pop()}sendDiagnosticsEvent(t,r,e,n){try{this.event({file:t,diagnostics:e.map(e=>Zye(t,r,e))},n)}catch(e){this.logError(e,n)}}updateErrorCheck(n,e,t,i=!0){Y4.assert(!this.suppressDiagnosticEvents);let a=this.changeSeq,r=Math.min(t,200),o=0,s=()=>{o++,e.length>o&&n.delay("checkOne",r,c)},c=()=>{if(this.changeSeq===a){let r=e[o];if(a3(r)&&!(r=this.toPendingErrorCheck(r)))s();else{let{fileName:e,project:t}=r;jye(t),t.containsFile(e,i)&&(this.syntacticCheck(e,t),this.changeSeq===a)&&(0!==t.projectService.serverMode?s():n.immediate("semanticCheck",()=>{this.semanticCheck(e,t),this.changeSeq===a&&(this.getPreferences(e).disableSuggestions?s():n.immediate("suggestionCheck",()=>{this.suggestionCheck(e,t),s()}))}))}}};e.length>o&&this.changeSeq===a&&n.delay("checkOne",t,c)}cleanProjects(e,t){if(t){this.logger.info("cleaning "+e);for(var r of t)r.getLanguageService(!1).cleanupSemanticCache(),r.cleanupProgram()}}cleanup(){this.cleanProjects("inferred projects",this.projectService.inferredProjects),this.cleanProjects("configured projects",ZT(this.projectService.configuredProjects.values())),this.cleanProjects("external projects",this.projectService.externalProjects),this.host.gc&&(this.logger.info("host.gc()"),this.host.gc())}getEncodedSyntacticClassifications(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e);return r.getEncodedSyntacticClassifications(t,e)}getEncodedSemanticClassifications(e){var{file:t,project:r}=this.getFileAndProject(e),n="2020"===e.format?"2020":"original";return r.getLanguageService().getEncodedSemanticClassifications(t,e,n)}getProject(e){return void 0===e?void 0:this.projectService.findProject(e)}getConfigFileAndProject(e){var t=this.getProject(e.projectFileName),e=r1e(e.file);return{configFile:t&&t.hasConfigFile(e)?e:void 0,project:t}}getConfigFileDiagnostics(t,e,r){e=NT(LT(e.getAllProjectErrors(),e.getLanguageService().getCompilerOptionsDiagnostics()),e=>!!e.file&&e.file.fileName===t);return r?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(e):$4(e,e=>rve(e,!1))}convertToDiagnosticsWithLinePositionFromDiagnosticFile(e){return e.map(e=>({message:lJ(e.messageText,this.host.newLine),start:e.start,length:e.length,category:Fn(e),code:e.code,source:e.source,startLocation:e.file&&tve(O3(e.file,e.start)),endLocation:e.file&&tve(O3(e.file,e.start+e.length)),reportsUnnecessary:e.reportsUnnecessary,reportsDeprecated:e.reportsDeprecated,relatedInformation:$4(e.relatedInformation,eve)}))}getCompilerOptionsDiagnostics(e){e=this.getProject(e.projectFileName);return this.convertToDiagnosticsWithLinePosition(NT(e.getLanguageService().getCompilerOptionsDiagnostics(),e=>!e.file),void 0)}convertToDiagnosticsWithLinePosition(e,t){return e.map(e=>({message:lJ(e.messageText,this.host.newLine),start:e.start,length:e.length,category:Fn(e),code:e.code,source:e.source,startLocation:t&&t.positionToLineOffset(e.start),endLocation:t&&t.positionToLineOffset(e.start+e.length),reportsUnnecessary:e.reportsUnnecessary,reportsDeprecated:e.reportsDeprecated,relatedInformation:$4(e.relatedInformation,eve)}))}getDiagnosticsWorker(e,t,r,n){let{project:i,file:a}=this.getFileAndProject(e);return t&&Yye(i,a)?Z0e:(e=i.getScriptInfoForNormalizedPath(a),t=r(i,a),n?this.convertToDiagnosticsWithLinePosition(t,e):t.map(e=>Zye(a,i,e)))}getDefinition(e,t){var{file:r,project:n}=this.getFileAndProject(e),e=this.getPositionInFile(e,r),r=this.mapDefinitionInfoLocations(n.getLanguageService().getDefinitionAtPosition(r,e)||Z0e,n);return t?this.mapDefinitionInfo(r,n):r.map(Hve.mapToOriginalLocation)}mapDefinitionInfoLocations(e,r){return e.map(e=>{var t=fve(e,r);return t?{...t,containerKind:e.containerKind,containerName:e.containerName,kind:e.kind,name:e.name,failedAliasResolution:e.failedAliasResolution,...e.unverified&&{unverified:e.unverified}}:e})}getDefinitionAndBoundSpan(e,t){var{file:r,project:n}=this.getFileAndProject(e),e=this.getPositionInFile(e,r),i=Y4.checkDefined(n.getScriptInfo(r)),r=n.getLanguageService().getDefinitionAndBoundSpan(r,e);return r&&r.definitions?(e=this.mapDefinitionInfoLocations(r.definitions,n),r=r["textSpan"],t?{definitions:this.mapDefinitionInfo(e,n),textSpan:yve(r,i)}:{definitions:e.map(Hve.mapToOriginalLocation),textSpan:r}):{definitions:Z0e,textSpan:void 0}}findSourceDefinition(e){let r,{file:i,project:c}=this.getFileAndProject(e),a=this.getPositionInFile(e,i);e=c.getLanguageService().getDefinitionAtPosition(i,a);let n=this.mapDefinitionInfoLocations(e||Z0e,c).slice();if(0===this.projectService.serverMode&&(!X4(n,e=>r1e(e.fileName)!==i&&!e.isAmbient)||X4(n,e=>!!e.failedAliasResolution))){let t=oe(e=>e.textSpan.start,bG(this.host.useCaseSensitiveFileNames));null!=n&&n.forEach(e=>t.add(e));var o=c.getNoDtsResolutionProject(i),s=o.getLanguageService(),e=null==(r=s.getDefinitionAtPosition(i,a,!0,!1))?void 0:r.filter(e=>r1e(e.fileName)!==i);if(X4(e))for(var l of e){if(l.unverified){var _=function(e,t,r){e=r.getSourceFile(e.fileName);if(e){var n=XH(t.getSourceFile(i),a),t=t.getTypeChecker().getSymbolAtLocation(n),n=t&&F7(t,276);if(n)return g((null==(t=n.propertyName)?void 0:t.text)||n.name.text,e,r)}}(l,c.getLanguageService().getProgram(),s.getProgram());if(X4(_)){for(var u of _)t.add(u);continue}}t.add(l)}else{var d,e=n.filter(e=>r1e(e.fileName)!==i&&e.isAmbient);for(d of X4(e)?e:function(){let t=c.getLanguageService(),e=t.getProgram(),r=XH(e.getSourceFile(i),a);if((k7(r)||uT(r))&&lD(r.parent))return uf(r,e=>{return e!==r&&X4(e=null==(e=t.getDefinitionAtPosition(i,e.getStart(),!0,!1))?void 0:e.filter(e=>r1e(e.fileName)!==i&&e.isAmbient).map(e=>({fileName:e.fileName,name:Kw(r)})))?e:void 0})||Z0e;return Z0e}()){var p=function(e,r,n){var i=dg(e);if(i&&e.lastIndexOf(fO)===i.topLevelNodeModulesIndex){var a=e.substring(0,i.packageRootIndex),o=null==(o=c.getModuleResolutionCache())?void 0:o.getPackageJsonInfoCache(),s=c.getCompilationSettings(),a=DO(E3(a+"/package.json",c.getCurrentDirectory()),NO(o,c,s));if(!a)return;var o=wO(a,{moduleResolution:2},c,c.getModuleResolutionCache()),s=$O(XO(e.substring(i.topLevelPackageNameIndex+1,i.packageRootIndex)));let t=c.toPath(e);return o&&X4(o,e=>c.toPath(e)===t)?null==(a=n.resolutionCache.resolveSingleModuleNameWithoutWatching(s,r).resolvedModule)?void 0:a.resolvedFileName:(o=e.substring(i.packageRootIndex+1),a=s+"/"+qm(o),null==(e=n.resolutionCache.resolveSingleModuleNameWithoutWatching(a,r).resolvedModule)?void 0:e.resolvedFileName)}}(d.fileName,i,o);if(p){var f=this.projectService.getOrCreateScriptInfoNotOpenedByClient(p,o.currentDirectory,o.directoryStructureHost,!1);if(f){o.containsScriptInfo(f)||(o.addRoot(f),o.updateGraph());var m,f=s.getProgram(),p=Y4.checkDefined(f.getSourceFile(p));for(m of g(d.name,p,f))t.add(m)}}}}n=ZT(t.values())}return n=n.filter(e=>!e.isAmbient&&!e.failedAliasResolution),this.mapDefinitionInfo(n,c);function g(e,t,r){return AT(ope.Core.getTopMostDeclarationNamesInFile(e,t),e=>{var t=r.getTypeChecker().getSymbolAtLocation(e),e=Su(e);if(t&&e)return mfe.createDefinitionInfo(e,r.getTypeChecker(),t,e,!0)})}}getEmitOutput(e){var{file:t,project:r}=this.getFileAndProject(e);return r.shouldEmitFile(r.getScriptInfo(t))?(r=r.getLanguageService().getEmitOutput(t),e.richResponse?{...r,diagnostics:e.includeLinePosition?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(r.diagnostics):r.diagnostics.map(e=>rve(e,!0))}:r):{emitSkipped:!0,outputFiles:[],diagnostics:[]}}mapJSDocTagInfo(e,t,r){return e?e.map(e=>{return{...e,text:r?this.mapDisplayParts(e.text,t):null==(e=e.text)?void 0:e.map(e=>e.text).join("")}}):[]}mapDisplayParts(e,t){return e?e.map(e=>"linkName"!==e.kind?e:{...e,target:this.toFileSpan(e.target.fileName,e.target.textSpan,t)}):[]}mapSignatureHelpItems(e,t,r){return e.map(e=>({...e,documentation:this.mapDisplayParts(e.documentation,t),parameters:e.parameters.map(e=>({...e,documentation:this.mapDisplayParts(e.documentation,t)})),tags:this.mapJSDocTagInfo(e.tags,t,r)}))}mapDefinitionInfo(e,t){return e.map(e=>({...this.toFileSpanWithContext(e.fileName,e.textSpan,e.contextSpan,t),...e.unverified&&{unverified:e.unverified}}))}static mapToOriginalLocation(e){return e.originalFileName?(Y4.assert(void 0!==e.originalTextSpan,"originalTextSpan should be present if originalFileName is"),{...e,fileName:e.originalFileName,textSpan:e.originalTextSpan,targetFileName:e.fileName,targetTextSpan:e.textSpan,contextSpan:e.originalContextSpan,targetContextSpan:e.contextSpan}):e}toFileSpan(e,t,r){var r=r.getLanguageService(),n=r.toLineColumnOffset(e,t.start),r=r.toLineColumnOffset(e,J3(t));return{file:e,start:{line:n.line+1,offset:n.character+1},end:{line:r.line+1,offset:r.character+1}}}toFileSpanWithContext(e,t,r,n){t=this.toFileSpan(e,t,n),e=r&&this.toFileSpan(e,r,n);return e?{...t,contextStart:e.start,contextEnd:e.end}:t}getTypeDefinition(e){var{file:t,project:r}=this.getFileAndProject(e),e=this.getPositionInFile(e,t),t=this.mapDefinitionInfoLocations(r.getLanguageService().getTypeDefinitionAtPosition(t,e)||Z0e,r);return this.mapDefinitionInfo(t,r)}mapImplementationLocations(e,r){return e.map(e=>{var t=fve(e,r);return t?{...t,kind:e.kind,displayParts:e.displayParts}:e})}getImplementation(e,t){let{file:r,project:n}=this.getFileAndProject(e);e=this.getPositionInFile(e,r),e=this.mapImplementationLocations(n.getLanguageService().getImplementationAtPosition(r,e)||Z0e,n);return t?e.map(({fileName:e,textSpan:t,contextSpan:r})=>this.toFileSpanWithContext(e,t,r,n)):e.map(Hve.mapToOriginalLocation)}getSyntacticDiagnosticsSync(e){var t=this.getConfigFileAndProject(e)["configFile"];return t?Z0e:this.getDiagnosticsWorker(e,!1,(e,t)=>e.getLanguageService().getSyntacticDiagnostics(t),!!e.includeLinePosition)}getSemanticDiagnosticsSync(e){var{configFile:t,project:r}=this.getConfigFileAndProject(e);return t?this.getConfigFileDiagnostics(t,r,!!e.includeLinePosition):this.getDiagnosticsWorker(e,!0,(e,t)=>e.getLanguageService().getSemanticDiagnostics(t).filter(e=>!!e.file),!!e.includeLinePosition)}getSuggestionDiagnosticsSync(e){var t=this.getConfigFileAndProject(e)["configFile"];return t?Z0e:this.getDiagnosticsWorker(e,!0,(e,t)=>e.getLanguageService().getSuggestionDiagnostics(t),!!e.includeLinePosition)}getJsxClosingTag(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=this.getPositionInFile(e,t),r=r.getJsxClosingTagAtPosition(t,e);return void 0===r?void 0:{newText:r.newText,caretOffset:0}}getLinkedEditingRange(e){var t,{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=this.getPositionInFile(e,r),n=n.getLinkedEditingRangeAtPosition(r,e),e=this.projectService.getScriptInfoForNormalizedPath(r);if(void 0!==e&&void 0!==n)return t=e,e=(r=n).ranges.map(e=>({start:t.positionToLineOffset(e.start),end:t.positionToLineOffset(e.start+e.length)})),r.wordPattern?{ranges:e,wordPattern:r.wordPattern}:{ranges:e}}getDocumentHighlights(e,t){let{file:r,project:i}=this.getFileAndProject(e);var n=this.getPositionInFile(e,r),n=i.getLanguageService().getDocumentHighlights(r,n,e.filesToSearch);return n?t?n.map(({fileName:e,highlightSpans:t})=>{let n=i.getScriptInfo(e);return{file:e,highlightSpans:t.map(({textSpan:e,kind:t,contextSpan:r})=>({...vve(e,r,n),kind:t}))}}):n:Z0e}provideInlayHints(e){var{file:t,project:r}=this.getFileAndProject(e);let n=this.projectService.getScriptInfoForNormalizedPath(t);return r.getLanguageService().provideInlayHints(t,e,this.getPreferences(t)).map(e=>{var{position:t,displayParts:r}=e;return{...e,position:n.positionToLineOffset(t),displayParts:null==r?void 0:r.map(({text:e,span:t,file:r})=>{var n;return t?(Y4.assertIsDefined(r,"Target file should be defined together with its span."),{text:e,span:{start:(n=this.projectService.getScriptInfo(r)).positionToLineOffset(t.start),end:n.positionToLineOffset(t.start+t.length),file:r}}):{text:e}})}})}mapCode(e){var t=this.getHostFormatOptions(),r=this.getHostPreferences(),{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(e);let a=this.projectService.getScriptInfoForNormalizedPath(n);var o=null==(o=e.mapping.focusLocations)?void 0:o.map(e=>e.map(e=>{var t=a.lineOffsetToPosition(e.start.line,e.start.offset);return{start:t,length:a.lineOffsetToPosition(e.end.line,e.end.offset)-t}})),i=i.mapCode(n,e.mapping.contents,o,t,r);return this.mapTextChangesToCodeEdits(i)}setCompilerOptionsForInferredProjects(e){this.projectService.setCompilerOptionsForInferredProjects(e.options,e.projectRootPath)}getProjectInfo(e){return this.getProjectInfoWorker(e.file,e.projectFileName,e.needFileNameList,!1)}getProjectInfoWorker(e,t,r,n){e=this.getFileAndProjectWorker(e,t).project,jye(e),t={configFileName:e.getProjectName(),languageServiceDisabled:!e.languageServiceEnabled,fileNames:r?e.getFileNames(!1,n):void 0};return t}getRenameInfo(e){var{file:t,project:r}=this.getFileAndProject(e),e=this.getPositionInFile(e,t),n=this.getPreferences(t);return r.getLanguageService().getRenameInfo(t,e,n)}getProjects(e,t,r){let n,i;if(e.projectFileName){var a=this.getProject(e.projectFileName);a&&(n=[a])}else{a=t?this.projectService.getScriptInfoEnsuringProjectsUptoDate(e.file):this.projectService.getScriptInfo(e.file);if(!a)return r?Z0e:(this.projectService.logErrorForScriptInfoNotFound(e.file),Q0e.ThrowNoProject());t||this.projectService.ensureDefaultProjectForFile(a),n=a.containingProjects,i=this.projectService.getSymlinkedProjects(a)}return n=NT(n,e=>e.languageServiceEnabled&&!e.isOrphan()),r||n&&n.length||i?i?{projects:n,symLinkedProjects:i}:n:(this.projectService.logErrorForScriptInfoNotFound(e.file??e.projectFileName),Q0e.ThrowNoProject())}getDefaultProject(e){if(e.projectFileName){var t=this.getProject(e.projectFileName);if(t)return t;if(!e.file)return Q0e.ThrowNoProject()}return this.projectService.getScriptInfo(e.file).getDefaultProject()}getRenameLocations(e,t){var r=r1e(e.file),n=this.getPositionInFile(e,r),i=this.getProjects(e),a=this.getDefaultProject(e),o=this.getPreferences(r),r=this.mapRenameInfo(a.getLanguageService().getRenameInfo(r,n,o),Y4.checkDefined(this.projectService.getScriptInfo(r)));return r.canRename?(i=function(e,t,r,n,i,a,o){if(i3(e=_ve(e,t,r,!0,(e,t)=>e.getLanguageService().findRenameLocations(t.fileName,t.pos,n,i,a),(e,t)=>t(dve(e)))))return e;let s=[],c=sve(o);return e.forEach((e,t)=>{for(var r of e)c.has(r)||pve(dve(r),t)||(s.push(r),c.add(r))}),s}(i,a,{fileName:e.file,pos:n},!!e.findInStrings,!!e.findInComments,o,this.host.useCaseSensitiveFileNames),t?{info:r,locs:this.toSpanGroups(i)}:i):t?{info:r,locs:[]}:[]}mapRenameInfo(e,t){var r,n,i,a,o,s,c;return e.canRename?({canRename:r,fileToRename:n,displayName:i,fullDisplayName:a,kind:o,kindModifiers:s,triggerSpan:c}=e,{canRename:r,fileToRename:n,displayName:i,fullDisplayName:a,kind:o,kindModifiers:s,triggerSpan:yve(c,t)}):e}toSpanGroups(e){var t,r,n,i,a,o,s,c=new Map;for({fileName:t,textSpan:r,contextSpan:n,originalContextSpan:i,originalTextSpan:a,originalFileName:o,...s}of e){let e=c.get(t);e||c.set(t,e={file:t,locs:[]});var l=Y4.checkDefined(this.projectService.getScriptInfo(t));e.locs.push({...vve(r,n,l),...s})}return ZT(c.values())}getReferences(e,t){var r=r1e(e.file),n=this.getProjects(e),i=this.getPositionInFile(e,r),n=cve(n,this.getDefaultProject(e),{fileName:e.file,pos:i},this.host.useCaseSensitiveFileNames,this.logger);if(!t)return n;let a=this.getPreferences(r);t=this.getDefaultProject(e),e=t.getScriptInfoForNormalizedPath(r),t=t.getLanguageService().getQuickInfoAtPosition(r,i),r=t?Ire(t.displayParts):"",i=t&&t.textSpan,t=i?e.positionToLineOffset(i.start).offset:0,e=i?e.getSnapshot().getText(i.start,J3(i)):"";return{refs:FT(n,e=>e.references.map(e=>Sve(this.projectService,e,a))),symbolName:e,symbolStartOffset:t,symbolDisplayString:r}}getFileReferences(e,t){var r=this.getProjects(e);let n=e.file,i=this.getPreferences(r1e(n)),a=[],o=sve(this.host.useCaseSensitiveFileNames);return lve(r,void 0,e=>{if(!e.getCancellationToken().isCancellationRequested()){e=e.getLanguageService().getFileReferences(n);if(e)for(var t of e)o.has(t)||(a.push(t),o.add(t))}}),t?{refs:a.map(e=>Sve(this.projectService,e,i)),symbolName:`"${e.file}"`}:a}openClientFile(e,t,r,n){this.projectService.openClientFileWithNormalizedPath(e,t,r,!1,n)}getPosition(e,t){return void 0!==e.position?e.position:t.lineOffsetToPosition(e.line,e.offset)}getPositionInFile(e,t){t=this.projectService.getScriptInfoForNormalizedPath(t);return this.getPosition(e,t)}getFileAndProject(e){return this.getFileAndProjectWorker(e.file,e.projectFileName)}getFileAndLanguageServiceForSyntacticOperation(e){var{file:e,project:t}=this.getFileAndProject(e);return{file:e,languageService:t.getLanguageService(!1)}}getFileAndProjectWorker(e,t){e=r1e(e);return{file:e,project:this.getProject(t)||this.projectService.ensureDefaultProjectForFile(e)}}getOutliningSpans(e,t){var{file:e,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),r=r.getOutliningSpans(e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(e);return r.map(e=>({textSpan:yve(e.textSpan,t),hintSpan:yve(e.hintSpan,t),bannerText:e.bannerText,autoCollapse:e.autoCollapse,kind:e.kind}))}return r}getTodoComments(e){var{file:t,project:r}=this.getFileAndProject(e);return r.getLanguageService().getTodoComments(t,e.descriptors)}getDocCommentTemplate(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=this.getPositionInFile(e,t);return r.getDocCommentTemplateAtPosition(t,e,this.getPreferences(t),this.getFormatOptions(t))}getSpanOfEnclosingComment(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),n=e.onlyMultiLine,e=this.getPositionInFile(e,t);return r.getSpanOfEnclosingComment(t,e,n)}getIndentation(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),n=this.getPositionInFile(e,t),e=e.options?mye(e.options):this.getFormatOptions(t);return{position:n,indentation:r.getIndentationAtPosition(t,n,e)}}getBreakpointStatement(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=this.getPositionInFile(e,t);return r.getBreakpointStatementAtPosition(t,e)}getNameOrDottedNameSpan(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=this.getPositionInFile(e,t);return r.getNameOrDottedNameSpan(t,e,e)}isValidBraceCompletion(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),n=this.getPositionInFile(e,t);return r.isValidBraceCompletionAtPosition(t,n,e.openingBrace.charCodeAt(0))}getQuickInfoWorker(e,t){var{file:r,project:n}=this.getFileAndProject(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=n.getLanguageService().getQuickInfoAtPosition(r,this.getPosition(e,i));if(e)return r=!!this.getPreferences(r).displayPartsForJSDoc,t?(t=Ire(e.displayParts),{kind:e.kind,kindModifiers:e.kindModifiers,start:i.positionToLineOffset(e.textSpan.start),end:i.positionToLineOffset(J3(e.textSpan)),displayString:t,documentation:r?this.mapDisplayParts(e.documentation,n):Ire(e.documentation),tags:this.mapJSDocTagInfo(e.tags,n,r)}):r?e:{...e,tags:this.mapJSDocTagInfo(e.tags,n,!1)}}getFormattingEditsForRange(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e);let n=this.projectService.getScriptInfoForNormalizedPath(t);var i=n.lineOffsetToPosition(e.line,e.offset),e=n.lineOffsetToPosition(e.endLine,e.endOffset),r=r.getFormattingEditsForRange(t,i,e,this.getFormatOptions(t));if(r)return r.map(e=>this.convertTextChangeToCodeEdit(e,n))}getFormattingEditsForRangeFull(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),n=e.options?mye(e.options):this.getFormatOptions(t);return r.getFormattingEditsForRange(t,e.position,e.endPosition,n)}getFormattingEditsForDocumentFull(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),e=e.options?mye(e.options):this.getFormatOptions(t);return r.getFormattingEditsForDocument(t,e)}getFormattingEditsAfterKeystrokeFull(e){var{file:t,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),n=e.options?mye(e.options):this.getFormatOptions(t);return r.getFormattingEditsAfterKeystroke(t,e.position,e.key,n)}getFormattingEditsAfterKeystroke(n){var{file:i,languageService:a}=this.getFileAndLanguageServiceForSyntacticOperation(n);let t=this.projectService.getScriptInfoForNormalizedPath(i);var r,o=t.lineOffsetToPosition(n.line,n.offset),s=this.getFormatOptions(i),c=a.getFormattingEditsAfterKeystroke(i,o,n.key,s);if("\n"===n.key&&(!c||0===c.length||(r=o,c.every(e=>J3(e.span)({start:t.positionToLineOffset(e.span.start),end:t.positionToLineOffset(J3(e.span)),newText:e.newText||""}))}getCompletions(e,t){var{file:r,project:n}=this.getFileAndProject(e);let h=this.projectService.getScriptInfoForNormalizedPath(r);var i=this.getPosition(e,h);let y=n.getLanguageService().getCompletionsAtPosition(r,i,{...xye(this.getPreferences(r)),triggerCharacter:e.triggerCharacter,triggerKind:e.triggerKind,includeExternalModuleExports:e.includeExternalModuleExports,includeInsertTextCompletions:e.includeInsertTextCompletions},n.projectService.getFormatCodeOptions(r));if(void 0!==y){if("completions-full"===t)return y;let g=e.prefix||"";i=AT(y.entries,e=>{var t,r,n,i,a,o,s,c,l,_,u,d,p,f,m;if(y.isMemberCompletion||f3(e.name.toLowerCase(),g.toLowerCase()))return{name:e,kind:t,kindModifiers:r,sortText:n,insertText:i,filterText:a,replacementSpan:o,hasAction:s,source:c,sourceDisplay:l,labelDetails:_,isSnippet:u,isRecommended:d,isPackageJsonImport:p,isImportStatementCompletion:f,data:m}=e,{name:e,kind:t,kindModifiers:r,sortText:n,insertText:i,filterText:a,replacementSpan:o?yve(o,h):void 0,isSnippet:u,hasAction:s||void 0,source:c,sourceDisplay:l,labelDetails:_,isRecommended:d,isPackageJsonImport:p,isImportStatementCompletion:f,data:m}});return"completions"===t?(y.metadata&&(i.metadata=y.metadata),i):{...y,optionalReplacementSpan:y.optionalReplacementSpan&&yve(y.optionalReplacementSpan,h),entries:i}}}getCompletionEntryDetails(e,t){let{file:n,project:i}=this.getFileAndProject(e);var r=this.projectService.getScriptInfoForNormalizedPath(n);let a=this.getPosition(e,r),o=i.projectService.getFormatCodeOptions(n),s=!!this.getPreferences(n).displayPartsForJSDoc;r=AT(e.entryNames,e=>{var{name:e,source:t,data:r}="string"==typeof e?{name:e,source:void 0,data:void 0}:e;return i.getLanguageService().getCompletionEntryDetails(n,a,e,o,t,this.getPreferences(n),r?s3(r,kve):void 0)});return t?s?r:r.map(e=>({...e,tags:this.mapJSDocTagInfo(e.tags,i,!1)})):r.map(e=>({...e,codeActions:$4(e.codeActions,e=>this.mapCodeAction(e)),documentation:this.mapDisplayParts(e.documentation,i),tags:this.mapJSDocTagInfo(e.tags,i,s)}))}getCompileOnSaveAffectedFileList(e){var t=this.getProjects(e,!0,!0),e=this.projectService.getScriptInfo(e.file);if(e){var r=e;var i=e=>this.projectService.getScriptInfoForPath(e);e=t;var a=(e,t)=>{if(e.compileOnSaveEnabled&&e.languageServiceEnabled&&!e.isOrphan()){var r,n=e.getCompilationSettings();if(!n.noEmit&&(!x9(t.fileName)||wD(r=n)||r.emitDecoratorMetadata))return{projectFileName:e.getProjectName(),fileNames:e.getCompileOnSaveAffectedFileList(t),projectUsesOutFile:!!n.outFile}}};let n=y(i3(e)?e:e.projects,e=>a(e,r));return!i3(e)&&e.symLinkedProjects&&e.symLinkedProjects.forEach((e,t)=>{let r=i(t);n.push(...FT(e,e=>a(e,r)))}),RT(n,c3)}return Z0e}emitFile(e){var{file:t,project:r}=this.getFileAndProject(e);return r||Q0e.ThrowNoProject(),r.languageServiceEnabled?(t=r.getScriptInfo(t),{emitSkipped:r,diagnostics:t}=r.emitFile(t,(e,t,r)=>this.host.writeFile(e,t,r)),e.richResponse?{emitSkipped:r,diagnostics:e.includeLinePosition?this.convertToDiagnosticsWithLinePositionFromDiagnosticFile(t):t.map(e=>rve(e,!0))}:!r):!!e.richResponse&&{emitSkipped:!0,diagnostics:[]}}getSignatureHelpItems(e,t){let{file:r,project:n}=this.getFileAndProject(e);var i=this.projectService.getScriptInfoForNormalizedPath(r),a=this.getPosition(e,i),a=n.getLanguageService().getSignatureHelpItems(r,a,e),e=!!this.getPreferences(r).displayPartsForJSDoc;return a&&t?(t=a.applicableSpan,{...a,applicableSpan:{start:i.positionToLineOffset(t.start),end:i.positionToLineOffset(t.start+t.length)},items:this.mapSignatureHelpItems(a.items,n,e)}):e||!a?a:{...a,items:a.items.map(e=>({...e,tags:this.mapJSDocTagInfo(e.tags,n,!1)}))}}toPendingErrorCheck(e){var e=r1e(e),t=this.projectService.tryGetDefaultProjectForFile(e);return t&&{fileName:e,project:t}}getDiagnostics(e,t,r){this.suppressDiagnosticEvents||0({text:e.text,kind:e.kind,kindModifiers:e.kindModifiers,spans:e.spans.map(e=>yve(e,t)),childItems:this.mapLocationNavigationBarItems(e.childItems,t),indent:e.indent}))}getNavigationBarItems(e,t){var{file:e,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),r=r.getNavigationBarItems(e);return r?t?this.mapLocationNavigationBarItems(r,this.projectService.getScriptInfoForNormalizedPath(e)):r:void 0}toLocationNavigationTree(e,t){return{text:e.text,kind:e.kind,kindModifiers:e.kindModifiers,spans:e.spans.map(e=>yve(e,t)),nameSpan:e.nameSpan&&yve(e.nameSpan,t),childItems:$4(e.childItems,e=>this.toLocationNavigationTree(e,t))}}getNavigationTree(e,t){var{file:e,languageService:r}=this.getFileAndLanguageServiceForSyntacticOperation(e),r=r.getNavigationTree(e);return r?t?this.toLocationNavigationTree(r,this.projectService.getScriptInfoForNormalizedPath(e)):r:void 0}getNavigateToItems(e,t){e=this.getFullNavigateToItems(e);return FT(e,t?({project:r,navigateToItems:e})=>e.map(e=>{var t=r.getScriptInfo(e.fileName),t={name:e.name,kind:e.kind,kindModifiers:e.kindModifiers,isCaseSensitive:e.isCaseSensitive,matchKind:e.matchKind,file:e.fileName,start:t.positionToLineOffset(e.textSpan.start),end:t.positionToLineOffset(J3(e.textSpan))};return e.kindModifiers&&""!==e.kindModifiers&&(t.kindModifiers=e.kindModifiers),e.containerName&&0e)}getFullNavigateToItems(e){let{currentFileOnly:t,searchValue:r,maxResultCount:n,projectFileName:i}=e;var a,o;if(t)return Y4.assertIsDefined(e.file),{file:a,project:o}=this.getFileAndProject(e),[{project:o,navigateToItems:o.getLanguageService().getNavigateToItems(r,n,a)}];let s=this.getHostPreferences(),c=[],l=new Map;return e.file||i?lve(this.getProjects(e),void 0,e=>_(e)):(this.projectService.loadAncestorProjectTree(),this.projectService.forEachEnabledProject(e=>_(e))),c;function _(t){var e=NT(t.getLanguageService().getNavigateToItems(r,n,void 0,t.isNonTsProject(),s.excludeLibrarySymbolsInNavTo),e=>function(e){var t=e.name;if(l.has(t)){var r,n=l.get(t);for(r of n)if(function(e,t){return e===t||!(!e||!t)&&e.containerKind===t.containerKind&&e.containerName===t.containerName&&e.fileName===t.fileName&&e.isCaseSensitive===t.isCaseSensitive&&e.kind===t.kind&&e.kindModifiers===t.kindModifiers&&e.matchKind===t.matchKind&&e.name===t.name&&e.textSpan.start===t.textSpan.start&&e.textSpan.length===t.textSpan.length}(r,e))return!1;n.push(e)}else l.set(t,[e]);return!0}(e)&&!pve(dve(e),t));e.length&&c.push({project:t,navigateToItems:e})}}getSupportedCodeFixes(e){var t,r;return e?e.file?({file:t,project:r}=this.getFileAndProject(e),r.getLanguageService().getSupportedCodeFixes(t)):((r=this.getProject(e.projectFileName))||Q0e.ThrowNoProject(),r.getLanguageService().getSupportedCodeFixes()):Lre()}isLocation(e){return void 0!==e.line}extractPositionOrRange(e,t){let r,n;var i;return this.isLocation(e)?r=void 0!==(i=e).position?i.position:t.lineOffsetToPosition(i.line,i.offset):n=this.getRange(e,t),Y4.checkDefined(void 0===r?n:r)}getRange(e,t){var{startPosition:e,endPosition:t}=this.getStartAndEndPosition(e,t);return{pos:e,end:t}}getApplicableRefactors(e){var{file:t,project:r}=this.getFileAndProject(e),n=r.getScriptInfoForNormalizedPath(t);return r.getLanguageService().getApplicableRefactors(t,this.extractPositionOrRange(e,n),this.getPreferences(t),e.triggerReason,e.kind,e.includeInteractiveActions).map(e=>({...e,actions:e.actions.map(e=>({...e,range:e.range?{start:tve({line:e.range.start.line,character:e.range.start.offset}),end:tve({line:e.range.end.line,character:e.range.end.offset})}:void 0}))}))}getEditsForRefactor(t,r){var{file:n,project:i}=this.getFileAndProject(t),a=i.getScriptInfoForNormalizedPath(n),a=i.getLanguageService().getEditsForRefactor(n,this.getFormatOptions(n),this.extractPositionOrRange(t,a),t.refactor,t.action,this.getPreferences(n),t.interactiveRefactorArguments);if(void 0===a)return{edits:[]};if(r){var{renameFilename:n,renameLocation:t,edits:r}=a;let e;return void 0!==n&&void 0!==t&&(i=i.getScriptInfoForNormalizedPath(r1e(n)),e=xve(KK(i.getSnapshot()),n,t,r)),{renameLocation:e,renameFilename:n,edits:this.mapTextChangesToCodeEdits(r),notApplicableReason:a.notApplicableReason}}return a}getMoveToRefactoringFileSuggestions(e){var{file:t,project:r}=this.getFileAndProject(e),n=r.getScriptInfoForNormalizedPath(t);return r.getLanguageService().getMoveToRefactoringFileSuggestions(t,this.extractPositionOrRange(e,n),this.getPreferences(t))}getPasteEdits(t){let{file:r,project:n}=this.getFileAndProject(t);var e=t.copiedFrom?{file:t.copiedFrom.file,range:t.copiedFrom.spans.map(e=>this.getRange({file:t.copiedFrom.file,startLine:e.start.line,startOffset:e.start.offset,endLine:e.end.line,endOffset:e.end.offset},n.getScriptInfoForNormalizedPath(r1e(t.copiedFrom.file))))}:void 0,e=n.getLanguageService().getPasteEdits({targetFile:r,pastedText:t.pastedText,pasteLocations:t.pasteLocations.map(e=>this.getRange({file:r,startLine:e.start.line,startOffset:e.start.offset,endLine:e.end.line,endOffset:e.end.offset},n.getScriptInfoForNormalizedPath(r))),copiedFrom:e,preferences:this.getPreferences(r)},this.getFormatOptions(r));return e&&this.mapPasteEditsAction(e)}organizeImports(e,t){Y4.assert("file"===e.scope.type);var{file:r,project:n}=this.getFileAndProject(e.scope.args),n=n.getLanguageService().organizeImports({fileName:r,mode:e.mode??(e.skipDestructiveCodeActions?"SortAndCombine":void 0),type:"file"},this.getFormatOptions(r),this.getPreferences(r));return t?this.mapTextChangesToCodeEdits(n):n}getEditsForFileRename(e,t){let i=r1e(e.oldFilePath),a=r1e(e.newFilePath),o=this.getHostFormatOptions(),s=this.getHostPreferences(),c=new Set,l=[];return this.projectService.loadAncestorProjectTree(),this.projectService.forEachEnabledProject(e=>{var t,r,n=[];for(t of e.getLanguageService().getEditsForFileRename(i,a,o,s))c.has(t.fileName)||(l.push(t),n.push(t.fileName));for(r of n)c.add(r)}),t?l.map(e=>this.mapTextChangeToCodeEdit(e)):l}getCodeFixes(r,e){var{file:n,project:i}=this.getFileAndProject(r),a=i.getScriptInfoForNormalizedPath(n);let{startPosition:o,endPosition:s}=this.getStartAndEndPosition(r,a),t;try{t=i.getLanguageService().getCodeFixesAtPosition(n,o,s,r.errorCodes,this.getFormatOptions(n),this.getPreferences(n))}catch(e){a=i.getLanguageService();let t=[...a.getSyntacticDiagnostics(n),...a.getSemanticDiagnostics(n),...a.getSuggestionDiagnostics(n)].map(e=>Go(o,s-o,e.start,e.length)&&e.code);i=r.errorCodes.find(e=>!t.includes(e));throw void 0!==i&&(e.message=`BADCLIENT: Bad error code, ${i} not found in range ${o}..${s} (found: ${t.join(", ")}); could have caused this error: -`+e.message),e}return e?t.map(e=>this.mapCodeFixAction(e)):t}getCombinedCodeFix({scope:e,fixId:t},r){Y4.assert("file"===e.type);var{file:e,project:n}=this.getFileAndProject(e.args),n=n.getLanguageService().getCombinedCodeFix({type:"file",fileName:e},t,this.getFormatOptions(e),this.getPreferences(e));return r?{changes:this.mapTextChangesToCodeEdits(n.changes),commands:n.commands}:n}applyCodeActionCommand(e){var t;for(t of se(e.command)){var{file:r,project:n}=this.getFileAndProject(t);n.getLanguageService().applyCodeActionCommand(t,this.getFormatOptions(r)).then(e=>{},e=>{})}return{}}getStartAndEndPosition(e,t){let r,n;return void 0!==e.startPosition?r=e.startPosition:(r=t.lineOffsetToPosition(e.startLine,e.startOffset),e.startPosition=r),void 0!==e.endPosition?n=e.endPosition:(n=t.lineOffsetToPosition(e.endLine,e.endOffset),e.endPosition=n),{startPosition:r,endPosition:n}}mapCodeAction({description:e,changes:t,commands:r}){return{description:e,changes:this.mapTextChangesToCodeEdits(t),commands:r}}mapCodeFixAction({fixName:e,description:t,changes:r,commands:n,fixId:i,fixAllDescription:a}){return{fixName:e,description:t,changes:this.mapTextChangesToCodeEdits(r),commands:n,fixId:i,fixAllDescription:a}}mapPasteEditsAction({edits:e,fixId:t}){return{edits:this.mapTextChangesToCodeEdits(e),fixId:t}}mapTextChangesToCodeEdits(e){return e.map(e=>this.mapTextChangeToCodeEdit(e))}mapTextChangeToCodeEdit(e){let r=this.projectService.getScriptInfoOrConfig(e.fileName);return!!e.isNewFile==!!r&&(r||this.projectService.logErrorForScriptInfoNotFound(e.fileName),Y4.fail("Expected isNewFile for (only) new files. "+JSON.stringify({isNewFile:!!e.isNewFile,hasScriptInfo:!!r}))),r?{fileName:e.fileName,textChanges:e.textChanges.map(e=>{return e=e,{start:bve(t=r,e.span.start),end:bve(t,J3(e.span)),newText:e.newText};var t})}:(e=e,Y4.assert(1===e.textChanges.length),t=WT(e.textChanges),Y4.assert(0===t.span.start&&0===t.span.length),{fileName:e.fileName,textChanges:[{start:{line:0,offset:0},end:{line:0,offset:0},newText:t.newText}]});var t}convertTextChangeToCodeEdit(e,t){return{start:t.positionToLineOffset(e.span.start),end:t.positionToLineOffset(e.span.start+e.span.length),newText:e.newText||""}}getBraceMatching(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e);let i=this.projectService.getScriptInfoForNormalizedPath(r);e=this.getPosition(e,i),n=n.getBraceMatchingAtPosition(r,e);return n?t?n.map(e=>yve(e,i)):n:void 0}getDiagnosticsForProject(e,r,n){if(!this.suppressDiagnosticEvents){var{fileNames:i,languageServiceDisabled:a}=this.getProjectInfoWorker(n,void 0,!0,!0);if(!a){a=i.filter(e=>!e.includes("lib.d.ts"));if(0!==a.length){var o,s=[],c=[],l=[],_=[],i=r1e(n);let t=this.projectService.ensureDefaultProjectForFile(i);for(o of a)(this.getCanonicalFileName(o)===this.getCanonicalFileName(n)?s:this.projectService.getScriptInfo(o).isScriptOpen()?c:x9(o)?_:l).push(o);i=[...s,...c,...l,..._].map(e=>({fileName:e,project:t}));this.updateErrorCheck(e,i,r,!1)}}}}configurePlugin(e){this.projectService.configurePlugin(e)}getSmartSelectionRange(e,t){var r=e["locations"];let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(e),a=Y4.checkDefined(this.projectService.getScriptInfo(n));return $4(r,e=>{e=this.getPosition(e,a),e=i.getSmartSelectionRange(n,e);return t?this.mapSelectionRange(e,a):e})}toggleLineComment(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfo(r),e=this.getRange(e,i),i=n.toggleLineComment(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}toggleMultilineComment(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.toggleMultilineComment(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}commentSelection(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.commentSelection(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}uncommentSelection(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.uncommentSelection(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}mapSelectionRange(e,t){var r={textSpan:yve(e.textSpan,t)};return e.parent&&(r.parent=this.mapSelectionRange(e.parent,t)),r}getScriptInfoFromProjectService(e){var e=r1e(e),t=this.projectService.getScriptInfoForNormalizedPath(e);return t||(this.projectService.logErrorForScriptInfoNotFound(e),Q0e.ThrowNoProject())}toProtocolCallHierarchyItem(e){var t=this.getScriptInfoFromProjectService(e.file);return{name:e.name,kind:e.kind,kindModifiers:e.kindModifiers,file:e.file,containerName:e.containerName,span:yve(e.span,t),selectionSpan:yve(e.selectionSpan,t)}}toProtocolCallHierarchyIncomingCall(e){let t=this.getScriptInfoFromProjectService(e.from.file);return{from:this.toProtocolCallHierarchyItem(e.from),fromSpans:e.fromSpans.map(e=>yve(e,t))}}toProtocolCallHierarchyOutgoingCall(e,t){return{to:this.toProtocolCallHierarchyItem(e.to),fromSpans:e.fromSpans.map(e=>yve(e,t))}}prepareCallHierarchy(e){var{file:t,project:r}=this.getFileAndProject(e),n=this.projectService.getScriptInfoForNormalizedPath(t);if(n)return e=this.getPosition(e,n),(n=r.getLanguageService().prepareCallHierarchy(t,e))&&tX(n,e=>this.toProtocolCallHierarchyItem(e))}provideCallHierarchyIncomingCalls(e){var{file:t,project:r}=this.getFileAndProject(e),n=this.getScriptInfoFromProjectService(t);return r.getLanguageService().provideCallHierarchyIncomingCalls(t,this.getPosition(e,n)).map(e=>this.toProtocolCallHierarchyIncomingCall(e))}provideCallHierarchyOutgoingCalls(e){var{file:t,project:r}=this.getFileAndProject(e);let n=this.getScriptInfoFromProjectService(t);return r.getLanguageService().provideCallHierarchyOutgoingCalls(t,this.getPosition(e,n)).map(e=>this.toProtocolCallHierarchyOutgoingCall(e,n))}getCanonicalFileName(e){return ua(this.host.useCaseSensitiveFileNames?e:br(e))}exit(){}notRequired(){return{responseRequired:!1}}requiredResponse(e){return{response:e,responseRequired:!0}}addProtocolHandler(e,t){if(this.handlers.has(e))throw new Error(`Protocol handler already exists for command "${e}"`);this.handlers.set(e,t)}setCurrentRequest(e){Y4.assert(void 0===this.currentRequestId),this.currentRequestId=e,this.cancellationToken.setRequest(e)}resetCurrentRequest(e){Y4.assert(this.currentRequestId===e),this.currentRequestId=void 0,this.cancellationToken.resetRequest(e)}executeWithRequestId(e,t){try{return this.setCurrentRequest(e),t()}finally{this.resetCurrentRequest(e)}}executeCommand(e){let t=this.handlers.get(e.command);var r;return t?(r=this.executeWithRequestId(e.seq,()=>t(e)),this.projectService.enableRequestedPlugins(),r):(this.logger.msg("Unrecognized JSON command:"+uW(e),"Err"),this.doOutput(void 0,"unknown",e.seq,!1,"Unrecognized JSON command: "+e.command),{responseRequired:!1})}onMessage(t){var e;this.gcTimer.scheduleCollect(),this.performanceData=void 0;let r;this.logger.hasLevel(2)&&(r=this.hrtime(),this.logger.hasLevel(3))&&this.logger.info("request:"+_W(this.toStringMessage(t)));let n,i;try{n=this.parseMessage(t),i=n.arguments&&n.arguments.file?n.arguments:void 0,null!=Z4&&Z4.instant(Z4.Phase.Session,"request",{seq:n.seq,command:n.command}),null!=er&&er.logStartCommand(""+n.command,this.toStringMessage(t).substring(0,100)),null!=Z4&&Z4.push(Z4.Phase.Session,"executeCommand",{seq:n.seq,command:n.command},!0);var a,{response:o,responseRequired:s}=this.executeCommand(n);null!=Z4&&Z4.pop(),this.logger.hasLevel(2)&&(a=((1e9*(e=this.hrtime(r))[0]+e[1])/1e6).toFixed(4),s?this.logger.perftrc(`${n.seq}::${n.command}: elapsed time (in milliseconds) `+a):this.logger.perftrc(`${n.seq}::${n.command}: async elapsed time (in milliseconds) `+a)),null!=er&&er.logStopCommand(""+n.command,"Success"),null!=Z4&&Z4.instant(Z4.Phase.Session,"response",{seq:n.seq,command:n.command,success:!!o}),o?this.doOutput(o,n.command,n.seq,!0):s&&this.doOutput(void 0,n.command,n.seq,!1,"No content available.")}catch(e){null!=Z4&&Z4.popAll(),e instanceof Vr?(null!=er&&er.logStopCommand(""+(n&&n.command),"Canceled: "+e),null!=Z4&&Z4.instant(Z4.Phase.Session,"commandCanceled",{seq:null==n?void 0:n.seq,command:null==n?void 0:n.command}),this.doOutput({canceled:!0},n.command,n.seq,!0)):(this.logErrorWorker(e,this.toStringMessage(t),i),null!=er&&er.logStopCommand(""+(n&&n.command),"Error: "+e),null!=Z4&&Z4.instant(Z4.Phase.Session,"commandError",{seq:null==n?void 0:n.seq,command:null==n?void 0:n.command,message:e.message}),this.doOutput(void 0,n?n.command:"unknown",n?n.seq:0,!1,"Error processing request. "+e.message+"\n"+e.stack))}}parseMessage(e){return JSON.parse(e)}toStringMessage(e){return e}getFormatOptions(e){return this.projectService.getFormatCodeOptions(e)}getPreferences(e){return this.projectService.getPreferences(e)}getHostFormatOptions(){return this.projectService.getHostFormatCodeOptions()}getHostPreferences(){return this.projectService.getHostPreferences()}};function yve(e,t){return{start:t.positionToLineOffset(e.start),end:t.positionToLineOffset(J3(e))}}function vve(e,t,r){e=yve(e,r),t=t&&yve(t,r);return t?{...e,contextStart:t.start,contextEnd:t.end}:e}function bve(e,t){return Kye(e)?{line:(r=e.getLineAndCharacterOfPosition(t)).line+1,offset:r.character+1}:e.positionToLineOffset(t);var r}function xve(e,t,r,n){var{line:e,character:t}=no(Za(function(t,e,r){for(var{fileName:n,textChanges:i}of r)if(n===e)for(let e=i.length-1;0<=e;e--){var{newText:a,span:{start:o,length:s}}=i[e];t=t.slice(0,o)+a+t.slice(o+s)}return t}(e,t,n)),r);return{line:e+1,offset:t+1}}function Sve(e,{fileName:t,textSpan:r,contextSpan:n,isWriteAccess:i,isDefinition:a},{disableLineTextInReferences:o}){e=Y4.checkDefined(e.getScriptInfo(t)),r=vve(r,n,e),n=o?void 0:function(e,t){t=e.lineToTextSpan(t.start.line-1);return e.getSnapshot().getText(t.start,J3(t)).replace(/\r|\n/g,"")}(e,r);return{file:t,...r,lineText:n,isWriteAccess:i,isDefinition:a}}function kve(e){return void 0===e||e&&"object"==typeof e&&"string"==typeof e.exportName&&(void 0===e.fileName||"string"==typeof e.fileName)&&(void 0===e.ambientModuleName||"string"==typeof e.ambientModuleName&&(void 0===e.isPackageJsonImport||"boolean"==typeof e.isPackageJsonImport))}var Tve=(e=>(e[e.PreStart=0]="PreStart",e[e.Start=1]="Start",e[e.Entire=2]="Entire",e[e.Mid=3]="Mid",e[e.End=4]="End",e[e.PostEnd=5]="PostEnd",e))(Tve||{}),Cve=class{constructor(){this.goSubtree=!0,this.lineIndex=new Eve,this.endBranch=[],this.state=2,this.initialText="",this.trailingText="",this.lineIndex.root=new Fve,this.startPath=[this.lineIndex.root],this.stack=[this.lineIndex.root]}get done(){return!1}insertLines(e,i){i&&(this.trailingText=""),e=e?this.initialText+e+this.trailingText:this.initialText+this.trailingText;var a=Eve.linesFromText(e).lines;1this.currentVersion))return e%Nve.maxVersions}currentVersionToIndex(){return this.currentVersion%Nve.maxVersions}edit(e,t,r){this.changes.push(new wve(e,t,r)),(this.changes.length>Nve.changeNumberThreshold||t>Nve.changeLengthThreshold||r&&r.length>Nve.changeLengthThreshold)&&this.getSnapshot()}getSnapshot(){return this._getSnapshot()}_getSnapshot(){let t=this.versions[this.currentVersionToIndex()];if(0=Nve.maxVersions&&(this.minVersion=this.currentVersion-Nve.maxVersions+1)}return t}getSnapshotVersion(){return this._getSnapshot().version}getAbsolutePositionAndLineText(e){return this._getSnapshot().index.lineNumberToInfo(e)}lineOffsetToPosition(e,t){return this._getSnapshot().index.absolutePositionOfStartOfLine(e)+(t-1)}positionToLineOffset(e){return this._getSnapshot().index.positionToLineOffset(e)}lineToTextSpan(e){var t=this._getSnapshot().index,{lineText:r,absolutePosition:n}=t.lineNumberToInfo(e+1);return Qo(n,void 0!==r?r.length:t.absolutePositionOfStartOfLine(e+2)-n)}getTextChangesBetweenVersions(t,r){if(!(t=this.minVersion){var n,i=[];for(let e=t+1;e<=r;e++)for(n of this.versions[this.versionToIndex(e)].changesSincePreviousVersion)i.push(n.getTextChangeRange());return ns(i)}}getLineCount(){return this._getSnapshot().index.getLineCount()}static fromString(e){var t=new Nve,r=new Pve(0,t,new Eve),e=(t.versions[t.currentVersion]=r,Eve.linesFromText(e));return r.index.load(e.lines),t}},Dve=(Nve.changeNumberThreshold=8,Nve.changeLengthThreshold=256,Nve.maxVersions=8,Nve),Pve=class Kve{constructor(e,t,r,n=Z0e){this.version=e,this.cache=t,this.index=r,this.changesSincePreviousVersion=n}getText(e,t){return this.index.getText(e,t-e)}getLength(){return this.index.getLength()}getChangeRange(e){if(e instanceof Kve&&this.cache===e.cache)return this.version<=e.version?rs:this.cache.getTextChangesBetweenVersions(e.version,this.version)}},Eve=class Gve{constructor(){this.checkEdits=!1}absolutePositionOfStartOfLine(e){return this.lineNumberToInfo(e).absolutePosition}positionToLineOffset(e){var{oneBasedLine:e,zeroBasedColumn:t}=this.root.charOffsetToLineInfo(1,e);return{line:e,offset:t+1}}positionToColumnAndLineText(e){return this.root.charOffsetToLineInfo(1,e)}getLineCount(){return this.root.lineCount()}lineNumberToInfo(e){var t;return e<=this.getLineCount()?({position:e,leaf:t}=this.root.lineNumberToInfo(e,0),{absolutePosition:e,lineText:t&&t.text}):{absolutePosition:this.root.charCount(),lineText:void 0}}load(t){if(0{n=n.concat(r.text.substring(e,e+t))}}),n}getLength(){return this.root.charCount()}every(n,e,t){t=t||this.root.charCount();var r={goSubtree:!0,done:!1,leaf(e,t,r){n(r,e,t)||(this.done=!0)}};return this.walk(e,t-e,r),!r.done}edit(r,n,i){if(0!==this.root.charCount()){let e;this.checkEdits&&(s=this.getText(0,this.root.charCount()),e=s.slice(0,r)+i+s.slice(r+n));var a,o,s=new Cve;let t=!1;return r>=this.root.charCount()?(r=this.root.charCount()-1,o=this.getText(r,1),i=i?o+i:o,n=0,t=!0):0=a;)this.skipChild(o,r,i,n,0),o-=a,i++,a=this.children[i].charCount();if(o+r<=a){if(this.execWalk(o,r,n,i,2))return}else{if(this.execWalk(o,a-o,n,i,1))return;let e=r-(a-o);i++;t=this.children[i];for(a=t.charCount();e>a;){if(this.execWalk(0,a,n,i,3))return;e-=a,i++,a=this.children[i].charCount()}if(0t)return r.isLeaf()?{oneBasedLine:e,zeroBasedColumn:t,lineText:r.text}:r.charOffsetToLineInfo(e,t);t-=r.charCount(),e+=r.lineCount()}var n=this.lineCount();return 0===n?{oneBasedLine:1,zeroBasedColumn:0,lineText:void 0}:{oneBasedLine:n,zeroBasedColumn:Y4.checkDefined(this.lineNumberToInfo(n,0).leaf).charCount(),lineText:void 0}}lineNumberToInfo(e,t){for(var r of this.children){var n=r.lineCount();if(e<=n)return r.isLeaf()?{position:t,leaf:r}:r.lineNumberToInfo(e,t);e-=n,t+=r.charCount()}return{position:t,leaf:void 0}}splitAfter(e){let t;var r=this.children.length,n=++e;if(e{(this.packageInstalledPromise??(this.packageInstalledPromise=new Map)).set(this.packageInstallId,{resolve:e,reject:t})});return this.installer.send(e),t}attach(e){this.projectService=e,this.installer=this.createInstallerProcess()}onProjectClosed(e){this.installer.send({projectName:e.getProjectName(),kind:"closeProject"})}enqueueInstallTypingsRequest(e,t,r){e=t1e(e,t,r);this.logger.hasLevel(3)&&this.logger.info("TIAdapter:: Scheduling throttled operation:"+uW(e)),this.activeRequestCount{this.logger.hasLevel(3)&&this.logger.info("TIAdapter:: Sending request:"+uW(e)),this.installer.send(e)},Ive.requestDelayMillis,e.projectName+"::"+e.kind)}},Ove=(Ive.requestDelayMillis=100,Ive),Lve={};r(Lve,{ActionInvalidate:()=>ZV,ActionPackageInstalled:()=>eW,ActionSet:()=>YV,ActionWatchTypingLocations:()=>aW,Arguments:()=>XV,AutoImportProviderProject:()=>q1e,AuxiliaryProject:()=>J1e,CharRangeSection:()=>Tve,CloseFileWatcherEvent:()=>cye,CommandNames:()=>nve,ConfigFileDiagEvent:()=>rye,ConfiguredProject:()=>U1e,ConfiguredProjectLoadKind:()=>Dye,CreateDirectoryWatcherEvent:()=>sye,CreateFileWatcherEvent:()=>oye,Errors:()=>Q0e,EventBeginInstallTypes:()=>rW,EventEndInstallTypes:()=>nW,EventInitializationFailed:()=>iW,EventTypesRegistry:()=>tW,ExternalProject:()=>V1e,GcTimer:()=>d1e,InferredProject:()=>B1e,LargeFileReferencedEvent:()=>tye,LineIndex:()=>Eve,LineLeaf:()=>Ave,LineNode:()=>Fve,LogLevel:()=>Y0e,Msg:()=>e1e,OpenFileInfoTelemetryEvent:()=>aye,Project:()=>M1e,ProjectInfoTelemetryEvent:()=>iye,ProjectKind:()=>A1e,ProjectLanguageServiceStateEvent:()=>nye,ProjectLoadingFinishEvent:()=>eye,ProjectLoadingStartEvent:()=>Z1e,ProjectService:()=>Hye,ProjectsUpdatedInBackgroundEvent:()=>Y1e,ScriptInfo:()=>D1e,ScriptVersionCache:()=>Dve,Session:()=>hve,TextStorage:()=>w1e,ThrottledOperations:()=>u1e,TypingsCache:()=>F1e,TypingsInstallerAdapter:()=>Ove,allFilesAreJsOrDts:()=>L1e,allRootFilesAreJsOrDts:()=>O1e,asNormalizedPath:()=>i1e,convertCompilerOptions:()=>gye,convertFormatOptions:()=>mye,convertScriptKindName:()=>bye,convertTypeAcquisition:()=>yye,convertUserPreferences:()=>xye,convertWatchOptions:()=>hye,countEachFileTypes:()=>I1e,createInstallTypingsRequest:()=>t1e,createModuleSpecifierCache:()=>$ye,createNormalizedPathMap:()=>a1e,createPackageJsonCache:()=>Xye,createSortedArray:()=>_1e,emptyArray:()=>Z0e,findArgument:()=>sW,forEachResolvedProjectReferenceProject:()=>Pye,formatDiagnosticToProtocol:()=>rve,formatMessage:()=>ive,getBaseConfigFileName:()=>p1e,getLocationInNewDocument:()=>xve,hasArgument:()=>oW,hasNoTypeScriptSource:()=>j1e,indent:()=>_W,isBackgroundProject:()=>G1e,isConfigFile:()=>Kye,isConfiguredProject:()=>H1e,isDynamicFileName:()=>N1e,isExternalProject:()=>K1e,isInferredProject:()=>W1e,isInferredProjectName:()=>o1e,isProjectDeferredClose:()=>$1e,makeAutoImportProviderProjectName:()=>c1e,makeAuxiliaryProjectName:()=>l1e,makeInferredProjectName:()=>s1e,maxFileSize:()=>Q1e,maxProgramSizeForNonTsFiles:()=>X1e,normalizedPathToPath:()=>n1e,nowString:()=>cW,nullCancellationToken:()=>Qye,nullTypingsInstaller:()=>P1e,protocol:()=>m1e,removeSorted:()=>f1e,stringifyIndented:()=>uW,toEvent:()=>ove,toNormalizedPath:()=>r1e,tryConvertScriptKindName:()=>vye,typingsInstaller:()=>W0e,updateProjectIfDirty:()=>jye}),"undefined"!=typeof console&&(Y4.loggingHost={log(e,t){switch(e){case 1:return console.error(t);case 2:return console.warn(t);case 3:case 4:return console.log(t)}}})}.call(this)}.call(this,t2e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t2e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/typescript/lib/typescript.js","/node_modules/typescript/lib")},{_process:46,buffer:1,crypto:1,fs:1,inspector:1,os:1,path:1,perf_hooks:1,"source-map-support":1}],48:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});let B=e("core-types-json-schema"),J=e("core-types-ts/dist/lib/ts-to-core-types"),p=e("core-types-ts"),z=e("./utils/sharedUtils"),q=e("./utils/constants");Draw.loadPlugin(function(P){var e=document.createElement("div");e.style.userSelect="none",e.style.overflow="hidden",e.style.padding="10px",e.style.height="100%";let i=document.createElement("textarea"),t=(i.style.height="200px",i.style.width="100%","-- click a nosql type button");i.value=t,mxUtils.br(e),e.appendChild(i);var r=P.menus.get("exportAs");let n="tonosql=To NoSQL",a=(r&&!window.VsCodeApi||(n="tonosql=Export As NoSQL"),mxResources.parse(n),new mxWindow(mxResources.get("tonosql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));function o(e){var t,r=function(e){var t={openapi:"3.0.0",info:{title:"drawio nosql export",version:q.pluginVersion,"x-comment":"Generated by from drawio uml using plugin nosql"},paths:{},components:{schemas:{}}},r={},n=e.getEntities();for(var i in n)if(Object.prototype.hasOwnProperty.call(n,i)){var a=n[i];if(!r[i]){r[i]={type:"object",title:i,additionalProperties:!1,properties:{}};for(let e=0;ethis.mapCodeFixAction(e)):t}getCombinedCodeFix({scope:e,fixId:t},r){Y4.assert("file"===e.type);var{file:e,project:n}=this.getFileAndProject(e.args),n=n.getLanguageService().getCombinedCodeFix({type:"file",fileName:e},t,this.getFormatOptions(e),this.getPreferences(e));return r?{changes:this.mapTextChangesToCodeEdits(n.changes),commands:n.commands}:n}applyCodeActionCommand(e){var t;for(t of se(e.command)){var{file:r,project:n}=this.getFileAndProject(t);n.getLanguageService().applyCodeActionCommand(t,this.getFormatOptions(r)).then(e=>{},e=>{})}return{}}getStartAndEndPosition(e,t){let r,n;return void 0!==e.startPosition?r=e.startPosition:(r=t.lineOffsetToPosition(e.startLine,e.startOffset),e.startPosition=r),void 0!==e.endPosition?n=e.endPosition:(n=t.lineOffsetToPosition(e.endLine,e.endOffset),e.endPosition=n),{startPosition:r,endPosition:n}}mapCodeAction({description:e,changes:t,commands:r}){return{description:e,changes:this.mapTextChangesToCodeEdits(t),commands:r}}mapCodeFixAction({fixName:e,description:t,changes:r,commands:n,fixId:i,fixAllDescription:a}){return{fixName:e,description:t,changes:this.mapTextChangesToCodeEdits(r),commands:n,fixId:i,fixAllDescription:a}}mapPasteEditsAction({edits:e,fixId:t}){return{edits:this.mapTextChangesToCodeEdits(e),fixId:t}}mapTextChangesToCodeEdits(e){return e.map(e=>this.mapTextChangeToCodeEdit(e))}mapTextChangeToCodeEdit(e){let r=this.projectService.getScriptInfoOrConfig(e.fileName);return!!e.isNewFile==!!r&&(r||this.projectService.logErrorForScriptInfoNotFound(e.fileName),Y4.fail("Expected isNewFile for (only) new files. "+JSON.stringify({isNewFile:!!e.isNewFile,hasScriptInfo:!!r}))),r?{fileName:e.fileName,textChanges:e.textChanges.map(e=>{return e=e,{start:bve(t=r,e.span.start),end:bve(t,J3(e.span)),newText:e.newText};var t})}:(e=e,Y4.assert(1===e.textChanges.length),t=WT(e.textChanges),Y4.assert(0===t.span.start&&0===t.span.length),{fileName:e.fileName,textChanges:[{start:{line:0,offset:0},end:{line:0,offset:0},newText:t.newText}]});var t}convertTextChangeToCodeEdit(e,t){return{start:t.positionToLineOffset(e.span.start),end:t.positionToLineOffset(e.span.start+e.span.length),newText:e.newText||""}}getBraceMatching(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e);let i=this.projectService.getScriptInfoForNormalizedPath(r);e=this.getPosition(e,i),n=n.getBraceMatchingAtPosition(r,e);return n?t?n.map(e=>yve(e,i)):n:void 0}getDiagnosticsForProject(e,r,n){if(!this.suppressDiagnosticEvents){var{fileNames:i,languageServiceDisabled:a}=this.getProjectInfoWorker(n,void 0,!0,!0);if(!a){a=i.filter(e=>!e.includes("lib.d.ts"));if(0!==a.length){var o,s=[],c=[],l=[],_=[],i=r1e(n);let t=this.projectService.ensureDefaultProjectForFile(i);for(o of a)(this.getCanonicalFileName(o)===this.getCanonicalFileName(n)?s:this.projectService.getScriptInfo(o).isScriptOpen()?c:x9(o)?_:l).push(o);i=[...s,...c,...l,..._].map(e=>({fileName:e,project:t}));this.updateErrorCheck(e,i,r,!1)}}}}configurePlugin(e){this.projectService.configurePlugin(e)}getSmartSelectionRange(e,t){var r=e["locations"];let{file:n,languageService:i}=this.getFileAndLanguageServiceForSyntacticOperation(e),a=Y4.checkDefined(this.projectService.getScriptInfo(n));return $4(r,e=>{e=this.getPosition(e,a),e=i.getSmartSelectionRange(n,e);return t?this.mapSelectionRange(e,a):e})}toggleLineComment(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfo(r),e=this.getRange(e,i),i=n.toggleLineComment(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}toggleMultilineComment(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.toggleMultilineComment(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}commentSelection(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.commentSelection(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}uncommentSelection(e,t){var{file:r,languageService:n}=this.getFileAndLanguageServiceForSyntacticOperation(e),i=this.projectService.getScriptInfoForNormalizedPath(r),e=this.getRange(e,i),i=n.uncommentSelection(r,e);if(t){let t=this.projectService.getScriptInfoForNormalizedPath(r);return i.map(e=>this.convertTextChangeToCodeEdit(e,t))}return i}mapSelectionRange(e,t){var r={textSpan:yve(e.textSpan,t)};return e.parent&&(r.parent=this.mapSelectionRange(e.parent,t)),r}getScriptInfoFromProjectService(e){var e=r1e(e),t=this.projectService.getScriptInfoForNormalizedPath(e);return t||(this.projectService.logErrorForScriptInfoNotFound(e),Q0e.ThrowNoProject())}toProtocolCallHierarchyItem(e){var t=this.getScriptInfoFromProjectService(e.file);return{name:e.name,kind:e.kind,kindModifiers:e.kindModifiers,file:e.file,containerName:e.containerName,span:yve(e.span,t),selectionSpan:yve(e.selectionSpan,t)}}toProtocolCallHierarchyIncomingCall(e){let t=this.getScriptInfoFromProjectService(e.from.file);return{from:this.toProtocolCallHierarchyItem(e.from),fromSpans:e.fromSpans.map(e=>yve(e,t))}}toProtocolCallHierarchyOutgoingCall(e,t){return{to:this.toProtocolCallHierarchyItem(e.to),fromSpans:e.fromSpans.map(e=>yve(e,t))}}prepareCallHierarchy(e){var{file:t,project:r}=this.getFileAndProject(e),n=this.projectService.getScriptInfoForNormalizedPath(t);if(n)return e=this.getPosition(e,n),(n=r.getLanguageService().prepareCallHierarchy(t,e))&&tX(n,e=>this.toProtocolCallHierarchyItem(e))}provideCallHierarchyIncomingCalls(e){var{file:t,project:r}=this.getFileAndProject(e),n=this.getScriptInfoFromProjectService(t);return r.getLanguageService().provideCallHierarchyIncomingCalls(t,this.getPosition(e,n)).map(e=>this.toProtocolCallHierarchyIncomingCall(e))}provideCallHierarchyOutgoingCalls(e){var{file:t,project:r}=this.getFileAndProject(e);let n=this.getScriptInfoFromProjectService(t);return r.getLanguageService().provideCallHierarchyOutgoingCalls(t,this.getPosition(e,n)).map(e=>this.toProtocolCallHierarchyOutgoingCall(e,n))}getCanonicalFileName(e){return ua(this.host.useCaseSensitiveFileNames?e:br(e))}exit(){}notRequired(){return{responseRequired:!1}}requiredResponse(e){return{response:e,responseRequired:!0}}addProtocolHandler(e,t){if(this.handlers.has(e))throw new Error(`Protocol handler already exists for command "${e}"`);this.handlers.set(e,t)}setCurrentRequest(e){Y4.assert(void 0===this.currentRequestId),this.currentRequestId=e,this.cancellationToken.setRequest(e)}resetCurrentRequest(e){Y4.assert(this.currentRequestId===e),this.currentRequestId=void 0,this.cancellationToken.resetRequest(e)}executeWithRequestId(e,t){try{return this.setCurrentRequest(e),t()}finally{this.resetCurrentRequest(e)}}executeCommand(e){let t=this.handlers.get(e.command);var r;return t?(r=this.executeWithRequestId(e.seq,()=>t(e)),this.projectService.enableRequestedPlugins(),r):(this.logger.msg("Unrecognized JSON command:"+uW(e),"Err"),this.doOutput(void 0,"unknown",e.seq,!1,"Unrecognized JSON command: "+e.command),{responseRequired:!1})}onMessage(t){var e;this.gcTimer.scheduleCollect(),this.performanceData=void 0;let r;this.logger.hasLevel(2)&&(r=this.hrtime(),this.logger.hasLevel(3))&&this.logger.info("request:"+_W(this.toStringMessage(t)));let n,i;try{n=this.parseMessage(t),i=n.arguments&&n.arguments.file?n.arguments:void 0,null!=Z4&&Z4.instant(Z4.Phase.Session,"request",{seq:n.seq,command:n.command}),null!=er&&er.logStartCommand(""+n.command,this.toStringMessage(t).substring(0,100)),null!=Z4&&Z4.push(Z4.Phase.Session,"executeCommand",{seq:n.seq,command:n.command},!0);var a,{response:o,responseRequired:s}=this.executeCommand(n);null!=Z4&&Z4.pop(),this.logger.hasLevel(2)&&(a=((1e9*(e=this.hrtime(r))[0]+e[1])/1e6).toFixed(4),s?this.logger.perftrc(`${n.seq}::${n.command}: elapsed time (in milliseconds) `+a):this.logger.perftrc(`${n.seq}::${n.command}: async elapsed time (in milliseconds) `+a)),null!=er&&er.logStopCommand(""+n.command,"Success"),null!=Z4&&Z4.instant(Z4.Phase.Session,"response",{seq:n.seq,command:n.command,success:!!o}),o?this.doOutput(o,n.command,n.seq,!0):s&&this.doOutput(void 0,n.command,n.seq,!1,"No content available.")}catch(e){null!=Z4&&Z4.popAll(),e instanceof Vr?(null!=er&&er.logStopCommand(""+(n&&n.command),"Canceled: "+e),null!=Z4&&Z4.instant(Z4.Phase.Session,"commandCanceled",{seq:null==n?void 0:n.seq,command:null==n?void 0:n.command}),this.doOutput({canceled:!0},n.command,n.seq,!0)):(this.logErrorWorker(e,this.toStringMessage(t),i),null!=er&&er.logStopCommand(""+(n&&n.command),"Error: "+e),null!=Z4&&Z4.instant(Z4.Phase.Session,"commandError",{seq:null==n?void 0:n.seq,command:null==n?void 0:n.command,message:e.message}),this.doOutput(void 0,n?n.command:"unknown",n?n.seq:0,!1,"Error processing request. "+e.message+"\n"+e.stack))}}parseMessage(e){return JSON.parse(e)}toStringMessage(e){return e}getFormatOptions(e){return this.projectService.getFormatCodeOptions(e)}getPreferences(e){return this.projectService.getPreferences(e)}getHostFormatOptions(){return this.projectService.getHostFormatCodeOptions()}getHostPreferences(){return this.projectService.getHostPreferences()}};function yve(e,t){return{start:t.positionToLineOffset(e.start),end:t.positionToLineOffset(J3(e))}}function vve(e,t,r){e=yve(e,r),t=t&&yve(t,r);return t?{...e,contextStart:t.start,contextEnd:t.end}:e}function bve(e,t){return Kye(e)?{line:(r=e.getLineAndCharacterOfPosition(t)).line+1,offset:r.character+1}:e.positionToLineOffset(t);var r}function xve(e,t,r,n){var{line:e,character:t}=no(Za(function(t,e,r){for(var{fileName:n,textChanges:i}of r)if(n===e)for(let e=i.length-1;0<=e;e--){var{newText:a,span:{start:o,length:s}}=i[e];t=t.slice(0,o)+a+t.slice(o+s)}return t}(e,t,n)),r);return{line:e+1,offset:t+1}}function Sve(e,{fileName:t,textSpan:r,contextSpan:n,isWriteAccess:i,isDefinition:a},{disableLineTextInReferences:o}){e=Y4.checkDefined(e.getScriptInfo(t)),r=vve(r,n,e),n=o?void 0:function(e,t){t=e.lineToTextSpan(t.start.line-1);return e.getSnapshot().getText(t.start,J3(t)).replace(/\r|\n/g,"")}(e,r);return{file:t,...r,lineText:n,isWriteAccess:i,isDefinition:a}}function kve(e){return void 0===e||e&&"object"==typeof e&&"string"==typeof e.exportName&&(void 0===e.fileName||"string"==typeof e.fileName)&&(void 0===e.ambientModuleName||"string"==typeof e.ambientModuleName&&(void 0===e.isPackageJsonImport||"boolean"==typeof e.isPackageJsonImport))}var Tve=(e=>(e[e.PreStart=0]="PreStart",e[e.Start=1]="Start",e[e.Entire=2]="Entire",e[e.Mid=3]="Mid",e[e.End=4]="End",e[e.PostEnd=5]="PostEnd",e))(Tve||{}),Cve=class{constructor(){this.goSubtree=!0,this.lineIndex=new Eve,this.endBranch=[],this.state=2,this.initialText="",this.trailingText="",this.lineIndex.root=new Fve,this.startPath=[this.lineIndex.root],this.stack=[this.lineIndex.root]}get done(){return!1}insertLines(e,i){i&&(this.trailingText=""),e=e?this.initialText+e+this.trailingText:this.initialText+this.trailingText;var a=Eve.linesFromText(e).lines;1this.currentVersion))return e%Nve.maxVersions}currentVersionToIndex(){return this.currentVersion%Nve.maxVersions}edit(e,t,r){this.changes.push(new wve(e,t,r)),(this.changes.length>Nve.changeNumberThreshold||t>Nve.changeLengthThreshold||r&&r.length>Nve.changeLengthThreshold)&&this.getSnapshot()}getSnapshot(){return this._getSnapshot()}_getSnapshot(){let t=this.versions[this.currentVersionToIndex()];if(0=Nve.maxVersions&&(this.minVersion=this.currentVersion-Nve.maxVersions+1)}return t}getSnapshotVersion(){return this._getSnapshot().version}getAbsolutePositionAndLineText(e){return this._getSnapshot().index.lineNumberToInfo(e)}lineOffsetToPosition(e,t){return this._getSnapshot().index.absolutePositionOfStartOfLine(e)+(t-1)}positionToLineOffset(e){return this._getSnapshot().index.positionToLineOffset(e)}lineToTextSpan(e){var t=this._getSnapshot().index,{lineText:r,absolutePosition:n}=t.lineNumberToInfo(e+1);return Qo(n,void 0!==r?r.length:t.absolutePositionOfStartOfLine(e+2)-n)}getTextChangesBetweenVersions(t,r){if(!(t=this.minVersion){var n,i=[];for(let e=t+1;e<=r;e++)for(n of this.versions[this.versionToIndex(e)].changesSincePreviousVersion)i.push(n.getTextChangeRange());return ns(i)}}getLineCount(){return this._getSnapshot().index.getLineCount()}static fromString(e){var t=new Nve,r=new Pve(0,t,new Eve),e=(t.versions[t.currentVersion]=r,Eve.linesFromText(e));return r.index.load(e.lines),t}},Dve=(Nve.changeNumberThreshold=8,Nve.changeLengthThreshold=256,Nve.maxVersions=8,Nve),Pve=class Kve{constructor(e,t,r,n=Z0e){this.version=e,this.cache=t,this.index=r,this.changesSincePreviousVersion=n}getText(e,t){return this.index.getText(e,t-e)}getLength(){return this.index.getLength()}getChangeRange(e){if(e instanceof Kve&&this.cache===e.cache)return this.version<=e.version?rs:this.cache.getTextChangesBetweenVersions(e.version,this.version)}},Eve=class Gve{constructor(){this.checkEdits=!1}absolutePositionOfStartOfLine(e){return this.lineNumberToInfo(e).absolutePosition}positionToLineOffset(e){var{oneBasedLine:e,zeroBasedColumn:t}=this.root.charOffsetToLineInfo(1,e);return{line:e,offset:t+1}}positionToColumnAndLineText(e){return this.root.charOffsetToLineInfo(1,e)}getLineCount(){return this.root.lineCount()}lineNumberToInfo(e){var t;return e<=this.getLineCount()?({position:e,leaf:t}=this.root.lineNumberToInfo(e,0),{absolutePosition:e,lineText:t&&t.text}):{absolutePosition:this.root.charCount(),lineText:void 0}}load(t){if(0{n=n.concat(r.text.substring(e,e+t))}}),n}getLength(){return this.root.charCount()}every(n,e,t){t=t||this.root.charCount();var r={goSubtree:!0,done:!1,leaf(e,t,r){n(r,e,t)||(this.done=!0)}};return this.walk(e,t-e,r),!r.done}edit(r,n,i){if(0!==this.root.charCount()){let e;this.checkEdits&&(s=this.getText(0,this.root.charCount()),e=s.slice(0,r)+i+s.slice(r+n));var a,o,s=new Cve;let t=!1;return r>=this.root.charCount()?(r=this.root.charCount()-1,o=this.getText(r,1),i=i?o+i:o,n=0,t=!0):0=a;)this.skipChild(o,r,i,n,0),o-=a,i++,a=this.children[i].charCount();if(o+r<=a){if(this.execWalk(o,r,n,i,2))return}else{if(this.execWalk(o,a-o,n,i,1))return;let e=r-(a-o);i++;t=this.children[i];for(a=t.charCount();e>a;){if(this.execWalk(0,a,n,i,3))return;e-=a,i++,a=this.children[i].charCount()}if(0t)return r.isLeaf()?{oneBasedLine:e,zeroBasedColumn:t,lineText:r.text}:r.charOffsetToLineInfo(e,t);t-=r.charCount(),e+=r.lineCount()}var n=this.lineCount();return 0===n?{oneBasedLine:1,zeroBasedColumn:0,lineText:void 0}:{oneBasedLine:n,zeroBasedColumn:Y4.checkDefined(this.lineNumberToInfo(n,0).leaf).charCount(),lineText:void 0}}lineNumberToInfo(e,t){for(var r of this.children){var n=r.lineCount();if(e<=n)return r.isLeaf()?{position:t,leaf:r}:r.lineNumberToInfo(e,t);e-=n,t+=r.charCount()}return{position:t,leaf:void 0}}splitAfter(e){let t;var r=this.children.length,n=++e;if(e{(this.packageInstalledPromise??(this.packageInstalledPromise=new Map)).set(this.packageInstallId,{resolve:e,reject:t})});return this.installer.send(e),t}attach(e){this.projectService=e,this.installer=this.createInstallerProcess()}onProjectClosed(e){this.installer.send({projectName:e.getProjectName(),kind:"closeProject"})}enqueueInstallTypingsRequest(e,t,r){e=t1e(e,t,r);this.logger.hasLevel(3)&&this.logger.info("TIAdapter:: Scheduling throttled operation:"+uW(e)),this.activeRequestCount{this.logger.hasLevel(3)&&this.logger.info("TIAdapter:: Sending request:"+uW(e)),this.installer.send(e)},Ive.requestDelayMillis,e.projectName+"::"+e.kind)}},Ove=(Ive.requestDelayMillis=100,Ive),Lve={};r(Lve,{ActionInvalidate:()=>ZV,ActionPackageInstalled:()=>eW,ActionSet:()=>YV,ActionWatchTypingLocations:()=>aW,Arguments:()=>XV,AutoImportProviderProject:()=>q1e,AuxiliaryProject:()=>J1e,CharRangeSection:()=>Tve,CloseFileWatcherEvent:()=>cye,CommandNames:()=>nve,ConfigFileDiagEvent:()=>rye,ConfiguredProject:()=>U1e,ConfiguredProjectLoadKind:()=>Dye,CreateDirectoryWatcherEvent:()=>sye,CreateFileWatcherEvent:()=>oye,Errors:()=>Q0e,EventBeginInstallTypes:()=>rW,EventEndInstallTypes:()=>nW,EventInitializationFailed:()=>iW,EventTypesRegistry:()=>tW,ExternalProject:()=>V1e,GcTimer:()=>d1e,InferredProject:()=>B1e,LargeFileReferencedEvent:()=>tye,LineIndex:()=>Eve,LineLeaf:()=>Ave,LineNode:()=>Fve,LogLevel:()=>Y0e,Msg:()=>e1e,OpenFileInfoTelemetryEvent:()=>aye,Project:()=>M1e,ProjectInfoTelemetryEvent:()=>iye,ProjectKind:()=>A1e,ProjectLanguageServiceStateEvent:()=>nye,ProjectLoadingFinishEvent:()=>eye,ProjectLoadingStartEvent:()=>Z1e,ProjectService:()=>Hye,ProjectsUpdatedInBackgroundEvent:()=>Y1e,ScriptInfo:()=>D1e,ScriptVersionCache:()=>Dve,Session:()=>hve,TextStorage:()=>w1e,ThrottledOperations:()=>u1e,TypingsCache:()=>F1e,TypingsInstallerAdapter:()=>Ove,allFilesAreJsOrDts:()=>L1e,allRootFilesAreJsOrDts:()=>O1e,asNormalizedPath:()=>i1e,convertCompilerOptions:()=>gye,convertFormatOptions:()=>mye,convertScriptKindName:()=>bye,convertTypeAcquisition:()=>yye,convertUserPreferences:()=>xye,convertWatchOptions:()=>hye,countEachFileTypes:()=>I1e,createInstallTypingsRequest:()=>t1e,createModuleSpecifierCache:()=>$ye,createNormalizedPathMap:()=>a1e,createPackageJsonCache:()=>Xye,createSortedArray:()=>_1e,emptyArray:()=>Z0e,findArgument:()=>sW,forEachResolvedProjectReferenceProject:()=>Pye,formatDiagnosticToProtocol:()=>rve,formatMessage:()=>ive,getBaseConfigFileName:()=>p1e,getLocationInNewDocument:()=>xve,hasArgument:()=>oW,hasNoTypeScriptSource:()=>j1e,indent:()=>_W,isBackgroundProject:()=>G1e,isConfigFile:()=>Kye,isConfiguredProject:()=>H1e,isDynamicFileName:()=>N1e,isExternalProject:()=>K1e,isInferredProject:()=>W1e,isInferredProjectName:()=>o1e,isProjectDeferredClose:()=>$1e,makeAutoImportProviderProjectName:()=>c1e,makeAuxiliaryProjectName:()=>l1e,makeInferredProjectName:()=>s1e,maxFileSize:()=>Q1e,maxProgramSizeForNonTsFiles:()=>X1e,normalizedPathToPath:()=>n1e,nowString:()=>cW,nullCancellationToken:()=>Qye,nullTypingsInstaller:()=>P1e,protocol:()=>m1e,removeSorted:()=>f1e,stringifyIndented:()=>uW,toEvent:()=>ove,toNormalizedPath:()=>r1e,tryConvertScriptKindName:()=>vye,typingsInstaller:()=>W0e,updateProjectIfDirty:()=>jye}),"undefined"!=typeof console&&(Y4.loggingHost={log(e,t){switch(e){case 1:return console.error(t);case 2:return console.warn(t);case 3:case 4:return console.log(t)}}})}.call(this)}.call(this,t2e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},t2e("buffer").Buffer,arguments[3],arguments[4],arguments[5],arguments[6],"/node_modules/typescript/lib/typescript.js","/node_modules/typescript/lib")},{_process:46,buffer:1,crypto:1,fs:1,inspector:1,os:1,path:1,perf_hooks:1,"source-map-support":1}],48:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0});let w=e("core-types-json-schema"),N=e("core-types-ts/dist/lib/ts-to-core-types"),g=e("core-types-ts"),D=e("./utils/sharedUtils"),P=e("./utils/constants"),E=e("./utils/nosqlUtils");Draw.loadPlugin(function(v){var e=document.createElement("div");e.style.userSelect="none",e.style.overflow="hidden",e.style.padding="10px",e.style.height="100%";let i=document.createElement("textarea"),t=(i.style.height="200px",i.style.width="100%","-- click a nosql type button");i.value=t,mxUtils.br(e),e.appendChild(i);var r=v.menus.get("exportAs");let n="tonosql=To NoSQL",a=(r&&!window.VsCodeApi||(n="tonosql=Export As NoSQL"),mxResources.parse(n),new mxWindow(mxResources.get("tonosql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));function o(e){var t,r=(0,D.getMermaidDiagramDb)(v,e),r=(0,E.dbToOpenApi)(r);let n="";"ts"==e?(t=(0,w.convertOpenApiToCoreTypes)(r)["data"],t=(0,g.convertCoreTypesToTypeScript)(t)["data"],n=`/* Generated in drawio Database: ${e} Plugin: nosql - Version: ${q.pluginVersion} + Version: ${P.pluginVersion} */ -`+n,n+=t):"openapi"==e&&(n=JSON.stringify(r,null,2)),i.value=n}a.destroyOnClose=!1,a.setMaximizable(!1),a.setResizable(!1),a.setClosable(!0),mxUtils.br(e);var s=mxUtils.button(mxResources.get("reset"),function(){i.value=t});s.style.marginTop="8px",s.style.marginRight="4px",s.style.padding="4px",e.appendChild(s);let c=mxUtils.button("TS",function(){o("ts")}),E=(c.style.marginTop="8px",c.style.padding="4px",e.appendChild(c),(c=mxUtils.button("OpenAPI",function(){o("openapi")})).style.marginTop="8px",c.style.padding="4px",e.appendChild(c),P.actions.addAction("tonosql",function(){a.setVisible(!a.isVisible()),a.isVisible()&&i.focus()}),[]),F=[],A=[],I=[],O=null,L=null,j=0,R=0;s=document.createElement("div");s.style.userSelect="none",s.style.overflow="hidden",s.style.padding="10px",s.style.height="100%";let l=document.createElement("textarea"),_=(l.style.height="200px",l.style.width="100%",`/* +`+n,n+=t):"openapi"==e&&(n=JSON.stringify(r,null,2)),i.value=n}a.destroyOnClose=!1,a.setMaximizable(!1),a.setResizable(!1),a.setClosable(!0),mxUtils.br(e);var s=mxUtils.button(mxResources.get("reset"),function(){i.value=t});s.style.marginTop="8px",s.style.marginRight="4px",s.style.padding="4px",e.appendChild(s);let c=mxUtils.button("TS",function(){o("ts")}),b=(c.style.marginTop="8px",c.style.padding="4px",e.appendChild(c),(c=mxUtils.button("OpenAPI",function(){o("openapi")})).style.marginTop="8px",c.style.padding="4px",e.appendChild(c),v.actions.addAction("tonosql",function(){a.setVisible(!a.isVisible()),a.isVisible()&&i.focus()}),[]),d=[],p=[],x=[],f=null,S=null,k=0,T=0;s=document.createElement("div");s.style.userSelect="none",s.style.overflow="hidden",s.style.padding="10px",s.style.height="100%";let l=document.createElement("textarea"),_=(l.style.height="200px",l.style.width="100%",`/* Drawio default value Plugin: nosql - Version: ${q.pluginVersion} + Version: ${P.pluginVersion} */ @@ -381,7 +381,7 @@ export interface Child { "openapi": "3.0.0", "info": { "title": "nosql plugin sample", - "version": "${q.pluginVersion}", + "version": "${P.pluginVersion}", "x-comment": "Generated by core-types-json-schema (https://github.com/grantila/core-types-json-schema)" }, "paths": {}, @@ -446,4 +446,4 @@ export interface Child { } } } - `,M=(l.value=_,mxUtils.br(s),s.appendChild(l),mxResources.parse("fromNoSql=From NoSQL"),new mxWindow(mxResources.get("fromNoSql"),s,document.body.offsetWidth-480,140,320,320,!0,!0));function d(t,r){var n,i,a,o;I=[],O=null,L=null;try{let e=null;var s,c,l,_,u,d={title:"nosql default options",version:q.pluginVersion},p=("openapi"==r?(s=JSON.parse(t),c=(0,B.convertOpenApiToCoreTypes)(s)["data"],l=(0,B.convertCoreTypesToJsonSchema)(c)["data"],e=(0,B.jsonSchemaDocumentToOpenApi)(l,d)):"ts"==r&&(_=(0,J.convertTypeScriptToCoreTypes)(t)["data"],u=(0,B.convertCoreTypesToJsonSchema)(_)["data"],e=(0,B.jsonSchemaDocumentToOpenApi)(u,d)),null==(n=null===e||void 0===e?void 0:e.components)?void 0:n.schemas);if(p){var f,m,g,h={Dialect:"nosql",TableList:[],PrimaryKeyList:[],ForeignKeyList:[]};for(f in p)if(Object.prototype.hasOwnProperty.call(p,f)){var y,v=p[f],b={Name:(0,z.dbTypeEnds)(f),Properties:[]};for(y in v.properties)if(Object.prototype.hasOwnProperty.call(v.properties,y)){var x,S,k=v.properties[y],T=function(e,t,r){let n,i=(null!==(n=r.type)&&void 0!==n?n:"object").toString();r.nullable&&(i+=" nullable");r={Name:(0,z.dbTypeEnds)(t),IsPrimaryKey:!1,IsForeignKey:!1,ColumnProperties:i,TableName:(0,z.dbTypeEnds)(e),ForeignKey:[]};return r}(f,y,k);if(T.ColumnProperties.includes("object")||T.ColumnProperties.includes("array")){let e=null;k.$ref?e=k.$ref.split("/").pop():k.items&&"object"==typeof k.items&&(e=null==(i=k.items.$ref)?void 0:i.split("/").pop()),e&&(x={PrimaryKeyTableName:(0,z.dbTypeEnds)(f),ReferencesTableName:(0,z.dbTypeEnds)(e),PrimaryKeyName:(0,z.dbTypeEnds)(y),ReferencesPropertyName:"",IsDestination:!1},S={ReferencesTableName:(0,z.dbTypeEnds)(f),PrimaryKeyTableName:(0,z.dbTypeEnds)(e),ReferencesPropertyName:(0,z.dbTypeEnds)(y),PrimaryKeyName:"",IsDestination:!0},h.ForeignKeyList.push(S),h.ForeignKeyList.push(x),T.IsForeignKey=!0)}b.Properties.push(T)}h.TableList.push(b)}for(let e=0;ee.Name==t.ReferencesTableName))?void 0:a.Properties[0])&&(h.ForeignKeyList[e].ReferencesPropertyName=m.Name),t.PrimaryKeyName||(g=null==(o=h.TableList.find(e=>e.Name==t.PrimaryKeyTableName))?void 0:o.Properties[0])&&(h.ForeignKeyList[e].PrimaryKeyName=g.Name)}E=h.ForeignKeyList,F=h.PrimaryKeyList,A=h.TableList,R=A.length;var C=r;if(A.forEach(function(r){var e,t=100+r.Name.length;(O=new mxCell(r.Name,new mxGeometry(j,0,t,26),"swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=default;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=default;align=center;")).vertex=!0,L&&null!==(e=P.editor.graph.getPreferredSizeForCell(L))&&(O.geometry.width=e.width+t),I.push(O),r.Properties.forEach(function(e){var t;e=e,r.Name,t=e.Name+(e.ColumnProperties?" "+e.ColumnProperties:""),(L=new mxCell(t,new mxGeometry(0,0,90,26),"shape=partialRectangle;top=0;left=0;right=0;bottom=0;align=left;verticalAlign=top;spacingTop=-2;fillColor=none;spacingLeft=64;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;dropTarget=0;")).vertex=!0,t=e.IsPrimaryKey&&e.IsForeignKey?"PK | FK":e.IsPrimaryKey?"PK":e.IsForeignKey?"FK":"",(e=sb.cloneCell(L,t)).connectable=!1,e.style="shape=partialRectangle;top=0;left=0;bottom=0;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=180;points=[];portConstraint=eastwest;part=1;",e.geometry.width=54,e.geometry.height=26,L.insert(e),t=P.editor.graph.getPreferredSizeForCell(L),O&&(null!==t&&O.geometry.width-1!==["FK","PK"].findIndex(e=>e==t.value.toUpperCase())||-1!=t.value.toUpperCase().indexOf("PK,"));if(u&&(_.attributeKeyType=u.value,"PK"!=_.attributeKeyType)&&-1!=_.attributeKeyType.indexOf("PK")&&(_.attributeKeyType="PK"),s.attributes.push(_),c.edges&&c.edges.length)for(let e=0;e-1!=t.toLocaleLowerCase().indexOf(e)),p=r&&-1!=p.findIndex(e=>-1!=r.toLocaleLowerCase().indexOf(e));if(!p&&!f||p&&f){if(p&&f){var m,p=S(d.source.value,l),g=(p.attributeKeyType="PK",v=p.attributeName,x(d.source.parent.value)),h=S(d.target.value,l),y=(h.attributeKeyType="PK",m=h.attributeName,x(d.target.parent.value)),p={name:x(g)+"_"+x(y),attributes:[p,h]};n[p.name]||(n[p.name]=p);let t={entityA:g,entityB:p.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${g}.${v}] to [${p.name}.${v}]`},r=(-1==i.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&i.push(t),{entityA:y,entityB:p.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${y}.${m}] to [${p.name}.${m}]`});-1==i.findIndex(e=>e.entityA==r.entityA&&e.entityB==r.entityB&&e.roleA==r.roleA)&&i.push(r)}}else{h=S(d.source.value,l).attributeName;var v,g=x(d.source.parent.value),y=(v=S(d.target.value,l).attributeName,x(d.target.parent.value));let t={entityA:f?g:y,entityB:f?y:g,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:f?`[${g}.${h}] to [${y}.${v}]`:`[${y}.${v}] to [${g}.${h}]`};-1==i.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&i.push(t)}}}}}if(n[s.name]){let e=2;for(;n[s.name+e.toString()];)e++;n[s.name+e.toString()]=s}else n[s.name]=s}}e=new class{constructor(e,t){this.entities=e,this.relationships=t}getEntities(){return this.entities}getRelationships(){return this.relationships}}(n,i);return e}},{}]},{},[48]); \ No newline at end of file + `,C=(l.value=_,mxUtils.br(s),s.appendChild(l),mxResources.parse("fromNoSql=From NoSQL"),new mxWindow(mxResources.get("fromNoSql"),s,document.body.offsetWidth-480,140,320,320,!0,!0));function m(t,r){var n;x=[],f=null,S=null;try{let e=null;var i,a,o,s,c,l={title:"nosql default options",version:P.pluginVersion},_=("openapi"==r?(i=JSON.parse(t),a=(0,w.convertOpenApiToCoreTypes)(i)["data"],o=(0,w.convertCoreTypesToJsonSchema)(a)["data"],(0,w.jsonSchemaDocumentToOpenApi)(o,l),e=i):"ts"==r&&(s=(0,N.convertTypeScriptToCoreTypes)(t)["data"],c=(0,w.convertCoreTypesToJsonSchema)(s)["data"],e=(0,w.jsonSchemaDocumentToOpenApi)(c,l)),null==(n=null===e||void 0===e?void 0:e.components)?void 0:n.schemas);if(_){var u=(0,E.ConvertOpenApiToDatabaseModel)(_),m=(b=u.ForeignKeyList,d=u.PrimaryKeyList,p=u.TableList,T=p.length,r);if(p.forEach(function(r){var e,t=100+r.Name.length;(f=new mxCell(r.Name,new mxGeometry(k,0,t,26),"swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=default;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=default;align=center;")).vertex=!0,S&&null!==(e=v.editor.graph.getPreferredSizeForCell(S))&&(f.geometry.width=e.width+t),x.push(f),r.Properties.forEach(function(e){var t;e=e,r.Name,t=e.Name+(e.ColumnProperties?" "+e.ColumnProperties:""),(S=new mxCell(t,new mxGeometry(0,0,90,26),"shape=partialRectangle;top=0;left=0;right=0;bottom=0;align=left;verticalAlign=top;spacingTop=-2;fillColor=none;spacingLeft=64;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;dropTarget=0;")).vertex=!0,t=e.IsPrimaryKey&&e.IsForeignKey?"PK | FK":e.IsPrimaryKey?"PK":e.IsForeignKey?"FK":"",(e=sb.cloneCell(S,t)).connectable=!1,e.style="shape=partialRectangle;top=0;left=0;bottom=0;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=180;points=[];portConstraint=eastwest;part=1;",e.geometry.width=54,e.geometry.height=26,S.insert(e),t=v.editor.graph.getPreferredSizeForCell(S),f&&(null!==t&&f.geometry.widthe.Name==t.ReferencesTableName))?void 0:u.Properties[0])&&(r.ForeignKeyList[e].ReferencesPropertyName=u.Name),t.PrimaryKeyName||(d=null==(u=r.TableList.find(e=>e.Name==t.PrimaryKeyTableName))?void 0:u.Properties[0])&&(r.ForeignKeyList[e].PrimaryKeyName=d.Name)}return r};let g=e("./constants"),h=e("./sharedUtils");function p(e,t,r){let n,i=(null!=(n=r.type)?n:"object").toString();r.enum?i=""+JSON.stringify(r.enum):r.nullable&&(i+=" nullable");r=(0,h.generateComment)(r.description,r.format),r&&(i+=" "+r),r={Name:(0,h.dbTypeEnds)(t),IsPrimaryKey:!1,IsForeignKey:!1,ColumnProperties:i,TableName:(0,h.dbTypeEnds)(e),ForeignKey:[]};return r}},{"./constants":49,"./sharedUtils":51}],51:[function(e,t,r){Object.defineProperty(r,"__esModule",{value:!0}),r.GetColumnQuantifiers=C,r.removeHtml=n,r.dbTypeEnds=function(e){return`\`${e}\``},r.RemoveNameQuantifiers=w,r.getDbLabel=N,r.entityName=function(e,t){let r="";e&&(r+=""+e);t&&(r+=" @format "+t);r=r&&`/** ${r=r.trim()} */`;return r},r.getCommentIndexes=D,r.getMermaidDiagramDb=function(e,i){var t=e.editor.graph.getModel(),a={},o=[];for(var s in t.cells)if(Object.hasOwnProperty.call(t.cells,s)){var c=t.cells[s];if(-1!==c.mxObjectId.indexOf("mxCell")&&c.style&&c.style.trim().startsWith("swimlane;")){let t=c.value.toString(),r="",n="";if(null!==t&&void 0!==t&&t.includes(T.commentColumnQuantifiers.Start)&&null!==t&&void 0!==t&&t.includes(T.commentColumnQuantifiers.End)){let e=t.toString();var s=D(e),l=s.start,_=s.end;t=e.substring(0,s.beforeStart),-1!==(e=e.substring(l,_)).indexOf(T.formatKeyword)&&(s=e.indexOf(T.formatKeyword),n=e.substring(s+T.formatKeyword.length).trim(),e=e.substring(0,s)),e&&(r=e)}var u={name:w(t),attributes:[]},l=E(r,n);l&&(u.name+=l);for(let e=0;e-1!==["FK","PK"].findIndex(e=>e==t.value.toUpperCase())||-1!=t.value.toUpperCase().indexOf("PK,"));if(m&&(f.attributeKeyType=m.value,"PK"!=f.attributeKeyType)&&-1!=f.attributeKeyType.indexOf("PK")&&(f.attributeKeyType="PK"),u.attributes.push(f),d.edges&&d.edges.length)for(let e=0;e-1!=t.toLocaleLowerCase().indexOf(e)),h=r&&-1!=h.findIndex(e=>-1!=r.toLocaleLowerCase().indexOf(e));if(!h&&!y||h&&y){if(h&&y){var v,h=N(g.source.value,p),b=(h.attributeKeyType="PK",k=h.attributeName,w(g.source.parent.value)),x=N(g.target.value,p),S=(x.attributeKeyType="PK",v=x.attributeName,w(g.target.parent.value)),h={name:w(b)+"_"+w(S),attributes:[h,x]};a[h.name]||(a[h.name]=h);let t={entityA:b,entityB:h.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${b}.${k}] to [${h.name}.${k}]`},r=(-1==o.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&o.push(t),{entityA:S,entityB:h.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${S}.${v}] to [${h.name}.${v}]`});-1==o.findIndex(e=>e.entityA==r.entityA&&e.entityB==r.entityB&&e.roleA==r.roleA)&&o.push(r)}}else{x=N(g.source.value,p).attributeName;var k,b=w(g.source.parent.value),S=(k=N(g.target.value,p).attributeName,w(g.target.parent.value));let t={entityA:y?b:S,entityB:y?S:b,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:y?`[${b}.${x}] to [${S}.${k}]`:`[${S}.${k}] to [${b}.${x}]`};-1==o.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&o.push(t)}}}}}if(a[u.name]){let e=2;for(;a[u.name+e.toString()];)e++;a[u.name+e.toString()]=u}else a[u.name]=u}}e=P(a,o);return e},r.GenerateDatabaseModel=P,r.generateComment=E;let T=e("./constants");function C(e){var t={Start:'"',End:'"'};return e&&["mysql","ts","openapi"].includes(e)?(t.Start="`",t.End="`"):"sqlserver"==e&&(t.Start="[",t.End="]"),t}function n(e){var t=document.createElement("div"),e=(t.innerHTML=e,t.textContent||t.innerText||"");return t.remove(),e}function w(e){return e.replace(/\[|\]|\(|\"|\'|\`/g,"").trim()}function N(e,t){let r=n(e);e=(r=r.toString().replace(/\s+/g," "))[0]==t.Start&&-1!==r.indexOf(t.End+" ")?r.indexOf(t.End+" "):r.indexOf(" "),t=r.substring(e+1).trim();return{attributeName:w(r.substring(0,e+1)),attributeType:t}}function D(e){let t=!1;return{beforeStart:(t=-1!==e.indexOf(T.commentColumnQuantifiers.Start)&&-1!==e.indexOf(T.commentColumnQuantifiers.End)?!0:t)?e.indexOf(T.commentColumnQuantifiers.Start):-1,start:t?e.indexOf(T.commentColumnQuantifiers.Start)+T.commentColumnQuantifiers.Start.length:-1,end:t?e.indexOf(T.commentColumnQuantifiers.End)-1:-1}}function P(e,t){return new class{constructor(e,t){this.entities=e,this.relationships=t}getEntities(){return this.entities}getRelationships(){return this.relationships}}(e,t)}function E(e,t){let r="";return e&&(r+=""+e),t&&(r+=" @format "+t),r&&(r=r.trim(),r=`${T.commentColumnQuantifiers.Start} ${r} `+T.commentColumnQuantifiers.End),r}},{"./constants":49}]},{},[48]); \ No newline at end of file diff --git a/dist/nosql.js b/dist/nosql.js index 3257270..3ee4ac5 100644 --- a/dist/nosql.js +++ b/dist/nosql.js @@ -4603,9 +4603,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); const core_types_json_schema_1 = require("core-types-json-schema"); const sharedUtils_1 = require("./utils/sharedUtils"); const constants_1 = require("./utils/constants"); +const nosqlUtils_1 = require("./utils/nosqlUtils"); /** * SQL Tools Plugin for importing and exporting typescript interfaces. - * Version: 0.0.4 + * Version: 0.0.5 */ Draw.loadPlugin(function (ui) { //Create Base div @@ -4638,7 +4639,7 @@ Draw.loadPlugin(function (ui) { function generateNoSql(type) { // get diagram model const db = (0, sharedUtils_1.getMermaidDiagramDb)(ui, type); - const openapi = dbToOpenApi(db); + const openapi = (0, nosqlUtils_1.dbToOpenApi)(db); let result = ""; if (type == "openapi") { result = JSON.stringify(openapi, null, 2); @@ -4649,59 +4650,6 @@ Draw.loadPlugin(function (ui) { sqlInputGenSQL.value = result; } ; - /** - * convert db to openapi - * @param db - * @returns - */ - function dbToOpenApi(db) { - var _a, _b, _c, _d, _e; - const result = { - openapi: "3.0.0", - info: { - // drawio file name? - title: "drawio nosql export", - version: constants_1.pluginVersion, - "x-comment": "Generated by from drawio uml using plugin nosql" - }, - paths: {}, - components: { - schemas: {} - } - }; - const schema = {}; - const entities = db.getEntities(); - for (const key in entities) { - if (Object.prototype.hasOwnProperty.call(entities, key)) { - const entity = entities[key]; - if (schema[key]) { - continue; - } - schema[key] = { - type: "object", - title: key, - additionalProperties: false, - properties: {} - }; - for (let p = 0; p < entity.attributes.length; p++) { - const attribute = entity.attributes[p]; - const propName = attribute.attributeName; - if (!propName || schema[key].properties[propName]) { - continue; - } - const attType = (_b = (_a = attribute.attributeType) === null || _a === void 0 ? void 0 : _a.split(" ")) !== null && _b !== void 0 ? _b : []; - const property = { - title: `${key}.${propName}`, - nullable: (_d = (_c = attribute.attributeType) === null || _c === void 0 ? void 0 : _c.includes("nullable")) !== null && _d !== void 0 ? _d : false, - type: ((_e = attType[0]) !== null && _e !== void 0 ? _e : "string") - }; - schema[key].properties[attribute.attributeName] = property; - } - } - } - result.components.schemas = schema; - return result; - } mxUtils.br(divGenSQL); const resetBtnGenSQL = mxUtils.button(mxResources.get("reset"), function () { sqlInputGenSQL.value = sqlExportDefault; @@ -4844,11 +4792,10 @@ Draw.loadPlugin(function (ui) { tableCell.insert(rowCell); tableCell.geometry.height += 26; } - rowCell = rowCell; } ; function parseFromInput(text, type) { - var _a, _b, _c, _d; + var _a; // reset values cells = []; tableCell = null; @@ -4864,84 +4811,16 @@ Draw.loadPlugin(function (ui) { const data = JSON.parse(text); const { data: doc } = (0, core_types_json_schema_1.convertOpenApiToCoreTypes)(data); const { data: jsonSchema } = (0, core_types_json_schema_1.convertCoreTypesToJsonSchema)(doc); - openApi = (0, core_types_json_schema_1.jsonSchemaDocumentToOpenApi)(jsonSchema, openApiOptions); + // was losing format option, just going to check if exception thrown here + (0, core_types_json_schema_1.jsonSchemaDocumentToOpenApi)(jsonSchema, openApiOptions); + openApi = data; } else { throw new Error(`type:${type} is not supported`); } const schemas = (_a = openApi === null || openApi === void 0 ? void 0 : openApi.components) === null || _a === void 0 ? void 0 : _a.schemas; if (schemas) { - const models = { - Dialect: "nosql", - TableList: [], - PrimaryKeyList: [], - ForeignKeyList: [], - }; - for (const key in schemas) { - if (Object.prototype.hasOwnProperty.call(schemas, key)) { - const schema = schemas[key]; - const tableModel = { - Name: (0, sharedUtils_1.dbTypeEnds)(key), - Properties: [], - }; - for (const propertyKey in schema.properties) { - if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { - const property = schema.properties[propertyKey]; - const propertyModel = GeneratePropertyModel(key, propertyKey, property); - if (propertyModel.ColumnProperties.includes("object") || - propertyModel.ColumnProperties.includes("array")) { - let refName = null; - if (property.$ref) { - refName = property.$ref.split("/").pop(); - } - else if (property.items && typeof property.items == "object") { - refName = (_b = property.items.$ref) === null || _b === void 0 ? void 0 : _b.split("/").pop(); - } - if (refName) { - const primaryKeyModel = { - PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(key), - ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(refName), - PrimaryKeyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), - // should just point to first property in uml table - ReferencesPropertyName: "", - IsDestination: false - }; - const foreignKeyModel = { - ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(key), - PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(refName), - ReferencesPropertyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), - // should just point to first property in uml table - PrimaryKeyName: "", - IsDestination: true - }; - models.ForeignKeyList.push(foreignKeyModel); - models.ForeignKeyList.push(primaryKeyModel); - propertyModel.IsForeignKey = true; - } - } - tableModel.Properties.push(propertyModel); - } - } - models.TableList.push(tableModel); - } - } - for (let i = 0; i < models.ForeignKeyList.length; i++) { - const fk = models.ForeignKeyList[i]; - if (!fk.ReferencesPropertyName) { - // match to first entry - const property = (_c = models.TableList.find(t => t.Name == fk.ReferencesTableName)) === null || _c === void 0 ? void 0 : _c.Properties[0]; - if (property) { - models.ForeignKeyList[i].ReferencesPropertyName = property.Name; - } - } - if (!fk.PrimaryKeyName) { - // match to first entry - const property = (_d = models.TableList.find(t => t.Name == fk.PrimaryKeyTableName)) === null || _d === void 0 ? void 0 : _d.Properties[0]; - if (property) { - models.ForeignKeyList[i].PrimaryKeyName = property.Name; - } - } - } + const models = (0, nosqlUtils_1.ConvertOpenApiToDatabaseModel)(schemas); foreignKeyList = models.ForeignKeyList; primaryKeyList = models.PrimaryKeyList; tableList = models.TableList; @@ -5104,13 +4983,192 @@ Draw.loadPlugin(function (ui) { } } }); + +},{"./utils/constants":29,"./utils/nosqlUtils":30,"./utils/sharedUtils":31,"core-types-json-schema":1}],29:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.validEnumTypes = exports.enumKeyword = exports.formatKeyword = exports.commentColumnQuantifiers = exports.pluginVersion = void 0; +// export sql methods +exports.pluginVersion = "0.0.5"; +exports.commentColumnQuantifiers = { + Start: "/**", + End: "*/", +}; +exports.formatKeyword = "@format"; +exports.enumKeyword = "enum"; +exports.validEnumTypes = ["string", "number", "integer", "boolean"]; + +},{}],30:[function(require,module,exports){ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.dbToOpenApi = dbToOpenApi; +exports.GeneratePropertyModel = GeneratePropertyModel; +exports.ConvertOpenApiToDatabaseModel = ConvertOpenApiToDatabaseModel; +const constants_1 = require("./constants"); +const sharedUtils_1 = require("./sharedUtils"); +/** + * convert db to openapi + * @param db + * @returns + */ +function dbToOpenApi(db) { + var _a, _b, _c, _d, _e, _f, _g; + const result = { + openapi: "3.0.0", + info: { + // drawio file name? + title: "drawio nosql export", + version: constants_1.pluginVersion, + "x-comment": "Generated by from drawio uml using plugin nosql", + }, + paths: {}, + components: { + schemas: {}, + }, + }; + const schema = {}; + const entities = db.getEntities(); + for (const key in entities) { + if (Object.prototype.hasOwnProperty.call(entities, key)) { + let schemaKey = key; + const entity = entities[key]; + let commentIndexes = (0, sharedUtils_1.getCommentIndexes)(key); + let description = ""; + let formatValue = ""; + if (commentIndexes.start > -1 && commentIndexes.end > -1) { + let result = schemaKey.toString().trim(); + commentIndexes = (0, sharedUtils_1.getCommentIndexes)(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + schemaKey = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex).trim(); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result.substring(formatIndex + constants_1.formatKeyword.length).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + } + if (schema[schemaKey]) { + continue; + } + schema[schemaKey] = { + type: "object", + title: schemaKey, + additionalProperties: false, + properties: {}, + }; + if (description) { + schema[schemaKey].description = description.trim(); + } + if (formatValue) { + schema[schemaKey].format = formatValue.trim(); + } + for (let p = 0; p < entity.attributes.length; p++) { + const attribute = entity.attributes[p]; + const propName = attribute.attributeName.trim(); + if (!propName || schema[schemaKey].properties[propName]) { + continue; + } + // TODO: trim double spaces + const attType = (_b = (_a = attribute.attributeType) === null || _a === void 0 ? void 0 : _a.trim().split(" ")) !== null && _b !== void 0 ? _b : []; + // check if enum + let isEnum = false; + let type = ((_c = attType[0]) !== null && _c !== void 0 ? _c : "string"); + if (propName.indexOf(constants_1.enumKeyword) !== -1) { + const splitPropName = propName.split(" "); + if (splitPropName.length == 2 && + constants_1.validEnumTypes.indexOf(splitPropName[0]) !== -1 && + splitPropName[1] == constants_1.enumKeyword) { + isEnum = true; + type = splitPropName[0]; + } + } + // extract desciption /** asdf */ + let description = ""; + let formatValue = ""; + let enumValues = null; + if (((_d = attribute.attributeType) === null || _d === void 0 ? void 0 : _d.includes(constants_1.commentColumnQuantifiers.Start)) && + ((_e = attribute.attributeType) === null || _e === void 0 ? void 0 : _e.includes(constants_1.commentColumnQuantifiers.End))) { + let result = attribute.attributeType; + const commentIndexes = (0, sharedUtils_1.getCommentIndexes)(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + const enumRaw = result.substring(0, commentIndexes.beforeStart).trim(); + if (enumRaw) { + try { + enumValues = JSON.parse(enumRaw); + } + catch (error) { + console.log(`Error parsing raw enum values: ${enumRaw} Message: ${JSON.stringify(error)}`); + } + } + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result + .substring(formatIndex + constants_1.formatKeyword.length) + .trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } + if (isEnum) { + if (schema[schemaKey].enum) + continue; + if (enumValues) { + schema[schemaKey].enum = enumValues; + } + if (description) { + schema[schemaKey].description = description.trim(); + } + if (formatValue) { + schema[schemaKey].format = formatValue.trim(); + } + schema[schemaKey].type = type; + } + else { + const property = { + title: `${key}.${propName}`, + nullable: (_g = (_f = attribute.attributeType) === null || _f === void 0 ? void 0 : _f.includes("nullable")) !== null && _g !== void 0 ? _g : false, + type: type, + }; + if (description) { + property.description = description.trim(); + } + if (formatValue) { + property.format = formatValue.trim(); + } + schema[schemaKey].properties[attribute.attributeName] = property; + } + } + if (Object.keys(schema[schemaKey].properties).length === 0) { + delete schema[schemaKey].properties; + } + } + } + result.components.schemas = schema; + return result; +} // TODO: may need to make recursive for when schema property items is array function GeneratePropertyModel(tableName, propertyName, property) { var _a; let columnProperties = ((_a = property.type) !== null && _a !== void 0 ? _a : "object").toString(); - if (property.nullable) { + if (property.enum) { + columnProperties = `${JSON.stringify(property.enum)}`; + } + else if (property.nullable) { columnProperties += " nullable"; } + const description = (0, sharedUtils_1.generateComment)(property.description, property.format); + if (description) { + columnProperties += ` ${description}`; + } const result = { Name: (0, sharedUtils_1.dbTypeEnds)(propertyName), IsPrimaryKey: false, @@ -5121,15 +5179,106 @@ function GeneratePropertyModel(tableName, propertyName, property) { }; return result; } +function ConvertOpenApiToDatabaseModel(schemas) { + var _a, _b, _c; + const models = { + Dialect: "nosql", + TableList: [], + PrimaryKeyList: [], + ForeignKeyList: [], + }; + for (const key in schemas) { + if (Object.prototype.hasOwnProperty.call(schemas, key)) { + const schema = schemas[key]; + const tableModel = { + Name: (0, sharedUtils_1.dbTypeEnds)(key), + Properties: [], + }; + if (schema.enum) { + const enumList = schema.enum; + // serialize to string enum [values] + const propertyKey = `${schema.type} enum`; + const property = { + enum: enumList, + }; + if (schema.description) { + property.description = schema.description; + } + if (schema.format) { + property.format = schema.format; + } + const propertyModel = GeneratePropertyModel(key, propertyKey, property); + tableModel.Properties.push(propertyModel); + } + else { + const comment = (0, sharedUtils_1.generateComment)(schema.description, schema.format); + if (comment) { + tableModel.Name += ` ${comment}`; + } + } + // schema level comments? should these be in a row or table name? + for (const propertyKey in schema.properties) { + if (Object.prototype.hasOwnProperty.call(schema.properties, propertyKey)) { + const property = schema.properties[propertyKey]; + const propertyModel = GeneratePropertyModel(key, propertyKey, property); + if (propertyModel.ColumnProperties.includes("object") || + propertyModel.ColumnProperties.includes("array")) { + let refName = null; + if (property.$ref) { + refName = property.$ref.split("/").pop(); + } + else if (property.items && typeof property.items == "object") { + refName = (_a = property.items.$ref) === null || _a === void 0 ? void 0 : _a.split("/").pop(); + } + if (refName) { + const primaryKeyModel = { + PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(key), + ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(refName), + PrimaryKeyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), + // should just point to first property in uml table + ReferencesPropertyName: "", + IsDestination: false, + }; + const foreignKeyModel = { + ReferencesTableName: (0, sharedUtils_1.dbTypeEnds)(key), + PrimaryKeyTableName: (0, sharedUtils_1.dbTypeEnds)(refName), + ReferencesPropertyName: (0, sharedUtils_1.dbTypeEnds)(propertyKey), + // should just point to first property in uml table + PrimaryKeyName: "", + IsDestination: true, + }; + models.ForeignKeyList.push(foreignKeyModel); + models.ForeignKeyList.push(primaryKeyModel); + propertyModel.IsForeignKey = true; + } + } + tableModel.Properties.push(propertyModel); + } + } + models.TableList.push(tableModel); + } + } + for (let i = 0; i < models.ForeignKeyList.length; i++) { + const fk = models.ForeignKeyList[i]; + if (!fk.ReferencesPropertyName) { + // match to first entry + const property = (_b = models.TableList.find((t) => t.Name == fk.ReferencesTableName)) === null || _b === void 0 ? void 0 : _b.Properties[0]; + if (property) { + models.ForeignKeyList[i].ReferencesPropertyName = property.Name; + } + } + if (!fk.PrimaryKeyName) { + // match to first entry + const property = (_c = models.TableList.find((t) => t.Name == fk.PrimaryKeyTableName)) === null || _c === void 0 ? void 0 : _c.Properties[0]; + if (property) { + models.ForeignKeyList[i].PrimaryKeyName = property.Name; + } + } + } + return models; +} -},{"./utils/constants":29,"./utils/sharedUtils":30,"core-types-json-schema":1}],29:[function(require,module,exports){ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.pluginVersion = void 0; -// export sql methods -exports.pluginVersion = "0.0.4"; - -},{}],30:[function(require,module,exports){ +},{"./constants":29,"./sharedUtils":31}],31:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetColumnQuantifiers = GetColumnQuantifiers; @@ -5137,7 +5286,12 @@ exports.removeHtml = removeHtml; exports.dbTypeEnds = dbTypeEnds; exports.RemoveNameQuantifiers = RemoveNameQuantifiers; exports.getDbLabel = getDbLabel; +exports.entityName = entityName; +exports.getCommentIndexes = getCommentIndexes; exports.getMermaidDiagramDb = getMermaidDiagramDb; +exports.GenerateDatabaseModel = GenerateDatabaseModel; +exports.generateComment = generateComment; +const constants_1 = require("./constants"); /** * return text quantifiers for dialect * @returns json @@ -5203,6 +5357,34 @@ function getDbLabel(label, columnQuantifiers) { }; return attribute; } +function entityName(description, format) { + let result = ""; + if (description) { + result += `${description}`; + } + if (format) { + result += ` @format ${format}`; + } + if (result) { + result = result.trim(); + result = `/** ${result} */`; + } + return result; +} +function getCommentIndexes(result) { + let hasComment = false; + if (result.indexOf(constants_1.commentColumnQuantifiers.Start) !== -1 && result.indexOf(constants_1.commentColumnQuantifiers.End) !== -1) { + hasComment = true; + } + const beforeIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) : -1; + const firstSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) + constants_1.commentColumnQuantifiers.Start.length : -1; + const lastSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.End) - 1 : -1; + return { + beforeStart: beforeIndex, + start: firstSpaceIndex, + end: lastSpaceIndex + }; +} /** * generate db from drawio graph models * @param ui @@ -5215,16 +5397,43 @@ function getMermaidDiagramDb(ui, type) { // only difference is entities is an array rather than object to allow duplicate tables const entities = {}; const relationships = []; + // TODO: support for ts and openapi enum // build models for (const key in model.cells) { if (Object.hasOwnProperty.call(model.cells, key)) { const mxcell = model.cells[key]; if (mxcell.mxObjectId.indexOf("mxCell") !== -1) { if (mxcell.style && mxcell.style.trim().startsWith("swimlane;")) { + let entityName = mxcell.value.toString(); + let description = ""; + let formatValue = ""; + if ((entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.Start)) && + (entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.End))) { + let result = entityName.toString(); + const commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + entityName = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result.substring(formatIndex + constants_1.formatKeyword.length).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } const entity = { - name: RemoveNameQuantifiers(mxcell.value), + name: RemoveNameQuantifiers(entityName), attributes: [], }; + const comment = generateComment(description, formatValue); + if (comment) { + entity.name += comment; + } + // const comment = for (let c = 0; c < mxcell.children.length; c++) { const col = mxcell.children[c]; if (col.mxObjectId.indexOf("mxCell") !== -1) { @@ -5378,6 +5587,10 @@ function getMermaidDiagramDb(ui, type) { } } } + const db = GenerateDatabaseModel(entities, relationships); + return db; +} +function GenerateDatabaseModel(entities, relationships) { class DatabaseModel { constructor(entities, relationships) { this.entities = entities; @@ -5393,5 +5606,19 @@ function getMermaidDiagramDb(ui, type) { const db = new DatabaseModel(entities, relationships); return db; } +function generateComment(description, formatValue) { + let result = ""; + if (description) { + result += `${description}`; + } + if (formatValue) { + result += ` @format ${formatValue}`; + } + if (result) { + result = result.trim(); + result = `${constants_1.commentColumnQuantifiers.Start} ${result} ${constants_1.commentColumnQuantifiers.End}`; + } + return result; +} -},{}]},{},[28]); +},{"./constants":29}]},{},[28]); diff --git a/dist/nosql.min.js b/dist/nosql.min.js index 8ee28de..4a6dcc7 100644 --- a/dist/nosql.min.js +++ b/dist/nosql.min.js @@ -1,9 +1,9 @@ -!function r(o,i,a){function l(t,e){if(!i[t]){if(!o[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(s)return s(t,!0);throw(e=new Error("Cannot find module '"+t+"'")).code="MODULE_NOT_FOUND",e}n=i[t]={exports:{}},o[t][0].call(n.exports,function(e){return l(o[t][1][e]||e)},n,n.exports,r,o,i,a)}return i[t].exports}for(var s="function"==typeof require&&require,e=0;e(0,o.ensureArray)(t).map(e=>"@see "+e).join("\n");if(e&&null!=t&&t.length)return e+"\n\n"+n();return e||n()}(e.description,e.see):void 0;return{...t,...e.title?{title:e.title}:{},...n?{description:n}:{},...e.default?{default:e.default}:{},...e.examples?{examples:e.examples}:{},...e.comment?{$comment:e.comment}:{}}},n.annotateCoreTypes=function(e,t){var{description:n,see:r}=function(e){var t=(null!=e?e:"").split("\n"),n=[];for(;0s(e)),e=(0,a.annotateJsonSchema)(e,{anyOf:t});return 1{return e=e,!(1===(e=Object.keys(e).sort()).length&&"type"===e[0]||2===e.length&&"title"===e[0]&&"type"===e[1])})&&(delete e.anyOf,e.type=t.map(({type:e})=>e)),e}function s(t){if("any"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{}));if("null"===t.type)return(0,a.annotateJsonSchema)(t,{type:"null"});if("boolean"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{type:"boolean"}));if("string"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{type:"string"}));if("number"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{type:"number"}));if("integer"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{type:"integer"}));if("and"===t.type)return(0,a.annotateJsonSchema)(t,{allOf:t.and.map(e=>s(e))});if("or"===t.type)return l(t);var e,n,r;if("object"===t.type)return n=(e=Object.keys(t.properties)).filter(e=>t.properties[e].required),r=Object.fromEntries(e.map(e=>[e,s(t.properties[e].node)])),(0,a.annotateJsonSchema)(t,c(t,{type:"object",...0s(e)),...!0===t.additionalItems?{}:t.additionalItems?{additionalItems:s(t.additionalItems)}:{additionalItems:!1},minItems:t.minItems}));if("ref"===t.type)return(0,a.annotateJsonSchema)(t,c(t,{$ref:(0,o.encodeRefNameJsonSchema)(t.ref)}));throw new i.UnsupportedError(`core-types node of type ${t.type} not supported`,t)}function c(e,t){return void 0!==e.const?{...t,const:e.const}:e.enum?{...t,enum:e.enum}:t}n.decorateSchema=r,n.convertCoreTypesToJsonSchema=function(e,t){var{version:e,types:n}=e;if(1!==e)throw new i.UnsupportedError(`core-types version ${e} not supported`);return r(e={definitions:Object.fromEntries(n.map(e=>[e.name,s(e)]))},null!=t?t:{}),{data:e,convertedTypes:n.map(({name:e})=>e),notConvertedTypes:[]}}},{"./annotations":2,"core-types":6,"openapi-json-schema":18}],4:[function(e,t,u){Object.defineProperty(u,"__esModule",{value:!0}),u.complexProps=u.convertJsonSchemaToCoreTypes=void 0;let i=e("jsonpos"),p=e("openapi-json-schema"),O=e("core-types"),f=e("./annotations"),d=(e,t)=>({...e,path:[...e.path,t]});function m(n,l){if("boolean"==typeof n)l.throwUnsupportedError("Boolean JSON Schema definition not supported",{blob:{schema:n}});else if("object"==typeof(e=n)&&Object.keys(e).some(e=>u.complexProps.has(e))){e=function(t,n){let{$ref:r,type:a,enum:l,const:s,items:c,additionalItems:u,required:p,properties:f,additionalProperties:d,then:e,else:o,allOf:i,anyOf:m,oneOf:y}=t;var h=i&&"object"==typeof i?i.filter(e=>e&&"object"==typeof e):null,b=m&&"object"==typeof m?m.filter(e=>e&&"object"==typeof e):null,g=y&&"object"==typeof y?y.filter(e=>e&&"object"==typeof e):null;let v=(e,o)=>{var i=(e,t)=>!(e&&t&&!(0,O.isEqual)(e,t));if(i(r,o.$ref)||n.throwUnsupportedError(`Cannot have $ref in a node *and* in its '${e}'`,{blob:t}),i(a,o.type)||n.throwUnsupportedError(`Cannot have 'type' in a node *and* in its '${e}'`,{blob:t}),l)if(o.enum){var i=(0,O.intersection)(l,o.enum);if(0===i.length)throw new O.MalformedTypeError("Cannot merge types with non-intersecting enums",{path:n.path,blob:{child:[...n.path,e]}});o.enum=i}else o.enum=l;if(void 0!==s)if(void 0!==o.const){if((0,O.isEqual)(s,o.const))throw new O.MalformedTypeError("Cannot merge types with mismatching const",{path:n.path,blob:{child:[...n.path,e]}})}else o.const=s;if(o.items=null!=(i=o.items)?i:c,o.additionalItems=null!=(e=o.additionalItems)?e:u,void 0===p&&void 0===o.required||(o.required=(0,O.union)(null!=(i=o.required)?i:[],null!==p&&void 0!==p?p:[])),void 0===f!=(void 0===o.properties))null!=o.properties||(o.properties=f);else if(void 0!==f){let t=f,n=o.properties;e=Object.keys(t),i=Object.keys(n),e=(0,O.union)(e,i);let r={};e.forEach(e=>{void 0!==t[e]?r[e]=n[e]:void 0!==n[e]?r[e]=t[e]:r[e]={allOf:[t[e],n[e]]}})}void 0===d!=(void 0===o.additionalProperties)?null==o.additionalProperties&&(o.additionalProperties=d):void 0!==d&&(o.additionalProperties={allOf:[o.additionalProperties,d]})};return e&&"object"==typeof e&&v("then",e),o&&"object"==typeof o&&v("else",o),h&&"object"==typeof h&&h.forEach(e=>v("allOf",e)),b&&"object"==typeof b&&b.forEach(e=>v("anyOf",e)),g&&"object"==typeof g&&g.forEach(e=>v("oneOf",e)),{...e&&"object"==typeof e?{then:e}:{},...o&&"object"==typeof o?{else:o}:{},...h&&"object"==typeof h?{allOf:h}:{},...b&&"object"==typeof b?{anyOf:b}:{},...g&&"object"==typeof g?{oneOf:g}:{}}}(n,l);var r=l;var{then:e,else:t,allOf:o,anyOf:i,oneOf:a}=e,e=[...e?[[d(r,"then"),e]]:[],...t?[[d(r,"else"),t]]:[]],t=[...i?i.map((e,t)=>[d(d(r,"anyOf"),t),e]):[],...a?a.map((e,t)=>[d(d(r,"oneOf"),t),e]):[]],i=[...o?o.map((e,t)=>[d(d(r,"allOf"),t),e]):[]];return{type:"and",and:[{type:"or",or:e.map(([e,t])=>m(t,e))},{type:"or",or:t.map(([e,t])=>m(t,e))},{type:"and",and:i.map(([e,t])=>m(t,e))}]};return}void 0===n&&l.throwUnsupportedError("Internal error",{blob:{schema:n}});let s=e=>({type:"ref",ref:(0,p.decodeRefNameJsonSchema)(e)});var a=e=>void 0===n.$ref?e:{type:"and",and:[e,s(n.$ref)]},{const:o,enum:e}=n;let c={...void 0!==o?{const:o}:{},...void 0!==e?{enum:e}:{}};return void 0===n.type?n.$ref?{...s(n.$ref),...c}:{type:"any",...c}:1===(t=(0,O.ensureArray)(n.type).map(e=>{var t,r=n,o=c,i=l;if(y(e))return"null"===e?(0,f.annotateCoreTypes)({type:"null"},r):(0,f.annotateCoreTypes)({type:e,...o},r);if("array"===e)return Array.isArray(r.items)?(0,f.annotateCoreTypes)({type:"tuple",elementTypes:r.items.map(e=>m(e,d(i,"items"))),additionalItems:void 0===r.additionalItems||("boolean"==typeof r.additionalItems?r.additionalItems:m(r.additionalItems,d(i,"additionalItems"))),minItems:null!=(a=r.minItems)?a:0,...o},r):!1===r.items?(0,f.annotateCoreTypes)({type:"tuple",elementTypes:[],additionalItems:!1,minItems:0,...o},r):(0,f.annotateCoreTypes)({type:"array",elementType:void 0===r.items||!0===r.items?{type:"any"}:m(r.items,d(i,"items")),...o},r);if("object"===e){let n=new Set(null!=(a=r.required)?a:[]);var a=null!=(a=r.additionalProperties)?a:i.defaultAdditionalProperties;return(0,f.annotateCoreTypes)({type:"object",properties:Object.fromEntries(Object.entries(null!=(t=r.properties)?t:{}).map(([e,t])=>[e,{node:m(t,d(d(i,"properties"),e)),required:n.has(e)}])),additionalProperties:"boolean"==typeof a?a:m(a,d(i,"additionalProperties")),...o},r)}i.throwUnsupportedError(`Unsupported JSON Schema type "${e}"`,{blob:{schema:r}})})).length?a(t[0]):a({type:"or",or:t})}u.convertJsonSchemaToCoreTypes=function(e,n={}){let r=("string"==typeof e?(0,i.getAstByString):(0,i.getAstByObject))(e),o=(e=r.json)["definitions"];return{data:e={version:1,types:Object.keys(null!==o&&void 0!==o?o:{}).map(e=>{var t;return{...m((null!==o&&void 0!==o?o:{})[e],{locByPath(){return{path:this.path,loc:(0,i.getLocation)(r,{dataPath:this.path,markIdentifier:!0})}},path:["definitions",e],throwUnsupportedError(e,t){throw(t={...t}).path||(t.path=this.path),t.loc||(t.loc=(0,i.getLocation)(r,{dataPath:this.path,markIdentifier:!0})),new O.UnsupportedError(e,t)},defaultAdditionalProperties:null==(t=n.defaultAdditionalProperties)||t}),name:e}})},convertedTypes:e.types.map(({name:e})=>e),notConvertedTypes:[]}},u.complexProps=new Set(["anyOf","allOf","oneOf","then","else"]);let y=e=>["string","number","integer","boolean","null"].includes(e)},{"./annotations":2,"core-types":6,jsonpos:25,"openapi-json-schema":18}],5:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.convertOpenApiToCoreTypes=n.convertCoreTypesToOpenApi=void 0;let o=e("openapi-json-schema"),i=e("./core-types-to-json-schema"),r=e("./json-schema-to-core-types");n.convertCoreTypesToOpenApi=function(e,t){let{data:n,...r}=(0,i.convertCoreTypesToJsonSchema)(e,t);return{...r,data:(0,o.jsonSchemaDocumentToOpenApi)(n,t)}},n.convertOpenApiToCoreTypes=function(e){return e="string"==typeof e?JSON.parse(e):e,e=(0,o.openApiToJsonSchema)(e),(0,r.convertJsonSchemaToCoreTypes)(e)}},{"./core-types-to-json-schema":3,"./json-schema-to-core-types":4,"openapi-json-schema":18}],6:[function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)},i=(Object.defineProperty(n,"__esModule",{value:!0}),n.traverse=n.some=n.mergeLocations=n.getPositionOffset=n.locationToLineColumn=n.positionToLineColumn=n.decorateError=n.decorateErrorMeta=n.isCoreTypesError=n.throwRelatedError=n.throwUnsupportedError=n.RelatedError=n.UnsupportedError=n.MissingReferenceError=n.MalformedTypeError=n.formatSee=n.formatDefault=n.formatExamples=n.stringify=n.stripAnnotations=n.stringifyAnnotations=n.extractAnnotations=n.mergeAnnotations=n.isNonNullable=n.union=n.intersection=n.isEqual=n.hasConstEnum=n.isPrimitiveType=n.ensureArray=n.validate=n.simplify=void 0,o(e("./lib/types"),n),e("./lib/simplify")),a=(Object.defineProperty(n,"simplify",{enumerable:!0,get:function(){return i.simplify}}),e("./lib/validate")),l=(Object.defineProperty(n,"validate",{enumerable:!0,get:function(){return a.validate}}),e("./lib/util")),s=(Object.defineProperty(n,"ensureArray",{enumerable:!0,get:function(){return l.ensureArray}}),Object.defineProperty(n,"isPrimitiveType",{enumerable:!0,get:function(){return l.isPrimitiveType}}),Object.defineProperty(n,"hasConstEnum",{enumerable:!0,get:function(){return l.hasConstEnum}}),Object.defineProperty(n,"isEqual",{enumerable:!0,get:function(){return l.isEqual}}),Object.defineProperty(n,"intersection",{enumerable:!0,get:function(){return l.intersection}}),Object.defineProperty(n,"union",{enumerable:!0,get:function(){return l.union}}),Object.defineProperty(n,"isNonNullable",{enumerable:!0,get:function(){return l.isNonNullable}}),e("./lib/annotation")),c=(Object.defineProperty(n,"mergeAnnotations",{enumerable:!0,get:function(){return s.mergeAnnotations}}),Object.defineProperty(n,"extractAnnotations",{enumerable:!0,get:function(){return s.extractAnnotations}}),Object.defineProperty(n,"stringifyAnnotations",{enumerable:!0,get:function(){return s.stringifyAnnotations}}),Object.defineProperty(n,"stripAnnotations",{enumerable:!0,get:function(){return s.stripAnnotations}}),Object.defineProperty(n,"stringify",{enumerable:!0,get:function(){return s.stringify}}),Object.defineProperty(n,"formatExamples",{enumerable:!0,get:function(){return s.formatExamples}}),Object.defineProperty(n,"formatDefault",{enumerable:!0,get:function(){return s.formatDefault}}),Object.defineProperty(n,"formatSee",{enumerable:!0,get:function(){return s.formatSee}}),e("./lib/error")),u=(Object.defineProperty(n,"MalformedTypeError",{enumerable:!0,get:function(){return c.MalformedTypeError}}),Object.defineProperty(n,"MissingReferenceError",{enumerable:!0,get:function(){return c.MissingReferenceError}}),Object.defineProperty(n,"UnsupportedError",{enumerable:!0,get:function(){return c.UnsupportedError}}),Object.defineProperty(n,"RelatedError",{enumerable:!0,get:function(){return c.RelatedError}}),Object.defineProperty(n,"throwUnsupportedError",{enumerable:!0,get:function(){return c.throwUnsupportedError}}),Object.defineProperty(n,"throwRelatedError",{enumerable:!0,get:function(){return c.throwRelatedError}}),Object.defineProperty(n,"isCoreTypesError",{enumerable:!0,get:function(){return c.isCoreTypesError}}),Object.defineProperty(n,"decorateErrorMeta",{enumerable:!0,get:function(){return c.decorateErrorMeta}}),Object.defineProperty(n,"decorateError",{enumerable:!0,get:function(){return c.decorateError}}),e("./lib/location")),p=(Object.defineProperty(n,"positionToLineColumn",{enumerable:!0,get:function(){return u.positionToLineColumn}}),Object.defineProperty(n,"locationToLineColumn",{enumerable:!0,get:function(){return u.locationToLineColumn}}),Object.defineProperty(n,"getPositionOffset",{enumerable:!0,get:function(){return u.getPositionOffset}}),Object.defineProperty(n,"mergeLocations",{enumerable:!0,get:function(){return u.mergeLocations}}),e("./lib/traverse"));Object.defineProperty(n,"some",{enumerable:!0,get:function(){return p.some}}),Object.defineProperty(n,"traverse",{enumerable:!0,get:function(){return p.traverse}})},{"./lib/annotation":7,"./lib/error":8,"./lib/location":9,"./lib/simplify":13,"./lib/traverse":14,"./lib/types":15,"./lib/util":16,"./lib/validate":17}],7:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.stringify=n.formatSee=n.formatDefault=n.formatExamples=n.arrayOrSingle=n.stripAnnotations=n.stringifyAnnotations=n.wrapWhitespace=n.extractAnnotations=n.mergeAnnotations=void 0;let u=e("./location"),p=e("./util");function l(e){return e.includes("\n")?["*",e.split("\n").map(e=>" * "+e).join("\n")," "].join("\n"):e.startsWith(" ")?e:" "+e}function f(e){return 1===e.length?e[0]:e}function s(e){return e.map(e=>"@example\n"+o(r(e).split("\n"),4)).join("\n").trim()}function c(e){return["@default",o(r(e).split("\n"),4)].join("\n").trim()}function d(e){return e.map(e=>"@see "+r(e)).join("\n").trim()}function r(e){return"string"==typeof e?e:JSON.stringify(e,null,2)}function o(e,n,r=!1){return e.map((e,t)=>{return(0===t&&r?" ".repeat(n-2)+"* ":" ".repeat(n))+e}).join("\n")}n.mergeAnnotations=function(e){let t,n=e=>!!e;var r=(e,t="\n")=>(0,p.uniq)(e.filter(n)).join(t).trim(),o=null==(t=e.find(e=>e.name))?void 0:t.name,i=r(e.map(e=>e.title),", "),a=r(e.map(e=>e.description)),l=(0,p.uniq)([].concat(...e.map(e=>(0,p.ensureArray)(e.examples))).filter(n)),s=r(e.map(e=>e.default)),c=(0,p.uniq)([].concat(...e.map(e=>(0,p.ensureArray)(e.see))).filter(n)),r=r(e.map(e=>e.comment)),e=(0,u.mergeLocations)(e.map(e=>e.loc));return{...o?{name:o}:{},...i?{title:i}:{},...a?{description:a}:{},...0e).join("\n\n").trim().replace(/\*\//g,"*\\/");return n&&e?l(e):e},n.stripAnnotations=function t(e,n=!0){let{comment:r,description:o,default:i,examples:a,see:l,title:s,...c}=e,u=c;if(n){if("and"===u.type)return{...u,and:u.and.map(e=>t(e,!0))};if("or"===u.type)return{...u,or:u.or.map(e=>t(e,!0))};if("array"===u.type)return{...u,elementType:t(u.elementType,!0)};if("tuple"===u.type)return{...u,elementTypes:u.elementTypes.map(e=>t(e,!0)),additionalItems:"object"==typeof u.additionalItems?t(u.additionalItems,!0):u.additionalItems};if("object"===u.type)return{...u,properties:Object.fromEntries(Object.keys(u.properties).map(e=>[e,{...u.properties[e],node:t(u.properties[e].node,!0)}])),additionalProperties:"object"==typeof u.additionalProperties?t(u.additionalProperties,!0):u.additionalProperties}}return u},n.arrayOrSingle=f,n.formatExamples=s,n.formatDefault=c,n.formatSee=d,n.stringify=r},{"./location":9,"./util":16}],8:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.decorateError=n.decorateErrorMeta=n.isCoreTypesError=n.throwRelatedError=n.throwUnsupportedError=n.RelatedError=n.UnsupportedError=n.MissingReferenceError=n.MalformedTypeError=n.CoreTypesError=void 0;class r extends Error{constructor(e,t={}){super(e),Object.setPrototypeOf(this,r.prototype),this.blob=t.blob,this.path=t.path,this.loc=t.loc,this.source=t.source,this.filename=t.filename,this.relatedError=t.relatedError}}n.CoreTypesError=r;class o extends r{constructor(e,t={}){super(e,t),Object.setPrototypeOf(this,o.prototype)}}n.MalformedTypeError=o;class i extends r{constructor(e,t={}){super(`Reference to missing type "${e}"`,t),Object.setPrototypeOf(this,i.prototype)}}n.MissingReferenceError=i;class a extends r{constructor(e,t={}){super(e,t),Object.setPrototypeOf(this,a.prototype)}}n.UnsupportedError=a;class l extends r{constructor(e,t={}){super(e.message,{...t,relatedError:e}),Object.setPrototypeOf(this,l.prototype)}}function s(e){return e instanceof r}function c(e,t){return t.blob&&null==e.blob&&(e.blob=t.blob),t.path&&null==e.path&&(e.path=t.path),t.loc&&null==e.loc&&(e.loc=t.loc),t.source&&null==e.source&&(e.source=t.source),t.filename&&null==e.filename&&(e.filename=t.filename),e}n.RelatedError=l,n.throwUnsupportedError=function(e,t,n){throw new a(e,{blob:t,...t.loc?{loc:t.loc}:{},...n?{path:n}:{}})},n.throwRelatedError=function(e,t){throw new l(e,t)},n.isCoreTypesError=s,n.decorateErrorMeta=c,n.decorateError=function(e,t){return s(e)&&c(e,t),e}},{}],9:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.mergeLocations=n.getPositionOffset=n.locationToLineColumn=n.positionToLineColumn=void 0;let s=e("./util");function r(e,t){var n=e.slice(0,t).split("\n").length,e=e.lastIndexOf("\n",t);return-1===e?{offset:t,line:n,column:t}:{offset:t,line:n,column:t-e}}n.positionToLineColumn=r,n.locationToLineColumn=function(e,t){return"object"==typeof t.start?t:{start:void 0===t.start?void 0:r(e,t.start),...null==t.end?{}:{end:r(e,t.end)}}},n.getPositionOffset=function(e){return void 0===e||"number"==typeof e?e:e.offset},n.mergeLocations=function(e){let t,n,r,o,i,a=e=>"number"==typeof e?e:null==e?void 0:e.offset;e.filter(s.isNonNullable).forEach(({start:e,end:t})=>{var n=a(e),r=a(t);void 0!==n&&(!o||"number"==typeof o.location&&o.location===n||o.offset>n)&&(o={location:e,offset:n}),void 0!==r&&(!i||"number"==typeof i.location&&i.location===n||i.offseti(e))).some(e=>0===e.length)?[]:(0,r.uniq)([].concat(...e))},n.combineConstAndEnum=i},{"../util":16}],11:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.intersectConstEnum=void 0;let r=e("../annotation"),o=e("../util");n.intersectConstEnum=function(e){if(0===e.length)throw new Error("Cannot intersect const and enum from an empty array of nodes");var t;return 1===e.length?e[0]:(t=(t=e.map(e=>void 0!==e.const?[e.const]:void 0!==e.enum?e.enum:void 0).filter(e=>!!e)).slice(1).reduce((e,t)=>(0,o.intersection)(e,t),t[0]),{type:e[0].type,...1===t.length?{const:t[0]}:{},...1!==t.length?{enum:t}:{},...(0,r.mergeAnnotations)(e)})}},{"../annotation":7,"../util":16}],12:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.simplifySingle=void 0;let r=e("./const-enum");n.simplifySingle=function(e){return"boolean"===e.type||"integer"===e.type||"number"===e.type||"string"===e.type?(0,r.simplifyEnumAndConst)(e):e}},{"./const-enum":10}],13:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.simplify=void 0;let a=e("./simplifications/single"),l=e("./simplifications/const-enum"),o=e("./simplifications/intersect-const-enum"),i=e("./error"),s=e("./annotation"),c=e("./util"),u=["any","string","number","integer","boolean"];n.simplify=function r(t){if(Array.isArray(t))return t.map(e=>r(e));if((0,c.isNodeDocument)(t))return{...t,types:r(t.types)};var e,n=e=>(0,c.copyName)(t,e);if("tuple"===t.type)return{...t,elementTypes:t.elementTypes.map(e=>r(e)),...t.additionalItems&&"object"==typeof t.additionalItems?{additionalItems:r(t.additionalItems)}:{}};if("array"===t.type)return{...t,elementType:r(t.elementType)};if("object"===t.type)return{...t,properties:Object.fromEntries(Object.entries(t.properties).map(([e,{node:t,required:n}])=>[e,{node:r(t),required:n}])),...t.additionalProperties&&"object"==typeof t.additionalProperties?{additionalProperties:r(t.additionalProperties)}:{}};if("and"!==t.type&&"or"!==t.type)return n((0,a.simplifySingle)(t));if("and"===t.type)return 1===(e=function(e){if(0<(e=(0,c.splitTypes)(e)).any.length){if(0===e.and.length&&0===e.or.length&&0===e.ref.length&&0===e.null.length&&0===e.string.length&&0===e.number.length&&0===e.integer.length&&0===e.boolean.length&&0===e.object.length&&0===e.array.length&&0===e.tuple.length)return[{type:"any",...(0,s.mergeAnnotations)(e.any.map(({node:e})=>e))}];e.any=[]}var t=e=>e.map(({node:e})=>e);return 1e),...t(e.any)]),order:(0,c.firstSplitTypeIndex)(e.boolean)}]),1e),...t(e.any)]),order:(0,c.firstSplitTypeIndex)(e.string)}]),0e),...t(e.integer),...t(e.any)]),order:(0,c.firstSplitTypeIndex)(e.number)}],e.integer=[]):1e),...t(e.any)]),order:(0,c.firstSplitTypeIndex)(e.number)}]:1e),...t(e.any)]),order:(0,c.firstSplitTypeIndex)(e.integer)}]),000(e=r(e)).and||[e])))).length?n({...e[0],...(0,s.mergeAnnotations)([(0,s.extractAnnotations)(t),e[0]])}):n({type:"and",and:e,...(0,s.extractAnnotations)(t)});if("or"===t.type)return 1===(e=function(e){var t,n,r,o,i=(0,c.splitTypes)(e);if(0e)).length)return[{type:"any",...(0,s.mergeAnnotations)(i.any.map(({node:e})=>e))}];for([t,n]of Object.entries(i))u.includes(t)&&n.length&&(r=n.map(({node:e})=>e),0===(o=(0,l.mergeConstEnumUnion)(r)).length?i[t]=[{node:{type:t,...(0,s.mergeAnnotations)(r)},order:(0,c.firstSplitTypeIndex)(n)}]:i[t]=[{node:(0,a.simplifySingle)({type:t,enum:o,...(0,s.mergeAnnotations)(r)}),order:(0,c.firstSplitTypeIndex)(n)}]);return 000(e=r(e)).or||[e])))).length?n({...e[0],...(0,s.mergeAnnotations)([(0,s.extractAnnotations)(t),e[0]])}):n({type:"or",or:e,...(0,s.extractAnnotations)(t)});throw new i.MalformedTypeError("Invalid node",t)}},{"./annotation":7,"./error":8,"./simplifications/const-enum":10,"./simplifications/intersect-const-enum":11,"./simplifications/single":12,"./util":16}],14:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.some=n.traverse=void 0;class r extends Error{}function o(e,t){function a(e,t,n,r,o,i){var i=void 0!==i?i:void 0===r?t[n]:t[n][r],a=[...e.path,n,...void 0===r?[]:[r]];return Object.assign({},e,{node:i,path:a,parentNode:t,parentProperty:n,index:r,required:o})}!function n(r,o){o(r);let i=r.node;if("array"===i.type)n(a(r,i,"elementType"),o);else if("tuple"===i.type)i.elementTypes.forEach((e,t)=>n(a(r,i,"elementTypes",t),o)),"object"==typeof i.additionalItems&&n(a(r,i,"additionalItems"),o);else if("object"===i.type){for(var e of Object.keys(i.properties))n(a(r,i,"properties",e,i.properties[e].required,i.properties[e].node),o);"object"==typeof i.additionalProperties&&n(a(r,i,"additionalProperties"),o)}else"and"===i.type?i.and.forEach((e,t)=>n(a(r,i,"and",t),o)):"or"===i.type&&i.or.forEach((e,t)=>n(a(r,i,"or",t),o))}({node:e,rootNode:e,path:[]},t)}n.traverse=o,n.some=function(e,t){try{o(e,e=>{if(t(e))throw new r})}catch(e){if(e instanceof r)return!0;throw e}return!1}},{}],15:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0})},{}],16:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.isNodeDocument=n.isNonNullable=n.copyName=n.firstSplitTypeIndex=n.flattenSplitTypeValues=n.splitTypes=n.union=n.intersection=n.isEqual=n.hasConstEnum=n.constEnumTypes=n.isPrimitiveType=n.ensureArray=n.uniq=void 0,n.uniq=function(r){return r.filter((t,n)=>{for(let e=0;e["null","string","number","integer","boolean"].includes(e.type),n.constEnumTypes=new Set(["any","string","number","integer","boolean","object","array","tuple","ref"]);function o(t,n){var e;return typeof t==typeof n&&!(null===t!=(null===n)||null!==t&&(Array.isArray(t)&&Array.isArray(n)?t.length!==n.length||t.some((e,t)=>!o(e,n[t])):Array.isArray(t)!==Array.isArray(n)||("object"==typeof t?!o(e=Object.keys(t).sort(),Object.keys(n).sort())||e.some(e=>!o(t[e],n[e])):t!==n)))}n.hasConstEnum=e=>n.constEnumTypes.has(e.type),n.isEqual=o,n.intersection=function(e,n){let r=[];return e.forEach(t=>{n.forEach(e=>{o(t,e)&&r.push(t)})}),r},n.union=function(e,t){let n=[...e];return t.forEach(t=>{e.some(e=>o(t,e))||n.push(t)}),n},n.splitTypes=function(e){let n={and:[],or:[],ref:[],any:[],null:[],string:[],number:[],integer:[],boolean:[],object:[],array:[],tuple:[]};return e.forEach((e,t)=>{("and"!==e.type&&"or"!==e.type||"and"===e.type&&0e.order-t.order).map(({node:e})=>e))},n.firstSplitTypeIndex=function(e){return Math.min(...e.map(({order:e})=>e))},n.copyName=function(e,t){return void 0===e.name?t:{...t,name:e.name}},n.isNonNullable=function(e){return null!=e},n.isNodeDocument=function(e){return Array.isArray(e.types)}},{}],17:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.validate=void 0;let r=e("./error"),o=e("./util");n.validate=function t(e){if((0,o.hasConstEnum)(e)){var n=e;if(n.enum&&0===n.enum.length)throw new r.MalformedTypeError("Empty enum is not allowed",n);if(n.enum&&void 0!==n.const&&!n.enum.some(e=>(0,o.isEqual)(e,n.const)))throw new r.MalformedTypeError("Enum and const are both set, but enum doesn't contain const",n)}"and"===e.type&&e.and.forEach(e=>t(e)),"or"===e.type&&e.or.forEach(e=>t(e))}},{"./error":8,"./util":16}],18:[function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(n,"__esModule",{value:!0}),o(e("./lib"),n),o(e("./lib/types"),n),o(e("./lib/utils"),n)},{"./lib":19,"./lib/types":22,"./lib/utils":23}],19:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.openApiToJsonSchema=n.jsonSchemaDocumentToOpenApi=n.decorateOpenApi=void 0;let o=e("./json-schema-to-openapi"),r=e("./openapi-to-json-schema");function i(e,{title:t,version:n,schemaVersion:r="3.0.0"}){t={title:t,version:n};return e.$id&&(t["x-id"]=e.$id,delete e.$id),e.$comment&&(t["x-comment"]=e.$comment,delete e.$comment),delete e.$schema,{openapi:r,info:t,paths:{},...e}}n.decorateOpenApi=i,n.jsonSchemaDocumentToOpenApi=function(e,t){let{definitions:n={},...r}=e;return i({...r,components:{schemas:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(0,o.jsonSchemaTypeToOpenApi)(t)]))}},t)},n.openApiToJsonSchema=function(e){let t=e.components.schemas;return{definitions:Object.fromEntries(Object.keys(t).map(e=>[e,(0,r.openApiToJsonSchemaType)(t[e])]))}}},{"./json-schema-to-openapi":20,"./openapi-to-json-schema":21}],20:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.jsonSchemaTypeToOpenApi=void 0;let r=e("./utils");n.jsonSchemaTypeToOpenApi=function e(t){var n;return"boolean"==typeof t?t:(t=function(e){if(void 0===e.type)return e;let{type:t,...n}=e,r=Array.isArray(t)?t.includes("null"):"null"===t;var o=Array.isArray(t)?t.filter(e=>"null"!==e):"null"===t?void 0:t;let i=(e,t)=>"any"!==t&&t?{...e,type:t}:e;return void 0!==e.const&&(n.enum=[e.const],delete n.const),e=e=>r?{...e,nullable:r}:e,Array.isArray(o)?0===o.length?e(n):1===o.length?i(e(n),o[0]):{...e(n),anyOf:o.map(e=>i({},e))}:i(e(n),o)}(t),t=(n=t).$ref?{...n,$ref:(0,r.encodeRefNameOpenApi)((0,r.decodeRefNameJsonSchema)(n.$ref))}:n,(0,r.recurseSchema)(t,e))}},{"./utils":23}],21:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.openApiToJsonSchemaType=void 0;let a=e("./utils");n.openApiToJsonSchemaType=function e(t){if("boolean"==typeof t)return t;let{type:n,nullable:r,...o}=t;var i,t=function(e,t){if(void 0!==e&&"any"!==e)return Array.isArray(e)?e.includes("any")?void 0:(!e.includes("null")&&t&&e.push("null"),1===e.length?e[0]:e):"null"!==e&&t?[e,"null"]:e}(n,r),t={...o,...t?{type:t}:{}},t=(i=t).$ref?{...i,$ref:(0,a.encodeRefNameJsonSchema)((0,a.decodeRefNameOpenApi)(i.$ref))}:i;return(0,a.recurseSchema)(t,e)}},{"./utils":23}],22:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{dup:15}],23:[function(e,t,n){function r(e){return encodeURIComponent(e)}function o(e){return decodeURIComponent(e)}function i(e){return e&&0n(e))}:{items:n(r.items)},..."object"!=typeof r.additionalItems?{}:{additionalItems:n(r.additionalItems)},..."object"!=typeof r.contains?{}:{contains:n(r.contains)},...i(r.properties)?{properties:Object.fromEntries(Object.keys(r.properties).map(e=>{var t;return[e,n(null==(t=r.properties)?void 0:t[e])]}))}:{},...i(r.patternProperties)?{patternProperties:Object.fromEntries(Object.keys(r.patternProperties).map(e=>{var t;return[e,n(null==(t=r.patternProperties)?void 0:t[e])]}))}:{},..."object"!=typeof r.additionalProperties?{}:{additionalProperties:n(r.additionalProperties)},...i(r.dependencies)?{dependencies:Object.fromEntries(Object.keys(r.dependencies).map(e=>{var t;return[e,n(null==(t=r.dependencies)?void 0:t[e])]}))}:{},..."object"!=typeof r.propertyNames?{}:{propertyNames:n(r.propertyNames)},..."object"!=typeof r.if?{}:{if:n(r.if)},..."object"!=typeof r.then?{}:{then:n(r.then)},..."object"!=typeof r.else?{}:{else:n(r.else)},..."object"==typeof r.allOf&&r.allOf.length?{allOf:r.allOf.map(e=>n(e))}:{},..."object"==typeof r.anyOf&&r.anyOf.length?{anyOf:r.anyOf.map(e=>n(e))}:{},..."object"==typeof r.oneOf&&r.oneOf.length?{oneOf:r.oneOf.map(e=>n(e))}:{},..."object"!=typeof r.not?{}:{not:n(r.not)},...i(r.definitions)?{definitions:Object.fromEntries(Object.keys(r.definitions).map(e=>{var t;return[e,n(null==(t=r.definitions)?void 0:t[e])]}))}:{}}}},{}],24:[function(e,n,r){!function(e){!function(){var e,t;e=this,t=function(){function e(e,t){return e(t={exports:{}},t.exports),t.exports}var l=new(e(function(e){function t(){function l(e,t){var n,r,o=e.charCodeAt(t=void 0===t?0:t);return 55296<=o&&o<=56319&&t=e.length-1))for(var n,r=s(l(e,t)),o=[],i=t+1;i=n)return r.substr(0,n);while(n>r.length&&t>1){if(t&1)r+=e;t>>=1;e+=e}r+=e;r=r.substr(0,n);return r}"use strict";var l=function e(t,n,r){if(t==null||n==null)return t;var o=String(t);var i=typeof n==="number"?n:parseInt(n,10);if(isNaN(i)||!isFinite(i))return o;var a=o.length;if(a>=i)return o;var l=r==null?"":String(r);if(l==="")l=" ";var s=i-a;while(l.lengths?l.substr(0,s):l;return c+o},m=Object.assign||function(e){for(var t=1;t at "+n.filter(Boolean).join(":")}},s={unexpectedSymbol:function(e){for(var t=arguments.length,n=Array(1 at "+n.filter(Boolean).join(":")}},d={LEFT_BRACE:0,RIGHT_BRACE:1,LEFT_BRACKET:2,RIGHT_BRACKET:3,COLON:4,COMMA:5,STRING:6,NUMBER:7,TRUE:8,FALSE:9,NULL:10},o={"{":d.LEFT_BRACE,"}":d.RIGHT_BRACE,"[":d.LEFT_BRACKET,"]":d.RIGHT_BRACKET,":":d.COLON,",":d.COMMA},m={true:d.TRUE,false:d.FALSE,null:d.NULL},y={_START_:0,START_QUOTE_OR_CHAR:1,ESCAPE:2},h={'"':0,"\\":1,"/":2,b:3,f:4,n:5,r:6,t:7,u:8},b={_START_:0,MINUS:1,ZERO:2,DIGIT:3,POINT:4,DIGIT_FRACTION:5,EXP:6,EXP_DIGIT_OR_SIGN:7};function g(e){return"1"<=e&&e<="9"}function v(e){return"0"<=e&&e<="9"}function O(e){return"e"===e||"E"===e}function T(e,t,n,r){var o=e.charAt(t);if("\r"===o)n++,r=1,"\n"===e.charAt(++t)&&t++;else if("\n"===o)t++,n++,r=1;else{if("\t"!==o&&" "!==o)return null;t++,r++}return{index:t,line:n,column:r}}function E(e,t,n,r){e=e.charAt(t);return e in o?{type:o[e],line:n,column:r+1,index:t+1,value:null}:null}function j(e,t,n,r){for(var o in m)if(m.hasOwnProperty(o)&&e.substr(t,o.length)===o)return{type:m[o],line:n,column:r+o.length,index:t+o.length,value:o};return null}function A(e,t,n,r){for(var o=t,i=y._START_;te),l=e=>{return e=e,"."+a.slice(0,e).join(".")+` [query: ${a.join(".")}]`};return{start:null==(t=a.reduce((e,t,n)=>{if("Object"===e.type){var r,o=e.children.find(e=>e.key.value===t);if(o)return{key:o,value:r}=o,i&&n===a.length-1?o:r;throw new Error(`No such property ${t} in `+l(n))}if("Array"!==e.type)return e;o=Number(t);if(isNaN(o))throw new Error(`Invalid non-numeric array index "${t}" `+"in array at "+l(n));if(o<0||o>=e.children.length)throw new RangeError(`Index ${o} out-of-bounds in array of `+`size ${e.children.length} at `+l(n));return e.children,e.children[Number(t)]},e).loc)?void 0:t.start,end:null==t?void 0:t.end}}},{}],27:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.getAstByObject=n.getAstByString=void 0;let r=e("json-to-ast");function o(e,t){var n=r(e,{loc:!0});return{json:t||JSON.parse(e),jsonString:e,jsonAST:n}}n.getAstByString=o,n.getAstByObject=function(e,t=4){return o(JSON.stringify(e,null,t))}},{"json-to-ast":24}],28:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});let $=e("core-types-json-schema"),U=e("./utils/sharedUtils"),B=e("./utils/constants");Draw.loadPlugin(function(S){var e=document.createElement("div");e.style.userSelect="none",e.style.overflow="hidden",e.style.padding="10px",e.style.height="100%";let r=document.createElement("textarea"),t=(r.style.height="200px",r.style.width="100%","-- click a nosql type button");r.value=t,mxUtils.br(e),e.appendChild(r);var n=S.menus.get("exportAs");let o="tonosql=To NoSQL",i=(n&&!window.VsCodeApi||(o="tonosql=Export As NoSQL"),mxResources.parse(o),new mxWindow(mxResources.get("tonosql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));function a(e){var t=function(e){var t={openapi:"3.0.0",info:{title:"drawio nosql export",version:B.pluginVersion,"x-comment":"Generated by from drawio uml using plugin nosql"},paths:{},components:{schemas:{}}},n={},r=e.getEntities();for(var o in r)if(Object.prototype.hasOwnProperty.call(r,o)){var i=r[o];if(!n[o]){n[o]={type:"object",title:o,additionalProperties:!1,properties:{}};for(let e=0;e(0,o.ensureArray)(t).map(e=>"@see "+e).join("\n");if(e&&null!=t&&t.length)return e+"\n\n"+n();return e||n()}(e.description,e.see):void 0;return{...t,...e.title?{title:e.title}:{},...n?{description:n}:{},...e.default?{default:e.default}:{},...e.examples?{examples:e.examples}:{},...e.comment?{$comment:e.comment}:{}}},n.annotateCoreTypes=function(e,t){var{description:n,see:r}=function(e){var t=(null!=e?e:"").split("\n"),n=[];for(;0s(e)),e=(0,a.annotateJsonSchema)(e,{anyOf:t});return 1{return e=e,!(1===(e=Object.keys(e).sort()).length&&"type"===e[0]||2===e.length&&"title"===e[0]&&"type"===e[1])})&&(delete e.anyOf,e.type=t.map(({type:e})=>e)),e}function s(t){if("any"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{}));if("null"===t.type)return(0,a.annotateJsonSchema)(t,{type:"null"});if("boolean"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{type:"boolean"}));if("string"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{type:"string"}));if("number"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{type:"number"}));if("integer"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{type:"integer"}));if("and"===t.type)return(0,a.annotateJsonSchema)(t,{allOf:t.and.map(e=>s(e))});if("or"===t.type)return l(t);var e,n,r;if("object"===t.type)return n=(e=Object.keys(t.properties)).filter(e=>t.properties[e].required),r=Object.fromEntries(e.map(e=>[e,s(t.properties[e].node)])),(0,a.annotateJsonSchema)(t,u(t,{type:"object",...0s(e)),...!0===t.additionalItems?{}:t.additionalItems?{additionalItems:s(t.additionalItems)}:{additionalItems:!1},minItems:t.minItems}));if("ref"===t.type)return(0,a.annotateJsonSchema)(t,u(t,{$ref:(0,o.encodeRefNameJsonSchema)(t.ref)}));throw new i.UnsupportedError(`core-types node of type ${t.type} not supported`,t)}function u(e,t){return void 0!==e.const?{...t,const:e.const}:e.enum?{...t,enum:e.enum}:t}n.decorateSchema=r,n.convertCoreTypesToJsonSchema=function(e,t){var{version:e,types:n}=e;if(1!==e)throw new i.UnsupportedError(`core-types version ${e} not supported`);return r(e={definitions:Object.fromEntries(n.map(e=>[e.name,s(e)]))},null!=t?t:{}),{data:e,convertedTypes:n.map(({name:e})=>e),notConvertedTypes:[]}}},{"./annotations":2,"core-types":6,"openapi-json-schema":18}],4:[function(e,t,c){Object.defineProperty(c,"__esModule",{value:!0}),c.complexProps=c.convertJsonSchemaToCoreTypes=void 0;let i=e("jsonpos"),p=e("openapi-json-schema"),O=e("core-types"),f=e("./annotations"),d=(e,t)=>({...e,path:[...e.path,t]});function m(n,l){if("boolean"==typeof n)l.throwUnsupportedError("Boolean JSON Schema definition not supported",{blob:{schema:n}});else if("object"==typeof(e=n)&&Object.keys(e).some(e=>c.complexProps.has(e))){e=function(t,n){let{$ref:r,type:a,enum:l,const:s,items:u,additionalItems:c,required:p,properties:f,additionalProperties:d,then:e,else:o,allOf:i,anyOf:m,oneOf:y}=t;var h=i&&"object"==typeof i?i.filter(e=>e&&"object"==typeof e):null,b=m&&"object"==typeof m?m.filter(e=>e&&"object"==typeof e):null,g=y&&"object"==typeof y?y.filter(e=>e&&"object"==typeof e):null;let v=(e,o)=>{var i=(e,t)=>!(e&&t&&!(0,O.isEqual)(e,t));if(i(r,o.$ref)||n.throwUnsupportedError(`Cannot have $ref in a node *and* in its '${e}'`,{blob:t}),i(a,o.type)||n.throwUnsupportedError(`Cannot have 'type' in a node *and* in its '${e}'`,{blob:t}),l)if(o.enum){var i=(0,O.intersection)(l,o.enum);if(0===i.length)throw new O.MalformedTypeError("Cannot merge types with non-intersecting enums",{path:n.path,blob:{child:[...n.path,e]}});o.enum=i}else o.enum=l;if(void 0!==s)if(void 0!==o.const){if((0,O.isEqual)(s,o.const))throw new O.MalformedTypeError("Cannot merge types with mismatching const",{path:n.path,blob:{child:[...n.path,e]}})}else o.const=s;if(o.items=null!=(i=o.items)?i:u,o.additionalItems=null!=(e=o.additionalItems)?e:c,void 0===p&&void 0===o.required||(o.required=(0,O.union)(null!=(i=o.required)?i:[],null!==p&&void 0!==p?p:[])),void 0===f!=(void 0===o.properties))null!=o.properties||(o.properties=f);else if(void 0!==f){let t=f,n=o.properties;e=Object.keys(t),i=Object.keys(n),e=(0,O.union)(e,i);let r={};e.forEach(e=>{void 0!==t[e]?r[e]=n[e]:void 0!==n[e]?r[e]=t[e]:r[e]={allOf:[t[e],n[e]]}})}void 0===d!=(void 0===o.additionalProperties)?null==o.additionalProperties&&(o.additionalProperties=d):void 0!==d&&(o.additionalProperties={allOf:[o.additionalProperties,d]})};return e&&"object"==typeof e&&v("then",e),o&&"object"==typeof o&&v("else",o),h&&"object"==typeof h&&h.forEach(e=>v("allOf",e)),b&&"object"==typeof b&&b.forEach(e=>v("anyOf",e)),g&&"object"==typeof g&&g.forEach(e=>v("oneOf",e)),{...e&&"object"==typeof e?{then:e}:{},...o&&"object"==typeof o?{else:o}:{},...h&&"object"==typeof h?{allOf:h}:{},...b&&"object"==typeof b?{anyOf:b}:{},...g&&"object"==typeof g?{oneOf:g}:{}}}(n,l);var r=l;var{then:e,else:t,allOf:o,anyOf:i,oneOf:a}=e,e=[...e?[[d(r,"then"),e]]:[],...t?[[d(r,"else"),t]]:[]],t=[...i?i.map((e,t)=>[d(d(r,"anyOf"),t),e]):[],...a?a.map((e,t)=>[d(d(r,"oneOf"),t),e]):[]],i=[...o?o.map((e,t)=>[d(d(r,"allOf"),t),e]):[]];return{type:"and",and:[{type:"or",or:e.map(([e,t])=>m(t,e))},{type:"or",or:t.map(([e,t])=>m(t,e))},{type:"and",and:i.map(([e,t])=>m(t,e))}]};return}void 0===n&&l.throwUnsupportedError("Internal error",{blob:{schema:n}});let s=e=>({type:"ref",ref:(0,p.decodeRefNameJsonSchema)(e)});var a=e=>void 0===n.$ref?e:{type:"and",and:[e,s(n.$ref)]},{const:o,enum:e}=n;let u={...void 0!==o?{const:o}:{},...void 0!==e?{enum:e}:{}};return void 0===n.type?n.$ref?{...s(n.$ref),...u}:{type:"any",...u}:1===(t=(0,O.ensureArray)(n.type).map(e=>{var t,r=n,o=u,i=l;if(y(e))return"null"===e?(0,f.annotateCoreTypes)({type:"null"},r):(0,f.annotateCoreTypes)({type:e,...o},r);if("array"===e)return Array.isArray(r.items)?(0,f.annotateCoreTypes)({type:"tuple",elementTypes:r.items.map(e=>m(e,d(i,"items"))),additionalItems:void 0===r.additionalItems||("boolean"==typeof r.additionalItems?r.additionalItems:m(r.additionalItems,d(i,"additionalItems"))),minItems:null!=(a=r.minItems)?a:0,...o},r):!1===r.items?(0,f.annotateCoreTypes)({type:"tuple",elementTypes:[],additionalItems:!1,minItems:0,...o},r):(0,f.annotateCoreTypes)({type:"array",elementType:void 0===r.items||!0===r.items?{type:"any"}:m(r.items,d(i,"items")),...o},r);if("object"===e){let n=new Set(null!=(a=r.required)?a:[]);var a=null!=(a=r.additionalProperties)?a:i.defaultAdditionalProperties;return(0,f.annotateCoreTypes)({type:"object",properties:Object.fromEntries(Object.entries(null!=(t=r.properties)?t:{}).map(([e,t])=>[e,{node:m(t,d(d(i,"properties"),e)),required:n.has(e)}])),additionalProperties:"boolean"==typeof a?a:m(a,d(i,"additionalProperties")),...o},r)}i.throwUnsupportedError(`Unsupported JSON Schema type "${e}"`,{blob:{schema:r}})})).length?a(t[0]):a({type:"or",or:t})}c.convertJsonSchemaToCoreTypes=function(e,n={}){let r=("string"==typeof e?(0,i.getAstByString):(0,i.getAstByObject))(e),o=(e=r.json)["definitions"];return{data:e={version:1,types:Object.keys(null!==o&&void 0!==o?o:{}).map(e=>{var t;return{...m((null!==o&&void 0!==o?o:{})[e],{locByPath(){return{path:this.path,loc:(0,i.getLocation)(r,{dataPath:this.path,markIdentifier:!0})}},path:["definitions",e],throwUnsupportedError(e,t){throw(t={...t}).path||(t.path=this.path),t.loc||(t.loc=(0,i.getLocation)(r,{dataPath:this.path,markIdentifier:!0})),new O.UnsupportedError(e,t)},defaultAdditionalProperties:null==(t=n.defaultAdditionalProperties)||t}),name:e}})},convertedTypes:e.types.map(({name:e})=>e),notConvertedTypes:[]}},c.complexProps=new Set(["anyOf","allOf","oneOf","then","else"]);let y=e=>["string","number","integer","boolean","null"].includes(e)},{"./annotations":2,"core-types":6,jsonpos:25,"openapi-json-schema":18}],5:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.convertOpenApiToCoreTypes=n.convertCoreTypesToOpenApi=void 0;let o=e("openapi-json-schema"),i=e("./core-types-to-json-schema"),r=e("./json-schema-to-core-types");n.convertCoreTypesToOpenApi=function(e,t){let{data:n,...r}=(0,i.convertCoreTypesToJsonSchema)(e,t);return{...r,data:(0,o.jsonSchemaDocumentToOpenApi)(n,t)}},n.convertOpenApiToCoreTypes=function(e){return e="string"==typeof e?JSON.parse(e):e,e=(0,o.openApiToJsonSchema)(e),(0,r.convertJsonSchemaToCoreTypes)(e)}},{"./core-types-to-json-schema":3,"./json-schema-to-core-types":4,"openapi-json-schema":18}],6:[function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)},i=(Object.defineProperty(n,"__esModule",{value:!0}),n.traverse=n.some=n.mergeLocations=n.getPositionOffset=n.locationToLineColumn=n.positionToLineColumn=n.decorateError=n.decorateErrorMeta=n.isCoreTypesError=n.throwRelatedError=n.throwUnsupportedError=n.RelatedError=n.UnsupportedError=n.MissingReferenceError=n.MalformedTypeError=n.formatSee=n.formatDefault=n.formatExamples=n.stringify=n.stripAnnotations=n.stringifyAnnotations=n.extractAnnotations=n.mergeAnnotations=n.isNonNullable=n.union=n.intersection=n.isEqual=n.hasConstEnum=n.isPrimitiveType=n.ensureArray=n.validate=n.simplify=void 0,o(e("./lib/types"),n),e("./lib/simplify")),a=(Object.defineProperty(n,"simplify",{enumerable:!0,get:function(){return i.simplify}}),e("./lib/validate")),l=(Object.defineProperty(n,"validate",{enumerable:!0,get:function(){return a.validate}}),e("./lib/util")),s=(Object.defineProperty(n,"ensureArray",{enumerable:!0,get:function(){return l.ensureArray}}),Object.defineProperty(n,"isPrimitiveType",{enumerable:!0,get:function(){return l.isPrimitiveType}}),Object.defineProperty(n,"hasConstEnum",{enumerable:!0,get:function(){return l.hasConstEnum}}),Object.defineProperty(n,"isEqual",{enumerable:!0,get:function(){return l.isEqual}}),Object.defineProperty(n,"intersection",{enumerable:!0,get:function(){return l.intersection}}),Object.defineProperty(n,"union",{enumerable:!0,get:function(){return l.union}}),Object.defineProperty(n,"isNonNullable",{enumerable:!0,get:function(){return l.isNonNullable}}),e("./lib/annotation")),u=(Object.defineProperty(n,"mergeAnnotations",{enumerable:!0,get:function(){return s.mergeAnnotations}}),Object.defineProperty(n,"extractAnnotations",{enumerable:!0,get:function(){return s.extractAnnotations}}),Object.defineProperty(n,"stringifyAnnotations",{enumerable:!0,get:function(){return s.stringifyAnnotations}}),Object.defineProperty(n,"stripAnnotations",{enumerable:!0,get:function(){return s.stripAnnotations}}),Object.defineProperty(n,"stringify",{enumerable:!0,get:function(){return s.stringify}}),Object.defineProperty(n,"formatExamples",{enumerable:!0,get:function(){return s.formatExamples}}),Object.defineProperty(n,"formatDefault",{enumerable:!0,get:function(){return s.formatDefault}}),Object.defineProperty(n,"formatSee",{enumerable:!0,get:function(){return s.formatSee}}),e("./lib/error")),c=(Object.defineProperty(n,"MalformedTypeError",{enumerable:!0,get:function(){return u.MalformedTypeError}}),Object.defineProperty(n,"MissingReferenceError",{enumerable:!0,get:function(){return u.MissingReferenceError}}),Object.defineProperty(n,"UnsupportedError",{enumerable:!0,get:function(){return u.UnsupportedError}}),Object.defineProperty(n,"RelatedError",{enumerable:!0,get:function(){return u.RelatedError}}),Object.defineProperty(n,"throwUnsupportedError",{enumerable:!0,get:function(){return u.throwUnsupportedError}}),Object.defineProperty(n,"throwRelatedError",{enumerable:!0,get:function(){return u.throwRelatedError}}),Object.defineProperty(n,"isCoreTypesError",{enumerable:!0,get:function(){return u.isCoreTypesError}}),Object.defineProperty(n,"decorateErrorMeta",{enumerable:!0,get:function(){return u.decorateErrorMeta}}),Object.defineProperty(n,"decorateError",{enumerable:!0,get:function(){return u.decorateError}}),e("./lib/location")),p=(Object.defineProperty(n,"positionToLineColumn",{enumerable:!0,get:function(){return c.positionToLineColumn}}),Object.defineProperty(n,"locationToLineColumn",{enumerable:!0,get:function(){return c.locationToLineColumn}}),Object.defineProperty(n,"getPositionOffset",{enumerable:!0,get:function(){return c.getPositionOffset}}),Object.defineProperty(n,"mergeLocations",{enumerable:!0,get:function(){return c.mergeLocations}}),e("./lib/traverse"));Object.defineProperty(n,"some",{enumerable:!0,get:function(){return p.some}}),Object.defineProperty(n,"traverse",{enumerable:!0,get:function(){return p.traverse}})},{"./lib/annotation":7,"./lib/error":8,"./lib/location":9,"./lib/simplify":13,"./lib/traverse":14,"./lib/types":15,"./lib/util":16,"./lib/validate":17}],7:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.stringify=n.formatSee=n.formatDefault=n.formatExamples=n.arrayOrSingle=n.stripAnnotations=n.stringifyAnnotations=n.wrapWhitespace=n.extractAnnotations=n.mergeAnnotations=void 0;let c=e("./location"),p=e("./util");function l(e){return e.includes("\n")?["*",e.split("\n").map(e=>" * "+e).join("\n")," "].join("\n"):e.startsWith(" ")?e:" "+e}function f(e){return 1===e.length?e[0]:e}function s(e){return e.map(e=>"@example\n"+o(r(e).split("\n"),4)).join("\n").trim()}function u(e){return["@default",o(r(e).split("\n"),4)].join("\n").trim()}function d(e){return e.map(e=>"@see "+r(e)).join("\n").trim()}function r(e){return"string"==typeof e?e:JSON.stringify(e,null,2)}function o(e,n,r=!1){return e.map((e,t)=>{return(0===t&&r?" ".repeat(n-2)+"* ":" ".repeat(n))+e}).join("\n")}n.mergeAnnotations=function(e){let t,n=e=>!!e;var r=(e,t="\n")=>(0,p.uniq)(e.filter(n)).join(t).trim(),o=null==(t=e.find(e=>e.name))?void 0:t.name,i=r(e.map(e=>e.title),", "),a=r(e.map(e=>e.description)),l=(0,p.uniq)([].concat(...e.map(e=>(0,p.ensureArray)(e.examples))).filter(n)),s=r(e.map(e=>e.default)),u=(0,p.uniq)([].concat(...e.map(e=>(0,p.ensureArray)(e.see))).filter(n)),r=r(e.map(e=>e.comment)),e=(0,c.mergeLocations)(e.map(e=>e.loc));return{...o?{name:o}:{},...i?{title:i}:{},...a?{description:a}:{},...0e).join("\n\n").trim().replace(/\*\//g,"*\\/");return n&&e?l(e):e},n.stripAnnotations=function t(e,n=!0){let{comment:r,description:o,default:i,examples:a,see:l,title:s,...u}=e,c=u;if(n){if("and"===c.type)return{...c,and:c.and.map(e=>t(e,!0))};if("or"===c.type)return{...c,or:c.or.map(e=>t(e,!0))};if("array"===c.type)return{...c,elementType:t(c.elementType,!0)};if("tuple"===c.type)return{...c,elementTypes:c.elementTypes.map(e=>t(e,!0)),additionalItems:"object"==typeof c.additionalItems?t(c.additionalItems,!0):c.additionalItems};if("object"===c.type)return{...c,properties:Object.fromEntries(Object.keys(c.properties).map(e=>[e,{...c.properties[e],node:t(c.properties[e].node,!0)}])),additionalProperties:"object"==typeof c.additionalProperties?t(c.additionalProperties,!0):c.additionalProperties}}return c},n.arrayOrSingle=f,n.formatExamples=s,n.formatDefault=u,n.formatSee=d,n.stringify=r},{"./location":9,"./util":16}],8:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.decorateError=n.decorateErrorMeta=n.isCoreTypesError=n.throwRelatedError=n.throwUnsupportedError=n.RelatedError=n.UnsupportedError=n.MissingReferenceError=n.MalformedTypeError=n.CoreTypesError=void 0;class r extends Error{constructor(e,t={}){super(e),Object.setPrototypeOf(this,r.prototype),this.blob=t.blob,this.path=t.path,this.loc=t.loc,this.source=t.source,this.filename=t.filename,this.relatedError=t.relatedError}}n.CoreTypesError=r;class o extends r{constructor(e,t={}){super(e,t),Object.setPrototypeOf(this,o.prototype)}}n.MalformedTypeError=o;class i extends r{constructor(e,t={}){super(`Reference to missing type "${e}"`,t),Object.setPrototypeOf(this,i.prototype)}}n.MissingReferenceError=i;class a extends r{constructor(e,t={}){super(e,t),Object.setPrototypeOf(this,a.prototype)}}n.UnsupportedError=a;class l extends r{constructor(e,t={}){super(e.message,{...t,relatedError:e}),Object.setPrototypeOf(this,l.prototype)}}function s(e){return e instanceof r}function u(e,t){return t.blob&&null==e.blob&&(e.blob=t.blob),t.path&&null==e.path&&(e.path=t.path),t.loc&&null==e.loc&&(e.loc=t.loc),t.source&&null==e.source&&(e.source=t.source),t.filename&&null==e.filename&&(e.filename=t.filename),e}n.RelatedError=l,n.throwUnsupportedError=function(e,t,n){throw new a(e,{blob:t,...t.loc?{loc:t.loc}:{},...n?{path:n}:{}})},n.throwRelatedError=function(e,t){throw new l(e,t)},n.isCoreTypesError=s,n.decorateErrorMeta=u,n.decorateError=function(e,t){return s(e)&&u(e,t),e}},{}],9:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.mergeLocations=n.getPositionOffset=n.locationToLineColumn=n.positionToLineColumn=void 0;let s=e("./util");function r(e,t){var n=e.slice(0,t).split("\n").length,e=e.lastIndexOf("\n",t);return-1===e?{offset:t,line:n,column:t}:{offset:t,line:n,column:t-e}}n.positionToLineColumn=r,n.locationToLineColumn=function(e,t){return"object"==typeof t.start?t:{start:void 0===t.start?void 0:r(e,t.start),...null==t.end?{}:{end:r(e,t.end)}}},n.getPositionOffset=function(e){return void 0===e||"number"==typeof e?e:e.offset},n.mergeLocations=function(e){let t,n,r,o,i,a=e=>"number"==typeof e?e:null==e?void 0:e.offset;e.filter(s.isNonNullable).forEach(({start:e,end:t})=>{var n=a(e),r=a(t);void 0!==n&&(!o||"number"==typeof o.location&&o.location===n||o.offset>n)&&(o={location:e,offset:n}),void 0!==r&&(!i||"number"==typeof i.location&&i.location===n||i.offseti(e))).some(e=>0===e.length)?[]:(0,r.uniq)([].concat(...e))},n.combineConstAndEnum=i},{"../util":16}],11:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.intersectConstEnum=void 0;let r=e("../annotation"),o=e("../util");n.intersectConstEnum=function(e){if(0===e.length)throw new Error("Cannot intersect const and enum from an empty array of nodes");var t;return 1===e.length?e[0]:(t=(t=e.map(e=>void 0!==e.const?[e.const]:void 0!==e.enum?e.enum:void 0).filter(e=>!!e)).slice(1).reduce((e,t)=>(0,o.intersection)(e,t),t[0]),{type:e[0].type,...1===t.length?{const:t[0]}:{},...1!==t.length?{enum:t}:{},...(0,r.mergeAnnotations)(e)})}},{"../annotation":7,"../util":16}],12:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.simplifySingle=void 0;let r=e("./const-enum");n.simplifySingle=function(e){return"boolean"===e.type||"integer"===e.type||"number"===e.type||"string"===e.type?(0,r.simplifyEnumAndConst)(e):e}},{"./const-enum":10}],13:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.simplify=void 0;let a=e("./simplifications/single"),l=e("./simplifications/const-enum"),o=e("./simplifications/intersect-const-enum"),i=e("./error"),s=e("./annotation"),u=e("./util"),c=["any","string","number","integer","boolean"];n.simplify=function r(t){if(Array.isArray(t))return t.map(e=>r(e));if((0,u.isNodeDocument)(t))return{...t,types:r(t.types)};var e,n=e=>(0,u.copyName)(t,e);if("tuple"===t.type)return{...t,elementTypes:t.elementTypes.map(e=>r(e)),...t.additionalItems&&"object"==typeof t.additionalItems?{additionalItems:r(t.additionalItems)}:{}};if("array"===t.type)return{...t,elementType:r(t.elementType)};if("object"===t.type)return{...t,properties:Object.fromEntries(Object.entries(t.properties).map(([e,{node:t,required:n}])=>[e,{node:r(t),required:n}])),...t.additionalProperties&&"object"==typeof t.additionalProperties?{additionalProperties:r(t.additionalProperties)}:{}};if("and"!==t.type&&"or"!==t.type)return n((0,a.simplifySingle)(t));if("and"===t.type)return 1===(e=function(e){if(0<(e=(0,u.splitTypes)(e)).any.length){if(0===e.and.length&&0===e.or.length&&0===e.ref.length&&0===e.null.length&&0===e.string.length&&0===e.number.length&&0===e.integer.length&&0===e.boolean.length&&0===e.object.length&&0===e.array.length&&0===e.tuple.length)return[{type:"any",...(0,s.mergeAnnotations)(e.any.map(({node:e})=>e))}];e.any=[]}var t=e=>e.map(({node:e})=>e);return 1e),...t(e.any)]),order:(0,u.firstSplitTypeIndex)(e.boolean)}]),1e),...t(e.any)]),order:(0,u.firstSplitTypeIndex)(e.string)}]),0e),...t(e.integer),...t(e.any)]),order:(0,u.firstSplitTypeIndex)(e.number)}],e.integer=[]):1e),...t(e.any)]),order:(0,u.firstSplitTypeIndex)(e.number)}]:1e),...t(e.any)]),order:(0,u.firstSplitTypeIndex)(e.integer)}]),000(e=r(e)).and||[e])))).length?n({...e[0],...(0,s.mergeAnnotations)([(0,s.extractAnnotations)(t),e[0]])}):n({type:"and",and:e,...(0,s.extractAnnotations)(t)});if("or"===t.type)return 1===(e=function(e){var t,n,r,o,i=(0,u.splitTypes)(e);if(0e)).length)return[{type:"any",...(0,s.mergeAnnotations)(i.any.map(({node:e})=>e))}];for([t,n]of Object.entries(i))c.includes(t)&&n.length&&(r=n.map(({node:e})=>e),0===(o=(0,l.mergeConstEnumUnion)(r)).length?i[t]=[{node:{type:t,...(0,s.mergeAnnotations)(r)},order:(0,u.firstSplitTypeIndex)(n)}]:i[t]=[{node:(0,a.simplifySingle)({type:t,enum:o,...(0,s.mergeAnnotations)(r)}),order:(0,u.firstSplitTypeIndex)(n)}]);return 000(e=r(e)).or||[e])))).length?n({...e[0],...(0,s.mergeAnnotations)([(0,s.extractAnnotations)(t),e[0]])}):n({type:"or",or:e,...(0,s.extractAnnotations)(t)});throw new i.MalformedTypeError("Invalid node",t)}},{"./annotation":7,"./error":8,"./simplifications/const-enum":10,"./simplifications/intersect-const-enum":11,"./simplifications/single":12,"./util":16}],14:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.some=n.traverse=void 0;class r extends Error{}function o(e,t){function a(e,t,n,r,o,i){var i=void 0!==i?i:void 0===r?t[n]:t[n][r],a=[...e.path,n,...void 0===r?[]:[r]];return Object.assign({},e,{node:i,path:a,parentNode:t,parentProperty:n,index:r,required:o})}!function n(r,o){o(r);let i=r.node;if("array"===i.type)n(a(r,i,"elementType"),o);else if("tuple"===i.type)i.elementTypes.forEach((e,t)=>n(a(r,i,"elementTypes",t),o)),"object"==typeof i.additionalItems&&n(a(r,i,"additionalItems"),o);else if("object"===i.type){for(var e of Object.keys(i.properties))n(a(r,i,"properties",e,i.properties[e].required,i.properties[e].node),o);"object"==typeof i.additionalProperties&&n(a(r,i,"additionalProperties"),o)}else"and"===i.type?i.and.forEach((e,t)=>n(a(r,i,"and",t),o)):"or"===i.type&&i.or.forEach((e,t)=>n(a(r,i,"or",t),o))}({node:e,rootNode:e,path:[]},t)}n.traverse=o,n.some=function(e,t){try{o(e,e=>{if(t(e))throw new r})}catch(e){if(e instanceof r)return!0;throw e}return!1}},{}],15:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0})},{}],16:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.isNodeDocument=n.isNonNullable=n.copyName=n.firstSplitTypeIndex=n.flattenSplitTypeValues=n.splitTypes=n.union=n.intersection=n.isEqual=n.hasConstEnum=n.constEnumTypes=n.isPrimitiveType=n.ensureArray=n.uniq=void 0,n.uniq=function(r){return r.filter((t,n)=>{for(let e=0;e["null","string","number","integer","boolean"].includes(e.type),n.constEnumTypes=new Set(["any","string","number","integer","boolean","object","array","tuple","ref"]);function o(t,n){var e;return typeof t==typeof n&&!(null===t!=(null===n)||null!==t&&(Array.isArray(t)&&Array.isArray(n)?t.length!==n.length||t.some((e,t)=>!o(e,n[t])):Array.isArray(t)!==Array.isArray(n)||("object"==typeof t?!o(e=Object.keys(t).sort(),Object.keys(n).sort())||e.some(e=>!o(t[e],n[e])):t!==n)))}n.hasConstEnum=e=>n.constEnumTypes.has(e.type),n.isEqual=o,n.intersection=function(e,n){let r=[];return e.forEach(t=>{n.forEach(e=>{o(t,e)&&r.push(t)})}),r},n.union=function(e,t){let n=[...e];return t.forEach(t=>{e.some(e=>o(t,e))||n.push(t)}),n},n.splitTypes=function(e){let n={and:[],or:[],ref:[],any:[],null:[],string:[],number:[],integer:[],boolean:[],object:[],array:[],tuple:[]};return e.forEach((e,t)=>{("and"!==e.type&&"or"!==e.type||"and"===e.type&&0e.order-t.order).map(({node:e})=>e))},n.firstSplitTypeIndex=function(e){return Math.min(...e.map(({order:e})=>e))},n.copyName=function(e,t){return void 0===e.name?t:{...t,name:e.name}},n.isNonNullable=function(e){return null!=e},n.isNodeDocument=function(e){return Array.isArray(e.types)}},{}],17:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.validate=void 0;let r=e("./error"),o=e("./util");n.validate=function t(e){if((0,o.hasConstEnum)(e)){var n=e;if(n.enum&&0===n.enum.length)throw new r.MalformedTypeError("Empty enum is not allowed",n);if(n.enum&&void 0!==n.const&&!n.enum.some(e=>(0,o.isEqual)(e,n.const)))throw new r.MalformedTypeError("Enum and const are both set, but enum doesn't contain const",n)}"and"===e.type&&e.and.forEach(e=>t(e)),"or"===e.type&&e.or.forEach(e=>t(e))}},{"./error":8,"./util":16}],18:[function(e,t,n){var r=this&&this.__createBinding||(Object.create?function(e,t,n,r){void 0===r&&(r=n),Object.defineProperty(e,r,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,r){e[r=void 0===r?n:r]=t[n]}),o=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||r(t,e,n)};Object.defineProperty(n,"__esModule",{value:!0}),o(e("./lib"),n),o(e("./lib/types"),n),o(e("./lib/utils"),n)},{"./lib":19,"./lib/types":22,"./lib/utils":23}],19:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.openApiToJsonSchema=n.jsonSchemaDocumentToOpenApi=n.decorateOpenApi=void 0;let o=e("./json-schema-to-openapi"),r=e("./openapi-to-json-schema");function i(e,{title:t,version:n,schemaVersion:r="3.0.0"}){t={title:t,version:n};return e.$id&&(t["x-id"]=e.$id,delete e.$id),e.$comment&&(t["x-comment"]=e.$comment,delete e.$comment),delete e.$schema,{openapi:r,info:t,paths:{},...e}}n.decorateOpenApi=i,n.jsonSchemaDocumentToOpenApi=function(e,t){let{definitions:n={},...r}=e;return i({...r,components:{schemas:Object.fromEntries(Object.entries(n).map(([e,t])=>[e,(0,o.jsonSchemaTypeToOpenApi)(t)]))}},t)},n.openApiToJsonSchema=function(e){let t=e.components.schemas;return{definitions:Object.fromEntries(Object.keys(t).map(e=>[e,(0,r.openApiToJsonSchemaType)(t[e])]))}}},{"./json-schema-to-openapi":20,"./openapi-to-json-schema":21}],20:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.jsonSchemaTypeToOpenApi=void 0;let r=e("./utils");n.jsonSchemaTypeToOpenApi=function e(t){var n;return"boolean"==typeof t?t:(t=function(e){if(void 0===e.type)return e;let{type:t,...n}=e,r=Array.isArray(t)?t.includes("null"):"null"===t;var o=Array.isArray(t)?t.filter(e=>"null"!==e):"null"===t?void 0:t;let i=(e,t)=>"any"!==t&&t?{...e,type:t}:e;return void 0!==e.const&&(n.enum=[e.const],delete n.const),e=e=>r?{...e,nullable:r}:e,Array.isArray(o)?0===o.length?e(n):1===o.length?i(e(n),o[0]):{...e(n),anyOf:o.map(e=>i({},e))}:i(e(n),o)}(t),t=(n=t).$ref?{...n,$ref:(0,r.encodeRefNameOpenApi)((0,r.decodeRefNameJsonSchema)(n.$ref))}:n,(0,r.recurseSchema)(t,e))}},{"./utils":23}],21:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.openApiToJsonSchemaType=void 0;let a=e("./utils");n.openApiToJsonSchemaType=function e(t){if("boolean"==typeof t)return t;let{type:n,nullable:r,...o}=t;var i,t=function(e,t){if(void 0!==e&&"any"!==e)return Array.isArray(e)?e.includes("any")?void 0:(!e.includes("null")&&t&&e.push("null"),1===e.length?e[0]:e):"null"!==e&&t?[e,"null"]:e}(n,r),t={...o,...t?{type:t}:{}},t=(i=t).$ref?{...i,$ref:(0,a.encodeRefNameJsonSchema)((0,a.decodeRefNameOpenApi)(i.$ref))}:i;return(0,a.recurseSchema)(t,e)}},{"./utils":23}],22:[function(e,t,n){arguments[4][15][0].apply(n,arguments)},{dup:15}],23:[function(e,t,n){function r(e){return encodeURIComponent(e)}function o(e){return decodeURIComponent(e)}function i(e){return e&&0n(e))}:{items:n(r.items)},..."object"!=typeof r.additionalItems?{}:{additionalItems:n(r.additionalItems)},..."object"!=typeof r.contains?{}:{contains:n(r.contains)},...i(r.properties)?{properties:Object.fromEntries(Object.keys(r.properties).map(e=>{var t;return[e,n(null==(t=r.properties)?void 0:t[e])]}))}:{},...i(r.patternProperties)?{patternProperties:Object.fromEntries(Object.keys(r.patternProperties).map(e=>{var t;return[e,n(null==(t=r.patternProperties)?void 0:t[e])]}))}:{},..."object"!=typeof r.additionalProperties?{}:{additionalProperties:n(r.additionalProperties)},...i(r.dependencies)?{dependencies:Object.fromEntries(Object.keys(r.dependencies).map(e=>{var t;return[e,n(null==(t=r.dependencies)?void 0:t[e])]}))}:{},..."object"!=typeof r.propertyNames?{}:{propertyNames:n(r.propertyNames)},..."object"!=typeof r.if?{}:{if:n(r.if)},..."object"!=typeof r.then?{}:{then:n(r.then)},..."object"!=typeof r.else?{}:{else:n(r.else)},..."object"==typeof r.allOf&&r.allOf.length?{allOf:r.allOf.map(e=>n(e))}:{},..."object"==typeof r.anyOf&&r.anyOf.length?{anyOf:r.anyOf.map(e=>n(e))}:{},..."object"==typeof r.oneOf&&r.oneOf.length?{oneOf:r.oneOf.map(e=>n(e))}:{},..."object"!=typeof r.not?{}:{not:n(r.not)},...i(r.definitions)?{definitions:Object.fromEntries(Object.keys(r.definitions).map(e=>{var t;return[e,n(null==(t=r.definitions)?void 0:t[e])]}))}:{}}}},{}],24:[function(e,n,r){!function(e){!function(){var e,t;e=this,t=function(){function e(e,t){return e(t={exports:{}},t.exports),t.exports}var l=new(e(function(e){function t(){function l(e,t){var n,r,o=e.charCodeAt(t=void 0===t?0:t);return 55296<=o&&o<=56319&&t=e.length-1))for(var n,r=s(l(e,t)),o=[],i=t+1;i=n)return r.substr(0,n);while(n>r.length&&t>1){if(t&1)r+=e;t>>=1;e+=e}r+=e;r=r.substr(0,n);return r}"use strict";var l=function e(t,n,r){if(t==null||n==null)return t;var o=String(t);var i=typeof n==="number"?n:parseInt(n,10);if(isNaN(i)||!isFinite(i))return o;var a=o.length;if(a>=i)return o;var l=r==null?"":String(r);if(l==="")l=" ";var s=i-a;while(l.lengths?l.substr(0,s):l;return u+o},m=Object.assign||function(e){for(var t=1;t at "+n.filter(Boolean).join(":")}},s={unexpectedSymbol:function(e){for(var t=arguments.length,n=Array(1 at "+n.filter(Boolean).join(":")}},d={LEFT_BRACE:0,RIGHT_BRACE:1,LEFT_BRACKET:2,RIGHT_BRACKET:3,COLON:4,COMMA:5,STRING:6,NUMBER:7,TRUE:8,FALSE:9,NULL:10},o={"{":d.LEFT_BRACE,"}":d.RIGHT_BRACE,"[":d.LEFT_BRACKET,"]":d.RIGHT_BRACKET,":":d.COLON,",":d.COMMA},m={true:d.TRUE,false:d.FALSE,null:d.NULL},y={_START_:0,START_QUOTE_OR_CHAR:1,ESCAPE:2},h={'"':0,"\\":1,"/":2,b:3,f:4,n:5,r:6,t:7,u:8},b={_START_:0,MINUS:1,ZERO:2,DIGIT:3,POINT:4,DIGIT_FRACTION:5,EXP:6,EXP_DIGIT_OR_SIGN:7};function g(e){return"1"<=e&&e<="9"}function v(e){return"0"<=e&&e<="9"}function O(e){return"e"===e||"E"===e}function T(e,t,n,r){var o=e.charAt(t);if("\r"===o)n++,r=1,"\n"===e.charAt(++t)&&t++;else if("\n"===o)t++,n++,r=1;else{if("\t"!==o&&" "!==o)return null;t++,r++}return{index:t,line:n,column:r}}function E(e,t,n,r){e=e.charAt(t);return e in o?{type:o[e],line:n,column:r+1,index:t+1,value:null}:null}function A(e,t,n,r){for(var o in m)if(m.hasOwnProperty(o)&&e.substr(t,o.length)===o)return{type:m[o],line:n,column:r+o.length,index:t+o.length,value:o};return null}function j(e,t,n,r){for(var o=t,i=y._START_;te),l=e=>{return e=e,"."+a.slice(0,e).join(".")+` [query: ${a.join(".")}]`};return{start:null==(t=a.reduce((e,t,n)=>{if("Object"===e.type){var r,o=e.children.find(e=>e.key.value===t);if(o)return{key:o,value:r}=o,i&&n===a.length-1?o:r;throw new Error(`No such property ${t} in `+l(n))}if("Array"!==e.type)return e;o=Number(t);if(isNaN(o))throw new Error(`Invalid non-numeric array index "${t}" `+"in array at "+l(n));if(o<0||o>=e.children.length)throw new RangeError(`Index ${o} out-of-bounds in array of `+`size ${e.children.length} at `+l(n));return e.children,e.children[Number(t)]},e).loc)?void 0:t.start,end:null==t?void 0:t.end}}},{}],27:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.getAstByObject=n.getAstByString=void 0;let r=e("json-to-ast");function o(e,t){var n=r(e,{loc:!0});return{json:t||JSON.parse(e),jsonString:e,jsonAST:n}}n.getAstByString=o,n.getAstByObject=function(e,t=4){return o(JSON.stringify(e,null,t))}},{"json-to-ast":24}],28:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});let j=e("core-types-json-schema"),P=e("./utils/sharedUtils"),x=e("./utils/constants"),S=e("./utils/nosqlUtils");Draw.loadPlugin(function(b){var e=document.createElement("div");e.style.userSelect="none",e.style.overflow="hidden",e.style.padding="10px",e.style.height="100%";let r=document.createElement("textarea"),t=(r.style.height="200px",r.style.width="100%","-- click a nosql type button");r.value=t,mxUtils.br(e),e.appendChild(r);var n=b.menus.get("exportAs");let o="tonosql=To NoSQL",i=(n&&!window.VsCodeApi||(o="tonosql=Export As NoSQL"),mxResources.parse(o),new mxWindow(mxResources.get("tonosql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));i.destroyOnClose=!1,i.setMaximizable(!1),i.setResizable(!1),i.setClosable(!0),mxUtils.br(e);var a=mxUtils.button(mxResources.get("reset"),function(){r.value=t}),a=(a.style.marginTop="8px",a.style.marginRight="4px",a.style.padding="4px",e.appendChild(a),mxUtils.button("OpenAPI",function(){{var t="openapi",n=(0,P.getMermaidDiagramDb)(b,t),n=(0,S.dbToOpenApi)(n);let e="";if("openapi"!=t)throw new Error(`type:${t} is not supported`);e=JSON.stringify(n,null,2),r.value=e}}));a.style.marginTop="8px",a.style.padding="4px",e.appendChild(a),b.actions.addAction("tonosql",function(){i.setVisible(!i.isVisible()),i.isVisible()&&r.focus()});let g=[],f,d=[],v=[],m=null,O=null,T=0,E;e=document.createElement("div");e.style.userSelect="none",e.style.overflow="hidden",e.style.padding="10px",e.style.height="100%";let l=document.createElement("textarea"),s=(l.style.height="200px",l.style.width="100%",` { "openapi": "3.0.0", "info": { "title": "nosql plugin sample", - "version": "${B.pluginVersion}", + "version": "${x.pluginVersion}", "x-comment": "Generated by core-types-json-schema (https://github.com/grantila/core-types-json-schema)" }, "paths": {}, @@ -68,4 +68,4 @@ } } } - `),k=(s.value=c,mxUtils.br(e),e.appendChild(s),mxResources.parse("fromNoSql=From NoSQL"),new mxWindow(mxResources.get("fromNoSql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));function u(t,n){var r,o,i,a;_=[],I=null,w=null;try{let e=null;var l={title:"nosql default options",version:B.pluginVersion};if("openapi"!=n)throw new Error(`type:${n} is not supported`);var s=JSON.parse(t),c=(0,$.convertOpenApiToCoreTypes)(s)["data"],u=(0,$.convertCoreTypesToJsonSchema)(c)["data"],p=null==(r=null===(e=(0,$.jsonSchemaDocumentToOpenApi)(u,l))||void 0===e?void 0:e.components)?void 0:r.schemas;if(p){var f,d,m,y={Dialect:"nosql",TableList:[],PrimaryKeyList:[],ForeignKeyList:[]};for(f in p)if(Object.prototype.hasOwnProperty.call(p,f)){var h,b=p[f],g={Name:(0,U.dbTypeEnds)(f),Properties:[]};for(h in b.properties)if(Object.prototype.hasOwnProperty.call(b.properties,h)){var v,O,T=b.properties[h],E=function(e,t,n){let r,o=(null!==(r=n.type)&&void 0!==r?r:"object").toString();n.nullable&&(o+=" nullable");n={Name:(0,U.dbTypeEnds)(t),IsPrimaryKey:!1,IsForeignKey:!1,ColumnProperties:o,TableName:(0,U.dbTypeEnds)(e),ForeignKey:[]};return n}(f,h,T);if(E.ColumnProperties.includes("object")||E.ColumnProperties.includes("array")){let e=null;T.$ref?e=T.$ref.split("/").pop():T.items&&"object"==typeof T.items&&(e=null==(o=T.items.$ref)?void 0:o.split("/").pop()),e&&(v={PrimaryKeyTableName:(0,U.dbTypeEnds)(f),ReferencesTableName:(0,U.dbTypeEnds)(e),PrimaryKeyName:(0,U.dbTypeEnds)(h),ReferencesPropertyName:"",IsDestination:!1},O={ReferencesTableName:(0,U.dbTypeEnds)(f),PrimaryKeyTableName:(0,U.dbTypeEnds)(e),ReferencesPropertyName:(0,U.dbTypeEnds)(h),PrimaryKeyName:"",IsDestination:!0},y.ForeignKeyList.push(O),y.ForeignKeyList.push(v),E.IsForeignKey=!0)}g.Properties.push(E)}y.TableList.push(g)}for(let e=0;ee.Name==t.ReferencesTableName))?void 0:i.Properties[0])&&(y.ForeignKeyList[e].ReferencesPropertyName=d.Name),t.PrimaryKeyName||(m=null==(a=y.TableList.find(e=>e.Name==t.PrimaryKeyTableName))?void 0:a.Properties[0])&&(y.ForeignKeyList[e].PrimaryKeyName=m.Name)}C=y.ForeignKeyList,R=y.PrimaryKeyList,N=y.TableList,L=N.length;var j=n;if(N.forEach(function(n){var e,t=100+n.Name.length;(I=new mxCell(n.Name,new mxGeometry(M,0,t,26),"swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=default;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=default;align=center;")).vertex=!0,w&&null!==(e=S.editor.graph.getPreferredSizeForCell(w))&&(I.geometry.width=e.width+t),_.push(I),n.Properties.forEach(function(e){var t;e=e,n.Name,t=e.Name+(e.ColumnProperties?" "+e.ColumnProperties:""),(w=new mxCell(t,new mxGeometry(0,0,90,26),"shape=partialRectangle;top=0;left=0;right=0;bottom=0;align=left;verticalAlign=top;spacingTop=-2;fillColor=none;spacingLeft=64;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;dropTarget=0;")).vertex=!0,t=e.IsPrimaryKey&&e.IsForeignKey?"PK | FK":e.IsPrimaryKey?"PK":e.IsForeignKey?"FK":"",(e=sb.cloneCell(w,t)).connectable=!1,e.style="shape=partialRectangle;top=0;left=0;bottom=0;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=180;points=[];portConstraint=eastwest;part=1;",e.geometry.width=54,e.geometry.height=26,w.insert(e),t=S.editor.graph.getPreferredSizeForCell(w),I&&(null!==t&&I.geometry.width-1!==["FK","PK"].findIndex(e=>e==t.value.toUpperCase())||-1!=t.value.toUpperCase().indexOf("PK,"));if(p&&(u.attributeKeyType=p.value,"PK"!=u.attributeKeyType)&&-1!=u.attributeKeyType.indexOf("PK")&&(u.attributeKeyType="PK"),l.attributes.push(u),s.edges&&s.edges.length)for(let e=0;e-1!=t.toLocaleLowerCase().indexOf(e)),d=n&&-1!=d.findIndex(e=>-1!=n.toLocaleLowerCase().indexOf(e));if(!d&&!m||d&&m){if(d&&m){var y,d=E(f.source.value,c),h=(d.attributeKeyType="PK",v=d.attributeName,T(f.source.parent.value)),b=E(f.target.value,c),g=(b.attributeKeyType="PK",y=b.attributeName,T(f.target.parent.value)),d={name:T(h)+"_"+T(g),attributes:[d,b]};r[d.name]||(r[d.name]=d);let t={entityA:h,entityB:d.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${h}.${v}] to [${d.name}.${v}]`},n=(-1==o.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&o.push(t),{entityA:g,entityB:d.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${g}.${y}] to [${d.name}.${y}]`});-1==o.findIndex(e=>e.entityA==n.entityA&&e.entityB==n.entityB&&e.roleA==n.roleA)&&o.push(n)}}else{b=E(f.source.value,c).attributeName;var v,h=T(f.source.parent.value),g=(v=E(f.target.value,c).attributeName,T(f.target.parent.value));let t={entityA:m?h:g,entityB:m?g:h,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:m?`[${h}.${b}] to [${g}.${v}]`:`[${g}.${v}] to [${h}.${b}]`};-1==o.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&o.push(t)}}}}}if(r[l.name]){let e=2;for(;r[l.name+e.toString()];)e++;r[l.name+e.toString()]=l}else r[l.name]=l}}e=new class{constructor(e,t){this.entities=e,this.relationships=t}getEntities(){return this.entities}getRelationships(){return this.relationships}}(r,o);return e}},{}]},{},[28]); \ No newline at end of file + `),A=(l.value=s,mxUtils.br(e),e.appendChild(l),mxResources.parse("fromNoSql=From NoSQL"),new mxWindow(mxResources.get("fromNoSql"),e,document.body.offsetWidth-480,140,320,320,!0,!0));function u(t,n){var r;v=[],m=null,O=null;try{let e=null;var o={title:"nosql default options",version:x.pluginVersion};if("openapi"!=n)throw new Error(`type:${n} is not supported`);var i=JSON.parse(t),a=(0,j.convertOpenApiToCoreTypes)(i)["data"],l=(0,j.convertCoreTypesToJsonSchema)(a)["data"],s=((0,j.jsonSchemaDocumentToOpenApi)(l,o),null==(r=null===(e=i)||void 0===e?void 0:e.components)?void 0:r.schemas);if(s){var u=(0,S.ConvertOpenApiToDatabaseModel)(s),c=(g=u.ForeignKeyList,f=u.PrimaryKeyList,d=u.TableList,E=d.length,n);if(d.forEach(function(n){var e,t=100+n.Name.length;(m=new mxCell(n.Name,new mxGeometry(T,0,t,26),"swimlane;fontStyle=0;childLayout=stackLayout;horizontal=1;startSize=26;fillColor=default;horizontalStack=0;resizeParent=1;resizeLast=0;collapsible=1;marginBottom=0;swimlaneFillColor=default;align=center;")).vertex=!0,O&&null!==(e=b.editor.graph.getPreferredSizeForCell(O))&&(m.geometry.width=e.width+t),v.push(m),n.Properties.forEach(function(e){var t;e=e,n.Name,t=e.Name+(e.ColumnProperties?" "+e.ColumnProperties:""),(O=new mxCell(t,new mxGeometry(0,0,90,26),"shape=partialRectangle;top=0;left=0;right=0;bottom=0;align=left;verticalAlign=top;spacingTop=-2;fillColor=none;spacingLeft=64;spacingRight=4;overflow=hidden;rotatable=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;dropTarget=0;")).vertex=!0,t=e.IsPrimaryKey&&e.IsForeignKey?"PK | FK":e.IsPrimaryKey?"PK":e.IsForeignKey?"FK":"",(e=sb.cloneCell(O,t)).connectable=!1,e.style="shape=partialRectangle;top=0;left=0;bottom=0;fillColor=none;align=left;verticalAlign=middle;spacingLeft=4;spacingRight=4;overflow=hidden;rotatable=180;points=[];portConstraint=eastwest;part=1;",e.geometry.width=54,e.geometry.height=26,O.insert(e),t=b.editor.graph.getPreferredSizeForCell(O),m&&(null!==t&&m.geometry.widthe.Name==t.ReferencesTableName))?void 0:p.Properties[0])&&(n.ForeignKeyList[e].ReferencesPropertyName=p.Name),t.PrimaryKeyName||(f=null==(p=n.TableList.find(e=>e.Name==t.PrimaryKeyTableName))?void 0:p.Properties[0])&&(n.ForeignKeyList[e].PrimaryKeyName=f.Name)}return n};let h=e("./constants"),b=e("./sharedUtils");function d(e,t,n){let r,o=(null!=(r=n.type)?r:"object").toString();n.enum?o=""+JSON.stringify(n.enum):n.nullable&&(o+=" nullable");n=(0,b.generateComment)(n.description,n.format),n&&(o+=" "+n),n={Name:(0,b.dbTypeEnds)(t),IsPrimaryKey:!1,IsForeignKey:!1,ColumnProperties:o,TableName:(0,b.dbTypeEnds)(e),ForeignKey:[]};return n}},{"./constants":29,"./sharedUtils":31}],31:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0}),n.GetColumnQuantifiers=P,n.removeHtml=r,n.dbTypeEnds=function(e){return`\`${e}\``},n.RemoveNameQuantifiers=x,n.getDbLabel=S,n.entityName=function(e,t){let n="";e&&(n+=""+e);t&&(n+=" @format "+t);n=n&&`/** ${n=n.trim()} */`;return n},n.getCommentIndexes=C,n.getMermaidDiagramDb=function(e,o){var t=e.editor.graph.getModel(),i={},a=[];for(var l in t.cells)if(Object.hasOwnProperty.call(t.cells,l)){var s=t.cells[l];if(-1!==s.mxObjectId.indexOf("mxCell")&&s.style&&s.style.trim().startsWith("swimlane;")){let t=s.value.toString(),n="",r="";if(null!==t&&void 0!==t&&t.includes(j.commentColumnQuantifiers.Start)&&null!==t&&void 0!==t&&t.includes(j.commentColumnQuantifiers.End)){let e=t.toString();var l=C(e),u=l.start,c=l.end;t=e.substring(0,l.beforeStart),-1!==(e=e.substring(u,c)).indexOf(j.formatKeyword)&&(l=e.indexOf(j.formatKeyword),r=e.substring(l+j.formatKeyword.length).trim(),e=e.substring(0,l)),e&&(n=e)}var p={name:x(t),attributes:[]},u=R(n,r);u&&(p.name+=u);for(let e=0;e-1!==["FK","PK"].findIndex(e=>e==t.value.toUpperCase())||-1!=t.value.toUpperCase().indexOf("PK,"));if(y&&(m.attributeKeyType=y.value,"PK"!=m.attributeKeyType)&&-1!=m.attributeKeyType.indexOf("PK")&&(m.attributeKeyType="PK"),p.attributes.push(m),f.edges&&f.edges.length)for(let e=0;e-1!=t.toLocaleLowerCase().indexOf(e)),b=n&&-1!=b.findIndex(e=>-1!=n.toLocaleLowerCase().indexOf(e));if(!b&&!g||b&&g){if(b&&g){var v,b=S(h.source.value,d),O=(b.attributeKeyType="PK",A=b.attributeName,x(h.source.parent.value)),T=S(h.target.value,d),E=(T.attributeKeyType="PK",v=T.attributeName,x(h.target.parent.value)),b={name:x(O)+"_"+x(E),attributes:[b,T]};i[b.name]||(i[b.name]=b);let t={entityA:O,entityB:b.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${O}.${A}] to [${b.name}.${A}]`},n=(-1==a.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&a.push(t),{entityA:E,entityB:b.name,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:`[${E}.${v}] to [${b.name}.${v}]`});-1==a.findIndex(e=>e.entityA==n.entityA&&e.entityB==n.entityB&&e.roleA==n.roleA)&&a.push(n)}}else{T=S(h.source.value,d).attributeName;var A,O=x(h.source.parent.value),E=(A=S(h.target.value,d).attributeName,x(h.target.parent.value));let t={entityA:g?O:E,entityB:g?E:O,relSpec:{cardA:"ZERO_OR_MORE",cardB:"ONLY_ONE",relType:"IDENTIFYING"},roleA:g?`[${O}.${T}] to [${E}.${A}]`:`[${E}.${A}] to [${O}.${T}]`};-1==a.findIndex(e=>e.entityA==t.entityA&&e.entityB==t.entityB&&e.roleA==t.roleA)&&a.push(t)}}}}}if(i[p.name]){let e=2;for(;i[p.name+e.toString()];)e++;i[p.name+e.toString()]=p}else i[p.name]=p}}e=N(i,a);return e},n.GenerateDatabaseModel=N,n.generateComment=R;let j=e("./constants");function P(e){var t={Start:'"',End:'"'};return e&&["mysql","ts","openapi"].includes(e)?(t.Start="`",t.End="`"):"sqlserver"==e&&(t.Start="[",t.End="]"),t}function r(e){var t=document.createElement("div"),e=(t.innerHTML=e,t.textContent||t.innerText||"");return t.remove(),e}function x(e){return e.replace(/\[|\]|\(|\"|\'|\`/g,"").trim()}function S(e,t){let n=r(e);e=(n=n.toString().replace(/\s+/g," "))[0]==t.Start&&-1!==n.indexOf(t.End+" ")?n.indexOf(t.End+" "):n.indexOf(" "),t=n.substring(e+1).trim();return{attributeName:x(n.substring(0,e+1)),attributeType:t}}function C(e){let t=!1;return{beforeStart:(t=-1!==e.indexOf(j.commentColumnQuantifiers.Start)&&-1!==e.indexOf(j.commentColumnQuantifiers.End)?!0:t)?e.indexOf(j.commentColumnQuantifiers.Start):-1,start:t?e.indexOf(j.commentColumnQuantifiers.Start)+j.commentColumnQuantifiers.Start.length:-1,end:t?e.indexOf(j.commentColumnQuantifiers.End)-1:-1}}function N(e,t){return new class{constructor(e,t){this.entities=e,this.relationships=t}getEntities(){return this.entities}getRelationships(){return this.relationships}}(e,t)}function R(e,t){let n="";return e&&(n+=""+e),t&&(n+=" @format "+t),n&&(n=n.trim(),n=`${j.commentColumnQuantifiers.Start} ${n} `+j.commentColumnQuantifiers.End),n}},{"./constants":29}]},{},[28]); \ No newline at end of file diff --git a/dist/sql.js b/dist/sql.js index c877bfd..6847492 100644 --- a/dist/sql.js +++ b/dist/sql.js @@ -898,7 +898,7 @@ const sharedUtils_1 = require("./utils/sharedUtils"); const constants_1 = require("./utils/constants"); /** * SQL Tools Plugin for importing diagrams from SQL DDL and exporting to SQL. - * Version: 0.0.4 + * Version: 0.0.5 */ Draw.loadPlugin(function (ui) { // export sql methods @@ -1035,7 +1035,6 @@ Draw.loadPlugin(function (ui) { tableCell.insert(rowCell); tableCell.geometry.height += 26; } - rowCell = rowCell; } ; function parseSql(text, type) { @@ -1229,9 +1228,16 @@ Draw.loadPlugin(function (ui) { },{"./utils/constants":5,"./utils/sharedUtils":6,"@funktechno/little-mermaid-2-the-sql/lib/src/generate-sql-ddl":1,"@funktechno/sqlsimpleparser":3}],5:[function(require,module,exports){ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.pluginVersion = void 0; +exports.validEnumTypes = exports.enumKeyword = exports.formatKeyword = exports.commentColumnQuantifiers = exports.pluginVersion = void 0; // export sql methods -exports.pluginVersion = "0.0.4"; +exports.pluginVersion = "0.0.5"; +exports.commentColumnQuantifiers = { + Start: "/**", + End: "*/", +}; +exports.formatKeyword = "@format"; +exports.enumKeyword = "enum"; +exports.validEnumTypes = ["string", "number", "integer", "boolean"]; },{}],6:[function(require,module,exports){ "use strict"; @@ -1241,7 +1247,12 @@ exports.removeHtml = removeHtml; exports.dbTypeEnds = dbTypeEnds; exports.RemoveNameQuantifiers = RemoveNameQuantifiers; exports.getDbLabel = getDbLabel; +exports.entityName = entityName; +exports.getCommentIndexes = getCommentIndexes; exports.getMermaidDiagramDb = getMermaidDiagramDb; +exports.GenerateDatabaseModel = GenerateDatabaseModel; +exports.generateComment = generateComment; +const constants_1 = require("./constants"); /** * return text quantifiers for dialect * @returns json @@ -1307,6 +1318,34 @@ function getDbLabel(label, columnQuantifiers) { }; return attribute; } +function entityName(description, format) { + let result = ""; + if (description) { + result += `${description}`; + } + if (format) { + result += ` @format ${format}`; + } + if (result) { + result = result.trim(); + result = `/** ${result} */`; + } + return result; +} +function getCommentIndexes(result) { + let hasComment = false; + if (result.indexOf(constants_1.commentColumnQuantifiers.Start) !== -1 && result.indexOf(constants_1.commentColumnQuantifiers.End) !== -1) { + hasComment = true; + } + const beforeIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) : -1; + const firstSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.Start) + constants_1.commentColumnQuantifiers.Start.length : -1; + const lastSpaceIndex = hasComment ? result.indexOf(constants_1.commentColumnQuantifiers.End) - 1 : -1; + return { + beforeStart: beforeIndex, + start: firstSpaceIndex, + end: lastSpaceIndex + }; +} /** * generate db from drawio graph models * @param ui @@ -1319,16 +1358,43 @@ function getMermaidDiagramDb(ui, type) { // only difference is entities is an array rather than object to allow duplicate tables const entities = {}; const relationships = []; + // TODO: support for ts and openapi enum // build models for (const key in model.cells) { if (Object.hasOwnProperty.call(model.cells, key)) { const mxcell = model.cells[key]; if (mxcell.mxObjectId.indexOf("mxCell") !== -1) { if (mxcell.style && mxcell.style.trim().startsWith("swimlane;")) { + let entityName = mxcell.value.toString(); + let description = ""; + let formatValue = ""; + if ((entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.Start)) && + (entityName === null || entityName === void 0 ? void 0 : entityName.includes(constants_1.commentColumnQuantifiers.End))) { + let result = entityName.toString(); + const commentIndexes = getCommentIndexes(result); + const firstSpaceIndex = commentIndexes.start; + const lastSpaceIndex = commentIndexes.end; + entityName = result.substring(0, commentIndexes.beforeStart); + result = result.substring(firstSpaceIndex, lastSpaceIndex); + if (result.indexOf(constants_1.formatKeyword) !== -1) { + const formatIndex = result.indexOf(constants_1.formatKeyword); + formatValue = result.substring(formatIndex + constants_1.formatKeyword.length).trim(); + result = result.substring(0, formatIndex); + } + if (result) { + description = result; + } + // decription = attribute.attributeType?.replace("/**", "").replace("*/", ""); + } const entity = { - name: RemoveNameQuantifiers(mxcell.value), + name: RemoveNameQuantifiers(entityName), attributes: [], }; + const comment = generateComment(description, formatValue); + if (comment) { + entity.name += comment; + } + // const comment = for (let c = 0; c < mxcell.children.length; c++) { const col = mxcell.children[c]; if (col.mxObjectId.indexOf("mxCell") !== -1) { @@ -1482,6 +1548,10 @@ function getMermaidDiagramDb(ui, type) { } } } + const db = GenerateDatabaseModel(entities, relationships); + return db; +} +function GenerateDatabaseModel(entities, relationships) { class DatabaseModel { constructor(entities, relationships) { this.entities = entities; @@ -1497,5 +1567,19 @@ function getMermaidDiagramDb(ui, type) { const db = new DatabaseModel(entities, relationships); return db; } +function generateComment(description, formatValue) { + let result = ""; + if (description) { + result += `${description}`; + } + if (formatValue) { + result += ` @format ${formatValue}`; + } + if (result) { + result = result.trim(); + result = `${constants_1.commentColumnQuantifiers.Start} ${result} ${constants_1.commentColumnQuantifiers.End}`; + } + return result; +} -},{}]},{},[4]); +},{"./constants":5}]},{},[4]); diff --git a/package.json b/package.json index 5f96a09..c7def0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sqltooling-drawio", - "version": "0.0.4", + "version": "0.0.5", "description": "plugins for sql tooling in drawio", "main": "index.js", "engines": {