@entifix/core 0.22.4 → 0.23.1
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.
- package/dist/entity-definition/describe/describe-entity-columns.d.ts +8 -0
- package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.js +50 -5
- package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts +4 -1
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts.map +1 -1
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js +5 -1
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js.map +1 -1
- package/dist/entity-definition/reconstruct/clone-entity-draft.d.ts.map +1 -1
- package/dist/entity-definition/reconstruct/clone-entity-draft.js +2 -1
- package/dist/entity-definition/reconstruct/clone-entity-draft.js.map +1 -1
- package/dist/entity-definition/reconstruct/coerce-field-value.d.ts.map +1 -1
- package/dist/entity-definition/reconstruct/coerce-field-value.js +1 -1
- package/dist/entity-definition/reconstruct/coerce-field-value.js.map +1 -1
- package/dist/entity-definition/revision.d.ts +30 -0
- package/dist/entity-definition/revision.d.ts.map +1 -0
- package/dist/entity-definition/revision.js +32 -0
- package/dist/entity-definition/revision.js.map +1 -0
- package/dist/entity-definition/validate/validate-records.d.ts.map +1 -1
- package/dist/entity-definition/validate/validate-records.js +1 -0
- package/dist/entity-definition/validate/validate-records.js.map +1 -1
- package/dist/failure/generic.d.ts +17 -2
- package/dist/failure/generic.d.ts.map +1 -1
- package/dist/failure/generic.js +13 -0
- package/dist/failure/generic.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/query/in-memory-query.js +3 -1
- package/dist/query/in-memory-query.js.map +1 -1
- package/package.json +1 -1
|
@@ -68,6 +68,12 @@ export interface EntityFieldDescriptor {
|
|
|
68
68
|
* A screen shows that record's name in its place.
|
|
69
69
|
*/
|
|
70
70
|
references?: MemberReference;
|
|
71
|
+
/**
|
|
72
|
+
* `'none'`: the member travels with the record and is never shown — a form
|
|
73
|
+
* keeps it in its draft without a field, a table without a column. Today
|
|
74
|
+
* only a `revision` member presents as nothing.
|
|
75
|
+
*/
|
|
76
|
+
presentation?: 'none';
|
|
71
77
|
}
|
|
72
78
|
/** Types whose values are scalars a user can meaningfully sort/filter on. */
|
|
73
79
|
export declare const SCALAR_TYPES: readonly MetaAccessorType[];
|
|
@@ -85,6 +91,8 @@ export declare const SCALAR_TYPES: readonly MetaAccessorType[];
|
|
|
85
91
|
* to add silently.
|
|
86
92
|
*/
|
|
87
93
|
export declare const COLLECTION_TYPES: readonly MetaAccessorType[];
|
|
94
|
+
/** The one name a revision member may have: the wire key is part of the contract. */
|
|
95
|
+
export declare const REVISION_MEMBER = "revision";
|
|
88
96
|
/**
|
|
89
97
|
* One parent member per entity. Two would be two trees over the same records,
|
|
90
98
|
* and which one a table indents by would depend on declaration order.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe-entity-columns.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EAEb,KAAK,eAAe,EAEpB,gBAAgB,EAChB,KAAK,WAAW,EACjB,MAAM,yCAAyC,CAAC;AAEjD;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,wEAAwE;IACxE,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,sEAAsE;IACtE,QAAQ,EAAE,OAAO,CAAC;IAClB,kEAAkE;IAClE,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,0FAA0F;IAC1F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,+EAA+E;IAC/E,SAAS,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC/C,6DAA6D;IAC7D,iBAAiB,EAAE,MAAM,CAAC;IAC1B,+EAA+E;IAC/E,kBAAkB,EAAE,MAAM,CAAC;IAC3B,0EAA0E;IAC1E,iBAAiB,EAAE,uBAAuB,CAAC;IAC3C;;;OAGG;IACH,SAAS,CAAC,EAAE,gBAAgB,CAAC;IAC7B;;;OAGG;IACH,YAAY,EAAE,OAAO,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,uDAAuD;IACvD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,UAAU,CAAC,EAAE,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"describe-entity-columns.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB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';
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* A collection member declared
|
|
49
|
-
*
|
|
48
|
+
* A collection member declared sortable is always a mistake, and so is a link
|
|
49
|
+
* or composition collection declared filterable — only a `scalarCollection`
|
|
50
|
+
* may be filtered, an equality on it meaning "any element matches". The
|
|
51
|
+
* mistake breaks the developer rather than the query — the same posture as `applyEntityLinks`
|
|
50
52
|
* throwing on an `embedded` link it cannot build.
|
|
51
53
|
*
|
|
52
54
|
* Silently clamping to `false` was the alternative and is worse: the author
|
|
@@ -54,8 +56,12 @@ import { EnumTones } from '../meta-entities/meta-accessor/index.js';
|
|
|
54
56
|
* result page rather than an error anyone can act on.
|
|
55
57
|
*/ function assertNotQueryable(metaAccessor, type) {
|
|
56
58
|
if (!COLLECTION_TYPES.includes(type)) return;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
// An array of scalars may be filtered (an equality means "any element
|
|
60
|
+
// matches"); sortable stays forbidden for every collection, and a link or
|
|
61
|
+
// composition collection is not filterable either.
|
|
62
|
+
const queryableFilter = type !== 'scalarCollection' && metaAccessor.filterable === true;
|
|
63
|
+
if (metaAccessor.sortable !== true && !queryableFilter) return;
|
|
64
|
+
throw new Error(`"${String(metaAccessor.name)}" is a ${type} and cannot be sortable, and only a scalarCollection may be filterable — member metadata is the server-side query allowlist, and a collection compared as a scalar matches nothing.`);
|
|
59
65
|
}
|
|
60
66
|
/**
|
|
61
67
|
* Item counts belong to a collection, and must be counts. A `minItems` on a
|
|
@@ -94,6 +100,40 @@ import { EnumTones } from '../meta-entities/meta-accessor/index.js';
|
|
|
94
100
|
if (type === 'id' || type === 'string') return;
|
|
95
101
|
throw new Error(`"${String(metaAccessor.name)}" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`);
|
|
96
102
|
}
|
|
103
|
+
/** The one name a revision member may have: the wire key is part of the contract. */ export const REVISION_MEMBER = 'revision';
|
|
104
|
+
/**
|
|
105
|
+
* A revision is the store's, not the author's: it is one number named
|
|
106
|
+
* `revision` that every save carries and no query uses, so it cannot be
|
|
107
|
+
* renamed, required, queried, hidden (it would not be serialized) or
|
|
108
|
+
* `readonly` (the same). One name makes one member, so an entity has one at
|
|
109
|
+
* most. Checked against every
|
|
110
|
+
* accessor before hidden ones are dropped, since a hidden revision is exactly
|
|
111
|
+
* the one describing would never see.
|
|
112
|
+
*/ function assertRevisionMembers(members) {
|
|
113
|
+
const revisions = members.filter((member)=>member.type === 'revision');
|
|
114
|
+
for (const member of revisions){
|
|
115
|
+
const name = String(member.name);
|
|
116
|
+
if (name !== REVISION_MEMBER || member.alias !== undefined) {
|
|
117
|
+
throw new Error(`"${name}" is a revision member and must be named "${REVISION_MEMBER}", with no alias — the wire key is part of the contract.`);
|
|
118
|
+
}
|
|
119
|
+
for (const flag of [
|
|
120
|
+
'required',
|
|
121
|
+
'filterable',
|
|
122
|
+
'sortable',
|
|
123
|
+
'hidden',
|
|
124
|
+
'readonly'
|
|
125
|
+
]){
|
|
126
|
+
if (member[flag] === true) {
|
|
127
|
+
throw new Error(`"${name}" is a revision member and cannot be ${flag} — it travels with every record and is never queried or entered.`);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/** A composition's child has no save of its own, so it carries no revision. */ function assertChildHasNoRevision(child) {
|
|
133
|
+
if (extractMetaAccessors(child).some((member)=>member.type === 'revision')) {
|
|
134
|
+
throw new Error(`${child.name} is the child of a composition and declares a revision member — a child has no save of its own, so its master's revision covers it.`);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
97
137
|
/** A reference's entity, as `@entity({ domain, key })` names it: two kebab-case words. */ const REFERENCE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
98
138
|
/**
|
|
99
139
|
* A reference holds one record's id, so it is an `id` or a `string` member, and
|
|
@@ -215,6 +255,8 @@ function toDescriptor(target, metaAccessor, index, sample) {
|
|
|
215
255
|
assertMoneyType(metaAccessor, type);
|
|
216
256
|
assertEnumTones(metaAccessor, type);
|
|
217
257
|
assertMinWidth(metaAccessor);
|
|
258
|
+
const child = type === 'composition' ? metaAccessor.childType == null ? void 0 : metaAccessor.childType.call(metaAccessor) : undefined;
|
|
259
|
+
if (child !== undefined) assertChildHasNoRevision(child);
|
|
218
260
|
// A localized member is queried one locale at a time (`name.en`), which
|
|
219
261
|
// makes it as queryable as the text each locale holds.
|
|
220
262
|
const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';
|
|
@@ -253,7 +295,9 @@ function toDescriptor(target, metaAccessor, index, sample) {
|
|
|
253
295
|
autocomplete: metaAccessor.autocomplete
|
|
254
296
|
}, {
|
|
255
297
|
parent: (_metaAccessor_parent = metaAccessor.parent) != null ? _metaAccessor_parent : false
|
|
256
|
-
},
|
|
298
|
+
}, type === 'revision' ? {
|
|
299
|
+
presentation: 'none'
|
|
300
|
+
} : {}, metaAccessor.references === undefined ? {} : {
|
|
257
301
|
references: metaAccessor.references
|
|
258
302
|
});
|
|
259
303
|
}
|
|
@@ -276,6 +320,7 @@ function toDescriptor(target, metaAccessor, index, sample) {
|
|
|
276
320
|
*/ export function describeEntityColumns(entityConstructor, sample) {
|
|
277
321
|
const seen = new Set();
|
|
278
322
|
assertParentVisible(extractMetaAccessors(entityConstructor));
|
|
323
|
+
assertRevisionMembers(extractMetaAccessors(entityConstructor));
|
|
279
324
|
const descriptors = extractMetaAccessors(entityConstructor).filter((metaAccessor)=>{
|
|
280
325
|
if (metaAccessor.hidden || metaAccessor.kind !== 'getter') return false;
|
|
281
326
|
const name = String(metaAccessor.name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors, findMetaEntity } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\nimport { assertBounds } from '../meta-entities/bounds.js';\nimport {\n type CardRole,\n type ChildConstructor,\n type EntityLinkSerialization,\n type EnumTone,\n EnumTones,\n type MemberReference,\n MetaAccessor,\n MetaAccessorType,\n type MoneyFormat,\n} from '../meta-entities/meta-accessor/index.js';\n\n/**\n * A displayable member of an entity, resolved from its accessor metadata. This\n * is the contract generic UI builds itself from — a table's columns today, a\n * form's fields later — so it stays framework-free and lives next to the\n * metadata it derives from.\n */\nexport interface EntityFieldDescriptor {\n /** Accessor name. The stable identity used by preferences and slots. */\n name: string;\n /** Wire/property key: `alias ?? name`. */\n key: string;\n label: string;\n /**\n * Catalog key for {@link label}, when the entity declared one. Resolution is\n * the presentation layer's job — core has no locale and no catalogs, and the\n * same descriptor feeds the server-side filter allowlist, where a translated\n * label would be meaningless.\n */\n labelKey?: string;\n type: MetaAccessorType;\n sortable: boolean;\n filterable: boolean;\n order: number;\n /** Cannot be written back. A form shows it but disables its input. */\n readonly: boolean;\n /** Must hold a value. A form rejects submit while it is empty. */\n required: boolean;\n enumValues?: readonly string[];\n /** Catalog prefix for {@link enumValues}; a value reads as `${enumLabelKey}.${value}`. */\n enumLabelKey?: string;\n /** The tone each value reads in as a status, when the member declares them. */\n enumTones?: Readonly<Record<string, EnumTone>>;\n /** Property of a `link` target used as its display label. */\n linkLabelProperty: string;\n /** Property of a `link` target a picker searches on. Defaults to the label. */\n linkSearchProperty: string;\n /** Whether a `link` writes back its foreign key or the inlined target. */\n linkSerialization: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member, resolved from the\n * accessor's thunk. Absent on every other type.\n */\n childType?: ChildConstructor;\n /**\n * The member is dropped when the record is copied — a unique code, an audit\n * stamp. The identity member is always reset and is not flagged.\n */\n resetOnClone: boolean;\n /** The fewest values a collection member may hold. */\n minItems?: number;\n /** The most values a collection member may hold. */\n maxItems?: number;\n /** The `date` member this one may not precede. */\n notBefore?: string;\n /** The member is an amount of money, read as this declares. `number` members only. */\n money?: MoneyFormat;\n /** The narrowest the member's column reads at, in `rem`, when declared. */\n minWidth?: number;\n /** The part the member plays on a record's card, when declared. */\n card?: CardRole;\n /** The member's HTML autofill token, when declared. */\n autocomplete?: string;\n /** This member holds the parent record's id: the entity forms a tree. */\n parent?: boolean;\n /**\n * This member holds the id of a record of another entity, named `domain:key`.\n * A screen shows that record's name in its place.\n */\n references?: MemberReference;\n}\n\n/** Types whose values are scalars a user can meaningfully sort/filter on. */\nexport const SCALAR_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n];\n\n/**\n * Types whose value is a collection. None of them may ever be sorted or\n * filtered: this descriptor is also the **server-side RSQL allowlist**, and an\n * array compared as a scalar matches nothing — so the query would not fail, it\n * would quietly return an empty page.\n *\n * Exported so `describe-entity-columns.spec.ts` can assert that this list,\n * {@link SCALAR_TYPES}, the two reference types and `localized` partition\n * `MetaAccessorTypes` exactly. Nothing in the repo guards `MetaAccessorType`\n * exhaustively — every switch over it has a `default` that treats the value as\n * a string — so that partition spec is what makes an eleventh type impossible\n * to add silently.\n */\nexport const COLLECTION_TYPES: readonly MetaAccessorType[] = [\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n];\n\n/** `productCode` / `product-code` / `product_code` → `Product Code`. */\nfunction humanize(name: string): string {\n return name\n .replace(/[-_]+/g, ' ')\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/\\s+/g, ' ')\n .trim()\n .replace(/^./, first => first.toUpperCase());\n}\n\n/**\n * Best-effort type for accessors that did not declare one. Entities are not\n * required to annotate every member, so a sample row keeps a bare `@accessor()`\n * usable; a declared `type` always wins over this.\n */\nfunction inferType(name: string, value: unknown): MetaAccessorType {\n if (value instanceof EntityLink) return 'link';\n if (value instanceof EntityCollectionLink) return 'linkCollection';\n if (value instanceof Date) return 'date';\n if (typeof value === 'number') return 'number';\n if (typeof value === 'boolean') return 'boolean';\n if (name === 'id') return 'id';\n return 'string';\n}\n\n/**\n * A collection member declared queryable is always a mistake, so it breaks the\n * developer rather than the query — the same posture as `applyEntityLinks`\n * throwing on an `embedded` link it cannot build.\n *\n * Silently clamping to `false` was the alternative and is worse: the author\n * keeps a declaration that reads as honoured, and the symptom is an empty\n * result page rather than an error anyone can act on.\n */\nfunction assertNotQueryable(\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n if (!COLLECTION_TYPES.includes(type)) return;\n if (metaAccessor.sortable !== true && metaAccessor.filterable !== true)\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be sortable or filterable — member metadata is the server-side query allowlist, and a collection compared as a scalar matches nothing.`,\n );\n}\n\n/**\n * Item counts belong to a collection, and must be counts. A `minItems` on a\n * string would read as honoured and constrain nothing.\n */\nfunction assertItemCounts(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { minItems, maxItems } = metaAccessor;\n if (minItems === undefined && maxItems === undefined) return;\n const name = String(metaAccessor.name);\n if (!COLLECTION_TYPES.includes(type)) {\n throw new Error(\n `\"${name}\" is a ${type}, and only a collection can declare minItems or maxItems.`,\n );\n }\n assertBounds(`\"${name}\"`, { min: minItems, max: maxItems });\n}\n\n/**\n * `notBefore` compares two instants, so both ends must be `date` members of\n * the same entity. Checked once every member is described, since the one it\n * names may be declared after it.\n */\nfunction assertNotBefore(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n );\n if (descriptor.type !== 'date' || earlier?.type !== 'date') {\n throw new Error(\n `\"${descriptor.name}\" declares notBefore \"${descriptor.notBefore}\", and both must be date members of the entity.`,\n );\n }\n }\n}\n\n/**\n * A parent is one record's id, so it is an `id` or a `string` member — a\n * number or a date cannot name a record, and a collection would be two\n * parents. Checked per member, since the type is only known once inferred.\n */\nfunction assertParentType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.parent !== true) return;\n if (type === 'id' || type === 'string') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n}\n\n/** A reference's entity, as `@entity({ domain, key })` names it: two kebab-case words. */\nconst REFERENCE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/**\n * A reference holds one record's id, so it is an `id` or a `string` member, and\n * names its target as `domain:key`. On the `parent` member it may only name the\n * entity itself — a parent is a record of the same entity, built into a tree —\n * which is what lets a list show a branch's parent by name.\n */\nfunction assertReference(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n const { references } = metaAccessor;\n if (references === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'id' && type !== 'string') {\n throw new Error(\n `\"${name}\" is a ${type} and declares references — a reference holds one record's id, so it is an id or a string.`,\n );\n }\n if (!REFERENCE_KEY.test(references.entity)) {\n throw new Error(\n `\"${name}\" references \"${references.entity}\", which is not an entity's \"domain:key\" — the pair its @entity({ domain, key }) declares.`,\n );\n }\n const own = findMetaEntity(target);\n if (\n metaAccessor.parent === true &&\n references.entity !== `${own?.domain}:${own?.key}`\n ) {\n throw new Error(\n `\"${name}\" is the parent member and references \"${references.entity}\" — a parent is a record of the same entity, so it can only reference ${target.name} itself.`,\n );\n }\n}\n\n/** Members whose value can name a record: a text, a number, or a reference to one. */\nconst LABEL_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'localized',\n];\n\n/**\n * An entity's `labelMember` must be a visible member that holds one value a\n * person can read: a hidden one never reaches the client, and a collection is\n * many names. Checked against every accessor, since a hidden member is exactly\n * the one describing would never see.\n */\nfunction assertLabelMember(\n target: ChildConstructor,\n descriptors: readonly EntityFieldDescriptor[],\n) {\n const labelMember = findMetaEntity(target)?.labelMember;\n if (labelMember === undefined) return;\n const declared = extractMetaAccessors(target).some(\n metaAccessor => String(metaAccessor.name) === labelMember,\n );\n const descriptor = descriptors.find(other => other.name === labelMember);\n if (descriptor === undefined) {\n throw new Error(\n declared\n ? `${target.name} is called by \"${labelMember}\", which is hidden — a hidden member never reaches the client, so nothing could show the name.`\n : `${target.name} is called by \"${labelMember}\", which is not a member of the entity.`,\n );\n }\n if (\n descriptor.references === undefined &&\n !LABEL_TYPES.includes(descriptor.type)\n ) {\n throw new Error(\n `${target.name} is called by \"${labelMember}\", a ${descriptor.type} — a record is called by a string, a localized text, a number or a reference.`,\n );\n }\n}\n\n/** Money is a reading of a number; any other member declaring it is a mistake. */\nfunction assertMoneyType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.money === undefined || type === 'number') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and declares money — only a number member can be an amount.`,\n );\n}\n\n/**\n * Tones belong to an enum's values: on any other member, or keyed by a value\n * the enum does not have, they would colour nothing — or the wrong thing.\n */\nfunction assertEnumTones(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { enumTones } = metaAccessor;\n if (enumTones === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'enum') {\n throw new Error(\n `\"${name}\" is a ${type} and declares enumTones — only an enum member's values have a tone.`,\n );\n }\n const values = metaAccessor.enumValues ?? [];\n for (const [value, tone] of Object.entries(enumTones)) {\n if (!values.includes(value)) {\n throw new Error(\n `\"${name}\" declares a tone for \"${value}\", which is not one of its enumValues (${values.join(', ')}).`,\n );\n }\n if (!(EnumTones as readonly string[]).includes(tone)) {\n throw new Error(\n `\"${name}\" declares tone \"${String(tone)}\" for \"${value}\" — a tone is one of ${EnumTones.join(', ')}.`,\n );\n }\n }\n}\n\n/** A width is a positive length; zero or less would never switch layouts. */\nfunction assertMinWidth(metaAccessor: MetaAccessor) {\n const { minWidth } = metaAccessor;\n if (minWidth === undefined || (Number.isFinite(minWidth) && minWidth > 0))\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" declares minWidth ${String(minWidth)} — a column's narrowest width is a positive number of rem.`,\n );\n}\n\n/**\n * A `currencyMember` must be a visible `string` member of the same entity: a\n * hidden one never reaches the client, so the amount would print with no\n * currency and nothing would say why.\n */\nfunction assertCurrencyMembers(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n const member = descriptor.money?.currencyMember;\n if (member === undefined) continue;\n const currency = descriptors.find(other => other.name === member);\n if (currency?.type !== 'string') {\n throw new Error(\n `\"${descriptor.name}\" reads its currency from \"${member}\", which must be a visible string member of the entity.`,\n );\n }\n }\n}\n\n/**\n * One parent member per entity. Two would be two trees over the same records,\n * and which one a table indents by would depend on declaration order.\n */\nexport function assertOneParent(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n }[],\n) {\n const parents = members.filter(member => member.parent === true);\n if (parents.length > 1) {\n throw new Error(\n `An entity declares one parent member at most; found ${parents.map(member => `\"${String(member.name)}\"`).join(', ')}.`,\n );\n }\n}\n\n/**\n * ⚠️ **A parent member must travel.** The serializer skips a `hidden` or\n * `readonly` member in both directions, so the parent key would not survive a\n * single trip over the wire and the tree would arrive flat, with nothing\n * failing. Hide it from a table or a form with a slot instead. Checked before\n * hidden members are dropped, since a hidden parent is exactly the one\n * describing would never see.\n */\nexport function assertParentVisible(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n readonly hidden?: boolean;\n readonly readonly?: boolean;\n }[],\n) {\n const stuck = members.find(\n member =>\n member.parent === true &&\n (member.hidden === true || member.readonly === true),\n );\n if (stuck === undefined) return;\n throw new Error(\n `\"${String(stuck.name)}\" is the parent member and is ${stuck.hidden === true ? 'hidden' : 'readonly'} — such a member is never serialized, so the tree would arrive flat. Hide it with a slot instead.`,\n );\n}\n\nfunction toDescriptor(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n index: number,\n sample: unknown,\n): EntityFieldDescriptor {\n const name = String(metaAccessor.name);\n const type =\n metaAccessor.type ??\n inferType(name, (sample as Record<string, unknown> | undefined)?.[name]);\n assertNotQueryable(metaAccessor, type);\n assertItemCounts(metaAccessor, type);\n assertParentType(metaAccessor, type);\n assertReference(target, metaAccessor, type);\n assertMoneyType(metaAccessor, type);\n assertEnumTones(metaAccessor, type);\n assertMinWidth(metaAccessor);\n // A localized member is queried one locale at a time (`name.en`), which\n // makes it as queryable as the text each locale holds.\n const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';\n const linkLabelProperty = metaAccessor.linkLabelProperty ?? 'name';\n\n return {\n name,\n key: String(metaAccessor.alias ?? metaAccessor.name),\n label: metaAccessor.label ?? humanize(name),\n labelKey: metaAccessor.labelKey,\n type,\n sortable: metaAccessor.sortable ?? isScalar,\n filterable: metaAccessor.filterable ?? isScalar,\n order: metaAccessor.order ?? index,\n readonly: metaAccessor.readonly ?? false,\n required: metaAccessor.required ?? false,\n enumValues: metaAccessor.enumValues,\n enumLabelKey: metaAccessor.enumLabelKey,\n ...(metaAccessor.enumTones === undefined\n ? {}\n : { enumTones: metaAccessor.enumTones }),\n linkLabelProperty,\n linkSearchProperty: metaAccessor.linkSearchProperty ?? linkLabelProperty,\n linkSerialization: metaAccessor.linkSerialization ?? 'id',\n childType: metaAccessor.childType?.(),\n resetOnClone: metaAccessor.resetOnClone ?? false,\n minItems: metaAccessor.minItems,\n maxItems: metaAccessor.maxItems,\n notBefore: metaAccessor.notBefore,\n ...(metaAccessor.money === undefined ? {} : { money: metaAccessor.money }),\n ...(metaAccessor.minWidth === undefined\n ? {}\n : { minWidth: metaAccessor.minWidth }),\n ...(metaAccessor.card === undefined ? {} : { card: metaAccessor.card }),\n ...(metaAccessor.autocomplete === undefined\n ? {}\n : { autocomplete: metaAccessor.autocomplete }),\n parent: metaAccessor.parent ?? false,\n ...(metaAccessor.references === undefined\n ? {}\n : { references: metaAccessor.references }),\n };\n}\n\n/**\n * Resolves an entity's displayable members from its accessor metadata, sorted by\n * `order` (declaration order when undeclared).\n *\n * Getter-kind and non-`hidden` mirror the filter {@link serializeEntity} walks,\n * minus its `readonly` exclusion: a read-only member is still worth showing,\n * it just cannot be written back.\n *\n * `sample` is an optional instance used only to infer the `type` of accessors\n * that did not declare one.\n *\n * The target is a {@link ChildConstructor} rather than an `EntityConstructor`,\n * which is wider than it looks: nothing here reads `id`, and a `composition`\n * member's child is a **value** with accessors and no identity. So the same\n * walk describes an entity and describes one row of the collection it owns,\n * from one implementation.\n */\nexport function describeEntityColumns<TTarget extends object>(\n entityConstructor: ChildConstructor<TTarget>,\n sample?: TTarget,\n): EntityFieldDescriptor[] {\n const seen = new Set<string>();\n assertParentVisible(extractMetaAccessors(entityConstructor));\n\n const descriptors = extractMetaAccessors(entityConstructor)\n .filter(metaAccessor => {\n if (metaAccessor.hidden || metaAccessor.kind !== 'getter') return false;\n const name = String(metaAccessor.name);\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n })\n .map((metaAccessor, index) =>\n toDescriptor(entityConstructor, metaAccessor, index, sample),\n )\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n assertLabelMember(entityConstructor, descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","findMetaEntity","EntityCollectionLink","EntityLink","assertBounds","EnumTones","SCALAR_TYPES","COLLECTION_TYPES","humanize","name","replace","trim","first","toUpperCase","inferType","value","Date","assertNotQueryable","metaAccessor","type","includes","sortable","filterable","Error","String","assertItemCounts","minItems","maxItems","undefined","min","max","assertNotBefore","descriptors","descriptor","notBefore","earlier","find","other","assertParentType","parent","REFERENCE_KEY","assertReference","target","references","test","entity","own","domain","key","LABEL_TYPES","assertLabelMember","labelMember","declared","some","assertMoneyType","money","assertEnumTones","enumTones","values","enumValues","tone","Object","entries","join","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","alias","label","labelKey","order","required","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","card","autocomplete","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","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dC,iBAA4C,EAC5ChB,MAAgB;IAEhB,MAAMiB,OAAO,IAAIC;IACjBxB,oBAAoB9E,qBAAqBoG;IAEzC,MAAMpE,cAAchC,qBAAqBoG,mBACtCzB,MAAM,CAACzD,CAAAA;QACN,IAAIA,aAAa8D,MAAM,IAAI9D,aAAaqF,IAAI,KAAK,UAAU,OAAO;QAClE,MAAM9F,OAAOe,OAAON,aAAaT,IAAI;QACrC,IAAI4F,KAAKG,GAAG,CAAC/F,OAAO,OAAO;QAC3B4F,KAAKI,GAAG,CAAChG;QACT,OAAO;IACT,GACCoE,GAAG,CAAC,CAAC3D,cAAciE,QAClBD,aAAakB,mBAAmBlF,cAAciE,OAAOC,SAEtDsB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKjB,KAAK,GAAGkB,MAAMlB,KAAK;IACjD3D,gBAAgBC;IAChBoC,sBAAsBpC;IACtBwC,gBAAgBxC;IAChBkB,kBAAkBkD,mBAAmBpE;IACrC,OAAOA;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors, findMetaEntity } from '../helpers/index.js';\nimport { EntityCollectionLink } from '../links/entity-collection-link/index.js';\nimport { EntityLink } from '../links/entity-link/index.js';\nimport { assertBounds } from '../meta-entities/bounds.js';\nimport {\n type CardRole,\n type ChildConstructor,\n type EntityLinkSerialization,\n type EnumTone,\n EnumTones,\n type MemberReference,\n MetaAccessor,\n MetaAccessorType,\n type MoneyFormat,\n} from '../meta-entities/meta-accessor/index.js';\n\n/**\n * A displayable member of an entity, resolved from its accessor metadata. This\n * is the contract generic UI builds itself from — a table's columns today, a\n * form's fields later — so it stays framework-free and lives next to the\n * metadata it derives from.\n */\nexport interface EntityFieldDescriptor {\n /** Accessor name. The stable identity used by preferences and slots. */\n name: string;\n /** Wire/property key: `alias ?? name`. */\n key: string;\n label: string;\n /**\n * Catalog key for {@link label}, when the entity declared one. Resolution is\n * the presentation layer's job — core has no locale and no catalogs, and the\n * same descriptor feeds the server-side filter allowlist, where a translated\n * label would be meaningless.\n */\n labelKey?: string;\n type: MetaAccessorType;\n sortable: boolean;\n filterable: boolean;\n order: number;\n /** Cannot be written back. A form shows it but disables its input. */\n readonly: boolean;\n /** Must hold a value. A form rejects submit while it is empty. */\n required: boolean;\n enumValues?: readonly string[];\n /** Catalog prefix for {@link enumValues}; a value reads as `${enumLabelKey}.${value}`. */\n enumLabelKey?: string;\n /** The tone each value reads in as a status, when the member declares them. */\n enumTones?: Readonly<Record<string, EnumTone>>;\n /** Property of a `link` target used as its display label. */\n linkLabelProperty: string;\n /** Property of a `link` target a picker searches on. Defaults to the label. */\n linkSearchProperty: string;\n /** Whether a `link` writes back its foreign key or the inlined target. */\n linkSerialization: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member, resolved from the\n * accessor's thunk. Absent on every other type.\n */\n childType?: ChildConstructor;\n /**\n * The member is dropped when the record is copied — a unique code, an audit\n * stamp. The identity member is always reset and is not flagged.\n */\n resetOnClone: boolean;\n /** The fewest values a collection member may hold. */\n minItems?: number;\n /** The most values a collection member may hold. */\n maxItems?: number;\n /** The `date` member this one may not precede. */\n notBefore?: string;\n /** The member is an amount of money, read as this declares. `number` members only. */\n money?: MoneyFormat;\n /** The narrowest the member's column reads at, in `rem`, when declared. */\n minWidth?: number;\n /** The part the member plays on a record's card, when declared. */\n card?: CardRole;\n /** The member's HTML autofill token, when declared. */\n autocomplete?: string;\n /** This member holds the parent record's id: the entity forms a tree. */\n parent?: boolean;\n /**\n * This member holds the id of a record of another entity, named `domain:key`.\n * A screen shows that record's name in its place.\n */\n references?: MemberReference;\n /**\n * `'none'`: the member travels with the record and is never shown — a form\n * keeps it in its draft without a field, a table without a column. Today\n * only a `revision` member presents as nothing.\n */\n presentation?: 'none';\n}\n\n/** Types whose values are scalars a user can meaningfully sort/filter on. */\nexport const SCALAR_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n];\n\n/**\n * Types whose value is a collection. None of them may ever be sorted or\n * filtered: this descriptor is also the **server-side RSQL allowlist**, and an\n * array compared as a scalar matches nothing — so the query would not fail, it\n * would quietly return an empty page.\n *\n * Exported so `describe-entity-columns.spec.ts` can assert that this list,\n * {@link SCALAR_TYPES}, the two reference types and `localized` partition\n * `MetaAccessorTypes` exactly. Nothing in the repo guards `MetaAccessorType`\n * exhaustively — every switch over it has a `default` that treats the value as\n * a string — so that partition spec is what makes an eleventh type impossible\n * to add silently.\n */\nexport const COLLECTION_TYPES: readonly MetaAccessorType[] = [\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n];\n\n/** `productCode` / `product-code` / `product_code` → `Product Code`. */\nfunction humanize(name: string): string {\n return name\n .replace(/[-_]+/g, ' ')\n .replace(/([a-z0-9])([A-Z])/g, '$1 $2')\n .replace(/\\s+/g, ' ')\n .trim()\n .replace(/^./, first => first.toUpperCase());\n}\n\n/**\n * Best-effort type for accessors that did not declare one. Entities are not\n * required to annotate every member, so a sample row keeps a bare `@accessor()`\n * usable; a declared `type` always wins over this.\n */\nfunction inferType(name: string, value: unknown): MetaAccessorType {\n if (value instanceof EntityLink) return 'link';\n if (value instanceof EntityCollectionLink) return 'linkCollection';\n if (value instanceof Date) return 'date';\n if (typeof value === 'number') return 'number';\n if (typeof value === 'boolean') return 'boolean';\n if (name === 'id') return 'id';\n return 'string';\n}\n\n/**\n * A collection member declared sortable is always a mistake, and so is a link\n * or composition collection declared filterable — only a `scalarCollection`\n * may be filtered, an equality on it meaning \"any element matches\". The\n * mistake breaks the developer rather than the query — the same posture as `applyEntityLinks`\n * throwing on an `embedded` link it cannot build.\n *\n * Silently clamping to `false` was the alternative and is worse: the author\n * keeps a declaration that reads as honoured, and the symptom is an empty\n * result page rather than an error anyone can act on.\n */\nfunction assertNotQueryable(\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n if (!COLLECTION_TYPES.includes(type)) return;\n // An array of scalars may be filtered (an equality means \"any element\n // matches\"); sortable stays forbidden for every collection, and a link or\n // composition collection is not filterable either.\n const queryableFilter =\n type !== 'scalarCollection' && metaAccessor.filterable === true;\n if (metaAccessor.sortable !== true && !queryableFilter) return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be sortable, and only a scalarCollection may be filterable — member metadata is the server-side query allowlist, and a collection compared as a scalar matches nothing.`,\n );\n}\n\n/**\n * Item counts belong to a collection, and must be counts. A `minItems` on a\n * string would read as honoured and constrain nothing.\n */\nfunction assertItemCounts(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { minItems, maxItems } = metaAccessor;\n if (minItems === undefined && maxItems === undefined) return;\n const name = String(metaAccessor.name);\n if (!COLLECTION_TYPES.includes(type)) {\n throw new Error(\n `\"${name}\" is a ${type}, and only a collection can declare minItems or maxItems.`,\n );\n }\n assertBounds(`\"${name}\"`, { min: minItems, max: maxItems });\n}\n\n/**\n * `notBefore` compares two instants, so both ends must be `date` members of\n * the same entity. Checked once every member is described, since the one it\n * names may be declared after it.\n */\nfunction assertNotBefore(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n );\n if (descriptor.type !== 'date' || earlier?.type !== 'date') {\n throw new Error(\n `\"${descriptor.name}\" declares notBefore \"${descriptor.notBefore}\", and both must be date members of the entity.`,\n );\n }\n }\n}\n\n/**\n * A parent is one record's id, so it is an `id` or a `string` member — a\n * number or a date cannot name a record, and a collection would be two\n * parents. Checked per member, since the type is only known once inferred.\n */\nfunction assertParentType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.parent !== true) return;\n if (type === 'id' || type === 'string') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and cannot be the parent member — a parent is one record's id, so it is an id or a string.`,\n );\n}\n\n/** The one name a revision member may have: the wire key is part of the contract. */\nexport const REVISION_MEMBER = 'revision';\n\n/**\n * A revision is the store's, not the author's: it is one number named\n * `revision` that every save carries and no query uses, so it cannot be\n * renamed, required, queried, hidden (it would not be serialized) or\n * `readonly` (the same). One name makes one member, so an entity has one at\n * most. Checked against every\n * accessor before hidden ones are dropped, since a hidden revision is exactly\n * the one describing would never see.\n */\nfunction assertRevisionMembers(members: readonly MetaAccessor[]) {\n const revisions = members.filter(member => member.type === 'revision');\n for (const member of revisions) {\n const name = String(member.name);\n if (name !== REVISION_MEMBER || member.alias !== undefined) {\n throw new Error(\n `\"${name}\" is a revision member and must be named \"${REVISION_MEMBER}\", with no alias — the wire key is part of the contract.`,\n );\n }\n for (const flag of [\n 'required',\n 'filterable',\n 'sortable',\n 'hidden',\n 'readonly',\n ] as const) {\n if (member[flag] === true) {\n throw new Error(\n `\"${name}\" is a revision member and cannot be ${flag} — it travels with every record and is never queried or entered.`,\n );\n }\n }\n }\n}\n\n/** A composition's child has no save of its own, so it carries no revision. */\nfunction assertChildHasNoRevision(child: ChildConstructor) {\n if (extractMetaAccessors(child).some(member => member.type === 'revision')) {\n throw new Error(\n `${child.name} is the child of a composition and declares a revision member — a child has no save of its own, so its master's revision covers it.`,\n );\n }\n}\n\n/** A reference's entity, as `@entity({ domain, key })` names it: two kebab-case words. */\nconst REFERENCE_KEY = /^[a-z0-9]+(?:-[a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*$/;\n\n/**\n * A reference holds one record's id, so it is an `id` or a `string` member, and\n * names its target as `domain:key`. On the `parent` member it may only name the\n * entity itself — a parent is a record of the same entity, built into a tree —\n * which is what lets a list show a branch's parent by name.\n */\nfunction assertReference(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n type: MetaAccessorType,\n) {\n const { references } = metaAccessor;\n if (references === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'id' && type !== 'string') {\n throw new Error(\n `\"${name}\" is a ${type} and declares references — a reference holds one record's id, so it is an id or a string.`,\n );\n }\n if (!REFERENCE_KEY.test(references.entity)) {\n throw new Error(\n `\"${name}\" references \"${references.entity}\", which is not an entity's \"domain:key\" — the pair its @entity({ domain, key }) declares.`,\n );\n }\n const own = findMetaEntity(target);\n if (\n metaAccessor.parent === true &&\n references.entity !== `${own?.domain}:${own?.key}`\n ) {\n throw new Error(\n `\"${name}\" is the parent member and references \"${references.entity}\" — a parent is a record of the same entity, so it can only reference ${target.name} itself.`,\n );\n }\n}\n\n/** Members whose value can name a record: a text, a number, or a reference to one. */\nconst LABEL_TYPES: readonly MetaAccessorType[] = [\n 'string',\n 'number',\n 'localized',\n];\n\n/**\n * An entity's `labelMember` must be a visible member that holds one value a\n * person can read: a hidden one never reaches the client, and a collection is\n * many names. Checked against every accessor, since a hidden member is exactly\n * the one describing would never see.\n */\nfunction assertLabelMember(\n target: ChildConstructor,\n descriptors: readonly EntityFieldDescriptor[],\n) {\n const labelMember = findMetaEntity(target)?.labelMember;\n if (labelMember === undefined) return;\n const declared = extractMetaAccessors(target).some(\n metaAccessor => String(metaAccessor.name) === labelMember,\n );\n const descriptor = descriptors.find(other => other.name === labelMember);\n if (descriptor === undefined) {\n throw new Error(\n declared\n ? `${target.name} is called by \"${labelMember}\", which is hidden — a hidden member never reaches the client, so nothing could show the name.`\n : `${target.name} is called by \"${labelMember}\", which is not a member of the entity.`,\n );\n }\n if (\n descriptor.references === undefined &&\n !LABEL_TYPES.includes(descriptor.type)\n ) {\n throw new Error(\n `${target.name} is called by \"${labelMember}\", a ${descriptor.type} — a record is called by a string, a localized text, a number or a reference.`,\n );\n }\n}\n\n/** Money is a reading of a number; any other member declaring it is a mistake. */\nfunction assertMoneyType(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n if (metaAccessor.money === undefined || type === 'number') return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" is a ${type} and declares money — only a number member can be an amount.`,\n );\n}\n\n/**\n * Tones belong to an enum's values: on any other member, or keyed by a value\n * the enum does not have, they would colour nothing — or the wrong thing.\n */\nfunction assertEnumTones(metaAccessor: MetaAccessor, type: MetaAccessorType) {\n const { enumTones } = metaAccessor;\n if (enumTones === undefined) return;\n const name = String(metaAccessor.name);\n if (type !== 'enum') {\n throw new Error(\n `\"${name}\" is a ${type} and declares enumTones — only an enum member's values have a tone.`,\n );\n }\n const values = metaAccessor.enumValues ?? [];\n for (const [value, tone] of Object.entries(enumTones)) {\n if (!values.includes(value)) {\n throw new Error(\n `\"${name}\" declares a tone for \"${value}\", which is not one of its enumValues (${values.join(', ')}).`,\n );\n }\n if (!(EnumTones as readonly string[]).includes(tone)) {\n throw new Error(\n `\"${name}\" declares tone \"${String(tone)}\" for \"${value}\" — a tone is one of ${EnumTones.join(', ')}.`,\n );\n }\n }\n}\n\n/** A width is a positive length; zero or less would never switch layouts. */\nfunction assertMinWidth(metaAccessor: MetaAccessor) {\n const { minWidth } = metaAccessor;\n if (minWidth === undefined || (Number.isFinite(minWidth) && minWidth > 0))\n return;\n throw new Error(\n `\"${String(metaAccessor.name)}\" declares minWidth ${String(minWidth)} — a column's narrowest width is a positive number of rem.`,\n );\n}\n\n/**\n * A `currencyMember` must be a visible `string` member of the same entity: a\n * hidden one never reaches the client, so the amount would print with no\n * currency and nothing would say why.\n */\nfunction assertCurrencyMembers(descriptors: readonly EntityFieldDescriptor[]) {\n for (const descriptor of descriptors) {\n const member = descriptor.money?.currencyMember;\n if (member === undefined) continue;\n const currency = descriptors.find(other => other.name === member);\n if (currency?.type !== 'string') {\n throw new Error(\n `\"${descriptor.name}\" reads its currency from \"${member}\", which must be a visible string member of the entity.`,\n );\n }\n }\n}\n\n/**\n * One parent member per entity. Two would be two trees over the same records,\n * and which one a table indents by would depend on declaration order.\n */\nexport function assertOneParent(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n }[],\n) {\n const parents = members.filter(member => member.parent === true);\n if (parents.length > 1) {\n throw new Error(\n `An entity declares one parent member at most; found ${parents.map(member => `\"${String(member.name)}\"`).join(', ')}.`,\n );\n }\n}\n\n/**\n * ⚠️ **A parent member must travel.** The serializer skips a `hidden` or\n * `readonly` member in both directions, so the parent key would not survive a\n * single trip over the wire and the tree would arrive flat, with nothing\n * failing. Hide it from a table or a form with a slot instead. Checked before\n * hidden members are dropped, since a hidden parent is exactly the one\n * describing would never see.\n */\nexport function assertParentVisible(\n members: readonly {\n readonly name: string | symbol;\n readonly parent?: boolean;\n readonly hidden?: boolean;\n readonly readonly?: boolean;\n }[],\n) {\n const stuck = members.find(\n member =>\n member.parent === true &&\n (member.hidden === true || member.readonly === true),\n );\n if (stuck === undefined) return;\n throw new Error(\n `\"${String(stuck.name)}\" is the parent member and is ${stuck.hidden === true ? 'hidden' : 'readonly'} — such a member is never serialized, so the tree would arrive flat. Hide it with a slot instead.`,\n );\n}\n\nfunction toDescriptor(\n target: ChildConstructor,\n metaAccessor: MetaAccessor,\n index: number,\n sample: unknown,\n): EntityFieldDescriptor {\n const name = String(metaAccessor.name);\n const type =\n metaAccessor.type ??\n inferType(name, (sample as Record<string, unknown> | undefined)?.[name]);\n assertNotQueryable(metaAccessor, type);\n assertItemCounts(metaAccessor, type);\n assertParentType(metaAccessor, type);\n assertReference(target, metaAccessor, type);\n assertMoneyType(metaAccessor, type);\n assertEnumTones(metaAccessor, type);\n assertMinWidth(metaAccessor);\n const child = type === 'composition' ? metaAccessor.childType?.() : undefined;\n if (child !== undefined) assertChildHasNoRevision(child);\n // A localized member is queried one locale at a time (`name.en`), which\n // makes it as queryable as the text each locale holds.\n const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';\n const linkLabelProperty = metaAccessor.linkLabelProperty ?? 'name';\n\n return {\n name,\n key: String(metaAccessor.alias ?? metaAccessor.name),\n label: metaAccessor.label ?? humanize(name),\n labelKey: metaAccessor.labelKey,\n type,\n sortable: metaAccessor.sortable ?? isScalar,\n filterable: metaAccessor.filterable ?? isScalar,\n order: metaAccessor.order ?? index,\n readonly: metaAccessor.readonly ?? false,\n required: metaAccessor.required ?? false,\n enumValues: metaAccessor.enumValues,\n enumLabelKey: metaAccessor.enumLabelKey,\n ...(metaAccessor.enumTones === undefined\n ? {}\n : { enumTones: metaAccessor.enumTones }),\n linkLabelProperty,\n linkSearchProperty: metaAccessor.linkSearchProperty ?? linkLabelProperty,\n linkSerialization: metaAccessor.linkSerialization ?? 'id',\n childType: metaAccessor.childType?.(),\n resetOnClone: metaAccessor.resetOnClone ?? false,\n minItems: metaAccessor.minItems,\n maxItems: metaAccessor.maxItems,\n notBefore: metaAccessor.notBefore,\n ...(metaAccessor.money === undefined ? {} : { money: metaAccessor.money }),\n ...(metaAccessor.minWidth === undefined\n ? {}\n : { minWidth: metaAccessor.minWidth }),\n ...(metaAccessor.card === undefined ? {} : { card: metaAccessor.card }),\n ...(metaAccessor.autocomplete === undefined\n ? {}\n : { autocomplete: metaAccessor.autocomplete }),\n parent: metaAccessor.parent ?? false,\n ...(type === 'revision' ? { presentation: 'none' as const } : {}),\n ...(metaAccessor.references === undefined\n ? {}\n : { references: metaAccessor.references }),\n };\n}\n\n/**\n * Resolves an entity's displayable members from its accessor metadata, sorted by\n * `order` (declaration order when undeclared).\n *\n * Getter-kind and non-`hidden` mirror the filter {@link serializeEntity} walks,\n * minus its `readonly` exclusion: a read-only member is still worth showing,\n * it just cannot be written back.\n *\n * `sample` is an optional instance used only to infer the `type` of accessors\n * that did not declare one.\n *\n * The target is a {@link ChildConstructor} rather than an `EntityConstructor`,\n * which is wider than it looks: nothing here reads `id`, and a `composition`\n * member's child is a **value** with accessors and no identity. So the same\n * walk describes an entity and describes one row of the collection it owns,\n * from one implementation.\n */\nexport function describeEntityColumns<TTarget extends object>(\n entityConstructor: ChildConstructor<TTarget>,\n sample?: TTarget,\n): EntityFieldDescriptor[] {\n const seen = new Set<string>();\n assertParentVisible(extractMetaAccessors(entityConstructor));\n assertRevisionMembers(extractMetaAccessors(entityConstructor));\n\n const descriptors = extractMetaAccessors(entityConstructor)\n .filter(metaAccessor => {\n if (metaAccessor.hidden || metaAccessor.kind !== 'getter') return false;\n const name = String(metaAccessor.name);\n if (seen.has(name)) return false;\n seen.add(name);\n return true;\n })\n .map((metaAccessor, index) =>\n toDescriptor(entityConstructor, metaAccessor, index, sample),\n )\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n assertLabelMember(entityConstructor, descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","findMetaEntity","EntityCollectionLink","EntityLink","assertBounds","EnumTones","SCALAR_TYPES","COLLECTION_TYPES","humanize","name","replace","trim","first","toUpperCase","inferType","value","Date","assertNotQueryable","metaAccessor","type","includes","queryableFilter","filterable","sortable","Error","String","assertItemCounts","minItems","maxItems","undefined","min","max","assertNotBefore","descriptors","descriptor","notBefore","earlier","find","other","assertParentType","parent","REVISION_MEMBER","assertRevisionMembers","members","revisions","filter","member","alias","flag","assertChildHasNoRevision","child","some","REFERENCE_KEY","assertReference","target","references","test","entity","own","domain","key","LABEL_TYPES","assertLabelMember","labelMember","declared","assertMoneyType","money","assertEnumTones","enumTones","values","enumValues","tone","Object","entries","join","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","currencyMember","currency","assertOneParent","parents","length","map","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","childType","isScalar","linkLabelProperty","label","labelKey","order","required","enumLabelKey","linkSearchProperty","linkSerialization","resetOnClone","card","autocomplete","presentation","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","right"],"mappings":";AAAA,SAASA,oBAAoB,EAAEC,cAAc,QAAQ,sBAAsB;AAC3E,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,UAAU,QAAQ,gCAAgC;AAC3D,SAASC,YAAY,QAAQ,6BAA6B;AAC1D,SAKEC,SAAS,QAKJ,0CAA0C;AA+EjD,2EAA2E,GAC3E,OAAO,MAAMC,eAA4C;IACvD;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC,mBAAgD;IAC3D;IACA;IACA;CACD,CAAC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aAAakB,mBAAmB1F,cAAcyE,OAAOC,SAEtDsB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKjB,KAAK,GAAGkB,MAAMlB,KAAK;IACjDlE,gBAAgBC;IAChB8C,sBAAsB9C;IACtBiD,gBAAgBjD;IAChB6B,kBAAkB8C,mBAAmB3E;IACrC,OAAOA;AACT"}
|
|
@@ -5,10 +5,13 @@ export type MetaAccessorKind = 'getter' | 'setter';
|
|
|
5
5
|
* TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,
|
|
6
6
|
* sorted and filtered differently.
|
|
7
7
|
*
|
|
8
|
+
* `revision` is a number the store owns: the version of the record a save read
|
|
9
|
+
* (ADR 0032). It travels in the body, and presents as nothing.
|
|
10
|
+
*
|
|
8
11
|
* `localized` holds a text per locale (`LocalizedText`). It is queried only
|
|
9
12
|
* through one locale at a time — `name.en` — never as the whole object.
|
|
10
13
|
*/
|
|
11
|
-
export declare const MetaAccessorTypes: readonly ["string", "number", "boolean", "date", "enum", "id", "link", "linkCollection", "composition", "scalarCollection", "localized"];
|
|
14
|
+
export declare const MetaAccessorTypes: readonly ["string", "number", "boolean", "date", "enum", "id", "link", "linkCollection", "composition", "scalarCollection", "localized", "revision"];
|
|
12
15
|
export type MetaAccessorType = (typeof MetaAccessorTypes)[number];
|
|
13
16
|
/**
|
|
14
17
|
* The class whose accessors describe one row of a `composition` member.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-accessor.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"meta-accessor.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAEnD;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AAO,CAAC;IAChC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,CAAC,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;IAC7B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAM7B,IAAI,EAAE,MAAM,GAAG,MAAM,EACrB,IAAI,EAAE,gBAAgB,EACtB,OAAO,CAAC,EAAE,mBAAmB;CAuChC"}
|
|
@@ -4,6 +4,9 @@
|
|
|
4
4
|
* TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,
|
|
5
5
|
* sorted and filtered differently.
|
|
6
6
|
*
|
|
7
|
+
* `revision` is a number the store owns: the version of the record a save read
|
|
8
|
+
* (ADR 0032). It travels in the body, and presents as nothing.
|
|
9
|
+
*
|
|
7
10
|
* `localized` holds a text per locale (`LocalizedText`). It is queried only
|
|
8
11
|
* through one locale at a time — `name.en` — never as the whole object.
|
|
9
12
|
*/ export const MetaAccessorTypes = [
|
|
@@ -17,7 +20,8 @@
|
|
|
17
20
|
'linkCollection',
|
|
18
21
|
'composition',
|
|
19
22
|
'scalarCollection',
|
|
20
|
-
'localized'
|
|
23
|
+
'localized',
|
|
24
|
+
'revision'
|
|
21
25
|
];
|
|
22
26
|
/**
|
|
23
27
|
* The wire shape a relation takes: the target's foreign key, or the whole
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"sourcesContent":["export type MetaAccessorKind = 'getter' | 'setter';\n\n/**\n * The kinds of value an accessor can hold, as far as generic UI and adapters\n * care. It is deliberately a presentation/behaviour taxonomy rather than a\n * TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,\n * sorted and filtered differently.\n *\n * `localized` holds a text per locale (`LocalizedText`). It is queried only\n * through one locale at a time — `name.en` — never as the whole object.\n */\nexport const MetaAccessorTypes = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n 'id',\n 'link',\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n 'localized',\n] as const;\nexport type MetaAccessorType = (typeof MetaAccessorTypes)[number];\n\n/**\n * The class whose accessors describe one row of a `composition` member.\n *\n * Deliberately not `EntityConstructor`: a child of a composition is a **value**,\n * not an entity. It has no identity of its own, is never addressed apart from\n * the master that holds it, and therefore has no `id` for `Entity` to require.\n * What it does have is `@accessor()` metadata, which is written to its own\n * class's `Symbol.metadata` bag independently of `@entity()` — so a child is\n * described by its accessors and by nothing else.\n *\n * ⚠️ It is a **shape declaration, not a runtime constructor contract.** Children\n * arrive off the wire as plain objects — the serializer walks `instanceof\n * EntityLink`, not the declared type, so an embedded array passes straight\n * through — and an autosaved draft may hold nothing that does not survive a\n * JSON round trip anyway. Nothing may branch on `instanceof` against this constructor.\n */\nexport type ChildConstructor<TChild extends object = object> = new (\n // Mirrors `EntityConstructor`: the arguments are the child's business, only\n // the class identity matters here.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => TChild;\n\n/**\n * The wire shape a relation takes: the target's foreign key, or the whole\n * target inlined. Declared here rather than next to `EntityLink` because it is\n * metadata about a member, not state of a link instance.\n */\nexport const EntityLinkSerializations = ['id', 'embedded'] as const;\nexport type EntityLinkSerialization = (typeof EntityLinkSerializations)[number];\n\nexport interface MetaAccessorOptions {\n alias?: string;\n type?: MetaAccessorType;\n readonly?: boolean;\n hidden?: boolean;\n /** Member must hold a value. Drives form validation; defaults to optional. */\n required?: boolean;\n /** Human label for UI. Falls back to a humanized `name`. */\n label?: string;\n /**\n * Translation key for the label, resolved by the presentation layer. Takes\n * precedence over `label`, which stays as the untranslated fallback for a\n * member that has no catalog entry yet.\n *\n * Keys mirror the entity's own `@entity({ key })`, so they are derivable\n * rather than invented: `entity:product-specification.fields.code`.\n */\n labelKey?: string;\n /** Opt in/out of sorting controls. Defaults per `type`. */\n sortable?: boolean;\n /** Opt in/out of filtering controls. Defaults per `type`. */\n filterable?: boolean;\n /** Default position among the entity's members; ties keep declaration order. */\n order?: number;\n /** Allowed values when `type` is `enum` — drives the filter value control. */\n enumValues?: readonly string[];\n /**\n * Catalog prefix for those values; a value's label is `${enumLabelKey}.${value}`.\n * Explicit rather than derived from `labelKey`, so a member whose values are\n * shared with another member can point both at one vocabulary.\n */\n enumLabelKey?: string;\n /**\n * The tone each value reads in where it is shown as a status: `success`,\n * `warning`, `danger`, `info` or `neutral`. Legal only on an `enum` member,\n * and every key must be one of its {@link enumValues}; a value left out reads\n * `neutral`. Declared, a screen shows the value as a tag in that tone beside\n * its words; undeclared, the value stays plain text — not every enum is a\n * status. Presentation only.\n */\n enumTones?: Readonly<Record<string, EnumTone>>;\n /** Property of a `link` target used as its display label. Default `name`. */\n linkLabelProperty?: string;\n /**\n * Property of a `link` target a picker searches on. Defaults to\n * {@link linkLabelProperty} — you search for what you read. It must be\n * `filterable` on the target entity, since member metadata is also the\n * server-side filter allowlist.\n */\n linkSearchProperty?: string;\n /**\n * How a `link` travels when its owner is serialized: as the target's scalar\n * foreign key (`id`, the default) or with the whole target inlined\n * (`embedded`). The serializer decides per *link instance* — it inlines\n * whatever `isLoaded` — so without this the shape a write takes would depend\n * on whether the form happened to hold the target. Declaring it on the entity\n * makes the wire shape a property of the relation instead of an accident of\n * the UI.\n */\n linkSerialization?: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member — the child's own\n * `@accessor()` metadata is what a detail grid renders its columns from.\n *\n * A **thunk**, because a child module and the entity that owns it are usually\n * declared in the same package and a direct reference makes the decorator's\n * evaluation order load-bearing. Deferring the read to first use removes the\n * ordering question entirely, which is the same reason a to-one relation's\n * target is reached through a resolver rather than an import.\n *\n * Meaningless on any other type. There is no inference fallback: an empty\n * array cannot be told apart from an empty `string[]` at runtime, so a\n * collection must be declared.\n */\n childType?: () => ChildConstructor;\n /**\n * Reset this member when the record is copied.\n *\n * It lives on the **accessor**, not on a use case's descriptor, and that is a\n * decision already made: `UseCaseDescriptor` is closed against per-verb\n * payloads, and this is the exact case, because a descriptor that\n * grows a field per verb ends up a union of every verb's arguments. Which\n * members a copy must not carry is a property of the *member* — a unique\n * code, an audit stamp, a sequence number — and it is the same answer however\n * the copy is triggered.\n *\n * The identity member is always reset and needs no flag.\n */\n resetOnClone?: boolean;\n /**\n * The fewest values a collection member may hold — `1` for \"not empty\". Only\n * meaningful on a collection type (`scalarCollection`, `linkCollection`,\n * `composition`); declaring it elsewhere fails when the entity is described.\n *\n * Distinct from {@link required}: on a collection `required` already means\n * \"at least one\", and a `minItems` of two is a fact `required` cannot state.\n */\n minItems?: number;\n /** The most values a collection member may hold. Collection types only. */\n maxItems?: number;\n /**\n * Another `date` member this one may not precede — a period's `end` declares\n * `notBefore: 'start'`. Checked only when both hold a value. Both members must\n * be `date`s, or describing the entity fails.\n */\n notBefore?: string;\n /**\n * This member holds the id of the record's **parent**, another record of\n * the same entity — so the entity forms a tree. At most one member per\n * entity, and it must be an `id` or a `string`; describing the entity fails\n * otherwise.\n *\n * An id rather than a `link` on purpose. A tree is always built from the\n * whole set of its records ({@link buildTree}), never by resolving one parent\n * at a time, so a link's lazy resolution would be a fetch per node that\n * nothing needs. Absent means a root.\n */\n parent?: boolean;\n /**\n * This `id` or `string` member holds the id of a record of another entity,\n * named by the `domain:key` pair that entity's `@entity({ domain, key })`\n * declares — so the declaring package imports nothing of the target's. A\n * screen reads the target's name in its place through the host's\n * `ReferenceLabelsTag` registry, rather than showing the key.\n *\n * Not a `link` on purpose: the target may live in another store, and a\n * `link` invites the storage-layer join that would couple the two, while its\n * accessor would import the target's class across a domain boundary.\n * Presentation and resolution only — to validation, queries, serialization\n * and every adapter the member is still its id.\n */\n references?: MemberReference;\n /**\n * This `number` member is an amount of money, and how to read it: its\n * currency, fixed or held by another member of the same record, and whether\n * the number counts the currency's minor units (cents) or its major ones.\n * Presentation only — the member is still a number to validation, queries\n * and every adapter — so a table prints `Q64,99` rather than `6499`, and a\n * form edits the major amount and writes back the stored one.\n */\n money?: MoneyFormat;\n /**\n * The narrowest this member's column reads at, in `rem`. A table whose\n * visible columns no longer fit side by side becomes a list of cards, so the\n * sum of these is where it switches. Undeclared, the member's type decides.\n * Presentation only.\n */\n minWidth?: number;\n /**\n * The part this member plays on a record's card: its `title` — the heading\n * that links to the record — a `subtitle` under it, a `badge`, a line of\n * `meta`, or `hidden` from the card. Undeclared, the record's first\n * filled-in member is the title, an id is hidden, the first enum is the\n * badge and up to three more members are meta. Presentation only.\n */\n card?: CardRole;\n /**\n * What the member holds about the person filling it in, as an HTML autofill\n * token — `email`, `given-name`, `tel`, `street-address` — so a browser can\n * fill it and assistive tech can say what it is for (WCAG 1.3.5).\n * Presentation only.\n */\n autocomplete?: string;\n}\n\n/**\n * The tone an enum value reads in as a status. Words always go beside it — a\n * tone never carries a meaning alone.\n */\nexport const EnumTones = [\n 'success',\n 'warning',\n 'danger',\n 'info',\n 'neutral',\n] as const;\nexport type EnumTone = (typeof EnumTones)[number];\n\n/** The entity a reference member points at, as `domain:key`. */\nexport interface MemberReference {\n readonly entity: string;\n}\n\n/** The part a member plays on a record's card. */\nexport type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';\n\n/**\n * How a `number` member reads as money: `currency` fixed, or\n * `currencyMember` naming the record's own ISO 4217 code member; `unit`\n * whether the stored number counts minor units (`6499` for 64.99) or major.\n */\nexport type MoneyFormat = { readonly unit: 'minor' | 'major' } & (\n | { readonly currency: string; readonly currencyMember?: never }\n | { readonly currencyMember: string; readonly currency?: never }\n);\n\nexport class MetaAccessor {\n //#region Properties\n\n readonly name: string | symbol;\n readonly kind: MetaAccessorKind;\n readonly alias?: string;\n readonly type?: MetaAccessorType;\n readonly readonly?: boolean;\n readonly hidden?: boolean;\n readonly required?: boolean;\n readonly label?: string;\n readonly labelKey?: string;\n readonly sortable?: boolean;\n readonly filterable?: boolean;\n readonly order?: number;\n readonly enumValues?: readonly string[];\n readonly enumLabelKey?: string;\n readonly enumTones?: Readonly<Record<string, EnumTone>>;\n readonly linkLabelProperty?: string;\n readonly linkSearchProperty?: string;\n readonly linkSerialization?: EntityLinkSerialization;\n readonly childType?: () => ChildConstructor;\n readonly resetOnClone?: boolean;\n readonly minItems?: number;\n readonly maxItems?: number;\n readonly notBefore?: string;\n readonly parent?: boolean;\n readonly references?: MemberReference;\n readonly money?: MoneyFormat;\n readonly minWidth?: number;\n readonly card?: CardRole;\n readonly autocomplete?: string;\n\n //#endregion\n\n //#region Constructors\n constructor(\n name: string | symbol,\n kind: MetaAccessorKind,\n options?: MetaAccessorOptions,\n ) {\n this.name = name;\n this.kind = kind;\n this.alias = options?.alias;\n this.type = options?.type;\n this.readonly = options?.readonly;\n this.hidden = options?.hidden;\n this.required = options?.required;\n this.label = options?.label;\n this.labelKey = options?.labelKey;\n this.sortable = options?.sortable;\n this.filterable = options?.filterable;\n this.order = options?.order;\n this.enumValues = options?.enumValues;\n this.enumLabelKey = options?.enumLabelKey;\n this.enumTones = options?.enumTones;\n this.linkLabelProperty = options?.linkLabelProperty;\n this.linkSearchProperty = options?.linkSearchProperty;\n this.linkSerialization = options?.linkSerialization;\n this.childType = options?.childType;\n this.resetOnClone = options?.resetOnClone;\n this.minItems = options?.minItems;\n this.maxItems = options?.maxItems;\n this.notBefore = options?.notBefore;\n this.parent = options?.parent;\n this.references = options?.references;\n this.money = options?.money;\n this.minWidth = options?.minWidth;\n this.card = options?.card;\n this.autocomplete = options?.autocomplete;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaAccessorTypes","EntityLinkSerializations","EnumTones","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","enumTones","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","references","money","minWidth","card","autocomplete"],"mappings":"AAEA;;;;;;;;CAQC,GACD,OAAO,MAAMA,oBAAoB;IAC/B;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAU;AA0BX;;;;CAIC,GACD,OAAO,MAAMC,2BAA2B;IAAC;IAAM;CAAW,CAAU;AAwKpE;;;CAGC,GACD,OAAO,MAAMC,YAAY;IACvB;IACA;IACA;IACA;IACA;CACD,CAAU;AAqBX,OAAO,MAAMC;IAiCX,YAAY;IAEZ,sBAAsB;IACtB,YACEC,IAAqB,EACrBC,IAAsB,EACtBC,OAA6B,CAC7B;QACA,IAAI,CAACF,IAAI,GAAGA;QACZ,IAAI,CAACC,IAAI,GAAGA;QACZ,IAAI,CAACE,KAAK,GAAGD,2BAAAA,QAASC,KAAK;QAC3B,IAAI,CAACC,IAAI,GAAGF,2BAAAA,QAASE,IAAI;QACzB,IAAI,CAACC,QAAQ,GAAGH,2BAAAA,QAASG,QAAQ;QACjC,IAAI,CAACC,MAAM,GAAGJ,2BAAAA,QAASI,MAAM;QAC7B,IAAI,CAACC,QAAQ,GAAGL,2BAAAA,QAASK,QAAQ;QACjC,IAAI,CAACC,KAAK,GAAGN,2BAAAA,QAASM,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGP,2BAAAA,QAASO,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGR,2BAAAA,QAASQ,QAAQ;QACjC,IAAI,CAACC,UAAU,GAAGT,2BAAAA,QAASS,UAAU;QACrC,IAAI,CAACC,KAAK,GAAGV,2BAAAA,QAASU,KAAK;QAC3B,IAAI,CAACC,UAAU,GAAGX,2BAAAA,QAASW,UAAU;QACrC,IAAI,CAACC,YAAY,GAAGZ,2BAAAA,QAASY,YAAY;QACzC,IAAI,CAACC,SAAS,GAAGb,2BAAAA,QAASa,SAAS;QACnC,IAAI,CAACC,iBAAiB,GAAGd,2BAAAA,QAASc,iBAAiB;QACnD,IAAI,CAACC,kBAAkB,GAAGf,2BAAAA,QAASe,kBAAkB;QACrD,IAAI,CAACC,iBAAiB,GAAGhB,2BAAAA,QAASgB,iBAAiB;QACnD,IAAI,CAACC,SAAS,GAAGjB,2BAAAA,QAASiB,SAAS;QACnC,IAAI,CAACC,YAAY,GAAGlB,2BAAAA,QAASkB,YAAY;QACzC,IAAI,CAACC,QAAQ,GAAGnB,2BAAAA,QAASmB,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGpB,2BAAAA,QAASoB,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGrB,2BAAAA,QAASqB,SAAS;QACnC,IAAI,CAACC,MAAM,GAAGtB,2BAAAA,QAASsB,MAAM;QAC7B,IAAI,CAACC,UAAU,GAAGvB,2BAAAA,QAASuB,UAAU;QACrC,IAAI,CAACC,KAAK,GAAGxB,2BAAAA,QAASwB,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGzB,2BAAAA,QAASyB,QAAQ;QACjC,IAAI,CAACC,IAAI,GAAG1B,2BAAAA,QAAS0B,IAAI;QACzB,IAAI,CAACC,YAAY,GAAG3B,2BAAAA,QAAS2B,YAAY;IAC3C;AAQF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-accessor/meta-accessor.ts"],"sourcesContent":["export type MetaAccessorKind = 'getter' | 'setter';\n\n/**\n * The kinds of value an accessor can hold, as far as generic UI and adapters\n * care. It is deliberately a presentation/behaviour taxonomy rather than a\n * TypeScript mirror: `id` and `enum` are strings at runtime but are rendered,\n * sorted and filtered differently.\n *\n * `revision` is a number the store owns: the version of the record a save read\n * (ADR 0032). It travels in the body, and presents as nothing.\n *\n * `localized` holds a text per locale (`LocalizedText`). It is queried only\n * through one locale at a time — `name.en` — never as the whole object.\n */\nexport const MetaAccessorTypes = [\n 'string',\n 'number',\n 'boolean',\n 'date',\n 'enum',\n 'id',\n 'link',\n 'linkCollection',\n 'composition',\n 'scalarCollection',\n 'localized',\n 'revision',\n] as const;\nexport type MetaAccessorType = (typeof MetaAccessorTypes)[number];\n\n/**\n * The class whose accessors describe one row of a `composition` member.\n *\n * Deliberately not `EntityConstructor`: a child of a composition is a **value**,\n * not an entity. It has no identity of its own, is never addressed apart from\n * the master that holds it, and therefore has no `id` for `Entity` to require.\n * What it does have is `@accessor()` metadata, which is written to its own\n * class's `Symbol.metadata` bag independently of `@entity()` — so a child is\n * described by its accessors and by nothing else.\n *\n * ⚠️ It is a **shape declaration, not a runtime constructor contract.** Children\n * arrive off the wire as plain objects — the serializer walks `instanceof\n * EntityLink`, not the declared type, so an embedded array passes straight\n * through — and an autosaved draft may hold nothing that does not survive a\n * JSON round trip anyway. Nothing may branch on `instanceof` against this constructor.\n */\nexport type ChildConstructor<TChild extends object = object> = new (\n // Mirrors `EntityConstructor`: the arguments are the child's business, only\n // the class identity matters here.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ...args: any[]\n) => TChild;\n\n/**\n * The wire shape a relation takes: the target's foreign key, or the whole\n * target inlined. Declared here rather than next to `EntityLink` because it is\n * metadata about a member, not state of a link instance.\n */\nexport const EntityLinkSerializations = ['id', 'embedded'] as const;\nexport type EntityLinkSerialization = (typeof EntityLinkSerializations)[number];\n\nexport interface MetaAccessorOptions {\n alias?: string;\n type?: MetaAccessorType;\n readonly?: boolean;\n hidden?: boolean;\n /** Member must hold a value. Drives form validation; defaults to optional. */\n required?: boolean;\n /** Human label for UI. Falls back to a humanized `name`. */\n label?: string;\n /**\n * Translation key for the label, resolved by the presentation layer. Takes\n * precedence over `label`, which stays as the untranslated fallback for a\n * member that has no catalog entry yet.\n *\n * Keys mirror the entity's own `@entity({ key })`, so they are derivable\n * rather than invented: `entity:product-specification.fields.code`.\n */\n labelKey?: string;\n /** Opt in/out of sorting controls. Defaults per `type`. */\n sortable?: boolean;\n /** Opt in/out of filtering controls. Defaults per `type`. */\n filterable?: boolean;\n /** Default position among the entity's members; ties keep declaration order. */\n order?: number;\n /** Allowed values when `type` is `enum` — drives the filter value control. */\n enumValues?: readonly string[];\n /**\n * Catalog prefix for those values; a value's label is `${enumLabelKey}.${value}`.\n * Explicit rather than derived from `labelKey`, so a member whose values are\n * shared with another member can point both at one vocabulary.\n */\n enumLabelKey?: string;\n /**\n * The tone each value reads in where it is shown as a status: `success`,\n * `warning`, `danger`, `info` or `neutral`. Legal only on an `enum` member,\n * and every key must be one of its {@link enumValues}; a value left out reads\n * `neutral`. Declared, a screen shows the value as a tag in that tone beside\n * its words; undeclared, the value stays plain text — not every enum is a\n * status. Presentation only.\n */\n enumTones?: Readonly<Record<string, EnumTone>>;\n /** Property of a `link` target used as its display label. Default `name`. */\n linkLabelProperty?: string;\n /**\n * Property of a `link` target a picker searches on. Defaults to\n * {@link linkLabelProperty} — you search for what you read. It must be\n * `filterable` on the target entity, since member metadata is also the\n * server-side filter allowlist.\n */\n linkSearchProperty?: string;\n /**\n * How a `link` travels when its owner is serialized: as the target's scalar\n * foreign key (`id`, the default) or with the whole target inlined\n * (`embedded`). The serializer decides per *link instance* — it inlines\n * whatever `isLoaded` — so without this the shape a write takes would depend\n * on whether the form happened to hold the target. Declaring it on the entity\n * makes the wire shape a property of the relation instead of an accident of\n * the UI.\n */\n linkSerialization?: EntityLinkSerialization;\n /**\n * The class describing one row of a `composition` member — the child's own\n * `@accessor()` metadata is what a detail grid renders its columns from.\n *\n * A **thunk**, because a child module and the entity that owns it are usually\n * declared in the same package and a direct reference makes the decorator's\n * evaluation order load-bearing. Deferring the read to first use removes the\n * ordering question entirely, which is the same reason a to-one relation's\n * target is reached through a resolver rather than an import.\n *\n * Meaningless on any other type. There is no inference fallback: an empty\n * array cannot be told apart from an empty `string[]` at runtime, so a\n * collection must be declared.\n */\n childType?: () => ChildConstructor;\n /**\n * Reset this member when the record is copied.\n *\n * It lives on the **accessor**, not on a use case's descriptor, and that is a\n * decision already made: `UseCaseDescriptor` is closed against per-verb\n * payloads, and this is the exact case, because a descriptor that\n * grows a field per verb ends up a union of every verb's arguments. Which\n * members a copy must not carry is a property of the *member* — a unique\n * code, an audit stamp, a sequence number — and it is the same answer however\n * the copy is triggered.\n *\n * The identity member is always reset and needs no flag.\n */\n resetOnClone?: boolean;\n /**\n * The fewest values a collection member may hold — `1` for \"not empty\". Only\n * meaningful on a collection type (`scalarCollection`, `linkCollection`,\n * `composition`); declaring it elsewhere fails when the entity is described.\n *\n * Distinct from {@link required}: on a collection `required` already means\n * \"at least one\", and a `minItems` of two is a fact `required` cannot state.\n */\n minItems?: number;\n /** The most values a collection member may hold. Collection types only. */\n maxItems?: number;\n /**\n * Another `date` member this one may not precede — a period's `end` declares\n * `notBefore: 'start'`. Checked only when both hold a value. Both members must\n * be `date`s, or describing the entity fails.\n */\n notBefore?: string;\n /**\n * This member holds the id of the record's **parent**, another record of\n * the same entity — so the entity forms a tree. At most one member per\n * entity, and it must be an `id` or a `string`; describing the entity fails\n * otherwise.\n *\n * An id rather than a `link` on purpose. A tree is always built from the\n * whole set of its records ({@link buildTree}), never by resolving one parent\n * at a time, so a link's lazy resolution would be a fetch per node that\n * nothing needs. Absent means a root.\n */\n parent?: boolean;\n /**\n * This `id` or `string` member holds the id of a record of another entity,\n * named by the `domain:key` pair that entity's `@entity({ domain, key })`\n * declares — so the declaring package imports nothing of the target's. A\n * screen reads the target's name in its place through the host's\n * `ReferenceLabelsTag` registry, rather than showing the key.\n *\n * Not a `link` on purpose: the target may live in another store, and a\n * `link` invites the storage-layer join that would couple the two, while its\n * accessor would import the target's class across a domain boundary.\n * Presentation and resolution only — to validation, queries, serialization\n * and every adapter the member is still its id.\n */\n references?: MemberReference;\n /**\n * This `number` member is an amount of money, and how to read it: its\n * currency, fixed or held by another member of the same record, and whether\n * the number counts the currency's minor units (cents) or its major ones.\n * Presentation only — the member is still a number to validation, queries\n * and every adapter — so a table prints `Q64,99` rather than `6499`, and a\n * form edits the major amount and writes back the stored one.\n */\n money?: MoneyFormat;\n /**\n * The narrowest this member's column reads at, in `rem`. A table whose\n * visible columns no longer fit side by side becomes a list of cards, so the\n * sum of these is where it switches. Undeclared, the member's type decides.\n * Presentation only.\n */\n minWidth?: number;\n /**\n * The part this member plays on a record's card: its `title` — the heading\n * that links to the record — a `subtitle` under it, a `badge`, a line of\n * `meta`, or `hidden` from the card. Undeclared, the record's first\n * filled-in member is the title, an id is hidden, the first enum is the\n * badge and up to three more members are meta. Presentation only.\n */\n card?: CardRole;\n /**\n * What the member holds about the person filling it in, as an HTML autofill\n * token — `email`, `given-name`, `tel`, `street-address` — so a browser can\n * fill it and assistive tech can say what it is for (WCAG 1.3.5).\n * Presentation only.\n */\n autocomplete?: string;\n}\n\n/**\n * The tone an enum value reads in as a status. Words always go beside it — a\n * tone never carries a meaning alone.\n */\nexport const EnumTones = [\n 'success',\n 'warning',\n 'danger',\n 'info',\n 'neutral',\n] as const;\nexport type EnumTone = (typeof EnumTones)[number];\n\n/** The entity a reference member points at, as `domain:key`. */\nexport interface MemberReference {\n readonly entity: string;\n}\n\n/** The part a member plays on a record's card. */\nexport type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';\n\n/**\n * How a `number` member reads as money: `currency` fixed, or\n * `currencyMember` naming the record's own ISO 4217 code member; `unit`\n * whether the stored number counts minor units (`6499` for 64.99) or major.\n */\nexport type MoneyFormat = { readonly unit: 'minor' | 'major' } & (\n | { readonly currency: string; readonly currencyMember?: never }\n | { readonly currencyMember: string; readonly currency?: never }\n);\n\nexport class MetaAccessor {\n //#region Properties\n\n readonly name: string | symbol;\n readonly kind: MetaAccessorKind;\n readonly alias?: string;\n readonly type?: MetaAccessorType;\n readonly readonly?: boolean;\n readonly hidden?: boolean;\n readonly required?: boolean;\n readonly label?: string;\n readonly labelKey?: string;\n readonly sortable?: boolean;\n readonly filterable?: boolean;\n readonly order?: number;\n readonly enumValues?: readonly string[];\n readonly enumLabelKey?: string;\n readonly enumTones?: Readonly<Record<string, EnumTone>>;\n readonly linkLabelProperty?: string;\n readonly linkSearchProperty?: string;\n readonly linkSerialization?: EntityLinkSerialization;\n readonly childType?: () => ChildConstructor;\n readonly resetOnClone?: boolean;\n readonly minItems?: number;\n readonly maxItems?: number;\n readonly notBefore?: string;\n readonly parent?: boolean;\n readonly references?: MemberReference;\n readonly money?: MoneyFormat;\n readonly minWidth?: number;\n readonly card?: CardRole;\n readonly autocomplete?: string;\n\n //#endregion\n\n //#region Constructors\n constructor(\n name: string | symbol,\n kind: MetaAccessorKind,\n options?: MetaAccessorOptions,\n ) {\n this.name = name;\n this.kind = kind;\n this.alias = options?.alias;\n this.type = options?.type;\n this.readonly = options?.readonly;\n this.hidden = options?.hidden;\n this.required = options?.required;\n this.label = options?.label;\n this.labelKey = options?.labelKey;\n this.sortable = options?.sortable;\n this.filterable = options?.filterable;\n this.order = options?.order;\n this.enumValues = options?.enumValues;\n this.enumLabelKey = options?.enumLabelKey;\n this.enumTones = options?.enumTones;\n this.linkLabelProperty = options?.linkLabelProperty;\n this.linkSearchProperty = options?.linkSearchProperty;\n this.linkSerialization = options?.linkSerialization;\n this.childType = options?.childType;\n this.resetOnClone = options?.resetOnClone;\n this.minItems = options?.minItems;\n this.maxItems = options?.maxItems;\n this.notBefore = options?.notBefore;\n this.parent = options?.parent;\n this.references = options?.references;\n this.money = options?.money;\n this.minWidth = options?.minWidth;\n this.card = options?.card;\n this.autocomplete = options?.autocomplete;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaAccessorTypes","EntityLinkSerializations","EnumTones","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","enumTones","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","references","money","minWidth","card","autocomplete"],"mappings":"AAEA;;;;;;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AI,CAACC,iBAAiB,GAAGhB,2BAAAA,QAASgB,iBAAiB;QACnD,IAAI,CAACC,SAAS,GAAGjB,2BAAAA,QAASiB,SAAS;QACnC,IAAI,CAACC,YAAY,GAAGlB,2BAAAA,QAASkB,YAAY;QACzC,IAAI,CAACC,QAAQ,GAAGnB,2BAAAA,QAASmB,QAAQ;QACjC,IAAI,CAACC,QAAQ,GAAGpB,2BAAAA,QAASoB,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGrB,2BAAAA,QAASqB,SAAS;QACnC,IAAI,CAACC,MAAM,GAAGtB,2BAAAA,QAASsB,MAAM;QAC7B,IAAI,CAACC,UAAU,GAAGvB,2BAAAA,QAASuB,UAAU;QACrC,IAAI,CAACC,KAAK,GAAGxB,2BAAAA,QAASwB,KAAK;QAC3B,IAAI,CAACC,QAAQ,GAAGzB,2BAAAA,QAASyB,QAAQ;QACjC,IAAI,CAACC,IAAI,GAAG1B,2BAAAA,QAAS0B,IAAI;QACzB,IAAI,CAACC,YAAY,GAAG3B,2BAAAA,QAAS2B,YAAY;IAC3C;AAQF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone-entity-draft.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/reconstruct/clone-entity-draft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAyB,MAAM,4BAA4B,CAAC;AAWhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,WAAW,GAClB,WAAW,
|
|
1
|
+
{"version":3,"file":"clone-entity-draft.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/reconstruct/clone-entity-draft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAyB,MAAM,4BAA4B,CAAC;AAWhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,MAAM,EAAE,WAAW,GAClB,WAAW,CAgCb"}
|
|
@@ -48,7 +48,8 @@ import { describeEntityColumns } from '../describe/index.js';
|
|
|
48
48
|
}
|
|
49
49
|
// An `id` member is reset unless it is the parent: a copy of a node is its
|
|
50
50
|
// sibling, and a copy that came out as a root would be moved, not copied.
|
|
51
|
-
|
|
51
|
+
// A `revision` is the original's version of itself: a copy is a create.
|
|
52
|
+
const isIdentityLike = descriptor.type === 'id' && !descriptor.parent || descriptor.type === 'revision';
|
|
52
53
|
if (!isIdentityLike && !descriptor.resetOnClone) continue;
|
|
53
54
|
if (!(descriptor.name in cloned)) continue;
|
|
54
55
|
cloned[descriptor.name] = '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/reconstruct/clone-entity-draft.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { EntityDraft, type EntityDraftValue } from '../../types/EntityDraft.js';\nimport {\n newRowKey,\n readRowDrafts,\n ROW_KEY,\n} from '../../types/EntityRowDraft.js';\nimport { describeEntityColumns } from '../describe/index.js';\n\n/** The member `Entity` requires every record to carry. */\nconst ID_MEMBER = 'id';\n\n/**\n * The draft for a copy of a record: everything the original held, minus the\n * members a copy must not carry.\n *\n * **A draft in and a draft out**, rather than an instance in and an instance\n * out, and that is the whole reason this composes with the rest of the form\n * layer. A form's state is a `Record<string, string>` that a workspace\n * autosaves, so a clone that returned an instance would have to be\n * re-seeded back into a draft by the caller — through `seedFieldValue`, which\n * lives in a package above this one. Staying in the draft keeps the operation\n * on one side of that boundary, and `reconstructEntity` is still what turns the\n * result into an entity at submit.\n *\n * Two kinds of member are dropped:\n *\n * - **the identity member**, always, with no flag — a copy that carries the\n * original's `id` is an update to the original, which is the one outcome a\n * Clone button must never produce;\n * - **anything declared `@accessor({ resetOnClone: true })`** — a unique code,\n * an audit stamp, a sequence number.\n *\n * Cleared to `''` rather than deleted, because `''` is what an empty control\n * drafts as: a member removed from the record entirely would arrive\n * `undefined`, and an input handed `undefined` flips from controlled to\n * uncontrolled — the same trap `restoreEntityDraft` layers a restored draft\n * over a seeded one to avoid.\n *\n * A member the entity declares but the draft never held stays absent, so this\n * neither invents keys nor widens the draft.\n */\nexport function cloneEntityDraft<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n values: EntityDraft,\n): EntityDraft {\n const cloned: EntityDraft = { ...values };\n\n // The identity member, cleared **without consulting the descriptors**.\n // `describeEntityColumns` drops `hidden` members, and a form hiding its id is\n // the ordinary case rather than the exotic one — every generated catalog page\n // does it — so a descriptor-driven sweep would leave the id in place on\n // exactly the forms a Clone button appears on, and the \"copy\" would silently\n // save over the original. `Entity` fixes this member's name, so there is no\n // metadata to consult anyway.\n if (ID_MEMBER in cloned) cloned[ID_MEMBER] = '';\n\n for (const descriptor of describeEntityColumns(entityConstructor)) {\n if (descriptor.type === 'composition') {\n cloned[descriptor.name] = clonedRows(\n cloned[descriptor.name],\n descriptor.resetOnClone,\n );\n continue;\n }\n // An `id` member is reset unless it is the parent: a copy of a node is its\n // sibling, and a copy that came out as a root would be moved, not copied.\n const isIdentityLike
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/reconstruct/clone-entity-draft.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { EntityDraft, type EntityDraftValue } from '../../types/EntityDraft.js';\nimport {\n newRowKey,\n readRowDrafts,\n ROW_KEY,\n} from '../../types/EntityRowDraft.js';\nimport { describeEntityColumns } from '../describe/index.js';\n\n/** The member `Entity` requires every record to carry. */\nconst ID_MEMBER = 'id';\n\n/**\n * The draft for a copy of a record: everything the original held, minus the\n * members a copy must not carry.\n *\n * **A draft in and a draft out**, rather than an instance in and an instance\n * out, and that is the whole reason this composes with the rest of the form\n * layer. A form's state is a `Record<string, string>` that a workspace\n * autosaves, so a clone that returned an instance would have to be\n * re-seeded back into a draft by the caller — through `seedFieldValue`, which\n * lives in a package above this one. Staying in the draft keeps the operation\n * on one side of that boundary, and `reconstructEntity` is still what turns the\n * result into an entity at submit.\n *\n * Two kinds of member are dropped:\n *\n * - **the identity member**, always, with no flag — a copy that carries the\n * original's `id` is an update to the original, which is the one outcome a\n * Clone button must never produce;\n * - **anything declared `@accessor({ resetOnClone: true })`** — a unique code,\n * an audit stamp, a sequence number.\n *\n * Cleared to `''` rather than deleted, because `''` is what an empty control\n * drafts as: a member removed from the record entirely would arrive\n * `undefined`, and an input handed `undefined` flips from controlled to\n * uncontrolled — the same trap `restoreEntityDraft` layers a restored draft\n * over a seeded one to avoid.\n *\n * A member the entity declares but the draft never held stays absent, so this\n * neither invents keys nor widens the draft.\n */\nexport function cloneEntityDraft<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n values: EntityDraft,\n): EntityDraft {\n const cloned: EntityDraft = { ...values };\n\n // The identity member, cleared **without consulting the descriptors**.\n // `describeEntityColumns` drops `hidden` members, and a form hiding its id is\n // the ordinary case rather than the exotic one — every generated catalog page\n // does it — so a descriptor-driven sweep would leave the id in place on\n // exactly the forms a Clone button appears on, and the \"copy\" would silently\n // save over the original. `Entity` fixes this member's name, so there is no\n // metadata to consult anyway.\n if (ID_MEMBER in cloned) cloned[ID_MEMBER] = '';\n\n for (const descriptor of describeEntityColumns(entityConstructor)) {\n if (descriptor.type === 'composition') {\n cloned[descriptor.name] = clonedRows(\n cloned[descriptor.name],\n descriptor.resetOnClone,\n );\n continue;\n }\n // An `id` member is reset unless it is the parent: a copy of a node is its\n // sibling, and a copy that came out as a root would be moved, not copied.\n // A `revision` is the original's version of itself: a copy is a create.\n const isIdentityLike =\n (descriptor.type === 'id' && !descriptor.parent) ||\n descriptor.type === 'revision';\n if (!isIdentityLike && !descriptor.resetOnClone) continue;\n if (!(descriptor.name in cloned)) continue;\n cloned[descriptor.name] = '';\n }\n\n return cloned;\n}\n\n/**\n * The rows a copy starts with.\n *\n * Two things the `''` rule above cannot express. A collection is **emptied to\n * `[]`, never to `''`**: an empty string is not a readable row list, so\n * `reconstructEntity` would skip the member and the \"reset\" collection would\n * come back holding the original's lines — a `resetOnClone` that resets nothing.\n *\n * And a row that *is* copied gets a **fresh key**. The key identifies a row\n * within one editing session; carrying the original's over means the copy and\n * the original name their lines identically, so a workspace holding both open\n * has two tabs whose rows claim the same identity — harmless until anything\n * addresses a row across them, and impossible to debug once it does.\n */\nfunction clonedRows(\n value: EntityDraftValue | undefined,\n reset: boolean,\n): EntityDraftValue {\n if (reset) return [];\n return readRowDrafts(value).map(row => ({ ...row, [ROW_KEY]: newRowKey() }));\n}\n"],"names":["newRowKey","readRowDrafts","ROW_KEY","describeEntityColumns","ID_MEMBER","cloneEntityDraft","entityConstructor","values","cloned","descriptor","type","name","clonedRows","resetOnClone","isIdentityLike","parent","value","reset","map","row"],"mappings":";AAEA,SACEA,SAAS,EACTC,aAAa,EACbC,OAAO,QACF,gCAAgC;AACvC,SAASC,qBAAqB,QAAQ,uBAAuB;AAE7D,wDAAwD,GACxD,MAAMC,YAAY;AAElB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BC,GACD,OAAO,SAASC,iBACdC,iBAA6C,EAC7CC,MAAmB;IAEnB,MAAMC,SAAsB,aAAKD;IAEjC,uEAAuE;IACvE,8EAA8E;IAC9E,8EAA8E;IAC9E,wEAAwE;IACxE,6EAA6E;IAC7E,4EAA4E;IAC5E,8BAA8B;IAC9B,IAAIH,aAAaI,QAAQA,MAAM,CAACJ,UAAU,GAAG;IAE7C,KAAK,MAAMK,cAAcN,sBAAsBG,mBAAoB;QACjE,IAAIG,WAAWC,IAAI,KAAK,eAAe;YACrCF,MAAM,CAACC,WAAWE,IAAI,CAAC,GAAGC,WACxBJ,MAAM,CAACC,WAAWE,IAAI,CAAC,EACvBF,WAAWI,YAAY;YAEzB;QACF;QACA,2EAA2E;QAC3E,0EAA0E;QAC1E,wEAAwE;QACxE,MAAMC,iBACJ,AAACL,WAAWC,IAAI,KAAK,QAAQ,CAACD,WAAWM,MAAM,IAC/CN,WAAWC,IAAI,KAAK;QACtB,IAAI,CAACI,kBAAkB,CAACL,WAAWI,YAAY,EAAE;QACjD,IAAI,CAAEJ,CAAAA,WAAWE,IAAI,IAAIH,MAAK,GAAI;QAClCA,MAAM,CAACC,WAAWE,IAAI,CAAC,GAAG;IAC5B;IAEA,OAAOH;AACT;AAEA;;;;;;;;;;;;;CAaC,GACD,SAASI,WACPI,KAAmC,EACnCC,KAAc;IAEd,IAAIA,OAAO,OAAO,EAAE;IACpB,OAAOhB,cAAce,OAAOE,GAAG,CAACC,CAAAA,MAAQ,aAAKA;YAAK,CAACjB,QAAQ,EAAEF;;AAC/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce-field-value.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/reconstruct/coerce-field-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,qBAAqB,EACjC,GAAG,EAAE,MAAM,GACV,OAAO,
|
|
1
|
+
{"version":3,"file":"coerce-field-value.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/reconstruct/coerce-field-value.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,qBAAqB,EACjC,GAAG,EAAE,MAAM,GACV,OAAO,CAUT;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CAGpC"}
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
return raw === '' ? [] : raw.split(',');
|
|
35
35
|
}
|
|
36
36
|
if (raw === '') return undefined;
|
|
37
|
-
if (descriptor.type === 'number') return Number(raw);
|
|
37
|
+
if (descriptor.type === 'number' || descriptor.type === 'revision') return Number(raw);
|
|
38
38
|
if (descriptor.type === 'date') return new Date(raw);
|
|
39
39
|
return raw;
|
|
40
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/reconstruct/coerce-field-value.ts"],"sourcesContent":["import type { EntityFieldDescriptor } from '../describe/index.js';\n\n/**\n * The typed value a draft string stands for.\n *\n * This is the exact inverse of the form layer's `seedFieldValue`, and the two\n * have to agree or the round trip is lossy — a member seeded from a record and\n * submitted untouched must come back equal. Two rules are not obvious:\n *\n * - **`boolean` is decided before the empty check, and never yields\n * `undefined`.** A checkbox renders `''` as unchecked, so `''` means `false`;\n * letting the blanket empty rule run first would write `undefined` where the\n * user saw a box they had deliberately left clear.\n * - **`number` checks empty first.** `Number('')` is `0`, so the other order\n * turns every blank numeric field into a real zero.\n *\n * A malformed `number` or `date` is passed through as `NaN` / an invalid `Date`\n * rather than dropped: the form's metadata validation rejects both before\n * submit, and silently discarding a value the user typed would be worse than\n * surfacing it.\n *\n * `scalarCollection` is the one collection with a lossless string form, so it\n * round-trips here rather than waiting for an editor: a comma list in, a\n * `string[]` out. It reads **empty as `[]`, never `undefined`** — a member the\n * user cleared holds no values, which is a different fact from a member that\n * was never set, and only the empty array survives a `required` check honestly.\n * `composition` has no string form at all and never reaches this function; its\n * rows are rebuilt by `reconstructChild`.\n *\n * Extracted from `reconstructEntity` so that a composition's rows coerce through\n * the **same** function their master's scalars do. Two copies of these rules is\n * how a child's `number` member would quietly start meaning something else.\n */\nexport function coerceFieldValue(\n descriptor: EntityFieldDescriptor,\n raw: string,\n): unknown {\n if (descriptor.type === 'boolean') return raw === 'true';\n if (descriptor.type === 'scalarCollection') {\n return raw === '' ? [] : raw.split(',');\n }\n if (raw === '') return undefined;\n if (descriptor.type === 'number')
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/reconstruct/coerce-field-value.ts"],"sourcesContent":["import type { EntityFieldDescriptor } from '../describe/index.js';\n\n/**\n * The typed value a draft string stands for.\n *\n * This is the exact inverse of the form layer's `seedFieldValue`, and the two\n * have to agree or the round trip is lossy — a member seeded from a record and\n * submitted untouched must come back equal. Two rules are not obvious:\n *\n * - **`boolean` is decided before the empty check, and never yields\n * `undefined`.** A checkbox renders `''` as unchecked, so `''` means `false`;\n * letting the blanket empty rule run first would write `undefined` where the\n * user saw a box they had deliberately left clear.\n * - **`number` checks empty first.** `Number('')` is `0`, so the other order\n * turns every blank numeric field into a real zero.\n *\n * A malformed `number` or `date` is passed through as `NaN` / an invalid `Date`\n * rather than dropped: the form's metadata validation rejects both before\n * submit, and silently discarding a value the user typed would be worse than\n * surfacing it.\n *\n * `scalarCollection` is the one collection with a lossless string form, so it\n * round-trips here rather than waiting for an editor: a comma list in, a\n * `string[]` out. It reads **empty as `[]`, never `undefined`** — a member the\n * user cleared holds no values, which is a different fact from a member that\n * was never set, and only the empty array survives a `required` check honestly.\n * `composition` has no string form at all and never reaches this function; its\n * rows are rebuilt by `reconstructChild`.\n *\n * Extracted from `reconstructEntity` so that a composition's rows coerce through\n * the **same** function their master's scalars do. Two copies of these rules is\n * how a child's `number` member would quietly start meaning something else.\n */\nexport function coerceFieldValue(\n descriptor: EntityFieldDescriptor,\n raw: string,\n): unknown {\n if (descriptor.type === 'boolean') return raw === 'true';\n if (descriptor.type === 'scalarCollection') {\n return raw === '' ? [] : raw.split(',');\n }\n if (raw === '') return undefined;\n if (descriptor.type === 'number' || descriptor.type === 'revision')\n return Number(raw);\n if (descriptor.type === 'date') return new Date(raw);\n return raw;\n}\n\n/**\n * The value a `localized` member's draft stands for: the locales that hold\n * text, or `undefined` when none does — an untouched member is not an object\n * of empty strings. Whether every declared locale is filled is the form's\n * question to ask before submit, not this one's.\n */\nexport function coerceLocalizedDraft(\n draft: Readonly<Record<string, string>>,\n): Record<string, string> | undefined {\n const filled = Object.entries(draft).filter(([, text]) => text.trim() !== '');\n return filled.length === 0 ? undefined : Object.fromEntries(filled);\n}\n"],"names":["coerceFieldValue","descriptor","raw","type","split","undefined","Number","Date","coerceLocalizedDraft","draft","filled","Object","entries","filter","text","trim","length","fromEntries"],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8BC,GACD,OAAO,SAASA,iBACdC,UAAiC,EACjCC,GAAW;IAEX,IAAID,WAAWE,IAAI,KAAK,WAAW,OAAOD,QAAQ;IAClD,IAAID,WAAWE,IAAI,KAAK,oBAAoB;QAC1C,OAAOD,QAAQ,KAAK,EAAE,GAAGA,IAAIE,KAAK,CAAC;IACrC;IACA,IAAIF,QAAQ,IAAI,OAAOG;IACvB,IAAIJ,WAAWE,IAAI,KAAK,YAAYF,WAAWE,IAAI,KAAK,YACtD,OAAOG,OAAOJ;IAChB,IAAID,WAAWE,IAAI,KAAK,QAAQ,OAAO,IAAII,KAAKL;IAChD,OAAOA;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASM,qBACdC,KAAuC;IAEvC,MAAMC,SAASC,OAAOC,OAAO,CAACH,OAAOI,MAAM,CAAC,CAAC,GAAGC,KAAK,GAAKA,KAAKC,IAAI,OAAO;IAC1E,OAAOL,OAAOM,MAAM,KAAK,IAAIX,YAAYM,OAAOM,WAAW,CAACP;AAC9D"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { ChildConstructor } from './meta-entities/meta-accessor/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The increment a write that changes a revisioned record states, so a verb's
|
|
4
|
+
* conditional write moves the revision in the same statement instead of
|
|
5
|
+
* re-deriving it (ADR 0032 §6). A form opened before the verb then saves at a
|
|
6
|
+
* revision that no longer matches, and the check protects something.
|
|
7
|
+
*
|
|
8
|
+
* Two spellings of one rule, each for an engine whose operators core does not
|
|
9
|
+
* import: a Mongo update document to merge into the write's own, and a SQL
|
|
10
|
+
* assignment to add to its `SET` list.
|
|
11
|
+
*/
|
|
12
|
+
export declare const bumpRevision: {
|
|
13
|
+
readonly mongo: {
|
|
14
|
+
readonly $inc: {
|
|
15
|
+
readonly revision: 1;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
readonly sql: "revision = revision + 1";
|
|
19
|
+
};
|
|
20
|
+
/** The one name a revision member may have: the wire key is part of the contract. */
|
|
21
|
+
export declare const REVISION_KEY = "revision";
|
|
22
|
+
/** Whether `entityConstructor` declares a `revision` member (ADR 0032). */
|
|
23
|
+
export declare function declaresRevision(entityConstructor: ChildConstructor): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* The revision a record holds, or `undefined` when it holds none — a record
|
|
26
|
+
* never saved, or one an author left without. Anything but a finite number is
|
|
27
|
+
* none: a save must not be conditional on a value it cannot compare.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readRevision(entity: unknown): number | undefined;
|
|
30
|
+
//# sourceMappingURL=revision.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"revision.d.ts","sourceRoot":"","sources":["../../src/entity-definition/revision.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE/E;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY;;;;;;;CAGf,CAAC;AAEX,qFAAqF;AACrF,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC,2EAA2E;AAC3E,wBAAgB,gBAAgB,CAAC,iBAAiB,EAAE,gBAAgB,GAAG,OAAO,CAI7E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKhE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { extractMetaAccessors } from './helpers/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* The increment a write that changes a revisioned record states, so a verb's
|
|
4
|
+
* conditional write moves the revision in the same statement instead of
|
|
5
|
+
* re-deriving it (ADR 0032 §6). A form opened before the verb then saves at a
|
|
6
|
+
* revision that no longer matches, and the check protects something.
|
|
7
|
+
*
|
|
8
|
+
* Two spellings of one rule, each for an engine whose operators core does not
|
|
9
|
+
* import: a Mongo update document to merge into the write's own, and a SQL
|
|
10
|
+
* assignment to add to its `SET` list.
|
|
11
|
+
*/ export const bumpRevision = {
|
|
12
|
+
mongo: {
|
|
13
|
+
$inc: {
|
|
14
|
+
revision: 1
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
sql: 'revision = revision + 1'
|
|
18
|
+
};
|
|
19
|
+
/** The one name a revision member may have: the wire key is part of the contract. */ export const REVISION_KEY = 'revision';
|
|
20
|
+
/** Whether `entityConstructor` declares a `revision` member (ADR 0032). */ export function declaresRevision(entityConstructor) {
|
|
21
|
+
return extractMetaAccessors(entityConstructor).some((member)=>member.type === 'revision');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The revision a record holds, or `undefined` when it holds none — a record
|
|
25
|
+
* never saved, or one an author left without. Anything but a finite number is
|
|
26
|
+
* none: a save must not be conditional on a value it cannot compare.
|
|
27
|
+
*/ export function readRevision(entity) {
|
|
28
|
+
const value = entity == null ? void 0 : entity.revision;
|
|
29
|
+
return typeof value === 'number' && Number.isFinite(value) ? value : undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=revision.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/entity-definition/revision.ts"],"sourcesContent":["import { extractMetaAccessors } from './helpers/index.js';\nimport type { ChildConstructor } from './meta-entities/meta-accessor/index.js';\n\n/**\n * The increment a write that changes a revisioned record states, so a verb's\n * conditional write moves the revision in the same statement instead of\n * re-deriving it (ADR 0032 §6). A form opened before the verb then saves at a\n * revision that no longer matches, and the check protects something.\n *\n * Two spellings of one rule, each for an engine whose operators core does not\n * import: a Mongo update document to merge into the write's own, and a SQL\n * assignment to add to its `SET` list.\n */\nexport const bumpRevision = {\n mongo: { $inc: { revision: 1 } },\n sql: 'revision = revision + 1',\n} as const;\n\n/** The one name a revision member may have: the wire key is part of the contract. */\nexport const REVISION_KEY = 'revision';\n\n/** Whether `entityConstructor` declares a `revision` member (ADR 0032). */\nexport function declaresRevision(entityConstructor: ChildConstructor): boolean {\n return extractMetaAccessors(entityConstructor).some(\n member => member.type === 'revision',\n );\n}\n\n/**\n * The revision a record holds, or `undefined` when it holds none — a record\n * never saved, or one an author left without. Anything but a finite number is\n * none: a save must not be conditional on a value it cannot compare.\n */\nexport function readRevision(entity: unknown): number | undefined {\n const value = (entity as { revision?: unknown } | null | undefined)?.revision;\n return typeof value === 'number' && Number.isFinite(value)\n ? value\n : undefined;\n}\n"],"names":["extractMetaAccessors","bumpRevision","mongo","$inc","revision","sql","REVISION_KEY","declaresRevision","entityConstructor","some","member","type","readRevision","entity","value","Number","isFinite","undefined"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,qBAAqB;AAG1D;;;;;;;;;CASC,GACD,OAAO,MAAMC,eAAe;IAC1BC,OAAO;QAAEC,MAAM;YAAEC,UAAU;QAAE;IAAE;IAC/BC,KAAK;AACP,EAAW;AAEX,mFAAmF,GACnF,OAAO,MAAMC,eAAe,WAAW;AAEvC,yEAAyE,GACzE,OAAO,SAASC,iBAAiBC,iBAAmC;IAClE,OAAOR,qBAAqBQ,mBAAmBC,IAAI,CACjDC,CAAAA,SAAUA,OAAOC,IAAI,KAAK;AAE9B;AAEA;;;;CAIC,GACD,OAAO,SAASC,aAAaC,MAAe;IAC1C,MAAMC,QAASD,0BAAD,AA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 @@ const counted = (n, noun)=>`${n} ${noun}${n === 1 ? '' : 's'}`;
|
|
|
63
63
|
/** A scalar: the type the metadata declares. */ function checkScalar(value, descriptor, report) {
|
|
64
64
|
switch(descriptor.type){
|
|
65
65
|
case 'number':
|
|
66
|
+
case 'revision':
|
|
66
67
|
if (typeof value !== 'number' || Number.isNaN(value)) {
|
|
67
68
|
report(descriptor.name, `holds ${JSON.stringify(value)}, not a number`);
|
|
68
69
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/validate/validate-records.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from '../../failure/define.js';\nimport { FieldProblem } from '../../failure/generic.js';\nimport { locales } from '../../i18n/locales.js';\nimport type {\n Entity,\n EntityConstructor,\n EntityId,\n} from '../../types/Entity.js';\nimport {\n COLLECTION_TYPES,\n describeEntityColumns,\n type EntityFieldDescriptor,\n extractEntityView,\n} from '../describe/index.js';\nimport { extractMetaEntity } from '../helpers/index.js';\n\n/**\n * Records checked against their entity's metadata before anything serves them.\n *\n * The mapping does not do this, on purpose: `deserializeSingleEntity` assigns\n * every non-relation value raw — it converts no date, enforces no `required`,\n * validates no enum value and resolves no link id — because a record off a\n * database was written through that same mapping and needs none of it. Records\n * that arrive as **untyped JSON** — files bundled with a static build, an\n * import, a seed — have had no such guarantee, and a wrong one reaches a reader\n * as `undefined` in the middle of a page, or as a string where a `Date` was\n * expected. This is the check those records go through.\n *\n * It sits in core, beside the deserializer it makes up for, so every adapter\n * that reads untyped records shares it — and the generated form judges a\n * draft by the same metadata, so a record a form refuses is one this refuses.\n *\n * Every problem is collected rather than the first thrown, each with the path\n * to its value: `employment.json › acme › role is required, and is missing`.\n */\n\nexport interface RecordProblem {\n /** `<source> › <id> › <member>`, as far as each is known. */\n readonly path: string;\n readonly message: string;\n}\n\n/**\n * Thrown by {@link validRecordsOrThrow}: an `invalid` failure carrying every\n * problem found, each as a field problem whose `pointer` is the problem's path\n * ([ADR 0013](../../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * Its `message` lists them, because the usual place it surfaces is a build that\n * read a bundled file — where the person reading is looking at a terminal, not\n * a problem body.\n */\nexport class InvalidRecords extends defineFailure('invalid')<InvalidRecords>()(\n 'InvalidRecords',\n 'invalidRecords',\n { errors: Schema.Array(FieldProblem) },\n {\n message: ({ errors }) =>\n `Records are invalid:\\n${errors\n .map(problem => ` ${problem.pointer} ${problem.detail}`)\n .join('\\n')}`,\n },\n) {}\n\n/** The field problems {@link InvalidRecords} carries for a set of record problems. */\nexport const recordFieldProblems = (\n problems: readonly RecordProblem[],\n): FieldProblem[] =>\n problems.map(problem => ({\n pointer: problem.path,\n detail: problem.message,\n code: 'invalidRecord',\n }));\n\n/**\n * A check one entity needs that metadata cannot express — at most one contact\n * channel per type, say. Handed every record (dates already parsed) and a way\n * to report against one of them by index.\n */\nexport type EntityRecordRule = (\n records: ReadonlyArray<Readonly<Record<string, unknown>>>,\n report: (index: number, member: string | undefined, message: string) => void,\n) => void;\n\nexport interface ValidateRecordsOptions {\n /** Where the records came from, for the path in a message. */\n readonly source?: string;\n /**\n * The ids that exist for each `link` or `linkCollection` member, by member\n * name. A member left out is checked for shape only.\n */\n readonly linkTargets?: Readonly<Record<string, ReadonlySet<EntityId>>>;\n /** Checks of the caller's own, run after the metadata's. */\n readonly rules?: readonly EntityRecordRule[];\n /**\n * Every locale a `localized` member must carry. Defaults to the locales the\n * host declared through `defineLocales`.\n */\n readonly locales?: readonly string[];\n /**\n * The view the records were published in. A member it omits is not\n * required of them, since the view left it out on purpose.\n */\n readonly view?: string;\n}\n\nexport interface ValidateRecordsResult {\n readonly problems: readonly RecordProblem[];\n /**\n * The records with every `date` member parsed into a `Date`, ready for the\n * mapping. Meaningless when `problems` is not empty.\n */\n readonly records: ReadonlyArray<Record<string, unknown>>;\n}\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst isAbsent = (value: unknown): boolean =>\n value === undefined || value === null || value === '';\n\ntype Report = (member: string | undefined, message: string) => void;\n\nconst counted = (n: number, noun: string) =>\n `${n} ${noun}${n === 1 ? '' : 's'}`;\n\n/** A date member, parsed: the mapping would leave it a string. */\nfunction parseDate(\n value: unknown,\n report: Report,\n member: string,\n): Date | undefined {\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) report(member, 'is an invalid date');\n return Number.isNaN(value.getTime()) ? undefined : value;\n }\n if (typeof value !== 'string' && typeof value !== 'number') {\n report(member, `holds a ${typeof value}, not a date`);\n return undefined;\n }\n const parsed = new Date(value);\n if (Number.isNaN(parsed.getTime())) {\n report(member, `is not a date: ${JSON.stringify(value)}`);\n return undefined;\n }\n return parsed;\n}\n\n/** A relation: ids, or embedded records, and ids that exist. */\nfunction checkLink(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n known: ReadonlySet<EntityId> | undefined,\n report: Report,\n): void {\n const isCollection = descriptor.type === 'linkCollection';\n if (isCollection && !Array.isArray(value)) {\n report(descriptor.name, 'is not a list');\n return;\n }\n for (const id of isCollection ? (value as unknown[]) : [value]) {\n if (isPlainObject(id)) continue; // An embedded record carries its own.\n if (typeof id !== 'string' && typeof id !== 'number') {\n report(descriptor.name, `holds a ${typeof id} where an id was expected`);\n } else if (known !== undefined && !known.has(id)) {\n report(\n descriptor.name,\n `points at ${JSON.stringify(id)}, which does not exist`,\n );\n }\n }\n}\n\n/** A scalar: the type the metadata declares. */\nfunction checkScalar(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n report: Report,\n): void {\n switch (descriptor.type) {\n case 'number':\n if (typeof value !== 'number' || Number.isNaN(value)) {\n report(descriptor.name, `holds ${JSON.stringify(value)}, not a number`);\n }\n return;\n case 'boolean':\n if (typeof value !== 'boolean') {\n report(\n descriptor.name,\n `holds ${JSON.stringify(value)}, not a boolean`,\n );\n }\n return;\n case 'enum':\n if (!descriptor.enumValues?.includes(value as string)) {\n report(\n descriptor.name,\n `holds ${JSON.stringify(value)}, which is not one of ${JSON.stringify(\n descriptor.enumValues ?? [],\n )}`,\n );\n }\n return;\n case 'scalarCollection':\n case 'composition':\n if (!Array.isArray(value)) report(descriptor.name, 'is not a list');\n return;\n default:\n // `string` and `id`, the two that carry text.\n if (typeof value !== 'string' && typeof value !== 'number') {\n report(descriptor.name, `holds a ${typeof value}, not text`);\n }\n }\n}\n\n/**\n * A localized member: an object with non-empty text under every locale. A\n * missing locale fails rather than falls back, so a page never shows one\n * language in the middle of another.\n */\nfunction checkLocalized(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n locales: readonly string[],\n report: Report,\n): void {\n if (!isPlainObject(value)) {\n report(descriptor.name, 'is not a text per locale');\n return;\n }\n for (const locale of locales) {\n const text = value[locale];\n if (text === undefined) {\n report(descriptor.name, `is missing \"${locale}\"`);\n } else if (typeof text !== 'string') {\n report(\n descriptor.name,\n `holds a ${typeof text} for \"${locale}\", not text`,\n );\n } else if (text.trim() === '') {\n report(descriptor.name, `is empty for \"${locale}\"`);\n }\n }\n}\n\n/** `minItems` / `maxItems` on a collection that is present and is a list. */\nfunction checkItemCount(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n report: Report,\n): void {\n if (!Array.isArray(value)) return;\n const { minItems, maxItems } = descriptor;\n if (minItems !== undefined && value.length < minItems) {\n report(\n descriptor.name,\n `holds ${counted(value.length, 'item')}, and needs at least ${minItems}`,\n );\n }\n if (maxItems !== undefined && value.length > maxItems) {\n report(\n descriptor.name,\n `holds ${counted(value.length, 'item')}, and takes at most ${maxItems}`,\n );\n }\n}\n\n/**\n * Checks every record of one entity against its metadata — identity, `required`,\n * each member's type, link ids, item counts, `notBefore`, and the entity's\n * cardinality — then runs the caller's rules.\n */\nexport function validateRecords<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n records: readonly unknown[],\n {\n source,\n linkTargets = {},\n rules = [],\n locales: required = locales(),\n view,\n }: ValidateRecordsOptions = {},\n): ValidateRecordsResult {\n const problems: RecordProblem[] = [];\n const descriptors = describeEntityColumns(entityConstructor);\n const omitted = new Set(\n view === undefined\n ? []\n : extractEntityView(entityConstructor, view).omitted.map(\n descriptor => descriptor.name,\n ),\n );\n const parsed: Record<string, unknown>[] = [];\n const seen = new Set<unknown>();\n\n const at = (where: string, member: string | undefined, message: string) =>\n problems.push({\n path: [source, where, member].filter(Boolean).join(' › '),\n message,\n });\n\n records.forEach((raw, index) => {\n if (!isPlainObject(raw)) {\n at(`#${index}`, undefined, 'is not a record');\n return;\n }\n\n const id = raw['id'];\n const report: Report = (member, message) =>\n at(isAbsent(id) ? `#${index}` : String(id), member, message);\n\n if (isAbsent(id)) {\n report('id', 'is missing');\n } else if (seen.has(id)) {\n report('id', 'is used more than once');\n } else {\n seen.add(id);\n }\n\n const record: Record<string, unknown> = { ...raw };\n\n for (const descriptor of descriptors) {\n if (descriptor.name === 'id') continue;\n const value = raw[descriptor.key];\n\n if (isAbsent(value)) {\n if (descriptor.required && !omitted.has(descriptor.name)) {\n report(descriptor.name, 'is required, and is missing');\n }\n continue;\n }\n\n if (descriptor.type === 'link' || descriptor.type === 'linkCollection') {\n checkLink(value, descriptor, linkTargets[descriptor.name], report);\n } else if (descriptor.type === 'localized') {\n checkLocalized(value, descriptor, required, report);\n } else if (descriptor.type === 'date') {\n const date = parseDate(value, report, descriptor.name);\n if (date !== undefined) record[descriptor.key] = date;\n } else {\n checkScalar(value, descriptor, report);\n }\n\n if (COLLECTION_TYPES.includes(descriptor.type)) {\n checkItemCount(value, descriptor, report);\n }\n }\n\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n ) as EntityFieldDescriptor;\n const end = record[descriptor.key];\n const start = record[earlier.key];\n if (start instanceof Date && end instanceof Date && end < start) {\n report(descriptor.name, `is before ${earlier.name}`);\n }\n }\n\n parsed.push(record);\n });\n\n const { cardinality, name } = extractMetaEntity(entityConstructor);\n const where = `${counted(records.length, 'record')}`;\n if (cardinality?.min !== undefined && records.length < cardinality.min) {\n at(name, undefined, `has ${where}, and needs at least ${cardinality.min}`);\n }\n if (cardinality?.max !== undefined && records.length > cardinality.max) {\n at(name, undefined, `has ${where}, and takes at most ${cardinality.max}`);\n }\n\n for (const rule of rules) {\n rule(parsed, (index, member, message) => {\n const id = parsed[index]?.['id'];\n at(isAbsent(id) ? `#${index}` : String(id), member, message);\n });\n }\n\n return { problems, records: parsed };\n}\n\n/** The records with their dates parsed, or an {@link InvalidRecords}. */\nexport function validRecordsOrThrow<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n records: readonly unknown[],\n options?: ValidateRecordsOptions,\n): ReadonlyArray<Record<string, unknown>> {\n const result = validateRecords(entityConstructor, records, options);\n if (result.problems.length > 0) {\n throw new InvalidRecords({ errors: recordFieldProblems(result.problems) });\n }\n return result.records;\n}\n"],"names":["Schema","defineFailure","FieldProblem","locales","COLLECTION_TYPES","describeEntityColumns","extractEntityView","extractMetaEntity","InvalidRecords","errors","Array","message","map","problem","pointer","detail","join","recordFieldProblems","problems","path","code","isPlainObject","value","isArray","isAbsent","undefined","counted","n","noun","parseDate","report","member","Date","Number","isNaN","getTime","parsed","JSON","stringify","checkLink","descriptor","known","isCollection","type","name","id","has","checkScalar","enumValues","includes","checkLocalized","locale","text","trim","checkItemCount","minItems","maxItems","length","validateRecords","entityConstructor","records","source","linkTargets","rules","required","view","descriptors","omitted","Set","seen","at","where","push","filter","Boolean","forEach","raw","index","String","add","record","key","date","notBefore","earlier","find","other","end","start","cardinality","min","max","rule","validRecordsOrThrow","options","result"],"mappings":";AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,YAAY,QAAQ,2BAA2B;AACxD,SAASC,OAAO,QAAQ,wBAAwB;AAMhD,SACEC,gBAAgB,EAChBC,qBAAqB,EAErBC,iBAAiB,QACZ,uBAAuB;AAC9B,SAASC,iBAAiB,QA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lC,iBAA6C,EAC7CC,OAA2B,EAC3BkC,OAAgC;IAEhC,MAAMC,SAASrC,gBAAgBC,mBAAmBC,SAASkC;IAC3D,IAAIC,OAAO7E,QAAQ,CAACuC,MAAM,GAAG,GAAG;QAC9B,MAAM,IAAIjD,eAAe;YAAEC,QAAQQ,oBAAoB8E,OAAO7E,QAAQ;QAAE;IAC1E;IACA,OAAO6E,OAAOnC,OAAO;AACvB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/validate/validate-records.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from '../../failure/define.js';\nimport { FieldProblem } from '../../failure/generic.js';\nimport { locales } from '../../i18n/locales.js';\nimport type {\n Entity,\n EntityConstructor,\n EntityId,\n} from '../../types/Entity.js';\nimport {\n COLLECTION_TYPES,\n describeEntityColumns,\n type EntityFieldDescriptor,\n extractEntityView,\n} from '../describe/index.js';\nimport { extractMetaEntity } from '../helpers/index.js';\n\n/**\n * Records checked against their entity's metadata before anything serves them.\n *\n * The mapping does not do this, on purpose: `deserializeSingleEntity` assigns\n * every non-relation value raw — it converts no date, enforces no `required`,\n * validates no enum value and resolves no link id — because a record off a\n * database was written through that same mapping and needs none of it. Records\n * that arrive as **untyped JSON** — files bundled with a static build, an\n * import, a seed — have had no such guarantee, and a wrong one reaches a reader\n * as `undefined` in the middle of a page, or as a string where a `Date` was\n * expected. This is the check those records go through.\n *\n * It sits in core, beside the deserializer it makes up for, so every adapter\n * that reads untyped records shares it — and the generated form judges a\n * draft by the same metadata, so a record a form refuses is one this refuses.\n *\n * Every problem is collected rather than the first thrown, each with the path\n * to its value: `employment.json › acme › role is required, and is missing`.\n */\n\nexport interface RecordProblem {\n /** `<source> › <id> › <member>`, as far as each is known. */\n readonly path: string;\n readonly message: string;\n}\n\n/**\n * Thrown by {@link validRecordsOrThrow}: an `invalid` failure carrying every\n * problem found, each as a field problem whose `pointer` is the problem's path\n * ([ADR 0013](../../../../../../docs/adr/0013-failures-are-typed-values-decided-at-the-shell.md)).\n *\n * Its `message` lists them, because the usual place it surfaces is a build that\n * read a bundled file — where the person reading is looking at a terminal, not\n * a problem body.\n */\nexport class InvalidRecords extends defineFailure('invalid')<InvalidRecords>()(\n 'InvalidRecords',\n 'invalidRecords',\n { errors: Schema.Array(FieldProblem) },\n {\n message: ({ errors }) =>\n `Records are invalid:\\n${errors\n .map(problem => ` ${problem.pointer} ${problem.detail}`)\n .join('\\n')}`,\n },\n) {}\n\n/** The field problems {@link InvalidRecords} carries for a set of record problems. */\nexport const recordFieldProblems = (\n problems: readonly RecordProblem[],\n): FieldProblem[] =>\n problems.map(problem => ({\n pointer: problem.path,\n detail: problem.message,\n code: 'invalidRecord',\n }));\n\n/**\n * A check one entity needs that metadata cannot express — at most one contact\n * channel per type, say. Handed every record (dates already parsed) and a way\n * to report against one of them by index.\n */\nexport type EntityRecordRule = (\n records: ReadonlyArray<Readonly<Record<string, unknown>>>,\n report: (index: number, member: string | undefined, message: string) => void,\n) => void;\n\nexport interface ValidateRecordsOptions {\n /** Where the records came from, for the path in a message. */\n readonly source?: string;\n /**\n * The ids that exist for each `link` or `linkCollection` member, by member\n * name. A member left out is checked for shape only.\n */\n readonly linkTargets?: Readonly<Record<string, ReadonlySet<EntityId>>>;\n /** Checks of the caller's own, run after the metadata's. */\n readonly rules?: readonly EntityRecordRule[];\n /**\n * Every locale a `localized` member must carry. Defaults to the locales the\n * host declared through `defineLocales`.\n */\n readonly locales?: readonly string[];\n /**\n * The view the records were published in. A member it omits is not\n * required of them, since the view left it out on purpose.\n */\n readonly view?: string;\n}\n\nexport interface ValidateRecordsResult {\n readonly problems: readonly RecordProblem[];\n /**\n * The records with every `date` member parsed into a `Date`, ready for the\n * mapping. Meaningless when `problems` is not empty.\n */\n readonly records: ReadonlyArray<Record<string, unknown>>;\n}\n\nconst isPlainObject = (value: unknown): value is Record<string, unknown> =>\n value !== null && typeof value === 'object' && !Array.isArray(value);\n\nconst isAbsent = (value: unknown): boolean =>\n value === undefined || value === null || value === '';\n\ntype Report = (member: string | undefined, message: string) => void;\n\nconst counted = (n: number, noun: string) =>\n `${n} ${noun}${n === 1 ? '' : 's'}`;\n\n/** A date member, parsed: the mapping would leave it a string. */\nfunction parseDate(\n value: unknown,\n report: Report,\n member: string,\n): Date | undefined {\n if (value instanceof Date) {\n if (Number.isNaN(value.getTime())) report(member, 'is an invalid date');\n return Number.isNaN(value.getTime()) ? undefined : value;\n }\n if (typeof value !== 'string' && typeof value !== 'number') {\n report(member, `holds a ${typeof value}, not a date`);\n return undefined;\n }\n const parsed = new Date(value);\n if (Number.isNaN(parsed.getTime())) {\n report(member, `is not a date: ${JSON.stringify(value)}`);\n return undefined;\n }\n return parsed;\n}\n\n/** A relation: ids, or embedded records, and ids that exist. */\nfunction checkLink(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n known: ReadonlySet<EntityId> | undefined,\n report: Report,\n): void {\n const isCollection = descriptor.type === 'linkCollection';\n if (isCollection && !Array.isArray(value)) {\n report(descriptor.name, 'is not a list');\n return;\n }\n for (const id of isCollection ? (value as unknown[]) : [value]) {\n if (isPlainObject(id)) continue; // An embedded record carries its own.\n if (typeof id !== 'string' && typeof id !== 'number') {\n report(descriptor.name, `holds a ${typeof id} where an id was expected`);\n } else if (known !== undefined && !known.has(id)) {\n report(\n descriptor.name,\n `points at ${JSON.stringify(id)}, which does not exist`,\n );\n }\n }\n}\n\n/** A scalar: the type the metadata declares. */\nfunction checkScalar(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n report: Report,\n): void {\n switch (descriptor.type) {\n case 'number':\n case 'revision':\n if (typeof value !== 'number' || Number.isNaN(value)) {\n report(descriptor.name, `holds ${JSON.stringify(value)}, not a number`);\n }\n return;\n case 'boolean':\n if (typeof value !== 'boolean') {\n report(\n descriptor.name,\n `holds ${JSON.stringify(value)}, not a boolean`,\n );\n }\n return;\n case 'enum':\n if (!descriptor.enumValues?.includes(value as string)) {\n report(\n descriptor.name,\n `holds ${JSON.stringify(value)}, which is not one of ${JSON.stringify(\n descriptor.enumValues ?? [],\n )}`,\n );\n }\n return;\n case 'scalarCollection':\n case 'composition':\n if (!Array.isArray(value)) report(descriptor.name, 'is not a list');\n return;\n default:\n // `string` and `id`, the two that carry text.\n if (typeof value !== 'string' && typeof value !== 'number') {\n report(descriptor.name, `holds a ${typeof value}, not text`);\n }\n }\n}\n\n/**\n * A localized member: an object with non-empty text under every locale. A\n * missing locale fails rather than falls back, so a page never shows one\n * language in the middle of another.\n */\nfunction checkLocalized(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n locales: readonly string[],\n report: Report,\n): void {\n if (!isPlainObject(value)) {\n report(descriptor.name, 'is not a text per locale');\n return;\n }\n for (const locale of locales) {\n const text = value[locale];\n if (text === undefined) {\n report(descriptor.name, `is missing \"${locale}\"`);\n } else if (typeof text !== 'string') {\n report(\n descriptor.name,\n `holds a ${typeof text} for \"${locale}\", not text`,\n );\n } else if (text.trim() === '') {\n report(descriptor.name, `is empty for \"${locale}\"`);\n }\n }\n}\n\n/** `minItems` / `maxItems` on a collection that is present and is a list. */\nfunction checkItemCount(\n value: unknown,\n descriptor: EntityFieldDescriptor,\n report: Report,\n): void {\n if (!Array.isArray(value)) return;\n const { minItems, maxItems } = descriptor;\n if (minItems !== undefined && value.length < minItems) {\n report(\n descriptor.name,\n `holds ${counted(value.length, 'item')}, and needs at least ${minItems}`,\n );\n }\n if (maxItems !== undefined && value.length > maxItems) {\n report(\n descriptor.name,\n `holds ${counted(value.length, 'item')}, and takes at most ${maxItems}`,\n );\n }\n}\n\n/**\n * Checks every record of one entity against its metadata — identity, `required`,\n * each member's type, link ids, item counts, `notBefore`, and the entity's\n * cardinality — then runs the caller's rules.\n */\nexport function validateRecords<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n records: readonly unknown[],\n {\n source,\n linkTargets = {},\n rules = [],\n locales: required = locales(),\n view,\n }: ValidateRecordsOptions = {},\n): ValidateRecordsResult {\n const problems: RecordProblem[] = [];\n const descriptors = describeEntityColumns(entityConstructor);\n const omitted = new Set(\n view === undefined\n ? []\n : extractEntityView(entityConstructor, view).omitted.map(\n descriptor => descriptor.name,\n ),\n );\n const parsed: Record<string, unknown>[] = [];\n const seen = new Set<unknown>();\n\n const at = (where: string, member: string | undefined, message: string) =>\n problems.push({\n path: [source, where, member].filter(Boolean).join(' › '),\n message,\n });\n\n records.forEach((raw, index) => {\n if (!isPlainObject(raw)) {\n at(`#${index}`, undefined, 'is not a record');\n return;\n }\n\n const id = raw['id'];\n const report: Report = (member, message) =>\n at(isAbsent(id) ? `#${index}` : String(id), member, message);\n\n if (isAbsent(id)) {\n report('id', 'is missing');\n } else if (seen.has(id)) {\n report('id', 'is used more than once');\n } else {\n seen.add(id);\n }\n\n const record: Record<string, unknown> = { ...raw };\n\n for (const descriptor of descriptors) {\n if (descriptor.name === 'id') continue;\n const value = raw[descriptor.key];\n\n if (isAbsent(value)) {\n if (descriptor.required && !omitted.has(descriptor.name)) {\n report(descriptor.name, 'is required, and is missing');\n }\n continue;\n }\n\n if (descriptor.type === 'link' || descriptor.type === 'linkCollection') {\n checkLink(value, descriptor, linkTargets[descriptor.name], report);\n } else if (descriptor.type === 'localized') {\n checkLocalized(value, descriptor, required, report);\n } else if (descriptor.type === 'date') {\n const date = parseDate(value, report, descriptor.name);\n if (date !== undefined) record[descriptor.key] = date;\n } else {\n checkScalar(value, descriptor, report);\n }\n\n if (COLLECTION_TYPES.includes(descriptor.type)) {\n checkItemCount(value, descriptor, report);\n }\n }\n\n for (const descriptor of descriptors) {\n if (descriptor.notBefore === undefined) continue;\n const earlier = descriptors.find(\n other => other.name === descriptor.notBefore,\n ) as EntityFieldDescriptor;\n const end = record[descriptor.key];\n const start = record[earlier.key];\n if (start instanceof Date && end instanceof Date && end < start) {\n report(descriptor.name, `is before ${earlier.name}`);\n }\n }\n\n parsed.push(record);\n });\n\n const { cardinality, name } = extractMetaEntity(entityConstructor);\n const where = `${counted(records.length, 'record')}`;\n if (cardinality?.min !== undefined && records.length < cardinality.min) {\n at(name, undefined, `has ${where}, and needs at least ${cardinality.min}`);\n }\n if (cardinality?.max !== undefined && records.length > cardinality.max) {\n at(name, undefined, `has ${where}, and takes at most ${cardinality.max}`);\n }\n\n for (const rule of rules) {\n rule(parsed, (index, member, message) => {\n const id = parsed[index]?.['id'];\n at(isAbsent(id) ? `#${index}` : String(id), member, message);\n });\n }\n\n return { problems, records: parsed };\n}\n\n/** The records with their dates parsed, or an {@link InvalidRecords}. */\nexport function validRecordsOrThrow<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n records: readonly unknown[],\n options?: ValidateRecordsOptions,\n): ReadonlyArray<Record<string, unknown>> {\n const result = validateRecords(entityConstructor, records, options);\n if (result.problems.length > 0) {\n throw new InvalidRecords({ errors: recordFieldProblems(result.problems) });\n }\n return result.records;\n}\n"],"names":["Schema","defineFailure","FieldProblem","locales","COLLECTION_TYPES","describeEntityColumns","extractEntityView","extractMetaEntity","InvalidRecords","errors","Array","message","map","problem","pointer","detail","join","recordFieldProblems","problems","path","code","isPlainObject","value","isArray","isAbsent","undefined","counted","n","noun","parseDate","report","member","Date","Number","isNaN","getTime","parsed","JSON","stringify","checkLink","descriptor","known","isCollection","type","name","id","has","checkScalar","enumValues","includes","checkLocalized","locale","text","trim","checkItemCount","minItems","maxItems","length","validateRecords","entityConstructor","records","source","linkTargets","rules","required","view","descriptors","omitted","Set","seen","at","where","push","filter","Boolean","forEach","raw","index","String","add","record","key","date","notBefore","earlier","find","other","end","start","cardinality","min","max","rule","validRecordsOrThrow","options","result"],"mappings":";AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,0BAA0B;AACxD,SAASC,YAAY,QAAQ,2BAA2B;AACxD,SAASC,OAAO,QAAQ,wBAAwB;AAMhD,SACEC,gBAAgB,EAChBC,qBAAqB,EAErBC,iBAAiB,QACZ,uBAAuB;AAC9B,SAASC,iBAAiB,QAAQ,sBAAsB;AA4BxD;;;;;;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CC,OAA2B,EAC3BkC,OAAgC;IAEhC,MAAMC,SAASrC,gBAAgBC,mBAAmBC,SAASkC;IAC3D,IAAIC,OAAO7E,QAAQ,CAACuC,MAAM,GAAG,GAAG;QAC9B,MAAM,IAAIjD,eAAe;YAAEC,QAAQQ,oBAAoB8E,OAAO7E,QAAQ;QAAE;IAC1E;IACA,OAAO6E,OAAOnC,OAAO;AACvB"}
|
|
@@ -75,6 +75,21 @@ declare const DuplicateKey_base: Schema.Class<DuplicateKey, Schema.TaggedStruct<
|
|
|
75
75
|
/** A write that would duplicate a value the store declares unique. */
|
|
76
76
|
export declare class DuplicateKey extends DuplicateKey_base {
|
|
77
77
|
}
|
|
78
|
+
declare const StaleRevision_base: Schema.Class<StaleRevision, Schema.TaggedStruct<"StaleRevision", {
|
|
79
|
+
readonly entity: Schema.optionalKey<Schema.String>;
|
|
80
|
+
readonly current: Schema.optionalKey<Schema.Number>;
|
|
81
|
+
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"staleRevision", "conflict">>;
|
|
82
|
+
/**
|
|
83
|
+
* A save named the revision it read, and the record has moved on: someone else
|
|
84
|
+
* saved first (ADR 0032). A `conflict`, not a `contention` — a retry sends the
|
|
85
|
+
* same stale revision and loses again; only a person who has seen the current
|
|
86
|
+
* record can make the save succeed.
|
|
87
|
+
*
|
|
88
|
+
* `current` is the stored revision, so a client can tell "changed since you read
|
|
89
|
+
* it" from "deleted since" (`NotFound`) without a second request.
|
|
90
|
+
*/
|
|
91
|
+
export declare class StaleRevision extends StaleRevision_base {
|
|
92
|
+
}
|
|
78
93
|
declare const Declined_base: Schema.Class<Declined, Schema.TaggedStruct<"Declined", {
|
|
79
94
|
readonly reason: Schema.optionalKey<Schema.String>;
|
|
80
95
|
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"declined", "declined">>;
|
|
@@ -142,13 +157,13 @@ export declare class IdempotencyKeyInFlight extends IdempotencyKeyInFlight_base
|
|
|
142
157
|
* reached, it did not answer in time, or it answered something unreadable.
|
|
143
158
|
* A port that talks to storage names this as its failure.
|
|
144
159
|
*/
|
|
145
|
-
export type StoreFailure = DuplicateKey | Contention | Unavailable | Timeout | ProtocolFailure;
|
|
160
|
+
export type StoreFailure = DuplicateKey | StaleRevision | Contention | Unavailable | Timeout | ProtocolFailure;
|
|
146
161
|
/**
|
|
147
162
|
* The technical part of {@link StoreFailure}: the store failing to answer, as
|
|
148
163
|
* opposed to answering no. A unit of work rolls back and surfaces these; a
|
|
149
164
|
* business failure — a `DuplicateKey` included — is its abort.
|
|
150
165
|
*/
|
|
151
|
-
export type StoreFault = Exclude<StoreFailure, DuplicateKey>;
|
|
166
|
+
export type StoreFault = Exclude<StoreFailure, DuplicateKey | StaleRevision>;
|
|
152
167
|
/** Whether `value` is a {@link StoreFault}, read by tag. */
|
|
153
168
|
export declare const isStoreFault: (value: unknown) => value is StoreFault;
|
|
154
169
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/failure/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAIhC;;;;;;GAMG;AAEH,kFAAkF;AAClF,eAAO,MAAM,YAAY;;;;EAIvB,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,YAAY,CAAC,IAAI,CAAC;;;;;;;;AAEpD,uEAAuE;AACvE,qBAAa,OAAQ,SAAQ,YAI5B;CAAG;;;;AAEJ,+DAA+D;AAC/D,qBAAa,YAAa,SAAQ,iBAKjC;CAAG;;;;AAEJ;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,oBAOpC;CAAG;;AAEJ,kDAAkD;AAClD,qBAAa,eAAgB,SAAQ,oBAEqB;CAAG;;;;AAE7D,2CAA2C;AAC3C,qBAAa,SAAU,SAAQ,cAM9B;CAAG;;AAEJ;;;;;;;;;;GAUG;AACH,qBAAa,oBAAqB,SAAQ,yBAE+B;CAAG;;;;AA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,OAAO,CAAC,YAAY,EAAE,YAAY,GAAG,aAAa,CAAC,CAAC;AAS7E,4DAA4D;AAC5D,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAGsB,CAAC"}
|
package/dist/failure/generic.js
CHANGED
|
@@ -59,6 +59,19 @@ import { defineFailure } from './define.js';
|
|
|
59
59
|
key: Schema.optionalKey(Schema.String)
|
|
60
60
|
}) {
|
|
61
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* A save named the revision it read, and the record has moved on: someone else
|
|
64
|
+
* saved first (ADR 0032). A `conflict`, not a `contention` — a retry sends the
|
|
65
|
+
* same stale revision and loses again; only a person who has seen the current
|
|
66
|
+
* record can make the save succeed.
|
|
67
|
+
*
|
|
68
|
+
* `current` is the stored revision, so a client can tell "changed since you read
|
|
69
|
+
* it" from "deleted since" (`NotFound`) without a second request.
|
|
70
|
+
*/ export class StaleRevision extends defineFailure('conflict')()('StaleRevision', 'staleRevision', {
|
|
71
|
+
entity: Schema.optionalKey(Schema.String),
|
|
72
|
+
current: Schema.optionalKey(Schema.Number)
|
|
73
|
+
}) {
|
|
74
|
+
}
|
|
62
75
|
/** A third party, or a rule over other records, said no. */ export class Declined extends defineFailure('declined')()('Declined', 'declined', {
|
|
63
76
|
reason: Schema.optionalKey(Schema.String)
|
|
64
77
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/failure/generic.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from './define.js';\n\n/**\n * The failures every host shares — the ones a framework route, an adapter or a\n * transport raises without knowing the domain it serves. A domain names its\n * own refusals beside these, through the same definers.\n *\n * Each code is permanent: a host's message catalog keys on it.\n */\n\n/** One field a request got wrong. `pointer` locates it, `code` names the rule. */\nexport const FieldProblem = Schema.Struct({\n pointer: Schema.String,\n detail: Schema.String,\n code: Schema.String,\n});\nexport type FieldProblem = typeof FieldProblem.Type;\n\n/** The request breaks rules on its own; every broken one is listed. */\nexport class Invalid extends defineFailure('invalid')<Invalid>()(\n 'Invalid',\n 'invalid',\n { errors: Schema.Array(FieldProblem) },\n) {}\n\n/** A list, filter or sort the query language cannot accept. */\nexport class InvalidQuery extends defineFailure('invalid')<InvalidQuery>()(\n 'InvalidQuery',\n 'invalidQuery',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/**\n * A payload that is not the envelope its reader expected. The sender's fault —\n * a `400` at an HTTP edge and poison on a bus, where redelivering the same\n * bytes produces the same refusal.\n */\nexport class InvalidEnvelope extends defineFailure(\n 'invalid',\n)<InvalidEnvelope>()(\n 'InvalidEnvelope',\n 'invalidEnvelope',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/** No credential, or one that does not verify. */\nexport class Unauthenticated extends defineFailure(\n 'unauthenticated',\n)<Unauthenticated>()('Unauthenticated', 'unauthenticated') {}\n\n/** A verified caller without the grant. */\nexport class Forbidden extends defineFailure('forbidden')<Forbidden>()(\n 'Forbidden',\n 'forbidden',\n // Which grant was missing: diagnostic, not a leak — the caller already\n // knows what it asked to do.\n { permission: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A signed-in caller whose session names no organization, on a route that acts\n * for one. A member of several organizations hits it before choosing one; the\n * code is what a client renders as \"select an organization\" instead of\n * \"forbidden\".\n *\n * Declared here rather than beside the guard that raises it, so every bundle\n * that decodes a problem knows the code: a browser loads no service shell, and\n * an unregistered code decodes as a protocol failure, losing the next step a\n * host registers for it.\n */\nexport class NoActiveOrganization extends defineFailure(\n 'conflict',\n)<NoActiveOrganization>()('NoActiveOrganization', 'noActiveOrganization') {}\n\n/** The addressed record does not exist. */\nexport class NotFound extends defineFailure('notFound')<NotFound>()(\n 'NotFound',\n 'notFound',\n { entity: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A write that would duplicate a value the store declares unique. */\nexport class DuplicateKey extends defineFailure('conflict')<DuplicateKey>()(\n 'DuplicateKey',\n 'duplicateKey',\n { key: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A third party, or a rule over other records, said no. */\nexport class Declined extends defineFailure('declined')<Declined>()(\n 'Declined',\n 'declined',\n { reason: Schema.optionalKey(Schema.String) },\n { message: ({ reason }) => reason ?? '' },\n) {}\n\n/** Lost a race that a retry can win — a claim taken, a transaction aborted. */\nexport class Contention extends defineFailure('contention')<Contention>()(\n 'Contention',\n 'contention',\n) {}\n\n/** The dependency asked for less load. Stops retries wherever it appears. */\nexport class Overloaded extends defineFailure('exhausted')<Overloaded>()(\n 'Overloaded',\n 'overloaded',\n { retryAfterSeconds: Schema.optionalKey(Schema.Number) },\n) {}\n\n/** A dependency could not be reached. */\nexport class Unavailable extends defineFailure('unavailable')<Unavailable>()(\n 'Unavailable',\n 'unavailable',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The service a proxy forwards to could not be reached. */\nexport class UpstreamUnavailable extends defineFailure(\n 'unavailable',\n)<UpstreamUnavailable>()('UpstreamUnavailable', 'upstreamUnavailable', {\n upstream: Schema.optionalKey(Schema.String),\n}) {}\n\n/** A dependency did not answer in time. */\nexport class Timeout extends defineFailure('timeout')<Timeout>()(\n 'Timeout',\n 'timeout',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A peer answered something that does not decode — a body that is not a\n * problem, a code nothing registered, a document that does not match its\n * schema.\n */\nexport class ProtocolFailure extends defineFailure(\n 'protocol',\n)<ProtocolFailure>()(\n 'ProtocolFailure',\n 'protocol',\n {\n reason: Schema.String,\n upstreamStatus: Schema.optionalKey(Schema.Number),\n },\n { message: ({ reason }) => reason },\n) {}\n\n/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */\nexport class Internal extends defineFailure('internal')<Internal>()(\n 'Internal',\n 'internal',\n) {}\n\n/** An idempotent route was called without its `Idempotency-Key`. */\nexport class IdempotencyKeyMissing extends defineFailure(\n 'invalid',\n)<IdempotencyKeyMissing>()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {}\n\n/** One `Idempotency-Key` arrived with two different payloads. */\nexport class IdempotencyKeyReused extends defineFailure(\n 'declined',\n)<IdempotencyKeyReused>()('IdempotencyKeyReused', 'idempotencyKeyReused') {}\n\n/** The first request under this `Idempotency-Key` has not finished. */\nexport class IdempotencyKeyInFlight extends defineFailure(\n 'contention',\n)<IdempotencyKeyInFlight>()(\n 'IdempotencyKeyInFlight',\n 'idempotencyKeyInFlight',\n) {}\n\n/**\n * What a store adapter fails with — a datastore, a cache, a bus: the value it\n * guarded already exists, someone else got there first, it could not be\n * reached, it did not answer in time, or it answered something unreadable.\n * A port that talks to storage names this as its failure.\n */\nexport type StoreFailure =\n DuplicateKey | Contention | Unavailable | Timeout | ProtocolFailure;\n\n/**\n * The technical part of {@link StoreFailure}: the store failing to answer, as\n * opposed to answering no. A unit of work rolls back and surfaces these; a\n * business failure — a `DuplicateKey` included — is its abort.\n */\nexport type StoreFault = Exclude<StoreFailure, DuplicateKey>;\n\nconst STORE_FAULT_TAGS: ReadonlySet<string> = new Set([\n 'Contention',\n 'Unavailable',\n 'Timeout',\n 'ProtocolFailure',\n]);\n\n/** Whether `value` is a {@link StoreFault}, read by tag. */\nexport const isStoreFault = (value: unknown): value is StoreFault =>\n typeof value === 'object' &&\n value !== null &&\n STORE_FAULT_TAGS.has((value as { readonly _tag?: unknown })._tag as string);\n"],"names":["Schema","defineFailure","FieldProblem","Struct","pointer","String","detail","code","Invalid","errors","Array","InvalidQuery","reason","message","InvalidEnvelope","Unauthenticated","Forbidden","permission","optionalKey","NoActiveOrganization","NotFound","entity","DuplicateKey","key","Declined","Contention","Overloaded","retryAfterSeconds","Number","Unavailable","dependency","UpstreamUnavailable","upstream","Timeout","ProtocolFailure","upstreamStatus","Internal","IdempotencyKeyMissing","IdempotencyKeyReused","IdempotencyKeyInFlight","STORE_FAULT_TAGS","Set","isStoreFault","value","has","_tag"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,cAAc;AAE5C;;;;;;CA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rE,OAAO,MAAMsC,+BAA+BtC,cAC1C,gBAEA,0BACA;AACC;AAkBH,MAAMuC,mBAAwC,IAAIC,IAAI;IACpD;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,OAAO,MAAMC,eAAe,CAACC,QAC3B,OAAOA,UAAU,YACjBA,UAAU,QACVH,iBAAiBI,GAAG,CAAC,AAACD,MAAsCE,IAAI,EAAY"}
|
|
1
|
+
{"version":3,"sources":["../../src/failure/generic.ts"],"sourcesContent":["import { Schema } from 'effect';\n\nimport { defineFailure } from './define.js';\n\n/**\n * The failures every host shares — the ones a framework route, an adapter or a\n * transport raises without knowing the domain it serves. A domain names its\n * own refusals beside these, through the same definers.\n *\n * Each code is permanent: a host's message catalog keys on it.\n */\n\n/** One field a request got wrong. `pointer` locates it, `code` names the rule. */\nexport const FieldProblem = Schema.Struct({\n pointer: Schema.String,\n detail: Schema.String,\n code: Schema.String,\n});\nexport type FieldProblem = typeof FieldProblem.Type;\n\n/** The request breaks rules on its own; every broken one is listed. */\nexport class Invalid extends defineFailure('invalid')<Invalid>()(\n 'Invalid',\n 'invalid',\n { errors: Schema.Array(FieldProblem) },\n) {}\n\n/** A list, filter or sort the query language cannot accept. */\nexport class InvalidQuery extends defineFailure('invalid')<InvalidQuery>()(\n 'InvalidQuery',\n 'invalidQuery',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/**\n * A payload that is not the envelope its reader expected. The sender's fault —\n * a `400` at an HTTP edge and poison on a bus, where redelivering the same\n * bytes produces the same refusal.\n */\nexport class InvalidEnvelope extends defineFailure(\n 'invalid',\n)<InvalidEnvelope>()(\n 'InvalidEnvelope',\n 'invalidEnvelope',\n { reason: Schema.String },\n { message: ({ reason }) => reason },\n) {}\n\n/** No credential, or one that does not verify. */\nexport class Unauthenticated extends defineFailure(\n 'unauthenticated',\n)<Unauthenticated>()('Unauthenticated', 'unauthenticated') {}\n\n/** A verified caller without the grant. */\nexport class Forbidden extends defineFailure('forbidden')<Forbidden>()(\n 'Forbidden',\n 'forbidden',\n // Which grant was missing: diagnostic, not a leak — the caller already\n // knows what it asked to do.\n { permission: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A signed-in caller whose session names no organization, on a route that acts\n * for one. A member of several organizations hits it before choosing one; the\n * code is what a client renders as \"select an organization\" instead of\n * \"forbidden\".\n *\n * Declared here rather than beside the guard that raises it, so every bundle\n * that decodes a problem knows the code: a browser loads no service shell, and\n * an unregistered code decodes as a protocol failure, losing the next step a\n * host registers for it.\n */\nexport class NoActiveOrganization extends defineFailure(\n 'conflict',\n)<NoActiveOrganization>()('NoActiveOrganization', 'noActiveOrganization') {}\n\n/** The addressed record does not exist. */\nexport class NotFound extends defineFailure('notFound')<NotFound>()(\n 'NotFound',\n 'notFound',\n { entity: Schema.optionalKey(Schema.String) },\n) {}\n\n/** A write that would duplicate a value the store declares unique. */\nexport class DuplicateKey extends defineFailure('conflict')<DuplicateKey>()(\n 'DuplicateKey',\n 'duplicateKey',\n { key: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A save named the revision it read, and the record has moved on: someone else\n * saved first (ADR 0032). A `conflict`, not a `contention` — a retry sends the\n * same stale revision and loses again; only a person who has seen the current\n * record can make the save succeed.\n *\n * `current` is the stored revision, so a client can tell \"changed since you read\n * it\" from \"deleted since\" (`NotFound`) without a second request.\n */\nexport class StaleRevision extends defineFailure('conflict')<StaleRevision>()(\n 'StaleRevision',\n 'staleRevision',\n {\n entity: Schema.optionalKey(Schema.String),\n current: Schema.optionalKey(Schema.Number),\n },\n) {}\n\n/** A third party, or a rule over other records, said no. */\nexport class Declined extends defineFailure('declined')<Declined>()(\n 'Declined',\n 'declined',\n { reason: Schema.optionalKey(Schema.String) },\n { message: ({ reason }) => reason ?? '' },\n) {}\n\n/** Lost a race that a retry can win — a claim taken, a transaction aborted. */\nexport class Contention extends defineFailure('contention')<Contention>()(\n 'Contention',\n 'contention',\n) {}\n\n/** The dependency asked for less load. Stops retries wherever it appears. */\nexport class Overloaded extends defineFailure('exhausted')<Overloaded>()(\n 'Overloaded',\n 'overloaded',\n { retryAfterSeconds: Schema.optionalKey(Schema.Number) },\n) {}\n\n/** A dependency could not be reached. */\nexport class Unavailable extends defineFailure('unavailable')<Unavailable>()(\n 'Unavailable',\n 'unavailable',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/** The service a proxy forwards to could not be reached. */\nexport class UpstreamUnavailable extends defineFailure(\n 'unavailable',\n)<UpstreamUnavailable>()('UpstreamUnavailable', 'upstreamUnavailable', {\n upstream: Schema.optionalKey(Schema.String),\n}) {}\n\n/** A dependency did not answer in time. */\nexport class Timeout extends defineFailure('timeout')<Timeout>()(\n 'Timeout',\n 'timeout',\n { dependency: Schema.optionalKey(Schema.String) },\n) {}\n\n/**\n * A peer answered something that does not decode — a body that is not a\n * problem, a code nothing registered, a document that does not match its\n * schema.\n */\nexport class ProtocolFailure extends defineFailure(\n 'protocol',\n)<ProtocolFailure>()(\n 'ProtocolFailure',\n 'protocol',\n {\n reason: Schema.String,\n upstreamStatus: Schema.optionalKey(Schema.Number),\n },\n { message: ({ reason }) => reason },\n) {}\n\n/** A bug, surfaced as a value. Never carries the bug's text onto a wire. */\nexport class Internal extends defineFailure('internal')<Internal>()(\n 'Internal',\n 'internal',\n) {}\n\n/** An idempotent route was called without its `Idempotency-Key`. */\nexport class IdempotencyKeyMissing extends defineFailure(\n 'invalid',\n)<IdempotencyKeyMissing>()('IdempotencyKeyMissing', 'idempotencyKeyMissing') {}\n\n/** One `Idempotency-Key` arrived with two different payloads. */\nexport class IdempotencyKeyReused extends defineFailure(\n 'declined',\n)<IdempotencyKeyReused>()('IdempotencyKeyReused', 'idempotencyKeyReused') {}\n\n/** The first request under this `Idempotency-Key` has not finished. */\nexport class IdempotencyKeyInFlight extends defineFailure(\n 'contention',\n)<IdempotencyKeyInFlight>()(\n 'IdempotencyKeyInFlight',\n 'idempotencyKeyInFlight',\n) {}\n\n/**\n * What a store adapter fails with — a datastore, a cache, a bus: the value it\n * guarded already exists, someone else got there first, it could not be\n * reached, it did not answer in time, or it answered something unreadable.\n * A port that talks to storage names this as its failure.\n */\nexport type StoreFailure =\n | DuplicateKey\n | StaleRevision\n | Contention\n | Unavailable\n | Timeout\n | ProtocolFailure;\n\n/**\n * The technical part of {@link StoreFailure}: the store failing to answer, as\n * opposed to answering no. A unit of work rolls back and surfaces these; a\n * business failure — a `DuplicateKey` included — is its abort.\n */\nexport type StoreFault = Exclude<StoreFailure, DuplicateKey | StaleRevision>;\n\nconst STORE_FAULT_TAGS: ReadonlySet<string> = new Set([\n 'Contention',\n 'Unavailable',\n 'Timeout',\n 'ProtocolFailure',\n]);\n\n/** Whether `value` is a {@link StoreFault}, read by tag. */\nexport const isStoreFault = (value: unknown): value is StoreFault =>\n typeof value === 'object' &&\n value !== null &&\n STORE_FAULT_TAGS.has((value as { readonly _tag?: unknown })._tag as string);\n"],"names":["Schema","defineFailure","FieldProblem","Struct","pointer","String","detail","code","Invalid","errors","Array","InvalidQuery","reason","message","InvalidEnvelope","Unauthenticated","Forbidden","permission","optionalKey","NoActiveOrganization","NotFound","entity","DuplicateKey","key","StaleRevision","current","Number","Declined","Contention","Overloaded","retryAfterSeconds","Unavailable","dependency","UpstreamUnavailable","upstream","Timeout","ProtocolFailure","upstreamStatus","Internal","IdempotencyKeyMissing","IdempotencyKeyReused","IdempotencyKeyInFlight","STORE_FAULT_TAGS","Set","isStoreFault","value","has","_tag"],"mappings":"AAAA,SAASA,MAAM,QAAQ,SAAS;AAEhC,SAASC,aAAa,QAAQ,cAAc;AAE5C;;;;;;CAMC,GAED,gFAAgF,GAChF,OAAO,MAAMC,eAAeF,OAAOG,MAAM,CAAC;IACxCC,SAASJ,OAAOK,MAAM;IACtBC,QAAQN,OAAOK,MAAM;IACrBE,MAAMP,OAAOK,MAAM;AACrB,GAAG;AAGH,qEAAqE,GACrE,OAAO,MAAMG,gBAAgBP,cAAc,aACzC,WACA,WACA;IAAEQ,QAAQT,OAAOU,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AuBH,MAAMyC,mBAAwC,IAAIC,IAAI;IACpD;IACA;IACA;IACA;CACD;AAED,0DAA0D,GAC1D,OAAO,MAAMC,eAAe,CAACC,QAC3B,OAAOA,UAAU,YACjBA,UAAU,QACVH,iBAAiBI,GAAG,CAAC,AAACD,MAAsCE,IAAI,EAAY"}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './entity-definition/meta-entities/meta-method/index.js';
|
|
|
20
20
|
export * from './entity-definition/meta-entities/meta-use-case/index.js';
|
|
21
21
|
export * from './entity-definition/metadata/index.js';
|
|
22
22
|
export * from './entity-definition/reconstruct/index.js';
|
|
23
|
+
export * from './entity-definition/revision.js';
|
|
23
24
|
export * from './entity-definition/serializer/index.js';
|
|
24
25
|
export * from './entity-definition/validate/index.js';
|
|
25
26
|
export * from './envelope/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,+CAA+C,CAAC;AAC9D,cAAc,4BAA4B,CAAC;AAC3C,cAAc,wBAAwB,CAAC;AACvC,cAAc,qBAAqB,CAAC;AACpC,cAAc,kDAAkD,CAAC;AACjE,cAAc,gDAAgD,CAAC;AAC/D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,kDAAkD,CAAC;AACjE,cAAc,uCAAuC,CAAC;AACtD,cAAc,mCAAmC,CAAC;AAClD,cAAc,sCAAsC,CAAC;AACrD,cAAc,uDAAuD,CAAC;AACtE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,gDAAgD,CAAC;AAC/D,cAAc,uDAAuD,CAAC;AACtE,cAAc,iDAAiD,CAAC;AAChE,cAAc,0DAA0D,CAAC;AACzE,cAAc,wDAAwD,CAAC;AACvE,cAAc,wDAAwD,CAAC;AACvE,cAAc,0DAA0D,CAAC;AACzE,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AAC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AAc,2DAA2D,CAAC;AAC1E,cAAc,gDAAgD,CAAC;AAC/D,cAAc,uDAAuD,CAAC;AACtE,cAAc,iDAAiD,CAAC;AAChE,cAAc,0DAA0D,CAAC;AACzE,cAAc,wDAAwD,CAAC;AACvE,cAAc,wDAAwD,CAAC;AACvE,cAAc,0DAA0D,CAAC;AACzE,cAAc,uCAAuC,CAAC;AACtD,cAAc,0CAA0C,CAAC;AACzD,cAAc,iCAAiC,CAAC;AAChD,cAAc,yCAAyC,CAAC;AACxD,cAAc,uCAAuC,CAAC;AACtD,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,iBAAiB,CAAC;AAChC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -20,6 +20,7 @@ export * from './entity-definition/meta-entities/meta-method/index.js';
|
|
|
20
20
|
export * from './entity-definition/meta-entities/meta-use-case/index.js';
|
|
21
21
|
export * from './entity-definition/metadata/index.js';
|
|
22
22
|
export * from './entity-definition/reconstruct/index.js';
|
|
23
|
+
export * from './entity-definition/revision.js';
|
|
23
24
|
export * from './entity-definition/serializer/index.js';
|
|
24
25
|
export * from './entity-definition/validate/index.js';
|
|
25
26
|
export * from './envelope/index.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './shortcut/chord.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,oBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/revision.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './shortcut/chord.js';\nexport * from './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,kCAAkC;AAChD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,oBAAoB"}
|
|
@@ -82,7 +82,9 @@ const isBetween = (actual, start, end)=>actual != null && compareStoredValues(ac
|
|
|
82
82
|
case 'eq':
|
|
83
83
|
case 'ne':
|
|
84
84
|
return {
|
|
85
|
-
test: (actual)=>
|
|
85
|
+
test: (actual)=>matchesAny(actual, [
|
|
86
|
+
filter.value
|
|
87
|
+
]),
|
|
86
88
|
negated: filter.operator === 'ne'
|
|
87
89
|
};
|
|
88
90
|
case 'gt':
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/query/in-memory-query.ts"],"sourcesContent":["import { EntityCollectionLink } from '../entity-definition/links/entity-collection-link/index.js';\nimport { EntityLink } from '../entity-definition/links/entity-link/index.js';\nimport type { Entity } from '../types/Entity.js';\nimport type {\n EntityFacetCounts,\n EntityFacetQuery,\n EntityFacetValue,\n} from '../types/EntityFacets.js';\nimport type {\n EntityFilter,\n EntityFiltering,\n FilterGroup,\n} from '../types/EntityFiltering.js';\nimport type { EntitySorting } from '../types/EntitySorting.js';\nimport { containsFolded } from './fold.js';\n\n/**\n * An {@link EntityLoadRequest}'s filtering and sorting, answered over records\n * held in memory, with the semantics of the Mongo adapter.\n *\n * One implementation for everything that queries records it holds itself — the\n * in-memory test double, the static repository, a published view — so none of\n * them can drift into a more forgiving version of the others. They used to be\n * separate copies, and one of them compared an array member with `===` and so\n * never matched `in` (#34).\n *\n * The rules, each Mongo's:\n * - a link is its target's id, a collection link the list of their ids;\n * - `in` and `nin` against an array match when **any element** does, as `$in`;\n * - a property may be a dotted path into a member holding an object, which is\n * how a filter reaches one locale of a `localized` member (`name.en`);\n * - `like` is a substring match that ignores accents and case — `cafe` finds\n * `Café` — by the one rule in `fold.ts` every adapter derives its form from;\n * - a missing value sorts below a present one, numbers and dates compare as\n * themselves and anything else as text;\n * - every top-level filtering entry is combined with `and`.\n */\n\n/**\n * A member as the Mongo adapter stores it, and so as its queries see it: a\n * link is its target's id, a collection link the list of their ids. Without\n * this no operator can compare a link, since `eq` against an id is never\n * `true` for an object.\n */\nexport function storedValue(value: unknown): unknown {\n if (value instanceof EntityLink) return value.id;\n if (value instanceof EntityCollectionLink) return value.ids;\n return value;\n}\n\n/**\n * The value a property names: a member, or a dotted path into one. A path\n * through something that is not an object ends in `undefined`, as a missing\n * field does in Mongo.\n */\nexport function valueAt(record: object, property: string): unknown {\n const [member, ...path] = property.split('.');\n return path.reduce<unknown>(\n (value, key) =>\n typeof value === 'object' && value !== null\n ? (value as Record<string, unknown>)[key]\n : undefined,\n storedValue((record as Record<string, unknown>)[member as string]),\n );\n}\n\n/** Ordering with Mongo's rules; `0` for two values it considers equal. */\nexport function compareStoredValues(left: unknown, right: unknown): number {\n if (left === right) return 0;\n // Mongo sorts missing values below present ones.\n if (left == null) return right == null ? 0 : -1;\n if (right == null) return 1;\n if (typeof left === 'number' && typeof right === 'number') {\n return left - right;\n }\n if (left instanceof Date && right instanceof Date) {\n return left.getTime() - right.getTime();\n }\n return String(left).localeCompare(String(right));\n}\n\n/** Equality by value, so two `Date`s naming one instant are equal. */\nconst isEqual = (actual: unknown, value: unknown): boolean =>\n actual instanceof Date && value instanceof Date\n ? actual.getTime() === value.getTime()\n : actual === value;\n\n/** `$in` semantics: a scalar matches a value, an array when any element does. */\nconst matchesAny = (actual: unknown, values: readonly unknown[]): boolean => {\n const matches = (element: unknown) =>\n values.some(value => isEqual(element, value));\n return Array.isArray(actual) ? actual.some(matches) : matches(actual);\n};\n\n/** `like`: a substring match with accents and case folded off (`fold.ts`). */\nconst matchesLike = (actual: unknown, value: string): boolean =>\n actual != null && containsFolded(String(actual), value);\n\nconst isFilterGroup = <TEntity extends Entity>(\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): node is FilterGroup<TEntity> =>\n !('property' in node) && (node.operator === 'and' || node.operator === 'or');\n\nconst isBetween = (actual: unknown, start: unknown, end: unknown) =>\n actual != null &&\n compareStoredValues(actual, start) >= 0 &&\n compareStoredValues(actual, end) <= 0;\n\n/**\n * The values a dotted path reaches **through an array** — every element's\n * member — or `undefined` when the path crosses no array, so the caller reads\n * the single value as before.\n */\nfunction valuesThroughArray(\n record: object,\n property: string,\n): unknown[] | undefined {\n const dot = property.indexOf('.');\n if (dot === -1) return undefined;\n const elements = storedValue(\n (record as Record<string, unknown>)[property.slice(0, dot)],\n );\n if (!Array.isArray(elements)) return undefined;\n const member = property.slice(dot + 1);\n return elements.map(element =>\n typeof element === 'object' && element !== null\n ? valueAt(element as object, member)\n : undefined,\n );\n}\n\n/**\n * Splits a filter into its positive test and whether the operator negates it,\n * so a path into an array can ask \"any element\" of the positive form and\n * negate the answer — never \"any element is not equal\", which almost always\n * holds.\n */\nfunction positiveTest<TEntity extends Entity>(\n filter: EntityFilter<TEntity>,\n): { readonly test: (actual: unknown) => boolean; readonly negated: boolean } {\n switch (filter.operator) {\n case 'eq':\n case 'ne':\n return {\n test: actual => isEqual(actual, filter.value),\n negated: filter.operator === 'ne',\n };\n case 'gt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) > 0,\n negated: false,\n };\n case 'gte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) >= 0,\n negated: false,\n };\n case 'lt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) < 0,\n negated: false,\n };\n case 'lte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) <= 0,\n negated: false,\n };\n case 'in':\n case 'nin':\n return {\n test: actual => matchesAny(actual, filter.values),\n negated: filter.operator === 'nin',\n };\n case 'between':\n case 'nbetween':\n return {\n test: actual => isBetween(actual, filter.start, filter.end),\n negated: filter.operator === 'nbetween',\n };\n case 'like':\n case 'nlike':\n return {\n test: actual => matchesLike(actual, filter.value),\n negated: filter.operator === 'nlike',\n };\n case 'isNull':\n case 'isNotNull':\n return {\n test: actual => actual != null,\n negated: filter.operator === 'isNull',\n };\n default: {\n // Exhaustiveness guard — a new operator must be handled explicitly.\n const never: never = filter;\n throw new Error(\n `Unknown filter operator \"${String((never as { operator: unknown }).operator)}\"`,\n );\n }\n }\n}\n\nfunction matchesFilter<TEntity extends Entity>(\n record: TEntity,\n filter: EntityFilter<TEntity>,\n): boolean {\n const { test, negated } = positiveTest(filter);\n const property = String(filter.property);\n const elements = valuesThroughArray(record, property);\n const holds =\n elements === undefined\n ? test(valueAt(record, property))\n : elements.some(test);\n return negated ? !holds : holds;\n}\n\nfunction matchesNode<TEntity extends Entity>(\n record: TEntity,\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): boolean {\n if (!isFilterGroup(node)) return matchesFilter(record, node);\n return node.operator === 'or'\n ? node.values.some(child => matchesNode(record, child))\n : node.values.every(child => matchesNode(record, child));\n}\n\n/** Whether one record matches a request's filtering. */\nexport function matchesFiltering<TEntity extends Entity>(\n record: TEntity,\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): boolean {\n return (filtering ?? []).every(entry =>\n Array.isArray(entry)\n ? entry.every(child => matchesNode(record, child))\n : matchesNode(record, entry),\n );\n}\n\n/** The records a request's filtering keeps, in the order they were given. */\nexport function applyFiltering<TEntity extends Entity>(\n records: readonly TEntity[],\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): TEntity[] {\n return records.filter(record => matchesFiltering(record, filtering));\n}\n\n/**\n * The records in the order a request asks for, as a new array. `EntitySorting`\n * is a record keyed by priority rather than a list, so two keys cannot tie by\n * accident. No key leaves the order the records were given in.\n */\nexport function applySorting<TEntity extends Entity>(\n records: readonly TEntity[],\n sorting: readonly EntitySorting<TEntity>[] | undefined,\n): TEntity[] {\n const keys = (sorting ?? []).flatMap(entry =>\n Object.keys(entry)\n .map(Number)\n .sort((left, right) => left - right)\n .map(priority => entry[priority])\n .filter(key => key != null),\n );\n if (keys.length === 0) return [...records];\n\n return [...records].sort((left, right) => {\n for (const key of keys) {\n const property = String(key.property);\n const compared = compareStoredValues(\n valueAt(left, property),\n valueAt(right, property),\n );\n if (compared !== 0) return key.type === 'desc' ? -compared : compared;\n }\n return 0;\n });\n}\n\nconst isFacetValue = (value: unknown): value is EntityFacetValue['value'] =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean';\n\n/** Count first, highest first; a tie by value, so the order is stable. */\nconst byCountThenValue = (left: EntityFacetValue, right: EntityFacetValue) =>\n right.count - left.count || compareStoredValues(left.value, right.value);\n\n/**\n * How many records hold each value of each queried member, each member counted\n * over the records **its own** filtering keeps — the in-memory form of a Mongo\n * `$facet` of `$match`, `$unwind` and `$group`, with its rules:\n * - an array member counts each element, as `$unwind` does;\n * - a missing or `null` value, or an empty array, is not counted;\n * - only a string, number or boolean is a value; anything else is skipped.\n */\nexport function countFacets<TEntity extends Entity>(\n records: readonly TEntity[],\n queries: readonly EntityFacetQuery<TEntity>[],\n): EntityFacetCounts {\n const counts: Record<string, readonly EntityFacetValue[]> = {};\n for (const { member, filtering } of queries) {\n const tally = new Map<EntityFacetValue['value'], number>();\n for (const record of applyFiltering(records, filtering)) {\n const stored = valueAt(record, member);\n for (const value of Array.isArray(stored) ? stored : [stored]) {\n if (isFacetValue(value)) tally.set(value, (tally.get(value) ?? 0) + 1);\n }\n }\n counts[member] = Array.from(tally, ([value, count]) => ({\n value,\n count,\n })).sort(byCountThenValue);\n }\n return counts;\n}\n"],"names":["EntityCollectionLink","EntityLink","containsFolded","storedValue","value","id","ids","valueAt","record","property","member","path","split","reduce","key","undefined","compareStoredValues","left","right","Date","getTime","String","localeCompare","isEqual","actual","matchesAny","values","matches","element","some","Array","isArray","matchesLike","isFilterGroup","node","operator","isBetween","start","end","valuesThroughArray","dot","indexOf","elements","slice","map","positiveTest","filter","test","negated","never","Error","matchesFilter","holds","matchesNode","child","every","matchesFiltering","filtering","entry","applyFiltering","records","applySorting","sorting","keys","flatMap","Object","Number","sort","priority","length","compared","type","isFacetValue","byCountThenValue","count","countFacets","queries","counts","tally","Map","stored","set","get","from"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,6DAA6D;AAClG,SAASC,UAAU,QAAQ,kDAAkD;AAa7E,SAASC,cAAc,QAAQ,YAAY;AAE3C;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;;CAKC,GACD,OAAO,SAASC,YAAYC,KAAc;IACxC,IAAIA,iBAAiBH,YAAY,OAAOG,MAAMC,EAAE;IAChD,IAAID,iBAAiBJ,sBAAsB,OAAOI,MAAME,GAAG;IAC3D,OAAOF;AACT;AAEA;;;;CAIC,GACD,OAAO,SAASG,QAAQC,MAAc,EAAEC,QAAgB;IACtD,MAAM,CAACC,QAAQ,GAAGC,KAAK,GAAGF,SAASG,KAAK,CAAC;IACzC,OAAOD,KAAKE,MAAM,CAChB,CAACT,OAAOU,MACN,OAAOV,UAAU,YAAYA,UAAU,OACnC,AAACA,KAAiC,CAACU,IAAI,GACvCC,WACNZ,YAAY,AAACK,MAAkC,CAACE,OAAiB;AAErE;AAEA,wEAAwE,GACxE,OAAO,SAASM,oBAAoBC,IAAa,EAAEC,KAAc;IAC/D,IAAID,SAASC,OAAO,OAAO;IAC3B,iDAAiD;IACjD,IAAID,QAAQ,MAAM,OAAOC,SAAS,OAAO,IAAI,CAAC;IAC9C,IAAIA,SAAS,MAAM,OAAO;IAC1B,IAAI,OAAOD,SAAS,YAAY,OAAOC,UAAU,UAAU;QACzD,OAAOD,OAAOC;IAChB;IACA,IAAID,gBAAgBE,QAAQD,iBAAiBC,MAAM;QACjD,OAAOF,KAAKG,OAAO,KAAKF,MAAME,OAAO;IACvC;IACA,OAAOC,OAAOJ,MAAMK,aAAa,CAACD,OAAOH;AAC3C;AAEA,oEAAoE,GACpE,MAAMK,UAAU,CAACC,QAAiBpB,QAChCoB,kBAAkBL,QAAQf,iBAAiBe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C,CAAC1E,OAAOsE,MAAM,GAAM,CAAA;gBACtDtE;gBACAsE;YACF,CAAA,GAAIP,IAAI,CAACM;IACX;IACA,OAAOI;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../src/query/in-memory-query.ts"],"sourcesContent":["import { EntityCollectionLink } from '../entity-definition/links/entity-collection-link/index.js';\nimport { EntityLink } from '../entity-definition/links/entity-link/index.js';\nimport type { Entity } from '../types/Entity.js';\nimport type {\n EntityFacetCounts,\n EntityFacetQuery,\n EntityFacetValue,\n} from '../types/EntityFacets.js';\nimport type {\n EntityFilter,\n EntityFiltering,\n FilterGroup,\n} from '../types/EntityFiltering.js';\nimport type { EntitySorting } from '../types/EntitySorting.js';\nimport { containsFolded } from './fold.js';\n\n/**\n * An {@link EntityLoadRequest}'s filtering and sorting, answered over records\n * held in memory, with the semantics of the Mongo adapter.\n *\n * One implementation for everything that queries records it holds itself — the\n * in-memory test double, the static repository, a published view — so none of\n * them can drift into a more forgiving version of the others. They used to be\n * separate copies, and one of them compared an array member with `===` and so\n * never matched `in` (#34).\n *\n * The rules, each Mongo's:\n * - a link is its target's id, a collection link the list of their ids;\n * - `in` and `nin` against an array match when **any element** does, as `$in`;\n * - a property may be a dotted path into a member holding an object, which is\n * how a filter reaches one locale of a `localized` member (`name.en`);\n * - `like` is a substring match that ignores accents and case — `cafe` finds\n * `Café` — by the one rule in `fold.ts` every adapter derives its form from;\n * - a missing value sorts below a present one, numbers and dates compare as\n * themselves and anything else as text;\n * - every top-level filtering entry is combined with `and`.\n */\n\n/**\n * A member as the Mongo adapter stores it, and so as its queries see it: a\n * link is its target's id, a collection link the list of their ids. Without\n * this no operator can compare a link, since `eq` against an id is never\n * `true` for an object.\n */\nexport function storedValue(value: unknown): unknown {\n if (value instanceof EntityLink) return value.id;\n if (value instanceof EntityCollectionLink) return value.ids;\n return value;\n}\n\n/**\n * The value a property names: a member, or a dotted path into one. A path\n * through something that is not an object ends in `undefined`, as a missing\n * field does in Mongo.\n */\nexport function valueAt(record: object, property: string): unknown {\n const [member, ...path] = property.split('.');\n return path.reduce<unknown>(\n (value, key) =>\n typeof value === 'object' && value !== null\n ? (value as Record<string, unknown>)[key]\n : undefined,\n storedValue((record as Record<string, unknown>)[member as string]),\n );\n}\n\n/** Ordering with Mongo's rules; `0` for two values it considers equal. */\nexport function compareStoredValues(left: unknown, right: unknown): number {\n if (left === right) return 0;\n // Mongo sorts missing values below present ones.\n if (left == null) return right == null ? 0 : -1;\n if (right == null) return 1;\n if (typeof left === 'number' && typeof right === 'number') {\n return left - right;\n }\n if (left instanceof Date && right instanceof Date) {\n return left.getTime() - right.getTime();\n }\n return String(left).localeCompare(String(right));\n}\n\n/** Equality by value, so two `Date`s naming one instant are equal. */\nconst isEqual = (actual: unknown, value: unknown): boolean =>\n actual instanceof Date && value instanceof Date\n ? actual.getTime() === value.getTime()\n : actual === value;\n\n/** `$in` semantics: a scalar matches a value, an array when any element does. */\nconst matchesAny = (actual: unknown, values: readonly unknown[]): boolean => {\n const matches = (element: unknown) =>\n values.some(value => isEqual(element, value));\n return Array.isArray(actual) ? actual.some(matches) : matches(actual);\n};\n\n/** `like`: a substring match with accents and case folded off (`fold.ts`). */\nconst matchesLike = (actual: unknown, value: string): boolean =>\n actual != null && containsFolded(String(actual), value);\n\nconst isFilterGroup = <TEntity extends Entity>(\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): node is FilterGroup<TEntity> =>\n !('property' in node) && (node.operator === 'and' || node.operator === 'or');\n\nconst isBetween = (actual: unknown, start: unknown, end: unknown) =>\n actual != null &&\n compareStoredValues(actual, start) >= 0 &&\n compareStoredValues(actual, end) <= 0;\n\n/**\n * The values a dotted path reaches **through an array** — every element's\n * member — or `undefined` when the path crosses no array, so the caller reads\n * the single value as before.\n */\nfunction valuesThroughArray(\n record: object,\n property: string,\n): unknown[] | undefined {\n const dot = property.indexOf('.');\n if (dot === -1) return undefined;\n const elements = storedValue(\n (record as Record<string, unknown>)[property.slice(0, dot)],\n );\n if (!Array.isArray(elements)) return undefined;\n const member = property.slice(dot + 1);\n return elements.map(element =>\n typeof element === 'object' && element !== null\n ? valueAt(element as object, member)\n : undefined,\n );\n}\n\n/**\n * Splits a filter into its positive test and whether the operator negates it,\n * so a path into an array can ask \"any element\" of the positive form and\n * negate the answer — never \"any element is not equal\", which almost always\n * holds.\n */\nfunction positiveTest<TEntity extends Entity>(\n filter: EntityFilter<TEntity>,\n): { readonly test: (actual: unknown) => boolean; readonly negated: boolean } {\n switch (filter.operator) {\n case 'eq':\n case 'ne':\n return {\n test: actual => matchesAny(actual, [filter.value]),\n negated: filter.operator === 'ne',\n };\n case 'gt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) > 0,\n negated: false,\n };\n case 'gte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) >= 0,\n negated: false,\n };\n case 'lt':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) < 0,\n negated: false,\n };\n case 'lte':\n return {\n test: actual =>\n actual != null && compareStoredValues(actual, filter.value) <= 0,\n negated: false,\n };\n case 'in':\n case 'nin':\n return {\n test: actual => matchesAny(actual, filter.values),\n negated: filter.operator === 'nin',\n };\n case 'between':\n case 'nbetween':\n return {\n test: actual => isBetween(actual, filter.start, filter.end),\n negated: filter.operator === 'nbetween',\n };\n case 'like':\n case 'nlike':\n return {\n test: actual => matchesLike(actual, filter.value),\n negated: filter.operator === 'nlike',\n };\n case 'isNull':\n case 'isNotNull':\n return {\n test: actual => actual != null,\n negated: filter.operator === 'isNull',\n };\n default: {\n // Exhaustiveness guard — a new operator must be handled explicitly.\n const never: never = filter;\n throw new Error(\n `Unknown filter operator \"${String((never as { operator: unknown }).operator)}\"`,\n );\n }\n }\n}\n\nfunction matchesFilter<TEntity extends Entity>(\n record: TEntity,\n filter: EntityFilter<TEntity>,\n): boolean {\n const { test, negated } = positiveTest(filter);\n const property = String(filter.property);\n const elements = valuesThroughArray(record, property);\n const holds =\n elements === undefined\n ? test(valueAt(record, property))\n : elements.some(test);\n return negated ? !holds : holds;\n}\n\nfunction matchesNode<TEntity extends Entity>(\n record: TEntity,\n node: EntityFilter<TEntity> | FilterGroup<TEntity>,\n): boolean {\n if (!isFilterGroup(node)) return matchesFilter(record, node);\n return node.operator === 'or'\n ? node.values.some(child => matchesNode(record, child))\n : node.values.every(child => matchesNode(record, child));\n}\n\n/** Whether one record matches a request's filtering. */\nexport function matchesFiltering<TEntity extends Entity>(\n record: TEntity,\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): boolean {\n return (filtering ?? []).every(entry =>\n Array.isArray(entry)\n ? entry.every(child => matchesNode(record, child))\n : matchesNode(record, entry),\n );\n}\n\n/** The records a request's filtering keeps, in the order they were given. */\nexport function applyFiltering<TEntity extends Entity>(\n records: readonly TEntity[],\n filtering: readonly EntityFiltering<TEntity>[] | undefined,\n): TEntity[] {\n return records.filter(record => matchesFiltering(record, filtering));\n}\n\n/**\n * The records in the order a request asks for, as a new array. `EntitySorting`\n * is a record keyed by priority rather than a list, so two keys cannot tie by\n * accident. No key leaves the order the records were given in.\n */\nexport function applySorting<TEntity extends Entity>(\n records: readonly TEntity[],\n sorting: readonly EntitySorting<TEntity>[] | undefined,\n): TEntity[] {\n const keys = (sorting ?? []).flatMap(entry =>\n Object.keys(entry)\n .map(Number)\n .sort((left, right) => left - right)\n .map(priority => entry[priority])\n .filter(key => key != null),\n );\n if (keys.length === 0) return [...records];\n\n return [...records].sort((left, right) => {\n for (const key of keys) {\n const property = String(key.property);\n const compared = compareStoredValues(\n valueAt(left, property),\n valueAt(right, property),\n );\n if (compared !== 0) return key.type === 'desc' ? -compared : compared;\n }\n return 0;\n });\n}\n\nconst isFacetValue = (value: unknown): value is EntityFacetValue['value'] =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean';\n\n/** Count first, highest first; a tie by value, so the order is stable. */\nconst byCountThenValue = (left: EntityFacetValue, right: EntityFacetValue) =>\n right.count - left.count || compareStoredValues(left.value, right.value);\n\n/**\n * How many records hold each value of each queried member, each member counted\n * over the records **its own** filtering keeps — the in-memory form of a Mongo\n * `$facet` of `$match`, `$unwind` and `$group`, with its rules:\n * - an array member counts each element, as `$unwind` does;\n * - a missing or `null` value, or an empty array, is not counted;\n * - only a string, number or boolean is a value; anything else is skipped.\n */\nexport function countFacets<TEntity extends Entity>(\n records: readonly TEntity[],\n queries: readonly EntityFacetQuery<TEntity>[],\n): EntityFacetCounts {\n const counts: Record<string, readonly EntityFacetValue[]> = {};\n for (const { member, filtering } of queries) {\n const tally = new Map<EntityFacetValue['value'], number>();\n for (const record of applyFiltering(records, filtering)) {\n const stored = valueAt(record, member);\n for (const value of Array.isArray(stored) ? stored : [stored]) {\n if (isFacetValue(value)) tally.set(value, (tally.get(value) ?? 0) + 1);\n }\n }\n counts[member] = Array.from(tally, ([value, count]) => ({\n value,\n count,\n })).sort(byCountThenValue);\n }\n return counts;\n}\n"],"names":["EntityCollectionLink","EntityLink","containsFolded","storedValue","value","id","ids","valueAt","record","property","member","path","split","reduce","key","undefined","compareStoredValues","left","right","Date","getTime","String","localeCompare","isEqual","actual","matchesAny","values","matches","element","some","Array","isArray","matchesLike","isFilterGroup","node","operator","isBetween","start","end","valuesThroughArray","dot","indexOf","elements","slice","map","positiveTest","filter","test","negated","never","Error","matchesFilter","holds","matchesNode","child","every","matchesFiltering","filtering","entry","applyFiltering","records","applySorting","sorting","keys","flatMap","Object","Number","sort","priority","length","compared","type","isFacetValue","byCountThenValue","count","countFacets","queries","counts","tally","Map","stored","set","get","from"],"mappings":"AAAA,SAASA,oBAAoB,QAAQ,6DAA6D;AAClG,SAASC,UAAU,QAAQ,kDAAkD;AAa7E,SAASC,cAAc,QAAQ,YAAY;AAE3C;;;;;;;;;;;;;;;;;;;;CAoBC,GAED;;;;;CAKC,GACD,OAAO,SAASC,YAAYC,KAAc;IACxC,IAAIA,iBAAiBH,YAAY,OAAOG,MAAMC,EAAE;IAChD,IAAID,iBAAiBJ,sBAAsB,OAA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