@reactionary/fake 0.10.53 → 0.10.54

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.
@@ -11,12 +11,17 @@ var __decorateClass = (decorators, target, key, kind) => {
11
11
  import {
12
12
  Reactionary,
13
13
  StoreCapability,
14
+ StorePaginatedResultSchema,
15
+ StoreQueryByIdSchema,
14
16
  StoreQueryByProximitySchema,
17
+ StoreQueryForListSchema,
15
18
  StoreSchema,
19
+ error,
16
20
  success
17
21
  } from "@reactionary/core";
18
22
  import * as z from "zod";
19
23
  import { base, en, Faker } from "@faker-js/faker";
24
+ import { calcSeed } from "../utilities/seed.js";
20
25
  class FakeStoreCapability extends StoreCapability {
21
26
  config;
22
27
  factory;
@@ -25,26 +30,82 @@ class FakeStoreCapability extends StoreCapability {
25
30
  this.config = config;
26
31
  this.factory = factory;
27
32
  }
28
- async queryByProximity(payload) {
33
+ /**
34
+ * The countries the fake brand has physical stores in.
35
+ */
36
+ getStoreCountries() {
37
+ return ["DK", "SE", "NO", "FI", "US"];
38
+ }
39
+ /**
40
+ * How many physical stores the seed generates per country.
41
+ */
42
+ getStoresPerCountry() {
43
+ return 3;
44
+ }
45
+ /**
46
+ * The seeded set of physical stores: a fixed number per country, generated
47
+ * deterministically from the store key.
48
+ */
49
+ getSeededStores() {
50
+ const stores = [];
51
+ for (const country of this.getStoreCountries()) {
52
+ for (let i = 1; i <= this.getStoresPerCountry(); i++) {
53
+ stores.push(this.generateStore(`${country.toLowerCase()}-${i}`, country));
54
+ }
55
+ }
56
+ return stores;
57
+ }
58
+ generateStore(key, countryCode) {
29
59
  const generator = new Faker({
30
- seed: 42,
60
+ seed: calcSeed(key),
31
61
  locale: [en, base]
32
62
  });
33
- const results = [];
34
- for (let i = 0; i < payload.limit; i++) {
35
- results.push(
36
- this.factory.parseStore(this.context, {
37
- identifier: {
38
- key: `${i}`
39
- },
40
- fulfillmentCenter: {
41
- key: `${i}`
42
- },
43
- name: generator.company.name()
44
- })
45
- );
63
+ const city = generator.location.city();
64
+ return this.factory.parseStore(this.context, {
65
+ identifier: {
66
+ key
67
+ },
68
+ fulfillmentCenter: {
69
+ key
70
+ },
71
+ name: `${generator.company.name()} ${city}`,
72
+ address: {
73
+ identifier: { nickName: key },
74
+ firstName: "",
75
+ lastName: "",
76
+ streetAddress: generator.location.streetAddress(),
77
+ streetNumber: "",
78
+ city,
79
+ region: "",
80
+ postalCode: generator.location.zipCode("####"),
81
+ countryCode
82
+ },
83
+ openingHours: "Mon-Fri 10am-6pm, Sat 10am-3pm"
84
+ });
85
+ }
86
+ async queryByProximity(payload) {
87
+ return success(this.getSeededStores().slice(0, payload.limit));
88
+ }
89
+ async list(payload) {
90
+ const stores = this.getSeededStores();
91
+ const { pageNumber, pageSize } = payload.paginationOptions;
92
+ const startIndex = (pageNumber - 1) * pageSize;
93
+ return success({
94
+ pageNumber,
95
+ pageSize,
96
+ totalCount: stores.length,
97
+ totalPages: Math.ceil(stores.length / pageSize),
98
+ items: stores.slice(startIndex, startIndex + pageSize)
99
+ });
100
+ }
101
+ async getById(payload) {
102
+ const store = this.getSeededStores().find(
103
+ (candidate) => candidate.identifier.key === payload.identifier.key
104
+ );
105
+ if (!store) {
106
+ return error({ type: "NotFound", identifier: payload.identifier });
46
107
  }
47
- return success(results);
108
+ return success(store);
48
109
  }
49
110
  }
50
111
  __decorateClass([
@@ -53,6 +114,18 @@ __decorateClass([
53
114
  outputSchema: z.array(StoreSchema)
54
115
  })
55
116
  ], FakeStoreCapability.prototype, "queryByProximity", 1);
117
+ __decorateClass([
118
+ Reactionary({
119
+ inputSchema: StoreQueryForListSchema,
120
+ outputSchema: StorePaginatedResultSchema
121
+ })
122
+ ], FakeStoreCapability.prototype, "list", 1);
123
+ __decorateClass([
124
+ Reactionary({
125
+ inputSchema: StoreQueryByIdSchema,
126
+ outputSchema: StoreSchema
127
+ })
128
+ ], FakeStoreCapability.prototype, "getById", 1);
56
129
  export {
57
130
  FakeStoreCapability
58
131
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reactionary/fake",
3
- "version": "0.10.53",
3
+ "version": "0.10.54",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "types": "./src/index.d.ts",
@@ -9,7 +9,7 @@
9
9
  "url": "git+https://github.com/Solteq/reactionary.git"
10
10
  },
11
11
  "dependencies": {
12
- "@reactionary/core": "0.10.53",
12
+ "@reactionary/core": "0.10.54",
13
13
  "zod": "4.1.9",
14
14
  "@faker-js/faker": "^9.8.0"
15
15
  },
@@ -1,4 +1,4 @@
1
- import type { Cache, RequestContext, Result, StoreFactory, StoreFactoryOutput, StoreFactoryWithOutput, StoreQueryByProximity } from '@reactionary/core';
1
+ import type { Cache, NotFoundError, RequestContext, Result, StoreFactory, StoreFactoryOutput, StoreFactoryWithOutput, StorePaginatedResult, StoreQueryById, StoreQueryByProximity, StoreQueryForList } from '@reactionary/core';
2
2
  import { StoreCapability } from '@reactionary/core';
3
3
  import type { FakeConfiguration } from '../schema/configuration.schema.js';
4
4
  import type { FakeStoreFactory } from '../factories/store/store.factory.js';
@@ -6,5 +6,21 @@ export declare class FakeStoreCapability<TFactory extends StoreFactory = FakeSto
6
6
  protected config: FakeConfiguration;
7
7
  protected factory: StoreFactoryWithOutput<TFactory>;
8
8
  constructor(config: FakeConfiguration, cache: Cache, context: RequestContext, factory: StoreFactoryWithOutput<TFactory>);
9
+ /**
10
+ * The countries the fake brand has physical stores in.
11
+ */
12
+ protected getStoreCountries(): string[];
13
+ /**
14
+ * How many physical stores the seed generates per country.
15
+ */
16
+ protected getStoresPerCountry(): number;
17
+ /**
18
+ * The seeded set of physical stores: a fixed number per country, generated
19
+ * deterministically from the store key.
20
+ */
21
+ protected getSeededStores(): StoreFactoryOutput<TFactory>[];
22
+ protected generateStore(key: string, countryCode: string): StoreFactoryOutput<TFactory>;
9
23
  queryByProximity(payload: StoreQueryByProximity): Promise<Result<StoreFactoryOutput<TFactory>[]>>;
24
+ list(payload: StoreQueryForList): Promise<Result<StorePaginatedResult>>;
25
+ getById(payload: StoreQueryById): Promise<Result<StoreFactoryOutput<TFactory>, NotFoundError>>;
10
26
  }