@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,39 @@
1
+ import { NormalizedKeyMetadata as $64$luvio_engine_NormalizedKeyMetadata } from '@luvio/engine';
2
+ export declare const ObjectFreeze: {
3
+ <T extends Function>(f: T): T;
4
+ <T_1 extends {
5
+ [idx: string]: object | U | null | undefined;
6
+ }, U extends string | number | bigint | boolean | symbol>(o: T_1): Readonly<T_1>;
7
+ <T_2>(o: T_2): Readonly<T_2>;
8
+ }, ObjectKeys: {
9
+ (o: object): string[];
10
+ (o: {}): string[];
11
+ }, ObjectCreate: {
12
+ (o: object | null): any;
13
+ (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
14
+ }, ObjectAssign: {
15
+ <T extends {}, U>(target: T, source: U): T & U;
16
+ <T_1 extends {}, U_1, V>(target: T_1, source1: U_1, source2: V): T_1 & U_1 & V;
17
+ <T_2 extends {}, U_2, V_1, W>(target: T_2, source1: U_2, source2: V_1, source3: W): T_2 & U_2 & V_1 & W;
18
+ (target: object, ...sources: any[]): any;
19
+ };
20
+ export declare const ArrayIsArray: (arg: any) => arg is any[];
21
+ export declare const JSONStringify: {
22
+ (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
23
+ (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
24
+ };
25
+ type AllowedPrimitives = boolean | string | number | Date | null;
26
+ type Value<T> = T extends AllowedPrimitives ? T : RecursivePartial<T>;
27
+ export type RecursivePartial<T> = null | {
28
+ [P in keyof T]?: T[P] extends Array<infer U> ? Array<Value<U>> | null : Value<T[P]> | null;
29
+ };
30
+ export declare function equalsArray<U, V extends U[]>(a: V, b: V, equalsItem: (itemA: U, itemB: U) => boolean | void): boolean;
31
+ export declare function equalsObject<U, V extends {
32
+ [key: string]: U;
33
+ }>(a: V, b: V, equalsProp: (propA: U, propB: U) => boolean | void): boolean;
34
+ export declare function deepFreeze(value: any): void;
35
+ export declare function createLink(ref: string | $64$luvio_engine_NormalizedKeyMetadata): {
36
+ __ref: string;
37
+ };
38
+ export declare function assignMetadataLink(entry: any, metadataKey: string | $64$luvio_engine_NormalizedKeyMetadata): void;
39
+ export {};
@@ -0,0 +1,369 @@
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
+ const { hasOwnProperty: ObjectPrototypeHasOwnProperty } = Object.prototype;
14
+ const { keys: ObjectKeys$1, freeze: ObjectFreeze$1, create: ObjectCreate$1 } = Object;
15
+ const { isArray: ArrayIsArray$1 } = Array;
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
+ const { displayName } = adapter;
25
+ const { required, optional, unsupported } = adapter.parameters;
26
+ if (config === undefined ||
27
+ required.every(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
28
+ throw new TypeError(`adapter ${displayName} configuration must specify ${required.sort().join(', ')}`);
29
+ }
30
+ if (oneOf && oneOf.some(req => ObjectPrototypeHasOwnProperty.call(config, req)) === false) {
31
+ throw new TypeError(`adapter ${displayName} configuration must specify one of ${oneOf.sort().join(', ')}`);
32
+ }
33
+ if (unsupported !== undefined &&
34
+ unsupported.some(req => ObjectPrototypeHasOwnProperty.call(config, req))) {
35
+ throw new TypeError(`adapter ${displayName} does not yet support ${unsupported.sort().join(', ')}`);
36
+ }
37
+ const supported = required.concat(optional);
38
+ if (ObjectKeys$1(config).some(key => !supported.includes(key))) {
39
+ throw new TypeError(`adapter ${displayName} configuration supports only ${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(req => req in config);
47
+ }
48
+ const snapshotRefreshOptions = {
49
+ overrides: {
50
+ headers: {
51
+ 'Cache-Control': 'no-cache',
52
+ },
53
+ }
54
+ };
55
+ const keyPrefix = 'WAVE';
56
+
57
+ const { freeze: ObjectFreeze, keys: ObjectKeys, create: ObjectCreate, assign: ObjectAssign } = Object;
58
+ const { isArray: ArrayIsArray } = Array;
59
+ const { stringify: JSONStringify } = JSON;
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 (let i = 0, len = value.length; i < len; i += 1) {
67
+ deepFreeze$1(value[i]);
68
+ }
69
+ }
70
+ else {
71
+ const keys = ObjectKeys(value);
72
+ for (let 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
+ const TTL = 5000;
85
+ const VERSION = "f4d046d44230e53375ee20bbd2483a1f";
86
+ function validate(obj, path = 'SoqlQueryResultRepresentation') {
87
+ const v_error = (() => {
88
+ if (typeof obj !== 'object' || ArrayIsArray(obj) || obj === null) {
89
+ return new TypeError('Expected "object" but received "' + typeof obj + '" (at "' + path + '")');
90
+ }
91
+ const obj_keys = ObjectKeys(obj);
92
+ for (let i = 0; i < obj_keys.length; i++) {
93
+ const key = obj_keys[i];
94
+ const obj_prop = obj[key];
95
+ const path_prop = path + '["' + key + '"]';
96
+ if (obj_prop === undefined) {
97
+ return new TypeError('Expected "defined" but received "' + typeof obj_prop + '" (at "' + path_prop + '")');
98
+ }
99
+ }
100
+ if (obj.done !== undefined) {
101
+ const obj_done = obj.done;
102
+ const path_done = path + '.done';
103
+ if (typeof obj_done !== 'boolean') {
104
+ return new TypeError('Expected "boolean" but received "' + typeof obj_done + '" (at "' + path_done + '")');
105
+ }
106
+ }
107
+ const obj_records = obj.records;
108
+ const path_records = path + '.records';
109
+ if (!ArrayIsArray(obj_records)) {
110
+ return new TypeError('Expected "array" but received "' + typeof obj_records + '" (at "' + path_records + '")');
111
+ }
112
+ for (let i = 0; i < obj_records.length; i++) {
113
+ const obj_records_item = obj_records[i];
114
+ const path_records_item = path_records + '[' + i + ']';
115
+ if (obj_records_item === undefined) {
116
+ return new TypeError('Expected "defined" but received "' + typeof obj_records_item + '" (at "' + path_records_item + '")');
117
+ }
118
+ }
119
+ if (obj.totalSize !== undefined) {
120
+ const obj_totalSize = obj.totalSize;
121
+ const path_totalSize = path + '.totalSize';
122
+ if (typeof obj_totalSize !== 'number') {
123
+ return new TypeError('Expected "number" but received "' + typeof obj_totalSize + '" (at "' + path_totalSize + '")');
124
+ }
125
+ }
126
+ })();
127
+ return v_error === undefined ? null : v_error;
128
+ }
129
+ const RepresentationType = 'SoqlQueryResultRepresentation';
130
+ function normalize(input, existing, path, luvio, store, timestamp) {
131
+ return input;
132
+ }
133
+ const select$1 = function SoqlQueryResultRepresentationSelect() {
134
+ return {
135
+ kind: 'Fragment',
136
+ version: VERSION,
137
+ private: [],
138
+ opaque: true
139
+ };
140
+ };
141
+ function equals(existing, incoming) {
142
+ if (JSONStringify(incoming) !== JSONStringify(existing)) {
143
+ return false;
144
+ }
145
+ return true;
146
+ }
147
+ function deepFreeze(input) {
148
+ const input_keys = Object.keys(input);
149
+ const input_length = input_keys.length;
150
+ for (let i = 0; i < input_length; i++) {
151
+ const key = input_keys[i];
152
+ const input_prop = input[key];
153
+ deepFreeze$1(input_prop);
154
+ }
155
+ const input_records = input.records;
156
+ for (let i = 0; i < input_records.length; i++) {
157
+ const input_records_item = input_records[i];
158
+ deepFreeze$1(input_records_item);
159
+ }
160
+ ObjectFreeze(input_records);
161
+ ObjectFreeze(input);
162
+ }
163
+ const ingest = function SoqlQueryResultRepresentationIngest(input, path, luvio, store, timestamp) {
164
+ if (process.env.NODE_ENV !== 'production') {
165
+ const validateError = validate(input);
166
+ if (validateError !== null) {
167
+ throw validateError;
168
+ }
169
+ }
170
+ const key = path.fullPath;
171
+ const existingRecord = store.readEntry(key);
172
+ const ttlToUse = TTL;
173
+ let incomingRecord = normalize(input, store.readEntry(key), {
174
+ fullPath: key,
175
+ parent: path.parent,
176
+ propertyName: path.propertyName,
177
+ ttl: ttlToUse
178
+ });
179
+ deepFreeze(input);
180
+ if (existingRecord === undefined || equals(existingRecord, incomingRecord) === false) {
181
+ luvio.storePublish(key, incomingRecord);
182
+ }
183
+ {
184
+ const storeMetadataParams = {
185
+ ttl: ttlToUse,
186
+ namespace: "WAVE",
187
+ version: VERSION,
188
+ representationName: RepresentationType,
189
+ };
190
+ luvio.publishStoreMetadata(key, storeMetadataParams);
191
+ }
192
+ return createLink(key);
193
+ };
194
+ function getTypeCacheKeys(luvio, input, fullPathFactory) {
195
+ const rootKeySet = new engine.StoreKeyMap();
196
+ // root cache key (uses fullPathFactory if keyBuilderFromType isn't defined)
197
+ const rootKey = fullPathFactory();
198
+ rootKeySet.set(rootKey, {
199
+ namespace: keyPrefix,
200
+ representationName: RepresentationType,
201
+ mergeable: false
202
+ });
203
+ return rootKeySet;
204
+ }
205
+
206
+ function select(luvio, params) {
207
+ return select$1();
208
+ }
209
+ function keyBuilder$1(luvio, params) {
210
+ return keyPrefix + '::SoqlQueryResultRepresentation:(' + 'query:' + params.body.query + ')';
211
+ }
212
+ function getResponseCacheKeys(luvio, resourceParams, response) {
213
+ return getTypeCacheKeys(luvio, response, () => keyBuilder$1(luvio, resourceParams));
214
+ }
215
+ function ingestSuccess(luvio, resourceParams, response, snapshotRefresh) {
216
+ const { body } = response;
217
+ const key = keyBuilder$1(luvio, resourceParams);
218
+ luvio.storeIngest(key, ingest, body);
219
+ const snapshot = luvio.storeLookup({
220
+ recordId: key,
221
+ node: select(),
222
+ variables: {},
223
+ }, snapshotRefresh);
224
+ if (process.env.NODE_ENV !== 'production') {
225
+ if (snapshot.state !== 'Fulfilled') {
226
+ throw new Error('Invalid network response. Expected resource response to result in Fulfilled snapshot');
227
+ }
228
+ }
229
+ return snapshot;
230
+ }
231
+ function ingestError(luvio, params, error, snapshotRefresh) {
232
+ const key = keyBuilder$1(luvio, params);
233
+ const errorSnapshot = luvio.errorSnapshot(error, snapshotRefresh);
234
+ const storeMetadataParams = {
235
+ ttl: TTL,
236
+ namespace: keyPrefix,
237
+ version: VERSION,
238
+ representationName: RepresentationType
239
+ };
240
+ luvio.storeIngestError(key, errorSnapshot, storeMetadataParams);
241
+ return errorSnapshot;
242
+ }
243
+ function createResourceRequest(config) {
244
+ const headers = {};
245
+ return {
246
+ baseUri: '/services/data/v58.0',
247
+ basePath: '/wave/soql',
248
+ method: 'post',
249
+ body: config.body,
250
+ urlParams: {},
251
+ queryParams: {},
252
+ headers,
253
+ priority: 'normal',
254
+ };
255
+ }
256
+
257
+ const executeSoqlQueryPost_ConfigPropertyNames = {
258
+ displayName: 'executeSoqlQueryPost',
259
+ parameters: {
260
+ required: ['query'],
261
+ optional: []
262
+ }
263
+ };
264
+ function createResourceParams(config) {
265
+ const resourceParams = {
266
+ body: {
267
+ query: config.query
268
+ }
269
+ };
270
+ return resourceParams;
271
+ }
272
+ function keyBuilder(luvio, config) {
273
+ const resourceParams = createResourceParams(config);
274
+ return keyBuilder$1(luvio, resourceParams);
275
+ }
276
+ function typeCheckConfig(untrustedConfig) {
277
+ const config = {};
278
+ const untrustedConfig_query = untrustedConfig.query;
279
+ if (typeof untrustedConfig_query === 'string') {
280
+ config.query = untrustedConfig_query;
281
+ }
282
+ return config;
283
+ }
284
+ function validateAdapterConfig(untrustedConfig, configPropertyNames) {
285
+ if (!untrustedIsObject(untrustedConfig)) {
286
+ return null;
287
+ }
288
+ if (process.env.NODE_ENV !== 'production') {
289
+ validateConfig(untrustedConfig, configPropertyNames);
290
+ }
291
+ const config = typeCheckConfig(untrustedConfig);
292
+ if (!areRequiredParametersPresent(config, configPropertyNames)) {
293
+ return null;
294
+ }
295
+ return config;
296
+ }
297
+ function adapterFragment(luvio, config) {
298
+ createResourceParams(config);
299
+ return select();
300
+ }
301
+ function onFetchResponseSuccess(luvio, config, resourceParams, response) {
302
+ const snapshot = ingestSuccess(luvio, resourceParams, response, {
303
+ config,
304
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
305
+ });
306
+ return luvio.storeBroadcast().then(() => snapshot);
307
+ }
308
+ function onFetchResponseError(luvio, config, resourceParams, response) {
309
+ const snapshot = ingestError(luvio, resourceParams, response, {
310
+ config,
311
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
312
+ });
313
+ return luvio.storeBroadcast().then(() => snapshot);
314
+ }
315
+ function buildNetworkSnapshot(luvio, config, options) {
316
+ const resourceParams = createResourceParams(config);
317
+ const request = createResourceRequest(resourceParams);
318
+ return luvio.dispatchResourceRequest(request, options)
319
+ .then((response) => {
320
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resourceParams, response), () => getResponseCacheKeys(luvio, resourceParams, response.body));
321
+ }, (response) => {
322
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, resourceParams, response));
323
+ });
324
+ }
325
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
326
+ const { luvio, config } = context;
327
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
328
+ const dispatchOptions = {
329
+ resourceRequestContext: {
330
+ requestCorrelator,
331
+ luvioRequestMethod: 'get',
332
+ },
333
+ eventObservers
334
+ };
335
+ if (networkPriority !== 'normal') {
336
+ dispatchOptions.overrides = {
337
+ priority: networkPriority
338
+ };
339
+ }
340
+ return buildNetworkSnapshot(luvio, config, dispatchOptions);
341
+ }
342
+ function buildCachedSnapshotCachePolicy(context, storeLookup) {
343
+ const { luvio, config } = context;
344
+ const selector = {
345
+ recordId: keyBuilder(luvio, config),
346
+ node: adapterFragment(luvio, config),
347
+ variables: {},
348
+ };
349
+ const cacheSnapshot = storeLookup(selector, {
350
+ config,
351
+ resolve: () => buildNetworkSnapshot(luvio, config, snapshotRefreshOptions)
352
+ });
353
+ return cacheSnapshot;
354
+ }
355
+ const executeSoqlQueryPostAdapterFactory = (luvio) => function WAVE__executeSoqlQueryPost(untrustedConfig, requestContext) {
356
+ const config = validateAdapterConfig(untrustedConfig, executeSoqlQueryPost_ConfigPropertyNames);
357
+ // Invalid or incomplete config
358
+ if (config === null) {
359
+ return null;
360
+ }
361
+ return luvio.applyCachePolicy((requestContext || {}), { config, luvio }, // BuildSnapshotContext
362
+ buildCachedSnapshotCachePolicy, buildNetworkSnapshotCachePolicy);
363
+ };
364
+
365
+ exports.executeSoqlQueryPostAdapterFactory = executeSoqlQueryPostAdapterFactory;
366
+
367
+ Object.defineProperty(exports, '__esModule', { value: true });
368
+
369
+ }));