@daffodil/driver 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-driver-hubspot-testing.mjs +53 -38
- package/fesm2022/daffodil-driver-hubspot-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-hubspot.mjs +41 -60
- package/fesm2022/daffodil-driver-hubspot.mjs.map +1 -1
- package/fesm2022/daffodil-driver-in-memory.mjs +186 -258
- package/fesm2022/daffodil-driver-in-memory.mjs.map +1 -1
- package/fesm2022/daffodil-driver-magento-2.4.7-testing.mjs +139 -0
- package/fesm2022/daffodil-driver-magento-2.4.7-testing.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-2.4.7.mjs +543 -0
- package/fesm2022/daffodil-driver-magento-2.4.7.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-auto-testing.mjs +7 -0
- package/fesm2022/daffodil-driver-magento-auto-testing.mjs.map +1 -0
- package/fesm2022/daffodil-driver-magento-auto.mjs +7 -0
- package/fesm2022/daffodil-driver-magento-auto.mjs.map +1 -0
- package/fesm2022/daffodil-driver-shopify-testing.mjs +359 -216
- package/fesm2022/daffodil-driver-shopify-testing.mjs.map +1 -1
- package/fesm2022/daffodil-driver-shopify.mjs +1090 -2289
- package/fesm2022/daffodil-driver-shopify.mjs.map +1 -1
- package/fesm2022/daffodil-driver.mjs +55 -54
- package/fesm2022/daffodil-driver.mjs.map +1 -1
- package/package.json +1 -1
- package/types/daffodil-driver-hubspot-testing.d.ts +12 -15
- package/types/daffodil-driver-hubspot.d.ts +44 -52
- package/types/daffodil-driver-in-memory.d.ts +104 -121
- package/types/daffodil-driver-magento-2.4.7-testing.d.ts +18 -0
- package/types/daffodil-driver-magento-2.4.7.d.ts +189 -0
- package/types/daffodil-driver-magento-auto-testing.d.ts +1 -0
- package/types/daffodil-driver-magento-auto.d.ts +1 -0
- package/types/daffodil-driver-shopify-testing.d.ts +112 -121
- package/types/daffodil-driver-shopify.d.ts +6902 -6943
- package/types/daffodil-driver.d.ts +32 -42
- package/fesm2022/daffodil-driver-magento-testing.mjs +0 -79
- package/fesm2022/daffodil-driver-magento-testing.mjs.map +0 -1
- package/fesm2022/daffodil-driver-magento.mjs +0 -998
- package/fesm2022/daffodil-driver-magento.mjs.map +0 -1
- package/types/daffodil-driver-magento-testing.d.ts +0 -23
- package/types/daffodil-driver-magento.d.ts +0 -225
|
@@ -1,267 +1,195 @@
|
|
|
1
|
-
import { createServicesInjectionToken, observe
|
|
2
|
-
import {
|
|
3
|
-
import * as i0 from
|
|
4
|
-
import { Inject, Injectable,
|
|
5
|
-
import { combineLatest,
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
/**
|
|
9
|
-
* A token that holds the currently loaded in-memory backends.
|
|
10
|
-
*/
|
|
11
|
-
token: DAFF_IN_MEMORY_BACKENDS,
|
|
12
|
-
/**
|
|
13
|
-
* Provide backend classes to {@link DAFF_IN_MEMORY_BACKENDS}.
|
|
14
|
-
*/
|
|
15
|
-
provider: provideDaffInMemoryBackends, } = createServicesInjectionToken('DAFF_IN_MEMORY_BACKENDS');
|
|
16
|
-
|
|
1
|
+
import { createConfigInjectionToken, createServicesInjectionToken, observe } from "@daffodil/core";
|
|
2
|
+
import { HttpClientInMemoryWebApiModule, STATUS } from "angular-in-memory-web-api";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import { Inject, Injectable, InjectionToken, NgModule, importProvidersFrom, inject, makeEnvironmentProviders } from "@angular/core";
|
|
5
|
+
import { combineLatest, map, take } from "rxjs";
|
|
6
|
+
const { token: DAFF_IN_MEMORY_BACKENDS, provider: provideDaffInMemoryBackends } = createServicesInjectionToken("DAFF_IN_MEMORY_BACKENDS");
|
|
17
7
|
var Method;
|
|
18
|
-
(function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
8
|
+
(function(Method) {
|
|
9
|
+
Method["GET"] = "get";
|
|
10
|
+
Method["POST"] = "post";
|
|
11
|
+
Method["PUT"] = "put";
|
|
12
|
+
Method["DELETE"] = "delete";
|
|
23
13
|
})(Method || (Method = {}));
|
|
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
|
-
|
|
14
|
+
var DaffInMemoryBackendDelegate = class {
|
|
15
|
+
constructor(backends, config) {
|
|
16
|
+
this.backends = backends;
|
|
17
|
+
this.config = config;
|
|
18
|
+
}
|
|
19
|
+
delegateRequest(reqInfo, method) {
|
|
20
|
+
const backend = this.backends.find((b) => "collectionName" in b ? b.collectionName === reqInfo.collectionName : b.canHandle(reqInfo.collectionName));
|
|
21
|
+
const request = backend?.[method];
|
|
22
|
+
if (request) return request.call(backend, reqInfo);
|
|
23
|
+
if (!this.config.passThroughUnknownRequests) return reqInfo.utils.createResponse$(() => ({
|
|
24
|
+
status: STATUS.NOT_FOUND,
|
|
25
|
+
statusText: `Backend ${reqInfo.collectionName} not found or does not support the ${method} request method`
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
get(reqInfo) {
|
|
29
|
+
return this.delegateRequest(reqInfo, Method.GET);
|
|
30
|
+
}
|
|
31
|
+
post(reqInfo) {
|
|
32
|
+
return this.delegateRequest(reqInfo, Method.POST);
|
|
33
|
+
}
|
|
34
|
+
put(reqInfo) {
|
|
35
|
+
return this.delegateRequest(reqInfo, Method.PUT);
|
|
36
|
+
}
|
|
37
|
+
delete(reqInfo) {
|
|
38
|
+
return this.delegateRequest(reqInfo, Method.DELETE);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var DaffInMemoryRootBackend = class DaffInMemoryRootBackend extends DaffInMemoryBackendDelegate {
|
|
42
|
+
constructor(_backends, _config) {
|
|
43
|
+
super(_backends, _config);
|
|
44
|
+
this._backends = _backends;
|
|
45
|
+
this._config = _config;
|
|
46
|
+
}
|
|
47
|
+
createDb(reqInfo) {
|
|
48
|
+
return combineLatest(this._backends.map(observe)).pipe(take(1), map((backends) => backends.reduce((db, backend) => ({
|
|
49
|
+
...db,
|
|
50
|
+
...backend.createDb(reqInfo)
|
|
51
|
+
}), {})));
|
|
52
|
+
}
|
|
53
|
+
static {
|
|
54
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
55
|
+
minVersion: "12.0.0",
|
|
56
|
+
version: "22.2.4",
|
|
57
|
+
ngImport: i0,
|
|
58
|
+
type: DaffInMemoryRootBackend,
|
|
59
|
+
deps: [{ token: DAFF_IN_MEMORY_BACKENDS }, { token: DAFF_IN_MEMORY_DRIVER_CONFIG }],
|
|
60
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
static {
|
|
64
|
+
this.ɵprov = i0.ɵɵngDeclareInjectable({
|
|
65
|
+
minVersion: "12.0.0",
|
|
66
|
+
version: "22.2.4",
|
|
67
|
+
ngImport: i0,
|
|
68
|
+
type: DaffInMemoryRootBackend,
|
|
69
|
+
providedIn: "root"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
74
|
+
minVersion: "12.0.0",
|
|
75
|
+
version: "22.2.4",
|
|
76
|
+
ngImport: i0,
|
|
77
|
+
type: DaffInMemoryRootBackend,
|
|
78
|
+
decorators: [{
|
|
79
|
+
type: Injectable,
|
|
80
|
+
args: [{ providedIn: "root" }]
|
|
81
|
+
}],
|
|
82
|
+
ctorParameters: () => [{
|
|
83
|
+
type: Array,
|
|
84
|
+
decorators: [{
|
|
85
|
+
type: Inject,
|
|
86
|
+
args: [DAFF_IN_MEMORY_BACKENDS]
|
|
87
|
+
}]
|
|
88
|
+
}, {
|
|
89
|
+
type: void 0,
|
|
90
|
+
decorators: [{
|
|
91
|
+
type: Inject,
|
|
92
|
+
args: [DAFF_IN_MEMORY_DRIVER_CONFIG]
|
|
93
|
+
}]
|
|
94
|
+
}]
|
|
95
|
+
});
|
|
96
|
+
var DaffInMemoryDriverBase = class {
|
|
97
|
+
constructor(config, collectionName) {
|
|
98
|
+
this.config = config;
|
|
99
|
+
this.collectionName = collectionName;
|
|
100
|
+
this.url = `/${this.config.apiBase}/${this.collectionName}`;
|
|
101
|
+
}
|
|
102
|
+
};
|
|
112
103
|
const DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT = {
|
|
113
|
-
|
|
114
|
-
|
|
104
|
+
apiBase: "api",
|
|
105
|
+
passThroughUnknownRequests: false
|
|
115
106
|
};
|
|
116
|
-
|
|
117
|
-
const { token: DAFF_IN_MEMORY_DRIVER_CONFIG,
|
|
118
|
-
/**
|
|
119
|
-
* Provider function for {@link DAFF_IN_MEMORY_DRIVER_CONFIG}.
|
|
120
|
-
*/
|
|
121
|
-
provider: provideDaffInMemoryDriverConfig, } = createConfigInjectionToken(DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, 'DAFF_IN_MEMORY_DRIVER_CONFIG');
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sets up the angular in memory web API with the {@link DaffInMemoryRootBackend}.
|
|
125
|
-
*/
|
|
126
|
-
class DaffInMemoryDriverModule {
|
|
127
|
-
static forRoot(config = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT) {
|
|
128
|
-
return {
|
|
129
|
-
ngModule: DaffInMemoryDriverModule,
|
|
130
|
-
providers: [
|
|
131
|
-
importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryRootBackend, config)),
|
|
132
|
-
provideDaffInMemoryDriverConfig(config),
|
|
133
|
-
],
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryDriverModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
|
|
137
|
-
static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryDriverModule }); }
|
|
138
|
-
static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryDriverModule }); }
|
|
139
|
-
}
|
|
140
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.9", ngImport: i0, type: DaffInMemoryDriverModule, decorators: [{
|
|
141
|
-
type: NgModule
|
|
142
|
-
}] });
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Configures the Angular in-memory web API with Daffodil backend services.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```ts
|
|
149
|
-
* bootstrapApplication(AppComponent, {
|
|
150
|
-
* providers: [
|
|
151
|
-
* provideDaffInMemoryDriver(
|
|
152
|
-
* { delay: 300 },
|
|
153
|
-
* DaffProductInMemoryBackendService,
|
|
154
|
-
* DaffCartInMemoryBackendService
|
|
155
|
-
* )
|
|
156
|
-
* ]
|
|
157
|
-
* });
|
|
158
|
-
* ```
|
|
159
|
-
*/
|
|
107
|
+
const { token: DAFF_IN_MEMORY_DRIVER_CONFIG, provider: provideDaffInMemoryDriverConfig } = createConfigInjectionToken(DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, "DAFF_IN_MEMORY_DRIVER_CONFIG");
|
|
160
108
|
const provideDaffInMemoryDriver = (config = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, ...backends) => {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
109
|
+
config = {
|
|
110
|
+
...DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,
|
|
111
|
+
...config
|
|
112
|
+
};
|
|
113
|
+
return [importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryRootBackend, {
|
|
114
|
+
...config,
|
|
115
|
+
passThruUnknownUrl: config.passThroughUnknownRequests
|
|
116
|
+
})), makeEnvironmentProviders([provideDaffInMemoryDriverConfig(config), provideDaffInMemoryBackends(...backends)])];
|
|
169
117
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
118
|
+
var DaffInMemoryDriverModule = class DaffInMemoryDriverModule {
|
|
119
|
+
static forRoot(config = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT) {
|
|
120
|
+
return {
|
|
121
|
+
ngModule: DaffInMemoryDriverModule,
|
|
122
|
+
providers: [provideDaffInMemoryDriver(config)]
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
static {
|
|
126
|
+
this.ɵfac = i0.ɵɵngDeclareFactory({
|
|
127
|
+
minVersion: "12.0.0",
|
|
128
|
+
version: "22.2.4",
|
|
129
|
+
ngImport: i0,
|
|
130
|
+
type: DaffInMemoryDriverModule,
|
|
131
|
+
deps: [],
|
|
132
|
+
target: i0.ɵɵFactoryTarget.NgModule
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
static {
|
|
136
|
+
this.ɵmod = i0.ɵɵngDeclareNgModule({
|
|
137
|
+
minVersion: "14.0.0",
|
|
138
|
+
version: "22.2.4",
|
|
139
|
+
ngImport: i0,
|
|
140
|
+
type: DaffInMemoryDriverModule
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
static {
|
|
144
|
+
this.ɵinj = i0.ɵɵngDeclareInjector({
|
|
145
|
+
minVersion: "12.0.0",
|
|
146
|
+
version: "22.2.4",
|
|
147
|
+
ngImport: i0,
|
|
148
|
+
type: DaffInMemoryDriverModule
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
153
|
+
minVersion: "12.0.0",
|
|
154
|
+
version: "22.2.4",
|
|
155
|
+
ngImport: i0,
|
|
156
|
+
type: DaffInMemoryDriverModule,
|
|
157
|
+
decorators: [{ type: NgModule }]
|
|
183
158
|
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
* This token automatically collects all registered routable object resolvers and builds
|
|
188
|
-
* a Map where the key is the URL path and the value is an object containing both the URL
|
|
189
|
-
* and its associated type. This map is used by in-memory drivers to resolve URLs to their types.
|
|
190
|
-
*
|
|
191
|
-
* @docs-private
|
|
192
|
-
*/
|
|
193
|
-
const DAFF_INMEMORY_ROUTABLE_OBJECTS = new InjectionToken('DAFF_INMEMORY_ROUTABLE_OBJECTS', {
|
|
194
|
-
providedIn: 'root',
|
|
195
|
-
factory: () => {
|
|
196
|
-
const resolvers = inject(DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER, { optional: true }) || [];
|
|
197
|
-
const map = new Map();
|
|
198
|
-
if (!Array.isArray(resolvers)) {
|
|
199
|
-
throw new Error('DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER must be an array');
|
|
200
|
-
}
|
|
201
|
-
resolvers.forEach((entry) => {
|
|
202
|
-
const entities = entry.resolver();
|
|
203
|
-
entities.forEach(entity => {
|
|
204
|
-
if (map.has(entity.url)) {
|
|
205
|
-
const existing = map.get(entity.url);
|
|
206
|
-
console.warn(`[@daffodil/driver/in-memory] Duplicate entity URL detected: "${entity.url}". ` +
|
|
207
|
-
`Already registered with type "${existing?.type}", attempting to register again with type "${entry.type}". ` +
|
|
208
|
-
`The first registration will be used.`);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
map.set(entity.url, { url: entity.url, type: entry.type });
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
return map;
|
|
215
|
-
},
|
|
159
|
+
const DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER = new InjectionToken("DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER", {
|
|
160
|
+
providedIn: "root",
|
|
161
|
+
factory: () => []
|
|
216
162
|
});
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
* export const appConfig: ApplicationConfig = {
|
|
248
|
-
* providers: [
|
|
249
|
-
* provideDaffInMemoryRoutableObjects("PRODUCTS", productResolver),
|
|
250
|
-
* ]
|
|
251
|
-
* };
|
|
252
|
-
* ```
|
|
253
|
-
*/
|
|
254
|
-
const provideDaffInMemoryRoutableObjects = (type, resolver) => makeEnvironmentProviders([
|
|
255
|
-
{
|
|
256
|
-
provide: DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER,
|
|
257
|
-
useValue: { type, resolver },
|
|
258
|
-
multi: true,
|
|
259
|
-
},
|
|
260
|
-
]);
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Generated bundle index. Do not edit.
|
|
264
|
-
*/
|
|
265
|
-
|
|
163
|
+
const DAFF_INMEMORY_ROUTABLE_OBJECTS = new InjectionToken("DAFF_INMEMORY_ROUTABLE_OBJECTS", {
|
|
164
|
+
providedIn: "root",
|
|
165
|
+
factory: () => {
|
|
166
|
+
const resolvers = inject(DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER, { optional: true }) || [];
|
|
167
|
+
const map = /* @__PURE__ */ new Map();
|
|
168
|
+
if (!Array.isArray(resolvers)) throw new Error("DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER must be an array");
|
|
169
|
+
resolvers.forEach((entry) => {
|
|
170
|
+
entry.resolver().forEach((entity) => {
|
|
171
|
+
if (map.has(entity.url)) {
|
|
172
|
+
const existing = map.get(entity.url);
|
|
173
|
+
console.warn(`[@daffodil/driver/in-memory] Duplicate entity URL detected: "${entity.url}". Already registered with type "${existing?.type}", attempting to register again with type "${entry.type}". The first registration will be used.`);
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
map.set(entity.url, {
|
|
177
|
+
url: entity.url,
|
|
178
|
+
type: entry.type
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
return map;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const provideDaffInMemoryRoutableObjects = (type, resolver) => makeEnvironmentProviders([{
|
|
186
|
+
provide: DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER,
|
|
187
|
+
useValue: {
|
|
188
|
+
type,
|
|
189
|
+
resolver
|
|
190
|
+
},
|
|
191
|
+
multi: true
|
|
192
|
+
}]);
|
|
266
193
|
export { DAFF_INMEMORY_ROUTABLE_OBJECTS, DAFF_IN_MEMORY_BACKENDS, DAFF_IN_MEMORY_DRIVER_CONFIG, DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, DaffInMemoryBackendDelegate, DaffInMemoryDriverBase, DaffInMemoryDriverModule, DaffInMemoryRootBackend, provideDaffInMemoryBackends, provideDaffInMemoryDriver, provideDaffInMemoryDriverConfig, provideDaffInMemoryRoutableObjects };
|
|
267
|
-
|
|
194
|
+
|
|
195
|
+
//# sourceMappingURL=daffodil-driver-in-memory.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"daffodil-driver-in-memory.mjs","sources":["../../../libs/driver/in-memory/src/backend/backends.token.ts","../../../libs/driver/in-memory/src/backend/delegate.class.ts","../../../libs/driver/in-memory/src/backend/root.service.ts","../../../libs/driver/in-memory/src/driver/base.class.ts","../../../libs/driver/in-memory/src/config/default.ts","../../../libs/driver/in-memory/src/config/token.ts","../../../libs/driver/in-memory/src/module.ts","../../../libs/driver/in-memory/src/provider.ts","../../../libs/driver/in-memory/src/routing/provider.ts","../../../libs/driver/in-memory/src/daffodil-driver-in-memory.ts"],"sourcesContent":["import { createServicesInjectionToken } from '@daffodil/core';\n\nimport { DaffInMemoryBackendInterface } from './type';\n\nexport const {\n /**\n * A token that holds the currently loaded in-memory backends.\n */\n token: DAFF_IN_MEMORY_BACKENDS,\n /**\n * Provide backend classes to {@link DAFF_IN_MEMORY_BACKENDS}.\n */\n provider: provideDaffInMemoryBackends,\n} = createServicesInjectionToken<DaffInMemoryBackendInterface>('DAFF_IN_MEMORY_BACKENDS');\n","import {\n RequestInfo,\n STATUS,\n} from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\n\nimport { DaffInMemoryDataServiceInterface } from './data-service.type';\nimport { DaffInMemoryRouteableBackend } from './routeable.type';\nimport { DaffInMemoryDriverConfig } from '../public_api';\n\nenum Method {\n GET = 'get',\n POST = 'post',\n PUT = 'put',\n DELETE = 'delete',\n}\n\n/**\n * An class that automatically delegates requests to in-memory backends.\n *\n * @inheritdoc\n */\nexport class DaffInMemoryBackendDelegate implements DaffInMemoryDataServiceInterface {\n\n constructor(\n protected backends: Array<DaffInMemoryRouteableBackend>,\n protected config: DaffInMemoryDriverConfig,\n ) {}\n\n protected delegateRequest(reqInfo: RequestInfo, method: Method): Observable<any> {\n const backend = this.backends.find((b) => 'collectionName' in b ? b.collectionName === reqInfo.collectionName : b.canHandle(reqInfo.collectionName));\n const request = backend?.[method];\n\n if(request) {\n // allow child backends to return nully values\n // which will fall back to default request behavior (https://github.com/angular/angular/tree/main/packages/misc/angular-in-memory-web-api#http-request-handling)\n return request.call(backend, reqInfo);\n }\n\n if(!this.config.passThroughUnknownRequests) {\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.NOT_FOUND,\n statusText: `Backend ${reqInfo.collectionName} not found or does not support the ${method} request method`,\n }));\n }\n\n return undefined;\n }\n\n get?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.GET);\n }\n\n post?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.POST);\n }\n\n put?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.PUT);\n }\n\n delete?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.DELETE);\n }\n}\n","import {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n InMemoryDbService,\n RequestInfo,\n} from 'angular-in-memory-web-api';\nimport {\n combineLatest,\n map,\n take,\n} from 'rxjs';\n\nimport { observe } from '@daffodil/core';\n\nimport { DAFF_IN_MEMORY_BACKENDS } from './backends.token';\nimport { DaffInMemoryDataServiceInterface } from './data-service.type';\nimport { DaffInMemoryBackendDelegate } from './delegate.class';\nimport { DaffInMemoryBackendInterface } from './type';\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG,\n DaffInMemoryDriverConfig,\n} from '../public_api';\n\n/**\n * An in-memory backend that automatically delegates requests to backends provided to {@link DAFF_IN_MEMORY_BACKENDS}.\n *\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryRootBackend extends DaffInMemoryBackendDelegate implements DaffInMemoryDataServiceInterface, InMemoryDbService {\n constructor(\n @Inject(DAFF_IN_MEMORY_BACKENDS) private _backends: Array<DaffInMemoryBackendInterface>,\n @Inject(DAFF_IN_MEMORY_DRIVER_CONFIG) private _config: DaffInMemoryDriverConfig,\n ) {\n super(_backends, _config);\n }\n\n createDb(reqInfo?: RequestInfo) {\n return combineLatest(this._backends.map(observe)).pipe(\n take(1),\n map((backends) => backends.reduce((db, backend) => ({\n ...db,\n ...backend.createDb(reqInfo),\n }), {})),\n );\n }\n}\n","import { InMemoryBackendConfigArgs } from 'angular-in-memory-web-api';\n\n/**\n * The base class for in-memory drivers.\n */\nexport abstract class DaffInMemoryDriverBase {\n /**\n * The URL of the corresponding backend.\n * Does not include a trailing slash, it is of the form: `/<api base>/<collection name>`.\n */\n protected readonly url = `/${this.config.apiBase}/${this.collectionName}`;\n\n constructor(\n private config: InMemoryBackendConfigArgs,\n private collectionName: string,\n ) {}\n}\n","import { DaffInMemoryDriverConfig } from './type';\n\nexport const DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT: DaffInMemoryDriverConfig = {\n apiBase: 'api',\n passThroughUnknownRequests: false,\n};\n","import { createConfigInjectionToken } from '@daffodil/core';\n\nimport { DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT } from './default';\nimport { DaffInMemoryDriverConfig } from './type';\n\nexport const {\n token: DAFF_IN_MEMORY_DRIVER_CONFIG,\n /**\n * Provider function for {@link DAFF_IN_MEMORY_DRIVER_CONFIG}.\n */\n provider: provideDaffInMemoryDriverConfig,\n} = createConfigInjectionToken<DaffInMemoryDriverConfig>(DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, 'DAFF_IN_MEMORY_DRIVER_CONFIG');\n","import {\n NgModule,\n ModuleWithProviders,\n importProvidersFrom,\n} from '@angular/core';\nimport { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';\n\nimport { DaffInMemoryRootBackend } from './backend/public_api';\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,\n DaffInMemoryDriverConfig,\n provideDaffInMemoryDriverConfig,\n} from './config/public_api';\n\n/**\n * Sets up the angular in memory web API with the {@link DaffInMemoryRootBackend}.\n */\n@NgModule()\nexport class DaffInMemoryDriverModule {\n static forRoot(config: DaffInMemoryDriverConfig = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT): ModuleWithProviders<DaffInMemoryDriverModule> {\n return {\n ngModule: DaffInMemoryDriverModule,\n providers: [\n importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryRootBackend, config)),\n provideDaffInMemoryDriverConfig(config),\n ],\n };\n }\n}\n","import {\n EnvironmentProviders,\n importProvidersFrom,\n makeEnvironmentProviders,\n Type,\n} from '@angular/core';\nimport { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';\n\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,\n DaffInMemoryBackendInterface,\n DaffInMemoryDriverConfig,\n DaffInMemoryRootBackend,\n provideDaffInMemoryBackends,\n provideDaffInMemoryDriverConfig,\n} from './public_api';\n\n/**\n * Configures the Angular in-memory web API with Daffodil backend services.\n *\n * @example\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideDaffInMemoryDriver(\n * { delay: 300 },\n * DaffProductInMemoryBackendService,\n * DaffCartInMemoryBackendService\n * )\n * ]\n * });\n * ```\n */\nexport const provideDaffInMemoryDriver = (config: DaffInMemoryDriverConfig = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, ...backends: Array<Type<DaffInMemoryBackendInterface>>): EnvironmentProviders[] => {\n config = { ...DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,...config };\n return [\n importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryRootBackend, { ...config, passThruUnknownUrl: config.passThroughUnknownRequests })),\n makeEnvironmentProviders([\n provideDaffInMemoryDriverConfig(config),\n provideDaffInMemoryBackends(...backends),\n ]),\n ];\n};\n","import {\n EnvironmentProviders,\n inject,\n InjectionToken,\n makeEnvironmentProviders,\n} from '@angular/core';\n\nimport {\n DaffInMemoryRoutableObject,\n DaffInMemoryRoutableObjects,\n} from './routable-object';\n\n/**\n * A function that returns an array of entities with URL properties.\n * Used to provide routable in-memory object information to the routing system.\n */\nexport type DaffInMemoryRoutableObjectsResolver = () => Array<{ url: string }>;\n\n/**\n * Multi-injection token for routable object resolvers.\n *\n * Each in-memory driver (e.g., product, navigation) can register a resolver\n * that provides its entities with URL properties. This token collects all\n * such resolvers so they can be processed together to build the routing map.\n *\n * @docs-private\n */\nconst DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER = new InjectionToken<{ type: string; resolver: DaffInMemoryRoutableObjectsResolver }[]>(\n 'DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER', {\n providedIn: 'root',\n factory: () => [],\n },\n);\n\n/**\n * Internal injection token that builds and provides the complete map of routable objects.\n *\n * This token automatically collects all registered routable object resolvers and builds\n * a Map where the key is the URL path and the value is an object containing both the URL\n * and its associated type. This map is used by in-memory drivers to resolve URLs to their types.\n *\n * @docs-private\n */\nexport const DAFF_INMEMORY_ROUTABLE_OBJECTS = new InjectionToken<DaffInMemoryRoutableObjects>(\n 'DAFF_INMEMORY_ROUTABLE_OBJECTS',\n {\n providedIn: 'root',\n factory: () => {\n const resolvers = inject(DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER, { optional: true }) || [];\n const map = new Map<string, DaffInMemoryRoutableObject>();\n\n if (!Array.isArray(resolvers)) {\n throw new Error('DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER must be an array');\n }\n\n resolvers.forEach((entry) => {\n const entities = entry.resolver();\n entities.forEach(entity => {\n if (map.has(entity.url)) {\n const existing = map.get(entity.url);\n console.warn(\n `[@daffodil/driver/in-memory] Duplicate entity URL detected: \"${entity.url}\". ` +\n `Already registered with type \"${existing?.type}\", attempting to register again with type \"${entry.type}\". ` +\n `The first registration will be used.`,\n );\n return;\n }\n map.set(entity.url, { url: entity.url, type: entry.type });\n });\n });\n\n return map;\n },\n },\n);\n\n/**\n * Registers routable objects from an in-memory driver with the routing system.\n *\n * This function allows in-memory drivers to provide their entities (with URL properties)\n * to enable automatic URL resolution. Each driver provides a resolver function that\n * returns its entities with URL properties, along with a type identifier.\n *\n * The resolver function runs in an injection context, which means you can use Angular's\n * `inject()` function within it to access services and dependencies.\n *\n * @param type - The type identifier for these routable objects (e.g., \"PRODUCTS\")\n * @param resolver - A function that returns an array of entities with URL properties.\n * This function runs in an injection context, allowing use of `inject()`.\n * @returns Environment providers that register the routable objects\n *\n * @usageNotes\n *\n * ### Basic Usage\n *\n * In your driver package, create a resolver function:\n *\n * ```typescript\n * const productResolver = (): Array<{ url: string }> => {\n * return inject(DaffInMemoryBackendProductService).products.map((p) => ({ url: p.url }));\n * };\n * ```\n *\n * Then in your app configuration:\n *\n * ```typescript\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDaffInMemoryRoutableObjects(\"PRODUCTS\", productResolver),\n * ]\n * };\n * ```\n */\nexport const provideDaffInMemoryRoutableObjects = (\n type: string,\n resolver: DaffInMemoryRoutableObjectsResolver,\n): EnvironmentProviders => makeEnvironmentProviders([\n {\n provide: DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER,\n useValue: { type, resolver },\n multi: true,\n },\n]);\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;AAIO,MAAM;AACX;;AAEG;AACH,KAAK,EAAE,uBAAuB;AAC9B;;AAEG;AACH,QAAQ,EAAE,2BAA2B,GACtC,GAAG,4BAA4B,CAA+B,yBAAyB;;ACHxF,IAAK,MAKJ;AALD,CAAA,UAAK,MAAM,EAAA;AACT,IAAA,MAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,MAAA,CAAA,MAAA,CAAA,GAAA,MAAa;AACb,IAAA,MAAA,CAAA,KAAA,CAAA,GAAA,KAAW;AACX,IAAA,MAAA,CAAA,QAAA,CAAA,GAAA,QAAiB;AACnB,CAAC,EALI,MAAM,KAAN,MAAM,GAAA,EAAA,CAAA,CAAA;AAOX;;;;AAIG;MACU,2BAA2B,CAAA;IAEtC,WAAA,CACY,QAA6C,EAC7C,MAAgC,EAAA;QADhC,IAAA,CAAA,QAAQ,GAAR,QAAQ;QACR,IAAA,CAAA,MAAM,GAAN,MAAM;IACf;IAEO,eAAe,CAAC,OAAoB,EAAE,MAAc,EAAA;AAC5D,QAAA,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,gBAAgB,IAAI,CAAC,GAAG,CAAC,CAAC,cAAc,KAAK,OAAO,CAAC,cAAc,GAAG,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;AACpJ,QAAA,MAAM,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;QAEjC,IAAG,OAAO,EAAE;;;YAGV,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC;QACvC;AAEA,QAAA,IAAG,CAAC,IAAI,CAAC,MAAM,CAAC,0BAA0B,EAAE;YAC1C,OAAO,OAAO,CAAC,KAAK,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,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;AAC5B,QAAA,KAAK,EAAE,IAAI;AACZ,KAAA;AACF,CAAA;;AC1HD;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"daffodil-driver-in-memory.mjs","names":[],"sources":["../../../libs/driver/in-memory/src/backend/backends.token.ts","../../../libs/driver/in-memory/src/backend/delegate.class.ts","../../../libs/driver/in-memory/src/backend/root.service.ts","../../../libs/driver/in-memory/src/driver/base.class.ts","../../../libs/driver/in-memory/src/config/default.ts","../../../libs/driver/in-memory/src/config/token.ts","../../../libs/driver/in-memory/src/provider.ts","../../../libs/driver/in-memory/src/module.ts","../../../libs/driver/in-memory/src/routing/provider.ts"],"sourcesContent":["import { createServicesInjectionToken } from '@daffodil/core';\n\nimport { DaffInMemoryBackendInterface } from './type';\n\nexport const {\n /**\n * A token that holds the currently loaded in-memory backends.\n */\n token: DAFF_IN_MEMORY_BACKENDS,\n /**\n * Provide backend classes to {@link DAFF_IN_MEMORY_BACKENDS}.\n */\n provider: provideDaffInMemoryBackends,\n} = createServicesInjectionToken<DaffInMemoryBackendInterface>('DAFF_IN_MEMORY_BACKENDS');\n","import {\n RequestInfo,\n STATUS,\n} from 'angular-in-memory-web-api';\nimport { Observable } from 'rxjs';\n\nimport { DaffInMemoryDataServiceInterface } from './data-service.type';\nimport { DaffInMemoryRouteableBackend } from './routeable.type';\nimport { DaffInMemoryDriverConfig } from '../public_api';\n\nenum Method {\n GET = 'get',\n POST = 'post',\n PUT = 'put',\n DELETE = 'delete',\n}\n\n/**\n * An class that automatically delegates requests to in-memory backends.\n *\n * @inheritdoc\n */\nexport class DaffInMemoryBackendDelegate implements DaffInMemoryDataServiceInterface {\n\n constructor(\n protected backends: Array<DaffInMemoryRouteableBackend>,\n protected config: DaffInMemoryDriverConfig,\n ) {}\n\n protected delegateRequest(reqInfo: RequestInfo, method: Method): Observable<any> {\n const backend = this.backends.find((b) => 'collectionName' in b ? b.collectionName === reqInfo.collectionName : b.canHandle(reqInfo.collectionName));\n const request = backend?.[method];\n\n if(request) {\n // allow child backends to return nully values\n // which will fall back to default request behavior (https://github.com/angular/angular/tree/main/packages/misc/angular-in-memory-web-api#http-request-handling)\n return request.call(backend, reqInfo);\n }\n\n if(!this.config.passThroughUnknownRequests) {\n return reqInfo.utils.createResponse$(() => ({\n status: STATUS.NOT_FOUND,\n statusText: `Backend ${reqInfo.collectionName} not found or does not support the ${method} request method`,\n }));\n }\n\n return undefined;\n }\n\n get?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.GET);\n }\n\n post?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.POST);\n }\n\n put?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.PUT);\n }\n\n delete?(reqInfo: RequestInfo): Observable<any> {\n return this.delegateRequest(reqInfo, Method.DELETE);\n }\n}\n","import {\n Inject,\n Injectable,\n} from '@angular/core';\nimport {\n InMemoryDbService,\n RequestInfo,\n} from 'angular-in-memory-web-api';\nimport {\n combineLatest,\n map,\n take,\n} from 'rxjs';\n\nimport { observe } from '@daffodil/core';\n\nimport { DAFF_IN_MEMORY_BACKENDS } from './backends.token';\nimport { DaffInMemoryDataServiceInterface } from './data-service.type';\nimport { DaffInMemoryBackendDelegate } from './delegate.class';\nimport { DaffInMemoryBackendInterface } from './type';\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG,\n DaffInMemoryDriverConfig,\n} from '../public_api';\n\n/**\n * An in-memory backend that automatically delegates requests to backends provided to {@link DAFF_IN_MEMORY_BACKENDS}.\n *\n * @inheritdoc\n */\n@Injectable({\n providedIn: 'root',\n})\nexport class DaffInMemoryRootBackend extends DaffInMemoryBackendDelegate implements DaffInMemoryDataServiceInterface, InMemoryDbService {\n constructor(\n @Inject(DAFF_IN_MEMORY_BACKENDS) private _backends: Array<DaffInMemoryBackendInterface>,\n @Inject(DAFF_IN_MEMORY_DRIVER_CONFIG) private _config: DaffInMemoryDriverConfig,\n ) {\n super(_backends, _config);\n }\n\n createDb(reqInfo?: RequestInfo) {\n return combineLatest(this._backends.map(observe)).pipe(\n take(1),\n map((backends) => backends.reduce((db, backend) => ({\n ...db,\n ...backend.createDb(reqInfo),\n }), {})),\n );\n }\n}\n","import { InMemoryBackendConfigArgs } from 'angular-in-memory-web-api';\n\n/**\n * The base class for in-memory drivers.\n */\nexport abstract class DaffInMemoryDriverBase {\n /**\n * The URL of the corresponding backend.\n * Does not include a trailing slash, it is of the form: `/<api base>/<collection name>`.\n */\n protected readonly url = `/${this.config.apiBase}/${this.collectionName}`;\n\n constructor(\n private config: InMemoryBackendConfigArgs,\n private collectionName: string,\n ) {}\n}\n","import { DaffInMemoryDriverConfig } from './type';\n\nexport const DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT: DaffInMemoryDriverConfig = {\n apiBase: 'api',\n passThroughUnknownRequests: false,\n};\n","import { createConfigInjectionToken } from '@daffodil/core';\n\nimport { DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT } from './default';\nimport { DaffInMemoryDriverConfig } from './type';\n\nexport const {\n token: DAFF_IN_MEMORY_DRIVER_CONFIG,\n /**\n * Provider function for {@link DAFF_IN_MEMORY_DRIVER_CONFIG}.\n */\n provider: provideDaffInMemoryDriverConfig,\n} = createConfigInjectionToken<DaffInMemoryDriverConfig>(DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, 'DAFF_IN_MEMORY_DRIVER_CONFIG');\n","import {\n EnvironmentProviders,\n importProvidersFrom,\n makeEnvironmentProviders,\n Type,\n} from '@angular/core';\nimport { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';\n\nimport {\n DaffInMemoryBackendInterface,\n DaffInMemoryRootBackend,\n provideDaffInMemoryBackends,\n} from './backend/public_api';\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,\n DaffInMemoryDriverConfig,\n provideDaffInMemoryDriverConfig,\n} from './config/public_api';\n\n/**\n * Configures the Angular in-memory web API with Daffodil backend services.\n *\n * @example\n * ```ts\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideDaffInMemoryDriver(\n * { delay: 300 },\n * DaffProductInMemoryBackendService,\n * DaffCartInMemoryBackendService\n * )\n * ]\n * });\n * ```\n */\nexport const provideDaffInMemoryDriver = (config: DaffInMemoryDriverConfig = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT, ...backends: Array<Type<DaffInMemoryBackendInterface>>): EnvironmentProviders[] => {\n config = { ...DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,...config };\n return [\n importProvidersFrom(HttpClientInMemoryWebApiModule.forRoot(DaffInMemoryRootBackend, { ...config, passThruUnknownUrl: config.passThroughUnknownRequests })),\n makeEnvironmentProviders([\n provideDaffInMemoryDriverConfig(config),\n provideDaffInMemoryBackends(...backends),\n ]),\n ];\n};\n","import {\n NgModule,\n ModuleWithProviders,\n} from '@angular/core';\n\nimport {\n DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT,\n DaffInMemoryDriverConfig,\n} from './config/public_api';\nimport { provideDaffInMemoryDriver } from './provider';\n\n/**\n * Sets up the angular in memory web API with the {@link DaffInMemoryRootBackend}.\n *\n * @deprecated in favor of {@link provideDaffInMemoryDriver} Deprecated in version 0.95.0. Will be removed in version 0.98.0.\n */\n@NgModule()\nexport class DaffInMemoryDriverModule {\n static forRoot(config: DaffInMemoryDriverConfig = DAFF_IN_MEMORY_DRIVER_CONFIG_DEFAULT): ModuleWithProviders<DaffInMemoryDriverModule> {\n return {\n ngModule: DaffInMemoryDriverModule,\n providers: [\n provideDaffInMemoryDriver(config),\n ],\n };\n }\n}\n","import {\n EnvironmentProviders,\n inject,\n InjectionToken,\n makeEnvironmentProviders,\n} from '@angular/core';\n\nimport {\n DaffInMemoryRoutableObject,\n DaffInMemoryRoutableObjects,\n} from './routable-object';\n\n/**\n * A function that returns an array of entities with URL properties.\n * Used to provide routable in-memory object information to the routing system.\n */\nexport type DaffInMemoryRoutableObjectsResolver = () => Array<{ url: string }>;\n\n/**\n * Multi-injection token for routable object resolvers.\n *\n * Each in-memory driver (e.g., product, navigation) can register a resolver\n * that provides its entities with URL properties. This token collects all\n * such resolvers so they can be processed together to build the routing map.\n *\n * @docs-private\n */\nconst DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER = new InjectionToken<{ type: string; resolver: DaffInMemoryRoutableObjectsResolver }[]>(\n 'DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER', {\n providedIn: 'root',\n factory: () => [],\n },\n);\n\n/**\n * Internal injection token that builds and provides the complete map of routable objects.\n *\n * This token automatically collects all registered routable object resolvers and builds\n * a Map where the key is the URL path and the value is an object containing both the URL\n * and its associated type. This map is used by in-memory drivers to resolve URLs to their types.\n *\n * @docs-private\n */\nexport const DAFF_INMEMORY_ROUTABLE_OBJECTS = new InjectionToken<DaffInMemoryRoutableObjects>(\n 'DAFF_INMEMORY_ROUTABLE_OBJECTS',\n {\n providedIn: 'root',\n factory: () => {\n const resolvers = inject(DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER, { optional: true }) || [];\n const map = new Map<string, DaffInMemoryRoutableObject>();\n\n if (!Array.isArray(resolvers)) {\n throw new Error('DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER must be an array');\n }\n\n resolvers.forEach((entry) => {\n const entities = entry.resolver();\n entities.forEach(entity => {\n if (map.has(entity.url)) {\n const existing = map.get(entity.url);\n console.warn(\n `[@daffodil/driver/in-memory] Duplicate entity URL detected: \"${entity.url}\". ` +\n `Already registered with type \"${existing?.type}\", attempting to register again with type \"${entry.type}\". ` +\n `The first registration will be used.`,\n );\n return;\n }\n map.set(entity.url, { url: entity.url, type: entry.type });\n });\n });\n\n return map;\n },\n },\n);\n\n/**\n * Registers routable objects from an in-memory driver with the routing system.\n *\n * This function allows in-memory drivers to provide their entities (with URL properties)\n * to enable automatic URL resolution. Each driver provides a resolver function that\n * returns its entities with URL properties, along with a type identifier.\n *\n * The resolver function runs in an injection context, which means you can use Angular's\n * `inject()` function within it to access services and dependencies.\n *\n * @param type - The type identifier for these routable objects (e.g., \"PRODUCTS\")\n * @param resolver - A function that returns an array of entities with URL properties.\n * This function runs in an injection context, allowing use of `inject()`.\n * @returns Environment providers that register the routable objects\n *\n * @usageNotes\n *\n * ### Basic Usage\n *\n * In your driver package, create a resolver function:\n *\n * ```typescript\n * const productResolver = (): Array<{ url: string }> => {\n * return inject(DaffInMemoryBackendProductService).products.map((p) => ({ url: p.url }));\n * };\n * ```\n *\n * Then in your app configuration:\n *\n * ```typescript\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideDaffInMemoryRoutableObjects(\"PRODUCTS\", productResolver),\n * ]\n * };\n * ```\n */\nexport const provideDaffInMemoryRoutableObjects = (\n type: string,\n resolver: DaffInMemoryRoutableObjectsResolver,\n): EnvironmentProviders => makeEnvironmentProviders([\n {\n provide: DAFF_INMEMORY_ROUTABLE_OBJECTS_RESOLVER,\n useValue: { type, resolver },\n multi: true,\n },\n]);\n"],"mappings":";;;;;AAIA,MAAa,EAIX,OAAO,yBAIP,UAAU,gCACR,6BAA2D,yBAAyB;ACHxF,IAAK;CAAL,SAAK,QAAM;CACT,OAAA,SAAA;CACA,OAAA,UAAA;CACA,OAAA,SAAA;CACA,OAAA,YAAA;AACF,EAAA,CALK,WAAA,SAAM,CAAA,EAAA;AAYX,IAAa,8BAAb,MAAwC;CAEtC,YACY,UACA,QAAgC;EADhC,KAAA,WAAA;EACA,KAAA,SAAA;CACT;CAEO,gBAAgB,SAAsB,QAAc;EAC5D,MAAM,UAAU,KAAK,SAAS,MAAM,MAAM,oBAAoB,IAAI,EAAE,mBAAmB,QAAQ,iBAAiB,EAAE,UAAU,QAAQ,cAAc,CAAC;EACnJ,MAAM,UAAU,UAAU;EAE1B,IAAG,SAGD,OAAO,QAAQ,KAAK,SAAS,OAAO;EAGtC,IAAG,CAAC,KAAK,OAAO,4BACd,OAAO,QAAQ,MAAM,uBAAu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