@entifix/core 0.13.0 → 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/rsql/coerce-rsql.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport {\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from '../entity-definition/describe/index.js';\nimport type { MetaAccessorType } from '../entity-definition/meta-entities/meta-accessor/index.js';\nimport { isLocale, type Locale } from '../i18n/locales.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFilter, FilterGroup } from '../types/EntityFiltering.js';\nimport {\n isRawFilter,\n type RawFilter,\n type RawFilterGroup,\n} from './parse-rsql.js';\n\n/**\n * Resolves the members a client is allowed to name, keyed by both the accessor\n * name and its wire key so a URL may use either.\n *\n * `select` is what makes this an allowlist rather than a lookup: a member the\n * entity did not mark `filterable`/`sortable` is simply not in the map, and a\n * request naming it is rejected. That is the guard against a client filtering\n * on a `hidden` member or an unindexed one.\n */\nexport function allowedDescriptors<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n select: (descriptor: EntityFieldDescriptor) => boolean,\n): Map<string, EntityFieldDescriptor> {\n const allowed = new Map<string, EntityFieldDescriptor>();\n for (const descriptor of describeEntityColumns(entityConstructor)) {\n if (!select(descriptor)) continue;\n allowed.set(descriptor.name, descriptor);\n allowed.set(descriptor.key, descriptor);\n }\n return allowed;\n}\n\nconst reject = (message: string, details?: Record<string, unknown>) =>\n new EntifixBuildError(message, undefined, details);\n\n/** A query property resolved against the allowlist. */\nexport interface AllowedProperty {\n readonly descriptor: EntityFieldDescriptor;\n /**\n * What an adapter names: the member's wire key, or for a `localized` member\n * the path to one locale's text (`title.en`).\n */\n readonly key: string;\n /** The locale a `localized` member is queried in. */\n readonly locale?: Locale;\n}\n\n/**\n * Resolves the property a filter or a sort names, or rejects it.\n *\n * A `localized` member is the one that takes a path: it holds an object, and\n * comparing an object as text matches nothing, so it is only ever queried\n * through one locale — `title.en` — and that locale must be one the host\n * declared. The bare member is rejected with a message that says so.\n */\nexport function resolveAllowedProperty(\n allowed: Map<string, EntityFieldDescriptor>,\n property: string,\n requirement: 'filterable' | 'sortable',\n): AllowedProperty {\n const direct = allowed.get(property);\n if (direct !== undefined) {\n if (direct.type === 'localized') {\n throw reject(\n `\"${property}\" is localized; name one locale, as \"${property}.<locale>\"`,\n { property },\n );\n }\n return { descriptor: direct, key: direct.key };\n }\n\n const dot = property.indexOf('.');\n const descriptor =\n dot === -1 ? undefined : allowed.get(property.slice(0, dot));\n if (descriptor?.type !== 'localized') {\n throw reject(`\"${property}\" is not a ${requirement} member`, { property });\n }\n const locale = property.slice(dot + 1);\n if (!isLocale(locale)) {\n throw reject(`\"${locale}\" is not a declared locale`, { property });\n }\n return { descriptor, key: `${descriptor.key}.${locale}`, locale };\n}\n\n/** Re-types one raw argument from the member's declared type. */\nfunction coerceValue(raw: string, descriptor: EntityFieldDescriptor): unknown {\n switch (descriptor.type as MetaAccessorType) {\n case 'number': {\n const value = Number(raw);\n if (raw.trim() === '' || Number.isNaN(value)) {\n throw reject(`\"${raw}\" is not a number for \"${descriptor.name}\"`);\n }\n return value;\n }\n case 'boolean': {\n if (raw !== 'true' && raw !== 'false') {\n throw reject(`\"${raw}\" is not a boolean for \"${descriptor.name}\"`);\n }\n return raw === 'true';\n }\n case 'date': {\n const value = new Date(raw);\n if (Number.isNaN(value.getTime())) {\n throw reject(`\"${raw}\" is not a date for \"${descriptor.name}\"`);\n }\n return value;\n }\n case 'enum': {\n if (descriptor.enumValues && !descriptor.enumValues.includes(raw)) {\n throw reject(`\"${raw}\" is not a value of \"${descriptor.name}\"`);\n }\n return raw;\n }\n default:\n return raw;\n }\n}\n\nfunction coerceFilter<TEntity extends Entity>(\n raw: RawFilter,\n allowed: Map<string, EntityFieldDescriptor>,\n): EntityFilter<TEntity> {\n const { descriptor, key } = resolveAllowedProperty(\n allowed,\n raw.property,\n 'filterable',\n );\n\n // The wire key is also the stored field name, so this is what the Mongo\n // translator downstream will use — dotted into one locale for a localized\n // member, which Mongo reads as a path natively.\n const property = key as keyof TEntity;\n const coerce = (value: string) => coerceValue(value, descriptor);\n\n if (raw.values) {\n return {\n property,\n operator: raw.operator,\n values: raw.values.map(coerce),\n } as EntityFilter<TEntity>;\n }\n if (raw.start !== undefined && raw.end !== undefined) {\n return {\n property,\n operator: raw.operator,\n start: coerce(raw.start),\n end: coerce(raw.end),\n } as EntityFilter<TEntity>;\n }\n if (raw.value !== undefined) {\n return {\n property,\n operator: raw.operator,\n value: coerce(raw.value),\n } as EntityFilter<TEntity>;\n }\n\n // `isNull`/`isNotNull` — no argument to coerce.\n return { property, operator: raw.operator } as EntityFilter<TEntity>;\n}\n\nfunction coerceNode<TEntity extends Entity>(\n node: RawFilter | RawFilterGroup,\n allowed: Map<string, EntityFieldDescriptor>,\n): EntityFilter<TEntity> | FilterGroup<TEntity> {\n return isRawFilter(node)\n ? coerceFilter<TEntity>(node, allowed)\n : {\n operator: node.operator,\n values: node.values.map(child => coerceNode<TEntity>(child, allowed)),\n };\n}\n\n/**\n * Turns a parsed, untyped RSQL tree into a typed {@link FilterGroup} the\n * repositories can execute, validating it against the entity's metadata on the\n * way through.\n *\n * This is the trust boundary of the query protocol. Everything before it is a\n * string a client chose; everything after it names only members the entity\n * declared `filterable` and carries only values of those members' declared\n * types. A violation throws {@link EntifixBuildError}, which services already\n * map to a `400`.\n */\nexport function coerceFiltering<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n parsed: RawFilterGroup,\n): FilterGroup<TEntity> {\n const allowed = allowedDescriptors(\n entityConstructor,\n descriptor => descriptor.filterable,\n );\n\n return {\n operator: parsed.operator,\n values: parsed.values.map(node => coerceNode<TEntity>(node, allowed)),\n };\n}\n"],"names":["EntifixBuildError","describeEntityColumns","isLocale","isRawFilter","allowedDescriptors","entityConstructor","select","allowed","Map","descriptor","set","name","key","reject","message","details","undefined","resolveAllowedProperty","property","requirement","direct","get","type","dot","indexOf","slice","locale","coerceValue","raw","value","Number","trim","isNaN","Date","getTime","enumValues","includes","coerceFilter","coerce","values","operator","map","start","end","coerceNode","node","child","coerceFiltering","parsed","filterable"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAC5E,SACEC,qBAAqB,QAEhB,yCAAyC;AAEhD,SAASC,QAAQ,QAAqB,qBAAqB;AAG3D,SACEC,WAAW,QAGN,kBAAkB;AAEzB;;;;;;;;CAQC,GACD,OAAO,SAASC,mBACdC,iBAA6C,EAC7CC,MAAsD;IAEtD,MAAMC,UAAU,IAAIC;IACpB,KAAK,MAAMC,cAAcR,sBAAsBI,mBAAoB;QACjE,IAAI,CAACC,OAAOG,aAAa;QACzBF,QAAQG,GAAG,CAACD,WAAWE,IAAI,EAAEF;QAC7BF,QAAQG,GAAG,CAACD,WAAWG,GAAG,EAAEH;IAC9B;IACA,OAAOF;AACT;AAEA,MAAMM,SAAS,CAACC,SAAiBC,UAC/B,IAAIf,kBAAkBc,SAASE,WAAWD;AAc5C;;;;;;;CAOC,GAC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b,WAAW;QAC3B,OAAO;YACLE;YACAsB,UAAUZ,IAAIY,QAAQ;YACtBX,OAAOS,OAAOV,IAAIC,KAAK;QACzB;IACF;IAEA,gDAAgD;IAChD,OAAO;QAAEX;QAAUsB,UAAUZ,IAAIY,QAAQ;IAAC;AAC5C;AAEA,SAASI,WACPC,IAAgC,EAChCtC,OAA2C;IAE3C,OAAOJ,YAAY0C,QACfR,aAAsBQ,MAAMtC,WAC5B;QACEiC,UAAUK,KAAKL,QAAQ;QACvBD,QAAQM,KAAKN,MAAM,CAACE,GAAG,CAACK,CAAAA,QAASF,WAAoBE,OAAOvC;IAC9D;AACN;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASwC,gBACd1C,iBAA6C,EAC7C2C,MAAsB;IAEtB,MAAMzC,UAAUH,mBACdC,mBACAI,CAAAA,aAAcA,WAAWwC,UAAU;IAGrC,OAAO;QACLT,UAAUQ,OAAOR,QAAQ;QACzBD,QAAQS,OAAOT,MAAM,CAACE,GAAG,CAACI,CAAAA,OAAQD,WAAoBC,MAAMtC;IAC9D;AACF"}
1
+ {"version":3,"sources":["../../src/rsql/coerce-rsql.ts"],"sourcesContent":["import {\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from '../entity-definition/describe/index.js';\nimport type { MetaAccessorType } from '../entity-definition/meta-entities/meta-accessor/index.js';\nimport { isLocale, type Locale } from '../i18n/locales.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFilter, FilterGroup } from '../types/EntityFiltering.js';\nimport {\n isRawFilter,\n type RawFilter,\n type RawFilterGroup,\n} from './parse-rsql.js';\n\n/**\n * Resolves the members a client is allowed to name, keyed by both the accessor\n * name and its wire key so a URL may use either.\n *\n * `select` is what makes this an allowlist rather than a lookup: a member the\n * entity did not mark `filterable`/`sortable` is simply not in the map, and a\n * request naming it is rejected. That is the guard against a client filtering\n * on a `hidden` member or an unindexed one.\n */\nexport function allowedDescriptors<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n select: (descriptor: EntityFieldDescriptor) => boolean,\n): Map<string, EntityFieldDescriptor> {\n const allowed = new Map<string, EntityFieldDescriptor>();\n for (const descriptor of describeEntityColumns(entityConstructor)) {\n if (!select(descriptor)) continue;\n allowed.set(descriptor.name, descriptor);\n allowed.set(descriptor.key, descriptor);\n }\n return allowed;\n}\n\nconst reject = (message: string, details?: Record<string, unknown>) =>\n new Error(message);\n\n/** A query property resolved against the allowlist. */\nexport interface AllowedProperty {\n readonly descriptor: EntityFieldDescriptor;\n /**\n * What an adapter names: the member's wire key, or for a `localized` member\n * the path to one locale's text (`title.en`).\n */\n readonly key: string;\n /** The locale a `localized` member is queried in. */\n readonly locale?: Locale;\n}\n\n/**\n * Resolves the property a filter or a sort names, or rejects it.\n *\n * A `localized` member is the one that takes a path: it holds an object, and\n * comparing an object as text matches nothing, so it is only ever queried\n * through one locale — `title.en` — and that locale must be one the host\n * declared. The bare member is rejected with a message that says so.\n */\nexport function resolveAllowedProperty(\n allowed: Map<string, EntityFieldDescriptor>,\n property: string,\n requirement: 'filterable' | 'sortable',\n): AllowedProperty {\n const direct = allowed.get(property);\n if (direct !== undefined) {\n if (direct.type === 'localized') {\n throw reject(\n `\"${property}\" is localized; name one locale, as \"${property}.<locale>\"`,\n { property },\n );\n }\n return { descriptor: direct, key: direct.key };\n }\n\n const dot = property.indexOf('.');\n const descriptor =\n dot === -1 ? undefined : allowed.get(property.slice(0, dot));\n if (descriptor?.type !== 'localized') {\n throw reject(`\"${property}\" is not a ${requirement} member`, { property });\n }\n const locale = property.slice(dot + 1);\n if (!isLocale(locale)) {\n throw reject(`\"${locale}\" is not a declared locale`, { property });\n }\n return { descriptor, key: `${descriptor.key}.${locale}`, locale };\n}\n\n/** Re-types one raw argument from the member's declared type. */\nfunction coerceValue(raw: string, descriptor: EntityFieldDescriptor): unknown {\n switch (descriptor.type as MetaAccessorType) {\n case 'number': {\n const value = Number(raw);\n if (raw.trim() === '' || Number.isNaN(value)) {\n throw reject(`\"${raw}\" is not a number for \"${descriptor.name}\"`);\n }\n return value;\n }\n case 'boolean': {\n if (raw !== 'true' && raw !== 'false') {\n throw reject(`\"${raw}\" is not a boolean for \"${descriptor.name}\"`);\n }\n return raw === 'true';\n }\n case 'date': {\n const value = new Date(raw);\n if (Number.isNaN(value.getTime())) {\n throw reject(`\"${raw}\" is not a date for \"${descriptor.name}\"`);\n }\n return value;\n }\n case 'enum': {\n if (descriptor.enumValues && !descriptor.enumValues.includes(raw)) {\n throw reject(`\"${raw}\" is not a value of \"${descriptor.name}\"`);\n }\n return raw;\n }\n default:\n return raw;\n }\n}\n\nfunction coerceFilter<TEntity extends Entity>(\n raw: RawFilter,\n allowed: Map<string, EntityFieldDescriptor>,\n): EntityFilter<TEntity> {\n const { descriptor, key } = resolveAllowedProperty(\n allowed,\n raw.property,\n 'filterable',\n );\n\n // The wire key is also the stored field name, so this is what the Mongo\n // translator downstream will use — dotted into one locale for a localized\n // member, which Mongo reads as a path natively.\n const property = key as keyof TEntity;\n const coerce = (value: string) => coerceValue(value, descriptor);\n\n if (raw.values) {\n return {\n property,\n operator: raw.operator,\n values: raw.values.map(coerce),\n } as EntityFilter<TEntity>;\n }\n if (raw.start !== undefined && raw.end !== undefined) {\n return {\n property,\n operator: raw.operator,\n start: coerce(raw.start),\n end: coerce(raw.end),\n } as EntityFilter<TEntity>;\n }\n if (raw.value !== undefined) {\n return {\n property,\n operator: raw.operator,\n value: coerce(raw.value),\n } as EntityFilter<TEntity>;\n }\n\n // `isNull`/`isNotNull` — no argument to coerce.\n return { property, operator: raw.operator } as EntityFilter<TEntity>;\n}\n\nfunction coerceNode<TEntity extends Entity>(\n node: RawFilter | RawFilterGroup,\n allowed: Map<string, EntityFieldDescriptor>,\n): EntityFilter<TEntity> | FilterGroup<TEntity> {\n return isRawFilter(node)\n ? coerceFilter<TEntity>(node, allowed)\n : {\n operator: node.operator,\n values: node.values.map(child => coerceNode<TEntity>(child, allowed)),\n };\n}\n\n/**\n * Turns a parsed, untyped RSQL tree into a typed {@link FilterGroup} the\n * repositories can execute, validating it against the entity's metadata on the\n * way through.\n *\n * This is the trust boundary of the query protocol. Everything before it is a\n * string a client chose; everything after it names only members the entity\n * declared `filterable` and carries only values of those members' declared\n * types. A violation throws an `Error`, which services already\n * map to a `400`.\n */\nexport function coerceFiltering<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n parsed: RawFilterGroup,\n): FilterGroup<TEntity> {\n const allowed = allowedDescriptors(\n entityConstructor,\n descriptor => descriptor.filterable,\n );\n\n return {\n operator: parsed.operator,\n values: parsed.values.map(node => coerceNode<TEntity>(node, allowed)),\n };\n}\n"],"names":["describeEntityColumns","isLocale","isRawFilter","allowedDescriptors","entityConstructor","select","allowed","Map","descriptor","set","name","key","reject","message","details","Error","resolveAllowedProperty","property","requirement","direct","get","undefined","type","dot","indexOf","slice","locale","coerceValue","raw","value","Number","trim","isNaN","Date","getTime","enumValues","includes","coerceFilter","coerce","values","operator","map","start","end","coerceNode","node","child","coerceFiltering","parsed","filterable"],"mappings":"AAAA,SACEA,qBAAqB,QAEhB,yCAAyC;AAEhD,SAASC,QAAQ,QAAqB,qBAAqB;AAG3D,SACEC,WAAW,QAGN,kBAAkB;AAEzB;;;;;;;;CAQC,GACD,OAAO,SAASC,mBACdC,iBAA6C,EAC7CC,MAAsD;IAEtD,MAAMC,UAAU,IAAIC;IACpB,KAAK,MAAMC,cAAcR,sBAAsBI,mBAAoB;QACjE,IAAI,CAACC,OAAOG,aAAa;QACzBF,QAAQG,GAAG,CAACD,WAAWE,IAAI,EAAEF;QAC7BF,QAAQG,GAAG,CAACD,WAAWG,GAAG,EAAEH;IAC9B;IACA,OAAOF;AACT;AAEA,MAAMM,SAAS,CAACC,SAAiBC,UAC/B,IAAIC,MAAMF;AAcZ;;;;;;;CAOC,GACD,OAAO,SAASG,uBACdV,OAA2C,EAC3CW,QAAgB,EAChBC,WAAsC;IAEtC,MAAMC,SAASb,QAAQc,GAAG,CAACH;IAC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KAAK;QACzB;IACF;IAEA,gDAAgD;IAChD,OAAO;QAAEZ;QAAUuB,UAAUZ,IAAIY,QAAQ;IAAC;AAC5C;AAEA,SAASI,WACPC,IAAgC,EAChCvC,OAA2C;IAE3C,OAAOJ,YAAY2C,QACfR,aAAsBQ,MAAMvC,WAC5B;QACEkC,UAAUK,KAAKL,QAAQ;QACvBD,QAAQM,KAAKN,MAAM,CAACE,GAAG,CAACK,CAAAA,QAASF,WAAoBE,OAAOxC;IAC9D;AACN;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASyC,gBACd3C,iBAA6C,EAC7C4C,MAAsB;IAEtB,MAAM1C,UAAUH,mBACdC,mBACAI,CAAAA,aAAcA,WAAWyC,UAAU;IAGrC,OAAO;QACLT,UAAUQ,OAAOR,QAAQ;QACzBD,QAAQS,OAAOT,MAAM,CAACE,GAAG,CAACI,CAAAA,OAAQD,WAAoBC,MAAMvC;IAC9D;AACF"}
@@ -19,7 +19,7 @@ export declare function serializeFacetQueryParams<TEntity extends Entity>(querie
19
19
  * values a filter would choose between, and counting a member nobody may
20
20
  * filter on would read out values the entity chose not to expose. A
21
21
  * `localized` member is refused, since its value is a record of texts, not one
22
- * to count. Every failure is an {@link EntifixBuildError}, so a `400`.
22
+ * to count. Every failure is a thrown `Error`, so a `400`.
23
23
  */
24
24
  export declare function parseFacetQueryParams<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, params: URLSearchParams): EntityFacetQuery<TEntity>[];
25
25
  //# sourceMappingURL=facet-query-url.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"facet-query-url.d.ts","sourceRoot":"","sources":["../../src/rsql/facet-query-url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAUjE,yEAAyE;AACzE,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MACvB,CAAC;AAE5B;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,SAAS,MAAM,EAC9D,OAAO,EAAE,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAAE,GAC5C,eAAe,CAQjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,eAAe,GACtB,gBAAgB,CAAC,OAAO,CAAC,EAAE,CA6C7B"}
1
+ {"version":3,"file":"facet-query-url.d.ts","sourceRoot":"","sources":["../../src/rsql/facet-query-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAUjE,yEAAyE;AACzE,eAAO,MAAM,WAAW,UAAU,CAAC;AAEnC,wEAAwE;AACxE,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MACvB,CAAC;AAE5B;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,SAAS,MAAM,EAC9D,OAAO,EAAE,SAAS,gBAAgB,CAAC,OAAO,CAAC,EAAE,GAC5C,eAAe,CAQjB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,eAAe,GACtB,gBAAgB,CAAC,OAAO,CAAC,EAAE,CAqC7B"}
@@ -1,5 +1,4 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
3
2
  import { allowedDescriptors, coerceFiltering, resolveAllowedProperty } from './coerce-rsql.js';
4
3
  import { RSQL_PARAM } from './load-request-url.js';
5
4
  import { parseRsql } from './parse-rsql.js';
@@ -28,16 +27,14 @@ import { serializeRsql } from './serialize-rsql.js';
28
27
  * values a filter would choose between, and counting a member nobody may
29
28
  * filter on would read out values the entity chose not to expose. A
30
29
  * `localized` member is refused, since its value is a record of texts, not one
31
- * to count. Every failure is an {@link EntifixBuildError}, so a `400`.
30
+ * to count. Every failure is a thrown `Error`, so a `400`.
32
31
  */ export function parseFacetQueryParams(entityConstructor, params) {
33
32
  const members = params.getAll(FACET_PARAM);
34
33
  if (members.length === 0) {
35
- throw new EntifixBuildError(`name at least one "${FACET_PARAM}"`);
34
+ throw new Error(`name at least one "${FACET_PARAM}"`);
36
35
  }
37
36
  if (new Set(members).size !== members.length) {
38
- throw new EntifixBuildError(`a "${FACET_PARAM}" is named twice`, undefined, {
39
- members
40
- });
37
+ throw new Error(`a "${FACET_PARAM}" is named twice`);
41
38
  }
42
39
  const allowed = allowedDescriptors(entityConstructor, (descriptor)=>descriptor.filterable);
43
40
  return members.map((member)=>{
@@ -45,9 +42,7 @@ import { serializeRsql } from './serialize-rsql.js';
45
42
  if (locale !== undefined) {
46
43
  // One locale of a localized member is prose, one value per record —
47
44
  // there is nothing to choose between, so nothing to count.
48
- throw new EntifixBuildError(`"${member}" cannot be counted`, undefined, {
49
- member
50
- });
45
+ throw new Error(`"${member}" cannot be counted`);
51
46
  }
52
47
  const expression = params.get(facetFilterParam(member));
53
48
  return _extends({
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/rsql/facet-query-url.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFacetQuery } from '../types/EntityFacets.js';\nimport {\n allowedDescriptors,\n coerceFiltering,\n resolveAllowedProperty,\n} from './coerce-rsql.js';\nimport { RSQL_PARAM } from './load-request-url.js';\nimport { parseRsql } from './parse-rsql.js';\nimport { serializeRsql } from './serialize-rsql.js';\n\n/** The parameter naming one member to count, repeated once per facet. */\nexport const FACET_PARAM = 'facet';\n\n/** The parameter holding one facet's own filtering: `rsql.<member>`. */\nexport const facetFilterParam = (member: string): string =>\n `${RSQL_PARAM}.${member}`;\n\n/**\n * Serializes facet queries into query parameters: each member as a `facet`,\n * and each one's filtering as RSQL under `rsql.<member>` — omitted when it\n * filters nothing, so an unfiltered count keeps a clean URL.\n */\nexport function serializeFacetQueryParams<TEntity extends Entity>(\n queries: readonly EntityFacetQuery<TEntity>[],\n): URLSearchParams {\n const params = new URLSearchParams();\n for (const { member, filtering } of queries) {\n params.append(FACET_PARAM, member);\n const rsql = serializeRsql(filtering);\n if (rsql !== '') params.set(facetFilterParam(member), rsql);\n }\n return params;\n}\n\n/**\n * Parses query parameters into facet queries, validated against the entity's\n * own metadata — the server-side half of the facet protocol, and the same\n * allowlist a load uses.\n *\n * A counted member must be `filterable`: a count is a question about the\n * values a filter would choose between, and counting a member nobody may\n * filter on would read out values the entity chose not to expose. A\n * `localized` member is refused, since its value is a record of texts, not one\n * to count. Every failure is an {@link EntifixBuildError}, so a `400`.\n */\nexport function parseFacetQueryParams<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n params: URLSearchParams,\n): EntityFacetQuery<TEntity>[] {\n const members = params.getAll(FACET_PARAM);\n if (members.length === 0) {\n throw new EntifixBuildError(`name at least one \"${FACET_PARAM}\"`);\n }\n if (new Set(members).size !== members.length) {\n throw new EntifixBuildError(\n `a \"${FACET_PARAM}\" is named twice`,\n undefined,\n {\n members,\n },\n );\n }\n\n const allowed = allowedDescriptors(\n entityConstructor,\n descriptor => descriptor.filterable,\n );\n\n return members.map(member => {\n const { key, locale } = resolveAllowedProperty(\n allowed,\n member,\n 'filterable',\n );\n if (locale !== undefined) {\n // One locale of a localized member is prose, one value per record —\n // there is nothing to choose between, so nothing to count.\n throw new EntifixBuildError(`\"${member}\" cannot be counted`, undefined, {\n member,\n });\n }\n const expression = params.get(facetFilterParam(member));\n return {\n member: key as keyof TEntity & string,\n ...(expression?.trim()\n ? {\n filtering: [\n coerceFiltering(entityConstructor, parseRsql(expression)),\n ],\n }\n : {}),\n };\n });\n}\n"],"names":["EntifixBuildError","allowedDescriptors","coerceFiltering","resolveAllowedProperty","RSQL_PARAM","parseRsql","serializeRsql","FACET_PARAM","facetFilterParam","member","serializeFacetQueryParams","queries","params","URLSearchParams","filtering","append","rsql","set","parseFacetQueryParams","entityConstructor","members","getAll","length","Set","size","undefined","allowed","descriptor","filterable","map","key","locale","expression","get","trim"],"mappings":";AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAG5E,SACEC,kBAAkB,EAClBC,eAAe,EACfC,sBAAsB,QACjB,mBAAmB;AAC1B,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,aAAa,QAAQ,sBAAsB;AAEpD,uEAAuE,GACvE,OAAO,MAAMC,cAAc,QAAQ;AAEnC,sEAAsE,GACtE,OAAO,MAAMC,mBAAmB,CAACC,SAC/B,GAAGL,WAAW,CAAC,EAAEK,QAAQ,CAAC;AAE5B;;;;CAIC,GACD,OAAO,SAASC,0BACdC,OAA6C;IAE7C,MAAMC,SAAS,IAAIC;IACnB,KAAK,MAAM,EAAEJ,MAAM,EAAEK,SAAS,EAAE,IAAIH,QAAS;QAC3CC,OAAOG,MAAM,CAACR,aAAaE;QAC3B,MAAMO,OAAOV,cAAcQ;QAC3B,IAAIE,SAAS,IAAIJ,OAAOK,GAAG,CAACT,iBAAiBC,SAASO;IACxD;IACA,OAAOJ;AACT;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASM,sBACdC,iBAA6C,EAC7CP,MAAuB;IAEvB,MAAMQ,UAAUR,OAAOS,MAAM,CAACd;IAC9B,IAAIa,QAAQE,MAAM,KAAK,GAAG;QACxB,MAAM,IAAItB,kBAAkB,CAAC,mBAAmB,EAAEO,YAAY,CAAC,CAAC;IAClE;IACA,IAAI,IAAIgB,IAAIH,SAASI,IAAI,KAAKJ,QAAQE,MAAM,EAAE;QAC5C,MAAM,IAAItB,kBACR,CAAC,GAAG,EAAEO,YAAY,gBAAgB,CAAC,EACnCkB,WACA;YACEL;QACF;IAEJ;IAEA,MAAMM,UAAUzB,mBACdkB,mBACAQ,CAAAA,aAAcA,WAAWC,UAAU;IAGrC,OAAOR,QAAQS,GAAG,CAACpB,CAAAA;QACjB,MAAM,EAAEqB,GAAG,EAAEC,MAAM,EAAE,GAAG5B,uBACtBuB,SACAjB,QACA;QAEF,IAAIsB,WAAWN,WAAW;YACxB,oEAAoE;YACpE,2DAA2D;YAC3D,MAAM,IAAIzB,kBAAkB,CAAC,CAAC,EAAES,OAAO,mBAAmB,CAAC,EAAEgB,WAAW;gBACtEhB;YACF;QACF;QACA,MAAMuB,aAAapB,OAAOqB,GAAG,CAACzB,iBAAiBC;QAC/C,OAAO;YACLA,QAAQqB;WACJE,CAAAA,8BAAAA,WAAYE,IAAI,MAChB;YACEpB,WAAW;gBACTZ,gBAAgBiB,mBAAmBd,UAAU2B;aAC9C;QACH,IACA,CAAC;IAET;AACF"}
1
+ {"version":3,"sources":["../../src/rsql/facet-query-url.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityFacetQuery } from '../types/EntityFacets.js';\nimport {\n allowedDescriptors,\n coerceFiltering,\n resolveAllowedProperty,\n} from './coerce-rsql.js';\nimport { RSQL_PARAM } from './load-request-url.js';\nimport { parseRsql } from './parse-rsql.js';\nimport { serializeRsql } from './serialize-rsql.js';\n\n/** The parameter naming one member to count, repeated once per facet. */\nexport const FACET_PARAM = 'facet';\n\n/** The parameter holding one facet's own filtering: `rsql.<member>`. */\nexport const facetFilterParam = (member: string): string =>\n `${RSQL_PARAM}.${member}`;\n\n/**\n * Serializes facet queries into query parameters: each member as a `facet`,\n * and each one's filtering as RSQL under `rsql.<member>` — omitted when it\n * filters nothing, so an unfiltered count keeps a clean URL.\n */\nexport function serializeFacetQueryParams<TEntity extends Entity>(\n queries: readonly EntityFacetQuery<TEntity>[],\n): URLSearchParams {\n const params = new URLSearchParams();\n for (const { member, filtering } of queries) {\n params.append(FACET_PARAM, member);\n const rsql = serializeRsql(filtering);\n if (rsql !== '') params.set(facetFilterParam(member), rsql);\n }\n return params;\n}\n\n/**\n * Parses query parameters into facet queries, validated against the entity's\n * own metadata — the server-side half of the facet protocol, and the same\n * allowlist a load uses.\n *\n * A counted member must be `filterable`: a count is a question about the\n * values a filter would choose between, and counting a member nobody may\n * filter on would read out values the entity chose not to expose. A\n * `localized` member is refused, since its value is a record of texts, not one\n * to count. Every failure is a thrown `Error`, so a `400`.\n */\nexport function parseFacetQueryParams<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n params: URLSearchParams,\n): EntityFacetQuery<TEntity>[] {\n const members = params.getAll(FACET_PARAM);\n if (members.length === 0) {\n throw new Error(`name at least one \"${FACET_PARAM}\"`);\n }\n if (new Set(members).size !== members.length) {\n throw new Error(`a \"${FACET_PARAM}\" is named twice`);\n }\n\n const allowed = allowedDescriptors(\n entityConstructor,\n descriptor => descriptor.filterable,\n );\n\n return members.map(member => {\n const { key, locale } = resolveAllowedProperty(\n allowed,\n member,\n 'filterable',\n );\n if (locale !== undefined) {\n // One locale of a localized member is prose, one value per record —\n // there is nothing to choose between, so nothing to count.\n throw new Error(`\"${member}\" cannot be counted`);\n }\n const expression = params.get(facetFilterParam(member));\n return {\n member: key as keyof TEntity & string,\n ...(expression?.trim()\n ? {\n filtering: [\n coerceFiltering(entityConstructor, parseRsql(expression)),\n ],\n }\n : {}),\n };\n });\n}\n"],"names":["allowedDescriptors","coerceFiltering","resolveAllowedProperty","RSQL_PARAM","parseRsql","serializeRsql","FACET_PARAM","facetFilterParam","member","serializeFacetQueryParams","queries","params","URLSearchParams","filtering","append","rsql","set","parseFacetQueryParams","entityConstructor","members","getAll","length","Error","Set","size","allowed","descriptor","filterable","map","key","locale","undefined","expression","get","trim"],"mappings":";AAEA,S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AC,CAAC,EAAEd,OAAO,mBAAmB,CAAC;QACjD;QACA,MAAMwB,aAAarB,OAAOsB,GAAG,CAAC1B,iBAAiBC;QAC/C,OAAO;YACLA,QAAQqB;WACJG,CAAAA,8BAAAA,WAAYE,IAAI,MAChB;YACErB,WAAW;gBACTZ,gBAAgBiB,mBAAmBd,UAAU4B;aAC9C;QACH,IACA,CAAC;IAET;AACF"}
@@ -23,7 +23,7 @@ export declare function serializeLoadRequestParams<TEntity extends Entity>(reque
23
23
  *
24
24
  * Every failure mode (malformed RSQL, an unknown or non-filterable member, a
25
25
  * value that is not of the member's type, a nonsense page) is an
26
- * {@link EntifixBuildError}: the client sent something wrong, so it is a `400`
26
+ * an `Error`: the client sent something wrong, so it is a `400`
27
27
  * and never a `500`.
28
28
  */
29
29
  export declare function parseLoadRequestParams<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, params: URLSearchParams, defaults?: Partial<LoadRequestDefaults>): EntityLoadRequest<TEntity>;
@@ -1 +1 @@
1
- {"version":3,"file":"load-request-url.d.ts","sourceRoot":"","sources":["../../src/rsql/load-request-url.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAMvE,2DAA2D;AAC3D,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,eAAe,aAAa,CAAC;AAE1C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAQD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,SAAS,MAAM,EAC/D,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,eAAe,CAejB;AAsBD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,eAAe,EACvB,QAAQ,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC1C,iBAAiB,CAAC,OAAO,CAAC,CAsB5B"}
1
+ {"version":3,"file":"load-request-url.d.ts","sourceRoot":"","sources":["../../src/rsql/load-request-url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAMvE,2DAA2D;AAC3D,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,UAAU,SAAS,CAAC;AACjC,eAAO,MAAM,eAAe,aAAa,CAAC;AAE1C,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAQD;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,SAAS,MAAM,EAC/D,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAClC,eAAe,CAejB;AAkBD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,eAAe,EACvB,QAAQ,GAAE,OAAO,CAAC,mBAAmB,CAAM,GAC1C,iBAAiB,CAAC,OAAO,CAAC,CAsB5B"}
@@ -1,5 +1,4 @@
1
1
  import { _ as _extends } from "@swc/helpers/_/_extends";
2
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
3
2
  import { coerceFiltering } from './coerce-rsql.js';
4
3
  import { parseRsql } from './parse-rsql.js';
5
4
  import { serializeRsql } from './serialize-rsql.js';
@@ -34,9 +33,7 @@ const DEFAULTS = {
34
33
  if (raw === null || raw.trim() === '') return fallback;
35
34
  const value = Number(raw);
36
35
  if (!Number.isInteger(value) || value < 1) {
37
- throw new EntifixBuildError(`"${name}" must be a positive integer`, undefined, {
38
- [name]: raw
39
- });
36
+ throw new Error(`"${name}" must be a positive integer`);
40
37
  }
41
38
  return value;
42
39
  }
@@ -46,7 +43,7 @@ const DEFAULTS = {
46
43
  *
47
44
  * Every failure mode (malformed RSQL, an unknown or non-filterable member, a
48
45
  * value that is not of the member's type, a nonsense page) is an
49
- * {@link EntifixBuildError}: the client sent something wrong, so it is a `400`
46
+ * an `Error`: the client sent something wrong, so it is a `400`
50
47
  * and never a `500`.
51
48
  */ export function parseLoadRequestParams(entityConstructor, params, defaults = {}) {
52
49
  const { page, pageSize, maxPageSize } = _extends({}, DEFAULTS, defaults);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/rsql/load-request-url.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityLoadRequest } from '../types/EntityLoadRequest.js';\nimport { coerceFiltering } from './coerce-rsql.js';\nimport { parseRsql } from './parse-rsql.js';\nimport { serializeRsql } from './serialize-rsql.js';\nimport { parseSort, serializeSort } from './sort-param.js';\n\n/** The query parameters a load request is expressed in. */\nexport const RSQL_PARAM = 'rsql';\nexport const SORT_PARAM = 'sort';\nexport const PAGE_PARAM = 'page';\nexport const PAGE_SIZE_PARAM = 'pageSize';\n\nexport interface LoadRequestDefaults {\n page: number;\n pageSize: number;\n /** Upper bound on `pageSize`, so a client cannot ask for the whole table. */\n maxPageSize?: number;\n}\n\nconst DEFAULTS: Required<LoadRequestDefaults> = {\n page: 1,\n pageSize: 10,\n maxPageSize: 200,\n};\n\n/**\n * Serializes a load request into query parameters. Empty filtering, empty\n * sorting and absent paging are all omitted rather than sent blank, so a plain\n * listing keeps a clean URL.\n */\nexport function serializeLoadRequestParams<TEntity extends Entity>(\n request: EntityLoadRequest<TEntity>,\n): URLSearchParams {\n const params = new URLSearchParams();\n\n const rsql = serializeRsql(request.filtering);\n if (rsql !== '') params.set(RSQL_PARAM, rsql);\n\n const sort = serializeSort(request.sorting);\n if (sort !== '') params.set(SORT_PARAM, sort);\n\n if (request.page != null) params.set(PAGE_PARAM, String(request.page));\n if (request.pageSize != null) {\n params.set(PAGE_SIZE_PARAM, String(request.pageSize));\n }\n\n return params;\n}\n\n/** Reads a positive integer parameter, falling back when absent or unusable. */\nfunction readPositiveInteger(\n params: URLSearchParams,\n name: string,\n fallback: number,\n): number {\n const raw = params.get(name);\n if (raw === null || raw.trim() === '') return fallback;\n\n const value = Number(raw);\n if (!Number.isInteger(value) || value < 1) {\n throw new EntifixBuildError(\n `\"${name}\" must be a positive integer`,\n undefined,\n { [name]: raw },\n );\n }\n return value;\n}\n\n/**\n * Parses query parameters into an {@link EntityLoadRequest}, validated against\n * the entity's own metadata — the server-side half of the query protocol.\n *\n * Every failure mode (malformed RSQL, an unknown or non-filterable member, a\n * value that is not of the member's type, a nonsense page) is an\n * {@link EntifixBuildError}: the client sent something wrong, so it is a `400`\n * and never a `500`.\n */\nexport function parseLoadRequestParams<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n params: URLSearchParams,\n defaults: Partial<LoadRequestDefaults> = {},\n): EntityLoadRequest<TEntity> {\n const { page, pageSize, maxPageSize } = { ...DEFAULTS, ...defaults };\n\n const expression = params.get(RSQL_PARAM);\n const filtering = expression?.trim()\n ? [coerceFiltering(entityConstructor, parseRsql(expression))]\n : undefined;\n\n const sorting = parseSort(entityConstructor, params.get(SORT_PARAM));\n\n const request: EntityLoadRequest<TEntity> = {\n page: readPositiveInteger(params, PAGE_PARAM, page),\n pageSize: Math.min(\n readPositiveInteger(params, PAGE_SIZE_PARAM, pageSize),\n maxPageSize,\n ),\n };\n\n if (filtering) request.filtering = filtering;\n if (sorting) request.sorting = sorting;\n\n return request;\n}\n"],"names":["EntifixBuildError","coerceFiltering","parseRsql","serializeRsql","parseSort","serializeSort","RSQL_PARAM","SORT_PARAM","PAGE_PARAM","PAGE_SIZE_PARAM","DEFAULTS","page","pageSize","maxPageSize","serializeLoadRequestParams","request","params","URLSearchParams","rsql","filtering","set","sort","sorting","String","readPositiveInteger","name","fallback","raw","get","trim","value","Number","isInteger","undefined","parseLoadRequestParams","entityConstructor","defaults","expression","Math","min"],"mappings":";AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAG5E,SAASC,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SAASC,SAAS,EAAEC,aAAa,QAAQ,kBAAkB;AAE3D,yDAAyD,GACzD,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,kBAAkB,WAAW;AAS1C,MAAMC,WAA0C;IAC9CC,MAAM;IACNC,UAAU;IACVC,aAAa;AACf;AAEA;;;;CAIC,GACD,OAAO,SAASC,2BACdC,OAAmC;IAEnC,MAAMC,SAAS,IAAIC;IAEnB,MAAMC,OAAOf,cAAcY,QAAQI,SAAS;IAC5C,IAAID,SAAS,IAAIF,OAAOI,GAAG,CAACd,YAAYY;IAExC,MAAMG,OAAOhB,cAAcU,QAAQO,OAAO;IAC1C,IAAID,SAAS,IAAIL,OAAOI,GAAG,CAACb,YAAYc;IAExC,IAAIN,QAAQJ,IAAI,IAAI,MAAMK,OAAOI,GAAG,CAACZ,YAAYe,OAAOR,QAAQJ,IAAI;IACpE,IAAII,QAAQH,QAAQ,IAAI,MAAM;QAC5BI,OAAOI,GAAG,CAACX,iBAAiBc,OAAOR,QAAQH,QAAQ;IACrD;IAEA,OAAOI;AACT;AAEA,8EAA8E,GAC9E,SAASQ,oBACPR,MAAuB,EACvBS,IAAY,EACZC,QAAgB;IAEhB,MAAMC,MAAMX,OAAOY,GAAG,CAACH;IACvB,IAAIE,QAAQ,QAAQA,IAAIE,IAAI,OAAO,IAAI,OAAOH;IAE9C,MAAMI,QAAQC,OAAOJ;IACrB,IAAI,CAACI,OAAOC,SAAS,CAACF,UAAUA,QAAQ,GAAG;QACzC,MAAM,IAAI9B,kBACR,CAAC,CAAC,EAAEyB,KAAK,4BAA4B,CAAC,EACtCQ,WACA;YAAE,CAACR,KAAK,EAAEE;QAAI;IAElB;IACA,OAAOG;AACT;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASI,uBACdC,iBAA6C,EAC7CnB,MAAuB,EACvBoB,WAAyC,CAAC,CAAC;IAE3C,MAAM,EAAEzB,IAAI,EAAEC,QAAQ,EAAEC,WAAW,EAAE,GAAG,aAAKH,UAAa0B;IAE1D,MAAMC,aAAarB,OAAOY,GAAG,CAACtB;IAC9B,MAAMa,YAAYkB,CAAAA,8BAAAA,WAAYR,IAAI,MAC9B;QAAC5B,gBAAgBkC,mBAAmBjC,UAAUmC;KAAa,GAC3DJ;IAEJ,MAAMX,UAAUlB,UAAU+B,mBAAmBnB,OAAOY,GAAG,CAACrB;IAExD,MAAMQ,UAAsC;QAC1CJ,MAAMa,oBAAoBR,QAAQR,YAAYG;QAC9CC,UAAU0B,KAAKC,GAAG,CAChBf,oBAAoBR,QAAQP,iBAAiBG,WAC7CC;IAEJ;IAEA,IAAIM,WAAWJ,QAAQI,SAAS,GAAGA;IACnC,IAAIG,SAASP,QAAQO,OAAO,GAAGA;IAE/B,OAAOP;AACT"}
1
+ {"version":3,"sources":["../../src/rsql/load-request-url.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../types/Entity.js';\nimport type { EntityLoadRequest } from '../types/EntityLoadRequest.js';\nimport { coerceFiltering } from './coerce-rsql.js';\nimport { parseRsql } from './parse-rsql.js';\nimport { serializeRsql } from './serialize-rsql.js';\nimport { parseSort, serializeSort } from './sort-param.js';\n\n/** The query parameters a load request is expressed in. */\nexport const RSQL_PARAM = 'rsql';\nexport const SORT_PARAM = 'sort';\nexport const PAGE_PARAM = 'page';\nexport const PAGE_SIZE_PARAM = 'pageSize';\n\nexport interface LoadRequestDefaults {\n page: number;\n pageSize: number;\n /** Upper bound on `pageSize`, so a client cannot ask for the whole table. */\n maxPageSize?: number;\n}\n\nconst DEFAULTS: Required<LoadRequestDefaults> = {\n page: 1,\n pageSize: 10,\n maxPageSize: 200,\n};\n\n/**\n * Serializes a load request into query parameters. Empty filtering, empty\n * sorting and absent paging are all omitted rather than sent blank, so a plain\n * listing keeps a clean URL.\n */\nexport function serializeLoadRequestParams<TEntity extends Entity>(\n request: EntityLoadRequest<TEntity>,\n): URLSearchParams {\n const params = new URLSearchParams();\n\n const rsql = serializeRsql(request.filtering);\n if (rsql !== '') params.set(RSQL_PARAM, rsql);\n\n const sort = serializeSort(request.sorting);\n if (sort !== '') params.set(SORT_PARAM, sort);\n\n if (request.page != null) params.set(PAGE_PARAM, String(request.page));\n if (request.pageSize != null) {\n params.set(PAGE_SIZE_PARAM, String(request.pageSize));\n }\n\n return params;\n}\n\n/** Reads a positive integer parameter, falling back when absent or unusable. */\nfunction readPositiveInteger(\n params: URLSearchParams,\n name: string,\n fallback: number,\n): number {\n const raw = params.get(name);\n if (raw === null || raw.trim() === '') return fallback;\n\n const value = Number(raw);\n if (!Number.isInteger(value) || value < 1) {\n throw new Error(`\"${name}\" must be a positive integer`);\n }\n return value;\n}\n\n/**\n * Parses query parameters into an {@link EntityLoadRequest}, validated against\n * the entity's own metadata — the server-side half of the query protocol.\n *\n * Every failure mode (malformed RSQL, an unknown or non-filterable member, a\n * value that is not of the member's type, a nonsense page) is an\n * an `Error`: the client sent something wrong, so it is a `400`\n * and never a `500`.\n */\nexport function parseLoadRequestParams<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n params: URLSearchParams,\n defaults: Partial<LoadRequestDefaults> = {},\n): EntityLoadRequest<TEntity> {\n const { page, pageSize, maxPageSize } = { ...DEFAULTS, ...defaults };\n\n const expression = params.get(RSQL_PARAM);\n const filtering = expression?.trim()\n ? [coerceFiltering(entityConstructor, parseRsql(expression))]\n : undefined;\n\n const sorting = parseSort(entityConstructor, params.get(SORT_PARAM));\n\n const request: EntityLoadRequest<TEntity> = {\n page: readPositiveInteger(params, PAGE_PARAM, page),\n pageSize: Math.min(\n readPositiveInteger(params, PAGE_SIZE_PARAM, pageSize),\n maxPageSize,\n ),\n };\n\n if (filtering) request.filtering = filtering;\n if (sorting) request.sorting = sorting;\n\n return request;\n}\n"],"names":["coerceFiltering","parseRsql","serializeRsql","parseSort","serializeSort","RSQL_PARAM","SORT_PARAM","PAGE_PARAM","PAGE_SIZE_PARAM","DEFAULTS","page","pageSize","maxPageSize","serializeLoadRequestParams","request","params","URLSearchParams","rsql","filtering","set","sort","sorting","String","readPositiveInteger","name","fallback","raw","get","trim","value","Number","isInteger","Error","parseLoadRequestParams","entityConstructor","defaults","expression","undefined","Math","min"],"mappings":";AAEA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SAASC,SAAS,EAAEC,aAAa,QAAQ,kBAAkB;AAE3D,yDAAyD,GACzD,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,aAAa,OAAO;AACjC,OAAO,MAAMC,kBAAkB,WAAW;AAS1C,MAAMC,WAA0C;IAC9CC,MAAM;IACNC,UAAU;IACVC,aAAa;AACf;AAEA;;;;CAIC,GACD,OAAO,SAASC,2BACdC,OAAmC;IAEnC,MAAMC,SAAS,IAAIC;IAEnB,MAAMC,OAAOf,cAAcY,QAAQI,SAAS;IAC5C,IAAID,SAAS,IAAIF,OAAOI,GAAG,CAACd,YAAYY;IAExC,MAAMG,OAA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SAASP,QAAQO,OAAO,GAAGA;IAE/B,OAAOP;AACT"}
@@ -26,7 +26,7 @@ export type RawFilterGroup = {
26
26
  * properties against the metadata allowlist. Parsing alone never trusts the
27
27
  * input enough to build a query from it.
28
28
  *
29
- * Throws {@link EntifixBuildError} on malformed input, which services surface
29
+ * Throws an `Error` on malformed input, which services surface
30
30
  * as a `400`.
31
31
  */
32
32
  export declare function parseRsql(expression: string): RawFilterGroup;
@@ -1 +1 @@
1
- {"version":3,"file":"parse-rsql.d.ts","sourceRoot":"","sources":["../../src/rsql/parse-rsql.ts"],"names":[],"mappings":"AACA,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,KAAK,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC;CAC3C,CAAC;AA4NF;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAiB5D;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,GAAG,cAAc,GAC/B,IAAI,IAAI,SAAS,CAEnB"}
1
+ {"version":3,"file":"parse-rsql.d.ts","sourceRoot":"","sources":["../../src/rsql/parse-rsql.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,YAAY,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAC;IACvB,MAAM,EAAE,KAAK,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC;CAC3C,CAAC;AA4NF;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,cAAc,CAiB5D;AAED,0CAA0C;AAC1C,wBAAgB,WAAW,CACzB,IAAI,EAAE,SAAS,GAAG,cAAc,GAC/B,IAAI,IAAI,SAAS,CAEnB"}
@@ -1,4 +1,3 @@
1
- import { EntifixBuildError } from '../base-entities/entifix-error/index.js';
2
1
  import { RSQL_AND, RSQL_COMPARISON_TOKENS, RSQL_NULL_TOKEN, RSQL_OPERATORS, RSQL_OR, rsqlArity } from './rsql-operators.js';
3
2
  /**
4
3
  * Bounds on what an inbound expression may cost us. The URL comes from a
@@ -7,9 +6,7 @@ import { RSQL_AND, RSQL_COMPARISON_TOKENS, RSQL_NULL_TOKEN, RSQL_OPERATORS, RSQL
7
6
  * Mongo query.
8
7
  */ const MAX_DEPTH = 16;
9
8
  const MAX_NODES = 128;
10
- const fail = (message, expression)=>new EntifixBuildError(`Invalid RSQL: ${message}`, undefined, {
11
- expression
12
- });
9
+ const fail = (message, expression)=>new Error(`Invalid RSQL: ${message}`);
13
10
  /** A property name — the RSQL selector. Kept conservative on purpose. */ const SELECTOR = /^[A-Za-z_][A-Za-z0-9_.-]*/;
14
11
  const atEnd = (cursor)=>cursor.index >= cursor.text.length;
15
12
  const peek = (cursor)=>cursor.text[cursor.index];
@@ -202,7 +199,7 @@ function parseOr(cursor, depth) {
202
199
  * properties against the metadata allowlist. Parsing alone never trusts the
203
200
  * input enough to build a query from it.
204
201
  *
205
- * Throws {@link EntifixBuildError} on malformed input, which services surface
202
+ * Throws an `Error` on malformed input, which services surface
206
203
  * as a `400`.
207
204
  */ export function parseRsql(expression) {
208
205
  const trimmed = expression.trim();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/rsql/parse-rsql.ts"],"sourcesContent":["import { EntifixBuildError } from '../base-entities/entifix-error/index.js';\nimport {\n RSQL_AND,\n RSQL_COMPARISON_TOKENS,\n RSQL_NULL_TOKEN,\n RSQL_OPERATORS,\n RSQL_OR,\n rsqlArity,\n type RsqlOperator,\n} from './rsql-operators.js';\n\n/**\n * A parsed filter before coercion: identical to an {@link EntityFilter} except\n * every argument is still the raw string the URL carried. Re-typing needs the\n * entity's metadata, which this parser deliberately does not have — see\n * `coerce-rsql`.\n */\nexport type RawFilter = {\n property: string;\n operator: RsqlOperator;\n value?: string;\n values?: string[];\n start?: string;\n end?: string;\n};\n\nexport type RawFilterGroup = {\n operator: 'and' | 'or';\n values: Array<RawFilter | RawFilterGroup>;\n};\n\n/**\n * Bounds on what an inbound expression may cost us. The URL comes from a\n * client, so an unbounded parser is a denial-of-service surface: deep nesting\n * would exhaust the stack and a huge disjunction would become an equally huge\n * Mongo query.\n */\nconst MAX_DEPTH = 16;\nconst MAX_NODES = 128;\n\nconst fail = (message: string, expression: string) =>\n new EntifixBuildError(`Invalid RSQL: ${message}`, undefined, { expression });\n\n/** A property name — the RSQL selector. Kept conservative on purpose. */\nconst SELECTOR = /^[A-Za-z_][A-Za-z0-9_.-]*/;\n\ninterface Cursor {\n readonly text: string;\n index: number;\n nodes: number;\n}\n\nconst atEnd = (cursor: Cursor) => cursor.index >= cursor.text.length;\n\nconst peek = (cursor: Cursor) => cursor.text[cursor.index];\n\nfunction skipWhitespace(cursor: Cursor): void {\n while (!atEnd(cursor) && /\\s/.test(cursor.text[cursor.index])) cursor.index++;\n}\n\nfunction countNode(cursor: Cursor): void {\n if (++cursor.nodes > MAX_NODES) {\n throw fail(`expression exceeds ${MAX_NODES} nodes`, cursor.text);\n }\n}\n\n/**\n * Reads one argument: a quoted string (either quote style, with `\\` escapes) or\n * a bare run of characters up to the next grammar character. The result is\n * always a string — typing happens later, from metadata.\n */\nfunction readValue(cursor: Cursor): string {\n skipWhitespace(cursor);\n const quoteChar = peek(cursor);\n\n if (quoteChar === \"'\" || quoteChar === '\"') {\n cursor.index++;\n let value = '';\n while (!atEnd(cursor)) {\n const char = cursor.text[cursor.index];\n if (char === '\\\\') {\n const escaped = cursor.text[cursor.index + 1];\n if (escaped === undefined) {\n throw fail('expression ends in an escape', cursor.text);\n }\n value += escaped;\n cursor.index += 2;\n continue;\n }\n if (char === quoteChar) {\n cursor.index++;\n return value;\n }\n value += char;\n cursor.index++;\n }\n throw fail('unterminated quoted value', cursor.text);\n }\n\n const start = cursor.index;\n while (!atEnd(cursor) && !/[;,()\\s]/.test(cursor.text[cursor.index])) {\n cursor.index++;\n }\n if (cursor.index === start) {\n throw fail('missing value', cursor.text);\n }\n return cursor.text.slice(start, cursor.index);\n}\n\n/** Reads `(a,b,…)` — the argument list of `=in=`/`=out=`/`=btn=`/`=nbtn=`. */\nfunction readValueList(cursor: Cursor): string[] {\n skipWhitespace(cursor);\n if (peek(cursor) !== '(') {\n throw fail('expected a parenthesized value list', cursor.text);\n }\n cursor.index++;\n\n const values: string[] = [];\n for (;;) {\n values.push(readValue(cursor));\n skipWhitespace(cursor);\n const char = peek(cursor);\n if (char === ',') {\n cursor.index++;\n continue;\n }\n if (char === ')') {\n cursor.index++;\n return values;\n }\n throw fail('unterminated value list', cursor.text);\n }\n}\n\n/** Matches the longest comparison token at the cursor, or `undefined`. */\nfunction readToken(cursor: Cursor): string | undefined {\n for (const token of RSQL_COMPARISON_TOKENS) {\n if (cursor.text.startsWith(token, cursor.index)) {\n cursor.index += token.length;\n return token;\n }\n }\n return undefined;\n}\n\nfunction parseComparison(cursor: Cursor): RawFilter {\n countNode(cursor);\n skipWhitespace(cursor);\n\n const selector = SELECTOR.exec(cursor.text.slice(cursor.index));\n if (!selector) {\n throw fail(\n `expected a property name at position ${cursor.index}`,\n cursor.text,\n );\n }\n const property = selector[0];\n cursor.index += property.length;\n\n skipWhitespace(cursor);\n const token = readToken(cursor);\n if (!token) {\n throw fail(`expected an operator after \"${property}\"`, cursor.text);\n }\n\n if (token === RSQL_NULL_TOKEN) {\n const argument = readValue(cursor);\n if (argument !== 'true' && argument !== 'false') {\n throw fail(`\"${RSQL_NULL_TOKEN}\" takes true or false`, cursor.text);\n }\n return {\n property,\n operator: argument === 'true' ? 'isNull' : 'isNotNull',\n };\n }\n\n const operator = RSQL_OPERATORS[token];\n\n switch (rsqlArity(operator)) {\n case 'list':\n return { property, operator, values: readValueList(cursor) };\n case 'range': {\n const bounds = readValueList(cursor);\n if (bounds.length !== 2) {\n throw fail(`\"${token}\" takes exactly two bounds`, cursor.text);\n }\n return { property, operator, start: bounds[0], end: bounds[1] };\n }\n default:\n return { property, operator, value: readValue(cursor) };\n }\n}\n\n/** A comparison, or a parenthesized sub-expression. */\nfunction parsePrimary(\n cursor: Cursor,\n depth: number,\n): RawFilter | RawFilterGroup {\n skipWhitespace(cursor);\n\n if (peek(cursor) === '(') {\n if (depth >= MAX_DEPTH) {\n throw fail(`nesting deeper than ${MAX_DEPTH} levels`, cursor.text);\n }\n cursor.index++;\n const group = parseOr(cursor, depth + 1);\n skipWhitespace(cursor);\n if (peek(cursor) !== ')') {\n throw fail('unbalanced parenthesis', cursor.text);\n }\n cursor.index++;\n return group;\n }\n\n return parseComparison(cursor);\n}\n\n/**\n * Collapses a single-child group into that child, so `a==1` parses to one\n * comparison rather than three nested wrappers. Keeps the parsed tree\n * comparable with the one that was serialized.\n */\nfunction group(\n operator: 'and' | 'or',\n values: Array<RawFilter | RawFilterGroup>,\n): RawFilter | RawFilterGroup {\n return values.length === 1 ? values[0] : { operator, values };\n}\n\nfunction parseAnd(cursor: Cursor, depth: number): RawFilter | RawFilterGroup {\n const values = [parsePrimary(cursor, depth)];\n for (;;) {\n skipWhitespace(cursor);\n if (peek(cursor) !== RSQL_AND) return group('and', values);\n cursor.index++;\n values.push(parsePrimary(cursor, depth));\n }\n}\n\nfunction parseOr(cursor: Cursor, depth: number): RawFilter | RawFilterGroup {\n const values = [parseAnd(cursor, depth)];\n for (;;) {\n skipWhitespace(cursor);\n if (peek(cursor) !== RSQL_OR) return group('or', values);\n cursor.index++;\n values.push(parseAnd(cursor, depth));\n }\n}\n\n/**\n * Parses an RSQL expression into a raw (still untyped) filter tree.\n *\n * Precedence follows RSQL: `,` (or) binds looser than `;` (and), and\n * parentheses override both. Values stay strings — {@link coerceFiltering} is\n * what turns them into the entity's own types, and it is also what checks the\n * properties against the metadata allowlist. Parsing alone never trusts the\n * input enough to build a query from it.\n *\n * Throws {@link EntifixBuildError} on malformed input, which services surface\n * as a `400`.\n */\nexport function parseRsql(expression: string): RawFilterGroup {\n const trimmed = expression.trim();\n if (trimmed === '') return { operator: 'and', values: [] };\n\n const cursor: Cursor = { text: trimmed, index: 0, nodes: 0 };\n const parsed = parseOr(cursor, 0);\n\n skipWhitespace(cursor);\n if (!atEnd(cursor)) {\n throw fail(\n `unexpected \"${peek(cursor)}\" at position ${cursor.index}`,\n trimmed,\n );\n }\n\n // The result is always a group, so callers get one shape to walk.\n return 'property' in parsed ? { operator: 'and', values: [parsed] } : parsed;\n}\n\n/** Narrows a raw node to a comparison. */\nexport function isRawFilter(\n node: RawFilter | RawFilterGroup,\n): node is RawFilter {\n return 'property' in node;\n}\n"],"names":["EntifixBuildError","RSQL_AND","RSQL_COMPARISON_TOKENS","RSQL_NULL_TOKEN","RSQL_OPERATORS","RSQL_OR","rsqlArity","MAX_DEPTH","MAX_NODES","fail","message","expression","undefined","SELECTOR","atEnd","cursor","index","text","length","peek","skipWhitespace","test","countNode","nodes","readValue","quoteChar","value","char","escaped","start","slice","readValueList","values","push","readToken","token","startsWith","parseComparison","selector","exec","property","argument","operator","bounds","end","parsePrimary","depth","group","parseOr","parseAnd","parseRsql","trimmed","trim","parsed","isRawFilter","node"],"mappings":"AAAA,SAASA,iBAAiB,QAAQ,0CAA0C;AAC5E,SACEC,QAAQ,EACRC,sBAAsB,EACtBC,eAAe,EACfC,cAAc,EACdC,OAAO,EACPC,SAAS,QAEJ,sBAAsB;AAsB7B;;;;;CAKC,GACD,MAAMC,YAAY;AAClB,MAAMC,YAAY;AAElB,MAAMC,OAAO,CAACC,SAAiBC,aAC7B,IAAIX,kBAAkB,CAAC,cAAc,EAAEU,SAAS,EAAEE,WAAW;QAAED;IAAW;AAE5E,uEAAuE,GACvE,MAAME,WAAW;AAQjB,MAAMC,QAAQ,CAACC,SAAmBA,OAAOC,KAAK,IAAID,OAAOE,IAAI,CAACC,MAAM;AAEpE,MAAMC,OAAO,CAACJ,SAAmBA,OAAOE,IAAI,CAACF,OAAOC,KAAK,CAAC;AAE1D,SAASI,eAAeL,MAAc;IACpC,MAAO,CAACD,MAAMC,WAAW,KAAKM,IAAI,CAACN,OAAOE,IAAI,CAACF,OAAOC,KAAK,CAAC,EAAGD,OAAOC,KAAK;AAC7E;AAEA,SAASM,UAAUP,MAAc;IAC/B,IAAI,EAAEA,OAAOQ,KAAK,GAAGf,WAAW;QAC9B,MAAMC,KAAK,CAAC,mBAAmB,EAAED,UAAU,MAAM,CAAC,EAAEO,OAAOE,IAAI;IACjE;AACF;AAEA;;;;CAIC,GACD,SAASO,UAAUT,MAAc;IAC/BK,eAAeL;IACf,MAAMU,YAAYN,KAAKJ;IAEvB,IAAIU,cAAc,OAAOA,cAAc,KAAK;QAC1CV,OAAOC,KAAK;QACZ,IAAIU,QAAQ;QACZ,MAAO,CAACZ,MAAMC,QAAS;YACrB,MAAMY,OAAOZ,OAAOE,IAAI,CAACF,OAAOC,KAAK,CAAC;YACtC,IAAIW,SAAS,MAAM;gBACjB,MAAMC,UAAUb,OAAOE,IAAI,CAACF,OAAOC,KAAK,GAAG,EAAE;gBAC7C,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IAC1C,MAAMwC,UAAUxC,WAAWyC,IAAI;IAC/B,IAAID,YAAY,IAAI,OAAO;QAAET,UAAU;QAAOV,QAAQ,EAAE;IAAC;IAEzD,MAAMjB,SAAiB;QAAEE,MAAMkC;QAASnC,OAAO;QAAGO,OAAO;IAAE;IAC3D,MAAM8B,SAASL,QAAQjC,QAAQ;IAE/BK,eAAeL;IACf,IAAI,CAACD,MAAMC,SAAS;QAClB,MAAMN,KACJ,CAAC,YAAY,EAAEU,KAAKJ,QAAQ,cAAc,EAAEA,OAAOC,KAAK,EAAE,EAC1DmC;IAEJ;IAEA,kEAAkE;IAClE,OAAO,cAAcE,SAAS;QAAEX,UAAU;QAAOV,QAAQ;YAACqB;SAAO;IAAC,IAAIA;AACxE;AAEA,wCAAwC,GACxC,OAAO,SAASC,YACdC,IAAgC;IAEhC,OAAO,cAAcA;AACvB"}
1
+ {"version":3,"sources":["../../src/rsql/parse-rsql.ts"],"sourcesContent":["import {\n RSQL_AND,\n RSQL_COMPARISON_TOKENS,\n RSQL_NULL_TOKEN,\n RSQL_OPERATORS,\n RSQL_OR,\n rsqlArity,\n type RsqlOperator,\n} from './rsql-operators.js';\n\n/**\n * A parsed filter before coercion: identical to an {@link EntityFilter} except\n * every argument is still the raw string the URL carried. Re-typing needs the\n * entity's metadata, which this parser deliberately does not have — see\n * `coerce-rsql`.\n */\nexport type RawFilter = {\n property: string;\n operator: RsqlOperator;\n value?: string;\n values?: string[];\n start?: string;\n end?: string;\n};\n\nexport type RawFilterGroup = {\n operator: 'and' | 'or';\n values: Array<RawFilter | RawFilterGroup>;\n};\n\n/**\n * Bounds on what an inbound expression may cost us. The URL comes from a\n * client, so an unbounded parser is a denial-of-service surface: deep nesting\n * would exhaust the stack and a huge disjunction would become an equally huge\n * Mongo query.\n */\nconst MAX_DEPTH = 16;\nconst MAX_NODES = 128;\n\nconst fail = (message: string, expression: string) =>\n new Error(`Invalid RSQL: ${message}`);\n\n/** A property name — the RSQL selector. Kept conservative on purpose. */\nconst SELECTOR = /^[A-Za-z_][A-Za-z0-9_.-]*/;\n\ninterface Cursor {\n readonly text: string;\n index: number;\n nodes: number;\n}\n\nconst atEnd = (cursor: Cursor) => cursor.index >= cursor.text.length;\n\nconst peek = (cursor: Cursor) => cursor.text[cursor.index];\n\nfunction skipWhitespace(cursor: Cursor): void {\n while (!atEnd(cursor) && /\\s/.test(cursor.text[cursor.index])) cursor.index++;\n}\n\nfunction countNode(cursor: Cursor): void {\n if (++cursor.nodes > MAX_NODES) {\n throw fail(`expression exceeds ${MAX_NODES} nodes`, cursor.text);\n }\n}\n\n/**\n * Reads one argument: a quoted string (either quote style, with `\\` escapes) or\n * a bare run of characters up to the next grammar character. The result is\n * always a string — typing happens later, from metadata.\n */\nfunction readValue(cursor: Cursor): string {\n skipWhitespace(cursor);\n const quoteChar = peek(cursor);\n\n if (quoteChar === \"'\" || quoteChar === '\"') {\n cursor.index++;\n let value = '';\n while (!atEnd(cursor)) {\n const char = cursor.text[cursor.index];\n if (char === '\\\\') {\n const escaped = cursor.text[cursor.index + 1];\n if (escaped === undefined) {\n throw fail('expression ends in an escape', cursor.text);\n }\n value += escaped;\n cursor.index += 2;\n continue;\n }\n if (char === quoteChar) {\n cursor.index++;\n return value;\n }\n value += char;\n cursor.index++;\n }\n throw fail('unterminated quoted value', cursor.text);\n }\n\n const start = cursor.index;\n while (!atEnd(cursor) && !/[;,()\\s]/.test(cursor.text[cursor.index])) {\n cursor.index++;\n }\n if (cursor.index === start) {\n throw fail('missing value', cursor.text);\n }\n return cursor.text.slice(start, cursor.index);\n}\n\n/** Reads `(a,b,…)` — the argument list of `=in=`/`=out=`/`=btn=`/`=nbtn=`. */\nfunction readValueList(cursor: Cursor): string[] {\n skipWhitespace(cursor);\n if (peek(cursor) !== '(') {\n throw fail('expected a parenthesized value list', cursor.text);\n }\n cursor.index++;\n\n const values: string[] = [];\n for (;;) {\n values.push(readValue(cursor));\n skipWhitespace(cursor);\n const char = peek(cursor);\n if (char === ',') {\n cursor.index++;\n continue;\n }\n if (char === ')') {\n cursor.index++;\n return values;\n }\n throw fail('unterminated value list', cursor.text);\n }\n}\n\n/** Matches the longest comparison token at the cursor, or `undefined`. */\nfunction readToken(cursor: Cursor): string | undefined {\n for (const token of RSQL_COMPARISON_TOKENS) {\n if (cursor.text.startsWith(token, cursor.index)) {\n cursor.index += token.length;\n return token;\n }\n }\n return undefined;\n}\n\nfunction parseComparison(cursor: Cursor): RawFilter {\n countNode(cursor);\n skipWhitespace(cursor);\n\n const selector = SELECTOR.exec(cursor.text.slice(cursor.index));\n if (!selector) {\n throw fail(\n `expected a property name at position ${cursor.index}`,\n cursor.text,\n );\n }\n const property = selector[0];\n cursor.index += property.length;\n\n skipWhitespace(cursor);\n const token = readToken(cursor);\n if (!token) {\n throw fail(`expected an operator after \"${property}\"`, cursor.text);\n }\n\n if (token === RSQL_NULL_TOKEN) {\n const argument = readValue(cursor);\n if (argument !== 'true' && argument !== 'false') {\n throw fail(`\"${RSQL_NULL_TOKEN}\" takes true or false`, cursor.text);\n }\n return {\n property,\n operator: argument === 'true' ? 'isNull' : 'isNotNull',\n };\n }\n\n const operator = RSQL_OPERATORS[token];\n\n switch (rsqlArity(operator)) {\n case 'list':\n return { property, operator, values: readValueList(cursor) };\n case 'range': {\n const bounds = readValueList(cursor);\n if (bounds.length !== 2) {\n throw fail(`\"${token}\" takes exactly two bounds`, cursor.text);\n }\n return { property, operator, start: bounds[0], end: bounds[1] };\n }\n default:\n return { property, operator, value: readValue(cursor) };\n }\n}\n\n/** A comparison, or a parenthesized sub-expression. */\nfunction parsePrimary(\n cursor: Cursor,\n depth: number,\n): RawFilter | RawFilterGroup {\n skipWhitespace(cursor);\n\n if (peek(cursor) === '(') {\n if (depth >= MAX_DEPTH) {\n throw fail(`nesting deeper than ${MAX_DEPTH} levels`, cursor.text);\n }\n cursor.index++;\n const group = parseOr(cursor, depth + 1);\n skipWhitespace(cursor);\n if (peek(cursor) !== ')') {\n throw fail('unbalanced parenthesis', cursor.text);\n }\n cursor.index++;\n return group;\n }\n\n return parseComparison(cursor);\n}\n\n/**\n * Collapses a single-child group into that child, so `a==1` parses to one\n * comparison rather than three nested wrappers. Keeps the parsed tree\n * comparable with the one that was serialized.\n */\nfunction group(\n operator: 'and' | 'or',\n values: Array<RawFilter | RawFilterGroup>,\n): RawFilter | RawFilterGroup {\n return values.length === 1 ? values[0] : { operator, values };\n}\n\nfunction parseAnd(cursor: Cursor, depth: number): RawFilter | RawFilterGroup {\n const values = [parsePrimary(cursor, depth)];\n for (;;) {\n skipWhitespace(cursor);\n if (peek(cursor) !== RSQL_AND) return group('and', values);\n cursor.index++;\n values.push(parsePrimary(cursor, depth));\n }\n}\n\nfunction parseOr(cursor: Cursor, depth: number): RawFilter | RawFilterGroup {\n const values = [parseAnd(cursor, depth)];\n for (;;) {\n skipWhitespace(cursor);\n if (peek(cursor) !== RSQL_OR) return group('or', values);\n cursor.index++;\n values.push(parseAnd(cursor, depth));\n }\n}\n\n/**\n * Parses an RSQL expression into a raw (still untyped) filter tree.\n *\n * Precedence follows RSQL: `,` (or) binds looser than `;` (and), and\n * parentheses override both. Values stay strings — {@link coerceFiltering} is\n * what turns them into the entity's own types, and it is also what checks the\n * properties against the metadata allowlist. Parsing alone never trusts the\n * input enough to build a query from it.\n *\n * Throws an `Error` on malformed input, which services surface\n * as a `400`.\n */\nexport function parseRsql(expression: string): RawFilterGroup {\n const trimmed = expression.trim();\n if (trimmed === '') return { operator: 'and', values: [] };\n\n const cursor: Cursor = { text: trimmed, index: 0, nodes: 0 };\n const parsed = parseOr(cursor, 0);\n\n skipWhitespace(cursor);\n if (!atEnd(cursor)) {\n throw fail(\n `unexpected \"${peek(cursor)}\" at position ${cursor.index}`,\n trimmed,\n );\n }\n\n // The result is always a group, so callers get one shape to walk.\n return 'property' in parsed ? { operator: 'and', values: [parsed] } : parsed;\n}\n\n/** Narrows a raw node to a comparison. */\nexport function isRawFilter(\n node: RawFilter | RawFilterGroup,\n): node is RawFilter {\n return 'property' in node;\n}\n"],"names":["RSQL_AND","RSQL_COMPARISON_TOKENS","RSQL_NULL_TOKEN","RSQL_OPERATORS","RSQL_OR","rsqlArity","MAX_DEPTH","MAX_NODES","fail","message","expression","Error","SELECTOR","atEnd","cursor","index","text","length","peek","skipWhitespace","test","countNode","nodes","readValue","quoteChar","value","char","escaped","undefined","start","slice","readValueList","values","push","readToken","token","startsWith","parseComparison","selector","exec","property","argument","operator","bounds","end","parsePrimary","depth","group","parseOr","parseAnd","parseRsql","trimmed","trim","parsed","isRawFilter","node"],"mappings":"AAAA,SACEA,QAAQ,EACRC,sBAAsB,EACtBC,eAAe,EACfC,cAAc,EACdC,OAAO,EACPC,SAAS,QAEJ,sBAAsB;AAsB7B;;;;;CAKC,GACD,MAAMC,YAAY;AAClB,MAAMC,YAAY;AAElB,MAAMC,OAAO,CAACC,SAAiBC,aAC7B,IAAIC,MAAM,CAAC,cAAc,EAAEF,SAAS;AAEtC,uEAAuE,GACvE,MAAMG,WAAW;AAQjB,MAAMC,QAAQ,CAACC,SAAmBA,OAAOC,KAAK,IAAID,OAAOE,IAAI,CAACC,MAAM;AAEpE,MAAMC,OAAO,CAACJ,SAAmBA,OAAOE,IAAI,CAACF,OAAOC,KAAK,CAAC;AAE1D,SAASI,eAAeL,MAAc;IACpC,MAAO,CAACD,MAAMC,WAAW,KAAKM,IAAI,CAACN,OAAOE,IAAI,CAACF,OAAOC,KAAK,CAAC,EAAGD,OAAOC,KAAK;AAC7E;AAEA,SAASM,UAAUP,MAAc;IAC/B,IAAI,EAAEA,OAAOQ,KAAK,GAAGf,WAAW;QAC9B,MAAMC,KAAK,CAAC,mBAAmB,EAAED,UAAU,MAAM,CAAC,EAAEO,OAAOE,IAAI;IACjE;AACF;AAEA;;;;CAIC,GACD,SAASO,UAAUT,MAAc;IAC/BK,eAAeL;IACf,MAAMU,YAAYN,KAAKJ;IAEvB,IAAIU,cAAc,OAAOA,cAAc,KAAK;QAC1CV,OAAOC,KAAK;QACZ,IAA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3B,eAAeL;QACf,IAAII,KAAKJ,YAAYV,SAAS,OAAO2C,MAAM,MAAMf;QACjDlB,OAAOC,KAAK;QACZiB,OAAOC,IAAI,CAACgB,SAASnC,QAAQgC;IAC/B;AACF;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASI,UAAUxC,UAAkB;IAC1C,MAAMyC,UAAUzC,WAAW0C,IAAI;IAC/B,IAAID,YAAY,IAAI,OAAO;QAAET,UAAU;QAAOV,QAAQ,EAAE;IAAC;IAEzD,MAAMlB,SAAiB;QAAEE,MAAMmC;QAASpC,OAAO;QAAGO,OAAO;IAAE;IAC3D,MAAM+B,SAASL,QAAQlC,QAAQ;IAE/BK,eAAeL;IACf,IAAI,CAACD,MAAMC,SAAS;QAClB,MAAMN,KACJ,CAAC,YAAY,EAAEU,KAAKJ,QAAQ,cAAc,EAAEA,OAAOC,KAAK,EAAE,EAC1DoC;IAEJ;IAEA,kEAAkE;IAClE,OAAO,cAAcE,SAAS;QAAEX,UAAU;QAAOV,QAAQ;YAACqB;SAAO;IAAC,IAAIA;AACxE;AAEA,wCAAwC,GACxC,OAAO,SAASC,YACdC,IAAgC;IAEhC,OAAO,cAAcA;AACvB"}
@@ -0,0 +1,24 @@
1
+ import type { Effect } from 'effect';
2
+ import type { EntifixFailure } from '../failure/failure.js';
3
+ import type { Entity, EntityId } from '../types/Entity.js';
4
+ import type { WriteResult } from './write-result.js';
5
+ /**
6
+ * An entity's writes as a screen makes them. Each answers {@link WriteResult},
7
+ * settled when the write happened or pending when the server handed it to a
8
+ * flow, so the server can move a write onto a flow without the screen
9
+ * changing
10
+ * ([ADR 0022](../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).
11
+ *
12
+ * A port: the REST adapter is one implementation, and a screen names it only
13
+ * through the host's composition.
14
+ */
15
+ export interface EntityWriter {
16
+ /**
17
+ * Creates an entity without an id and updates one with an id. A settled
18
+ * save answers the stored entity.
19
+ */
20
+ save<TInput extends Entity>(entity: TInput): Effect.Effect<WriteResult<TInput>, EntifixFailure>;
21
+ /** Deletes by id or by entity. A settled delete answers nothing. */
22
+ delete(entityOrId: EntityId | Entity): Effect.Effect<WriteResult<void>, EntifixFailure>;
23
+ }
24
+ //# sourceMappingURL=entity-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-writer.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/entity-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,IAAI,CAAC,MAAM,SAAS,MAAM,EACxB,MAAM,EAAE,MAAM,GACb,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,cAAc,CAAC,CAAC;IACtD,oEAAoE;IACpE,MAAM,CACJ,UAAU,EAAE,QAAQ,GAAG,MAAM,GAC5B,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC;CACrD"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * An entity's writes as a screen makes them. Each answers {@link WriteResult},
3
+ * settled when the write happened or pending when the server handed it to a
4
+ * flow, so the server can move a write onto a flow without the screen
5
+ * changing
6
+ * ([ADR 0022](../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).
7
+ *
8
+ * A port: the REST adapter is one implementation, and a screen names it only
9
+ * through the host's composition.
10
+ */ export { };
11
+
12
+ //# sourceMappingURL=entity-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/use-case-runner/entity-writer.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type { EntifixFailure } from '../failure/failure.js';\nimport type { Entity, EntityId } from '../types/Entity.js';\nimport type { WriteResult } from './write-result.js';\n\n/**\n * An entity's writes as a screen makes them. Each answers {@link WriteResult},\n * settled when the write happened or pending when the server handed it to a\n * flow, so the server can move a write onto a flow without the screen\n * changing\n * ([ADR 0022](../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).\n *\n * A port: the REST adapter is one implementation, and a screen names it only\n * through the host's composition.\n */\nexport interface EntityWriter {\n /**\n * Creates an entity without an id and updates one with an id. A settled\n * save answers the stored entity.\n */\n save<TInput extends Entity>(\n entity: TInput,\n ): Effect.Effect<WriteResult<TInput>, EntifixFailure>;\n /** Deletes by id or by entity. A settled delete answers nothing. */\n delete(\n entityOrId: EntityId | Entity,\n ): Effect.Effect<WriteResult<void>, EntifixFailure>;\n}\n"],"names":[],"mappings":"AAMA;;;;;;;;;CASC,GACD,WAYC"}
@@ -1,2 +1,4 @@
1
+ export * from './entity-writer.js';
1
2
  export * from './use-case-runner.js';
3
+ export * from './write-result.js';
2
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
@@ -1,3 +1,5 @@
1
+ export * from './entity-writer.js';
1
2
  export * from './use-case-runner.js';
3
+ export * from './write-result.js';
2
4
 
3
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/use-case-runner/index.ts"],"sourcesContent":["export * from './use-case-runner.js';\n"],"names":[],"mappings":"AAAA,cAAc,uBAAuB"}
1
+ {"version":3,"sources":["../../src/use-case-runner/index.ts"],"sourcesContent":["export * from './entity-writer.js';\nexport * from './use-case-runner.js';\nexport * from './write-result.js';\n"],"names":[],"mappings":"AAAA,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,oBAAoB"}
@@ -1,10 +1,11 @@
1
1
  import type { Effect } from 'effect';
2
2
  import type { UseCaseDescriptor } from '../entity-definition/describe/describe-entity-use-cases.js';
3
3
  import type { UseCaseBinding } from '../entity-definition/meta-entities/meta-use-case/meta-use-case.js';
4
- import type { TransitionalFailure } from '../failure/failure.js';
4
+ import type { EntifixFailure } from '../failure/failure.js';
5
5
  import type { BulkOutcome } from '../types/BulkOutcome.js';
6
6
  import type { Entity, EntityId } from '../types/Entity.js';
7
7
  import type { EntitySelection } from '../types/EntitySelection.js';
8
+ import type { WriteResult } from './write-result.js';
8
9
  /**
9
10
  * The path a verb is served at, from its entity's key, its own key and its
10
11
  * binding
@@ -21,9 +22,13 @@ export declare const verbPath: (entityKey: string, useCaseKey: string, binding:
21
22
  * a verb without knowing which.
22
23
  */
23
24
  export interface EntityUseCaseRunner {
24
- /** Runs a verb on one record, or on nothing for an unbound verb. */
25
- run(useCase: UseCaseDescriptor, id?: EntityId): Effect.Effect<void, TransitionalFailure>;
25
+ /**
26
+ * Runs a verb on one record, or on nothing for an unbound verb. A verb that
27
+ * starts a flow answers {@link Pending}; one that finished answers
28
+ * {@link Settled} with what the service sent back.
29
+ */
30
+ run(useCase: UseCaseDescriptor, id?: EntityId): Effect.Effect<WriteResult<unknown>, EntifixFailure>;
26
31
  /** Runs a collection verb on a selection, one outcome per record. */
27
- bulk(useCase: UseCaseDescriptor, selection: EntitySelection<Entity>): Effect.Effect<readonly BulkOutcome[], TransitionalFailure>;
32
+ bulk(useCase: UseCaseDescriptor, selection: EntitySelection<Entity>): Effect.Effect<readonly BulkOutcome[], EntifixFailure>;
28
33
  }
29
34
  //# sourceMappingURL=use-case-runner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-case-runner.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/use-case-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAEnE;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GACnB,WAAW,MAAM,EACjB,YAAY,MAAM,EAClB,SAAS,cAAc,KACtB,IAAI,MAAM,EAG0B,CAAC;AAExC;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,oEAAoE;IACpE,GAAG,CACD,OAAO,EAAE,iBAAiB,EAC1B,EAAE,CAAC,EAAE,QAAQ,GACZ,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC;IAC5C,qEAAqE;IACrE,IAAI,CACF,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,eAAe,CAAC,MAAM,CAAC,GACjC,MAAM,CAAC,MAAM,CAAC,SAAS,WAAW,EAAE,EAAE,mBAAmB,CAAC,CAAC;CAC/D"}
1
+ {"version":3,"file":"use-case-runner.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/use-case-runner.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4DAA4D,CAAC;AACpG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mEAAmE,CAAC;AACxG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAErD;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,GACnB,WAAW,MAAM,EACjB,YAAY,MAAM,EAClB,SAAS,cAAc,KACtB,IAAI,MAAM,EAG0B,CAAC;AAExC;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,GAAG,CACD,OAAO,EAAE,iBAAiB,EAC1B,EAAE,CAAC,EAAE,QAAQ,GACZ,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC;IACvD,qEAAqE;IACrE,IAAI,CACF,OAAO,EAAE,iBAAiB,EAC1B,SAAS,EAAE,eAAe,CAAC,MAAM,CAAC,GACjC,MAAM,CAAC,MAAM,CAAC,SAAS,WAAW,EAAE,EAAE,cAAc,CAAC,CAAC;CAC1D"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/use-case-runner/use-case-runner.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type { UseCaseDescriptor } from '../entity-definition/describe/describe-entity-use-cases.js';\nimport type { UseCaseBinding } from '../entity-definition/meta-entities/meta-use-case/meta-use-case.js';\nimport type { TransitionalFailure } from '../failure/failure.js';\nimport type { BulkOutcome } from '../types/BulkOutcome.js';\nimport type { Entity, EntityId } from '../types/Entity.js';\nimport type { EntitySelection } from '../types/EntitySelection.js';\n\n/**\n * The path a verb is served at, from its entity's key, its own key and its\n * binding\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)):\n * a verb on one record is `POST /api/<entity>/:id/<verb>`, one on a selection\n * or on nothing is `POST /api/<entity>/<verb>`. The shell serves it there and a\n * client calls it there, so the two cannot disagree.\n */\nexport const verbPath = (\n entityKey: string,\n useCaseKey: string,\n binding: UseCaseBinding,\n): `/${string}` =>\n binding === 'entity'\n ? `/api/${entityKey}/:id/${useCaseKey}`\n : `/api/${entityKey}/${useCaseKey}`;\n\n/**\n * Runs an entity's verbs for a screen — over REST against the service that\n * serves them, or in-process for a host whose records live in the browser.\n * Chosen at composition, the way a repository is, so a generated screen runs\n * a verb without knowing which.\n */\nexport interface EntityUseCaseRunner {\n /** Runs a verb on one record, or on nothing for an unbound verb. */\n run(\n useCase: UseCaseDescriptor,\n id?: EntityId,\n ): Effect.Effect<void, TransitionalFailure>;\n /** Runs a collection verb on a selection, one outcome per record. */\n bulk(\n useCase: UseCaseDescriptor,\n selection: EntitySelection<Entity>,\n ): Effect.Effect<readonly BulkOutcome[], TransitionalFailure>;\n}\n"],"names":["verbPath","entityKey","useCaseKey","binding"],"mappings":"AASA;;;;;;;CAOC,GACD,OAAO,MAAMA,WAAW,CACtBC,WACAC,YACAC,UAEAA,YAAY,WACR,CAAC,KAAK,EAAEF,UAAU,KAAK,EAAEC,YAAY,GACrC,CAAC,KAAK,EAAED,UAAU,CAAC,EAAEC,YAAY,CAAC"}
1
+ {"version":3,"sources":["../../src/use-case-runner/use-case-runner.ts"],"sourcesContent":["import type { Effect } from 'effect';\n\nimport type { UseCaseDescriptor } from '../entity-definition/describe/describe-entity-use-cases.js';\nimport type { UseCaseBinding } from '../entity-definition/meta-entities/meta-use-case/meta-use-case.js';\nimport type { EntifixFailure } from '../failure/failure.js';\nimport type { BulkOutcome } from '../types/BulkOutcome.js';\nimport type { Entity, EntityId } from '../types/Entity.js';\nimport type { EntitySelection } from '../types/EntitySelection.js';\nimport type { WriteResult } from './write-result.js';\n\n/**\n * The path a verb is served at, from its entity's key, its own key and its\n * binding\n * ([ADR 0020](../../../../../docs/adr/0020-endpoints-are-descriptors-and-the-shell-builds-an-httpapi.md)):\n * a verb on one record is `POST /api/<entity>/:id/<verb>`, one on a selection\n * or on nothing is `POST /api/<entity>/<verb>`. The shell serves it there and a\n * client calls it there, so the two cannot disagree.\n */\nexport const verbPath = (\n entityKey: string,\n useCaseKey: string,\n binding: UseCaseBinding,\n): `/${string}` =>\n binding === 'entity'\n ? `/api/${entityKey}/:id/${useCaseKey}`\n : `/api/${entityKey}/${useCaseKey}`;\n\n/**\n * Runs an entity's verbs for a screen — over REST against the service that\n * serves them, or in-process for a host whose records live in the browser.\n * Chosen at composition, the way a repository is, so a generated screen runs\n * a verb without knowing which.\n */\nexport interface EntityUseCaseRunner {\n /**\n * Runs a verb on one record, or on nothing for an unbound verb. A verb that\n * starts a flow answers {@link Pending}; one that finished answers\n * {@link Settled} with what the service sent back.\n */\n run(\n useCase: UseCaseDescriptor,\n id?: EntityId,\n ): Effect.Effect<WriteResult<unknown>, EntifixFailure>;\n /** Runs a collection verb on a selection, one outcome per record. */\n bulk(\n useCase: UseCaseDescriptor,\n selection: EntitySelection<Entity>,\n ): Effect.Effect<readonly BulkOutcome[], EntifixFailure>;\n}\n"],"names":["verbPath","entityKey","useCaseKey","binding"],"mappings":"AAUA;;;;;;;CAOC,GACD,OAAO,MAAMA,WAAW,CACtBC,WACAC,YACAC,UAEAA,YAAY,WACR,CAAC,KAAK,EAAEF,UAAU,KAAK,EAAEC,YAAY,GACrC,CAAC,KAAK,EAAED,UAAU,CAAC,EAAEC,YAAY,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Where a flow can be watched: its status read and its stream.
3
+ *
4
+ * The same two links a `202 flowAccepted` body carries.
5
+ */
6
+ export interface FlowLink {
7
+ readonly rel: 'status' | 'stream';
8
+ readonly href: string;
9
+ }
10
+ /** A write that happened: `200` or `201`, and what the service answered. */
11
+ export interface Settled<T> {
12
+ readonly _tag: 'settled';
13
+ readonly value: T;
14
+ }
15
+ /**
16
+ * A write handed to a flow: `202 flowAccepted`. Nothing about its outcome is
17
+ * known yet, and nothing here claims one — only the flow's own events say
18
+ * whether it completed
19
+ * ([ADR 0022](../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).
20
+ */
21
+ export interface Pending {
22
+ readonly _tag: 'pending';
23
+ readonly flowId: string;
24
+ readonly links: readonly FlowLink[];
25
+ }
26
+ /**
27
+ * What a save, a delete or a verb answers. The server picks the mode; a
28
+ * client handles both through one API and never branches on a status code.
29
+ */
30
+ export type WriteResult<T> = Settled<T> | Pending;
31
+ export declare const settled: <T>(value: T) => Settled<T>;
32
+ export declare const pending: (flowId: string, links?: readonly FlowLink[]) => Pending;
33
+ export declare const isPending: <T>(result: WriteResult<T>) => result is Pending;
34
+ /** The link of `rel` a pending write named, if it named one. */
35
+ export declare const flowLink: (result: Pending, rel: FlowLink["rel"]) => string | undefined;
36
+ //# sourceMappingURL=write-result.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-result.d.ts","sourceRoot":"","sources":["../../src/use-case-runner/write-result.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,GAAG,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,4EAA4E;AAC5E,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAC;CACrC;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAElD,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,OAAO,CAAC,KAAG,OAAO,CAAC,CAAC,CAG7C,CAAC;AAEH,eAAO,MAAM,OAAO,GAClB,QAAQ,MAAM,EACd,QAAO,SAAS,QAAQ,EAAO,KAC9B,OAA+C,CAAC;AAEnD,eAAO,MAAM,SAAS,GAAI,CAAC,EAAE,QAAQ,WAAW,CAAC,CAAC,CAAC,KAAG,MAAM,IAAI,OACrC,CAAC;AAE5B,gEAAgE;AAChE,eAAO,MAAM,QAAQ,GACnB,QAAQ,OAAO,EACf,KAAK,QAAQ,CAAC,KAAK,CAAC,KACnB,MAAM,GAAG,SAA8D,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Where a flow can be watched: its status read and its stream.
3
+ *
4
+ * The same two links a `202 flowAccepted` body carries.
5
+ */ export const settled = (value)=>({
6
+ _tag: 'settled',
7
+ value
8
+ });
9
+ export const pending = (flowId, links = [])=>({
10
+ _tag: 'pending',
11
+ flowId,
12
+ links
13
+ });
14
+ export const isPending = (result)=>result._tag === 'pending';
15
+ /** The link of `rel` a pending write named, if it named one. */ export const flowLink = (result, rel)=>{
16
+ var _result_links_find;
17
+ return (_result_links_find = result.links.find((link)=>link.rel === rel)) == null ? void 0 : _result_links_find.href;
18
+ };
19
+
20
+ //# sourceMappingURL=write-result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/use-case-runner/write-result.ts"],"sourcesContent":["/**\n * Where a flow can be watched: its status read and its stream.\n *\n * The same two links a `202 flowAccepted` body carries.\n */\nexport interface FlowLink {\n readonly rel: 'status' | 'stream';\n readonly href: string;\n}\n\n/** A write that happened: `200` or `201`, and what the service answered. */\nexport interface Settled<T> {\n readonly _tag: 'settled';\n readonly value: T;\n}\n\n/**\n * A write handed to a flow: `202 flowAccepted`. Nothing about its outcome is\n * known yet, and nothing here claims one — only the flow's own events say\n * whether it completed\n * ([ADR 0022](../../../../../docs/adr/0022-two-settle-modes-and-the-pending-flow-store.md)).\n */\nexport interface Pending {\n readonly _tag: 'pending';\n readonly flowId: string;\n readonly links: readonly FlowLink[];\n}\n\n/**\n * What a save, a delete or a verb answers. The server picks the mode; a\n * client handles both through one API and never branches on a status code.\n */\nexport type WriteResult<T> = Settled<T> | Pending;\n\nexport const settled = <T>(value: T): Settled<T> => ({\n _tag: 'settled',\n value,\n});\n\nexport const pending = (\n flowId: string,\n links: readonly FlowLink[] = [],\n): Pending => ({ _tag: 'pending', flowId, links });\n\nexport const isPending = <T>(result: WriteResult<T>): result is Pending =>\n result._tag === 'pending';\n\n/** The link of `rel` a pending write named, if it named one. */\nexport const flowLink = (\n result: Pending,\n rel: FlowLink['rel'],\n): string | undefined => result.links.find(link => link.rel === rel)?.href;\n"],"names":["settled","value","_tag","pending","flowId","links","isPending","result","flowLink","rel","find","link","href"],"mappings":"AAAA;;;;CAIC,GA8BD,OAAO,MAAMA,UAAU,CAAIC,QAA0B,CAAA;QACnDC,MAAM;QACND;IACF,CAAA,EAAG;AAEH,OAAO,MAAME,UAAU,CACrBC,QACAC,QAA6B,EAAE,GAClB,CAAA;QAAEH,MAAM;QAAWE;QAAQC;IAAM,CAAA,EAAG;AAEnD,OAAO,MAAMC,YAAY,CAAIC,SAC3BA,OAAOL,IAAI,KAAK,UAAU;AAE5B,8DAA8D,GAC9D,OAAO,MAAMM,WAAW,CACtBD,QACAE;QACuBF;YAAAA,qBAAAA,OAAOF,KAAK,CAACK,IAAI,CAACC,CAAAA,OAAQA,KAAKF,GAAG,KAAKA,yBAAvCF,mBAA6CK,IAAI;EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"wizard-definition.d.ts","sourceRoot":"","sources":["../../src/wizard/wizard-definition.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,+DAMlB,CAAC;AACX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;A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