@salesforce/lds-bindings 0.1.0-dev1

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.
package/LICENSE.txt ADDED
@@ -0,0 +1,82 @@
1
+ Terms of Use
2
+
3
+ Copyright 2022 Salesforce, Inc. All rights reserved.
4
+
5
+ These Terms of Use govern the download, installation, and/or use of this
6
+ software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
7
+ last updated on April 15, 2022, and constitute a legally binding
8
+ agreement between you and Salesforce. If you do not agree to these Terms of
9
+ Use, do not install or use the Software.
10
+
11
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
12
+ copyright license to reproduce, prepare derivative works of, publicly
13
+ display, publicly perform, sublicense, and distribute the Software and
14
+ derivative works subject to these Terms. These Terms shall be included in
15
+ all copies or substantial portions of the Software.
16
+
17
+ Subject to the limited rights expressly granted hereunder, Salesforce
18
+ reserves all rights, title, and interest in and to all intellectual
19
+ property subsisting in the Software. No rights are granted to you hereunder
20
+ other than as expressly set forth herein. Users residing in countries on
21
+ the United States Office of Foreign Assets Control sanction list, or which
22
+ are otherwise subject to a US export embargo, may not use the Software.
23
+
24
+ Implementation of the Software may require development work, for which you
25
+ are responsible. The Software may contain bugs, errors and
26
+ incompatibilities and is made available on an AS IS basis without support,
27
+ updates, or service level commitments.
28
+
29
+ Salesforce reserves the right at any time to modify, suspend, or
30
+ discontinue, the Software (or any part thereof) with or without notice. You
31
+ agree that Salesforce shall not be liable to you or to any third party for
32
+ any modification, suspension, or discontinuance.
33
+
34
+ You agree to defend Salesforce against any claim, demand, suit or
35
+ proceeding made or brought against Salesforce by a third party arising out
36
+ of or accruing from (a) your use of the Software, and (b) any application
37
+ you develop with the Software that infringes any copyright, trademark,
38
+ trade secret, trade dress, patent, or other intellectual property right of
39
+ any person or defames any person or violates their rights of publicity or
40
+ privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
41
+ from any damages, attorney fees, and costs finally awarded against
42
+ Salesforce as a result of, or for any amounts paid by Salesforce under a
43
+ settlement approved by you in writing of, a Claim Against Salesforce,
44
+ provided Salesforce (x) promptly gives you written notice of the Claim
45
+ Against Salesforce, (y) gives you sole control of the defense and
46
+ settlement of the Claim Against Salesforce (except that you may not settle
47
+ any Claim Against Salesforce unless it unconditionally releases Salesforce
48
+ of all liability), and (z) gives you all reasonable assistance, at your
49
+ expense.
50
+
51
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
52
+ SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53
+ IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
54
+ INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
55
+ PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
56
+ OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
57
+ CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
58
+ HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
59
+
60
+ These Terms of Use shall be governed exclusively by the internal laws of
61
+ the State of California, without regard to its conflicts of laws
62
+ rules. Each party hereby consents to the exclusive jurisdiction of the
63
+ state and federal courts located in San Francisco County, California to
64
+ adjudicate any dispute arising out of or relating to these Terms of Use and
65
+ the download, installation, and/or use of the Software. Except as expressly
66
+ stated herein, these Terms of Use constitute the entire agreement between
67
+ the parties, and supersede all prior and contemporaneous agreements,
68
+ proposals, or representations, written or oral, concerning their subject
69
+ matter. No modification, amendment, or waiver of any provision of these
70
+ Terms of Use shall be effective unless it is by an update to these Terms of
71
+ Use that Salesforce makes available, or is in writing and signed by the
72
+ party against whom the modification, amendment, or waiver is to be
73
+ asserted.
74
+
75
+ Data Privacy: Salesforce may collect, process, and store device,
76
+ system, and other information related to your use of the Software. This
77
+ information includes, but is not limited to, IP address, user metrics, and
78
+ other data ("Usage Data"). Salesforce may use Usage Data for analytics,
79
+ product development, and marketing purposes. You acknowledge that files
80
+ generated in conjunction with the Software may contain sensitive or
81
+ confidential data, and you are solely responsible for anonymizing and
82
+ protecting such data.
@@ -0,0 +1,1054 @@
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 { unwrap } from 'lwc';
16
+
17
+ // instrumentation keys to be imported by ldsInstrumentation
18
+ const REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
19
+ const ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
20
+ const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
21
+ const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
22
+ const USERLAND_GRAPHQL_PARSER_ERROR_MESSAGE = 'Use `gql` parser to parse your "query" string';
23
+
24
+ // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
25
+ // initially-emitted { data: undefined, error: undefined } value
26
+ const dataToTupleWeakMap = new WeakMap();
27
+
28
+ var SnapshotState$1;
29
+ (function (SnapshotState) {
30
+ SnapshotState["Fulfilled"] = "Fulfilled";
31
+ SnapshotState["Unfulfilled"] = "Unfulfilled";
32
+ SnapshotState["Error"] = "Error";
33
+ SnapshotState["Pending"] = "Pending";
34
+ SnapshotState["Stale"] = "Stale";
35
+ })(SnapshotState$1 || (SnapshotState$1 = {}));
36
+ function isErrorSnapshot$1(snapshot) {
37
+ return snapshot.state === SnapshotState$1.Error;
38
+ }
39
+ function isFulfilledSnapshot(snapshot) {
40
+ return snapshot.state === SnapshotState$1.Fulfilled;
41
+ }
42
+ function isStaleSnapshot(snapshot) {
43
+ return snapshot.state === SnapshotState$1.Stale;
44
+ }
45
+ function isUnfulfilledSnapshot(snapshot) {
46
+ return snapshot.state === SnapshotState$1.Unfulfilled;
47
+ }
48
+ /**
49
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
50
+ *
51
+ * @param snapshot Snapshot
52
+ */
53
+ function snapshotToPayload$1(snapshot) {
54
+ if (snapshot === undefined) {
55
+ return {
56
+ data: undefined,
57
+ error: undefined,
58
+ };
59
+ }
60
+ if (isErrorSnapshot$1(snapshot)) {
61
+ return {
62
+ data: undefined,
63
+ error: snapshot.error,
64
+ };
65
+ }
66
+ // fulfilled or stale
67
+ return {
68
+ data: snapshot.data,
69
+ error: undefined,
70
+ };
71
+ }
72
+
73
+ function bindWireRefresh$1(luvio) {
74
+ return function refresh(data) {
75
+ return refreshData(data, dataToTupleWeakMap, luvio);
76
+ };
77
+ }
78
+ function refreshData(data, dataToTuple, luvio) {
79
+ const tuple = dataToTuple.get(unwrap(data));
80
+ if (tuple === undefined) {
81
+ if (process.env.NODE_ENV !== 'production') {
82
+ throw new Error('Refresh failed because resolved configuration is not available.');
83
+ }
84
+ return;
85
+ }
86
+ const [adapterName, snapshot] = tuple;
87
+ luvio.instrument(() => {
88
+ return {
89
+ [REFRESH_ADAPTER_EVENT]: true,
90
+ adapterName,
91
+ };
92
+ });
93
+ // snapshot is undefined when a caller refreshes the initial
94
+ // { data: undefined, error: undefined } object that we emitted
95
+ if (snapshot === undefined) {
96
+ return Promise.resolve(undefined);
97
+ }
98
+ return luvio.refreshSnapshot(snapshot).then((refreshed) => {
99
+ if (isErrorSnapshot$1(refreshed)) {
100
+ throw refreshed.error;
101
+ }
102
+ if (process.env.NODE_ENV !== 'production') {
103
+ if (isUnfulfilledSnapshot(refreshed)) {
104
+ throw new Error('Refresh resulted in unfulfilled snapshot');
105
+ }
106
+ }
107
+ return undefined;
108
+ });
109
+ }
110
+
111
+ function isPromise$1(value) {
112
+ // check for Thenable due to test frameworks using custom Promise impls
113
+ return value.then !== undefined;
114
+ }
115
+
116
+ const { isArray } = Array;
117
+ const { stringify } = JSON;
118
+
119
+ /**
120
+ * (Re)throws an error after adding a prefix to the message.
121
+ *
122
+ * @param error Error
123
+ * @param messagePrefix prefix to add to error's message
124
+ */
125
+ function throwAnnotatedError(error, messagePrefix) {
126
+ if (error instanceof Error) {
127
+ error.message = `${messagePrefix}\n[${error.message}]`;
128
+ throw error;
129
+ }
130
+ throw new Error(`${messagePrefix}\n[${stringify(error)}]`);
131
+ }
132
+
133
+ class Sanitizer {
134
+ constructor(obj) {
135
+ this.obj = obj;
136
+ this.copy = {};
137
+ this.currentPath = {
138
+ key: '',
139
+ value: obj,
140
+ parent: null,
141
+ data: this.copy,
142
+ };
143
+ }
144
+ sanitize() {
145
+ const sanitizer = this;
146
+ stringify(this.obj, function (key, value) {
147
+ if (key === '') {
148
+ return value;
149
+ }
150
+ const parent = this;
151
+ if (parent !== sanitizer.currentPath.value) {
152
+ sanitizer.exit(parent);
153
+ }
154
+ if (typeof value === 'object' && value !== null) {
155
+ sanitizer.enter(key, value);
156
+ return value;
157
+ }
158
+ sanitizer.currentPath.data[key] = value;
159
+ return value;
160
+ });
161
+ return this.copy;
162
+ }
163
+ enter(key, value) {
164
+ const { currentPath: parentPath } = this;
165
+ const data = (parentPath.data[key] = isArray(value) ? [] : {});
166
+ this.currentPath = {
167
+ key,
168
+ value,
169
+ parent: parentPath,
170
+ data,
171
+ };
172
+ }
173
+ exit(parent) {
174
+ while (this.currentPath.value !== parent) {
175
+ this.currentPath = this.currentPath.parent || this.currentPath;
176
+ }
177
+ }
178
+ }
179
+ /**
180
+ * Returns a sanitized version of an object by recursively unwrapping the Proxies.
181
+ *
182
+ * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
183
+ * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
184
+ * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
185
+ * sanitized first.
186
+ */
187
+ function sanitize(obj) {
188
+ return new Sanitizer(obj).sanitize();
189
+ }
190
+
191
+ class LWCLuvioWireAdapter {
192
+ /**
193
+ * Constructs a new wire adapter instance for the given adapter.
194
+ *
195
+ * @param callback callback to be invoked with new values
196
+ */
197
+ constructor(adapter, name, luvio, callback, sourceContext) {
198
+ // a component can be connected-disconnected-reconnected multiple times during its
199
+ // life but we only want to keep subscriptions active while it is connected; the
200
+ // connect/disconnect methods below keep this value updated to reflect the current
201
+ // state
202
+ this.connected = false;
203
+ this.adapter = adapter;
204
+ this.name = name;
205
+ this.luvio = luvio;
206
+ this.callback = callback;
207
+ this.sourceContext = sourceContext;
208
+ // initialize the wired property with a properly shaped object so cmps can use <template if:true={wiredProperty.data}>
209
+ this.emit();
210
+ }
211
+ // WireAdapter interface methods
212
+ /**
213
+ * Called when the component associated with the wire adapter is connected.
214
+ */
215
+ connect() {
216
+ this.connected = true;
217
+ this.callAdapter(this.generateAdapterRequestContext());
218
+ }
219
+ /**
220
+ * Called when the component associated with the wire adapter is disconnected.
221
+ */
222
+ disconnect() {
223
+ this.unsubscribe();
224
+ this.connected = false;
225
+ }
226
+ /**
227
+ * Called when new or updated config is supplied to the wire adapter.
228
+ *
229
+ * @param config new config parameters for the wire adapter
230
+ * @param _context not used
231
+ */
232
+ update(config, context) {
233
+ this.unsubscribe();
234
+ this.config = sanitize(config);
235
+ this.callAdapter(this.generateAdapterRequestContext(context));
236
+ }
237
+ // private and protected utility methods
238
+ /**
239
+ * Accepts a WireContext and generates corresponding AdapterRequestContext
240
+ */
241
+ generateAdapterRequestContext(_context) {
242
+ if (!this.sourceContext) {
243
+ return {};
244
+ }
245
+ return {
246
+ sourceContext: { ...this.sourceContext },
247
+ };
248
+ }
249
+ /**
250
+ * Calls the adapter if config has been set and the component is connected.
251
+ */
252
+ callAdapter(context) {
253
+ if (!this.connected || this.config === undefined) {
254
+ return;
255
+ }
256
+ const snapshotOrPromise = this.adapter(this.config, context);
257
+ this.processAdapterResponse(snapshotOrPromise);
258
+ }
259
+ processAdapterResponse(snapshotOrPromise) {
260
+ // insufficient config, wait for new config from component
261
+ if (snapshotOrPromise === null) {
262
+ return;
263
+ }
264
+ const configForSnapshot = this.config;
265
+ const emitAndSubscribe = (snapshot) => {
266
+ // adapters leveraging adapter context could asynchronously
267
+ // return null (due to invalid config)
268
+ if (snapshot === null) {
269
+ return;
270
+ }
271
+ // We should never broadcast an unfulfilled snapshot to a component
272
+ if (isUnfulfilledSnapshot(snapshot)) {
273
+ if (process.env.NODE_ENV !== 'production') {
274
+ throw new Error(`Unfulfilled snapshot emitted to component from subscription, missingPaths: ${snapshot.missingPaths.keysAsArray()}`);
275
+ }
276
+ // Instrument as a failed request
277
+ this.luvio.instrument(() => {
278
+ return {
279
+ [ADAPTER_UNFULFILLED_ERROR]: true,
280
+ adapterName: this.adapter.name,
281
+ missingPaths: snapshot.missingPaths,
282
+ missingLinks: snapshot.missingLinks,
283
+ };
284
+ });
285
+ return;
286
+ }
287
+ // if config has changed before the snapshot arrives then ignore snapshot
288
+ if (this.config !== configForSnapshot) {
289
+ return;
290
+ }
291
+ // emit unless snapshot is pending
292
+ if (isFulfilledSnapshot(snapshot) ||
293
+ isErrorSnapshot$1(snapshot) ||
294
+ isStaleSnapshot(snapshot)) {
295
+ this.emit(snapshot);
296
+ }
297
+ // subscribe to the new snapshot
298
+ this.subscribe(snapshot);
299
+ };
300
+ // Data resolved sync
301
+ if (!isPromise$1(snapshotOrPromise)) {
302
+ emitAndSubscribe(snapshotOrPromise);
303
+ }
304
+ else {
305
+ // We want to let errors from this promise propagate to the app container,
306
+ // which is why we do not have a reject handler here.
307
+ // If an error is thrown here, it means that there was an error somewhere
308
+ // inside an adapter which means that there was a mistake by the implementor.
309
+ // Errors that come from the network should never hit this block because
310
+ // they are treated like regular snapshots, not true error paths.
311
+ snapshotOrPromise.then(emitAndSubscribe, (error) => throwAnnotatedError(error, ADAPTER_SNAPSHOT_REJECTED_MESSAGE));
312
+ }
313
+ }
314
+ /**
315
+ * Emits new values to the callback.
316
+ *
317
+ * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
318
+ */
319
+ emit(snapshot) {
320
+ const payload = snapshotToPayload$1(snapshot);
321
+ dataToTupleWeakMap.set(payload, [this.name, snapshot]);
322
+ try {
323
+ this.callback(payload);
324
+ }
325
+ catch (error) {
326
+ if (error instanceof Error) {
327
+ throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
328
+ }
329
+ }
330
+ }
331
+ /**
332
+ * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
333
+ * to the snapshot will be automatically emitted to the component.
334
+ *
335
+ * @param snapshot Snapshot
336
+ * @param subscriptionCallback callback
337
+ */
338
+ subscribe(snapshot) {
339
+ // always clean up any old subscription that we might have
340
+ this.unsubscribe();
341
+ // but only subscribe if component is currently connected
342
+ if (this.connected) {
343
+ this.unsubscriber = this.luvio.storeSubscribe(snapshot, this.emit.bind(this));
344
+ }
345
+ }
346
+ /**
347
+ * Deletes this wire adapter's snapshot subscription (if any).
348
+ */
349
+ unsubscribe() {
350
+ // clean up subscription
351
+ if (this.unsubscriber !== undefined) {
352
+ this.unsubscriber();
353
+ this.unsubscriber = undefined;
354
+ }
355
+ }
356
+ }
357
+ /**
358
+ * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
359
+ *
360
+ * @param adapter Adapter
361
+ * @param name name to assign to the generated constructor
362
+ * @param luvio Luvio
363
+ */
364
+ function createWireAdapterConstructor$1(adapter, name, luvio) {
365
+ const constructor = function (callback, sourceContext) {
366
+ const delegate = new LWCLuvioWireAdapter(adapter, name, luvio, callback, sourceContext);
367
+ this.connect = () => delegate.connect();
368
+ this.disconnect = () => delegate.disconnect();
369
+ this.update = (config, context) => delegate.update(config, context);
370
+ };
371
+ Object.defineProperty(constructor, 'name', { value: name });
372
+ return constructor;
373
+ }
374
+
375
+ /**
376
+ * Simple deep equality comparison for configuration objects.
377
+ * Handles primitives, arrays, and plain objects.
378
+ */
379
+ function deepEquals(a, b) {
380
+ if (a === b) {
381
+ return true;
382
+ }
383
+ if (a === null || a === undefined || b === null || b === undefined) {
384
+ return a === b;
385
+ }
386
+ if (typeof a !== typeof b) {
387
+ return false;
388
+ }
389
+ if (typeof a !== 'object') {
390
+ return false;
391
+ }
392
+ if (Array.isArray(a) !== Array.isArray(b)) {
393
+ return false;
394
+ }
395
+ if (Array.isArray(a) && Array.isArray(b)) {
396
+ if (a.length !== b.length) {
397
+ return false;
398
+ }
399
+ for (let i = 0; i < a.length; i++) {
400
+ if (!deepEquals(a[i], b[i])) {
401
+ return false;
402
+ }
403
+ }
404
+ return true;
405
+ }
406
+ // Handle plain objects
407
+ const aKeys = Object.keys(a);
408
+ const bKeys = Object.keys(b);
409
+ if (aKeys.length !== bKeys.length) {
410
+ return false;
411
+ }
412
+ for (const key of aKeys) {
413
+ if (!bKeys.includes(key)) {
414
+ return false;
415
+ }
416
+ if (!deepEquals(a[key], b[key])) {
417
+ return false;
418
+ }
419
+ }
420
+ return true;
421
+ }
422
+ class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
423
+ constructor(adapter, name, luvio, callback, sourceContext, paginationConfigParamNames) {
424
+ super(adapter, name, luvio, callback, sourceContext);
425
+ this.paginationConfigParamNames = paginationConfigParamNames;
426
+ }
427
+ /**
428
+ * Called when the component associated with the wire adapter is connected.
429
+ */
430
+ connect() {
431
+ this.connectTimestamp = Date.now();
432
+ super.connect();
433
+ }
434
+ /**
435
+ * Called when the component associated with the wire adapter is disconnected.
436
+ */
437
+ disconnect() {
438
+ this.connectTimestamp = undefined;
439
+ super.disconnect();
440
+ }
441
+ /**
442
+ * Called when new or updated config is supplied to the wire adapter.
443
+ *
444
+ * @param config new config parameters for the wire adapter
445
+ * @param context context for the wire adapter
446
+ */
447
+ update(config, context) {
448
+ if (this.connectTimestamp) {
449
+ // compare the incoming config with the current config.
450
+ // if any non-pagination config params have changed, we need to reset the connectTimestamp
451
+ const currentConfig = this.config;
452
+ // Check if any non-pagination parameters have changed
453
+ const hasNonPaginationParamChanged = Object.keys(config).some((paramName) => {
454
+ var _a;
455
+ // If this is not a pagination param and its value has changed
456
+ return (!((_a = this.paginationConfigParamNames) === null || _a === void 0 ? void 0 : _a.includes(paramName)) &&
457
+ !deepEquals(config[paramName], currentConfig === null || currentConfig === void 0 ? void 0 : currentConfig[paramName]));
458
+ });
459
+ if (hasNonPaginationParamChanged) {
460
+ this.connectTimestamp = Date.now();
461
+ }
462
+ const adapterRequestContext = this.generateAdapterRequestContext(context);
463
+ super.unsubscribe();
464
+ this.config = sanitize(config);
465
+ // this.callAdapterWithContext(mergedContext);
466
+ super.callAdapter(adapterRequestContext);
467
+ }
468
+ else {
469
+ super.update(config, context);
470
+ }
471
+ }
472
+ generateAdapterRequestContext(context) {
473
+ const baseContext = super.generateAdapterRequestContext(context);
474
+ // this code-path is only called when the wire adapter is connected
475
+ // and the connectTimestamp is set
476
+ return {
477
+ ...baseContext,
478
+ cachePolicy: {
479
+ type: 'valid-at',
480
+ timestamp: this.connectTimestamp,
481
+ },
482
+ };
483
+ }
484
+ subscribe(snapshot) {
485
+ var _a;
486
+ super.subscribe(snapshot);
487
+ // if the snapshot is refreshed we should stop using data from before the refresh
488
+ if (this.connected && ((_a = snapshot.refresh) === null || _a === void 0 ? void 0 : _a.resolve)) {
489
+ const originalResolve = snapshot.refresh.resolve;
490
+ snapshot.refresh.resolve = (config) => {
491
+ this.connectTimestamp = Date.now();
492
+ return originalResolve(config);
493
+ };
494
+ }
495
+ }
496
+ }
497
+ function createInfiniteScrollingWireAdapterConstructor$1(adapter, name, luvio, paginationConfigParamNames) {
498
+ const constructor = function (callback, sourceContext) {
499
+ const delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback, sourceContext, paginationConfigParamNames);
500
+ this.connect = () => delegate.connect();
501
+ this.disconnect = () => delegate.disconnect();
502
+ this.update = (config, context) => delegate.update(config, context);
503
+ };
504
+ Object.defineProperty(constructor, 'name', { value: name });
505
+ return constructor;
506
+ }
507
+
508
+ function snapshotToPayload(snapshot) {
509
+ const payload = {
510
+ data: undefined,
511
+ errors: undefined,
512
+ };
513
+ if (snapshot === undefined) {
514
+ return payload;
515
+ }
516
+ payload.data = extractSnapshotData(snapshot);
517
+ // TODO handle batch error scenarios.
518
+ if ('error' in snapshot && snapshot.error !== undefined) {
519
+ if (Array.isArray(snapshot.error)) {
520
+ payload.errors = snapshot.error;
521
+ }
522
+ else {
523
+ payload.errors = [snapshot.error];
524
+ }
525
+ }
526
+ return payload;
527
+ }
528
+ class LWCGraphQLLuvioWireAdapter extends LWCLuvioWireAdapter {
529
+ constructor(adapter, name, luvio, astResolver, callback, sourceContext) {
530
+ super(adapter, name, luvio, callback, sourceContext);
531
+ this.astResolver = astResolver;
532
+ }
533
+ update(config, context) {
534
+ this.unsubscribe();
535
+ if (config.batchQuery) {
536
+ this.config = {
537
+ batchQuery: config.batchQuery.map((individualConfig) => safeSanitizeGraphQLConfigObject(individualConfig)),
538
+ };
539
+ }
540
+ else {
541
+ this.config = safeSanitizeGraphQLConfigObject(config);
542
+ }
543
+ this.callAdapter(super.generateAdapterRequestContext(context));
544
+ }
545
+ /**
546
+ * Emits new values to the callback.
547
+ *
548
+ * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
549
+ */
550
+ emit(snapshot) {
551
+ const payload = snapshotToPayload(snapshot);
552
+ dataToTupleWeakMap.set(payload, [this.name, snapshot]);
553
+ try {
554
+ this.callback(payload);
555
+ }
556
+ catch (error) {
557
+ if (error instanceof Error) {
558
+ throwAnnotatedError(error, USERLAND_PROVISION_ERROR_MESSAGE);
559
+ }
560
+ }
561
+ }
562
+ /**
563
+ * Coerce config before calling the adapter, preserve current behavior otherwise
564
+ */
565
+ callAdapter(context) {
566
+ if (!this.connected || this.config === undefined) {
567
+ return;
568
+ }
569
+ const config = this.config;
570
+ if ('batchQuery' in config) {
571
+ const batchConfig = {
572
+ batchQuery: config.batchQuery.map((individualConfig) => this.resolveQueryAst(individualConfig)),
573
+ };
574
+ // If any of the configurations are invalid, we bail out of calling the adapter.
575
+ if (batchConfig.batchQuery.some((val) => val === undefined)) {
576
+ return;
577
+ }
578
+ const snapshotOrPromise = this.adapter(batchConfig, context);
579
+ this.processAdapterResponse(snapshotOrPromise);
580
+ }
581
+ else if ('query' in config) {
582
+ const singleConfig = this.resolveQueryAst(config);
583
+ if (singleConfig !== undefined) {
584
+ const snapshotOrPromise = this.adapter(singleConfig, context);
585
+ this.processAdapterResponse(snapshotOrPromise);
586
+ }
587
+ }
588
+ }
589
+ resolveQueryAst(config) {
590
+ if (config.query === null) {
591
+ return;
592
+ }
593
+ const ast = this.astResolver(config.query);
594
+ if (ast === undefined && config.query !== undefined) {
595
+ // this should only happen if the user didn't parse the query
596
+ if (process.env.NODE_ENV !== 'production') {
597
+ throw new Error(USERLAND_GRAPHQL_PARSER_ERROR_MESSAGE);
598
+ }
599
+ return;
600
+ }
601
+ const resolvedAdapterConfig = {
602
+ ...config,
603
+ query: ast,
604
+ };
605
+ return resolvedAdapterConfig;
606
+ }
607
+ }
608
+ function extractSnapshotData(snapshot) {
609
+ if ('data' in snapshot && snapshot.data !== undefined) {
610
+ const isSingleGraphQLData = 'data' in snapshot.data && snapshot.data.data !== undefined;
611
+ const isBatchGraphQLData = 'results' in snapshot.data && snapshot.data.results !== undefined;
612
+ if (isSingleGraphQLData)
613
+ return snapshot.data.data;
614
+ if (isBatchGraphQLData)
615
+ return snapshot.data;
616
+ }
617
+ }
618
+ /**
619
+ * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
620
+ *
621
+ * @param adapter Adapter
622
+ * @param name name to assign to the generated constructor
623
+ * @param luvio Luvio
624
+ */
625
+ function createGraphQLWireAdapterConstructor$1(adapter, name, luvio, astResolver) {
626
+ const constructor = function (callback, sourceContext) {
627
+ const delegate = new LWCGraphQLLuvioWireAdapter(adapter, name, luvio, astResolver, callback, sourceContext);
628
+ this.connect = () => delegate.connect();
629
+ this.disconnect = () => delegate.disconnect();
630
+ this.update = (config, context) => delegate.update(config, context);
631
+ };
632
+ Object.defineProperty(constructor, 'name', { value: name });
633
+ return constructor;
634
+ }
635
+ function safeSanitizeGraphQLConfigObject(config) {
636
+ // graphql query AST is passed by reference
637
+ // sanitizing it makes a copy and we lose that reference
638
+ // so we avoid sanitizing it
639
+ return {
640
+ ...sanitize(config),
641
+ query: config.query,
642
+ };
643
+ }
644
+
645
+ // For use by callers within this module to instrument interesting things.
646
+ let instrumentation = {
647
+ refreshCalled: (_fromSource) => { },
648
+ instrumentAdapter: (adapter, _metadata) => {
649
+ return adapter;
650
+ },
651
+ };
652
+ /**
653
+ * Allows external modules (typically a runtime environment) to set
654
+ * instrumentation hooks for this module. Note that the hooks are
655
+ * incremental - hooks not suppiled in newInstrumentation will retain
656
+ * their previous values. The default instrumentation hooks are no-ops.
657
+ *
658
+ * @param newInstrumentation instrumentation hooks to be overridden
659
+ */
660
+ function instrument(newInstrumentation) {
661
+ instrumentation = Object.assign(instrumentation, newInstrumentation);
662
+ }
663
+
664
+ let refresh;
665
+ function bindWireRefresh(luvio) {
666
+ const wireRefresh = bindWireRefresh$1(luvio);
667
+ refresh = (data, apiFamily) => {
668
+ instrumentation.refreshCalled(apiFamily);
669
+ return wireRefresh(data);
670
+ };
671
+ }
672
+
673
+ function createInstrumentedAdapter(adapter, metadata) {
674
+ return instrumentation.instrumentAdapter(adapter, metadata);
675
+ }
676
+
677
+ function createLDSAdapter(luvio, name, factory) {
678
+ return factory(luvio);
679
+ }
680
+
681
+ const { create, defineProperty, defineProperties } = Object;
682
+
683
+ var SnapshotState;
684
+ (function (SnapshotState) {
685
+ SnapshotState["Fulfilled"] = "Fulfilled";
686
+ SnapshotState["Unfulfilled"] = "Unfulfilled";
687
+ SnapshotState["Error"] = "Error";
688
+ SnapshotState["Pending"] = "Pending";
689
+ SnapshotState["Stale"] = "Stale";
690
+ })(SnapshotState || (SnapshotState = {}));
691
+ function isErrorSnapshot(snapshot) {
692
+ return snapshot.state === SnapshotState.Error;
693
+ }
694
+ function isPendingSnapshot(snapshot) {
695
+ return snapshot.state === SnapshotState.Pending;
696
+ }
697
+
698
+ function isPromise(value) {
699
+ // check for Thenable due to test frameworks using custom Promise impls
700
+ return value !== null && value.then !== undefined;
701
+ }
702
+
703
+ function snapshotToTuple$1(snapshot) {
704
+ if (isErrorSnapshot(snapshot)) {
705
+ return {
706
+ data: undefined,
707
+ error: snapshot.error,
708
+ };
709
+ }
710
+ // We might still get pending snapshot here from invoke calls here
711
+ return {
712
+ data: snapshot.data,
713
+ error: undefined,
714
+ };
715
+ }
716
+ function createInvalidConfigError$1() {
717
+ return {
718
+ data: undefined,
719
+ error: {
720
+ ok: false,
721
+ status: 400,
722
+ statusText: 'INVALID_CONFIG',
723
+ body: undefined,
724
+ headers: {},
725
+ errorType: 'fetchResponse',
726
+ },
727
+ };
728
+ }
729
+ /**
730
+ * Creates an imperative adapter
731
+ *
732
+ * @param luvio Luvio
733
+ * @param adapter luvio adapter
734
+ * @param metadata AdapterMetadata
735
+ * @returns Imperative adapter object with invoke and subscribe functions
736
+ */
737
+ function createImperativeAdapter(luvio, adapter, metadata) {
738
+ const { name } = metadata;
739
+ const imperativeAdapterInvoke = (config, requestContext, callback) => {
740
+ const snapshotOrPromise = adapter(config, requestContext);
741
+ if (snapshotOrPromise === null) {
742
+ callback(createInvalidConfigError$1());
743
+ return;
744
+ }
745
+ if (!isPromise(snapshotOrPromise)) {
746
+ callback(snapshotToTuple$1(snapshotOrPromise));
747
+ return;
748
+ }
749
+ snapshotOrPromise
750
+ .then((snapshot) => {
751
+ if (snapshot === null) {
752
+ callback(createInvalidConfigError$1());
753
+ return;
754
+ }
755
+ callback(snapshotToTuple$1(snapshot));
756
+ })
757
+ .finally(() => {
758
+ luvio.storeCleanup();
759
+ });
760
+ };
761
+ defineProperty(imperativeAdapterInvoke, 'name', {
762
+ value: `${name}_invoke`,
763
+ });
764
+ // Invokes the adapter and subscribes to the received snapshot
765
+ // Returns an unsubscribe function to the consumer
766
+ const imperativeAdapterSubscribe = (config, requestContext, callback) => {
767
+ let subscriberCallback = callback;
768
+ let unsub;
769
+ const snapshotOrPromise = adapter(config, requestContext);
770
+ if (snapshotOrPromise === null) {
771
+ subscriberCallback(createInvalidConfigError$1());
772
+ return () => { };
773
+ }
774
+ // Can rebuild lead to pending snapshots?
775
+ const luvioStoreSubscribe = (snapshot) => {
776
+ unsub = luvio.storeSubscribe(snapshot, (snapshotFromRebuild) => {
777
+ if (subscriberCallback !== null && !isPendingSnapshot(snapshotFromRebuild)) {
778
+ subscriberCallback(snapshotToTuple$1(snapshotFromRebuild));
779
+ }
780
+ });
781
+ };
782
+ if (!isPromise(snapshotOrPromise)) {
783
+ // We don't want to return pending snapshots to user-land
784
+ // Instead we just subscribe to it
785
+ if (!isPendingSnapshot(snapshotOrPromise)) {
786
+ subscriberCallback(snapshotToTuple$1(snapshotOrPromise));
787
+ }
788
+ luvioStoreSubscribe(snapshotOrPromise);
789
+ }
790
+ else {
791
+ snapshotOrPromise.then((snapshot) => {
792
+ if (subscriberCallback !== null) {
793
+ if (snapshot === null) {
794
+ subscriberCallback(createInvalidConfigError$1());
795
+ return;
796
+ }
797
+ // We don't want to return pending snapshots to user-land
798
+ // Instead we just subscribe to it
799
+ if (!isPendingSnapshot(snapshot)) {
800
+ subscriberCallback(snapshotToTuple$1(snapshot));
801
+ }
802
+ luvioStoreSubscribe(snapshot);
803
+ }
804
+ });
805
+ }
806
+ return () => {
807
+ if (subscriberCallback !== null && unsub !== undefined) {
808
+ unsub();
809
+ }
810
+ subscriberCallback = null;
811
+ unsub = undefined;
812
+ };
813
+ };
814
+ defineProperty(imperativeAdapterSubscribe, 'name', {
815
+ value: `${name}_subscribe`,
816
+ });
817
+ return {
818
+ invoke: imperativeAdapterInvoke,
819
+ subscribe: imperativeAdapterSubscribe,
820
+ };
821
+ }
822
+
823
+ function snapshotToTuple(snapshot) {
824
+ if (isErrorSnapshot(snapshot)) {
825
+ if (snapshot.error.errorType === 'adapterError') {
826
+ // GraphQL can return 200 with an errors array
827
+ return {
828
+ data: undefined,
829
+ errors: snapshot.error.error,
830
+ };
831
+ }
832
+ else {
833
+ // This is a network error or some other error - usually with a single error bubled up.
834
+ return {
835
+ data: undefined,
836
+ errors: [snapshot.error],
837
+ };
838
+ }
839
+ }
840
+ // cast any PendingSnapshot to FulfilledSnapshot here,
841
+ // we shouldn't get anything pending at this point
842
+ const payload = {};
843
+ const dataSnapshot = snapshot;
844
+ if ('data' in dataSnapshot.data && dataSnapshot.data.data !== undefined) {
845
+ payload.data = dataSnapshot.data.data;
846
+ }
847
+ if (dataSnapshot.data.errors !== undefined) {
848
+ payload.errors = dataSnapshot.data.errors;
849
+ }
850
+ return payload;
851
+ }
852
+ /**
853
+ * The graphql batch snapshot should be treated the same as a regular imperative adapter snapshot.
854
+ * @param snapshot - The snapshot to convert to a tuple
855
+ * @returns The tuple representation of the snapshot
856
+ */
857
+ function batchSnapshotToTuple(snapshot) {
858
+ if (isErrorSnapshot(snapshot)) {
859
+ return {
860
+ data: undefined,
861
+ error: snapshot.error,
862
+ };
863
+ }
864
+ // We might still get pending snapshot here from invoke calls here
865
+ return {
866
+ data: snapshot.data,
867
+ error: undefined,
868
+ };
869
+ }
870
+ function createInvalidConfigError() {
871
+ return {
872
+ data: undefined,
873
+ errors: [
874
+ {
875
+ ok: false,
876
+ status: 400,
877
+ statusText: 'INVALID_CONFIG',
878
+ body: undefined,
879
+ headers: {},
880
+ errorType: 'fetchResponse',
881
+ },
882
+ ],
883
+ };
884
+ }
885
+ /**
886
+ * Creates an imperative adapter
887
+ *
888
+ * @param luvio Luvio
889
+ * @param adapter luvio adapter
890
+ * @param metadata AdapterMetadata
891
+ * @returns Imperative adapter object with invoke and subscribe functions
892
+ */
893
+ function createGraphQLImperativeAdapter(luvio, adapter, metadata, astResolver) {
894
+ const { name } = metadata;
895
+ const imperativeAdapterInvoke = (config, requestContext, callback) => {
896
+ let coercedConfig = null;
897
+ let isBatch = false;
898
+ if ('batchQuery' in config) {
899
+ isBatch = true;
900
+ coercedConfig = {
901
+ batchQuery: config.batchQuery.map((individualConfig) => ({
902
+ ...individualConfig,
903
+ query: astResolver(individualConfig.query),
904
+ })),
905
+ };
906
+ // If any of the configurations are invalid, we bail out of calling the adapter.
907
+ if (coercedConfig.batchQuery.some((individualConfig) => individualConfig.query === undefined)) {
908
+ callback(createInvalidConfigError());
909
+ return;
910
+ }
911
+ }
912
+ else if ('query' in config) {
913
+ const ast = astResolver(config.query);
914
+ if (ast === undefined) {
915
+ callback(createInvalidConfigError());
916
+ return;
917
+ }
918
+ coercedConfig = {
919
+ ...config,
920
+ query: ast,
921
+ };
922
+ }
923
+ const snapshotOrPromise = adapter(coercedConfig, requestContext);
924
+ if (snapshotOrPromise === null) {
925
+ callback(createInvalidConfigError());
926
+ return;
927
+ }
928
+ if (!isPromise(snapshotOrPromise)) {
929
+ callback(isBatch
930
+ ? batchSnapshotToTuple(snapshotOrPromise)
931
+ : snapshotToTuple(snapshotOrPromise));
932
+ return;
933
+ }
934
+ snapshotOrPromise
935
+ .then((snapshot) => {
936
+ if (snapshot === null) {
937
+ callback(createInvalidConfigError());
938
+ return;
939
+ }
940
+ callback(isBatch ? batchSnapshotToTuple(snapshot) : snapshotToTuple(snapshot));
941
+ })
942
+ .finally(() => {
943
+ luvio.storeCleanup();
944
+ });
945
+ };
946
+ defineProperty(imperativeAdapterInvoke, 'name', {
947
+ value: `${name}_invoke`,
948
+ });
949
+ // Invokes the adapter and subscribes to the received snapshot
950
+ // Returns an unsubscribe function to the consumer
951
+ const imperativeAdapterSubscribe = (config, requestContext, callback) => {
952
+ let subscriberCallback = callback;
953
+ let unsub;
954
+ let coercedConfig = null;
955
+ let isBatch = false;
956
+ if ('batchQuery' in config) {
957
+ isBatch = true;
958
+ coercedConfig = {
959
+ batchQuery: config.batchQuery.map((individualConfig) => ({
960
+ ...individualConfig,
961
+ query: astResolver(individualConfig.query),
962
+ })),
963
+ };
964
+ // If any of the configurations are invalid, we bail out of calling the adapter.
965
+ if (coercedConfig.batchQuery.some((individualConfig) => individualConfig.query === undefined)) {
966
+ callback(createInvalidConfigError());
967
+ return () => { };
968
+ }
969
+ }
970
+ else if ('query' in config) {
971
+ const ast = astResolver(config.query);
972
+ if (ast === undefined) {
973
+ callback(createInvalidConfigError());
974
+ return () => { };
975
+ }
976
+ coercedConfig = {
977
+ ...config,
978
+ query: ast,
979
+ };
980
+ }
981
+ const snapshotOrPromise = adapter(coercedConfig, requestContext);
982
+ if (snapshotOrPromise === null) {
983
+ subscriberCallback(createInvalidConfigError());
984
+ return () => { };
985
+ }
986
+ // Can rebuild lead to pending snapshots?
987
+ const luvioStoreSubscribe = (snapshot) => {
988
+ unsub = luvio.storeSubscribe(snapshot, (snapshotFromRebuild) => {
989
+ if (subscriberCallback !== null && !isPendingSnapshot(snapshotFromRebuild)) {
990
+ subscriberCallback(isBatch
991
+ ? batchSnapshotToTuple(snapshotFromRebuild)
992
+ : snapshotToTuple(snapshotFromRebuild));
993
+ }
994
+ });
995
+ };
996
+ if (!isPromise(snapshotOrPromise)) {
997
+ // We don't want to return pending snapshots to user-land
998
+ // Instead we just subscribe to it
999
+ if (!isPendingSnapshot(snapshotOrPromise)) {
1000
+ subscriberCallback(isBatch
1001
+ ? batchSnapshotToTuple(snapshotOrPromise)
1002
+ : snapshotToTuple(snapshotOrPromise));
1003
+ }
1004
+ luvioStoreSubscribe(snapshotOrPromise);
1005
+ }
1006
+ else {
1007
+ snapshotOrPromise.then((snapshot) => {
1008
+ if (subscriberCallback !== null) {
1009
+ if (snapshot === null) {
1010
+ subscriberCallback(createInvalidConfigError());
1011
+ return;
1012
+ }
1013
+ // TODO [W-11370904]: revisit this. Does GraphQL need to worry about pending?
1014
+ // We don't want to return pending snapshots to user-land
1015
+ // Instead we just subscribe to it
1016
+ if (!isPendingSnapshot(snapshot)) {
1017
+ subscriberCallback(isBatch ? batchSnapshotToTuple(snapshot) : snapshotToTuple(snapshot));
1018
+ }
1019
+ luvioStoreSubscribe(snapshot);
1020
+ }
1021
+ });
1022
+ }
1023
+ return () => {
1024
+ if (subscriberCallback !== null && unsub !== undefined) {
1025
+ unsub();
1026
+ }
1027
+ subscriberCallback = null;
1028
+ unsub = undefined;
1029
+ };
1030
+ };
1031
+ defineProperty(imperativeAdapterSubscribe, 'name', {
1032
+ value: `${name}_subscribe`,
1033
+ });
1034
+ return {
1035
+ invoke: imperativeAdapterInvoke,
1036
+ subscribe: imperativeAdapterSubscribe,
1037
+ };
1038
+ }
1039
+
1040
+ function createWireAdapterConstructor(luvio, adapter, metadata) {
1041
+ const { apiFamily, name } = metadata;
1042
+ return createWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio);
1043
+ }
1044
+ function createInfiniteScrollingWireAdapterConstructor(luvio, adapter, metadata, paginationConfigParamNames) {
1045
+ const { apiFamily, name } = metadata;
1046
+ return createInfiniteScrollingWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, paginationConfigParamNames);
1047
+ }
1048
+ function createGraphQLWireAdapterConstructor(luvio, adapter, metadata, astResolver) {
1049
+ const { apiFamily, name } = metadata;
1050
+ return createGraphQLWireAdapterConstructor$1(adapter, `${apiFamily}.${name}`, luvio, astResolver);
1051
+ }
1052
+
1053
+ export { ADAPTER_UNFULFILLED_ERROR, REFRESH_ADAPTER_EVENT, bindWireRefresh, createGraphQLImperativeAdapter, createGraphQLWireAdapterConstructor, createImperativeAdapter, createInfiniteScrollingWireAdapterConstructor, createInstrumentedAdapter, createLDSAdapter, createWireAdapterConstructor, instrument, refresh };
1054
+ // version: 0.1.0-dev1-54c03dd38c
@@ -0,0 +1,7 @@
1
+ import type { Luvio } from '@luvio/engine';
2
+ export type refreshApiNames = {
3
+ refreshApex: string;
4
+ refreshUiApi: string;
5
+ };
6
+ export declare let refresh: (data: any, apiFamily: keyof refreshApiNames) => Promise<undefined> | undefined;
7
+ export declare function bindWireRefresh(luvio: Luvio): void;
@@ -0,0 +1 @@
1
+ export { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR } from '@luvio/lwc-luvio';
@@ -0,0 +1,40 @@
1
+ import type { Adapter, AdapterRequestContext, ErrorResponse as LuvioErrorResponse, Luvio, Unsubscribe } from '@luvio/engine';
2
+ import type { AstResolver } from '@luvio/graphql-parser';
3
+ import type { GraphQLError, GraphQLInput } from '@luvio/lwc-luvio';
4
+ import type { AdapterMetadata } from './ldsAdapter';
5
+ interface DataResponse {
6
+ data: any;
7
+ errors?: GraphQLError[];
8
+ }
9
+ interface ErrorResponse {
10
+ data: undefined;
11
+ errors: LuvioErrorResponse[];
12
+ }
13
+ interface BatchDataResponse {
14
+ data: any;
15
+ error?: undefined;
16
+ }
17
+ interface BatchErrorResponse {
18
+ data: undefined;
19
+ error: LuvioErrorResponse;
20
+ }
21
+ type DataCallbackTuple = DataResponse | ErrorResponse | BatchDataResponse | BatchErrorResponse;
22
+ interface DataCallback {
23
+ (response: DataCallbackTuple): void;
24
+ }
25
+ type ImperativeAdapterInvokeType<C> = (config: C, context: AdapterRequestContext, callback: DataCallback) => void;
26
+ type ImperativeAdapterSubscribeType<C> = (config: C, context: AdapterRequestContext, callback: DataCallback) => Unsubscribe;
27
+ export interface ImperativeAdapter<C> {
28
+ invoke: ImperativeAdapterInvokeType<C>;
29
+ subscribe: ImperativeAdapterSubscribeType<C>;
30
+ }
31
+ /**
32
+ * Creates an imperative adapter
33
+ *
34
+ * @param luvio Luvio
35
+ * @param adapter luvio adapter
36
+ * @param metadata AdapterMetadata
37
+ * @returns Imperative adapter object with invoke and subscribe functions
38
+ */
39
+ export declare function createGraphQLImperativeAdapter<C extends GraphQLInput, D>(luvio: Luvio, adapter: Adapter<C, D>, metadata: AdapterMetadata, astResolver: AstResolver): ImperativeAdapter<C>;
40
+ export {};
@@ -0,0 +1,31 @@
1
+ import type { Adapter, AdapterRequestContext, ErrorResponse as LuvioErrorResponse, Luvio, Snapshot, StaleSnapshot, UnfulfilledSnapshot, Unsubscribe } from '@luvio/engine';
2
+ import type { AdapterMetadata } from './ldsAdapter';
3
+ interface DataResponse<D> {
4
+ data: D;
5
+ error: undefined;
6
+ }
7
+ interface ErrorResponse {
8
+ data: undefined;
9
+ error: LuvioErrorResponse;
10
+ }
11
+ export type DataCallbackTuple<D> = DataResponse<D> | ErrorResponse;
12
+ export type CallbackSnapshot<D> = Exclude<Snapshot<D>, UnfulfilledSnapshot<D> | StaleSnapshot<D>>;
13
+ export interface DataCallback<D> {
14
+ (response: DataCallbackTuple<D>): void;
15
+ }
16
+ type ImperativeAdapterInvokeType<C, D> = (config: C, context: AdapterRequestContext | undefined, callback: DataCallback<D>) => void;
17
+ type ImperativeAdapterSubscribeType<C, D> = (config: C, context: AdapterRequestContext | undefined, callback: DataCallback<D>) => Unsubscribe;
18
+ export interface ImperativeAdapter<C, D> {
19
+ invoke: ImperativeAdapterInvokeType<C, D>;
20
+ subscribe: ImperativeAdapterSubscribeType<C, D>;
21
+ }
22
+ /**
23
+ * Creates an imperative adapter
24
+ *
25
+ * @param luvio Luvio
26
+ * @param adapter luvio adapter
27
+ * @param metadata AdapterMetadata
28
+ * @returns Imperative adapter object with invoke and subscribe functions
29
+ */
30
+ export declare function createImperativeAdapter<C, D>(luvio: Luvio, adapter: Adapter<C, D>, metadata: AdapterMetadata): ImperativeAdapter<C, D>;
31
+ export {};
@@ -0,0 +1,29 @@
1
+ import type { Adapter } from '@luvio/engine';
2
+ import type { AdapterMetadata } from './ldsAdapter';
3
+ import type { refreshApiNames } from './bindWireRefresh';
4
+ /**
5
+ * Instrumentation hooks exposed by this module.
6
+ */
7
+ export interface LwcBindingsInstrumentation {
8
+ /**
9
+ * Called when an LWC calls `refresh`.
10
+ */
11
+ refreshCalled?: (fromSource: keyof refreshApiNames) => void;
12
+ /**
13
+ * Called when creating wire adapters.
14
+ */
15
+ instrumentAdapter?: <C, D>(adapter: Adapter<C, D>, metadata: AdapterMetadata) => Adapter<C, D>;
16
+ }
17
+ export declare let instrumentation: {
18
+ refreshCalled: (_fromSource: keyof refreshApiNames) => void;
19
+ instrumentAdapter: <C, D>(adapter: Adapter<C, D>, _metadata: AdapterMetadata) => Adapter<C, D>;
20
+ };
21
+ /**
22
+ * Allows external modules (typically a runtime environment) to set
23
+ * instrumentation hooks for this module. Note that the hooks are
24
+ * incremental - hooks not suppiled in newInstrumentation will retain
25
+ * their previous values. The default instrumentation hooks are no-ops.
26
+ *
27
+ * @param newInstrumentation instrumentation hooks to be overridden
28
+ */
29
+ export declare function instrument(newInstrumentation: LwcBindingsInstrumentation): void;
@@ -0,0 +1,3 @@
1
+ import type { Adapter } from '@luvio/engine';
2
+ import type { AdapterMetadata } from './ldsAdapter';
3
+ export declare function createInstrumentedAdapter<C, D>(adapter: Adapter<C, D>, metadata: AdapterMetadata): Adapter<C, D>;
@@ -0,0 +1,7 @@
1
+ import type { Luvio } from '@luvio/engine';
2
+ export interface AdapterMetadata {
3
+ apiFamily: string;
4
+ name: string;
5
+ ttl?: number;
6
+ }
7
+ export declare function createLDSAdapter<T>(luvio: Luvio, name: string, factory: (luvio: Luvio) => T): T;
@@ -0,0 +1,10 @@
1
+ export { bindWireRefresh, refresh } from './bindWireRefresh';
2
+ export { LwcBindingsInstrumentation, instrument } from './instrumentation';
3
+ export { createInstrumentedAdapter } from './instrumentedAdapter';
4
+ export { AdapterMetadata, createLDSAdapter } from './ldsAdapter';
5
+ export { createImperativeAdapter } from './imperativeAdapter';
6
+ export { createGraphQLImperativeAdapter } from './graphQLImperativeAdapter';
7
+ export { createWireAdapterConstructor, createInfiniteScrollingWireAdapterConstructor, createGraphQLWireAdapterConstructor, } from './wireAdapter';
8
+ export { DataCallback, DataCallbackTuple, ImperativeAdapter } from './imperativeAdapter';
9
+ export { ImperativeAdapter as GraphQLImperativeAdapter } from './graphQLImperativeAdapter';
10
+ export { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR } from './constants';
@@ -0,0 +1,5 @@
1
+ declare const create: {
2
+ (o: object | null): any;
3
+ (o: object | null, properties: PropertyDescriptorMap & ThisType<any>): any;
4
+ }, defineProperty: <T>(o: T, p: PropertyKey, attributes: PropertyDescriptor & ThisType<any>) => T, defineProperties: <T>(o: T, properties: PropertyDescriptorMap & ThisType<any>) => T;
5
+ export { create as ObjectCreate, defineProperty as ObjectDefineProperty, defineProperties as ObjectDefineProperties, };
@@ -0,0 +1,3 @@
1
+ import type { ErrorSnapshot, PendingSnapshot, Snapshot } from '@luvio/engine';
2
+ export declare function isErrorSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is ErrorSnapshot;
3
+ export declare function isPendingSnapshot<D>(snapshot: Snapshot<D, unknown>): snapshot is PendingSnapshot<D>;
@@ -0,0 +1 @@
1
+ export declare function isPromise<D>(value: D | Promise<D> | null): value is Promise<D>;
@@ -0,0 +1,7 @@
1
+ import type { Adapter, Luvio } from '@luvio/engine';
2
+ import type { WireAdapterConstructor } from '@lwc/engine-core';
3
+ import type { AdapterMetadata } from './ldsAdapter';
4
+ import type { AstResolver } from '@luvio/graphql-parser';
5
+ export declare function createWireAdapterConstructor<C, D>(luvio: Luvio, adapter: Adapter<C, D>, metadata: AdapterMetadata): WireAdapterConstructor;
6
+ export declare function createInfiniteScrollingWireAdapterConstructor<C, D>(luvio: Luvio, adapter: Adapter<C, D>, metadata: AdapterMetadata, paginationConfigParamNames?: string[]): WireAdapterConstructor;
7
+ export declare function createGraphQLWireAdapterConstructor<C, D>(luvio: Luvio, adapter: Adapter<C, D>, metadata: AdapterMetadata, astResolver: AstResolver): WireAdapterConstructor;
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@salesforce/lds-bindings",
3
+ "version": "0.1.0-dev1",
4
+ "license": "SEE LICENSE IN LICENSE.txt",
5
+ "description": "LDS Bindings for SFDC",
6
+ "main": "dist/ldsBindings.js",
7
+ "module": "dist/ldsBindings.js",
8
+ "types": "dist/types/main.d.ts",
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/main.d.ts",
15
+ "import": "./dist/ldsBindings.js",
16
+ "default": "./dist/ldsBindings.js"
17
+ }
18
+ },
19
+ "sfdc": {
20
+ "path": "forcelds/ldsBindings/",
21
+ "overrides": {
22
+ "artifactDirectory": "dist"
23
+ }
24
+ },
25
+ "scripts": {
26
+ "prepare": "yarn build",
27
+ "build": "rollup --bundleConfigAsCjs --config rollup.config.js",
28
+ "clean": "rm -rf dist",
29
+ "test:unit": "jest",
30
+ "test:unit:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand",
31
+ "release:corejar": "yarn build && ../core-build/scripts/core.js --name=lds-bindings"
32
+ },
33
+ "dependencies": {
34
+ "@salesforce/lds-graphql-parser": "^0.1.0-dev1"
35
+ },
36
+ "devDependencies": {
37
+ "@lwc/engine-core": "2.42.0"
38
+ },
39
+ "volta": {
40
+ "extends": "../../package.json"
41
+ }
42
+ }