@salesforce/lds-adapters-graphql 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.
Files changed (30) hide show
  1. package/LICENSE.txt +82 -0
  2. package/dist/es/es2018/graphql-service.js +2282 -0
  3. package/dist/es/es2018/types/src/__mocks__/@salesforce/lds-adapters-uiapi/sfdc/graphqlAdapters.d.ts +1 -0
  4. package/dist/es/es2018/types/src/configuration.d.ts +11 -0
  5. package/dist/es/es2018/types/src/custom/connection.d.ts +17 -0
  6. package/dist/es/es2018/types/src/custom/record.d.ts +46 -0
  7. package/dist/es/es2018/types/src/main.d.ts +26 -0
  8. package/dist/es/es2018/types/src/sfdc.d.ts +5 -0
  9. package/dist/es/es2018/types/src/type/Argument.d.ts +10 -0
  10. package/dist/es/es2018/types/src/type/CustomField.d.ts +4 -0
  11. package/dist/es/es2018/types/src/type/Document.d.ts +11 -0
  12. package/dist/es/es2018/types/src/type/Field.d.ts +4 -0
  13. package/dist/es/es2018/types/src/type/ObjectField.d.ts +2 -0
  14. package/dist/es/es2018/types/src/type/Operation.d.ts +5 -0
  15. package/dist/es/es2018/types/src/type/ScalarField.d.ts +2 -0
  16. package/dist/es/es2018/types/src/type/Selection.d.ts +23 -0
  17. package/dist/es/es2018/types/src/type/Variable.d.ts +4 -0
  18. package/dist/es/es2018/types/src/util/adapter.d.ts +16 -0
  19. package/dist/es/es2018/types/src/util/ast-to-string.d.ts +7 -0
  20. package/dist/es/es2018/types/src/util/equal.d.ts +7 -0
  21. package/dist/es/es2018/types/src/util/ingest.d.ts +18 -0
  22. package/dist/es/es2018/types/src/util/language.d.ts +20 -0
  23. package/dist/es/es2018/types/src/util/merge.d.ts +1 -0
  24. package/dist/es/es2018/types/src/util/read.d.ts +4 -0
  25. package/dist/es/es2018/types/src/util/serialize.d.ts +12 -0
  26. package/dist/es/es2018/types/src/util/sortUsingKey.d.ts +1 -0
  27. package/dist/es/es2018/types/src/util/synthetic-fields.d.ts +18 -0
  28. package/package.json +75 -0
  29. package/sfdc/index.d.ts +1 -0
  30. package/sfdc/index.js +2307 -0
package/sfdc/index.js ADDED
@@ -0,0 +1,2307 @@
1
+ /**
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+
7
+ /* *******************************************************************************************
8
+ * ATTENTION!
9
+ * THIS IS A GENERATED FILE FROM https://github.com/salesforce-experience-platform-emu/lds-lightning-platform
10
+ * If you would like to contribute to LDS, please follow the steps outlined in the git repo.
11
+ * Any changes made to this file in p4 will be automatically overwritten.
12
+ * *******************************************************************************************
13
+ */
14
+ /* proxy-compat-disable */
15
+ import { createLDSAdapter, createWireAdapterConstructor, createInstrumentedAdapter, createImperativeAdapter } from 'force/ldsBindings';
16
+ import { register, withDefaultLuvio } from 'force/ldsEngine';
17
+ import { StoreKeyMap } from 'force/luvioEngine';
18
+ import { Kind, astResolver } from 'force/ldsGraphqlParser';
19
+ import { graphqlAdapterFactory } from 'force/ldsAdaptersUiapiGraphql';
20
+ import { createIngestRecordWithFields, keyBuilderRecord } from 'force/ldsAdaptersUiapi';
21
+
22
+ const { isArray } = Array;
23
+ const { keys, freeze, create } = Object;
24
+ const { hasOwnProperty } = Object.prototype;
25
+ const { parse, stringify } = JSON;
26
+
27
+ function sortAndCopyUsingObjectKey(arr, key) {
28
+ return [...arr].sort((a, b) => {
29
+ const aKey = a[key];
30
+ const bKey = b[key];
31
+ if (aKey < bKey) {
32
+ return -1;
33
+ }
34
+ if (aKey > bKey) {
35
+ return 1;
36
+ }
37
+ return 0;
38
+ });
39
+ }
40
+
41
+ function untrustedIsObject(untrusted) {
42
+ return typeof untrusted === 'object' && untrusted !== null && isArray(untrusted) === false;
43
+ }
44
+ function deepFreeze(value) {
45
+ // No need to freeze primitives
46
+ if (typeof value !== 'object' || value === null) {
47
+ return;
48
+ }
49
+ if (isArray(value)) {
50
+ for (let i = 0, len = value.length; i < len; i += 1) {
51
+ deepFreeze(value[i]);
52
+ }
53
+ }
54
+ else {
55
+ const keys$1 = keys(value);
56
+ for (let i = 0, len = keys$1.length; i < len; i += 1) {
57
+ const v = value[keys$1[i]];
58
+ deepFreeze(v);
59
+ }
60
+ }
61
+ return freeze(value);
62
+ }
63
+ /**
64
+ * A deterministic JSON stringify implementation. Heavily adapted from https://github.com/epoberezkin/fast-json-stable-stringify.
65
+ * This is needed because insertion order for JSON.stringify(object) affects output:
66
+ * JSON.stringify({a: 1, b: 2})
67
+ * "{"a":1,"b":2}"
68
+ * JSON.stringify({b: 2, a: 1})
69
+ * "{"b":2,"a":1}"
70
+ * @param data Data to be JSON-stringified.
71
+ * @returns JSON.stringified value with consistent ordering of keys.
72
+ */
73
+ function stableJSONStringify(node) {
74
+ // This is for Date values.
75
+ if (node && node.toJSON && typeof node.toJSON === 'function') {
76
+ // eslint-disable-next-line no-param-reassign
77
+ node = node.toJSON();
78
+ }
79
+ if (node === undefined) {
80
+ return '';
81
+ }
82
+ if (typeof node === 'number') {
83
+ return isFinite(node) ? '' + node : 'null';
84
+ }
85
+ if (typeof node !== 'object') {
86
+ return stringify(node);
87
+ }
88
+ let i;
89
+ let out;
90
+ if (isArray(node)) {
91
+ node.sort();
92
+ out = '[';
93
+ for (i = 0; i < node.length; i++) {
94
+ if (i) {
95
+ out += ',';
96
+ }
97
+ out += stableJSONStringify(node[i]) || 'null';
98
+ }
99
+ return out + ']';
100
+ }
101
+ if (node === null) {
102
+ return 'null';
103
+ }
104
+ const keys$1 = keys(node).sort();
105
+ out = '';
106
+ for (i = 0; i < keys$1.length; i++) {
107
+ const key = keys$1[i];
108
+ const value = stableJSONStringify(node[key]);
109
+ if (!value) {
110
+ continue;
111
+ }
112
+ if (out) {
113
+ out += ',';
114
+ }
115
+ out += key + ':' + value;
116
+ }
117
+ return '{' + out + '}';
118
+ }
119
+ const namespace = 'GraphQL';
120
+ const representationName = 'graphql';
121
+
122
+ function serialize$1(args) {
123
+ return serializeArgs(args, { render: false });
124
+ }
125
+ function render$1(args, variables) {
126
+ return serializeArgs(args, { render: true, variables });
127
+ }
128
+ function serializeArgs(args, option) {
129
+ const sortedArgs = option.render === true ? sortAndCopyUsingObjectKey(args, 'name') : args;
130
+ let str = '';
131
+ for (let i = 0, len = sortedArgs.length; i < len; i += 1) {
132
+ str = `${str}${serializeArgumentNode(sortedArgs[i], option)}`;
133
+ if (len > 1 && i < len - 1) {
134
+ str = `${str},`;
135
+ }
136
+ }
137
+ return str;
138
+ }
139
+ function serializeArgumentValueNode(valueDefinition, option) {
140
+ const { kind } = valueDefinition;
141
+ switch (kind) {
142
+ case 'ObjectValue':
143
+ return serializeAndSortObjectValueNode(valueDefinition, option);
144
+ case 'ListValue':
145
+ return serializeAndSortListValueNode(valueDefinition, option);
146
+ case 'Variable':
147
+ return serializeVariableNode$1(valueDefinition, option);
148
+ default:
149
+ return serializeValueNode(valueDefinition);
150
+ }
151
+ }
152
+ function serializeVariableNode$1(literalValueNode, option) {
153
+ if (option.render === false) {
154
+ return `$${literalValueNode.name}`;
155
+ }
156
+ return `${serializeVariableValue(option.variables[literalValueNode.name])}`;
157
+ }
158
+ function serializeVariableValue(value) {
159
+ return stableJSONStringify(value);
160
+ }
161
+ function serializeAndSortListValueNode(objectValueDefinition, option) {
162
+ const { values } = objectValueDefinition;
163
+ const str = [];
164
+ const sorted = option.render === true ? sortAndCopyUsingObjectKey(values, 'value') : values;
165
+ for (let i = 0, len = sorted.length; i < len; i += 1) {
166
+ str.push(serializeArgumentValueNode(sorted[i], option));
167
+ }
168
+ return `[${str.join(',')}]`;
169
+ }
170
+ function serializeAndSortObjectValueNode(objectValueDefinition, option) {
171
+ const { fields } = objectValueDefinition;
172
+ let str = '';
173
+ const fieldKeys = keys(fields).sort();
174
+ for (let i = 0, len = fieldKeys.length; i < len; i += 1) {
175
+ const fieldKey = fieldKeys[i];
176
+ str = `${str}${fieldKey}:${serializeArgumentValueNode(fields[fieldKey], option)}`;
177
+ if (len > 1 && i < len - 1) {
178
+ str = `${str},`;
179
+ }
180
+ }
181
+ return `{${str}}`;
182
+ }
183
+ function serializeArgumentNode(arg, option) {
184
+ const { name, value } = arg;
185
+ return `${name}:${serializeArgumentValueNode(value, option)}`;
186
+ }
187
+
188
+ function render(sel, variables) {
189
+ return serializeField(sel, { render: true, variables });
190
+ }
191
+ function serializeField(sel, option) {
192
+ const { name: fieldName } = sel;
193
+ if (sel.kind === 'ScalarFieldSelection') {
194
+ return fieldName;
195
+ }
196
+ const { arguments: selectionArguments } = sel;
197
+ if (selectionArguments === undefined || selectionArguments.length === 0) {
198
+ return fieldName;
199
+ }
200
+ return `${fieldName}(${option.render === true
201
+ ? render$1(selectionArguments, option.variables)
202
+ : serialize$1(selectionArguments)})`;
203
+ }
204
+
205
+ function readScalarFieldSelection(builder, source, fieldName, sink) {
206
+ const gqlData = source[fieldName];
207
+ if (gqlData !== undefined && gqlData !== null && gqlData.__ref !== undefined) {
208
+ if (process.env.NODE_ENV !== 'production') {
209
+ throw new Error(`Scalar requested at "${fieldName}" but is instead an object at "${gqlData.__ref}"`);
210
+ }
211
+ }
212
+ builder.readScalar(fieldName, source, sink);
213
+ }
214
+
215
+ const CUSTOM_FIELD_NODE_TYPE = 'Record';
216
+ const RECORD_DEFAULT_FIELD_VALUES = ['value', 'displayValue'];
217
+ function collectObjectFieldSelection(data) {
218
+ return {
219
+ value: data.value,
220
+ displayValue: data.displayValue,
221
+ };
222
+ }
223
+ function childTypeIsChildRelationships(sel, _data) {
224
+ return sel.type === CONNECTION_NODE_TYPE;
225
+ }
226
+ function childTypeIsSpanningGqlRecord(sel, _data) {
227
+ return sel.type === CUSTOM_FIELD_NODE_TYPE;
228
+ }
229
+ function convertAstToTrie(ast) {
230
+ const selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
231
+ const children = {};
232
+ const trie = {
233
+ name: ast.name,
234
+ children,
235
+ };
236
+ for (let i = 0, len = selections.length; i < len; i += 1) {
237
+ const sel = getLuvioFieldNodeSelection(selections[i]);
238
+ const { name: selName, kind } = sel;
239
+ switch (kind) {
240
+ case 'ObjectFieldSelection': {
241
+ children[selName] = {
242
+ name: selName,
243
+ children: {},
244
+ };
245
+ break;
246
+ }
247
+ case 'CustomFieldSelection': {
248
+ children[selName] = convertAstToTrie(sel);
249
+ break;
250
+ }
251
+ }
252
+ }
253
+ return trie;
254
+ }
255
+ function formatSpanningCustomFieldSelection(sel, data) {
256
+ if (data === null) {
257
+ return {
258
+ value: {
259
+ displayValue: null,
260
+ value: null,
261
+ },
262
+ trie: convertAstToTrie(sel),
263
+ };
264
+ }
265
+ const { recordRepresentation, fieldsTrie } = convertToRecordRepresentation(sel, data);
266
+ return {
267
+ trie: fieldsTrie,
268
+ value: {
269
+ displayValue: data.DisplayValue,
270
+ value: recordRepresentation,
271
+ },
272
+ };
273
+ }
274
+ function convertToRecordRepresentation(ast, record) {
275
+ const { Id, WeakEtag, ApiName, LastModifiedById, LastModifiedDate, SystemModstamp, ldsRecordTypeId, } = record;
276
+ const { luvioSelections } = ast;
277
+ if (luvioSelections === undefined) {
278
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
279
+ throw new Error('Undefined selections');
280
+ }
281
+ const trieChildren = {};
282
+ const trie = {
283
+ name: ApiName,
284
+ children: trieChildren,
285
+ };
286
+ const childRelationships = {};
287
+ const fieldsBag = {};
288
+ for (let i = 0, len = luvioSelections.length; i < len; i += 1) {
289
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
290
+ const { name: fieldName, alias } = sel;
291
+ const propertyName = alias === undefined ? fieldName : alias;
292
+ const data = record[propertyName];
293
+ switch (sel.kind) {
294
+ case 'ObjectFieldSelection': {
295
+ trieChildren[fieldName] = {
296
+ name: fieldName,
297
+ children: {},
298
+ };
299
+ fieldsBag[fieldName] = collectObjectFieldSelection(data);
300
+ break;
301
+ }
302
+ case 'CustomFieldSelection': {
303
+ if (childTypeIsSpanningGqlRecord(sel)) {
304
+ const { value, trie } = formatSpanningCustomFieldSelection(sel, data);
305
+ trieChildren[fieldName] = trie;
306
+ fieldsBag[fieldName] = value;
307
+ }
308
+ else if (childTypeIsChildRelationships(sel)) {
309
+ childRelationships[fieldName] = {
310
+ ast: sel,
311
+ data: data,
312
+ };
313
+ }
314
+ break;
315
+ }
316
+ }
317
+ }
318
+ const rep = {
319
+ apiName: ApiName,
320
+ eTag: '',
321
+ lastModifiedById: LastModifiedById.value,
322
+ lastModifiedDate: LastModifiedDate.value,
323
+ systemModstamp: SystemModstamp.value,
324
+ recordTypeId: ldsRecordTypeId === null ? null : ldsRecordTypeId.value,
325
+ recordTypeInfo: null,
326
+ childRelationships: {},
327
+ id: Id,
328
+ weakEtag: WeakEtag,
329
+ fields: fieldsBag,
330
+ };
331
+ return {
332
+ recordRepresentation: rep,
333
+ fieldsTrie: trie,
334
+ childRelationships,
335
+ };
336
+ }
337
+ const defaultRecordFieldsFragmentName = 'defaultRecordFields';
338
+ const defaultRecordFieldsFragment = `fragment ${defaultRecordFieldsFragmentName} on Record { __typename, ApiName, WeakEtag, Id, DisplayValue, SystemModstamp { value } LastModifiedById { value } LastModifiedDate { value } ldsRecordTypeId: RecordTypeId(fallback: true) { value } }`;
339
+ function getChildRelationshipsKey(recordKey, propertyName) {
340
+ return `${recordKey}__childRelationships__${propertyName}`;
341
+ }
342
+ const createIngest$4 = (ast, variables) => {
343
+ return (data, path, luvio, store, timestamp) => {
344
+ const { recordRepresentation, fieldsTrie, childRelationships } = convertToRecordRepresentation(ast, data);
345
+ const ingestRecord = createIngestRecordWithFields(fieldsTrie, {
346
+ name: recordRepresentation.apiName,
347
+ children: {},
348
+ });
349
+ const recordIngest = ingestRecord(recordRepresentation, path, luvio, store, timestamp);
350
+ const recordKey = recordIngest.__ref;
351
+ const childRelationshipKeys = Object.keys(childRelationships);
352
+ for (let i = 0, len = childRelationshipKeys.length; i < len; i += 1) {
353
+ const propertyName = childRelationshipKeys[i];
354
+ const childRelationship = childRelationships[propertyName];
355
+ const { ast: childRelationshipAst, data: childRelationshipData } = childRelationship;
356
+ const fullPath = getChildRelationshipsKey(recordKey, propertyName);
357
+ createIngest$1(childRelationshipAst, fullPath, variables)(childRelationshipData, {
358
+ parent: {
359
+ data,
360
+ key: recordKey,
361
+ existing: undefined,
362
+ },
363
+ fullPath: fullPath,
364
+ propertyName: propertyName,
365
+ }, luvio, store, timestamp);
366
+ }
367
+ return recordIngest;
368
+ };
369
+ };
370
+ const recordProperties = {
371
+ Id: {
372
+ propertyName: 'id',
373
+ },
374
+ ApiName: {
375
+ propertyName: 'apiName',
376
+ },
377
+ };
378
+ function getNonSpanningField(sel, builder, source) {
379
+ const sink = {};
380
+ const { luvioSelections } = sel;
381
+ if (luvioSelections === undefined) {
382
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
383
+ throw new Error('Empty selections not supported');
384
+ }
385
+ for (let i = 0, len = luvioSelections.length; i < len; i += 1) {
386
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
387
+ const { kind } = sel;
388
+ const name = sel.name;
389
+ builder.enterPath(name);
390
+ if (kind !== 'ScalarFieldSelection') {
391
+ if (process.env.NODE_ENV !== 'production') {
392
+ throw new Error(`Unexpected kind "${kind}"`);
393
+ }
394
+ }
395
+ builder.assignScalar(name, sink, source[name]);
396
+ builder.exitPath();
397
+ }
398
+ return sink;
399
+ }
400
+ function getCustomSelection(luvio, selection, builder, options, variables) {
401
+ const { type } = selection;
402
+ switch (type) {
403
+ case 'Record':
404
+ return readRecordRepresentation(luvio, selection, builder, options, variables);
405
+ }
406
+ }
407
+ function getScalarValue(selectionName, state) {
408
+ if (selectionName === 'DisplayValue') {
409
+ const { parentFieldValue } = state;
410
+ if (parentFieldValue === undefined) {
411
+ if (process.env.NODE_ENV !== 'production') {
412
+ throw new Error('Unable to calculate DisplayValue');
413
+ }
414
+ else {
415
+ return undefined;
416
+ }
417
+ }
418
+ return parentFieldValue.displayValue;
419
+ }
420
+ const assignment = recordProperties[selectionName];
421
+ if (assignment === undefined) {
422
+ if (process.env.NODE_ENV !== 'production') {
423
+ throw new Error(`Unknown assignment for ScalarFieldSelection at property "${selectionName}"`);
424
+ }
425
+ }
426
+ return state.source[assignment.propertyName];
427
+ }
428
+ function assignConnectionSelection(luvio, builder, sink, sel, recordKey, propertyName, variables) {
429
+ const key = getChildRelationshipsKey(recordKey, propertyName);
430
+ const resolved = resolveKey(builder, key);
431
+ if (resolved === undefined) {
432
+ return;
433
+ }
434
+ const data = createRead$2(luvio, sel, variables)(resolved.value, builder);
435
+ builder.assignNonScalar(sink, propertyName, data);
436
+ }
437
+ function assignSelection(luvio, selection, builder, state, variables) {
438
+ const sel = getLuvioFieldNodeSelection(selection);
439
+ const { name: selectionName, kind, alias } = sel;
440
+ const propertyName = alias === undefined ? selectionName : alias;
441
+ const { source, sink } = state;
442
+ const { fields } = source;
443
+ builder.enterPath(selectionName);
444
+ switch (kind) {
445
+ case 'ScalarFieldSelection': {
446
+ builder.assignScalar(propertyName, sink, getScalarValue(selectionName, state));
447
+ break;
448
+ }
449
+ case 'ObjectFieldSelection': {
450
+ // regular field, not spanning
451
+ const field = propertyLookup(builder, selectionName, fields);
452
+ if (field.state === PropertyLookupResultState.Missing) {
453
+ break;
454
+ }
455
+ const resolved = resolveLink(builder, field.value);
456
+ if (resolved === undefined) {
457
+ break;
458
+ }
459
+ const data = getNonSpanningField(sel, builder, resolved.value);
460
+ builder.assignNonScalar(sink, propertyName, data);
461
+ break;
462
+ }
463
+ case 'CustomFieldSelection': {
464
+ if (sel.type === 'Connection') {
465
+ const recordKey = keyBuilderRecord(luvio, {
466
+ recordId: state.source.id,
467
+ });
468
+ assignConnectionSelection(luvio, builder, sink, sel, recordKey, propertyName, variables);
469
+ }
470
+ else {
471
+ const field = fields[selectionName];
472
+ const resolvedParentFieldValue = resolveLink(builder, field);
473
+ if (resolvedParentFieldValue === undefined) {
474
+ break;
475
+ }
476
+ const { value: spanningFieldResult } = resolvedParentFieldValue;
477
+ const { value: spanningFieldValue } = spanningFieldResult;
478
+ if (spanningFieldValue === null || typeof spanningFieldValue !== 'object') {
479
+ sink[propertyName] = null;
480
+ break;
481
+ }
482
+ const resolvedSpanningRecordValue = resolveLink(builder, spanningFieldValue);
483
+ if (resolvedSpanningRecordValue === undefined) {
484
+ break;
485
+ }
486
+ const data = getCustomSelection(luvio, sel, builder, {
487
+ source: resolvedSpanningRecordValue.value,
488
+ parentFieldValue: spanningFieldResult,
489
+ }, variables);
490
+ builder.assignNonScalar(sink, propertyName, data);
491
+ }
492
+ }
493
+ }
494
+ builder.exitPath();
495
+ }
496
+ function readRecordRepresentation(luvio, ast, builder, options, variables) {
497
+ const { luvioSelections } = ast;
498
+ if (luvioSelections === undefined) {
499
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
500
+ throw new Error('Empty selections not supported');
501
+ }
502
+ const sink = {};
503
+ const state = {
504
+ source: options.source,
505
+ sink,
506
+ parentFieldValue: options.parentFieldValue,
507
+ };
508
+ for (let i = 0, len = luvioSelections.length; i < len; i += 1) {
509
+ assignSelection(luvio, luvioSelections[i], builder, state, variables);
510
+ }
511
+ return sink;
512
+ }
513
+ const createRead$3 = (luvio, ast, variables) => {
514
+ return (data, builder) => {
515
+ return readRecordRepresentation(luvio, ast, builder, {
516
+ source: data,
517
+ parentFieldValue: undefined,
518
+ }, variables);
519
+ };
520
+ };
521
+
522
+ const createIngest$3 = (ast, variables) => {
523
+ const { type } = ast;
524
+ switch (type) {
525
+ case CUSTOM_FIELD_NODE_TYPE:
526
+ return createIngest$4(ast, variables);
527
+ case CONNECTION_NODE_TYPE:
528
+ return createIngest$1(ast, keyBuilder(ast, variables), variables);
529
+ }
530
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
531
+ throw new Error(`Unsupported type: "${type}"`);
532
+ };
533
+
534
+ function merge(existing, incoming) {
535
+ if (existing === undefined) {
536
+ return incoming;
537
+ }
538
+ // Merge existing and incoming values together
539
+ return {
540
+ ...existing,
541
+ ...incoming,
542
+ };
543
+ }
544
+
545
+ function resolveValue(ast, variables, source) {
546
+ const { alias } = ast;
547
+ const propertyName = render(ast, variables);
548
+ if (process.env.NODE_ENV !== 'production') {
549
+ if (alias !== undefined && alias in source) {
550
+ throw new Error(`Invalid alias "${alias}" passed to "equal" function. All aliases need to be normalized before calling equal`);
551
+ }
552
+ }
553
+ return source[propertyName];
554
+ }
555
+ function linkEquals(ast, variables, existing, incoming) {
556
+ const value = resolveValue(ast, variables, existing);
557
+ if (value === undefined) {
558
+ return false;
559
+ }
560
+ const incomingLink = resolveValue(ast, variables, incoming);
561
+ if (process.env.NODE_ENV !== 'production') {
562
+ if (incomingLink === undefined) {
563
+ throw new Error('Unexpected undefined link');
564
+ }
565
+ }
566
+ return value.__ref === incomingLink.__ref;
567
+ }
568
+ function scalarFieldEquals(ast, variables, existing, incoming) {
569
+ const { name } = ast;
570
+ const value = existing[name];
571
+ if (value === undefined) {
572
+ return false;
573
+ }
574
+ return value === resolveValue(ast, variables, incoming);
575
+ }
576
+ function equals(ast, variables, existing, incoming) {
577
+ const selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
578
+ for (let i = 0, len = selections.length; i < len; i += 1) {
579
+ const sel = getLuvioFieldNodeSelection(selections[i]);
580
+ if (sel.kind === 'ScalarFieldSelection') {
581
+ if (scalarFieldEquals(sel, variables, existing, incoming) === false) {
582
+ return false;
583
+ }
584
+ }
585
+ else {
586
+ if (linkEquals(sel, variables, existing, incoming) === false) {
587
+ return false;
588
+ }
589
+ }
590
+ }
591
+ return true;
592
+ }
593
+
594
+ const DEFAULT_GRAPHQL_TTL = 30000;
595
+ const GRAPHQL_INGEST_VERSION = 'GRAPHQL_INGEST_VERSION_1';
596
+ function createIngest$2(ast, variables) {
597
+ if (ast.kind === 'CustomFieldSelection') {
598
+ return createIngest$3(ast, variables);
599
+ }
600
+ return genericCreateIngest(ast, variables);
601
+ }
602
+ function publishDataIfChanged(params) {
603
+ const { store, key, ast, incoming, luvio, variables } = params;
604
+ const existing = store.readEntry(key);
605
+ if (existing === undefined || equals(ast, variables, existing, incoming) === false) {
606
+ const newData = merge(existing, incoming);
607
+ luvio.storePublish(key, newData);
608
+ }
609
+ }
610
+ function genericCreateIngest(ast, variables) {
611
+ let selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
612
+ return (data, path, luvio, store, timestamp) => {
613
+ const { fullPath } = path;
614
+ for (let i = 0, len = selections.length; i < len; i += 1) {
615
+ const sel = getLuvioFieldNodeSelection(selections[i]);
616
+ if (sel.kind === 'ScalarFieldSelection') {
617
+ continue;
618
+ }
619
+ const { name: fieldName, alias } = sel;
620
+ const readPropertyName = alias === undefined ? fieldName : alias;
621
+ const propertyFullPath = `${fullPath}__${fieldName}`;
622
+ const writePropertyName = render(sel, variables);
623
+ const childPath = {
624
+ parent: {
625
+ existing: null,
626
+ key: fullPath,
627
+ data,
628
+ },
629
+ propertyName: readPropertyName,
630
+ fullPath: propertyFullPath,
631
+ };
632
+ data[writePropertyName] = createIngest$2(sel, variables)(data[readPropertyName], childPath, luvio, store, timestamp);
633
+ if (writePropertyName !== readPropertyName && data[readPropertyName] !== undefined) {
634
+ delete data[readPropertyName];
635
+ }
636
+ }
637
+ publishDataIfChanged({
638
+ ast,
639
+ luvio,
640
+ store,
641
+ key: fullPath,
642
+ variables: {},
643
+ incoming: data,
644
+ });
645
+ if (data && data.__typename !== undefined) {
646
+ luvio.publishStoreMetadata(fullPath, {
647
+ representationName: data.__typename,
648
+ namespace: namespace,
649
+ ttl: DEFAULT_GRAPHQL_TTL,
650
+ version: GRAPHQL_INGEST_VERSION,
651
+ });
652
+ }
653
+ return {
654
+ __ref: fullPath,
655
+ };
656
+ };
657
+ }
658
+
659
+ const CONNECTION_NODE_TYPE = 'Connection';
660
+ const TYPENAME_FIELD$1 = '__typename';
661
+ const PAGE_INFO_REQUIRED_FIELDS = ['hasNextPage', 'hasPreviousPage'];
662
+ const EDGE_REQUIRED_FIELDS = ['cursor'];
663
+ const PROPERTY_NAME_EDGES = 'edges';
664
+ const PROPERTY_NAME_PAGE_INFO = 'pageInfo';
665
+ const PROPERTY_NAME_TOTAL_COUNT = 'totalCount';
666
+ function keyBuilder(ast, variables) {
667
+ const { arguments: args, name } = ast;
668
+ if (args === undefined) {
669
+ return `${namespace}::${CONNECTION_NODE_TYPE}:${name}()`;
670
+ }
671
+ const serialized = render$1(args, variables);
672
+ return `${namespace}::${CONNECTION_NODE_TYPE}:${name}(${serialized})`;
673
+ }
674
+ function selectEdges(luvio, builder, ast, links, variables) {
675
+ const sink = [];
676
+ for (let i = 0, len = links.length; i < len; i += 1) {
677
+ builder.enterPath(i);
678
+ const link = links[i];
679
+ const resolved = followLink(luvio, ast, builder, link, variables);
680
+ builder.assignNonScalar(sink, i, resolved);
681
+ builder.exitPath();
682
+ }
683
+ return sink;
684
+ }
685
+ const createRead$2 = (luvio, ast, variables) => {
686
+ const selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
687
+ return (source, builder) => {
688
+ const sink = {};
689
+ for (let i = 0, len = selections.length; i < len; i += 1) {
690
+ const sel = getLuvioFieldNodeSelection(selections[i]);
691
+ const { name, kind } = sel;
692
+ if (kind === 'ScalarFieldSelection') {
693
+ readScalarFieldSelection(builder, source, name, sink);
694
+ continue;
695
+ }
696
+ const readPropertyName = render(sel, variables);
697
+ builder.enterPath(readPropertyName);
698
+ const edges = resolveLink(builder, source[readPropertyName]);
699
+ if (edges === undefined) {
700
+ builder.exitPath();
701
+ break;
702
+ }
703
+ if (readPropertyName === PROPERTY_NAME_EDGES) {
704
+ const data = selectEdges(luvio, builder, sel, edges.value, variables);
705
+ builder.assignNonScalar(sink, readPropertyName, data);
706
+ }
707
+ else {
708
+ if (process.env.NODE_ENV !== 'production') {
709
+ throw new Error('Not supported');
710
+ }
711
+ }
712
+ builder.exitPath();
713
+ }
714
+ return sink;
715
+ };
716
+ };
717
+ function ingestConnectionProperty(sel, data, path, luvio, store, timestamp, variables) {
718
+ const propertyName = sel.name;
719
+ switch (propertyName) {
720
+ case PROPERTY_NAME_EDGES:
721
+ return ingestConnectionEdges(sel, data, path, luvio, store, timestamp, variables);
722
+ }
723
+ }
724
+ function ingestConnectionEdges(sel, data, path, luvio, store, timestamp, variables) {
725
+ const key = path.fullPath;
726
+ const existing = store.readEntry(key);
727
+ let hasChanges = existing === undefined || data.length !== existing.length;
728
+ for (let i = 0, len = data.length; i < len; i += 1) {
729
+ const incomingItem = (data[i] = createIngest$2(sel, variables)(data[i], {
730
+ parent: {
731
+ data,
732
+ existing: null,
733
+ key,
734
+ },
735
+ propertyName: i,
736
+ fullPath: `${key}__${i}`,
737
+ }, luvio, store, timestamp));
738
+ const existingItem = existing !== undefined ? existing[i] : undefined;
739
+ if (existingItem === undefined || existingItem.__ref !== incomingItem.__ref) {
740
+ hasChanges = true;
741
+ }
742
+ }
743
+ if (hasChanges === true) {
744
+ luvio.storePublish(key, data);
745
+ }
746
+ luvio.publishStoreMetadata(key, {
747
+ representationName: CONNECTION_NODE_TYPE,
748
+ namespace: namespace,
749
+ ttl: DEFAULT_GRAPHQL_TTL,
750
+ version: GRAPHQL_INGEST_VERSION,
751
+ });
752
+ return {
753
+ __ref: key,
754
+ };
755
+ }
756
+ const createIngest$1 = (ast, key, variables) => {
757
+ const { luvioSelections } = ast;
758
+ const selections = luvioSelections === undefined ? [] : luvioSelections;
759
+ return (data, path, luvio, store, timestamp) => {
760
+ for (let i = 0, len = selections.length; i < len; i += 1) {
761
+ const sel = getLuvioFieldNodeSelection(selections[i]);
762
+ const { kind } = sel;
763
+ const propertyName = sel.name;
764
+ if (kind !== 'ObjectFieldSelection') {
765
+ continue;
766
+ }
767
+ data[propertyName] = ingestConnectionProperty(sel, data[propertyName], {
768
+ parent: {
769
+ existing: null,
770
+ key,
771
+ data,
772
+ },
773
+ fullPath: `${key}__${propertyName}`,
774
+ propertyName,
775
+ }, luvio, store, timestamp, variables);
776
+ }
777
+ publishDataIfChanged({
778
+ key,
779
+ luvio,
780
+ store,
781
+ incoming: data,
782
+ variables: {},
783
+ ast,
784
+ });
785
+ const typeName = data.__typename;
786
+ luvio.publishStoreMetadata(key, {
787
+ representationName: typeName,
788
+ namespace: namespace,
789
+ ttl: DEFAULT_GRAPHQL_TTL,
790
+ version: GRAPHQL_INGEST_VERSION,
791
+ });
792
+ return {
793
+ __ref: key,
794
+ };
795
+ };
796
+ };
797
+ function serialize(def, state) {
798
+ const { luvioSelections, arguments: args } = def;
799
+ if (luvioSelections === undefined) {
800
+ if (process.env.NODE_ENV !== 'production') {
801
+ throw new Error('Connection field node must have selections');
802
+ }
803
+ return '';
804
+ }
805
+ const argsString = args === undefined || args.length === 0 ? '' : `(${serializeArguments(args)})`;
806
+ const seenFields = {};
807
+ const serializedFields = [];
808
+ for (let i = 0; i < luvioSelections.length; i++) {
809
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
810
+ const { name: fieldName } = sel;
811
+ seenFields[fieldName] = true;
812
+ if (fieldName === PROPERTY_NAME_PAGE_INFO) {
813
+ serializedFields.push(serializePageInfo(sel, state));
814
+ }
815
+ else if (fieldName === PROPERTY_NAME_EDGES) {
816
+ serializedFields.push(serializeEdges(sel, state));
817
+ }
818
+ else {
819
+ serializedFields.push(serializeFieldNode(sel, state));
820
+ }
821
+ }
822
+ appendRequiredConnectionFields(seenFields, serializedFields);
823
+ return `${serializeFieldNodeName(def)}${argsString} { ${serializedFields.join(' ')} }`;
824
+ }
825
+ function serializeEdges(node, state) {
826
+ if (!isLuvioFieldNodeObjectFieldNode(node)) {
827
+ if (process.env.NODE_ENV !== 'production') {
828
+ throw new Error('PageInfo must be an ObjectFieldNode');
829
+ }
830
+ return '';
831
+ }
832
+ const { luvioSelections } = node;
833
+ if (luvioSelections === undefined)
834
+ return '';
835
+ const seenFields = {};
836
+ const serializedFields = [];
837
+ for (let i = 0; i < luvioSelections.length; i++) {
838
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
839
+ seenFields[sel.name] = true;
840
+ serializedFields.push(serializeFieldNode(sel, state));
841
+ }
842
+ appendRequiredFields(EDGE_REQUIRED_FIELDS, seenFields, serializedFields);
843
+ insertTypeName(seenFields, serializedFields);
844
+ return `${serializeFieldNodeName(node)} { ${serializedFields.join(' ')} }`;
845
+ }
846
+ function serializePageInfo(node, state) {
847
+ if (!isLuvioFieldNodeObjectFieldNode(node)) {
848
+ if (process.env.NODE_ENV !== 'production') {
849
+ throw new Error('PageInfo must be an ObjectFieldNode');
850
+ }
851
+ return '';
852
+ }
853
+ const { luvioSelections } = node;
854
+ if (luvioSelections === undefined)
855
+ return '';
856
+ const seenFields = {};
857
+ const serializedFields = [];
858
+ for (let i = 0; i < luvioSelections.length; i++) {
859
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
860
+ seenFields[sel.name] = true;
861
+ serializedFields.push(serializeFieldNode(sel, state));
862
+ }
863
+ appendRequiredFields(PAGE_INFO_REQUIRED_FIELDS, seenFields, serializedFields);
864
+ return `${serializeFieldNodeName(node)} { ${serializedFields.join(' ')} }`;
865
+ }
866
+ function appendRequiredFields(requiredFields, seenFields, result) {
867
+ for (let i = 0; i < requiredFields.length; i++) {
868
+ const fieldName = requiredFields[i];
869
+ if (seenFields[fieldName] !== true) {
870
+ result.push(fieldName);
871
+ }
872
+ }
873
+ }
874
+ function appendRequiredConnectionFields(seenFields, result) {
875
+ if (seenFields[PROPERTY_NAME_PAGE_INFO] !== true) {
876
+ result.push('pageInfo { hasNextPage hasPreviousPage }');
877
+ }
878
+ if (seenFields[PROPERTY_NAME_TOTAL_COUNT] !== true) {
879
+ result.push(PROPERTY_NAME_TOTAL_COUNT);
880
+ }
881
+ insertTypeName(seenFields, result);
882
+ }
883
+ function insertTypeName(seenFields, result) {
884
+ if (seenFields[TYPENAME_FIELD$1] !== true) {
885
+ result.unshift(TYPENAME_FIELD$1);
886
+ }
887
+ }
888
+
889
+ function createCustomFieldRead(luvio, sel, variables) {
890
+ if (sel.type === 'Connection') {
891
+ return createRead$2(luvio, sel, variables);
892
+ }
893
+ return createRead$3(luvio, sel, variables);
894
+ }
895
+ function createRead$1(luvio, ast, variables) {
896
+ if (ast.kind === 'CustomFieldSelection') {
897
+ return createCustomFieldRead(luvio, ast, variables);
898
+ }
899
+ if (ast.kind === 'FragmentSpread' ||
900
+ ast.kind === 'InlineFragment' ||
901
+ ast.kind === 'ScalarFieldSelection') {
902
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
903
+ throw new Error('"FragmentSpread" and "InlineFragment" currently not supported');
904
+ }
905
+ return genericCreateRead(luvio, ast, variables);
906
+ }
907
+ const genericCreateRead = (luvio, ast, variables) => {
908
+ const selections = ast.luvioSelections === undefined ? [] : ast.luvioSelections;
909
+ return (source, builder) => {
910
+ const sink = {};
911
+ for (let i = 0, len = selections.length; i < len; i += 1) {
912
+ const sel = getLuvioFieldNodeSelection(selections[i]);
913
+ const { name: fieldName, alias } = sel;
914
+ const propertyName = alias === undefined ? fieldName : alias;
915
+ builder.enterPath(fieldName);
916
+ switch (sel.kind) {
917
+ case 'ScalarFieldSelection':
918
+ readScalarFieldSelection(builder, source, fieldName, sink);
919
+ break;
920
+ default: {
921
+ const data = followLink(luvio, sel, builder, source[render(sel, variables)], variables);
922
+ builder.assignNonScalar(sink, propertyName, data);
923
+ }
924
+ }
925
+ builder.exitPath();
926
+ }
927
+ return sink;
928
+ };
929
+ };
930
+
931
+ var PropertyLookupResultState;
932
+ (function (PropertyLookupResultState) {
933
+ PropertyLookupResultState[PropertyLookupResultState["Missing"] = 0] = "Missing";
934
+ PropertyLookupResultState[PropertyLookupResultState["Present"] = 1] = "Present";
935
+ })(PropertyLookupResultState || (PropertyLookupResultState = {}));
936
+ const objectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty;
937
+ function propertyLookup(builder, key, source) {
938
+ if (objectPrototypeHasOwnProperty.call(source, key) === false) {
939
+ builder.markMissing();
940
+ return {
941
+ state: PropertyLookupResultState.Missing,
942
+ };
943
+ }
944
+ return {
945
+ state: PropertyLookupResultState.Present,
946
+ value: source[key],
947
+ };
948
+ }
949
+ function markStoreResolveResultSeen(builder, state) {
950
+ const { redirects, resolvedKey } = state;
951
+ builder.markSeenId(resolvedKey);
952
+ const { length: len } = redirects;
953
+ if (len === 0) {
954
+ return;
955
+ }
956
+ for (let i = 0; i < len; i += 1) {
957
+ builder.markSeenId(redirects[i]);
958
+ }
959
+ }
960
+ function resolveKey(builder, key) {
961
+ const { StoreResolveResultState } = builder;
962
+ const lookup = builder.storeLookup(key);
963
+ markStoreResolveResultSeen(builder, lookup);
964
+ switch (lookup.state) {
965
+ case StoreResolveResultState.NotPresent:
966
+ builder.markMissingLink(key);
967
+ return;
968
+ case StoreResolveResultState.Stale:
969
+ builder.markStale();
970
+ return lookup;
971
+ case StoreResolveResultState.Error:
972
+ if (process.env.NODE_ENV !== 'production') {
973
+ throw new Error('TODO: Implement error links');
974
+ }
975
+ else {
976
+ return;
977
+ }
978
+ }
979
+ return lookup;
980
+ }
981
+ function resolveLink(builder, storeLink) {
982
+ const { StoreLinkStateValues } = builder;
983
+ const linkState = builder.getLinkState(storeLink);
984
+ switch (linkState.state) {
985
+ case StoreLinkStateValues.RefNotPresent:
986
+ case StoreLinkStateValues.NotPresent:
987
+ case StoreLinkStateValues.Missing:
988
+ builder.markMissing();
989
+ return;
990
+ case StoreLinkStateValues.Pending:
991
+ builder.markPending();
992
+ return;
993
+ case StoreLinkStateValues.Null:
994
+ if (process.env.NODE_ENV !== 'production') {
995
+ throw new Error(`TODO: Invalid Link State. Link on "${builder.currentPath.fullPath}"`);
996
+ }
997
+ else {
998
+ return;
999
+ }
1000
+ }
1001
+ const { key: __ref } = linkState;
1002
+ return resolveKey(builder, __ref);
1003
+ }
1004
+ function followLink(luvio, sel, builder, storeLink, variables) {
1005
+ const linkState = resolveLink(builder, storeLink);
1006
+ if (linkState === undefined) {
1007
+ return;
1008
+ }
1009
+ const { value } = linkState;
1010
+ return createRead$1(luvio, sel, variables)(value, builder);
1011
+ }
1012
+ function getLuvioFieldNodeSelection(ast) {
1013
+ const { kind } = ast;
1014
+ if (kind === 'FragmentSpread' || kind === 'InlineFragment') {
1015
+ if (process.env.NODE_ENV !== 'production') {
1016
+ throw new Error('"FragmentSpread" and "InlineFragment" currently not supported');
1017
+ }
1018
+ }
1019
+ return ast;
1020
+ }
1021
+
1022
+ const TYPENAME_FIELD = '__typename';
1023
+ const KIND_OBJECT_FIELD_SELECTION = 'ObjectFieldSelection';
1024
+ function serializeFieldNodeName(node) {
1025
+ const { name, alias } = node;
1026
+ return alias === undefined ? `${name}` : `${alias}: ${name}`;
1027
+ }
1028
+ function serializeSelections(selections, state) {
1029
+ if (selections === undefined) {
1030
+ return '';
1031
+ }
1032
+ let str = '';
1033
+ for (let i = 0, len = selections.length; i < len; i += 1) {
1034
+ const def = serializeFieldNode(selections[i], state);
1035
+ str = `${str}${def}`;
1036
+ }
1037
+ return str;
1038
+ }
1039
+ function serializeFieldNode(def, state) {
1040
+ const { kind } = def;
1041
+ switch (kind) {
1042
+ case 'ObjectFieldSelection':
1043
+ return serializeObjectFieldNode(def, state);
1044
+ case 'CustomFieldSelection':
1045
+ return serializeCustomFieldNode(def, state);
1046
+ case 'ScalarFieldSelection':
1047
+ return serializeScalarFieldNode(def);
1048
+ }
1049
+ if (process.env.NODE_ENV !== 'production') {
1050
+ throw new Error(`Unable to serialize graphql query, unsupported field node "${kind}"`);
1051
+ }
1052
+ return '';
1053
+ }
1054
+ function serializeObjectFieldNode(def, state) {
1055
+ const { luvioSelections, arguments: defArgs } = def;
1056
+ const args = defArgs === undefined ? '' : `(${serializeArguments(defArgs)})`;
1057
+ return `${serializeFieldNodeName(def)}${args} { ${TYPENAME_FIELD} ${serializeSelections(luvioSelections, state)} }`;
1058
+ }
1059
+ function serializeCustomFieldNode(def, state) {
1060
+ const { type } = def;
1061
+ switch (type) {
1062
+ case 'Connection':
1063
+ return serialize(def, state);
1064
+ case 'Record':
1065
+ return serializeCustomFieldRecord(def, state);
1066
+ }
1067
+ if (process.env.NODE_ENV !== 'production') {
1068
+ throw new Error(`Unable to serialize graphql query, unsupported CustomField type "${type}"`);
1069
+ }
1070
+ return '';
1071
+ }
1072
+ function serializeScalarFieldNode(def) {
1073
+ return `${serializeFieldNodeName(def)}, `;
1074
+ }
1075
+ function serializeRecordSelections(selections, state) {
1076
+ if (selections === undefined) {
1077
+ return '';
1078
+ }
1079
+ let str = '';
1080
+ for (let i = 0, len = selections.length; i < len; i += 1) {
1081
+ const sel = getLuvioFieldNodeSelection(selections[i]);
1082
+ const def = isLuvioFieldNodeObjectFieldNode(sel)
1083
+ ? serializeObjectFieldNodeUnderRecord(sel)
1084
+ : serializeFieldNode(sel, state);
1085
+ str = `${str}${def}`;
1086
+ }
1087
+ return str;
1088
+ }
1089
+ function isLuvioFieldNodeObjectFieldNode(node) {
1090
+ return node.kind === KIND_OBJECT_FIELD_SELECTION;
1091
+ }
1092
+ function serializeObjectFieldNodeUnderRecord(node) {
1093
+ const { luvioSelections, arguments: nodeArgs, name: nodeName } = node;
1094
+ const fields = {};
1095
+ let result = ``;
1096
+ if (luvioSelections === undefined) {
1097
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
1098
+ throw new Error('selection should not be empty for ObjectFieldNodeUnderRecord');
1099
+ }
1100
+ const luvioSelectionsLength = luvioSelections.length;
1101
+ for (let i = 0; i < luvioSelectionsLength; i++) {
1102
+ const sel = getLuvioFieldNodeSelection(luvioSelections[i]);
1103
+ const { name } = sel;
1104
+ if (sel.kind !== 'ScalarFieldSelection') {
1105
+ if (process.env.NODE_ENV !== 'production') {
1106
+ throw new Error(`Invalid selection for ${nodeName}. ${nodeName} appears to be a Record, but is missing @resource(type: "Record")`);
1107
+ }
1108
+ }
1109
+ if (RECORD_DEFAULT_FIELD_VALUES.indexOf(name) === -1) {
1110
+ if (process.env.NODE_ENV !== 'production') {
1111
+ throw new Error(`Invalid selection for "${nodeName}.${name}". Only ${RECORD_DEFAULT_FIELD_VALUES.join(', ')} are supported. If "${nodeName}" is a spanning Record, please include @resource(type: "Record") directive.`);
1112
+ }
1113
+ }
1114
+ fields[name] = true;
1115
+ result = `${result}${serializeScalarFieldNode(sel)}`;
1116
+ }
1117
+ result = appendRecordDefaultFieldValues(result, fields);
1118
+ const args = nodeArgs === undefined ? '' : `(${serializeArguments(nodeArgs)})`;
1119
+ return `${serializeFieldNodeName(node)}${args} { ${TYPENAME_FIELD} ${result} }`;
1120
+ }
1121
+ function appendRecordDefaultFieldValues(fieldValues, fieldValuesMap) {
1122
+ let str = fieldValues;
1123
+ for (let i = 0, len = RECORD_DEFAULT_FIELD_VALUES.length; i < len; i++) {
1124
+ const defaultField = RECORD_DEFAULT_FIELD_VALUES[i];
1125
+ if (fieldValuesMap[defaultField] !== true) {
1126
+ str = `${str}${defaultField}, `;
1127
+ }
1128
+ }
1129
+ return str;
1130
+ }
1131
+ function appendSpanningRecordIds(luvioSelections) {
1132
+ if (luvioSelections === undefined) {
1133
+ return undefined;
1134
+ }
1135
+ //add record ref ids
1136
+ let spanningRecordIdFields = [];
1137
+ let selections = luvioSelections;
1138
+ //Find all fields with a record type declaration and add the corresponding
1139
+ //reference ID.
1140
+ // TODO [W-11342283]: This approach uses a naming pattern that is brittle and not
1141
+ // guaranteed to work in the long run. A more correct approach is to thread through
1142
+ // ObjectInfo schemas and use its mapping definitions.
1143
+ for (let i = 0; i < selections.length; i++) {
1144
+ const selection = selections[i];
1145
+ if (selection.kind === 'CustomFieldSelection' && selection.type === 'Record') {
1146
+ const customFieldMatches = selection.name.match(/(.*__)r$/);
1147
+ if (customFieldMatches) {
1148
+ // For `FSL__Related_Service__r {...}`, inject `FSL__Related_Service__c { value } as a peer field`
1149
+ const [, captureGroup] = customFieldMatches;
1150
+ spanningRecordIdFields.push(`${captureGroup}c`);
1151
+ }
1152
+ else {
1153
+ // For `Owner {...}`, inject `OwnerId { value } as a peer field`
1154
+ spanningRecordIdFields.push(`${selection.name}Id`);
1155
+ }
1156
+ }
1157
+ }
1158
+ //Add all missing reference IDs to the set of selections
1159
+ for (let i = 0; i < spanningRecordIdFields.length; i++) {
1160
+ const idField = spanningRecordIdFields[i];
1161
+ if (selections.findIndex((e) => e.kind === 'ObjectFieldSelection' && e.name === idField) >
1162
+ -1) {
1163
+ continue;
1164
+ }
1165
+ selections.push({
1166
+ kind: 'ObjectFieldSelection',
1167
+ name: idField,
1168
+ luvioSelections: [{ kind: 'ScalarFieldSelection', name: 'value' }],
1169
+ });
1170
+ }
1171
+ return selections;
1172
+ }
1173
+ function serializeCustomFieldRecord(def, state) {
1174
+ const { luvioSelections } = def;
1175
+ if (state.fragments[defaultRecordFieldsFragmentName] === undefined) {
1176
+ state.fragments[defaultRecordFieldsFragmentName] = defaultRecordFieldsFragment;
1177
+ }
1178
+ const selections = appendSpanningRecordIds(luvioSelections);
1179
+ return `${serializeFieldNodeName(def)} { ${serializeRecordSelections(selections, state)} ...${defaultRecordFieldsFragmentName} }`;
1180
+ }
1181
+ function serializeArguments(argDefinitions) {
1182
+ if (argDefinitions === undefined) {
1183
+ return '';
1184
+ }
1185
+ let str = '';
1186
+ for (let i = 0, len = argDefinitions.length; i < len; i += 1) {
1187
+ let def = serializeArgument(argDefinitions[i]);
1188
+ if (i !== 0) {
1189
+ def = ` ${def}`;
1190
+ }
1191
+ str = `${str}${def}`;
1192
+ }
1193
+ return str;
1194
+ }
1195
+ function serializeArgument(argDefinition) {
1196
+ const { name, value } = argDefinition;
1197
+ return `${name}: ${serializeValueNode(value)}`;
1198
+ }
1199
+
1200
+ function serializeValueNode(valueDefinition) {
1201
+ const { kind } = valueDefinition;
1202
+ switch (kind) {
1203
+ case 'ObjectValue':
1204
+ return serializeObjectValueNode(valueDefinition);
1205
+ case 'StringValue':
1206
+ return serializeStringValueNode(valueDefinition);
1207
+ case 'NullValue':
1208
+ return 'null';
1209
+ case 'FloatValue':
1210
+ case 'IntValue':
1211
+ case 'BooleanValue':
1212
+ case 'EnumValue':
1213
+ return valueDefinition.value;
1214
+ case 'Variable':
1215
+ return serializeVariableNode(valueDefinition);
1216
+ case 'ListValue':
1217
+ return serializeListValueNode(valueDefinition);
1218
+ }
1219
+ if (process.env.NODE_ENV !== 'production') {
1220
+ throw new Error(`Unable to serialize graphql query, unsupported value node "${kind}"`);
1221
+ }
1222
+ }
1223
+ function serializeVariableNode(variableNode) {
1224
+ return `$${variableNode.name}`;
1225
+ }
1226
+ function serializeListValueNode(listNode) {
1227
+ const { values } = listNode;
1228
+ if (values.length === 0) {
1229
+ return '';
1230
+ }
1231
+ let str = '';
1232
+ for (let i = 0, len = values.length; i < len; i += 1) {
1233
+ str = `${str}${serializeValueNode(values[i])}, `;
1234
+ }
1235
+ return `[${str.substring(0, str.length - 2)}]`;
1236
+ }
1237
+ function serializeStringValueNode(literalValueNode) {
1238
+ return `"${literalValueNode.value}"`;
1239
+ }
1240
+ function serializeObjectValueNode(objectValueDefinition) {
1241
+ const { fields } = objectValueDefinition;
1242
+ let str = [];
1243
+ const fieldKeys = keys(fields);
1244
+ for (let i = 0, len = fieldKeys.length; i < len; i += 1) {
1245
+ const fieldKey = fieldKeys[i];
1246
+ str.push(`${fieldKey}: ${serializeValueNode(fields[fieldKey])}`);
1247
+ }
1248
+ return `{ ${str.join(', ')} }`;
1249
+ }
1250
+ function serializeVariableDefinitions(definitons) {
1251
+ if (definitons === undefined || definitons.length === 0) {
1252
+ return '';
1253
+ }
1254
+ let str = '';
1255
+ for (let i = 0, len = definitons.length; i < len; i += 1) {
1256
+ const def = serializeVariableDefinitionNode(definitons[i]);
1257
+ str = `${str}${def}, `;
1258
+ }
1259
+ return ` (${str.substring(0, str.length - 2)})`;
1260
+ }
1261
+ function serializeVariableDefinitionNode(def) {
1262
+ const { variable, type, defaultValue } = def;
1263
+ return defaultValue === undefined
1264
+ ? `$${variable.name}: ${serializeTypeNode(type)}`
1265
+ : `$${variable.name}: ${serializeTypeNode(type)} = ${serializeValueNode(defaultValue)}`;
1266
+ }
1267
+ function serializeTypeNode(type) {
1268
+ const { kind } = type;
1269
+ switch (kind) {
1270
+ case 'NamedType':
1271
+ return serializeNamedTypeNode(type);
1272
+ case 'ListType':
1273
+ return serializeListTypeNode(type);
1274
+ }
1275
+ if (process.env.NODE_ENV !== 'production') {
1276
+ throw new Error(`Unable to serialize graphql query, unsupported variable definition type node "${type.kind}"`);
1277
+ }
1278
+ return '';
1279
+ }
1280
+ function serializeNamedTypeNode(type) {
1281
+ return type.name;
1282
+ }
1283
+ function serializeListTypeNode(type) {
1284
+ return `[${serializeTypeNode(type.type)}]`;
1285
+ }
1286
+ function serializeOperationNode(def, state) {
1287
+ const { kind } = def;
1288
+ switch (kind) {
1289
+ case 'OperationDefinition':
1290
+ return serializeOperationDefinition(def, state);
1291
+ }
1292
+ if (process.env.NODE_ENV !== 'production') {
1293
+ throw new Error(`Unable to serialize graphql query, unsupported OperationDefinition type "${kind}"`);
1294
+ }
1295
+ }
1296
+ function serializeOperationDefinition(def, state) {
1297
+ const { operation, luvioSelections, name, variableDefinitions } = def;
1298
+ const nameStr = name === undefined ? ' ' : ` ${name} `;
1299
+ return `${operation}${nameStr}${serializeVariableDefinitions(variableDefinitions)}{ ${TYPENAME_FIELD} ${serializeSelections(luvioSelections, state)} }`;
1300
+ }
1301
+ function applyFragments(str, fragments) {
1302
+ let appliedString = str;
1303
+ const fragmentNames = Object.keys(fragments);
1304
+ for (let i = 0, len = fragmentNames.length; i < len; i += 1) {
1305
+ const name = fragmentNames[i];
1306
+ appliedString = `${appliedString} ${fragments[name]}`;
1307
+ }
1308
+ return appliedString;
1309
+ }
1310
+ function astToString(ast) {
1311
+ const { definitions } = ast;
1312
+ const state = {
1313
+ fragments: {},
1314
+ };
1315
+ let str = '';
1316
+ for (let i = 0, len = definitions.length; i < len; i += 1) {
1317
+ const def = serializeOperationNode(definitions[i], state);
1318
+ str = `${str}${def}`;
1319
+ }
1320
+ return applyFragments(str, state.fragments);
1321
+ }
1322
+
1323
+ function isGraphQLVariables(unknown) {
1324
+ return untrustedIsObject(unknown);
1325
+ }
1326
+ function validateVariableDefinitions(definitons, variables) {
1327
+ const errors = [];
1328
+ for (let i = 0, len = definitons.length; i < len; i += 1) {
1329
+ const { variable, type, defaultValue } = definitons[i];
1330
+ const value = getVariableValue(variable.name, variables, defaultValue);
1331
+ if (value === undefined) {
1332
+ errors.push(`Variable $${variable.name} has an undefined value provided for it.`);
1333
+ }
1334
+ if (type.kind === 'NonNullType' && value === null) {
1335
+ errors.push(`Expected a non-null value to be provided as value for $${variable.name}`);
1336
+ }
1337
+ if (type.kind === 'ListType' && value !== null && !Array.isArray(value)) {
1338
+ errors.push(`Expected a list to be provided as value for $${variable.name}`);
1339
+ }
1340
+ }
1341
+ return errors;
1342
+ }
1343
+ function getVariableValue(name, variables, defaultValue) {
1344
+ if (name in variables) {
1345
+ return variables[name];
1346
+ }
1347
+ if (defaultValue === undefined) {
1348
+ return null;
1349
+ }
1350
+ return defaultValue;
1351
+ }
1352
+
1353
+ function validate$1(ast, variables) {
1354
+ const { variableDefinitions } = ast;
1355
+ const errors = [];
1356
+ if (variableDefinitions !== undefined) {
1357
+ errors.push(...validateVariableDefinitions(variableDefinitions, variables));
1358
+ }
1359
+ return errors;
1360
+ }
1361
+
1362
+ function isLuvioDocumentNode(unknown) {
1363
+ if (untrustedIsObject(unknown) === true &&
1364
+ hasOwnProperty.call(unknown, 'kind') === true &&
1365
+ hasOwnProperty.call(unknown, 'definitions') === true) {
1366
+ return (typeof unknown.kind === 'string' &&
1367
+ isArray(unknown.definitions));
1368
+ }
1369
+ return false;
1370
+ }
1371
+ const createRead = (luvio, ast, variables) => {
1372
+ const definitions = ast.definitions === undefined ? [] : ast.definitions;
1373
+ return (source, builder) => {
1374
+ builder.enterPath('data');
1375
+ let sink = {};
1376
+ for (let i = 0, len = definitions.length; i < len; i += 1) {
1377
+ const def = definitions[i];
1378
+ if (def.kind !== 'OperationDefinition') {
1379
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
1380
+ throw new Error(`Unsupported document definition "${def.kind}"`);
1381
+ }
1382
+ const data = createRead$1(luvio, def, variables)(source, builder);
1383
+ sink = {
1384
+ ...sink,
1385
+ ...data,
1386
+ };
1387
+ }
1388
+ const gqlData = {};
1389
+ builder.assignNonScalar(gqlData, 'data', sink);
1390
+ builder.exitPath();
1391
+ builder.enterPath('errors');
1392
+ builder.assignNonScalar(gqlData, 'errors', []);
1393
+ builder.exitPath();
1394
+ return gqlData;
1395
+ };
1396
+ };
1397
+ function createIngest(ast, variables) {
1398
+ const definitions = ast.definitions === undefined ? [] : ast.definitions;
1399
+ return (data, path, luvio, store, timestamp) => {
1400
+ const key = path.fullPath;
1401
+ for (let i = 0, len = definitions.length; i < len; i += 1) {
1402
+ const def = definitions[i];
1403
+ if (def.kind !== 'OperationDefinition') {
1404
+ // eslint-disable-next-line @salesforce/lds/no-error-in-production
1405
+ throw new Error(`Unsupported document definition "${def.kind}"`);
1406
+ }
1407
+ createIngest$2(def, variables)(data, {
1408
+ parent: null,
1409
+ fullPath: key,
1410
+ propertyName: null,
1411
+ }, luvio, store, timestamp);
1412
+ }
1413
+ return {
1414
+ __ref: key,
1415
+ };
1416
+ };
1417
+ }
1418
+ function validate(ast, variables) {
1419
+ const errors = [];
1420
+ const { definitions } = ast;
1421
+ for (let i = 0, len = definitions.length; i < len; i += 1) {
1422
+ const def = definitions[i];
1423
+ if (def.kind !== 'OperationDefinition') {
1424
+ errors.push(`Unsupported document definition "${def.kind}"`);
1425
+ }
1426
+ else {
1427
+ errors.push(...validate$1(def, variables));
1428
+ }
1429
+ }
1430
+ return errors;
1431
+ }
1432
+
1433
+ let storeEval = undefined;
1434
+ let draftFunctions = undefined;
1435
+ const configuration = {
1436
+ setStoreEval: function (storeEvalArg) {
1437
+ storeEval = storeEvalArg;
1438
+ },
1439
+ setDraftFunctions: function (draftFuncs) {
1440
+ draftFunctions = draftFuncs;
1441
+ },
1442
+ };
1443
+
1444
+ const assignedToMe = {
1445
+ kind: 'CustomFieldSelection',
1446
+ name: 'ServiceResources',
1447
+ type: 'Connection',
1448
+ luvioSelections: [
1449
+ {
1450
+ kind: 'ObjectFieldSelection',
1451
+ name: 'edges',
1452
+ luvioSelections: [
1453
+ {
1454
+ kind: 'CustomFieldSelection',
1455
+ name: 'node',
1456
+ type: 'Record',
1457
+ luvioSelections: [
1458
+ {
1459
+ kind: 'ObjectFieldSelection',
1460
+ name: 'ServiceResourceId',
1461
+ luvioSelections: [
1462
+ {
1463
+ kind: 'ScalarFieldSelection',
1464
+ name: 'value',
1465
+ },
1466
+ ],
1467
+ },
1468
+ {
1469
+ kind: 'ObjectFieldSelection',
1470
+ name: 'ServiceAppointmentId',
1471
+ luvioSelections: [
1472
+ {
1473
+ kind: 'ScalarFieldSelection',
1474
+ name: 'value',
1475
+ },
1476
+ ],
1477
+ },
1478
+ {
1479
+ kind: 'CustomFieldSelection',
1480
+ name: 'ServiceResource',
1481
+ type: 'Record',
1482
+ luvioSelections: [
1483
+ {
1484
+ kind: 'ScalarFieldSelection',
1485
+ name: 'Id',
1486
+ },
1487
+ {
1488
+ kind: 'ObjectFieldSelection',
1489
+ name: 'RelatedRecordId',
1490
+ luvioSelections: [
1491
+ {
1492
+ kind: 'ScalarFieldSelection',
1493
+ name: 'value',
1494
+ },
1495
+ ],
1496
+ },
1497
+ ],
1498
+ },
1499
+ ],
1500
+ },
1501
+ ],
1502
+ },
1503
+ ],
1504
+ };
1505
+ function shouldInjectFields(ast) {
1506
+ let injectScope = false;
1507
+ const recordNodes = findRecordSelections(ast);
1508
+ if (recordNodes !== undefined && recordNodes.length > 0) {
1509
+ for (const recordNode of recordNodes) {
1510
+ if (recordNode.arguments !== undefined) {
1511
+ for (const argument of recordNode.arguments) {
1512
+ if (argument.name === 'scope' &&
1513
+ argument.value.kind === 'EnumValue' &&
1514
+ argument.value.value === 'ASSIGNEDTOME') {
1515
+ injectScope = true;
1516
+ break;
1517
+ }
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ return injectScope;
1523
+ }
1524
+ function injectFieldsGQL(ast) {
1525
+ return injectScopeFields(ast);
1526
+ }
1527
+ function swapIdsOfDocumentNode(documentnode, draftFunctions) {
1528
+ const recordNodes = findRecordSelections(documentnode);
1529
+ recordNodes.forEach((recordConnection) => {
1530
+ swapIdsOfFieldNode(recordConnection, draftFunctions);
1531
+ });
1532
+ return documentnode;
1533
+ }
1534
+ function swapIdsOfFieldNode(selectionNode, draftFunctions) {
1535
+ if (isCustomFieldNode(selectionNode) &&
1536
+ selectionNode.type === 'Connection' &&
1537
+ selectionNode.arguments !== undefined &&
1538
+ selectionNode.arguments.some((argment) => argment.name === 'where')) {
1539
+ const swappedArguments = selectionNode.arguments.map((argument) => {
1540
+ if (argument.name === 'where') {
1541
+ return {
1542
+ ...argument,
1543
+ value: swapIdsOfValueNode(argument.value, draftFunctions.isDraftId, draftFunctions.getCanonicalId),
1544
+ };
1545
+ }
1546
+ else {
1547
+ return argument;
1548
+ }
1549
+ });
1550
+ selectionNode.arguments = swappedArguments;
1551
+ }
1552
+ if (selectionNode.luvioSelections !== undefined) {
1553
+ for (const childSelectionNode of selectionNode.luvioSelections) {
1554
+ if (isCustomFieldNode(childSelectionNode) ||
1555
+ isObjectFieldSelection(childSelectionNode)) {
1556
+ swapIdsOfFieldNode(childSelectionNode, draftFunctions);
1557
+ }
1558
+ }
1559
+ }
1560
+ }
1561
+ function swapIdsOfValueNode(valueNode, isDraftId, idMapper) {
1562
+ switch (valueNode.kind) {
1563
+ case Kind.OBJECT: {
1564
+ const swappedObjectValueNode = {};
1565
+ for (const key of keys(valueNode.fields)) {
1566
+ swappedObjectValueNode[key] = swapIdsOfValueNode(valueNode.fields[key], isDraftId, idMapper);
1567
+ }
1568
+ return {
1569
+ kind: 'ObjectValue',
1570
+ fields: swappedObjectValueNode,
1571
+ };
1572
+ }
1573
+ case Kind.LIST: {
1574
+ const listValueNodes = [];
1575
+ for (const child of valueNode.values) {
1576
+ listValueNodes.push(swapIdsOfValueNode(child, isDraftId, idMapper));
1577
+ }
1578
+ return {
1579
+ kind: 'ListValue',
1580
+ values: listValueNodes,
1581
+ };
1582
+ }
1583
+ case Kind.STRING: {
1584
+ if (!isDraftId(valueNode.value)) {
1585
+ return valueNode;
1586
+ }
1587
+ return {
1588
+ kind: 'StringValue',
1589
+ value: idMapper(valueNode.value),
1590
+ block: false,
1591
+ };
1592
+ }
1593
+ default:
1594
+ return {
1595
+ ...valueNode,
1596
+ };
1597
+ }
1598
+ }
1599
+ function injectScopeFields(ast) {
1600
+ const modifiedDocumentNode = {
1601
+ kind: 'Document',
1602
+ definitions: [
1603
+ {
1604
+ kind: 'OperationDefinition',
1605
+ operation: 'query',
1606
+ luvioSelections: [
1607
+ {
1608
+ kind: 'ObjectFieldSelection',
1609
+ name: 'uiapi',
1610
+ luvioSelections: [
1611
+ {
1612
+ kind: 'ObjectFieldSelection',
1613
+ name: 'query',
1614
+ luvioSelections: [],
1615
+ },
1616
+ ],
1617
+ },
1618
+ ],
1619
+ },
1620
+ ],
1621
+ };
1622
+ const modifiedSelections = [];
1623
+ const recordNodes = findRecordSelections(ast);
1624
+ if (recordNodes !== undefined && recordNodes.length > 0) {
1625
+ // each record node represent a connection
1626
+ for (const recordNode of recordNodes) {
1627
+ modifiedSelections.push(injectConnectionForScope(recordNode));
1628
+ }
1629
+ }
1630
+ const queryNode = modifiedDocumentNode.definitions
1631
+ .filter(isOperationDefinition)
1632
+ .reduce(flatMap(luvioSelections), [])
1633
+ .filter(isObjectFieldSelection)
1634
+ .filter(named('uiapi'))
1635
+ .reduce(flatMap(luvioSelections), [])
1636
+ .filter(isObjectFieldSelection)
1637
+ .filter(named('query'))[0];
1638
+ queryNode.luvioSelections.push(...modifiedSelections);
1639
+ return ast;
1640
+ }
1641
+ function injectConnectionForScope(connectionNode) {
1642
+ if (connectionNode.name === 'ServiceAppointment') {
1643
+ if (connectionNode.arguments !== undefined) {
1644
+ for (const argument of connectionNode.arguments) {
1645
+ if (argument.name === 'scope' &&
1646
+ argument.value.kind === 'EnumValue' &&
1647
+ argument.value.value === 'ASSIGNEDTOME') {
1648
+ const injectedConnctionNode = {
1649
+ ...connectionNode,
1650
+ };
1651
+ if (injectedConnctionNode.luvioSelections !== undefined) {
1652
+ const injectedNodes = injectedConnctionNode.luvioSelections
1653
+ .filter(isObjectFieldSelection)
1654
+ .filter(named('edges'))
1655
+ .reduce(flatMap(luvioSelections), [])
1656
+ .filter(isCustomFieldNode)
1657
+ .filter(named('node'));
1658
+ if (injectedNodes !== undefined && injectedNodes.length > 0) {
1659
+ const injectedNode = injectedNodes[0];
1660
+ if (injectedNode.luvioSelections !== undefined) {
1661
+ injectedNode.luvioSelections = mergeSelectionNodes(injectedNode.luvioSelections, [assignedToMe]);
1662
+ }
1663
+ }
1664
+ }
1665
+ return injectedConnctionNode;
1666
+ }
1667
+ }
1668
+ }
1669
+ }
1670
+ return { ...connectionNode };
1671
+ }
1672
+ function mergeSelectionNodes(group1, group2) {
1673
+ let sameFields1 = [];
1674
+ let sameFields2 = [];
1675
+ let results = [];
1676
+ for (const node2 of group2) {
1677
+ if (isCustomFieldNode(node2)) {
1678
+ const nodes1SameLevel = group1
1679
+ .filter(isCustomFieldNode)
1680
+ .filter((node1) => node1.name === node2.name && node1.type === node2.type);
1681
+ if (nodes1SameLevel.length > 0) {
1682
+ sameFields1.push(...nodes1SameLevel);
1683
+ sameFields2.push(node2);
1684
+ const mergedNode = nodes1SameLevel.reduce((accu, cur) => mergeCustomFieldNodes(accu, cur), node2);
1685
+ results.push(mergedNode);
1686
+ }
1687
+ }
1688
+ else if (isObjectFieldSelection(node2)) {
1689
+ const nodes1SameLevel = group1
1690
+ .filter(isObjectFieldSelection)
1691
+ .filter((node1) => node1.name === node2.name);
1692
+ if (nodes1SameLevel.length > 0) {
1693
+ sameFields1.push(...nodes1SameLevel);
1694
+ sameFields2.push(node2);
1695
+ const mergedNode = nodes1SameLevel.reduce((accu, cur) => mergeObjectFieldNodes(accu, cur), node2);
1696
+ results.push(mergedNode);
1697
+ }
1698
+ }
1699
+ }
1700
+ if (sameFields1.length > 0) {
1701
+ const differentNodes1 = group1.filter((node) => !sameFields1.includes(node));
1702
+ results.push(...differentNodes1);
1703
+ const differentNodes2 = group2.filter((node) => !sameFields2.includes(node));
1704
+ results.push(...differentNodes2);
1705
+ }
1706
+ else {
1707
+ return group1.concat(group2);
1708
+ }
1709
+ return results;
1710
+ }
1711
+ function mergeCustomFieldNodes(node1, node2) {
1712
+ let result = node1;
1713
+ if (node1.name === node2.name && node1.kind === node2.kind && node1.type === node2.type) {
1714
+ result = {
1715
+ kind: node1.kind,
1716
+ name: node1.name,
1717
+ type: node1.type,
1718
+ luvioSelections: [],
1719
+ };
1720
+ let selections = [];
1721
+ let sameCustomFields1 = [];
1722
+ let sameCustomFields2 = [];
1723
+ let sameObjectFields1 = [];
1724
+ let sameObjectFields2 = [];
1725
+ let sameScalarFields1 = [];
1726
+ let sameScalarFields2 = [];
1727
+ if (node1.luvioSelections && node2.luvioSelections) {
1728
+ sameCustomFields1 = node1.luvioSelections
1729
+ .filter(isCustomFieldNode)
1730
+ .filter((childNode1) => {
1731
+ if (node2.luvioSelections) {
1732
+ const sames = node2.luvioSelections
1733
+ .filter(isCustomFieldNode)
1734
+ .filter((childNode2) => childNode2.name === childNode1.name);
1735
+ if (sames.length > 0) {
1736
+ const mergedNode = sames.reduce((accu, cur) => mergeCustomFieldNodes(accu, cur), childNode1);
1737
+ selections.push(mergedNode);
1738
+ result = {
1739
+ ...result,
1740
+ luvioSelections: selections,
1741
+ };
1742
+ sameCustomFields2.push(...sames);
1743
+ return true;
1744
+ }
1745
+ }
1746
+ return false;
1747
+ });
1748
+ sameObjectFields1 = node1.luvioSelections
1749
+ .filter(isObjectFieldSelection)
1750
+ .filter((childNode1) => {
1751
+ if (node2.luvioSelections) {
1752
+ const sames = node2.luvioSelections
1753
+ .filter(isObjectFieldSelection)
1754
+ .filter((childNode2) => childNode2.name === childNode1.name);
1755
+ if (sames.length > 0) {
1756
+ const mergedNode = sames.reduce((accu, cur) => mergeObjectFieldNodes(accu, cur), childNode1);
1757
+ selections.push(mergedNode);
1758
+ result = {
1759
+ ...result,
1760
+ luvioSelections: selections,
1761
+ };
1762
+ sameObjectFields2.push(...sames);
1763
+ return true;
1764
+ }
1765
+ }
1766
+ return false;
1767
+ });
1768
+ sameScalarFields1 = node1.luvioSelections
1769
+ .filter(isScalarFieldNode)
1770
+ .filter((childNode1) => {
1771
+ if (node2.luvioSelections) {
1772
+ const sames = node2.luvioSelections
1773
+ .filter(isScalarFieldNode)
1774
+ .filter((childNode2) => childNode2.name === childNode1.name);
1775
+ if (sames.length > 0) {
1776
+ const mergedNode = sames.reduce((accu, cur) => mergeScalarFieldNode(accu, cur), childNode1);
1777
+ selections.push(mergedNode);
1778
+ result = {
1779
+ ...result,
1780
+ luvioSelections: selections,
1781
+ };
1782
+ sameScalarFields2.push(...sames);
1783
+ return true;
1784
+ }
1785
+ }
1786
+ return false;
1787
+ });
1788
+ if (sameCustomFields1.length > 0 ||
1789
+ sameObjectFields1.length > 0 ||
1790
+ sameScalarFields1.length > 0) {
1791
+ const diffNodes1 = node1.luvioSelections.filter((node) => !sameCustomFields1.includes(node) &&
1792
+ !sameObjectFields1.includes(node) &&
1793
+ !sameScalarFields1.includes(node));
1794
+ selections.push(...diffNodes1);
1795
+ const diffNodes2 = node2.luvioSelections.filter((node) => !sameCustomFields2.includes(node) &&
1796
+ !sameObjectFields2.includes(node) &&
1797
+ !sameScalarFields2.includes(node));
1798
+ selections.push(...diffNodes2);
1799
+ result = {
1800
+ ...result,
1801
+ luvioSelections: selections,
1802
+ };
1803
+ }
1804
+ else {
1805
+ selections.push(...node1.luvioSelections);
1806
+ selections.push(...node2.luvioSelections);
1807
+ result = {
1808
+ ...result,
1809
+ luvioSelections: selections,
1810
+ };
1811
+ }
1812
+ }
1813
+ else {
1814
+ if (node1.luvioSelections) {
1815
+ return node1;
1816
+ }
1817
+ if (node2.luvioSelections) {
1818
+ return node2;
1819
+ }
1820
+ }
1821
+ return result;
1822
+ }
1823
+ else {
1824
+ // eslint-disable-next-line
1825
+ throw new Error('The fields name needs to be same to be merged');
1826
+ }
1827
+ }
1828
+ function mergeObjectFieldNodes(node1, node2) {
1829
+ let result = node1;
1830
+ if (node1.name === node2.name && node1.kind === node2.kind) {
1831
+ result = {
1832
+ kind: node1.kind,
1833
+ name: node1.name,
1834
+ directives: node1.directives,
1835
+ luvioSelections: [],
1836
+ };
1837
+ let selections = [];
1838
+ let sameCustomFields1 = [];
1839
+ let sameCustomFields2 = [];
1840
+ let sameObjectFields1 = [];
1841
+ let sameObjectFields2 = [];
1842
+ let sameScalarFields1 = [];
1843
+ let sameScalarFields2 = [];
1844
+ if (node1.luvioSelections && node2.luvioSelections) {
1845
+ sameCustomFields1 = node1.luvioSelections
1846
+ .filter(isCustomFieldNode)
1847
+ .filter((childNode1) => {
1848
+ if (node2.luvioSelections) {
1849
+ const sames = node2.luvioSelections
1850
+ .filter(isCustomFieldNode)
1851
+ .filter((childNode2) => childNode2.name === childNode1.name);
1852
+ if (sames.length > 0) {
1853
+ const mergedNode = sames.reduce((accu, cur) => mergeCustomFieldNodes(accu, cur), childNode1);
1854
+ selections.push(mergedNode);
1855
+ result = {
1856
+ ...result,
1857
+ luvioSelections: selections,
1858
+ };
1859
+ sameCustomFields2.push(...sames);
1860
+ return true;
1861
+ }
1862
+ }
1863
+ return false;
1864
+ });
1865
+ sameObjectFields1 = node1.luvioSelections
1866
+ .filter(isObjectFieldSelection)
1867
+ .filter((childNode1) => {
1868
+ if (node2.luvioSelections) {
1869
+ const sames = node2.luvioSelections
1870
+ .filter(isObjectFieldSelection)
1871
+ .filter((childNode2) => childNode2.name === childNode1.name);
1872
+ if (sames.length > 0) {
1873
+ const mergedNode = sames.reduce((accu, cur) => mergeObjectFieldNodes(accu, cur), childNode1);
1874
+ selections.push(mergedNode);
1875
+ result = {
1876
+ ...result,
1877
+ luvioSelections: selections,
1878
+ };
1879
+ sameObjectFields2.push(...sames);
1880
+ return true;
1881
+ }
1882
+ }
1883
+ return false;
1884
+ });
1885
+ sameScalarFields1 = node1.luvioSelections
1886
+ .filter(isScalarFieldNode)
1887
+ .filter((childNode1) => {
1888
+ if (node2.luvioSelections) {
1889
+ const sames = node2.luvioSelections
1890
+ .filter(isScalarFieldNode)
1891
+ .filter((childNode2) => childNode2.name === childNode1.name);
1892
+ if (sames.length > 0) {
1893
+ const mergedNode = sames.reduce((accu, cur) => mergeScalarFieldNode(accu, cur), childNode1);
1894
+ selections.push(mergedNode);
1895
+ result = {
1896
+ ...result,
1897
+ luvioSelections: selections,
1898
+ };
1899
+ sameScalarFields2.push(...sames);
1900
+ return true;
1901
+ }
1902
+ }
1903
+ return false;
1904
+ });
1905
+ if (sameCustomFields1.length > 0 ||
1906
+ sameObjectFields1.length > 0 ||
1907
+ sameScalarFields1.length > 0) {
1908
+ const diffNodes1 = node1.luvioSelections.filter((node) => !sameCustomFields1.includes(node) &&
1909
+ !sameObjectFields1.includes(node) &&
1910
+ !sameScalarFields1.includes(node));
1911
+ selections.push(...diffNodes1);
1912
+ const diffNodes2 = node2.luvioSelections.filter((node) => !sameCustomFields2.includes(node) &&
1913
+ !sameObjectFields2.includes(node) &&
1914
+ !sameScalarFields2.includes(node));
1915
+ selections.push(...diffNodes2);
1916
+ result = {
1917
+ ...result,
1918
+ luvioSelections: selections,
1919
+ };
1920
+ }
1921
+ else {
1922
+ selections.push(...node1.luvioSelections);
1923
+ selections.push(...node2.luvioSelections);
1924
+ result = {
1925
+ ...result,
1926
+ luvioSelections: selections,
1927
+ };
1928
+ }
1929
+ }
1930
+ else {
1931
+ if (node1.luvioSelections) {
1932
+ return node1;
1933
+ }
1934
+ if (node2.luvioSelections) {
1935
+ return node2;
1936
+ }
1937
+ }
1938
+ return result;
1939
+ }
1940
+ else {
1941
+ // eslint-disable-next-line
1942
+ throw new Error('The fields name needs to be same to be merged');
1943
+ }
1944
+ }
1945
+ function mergeScalarFieldNode(node1, node2) {
1946
+ if (node1.kind === node1.kind && node1.name === node2.name) {
1947
+ return { ...node1 };
1948
+ }
1949
+ // eslint-disable-next-line
1950
+ throw new Error('The fields name needs to be same to be merged');
1951
+ }
1952
+ function findRecordSelections(document) {
1953
+ return document.definitions
1954
+ .filter(isOperationDefinition)
1955
+ .reduce(flatMap(luvioSelections), [])
1956
+ .filter(isObjectFieldSelection)
1957
+ .filter(named('uiapi'))
1958
+ .reduce(flatMap(luvioSelections), [])
1959
+ .filter(isObjectFieldSelection)
1960
+ .filter(named('query'))
1961
+ .reduce(flatMap(luvioSelections), [])
1962
+ .filter(isCustomFieldNode);
1963
+ }
1964
+ function isOperationDefinition(node) {
1965
+ return node.kind === 'OperationDefinition';
1966
+ }
1967
+ function isObjectFieldSelection(node) {
1968
+ return node !== undefined && node.kind === 'ObjectFieldSelection';
1969
+ }
1970
+ function isCustomFieldNode(node) {
1971
+ return node !== undefined && node.kind === 'CustomFieldSelection';
1972
+ }
1973
+ function isScalarFieldNode(node) {
1974
+ return node !== undefined && node.kind === 'ScalarFieldSelection';
1975
+ }
1976
+ function flatMap(transform) {
1977
+ return (acc, current) => {
1978
+ const mapped = transform(current);
1979
+ return acc.concat(mapped);
1980
+ };
1981
+ }
1982
+ function luvioSelections(node) {
1983
+ return node.luvioSelections === undefined ? [] : node.luvioSelections;
1984
+ }
1985
+ function named(name) {
1986
+ return (node) => node.name === name;
1987
+ }
1988
+
1989
+ const adapterName = 'graphQL';
1990
+ const RECORD_REPRESENTATION_NAME = 'RecordRepresentation';
1991
+ const GRAPHQL_ROOT_KEY = `${namespace}::${representationName}`;
1992
+ function buildSnapshotRefresh(luvio, config, fragment) {
1993
+ return {
1994
+ config,
1995
+ resolve: () => buildNetworkSnapshot(luvio, config, fragment),
1996
+ };
1997
+ }
1998
+ function createFragment(luvio, query, variables) {
1999
+ return {
2000
+ kind: 'Fragment',
2001
+ synthetic: false,
2002
+ reader: true,
2003
+ version: GRAPHQL_INGEST_VERSION,
2004
+ read: createRead(luvio, query, variables),
2005
+ };
2006
+ }
2007
+ function onFetchResponseSuccess(luvio, config, response, fragment) {
2008
+ const { query, variables } = config;
2009
+ const { body } = response;
2010
+ if (body.errors && body.errors.length > 0) {
2011
+ return Promise.resolve(luvio.storeLookup({
2012
+ recordId: representationName,
2013
+ node: {
2014
+ kind: 'Fragment',
2015
+ synthetic: true,
2016
+ reader: true,
2017
+ read: (reader) => {
2018
+ const sink = {};
2019
+ reader.enterPath('data');
2020
+ reader.assignNonScalar(sink, 'data', body.data);
2021
+ reader.exitPath();
2022
+ reader.enterPath('errors');
2023
+ reader.assignNonScalar(sink, 'errors', deepFreeze(body.errors));
2024
+ reader.exitPath();
2025
+ return sink;
2026
+ },
2027
+ },
2028
+ variables: {},
2029
+ }));
2030
+ }
2031
+ const ingest = createIngest(query, variables);
2032
+ luvio.storeIngest(GRAPHQL_ROOT_KEY, ingest, body.data);
2033
+ const snapshot = luvio.storeLookup({
2034
+ recordId: GRAPHQL_ROOT_KEY,
2035
+ node: fragment,
2036
+ variables: {},
2037
+ }, buildSnapshotRefresh(luvio, config, fragment));
2038
+ return luvio.storeBroadcast().then(() => snapshot);
2039
+ }
2040
+ function getResponseCacheKeys(luvio, config, response, fragment) {
2041
+ // TODO [W-10147827]: make this more efficient
2042
+ // for now we will get the cache keys by actually ingesting then looking at
2043
+ // the seenRecords + recordId
2044
+ const { query, variables } = config;
2045
+ const { body } = response;
2046
+ if (body.errors && body.errors.length > 0) {
2047
+ return new StoreKeyMap();
2048
+ }
2049
+ const ingest = createIngest(query, variables);
2050
+ // ingest mutates the response so we have to make a copy
2051
+ const dataCopy = parse(stringify(body.data));
2052
+ luvio.storeIngest(GRAPHQL_ROOT_KEY, ingest, dataCopy);
2053
+ const snapshot = luvio.storeLookup({
2054
+ recordId: GRAPHQL_ROOT_KEY,
2055
+ node: fragment,
2056
+ variables: {},
2057
+ }, buildSnapshotRefresh(luvio, config, fragment));
2058
+ if (snapshot.state === 'Error') {
2059
+ return new StoreKeyMap();
2060
+ }
2061
+ const keys = [...snapshot.seenRecords.keysAsArray(), snapshot.recordId];
2062
+ const keySet = new StoreKeyMap();
2063
+ for (let i = 0, len = keys.length; i < len; i++) {
2064
+ const key = keys[i];
2065
+ const keyNamespace = key.split('::')[0];
2066
+ const representationName = key.split('::')[1].split(':')[0];
2067
+ keySet.set(key, {
2068
+ namespace: keyNamespace,
2069
+ representationName,
2070
+ mergeable: keyNamespace === namespace || representationName === RECORD_REPRESENTATION_NAME,
2071
+ });
2072
+ }
2073
+ return keySet;
2074
+ }
2075
+ function onFetchResponseError(luvio, config, response) {
2076
+ const errorSnapshot = luvio.errorSnapshot(response);
2077
+ luvio.storeIngestError(GRAPHQL_ROOT_KEY, errorSnapshot);
2078
+ return luvio.storeBroadcast().then(() => errorSnapshot);
2079
+ }
2080
+ function buildNetworkSnapshot(luvio, config, fragment, options) {
2081
+ const { variables: queryVariables, query } = config;
2082
+ const request = {
2083
+ baseUri: '/services/data/v58.0',
2084
+ basePath: '/graphql',
2085
+ method: 'post',
2086
+ priority: 'normal',
2087
+ body: {
2088
+ query: astToString(query),
2089
+ variables: queryVariables,
2090
+ },
2091
+ queryParams: {},
2092
+ urlParams: {},
2093
+ headers: {},
2094
+ };
2095
+ return luvio.dispatchResourceRequest(request, options).then((resp) => {
2096
+ return luvio.handleSuccessResponse(() => onFetchResponseSuccess(luvio, config, resp, fragment), () => getResponseCacheKeys(luvio, config, resp, fragment));
2097
+ }, (errorResponse) => {
2098
+ return luvio.handleErrorResponse(() => onFetchResponseError(luvio, config, errorResponse));
2099
+ });
2100
+ }
2101
+ function validateGraphQlConfig(untrustedConfig) {
2102
+ if (!untrustedIsObject(untrustedConfig)) {
2103
+ return {
2104
+ validatedConfig: null,
2105
+ errors: ["Invalid Config provided isn't an object"],
2106
+ };
2107
+ }
2108
+ if (!('variables' in untrustedConfig && 'query' in untrustedConfig)) {
2109
+ return {
2110
+ validatedConfig: null,
2111
+ errors: [
2112
+ 'Missing one or both of the required config parameters "query" and "variables"',
2113
+ ],
2114
+ };
2115
+ }
2116
+ const { variables, query } = untrustedConfig;
2117
+ const validationErrors = [];
2118
+ if (isLuvioDocumentNode(query) === false) {
2119
+ validationErrors.push('The config parameter "query" isn\'t a valid LuvioDocumentNode');
2120
+ }
2121
+ const ast = query;
2122
+ if (isGraphQLVariables(variables) === false) {
2123
+ validationErrors.push('The config parameter "variables" isn\'t an object');
2124
+ }
2125
+ if (validationErrors.length > 0) {
2126
+ return {
2127
+ validatedConfig: null,
2128
+ errors: validationErrors,
2129
+ };
2130
+ }
2131
+ validationErrors.push(...validate(ast, variables));
2132
+ const { useUiApiAdapter } = untrustedConfig;
2133
+ if (useUiApiAdapter !== undefined && typeof useUiApiAdapter !== 'boolean') {
2134
+ validationErrors.push('The config parameter "useUiApiAdapter" isn\'t a boolean');
2135
+ }
2136
+ if (validationErrors.length > 0) {
2137
+ return {
2138
+ validatedConfig: null,
2139
+ errors: validationErrors,
2140
+ };
2141
+ }
2142
+ return {
2143
+ validatedConfig: {
2144
+ variables,
2145
+ query,
2146
+ useUiApiAdapter,
2147
+ },
2148
+ errors: [],
2149
+ };
2150
+ }
2151
+ function buildCachedSnapshot(context, storeLookup) {
2152
+ return buildInMemorySnapshot(context, storeLookup);
2153
+ }
2154
+ function buildInMemorySnapshot(context, storeLookup) {
2155
+ const { config, fragment, luvio } = context;
2156
+ const selector = {
2157
+ recordId: GRAPHQL_ROOT_KEY,
2158
+ node: fragment,
2159
+ variables: {},
2160
+ };
2161
+ return storeLookup(selector, buildSnapshotRefresh(luvio, config, fragment));
2162
+ }
2163
+ function buildNetworkSnapshotCachePolicy(context, coercedAdapterRequestContext) {
2164
+ const { config, fragment, luvio } = context;
2165
+ const { networkPriority, requestCorrelator, eventObservers } = coercedAdapterRequestContext;
2166
+ const dispatchOptions = {
2167
+ resourceRequestContext: {
2168
+ requestCorrelator,
2169
+ },
2170
+ eventObservers,
2171
+ };
2172
+ if (networkPriority !== 'normal') {
2173
+ dispatchOptions.overrides = {
2174
+ priority: networkPriority,
2175
+ };
2176
+ }
2177
+ return buildNetworkSnapshot(luvio, config, fragment, dispatchOptions);
2178
+ }
2179
+ const replaceDraftIdsInVariables = (variables, draftFunctions) => {
2180
+ const replace = (object) => {
2181
+ if (typeof object === 'string') {
2182
+ if (!draftFunctions.isDraftId(object)) {
2183
+ return object;
2184
+ }
2185
+ return draftFunctions.getCanonicalId(object);
2186
+ }
2187
+ else if (isArray(object)) {
2188
+ return object.map(replace);
2189
+ }
2190
+ else if (typeof object === 'object' && object !== null) {
2191
+ let source = object;
2192
+ return keys(source).reduce((acc, key) => {
2193
+ acc[key] = replace(source[key]);
2194
+ return acc;
2195
+ }, {});
2196
+ }
2197
+ else {
2198
+ return object;
2199
+ }
2200
+ };
2201
+ let newVariables = keys(variables).reduce((acc, key) => {
2202
+ acc[key] = replace(variables[key]);
2203
+ return acc;
2204
+ }, {});
2205
+ return newVariables;
2206
+ };
2207
+ const graphQLAdapterFactory = (luvio) => {
2208
+ const uiApiGraphQLAdapter = graphqlAdapterFactory(luvio);
2209
+ function graphql(untrustedConfig, requestContext) {
2210
+ const { validatedConfig, errors } = validateGraphQlConfig(untrustedConfig);
2211
+ if (errors.length > 0 || validatedConfig === null) {
2212
+ if (process.env.NODE_ENV !== 'production') {
2213
+ throw new Error(errors.join(', '));
2214
+ }
2215
+ return null;
2216
+ }
2217
+ const { query, variables, useUiApiAdapter } = validatedConfig;
2218
+ if (useUiApiAdapter === true) {
2219
+ // Forward to new adapters
2220
+ const resolvedQuery = astResolver(query);
2221
+ if (resolvedQuery === undefined) {
2222
+ if (process.env.NODE_ENV !== 'production') {
2223
+ throw new Error('Could not resolve standard AST');
2224
+ }
2225
+ return null;
2226
+ }
2227
+ return uiApiGraphQLAdapter({
2228
+ query: resolvedQuery,
2229
+ variables,
2230
+ }, requestContext);
2231
+ }
2232
+ else {
2233
+ const fieldInjectionRequired = shouldInjectFields(query);
2234
+ const validatedConfigWithInjection = fieldInjectionRequired
2235
+ ? graphqlConfigWithInjectedAST(validatedConfig)
2236
+ : validatedConfig;
2237
+ const sanitizedConfig = draftFunctions !== undefined
2238
+ ? sanitizeConfig(validatedConfigWithInjection, draftFunctions)
2239
+ : validatedConfigWithInjection;
2240
+ if (sanitizedConfig.variables && draftFunctions !== undefined) {
2241
+ const variablesWithSwappedDraftIds = replaceDraftIdsInVariables(sanitizedConfig.variables, draftFunctions);
2242
+ sanitizedConfig.variables = variablesWithSwappedDraftIds;
2243
+ validatedConfig.variables = variablesWithSwappedDraftIds;
2244
+ }
2245
+ const fragment = createFragment(luvio, sanitizedConfig.query, sanitizedConfig.variables);
2246
+ const context = {
2247
+ config: sanitizedConfig,
2248
+ fragment,
2249
+ luvio,
2250
+ };
2251
+ // NOTE: For evaluating environments, set a context property to let the
2252
+ // environment detect that eval will happen and to check varous gates
2253
+ // for eval behavior customizations.
2254
+ if (storeEval !== undefined) {
2255
+ context.gqlEval = true;
2256
+ }
2257
+ const snapshotOrPromiseFromCachePolicy = luvio.applyCachePolicy(requestContext || {}, context, buildCachedSnapshot, buildNetworkSnapshotCachePolicy);
2258
+ if (storeEval !== undefined) {
2259
+ const observers = requestContext && requestContext.eventObservers
2260
+ ? requestContext.eventObservers
2261
+ : [];
2262
+ // uses the original ast to do the eval to avoid fields not needed by users. The draftID swapping happens when filters transform to predicates.
2263
+ return storeEval(validatedConfig, snapshotOrPromiseFromCachePolicy, observers, keyBuilder);
2264
+ }
2265
+ return snapshotOrPromiseFromCachePolicy;
2266
+ }
2267
+ }
2268
+ return graphql;
2269
+ };
2270
+ function graphqlConfigWithInjectedAST(graphqlConfig) {
2271
+ const { query } = graphqlConfig;
2272
+ const astCopy = parse(stringify(query));
2273
+ const modifiedAST = injectFieldsGQL(astCopy);
2274
+ return {
2275
+ ...graphqlConfig,
2276
+ query: modifiedAST,
2277
+ };
2278
+ }
2279
+ function sanitizeConfig(graphqlConfig, draftFunctions) {
2280
+ const { query } = graphqlConfig;
2281
+ const astCopy = parse(stringify(query));
2282
+ const modifiedAST = swapIdsOfDocumentNode(astCopy, draftFunctions);
2283
+ return {
2284
+ ...graphqlConfig,
2285
+ query: modifiedAST,
2286
+ };
2287
+ }
2288
+ // make sure to register the configuration whenever this module loads
2289
+ register({ id: '@salesforce/lds-adapters-graphql', configuration });
2290
+
2291
+ let graphQL;
2292
+ let unstable_graphQL_imperative;
2293
+ // TODO [W-9992865]: remove this export when lds-worker-api usage has been updated
2294
+ let graphQLImperative;
2295
+ const adapterMetadata = {
2296
+ apiFamily: namespace,
2297
+ name: adapterName,
2298
+ };
2299
+ withDefaultLuvio((luvio) => {
2300
+ const ldsAdapter = createLDSAdapter(luvio, namespace, graphQLAdapterFactory);
2301
+ graphQL = createWireAdapterConstructor(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
2302
+ unstable_graphQL_imperative = createImperativeAdapter(luvio, createInstrumentedAdapter(ldsAdapter, adapterMetadata), adapterMetadata);
2303
+ graphQLImperative = ldsAdapter;
2304
+ });
2305
+
2306
+ export { graphQL, graphQLImperative, unstable_graphQL_imperative };
2307
+ // version: 0.131.0-c1ec5b7de