foldkit-entity 0.14.0 → 0.15.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.
Files changed (93) hide show
  1. package/README.md +139 -5
  2. package/dist/collation.d.ts +33 -2
  3. package/dist/collation.d.ts.map +1 -0
  4. package/dist/conformance/index.d.ts +4 -4
  5. package/dist/conformance/index.d.ts.map +1 -1
  6. package/dist/conformance/index.js +5 -7
  7. package/dist/conformance/index.js.map +1 -1
  8. package/dist/conformance/operator.d.ts +1 -2
  9. package/dist/conformance/operator.d.ts.map +1 -1
  10. package/dist/conformance/operator.js +2 -6
  11. package/dist/conformance/operator.js.map +1 -1
  12. package/dist/conformance/relational.d.ts +17 -17
  13. package/dist/conformance/relational.d.ts.map +1 -1
  14. package/dist/conformance/relational.js +1 -3
  15. package/dist/conformance/relational.js.map +1 -1
  16. package/dist/conformance/variants.d.ts +47 -0
  17. package/dist/conformance/variants.d.ts.map +1 -0
  18. package/dist/conformance/variants.js +126 -0
  19. package/dist/conformance/variants.js.map +1 -0
  20. package/dist/context.d.ts +60 -2
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/descriptor.d.ts +33 -0
  23. package/dist/descriptor.d.ts.map +1 -0
  24. package/dist/descriptor.js +137 -0
  25. package/dist/descriptor.js.map +1 -0
  26. package/dist/entity.d.ts +231 -0
  27. package/dist/entity.d.ts.map +1 -0
  28. package/dist/entity.js +435 -0
  29. package/dist/entity.js.map +1 -0
  30. package/dist/evaluate.d.ts +204 -2
  31. package/dist/evaluate.d.ts.map +1 -0
  32. package/dist/evaluate.js +51 -7
  33. package/dist/evaluate.js.map +1 -1
  34. package/dist/expr.d.ts +915 -2
  35. package/dist/expr.d.ts.map +1 -0
  36. package/dist/expr.js +50 -10
  37. package/dist/expr.js.map +1 -1
  38. package/dist/held.d.ts +112 -2
  39. package/dist/held.d.ts.map +1 -0
  40. package/dist/held.js +13 -2
  41. package/dist/held.js.map +1 -1
  42. package/dist/ids.d.ts +8 -0
  43. package/dist/ids.d.ts.map +1 -0
  44. package/dist/ids.js +8 -0
  45. package/dist/ids.js.map +1 -0
  46. package/dist/index.d.ts +380 -6
  47. package/dist/index.d.ts.map +1 -0
  48. package/dist/index.js +108 -12
  49. package/dist/index.js.map +1 -0
  50. package/dist/invariant.d.ts +123 -2
  51. package/dist/invariant.d.ts.map +1 -0
  52. package/dist/invariant.js +236 -1
  53. package/dist/invariant.js.map +1 -0
  54. package/dist/law.d.ts +264 -2
  55. package/dist/law.d.ts.map +1 -0
  56. package/dist/law.js +1 -1
  57. package/dist/operators.d.ts +170 -2
  58. package/dist/operators.d.ts.map +1 -0
  59. package/dist/operators.js +3 -3
  60. package/dist/readFilter.d.ts +8 -2
  61. package/dist/readFilter.d.ts.map +1 -0
  62. package/dist/sets.d.ts +18 -2
  63. package/dist/sets.d.ts.map +1 -0
  64. package/dist/sets.js +1 -1
  65. package/dist/shape.d.ts +23 -2
  66. package/dist/shape.d.ts.map +1 -0
  67. package/dist/tested.d.ts +8 -2
  68. package/dist/tested.d.ts.map +1 -0
  69. package/dist/text.d.ts +27 -2
  70. package/dist/text.d.ts.map +1 -0
  71. package/dist/text.js +1 -1
  72. package/dist/variants.d.ts +72 -0
  73. package/dist/variants.d.ts.map +1 -0
  74. package/dist/variants.js +76 -0
  75. package/dist/variants.js.map +1 -0
  76. package/dist/words.d.ts +17 -2
  77. package/dist/words.d.ts.map +1 -0
  78. package/dist/write.d.ts +312 -2
  79. package/dist/write.d.ts.map +1 -0
  80. package/dist/write.js +3 -3
  81. package/package.json +3 -3
  82. package/dist/collation-BB4YTIbY.d.ts +0 -34
  83. package/dist/collation-BB4YTIbY.d.ts.map +0 -1
  84. package/dist/index-48JeXG0A.d.ts +0 -2585
  85. package/dist/index-48JeXG0A.d.ts.map +0 -1
  86. package/dist/readFilter-CWMnFRVw.d.ts +0 -9
  87. package/dist/readFilter-CWMnFRVw.d.ts.map +0 -1
  88. package/dist/shape-LAowRf9f.d.ts +0 -23
  89. package/dist/shape-LAowRf9f.d.ts.map +0 -1
  90. package/dist/src-DKhUqLoC.js +0 -731
  91. package/dist/src-DKhUqLoC.js.map +0 -1
  92. package/dist/words-a4e9o-TK.d.ts +0 -18
  93. package/dist/words-a4e9o-TK.d.ts.map +0 -1
package/dist/context.d.ts CHANGED
@@ -1,2 +1,60 @@
1
- import { cr as NowExpr, dr as contextValue, fr as now, lr as ViewerExpr, mr as viewerIdOf, pr as viewer, sr as ExprContext, ur as ViewerPathExpr } from "./index-48JeXG0A.js";
2
- export { ExprContext, NowExpr, ViewerExpr, ViewerPathExpr, contextValue, now, viewer, viewerIdOf };
1
+ import { Option, Schema } from "effect";
2
+ import { AnyEntity, EntityIdentity, EntityRef, IdOf } from "./index.js";
3
+ import { FieldExpr, OneRelation } from "./expr.js";
4
+ /**
5
+ * Whoever asks, as the row they are of `target`: shaped as a `one` relation
6
+ * to that Entity, so a path can go on from it. Its value is the row's id; for
7
+ * a visitor, or a viewer of another Entity, it is null, which compares as
8
+ * SQL's unknown.
9
+ */
10
+ export interface ViewerExpr<T, Name extends string = string> {
11
+ readonly _tag: 'Viewer';
12
+ readonly entity: EntityIdentity<Name>;
13
+ readonly target: () => AnyEntity;
14
+ readonly schema: Schema.Codec<T, unknown>;
15
+ }
16
+ /**
17
+ * What the row of whoever asks holds, or the row reached from it through `one`
18
+ * relations (`Expr.path(Expr.viewer(User), end)`): a field of that row. Null
19
+ * for a visitor, a viewer of another Entity, a null link, or a row the reader
20
+ * may not see. `Entity.sets` reads one, and so may a query body or a rule:
21
+ * SQL reads the viewer's row under its Entity's `visible` rule, and the client
22
+ * judges it from the rows it holds.
23
+ */
24
+ export interface ViewerPathExpr<T> {
25
+ readonly _tag: 'ViewerPath';
26
+ readonly viewer: ViewerExpr<unknown>;
27
+ /** The relations followed from the viewer's row, in order; empty for a field of it. */
28
+ readonly via: ReadonlyArray<OneRelation>;
29
+ readonly field: FieldExpr<T>;
30
+ }
31
+ /** The time of the write, in milliseconds since the epoch. */
32
+ export interface NowExpr<T> {
33
+ readonly _tag: 'Now';
34
+ readonly schema: Schema.Codec<T, unknown>;
35
+ }
36
+ /**
37
+ * What the context terms read, as one side provides it: the viewer as a
38
+ * ref, none for a visitor; the time, none where the side has no reading of
39
+ * it (a client judging a list, which knows no time the server judged it at).
40
+ */
41
+ export interface ExprContext {
42
+ readonly viewer: Option.Option<EntityRef>;
43
+ readonly now: Option.Option<number>;
44
+ }
45
+ /** `Expr.viewer`: whoever asks, as a row of `entity`. */
46
+ export declare const viewer: <E extends AnyEntity>(entity: E) => ViewerExpr<IdOf<E>, E['name']>;
47
+ /** `Expr.now`: the time of the write. */
48
+ export declare const now: NowExpr<number>;
49
+ /**
50
+ * What a context term comes to in `context`, as an interpreter binds it: the
51
+ * viewer's id when they are a row of the term's Entity, else null, as for a
52
+ * visitor; the time. None when the side has no reading of the time, which is
53
+ * not a null: an interpreter refuses what it cannot say.
54
+ */
55
+ export declare const contextValue: (term: ViewerExpr<unknown> | NowExpr<unknown>, context: ExprContext) => Option.Option<string | number | null>;
56
+ /** The viewer's id, when they are a row of `entity`. */
57
+ export declare const viewerIdOf: (entity: {
58
+ readonly name: string;
59
+ }, context: Pick<ExprContext, 'viewer'>) => Option.Option<string>;
60
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","names":[],"sources":["../src/context.ts"],"mappings":";;;;;;;;;iBAgBiB,WAAW,GAAG;WACpB;WACA,QAAQ,eAAe;WACvB,cAAc;WACd,QAAQ,OAAO,MAAM;;;;;;;;;;iBAWf,eAAe;WACrB;WACA,QAAQ;;WAER,KAAK,cAAc;WACnB,OAAO,UAAU;;;iBAIX,QAAQ;WACd;WACA,QAAQ,OAAO,MAAM;;;;;;;iBAQf;WACN,QAAQ,OAAO,OAAO;WACtB,KAAK,OAAO;;;qBAMV,SAAU,UAAU,WAAS,QAAU,MAAI,WAAW,KAAK,IAAI;;qBAU/D,KAAK;;;;;;;qBAQL,eAAY,MACjB,sBAAsB,kBAAgB,SACnC,gBACR,OAAO;;qBAUG,aAAU;WACF;GAAc,SACxB,KAAK,2BACb,OAAO"}
@@ -0,0 +1,33 @@
1
+ import { Schema } from "effect";
2
+ import { Metadata } from "foldkit-metadata";
3
+ import { AnyEntity, EntityIdentity, EntityMember } from "./index.js";
4
+ import { EntitySet } from "./sets.js";
5
+ /** What one descriptor holds of its own: its fields, and the metadata annotated on it. */
6
+ interface Parts {
7
+ readonly identity: EntityIdentity<string>;
8
+ readonly schema: Schema.Struct<Schema.Struct.Fields>;
9
+ readonly fields: Readonly<Record<string, EntityMember>>;
10
+ /** Metadata `annotateMembers` gave this descriptor's relations and derived members, by key. */
11
+ readonly annotated: Readonly<Record<string, Metadata>>;
12
+ readonly metadata: Metadata;
13
+ }
14
+ export declare const partsOf: WeakMap<AnyEntity, Parts>;
15
+ export declare const make: (parts: Parts) => AnyEntity;
16
+ /** A new descriptor of the same Entity, with some of its own parts changed. */
17
+ export declare const remake: (entity: AnyEntity, changed: Partial<Parts>) => AnyEntity;
18
+ /** The relations every descriptor of the Entity `identity` names holds. */
19
+ export declare const relationsOf: (identity: EntityIdentity<string>) => Readonly<Record<string, EntityMember>>;
20
+ /** Adds to the Entity's shared members, which every descriptor of it then reads. */
21
+ export declare const extend: (entity: AnyEntity, added: {
22
+ readonly relations?: Readonly<Record<string, EntityMember>>;
23
+ readonly derived?: Readonly<Record<string, EntityMember>>;
24
+ readonly sets?: Readonly<Record<string, EntitySet>>;
25
+ }) => void;
26
+ export declare const mapValues: <A, B>(record: Readonly<Record<string, A>>, f: (value: A, key: string) => B) => Record<string, B>;
27
+ /**
28
+ * A variant Entity's descriptor as declared, by its identity: each case's
29
+ * invariant is built over its fields when first read.
30
+ */
31
+ export declare const variantBases: WeakMap<EntityIdentity<string>, AnyEntity>;
32
+ export {};
33
+ //# sourceMappingURL=descriptor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descriptor.d.ts","names":[],"sources":["../src/descriptor.ts"],"mappings":";;;;;UAsCU;WACC,UAAU;WACV,QAAQ,OAAO,OAAO,OAAO,OAAO;WACpC,QAAQ,SAAS,eAAe;;WAEhC,WAAW,SAAS,eAAe;WACnC,UAAU;;qBAGR,SAAO,QAAA,WAAA;qBASP,OAAI,OAAW,UAAQ;;qBA6DvB,SAAM,QAAY,WAAS,SAAW,QAAQ,WAAS;;qBAIvD,cAAW,UACZ,2BACT,SAAS,eAAe;;qBAGd,SAAM,QACT,WAAS;WAEN,YAAY,SAAS,eAAe;WACpC,UAAU,SAAS,eAAe;WAClC,OAAO,SAAS,eAAe;;qBAW/B,YAAa,GAAG,GAAC,QACpB,SAAS,eAAe,KAAG,IAC/B,OAAO,GAAG,gBAAgB,MAC7B,eAAe;;;;;qBAOL,cAAY,QAAA,wBAAA"}
@@ -0,0 +1,137 @@
1
+ import { Option, Pipeable } from "effect";
2
+ import { Metadata } from "foldkit-metadata";
3
+ import { EntityTypeId } from "./ids.js";
4
+ import { own, put } from "./record.js";
5
+ import { variantsOf } from "./variants.js";
6
+ // src/descriptor.ts
7
+ /**
8
+ * What makes an Entity descriptor: its parts, the members every descriptor of
9
+ * one Entity shares, and making a new descriptor from them. Apart from the
10
+ * `Entity` namespace, so an invariant attaches itself without importing it.
11
+ */
12
+ const shapes = /* @__PURE__ */ new WeakMap();
13
+ const shapeOf = (identity) => {
14
+ const known = shapes.get(identity);
15
+ if (known !== void 0) return known;
16
+ const shape = {
17
+ relations: {},
18
+ derived: {},
19
+ sets: {},
20
+ revision: 0
21
+ };
22
+ shapes.set(identity, shape);
23
+ return shape;
24
+ };
25
+ const partsOf = /* @__PURE__ */ new WeakMap();
26
+ const EntityProto = {
27
+ [EntityTypeId]: EntityTypeId,
28
+ pipe() {
29
+ return Pipeable.pipeArguments(this, arguments);
30
+ }
31
+ };
32
+ const make = (parts) => {
33
+ const shape = shapeOf(parts.identity);
34
+ const fields = Object.freeze(parts.fields);
35
+ const copies = /* @__PURE__ */ new WeakMap();
36
+ const annotate = (members) => Object.freeze(mapValues(members, (member, key) => {
37
+ const extra = own(parts.annotated, key);
38
+ if (extra === void 0) return member;
39
+ const copied = copies.get(member);
40
+ if (copied !== void 0) return copied;
41
+ const copy = Object.freeze({
42
+ ...member,
43
+ metadata: Metadata.combine([member.metadata, extra])
44
+ });
45
+ copies.set(member, copy);
46
+ return copy;
47
+ }));
48
+ let seen = -1;
49
+ let view;
50
+ const current = () => {
51
+ if (seen !== shape.revision) {
52
+ const relations = annotate(shape.relations);
53
+ const derived = annotate(shape.derived);
54
+ view = {
55
+ relations,
56
+ derived,
57
+ sets: Object.freeze({ ...shape.sets }),
58
+ members: Object.freeze({
59
+ ...fields,
60
+ ...relations,
61
+ ...derived
62
+ })
63
+ };
64
+ seen = shape.revision;
65
+ }
66
+ return view;
67
+ };
68
+ const entity = Object.create(EntityProto);
69
+ Object.defineProperties(entity, {
70
+ identity: {
71
+ value: parts.identity,
72
+ enumerable: true
73
+ },
74
+ name: {
75
+ value: parts.identity.name,
76
+ enumerable: true
77
+ },
78
+ schema: {
79
+ value: parts.schema,
80
+ enumerable: true
81
+ },
82
+ fields: {
83
+ value: fields,
84
+ enumerable: true
85
+ },
86
+ relations: {
87
+ get: () => current().relations,
88
+ enumerable: true
89
+ },
90
+ derived: {
91
+ get: () => current().derived,
92
+ enumerable: true
93
+ },
94
+ members: {
95
+ get: () => current().members,
96
+ enumerable: true
97
+ },
98
+ sets: {
99
+ get: () => current().sets,
100
+ enumerable: true
101
+ },
102
+ metadata: {
103
+ value: parts.metadata,
104
+ enumerable: true
105
+ }
106
+ });
107
+ Option.map(variantsOf(parts.identity), ({ union }) => Object.defineProperty(entity, "variants", {
108
+ value: union,
109
+ enumerable: true
110
+ }));
111
+ partsOf.set(entity, parts);
112
+ return Object.freeze(entity);
113
+ };
114
+ /** A new descriptor of the same Entity, with some of its own parts changed. */
115
+ const remake = (entity, changed) => make({
116
+ ...partsOf.get(entity),
117
+ ...changed
118
+ });
119
+ /** The relations every descriptor of the Entity `identity` names holds. */
120
+ const relationsOf = (identity) => shapeOf(identity).relations;
121
+ /** Adds to the Entity's shared members, which every descriptor of it then reads. */
122
+ const extend = (entity, added) => {
123
+ const shape = shapeOf(entity.identity);
124
+ for (const [key, member] of Object.entries(added.relations ?? {})) put(shape.relations, key, member);
125
+ for (const [key, member] of Object.entries(added.derived ?? {})) put(shape.derived, key, member);
126
+ for (const [key, set] of Object.entries(added.sets ?? {})) put(shape.sets, key, set);
127
+ shape.revision += 1;
128
+ };
129
+ const mapValues = (record, f) => Object.fromEntries(Object.entries(record).map(([key, value]) => [key, f(value, key)]));
130
+ /**
131
+ * A variant Entity's descriptor as declared, by its identity: each case's
132
+ * invariant is built over its fields when first read.
133
+ */
134
+ const variantBases = /* @__PURE__ */ new WeakMap();
135
+ export { extend, make, mapValues, partsOf, relationsOf, remake, variantBases };
136
+
137
+ //# sourceMappingURL=descriptor.js.map
@@ -0,0 +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 * member added through one descriptor is a member of every other, the one a\n * relation's `target()` returns and the one declared before `relate` alike.\n */\ninterface Shape {\n readonly relations: Record<string, EntityMember>\n readonly derived: Record<string, EntityMember>\n readonly sets: Record<string, EntitySet>\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: {}, 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/** Adds to the Entity's shared members, 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 },\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 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":";;;;;;;;;;;AA2BA,MAAM,yBAAS,IAAI,QAAuC;AAE1D,MAAM,WAAW,aAA4C;CAC3D,MAAM,QAAQ,OAAO,IAAI,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M,MAAM,KAAK,GAAG;CACnF,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"}
@@ -0,0 +1,231 @@
1
+ import { Option, Schema } from "effect";
2
+ import { Metadata } from "foldkit-metadata";
3
+ import { CheckCases, EntityVariants, StoredFields, VariantCases, VariantUnion } from "./variants.js";
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
+ import { SetOn } from "./sets.js";
6
+ import { check, invariant, invariantsOf as invariants, judge, judgeAgainst, judgeInput, readsBefore } from "./invariant.js";
7
+ import { OneRelation } from "./expr.js";
8
+ /** Unsatisfiable when a new key is already a member, so the pipe step is the error site. */
9
+ type Free<E extends AnyEntity, New> = keyof New & keyof E['members'] extends never ? unknown : {
10
+ readonly alreadyAMember: keyof New & keyof E['members'];
11
+ };
12
+ /** Unsatisfiable when a `Derived.count` or `Derived.exists` names a relation pointing at another Entity. */
13
+ type PointsHere<E extends AnyEntity, New extends DerivedSpecs> = { [K in keyof New]: New[K]['derives'] extends {
14
+ readonly _tag: 'Count' | 'Exists';
15
+ readonly relation: EntityRelation<any, any, infer Target, any, any>;
16
+ } ? [Target['name']] extends [E['name']] ? never : K : never; }[keyof New] extends (infer Wrong) ? [Wrong] extends [never] ? unknown : {
17
+ readonly countsRowsPointingAtAnotherEntity: Wrong;
18
+ } : never;
19
+ type WithDerived<E, New extends DerivedSpecs> = E extends VariantEntity<infer Name, infer Fields, infer R, infer D, infer U> ? VariantEntity<Name, Fields, R, D & New, U> : E extends Entity<infer Name, infer Fields, infer R, infer D> ? Entity<Name, Fields, R, D & New> : never;
20
+ /** Marks a relation key that is already a member of its owner, or an owner that is not listed. */
21
+ type CheckRelations<Es extends Entities, Rs> = { readonly [K in keyof Rs]: K extends keyof Es ? { readonly [R in keyof Rs[K]]: R extends keyof Es[K]['members'] ? `"${R & string}" is already a member of ${Es[K]['name']}` : Rs[K][R]; } : 'not one of the entities being related'; };
22
+ type RefSchema<Target extends AnyEntity> = Schema.Struct<{
23
+ readonly entity: Schema.Literal<Target['name']>;
24
+ readonly id: IdSchemaOf<Target>;
25
+ }>;
26
+ type AnySelection<Name extends string = string> = Selection<Name, any, any>;
27
+ type PageSchema<S extends Schema.Constraint> = Schema.Struct<{
28
+ readonly items: Schema.$Array<S>;
29
+ readonly hasNext: Schema.Boolean;
30
+ readonly hasPrevious: Schema.Boolean;
31
+ }>;
32
+ /** A variant Entity's cases, by tag, as the field sets of its union (`_tag` among them); never for one shape. */
33
+ type CaseFieldSets<E> = E extends {
34
+ readonly variants: {
35
+ readonly cases: infer C extends Readonly<Record<string, {
36
+ readonly fields: Schema.Struct.Fields;
37
+ }>>;
38
+ };
39
+ } ? { readonly [T in keyof C & string]: C[T]['fields']; } : never;
40
+ /** Whether `K` is a field only some cases have, selected without `_tag` to say which case a row is. */
41
+ type CaseOnlyWithoutTag<E extends AnyEntity, K, Spec> = [CaseFieldSets<E>] extends [never] ? false : '_tag' extends keyof Spec ? false : K extends keyof E['fields'] ? K extends keyof CaseFieldSets<E>[keyof CaseFieldSets<E>] ? false : true : false;
42
+ /** `true` for any member; a relation also takes a Selection of its target. */
43
+ type SelectionSpec<E extends AnyEntity, Spec> = { readonly [K in keyof Spec]: K extends keyof E['relations'] ? E['relations'][K] extends EntityRelation<any, any, infer Target, infer C, any> ? true | AnySelection<Target['name']> | (C extends 'many' ? SelectionPage<Target['name'], any> : never) : never : K extends keyof E['members'] ? CaseOnlyWithoutTag<E, K, Spec> extends true ? `"${K & string}" is a field of some cases of ${E['name']}; select _tag with it` : true : `"${K & string}" is not a member of ${E['name']}`; };
44
+ type RelationShape<C extends Cardinality, Optional extends boolean, S extends Schema.Constraint> = C extends 'many' ? Schema.$Array<S> : Optional extends true ? Schema.NullOr<S> : S;
45
+ type SelectedSchema<Member, Selected> = Member extends EntityField<any, any, infer S> | EntityDerived<any, any, infer S> ? S : Member extends EntityRelation<any, any, infer Target, infer C, infer Optional> ? Selected extends SelectionPage<any, infer S> ? PageSchema<S> : RelationShape<C, Optional, Selected extends Selection<any, any, infer S> ? S : RefSchema<Target>> : never;
46
+ type FlatSelectionSchema<E extends AnyEntity, Spec> = Schema.Struct<{ readonly [K in keyof Spec & keyof E['members']]: SelectedSchema<E['members'][K], Spec[K]>; }>;
47
+ /** What one case holds of a Selection: the selected fields it has, as it holds them, and every other member. */
48
+ type CaseSelectionFields<E extends AnyEntity, Spec, Fields> = { readonly [K in Exclude<keyof Spec & keyof E['members'], '_tag'> as K extends keyof E['fields'] ? K extends keyof Fields ? K : never : K]: K extends keyof Fields ? Fields[K] : SelectedSchema<E['members'][K], Spec[K]>; };
49
+ /**
50
+ * A Selection's schema: a Struct, or, for a variant Entity whose `_tag` is
51
+ * selected, a tagged union with a case per variant.
52
+ */
53
+ type SelectionSchema<E extends AnyEntity, Spec> = [CaseFieldSets<E>] extends [never] ? FlatSelectionSchema<E, Spec> : '_tag' extends keyof Spec ? Schema.TaggedUnion<{ readonly [T in keyof CaseFieldSets<E> & string]: Schema.TaggedStruct<T, CaseSelectionFields<E, Spec, CaseFieldSets<E>[T]>>; }> : FlatSelectionSchema<E, Spec>;
54
+ /** The ids a relation takes as input: one id, a nullable id, or a list of ids. */
55
+ type RelationIds<R> = R extends EntityRelation<any, any, infer Target, infer C, infer Optional> ? C extends 'many' ? ReadonlyArray<IdOf<Target>> : Optional extends true ? IdOf<Target> | null : IdOf<Target> : never;
56
+ /** What a nested input takes: the value of the target's input, or a list of them for a `many`. */
57
+ type NestedValues<R, I> = I extends EntityInput<any, infer Fields, any> ? R extends EntityRelation<any, any, any, 'many', any> ? ReadonlyArray<Schema.Struct.Type<Fields>> : Schema.Struct.Type<Fields> : never;
58
+ type Present<T> = Exclude<T, null | undefined>;
59
+ /** What an `Option` holds, else the value itself. */
60
+ type Held<T> = T extends Option.Some<infer A> ? Present<A> : T extends Option.None<any> ? never : Present<T>;
61
+ /**
62
+ * Whether an input value fits a field. Only the value that is present has to
63
+ * fit: an input may leave a key out (a partial update), send `null` to clear
64
+ * it, or hold an `Option` (an id absent for something new), whose value fits as
65
+ * it is (an `Option` field) or as what it holds. Whether it may is the input
66
+ * schema's rule; the fit only guards against mapping the wrong member.
67
+ */
68
+ type Fits<Input, Field> = [Present<Input>] extends [Field] ? true : [Held<Input>] extends [Field] ? true : false;
69
+ type MappingFor<Name extends string, Input, M> = M extends Unmapped ? M : M extends EntityField<infer Owner, any, any> | RelationInput<EntityRelation<infer Owner, any, any, any, any>> | NestedInput<EntityRelation<infer Owner, any, any, any, any>, any> ? [Owner] extends [Name] ? M extends EntityField<any, any, infer S> ? Fits<Input, Schema.Schema.Type<S>> extends true ? M : 'the input value does not fit this field' : M extends RelationInput<infer R> ? Present<Input> extends RelationIds<R> ? M : 'the input value is not the id shape of this relation' : M extends NestedInput<infer R, infer I> ? R extends EntityRelation<any, any, infer Target, any, any> ? I extends EntityInput<infer Of, any, any> ? [Of['name']] extends [Target['name']] ? Present<Input> extends NestedValues<R, I> ? M : 'the input value is not the value of the nested input' : `the nested input is of ${Of['name']}, not ${Target['name']}` : never : never : never : `this member belongs to ${Owner}` : 'map an input key to a Field, Relation.input(relation), Relation.nested(relation, input), or Entity.unmapped';
70
+ /** A key that names a field whose value it fits maps itself; every other key needs an entry. */
71
+ type SelfMapped<E extends AnyEntity, Fields extends Schema.Struct.Fields> = { [K in keyof Fields]: K extends keyof E['fields'] ? Fits<Schema.Schema.Type<Fields[K]>, Schema.Schema.Type<E['fields'][K]['schema']>> extends true ? K : never : never; }[keyof Fields];
72
+ /**
73
+ * A mapping written as a member's key: `'title'` is that Field, and `'author'` is
74
+ * `Relation.input` of that relation. Nothing is inferred from the input key's own
75
+ * name; the member is still named, only more briefly.
76
+ */
77
+ type Named<E extends AnyEntity, M> = M extends string ? M extends keyof E['fields'] ? E['fields'][M] : M extends keyof E['relations'] ? RelationInput<E['relations'][M]> : `"${M}" names no field or relation of ${E['name']}` : M;
78
+ type InputMapping<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = { readonly [K in Exclude<keyof Fields, SelfMapped<E, Fields>>]: unknown; } & { readonly [K in keyof Mapping]: K extends keyof Fields ? Named<E, Mapping[K]> extends (infer Member) ? Member extends string ? Member : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> extends Member ? Mapping[K] : MappingFor<E['name'], Schema.Schema.Type<Fields[K]>, Member> : never : `"${K & string}" is not a key of the input`; };
79
+ /** The member each key of an input writes, as `Entity.input` reads it from a mapping. */
80
+ export type InputMembers<E extends AnyEntity, Fields extends Schema.Struct.Fields, Mapping> = { readonly [K in keyof Fields]: K extends keyof Mapping ? Named<E, Mapping[K]> : K extends keyof E['fields'] ? E['fields'][K] : never; };
81
+ /** The Entity member an input key writes, by its key; nothing for an unmapped key. */
82
+ export type WrittenKey<M> = M extends EntityField<any, infer Key, any> ? Key : M extends RelationInput<EntityRelation<any, infer Key, any, any, any>> | NestedInput<EntityRelation<any, infer Key, any, any, any>, any> ? Key : never;
83
+ /** A nested input reads what it writes of the target; every other member reads as it is. */
84
+ export type WrittenAs<M> = M extends NestedInput<any, EntityInput<infer Of, any, infer Members>> ? Selection<Of['name'], WrittenSpec<Members>, SelectionSchema<Of, WrittenSpec<Members>>> : true;
85
+ /** Every member the input writes: what to read to show the input's current values. */
86
+ export type WrittenSpec<Members> = { readonly [K in keyof Members as WrittenKey<Members[K]>]: WrittenAs<Members[K]>; };
87
+ /**
88
+ * The schema a Selection of `entity` reads, given each selected member's
89
+ * schema by key: a Struct, or, for a variant Entity whose `_tag` is among
90
+ * them, its tagged union (each case keeps the selected fields it has, as it
91
+ * holds them). An interpreter that reads members its own way (Remote reads a
92
+ * relation as a ref) builds a Selection's value with it.
93
+ *
94
+ * A variant Entity's Selection: with `_tag`, a tagged union whose cases hold
95
+ * the selected fields they have, each as the case holds it, and every
96
+ * selected relation and derived member; without it, the stored row's Struct,
97
+ * refused when it selects a field only some cases have.
98
+ */
99
+ export declare const selectionSchema: (entity: AnyEntity, selected: Readonly<Record<string, Schema.Constraint>>) => Schema.Top;
100
+ /** For an input key that is about the operation rather than the Entity. */
101
+ export declare const unmapped: Unmapped;
102
+ /** True when both descriptors are versions of one Entity. */
103
+ declare const isSameEntity: (left: AnyEntity, right: AnyEntity) => boolean;
104
+ declare const isEntity: (value: unknown) => value is AnyEntity;
105
+ /** Declares an Entity from its intrinsic fields. Each call is a new identity. */
106
+ export declare const define: <const Name extends string, Fields extends Schema.Struct.Fields>(name: Name, schema: Schema.Struct<Fields>) => Entity<Name, Fields>;
107
+ /**
108
+ * Declares an Entity whose rows are one of several shapes, each case's fields
109
+ * by its tag:
110
+ *
111
+ * ```ts
112
+ * const Domain = Entity.defineVariants('Domain', {
113
+ * Available: { ...DomainName.fields, ...DomainQuote.fields },
114
+ * Unconfirmed: DomainName.fields,
115
+ * })
116
+ * Domain.variants.match(row, { Available: ({ price }) => price, Unconfirmed: () => 0 })
117
+ * ```
118
+ *
119
+ * A row is `Domain.variants`, Effect's tagged union of the cases. The stored
120
+ * row is `fields` and `schema`: `_tag`, the fields every case has, and each
121
+ * other field nullable, null on a row of another case. Each case with fields
122
+ * of its own gets an invariant saying so (`variant_Available`), which a
123
+ * database binding writes as a CHECK. A key in several cases is one stored
124
+ * field, so it is declared with one schema, spread into each case. Refused
125
+ * here: fewer than two cases, a case declaring `_tag`, an optional key.
126
+ */
127
+ export declare const defineVariants: <const Name extends string, const Cases extends VariantCases>(name: Name, cases: Cases & CheckCases<Cases>) => VariantEntity<Name, StoredFields<Cases>, {}, {}, VariantUnion<Cases>>;
128
+ /**
129
+ * An Entity's variants as an interpreter reads them: the union, each case's
130
+ * fields, and the codec from a stored row to its case. None for an Entity of
131
+ * one shape.
132
+ */
133
+ export declare const variantsOf: (entity: AnyEntity) => Option.Option<EntityVariants>;
134
+ /**
135
+ * Declares the relations between a set of Entities in one step, and returns
136
+ * them related. One step, because Entities that point at each other cannot
137
+ * each be declared in terms of the other.
138
+ */
139
+ 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 cascades through, and the Entity that owns it, whose rows go. */
141
+ export interface Cascade {
142
+ readonly relation: OneRelation;
143
+ readonly owner: AnyEntity;
144
+ }
145
+ /**
146
+ * The `one` relations, of any Entity, declared `onDelete: 'cascade'` that point
147
+ * at `entity`: deleting one of its rows deletes each row pointing at it through
148
+ * one, and so on from those. The owner is the Entity as it was related, whose
149
+ * members every descriptor of it shares.
150
+ */
151
+ export declare const cascading: (entity: AnyEntity) => ReadonlyArray<Cascade>;
152
+ /**
153
+ * Selects members of an Entity and assembles the schema of the result. A
154
+ * relation selected with `true` yields an `EntityRef`; with a Selection of its
155
+ * target, that Selection's value. `many` yields an array, an optional `one`
156
+ * is nullable.
157
+ */
158
+ export declare const select: <E extends AnyEntity, const Spec>(entity: E, spec: Spec & SelectionSpec<E, Spec>) => Selection<E['name'], Spec, SelectionSchema<E, Spec>, IdOf<E>>;
159
+ /**
160
+ * A `many` relation read a page at a time, in place of its Selection:
161
+ * `comments: Entity.page(CommentSummary, { first: 10 })`. The value is a page
162
+ * of the Selection's values: `items`, `hasNext`, `hasPrevious`. Reading on from a cursor is another window.
163
+ */
164
+ export declare const page: <Name extends string, S extends Schema.Constraint>(selection: Selection<Name, any, S>, window: PageWindow) => SelectionPage<Name, S>;
165
+ /**
166
+ * Adds readable members that are not part of `entity.schema`. A
167
+ * `Derived.count` or `Derived.exists` must read rows pointing at this
168
+ * Entity: one over a relation to another is refused here, as is an exists
169
+ * whose viewer is not another `one` relation of the same pointing Entity.
170
+ */
171
+ export declare const derived: <const New extends DerivedSpecs>(specs: New) => <E extends AnyEntity>(entity: E & Free<E, New> & PointsHere<E, New>) => WithDerived<E, New>;
172
+ /**
173
+ * Says which members take their value from the write's context, never its
174
+ * input: `Expr.viewer(User)`, whoever asks (a `one` relation to a User, or a
175
+ * field holding their id), and `Expr.now`, when (a field stored as a
176
+ * number). `on` says which writes set them: `'create'`, every insert, or
177
+ * `'write'`, every insert and every update.
178
+ *
179
+ * ```ts
180
+ * const Post = Blog.Post.pipe(
181
+ * Entity.sets({ author: Expr.viewer(User), createdAt: Expr.now }, { on: 'create' }),
182
+ * Entity.sets({ editedAt: Expr.now }, { on: 'write' }),
183
+ * )
184
+ * ```
185
+ *
186
+ * Every write of the Entity follows from it: a server writes the values and
187
+ * a client predicts them, and a write whose input sets one is refused where
188
+ * it is declared. Refused here: the id, a member set already, a `many`
189
+ * relation, a relation set to anything but the viewer of its target, and a
190
+ * field that cannot hold its value. Added after `Entity.relate` to set a
191
+ * relation.
192
+ */
193
+ export declare const sets: <E extends AnyEntity>(values: EntitySets<E>, options: {
194
+ readonly on: SetOn;
195
+ }) => (entity: E) => E;
196
+ /** Attaches an interpreter's metadata to the Entity itself. */
197
+ export declare const annotate: (metadata: Metadata) => <E extends AnyEntity>(entity: E) => E;
198
+ /** Attaches an interpreter's metadata to members, by key. */
199
+ export declare const annotateMembers: <E extends AnyEntity>(metadata: { readonly [K in keyof E['members']]?: Metadata; }) => (entity: E) => E;
200
+ /**
201
+ * Reads an operation's input schema against an Entity. A key that names a
202
+ * field maps to it; any other key is mapped explicitly, to a Field, to
203
+ * `Relation.input(relation)`, or to `Entity.unmapped`. Nothing is inferred
204
+ * from a naming convention such as `authorId`.
205
+ */
206
+ export declare const input: <E extends AnyEntity, Fields extends Schema.Struct.Fields, const Mapping = {}>(entity: E, schema: Schema.Struct<Fields>, ...mapping: keyof InputMapping<E, Fields, Mapping> extends never ? [mapping?: Mapping & InputMapping<E, Fields, Mapping>] : [mapping: Mapping & InputMapping<E, Fields, Mapping>]) => EntityInput<E, Fields, InputMembers<E, Fields, Mapping>>;
207
+ /**
208
+ * The schemas of some of an Entity's fields, by key, to spread into an input's
209
+ * struct: `Schema.Struct({ ...Entity.fields(Post, 'id', 'title'), editorId: ... })`.
210
+ * The input then keeps the field's own rules, and its keys map themselves.
211
+ */
212
+ export declare const fields: <E extends AnyEntity, const Keys extends ReadonlyArray<keyof E['fields'] & string>>(entity: E, ...keys: Keys) => { readonly [K in Keys[number]]: E['fields'][K]['schema']; };
213
+ /**
214
+ * The Selection of every member an input writes, with each relation as refs:
215
+ * what an edit screen loads before it shows the input's current values.
216
+ * `also` names members to read beside them, each with `true` (what a lock
217
+ * reads). The Selection is typed as the input's alone: what it reads has
218
+ * those members, and these besides.
219
+ */
220
+ export declare const selectFor: <E extends AnyEntity, Fields extends Schema.Struct.Fields, Members>(input: EntityInput<E, Fields, Members>, options?: {
221
+ readonly also?: Readonly<Record<string, true>> | undefined;
222
+ }) => Selection<E['name'], WrittenSpec<Members>, SelectionSchema<E, WrittenSpec<Members>>, IdOf<E>>;
223
+ /**
224
+ * The input values that reproduce `value`, a value read through `selectFor`
225
+ * (or any Selection with those members): a field as it is, a relation as the
226
+ * id or ids of its refs. A key whose member `value` lacks is left out, as is
227
+ * an unmapped key, which the Entity knows nothing about.
228
+ */
229
+ 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 };
231
+ //# sourceMappingURL=entity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity.d.ts","names":[],"sources":["../src/entity.ts"],"mappings":";;;;;;;;KA6DK,KAAK,UAAU,WAAW,aAAa,YAAY;WAEzC,sBAAsB,YAAY;;;KAG5C,WAAW,UA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