foldkit-entity 0.16.0 → 0.18.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/README.md +582 -240
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +30 -4
- package/dist/conformance/index.js.map +1 -1
- package/dist/conformance/operator.d.ts.map +1 -1
- package/dist/conformance/operator.js +13 -4
- package/dist/conformance/operator.js.map +1 -1
- package/dist/descriptor.d.ts +5 -1
- package/dist/descriptor.d.ts.map +1 -1
- package/dist/descriptor.js +6 -2
- package/dist/descriptor.js.map +1 -1
- package/dist/entity.d.ts +16 -3
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +44 -14
- package/dist/entity.js.map +1 -1
- package/dist/enumerate.d.ts +44 -0
- package/dist/enumerate.d.ts.map +1 -0
- package/dist/enumerate.js +128 -0
- package/dist/enumerate.js.map +1 -0
- package/dist/evaluate.d.ts +12 -6
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +48 -23
- package/dist/evaluate.js.map +1 -1
- package/dist/expr.d.ts +78 -22
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +86 -57
- package/dist/expr.js.map +1 -1
- package/dist/footprint.d.ts +120 -0
- package/dist/footprint.d.ts.map +1 -0
- package/dist/footprint.js +41 -0
- package/dist/footprint.js.map +1 -0
- package/dist/held.js +11 -3
- package/dist/held.js.map +1 -1
- package/dist/index.d.ts +24 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -6
- package/dist/index.js.map +1 -1
- package/dist/invariant.d.ts +41 -11
- package/dist/invariant.d.ts.map +1 -1
- package/dist/invariant.js +102 -51
- package/dist/invariant.js.map +1 -1
- package/dist/law.d.ts.map +1 -1
- package/dist/law.js +3 -9
- package/dist/law.js.map +1 -1
- package/dist/lawCore.d.ts +42 -0
- package/dist/lawCore.d.ts.map +1 -0
- package/dist/lawCore.js +12 -0
- package/dist/lawCore.js.map +1 -0
- package/dist/lawIds.d.ts +15 -0
- package/dist/lawIds.d.ts.map +1 -0
- package/dist/lawIds.js +13 -0
- package/dist/lawIds.js.map +1 -0
- package/dist/laws.d.ts +308 -0
- package/dist/laws.d.ts.map +1 -0
- package/dist/laws.js +566 -0
- package/dist/laws.js.map +1 -0
- package/dist/memoryTable.d.ts +11 -0
- package/dist/memoryTable.d.ts.map +1 -0
- package/dist/memoryTable.js +69 -0
- package/dist/memoryTable.js.map +1 -0
- package/dist/operators.d.ts +1 -1
- package/dist/operators.d.ts.map +1 -1
- package/dist/operators.js +2 -66
- package/dist/operators.js.map +1 -1
- package/dist/refine.d.ts +64 -0
- package/dist/refine.d.ts.map +1 -0
- package/dist/refine.js +104 -0
- package/dist/refine.js.map +1 -0
- package/dist/rows.d.ts +15 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +23 -0
- package/dist/rows.js.map +1 -0
- package/dist/sets.js.map +1 -1
- package/dist/uncollated.d.ts +10 -0
- package/dist/uncollated.d.ts.map +1 -0
- package/dist/uncollated.js +18 -0
- package/dist/uncollated.js.map +1 -0
- package/dist/write.d.ts +65 -7
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +128 -30
- package/dist/write.js.map +1 -1
- package/package.json +3 -3
package/dist/descriptor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"descriptor.js","names":[],"sources":["../src/descriptor.ts"],"sourcesContent":["/**\n * What makes an Entity descriptor: its parts, the members every descriptor of\n * one Entity shares, and making a new descriptor from them. Apart from the\n * `Entity` namespace, so an invariant attaches itself without importing it.\n */\nimport { Option, Pipeable, type Schema } from 'effect'\nimport { Metadata } from 'foldkit-metadata'\nimport { EntityTypeId } from './ids.js'\nimport type { AnyEntity, EntityIdentity, EntityMember } from './index.js'\nimport { own, put } from './record.js'\nimport type { EntitySet } from './sets.js'\nimport { variantsOf } from './variants.js'\n\n/**\n * What every descriptor of one Entity shares: the members `Entity.relate`,\n * `Entity.derived` and `Entity.sets` add. It belongs to the identity, so a\n *
|
|
1
|
+
{"version":3,"file":"descriptor.js","names":[],"sources":["../src/descriptor.ts"],"sourcesContent":["/**\n * What makes an Entity descriptor: its parts, the members every descriptor of\n * one Entity shares, and making a new descriptor from them. Apart from the\n * `Entity` namespace, so an invariant attaches itself without importing it.\n */\nimport { Option, Pipeable, type Schema } from 'effect'\nimport { Metadata } from 'foldkit-metadata'\nimport { EntityTypeId } from './ids.js'\nimport type { AnyEntity, EntityIdentity, EntityMember } from './index.js'\nimport type { Invariant } from './invariant.js'\nimport { own, put } from './record.js'\nimport type { EntitySet } from './sets.js'\nimport { variantsOf } from './variants.js'\n\n/**\n * What every descriptor of one Entity shares: the members `Entity.relate`,\n * `Entity.derived` and `Entity.sets` add, and the invariants\n * `Entity.invariant` declares. It belongs to the identity, so a member added\n * through one descriptor is a member of every other, the one a relation's\n * `target()` returns and the one declared before `relate` alike. An invariant\n * is a fact about the stored row, so no descriptor may judge without it (#539).\n */\ninterface Shape {\n readonly relations: Record<string, EntityMember>\n readonly derived: Record<string, EntityMember>\n readonly sets: Record<string, EntitySet>\n /**\n * In the order they were declared. Replaced, never changed, so a reader that\n * kept it (a binding compiling its checks) keeps what it compiled.\n */\n invariants: ReadonlyArray<Invariant>\n /** Moves with every addition, so a descriptor knows when its view is stale. */\n revision: number\n}\n\nconst shapes = new WeakMap<EntityIdentity<string>, Shape>()\n\nconst shapeOf = (identity: EntityIdentity<string>): Shape => {\n const known = shapes.get(identity)\n if (known !== undefined) return known\n const shape: Shape = { relations: {}, derived: {}, sets: {}, invariants: [], revision: 0 }\n shapes.set(identity, shape)\n return shape\n}\n\n/** What one descriptor holds of its own: its fields, and the metadata annotated on it. */\ninterface Parts {\n readonly identity: EntityIdentity<string>\n readonly schema: Schema.Struct<Schema.Struct.Fields>\n readonly fields: Readonly<Record<string, EntityMember>>\n /** Metadata `annotateMembers` gave this descriptor's relations and derived members, by key. */\n readonly annotated: Readonly<Record<string, Metadata>>\n readonly metadata: Metadata\n}\n\nexport const partsOf = new WeakMap<AnyEntity, Parts>()\n\nconst EntityProto = {\n [EntityTypeId]: EntityTypeId,\n pipe() {\n return Pipeable.pipeArguments(this, arguments)\n },\n}\n\nexport const make = (parts: Parts): AnyEntity => {\n const shape = shapeOf(parts.identity)\n const fields = Object.freeze(parts.fields)\n // A shared member annotated here is a copy, made once, so it keeps its identity across reads.\n const copies = new WeakMap<EntityMember, EntityMember>()\n const annotate = (members: Readonly<Record<string, EntityMember>>) =>\n Object.freeze(\n mapValues(members, (member, key) => {\n const extra = own(parts.annotated, key)\n if (extra === undefined) return member\n const copied = copies.get(member)\n if (copied !== undefined) return copied\n const copy = Object.freeze({\n ...member,\n metadata: Metadata.combine([member.metadata, extra]),\n })\n copies.set(member, copy)\n return copy\n }),\n )\n let seen = -1\n let view: {\n readonly relations: Readonly<Record<string, EntityMember>>\n readonly derived: Readonly<Record<string, EntityMember>>\n readonly sets: Readonly<Record<string, EntitySet>>\n readonly members: Readonly<Record<string, EntityMember>>\n }\n const current = () => {\n if (seen !== shape.revision) {\n const relations = annotate(shape.relations)\n const derived = annotate(shape.derived)\n view = {\n relations,\n derived,\n sets: Object.freeze({ ...shape.sets }),\n members: Object.freeze({ ...fields, ...relations, ...derived }),\n }\n seen = shape.revision\n }\n return view\n }\n const entity = Object.create(EntityProto)\n Object.defineProperties(entity, {\n identity: { value: parts.identity, enumerable: true },\n name: { value: parts.identity.name, enumerable: true },\n schema: { value: parts.schema, enumerable: true },\n fields: { value: fields, enumerable: true },\n relations: { get: () => current().relations, enumerable: true },\n derived: { get: () => current().derived, enumerable: true },\n members: { get: () => current().members, enumerable: true },\n sets: { get: () => current().sets, enumerable: true },\n metadata: { value: parts.metadata, enumerable: true },\n })\n Option.map(variantsOf(parts.identity), ({ union }) =>\n Object.defineProperty(entity, 'variants', { value: union, enumerable: true }),\n )\n partsOf.set(entity, parts)\n return Object.freeze(entity)\n}\n\n/** A new descriptor of the same Entity, with some of its own parts changed. */\nexport const remake = (entity: AnyEntity, changed: Partial<Parts>): AnyEntity =>\n make({ ...partsOf.get(entity)!, ...changed })\n\n/** The relations every descriptor of the Entity `identity` names holds. */\nexport const relationsOf = (\n identity: EntityIdentity<string>,\n): Readonly<Record<string, EntityMember>> => shapeOf(identity).relations\n\n/** The invariants every descriptor of the Entity `identity` names judges. */\nexport const invariantsOfIdentity = (identity: EntityIdentity<string>): ReadonlyArray<Invariant> =>\n shapeOf(identity).invariants\n\n/** Adds to the Entity's shared parts, which every descriptor of it then reads. */\nexport const extend = (\n entity: AnyEntity,\n added: {\n readonly relations?: Readonly<Record<string, EntityMember>>\n readonly derived?: Readonly<Record<string, EntityMember>>\n readonly sets?: Readonly<Record<string, EntitySet>>\n readonly invariants?: ReadonlyArray<Invariant>\n },\n): void => {\n const shape = shapeOf(entity.identity)\n for (const [key, member] of Object.entries(added.relations ?? {}))\n put(shape.relations, key, member)\n for (const [key, member] of Object.entries(added.derived ?? {})) put(shape.derived, key, member)\n for (const [key, set] of Object.entries(added.sets ?? {})) put(shape.sets, key, set)\n if (added.invariants !== undefined)\n shape.invariants = Object.freeze([...shape.invariants, ...added.invariants])\n shape.revision += 1\n}\n\nexport const mapValues = <A, B>(\n record: Readonly<Record<string, A>>,\n f: (value: A, key: string) => B,\n): Record<string, B> =>\n Object.fromEntries(Object.entries(record).map(([key, value]) => [key, f(value, key)]))\n\n/**\n * A variant Entity's descriptor as declared, by its identity: each case's\n * invariant is built over its fields when first read.\n */\nexport const variantBases = new WeakMap<EntityIdentity<string>, AnyEntity>()\n"],"mappings":";;;;;;;;;;;AAmCA,MAAM,yBAAS,IAAI,QAAuC;AAE1D,MAAM,WAAW,aAA4C;CAC3D,MAAM,QAAQ,OAAO,IAAI,QAAQ;CACjC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,QAAe;EAAE,WAAW,CAAC;EAAG,SAAS,CAAC;EAAG,MAAM,CAAC;EAAG,YAAY,CAAC;EAAG,UAAU;CAAE;CACzF,OAAO,IAAI,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M,YAAY,GAAG,MAAM,UAAU,CAAC;CAC7E,MAAM,YAAY;AACpB;AAEA,MAAa,aACX,QACA,MAEA,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC;;;;;AAMvF,MAAa,+BAAe,IAAI,QAA2C"}
|
package/dist/entity.d.ts
CHANGED
|
@@ -3,7 +3,8 @@ import { Metadata } from "foldkit-metadata";
|
|
|
3
3
|
import { CheckCases, EntityVariants, StoredFields, VariantCases, VariantUnion } from "./variants.js";
|
|
4
4
|
import { AnyEntity, Cardinality, DerivedSpecs, Entities, Entity, EntityDerived, EntityField, EntityInput, EntityRelation, EntitySets, IdOf, IdSchemaOf, NestedInput, PageWindow, Related, RelationInput, RelationMap, Selection, SelectionPage, Unmapped, VariantEntity } from "./index.js";
|
|
5
5
|
import { SetOn } from "./sets.js";
|
|
6
|
-
import {
|
|
6
|
+
import { inState, refine, states } from "./refine.js";
|
|
7
|
+
import { JudgeInputOptions, check, invariant, invariantsOf as invariants, judge, judgeAgainst, judgeInput, judgedBy, readsBefore, rowFrom } from "./invariant.js";
|
|
7
8
|
import { OneRelation } from "./expr.js";
|
|
8
9
|
/** Unsatisfiable when a new key is already a member, so the pipe step is the error site. */
|
|
9
10
|
type Free<E extends AnyEntity, New> = keyof New & keyof E['members'] extends never ? unknown : {
|
|
@@ -137,7 +138,7 @@ export declare const variantsOf: (entity: AnyEntity) => Option.Option<EntityVari
|
|
|
137
138
|
* each be declared in terms of the other.
|
|
138
139
|
*/
|
|
139
140
|
export declare const relate: <const Es extends Entities, const Rs extends RelationMap<Es>>(entities: Es, relations: Rs & CheckRelations<Es, Rs>) => { readonly [K in keyof Es]: Related<Es, Rs, K>; };
|
|
140
|
-
/** A `one` relation a delete
|
|
141
|
+
/** A `one` relation a delete acts through (it cascades, restricts or clears), and the Entity that owns it. */
|
|
141
142
|
export interface Cascade {
|
|
142
143
|
readonly relation: OneRelation;
|
|
143
144
|
readonly owner: AnyEntity;
|
|
@@ -149,6 +150,18 @@ export interface Cascade {
|
|
|
149
150
|
* members every descriptor of it shares.
|
|
150
151
|
*/
|
|
151
152
|
export declare const cascading: (entity: AnyEntity) => ReadonlyArray<Cascade>;
|
|
153
|
+
/**
|
|
154
|
+
* The `one` relations, of any Entity, declared `onDelete: 'restrict'` that
|
|
155
|
+
* point at `entity`: a delete of one of its rows is refused while a row points
|
|
156
|
+
* at it through one (#467).
|
|
157
|
+
*/
|
|
158
|
+
export declare const restricting: (entity: AnyEntity) => ReadonlyArray<Cascade>;
|
|
159
|
+
/**
|
|
160
|
+
* The optional `one` relations, of any Entity, declared `onDelete: 'setNull'`
|
|
161
|
+
* that point at `entity`: deleting one of its rows clears the link on each row
|
|
162
|
+
* pointing at it through one, which stays (#467).
|
|
163
|
+
*/
|
|
164
|
+
export declare const clearing: (entity: AnyEntity) => ReadonlyArray<Cascade>;
|
|
152
165
|
/**
|
|
153
166
|
* Selects members of an Entity and assembles the schema of the result. A
|
|
154
167
|
* relation selected with `true` yields an `EntityRef`; with a Selection of its
|
|
@@ -227,5 +240,5 @@ export declare const selectFor: <E extends AnyEntity, Fields extends Schema.Stru
|
|
|
227
240
|
* an unmapped key, which the Entity knows nothing about.
|
|
228
241
|
*/
|
|
229
242
|
export declare const valuesFor: <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(input: EntityInput<E, Fields, Members>, value: Readonly<Record<string, unknown>>) => Partial<Schema.Struct.Type<Fields>>;
|
|
230
|
-
export { check, invariant, invariants, isEntity as is, judge, judgeAgainst, judgeInput, readsBefore, isSameEntity as same };
|
|
243
|
+
export { type JudgeInputOptions, check, inState, invariant, invariants, isEntity as is, judge, judgeAgainst, judgeInput, judgedBy, readsBefore, refine, rowFrom, isSameEntity as same, states };
|
|
231
244
|
//# sourceMappingURL=entity.d.ts.map
|
package/dist/entity.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.d.ts","names":[],"sources":["../src/entity.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"entity.d.ts","names":[],"sources":["../src/entity.ts"],"mappings":";;;;;;;;;KA+DK,KAAK,UAAU,WAAW,aAAa,YAAY;WAEzC,sBAAsB,YAAY;;;KAG5C,WAAW,UAAU,WAAW,YAAY,mBAC9C,WAAW,MAAM,IAAI;WACX;WACA,UAAU,+BAA+B;KAE/C,yBAAyB,qBAExB,mBAEA,oBAAmB,UACtB;WAEY,mCAAmC;;KAG/C,YAAY,GAAG,YAAY,gBAC9B,UAAU,oBAAoB,YAAY,cAAc,SAAS,SAAS,KACtE,cAAc,MAAM,QAAQ,GAAG,IAAI,KAAK,KACxC,UAAU,aAAa,YAAY,cAAc,SAAS,KACxD,OAAO,MAAM,QAAQ,GAAG,IAAI;;KAI/B,eAAe,WAAW,UAAU,kBAC7B,WAAW,KAAK,gBAAgB,iBAE1B,WAAW,GAAG,KAAK,gBAAgB,GAAG,oBACxC,sCAAsC,GAAG,eAC7C,GAAG,GAAG;KAKb,UAAU,eAAe,aAAa,OAAO;WACvC,QAAQ,OAAO,QAAQ;WACvB,IAAI,WAAW;;KAGrB,aAAa,gCAAgC,UAAU;KAEvD,WAAW,UAAU,OAAO,cAAc,OAAO;WAC3C,OAAO,OAAO,OAAO;WACrB,SAAS,OAAO;WAChB,aAAa,OAAO;;;KAI1B,cAAc,KAAK;WACb;aACE,aAAa,UAAU,SAC9B;eAA0B,QAAQ,OAAO,OAAO;;;gBAItC,WAAW,aAAa,EAAE;;KAIrC,mBAAmB,UAAU,WAAW,GAAG,SAAS,cAAc,mDAE9C,eAEnB,gBAAgB,cACd,gBAAgB,cAAc,SAAS,cAAc;;KAMxD,cAAc,UAAU,WAAW,oBAC5B,WAAW,OAAO,gBAAgB,iBACxC,eAAe,WAAW,+BAA+B,cAAc,iBAGjE,aAAa,mBAEZ,mBAAmB,cAAc,wCAExC,gBAAgB,eACd,mBAAmB,GAAG,GAAG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,WAAS,sBAAwB,WAAW,gBAAgB,iBAAU,QACxE,MAAI;;;;;;;qBA4BF,QACX,UAAU,WACV,eAAe,OAAO,OAAO,cAEvB,cAAY,QAEV,GAAC,QACD,OAAO,OAAO,YAAO,eACX,aAAa,GAAG,QAAQ,0BACrC,UAAU,UAAU,aAAa,GAAG,QAAQ,aAC5C,SAAS,UAAU,aAAa,GAAG,QAAQ,cAC/C,YAAY,GAAG,QAAQ,aAAa,GAAG,QAAQ;;;;;;qBAiErC,SACX,UAAU,iBACJ,aAAa,oBAAoB,uBAAqB,QAEpD,MAAC,MACA,qBACI,KAAK,eAAe,YAAY;;;;;;;;qBAoBlC,YAAa,UAAU,WAAW,eAAe,OAAO,OAAO,QAAQ,SAAO,OAClF,YAAY,GAAG,QAAQ,UAAQ;WAClB,OAAO,SAAS;MACnC,UACD,WACA,YAAY,UACZ,gBAAgB,GAAG,YAAY,WAC/B,KAAK;;;;;;;qBAuBM,YAAa,UAAU,WAAW,eAAe,OAAO,OAAO,QAAQ,SAAO,OAClF,YAAY,GAAG,QAAQ,UAAQ,OAC/B,SAAS,6BACf,QAAQ,OAAO,OAAO,KAAK"}
|
package/dist/entity.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import { Option, Schema } from "effect";
|
|
1
|
+
import { Match, Option, Schema } from "effect";
|
|
2
2
|
import { Metadata } from "foldkit-metadata";
|
|
3
3
|
import { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from "./ids.js";
|
|
4
4
|
import { own, put } from "./record.js";
|
|
5
5
|
import { declareVariants, registerVariants, variantsOf as variantsOf$1 } from "./variants.js";
|
|
6
6
|
import { extend, make, mapValues, partsOf, remake, variantBases } from "./descriptor.js";
|
|
7
7
|
import { Derivation } from "./index.js";
|
|
8
|
+
import { linkId } from "./rows.js";
|
|
8
9
|
import { checkedSet } from "./sets.js";
|
|
9
10
|
import { SchemaShape } from "./shape.js";
|
|
10
|
-
import {
|
|
11
|
+
import { inState, refine, states } from "./refine.js";
|
|
12
|
+
import { check, invariant, invariantsOf as invariants, judge, judgeAgainst, judgeInput, judgedBy, readsBefore, rowFrom } from "./invariant.js";
|
|
11
13
|
// src/entity.ts
|
|
12
14
|
/**
|
|
13
15
|
* The `Entity` namespace: declaring Entities, their relations and derived
|
|
@@ -177,17 +179,21 @@ const relate = (entities, relations) => {
|
|
|
177
179
|
put(related, ownerKey, entity);
|
|
178
180
|
}
|
|
179
181
|
for (const [entity, added] of additions) extend(entity, { relations: added });
|
|
180
|
-
for (const [entity, added] of additions) for (const member of Object.values(added)) if (member._tag === "Relation" && Option.isSome(member.onDelete))
|
|
182
|
+
for (const [entity, added] of additions) for (const member of Object.values(added)) if (member._tag === "Relation" && Option.isSome(member.onDelete)) pointInto(member.onDelete.value, member.target().identity, {
|
|
181
183
|
relation: member,
|
|
182
184
|
owner: entity
|
|
183
185
|
});
|
|
184
186
|
return Object.freeze(related);
|
|
185
187
|
};
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
188
|
+
const pointing = {
|
|
189
|
+
cascade: /* @__PURE__ */ new WeakMap(),
|
|
190
|
+
restrict: /* @__PURE__ */ new WeakMap(),
|
|
191
|
+
setNull: /* @__PURE__ */ new WeakMap()
|
|
192
|
+
};
|
|
193
|
+
const pointInto = (action, target, edge) => {
|
|
194
|
+
const known = pointing[action].get(target) ?? [];
|
|
195
|
+
known.push(edge);
|
|
196
|
+
pointing[action].set(target, known);
|
|
191
197
|
};
|
|
192
198
|
/**
|
|
193
199
|
* The `one` relations, of any Entity, declared `onDelete: 'cascade'` that point
|
|
@@ -195,7 +201,19 @@ const cascadeInto = (target, cascade) => {
|
|
|
195
201
|
* one, and so on from those. The owner is the Entity as it was related, whose
|
|
196
202
|
* members every descriptor of it shares.
|
|
197
203
|
*/
|
|
198
|
-
const cascading = (entity) =>
|
|
204
|
+
const cascading = (entity) => pointing.cascade.get(entity.identity) ?? [];
|
|
205
|
+
/**
|
|
206
|
+
* The `one` relations, of any Entity, declared `onDelete: 'restrict'` that
|
|
207
|
+
* point at `entity`: a delete of one of its rows is refused while a row points
|
|
208
|
+
* at it through one (#467).
|
|
209
|
+
*/
|
|
210
|
+
const restricting = (entity) => pointing.restrict.get(entity.identity) ?? [];
|
|
211
|
+
/**
|
|
212
|
+
* The optional `one` relations, of any Entity, declared `onDelete: 'setNull'`
|
|
213
|
+
* that point at `entity`: deleting one of its rows clears the link on each row
|
|
214
|
+
* pointing at it through one, which stays (#467).
|
|
215
|
+
*/
|
|
216
|
+
const clearing = (entity) => pointing.setNull.get(entity.identity) ?? [];
|
|
199
217
|
/**
|
|
200
218
|
* Selects members of an Entity and assembles the schema of the result. A
|
|
201
219
|
* relation selected with `true` yields an `EntityRef`; with a Selection of its
|
|
@@ -371,7 +389,10 @@ const input = (entity, schema, ...mapping) => {
|
|
|
371
389
|
const fields = entity.fields;
|
|
372
390
|
const members = mapValues(schema.fields, (_, key) => {
|
|
373
391
|
const member = own(given, key) ?? own(fields, key) ?? fail(entity, `input key "${key}" names no field; map it to a member or Entity.unmapped`);
|
|
374
|
-
const owned =
|
|
392
|
+
const owned = Match.value(member).pipe(Match.tag("Field", (field) => field), Match.tags({
|
|
393
|
+
RelationInput: ({ relation }) => relation,
|
|
394
|
+
NestedInput: ({ relation }) => relation
|
|
395
|
+
}), Match.tag("Unmapped", () => void 0), Match.orElse(() => fail(entity, `input key "${key}" maps to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped`)));
|
|
375
396
|
if (owned !== void 0 && owned.owner.token !== entity.identity.token) fail(entity, `input key "${key}" is mapped to a member of "${owned.owner.name}"`);
|
|
376
397
|
if (member._tag === "NestedInput" && !isSameEntity(member.input.entity, member.relation.target())) fail(entity, `input key "${key}" nests an input of "${member.input.entity.name}", but "${member.relation.key}" is of "${member.relation.target().name}"`);
|
|
377
398
|
return member;
|
|
@@ -397,7 +418,12 @@ const fields = (entity, ...keys) => Object.fromEntries(keys.map((key) => [key, (
|
|
|
397
418
|
*/
|
|
398
419
|
const selectFor = (input, options = {}) => {
|
|
399
420
|
const members = input.members;
|
|
400
|
-
const spec = Object.fromEntries(Object.values(members).flatMap((member) =>
|
|
421
|
+
const spec = Object.fromEntries(Object.values(members).flatMap((member) => Match.valueTags(member, {
|
|
422
|
+
Field: ({ key }) => [[key, true]],
|
|
423
|
+
RelationInput: ({ relation }) => [[relation.key, true]],
|
|
424
|
+
NestedInput: ({ relation, input: nested }) => [[relation.key, selectFor(nested)]],
|
|
425
|
+
Unmapped: () => []
|
|
426
|
+
})));
|
|
401
427
|
return select(input.entity, {
|
|
402
428
|
...spec,
|
|
403
429
|
...options.also
|
|
@@ -411,10 +437,14 @@ const selectFor = (input, options = {}) => {
|
|
|
411
437
|
*/
|
|
412
438
|
const valuesFor = (input, value) => {
|
|
413
439
|
const members = input.members;
|
|
414
|
-
const idOf = (held) =>
|
|
440
|
+
const idOf = (held) => Option.getOrUndefined(linkId(held));
|
|
415
441
|
const entries = Object.entries(members).flatMap(([key, member]) => {
|
|
416
442
|
if (member._tag === "Unmapped") return [];
|
|
417
|
-
const written =
|
|
443
|
+
const written = Match.valueTags(member, {
|
|
444
|
+
Field: ({ key: field }) => field,
|
|
445
|
+
RelationInput: ({ relation }) => relation.key,
|
|
446
|
+
NestedInput: ({ relation }) => relation.key
|
|
447
|
+
});
|
|
418
448
|
if (!(written in value)) return [];
|
|
419
449
|
const read = value[written];
|
|
420
450
|
switch (member._tag) {
|
|
@@ -431,6 +461,6 @@ const valuesFor = (input, value) => {
|
|
|
431
461
|
});
|
|
432
462
|
return Object.fromEntries(entries);
|
|
433
463
|
};
|
|
434
|
-
export { annotate, annotateMembers, cascading, check, define, defineVariants, derived, fields, input, invariant, invariants, isEntity as is, judge, judgeAgainst, judgeInput, page, readsBefore, relate, isSameEntity as same, select, selectFor, selectionSchema, sets, unmapped, valuesFor, variantsOf };
|
|
464
|
+
export { annotate, annotateMembers, cascading, check, clearing, define, defineVariants, derived, fields, inState, input, invariant, invariants, isEntity as is, judge, judgeAgainst, judgeInput, judgedBy, page, readsBefore, refine, relate, restricting, rowFrom, isSameEntity as same, select, selectFor, selectionSchema, sets, states, unmapped, valuesFor, variantsOf };
|
|
435
465
|
|
|
436
466
|
//# sourceMappingURL=entity.js.map
|
package/dist/entity.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"entity.js","names":["variantsOfIdentity"],"sources":["../src/entity.ts"],"sourcesContent":["/**\n * The `Entity` namespace: declaring Entities, their relations and derived\n * members, and Selections and inputs over them. An ES module rather than an\n * object, so a page keeps only the members it calls: one that declares and\n * reads Entities keeps none of the invariant judge or its expression\n * evaluator (#378).\n */\nimport { Option, Schema } from 'effect'\nimport { Metadata } from 'foldkit-metadata'\nimport { extend, make, mapValues, partsOf, remake, variantBases } from './descriptor.js'\nimport type { OneRelation } from './expr.js'\nimport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\nimport {\n Derivation,\n type AnyEntity,\n type Cardinality,\n type DerivedSpec,\n type DerivedSpecs,\n type Entities,\n type Entity,\n type EntityDerived,\n type EntityField,\n type EntityIdentity,\n type EntityInput,\n type EntityMember,\n type EntityRelation,\n type EntitySets,\n type IdOf,\n type IdSchemaOf,\n type InputMember,\n type NestedInput,\n type PageWindow,\n type Related,\n type RelationInput,\n type RelationMap,\n type RelationSpec,\n type RelationSpecs,\n type Selection,\n type SelectionPage,\n type Unmapped,\n type VariantEntity,\n} from './index.js'\nimport { own, put } from './record.js'\nimport { checkedSet, type EntitySet, type SetOn } from './sets.js'\nimport { SchemaShape } from './shape.js'\nimport {\n declareVariants,\n registerVariants,\n variantsOf as variantsOfIdentity,\n type CheckCases,\n type EntityVariants,\n type StoredFields,\n type VariantCases,\n type VariantUnion,\n} from './variants.js'\n\n// What the signatures below check with. Not exported: a consumer's declaration\n// then writes out what one resolves to instead of naming a module the\n// package does not export.\n\n/** Unsatisfiable when a new key is already a member, so the pipe step is the error site. */\ntype Free<E extends AnyEntity, New> = keyof New & keyof E['members'] extends never\n ? unknown\n : { readonly alreadyAMember: keyof New & keyof E['members'] }\n\n/** Unsatisfiable when a `Derived.count` or `Derived.exists` names a relation pointing at another Entity. */\ntype PointsHere<E extends AnyEntity, New extends DerivedSpecs> = {\n [K in keyof New]: New[K]['derives'] extends {\n readonly _tag: 'Count' | 'Exists'\n readonly relation: EntityRelation<any, any, infer Target, any, any>\n }\n ? [Target['name']] extends [E['name']]\n ? never\n : K\n : never\n}[keyof New] extends infer Wrong\n ? [Wrong] extends [never]\n ? unknown\n : { readonly countsRowsPointingAtAnotherEntity: Wrong }\n : never\n\ntype WithDerived<E, New extends DerivedSpecs> =\n E extends VariantEntity<infer Name, infer Fields, infer R, infer D, infer U>\n ? VariantEntity<Name, Fields, R, D & New, U>\n : E extends Entity<infer Name, infer Fields, infer R, infer D>\n ? Entity<Name, Fields, R, D & New>\n : never\n\n/** Marks a relation key that is already a member of its owner, or an owner that is not listed. */\ntype CheckRelations<Es extends Entities, Rs> = {\n readonly [K in keyof Rs]: K extends keyof Es\n ? {\n readonly [R in keyof Rs[K]]: R extends keyof Es[K]['members']\n ? `\"${R & string}\" is already a member of ${Es[K]['name']}`\n : Rs[K][R]\n }\n : 'not one of the entities being related'\n}\n\ntype RefSchema<Target extends AnyEntity> = Schema.Struct<{\n readonly entity: Schema.Literal<Target['name']>\n readonly id: IdSchemaOf<Target>\n}>\n\ntype AnySelection<Name extends string = string> = Selection<Name, any, any>\n\ntype PageSchema<S extends Schema.Constraint> = Schema.Struct<{\n readonly items: Schema.$Array<S>\n readonly hasNext: Schema.Boolean\n readonly hasPrevious: Schema.Boolean\n}>\n\n/** A variant Entity's cases, by tag, as the field sets of its union (`_tag` among them); never for one shape. */\ntype CaseFieldSets<E> = E extends {\n readonly variants: {\n readonly cases: infer C extends Readonly<\n Record<string, { readonly fields: Schema.Struct.Fields }>\n >\n }\n}\n ? { readonly [T in keyof C & string]: C[T]['fields'] }\n : never\n\n/** Whether `K` is a field only some cases have, selected without `_tag` to say which case a row is. */\ntype CaseOnlyWithoutTag<E extends AnyEntity, K, Spec> = [CaseFieldSets<E>] extends [never]\n ? false\n : '_tag' extends keyof Spec\n ? false\n : K extends keyof E['fields']\n ? K extends keyof CaseFieldSets<E>[keyof CaseFieldSets<E>]\n ? false\n : true\n : false\n\n/** `true` for any member; a relation also takes a Selection of its target. */\ntype SelectionSpec<E extends AnyEntity, Spec> = {\n readonly [K in keyof Spec]: K extends keyof E['relations']\n ? E['relations'][K] extends EntityRelation<any, any, infer Target, infer C, any>\n ?\n | true\n | AnySelection<Target['name']>\n // Only a `many` relation has pages.\n | (C extends 'many' ? SelectionPage<Target['name'], any> : never)\n : never\n : K extends keyof E['members']\n ? CaseOnlyWithoutTag<E, K, Spec> extends true\n ? `\"${K & string}\" is a field of some cases of ${E['name']}; select _tag with it`\n : true\n : `\"${K & string}\" is not a member of ${E['name']}`\n}\n\ntype RelationShape<\n C extends Cardinality,\n Optional extends boolean,\n S extends Schema.Constraint,\n> = C extends 'many' ? Schema.$Array<S> : Optional extends true ? Schema.NullOr<S> : S\n\ntype SelectedSchema<Member, Selected> = Member extends\n | EntityField<any, any, infer S>\n | EntityDerived<any, any, infer S>\n ? S\n : Member extends EntityRelation<any, any, infer Target, infer C, infer Optional>\n ? Selected extends SelectionPage<any, infer S>\n ? PageSchema<S>\n : RelationShape<\n C,\n Optional,\n Selected extends Selection<any, any, infer S> ? S : RefSchema<Target>\n >\n : never\n\ntype FlatSelectionSchema<E extends AnyEntity, Spec> = Schema.Struct<{\n readonly [K in keyof Spec & keyof E['members']]: SelectedSchema<E['members'][K], Spec[K]>\n}>\n\n/** What one case holds of a Selection: the selected fields it has, as it holds them, and every other member. */\ntype CaseSelectionFields<E extends AnyEntity, Spec, Fields> = {\n readonly [\n K in Exclude<keyof Spec & keyof E['members'], '_tag'> as K extends keyof E['fields']\n ? K extends keyof Fields\n ? K\n : never\n : K\n ]: K extends keyof Fields ? Fields[K] : SelectedSchema<E['members'][K], Spec[K]>\n}\n\n/**\n * A Selection's schema: a Struct, or, for a variant Entity whose `_tag` is\n * selected, a tagged union with a case per variant.\n */\ntype SelectionSchema<E extends AnyEntity, Spec> = [CaseFieldSets<E>] extends [never]\n ? FlatSelectionSchema<E, Spec>\n : '_tag' extends keyof Spec\n ? Schema.TaggedUnion<{\n readonly [T in keyof CaseFieldSets<E> & string]: Schema.TaggedStruct<\n T,\n CaseSelectionFields<E, Spec, CaseFieldSets<E>[T]>\n >\n }>\n : FlatSelectionSchema<E, Spec>\n\n/** The ids a relation takes as input: one id, a nullable id, or a list of ids. */\ntype RelationIds<R> =\n R extends EntityRelation<any, any, infer Target, infer C, infer Optional>\n ? C extends 'many'\n ? ReadonlyArray<IdOf<Target>>\n : Optional extends true\n ? IdOf<Target> | null\n : IdOf<Target>\n : never\n\n/** What a nested input takes: the value of the target's input, or a list of them for a `many`. */\ntype NestedValues<R, I> =\n I extends EntityInput<any, infer Fields, any>\n ? R extends EntityRelation<any, any, any, 'many', any>\n ? ReadonlyArray<Schema.Struct.Type<Fields>>\n : Schema.Struct.Type<Fields>\n : never\n\ntype Present<T> = Exclude<T, null | undefined>\n\n/** What an `Option` holds, else the value itself. */\ntype Held<T> =\n T extends Option.Some<infer A> ? Present<A> : T extends Option.None<any> ? never : Present<T>\n\n/**\n * Whether an input value fits a field. Only the value that is present has to\n * fit: an input may leave a key out (a partial update), send `null` to clear\n * it, or hold an `Option` (an id absent for something new), whose value fits as\n * it is (an `Option` field) or as what it holds. Whether it may is the input\n * schema's rule; the fit only guards against mapping the wrong member.\n */\ntype Fits<Input, Field> = [Present<Input>] extends [Field]\n ? true\n : [Held<Input>] extends [Field]\n ? true\n : false\n\ntype MappingFor<Name extends string, Input, M> = M extends Unmapped\n ? M\n : M extends\n | EntityField<infer Owner, any, any>\n | RelationInput<EntityRelation<infer Owner, any, any, any, any>>\n | NestedInput<EntityRelation<infer Owner, any, any, any, any>, any>\n ? [Owner] extends [Name]\n ? M extends EntityField<any, any, infer S>\n ? Fits<Input, Schema.Schema.Type<S>> extends true\n ? M\n : 'the input value does not fit this field'\n : M extends RelationInput<infer R>\n ? Held<Input> extends RelationIds<R>\n ? M\n : 'the input value is not the id shape of this relation'\n : M extends NestedInput<infer R, infer I>\n ? R extends EntityRelation<any, any, infer Target, any, any>\n ? I extends EntityInput<infer Of, any, any>\n ? [Of['name']] extends [Target['name']]\n ? Present<Input> extends NestedValues<R, I>\n ? M\n : 'the input value is not the value of the nested input'\n : `the nested input is of ${Of['name']}, not ${Target['name']}`\n : never\n : never\n : never\n : `this member belongs to ${Owner}`\n : 'map an input key to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped'\n\n/** A key that names a field whose value it fits maps itself; every other key needs an entry. */\ntype SelfMapped<E extends AnyEntity, Fields extends Schema.Struct.Fields> = {\n [K in keyof Fields]: K extends keyof E['fields']\n ? Fits<Schema.Schema.Type<Fields[K]>, Schema.Schema.Type<E['fields'][K]['schema']>> extends true\n ? K\n : never\n : never\n}[keyof Fields]\n\n/**\n * A mapping written as a member's key: `'title'` is that Field, and `'author'` is\n * `Relation.input` of that relation. Nothing is inferred from the input key's own\n * name; the member is still named, only more briefly.\n */\ntype Named<E extends AnyEntity, M> = M extends string\n ? M extends keyof E['fields']\n ? E['fields'][M]\n : M extends keyof E['relations']\n ? RelationInput<E['relations'][M]>\n : `\"${M}\" names no field or relation of ${E['name']}`\n : M\n\ntype InputMapping<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = {\n readonly [K in Exclude<keyof Fields, SelfMapped<E, Fields>>]: unknown\n} & {\n readonly [K in keyof Mapping]: K extends keyof Fields\n ? Named<E, Mapping[K]> extends infer Member\n ? Member extends string\n ? Member\n : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> extends Member\n ? Mapping[K]\n : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member>\n : never\n : `\"${K & string}\" is not a key of the input`\n}\n\n/** The member each key of an input writes, as `Entity.input` reads it from a mapping. */\nexport type InputMembers<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = {\n readonly [K in keyof Fields]: K extends keyof Mapping\n ? Named<E, Mapping[K]>\n : K extends keyof E['fields']\n ? E['fields'][K]\n : never\n}\n\n/** The Entity member an input key writes, by its key; nothing for an unmapped key. */\nexport type WrittenKey<M> =\n M extends EntityField<any, infer Key, any>\n ? Key\n : M extends\n | RelationInput<EntityRelation<any, infer Key, any, any, any>>\n | NestedInput<EntityRelation<any, infer Key, any, any, any>, any>\n ? Key\n : never\n\n/** A nested input reads what it writes of the target; every other member reads as it is. */\nexport type WrittenAs<M> =\n M extends NestedInput<any, EntityInput<infer Of, any, infer Members>>\n ? Selection<Of['name'], WrittenSpec<Members>, SelectionSchema<Of, WrittenSpec<Members>>>\n : true\n\n/** Every member the input writes: what to read to show the input's current values. */\nexport type WrittenSpec<Members> = {\n readonly [K in keyof Members as WrittenKey<Members[K]>]: WrittenAs<Members[K]>\n}\n\n/** The `id` field's schema when it is text, so a ref's id keeps its brand and its checks; else text. */\nconst idSchemaOf = (entity: AnyEntity): Schema.Top => {\n const fields: Readonly<Record<string, EntityMember | undefined>> = entity.fields\n const id = fields.id\n if (id === undefined || id._tag !== 'Field') return Schema.String\n const type = Schema.toType(id.schema as Schema.Top)\n return SchemaShape.isText(type.ast) ? type : Schema.String\n}\n\n/**\n * The schema a Selection of `entity` reads, given each selected member's\n * schema by key: a Struct, or, for a variant Entity whose `_tag` is among\n * them, its tagged union (each case keeps the selected fields it has, as it\n * holds them). An interpreter that reads members its own way (Remote reads a\n * relation as a ref) builds a Selection's value with it.\n *\n * A variant Entity's Selection: with `_tag`, a tagged union whose cases hold\n * the selected fields they have, each as the case holds it, and every\n * selected relation and derived member; without it, the stored row's Struct,\n * refused when it selects a field only some cases have.\n */\nexport const selectionSchema = (\n entity: AnyEntity,\n selected: Readonly<Record<string, Schema.Constraint>>,\n): Schema.Top =>\n Option.match(variantsOfIdentity(entity.identity), {\n onNone: () => Schema.Struct(selected),\n onSome: variants => variantSelection(entity, variants, selected),\n })\n\nconst variantSelection = (\n entity: AnyEntity,\n variants: EntityVariants,\n selected: Readonly<Record<string, Schema.Constraint>>,\n): Schema.Top => {\n const caseOnly = (key: string) =>\n Object.hasOwn(entity.fields, key) &&\n key !== '_tag' &&\n variants.tags.some(tag => !Object.hasOwn(variants.cases[tag]!, key))\n if (!Object.hasOwn(selected, '_tag')) {\n const untold = Object.keys(selected).filter(caseOnly)\n if (untold.length > 0)\n fail(\n entity,\n `${untold.join(', ')} ${untold.length === 1 ? 'is a field' : 'are fields'} of some cases; select _tag with ${untold.length === 1 ? 'it' : 'them'}`,\n )\n return Schema.Struct(selected)\n }\n const cases: Record<string, Schema.Struct.Fields> = {}\n for (const tag of variants.tags) {\n const own = variants.cases[tag]!\n const fields: Record<string, Schema.Constraint> = {}\n for (const [key, schema] of Object.entries(selected)) {\n if (key === '_tag') continue\n if (!Object.hasOwn(entity.fields, key)) put(fields, key, schema)\n else if (Object.hasOwn(own, key)) put(fields, key, own[key]!)\n }\n put(cases, tag, fields)\n }\n return Schema.TaggedUnion(cases)\n}\n\nconst isSelectionPage = (value: unknown): value is SelectionPage<string, Schema.Constraint> =>\n typeof value === 'object' && value !== null && SelectionPageTypeId in value\n\nconst isSelection = (value: unknown): value is AnySelection =>\n typeof value === 'object' && value !== null && SelectionTypeId in value\n\n/** For an input key that is about the operation rather than the Entity. */\nexport const unmapped: Unmapped = Object.freeze({ _tag: 'Unmapped' })\n\n/** True when both descriptors are versions of one Entity. */\nconst isSameEntity = (left: AnyEntity, right: AnyEntity): boolean =>\n left.identity.token === right.identity.token\n\nconst fail = (entity: AnyEntity, message: string): never => {\n throw new Error(`Entity \"${entity.name}\": ${message}`)\n}\n\nconst isEntity = (value: unknown): value is AnyEntity =>\n typeof value === 'object' && value !== null && EntityTypeId in value\n\nconst kindName = { Field: 'field', Relation: 'relation', Derived: 'derived member' } as const\n\nconst kindOf = (entity: AnyEntity, key: string): string | undefined => {\n const member = (entity.members as Readonly<Record<string, EntityMember>>)[key]\n return member && kindName[member._tag]\n}\n\nconst assertFree = (entity: AnyEntity, keys: ReadonlyArray<string>, adding: string): void => {\n for (const key of keys) {\n const kind = kindOf(entity, key)\n if (kind !== undefined)\n throw new Error(\n `Entity \"${entity.name}\": cannot add ${adding} \"${key}\", it is already a ${kind}`,\n )\n }\n}\n\n/** Declares an Entity from its intrinsic fields. Each call is a new identity. */\nexport const define = <const Name extends string, Fields extends Schema.Struct.Fields>(\n name: Name,\n schema: Schema.Struct<Fields>,\n): Entity<Name, Fields> => {\n const identity: EntityIdentity<Name> = Object.freeze({ name, token: Symbol(name) })\n return make({\n identity,\n schema,\n fields: mapValues(schema.fields, (fieldSchema, key) =>\n Object.freeze({\n _tag: 'Field',\n owner: identity,\n key,\n schema: fieldSchema,\n metadata: Metadata.empty,\n }),\n ),\n annotated: {},\n metadata: Metadata.empty,\n }) as Entity<Name, Fields>\n}\n\n/**\n * Declares an Entity whose rows are one of several shapes, each case's fields\n * by its tag:\n *\n * ```ts\n * const Domain = Entity.defineVariants('Domain', {\n * Available: { ...DomainName.fields, ...DomainQuote.fields },\n * Unconfirmed: DomainName.fields,\n * })\n * Domain.variants.match(row, { Available: ({ price }) => price, Unconfirmed: () => 0 })\n * ```\n *\n * A row is `Domain.variants`, Effect's tagged union of the cases. The stored\n * row is `fields` and `schema`: `_tag`, the fields every case has, and each\n * other field nullable, null on a row of another case. Each case with fields\n * of its own gets an invariant saying so (`variant_Available`), which a\n * database binding writes as a CHECK. A key in several cases is one stored\n * field, so it is declared with one schema, spread into each case. Refused\n * here: fewer than two cases, a case declaring `_tag`, an optional key.\n */\nexport const defineVariants = <const Name extends string, const Cases extends VariantCases>(\n name: Name,\n cases: Cases & CheckCases<Cases>,\n): VariantEntity<Name, StoredFields<Cases>, {}, {}, VariantUnion<Cases>> => {\n const { fields, variants } = declareVariants(name, cases)\n const declared = define(name, Schema.Struct(fields))\n registerVariants(declared.identity, declared.schema, variants)\n // Made again so the descriptor reads the variants just registered.\n const entity = remake(declared, {})\n // Each case's invariant is built from it when first read (`Entity.invariants`).\n variantBases.set(entity.identity, entity)\n return entity as never\n}\n\n/**\n * An Entity's variants as an interpreter reads them: the union, each case's\n * fields, and the codec from a stored row to its case. None for an Entity of\n * one shape.\n */\nexport const variantsOf = (entity: AnyEntity): Option.Option<EntityVariants> =>\n variantsOfIdentity(entity.identity)\n\n/**\n * Declares the relations between a set of Entities in one step, and returns\n * them related. One step, because Entities that point at each other cannot\n * each be declared in terms of the other.\n */\nexport const relate = <const Es extends Entities, const Rs extends RelationMap<Es>>(\n entities: Es,\n relations: Rs & CheckRelations<Es, Rs>,\n): { readonly [K in keyof Es]: Related<Es, Rs, K> } => {\n const keyByToken = new Map<symbol, string>()\n for (const [key, entity] of Object.entries(entities)) {\n if (!isEntity(entity)) throw new Error(`Entity.relate: \"${key}\" is not an Entity`)\n const earlier = keyByToken.get(entity.identity.token)\n if (earlier !== undefined)\n throw new Error(`Entity.relate: \"${earlier}\" and \"${key}\" are the same Entity`)\n keyByToken.set(entity.identity.token, key)\n }\n const given: Readonly<Record<string, RelationSpecs | undefined>> = relations\n for (const owner of Object.keys(given))\n if (!Object.hasOwn(entities, owner))\n throw new Error(`Entity.relate: relations given for \"${owner}\", which is not being related`)\n\n const related: Record<string, AnyEntity> = {}\n // Every relation is checked before any is added, so a refused call adds none.\n const additions: Array<readonly [AnyEntity, Readonly<Record<string, EntityMember>>]> = []\n for (const [ownerKey, entity] of Object.entries(entities)) {\n const specs = own(given, ownerKey) ?? {}\n assertFree(entity, Object.keys(specs), 'relation')\n const added = mapValues<RelationSpec<AnyEntity, Cardinality, boolean>, EntityMember>(\n specs,\n (spec, key) => {\n const targetKey = isEntity(spec.target)\n ? keyByToken.get(spec.target.identity.token)\n : undefined\n if (targetKey === undefined)\n throw new Error(\n `Entity \"${entity.name}\": relation \"${key}\" targets an Entity that is not being related`,\n )\n return Object.freeze({\n _tag: 'Relation',\n owner: entity.identity,\n key,\n // Read on call: the target may come later in `entities` than its owner.\n target: () => related[targetKey]!,\n cardinality: spec.cardinality,\n optional: spec.optional,\n onDelete: spec.onDelete,\n authorizedBy: spec.authorizedBy,\n metadata: Metadata.empty,\n })\n },\n )\n additions.push([entity, added])\n put(related, ownerKey, entity)\n }\n for (const [entity, added] of additions) extend(entity, { relations: added })\n // Once every relation is added, so each target is the one `relate` returns.\n for (const [entity, added] of additions)\n for (const member of Object.values(added))\n if (member._tag === 'Relation' && Option.isSome(member.onDelete))\n cascadeInto(member.target().identity, { relation: member as OneRelation, owner: entity })\n return Object.freeze(related) as never\n}\n\n/** A `one` relation a delete cascades through, and the Entity that owns it, whose rows go. */\nexport interface Cascade {\n readonly relation: OneRelation\n readonly owner: AnyEntity\n}\n\nconst cascades = new WeakMap<EntityIdentity<string>, Array<Cascade>>()\nconst cascadeInto = (target: EntityIdentity<string>, cascade: Cascade): void => {\n const known = cascades.get(target) ?? []\n known.push(cascade)\n cascades.set(target, known)\n}\n\n/**\n * The `one` relations, of any Entity, declared `onDelete: 'cascade'` that point\n * at `entity`: deleting one of its rows deletes each row pointing at it through\n * one, and so on from those. The owner is the Entity as it was related, whose\n * members every descriptor of it shares.\n */\nexport const cascading = (entity: AnyEntity): ReadonlyArray<Cascade> =>\n cascades.get(entity.identity) ?? []\n\n/**\n * Selects members of an Entity and assembles the schema of the result. A\n * relation selected with `true` yields an `EntityRef`; with a Selection of its\n * target, that Selection's value. `many` yields an array, an optional `one`\n * is nullable.\n */\nexport const select = <E extends AnyEntity, const Spec>(\n entity: E,\n spec: Spec & SelectionSpec<E, Spec>,\n): Selection<E['name'], Spec, SelectionSchema<E, Spec>, IdOf<E>> => {\n const members: Readonly<Record<string, EntityMember>> = entity.members\n const fields = mapValues<unknown, Schema.Constraint>(spec, (selected, key) => {\n const member = own(members, key)\n if (member === undefined)\n throw new Error(`Entity \"${entity.name}\": cannot select \"${key}\", it is not a member`)\n if (member._tag !== 'Relation') {\n if (selected !== true)\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" is a ${kindName[member._tag]}, select it with true`,\n )\n return member.schema\n }\n const target = member.target()\n if (isSelectionPage(selected)) {\n if (member.cardinality !== 'many')\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" is one ${target.name}, so it has no pages`,\n )\n if (!isSameEntity(selected.selection.entity, target))\n throw new Error(`Entity \"${entity.name}\": \"${key}\" pages a Selection of ${target.name}`)\n return Schema.Struct({\n items: Schema.Array(selected.selection.schema as Schema.Top),\n hasNext: Schema.Boolean,\n hasPrevious: Schema.Boolean,\n })\n }\n let item: Schema.Top\n if (selected === true)\n item = Schema.Struct({ entity: Schema.Literal(target.name), id: idSchemaOf(target) })\n else if (isSelection(selected) && isSameEntity(selected.entity, target)) item = selected.schema\n else\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" takes true or a Selection of ${target.name}`,\n )\n return member.cardinality === 'many'\n ? Schema.Array(item)\n : member.optional\n ? Schema.NullOr(item)\n : item\n })\n return Object.freeze({\n [SelectionTypeId]: SelectionTypeId,\n entity,\n members: spec,\n schema: selectionSchema(entity, fields),\n }) as never\n}\n\n/**\n * A `many` relation read a page at a time, in place of its Selection:\n * `comments: Entity.page(CommentSummary, { first: 10 })`. The value is a page\n * of the Selection's values: `items`, `hasNext`, `hasPrevious`. Reading on from a cursor is another window.\n */\nexport const page = <Name extends string, S extends Schema.Constraint>(\n selection: Selection<Name, any, S>,\n window: PageWindow,\n): SelectionPage<Name, S> => {\n const sides = [window.first, window.last].filter(size => size !== undefined)\n if (sides.length !== 1 || !sides.every(size => Number.isInteger(size) && size >= 0))\n throw new Error(\n `Entity.page: a window of ${selection.entity.name} takes first or last, a non-negative integer`,\n )\n if (\n (window.first !== undefined && window.before !== undefined) ||\n (window.last !== undefined && window.after !== undefined)\n )\n throw new Error(\n `Entity.page: a window of ${selection.entity.name} reads first after a cursor, or last before one`,\n )\n const page: SelectionPage<Name, S> = {\n [SelectionPageTypeId]: SelectionPageTypeId,\n selection,\n window,\n }\n return Object.freeze(page)\n}\n\n/**\n * Adds readable members that are not part of `entity.schema`. A\n * `Derived.count` or `Derived.exists` must read rows pointing at this\n * Entity: one over a relation to another is refused here, as is an exists\n * whose viewer is not another `one` relation of the same pointing Entity.\n */\nexport const derived =\n <const New extends DerivedSpecs>(specs: New) =>\n <E extends AnyEntity>(entity: E & Free<E, New> & PointsHere<E, New>): WithDerived<E, New> => {\n const members: Readonly<Record<string, EntityMember>> = entity.members\n // The very spec added again (`Guards.may` on a second view of the Entity) is the member it added.\n const fresh: DerivedSpecs = Object.fromEntries(\n Object.entries(specs).filter(([key, spec]) => {\n const taken = own(members, key)\n return !(\n taken?._tag === 'Derived' &&\n taken.schema === spec.schema &&\n taken.derives === spec.derives\n )\n }),\n )\n assertFree(entity, Object.keys(fresh), 'derived member')\n const added = mapValues<DerivedSpec<Schema.Constraint>, EntityMember>(fresh, (spec, key) => {\n const pointingHere = (relation: OneRelation, verb: string): void => {\n if (relation.cardinality !== 'one')\n fail(\n entity,\n `\"${key}\" ${verb} \"${relation.key}\", a many relation; name a one relation that points here`,\n )\n if (!isSameEntity(relation.target(), entity))\n fail(\n entity,\n `\"${key}\" ${verb} \"${relation.owner.name}.${relation.key}\", which points at ${relation.target().name}`,\n )\n }\n Derivation.$match(spec.derives, {\n Supplied: () => undefined,\n Count: ({ relation }) => pointingHere(relation, 'counts'),\n Exists: ({ relation, viewer }) => {\n pointingHere(relation, 'reads')\n if (viewer.owner.token !== relation.owner.token || viewer.key === relation.key)\n fail(\n entity,\n `\"${key}\"'s viewer \"${viewer.owner.name}.${viewer.key}\" must be another one relation of ${relation.owner.name}`,\n )\n },\n })\n return Object.freeze({\n _tag: 'Derived',\n owner: entity.identity,\n key,\n schema: spec.schema,\n derives: spec.derives,\n metadata: Metadata.empty,\n })\n })\n extend(entity, { derived: added })\n return entity as never\n }\n\n/**\n * Says which members take their value from the write's context, never its\n * input: `Expr.viewer(User)`, whoever asks (a `one` relation to a User, or a\n * field holding their id), and `Expr.now`, when (a field stored as a\n * number). `on` says which writes set them: `'create'`, every insert, or\n * `'write'`, every insert and every update.\n *\n * ```ts\n * const Post = Blog.Post.pipe(\n * Entity.sets({ author: Expr.viewer(User), createdAt: Expr.now }, { on: 'create' }),\n * Entity.sets({ editedAt: Expr.now }, { on: 'write' }),\n * )\n * ```\n *\n * Every write of the Entity follows from it: a server writes the values and\n * a client predicts them, and a write whose input sets one is refused where\n * it is declared. Refused here: the id, a member set already, a `many`\n * relation, a relation set to anything but the viewer of its target, and a\n * field that cannot hold its value. Added after `Entity.relate` to set a\n * relation.\n */\nexport const sets =\n <E extends AnyEntity>(values: EntitySets<E>, options: { readonly on: SetOn }) =>\n (entity: E): E => {\n const given: Readonly<Record<string, unknown>> = values\n const added: Record<string, EntitySet> = {}\n for (const [key, value] of Object.entries(given)) {\n if (value === undefined) continue\n put(added, key, checkedSet(entity, key, value, options.on))\n }\n extend(entity, { sets: added })\n return entity\n }\n\n/** Attaches an interpreter's metadata to the Entity itself. */\nexport const annotate =\n (metadata: Metadata) =>\n <E extends AnyEntity>(entity: E): E =>\n remake(entity, { metadata: Metadata.combine([entity.metadata, metadata]) }) as E\n\n/** Attaches an interpreter's metadata to members, by key. */\nexport const annotateMembers =\n <E extends AnyEntity>(metadata: { readonly [K in keyof E['members']]?: Metadata }) =>\n (entity: E): E => {\n const given = metadata as Readonly<Record<string, Metadata | undefined>>\n for (const key of Object.keys(given))\n if (kindOf(entity, key) === undefined)\n throw new Error(`Entity \"${entity.name}\": cannot annotate \"${key}\", it is not a member`)\n const parts = partsOf.get(entity)!\n const fields = mapValues(entity.fields, (member: EntityMember, key) => {\n const extra = own(given, key)\n return extra === undefined\n ? member\n : Object.freeze({ ...member, metadata: Metadata.combine([member.metadata, extra]) })\n })\n // A relation or derived member is the Entity's own, so its metadata here is this descriptor's.\n const annotated: Record<string, Metadata> = { ...parts.annotated }\n for (const [key, extra] of Object.entries(given)) {\n if (extra === undefined || Object.hasOwn(entity.fields, key)) continue\n const earlier = own(parts.annotated, key)\n put(annotated, key, earlier === undefined ? extra : Metadata.combine([earlier, extra]))\n }\n return remake(entity, { fields, annotated }) as E\n }\n\n/**\n * Reads an operation's input schema against an Entity. A key that names a\n * field maps to it; any other key is mapped explicitly, to a Field, to\n * `Relation.input(relation)`, or to `Entity.unmapped`. Nothing is inferred\n * from a naming convention such as `authorId`.\n */\nexport const input = <\n E extends AnyEntity,\n Fields extends Schema.Struct.Fields,\n // `{}` when every key maps itself, so the argument can be omitted.\n const Mapping = {},\n>(\n entity: E,\n schema: Schema.Struct<Fields>,\n ...mapping: keyof InputMapping<E, Fields, Mapping> extends never\n ? [mapping?: Mapping & InputMapping<E, Fields, Mapping>]\n : [mapping: Mapping & InputMapping<E, Fields, Mapping>]\n): EntityInput<E, Fields, InputMembers<E, Fields, Mapping>> => {\n const written: Readonly<Record<string, InputMember | string | undefined>> = mapping[0] ?? {}\n for (const key of Object.keys(written))\n if (!Object.hasOwn(schema.fields, key))\n throw new Error(`Entity \"${entity.name}\": \"${key}\" is mapped but is not a key of the input`)\n // A member named by its key: a Field as it is, a relation as its ids.\n const named = (key: string, name: string): InputMember => {\n const member = (entity.members as Readonly<Record<string, EntityMember | undefined>>)[name]\n switch (member?._tag) {\n case 'Field':\n return member\n case 'Relation':\n return Object.freeze({ _tag: 'RelationInput', relation: member })\n case 'Derived':\n case undefined:\n return fail(\n entity,\n `input key \"${key}\" is mapped to \"${name}\", which names no field or relation`,\n )\n }\n }\n const given: Readonly<Record<string, InputMember | undefined>> = mapValues(\n written,\n (member, key) => (typeof member === 'string' ? named(key, member) : member),\n )\n const fields: Readonly<Record<string, InputMember | undefined>> = entity.fields\n const members = mapValues(schema.fields, (_, key) => {\n const member =\n own(given, key) ??\n own(fields, key) ??\n fail(entity, `input key \"${key}\" names no field; map it to a member or Entity.unmapped`)\n const owned =\n member._tag === 'Field'\n ? member\n : member._tag === 'RelationInput' || member._tag === 'NestedInput'\n ? member.relation\n : member._tag === 'Unmapped'\n ? undefined\n : fail(\n entity,\n `input key \"${key}\" maps to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped`,\n )\n if (owned !== undefined && owned.owner.token !== entity.identity.token)\n fail(entity, `input key \"${key}\" is mapped to a member of \"${owned.owner.name}\"`)\n if (\n member._tag === 'NestedInput' &&\n !isSameEntity(member.input.entity, member.relation.target())\n )\n fail(\n entity,\n `input key \"${key}\" nests an input of \"${member.input.entity.name}\", but \"${member.relation.key}\" is of \"${member.relation.target().name}\"`,\n )\n return member\n })\n return Object.freeze({ entity, schema, members: Object.freeze(members) }) as never\n}\n\n/**\n * The schemas of some of an Entity's fields, by key, to spread into an input's\n * struct: `Schema.Struct({ ...Entity.fields(Post, 'id', 'title'), editorId: ... })`.\n * The input then keeps the field's own rules, and its keys map themselves.\n */\nexport const fields = <\n E extends AnyEntity,\n const Keys extends ReadonlyArray<keyof E['fields'] & string>,\n>(\n entity: E,\n ...keys: Keys\n): { readonly [K in Keys[number]]: E['fields'][K]['schema'] } =>\n Object.fromEntries(\n keys.map(key => [\n key,\n (\n own(\n entity.fields as Readonly<Record<string, EntityField<string, string, Schema.Constraint>>>,\n key,\n ) ?? fail(entity, `\"${key}\" is not a field`)\n ).schema,\n ]),\n ) as never\n\n/**\n * The Selection of every member an input writes, with each relation as refs:\n * what an edit screen loads before it shows the input's current values.\n * `also` names members to read beside them, each with `true` (what a lock\n * reads). The Selection is typed as the input's alone: what it reads has\n * those members, and these besides.\n */\nexport const selectFor = <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(\n input: EntityInput<E, Fields, Members>,\n options: { readonly also?: Readonly<Record<string, true>> | undefined } = {},\n): Selection<\n E['name'],\n WrittenSpec<Members>,\n SelectionSchema<E, WrittenSpec<Members>>,\n IdOf<E>\n> => {\n const members: Readonly<Record<string, InputMember>> = input.members as never\n const spec = Object.fromEntries(\n Object.values(members).flatMap((member): ReadonlyArray<readonly [string, unknown]> =>\n member._tag === 'Field'\n ? [[member.key, true]]\n : member._tag === 'RelationInput'\n ? [[member.relation.key, true]]\n : member._tag === 'NestedInput'\n ? // What the nested input writes of the target, so its keys can be shown too.\n [[member.relation.key, selectFor(member.input)]]\n : [],\n ),\n )\n return select(input.entity, { ...spec, ...options.also } as never) as never\n}\n\n/**\n * The input values that reproduce `value`, a value read through `selectFor`\n * (or any Selection with those members): a field as it is, a relation as the\n * id or ids of its refs. A key whose member `value` lacks is left out, as is\n * an unmapped key, which the Entity knows nothing about.\n */\nexport const valuesFor = <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(\n input: EntityInput<E, Fields, Members>,\n value: Readonly<Record<string, unknown>>,\n): Partial<Schema.Struct.Type<Fields>> => {\n const members: Readonly<Record<string, InputMember>> = input.members as never\n // The id of a ref or of a nested Selection's value; `undefined` when it has none.\n const idOf = (held: unknown): unknown =>\n held === null\n ? null\n : typeof held === 'object' && 'id' in held\n ? held.id\n : typeof held === 'string'\n ? held\n : undefined\n const entries = Object.entries(members).flatMap(([key, member]) => {\n if (member._tag === 'Unmapped') return []\n const written = member._tag === 'Field' ? member.key : member.relation.key\n if (!(written in value)) return []\n const read = value[written]\n switch (member._tag) {\n case 'Field':\n return [[key, read] as const]\n case 'NestedInput': {\n const nested = (held: unknown): unknown =>\n typeof held === 'object' && held !== null\n ? valuesFor(member.input, held as Readonly<Record<string, unknown>>)\n : null\n return [[key, Array.isArray(read) ? read.map(nested) : nested(read)] as const]\n }\n case 'RelationInput': {\n const ids = Array.isArray(read) ? read.map(idOf) : idOf(read)\n // A relation read without its ids (a nested Selection that left `id` out) fills nothing.\n const known = Array.isArray(ids) ? !ids.includes(undefined) : ids !== undefined\n return known ? [[key, ids] as const] : []\n }\n }\n })\n return Object.fromEntries(entries) as Partial<Schema.Struct.Type<Fields>>\n}\n\nexport { isEntity as is, isSameEntity as same }\nexport {\n check,\n invariant,\n invariantsOf as invariants,\n judge,\n judgeAgainst,\n judgeInput,\n readsBefore,\n} from './invariant.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8U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AAU,OAAO,QAAQ,OAAO,CAAC,CAAC,SAAS,CAAC,KAAK,YAAY;EACjE,IAAI,OAAO,SAAS,YAAY,OAAO,CAAC;EACxC,MAAM,UAAU,OAAO,SAAS,UAAU,OAAO,MAAM,OAAO,SAAS;EACvE,IAAI,EAAE,WAAW,QAAQ,OAAO,CAAC;EACjC,MAAM,OAAO,MAAM;EACnB,QAAQ,OAAO,MAAf;GACE,KAAK,SACH,OAAO,CAAC,CAAC,KAAK,IAAI,CAAU;GAC9B,KAAK,eAAe;IAClB,MAAM,UAAU,SACd,OAAO,SAAS,YAAY,SAAS,OACjC,UAAU,OAAO,OAAO,IAAyC,IACjE;IACN,OAAO,CAAC,CAAC,KAAK,MAAM,QAAQ,IAAI,IAAI,KAAK,IAAI,MAAM,IAAI,OAAO,IAAI,CAAC,CAAU;GAC/E;GACA,KAAK,iBAAiB;IACpB,MAAM,MAAM,MAAM,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI;IAG5D,QADc,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,SAAS,KAAA,CAAS,IAAI,QAAQ,KAAA,KACvD,CAAC,CAAC,KAAK,GAAG,CAAU,IAAI,CAAC;GAC1C;EACF;CACF,CAAC;CACD,OAAO,OAAO,YAAY,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"entity.js","names":["variantsOfIdentity"],"sources":["../src/entity.ts"],"sourcesContent":["/**\n * The `Entity` namespace: declaring Entities, their relations and derived\n * members, and Selections and inputs over them. An ES module rather than an\n * object, so a page keeps only the members it calls: one that declares and\n * reads Entities keeps none of the invariant judge or its expression\n * evaluator (#378).\n */\nimport { Match, Option, Schema } from 'effect'\nimport { Metadata } from 'foldkit-metadata'\nimport { extend, make, mapValues, partsOf, remake, variantBases } from './descriptor.js'\nimport type { OneRelation } from './expr.js'\nimport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\nimport {\n Derivation,\n type AnyEntity,\n type Cardinality,\n type DerivedSpec,\n type DerivedSpecs,\n type Entities,\n type Entity,\n type EntityDerived,\n type EntityField,\n type EntityIdentity,\n type EntityInput,\n type EntityMember,\n type EntityRelation,\n type EntitySets,\n type IdOf,\n type IdSchemaOf,\n type InputMember,\n type NestedInput,\n type OnDelete,\n type PageWindow,\n type Related,\n type RelationInput,\n type RelationMap,\n type RelationSpec,\n type RelationSpecs,\n type Selection,\n type SelectionPage,\n type Unmapped,\n type VariantEntity,\n} from './index.js'\nimport { own, put } from './record.js'\nimport { linkId } from './rows.js'\nimport { checkedSet, type EntitySet, type SetOn } from './sets.js'\nimport { SchemaShape } from './shape.js'\nimport {\n declareVariants,\n registerVariants,\n variantsOf as variantsOfIdentity,\n type CheckCases,\n type EntityVariants,\n type StoredFields,\n type VariantCases,\n type VariantUnion,\n} from './variants.js'\n\n// What the signatures below check with. Not exported: a consumer's declaration\n// then writes out what one resolves to instead of naming a module the\n// package does not export.\n\n/** Unsatisfiable when a new key is already a member, so the pipe step is the error site. */\ntype Free<E extends AnyEntity, New> = keyof New & keyof E['members'] extends never\n ? unknown\n : { readonly alreadyAMember: keyof New & keyof E['members'] }\n\n/** Unsatisfiable when a `Derived.count` or `Derived.exists` names a relation pointing at another Entity. */\ntype PointsHere<E extends AnyEntity, New extends DerivedSpecs> = {\n [K in keyof New]: New[K]['derives'] extends {\n readonly _tag: 'Count' | 'Exists'\n readonly relation: EntityRelation<any, any, infer Target, any, any>\n }\n ? [Target['name']] extends [E['name']]\n ? never\n : K\n : never\n}[keyof New] extends infer Wrong\n ? [Wrong] extends [never]\n ? unknown\n : { readonly countsRowsPointingAtAnotherEntity: Wrong }\n : never\n\ntype WithDerived<E, New extends DerivedSpecs> =\n E extends VariantEntity<infer Name, infer Fields, infer R, infer D, infer U>\n ? VariantEntity<Name, Fields, R, D & New, U>\n : E extends Entity<infer Name, infer Fields, infer R, infer D>\n ? Entity<Name, Fields, R, D & New>\n : never\n\n/** Marks a relation key that is already a member of its owner, or an owner that is not listed. */\ntype CheckRelations<Es extends Entities, Rs> = {\n readonly [K in keyof Rs]: K extends keyof Es\n ? {\n readonly [R in keyof Rs[K]]: R extends keyof Es[K]['members']\n ? `\"${R & string}\" is already a member of ${Es[K]['name']}`\n : Rs[K][R]\n }\n : 'not one of the entities being related'\n}\n\ntype RefSchema<Target extends AnyEntity> = Schema.Struct<{\n readonly entity: Schema.Literal<Target['name']>\n readonly id: IdSchemaOf<Target>\n}>\n\ntype AnySelection<Name extends string = string> = Selection<Name, any, any>\n\ntype PageSchema<S extends Schema.Constraint> = Schema.Struct<{\n readonly items: Schema.$Array<S>\n readonly hasNext: Schema.Boolean\n readonly hasPrevious: Schema.Boolean\n}>\n\n/** A variant Entity's cases, by tag, as the field sets of its union (`_tag` among them); never for one shape. */\ntype CaseFieldSets<E> = E extends {\n readonly variants: {\n readonly cases: infer C extends Readonly<\n Record<string, { readonly fields: Schema.Struct.Fields }>\n >\n }\n}\n ? { readonly [T in keyof C & string]: C[T]['fields'] }\n : never\n\n/** Whether `K` is a field only some cases have, selected without `_tag` to say which case a row is. */\ntype CaseOnlyWithoutTag<E extends AnyEntity, K, Spec> = [CaseFieldSets<E>] extends [never]\n ? false\n : '_tag' extends keyof Spec\n ? false\n : K extends keyof E['fields']\n ? K extends keyof CaseFieldSets<E>[keyof CaseFieldSets<E>]\n ? false\n : true\n : false\n\n/** `true` for any member; a relation also takes a Selection of its target. */\ntype SelectionSpec<E extends AnyEntity, Spec> = {\n readonly [K in keyof Spec]: K extends keyof E['relations']\n ? E['relations'][K] extends EntityRelation<any, any, infer Target, infer C, any>\n ?\n | true\n | AnySelection<Target['name']>\n // Only a `many` relation has pages.\n | (C extends 'many' ? SelectionPage<Target['name'], any> : never)\n : never\n : K extends keyof E['members']\n ? CaseOnlyWithoutTag<E, K, Spec> extends true\n ? `\"${K & string}\" is a field of some cases of ${E['name']}; select _tag with it`\n : true\n : `\"${K & string}\" is not a member of ${E['name']}`\n}\n\ntype RelationShape<\n C extends Cardinality,\n Optional extends boolean,\n S extends Schema.Constraint,\n> = C extends 'many' ? Schema.$Array<S> : Optional extends true ? Schema.NullOr<S> : S\n\ntype SelectedSchema<Member, Selected> = Member extends\n | EntityField<any, any, infer S>\n | EntityDerived<any, any, infer S>\n ? S\n : Member extends EntityRelation<any, any, infer Target, infer C, infer Optional>\n ? Selected extends SelectionPage<any, infer S>\n ? PageSchema<S>\n : RelationShape<\n C,\n Optional,\n Selected extends Selection<any, any, infer S> ? S : RefSchema<Target>\n >\n : never\n\ntype FlatSelectionSchema<E extends AnyEntity, Spec> = Schema.Struct<{\n readonly [K in keyof Spec & keyof E['members']]: SelectedSchema<E['members'][K], Spec[K]>\n}>\n\n/** What one case holds of a Selection: the selected fields it has, as it holds them, and every other member. */\ntype CaseSelectionFields<E extends AnyEntity, Spec, Fields> = {\n readonly [\n K in Exclude<keyof Spec & keyof E['members'], '_tag'> as K extends keyof E['fields']\n ? K extends keyof Fields\n ? K\n : never\n : K\n ]: K extends keyof Fields ? Fields[K] : SelectedSchema<E['members'][K], Spec[K]>\n}\n\n/**\n * A Selection's schema: a Struct, or, for a variant Entity whose `_tag` is\n * selected, a tagged union with a case per variant.\n */\ntype SelectionSchema<E extends AnyEntity, Spec> = [CaseFieldSets<E>] extends [never]\n ? FlatSelectionSchema<E, Spec>\n : '_tag' extends keyof Spec\n ? Schema.TaggedUnion<{\n readonly [T in keyof CaseFieldSets<E> & string]: Schema.TaggedStruct<\n T,\n CaseSelectionFields<E, Spec, CaseFieldSets<E>[T]>\n >\n }>\n : FlatSelectionSchema<E, Spec>\n\n/** The ids a relation takes as input: one id, a nullable id, or a list of ids. */\ntype RelationIds<R> =\n R extends EntityRelation<any, any, infer Target, infer C, infer Optional>\n ? C extends 'many'\n ? ReadonlyArray<IdOf<Target>>\n : Optional extends true\n ? IdOf<Target> | null\n : IdOf<Target>\n : never\n\n/** What a nested input takes: the value of the target's input, or a list of them for a `many`. */\ntype NestedValues<R, I> =\n I extends EntityInput<any, infer Fields, any>\n ? R extends EntityRelation<any, any, any, 'many', any>\n ? ReadonlyArray<Schema.Struct.Type<Fields>>\n : Schema.Struct.Type<Fields>\n : never\n\ntype Present<T> = Exclude<T, null | undefined>\n\n/** What an `Option` holds, else the value itself. */\ntype Held<T> =\n T extends Option.Some<infer A> ? Present<A> : T extends Option.None<any> ? never : Present<T>\n\n/**\n * Whether an input value fits a field. Only the value that is present has to\n * fit: an input may leave a key out (a partial update), send `null` to clear\n * it, or hold an `Option` (an id absent for something new), whose value fits as\n * it is (an `Option` field) or as what it holds. Whether it may is the input\n * schema's rule; the fit only guards against mapping the wrong member.\n */\ntype Fits<Input, Field> = [Present<Input>] extends [Field]\n ? true\n : [Held<Input>] extends [Field]\n ? true\n : false\n\ntype MappingFor<Name extends string, Input, M> = M extends Unmapped\n ? M\n : M extends\n | EntityField<infer Owner, any, any>\n | RelationInput<EntityRelation<infer Owner, any, any, any, any>>\n | NestedInput<EntityRelation<infer Owner, any, any, any, any>, any>\n ? [Owner] extends [Name]\n ? M extends EntityField<any, any, infer S>\n ? Fits<Input, Schema.Schema.Type<S>> extends true\n ? M\n : 'the input value does not fit this field'\n : M extends RelationInput<infer R>\n ? Held<Input> extends RelationIds<R>\n ? M\n : 'the input value is not the id shape of this relation'\n : M extends NestedInput<infer R, infer I>\n ? R extends EntityRelation<any, any, infer Target, any, any>\n ? I extends EntityInput<infer Of, any, any>\n ? [Of['name']] extends [Target['name']]\n ? Present<Input> extends NestedValues<R, I>\n ? M\n : 'the input value is not the value of the nested input'\n : `the nested input is of ${Of['name']}, not ${Target['name']}`\n : never\n : never\n : never\n : `this member belongs to ${Owner}`\n : 'map an input key to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped'\n\n/** A key that names a field whose value it fits maps itself; every other key needs an entry. */\ntype SelfMapped<E extends AnyEntity, Fields extends Schema.Struct.Fields> = {\n [K in keyof Fields]: K extends keyof E['fields']\n ? Fits<Schema.Schema.Type<Fields[K]>, Schema.Schema.Type<E['fields'][K]['schema']>> extends true\n ? K\n : never\n : never\n}[keyof Fields]\n\n/**\n * A mapping written as a member's key: `'title'` is that Field, and `'author'` is\n * `Relation.input` of that relation. Nothing is inferred from the input key's own\n * name; the member is still named, only more briefly.\n */\ntype Named<E extends AnyEntity, M> = M extends string\n ? M extends keyof E['fields']\n ? E['fields'][M]\n : M extends keyof E['relations']\n ? RelationInput<E['relations'][M]>\n : `\"${M}\" names no field or relation of ${E['name']}`\n : M\n\ntype InputMapping<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = {\n readonly [K in Exclude<keyof Fields, SelfMapped<E, Fields>>]: unknown\n} & {\n readonly [K in keyof Mapping]: K extends keyof Fields\n ? Named<E, Mapping[K]> extends infer Member\n ? Member extends string\n ? Member\n : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> extends Member\n ? Mapping[K]\n : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member>\n : never\n : `\"${K & string}\" is not a key of the input`\n}\n\n/** The member each key of an input writes, as `Entity.input` reads it from a mapping. */\nexport type InputMembers<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = {\n readonly [K in keyof Fields]: K extends keyof Mapping\n ? Named<E, Mapping[K]>\n : K extends keyof E['fields']\n ? E['fields'][K]\n : never\n}\n\n/** The Entity member an input key writes, by its key; nothing for an unmapped key. */\nexport type WrittenKey<M> =\n M extends EntityField<any, infer Key, any>\n ? Key\n : M extends\n | RelationInput<EntityRelation<any, infer Key, any, any, any>>\n | NestedInput<EntityRelation<any, infer Key, any, any, any>, any>\n ? Key\n : never\n\n/** A nested input reads what it writes of the target; every other member reads as it is. */\nexport type WrittenAs<M> =\n M extends NestedInput<any, EntityInput<infer Of, any, infer Members>>\n ? Selection<Of['name'], WrittenSpec<Members>, SelectionSchema<Of, WrittenSpec<Members>>>\n : true\n\n/** Every member the input writes: what to read to show the input's current values. */\nexport type WrittenSpec<Members> = {\n readonly [K in keyof Members as WrittenKey<Members[K]>]: WrittenAs<Members[K]>\n}\n\n/** The `id` field's schema when it is text, so a ref's id keeps its brand and its checks; else text. */\nconst idSchemaOf = (entity: AnyEntity): Schema.Top => {\n const fields: Readonly<Record<string, EntityMember | undefined>> = entity.fields\n const id = fields.id\n if (id === undefined || id._tag !== 'Field') return Schema.String\n const type = Schema.toType(id.schema as Schema.Top)\n return SchemaShape.isText(type.ast) ? type : Schema.String\n}\n\n/**\n * The schema a Selection of `entity` reads, given each selected member's\n * schema by key: a Struct, or, for a variant Entity whose `_tag` is among\n * them, its tagged union (each case keeps the selected fields it has, as it\n * holds them). An interpreter that reads members its own way (Remote reads a\n * relation as a ref) builds a Selection's value with it.\n *\n * A variant Entity's Selection: with `_tag`, a tagged union whose cases hold\n * the selected fields they have, each as the case holds it, and every\n * selected relation and derived member; without it, the stored row's Struct,\n * refused when it selects a field only some cases have.\n */\nexport const selectionSchema = (\n entity: AnyEntity,\n selected: Readonly<Record<string, Schema.Constraint>>,\n): Schema.Top =>\n Option.match(variantsOfIdentity(entity.identity), {\n onNone: () => Schema.Struct(selected),\n onSome: variants => variantSelection(entity, variants, selected),\n })\n\nconst variantSelection = (\n entity: AnyEntity,\n variants: EntityVariants,\n selected: Readonly<Record<string, Schema.Constraint>>,\n): Schema.Top => {\n const caseOnly = (key: string) =>\n Object.hasOwn(entity.fields, key) &&\n key !== '_tag' &&\n variants.tags.some(tag => !Object.hasOwn(variants.cases[tag]!, key))\n if (!Object.hasOwn(selected, '_tag')) {\n const untold = Object.keys(selected).filter(caseOnly)\n if (untold.length > 0)\n fail(\n entity,\n `${untold.join(', ')} ${untold.length === 1 ? 'is a field' : 'are fields'} of some cases; select _tag with ${untold.length === 1 ? 'it' : 'them'}`,\n )\n return Schema.Struct(selected)\n }\n const cases: Record<string, Schema.Struct.Fields> = {}\n for (const tag of variants.tags) {\n const own = variants.cases[tag]!\n const fields: Record<string, Schema.Constraint> = {}\n for (const [key, schema] of Object.entries(selected)) {\n if (key === '_tag') continue\n if (!Object.hasOwn(entity.fields, key)) put(fields, key, schema)\n else if (Object.hasOwn(own, key)) put(fields, key, own[key]!)\n }\n put(cases, tag, fields)\n }\n return Schema.TaggedUnion(cases)\n}\n\nconst isSelectionPage = (value: unknown): value is SelectionPage<string, Schema.Constraint> =>\n typeof value === 'object' && value !== null && SelectionPageTypeId in value\n\nconst isSelection = (value: unknown): value is AnySelection =>\n typeof value === 'object' && value !== null && SelectionTypeId in value\n\n/** For an input key that is about the operation rather than the Entity. */\nexport const unmapped: Unmapped = Object.freeze({ _tag: 'Unmapped' })\n\n/** True when both descriptors are versions of one Entity. */\nconst isSameEntity = (left: AnyEntity, right: AnyEntity): boolean =>\n left.identity.token === right.identity.token\n\nconst fail = (entity: AnyEntity, message: string): never => {\n throw new Error(`Entity \"${entity.name}\": ${message}`)\n}\n\nconst isEntity = (value: unknown): value is AnyEntity =>\n typeof value === 'object' && value !== null && EntityTypeId in value\n\nconst kindName = { Field: 'field', Relation: 'relation', Derived: 'derived member' } as const\n\nconst kindOf = (entity: AnyEntity, key: string): string | undefined => {\n const member = (entity.members as Readonly<Record<string, EntityMember>>)[key]\n return member && kindName[member._tag]\n}\n\nconst assertFree = (entity: AnyEntity, keys: ReadonlyArray<string>, adding: string): void => {\n for (const key of keys) {\n const kind = kindOf(entity, key)\n if (kind !== undefined)\n throw new Error(\n `Entity \"${entity.name}\": cannot add ${adding} \"${key}\", it is already a ${kind}`,\n )\n }\n}\n\n/** Declares an Entity from its intrinsic fields. Each call is a new identity. */\nexport const define = <const Name extends string, Fields extends Schema.Struct.Fields>(\n name: Name,\n schema: Schema.Struct<Fields>,\n): Entity<Name, Fields> => {\n const identity: EntityIdentity<Name> = Object.freeze({ name, token: Symbol(name) })\n return make({\n identity,\n schema,\n fields: mapValues(schema.fields, (fieldSchema, key) =>\n Object.freeze({\n _tag: 'Field',\n owner: identity,\n key,\n schema: fieldSchema,\n metadata: Metadata.empty,\n }),\n ),\n annotated: {},\n metadata: Metadata.empty,\n }) as Entity<Name, Fields>\n}\n\n/**\n * Declares an Entity whose rows are one of several shapes, each case's fields\n * by its tag:\n *\n * ```ts\n * const Domain = Entity.defineVariants('Domain', {\n * Available: { ...DomainName.fields, ...DomainQuote.fields },\n * Unconfirmed: DomainName.fields,\n * })\n * Domain.variants.match(row, { Available: ({ price }) => price, Unconfirmed: () => 0 })\n * ```\n *\n * A row is `Domain.variants`, Effect's tagged union of the cases. The stored\n * row is `fields` and `schema`: `_tag`, the fields every case has, and each\n * other field nullable, null on a row of another case. Each case with fields\n * of its own gets an invariant saying so (`variant_Available`), which a\n * database binding writes as a CHECK. A key in several cases is one stored\n * field, so it is declared with one schema, spread into each case. Refused\n * here: fewer than two cases, a case declaring `_tag`, an optional key.\n */\nexport const defineVariants = <const Name extends string, const Cases extends VariantCases>(\n name: Name,\n cases: Cases & CheckCases<Cases>,\n): VariantEntity<Name, StoredFields<Cases>, {}, {}, VariantUnion<Cases>> => {\n const { fields, variants } = declareVariants(name, cases)\n const declared = define(name, Schema.Struct(fields))\n registerVariants(declared.identity, declared.schema, variants)\n // Made again so the descriptor reads the variants just registered.\n const entity = remake(declared, {})\n // Each case's invariant is built from it when first read (`Entity.invariants`).\n variantBases.set(entity.identity, entity)\n return entity as never\n}\n\n/**\n * An Entity's variants as an interpreter reads them: the union, each case's\n * fields, and the codec from a stored row to its case. None for an Entity of\n * one shape.\n */\nexport const variantsOf = (entity: AnyEntity): Option.Option<EntityVariants> =>\n variantsOfIdentity(entity.identity)\n\n/**\n * Declares the relations between a set of Entities in one step, and returns\n * them related. One step, because Entities that point at each other cannot\n * each be declared in terms of the other.\n */\nexport const relate = <const Es extends Entities, const Rs extends RelationMap<Es>>(\n entities: Es,\n relations: Rs & CheckRelations<Es, Rs>,\n): { readonly [K in keyof Es]: Related<Es, Rs, K> } => {\n const keyByToken = new Map<symbol, string>()\n for (const [key, entity] of Object.entries(entities)) {\n if (!isEntity(entity)) throw new Error(`Entity.relate: \"${key}\" is not an Entity`)\n const earlier = keyByToken.get(entity.identity.token)\n if (earlier !== undefined)\n throw new Error(`Entity.relate: \"${earlier}\" and \"${key}\" are the same Entity`)\n keyByToken.set(entity.identity.token, key)\n }\n const given: Readonly<Record<string, RelationSpecs | undefined>> = relations\n for (const owner of Object.keys(given))\n if (!Object.hasOwn(entities, owner))\n throw new Error(`Entity.relate: relations given for \"${owner}\", which is not being related`)\n\n const related: Record<string, AnyEntity> = {}\n // Every relation is checked before any is added, so a refused call adds none.\n const additions: Array<readonly [AnyEntity, Readonly<Record<string, EntityMember>>]> = []\n for (const [ownerKey, entity] of Object.entries(entities)) {\n const specs = own(given, ownerKey) ?? {}\n assertFree(entity, Object.keys(specs), 'relation')\n const added = mapValues<RelationSpec<AnyEntity, Cardinality, boolean>, EntityMember>(\n specs,\n (spec, key) => {\n const targetKey = isEntity(spec.target)\n ? keyByToken.get(spec.target.identity.token)\n : undefined\n if (targetKey === undefined)\n throw new Error(\n `Entity \"${entity.name}\": relation \"${key}\" targets an Entity that is not being related`,\n )\n return Object.freeze({\n _tag: 'Relation',\n owner: entity.identity,\n key,\n // Read on call: the target may come later in `entities` than its owner.\n target: () => related[targetKey]!,\n cardinality: spec.cardinality,\n optional: spec.optional,\n onDelete: spec.onDelete,\n authorizedBy: spec.authorizedBy,\n metadata: Metadata.empty,\n })\n },\n )\n additions.push([entity, added])\n put(related, ownerKey, entity)\n }\n for (const [entity, added] of additions) extend(entity, { relations: added })\n // Once every relation is added, so each target is the one `relate` returns.\n for (const [entity, added] of additions)\n for (const member of Object.values(added))\n if (member._tag === 'Relation' && Option.isSome(member.onDelete))\n pointInto(member.onDelete.value, member.target().identity, {\n relation: member as OneRelation,\n owner: entity,\n })\n return Object.freeze(related) as never\n}\n\n/** A `one` relation a delete acts through (it cascades, restricts or clears), and the Entity that owns it. */\nexport interface Cascade {\n readonly relation: OneRelation\n readonly owner: AnyEntity\n}\n\nconst pointing: Readonly<Record<OnDelete, WeakMap<EntityIdentity<string>, Array<Cascade>>>> = {\n cascade: new WeakMap(),\n restrict: new WeakMap(),\n setNull: new WeakMap(),\n}\nconst pointInto = (action: OnDelete, target: EntityIdentity<string>, edge: Cascade): void => {\n const known = pointing[action].get(target) ?? []\n known.push(edge)\n pointing[action].set(target, known)\n}\n\n/**\n * The `one` relations, of any Entity, declared `onDelete: 'cascade'` that point\n * at `entity`: deleting one of its rows deletes each row pointing at it through\n * one, and so on from those. The owner is the Entity as it was related, whose\n * members every descriptor of it shares.\n */\nexport const cascading = (entity: AnyEntity): ReadonlyArray<Cascade> =>\n pointing.cascade.get(entity.identity) ?? []\n\n/**\n * The `one` relations, of any Entity, declared `onDelete: 'restrict'` that\n * point at `entity`: a delete of one of its rows is refused while a row points\n * at it through one (#467).\n */\nexport const restricting = (entity: AnyEntity): ReadonlyArray<Cascade> =>\n pointing.restrict.get(entity.identity) ?? []\n\n/**\n * The optional `one` relations, of any Entity, declared `onDelete: 'setNull'`\n * that point at `entity`: deleting one of its rows clears the link on each row\n * pointing at it through one, which stays (#467).\n */\nexport const clearing = (entity: AnyEntity): ReadonlyArray<Cascade> =>\n pointing.setNull.get(entity.identity) ?? []\n\n/**\n * Selects members of an Entity and assembles the schema of the result. A\n * relation selected with `true` yields an `EntityRef`; with a Selection of its\n * target, that Selection's value. `many` yields an array, an optional `one`\n * is nullable.\n */\nexport const select = <E extends AnyEntity, const Spec>(\n entity: E,\n spec: Spec & SelectionSpec<E, Spec>,\n): Selection<E['name'], Spec, SelectionSchema<E, Spec>, IdOf<E>> => {\n const members: Readonly<Record<string, EntityMember>> = entity.members\n const fields = mapValues<unknown, Schema.Constraint>(spec, (selected, key) => {\n const member = own(members, key)\n if (member === undefined)\n throw new Error(`Entity \"${entity.name}\": cannot select \"${key}\", it is not a member`)\n if (member._tag !== 'Relation') {\n if (selected !== true)\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" is a ${kindName[member._tag]}, select it with true`,\n )\n return member.schema\n }\n const target = member.target()\n if (isSelectionPage(selected)) {\n if (member.cardinality !== 'many')\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" is one ${target.name}, so it has no pages`,\n )\n if (!isSameEntity(selected.selection.entity, target))\n throw new Error(`Entity \"${entity.name}\": \"${key}\" pages a Selection of ${target.name}`)\n return Schema.Struct({\n items: Schema.Array(selected.selection.schema as Schema.Top),\n hasNext: Schema.Boolean,\n hasPrevious: Schema.Boolean,\n })\n }\n let item: Schema.Top\n if (selected === true)\n item = Schema.Struct({ entity: Schema.Literal(target.name), id: idSchemaOf(target) })\n else if (isSelection(selected) && isSameEntity(selected.entity, target)) item = selected.schema\n else\n throw new Error(\n `Entity \"${entity.name}\": \"${key}\" takes true or a Selection of ${target.name}`,\n )\n return member.cardinality === 'many'\n ? Schema.Array(item)\n : member.optional\n ? Schema.NullOr(item)\n : item\n })\n return Object.freeze({\n [SelectionTypeId]: SelectionTypeId,\n entity,\n members: spec,\n schema: selectionSchema(entity, fields),\n }) as never\n}\n\n/**\n * A `many` relation read a page at a time, in place of its Selection:\n * `comments: Entity.page(CommentSummary, { first: 10 })`. The value is a page\n * of the Selection's values: `items`, `hasNext`, `hasPrevious`. Reading on from a cursor is another window.\n */\nexport const page = <Name extends string, S extends Schema.Constraint>(\n selection: Selection<Name, any, S>,\n window: PageWindow,\n): SelectionPage<Name, S> => {\n const sides = [window.first, window.last].filter(size => size !== undefined)\n if (sides.length !== 1 || !sides.every(size => Number.isInteger(size) && size >= 0))\n throw new Error(\n `Entity.page: a window of ${selection.entity.name} takes first or last, a non-negative integer`,\n )\n if (\n (window.first !== undefined && window.before !== undefined) ||\n (window.last !== undefined && window.after !== undefined)\n )\n throw new Error(\n `Entity.page: a window of ${selection.entity.name} reads first after a cursor, or last before one`,\n )\n const page: SelectionPage<Name, S> = {\n [SelectionPageTypeId]: SelectionPageTypeId,\n selection,\n window,\n }\n return Object.freeze(page)\n}\n\n/**\n * Adds readable members that are not part of `entity.schema`. A\n * `Derived.count` or `Derived.exists` must read rows pointing at this\n * Entity: one over a relation to another is refused here, as is an exists\n * whose viewer is not another `one` relation of the same pointing Entity.\n */\nexport const derived =\n <const New extends DerivedSpecs>(specs: New) =>\n <E extends AnyEntity>(entity: E & Free<E, New> & PointsHere<E, New>): WithDerived<E, New> => {\n const members: Readonly<Record<string, EntityMember>> = entity.members\n // The very spec added again (`Guards.may` on a second view of the Entity) is the member it added.\n const fresh: DerivedSpecs = Object.fromEntries(\n Object.entries(specs).filter(([key, spec]) => {\n const taken = own(members, key)\n return !(\n taken?._tag === 'Derived' &&\n taken.schema === spec.schema &&\n taken.derives === spec.derives\n )\n }),\n )\n assertFree(entity, Object.keys(fresh), 'derived member')\n const added = mapValues<DerivedSpec<Schema.Constraint>, EntityMember>(fresh, (spec, key) => {\n const pointingHere = (relation: OneRelation, verb: string): void => {\n if (relation.cardinality !== 'one')\n fail(\n entity,\n `\"${key}\" ${verb} \"${relation.key}\", a many relation; name a one relation that points here`,\n )\n if (!isSameEntity(relation.target(), entity))\n fail(\n entity,\n `\"${key}\" ${verb} \"${relation.owner.name}.${relation.key}\", which points at ${relation.target().name}`,\n )\n }\n Derivation.$match(spec.derives, {\n Supplied: () => undefined,\n Count: ({ relation }) => pointingHere(relation, 'counts'),\n Exists: ({ relation, viewer }) => {\n pointingHere(relation, 'reads')\n if (viewer.owner.token !== relation.owner.token || viewer.key === relation.key)\n fail(\n entity,\n `\"${key}\"'s viewer \"${viewer.owner.name}.${viewer.key}\" must be another one relation of ${relation.owner.name}`,\n )\n },\n })\n return Object.freeze({\n _tag: 'Derived',\n owner: entity.identity,\n key,\n schema: spec.schema,\n derives: spec.derives,\n metadata: Metadata.empty,\n })\n })\n extend(entity, { derived: added })\n return entity as never\n }\n\n/**\n * Says which members take their value from the write's context, never its\n * input: `Expr.viewer(User)`, whoever asks (a `one` relation to a User, or a\n * field holding their id), and `Expr.now`, when (a field stored as a\n * number). `on` says which writes set them: `'create'`, every insert, or\n * `'write'`, every insert and every update.\n *\n * ```ts\n * const Post = Blog.Post.pipe(\n * Entity.sets({ author: Expr.viewer(User), createdAt: Expr.now }, { on: 'create' }),\n * Entity.sets({ editedAt: Expr.now }, { on: 'write' }),\n * )\n * ```\n *\n * Every write of the Entity follows from it: a server writes the values and\n * a client predicts them, and a write whose input sets one is refused where\n * it is declared. Refused here: the id, a member set already, a `many`\n * relation, a relation set to anything but the viewer of its target, and a\n * field that cannot hold its value. Added after `Entity.relate` to set a\n * relation.\n */\nexport const sets =\n <E extends AnyEntity>(values: EntitySets<E>, options: { readonly on: SetOn }) =>\n (entity: E): E => {\n const given: Readonly<Record<string, unknown>> = values\n const added: Record<string, EntitySet> = {}\n for (const [key, value] of Object.entries(given)) {\n if (value === undefined) continue\n put(added, key, checkedSet(entity, key, value, options.on))\n }\n extend(entity, { sets: added })\n return entity\n }\n\n/** Attaches an interpreter's metadata to the Entity itself. */\nexport const annotate =\n (metadata: Metadata) =>\n <E extends AnyEntity>(entity: E): E =>\n remake(entity, { metadata: Metadata.combine([entity.metadata, metadata]) }) as E\n\n/** Attaches an interpreter's metadata to members, by key. */\nexport const annotateMembers =\n <E extends AnyEntity>(metadata: { readonly [K in keyof E['members']]?: Metadata }) =>\n (entity: E): E => {\n const given = metadata as Readonly<Record<string, Metadata | undefined>>\n for (const key of Object.keys(given))\n if (kindOf(entity, key) === undefined)\n throw new Error(`Entity \"${entity.name}\": cannot annotate \"${key}\", it is not a member`)\n const parts = partsOf.get(entity)!\n const fields = mapValues(entity.fields, (member: EntityMember, key) => {\n const extra = own(given, key)\n return extra === undefined\n ? member\n : Object.freeze({ ...member, metadata: Metadata.combine([member.metadata, extra]) })\n })\n // A relation or derived member is the Entity's own, so its metadata here is this descriptor's.\n const annotated: Record<string, Metadata> = { ...parts.annotated }\n for (const [key, extra] of Object.entries(given)) {\n if (extra === undefined || Object.hasOwn(entity.fields, key)) continue\n const earlier = own(parts.annotated, key)\n put(annotated, key, earlier === undefined ? extra : Metadata.combine([earlier, extra]))\n }\n return remake(entity, { fields, annotated }) as E\n }\n\n/**\n * Reads an operation's input schema against an Entity. A key that names a\n * field maps to it; any other key is mapped explicitly, to a Field, to\n * `Relation.input(relation)`, or to `Entity.unmapped`. Nothing is inferred\n * from a naming convention such as `authorId`.\n */\nexport const input = <\n E extends AnyEntity,\n Fields extends Schema.Struct.Fields,\n // `{}` when every key maps itself, so the argument can be omitted.\n const Mapping = {},\n>(\n entity: E,\n schema: Schema.Struct<Fields>,\n ...mapping: keyof InputMapping<E, Fields, Mapping> extends never\n ? [mapping?: Mapping & InputMapping<E, Fields, Mapping>]\n : [mapping: Mapping & InputMapping<E, Fields, Mapping>]\n): EntityInput<E, Fields, InputMembers<E, Fields, Mapping>> => {\n const written: Readonly<Record<string, InputMember | string | undefined>> = mapping[0] ?? {}\n for (const key of Object.keys(written))\n if (!Object.hasOwn(schema.fields, key))\n throw new Error(`Entity \"${entity.name}\": \"${key}\" is mapped but is not a key of the input`)\n // A member named by its key: a Field as it is, a relation as its ids.\n const named = (key: string, name: string): InputMember => {\n const member = (entity.members as Readonly<Record<string, EntityMember | undefined>>)[name]\n switch (member?._tag) {\n case 'Field':\n return member\n case 'Relation':\n return Object.freeze({ _tag: 'RelationInput', relation: member })\n case 'Derived':\n case undefined:\n return fail(\n entity,\n `input key \"${key}\" is mapped to \"${name}\", which names no field or relation`,\n )\n }\n }\n const given: Readonly<Record<string, InputMember | undefined>> = mapValues(\n written,\n (member, key) => (typeof member === 'string' ? named(key, member) : member),\n )\n const fields: Readonly<Record<string, InputMember | undefined>> = entity.fields\n const members = mapValues(schema.fields, (_, key) => {\n const member =\n own(given, key) ??\n own(fields, key) ??\n fail(entity, `input key \"${key}\" names no field; map it to a member or Entity.unmapped`)\n const owned = Match.value(member).pipe(\n Match.tag('Field', field => field),\n Match.tags({\n RelationInput: ({ relation }) => relation,\n NestedInput: ({ relation }) => relation,\n }),\n Match.tag('Unmapped', () => undefined),\n Match.orElse(() =>\n fail(\n entity,\n `input key \"${key}\" maps to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped`,\n ),\n ),\n )\n if (owned !== undefined && owned.owner.token !== entity.identity.token)\n fail(entity, `input key \"${key}\" is mapped to a member of \"${owned.owner.name}\"`)\n if (\n member._tag === 'NestedInput' &&\n !isSameEntity(member.input.entity, member.relation.target())\n )\n fail(\n entity,\n `input key \"${key}\" nests an input of \"${member.input.entity.name}\", but \"${member.relation.key}\" is of \"${member.relation.target().name}\"`,\n )\n return member\n })\n return Object.freeze({ entity, schema, members: Object.freeze(members) }) as never\n}\n\n/**\n * The schemas of some of an Entity's fields, by key, to spread into an input's\n * struct: `Schema.Struct({ ...Entity.fields(Post, 'id', 'title'), editorId: ... })`.\n * The input then keeps the field's own rules, and its keys map themselves.\n */\nexport const fields = <\n E extends AnyEntity,\n const Keys extends ReadonlyArray<keyof E['fields'] & string>,\n>(\n entity: E,\n ...keys: Keys\n): { readonly [K in Keys[number]]: E['fields'][K]['schema'] } =>\n Object.fromEntries(\n keys.map(key => [\n key,\n (\n own(\n entity.fields as Readonly<Record<string, EntityField<string, string, Schema.Constraint>>>,\n key,\n ) ?? fail(entity, `\"${key}\" is not a field`)\n ).schema,\n ]),\n ) as never\n\n/**\n * The Selection of every member an input writes, with each relation as refs:\n * what an edit screen loads before it shows the input's current values.\n * `also` names members to read beside them, each with `true` (what a lock\n * reads). The Selection is typed as the input's alone: what it reads has\n * those members, and these besides.\n */\nexport const selectFor = <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(\n input: EntityInput<E, Fields, Members>,\n options: { readonly also?: Readonly<Record<string, true>> | undefined } = {},\n): Selection<\n E['name'],\n WrittenSpec<Members>,\n SelectionSchema<E, WrittenSpec<Members>>,\n IdOf<E>\n> => {\n const members: Readonly<Record<string, InputMember>> = input.members as never\n const spec = Object.fromEntries(\n Object.values(members).flatMap((member): ReadonlyArray<readonly [string, unknown]> =>\n Match.valueTags(member, {\n Field: ({ key }) => [[key, true] as const],\n RelationInput: ({ relation }) => [[relation.key, true] as const],\n // What the nested input writes of the target, so its keys can be shown too.\n NestedInput: ({ relation, input: nested }) => [[relation.key, selectFor(nested)] as const],\n Unmapped: () => [],\n }),\n ),\n )\n return select(input.entity, { ...spec, ...options.also } as never) as never\n}\n\n/**\n * The input values that reproduce `value`, a value read through `selectFor`\n * (or any Selection with those members): a field as it is, a relation as the\n * id or ids of its refs. A key whose member `value` lacks is left out, as is\n * an unmapped key, which the Entity knows nothing about.\n */\nexport const valuesFor = <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(\n input: EntityInput<E, Fields, Members>,\n value: Readonly<Record<string, unknown>>,\n): Partial<Schema.Struct.Type<Fields>> => {\n const members: Readonly<Record<string, InputMember>> = input.members as never\n const idOf = (held: unknown): unknown => Option.getOrUndefined(linkId(held))\n const entries = Object.entries(members).flatMap(([key, member]) => {\n if (member._tag === 'Unmapped') return []\n const written = Match.valueTags(member, {\n Field: ({ key: field }) => field,\n RelationInput: ({ relation }) => relation.key,\n NestedInput: ({ relation }) => relation.key,\n })\n if (!(written in value)) return []\n const read = value[written]\n switch (member._tag) {\n case 'Field':\n return [[key, read] as const]\n case 'NestedInput': {\n const nested = (held: unknown): unknown =>\n typeof held === 'object' && held !== null\n ? valuesFor(member.input, held as Readonly<Record<string, unknown>>)\n : null\n return [[key, Array.isArray(read) ? read.map(nested) : nested(read)] as const]\n }\n case 'RelationInput': {\n const ids = Array.isArray(read) ? read.map(idOf) : idOf(read)\n // A relation read without its ids (a nested Selection that left `id` out) fills nothing.\n const known = Array.isArray(ids) ? !ids.includes(undefined) : ids !== undefined\n return known ? [[key, ids] as const] : []\n }\n }\n })\n return Object.fromEntries(entries) as Partial<Schema.Struct.Type<Fields>>\n}\n\nexport { isEntity as is, isSameEntity as same }\nexport { inState, refine, states } from './refine.js'\nexport {\n check,\n invariant,\n invariantsOf as invariants,\n judge,\n judgeAgainst,\n judgeInput,\n judgedBy,\n readsBefore,\n rowFrom,\n type JudgeInputOptions,\n} from './invariant.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAgVA,MAAM,cAAc,WAAkC;CAEpD,MAAM,KAD6D,OAAO,OACxD;CA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@
|
|
|
1
|
+
import { Data, Option, Schema } from "effect";
|
|
2
|
+
import { Row } from "./evaluate.js";
|
|
3
|
+
import { MemoryOperators } from "./operators.js";
|
|
4
|
+
import { AnyWrite } from "./write.js";
|
|
5
|
+
/** The most rows (rows before, times inputs) one question is enumerated over. */
|
|
6
|
+
export declare const maxRows = 4096;
|
|
7
|
+
/**
|
|
8
|
+
* The values a stored form can hold, when they are few: a literal, a union of
|
|
9
|
+
* literals, a boolean, each with or without null. None for anything else.
|
|
10
|
+
*/
|
|
11
|
+
export declare const finiteValues: (schema: Schema.Top) => Option.Option<ReadonlyArray<unknown>>;
|
|
12
|
+
/** One row a write can start from, an input it can be given, and the row it leaves. */
|
|
13
|
+
export interface Step {
|
|
14
|
+
readonly before: Row;
|
|
15
|
+
readonly input: Row;
|
|
16
|
+
readonly after: Row;
|
|
17
|
+
}
|
|
18
|
+
/** What enumerating a write comes to: every step, or why there is no list of them. */
|
|
19
|
+
export type Steps = Data.TaggedEnum<{
|
|
20
|
+
Steps: {
|
|
21
|
+
readonly steps: ReadonlyArray<Step>;
|
|
22
|
+
};
|
|
23
|
+
Undecided: {
|
|
24
|
+
readonly reason: string;
|
|
25
|
+
};
|
|
26
|
+
}>;
|
|
27
|
+
export declare const Steps: Data.TaggedEnum.Constructor<{
|
|
28
|
+
readonly _tag: "Steps";
|
|
29
|
+
readonly steps: ReadonlyArray<Step>;
|
|
30
|
+
} | {
|
|
31
|
+
readonly _tag: "Undecided";
|
|
32
|
+
readonly reason: string;
|
|
33
|
+
}>;
|
|
34
|
+
/**
|
|
35
|
+
* Every step `write` can take over the members `members` names (field keys of
|
|
36
|
+
* its Entity): each row before over them and the finite members its `when`
|
|
37
|
+
* reads, dropping a row the `when` definitely refuses, with each input value
|
|
38
|
+
* of the keys that set them. Rows are not filtered by the Entity's
|
|
39
|
+
* invariants: a row may be invalid before a write.
|
|
40
|
+
*/
|
|
41
|
+
export declare const steps: (write: AnyWrite, members: ReadonlyArray<string>, options?: {
|
|
42
|
+
readonly operators?: MemoryOperators | undefined;
|
|
43
|
+
}) => Steps;
|
|
44
|
+
//# sourceMappingURL=enumerate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enumerate.d.ts","names":[],"sources":["../src/enumerate.ts"],"mappings":";;;;;qBAoBa;;;;;qBAMA,eAAY,QAAY,OAAO,QAAM,OAAO,OAAO;;iBAc/C;WACN,QAAQ;WACR,OAAO;WACP,OAAO;;;YAIN,QAAQ,KAAK;EACvB;aAAkB,OAAO,cAAc;;EACvC;aAAsB;;;qBAEX,OAAK,KAAA,WAAA;;WAHS,OAAA,cAAc;;;WACT;;;;;;;;;qBAuFnB,QAAK,OACT,UAAQ,SACN,uBAAqB;WACV,YAAY;MAC/B"}
|