@salesforce/lds-adapters-analytics-wave-private 1.100.1

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,370 @@
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.analyticsWavePrivate = {}, 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 = 'WAVE';
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 = 5000;
85
+ var VERSION = "f4d046d44230e53375ee20bbd2483a1f";
86
+ function validate(obj, path) {
87
+ if (path === void 0) { path = 'SoqlQueryResultRepresentation'; }
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_keys = ObjectKeys(obj);
93
+ for (var i = 0; i < obj_keys.length; i++) {
94
+ var key = obj_keys[i];
95
+ var obj_prop = obj[key];
96
+ var path_prop = path + '["' + key + '"]';
97
+ if (obj_prop === undefined) {
98
+ return new TypeError('Expected "defined" but received "' + typeof obj_prop + '" (at "' + path_prop + '")');
99
+ }
100
+ }
101
+ if (obj.done !== undefined) {
102
+ var obj_done = obj.done;
103
+ var path_done = path + '.done';
104
+ if (typeof obj_done !== 'boolean') {
105
+ return new TypeError('Expected "boolean" but received "' + typeof obj_done + '" (at "' + path_done + '")');
106
+ }
107
+ }
108
+ var obj_records = obj.records;
109
+ var path_records = path + '.records';
110
+ if (!ArrayIsArray(obj_records)) {
111
+ return new TypeError('Expected "array" but received "' + typeof obj_records + '" (at "' + path_records + '")');
112
+ }
113
+ for (var i = 0; i < obj_records.length; i++) {
114
+ var obj_records_item = obj_records[i];
115
+ var path_records_item = path_records + '[' + i + ']';
116
+ if (obj_records_item === undefined) {
117
+ return new TypeError('Expected "defined" but received "' + typeof obj_records_item + '" (at "' + path_records_item + '")');
118
+ }
119
+ }
120
+ if (obj.totalSize !== undefined) {
121
+ var obj_totalSize = obj.totalSize;
122
+ var path_totalSize = path + '.totalSize';
123
+ if (typeof obj_totalSize !== 'number') {
124
+ return new TypeError('Expected "number" but received "' + typeof obj_totalSize + '" (at "' + path_totalSize + '")');
125
+ }
126
+ }
127
+ })();
128
+ return v_error === undefined ? null : v_error;
129
+ }
130
+ var RepresentationType = 'SoqlQueryResultRepresentation';
131
+ function normalize(input, existing, path, luvio, store, timestamp) {
132
+ return input;
133
+ }
134
+ var select$1 = function SoqlQueryResultRepresentationSelect() {
135
+ return {
136
+ kind: 'Fragment',
137
+ version: VERSION,
138
+ private: [],
139
+ opaque: true
140
+ };
141
+ };
142
+ function equals(existing, incoming) {
143
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
144
+ return false;
145
+ }
146
+ return true;
147
+ }
148
+ function deepFreeze(input) {
149
+ var input_keys = Object.keys(input);
150
+ var input_length = input_keys.length;
151
+ for (var i = 0; i < input_length; i++) {
152
+ var key = input_keys[i];
153
+ var input_prop = input[key];
154
+ deepFreeze$1(input_prop);
155
+ }
156
+ var input_records = input.records;
157
+ for (var i = 0; i < input_records.length; i++) {
158
+ var input_records_item = input_records[i];
159
+ deepFreeze$1(input_records_item);
160
+ }
161
+ ObjectFreeze(input_records);
162
+ ObjectFreeze(input);
163
+ }
164
+ var ingest = function SoqlQueryResultRepresentationIngest(input, path, luvio, store, timestamp) {
165
+ if (process.env.NODE_ENV !== 'production') {
166
+ var validateError = validate(input);
167
+ if (validateError !== null) {
168
+ throw validateError;
169
+ }
170
+ }
171
+ var key = path.fullPath;
172
+ var existingRecord = store.readEntry(key);
173
+ var ttlToUse = TTL;
174
+ var incomingRecord = normalize(input, store.readEntry(key), {
175
+ fullPath: key,
176
+ parent: path.parent,
177
+ propertyName: path.propertyName,
178
+ ttl: ttlToUse
179
+ });
180
+ deepFreeze(input);
181
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
182
+ luvio.storePublish(key, incomingRecord);
183
+ }
184
+ {
185
+ var storeMetadataParams = {
186
+ ttl: ttlToUse,
187
+ namespace: "WAVE",
188
+ version: VERSION,
189
+ representationName: RepresentationType,
190
+ };
191
+ luvio.publishStoreMetadata(key, storeMetadataParams);
192
+ }
193
+ return createLink(key);
194
+ };
195
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
196
+ var rootKeySet = new engine.StoreKeyMap();
197
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
198
+ var rootKey = fullPathFactory();
199
+ rootKeySet.set(rootKey, {
200
+ namespace: keyPrefix,
201
+ representationName: RepresentationType,
202
+ mergeable: false
203
+ });
204
+ return rootKeySet;
205
+ }
206
+
207
+ function select(luvio, params) {
208
+ return select$1();
209
+ }
210
+ function keyBuilder$1(luvio, params) {
211
+ return keyPrefix + '::SoqlQueryResultRepresentation:(' + 'query:' + params.body.query + ')';
212
+ }
213
+ function getResponseCacheKeys(luvio, resourceParams, response) {
214
+ return getTypeCacheKeys(luvio, response, function () { return keyBuilder$1(luvio, resourceParams); });
215
+ }
216
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
217
+ var body = response.body;
218
+ var key = keyBuilder$1(luvio, resourceParams);
219
+ luvio.storeIngest(key, ingest, body);
220
+ var snapshot = luvio.storeLookup({
221
+ recordId: key,
222
+ node: select(),
223
+ variables: {},
224
+ }, snapshotRefresh);
225
+ if (process.env.NODE_ENV !== 'production') {
226
+ if (snapshot.state !== 'Fulfilled') {
227
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
228
+ }
229
+ }
230
+ return snapshot;
231
+ }
232
+ function ingestError(luvio, params, error, snapshotRefresh) {
233
+ var key = keyBuilder$1(luvio, params);
234
+ var errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
235
+ var storeMetadataParams = {
236
+ ttl: TTL,
237
+ namespace: keyPrefix,
238
+ version: VERSION,
239
+ representationName: RepresentationType
240
+ };
241
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
242
+ return errorSnapshot;
243
+ }
244
+ function createResourceRequest(config) {
245
+ var headers = {};
246
+ return {
247
+ baseUri: '/services/data/v58.0',
248
+ basePath: '/wave/soql',
249
+ method: 'post',
250
+ body: config.body,
251
+ urlParams: {},
252
+ queryParams: {},
253
+ headers: headers,
254
+ priority: 'normal',
255
+ };
256
+ }
257
+
258
+ var executeSoqlQueryPost_ConfigPropertyNames = {
259
+ displayName: 'executeSoqlQueryPost',
260
+ parameters: {
261
+ required: ['query'],
262
+ optional: []
263
+ }
264
+ };
265
+ function createResourceParams(config) {
266
+ var resourceParams = {
267
+ body: {
268
+ query: config.query
269
+ }
270
+ };
271
+ return resourceParams;
272
+ }
273
+ function keyBuilder(luvio, config) {
274
+ var resourceParams = createResourceParams(config);
275
+ return keyBuilder$1(luvio, resourceParams);
276
+ }
277
+ function typeCheckConfig(untrustedConfig) {
278
+ var config = {};
279
+ var untrustedConfig_query = untrustedConfig.query;
280
+ if (typeof untrustedConfig_query === 'string') {
281
+ config.query = untrustedConfig_query;
282
+ }
283
+ return config;
284
+ }
285
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
286
+ if (!untrustedIsObject(untrustedConfig)) {
287
+ return null;
288
+ }
289
+ if (process.env.NODE_ENV !== 'production') {
290
+ validateConfig(untrustedConfig, configPropertyNames);
291
+ }
292
+ var config = typeCheckConfig(untrustedConfig);
293
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
294
+ return null;
295
+ }
296
+ return config;
297
+ }
298
+ function adapterFragment(luvio, config) {
299
+ createResourceParams(config);
300
+ return select();
301
+ }
302
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
303
+ var snapshot = ingestSuccess(luvio, resourceParams, response, {
304
+ config: config,
305
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
306
+ });
307
+ return luvio.storeBroadcast().then(function () { return snapshot; });
308
+ }
309
+ function onFetchResponseError(luvio, config, resourceParams, response) {
310
+ var snapshot = ingestError(luvio, resourceParams, response, {
311
+ config: config,
312
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
313
+ });
314
+ return luvio.storeBroadcast().then(function () { return snapshot; });
315
+ }
316
+ function buildNetworkSnapshot(luvio, config, options) {
317
+ var resourceParams = createResourceParams(config);
318
+ var request = createResourceRequest(resourceParams);
319
+ return luvio.dispatchResourceRequest(request, options)
320
+ .then(function (response) {
321
+ return luvio.handleSuccessResponse(function () { return onFetchResponseSuccess(luvio, config, resourceParams, response); }, function () { return getResponseCacheKeys(luvio, resourceParams, response.body); });
322
+ }, function (response) {
323
+ return luvio.handleErrorResponse(function () { return onFetchResponseError(luvio, config, resourceParams, response); });
324
+ });
325
+ }
326
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
327
+ var luvio = context.luvio, config = context.config;
328
+ var networkPriority = coercedAdapterRequestContext.networkPriority, requestCorrelator = coercedAdapterRequestContext.requestCorrelator, eventObservers = coercedAdapterRequestContext.eventObservers;
329
+ var dispatchOptions = {
330
+ resourceRequestContext: {
331
+ requestCorrelator: requestCorrelator,
332
+ luvioRequestMethod: 'get',
333
+ },
334
+ eventObservers: eventObservers
335
+ };
336
+ if (networkPriority !== 'normal') {
337
+ dispatchOptions.overrides = {
338
+ priority: networkPriority
339
+ };
340
+ }
341
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
342
+ }
343
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
344
+ var luvio = context.luvio, config = context.config;
345
+ var selector = {
346
+ recordId: keyBuilder(luvio, config),
347
+ node: adapterFragment(luvio, config),
348
+ variables: {},
349
+ };
350
+ var cacheSnapshot = storeLookup(selector, {
351
+ config: config,
352
+ resolve: function () { return buildNetworkSnapshot(luvio, config, snapshotRefreshOptions); }
353
+ });
354
+ return cacheSnapshot;
355
+ }
356
+ var executeSoqlQueryPostAdapterFactory = function (luvio) { return function WAVE__executeSoqlQueryPost(untrustedConfig, requestContext) {
357
+ var config = validateAdapterConfig(untrustedConfig, executeSoqlQueryPost_ConfigPropertyNames);
358
+ // Invalid or incomplete config
359
+ if (config === null) {
360
+ return null;
361
+ }
362
+ return luvio.applyCachePolicy((requestContext || {}), { config: config, luvio: luvio }, // BuildSnapshotContext
363
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
364
+ }; };
365
+
366
+ exports.executeSoqlQueryPostAdapterFactory = executeSoqlQueryPostAdapterFactory;
367
+
368
+ Object.defineProperty(exports, '__esModule', { value: true });
369
+
370
+ }));
package/package.json ADDED
@@ -0,0 +1,69 @@
1
+ {
2
+ "name": "@salesforce/lds-adapters-analytics-wave-private",
3
+ "version": "1.100.1",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "The Einstein Analytics family of APIs that are not publically exposed",
6
+ "main": "dist/umd/es2018/analytics-wave-private.js",
7
+ "module": "dist/es/es2018/analytics-wave-private.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/analytics-wave-private.js",
17
+ "require": "./dist/umd/es2018/analytics-wave-private.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
+ "lindsey.burnett@salesforce.com"
28
+ ],
29
+ "sfdc": {
30
+ "path": "forcelds/ldsAdaptersAnalyticsWavePrivate/"
31
+ },
32
+ "scripts": {
33
+ "clean": "rm -rf dist sfdc src/generated karma/dist",
34
+ "build": "yarn build:raml && yarn build:services && yarn build:karma",
35
+ "build:karma": "rollup --config rollup.config.karma.js",
36
+ "build:raml": "luvio generate src/raml/luvio.raml src/generated -p '../lds-compiler-plugins'",
37
+ "build:services": "rollup --config rollup.config.js",
38
+ "start": "karma start",
39
+ "test": "karma start --single-run",
40
+ "test:compat": "karma start --single-run --compat",
41
+ "release:corejar": "yarn build && ../core-build/scripts/core.js --adapter=lds-adapters-analytics-wave-private",
42
+ "release:core": "../../scripts/release/core.js --adapter=lds-adapters-analytics-wave-private"
43
+ },
44
+ "nx": {
45
+ "targets": {
46
+ "build": {
47
+ "outputs": [
48
+ "packages/lds-adapters-analytics-wave-private/dist",
49
+ "packages/lds-adapters-analytics-wave-private/karma/dist",
50
+ "packages/lds-adapters-analytics-wave-private/sfdc",
51
+ "packages/lds-adapters-analytics-wave-private/src/generated"
52
+ ]
53
+ }
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@salesforce/lds-bindings": "^1.100.1"
58
+ },
59
+ "devDependencies": {
60
+ "@luvio/cli": "0.135.4",
61
+ "@luvio/compiler": "0.135.4",
62
+ "@luvio/engine": "0.135.4",
63
+ "@luvio/lwc-luvio": "0.135.4",
64
+ "@salesforce/lds-karma": "^1.100.1"
65
+ },
66
+ "volta": {
67
+ "extends": "../../package.json"
68
+ }
69
+ }
@@ -0,0 +1 @@
1
+ export * from '../dist/types/src/generated/artifacts/sfdc';