@api-client/core 0.19.11 → 0.19.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/build/src/browser.d.ts +3 -1
  2. package/build/src/browser.d.ts.map +1 -1
  3. package/build/src/browser.js +2 -0
  4. package/build/src/browser.js.map +1 -1
  5. package/build/src/index.d.ts +3 -1
  6. package/build/src/index.d.ts.map +1 -1
  7. package/build/src/index.js +2 -0
  8. package/build/src/index.js.map +1 -1
  9. package/build/src/modeling/ApiValidation.d.ts +26 -0
  10. package/build/src/modeling/ApiValidation.d.ts.map +1 -0
  11. package/build/src/modeling/ApiValidation.js +73 -0
  12. package/build/src/modeling/ApiValidation.js.map +1 -0
  13. package/build/src/modeling/DomainValidation.d.ts +10 -4
  14. package/build/src/modeling/DomainValidation.d.ts.map +1 -1
  15. package/build/src/modeling/DomainValidation.js +55 -72
  16. package/build/src/modeling/DomainValidation.js.map +1 -1
  17. package/build/src/modeling/validation/api_model_rules.d.ts +1 -2
  18. package/build/src/modeling/validation/api_model_rules.d.ts.map +1 -1
  19. package/build/src/modeling/validation/api_model_rules.js +0 -26
  20. package/build/src/modeling/validation/api_model_rules.js.map +1 -1
  21. package/build/src/modeling/validation/association_validation.d.ts +4 -4
  22. package/build/src/modeling/validation/association_validation.d.ts.map +1 -1
  23. package/build/src/modeling/validation/association_validation.js.map +1 -1
  24. package/build/src/modeling/validation/entity_validation.d.ts +6 -6
  25. package/build/src/modeling/validation/entity_validation.d.ts.map +1 -1
  26. package/build/src/modeling/validation/entity_validation.js.map +1 -1
  27. package/build/src/modeling/validation/property_validation.d.ts +3 -3
  28. package/build/src/modeling/validation/property_validation.d.ts.map +1 -1
  29. package/build/src/modeling/validation/property_validation.js.map +1 -1
  30. package/build/src/modeling/validation/rules.d.ts +2 -2
  31. package/build/src/modeling/validation/rules.d.ts.map +1 -1
  32. package/build/src/modeling/validation/rules.js.map +1 -1
  33. package/build/src/modeling/validation/semantic_validation.d.ts +2 -2
  34. package/build/src/modeling/validation/semantic_validation.d.ts.map +1 -1
  35. package/build/src/modeling/validation/semantic_validation.js.map +1 -1
  36. package/build/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +1 -1
  38. package/src/modeling/ApiValidation.ts +86 -0
  39. package/src/modeling/DomainValidation.ts +57 -74
  40. package/src/modeling/validation/api_model_rules.ts +1 -31
  41. package/src/modeling/validation/association_validation.ts +6 -6
  42. package/src/modeling/validation/entity_validation.ts +11 -11
  43. package/src/modeling/validation/property_validation.ts +4 -4
  44. package/src/modeling/validation/rules.ts +6 -3
  45. package/src/modeling/validation/semantic_validation.ts +11 -11
  46. package/tests/unit/modeling/domain_validation.spec.ts +7 -13
  47. package/tests/unit/modeling/validation/api_model_rules.spec.ts +11 -9
@@ -1 +1 @@
1
- {"version":3,"file":"entity_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/entity_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACL;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,MAA6B;QACpC,MAAM,OAAO,GAAuB,EAAE,CAAA;QACtC,IAAI,MAAgC,CAAA;QACpC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,CAAA;QACzC,CAAC;aAAM,CAAC;YACN,MAAM,GAAG,MAAM,CAAA;QACjB,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,OAAO,GAAG,QAAQ,MAAM,0BAA0B,CAAA;YACxD,MAAM,IAAI,GAAG,2CAA2C,CAAA;YAC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MAAM,CAAC,sBAAsB,EAAE,EAAE,CAAC;YACzD,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;gBACxE,MAAM,OAAO,GAAG,QAAQ,IAAI,2DAA2D,CAAA;gBACvF,MAAM,IAAI,GAAG,0EAA0E,CAAA;gBACvF,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,QAAQ;oBACd,OAAO;oBACP,IAAI;oBACJ,QAAQ,EAAE,OAAO;oBACjB,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG;iBACzB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { DomainEntityKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { ReservedKeywords } from './postgresql.js'\nimport type { DomainValidation } from './rules.js'\n\n/**\n * EntityValidation is a class that performs validation on entities in a data domain.\n *\n * @remarks\n * - We do not need to check for parent uniqueness here, because in the graph there can only be one edge\n * between two nodes. Parent relationships are described by an edge in the graph.\n */\nexport class EntityValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the entity.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target entity to validate. Can be a string with\n * the entity key or a DomainEntity object.\n */\n validate(target: string | DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n let entity: DomainEntity | undefined\n if (typeof target === 'string') {\n entity = this.domain.findEntity(target)\n } else {\n entity = target\n }\n if (!entity) {\n const message = `The \"${target}\" entity does not exist.`\n const help = `The entity must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainEntityKind,\n severity: 'error',\n })\n return results\n }\n const primaryKey = this.validatePrimaryKey(entity)\n results.push(...primaryKey)\n const minimumProperties = this.minimumRequiredProperties(entity)\n results.push(...minimumProperties)\n const name = this.validateName(entity)\n results.push(...name)\n const unique = this.uniqueName(entity)\n results.push(...unique)\n return results\n }\n\n /**\n * Validates the entity primary key.\n * @param entity The entity to validate\n */\n validatePrimaryKey(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const primary = entity.primaryKey()\n if (!primary) {\n const message = `The \"${entity.info.getLabel()}\" entity has no identifier.`\n const help = `An entity that can exists by itself must have identifier defined.`\n results.push({\n field: 'properties',\n rule: 'primary_key',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if an entity has properties through its entire inheritance chain.\n * This includes direct properties and properties inherited from any level of parent entities.\n * @param entity The entity to check\n * @returns True if the entity has properties either directly or through inheritance\n */\n private hasPropertiesInherited(entity: DomainEntity): boolean {\n // Check direct properties first\n if (entity.hasProperties()) {\n return true\n }\n\n // Check all parents recursively\n for (const parent of entity.listParents()) {\n if (this.hasPropertiesInherited(parent)) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Checks if an entity has associations through its entire inheritance chain.\n * This includes direct associations and associations inherited from any level of parent entities.\n * @param entity The entity to check\n * @returns True if the entity has associations either directly or through inheritance\n */\n private hasAssociationsInherited(entity: DomainEntity): boolean {\n // Check direct associations first\n if (entity.hasAssociations()) {\n return true\n }\n\n // Check all parents recursively\n for (const parent of entity.listParents()) {\n if (this.hasAssociationsInherited(parent)) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Checks if the entity has the minimum required properties.\n * @param entity The entity to validate\n */\n minimumRequiredProperties(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n\n // Check if entity has properties or associations through entire inheritance chain\n const hasProperties = this.hasPropertiesInherited(entity)\n const hasAssociations = this.hasAssociationsInherited(entity)\n\n if (!hasProperties && !hasAssociations) {\n const message = `The \"${entity.info.getLabel()}\" entity has no properties. It will be ignored.`\n const help = `Entities that have no properties are ignored in the data domain. No schema will be generated for it.`\n results.push({\n field: 'properties',\n rule: 'required',\n message,\n help,\n severity: 'warning',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Validates the entity name.\n *\n * @remarks\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Table names must start with a letter (a-z) or underscore (_).\n * - Subsequent characters can be letters, digits (0-9), or underscores (_).\n * - Names are case-insensitive.\n * - The maximum length of a table name is 31 characters\n * - Should be snake case (it's a convention, not an error).\n * - Should not be a reserved word (for example: \"IN\", \"SELECT\", \"FROM\", etc.).\n * @param entity The entity to validate\n */\n validateName(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const label = entity.info.getLabel()\n if (!entity.info.name) {\n const message = `The \"${label}\" entity has no name.`\n const help = `An entity must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n return results\n }\n\n const name = entity.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" entity name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (name.length > 31) {\n const message = `The \"${label}\" entity name is too long.`\n const help = `The name must be at most 31 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" entity name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" entity name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" entity name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if the entity name is unique in the data domain.\n * @param entity The entity to validate\n */\n uniqueName(entity: DomainEntity): DomainValidation[] {\n const results: DomainValidation[] = []\n const name = entity.info.name?.toLowerCase()\n if (!name) {\n return results\n }\n // We need to check the unique names in all entities, including foreign ones.\n for (const other of this.domain.listEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n })\n }\n }\n for (const other of this.domain.listAllForeignEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the foreign data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n parent: other.domain.key,\n })\n }\n }\n return results\n }\n}\n"]}
1
+ {"version":3,"file":"entity_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/entity_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAGxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAGlD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IACL;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,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E,KAAK,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;gBACxE,MAAM,OAAO,GAAG,QAAQ,IAAI,mDAAmD,CAAA;gBAC/E,MAAM,IAAI,GAAG,0EAA0E,CAAA;gBACvF,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,QAAQ;oBACd,OAAO;oBACP,IAAI;oBACJ,QAAQ,EAAE,OAAO;oBACjB,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QACD,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,sBAAsB,EAAE,EAAE,CAAC;YACzD,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,GAAG,KAAK,MAAM,CAAC,GAAG,EAAE,CAAC;gBACxE,MAAM,OAAO,GAAG,QAAQ,IAAI,2DAA2D,CAAA;gBACvF,MAAM,IAAI,GAAG,0EAA0E,CAAA;gBACvF,OAAO,CAAC,IAAI,CAAC;oBACX,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,QAAQ;oBACd,OAAO;oBACP,IAAI;oBACJ,QAAQ,EAAE,OAAO;oBACjB,GAAG,EAAE,KAAK,CAAC,GAAG;oBACd,IAAI,EAAE,KAAK,CAAC,IAAI;oBAChB,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG;iBACzB,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { DomainEntityKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { ReservedKeywords } from './postgresql.js'\nimport type { DomainValidationSchema } from './rules.js'\n\n/**\n * EntityValidation is a class that performs validation on entities in a data domain.\n *\n * @remarks\n * - We do not need to check for parent uniqueness here, because in the graph there can only be one edge\n * between two nodes. Parent relationships are described by an edge in the graph.\n */\nexport class EntityValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the entity.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target entity to validate. Can be a string with\n * the entity key or a DomainEntity object.\n */\n validate(target: string | DomainEntity): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n let entity: DomainEntity | undefined\n if (typeof target === 'string') {\n entity = this.domain.findEntity(target)\n } else {\n entity = target\n }\n if (!entity) {\n const message = `The \"${target}\" entity does not exist.`\n const help = `The entity must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainEntityKind,\n severity: 'error',\n })\n return results\n }\n const primaryKey = this.validatePrimaryKey(entity)\n results.push(...primaryKey)\n const minimumProperties = this.minimumRequiredProperties(entity)\n results.push(...minimumProperties)\n const name = this.validateName(entity)\n results.push(...name)\n const unique = this.uniqueName(entity)\n results.push(...unique)\n return results\n }\n\n /**\n * Validates the entity primary key.\n * @param entity The entity to validate\n */\n validatePrimaryKey(entity: DomainEntity): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n const primary = entity.primaryKey()\n if (!primary) {\n const message = `The \"${entity.info.getLabel()}\" entity has no identifier.`\n const help = `An entity that can exists by itself must have identifier defined.`\n results.push({\n field: 'properties',\n rule: 'primary_key',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if an entity has properties through its entire inheritance chain.\n * This includes direct properties and properties inherited from any level of parent entities.\n * @param entity The entity to check\n * @returns True if the entity has properties either directly or through inheritance\n */\n private hasPropertiesInherited(entity: DomainEntity): boolean {\n // Check direct properties first\n if (entity.hasProperties()) {\n return true\n }\n\n // Check all parents recursively\n for (const parent of entity.listParents()) {\n if (this.hasPropertiesInherited(parent)) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Checks if an entity has associations through its entire inheritance chain.\n * This includes direct associations and associations inherited from any level of parent entities.\n * @param entity The entity to check\n * @returns True if the entity has associations either directly or through inheritance\n */\n private hasAssociationsInherited(entity: DomainEntity): boolean {\n // Check direct associations first\n if (entity.hasAssociations()) {\n return true\n }\n\n // Check all parents recursively\n for (const parent of entity.listParents()) {\n if (this.hasAssociationsInherited(parent)) {\n return true\n }\n }\n\n return false\n }\n\n /**\n * Checks if the entity has the minimum required properties.\n * @param entity The entity to validate\n */\n minimumRequiredProperties(entity: DomainEntity): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n\n // Check if entity has properties or associations through entire inheritance chain\n const hasProperties = this.hasPropertiesInherited(entity)\n const hasAssociations = this.hasAssociationsInherited(entity)\n\n if (!hasProperties && !hasAssociations) {\n const message = `The \"${entity.info.getLabel()}\" entity has no properties. It will be ignored.`\n const help = `Entities that have no properties are ignored in the data domain. No schema will be generated for it.`\n results.push({\n field: 'properties',\n rule: 'required',\n message,\n help,\n severity: 'warning',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Validates the entity name.\n *\n * @remarks\n * - An entity must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Table names must start with a letter (a-z) or underscore (_).\n * - Subsequent characters can be letters, digits (0-9), or underscores (_).\n * - Names are case-insensitive.\n * - The maximum length of a table name is 31 characters\n * - Should be snake case (it's a convention, not an error).\n * - Should not be a reserved word (for example: \"IN\", \"SELECT\", \"FROM\", etc.).\n * @param entity The entity to validate\n */\n validateName(entity: DomainEntity): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n const label = entity.info.getLabel()\n if (!entity.info.name) {\n const message = `The \"${label}\" entity has no name.`\n const help = `An entity must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n return results\n }\n\n const name = entity.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" entity name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (name.length > 31) {\n const message = `The \"${label}\" entity name is too long.`\n const help = `The name must be at most 31 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" entity name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" entity name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" entity name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: entity.key,\n kind: entity.kind,\n })\n }\n return results\n }\n\n /**\n * Checks if the entity name is unique in the data domain.\n * @param entity The entity to validate\n */\n uniqueName(entity: DomainEntity): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n const name = entity.info.name?.toLowerCase()\n if (!name) {\n return results\n }\n // We need to check the unique names in all entities, including foreign ones.\n for (const other of this.domain.listEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n })\n }\n }\n for (const other of this.domain.listAllForeignEntities()) {\n if (other.info.name?.toLowerCase() === name && other.key !== entity.key) {\n const message = `The \"${name}\" entity name is already used in the foreign data domain.`\n const help = `The name must be unique. This includes references to other data domains.`\n results.push({\n field: 'name',\n rule: 'unique',\n message,\n help,\n severity: 'error',\n key: other.key,\n kind: other.kind,\n parent: other.domain.key,\n })\n }\n }\n return results\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import type { DataDomain } from '../DataDomain.js';
2
2
  import type { DomainProperty } from '../DomainProperty.js';
3
- import { type DomainValidation } from './rules.js';
3
+ import { type DomainValidationSchema } from './rules.js';
4
4
  export declare class PropertyValidation {
5
5
  protected domain: DataDomain;
6
6
  constructor(domain: DataDomain);
@@ -10,7 +10,7 @@ export declare class PropertyValidation {
10
10
  * @param target The target property to validate. Can be a string with
11
11
  * the property key or a DomainProperty object.
12
12
  */
13
- validate(target: string | DomainProperty): DomainValidation[];
13
+ validate(target: string | DomainProperty): DomainValidationSchema[];
14
14
  /**
15
15
  * Validates the property name.
16
16
  *
@@ -24,6 +24,6 @@ export declare class PropertyValidation {
24
24
  * - (recommendation) Column names should be in lower case.
25
25
  * @param property The property to validate
26
26
  */
27
- validateName(property: DomainProperty): DomainValidation[];
27
+ validateName(property: DomainProperty): DomainValidationSchema[];
28
28
  }
29
29
  //# sourceMappingURL=property_validation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"property_validation.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,YAAY,CAAA;AAExE,qBAAa,kBAAkB;IACjB,SAAS,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,gBAAgB,EAAE;IA2B7D;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,gBAAgB,EAAE;CAG3D"}
1
+ {"version":3,"file":"property_validation.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,EAAE,KAAK,sBAAsB,EAAwB,MAAM,YAAY,CAAA;AAE9E,qBAAa,kBAAkB;IACjB,SAAS,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAExC;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,sBAAsB,EAAE;IA2BnE;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAQ,EAAE,cAAc,GAAG,sBAAsB,EAAE;CAGjE"}
@@ -1 +1 @@
1
- {"version":3,"file":"property_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,OAAO,EAAyB,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAExE,MAAM,OAAO,kBAAkB;IACP;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,MAA+B;QACtC,MAAM,OAAO,GAAuB,EAAE,CAAA;QACtC,IAAI,QAAoC,CAAA;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAC7C,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,MAAM,CAAA;QACnB,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,QAAQ,MAAM,4BAA4B,CAAA;YAC1D,MAAM,IAAI,GAAG,6CAA6C,CAAA;YAC1D,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO;gBACP,IAAI;gBACJ,GAAG,EAAE,MAAgB;gBACrB,IAAI,EAAE,kBAAkB;gBACxB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACrB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAwB;QACnC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACvC,CAAC;CACF","sourcesContent":["import { DomainPropertyKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport { type DomainValidation, validatePropertyName } from './rules.js'\n\nexport class PropertyValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the property.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target property to validate. Can be a string with\n * the property key or a DomainProperty object.\n */\n validate(target: string | DomainProperty): DomainValidation[] {\n const results: DomainValidation[] = []\n let property: DomainProperty | undefined\n if (typeof target === 'string') {\n property = this.domain.findProperty(target)\n } else {\n property = target\n }\n if (!property) {\n const message = `The \"${target}\" property does not exist.`\n const help = `The property must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainPropertyKind,\n severity: 'error',\n })\n return results\n }\n const name = this.validateName(property)\n results.push(...name)\n return results\n }\n\n /**\n * Validates the property name.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n * @param property The property to validate\n */\n validateName(property: DomainProperty): DomainValidation[] {\n return validatePropertyName(property)\n }\n}\n"]}
1
+ {"version":3,"file":"property_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/property_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAG1D,OAAO,EAA+B,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAE9E,MAAM,OAAO,kBAAkB;IACP;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,MAA+B;QACtC,MAAM,OAAO,GAA6B,EAAE,CAAA;QAC5C,IAAI,QAAoC,CAAA;QACxC,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YAC/B,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;QAC7C,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,MAAM,CAAA;QACnB,CAAC;QACD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,OAAO,GAAG,QAAQ,MAAM,4BAA4B,CAAA;YAC1D,MAAM,IAAI,GAAG,6CAA6C,CAAA;YAC1D,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO;gBACP,IAAI;gBACJ,GAAG,EAAE,MAAgB;gBACrB,IAAI,EAAE,kBAAkB;gBACxB,QAAQ,EAAE,OAAO;aAClB,CAAC,CAAA;YACF,OAAO,OAAO,CAAA;QAChB,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAA;QACxC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;QACrB,OAAO,OAAO,CAAA;IAChB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,QAAwB;QACnC,OAAO,oBAAoB,CAAC,QAAQ,CAAC,CAAA;IACvC,CAAC;CACF","sourcesContent":["import { DomainPropertyKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport { type DomainValidationSchema, validatePropertyName } from './rules.js'\n\nexport class PropertyValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the validation rules on the property.\n * If you are interested in a specific rule, use the specific method.\n * @param target The target property to validate. Can be a string with\n * the property key or a DomainProperty object.\n */\n validate(target: string | DomainProperty): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n let property: DomainProperty | undefined\n if (typeof target === 'string') {\n property = this.domain.findProperty(target)\n } else {\n property = target\n }\n if (!property) {\n const message = `The \"${target}\" property does not exist.`\n const help = `The property must be defined in the domain.`\n results.push({\n field: '*',\n rule: 'exists',\n message,\n help,\n key: target as string,\n kind: DomainPropertyKind,\n severity: 'error',\n })\n return results\n }\n const name = this.validateName(property)\n results.push(...name)\n return results\n }\n\n /**\n * Validates the property name.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n * @param property The property to validate\n */\n validateName(property: DomainProperty): DomainValidationSchema[] {\n return validatePropertyName(property)\n }\n}\n"]}
@@ -8,7 +8,7 @@ import type { DomainImpactItem } from '../types.js';
8
8
  * - `type` -> unused
9
9
  * - `relationship` -> unused
10
10
  */
11
- export interface DomainValidation extends Omit<DomainImpactItem, 'type' | 'impact' | 'relationship' | 'resolution'> {
11
+ export interface DomainValidationSchema extends Omit<DomainImpactItem, 'type' | 'impact' | 'relationship' | 'resolution'> {
12
12
  /**
13
13
  * The field that did not pass validation.
14
14
  */
@@ -50,5 +50,5 @@ export interface DomainValidation extends Omit<DomainImpactItem, 'type' | 'impac
50
50
  *
51
51
  * @param property The property to validate
52
52
  */
53
- export declare function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidation[];
53
+ export declare function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidationSchema[];
54
54
  //# sourceMappingURL=rules.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAC1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAInD;;;;;;GAMG;AACH,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,YAAY,CAAC;IACjH;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IACb;;;OAGG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,cAAc,GAAG,iBAAiB,GAAG,gBAAgB,EAAE,CA4FrG"}
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"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;YAChB,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,OAAO;YACjB,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,YAAY,CAAC,GAAG;SACzB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { ReservedKeywords } from './postgresql.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport type { DomainAssociation } from '../DomainAssociation.js'\nimport type { DomainImpactItem } from '../types.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { DomainPropertyKind } from '../../models/kinds.js'\n\n/**\n * `DomainImpactItem` mapping:\n * - `impact` -> `message`\n * - `resolution` -> `help`\n * - `type` -> unused\n * - `relationship` -> unused\n */\nexport interface DomainValidation extends Omit<DomainImpactItem, 'type' | 'impact' | 'relationship' | 'resolution'> {\n /**\n * The field that did not pass validation.\n */\n field: string\n /**\n * The name of the rule that was violated.\n */\n rule: string\n /**\n * Optional help message that can be used to provide\n * more information about the error.\n */\n help?: string\n /**\n * Optional URL that can be used to provide more information\n * about the error.\n */\n url?: string\n /**\n * The validation error message.\n * This message should be user-friendly and should not\n * contain any technical details.\n * It should be used to display the error to the user.\n * It should be short and concise.\n */\n message: string\n}\n\n/**\n * Validates the property name. This includes associations.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n *\n * @param property The property to validate\n */\nexport function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidation[] {\n const results: DomainValidation[] = []\n const label = property.info.getLabel()\n const parentEntity = property.getParentInstance() as DomainEntity\n const type = property.kind === DomainPropertyKind ? 'property' : 'association'\n if (!property.info.name) {\n const message = `The \"${label}\" ${type} has no name.`\n const help = `The ${type} must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n return results\n }\n const name = property.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" ${type} name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (name.length > 59) {\n const message = `The \"${label}\" ${type} name is too long.`\n const help = `The name must be at most 59 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" ${type} name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" ${type} name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" ${type} name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n return results\n}\n"]}
1
+ {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAA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,IAAI;YACJ,QAAQ,EAAE,MAAM;YAChB,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,YAAY,CAAC,GAAG;SACzB,CAAC,CAAA;IACJ,CAAC;IACD,IAAI,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,CAAC;QAC7C,MAAM,OAAO,GAAG,QAAQ,KAAK,KAAK,IAAI,8BAA8B,CAAA;QACpE,MAAM,IAAI,GAAG,4CAA4C,CAAA;QACzD,OAAO,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,UAAU;YAChB,OAAO;YACP,IAAI;YACJ,QAAQ,EAAE,OAAO;YACjB,GAAG,EAAE,QAAQ,CAAC,GAAG;YACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,MAAM,EAAE,YAAY,CAAC,GAAG;SACzB,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["import { ReservedKeywords } from './postgresql.js'\nimport type { DomainProperty } from '../DomainProperty.js'\nimport type { DomainAssociation } from '../DomainAssociation.js'\nimport type { DomainImpactItem } from '../types.js'\nimport type { DomainEntity } from '../DomainEntity.js'\nimport { DomainPropertyKind } from '../../models/kinds.js'\n\n/**\n * `DomainImpactItem` mapping:\n * - `impact` -> `message`\n * - `resolution` -> `help`\n * - `type` -> unused\n * - `relationship` -> unused\n */\nexport interface DomainValidationSchema extends Omit<\n DomainImpactItem,\n 'type' | 'impact' | 'relationship' | 'resolution'\n> {\n /**\n * The field that did not pass validation.\n */\n field: string\n /**\n * The name of the rule that was violated.\n */\n rule: string\n /**\n * Optional help message that can be used to provide\n * more information about the error.\n */\n help?: string\n /**\n * Optional URL that can be used to provide more information\n * about the error.\n */\n url?: string\n /**\n * The validation error message.\n * This message should be user-friendly and should not\n * contain any technical details.\n * It should be used to display the error to the user.\n * It should be short and concise.\n */\n message: string\n}\n\n/**\n * Validates the property name. This includes associations.\n *\n * @remarks\n * - A property must have a name defined.\n * - The name has to follow the same rules as the names in a PostgreSQL database.\n * - Column names can only contain letters (a-z, A-Z), numbers (0-9), and underscores (_).\n * - The name must start with a letter (a-z, A-Z) or an underscore (_).\n * - PostgreSQL limits column names to a maximum of 59 characters.\n * - (our rule) Column names are case insensitive.\n * - (recommendation) Column names should be in lower case.\n *\n * @param property The property to validate\n */\nexport function validatePropertyName(property: DomainProperty | DomainAssociation): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n const label = property.info.getLabel()\n const parentEntity = property.getParentInstance() as DomainEntity\n const type = property.kind === DomainPropertyKind ? 'property' : 'association'\n if (!property.info.name) {\n const message = `The \"${label}\" ${type} has no name.`\n const help = `The ${type} must have a name.`\n results.push({\n field: 'name',\n rule: 'required',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n return results\n }\n const name = property.info.name\n if (name.length < 2) {\n const message = `The \"${label}\" ${type} name is too short.`\n const help = `The name must be at least 2 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (name.length > 59) {\n const message = `The \"${label}\" ${type} name is too long.`\n const help = `The name must be at most 59 characters long.`\n results.push({\n field: 'name',\n rule: 'length',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n const message = `The \"${label}\" ${type} name is invalid.`\n const help = `The name must start with a letter (a-z) or underscore (_). Subsequent characters can be letters, digits (0-9), or underscores (_).`\n results.push({\n field: 'name',\n rule: 'format',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (/^[A-Z]/.test(name)) {\n const message = `The \"${label}\" ${type} name is not in snake case.`\n const help = `The name should be in snake case (lowercase letters and underscores).`\n results.push({\n field: 'name',\n rule: 'snake_case',\n message,\n help,\n severity: 'info',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n if (ReservedKeywords.has(name.toUpperCase())) {\n const message = `The \"${label}\" ${type} name is a reserved keyword.`\n const help = `The name should not be a reserved keyword.`\n results.push({\n field: 'name',\n rule: 'reserved',\n message,\n help,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: parentEntity.key,\n })\n }\n return results\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { DataDomain } from '../DataDomain.js';
2
- import type { DomainValidation } from './rules.js';
2
+ import type { DomainValidationSchema } from './rules.js';
3
3
  /**
4
4
  * SemanticValidation is a class that performs validation on semantics in a data domain.
5
5
  * It checks for required and recommended semantics in entities, properties, and associations.
@@ -11,7 +11,7 @@ export declare class SemanticValidation {
11
11
  * Performs all the semantic validation rules on the domain.
12
12
  * @returns The list of validation messages.
13
13
  */
14
- validate(): DomainValidation[];
14
+ validate(): DomainValidationSchema[];
15
15
  /**
16
16
  * Validates if there is at least one entity with the User semantic.
17
17
  * This is a recommended semantic for authentication purposes.
@@ -1 +1 @@
1
- {"version":3,"file":"semantic_validation.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/semantic_validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAElD;;;GAGG;AACH,qBAAa,kBAAkB;IACjB,SAAS,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAExC;;;OAGG;IACH,QAAQ,IAAI,gBAAgB,EAAE;IAsB9B;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IA4ClC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IA6BnC;;OAEG;IACH,OAAO,CAAC,kCAAkC;CA0B3C"}
1
+ {"version":3,"file":"semantic_validation.d.ts","sourceRoot":"","sources":["../../../../src/modeling/validation/semantic_validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAExD;;;GAGG;AACH,qBAAa,kBAAkB;IACjB,SAAS,CAAC,MAAM,EAAE,UAAU;gBAAlB,MAAM,EAAE,UAAU;IAExC;;;OAGG;IACH,QAAQ,IAAI,sBAAsB,EAAE;IAsBpC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IA0B1B;;;OAGG;IACH,OAAO,CAAC,0BAA0B;IA4ClC;;;OAGG;IACH,OAAO,CAAC,2BAA2B;IA6BnC;;OAEG;IACH,OAAO,CAAC,kCAAkC;CA0B3C"}
@@ -1 +1 @@
1
- {"version":3,"file":"semantic_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/semantic_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGjF;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACP;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;OAGG;IACH,QAAQ;QACN,MAAM,OAAO,GAAuB,EAAE,CAAA;QAEtC,iCAAiC;QACjC,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAA;QAC/C,OAAO,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC,CAAA;QAE9B,gCAAgC;QAChC,MAAM,kBAAkB,GAAG,IAAI,CAAC,0BAA0B,EAAE,CAAA;QAC5D,OAAO,CAAC,IAAI,CAAC,GAAG,kBAAkB,CAAC,CAAA;QAEnC,kCAAkC;QAClC,M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AC,IAAI,CAAC,QAAQ,EAAE,uBAAuB,kBAAkB,CAAC,WAAW,qCAAqC,QAAQ,CAAC,IAAI,sBAAsB;gCACtK,IAAI,EAAE,QAAQ,kBAAkB,CAAC,WAAW,4DAA4D,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gCAC5J,QAAQ,EAAE,OAAO;gCACjB,GAAG,EAAE,QAAQ,CAAC,GAAG;gCACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;gCACnB,MAAM,EAAE,MAAM,CAAC,GAAG;6BACnB,CAAC,CAAA;wBACJ,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { DomainEntityKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport { DataSemantics, isPropertySemantic, SemanticType } from '../Semantics.js'\nimport type { DomainValidation } from './rules.js'\n\n/**\n * SemanticValidation is a class that performs validation on semantics in a data domain.\n * It checks for required and recommended semantics in entities, properties, and associations.\n */\nexport class SemanticValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the semantic validation rules on the domain.\n * @returns The list of validation messages.\n */\n validate(): DomainValidation[] {\n const results: DomainValidation[] = []\n\n // Check for User entity semantic\n const hasUserEntity = this.validateUserEntity()\n results.push(...hasUserEntity)\n\n // Check for timestamp semantics\n const timestampSemantics = this.validateTimestampSemantics()\n results.push(...timestampSemantics)\n\n // Check for soft delete semantics\n const softDeleteSemantics = this.validateSoftDeleteSemantics()\n results.push(...softDeleteSemantics)\n\n // Validate property semantics data types\n const propertySemanticsDataTypes = this.validatePropertySemanticsDataTypes()\n results.push(...propertySemanticsDataTypes)\n\n return results\n }\n\n /**\n * Validates if there is at least one entity with the User semantic.\n * This is a recommended semantic for authentication purposes.\n */\n private validateUserEntity(): DomainValidation[] {\n const results: DomainValidation[] = []\n let hasUserEntity = false\n\n for (const entity of this.domain.listEntities()) {\n if (entity.hasSemantic(SemanticType.User)) {\n hasUserEntity = true\n break\n }\n }\n\n if (!hasUserEntity) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: 'No entity with User taxonomy found in the domain.',\n help: 'It is recommended to have at least one entity with the User taxonomy for authentication purposes.',\n severity: 'warning',\n key: 'user_semantic',\n kind: DomainEntityKind,\n })\n }\n\n return results\n }\n\n /**\n * Validates if entities have the recommended timestamp semantics.\n * This includes CreatedTimestamp and UpdatedTimestamp.\n */\n private validateTimestampSemantics(): DomainValidation[] {\n const results: DomainValidation[] = []\n\n for (const entity of this.domain.listEntities()) {\n let hasCreatedTimestamp = false\n let hasUpdatedTimestamp = false\n\n for (const property of entity.listProperties()) {\n if (property.hasSemantic(SemanticType.CreatedTimestamp)) {\n hasCreatedTimestamp = true\n }\n if (property.hasSemantic(SemanticType.UpdatedTimestamp)) {\n hasUpdatedTimestamp = true\n }\n }\n\n if (!hasCreatedTimestamp) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have a CreatedTimestamp taxonomy.`,\n help: 'It is recommended to have a CreatedTimestamp property to track when the entity was created.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n\n if (!hasUpdatedTimestamp) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have an UpdatedTimestamp taxonomy.`,\n help: 'It is recommended to have an UpdatedTimestamp property to track when the entity was last modified.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n }\n\n return results\n }\n\n /**\n * Validates if entities have the recommended soft delete semantics.\n * This includes either DeletedTimestamp or DeletedFlag.\n */\n private validateSoftDeleteSemantics(): DomainValidation[] {\n const results: DomainValidation[] = []\n\n for (const entity of this.domain.listEntities()) {\n let hasSoftDelete = false\n\n for (const property of entity.listProperties()) {\n if (property.hasSemantic(SemanticType.DeletedTimestamp) || property.hasSemantic(SemanticType.DeletedFlag)) {\n hasSoftDelete = true\n break\n }\n }\n\n if (!hasSoftDelete) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have soft delete taxonomy.`,\n help: 'It is recommended to have either a DeletedTimestamp or DeletedFlag property for soft deletion.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n }\n\n return results\n }\n\n /**\n * Validates if property semantics are applied to properties with compatible data types.\n */\n private validatePropertySemanticsDataTypes(): DomainValidation[] {\n const results: DomainValidation[] = []\n\n for (const entity of this.domain.listEntities()) {\n for (const property of entity.listProperties()) {\n for (const appliedSemantic of property.semantics) {\n const semanticDefinition = DataSemantics[appliedSemantic.id]\n if (isPropertySemantic(semanticDefinition) && semanticDefinition.applicableDataTypes) {\n if (!semanticDefinition.applicableDataTypes.includes(property.type)) {\n results.push({\n field: 'semantics',\n rule: 'type_mismatch',\n message: `The \"${property.info.getLabel()}\" property has the \"${semanticDefinition.displayName}\" semantic applied, but its type \"${property.type}\" is not compatible.`,\n help: `The \"${semanticDefinition.displayName}\" semantic can only be applied to properties of type(s): ${semanticDefinition.applicableDataTypes.join(', ')}.`,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: entity.key,\n })\n }\n }\n }\n }\n }\n return results\n }\n}\n"]}
1
+ {"version":3,"file":"semantic_validation.js","sourceRoot":"","sources":["../../../../src/modeling/validation/semantic_validation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAExD,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AAGjF;;;GAGG;AACH,MAAM,OAAO,kBAAkB;IACP;IAAtB,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;OAGG;IACH,QAAQ;QACN,MAAM,OAAO,GAA6B,EAAE,CAAA;QAE5C,iCAAiC;QACjC,MAAM,aAAa,GAAG,IAAI,CA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mBAAmB,EAAE,CAAC;wBACrF,IAAI,CAAC,kBAAkB,CAAC,mBAAmB,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;4BACpE,OAAO,CAAC,IAAI,CAAC;gCACX,KAAK,EAAE,WAAW;gCAClB,IAAI,EAAE,eAAe;gCACrB,OAAO,EAAE,QAAQ,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,uBAAuB,kBAAkB,CAAC,WAAW,qCAAqC,QAAQ,CAAC,IAAI,sBAAsB;gCACtK,IAAI,EAAE,QAAQ,kBAAkB,CAAC,WAAW,4DAA4D,kBAAkB,CAAC,mBAAmB,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;gCAC5J,QAAQ,EAAE,OAAO;gCACjB,GAAG,EAAE,QAAQ,CAAC,GAAG;gCACjB,IAAI,EAAE,QAAQ,CAAC,IAAI;gCACnB,MAAM,EAAE,MAAM,CAAC,GAAG;6BACnB,CAAC,CAAA;wBACJ,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;CACF","sourcesContent":["import { DomainEntityKind } from '../../models/kinds.js'\nimport type { DataDomain } from '../DataDomain.js'\nimport { DataSemantics, isPropertySemantic, SemanticType } from '../Semantics.js'\nimport type { DomainValidationSchema } from './rules.js'\n\n/**\n * SemanticValidation is a class that performs validation on semantics in a data domain.\n * It checks for required and recommended semantics in entities, properties, and associations.\n */\nexport class SemanticValidation {\n constructor(protected domain: DataDomain) {}\n\n /**\n * Performs all the semantic validation rules on the domain.\n * @returns The list of validation messages.\n */\n validate(): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n\n // Check for User entity semantic\n const hasUserEntity = this.validateUserEntity()\n results.push(...hasUserEntity)\n\n // Check for timestamp semantics\n const timestampSemantics = this.validateTimestampSemantics()\n results.push(...timestampSemantics)\n\n // Check for soft delete semantics\n const softDeleteSemantics = this.validateSoftDeleteSemantics()\n results.push(...softDeleteSemantics)\n\n // Validate property semantics data types\n const propertySemanticsDataTypes = this.validatePropertySemanticsDataTypes()\n results.push(...propertySemanticsDataTypes)\n\n return results\n }\n\n /**\n * Validates if there is at least one entity with the User semantic.\n * This is a recommended semantic for authentication purposes.\n */\n private validateUserEntity(): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n let hasUserEntity = false\n\n for (const entity of this.domain.listEntities()) {\n if (entity.hasSemantic(SemanticType.User)) {\n hasUserEntity = true\n break\n }\n }\n\n if (!hasUserEntity) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: 'No entity with User taxonomy found in the domain.',\n help: 'It is recommended to have at least one entity with the User taxonomy for authentication purposes.',\n severity: 'warning',\n key: 'user_semantic',\n kind: DomainEntityKind,\n })\n }\n\n return results\n }\n\n /**\n * Validates if entities have the recommended timestamp semantics.\n * This includes CreatedTimestamp and UpdatedTimestamp.\n */\n private validateTimestampSemantics(): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n\n for (const entity of this.domain.listEntities()) {\n let hasCreatedTimestamp = false\n let hasUpdatedTimestamp = false\n\n for (const property of entity.listProperties()) {\n if (property.hasSemantic(SemanticType.CreatedTimestamp)) {\n hasCreatedTimestamp = true\n }\n if (property.hasSemantic(SemanticType.UpdatedTimestamp)) {\n hasUpdatedTimestamp = true\n }\n }\n\n if (!hasCreatedTimestamp) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have a CreatedTimestamp taxonomy.`,\n help: 'It is recommended to have a CreatedTimestamp property to track when the entity was created.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n\n if (!hasUpdatedTimestamp) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have an UpdatedTimestamp taxonomy.`,\n help: 'It is recommended to have an UpdatedTimestamp property to track when the entity was last modified.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n }\n\n return results\n }\n\n /**\n * Validates if entities have the recommended soft delete semantics.\n * This includes either DeletedTimestamp or DeletedFlag.\n */\n private validateSoftDeleteSemantics(): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n\n for (const entity of this.domain.listEntities()) {\n let hasSoftDelete = false\n\n for (const property of entity.listProperties()) {\n if (property.hasSemantic(SemanticType.DeletedTimestamp) || property.hasSemantic(SemanticType.DeletedFlag)) {\n hasSoftDelete = true\n break\n }\n }\n\n if (!hasSoftDelete) {\n results.push({\n field: 'semantics',\n rule: 'recommended',\n message: `The \"${entity.info.getLabel()}\" entity does not have soft delete taxonomy.`,\n help: 'It is recommended to have either a DeletedTimestamp or DeletedFlag property for soft deletion.',\n severity: 'info',\n key: entity.key,\n kind: entity.kind,\n })\n }\n }\n\n return results\n }\n\n /**\n * Validates if property semantics are applied to properties with compatible data types.\n */\n private validatePropertySemanticsDataTypes(): DomainValidationSchema[] {\n const results: DomainValidationSchema[] = []\n\n for (const entity of this.domain.listEntities()) {\n for (const property of entity.listProperties()) {\n for (const appliedSemantic of property.semantics) {\n const semanticDefinition = DataSemantics[appliedSemantic.id]\n if (isPropertySemantic(semanticDefinition) && semanticDefinition.applicableDataTypes) {\n if (!semanticDefinition.applicableDataTypes.includes(property.type)) {\n results.push({\n field: 'semantics',\n rule: 'type_mismatch',\n message: `The \"${property.info.getLabel()}\" property has the \"${semanticDefinition.displayName}\" semantic applied, but its type \"${property.type}\" is not compatible.`,\n help: `The \"${semanticDefinition.displayName}\" semantic can only be applied to properties of type(s): ${semanticDefinition.applicableDataTypes.join(', ')}.`,\n severity: 'error',\n key: property.key,\n kind: property.kind,\n parent: entity.key,\n })\n }\n }\n }\n }\n }\n return results\n }\n}\n"]}