@reventlessdev/reventless-gwt 1.0.0-alpha.292 → 1.0.0-alpha.294

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.
@@ -58,7 +58,8 @@ let View = Projection_GWT$ReventlessGwt.Make({
58
58
  cmp: Id$Reventless.StringPure.cmp
59
59
  },
60
60
  consumedEventSchema: consumedEventSchema,
61
- subIdConfig: undefined
61
+ subIdConfig: undefined,
62
+ authorization: "AllowAuthenticated"
62
63
  })({
63
64
  project: project
64
65
  });
@@ -157,3 +157,51 @@ OrdersQuery.describe("OrdersView StateViewSlice queries", () => {
157
157
  ->OrdersQuery.thenRowFromComposite(None)
158
158
  )
159
159
  })
160
+
161
+ // ---------------------------------------------------------------------------
162
+ // Read as a person: a cart is its customer's. A spec file says `@owner`; an
163
+ // inline spec marks the field as the PPX would.
164
+ // ---------------------------------------------------------------------------
165
+
166
+ module CartsReadModel = {
167
+ module Id = Reventless.Id.StringPure
168
+ let name = "Carts"
169
+ let moduleUrl = ""
170
+
171
+ @schema
172
+ type state = {cartId: string, customerId: @s.matches(Reventless.Owner.string) string, items: int}
173
+
174
+ let config = Reventless.ReadModel.config()
175
+ let subIdConfig = None
176
+ }
177
+
178
+ module CartsQuery = Query_GWT.Make(Query_GWT.FromReadModel(CartsReadModel))
179
+
180
+ CartsQuery.describe("Carts read as a person", () => {
181
+ let carts = () =>
182
+ CartsQuery.givenStore([
183
+ ("k1", {cartId: "k1", customerId: "c1", items: 2}),
184
+ ("k2", {cartId: "k2", customerId: "c2", items: 1}),
185
+ ])
186
+
187
+ CartsQuery.test("the customer finds their cart", () =>
188
+ carts()
189
+ ->CartsQuery.asCaller(CartsQuery.Caller.owner("c1"))
190
+ ->CartsQuery.whenQueryById("k1")
191
+ ->CartsQuery.thenRow(Some({cartId: "k1", customerId: "c1", items: 2}))
192
+ )
193
+
194
+ CartsQuery.test("another customer's cart is not there to be found", () =>
195
+ carts()
196
+ ->CartsQuery.asCaller(CartsQuery.Caller.owner("c1"))
197
+ ->CartsQuery.whenQueryById("k2")
198
+ ->CartsQuery.thenRow(None)
199
+ )
200
+
201
+ CartsQuery.test("an operator finds every cart", () =>
202
+ carts()
203
+ ->CartsQuery.asCaller(CartsQuery.Caller.operator)
204
+ ->CartsQuery.whenQueryById("k2")
205
+ ->CartsQuery.thenRow(Some({cartId: "k2", customerId: "c2", items: 1}))
206
+ )
207
+ })
@@ -3,6 +3,7 @@
3
3
  import * as Sury from "sury";
4
4
  import * as Stdlib_Array from "@rescript/runtime/lib/es6/Stdlib_Array.js";
5
5
  import * as Id$Reventless from "@reventlessdev/reventless-spec/src/types/Id.res.mjs";
6
+ import * as Owner$Reventless from "@reventlessdev/reventless-spec/src/components/Owner.res.mjs";
6
7
  import * as ReadModel$Reventless from "@reventlessdev/reventless-spec/src/components/ReadModel.res.mjs";
7
8
  import * as Outcome$ReventlessGwt from "../src/Outcome.res.mjs";
8
9
  import * as Query_GWT$ReventlessGwt from "../src/Query_GWT.res.mjs";
@@ -312,10 +313,84 @@ OrdersQuery.describe("OrdersView StateViewSlice queries", () => {
312
313
  }), undefined));
313
314
  });
314
315
 
316
+ let name$2 = "Carts";
317
+
318
+ let moduleUrl$2 = "";
319
+
320
+ let stateSchema$2 = Sury.$schema(s => ({
321
+ cartId: s.m(Sury.string),
322
+ customerId: s.m(Owner$Reventless.string),
323
+ items: s.m(Sury.int32)
324
+ }));
325
+
326
+ let config$2 = ReadModel$Reventless.config(undefined, undefined, undefined);
327
+
328
+ let CartsReadModel = {
329
+ Id: undefined,
330
+ name: name$2,
331
+ moduleUrl: moduleUrl$2,
332
+ stateSchema: stateSchema$2,
333
+ config: config$2,
334
+ subIdConfig: undefined,
335
+ authorization: "AllowAuthenticated",
336
+ visibility: "Public"
337
+ };
338
+
339
+ let CartsQuery = Query_GWT$ReventlessGwt.Make(Query_GWT$ReventlessGwt.FromReadModel({
340
+ Id: {
341
+ schema: Id$Reventless.StringPure.schema,
342
+ make: prim => prim,
343
+ makeFromString: prim => prim,
344
+ toString: prim => prim,
345
+ cmp: Id$Reventless.StringPure.cmp
346
+ },
347
+ name: name$2,
348
+ moduleUrl: moduleUrl$2,
349
+ stateSchema: stateSchema$2,
350
+ config: config$2,
351
+ subIdConfig: undefined,
352
+ authorization: "AllowAuthenticated",
353
+ visibility: "Public"
354
+ }));
355
+
356
+ CartsQuery.describe("Carts read as a person", () => {
357
+ let carts = () => CartsQuery.givenStore([
358
+ [
359
+ "k1",
360
+ {
361
+ cartId: "k1",
362
+ customerId: "c1",
363
+ items: 2
364
+ }
365
+ ],
366
+ [
367
+ "k2",
368
+ {
369
+ cartId: "k2",
370
+ customerId: "c2",
371
+ items: 1
372
+ }
373
+ ]
374
+ ]);
375
+ CartsQuery.test("the customer finds their cart", () => CartsQuery.thenRow(CartsQuery.whenQueryById(CartsQuery.asCaller(carts(), CartsQuery.Caller.owner("c1", undefined)), "k1"), {
376
+ cartId: "k1",
377
+ customerId: "c1",
378
+ items: 2
379
+ }));
380
+ CartsQuery.test("another customer's cart is not there to be found", () => CartsQuery.thenRow(CartsQuery.whenQueryById(CartsQuery.asCaller(carts(), CartsQuery.Caller.owner("c1", undefined)), "k2"), undefined));
381
+ CartsQuery.test("an operator finds every cart", () => CartsQuery.thenRow(CartsQuery.whenQueryById(CartsQuery.asCaller(carts(), CartsQuery.Caller.operator), "k2"), {
382
+ cartId: "k2",
383
+ customerId: "c2",
384
+ items: 1
385
+ }));
386
+ });
387
+
315
388
  export {
316
389
  CategoriesReadModel,
317
390
  CategoriesQuery,
318
391
  OrdersView,
319
392
  OrdersQuery,
393
+ CartsReadModel,
394
+ CartsQuery,
320
395
  }
321
396
  /* stateSchema Not a pure module */
@@ -93,7 +93,8 @@ let include = Projection_GWT$ReventlessGwt.Make({
93
93
  cmp: Id$Reventless.StringPure.cmp
94
94
  },
95
95
  consumedEventSchema: consumedEventSchema,
96
- subIdConfig: undefined
96
+ subIdConfig: undefined,
97
+ authorization: "AllowAuthenticated"
97
98
  })({
98
99
  project: project
99
100
  });
@@ -152,6 +153,8 @@ let describeWithId = include.describeWithId;
152
153
 
153
154
  let todo = include.todo;
154
155
 
156
+ let givenEventsAt = include.givenEventsAt;
157
+
155
158
  let whenEvents = include.whenEvents;
156
159
 
157
160
  let thenStates = include.thenStates;
@@ -168,6 +171,12 @@ let thenThrow = include.thenThrow;
168
171
 
169
172
  let thenFail = include.thenFail;
170
173
 
174
+ let Caller = include.Caller;
175
+
176
+ let asCaller = include.asCaller;
177
+
178
+ let readableBy = include.readableBy;
179
+
171
180
  export {
172
181
  CategoriesView,
173
182
  CategoriesViewProjection,
@@ -177,6 +186,7 @@ export {
177
186
  todo,
178
187
  test,
179
188
  givenEvents,
189
+ givenEventsAt,
180
190
  whenEvent,
181
191
  whenEvents,
182
192
  thenStates,
@@ -187,5 +197,8 @@ export {
187
197
  thenNoState,
188
198
  thenThrow,
189
199
  thenFail,
200
+ Caller,
201
+ asCaller,
202
+ readableBy,
190
203
  }
191
204
  /* stateSchema Not a pure module */