@reventlessdev/reventless-gwt 1.0.0-alpha.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +916 -0
  2. package/LICENSE +202 -0
  3. package/bin/reventless-dev.mjs +21 -0
  4. package/package.json +54 -0
  5. package/rescript.json +36 -0
  6. package/src/.gwtignore +10 -0
  7. package/src/Automation_GWT.res +207 -0
  8. package/src/Automation_GWT.res.mjs +160 -0
  9. package/src/Behavior_GWT.res +569 -0
  10. package/src/Behavior_GWT.res.mjs +523 -0
  11. package/src/Bind.res +29 -0
  12. package/src/Bind.res.mjs +22 -0
  13. package/src/BuildClassifier.res +147 -0
  14. package/src/BuildClassifier.res.mjs +136 -0
  15. package/src/Cancellation.res +37 -0
  16. package/src/Cancellation.res.mjs +46 -0
  17. package/src/ChildProcess.res +102 -0
  18. package/src/ChildProcess.res.mjs +107 -0
  19. package/src/Cli.res +905 -0
  20. package/src/Cli.res.mjs +952 -0
  21. package/src/Collector.res +212 -0
  22. package/src/Collector.res.mjs +218 -0
  23. package/src/ComponentMeta.res +77 -0
  24. package/src/ComponentMeta.res.mjs +91 -0
  25. package/src/ComponentScan.res +103 -0
  26. package/src/ComponentScan.res.mjs +105 -0
  27. package/src/Delegate_GWT.res +303 -0
  28. package/src/Delegate_GWT.res.mjs +372 -0
  29. package/src/Diff.res +91 -0
  30. package/src/Diff.res.mjs +98 -0
  31. package/src/Discovery.res +105 -0
  32. package/src/Discovery.res.mjs +99 -0
  33. package/src/DomainDeadCode.res +98 -0
  34. package/src/DomainDeadCode.res.mjs +72 -0
  35. package/src/DomainGraph.res +0 -0
  36. package/src/DomainGraph.res.mjs +0 -0
  37. package/src/EventMapping_GWT.res +29 -0
  38. package/src/EventMapping_GWT.res.mjs +44 -0
  39. package/src/Filter.res +45 -0
  40. package/src/Filter.res.mjs +47 -0
  41. package/src/Flow_GWT.res +664 -0
  42. package/src/Flow_GWT.res.mjs +604 -0
  43. package/src/FormatterHuman.res +109 -0
  44. package/src/FormatterHuman.res.mjs +115 -0
  45. package/src/FormatterJson.res +264 -0
  46. package/src/FormatterJson.res.mjs +322 -0
  47. package/src/FormatterJunit.res +93 -0
  48. package/src/FormatterJunit.res.mjs +90 -0
  49. package/src/FormatterTap.res +100 -0
  50. package/src/FormatterTap.res.mjs +131 -0
  51. package/src/FormatterVsCode.res +352 -0
  52. package/src/FormatterVsCode.res.mjs +546 -0
  53. package/src/Hint.res +119 -0
  54. package/src/Hint.res.mjs +124 -0
  55. package/src/InboundTranslation_GWT.res +83 -0
  56. package/src/InboundTranslation_GWT.res.mjs +94 -0
  57. package/src/JestBind.res +70 -0
  58. package/src/JestBind.res.mjs +63 -0
  59. package/src/Loader.res +24 -0
  60. package/src/Loader.res.mjs +23 -0
  61. package/src/LocalHost.res +119 -0
  62. package/src/LocalHost.res.mjs +99 -0
  63. package/src/Mapping_GWT.res +474 -0
  64. package/src/Mapping_GWT.res.mjs +322 -0
  65. package/src/MismatchRender.res +72 -0
  66. package/src/MismatchRender.res.mjs +127 -0
  67. package/src/MultiSourceProjection_GWT.res +316 -0
  68. package/src/MultiSourceProjection_GWT.res.mjs +354 -0
  69. package/src/OutboundTranslation_GWT.res +238 -0
  70. package/src/OutboundTranslation_GWT.res.mjs +186 -0
  71. package/src/Outcome.res +97 -0
  72. package/src/Outcome.res.mjs +93 -0
  73. package/src/PackageScan.res +80 -0
  74. package/src/PackageScan.res.mjs +81 -0
  75. package/src/PlatformRunner.res +181 -0
  76. package/src/PlatformRunner.res.mjs +176 -0
  77. package/src/PlatformScan.res +142 -0
  78. package/src/PlatformScan.res.mjs +132 -0
  79. package/src/ProcessManager.res +135 -0
  80. package/src/ProcessManager.res.mjs +119 -0
  81. package/src/Projection_GWT.res +312 -0
  82. package/src/Projection_GWT.res.mjs +332 -0
  83. package/src/Query_GWT.res +379 -0
  84. package/src/Query_GWT.res.mjs +367 -0
  85. package/src/RenderRescript.res +125 -0
  86. package/src/RenderRescript.res.mjs +141 -0
  87. package/src/RunWorker.res +24 -0
  88. package/src/RunWorker.res.mjs +16 -0
  89. package/src/RunnerTypes.res +68 -0
  90. package/src/RunnerTypes.res.mjs +60 -0
  91. package/src/SideEffect_GWT.res +157 -0
  92. package/src/SideEffect_GWT.res.mjs +113 -0
  93. package/src/StateChange/ExternalAddCategorySlice.res +25 -0
  94. package/src/StateChange/ExternalAddCategorySlice.res.mjs +34 -0
  95. package/src/StateChange/ExternalAddCategorySlice_Behavior.res +19 -0
  96. package/src/StateChange/ExternalAddCategorySlice_Behavior.res.mjs +46 -0
  97. package/src/StateChange/WithFixtures.res +22 -0
  98. package/src/StateChange/WithFixtures.res.mjs +31 -0
  99. package/src/StateChange/WithFixtures_Behavior.res +17 -0
  100. package/src/StateChange/WithFixtures_Behavior.res.mjs +37 -0
  101. package/src/StateChange/WithManualOpen.res +23 -0
  102. package/src/StateChange/WithManualOpen.res.mjs +31 -0
  103. package/src/StateChange/WithManualOpen_Behavior.res +17 -0
  104. package/src/StateChange/WithManualOpen_Behavior.res.mjs +37 -0
  105. package/src/StubRuntime.res +54 -0
  106. package/src/StubRuntime.res.mjs +55 -0
  107. package/src/TestFixtures.res +16 -0
  108. package/src/TestFixtures.res.mjs +34 -0
  109. package/src/Watch.res +108 -0
  110. package/src/Watch.res.mjs +85 -0
  111. package/src/WatcherProbe.res +56 -0
  112. package/src/WatcherProbe.res.mjs +59 -0
  113. package/src/Worker.res +24 -0
  114. package/src/Worker.res.mjs +9 -0
  115. package/tests/AutomationGwtTest.res +71 -0
  116. package/tests/AutomationGwtTest.res.mjs +189 -0
  117. package/tests/BuildClassifierTest.res +133 -0
  118. package/tests/BuildClassifierTest.res.mjs +176 -0
  119. package/tests/CliRunEntryTest.res +57 -0
  120. package/tests/CliRunEntryTest.res.mjs +65 -0
  121. package/tests/CliWatchScopeTest.res +62 -0
  122. package/tests/CliWatchScopeTest.res.mjs +95 -0
  123. package/tests/ComponentMetaTest.res +67 -0
  124. package/tests/ComponentMetaTest.res.mjs +71 -0
  125. package/tests/DelegateGwtTest.res +487 -0
  126. package/tests/DelegateGwtTest.res.mjs +891 -0
  127. package/tests/DiscoveryTest.res +42 -0
  128. package/tests/DiscoveryTest.res.mjs +43 -0
  129. package/tests/DomainDeadCodeTest.res +119 -0
  130. package/tests/DomainDeadCodeTest.res.mjs +158 -0
  131. package/tests/DomainGraphTest.res +448 -0
  132. package/tests/DomainGraphTest.res.mjs +505 -0
  133. package/tests/FlowAggregateGwtTest.res +171 -0
  134. package/tests/FlowAggregateGwtTest.res.mjs +273 -0
  135. package/tests/FlowCrossPluginGwtTest.res +340 -0
  136. package/tests/FlowCrossPluginGwtTest.res.mjs +798 -0
  137. package/tests/FlowGwtTest.res +222 -0
  138. package/tests/FlowGwtTest.res.mjs +433 -0
  139. package/tests/FormatterGoldenTest.res +125 -0
  140. package/tests/FormatterGoldenTest.res.mjs +162 -0
  141. package/tests/FormatterVsCodeMessageTest.res +41 -0
  142. package/tests/FormatterVsCodeMessageTest.res.mjs +42 -0
  143. package/tests/InboundTranslationGwtTest.res +34 -0
  144. package/tests/InboundTranslationGwtTest.res.mjs +99 -0
  145. package/tests/LocalHostIntegration.res +70 -0
  146. package/tests/LocalHostIntegration.res.mjs +64 -0
  147. package/tests/LocalHostTest.res +71 -0
  148. package/tests/LocalHostTest.res.mjs +63 -0
  149. package/tests/MappingGwtTest.res +350 -0
  150. package/tests/MappingGwtTest.res.mjs +596 -0
  151. package/tests/OutboundTranslationGwtTest.res +59 -0
  152. package/tests/OutboundTranslationGwtTest.res.mjs +139 -0
  153. package/tests/PlatformRunnerTest.res +66 -0
  154. package/tests/PlatformRunnerTest.res.mjs +85 -0
  155. package/tests/PlatformScanTest.res +61 -0
  156. package/tests/PlatformScanTest.res.mjs +56 -0
  157. package/tests/QueryGwtTest.res +161 -0
  158. package/tests/QueryGwtTest.res.mjs +314 -0
  159. package/tests/QueryResolverGwtTest.res +71 -0
  160. package/tests/QueryResolverGwtTest.res.mjs +136 -0
  161. package/tests/RunnerUnitTest.res +219 -0
  162. package/tests/RunnerUnitTest.res.mjs +244 -0
  163. package/tests/SideEffect/FakeOrderNotification.res +23 -0
  164. package/tests/SideEffect/FakeOrderNotification.res.mjs +36 -0
  165. package/tests/SideEffect/FakeOrderNotificationGwtTest.res +35 -0
  166. package/tests/SideEffect/FakeOrderNotificationGwtTest.res.mjs +73 -0
  167. package/tests/SideEffect/MockEmail.res +18 -0
  168. package/tests/SideEffect/MockEmail.res.mjs +47 -0
  169. package/tests/StateChange/ExternalAddCategorySlice_GWT.res +27 -0
  170. package/tests/StateChange/ExternalAddCategorySlice_GWT.res.mjs +70 -0
  171. package/tests/StateChange/WithFixtures_Fixtures.res +9 -0
  172. package/tests/StateChange/WithFixtures_Fixtures.res.mjs +20 -0
  173. package/tests/StateChange/WithFixtures_GWT.res +23 -0
  174. package/tests/StateChange/WithFixtures_GWT.res.mjs +56 -0
  175. package/tests/StateChange/WithManualOpen_Fixtures.res +7 -0
  176. package/tests/StateChange/WithManualOpen_Fixtures.res.mjs +20 -0
  177. package/tests/StateChange/WithManualOpen_GWT.res +17 -0
  178. package/tests/StateChange/WithManualOpen_GWT.res.mjs +56 -0
  179. package/tests/StateChangeSliceGwtTest.res +160 -0
  180. package/tests/StateChangeSliceGwtTest.res.mjs +280 -0
  181. package/tests/StateViewSliceGwtTest.res +64 -0
  182. package/tests/StateViewSliceGwtTest.res.mjs +161 -0
  183. package/tests/WatchDebounceTest.res +106 -0
  184. package/tests/WatchDebounceTest.res.mjs +128 -0
@@ -0,0 +1,314 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as S from "sury/src/S.res.mjs";
4
+ import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
5
+ import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
6
+ import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
7
+ import * as Outcome$ReventlessGwt from "../src/Outcome.res.mjs";
8
+ import * as Query_GWT$ReventlessGwt from "../src/Query_GWT.res.mjs";
9
+
10
+ S.enableJson();
11
+
12
+ let name = "Categories";
13
+
14
+ let moduleUrl = "";
15
+
16
+ let stateSchema = S.schema(s => ({
17
+ categoryId: s.m(S.string),
18
+ name: s.m(S.string),
19
+ archived: s.m(S.bool)
20
+ }));
21
+
22
+ let config = ReadModel$Reventless.config(undefined, undefined, [{
23
+ index: "byName",
24
+ type_: "S",
25
+ idField: "name",
26
+ projectionType: "ALL"
27
+ }]);
28
+
29
+ let CategoriesReadModel = {
30
+ Id: undefined,
31
+ name: name,
32
+ moduleUrl: moduleUrl,
33
+ stateSchema: stateSchema,
34
+ config: config,
35
+ subIdConfig: undefined,
36
+ authorization: "AllowAuthenticated",
37
+ visibility: "Public"
38
+ };
39
+
40
+ let CategoriesQuery = Query_GWT$ReventlessGwt.Make(Query_GWT$ReventlessGwt.FromReadModel({
41
+ Id: {
42
+ schema: Id$Reventless.StringPure.schema,
43
+ make: prim => prim,
44
+ makeFromString: prim => prim,
45
+ toString: prim => prim,
46
+ cmp: Id$Reventless.StringPure.cmp
47
+ },
48
+ name: name,
49
+ moduleUrl: moduleUrl,
50
+ stateSchema: stateSchema,
51
+ config: config,
52
+ subIdConfig: undefined,
53
+ authorization: "AllowAuthenticated",
54
+ visibility: "Public"
55
+ }));
56
+
57
+ CategoriesQuery.describe("Categories ReadModel queries", () => {
58
+ CategoriesQuery.test("primary-id lookup returns the row", () => CategoriesQuery.thenRow(CategoriesQuery.whenQueryById(CategoriesQuery.givenStore([
59
+ [
60
+ "c1",
61
+ {
62
+ categoryId: "c1",
63
+ name: "Electronics",
64
+ archived: false
65
+ }
66
+ ],
67
+ [
68
+ "c2",
69
+ {
70
+ categoryId: "c2",
71
+ name: "Books",
72
+ archived: true
73
+ }
74
+ ]
75
+ ]), "c1"), {
76
+ categoryId: "c1",
77
+ name: "Electronics",
78
+ archived: false
79
+ }));
80
+ CategoriesQuery.test("by-name (GSI) returns matching rows", () => CategoriesQuery.thenRows(CategoriesQuery.whenQuery(CategoriesQuery.givenStore([
81
+ [
82
+ "c1",
83
+ {
84
+ categoryId: "c1",
85
+ name: "Electronics",
86
+ archived: false
87
+ }
88
+ ],
89
+ [
90
+ "c2",
91
+ {
92
+ categoryId: "c2",
93
+ name: "Books",
94
+ archived: true
95
+ }
96
+ ]
97
+ ]), {
98
+ by: "name",
99
+ value: "Electronics",
100
+ index: "byName"
101
+ }), [{
102
+ categoryId: "c1",
103
+ name: "Electronics",
104
+ archived: false
105
+ }]));
106
+ CategoriesQuery.test("missing index produces QueryRowsMismatch", () => {
107
+ let outcome = CategoriesQuery.thenRows(CategoriesQuery.whenQuery(CategoriesQuery.givenStore([[
108
+ "c1",
109
+ {
110
+ categoryId: "c1",
111
+ name: "Electronics",
112
+ archived: false
113
+ }
114
+ ]]), {
115
+ by: "name",
116
+ value: "Electronics",
117
+ index: "byArchived"
118
+ }), []);
119
+ if (outcome.TAG === "Ok") {
120
+ return Outcome$ReventlessGwt.fail({
121
+ TAG: "Throw",
122
+ error: "expected failure, got pass",
123
+ stack: ""
124
+ });
125
+ }
126
+ let other = outcome._0;
127
+ if (other.TAG === "QueryRowsMismatch") {
128
+ return Outcome$ReventlessGwt.pass;
129
+ } else {
130
+ return Outcome$ReventlessGwt.fail({
131
+ TAG: "Throw",
132
+ error: "expected QueryRowsMismatch, got: " + Outcome$ReventlessGwt.kindName(other),
133
+ stack: ""
134
+ });
135
+ }
136
+ });
137
+ CategoriesQuery.test("filter narrows results after the index scan", () => CategoriesQuery.thenRows(CategoriesQuery.whenQuery(CategoriesQuery.givenStore([
138
+ [
139
+ "c1",
140
+ {
141
+ categoryId: "c1",
142
+ name: "Books",
143
+ archived: false
144
+ }
145
+ ],
146
+ [
147
+ "c2",
148
+ {
149
+ categoryId: "c2",
150
+ name: "Books",
151
+ archived: true
152
+ }
153
+ ]
154
+ ]), {
155
+ by: "name",
156
+ value: "Books",
157
+ index: "byName",
158
+ filter: r => !r.archived
159
+ }), [{
160
+ categoryId: "c1",
161
+ name: "Books",
162
+ archived: false
163
+ }]));
164
+ CategoriesQuery.test("limit truncates results and thenRowCount verifies", () => CategoriesQuery.thenRowCount(CategoriesQuery.whenQuery(CategoriesQuery.givenStore(Stdlib_Array.fromInitializer(10, i => {
165
+ let id = "c" + i.toString();
166
+ let state = {
167
+ categoryId: id,
168
+ name: "Books",
169
+ archived: false
170
+ };
171
+ return [
172
+ id,
173
+ state
174
+ ];
175
+ })), {
176
+ by: "name",
177
+ value: "Books",
178
+ index: "byName",
179
+ limit: 3
180
+ }), 3));
181
+ CategoriesQuery.test("composite-id lookup without subIdConfig fails", () => {
182
+ let outcome = CategoriesQuery.thenRowFromComposite(CategoriesQuery.whenQueryByCompositeId(CategoriesQuery.givenStore([]), {
183
+ id: "c1",
184
+ subId: "v1"
185
+ }), undefined);
186
+ if (outcome.TAG === "Ok") {
187
+ return Outcome$ReventlessGwt.fail({
188
+ TAG: "Throw",
189
+ error: "expected failure, got pass",
190
+ stack: ""
191
+ });
192
+ }
193
+ let other = outcome._0;
194
+ if (other.TAG === "QueryRowsMismatch") {
195
+ return Outcome$ReventlessGwt.pass;
196
+ } else {
197
+ return Outcome$ReventlessGwt.fail({
198
+ TAG: "Throw",
199
+ error: "expected QueryRowsMismatch, got: " + Outcome$ReventlessGwt.kindName(other),
200
+ stack: ""
201
+ });
202
+ }
203
+ });
204
+ });
205
+
206
+ let name$1 = "OrdersView";
207
+
208
+ let moduleUrl$1 = "";
209
+
210
+ let stateSchema$1 = S.schema(s => ({
211
+ orderId: s.m(S.string),
212
+ customerId: s.m(S.string),
213
+ total: s.m(S.int)
214
+ }));
215
+
216
+ let consumedEventSchema = S.schema(s => ({
217
+ TAG: "OrderPlaced",
218
+ orderId: s.m(S.string),
219
+ customerId: s.m(S.string),
220
+ total: s.m(S.int)
221
+ }));
222
+
223
+ function project(event) {
224
+ let orderId = event.orderId;
225
+ return [{
226
+ TAG: "Set",
227
+ _0: orderId,
228
+ _1: {
229
+ orderId: orderId,
230
+ customerId: event.customerId,
231
+ total: event.total
232
+ }
233
+ }];
234
+ }
235
+
236
+ let config$1 = ReadModel$Reventless.config(undefined, undefined, undefined);
237
+
238
+ let subIdConfig = {
239
+ subIdField: "customerId",
240
+ getSubId: s => s.customerId
241
+ };
242
+
243
+ let OrdersView = {
244
+ name: name$1,
245
+ moduleUrl: moduleUrl$1,
246
+ stateSchema: stateSchema$1,
247
+ consumedEventSchema: consumedEventSchema,
248
+ project: project,
249
+ config: config$1,
250
+ subIdConfig: subIdConfig,
251
+ authorization: "AllowAuthenticated",
252
+ visibility: "Public"
253
+ };
254
+
255
+ let OrdersQuery = Query_GWT$ReventlessGwt.Make(Query_GWT$ReventlessGwt.FromStateViewSlice({
256
+ name: name$1,
257
+ moduleUrl: moduleUrl$1,
258
+ stateSchema: stateSchema$1,
259
+ consumedEventSchema: consumedEventSchema,
260
+ config: config$1,
261
+ subIdConfig: subIdConfig,
262
+ authorization: "AllowAuthenticated",
263
+ visibility: "Public"
264
+ }));
265
+
266
+ OrdersQuery.describe("OrdersView StateViewSlice queries", () => {
267
+ OrdersQuery.test("composite-id lookup returns the row", () => OrdersQuery.thenRowFromComposite(OrdersQuery.whenQueryByCompositeId(OrdersQuery.givenCompositeStore([
268
+ [
269
+ "ord-1",
270
+ "cust-a",
271
+ {
272
+ orderId: "ord-1",
273
+ customerId: "cust-a",
274
+ total: 100
275
+ }
276
+ ],
277
+ [
278
+ "ord-2",
279
+ "cust-b",
280
+ {
281
+ orderId: "ord-2",
282
+ customerId: "cust-b",
283
+ total: 200
284
+ }
285
+ ]
286
+ ]), {
287
+ id: "ord-1",
288
+ subId: "cust-a"
289
+ }), {
290
+ orderId: "ord-1",
291
+ customerId: "cust-a",
292
+ total: 100
293
+ }));
294
+ OrdersQuery.test("composite-id lookup with wrong subId returns None", () => OrdersQuery.thenRowFromComposite(OrdersQuery.whenQueryByCompositeId(OrdersQuery.givenCompositeStore([[
295
+ "ord-1",
296
+ "cust-a",
297
+ {
298
+ orderId: "ord-1",
299
+ customerId: "cust-a",
300
+ total: 100
301
+ }
302
+ ]]), {
303
+ id: "ord-1",
304
+ subId: "cust-z"
305
+ }), undefined));
306
+ });
307
+
308
+ export {
309
+ CategoriesReadModel,
310
+ CategoriesQuery,
311
+ OrdersView,
312
+ OrdersQuery,
313
+ }
314
+ /* Not a pure module */
@@ -0,0 +1,71 @@
1
+ // Worked example for Query_GWT.MakeResolver — cross-spec (`@resolves` /
2
+ // `@resolvesMany`) GraphQL resolvers. An Orders read model carries a foreign
3
+ // productId (and a productIds array) that resolve into a Products read model;
4
+ // the resolver DSL follows those keys across the spec boundary.
5
+
6
+ S.enableJson()
7
+
8
+ module RM = Reventless.ReadModel
9
+
10
+ module ProductRow = {
11
+ let name = "ProductRow"
12
+
13
+ @schema
14
+ type state = {productId: string, name: string, price: float}
15
+
16
+ let config = RM.config()
17
+ let subIdConfig = None
18
+ }
19
+
20
+ module OrderRow = {
21
+ let name = "OrderRow"
22
+
23
+ @schema
24
+ type state = {orderId: string, productId: string, productIds: array<string>}
25
+
26
+ let config = RM.config(
27
+ ~idResolvers=[
28
+ {
29
+ source: {RM.idField: "productId", subId: NoSubId, resolvedField: Single("product")},
30
+ target: {RM.tableName: "ProductRow", idField: Id},
31
+ },
32
+ ],
33
+ ~idsResolvers=[
34
+ {
35
+ source: {RM.idsField: "productIds", resolvedField: "products"},
36
+ target: {RM.tableName: "ProductRow"},
37
+ },
38
+ ],
39
+ )
40
+ let subIdConfig = None
41
+ }
42
+
43
+ module R = Query_GWT.MakeResolver(OrderRow, ProductRow)
44
+
45
+ let book: ProductRow.state = {productId: "p1", name: "Book", price: 9.99}
46
+ let pen: ProductRow.state = {productId: "p2", name: "Pen", price: 1.5}
47
+ let order: OrderRow.state = {orderId: "order1", productId: "p1", productIds: ["p1", "p2"]}
48
+
49
+ let stores = () => R.givenStores([("order1", order)], [("p1", book), ("p2", pen)])
50
+
51
+ R.describe("Cross-spec resolvers (MakeResolver)", () => {
52
+ R.test("@resolves follows productId into the Products table", () =>
53
+ stores()
54
+ ->R.whenResolve(~field="productId", "order1")
55
+ ->R.thenResolved(Some(book))
56
+ )
57
+
58
+ R.test("@resolvesMany follows productIds into multiple Products rows", () =>
59
+ stores()
60
+ ->R.whenResolveMany(~field="productIds", "order1")
61
+ ->R.thenResolvedMany([book, pen])
62
+ )
63
+
64
+ R.test("resolving an unknown foreign key returns no row", () =>
65
+ R.givenStores([("order2", {OrderRow.orderId: "order2", productId: "px", productIds: []})], [
66
+ ("p1", book),
67
+ ])
68
+ ->R.whenResolve(~field="productId", "order2")
69
+ ->R.thenResolved(None)
70
+ )
71
+ })
@@ -0,0 +1,136 @@
1
+ // Generated by ReScript, PLEASE EDIT WITH CARE
2
+
3
+ import * as S from "sury/src/S.res.mjs";
4
+ import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
5
+ import * as Query_GWT$ReventlessGwt from "../src/Query_GWT.res.mjs";
6
+
7
+ S.enableJson();
8
+
9
+ let stateSchema = S.schema(s => ({
10
+ productId: s.m(S.string),
11
+ name: s.m(S.string),
12
+ price: s.m(S.float)
13
+ }));
14
+
15
+ let config = ReadModel$Reventless.config(undefined, undefined, undefined);
16
+
17
+ let ProductRow = {
18
+ name: "ProductRow",
19
+ stateSchema: stateSchema,
20
+ config: config,
21
+ subIdConfig: undefined,
22
+ authorization: "AllowAuthenticated",
23
+ visibility: "Public"
24
+ };
25
+
26
+ let stateSchema$1 = S.schema(s => ({
27
+ orderId: s.m(S.string),
28
+ productId: s.m(S.string),
29
+ productIds: s.m(S.array(S.string))
30
+ }));
31
+
32
+ let config$1 = ReadModel$Reventless.config([{
33
+ source: {
34
+ idField: "productId",
35
+ subId: "NoSubId",
36
+ resolvedField: {
37
+ TAG: "Single",
38
+ _0: "product"
39
+ }
40
+ },
41
+ target: {
42
+ tableName: "ProductRow",
43
+ idField: "Id"
44
+ }
45
+ }], [{
46
+ source: {
47
+ idsField: "productIds",
48
+ resolvedField: "products"
49
+ },
50
+ target: {
51
+ tableName: "ProductRow"
52
+ }
53
+ }], undefined);
54
+
55
+ let OrderRow = {
56
+ name: "OrderRow",
57
+ stateSchema: stateSchema$1,
58
+ config: config$1,
59
+ subIdConfig: undefined,
60
+ authorization: "AllowAuthenticated",
61
+ visibility: "Public"
62
+ };
63
+
64
+ let R = Query_GWT$ReventlessGwt.MakeResolver(OrderRow)(ProductRow);
65
+
66
+ let book = {
67
+ productId: "p1",
68
+ name: "Book",
69
+ price: 9.99
70
+ };
71
+
72
+ let pen = {
73
+ productId: "p2",
74
+ name: "Pen",
75
+ price: 1.5
76
+ };
77
+
78
+ let order_productIds = [
79
+ "p1",
80
+ "p2"
81
+ ];
82
+
83
+ let order = {
84
+ orderId: "order1",
85
+ productId: "p1",
86
+ productIds: order_productIds
87
+ };
88
+
89
+ function stores() {
90
+ return R.givenStores([[
91
+ "order1",
92
+ order
93
+ ]], [
94
+ [
95
+ "p1",
96
+ book
97
+ ],
98
+ [
99
+ "p2",
100
+ pen
101
+ ]
102
+ ]);
103
+ }
104
+
105
+ R.describe("Cross-spec resolvers (MakeResolver)", () => {
106
+ R.test("@resolves follows productId into the Products table", () => R.thenResolved(R.whenResolve(stores(), "productId", "order1"), book));
107
+ R.test("@resolvesMany follows productIds into multiple Products rows", () => R.thenResolvedMany(R.whenResolveMany(stores(), "productIds", "order1"), [
108
+ book,
109
+ pen
110
+ ]));
111
+ R.test("resolving an unknown foreign key returns no row", () => R.thenResolved(R.whenResolve(R.givenStores([[
112
+ "order2",
113
+ {
114
+ orderId: "order2",
115
+ productId: "px",
116
+ productIds: []
117
+ }
118
+ ]], [[
119
+ "p1",
120
+ book
121
+ ]]), "productId", "order2"), undefined));
122
+ });
123
+
124
+ let RM;
125
+
126
+ export {
127
+ RM,
128
+ ProductRow,
129
+ OrderRow,
130
+ R,
131
+ book,
132
+ pen,
133
+ order,
134
+ stores,
135
+ }
136
+ /* Not a pure module */