@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/lwc-luvio",
3
- "version": "0.142.2",
3
+ "version": "0.142.3",
4
4
  "description": "Lightning Web Component bindings for Luvio",
5
5
  "repository": {
6
6
  "type": "git",
@@ -8,9 +8,13 @@
8
8
  "directory": "packages/@luvio/lwc-luvio"
9
9
  },
10
10
  "license": "MIT",
11
- "main": "dist/es/es2018/lwcluvio.js",
12
- "module": "dist/es/es2018/lwcluvio.js",
13
- "types": "dist/es/es2018/types/main.d.ts",
11
+ "exports": {
12
+ "types": "./dist/types/main.d.ts",
13
+ "import": "./dist/lwcluvio.js",
14
+ "default": "./dist/lwcluvio.js"
15
+ },
16
+ "module": "dist/lwcluvio.js",
17
+ "types": "dist/types/main.d.ts",
14
18
  "files": [
15
19
  "dist/"
16
20
  ],
@@ -25,12 +29,12 @@
25
29
  "watch": "yarn build --watch"
26
30
  },
27
31
  "dependencies": {
28
- "@luvio/engine": "^0.142.2",
32
+ "@luvio/engine": "^0.142.3",
29
33
  "@lwc/engine-core": "2.40.1"
30
34
  },
31
35
  "devDependencies": {
32
- "@luvio/adapter-test-library": "^0.142.2",
33
- "@luvio/cli": "^0.142.2",
36
+ "@luvio/adapter-test-library": "^0.142.3",
37
+ "@luvio/cli": "^0.142.3",
34
38
  "@lwc/jest-preset": "11.7.1"
35
39
  },
36
40
  "volta": {
@@ -1,558 +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
- const REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
9
- const ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
10
- const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
11
- const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
12
- const 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
- const 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
- const 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
- const [adapterName, snapshot] = tuple;
77
- luvio.instrument(() => {
78
- return {
79
- [REFRESH_ADAPTER_EVENT]: true,
80
- adapterName,
81
- };
82
- });
83
- // snapshot is undefined when a caller refreshes the initial
84
- // { data: undefined, error: undefined } object that we emitted
85
- if (snapshot === undefined) {
86
- return Promise.resolve(undefined);
87
- }
88
- return luvio.refreshSnapshot(snapshot).then((refreshed) => {
89
- if (isErrorSnapshot(refreshed)) {
90
- throw refreshed.error;
91
- }
92
- if (process.env.NODE_ENV !== 'production') {
93
- if (isUnfulfilledSnapshot(refreshed)) {
94
- throw new Error('Refresh resulted in unfulfilled snapshot');
95
- }
96
- }
97
- return undefined;
98
- });
99
- }
100
-
101
- const { freeze, keys } = Object;
102
- const { isArray } = Array;
103
- const { stringify } = JSON;
104
-
105
- function isPromise(value) {
106
- // check for Thenable due to test frameworks using custom Promise impls
107
- return value.then !== undefined;
108
- }
109
-
110
- /**
111
- * (Re)throws an error after adding a prefix to the message.
112
- *
113
- * @param error Error
114
- * @param messagePrefix prefix to add to error's message
115
- */
116
- function throwAnnotatedError(error, messagePrefix) {
117
- if (error instanceof Error) {
118
- error.message = `${messagePrefix}\n[${error.message}]`;
119
- throw error;
120
- }
121
- throw new Error(`${messagePrefix}\n[${stringify(error)}]`);
122
- }
123
-
124
- class Sanitizer {
125
- constructor(obj) {
126
- this.obj = obj;
127
- this.copy = {};
128
- this.currentPath = {
129
- key: '',
130
- value: obj,
131
- parent: null,
132
- data: this.copy,
133
- };
134
- }
135
- sanitize() {
136
- const sanitizer = this;
137
- stringify(this.obj, function (key, value) {
138
- if (key === '') {
139
- return value;
140
- }
141
- const parent = this;
142
- if (parent !== sanitizer.currentPath.value) {
143
- sanitizer.exit(parent);
144
- }
145
- if (typeof value === 'object' && value !== null) {
146
- sanitizer.enter(key, value);
147
- return value;
148
- }
149
- sanitizer.currentPath.data[key] = value;
150
- return value;
151
- });
152
- return this.copy;
153
- }
154
- enter(key, value) {
155
- const { currentPath: parentPath } = this;
156
- const data = (parentPath.data[key] = isArray(value) ? [] : {});
157
- this.currentPath = {
158
- key,
159
- value,
160
- parent: parentPath,
161
- data,
162
- };
163
- }
164
- exit(parent) {
165
- while (this.currentPath.value !== parent) {
166
- this.currentPath = this.currentPath.parent || this.currentPath;
167
- }
168
- }
169
- }
170
- /**
171
- * Returns a sanitized version of an object by recursively unwrapping the Proxies.
172
- *
173
- * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
174
- * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
175
- * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
176
- * sanitized first.
177
- */
178
- function sanitize(obj) {
179
- return new Sanitizer(obj).sanitize();
180
- }
181
-
182
- class LWCLuvioWireAdapter {
183
- /**
184
- * Constructs a new wire adapter instance for the given adapter.
185
- *
186
- * @param callback callback to be invoked with new values
187
- */
188
- constructor(adapter, name, luvio, callback) {
189
- // a component can be connected-disconnected-reconnected multiple times during its
190
- // life but we only want to keep subscriptions active while it is connected; the
191
- // connect/disconnect methods below keep this value updated to reflect the current
192
- // state
193
- this.connected = false;
194
- this.adapter = adapter;
195
- this.name = name;
196
- this.luvio = luvio;
197
- this.callback = callback;
198
- // initialize the wired property with a properly shaped object so cmps can use <template if:true={wiredProperty.data}>
199
- this.emit();
200
- }
201
- // WireAdapter interface methods
202
- /**
203
- * Called when the component associated with the wire adapter is connected.
204
- */
205
- connect() {
206
- this.connected = true;
207
- this.callAdapter();
208
- }
209
- /**
210
- * Called when the component associated with the wire adapter is disconnected.
211
- */
212
- disconnect() {
213
- this.unsubscribe();
214
- this.connected = false;
215
- }
216
- /**
217
- * Called when new or updated config is supplied to the wire adapter.
218
- *
219
- * @param config new config parameters for the wire adapter
220
- * @param _context not used
221
- */
222
- update(config, _context) {
223
- this.unsubscribe();
224
- this.config = sanitize(config);
225
- this.callAdapter();
226
- }
227
- // private and protected utility methods
228
- /**
229
- * Calls the adapter if config has been set and the component is connected.
230
- */
231
- callAdapter() {
232
- if (!this.connected || this.config === undefined) {
233
- return;
234
- }
235
- const snapshotOrPromise = this.adapter(this.config);
236
- this.processAdapterResponse(snapshotOrPromise);
237
- }
238
- processAdapterResponse(snapshotOrPromise) {
239
- // insufficient config, wait for new config from component
240
- if (snapshotOrPromise === null) {
241
- return;
242
- }
243
- const configForSnapshot = this.config;
244
- const emitAndSubscribe = (snapshot) => {
245
- // adapters leveraging adapter context could asynchronously
246
- // return null (due to invalid config)
247
- if (snapshot === null) {
248
- return;
249
- }
250
- // We should never broadcast an unfulfilled snapshot to a component
251
- if (isUnfulfilledSnapshot(snapshot)) {
252
- if (process.env.NODE_ENV !== 'production') {
253
- throw new Error(`Unfulfilled snapshot emitted to component from subscription, missingPaths: ${keys(snapshot.missingPaths)}`);
254
- }
255
- // Instrument as a failed request
256
- this.luvio.instrument(() => {
257
- return {
258
- [ADAPTER_UNFULFILLED_ERROR]: true,
259
- adapterName: this.adapter.name,
260
- missingPaths: snapshot.missingPaths,
261
- missingLinks: snapshot.missingLinks,
262
- };
263
- });
264
- return;
265
- }
266
- // if config has changed before the snapshot arrives then ignore snapshot
267
- if (this.config !== configForSnapshot) {
268
- return;
269
- }
270
- // emit unless snapshot is pending
271
- if (isFulfilledSnapshot(snapshot) ||
272
- isErrorSnapshot(snapshot) ||
273
- isStaleSnapshot(snapshot)) {
274
- this.emit(snapshot);
275
- }
276
- // subscribe to the new snapshot
277
- this.subscribe(snapshot);
278
- };
279
- // Data resolved sync
280
- if (!isPromise(snapshotOrPromise)) {
281
- emitAndSubscribe(snapshotOrPromise);
282
- }
283
- else {
284
- // We want to let errors from this promise propagate to the app container,
285
- // which is why we do not have a reject handler here.
286
- // If an error is thrown here, it means that there was an error somewhere
287
- // inside an adapter which means that there was a mistake by the implementor.
288
- // Errors that come from the network should never hit this block because
289
- // they are treated like regular snapshots, not true error paths.
290
- snapshotOrPromise.then(emitAndSubscribe, (error) => throwAnnotatedError(error, ADAPTER_SNAPSHOT_REJECTED_MESSAGE));
291
- }
292
- }
293
- /**
294
- * Emits new values to the callback.
295
- *
296
- * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
297
- */
298
- emit(snapshot) {
299
- const payload = snapshotToPayload$1(snapshot);
300
- dataToTupleWeakMap.set(payload, [this.name, snapshot]);
301
- try {
302
- this.callback(payload);
303
- }
304
- catch (error) {
305
- if (error instanceof Error) {
306
- throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
307
- }
308
- }
309
- }
310
- /**
311
- * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
312
- * to the snapshot will be automatically emitted to the component.
313
- *
314
- * @param snapshot Snapshot
315
- * @param subscriptionCallback callback
316
- */
317
- subscribe(snapshot) {
318
- // always clean up any old subscription that we might have
319
- this.unsubscribe();
320
- // but only subscribe if component is currently connected
321
- if (this.connected) {
322
- this.unsubscriber = this.luvio.storeSubscribe(snapshot, this.emit.bind(this));
323
- }
324
- }
325
- /**
326
- * Deletes this wire adapter's snapshot subscription (if any).
327
- */
328
- unsubscribe() {
329
- // clean up subscription
330
- if (this.unsubscriber !== undefined) {
331
- this.unsubscriber();
332
- this.unsubscriber = undefined;
333
- }
334
- }
335
- }
336
- /**
337
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
338
- *
339
- * @param adapter Adapter
340
- * @param name name to assign to the generated constructor
341
- * @param luvio Luvio
342
- */
343
- function createWireAdapterConstructor(adapter, name, luvio) {
344
- const constructor = function (callback) {
345
- const delegate = new LWCLuvioWireAdapter(adapter, name, luvio, callback);
346
- this.connect = () => delegate.connect();
347
- this.disconnect = () => delegate.disconnect();
348
- this.update = (config, context) => delegate.update(config, context);
349
- };
350
- Object.defineProperty(constructor, 'name', { value: name });
351
- return constructor;
352
- }
353
-
354
- class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
355
- /**
356
- * Called when the component associated with the wire adapter is connected.
357
- */
358
- connect() {
359
- this.connectTimestamp = Date.now();
360
- super.connect();
361
- }
362
- /**
363
- * Called when the component associated with the wire adapter is disconnected.
364
- */
365
- disconnect() {
366
- this.connectTimestamp = undefined;
367
- super.disconnect();
368
- }
369
- /**
370
- * Called when new or updated config is supplied to the wire adapter.
371
- *
372
- * @param config new config parameters for the wire adapter
373
- * @param context context for the wire adapter
374
- */
375
- update(config, context) {
376
- if (this.connectTimestamp) {
377
- const mergedContext = Object.assign({
378
- cachePolicy: {
379
- type: 'valid-at',
380
- timestamp: this.connectTimestamp,
381
- },
382
- }, context);
383
- super.unsubscribe();
384
- this.config = sanitize(config);
385
- this.callAdapterWithContext(mergedContext);
386
- }
387
- else {
388
- super.update(config, context);
389
- }
390
- }
391
- /**
392
- * Calls the adapter if config has been set and the component is connected.
393
- */
394
- callAdapterWithContext(context) {
395
- if (!this.connected || this.config === undefined) {
396
- return;
397
- }
398
- const snapshotOrPromise = this.adapter(this.config, context);
399
- super.processAdapterResponse(snapshotOrPromise);
400
- }
401
- }
402
- function createInfiniteScrollingWireAdapterConstructor(adapter, name, luvio) {
403
- const constructor = function (callback) {
404
- const delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback);
405
- this.connect = () => delegate.connect();
406
- this.disconnect = () => delegate.disconnect();
407
- this.update = (config, context) => delegate.update(config, context);
408
- };
409
- Object.defineProperty(constructor, 'name', { value: name });
410
- return constructor;
411
- }
412
-
413
- function snapshotToPayload(snapshot) {
414
- const payload = {
415
- data: undefined,
416
- errors: undefined,
417
- };
418
- if (snapshot === undefined) {
419
- return payload;
420
- }
421
- payload.data = extractSnapshotData(snapshot);
422
- // TODO handle batch error scenarios.
423
- if ('error' in snapshot && snapshot.error !== undefined) {
424
- if (Array.isArray(snapshot.error)) {
425
- payload.errors = snapshot.error;
426
- }
427
- else {
428
- payload.errors = [snapshot.error];
429
- }
430
- }
431
- return payload;
432
- }
433
- class LWCGraphQLLuvioWireAdapter extends LWCLuvioWireAdapter {
434
- constructor(adapter, name, luvio, astResolver, callback) {
435
- super(adapter, name, luvio, callback);
436
- this.astResolver = astResolver;
437
- }
438
- update(config, _context) {
439
- this.unsubscribe();
440
- if (config.batchQuery) {
441
- this.config = {
442
- batchQuery: config.batchQuery.map((individualConfig) => safeSanitizeGraphQLConfigObject(individualConfig)),
443
- };
444
- }
445
- else {
446
- this.config = safeSanitizeGraphQLConfigObject(config);
447
- }
448
- this.callAdapter();
449
- }
450
- /**
451
- * Emits new values to the callback.
452
- *
453
- * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
454
- */
455
- emit(snapshot) {
456
- const payload = snapshotToPayload(snapshot);
457
- dataToTupleWeakMap.set(payload, [this.name, snapshot]);
458
- try {
459
- this.callback(payload);
460
- }
461
- catch (error) {
462
- if (error instanceof Error) {
463
- throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
464
- }
465
- }
466
- }
467
- /**
468
- * Coerce config before calling the adapter, preserve current behavior otherwise
469
- */
470
- callAdapter() {
471
- if (!this.connected || this.config === undefined) {
472
- return;
473
- }
474
- const config = this.config;
475
- if ('batchQuery' in config) {
476
- const batchConfig = {
477
- batchQuery: config.batchQuery.map((individualConfig) => this.resolveQueryAst(individualConfig)),
478
- };
479
- // If any of the configurations are invalid, we bail out of calling the adapter.
480
- if (batchConfig.batchQuery.some((val) => val === undefined)) {
481
- return;
482
- }
483
- const snapshotOrPromise = this.adapter(batchConfig);
484
- this.processAdapterResponse(snapshotOrPromise);
485
- }
486
- else if ('query' in config) {
487
- const singleConfig = this.resolveQueryAst(config);
488
- if (singleConfig !== undefined) {
489
- const snapshotOrPromise = this.adapter(singleConfig);
490
- this.processAdapterResponse(snapshotOrPromise);
491
- }
492
- }
493
- }
494
- resolveQueryAst(config) {
495
- if (config.query === null) {
496
- return;
497
- }
498
- const ast = this.astResolver(config.query);
499
- if (ast === undefined && config.query !== undefined) {
500
- // this should only happen if the user didn't parse the query
501
- if (process.env.NODE_ENV !== 'production') {
502
- throw new Error(USERLAND_GRAPHQL_PARSER_ERROR_MESSAGE);
503
- }
504
- return;
505
- }
506
- const resolvedAdapterConfig = {
507
- ...config,
508
- query: ast,
509
- };
510
- return resolvedAdapterConfig;
511
- }
512
- }
513
- function extractSnapshotData(snapshot) {
514
- if ('data' in snapshot && snapshot.data !== undefined) {
515
- const isSingleGraphQLData = 'data' in snapshot.data && snapshot.data.data !== undefined;
516
- const isBatchGraphQLData = 'results' in snapshot.data && snapshot.data.results !== undefined;
517
- if (isSingleGraphQLData)
518
- return snapshot.data.data;
519
- if (isBatchGraphQLData)
520
- return snapshot.data;
521
- }
522
- }
523
- /**
524
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
525
- *
526
- * @param adapter Adapter
527
- * @param name name to assign to the generated constructor
528
- * @param luvio Luvio
529
- */
530
- function createGraphQLWireAdapterConstructor(adapter, name, luvio, astResolver) {
531
- const constructor = function (callback) {
532
- const delegate = new LWCGraphQLLuvioWireAdapter(adapter, name, luvio, astResolver, callback);
533
- this.connect = () => delegate.connect();
534
- this.disconnect = () => delegate.disconnect();
535
- this.update = (config, context) => delegate.update(config, context);
536
- };
537
- Object.defineProperty(constructor, 'name', { value: name });
538
- return constructor;
539
- }
540
- function safeSanitizeGraphQLConfigObject(config) {
541
- // graphql query AST is passed by reference
542
- // sanitizing it makes a copy and we lose that reference
543
- // so we avoid sanitizing it
544
- return {
545
- ...sanitize(config),
546
- query: config.query,
547
- };
548
- }
549
-
550
- exports.ADAPTER_UNFULFILLED_ERROR = ADAPTER_UNFULFILLED_ERROR;
551
- exports.REFRESH_ADAPTER_EVENT = REFRESH_ADAPTER_EVENT;
552
- exports.bindWireRefresh = bindWireRefresh;
553
- exports.createGraphQLWireAdapterConstructor = createGraphQLWireAdapterConstructor;
554
- exports.createInfiniteScrollingWireAdapterConstructor = createInfiniteScrollingWireAdapterConstructor;
555
- exports.createWireAdapterConstructor = createWireAdapterConstructor;
556
- exports.refreshData = refreshData;
557
-
558
- }));
@@ -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;
@@ -1,26 +0,0 @@
1
- import type { Adapter, Luvio } from '@luvio/engine';
2
- import type { WireConfigValue, WireContextValue, WireAdapterConstructor } from '@lwc/engine-core';
3
- import { LWCLuvioWireAdapter } from './LWCLuvioWireAdapter';
4
- export declare class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
5
- private connectTimestamp?;
6
- /**
7
- * Called when the component associated with the wire adapter is connected.
8
- */
9
- connect(): void;
10
- /**
11
- * Called when the component associated with the wire adapter is disconnected.
12
- */
13
- disconnect(): void;
14
- /**
15
- * Called when new or updated config is supplied to the wire adapter.
16
- *
17
- * @param config new config parameters for the wire adapter
18
- * @param context context for the wire adapter
19
- */
20
- update(config: WireConfigValue, context?: WireContextValue): void;
21
- /**
22
- * Calls the adapter if config has been set and the component is connected.
23
- */
24
- private callAdapterWithContext;
25
- }
26
- export declare function createInfiniteScrollingWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -1,4 +0,0 @@
1
- import type { Luvio } from '@luvio/engine';
2
- import { dataToTupleWeakMap } from './utils/dataToTupleWeakMap';
3
- export declare function bindWireRefresh(luvio: Luvio): <D>(data: D) => Promise<undefined> | undefined;
4
- export declare function refreshData<D>(data: D, dataToTuple: typeof dataToTupleWeakMap, luvio: Luvio): Promise<undefined> | undefined;