@entifix/core 0.12.1 → 0.14.0

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 (113) hide show
  1. package/dist/base-entities/configuration-client/configuration-client-singleton.d.ts +12 -13
  2. package/dist/base-entities/configuration-client/configuration-client-singleton.d.ts.map +1 -1
  3. package/dist/base-entities/configuration-client/configuration-client-singleton.js +4 -17
  4. package/dist/base-entities/configuration-client/configuration-client-singleton.js.map +1 -1
  5. package/dist/base-entities/configuration-client/types.d.ts +13 -13
  6. package/dist/base-entities/configuration-client/types.d.ts.map +1 -1
  7. package/dist/base-entities/configuration-client/types.js.map +1 -1
  8. package/dist/command-palette/command-matching.d.ts.map +1 -1
  9. package/dist/command-palette/command-matching.js +1 -5
  10. package/dist/command-palette/command-matching.js.map +1 -1
  11. package/dist/entity-definition/describe/describe-child-columns.d.ts +3 -3
  12. package/dist/entity-definition/describe/describe-child-columns.d.ts.map +1 -1
  13. package/dist/entity-definition/describe/describe-child-columns.js +5 -10
  14. package/dist/entity-definition/describe/describe-child-columns.js.map +1 -1
  15. package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
  16. package/dist/entity-definition/describe/describe-entity-columns.js +6 -7
  17. package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
  18. package/dist/entity-definition/describe/entity-view.d.ts.map +1 -1
  19. package/dist/entity-definition/describe/entity-view.js +2 -3
  20. package/dist/entity-definition/describe/entity-view.js.map +1 -1
  21. package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
  22. package/dist/entity-definition/helpers/entity-definition-helpers.js +4 -5
  23. package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
  24. package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts +1 -1
  25. package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts.map +1 -1
  26. package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js +2 -6
  27. package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js.map +1 -1
  28. package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts +3 -3
  29. package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts.map +1 -1
  30. package/dist/entity-definition/links/entity-collection-link/entity-collection-link.js.map +1 -1
  31. package/dist/entity-definition/links/entity-link/entity-link.d.ts +4 -4
  32. package/dist/entity-definition/links/entity-link/entity-link.d.ts.map +1 -1
  33. package/dist/entity-definition/links/entity-link/entity-link.js.map +1 -1
  34. package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts +3 -3
  35. package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts.map +1 -1
  36. package/dist/entity-definition/links/entity-link-source/entity-link-source.js.map +1 -1
  37. package/dist/entity-definition/links/link-targets/link-targets.d.ts.map +1 -1
  38. package/dist/entity-definition/links/link-targets/link-targets.js +2 -3
  39. package/dist/entity-definition/links/link-targets/link-targets.js.map +1 -1
  40. package/dist/entity-definition/meta-entities/bounds.d.ts.map +1 -1
  41. package/dist/entity-definition/meta-entities/bounds.js +2 -3
  42. package/dist/entity-definition/meta-entities/bounds.js.map +1 -1
  43. package/dist/entity-definition/serializer/deserialize.d.ts +3 -3
  44. package/dist/entity-definition/serializer/deserialize.d.ts.map +1 -1
  45. package/dist/entity-definition/serializer/deserialize.js +11 -18
  46. package/dist/entity-definition/serializer/deserialize.js.map +1 -1
  47. package/dist/failure/failure.d.ts +0 -7
  48. package/dist/failure/failure.d.ts.map +1 -1
  49. package/dist/failure/failure.js.map +1 -1
  50. package/dist/failure/predicates.d.ts +6 -0
  51. package/dist/failure/predicates.d.ts.map +1 -1
  52. package/dist/failure/predicates.js +5 -0
  53. package/dist/failure/predicates.js.map +1 -1
  54. package/dist/hierarchy/hierarchy.d.ts.map +1 -1
  55. package/dist/hierarchy/hierarchy.js +1 -2
  56. package/dist/hierarchy/hierarchy.js.map +1 -1
  57. package/dist/i18n/locales.d.ts.map +1 -1
  58. package/dist/i18n/locales.js +19 -4
  59. package/dist/i18n/locales.js.map +1 -1
  60. package/dist/index.d.ts +0 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +0 -1
  63. package/dist/index.js.map +1 -1
  64. package/dist/query/in-memory-query.d.ts.map +1 -1
  65. package/dist/query/in-memory-query.js +1 -2
  66. package/dist/query/in-memory-query.js.map +1 -1
  67. package/dist/rsql/coerce-rsql.d.ts +1 -1
  68. package/dist/rsql/coerce-rsql.d.ts.map +1 -1
  69. package/dist/rsql/coerce-rsql.js +2 -3
  70. package/dist/rsql/coerce-rsql.js.map +1 -1
  71. package/dist/rsql/facet-query-url.d.ts +1 -1
  72. package/dist/rsql/facet-query-url.d.ts.map +1 -1
  73. package/dist/rsql/facet-query-url.js +4 -9
  74. package/dist/rsql/facet-query-url.js.map +1 -1
  75. package/dist/rsql/load-request-url.d.ts +1 -1
  76. package/dist/rsql/load-request-url.d.ts.map +1 -1
  77. package/dist/rsql/load-request-url.js +2 -5
  78. package/dist/rsql/load-request-url.js.map +1 -1
  79. package/dist/rsql/parse-rsql.d.ts +1 -1
  80. package/dist/rsql/parse-rsql.d.ts.map +1 -1
  81. package/dist/rsql/parse-rsql.js +2 -5
  82. package/dist/rsql/parse-rsql.js.map +1 -1
  83. package/dist/use-case-runner/entity-writer.d.ts +24 -0
  84. package/dist/use-case-runner/entity-writer.d.ts.map +1 -0
  85. package/dist/use-case-runner/entity-writer.js +12 -0
  86. package/dist/use-case-runner/entity-writer.js.map +1 -0
  87. package/dist/use-case-runner/index.d.ts +2 -0
  88. package/dist/use-case-runner/index.d.ts.map +1 -1
  89. package/dist/use-case-runner/index.js +2 -0
  90. package/dist/use-case-runner/index.js.map +1 -1
  91. package/dist/use-case-runner/use-case-runner.d.ts +9 -4
  92. package/dist/use-case-runner/use-case-runner.d.ts.map +1 -1
  93. package/dist/use-case-runner/use-case-runner.js.map +1 -1
  94. package/dist/use-case-runner/write-result.d.ts +36 -0
  95. package/dist/use-case-runner/write-result.d.ts.map +1 -0
  96. package/dist/use-case-runner/write-result.js +20 -0
  97. package/dist/use-case-runner/write-result.js.map +1 -0
  98. package/dist/wizard/wizard-definition.d.ts.map +1 -1
  99. package/dist/wizard/wizard-definition.js +10 -11
  100. package/dist/wizard/wizard-definition.js.map +1 -1
  101. package/dist/wizard/wizard-navigation.d.ts +1 -1
  102. package/dist/wizard/wizard-navigation.d.ts.map +1 -1
  103. package/dist/wizard/wizard-navigation.js +2 -3
  104. package/dist/wizard/wizard-navigation.js.map +1 -1
  105. package/package.json +3 -3
  106. package/dist/base-entities/entifix-error/entifix-error.d.ts +0 -31
  107. package/dist/base-entities/entifix-error/entifix-error.d.ts.map +0 -1
  108. package/dist/base-entities/entifix-error/entifix-error.js +0 -56
  109. package/dist/base-entities/entifix-error/entifix-error.js.map +0 -1
  110. package/dist/base-entities/entifix-error/index.d.ts +0 -2
  111. package/dist/base-entities/entifix-error/index.d.ts.map +0 -1
  112. package/dist/base-entities/entifix-error/index.js +0 -3
  113. package/dist/base-entities/entifix-error/index.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/entity-definition/serializer/deserialize.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { EntifixBuildError } from '../../base-entities/entifix-error/index.js';\nimport { Entity, EntityConstructor, EntityId } from '../../types/Entity.js';\nimport { extractMetaAccessors } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\n\n/**\n * Result of deserializing a value against an entity constructor. A value can be\n * a single entity, a missing entity (`undefined`) or an arbitrarily nested\n * array of those — which lets collections recurse into arrays of arrays.\n */\ntype DeserializedEntity<TEntity extends Entity> =\n TEntity | undefined | DeserializedEntity<TEntity>[];\n\n//#region Validations\n\nfunction assertEntityObject<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n): asserts entityData is object {\n if (typeof entityData !== 'object') {\n throw new EntifixBuildError(\n `Failed to deserialize entity of type ${\n entityConstructor.name\n }. Expected an object but got ${typeof entityData}`,\n undefined,\n {\n entityData,\n entityConstructor: entityConstructor.name,\n },\n );\n }\n}\n\nfunction assertEntityCollection<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n): asserts entityCollectionData is unknown[] {\n if (!Array.isArray(entityCollectionData)) {\n throw new EntifixBuildError(\n `Failed to deserialize entity collection of type ${\n entityConstructor.name\n }. Expected an array but got ${typeof entityCollectionData}`,\n undefined,\n {\n entityCollectionData,\n entityConstructor: entityConstructor.name,\n },\n );\n }\n}\n\n//#endregion\n\n//#region Recursive deserialization\n\nfunction isEmbeddedData(value: unknown): value is object {\n return value != null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Populates a to-one relation from its raw value. An object is treated as\n * embedded data and deserialized into an instance; any scalar is treated as a\n * foreign key and stored as the link id (resolved lazily via `reload`).\n */\nfunction populateEntityLink<TEntity extends Entity>(\n link: EntityLink<TEntity>,\n rawValue: unknown,\n): void {\n if (rawValue == null) {\n return;\n }\n if (isEmbeddedData(rawValue)) {\n link.setValue(buildEntityInstance(link.entityConstructor, rawValue));\n return;\n }\n link.setId(rawValue as EntityId);\n}\n\n/**\n * Populates a to-many relation from its raw array, mixing embedded objects\n * (deserialized) and scalar foreign keys as they appear.\n */\nfunction populateEntityCollectionLink<TEntity extends Entity>(\n link: EntityCollectionLink<TEntity>,\n rawValue: unknown,\n): void {\n if (!Array.isArray(rawValue)) {\n return;\n }\n const values: TEntity[] = [];\n const ids: EntityId[] = [];\n for (const item of rawValue) {\n if (isEmbeddedData(item)) {\n values.push(buildEntityInstance(link.entityConstructor, item));\n } else if (item != null) {\n ids.push(item as EntityId);\n }\n }\n if (values.length > 0) {\n link.setValues(values);\n } else if (ids.length > 0) {\n link.setIds(ids);\n }\n}\n\nfunction buildEntityInstance<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: object,\n): TEntity {\n const metaAccessors = extractMetaAccessors(entityConstructor);\n\n const newInstance = new entityConstructor();\n metaAccessors\n // Entities decorate their accessors on the getter, so the writable property\n // list comes from getter-kind metadata; read-only/hidden ones are skipped.\n // The value is then assigned through the instance's JS setter.\n .filter(\n metaAccessor =>\n !metaAccessor.hidden &&\n !metaAccessor.readonly &&\n metaAccessor.kind === 'getter',\n )\n .forEach(metaAccessor => {\n const propertyName = metaAccessor.alias ?? metaAccessor.name;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const current = (newInstance as any)[metaAccessor.name];\n\n // Relations are pre-initialized as link instances by the entity\n // constructor. Their accessors are read-only getters, so populate the\n // existing link from the raw value rather than assigning through a setter.\n if (current instanceof EntityLink) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n populateEntityLink(current, (entityData as any)[propertyName]);\n return;\n }\n if (current instanceof EntityCollectionLink) {\n populateEntityCollectionLink(\n current,\n (entityData as any)[propertyName],\n );\n return;\n }\n\n // Owned rows are rebuilt through the child's own accessors, the mirror of\n // what `serializeEntity` wrote. Without this the member would hold plain\n // objects while its declared type says otherwise — and a child whose\n // accessor carries an `alias` would keep the storage column name as its\n // property, which is exactly the mapping layer the serializer exists to\n // remove.\n if (metaAccessor.type === 'composition' && metaAccessor.childType) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rows = (entityData as any)[propertyName];\n if (Array.isArray(rows)) {\n const childType =\n metaAccessor.childType() as EntityConstructor<Entity>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (newInstance as any)[metaAccessor.name] = rows.map(row =>\n buildEntityInstance(childType, row as object),\n );\n }\n return;\n }\n\n if (\n propertyName in entityData &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (entityData as any)[propertyName] !== undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (newInstance as any)[metaAccessor.name] = (entityData as any)[\n propertyName\n ];\n }\n });\n\n return newInstance;\n}\n\nfunction deserializeEntity<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n): TEntity | undefined {\n if (entityData == null) {\n return undefined;\n }\n assertEntityObject(entityConstructor, entityData);\n return buildEntityInstance(entityConstructor, entityData);\n}\n\nfunction deserializeCollection<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n failOnNull: boolean,\n): DeserializedEntity<TEntity>[] {\n if (entityCollectionData == null && !failOnNull) {\n return [];\n }\n assertEntityCollection(entityConstructor, entityCollectionData);\n\n // Recurse into nested arrays so a collection can hold arrays of arrays,\n // and reuse the single-entity validation/build for the leaf items.\n return entityCollectionData.map(item =>\n Array.isArray(item)\n ? deserializeCollection(entityConstructor, item, failOnNull)\n : deserializeEntity(entityConstructor, item),\n );\n}\n\n//#endregion\n\n//#region Effect factories\n\nconst toEntifixBuildError =\n (message: string, context: Record<string, unknown>) => (error: unknown) =>\n error instanceof EntifixBuildError\n ? error\n : new EntifixBuildError(message, error, context);\n\nexport const deserializeSingleEntity = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n) =>\n Effect.try({\n try: () => deserializeEntity(entityConstructor, entityData),\n catch: toEntifixBuildError(\n `Failed to deserialize entity of type ${entityConstructor.name}`,\n {\n entityData,\n entityConstructor: entityConstructor.name,\n },\n ),\n });\n\nexport const deserializeEntityCollection = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n failOnNull = false,\n) =>\n Effect.try({\n try: () =>\n deserializeCollection(\n entityConstructor,\n entityCollectionData,\n failOnNull,\n ),\n catch: toEntifixBuildError(\n `Failed to deserialize entity collection of type ${entityConstructor.name}`,\n {\n entityCollectionData,\n entityConstructor: entityConstructor.name,\n },\n ),\n });\n\n//#endregion\n"],"names":["Effect","EntifixBuildError","extractMetaAccessors","EntityCollectionLink","EntityLink","assertEntityObject","entityConstructor","entityData","name","undefined","assertEntityCollection","entityCollectionData","Array","isArray","isEmbeddedData","value","populateEntityLink","link","rawValue","setValue","buildEntityInstance","setId","populateEntityCollectionLink","values","ids","item","push","length","setValues","setIds","metaAccessors","newInstance","filter","metaAccessor","hidden","readonly","kind","forEach","propertyName","alias","current","type","childType","rows","map","row","deserializeEntity","deserializeCollection","failOnNull","toEntifixBuildError","message","context","error","deserializeSingleEntity","try","catch","deserializeEntityCollection"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,iBAAiB,QAAQ,6CAA6C;AAE/E,SAASC,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,UAAU,QAAQ,gCAAgC;AAU3D,qBAAqB;AAErB,SAASC,mBACPC,iBAA6C,EAC7CC,UAAmB;IAEnB,IAAI,OAAOA,eAAe,UAAU;QAClC,MAAM,IAAIN,kBACR,CAAC,qCAAqC,EACpCK,kBAAkBE,IAAI,CACvB,6BAA6B,EAAE,OAAOD,YAAY,EACnDE,WACA;YACEF;YACAD,mBAAmBA,kBAAkBE,IAAI;QAC3C;IAEJ;AACF;AAEA,SAASE,uBACPJ,iBAA6C,EAC7CK,oBAA6B;IAE7B,IAAI,CAACC,MAAMC,OAAO,CAACF,uBAAuB;QACxC,MAAM,IAAIV,kBACR,CAAC,gDAAgD,EAC/CK,kBAAkBE,IAAI,CACvB,4BAA4B,EAAE,OAAOG,sBAAsB,EAC5DF,WACA;YACEE;YACAL,mBAAmBA,kBAAkBE,IAAI;QAC3C;IAEJ;AACF;AAEA,YAAY;AAEZ,mCAAmC;AAEnC,SAASM,eAAeC,KAAc;IACpC,OAAOA,SAAS,QAAQ,OAAOA,UAAU,YAAY,CAACH,MAAMC,OAAO,CAACE;AACtE;AAEA;;;;CAIC,GACD,SAASC,mBACPC,IAAyB,EACzBC,QAAiB;IAEjB,IAAIA,YAAY,MAAM;QACpB;IACF;IACA,IAAIJ,eAAeI,WAAW;QAC5BD,KAAKE,QAAQ,CAACC,oBAAoBH,KAAKX,iBAAiB,EAAEY;QAC1D;IACF;IACAD,KAA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BAAkBiD,SAASE,OAAOD;AAE9C,OAAO,MAAME,0BAA0B,CACrC/C,mBACAC,aAEAP,OAAOsD,GAAG,CAAC;QACTA,KAAK,IAAMR,kBAAkBxC,mBAAmBC;QAChDgD,OAAON,oBACL,CAAC,qCAAqC,EAAE3C,kBAAkBE,IAAI,EAAE,EAChE;YACED;YACAD,mBAAmBA,kBAAkBE,IAAI;QAC3C;IAEJ,GAAG;AAEL,OAAO,MAAMgD,8BAA8B,CACzClD,mBACAK,sBACAqC,aAAa,KAAK,GAElBhD,OAAOsD,GAAG,CAAC;QACTA,KAAK,IACHP,sBACEzC,mBACAK,sBACAqC;QAEJO,OAAON,oBACL,CAAC,gDAAgD,EAAE3C,kBAAkBE,IAAI,EAAE,EAC3E;YACEG;YACAL,mBAAmBA,kBAAkBE,IAAI;QAC3C;IAEJ,GAAG,CAEL,YAAY"}
1
+ {"version":3,"sources":["../../../src/entity-definition/serializer/deserialize.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport { ProtocolFailure } from '../../failure/generic.js';\nimport { messageOf } from '../../failure/predicates.js';\nimport { Entity, EntityConstructor, EntityId } from '../../types/Entity.js';\nimport { extractMetaAccessors } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\n\n/**\n * Result of deserializing a value against an entity constructor. A value can be\n * a single entity, a missing entity (`undefined`) or an arbitrarily nested\n * array of those — which lets collections recurse into arrays of arrays.\n */\ntype DeserializedEntity<TEntity extends Entity> =\n TEntity | undefined | DeserializedEntity<TEntity>[];\n\n//#region Validations\n\nfunction assertEntityObject<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n): asserts entityData is object {\n if (typeof entityData !== 'object') {\n throw new Error(\n `Failed to deserialize entity of type ${\n entityConstructor.name\n }. Expected an object but got ${typeof entityData}`,\n );\n }\n}\n\nfunction assertEntityCollection<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n): asserts entityCollectionData is unknown[] {\n if (!Array.isArray(entityCollectionData)) {\n throw new Error(\n `Failed to deserialize entity collection of type ${\n entityConstructor.name\n }. Expected an array but got ${typeof entityCollectionData}`,\n );\n }\n}\n\n//#endregion\n\n//#region Recursive deserialization\n\nfunction isEmbeddedData(value: unknown): value is object {\n return value != null && typeof value === 'object' && !Array.isArray(value);\n}\n\n/**\n * Populates a to-one relation from its raw value. An object is treated as\n * embedded data and deserialized into an instance; any scalar is treated as a\n * foreign key and stored as the link id (resolved lazily via `reload`).\n */\nfunction populateEntityLink<TEntity extends Entity>(\n link: EntityLink<TEntity>,\n rawValue: unknown,\n): void {\n if (rawValue == null) {\n return;\n }\n if (isEmbeddedData(rawValue)) {\n link.setValue(buildEntityInstance(link.entityConstructor, rawValue));\n return;\n }\n link.setId(rawValue as EntityId);\n}\n\n/**\n * Populates a to-many relation from its raw array, mixing embedded objects\n * (deserialized) and scalar foreign keys as they appear.\n */\nfunction populateEntityCollectionLink<TEntity extends Entity>(\n link: EntityCollectionLink<TEntity>,\n rawValue: unknown,\n): void {\n if (!Array.isArray(rawValue)) {\n return;\n }\n const values: TEntity[] = [];\n const ids: EntityId[] = [];\n for (const item of rawValue) {\n if (isEmbeddedData(item)) {\n values.push(buildEntityInstance(link.entityConstructor, item));\n } else if (item != null) {\n ids.push(item as EntityId);\n }\n }\n if (values.length > 0) {\n link.setValues(values);\n } else if (ids.length > 0) {\n link.setIds(ids);\n }\n}\n\nfunction buildEntityInstance<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: object,\n): TEntity {\n const metaAccessors = extractMetaAccessors(entityConstructor);\n\n const newInstance = new entityConstructor();\n metaAccessors\n // Entities decorate their accessors on the getter, so the writable property\n // list comes from getter-kind metadata; read-only/hidden ones are skipped.\n // The value is then assigned through the instance's JS setter.\n .filter(\n metaAccessor =>\n !metaAccessor.hidden &&\n !metaAccessor.readonly &&\n metaAccessor.kind === 'getter',\n )\n .forEach(metaAccessor => {\n const propertyName = metaAccessor.alias ?? metaAccessor.name;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const current = (newInstance as any)[metaAccessor.name];\n\n // Relations are pre-initialized as link instances by the entity\n // constructor. Their accessors are read-only getters, so populate the\n // existing link from the raw value rather than assigning through a setter.\n if (current instanceof EntityLink) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n populateEntityLink(current, (entityData as any)[propertyName]);\n return;\n }\n if (current instanceof EntityCollectionLink) {\n populateEntityCollectionLink(\n current,\n (entityData as any)[propertyName],\n );\n return;\n }\n\n // Owned rows are rebuilt through the child's own accessors, the mirror of\n // what `serializeEntity` wrote. Without this the member would hold plain\n // objects while its declared type says otherwise — and a child whose\n // accessor carries an `alias` would keep the storage column name as its\n // property, which is exactly the mapping layer the serializer exists to\n // remove.\n if (metaAccessor.type === 'composition' && metaAccessor.childType) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const rows = (entityData as any)[propertyName];\n if (Array.isArray(rows)) {\n const childType =\n metaAccessor.childType() as EntityConstructor<Entity>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (newInstance as any)[metaAccessor.name] = rows.map(row =>\n buildEntityInstance(childType, row as object),\n );\n }\n return;\n }\n\n if (\n propertyName in entityData &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (entityData as any)[propertyName] !== undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (newInstance as any)[metaAccessor.name] = (entityData as any)[\n propertyName\n ];\n }\n });\n\n return newInstance;\n}\n\nfunction deserializeEntity<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n): TEntity | undefined {\n if (entityData == null) {\n return undefined;\n }\n assertEntityObject(entityConstructor, entityData);\n return buildEntityInstance(entityConstructor, entityData);\n}\n\nfunction deserializeCollection<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n failOnNull: boolean,\n): DeserializedEntity<TEntity>[] {\n if (entityCollectionData == null && !failOnNull) {\n return [];\n }\n assertEntityCollection(entityConstructor, entityCollectionData);\n\n // Recurse into nested arrays so a collection can hold arrays of arrays,\n // and reuse the single-entity validation/build for the leaf items.\n return entityCollectionData.map(item =>\n Array.isArray(item)\n ? deserializeCollection(entityConstructor, item, failOnNull)\n : deserializeEntity(entityConstructor, item),\n );\n}\n\n//#endregion\n\n//#region Effect factories\n\n// A record that does not build is a peer answering something unreadable: a\n// stored row or a served body that does not match the entity.\nconst unreadable = (message: string) => (error: unknown) =>\n new ProtocolFailure({\n reason: `${message}: ${messageOf(error)}`,\n });\n\nexport const deserializeSingleEntity = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityData: unknown,\n) =>\n Effect.try({\n try: () => deserializeEntity(entityConstructor, entityData),\n catch: unreadable(\n `Failed to deserialize entity of type ${entityConstructor.name}`,\n ),\n });\n\nexport const deserializeEntityCollection = <TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n entityCollectionData: unknown,\n failOnNull = false,\n) =>\n Effect.try({\n try: () =>\n deserializeCollection(\n entityConstructor,\n entityCollectionData,\n failOnNull,\n ),\n catch: unreadable(\n `Failed to deserialize entity collection of type ${entityConstructor.name}`,\n ),\n });\n\n//#endregion\n"],"names":["Effect","ProtocolFailure","messageOf","extractMetaAccessors","EntityCollectionLink","EntityLink","assertEntityObject","entityConstructor","entityData","Error","name","assertEntityCollection","entityCollectionData","Array","isArray","isEmbeddedData","value","populateEntityLink","link","rawValue","setValue","buildEntityInstance","setId","populateEntityCollectionLink","values","ids","item","push","length","setValues","setIds","metaAccessors","newInstance","filter","metaAccessor","hidden","readonly","kind","forEach","propertyName","alias","current","type","childType","rows","map","row","undefined","deserializeEntity","deserializeCollection","failOnNull","unreadable","message","error","reason","deserializeSingleEntity","try","catch","deserializeEntityCollection"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,eAAe,QAAQ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AAG,CAAC;QACTA,KAAK,IACHP,sBACE1C,mBACAK,sBACAsC;QAEJO,OAAON,WACL,CAAC,gDAAgD,EAAE5C,kBAAkBG,IAAI,EAAE;IAE/E,GAAG,CAEL,YAAY"}
@@ -1,5 +1,4 @@
1
1
  import type { Schema } from 'effect';
2
- import type { EntifixError } from '../base-entities/entifix-error/entifix-error.js';
3
2
  /**
4
3
  * The two families every failure belongs to
5
4
  * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).
@@ -70,10 +69,4 @@ export interface FailureClass {
70
69
  * because the decoder reads them back as the envelope rather than as fields.
71
70
  */
72
71
  export declare const RESERVED_FIELDS: ReadonlySet<string>;
73
- /**
74
- * What a port or a hook fails with while the framework moves from the
75
- * `EntifixError` class tree to typed failures: either one. Deleted with the
76
- * class tree, in the release that removes it.
77
- */
78
- export type TransitionalFailure = EntifixError | EntifixFailure;
79
72
  //# sourceMappingURL=failure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"failure.d.ts","sourceRoot":"","sources":["../../src/failure/failure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iDAAiD,CAAC;AAEpF;;;;;;;;GAQG;AACH,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,WAAW,CAAC;AAErD,2EAA2E;AAC3E,eAAO,MAAM,mBAAmB;;;;;;;CAOtB,CAAC;AAEX,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB;;;;;;;CAOvB,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,mBAAmB,CAAC;AAChE,MAAM,MAAM,iBAAiB,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAElE;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG,iBAAiB,CAAC;AAEnE,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,e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GAAG,MAAM,EAC5B,CAAC,SAAS,eAAe,GAAG,eAAe,CAC3C,SAAQ,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAC7B,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;IACnB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,KAAK,GAAG,IAAI,EAAE,KAAK,EAAE,GAAG,cAAc,CAAC;IACvC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC;CACvC;AAED;;;GAGG;AACH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,CAW9C,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/failure/failure.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { EntifixError } from '../base-entities/entifix-error/entifix-error.js';\n\n/**\n * The two families every failure belongs to\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * - `business` — an answer. The request was understood and the answer is no.\n * Never retried, never trips a breaker.\n * - `technical` — a non-answer. Something stopped the request being answered,\n * and the layer directly above may retry it.\n */\nexport type FailureFamily = 'business' | 'technical';\n\n/** The business categories, each with the status it answers by default. */\nexport const BUSINESS_CATEGORIES = {\n invalid: 400,\n unauthenticated: 401,\n forbidden: 403,\n notFound: 404,\n conflict: 409,\n declined: 422,\n} as const;\n\n/** The technical categories, each with the status it answers by default. */\nexport const TECHNICAL_CATEGORIES = {\n contention: 409,\n exhausted: 429,\n unavailable: 503,\n timeout: 504,\n protocol: 502,\n internal: 500,\n} as const;\n\nexport type BusinessCategory = keyof typeof BUSINESS_CATEGORIES;\nexport type TechnicalCategory = keyof typeof TECHNICAL_CATEGORIES;\n\n/**\n * The closed set. Every layer branches on it — the shell's status and log\n * tables, the bus's poison rule, the client's inline-versus-toast choice — so\n * it stays small enough for each of them to be exhaustive over. Tags stay open.\n */\nexport type FailureCategory = BusinessCategory | TechnicalCategory;\n\nexport type FamilyOf<C extends FailureCategory> = C extends BusinessCategory\n ? 'business'\n : 'technical';\n\nexport const FAILURE_CATEGORIES: readonly FailureCategory[] = [\n ...(Object.keys(BUSINESS_CATEGORIES) as BusinessCategory[]),\n ...(Object.keys(TECHNICAL_CATEGORIES) as TechnicalCategory[]),\n];\n\nexport const familyOf = <C extends FailureCategory>(category: C): FamilyOf<C> =>\n (category in BUSINESS_CATEGORIES ? 'business' : 'technical') as FamilyOf<C>;\n\n/** The status a category answers with unless a host overrides its tag. */\nexport const defaultStatus = (category: FailureCategory): number =>\n category in BUSINESS_CATEGORIES\n ? BUSINESS_CATEGORIES[category as BusinessCategory]\n : TECHNICAL_CATEGORIES[category as TechnicalCategory];\n\n/**\n * What every failure carries beyond its own fields. `code` is the permanent,\n * wire-visible key a client translates; `category` and `family` are what every\n * layer above decides by.\n */\nexport interface FailureFacts<\n Code extends string = string,\n C extends FailureCategory = FailureCategory,\n> {\n readonly code: Code;\n readonly category: C;\n readonly family: FamilyOf<C>;\n}\n\n/**\n * Any failure the framework or a host raises: a `Schema.TaggedError` carrying\n * its code, category and family.\n */\nexport interface EntifixFailure<\n Tag extends string = string,\n Code extends string = string,\n C extends FailureCategory = FailureCategory,\n> extends FailureFacts<Code, C> {\n readonly _tag: Tag;\n readonly message: string;\n}\n\n/** A failure class, as the registry and the problem codec hold it. */\nexport interface FailureClass {\n new (...args: never[]): EntifixFailure;\n readonly identifier: string;\n readonly fields: Schema.Struct.Fields;\n}\n\n/**\n * Members of the problem body that a failure's own fields must not shadow,\n * because the decoder reads them back as the envelope rather than as fields.\n */\nexport const RESERVED_FIELDS: ReadonlySet<string> = new Set([\n 'type',\n 'title',\n 'status',\n 'detail',\n 'instance',\n 'code',\n 'category',\n 'family',\n 'traceId',\n 'retryAfter',\n]);\n\n/**\n * What a port or a hook fails with while the framework moves from the\n * `EntifixError` class tree to typed failures: either one. Deleted with the\n * class tree, in the release that removes it.\n */\nexport type TransitionalFailure = EntifixError | EntifixFailure;\n"],"names":["BUSINESS_CATEGORIES","invalid","unauthenticated","forbidden","notFound","conflict","declined","TECHNICAL_CATEGORIES","contention","exhausted","unavailable","timeout","protocol","internal","FAILURE_CATEGORIES","Object","keys","familyOf","category","defaultStatus","RESERVED_FIELDS","Set"],"mappings":"AAeA,yEAAyE,GACzE,OAAO,MAAMA,sBAAsB;IACjCC,SAAS;IACTC,iBAAiB;IACjBC,WAAW;IACXC,UAAU;IACVC,UAAU;IACVC,UAAU;AACZ,EAAW;AAEX,0EAA0E,GAC1E,OAAO,MAAMC,uBAAuB;IAClCC,YAAY;IACZC,WAAW;IACXC,aAAa;IACbC,SAAS;IACTC,UAAU;IACVC,UAAU;AACZ,EAAW;AAgBX,OAAO,MAAMC,qBAAiD;OACxDC,OAAOC,IAAI,CAAChB;OACZe,OAAOC,IAAI,CAACT;CACjB,CAAC;AAEF,OAAO,MAAMU,WAAW,CAA4BC,WACjDA,YAAYlB,sBAAsB,aAAa,YAA4B;AAE9E,wEAAwE,GACxE,OAAO,MAAMmB,gBAAgB,CAACD,WAC5BA,YAAYlB,sBACRA,mBAAmB,CAACkB,SAA6B,GACjDX,oBAAoB,CAACW,SAA8B,CAAC;AAoC1D;;;CAGC,GACD,OAAO,MAAME,kBAAuC,IAAIC,IAAI;IAC1D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE"}
1
+ {"version":3,"sources":["../../src/failure/failure.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\n/**\n * The two families every failure belongs to\n * ([ADR 0013](../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * - `business` — an answer. The request was understood and the answer is no.\n * Never retried, never trips a breaker.\n * - `technical` — a non-answer. Something stopped the request being answered,\n * and the layer directly above may retry it.\n */\nexport type FailureFamily = 'business' | 'technical';\n\n/** The business categories, each with the status it answers by default. */\nexport const BUSINESS_CATEGORIES = {\n invalid: 400,\n unauthenticated: 401,\n forbidden: 403,\n notFound: 404,\n conflict: 409,\n declined: 422,\n} as const;\n\n/** The technical categories, each with the status it answers by default. */\nexport const TECHNICAL_CATEGORIES = {\n contention: 409,\n exhausted: 429,\n unavailable: 503,\n timeout: 504,\n protocol: 502,\n internal: 500,\n} as const;\n\nexport type BusinessCategory = keyof typeof BUSINESS_CATEGORIES;\nexport type TechnicalCategory = keyof typeof TECHNICAL_CATEGORIES;\n\n/**\n * The closed set. Every layer branches on it — the shell's status and log\n * tables, the bus's poison rule, the client's inline-versus-toast choice — so\n * it stays small enough for each of them to be exhaustive over. Tags stay open.\n */\nexport type FailureCategory = BusinessCategory | TechnicalCategory;\n\nexport type FamilyOf<C extends FailureCategory> = C extends BusinessCategory\n ? 'business'\n : 'technical';\n\nexport const FAILURE_CATEGORIES: readonly FailureCategory[] = [\n ...(Object.keys(BUSINESS_CATEGORIES) as BusinessCategory[]),\n ...(Object.keys(TECHNICAL_CATEGORIES) as TechnicalCategory[]),\n];\n\nexport const familyOf = <C extends FailureCategory>(category: C): FamilyOf<C> =>\n (category in BUSINESS_CATEGORIES ? 'business' : 'technical') as FamilyOf<C>;\n\n/** The status a category answers with unless a host overrides its tag. */\nexport const defaultStatus = (category: FailureCategory): number =>\n category in BUSINESS_CATEGORIES\n ? BUSINESS_CATEGORIES[category as BusinessCategory]\n : TECHNICAL_CATEGORIES[category as TechnicalCategory];\n\n/**\n * What every failure carries beyond its own fields. `code` is the permanent,\n * wire-visible key a client translates; `category` and `family` are what every\n * layer above decides by.\n */\nexport interface FailureFacts<\n Code extends string = string,\n C extends FailureCategory = FailureCategory,\n> {\n readonly code: Code;\n readonly category: C;\n readonly family: FamilyOf<C>;\n}\n\n/**\n * Any failure the framework or a host raises: a `Schema.TaggedError` carrying\n * its code, category and family.\n */\nexport interface EntifixFailure<\n Tag extends string = string,\n Code extends string = string,\n C extends FailureCategory = FailureCategory,\n> extends FailureFacts<Code, C> {\n readonly _tag: Tag;\n readonly message: string;\n}\n\n/** A failure class, as the registry and the problem codec hold it. */\nexport interface FailureClass {\n new (...args: never[]): EntifixFailure;\n readonly identifier: string;\n readonly fields: Schema.Struct.Fields;\n}\n\n/**\n * Members of the problem body that a failure's own fields must not shadow,\n * because the decoder reads them back as the envelope rather than as fields.\n */\nexport const RESERVED_FIELDS: ReadonlySet<string> = new Set([\n 'type',\n 'title',\n 'status',\n 'detail',\n 'instance',\n 'code',\n 'category',\n 'family',\n 'traceId',\n 'retryAfter',\n]);\n"],"names":["BUSINESS_CATEGORIES","invalid","unauthenticated","forbidden","notFound","conflict","declined","TECHNICAL_CATEGORIES","contention","exhausted","unavailable","timeout","protocol","internal","FAILURE_CATEGORIES","Object","keys","familyOf","category","defaultStatus","RESERVED_FIELDS","Set"],"mappings":"AAaA,yEAAyE,GACzE,OAAO,MAAMA,sBAAsB;IACjCC,SAAS;IACTC,iBAAiB;IACjBC,WAAW;IACXC,UAAU;IACVC,UAAU;IACVC,UAAU;AACZ,EAAW;AAEX,0EAA0E,GAC1E,OAAO,MAAMC,uBAAuB;IAClCC,YAAY;IACZC,WAAW;IACXC,aAAa;IACbC,SAAS;IACTC,UAAU;IACVC,UAAU;AACZ,EAAW;AAgBX,OAAO,MAAMC,qBAAiD;OACxDC,OAAOC,IAAI,CAAChB;OACZe,OAAOC,IAAI,CAACT;CACjB,CAAC;AAEF,OAAO,MAAMU,WAAW,CAA4BC,WACjDA,YAAYlB,sBAAsB,aAAa,YAA4B;AAE9E,wEAAwE,GACxE,OAAO,MAAMmB,gBAAgB,CAACD,WAC5BA,YAAYlB,sBACRA,mBAAmB,CAACkB,SAA6B,GACjDX,oBAAoB,CAACW,SAA8B,CAAC;AAoC1D;;;CAGC,GACD,OAAO,MAAME,kBAAuC,IAAIC,IAAI;IAC1D;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE"}
@@ -53,4 +53,10 @@ export interface EffectfulFailurePredicate<Shape, R = never> {
53
53
  }
54
54
  /** Pairs a guard with a condition read from the request's context. */
55
55
  export declare const when: <Shape, R = never>(guard: FailureGuard<Shape>, condition: (failure: Shape) => Effect.Effect<boolean, never, R>) => EffectfulFailurePredicate<Shape, R>;
56
+ /**
57
+ * What a thrown value says about itself: its `message` when it carries one,
58
+ * otherwise the value as text. Read off the shape rather than the class, so a
59
+ * value thrown from another realm or rebuilt from a wire reads the same.
60
+ */
61
+ export declare const messageOf: (thrown: unknown) => string;
56
62
  //# sourceMappingURL=predicates.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../../src/failure/predicates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,cAAc,CAAC;AAEtB;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,YAAY,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,OAAO,KAAK,KAAK,IAAI,KAAK,CAAC;AAOrE,gDAAgD;AAChD,eAAO,MAAM,KAAK,GACf,KAAK,CAAC,GAAG,SAAS,MAAM,EAAE,KAAK,GAAG,KAAG,YAAY,CAAC;IAAE,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAA;CAAE,CAE5C,CAAC;AAEhC,0CAA0C;AAC1C,eAAO,MAAM,UAAU,GACpB,KAAK,CAAC,CAAC,SAAS,eAAe,EAC9B,UAAU,CAAC,KACV,YAAY,CAAC;IAAE,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAA;CAAE,CAEF,CAAC;AAEzC,wCAAwC;AACxC,eAAO,MAAM,QAAQ,GAClB,KAAK,CAAC,CAAC,SAAS,aAAa,EAC5B,QAAQ,CAAC,KACR,YAAY,CAAC;IAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;CAAE,CAEJ,CAAC;AAErC,oDAAoD;AACpD,eAAO,MAAM,SA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MAAM,GAAG,GACb,CAAC,EAAE,OAAO,YAAY,CAAC,CAAC,CAAC,MACzB,CAAC,EAAE,OAAO,CAAC,KAAG,KAAK,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CACrB,CAAC;AAElB;;;;GAIG;AACH,MAAM,WAAW,yBAAyB,CAAC,KAAK,EAAE,CAAC,GAAG,KAAK;IACzD,QAAQ,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACpC,QAAQ,CAAC,SAAS,EAAE,CAAC,OAAO,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;CAC1E;AAED,sEAAsE;AACtE,eAAO,MAAM,IAAI,GAAI,KAAK,EAAE,CAAC,GAAG,KAAK,EACnC,OAAO,YAAY,CAAC,KAAK,CAAC,EAC1B,WAAW,CAAC,OAAO,EAAE,KAAK,KAAK,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC,KAC9D,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAA2B,CAAC;AAEjE;;;;GAIG;AACH,eAAO,MAAM,SAAS,GAAI,QAAQ,OAAO,KAAG,MAMxB,CAAC"}
@@ -18,5 +18,10 @@ const readsAs = (value, key, expected)=>typeof value === 'object' && value !== n
18
18
  guard,
19
19
  condition
20
20
  });
21
+ /**
22
+ * What a thrown value says about itself: its `message` when it carries one,
23
+ * otherwise the value as text. Read off the shape rather than the class, so a
24
+ * value thrown from another realm or rebuilt from a wire reads the same.
25
+ */ export const messageOf = (thrown)=>typeof thrown === 'object' && thrown !== null && 'message' in thrown && typeof thrown.message === 'string' ? thrown.message : String(thrown);
21
26
 
22
27
  //# sourceMappingURL=predicates.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/failure/predicates.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type {\n EntifixFailure,\n FailureCategory,\n FailureFamily,\n} from './failure.js';\n\n/**\n * A guard over anything, naming the shape it admits.\n *\n * It is written over `unknown` rather than over a failure union on purpose:\n * TypeScript narrows a union by a guard on a supertype by **filtering** its\n * members, so `if (isCategory('conflict')(e))` leaves exactly the members of\n * `E` whose `category` is `'conflict'` — the same as `Extract<E, Shape>` — and\n * one predicate serves every union it is applied to.\n *\n * The check reads `_tag`, `category` and `family` and never the prototype, so a\n * failure decoded off a wire or defined in a second copy of this module\n * matches exactly as one constructed in place.\n */\nexport type FailureGuard<Shape> = (value: unknown) => value is Shape;\n\nconst readsAs = (value: unknown, key: string, expected: string): boolean =>\n typeof value === 'object' &&\n value !== null &&\n (value as Record<string, unknown>)[key] === expected;\n\n/** Admits the failure whose `_tag` is `tag`. */\nexport const isTag =\n <const Tag extends string>(tag: Tag): FailureGuard<{ readonly _tag: Tag }> =>\n (value): value is { readonly _tag: Tag } =>\n readsAs(value, '_tag', tag);\n\n/** Admits every failure in `category`. */\nexport const isCategory =\n <const C extends FailureCategory>(\n category: C,\n ): FailureGuard<{ readonly category: C }> =>\n (value): value is { readonly category: C } =>\n readsAs(value, 'category', category);\n\n/** Admits every failure in `family`. */\nexport const isFamily =\n <const F extends FailureFamily>(\n family: F,\n ): FailureGuard<{ readonly family: F }> =>\n (value): value is { readonly family: F } =>\n readsAs(value, 'family', family);\n\n/** Admits any `EntifixFailure`, of any category. */\nexport const isFailure: FailureGuard<EntifixFailure> = (\n value,\n): value is EntifixFailure =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Record<string, unknown>)['_tag'] === 'string' &&\n typeof (value as Record<string, unknown>)['code'] === 'string' &&\n typeof (value as Record<string, unknown>)['category'] === 'string';\n\n/** Both guards admit it. */\nexport const and =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A & B> =>\n (value): value is A & B =>\n left(value) && right(value);\n\n/** Either guard admits it. */\nexport const or =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A | B> =>\n (value): value is A | B =>\n left(value) || right(value);\n\n/**\n * The guard does not admit it.\n *\n * ⚠️ Generic over the union it is applied to, because \"not this shape\" has no\n * shape of its own: `not(isFamily('business'))(e)` narrows `E` to\n * `Exclude<E, { family: 'business' }>`. Applied with no union in view — as an\n * argument to {@link and} or {@link or} — it admits correctly and narrows\n * nothing, so keep it the outermost combinator.\n */\nexport const not =\n <S>(guard: FailureGuard<S>) =>\n <E>(value: E): value is Exclude<E, S> =>\n !guard(value);\n\n/**\n * A guard plus a condition that needs the request — a dial read from\n * configuration, the caller's organization. The guard narrows; the condition\n * decides, and it is an Effect because the context it reads is.\n */\nexport interface EffectfulFailurePredicate<Shape, R = never> {\n readonly guard: FailureGuard<Shape>;\n readonly condition: (failure: Shape) => Effect.Effect<boolean, never, R>;\n}\n\n/** Pairs a guard with a condition read from the request's context. */\nexport const when = <Shape, R = never>(\n guard: FailureGuard<Shape>,\n condition: (failure: Shape) => Effect.Effect<boolean, never, R>,\n): EffectfulFailurePredicate<Shape, R> => ({ guard, condition });\n"],"names":["readsAs","value","key","expected","isTag","tag","isCategory","category","isFamily","family","isFailure","and","left","right","or","not","guard","when","condition"],"mappings":"AAuBA,MAAMA,UAAU,CAACC,OAAgBC,KAAaC,WAC5C,OAAOF,UAAU,YACjBA,UAAU,QACV,AAACA,KAAiC,CAACC,IAAI,KAAKC;AAE9C,8CAA8C,GAC9C,OAAO,MAAMC,QACX,CAA2BC,MAC3B,CAACJ,QACCD,QAAQC,OAAO,QAAQI,KAAK;AAEhC,wCAAwC,GACxC,OAAO,MAAMC,aACX,CACEC,WAEF,CAACN,QACCD,QAAQC,OAAO,YAAYM,UAAU;AAEzC,sCAAsC,GACtC,OAAO,MAAMC,WACX,CACEC,SAEF,CAACR,QACCD,QAAQC,OAAO,UAAUQ,QAAQ;AAErC,kDAAkD,GAClD,OAAO,MAAMC,YAA0C,CACrDT,QAEA,OAAOA,UAAU,YACjBA,UAAU,QACV,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,WAAW,KAAK,SAAS;AAErE,0BAA0B,GAC1B,OAAO,MAAMU,MACX,CAAOC,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC,4BAA4B,GAC5B,OAAO,MAAMa,KACX,CAAOF,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC;;;;;;;;CAQC,GACD,OAAO,MAAMc,MACX,CAAIC,QACJ,CAAIf,QACF,CAACe,MAAMf,OAAO;AAYlB,oEAAoE,GACpE,OAAO,MAAMgB,OAAO,CAClBD,OACAE,YACyC,CAAA;QAAEF;QAAOE;IAAU,CAAA,EAAG"}
1
+ {"version":3,"sources":["../../src/failure/predicates.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type {\n EntifixFailure,\n FailureCategory,\n FailureFamily,\n} from './failure.js';\n\n/**\n * A guard over anything, naming the shape it admits.\n *\n * It is written over `unknown` rather than over a failure union on purpose:\n * TypeScript narrows a union by a guard on a supertype by **filtering** its\n * members, so `if (isCategory('conflict')(e))` leaves exactly the members of\n * `E` whose `category` is `'conflict'` — the same as `Extract<E, Shape>` — and\n * one predicate serves every union it is applied to.\n *\n * The check reads `_tag`, `category` and `family` and never the prototype, so a\n * failure decoded off a wire or defined in a second copy of this module\n * matches exactly as one constructed in place.\n */\nexport type FailureGuard<Shape> = (value: unknown) => value is Shape;\n\nconst readsAs = (value: unknown, key: string, expected: string): boolean =>\n typeof value === 'object' &&\n value !== null &&\n (value as Record<string, unknown>)[key] === expected;\n\n/** Admits the failure whose `_tag` is `tag`. */\nexport const isTag =\n <const Tag extends string>(tag: Tag): FailureGuard<{ readonly _tag: Tag }> =>\n (value): value is { readonly _tag: Tag } =>\n readsAs(value, '_tag', tag);\n\n/** Admits every failure in `category`. */\nexport const isCategory =\n <const C extends FailureCategory>(\n category: C,\n ): FailureGuard<{ readonly category: C }> =>\n (value): value is { readonly category: C } =>\n readsAs(value, 'category', category);\n\n/** Admits every failure in `family`. */\nexport const isFamily =\n <const F extends FailureFamily>(\n family: F,\n ): FailureGuard<{ readonly family: F }> =>\n (value): value is { readonly family: F } =>\n readsAs(value, 'family', family);\n\n/** Admits any `EntifixFailure`, of any category. */\nexport const isFailure: FailureGuard<EntifixFailure> = (\n value,\n): value is EntifixFailure =>\n typeof value === 'object' &&\n value !== null &&\n typeof (value as Record<string, unknown>)['_tag'] === 'string' &&\n typeof (value as Record<string, unknown>)['code'] === 'string' &&\n typeof (value as Record<string, unknown>)['category'] === 'string';\n\n/** Both guards admit it. */\nexport const and =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A & B> =>\n (value): value is A & B =>\n left(value) && right(value);\n\n/** Either guard admits it. */\nexport const or =\n <A, B>(left: FailureGuard<A>, right: FailureGuard<B>): FailureGuard<A | B> =>\n (value): value is A | B =>\n left(value) || right(value);\n\n/**\n * The guard does not admit it.\n *\n * ⚠️ Generic over the union it is applied to, because \"not this shape\" has no\n * shape of its own: `not(isFamily('business'))(e)` narrows `E` to\n * `Exclude<E, { family: 'business' }>`. Applied with no union in view — as an\n * argument to {@link and} or {@link or} — it admits correctly and narrows\n * nothing, so keep it the outermost combinator.\n */\nexport const not =\n <S>(guard: FailureGuard<S>) =>\n <E>(value: E): value is Exclude<E, S> =>\n !guard(value);\n\n/**\n * A guard plus a condition that needs the request — a dial read from\n * configuration, the caller's organization. The guard narrows; the condition\n * decides, and it is an Effect because the context it reads is.\n */\nexport interface EffectfulFailurePredicate<Shape, R = never> {\n readonly guard: FailureGuard<Shape>;\n readonly condition: (failure: Shape) => Effect.Effect<boolean, never, R>;\n}\n\n/** Pairs a guard with a condition read from the request's context. */\nexport const when = <Shape, R = never>(\n guard: FailureGuard<Shape>,\n condition: (failure: Shape) => Effect.Effect<boolean, never, R>,\n): EffectfulFailurePredicate<Shape, R> => ({ guard, condition });\n\n/**\n * What a thrown value says about itself: its `message` when it carries one,\n * otherwise the value as text. Read off the shape rather than the class, so a\n * value thrown from another realm or rebuilt from a wire reads the same.\n */\nexport const messageOf = (thrown: unknown): string =>\n typeof thrown === 'object' &&\n thrown !== null &&\n 'message' in thrown &&\n typeof thrown.message === 'string'\n ? thrown.message\n : String(thrown);\n"],"names":["readsAs","value","key","expected","isTag","tag","isCategory","category","isFamily","family","isFailure","and","left","right","or","not","guard","when","condition","messageOf","thrown","message","String"],"mappings":"AAuBA,MAAMA,UAAU,CAACC,OAAgBC,KAAaC,WAC5C,OAAOF,UAAU,YACjBA,UAAU,QACV,AAACA,KAAiC,CAACC,IAAI,KAAKC;AAE9C,8CAA8C,GAC9C,OAAO,MAAMC,QACX,CAA2BC,MAC3B,CAACJ,QACCD,QAAQC,OAAO,QAAQI,KAAK;AAEhC,wCAAwC,GACxC,OAAO,MAAMC,aACX,CACEC,WAEF,CAACN,QACCD,QAAQC,OAAO,YAAYM,UAAU;AAEzC,sCAAsC,GACtC,OAAO,MAAMC,WACX,CACEC,SAEF,CAACR,QACCD,QAAQC,OAAO,UAAUQ,QAAQ;AAErC,kDAAkD,GAClD,OAAO,MAAMC,YAA0C,CACrDT,QAEA,OAAOA,UAAU,YACjBA,UAAU,QACV,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,OAAO,KAAK,YACtD,OAAO,AAACA,KAAiC,CAAC,WAAW,KAAK,SAAS;AAErE,0BAA0B,GAC1B,OAAO,MAAMU,MACX,CAAOC,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC,4BAA4B,GAC5B,OAAO,MAAMa,KACX,CAAOF,MAAuBC,QAC9B,CAACZ,QACCW,KAAKX,UAAUY,MAAMZ,OAAO;AAEhC;;;;;;;;CAQC,GACD,OAAO,MAAMc,MACX,CAAIC,QACJ,CAAIf,QACF,CAACe,MAAMf,OAAO;AAYlB,oEAAoE,GACpE,OAAO,MAAMgB,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AC1E,wBAAgB,WAAW,CAAC,CAAC,EAC3B,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EACb,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GACrB,OAAO,CAAC,CAAC,CAAC,EAAE,CAed;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAC3B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,GAAG,EAAE,MAAM,GACV,CAAC,EAAE,CAaL;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,GAAG,EAAE,MAAM,GACV,MAAM,EAAE,CAqBV;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,OAAO,CAGT;AAED,wEAAwE;AACxE,wBAAgB,OAAO,CAAC,CAAC,EACvB,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EACtB,GAAG,EAAE,MAAM,GACV,MAAM,CAER;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,MAAM,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC1B,aAAa,CAAC,CAAC,CAAC,GAAG,SAAS,CA2B9B"}
@@ -1,4 +1,3 @@
1
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
2
1
  import { assertOneParent, assertParentVisible } from '../entity-definition/describe/index.js';
3
2
  import { extractMetaAccessors } from '../entity-definition/helpers/index.js';
4
3
  /** An empty parent key is no parent, the way an empty form control is no value. */ const parentKey = (keys, item)=>{
@@ -148,7 +147,7 @@ import { extractMetaAccessors } from '../entity-definition/helpers/index.js';
148
147
  const parent = accessors.find((accessor)=>accessor.parent === true);
149
148
  if (parent === undefined) return undefined;
150
149
  if (parent.type !== undefined && parent.type !== 'id' && parent.type !== 'string') {
151
- throw new EntifixBuildError(`"${String(parent.name)}" is a ${parent.type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`);
150
+ throw new Error(`"${String(parent.name)}" is a ${parent.type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`);
152
151
  }
153
152
  const member = String((_parent_alias = parent.alias) != null ? _parent_alias : parent.name);
154
153
  const read = (item, name)=>item[name];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/hierarchy/hierarchy.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport {\n assertOneParent,\n assertParentVisible,\n} from '../entity-definition/describe/index.js';\nimport { extractMetaAccessors } from '../entity-definition/helpers/index.js';\nimport type { ChildConstructor } from '../entity-definition/meta-entities/meta-accessor/index.js';\n\n/**\n * How to read a record's place in a tree: its own key, and its parent's key or\n * `undefined` for a root. Every helper here takes one, so the same walk serves\n * an entity, a plain fixture row and a draft.\n */\nexport interface HierarchyKeys<T> {\n readonly idOf: (item: T) => string;\n readonly parentOf: (item: T) => string | undefined;\n}\n\n/** One record and the records whose parent it is, in their incoming order. */\nexport interface TreeNode<T> {\n readonly item: T;\n readonly depth: number;\n readonly children: readonly TreeNode<T>[];\n}\n\n/**\n * A set of records arranged as a tree.\n *\n * `detached` holds the records on a cycle — `a` is `b`'s parent and `b` is\n * `a`'s. No root leads to them, so they are in no subtree. They are\n * returned rather than dropped, because a record that silently disappears\n * from a listing is a defect nobody can see. A host that enforces the\n * invariant at save ({@link wouldCycle}) never has any.\n */\nexport interface Tree<T> {\n readonly roots: readonly TreeNode<T>[];\n readonly detached: readonly T[];\n}\n\n/** A tree node as one row of a flat listing. */\nexport interface TreeRow<T> {\n readonly item: T;\n readonly depth: number;\n readonly hasChildren: boolean;\n /** The keys of every ancestor, root first. */\n readonly path: readonly string[];\n}\n\n/** An empty parent key is no parent, the way an empty form control is no value. */\nconst parentKey = <T>(keys: HierarchyKeys<T>, item: T) => {\n const parent = keys.parentOf(item);\n return parent === undefined || parent === '' ? undefined : parent;\n};\n\n/**\n * Arrange records as a tree.\n *\n * A record whose parent is not in the set is a **root**: a page of records\n * holds children whose parents are on another page, and a retired or deleted\n * parent leaves its children behind. Siblings keep the order they came in,\n * so a sorted load stays sorted within each level.\n */\nexport function buildTree<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n): Tree<T> {\n const byKey = new Map(items.map(item => [keys.idOf(item), item]));\n const childrenOf = new Map<string, T[]>();\n const roots: T[] = [];\n for (const item of items) {\n const parent = parentKey(keys, item);\n if (parent === undefined || !byKey.has(parent)) {\n roots.push(item);\n } else {\n childrenOf.set(parent, [...(childrenOf.get(parent) ?? []), item]);\n }\n }\n\n const placed = new Set<string>();\n const node = (item: T, depth: number): TreeNode<T> => {\n const key = keys.idOf(item);\n placed.add(key);\n return {\n item,\n depth,\n children: (childrenOf.get(key) ?? []).map(child =>\n node(child, depth + 1),\n ),\n };\n };\n const tree = roots.map(root => node(root, 0));\n\n return {\n roots: tree,\n detached: items.filter(item => !placed.has(keys.idOf(item))),\n };\n}\n\n/** The tree as rows, depth first: each record followed by its subtree. */\nexport function flattenTree<T>(\n tree: Tree<T>,\n keys: HierarchyKeys<T>,\n): TreeRow<T>[] {\n const rows: TreeRow<T>[] = [];\n const walk = (node: TreeNode<T>, path: readonly string[]) => {\n rows.push({\n item: node.item,\n depth: node.depth,\n hasChildren: node.children.length > 0,\n path,\n });\n for (const child of node.children) {\n walk(child, [...path, keys.idOf(node.item)]);\n }\n };\n for (const root of tree.roots) walk(root, []);\n return rows;\n}\n\n/**\n * The ancestors of `key`, root first, not including the record itself.\n *\n * Stops at the first key it has already visited, so data that holds a cycle\n * yields a finite chain rather than a hung render.\n */\nexport function ancestorsOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): T[] {\n const byKey = new Map(items.map(item => [keys.idOf(item), item]));\n const chain: T[] = [];\n const seen = new Set([key]);\n let current = byKey.get(key);\n while (current !== undefined) {\n const parent = parentKey(keys, current);\n if (parent === undefined || seen.has(parent)) break;\n seen.add(parent);\n current = byKey.get(parent);\n if (current !== undefined) chain.unshift(current);\n }\n return chain;\n}\n\n/** The keys of every record under `key`, at any depth. Cycle-safe. */\nexport function descendantsOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): string[] {\n const childrenOf = new Map<string, string[]>();\n for (const item of items) {\n const parent = parentKey(keys, item);\n if (parent === undefined) continue;\n childrenOf.set(parent, [\n ...(childrenOf.get(parent) ?? []),\n keys.idOf(item),\n ]);\n }\n const found: string[] = [];\n const seen = new Set([key]);\n const queue = [...(childrenOf.get(key) ?? [])];\n while (queue.length > 0) {\n const next = queue.shift() as string;\n if (seen.has(next)) continue;\n seen.add(next);\n found.push(next);\n queue.push(...(childrenOf.get(next) ?? []));\n }\n return found;\n}\n\n/**\n * Would giving `key` the parent `parent` make a cycle? True when the parent is\n * the record itself or anything under it. The check a save runs, and the set a\n * parent picker excludes.\n */\nexport function wouldCycle<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n parent: string | undefined,\n): boolean {\n if (parent === undefined || parent === '') return false;\n return parent === key || descendantsOf(items, keys, key).includes(parent);\n}\n\n/** How deep `key` sits: 1 for a root, 2 for its children, and so on. */\nexport function depthOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): number {\n return ancestorsOf(items, keys, key).length + 1;\n}\n\n/**\n * The keys an entity's own metadata declares: its `id`, and the member marked\n * `@accessor({ parent: true })` — read by its wire key, the way a record\n * arrives. `undefined` when the entity declares no parent and so is not a\n * tree.\n *\n * Refuses a `hidden` or `readonly` parent, for the reason describing an\n * entity does: such a member is never serialized, so the tree would arrive\n * flat.\n */\nexport function hierarchyOf<T extends object>(\n target: ChildConstructor<T>,\n): HierarchyKeys<T> | undefined {\n const accessors = extractMetaAccessors(target).filter(\n accessor => accessor.kind === 'getter',\n );\n assertOneParent(accessors);\n assertParentVisible(accessors);\n const parent = accessors.find(accessor => accessor.parent === true);\n if (parent === undefined) return undefined;\n if (\n parent.type !== undefined &&\n parent.type !== 'id' &&\n parent.type !== 'string'\n ) {\n throw new EntifixBuildError(\n `\"${String(parent.name)}\" is a ${parent.type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n }\n const member = String(parent.alias ?? parent.name);\n const read = (item: T, name: string) =>\n (item as Record<string, unknown>)[name];\n const asKey = (value: unknown) =>\n value === undefined || value === null ? undefined : String(value);\n\n return {\n idOf: item => String(read(item, 'id') ?? ''),\n parentOf: item => asKey(read(item, member)),\n };\n}\n"],"names":["EntifixBuildError","assertOneParent","assertParentVisible","extractMetaAccessors","parentKey","keys","item","parent","parentOf","undefined","buildTree","items","byKey","Map","map","idOf","childrenOf","roots","has","push","set","get","placed","Set","node","depth","key","add","children","child","tree","root","detached","filter","flattenTree","rows","walk","path","hasChildren","length","ancestorsOf","chain","seen","current","unshift","descendantsOf","found","queue","next","shift","wouldCycle","includes","depthOf","hierarchyOf","target","accessors","accessor","kind","find","type","String","name","member","alias","read","asKey","value"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAC5E,SACEC,eAAe,EACfC,mBAAmB,QACd,yCAAyC;AAChD,SAASC,oBAAoB,QAAQ,wCAAwC;AA2C7E,iFAAiF,GACjF,MAAMC,YAAY,CAAIC,MAAwBC;IAC5C,MAAMC,SAASF,KAAKG,QAAQ,CAACF;IAC7B,OAAOC,WAAWE,aAAaF,WAAW,KAAKE,YAAYF;AAC7D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,UACdC,KAAmB,EACnBN,IAAsB;IAEtB,MAAMO,QAAQ,IAAIC,IAAIF,MAAMG,GAAG,CAACR,CAAAA,OAAQ;YAACD,KAAKU,IA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MG,OAAO,CAAC1D,MAASuD,OACrB,AAACvD,IAAgC,CAACuD,KAAK;IACzC,MAAMI,QAAQ,CAACC,QACbA,UAAUzD,aAAayD,UAAU,OAAOzD,YAAYmD,OAAOM;IAE7D,OAAO;QACLnD,MAAMT,CAAAA;gBAAe0D;mBAAPJ,QAAOI,QAAAA,KAAK1D,MAAM,iBAAX0D,QAAoB;;QACzCxD,UAAUF,CAAAA,OAAQ2D,MAAMD,KAAK1D,MAAMwD;IACrC;AACF"}
1
+ {"version":3,"sources":["../../src/hierarchy/hierarchy.ts"],"sourcesContent":["import {\n assertOneParent,\n assertParentVisible,\n} from '../entity-definition/describe/index.js';\nimport { extractMetaAccessors } from '../entity-definition/helpers/index.js';\nimport type { ChildConstructor } from '../entity-definition/meta-entities/meta-accessor/index.js';\n\n/**\n * How to read a record's place in a tree: its own key, and its parent's key or\n * `undefined` for a root. Every helper here takes one, so the same walk serves\n * an entity, a plain fixture row and a draft.\n */\nexport interface HierarchyKeys<T> {\n readonly idOf: (item: T) => string;\n readonly parentOf: (item: T) => string | undefined;\n}\n\n/** One record and the records whose parent it is, in their incoming order. */\nexport interface TreeNode<T> {\n readonly item: T;\n readonly depth: number;\n readonly children: readonly TreeNode<T>[];\n}\n\n/**\n * A set of records arranged as a tree.\n *\n * `detached` holds the records on a cycle — `a` is `b`'s parent and `b` is\n * `a`'s. No root leads to them, so they are in no subtree. They are\n * returned rather than dropped, because a record that silently disappears\n * from a listing is a defect nobody can see. A host that enforces the\n * invariant at save ({@link wouldCycle}) never has any.\n */\nexport interface Tree<T> {\n readonly roots: readonly TreeNode<T>[];\n readonly detached: readonly T[];\n}\n\n/** A tree node as one row of a flat listing. */\nexport interface TreeRow<T> {\n readonly item: T;\n readonly depth: number;\n readonly hasChildren: boolean;\n /** The keys of every ancestor, root first. */\n readonly path: readonly string[];\n}\n\n/** An empty parent key is no parent, the way an empty form control is no value. */\nconst parentKey = <T>(keys: HierarchyKeys<T>, item: T) => {\n const parent = keys.parentOf(item);\n return parent === undefined || parent === '' ? undefined : parent;\n};\n\n/**\n * Arrange records as a tree.\n *\n * A record whose parent is not in the set is a **root**: a page of records\n * holds children whose parents are on another page, and a retired or deleted\n * parent leaves its children behind. Siblings keep the order they came in,\n * so a sorted load stays sorted within each level.\n */\nexport function buildTree<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n): Tree<T> {\n const byKey = new Map(items.map(item => [keys.idOf(item), item]));\n const childrenOf = new Map<string, T[]>();\n const roots: T[] = [];\n for (const item of items) {\n const parent = parentKey(keys, item);\n if (parent === undefined || !byKey.has(parent)) {\n roots.push(item);\n } else {\n childrenOf.set(parent, [...(childrenOf.get(parent) ?? []), item]);\n }\n }\n\n const placed = new Set<string>();\n const node = (item: T, depth: number): TreeNode<T> => {\n const key = keys.idOf(item);\n placed.add(key);\n return {\n item,\n depth,\n children: (childrenOf.get(key) ?? []).map(child =>\n node(child, depth + 1),\n ),\n };\n };\n const tree = roots.map(root => node(root, 0));\n\n return {\n roots: tree,\n detached: items.filter(item => !placed.has(keys.idOf(item))),\n };\n}\n\n/** The tree as rows, depth first: each record followed by its subtree. */\nexport function flattenTree<T>(\n tree: Tree<T>,\n keys: HierarchyKeys<T>,\n): TreeRow<T>[] {\n const rows: TreeRow<T>[] = [];\n const walk = (node: TreeNode<T>, path: readonly string[]) => {\n rows.push({\n item: node.item,\n depth: node.depth,\n hasChildren: node.children.length > 0,\n path,\n });\n for (const child of node.children) {\n walk(child, [...path, keys.idOf(node.item)]);\n }\n };\n for (const root of tree.roots) walk(root, []);\n return rows;\n}\n\n/**\n * The ancestors of `key`, root first, not including the record itself.\n *\n * Stops at the first key it has already visited, so data that holds a cycle\n * yields a finite chain rather than a hung render.\n */\nexport function ancestorsOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): T[] {\n const byKey = new Map(items.map(item => [keys.idOf(item), item]));\n const chain: T[] = [];\n const seen = new Set([key]);\n let current = byKey.get(key);\n while (current !== undefined) {\n const parent = parentKey(keys, current);\n if (parent === undefined || seen.has(parent)) break;\n seen.add(parent);\n current = byKey.get(parent);\n if (current !== undefined) chain.unshift(current);\n }\n return chain;\n}\n\n/** The keys of every record under `key`, at any depth. Cycle-safe. */\nexport function descendantsOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): string[] {\n const childrenOf = new Map<string, string[]>();\n for (const item of items) {\n const parent = parentKey(keys, item);\n if (parent === undefined) continue;\n childrenOf.set(parent, [\n ...(childrenOf.get(parent) ?? []),\n keys.idOf(item),\n ]);\n }\n const found: string[] = [];\n const seen = new Set([key]);\n const queue = [...(childrenOf.get(key) ?? [])];\n while (queue.length > 0) {\n const next = queue.shift() as string;\n if (seen.has(next)) continue;\n seen.add(next);\n found.push(next);\n queue.push(...(childrenOf.get(next) ?? []));\n }\n return found;\n}\n\n/**\n * Would giving `key` the parent `parent` make a cycle? True when the parent is\n * the record itself or anything under it. The check a save runs, and the set a\n * parent picker excludes.\n */\nexport function wouldCycle<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n parent: string | undefined,\n): boolean {\n if (parent === undefined || parent === '') return false;\n return parent === key || descendantsOf(items, keys, key).includes(parent);\n}\n\n/** How deep `key` sits: 1 for a root, 2 for its children, and so on. */\nexport function depthOf<T>(\n items: readonly T[],\n keys: HierarchyKeys<T>,\n key: string,\n): number {\n return ancestorsOf(items, keys, key).length + 1;\n}\n\n/**\n * The keys an entity's own metadata declares: its `id`, and the member marked\n * `@accessor({ parent: true })` — read by its wire key, the way a record\n * arrives. `undefined` when the entity declares no parent and so is not a\n * tree.\n *\n * Refuses a `hidden` or `readonly` parent, for the reason describing an\n * entity does: such a member is never serialized, so the tree would arrive\n * flat.\n */\nexport function hierarchyOf<T extends object>(\n target: ChildConstructor<T>,\n): HierarchyKeys<T> | undefined {\n const accessors = extractMetaAccessors(target).filter(\n accessor => accessor.kind === 'getter',\n );\n assertOneParent(accessors);\n assertParentVisible(accessors);\n const parent = accessors.find(accessor => accessor.parent === true);\n if (parent === undefined) return undefined;\n if (\n parent.type !== undefined &&\n parent.type !== 'id' &&\n parent.type !== 'string'\n ) {\n throw new Error(\n `\"${String(parent.name)}\" is a ${parent.type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n }\n const member = String(parent.alias ?? parent.name);\n const read = (item: T, name: string) =>\n (item as Record<string, unknown>)[name];\n const asKey = (value: unknown) =>\n value === undefined || value === null ? undefined : String(value);\n\n return {\n idOf: item => String(read(item, 'id') ?? ''),\n parentOf: item => asKey(read(item, member)),\n };\n}\n"],"names":["assertOneParent","assertParentVisible","extractMetaAccessors","parentKey","keys","item","parent","parentOf","undefined","buildTree","items","byKey","Map","map","idOf","childrenOf","roots","has","push","set","get","placed","Set","node","depth","key","add","children","child","tree","root","detached","filter","flattenTree","rows","walk","path","hasChildren","length","ancestorsOf","chain","seen","current","unshift","descendantsOf","found","queue","next","shift","wouldCycle","includes","depthOf","hierarchyOf","target","accessors","accessor","kind","find","type","Error","String","name","member","alias","read","asKey","value"],"mappings":"AAAA,SACEA,eAAe,EACfC,mBAAmB,QACd,yCAAyC;AAChD,SAASC,oBAAoB,QAAQ,wCAAwC;AA2C7E,iFAAiF,GACjF,MAAMC,YAAY,CAAIC,MAAwBC;IAC5C,MAAMC,SAASF,KAAKG,QAAQ,CAACF;IAC7B,OAAOC,WAAWE,aAAaF,WAAW,KAAKE,YAAYF;AAC7D;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,UACdC,KAAmB,EACnBN,IAAsB;IAEtB,MAAMO,QAAQ,IAAIC,IAAIF,MAAMG,GAAG,CAACR,CAAAA,OAAQ;YAACD,KAAKU,IAAI,CAACT;YAAOA;SAAK;IAC/D,MAAMU,aAAa,IAAIH;IACvB,MAAMI,QAAa,EAAE;IACrB,KAAK,MAAMX,QAAQK,MAAO;QACxB,MAAMJ,SAASH,UAAUC,MAAMC;QAC/B,IAAIC,WAAWE,aAAa,CAACG,MAAMM,GAAG,CAACX,SAAS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A,KAAK3D,MAAM,iBAAX2D,QAAoB;;QACzCzD,UAAUF,CAAAA,OAAQ4D,MAAMD,KAAK3D,MAAMyD;IACrC;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../src/i18n/locales.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AAGH,MAAM,WAAW,cAAc;CAAG;AAElC,uEAAuE;AACvE,MAAM,MAAM,MAAM,GAAG,cAAc,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM,CAAA;CAAE,GAC1E,CAAC,GACD,MAAM,CAAC;AAEX,0DAA0D;AAC1D,MAAM,WAAW,gBAAgB;IAC/B,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAcD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAmBhE;AAED,qCAAqC;AACrC,wBAAgB,OAAO,IAAI,SAAS,MAAM,EAAE,CAE3C;AAED,iCAAiC;AACjC,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,iDAAiD;AACjD,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAEhD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAKxD"}
1
+ {"version":3,"file":"locales.d.ts","sourceRoot":"","sources":["../../src/i18n/locales.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,MAAM,WAAW,cAAc;CAAG;AAElC,uEAAuE;AACvE,MAAM,MAAM,MAAM,GAAG,cAAc,SAAS;IAAE,MAAM,EAAE,MAAM,CAAC,SAAS,MAAM,CAAA;CAAE,GAC1E,CAAC,GACD,MAAM,CAAC;AAEX,0DAA0D;AAC1D,MAAM,WAAW,gBAAgB;IAC/B,wEAAwE;IACxE,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;CAChC;AAcD;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,IAAI,CAiBhE;AAED,qCAAqC;AACrC,wBAAgB,OAAO,IAAI,SAAS,MAAM,EAAE,CAE3C;AAED,iCAAiC;AACjC,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,iDAAiD;AACjD,wBAAgB,YAAY,IAAI,IAAI,CAEnC;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C;;;;GAIG;AACH,eAAO,MAAM,aAAa,qBAAqB,CAAC;AAEhD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAKxD"}
@@ -1,4 +1,19 @@
1
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
1
+ /**
2
+ * Where a host narrows {@link Locale} to the locales it ships:
3
+ *
4
+ * ```ts
5
+ * declare module '@entifix/core' {
6
+ * interface LocaleRegister {
7
+ * locale: 'es' | 'en';
8
+ * }
9
+ * }
10
+ * ```
11
+ *
12
+ * The same mechanism i18next's `CustomTypeOptions` uses. Without it a locale is
13
+ * any string, which is honest for a framework that does not know which
14
+ * languages its host speaks.
15
+ */ // An empty interface is the point: a host merges its declaration into it.
16
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type
2
17
  /**
3
18
  * What a host gets when it declares nothing: English alone. Neutral rather than
4
19
  * any one adopter's choice — the adopter that once supplied the `es` default
@@ -22,14 +37,14 @@ let declared = UNDECLARED;
22
37
  */ export function defineLocales(definition) {
23
38
  const { locales: list, defaultLocale: fallback } = definition;
24
39
  if (list.length === 0) {
25
- throw new EntifixBuildError('defineLocales needs at least one locale.');
40
+ throw new Error('defineLocales needs at least one locale.');
26
41
  }
27
42
  const duplicate = list.find((locale, index)=>list.indexOf(locale) !== index);
28
43
  if (duplicate !== undefined) {
29
- throw new EntifixBuildError(`defineLocales was given "${duplicate}" more than once.`);
44
+ throw new Error(`defineLocales was given "${duplicate}" more than once.`);
30
45
  }
31
46
  if (!list.includes(fallback)) {
32
- throw new EntifixBuildError(`The default locale "${fallback}" is not one of ${JSON.stringify(list)}.`);
47
+ throw new Error(`The default locale "${fallback}" is not one of ${JSON.stringify(list)}.`);
33
48
  }
34
49
  declared = {
35
50
  locales: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/i18n/locales.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\n\n/**\n * Where a host narrows {@link Locale} to the locales it ships:\n *\n * ```ts\n * declare module '@entifix/core' {\n * interface LocaleRegister {\n * locale: 'es' | 'en';\n * }\n * }\n * ```\n *\n * The same mechanism i18next's `CustomTypeOptions` uses. Without it a locale is\n * any string, which is honest for a framework that does not know which\n * languages its host speaks.\n */\n// An empty interface is the point: a host merges its declaration into it.\n// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type\nexport interface LocaleRegister {}\n\n/** A locale the host declared, or any string when it declared none. */\nexport type Locale = LocaleRegister extends { locale: infer L extends string }\n ? L\n : string;\n\n/** What a host declares through {@link defineLocales}. */\nexport interface LocaleDefinition {\n /** Every locale the host ships, in the order a switcher offers them. */\n readonly locales: readonly Locale[];\n /**\n * The locale a visitor gets when nothing else decides, and the one a missing\n * catalog key falls back to.\n */\n readonly defaultLocale: Locale;\n}\n\n/**\n * What a host gets when it declares nothing: English alone. Neutral rather than\n * any one adopter's choice — the adopter that once supplied the `es` default\n * here now declares it like everyone else (#35).\n */\nconst UNDECLARED: LocaleDefinition = {\n locales: ['en' as Locale],\n defaultLocale: 'en' as Locale,\n};\n\nlet declared: LocaleDefinition = UNDECLARED;\n\n/**\n * Declares the host's locales. Call it once, from a module every entry point\n * imports — including a Next middleware, which is bundled on its own and shares\n * no module state with the server.\n *\n * Read at call time by every helper below and by `@entifix/i18n`,\n * `@entifix/react-controls` and `@entifix/next-i18n`, so a host declaring\n * `['en', 'es']` with `en` first gets English as the fallback everywhere, and a\n * third locale needs no change to entifix.\n */\nexport function defineLocales(definition: LocaleDefinition): void {\n const { locales: list, defaultLocale: fallback } = definition;\n if (list.length === 0) {\n throw new EntifixBuildError('defineLocales needs at least one locale.');\n }\n const duplicate = list.find(\n (locale, index) => list.indexOf(locale) !== index,\n );\n if (duplicate !== undefined) {\n throw new EntifixBuildError(\n `defineLocales was given \"${duplicate}\" more than once.`,\n );\n }\n if (!list.includes(fallback)) {\n throw new EntifixBuildError(\n `The default locale \"${fallback}\" is not one of ${JSON.stringify(list)}.`,\n );\n }\n declared = { locales: [...list], defaultLocale: fallback };\n}\n\n/** The locales the host declared. */\nexport function locales(): readonly Locale[] {\n return declared.locales;\n}\n\n/** The host's default locale. */\nexport function defaultLocale(): Locale {\n return declared.defaultLocale;\n}\n\n/** Forgets the host's declaration. For specs. */\nexport function resetLocales(): void {\n declared = UNDECLARED;\n}\n\n/**\n * Host-scoped so the choice is shared across the fleet's localhost ports in dev,\n * exactly like `entifix_at`/`entifix_sid`. Written by the locale middleware on every\n * redirect, so a visitor who lands on `/en/...` keeps English on the next visit.\n */\nexport const LOCALE_COOKIE = 'entifix_locale';\n\n/**\n * Request header the locale middleware sets when it rewrites a prefixed path.\n * Server components read it instead of a route param, which is what lets the\n * route tree stay free of an `app/[locale]` segment.\n */\nexport const LOCALE_HEADER = 'x-entifix-locale';\n\nexport function isLocale(value: unknown): value is Locale {\n return (\n typeof value === 'string' &&\n (declared.locales as readonly string[]).includes(value)\n );\n}\n"],"names":["EntifixBuildError","UNDECLARED","locales","defaultLocale","declared","defineLocales","definition","list","fallback","length","duplicate","find","locale","index","indexOf","undefined","includes","JSON","stringify","resetLocales","LOCALE_COOKIE","LOCALE_HEADER","isLocale","value"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAqC5E;;;;CAIC,GACD,MAAMC,aAA+B;IACnCC,SAAS;QAAC;KAAe;IACzBC,eAAe;AACjB;AAEA,IAAIC,WAA6BH;AAEjC;;;;;;;;;CASC,GACD,OAAO,SAASI,cAAcC,UAA4B;IACxD,MAAM,EAAEJ,SAASK,IAAI,EAAEJ,eAAeK,QAAQ,EAAE,GAAGF;IACnD,IAAIC,KAAKE,MAAM,KAAK,GAAG;QACrB,MAAM,IAAIT,kBAAkB;IAC9B;IACA,MAAMU,YAAYH,KAAKI,IAAI,CACzB,CAACC,QAAQC,QAAUN,KAAKO,OAAO,CAACF,YAAYC;IAE9C,IAAIH,cAAcK,WAAW;QAC3B,MAAM,IAAIf,kBACR,CAAC,yBAAyB,EAAEU,UAAU,iBAAiB,CAAC;IAE5D;IACA,IAAI,CAACH,KAAKS,QAAQ,CAACR,WAAW;QAC5B,MAAM,IAAIR,kBACR,CAAC,oBAAoB,EAAEQ,SAAS,gBAAgB,EAAES,KAAKC,SAAS,CAACX,MAAM,CAAC,CAAC;IAE7E;IACAH,WAAW;QAAEF,SAAS;eAAIK;SAAK;QAAEJ,eAAeK;IAAS;AAC3D;AAEA,mCAAmC,GACnC,OAAO,SAASN;IACd,OAAOE,SAASF,OAAO;AACzB;AAEA,+BAA+B,GAC/B,OAAO,SAASC;IACd,OAAOC,SAASD,aAAa;AAC/B;AAEA,+CAA+C,GAC/C,OAAO,SAASgB;IACdf,WAAWH;AACb;AAEA;;;;CAIC,GACD,OAAO,MAAMmB,gBAAgB,iBAAiB;AAE9C;;;;CAIC,GACD,OAAO,MAAMC,gBAAgB,mBAAmB;AAEhD,OAAO,SAASC,SAASC,KAAc;IACrC,OACE,OAAOA,UAAU,YACjB,AAACnB,SAASF,OAAO,CAAuBc,QAAQ,CAACO;AAErD"}
1
+ {"version":3,"sources":["../../src/i18n/locales.ts"],"sourcesContent":["/**\n * Where a host narrows {@link Locale} to the locales it ships:\n *\n * ```ts\n * declare module '@entifix/core' {\n * interface LocaleRegister {\n * locale: 'es' | 'en';\n * }\n * }\n * ```\n *\n * The same mechanism i18next's `CustomTypeOptions` uses. Without it a locale is\n * any string, which is honest for a framework that does not know which\n * languages its host speaks.\n */\n// An empty interface is the point: a host merges its declaration into it.\n// eslint-disable-next-line @typescript-eslint/no-empty-interface, @typescript-eslint/no-empty-object-type\nexport interface LocaleRegister {}\n\n/** A locale the host declared, or any string when it declared none. */\nexport type Locale = LocaleRegister extends { locale: infer L extends string }\n ? L\n : string;\n\n/** What a host declares through {@link defineLocales}. */\nexport interface LocaleDefinition {\n /** Every locale the host ships, in the order a switcher offers them. */\n readonly locales: readonly Locale[];\n /**\n * The locale a visitor gets when nothing else decides, and the one a missing\n * catalog key falls back to.\n */\n readonly defaultLocale: Locale;\n}\n\n/**\n * What a host gets when it declares nothing: English alone. Neutral rather than\n * any one adopter's choice — the adopter that once supplied the `es` default\n * here now declares it like everyone else (#35).\n */\nconst UNDECLARED: LocaleDefinition = {\n locales: ['en' as Locale],\n defaultLocale: 'en' as Locale,\n};\n\nlet declared: LocaleDefinition = UNDECLARED;\n\n/**\n * Declares the host's locales. Call it once, from a module every entry point\n * imports — including a Next middleware, which is bundled on its own and shares\n * no module state with the server.\n *\n * Read at call time by every helper below and by `@entifix/i18n`,\n * `@entifix/react-controls` and `@entifix/next-i18n`, so a host declaring\n * `['en', 'es']` with `en` first gets English as the fallback everywhere, and a\n * third locale needs no change to entifix.\n */\nexport function defineLocales(definition: LocaleDefinition): void {\n const { locales: list, defaultLocale: fallback } = definition;\n if (list.length === 0) {\n throw new Error('defineLocales needs at least one locale.');\n }\n const duplicate = list.find(\n (locale, index) => list.indexOf(locale) !== index,\n );\n if (duplicate !== undefined) {\n throw new Error(`defineLocales was given \"${duplicate}\" more than once.`);\n }\n if (!list.includes(fallback)) {\n throw new Error(\n `The default locale \"${fallback}\" is not one of ${JSON.stringify(list)}.`,\n );\n }\n declared = { locales: [...list], defaultLocale: fallback };\n}\n\n/** The locales the host declared. */\nexport function locales(): readonly Locale[] {\n return declared.locales;\n}\n\n/** The host's default locale. */\nexport function defaultLocale(): Locale {\n return declared.defaultLocale;\n}\n\n/** Forgets the host's declaration. For specs. */\nexport function resetLocales(): void {\n declared = UNDECLARED;\n}\n\n/**\n * Host-scoped so the choice is shared across the fleet's localhost ports in dev,\n * exactly like `entifix_at`/`entifix_sid`. Written by the locale middleware on every\n * redirect, so a visitor who lands on `/en/...` keeps English on the next visit.\n */\nexport const LOCALE_COOKIE = 'entifix_locale';\n\n/**\n * Request header the locale middleware sets when it rewrites a prefixed path.\n * Server components read it instead of a route param, which is what lets the\n * route tree stay free of an `app/[locale]` segment.\n */\nexport const LOCALE_HEADER = 'x-entifix-locale';\n\nexport function isLocale(value: unknown): value is Locale {\n return (\n typeof value === 'string' &&\n (declared.locales as readonly string[]).includes(value)\n );\n}\n"],"names":["UNDECLARED","locales","defaultLocale","declared","defineLocales","definition","list","fallback","length","Error","duplicate","find","locale","index","indexOf","undefined","includes","JSON","stringify","resetLocales","LOCALE_COOKIE","LOCALE_HEADER","isLocale","value"],"mappings":"AAAA;;;;;;;;;;;;;;CAcC,GACD,0EAA0E;AAC1E,0GAA0G;AAmB1G;;;;CAIC,GACD,MAAMA,aAA+B;IACnCC,SAAS;QAAC;KAAe;IACzBC,eAAe;AACjB;AAEA,IAAIC,WAA6BH;AAEjC;;;;;;;;;CASC,GACD,OAAO,SAASI,cAAcC,UAA4B;IACxD,MAAM,EAAEJ,SAASK,IAAI,EAAEJ,eAAeK,QAAQ,EAAE,GAAGF;IACnD,IAAIC,KAAKE,MAAM,KAAK,GAAG;QACrB,MAAM,IAAIC,MAAM;IAClB;IACA,MAAMC,YAAYJ,KAAKK,IAAI,CACzB,CAACC,QAAQC,QAAUP,KAAKQ,OAAO,CAACF,YAAYC;IAE9C,IAAIH,cAAcK,WAAW;QAC3B,MAAM,IAAIN,MAAM,CAAC,yBAAyB,EAAEC,UAAU,iBAAiB,CAAC;IAC1E;IACA,IAAI,CAACJ,KAAKU,QAAQ,CAACT,WAAW;QAC5B,MAAM,IAAIE,MACR,CAAC,oBAAoB,EAAEF,SAAS,gBAAgB,EAAEU,KAAKC,SAAS,CAACZ,MAAM,CAAC,CAAC;IAE7E;IACAH,WAAW;QAAEF,SAAS;eAAIK;SAAK;QAAEJ,eAAeK;IAAS;AAC3D;AAEA,mCAAmC,GACnC,OAAO,SAASN;IACd,OAAOE,SAASF,OAAO;AACzB;AAEA,+BAA+B,GAC/B,OAAO,SAASC;IACd,OAAOC,SAASD,aAAa;AAC/B;AAEA,+CAA+C,GAC/C,OAAO,SAASiB;IACdhB,WAAWH;AACb;AAEA;;;;CAIC,GACD,OAAO,MAAMoB,gBAAgB,iBAAiB;AAE9C;;;;CAIC,GACD,OAAO,MAAMC,gBAAgB,mBAAmB;AAEhD,OAAO,SAASC,SAASC,KAAc;IACrC,OACE,OAAOA,UAAU,YACjB,AAACpB,SAASF,OAAO,CAAuBe,QAAQ,CAACO;AAErD"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './base-entities/configuration-client/index.js';
2
- export * from './base-entities/entifix-error/index.js';
3
2
  export * from './command-palette/index.js';
4
3
  export * from './deadline/deadline.js';
5
4
  export * from './endpoint/index.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+CAA+C,CAAC;AAC9D,cAAc,wCAAwC,CAAC;AACvD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC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AAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export * from './base-entities/configuration-client/index.js';
2
- export * from './base-entities/entifix-error/index.js';
3
2
  export * from './command-palette/index.js';
4
3
  export * from './deadline/deadline.js';
5
4
  export * from './endpoint/index.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './base-entities/entifix-error/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,yCAAyC;AACvD,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,oBAAoB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc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nD,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,SAAS,EAAE,SAAS,eAAe,CAAC,OAAO,CAAC,EAAE,GAAG,SAAS,GACzD,OAAO,EAAE,CAEX;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,EACjD,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,OAAO,EAAE,SAAS,aAAa,CAAC,OAAO,CAAC,EAAE,GAAG,SAAS,GACrD,OAAO,EAAE,CAqBX;AAWD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,OAAO,SAAS,MAAM,EAChD,OAAO,EAAE,SAAS,OAAO,EAAE,EAC3B,OAAO,EAAE,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAAE,GAC5C,iBAAiB,CAgBnB"}
@@ -1,4 +1,3 @@
1
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
2
1
  import { EntityCollectionLink } from '../entity-definition/links/entity-collection-link/index.js';
3
2
  import { EntityLink } from '../entity-definition/links/entity-link/index.js';
4
3
  import { containsFolded } from './fold.js';
@@ -134,7 +133,7 @@ const isBetween = (actual, start, end)=>actual != null && compareStoredValues(ac
134
133
  {
135
134
  // Exhaustiveness guard — a new operator must be handled explicitly.
136
135
  const never = filter;
137
- throw new EntifixBuildError(`Unknown filter operator "${String(never.operator)}"`);
136
+ throw new Error(`Unknown filter operator "${String(never.operator)}"`);
138
137
  }
139
138
  }
140
139
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/query/in-memory-query.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport { EntityCollectionLink } from '../entity-definition/links/entity-collection-link/index.js';\nimport { EntityLink } from '../entity-definition/links/entity-link/index.js';\nimport type { Entity } from '../types/Entity.js';\nimport type {\n EntityFacetCounts,\n EntityFacetQuery,\n EntityFacetValue,\n} from '../types/EntityFacets.js';\nimport type {\n EntityFilter,\n EntityFiltering,\n FilterGroup,\n} from '../types/EntityFiltering.js';\nimport type { EntitySorting } from '../types/EntitySorting.js';\nimport { containsFolded } from './fold.js';\n\n/**\n * An {@link EntityLoadRequest}'s filtering and sorting, answered over records\n * held in memory, with the semantics of the Mongo adapter.\n *\n * One implementation for everything that queries records it holds itself — the\n * in-memory test double, the static repository, a published view — so none of\n * them can drift into a more forgiving version of the others. They used to be\n * separate copies, and one of them compared an array member with `===` and so\n * never matched `in` (#34).\n *\n * The rules, each Mongo's:\n * - a link is its target's id, a collection link the list of their ids;\n * - `in` and `nin` against an array match when **any element** does, as `$in`;\n * - a property may be a dotted path into a member holding an object, which is\n * how a filter reaches one locale of a `localized` member (`name.en`);\n * - `like` is a substring match that ignores accents and case — `cafe` finds\n * `Café` — by the one rule in `fold.ts` every adapter derives its form from;\n * - a missing value sorts below a present one, numbers and dates compare as\n * themselves and anything else as text;\n * - every top-level filtering entry is combined with `and`.\n */\n\n/**\n * A member as the Mongo adapter stores it, and so as its queries see it: a\n * link is its target's id, a collection link the list of their ids. Without\n * this no operator can compare a link, since `eq` against an id is never\n * `true` for an object.\n */\nexport function storedValue(value: unknown): unknown {\n if (value instanceof EntityLink) return value.id;\n if (value instanceof EntityCollectionLink) return value.ids;\n return value;\n}\n\n/**\n * The value a property names: a member, or a dotted path into one. A path\n * through something that is not an object ends in `undefined`, as a missing\n * field does in Mongo.\n */\nexport function valueAt(record: object, property: string): unknown {\n const [member, ...path] = property.split('.');\n return path.reduce<unknown>(\n (value, key) =>\n typeof value === 'object' && value !== null\n ? (value as Record<string, unknown>)[key]\n : undefined,\n storedValue((record as Record<string, unknown>)[member as string]),\n );\n}\n\n/** Ordering with Mongo's rules; `0` for two values it considers equal. */\nexport function compareStoredValues(left: unknown, right: unknown): number {\n if (left === right) return 0;\n // Mongo sorts missing values below present ones.\n if (left == null) return right == null ? 0 : -1;\n if (right == null) return 1;\n if (typeof left === 'number' && typeof right === 'number') {\n return left - right;\n }\n if (left instanceof Date && right instanceof Date) {\n return left.getTime() - right.getTime();\n }\n return String(left).localeCompare(String(right));\n}\n\n/** Equality by value, so two `Date`s naming one instant are equal. */\nconst isEqual = (actual: unknown, value: unknown): boolean =>\n actual instanceof Date && value instanceof Date\n ? actual.getTime() === value.getTime()\n : actual === value;\n\n/** `$in` semantics: a scalar matches a value, an array when any element does. */\nconst matchesAny = (actual: unknown, values: readonly unknown[]): boolean => {\n const matches = (element: unknown) =>\n values.some(value => isEqual(element, value));\n return Array.isArray(actual) ? actual.some(matches) : matches(actual);\n};\n\n/** `like`: a substring match with accents and case folded off (`fold.ts`). */\nconst matchesLike = (actual: unknown, value: string): boolean =>\n actual != null && containsFolded(String(actual), value);\n\nconst isFilterGroup = <TEntity extends Entity>(\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): node is FilterGroup<TEntity> =>\n !('property' in node) && (node.operator === 'and' || node.operator === 'or');\n\nconst isBetween = (actual: unknown, start: unknown, end: unknown) =>\n actual != null &&\n compareStoredValues(actual, start) >= 0 &&\n compareStoredValues(actual, end) <= 0;\n\n/**\n * The values a dotted path reaches **through an array** — every element's\n * member — or `undefined` when the path crosses no array, so the caller reads\n * the single value as before.\n */\nfunction valuesThroughArray(\n record: object,\n property: string,\n): unknown[] | undefined {\n const dot = property.indexOf('.');\n if (dot === -1) return undefined;\n const elements = storedValue(\n (record as Record<string, unknown>)[property.slice(0, dot)],\n );\n if (!Array.isArray(elements)) return undefined;\n const member = property.slice(dot + 1);\n return elements.map(element =>\n typeof element === 'object' && element !== null\n ? valueAt(element as object, member)\n : undefined,\n );\n}\n\n/**\n * Splits a filter into its positive test and whether the operator negates it,\n * so a path into an array can ask \"any element\" of the positive form and\n * negate the answer — never \"any element is not equal\", which almost always\n * holds.\n */\nfunction positiveTest<TEntity extends Entity>(\n filter: EntityFilter<TEntity>,\n): { readonly test: (actual: unknown) => boolean; readonly negated: boolean } {\n switch (filter.operator) {\n case 'eq':\n case 'ne':\n return {\n test: actual => isEqual(actual, filter.value),\n negated: filter.operator === 'ne',\n };\n case 'gt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) > 0,\n negated: false,\n };\n case 'gte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) >= 0,\n negated: false,\n };\n case 'lt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) < 0,\n negated: false,\n };\n case 'lte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) <= 0,\n negated: false,\n };\n case 'in':\n case 'nin':\n return {\n test: actual => matchesAny(actual, filter.values),\n negated: filter.operator === 'nin',\n };\n case 'between':\n case 'nbetween':\n return {\n test: actual => isBetween(actual, filter.start, filter.end),\n negated: filter.operator === 'nbetween',\n };\n case 'like':\n case 'nlike':\n return {\n test: actual => matchesLike(actual, filter.value),\n negated: filter.operator === 'nlike',\n };\n case 'isNull':\n case 'isNotNull':\n return {\n test: actual => actual != null,\n negated: filter.operator === 'isNull',\n };\n default: {\n // Exhaustiveness guard — a new operator must be handled explicitly.\n const never: never = filter;\n throw new EntifixBuildError(\n `Unknown filter operator \"${String((never as { operator: unknown }).operator)}\"`,\n );\n }\n }\n}\n\nfunction matchesFilter<TEntity extends Entity>(\n record: TEntity,\n filter: EntityFilter<TEntity>,\n): boolean {\n const { test, negated } = positiveTest(filter);\n const property = String(filter.property);\n const elements = valuesThroughArray(record, property);\n const holds =\n elements === undefined\n ? test(valueAt(record, property))\n : elements.some(test);\n return negated ? !holds : holds;\n}\n\nfunction matchesNode<TEntity extends Entity>(\n record: TEntity,\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): boolean {\n if (!isFilterGroup(node)) return matchesFilter(record, node);\n return node.operator === 'or'\n ? node.values.some(child => matchesNode(record, child))\n : node.values.every(child => matchesNode(record, child));\n}\n\n/** Whether one record matches a request's filtering. */\nexport function matchesFiltering<TEntity extends Entity>(\n record: TEntity,\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): boolean {\n return (filtering ?? []).every(entry =>\n Array.isArray(entry)\n ? entry.every(child => matchesNode(record, child))\n : matchesNode(record, entry),\n );\n}\n\n/** The records a request's filtering keeps, in the order they were given. */\nexport function applyFiltering<TEntity extends Entity>(\n records: readonly TEntity[],\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): TEntity[] {\n return records.filter(record => matchesFiltering(record, filtering));\n}\n\n/**\n * The records in the order a request asks for, as a new array. `EntitySorting`\n * is a record keyed by priority rather than a list, so two keys cannot tie by\n * accident. No key leaves the order the records were given in.\n */\nexport function applySorting<TEntity extends Entity>(\n records: readonly TEntity[],\n sorting: readonly EntitySorting<TEntity>[] | undefined,\n): TEntity[] {\n const keys = (sorting ?? []).flatMap(entry =>\n Object.keys(entry)\n .map(Number)\n .sort((left, right) => left - right)\n .map(priority => entry[priority])\n .filter(key => key != null),\n );\n if (keys.length === 0) return [...records];\n\n return [...records].sort((left, right) => {\n for (const key of keys) {\n const property = String(key.property);\n const compared = compareStoredValues(\n valueAt(left, property),\n valueAt(right, property),\n );\n if (compared !== 0) return key.type === 'desc' ? -compared : compared;\n }\n return 0;\n });\n}\n\nconst isFacetValue = (value: unknown): value is EntityFacetValue['value'] =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean';\n\n/** Count first, highest first; a tie by value, so the order is stable. */\nconst byCountThenValue = (left: EntityFacetValue, right: EntityFacetValue) =>\n right.count - left.count || compareStoredValues(left.value, right.value);\n\n/**\n * How many records hold each value of each queried member, each member counted\n * over the records **its own** filtering keeps — the in-memory form of a Mongo\n * `$facet` of `$match`, `$unwind` and `$group`, with its rules:\n * - an array member counts each element, as `$unwind` does;\n * - a missing or `null` value, or an empty array, is not counted;\n * - only a string, number or boolean is a value; anything else is skipped.\n */\nexport function countFacets<TEntity extends Entity>(\n records: readonly TEntity[],\n queries: readonly EntityFacetQuery<TEntity>[],\n): EntityFacetCounts {\n const counts: Record<string, readonly EntityFacetValue[]> = {};\n for (const { member, filtering } of queries) {\n const tally = new Map<EntityFacetValue['value'], number>();\n for (const record of applyFiltering(records, filtering)) {\n const stored = valueAt(record, member);\n for (const value of Array.isArray(stored) ? stored : [stored]) {\n if (isFacetValue(value)) tally.set(value, (tally.get(value) ?? 0) + 1);\n }\n }\n counts[member] = Array.from(tally, ([value, count]) => ({\n value,\n count,\n })).sort(byCountThenValue);\n }\n return counts;\n}\n"],"names":["EntifixBuildError","EntityCollectionLink","EntityLink","containsFolded","storedValue","value","id","ids","valueAt","record","property","member","path","split","reduce","key","undefined","compareStoredValues","left","right","Date","getTime","String","localeCompare","isEqual","actual","matchesAny","values","matches","element","some","Array","isArray","matchesLike","isFilterGroup","node","operator","isBetween","start","end","valuesThroughArray","dot","indexOf","elements","slice","map","positiveTest","filter","test","negated","never","matchesFilter","holds","matchesNode","child","every","matchesFiltering","filtering","entry","applyFiltering","records","applySorting","sorting","keys","flatMap","Object","Number","sort","priority","length","compared","type","isFacetValue","byCountThenValue","count","countFacets","queries","counts","tally","Map","stored","set","get","from"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAC5E,SAASC,oBAAoB,QAAQ,6DAA6D;AAClG,SAASC,UAAU,QAAQ,kDAAkD;AAa7E,SAASC,cAAc,QAAQ,YAAY;AAE3C;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;;CAKC,GACD,OAAO,SAASC,YAAYC,KAAc;IACxC,IAAIA,iBAAiBH,YAAY,OAAOG,MAAMC,EAAE;IAChD,IAAID,iBAAiBJ,sBAAsB,OAAOI,MAAME,GAAG;IAC3D,OAAOF;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,QAAQC,MAAc,EAAEC,QAAgB;IACtD,MAAM,CAACC,QAAQ,GAAGC,KAAK,GAAGF,SAASG,KAAK,CAAC;IACzC,OAAOD,KAAKE,MAAM,CAChB,CAACT,OAAOU,MACN,OAAOV,UAAU,YAAYA,UAAU,OACnC,AAACA,KAAiC,CAACU,IAAI,GACvCC,WACNZ,YAAY,AAACK,MAAkC,CAACE,OAAiB;AAErE;AAEA,wEAAwE,GACxE,OAAO,SAASM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,SAAsD,CAAC;IAC7D,KAAK,MAAM,EAAElE,MAAM,EAAE8C,SAAS,EAAE,IAAImB,QAAS;QAC3C,MAAME,QAAQ,IAAIC;QAClB,KAAK,MAAMtE,UAAUkD,eAAeC,SAASH,WAAY;YACvD,MAAMuB,SAASxE,QAAQC,QAAQE;YAC/B,KAAK,MAAMN,SAAS0B,MAAMC,OAAO,CAACgD,UAAUA,SAAS;gBAACA;aAAO,CAAE;oBAClBF;gBAA3C,IAAIN,aAAanE,QAAQyE,MAAMG,GAAG,CAAC5E,OAAO,EAACyE,aAAAA,MAAMI,GAAG,CAAC7E,kBAAVyE,aAAoB,KAAK;YACtE;QACF;QACAD,MAAM,CAAClE,OAAO,GAAGoB,MAAMoD,IAAI,CAACL,OAAO,CAAC,CAACzE,OAAOqE,MAAM,GAAM,CAAA;gBACtDrE;gBACAqE;YACF,CAAA,GAAIP,IAAI,CAACM;IACX;IACA,OAAOI;AACT"}
1
+ {"version":3,"sources":["../../src/query/in-memory-query.ts"],"sourcesContent":["import { EntityCollectionLink } from '../entity-definition/links/entity-collection-link/index.js';\nimport { EntityLink } from '../entity-definition/links/entity-link/index.js';\nimport type { Entity } from '../types/Entity.js';\nimport type {\n EntityFacetCounts,\n EntityFacetQuery,\n EntityFacetValue,\n} from '../types/EntityFacets.js';\nimport type {\n EntityFilter,\n EntityFiltering,\n FilterGroup,\n} from '../types/EntityFiltering.js';\nimport type { EntitySorting } from '../types/EntitySorting.js';\nimport { containsFolded } from './fold.js';\n\n/**\n * An {@link EntityLoadRequest}'s filtering and sorting, answered over records\n * held in memory, with the semantics of the Mongo adapter.\n *\n * One implementation for everything that queries records it holds itself — the\n * in-memory test double, the static repository, a published view — so none of\n * them can drift into a more forgiving version of the others. They used to be\n * separate copies, and one of them compared an array member with `===` and so\n * never matched `in` (#34).\n *\n * The rules, each Mongo's:\n * - a link is its target's id, a collection link the list of their ids;\n * - `in` and `nin` against an array match when **any element** does, as `$in`;\n * - a property may be a dotted path into a member holding an object, which is\n * how a filter reaches one locale of a `localized` member (`name.en`);\n * - `like` is a substring match that ignores accents and case — `cafe` finds\n * `Café` — by the one rule in `fold.ts` every adapter derives its form from;\n * - a missing value sorts below a present one, numbers and dates compare as\n * themselves and anything else as text;\n * - every top-level filtering entry is combined with `and`.\n */\n\n/**\n * A member as the Mongo adapter stores it, and so as its queries see it: a\n * link is its target's id, a collection link the list of their ids. Without\n * this no operator can compare a link, since `eq` against an id is never\n * `true` for an object.\n */\nexport function storedValue(value: unknown): unknown {\n if (value instanceof EntityLink) return value.id;\n if (value instanceof EntityCollectionLink) return value.ids;\n return value;\n}\n\n/**\n * The value a property names: a member, or a dotted path into one. A path\n * through something that is not an object ends in `undefined`, as a missing\n * field does in Mongo.\n */\nexport function valueAt(record: object, property: string): unknown {\n const [member, ...path] = property.split('.');\n return path.reduce<unknown>(\n (value, key) =>\n typeof value === 'object' && value !== null\n ? (value as Record<string, unknown>)[key]\n : undefined,\n storedValue((record as Record<string, unknown>)[member as string]),\n );\n}\n\n/** Ordering with Mongo's rules; `0` for two values it considers equal. */\nexport function compareStoredValues(left: unknown, right: unknown): number {\n if (left === right) return 0;\n // Mongo sorts missing values below present ones.\n if (left == null) return right == null ? 0 : -1;\n if (right == null) return 1;\n if (typeof left === 'number' && typeof right === 'number') {\n return left - right;\n }\n if (left instanceof Date && right instanceof Date) {\n return left.getTime() - right.getTime();\n }\n return String(left).localeCompare(String(right));\n}\n\n/** Equality by value, so two `Date`s naming one instant are equal. */\nconst isEqual = (actual: unknown, value: unknown): boolean =>\n actual instanceof Date && value instanceof Date\n ? actual.getTime() === value.getTime()\n : actual === value;\n\n/** `$in` semantics: a scalar matches a value, an array when any element does. */\nconst matchesAny = (actual: unknown, values: readonly unknown[]): boolean => {\n const matches = (element: unknown) =>\n values.some(value => isEqual(element, value));\n return Array.isArray(actual) ? actual.some(matches) : matches(actual);\n};\n\n/** `like`: a substring match with accents and case folded off (`fold.ts`). */\nconst matchesLike = (actual: unknown, value: string): boolean =>\n actual != null && containsFolded(String(actual), value);\n\nconst isFilterGroup = <TEntity extends Entity>(\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): node is FilterGroup<TEntity> =>\n !('property' in node) && (node.operator === 'and' || node.operator === 'or');\n\nconst isBetween = (actual: unknown, start: unknown, end: unknown) =>\n actual != null &&\n compareStoredValues(actual, start) >= 0 &&\n compareStoredValues(actual, end) <= 0;\n\n/**\n * The values a dotted path reaches **through an array** — every element's\n * member — or `undefined` when the path crosses no array, so the caller reads\n * the single value as before.\n */\nfunction valuesThroughArray(\n record: object,\n property: string,\n): unknown[] | undefined {\n const dot = property.indexOf('.');\n if (dot === -1) return undefined;\n const elements = storedValue(\n (record as Record<string, unknown>)[property.slice(0, dot)],\n );\n if (!Array.isArray(elements)) return undefined;\n const member = property.slice(dot + 1);\n return elements.map(element =>\n typeof element === 'object' && element !== null\n ? valueAt(element as object, member)\n : undefined,\n );\n}\n\n/**\n * Splits a filter into its positive test and whether the operator negates it,\n * so a path into an array can ask \"any element\" of the positive form and\n * negate the answer — never \"any element is not equal\", which almost always\n * holds.\n */\nfunction positiveTest<TEntity extends Entity>(\n filter: EntityFilter<TEntity>,\n): { readonly test: (actual: unknown) => boolean; readonly negated: boolean } {\n switch (filter.operator) {\n case 'eq':\n case 'ne':\n return {\n test: actual => isEqual(actual, filter.value),\n negated: filter.operator === 'ne',\n };\n case 'gt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) > 0,\n negated: false,\n };\n case 'gte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) >= 0,\n negated: false,\n };\n case 'lt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) < 0,\n negated: false,\n };\n case 'lte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) <= 0,\n negated: false,\n };\n case 'in':\n case 'nin':\n return {\n test: actual => matchesAny(actual, filter.values),\n negated: filter.operator === 'nin',\n };\n case 'between':\n case 'nbetween':\n return {\n test: actual => isBetween(actual, filter.start, filter.end),\n negated: filter.operator === 'nbetween',\n };\n case 'like':\n case 'nlike':\n return {\n test: actual => matchesLike(actual, filter.value),\n negated: filter.operator === 'nlike',\n };\n case 'isNull':\n case 'isNotNull':\n return {\n test: actual => actual != null,\n negated: filter.operator === 'isNull',\n };\n default: {\n // Exhaustiveness guard — a new operator must be handled explicitly.\n const never: never = filter;\n throw new Error(\n `Unknown filter operator \"${String((never as { operator: unknown }).operator)}\"`,\n );\n }\n }\n}\n\nfunction matchesFilter<TEntity extends Entity>(\n record: TEntity,\n filter: EntityFilter<TEntity>,\n): boolean {\n const { test, negated } = positiveTest(filter);\n const property = String(filter.property);\n const elements = valuesThroughArray(record, property);\n const holds =\n elements === undefined\n ? test(valueAt(record, property))\n : elements.some(test);\n return negated ? !holds : holds;\n}\n\nfunction matchesNode<TEntity extends Entity>(\n record: TEntity,\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): boolean {\n if (!isFilterGroup(node)) return matchesFilter(record, node);\n return node.operator === 'or'\n ? node.values.some(child => matchesNode(record, child))\n : node.values.every(child => matchesNode(record, child));\n}\n\n/** Whether one record matches a request's filtering. */\nexport function matchesFiltering<TEntity extends Entity>(\n record: TEntity,\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): boolean {\n return (filtering ?? []).every(entry =>\n Array.isArray(entry)\n ? entry.every(child => matchesNode(record, child))\n : matchesNode(record, entry),\n );\n}\n\n/** The records a request's filtering keeps, in the order they were given. */\nexport function applyFiltering<TEntity extends Entity>(\n records: readonly TEntity[],\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): TEntity[] {\n return records.filter(record => matchesFiltering(record, filtering));\n}\n\n/**\n * The records in the order a request asks for, as a new array. `EntitySorting`\n * is a record keyed by priority rather than a list, so two keys cannot tie by\n * accident. No key leaves the order the records were given in.\n */\nexport function applySorting<TEntity extends Entity>(\n records: readonly TEntity[],\n sorting: readonly EntitySorting<TEntity>[] | undefined,\n): TEntity[] {\n const keys = (sorting ?? []).flatMap(entry =>\n Object.keys(entry)\n .map(Number)\n .sort((left, right) => left - right)\n .map(priority => entry[priority])\n .filter(key => key != null),\n );\n if (keys.length === 0) return [...records];\n\n return [...records].sort((left, right) => {\n for (const key of keys) {\n const property = String(key.property);\n const compared = compareStoredValues(\n valueAt(left, property),\n valueAt(right, property),\n );\n if (compared !== 0) return key.type === 'desc' ? -compared : compared;\n }\n return 0;\n });\n}\n\nconst isFacetValue = (value: unknown): value is EntityFacetValue['value'] =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean';\n\n/** Count first, highest first; a tie by value, so the order is stable. */\nconst byCountThenValue = (left: EntityFacetValue, right: EntityFacetValue) =>\n right.count - left.count || compareStoredValues(left.value, right.value);\n\n/**\n * How many records hold each value of each queried member, each member counted\n * over the records **its own** filtering keeps — the in-memory form of a Mongo\n * `$facet` of `$match`, `$unwind` and `$group`, with its rules:\n * - an array member counts each element, as `$unwind` does;\n * - a missing or `null` value, or an empty array, is not counted;\n * - only a string, number or boolean is a value; anything else is skipped.\n */\nexport function countFacets<TEntity extends Entity>(\n records: readonly TEntity[],\n queries: readonly EntityFacetQuery<TEntity>[],\n): EntityFacetCounts {\n const counts: Record<string, readonly EntityFacetValue[]> = {};\n for (const { member, filtering } of queries) {\n const tally = new Map<EntityFacetValue['value'], number>();\n for (const record of applyFiltering(records, filtering)) {\n const stored = valueAt(record, member);\n for (const value of Array.isArray(stored) ? stored : [stored]) {\n if (isFacetValue(value)) tally.set(value, (tally.get(value) ?? 0) + 1);\n }\n }\n counts[member] = Array.from(tally, ([value, count]) => ({\n value,\n count,\n })).sort(byCountThenValue);\n }\n return counts;\n}\n"],"names":["EntityCollectionLink","EntityLink","containsFolded","storedValue","value","id","ids","valueAt","record","property","member","path","split","reduce","key","undefined","compareStoredValues","left","right","Date","getTime","String","localeCompare","isEqual","actual","matchesAny","values","matches","element","some","Array","isArray","matchesLike","isFilterGroup","node","operator","isBetween","start","end","valuesThroughArray","dot","indexOf","elements","slice","map","positiveTest","filter","test","negated","never","Error","matchesFilter","holds","matchesNode","child","every","matchesFiltering","filtering","entry","applyFiltering","records","applySorting","sorting","keys","flatMap","Object","Number","sort","priority","length","compared","type","isFacetValue","byCountThenValue","count","countFacets","queries","counts","tally","Map","stored","set","get","from"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,6DAA6D;AAClG,SAASC,UAAU,QAAQ,kDAAkD;AAa7E,SAASC,cAAc,QAAQ,YAAY;AAE3C;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;;CAKC,GACD,OAAO,SAASC,YAAYC,KAAc;IACxC,IAAIA,iBAAiBH,YAAY,OAAOG,MAAMC,EAAE;IAChD,IAAID,iBAAiBJ,sBAAsB,OAAOI,MAAME,GAAG;IAC3D,OAAOF;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,QAAQC,MAAc,EAAEC,QAAgB;IACtD,MAAM,CAACC,QAAQ,GAAGC,KAAK,GAAGF,SAASG,KAAK,CAAC;IACzC,OAAOD,KAAKE,MAAM,CAChB,CAACT,OAAOU,MACN,OAAOV,UAAU,YAAYA,UAAU,OACnC,AAACA,KAAiC,CAACU,IAAI,GACvCC,WACNZ,YAAY,AAACK,MAAkC,CAACE,OAAiB;AAErE;AAEA,wEAAwE,GACxE,OAAO,SAASM,oBAAoBC,IAAa,EAAEC,KAAc;IAC/D,IAAID,SAASC,OAAO,OAAO;IAC3B,iDAAiD;IACjD,IAAID,QAAQ,MAAM,OAAOC,SAAS,OAAO,IAAI,CAAC;IAC9C,IAAIA,SAAS,MAAM,OAAO;IAC1B,IAAI,OAAOD,SAAS,YAAY,OAAOC,UAAU,UAAU;QACzD,OAAOD,OAAOC;IAChB;IACA,IAAID,gBAAgBE,QAAQD,iBAAiBC,MAAM;QACjD,OAAOF,KAAKG,OAAO,KAAKF,MAAME,OAAO;IACvC;IACA,OAAOC,OAAOJ,MAAMK,aAAa,CAACD,OAAOH;AAC3C;AAEA,oEAAoE,GACpE,MAA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,MAAM,CAACnE,OAAO,GAAGoB,MAAMqD,IAAI,CAACL,OAAO,CAAC,CAAC1E,OAAOsE,MAAM,GAAM,CAAA;gBACtDtE;gBACAsE;YACF,CAAA,GAAIP,IAAI,CAACM;IACX;IACA,OAAOI;AACT"}
@@ -41,7 +41,7 @@ export declare function resolveAllowedProperty(allowed: Map<string, EntityFieldD
41
41
  * This is the trust boundary of the query protocol. Everything before it is a
42
42
  * string a client chose; everything after it names only members the entity
43
43
  * declared `filterable` and carries only values of those members' declared
44
- * types. A violation throws {@link EntifixBuildError}, which services already
44
+ * types. A violation throws an `Error`, which services already
45
45
  * map to a `400`.
46
46
  */
47
47
  export declare function coerceFiltering<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, parsed: RawFilterGroup): FilterGroup<TEntity>;
@@ -1 +1 @@
1
- {"version":3,"file":"coerce-rsql.d.ts","sourceRoot":"","sources":["../../src/rsql/coerce-rsql.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,wCAAwC,CAAC;AAEhD,OAAO,EAAY,KAAK,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,EAGL,KAAK,cAAc,EACpB,MAAM,iBAAiB,CAAC;AAEzB;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,CAAC,UAAU,EAAE,qBAAqB,KAAK,OAAO,GACrD,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAQpC;AAKD,uDAAuD;AACvD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C;;;OAGG;IACH,QAA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qD;IACrD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,EAC3C,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,YAAY,GAAG,UAAU,GACrC,eAAe,CAuBjB;AA2FD;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,MAAM,EACpD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,cAAc,GACrB,WAAW,CAAC,OAAO,CAAC,CAUtB"}
@@ -1,4 +1,3 @@
1
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
2
1
  import { describeEntityColumns } from '../entity-definition/describe/index.js';
3
2
  import { isLocale } from '../i18n/locales.js';
4
3
  import { isRawFilter } from './parse-rsql.js';
@@ -19,7 +18,7 @@ import { isRawFilter } from './parse-rsql.js';
19
18
  }
20
19
  return allowed;
21
20
  }
22
- const reject = (message, details)=>new EntifixBuildError(message, undefined, details);
21
+ const reject = (message, details)=>new Error(message);
23
22
  /**
24
23
  * Resolves the property a filter or a sort names, or rejects it.
25
24
  *
@@ -144,7 +143,7 @@ function coerceNode(node, allowed) {
144
143
  * This is the trust boundary of the query protocol. Everything before it is a
145
144
  * string a client chose; everything after it names only members the entity
146
145
  * declared `filterable` and carries only values of those members' declared
147
- * types. A violation throws {@link EntifixBuildError}, which services already
146
+ * types. A violation throws an `Error`, which services already
148
147
  * map to a `400`.
149
148
  */ export function coerceFiltering(entityConstructor, parsed) {
150
149
  const allowed = allowedDescriptors(entityConstructor, (descriptor)=>descriptor.filterable);