@reactionary/source 0.0.31 → 0.0.32
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/core/package.json +1 -1
- package/core/src/client/client-builder.ts +63 -0
- package/core/src/decorators/trpc.decorators.ts +144 -0
- package/core/src/index.ts +3 -0
- package/core/src/providers/analytics.provider.ts +2 -28
- package/core/src/providers/base.provider.ts +7 -135
- package/core/src/providers/cart.provider.ts +9 -22
- package/core/src/providers/identity.provider.ts +7 -21
- package/core/src/providers/inventory.provider.ts +4 -18
- package/core/src/providers/price.provider.ts +5 -22
- package/core/src/providers/product.provider.ts +5 -28
- package/core/src/providers/search.provider.ts +5 -22
- package/core/src/schemas/mutations/base.mutation.ts +0 -1
- package/core/src/schemas/mutations/cart.mutation.ts +0 -6
- package/core/src/schemas/mutations/identity.mutation.ts +0 -5
- package/core/src/schemas/queries/base.query.ts +0 -1
- package/core/src/schemas/queries/cart.query.ts +1 -3
- package/core/src/schemas/queries/identity.query.ts +1 -3
- package/core/src/schemas/queries/inventory.query.ts +0 -1
- package/core/src/schemas/queries/price.query.ts +0 -3
- package/core/src/schemas/queries/product.query.ts +2 -7
- package/core/src/schemas/queries/search.query.ts +0 -3
- package/examples/node/package.json +1 -5
- package/examples/node/src/basic/basic-node-provider-model-extension.spec.ts +97 -0
- package/examples/node/src/basic/basic-node-provider-query-extension.spec.ts +84 -0
- package/examples/node/src/basic/basic-node-setup.spec.ts +40 -0
- package/otel/src/index.ts +3 -0
- package/otel/src/trace-decorator.ts +246 -0
- package/package.json +2 -1
- package/providers/algolia/src/core/initialize.ts +3 -3
- package/providers/algolia/src/providers/product.provider.ts +44 -11
- package/providers/algolia/src/providers/search.provider.ts +47 -66
- package/providers/commercetools/src/core/client.ts +0 -1
- package/providers/commercetools/src/core/initialize.ts +8 -9
- package/providers/commercetools/src/providers/cart.provider.ts +58 -90
- package/providers/commercetools/src/providers/identity.provider.ts +34 -51
- package/providers/commercetools/src/providers/inventory.provider.ts +16 -29
- package/providers/commercetools/src/providers/price.provider.ts +30 -35
- package/providers/commercetools/src/providers/product.provider.ts +48 -38
- package/providers/commercetools/src/providers/search.provider.ts +32 -47
- package/providers/commercetools/src/schema/capabilities.schema.ts +1 -1
- package/providers/fake/package.json +1 -0
- package/providers/fake/src/core/initialize.ts +12 -11
- package/providers/fake/src/index.ts +4 -0
- package/providers/fake/src/providers/analytics.provider.ts +19 -0
- package/providers/fake/src/providers/cart.provider.ts +107 -0
- package/providers/fake/src/providers/identity.provider.ts +78 -68
- package/providers/fake/src/providers/inventory.provider.ts +54 -0
- package/providers/fake/src/providers/price.provider.ts +60 -0
- package/providers/fake/src/providers/product.provider.ts +53 -49
- package/providers/fake/src/providers/search.provider.ts +15 -33
- package/trpc/__mocks__/superjson.js +25 -0
- package/trpc/jest.config.ts +14 -0
- package/trpc/package.json +2 -1
- package/trpc/src/client.ts +176 -0
- package/trpc/src/index.ts +35 -62
- package/trpc/src/integration.spec.ts +216 -0
- package/trpc/src/server.ts +123 -0
- package/trpc/src/transparent-client.spec.ts +160 -0
- package/trpc/src/types.ts +142 -0
- package/trpc/tsconfig.json +3 -0
- package/trpc/tsconfig.lib.json +2 -1
- package/trpc/tsconfig.spec.json +15 -0
- package/tsconfig.base.json +0 -2
- package/examples/angular/e2e/example.spec.ts +0 -9
- package/examples/angular/eslint.config.mjs +0 -41
- package/examples/angular/playwright.config.ts +0 -38
- package/examples/angular/project.json +0 -86
- package/examples/angular/public/favicon.ico +0 -0
- package/examples/angular/src/app/app.component.html +0 -6
- package/examples/angular/src/app/app.component.scss +0 -22
- package/examples/angular/src/app/app.component.ts +0 -14
- package/examples/angular/src/app/app.config.ts +0 -16
- package/examples/angular/src/app/app.routes.ts +0 -25
- package/examples/angular/src/app/cart/cart.component.html +0 -4
- package/examples/angular/src/app/cart/cart.component.scss +0 -14
- package/examples/angular/src/app/cart/cart.component.ts +0 -73
- package/examples/angular/src/app/identity/identity.component.html +0 -6
- package/examples/angular/src/app/identity/identity.component.scss +0 -18
- package/examples/angular/src/app/identity/identity.component.ts +0 -49
- package/examples/angular/src/app/product/product.component.html +0 -14
- package/examples/angular/src/app/product/product.component.scss +0 -11
- package/examples/angular/src/app/product/product.component.ts +0 -42
- package/examples/angular/src/app/search/search.component.html +0 -35
- package/examples/angular/src/app/search/search.component.scss +0 -129
- package/examples/angular/src/app/search/search.component.ts +0 -50
- package/examples/angular/src/app/services/product.service.ts +0 -35
- package/examples/angular/src/app/services/search.service.ts +0 -48
- package/examples/angular/src/app/services/trpc.client.ts +0 -27
- package/examples/angular/src/index.html +0 -13
- package/examples/angular/src/main.ts +0 -7
- package/examples/angular/src/styles.scss +0 -17
- package/examples/angular/src/test-setup.ts +0 -6
- package/examples/angular/tsconfig.app.json +0 -10
- package/examples/angular/tsconfig.editor.json +0 -6
- package/examples/angular/tsconfig.json +0 -32
- package/examples/node/src/initialize-algolia.spec.ts +0 -29
- package/examples/node/src/initialize-commercetools.spec.ts +0 -31
- package/examples/node/src/initialize-extended-providers.spec.ts +0 -38
- package/examples/node/src/initialize-mixed-providers.spec.ts +0 -36
- package/examples/node/src/providers/custom-algolia-product.provider.ts +0 -18
- package/examples/node/src/schemas/custom-product.schema.ts +0 -8
- package/examples/trpc-node/.env.example +0 -52
- package/examples/trpc-node/eslint.config.mjs +0 -3
- package/examples/trpc-node/project.json +0 -61
- package/examples/trpc-node/src/assets/.gitkeep +0 -0
- package/examples/trpc-node/src/main.ts +0 -59
- package/examples/trpc-node/src/router-instance.ts +0 -54
- package/examples/trpc-node/tsconfig.app.json +0 -9
- package/examples/trpc-node/tsconfig.json +0 -13
|
@@ -1,92 +1,102 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Identity,
|
|
3
|
-
IdentityMutation,
|
|
4
|
-
IdentityMutationLogin,
|
|
5
3
|
IdentityProvider,
|
|
6
|
-
|
|
4
|
+
IdentityQuerySelf,
|
|
5
|
+
IdentityMutationLogin,
|
|
6
|
+
IdentityMutationLogout,
|
|
7
7
|
Session,
|
|
8
|
+
Cache,
|
|
8
9
|
} from '@reactionary/core';
|
|
9
|
-
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
10
|
import z from 'zod';
|
|
11
|
-
import {
|
|
11
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
12
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
12
13
|
|
|
13
14
|
export class FakeIdentityProvider<
|
|
14
|
-
T extends Identity = Identity
|
|
15
|
-
|
|
16
|
-
M extends IdentityMutation = IdentityMutation
|
|
17
|
-
> extends IdentityProvider<T, Q, M> {
|
|
15
|
+
T extends Identity = Identity
|
|
16
|
+
> extends IdentityProvider<T> {
|
|
18
17
|
protected config: FakeConfiguration;
|
|
18
|
+
private currentIdentity: T | null = null;
|
|
19
19
|
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
schema: z.ZodType<T>,
|
|
23
|
-
querySchema: z.ZodType<Q, Q>,
|
|
24
|
-
mutationSchema: z.ZodType<M, M>,
|
|
25
|
-
cache: any
|
|
26
|
-
) {
|
|
27
|
-
super(schema, querySchema, mutationSchema, cache);
|
|
20
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache) {
|
|
21
|
+
super(schema, cache);
|
|
28
22
|
|
|
29
23
|
this.config = config;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for (const query of queries) {
|
|
36
|
-
const result = await this.get(session);
|
|
37
|
-
|
|
38
|
-
results.push(result);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return results;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected override async process(
|
|
45
|
-
mutations: M[],
|
|
46
|
-
session: Session
|
|
26
|
+
public override async getSelf(
|
|
27
|
+
_payload: IdentityQuerySelf,
|
|
28
|
+
_session: Session
|
|
47
29
|
): Promise<T> {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
if (!this.currentIdentity) {
|
|
31
|
+
const model = this.newModel();
|
|
32
|
+
Object.assign(model, {
|
|
33
|
+
id: 'anonymous',
|
|
34
|
+
type: 'Anonymous',
|
|
35
|
+
issued: new Date(),
|
|
36
|
+
expiry: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours from now
|
|
37
|
+
meta: {
|
|
38
|
+
cache: {
|
|
39
|
+
hit: false,
|
|
40
|
+
key: 'anonymous',
|
|
41
|
+
},
|
|
42
|
+
placeholder: false,
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
this.currentIdentity = this.assert(model);
|
|
59
46
|
}
|
|
60
47
|
|
|
61
|
-
return
|
|
48
|
+
return this.currentIdentity;
|
|
62
49
|
}
|
|
63
50
|
|
|
64
|
-
|
|
51
|
+
public override async login(
|
|
65
52
|
payload: IdentityMutationLogin,
|
|
66
|
-
|
|
53
|
+
_session: Session
|
|
67
54
|
): Promise<T> {
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
55
|
+
const generator = new Faker({
|
|
56
|
+
seed: 42,
|
|
57
|
+
locale: [en, base],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const model = this.newModel();
|
|
61
|
+
Object.assign(model, {
|
|
62
|
+
id: generator.string.uuid(),
|
|
63
|
+
type: 'Registered',
|
|
64
|
+
token: generator.string.alphanumeric(32),
|
|
65
|
+
issued: new Date(),
|
|
66
|
+
expiry: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000), // 7 days from now
|
|
67
|
+
meta: {
|
|
68
|
+
cache: {
|
|
69
|
+
hit: false,
|
|
70
|
+
key: payload.username,
|
|
71
|
+
},
|
|
72
|
+
placeholder: false,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
this.currentIdentity = this.assert(model);
|
|
77
|
+
return this.currentIdentity;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
80
|
+
public override async logout(
|
|
81
|
+
_payload: IdentityMutationLogout,
|
|
82
|
+
_session: Session
|
|
83
|
+
): Promise<T> {
|
|
84
|
+
const model = this.newModel();
|
|
85
|
+
Object.assign(model, {
|
|
86
|
+
id: 'anonymous',
|
|
87
|
+
type: 'Anonymous',
|
|
88
|
+
issued: new Date(),
|
|
89
|
+
expiry: new Date(Date.now() + 24 * 60 * 60 * 1000), // 24 hours from now
|
|
90
|
+
meta: {
|
|
91
|
+
cache: {
|
|
92
|
+
hit: false,
|
|
93
|
+
key: 'anonymous',
|
|
94
|
+
},
|
|
95
|
+
placeholder: false,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
this.currentIdentity = this.assert(model);
|
|
100
|
+
return this.currentIdentity;
|
|
91
101
|
}
|
|
92
|
-
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Inventory,
|
|
3
|
+
InventoryProvider,
|
|
4
|
+
InventoryQuery,
|
|
5
|
+
Session,
|
|
6
|
+
Cache,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import z from 'zod';
|
|
9
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
11
|
+
|
|
12
|
+
export class FakeInventoryProvider<
|
|
13
|
+
T extends Inventory = Inventory
|
|
14
|
+
> extends InventoryProvider<T> {
|
|
15
|
+
protected config: FakeConfiguration;
|
|
16
|
+
|
|
17
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache) {
|
|
18
|
+
super(schema, cache);
|
|
19
|
+
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override async getBySKU(
|
|
24
|
+
payload: InventoryQuery,
|
|
25
|
+
_session: Session
|
|
26
|
+
): Promise<T> {
|
|
27
|
+
// Generate a simple hash from the SKU string for seeding
|
|
28
|
+
let hash = 0;
|
|
29
|
+
const skuString = payload.sku;
|
|
30
|
+
for (let i = 0; i < skuString.length; i++) {
|
|
31
|
+
hash = ((hash << 5) - hash) + skuString.charCodeAt(i);
|
|
32
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const generator = new Faker({
|
|
36
|
+
seed: hash || 42,
|
|
37
|
+
locale: [en, base],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const model = this.newModel();
|
|
41
|
+
Object.assign(model, {
|
|
42
|
+
quantity: generator.number.int({ min: 0, max: 100 }),
|
|
43
|
+
meta: {
|
|
44
|
+
cache: {
|
|
45
|
+
hit: false,
|
|
46
|
+
key: payload.sku,
|
|
47
|
+
},
|
|
48
|
+
placeholder: false,
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return this.assert(model);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Price,
|
|
3
|
+
PriceProvider,
|
|
4
|
+
PriceQueryBySku,
|
|
5
|
+
Session,
|
|
6
|
+
Cache,
|
|
7
|
+
} from '@reactionary/core';
|
|
8
|
+
import z from 'zod';
|
|
9
|
+
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
10
|
+
import { base, en, Faker } from '@faker-js/faker';
|
|
11
|
+
|
|
12
|
+
export class FakePriceProvider<
|
|
13
|
+
T extends Price = Price
|
|
14
|
+
> extends PriceProvider<T> {
|
|
15
|
+
protected config: FakeConfiguration;
|
|
16
|
+
|
|
17
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: Cache) {
|
|
18
|
+
super(schema, cache);
|
|
19
|
+
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public override async getBySKU(
|
|
24
|
+
payload: PriceQueryBySku,
|
|
25
|
+
_session: Session
|
|
26
|
+
): Promise<T> {
|
|
27
|
+
// Generate a simple hash from the SKU key string for seeding
|
|
28
|
+
let hash = 0;
|
|
29
|
+
const skuString = payload.sku.key;
|
|
30
|
+
for (let i = 0; i < skuString.length; i++) {
|
|
31
|
+
hash = ((hash << 5) - hash) + skuString.charCodeAt(i);
|
|
32
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const generator = new Faker({
|
|
36
|
+
seed: hash || 42,
|
|
37
|
+
locale: [en, base],
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const model = this.newModel();
|
|
41
|
+
Object.assign(model, {
|
|
42
|
+
identifier: {
|
|
43
|
+
sku: payload.sku,
|
|
44
|
+
},
|
|
45
|
+
value: {
|
|
46
|
+
cents: generator.number.int({ min: 100, max: 100000 }),
|
|
47
|
+
currency: 'USD',
|
|
48
|
+
},
|
|
49
|
+
meta: {
|
|
50
|
+
cache: {
|
|
51
|
+
hit: false,
|
|
52
|
+
key: payload.sku,
|
|
53
|
+
},
|
|
54
|
+
placeholder: false,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return this.assert(model);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,73 +1,77 @@
|
|
|
1
1
|
import {
|
|
2
|
-
BaseMutation,
|
|
3
2
|
Product,
|
|
4
|
-
ProductMutation,
|
|
5
3
|
ProductProvider,
|
|
6
|
-
|
|
4
|
+
ProductQueryById,
|
|
5
|
+
ProductQueryBySlug,
|
|
7
6
|
Session,
|
|
7
|
+
Cache as ReactinaryCache,
|
|
8
8
|
} from '@reactionary/core';
|
|
9
9
|
import z from 'zod';
|
|
10
10
|
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
11
11
|
import { base, en, Faker } from '@faker-js/faker';
|
|
12
|
+
import { traced } from '@reactionary/otel';
|
|
12
13
|
|
|
13
14
|
export class FakeProductProvider<
|
|
14
|
-
T extends Product = Product
|
|
15
|
-
|
|
16
|
-
M extends ProductMutation = ProductMutation
|
|
17
|
-
> extends ProductProvider<T, Q, M> {
|
|
15
|
+
T extends Product = Product
|
|
16
|
+
> extends ProductProvider<T> {
|
|
18
17
|
protected config: FakeConfiguration;
|
|
19
18
|
|
|
20
|
-
constructor(config: FakeConfiguration, schema: z.ZodType<T>,
|
|
21
|
-
super(schema,
|
|
19
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: ReactinaryCache) {
|
|
20
|
+
super(schema, cache);
|
|
22
21
|
|
|
23
22
|
this.config = config;
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
@traced()
|
|
26
|
+
public override async getById(
|
|
27
|
+
payload: ProductQueryById,
|
|
28
|
+
_session: Session
|
|
29
|
+
): Promise<T> {
|
|
30
|
+
return this.parseSingle(payload);
|
|
31
|
+
}
|
|
28
32
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
public override async getBySlug(
|
|
34
|
+
payload: ProductQueryBySlug,
|
|
35
|
+
_session: Session
|
|
36
|
+
): Promise<T> {
|
|
37
|
+
return this.parseSingle(payload);
|
|
38
|
+
}
|
|
34
39
|
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
protected override parseSingle(body: ProductQueryById | ProductQueryBySlug): T {
|
|
41
|
+
const generator = new Faker({
|
|
42
|
+
seed: 42,
|
|
43
|
+
locale: [en, base],
|
|
44
|
+
});
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
identifier: {
|
|
40
|
-
key: key,
|
|
41
|
-
},
|
|
42
|
-
name: generator.commerce.productName(),
|
|
43
|
-
slug: slug,
|
|
44
|
-
attributes: [],
|
|
45
|
-
description: generator.commerce.productDescription(),
|
|
46
|
-
image: generator.image.urlPicsumPhotos({
|
|
47
|
-
width: 600,
|
|
48
|
-
height: 600,
|
|
49
|
-
}),
|
|
50
|
-
images: [],
|
|
51
|
-
meta: {
|
|
52
|
-
cache: {
|
|
53
|
-
hit: false,
|
|
54
|
-
key: key,
|
|
55
|
-
},
|
|
56
|
-
placeholder: false
|
|
57
|
-
},
|
|
58
|
-
skus: [],
|
|
59
|
-
};
|
|
46
|
+
const key = body.slug || body.id;
|
|
60
47
|
|
|
61
|
-
|
|
62
|
-
|
|
48
|
+
// Create a model instance based on the schema
|
|
49
|
+
const model = this.newModel();
|
|
63
50
|
|
|
64
|
-
|
|
65
|
-
|
|
51
|
+
// Merge the generated data into the model
|
|
52
|
+
Object.assign(model, {
|
|
53
|
+
identifier: {
|
|
54
|
+
key: key,
|
|
55
|
+
},
|
|
56
|
+
name: generator.commerce.productName(),
|
|
57
|
+
slug: key,
|
|
58
|
+
attributes: [],
|
|
59
|
+
description: generator.commerce.productDescription(),
|
|
60
|
+
image: generator.image.urlPicsumPhotos({
|
|
61
|
+
width: 600,
|
|
62
|
+
height: 600,
|
|
63
|
+
}),
|
|
64
|
+
images: [],
|
|
65
|
+
meta: {
|
|
66
|
+
cache: {
|
|
67
|
+
hit: false,
|
|
68
|
+
key: key,
|
|
69
|
+
},
|
|
70
|
+
placeholder: false,
|
|
71
|
+
},
|
|
72
|
+
skus: [],
|
|
73
|
+
});
|
|
66
74
|
|
|
67
|
-
|
|
68
|
-
mutation: BaseMutation[],
|
|
69
|
-
session: Session
|
|
70
|
-
): Promise<T> {
|
|
71
|
-
throw new Error('Method not implemented.');
|
|
75
|
+
return this.assert(model);
|
|
72
76
|
}
|
|
73
77
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
SearchIdentifier,
|
|
3
|
-
SearchMutation,
|
|
4
2
|
SearchProvider,
|
|
5
|
-
|
|
3
|
+
SearchQueryByTerm,
|
|
6
4
|
SearchResult,
|
|
7
5
|
SearchResultFacet,
|
|
8
6
|
SearchResultProduct,
|
|
9
7
|
Session,
|
|
8
|
+
Cache as ReactinaryCache,
|
|
10
9
|
} from '@reactionary/core';
|
|
11
10
|
import z from 'zod';
|
|
12
11
|
import { FakeConfiguration } from '../schema/configuration.schema';
|
|
@@ -14,41 +13,24 @@ import { Faker, en, base } from '@faker-js/faker';
|
|
|
14
13
|
import { jitter } from '../utilities/jitter';
|
|
15
14
|
|
|
16
15
|
export class FakeSearchProvider<
|
|
17
|
-
T extends SearchResult = SearchResult
|
|
18
|
-
|
|
19
|
-
M extends SearchMutation = SearchMutation
|
|
20
|
-
> extends SearchProvider<T, Q, M> {
|
|
16
|
+
T extends SearchResult = SearchResult
|
|
17
|
+
> extends SearchProvider<T> {
|
|
21
18
|
protected config: FakeConfiguration;
|
|
22
19
|
|
|
23
|
-
constructor(config: FakeConfiguration, schema: z.ZodType<T>,
|
|
24
|
-
super(schema,
|
|
20
|
+
constructor(config: FakeConfiguration, schema: z.ZodType<T>, cache: ReactinaryCache) {
|
|
21
|
+
super(schema, cache);
|
|
25
22
|
|
|
26
23
|
this.config = config;
|
|
27
24
|
}
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const result = await this.get(query.search);
|
|
34
|
-
|
|
35
|
-
results.push(result);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return results;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected override process(mutations: M[], session: Session): Promise<T> {
|
|
42
|
-
throw new Error('Method not implemented.');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public async get(identifier: SearchIdentifier): Promise<T> {
|
|
26
|
+
public override async queryByTerm(
|
|
27
|
+
payload: SearchQueryByTerm,
|
|
28
|
+
_session: Session
|
|
29
|
+
): Promise<SearchResult> {
|
|
46
30
|
await jitter(this.config.jitter.mean, this.config.jitter.deviation);
|
|
47
31
|
|
|
48
|
-
|
|
49
|
-
}
|
|
32
|
+
const query = payload.search;
|
|
50
33
|
|
|
51
|
-
public parse(data: unknown, query: SearchIdentifier): T {
|
|
52
34
|
const querySpecificity =
|
|
53
35
|
20 - query.term.length - query.page - query.facets.length;
|
|
54
36
|
const totalProducts = 10 * querySpecificity;
|
|
@@ -77,7 +59,7 @@ export class FakeSearchProvider<
|
|
|
77
59
|
height: 300,
|
|
78
60
|
width: 300,
|
|
79
61
|
grayscale: true,
|
|
80
|
-
blur: 8
|
|
62
|
+
blur: 8,
|
|
81
63
|
}),
|
|
82
64
|
name: productGenerator.commerce.productName(),
|
|
83
65
|
slug: productGenerator.lorem.slug(),
|
|
@@ -131,10 +113,10 @@ export class FakeSearchProvider<
|
|
|
131
113
|
meta: {
|
|
132
114
|
cache: {
|
|
133
115
|
hit: false,
|
|
134
|
-
key: ''
|
|
116
|
+
key: '',
|
|
135
117
|
},
|
|
136
|
-
placeholder: false
|
|
137
|
-
}
|
|
118
|
+
placeholder: false,
|
|
119
|
+
},
|
|
138
120
|
} satisfies SearchResult;
|
|
139
121
|
|
|
140
122
|
return this.schema.parse(result);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// Mock superjson for Jest testing
|
|
2
|
+
module.exports = {
|
|
3
|
+
default: {
|
|
4
|
+
stringify: JSON.stringify,
|
|
5
|
+
parse: JSON.parse,
|
|
6
|
+
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
7
|
+
deserialize: (data) => data.json,
|
|
8
|
+
output: {
|
|
9
|
+
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
10
|
+
},
|
|
11
|
+
input: {
|
|
12
|
+
deserialize: (data) => data.json
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
stringify: JSON.stringify,
|
|
16
|
+
parse: JSON.parse,
|
|
17
|
+
serialize: (obj) => ({ json: obj, meta: undefined }),
|
|
18
|
+
deserialize: (data) => data.json,
|
|
19
|
+
output: {
|
|
20
|
+
serialize: (obj) => ({ json: obj, meta: undefined })
|
|
21
|
+
},
|
|
22
|
+
input: {
|
|
23
|
+
deserialize: (data) => data.json
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
displayName: 'trpc',
|
|
3
|
+
preset: '../jest.preset.js',
|
|
4
|
+
testEnvironment: 'node',
|
|
5
|
+
testTimeout: 15000,
|
|
6
|
+
transform: {
|
|
7
|
+
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
|
|
8
|
+
},
|
|
9
|
+
moduleFileExtensions: ['ts', 'js', 'html'],
|
|
10
|
+
moduleNameMapper: {
|
|
11
|
+
'^superjson$': '<rootDir>/__mocks__/superjson.js',
|
|
12
|
+
},
|
|
13
|
+
coverageDirectory: '../coverage/trpc',
|
|
14
|
+
};
|