@luvio/lwc-luvio 0.62.3 → 0.63.2

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 (31) hide show
  1. package/dist/es/es2018/LWCInfiniteScrollingLuvioWireAdapter.d.ts +6 -0
  2. package/dist/es/es2018/LWCLuvioBindings.d.ts +4 -0
  3. package/dist/es/es2018/LWCLuvioWireAdapter.d.ts +62 -0
  4. package/dist/es/es2018/lwcluvio.js +114 -98
  5. package/dist/es/es2018/main.d.ts +5 -16
  6. package/dist/es/es2018/utils/SnapshotState.d.ts +12 -0
  7. package/dist/es/es2018/utils/constants.d.ts +4 -0
  8. package/dist/es/es2018/utils/dataToTupleWeakMap.d.ts +2 -0
  9. package/dist/es/es2018/utils/isPromise.d.ts +1 -0
  10. package/dist/es/es2018/utils/throwAnnotatedError.d.ts +7 -0
  11. package/dist/umd/es2018/LWCInfiniteScrollingLuvioWireAdapter.d.ts +6 -0
  12. package/dist/umd/es2018/LWCLuvioBindings.d.ts +4 -0
  13. package/dist/umd/es2018/LWCLuvioWireAdapter.d.ts +62 -0
  14. package/dist/umd/es2018/lwcluvio.js +117 -100
  15. package/dist/umd/es2018/main.d.ts +5 -16
  16. package/dist/umd/es2018/utils/SnapshotState.d.ts +12 -0
  17. package/dist/umd/es2018/utils/constants.d.ts +4 -0
  18. package/dist/umd/es2018/utils/dataToTupleWeakMap.d.ts +2 -0
  19. package/dist/umd/es2018/utils/isPromise.d.ts +1 -0
  20. package/dist/umd/es2018/utils/throwAnnotatedError.d.ts +7 -0
  21. package/dist/umd/es5/LWCInfiniteScrollingLuvioWireAdapter.d.ts +6 -0
  22. package/dist/umd/es5/LWCLuvioBindings.d.ts +4 -0
  23. package/dist/umd/es5/LWCLuvioWireAdapter.d.ts +62 -0
  24. package/dist/umd/es5/lwcluvio.js +160 -105
  25. package/dist/umd/es5/main.d.ts +5 -16
  26. package/dist/umd/es5/utils/SnapshotState.d.ts +12 -0
  27. package/dist/umd/es5/utils/constants.d.ts +4 -0
  28. package/dist/umd/es5/utils/dataToTupleWeakMap.d.ts +2 -0
  29. package/dist/umd/es5/utils/isPromise.d.ts +1 -0
  30. package/dist/umd/es5/utils/throwAnnotatedError.d.ts +7 -0
  31. package/package.json +4 -4
@@ -0,0 +1,6 @@
1
+ import { Adapter, Luvio } from '@luvio/engine';
2
+ import { WireAdapterConstructor } from '@lwc/engine-core';
3
+ import { LWCLuvioWireAdapter } from './LWCLuvioWireAdapter';
4
+ export declare class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
5
+ }
6
+ export declare function createInfiniteScrollingWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -0,0 +1,4 @@
1
+ import { 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;
@@ -0,0 +1,62 @@
1
+ import { Adapter, Luvio, Unsubscribe } from '@luvio/engine';
2
+ import { WireConfigValue, WireContextValue, DataCallback, WireAdapter, WireAdapterConstructor } from '@lwc/engine-core';
3
+ export declare class LWCLuvioWireAdapter implements WireAdapter {
4
+ adapter: Adapter<unknown, unknown>;
5
+ name: string;
6
+ callback: DataCallback;
7
+ config?: unknown;
8
+ connected: boolean;
9
+ luvio: Luvio;
10
+ unsubscriber?: Unsubscribe;
11
+ /**
12
+ * Constructs a new wire adapter instance for the given adapter.
13
+ *
14
+ * @param callback callback to be invoked with new values
15
+ */
16
+ constructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio, callback: DataCallback);
17
+ /**
18
+ * Called when the component associated with the wire adapter is connected.
19
+ */
20
+ connect(): void;
21
+ /**
22
+ * Called when the component associated with the wire adapter is disconnected.
23
+ */
24
+ disconnect(): void;
25
+ /**
26
+ * Called when new or updated config is supplied to the wire adapter.
27
+ *
28
+ * @param config new config parameters for the wire adapter
29
+ * @param _context not used
30
+ */
31
+ update(config: WireConfigValue, _context?: WireContextValue): void;
32
+ /**
33
+ * Calls the adapter if config has been set and the component is connected.
34
+ */
35
+ private callAdapter;
36
+ /**
37
+ * Emits new values to the callback.
38
+ *
39
+ * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
40
+ */
41
+ private emit;
42
+ /**
43
+ * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
44
+ * to the snapshot will be automatically emitted to the component.
45
+ *
46
+ * @param snapshot Snapshot
47
+ * @param subscriptionCallback callback
48
+ */
49
+ private subscribe;
50
+ /**
51
+ * Deletes this wire adapter's snapshot subscription (if any).
52
+ */
53
+ private unsubscribe;
54
+ }
55
+ /**
56
+ * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
57
+ *
58
+ * @param adapter Adapter
59
+ * @param name name to assign to the generated constructor
60
+ * @param luvio Luvio
61
+ */
62
+ export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -1,69 +1,15 @@
1
1
  import { unwrap } from 'lwc';
2
2
 
3
- const { freeze, keys } = Object;
4
- const { isArray } = Array;
5
- const { stringify } = JSON;
3
+ // instrumentation keys to be imported by ldsInstrumentation
4
+ const REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
5
+ const ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
6
+ const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
7
+ const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
6
8
 
7
- class Sanitizer {
8
- constructor(obj) {
9
- this.obj = obj;
10
- this.copy = {};
11
- this.currentPath = {
12
- key: '',
13
- value: obj,
14
- parent: null,
15
- data: this.copy,
16
- };
17
- }
18
- sanitize() {
19
- const sanitizer = this;
20
- stringify(this.obj, function (key, value) {
21
- if (key === '') {
22
- return value;
23
- }
24
- const parent = this;
25
- if (parent !== sanitizer.currentPath.value) {
26
- sanitizer.exit(parent);
27
- }
28
- if (typeof value === 'object' && value !== null) {
29
- sanitizer.enter(key, value);
30
- return value;
31
- }
32
- sanitizer.currentPath.data[key] = value;
33
- return value;
34
- });
35
- return this.copy;
36
- }
37
- enter(key, value) {
38
- const { currentPath: parentPath } = this;
39
- const data = (parentPath.data[key] = isArray(value) ? [] : {});
40
- this.currentPath = {
41
- key,
42
- value,
43
- parent: parentPath,
44
- data,
45
- };
46
- }
47
- exit(parent) {
48
- while (this.currentPath.value !== parent) {
49
- this.currentPath = this.currentPath.parent || this.currentPath;
50
- }
51
- }
52
- }
53
- /**
54
- * Returns a sanitized version of an object by recursively unwrapping the Proxies.
55
- *
56
- * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
57
- * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
58
- * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
59
- * sanitized first.
60
- */
61
- function sanitize(obj) {
62
- return new Sanitizer(obj).sanitize();
63
- }
9
+ // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
10
+ // initially-emitted { data: undefined, error: undefined } value
11
+ const dataToTupleWeakMap = new WeakMap();
64
12
 
65
- // Copied from engine to avoid build time dependency
66
- // BEGIN OF COPY BLOCK
67
13
  var SnapshotState;
68
14
  (function (SnapshotState) {
69
15
  SnapshotState["Fulfilled"] = "Fulfilled";
@@ -84,20 +30,36 @@ function isStaleSnapshot(snapshot) {
84
30
  function isUnfulfilledSnapshot(snapshot) {
85
31
  return snapshot.state === SnapshotState.Unfulfilled;
86
32
  }
87
- // END OF COPY BLOCK
88
- const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
89
- const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
90
- // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
91
- // initially-emitted { data: undefined, error: undefined } value
92
- const dataToTupleWeakMap = new WeakMap();
33
+ /**
34
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
35
+ *
36
+ * @param snapshot Snapshot
37
+ */
38
+ function snapshotToPayload(snapshot) {
39
+ if (snapshot === undefined) {
40
+ return {
41
+ data: undefined,
42
+ error: undefined,
43
+ };
44
+ }
45
+ if (isErrorSnapshot(snapshot)) {
46
+ return {
47
+ data: undefined,
48
+ error: snapshot.error,
49
+ };
50
+ }
51
+ // fulfilled or stale
52
+ return {
53
+ data: snapshot.data,
54
+ error: undefined,
55
+ };
56
+ }
57
+
93
58
  function bindWireRefresh(luvio) {
94
59
  return function refresh(data) {
95
60
  return refreshData(data, dataToTupleWeakMap, luvio);
96
61
  };
97
62
  }
98
- // instrumentation keys to be imported by ldsInstrumentation
99
- const REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
100
- const ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
101
63
  function refreshData(data, dataToTuple, luvio) {
102
64
  const tuple = dataToTuple.get(unwrap(data));
103
65
  if (tuple === undefined) {
@@ -129,35 +91,17 @@ function refreshData(data, dataToTuple, luvio) {
129
91
  }
130
92
  return undefined;
131
93
  });
132
- }
94
+ }
95
+
96
+ const { freeze, keys } = Object;
97
+ const { isArray } = Array;
98
+ const { stringify } = JSON;
99
+
133
100
  function isPromise(value) {
134
101
  // check for Thenable due to test frameworks using custom Promise impls
135
102
  return value.then !== undefined;
136
- }
137
- /**
138
- * Transform a Snapshot into a payload suitable for passing to a DataCallback.
139
- *
140
- * @param snapshot Snapshot
141
- */
142
- function snapshotToPayload(snapshot) {
143
- if (snapshot === undefined) {
144
- return {
145
- data: undefined,
146
- error: undefined,
147
- };
148
- }
149
- if (isErrorSnapshot(snapshot)) {
150
- return {
151
- data: undefined,
152
- error: snapshot.error,
153
- };
154
- }
155
- // fulfilled or stale
156
- return {
157
- data: snapshot.data,
158
- error: undefined,
159
- };
160
- }
103
+ }
104
+
161
105
  /**
162
106
  * (Re)throws an error after adding a prefix to the message.
163
107
  *
@@ -170,7 +114,66 @@ function throwAnnotatedError(error, messagePrefix) {
170
114
  throw error;
171
115
  }
172
116
  throw new Error(`${messagePrefix}\n[${stringify(error)}]`);
117
+ }
118
+
119
+ class Sanitizer {
120
+ constructor(obj) {
121
+ this.obj = obj;
122
+ this.copy = {};
123
+ this.currentPath = {
124
+ key: '',
125
+ value: obj,
126
+ parent: null,
127
+ data: this.copy,
128
+ };
129
+ }
130
+ sanitize() {
131
+ const sanitizer = this;
132
+ stringify(this.obj, function (key, value) {
133
+ if (key === '') {
134
+ return value;
135
+ }
136
+ const parent = this;
137
+ if (parent !== sanitizer.currentPath.value) {
138
+ sanitizer.exit(parent);
139
+ }
140
+ if (typeof value === 'object' && value !== null) {
141
+ sanitizer.enter(key, value);
142
+ return value;
143
+ }
144
+ sanitizer.currentPath.data[key] = value;
145
+ return value;
146
+ });
147
+ return this.copy;
148
+ }
149
+ enter(key, value) {
150
+ const { currentPath: parentPath } = this;
151
+ const data = (parentPath.data[key] = isArray(value) ? [] : {});
152
+ this.currentPath = {
153
+ key,
154
+ value,
155
+ parent: parentPath,
156
+ data,
157
+ };
158
+ }
159
+ exit(parent) {
160
+ while (this.currentPath.value !== parent) {
161
+ this.currentPath = this.currentPath.parent || this.currentPath;
162
+ }
163
+ }
173
164
  }
165
+ /**
166
+ * Returns a sanitized version of an object by recursively unwrapping the Proxies.
167
+ *
168
+ * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
169
+ * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
170
+ * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
171
+ * sanitized first.
172
+ */
173
+ function sanitize(obj) {
174
+ return new Sanitizer(obj).sanitize();
175
+ }
176
+
174
177
  class LWCLuvioWireAdapter {
175
178
  /**
176
179
  * Constructs a new wire adapter instance for the given adapter.
@@ -340,4 +343,17 @@ function createWireAdapterConstructor(adapter, name, luvio) {
340
343
  return constructor;
341
344
  }
342
345
 
343
- export { ADAPTER_UNFULFILLED_ERROR, REFRESH_ADAPTER_EVENT, bindWireRefresh, createWireAdapterConstructor, refreshData };
346
+ class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
347
+ }
348
+ function createInfiniteScrollingWireAdapterConstructor(adapter, name, luvio) {
349
+ const constructor = function (callback) {
350
+ const delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback);
351
+ this.connect = () => delegate.connect();
352
+ this.disconnect = () => delegate.disconnect();
353
+ this.update = (config, context) => delegate.update(config, context);
354
+ };
355
+ Object.defineProperty(constructor, 'name', { value: name });
356
+ return constructor;
357
+ }
358
+
359
+ export { ADAPTER_UNFULFILLED_ERROR, REFRESH_ADAPTER_EVENT, bindWireRefresh, createInfiniteScrollingWireAdapterConstructor, createWireAdapterConstructor, refreshData };
@@ -1,16 +1,5 @@
1
- import { Adapter, ErrorSnapshot, Luvio, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
- import { WireAdapterConstructor } from '@lwc/engine-core';
3
- declare const dataToTupleWeakMap: WeakMap<any, [string, ErrorSnapshot | FulfilledSnapshot<unknown, unknown> | UnfulfilledSnapshot<unknown, unknown> | StaleSnapshot<unknown, unknown> | import("@luvio/engine").PendingSnapshot<unknown, unknown> | undefined]>;
4
- export declare function bindWireRefresh(luvio: Luvio): <D>(data: D) => Promise<undefined> | undefined;
5
- export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
6
- export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
7
- export declare function refreshData<D>(data: D, dataToTuple: typeof dataToTupleWeakMap, luvio: Luvio): Promise<undefined> | undefined;
8
- /**
9
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
10
- *
11
- * @param adapter Adapter
12
- * @param name name to assign to the generated constructor
13
- * @param luvio Luvio
14
- */
15
- export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
16
- export {};
1
+ import { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR } from './utils/constants';
2
+ import { bindWireRefresh, refreshData } from './LWCLuvioBindings';
3
+ import { createWireAdapterConstructor } from './LWCLuvioWireAdapter';
4
+ import { createInfiniteScrollingWireAdapterConstructor } from './LWCInfiniteScrollingLuvioWireAdapter';
5
+ export { createWireAdapterConstructor, createInfiniteScrollingWireAdapterConstructor, bindWireRefresh, refreshData, REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR, };
@@ -0,0 +1,12 @@
1
+ import { ErrorSnapshot, Snapshot, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
+ export declare function isErrorSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is ErrorSnapshot;
3
+ export declare function isFulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is FulfilledSnapshot<unknown, unknown>;
4
+ export declare function isStaleSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is StaleSnapshot<unknown, unknown>;
5
+ export declare function isUnfulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is UnfulfilledSnapshot<unknown, unknown>;
6
+ export declare type EmittableSnapshot = FulfilledSnapshot<unknown> | StaleSnapshot<unknown> | ErrorSnapshot;
7
+ /**
8
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
9
+ *
10
+ * @param snapshot Snapshot
11
+ */
12
+ export declare function snapshotToPayload(snapshot?: EmittableSnapshot): any;
@@ -0,0 +1,4 @@
1
+ export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
2
+ export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
3
+ export declare const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
4
+ export declare const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = "Luvio wire adapter Promise<Snapshot> rejected. Original error:";
@@ -0,0 +1,2 @@
1
+ import { Snapshot } from '@luvio/engine';
2
+ export declare const dataToTupleWeakMap: WeakMap<any, [string, Snapshot<unknown, unknown> | undefined]>;
@@ -0,0 +1 @@
1
+ export declare function isPromise<U>(value: Promise<U> | U): value is Promise<U>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * (Re)throws an error after adding a prefix to the message.
3
+ *
4
+ * @param error Error
5
+ * @param messagePrefix prefix to add to error's message
6
+ */
7
+ export declare function throwAnnotatedError(error: unknown, messagePrefix: string): never;
@@ -0,0 +1,6 @@
1
+ import { Adapter, Luvio } from '@luvio/engine';
2
+ import { WireAdapterConstructor } from '@lwc/engine-core';
3
+ import { LWCLuvioWireAdapter } from './LWCLuvioWireAdapter';
4
+ export declare class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
5
+ }
6
+ export declare function createInfiniteScrollingWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -0,0 +1,4 @@
1
+ import { 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;
@@ -0,0 +1,62 @@
1
+ import { Adapter, Luvio, Unsubscribe } from '@luvio/engine';
2
+ import { WireConfigValue, WireContextValue, DataCallback, WireAdapter, WireAdapterConstructor } from '@lwc/engine-core';
3
+ export declare class LWCLuvioWireAdapter implements WireAdapter {
4
+ adapter: Adapter<unknown, unknown>;
5
+ name: string;
6
+ callback: DataCallback;
7
+ config?: unknown;
8
+ connected: boolean;
9
+ luvio: Luvio;
10
+ unsubscriber?: Unsubscribe;
11
+ /**
12
+ * Constructs a new wire adapter instance for the given adapter.
13
+ *
14
+ * @param callback callback to be invoked with new values
15
+ */
16
+ constructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio, callback: DataCallback);
17
+ /**
18
+ * Called when the component associated with the wire adapter is connected.
19
+ */
20
+ connect(): void;
21
+ /**
22
+ * Called when the component associated with the wire adapter is disconnected.
23
+ */
24
+ disconnect(): void;
25
+ /**
26
+ * Called when new or updated config is supplied to the wire adapter.
27
+ *
28
+ * @param config new config parameters for the wire adapter
29
+ * @param _context not used
30
+ */
31
+ update(config: WireConfigValue, _context?: WireContextValue): void;
32
+ /**
33
+ * Calls the adapter if config has been set and the component is connected.
34
+ */
35
+ private callAdapter;
36
+ /**
37
+ * Emits new values to the callback.
38
+ *
39
+ * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
40
+ */
41
+ private emit;
42
+ /**
43
+ * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
44
+ * to the snapshot will be automatically emitted to the component.
45
+ *
46
+ * @param snapshot Snapshot
47
+ * @param subscriptionCallback callback
48
+ */
49
+ private subscribe;
50
+ /**
51
+ * Deletes this wire adapter's snapshot subscription (if any).
52
+ */
53
+ private unsubscribe;
54
+ }
55
+ /**
56
+ * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
57
+ *
58
+ * @param adapter Adapter
59
+ * @param name name to assign to the generated constructor
60
+ * @param luvio Luvio
61
+ */
62
+ export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -1,73 +1,19 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lwc')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'lwc'], factory) :
4
- (global = global || self, factory(global.lwcLuvio = {}, global.LWC));
5
- }(this, (function (exports, lwc) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.lwcLuvio = {}, global.LWC));
5
+ })(this, (function (exports, lwc) { 'use strict';
6
6
 
7
- const { freeze, keys } = Object;
8
- const { isArray } = Array;
9
- const { stringify } = JSON;
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:';
10
12
 
11
- class Sanitizer {
12
- constructor(obj) {
13
- this.obj = obj;
14
- this.copy = {};
15
- this.currentPath = {
16
- key: '',
17
- value: obj,
18
- parent: null,
19
- data: this.copy,
20
- };
21
- }
22
- sanitize() {
23
- const sanitizer = this;
24
- stringify(this.obj, function (key, value) {
25
- if (key === '') {
26
- return value;
27
- }
28
- const parent = this;
29
- if (parent !== sanitizer.currentPath.value) {
30
- sanitizer.exit(parent);
31
- }
32
- if (typeof value === 'object' && value !== null) {
33
- sanitizer.enter(key, value);
34
- return value;
35
- }
36
- sanitizer.currentPath.data[key] = value;
37
- return value;
38
- });
39
- return this.copy;
40
- }
41
- enter(key, value) {
42
- const { currentPath: parentPath } = this;
43
- const data = (parentPath.data[key] = isArray(value) ? [] : {});
44
- this.currentPath = {
45
- key,
46
- value,
47
- parent: parentPath,
48
- data,
49
- };
50
- }
51
- exit(parent) {
52
- while (this.currentPath.value !== parent) {
53
- this.currentPath = this.currentPath.parent || this.currentPath;
54
- }
55
- }
56
- }
57
- /**
58
- * Returns a sanitized version of an object by recursively unwrapping the Proxies.
59
- *
60
- * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
61
- * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
62
- * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
63
- * sanitized first.
64
- */
65
- function sanitize(obj) {
66
- return new Sanitizer(obj).sanitize();
67
- }
13
+ // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
14
+ // initially-emitted { data: undefined, error: undefined } value
15
+ const dataToTupleWeakMap = new WeakMap();
68
16
 
69
- // Copied from engine to avoid build time dependency
70
- // BEGIN OF COPY BLOCK
71
17
  var SnapshotState;
72
18
  (function (SnapshotState) {
73
19
  SnapshotState["Fulfilled"] = "Fulfilled";
@@ -88,20 +34,36 @@
88
34
  function isUnfulfilledSnapshot(snapshot) {
89
35
  return snapshot.state === SnapshotState.Unfulfilled;
90
36
  }
91
- // END OF COPY BLOCK
92
- const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
93
- const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
94
- // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
95
- // initially-emitted { data: undefined, error: undefined } value
96
- const dataToTupleWeakMap = new WeakMap();
37
+ /**
38
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
39
+ *
40
+ * @param snapshot Snapshot
41
+ */
42
+ function snapshotToPayload(snapshot) {
43
+ if (snapshot === undefined) {
44
+ return {
45
+ data: undefined,
46
+ error: undefined,
47
+ };
48
+ }
49
+ if (isErrorSnapshot(snapshot)) {
50
+ return {
51
+ data: undefined,
52
+ error: snapshot.error,
53
+ };
54
+ }
55
+ // fulfilled or stale
56
+ return {
57
+ data: snapshot.data,
58
+ error: undefined,
59
+ };
60
+ }
61
+
97
62
  function bindWireRefresh(luvio) {
98
63
  return function refresh(data) {
99
64
  return refreshData(data, dataToTupleWeakMap, luvio);
100
65
  };
101
66
  }
102
- // instrumentation keys to be imported by ldsInstrumentation
103
- const REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
104
- const ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
105
67
  function refreshData(data, dataToTuple, luvio) {
106
68
  const tuple = dataToTuple.get(lwc.unwrap(data));
107
69
  if (tuple === undefined) {
@@ -133,35 +95,17 @@
133
95
  }
134
96
  return undefined;
135
97
  });
136
- }
98
+ }
99
+
100
+ const { freeze, keys } = Object;
101
+ const { isArray } = Array;
102
+ const { stringify } = JSON;
103
+
137
104
  function isPromise(value) {
138
105
  // check for Thenable due to test frameworks using custom Promise impls
139
106
  return value.then !== undefined;
140
- }
141
- /**
142
- * Transform a Snapshot into a payload suitable for passing to a DataCallback.
143
- *
144
- * @param snapshot Snapshot
145
- */
146
- function snapshotToPayload(snapshot) {
147
- if (snapshot === undefined) {
148
- return {
149
- data: undefined,
150
- error: undefined,
151
- };
152
- }
153
- if (isErrorSnapshot(snapshot)) {
154
- return {
155
- data: undefined,
156
- error: snapshot.error,
157
- };
158
- }
159
- // fulfilled or stale
160
- return {
161
- data: snapshot.data,
162
- error: undefined,
163
- };
164
- }
107
+ }
108
+
165
109
  /**
166
110
  * (Re)throws an error after adding a prefix to the message.
167
111
  *
@@ -174,7 +118,66 @@
174
118
  throw error;
175
119
  }
176
120
  throw new Error(`${messagePrefix}\n[${stringify(error)}]`);
121
+ }
122
+
123
+ class Sanitizer {
124
+ constructor(obj) {
125
+ this.obj = obj;
126
+ this.copy = {};
127
+ this.currentPath = {
128
+ key: '',
129
+ value: obj,
130
+ parent: null,
131
+ data: this.copy,
132
+ };
133
+ }
134
+ sanitize() {
135
+ const sanitizer = this;
136
+ stringify(this.obj, function (key, value) {
137
+ if (key === '') {
138
+ return value;
139
+ }
140
+ const parent = this;
141
+ if (parent !== sanitizer.currentPath.value) {
142
+ sanitizer.exit(parent);
143
+ }
144
+ if (typeof value === 'object' && value !== null) {
145
+ sanitizer.enter(key, value);
146
+ return value;
147
+ }
148
+ sanitizer.currentPath.data[key] = value;
149
+ return value;
150
+ });
151
+ return this.copy;
152
+ }
153
+ enter(key, value) {
154
+ const { currentPath: parentPath } = this;
155
+ const data = (parentPath.data[key] = isArray(value) ? [] : {});
156
+ this.currentPath = {
157
+ key,
158
+ value,
159
+ parent: parentPath,
160
+ data,
161
+ };
162
+ }
163
+ exit(parent) {
164
+ while (this.currentPath.value !== parent) {
165
+ this.currentPath = this.currentPath.parent || this.currentPath;
166
+ }
167
+ }
177
168
  }
169
+ /**
170
+ * Returns a sanitized version of an object by recursively unwrapping the Proxies.
171
+ *
172
+ * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
173
+ * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
174
+ * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
175
+ * sanitized first.
176
+ */
177
+ function sanitize(obj) {
178
+ return new Sanitizer(obj).sanitize();
179
+ }
180
+
178
181
  class LWCLuvioWireAdapter {
179
182
  /**
180
183
  * Constructs a new wire adapter instance for the given adapter.
@@ -344,12 +347,26 @@
344
347
  return constructor;
345
348
  }
346
349
 
350
+ class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
351
+ }
352
+ function createInfiniteScrollingWireAdapterConstructor(adapter, name, luvio) {
353
+ const constructor = function (callback) {
354
+ const delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback);
355
+ this.connect = () => delegate.connect();
356
+ this.disconnect = () => delegate.disconnect();
357
+ this.update = (config, context) => delegate.update(config, context);
358
+ };
359
+ Object.defineProperty(constructor, 'name', { value: name });
360
+ return constructor;
361
+ }
362
+
347
363
  exports.ADAPTER_UNFULFILLED_ERROR = ADAPTER_UNFULFILLED_ERROR;
348
364
  exports.REFRESH_ADAPTER_EVENT = REFRESH_ADAPTER_EVENT;
349
365
  exports.bindWireRefresh = bindWireRefresh;
366
+ exports.createInfiniteScrollingWireAdapterConstructor = createInfiniteScrollingWireAdapterConstructor;
350
367
  exports.createWireAdapterConstructor = createWireAdapterConstructor;
351
368
  exports.refreshData = refreshData;
352
369
 
353
370
  Object.defineProperty(exports, '__esModule', { value: true });
354
371
 
355
- })));
372
+ }));
@@ -1,16 +1,5 @@
1
- import { Adapter, ErrorSnapshot, Luvio, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
- import { WireAdapterConstructor } from '@lwc/engine-core';
3
- declare const dataToTupleWeakMap: WeakMap<any, [string, ErrorSnapshot | FulfilledSnapshot<unknown, unknown> | UnfulfilledSnapshot<unknown, unknown> | StaleSnapshot<unknown, unknown> | import("@luvio/engine").PendingSnapshot<unknown, unknown> | undefined]>;
4
- export declare function bindWireRefresh(luvio: Luvio): <D>(data: D) => Promise<undefined> | undefined;
5
- export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
6
- export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
7
- export declare function refreshData<D>(data: D, dataToTuple: typeof dataToTupleWeakMap, luvio: Luvio): Promise<undefined> | undefined;
8
- /**
9
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
10
- *
11
- * @param adapter Adapter
12
- * @param name name to assign to the generated constructor
13
- * @param luvio Luvio
14
- */
15
- export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
16
- export {};
1
+ import { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR } from './utils/constants';
2
+ import { bindWireRefresh, refreshData } from './LWCLuvioBindings';
3
+ import { createWireAdapterConstructor } from './LWCLuvioWireAdapter';
4
+ import { createInfiniteScrollingWireAdapterConstructor } from './LWCInfiniteScrollingLuvioWireAdapter';
5
+ export { createWireAdapterConstructor, createInfiniteScrollingWireAdapterConstructor, bindWireRefresh, refreshData, REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR, };
@@ -0,0 +1,12 @@
1
+ import { ErrorSnapshot, Snapshot, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
+ export declare function isErrorSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is ErrorSnapshot;
3
+ export declare function isFulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is FulfilledSnapshot<unknown, unknown>;
4
+ export declare function isStaleSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is StaleSnapshot<unknown, unknown>;
5
+ export declare function isUnfulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is UnfulfilledSnapshot<unknown, unknown>;
6
+ export declare type EmittableSnapshot = FulfilledSnapshot<unknown> | StaleSnapshot<unknown> | ErrorSnapshot;
7
+ /**
8
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
9
+ *
10
+ * @param snapshot Snapshot
11
+ */
12
+ export declare function snapshotToPayload(snapshot?: EmittableSnapshot): any;
@@ -0,0 +1,4 @@
1
+ export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
2
+ export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
3
+ export declare const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
4
+ export declare const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = "Luvio wire adapter Promise<Snapshot> rejected. Original error:";
@@ -0,0 +1,2 @@
1
+ import { Snapshot } from '@luvio/engine';
2
+ export declare const dataToTupleWeakMap: WeakMap<any, [string, Snapshot<unknown, unknown> | undefined]>;
@@ -0,0 +1 @@
1
+ export declare function isPromise<U>(value: Promise<U> | U): value is Promise<U>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * (Re)throws an error after adding a prefix to the message.
3
+ *
4
+ * @param error Error
5
+ * @param messagePrefix prefix to add to error's message
6
+ */
7
+ export declare function throwAnnotatedError(error: unknown, messagePrefix: string): never;
@@ -0,0 +1,6 @@
1
+ import { Adapter, Luvio } from '@luvio/engine';
2
+ import { WireAdapterConstructor } from '@lwc/engine-core';
3
+ import { LWCLuvioWireAdapter } from './LWCLuvioWireAdapter';
4
+ export declare class LWCInfinteScrollingLuvioWireAdapter extends LWCLuvioWireAdapter {
5
+ }
6
+ export declare function createInfiniteScrollingWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -0,0 +1,4 @@
1
+ import { 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;
@@ -0,0 +1,62 @@
1
+ import { Adapter, Luvio, Unsubscribe } from '@luvio/engine';
2
+ import { WireConfigValue, WireContextValue, DataCallback, WireAdapter, WireAdapterConstructor } from '@lwc/engine-core';
3
+ export declare class LWCLuvioWireAdapter implements WireAdapter {
4
+ adapter: Adapter<unknown, unknown>;
5
+ name: string;
6
+ callback: DataCallback;
7
+ config?: unknown;
8
+ connected: boolean;
9
+ luvio: Luvio;
10
+ unsubscriber?: Unsubscribe;
11
+ /**
12
+ * Constructs a new wire adapter instance for the given adapter.
13
+ *
14
+ * @param callback callback to be invoked with new values
15
+ */
16
+ constructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio, callback: DataCallback);
17
+ /**
18
+ * Called when the component associated with the wire adapter is connected.
19
+ */
20
+ connect(): void;
21
+ /**
22
+ * Called when the component associated with the wire adapter is disconnected.
23
+ */
24
+ disconnect(): void;
25
+ /**
26
+ * Called when new or updated config is supplied to the wire adapter.
27
+ *
28
+ * @param config new config parameters for the wire adapter
29
+ * @param _context not used
30
+ */
31
+ update(config: WireConfigValue, _context?: WireContextValue): void;
32
+ /**
33
+ * Calls the adapter if config has been set and the component is connected.
34
+ */
35
+ private callAdapter;
36
+ /**
37
+ * Emits new values to the callback.
38
+ *
39
+ * @param snapshot Snapshot to be emitted, if omitted then undefineds will be emitted
40
+ */
41
+ private emit;
42
+ /**
43
+ * Subscribes this wire adapter to future changes to the specified snapshot. Any changes
44
+ * to the snapshot will be automatically emitted to the component.
45
+ *
46
+ * @param snapshot Snapshot
47
+ * @param subscriptionCallback callback
48
+ */
49
+ private subscribe;
50
+ /**
51
+ * Deletes this wire adapter's snapshot subscription (if any).
52
+ */
53
+ private unsubscribe;
54
+ }
55
+ /**
56
+ * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
57
+ *
58
+ * @param adapter Adapter
59
+ * @param name name to assign to the generated constructor
60
+ * @param luvio Luvio
61
+ */
62
+ export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
@@ -1,74 +1,19 @@
1
1
  (function (global, factory) {
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('lwc')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'lwc'], factory) :
4
- (global = global || self, factory(global.lwcLuvio = {}, global.LWC));
5
- }(this, (function (exports, lwc) { 'use strict';
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.lwcLuvio = {}, global.LWC));
5
+ })(this, (function (exports, lwc) { 'use strict';
6
6
 
7
- var keys = Object.keys;
8
- var isArray = Array.isArray;
9
- var stringify = JSON.stringify;
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:';
10
12
 
11
- var Sanitizer = /** @class */ (function () {
12
- function Sanitizer(obj) {
13
- this.obj = obj;
14
- this.copy = {};
15
- this.currentPath = {
16
- key: '',
17
- value: obj,
18
- parent: null,
19
- data: this.copy,
20
- };
21
- }
22
- Sanitizer.prototype.sanitize = function () {
23
- var sanitizer = this;
24
- stringify(this.obj, function (key, value) {
25
- if (key === '') {
26
- return value;
27
- }
28
- var parent = this;
29
- if (parent !== sanitizer.currentPath.value) {
30
- sanitizer.exit(parent);
31
- }
32
- if (typeof value === 'object' && value !== null) {
33
- sanitizer.enter(key, value);
34
- return value;
35
- }
36
- sanitizer.currentPath.data[key] = value;
37
- return value;
38
- });
39
- return this.copy;
40
- };
41
- Sanitizer.prototype.enter = function (key, value) {
42
- var parentPath = this.currentPath;
43
- var data = (parentPath.data[key] = isArray(value) ? [] : {});
44
- this.currentPath = {
45
- key: key,
46
- value: value,
47
- parent: parentPath,
48
- data: data,
49
- };
50
- };
51
- Sanitizer.prototype.exit = function (parent) {
52
- while (this.currentPath.value !== parent) {
53
- this.currentPath = this.currentPath.parent || this.currentPath;
54
- }
55
- };
56
- return Sanitizer;
57
- }());
58
- /**
59
- * Returns a sanitized version of an object by recursively unwrapping the Proxies.
60
- *
61
- * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
62
- * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
63
- * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
64
- * sanitized first.
65
- */
66
- function sanitize(obj) {
67
- return new Sanitizer(obj).sanitize();
68
- }
13
+ // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
14
+ // initially-emitted { data: undefined, error: undefined } value
15
+ var dataToTupleWeakMap = new WeakMap();
69
16
 
70
- // Copied from engine to avoid build time dependency
71
- // BEGIN OF COPY BLOCK
72
17
  var SnapshotState;
73
18
  (function (SnapshotState) {
74
19
  SnapshotState["Fulfilled"] = "Fulfilled";
@@ -89,20 +34,36 @@
89
34
  function isUnfulfilledSnapshot(snapshot) {
90
35
  return snapshot.state === SnapshotState.Unfulfilled;
91
36
  }
92
- // END OF COPY BLOCK
93
- var USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
94
- var ADAPTER_SNAPSHOT_REJECTED_MESSAGE = 'Luvio wire adapter Promise<Snapshot> rejected. Original error:';
95
- // map of emitted object -> [ adapter name, snapshot ]; snapshot is only undefined for the
96
- // initially-emitted { data: undefined, error: undefined } value
97
- var dataToTupleWeakMap = new WeakMap();
37
+ /**
38
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
39
+ *
40
+ * @param snapshot Snapshot
41
+ */
42
+ function snapshotToPayload(snapshot) {
43
+ if (snapshot === undefined) {
44
+ return {
45
+ data: undefined,
46
+ error: undefined,
47
+ };
48
+ }
49
+ if (isErrorSnapshot(snapshot)) {
50
+ return {
51
+ data: undefined,
52
+ error: snapshot.error,
53
+ };
54
+ }
55
+ // fulfilled or stale
56
+ return {
57
+ data: snapshot.data,
58
+ error: undefined,
59
+ };
60
+ }
61
+
98
62
  function bindWireRefresh(luvio) {
99
63
  return function refresh(data) {
100
64
  return refreshData(data, dataToTupleWeakMap, luvio);
101
65
  };
102
66
  }
103
- // instrumentation keys to be imported by ldsInstrumentation
104
- var REFRESH_ADAPTER_EVENT = 'refresh-adapter-event';
105
- var ADAPTER_UNFULFILLED_ERROR = 'adapter-unfulfilled-error';
106
67
  function refreshData(data, dataToTuple, luvio) {
107
68
  var tuple = dataToTuple.get(lwc.unwrap(data));
108
69
  if (tuple === undefined) {
@@ -135,35 +96,17 @@
135
96
  }
136
97
  return undefined;
137
98
  });
138
- }
99
+ }
100
+
101
+ var keys = Object.keys;
102
+ var isArray = Array.isArray;
103
+ var stringify = JSON.stringify;
104
+
139
105
  function isPromise(value) {
140
106
  // check for Thenable due to test frameworks using custom Promise impls
141
107
  return value.then !== undefined;
142
- }
143
- /**
144
- * Transform a Snapshot into a payload suitable for passing to a DataCallback.
145
- *
146
- * @param snapshot Snapshot
147
- */
148
- function snapshotToPayload(snapshot) {
149
- if (snapshot === undefined) {
150
- return {
151
- data: undefined,
152
- error: undefined,
153
- };
154
- }
155
- if (isErrorSnapshot(snapshot)) {
156
- return {
157
- data: undefined,
158
- error: snapshot.error,
159
- };
160
- }
161
- // fulfilled or stale
162
- return {
163
- data: snapshot.data,
164
- error: undefined,
165
- };
166
- }
108
+ }
109
+
167
110
  /**
168
111
  * (Re)throws an error after adding a prefix to the message.
169
112
  *
@@ -172,11 +115,71 @@
172
115
  */
173
116
  function throwAnnotatedError(error, messagePrefix) {
174
117
  if (error instanceof Error) {
175
- error.message = messagePrefix + "\n[" + error.message + "]";
118
+ error.message = "".concat(messagePrefix, "\n[").concat(error.message, "]");
176
119
  throw error;
177
120
  }
178
- throw new Error(messagePrefix + "\n[" + stringify(error) + "]");
179
- }
121
+ throw new Error("".concat(messagePrefix, "\n[").concat(stringify(error), "]"));
122
+ }
123
+
124
+ var Sanitizer = /** @class */ (function () {
125
+ function Sanitizer(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
+ Sanitizer.prototype.sanitize = function () {
136
+ var sanitizer = this;
137
+ stringify(this.obj, function (key, value) {
138
+ if (key === '') {
139
+ return value;
140
+ }
141
+ var 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
+ Sanitizer.prototype.enter = function (key, value) {
155
+ var parentPath = this.currentPath;
156
+ var data = (parentPath.data[key] = isArray(value) ? [] : {});
157
+ this.currentPath = {
158
+ key: key,
159
+ value: value,
160
+ parent: parentPath,
161
+ data: data,
162
+ };
163
+ };
164
+ Sanitizer.prototype.exit = function (parent) {
165
+ while (this.currentPath.value !== parent) {
166
+ this.currentPath = this.currentPath.parent || this.currentPath;
167
+ }
168
+ };
169
+ return Sanitizer;
170
+ }());
171
+ /**
172
+ * Returns a sanitized version of an object by recursively unwrapping the Proxies.
173
+ *
174
+ * In order to keep luvio performance optimal on IE11, we need to make sure that luvio code gets
175
+ * transformed by the es5-proxy-compat. At the same time we need to ensure that no ProxyCompat leaks
176
+ * into the luvio engine code nor into the adapters. All the data coming from LWC-land need to be
177
+ * sanitized first.
178
+ */
179
+ function sanitize(obj) {
180
+ return new Sanitizer(obj).sanitize();
181
+ }
182
+
180
183
  var LWCLuvioWireAdapter = /** @class */ (function () {
181
184
  /**
182
185
  * Constructs a new wire adapter instance for the given adapter.
@@ -246,7 +249,7 @@
246
249
  // We should never broadcast an unfulfilled snapshot to a component
247
250
  if (isUnfulfilledSnapshot(snapshot)) {
248
251
  if (process.env.NODE_ENV !== 'production') {
249
- throw new Error("Unfulfilled snapshot emitted to component from subscription, missingPaths: " + keys(snapshot.missingPaths));
252
+ throw new Error("Unfulfilled snapshot emitted to component from subscription, missingPaths: ".concat(keys(snapshot.missingPaths)));
250
253
  }
251
254
  // Instrument as a failed request
252
255
  _this.luvio.instrument(function () {
@@ -353,12 +356,64 @@
353
356
  return constructor;
354
357
  }
355
358
 
359
+ /*! *****************************************************************************
360
+ Copyright (c) Microsoft Corporation.
361
+
362
+ Permission to use, copy, modify, and/or distribute this software for any
363
+ purpose with or without fee is hereby granted.
364
+
365
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
366
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
367
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
368
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
369
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
370
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
371
+ PERFORMANCE OF THIS SOFTWARE.
372
+ ***************************************************************************** */
373
+ /* global Reflect, Promise */
374
+
375
+ var extendStatics = function(d, b) {
376
+ extendStatics = Object.setPrototypeOf ||
377
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
378
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
379
+ return extendStatics(d, b);
380
+ };
381
+
382
+ function __extends(d, b) {
383
+ if (typeof b !== "function" && b !== null)
384
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
385
+ extendStatics(d, b);
386
+ function __() { this.constructor = d; }
387
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
388
+ }
389
+
390
+ var LWCInfinteScrollingLuvioWireAdapter = /** @class */ (function (_super) {
391
+ __extends(LWCInfinteScrollingLuvioWireAdapter, _super);
392
+ function LWCInfinteScrollingLuvioWireAdapter() {
393
+ return _super !== null && _super.apply(this, arguments) || this;
394
+ }
395
+ return LWCInfinteScrollingLuvioWireAdapter;
396
+ }(LWCLuvioWireAdapter));
397
+ function createInfiniteScrollingWireAdapterConstructor(adapter, name, luvio) {
398
+ var constructor = function (callback) {
399
+ var delegate = new LWCInfinteScrollingLuvioWireAdapter(adapter, name, luvio, callback);
400
+ this.connect = function () { return delegate.connect(); };
401
+ this.disconnect = function () { return delegate.disconnect(); };
402
+ this.update = function (config, context) {
403
+ return delegate.update(config, context);
404
+ };
405
+ };
406
+ Object.defineProperty(constructor, 'name', { value: name });
407
+ return constructor;
408
+ }
409
+
356
410
  exports.ADAPTER_UNFULFILLED_ERROR = ADAPTER_UNFULFILLED_ERROR;
357
411
  exports.REFRESH_ADAPTER_EVENT = REFRESH_ADAPTER_EVENT;
358
412
  exports.bindWireRefresh = bindWireRefresh;
413
+ exports.createInfiniteScrollingWireAdapterConstructor = createInfiniteScrollingWireAdapterConstructor;
359
414
  exports.createWireAdapterConstructor = createWireAdapterConstructor;
360
415
  exports.refreshData = refreshData;
361
416
 
362
417
  Object.defineProperty(exports, '__esModule', { value: true });
363
418
 
364
- })));
419
+ }));
@@ -1,16 +1,5 @@
1
- import { Adapter, ErrorSnapshot, Luvio, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
- import { WireAdapterConstructor } from '@lwc/engine-core';
3
- declare const dataToTupleWeakMap: WeakMap<any, [string, ErrorSnapshot | FulfilledSnapshot<unknown, unknown> | UnfulfilledSnapshot<unknown, unknown> | StaleSnapshot<unknown, unknown> | import("@luvio/engine").PendingSnapshot<unknown, unknown> | undefined]>;
4
- export declare function bindWireRefresh(luvio: Luvio): <D>(data: D) => Promise<undefined> | undefined;
5
- export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
6
- export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
7
- export declare function refreshData<D>(data: D, dataToTuple: typeof dataToTupleWeakMap, luvio: Luvio): Promise<undefined> | undefined;
8
- /**
9
- * Wraps a luvio Adapter in a WireAdapterConstructor that conforms to https://rfcs.lwc.dev/rfcs/lwc/0000-wire-reform#wire-adapter-protocol.
10
- *
11
- * @param adapter Adapter
12
- * @param name name to assign to the generated constructor
13
- * @param luvio Luvio
14
- */
15
- export declare function createWireAdapterConstructor(adapter: Adapter<unknown, unknown>, name: string, luvio: Luvio): WireAdapterConstructor;
16
- export {};
1
+ import { REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR } from './utils/constants';
2
+ import { bindWireRefresh, refreshData } from './LWCLuvioBindings';
3
+ import { createWireAdapterConstructor } from './LWCLuvioWireAdapter';
4
+ import { createInfiniteScrollingWireAdapterConstructor } from './LWCInfiniteScrollingLuvioWireAdapter';
5
+ export { createWireAdapterConstructor, createInfiniteScrollingWireAdapterConstructor, bindWireRefresh, refreshData, REFRESH_ADAPTER_EVENT, ADAPTER_UNFULFILLED_ERROR, };
@@ -0,0 +1,12 @@
1
+ import { ErrorSnapshot, Snapshot, StaleSnapshot, FulfilledSnapshot, UnfulfilledSnapshot } from '@luvio/engine';
2
+ export declare function isErrorSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is ErrorSnapshot;
3
+ export declare function isFulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is FulfilledSnapshot<unknown, unknown>;
4
+ export declare function isStaleSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is StaleSnapshot<unknown, unknown>;
5
+ export declare function isUnfulfilledSnapshot(snapshot: Snapshot<unknown, unknown>): snapshot is UnfulfilledSnapshot<unknown, unknown>;
6
+ export declare type EmittableSnapshot = FulfilledSnapshot<unknown> | StaleSnapshot<unknown> | ErrorSnapshot;
7
+ /**
8
+ * Transform a Snapshot into a payload suitable for passing to a DataCallback.
9
+ *
10
+ * @param snapshot Snapshot
11
+ */
12
+ export declare function snapshotToPayload(snapshot?: EmittableSnapshot): any;
@@ -0,0 +1,4 @@
1
+ export declare const REFRESH_ADAPTER_EVENT = "refresh-adapter-event";
2
+ export declare const ADAPTER_UNFULFILLED_ERROR = "adapter-unfulfilled-error";
3
+ export declare const USERLAND_PROVISION_ERROR_MESSAGE = "LWC component's @wire target property or method threw an error during value provisioning. Original error:";
4
+ export declare const ADAPTER_SNAPSHOT_REJECTED_MESSAGE = "Luvio wire adapter Promise<Snapshot> rejected. Original error:";
@@ -0,0 +1,2 @@
1
+ import { Snapshot } from '@luvio/engine';
2
+ export declare const dataToTupleWeakMap: WeakMap<any, [string, Snapshot<unknown, unknown> | undefined]>;
@@ -0,0 +1 @@
1
+ export declare function isPromise<U>(value: Promise<U> | U): value is Promise<U>;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * (Re)throws an error after adding a prefix to the message.
3
+ *
4
+ * @param error Error
5
+ * @param messagePrefix prefix to add to error's message
6
+ */
7
+ export declare function throwAnnotatedError(error: unknown, messagePrefix: string): never;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luvio/lwc-luvio",
3
- "version": "0.62.3",
3
+ "version": "0.63.2",
4
4
  "description": "Lightning Web Component bindings for Luvio",
5
5
  "main": "dist/umd/es2018/lwcluvio.js",
6
6
  "module": "dist/es/es2018/lwcluvio.js",
@@ -18,12 +18,12 @@
18
18
  "dist/"
19
19
  ],
20
20
  "devDependencies": {
21
- "@luvio/adapter-test-library": "0.62.3",
22
- "@luvio/cli": "0.62.3",
21
+ "@luvio/adapter-test-library": "0.63.2",
22
+ "@luvio/cli": "0.63.2",
23
23
  "@lwc/jest-preset": "11.2.2"
24
24
  },
25
25
  "dependencies": {
26
- "@luvio/engine": "0.62.3",
26
+ "@luvio/engine": "0.63.2",
27
27
  "@lwc/engine-core": "^2.5.10"
28
28
  }
29
29
  }