@salesforce/lds-adapters-platform-data-provider 1.100.2

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,352 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@luvio/engine')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', '@luvio/engine'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.platformDataProvider = {}, global.engine));
11
+ })(this, (function (exports, engine) { 'use strict';
12
+
13
+ var ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
14
+ var ObjectKeys$1 = Object.keys;
15
+ var ArrayIsArray$1 = Array.isArray;
16
+ /**
17
+ * Validates an adapter config is well-formed.
18
+ * @param config The config to validate.
19
+ * @param adapter The adapter validation configuration.
20
+ * @param oneOf The keys the config must contain at least one of.
21
+ * @throws A TypeError if config doesn't satisfy the adapter's config validation.
22
+ */
23
+ function validateConfig(config, adapter, oneOf) {
24
+ var displayName = adapter.displayName;
25
+ var _a = adapter.parameters, required = _a.required, optional = _a.optional, unsupported = _a.unsupported;
26
+ if (config === undefined ||
27
+ required.every(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
28
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify ").concat(required.sort().join(', ')));
29
+ }
30
+ if (oneOf && oneOf.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); }) === false) {
31
+ throw new TypeError("adapter ".concat(displayName, " configuration must specify one of ").concat(oneOf.sort().join(', ')));
32
+ }
33
+ if (unsupported !== undefined &&
34
+ unsupported.some(function (req) { return ObjectPrototypeHasOwnProperty.call(config, req); })) {
35
+ throw new TypeError("adapter ".concat(displayName, " does not yet support ").concat(unsupported.sort().join(', ')));
36
+ }
37
+ var supported = required.concat(optional);
38
+ if (ObjectKeys$1(config).some(function (key) { return !supported.includes(key); })) {
39
+ throw new TypeError("adapter ".concat(displayName, " configuration supports only ").concat(supported.sort().join(', ')));
40
+ }
41
+ }
42
+ function untrustedIsObject(untrusted) {
43
+ return typeof untrusted === 'object' && untrusted !== null && ArrayIsArray$1(untrusted) === false;
44
+ }
45
+ function areRequiredParametersPresent(config, configPropertyNames) {
46
+ return configPropertyNames.parameters.required.every(function (req) { return req in config; });
47
+ }
48
+ var snapshotRefreshOptions = {
49
+ overrides: {
50
+ headers: {
51
+ 'Cache-Control': 'no-cache',
52
+ },
53
+ }
54
+ };
55
+ var keyPrefix = 'DataProviders';
56
+
57
+ var ObjectFreeze = Object.freeze, ObjectKeys = Object.keys;
58
+ var ArrayIsArray = Array.isArray;
59
+ var JSONStringify = JSON.stringify;
60
+ function deepFreeze$1(value) {
61
+ // No need to freeze primitives
62
+ if (typeof value !== 'object' || value === null) {
63
+ return;
64
+ }
65
+ if (ArrayIsArray(value)) {
66
+ for (var i = 0, len = value.length; i < len; i += 1) {
67
+ deepFreeze$1(value[i]);
68
+ }
69
+ }
70
+ else {
71
+ var keys = ObjectKeys(value);
72
+ for (var i = 0, len = keys.length; i < len; i += 1) {
73
+ deepFreeze$1(value[keys[i]]);
74
+ }
75
+ }
76
+ ObjectFreeze(value);
77
+ }
78
+ function createLink(ref) {
79
+ return {
80
+ __ref: engine.serializeStructuredKey(ref),
81
+ };
82
+ }
83
+
84
+ var TTL = 3600000;
85
+ var VERSION = "fa63b622a17d190f6bafa7967153c8be";
86
+ function validate(obj, path) {
87
+ if (path === void 0) { path = 'DataProviderSchemaRepresentation'; }
88
+ var v_error = (function () {
89
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
90
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
91
+ }
92
+ var obj_schema = obj.schema;
93
+ var path_schema = path + '.schema';
94
+ if (typeof obj_schema !== 'object' || ArrayIsArray(obj_schema) || obj_schema === null) {
95
+ return new TypeError('Expected "object" but received "' + typeof obj_schema + '" (at "' + path_schema + '")');
96
+ }
97
+ var obj_schema_keys = ObjectKeys(obj_schema);
98
+ for (var i = 0; i < obj_schema_keys.length; i++) {
99
+ var key = obj_schema_keys[i];
100
+ var obj_schema_prop = obj_schema[key];
101
+ var path_schema_prop = path_schema + '["' + key + '"]';
102
+ if (obj_schema_prop === undefined) {
103
+ return new TypeError('Expected "defined" but received "' + typeof obj_schema_prop + '" (at "' + path_schema_prop + '")');
104
+ }
105
+ }
106
+ })();
107
+ return v_error === undefined ? null : v_error;
108
+ }
109
+ var RepresentationType = 'DataProviderSchemaRepresentation';
110
+ function normalize(input, existing, path, luvio, store, timestamp) {
111
+ return input;
112
+ }
113
+ var select$1 = function DataProviderSchemaRepresentationSelect() {
114
+ return {
115
+ kind: 'Fragment',
116
+ version: VERSION,
117
+ private: [],
118
+ opaque: true
119
+ };
120
+ };
121
+ function equals(existing, incoming) {
122
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
123
+ return false;
124
+ }
125
+ return true;
126
+ }
127
+ function deepFreeze(input) {
128
+ var input_schema = input.schema;
129
+ var input_schema_keys = Object.keys(input_schema);
130
+ var input_schema_length = input_schema_keys.length;
131
+ for (var i = 0; i < input_schema_length; i++) {
132
+ var key = input_schema_keys[i];
133
+ var input_schema_prop = input_schema[key];
134
+ deepFreeze$1(input_schema_prop);
135
+ }
136
+ ObjectFreeze(input_schema);
137
+ ObjectFreeze(input);
138
+ }
139
+ var ingest = function DataProviderSchemaRepresentationIngest(input, path, luvio, store, timestamp) {
140
+ if (process.env.NODE_ENV !== 'production') {
141
+ var validateError = validate(input);
142
+ if (validateError !== null) {
143
+ throw validateError;
144
+ }
145
+ }
146
+ var key = path.fullPath;
147
+ var existingRecord = store.readEntry(key);
148
+ var ttlToUse = TTL;
149
+ var incomingRecord = normalize(input, store.readEntry(key), {
150
+ fullPath: key,
151
+ parent: path.parent,
152
+ propertyName: path.propertyName,
153
+ ttl: ttlToUse
154
+ });
155
+ deepFreeze(input);
156
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
157
+ luvio.storePublish(key, incomingRecord);
158
+ }
159
+ {
160
+ var storeMetadataParams = {
161
+ ttl: ttlToUse,
162
+ namespace: "DataProviders",
163
+ version: VERSION,
164
+ representationName: RepresentationType,
165
+ };
166
+ luvio.publishStoreMetadata(key, storeMetadataParams);
167
+ }
168
+ return createLink(key);
169
+ };
170
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
171
+ var rootKeySet = new engine.StoreKeyMap();
172
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
173
+ var rootKey = fullPathFactory();
174
+ rootKeySet.set(rootKey, {
175
+ namespace: keyPrefix,
176
+ representationName: RepresentationType,
177
+ mergeable: false
178
+ });
179
+ return rootKeySet;
180
+ }
181
+
182
+ function select(luvio, params) {
183
+ return select$1();
184
+ }
185
+ function keyBuilder$1(luvio, params) {
186
+ return keyPrefix + '::DataProviderSchemaRepresentation:(' + 'config:' + params.queryParams.config + ',' + 'dataProviderFQN:' + params.urlParams.dataProviderFQN + ')';
187
+ }
188
+ function getResponseCacheKeys(luvio, resourceParams, response) {
189
+ return getTypeCacheKeys(luvio, response, function () { return keyBuilder$1(luvio, resourceParams); });
190
+ }
191
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
192
+ var body = response.body;
193
+ var key = keyBuilder$1(luvio, resourceParams);
194
+ luvio.storeIngest(key, ingest, body);
195
+ var snapshot = luvio.storeLookup({
196
+ recordId: key,
197
+ node: select(),
198
+ variables: {},
199
+ }, snapshotRefresh);
200
+ if (process.env.NODE_ENV !== 'production') {
201
+ if (snapshot.state !== 'Fulfilled') {
202
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
203
+ }
204
+ }
205
+ return snapshot;
206
+ }
207
+ function ingestError(luvio, params, error, snapshotRefresh) {
208
+ var key = keyBuilder$1(luvio, params);
209
+ var errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
210
+ var storeMetadataParams = {
211
+ ttl: TTL,
212
+ namespace: keyPrefix,
213
+ version: VERSION,
214
+ representationName: RepresentationType
215
+ };
216
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
217
+ return errorSnapshot;
218
+ }
219
+ function createResourceRequest(config) {
220
+ var headers = {};
221
+ return {
222
+ baseUri: '/services/data/v58.0',
223
+ basePath: '/connect/data-providers/' + config.urlParams.dataProviderFQN + '/schema',
224
+ method: 'get',
225
+ body: null,
226
+ urlParams: config.urlParams,
227
+ queryParams: config.queryParams,
228
+ headers: headers,
229
+ priority: 'normal',
230
+ };
231
+ }
232
+
233
+ var getSchema_ConfigPropertyNames = {
234
+ displayName: 'getSchema',
235
+ parameters: {
236
+ required: ['dataProviderFQN'],
237
+ optional: ['config']
238
+ }
239
+ };
240
+ function createResourceParams(config) {
241
+ var resourceParams = {
242
+ urlParams: {
243
+ dataProviderFQN: config.dataProviderFQN
244
+ },
245
+ queryParams: {
246
+ config: config.config
247
+ }
248
+ };
249
+ return resourceParams;
250
+ }
251
+ function keyBuilder(luvio, config) {
252
+ var resourceParams = createResourceParams(config);
253
+ return keyBuilder$1(luvio, resourceParams);
254
+ }
255
+ function typeCheckConfig(untrustedConfig) {
256
+ var config = {};
257
+ var untrustedConfig_dataProviderFQN = untrustedConfig.dataProviderFQN;
258
+ if (typeof untrustedConfig_dataProviderFQN === 'string') {
259
+ config.dataProviderFQN = untrustedConfig_dataProviderFQN;
260
+ }
261
+ var untrustedConfig_config = untrustedConfig.config;
262
+ if (typeof untrustedConfig_config === 'string') {
263
+ config.config = untrustedConfig_config;
264
+ }
265
+ return config;
266
+ }
267
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
268
+ if (!untrustedIsObject(untrustedConfig)) {
269
+ return null;
270
+ }
271
+ if (process.env.NODE_ENV !== 'production') {
272
+ validateConfig(untrustedConfig, configPropertyNames);
273
+ }
274
+ var config = typeCheckConfig(untrustedConfig);
275
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
276
+ return null;
277
+ }
278
+ return config;
279
+ }
280
+ function adapterFragment(luvio, config) {
281
+ createResourceParams(config);
282
+ return select();
283
+ }
284
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
285
+ var snapshot = ingestSuccess(luvio, resourceParams, response, {
286
+ config: config,
287
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
288
+ });
289
+ return luvio.storeBroadcast().then(function () { return snapshot; });
290
+ }
291
+ function onFetchResponseError(luvio, config, resourceParams, response) {
292
+ var snapshot = ingestError(luvio, resourceParams, response, {
293
+ config: config,
294
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
295
+ });
296
+ return luvio.storeBroadcast().then(function () { return snapshot; });
297
+ }
298
+ function buildNetworkSnapshot(luvio, config, options) {
299
+ var resourceParams = createResourceParams(config);
300
+ var request = createResourceRequest(resourceParams);
301
+ return luvio.dispatchResourceRequest(request, options)
302
+ .then(function (response) {
303
+ return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resourceParams, response); }, function () { return getResponseCacheKeys(luvio, resourceParams, response.body); });
304
+ }, function (response) {
305
+ return luvio.handleErrorResponse(function () { return onFetchResponseError(luvio, config, resourceParams, response); });
306
+ });
307
+ }
308
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
309
+ var luvio = context.luvio, config = context.config;
310
+ var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
311
+ var dispatchOptions = {
312
+ resourceRequestContext: {
313
+ requestCorrelator: requestCorrelator,
314
+ luvioRequestMethod: undefined,
315
+ },
316
+ eventObservers: eventObservers
317
+ };
318
+ if (networkPriority !== 'normal') {
319
+ dispatchOptions.overrides = {
320
+ priority: networkPriority
321
+ };
322
+ }
323
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
324
+ }
325
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
326
+ var luvio = context.luvio, config = context.config;
327
+ var selector = {
328
+ recordId: keyBuilder(luvio, config),
329
+ node: adapterFragment(luvio, config),
330
+ variables: {},
331
+ };
332
+ var cacheSnapshot = storeLookup(selector, {
333
+ config: config,
334
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
335
+ });
336
+ return cacheSnapshot;
337
+ }
338
+ var getSchemaAdapterFactory = function (luvio) { return function DataProviders__getSchema(untrustedConfig, requestContext) {
339
+ var config = validateAdapterConfig(untrustedConfig, getSchema_ConfigPropertyNames);
340
+ // Invalid or incomplete config
341
+ if (config === null) {
342
+ return null;
343
+ }
344
+ return luvio.applyCachePolicy((requestContext || {}), { config: config, luvio: luvio }, // BuildSnapshotContext
345
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
346
+ }; };
347
+
348
+ exports.getSchemaAdapterFactory = getSchemaAdapterFactory;
349
+
350
+ Object.defineProperty(exports, '__esModule', { value: true });
351
+
352
+ }));
package/package.json ADDED
@@ -0,0 +1,64 @@
1
+ {
2
+ "name": "@salesforce/lds-adapters-platform-data-provider",
3
+ "version": "1.100.2",
4
+ "description": "Data Provider connect api resource family",
5
+ "license": "SEE LICENSE IN LICENSE.txt",
6
+ "main": "dist/umd/es2018/platform-data-provider.js",
7
+ "module": "dist/es/es2018/platform-data-provider.js",
8
+ "types": "dist/types/src/generated/artifacts/main.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "sfdc",
12
+ "src/raml/*"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "import": "./dist/es/es2018/platform-data-provider.js",
17
+ "require": "./dist/umd/es2018/platform-data-provider.js",
18
+ "types": "./dist/types/src/generated/artifacts/main.d.ts"
19
+ },
20
+ "./sfdc": {
21
+ "import": "./sfdc/index.js",
22
+ "types": "./sfdc/index.d.ts",
23
+ "default": "./sfdc/index.js"
24
+ }
25
+ },
26
+ "contributors": [
27
+ "t.garg@salesforce.com"
28
+ ],
29
+ "scripts": {
30
+ "build": "yarn build:raml && yarn build:services && yarn build:karma",
31
+ "build:karma": "rollup --config rollup.config.karma.js",
32
+ "build:raml": "luvio generate src/raml/luvio.raml src/generated -p '../lds-compiler-plugins'",
33
+ "build:services": "rollup --config rollup.config.js",
34
+ "clean": "rm -rf dist sfdc src/generated karma/dist",
35
+ "release:core": "../../scripts/release/core.js --adapter=lds-adapters-platform-data-provider",
36
+ "release:corejar": "yarn build && ../core-build/scripts/core.js --adapter=lds-adapters-platform-data-provider",
37
+ "start": "karma start",
38
+ "test": "karma start --single-run",
39
+ "test:compat": "karma start --single-run --compat",
40
+ "test:unit": "jest"
41
+ },
42
+ "dependencies": {
43
+ "@salesforce/lds-bindings": "^1.100.2"
44
+ },
45
+ "devDependencies": {
46
+ "@luvio/cli": "0.135.4",
47
+ "@luvio/compiler": "0.135.4",
48
+ "@luvio/engine": "0.135.4",
49
+ "@luvio/lwc-luvio": "0.135.4",
50
+ "@salesforce/lds-karma": "^1.100.2"
51
+ },
52
+ "nx": {
53
+ "targets": {
54
+ "build": {
55
+ "outputs": [
56
+ "packages/lds-adapters-platform-data-provider/dist",
57
+ "packages/lds-adapters-platform-data-provider/karma/dist",
58
+ "packages/lds-adapters-platform-data-provider/sfdc",
59
+ "packages/lds-adapters-platform-data-provider/src/generated"
60
+ ]
61
+ }
62
+ }
63
+ }
64
+ }
@@ -0,0 +1 @@
1
+ export * from '../dist/types/src/generated/artifacts/sfdc';