@daffodil/product 0.94.1-rc.0 → 0.95.0
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/fesm2022/daffodil-product-driver-in-memory.mjs +200 -227
- package/fesm2022/daffodil-product-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver-magento-2.4.7-testing.mjs +444 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7-testing.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7.mjs +704 -0
- package/fesm2022/daffodil-product-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-auto-testing.mjs +7 -0
- package/fesm2022/daffodil-product-driver-magento-auto-testing.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-product-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-product-driver-shopify.mjs +99 -127
- package/fesm2022/daffodil-product-driver-shopify.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver-testing.mjs +117 -87
- package/fesm2022/daffodil-product-driver-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product-driver.mjs +22 -45
- package/fesm2022/daffodil-product-driver.mjs.map +1 -1
- package/fesm2022/daffodil-product-routing.mjs +347 -285
- package/fesm2022/daffodil-product-routing.mjs.map +1 -1
- package/fesm2022/daffodil-product-state-testing.mjs +189 -106
- package/fesm2022/daffodil-product-state-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product-state.mjs +566 -659
- package/fesm2022/daffodil-product-state.mjs.map +1 -1
- package/fesm2022/daffodil-product-testing.mjs +316 -276
- package/fesm2022/daffodil-product-testing.mjs.map +1 -1
- package/fesm2022/daffodil-product.mjs +8 -29
- package/fesm2022/daffodil-product.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-product-driver-in-memory.d.ts +65 -75
- package/types/daffodil-product-driver-magento-2.4.7-testing.d.ts +105 -0
- package/types/daffodil-product-driver-magento-2.4.7.d.ts +337 -0
- package/types/daffodil-product-driver-magento-auto-testing.d.ts +1 -0
- package/types/daffodil-product-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-product-driver-shopify.d.ts +31 -43
- package/types/daffodil-product-driver-testing.d.ts +28 -26
- package/types/daffodil-product-driver.d.ts +50 -61
- package/types/daffodil-product-routing.d.ts +101 -110
- package/types/daffodil-product-state-testing.d.ts +45 -43
- package/types/daffodil-product-state.d.ts +347 -375
- package/types/daffodil-product-testing.d.ts +82 -89
- package/types/daffodil-product.d.ts +93 -102
- package/fesm2022/daffodil-product-driver-magento-testing.mjs +0 -275
- package/fesm2022/daffodil-product-driver-magento-testing.mjs.map +0 -1
- package/fesm2022/daffodil-product-driver-magento.mjs +0 -855
- package/fesm2022/daffodil-product-driver-magento.mjs.map +0 -1
- package/types/daffodil-product-driver-magento-testing.d.ts +0 -114
- package/types/daffodil-product-driver-magento.d.ts +0 -396
|
@@ -1,233 +1,206 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as i0 from
|
|
3
|
-
import {
|
|
4
|
-
import * as i2 from
|
|
5
|
-
import {
|
|
6
|
-
import { daffUriTruncateLeadingSlash } from
|
|
7
|
-
import { DaffProductExtensionFactory,
|
|
8
|
-
import * as i1 from
|
|
9
|
-
import { map } from
|
|
10
|
-
import { DaffInMemoryDriverBase, provideDaffInMemoryBackends, provideDaffInMemoryRoutableObjects } from
|
|
11
|
-
import { createMultiInjectionToken, createSingleInjectionToken } from
|
|
12
|
-
import { provideDaffProductDriver } from
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
import { CommonModule, isPlatformBrowser } from "@angular/common";
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
import { Inject, Injectable, NgModule, PLATFORM_ID, TransferState, inject, makeStateKey } from "@angular/core";
|
|
4
|
+
import * as i2 from "angular-in-memory-web-api";
|
|
5
|
+
import { InMemoryBackendConfig, STATUS } from "angular-in-memory-web-api";
|
|
6
|
+
import { daffUriTruncateLeadingSlash } from "@daffodil/core/routing";
|
|
7
|
+
import { DaffProductExtensionFactory, provideDaffProductTesting } from "@daffodil/product/testing";
|
|
8
|
+
import * as i1 from "@angular/common/http";
|
|
9
|
+
import { map } from "rxjs/operators";
|
|
10
|
+
import { DaffInMemoryDriverBase, provideDaffInMemoryBackends, provideDaffInMemoryRoutableObjects } from "@daffodil/driver/in-memory";
|
|
11
|
+
import { createMultiInjectionToken, createSingleInjectionToken } from "@daffodil/core";
|
|
12
|
+
import { provideDaffProductDriver } from "@daffodil/product/driver";
|
|
13
|
+
const DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME = "products";
|
|
14
|
+
const TRANSFER_STATE_KEY = makeStateKey("DAFF_PRODUCTS_INMEMORY_DATA");
|
|
15
|
+
var DaffInMemoryBackendProductService = class DaffInMemoryBackendProductService {
|
|
16
|
+
get products() {
|
|
17
|
+
return this._products;
|
|
18
|
+
}
|
|
19
|
+
constructor() {
|
|
20
|
+
this.collectionName = DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME;
|
|
21
|
+
this._products = [];
|
|
22
|
+
const transferState = inject(TransferState);
|
|
23
|
+
const platform = inject(PLATFORM_ID);
|
|
24
|
+
const productFactory = inject(DaffProductExtensionFactory);
|
|
25
|
+
if (isPlatformBrowser(platform)) this._products = transferState.get(TRANSFER_STATE_KEY, productFactory.createMany(35));
|
|
26
|
+
else {
|
|
27
|
+
this._products = productFactory.createMany(35);
|
|
28
|
+
transferState.set(TRANSFER_STATE_KEY, this._products);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
parseRequestUrl(url, utils) {
|
|
32
|
+
return utils.parseRequestUrl(url);
|
|
33
|
+
}
|
|
34
|
+
createDb() {
|
|
35
|
+
return { products: this._products };
|
|
36
|
+
}
|
|
37
|
+
get(reqInfo) {
|
|
38
|
+
if (reqInfo.id?.includes(".html")) {
|
|
39
|
+
const product = this._products.find((p) => daffUriTruncateLeadingSlash(p.url) === reqInfo.id);
|
|
40
|
+
if (!product) return;
|
|
41
|
+
return reqInfo.utils.createResponse$(() => ({
|
|
42
|
+
body: product,
|
|
43
|
+
status: STATUS.OK
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
static {
|
|
48
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
49
|
+
minVersion: "12.0.0",
|
|
50
|
+
version: "22.2.4",
|
|
51
|
+
ngImport: i0,
|
|
52
|
+
type: DaffInMemoryBackendProductService,
|
|
53
|
+
deps: [],
|
|
54
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
static {
|
|
58
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
59
|
+
minVersion: "12.0.0",
|
|
60
|
+
version: "22.2.4",
|
|
61
|
+
ngImport: i0,
|
|
62
|
+
type: DaffInMemoryBackendProductService,
|
|
63
|
+
providedIn: "root"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
68
|
+
minVersion: "12.0.0",
|
|
69
|
+
version: "22.2.4",
|
|
70
|
+
ngImport: i0,
|
|
71
|
+
type: DaffInMemoryBackendProductService,
|
|
72
|
+
decorators: [{
|
|
73
|
+
type: Injectable,
|
|
74
|
+
args: [{ providedIn: "root" }]
|
|
75
|
+
}],
|
|
76
|
+
ctorParameters: () => []
|
|
77
|
+
});
|
|
78
|
+
const { token: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, provider: provideDaffProductInMemoryExtraProductResponseTransforms } = createMultiInjectionToken("DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS");
|
|
79
|
+
const { token: DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM, provider: provideDaffProductInMemoryProductResponseTransform } = createSingleInjectionToken("DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM", { factory: () => {
|
|
80
|
+
const transforms = inject(DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS);
|
|
81
|
+
return (product) => transforms.reduce((daffProductResponse, transform) => transform(daffProductResponse, product), {
|
|
82
|
+
id: product.id,
|
|
83
|
+
products: [product]
|
|
84
|
+
});
|
|
85
|
+
} });
|
|
86
|
+
var DaffInMemoryProductService = class DaffInMemoryProductService extends DaffInMemoryDriverBase {
|
|
87
|
+
constructor(http, config, transform) {
|
|
88
|
+
super(config, DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME);
|
|
89
|
+
this.http = http;
|
|
90
|
+
this.transform = transform;
|
|
91
|
+
}
|
|
92
|
+
getAll() {
|
|
93
|
+
return this.http.get(this.url);
|
|
94
|
+
}
|
|
95
|
+
get(productId) {
|
|
96
|
+
return this.http.get(`${this.url}/${productId}`).pipe(map(this.transform));
|
|
97
|
+
}
|
|
98
|
+
getByUrl(url) {
|
|
99
|
+
return this.http.get(`${this.url}/${daffUriTruncateLeadingSlash(url)}`).pipe(map(this.transform));
|
|
100
|
+
}
|
|
101
|
+
static {
|
|
102
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
103
|
+
minVersion: "12.0.0",
|
|
104
|
+
version: "22.2.4",
|
|
105
|
+
ngImport: i0,
|
|
106
|
+
type: DaffInMemoryProductService,
|
|
107
|
+
deps: [
|
|
108
|
+
{ token: i1.HttpClient },
|
|
109
|
+
{ token: InMemoryBackendConfig },
|
|
110
|
+
{ token: DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM }
|
|
111
|
+
],
|
|
112
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
static {
|
|
116
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
117
|
+
minVersion: "12.0.0",
|
|
118
|
+
version: "22.2.4",
|
|
119
|
+
ngImport: i0,
|
|
120
|
+
type: DaffInMemoryProductService
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
125
|
+
minVersion: "12.0.0",
|
|
126
|
+
version: "22.2.4",
|
|
127
|
+
ngImport: i0,
|
|
128
|
+
type: DaffInMemoryProductService,
|
|
129
|
+
decorators: [{ type: Injectable }],
|
|
130
|
+
ctorParameters: () => [
|
|
131
|
+
{ type: i1.HttpClient },
|
|
132
|
+
{
|
|
133
|
+
type: i2.InMemoryBackendConfigArgs,
|
|
134
|
+
decorators: [{
|
|
135
|
+
type: Inject,
|
|
136
|
+
args: [InMemoryBackendConfig]
|
|
137
|
+
}]
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: void 0,
|
|
141
|
+
decorators: [{
|
|
142
|
+
type: Inject,
|
|
143
|
+
args: [DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM]
|
|
144
|
+
}]
|
|
145
|
+
}
|
|
146
|
+
]
|
|
136
147
|
});
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* The product inmemory driver to mock the product backend service.
|
|
140
|
-
*
|
|
141
|
-
* @inheritdoc
|
|
142
|
-
* @Param HttpClient
|
|
143
|
-
*/
|
|
144
|
-
class DaffInMemoryProductService extends DaffInMemoryDriverBase {
|
|
145
|
-
constructor(http, config, transform) {
|
|
146
|
-
super(config, DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME);
|
|
147
|
-
this.http = http;
|
|
148
|
-
this.transform = transform;
|
|
149
|
-
}
|
|
150
|
-
getAll() {
|
|
151
|
-
return this.http.get(this.url);
|
|
152
|
-
}
|
|
153
|
-
get(productId) {
|
|
154
|
-
return this.http.get(`${this.url}/${productId}`).pipe(map(this.transform));
|
|
155
|
-
}
|
|
156
|
-
getByUrl(url) {
|
|
157
|
-
return this.http.get(`${this.url}/${daffUriTruncateLeadingSlash(url)}`).pipe(map(this.transform));
|
|
158
|
-
}
|
|
159
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryProductService, deps: [{ token: i1.HttpClient }, { token: InMemoryBackendConfig }, { token: DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM }], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
160
|
-
/** @nocollapse */ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryProductService }); }
|
|
161
|
-
}
|
|
162
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryProductService, decorators: [{
|
|
163
|
-
type: Injectable
|
|
164
|
-
}], ctorParameters: () => [{ type: i1.HttpClient }, { type: i2.InMemoryBackendConfigArgs, decorators: [{
|
|
165
|
-
type: Inject,
|
|
166
|
-
args: [InMemoryBackendConfig]
|
|
167
|
-
}] }, { type: undefined, decorators: [{
|
|
168
|
-
type: Inject,
|
|
169
|
-
args: [DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM]
|
|
170
|
-
}] }] });
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Module for providing the DaffInMemoryProductService driver to your application.
|
|
174
|
-
*/
|
|
175
|
-
class DaffProductInMemoryDriverModule {
|
|
176
|
-
static forRoot() {
|
|
177
|
-
return {
|
|
178
|
-
ngModule: DaffProductInMemoryDriverModule,
|
|
179
|
-
providers: [
|
|
180
|
-
DaffInMemoryProductService,
|
|
181
|
-
provideDaffProductDriver(DaffInMemoryProductService),
|
|
182
|
-
provideDaffProductExtraFactoryTypes(DaffDefaultProductFactory),
|
|
183
|
-
provideDaffInMemoryBackends(DaffInMemoryBackendProductService),
|
|
184
|
-
],
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
/** @nocollapse */ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductInMemoryDriverModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
188
|
-
/** @nocollapse */ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DaffProductInMemoryDriverModule, imports: [CommonModule,
|
|
189
|
-
DaffProductTestingModule] }); }
|
|
190
|
-
/** @nocollapse */ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductInMemoryDriverModule, imports: [CommonModule,
|
|
191
|
-
DaffProductTestingModule] }); }
|
|
192
|
-
}
|
|
193
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffProductInMemoryDriverModule, decorators: [{
|
|
194
|
-
type: NgModule,
|
|
195
|
-
args: [{
|
|
196
|
-
imports: [
|
|
197
|
-
CommonModule,
|
|
198
|
-
DaffProductTestingModule,
|
|
199
|
-
],
|
|
200
|
-
}]
|
|
201
|
-
}] });
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* A factory function that provides routable product objects for the in-memory driver.
|
|
205
|
-
*
|
|
206
|
-
* Returns a function that provides all product entities with their URL properties.
|
|
207
|
-
* Used internally by {@link provideDaffProductInMemoryDriver} with
|
|
208
|
-
* {@link provideDaffInMemoryRoutableObjects} to enable automatic URL resolution for products.
|
|
209
|
-
*
|
|
210
|
-
* @docs-private
|
|
211
|
-
*/
|
|
212
148
|
const daffProductInMemoryRoutableObjects = () => {
|
|
213
|
-
|
|
214
|
-
return service.products.map((p) => ({ url: p.url }));
|
|
149
|
+
return inject(DaffInMemoryBackendProductService).products.map((p) => ({ url: p.url }));
|
|
215
150
|
};
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Provides the Daffodil product in-memory driver and its dependencies.
|
|
219
|
-
*/
|
|
220
151
|
const provideDaffProductInMemoryDriver = () => [
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
152
|
+
provideDaffProductTesting(),
|
|
153
|
+
DaffInMemoryProductService,
|
|
154
|
+
provideDaffProductDriver(DaffInMemoryProductService),
|
|
155
|
+
provideDaffInMemoryBackends(DaffInMemoryBackendProductService),
|
|
156
|
+
provideDaffInMemoryRoutableObjects("PRODUCT", daffProductInMemoryRoutableObjects)
|
|
226
157
|
];
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
158
|
+
var DaffProductInMemoryDriverModule = class DaffProductInMemoryDriverModule {
|
|
159
|
+
static forRoot() {
|
|
160
|
+
return {
|
|
161
|
+
ngModule: DaffProductInMemoryDriverModule,
|
|
162
|
+
providers: [provideDaffProductInMemoryDriver()]
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
static {
|
|
166
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
167
|
+
minVersion: "12.0.0",
|
|
168
|
+
version: "22.2.4",
|
|
169
|
+
ngImport: i0,
|
|
170
|
+
type: DaffProductInMemoryDriverModule,
|
|
171
|
+
deps: [],
|
|
172
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
static {
|
|
176
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
177
|
+
minVersion: "14.0.0",
|
|
178
|
+
version: "22.2.4",
|
|
179
|
+
ngImport: i0,
|
|
180
|
+
type: DaffProductInMemoryDriverModule,
|
|
181
|
+
imports: [CommonModule]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
static {
|
|
185
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
186
|
+
minVersion: "12.0.0",
|
|
187
|
+
version: "22.2.4",
|
|
188
|
+
ngImport: i0,
|
|
189
|
+
type: DaffProductInMemoryDriverModule,
|
|
190
|
+
imports: [CommonModule]
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
195
|
+
minVersion: "12.0.0",
|
|
196
|
+
version: "22.2.4",
|
|
197
|
+
ngImport: i0,
|
|
198
|
+
type: DaffProductInMemoryDriverModule,
|
|
199
|
+
decorators: [{
|
|
200
|
+
type: NgModule,
|
|
201
|
+
args: [{ imports: [CommonModule] }]
|
|
202
|
+
}]
|
|
203
|
+
});
|
|
232
204
|
export { DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS, DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM, DaffInMemoryBackendProductService, DaffInMemoryProductService, DaffProductInMemoryDriverModule, provideDaffProductInMemoryDriver, provideDaffProductInMemoryExtraProductResponseTransforms };
|
|
233
|
-
|
|
205
|
+
|
|
206
|
+
//# sourceMappingURL=daffodil-product-driver-in-memory.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daffodil-product-driver-in-memory.mjs","sources":["../../../libs/product/driver/in-memory/src/collection-name.const.ts","../../../libs/product/driver/in-memory/src/backend/transfer-state-key.ts","../../../libs/product/driver/in-memory/src/backend/product.service.ts","../../../libs/product/driver/in-memory/src/injection-tokens/transforms/product-response/response-extra.token.ts","../../../libs/product/driver/in-memory/src/injection-tokens/transforms/product-response/response.token.ts","../../../libs/product/driver/in-memory/src/driver/product.service.ts","../../../libs/product/driver/in-memory/src/driver/product-driver.module.ts","../../../libs/product/driver/in-memory/src/driver/routable-objects.token.ts","../../../libs/product/driver/in-memory/src/driver/provider.ts","../../../libs/product/driver/in-memory/src/daffodil-product-driver-in-memory.ts"],"sourcesContent":["export const DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME = 'products';\n","import { makeStateKey } from '@angular/core';\n\nimport { DaffProduct } from '@daffodil/product';\n\nexport const TRANSFER_STATE_KEY = makeStateKey<DaffProduct[]>('DAFF_PRODUCTS_INMEMORY_DATA');\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n inject,\n Injectable,\n PLATFORM_ID,\n TransferState,\n} from '@angular/core';\nimport {\n InMemoryDbService,\n RequestInfoUtilities,\n ParsedRequestUrl,\n RequestInfo,\n STATUS,\n} from 'angular-in-memory-web-api';\n\nimport { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';\nimport { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';\nimport { DaffProduct } from '@daffodil/product';\nimport { DaffProductExtensionFactory } from '@daffodil/product/testing';\n\nimport { DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { TRANSFER_STATE_KEY } from './transfer-state-key';\n/**\n * An in-memory service that stubs out the backend services for getting products.\n *\n * @Param productFactory: DaffProductFactory instance\n * @Param productImageFactory: DaffProductImageFactory instance\n * @Param products: An array of Products\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryBackendProductService implements InMemoryDbService, DaffInMemorySingleRouteableBackend {\n readonly collectionName = DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME;\n\n protected _products: DaffProduct[] = [];\n\n /**\n * The collection of products in the backend.\n */\n get products(): DaffProduct[] {\n return this._products;\n };\n\n constructor(){\n const transferState = inject(TransferState);\n const platform = inject(PLATFORM_ID);\n const productFactory = inject(DaffProductExtensionFactory);\n\n if(isPlatformBrowser(platform)) {\n this._products = transferState.get(TRANSFER_STATE_KEY, productFactory.createMany(35));\n } else {\n this._products = productFactory.createMany(35);\n transferState.set(TRANSFER_STATE_KEY, this._products);\n }\n }\n\n /**\n * Automatically called as part of the InMemoryDbService to parse incoming urls to match the InMemory backend urls.\n *\n * @param url initial url\n * @param utils utility to parse url\n * @returns ParsedRequestUrl\n * @docs-private\n */\n parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {\n return utils.parseRequestUrl(url);\n }\n\n /**\n * Creates a fake database of products for the product inmemory backend service.\n *\n * @returns A fake database of an array of products\n * @docs-private\n */\n createDb(): any {\n return {\n products: this._products,\n };\n }\n\n /**\n * Returns products based on the url given.\n *\n * @param reqInfo request object\n * @returns An http response object\n */\n get(reqInfo: RequestInfo) {\n if(reqInfo.id?.includes('.html')) {\n const product = this._products.find((p) => daffUriTruncateLeadingSlash(p.url) === reqInfo.id);\n\n if(!product) {\n return undefined;\n }\n\n return reqInfo.utils.createResponse$(() => ({\n body: product,\n status: STATUS.OK,\n }));\n }\n return undefined;\n }\n}\n","import { createMultiInjectionToken } from '@daffodil/core';\n\nimport { DaffInMemoryProductResponseExtraTransform } from '../../../interfaces/public_api';\n\nexport const {\n /**\n * A multi-provider injection token for providing extra transform logic in the Product In-Memory driver.\n * It is run after the standard transforms and passed both the current transformed Daffodil response and the In-Memory product response.\n */\n token: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS,\n\n /**\n * Provides extra product transforms for the In-Memory product driver.\n *\n * See {@link DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS}.\n *\n * @example\n * ```ts\n * providers: [\n * ...provideDaffProductInMemoryExtraProductResponseTransforms(\n * myExtraProductTransform\n * )\n * ]\n * ```\n */\n provider: provideDaffProductInMemoryExtraProductResponseTransforms,\n} = createMultiInjectionToken<DaffInMemoryProductResponseExtraTransform>('DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS');\n","import { inject } from '@angular/core';\n\nimport { createSingleInjectionToken } from '@daffodil/core';\nimport { DaffProduct } from '@daffodil/product';\n\nimport { DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS } from './response-extra.token';\nimport { DaffInMemoryProductResponseTransform } from '../../../interfaces/public_api';\n\nexport const {\n /**\n * An internal token to combine the In-Memory response transform with the injected transforms.\n */\n token: DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM,\n /**\n * Provider function for {@link DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM}.\n */\n provider: provideDaffProductInMemoryProductResponseTransform,\n} = createSingleInjectionToken<DaffInMemoryProductResponseTransform>(\n 'DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM',\n {\n factory: () => {\n const transforms = inject(DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS);\n return (product: DaffProduct) =>\n transforms.reduce(\n (daffProductResponse, transform) => transform(daffProductResponse, product),\n {\n id: product.id,\n products: [product],\n },\n );\n },\n },\n);\n","import { HttpClient } from '@angular/common/http';\nimport {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n InMemoryBackendConfig,\n InMemoryBackendConfigArgs,\n} from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nimport { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\nimport { DaffProduct } from '@daffodil/product';\nimport {\n DaffProductDriverResponse,\n DaffProductServiceInterface,\n} from '@daffodil/product/driver';\n\nimport { DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM } from '../injection-tokens/public_api';\nimport { DaffInMemoryProductResponseTransform } from '../interfaces/public_api';\n\n/**\n * The product inmemory driver to mock the product backend service.\n *\n * @inheritdoc\n * @Param HttpClient\n */\n@Injectable()\nexport class DaffInMemoryProductService extends DaffInMemoryDriverBase implements DaffProductServiceInterface {\n constructor(\n private http: HttpClient,\n @Inject(InMemoryBackendConfig) config: InMemoryBackendConfigArgs,\n @Inject(DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM) private transform: DaffInMemoryProductResponseTransform,\n ) {\n super(config, DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME);\n }\n\n getAll(): Observable<DaffProduct[]> {\n return this.http.get<DaffProduct[]>(this.url);\n }\n\n get(productId: DaffProduct['id']): Observable<DaffProductDriverResponse> {\n return this.http.get<DaffProduct>(`${this.url}/${productId}`).pipe(\n map(this.transform),\n );\n }\n\n getByUrl(url: DaffProduct['url']): Observable<DaffProductDriverResponse> {\n return this.http.get<DaffProduct>(`${this.url}/${daffUriTruncateLeadingSlash(url)}`).pipe(\n map(this.transform),\n );\n }\n}\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { provideDaffInMemoryBackends } from '@daffodil/driver/in-memory';\nimport { provideDaffProductDriver } from '@daffodil/product/driver';\nimport {\n DaffDefaultProductFactory,\n DaffProductTestingModule,\n provideDaffProductExtraFactoryTypes,\n} from '@daffodil/product/testing';\n\nimport { DaffInMemoryProductService } from './product.service';\nimport { DaffInMemoryBackendProductService } from '../backend/product.service';\n\n/**\n * Module for providing the DaffInMemoryProductService driver to your application.\n */\n@NgModule({\n imports: [\n CommonModule,\n DaffProductTestingModule,\n ],\n})\nexport class DaffProductInMemoryDriverModule {\n static forRoot(): ModuleWithProviders<DaffProductInMemoryDriverModule> {\n return {\n ngModule: DaffProductInMemoryDriverModule,\n providers: [\n DaffInMemoryProductService,\n provideDaffProductDriver(DaffInMemoryProductService),\n provideDaffProductExtraFactoryTypes(DaffDefaultProductFactory),\n provideDaffInMemoryBackends(DaffInMemoryBackendProductService),\n ],\n };\n }\n}\n","import { inject } from '@angular/core';\n\n\nimport { DaffInMemoryBackendProductService } from '../backend/product.service';\n\n/**\n * A factory function that provides routable product objects for the in-memory driver.\n *\n * Returns a function that provides all product entities with their URL properties.\n * Used internally by {@link provideDaffProductInMemoryDriver} with\n * {@link provideDaffInMemoryRoutableObjects} to enable automatic URL resolution for products.\n *\n * @docs-private\n */\nexport const daffProductInMemoryRoutableObjects = () => {\n const service = inject(DaffInMemoryBackendProductService);\n return service.products.map((p) => ({ url: p.url }));\n};\n","import {\n EnvironmentProviders,\n Provider,\n} from '@angular/core';\n\nimport {\n provideDaffInMemoryBackends,\n provideDaffInMemoryRoutableObjects,\n} from '@daffodil/driver/in-memory';\nimport { provideDaffProductDriver } from '@daffodil/product/driver';\nimport {\n DaffDefaultProductFactory,\n provideDaffProductExtraFactoryTypes,\n} from '@daffodil/product/testing';\n\nimport {\n DaffInMemoryBackendProductService,\n DaffInMemoryProductService,\n} from '../public_api';\nimport { daffProductInMemoryRoutableObjects } from './routable-objects.token';\n\n/**\n * Provides the Daffodil product in-memory driver and its dependencies.\n */\nexport const provideDaffProductInMemoryDriver = (): Array<Provider | EnvironmentProviders> => [\n DaffInMemoryProductService,\n provideDaffProductDriver(DaffInMemoryProductService),\n provideDaffProductExtraFactoryTypes(DaffDefaultProductFactory),\n provideDaffInMemoryBackends(DaffInMemoryBackendProductService),\n provideDaffInMemoryRoutableObjects('PRODUCT', daffProductInMemoryRoutableObjects),\n];\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;;;;;;;AAAO,MAAM,sCAAsC,GAAG,UAAU;;ACIzD,MAAM,kBAAkB,GAAG,YAAY,CAAgB,6BAA6B,CAAC;;ACkB5F;;;;;;AAMG;MAIU,iCAAiC,CAAA;AAK5C;;AAEG;AACH,IAAA,IAAI,QAAQ,GAAA;QACV,OAAO,IAAI,CAAC,SAAS;IACvB;;AAEA,IAAA,WAAA,GAAA;QAXS,IAAA,CAAA,cAAc,GAAG,sCAAsC;QAEtD,IAAA,CAAA,SAAS,GAAkB,EAAE;AAUrC,QAAA,MAAM,aAAa,GAAG,MAAM,CAAC,aAA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-memory.mjs","names":[],"sources":["../../../libs/product/driver/in-memory/src/collection-name.const.ts","../../../libs/product/driver/in-memory/src/backend/transfer-state-key.ts","../../../libs/product/driver/in-memory/src/backend/product.service.ts","../../../libs/product/driver/in-memory/src/injection-tokens/transforms/product-response/response-extra.token.ts","../../../libs/product/driver/in-memory/src/injection-tokens/transforms/product-response/response.token.ts","../../../libs/product/driver/in-memory/src/driver/product.service.ts","../../../libs/product/driver/in-memory/src/driver/routable-objects.token.ts","../../../libs/product/driver/in-memory/src/driver/provider.ts","../../../libs/product/driver/in-memory/src/driver/product-driver.module.ts"],"sourcesContent":["export const DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME = 'products';\n","import { makeStateKey } from '@angular/core';\n\nimport { DaffProduct } from '@daffodil/product';\n\nexport const TRANSFER_STATE_KEY = makeStateKey<DaffProduct[]>('DAFF_PRODUCTS_INMEMORY_DATA');\n","import { isPlatformBrowser } from '@angular/common';\nimport {\n inject,\n Injectable,\n PLATFORM_ID,\n TransferState,\n} from '@angular/core';\nimport {\n InMemoryDbService,\n RequestInfoUtilities,\n ParsedRequestUrl,\n RequestInfo,\n STATUS,\n} from 'angular-in-memory-web-api';\n\nimport { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';\nimport { DaffInMemorySingleRouteableBackend } from '@daffodil/driver/in-memory';\nimport { DaffProduct } from '@daffodil/product';\nimport { DaffProductExtensionFactory } from '@daffodil/product/testing';\n\nimport { DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { TRANSFER_STATE_KEY } from './transfer-state-key';\n/**\n * An in-memory service that stubs out the backend services for getting products.\n *\n * @Param productFactory: DaffProductFactory instance\n * @Param productImageFactory: DaffProductImageFactory instance\n * @Param products: An array of Products\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryBackendProductService implements InMemoryDbService, DaffInMemorySingleRouteableBackend {\n readonly collectionName = DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME;\n\n protected _products: DaffProduct[] = [];\n\n /**\n * The collection of products in the backend.\n */\n get products(): DaffProduct[] {\n return this._products;\n };\n\n constructor(){\n const transferState = inject(TransferState);\n const platform = inject(PLATFORM_ID);\n const productFactory = inject(DaffProductExtensionFactory);\n\n if(isPlatformBrowser(platform)) {\n this._products = transferState.get(TRANSFER_STATE_KEY, productFactory.createMany(35));\n } else {\n this._products = productFactory.createMany(35);\n transferState.set(TRANSFER_STATE_KEY, this._products);\n }\n }\n\n /**\n * Automatically called as part of the InMemoryDbService to parse incoming urls to match the InMemory backend urls.\n *\n * @param url initial url\n * @param utils utility to parse url\n * @returns ParsedRequestUrl\n * @docs-private\n */\n parseRequestUrl(url: string, utils: RequestInfoUtilities): ParsedRequestUrl {\n return utils.parseRequestUrl(url);\n }\n\n /**\n * Creates a fake database of products for the product inmemory backend service.\n *\n * @returns A fake database of an array of products\n * @docs-private\n */\n createDb(): any {\n return {\n products: this._products,\n };\n }\n\n /**\n * Returns products based on the url given.\n *\n * @param reqInfo request object\n * @returns An http response object\n */\n get(reqInfo: RequestInfo) {\n if(reqInfo.id?.includes('.html')) {\n const product = this._products.find((p) => daffUriTruncateLeadingSlash(p.url) === reqInfo.id);\n\n if(!product) {\n return undefined;\n }\n\n return reqInfo.utils.createResponse$(() => ({\n body: product,\n status: STATUS.OK,\n }));\n }\n return undefined;\n }\n}\n","import { createMultiInjectionToken } from '@daffodil/core';\n\nimport { DaffInMemoryProductResponseExtraTransform } from '../../../interfaces/public_api';\n\nexport const {\n /**\n * A multi-provider injection token for providing extra transform logic in the Product In-Memory driver.\n * It is run after the standard transforms and passed both the current transformed Daffodil response and the In-Memory product response.\n */\n token: DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS,\n\n /**\n * Provides extra product transforms for the In-Memory product driver.\n *\n * See {@link DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS}.\n *\n * @example\n * ```ts\n * providers: [\n * ...provideDaffProductInMemoryExtraProductResponseTransforms(\n * myExtraProductTransform\n * )\n * ]\n * ```\n */\n provider: provideDaffProductInMemoryExtraProductResponseTransforms,\n} = createMultiInjectionToken<DaffInMemoryProductResponseExtraTransform>('DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS');\n","import { inject } from '@angular/core';\n\nimport { createSingleInjectionToken } from '@daffodil/core';\nimport { DaffProduct } from '@daffodil/product';\n\nimport { DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS } from './response-extra.token';\nimport { DaffInMemoryProductResponseTransform } from '../../../interfaces/public_api';\n\nexport const {\n /**\n * An internal token to combine the In-Memory response transform with the injected transforms.\n */\n token: DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM,\n /**\n * Provider function for {@link DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM}.\n */\n provider: provideDaffProductInMemoryProductResponseTransform,\n} = createSingleInjectionToken<DaffInMemoryProductResponseTransform>(\n 'DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM',\n {\n factory: () => {\n const transforms = inject(DAFF_PRODUCT_IN_MEMORY_EXTRA_PRODUCT_RESPONSE_TRANSFORMS);\n return (product: DaffProduct) =>\n transforms.reduce(\n (daffProductResponse, transform) => transform(daffProductResponse, product),\n {\n id: product.id,\n products: [product],\n },\n );\n },\n },\n);\n","import { HttpClient } from '@angular/common/http';\nimport {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n InMemoryBackendConfig,\n InMemoryBackendConfigArgs,\n} from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\nimport { map } from 'rxjs/operators';\n\nimport { daffUriTruncateLeadingSlash } from '@daffodil/core/routing';\nimport { DaffInMemoryDriverBase } from '@daffodil/driver/in-memory';\nimport { DaffProduct } from '@daffodil/product';\nimport {\n DaffProductDriverResponse,\n DaffProductServiceInterface,\n} from '@daffodil/product/driver';\n\nimport { DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME } from '../collection-name.const';\nimport { DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM } from '../injection-tokens/public_api';\nimport { DaffInMemoryProductResponseTransform } from '../interfaces/public_api';\n\n/**\n * The product inmemory driver to mock the product backend service.\n *\n * @inheritdoc\n * @Param HttpClient\n */\n@Injectable()\nexport class DaffInMemoryProductService extends DaffInMemoryDriverBase implements DaffProductServiceInterface {\n constructor(\n private http: HttpClient,\n @Inject(InMemoryBackendConfig) config: InMemoryBackendConfigArgs,\n @Inject(DAFF_PRODUCT_IN_MEMORY_PRODUCT_RESPONSE_TRANSFORM) private transform: DaffInMemoryProductResponseTransform,\n ) {\n super(config, DAFF_PRODUCT_IN_MEMORY_COLLECTION_NAME);\n }\n\n getAll(): Observable<DaffProduct[]> {\n return this.http.get<DaffProduct[]>(this.url);\n }\n\n get(productId: DaffProduct['id']): Observable<DaffProductDriverResponse> {\n return this.http.get<DaffProduct>(`${this.url}/${productId}`).pipe(\n map(this.transform),\n );\n }\n\n getByUrl(url: DaffProduct['url']): Observable<DaffProductDriverResponse> {\n return this.http.get<DaffProduct>(`${this.url}/${daffUriTruncateLeadingSlash(url)}`).pipe(\n map(this.transform),\n );\n }\n}\n","import { inject } from '@angular/core';\n\n\nimport { DaffInMemoryBackendProductService } from '../backend/product.service';\n\n/**\n * A factory function that provides routable product objects for the in-memory driver.\n *\n * Returns a function that provides all product entities with their URL properties.\n * Used internally by {@link provideDaffProductInMemoryDriver} with\n * {@link provideDaffInMemoryRoutableObjects} to enable automatic URL resolution for products.\n *\n * @docs-private\n */\nexport const daffProductInMemoryRoutableObjects = () => {\n const service = inject(DaffInMemoryBackendProductService);\n return service.products.map((p) => ({ url: p.url }));\n};\n","import {\n EnvironmentProviders,\n Provider,\n} from '@angular/core';\n\nimport {\n provideDaffInMemoryBackends,\n provideDaffInMemoryRoutableObjects,\n} from '@daffodil/driver/in-memory';\nimport { provideDaffProductDriver } from '@daffodil/product/driver';\nimport { provideDaffProductTesting } from '@daffodil/product/testing';\n\nimport { DaffInMemoryProductService } from './product.service';\nimport { daffProductInMemoryRoutableObjects } from './routable-objects.token';\nimport { DaffInMemoryBackendProductService } from '../backend/product.service';\n\n/**\n * Provides the Daffodil product in-memory driver and its dependencies.\n * Includes {@link provideDaffProductTesting}.\n */\nexport const provideDaffProductInMemoryDriver = (): Array<Provider | EnvironmentProviders> => [\n provideDaffProductTesting(),\n DaffInMemoryProductService,\n provideDaffProductDriver(DaffInMemoryProductService),\n provideDaffInMemoryBackends(DaffInMemoryBackendProductService),\n provideDaffInMemoryRoutableObjects('PRODUCT', daffProductInMemoryRoutableObjects),\n];\n","import { CommonModule } from '@angular/common';\nimport {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport { provideDaffProductInMemoryDriver } from './provider';\n\n/**\n * Module for providing the DaffInMemoryProductService driver to your application.\n *\n * @deprecated in favor of {@link provideDaffProductInMemoryDriver} Deprecated in version 0.95.0. Will be removed in version 0.98.0.\n */\n@NgModule({\n imports: [\n CommonModule,\n ],\n})\nexport class DaffProductInMemoryDriverModule {\n static forRoot(): ModuleWithProviders<DaffProductInMemoryDriverModule> {\n return {\n ngModule: DaffProductInMemoryDriverModule,\n providers: [\n provideDaffProductInMemoryDriver(),\n ],\n };\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,MAAa,yCAAyC;ACItD,MAAa,qBAAqB,aAA4B,6BAA6B;AC4B3F,IAAa,oCAAb,MAAa,kCAAiC;CAQ5C,IAAI,WAAQ;EACV,OAAO,KAAK;CACd;CAEA,cAAA;EAXS,KAAA,iBAAiB;EAEhB,KAAA,YAA2B,CAAA;EAUnC,MAAM,gBAAgB,OAAO,aAAa;EAC1C,MAAM,WAAW,OAAO,WAAW;EACnC,MAAM,iBAAiB,OAAO,2BAA2B;EAEzD,IAAG,kBAAkB,QAAQ,GAC3B,KAAK,YAAY,cAAc,IAAI,oBAAoB,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