@entifix/core 0.19.0 → 0.20.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/README.md +2 -0
- package/dist/entity-definition/describe/describe-entity-columns.d.ts +7 -1
- package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.js +12 -0
- package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
- package/dist/entity-definition/describe/describe-entity-use-cases.d.ts +6 -2
- package/dist/entity-definition/describe/describe-entity-use-cases.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-entity-use-cases.js +6 -0
- package/dist/entity-definition/describe/describe-entity-use-cases.js.map +1 -1
- package/dist/entity-definition/helpers/entity-definition-helpers.d.ts.map +1 -1
- package/dist/entity-definition/helpers/entity-definition-helpers.js +25 -1
- package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.d.ts +27 -0
- 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 +3 -0
- package/dist/entity-definition/meta-entities/meta-accessor/meta-accessor.js.map +1 -1
- package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts +8 -0
- package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts.map +1 -1
- package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js +2 -0
- package/dist/entity-definition/meta-entities/meta-entity/meta-entity.js.map +1 -1
- package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts +64 -1
- package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.d.ts.map +1 -1
- package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js +6 -0
- package/dist/entity-definition/meta-entities/meta-use-case/meta-use-case.js.map +1 -1
- package/dist/failure/generic.d.ts +14 -0
- package/dist/failure/generic.d.ts.map +1 -1
- package/dist/failure/generic.js +12 -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/shortcut/chord.d.ts +23 -0
- package/dist/shortcut/chord.d.ts.map +1 -0
- package/dist/shortcut/chord.js +64 -0
- package/dist/shortcut/chord.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
The entity system. A class decorated with `@entity()` and `@accessor()` describes itself — its members, their types and labels, which of them are sortable or filterable — and everything else in entifix reads that description instead of being told it again.
|
|
4
4
|
|
|
5
|
+
Presentation lives on the class too: `@entity({ creatable })`, and `@accessor({ minWidth, card, autocomplete })` for how a member reads in a table, on a card and to a browser's autofill. A `@useCase()` declares its place in the action hierarchy (`emphasis`, `priority`, `rowInline`, `shortcut`) and, when destructive, how it is undone (`reversible`, `inverse`); a bad shortcut (`parseChord`) or an unsafe destructive verb fails at load.
|
|
6
|
+
|
|
5
7
|
It also owns what crosses the wire: entity serialization and reconstruction, the envelopes a service answers with, and the RSQL filter and sort protocol a query is written in. Nothing here performs I/O.
|
|
6
8
|
|
|
7
9
|
## Install
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChildConstructor, type EntityLinkSerialization, MetaAccessorType, type MoneyFormat } from '../meta-entities/meta-accessor/index.js';
|
|
1
|
+
import { type CardRole, type ChildConstructor, type EntityLinkSerialization, MetaAccessorType, type MoneyFormat } from '../meta-entities/meta-accessor/index.js';
|
|
2
2
|
/**
|
|
3
3
|
* A displayable member of an entity, resolved from its accessor metadata. This
|
|
4
4
|
* is the contract generic UI builds itself from — a table's columns today, a
|
|
@@ -53,6 +53,12 @@ export interface EntityFieldDescriptor {
|
|
|
53
53
|
notBefore?: string;
|
|
54
54
|
/** The member is an amount of money, read as this declares. `number` members only. */
|
|
55
55
|
money?: MoneyFormat;
|
|
56
|
+
/** The narrowest the member's column reads at, in `rem`, when declared. */
|
|
57
|
+
minWidth?: number;
|
|
58
|
+
/** The part the member plays on a record's card, when declared. */
|
|
59
|
+
card?: CardRole;
|
|
60
|
+
/** The member's HTML autofill token, when declared. */
|
|
61
|
+
autocomplete?: string;
|
|
56
62
|
/** This member holds the parent record's id: the entity forms a tree. */
|
|
57
63
|
parent?: boolean;
|
|
58
64
|
}
|
|
@@ -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,gBAAgB,EACrB,KAAK,uBAAuB,EAE5B,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,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,yEAAyE;IACzE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,6EAA6E;AAC7E,eAAO,MAAM,YAAY,EAAE,SAAS,gBAAgB,EAMnD,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,gBAAgB,EAIvD,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,KAAK,uBAAuB,EAE5B,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,6DAA6D;IAC7D,iBAAiB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AAE,OAAO,CAAC;CAC7B,EAAE,QAWJ;AAsDD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,MAAM,EAC1D,iBAAiB,EAAE,gBAAgB,CAAC,OAAO,CAAC,EAC5C,MAAM,CAAC,EAAE,OAAO,GACf,qBAAqB,EAAE,CAkBzB"}
|
|
@@ -97,6 +97,11 @@ import { assertBounds } from '../meta-entities/bounds.js';
|
|
|
97
97
|
if (metaAccessor.money === undefined || type === 'number') return;
|
|
98
98
|
throw new Error(`"${String(metaAccessor.name)}" is a ${type} and declares money — only a number member can be an amount.`);
|
|
99
99
|
}
|
|
100
|
+
/** A width is a positive length; zero or less would never switch layouts. */ function assertMinWidth(metaAccessor) {
|
|
101
|
+
const { minWidth } = metaAccessor;
|
|
102
|
+
if (minWidth === undefined || Number.isFinite(minWidth) && minWidth > 0) return;
|
|
103
|
+
throw new Error(`"${String(metaAccessor.name)}" declares minWidth ${String(minWidth)} — a column's narrowest width is a positive number of rem.`);
|
|
104
|
+
}
|
|
100
105
|
/**
|
|
101
106
|
* A `currencyMember` must be a visible `string` member of the same entity: a
|
|
102
107
|
* hidden one never reaches the client, so the amount would print with no
|
|
@@ -141,6 +146,7 @@ function toDescriptor(metaAccessor, index, sample) {
|
|
|
141
146
|
assertItemCounts(metaAccessor, type);
|
|
142
147
|
assertParentType(metaAccessor, type);
|
|
143
148
|
assertMoneyType(metaAccessor, type);
|
|
149
|
+
assertMinWidth(metaAccessor);
|
|
144
150
|
// A localized member is queried one locale at a time (`name.en`), which
|
|
145
151
|
// makes it as queryable as the text each locale holds.
|
|
146
152
|
const isScalar = SCALAR_TYPES.includes(type) || type === 'localized';
|
|
@@ -168,6 +174,12 @@ function toDescriptor(metaAccessor, index, sample) {
|
|
|
168
174
|
notBefore: metaAccessor.notBefore
|
|
169
175
|
}, metaAccessor.money === undefined ? {} : {
|
|
170
176
|
money: metaAccessor.money
|
|
177
|
+
}, metaAccessor.minWidth === undefined ? {} : {
|
|
178
|
+
minWidth: metaAccessor.minWidth
|
|
179
|
+
}, metaAccessor.card === undefined ? {} : {
|
|
180
|
+
card: metaAccessor.card
|
|
181
|
+
}, metaAccessor.autocomplete === undefined ? {} : {
|
|
182
|
+
autocomplete: metaAccessor.autocomplete
|
|
171
183
|
}, {
|
|
172
184
|
parent: (_metaAccessor_parent = metaAccessor.parent) != null ? _metaAccessor_parent : false
|
|
173
185
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors } 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 ChildConstructor,\n type EntityLinkSerialization,\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 /** 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 /** This member holds the parent record's id: the entity forms a tree. */\n parent?: boolean;\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/** 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 * 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 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 assertMoneyType(metaAccessor, type);\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 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 parent: metaAccessor.parent ?? false,\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) => toDescriptor(metaAccessor, index, sample))\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","EntityCollectionLink","EntityLink","assertBounds","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","assertMoneyType","money","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","join","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","key","alias","label","labelKey","order","required","enumValues","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","right"],"mappings":";AAAA,SAASA,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,oBAAo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R,aAAaQ,QAAQ;QAC/BC,UAAUT,aAAaS,QAAQ;QAC/BO,WAAWhB,aAAagB,SAAS;OAC7BhB,aAAauB,KAAK,KAAKb,YAAY,CAAC,IAAI;QAAEa,OAAOvB,aAAauB,KAAK;IAAC;QACxEF,MAAM,GAAErB,uBAAAA,aAAaqB,MAAM,YAAnBrB,uBAAuB;;AAEnC;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,SAASwD,sBACdC,iBAA4C,EAC5ChB,MAAgB;IAEhB,MAAMiB,OAAO,IAAIC;IACjBxB,oBAAoBnD,qBAAqByE;IAEzC,MAAM3C,cAAc9B,qBAAqByE,mBACtC1B,MAAM,CAAC/B,CAAAA;QACN,IAAIA,aAAaqC,MAAM,IAAIrC,aAAa4D,IAAI,KAAK,UAAU,OAAO;QAClE,MAAMrE,OAAOe,OAAON,aAAaT,IAAI;QACrC,IAAImE,KAAKG,GAAG,CAACtE,OAAO,OAAO;QAC3BmE,KAAKI,GAAG,CAACvE;QACT,OAAO;IACT,GACC0C,GAAG,CAAC,CAACjC,cAAcwC,QAAUD,aAAavC,cAAcwC,OAAOC,SAC/DsB,IAAI,CAAC,CAACC,MAAMC,QAAUD,KAAKhB,KAAK,GAAGiB,MAAMjB,KAAK;IACjDnC,gBAAgBC;IAChBU,sBAAsBV;IACtBc,gBAAgBd;IAChB,OAAOA;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-columns.ts"],"sourcesContent":["import { extractMetaAccessors } 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 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 /** 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\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/** 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/** 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 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 assertMoneyType(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 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 };\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) => toDescriptor(metaAccessor, index, sample))\n .sort((left, right) => left.order - right.order);\n assertNotBefore(descriptors);\n assertCurrencyMembers(descriptors);\n assertOneParent(descriptors);\n return descriptors;\n}\n"],"names":["extractMetaAccessors","EntityCollectionLink","EntityLink","assertBounds","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","assertMoneyType","money","assertMinWidth","minWidth","Number","isFinite","assertCurrencyMembers","member","currencyMember","currency","assertOneParent","members","parents","filter","length","map","join","assertParentVisible","stuck","hidden","readonly","toDescriptor","index","sample","isScalar","linkLabelProperty","key","alias","label","labelKey","order","required","enumValues","enumLabelKey","linkSearchProperty","linkSerialization","childType","resetOnClone","card","autocomplete","describeEntityColumns","entityConstructor","seen","Set","kind","has","add","sort","left","right"],"mappings":";AAAA,SAASA,oBAAoB,QAAQ,sBAAsB;AAC3D,SAASC,oBAAoB,QAAQ,2CAA2C;AAChF,SAASC,UAAU,QAAQ,gCAAgC;AAC3D,SAASC,YAAY,QAAQ,6BAA6B;AA0E1D,2EAA2E,GAC3E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,gBAAgBC;IAChBc,sBAAsBd;IACtBkB,gBAAgBlB;IAChB,OAAOA;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Entity, EntityConstructor } from '../../types/Entity.js';
|
|
2
|
-
import type { UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCasePlacement } from '../meta-entities/meta-use-case/index.js';
|
|
2
|
+
import type { UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCaseHierarchy, UseCasePlacement, UseCaseReversible } from '../meta-entities/meta-use-case/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* An action a caller may take on an entity, resolved from its use-case
|
|
5
5
|
* metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,
|
|
@@ -8,7 +8,7 @@ import type { UseCaseBinding, UseCaseCell, UseCaseConfirm, UseCasePlacement } fr
|
|
|
8
8
|
* It carries no `entity`: this is the shape that goes over the wire from
|
|
9
9
|
* `GET /api/<entity>/$metadata`, where the entity is already the address.
|
|
10
10
|
*/
|
|
11
|
-
export interface UseCaseDescriptor {
|
|
11
|
+
export interface UseCaseDescriptor extends UseCaseHierarchy {
|
|
12
12
|
/** The verb. Also the third segment of the permission guarding it. */
|
|
13
13
|
key: string;
|
|
14
14
|
binding: UseCaseBinding;
|
|
@@ -18,6 +18,10 @@ export interface UseCaseDescriptor {
|
|
|
18
18
|
labelKey: string;
|
|
19
19
|
keywordsKey?: string;
|
|
20
20
|
confirm?: UseCaseConfirm;
|
|
21
|
+
/** How a destructive verb is made safe — see `UseCaseReversible`. */
|
|
22
|
+
reversible?: UseCaseReversible;
|
|
23
|
+
/** The verb Undo runs, by key. */
|
|
24
|
+
inverse?: string;
|
|
21
25
|
form?: string;
|
|
22
26
|
/** The named variant set this verb resolves between. */
|
|
23
27
|
variants?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,
|
|
1
|
+
{"version":3,"file":"describe-entity-use-cases.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,yCAAyC,CAAC;AAEjD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAkB,SAAQ,gBAAgB;IACzD,sEAAsE;IACtE,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;IAC5B,0EAA0E;IAC1E,MAAM,CAAC,EAAE,SAAS,WAAW,EAAE,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,qEAAqE;IACrE,UAAU,CAAC,EAAE,iBAAiB,CAAC;IAC/B,kCAAkC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,WAAW,CAAC,EAAE,kBAAkB,CAAC;CAClC;AAED,wEAAwE;AACxE,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0DAA0D;IAC1D,SAAS,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC/B;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,MAAM,EAC3D,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,iBAAiB,EAAE,CAmBrB"}
|
|
@@ -18,6 +18,12 @@ import { extractMetaUseCases } from '../helpers/index.js';
|
|
|
18
18
|
labelKey: metaUseCase.labelKey,
|
|
19
19
|
keywordsKey: metaUseCase.keywordsKey,
|
|
20
20
|
confirm: metaUseCase.confirm,
|
|
21
|
+
reversible: metaUseCase.reversible,
|
|
22
|
+
inverse: metaUseCase.inverse,
|
|
23
|
+
emphasis: metaUseCase.emphasis,
|
|
24
|
+
priority: metaUseCase.priority,
|
|
25
|
+
rowInline: metaUseCase.rowInline,
|
|
26
|
+
shortcut: metaUseCase.shortcut,
|
|
21
27
|
form: metaUseCase.form,
|
|
22
28
|
variants: metaUseCase.variants,
|
|
23
29
|
recipe: metaUseCase.recipe
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCasePlacement,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","form","variants","recipe"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/describe/describe-entity-use-cases.ts"],"sourcesContent":["import { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaUseCases } from '../helpers/index.js';\nimport type {\n UseCaseBinding,\n UseCaseCell,\n UseCaseConfirm,\n UseCaseHierarchy,\n UseCasePlacement,\n UseCaseReversible,\n} from '../meta-entities/meta-use-case/index.js';\n\n/**\n * An action a caller may take on an entity, resolved from its use-case\n * metadata. The counterpart to {@link EntityFieldDescriptor}, and like it,\n * framework-free and copy-free — every human-readable member is a catalog key.\n *\n * It carries no `entity`: this is the shape that goes over the wire from\n * `GET /api/<entity>/$metadata`, where the entity is already the address.\n */\nexport interface UseCaseDescriptor extends UseCaseHierarchy {\n /** The verb. Also the third segment of the permission guarding it. */\n key: string;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /** Further cells this same verb appears in — see `MetaUseCaseOptions`. */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe — see `UseCaseReversible`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. */\n inverse?: string;\n form?: string;\n /** The named variant set this verb resolves between. */\n variants?: string;\n /** The named recipe this verb starts a flow from. */\n recipe?: string;\n /**\n * What this verb resolves to **for the caller asking** — present only on a\n * served `$metadata` document, computed per principal.\n */\n composition?: UseCaseComposition;\n}\n\n/** Which variant, and which flow, a verb resolves to for one caller. */\nexport interface UseCaseComposition {\n useCase: string;\n variant: string;\n recipe?: string;\n slipVersion?: number;\n /** The `id@n` references the recipe can pin, in order. */\n fragments?: readonly string[];\n}\n\n/**\n * Resolves the use cases declared against an entity, in declaration order.\n *\n * Unlike {@link describeEntityColumns}, this is only trustworthy where the\n * use-case modules have been loaded: a `@useCase()` class registers itself when\n * its module evaluates. On a service that is the composition root's job, and\n * a host's register should fail the build on a class its package barrel does\n * not export.\n * A browser never calls this — it fetches the descriptors instead, so no\n * use-case implementation reaches a client bundle.\n */\nexport function describeEntityUseCases<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): UseCaseDescriptor[] {\n return extractMetaUseCases(entityConstructor).map(metaUseCase => ({\n key: metaUseCase.key,\n binding: metaUseCase.binding,\n placement: metaUseCase.placement,\n alsoAt: metaUseCase.alsoAt,\n labelKey: metaUseCase.labelKey,\n keywordsKey: metaUseCase.keywordsKey,\n confirm: metaUseCase.confirm,\n reversible: metaUseCase.reversible,\n inverse: metaUseCase.inverse,\n emphasis: metaUseCase.emphasis,\n priority: metaUseCase.priority,\n rowInline: metaUseCase.rowInline,\n shortcut: metaUseCase.shortcut,\n form: metaUseCase.form,\n variants: metaUseCase.variants,\n recipe: metaUseCase.recipe,\n }));\n}\n"],"names":["extractMetaUseCases","describeEntityUseCases","entityConstructor","map","metaUseCase","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe"],"mappings":"AACA,SAASA,mBAAmB,QAAQ,sBAAsB;AAsD1D;;;;;;;;;;CAUC,GACD,OAAO,SAASC,uBACdC,iBAA6C;IAE7C,OAAOF,oBAAoBE,mBAAmBC,GAAG,CAACC,CAAAA,cAAgB,CAAA;YAChEC,KAAKD,YAAYC,GAAG;YACpBC,SAASF,YAAYE,OAAO;YAC5BC,WAAWH,YAAYG,SAAS;YAChCC,QAAQJ,YAAYI,MAAM;YAC1BC,UAAUL,YAAYK,QAAQ;YAC9BC,aAAaN,YAAYM,WAAW;YACpCC,SAASP,YAAYO,OAAO;YAC5BC,YAAYR,YAAYQ,UAAU;YAClCC,SAAST,YAAYS,OAAO;YAC5BC,UAAUV,YAAYU,QAAQ;YAC9BC,UAAUX,YAAYW,QAAQ;YAC9BC,WAAWZ,YAAYY,SAAS;YAChCC,UAAUb,YAAYa,QAAQ;YAC9BC,MAAMd,YAAYc,IAAI;YACtBC,UAAUf,YAAYe,QAAQ;YAC9BC,QAAQhB,YAAYgB,MAAM;QAC5B,CAAA;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity-definition-helpers.d.ts","sourceRoot":"","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EAAE,kBAAkB,QAG5B;AAQD,wBAAgB,iBAAiB,CAAC,OAAO,SAAS,MAAM,EACtD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,CAOZ;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAG7E;AAED,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,UAAU,EAAE,CAGd;AAED,8EAA8E;AAC9E,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GACjC,WAAW,EAAE,CAGf;AAED,2DAA2D;AAC3D,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,kBAAkB,GACzB,kBAAkB,CAYpB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,kBAAkB,GAAG,WAAW,CAQtE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var _Symbol, _metadata;
|
|
2
2
|
(_metadata = (_Symbol = Symbol).metadata) != null ? _metadata : _Symbol.metadata = Symbol.for('Symbol.metadata');
|
|
3
|
+
import { assertChord } from '../../shortcut/chord.js';
|
|
3
4
|
export const META_ENTITY_KEY = Symbol('MetaEntity');
|
|
4
5
|
export const META_ACCESSOR_KEY = Symbol('MetaAccessor');
|
|
5
6
|
export const META_METHOD_KEY = Symbol('MetaMethod');
|
|
@@ -49,12 +50,35 @@ export function appendMetaMethod(metadata, metaMethod) {
|
|
|
49
50
|
* `@entity()`, or a circular import that evaluated the use case first.
|
|
50
51
|
*/ export function appendMetaUseCase(target, metaUseCase) {
|
|
51
52
|
var _own_META_USE_CASE_KEY;
|
|
52
|
-
var _Object_getOwnPropertyDescriptor;
|
|
53
|
+
var _Object_getOwnPropertyDescriptor, _metaUseCase_confirm;
|
|
53
54
|
const own = (_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(target, Symbol.metadata)) == null ? void 0 : _Object_getOwnPropertyDescriptor.value;
|
|
54
55
|
if (!own) {
|
|
55
56
|
throw new Error(`Use case "${metaUseCase.key}" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`);
|
|
56
57
|
}
|
|
58
|
+
if (((_metaUseCase_confirm = metaUseCase.confirm) == null ? void 0 : _metaUseCase_confirm.tone) === 'destructive' && metaUseCase.reversible === undefined) {
|
|
59
|
+
throw new Error(`Use case "${metaUseCase.key}" on ${target.name} is destructive and declares no \`reversible\`. Say how it is made safe: 'undo' (with an \`inverse\`), 'confirm' or 'typed'.`);
|
|
60
|
+
}
|
|
61
|
+
if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {
|
|
62
|
+
throw new Error(`Use case "${metaUseCase.key}" on ${target.name} is reversible by undo and names no \`inverse\`: Undo has nothing to run.`);
|
|
63
|
+
}
|
|
64
|
+
// A shortcut is checked where it is declared, so a chord no reader can use
|
|
65
|
+
// — a bare key, Option+letter, Mod+C — fails at load rather than on a page.
|
|
66
|
+
if (metaUseCase.shortcut !== undefined) {
|
|
67
|
+
try {
|
|
68
|
+
assertChord(metaUseCase.shortcut);
|
|
69
|
+
} catch (refused) {
|
|
70
|
+
throw new Error(`Use case "${metaUseCase.key}" on ${target.name}: ${refused.message}`, {
|
|
71
|
+
cause: refused
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
57
75
|
const existing = (_own_META_USE_CASE_KEY = own[META_USE_CASE_KEY]) != null ? _own_META_USE_CASE_KEY : [];
|
|
76
|
+
// A verb declared on a record and over a selection is one verb under one
|
|
77
|
+
// key, so only a different key makes a second inline verb.
|
|
78
|
+
const inline = existing.find((declared)=>declared.rowInline && declared.key !== metaUseCase.key);
|
|
79
|
+
if (metaUseCase.rowInline && inline) {
|
|
80
|
+
throw new Error(`Use case "${metaUseCase.key}" on ${target.name} is rowInline, and so is "${inline.key}": a row shows at most one verb inline.`);
|
|
81
|
+
}
|
|
58
82
|
own[META_USE_CASE_KEY] = [
|
|
59
83
|
...existing,
|
|
60
84
|
metaUseCase
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * Every accessor declared on a class.\n *\n * The target is a {@link ChildConstructor}, not an `EntityConstructor`: an\n * `@accessor()` writes to its own class's metadata bag with no help from\n * `@entity()`, so a `composition` member's child — a value with no `id` — is\n * described by exactly this walk.\n */\nexport function extractMetaAccessors(target: ChildConstructor): MetaAccessor[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n}\n\nexport function extractMetaMethods<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaMethod[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n}\n\n/** Every use case declared against an entity. Empty until one is imported. */\nexport function extractMetaUseCases<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaUseCase[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n}\n\n/** The entity and verb a `@useCase()` class implements. */\nexport function extractMetaUseCaseBinding(\n target: UseCaseConstructor,\n): MetaUseCaseBinding {\n const metadata = (\n target as { [Symbol.metadata]?: DecoratorMetadataObject | null }\n )[Symbol.metadata];\n const binding = metadata?.[META_USE_CASE_BINDING_KEY] as\n MetaUseCaseBinding | undefined;\n if (!binding) {\n throw new Error(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n\n/**\n * The `@useCase()` a class declares, as the entity it is declared against\n * holds it — with its binding and its endpoint contract.\n */\nexport function extractUseCase(target: UseCaseConstructor): MetaUseCase {\n const { entity, key, binding } = extractMetaUseCaseBinding(target);\n // `@useCase()` appends to the entity before it records the binding, so a\n // bound class always has its entry — found by binding as well as key, since\n // one key may be declared on a record and over a selection.\n return extractMetaUseCases(entity).find(\n metaUseCase => metaUseCase.key === key && metaUseCase.binding === binding,\n ) as MetaUseCase;\n}\n"],"names":["Symbol","metadata","for","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","Error","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","setMetaUseCaseBinding","binding","readMetadata","undefined","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity","find"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAqB1D,OAAO,MAAMC,kBAAkBH,OAAO,cAAc;AACpD,OAAO,MAAMI,oBAAoBJ,OAAO,gBAAgB;AACxD,OAAO,MAAMK,kBAAkBL,OAAO,cAAc;AACpD,OAAO,MAAMM,oBAAoBN,OAAO,eAAe;AACvD,OAAO,MAAMO,4BAA4BP,OAAO,sBAAsB;AAEtE,SAASQ,gBACPP,QAA6C;IAE7C,IAAI,CAACA,UAAU;QACb,MAAM,IAAIQ,MACR;IAEJ;IACA,OAAOR;AACT;AAEA,OAAO,SAASS,cACdT,QAA6C,EAC7CU,UAAsB;IAEtBH,gBAAgBP,SAAS,CAACE,gBAAgB,GAAGQ;AAC/C;AAEA,OAAO,SAASC,mBACdX,QAA6C,EAC7CY,YAA0B;QAIvBC;IAFH,MAAMA,OAAON,gBAAgBP;IAC7B,MAAMc,YACHD,0BAAAA,IAAI,CAACV,kBAAkB,YAAvBU,0BAA0D,EAAE;IAC/DA,IAAI,CAACV,kBAAkB,GAAG;WAAIW;QAAUF;KAAa;AACvD;AAEA,OAAO,SAASG,iBACdf,QAA6C,EAC7CgB,UAAsB;QAGJH;IADlB,MAAMA,O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AAO,SAAS6B,mBACdd,MAAkC;;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACI,gBAAgB,mBAAiC,EAAE;AACxE;AAEA,4EAA4E,GAC5E,OAAO,SAAS6B,oBACdf,MAAkC;;IAElC,MAAMlB,WAAW4B,aAAaV;IAC9B,eAAQlB,4BAAAA,QAAU,CAACK,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAAS6B,0BACdhB,MAA0B;IAE1B,MAAMlB,WAAW,AACfkB,MACD,CAACnB,OAAOC,QAAQ,CAAC;IAClB,MAAM2B,UAAU3B,4BAAAA,QAAU,CAACM,0BAA0B;IAErD,IAAI,CAACqB,SAAS;QACZ,MAAM,IAAInB,MACR,CAAC,0BAA0B,EAAEU,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOE;AACT;AAEA;;;CAGC,GACD,OAAO,SAASQ,eAAejB,MAA0B;IACvD,MAAM,EAAEkB,MAAM,EAAEZ,GAAG,EAAEG,OAAO,EAAE,GAAGO,0BAA0BhB;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAOe,oBAAoBG,QAAQC,IAAI,CACrClB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYQ,OAAO,KAAKA;AAEtE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"sourcesContent":["(Symbol as { metadata?: symbol }).metadata ??= Symbol.for('Symbol.metadata');\n\nimport { assertChord } from '../../shortcut/chord.js';\nimport { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { UseCaseConstructor } from '../../types/UseCase.js';\nimport {\n type ChildConstructor,\n MetaAccessor,\n} from '../meta-entities/meta-accessor/index.js';\nimport { MetaEntity } from '../meta-entities/meta-entity/index.js';\nimport { MetaMethod } from '../meta-entities/meta-method/index.js';\nimport {\n MetaUseCase,\n MetaUseCaseBinding,\n} from '../meta-entities/meta-use-case/index.js';\n\ndeclare global {\n interface SymbolConstructor {\n readonly metadata: unique symbol;\n }\n}\n\nexport const META_ENTITY_KEY = Symbol('MetaEntity');\nexport const META_ACCESSOR_KEY = Symbol('MetaAccessor');\nexport const META_METHOD_KEY = Symbol('MetaMethod');\nexport const META_USE_CASE_KEY = Symbol('MetaUseCase');\nexport const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');\n\nfunction requireMetadata(\n metadata: DecoratorMetadataObject | undefined,\n): DecoratorMetadataObject {\n if (!metadata) {\n throw new Error(\n 'Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.',\n );\n }\n return metadata;\n}\n\nexport function setMetaEntity(\n metadata: DecoratorMetadataObject | undefined,\n metaEntity: MetaEntity,\n) {\n requireMetadata(metadata)[META_ENTITY_KEY] = metaEntity;\n}\n\nexport function appendMetaAccessor(\n metadata: DecoratorMetadataObject | undefined,\n metaAccessor: MetaAccessor,\n) {\n const meta = requireMetadata(metadata);\n const existing =\n (meta[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n meta[META_ACCESSOR_KEY] = [...existing, metaAccessor];\n}\n\nexport function appendMetaMethod(\n metadata: DecoratorMetadataObject | undefined,\n metaMethod: MetaMethod,\n) {\n const meta = requireMetadata(metadata);\n const existing = (meta[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n meta[META_METHOD_KEY] = [...existing, metaMethod];\n}\n\n/**\n * Append a use case to the metadata of the entity it acts on.\n *\n * This is the one decorator that writes a bag other than its own: a use case is\n * declared on its own class, but the entity is what a surface holds, so the\n * descriptor has to end up there. The consequence is that a use-case module\n * which is never imported leaves the entity looking as if it had no actions,\n * which is why a host's register should assert every `@useCase()` class is\n * re-exported from its package barrel.\n *\n * It reads the target's **own** metadata rather than going through\n * {@link readMetadata}. `Symbol.metadata` resolves along the prototype chain, so\n * an inherited read would append the verb to a base class's bag and leak it to\n * every subclass. A target with no own metadata is an entity missing\n * `@entity()`, or a circular import that evaluated the use case first.\n */\nexport function appendMetaUseCase<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n metaUseCase: MetaUseCase,\n) {\n const own = Object.getOwnPropertyDescriptor(target, Symbol.metadata)\n ?.value as DecoratorMetadataObject | null | undefined;\n if (!own) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" targets ${target.name}, which has no metadata of its own — it is missing @entity(), or a circular import evaluated the use case first.`,\n );\n }\n if (\n metaUseCase.confirm?.tone === 'destructive' &&\n metaUseCase.reversible === undefined\n ) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is destructive and declares no \\`reversible\\`. Say how it is made safe: 'undo' (with an \\`inverse\\`), 'confirm' or 'typed'.`,\n );\n }\n if (metaUseCase.reversible === 'undo' && metaUseCase.inverse === undefined) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is reversible by undo and names no \\`inverse\\`: Undo has nothing to run.`,\n );\n }\n // A shortcut is checked where it is declared, so a chord no reader can use\n // — a bare key, Option+letter, Mod+C — fails at load rather than on a page.\n if (metaUseCase.shortcut !== undefined) {\n try {\n assertChord(metaUseCase.shortcut);\n } catch (refused) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name}: ${(refused as Error).message}`,\n { cause: refused },\n );\n }\n }\n const existing = (own[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n // A verb declared on a record and over a selection is one verb under one\n // key, so only a different key makes a second inline verb.\n const inline = existing.find(\n declared => declared.rowInline && declared.key !== metaUseCase.key,\n );\n if (metaUseCase.rowInline && inline) {\n throw new Error(\n `Use case \"${metaUseCase.key}\" on ${target.name} is rowInline, and so is \"${inline.key}\": a row shows at most one verb inline.`,\n );\n }\n own[META_USE_CASE_KEY] = [...existing, metaUseCase];\n}\n\n/**\n * Record on the use-case class itself which entity and verb it implements, so\n * the permission can be derived from the class alone. That is what keeps the\n * verb string written once, at the declaration, instead of being retyped at\n * every guard.\n */\nexport function setMetaUseCaseBinding(\n metadata: DecoratorMetadataObject | undefined,\n binding: MetaUseCaseBinding,\n) {\n requireMetadata(metadata)[META_USE_CASE_BINDING_KEY] = binding;\n}\n\nfunction readMetadata(\n target: ChildConstructor,\n): DecoratorMetadataObject | undefined {\n return target[Symbol.metadata] ?? undefined;\n}\n\nexport function extractMetaEntity<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaEntity {\n const metadata = readMetadata(target);\n const metaEntity = metadata?.[META_ENTITY_KEY] as MetaEntity | undefined;\n if (!metaEntity) {\n throw new Error(`MetaEntity not found for ${target.name}`);\n }\n return metaEntity;\n}\n\n/**\n * Every accessor declared on a class.\n *\n * The target is a {@link ChildConstructor}, not an `EntityConstructor`: an\n * `@accessor()` writes to its own class's metadata bag with no help from\n * `@entity()`, so a `composition` member's child — a value with no `id` — is\n * described by exactly this walk.\n */\nexport function extractMetaAccessors(target: ChildConstructor): MetaAccessor[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_ACCESSOR_KEY] as MetaAccessor[] | undefined) ?? [];\n}\n\nexport function extractMetaMethods<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaMethod[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_METHOD_KEY] as MetaMethod[] | undefined) ?? [];\n}\n\n/** Every use case declared against an entity. Empty until one is imported. */\nexport function extractMetaUseCases<TEntity extends Entity>(\n target: EntityConstructor<TEntity>,\n): MetaUseCase[] {\n const metadata = readMetadata(target);\n return (metadata?.[META_USE_CASE_KEY] as MetaUseCase[] | undefined) ?? [];\n}\n\n/** The entity and verb a `@useCase()` class implements. */\nexport function extractMetaUseCaseBinding(\n target: UseCaseConstructor,\n): MetaUseCaseBinding {\n const metadata = (\n target as { [Symbol.metadata]?: DecoratorMetadataObject | null }\n )[Symbol.metadata];\n const binding = metadata?.[META_USE_CASE_BINDING_KEY] as\n MetaUseCaseBinding | undefined;\n if (!binding) {\n throw new Error(\n `MetaUseCase not found for ${target.name} — is it missing @useCase()?`,\n );\n }\n return binding;\n}\n\n/**\n * The `@useCase()` a class declares, as the entity it is declared against\n * holds it — with its binding and its endpoint contract.\n */\nexport function extractUseCase(target: UseCaseConstructor): MetaUseCase {\n const { entity, key, binding } = extractMetaUseCaseBinding(target);\n // `@useCase()` appends to the entity before it records the binding, so a\n // bound class always has its entry — found by binding as well as key, since\n // one key may be declared on a record and over a selection.\n return extractMetaUseCases(entity).find(\n metaUseCase => metaUseCase.key === key && metaUseCase.binding === binding,\n ) as MetaUseCase;\n}\n"],"names":["Symbol","metadata","for","assertChord","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","Error","setMetaEntity","metaEntity","appendMetaAccessor","metaAccessor","meta","existing","appendMetaMethod","metaMethod","appendMetaUseCase","target","metaUseCase","own","Object","getOwnPropertyDescriptor","value","key","name","confirm","tone","reversible","undefined","inverse","shortcut","refused","message","cause","inline","find","declared","rowInline","setMetaUseCaseBinding","binding","readMetadata","extractMetaEntity","extractMetaAccessors","extractMetaMethods","extractMetaUseCases","extractMetaUseCaseBinding","extractUseCase","entity"],"mappings":"IAACA,SAAD;CAAA,YAAA,CAACA,UAAAA,QAAiCC,QAAQ,YAA1C,YAAA,AAACD,QAAiCC,QAAQ,GAAKD,OAAOE,GAAG,CAAC;AAE1D,SAASC,WAAW,QAAQ,0BAA0B;AAoBtD,OAAO,MAAMC,kBAAkBJ,OAAO,cAAc;AACpD,OAAO,MAAMK,oBAAoBL,OAAO,gBAAgB;AACxD,OAAO,MAAMM,kBAAkBN,OAAO,cAAc;AACpD,OAAO,MAAMO,oBAAoBP,OAAO,eAAe;AACvD,OAAO,MAAMQ,4BAA4BR,OAAO,sBAAsB;AAEtE,SAASS,gBACPR,QAA6C;IAE7C,IAAI,CAACA,UAAU;QACb,MAAM,IAAIS,MACR;IAEJ;IACA,OAAOT;AACT;AAEA,OAAO,SAASU,cACdV,QAA6C,EAC7CW,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I,EAAE;IAC3D;IACA,OAAOf;AACT;AAEA;;;;;;;CAOC,GACD,OAAO,SAASiC,qBAAqBzB,MAAwB;;IAC3D,MAAMnB,WAAW0C,aAAavB;IAC9B,eAAQnB,4BAAAA,QAAU,CAACI,kBAAkB,mBAAmC,EAAE;AAC5E;AAEA,OAAO,SAASyC,mBACd1B,MAAkC;;IAElC,MAAMnB,WAAW0C,aAAavB;IAC9B,eAAQnB,4BAAAA,QAAU,CAACK,gBAAgB,mBAAiC,EAAE;AACxE;AAEA,4EAA4E,GAC5E,OAAO,SAASyC,oBACd3B,MAAkC;;IAElC,MAAMnB,WAAW0C,aAAavB;IAC9B,eAAQnB,4BAAAA,QAAU,CAACM,kBAAkB,mBAAkC,EAAE;AAC3E;AAEA,yDAAyD,GACzD,OAAO,SAASyC,0BACd5B,MAA0B;IAE1B,MAAMnB,WAAW,AACfmB,MACD,CAACpB,OAAOC,QAAQ,CAAC;IAClB,MAAMyC,UAAUzC,4BAAAA,QAAU,CAACO,0BAA0B;IAErD,IAAI,CAACkC,SAAS;QACZ,MAAM,IAAIhC,MACR,CAAC,0BAA0B,EAAEU,OAAOO,IAAI,CAAC,4BAA4B,CAAC;IAE1E;IACA,OAAOe;AACT;AAEA;;;CAGC,GACD,OAAO,SAASO,eAAe7B,MAA0B;IACvD,MAAM,EAAE8B,MAAM,EAAExB,GAAG,EAAEgB,OAAO,EAAE,GAAGM,0BAA0B5B;IAC3D,yEAAyE;IACzE,4EAA4E;IAC5E,4DAA4D;IAC5D,OAAO2B,oBAAoBG,QAAQZ,IAAI,CACrCjB,CAAAA,cAAeA,YAAYK,GAAG,KAAKA,OAAOL,YAAYqB,OAAO,KAAKA;AAEtE"}
|
|
@@ -152,7 +152,31 @@ export interface MetaAccessorOptions {
|
|
|
152
152
|
* form edits the major amount and writes back the stored one.
|
|
153
153
|
*/
|
|
154
154
|
money?: MoneyFormat;
|
|
155
|
+
/**
|
|
156
|
+
* The narrowest this member's column reads at, in `rem`. A table whose
|
|
157
|
+
* visible columns no longer fit side by side becomes a list of cards, so the
|
|
158
|
+
* sum of these is where it switches. Undeclared, the member's type decides.
|
|
159
|
+
* Presentation only.
|
|
160
|
+
*/
|
|
161
|
+
minWidth?: number;
|
|
162
|
+
/**
|
|
163
|
+
* The part this member plays on a record's card: its `title` — the heading
|
|
164
|
+
* that links to the record — a `subtitle` under it, a `badge`, a line of
|
|
165
|
+
* `meta`, or `hidden` from the card. Undeclared, the record's first
|
|
166
|
+
* filled-in member is the title, an id is hidden, the first enum is the
|
|
167
|
+
* badge and up to three more members are meta. Presentation only.
|
|
168
|
+
*/
|
|
169
|
+
card?: CardRole;
|
|
170
|
+
/**
|
|
171
|
+
* What the member holds about the person filling it in, as an HTML autofill
|
|
172
|
+
* token — `email`, `given-name`, `tel`, `street-address` — so a browser can
|
|
173
|
+
* fill it and assistive tech can say what it is for (WCAG 1.3.5).
|
|
174
|
+
* Presentation only.
|
|
175
|
+
*/
|
|
176
|
+
autocomplete?: string;
|
|
155
177
|
}
|
|
178
|
+
/** The part a member plays on a record's card. */
|
|
179
|
+
export type CardRole = 'title' | 'subtitle' | 'badge' | 'meta' | 'hidden';
|
|
156
180
|
/**
|
|
157
181
|
* How a `number` member reads as money: `currency` fixed, or
|
|
158
182
|
* `currencyMember` naming the record's own ISO 4217 code member; `unit`
|
|
@@ -192,6 +216,9 @@ export declare class MetaAccessor {
|
|
|
192
216
|
readonly notBefore?: string;
|
|
193
217
|
readonly parent?: boolean;
|
|
194
218
|
readonly money?: MoneyFormat;
|
|
219
|
+
readonly minWidth?: number;
|
|
220
|
+
readonly card?: CardRole;
|
|
221
|
+
readonly autocomplete?: string;
|
|
195
222
|
constructor(name: string | symbol, kind: MetaAccessorKind, options?: MetaAccessorOptions);
|
|
196
223
|
}
|
|
197
224
|
//# sourceMappingURL=meta-accessor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-accessor.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta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MAAM,CAAC;IAC5B;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IAC5C;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,EAAE,MAAM,gBAAgB,CAAC;IACnC;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;;;;;;OAUG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;;;;;OAOG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;
|
|
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;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,0IAYpB,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAElE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,IAAI,KAI7D,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,MAAM,CAAC;AAEZ;;;;GAIG;AACH,eAAO,MAAM,wBAAwB,6BAA8B,CAAC;AACpE,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEhF,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,CA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E,MAAM,CAAC;IACrC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,uBAAuB,CAAC;IACrD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,gBAAgB,CAAC;IAC5C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,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,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;CAqChC"}
|
|
@@ -55,6 +55,9 @@ export class MetaAccessor {
|
|
|
55
55
|
this.notBefore = options == null ? void 0 : options.notBefore;
|
|
56
56
|
this.parent = options == null ? void 0 : options.parent;
|
|
57
57
|
this.money = options == null ? void 0 : options.money;
|
|
58
|
+
this.minWidth = options == null ? void 0 : options.minWidth;
|
|
59
|
+
this.card = options == null ? void 0 : options.card;
|
|
60
|
+
this.autocomplete = options == null ? void 0 : options.autocomplete;
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
63
|
|
|
@@ -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 /** 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 `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\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 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 money?: MoneyFormat;\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.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.money = options?.money;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaAccessorTypes","EntityLinkSerializations","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","money"],"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,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jC,IAAI,CAACC,SAAS,GAAGpB,2BAAAA,QAASoB,SAAS;QACnC,IAAI,CAACC,MAAM,GAAGrB,2BAAAA,QAASqB,MAAM;QAC7B,IAAI,CAACC,KAAK,GAAGtB,2BAAAA,QAASsB,KAAK;IAC7B;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 * `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 /** 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 `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/** 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 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 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.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.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","MetaAccessor","name","kind","options","alias","type","readonly","hidden","required","label","labelKey","sortable","filterable","order","enumValues","enumLabelKey","linkLabelProperty","linkSearchProperty","linkSerialization","childType","resetOnClone","minItems","maxItems","notBefore","parent","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;AA8JpE,OAAO,MAAMC;IA+BX,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,GAAG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I,CAACC,IAAI,GAAGxB,2BAAAA,QAASwB,IAAI;QACzB,IAAI,CAACC,YAAY,GAAGzB,2BAAAA,QAASyB,YAAY;IAC3C;AAQF"}
|
|
@@ -47,6 +47,13 @@ export interface MetaEntityOptions {
|
|
|
47
47
|
cardinality?: EntityCardinality;
|
|
48
48
|
/** Named shapes the entity is published in, by view name. */
|
|
49
49
|
views?: Readonly<Record<string, EntityViewOptions>>;
|
|
50
|
+
/**
|
|
51
|
+
* `false` for an entity no person creates — one only ever written by a flow,
|
|
52
|
+
* such as an order a checkout opens. A list of it offers no "New", whatever
|
|
53
|
+
* the caller holds; absent, it offers one to a caller who may write it
|
|
54
|
+
* ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
55
|
+
*/
|
|
56
|
+
creatable?: boolean;
|
|
50
57
|
}
|
|
51
58
|
export declare class MetaEntity {
|
|
52
59
|
readonly name: string;
|
|
@@ -56,6 +63,7 @@ export declare class MetaEntity {
|
|
|
56
63
|
readonly pluralKey?: string;
|
|
57
64
|
readonly cardinality?: EntityCardinality;
|
|
58
65
|
readonly views?: Readonly<Record<string, EntityViewOptions>>;
|
|
66
|
+
readonly creatable: boolean;
|
|
59
67
|
constructor(name: string, options?: MetaEntityOptions);
|
|
60
68
|
}
|
|
61
69
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-entity.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE;;;;;GAKG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,kEAAkE;IAClE,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,eAAe,CAAC,SAAS,CAAC,EAAE,CAAC;IAC3D,wCAAwC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,aAAa,CAAC,SAAS,CAAC,EAAE,CAAC;IACvD,sDAAsD;IACtD,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iGAAiG;IACjG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kFAAkF;IAClF,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4CAA4C;IAC5C,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAChC,6DAA6D;IAC7D,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"meta-entity.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAGrE;;;;;GAKG;AACH,KAAK,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAElD;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC,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,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAIhB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAkBtD"}
|
|
@@ -3,6 +3,7 @@ export class MetaEntity {
|
|
|
3
3
|
//#endregion
|
|
4
4
|
//#region Constructors
|
|
5
5
|
constructor(name, options){
|
|
6
|
+
var _ref;
|
|
6
7
|
this.name = name;
|
|
7
8
|
this.key = options == null ? void 0 : options.key;
|
|
8
9
|
this.domain = options == null ? void 0 : options.domain;
|
|
@@ -11,6 +12,7 @@ export class MetaEntity {
|
|
|
11
12
|
assertBounds(`${name}'s cardinality`, options == null ? void 0 : options.cardinality);
|
|
12
13
|
this.cardinality = options == null ? void 0 : options.cardinality;
|
|
13
14
|
this.views = options == null ? void 0 : options.views;
|
|
15
|
+
this.creatable = (_ref = options == null ? void 0 : options.creatable) != null ? _ref : true;
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport type { EntityFiltering } from '../../../types/EntityFiltering.js';\nimport type { EntitySorting } from '../../../types/EntitySorting.js';\nimport { assertBounds } from '../bounds.js';\n\n/**\n * An entity a view's filtering names members of. `@entity()` is applied before\n * TypeScript knows which class it decorates, so a view's members cannot be\n * checked against it there; `extractEntityView` checks them when the view is\n * first read instead.\n */\ntype AnyEntity = Entity & Record<string, unknown>;\n\n/**\n * A narrower shape an entity is published in: some records left out, some\n * members omitted — posts without their bodies, drafts left out.\n *\n * Read by `serializeEntityCollection(entity, records, { view })` and by any\n * adapter that publishes records, so the shape is declared once on the entity\n * rather than per consumer. A member a view omits is optional **in that view\n * only**: `validateRecords(…, { view })` does not require it, and `required`\n * keeps its meaning for the full record.\n */\nexport interface EntityViewOptions {\n /** The records the view keeps, as a load request filters them. */\n readonly filtering?: readonly EntityFiltering<AnyEntity>[];\n /** The order the view lists them in. */\n readonly sorting?: readonly EntitySorting<AnyEntity>[];\n /** Members, by accessor name, the view leaves out. */\n readonly omit?: readonly string[];\n}\n\n/**\n * How many records an entity may have: `{ min: 1, max: 1 }` for a site's one\n * profile, `{ min: 1 }` for \"at least one\". Checked by `validateRecords` over a\n * whole set of records — a static build's content, an import — and never by a\n * single save, which cannot see the others.\n */\nexport interface EntityCardinality {\n readonly min?: number;\n readonly max?: number;\n}\n\nexport interface MetaEntityOptions {\n key?: string;\n domain?: string;\n /** Translation key for the entity's singular name, e.g. `entity:product-specification.label`. */\n labelKey?: string;\n /** Translation key for its plural, e.g. `entity:product-specification.plural`. */\n pluralKey?: string;\n /** How many records the entity may have. */\n cardinality?: EntityCardinality;\n /** Named shapes the entity is published in, by view name. */\n views?: Readonly<Record<string, EntityViewOptions>>;\n}\n\nexport class MetaEntity {\n //#region Properties\n readonly name: string;\n readonly key?: string;\n readonly domain?: string;\n readonly labelKey?: string;\n readonly pluralKey?: string;\n readonly cardinality?: EntityCardinality;\n readonly views?: Readonly<Record<string, EntityViewOptions>>;\n //#endregion\n\n //#region Constructors\n constructor(name: string, options?: MetaEntityOptions) {\n this.name = name;\n this.key = options?.key;\n this.domain = options?.domain;\n this.labelKey = options?.labelKey;\n this.pluralKey = options?.pluralKey;\n assertBounds(`${name}'s cardinality`, options?.cardinality);\n this.cardinality = options?.cardinality;\n this.views = options?.views;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["assertBounds","MetaEntity","name","options","key","domain","labelKey","pluralKey","cardinality","views"],"mappings":"AAGA,SAASA,YAAY,QAAQ,eAAe;
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-entity/meta-entity.ts"],"sourcesContent":["import type { Entity } from '../../../types/Entity.js';\nimport type { EntityFiltering } from '../../../types/EntityFiltering.js';\nimport type { EntitySorting } from '../../../types/EntitySorting.js';\nimport { assertBounds } from '../bounds.js';\n\n/**\n * An entity a view's filtering names members of. `@entity()` is applied before\n * TypeScript knows which class it decorates, so a view's members cannot be\n * checked against it there; `extractEntityView` checks them when the view is\n * first read instead.\n */\ntype AnyEntity = Entity & Record<string, unknown>;\n\n/**\n * A narrower shape an entity is published in: some records left out, some\n * members omitted — posts without their bodies, drafts left out.\n *\n * Read by `serializeEntityCollection(entity, records, { view })` and by any\n * adapter that publishes records, so the shape is declared once on the entity\n * rather than per consumer. A member a view omits is optional **in that view\n * only**: `validateRecords(…, { view })` does not require it, and `required`\n * keeps its meaning for the full record.\n */\nexport interface EntityViewOptions {\n /** The records the view keeps, as a load request filters them. */\n readonly filtering?: readonly EntityFiltering<AnyEntity>[];\n /** The order the view lists them in. */\n readonly sorting?: readonly EntitySorting<AnyEntity>[];\n /** Members, by accessor name, the view leaves out. */\n readonly omit?: readonly string[];\n}\n\n/**\n * How many records an entity may have: `{ min: 1, max: 1 }` for a site's one\n * profile, `{ min: 1 }` for \"at least one\". Checked by `validateRecords` over a\n * whole set of records — a static build's content, an import — and never by a\n * single save, which cannot see the others.\n */\nexport interface EntityCardinality {\n readonly min?: number;\n readonly max?: number;\n}\n\nexport interface MetaEntityOptions {\n key?: string;\n domain?: string;\n /** Translation key for the entity's singular name, e.g. `entity:product-specification.label`. */\n labelKey?: string;\n /** Translation key for its plural, e.g. `entity:product-specification.plural`. */\n pluralKey?: string;\n /** How many records the entity may have. */\n cardinality?: EntityCardinality;\n /** Named shapes the entity is published in, by view name. */\n views?: Readonly<Record<string, EntityViewOptions>>;\n /**\n * `false` for an entity no person creates — one only ever written by a flow,\n * such as an order a checkout opens. A list of it offers no \"New\", whatever\n * the caller holds; absent, it offers one to a caller who may write it\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\n creatable?: boolean;\n}\n\nexport class MetaEntity {\n //#region Properties\n readonly name: string;\n readonly key?: string;\n readonly domain?: string;\n readonly labelKey?: string;\n readonly pluralKey?: string;\n readonly cardinality?: EntityCardinality;\n readonly views?: Readonly<Record<string, EntityViewOptions>>;\n readonly creatable: boolean;\n //#endregion\n\n //#region Constructors\n constructor(name: string, options?: MetaEntityOptions) {\n this.name = name;\n this.key = options?.key;\n this.domain = options?.domain;\n this.labelKey = options?.labelKey;\n this.pluralKey = options?.pluralKey;\n assertBounds(`${name}'s cardinality`, options?.cardinality);\n this.cardinality = options?.cardinality;\n this.views = options?.views;\n this.creatable = options?.creatable ?? true;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["assertBounds","MetaEntity","name","options","key","domain","labelKey","pluralKey","cardinality","views","creatable"],"mappings":"AAGA,SAASA,YAAY,QAAQ,eAAe;AA4D5C,OAAO,MAAMC;IAUX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,IAAY,EAAEC,OAA2B,CAAE;;QACrD,IAAI,CAACD,IAAI,GAAGA;QACZ,IAAI,CAACE,GAAG,GAAGD,2BAAAA,QAASC,GAAG;QACvB,IAAI,CAACC,MAAM,GAAGF,2BAAAA,QAASE,MAAM;QAC7B,IAAI,CAACC,QAAQ,GAAGH,2BAAAA,QAASG,QAAQ;QACjC,IAAI,CAACC,SAAS,GAAGJ,2BAAAA,QAASI,SAAS;QACnCP,aAAa,GAAGE,KAAK,cAAc,CAAC,EAAEC,2BAAAA,QAASK,WAAW;QAC1D,IAAI,CAACA,WAAW,GAAGL,2BAAAA,QAASK,WAAW;QACvC,IAAI,CAACC,KAAK,GAAGN,2BAAAA,QAASM,KAAK;QAC3B,IAAI,CAACC,SAAS,WAAGP,2BAAAA,QAASO,SAAS,mBAAI;IACzC;AAQF"}
|
|
@@ -28,6 +28,59 @@ export interface UseCaseConfirm {
|
|
|
28
28
|
tone: 'destructive' | 'neutral';
|
|
29
29
|
/** Catalog key. Copy never lives in a descriptor. */
|
|
30
30
|
messageKey: string;
|
|
31
|
+
/**
|
|
32
|
+
* Catalog key for the confirming button. Absent, the button repeats the
|
|
33
|
+
* verb's own label: a dialog that says "Confirm" makes the reader go back to
|
|
34
|
+
* the title to learn what they are agreeing to.
|
|
35
|
+
*/
|
|
36
|
+
confirmLabelKey?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Catalog key for what an `undo` verb's toast says once it has run, in the
|
|
39
|
+
* past tense — "Invoice voided." Absent, a generic sentence names the verb.
|
|
40
|
+
*/
|
|
41
|
+
doneKey?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* How a destructive verb is made safe
|
|
45
|
+
* ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):
|
|
46
|
+
* - `undo` acts at once and offers Undo, which runs the verb's `inverse`;
|
|
47
|
+
* - `confirm` asks first, in a dialog that names what will be destroyed;
|
|
48
|
+
* - `typed` asks the reader to type the record's name, or the count, first.
|
|
49
|
+
*
|
|
50
|
+
* Required on every `confirm.tone: 'destructive'` verb, and refused at
|
|
51
|
+
* declaration without it: a destructive verb whose safety is left to whichever
|
|
52
|
+
* surface renders it is one click on one of them.
|
|
53
|
+
*/
|
|
54
|
+
export type UseCaseReversible = 'undo' | 'confirm' | 'typed';
|
|
55
|
+
/**
|
|
56
|
+
* How much weight a surface gives a verb. One `primary` per surface — the
|
|
57
|
+
* thing the surface is for — and every other verb `default`; a second primary
|
|
58
|
+
* on one surface throws when it renders
|
|
59
|
+
* ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).
|
|
60
|
+
*/
|
|
61
|
+
export type UseCaseEmphasis = 'primary' | 'default';
|
|
62
|
+
/**
|
|
63
|
+
* The hierarchy a surface renders a verb in: its weight, its order among the
|
|
64
|
+
* secondaries, whether a row shows it inline, and the chord that reaches it.
|
|
65
|
+
*/
|
|
66
|
+
export interface UseCaseHierarchy {
|
|
67
|
+
emphasis?: UseCaseEmphasis;
|
|
68
|
+
/**
|
|
69
|
+
* Order among the surface's secondaries, lowest first; equal or absent keeps
|
|
70
|
+
* declaration order. The first three stay visible and the rest fold into
|
|
71
|
+
* "More actions".
|
|
72
|
+
*/
|
|
73
|
+
priority?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Shown on the row itself rather than only in its menu — at most one verb
|
|
76
|
+
* per entity, since a row with two inline buttons is a toolbar per row.
|
|
77
|
+
*/
|
|
78
|
+
rowInline?: true;
|
|
79
|
+
/**
|
|
80
|
+
* A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.
|
|
81
|
+
* Rendered as `aria-keyshortcuts` and listed in the command palette.
|
|
82
|
+
*/
|
|
83
|
+
shortcut?: string;
|
|
31
84
|
}
|
|
32
85
|
/**
|
|
33
86
|
* What `@useCase()` declares.
|
|
@@ -43,7 +96,7 @@ export interface UseCaseConfirm {
|
|
|
43
96
|
* matches across locales — a user typing an English term reaches a Spanish
|
|
44
97
|
* command.
|
|
45
98
|
*/
|
|
46
|
-
export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity> {
|
|
99
|
+
export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity> extends UseCaseHierarchy {
|
|
47
100
|
entity: EntityConstructor<TEntity>;
|
|
48
101
|
key: TKey;
|
|
49
102
|
binding: UseCaseBinding;
|
|
@@ -68,6 +121,10 @@ export interface MetaUseCaseOptions<TKey extends string, TEntity extends Entity>
|
|
|
68
121
|
labelKey: string;
|
|
69
122
|
keywordsKey?: string;
|
|
70
123
|
confirm?: UseCaseConfirm;
|
|
124
|
+
/** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */
|
|
125
|
+
reversible?: UseCaseReversible;
|
|
126
|
+
/** The verb Undo runs, by key. Required with `reversible: 'undo'`. */
|
|
127
|
+
inverse?: string;
|
|
71
128
|
/** Names a form a surface should open instead of acting immediately. */
|
|
72
129
|
form?: string;
|
|
73
130
|
/**
|
|
@@ -112,6 +169,12 @@ export declare class MetaUseCase {
|
|
|
112
169
|
readonly labelKey: string;
|
|
113
170
|
readonly keywordsKey?: string;
|
|
114
171
|
readonly confirm?: UseCaseConfirm;
|
|
172
|
+
readonly reversible?: UseCaseReversible;
|
|
173
|
+
readonly inverse?: string;
|
|
174
|
+
readonly emphasis?: UseCaseEmphasis;
|
|
175
|
+
readonly priority?: number;
|
|
176
|
+
readonly rowInline?: true;
|
|
177
|
+
readonly shortcut?: string;
|
|
115
178
|
readonly form?: string;
|
|
116
179
|
readonly variants?: string;
|
|
117
180
|
readonly recipe?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"meta-use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE1E,oEAAoE;AACpE,MAAM,MAAM,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,CAAC;AAEjE;;;;;;GAMG;AACH,MAAM,MAAM,gBAAgB,GAC1B,mBAAmB,GAAG,qBAAqB,GAAG,aAAa,CAAC;AAE9D;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,gBAAgB,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,GAAG,SAAS,CAAC;IAChC,qDAAqD;IACrD,UAAU,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"meta-use-case.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAErC,OAAO,KAAK,EAAE,YAAY,EA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AAc,CAAC;IAClC,QAAQ,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,eAAe,CAAC;IACpC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC;IAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;IAC9B,QAAQ,CAAC,MAAM,CAAC,EAAE,SAAS,YAAY,EAAE,CAAC;gBAI9B,OAAO,EAAE,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC;CA6BxD"}
|
|
@@ -10,6 +10,12 @@ export class MetaUseCase {
|
|
|
10
10
|
this.labelKey = options.labelKey;
|
|
11
11
|
this.keywordsKey = options.keywordsKey;
|
|
12
12
|
this.confirm = options.confirm;
|
|
13
|
+
this.reversible = options.reversible;
|
|
14
|
+
this.inverse = options.inverse;
|
|
15
|
+
this.emphasis = options.emphasis;
|
|
16
|
+
this.priority = options.priority;
|
|
17
|
+
this.rowInline = options.rowInline;
|
|
18
|
+
this.shortcut = options.shortcut;
|
|
13
19
|
this.form = options.form;
|
|
14
20
|
this.variants = options.variants;
|
|
15
21
|
this.recipe = options.recipe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","form","variants","recipe","payload","success","errors"],"mappings":"AAqHA,OAAO,MAAMA;IAgBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,IAAI,GAAGT,QAAQS,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGV,QAAQU,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGX,QAAQW,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGZ,QAAQY,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGb,QAAQa,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGd,QAAQc,MAAM;IAC9B;AAQF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/meta-entities/meta-use-case/meta-use-case.ts"],"sourcesContent":["import type { Schema } from 'effect';\n\nimport type { FailureClass } from '../../../failure/failure.js';\nimport type { Entity, EntityConstructor } from '../../../types/Entity.js';\n\n/** What a use case acts on: one record, a selection, or nothing. */\nexport type UseCaseBinding = 'entity' | 'collection' | 'unbound';\n\n/**\n * Where a surface puts the action. Deliberately **not** derivable from\n * {@link UseCaseBinding}: an entity-bound action can be determining (a footer\n * \"Publish\" that finalizes the page) or context-independent (a toolbar action\n * available whenever a record is open). Collapsing the two would force every\n * surface to re-derive a placement the author already knew.\n */\nexport type UseCasePlacement =\n 'context-dependent' | 'context-independent' | 'determining';\n\n/**\n * One place a verb can appear: a binding and a placement together.\n *\n * The pair is the unit rather than either half, because the two answer\n * different questions — placement decides the *surface* and binding decides the\n * *payload* — and a verb reachable from a row and from a selection differs in\n * both at once.\n */\nexport interface UseCaseCell {\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n}\n\n/** Confirmation a surface must obtain before running the use case. */\nexport interface UseCaseConfirm {\n tone: 'destructive' | 'neutral';\n /** Catalog key. Copy never lives in a descriptor. */\n messageKey: string;\n /**\n * Catalog key for the confirming button. Absent, the button repeats the\n * verb's own label: a dialog that says \"Confirm\" makes the reader go back to\n * the title to learn what they are agreeing to.\n */\n confirmLabelKey?: string;\n /**\n * Catalog key for what an `undo` verb's toast says once it has run, in the\n * past tense — \"Invoice voided.\" Absent, a generic sentence names the verb.\n */\n doneKey?: string;\n}\n\n/**\n * How a destructive verb is made safe\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)):\n * - `undo` acts at once and offers Undo, which runs the verb's `inverse`;\n * - `confirm` asks first, in a dialog that names what will be destroyed;\n * - `typed` asks the reader to type the record's name, or the count, first.\n *\n * Required on every `confirm.tone: 'destructive'` verb, and refused at\n * declaration without it: a destructive verb whose safety is left to whichever\n * surface renders it is one click on one of them.\n */\nexport type UseCaseReversible = 'undo' | 'confirm' | 'typed';\n\n/**\n * How much weight a surface gives a verb. One `primary` per surface — the\n * thing the surface is for — and every other verb `default`; a second primary\n * on one surface throws when it renders\n * ([ADR 0026](../../../../../../../docs/adr/0026-actions-hierarchy-overflow-and-destructive-verbs.md)).\n */\nexport type UseCaseEmphasis = 'primary' | 'default';\n\n/**\n * The hierarchy a surface renders a verb in: its weight, its order among the\n * secondaries, whether a row shows it inline, and the chord that reaches it.\n */\nexport interface UseCaseHierarchy {\n emphasis?: UseCaseEmphasis;\n /**\n * Order among the surface's secondaries, lowest first; equal or absent keeps\n * declaration order. The first three stay visible and the rest fold into\n * \"More actions\".\n */\n priority?: number;\n /**\n * Shown on the row itself rather than only in its menu — at most one verb\n * per entity, since a row with two inline buttons is a toolbar per row.\n */\n rowInline?: true;\n /**\n * A modifier chord, `Mod+Shift+P`: `Mod` is ⌘ on macOS and Ctrl elsewhere.\n * Rendered as `aria-keyshortcuts` and listed in the command palette.\n */\n shortcut?: string;\n}\n\n/**\n * What `@useCase()` declares.\n *\n * `entity` is the target the verb is registered against — it is what the\n * decorator appends to, and it is not part of the served descriptor.\n *\n * `labelKey` is mandatory and namespace-qualified, the `GuardedNavItem`\n * convention: i18n is mandatory and `react/jsx-no-literals` fails the build on a\n * string written into JSX, so a descriptor carrying copy could not be rendered.\n *\n * `keywordsKey` is a catalog key rather than a `string[]` so the command palette\n * matches across locales — a user typing an English term reaches a Spanish\n * command.\n */\nexport interface MetaUseCaseOptions<\n TKey extends string,\n TEntity extends Entity,\n> extends UseCaseHierarchy {\n entity: EntityConstructor<TEntity>;\n key: TKey;\n binding: UseCaseBinding;\n placement: UseCasePlacement;\n /**\n * Further places the same verb appears, beyond the {@link binding} and\n * {@link placement} above.\n *\n * ⚠️ **One verb, one permission, several surfaces.** Publishing an offering\n * from its form, from a row menu and over a selection is one act reached three\n * ways, and the alternative was three `@useCase()` classes — which `slices`\n * refuses anyway, since a verb key is the third segment of one permission and\n * two classes cannot share a key. Three classes would have meant three\n * permissions for one act, and a grant that let somebody publish one offering\n * but not twenty.\n *\n * The primary cell stays where it is so that nothing already declared\n * changes, and so a descriptor still reads as \"this verb lives here\" with the\n * rest as additions.\n */\n alsoAt?: readonly UseCaseCell[];\n labelKey: string;\n keywordsKey?: string;\n confirm?: UseCaseConfirm;\n /** How a destructive verb is made safe. Required when `confirm.tone` is `destructive`. */\n reversible?: UseCaseReversible;\n /** The verb Undo runs, by key. Required with `reversible: 'undo'`. */\n inverse?: string;\n /** Names a form a surface should open instead of acting immediately. */\n form?: string;\n /**\n * The use case whose variants this verb resolves between, by name: the\n * service holds the rules, and `$metadata` reports which one this caller\n * resolves to.\n */\n variants?: string;\n /** The recipe this verb starts a flow from, by name — the flow-backed verbs. */\n recipe?: string;\n /**\n * What the verb's endpoint takes, answers and refuses with — the contract\n * the shell derives the endpoint from. Absent `payload` means the verb takes\n * no body; absent `success` means its answer is not described. None of the\n * three reaches a served `$metadata` document.\n */\n payload?: Schema.Top;\n success?: Schema.Top;\n errors?: readonly FailureClass[];\n}\n\n/**\n * What the use-case class's **own** metadata carries, as opposed to what is\n * appended to the entity. Two fields are enough to derive the permission, which\n * is what lets `permissionForUseCase(SomeUC)` take a single argument and keeps\n * the verb string written exactly once.\n */\nexport interface MetaUseCaseBinding {\n entity: EntityConstructor<Entity>;\n key: string;\n /**\n * Which of the entity's verbs under `key` the class is: one key may be\n * declared on a record and over a selection, and each class is one of them.\n */\n binding: UseCaseBinding;\n}\n\nexport class MetaUseCase {\n //#region Properties\n readonly entity: EntityConstructor<Entity>;\n readonly key: string;\n readonly binding: UseCaseBinding;\n readonly placement: UseCasePlacement;\n readonly alsoAt?: readonly UseCaseCell[];\n readonly labelKey: string;\n readonly keywordsKey?: string;\n readonly confirm?: UseCaseConfirm;\n readonly reversible?: UseCaseReversible;\n readonly inverse?: string;\n readonly emphasis?: UseCaseEmphasis;\n readonly priority?: number;\n readonly rowInline?: true;\n readonly shortcut?: string;\n readonly form?: string;\n readonly variants?: string;\n readonly recipe?: string;\n readonly payload?: Schema.Top;\n readonly success?: Schema.Top;\n readonly errors?: readonly FailureClass[];\n //#endregion\n\n //#region Constructors\n constructor(options: MetaUseCaseOptions<string, Entity>) {\n this.entity = options.entity;\n this.key = options.key;\n this.binding = options.binding;\n this.placement = options.placement;\n this.alsoAt = options.alsoAt;\n this.labelKey = options.labelKey;\n this.keywordsKey = options.keywordsKey;\n this.confirm = options.confirm;\n this.reversible = options.reversible;\n this.inverse = options.inverse;\n this.emphasis = options.emphasis;\n this.priority = options.priority;\n this.rowInline = options.rowInline;\n this.shortcut = options.shortcut;\n this.form = options.form;\n this.variants = options.variants;\n this.recipe = options.recipe;\n this.payload = options.payload;\n this.success = options.success;\n this.errors = options.errors;\n }\n //#endregion\n\n //#region Methods\n //#endregion\n\n //#region Accessors\n //#endregion\n}\n"],"names":["MetaUseCase","options","entity","key","binding","placement","alsoAt","labelKey","keywordsKey","confirm","reversible","inverse","emphasis","priority","rowInline","shortcut","form","variants","recipe","payload","success","errors"],"mappings":"AAiLA,OAAO,MAAMA;IAsBX,YAAY;IAEZ,sBAAsB;IACtB,YAAYC,OAA2C,CAAE;QACvD,IAAI,CAACC,MAAM,GAAGD,QAAQC,MAAM;QAC5B,IAAI,CAACC,GAAG,GAAGF,QAAQE,GAAG;QACtB,IAAI,CAACC,OAAO,GAAGH,QAAQG,OAAO;QAC9B,IAAI,CAACC,SAAS,GAAGJ,QAAQI,SAAS;QAClC,IAAI,CAACC,MAAM,GAAGL,QAAQK,MAAM;QAC5B,IAAI,CAACC,QAAQ,GAAGN,QAAQM,QAAQ;QAChC,IAAI,CAACC,WAAW,GAAGP,QAAQO,WAAW;QACtC,IAAI,CAACC,OAAO,GAAGR,QAAQQ,OAAO;QAC9B,IAAI,CAACC,UAAU,GAAGT,QAAQS,UAAU;QACpC,IAAI,CAACC,OAAO,GAAGV,QAAQU,OAAO;QAC9B,IAAI,CAACC,QAAQ,GAAGX,QAAQW,QAAQ;QAChC,IAAI,CAACC,QAAQ,GAAGZ,QAAQY,QAAQ;QAChC,IAAI,CAACC,SAAS,GAAGb,QAAQa,SAAS;QAClC,IAAI,CAACC,QAAQ,GAAGd,QAAQc,QAAQ;QAChC,IAAI,CAACC,IAAI,GAAGf,QAAQe,IAAI;QACxB,IAAI,CAACC,QAAQ,GAAGhB,QAAQgB,QAAQ;QAChC,IAAI,CAACC,MAAM,GAAGjB,QAAQiB,MAAM;QAC5B,IAAI,CAACC,OAAO,GAAGlB,QAAQkB,OAAO;QAC9B,IAAI,CAACC,OAAO,GAAGnB,QAAQmB,OAAO;QAC9B,IAAI,CAACC,MAAM,GAAGpB,QAAQoB,MAAM;IAC9B;AAQF"}
|
|
@@ -49,6 +49,20 @@ declare const Forbidden_base: Schema.Class<Forbidden, Schema.TaggedStruct<"Forbi
|
|
|
49
49
|
/** A verified caller without the grant. */
|
|
50
50
|
export declare class Forbidden extends Forbidden_base {
|
|
51
51
|
}
|
|
52
|
+
declare const NoActiveOrganization_base: Schema.Class<NoActiveOrganization, Schema.TaggedStruct<"NoActiveOrganization", Record<never, never>>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"noActiveOrganization", "conflict">>;
|
|
53
|
+
/**
|
|
54
|
+
* A signed-in caller whose session names no organization, on a route that acts
|
|
55
|
+
* for one. A member of several organizations hits it before choosing one; the
|
|
56
|
+
* code is what a client renders as "select an organization" instead of
|
|
57
|
+
* "forbidden".
|
|
58
|
+
*
|
|
59
|
+
* Declared here rather than beside the guard that raises it, so every bundle
|
|
60
|
+
* that decodes a problem knows the code: a browser loads no service shell, and
|
|
61
|
+
* an unregistered code decodes as a protocol failure, losing the next step a
|
|
62
|
+
* host registers for it.
|
|
63
|
+
*/
|
|
64
|
+
export declare class NoActiveOrganization extends NoActiveOrganization_base {
|
|
65
|
+
}
|
|
52
66
|
declare const NotFound_base: Schema.Class<NotFound, Schema.TaggedStruct<"NotFound", {
|
|
53
67
|
readonly entity: Schema.optionalKey<Schema.String>;
|
|
54
68
|
}>, import("effect/Cause").YieldableError & import("./failure.js").FailureFacts<"notFound", "notFound">>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generic.d.ts","sourceRoot":"","sources":["../../src/failure/generic.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ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BAAa,QAAS,SAAQ,aAK7B;CAAG;;AAEJ,+EAA+E;AAC/E,qBAAa,UAAW,SAAQ,eAG/B;CAAG;;;;AAEJ,6EAA6E;AAC7E,qBAAa,UAAW,SAAQ,eAI/B;CAAG;;;;AAEJ,yCAAyC;AACzC,qBAAa,WAAY,SAAQ,gBAIhC;CAAG;;;;AAEJ,4DAA4D;AAC5D,qBAAa,mBAAoB,SAAQ,wBAIvC;CAAG;;;;AAEL,2CAA2C;AAC3C,qBAAa,OAAQ,SAAQ,YAI5B;CAAG;;;;;AAEJ;;;;GAIG;AACH,qBAAa,eAAgB,SAAQ,oBAUpC;CAAG;;AAEJ,4EAA4E;AAC5E,qBAAa,QAAS,SAAQ,aAG7B;CAAG;;AAEJ,oEAAoE;AACpE,qBAAa,qBAAsB,SAAQ,0BAEiC;CAAG;;AAE/E,iEAAiE;AACjE,qBAAa,oBAAqB,SAAQ,yBAE+B;CAAG;;AAE5E,uEAAuE;AACvE,qBAAa,sBAAuB,SAAQ,2BAK3C;CAAG;AAEJ;;;;;GAKG;AACH,MAAM,MAAM,YAAY,GACtB,YAAY,GAAG,UAAU,GAAG,WAAW,GAAG,OAAO,GAAG,eAAe,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;AAS7D,4DAA4D;AAC5D,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAGsB,CAAC"}
|
package/dist/failure/generic.js
CHANGED
|
@@ -39,6 +39,18 @@ import { defineFailure } from './define.js';
|
|
|
39
39
|
permission: Schema.optionalKey(Schema.String)
|
|
40
40
|
}) {
|
|
41
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* A signed-in caller whose session names no organization, on a route that acts
|
|
44
|
+
* for one. A member of several organizations hits it before choosing one; the
|
|
45
|
+
* code is what a client renders as "select an organization" instead of
|
|
46
|
+
* "forbidden".
|
|
47
|
+
*
|
|
48
|
+
* Declared here rather than beside the guard that raises it, so every bundle
|
|
49
|
+
* that decodes a problem knows the code: a browser loads no service shell, and
|
|
50
|
+
* an unregistered code decodes as a protocol failure, losing the next step a
|
|
51
|
+
* host registers for it.
|
|
52
|
+
*/ export class NoActiveOrganization extends defineFailure('conflict')()('NoActiveOrganization', 'noActiveOrganization') {
|
|
53
|
+
}
|
|
42
54
|
/** The addressed record does not exist. */ export class NotFound extends defineFailure('notFound')()('NotFound', 'notFound', {
|
|
43
55
|
entity: Schema.optionalKey(Schema.String)
|
|
44
56
|
}) {
|
|
@@ -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/** 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","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;;;;;;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,KAAK,CAACR;AAAc;AACpC;AAEH,6DAA6D,GAC7D,OAAO,MAAMS,qBAAqBV,cAAc,aAC9C,gBACA,gBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH;;;;CAIC,GACD,OAAO,MAAME,wBAAwBb,cACnC,aAEA,mBACA,mBACA;IAAEW,QAAQZ,OAAOK,MAAM;AAAC,GACxB;IAAEQ,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,gDAAgD,GAChD,OAAO,MAAMG,wBAAwBd,cACnC,qBACmB,mBAAmB;AAAoB;AAE5D,yCAAyC,GACzC,OAAO,MAAMe,kBAAkBf,cAAc,eAC3C,aACA,aACA,uEAAuE;AACvE,6BAA6B;AAC7B;IAAEgB,YAAYjB,OAAOkB,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,gBAAgBlC,OAAOkB,WAAW,CAAClB,OAAO2B,MAAM;AAClD,GACA;IAAEd,SAAS,CAAC,EAAED,MAAM,EAAE,GAAKA;AAAO;AACjC;AAEH,0EAA0E,GAC1E,OAAO,MAAMuB,iBAAiBlC,cAAc,cAC1C,YACA;AACC;AAEH,kEAAkE,GAClE,OAAO,MAAMmC,8BAA8BnC,cACzC,aACyB,yBAAyB;AAA0B;AAE9E,+DAA+D,GAC/D,OAAO,MAAMoC,6BAA6BpC,cACxC,cACwB,wBAAwB;AAAyB;AAE3E,qEAAqE,GACrE,OAAO,MAAMqC,+BAA+BrC,cAC1C,gBAEA,0BACA;AACC;AAkBH,MAAMsC,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/** 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;;;;;;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,KAAK,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
|
package/dist/index.d.ts
CHANGED
|
@@ -34,6 +34,7 @@ export * from './idempotency/index.js';
|
|
|
34
34
|
export * from './query/fold.js';
|
|
35
35
|
export * from './query/in-memory-query.js';
|
|
36
36
|
export * from './rsql/index.js';
|
|
37
|
+
export * from './shortcut/chord.js';
|
|
37
38
|
export * from './types/BulkOutcome.js';
|
|
38
39
|
export * from './types/Entity.js';
|
|
39
40
|
export * from './types/EntityAction.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;AACzD,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,q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yC,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
|
@@ -34,6 +34,7 @@ export * from './idempotency/index.js';
|
|
|
34
34
|
export * from './query/fold.js';
|
|
35
35
|
export * from './query/in-memory-query.js';
|
|
36
36
|
export * from './rsql/index.js';
|
|
37
|
+
export * from './shortcut/chord.js';
|
|
37
38
|
export * from './types/BulkOutcome.js';
|
|
38
39
|
export * from './types/Entity.js';
|
|
39
40
|
export * from './types/EntityAction.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 './types/BulkOutcome.js';\nexport * from './types/Entity.js';\nexport * from './types/EntityAction.js';\nexport * from './types/EntityDraft.js';\nexport * from './types/EntityFacets.js';\nexport * from './types/EntityFiltering.js';\nexport * from './types/EntityLoadRequest.js';\nexport * from './types/EntityPage.js';\nexport * from './types/EntityRowDraft.js';\nexport * from './types/EntitySelection.js';\nexport * from './types/EntitySorting.js';\nexport * from './types/Json.js';\nexport * from './types/StandardSchema.js';\nexport * from './types/UseCase.js';\nexport * from './use-case-runner/index.js';\nexport * from './wizard/index.js';\n"],"names":[],"mappings":"AAAA,cAAc,gDAAgD;AAC9D,cAAc,6BAA6B;AAC3C,cAAc,yBAAyB;AACvC,cAAc,sBAAsB;AACpC,cAAc,mDAAmD;AACjE,cAAc,iDAAiD;AAC/D,cAAc,iDAAiD;AAC/D,cAAc,mDAAmD;AACjE,cAAc,wCAAwC;AACtD,cAAc,oCAAoC;AAClD,cAAc,uCAAuC;AACrD,cAAc,wDAAwD;AACtE,cAAc,4DAA4D;AAC1E,cAAc,iDAAiD;AAC/D,cAAc,wDAAwD;AACtE,cAAc,kDAAkD;AAChE,cAAc,2DAA2D;AACzE,cAAc,yDAAyD;AACvE,cAAc,yDAAyD;AACvE,cAAc,2DAA2D;AACzE,cAAc,wCAAwC;AACtD,cAAc,2CAA2C;AACzD,cAAc,0CAA0C;AACxD,cAAc,wCAAwC;AACtD,cAAc,sBAAsB;AACpC,cAAc,qBAAqB;AACnC,cAAc,uBAAuB;AACrC,cAAc,4BAA4B;AAC1C,cAAc,mBAAmB;AACjC,cAAc,oBAAoB;AAClC,cAAc,2BAA2B;AACzC,cAAc,sBAAsB;AACpC,cAAc,yBAAyB;AACvC,cAAc,kBAAkB;AAChC,cAAc,6BAA6B;AAC3C,cAAc,kBAAkB;AAChC,cAAc,yBAAyB;AACvC,cAAc,oBAAoB;AAClC,cAAc,0BAA0B;AACxC,cAAc,yBAAyB;AACvC,cAAc,0BAA0B;AACxC,cAAc,6BAA6B;AAC3C,cAAc,+BAA+B;AAC7C,cAAc,wBAAwB;AACtC,cAAc,4BAA4B;AAC1C,cAAc,6BAA6B;AAC3C,cAAc,2BAA2B;AACzC,cAAc,kBAAkB;AAChC,cAAc,4BAA4B;AAC1C,cAAc,qBAAqB;AACnC,cAAc,6BAA6B;AAC3C,cAAc,oBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './base-entities/configuration-client/index.js';\nexport * from './command-palette/index.js';\nexport * from './deadline/deadline.js';\nexport * from './endpoint/index.js';\nexport * from './entity-definition/decorators/accessor/index.js';\nexport * from './entity-definition/decorators/entity/index.js';\nexport * from './entity-definition/decorators/method/index.js';\nexport * from './entity-definition/decorators/use-case/index.js';\nexport * from './entity-definition/describe/index.js';\nexport * from './entity-definition/field-path.js';\nexport * from './entity-definition/helpers/index.js';\nexport * from './entity-definition/links/apply-entity-links/index.js';\nexport * from './entity-definition/links/entity-collection-link/index.js';\nexport * from './entity-definition/links/entity-link/index.js';\nexport * from './entity-definition/links/entity-link-source/index.js';\nexport * from './entity-definition/links/link-targets/index.js';\nexport * from './entity-definition/meta-entities/meta-accessor/index.js';\nexport * from './entity-definition/meta-entities/meta-entity/index.js';\nexport * from './entity-definition/meta-entities/meta-method/index.js';\nexport * from './entity-definition/meta-entities/meta-use-case/index.js';\nexport * from './entity-definition/metadata/index.js';\nexport * from './entity-definition/reconstruct/index.js';\nexport * from './entity-definition/serializer/index.js';\nexport * from './entity-definition/validate/index.js';\nexport * from './envelope/index.js';\nexport * from './failure/index.js';\nexport * from './hierarchy/index.js';\nexport * from './http/session-cookies.js';\nexport * from './i18n/format.js';\nexport * from './i18n/locales.js';\nexport * from './i18n/localized-text.js';\nexport * from './i18n/negotiate.js';\nexport * from './idempotency/index.js';\nexport * from './query/fold.js';\nexport * from './query/in-memory-query.js';\nexport * from './rsql/index.js';\nexport * from './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"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A keyboard chord, read: `"Mod+Shift+S"` as its parts. */
|
|
2
|
+
export interface ParsedChord {
|
|
3
|
+
/** The chord as written, normalized: `Mod`, then `Alt`, then `Shift`. */
|
|
4
|
+
readonly text: string;
|
|
5
|
+
/** `KeyboardEvent.key`, lower-cased. */
|
|
6
|
+
readonly key: string;
|
|
7
|
+
readonly shift: boolean;
|
|
8
|
+
readonly alt: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Reads a chord, refusing one a shortcut may not take (ADR 0026):
|
|
12
|
+
*
|
|
13
|
+
* - **without `Mod`** — a single key, or Shift+key, fires while a reader
|
|
14
|
+
* types (WCAG 2.1.4);
|
|
15
|
+
* - **Alt+letter** — macOS Option composes it into a character;
|
|
16
|
+
* - **an editing chord** — Mod+A, C, V, X, Y, Z are the field's.
|
|
17
|
+
*
|
|
18
|
+
* `Mod` is ⌘ on a Mac and Ctrl elsewhere.
|
|
19
|
+
*/
|
|
20
|
+
export declare function parseChord(chord: string): ParsedChord;
|
|
21
|
+
/** Throws unless `chord` is one a shortcut may take; see {@link parseChord}. */
|
|
22
|
+
export declare function assertChord(chord: string): void;
|
|
23
|
+
//# sourceMappingURL=chord.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chord.d.ts","sourceRoot":"","sources":["../../src/shortcut/chord.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,MAAM,WAAW,WAAW;IAC1B,yEAAyE;IACzE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,wCAAwC;IACxC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC;CACvB;AAWD;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAmCrD;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAE/C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** A keyboard chord, read: `"Mod+Shift+S"` as its parts. */ /**
|
|
2
|
+
* The chords that belong to whatever field has focus: select all, copy, paste,
|
|
3
|
+
* cut, undo and redo. A shortcut on one of them would take an edit away from
|
|
4
|
+
* the reader mid-sentence.
|
|
5
|
+
*/ const EDITING_KEYS = new Set([
|
|
6
|
+
'a',
|
|
7
|
+
'c',
|
|
8
|
+
'v',
|
|
9
|
+
'x',
|
|
10
|
+
'y',
|
|
11
|
+
'z'
|
|
12
|
+
]);
|
|
13
|
+
const MODIFIERS = new Set([
|
|
14
|
+
'mod',
|
|
15
|
+
'shift',
|
|
16
|
+
'alt'
|
|
17
|
+
]);
|
|
18
|
+
/**
|
|
19
|
+
* Reads a chord, refusing one a shortcut may not take (ADR 0026):
|
|
20
|
+
*
|
|
21
|
+
* - **without `Mod`** — a single key, or Shift+key, fires while a reader
|
|
22
|
+
* types (WCAG 2.1.4);
|
|
23
|
+
* - **Alt+letter** — macOS Option composes it into a character;
|
|
24
|
+
* - **an editing chord** — Mod+A, C, V, X, Y, Z are the field's.
|
|
25
|
+
*
|
|
26
|
+
* `Mod` is ⌘ on a Mac and Ctrl elsewhere.
|
|
27
|
+
*/ export function parseChord(chord) {
|
|
28
|
+
const parts = chord.split('+').map((part)=>part.trim());
|
|
29
|
+
// `split` always yields a last part, empty for `"Mod+"`.
|
|
30
|
+
const last = parts[parts.length - 1];
|
|
31
|
+
const key = last.toLowerCase();
|
|
32
|
+
const modifiers = new Set(parts.slice(0, -1).map((part)=>part.toLowerCase()));
|
|
33
|
+
const refuse = (why)=>{
|
|
34
|
+
throw new Error(`"${chord}" cannot be a shortcut: ${why}.`);
|
|
35
|
+
};
|
|
36
|
+
if (key === '' || MODIFIERS.has(key)) refuse('it names no key');
|
|
37
|
+
for (const modifier of modifiers)if (!MODIFIERS.has(modifier)) refuse(`"${modifier}" is not Mod, Alt or Shift`);
|
|
38
|
+
if (!modifiers.has('mod')) refuse('a shortcut holds Mod, so it never fires while someone types');
|
|
39
|
+
if (modifiers.has('alt') && /^[a-z]$/.test(key)) refuse('Option+letter types a character on macOS');
|
|
40
|
+
if (!modifiers.has('alt') && !modifiers.has('shift') && EDITING_KEYS.has(key)) refuse('it is an editing chord a text field needs');
|
|
41
|
+
const shift = modifiers.has('shift');
|
|
42
|
+
const alt = modifiers.has('alt');
|
|
43
|
+
const display = key.length === 1 ? key.toUpperCase() : last;
|
|
44
|
+
return {
|
|
45
|
+
text: [
|
|
46
|
+
'Mod',
|
|
47
|
+
...alt ? [
|
|
48
|
+
'Alt'
|
|
49
|
+
] : [],
|
|
50
|
+
...shift ? [
|
|
51
|
+
'Shift'
|
|
52
|
+
] : [],
|
|
53
|
+
display
|
|
54
|
+
].join('+'),
|
|
55
|
+
key,
|
|
56
|
+
shift,
|
|
57
|
+
alt
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Throws unless `chord` is one a shortcut may take; see {@link parseChord}. */ export function assertChord(chord) {
|
|
61
|
+
parseChord(chord);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=chord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/shortcut/chord.ts"],"sourcesContent":["/** A keyboard chord, read: `\"Mod+Shift+S\"` as its parts. */\nexport interface ParsedChord {\n /** The chord as written, normalized: `Mod`, then `Alt`, then `Shift`. */\n readonly text: string;\n /** `KeyboardEvent.key`, lower-cased. */\n readonly key: string;\n readonly shift: boolean;\n readonly alt: boolean;\n}\n\n/**\n * The chords that belong to whatever field has focus: select all, copy, paste,\n * cut, undo and redo. A shortcut on one of them would take an edit away from\n * the reader mid-sentence.\n */\nconst EDITING_KEYS = new Set(['a', 'c', 'v', 'x', 'y', 'z']);\n\nconst MODIFIERS = new Set(['mod', 'shift', 'alt']);\n\n/**\n * Reads a chord, refusing one a shortcut may not take (ADR 0026):\n *\n * - **without `Mod`** — a single key, or Shift+key, fires while a reader\n * types (WCAG 2.1.4);\n * - **Alt+letter** — macOS Option composes it into a character;\n * - **an editing chord** — Mod+A, C, V, X, Y, Z are the field's.\n *\n * `Mod` is ⌘ on a Mac and Ctrl elsewhere.\n */\nexport function parseChord(chord: string): ParsedChord {\n const parts = chord.split('+').map(part => part.trim());\n // `split` always yields a last part, empty for `\"Mod+\"`.\n const last = parts[parts.length - 1] as string;\n const key = last.toLowerCase();\n const modifiers = new Set(parts.slice(0, -1).map(part => part.toLowerCase()));\n const refuse = (why: string): never => {\n throw new Error(`\"${chord}\" cannot be a shortcut: ${why}.`);\n };\n\n if (key === '' || MODIFIERS.has(key)) refuse('it names no key');\n for (const modifier of modifiers)\n if (!MODIFIERS.has(modifier))\n refuse(`\"${modifier}\" is not Mod, Alt or Shift`);\n if (!modifiers.has('mod'))\n refuse('a shortcut holds Mod, so it never fires while someone types');\n if (modifiers.has('alt') && /^[a-z]$/.test(key))\n refuse('Option+letter types a character on macOS');\n if (!modifiers.has('alt') && !modifiers.has('shift') && EDITING_KEYS.has(key))\n refuse('it is an editing chord a text field needs');\n\n const shift = modifiers.has('shift');\n const alt = modifiers.has('alt');\n const display = key.length === 1 ? key.toUpperCase() : last;\n return {\n text: [\n 'Mod',\n ...(alt ? ['Alt'] : []),\n ...(shift ? ['Shift'] : []),\n display,\n ].join('+'),\n key,\n shift,\n alt,\n };\n}\n\n/** Throws unless `chord` is one a shortcut may take; see {@link parseChord}. */\nexport function assertChord(chord: string): void {\n parseChord(chord);\n}\n"],"names":["EDITING_KEYS","Set","MODIFIERS","parseChord","chord","parts","split","map","part","trim","last","length","key","toLowerCase","modifiers","slice","refuse","why","Error","has","modifier","test","shift","alt","display","toUpperCase","text","join","assertChord"],"mappings":"AAAA,0DAA0D,GAU1D;;;;CAIC,GACD,MAAMA,eAAe,IAAIC,IAAI;IAAC;IAAK;IAAK;IAAK;IAAK;IAAK;CAAI;AAE3D,MAAMC,YAAY,IAAID,IAAI;IAAC;IAAO;IAAS;CAAM;AAEjD;;;;;;;;;CASC,GACD,OAAO,SAASE,WAAWC,KAAa;IACtC,MAAMC,QAAQD,MAAME,KAAK,CAAC,KAAKC,GAAG,CAACC,CAAAA,OAAQA,KAAKC,IAAI;IACpD,yDAAy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