@entifix/core 0.22.0 → 0.22.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/entity-definition/describe/record-label.d.ts +4 -2
- package/dist/entity-definition/describe/record-label.d.ts.map +1 -1
- package/dist/entity-definition/describe/record-label.js +8 -3
- package/dist/entity-definition/describe/record-label.js.map +1 -1
- package/dist/entity-definition/meta-entities/meta-entity/meta-entity.d.ts +3 -1
- 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.map +1 -1
- package/package.json +1 -1
|
@@ -41,8 +41,10 @@ export declare function canNameRecord(descriptor: EntityFieldDescriptor): boolea
|
|
|
41
41
|
*
|
|
42
42
|
* 1. the entity's declared `labelMember`, or the member it declares the card's
|
|
43
43
|
* `title`, when filled in — a reference is answered as one, to resolve;
|
|
44
|
-
* 2. the first filled-in member
|
|
45
|
-
* a
|
|
44
|
+
* 2. the first filled-in **text** member — a `string` or a `localized` — that
|
|
45
|
+
* is not a reference: a status, a payment method, a weight or a date is a
|
|
46
|
+
* value the record holds, never what it is called, and an order named
|
|
47
|
+
* "card" or a shipment named "dispatched" is the guess this replaced;
|
|
46
48
|
* 3. the fallback: the noun and the id's {@link shortId}.
|
|
47
49
|
*
|
|
48
50
|
* `record` is read by member name, so an entity instance, a plain record and a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-label.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/describe/record-label.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAChF,OAAO,EAGL,KAAK,qBAAqB,EAC3B,MAAM,8BAA8B,CAAC;AAEtC,yFAAyF;AACzF,eAAO,MAAM,eAAe,IAAI,CAAC;AAEj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B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;CACrB,GACD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAyB7D;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,qBAAqB,GAAG,OAAO,CAOxE;AAqBD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CACzB,iBAAiB,EAAE,gBAAgB,EACnC,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,WAAW,CAyBb;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC;;;GAGG;AACH,wBAAgB,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,SAAS,MAAM,EACvD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAC5C,MAAM,CAQR"}
|
|
@@ -36,6 +36,9 @@ function labelFrom(descriptor, value) {
|
|
|
36
36
|
id: String(value)
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
|
+
/** A member whose value reads as words: only such a member names a record undeclared. */ function isText(descriptor) {
|
|
40
|
+
return descriptor.type === 'string' || descriptor.type === 'localized';
|
|
41
|
+
}
|
|
39
42
|
/**
|
|
40
43
|
* What a record is called — the **one derivation** every surface that names a
|
|
41
44
|
* record goes through: a row's title and checkbox, a card's heading, a confirm
|
|
@@ -43,8 +46,10 @@ function labelFrom(descriptor, value) {
|
|
|
43
46
|
*
|
|
44
47
|
* 1. the entity's declared `labelMember`, or the member it declares the card's
|
|
45
48
|
* `title`, when filled in — a reference is answered as one, to resolve;
|
|
46
|
-
* 2. the first filled-in member
|
|
47
|
-
* a
|
|
49
|
+
* 2. the first filled-in **text** member — a `string` or a `localized` — that
|
|
50
|
+
* is not a reference: a status, a payment method, a weight or a date is a
|
|
51
|
+
* value the record holds, never what it is called, and an order named
|
|
52
|
+
* "card" or a shipment named "dispatched" is the guess this replaced;
|
|
48
53
|
* 3. the fallback: the noun and the id's {@link shortId}.
|
|
49
54
|
*
|
|
50
55
|
* `record` is read by member name, so an entity instance, a plain record and a
|
|
@@ -59,7 +64,7 @@ function labelFrom(descriptor, value) {
|
|
|
59
64
|
if (declared !== undefined && isFilled(declared, values[declared.name])) {
|
|
60
65
|
return labelFrom(declared, values[declared.name]);
|
|
61
66
|
}
|
|
62
|
-
const undeclared = descriptors.find((descriptor)=>canNameRecord(descriptor) && isFilled(descriptor, values[descriptor.name]));
|
|
67
|
+
const undeclared = descriptors.find((descriptor)=>canNameRecord(descriptor) && isText(descriptor) && isFilled(descriptor, values[descriptor.name]));
|
|
63
68
|
if (undeclared !== undefined) {
|
|
64
69
|
return labelFrom(undeclared, values[undeclared.name]);
|
|
65
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/describe/record-label.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaEntity, findMetaEntity } from '../helpers/index.js';\nimport type { ChildConstructor } from '../meta-entities/meta-accessor/index.js';\nimport {\n COLLECTION_TYPES,\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from './describe-entity-columns.js';\n\n/** How many characters of a long id a fallback label shows. A whole UUID never reads. */\nexport const SHORT_ID_LENGTH = 8;\n\n/**\n * What a record is called, before it is put into words. Core knows neither the\n * reader's locale nor the entity's translated noun, so it answers with what to\n * show and leaves the words to the presentation layer:\n *\n * - `value` — a member's own value, read through its descriptor (a localized\n * text in the reader's locale, a number formatted);\n * - `reference` — the name of the record another entity holds under `id`,\n * which the host's reference registry resolves;\n * - `fallback` — nothing names the record: the entity's noun with\n * {@link shortId} of its id, when it has one.\n */\nexport type RecordLabel =\n | {\n readonly kind: 'value';\n readonly member: EntityFieldDescriptor;\n readonly value: unknown;\n }\n | {\n readonly kind: 'reference';\n readonly member: EntityFieldDescriptor;\n readonly entity: string;\n readonly id: string;\n }\n | { readonly kind: 'fallback'; readonly shortId?: string };\n\nconst described = new WeakMap<ChildConstructor, EntityFieldDescriptor[]>();\n\nfunction descriptorsOf(target: ChildConstructor): EntityFieldDescriptor[] {\n let descriptors = described.get(target);\n if (descriptors === undefined) {\n descriptors = describeEntityColumns(target);\n described.set(target, descriptors);\n }\n return descriptors;\n}\n\n/** Holds something a person could read: not empty, and a localized text in at least one locale. */\nfunction isFilled(descriptor: EntityFieldDescriptor, value: unknown): boolean {\n if (value === undefined || value === null || value === '') return false;\n if (descriptor.type === 'localized') {\n return (\n typeof value === 'object' &&\n Object.values(value).some(text => typeof text === 'string' && text !== '')\n );\n }\n return true;\n}\n\n/**\n * Whether a member can name a record it was not declared to name. One that\n * holds a key or a list never can: an id, a reference and a link are keys,\n * and a collection is many values.\n */\nexport function canNameRecord(descriptor: EntityFieldDescriptor): boolean {\n return (\n descriptor.type !== 'id' &&\n descriptor.type !== 'link' &&\n descriptor.references === undefined &&\n !COLLECTION_TYPES.includes(descriptor.type)\n );\n}\n\nfunction labelFrom(\n descriptor: EntityFieldDescriptor,\n value: unknown,\n): RecordLabel {\n return descriptor.references === undefined\n ? { kind: 'value', member: descriptor, value }\n : {\n kind: 'reference',\n member: descriptor,\n entity: descriptor.references.entity,\n id: String(value),\n };\n}\n\n/**\n * What a record is called — the **one derivation** every surface that names a\n * record goes through: a row's title and checkbox, a card's heading, a confirm\n * dialog's object, a breadcrumb, a toast, the typed delete policy. In order:\n *\n * 1. the entity's declared `labelMember`, or the member it declares the card's\n * `title`, when filled in — a reference is answered as one, to resolve;\n * 2. the first filled-in member that is
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/describe/record-label.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaEntity, findMetaEntity } from '../helpers/index.js';\nimport type { ChildConstructor } from '../meta-entities/meta-accessor/index.js';\nimport {\n COLLECTION_TYPES,\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from './describe-entity-columns.js';\n\n/** How many characters of a long id a fallback label shows. A whole UUID never reads. */\nexport const SHORT_ID_LENGTH = 8;\n\n/**\n * What a record is called, before it is put into words. Core knows neither the\n * reader's locale nor the entity's translated noun, so it answers with what to\n * show and leaves the words to the presentation layer:\n *\n * - `value` — a member's own value, read through its descriptor (a localized\n * text in the reader's locale, a number formatted);\n * - `reference` — the name of the record another entity holds under `id`,\n * which the host's reference registry resolves;\n * - `fallback` — nothing names the record: the entity's noun with\n * {@link shortId} of its id, when it has one.\n */\nexport type RecordLabel =\n | {\n readonly kind: 'value';\n readonly member: EntityFieldDescriptor;\n readonly value: unknown;\n }\n | {\n readonly kind: 'reference';\n readonly member: EntityFieldDescriptor;\n readonly entity: string;\n readonly id: string;\n }\n | { readonly kind: 'fallback'; readonly shortId?: string };\n\nconst described = new WeakMap<ChildConstructor, EntityFieldDescriptor[]>();\n\nfunction descriptorsOf(target: ChildConstructor): EntityFieldDescriptor[] {\n let descriptors = described.get(target);\n if (descriptors === undefined) {\n descriptors = describeEntityColumns(target);\n described.set(target, descriptors);\n }\n return descriptors;\n}\n\n/** Holds something a person could read: not empty, and a localized text in at least one locale. */\nfunction isFilled(descriptor: EntityFieldDescriptor, value: unknown): boolean {\n if (value === undefined || value === null || value === '') return false;\n if (descriptor.type === 'localized') {\n return (\n typeof value === 'object' &&\n Object.values(value).some(text => typeof text === 'string' && text !== '')\n );\n }\n return true;\n}\n\n/**\n * Whether a member can name a record it was not declared to name. One that\n * holds a key or a list never can: an id, a reference and a link are keys,\n * and a collection is many values.\n */\nexport function canNameRecord(descriptor: EntityFieldDescriptor): boolean {\n return (\n descriptor.type !== 'id' &&\n descriptor.type !== 'link' &&\n descriptor.references === undefined &&\n !COLLECTION_TYPES.includes(descriptor.type)\n );\n}\n\nfunction labelFrom(\n descriptor: EntityFieldDescriptor,\n value: unknown,\n): RecordLabel {\n return descriptor.references === undefined\n ? { kind: 'value', member: descriptor, value }\n : {\n kind: 'reference',\n member: descriptor,\n entity: descriptor.references.entity,\n id: String(value),\n };\n}\n\n/** A member whose value reads as words: only such a member names a record undeclared. */\nfunction isText(descriptor: EntityFieldDescriptor): boolean {\n return descriptor.type === 'string' || descriptor.type === 'localized';\n}\n\n/**\n * What a record is called — the **one derivation** every surface that names a\n * record goes through: a row's title and checkbox, a card's heading, a confirm\n * dialog's object, a breadcrumb, a toast, the typed delete policy. In order:\n *\n * 1. the entity's declared `labelMember`, or the member it declares the card's\n * `title`, when filled in — a reference is answered as one, to resolve;\n * 2. the first filled-in **text** member — a `string` or a `localized` — that\n * is not a reference: a status, a payment method, a weight or a date is a\n * value the record holds, never what it is called, and an order named\n * \"card\" or a shipment named \"dispatched\" is the guess this replaced;\n * 3. the fallback: the noun and the id's {@link shortId}.\n *\n * `record` is read by member name, so an entity instance, a plain record and a\n * form's draft all work; a record not loaded yet is called by the noun alone.\n */\nexport function recordLabel(\n entityConstructor: ChildConstructor,\n record: object | undefined,\n): RecordLabel {\n const values = (record ?? {}) as Record<string, unknown>;\n const descriptors = descriptorsOf(entityConstructor);\n const declaredName =\n findMetaEntity(entityConstructor)?.labelMember ??\n descriptors.find(descriptor => descriptor.card === 'title')?.name;\n const declared = descriptors.find(\n descriptor => descriptor.name === declaredName,\n );\n if (declared !== undefined && isFilled(declared, values[declared.name])) {\n return labelFrom(declared, values[declared.name]);\n }\n const undeclared = descriptors.find(\n descriptor =>\n canNameRecord(descriptor) &&\n isText(descriptor) &&\n isFilled(descriptor, values[descriptor.name]),\n );\n if (undeclared !== undefined) {\n return labelFrom(undeclared, values[undeclared.name]);\n }\n const id = values['id'];\n return id === undefined || id === null || id === ''\n ? { kind: 'fallback' }\n : { kind: 'fallback', shortId: shortId(String(id)) };\n}\n\n/**\n * Ids no longer than this are quoted whole: `offering-12` cut to eight\n * characters would name every offering alike, while a UUID is never short.\n */\nexport const SHORT_ID_WHOLE = 12;\n\n/**\n * What a label quotes of an id when nothing names the record: a short id\n * whole, a long one cut to its first {@link SHORT_ID_LENGTH} characters.\n */\nexport function shortId(id: string): string {\n return id.length <= SHORT_ID_WHOLE ? id : id.slice(0, SHORT_ID_LENGTH);\n}\n\n/**\n * The `domain:key` an entity is referenced by — the pair its\n * `@entity({ domain, key })` declares, which is also its permission namespace.\n * Throws for an entity that declares only one of them: nothing could reference\n * it.\n */\nexport function entityReferenceKey<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n): string {\n const { domain, key, name } = extractMetaEntity(entityConstructor);\n if (domain === undefined || key === undefined) {\n throw new Error(\n `${name} needs both a domain and a key to be referenced — a reference names its target as \"domain:key\".`,\n );\n }\n return `${domain}:${key}`;\n}\n"],"names":["extractMetaEntity","findMetaEntity","COLLECTION_TYPES","describeEntityColumns","SHORT_ID_LENGTH","described","WeakMap","descriptorsOf","target","descriptors","get","undefined","set","isFilled","descriptor","value","type","Object","values","some","text","canNameRecord","references","includes","labelFrom","kind","member","entity","id","String","isText","recordLabel","entityConstructor","record","declaredName","labelMember","find","card","name","declared","undeclared","shortId","SHORT_ID_WHOLE","length","slice","entityReferenceKey","domain","key","Error"],"mappings":"AACA,SAASA,iBAAiB,EAAEC,cAAc,QAAQ,sBAAsB;AAExE,SACEC,gBAAgB,EAChBC,qBAAqB,QAEhB,+BAA+B;AAEtC,uFAAuF,GACvF,OAAO,MAAMC,kBAAkB,EAAE;AA4BjC,MAAMC,YAAY,IAAIC;AAEtB,SAASC,cAAcC,MAAwB;IAC7C,IAAIC,cAAcJ,UAAUK,GAAG,CAACF;IAChC,IAAIC,gBAAgBE,WAAW;QAC7BF,cAAcN,sBAAsBK;QACpCH,UAAUO,GAAG,CAACJ,QAAQC;IACxB;IACA,OAAOA;AACT;AAEA,iGAAiG,GACjG,SAASI,SAASC,UAAiC,EAAEC,KAAc;IACjE,IAAIA,UAAUJ,aAAaI,UAAU,QAAQA,UAAU,IAAI,OAAO;IAClE,IAAID,WAAWE,IAAI,KAAK,aAAa;QACnC,OACE,OAAOD,UAA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2B,IAAI,CACjCtB,CAAAA,aACEO,cAAcP,eACdgB,OAAOhB,eACPD,SAASC,YAAYI,MAAM,CAACJ,WAAWwB,IAAI,CAAC;IAEhD,IAAIE,eAAe7B,WAAW;QAC5B,OAAOa,UAAUgB,YAAYtB,MAAM,CAACsB,WAAWF,IAAI,CAAC;IACtD;IACA,MAAMV,KAAKV,MAAM,CAAC,KAAK;IACvB,OAAOU,OAAOjB,aAAaiB,OAAO,QAAQA,OAAO,KAC7C;QAAEH,MAAM;IAAW,IACnB;QAAEA,MAAM;QAAYgB,SAASA,QAAQZ,OAAOD;IAAK;AACvD;AAEA;;;CAGC,GACD,OAAO,MAAMc,iBAAiB,GAAG;AAEjC;;;CAGC,GACD,OAAO,SAASD,QAAQb,EAAU;IAChC,OAAOA,GAAGe,MAAM,IAAID,iBAAiBd,KAAKA,GAAGgB,KAAK,CAAC,GAAGxC;AACxD;AAEA;;;;;CAKC,GACD,OAAO,SAASyC,mBACdb,iBAA6C;IAE7C,MAAM,EAAEc,MAAM,EAAEC,GAAG,EAAET,IAAI,EAAE,GAAGtC,kBAAkBgC;IAChD,IAAIc,WAAWnC,aAAaoC,QAAQpC,WAAW;QAC7C,MAAM,IAAIqC,MACR,GAAGV,KAAK,+FAA+F,CAAC;IAE5G;IACA,OAAO,GAAGQ,OAAO,CAAC,EAAEC,KAAK;AAC3B"}
|
|
@@ -59,7 +59,9 @@ export interface MetaEntityOptions {
|
|
|
59
59
|
* or a reference, in which case the record is called by its target's name.
|
|
60
60
|
* Every surface that names a record (a row, a card's heading, a confirm
|
|
61
61
|
* dialog, a breadcrumb, a toast) reads it through `recordLabel()`.
|
|
62
|
-
* Undeclared, the first filled-in member that is not a key is used
|
|
62
|
+
* Undeclared, the first filled-in text member that is not a key is used —
|
|
63
|
+
* never a number, an enum or a date, which hold a value rather than a name;
|
|
64
|
+
* with none, the record is the noun and its short id. Checked
|
|
63
65
|
* when the entity is described: a member that does not exist, is hidden or
|
|
64
66
|
* is a collection fails
|
|
65
67
|
* ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).
|
|
@@ -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;IACpD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB
|
|
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;IACpD;;;;;OAKG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;;;;;;;;OAWG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,UAAU;IAErB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC7D,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;gBAIlB,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB;CAmBtD"}
|
|
@@ -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 * `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 * The member a record is called by — a `string`, a `localized`, a `number`\n * or a reference, in which case the record is called by its target's name.\n * Every surface that names a record (a row, a card's heading, a confirm\n * dialog, a breadcrumb, a toast) reads it through `recordLabel()`.\n * Undeclared, the first filled-in member that is not a key is used. Checked\n * when the entity is described: a member that does not exist, is hidden or\n * is a collection fails\n * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n */\n labelMember?: string;\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 readonly labelMember?: string;\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 this.labelMember = options?.labelMember;\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","labelMember"],"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 * The member a record is called by — a `string`, a `localized`, a `number`\n * or a reference, in which case the record is called by its target's name.\n * Every surface that names a record (a row, a card's heading, a confirm\n * dialog, a breadcrumb, a toast) reads it through `recordLabel()`.\n * Undeclared, the first filled-in text member that is not a key is used —\n * never a number, an enum or a date, which hold a value rather than a name;\n * with none, the record is the noun and its short id. Checked\n * when the entity is described: a member that does not exist, is hidden or\n * is a collection fails\n * ([ADR 0030](../../../../../../../docs/adr/0030-a-reference-names-its-target-through-the-owners-read-port.md)).\n */\n labelMember?: string;\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 readonly labelMember?: string;\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 this.labelMember = options?.labelMember;\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","labelMember"],"mappings":"AAGA,SAASA,YAAY,QAAQ,eAAe;AAyE5C,OAAO,MAAMC;IAWX,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;QACvC,IAAI,CAACC,WAAW,GAAGR,2BAAAA,QAASQ,WAAW;IACzC;AAQF"}
|
package/package.json
CHANGED