@salesforce/lds-adapters-platform-data-provider 1.124.2 → 1.124.3

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.
@@ -6,336 +6,336 @@
6
6
 
7
7
  import { serializeStructuredKey, StoreKeyMap } from '@luvio/engine';
8
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
- };
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
51
  const keyPrefix = 'DataProviders';
52
52
 
53
- const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
54
- const { isArray: ArrayIsArray } = Array;
55
- const { stringify: JSONStringify } = JSON;
56
- function deepFreeze$1(value) {
57
- // No need to freeze primitives
58
- if (typeof value !== 'object' || value === null) {
59
- return;
60
- }
61
- if (ArrayIsArray(value)) {
62
- for (let i = 0, len = value.length; i < len; i += 1) {
63
- deepFreeze$1(value[i]);
64
- }
65
- }
66
- else {
67
- const keys = ObjectKeys(value);
68
- for (let i = 0, len = keys.length; i < len; i += 1) {
69
- deepFreeze$1(value[keys[i]]);
70
- }
71
- }
72
- ObjectFreeze(value);
73
- }
74
- function createLink(ref) {
75
- return {
76
- __ref: serializeStructuredKey(ref),
77
- };
53
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
54
+ const { isArray: ArrayIsArray } = Array;
55
+ const { stringify: JSONStringify } = JSON;
56
+ function deepFreeze$1(value) {
57
+ // No need to freeze primitives
58
+ if (typeof value !== 'object' || value === null) {
59
+ return;
60
+ }
61
+ if (ArrayIsArray(value)) {
62
+ for (let i = 0, len = value.length; i < len; i += 1) {
63
+ deepFreeze$1(value[i]);
64
+ }
65
+ }
66
+ else {
67
+ const keys = ObjectKeys(value);
68
+ for (let i = 0, len = keys.length; i < len; i += 1) {
69
+ deepFreeze$1(value[keys[i]]);
70
+ }
71
+ }
72
+ ObjectFreeze(value);
73
+ }
74
+ function createLink(ref) {
75
+ return {
76
+ __ref: serializeStructuredKey(ref),
77
+ };
78
78
  }
79
79
 
80
- const TTL = 3600000;
81
- const VERSION = "fa63b622a17d190f6bafa7967153c8be";
82
- function validate(obj, path = 'DataProviderSchemaRepresentation') {
83
- const v_error = (() => {
84
- if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
85
- return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
86
- }
87
- const obj_schema = obj.schema;
88
- const path_schema = path + '.schema';
89
- if (typeof obj_schema !== 'object' || ArrayIsArray(obj_schema) || obj_schema === null) {
90
- return new TypeError('Expected "object" but received "' + typeof obj_schema + '" (at "' + path_schema + '")');
91
- }
92
- const obj_schema_keys = ObjectKeys(obj_schema);
93
- for (let i = 0; i < obj_schema_keys.length; i++) {
94
- const key = obj_schema_keys[i];
95
- const obj_schema_prop = obj_schema[key];
96
- const path_schema_prop = path_schema + '["' + key + '"]';
97
- if (obj_schema_prop === undefined) {
98
- return new TypeError('Expected "defined" but received "' + typeof obj_schema_prop + '" (at "' + path_schema_prop + '")');
99
- }
100
- }
101
- })();
102
- return v_error === undefined ? null : v_error;
103
- }
104
- const RepresentationType = 'DataProviderSchemaRepresentation';
105
- function normalize(input, existing, path, luvio, store, timestamp) {
106
- return input;
107
- }
108
- const select$1 = function DataProviderSchemaRepresentationSelect() {
109
- return {
110
- kind: 'Fragment',
111
- version: VERSION,
112
- private: [],
113
- opaque: true
114
- };
115
- };
116
- function equals(existing, incoming) {
117
- if (JSONStringify(incoming) !== JSONStringify(existing)) {
118
- return false;
119
- }
120
- return true;
121
- }
122
- function deepFreeze(input) {
123
- const input_schema = input.schema;
124
- const input_schema_keys = Object.keys(input_schema);
125
- const input_schema_length = input_schema_keys.length;
126
- for (let i = 0; i < input_schema_length; i++) {
127
- const key = input_schema_keys[i];
128
- const input_schema_prop = input_schema[key];
129
- deepFreeze$1(input_schema_prop);
130
- }
131
- ObjectFreeze(input_schema);
132
- ObjectFreeze(input);
133
- }
134
- const ingest = function DataProviderSchemaRepresentationIngest(input, path, luvio, store, timestamp) {
135
- if (process.env.NODE_ENV !== 'production') {
136
- const validateError = validate(input);
137
- if (validateError !== null) {
138
- throw validateError;
139
- }
140
- }
141
- const key = path.fullPath;
142
- const existingRecord = store.readEntry(key);
143
- const ttlToUse = TTL;
144
- let incomingRecord = normalize(input, store.readEntry(key), {
145
- fullPath: key,
146
- parent: path.parent,
147
- propertyName: path.propertyName,
148
- ttl: ttlToUse
149
- });
150
- deepFreeze(input);
151
- if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
152
- luvio.storePublish(key, incomingRecord);
153
- }
154
- {
155
- const storeMetadataParams = {
156
- ttl: ttlToUse,
157
- namespace: "DataProviders",
158
- version: VERSION,
159
- representationName: RepresentationType,
160
- };
161
- luvio.publishStoreMetadata(key, storeMetadataParams);
162
- }
163
- return createLink(key);
164
- };
165
- function getTypeCacheKeys(luvio, input, fullPathFactory) {
166
- const rootKeySet = new StoreKeyMap();
167
- // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
168
- const rootKey = fullPathFactory();
169
- rootKeySet.set(rootKey, {
170
- namespace: keyPrefix,
171
- representationName: RepresentationType,
172
- mergeable: false
173
- });
174
- return rootKeySet;
80
+ const TTL = 3600000;
81
+ const VERSION = "fa63b622a17d190f6bafa7967153c8be";
82
+ function validate(obj, path = 'DataProviderSchemaRepresentation') {
83
+ const v_error = (() => {
84
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
85
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
86
+ }
87
+ const obj_schema = obj.schema;
88
+ const path_schema = path + '.schema';
89
+ if (typeof obj_schema !== 'object' || ArrayIsArray(obj_schema) || obj_schema === null) {
90
+ return new TypeError('Expected "object" but received "' + typeof obj_schema + '" (at "' + path_schema + '")');
91
+ }
92
+ const obj_schema_keys = ObjectKeys(obj_schema);
93
+ for (let i = 0; i < obj_schema_keys.length; i++) {
94
+ const key = obj_schema_keys[i];
95
+ const obj_schema_prop = obj_schema[key];
96
+ const path_schema_prop = path_schema + '["' + key + '"]';
97
+ if (obj_schema_prop === undefined) {
98
+ return new TypeError('Expected "defined" but received "' + typeof obj_schema_prop + '" (at "' + path_schema_prop + '")');
99
+ }
100
+ }
101
+ })();
102
+ return v_error === undefined ? null : v_error;
103
+ }
104
+ const RepresentationType = 'DataProviderSchemaRepresentation';
105
+ function normalize(input, existing, path, luvio, store, timestamp) {
106
+ return input;
107
+ }
108
+ const select$1 = function DataProviderSchemaRepresentationSelect() {
109
+ return {
110
+ kind: 'Fragment',
111
+ version: VERSION,
112
+ private: [],
113
+ opaque: true
114
+ };
115
+ };
116
+ function equals(existing, incoming) {
117
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
118
+ return false;
119
+ }
120
+ return true;
121
+ }
122
+ function deepFreeze(input) {
123
+ const input_schema = input.schema;
124
+ const input_schema_keys = Object.keys(input_schema);
125
+ const input_schema_length = input_schema_keys.length;
126
+ for (let i = 0; i < input_schema_length; i++) {
127
+ const key = input_schema_keys[i];
128
+ const input_schema_prop = input_schema[key];
129
+ deepFreeze$1(input_schema_prop);
130
+ }
131
+ ObjectFreeze(input_schema);
132
+ ObjectFreeze(input);
133
+ }
134
+ const ingest = function DataProviderSchemaRepresentationIngest(input, path, luvio, store, timestamp) {
135
+ if (process.env.NODE_ENV !== 'production') {
136
+ const validateError = validate(input);
137
+ if (validateError !== null) {
138
+ throw validateError;
139
+ }
140
+ }
141
+ const key = path.fullPath;
142
+ const existingRecord = store.readEntry(key);
143
+ const ttlToUse = TTL;
144
+ let incomingRecord = normalize(input, store.readEntry(key), {
145
+ fullPath: key,
146
+ parent: path.parent,
147
+ propertyName: path.propertyName,
148
+ ttl: ttlToUse
149
+ });
150
+ deepFreeze(input);
151
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
152
+ luvio.storePublish(key, incomingRecord);
153
+ }
154
+ {
155
+ const storeMetadataParams = {
156
+ ttl: ttlToUse,
157
+ namespace: "DataProviders",
158
+ version: VERSION,
159
+ representationName: RepresentationType,
160
+ };
161
+ luvio.publishStoreMetadata(key, storeMetadataParams);
162
+ }
163
+ return createLink(key);
164
+ };
165
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
166
+ const rootKeySet = new StoreKeyMap();
167
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
168
+ const rootKey = fullPathFactory();
169
+ rootKeySet.set(rootKey, {
170
+ namespace: keyPrefix,
171
+ representationName: RepresentationType,
172
+ mergeable: false
173
+ });
174
+ return rootKeySet;
175
175
  }
176
176
 
177
- function select(luvio, params) {
178
- return select$1();
179
- }
180
- function keyBuilder$1(luvio, params) {
181
- return keyPrefix + '::DataProviderSchemaRepresentation:(' + 'dataProviderFullyQualifiedName:' + params.urlParams.dataProviderFullyQualifiedName + ',' + 'schema:' + params.body.schema + ')';
182
- }
183
- function getResponseCacheKeys(luvio, resourceParams, response) {
184
- return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
185
- }
186
- function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
187
- const { body } = response;
188
- const key = keyBuilder$1(luvio, resourceParams);
189
- luvio.storeIngest(key, ingest, body);
190
- const snapshot = luvio.storeLookup({
191
- recordId: key,
192
- node: select(),
193
- variables: {},
194
- }, snapshotRefresh);
195
- if (process.env.NODE_ENV !== 'production') {
196
- if (snapshot.state !== 'Fulfilled') {
197
- throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
198
- }
199
- }
200
- return snapshot;
201
- }
202
- function ingestError(luvio, params, error, snapshotRefresh) {
203
- const key = keyBuilder$1(luvio, params);
204
- const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
205
- const storeMetadataParams = {
206
- ttl: TTL,
207
- namespace: keyPrefix,
208
- version: VERSION,
209
- representationName: RepresentationType
210
- };
211
- luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
212
- return errorSnapshot;
213
- }
214
- function createResourceRequest(config) {
215
- const headers = {};
216
- return {
217
- baseUri: '/services/data/v58.0',
218
- basePath: '/connect/data-providers/' + config.urlParams.dataProviderFullyQualifiedName + '/schema',
219
- method: 'post',
220
- body: config.body,
221
- urlParams: config.urlParams,
222
- queryParams: {},
223
- headers,
224
- priority: 'normal',
225
- };
177
+ function select(luvio, params) {
178
+ return select$1();
179
+ }
180
+ function keyBuilder$1(luvio, params) {
181
+ return keyPrefix + '::DataProviderSchemaRepresentation:(' + 'dataProviderFullyQualifiedName:' + params.urlParams.dataProviderFullyQualifiedName + ',' + 'schema:' + params.body.schema + ')';
182
+ }
183
+ function getResponseCacheKeys(luvio, resourceParams, response) {
184
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
185
+ }
186
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
187
+ const { body } = response;
188
+ const key = keyBuilder$1(luvio, resourceParams);
189
+ luvio.storeIngest(key, ingest, body);
190
+ const snapshot = luvio.storeLookup({
191
+ recordId: key,
192
+ node: select(),
193
+ variables: {},
194
+ }, snapshotRefresh);
195
+ if (process.env.NODE_ENV !== 'production') {
196
+ if (snapshot.state !== 'Fulfilled') {
197
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
198
+ }
199
+ }
200
+ return snapshot;
201
+ }
202
+ function ingestError(luvio, params, error, snapshotRefresh) {
203
+ const key = keyBuilder$1(luvio, params);
204
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
205
+ const storeMetadataParams = {
206
+ ttl: TTL,
207
+ namespace: keyPrefix,
208
+ version: VERSION,
209
+ representationName: RepresentationType
210
+ };
211
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
212
+ return errorSnapshot;
213
+ }
214
+ function createResourceRequest(config) {
215
+ const headers = {};
216
+ return {
217
+ baseUri: '/services/data/v58.0',
218
+ basePath: '/connect/data-providers/' + config.urlParams.dataProviderFullyQualifiedName + '/schema',
219
+ method: 'post',
220
+ body: config.body,
221
+ urlParams: config.urlParams,
222
+ queryParams: {},
223
+ headers,
224
+ priority: 'normal',
225
+ };
226
226
  }
227
227
 
228
- const getSchema_ConfigPropertyNames = {
229
- displayName: 'getSchema',
230
- parameters: {
231
- required: ['dataProviderFullyQualifiedName', 'schema'],
232
- optional: []
233
- }
234
- };
235
- function createResourceParams(config) {
236
- const resourceParams = {
237
- urlParams: {
238
- dataProviderFullyQualifiedName: config.dataProviderFullyQualifiedName
239
- },
240
- body: {
241
- schema: config.schema
242
- }
243
- };
244
- return resourceParams;
245
- }
246
- function keyBuilder(luvio, config) {
247
- const resourceParams = createResourceParams(config);
248
- return keyBuilder$1(luvio, resourceParams);
249
- }
250
- function typeCheckConfig(untrustedConfig) {
251
- const config = {};
252
- const untrustedConfig_dataProviderFullyQualifiedName = untrustedConfig.dataProviderFullyQualifiedName;
253
- if (typeof untrustedConfig_dataProviderFullyQualifiedName === 'string') {
254
- config.dataProviderFullyQualifiedName = untrustedConfig_dataProviderFullyQualifiedName;
255
- }
256
- const untrustedConfig_schema = untrustedConfig.schema;
257
- config.schema = untrustedConfig_schema;
258
- return config;
259
- }
260
- function validateAdapterConfig(untrustedConfig, configPropertyNames) {
261
- if (!untrustedIsObject(untrustedConfig)) {
262
- return null;
263
- }
264
- if (process.env.NODE_ENV !== 'production') {
265
- validateConfig(untrustedConfig, configPropertyNames);
266
- }
267
- const config = typeCheckConfig(untrustedConfig);
268
- if (!areRequiredParametersPresent(config, configPropertyNames)) {
269
- return null;
270
- }
271
- return config;
272
- }
273
- function adapterFragment(luvio, config) {
274
- createResourceParams(config);
275
- return select();
276
- }
277
- function onFetchResponseSuccess(luvio, config, resourceParams, response) {
278
- const snapshot = ingestSuccess(luvio, resourceParams, response, {
279
- config,
280
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
281
- });
282
- return luvio.storeBroadcast().then(() => snapshot);
283
- }
284
- function onFetchResponseError(luvio, config, resourceParams, response) {
285
- const snapshot = ingestError(luvio, resourceParams, response, {
286
- config,
287
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
288
- });
289
- return luvio.storeBroadcast().then(() => snapshot);
290
- }
291
- function buildNetworkSnapshot(luvio, config, options) {
292
- const resourceParams = createResourceParams(config);
293
- const request = createResourceRequest(resourceParams);
294
- return luvio.dispatchResourceRequest(request, options)
295
- .then((response) => {
296
- return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
297
- }, (response) => {
298
- return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
299
- });
300
- }
301
- function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
302
- const { luvio, config } = context;
303
- const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
304
- const dispatchOptions = {
305
- resourceRequestContext: {
306
- requestCorrelator,
307
- luvioRequestMethod: 'get',
308
- },
309
- eventObservers
310
- };
311
- if (networkPriority !== 'normal') {
312
- dispatchOptions.overrides = {
313
- priority: networkPriority
314
- };
315
- }
316
- return buildNetworkSnapshot(luvio, config, dispatchOptions);
317
- }
318
- function buildCachedSnapshotCachePolicy(context, storeLookup) {
319
- const { luvio, config } = context;
320
- const selector = {
321
- recordId: keyBuilder(luvio, config),
322
- node: adapterFragment(luvio, config),
323
- variables: {},
324
- };
325
- const cacheSnapshot = storeLookup(selector, {
326
- config,
327
- resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
328
- });
329
- return cacheSnapshot;
330
- }
331
- const getSchemaAdapterFactory = (luvio) => function DataProviders__getSchema(untrustedConfig, requestContext) {
332
- const config = validateAdapterConfig(untrustedConfig, getSchema_ConfigPropertyNames);
333
- // Invalid or incomplete config
334
- if (config === null) {
335
- return null;
336
- }
337
- return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
338
- buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
228
+ const getSchema_ConfigPropertyNames = {
229
+ displayName: 'getSchema',
230
+ parameters: {
231
+ required: ['dataProviderFullyQualifiedName', 'schema'],
232
+ optional: []
233
+ }
234
+ };
235
+ function createResourceParams(config) {
236
+ const resourceParams = {
237
+ urlParams: {
238
+ dataProviderFullyQualifiedName: config.dataProviderFullyQualifiedName
239
+ },
240
+ body: {
241
+ schema: config.schema
242
+ }
243
+ };
244
+ return resourceParams;
245
+ }
246
+ function keyBuilder(luvio, config) {
247
+ const resourceParams = createResourceParams(config);
248
+ return keyBuilder$1(luvio, resourceParams);
249
+ }
250
+ function typeCheckConfig(untrustedConfig) {
251
+ const config = {};
252
+ const untrustedConfig_dataProviderFullyQualifiedName = untrustedConfig.dataProviderFullyQualifiedName;
253
+ if (typeof untrustedConfig_dataProviderFullyQualifiedName === 'string') {
254
+ config.dataProviderFullyQualifiedName = untrustedConfig_dataProviderFullyQualifiedName;
255
+ }
256
+ const untrustedConfig_schema = untrustedConfig.schema;
257
+ config.schema = untrustedConfig_schema;
258
+ return config;
259
+ }
260
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
261
+ if (!untrustedIsObject(untrustedConfig)) {
262
+ return null;
263
+ }
264
+ if (process.env.NODE_ENV !== 'production') {
265
+ validateConfig(untrustedConfig, configPropertyNames);
266
+ }
267
+ const config = typeCheckConfig(untrustedConfig);
268
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
269
+ return null;
270
+ }
271
+ return config;
272
+ }
273
+ function adapterFragment(luvio, config) {
274
+ createResourceParams(config);
275
+ return select();
276
+ }
277
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
278
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
279
+ config,
280
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
281
+ });
282
+ return luvio.storeBroadcast().then(() => snapshot);
283
+ }
284
+ function onFetchResponseError(luvio, config, resourceParams, response) {
285
+ const snapshot = ingestError(luvio, resourceParams, response, {
286
+ config,
287
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
288
+ });
289
+ return luvio.storeBroadcast().then(() => snapshot);
290
+ }
291
+ function buildNetworkSnapshot(luvio, config, options) {
292
+ const resourceParams = createResourceParams(config);
293
+ const request = createResourceRequest(resourceParams);
294
+ return luvio.dispatchResourceRequest(request, options)
295
+ .then((response) => {
296
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
297
+ }, (response) => {
298
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
299
+ });
300
+ }
301
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
302
+ const { luvio, config } = context;
303
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
304
+ const dispatchOptions = {
305
+ resourceRequestContext: {
306
+ requestCorrelator,
307
+ luvioRequestMethod: 'get',
308
+ },
309
+ eventObservers
310
+ };
311
+ if (networkPriority !== 'normal') {
312
+ dispatchOptions.overrides = {
313
+ priority: networkPriority
314
+ };
315
+ }
316
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
317
+ }
318
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
319
+ const { luvio, config } = context;
320
+ const selector = {
321
+ recordId: keyBuilder(luvio, config),
322
+ node: adapterFragment(luvio, config),
323
+ variables: {},
324
+ };
325
+ const cacheSnapshot = storeLookup(selector, {
326
+ config,
327
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
328
+ });
329
+ return cacheSnapshot;
330
+ }
331
+ const getSchemaAdapterFactory = (luvio) => function DataProviders__getSchema(untrustedConfig, requestContext) {
332
+ const config = validateAdapterConfig(untrustedConfig, getSchema_ConfigPropertyNames);
333
+ // Invalid or incomplete config
334
+ if (config === null) {
335
+ return null;
336
+ }
337
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
338
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
339
339
  };
340
340
 
341
341
  export { getSchemaAdapterFactory };