@reactionary/provider-fake 0.0.27

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 ADDED
@@ -0,0 +1,7 @@
1
+ # Fake
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build provider-fake` to build the library.
package/index.js ADDED
@@ -0,0 +1,766 @@
1
+ // core/src/cache/redis-cache.ts
2
+ import { Redis } from "@upstash/redis";
3
+
4
+ // core/src/providers/base.provider.ts
5
+ var BaseProvider = class {
6
+ constructor(schema, querySchema, mutationSchema) {
7
+ this.schema = schema;
8
+ this.querySchema = querySchema;
9
+ this.mutationSchema = mutationSchema;
10
+ }
11
+ /**
12
+ * Validates that the final domain model constructed by the provider
13
+ * fulfills the schema as defined. This will throw an exception.
14
+ */
15
+ assert(value) {
16
+ return this.schema.parse(value);
17
+ }
18
+ /**
19
+ * Creates a new model entity based on the schema defaults.
20
+ */
21
+ newModel() {
22
+ return this.schema.parse({});
23
+ }
24
+ /**
25
+ * Retrieves a set of entities matching the list of queries. The size of
26
+ * the resulting list WILL always match the size of the query list. The
27
+ * result list will never contain nulls or undefined. The order
28
+ * of the results will match the order of the queries.
29
+ */
30
+ async query(queries, session) {
31
+ const results = await this.fetch(queries, session);
32
+ for (const result of results) {
33
+ this.assert(result);
34
+ }
35
+ return results;
36
+ }
37
+ /**
38
+ * Executes the listed mutations in order and returns the final state
39
+ * resulting from that set of operations.
40
+ */
41
+ async mutate(mutations, session) {
42
+ const result = await this.process(mutations, session);
43
+ this.assert(result);
44
+ return result;
45
+ }
46
+ };
47
+
48
+ // core/src/providers/identity.provider.ts
49
+ var IdentityProvider = class extends BaseProvider {
50
+ };
51
+
52
+ // core/src/providers/product.provider.ts
53
+ var ProductProvider = class extends BaseProvider {
54
+ };
55
+
56
+ // core/src/providers/search.provider.ts
57
+ var SearchProvider = class extends BaseProvider {
58
+ };
59
+
60
+ // core/src/schemas/capabilities.schema.ts
61
+ import { z } from "zod";
62
+ var CapabilitiesSchema = z.looseInterface({
63
+ product: z.boolean(),
64
+ search: z.boolean(),
65
+ analytics: z.boolean(),
66
+ identity: z.boolean(),
67
+ cart: z.boolean(),
68
+ inventory: z.boolean(),
69
+ price: z.boolean()
70
+ });
71
+
72
+ // core/src/schemas/session.schema.ts
73
+ import { z as z4 } from "zod";
74
+
75
+ // core/src/schemas/models/identity.model.ts
76
+ import { z as z3 } from "zod";
77
+
78
+ // core/src/schemas/models/base.model.ts
79
+ import { z as z2 } from "zod";
80
+ var CacheInformationSchema = z2.looseInterface({
81
+ hit: z2.boolean().default(false),
82
+ key: z2.string().default("")
83
+ });
84
+ var MetaSchema = z2.looseInterface({
85
+ cache: CacheInformationSchema.default(() => CacheInformationSchema.parse({})),
86
+ placeholder: z2.boolean().default(false).describe("Whether or not the entity exists in a remote system, or is a default placeholder.")
87
+ });
88
+ var BaseModelSchema = z2.looseInterface({
89
+ meta: MetaSchema.default(() => MetaSchema.parse({}))
90
+ });
91
+
92
+ // core/src/schemas/models/identity.model.ts
93
+ var IdentityTypeSchema = z3.enum(["Anonymous", "Guest", "Registered"]);
94
+ var IdentitySchema = BaseModelSchema.extend({
95
+ id: z3.string().default(""),
96
+ type: IdentityTypeSchema.default("Anonymous"),
97
+ token: z3.string().optional(),
98
+ issued: z3.coerce.date().default(/* @__PURE__ */ new Date()),
99
+ expiry: z3.coerce.date().default(/* @__PURE__ */ new Date())
100
+ });
101
+
102
+ // core/src/schemas/session.schema.ts
103
+ var SessionSchema = z4.looseObject({
104
+ id: z4.string(),
105
+ identity: IdentitySchema.default(() => IdentitySchema.parse({}))
106
+ });
107
+
108
+ // core/src/schemas/models/cart.model.ts
109
+ import { z as z6 } from "zod";
110
+
111
+ // core/src/schemas/models/identifiers.model.ts
112
+ import { z as z5 } from "zod";
113
+ var FacetIdentifierSchema = z5.looseInterface({
114
+ key: z5.string().default("").nonoptional()
115
+ });
116
+ var FacetValueIdentifierSchema = z5.looseInterface({
117
+ facet: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
118
+ key: z5.string().default("")
119
+ });
120
+ var SKUIdentifierSchema = z5.looseInterface({
121
+ key: z5.string().default("").nonoptional()
122
+ });
123
+ var ProductIdentifierSchema = z5.looseInterface({
124
+ key: z5.string().default("")
125
+ });
126
+ var SearchIdentifierSchema = z5.looseInterface({
127
+ term: z5.string().default(""),
128
+ page: z5.number().default(0),
129
+ pageSize: z5.number().default(20),
130
+ facets: z5.array(FacetValueIdentifierSchema.required()).default(() => [])
131
+ });
132
+ var CartIdentifierSchema = z5.looseInterface({
133
+ key: z5.string().default("")
134
+ });
135
+ var CartItemIdentifierSchema = z5.looseInterface({
136
+ key: z5.string().default("")
137
+ });
138
+ var PriceIdentifierSchema = z5.looseInterface({
139
+ sku: SKUIdentifierSchema.default(() => SKUIdentifierSchema.parse({}))
140
+ });
141
+
142
+ // core/src/schemas/models/cart.model.ts
143
+ var CartItemSchema = z6.looseInterface({
144
+ identifier: CartItemIdentifierSchema.default(() => CartItemIdentifierSchema.parse({})),
145
+ product: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
146
+ quantity: z6.number().default(0)
147
+ });
148
+ var CartSchema = BaseModelSchema.extend({
149
+ identifier: CartIdentifierSchema.default(() => CartIdentifierSchema.parse({})),
150
+ items: z6.array(CartItemSchema).default(() => [])
151
+ });
152
+
153
+ // core/src/schemas/models/currency.model.ts
154
+ import { z as z7 } from "zod";
155
+ var CurrencySchema = z7.enum([
156
+ "AED",
157
+ "AFN",
158
+ "ALL",
159
+ "AMD",
160
+ "ANG",
161
+ "AOA",
162
+ "ARS",
163
+ "AUD",
164
+ "AWG",
165
+ "AZN",
166
+ "BAM",
167
+ "BBD",
168
+ "BDT",
169
+ "BGN",
170
+ "BHD",
171
+ "BIF",
172
+ "BMD",
173
+ "BND",
174
+ "BOB",
175
+ "BOV",
176
+ "BRL",
177
+ "BSD",
178
+ "BTN",
179
+ "BWP",
180
+ "BYN",
181
+ "BZD",
182
+ "CAD",
183
+ "CDF",
184
+ "CHE",
185
+ "CHF",
186
+ "CHW",
187
+ "CLF",
188
+ "CLP",
189
+ "CNY",
190
+ "COP",
191
+ "COU",
192
+ "CRC",
193
+ "CUC",
194
+ "CUP",
195
+ "CVE",
196
+ "CZK",
197
+ "DJF",
198
+ "DKK",
199
+ "DOP",
200
+ "DZD",
201
+ "EGP",
202
+ "ERN",
203
+ "ETB",
204
+ "EUR",
205
+ "FJD",
206
+ "FKP",
207
+ "GBP",
208
+ "GEL",
209
+ "GHS",
210
+ "GIP",
211
+ "GMD",
212
+ "GNF",
213
+ "GTQ",
214
+ "GYD",
215
+ "HKD",
216
+ "HNL",
217
+ "HRK",
218
+ "HTG",
219
+ "HUF",
220
+ "IDR",
221
+ "ILS",
222
+ "INR",
223
+ "IQD",
224
+ "IRR",
225
+ "ISK",
226
+ "JMD",
227
+ "JOD",
228
+ "JPY",
229
+ "KES",
230
+ "KGS",
231
+ "KHR",
232
+ "KMF",
233
+ "KPW",
234
+ "KRW",
235
+ "KWD",
236
+ "KYD",
237
+ "KZT",
238
+ "LAK",
239
+ "LBP",
240
+ "LKR",
241
+ "LRD",
242
+ "LSL",
243
+ "LYD",
244
+ "MAD",
245
+ "MDL",
246
+ "MGA",
247
+ "MKD",
248
+ "MMK",
249
+ "MNT",
250
+ "MOP",
251
+ "MRU",
252
+ "MUR",
253
+ "MVR",
254
+ "MWK",
255
+ "MXN",
256
+ "MXV",
257
+ "MYR",
258
+ "MZN",
259
+ "NAD",
260
+ "NGN",
261
+ "NIO",
262
+ "NOK",
263
+ "NPR",
264
+ "NZD",
265
+ "OMR",
266
+ "PAB",
267
+ "PEN",
268
+ "PGK",
269
+ "PHP",
270
+ "PKR",
271
+ "PLN",
272
+ "PYG",
273
+ "QAR",
274
+ "RON",
275
+ "RSD",
276
+ "RUB",
277
+ "RWF",
278
+ "SAR",
279
+ "SBD",
280
+ "SCR",
281
+ "SDG",
282
+ "SEK",
283
+ "SGD",
284
+ "SHP",
285
+ "SLE",
286
+ "SLL",
287
+ "SOS",
288
+ "SRD",
289
+ "SSP",
290
+ "STN",
291
+ "SYP",
292
+ "SZL",
293
+ "THB",
294
+ "TJS",
295
+ "TMT",
296
+ "TND",
297
+ "TOP",
298
+ "TRY",
299
+ "TTD",
300
+ "TVD",
301
+ "TWD",
302
+ "TZS",
303
+ "UAH",
304
+ "UGX",
305
+ "USD",
306
+ "USN",
307
+ "UYI",
308
+ "UYU",
309
+ "UYW",
310
+ "UZS",
311
+ "VED",
312
+ "VES",
313
+ "VND",
314
+ "VUV",
315
+ "WST",
316
+ "XAF",
317
+ "XAG",
318
+ "XAU",
319
+ "XBA",
320
+ "XBB",
321
+ "XBC",
322
+ "XBD",
323
+ "XCD",
324
+ "XDR",
325
+ "XOF",
326
+ "XPD",
327
+ "XPF",
328
+ "XPT",
329
+ "XSU",
330
+ "XTS",
331
+ "XUA",
332
+ "XXX",
333
+ "YER",
334
+ "ZAR",
335
+ "ZMW",
336
+ "ZWL"
337
+ ]);
338
+
339
+ // core/src/schemas/models/inventory.model.ts
340
+ import { z as z8 } from "zod";
341
+ var InventorySchema = BaseModelSchema.extend({
342
+ quantity: z8.number().default(0)
343
+ });
344
+
345
+ // core/src/schemas/models/price.model.ts
346
+ import { z as z9 } from "zod";
347
+ var MonetaryAmountSchema = z9.looseInterface({
348
+ cents: z9.number().default(0).describe("The monetary amount in cent-precision."),
349
+ currency: CurrencySchema.default("XXX").describe("The currency associated with the amount, as a ISO 4217 standardized code.")
350
+ });
351
+ var PriceSchema = BaseModelSchema.extend({
352
+ identifier: PriceIdentifierSchema.default(() => PriceIdentifierSchema.parse({})),
353
+ value: MonetaryAmountSchema.default(() => MonetaryAmountSchema.parse({}))
354
+ });
355
+
356
+ // core/src/schemas/models/product.model.ts
357
+ import { z as z10 } from "zod";
358
+ var SKUSchema = z10.looseInterface({
359
+ identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({}))
360
+ });
361
+ var ProductAttributeSchema = z10.looseInterface({
362
+ id: z10.string(),
363
+ name: z10.string(),
364
+ value: z10.string()
365
+ });
366
+ var ProductSchema = BaseModelSchema.extend({
367
+ identifier: ProductIdentifierSchema.default(() => ProductIdentifierSchema.parse({})),
368
+ name: z10.string().default(""),
369
+ slug: z10.string().default(""),
370
+ description: z10.string().default(""),
371
+ image: z10.string().url().default("https://placehold.co/400"),
372
+ images: z10.string().url().array().default(() => []),
373
+ attributes: z10.array(ProductAttributeSchema).default(() => []),
374
+ skus: z10.array(SKUSchema).default(() => [])
375
+ });
376
+
377
+ // core/src/schemas/models/search.model.ts
378
+ import { z as z11 } from "zod";
379
+ var SearchResultProductSchema = z11.looseInterface({
380
+ identifier: ProductIdentifierSchema.default(ProductIdentifierSchema.parse({})),
381
+ name: z11.string().default(""),
382
+ image: z11.string().url().default("https://placehold.co/400"),
383
+ slug: z11.string().default("")
384
+ });
385
+ var SearchResultFacetValueSchema = z11.looseInterface({
386
+ identifier: FacetValueIdentifierSchema.default(() => FacetValueIdentifierSchema.parse({})),
387
+ name: z11.string().default(""),
388
+ count: z11.number().default(0),
389
+ active: z11.boolean().default(false)
390
+ });
391
+ var SearchResultFacetSchema = z11.looseInterface({
392
+ identifier: FacetIdentifierSchema.default(() => FacetIdentifierSchema.parse({})),
393
+ name: z11.string().default(""),
394
+ values: z11.array(SearchResultFacetValueSchema).default(() => [])
395
+ });
396
+ var SearchResultSchema = BaseModelSchema.extend({
397
+ identifier: SearchIdentifierSchema.default(() => SearchIdentifierSchema.parse({})),
398
+ products: z11.array(SearchResultProductSchema).default(() => []),
399
+ pages: z11.number().default(0),
400
+ facets: z11.array(SearchResultFacetSchema).default(() => [])
401
+ });
402
+
403
+ // core/src/schemas/mutations/base.mutation.ts
404
+ import { z as z12 } from "zod";
405
+ var BaseMutationSchema = z12.looseInterface({
406
+ mutation: z12.ZodLiteral
407
+ });
408
+
409
+ // core/src/schemas/mutations/cart.mutation.ts
410
+ import { z as z13 } from "zod";
411
+ var CartMutationItemAddSchema = BaseMutationSchema.extend({
412
+ mutation: z13.literal("add"),
413
+ cart: CartIdentifierSchema.required(),
414
+ product: ProductIdentifierSchema.required(),
415
+ quantity: z13.number()
416
+ });
417
+ var CartMutationItemRemoveSchema = BaseMutationSchema.extend({
418
+ mutation: z13.literal("remove"),
419
+ cart: CartIdentifierSchema.required(),
420
+ item: CartItemIdentifierSchema.required()
421
+ });
422
+ var CartMutationItemQuantityChangeSchema = BaseMutationSchema.extend({
423
+ mutation: z13.literal("adjustQuantity"),
424
+ cart: CartIdentifierSchema.required(),
425
+ item: CartItemIdentifierSchema.required(),
426
+ quantity: z13.number()
427
+ });
428
+ var CartMutationSchema = z13.union([CartMutationItemAddSchema, CartMutationItemRemoveSchema, CartMutationItemQuantityChangeSchema]);
429
+
430
+ // core/src/schemas/mutations/identity.mutation.ts
431
+ import { z as z14 } from "zod";
432
+ var IdentityMutationLoginSchema = BaseMutationSchema.extend({
433
+ mutation: z14.literal("login"),
434
+ username: z14.string(),
435
+ password: z14.string()
436
+ });
437
+ var IdentityMutationLogoutSchema = BaseMutationSchema.extend({
438
+ mutation: z14.literal("logout")
439
+ });
440
+ var IdentityMutationSchema = z14.union([IdentityMutationLoginSchema, IdentityMutationLogoutSchema]);
441
+
442
+ // core/src/schemas/mutations/inventory.mutation.ts
443
+ import { z as z15 } from "zod";
444
+ var InventoryMutationSchema = z15.union([]);
445
+
446
+ // core/src/schemas/mutations/price.mutation.ts
447
+ import { z as z16 } from "zod";
448
+ var PriceMutationSchema = z16.union([]);
449
+
450
+ // core/src/schemas/mutations/product.mutation.ts
451
+ import { z as z17 } from "zod";
452
+ var ProductMutationSchema = z17.union([]);
453
+
454
+ // core/src/schemas/mutations/search.mutation.ts
455
+ import { z as z18 } from "zod";
456
+ var SearchMutationSchema = z18.union([]);
457
+
458
+ // core/src/schemas/queries/base.query.ts
459
+ import { z as z19 } from "zod";
460
+ var BaseQuerySchema = z19.looseInterface({
461
+ query: z19.ZodLiteral
462
+ });
463
+
464
+ // core/src/schemas/queries/cart.query.ts
465
+ import { z as z20 } from "zod";
466
+ var CartQueryByIdSchema = BaseQuerySchema.extend({
467
+ query: z20.literal("id"),
468
+ cart: CartIdentifierSchema.required()
469
+ });
470
+ var CartQuerySchema = z20.union([CartQueryByIdSchema]);
471
+
472
+ // core/src/schemas/queries/identity.query.ts
473
+ import { z as z21 } from "zod";
474
+ var IdentityQuerySelfSchema = BaseQuerySchema.extend({
475
+ query: z21.literal("self")
476
+ });
477
+ var IdentityQuerySchema = z21.union([IdentityQuerySelfSchema]);
478
+
479
+ // core/src/schemas/queries/inventory.query.ts
480
+ import { z as z22 } from "zod";
481
+ var InventoryQuerySchema = BaseQuerySchema.extend({
482
+ query: z22.literal("sku"),
483
+ sku: z22.string()
484
+ });
485
+
486
+ // core/src/schemas/queries/price.query.ts
487
+ import { z as z23 } from "zod";
488
+ var PriceQueryBySkuSchema = BaseQuerySchema.extend({
489
+ query: z23.literal("sku"),
490
+ sku: SKUIdentifierSchema.required()
491
+ });
492
+ var PriceQuerySchema = z23.union([PriceQueryBySkuSchema]);
493
+
494
+ // core/src/schemas/queries/product.query.ts
495
+ import { z as z24 } from "zod";
496
+ var ProductQueryBySlugSchema = BaseQuerySchema.extend({
497
+ query: z24.literal("slug"),
498
+ slug: z24.string()
499
+ });
500
+ var ProductQueryByIdSchema = BaseQuerySchema.extend({
501
+ query: z24.literal("id"),
502
+ id: z24.string()
503
+ });
504
+ var ProductQuerySchema = z24.union([ProductQueryBySlugSchema, ProductQueryByIdSchema]);
505
+
506
+ // core/src/schemas/queries/search.query.ts
507
+ import { z as z25 } from "zod";
508
+ var SearchQueryByTermSchema = BaseQuerySchema.extend({
509
+ query: z25.literal("term"),
510
+ search: SearchIdentifierSchema.required()
511
+ });
512
+ var SearchQuerySchema = z25.union([SearchQueryByTermSchema]);
513
+
514
+ // providers/fake/src/providers/product.provider.ts
515
+ import { base, en, Faker } from "@faker-js/faker";
516
+ var FakeProductProvider = class extends ProductProvider {
517
+ constructor(config, schema, querySchema, mutationSchema) {
518
+ super(schema, querySchema, mutationSchema);
519
+ this.config = config;
520
+ }
521
+ async fetch(queries, session) {
522
+ const results = new Array();
523
+ for (const query of queries) {
524
+ const generator = new Faker({
525
+ seed: 42,
526
+ locale: [en, base]
527
+ });
528
+ const key = query.id || generator.commerce.isbn();
529
+ const slug = query.slug || generator.lorem.slug();
530
+ const product = {
531
+ identifier: {
532
+ key
533
+ },
534
+ name: generator.commerce.productName(),
535
+ slug,
536
+ attributes: [],
537
+ description: generator.commerce.productDescription(),
538
+ image: generator.image.urlPicsumPhotos({
539
+ width: 600,
540
+ height: 600
541
+ }),
542
+ images: [],
543
+ meta: {
544
+ cache: {
545
+ hit: false,
546
+ key
547
+ },
548
+ placeholder: false
549
+ },
550
+ skus: []
551
+ };
552
+ results.push(product);
553
+ }
554
+ return results;
555
+ }
556
+ process(mutation, session) {
557
+ throw new Error("Method not implemented.");
558
+ }
559
+ };
560
+
561
+ // providers/fake/src/providers/search.provider.ts
562
+ import { Faker as Faker2, en as en2, base as base2 } from "@faker-js/faker";
563
+
564
+ // providers/fake/src/utilities/jitter.ts
565
+ async function jitter(duration, deviation) {
566
+ const j = gaussianRandom(duration, deviation);
567
+ return new Promise((resolve) => setTimeout(resolve, j));
568
+ }
569
+ function gaussianRandom(mean, deviation) {
570
+ const u = 1 - Math.random();
571
+ const v = Math.random();
572
+ const z27 = Math.sqrt(-2 * Math.log(u)) * Math.cos(2 * Math.PI * v);
573
+ return z27 * deviation + mean;
574
+ }
575
+
576
+ // providers/fake/src/providers/search.provider.ts
577
+ var FakeSearchProvider = class extends SearchProvider {
578
+ constructor(config, schema, querySchema, mutationSchema) {
579
+ super(schema, querySchema, mutationSchema);
580
+ this.config = config;
581
+ }
582
+ async fetch(queries, session) {
583
+ const results = [];
584
+ for (const query of queries) {
585
+ const result = await this.get(query.search);
586
+ results.push(result);
587
+ }
588
+ return results;
589
+ }
590
+ process(mutations, session) {
591
+ throw new Error("Method not implemented.");
592
+ }
593
+ async get(identifier) {
594
+ await jitter(this.config.jitter.mean, this.config.jitter.deviation);
595
+ return this.parse({}, identifier);
596
+ }
597
+ parse(data, query) {
598
+ const querySpecificity = 20 - query.term.length - query.page - query.facets.length;
599
+ const totalProducts = 10 * querySpecificity;
600
+ const totalPages = Math.ceil(totalProducts / query.pageSize);
601
+ const productsOnPage = Math.min(totalProducts, query.pageSize);
602
+ const productGenerator = new Faker2({
603
+ seed: querySpecificity,
604
+ locale: [en2, base2]
605
+ });
606
+ const facetGenerator = new Faker2({
607
+ seed: 100,
608
+ locale: [en2, base2]
609
+ });
610
+ const products = new Array();
611
+ const facets = new Array();
612
+ for (let i = 0; i < productsOnPage; i++) {
613
+ products.push({
614
+ identifier: {
615
+ key: productGenerator.commerce.isbn()
616
+ },
617
+ image: productGenerator.image.urlPicsumPhotos({
618
+ height: 300,
619
+ width: 300,
620
+ grayscale: true,
621
+ blur: 8
622
+ }),
623
+ name: productGenerator.commerce.productName(),
624
+ slug: productGenerator.lorem.slug()
625
+ });
626
+ }
627
+ const facetBase = ["color", "size"];
628
+ for (const base3 of facetBase) {
629
+ const facet = {
630
+ identifier: {
631
+ key: base3
632
+ },
633
+ name: base3,
634
+ values: []
635
+ };
636
+ for (let i = 0; i < 10; i++) {
637
+ const valueKey = i.toString();
638
+ const isActive = query.facets.find(
639
+ (x) => x.facet.key === facet.identifier.key && x.key === valueKey
640
+ ) !== void 0;
641
+ facet.values.push({
642
+ active: isActive,
643
+ count: facetGenerator.number.int({ min: 1, max: 50 }),
644
+ identifier: {
645
+ facet: {
646
+ key: facet.identifier.key
647
+ },
648
+ key: valueKey
649
+ },
650
+ name: facetGenerator.color.human()
651
+ });
652
+ }
653
+ facets.push(facet);
654
+ }
655
+ const result = {
656
+ pages: totalPages,
657
+ identifier: {
658
+ term: query.term,
659
+ page: query.page,
660
+ facets: query.facets,
661
+ pageSize: query.pageSize
662
+ },
663
+ facets,
664
+ products,
665
+ meta: {
666
+ cache: {
667
+ hit: false,
668
+ key: ""
669
+ },
670
+ placeholder: false
671
+ }
672
+ };
673
+ return this.schema.parse(result);
674
+ }
675
+ };
676
+
677
+ // providers/fake/src/providers/identity.provider.ts
678
+ import { faker } from "@faker-js/faker";
679
+ var FakeIdentityProvider = class extends IdentityProvider {
680
+ constructor(config, schema, querySchema, mutationSchema) {
681
+ super(schema, querySchema, mutationSchema);
682
+ this.config = config;
683
+ }
684
+ async fetch(queries, session) {
685
+ const results = [];
686
+ for (const query of queries) {
687
+ const result = await this.get(session);
688
+ results.push(result);
689
+ }
690
+ return results;
691
+ }
692
+ async process(mutations, session) {
693
+ let result = this.newModel();
694
+ for (const mutation of mutations) {
695
+ switch (mutation.mutation) {
696
+ case "login":
697
+ result = await this.login(mutation, session);
698
+ break;
699
+ case "logout":
700
+ result = await this.logout(session);
701
+ break;
702
+ }
703
+ }
704
+ return result;
705
+ }
706
+ async login(payload, session) {
707
+ const base3 = this.newModel();
708
+ base3.id = faker.string.uuid();
709
+ base3.token = faker.string.uuid();
710
+ base3.issued = faker.date.recent();
711
+ base3.issued = faker.date.soon();
712
+ base3.type = "Registered";
713
+ return base3;
714
+ }
715
+ async get(session) {
716
+ const base3 = this.schema.parse(session.identity);
717
+ return base3;
718
+ }
719
+ async logout(session) {
720
+ const base3 = this.newModel();
721
+ session.identity = base3;
722
+ return base3;
723
+ }
724
+ };
725
+
726
+ // providers/fake/src/core/initialize.ts
727
+ function withFakeCapabilities(configuration, capabilities) {
728
+ const client = {};
729
+ if (capabilities.product) {
730
+ client.product = new FakeProductProvider(configuration, ProductSchema, ProductQuerySchema, ProductMutationSchema);
731
+ }
732
+ if (capabilities.search) {
733
+ client.search = new FakeSearchProvider(configuration, SearchResultSchema, SearchQuerySchema, SearchMutationSchema);
734
+ }
735
+ if (capabilities.identity) {
736
+ client.identity = new FakeIdentityProvider(configuration, IdentitySchema, IdentityQuerySchema, IdentityMutationSchema);
737
+ }
738
+ return client;
739
+ }
740
+
741
+ // providers/fake/src/schema/capabilities.schema.ts
742
+ var FakeCapabilitiesSchema = CapabilitiesSchema.pick({
743
+ product: true,
744
+ search: true,
745
+ identity: true
746
+ }).partial();
747
+
748
+ // providers/fake/src/schema/configuration.schema.ts
749
+ import { z as z26 } from "zod";
750
+ var FakeConfigurationSchema = z26.looseInterface({
751
+ jitter: z26.looseInterface({
752
+ mean: z26.number().min(0).max(1e4),
753
+ deviation: z26.number().min(0).max(5e3)
754
+ }).default({
755
+ mean: 0,
756
+ deviation: 0
757
+ })
758
+ });
759
+ export {
760
+ FakeCapabilitiesSchema,
761
+ FakeConfigurationSchema,
762
+ FakeIdentityProvider,
763
+ FakeProductProvider,
764
+ FakeSearchProvider,
765
+ withFakeCapabilities
766
+ };
package/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@reactionary/provider-fake",
3
+ "version": "0.0.27",
4
+ "dependencies": {
5
+ "@reactionary/core": "0.0.27",
6
+ "zod": "4.0.0-beta.20250430T185432",
7
+ "@faker-js/faker": "^9.8.0"
8
+ }
9
+ }
@@ -0,0 +1,4 @@
1
+ import { Client } from "@reactionary/core";
2
+ import { FakeConfiguration } from "../schema/configuration.schema";
3
+ import { FakeCapabilities } from "../schema/capabilities.schema";
4
+ export declare function withFakeCapabilities(configuration: FakeConfiguration, capabilities: FakeCapabilities): Partial<Client>;
package/src/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export * from './core/initialize';
2
+ export * from './providers/identity.provider';
3
+ export * from './providers/product.provider';
4
+ export * from './providers/search.provider';
5
+ export * from './schema/capabilities.schema';
6
+ export * from './schema/configuration.schema';
@@ -0,0 +1,12 @@
1
+ import { Identity, IdentityMutation, IdentityMutationLogin, IdentityProvider, IdentityQuery, Session } from '@reactionary/core';
2
+ import { FakeConfiguration } from '../schema/configuration.schema';
3
+ import z from 'zod';
4
+ export declare class FakeIdentityProvider<T extends Identity = Identity, Q extends IdentityQuery = IdentityQuery, M extends IdentityMutation = IdentityMutation> extends IdentityProvider<T, Q, M> {
5
+ protected config: FakeConfiguration;
6
+ constructor(config: FakeConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>);
7
+ protected fetch(queries: Q[], session: Session): Promise<T[]>;
8
+ protected process(mutations: M[], session: Session): Promise<T>;
9
+ protected login(payload: IdentityMutationLogin, session: Session): Promise<T>;
10
+ protected get(session: Session): Promise<T>;
11
+ protected logout(session: Session): Promise<T>;
12
+ }
@@ -0,0 +1,9 @@
1
+ import { BaseMutation, Product, ProductMutation, ProductProvider, ProductQuery, Session } from '@reactionary/core';
2
+ import z from 'zod';
3
+ import { FakeConfiguration } from '../schema/configuration.schema';
4
+ export declare class FakeProductProvider<T extends Product = Product, Q extends ProductQuery = ProductQuery, M extends ProductMutation = ProductMutation> extends ProductProvider<T, Q, M> {
5
+ protected config: FakeConfiguration;
6
+ constructor(config: FakeConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>);
7
+ protected fetch(queries: Q[], session: Session): Promise<T[]>;
8
+ protected process(mutation: BaseMutation[], session: Session): Promise<T>;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { SearchIdentifier, SearchMutation, SearchProvider, SearchQuery, SearchResult, Session } from '@reactionary/core';
2
+ import z from 'zod';
3
+ import { FakeConfiguration } from '../schema/configuration.schema';
4
+ export declare class FakeSearchProvider<T extends SearchResult = SearchResult, Q extends SearchQuery = SearchQuery, M extends SearchMutation = SearchMutation> extends SearchProvider<T, Q, M> {
5
+ protected config: FakeConfiguration;
6
+ constructor(config: FakeConfiguration, schema: z.ZodType<T>, querySchema: z.ZodType<Q, Q>, mutationSchema: z.ZodType<M, M>);
7
+ protected fetch(queries: Q[], session: Session): Promise<T[]>;
8
+ protected process(mutations: M[], session: Session): Promise<T>;
9
+ get(identifier: SearchIdentifier): Promise<T>;
10
+ parse(data: unknown, query: SearchIdentifier): T;
11
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ export declare const FakeCapabilitiesSchema: z.ZodInterface<{
3
+ identity: z.ZodOptional<z.ZodBoolean>;
4
+ search: z.ZodOptional<z.ZodBoolean>;
5
+ product: z.ZodOptional<z.ZodBoolean>;
6
+ }, {
7
+ optional: "identity" | "search" | "product";
8
+ defaulted: never;
9
+ extra: Record<string, unknown>;
10
+ }>;
11
+ export type FakeCapabilities = z.infer<typeof FakeCapabilitiesSchema>;
@@ -0,0 +1,16 @@
1
+ import { z } from 'zod';
2
+ export declare const FakeConfigurationSchema: z.ZodInterface<{
3
+ jitter: z.ZodDefault<z.ZodInterface<{
4
+ mean: z.ZodNumber;
5
+ deviation: z.ZodNumber;
6
+ }, {
7
+ optional: never;
8
+ defaulted: never;
9
+ extra: Record<string, unknown>;
10
+ }>>;
11
+ }, {
12
+ optional: never;
13
+ defaulted: never;
14
+ extra: Record<string, unknown>;
15
+ }>;
16
+ export type FakeConfiguration = z.infer<typeof FakeConfigurationSchema>;
@@ -0,0 +1 @@
1
+ export declare function jitter(duration: number, deviation: number): Promise<unknown>;