@reventlessdev/reventless-core 3.0.0-alpha.240 → 3.0.0-alpha.242
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/CHANGELOG.md +14 -0
- package/package.json +6 -6
- package/src/admin/Platform_Admin.res +1 -16
- package/src/admin/Platform_Admin.res.mjs +2 -30
- package/src/admin/Platform_Admin_Structure.res +25 -0
- package/src/admin/Platform_Admin_Structure.res.mjs +16 -0
- package/src/components/Api/GraphQL_FragmentGenerator.res +49 -1
- package/src/components/Api/GraphQL_FragmentGenerator.res.mjs +23 -1
- package/src/components/Api/SchemaType.res +133 -1
- package/src/components/Api/SchemaType.res.mjs +133 -8
- package/src/components/Api/SuryToJsonSchema.res +36 -0
- package/src/components/Api/SuryToJsonSchema.res.mjs +45 -0
- package/src/components/QueryDb/QueryDb_Operations.res +13 -0
- package/src/components/QueryDb/QueryDb_Operations.res.mjs +5 -0
- package/src/plugin/component/Plugin_Structure.res +9 -0
- package/src/plugin/component/Plugin_Structure.res.mjs +6 -4
- package/src/plugin/component/SchemaWalker.res +16 -3
- package/src/plugin/component/SchemaWalker.res.mjs +17 -6
- package/src/plugin/lifecycle/PluginsReadModelSpec.res +1 -1
- package/tests/admin/Platform_Admin_StructureTest.res +2 -2
- package/tests/api/TaggedUnionSchemaTest.res +198 -0
- package/tests/api/TaggedUnionSchemaTest.res.mjs +176 -0
- package/tests/fixtures/TaggedUnionFixtures.res +88 -0
- package/tests/fixtures/TaggedUnionFixtures.res.mjs +117 -0
- package/tests/querydb/TaggedUnionStampTest.res +163 -0
- package/tests/querydb/TaggedUnionStampTest.res.mjs +267 -0
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
2
|
+
|
|
3
|
+
import * as Stream from "@reventlessdev/rescript-effect/src/Stream.res.mjs";
|
|
4
|
+
import * as Stdlib_JSON from "@rescript/runtime/lib/es6/Stdlib_JSON.js";
|
|
5
|
+
import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
|
|
6
|
+
import * as Stdlib_Option from "@rescript/runtime/lib/es6/Stdlib_Option.js";
|
|
7
|
+
import * as Effect from "effect/Effect";
|
|
8
|
+
import * as QueryDbFixtures$ReventlessCore from "./QueryDbFixtures.res.mjs";
|
|
9
|
+
import * as QueryDb_Operations$ReventlessCore from "../../src/components/QueryDb/QueryDb_Operations.res.mjs";
|
|
10
|
+
import * as TaggedUnionFixtures$ReventlessCore from "../fixtures/TaggedUnionFixtures.res.mjs";
|
|
11
|
+
|
|
12
|
+
let Customers = QueryDb_Operations$ReventlessCore.Make({
|
|
13
|
+
Id: {
|
|
14
|
+
schema: Id$Reventless.StringPure.schema,
|
|
15
|
+
make: prim => prim,
|
|
16
|
+
makeFromString: prim => prim,
|
|
17
|
+
toString: prim => prim,
|
|
18
|
+
cmp: Id$Reventless.StringPure.cmp
|
|
19
|
+
},
|
|
20
|
+
name: TaggedUnionFixtures$ReventlessCore.CustomersSpec.name,
|
|
21
|
+
moduleUrl: TaggedUnionFixtures$ReventlessCore.CustomersSpec.moduleUrl,
|
|
22
|
+
stateSchema: TaggedUnionFixtures$ReventlessCore.CustomersSpec.stateSchema,
|
|
23
|
+
config: TaggedUnionFixtures$ReventlessCore.CustomersSpec.config,
|
|
24
|
+
subIdConfig: TaggedUnionFixtures$ReventlessCore.CustomersSpec.subIdConfig,
|
|
25
|
+
authorization: TaggedUnionFixtures$ReventlessCore.CustomersSpec.authorization,
|
|
26
|
+
visibility: TaggedUnionFixtures$ReventlessCore.CustomersSpec.visibility
|
|
27
|
+
})({
|
|
28
|
+
jsonOps: QueryDbFixtures$ReventlessCore.mockJsonOps
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
let Sightings = QueryDb_Operations$ReventlessCore.Make({
|
|
32
|
+
Id: {
|
|
33
|
+
schema: Id$Reventless.StringPure.schema,
|
|
34
|
+
make: prim => prim,
|
|
35
|
+
makeFromString: prim => prim,
|
|
36
|
+
toString: prim => prim,
|
|
37
|
+
cmp: Id$Reventless.StringPure.cmp
|
|
38
|
+
},
|
|
39
|
+
name: TaggedUnionFixtures$ReventlessCore.SightingsSpec.name,
|
|
40
|
+
moduleUrl: TaggedUnionFixtures$ReventlessCore.SightingsSpec.moduleUrl,
|
|
41
|
+
stateSchema: TaggedUnionFixtures$ReventlessCore.SightingsSpec.stateSchema,
|
|
42
|
+
config: TaggedUnionFixtures$ReventlessCore.SightingsSpec.config,
|
|
43
|
+
subIdConfig: TaggedUnionFixtures$ReventlessCore.SightingsSpec.subIdConfig,
|
|
44
|
+
authorization: TaggedUnionFixtures$ReventlessCore.SightingsSpec.authorization,
|
|
45
|
+
visibility: TaggedUnionFixtures$ReventlessCore.SightingsSpec.visibility
|
|
46
|
+
})({
|
|
47
|
+
jsonOps: QueryDbFixtures$ReventlessCore.mockJsonOps
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
let Items = QueryDb_Operations$ReventlessCore.Make({
|
|
51
|
+
Id: {
|
|
52
|
+
schema: Id$Reventless.StringPure.schema,
|
|
53
|
+
make: prim => prim,
|
|
54
|
+
makeFromString: prim => prim,
|
|
55
|
+
toString: prim => prim,
|
|
56
|
+
cmp: Id$Reventless.StringPure.cmp
|
|
57
|
+
},
|
|
58
|
+
name: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.name,
|
|
59
|
+
moduleUrl: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.moduleUrl,
|
|
60
|
+
stateSchema: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.stateSchema,
|
|
61
|
+
config: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.config,
|
|
62
|
+
subIdConfig: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.subIdConfig,
|
|
63
|
+
authorization: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.authorization,
|
|
64
|
+
visibility: QueryDbFixtures$ReventlessCore.ItemQueryDbSpec.visibility
|
|
65
|
+
})({
|
|
66
|
+
jsonOps: QueryDbFixtures$ReventlessCore.mockJsonOps
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
globalThis.beforeEach(() => QueryDbFixtures$ReventlessCore.reset());
|
|
70
|
+
|
|
71
|
+
function storedRow(id) {
|
|
72
|
+
return Stdlib_Option.getOr(Stdlib_Option.getOr(QueryDbFixtures$ReventlessCore.store.contents[id], [])[0], null);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function field(json, name) {
|
|
76
|
+
return Stdlib_Option.getOr(Stdlib_Option.flatMap(Stdlib_JSON.Decode.object(json), o => o[name]), null);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function string(json) {
|
|
80
|
+
return Stdlib_JSON.Decode.string(json);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
globalThis.describe("QueryDb_Operations stamps union members", () => {
|
|
84
|
+
globalThis.test("the stored value carries __typename beside TAG", async () => {
|
|
85
|
+
await Customers.save("c-1", {
|
|
86
|
+
customerId: "c-1",
|
|
87
|
+
geolocation: {
|
|
88
|
+
TAG: "Located",
|
|
89
|
+
point: {
|
|
90
|
+
lat: 48.2082,
|
|
91
|
+
lng: 16.3738
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, "Init", undefined);
|
|
95
|
+
let geo = field(storedRow("c-1"), "geolocation");
|
|
96
|
+
globalThis.expect(Stdlib_JSON.Decode.string(field(geo, "TAG"))).toEqual("Located");
|
|
97
|
+
globalThis.expect(Stdlib_JSON.Decode.string(field(geo, "__typename"))).toEqual("GeolocationLocated");
|
|
98
|
+
});
|
|
99
|
+
globalThis.test("every arm is stamped as the member type it is", async () => {
|
|
100
|
+
await Customers.save("c-2", {
|
|
101
|
+
customerId: "c-2",
|
|
102
|
+
geolocation: {
|
|
103
|
+
TAG: "Pending",
|
|
104
|
+
requestedFor: "1 High St"
|
|
105
|
+
}
|
|
106
|
+
}, "Init", undefined);
|
|
107
|
+
await Customers.save("c-3", {
|
|
108
|
+
customerId: "c-3",
|
|
109
|
+
geolocation: {
|
|
110
|
+
TAG: "Unresolvable",
|
|
111
|
+
reason: "ambiguous"
|
|
112
|
+
}
|
|
113
|
+
}, "Init", undefined);
|
|
114
|
+
globalThis.expect(Stdlib_JSON.Decode.string(field(field(storedRow("c-2"), "geolocation"), "__typename"))).toEqual("GeolocationPending");
|
|
115
|
+
globalThis.expect(Stdlib_JSON.Decode.string(field(field(storedRow("c-3"), "geolocation"), "__typename"))).toEqual("GeolocationUnresolvable");
|
|
116
|
+
});
|
|
117
|
+
globalThis.test("an optional union and an array of them are stamped too", async () => {
|
|
118
|
+
let state_lastSeen = {
|
|
119
|
+
TAG: "Located",
|
|
120
|
+
point: {
|
|
121
|
+
lat: 1.0,
|
|
122
|
+
lng: 2.0
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
let state_history = [
|
|
126
|
+
{
|
|
127
|
+
TAG: "Pending",
|
|
128
|
+
requestedFor: "somewhere"
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
TAG: "Unresolvable",
|
|
132
|
+
reason: "gone"
|
|
133
|
+
}
|
|
134
|
+
];
|
|
135
|
+
let state = {
|
|
136
|
+
sightingId: "s-1",
|
|
137
|
+
lastSeen: state_lastSeen,
|
|
138
|
+
history: state_history
|
|
139
|
+
};
|
|
140
|
+
await Sightings.save("s-1", state, "Init", undefined);
|
|
141
|
+
let row = storedRow("s-1");
|
|
142
|
+
globalThis.expect(Stdlib_JSON.Decode.string(field(field(row, "lastSeen"), "__typename"))).toEqual("GeolocationLocated");
|
|
143
|
+
let history = Stdlib_Option.getOr(Stdlib_JSON.Decode.array(field(row, "history")), []);
|
|
144
|
+
globalThis.expect(history.map(h => Stdlib_JSON.Decode.string(field(h, "__typename")))).toEqual([
|
|
145
|
+
"GeolocationPending",
|
|
146
|
+
"GeolocationUnresolvable"
|
|
147
|
+
]);
|
|
148
|
+
});
|
|
149
|
+
globalThis.test("an absent optional union leaves nothing behind", async () => {
|
|
150
|
+
await Sightings.save("s-2", {
|
|
151
|
+
sightingId: "s-2",
|
|
152
|
+
lastSeen: undefined,
|
|
153
|
+
history: []
|
|
154
|
+
}, "Init", undefined);
|
|
155
|
+
globalThis.expect(field(storedRow("s-2"), "lastSeen")).toEqual(null);
|
|
156
|
+
});
|
|
157
|
+
globalThis.test("a view with no union field stores what it always stored", async () => {
|
|
158
|
+
await Items.save("item-1", {
|
|
159
|
+
name: "Widget",
|
|
160
|
+
count: 5
|
|
161
|
+
}, "Init", undefined);
|
|
162
|
+
globalThis.expect(JSON.stringify(storedRow("item-1"))).toBe(`{"name":"Widget","count":5,"id":"item-1"}`);
|
|
163
|
+
});
|
|
164
|
+
globalThis.test("saveBatch stamps every row", async () => {
|
|
165
|
+
let batch = [
|
|
166
|
+
[
|
|
167
|
+
"c-4",
|
|
168
|
+
{
|
|
169
|
+
customerId: "c-4",
|
|
170
|
+
geolocation: {
|
|
171
|
+
TAG: "Located",
|
|
172
|
+
point: {
|
|
173
|
+
lat: 0.0,
|
|
174
|
+
lng: 0.0
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
undefined
|
|
179
|
+
],
|
|
180
|
+
[
|
|
181
|
+
"c-5",
|
|
182
|
+
{
|
|
183
|
+
customerId: "c-5",
|
|
184
|
+
geolocation: {
|
|
185
|
+
TAG: "Pending",
|
|
186
|
+
requestedFor: "x"
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
undefined
|
|
190
|
+
]
|
|
191
|
+
];
|
|
192
|
+
await Customers.saveBatch(batch);
|
|
193
|
+
globalThis.expect([
|
|
194
|
+
Stdlib_JSON.Decode.string(field(field(storedRow("c-4"), "geolocation"), "__typename")),
|
|
195
|
+
Stdlib_JSON.Decode.string(field(field(storedRow("c-5"), "geolocation"), "__typename"))
|
|
196
|
+
]).toEqual([
|
|
197
|
+
"GeolocationLocated",
|
|
198
|
+
"GeolocationPending"
|
|
199
|
+
]);
|
|
200
|
+
});
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
globalThis.describe("a stamped row decodes back", () => {
|
|
204
|
+
globalThis.test("the extra key does not disturb the parse", async () => {
|
|
205
|
+
await Customers.save("c-6", {
|
|
206
|
+
customerId: "c-6",
|
|
207
|
+
geolocation: {
|
|
208
|
+
TAG: "Located",
|
|
209
|
+
point: {
|
|
210
|
+
lat: 48.2082,
|
|
211
|
+
lng: 16.3738
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}, "Init", undefined);
|
|
215
|
+
let result = await Effect.runPromise(Stream.runCollect(Customers.loadStream("c-6")));
|
|
216
|
+
if (result.length === 1) {
|
|
217
|
+
let match = result[0];
|
|
218
|
+
let match$1 = match.geolocation;
|
|
219
|
+
switch (match$1.TAG) {
|
|
220
|
+
case "Located" :
|
|
221
|
+
let point = match$1.point;
|
|
222
|
+
globalThis.expect([
|
|
223
|
+
point.lat,
|
|
224
|
+
point.lng
|
|
225
|
+
]).toEqual([
|
|
226
|
+
48.2082,
|
|
227
|
+
16.3738
|
|
228
|
+
]);
|
|
229
|
+
return;
|
|
230
|
+
case "Pending" :
|
|
231
|
+
case "Unresolvable" :
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
globalThis.expect("round trip").toBe("Located with its point intact");
|
|
236
|
+
});
|
|
237
|
+
globalThis.test("a row written before the union field arrives as the first arm", async () => {
|
|
238
|
+
QueryDbFixtures$ReventlessCore.store.contents["c-7"] = [Object.fromEntries([[
|
|
239
|
+
"customerId",
|
|
240
|
+
"c-7"
|
|
241
|
+
]])];
|
|
242
|
+
let result = await Effect.runPromise(Stream.runCollect(Customers.loadStream("c-7")));
|
|
243
|
+
if (result.length === 1) {
|
|
244
|
+
let match = result[0];
|
|
245
|
+
let match$1 = match.geolocation;
|
|
246
|
+
switch (match$1.TAG) {
|
|
247
|
+
case "Pending" :
|
|
248
|
+
globalThis.expect(match$1.requestedFor).toBe("");
|
|
249
|
+
return;
|
|
250
|
+
case "Located" :
|
|
251
|
+
case "Unresolvable" :
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
globalThis.expect("healed row").toBe("Pending");
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
export {
|
|
260
|
+
Customers,
|
|
261
|
+
Sightings,
|
|
262
|
+
Items,
|
|
263
|
+
storedRow,
|
|
264
|
+
field,
|
|
265
|
+
string,
|
|
266
|
+
}
|
|
267
|
+
/* Customers Not a pure module */
|