@salesforce/lds-adapters-industries-dataloading 0.131.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.
@@ -0,0 +1,628 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ import { serializeStructuredKey, StoreKeyMap } from '@luvio/engine';
8
+
9
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
10
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
11
+ const { isArray: ArrayIsArray$1 } = Array;
12
+ /**
13
+ * Validates an adapter config is well-formed.
14
+ * @param config The config to validate.
15
+ * @param adapter The adapter validation configuration.
16
+ * @param oneOf The keys the config must contain at least one of.
17
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
18
+ */
19
+ function validateConfig(config, adapter, oneOf) {
20
+ const { displayName } = adapter;
21
+ const { required, optional, unsupported } = adapter.parameters;
22
+ if (config === undefined ||
23
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
24
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
25
+ }
26
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
27
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
28
+ }
29
+ if (unsupported !== undefined &&
30
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
31
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
32
+ }
33
+ const supported = required.concat(optional);
34
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
35
+ throw new TypeError(`adapter ${displayName} configuration supports only ${supported.sort().join(', ')}`);
36
+ }
37
+ }
38
+ function untrustedIsObject(untrusted) {
39
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
40
+ }
41
+ function areRequiredParametersPresent(config, configPropertyNames) {
42
+ return configPropertyNames.parameters.required.every(req => req in config);
43
+ }
44
+ const snapshotRefreshOptions = {
45
+ overrides: {
46
+ headers: {
47
+ 'Cache-Control': 'no-cache',
48
+ },
49
+ }
50
+ };
51
+ const keyPrefix = 'dataloading';
52
+
53
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
54
+ const { isArray: ArrayIsArray } = Array;
55
+ const { stringify: JSONStringify } = JSON;
56
+ function createLink(ref) {
57
+ return {
58
+ __ref: serializeStructuredKey(ref),
59
+ };
60
+ }
61
+
62
+ const TTL$1 = 300;
63
+ const VERSION$1 = "b425ebad11bb7cc3aa194625f9745e2a";
64
+ function validate$2(obj, path = 'ObjectCsvDataTemplateRepresentation') {
65
+ const v_error = (() => {
66
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
67
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
68
+ }
69
+ const obj_code = obj.code;
70
+ const path_code = path + '.code';
71
+ if (typeof obj_code !== 'number' || (typeof obj_code === 'number' && Math.floor(obj_code) !== obj_code)) {
72
+ return new TypeError('Expected "integer" but received "' + typeof obj_code + '" (at "' + path_code + '")');
73
+ }
74
+ const obj_message = obj.message;
75
+ const path_message = path + '.message';
76
+ if (typeof obj_message !== 'string') {
77
+ return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
78
+ }
79
+ const obj_template = obj.template;
80
+ const path_template = path + '.template';
81
+ if (typeof obj_template !== 'object' || ArrayIsArray(obj_template) || obj_template === null) {
82
+ return new TypeError('Expected "object" but received "' + typeof obj_template + '" (at "' + path_template + '")');
83
+ }
84
+ })();
85
+ return v_error === undefined ? null : v_error;
86
+ }
87
+ const RepresentationType$1 = 'ObjectCsvDataTemplateRepresentation';
88
+ function normalize$1(input, existing, path, luvio, store, timestamp) {
89
+ return input;
90
+ }
91
+ const select$3 = function ObjectCsvDataTemplateRepresentationSelect() {
92
+ return {
93
+ kind: 'Fragment',
94
+ version: VERSION$1,
95
+ private: [],
96
+ opaque: true
97
+ };
98
+ };
99
+ function equals$1(existing, incoming) {
100
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
101
+ return false;
102
+ }
103
+ return true;
104
+ }
105
+ function deepFreeze$2(input) {
106
+ const input_template = input.template;
107
+ ObjectFreeze(input_template);
108
+ ObjectFreeze(input);
109
+ }
110
+ const ingest$1 = function ObjectCsvDataTemplateRepresentationIngest(input, path, luvio, store, timestamp) {
111
+ if (process.env.NODE_ENV !== 'production') {
112
+ const validateError = validate$2(input);
113
+ if (validateError !== null) {
114
+ throw validateError;
115
+ }
116
+ }
117
+ const key = path.fullPath;
118
+ const existingRecord = store.readEntry(key);
119
+ const ttlToUse = TTL$1;
120
+ let incomingRecord = normalize$1(input, store.readEntry(key), {
121
+ fullPath: key,
122
+ parent: path.parent,
123
+ propertyName: path.propertyName,
124
+ ttl: ttlToUse
125
+ });
126
+ deepFreeze$2(input);
127
+ if (existingRecord === undefined || equals$1(existingRecord, incomingRecord) === false) {
128
+ luvio.storePublish(key, incomingRecord);
129
+ }
130
+ {
131
+ const storeMetadataParams = {
132
+ ttl: ttlToUse,
133
+ namespace: "dataloading",
134
+ version: VERSION$1,
135
+ representationName: RepresentationType$1,
136
+ };
137
+ luvio.publishStoreMetadata(key, storeMetadataParams);
138
+ }
139
+ return createLink(key);
140
+ };
141
+ function getTypeCacheKeys$1(luvio, input, fullPathFactory) {
142
+ const rootKeySet = new StoreKeyMap();
143
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
144
+ const rootKey = fullPathFactory();
145
+ rootKeySet.set(rootKey, {
146
+ namespace: keyPrefix,
147
+ representationName: RepresentationType$1,
148
+ mergeable: false
149
+ });
150
+ return rootKeySet;
151
+ }
152
+
153
+ function select$2(luvio, params) {
154
+ return select$3();
155
+ }
156
+ function keyBuilder$3(luvio, params) {
157
+ return keyPrefix + '::ObjectCsvDataTemplateRepresentation:(' + 'objectApiName:' + params.urlParams.objectApiName + ')';
158
+ }
159
+ function getResponseCacheKeys$1(luvio, resourceParams, response) {
160
+ return getTypeCacheKeys$1(luvio, response, () => keyBuilder$3(luvio, resourceParams));
161
+ }
162
+ function ingestSuccess$1(luvio, resourceParams, response, snapshotRefresh) {
163
+ const { body } = response;
164
+ const key = keyBuilder$3(luvio, resourceParams);
165
+ luvio.storeIngest(key, ingest$1, body);
166
+ const snapshot = luvio.storeLookup({
167
+ recordId: key,
168
+ node: select$2(),
169
+ variables: {},
170
+ }, snapshotRefresh);
171
+ if (process.env.NODE_ENV !== 'production') {
172
+ if (snapshot.state !== 'Fulfilled') {
173
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
174
+ }
175
+ }
176
+ return snapshot;
177
+ }
178
+ function ingestError$1(luvio, params, error, snapshotRefresh) {
179
+ const key = keyBuilder$3(luvio, params);
180
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
181
+ const storeMetadataParams = {
182
+ ttl: TTL$1,
183
+ namespace: keyPrefix,
184
+ version: VERSION$1,
185
+ representationName: RepresentationType$1
186
+ };
187
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
188
+ return errorSnapshot;
189
+ }
190
+ function createResourceRequest$1(config) {
191
+ const headers = {};
192
+ return {
193
+ baseUri: '/services/data/v58.0',
194
+ basePath: '/connect/industries/csv-data-template/' + config.urlParams.objectApiName + '',
195
+ method: 'get',
196
+ body: null,
197
+ urlParams: config.urlParams,
198
+ queryParams: {},
199
+ headers,
200
+ priority: 'normal',
201
+ };
202
+ }
203
+
204
+ const getCsvDataTemplate_ConfigPropertyNames = {
205
+ displayName: 'getCsvDataTemplate',
206
+ parameters: {
207
+ required: ['objectApiName'],
208
+ optional: []
209
+ }
210
+ };
211
+ function createResourceParams$1(config) {
212
+ const resourceParams = {
213
+ urlParams: {
214
+ objectApiName: config.objectApiName
215
+ }
216
+ };
217
+ return resourceParams;
218
+ }
219
+ function keyBuilder$2(luvio, config) {
220
+ const resourceParams = createResourceParams$1(config);
221
+ return keyBuilder$3(luvio, resourceParams);
222
+ }
223
+ function typeCheckConfig$1(untrustedConfig) {
224
+ const config = {};
225
+ const untrustedConfig_objectApiName = untrustedConfig.objectApiName;
226
+ if (typeof untrustedConfig_objectApiName === 'string') {
227
+ config.objectApiName = untrustedConfig_objectApiName;
228
+ }
229
+ return config;
230
+ }
231
+ function validateAdapterConfig$1(untrustedConfig, configPropertyNames) {
232
+ if (!untrustedIsObject(untrustedConfig)) {
233
+ return null;
234
+ }
235
+ if (process.env.NODE_ENV !== 'production') {
236
+ validateConfig(untrustedConfig, configPropertyNames);
237
+ }
238
+ const config = typeCheckConfig$1(untrustedConfig);
239
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
240
+ return null;
241
+ }
242
+ return config;
243
+ }
244
+ function adapterFragment$1(luvio, config) {
245
+ createResourceParams$1(config);
246
+ return select$2();
247
+ }
248
+ function onFetchResponseSuccess$1(luvio, config, resourceParams, response) {
249
+ const snapshot = ingestSuccess$1(luvio, resourceParams, response, {
250
+ config,
251
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
252
+ });
253
+ return luvio.storeBroadcast().then(() => snapshot);
254
+ }
255
+ function onFetchResponseError$1(luvio, config, resourceParams, response) {
256
+ const snapshot = ingestError$1(luvio, resourceParams, response, {
257
+ config,
258
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
259
+ });
260
+ return luvio.storeBroadcast().then(() => snapshot);
261
+ }
262
+ function buildNetworkSnapshot$1(luvio, config, options) {
263
+ const resourceParams = createResourceParams$1(config);
264
+ const request = createResourceRequest$1(resourceParams);
265
+ return luvio.dispatchResourceRequest(request, options)
266
+ .then((response) => {
267
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess$1(luvio, config, resourceParams, response), () => getResponseCacheKeys$1(luvio, resourceParams, response.body));
268
+ }, (response) => {
269
+ return luvio.handleErrorResponse(() => onFetchResponseError$1(luvio, config, resourceParams, response));
270
+ });
271
+ }
272
+ function buildNetworkSnapshotCachePolicy$1(context, coercedAdapterRequestContext) {
273
+ const { luvio, config } = context;
274
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
275
+ const dispatchOptions = {
276
+ resourceRequestContext: {
277
+ requestCorrelator,
278
+ luvioRequestMethod: undefined,
279
+ },
280
+ eventObservers
281
+ };
282
+ if (networkPriority !== 'normal') {
283
+ dispatchOptions.overrides = {
284
+ priority: networkPriority
285
+ };
286
+ }
287
+ return buildNetworkSnapshot$1(luvio, config, dispatchOptions);
288
+ }
289
+ function buildCachedSnapshotCachePolicy$1(context, storeLookup) {
290
+ const { luvio, config } = context;
291
+ const selector = {
292
+ recordId: keyBuilder$2(luvio, config),
293
+ node: adapterFragment$1(luvio, config),
294
+ variables: {},
295
+ };
296
+ const cacheSnapshot = storeLookup(selector, {
297
+ config,
298
+ resolve: () => buildNetworkSnapshot$1(luvio, config, snapshotRefreshOptions)
299
+ });
300
+ return cacheSnapshot;
301
+ }
302
+ const getCsvDataTemplateAdapterFactory = (luvio) => function dataloading__getCsvDataTemplate(untrustedConfig, requestContext) {
303
+ const config = validateAdapterConfig$1(untrustedConfig, getCsvDataTemplate_ConfigPropertyNames);
304
+ // Invalid or incomplete config
305
+ if (config === null) {
306
+ return null;
307
+ }
308
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
309
+ buildCachedSnapshotCachePolicy$1, buildNetworkSnapshotCachePolicy$1);
310
+ };
311
+
312
+ function validate$1(obj, path = 'FeatureObjectRepresentation') {
313
+ const v_error = (() => {
314
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
315
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
316
+ }
317
+ const obj_apiName = obj.apiName;
318
+ const path_apiName = path + '.apiName';
319
+ if (typeof obj_apiName !== 'string') {
320
+ return new TypeError('Expected "string" but received "' + typeof obj_apiName + '" (at "' + path_apiName + '")');
321
+ }
322
+ const obj_label = obj.label;
323
+ const path_label = path + '.label';
324
+ if (typeof obj_label !== 'string') {
325
+ return new TypeError('Expected "string" but received "' + typeof obj_label + '" (at "' + path_label + '")');
326
+ }
327
+ })();
328
+ return v_error === undefined ? null : v_error;
329
+ }
330
+ function deepFreeze$1(input) {
331
+ ObjectFreeze(input);
332
+ }
333
+
334
+ const TTL = 300;
335
+ const VERSION = "440ab792d2d7f730b3d308c484a9222b";
336
+ function validate(obj, path = 'FeatureObjectsResultRepresentation') {
337
+ const v_error = (() => {
338
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
339
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
340
+ }
341
+ const obj_code = obj.code;
342
+ const path_code = path + '.code';
343
+ if (typeof obj_code !== 'number' || (typeof obj_code === 'number' && Math.floor(obj_code) !== obj_code)) {
344
+ return new TypeError('Expected "integer" but received "' + typeof obj_code + '" (at "' + path_code + '")');
345
+ }
346
+ const obj_currentPageNumber = obj.currentPageNumber;
347
+ const path_currentPageNumber = path + '.currentPageNumber';
348
+ if (typeof obj_currentPageNumber !== 'number' || (typeof obj_currentPageNumber === 'number' && Math.floor(obj_currentPageNumber) !== obj_currentPageNumber)) {
349
+ return new TypeError('Expected "integer" but received "' + typeof obj_currentPageNumber + '" (at "' + path_currentPageNumber + '")');
350
+ }
351
+ const obj_currentPageSize = obj.currentPageSize;
352
+ const path_currentPageSize = path + '.currentPageSize';
353
+ if (typeof obj_currentPageSize !== 'number' || (typeof obj_currentPageSize === 'number' && Math.floor(obj_currentPageSize) !== obj_currentPageSize)) {
354
+ return new TypeError('Expected "integer" but received "' + typeof obj_currentPageSize + '" (at "' + path_currentPageSize + '")');
355
+ }
356
+ const obj_message = obj.message;
357
+ const path_message = path + '.message';
358
+ if (typeof obj_message !== 'string') {
359
+ return new TypeError('Expected "string" but received "' + typeof obj_message + '" (at "' + path_message + '")');
360
+ }
361
+ const obj_objects = obj.objects;
362
+ const path_objects = path + '.objects';
363
+ if (!ArrayIsArray(obj_objects)) {
364
+ return new TypeError('Expected "array" but received "' + typeof obj_objects + '" (at "' + path_objects + '")');
365
+ }
366
+ for (let i = 0; i < obj_objects.length; i++) {
367
+ const obj_objects_item = obj_objects[i];
368
+ const path_objects_item = path_objects + '[' + i + ']';
369
+ const referencepath_objects_itemValidationError = validate$1(obj_objects_item, path_objects_item);
370
+ if (referencepath_objects_itemValidationError !== null) {
371
+ let message = 'Object doesn\'t match FeatureObjectRepresentation (at "' + path_objects_item + '")\n';
372
+ message += referencepath_objects_itemValidationError.message.split('\n').map((line) => '\t' + line).join('\n');
373
+ return new TypeError(message);
374
+ }
375
+ }
376
+ const obj_totalAvailableItems = obj.totalAvailableItems;
377
+ const path_totalAvailableItems = path + '.totalAvailableItems';
378
+ if (typeof obj_totalAvailableItems !== 'number' || (typeof obj_totalAvailableItems === 'number' && Math.floor(obj_totalAvailableItems) !== obj_totalAvailableItems)) {
379
+ return new TypeError('Expected "integer" but received "' + typeof obj_totalAvailableItems + '" (at "' + path_totalAvailableItems + '")');
380
+ }
381
+ })();
382
+ return v_error === undefined ? null : v_error;
383
+ }
384
+ const RepresentationType = 'FeatureObjectsResultRepresentation';
385
+ function normalize(input, existing, path, luvio, store, timestamp) {
386
+ return input;
387
+ }
388
+ const select$1 = function FeatureObjectsResultRepresentationSelect() {
389
+ return {
390
+ kind: 'Fragment',
391
+ version: VERSION,
392
+ private: [],
393
+ opaque: true
394
+ };
395
+ };
396
+ function equals(existing, incoming) {
397
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
398
+ return false;
399
+ }
400
+ return true;
401
+ }
402
+ function deepFreeze(input) {
403
+ const input_objects = input.objects;
404
+ for (let i = 0; i < input_objects.length; i++) {
405
+ const input_objects_item = input_objects[i];
406
+ deepFreeze$1(input_objects_item);
407
+ }
408
+ ObjectFreeze(input_objects);
409
+ ObjectFreeze(input);
410
+ }
411
+ const ingest = function FeatureObjectsResultRepresentationIngest(input, path, luvio, store, timestamp) {
412
+ if (process.env.NODE_ENV !== 'production') {
413
+ const validateError = validate(input);
414
+ if (validateError !== null) {
415
+ throw validateError;
416
+ }
417
+ }
418
+ const key = path.fullPath;
419
+ const existingRecord = store.readEntry(key);
420
+ const ttlToUse = TTL;
421
+ let incomingRecord = normalize(input, store.readEntry(key), {
422
+ fullPath: key,
423
+ parent: path.parent,
424
+ propertyName: path.propertyName,
425
+ ttl: ttlToUse
426
+ });
427
+ deepFreeze(input);
428
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
429
+ luvio.storePublish(key, incomingRecord);
430
+ }
431
+ {
432
+ const storeMetadataParams = {
433
+ ttl: ttlToUse,
434
+ namespace: "dataloading",
435
+ version: VERSION,
436
+ representationName: RepresentationType,
437
+ };
438
+ luvio.publishStoreMetadata(key, storeMetadataParams);
439
+ }
440
+ return createLink(key);
441
+ };
442
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
443
+ const rootKeySet = new StoreKeyMap();
444
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
445
+ const rootKey = fullPathFactory();
446
+ rootKeySet.set(rootKey, {
447
+ namespace: keyPrefix,
448
+ representationName: RepresentationType,
449
+ mergeable: false
450
+ });
451
+ return rootKeySet;
452
+ }
453
+
454
+ function select(luvio, params) {
455
+ return select$1();
456
+ }
457
+ function keyBuilder$1(luvio, params) {
458
+ return keyPrefix + '::FeatureObjectsResultRepresentation:(' + 'limit:' + params.queryParams.limit + ',' + 'offset:' + params.queryParams.offset + ',' + 'entityType:' + params.queryParams.entityType + ',' + 'featureName:' + params.urlParams.featureName + ')';
459
+ }
460
+ function getResponseCacheKeys(luvio, resourceParams, response) {
461
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
462
+ }
463
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
464
+ const { body } = response;
465
+ const key = keyBuilder$1(luvio, resourceParams);
466
+ luvio.storeIngest(key, ingest, body);
467
+ const snapshot = luvio.storeLookup({
468
+ recordId: key,
469
+ node: select(),
470
+ variables: {},
471
+ }, snapshotRefresh);
472
+ if (process.env.NODE_ENV !== 'production') {
473
+ if (snapshot.state !== 'Fulfilled') {
474
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
475
+ }
476
+ }
477
+ return snapshot;
478
+ }
479
+ function ingestError(luvio, params, error, snapshotRefresh) {
480
+ const key = keyBuilder$1(luvio, params);
481
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
482
+ const storeMetadataParams = {
483
+ ttl: TTL,
484
+ namespace: keyPrefix,
485
+ version: VERSION,
486
+ representationName: RepresentationType
487
+ };
488
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
489
+ return errorSnapshot;
490
+ }
491
+ function createResourceRequest(config) {
492
+ const headers = {};
493
+ return {
494
+ baseUri: '/services/data/v58.0',
495
+ basePath: '/connect/industries/' + config.urlParams.featureName + '/objects',
496
+ method: 'get',
497
+ body: null,
498
+ urlParams: config.urlParams,
499
+ queryParams: config.queryParams,
500
+ headers,
501
+ priority: 'normal',
502
+ };
503
+ }
504
+
505
+ const getObjectsForFeature_ConfigPropertyNames = {
506
+ displayName: 'getObjectsForFeature',
507
+ parameters: {
508
+ required: ['featureName', 'entityType'],
509
+ optional: ['limit', 'offset']
510
+ }
511
+ };
512
+ function createResourceParams(config) {
513
+ const resourceParams = {
514
+ urlParams: {
515
+ featureName: config.featureName
516
+ },
517
+ queryParams: {
518
+ limit: config.limit, offset: config.offset, entityType: config.entityType
519
+ }
520
+ };
521
+ return resourceParams;
522
+ }
523
+ function keyBuilder(luvio, config) {
524
+ const resourceParams = createResourceParams(config);
525
+ return keyBuilder$1(luvio, resourceParams);
526
+ }
527
+ function typeCheckConfig(untrustedConfig) {
528
+ const config = {};
529
+ const untrustedConfig_featureName = untrustedConfig.featureName;
530
+ if (typeof untrustedConfig_featureName === 'string') {
531
+ config.featureName = untrustedConfig_featureName;
532
+ }
533
+ const untrustedConfig_limit = untrustedConfig.limit;
534
+ if (typeof untrustedConfig_limit === 'number' && Math.floor(untrustedConfig_limit) === untrustedConfig_limit) {
535
+ config.limit = untrustedConfig_limit;
536
+ }
537
+ const untrustedConfig_offset = untrustedConfig.offset;
538
+ if (typeof untrustedConfig_offset === 'number' && Math.floor(untrustedConfig_offset) === untrustedConfig_offset) {
539
+ config.offset = untrustedConfig_offset;
540
+ }
541
+ const untrustedConfig_entityType = untrustedConfig.entityType;
542
+ if (typeof untrustedConfig_entityType === 'string') {
543
+ config.entityType = untrustedConfig_entityType;
544
+ }
545
+ return config;
546
+ }
547
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
548
+ if (!untrustedIsObject(untrustedConfig)) {
549
+ return null;
550
+ }
551
+ if (process.env.NODE_ENV !== 'production') {
552
+ validateConfig(untrustedConfig, configPropertyNames);
553
+ }
554
+ const config = typeCheckConfig(untrustedConfig);
555
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
556
+ return null;
557
+ }
558
+ return config;
559
+ }
560
+ function adapterFragment(luvio, config) {
561
+ createResourceParams(config);
562
+ return select();
563
+ }
564
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
565
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
566
+ config,
567
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
568
+ });
569
+ return luvio.storeBroadcast().then(() => snapshot);
570
+ }
571
+ function onFetchResponseError(luvio, config, resourceParams, response) {
572
+ const snapshot = ingestError(luvio, resourceParams, response, {
573
+ config,
574
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
575
+ });
576
+ return luvio.storeBroadcast().then(() => snapshot);
577
+ }
578
+ function buildNetworkSnapshot(luvio, config, options) {
579
+ const resourceParams = createResourceParams(config);
580
+ const request = createResourceRequest(resourceParams);
581
+ return luvio.dispatchResourceRequest(request, options)
582
+ .then((response) => {
583
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
584
+ }, (response) => {
585
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
586
+ });
587
+ }
588
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
589
+ const { luvio, config } = context;
590
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
591
+ const dispatchOptions = {
592
+ resourceRequestContext: {
593
+ requestCorrelator,
594
+ luvioRequestMethod: undefined,
595
+ },
596
+ eventObservers
597
+ };
598
+ if (networkPriority !== 'normal') {
599
+ dispatchOptions.overrides = {
600
+ priority: networkPriority
601
+ };
602
+ }
603
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
604
+ }
605
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
606
+ const { luvio, config } = context;
607
+ const selector = {
608
+ recordId: keyBuilder(luvio, config),
609
+ node: adapterFragment(luvio, config),
610
+ variables: {},
611
+ };
612
+ const cacheSnapshot = storeLookup(selector, {
613
+ config,
614
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
615
+ });
616
+ return cacheSnapshot;
617
+ }
618
+ const getObjectsForFeatureAdapterFactory = (luvio) => function dataloading__getObjectsForFeature(untrustedConfig, requestContext) {
619
+ const config = validateAdapterConfig(untrustedConfig, getObjectsForFeature_ConfigPropertyNames);
620
+ // Invalid or incomplete config
621
+ if (config === null) {
622
+ return null;
623
+ }
624
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
625
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
626
+ };
627
+
628
+ export { getCsvDataTemplateAdapterFactory, getObjectsForFeatureAdapterFactory };
@@ -0,0 +1,66 @@
1
+ import { Adapter as $64$luvio_engine_Adapter, Snapshot as $64$luvio_engine_Snapshot, UnfulfilledSnapshot as $64$luvio_engine_UnfulfilledSnapshot } from '@luvio/engine';
2
+ export declare const ObjectPrototypeHasOwnProperty: (v: PropertyKey) => boolean;
3
+ declare const ObjectKeys: {
4
+ (o: object): string[];
5
+ (o: {}): string[];
6
+ }, ObjectFreeze: {
7
+ <T extends Function>(f: T): T;
8
+ <T_1 extends {
9
+ [idx: string]: object | U | null | undefined;
10
+ }, U extends string | number | bigint | boolean | symbol>(o: T_1): Readonly<T_1>;
11
+ <T_2>(o: T_2): Readonly<T_2>;
12
+ }, ObjectCreate: {
13
+ (o: object | null): any;
14
+ (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
15
+ };
16
+ export { ObjectFreeze, ObjectCreate, ObjectKeys };
17
+ export declare const ArrayIsArray: (arg: any) => arg is any[];
18
+ export declare const ArrayPrototypePush: (...items: any[]) => number;
19
+ export interface AdapterValidationConfig {
20
+ displayName: string;
21
+ parameters: {
22
+ required: string[];
23
+ optional: string[];
24
+ unsupported?: string[];
25
+ };
26
+ }
27
+ /**
28
+ * Validates an adapter config is well-formed.
29
+ * @param config The config to validate.
30
+ * @param adapter The adapter validation configuration.
31
+ * @param oneOf The keys the config must contain at least one of.
32
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
33
+ */
34
+ export declare function validateConfig<T>(config: Untrusted<T>, adapter: AdapterValidationConfig, oneOf?: string[]): void;
35
+ export declare function untrustedIsObject<Base>(untrusted: unknown): untrusted is Untrusted<Base>;
36
+ export type UncoercedConfiguration<Base, Options extends {
37
+ [key in keyof Base]?: any;
38
+ }> = {
39
+ [Key in keyof Base]?: Base[Key] | Options[Key];
40
+ };
41
+ export type Untrusted<Base> = Partial<Base>;
42
+ export declare function areRequiredParametersPresent<T>(config: any, configPropertyNames: AdapterValidationConfig): config is T;
43
+ export declare function refreshable<C, D, R>(adapter: $64$luvio_engine_Adapter<C, D>, resolve: (config: unknown) => Promise<$64$luvio_engine_Snapshot<R>>): $64$luvio_engine_Adapter<C, D>;
44
+ export declare const SNAPSHOT_STATE_FULFILLED = "Fulfilled";
45
+ export declare const SNAPSHOT_STATE_UNFULFILLED = "Unfulfilled";
46
+ export declare const snapshotRefreshOptions: {
47
+ overrides: {
48
+ headers: {
49
+ 'Cache-Control': string;
50
+ };
51
+ };
52
+ };
53
+ /**
54
+ * A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
55
+ * This is needed because insertion order for JSON.stringify(object) affects output:
56
+ * JSON.stringify({a: 1, b: 2})
57
+ * "{"a":1,"b":2}"
58
+ * JSON.stringify({b: 2, a: 1})
59
+ * "{"b":2,"a":1}"
60
+ * @param data Data to be JSON-stringified.
61
+ * @returns JSON.stringified value with consistent ordering of keys.
62
+ */
63
+ export declare function stableJSONStringify(node: any): string | undefined;
64
+ export declare function getFetchResponseStatusText(status: number): string;
65
+ export declare function isUnfulfilledSnapshot<T, U>(snapshot: $64$luvio_engine_Snapshot<T, U>): snapshot is $64$luvio_engine_UnfulfilledSnapshot<T, U>;
66
+ export declare const keyPrefix = "dataloading";