@entifix/core 0.12.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base-entities/configuration-client/configuration-client-singleton.d.ts +12 -13
- package/dist/base-entities/configuration-client/configuration-client-singleton.d.ts.map +1 -1
- package/dist/base-entities/configuration-client/configuration-client-singleton.js +4 -17
- package/dist/base-entities/configuration-client/configuration-client-singleton.js.map +1 -1
- package/dist/base-entities/configuration-client/types.d.ts +13 -13
- package/dist/base-entities/configuration-client/types.d.ts.map +1 -1
- package/dist/base-entities/configuration-client/types.js.map +1 -1
- package/dist/command-palette/command-matching.d.ts.map +1 -1
- package/dist/command-palette/command-matching.js +1 -5
- package/dist/command-palette/command-matching.js.map +1 -1
- package/dist/entity-definition/describe/describe-child-columns.d.ts +3 -3
- package/dist/entity-definition/describe/describe-child-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-child-columns.js +5 -10
- package/dist/entity-definition/describe/describe-child-columns.js.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.d.ts.map +1 -1
- package/dist/entity-definition/describe/describe-entity-columns.js +6 -7
- package/dist/entity-definition/describe/describe-entity-columns.js.map +1 -1
- package/dist/entity-definition/describe/entity-view.d.ts.map +1 -1
- package/dist/entity-definition/describe/entity-view.js +2 -3
- package/dist/entity-definition/describe/entity-view.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 +4 -5
- package/dist/entity-definition/helpers/entity-definition-helpers.js.map +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.d.ts.map +1 -1
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js +2 -6
- package/dist/entity-definition/links/apply-entity-links/apply-entity-links.js.map +1 -1
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts +3 -3
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-collection-link/entity-collection-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.d.ts +4 -4
- package/dist/entity-definition/links/entity-link/entity-link.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link/entity-link.js.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts +3 -3
- package/dist/entity-definition/links/entity-link-source/entity-link-source.d.ts.map +1 -1
- package/dist/entity-definition/links/entity-link-source/entity-link-source.js.map +1 -1
- package/dist/entity-definition/links/link-targets/link-targets.d.ts.map +1 -1
- package/dist/entity-definition/links/link-targets/link-targets.js +2 -3
- package/dist/entity-definition/links/link-targets/link-targets.js.map +1 -1
- package/dist/entity-definition/meta-entities/bounds.d.ts.map +1 -1
- package/dist/entity-definition/meta-entities/bounds.js +2 -3
- package/dist/entity-definition/meta-entities/bounds.js.map +1 -1
- package/dist/entity-definition/serializer/deserialize.d.ts +3 -3
- package/dist/entity-definition/serializer/deserialize.d.ts.map +1 -1
- package/dist/entity-definition/serializer/deserialize.js +11 -18
- package/dist/entity-definition/serializer/deserialize.js.map +1 -1
- package/dist/failure/failure.d.ts +0 -7
- package/dist/failure/failure.d.ts.map +1 -1
- package/dist/failure/failure.js.map +1 -1
- package/dist/failure/predicates.d.ts +6 -0
- package/dist/failure/predicates.d.ts.map +1 -1
- package/dist/failure/predicates.js +5 -0
- package/dist/failure/predicates.js.map +1 -1
- package/dist/hierarchy/hierarchy.d.ts.map +1 -1
- package/dist/hierarchy/hierarchy.js +1 -2
- package/dist/hierarchy/hierarchy.js.map +1 -1
- package/dist/i18n/locales.d.ts.map +1 -1
- package/dist/i18n/locales.js +19 -4
- package/dist/i18n/locales.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/query/in-memory-query.d.ts.map +1 -1
- package/dist/query/in-memory-query.js +1 -2
- package/dist/query/in-memory-query.js.map +1 -1
- package/dist/rsql/coerce-rsql.d.ts +1 -1
- package/dist/rsql/coerce-rsql.d.ts.map +1 -1
- package/dist/rsql/coerce-rsql.js +2 -3
- package/dist/rsql/coerce-rsql.js.map +1 -1
- package/dist/rsql/facet-query-url.d.ts +1 -1
- package/dist/rsql/facet-query-url.d.ts.map +1 -1
- package/dist/rsql/facet-query-url.js +4 -9
- package/dist/rsql/facet-query-url.js.map +1 -1
- package/dist/rsql/load-request-url.d.ts +1 -1
- package/dist/rsql/load-request-url.d.ts.map +1 -1
- package/dist/rsql/load-request-url.js +2 -5
- package/dist/rsql/load-request-url.js.map +1 -1
- package/dist/rsql/parse-rsql.d.ts +1 -1
- package/dist/rsql/parse-rsql.d.ts.map +1 -1
- package/dist/rsql/parse-rsql.js +2 -5
- package/dist/rsql/parse-rsql.js.map +1 -1
- package/dist/use-case-runner/entity-writer.d.ts +24 -0
- package/dist/use-case-runner/entity-writer.d.ts.map +1 -0
- package/dist/use-case-runner/entity-writer.js +12 -0
- package/dist/use-case-runner/entity-writer.js.map +1 -0
- package/dist/use-case-runner/index.d.ts +2 -0
- package/dist/use-case-runner/index.d.ts.map +1 -1
- package/dist/use-case-runner/index.js +2 -0
- package/dist/use-case-runner/index.js.map +1 -1
- package/dist/use-case-runner/use-case-runner.d.ts +9 -4
- package/dist/use-case-runner/use-case-runner.d.ts.map +1 -1
- package/dist/use-case-runner/use-case-runner.js.map +1 -1
- package/dist/use-case-runner/write-result.d.ts +36 -0
- package/dist/use-case-runner/write-result.d.ts.map +1 -0
- package/dist/use-case-runner/write-result.js +20 -0
- package/dist/use-case-runner/write-result.js.map +1 -0
- package/dist/wizard/wizard-definition.d.ts.map +1 -1
- package/dist/wizard/wizard-definition.js +10 -11
- package/dist/wizard/wizard-definition.js.map +1 -1
- package/dist/wizard/wizard-navigation.d.ts +1 -1
- package/dist/wizard/wizard-navigation.d.ts.map +1 -1
- package/dist/wizard/wizard-navigation.js +2 -3
- package/dist/wizard/wizard-navigation.js.map +1 -1
- package/package.json +3 -3
- package/dist/base-entities/entifix-error/entifix-error.d.ts +0 -31
- package/dist/base-entities/entifix-error/entifix-error.d.ts.map +0 -1
- package/dist/base-entities/entifix-error/entifix-error.js +0 -56
- package/dist/base-entities/entifix-error/entifix-error.js.map +0 -1
- package/dist/base-entities/entifix-error/index.d.ts +0 -2
- package/dist/base-entities/entifix-error/index.d.ts.map +0 -1
- package/dist/base-entities/entifix-error/index.js +0 -3
- package/dist/base-entities/entifix-error/index.js.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { _ as _extends } from "@swc/helpers/_/_extends";
|
|
2
|
-
import { EntifixBuildError } from '../../base-entities/entifix-error/index.js';
|
|
3
2
|
import { extractMetaEntity } from '../helpers/index.js';
|
|
4
3
|
import { describeEntityColumns } from './describe-entity-columns.js';
|
|
5
4
|
/**
|
|
@@ -16,13 +15,13 @@ import { describeEntityColumns } from './describe-entity-columns.js';
|
|
|
16
15
|
const view = (_meta_views = meta.views) == null ? void 0 : _meta_views[name];
|
|
17
16
|
if (view === undefined) {
|
|
18
17
|
var _meta_views1;
|
|
19
|
-
throw new
|
|
18
|
+
throw new Error(`${meta.name} declares no view "${name}"; it declares ${JSON.stringify(Object.keys((_meta_views1 = meta.views) != null ? _meta_views1 : {}))}.`);
|
|
20
19
|
}
|
|
21
20
|
const descriptors = describeEntityColumns(entityConstructor);
|
|
22
21
|
const omitted = ((_view_omit = view.omit) != null ? _view_omit : []).map((member)=>{
|
|
23
22
|
const descriptor = descriptors.find((each)=>each.name === member);
|
|
24
23
|
if (descriptor === undefined || descriptor.name === 'id') {
|
|
25
|
-
throw new
|
|
24
|
+
throw new Error(`${meta.name}'s view "${name}" omits "${member}", which is ${descriptor === undefined ? 'not a member of it' : 'its identity'}.`);
|
|
26
25
|
}
|
|
27
26
|
return descriptor;
|
|
28
27
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/describe/entity-view.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/describe/entity-view.ts"],"sourcesContent":["import type { Entity, EntityConstructor } from '../../types/Entity.js';\nimport { extractMetaEntity } from '../helpers/index.js';\nimport type { EntityViewOptions } from '../meta-entities/meta-entity/index.js';\nimport {\n describeEntityColumns,\n type EntityFieldDescriptor,\n} from './describe-entity-columns.js';\n\n/** A view, resolved against the entity it belongs to. */\nexport interface EntityView extends EntityViewOptions {\n readonly name: string;\n /** The omitted members' descriptors, so a caller can drop them by wire key. */\n readonly omitted: readonly EntityFieldDescriptor[];\n}\n\n/**\n * One of an entity's named views, checked against the entity: a view it does\n * not declare, or one omitting a member it does not have, is a declaration\n * error rather than a view that silently publishes the whole record.\n *\n * The identity member cannot be omitted — a published record still has to say\n * which record it is.\n */\nexport function extractEntityView<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n name: string,\n): EntityView {\n const meta = extractMetaEntity(entityConstructor);\n const view = meta.views?.[name];\n if (view === undefined) {\n throw new Error(\n `${meta.name} declares no view \"${name}\"; it declares ${JSON.stringify(\n Object.keys(meta.views ?? {}),\n )}.`,\n );\n }\n const descriptors = describeEntityColumns(entityConstructor);\n const omitted = (view.omit ?? []).map(member => {\n const descriptor = descriptors.find(each => each.name === member);\n if (descriptor === undefined || descriptor.name === 'id') {\n throw new Error(\n `${meta.name}'s view \"${name}\" omits \"${member}\", which is ${\n descriptor === undefined ? 'not a member of it' : 'its identity'\n }.`,\n );\n }\n return descriptor;\n });\n return { ...view, name, omitted };\n}\n"],"names":["extractMetaEntity","describeEntityColumns","extractEntityView","entityConstructor","name","view","meta","views","undefined","Error","JSON","stringify","Object","keys","descriptors","omitted","omit","map","member","descriptor","find","each"],"mappings":";AACA,SAASA,iBAAiB,QAAQ,sBAAsB;AAExD,SACEC,qBAAqB,QAEhB,+BAA+B;AAStC;;;;;;;CAOC,GACD,OAAO,SAASC,kBACdC,iBAA6C,EAC7CC,IAAY;QAYKC;QATJC;IADb,MAAMA,OAAON,kBAAkBG;IAC/B,MAAME,QAAOC,cAAAA,KAAKC,KAAK,qBAAVD,WAAY,CAACF,KAAK;IAC/B,IAAIC,SAASG,WAAW;YAGNF;QAFhB,MAAM,IAAIG,MACR,GAAGH,KAAKF,IAAI,CAAC,mBAAmB,EAAEA,KAAK,eAAe,EAAEM,KAAKC,SAAS,CACpEC,OAAOC,IAAI,EAACP,eAAAA,KAAKC,KAAK,YAAVD,eAAc,CAAC,IAC3B,CAAC,CAAC;IAER;IACA,MAAMQ,cAAcb,sBAAsBE;IAC1C,MAAMY,UAAU,EAACV,aAAAA,KAAKW,IAAI,YAATX,aAAa,EAAE,EAAEY,GAAG,CAACC,CAAAA;QACpC,MAAMC,aAAaL,YAAYM,IAAI,CAACC,CAAAA,OAAQA,KAAKjB,IAAI,KAAKc;QAC1D,IAAIC,eAAeX,aAAaW,WAAWf,IAAI,KAAK,MAAM;YACxD,MAAM,IAAIK,MACR,GAAGH,KAAKF,IAAI,CAAC,SAAS,EAAEA,KAAK,SAAS,EAAEc,OAAO,YAAY,EACzDC,eAAeX,YAAY,uBAAuB,eACnD,CAAC,CAAC;QAEP;QACA,OAAOW;IACT;IACA,OAAO,aAAKd;QAAMD;QAAMW;;AAC1B"}
|
|
@@ -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":"","sources":["../../../src/entity-definition/helpers/entity-definition-helpers.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACL,KAAK,gBAAgB,EACrB,YAAY,EACb,MAAM,yCAAyC,CAAC;AAC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,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,6 +1,5 @@
|
|
|
1
1
|
var _Symbol, _metadata;
|
|
2
2
|
(_metadata = (_Symbol = Symbol).metadata) != null ? _metadata : _Symbol.metadata = Symbol.for('Symbol.metadata');
|
|
3
|
-
import { EntifixBuildError } from '../../base-entities/entifix-error/index.js';
|
|
4
3
|
export const META_ENTITY_KEY = Symbol('MetaEntity');
|
|
5
4
|
export const META_ACCESSOR_KEY = Symbol('MetaAccessor');
|
|
6
5
|
export const META_METHOD_KEY = Symbol('MetaMethod');
|
|
@@ -8,7 +7,7 @@ export const META_USE_CASE_KEY = Symbol('MetaUseCase');
|
|
|
8
7
|
export const META_USE_CASE_BINDING_KEY = Symbol('MetaUseCaseBinding');
|
|
9
8
|
function requireMetadata(metadata) {
|
|
10
9
|
if (!metadata) {
|
|
11
|
-
throw new
|
|
10
|
+
throw new Error('Decorator metadata unavailable — Symbol.metadata polyfill missing or stage-3 decorator emit not enabled.');
|
|
12
11
|
}
|
|
13
12
|
return metadata;
|
|
14
13
|
}
|
|
@@ -53,7 +52,7 @@ export function appendMetaMethod(metadata, metaMethod) {
|
|
|
53
52
|
var _Object_getOwnPropertyDescriptor;
|
|
54
53
|
const own = (_Object_getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor(target, Symbol.metadata)) == null ? void 0 : _Object_getOwnPropertyDescriptor.value;
|
|
55
54
|
if (!own) {
|
|
56
|
-
throw new
|
|
55
|
+
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.`);
|
|
57
56
|
}
|
|
58
57
|
const existing = (_own_META_USE_CASE_KEY = own[META_USE_CASE_KEY]) != null ? _own_META_USE_CASE_KEY : [];
|
|
59
58
|
own[META_USE_CASE_KEY] = [
|
|
@@ -77,7 +76,7 @@ export function extractMetaEntity(target) {
|
|
|
77
76
|
const metadata = readMetadata(target);
|
|
78
77
|
const metaEntity = metadata == null ? void 0 : metadata[META_ENTITY_KEY];
|
|
79
78
|
if (!metaEntity) {
|
|
80
|
-
throw new
|
|
79
|
+
throw new Error(`MetaEntity not found for ${target.name}`);
|
|
81
80
|
}
|
|
82
81
|
return metaEntity;
|
|
83
82
|
}
|
|
@@ -107,7 +106,7 @@ export function extractMetaMethods(target) {
|
|
|
107
106
|
const metadata = target[Symbol.metadata];
|
|
108
107
|
const binding = metadata == null ? void 0 : metadata[META_USE_CASE_BINDING_KEY];
|
|
109
108
|
if (!binding) {
|
|
110
|
-
throw new
|
|
109
|
+
throw new Error(`MetaUseCase not found for ${target.name} — is it missing @useCase()?`);
|
|
111
110
|
}
|
|
112
111
|
return binding;
|
|
113
112
|
}
|
|
@@ -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 { EntifixBuildError } from '../../base-entities/entifix-error/index.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 EntifixBuildError(\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 EntifixBuildError(\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 EntifixBuildError(`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 EntifixBuildError(\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","EntifixBuildError","META_ENTITY_KEY","META_ACCESSOR_KEY","META_METHOD_KEY","META_USE_CASE_KEY","META_USE_CASE_BINDING_KEY","requireMetadata","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,Y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BAA0B;IAErD,IAAI,CAACoB,SAAS;QACZ,MAAM,IAAIzB,kBACR,CAAC,0BAA0B,EAAEgB,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 { 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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` members are left untouched: the to-many editor is a follow-up,
|
|
33
33
|
* and this is the branch where `setIds`/`setValues` will land.
|
|
34
34
|
*
|
|
35
|
-
* Throws
|
|
35
|
+
* Throws an `Error` when an `embedded` member holds an id with no
|
|
36
36
|
* instance to inline — see the branch below for why that is a fault and not a
|
|
37
37
|
* fallback.
|
|
38
38
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply-entity-links.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/apply-entity-links/apply-entity-links.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"apply-entity-links.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/apply-entity-links/apply-entity-links.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAY,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAmB,MAAM,+BAA+B,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAGhE;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAErE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,MAAM,EACrD,QAAQ,EAAE,OAAO,EACjB,WAAW,EAAE,SAAS,qBAAqB,EAAE,EAC7C,MAAM,EAAE,WAAW,EACnB,SAAS,GAAE,mBAAwB,GAClC,IAAI,CAgDN;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,MAAM,EAC5D,WAAW,EAAE,SAAS,qBAAqB,EAAE,EAC7C,MAAM,EAAE,OAAO,GAAG,SAAS,GAC1B,mBAAmB,CAgBrB"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EntifixLogicError } from '../../../base-entities/entifix-error/index.js';
|
|
2
1
|
import { readDraftString } from '../../../types/EntityDraft.js';
|
|
3
2
|
import { EntityLink } from '../entity-link/index.js';
|
|
4
3
|
/**
|
|
@@ -17,7 +16,7 @@ import { EntityLink } from '../entity-link/index.js';
|
|
|
17
16
|
* `linkCollection` members are left untouched: the to-many editor is a follow-up,
|
|
18
17
|
* and this is the branch where `setIds`/`setValues` will land.
|
|
19
18
|
*
|
|
20
|
-
* Throws
|
|
19
|
+
* Throws an `Error` when an `embedded` member holds an id with no
|
|
21
20
|
* instance to inline — see the branch below for why that is a fault and not a
|
|
22
21
|
* fallback.
|
|
23
22
|
*/ export function applyEntityLinks(instance, descriptors, values, selection = {}) {
|
|
@@ -46,10 +45,7 @@ import { EntityLink } from '../entity-link/index.js';
|
|
|
46
45
|
// degradation. The caller's job is to resolve the id first
|
|
47
46
|
// (`EntityLinkSource.selected.entity`) and hand the instance over.
|
|
48
47
|
if (descriptor.linkSerialization === 'embedded' && rawId !== '') {
|
|
49
|
-
throw new
|
|
50
|
-
member: descriptor.name,
|
|
51
|
-
id: rawId
|
|
52
|
-
});
|
|
48
|
+
throw new Error(`Cannot write "${descriptor.name}" as an embedded relation: the draft ` + 'holds an id but no instance. Resolve the id through the link ' + "source's `selected.entity` before submitting, or declare the " + "member `linkSerialization: 'id'`.");
|
|
53
49
|
}
|
|
54
50
|
link.setValue(undefined);
|
|
55
51
|
link.setId(rawId === '' ? undefined : rawId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/links/apply-entity-links/apply-entity-links.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/links/apply-entity-links/apply-entity-links.ts"],"sourcesContent":["import { Entity, EntityId } from '../../../types/Entity.js';\nimport { EntityDraft, readDraftString } from '../../../types/EntityDraft.js';\nimport { EntityFieldDescriptor } from '../../describe/index.js';\nimport { EntityLink } from '../entity-link/index.js';\n\n/**\n * The instances a user picked, keyed by accessor name — the sidecar to a form's\n * string draft.\n *\n * A draft holds ids because it must stay JSON (a workspace autosaves it), but an\n * id alone cannot be written as an embedded relation. So the picker remembers the\n * instance it handed over, and this map is that memory.\n *\n * It is a *cache*, and it is not persisted — it dies with the page, and a\n * restored draft arrives holding ids and nothing else. What refills it is\n * `EntityLinkSource.selected.entity`, which resolves the id the draft did keep.\n * For an `id` member a missing entry costs nothing; for an `embedded` one\n * {@link applyEntityLinks} throws rather than write the wrong wire shape.\n */\nexport type EntityLinkSelection = Record<string, Entity | undefined>;\n\n/**\n * Writes a draft's relations onto a freshly built entity, following each\n * member's declared {@link EntityFieldDescriptor.linkSerialization}.\n *\n * This is the counterpart to `serializeEntity`, which inlines a link whenever it\n * `isLoaded`: an `embedded` member therefore needs the picked instance handed to\n * `setValue`, while an `id` member must be given only the scalar even when the\n * instance is at hand — otherwise the wire shape would flip the moment a picker\n * happened to hold the target.\n *\n * Pure and framework-free, so the same reconstruction runs in a browser form and\n * in a backend use-case that assembles an entity from a raw draft.\n *\n * `linkCollection` members are left untouched: the to-many editor is a follow-up,\n * and this is the branch where `setIds`/`setValues` will land.\n *\n * Throws an `Error` when an `embedded` member holds an id with no\n * instance to inline — see the branch below for why that is a fault and not a\n * fallback.\n */\nexport function applyEntityLinks<TEntity extends Entity>(\n instance: TEntity,\n descriptors: readonly EntityFieldDescriptor[],\n values: EntityDraft,\n selection: EntityLinkSelection = {},\n): void {\n for (const descriptor of descriptors) {\n if (descriptor.type !== 'link') continue;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const link = (instance as any)[descriptor.name];\n // A link accessor is expected to be pre-initialized by the constructor. A\n // member typed `link` that is not one is a declaration mistake, not a value\n // to coerce — skipping keeps this helper from writing nonsense onto it.\n if (!(link instanceof EntityLink)) continue;\n\n const picked = selection[descriptor.name];\n // Read as a string rather than trusting the draft's `JsonValue`: a\n // relation's draft value is a foreign key, and a member that came back\n // from storage as anything else must read as absent rather than be cast\n // onto the link as an id.\n const rawId = readDraftString(values, descriptor.name);\n\n if (picked === undefined) {\n // An `embedded` member cannot be written from an id: `serializeEntity`\n // inlines whatever `isLoaded`, so falling through here would emit the `id`\n // shape onto a member the entity declares as inlined — silently, and\n // differently from the same save a moment earlier when the picker still\n // held the instance. The wire shape is metadata, not a function of what\n // the UI happens to have in memory, so this is a fault rather than a\n // degradation. The caller's job is to resolve the id first\n // (`EntityLinkSource.selected.entity`) and hand the instance over.\n if (descriptor.linkSerialization === 'embedded' && rawId !== '') {\n throw new Error(\n `Cannot write \"${descriptor.name}\" as an embedded relation: the draft ` +\n 'holds an id but no instance. Resolve the id through the link ' +\n \"source's `selected.entity` before submitting, or declare the \" +\n \"member `linkSerialization: 'id'`.\",\n );\n }\n link.setValue(undefined);\n link.setId(rawId === '' ? undefined : (rawId as EntityId));\n continue;\n }\n\n if (descriptor.linkSerialization === 'embedded') {\n link.setValue(picked);\n continue;\n }\n\n link.setValue(undefined);\n link.setId(picked.id ?? (rawId === '' ? undefined : (rawId as EntityId)));\n }\n}\n\n/**\n * Seeds a {@link EntityLinkSelection} from a record whose relations already\n * arrived materialized — an embedded payload, or a link a use-case resolved.\n *\n * It is what keeps opening a loaded record from re-fetching every relation label\n * the record already carries.\n */\nexport function seedEntityLinkSelection<TEntity extends Entity>(\n descriptors: readonly EntityFieldDescriptor[],\n entity: TEntity | undefined,\n): EntityLinkSelection {\n const selection: EntityLinkSelection = {};\n if (entity == null) return selection;\n\n // Only to-one links, for the same reason {@link applyEntityLinks} writes only\n // those: a collection's values are not a single selection.\n for (const descriptor of descriptors) {\n if (descriptor.type !== 'link') continue;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const link = (entity as any)[descriptor.name];\n if (link instanceof EntityLink && link.value !== undefined) {\n selection[descriptor.name] = link.value;\n }\n }\n\n return selection;\n}\n"],"names":["readDraftString","EntityLink","applyEntityLinks","instance","descriptors","values","selection","descriptor","picked","type","link","name","rawId","undefined","linkSerialization","Error","setValue","setId","id","seedEntityLinkSelection","entity","value"],"mappings":"AACA,SAAsBA,eAAe,QAAQ,gCAAgC;AAE7E,SAASC,U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AC;IACxC,IAAIc,UAAU,MAAM,OAAOd;IAE3B,8EAA8E;IAC9E,2DAA2D;IAC3D,KAAK,MAAMC,cAAcH,YAAa;QACpC,IAAIG,WAAWE,IAAI,KAAK,QAAQ;QAChC,8DAA8D;QAC9D,MAAMC,OAAO,AAACU,MAAc,CAACb,WAAWI,IAAI,CAAC;QAC7C,IAAID,gBAAgBT,cAAcS,KAAKW,KAAK,KAAKR,WAAW;YAC1DP,SAAS,CAACC,WAAWI,IAAI,CAAC,GAAGD,KAAKW,KAAK;QACzC;IACF;IAEA,OAAOf;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntifixFailure } from '../../../failure/failure.js';
|
|
3
3
|
import { Entity, EntityConstructor, EntityId } from '../../../types/Entity.js';
|
|
4
4
|
import { EntityLinkResolver } from '../entity-link/index.js';
|
|
5
5
|
export interface EntityCollectionLinkInit<TEntity extends Entity> {
|
|
@@ -20,8 +20,8 @@ export declare class EntityCollectionLink<TEntity extends Entity> {
|
|
|
20
20
|
/**
|
|
21
21
|
* Fetches every referenced target through the resolver and caches the result.
|
|
22
22
|
*/
|
|
23
|
-
reload(resolver: EntityLinkResolver): Effect.Effect<TEntity[],
|
|
24
|
-
resolve(resolver: EntityLinkResolver): Effect.Effect<TEntity[],
|
|
23
|
+
reload(resolver: EntityLinkResolver): Effect.Effect<TEntity[], EntifixFailure>;
|
|
24
|
+
resolve(resolver: EntityLinkResolver): Effect.Effect<TEntity[], EntifixFailure>;
|
|
25
25
|
get ids(): EntityId[];
|
|
26
26
|
get values(): TEntity[] | undefined;
|
|
27
27
|
get isLoaded(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-collection-link.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-collection-link/entity-collection-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"entity-collection-link.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-collection-link/entity-collection-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAC/E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D,MAAM,WAAW,wBAAwB,CAAC,OAAO,SAAS,MAAM;IAC9D,GAAG,CAAC,EAAE,QAAQ,EAAE,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,oBAAoB,CAAC,OAAO,SAAS,MAAM;;IAEtD,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBAOrD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,IAAI,CAAC,EAAE,wBAAwB,CAAC,OAAO,CAAC;IAc1C,MAAM,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI;IAI7B,SAAS,CAAC,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,GAAG,IAAI;IAS9C;;OAEG;IACH,MAAM,CACJ,QAAQ,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC;IAQ3C,OAAO,CACL,QAAQ,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,cAAc,CAAC;IAQ3C,IAAI,GAAG,IAAI,QAAQ,EAAE,CAEpB;IAED,IAAI,MAAM,IAAI,OAAO,EAAE,GAAG,SAAS,CAElC;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/links/entity-collection-link/entity-collection-link.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/links/entity-collection-link/entity-collection-link.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type { EntifixFailure } from '../../../failure/failure.js';\nimport { Entity, EntityConstructor, EntityId } from '../../../types/Entity.js';\nimport { EntityLinkResolver } from '../entity-link/index.js';\n\nexport interface EntityCollectionLinkInit<TEntity extends Entity> {\n ids?: EntityId[];\n values?: TEntity[];\n}\n\n/**\n * A one-to-many reference. Like {@link EntityLink} it accepts either foreign\n * keys (lazy, resolved through an {@link EntityLinkResolver}) or embedded\n * instances, but for a collection of targets.\n */\nexport class EntityCollectionLink<TEntity extends Entity> {\n // #region properties\n readonly entityConstructor: EntityConstructor<TEntity>;\n #ids: EntityId[];\n #values?: TEntity[];\n // #endregion\n\n // #region constructors\n constructor(\n entityConstructor: EntityConstructor<TEntity>,\n init?: EntityCollectionLinkInit<TEntity>,\n ) {\n this.entityConstructor = entityConstructor;\n this.#values = init?.values;\n this.#ids =\n init?.ids ??\n init?.values\n ?.map(value => value.id)\n .filter((id): id is EntityId => id != null) ??\n [];\n }\n // #endregion\n\n // #region methods\n setIds(ids: EntityId[]): void {\n this.#ids = ids;\n }\n\n setValues(values: TEntity[] | undefined): void {\n this.#values = values;\n if (values !== undefined) {\n this.#ids = values\n .map(value => value.id)\n .filter((id): id is EntityId => id != null);\n }\n }\n\n /**\n * Fetches every referenced target through the resolver and caches the result.\n */\n reload(\n resolver: EntityLinkResolver,\n ): Effect.Effect<TEntity[], EntifixFailure> {\n return Effect.forEach(\n this.#ids,\n id => resolver.resolve(this.entityConstructor, id),\n { concurrency: 'unbounded' },\n ).pipe(Effect.tap(values => Effect.sync(() => this.setValues(values))));\n }\n\n resolve(\n resolver: EntityLinkResolver,\n ): Effect.Effect<TEntity[], EntifixFailure> {\n return this.#values !== undefined\n ? Effect.succeed(this.#values)\n : this.reload(resolver);\n }\n // #endregion\n\n // #region accessors\n get ids(): EntityId[] {\n return this.#ids;\n }\n\n get values(): TEntity[] | undefined {\n return this.#values;\n }\n\n get isLoaded(): boolean {\n return this.#values !== undefined;\n }\n // #endregion\n}\n"],"names":["Effect","EntityCollectionLink","setIds","ids","setValues","values","undefined","map","value","id","filter","reload","resolver","forEach","resolve","entityConstructor","concurrency","pipe","tap","sync","succeed","isLoaded","init"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,SAAS;IAmB9B,6DACA;AATF;;;;CAIC,GACD,OAAO,MAAMC;IAqBX,aAAa;IAEb,kBAAkB;IAClBC,OAAOC,GAAe,EAAQ;QAC5B,gCAAA,IAAI,EAAC,MAAA,QAAOA;IACd;IAEAC,UAAUC,MAA6B,EAAQ;QAC7C,gCAAA,IAAI,EAAC,SAAA,WAAUA;QACf,IAAIA,WAAWC,WAAW;YACxB,gCAAA,IAAI,EAAC,MAAA,QAAOD,OACTE,GAAG,CAACC,CAAAA,QAASA,MAAMC,EAAE,EACrBC,MAAM,CAAC,CAACD,KAAuBA,MAAM;QAC1C;IACF;IAEA;;GAEC,GACDE,OACEC,QAA4B,EACc;QAC1C,OAAOZ,OAAOa,OAAO,CACnB,gCAAA,IAAI,EAAC,MAAA,OACLJ,CAAAA,KAAMG,SAASE,OAAO,CAAC,IAAI,CAACC,iBAAiB,EAAEN,KAC/C;YAAEO,aAAa;QAAY,GAC3BC,IAAI,CAACjB,OAAOkB,GAAG,CAACb,CAAAA,SAAUL,OAAOmB,IAAI,CAAC,IAAM,IAAI,CAACf,SAAS,CAACC;IAC/D;IAEAS,QACEF,QAA4B,EACc;QAC1C,OAAO,gCAAA,IAAI,EAAC,SAAA,aAAYN,YACpBN,OAAOoB,OAAO,CAAC,gCAAA,IAAI,EAAC,SAAA,YACpB,IAAI,CAACT,MAAM,CAACC;IAClB;IACA,aAAa;IAEb,oBAAoB;IACpB,IAAIT,MAAkB;QACpB,OAAO,gCAAA,IAAI,EAAC,MAAA;IACd;IAEA,IAAIE,SAAgC;QAClC,OAAO,gCAAA,IAAI,EAAC,SAAA;IACd;IAEA,IAAIgB,WAAoB;QACtB,OAAO,gCAAA,IAAI,EAAC,SAAA,aAAYf;IAC1B;IAjEA,aAAa;IAEb,uBAAuB;IACvB,YACES,iBAA6C,EAC7CO,IAAwC,CACxC;YAIEA;YACAA;QAbJ,4BAAA;;mBAAA,KAAA;;QACA,4BAAA;;mBAAA,KAAA;;QAQE,IAAI,CAACP,iBAAiB,GAAGA;QACzB,gCAAA,IAAI,EAAC,SAAA,WAAUO,wBAAAA,KAAMjB,MAAM;QAC3B,gCAAA,IAAI,EAAC,MAAA,SACHiB,gBAAAA,wBAAAA,KAAMnB,GAAG,oBACTmB,yBAAAA,eAAAA,KAAMjB,MAAM,qBAAZiB,aACIf,GAAG,CAACC,CAAAA,QAASA,MAAMC,EAAE,EACtBC,MAAM,CAAC,CAACD,KAAuBA,MAAM,iBAHxCa,OAIA,EAAE;IACN;AAoDF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import type {
|
|
2
|
+
import type { EntifixFailure } from '../../../failure/failure.js';
|
|
3
3
|
import { Entity, EntityConstructor, EntityId } from '../../../types/Entity.js';
|
|
4
4
|
/**
|
|
5
5
|
* Framework-free seam a link uses to materialize its target entity. The concrete
|
|
@@ -9,7 +9,7 @@ import { Entity, EntityConstructor, EntityId } from '../../../types/Entity.js';
|
|
|
9
9
|
* repository contracts defined in `@entifix/business`.
|
|
10
10
|
*/
|
|
11
11
|
export interface EntityLinkResolver {
|
|
12
|
-
resolve<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, id: EntityId): Effect.Effect<TEntity,
|
|
12
|
+
resolve<TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, id: EntityId): Effect.Effect<TEntity, EntifixFailure>;
|
|
13
13
|
}
|
|
14
14
|
export interface EntityLinkInit<TEntity extends Entity> {
|
|
15
15
|
id?: EntityId;
|
|
@@ -46,11 +46,11 @@ export declare class EntityLink<TEntity extends Entity> {
|
|
|
46
46
|
* hits the resolver — use {@link resolve} to fetch only when not already
|
|
47
47
|
* loaded.
|
|
48
48
|
*/
|
|
49
|
-
reload(resolver: EntityLinkResolver): Effect.Effect<TEntity,
|
|
49
|
+
reload(resolver: EntityLinkResolver): Effect.Effect<TEntity, EntifixFailure>;
|
|
50
50
|
/**
|
|
51
51
|
* Returns the cached target if present, otherwise reloads it once.
|
|
52
52
|
*/
|
|
53
|
-
resolve(resolver: EntityLinkResolver): Effect.Effect<TEntity,
|
|
53
|
+
resolve(resolver: EntityLinkResolver): Effect.Effect<TEntity, EntifixFailure>;
|
|
54
54
|
get id(): EntityId;
|
|
55
55
|
get value(): TEntity | undefined;
|
|
56
56
|
get isLoaded(): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-link.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-link/entity-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"entity-link.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-link/entity-link.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAE/E;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,OAAO,CAAC,OAAO,SAAS,MAAM,EAC5B,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,EAAE,EAAE,QAAQ,GACX,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,MAAM;IACpD,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,UAAU,CAAC,OAAO,SAAS,MAAM;;IAE5C,QAAQ,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;gBAOrD,iBAAiB,EAAE,iBAAiB,CAAC,OAAO,CAAC,EAC7C,IAAI,CAAC,EAAE,cAAc,CAAC,OAAO,CAAC;IAYhC;;OAEG;IACH,KAAK,CAAC,EAAE,EAAE,QAAQ,GAAG,IAAI;IAIzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,IAAI;IAO1C;;;;OAIG;IACH,MAAM,CAAC,QAAQ,EAAE,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC;IAM5E;;OAEG;IACH,OAAO,CACL,QAAQ,EAAE,kBAAkB,GAC3B,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC;IAQzC,IAAI,EAAE,IAAI,QAAQ,CAEjB;IAED,IAAI,KAAK,IAAI,OAAO,GAAG,SAAS,CAE/B;IAED,IAAI,QAAQ,IAAI,OAAO,CAEtB;CAEF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/links/entity-link/entity-link.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/links/entity-link/entity-link.ts"],"sourcesContent":["import { Effect } from 'effect';\n\nimport type { EntifixFailure } from '../../../failure/failure.js';\nimport { Entity, EntityConstructor, EntityId } from '../../../types/Entity.js';\n\n/**\n * Framework-free seam a link uses to materialize its target entity. The concrete\n * implementation lives at the composition root (a REST-backed resolver on the\n * web, a Mongo-backed one on the backend) and is injected through Effect's\n * context. Keeping the interface in `core` avoids an upward dependency on the\n * repository contracts defined in `@entifix/business`.\n */\nexport interface EntityLinkResolver {\n resolve<TEntity extends Entity>(\n entityConstructor: EntityConstructor<TEntity>,\n id: EntityId,\n ): Effect.Effect<TEntity, EntifixFailure>;\n}\n\nexport interface EntityLinkInit<TEntity extends Entity> {\n id?: EntityId;\n value?: TEntity;\n}\n\n/**\n * A reference from one entity to another. It models both shapes a raw payload\n * can carry for a relation:\n *\n * - a **foreign key** — only the target id is known, so the entity is fetched\n * lazily through {@link reload};\n * - **embedded data** — the target already arrived inline and was deserialized\n * into an instance, so {@link value} is populated and no fetch is needed.\n *\n * Resolution is expressed as an `Effect`, so the same link works in any\n * environment: the caller provides an {@link EntityLinkResolver} backed by\n * whatever adapter (REST, Mongo, …) fits the runtime.\n */\nexport class EntityLink<TEntity extends Entity> {\n // #region properties\n readonly entityConstructor: EntityConstructor<TEntity>;\n #id: EntityId;\n #value?: TEntity;\n // #endregion\n\n // #region constructors\n constructor(\n entityConstructor: EntityConstructor<TEntity>,\n init?: EntityLinkInit<TEntity>,\n ) {\n this.entityConstructor = entityConstructor;\n this.#id = init?.id;\n this.#value = init?.value;\n if (this.#value !== undefined && this.#id == null) {\n this.#id = this.#value.id;\n }\n }\n // #endregion\n\n // #region methods\n /**\n * Records the foreign key when the payload only referenced the target by id.\n */\n setId(id: EntityId): void {\n this.#id = id;\n }\n\n /**\n * Stores an already-materialized target (embedded payload or a completed\n * reload) and keeps the id in sync with it.\n */\n setValue(value: TEntity | undefined): void {\n this.#value = value;\n if (value !== undefined && value.id != null) {\n this.#id = value.id;\n }\n }\n\n /**\n * Fetches the target through the resolver and caches it on the link. Always\n * hits the resolver — use {@link resolve} to fetch only when not already\n * loaded.\n */\n reload(resolver: EntityLinkResolver): Effect.Effect<TEntity, EntifixFailure> {\n return resolver\n .resolve(this.entityConstructor, this.#id)\n .pipe(Effect.tap(value => Effect.sync(() => this.setValue(value))));\n }\n\n /**\n * Returns the cached target if present, otherwise reloads it once.\n */\n resolve(\n resolver: EntityLinkResolver,\n ): Effect.Effect<TEntity, EntifixFailure> {\n return this.#value !== undefined\n ? Effect.succeed(this.#value)\n : this.reload(resolver);\n }\n // #endregion\n\n // #region accessors\n get id(): EntityId {\n return this.#id ?? this.#value?.id;\n }\n\n get value(): TEntity | undefined {\n return this.#value;\n }\n\n get isLoaded(): boolean {\n return this.#value !== undefined;\n }\n // #endregion\n}\n"],"names":["Effect","EntityLink","setId","id","setValue","value","undefined","reload","resolver","resolve","entityConstructor","pipe","tap","sync","succeed","isLoaded","init"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,SAAS;IAwC9B,2DACA;AAjBF;;;;;;;;;;;;CAYC,GACD,OAAO,MAAMC;IAmBX,aAAa;IAEb,kBAAkB;IAClB;;GAEC,GACDC,MAAMC,EAAY,EAAQ;QACxB,gCAAA,IAAI,EAAC,KAAA,OAAMA;IACb;IAEA;;;GAGC,GACDC,SAASC,KAA0B,EAAQ;QACzC,gCAAA,IAAI,EAAC,QAAA,UAASA;QACd,IAAIA,UAAUC,aAAaD,MAAMF,EAAE,IAAI,MAAM;YAC3C,gCAAA,IAAI,EAAC,KAAA,OAAME,MAAMF,EAAE;QACrB;IACF;IAEA;;;;GAIC,GACDI,OAAOC,QAA4B,EAA0C;QAC3E,OAAOA,SACJC,OAAO,CAAC,IAAI,CAACC,iBAAiB,EAAE,gCAAA,IAAI,EAAC,KAAA,MACrCC,IAAI,CAACX,OAAOY,GAAG,CAACP,CAAAA,QAASL,OAAOa,IAAI,CAAC,IAAM,IAAI,CAACT,QAAQ,CAACC;IAC9D;IAEA;;GAEC,GACDI,QACED,QAA4B,EACY;QACxC,OAAO,gCAAA,IAAI,EAAC,QAAA,YAAWF,YACnBN,OAAOc,OAAO,CAAC,gCAAA,IAAI,EAAC,QAAA,WACpB,IAAI,CAACP,MAAM,CAACC;IAClB;IACA,aAAa;IAEb,oBAAoB;IACpB,IAAIL,KAAe;;;QACjB,8CAAO,gCAAA,IAAI,EAAC,KAAA,gGAAO,gCAAA,IAAI,EAAC,QAAA,4BAAL,uCAAaA,EAAE;IACpC;IAEA,IAAIE,QAA6B;QAC/B,OAAO,gCAAA,IAAI,EAAC,QAAA;IACd;IAEA,IAAIU,WAAoB;QACtB,OAAO,gCAAA,IAAI,EAAC,QAAA,YAAWT;IACzB;IArEA,aAAa;IAEb,uBAAuB;IACvB,YACEI,iBAA6C,EAC7CM,IAA8B,CAC9B;QARF,4BAAA;;mBAAA,KAAA;;QACA,4BAAA;;mBAAA,KAAA;;QAQE,IAAI,CAACN,iBAAiB,GAAGA;QACzB,gCAAA,IAAI,EAAC,KAAA,OAAMM,wBAAAA,KAAMb,EAAE;QACnB,gCAAA,IAAI,EAAC,QAAA,UAASa,wBAAAA,KAAMX,KAAK;QACzB,IAAI,gCAAA,IAAI,EAAC,QAAA,YAAWC,aAAa,gCAAA,IAAI,EAAC,KAAA,QAAO,MAAM;YACjD,gCAAA,IAAI,EAAC,KAAA,OAAM,gCAAA,IAAI,EAAC,QAAA,QAAOH,EAAE;QAC3B;IACF;AA0DF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntifixFailure } from '../../../failure/failure.js';
|
|
2
2
|
import { Entity, EntityConstructor } from '../../../types/Entity.js';
|
|
3
3
|
import { FilterGroup } from '../../../types/EntityFiltering.js';
|
|
4
4
|
import { EntitySorting } from '../../../types/EntitySorting.js';
|
|
@@ -18,7 +18,7 @@ export interface EntityLinkListView<TEntity extends Entity> {
|
|
|
18
18
|
currentPage: number;
|
|
19
19
|
pageSize: number;
|
|
20
20
|
isLoading: boolean;
|
|
21
|
-
error?:
|
|
21
|
+
error?: EntifixFailure;
|
|
22
22
|
filtering?: FilterGroup<TEntity>;
|
|
23
23
|
sorting?: EntitySorting<TEntity>;
|
|
24
24
|
onPageChange: (page: number) => void;
|
|
@@ -32,7 +32,7 @@ export interface EntityLinkQuickSearch<TEntity extends Entity> {
|
|
|
32
32
|
setTerm: (term: string) => void;
|
|
33
33
|
options: ReadonlyArray<TEntity>;
|
|
34
34
|
isLoading: boolean;
|
|
35
|
-
error?:
|
|
35
|
+
error?: EntifixFailure;
|
|
36
36
|
}
|
|
37
37
|
/** The browse half: the full list view, plus the dialog holding it. */
|
|
38
38
|
export interface EntityLinkBrowse<TEntity extends Entity> extends EntityLinkListView<TEntity> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity-link-source.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-link-source/entity-link-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"entity-link-source.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/entity-link-source/entity-link-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChE,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEhE;;;;;;;;;GASG;AACH,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,MAAM;IACxD,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,SAAS,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;IACjC,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAA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["import type {
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/links/entity-link-source/entity-link-source.ts"],"sourcesContent":["import type { EntifixFailure } from '../../../failure/failure.js';\nimport { Entity, EntityConstructor } from '../../../types/Entity.js';\nimport { FilterGroup } from '../../../types/EntityFiltering.js';\nimport { EntitySorting } from '../../../types/EntitySorting.js';\n\n/**\n * A paged, filterable list of link targets, expressed as state plus the commands\n * that change it.\n *\n * The member names match what a table already renders from, so a browse dialog\n * forwards this object through untouched. It carries no Effect and no React: the\n * hook that produces it lives in the integration layer, the components that\n * consume it in the controls layer, and those two may not import each other —\n * this contract in `core` is what lets them meet.\n */\nexport interface EntityLinkListView<TEntity extends Entity> {\n items: ReadonlyArray<TEntity>;\n totalItems: number;\n currentPage: number;\n pageSize: number;\n isLoading: boolean;\n error?: EntifixFailure;\n filtering?: FilterGroup<TEntity>;\n sorting?: EntitySorting<TEntity>;\n onPageChange: (page: number) => void;\n onPageSizeChange: (pageSize: number) => void;\n onFilteringChange: (filtering: FilterGroup<TEntity>) => void;\n onSortingChange: (sorting: EntitySorting<TEntity>) => void;\n}\n\n/** The quick half: a term, and the short list of matches it produces. */\nexport interface EntityLinkQuickSearch<TEntity extends Entity> {\n term: string;\n setTerm: (term: string) => void;\n options: ReadonlyArray<TEntity>;\n isLoading: boolean;\n error?: EntifixFailure;\n}\n\n/** The browse half: the full list view, plus the dialog holding it. */\nexport interface EntityLinkBrowse<\n TEntity extends Entity,\n> extends EntityLinkListView<TEntity> {\n isOpen: boolean;\n open: () => void;\n close: () => void;\n}\n\n/**\n * Everything an editor needs in order to set one relation, and nothing about how\n * the targets are fetched.\n *\n * Two ways in, because they answer different questions: {@link quick} is\n * \"I know roughly what it is called\", {@link browse} is \"I need to look at the\n * catalog and filter it\". {@link selected} is the third, quieter one — a draft\n * restored from storage holds an id and no instance, and an id is not a name.\n */\nexport interface EntityLinkSource<TEntity extends Entity> {\n entityConstructor: EntityConstructor<TEntity>;\n /** Reads a target's display label, per the owner's `linkLabelProperty`. */\n labelOf: (entity: TEntity) => string;\n /**\n * The currently held id, resolved into something a form can use.\n *\n * `entity` is the whole target, not just its name, and that matters: a draft\n * restored from storage holds ids only, so the instance a `linkSerialization:\n * 'embedded'` member needs at submit is gone. Resolving the id was already\n * happening for the label — carrying the instance out is what lets the form\n * rehydrate its selection instead of quietly writing the `id` shape onto an\n * `embedded` member.\n */\n selected: { label?: string; entity?: TEntity; isLoading: boolean };\n quick: EntityLinkQuickSearch<TEntity>;\n browse: EntityLinkBrowse<TEntity>;\n}\n"],"names":[],"mappings":"AAgDA;;;;;;;;CAQC,GACD,WAiBC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link-targets.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/link-targets/link-targets.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"link-targets.d.ts","sourceRoot":"","sources":["../../../../src/entity-definition/links/link-targets/link-targets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,OAAO,SAAS,MAAM,EAC7C,IAAI,EAAE,UAAU,CAAC,OAAO,CAAC,GACxB,OAAO,CAQT;AAED,6DAA6D;AAC7D,wBAAgB,SAAS,CAAC,OAAO,SAAS,MAAM,EAC9C,KAAK,EAAE,oBAAoB,CAAC,OAAO,CAAC,GACnC,OAAO,EAAE,CAQX"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EntifixLogicError } from '../../../base-entities/entifix-error/index.js';
|
|
2
1
|
/**
|
|
3
2
|
* The record a resolved link names, read without a cast.
|
|
4
3
|
*
|
|
@@ -9,14 +8,14 @@ import { EntifixLogicError } from '../../../base-entities/entifix-error/index.js
|
|
|
9
8
|
*/ export function targetOf(link) {
|
|
10
9
|
const { value } = link;
|
|
11
10
|
if (value === undefined) {
|
|
12
|
-
throw new
|
|
11
|
+
throw new Error(`The link to ${link.entityConstructor.name} ${String(link.id)} was read before it was resolved`);
|
|
13
12
|
}
|
|
14
13
|
return value;
|
|
15
14
|
}
|
|
16
15
|
/** The records a resolved collection names, in its order. */ export function targetsOf(links) {
|
|
17
16
|
const { values } = links;
|
|
18
17
|
if (values === undefined) {
|
|
19
|
-
throw new
|
|
18
|
+
throw new Error(`The links to ${links.entityConstructor.name} were read before they were resolved`);
|
|
20
19
|
}
|
|
21
20
|
return values;
|
|
22
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/entity-definition/links/link-targets/link-targets.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/entity-definition/links/link-targets/link-targets.ts"],"sourcesContent":["import { Entity } from '../../../types/Entity.js';\nimport { EntityCollectionLink } from '../entity-collection-link/index.js';\nimport { EntityLink } from '../entity-link/index.js';\n\n/**\n * The record a resolved link names, read without a cast.\n *\n * `value` is `undefined` until the link is resolved, so reading it means a\n * non-null assertion at every call site. This reads it once, and a link\n * nothing resolved fails here, naming it, rather than as an `undefined` deep\n * in a render.\n */\nexport function targetOf<TEntity extends Entity>(\n link: EntityLink<TEntity>,\n): TEntity {\n const { value } = link;\n if (value === undefined) {\n throw new Error(\n `The link to ${link.entityConstructor.name} ${String(link.id)} was read before it was resolved`,\n );\n }\n return value;\n}\n\n/** The records a resolved collection names, in its order. */\nexport function targetsOf<TEntity extends Entity>(\n links: EntityCollectionLink<TEntity>,\n): TEntity[] {\n const { values } = links;\n if (values === undefined) {\n throw new Error(\n `The links to ${links.entityConstructor.name} were read before they were resolved`,\n );\n }\n return values;\n}\n"],"names":["targetOf","link","value","undefined","Error","entityConstructor","name","String","id","targetsOf","links","values"],"mappings":"AAIA;;;;;;;CAOC,GACD,OAAO,SAASA,SACdC,IAAyB;IAEzB,MAAM,EAAEC,KAAK,EAAE,GAAGD;IAClB,IAAIC,UAAUC,WAAW;QACvB,MAAM,IAAIC,MACR,CAAC,YAAY,EAAEH,KAAKI,iBAAiB,CAACC,IAAI,CAAC,CAAC,EAAEC,OAAON,KAAKO,EAAE,EAAE,gCAAgC,CAAC;IAEnG;IACA,OAAON;AACT;AAEA,2DAA2D,GAC3D,OAAO,SAASO,UACdC,KAAoC;IAEpC,MAAM,EAAEC,MAAM,EAAE,GAAGD;IACnB,IAAIC,WAAWR,WAAW;QACxB,MAAM,IAAIC,MACR,CAAC,aAAa,EAAEM,MAAML,iBAAiB,CAACC,IAAI,CAAC,oCAAoC,CAAC;IAEtF;IACA,OAAOK;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/meta-entities/bounds.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bounds.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/meta-entities/bounds.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;IAAE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,GACnE,IAAI,CAgBN"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { EntifixBuildError } from '../../base-entities/entifix-error/index.js';
|
|
2
1
|
const isCount = (value)=>value === undefined || Number.isInteger(value) && value >= 0;
|
|
3
2
|
/**
|
|
4
3
|
* A count option that cannot be honoured is a declaration error, thrown when
|
|
@@ -7,10 +6,10 @@ const isCount = (value)=>value === undefined || Number.isInteger(value) && value
|
|
|
7
6
|
*/ export function assertBounds(owner, bounds) {
|
|
8
7
|
if (bounds === undefined) return;
|
|
9
8
|
if (!isCount(bounds.min) || !isCount(bounds.max)) {
|
|
10
|
-
throw new
|
|
9
|
+
throw new Error(`${owner} declares a count that is not a whole number of zero or more.`);
|
|
11
10
|
}
|
|
12
11
|
if (bounds.min !== undefined && bounds.max !== undefined && bounds.min > bounds.max) {
|
|
13
|
-
throw new
|
|
12
|
+
throw new Error(`${owner} declares a minimum of ${bounds.min} above its maximum of ${bounds.max}.`);
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/entity-definition/meta-entities/bounds.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/entity-definition/meta-entities/bounds.ts"],"sourcesContent":["const isCount = (value: number | undefined) =>\n value === undefined || (Number.isInteger(value) && value >= 0);\n\n/**\n * A count option that cannot be honoured is a declaration error, thrown when\n * the class is decorated rather than the first time a set of records is\n * checked.\n */\nexport function assertBounds(\n owner: string,\n bounds: { readonly min?: number; readonly max?: number } | undefined,\n): void {\n if (bounds === undefined) return;\n if (!isCount(bounds.min) || !isCount(bounds.max)) {\n throw new Error(\n `${owner} declares a count that is not a whole number of zero or more.`,\n );\n }\n if (\n bounds.min !== undefined &&\n bounds.max !== undefined &&\n bounds.min > bounds.max\n ) {\n throw new Error(\n `${owner} declares a minimum of ${bounds.min} above its maximum of ${bounds.max}.`,\n );\n }\n}\n"],"names":["isCount","value","undefined","Number","isInteger","assertBounds","owner","bounds","min","max","Error"],"mappings":"AAAA,MAAMA,UAAU,CAACC,QACfA,UAAUC,aAAcC,OAAOC,SAAS,CAACH,UAAUA,SAAS;AAE9D;;;;CAIC,GACD,OAAO,SAASI,aACdC,KAAa,EACbC,MAAoE;IAEpE,IAAIA,WAAWL,WAAW;IAC1B,IAAI,CAACF,QAAQO,OAAOC,GAAG,KAAK,CAACR,QAAQO,OAAOE,GAAG,GAAG;QAChD,MAAM,IAAIC,MACR,GAAGJ,MAAM,6DAA6D,CAAC;IAE3E;IACA,IACEC,OAAOC,GAAG,KAAKN,aACfK,OAAOE,GAAG,KAAKP,aACfK,OAAOC,GAAG,GAAGD,OAAOE,GAAG,EACvB;QACA,MAAM,IAAIC,MACR,GAAGJ,MAAM,uBAAuB,EAAEC,OAAOC,GAAG,CAAC,sBAAsB,EAAED,OAAOE,GAAG,CAAC,CAAC,CAAC;IAEtF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import {
|
|
2
|
+
import { ProtocolFailure } from '../../failure/generic.js';
|
|
3
3
|
import { Entity, EntityConstructor } from '../../types/Entity.js';
|
|
4
4
|
/**
|
|
5
5
|
* Result of deserializing a value against an entity constructor. A value can be
|
|
@@ -7,7 +7,7 @@ import { Entity, EntityConstructor } from '../../types/Entity.js';
|
|
|
7
7
|
* array of those — which lets collections recurse into arrays of arrays.
|
|
8
8
|
*/
|
|
9
9
|
type DeserializedEntity<TEntity extends Entity> = TEntity | undefined | DeserializedEntity<TEntity>[];
|
|
10
|
-
export declare const deserializeSingleEntity: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, entityData: unknown) => Effect.Effect<TEntity | undefined,
|
|
11
|
-
export declare const deserializeEntityCollection: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, entityCollectionData: unknown, failOnNull?: boolean) => Effect.Effect<DeserializedEntity<TEntity>[],
|
|
10
|
+
export declare const deserializeSingleEntity: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, entityData: unknown) => Effect.Effect<TEntity | undefined, ProtocolFailure, never>;
|
|
11
|
+
export declare const deserializeEntityCollection: <TEntity extends Entity>(entityConstructor: EntityConstructor<TEntity>, entityCollectionData: unknown, failOnNull?: boolean) => Effect.Effect<DeserializedEntity<TEntity>[], ProtocolFailure, never>;
|
|
12
12
|
export {};
|
|
13
13
|
//# sourceMappingURL=deserialize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/serializer/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"deserialize.d.ts","sourceRoot":"","sources":["../../../src/entity-definition/serializer/deserialize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAY,MAAM,uBAAuB,CAAC;AAK5E;;;;GAIG;AACH,KAAK,kBAAkB,CAAC,OAAO,SAAS,MAAM,IAC5C,OAAO,GAAG,SAAS,GAAG,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;AAsMtD,eAAO,MAAM,uBAAuB,GAAI,OAAO,SAAS,MAAM,EAC5D,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,YAAY,OAAO,+DAOjB,CAAC;AAEL,eAAO,MAAM,2BAA2B,GAAI,OAAO,SAAS,MAAM,EAChE,mBAAmB,iBAAiB,CAAC,OAAO,CAAC,EAC7C,sBAAsB,OAAO,EAC7B,oBAAkB,yEAYhB,CAAC"}
|
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import {
|
|
2
|
+
import { ProtocolFailure } from '../../failure/generic.js';
|
|
3
|
+
import { messageOf } from '../../failure/predicates.js';
|
|
3
4
|
import { extractMetaAccessors } from '../helpers/index.js';
|
|
4
5
|
import { EntityCollectionLink } from '../links/entity-collection-link/index.js';
|
|
5
6
|
import { EntityLink } from '../links/entity-link/index.js';
|
|
6
7
|
//#region Validations
|
|
7
8
|
function assertEntityObject(entityConstructor, entityData) {
|
|
8
9
|
if (typeof entityData !== 'object') {
|
|
9
|
-
throw new
|
|
10
|
-
entityData,
|
|
11
|
-
entityConstructor: entityConstructor.name
|
|
12
|
-
});
|
|
10
|
+
throw new Error(`Failed to deserialize entity of type ${entityConstructor.name}. Expected an object but got ${typeof entityData}`);
|
|
13
11
|
}
|
|
14
12
|
}
|
|
15
13
|
function assertEntityCollection(entityConstructor, entityCollectionData) {
|
|
16
14
|
if (!Array.isArray(entityCollectionData)) {
|
|
17
|
-
throw new
|
|
18
|
-
entityCollectionData,
|
|
19
|
-
entityConstructor: entityConstructor.name
|
|
20
|
-
});
|
|
15
|
+
throw new Error(`Failed to deserialize entity collection of type ${entityConstructor.name}. Expected an array but got ${typeof entityCollectionData}`);
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
18
|
//#endregion
|
|
@@ -126,20 +121,18 @@ function deserializeCollection(entityConstructor, entityCollectionData, failOnNu
|
|
|
126
121
|
}
|
|
127
122
|
//#endregion
|
|
128
123
|
//#region Effect factories
|
|
129
|
-
|
|
124
|
+
// A record that does not build is a peer answering something unreadable: a
|
|
125
|
+
// stored row or a served body that does not match the entity.
|
|
126
|
+
const unreadable = (message)=>(error)=>new ProtocolFailure({
|
|
127
|
+
reason: `${message}: ${messageOf(error)}`
|
|
128
|
+
});
|
|
130
129
|
export const deserializeSingleEntity = (entityConstructor, entityData)=>Effect.try({
|
|
131
130
|
try: ()=>deserializeEntity(entityConstructor, entityData),
|
|
132
|
-
catch:
|
|
133
|
-
entityData,
|
|
134
|
-
entityConstructor: entityConstructor.name
|
|
135
|
-
})
|
|
131
|
+
catch: unreadable(`Failed to deserialize entity of type ${entityConstructor.name}`)
|
|
136
132
|
});
|
|
137
133
|
export const deserializeEntityCollection = (entityConstructor, entityCollectionData, failOnNull = false)=>Effect.try({
|
|
138
134
|
try: ()=>deserializeCollection(entityConstructor, entityCollectionData, failOnNull),
|
|
139
|
-
catch:
|
|
140
|
-
entityCollectionData,
|
|
141
|
-
entityConstructor: entityConstructor.name
|
|
142
|
-
})
|
|
135
|
+
catch: unreadable(`Failed to deserialize entity collection of type ${entityConstructor.name}`)
|
|
143
136
|
}); //#endregion
|
|
144
137
|
|
|
145
138
|
//# sourceMappingURL=deserialize.js.map
|