@luvio/lwc-luvio 0.142.2 → 0.142.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/package.json +11 -7
  2. package/dist/umd/es2018/lwcluvio.js +0 -558
  3. package/dist/umd/es2018/types/LWCGraphQLLuvioWireAdapter.d.ts +0 -56
  4. package/dist/umd/es2018/types/LWCInfiniteScrollingLuvioWireAdapter.d.ts +0 -26
  5. package/dist/umd/es2018/types/LWCLuvioBindings.d.ts +0 -4
  6. package/dist/umd/es2018/types/LWCLuvioWireAdapter.d.ts +0 -64
  7. package/dist/umd/es2018/types/main.d.ts +0 -8
  8. package/dist/umd/es2018/types/utils/SnapshotState.d.ts +0 -12
  9. package/dist/umd/es2018/types/utils/constants.d.ts +0 -5
  10. package/dist/umd/es2018/types/utils/dataToTupleWeakMap.d.ts +0 -2
  11. package/dist/umd/es2018/types/utils/isPromise.d.ts +0 -1
  12. package/dist/umd/es2018/types/utils/language.d.ts +0 -16
  13. package/dist/umd/es2018/types/utils/sanitize.d.ts +0 -9
  14. package/dist/umd/es2018/types/utils/throwAnnotatedError.d.ts +0 -7
  15. package/dist/umd/es5/lwcluvio.js +0 -620
  16. package/dist/umd/es5/types/LWCGraphQLLuvioWireAdapter.d.ts +0 -56
  17. package/dist/umd/es5/types/LWCInfiniteScrollingLuvioWireAdapter.d.ts +0 -26
  18. package/dist/umd/es5/types/LWCLuvioBindings.d.ts +0 -4
  19. package/dist/umd/es5/types/LWCLuvioWireAdapter.d.ts +0 -64
  20. package/dist/umd/es5/types/main.d.ts +0 -8
  21. package/dist/umd/es5/types/utils/SnapshotState.d.ts +0 -12
  22. package/dist/umd/es5/types/utils/constants.d.ts +0 -5
  23. package/dist/umd/es5/types/utils/dataToTupleWeakMap.d.ts +0 -2
  24. package/dist/umd/es5/types/utils/isPromise.d.ts +0 -1
  25. package/dist/umd/es5/types/utils/language.d.ts +0 -16
  26. package/dist/umd/es5/types/utils/sanitize.d.ts +0 -9
  27. package/dist/umd/es5/types/utils/throwAnnotatedError.d.ts +0 -7
  28. /package/dist/{es/es2018/lwcluvio.js → lwcluvio.js} +0 -0
  29. /package/dist/{es/es2018/types → types}/LWCGraphQLLuvioWireAdapter.d.ts +0 -0
  30. /package/dist/{es/es2018/types → types}/LWCInfiniteScrollingLuvioWireAdapter.d.ts +0 -0
  31. /package/dist/{es/es2018/types → types}/LWCLuvioBindings.d.ts +0 -0
  32. /package/dist/{es/es2018/types → types}/LWCLuvioWireAdapter.d.ts +0 -0
  33. /package/dist/{es/es2018/types → types}/main.d.ts +0 -0
  34. /package/dist/{es/es2018/types → types}/utils/SnapshotState.d.ts +0 -0
  35. /package/dist/{es/es2018/types → types}/utils/constants.d.ts +0 -0
  36. /package/dist/{es/es2018/types → types}/utils/dataToTupleWeakMap.d.ts +0 -0
  37. /package/dist/{es/es2018/types → types}/utils/isPromise.d.ts +0 -0
  38. /package/dist/{es/es2018/types → types}/utils/language.d.ts +0 -0
  39. /package/dist/{es/es2018/types → types}/utils/sanitize.d.ts +0 -0
  40. /package/dist/{es/es2018/types → types}/utils/throwAnnotatedError.d.ts +0 -0
@@ -1,620 +0,0 @@
1
- (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lwc')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'lwc'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.lwcLuvio = {}, global.LWC));
5
- })(this, (function (exports, lwc) { 'use strict';
6
-
7
- // instrumentation keys to be imported by ldsInstrumentation
8
- var REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
9
- var ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
10
- var USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
11
- var ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
12
- var USERLAND_GRAPHQL_PARSER_ERROR_MESSAGE = 'Use `gql` parser to parse your "query" string';
13
-
14
- // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
15
- // initially-emitted { data: undefined, error: undefined } value
16
- var dataToTupleWeakMap = new WeakMap();
17
-
18
- var SnapshotState;
19
- (function (SnapshotState) {
20
- SnapshotState["Fulfilled"] = "Fulfilled";
21
- SnapshotState["Unfulfilled"] = "Unfulfilled";
22
- SnapshotState["Error"] = "Error";
23
- SnapshotState["Pending"] = "Pending";
24
- SnapshotState["Stale"] = "Stale";
25
- })(SnapshotState || (SnapshotState = {}));
26
- function isErrorSnapshot(snapshot) {
27
- return snapshot.state === SnapshotState.Error;
28
- }
29
- function isFulfilledSnapshot(snapshot) {
30
- return snapshot.state === SnapshotState.Fulfilled;
31
- }
32
- function isStaleSnapshot(snapshot) {
33
- return snapshot.state === SnapshotState.Stale;
34
- }
35
- function isUnfulfilledSnapshot(snapshot) {
36
- return snapshot.state === SnapshotState.Unfulfilled;
37
- }
38
- /**
39
- * Transform a Snapshot into a payload suitable for passing to a DataCallback.
40
- *
41
- * @param snapshot Snapshot
42
- */
43
- function snapshotToPayload$1(snapshot) {
44
- if (snapshot === undefined) {
45
- return {
46
- data: undefined,
47
- error: undefined,
48
- };
49
- }
50
- if (isErrorSnapshot(snapshot)) {
51
- return {
52
- data: undefined,
53
- error: snapshot.error,
54
- };
55
- }
56
- // fulfilled or stale
57
- return {
58
- data: snapshot.data,
59
- error: undefined,
60
- };
61
- }
62
-
63
- function bindWireRefresh(luvio) {
64
- return function refresh(data) {
65
- return refreshData(data, dataToTupleWeakMap, luvio);
66
- };
67
- }
68
- function refreshData(data, dataToTuple, luvio) {
69
- var tuple = dataToTuple.get(lwc.unwrap(data));
70
- if (tuple === undefined) {
71
- if (process.env.NODE_ENV !== 'production') {
72
- throw new Error('Refresh failed because resolved configuration is not available.');
73
- }
74
- return;
75
- }
76
- var adapterName = tuple[0], snapshot = tuple[1];
77
- luvio.instrument(function () {
78
- var _a;
79
- return _a = {},
80
- _a[REFRESH_ADAPTER_EVENT] = true,
81
- _a.adapterName = adapterName,
82
- _a;
83
- });
84
- // snapshot is undefined when a caller refreshes the initial
85
- // { data: undefined, error: undefined } object that we emitted
86
- if (snapshot === undefined) {
87
- return Promise.resolve(undefined);
88
- }
89
- return luvio.refreshSnapshot(snapshot).then(function (refreshed) {
90
- if (isErrorSnapshot(refreshed)) {
91
- throw refreshed.error;
92
- }
93
- if (process.env.NODE_ENV !== 'production') {
94
- if (isUnfulfilledSnapshot(refreshed)) {
95
- throw new Error('Refresh resulted in unfulfilled snapshot');
96
- }
97
- }
98
- return undefined;
99
- });
100
- }
101
-
102
- var keys = Object.keys;
103
- var isArray = Array.isArray;
104
- var stringify = JSON.stringify;
105
-
106
- function isPromise(value) {
107
- // check for Thenable due to test frameworks using custom Promise impls
108
- return value.then !== undefined;
109
- }
110
-
111
- /**
112
- * (Re)throws an error after adding a prefix to the message.
113
- *
114
- * @param error Error
115
- * @param messagePrefix prefix to add to error's message
116
- */
117
- function throwAnnotatedError(error, messagePrefix) {
118
- if (error instanceof Error) {
119
- error.message = "".concat(messagePrefix, "\n[").concat(error.message, "]");
120
- throw error;
121
- }
122
- throw new Error("".concat(messagePrefix, "\n[").concat(stringify(error), "]"));
123
- }
124
-
125
- var Sanitizer = /** @class */ (function () {
126
- function Sanitizer(obj) {
127
- this.obj = obj;
128
- this.copy = {};
129
- this.currentPath = {
130
- key: '',
131
- value: obj,
132
- parent: null,
133
- data: this.copy,
134
- };
135
- }
136
- Sanitizer.prototype.sanitize = function () {
137
- var sanitizer = this;
138
- stringify(this.obj, function (key, value) {
139
- if (key === '') {
140
- return value;
141
- }
142
- var parent = this;
143
- if (parent !== sanitizer.currentPath.value) {
144
- sanitizer.exit(parent);
145
- }
146
- if (typeof value === 'object' && value !== null) {
147
- sanitizer.enter(key, value);
148
- return value;
149
- }
150
- sanitizer.currentPath.data[key] = value;
151
- return value;
152
- });
153
- return this.copy;
154
- };
155
- Sanitizer.prototype.enter = function (key, value) {
156
- var parentPath = this.currentPath;
157
- var data = (parentPath.data[key] = isArray(value) ? [] : {});
158
- this.currentPath = {
159
- key: key,
160
- value: value,
161
- parent: parentPath,
162
- data: data,
163
- };
164
- };
165
- Sanitizer.prototype.exit = function (parent) {
166
- while (this.currentPath.value !== parent) {
167
- this.currentPath = this.currentPath.parent || this.currentPath;
168
- }
169
- };
170
- return Sanitizer;
171
- }());
172
- /**
173
- * Returns a sanitized version of an object by recursively unwrapping the Proxies.
174
- *
175
- * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
176
- * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
177
- * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
178
- * sanitized first.
179
- */
180
- function sanitize(obj) {
181
- return new Sanitizer(obj).sanitize();
182
- }
183
-
184
- var LWCLuvioWireAdapter = /** @class */ (function () {
185
- /**
186
- * Constructs a new wire adapter instance for the given adapter.
187
- *
188
- * @param callback callback to be invoked with new values
189
- */
190
- function LWCLuvioWireAdapter(adapter, name, luvio, callback) {
191
- // a component can be connected-disconnected-reconnected multiple times during its
192
- // life but we only want to keep subscriptions active while it is connected; the
193
- // connect/disconnect methods below keep this value updated to reflect the current
194
- // state
195
- this.connected = false;
196
- this.adapter = adapter;
197
- this.name = name;
198
- this.luvio = luvio;
199
- this.callback = callback;
200
- // initialize the wired property with a properly shaped object so cmps can use <template if:true={wiredProperty.data}>
201
- this.emit();
202
- }
203
- // WireAdapter interface methods
204
- /**
205
- * Called when the component associated with the wire adapter is connected.
206
- */
207
- LWCLuvioWireAdapter.prototype.connect = function () {
208
- this.connected = true;
209
- this.callAdapter();
210
- };
211
- /**
212
- * Called when the component associated with the wire adapter is disconnected.
213
- */
214
- LWCLuvioWireAdapter.prototype.disconnect = function () {
215
- this.unsubscribe();
216
- this.connected = false;
217
- };
218
- /**
219
- * Called when new or updated config is supplied to the wire adapter.
220
- *
221
- * @param config new config parameters for the wire adapter
222
- * @param _context not used
223
- */
224
- LWCLuvioWireAdapter.prototype.update = function (config, _context) {
225
- this.unsubscribe();
226
- this.config = sanitize(config);
227
- this.callAdapter();
228
- };
229
- // private and protected utility methods
230
- /**
231
- * Calls the adapter if config has been set and the component is connected.
232
- */
233
- LWCLuvioWireAdapter.prototype.callAdapter = function () {
234
- if (!this.connected || this.config === undefined) {
235
- return;
236
- }
237
- var snapshotOrPromise = this.adapter(this.config);
238
- this.processAdapterResponse(snapshotOrPromise);
239
- };
240
- LWCLuvioWireAdapter.prototype.processAdapterResponse = function (snapshotOrPromise) {
241
- var _this = this;
242
- // insufficient config, wait for new config from component
243
- if (snapshotOrPromise === null) {
244
- return;
245
- }
246
- var configForSnapshot = this.config;
247
- var emitAndSubscribe = function (snapshot) {
248
- // adapters leveraging adapter context could asynchronously
249
- // return null (due to invalid config)
250
- if (snapshot === null) {
251
- return;
252
- }
253
- // We should never broadcast an unfulfilled snapshot to a component
254
- if (isUnfulfilledSnapshot(snapshot)) {
255
- if (process.env.NODE_ENV !== 'production') {
256
- throw new Error("Unfulfilled snapshot emitted to component from subscription, missingPaths: ".concat(keys(snapshot.missingPaths)));
257
- }
258
- // Instrument as a failed request
259
- _this.luvio.instrument(function () {
260
- var _a;
261
- return _a = {},
262
- _a[ADAPTER_UNFULFILLED_ERROR] = true,
263
- _a.adapterName = _this.adapter.name,
264
- _a.missingPaths = snapshot.missingPaths,
265
- _a.missingLinks = snapshot.missingLinks,
266
- _a;
267
- });
268
- return;
269
- }
270
- // if config has changed before the snapshot arrives then ignore snapshot
271
- if (_this.config !== configForSnapshot) {
272
- return;
273
- }
274
- // emit unless snapshot is pending
275
- if (isFulfilledSnapshot(snapshot) ||
276
- isErrorSnapshot(snapshot) ||
277
- isStaleSnapshot(snapshot)) {
278
- _this.emit(snapshot);
279
- }
280
- // subscribe to the new snapshot
281
- _this.subscribe(snapshot);
282
- };
283
- // Data resolved sync
284
- if (!isPromise(snapshotOrPromise)) {
285
- emitAndSubscribe(snapshotOrPromise);
286
- }
287
- else {
288
- // We want to let errors from this promise propagate to the app container,
289
- // which is why we do not have a reject handler here.
290
- // If an error is thrown here, it means that there was an error somewhere
291
- // inside an adapter which means that there was a mistake by the implementor.
292
- // Errors that come from the network should never hit this block because
293
- // they are treated like regular snapshots, not true error paths.
294
- snapshotOrPromise.then(emitAndSubscribe, function (error) {
295
- return throwAnnotatedError(error, ADAPTER_SNAPSHOT_REJECTED_MESSAGE);
296
- });
297
- }
298
- };
299
- /**
300
- * Emits new values to the callback.
301
- *
302
- * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
303
- */
304
- LWCLuvioWireAdapter.prototype.emit = function (snapshot) {
305
- var payload = snapshotToPayload$1(snapshot);
306
- dataToTupleWeakMap.set(payload, [this.name, snapshot]);
307
- try {
308
- this.callback(payload);
309
- }
310
- catch (error) {
311
- if (error instanceof Error) {
312
- throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
313
- }
314
- }
315
- };
316
- /**
317
- * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
318
- * to the snapshot will be automatically emitted to the component.
319
- *
320
- * @param snapshot Snapshot
321
- * @param subscriptionCallback callback
322
- */
323
- LWCLuvioWireAdapter.prototype.subscribe = function (snapshot) {
324
- // always clean up any old subscription that we might have
325
- this.unsubscribe();
326
- // but only subscribe if component is currently connected
327
- if (this.connected) {
328
- this.unsubscriber = this.luvio.storeSubscribe(snapshot, this.emit.bind(this));
329
- }
330
- };
331
- /**
332
- * Deletes this wire adapter's snapshot subscription (if any).
333
- */
334
- LWCLuvioWireAdapter.prototype.unsubscribe = function () {
335
- // clean up subscription
336
- if (this.unsubscriber !== undefined) {
337
- this.unsubscriber();
338
- this.unsubscriber = undefined;
339
- }
340
- };
341
- return LWCLuvioWireAdapter;
342
- }());
343
- /**
344
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
345
- *
346
- * @param adapter Adapter
347
- * @param name name to assign to the generated constructor
348
- * @param luvio Luvio
349
- */
350
- function createWireAdapterConstructor(adapter, name, luvio) {
351
- var constructor = function (callback) {
352
- var delegate = new LWCLuvioWireAdapter(adapter, name, luvio, callback);
353
- this.connect = function () { return delegate.connect(); };
354
- this.disconnect = function () { return delegate.disconnect(); };
355
- this.update = function (config, context) {
356
- return delegate.update(config, context);
357
- };
358
- };
359
- Object.defineProperty(constructor, 'name', { value: name });
360
- return constructor;
361
- }
362
-
363
- /******************************************************************************
364
- Copyright (c) Microsoft Corporation.
365
-
366
- Permission to use, copy, modify, and/or distribute this software for any
367
- purpose with or without fee is hereby granted.
368
-
369
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
370
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
371
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
372
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
373
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
374
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
375
- PERFORMANCE OF THIS SOFTWARE.
376
- ***************************************************************************** */
377
- /* global Reflect, Promise */
378
-
379
- var extendStatics = function(d, b) {
380
- extendStatics = Object.setPrototypeOf ||
381
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
382
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
383
- return extendStatics(d, b);
384
- };
385
-
386
- function __extends(d, b) {
387
- if (typeof b !== "function" && b !== null)
388
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
389
- extendStatics(d, b);
390
- function __() { this.constructor = d; }
391
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
392
- }
393
-
394
- var __assign = function() {
395
- __assign = Object.assign || function __assign(t) {
396
- for (var s, i = 1, n = arguments.length; i < n; i++) {
397
- s = arguments[i];
398
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
399
- }
400
- return t;
401
- };
402
- return __assign.apply(this, arguments);
403
- };
404
-
405
- var LWCInfinteScrollingLuvioWireAdapter = /** @class */ (function (_super) {
406
- __extends(LWCInfinteScrollingLuvioWireAdapter, _super);
407
- function LWCInfinteScrollingLuvioWireAdapter() {
408
- return _super !== null && _super.apply(this, arguments) || this;
409
- }
410
- /**
411
- * Called when the component associated with the wire adapter is connected.
412
- */
413
- LWCInfinteScrollingLuvioWireAdapter.prototype.connect = function () {
414
- this.connectTimestamp = Date.now();
415
- _super.prototype.connect.call(this);
416
- };
417
- /**
418
- * Called when the component associated with the wire adapter is disconnected.
419
- */
420
- LWCInfinteScrollingLuvioWireAdapter.prototype.disconnect = function () {
421
- this.connectTimestamp = undefined;
422
- _super.prototype.disconnect.call(this);
423
- };
424
- /**
425
- * Called when new or updated config is supplied to the wire adapter.
426
- *
427
- * @param config new config parameters for the wire adapter
428
- * @param context context for the wire adapter
429
- */
430
- LWCInfinteScrollingLuvioWireAdapter.prototype.update = function (config, context) {
431
- if (this.connectTimestamp) {
432
- var mergedContext = Object.assign({
433
- cachePolicy: {
434
- type: 'valid-at',
435
- timestamp: this.connectTimestamp,
436
- },
437
- }, context);
438
- _super.prototype.unsubscribe.call(this);
439
- this.config = sanitize(config);
440
- this.callAdapterWithContext(mergedContext);
441
- }
442
- else {
443
- _super.prototype.update.call(this, config, context);
444
- }
445
- };
446
- /**
447
- * Calls the adapter if config has been set and the component is connected.
448
- */
449
- LWCInfinteScrollingLuvioWireAdapter.prototype.callAdapterWithContext = function (context) {
450
- if (!this.connected || this.config === undefined) {
451
- return;
452
- }
453
- var snapshotOrPromise = this.adapter(this.config, context);
454
- _super.prototype.processAdapterResponse.call(this, snapshotOrPromise);
455
- };
456
- return LWCInfinteScrollingLuvioWireAdapter;
457
- }(LWCLuvioWireAdapter));
458
- function createInfiniteScrollingWireAdapterConstructor(adapter, name, luvio) {
459
- var constructor = function (callback) {
460
- var delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback);
461
- this.connect = function () { return delegate.connect(); };
462
- this.disconnect = function () { return delegate.disconnect(); };
463
- this.update = function (config, context) {
464
- return delegate.update(config, context);
465
- };
466
- };
467
- Object.defineProperty(constructor, 'name', { value: name });
468
- return constructor;
469
- }
470
-
471
- function snapshotToPayload(snapshot) {
472
- var payload = {
473
- data: undefined,
474
- errors: undefined,
475
- };
476
- if (snapshot === undefined) {
477
- return payload;
478
- }
479
- payload.data = extractSnapshotData(snapshot);
480
- // TODO handle batch error scenarios.
481
- if ('error' in snapshot && snapshot.error !== undefined) {
482
- if (Array.isArray(snapshot.error)) {
483
- payload.errors = snapshot.error;
484
- }
485
- else {
486
- payload.errors = [snapshot.error];
487
- }
488
- }
489
- return payload;
490
- }
491
- var LWCGraphQLLuvioWireAdapter = /** @class */ (function (_super) {
492
- __extends(LWCGraphQLLuvioWireAdapter, _super);
493
- function LWCGraphQLLuvioWireAdapter(adapter, name, luvio, astResolver, callback) {
494
- var _this = _super.call(this, adapter, name, luvio, callback) || this;
495
- _this.astResolver = astResolver;
496
- return _this;
497
- }
498
- LWCGraphQLLuvioWireAdapter.prototype.update = function (config, _context) {
499
- this.unsubscribe();
500
- if (config.batchQuery) {
501
- this.config = {
502
- batchQuery: config.batchQuery.map(function (individualConfig) {
503
- return safeSanitizeGraphQLConfigObject(individualConfig);
504
- }),
505
- };
506
- }
507
- else {
508
- this.config = safeSanitizeGraphQLConfigObject(config);
509
- }
510
- this.callAdapter();
511
- };
512
- /**
513
- * Emits new values to the callback.
514
- *
515
- * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
516
- */
517
- LWCGraphQLLuvioWireAdapter.prototype.emit = function (snapshot) {
518
- var payload = snapshotToPayload(snapshot);
519
- dataToTupleWeakMap.set(payload, [this.name, snapshot]);
520
- try {
521
- this.callback(payload);
522
- }
523
- catch (error) {
524
- if (error instanceof Error) {
525
- throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
526
- }
527
- }
528
- };
529
- /**
530
- * Coerce config before calling the adapter, preserve current behavior otherwise
531
- */
532
- LWCGraphQLLuvioWireAdapter.prototype.callAdapter = function () {
533
- var _this = this;
534
- if (!this.connected || this.config === undefined) {
535
- return;
536
- }
537
- var config = this.config;
538
- if ('batchQuery' in config) {
539
- var batchConfig = {
540
- batchQuery: config.batchQuery.map(function (individualConfig) {
541
- return _this.resolveQueryAst(individualConfig);
542
- }),
543
- };
544
- // If any of the configurations are invalid, we bail out of calling the adapter.
545
- if (batchConfig.batchQuery.some(function (val) { return val === undefined; })) {
546
- return;
547
- }
548
- var snapshotOrPromise = this.adapter(batchConfig);
549
- this.processAdapterResponse(snapshotOrPromise);
550
- }
551
- else if ('query' in config) {
552
- var singleConfig = this.resolveQueryAst(config);
553
- if (singleConfig !== undefined) {
554
- var snapshotOrPromise = this.adapter(singleConfig);
555
- this.processAdapterResponse(snapshotOrPromise);
556
- }
557
- }
558
- };
559
- LWCGraphQLLuvioWireAdapter.prototype.resolveQueryAst = function (config) {
560
- if (config.query === null) {
561
- return;
562
- }
563
- var ast = this.astResolver(config.query);
564
- if (ast === undefined && config.query !== undefined) {
565
- // this should only happen if the user didn't parse the query
566
- if (process.env.NODE_ENV !== 'production') {
567
- throw new Error(USERLAND_GRAPHQL_PARSER_ERROR_MESSAGE);
568
- }
569
- return;
570
- }
571
- var resolvedAdapterConfig = __assign(__assign({}, config), { query: ast });
572
- return resolvedAdapterConfig;
573
- };
574
- return LWCGraphQLLuvioWireAdapter;
575
- }(LWCLuvioWireAdapter));
576
- function extractSnapshotData(snapshot) {
577
- if ('data' in snapshot && snapshot.data !== undefined) {
578
- var isSingleGraphQLData = 'data' in snapshot.data && snapshot.data.data !== undefined;
579
- var isBatchGraphQLData = 'results' in snapshot.data && snapshot.data.results !== undefined;
580
- if (isSingleGraphQLData)
581
- return snapshot.data.data;
582
- if (isBatchGraphQLData)
583
- return snapshot.data;
584
- }
585
- }
586
- /**
587
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
588
- *
589
- * @param adapter Adapter
590
- * @param name name to assign to the generated constructor
591
- * @param luvio Luvio
592
- */
593
- function createGraphQLWireAdapterConstructor(adapter, name, luvio, astResolver) {
594
- var constructor = function (callback) {
595
- var delegate = new LWCGraphQLLuvioWireAdapter(adapter, name, luvio, astResolver, callback);
596
- this.connect = function () { return delegate.connect(); };
597
- this.disconnect = function () { return delegate.disconnect(); };
598
- this.update = function (config, context) {
599
- return delegate.update(config, context);
600
- };
601
- };
602
- Object.defineProperty(constructor, 'name', { value: name });
603
- return constructor;
604
- }
605
- function safeSanitizeGraphQLConfigObject(config) {
606
- // graphql query AST is passed by reference
607
- // sanitizing it makes a copy and we lose that reference
608
- // so we avoid sanitizing it
609
- return __assign(__assign({}, sanitize(config)), { query: config.query });
610
- }
611
-
612
- exports.ADAPTER_UNFULFILLED_ERROR = ADAPTER_UNFULFILLED_ERROR;
613
- exports.REFRESH_ADAPTER_EVENT = REFRESH_ADAPTER_EVENT;
614
- exports.bindWireRefresh = bindWireRefresh;
615
- exports.createGraphQLWireAdapterConstructor = createGraphQLWireAdapterConstructor;
616
- exports.createInfiniteScrollingWireAdapterConstructor = createInfiniteScrollingWireAdapterConstructor;
617
- exports.createWireAdapterConstructor = createWireAdapterConstructor;
618
- exports.refreshData = refreshData;
619
-
620
- }));
@@ -1,56 +0,0 @@
1
- import type { Adapter, Luvio } from '@luvio/engine';
2
- import type { WireConfigValue, WireContextValue, DataCallback, WireAdapterConstructor } from '@lwc/engine-core';
3
- import type { AstResolver, DocumentNode } from '@luvio/graphql-parser';
4
- import { LWCLuvioWireAdapter } from './LWCLuvioWireAdapter';
5
- import type { EmittableSnapshot } from './utils/SnapshotState';
6
- export type GraphQLError = {
7
- message: string;
8
- locations?: Array<{
9
- line: number;
10
- column: number;
11
- }>;
12
- path?: Array<string | number>;
13
- extensions?: Record<string, any>;
14
- };
15
- export interface GraphQLUserInput {
16
- query?: object;
17
- variables?: Record<string, string | number | boolean>;
18
- operationName?: string;
19
- }
20
- export interface ResolvedGraphQLConfig extends GraphQLUserInput {
21
- query?: DocumentNode;
22
- }
23
- export interface GraphQLBatchUserInput {
24
- batchQuery: GraphQLUserInput[];
25
- }
26
- export type GraphQLInput = GraphQLUserInput | GraphQLBatchUserInput;
27
- export type GraphQLResponse = {
28
- data: any;
29
- errors?: GraphQLError[];
30
- } | {
31
- errors: GraphQLError[];
32
- };
33
- export declare class LWCGraphQLLuvioWireAdapter extends LWCLuvioWireAdapter {
34
- astResolver: AstResolver;
35
- constructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio, astResolver: AstResolver, callback: DataCallback);
36
- update(config: WireConfigValue, _context?: WireContextValue): void;
37
- /**
38
- * Emits new values to the callback.
39
- *
40
- * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
41
- */
42
- protected emit(snapshot?: EmittableSnapshot<GraphQLResponse>): void;
43
- /**
44
- * Coerce config before calling the adapter, preserve current behavior otherwise
45
- */
46
- protected callAdapter(): void;
47
- resolveQueryAst(config: GraphQLUserInput): ResolvedGraphQLConfig | undefined;
48
- }
49
- /**
50
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
51
- *
52
- * @param adapter Adapter
53
- * @param name name to assign to the generated constructor
54
- * @param luvio Luvio
55
- */
56
- export declare function createGraphQLWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio, astResolver: AstResolver): WireAdapterConstructor;