foldkit-entity 0.13.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.
- package/README.md +962 -512
- package/dist/collation.d.ts +33 -0
- package/dist/collation.d.ts.map +1 -0
- package/dist/collation.js +46 -0
- package/dist/collation.js.map +1 -0
- package/dist/conformance/index.d.ts +66 -0
- package/dist/conformance/index.d.ts.map +1 -0
- package/dist/conformance/{index.mjs → index.js} +22 -360
- package/dist/conformance/index.js.map +1 -0
- package/dist/conformance/operator.d.ts +115 -0
- package/dist/conformance/operator.d.ts.map +1 -0
- package/dist/conformance/operator.js +354 -0
- package/dist/conformance/operator.js.map +1 -0
- package/dist/conformance/relational.d.ts +240 -0
- package/dist/conformance/relational.d.ts.map +1 -0
- package/dist/conformance/relational.js +425 -0
- package/dist/conformance/relational.js.map +1 -0
- package/dist/conformance/tuples.d.ts +8 -0
- package/dist/conformance/tuples.d.ts.map +1 -0
- package/dist/conformance/tuples.js +43 -0
- package/dist/conformance/tuples.js.map +1 -0
- package/dist/conformance/variants.d.ts +47 -0
- package/dist/conformance/variants.d.ts.map +1 -0
- package/dist/conformance/variants.js +126 -0
- package/dist/conformance/variants.js.map +1 -0
- package/dist/context.d.ts +60 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +36 -0
- package/dist/context.js.map +1 -0
- package/dist/descriptor.d.ts +33 -0
- package/dist/descriptor.d.ts.map +1 -0
- package/dist/descriptor.js +137 -0
- package/dist/descriptor.js.map +1 -0
- package/dist/entity.d.ts +231 -0
- package/dist/entity.d.ts.map +1 -0
- package/dist/entity.js +435 -0
- package/dist/entity.js.map +1 -0
- package/dist/evaluate.d.ts +204 -0
- package/dist/evaluate.d.ts.map +1 -0
- package/dist/evaluate.js +765 -0
- package/dist/evaluate.js.map +1 -0
- package/dist/expr.d.ts +915 -0
- package/dist/expr.d.ts.map +1 -0
- package/dist/expr.js +1630 -0
- package/dist/expr.js.map +1 -0
- package/dist/held.d.ts +112 -0
- package/dist/held.d.ts.map +1 -0
- package/dist/held.js +155 -0
- package/dist/held.js.map +1 -0
- package/dist/ids.d.ts +8 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +8 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +380 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/invariant.d.ts +123 -0
- package/dist/invariant.d.ts.map +1 -0
- package/dist/invariant.js +236 -0
- package/dist/invariant.js.map +1 -0
- package/dist/jsonSchema.d.ts +3 -0
- package/dist/jsonSchema.d.ts.map +1 -0
- package/dist/jsonSchema.js +17 -0
- package/dist/jsonSchema.js.map +1 -0
- package/dist/law.d.ts +264 -0
- package/dist/law.d.ts.map +1 -0
- package/dist/law.js +111 -0
- package/dist/law.js.map +1 -0
- package/dist/operators.d.ts +170 -0
- package/dist/operators.d.ts.map +1 -0
- package/dist/operators.js +207 -0
- package/dist/operators.js.map +1 -0
- package/dist/readFilter.d.ts +8 -0
- package/dist/readFilter.d.ts.map +1 -0
- package/dist/readFilter.js +23 -0
- package/dist/readFilter.js.map +1 -0
- package/dist/record.d.ts +11 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +21 -0
- package/dist/record.js.map +1 -0
- package/dist/sets.d.ts +18 -0
- package/dist/sets.d.ts.map +1 -0
- package/dist/sets.js +57 -0
- package/dist/sets.js.map +1 -0
- package/dist/shape.d.ts +23 -0
- package/dist/shape.d.ts.map +1 -0
- package/dist/shape.js +30 -0
- package/dist/shape.js.map +1 -0
- package/dist/tested.d.ts +8 -0
- package/dist/tested.d.ts.map +1 -0
- package/dist/tested.js +25 -0
- package/dist/tested.js.map +1 -0
- package/dist/text.d.ts +27 -0
- package/dist/text.d.ts.map +1 -0
- package/dist/text.js +39 -0
- package/dist/text.js.map +1 -0
- package/dist/variants.d.ts +72 -0
- package/dist/variants.d.ts.map +1 -0
- package/dist/variants.js +76 -0
- package/dist/variants.js.map +1 -0
- package/dist/words.d.ts +17 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +22 -0
- package/dist/words.js.map +1 -0
- package/dist/write.d.ts +312 -0
- package/dist/write.d.ts.map +1 -0
- package/dist/write.js +520 -0
- package/dist/write.js.map +1 -0
- package/package.json +8 -8
- package/dist/conformance/index.d.mts +0 -274
- package/dist/conformance/index.d.mts.map +0 -1
- package/dist/conformance/index.mjs.map +0 -1
- package/dist/index-hu8IYlNc.d.mts +0 -2228
- package/dist/index-hu8IYlNc.d.mts.map +0 -1
- package/dist/index.d.mts +0 -2
- package/dist/index.mjs +0 -1
- package/dist/src-DBAilaDV.mjs +0 -3061
- package/dist/src-DBAilaDV.mjs.map +0 -1
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Entity, Expr, Order, Query } from "../index.js";
|
|
3
|
+
// src/conformance/variants.ts
|
|
4
|
+
/**
|
|
5
|
+
* Variants (#357): an Entity whose rows are one of several cases, stored as one
|
|
6
|
+
* row with `_tag` and a nullable column per case field. `Expr.is` compiles to
|
|
7
|
+
* `_tag = case` and what is asked of the case, so an interpreter runs it with
|
|
8
|
+
* the operations it has; these cases pin that a row of another case is false
|
|
9
|
+
* under `Expr.is`, while the stored column is null there and unknown under a
|
|
10
|
+
* comparison.
|
|
11
|
+
*/
|
|
12
|
+
/** `cents` is shared by `Priced` and `Held`, so one nullable column serves two cases. */
|
|
13
|
+
const Cents = Schema.Int;
|
|
14
|
+
const Variant = Entity.defineVariants("Variant", {
|
|
15
|
+
Priced: {
|
|
16
|
+
id: Schema.String,
|
|
17
|
+
label: Schema.String,
|
|
18
|
+
cents: Cents
|
|
19
|
+
},
|
|
20
|
+
Free: {
|
|
21
|
+
id: Schema.String,
|
|
22
|
+
label: Schema.String
|
|
23
|
+
},
|
|
24
|
+
Held: {
|
|
25
|
+
id: Schema.String,
|
|
26
|
+
label: Schema.String,
|
|
27
|
+
cents: Cents,
|
|
28
|
+
until: Schema.String
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
const variantRows = [
|
|
32
|
+
{
|
|
33
|
+
_tag: "Priced",
|
|
34
|
+
id: "p1",
|
|
35
|
+
label: "Mug",
|
|
36
|
+
cents: 500,
|
|
37
|
+
until: null
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
_tag: "Priced",
|
|
41
|
+
id: "p2",
|
|
42
|
+
label: "Lamp",
|
|
43
|
+
cents: 1500,
|
|
44
|
+
until: null
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
_tag: "Free",
|
|
48
|
+
id: "f1",
|
|
49
|
+
label: "Sticker",
|
|
50
|
+
cents: null,
|
|
51
|
+
until: null
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
_tag: "Held",
|
|
55
|
+
id: "h1",
|
|
56
|
+
label: "Chair",
|
|
57
|
+
cents: 900,
|
|
58
|
+
until: "2026-02-01"
|
|
59
|
+
}
|
|
60
|
+
];
|
|
61
|
+
const from = Query.from(Variant);
|
|
62
|
+
const byId = Query.orderBy(Order.asc(Variant.fields.id));
|
|
63
|
+
const cheapPriced = Expr.is(Variant, "Priced", ({ cents }) => Expr.lt(cents, 1e3));
|
|
64
|
+
const variantCases = [
|
|
65
|
+
{
|
|
66
|
+
what: "is matches the rows of a case",
|
|
67
|
+
body: from.pipe(Query.where(Expr.is(Variant, "Priced")), byId),
|
|
68
|
+
input: {},
|
|
69
|
+
expected: ["p1", "p2"]
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
what: "is asks of the case’s fields",
|
|
73
|
+
body: from.pipe(Query.where(cheapPriced), byId),
|
|
74
|
+
input: {},
|
|
75
|
+
expected: ["p1"]
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
what: "not of is holds on every other case, which is false and never unknown",
|
|
79
|
+
body: from.pipe(Query.where(Expr.not(cheapPriced)), byId),
|
|
80
|
+
input: {},
|
|
81
|
+
expected: [
|
|
82
|
+
"f1",
|
|
83
|
+
"h1",
|
|
84
|
+
"p2"
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
what: "a stored case field is null on another case, so a comparison drops that row",
|
|
89
|
+
body: from.pipe(Query.where(Expr.lt(Variant.fields.cents, 1e3)), byId),
|
|
90
|
+
input: {},
|
|
91
|
+
expected: ["h1", "p1"]
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
what: "and so does its not",
|
|
95
|
+
body: from.pipe(Query.where(Expr.not(Expr.lt(Variant.fields.cents, 1e3))), byId),
|
|
96
|
+
input: {},
|
|
97
|
+
expected: ["p2"]
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
what: "a case field is never null within its case",
|
|
101
|
+
body: from.pipe(Query.where(Expr.is(Variant, "Priced", ({ cents }) => Expr.isNull(cents))), byId),
|
|
102
|
+
input: {},
|
|
103
|
+
expected: []
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
what: "a field of one case is read within it",
|
|
107
|
+
body: from.pipe(Query.where(Expr.is(Variant, "Held", ({ until }) => Expr.eq(until, "2026-02-01"))), byId),
|
|
108
|
+
input: {},
|
|
109
|
+
expected: ["h1"]
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
what: "several cases are an in over _tag",
|
|
113
|
+
body: from.pipe(Query.where(Expr.in(Variant.fields._tag, ["Free", "Held"])), byId),
|
|
114
|
+
input: {},
|
|
115
|
+
expected: ["f1", "h1"]
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
what: "cases combine under or",
|
|
119
|
+
body: from.pipe(Query.where(Expr.or(Expr.is(Variant, "Free"), Expr.is(Variant, "Priced", ({ cents }) => Expr.gt(cents, 1e3)))), byId),
|
|
120
|
+
input: {},
|
|
121
|
+
expected: ["f1", "p2"]
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
export { Variant, variantCases, variantRows };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=variants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"variants.js","names":[],"sources":["../../src/conformance/variants.ts"],"sourcesContent":["/**\n * Variants (#357): an Entity whose rows are one of several cases, stored as one\n * row with `_tag` and a nullable column per case field. `Expr.is` compiles to\n * `_tag = case` and what is asked of the case, so an interpreter runs it with\n * the operations it has; these cases pin that a row of another case is false\n * under `Expr.is`, while the stored column is null there and unknown under a\n * comparison.\n */\nimport { Schema } from 'effect'\nimport { Entity, Expr, Order, Query } from '../index.js'\nimport type { ConformanceCase } from './index.js'\n\n/** `cents` is shared by `Priced` and `Held`, so one nullable column serves two cases. */\nconst Cents = Schema.Int\n\nexport const Variant = Entity.defineVariants('Variant', {\n Priced: { id: Schema.String, label: Schema.String, cents: Cents },\n Free: { id: Schema.String, label: Schema.String },\n Held: { id: Schema.String, label: Schema.String, cents: Cents, until: Schema.String },\n})\n\n/** A stored row: every field of every case, null where the row is of another. */\nexport interface VariantRow {\n readonly _tag: 'Priced' | 'Free' | 'Held'\n readonly id: string\n readonly label: string\n readonly cents: number | null\n readonly until: string | null\n readonly [key: string]: unknown\n}\n\nexport const variantRows: ReadonlyArray<VariantRow> = [\n { _tag: 'Priced', id: 'p1', label: 'Mug', cents: 500, until: null },\n { _tag: 'Priced', id: 'p2', label: 'Lamp', cents: 1500, until: null },\n { _tag: 'Free', id: 'f1', label: 'Sticker', cents: null, until: null },\n { _tag: 'Held', id: 'h1', label: 'Chair', cents: 900, until: '2026-02-01' },\n]\n\nconst from = Query.from(Variant)\nconst byId = Query.orderBy(Order.asc(Variant.fields.id))\nconst cheapPriced = Expr.is(Variant, 'Priced', ({ cents }) => Expr.lt(cents, 1000))\n\nexport const variantCases: ReadonlyArray<ConformanceCase> = [\n {\n what: 'is matches the rows of a case',\n body: from.pipe(Query.where(Expr.is(Variant, 'Priced')), byId),\n input: {},\n expected: ['p1', 'p2'],\n },\n {\n what: 'is asks of the case’s fields',\n body: from.pipe(Query.where(cheapPriced), byId),\n input: {},\n expected: ['p1'],\n },\n {\n what: 'not of is holds on every other case, which is false and never unknown',\n body: from.pipe(Query.where(Expr.not(cheapPriced)), byId),\n input: {},\n expected: ['f1', 'h1', 'p2'],\n },\n {\n what: 'a stored case field is null on another case, so a comparison drops that row',\n body: from.pipe(Query.where(Expr.lt(Variant.fields.cents, 1000)), byId),\n input: {},\n expected: ['h1', 'p1'],\n },\n {\n what: 'and so does its not',\n body: from.pipe(Query.where(Expr.not(Expr.lt(Variant.fields.cents, 1000))), byId),\n input: {},\n expected: ['p2'],\n },\n {\n what: 'a case field is never null within its case',\n body: from.pipe(\n Query.where(Expr.is(Variant, 'Priced', ({ cents }) => Expr.isNull(cents))),\n byId,\n ),\n input: {},\n expected: [],\n },\n {\n what: 'a field of one case is read within it',\n body: from.pipe(\n Query.where(Expr.is(Variant, 'Held', ({ until }) => Expr.eq(until, '2026-02-01'))),\n byId,\n ),\n input: {},\n expected: ['h1'],\n },\n {\n what: 'several cases are an in over _tag',\n body: from.pipe(Query.where(Expr.in(Variant.fields._tag, ['Free', 'Held'])), byId),\n input: {},\n expected: ['f1', 'h1'],\n },\n {\n what: 'cases combine under or',\n body: from.pipe(\n Query.where(\n Expr.or(\n Expr.is(Variant, 'Free'),\n Expr.is(Variant, 'Priced', ({ cents }) => Expr.gt(cents, 1000)),\n ),\n ),\n byId,\n ),\n input: {},\n expected: ['f1', 'p2'],\n },\n]\n"],"mappings":";;;;;;;;;;;;AAaA,MAAM,QAAQ,OAAO;AAErB,MAAa,UAAU,OAAO,eAAe,WAAW;CACtD,QAAQ;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;EAAQ,OAAO;CAAM;CAChE,MAAM;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;CAAO;CAChD,MAAM;EAAE,IAAI,OAAO;EAAQ,OAAO,OAAO;EAAQ,OAAO;EAAO,OAAO,OAAO;CAAO;AACtF,CAAC;AAYD,MAAa,cAAyC;CACpD;EAAE,MAAM;EAAU,IAAI;EAAM,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EACN,MAAM,KAAK,KACT,MAAM,MAAM,KAAK,GAAG,SAAS,WAAW,EAAE,YAAY,KAAK,OAAO,KAAK,CAAC,CAAC,GACzE,IACF;EACA,OAAO,CAAC;EACR,UAAU,CAAC;CACb;CACA;EACE,MAAM;EACN,MAAM,KAAK,KACT,MAAM,MAAM,KAAK,GAAG,SAAS,SAAS,EAAE,YAAY,KAAK,GAAG,OAAO,YAAY,CAAC,CAAC,GACjF,IACF;EACA,OAAO,CAAC;EACR,UAAU,CAAC,IAAI;CACjB;CACA;EACE,MAAM;EACN,MAAM,KAAK,KAAK,MAAM,MAAM,KAAK,GAAG,QAAQ,OAAO,MAAM,CAAC,QAAQ,MAAM,CAAC,CAAC,GAAG,IAAI;EACjF,OAAO,CAAC;EACR,UAAU,CAAC,MAAM,IAAI;CACvB;CACA;EACE,MAAM;EACN,MAAM,KAAK,KACT,MAAM,MACJ,KAAK,GACH,KAAK,GAAG,SAAS,MAAM,GACvB,KAAK,GAAG,SAAS,WAAW,EAAE,YAAY,KAAK,GAAG,OAAO,GAAI,CAAC,CAChE,CACF,GACA,IACF;EACA,OAAO,CAAC;EACR,UAAU,CAAC,MAAM,IAAI;CACvB;AACF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
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"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Match, Option, Schema } from "effect";
|
|
2
|
+
// src/context.ts
|
|
3
|
+
/**
|
|
4
|
+
* A write's context as terms of `Expr`: who asks (`Expr.viewer`) and what
|
|
5
|
+
* time it is (`Expr.now`). Each is a value no row and no input holds, which
|
|
6
|
+
* each side provides once: a server from its principal and its clock, a
|
|
7
|
+
* client from `Remote.make`'s `viewer` and its stand-in for the time.
|
|
8
|
+
*/
|
|
9
|
+
const Millis = Schema.Int;
|
|
10
|
+
/** `Expr.viewer`: whoever asks, as a row of `entity`. */
|
|
11
|
+
const viewer = (entity) => Object.freeze({
|
|
12
|
+
_tag: "Viewer",
|
|
13
|
+
entity: entity.identity,
|
|
14
|
+
target: () => entity,
|
|
15
|
+
schema: Schema.String
|
|
16
|
+
});
|
|
17
|
+
/** `Expr.now`: the time of the write. */
|
|
18
|
+
const now = Object.freeze({
|
|
19
|
+
_tag: "Now",
|
|
20
|
+
schema: Millis
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* What a context term comes to in `context`, as an interpreter binds it: the
|
|
24
|
+
* viewer's id when they are a row of the term's Entity, else null, as for a
|
|
25
|
+
* visitor; the time. None when the side has no reading of the time, which is
|
|
26
|
+
* not a null: an interpreter refuses what it cannot say.
|
|
27
|
+
*/
|
|
28
|
+
const contextValue = (term, context) => Match.value(term).pipe(Match.tagsExhaustive({
|
|
29
|
+
Viewer: ({ entity }) => Option.some(Option.getOrNull(viewerIdOf(entity, context))),
|
|
30
|
+
Now: () => context.now
|
|
31
|
+
}));
|
|
32
|
+
/** The viewer's id, when they are a row of `entity`. */
|
|
33
|
+
const viewerIdOf = (entity, context) => Option.map(Option.filter(context.viewer, (ref) => ref.entity === entity.name), (ref) => ref.id);
|
|
34
|
+
export { contextValue, now, viewer, viewerIdOf };
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","names":[],"sources":["../src/context.ts"],"sourcesContent":["/**\n * A write's context as terms of `Expr`: who asks (`Expr.viewer`) and what\n * time it is (`Expr.now`). Each is a value no row and no input holds, which\n * each side provides once: a server from its principal and its clock, a\n * client from `Remote.make`'s `viewer` and its stand-in for the time.\n */\nimport { Match, Option, Schema } from 'effect'\nimport type { FieldExpr, OneRelation } from './expr.js'\nimport type { AnyEntity, EntityIdentity, EntityRef, IdOf } from './index.js'\n\n/**\n * Whoever asks, as the row they are of `target`: shaped as a `one` relation\n * to that Entity, so a path can go on from it. Its value is the row's id; for\n * a visitor, or a viewer of another Entity, it is null, which compares as\n * SQL's unknown.\n */\nexport interface ViewerExpr<T, Name extends string = string> {\n readonly _tag: 'Viewer'\n readonly entity: EntityIdentity<Name>\n readonly target: () => AnyEntity\n readonly schema: Schema.Codec<T, unknown>\n}\n\n/**\n * What the row of whoever asks holds, or the row reached from it through `one`\n * relations (`Expr.path(Expr.viewer(User), end)`): a field of that row. Null\n * for a visitor, a viewer of another Entity, a null link, or a row the reader\n * may not see. `Entity.sets` reads one, and so may a query body or a rule:\n * SQL reads the viewer's row under its Entity's `visible` rule, and the client\n * judges it from the rows it holds.\n */\nexport interface ViewerPathExpr<T> {\n readonly _tag: 'ViewerPath'\n readonly viewer: ViewerExpr<unknown>\n /** The relations followed from the viewer's row, in order; empty for a field of it. */\n readonly via: ReadonlyArray<OneRelation>\n readonly field: FieldExpr<T>\n}\n\n/** The time of the write, in milliseconds since the epoch. */\nexport interface NowExpr<T> {\n readonly _tag: 'Now'\n readonly schema: Schema.Codec<T, unknown>\n}\n\n/**\n * What the context terms read, as one side provides it: the viewer as a\n * ref, none for a visitor; the time, none where the side has no reading of\n * it (a client judging a list, which knows no time the server judged it at).\n */\nexport interface ExprContext {\n readonly viewer: Option.Option<EntityRef>\n readonly now: Option.Option<number>\n}\n\nconst Millis = Schema.Int\n\n/** `Expr.viewer`: whoever asks, as a row of `entity`. */\nexport const viewer = <E extends AnyEntity>(entity: E): ViewerExpr<IdOf<E>, E['name']> =>\n Object.freeze({\n _tag: 'Viewer',\n entity: entity.identity,\n target: () => entity,\n // A ref's id travels as text, whatever the Entity's id field stores.\n schema: Schema.String as unknown as Schema.Codec<IdOf<E>, unknown>,\n })\n\n/** `Expr.now`: the time of the write. */\nexport const now: NowExpr<number> = Object.freeze({ _tag: 'Now', schema: Millis })\n\n/**\n * What a context term comes to in `context`, as an interpreter binds it: the\n * viewer's id when they are a row of the term's Entity, else null, as for a\n * visitor; the time. None when the side has no reading of the time, which is\n * not a null: an interpreter refuses what it cannot say.\n */\nexport const contextValue = (\n term: ViewerExpr<unknown> | NowExpr<unknown>,\n context: ExprContext,\n): Option.Option<string | number | null> =>\n Match.value(term).pipe(\n Match.tagsExhaustive({\n Viewer: ({ entity }): Option.Option<string | number | null> =>\n Option.some(Option.getOrNull(viewerIdOf(entity, context))),\n Now: () => context.now,\n }),\n )\n\n/** The viewer's id, when they are a row of `entity`. */\nexport const viewerIdOf = (\n entity: { readonly name: string },\n context: Pick<ExprContext, 'viewer'>,\n): Option.Option<string> =>\n Option.map(\n Option.filter(context.viewer, ref => ref.entity === entity.name),\n ref => ref.id,\n )\n"],"mappings":";;;;;;;;AAuDA,MAAM,SAAS,OAAO;;AAGtB,MAAa,UAA+B,WAC1C,OAAO,OAAO;CACZ,MAAM;CACN,QAAQ,OAAO;CACf,cAAc;CAEd,QAAQ,OAAO;AACjB,CAAC;;AAGH,MAAa,MAAuB,OAAO,OAAO;CAAE,MAAM;CAAO,QAAQ;AAAO,CAAC;;;;;;;AAQjF,MAAa,gBACX,MACA,YAEA,MAAM,MAAM,IAAI,CAAC,CAAC,KAChB,MAAM,eAAe;CACnB,SAAS,EAAE,aACT,OAAO,KAAK,OAAO,UAAU,WAAW,QAAQ,OAAO,CAAC,CAAC;CAC3D,WAAW,QAAQ;AACrB,CAAC,CACH;;AAGF,MAAa,cACX,QACA,YAEA,OAAO,IACL,OAAO,OAAO,QAAQ,SAAQ,QAAO,IAAI,WAAW,OAAO,IAAI,IAC/D,QAAO,IAAI,EACb"}
|
|
@@ -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,QAAQ;CACjC,IAAI,UAAU,KAAA,GAAW,OAAO;CAChC,MAAM,QAAe;EAAE,WAAW,CAAC;EAAG,SAAS,CAAC;EAAG,MAAM,CAAC;EAAG,UAAU;CAAE;CACzE,OAAO,IAAI,UAAU,KAAK;CAC1B,OAAO;AACT;AAYA,MAAa,0BAAU,IAAI,QAA0B;AAErD,MAAM,cAAc;EACjB,eAAe;CAChB,OAAO;EACL,OAAO,SAAS,cAAc,MAAM,SAAS;CAC/C;AACF;AAEA,MAA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