@api-client/core 0.12.2 → 0.12.3

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.
@@ -126,9 +126,9 @@ export class EntityValidation {
126
126
  return results;
127
127
  }
128
128
  const name = entity.info.name;
129
- if (name.length < 3) {
129
+ if (name.length < 2) {
130
130
  const message = `The "${label}" entity name is too short.`;
131
- const help = `The name must be at least 3 characters long.`;
131
+ const help = `The name must be at least 2 characters long.`;
132
132
  results.push({
133
133
  field: 'name',
134
134
  rule: 'length',
@@ -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;;;;OAIG;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;YACxD,OAAO,CAAC,IAAI,CAAC;gBACX,KAAK,EAAE,GAAG;gBACV,IAAI,EAAE,QAAQ;gBACd,OAAO;gBACP,IAAI;gBACJ,GAAG,EAAE,MAAgB;gBACrB,IAAI,EAAE,gBAAg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ACb,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,mBAAmB,EAAE,EAAE,CAAC;YACtD,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 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 primary = this.validatePrimaryKey(entity)\n results.push(...primary)\n const minimum = this.minimumRequiredProperties(entity)\n results.push(...minimum)\n const name = this.validateName(entity)\n results.push(...name)\n const uniqueName = this.uniqueName(entity)\n results.push(...uniqueName)\n return results\n }\n\n /**\n * Validates the entity against the primary key validation rules.\n * @param entity The entity to validate\n * @returns The list of validation messages.\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 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 if (!entity.hasProperties() && !entity.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 < 3) {\n const message = `The \"${label}\" entity name is too short.`\n const help = `The name must be at least 3 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.listForeignEntities()) {\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,GAAN,MAAM,CAAY;IAAG,CAAC;IAE5C;;;;OAIG;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,QA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,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,mBAAmB,EAAE,EAAE,CAAC;YACtD,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 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 primary = this.validatePrimaryKey(entity)\n results.push(...primary)\n const minimum = this.minimumRequiredProperties(entity)\n results.push(...minimum)\n const name = this.validateName(entity)\n results.push(...name)\n const uniqueName = this.uniqueName(entity)\n results.push(...uniqueName)\n return results\n }\n\n /**\n * Validates the entity against the primary key validation rules.\n * @param entity The entity to validate\n * @returns The list of validation messages.\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 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 if (!entity.hasProperties() && !entity.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.listForeignEntities()) {\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"]}
@@ -35,9 +35,9 @@ export function validatePropertyName(property) {
35
35
  return results;
36
36
  }
37
37
  const name = property.info.name;
38
- if (name.length < 3) {
38
+ if (name.length < 2) {
39
39
  const message = `The "${label}" ${type} name is too short.`;
40
- const help = `The name must be at least 3 characters long.`;
40
+ const help = `The name must be at least 2 characters long.`;
41
41
  results.push({
42
42
  field: 'name',
43
43
  rule: 'length',
@@ -1 +1 @@
1
- {"version":3,"file":"rules.js","sourceRoot":"","sources":["../../../../src/modeling/validation/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAKlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAw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C,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 '../DomainImpactAnalysis.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 * - `blocking` -> unused (deprecated)\n * - `relationship` -> unused\n */\nexport interface DomainValidation\n extends Omit<DomainImpactItem, 'type' | 'impact' | 'blocking' | '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 < 3) {\n const message = `The \"${label}\" ${type} name is too short.`\n const help = `The name must be at least 3 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,CAAA;AAKlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAwC1D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAA4C;IAC/E,MAAM,OAAO,GAAuB,EAAE,CAAA;IACtC,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAA;IACtC,MAAM,YAAY,GAAG,QAAQ,CAAC,iBAAiB,EAAkB,CAAA;IACjE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,KAAK,kBAAkB,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,aAAa,CAAA;IAC9E,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,QAAQ,KAAK,KAAK,IAAI,eAAe,CAAA;QACrD,MAAM,IAAI,GAAG,OAAO,IAAI,oBAAoB,CAAA;QAC5C,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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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,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,OAAO,GAAG,QAAQ,KAAK,KAAK,IAAI,6BAA6B,CAAA;QACnE,MAAM,IAAI,GAAG,uEAAuE,CAAA;QACpF,OAAO,CAAC,IAAI,CAAC;YACX,KAAK,EAAE,MAAM;YACb,IAAI,EAAE,YAAY;YAClB,OAAO;YACP,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 '../DomainImpactAnalysis.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 * - `blocking` -> unused (deprecated)\n * - `relationship` -> unused\n */\nexport interface DomainValidation\n extends Omit<DomainImpactItem, 'type' | 'impact' | 'blocking' | '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"]}
@@ -41728,10 +41728,10 @@
41728
41728
  "@id": "#194"
41729
41729
  },
41730
41730
  {
41731
- "@id": "#200"
41731
+ "@id": "#197"
41732
41732
  },
41733
41733
  {
41734
- "@id": "#197"
41734
+ "@id": "#200"
41735
41735
  },
41736
41736
  {
41737
41737
  "@id": "#203"
@@ -43138,7 +43138,7 @@
43138
43138
  "doc:ExternalDomainElement",
43139
43139
  "doc:DomainElement"
43140
43140
  ],
43141
- "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43141
+ "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43142
43142
  "core:mediaType": "application/yaml",
43143
43143
  "sourcemaps:sources": [
43144
43144
  {
@@ -43159,7 +43159,7 @@
43159
43159
  "doc:ExternalDomainElement",
43160
43160
  "doc:DomainElement"
43161
43161
  ],
43162
- "doc:raw": "code: '5'\ndescription: 'Limited company'\n",
43162
+ "doc:raw": "class: '3'\ndescription: '150 - 300'\nnumberOfFte: 5500\nnumberOfEmployees: 5232\n",
43163
43163
  "core:mediaType": "application/yaml",
43164
43164
  "sourcemaps:sources": [
43165
43165
  {
@@ -44426,12 +44426,12 @@
44426
44426
  {
44427
44427
  "@id": "#199/source-map/lexical/element_0",
44428
44428
  "sourcemaps:element": "amf://id#199",
44429
- "sourcemaps:value": "[(1,0)-(5,0)]"
44429
+ "sourcemaps:value": "[(1,0)-(3,0)]"
44430
44430
  },
44431
44431
  {
44432
44432
  "@id": "#202/source-map/lexical/element_0",
44433
44433
  "sourcemaps:element": "amf://id#202",
44434
- "sourcemaps:value": "[(1,0)-(3,0)]"
44434
+ "sourcemaps:value": "[(1,0)-(5,0)]"
44435
44435
  },
44436
44436
  {
44437
44437
  "@id": "#205/source-map/lexical/element_0",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@api-client/core",
3
3
  "description": "The API Client's core client library. Works in NodeJS and in a ES enabled browser.",
4
- "version": "0.12.2",
4
+ "version": "0.12.3",
5
5
  "license": "Apache-2.0",
6
6
  "exports": {
7
7
  "./browser.js": {
@@ -131,9 +131,9 @@ export class EntityValidation {
131
131
  }
132
132
 
133
133
  const name = entity.info.name
134
- if (name.length < 3) {
134
+ if (name.length < 2) {
135
135
  const message = `The "${label}" entity name is too short.`
136
- const help = `The name must be at least 3 characters long.`
136
+ const help = `The name must be at least 2 characters long.`
137
137
  results.push({
138
138
  field: 'name',
139
139
  rule: 'length',
@@ -78,9 +78,9 @@ export function validatePropertyName(property: DomainProperty | DomainAssociatio
78
78
  return results
79
79
  }
80
80
  const name = property.info.name
81
- if (name.length < 3) {
81
+ if (name.length < 2) {
82
82
  const message = `The "${label}" ${type} name is too short.`
83
- const help = `The name must be at least 3 characters long.`
83
+ const help = `The name must be at least 2 characters long.`
84
84
  results.push({
85
85
  field: 'name',
86
86
  rule: 'length',
@@ -90,6 +90,23 @@ test.group('AssociationValidation', (group) => {
90
90
  assert.equal(results[0].severity, 'error')
91
91
  })
92
92
 
93
+ test('validateName() should return an error when the association name is too short', ({ assert }) => {
94
+ const model = domain.addModel({ key: 'model' })
95
+ const entity1 = model.addEntity({ key: 'entity1', info: { name: 'Entity1' } })
96
+ const entity2 = model.addEntity({ key: 'entity2', info: { name: 'Entity2' } })
97
+ const association = entity1.addAssociation(
98
+ { key: entity2.key },
99
+ {
100
+ key: 'a',
101
+ info: { name: 'a' },
102
+ }
103
+ )
104
+ const results = validation.validateName(association)
105
+ assert.lengthOf(results, 1)
106
+ assert.equal(results[0].rule, 'length')
107
+ assert.equal(results[0].severity, 'error')
108
+ })
109
+
93
110
  test('validateName() should return an error when the association name is too long', ({ assert }) => {
94
111
  const model = domain.addModel({ key: 'model' })
95
112
  const entity1 = model.addEntity({ key: 'entity1', info: { name: 'Entity1' } })
@@ -90,7 +90,7 @@ test.group('EntityValidation', (group) => {
90
90
 
91
91
  test('validateName() should return an error when the entity name is too short', ({ assert }) => {
92
92
  const model = domain.addModel({ key: 'model' })
93
- const entity = model.addEntity({ key: 'entity', info: { name: 'ab' } })
93
+ const entity = model.addEntity({ key: 'entity', info: { name: 'a' } })
94
94
  const results = validation.validateName(entity)
95
95
  assert.lengthOf(results, 1)
96
96
  assert.equal(results[0].rule, 'length')
@@ -64,6 +64,16 @@ test.group('PropertyValidation', (group) => {
64
64
  assert.equal(results[0].severity, 'error')
65
65
  })
66
66
 
67
+ test('validateName() should return an error when the property name is too short', ({ assert }) => {
68
+ const model = domain.addModel({ key: 'model' })
69
+ const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })
70
+ const property = entity.addProperty({ key: 'a', type: 'string', info: { name: 'a' } })
71
+ const results = validation.validateName(property)
72
+ assert.lengthOf(results, 1)
73
+ assert.equal(results[0].rule, 'length')
74
+ assert.equal(results[0].severity, 'error')
75
+ })
76
+
67
77
  test('validateName() should return an error when the property name is too long', ({ assert }) => {
68
78
  const model = domain.addModel({ key: 'model' })
69
79
  const entity = model.addEntity({ key: 'entity', info: { name: 'Entity' } })