foldkit-entity 0.17.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 +466 -227
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +10 -4
- package/dist/conformance/index.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 +3 -2
- package/dist/entity.d.ts.map +1 -1
- package/dist/entity.js +5 -3
- 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 +11 -5
- package/dist/evaluate.d.ts.map +1 -1
- package/dist/evaluate.js +27 -6
- package/dist/evaluate.js.map +1 -1
- package/dist/expr.d.ts +8 -2
- package/dist/expr.d.ts.map +1 -1
- package/dist/expr.js +19 -10
- 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/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- 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 +83 -38
- package/dist/invariant.js.map +1 -1
- 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/operators.d.ts +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/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 +64 -6
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +88 -12
- package/dist/write.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Data, Schema } from "effect";
|
|
2
|
+
import { EntityField, EntityIdentity } from "./index.js";
|
|
3
|
+
export type Footprint = Data.TaggedEnum<{
|
|
4
|
+
/** Read off a declared write. */
|
|
5
|
+
Derived: {
|
|
6
|
+
readonly reads: ReadonlyArray<string>;
|
|
7
|
+
readonly writes: ReadonlyArray<string>;
|
|
8
|
+
};
|
|
9
|
+
/** The author's word, and whose (`by`): kept by disjointness alone, never enumerated. */
|
|
10
|
+
Declared: {
|
|
11
|
+
readonly entity: string;
|
|
12
|
+
readonly reads: ReadonlyArray<string>;
|
|
13
|
+
readonly writes: ReadonlyArray<string>;
|
|
14
|
+
readonly by: string;
|
|
15
|
+
};
|
|
16
|
+
/** Writes every member: undecided against every invariant of its Entity. */
|
|
17
|
+
Unknown: {};
|
|
18
|
+
}>;
|
|
19
|
+
/** A declared footprint over the Entity named `Name`. */
|
|
20
|
+
export type DeclaredFootprint<Name extends string> = Extract<Footprint, {
|
|
21
|
+
_tag: 'Declared';
|
|
22
|
+
}> & {
|
|
23
|
+
readonly entity: Name;
|
|
24
|
+
};
|
|
25
|
+
type AnyField = EntityField<string, string, Schema.Constraint>;
|
|
26
|
+
type OwnerOf<F> = F extends EntityField<infer Name, string, Schema.Constraint> ? Name : never;
|
|
27
|
+
/** The Entity each declared footprint's fields belong to, so an entry over another is refused. */
|
|
28
|
+
export declare const declaredOwner: WeakMap<{
|
|
29
|
+
readonly _tag: "Declared";
|
|
30
|
+
readonly entity: string;
|
|
31
|
+
readonly reads: ReadonlyArray<string>;
|
|
32
|
+
readonly writes: ReadonlyArray<string>;
|
|
33
|
+
readonly by: string;
|
|
34
|
+
} | {
|
|
35
|
+
readonly _tag: "Derived";
|
|
36
|
+
readonly reads: ReadonlyArray<string>;
|
|
37
|
+
readonly writes: ReadonlyArray<string>;
|
|
38
|
+
} | {
|
|
39
|
+
readonly _tag: "Unknown";
|
|
40
|
+
}, EntityIdentity<string>>;
|
|
41
|
+
export declare const Footprint: {
|
|
42
|
+
Derived: Data.TaggedEnum.ConstructorFrom<{
|
|
43
|
+
readonly _tag: "Derived";
|
|
44
|
+
readonly reads: ReadonlyArray<string>;
|
|
45
|
+
readonly writes: ReadonlyArray<string>;
|
|
46
|
+
}, "_tag">;
|
|
47
|
+
/**
|
|
48
|
+
* What the author says a transition reads and writes, by field reference
|
|
49
|
+
* (`Product.fields.name`), and on whose word (`by`). Every field is of one
|
|
50
|
+
* Entity: another's throws here, and is a type error where the entry names
|
|
51
|
+
* its Entity.
|
|
52
|
+
*/
|
|
53
|
+
declared: <const R extends AnyField = never, const W extends AnyField = never>(declared: {
|
|
54
|
+
readonly reads?: ReadonlyArray<R>;
|
|
55
|
+
readonly writes: ReadonlyArray<W>;
|
|
56
|
+
readonly by: string;
|
|
57
|
+
}) => DeclaredFootprint<OwnerOf<R | W>>;
|
|
58
|
+
/** Nothing is known of what it writes, so every member: never kept. */
|
|
59
|
+
unknown: Extract<Footprint, {
|
|
60
|
+
readonly _tag: 'Unknown';
|
|
61
|
+
}>;
|
|
62
|
+
$match: {
|
|
63
|
+
<Cases extends { readonly [Tag in "Declared" | "Derived" | "Unknown"]: (args: Extract<{
|
|
64
|
+
readonly _tag: "Declared";
|
|
65
|
+
readonly entity: string;
|
|
66
|
+
readonly reads: ReadonlyArray<string>;
|
|
67
|
+
readonly writes: ReadonlyArray<string>;
|
|
68
|
+
readonly by: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly _tag: "Derived";
|
|
71
|
+
readonly reads: ReadonlyArray<string>;
|
|
72
|
+
readonly writes: ReadonlyArray<string>;
|
|
73
|
+
} | {
|
|
74
|
+
readonly _tag: "Unknown";
|
|
75
|
+
}, {
|
|
76
|
+
readonly _tag: Tag;
|
|
77
|
+
}>) => any; }>(cases: Cases): (value: {
|
|
78
|
+
readonly _tag: "Declared";
|
|
79
|
+
readonly entity: string;
|
|
80
|
+
readonly reads: ReadonlyArray<string>;
|
|
81
|
+
readonly writes: ReadonlyArray<string>;
|
|
82
|
+
readonly by: string;
|
|
83
|
+
} | {
|
|
84
|
+
readonly _tag: "Derived";
|
|
85
|
+
readonly reads: ReadonlyArray<string>;
|
|
86
|
+
readonly writes: ReadonlyArray<string>;
|
|
87
|
+
} | {
|
|
88
|
+
readonly _tag: "Unknown";
|
|
89
|
+
}) => import("effect/Unify").Unify<ReturnType<Cases["Declared" | "Derived" | "Unknown"]>>;
|
|
90
|
+
<Cases extends { readonly [Tag in "Declared" | "Derived" | "Unknown"]: (args: Extract<{
|
|
91
|
+
readonly _tag: "Declared";
|
|
92
|
+
readonly entity: string;
|
|
93
|
+
readonly reads: ReadonlyArray<string>;
|
|
94
|
+
readonly writes: ReadonlyArray<string>;
|
|
95
|
+
readonly by: string;
|
|
96
|
+
} | {
|
|
97
|
+
readonly _tag: "Derived";
|
|
98
|
+
readonly reads: ReadonlyArray<string>;
|
|
99
|
+
readonly writes: ReadonlyArray<string>;
|
|
100
|
+
} | {
|
|
101
|
+
readonly _tag: "Unknown";
|
|
102
|
+
}, {
|
|
103
|
+
readonly _tag: Tag;
|
|
104
|
+
}>) => any; }>(value: {
|
|
105
|
+
readonly _tag: "Declared";
|
|
106
|
+
readonly entity: string;
|
|
107
|
+
readonly reads: ReadonlyArray<string>;
|
|
108
|
+
readonly writes: ReadonlyArray<string>;
|
|
109
|
+
readonly by: string;
|
|
110
|
+
} | {
|
|
111
|
+
readonly _tag: "Derived";
|
|
112
|
+
readonly reads: ReadonlyArray<string>;
|
|
113
|
+
readonly writes: ReadonlyArray<string>;
|
|
114
|
+
} | {
|
|
115
|
+
readonly _tag: "Unknown";
|
|
116
|
+
}, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["Declared" | "Derived" | "Unknown"]>>;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export {};
|
|
120
|
+
//# sourceMappingURL=footprint.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"footprint.d.ts","names":[],"sources":["../src/footprint.ts"],"mappings":";;YASY,YAAY,KAAK;;EAE3B;aAAoB,OAAO;aAAgC,QAAQ;;;EAEnE;aACW;aACA,OAAO;aACP,QAAQ;aACR;;;EAGX;;;YAMU,kBAAkB,uBAAuB,QAAQ;EAAa;;WAC/D,QAAQ;;KAGd,WAAW,4BAA4B,OAAO;KAC9C,QAAQ,KAAK,UAAU,kBAAkB,cAAc,OAAO,cAAc;;qBAGpE,eAAa;;WApBL;WACD,OAAA;WACC,QAAA;WACJ;;;WANY,OAAA;WAAwC,QAAA;;;GAuBQ;qBAEhE;EACX,SAAO,KAAA,WAAA;;aA1BoB,OAAA;aAAwC,QAAA;;;;;;;;EAiCnE,iBAAiB,UAAU,wBAAwB,UAAU,kBAAgB;aAClE,QAAQ,cAAc;aACtB,QAAQ,cAAc;aACtB;QACP,kBAAkB,QAAQ,IAAI;;EAsBlC,SAAiC,QAAQ;aAAsB;;EAC/D;;;eAzDmB;eACD,OAAA;eACC,QAAA;eACJ;;;eANY,OAAA;eAAwC,QAAA;;;;;;;;;;;;;;;;;;;;eAGhD;eACD,OAAA;eACC,QAAA;eACJ;;;eANY,OAAA;eAAwC,QAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Data } from "effect";
|
|
2
|
+
// src/footprint.ts
|
|
3
|
+
/**
|
|
4
|
+
* A transition's footprint: the members of its Entity it reads and writes, by
|
|
5
|
+
* field key. `Laws.check` reads one per entry, derived from a declared write
|
|
6
|
+
* (`Write.footprint`), declared by the author for a transition that is not one,
|
|
7
|
+
* or unknown, which writes every member.
|
|
8
|
+
*/
|
|
9
|
+
const Footprints = Data.taggedEnum();
|
|
10
|
+
/** The Entity each declared footprint's fields belong to, so an entry over another is refused. */
|
|
11
|
+
const declaredOwner = /* @__PURE__ */ new WeakMap();
|
|
12
|
+
const Footprint = {
|
|
13
|
+
Derived: Footprints.Derived,
|
|
14
|
+
/**
|
|
15
|
+
* What the author says a transition reads and writes, by field reference
|
|
16
|
+
* (`Product.fields.name`), and on whose word (`by`). Every field is of one
|
|
17
|
+
* Entity: another's throws here, and is a type error where the entry names
|
|
18
|
+
* its Entity.
|
|
19
|
+
*/
|
|
20
|
+
declared: (declared) => {
|
|
21
|
+
const fields = [...declared.reads ?? [], ...declared.writes];
|
|
22
|
+
const owner = fields[0]?.owner;
|
|
23
|
+
if (owner === void 0) throw new Error("[foldkit-entity] Footprint.declared names no field; it needs one to say whose");
|
|
24
|
+
const stranger = fields.find((field) => field.owner !== owner);
|
|
25
|
+
if (stranger !== void 0) throw new Error(`[foldkit-entity] Footprint.declared names ${owner.name}'s fields and ${stranger.owner.name}.${stranger.key}; a footprint is of one Entity`);
|
|
26
|
+
const footprint = Footprints.Declared({
|
|
27
|
+
entity: owner.name,
|
|
28
|
+
reads: (declared.reads ?? []).map((field) => field.key),
|
|
29
|
+
writes: declared.writes.map((field) => field.key),
|
|
30
|
+
by: declared.by
|
|
31
|
+
});
|
|
32
|
+
declaredOwner.set(footprint, owner);
|
|
33
|
+
return footprint;
|
|
34
|
+
},
|
|
35
|
+
/** Nothing is known of what it writes, so every member: never kept. */
|
|
36
|
+
unknown: Footprints.Unknown(),
|
|
37
|
+
$match: Footprints.$match
|
|
38
|
+
};
|
|
39
|
+
export { Footprint, declaredOwner };
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=footprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"footprint.js","names":[],"sources":["../src/footprint.ts"],"sourcesContent":["/**\n * A transition's footprint: the members of its Entity it reads and writes, by\n * field key. `Laws.check` reads one per entry, derived from a declared write\n * (`Write.footprint`), declared by the author for a transition that is not one,\n * or unknown, which writes every member.\n */\nimport { Data, type Schema } from 'effect'\nimport type { EntityField, EntityIdentity } from './index.js'\n\nexport type Footprint = Data.TaggedEnum<{\n /** Read off a declared write. */\n Derived: { readonly reads: ReadonlyArray<string>; readonly writes: ReadonlyArray<string> }\n /** The author's word, and whose (`by`): kept by disjointness alone, never enumerated. */\n Declared: {\n readonly entity: string\n readonly reads: ReadonlyArray<string>\n readonly writes: ReadonlyArray<string>\n readonly by: string\n }\n /** Writes every member: undecided against every invariant of its Entity. */\n Unknown: {}\n}>\n\nconst Footprints = Data.taggedEnum<Footprint>()\n\n/** A declared footprint over the Entity named `Name`. */\nexport type DeclaredFootprint<Name extends string> = Extract<Footprint, { _tag: 'Declared' }> & {\n readonly entity: Name\n}\n\ntype AnyField = EntityField<string, string, Schema.Constraint>\ntype OwnerOf<F> = F extends EntityField<infer Name, string, Schema.Constraint> ? Name : never\n\n/** The Entity each declared footprint's fields belong to, so an entry over another is refused. */\nexport const declaredOwner = new WeakMap<Footprint, EntityIdentity<string>>()\n\nexport const Footprint = {\n Derived: Footprints.Derived,\n /**\n * What the author says a transition reads and writes, by field reference\n * (`Product.fields.name`), and on whose word (`by`). Every field is of one\n * Entity: another's throws here, and is a type error where the entry names\n * its Entity.\n */\n declared: <const R extends AnyField = never, const W extends AnyField = never>(declared: {\n readonly reads?: ReadonlyArray<R>\n readonly writes: ReadonlyArray<W>\n readonly by: string\n }): DeclaredFootprint<OwnerOf<R | W>> => {\n const fields = [...(declared.reads ?? []), ...declared.writes]\n const owner = fields[0]?.owner\n if (owner === undefined)\n throw new Error(\n '[foldkit-entity] Footprint.declared names no field; it needs one to say whose',\n )\n const stranger = fields.find(field => field.owner !== owner)\n if (stranger !== undefined)\n throw new Error(\n `[foldkit-entity] Footprint.declared names ${owner.name}'s fields and ${stranger.owner.name}.${stranger.key}; a footprint is of one Entity`,\n )\n const footprint = Footprints.Declared({\n entity: owner.name,\n reads: (declared.reads ?? []).map(field => field.key),\n writes: declared.writes.map(field => field.key),\n by: declared.by,\n })\n declaredOwner.set(footprint, owner)\n return footprint as DeclaredFootprint<OwnerOf<R | W>>\n },\n /** Nothing is known of what it writes, so every member: never kept. */\n unknown: Footprints.Unknown() as Extract<Footprint, { readonly _tag: 'Unknown' }>,\n $match: Footprints.$match,\n}\n"],"mappings":";;;;;;;;AAuBA,MAAM,aAAa,KAAK,WAAsB;;AAW9C,MAAa,gCAAgB,IAAI,QAA2C;AAE5E,MAAa,YAAY;CACvB,SAAS,WAAW;;;;;;;CAOpB,WAA+E,aAItC;EACvC,MAAM,SAAS,CAAC,GAAI,SAAS,SAAS,CAAC,GAAI,GAAG,SAAS,MAAM;EAC7D,MAAM,QAAQ,OAAO,EAAE,EAAE;EACzB,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,MACR,+EACF;EACF,MAAM,WAAW,OAAO,MAAK,UAAS,MAAM,UAAU,KAAK;EAC3D,IAAI,aAAa,KAAA,GACf,MAAM,IAAI,MACR,6CAA6C,MAAM,KAAK,gBAAgB,SAAS,MAAM,KAAK,GAAG,SAAS,IAAI,+BAC9G;EACF,MAAM,YAAY,WAAW,SAAS;GACpC,QAAQ,MAAM;GACd,QAAQ,SAAS,SAAS,CAAC,EAAA,CAAG,KAAI,UAAS,MAAM,GAAG;GACpD,QAAQ,SAAS,OAAO,KAAI,UAAS,MAAM,GAAG;GAC9C,IAAI,SAAS;EACf,CAAC;EACD,cAAc,IAAI,WAAW,KAAK;EAClC,OAAO;CACT;;CAEA,SAAS,WAAW,QAAQ;CAC5B,QAAQ,WAAW;AACrB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,21 +4,26 @@ import { Metadata } from "foldkit-metadata";
|
|
|
4
4
|
import { EntityTypeId, EntityTypeId as EntityTypeId$1, SelectionPageTypeId, SelectionPageTypeId as SelectionPageTypeId$1, SelectionTypeId, SelectionTypeId as SelectionTypeId$1 } from "./ids.js";
|
|
5
5
|
import { AnyVariantUnion, AnyVariantUnion as AnyVariantUnion$1, CheckCases, EntityVariants, StoredFields, VariantCases, VariantUnion } from "./variants.js";
|
|
6
6
|
import { ContextValue, EntitySet, EntitySet as EntitySet$1, SetOn } from "./sets.js";
|
|
7
|
+
import { AnyRefinement, Refinement, RefinementBuild, RefinementLiteral, RefinementOf } from "./refine.js";
|
|
7
8
|
import { AfterRow, BeforeRow, Change, DeclaredInvariant, Invariant, Judgement } from "./invariant.js";
|
|
8
9
|
import { HeldRow, HeldRows } from "./held.js";
|
|
9
10
|
import { ExprContext, ExprContext as ExprContext$1, NowExpr, NowExpr as NowExpr$1, ViewerExpr, ViewerExpr as ViewerExpr$1, ViewerPathExpr, ViewerPathExpr as ViewerPathExpr$1, contextValue, viewerIdOf } from "./context.js";
|
|
10
11
|
import { InputMembers, WrittenAs, WrittenKey, WrittenSpec } from "./entity.js";
|
|
12
|
+
import { DeclaredFootprint, Footprint } from "./footprint.js";
|
|
13
|
+
import { Arrow, Finding, FootprintEntry, LawEdge, LawEntry, LawFacts, LawNode, LawPair, LawReport, LawVerdict, Laws, WriteEntry, lawFactsOf } from "./laws.js";
|
|
14
|
+
import { lawId, transitionId } from "./lawIds.js";
|
|
11
15
|
import { AnyWrite, BoundWrite, Computation, ConditionedWrite, ContextRead, ContextSet, ContextValues, Write, WriteAssignment, WriteComputations, WriteCondition, WriteIncrement, WriteKind, WriteLink, WriteSet } from "./write.js";
|
|
16
|
+
import { Step } from "./enumerate.js";
|
|
12
17
|
export * from "./shape.js";
|
|
13
|
-
export * from "./
|
|
18
|
+
export * from "./evaluate.js";
|
|
14
19
|
export * from "./expr.js";
|
|
20
|
+
export * from "./collation.js";
|
|
15
21
|
export * from "./held.js";
|
|
16
22
|
export * from "./operators.js";
|
|
17
23
|
export * from "./law.js";
|
|
18
24
|
export * from "./text.js";
|
|
19
25
|
export * from "./readFilter.js";
|
|
20
26
|
export * from "./words.js";
|
|
21
|
-
export * from "./evaluate.js";
|
|
22
27
|
/**
|
|
23
28
|
* What makes two descriptors the same Entity. A pipe step returns a new
|
|
24
29
|
* descriptor with the same identity, so compare `identity`, never the objects.
|
|
@@ -407,6 +412,6 @@ export declare const Derived: {
|
|
|
407
412
|
readonly viewer: V;
|
|
408
413
|
}>;
|
|
409
414
|
};
|
|
410
|
-
export { type AfterRow, type AnyVariantUnion, type AnyWrite, type BeforeRow, type BoundWrite, type Change, type CheckCases, Computation, type ConditionedWrite, type ContextRead, type ContextSet, type ContextValue, type ContextValues, type DeclaredInvariant, type EntitySet, EntityTypeId, type EntityVariants, type ExprContext, type InputMembers, type Invariant, type Judgement, type NowExpr, SelectionPageTypeId, SelectionTypeId, type SetOn, type StoredFields, type VariantCases, type VariantUnion, type ViewerExpr, type ViewerPathExpr, Write, type WriteAssignment, type WriteComputations, type WriteCondition, type WriteIncrement, type WriteKind, type WriteLink, type WriteSet, type WrittenAs, type WrittenKey, type WrittenSpec, contextValue, viewerIdOf };
|
|
415
|
+
export { type AfterRow, type AnyRefinement, type AnyVariantUnion, type AnyWrite, type Arrow, type BeforeRow, type BoundWrite, type Change, type CheckCases, Computation, type ConditionedWrite, type ContextRead, type ContextSet, type ContextValue, type ContextValues, type DeclaredFootprint, type DeclaredInvariant, type EntitySet, EntityTypeId, type EntityVariants, type ExprContext, Finding, Footprint, type FootprintEntry, type InputMembers, type Invariant, type Judgement, LawEdge, type LawEntry, type LawFacts, LawNode, type LawPair, type LawReport, LawVerdict, Laws, type NowExpr, type Refinement, type RefinementBuild, type RefinementLiteral, type RefinementOf, SelectionPageTypeId, SelectionTypeId, type SetOn, type Step, type StoredFields, type VariantCases, type VariantUnion, type ViewerExpr, type ViewerPathExpr, Write, type WriteAssignment, type WriteComputations, type WriteCondition, type WriteEntry, type WriteIncrement, type WriteKind, type WriteLink, type WriteSet, type WrittenAs, type WrittenKey, type WrittenSpec, contextValue, lawFactsOf, lawId, transitionId, viewerIdOf };
|
|
411
416
|
export { EntityMembers as Entity };
|
|
412
417
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["ExprContext","EntityTypeId","EntitySet","AnyVariantUnion","NowExpr","ViewerExpr","ViewerPathExpr","SelectionTypeId","SelectionPageTypeId"],"sources":["../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["ExprContext","EntityTypeId","EntitySet","AnyVariantUnion","NowExpr","ViewerExpr","ViewerPathExpr","SelectionTypeId","SelectionPageTypeId"],"sources":["../src/index.ts"],"mappings":"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"}
|
package/dist/index.js
CHANGED
|
@@ -2,17 +2,20 @@ import { Data, Option, Schema } from "effect";
|
|
|
2
2
|
import { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from "./ids.js";
|
|
3
3
|
import { contextValue, viewerIdOf } from "./context.js";
|
|
4
4
|
import * as Entity from "./entity.js";
|
|
5
|
+
import { Footprint } from "./footprint.js";
|
|
6
|
+
import { Finding, LawEdge, LawNode, LawVerdict, Laws, lawFactsOf } from "./laws.js";
|
|
7
|
+
import { lawId, transitionId } from "./lawIds.js";
|
|
5
8
|
import { Computation, Write } from "./write.js";
|
|
6
9
|
export * from "./shape.js";
|
|
7
|
-
export * from "./
|
|
10
|
+
export * from "./evaluate.js";
|
|
8
11
|
export * from "./expr.js";
|
|
12
|
+
export * from "./collation.js";
|
|
9
13
|
export * from "./held.js";
|
|
10
14
|
export * from "./operators.js";
|
|
11
15
|
export * from "./law.js";
|
|
12
16
|
export * from "./text.js";
|
|
13
17
|
export * from "./readFilter.js";
|
|
14
18
|
export * from "./words.js";
|
|
15
|
-
export * from "./evaluate.js";
|
|
16
19
|
// src/index.ts
|
|
17
20
|
/**
|
|
18
21
|
* `foldkit-entity` — domain structure as typed values.
|
|
@@ -111,6 +114,6 @@ const Derived = {
|
|
|
111
114
|
})
|
|
112
115
|
})
|
|
113
116
|
};
|
|
114
|
-
export { Computation, Derivation, Derived, Entity, EntityTypeId, Relation, SelectionPageTypeId, SelectionTypeId, Write, contextValue, viewerIdOf };
|
|
117
|
+
export { Computation, Derivation, Derived, Entity, EntityTypeId, Finding, Footprint, LawEdge, LawNode, LawVerdict, Laws, Relation, SelectionPageTypeId, SelectionTypeId, Write, contextValue, lawFactsOf, lawId, transitionId, viewerIdOf };
|
|
115
118
|
|
|
116
119
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-entity` — domain structure as typed values.\n *\n * An Entity names its intrinsic Fields (one `Schema.Struct`), its Relations\n * (navigation edges to other Entities, declared with `Entity.relate`), and its Derived members (readable\n * values an interpreter supplies). It describes; it fetches, stores, and\n * renders nothing. Remote, Drizzle, and form packages interpret it and attach\n * what they need as `foldkit-metadata`.\n */\nimport { Data, Option, type Pipeable, Schema } from 'effect'\nimport type { Metadata } from 'foldkit-metadata'\nimport type { ExprContext, NowExpr, ViewerExpr, ViewerPathExpr } from './context.js'\nimport type { HeldRow, HeldRows } from './held.js'\nimport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\nimport type { EntitySet } from './sets.js'\n// The members of `Entity`, a namespace rather than an object so a page keeps only\n// those it calls (#378). Exported under the interface's name; `export * as`\n// would make each `Entity` type here a reference the declaration emitter refuses.\nimport * as EntityMembers from './entity.js'\nimport type { AnyVariantUnion } from './variants.js'\n\nexport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\n\n/**\n * What makes two descriptors the same Entity. A pipe step returns a new\n * descriptor with the same identity, so compare `identity`, never the objects.\n */\nexport interface EntityIdentity<Name extends string> {\n readonly name: Name\n /** Distinguishes two Entities that were defined with the same name. */\n readonly token: symbol\n}\n\n/** An intrinsic value of the Entity: one property of `entity.schema`. */\nexport interface EntityField<Name extends string, Key extends string, S extends Schema.Constraint> {\n readonly _tag: 'Field'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n readonly schema: S\n readonly metadata: Metadata\n}\n\nexport type Cardinality = 'one' | 'many'\n\n/**\n * What happens to a row when the row its `one` relation points at is deleted\n * (`Relation.one(Post, { onDelete: 'cascade' })`): `cascade`, it is deleted\n * with it, by the server in the write that deletes, and foreseen by a client;\n * `restrict`, the delete is refused while any row points there (#467), naming\n * the relation and none of the rows; `setNull`, an optional link is cleared,\n * an update of the row held to its own `Update` rules.\n */\nexport type OnDelete = 'cascade' | 'restrict' | 'setNull'\n\n/**\n * Who may let a cascade take a row (#348). `child`, the default: the row's own\n * `Delete` rule, judged for whoever deletes the row it points at, so a delete\n * that would take a row they may not delete is refused whole. `parent`: whoever\n * may delete the row it points at may take it too (a post's author removing\n * the likes under it), declared on the relation so it is never a default.\n */\nexport type AuthorizedBy = 'child' | 'parent'\n\n/** What `Relation.one` / `Relation.many` return, before `Entity.relate` binds it to an owner. */\nexport interface RelationSpec<\n Target extends AnyEntity,\n C extends Cardinality,\n Optional extends boolean,\n> {\n readonly target: Target\n readonly cardinality: C\n readonly optional: Optional\n readonly onDelete: Option.Option<OnDelete>\n readonly authorizedBy: Option.Option<AuthorizedBy>\n}\n\n/**\n * A navigation edge as its owner sees it: one or many of `target`. How the edge\n * is stored (a foreign key, a join table, a nested document) is the\n * interpreter's concern.\n */\nexport interface EntityRelation<\n Name extends string,\n Key extends string,\n Target extends AnyEntity,\n C extends Cardinality,\n Optional extends boolean,\n> {\n readonly _tag: 'Relation'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n /** The target as `Entity.relate` returned it, so its own relations can be followed. */\n readonly target: () => Target\n readonly cardinality: C\n readonly optional: Optional\n /**\n * What happens to this row when the row a `one` relation points at is\n * deleted; none for a `many`, and for a `one` declared with nothing.\n */\n readonly onDelete: Option.Option<OnDelete>\n /** Who may let a cascade through it take this row: some exactly where `onDelete` is `cascade`. */\n readonly authorizedBy: Option.Option<AuthorizedBy>\n readonly metadata: Metadata\n}\n\ntype OneRelation = EntityRelation<string, string, AnyEntity, 'one', boolean>\n\n/**\n * What a derived member is. `Supplied` (`Derived.make`): an interpreter\n * supplies it, and nothing else can say what it is. `Count`\n * (`Derived.count`): how many rows point at this one through `relation`, a\n * `one` relation of the counted Entity. `Exists` (`Derived.exists`): the id of\n * a row pointing here through `relation` whose `viewer` relation points at\n * whoever reads it, or none. A client predicts both from the rows it writes,\n * and a server compiles both from the relations' storage.\n */\nexport type Derivation = Data.TaggedEnum<{\n /**\n * `predict`: how a client foresees it for a row it writes; none, it waits\n * for the server. `forbids`: which write to the row its value refuses, so a\n * client holding it refuses that write where it is made.\n */\n Supplied: { readonly predict: Option.Option<Predict>; readonly forbids: Option.Option<Forbids> }\n Count: { readonly relation: OneRelation }\n Exists: { readonly relation: OneRelation; readonly viewer: OneRelation }\n}>\nexport const Derivation = Data.taggedEnum<Derivation>()\n\n/** What a supplied member's prediction is given: the row a write leaves, as its holder has it. */\nexport interface Predicting {\n /** The Entity written, as the write declared it. */\n readonly entity: AnyEntity\n readonly row: HeldRow\n /** The holder's other rows, where a rule's path reads. */\n readonly rows: HeldRows\n /** The operation's context: who asks, and the write's time. */\n readonly context: ExprContext\n}\n\n/**\n * A supplied member foreseen: its value **encoded**, as the store holds it, or\n * none where the holder cannot know it, so nothing is shown before the answer.\n */\nexport type Predict = (predicting: Predicting) => Option.Option<unknown>\n\n/**\n * What a write does to a row it finds, as a supplied member's `forbids` is\n * asked: an update's members and the relations it points, or a delete.\n */\nexport interface WriteSurface {\n readonly kind: 'Update' | 'Delete'\n /** The members it sets, moves or computes, relations not among them. */\n readonly members: ReadonlyArray<string>\n /** Each relation it points: at a row (`Link`), or at none (`Unlink`). */\n readonly relations: ReadonlyArray<{\n readonly relation: string\n readonly interaction: 'Link' | 'Unlink'\n }>\n}\n\n/**\n * Whether a supplied member's value, **encoded** as the store holds it,\n * refuses `surface`, with the reader's words for why when there are any; none\n * where it does not say so for certain. Only a definite refusal: a client\n * refuses the write unseen, and its server would refuse it too.\n */\nexport type Forbids = (\n value: unknown,\n surface: WriteSurface,\n) => Option.Option<{ readonly reason: Option.Option<string> }>\n\n/** What `Derived.make`, `Derived.count` or `Derived.exists` returns, before an Entity owns it. */\nexport interface DerivedSpec<S extends Schema.Constraint, D extends Derivation = Derivation> {\n readonly schema: S\n readonly derives: D\n}\n\n/** A value consumers may read that is not part of `entity.schema`, and what it derives. */\nexport interface EntityDerived<\n Name extends string,\n Key extends string,\n S extends Schema.Constraint,\n D extends Derivation = Derivation,\n> {\n readonly _tag: 'Derived'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n readonly schema: S\n readonly derives: D\n readonly metadata: Metadata\n}\n\nexport type EntityMember =\n | EntityField<string, string, Schema.Constraint>\n | EntityRelation<string, string, AnyEntity, Cardinality, boolean>\n | EntityDerived<string, string, Schema.Constraint>\n\nexport type RelationSpecs = Readonly<Record<string, RelationSpec<AnyEntity, Cardinality, boolean>>>\nexport type DerivedSpecs = Readonly<Record<string, DerivedSpec<Schema.Constraint>>>\n\ntype FieldsOf<Name extends string, Fields extends Schema.Struct.Fields> = {\n readonly [K in keyof Fields & string]: EntityField<Name, K, Fields[K]>\n}\ntype RelationsOf<Name extends string, Relations extends RelationSpecs> = {\n readonly [K in keyof Relations & string]: Relations[K] extends RelationSpec<\n infer Target,\n infer C,\n infer Optional\n >\n ? EntityRelation<Name, K, Target, C, Optional>\n : never\n}\ntype DerivedOf<Name extends string, Derived extends DerivedSpecs> = {\n readonly [K in keyof Derived & string]: EntityDerived<\n Name,\n K,\n Derived[K]['schema'],\n Derived[K]['derives']\n >\n}\n\nexport interface Entity<\n Name extends string,\n Fields extends Schema.Struct.Fields,\n Relations extends RelationSpecs = {},\n Derived extends DerivedSpecs = {},\n>\n extends Pipeable.Pipeable {\n readonly [EntityTypeId]: EntityTypeId\n readonly identity: EntityIdentity<Name>\n readonly name: Name\n /** The intrinsic value only: no relations, no derived members. */\n readonly schema: Schema.Struct<Fields>\n readonly fields: FieldsOf<Name, Fields>\n readonly relations: RelationsOf<Name, Relations>\n readonly derived: DerivedOf<Name, Derived>\n /** Every readable member under one namespace; keys never collide. */\n readonly members: FieldsOf<Name, Fields> & RelationsOf<Name, Relations> & DerivedOf<Name, Derived>\n /** The members whose value is the write's context, never its input (`Entity.sets`), by key. */\n readonly sets: Readonly<Record<string, EntitySet>>\n readonly metadata: Metadata\n}\n\nexport type AnyEntity = Entity<string, any, any, any>\n\n/**\n * An Entity whose rows are one of several shapes (`Entity.defineVariants`).\n * `variants` is Effect's tagged union of them, read with its own `match`;\n * `fields` and `schema` are the stored row, which every case shares.\n */\nexport interface VariantEntity<\n Name extends string,\n Fields extends Schema.Struct.Fields,\n Relations extends RelationSpecs = {},\n Derived extends DerivedSpecs = {},\n Union extends AnyVariantUnion = AnyVariantUnion,\n> extends Entity<Name, Fields, Relations, Derived> {\n readonly variants: Union\n}\n\nexport type AnyVariantEntity = VariantEntity<string, any, any, any, any>\n\n/** The keys of an Entity's `one` relations. */\ntype OneRelationKeys<E extends AnyEntity> = {\n [K in keyof E['relations'] & string]: E['relations'][K]['cardinality'] extends 'one' ? K : never\n}[keyof E['relations'] & string]\n\n/**\n * What a field holding `T` may be set to: the time where it holds a number,\n * the viewer's id where text, and what a path from the viewer reads where it\n * holds that.\n */\ntype ContextValueFor<T> =\n | (number extends T ? NowExpr<number> : never)\n | (T extends string ? ViewerExpr<T> : never)\n | ViewerPathExpr<T | null>\n\n/** The name of the Entity the `one` relation `K` points at. */\ntype TargetName<E extends AnyEntity, K extends keyof E['relations']> = ReturnType<\n E['relations'][K]['target']\n>['name']\n\n/**\n * What `Entity.sets` takes, by member: a field the value of the write's\n * context it can hold, a `one` relation `Expr.viewer` of its target.\n */\nexport type EntitySets<E extends AnyEntity> = {\n readonly [K in Exclude<keyof E['fields'] & string, 'id'>]?: ContextValueFor<\n Schema.Schema.Type<E['fields'][K]['schema']>\n >\n} & {\n readonly [K in OneRelationKeys<E>]?: ViewerExpr<unknown, TargetName<E, K>>\n}\n\nexport type Entities = Readonly<Record<string, AnyEntity>>\nexport type RelationMap<Es extends Entities> = { readonly [K in keyof Es]?: RelationSpecs }\n\n/** The key in `Es` of the Entity a spec targets, matched by name. */\nexport type TargetKey<Es extends Entities, Target extends AnyEntity> = {\n [K in keyof Es]: [Es[K]['name'], Target['name']] extends [Target['name'], Es[K]['name']]\n ? K\n : never\n}[keyof Es]\n\nexport type RelatedSpecs<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> = {\n readonly [R in keyof Rs[K]]: Rs[K][R] extends RelationSpec<infer Target, infer C, infer Optional>\n ? RelationSpec<Related<Es, Rs, TargetKey<Es, Target>>, C, Optional>\n : never\n}\n\n/**\n * One Entity of an `Entity.relate` result. A relation's target is again a\n * `Related`, so relations can be followed through a cycle; the recursion goes\n * through type arguments, which TypeScript resolves only when asked.\n */\nexport type Related<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> =\n Es[K] extends VariantEntity<infer Name, infer Fields, infer R, infer D, infer U>\n ? VariantEntity<Name, Fields, R & RelatedSpecs<Es, Rs, K>, D, U>\n : Es[K] extends Entity<infer Name, infer Fields, infer R, infer D>\n ? Entity<Name, Fields, R & RelatedSpecs<Es, Rs, K>, D>\n : never\n\n/**\n * The schema that identifies one of an Entity: its `id` field when that is text\n * (a plain string, a brand, a pattern), and plain text otherwise. An id is text\n * because a ref travels and is stored as text; an Entity keyed by a number still\n * has refs, and their ids are the number as text.\n */\nexport type IdSchemaOf<E> = E extends {\n readonly fields: { readonly id: { readonly schema: infer S } }\n}\n ? S extends Schema.Constraint\n ? [S['Type']] extends [string]\n ? S\n : Schema.String\n : Schema.String\n : Schema.String\n\n/** What identifies one of an Entity: `IdOf<typeof Blog.Post>` is `PostId` when its `id` field is one. */\nexport type IdOf<E> = IdSchemaOf<E>['Type']\n\n/**\n * What a relation selected with `true` yields: which Entity, and which one. `Id`\n * is the target's own id type, so a ref to an Author cannot be used as a Post's.\n */\nexport interface EntityRef<Name extends string = string, Id extends string = string> {\n readonly entity: Name\n readonly id: Id\n}\n\n/**\n * A view of the Entity graph: which members to read, and the schema of the\n * value that results. It says nothing about where the value comes from.\n */\nexport interface Selection<\n Name extends string,\n Members,\n S extends Schema.Constraint,\n Id extends string = string,\n> {\n readonly [SelectionTypeId]: SelectionTypeId\n /** Type-only: the id type of the Entity selected, so a reader can ask for the right one. Never set. */\n readonly Id?: Id\n readonly entity: Entity<Name, any, any, any>\n /** What was selected, by member key: `true`, or a relation's nested Selection. */\n readonly members: Members\n readonly schema: S\n}\n\n/** The value a Selection reads: `Selected<typeof PostCard>` is one card's fields. */\nexport type Selected<S extends Selection<string, unknown, Schema.Constraint>> = S['schema']['Type']\n\n/**\n * Which part of a `many` relation to read: the first or last so many, from a\n * cursor or from the end. A cursor is whatever the interpreter handed out with an\n * earlier page; nothing here looks inside it.\n */\nexport interface PageWindow {\n readonly first?: number | undefined\n readonly last?: number | undefined\n readonly after?: string | undefined\n readonly before?: string | undefined\n}\n\n/** A Selection of a `many` relation's target, read a page at a time. */\nexport interface SelectionPage<Name extends string, S extends Schema.Constraint> {\n readonly [SelectionPageTypeId]: SelectionPageTypeId\n readonly selection: Selection<Name, any, S>\n readonly window: PageWindow\n}\n\n/** An input key that carries a relation's target: the id of a `one`, the ids of a `many`. */\nexport interface RelationInput<R extends EntityRelation<any, any, any, any, any>> {\n readonly _tag: 'RelationInput'\n readonly relation: R\n}\n\n/**\n * An input key that carries the relation's target itself, written through an\n * input of its own: a post created with a new author, an order with its lines.\n * A `one` holds that input's value, a `many` a list of them.\n */\nexport interface NestedInput<\n R extends EntityRelation<any, any, any, any, any>,\n I extends EntityInput<any, any, any>,\n> {\n readonly _tag: 'NestedInput'\n readonly relation: R\n readonly input: I\n}\n\n/** An input key that is about the operation, not the Entity: a reason, a flag, a confirmation. */\nexport interface Unmapped {\n readonly _tag: 'Unmapped'\n}\n\n/** What one key of an operation's input means in terms of the Entity. */\nexport type InputMember =\n | EntityField<string, string, Schema.Constraint>\n | RelationInput<EntityRelation<string, string, AnyEntity, Cardinality, boolean>>\n | NestedInput<\n EntityRelation<string, string, AnyEntity, Cardinality, boolean>,\n EntityInput<AnyEntity, any, any>\n >\n | Unmapped\n\n/**\n * An operation's input read against an Entity: which member each input key\n * writes. The operation decides what may be submitted; the Entity only says\n * what each submitted key means.\n */\nexport interface EntityInput<E extends AnyEntity, Fields extends Schema.Struct.Fields, Members> {\n readonly entity: E\n readonly schema: Schema.Struct<Fields>\n readonly members: Members\n}\n\nexport type { InputMembers, WrittenAs, WrittenKey, WrittenSpec } from './entity.js'\nexport { EntityMembers as Entity }\n\n/**\n * How a `one` relation is declared: whether it may point nowhere, and what a\n * delete of its target does. `authorizedBy` is said only beside `onDelete`.\n */\nexport type OneOptions<Optional extends boolean> = {\n readonly optional?: Optional\n} & (\n | { readonly onDelete?: undefined; readonly authorizedBy?: undefined }\n | {\n /** `cascade`: a row pointing here is deleted with the row it points at. */\n readonly onDelete: 'cascade'\n /** Whose `Delete` rule lets the cascade take this row: its own (`child`), or the parent's. */\n readonly authorizedBy?: AuthorizedBy\n }\n | {\n /** `restrict`: the row it points at cannot be deleted while this row points there. */\n readonly onDelete: 'restrict'\n readonly authorizedBy?: undefined\n }\n | {\n /** `setNull`: this row stays and points nowhere; only a link that may point nowhere can. */\n readonly onDelete: 'setNull'\n readonly optional: true\n readonly authorizedBy?: undefined\n }\n)\n\nfunction one<Target extends AnyEntity>(target: Target): RelationSpec<Target, 'one', false>\nfunction one<Target extends AnyEntity, const Optional extends boolean>(\n target: Target,\n options: OneOptions<Optional> & { readonly optional: Optional },\n): RelationSpec<Target, 'one', Optional>\nfunction one<Target extends AnyEntity>(\n target: Target,\n options: OneOptions<false>,\n): RelationSpec<Target, 'one', false>\nfunction one(\n target: AnyEntity,\n options?: OneOptions<boolean>,\n): RelationSpec<AnyEntity, 'one', boolean> {\n const onDelete = options?.onDelete\n const authorizedBy = options?.authorizedBy\n if (\n onDelete !== undefined &&\n onDelete !== 'cascade' &&\n onDelete !== 'restrict' &&\n onDelete !== 'setNull'\n )\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): onDelete is 'cascade', 'restrict' or 'setNull'; ${String(onDelete)} is not one`,\n )\n if (onDelete === 'setNull' && options?.optional !== true)\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): onDelete: 'setNull' clears the link, so it needs optional: true`,\n )\n if (authorizedBy !== undefined && authorizedBy !== 'child' && authorizedBy !== 'parent')\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): authorizedBy is 'child' or 'parent'; ${String(authorizedBy)} is not one`,\n )\n if (authorizedBy !== undefined && onDelete !== 'cascade')\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): authorizedBy says who lets a cascade take the row, so it needs onDelete: 'cascade'`,\n )\n return {\n target,\n cardinality: 'one',\n optional: options?.optional ?? false,\n onDelete: Option.fromUndefinedOr(onDelete),\n authorizedBy: onDelete === 'cascade' ? Option.some(authorizedBy ?? 'child') : Option.none(),\n }\n}\n\n/** What the owner sees: one or many of `target`. Used inside `Entity.relate`. */\nexport const Relation = {\n one,\n\n /** For `Entity.input`: the input key holds this relation's target id, or ids for a `many`. */\n input: <R extends EntityRelation<any, any, any, any, any>>(relation: R): RelationInput<R> =>\n Object.freeze({ _tag: 'RelationInput', relation }),\n\n /**\n * For `Entity.input`: the input key holds the relation's target itself, written\n * through `input`, an `Entity.input` of the target. A `many` holds a list.\n */\n nested: <R extends EntityRelation<any, any, any, any, any>, I extends EntityInput<any, any, any>>(\n relation: R,\n input: I,\n ): NestedInput<R, I> => Object.freeze({ _tag: 'NestedInput', relation, input }),\n\n many: <Target extends AnyEntity>(target: Target): RelationSpec<Target, 'many', false> => ({\n target,\n cardinality: 'many',\n optional: false,\n onDelete: Option.none(),\n authorizedBy: Option.none(),\n }),\n}\n\n/** A count: never negative, never a fraction. */\nconst CountSchema = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))\n\n/** The id of the row an exists found, as every Remote id is held: text, or none. */\nconst WitnessSchema = Schema.OptionFromNullOr(Schema.String)\n\ntype OwnerName<R> = R extends EntityRelation<infer Name, any, any, any, any> ? Name : never\n\nexport const Derived = {\n /**\n * A member only an interpreter can compute, of type `schema`: it supplies the\n * value. `predict` says how a client foresees it for a row it writes (Guard's\n * `may`); without it the row reads as missing the member until the answer.\n * `forbids` says which write to the row its value refuses (Guard's `may`\n * again), so a client holding it refuses that write where it is made.\n */\n make: <S extends Schema.Constraint>(\n schema: S,\n options: {\n readonly predict?: Predict | undefined\n readonly forbids?: Forbids | undefined\n } = {},\n ): DerivedSpec<S, Extract<Derivation, { readonly _tag: 'Supplied' }>> => ({\n schema,\n derives: Derivation.Supplied({\n predict: Option.fromUndefinedOr(options.predict),\n forbids: Option.fromUndefinedOr(options.forbids),\n }),\n }),\n\n /**\n * How many rows point at this one through `relation`, a `one` relation of\n * the counted Entity: `likeCount: Derived.count(Like.relations.post)` on\n * Post. Added after `Entity.relate`, which makes the relation. A server\n * compiles it from the relation's storage, and a client predicts it from\n * the rows a pending write inserts, deletes or points elsewhere.\n */\n count: <R extends EntityRelation<string, string, AnyEntity, 'one', boolean>>(\n relation: R,\n ): DerivedSpec<typeof CountSchema, { readonly _tag: 'Count'; readonly relation: R }> => ({\n schema: CountSchema,\n derives: Derivation.Count({ relation }) as { readonly _tag: 'Count'; readonly relation: R },\n }),\n\n /**\n * Whether a row points at this one through `relation` and at whoever reads\n * it through `viewer`, another `one` relation of the same pointing Entity:\n * `liked: Derived.exists(Like.relations.post, { viewer: Like.relations.user })`\n * on Post. Its value is that row's id as the store holds it, or none, so the\n * reader can take it back (`Write.delete` by that id). It depends on who\n * reads it: a server answers it for the principal it reads as, and a client\n * predicts it for the viewer it is told of.\n */\n exists: <\n R extends OneRelation,\n V extends EntityRelation<OwnerName<R>, string, AnyEntity, 'one', boolean>,\n >(\n relation: R,\n options: { readonly viewer: V },\n ): DerivedSpec<\n typeof WitnessSchema,\n { readonly _tag: 'Exists'; readonly relation: R; readonly viewer: V }\n > => ({\n schema: WitnessSchema,\n derives: Derivation.Exists({ relation, viewer: options.viewer }) as {\n readonly _tag: 'Exists'\n readonly relation: R\n readonly viewer: V\n },\n }),\n}\n\nexport * from './expr.js'\nexport {\n contextValue,\n viewerIdOf,\n type ExprContext,\n type NowExpr,\n type ViewerExpr,\n type ViewerPathExpr,\n} from './context.js'\nexport * from './collation.js'\nexport * from './operators.js'\nexport * from './law.js'\nexport * from './text.js'\nexport * from './readFilter.js'\nexport * from './words.js'\nexport * from './shape.js'\nexport type {\n AnyVariantUnion,\n CheckCases,\n EntityVariants,\n StoredFields,\n VariantCases,\n VariantUnion,\n} from './variants.js'\n// The reference semantics of the IR above. The conformance suite that proves\n// an interpreter agrees with it is `foldkit-entity/conformance`, kept out of\n// this entry because it is fixture data every form and admin screen would\n// otherwise carry.\nexport * from './evaluate.js'\nexport * from './held.js'\nexport type {\n AfterRow,\n BeforeRow,\n Change,\n DeclaredInvariant,\n Invariant,\n Judgement,\n} from './invariant.js'\nexport type { ContextValue, EntitySet, SetOn } from './sets.js'\nexport {\n Write,\n type AnyWrite,\n type BoundWrite,\n type ConditionedWrite,\n Computation,\n type WriteAssignment,\n type WriteComputations,\n type WriteCondition,\n type WriteIncrement,\n type WriteKind,\n type WriteLink,\n type WriteSet,\n type ContextSet,\n type ContextRead,\n type ContextValues,\n} from './write.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA8HA,MAAa,aAAa,KAAK,WAAuB;AA8VtD,SAAS,IACP,QACA,SACyC;CACzC,MAAM,WAAW,SAAS;CAC1B,MAAM,eAAe,SAAS;CAC9B,IACE,aAAa,KAAA,KACb,aAAa,aACb,aAAa,cACb,aAAa,WAEb,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,qDAAqD,OAAO,QAAQ,EAAE,YACrH;CACF,IAAI,aAAa,aAAa,SAAS,aAAa,MAClD,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,mEAC/C;CACF,IAAI,iBAAiB,KAAA,KAAa,iBAAiB,WAAW,iBAAiB,UAC7E,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,0CAA0C,OAAO,YAAY,EAAE,YAC9G;CACF,IAAI,iBAAiB,KAAA,KAAa,aAAa,WAC7C,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,sFAC/C;CACF,OAAO;EACL;EACA,aAAa;EACb,UAAU,SAAS,YAAY;EAC/B,UAAU,OAAO,gBAAgB,QAAQ;EACzC,cAAc,aAAa,YAAY,OAAO,KAAK,gBAAgB,OAAO,IAAI,OAAO,KAAK;CAC5F;AACF;;AAGA,MAAa,WAAW;CACtB;;CAGA,QAA2D,aACzD,OAAO,OAAO;EAAE,MAAM;EAAiB;CAAS,CAAC;;;;;CAMnD,SACE,UACA,UACsB,OAAO,OAAO;EAAE,MAAM;EAAe;EAAU;CAAM,CAAC;CAE9E,OAAiC,YAAyD;EACxF;EACA,aAAa;EACb,UAAU;EACV,UAAU,OAAO,KAAK;EACtB,cAAc,OAAO,KAAK;CAC5B;AACF;;AAGA,MAAM,cAAc,OAAO,OAAO,MAAM,OAAO,MAAM,GAAG,OAAO,uBAAuB,CAAC,CAAC;;AAGxF,MAAM,gBAAgB,OAAO,iBAAiB,OAAO,MAAM;AAI3D,MAAa,UAAU;;;;;;;;CAQrB,OACE,QACA,UAGI,CAAC,OACmE;EACxE;EACA,SAAS,WAAW,SAAS;GAC3B,SAAS,OAAO,gBAAgB,QAAQ,OAAO;GAC/C,SAAS,OAAO,gBAAgB,QAAQ,OAAO;EACjD,CAAC;CACH;;;;;;;;CASA,QACE,cACuF;EACvF,QAAQ;EACR,SAAS,WAAW,MAAM,EAAE,SAAS,CAAC;CACxC;;;;;;;;;;CAWA,SAIE,UACA,aAII;EACJ,QAAQ;EACR,SAAS,WAAW,OAAO;GAAE;GAAU,QAAQ,QAAQ;EAAO,CAAC;CAKjE;AACF"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * `foldkit-entity` — domain structure as typed values.\n *\n * An Entity names its intrinsic Fields (one `Schema.Struct`), its Relations\n * (navigation edges to other Entities, declared with `Entity.relate`), and its Derived members (readable\n * values an interpreter supplies). It describes; it fetches, stores, and\n * renders nothing. Remote, Drizzle, and form packages interpret it and attach\n * what they need as `foldkit-metadata`.\n */\nimport { Data, Option, type Pipeable, Schema } from 'effect'\nimport type { Metadata } from 'foldkit-metadata'\nimport type { ExprContext, NowExpr, ViewerExpr, ViewerPathExpr } from './context.js'\nimport type { HeldRow, HeldRows } from './held.js'\nimport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\nimport type { EntitySet } from './sets.js'\n// The members of `Entity`, a namespace rather than an object so a page keeps only\n// those it calls (#378). Exported under the interface's name; `export * as`\n// would make each `Entity` type here a reference the declaration emitter refuses.\nimport * as EntityMembers from './entity.js'\nimport type { AnyVariantUnion } from './variants.js'\n\nexport { EntityTypeId, SelectionPageTypeId, SelectionTypeId } from './ids.js'\n\n/**\n * What makes two descriptors the same Entity. A pipe step returns a new\n * descriptor with the same identity, so compare `identity`, never the objects.\n */\nexport interface EntityIdentity<Name extends string> {\n readonly name: Name\n /** Distinguishes two Entities that were defined with the same name. */\n readonly token: symbol\n}\n\n/** An intrinsic value of the Entity: one property of `entity.schema`. */\nexport interface EntityField<Name extends string, Key extends string, S extends Schema.Constraint> {\n readonly _tag: 'Field'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n readonly schema: S\n readonly metadata: Metadata\n}\n\nexport type Cardinality = 'one' | 'many'\n\n/**\n * What happens to a row when the row its `one` relation points at is deleted\n * (`Relation.one(Post, { onDelete: 'cascade' })`): `cascade`, it is deleted\n * with it, by the server in the write that deletes, and foreseen by a client;\n * `restrict`, the delete is refused while any row points there (#467), naming\n * the relation and none of the rows; `setNull`, an optional link is cleared,\n * an update of the row held to its own `Update` rules.\n */\nexport type OnDelete = 'cascade' | 'restrict' | 'setNull'\n\n/**\n * Who may let a cascade take a row (#348). `child`, the default: the row's own\n * `Delete` rule, judged for whoever deletes the row it points at, so a delete\n * that would take a row they may not delete is refused whole. `parent`: whoever\n * may delete the row it points at may take it too (a post's author removing\n * the likes under it), declared on the relation so it is never a default.\n */\nexport type AuthorizedBy = 'child' | 'parent'\n\n/** What `Relation.one` / `Relation.many` return, before `Entity.relate` binds it to an owner. */\nexport interface RelationSpec<\n Target extends AnyEntity,\n C extends Cardinality,\n Optional extends boolean,\n> {\n readonly target: Target\n readonly cardinality: C\n readonly optional: Optional\n readonly onDelete: Option.Option<OnDelete>\n readonly authorizedBy: Option.Option<AuthorizedBy>\n}\n\n/**\n * A navigation edge as its owner sees it: one or many of `target`. How the edge\n * is stored (a foreign key, a join table, a nested document) is the\n * interpreter's concern.\n */\nexport interface EntityRelation<\n Name extends string,\n Key extends string,\n Target extends AnyEntity,\n C extends Cardinality,\n Optional extends boolean,\n> {\n readonly _tag: 'Relation'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n /** The target as `Entity.relate` returned it, so its own relations can be followed. */\n readonly target: () => Target\n readonly cardinality: C\n readonly optional: Optional\n /**\n * What happens to this row when the row a `one` relation points at is\n * deleted; none for a `many`, and for a `one` declared with nothing.\n */\n readonly onDelete: Option.Option<OnDelete>\n /** Who may let a cascade through it take this row: some exactly where `onDelete` is `cascade`. */\n readonly authorizedBy: Option.Option<AuthorizedBy>\n readonly metadata: Metadata\n}\n\ntype OneRelation = EntityRelation<string, string, AnyEntity, 'one', boolean>\n\n/**\n * What a derived member is. `Supplied` (`Derived.make`): an interpreter\n * supplies it, and nothing else can say what it is. `Count`\n * (`Derived.count`): how many rows point at this one through `relation`, a\n * `one` relation of the counted Entity. `Exists` (`Derived.exists`): the id of\n * a row pointing here through `relation` whose `viewer` relation points at\n * whoever reads it, or none. A client predicts both from the rows it writes,\n * and a server compiles both from the relations' storage.\n */\nexport type Derivation = Data.TaggedEnum<{\n /**\n * `predict`: how a client foresees it for a row it writes; none, it waits\n * for the server. `forbids`: which write to the row its value refuses, so a\n * client holding it refuses that write where it is made.\n */\n Supplied: { readonly predict: Option.Option<Predict>; readonly forbids: Option.Option<Forbids> }\n Count: { readonly relation: OneRelation }\n Exists: { readonly relation: OneRelation; readonly viewer: OneRelation }\n}>\nexport const Derivation = Data.taggedEnum<Derivation>()\n\n/** What a supplied member's prediction is given: the row a write leaves, as its holder has it. */\nexport interface Predicting {\n /** The Entity written, as the write declared it. */\n readonly entity: AnyEntity\n readonly row: HeldRow\n /** The holder's other rows, where a rule's path reads. */\n readonly rows: HeldRows\n /** The operation's context: who asks, and the write's time. */\n readonly context: ExprContext\n}\n\n/**\n * A supplied member foreseen: its value **encoded**, as the store holds it, or\n * none where the holder cannot know it, so nothing is shown before the answer.\n */\nexport type Predict = (predicting: Predicting) => Option.Option<unknown>\n\n/**\n * What a write does to a row it finds, as a supplied member's `forbids` is\n * asked: an update's members and the relations it points, or a delete.\n */\nexport interface WriteSurface {\n readonly kind: 'Update' | 'Delete'\n /** The members it sets, moves or computes, relations not among them. */\n readonly members: ReadonlyArray<string>\n /** Each relation it points: at a row (`Link`), or at none (`Unlink`). */\n readonly relations: ReadonlyArray<{\n readonly relation: string\n readonly interaction: 'Link' | 'Unlink'\n }>\n}\n\n/**\n * Whether a supplied member's value, **encoded** as the store holds it,\n * refuses `surface`, with the reader's words for why when there are any; none\n * where it does not say so for certain. Only a definite refusal: a client\n * refuses the write unseen, and its server would refuse it too.\n */\nexport type Forbids = (\n value: unknown,\n surface: WriteSurface,\n) => Option.Option<{ readonly reason: Option.Option<string> }>\n\n/** What `Derived.make`, `Derived.count` or `Derived.exists` returns, before an Entity owns it. */\nexport interface DerivedSpec<S extends Schema.Constraint, D extends Derivation = Derivation> {\n readonly schema: S\n readonly derives: D\n}\n\n/** A value consumers may read that is not part of `entity.schema`, and what it derives. */\nexport interface EntityDerived<\n Name extends string,\n Key extends string,\n S extends Schema.Constraint,\n D extends Derivation = Derivation,\n> {\n readonly _tag: 'Derived'\n readonly owner: EntityIdentity<Name>\n readonly key: Key\n readonly schema: S\n readonly derives: D\n readonly metadata: Metadata\n}\n\nexport type EntityMember =\n | EntityField<string, string, Schema.Constraint>\n | EntityRelation<string, string, AnyEntity, Cardinality, boolean>\n | EntityDerived<string, string, Schema.Constraint>\n\nexport type RelationSpecs = Readonly<Record<string, RelationSpec<AnyEntity, Cardinality, boolean>>>\nexport type DerivedSpecs = Readonly<Record<string, DerivedSpec<Schema.Constraint>>>\n\ntype FieldsOf<Name extends string, Fields extends Schema.Struct.Fields> = {\n readonly [K in keyof Fields & string]: EntityField<Name, K, Fields[K]>\n}\ntype RelationsOf<Name extends string, Relations extends RelationSpecs> = {\n readonly [K in keyof Relations & string]: Relations[K] extends RelationSpec<\n infer Target,\n infer C,\n infer Optional\n >\n ? EntityRelation<Name, K, Target, C, Optional>\n : never\n}\ntype DerivedOf<Name extends string, Derived extends DerivedSpecs> = {\n readonly [K in keyof Derived & string]: EntityDerived<\n Name,\n K,\n Derived[K]['schema'],\n Derived[K]['derives']\n >\n}\n\nexport interface Entity<\n Name extends string,\n Fields extends Schema.Struct.Fields,\n Relations extends RelationSpecs = {},\n Derived extends DerivedSpecs = {},\n>\n extends Pipeable.Pipeable {\n readonly [EntityTypeId]: EntityTypeId\n readonly identity: EntityIdentity<Name>\n readonly name: Name\n /** The intrinsic value only: no relations, no derived members. */\n readonly schema: Schema.Struct<Fields>\n readonly fields: FieldsOf<Name, Fields>\n readonly relations: RelationsOf<Name, Relations>\n readonly derived: DerivedOf<Name, Derived>\n /** Every readable member under one namespace; keys never collide. */\n readonly members: FieldsOf<Name, Fields> & RelationsOf<Name, Relations> & DerivedOf<Name, Derived>\n /** The members whose value is the write's context, never its input (`Entity.sets`), by key. */\n readonly sets: Readonly<Record<string, EntitySet>>\n readonly metadata: Metadata\n}\n\nexport type AnyEntity = Entity<string, any, any, any>\n\n/**\n * An Entity whose rows are one of several shapes (`Entity.defineVariants`).\n * `variants` is Effect's tagged union of them, read with its own `match`;\n * `fields` and `schema` are the stored row, which every case shares.\n */\nexport interface VariantEntity<\n Name extends string,\n Fields extends Schema.Struct.Fields,\n Relations extends RelationSpecs = {},\n Derived extends DerivedSpecs = {},\n Union extends AnyVariantUnion = AnyVariantUnion,\n> extends Entity<Name, Fields, Relations, Derived> {\n readonly variants: Union\n}\n\nexport type AnyVariantEntity = VariantEntity<string, any, any, any, any>\n\n/** The keys of an Entity's `one` relations. */\ntype OneRelationKeys<E extends AnyEntity> = {\n [K in keyof E['relations'] & string]: E['relations'][K]['cardinality'] extends 'one' ? K : never\n}[keyof E['relations'] & string]\n\n/**\n * What a field holding `T` may be set to: the time where it holds a number,\n * the viewer's id where text, and what a path from the viewer reads where it\n * holds that.\n */\ntype ContextValueFor<T> =\n | (number extends T ? NowExpr<number> : never)\n | (T extends string ? ViewerExpr<T> : never)\n | ViewerPathExpr<T | null>\n\n/** The name of the Entity the `one` relation `K` points at. */\ntype TargetName<E extends AnyEntity, K extends keyof E['relations']> = ReturnType<\n E['relations'][K]['target']\n>['name']\n\n/**\n * What `Entity.sets` takes, by member: a field the value of the write's\n * context it can hold, a `one` relation `Expr.viewer` of its target.\n */\nexport type EntitySets<E extends AnyEntity> = {\n readonly [K in Exclude<keyof E['fields'] & string, 'id'>]?: ContextValueFor<\n Schema.Schema.Type<E['fields'][K]['schema']>\n >\n} & {\n readonly [K in OneRelationKeys<E>]?: ViewerExpr<unknown, TargetName<E, K>>\n}\n\nexport type Entities = Readonly<Record<string, AnyEntity>>\nexport type RelationMap<Es extends Entities> = { readonly [K in keyof Es]?: RelationSpecs }\n\n/** The key in `Es` of the Entity a spec targets, matched by name. */\nexport type TargetKey<Es extends Entities, Target extends AnyEntity> = {\n [K in keyof Es]: [Es[K]['name'], Target['name']] extends [Target['name'], Es[K]['name']]\n ? K\n : never\n}[keyof Es]\n\nexport type RelatedSpecs<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> = {\n readonly [R in keyof Rs[K]]: Rs[K][R] extends RelationSpec<infer Target, infer C, infer Optional>\n ? RelationSpec<Related<Es, Rs, TargetKey<Es, Target>>, C, Optional>\n : never\n}\n\n/**\n * One Entity of an `Entity.relate` result. A relation's target is again a\n * `Related`, so relations can be followed through a cycle; the recursion goes\n * through type arguments, which TypeScript resolves only when asked.\n */\nexport type Related<Es extends Entities, Rs extends RelationMap<Es>, K extends keyof Es> =\n Es[K] extends VariantEntity<infer Name, infer Fields, infer R, infer D, infer U>\n ? VariantEntity<Name, Fields, R & RelatedSpecs<Es, Rs, K>, D, U>\n : Es[K] extends Entity<infer Name, infer Fields, infer R, infer D>\n ? Entity<Name, Fields, R & RelatedSpecs<Es, Rs, K>, D>\n : never\n\n/**\n * The schema that identifies one of an Entity: its `id` field when that is text\n * (a plain string, a brand, a pattern), and plain text otherwise. An id is text\n * because a ref travels and is stored as text; an Entity keyed by a number still\n * has refs, and their ids are the number as text.\n */\nexport type IdSchemaOf<E> = E extends {\n readonly fields: { readonly id: { readonly schema: infer S } }\n}\n ? S extends Schema.Constraint\n ? [S['Type']] extends [string]\n ? S\n : Schema.String\n : Schema.String\n : Schema.String\n\n/** What identifies one of an Entity: `IdOf<typeof Blog.Post>` is `PostId` when its `id` field is one. */\nexport type IdOf<E> = IdSchemaOf<E>['Type']\n\n/**\n * What a relation selected with `true` yields: which Entity, and which one. `Id`\n * is the target's own id type, so a ref to an Author cannot be used as a Post's.\n */\nexport interface EntityRef<Name extends string = string, Id extends string = string> {\n readonly entity: Name\n readonly id: Id\n}\n\n/**\n * A view of the Entity graph: which members to read, and the schema of the\n * value that results. It says nothing about where the value comes from.\n */\nexport interface Selection<\n Name extends string,\n Members,\n S extends Schema.Constraint,\n Id extends string = string,\n> {\n readonly [SelectionTypeId]: SelectionTypeId\n /** Type-only: the id type of the Entity selected, so a reader can ask for the right one. Never set. */\n readonly Id?: Id\n readonly entity: Entity<Name, any, any, any>\n /** What was selected, by member key: `true`, or a relation's nested Selection. */\n readonly members: Members\n readonly schema: S\n}\n\n/** The value a Selection reads: `Selected<typeof PostCard>` is one card's fields. */\nexport type Selected<S extends Selection<string, unknown, Schema.Constraint>> = S['schema']['Type']\n\n/**\n * Which part of a `many` relation to read: the first or last so many, from a\n * cursor or from the end. A cursor is whatever the interpreter handed out with an\n * earlier page; nothing here looks inside it.\n */\nexport interface PageWindow {\n readonly first?: number | undefined\n readonly last?: number | undefined\n readonly after?: string | undefined\n readonly before?: string | undefined\n}\n\n/** A Selection of a `many` relation's target, read a page at a time. */\nexport interface SelectionPage<Name extends string, S extends Schema.Constraint> {\n readonly [SelectionPageTypeId]: SelectionPageTypeId\n readonly selection: Selection<Name, any, S>\n readonly window: PageWindow\n}\n\n/** An input key that carries a relation's target: the id of a `one`, the ids of a `many`. */\nexport interface RelationInput<R extends EntityRelation<any, any, any, any, any>> {\n readonly _tag: 'RelationInput'\n readonly relation: R\n}\n\n/**\n * An input key that carries the relation's target itself, written through an\n * input of its own: a post created with a new author, an order with its lines.\n * A `one` holds that input's value, a `many` a list of them.\n */\nexport interface NestedInput<\n R extends EntityRelation<any, any, any, any, any>,\n I extends EntityInput<any, any, any>,\n> {\n readonly _tag: 'NestedInput'\n readonly relation: R\n readonly input: I\n}\n\n/** An input key that is about the operation, not the Entity: a reason, a flag, a confirmation. */\nexport interface Unmapped {\n readonly _tag: 'Unmapped'\n}\n\n/** What one key of an operation's input means in terms of the Entity. */\nexport type InputMember =\n | EntityField<string, string, Schema.Constraint>\n | RelationInput<EntityRelation<string, string, AnyEntity, Cardinality, boolean>>\n | NestedInput<\n EntityRelation<string, string, AnyEntity, Cardinality, boolean>,\n EntityInput<AnyEntity, any, any>\n >\n | Unmapped\n\n/**\n * An operation's input read against an Entity: which member each input key\n * writes. The operation decides what may be submitted; the Entity only says\n * what each submitted key means.\n */\nexport interface EntityInput<E extends AnyEntity, Fields extends Schema.Struct.Fields, Members> {\n readonly entity: E\n readonly schema: Schema.Struct<Fields>\n readonly members: Members\n}\n\nexport type { InputMembers, WrittenAs, WrittenKey, WrittenSpec } from './entity.js'\nexport { EntityMembers as Entity }\n\n/**\n * How a `one` relation is declared: whether it may point nowhere, and what a\n * delete of its target does. `authorizedBy` is said only beside `onDelete`.\n */\nexport type OneOptions<Optional extends boolean> = {\n readonly optional?: Optional\n} & (\n | { readonly onDelete?: undefined; readonly authorizedBy?: undefined }\n | {\n /** `cascade`: a row pointing here is deleted with the row it points at. */\n readonly onDelete: 'cascade'\n /** Whose `Delete` rule lets the cascade take this row: its own (`child`), or the parent's. */\n readonly authorizedBy?: AuthorizedBy\n }\n | {\n /** `restrict`: the row it points at cannot be deleted while this row points there. */\n readonly onDelete: 'restrict'\n readonly authorizedBy?: undefined\n }\n | {\n /** `setNull`: this row stays and points nowhere; only a link that may point nowhere can. */\n readonly onDelete: 'setNull'\n readonly optional: true\n readonly authorizedBy?: undefined\n }\n)\n\nfunction one<Target extends AnyEntity>(target: Target): RelationSpec<Target, 'one', false>\nfunction one<Target extends AnyEntity, const Optional extends boolean>(\n target: Target,\n options: OneOptions<Optional> & { readonly optional: Optional },\n): RelationSpec<Target, 'one', Optional>\nfunction one<Target extends AnyEntity>(\n target: Target,\n options: OneOptions<false>,\n): RelationSpec<Target, 'one', false>\nfunction one(\n target: AnyEntity,\n options?: OneOptions<boolean>,\n): RelationSpec<AnyEntity, 'one', boolean> {\n const onDelete = options?.onDelete\n const authorizedBy = options?.authorizedBy\n if (\n onDelete !== undefined &&\n onDelete !== 'cascade' &&\n onDelete !== 'restrict' &&\n onDelete !== 'setNull'\n )\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): onDelete is 'cascade', 'restrict' or 'setNull'; ${String(onDelete)} is not one`,\n )\n if (onDelete === 'setNull' && options?.optional !== true)\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): onDelete: 'setNull' clears the link, so it needs optional: true`,\n )\n if (authorizedBy !== undefined && authorizedBy !== 'child' && authorizedBy !== 'parent')\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): authorizedBy is 'child' or 'parent'; ${String(authorizedBy)} is not one`,\n )\n if (authorizedBy !== undefined && onDelete !== 'cascade')\n throw new Error(\n `[foldkit-entity] Relation.one(${target.name}): authorizedBy says who lets a cascade take the row, so it needs onDelete: 'cascade'`,\n )\n return {\n target,\n cardinality: 'one',\n optional: options?.optional ?? false,\n onDelete: Option.fromUndefinedOr(onDelete),\n authorizedBy: onDelete === 'cascade' ? Option.some(authorizedBy ?? 'child') : Option.none(),\n }\n}\n\n/** What the owner sees: one or many of `target`. Used inside `Entity.relate`. */\nexport const Relation = {\n one,\n\n /** For `Entity.input`: the input key holds this relation's target id, or ids for a `many`. */\n input: <R extends EntityRelation<any, any, any, any, any>>(relation: R): RelationInput<R> =>\n Object.freeze({ _tag: 'RelationInput', relation }),\n\n /**\n * For `Entity.input`: the input key holds the relation's target itself, written\n * through `input`, an `Entity.input` of the target. A `many` holds a list.\n */\n nested: <R extends EntityRelation<any, any, any, any, any>, I extends EntityInput<any, any, any>>(\n relation: R,\n input: I,\n ): NestedInput<R, I> => Object.freeze({ _tag: 'NestedInput', relation, input }),\n\n many: <Target extends AnyEntity>(target: Target): RelationSpec<Target, 'many', false> => ({\n target,\n cardinality: 'many',\n optional: false,\n onDelete: Option.none(),\n authorizedBy: Option.none(),\n }),\n}\n\n/** A count: never negative, never a fraction. */\nconst CountSchema = Schema.Number.check(Schema.isInt(), Schema.isGreaterThanOrEqualTo(0))\n\n/** The id of the row an exists found, as every Remote id is held: text, or none. */\nconst WitnessSchema = Schema.OptionFromNullOr(Schema.String)\n\ntype OwnerName<R> = R extends EntityRelation<infer Name, any, any, any, any> ? Name : never\n\nexport const Derived = {\n /**\n * A member only an interpreter can compute, of type `schema`: it supplies the\n * value. `predict` says how a client foresees it for a row it writes (Guard's\n * `may`); without it the row reads as missing the member until the answer.\n * `forbids` says which write to the row its value refuses (Guard's `may`\n * again), so a client holding it refuses that write where it is made.\n */\n make: <S extends Schema.Constraint>(\n schema: S,\n options: {\n readonly predict?: Predict | undefined\n readonly forbids?: Forbids | undefined\n } = {},\n ): DerivedSpec<S, Extract<Derivation, { readonly _tag: 'Supplied' }>> => ({\n schema,\n derives: Derivation.Supplied({\n predict: Option.fromUndefinedOr(options.predict),\n forbids: Option.fromUndefinedOr(options.forbids),\n }),\n }),\n\n /**\n * How many rows point at this one through `relation`, a `one` relation of\n * the counted Entity: `likeCount: Derived.count(Like.relations.post)` on\n * Post. Added after `Entity.relate`, which makes the relation. A server\n * compiles it from the relation's storage, and a client predicts it from\n * the rows a pending write inserts, deletes or points elsewhere.\n */\n count: <R extends EntityRelation<string, string, AnyEntity, 'one', boolean>>(\n relation: R,\n ): DerivedSpec<typeof CountSchema, { readonly _tag: 'Count'; readonly relation: R }> => ({\n schema: CountSchema,\n derives: Derivation.Count({ relation }) as { readonly _tag: 'Count'; readonly relation: R },\n }),\n\n /**\n * Whether a row points at this one through `relation` and at whoever reads\n * it through `viewer`, another `one` relation of the same pointing Entity:\n * `liked: Derived.exists(Like.relations.post, { viewer: Like.relations.user })`\n * on Post. Its value is that row's id as the store holds it, or none, so the\n * reader can take it back (`Write.delete` by that id). It depends on who\n * reads it: a server answers it for the principal it reads as, and a client\n * predicts it for the viewer it is told of.\n */\n exists: <\n R extends OneRelation,\n V extends EntityRelation<OwnerName<R>, string, AnyEntity, 'one', boolean>,\n >(\n relation: R,\n options: { readonly viewer: V },\n ): DerivedSpec<\n typeof WitnessSchema,\n { readonly _tag: 'Exists'; readonly relation: R; readonly viewer: V }\n > => ({\n schema: WitnessSchema,\n derives: Derivation.Exists({ relation, viewer: options.viewer }) as {\n readonly _tag: 'Exists'\n readonly relation: R\n readonly viewer: V\n },\n }),\n}\n\nexport * from './expr.js'\nexport {\n contextValue,\n viewerIdOf,\n type ExprContext,\n type NowExpr,\n type ViewerExpr,\n type ViewerPathExpr,\n} from './context.js'\nexport * from './collation.js'\nexport * from './operators.js'\nexport * from './law.js'\nexport * from './text.js'\nexport * from './readFilter.js'\nexport * from './words.js'\nexport * from './shape.js'\nexport type {\n AnyVariantUnion,\n CheckCases,\n EntityVariants,\n StoredFields,\n VariantCases,\n VariantUnion,\n} from './variants.js'\n// The reference semantics of the IR above. The conformance suite that proves\n// an interpreter agrees with it is `foldkit-entity/conformance`, kept out of\n// this entry because it is fixture data every form and admin screen would\n// otherwise carry.\nexport * from './evaluate.js'\nexport * from './held.js'\nexport type {\n AfterRow,\n BeforeRow,\n Change,\n DeclaredInvariant,\n Invariant,\n Judgement,\n} from './invariant.js'\nexport type { ContextValue, EntitySet, SetOn } from './sets.js'\nexport type {\n AnyRefinement,\n Refinement,\n RefinementBuild,\n RefinementLiteral,\n RefinementOf,\n} from './refine.js'\nexport { Footprint, type DeclaredFootprint } from './footprint.js'\nexport {\n Laws,\n Finding,\n LawEdge,\n LawNode,\n LawVerdict,\n lawFactsOf,\n type Arrow,\n type FootprintEntry,\n type LawEntry,\n type LawFacts,\n type LawPair,\n type LawReport,\n type WriteEntry,\n} from './laws.js'\nexport type { Step } from './enumerate.js'\nexport { lawId, transitionId } from './lawIds.js'\nexport {\n Write,\n type AnyWrite,\n type BoundWrite,\n type ConditionedWrite,\n Computation,\n type WriteAssignment,\n type WriteComputations,\n type WriteCondition,\n type WriteIncrement,\n type WriteKind,\n type WriteLink,\n type WriteSet,\n type ContextSet,\n type ContextRead,\n type ContextValues,\n} from './write.js'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8HA,MAAa,aAAa,KAAK,WAAuB;AA8VtD,SAAS,IACP,QACA,SACyC;CACzC,MAAM,WAAW,SAAS;CAC1B,MAAM,eAAe,SAAS;CAC9B,IACE,aAAa,KAAA,KACb,aAAa,aACb,aAAa,cACb,aAAa,WAEb,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,qDAAqD,OAAO,QAAQ,EAAE,YACrH;CACF,IAAI,aAAa,aAAa,SAAS,aAAa,MAClD,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,mEAC/C;CACF,IAAI,iBAAiB,KAAA,KAAa,iBAAiB,WAAW,iBAAiB,UAC7E,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,0CAA0C,OAAO,YAAY,EAAE,YAC9G;CACF,IAAI,iBAAiB,KAAA,KAAa,aAAa,WAC7C,MAAM,IAAI,MACR,iCAAiC,OAAO,KAAK,sFAC/C;CACF,OAAO;EACL;EACA,aAAa;EACb,UAAU,SAAS,YAAY;EAC/B,UAAU,OAAO,gBAAgB,QAAQ;EACzC,cAAc,aAAa,YAAY,OAAO,KAAK,gBAAgB,OAAO,IAAI,OAAO,KAAK;CAC5F;AACF;;AAGA,MAAa,WAAW;CACtB;;CAGA,QAA2D,aACzD,OAAO,OAAO;EAAE,MAAM;EAAiB;CAAS,CAAC;;;;;CAMnD,SACE,UACA,UACsB,OAAO,OAAO;EAAE,MAAM;EAAe;EAAU;CAAM,CAAC;CAE9E,OAAiC,YAAyD;EACxF;EACA,aAAa;EACb,UAAU;EACV,UAAU,OAAO,KAAK;EACtB,cAAc,OAAO,KAAK;CAC5B;AACF;;AAGA,MAAM,cAAc,OAAO,OAAO,MAAM,OAAO,MAAM,GAAG,OAAO,uBAAuB,CAAC,CAAC;;AAGxF,MAAM,gBAAgB,OAAO,iBAAiB,OAAO,MAAM;AAI3D,MAAa,UAAU;;;;;;;;CAQrB,OACE,QACA,UAGI,CAAC,OACmE;EACxE;EACA,SAAS,WAAW,SAAS;GAC3B,SAAS,OAAO,gBAAgB,QAAQ,OAAO;GAC/C,SAAS,OAAO,gBAAgB,QAAQ,OAAO;EACjD,CAAC;CACH;;;;;;;;CASA,QACE,cACuF;EACvF,QAAQ;EACR,SAAS,WAAW,MAAM,EAAE,SAAS,CAAC;CACxC;;;;;;;;;;CAWA,SAIE,UACA,aAII;EACJ,QAAQ;EACR,SAAS,WAAW,OAAO;GAAE;GAAU,QAAQ,QAAQ;EAAO,CAAC;CAKjE;AACF"}
|
package/dist/invariant.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Schema, SchemaAST } from "effect";
|
|
2
2
|
import { AnyEntity, EntityInput } from "./index.js";
|
|
3
|
+
import { Row } from "./evaluate.js";
|
|
3
4
|
import { FieldExpr, NextExpr, Predicate, Reads } from "./expr.js";
|
|
4
5
|
import { MemoryOperators as MemoryOperators$1 } from "./operators.js";
|
|
5
|
-
import { Row } from "./evaluate.js";
|
|
6
6
|
/** One invariant of an Entity, as its interpreters read it. */
|
|
7
7
|
export interface Invariant {
|
|
8
8
|
/** Stable, unique within its Entity: what a refusal names, and forms and logs key on. */
|
|
@@ -57,8 +57,9 @@ export type Judgement = {
|
|
|
57
57
|
/** Whether an invariant reads the row before a write: judged on updates only, and no CHECK. */
|
|
58
58
|
export declare const readsBefore: (held: Invariant) => boolean;
|
|
59
59
|
/**
|
|
60
|
-
* An invariant as declared: the step that attaches it to its Entity
|
|
61
|
-
* its id and, once attached,
|
|
60
|
+
* An invariant as declared: the step that attaches it to its Entity and
|
|
61
|
+
* returns the descriptor it was given, carrying its id and, once attached,
|
|
62
|
+
* that Entity's name, so a refusal is matched
|
|
62
63
|
* against the declaration rather than a string spelled again
|
|
63
64
|
* (`Refusal.isInvalidBy(refusal, reservedWithinQuantity)`). An id is unique
|
|
64
65
|
* only within an Entity, so the name is part of what a refusal names; reading
|
|
@@ -82,7 +83,9 @@ interface Options<E extends AnyEntity> {
|
|
|
82
83
|
* Declares what every stored row, or every change of one, must hold:
|
|
83
84
|
* `Entity.invariant('reservedWithinQuantity', ({ after }) =>
|
|
84
85
|
* Expr.lte(after.reserved, after.quantity), { message })` over the row a
|
|
85
|
-
* write leaves, or with `before` too over the change an update makes.
|
|
86
|
+
* write leaves, or with `before` too over the change an update makes. It is
|
|
87
|
+
* the Entity's: every descriptor of it judges it, and the step returns the one
|
|
88
|
+
* it was given. Applied to that Entity again, it adds nothing.
|
|
86
89
|
* Refused where it is declared: an id declared twice, a predicate over another
|
|
87
90
|
* Entity, one reading an input or nothing of `after` (that is a `when`), a path
|
|
88
91
|
* naming no field.
|
|
@@ -100,15 +103,42 @@ export declare const judgeAgainst: (invariants: ReadonlyArray<Invariant>, change
|
|
|
100
103
|
* are not judged.
|
|
101
104
|
*/
|
|
102
105
|
export declare const judge: (entity: AnyEntity, change: Change, operators?: MemoryOperators$1) => Judgement;
|
|
106
|
+
/** What `judgeInput` is given beside the input's value. */
|
|
107
|
+
export interface JudgeInputOptions {
|
|
108
|
+
/** The table the judge runs operators with: `Operators.kernel` by default. */
|
|
109
|
+
readonly operators?: MemoryOperators$1 | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* The row the input edits, encoded as the store holds it (`rowFrom`): the
|
|
112
|
+
* input's keys are laid over it, and it is the row before, so transition
|
|
113
|
+
* invariants are judged too. None for a create.
|
|
114
|
+
*/
|
|
115
|
+
readonly over?: Readonly<Record<string, unknown>> | undefined;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The row an input's value describes, judged under its Entity's invariants:
|
|
119
|
+
* each key mapped to a field, encoded as the store holds it, and each mapped
|
|
120
|
+
* to a `one` relation as the id it points at. Without `over`, an invariant
|
|
121
|
+
* over a field the input does not set (an `Option` holding nothing, a key left
|
|
122
|
+
* out) is undecided, so a partial input is never called valid on its account,
|
|
123
|
+
* and no transition is judged. With `over`, the row it edits, such a field is
|
|
124
|
+
* the row's, and the change from the row to the row with the input laid over
|
|
125
|
+
* it is judged, transitions included.
|
|
126
|
+
*/
|
|
127
|
+
export declare const judgeInput: (input: EntityInput<AnyEntity, any, any>, value: Readonly<Record<string, unknown>>, options?: JudgeInputOptions) => Judgement;
|
|
128
|
+
/**
|
|
129
|
+
* A decoded value of `entity`, such as a Selection's, as the row the judge
|
|
130
|
+
* reads: each field it holds encoded as the store holds it, and each `one`
|
|
131
|
+
* relation as the id it points at. A member it does not hold is left out, so
|
|
132
|
+
* an invariant reading it is undecided.
|
|
133
|
+
*/
|
|
134
|
+
export declare const rowFrom: (entity: AnyEntity, value: Readonly<Record<string, unknown>>) => Readonly<Record<string, unknown>>;
|
|
103
135
|
/**
|
|
104
|
-
* The
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
* key left out) is undecided, so a partial input is never called valid on its
|
|
109
|
-
* account. It has no row before, so it judges no transition.
|
|
136
|
+
* The members outside `input` that its Entity's invariants read, of each
|
|
137
|
+
* invariant that also reads a member the input sets: what a form over the
|
|
138
|
+
* input loads beside its own keys (`Entity.selectFor(input, { also })`), so it
|
|
139
|
+
* can judge those invariants over the row it edits.
|
|
110
140
|
*/
|
|
111
|
-
export declare const
|
|
141
|
+
export declare const judgedBy: (input: EntityInput<AnyEntity, any, any>) => Readonly<Record<string, true>>;
|
|
112
142
|
/**
|
|
113
143
|
* The Entity's state invariants as an Effect Schema check over its row type:
|
|
114
144
|
* each failure at its path, with its message. The value is encoded first,
|
package/dist/invariant.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"invariant.d.ts","names":["MemoryOperators"],"sources":["../src/invariant.ts"],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"invariant.d.ts","names":["MemoryOperators"],"sources":["../src/invariant.ts"],"mappings":";;;;;;iBA0CiB;;WAEN;;WAEA;WACA,WAAW;;WAEX;;WAEA,MAAM;;WAEN,QAAQ;;WAER,OAAO;;;KAIb,SAAS,UAAU,gBACrB,WAAW,0BAA0B,eAAe,kCAAkC,mBACjF;;KAGH,OACH,UAAU,WACV,gBAAgB,kBACd,eAAe;;;;;;;YAQP,UAAU,UAAU,yBACpB,WAAW,uBAAuB,UAC1C,OAAO,MAAM,QAAQ,YAAY,iBAEjC,MAAM,4BACM,KAAK,SAAS,KAAK,UAAU,OAAO,GAAG,MAAM,MAAM;;YAGvD,SAAS,UAAU,yBACnB,WAAW,uBAAuB,SAC1C,OAAO,MAAM,QAAQ,YAAY,iBAEjC,MAAM,4BACM,KAAK,SAAS,KAAK,SAAS,OAAO,GAAG,MAAM,MAAM;;iBAGjD;WACN,OAAO;;WAEP,SAAS;;;YAIR;WACG;;WACA;WAA0B,UAAU,cAAc;;;;;;;WAMlD;WACA,QAAQ;WACR,WAAW;;;qBAIb,cAAW,MAAU;;;;;;;;;;iBAWjB,kBAAkB,UAAU;GAC1C,QAAQ,IAAI;WACJ;WACA;;;KAQN,MAAM,UAAU,cAAc;WACxB,QAAQ,UAAU;WAClB,OAAO,SAAS;MACrB,YAAY,MAAM;UAEd,QAAQ,UAAU;WACjB;WACA,OAAO,qBAAqB,wBAAwB,SAAS;;;;;;;;;;;;;qBA+D3D,YAAa,UAAU,WAAS,YACjC,OACH,MAAM,IAAE,SACN,QAAQ,OAChB,kBAAkB;;qBAuFR,eAAY,QAAY,cAAY,cAAc;;qBAOlD,eAAY,YACX,cAAc,YAAU,QAC5B,QAAM,YACHA,sBACV;;;;;;;;qBAyCU,QAAK,QACR,WAAS,QACT,QAAM,YACHA,sBACV;;iBAGc;;WAEN,YAAYA;;;;;;WAMZ,OAAO,SAAS;;;;;;;;;;;;qBAad,aAAU,OACd,YAAY,sBAAoB,OAChC,SAAS,0BAAwB,UAC/B,sBACR;;;;;;;qBA0CU,UAAO,QACV,WAAS,OACV,SAAS,6BACf,SAAS;;;;;;;qBA0BC,WAAQ,OACZ,YAAY,yBAClB,SAAS;;;;;;;;qBA2BC,QAAS,UAAU,WAAS,QAC/B,GAAC;WACW,YAAYA;MAC/B,UAAU,OAAO,OAAO,OAAO,KAAK"}
|