@reactionary/source 0.0.31 → 0.0.33
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 +3 -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 +3 -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,73 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChangeDetectionStrategy,
|
|
3
|
-
Component,
|
|
4
|
-
inject,
|
|
5
|
-
signal,
|
|
6
|
-
ViewEncapsulation,
|
|
7
|
-
} from '@angular/core';
|
|
8
|
-
import { CommonModule } from '@angular/common';
|
|
9
|
-
import { TRPC } from '../services/trpc.client';
|
|
10
|
-
import { Cart } from '@reactionary/core';
|
|
11
|
-
|
|
12
|
-
@Component({
|
|
13
|
-
selector: 'app-cart',
|
|
14
|
-
imports: [CommonModule],
|
|
15
|
-
templateUrl: './cart.component.html',
|
|
16
|
-
styleUrl: './cart.component.scss',
|
|
17
|
-
encapsulation: ViewEncapsulation.ShadowDom,
|
|
18
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
-
})
|
|
20
|
-
export class CartComponent {
|
|
21
|
-
protected trpc = inject(TRPC);
|
|
22
|
-
protected cart = signal<Cart | undefined>(undefined);
|
|
23
|
-
|
|
24
|
-
protected async add() {
|
|
25
|
-
const c = await this.trpc.client.cartMutation.mutate([
|
|
26
|
-
{
|
|
27
|
-
mutation: 'add',
|
|
28
|
-
cart: {
|
|
29
|
-
key: this.cart()?.identifier.key || '',
|
|
30
|
-
},
|
|
31
|
-
product: {
|
|
32
|
-
key: 'ad153f54-6ae9-4800-8e5e-b40a07eb87b4',
|
|
33
|
-
},
|
|
34
|
-
quantity: 2,
|
|
35
|
-
},
|
|
36
|
-
]);
|
|
37
|
-
|
|
38
|
-
this.cart.set(c);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
protected async adjust() {
|
|
42
|
-
const existing = this.cart();
|
|
43
|
-
|
|
44
|
-
if (existing) {
|
|
45
|
-
const c = await this.trpc.client.cartMutation.mutate([
|
|
46
|
-
{
|
|
47
|
-
mutation: 'adjustQuantity',
|
|
48
|
-
cart: existing.identifier,
|
|
49
|
-
item: existing.items[0].identifier,
|
|
50
|
-
quantity: existing.items[0].quantity + 1,
|
|
51
|
-
},
|
|
52
|
-
]);
|
|
53
|
-
|
|
54
|
-
this.cart.set(c);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
protected async remove() {
|
|
59
|
-
const existing = this.cart();
|
|
60
|
-
|
|
61
|
-
if (existing) {
|
|
62
|
-
const c = await this.trpc.client.cartMutation.mutate([
|
|
63
|
-
{
|
|
64
|
-
mutation: 'remove',
|
|
65
|
-
cart: existing.identifier,
|
|
66
|
-
item: existing.items[0].identifier,
|
|
67
|
-
},
|
|
68
|
-
]);
|
|
69
|
-
|
|
70
|
-
this.cart.set(c);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ChangeDetectionStrategy,
|
|
3
|
-
Component,
|
|
4
|
-
inject,
|
|
5
|
-
signal,
|
|
6
|
-
ViewEncapsulation,
|
|
7
|
-
} from '@angular/core';
|
|
8
|
-
import { CommonModule } from '@angular/common';
|
|
9
|
-
import { TRPC } from '../services/trpc.client';
|
|
10
|
-
import { Identity } from '@reactionary/core';
|
|
11
|
-
|
|
12
|
-
@Component({
|
|
13
|
-
selector: 'app-identity',
|
|
14
|
-
imports: [CommonModule],
|
|
15
|
-
templateUrl: './identity.component.html',
|
|
16
|
-
styleUrl: './identity.component.scss',
|
|
17
|
-
encapsulation: ViewEncapsulation.ShadowDom,
|
|
18
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
19
|
-
})
|
|
20
|
-
export class IdentityComponent {
|
|
21
|
-
protected trpc = inject(TRPC);
|
|
22
|
-
protected identity = signal<Identity | undefined>(undefined);
|
|
23
|
-
|
|
24
|
-
protected async login(username: string, password: string) {
|
|
25
|
-
const res = await this.trpc.client.identityMutation.mutate([
|
|
26
|
-
{
|
|
27
|
-
mutation: 'login',
|
|
28
|
-
username,
|
|
29
|
-
password
|
|
30
|
-
}
|
|
31
|
-
]);
|
|
32
|
-
|
|
33
|
-
this.identity.set(res);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
protected async logout() {
|
|
37
|
-
const res = await this.trpc.client.identityMutation.mutate([{
|
|
38
|
-
mutation: 'logout'
|
|
39
|
-
}])
|
|
40
|
-
|
|
41
|
-
this.identity.set(res);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
protected async refresh() {
|
|
45
|
-
const res = await this.trpc.client.identity.query([{ query: 'self' }])
|
|
46
|
-
|
|
47
|
-
this.identity.set(res[0]);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
@if (service.productResource.value(); as product) {
|
|
2
|
-
<section>
|
|
3
|
-
<img [src]="product.image" [alt]="product.name" />
|
|
4
|
-
</section>
|
|
5
|
-
<section>
|
|
6
|
-
<h2>{{ product.name }}</h2>
|
|
7
|
-
<h3>{{ product.description }}</h3>
|
|
8
|
-
<ol>
|
|
9
|
-
@for (attribute of product.attributes; track $index) {
|
|
10
|
-
${{ attribute | json }}
|
|
11
|
-
}
|
|
12
|
-
</ol>
|
|
13
|
-
</section>
|
|
14
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { Component, effect, inject } from '@angular/core';
|
|
2
|
-
import { CommonModule } from '@angular/common';
|
|
3
|
-
import { ProductService } from '../services/product.service';
|
|
4
|
-
import { TRPC } from '../services/trpc.client';
|
|
5
|
-
|
|
6
|
-
@Component({
|
|
7
|
-
selector: 'app-product',
|
|
8
|
-
imports: [CommonModule],
|
|
9
|
-
templateUrl: './product.component.html',
|
|
10
|
-
styleUrl: './product.component.scss',
|
|
11
|
-
})
|
|
12
|
-
export class ProductComponent {
|
|
13
|
-
protected service = inject(ProductService);
|
|
14
|
-
protected trpc = inject(TRPC);
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
effect(async () => {
|
|
18
|
-
const product = this.service.productResource.value();
|
|
19
|
-
|
|
20
|
-
console.log('product: ', product);
|
|
21
|
-
|
|
22
|
-
if (product && product.skus.length > 0) {
|
|
23
|
-
const inventory = await this.trpc.client.inventory.query([{
|
|
24
|
-
query: 'sku',
|
|
25
|
-
sku: product.skus[0].identifier.key,
|
|
26
|
-
}]);
|
|
27
|
-
console.log('inventory: ', inventory);
|
|
28
|
-
|
|
29
|
-
const prices = await this.trpc.client.price.query([
|
|
30
|
-
{ sku: product.skus[0].identifier, query: 'sku' },
|
|
31
|
-
]);
|
|
32
|
-
console.log('price: ', prices);
|
|
33
|
-
|
|
34
|
-
const pricesWithUnknownSku = await this.trpc.client.price.query([
|
|
35
|
-
{ sku: product.skus[0].identifier, query: 'sku' },
|
|
36
|
-
{ sku: { key: '123456' }, query: 'sku' },
|
|
37
|
-
]);
|
|
38
|
-
console.log('pricesWithUnknownSku: ', pricesWithUnknownSku);
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
<aside>
|
|
2
|
-
@for (facet of service.search()?.facets; track $index) {
|
|
3
|
-
<details [open]="true">
|
|
4
|
-
<summary>{{ facet.name }}</summary>
|
|
5
|
-
|
|
6
|
-
<div class="content">
|
|
7
|
-
@for (value of facet.values; track $index) {
|
|
8
|
-
<label>
|
|
9
|
-
<span>{{ value.name }}</span>
|
|
10
|
-
<span>{{ value.count }}</span>
|
|
11
|
-
<input type="checkbox" (click)="toggleFacet(value.identifier)" [checked]="value.active"/>
|
|
12
|
-
</label>
|
|
13
|
-
}
|
|
14
|
-
</div>
|
|
15
|
-
</details>
|
|
16
|
-
}
|
|
17
|
-
</aside>
|
|
18
|
-
<section>
|
|
19
|
-
@for (product of service.search()?.products; track $index) {
|
|
20
|
-
<a [routerLink]="['/', 'product', product.slug]">
|
|
21
|
-
<article>
|
|
22
|
-
<img [src]="product.image.replace('w_200', 'w_200,h_200,')" [alt]="product.name" />
|
|
23
|
-
<h3>{{ product.name }}</h3>
|
|
24
|
-
</article>
|
|
25
|
-
</a>
|
|
26
|
-
}
|
|
27
|
-
</section>
|
|
28
|
-
<footer>
|
|
29
|
-
<button (click)="previousPage()" [disabled]="hasPrevious()">
|
|
30
|
-
<
|
|
31
|
-
</button>
|
|
32
|
-
<button (click)="nextPage()" [disabled]="hasNext()">
|
|
33
|
-
>
|
|
34
|
-
</button>
|
|
35
|
-
</footer>
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
display: grid;
|
|
3
|
-
gap: 0.5rem;
|
|
4
|
-
grid-template-columns: 300px 1fr;
|
|
5
|
-
color: rgb(205, 214, 244);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
details[open] {
|
|
9
|
-
summary:after {
|
|
10
|
-
content: '-';
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
details {
|
|
15
|
-
position: relative;
|
|
16
|
-
background: rgb(49, 50, 68);
|
|
17
|
-
border-radius: 0.5rem;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
summary {
|
|
21
|
-
font-weight: bold;
|
|
22
|
-
text-transform: capitalize;
|
|
23
|
-
list-style: none;
|
|
24
|
-
padding: 0.5rem;
|
|
25
|
-
|
|
26
|
-
&::-webkit-details-marker {
|
|
27
|
-
display: none;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
&::after {
|
|
31
|
-
position: absolute;
|
|
32
|
-
top: 0.5rem;
|
|
33
|
-
right: 0.5rem;
|
|
34
|
-
content: '+';
|
|
35
|
-
line-height: 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
aside {
|
|
40
|
-
display: grid;
|
|
41
|
-
grid-template-columns: 1fr;
|
|
42
|
-
grid-auto-rows: min-content;
|
|
43
|
-
gap: 0.25rem;
|
|
44
|
-
|
|
45
|
-
.content {
|
|
46
|
-
display: grid;
|
|
47
|
-
grid-template-columns: 1fr min-content min-content;
|
|
48
|
-
grid-auto-rows: min-content;
|
|
49
|
-
padding: 0.5rem;
|
|
50
|
-
gap: 0.5rem;
|
|
51
|
-
|
|
52
|
-
label {
|
|
53
|
-
grid-column: span 3;
|
|
54
|
-
display: grid;
|
|
55
|
-
grid-template-columns: subgrid;
|
|
56
|
-
align-items: center;
|
|
57
|
-
gap: 0.5rem;
|
|
58
|
-
|
|
59
|
-
input {
|
|
60
|
-
width: 1.5rem;
|
|
61
|
-
height: 1.5rem;
|
|
62
|
-
background: rgb(147, 153, 178);
|
|
63
|
-
border-radius: 0.125rem;
|
|
64
|
-
|
|
65
|
-
&:checked {
|
|
66
|
-
background: rgb(137, 220, 235);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
section {
|
|
74
|
-
justify-content: center;
|
|
75
|
-
display: grid;
|
|
76
|
-
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
|
77
|
-
grid-auto-rows: min-content;
|
|
78
|
-
gap: 0.5rem;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
article {
|
|
82
|
-
background: rgb(49, 50, 68);
|
|
83
|
-
border-radius: 0.25rem;
|
|
84
|
-
display: grid;
|
|
85
|
-
grid-template-columns: 1fr;
|
|
86
|
-
grid-template-rows: 1fr min-content;
|
|
87
|
-
gap: 1rem;
|
|
88
|
-
|
|
89
|
-
h3 {
|
|
90
|
-
line-height: 1.2;
|
|
91
|
-
font-size: 1rem;
|
|
92
|
-
text-align: center;
|
|
93
|
-
margin-bottom: 1rem;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
img {
|
|
97
|
-
object-fit: contain;
|
|
98
|
-
border-radius: inherit;
|
|
99
|
-
max-width: 100%;
|
|
100
|
-
width: 100%;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
footer {
|
|
105
|
-
grid-column: 2;
|
|
106
|
-
margin: 0.5rem;
|
|
107
|
-
gap: 0.25rem;
|
|
108
|
-
display: grid;
|
|
109
|
-
grid-template-columns: min-content min-content;
|
|
110
|
-
align-items: center;
|
|
111
|
-
justify-content: center;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
button {
|
|
115
|
-
display: grid;
|
|
116
|
-
justify-content: center;
|
|
117
|
-
align-items: center;
|
|
118
|
-
|
|
119
|
-
height: 3rem;
|
|
120
|
-
background: rgb(49, 50, 68);
|
|
121
|
-
color: rgb(205, 214, 244);
|
|
122
|
-
aspect-ratio: 1 / 1;
|
|
123
|
-
border-radius: 0.25rem;
|
|
124
|
-
|
|
125
|
-
&:disabled {
|
|
126
|
-
opacity: 0.5;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Component, computed, inject } from '@angular/core';
|
|
2
|
-
import { CommonModule } from '@angular/common';
|
|
3
|
-
import { SearchService } from '../services/search.service';
|
|
4
|
-
import { FacetValueIdentifier } from '@reactionary/core';
|
|
5
|
-
import { RouterModule } from '@angular/router';
|
|
6
|
-
import { TRPC } from '../services/trpc.client';
|
|
7
|
-
|
|
8
|
-
@Component({
|
|
9
|
-
selector: 'app-search',
|
|
10
|
-
imports: [CommonModule, RouterModule],
|
|
11
|
-
templateUrl: './search.component.html',
|
|
12
|
-
styleUrl: './search.component.scss',
|
|
13
|
-
})
|
|
14
|
-
export class SearchComponent {
|
|
15
|
-
protected service = inject(SearchService);
|
|
16
|
-
protected client = inject(TRPC);
|
|
17
|
-
|
|
18
|
-
protected hasNext = computed(() => {
|
|
19
|
-
return this.service.page() >= (this.service.search()?.pages || 0) - 1;
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
protected hasPrevious = computed(() => {
|
|
23
|
-
return !(this.service.page() > 0);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
protected previousPage() {
|
|
27
|
-
this.service.page.update((old) => old - 1);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
protected nextPage() {
|
|
31
|
-
this.service.page.update((old) => old + 1);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
protected toggleFacet(value: FacetValueIdentifier) {
|
|
35
|
-
this.service.facets.update((old) => {
|
|
36
|
-
const existingIndex = old.findIndex(
|
|
37
|
-
(x) => JSON.stringify(x) === JSON.stringify(value)
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
if (existingIndex > -1) {
|
|
41
|
-
const updated = [...old];
|
|
42
|
-
updated.splice(existingIndex, 1);
|
|
43
|
-
|
|
44
|
-
return updated;
|
|
45
|
-
} else {
|
|
46
|
-
return [...old, value];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { inject, Injectable, resource } from '@angular/core';
|
|
2
|
-
import { TRPC } from './trpc.client';
|
|
3
|
-
import { ActivationEnd, Router } from '@angular/router';
|
|
4
|
-
import { toSignal } from '@angular/core/rxjs-interop';
|
|
5
|
-
import { filter, map } from 'rxjs';
|
|
6
|
-
|
|
7
|
-
@Injectable({
|
|
8
|
-
providedIn: 'root',
|
|
9
|
-
})
|
|
10
|
-
export class ProductService {
|
|
11
|
-
protected client = inject(TRPC);
|
|
12
|
-
protected router = inject(Router);
|
|
13
|
-
protected slug = toSignal(
|
|
14
|
-
this.router.events.pipe(filter(x => x instanceof ActivationEnd), map(x => x.snapshot.params['slug'])),
|
|
15
|
-
{ initialValue: '' }
|
|
16
|
-
);
|
|
17
|
-
|
|
18
|
-
public productResource = resource({
|
|
19
|
-
request: () => ({
|
|
20
|
-
slug: this.slug(),
|
|
21
|
-
}),
|
|
22
|
-
loader: async ({ request }) => {
|
|
23
|
-
if (request.slug) {
|
|
24
|
-
const results = await this.client.client.product.query([{
|
|
25
|
-
query: 'slug',
|
|
26
|
-
slug: request.slug,
|
|
27
|
-
}]);
|
|
28
|
-
|
|
29
|
-
return results[0];
|
|
30
|
-
} else {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { inject, Injectable, linkedSignal, resource, signal } from '@angular/core';
|
|
2
|
-
import { FacetValueIdentifier, SearchResult } from '@reactionary/core';
|
|
3
|
-
import { TRPC } from './trpc.client';
|
|
4
|
-
|
|
5
|
-
@Injectable({
|
|
6
|
-
providedIn: 'root',
|
|
7
|
-
})
|
|
8
|
-
export class SearchService {
|
|
9
|
-
protected client = inject(TRPC);
|
|
10
|
-
|
|
11
|
-
public pageSize = signal(20);
|
|
12
|
-
public page = signal(0);
|
|
13
|
-
public term = signal('glass');
|
|
14
|
-
public facets = signal(new Array<FacetValueIdentifier>());
|
|
15
|
-
|
|
16
|
-
protected searchResource = resource({
|
|
17
|
-
request: () => ({
|
|
18
|
-
pageSize: this.pageSize(),
|
|
19
|
-
page: this.page(),
|
|
20
|
-
term: this.term(),
|
|
21
|
-
facets: this.facets(),
|
|
22
|
-
}),
|
|
23
|
-
loader: async ({ request }) => {
|
|
24
|
-
const result = await this.client.client.search.query([{
|
|
25
|
-
query: 'term',
|
|
26
|
-
search: {
|
|
27
|
-
...request
|
|
28
|
-
}
|
|
29
|
-
}]);
|
|
30
|
-
|
|
31
|
-
return result[0];
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
public search = linkedSignal<
|
|
36
|
-
SearchResult | undefined,
|
|
37
|
-
SearchResult | undefined
|
|
38
|
-
>({
|
|
39
|
-
source: () => this.searchResource.value(),
|
|
40
|
-
computation: (source, previous) => {
|
|
41
|
-
if (source) {
|
|
42
|
-
return source;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return previous?.value;
|
|
46
|
-
},
|
|
47
|
-
}).asReadonly();
|
|
48
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Injectable } from "@angular/core";
|
|
2
|
-
import { createTRPCClient, httpBatchLink } from "@trpc/client";
|
|
3
|
-
|
|
4
|
-
// FIXME: move the router to a buildable library, to allow importing it
|
|
5
|
-
// eslint-disable-next-line @nx/enforce-module-boundaries
|
|
6
|
-
import type { RouterType } from '../../../../trpc-node/src/router-instance';
|
|
7
|
-
import superjson from "superjson";
|
|
8
|
-
|
|
9
|
-
@Injectable({
|
|
10
|
-
providedIn: 'root',
|
|
11
|
-
})
|
|
12
|
-
export class TRPC {
|
|
13
|
-
public client = createTRPCClient<RouterType>({
|
|
14
|
-
links: [
|
|
15
|
-
httpBatchLink({
|
|
16
|
-
url: 'http://localhost:3000/trpc',
|
|
17
|
-
transformer: superjson,
|
|
18
|
-
fetch(url, options) {
|
|
19
|
-
return fetch(url, {
|
|
20
|
-
...options,
|
|
21
|
-
credentials: 'include',
|
|
22
|
-
});
|
|
23
|
-
},
|
|
24
|
-
}),
|
|
25
|
-
],
|
|
26
|
-
});
|
|
27
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8" />
|
|
5
|
-
<title>examples-angular</title>
|
|
6
|
-
<base href="/" />
|
|
7
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
8
|
-
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<app-root></app-root>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2022",
|
|
4
|
-
"esModuleInterop": true,
|
|
5
|
-
"forceConsistentCasingInFileNames": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"noImplicitOverride": true,
|
|
8
|
-
"noPropertyAccessFromIndexSignature": true,
|
|
9
|
-
"noImplicitReturns": true,
|
|
10
|
-
"noFallthroughCasesInSwitch": true
|
|
11
|
-
},
|
|
12
|
-
"files": [],
|
|
13
|
-
"include": [],
|
|
14
|
-
"references": [
|
|
15
|
-
{
|
|
16
|
-
"path": "./tsconfig.editor.json"
|
|
17
|
-
},
|
|
18
|
-
{
|
|
19
|
-
"path": "./tsconfig.app.json"
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
"path": "./tsconfig.spec.json"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"extends": "../../tsconfig.base.json",
|
|
26
|
-
"angularCompilerOptions": {
|
|
27
|
-
"enableI18nLegacyMessageIdFormat": false,
|
|
28
|
-
"strictInjectionParameters": true,
|
|
29
|
-
"strictInputAccessModifiers": true,
|
|
30
|
-
"strictTemplates": true
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { buildClient } from '@reactionary/core';
|
|
2
|
-
import { withAlgoliaCapabilities } from '@reactionary/provider-algolia';
|
|
3
|
-
|
|
4
|
-
describe('initialize algolia', () => {
|
|
5
|
-
it('should be able to search against algolia', async () => {
|
|
6
|
-
const client = buildClient([
|
|
7
|
-
withAlgoliaCapabilities(
|
|
8
|
-
{
|
|
9
|
-
apiKey: process.env['ALGOLIA_API_KEY'] || '',
|
|
10
|
-
appId: process.env['ALGOLIA_APP_ID'] || '',
|
|
11
|
-
indexName: process.env['ALGOLIA_INDEX'] || '',
|
|
12
|
-
},
|
|
13
|
-
{ product: true, search: true }
|
|
14
|
-
),
|
|
15
|
-
]);
|
|
16
|
-
|
|
17
|
-
expect(client.search).toBeDefined();
|
|
18
|
-
|
|
19
|
-
const result = await client.search.get({
|
|
20
|
-
term: 'glass',
|
|
21
|
-
page: 0,
|
|
22
|
-
pageSize: 10,
|
|
23
|
-
facets: []
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
expect(result.identifier.term).toBe('glass');
|
|
27
|
-
expect(result.products.length).toBeGreaterThan(0);
|
|
28
|
-
});
|
|
29
|
-
});
|