@conduit-client/lwc-bindings 5.67.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,27 @@
1
+ *Attorney/Client Privileged + Confidential*
2
+
3
+ Terms of Use for Public Code (Non-OSS)
4
+
5
+ *NOTE:* Before publishing code under this license/these Terms of Use, please review https://salesforce.quip.com/WFfvAMKB18AL and confirm that you’ve completed all prerequisites described therein. *These Terms of Use may not be used or modified without input from IP and Product Legal.*
6
+
7
+ *Terms of Use*
8
+
9
+ Copyright 2022 Salesforce, Inc. All rights reserved.
10
+
11
+ These Terms of Use govern the download, installation, and/or use of this software provided by Salesforce, Inc. (“Salesforce”) (the “Software”), were last updated on April 15, 2022, ** and constitute a legally binding agreement between you and Salesforce. If you do not agree to these Terms of Use, do not install or use the Software.
12
+
13
+ Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute the Software and derivative works subject to these Terms. These Terms shall be included in all copies or substantial portions of the Software.
14
+
15
+ Subject to the limited rights expressly granted hereunder, Salesforce reserves all rights, title, and interest in and to all intellectual property subsisting in the Software. No rights are granted to you hereunder other than as expressly set forth herein. Users residing in countries on the United States Office of Foreign Assets Control sanction list, or which are otherwise subject to a US export embargo, may not use the Software.
16
+
17
+ Implementation of the Software may require development work, for which you are responsible. The Software may contain bugs, errors and incompatibilities and is made available on an AS IS basis without support, updates, or service level commitments.
18
+
19
+ Salesforce reserves the right at any time to modify, suspend, or discontinue, the Software (or any part thereof) with or without notice. You agree that Salesforce shall not be liable to you or to any third party for any modification, suspension, or discontinuance.
20
+
21
+ You agree to defend Salesforce against any claim, demand, suit or proceeding made or brought against Salesforce by a third party arising out of or accruing from (a) your use of the Software, and (b) any application you develop with the Software that infringes any copyright, trademark, trade secret, trade dress, patent, or other intellectual property right of any person or defames any person or violates their rights of publicity or privacy (each a “Claim Against Salesforce”), and will indemnify Salesforce from any damages, attorney fees, and costs finally awarded against Salesforce as a result of, or for any amounts paid by Salesforce under a settlement approved by you in writing of, a Claim Against Salesforce, provided Salesforce (x) promptly gives you written notice of the Claim Against Salesforce, (y) gives you sole control of the defense and settlement of the Claim Against Salesforce (except that you may not settle any Claim Against Salesforce unless it unconditionally releases Salesforce of all liability), and (z) gives you all reasonable assistance, at your expense.
22
+
23
+ WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA, OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
24
+
25
+ These Terms of Use shall be governed exclusively by the internal laws of the State of California, without regard to its conflicts of laws rules. Each party hereby consents to the exclusive jurisdiction of the state and federal courts located in San Francisco County, California to adjudicate any dispute arising out of or relating to these Terms of Use and the download, installation, and/or use of the Software. Except as expressly stated herein, these Terms of Use constitute the entire agreement between the parties, and supersede all prior and contemporaneous agreements, proposals, or representations, written or oral, concerning their subject matter. No modification, amendment, or waiver of any provision of these Terms of Use shall be effective unless it is by an update to these Terms of Use that Salesforce makes available, or is in writing and signed by the party against whom the modification, amendment, or waiver is to be asserted.
26
+
27
+ _*Data Privacy*_: Salesforce may collect, process, and store device, system, and other information related to your use of the Software. This information includes, but is not limited to, IP address, user metrics, and other data (“Usage Data”). Salesforce may use Usage Data for analytics, product development, and marketing purposes. You acknowledge that files generated in conjunction with the Software may contain sensitive or confidential data, and you are solely responsible for anonymizing and protecting such data.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ This software is provided as-is with no support provided.
package/dist/index.js ADDED
@@ -0,0 +1,719 @@
1
+ /*!
2
+ * Copyright (c) 2022, Salesforce, Inc.,
3
+ * All rights reserved.
4
+ * For full license text, see the LICENSE.txt file
5
+ */
6
+ import { isSubscribableResult, deepFreeze, ok, toError } from "@conduit-client/utils";
7
+ import { assertIsValid, MissingRequiredPropertyError, JsonSchemaViolationError } from "@conduit-client/jsonschema-validate";
8
+ import { astResolver, Kind } from "@conduit-client/onestore-graphql-parser/v1";
9
+ class Sanitizer {
10
+ constructor(obj) {
11
+ this.obj = obj;
12
+ this.copy = {};
13
+ this.currentPath = {
14
+ key: "",
15
+ value: obj,
16
+ parent: null,
17
+ data: this.copy
18
+ };
19
+ }
20
+ sanitize() {
21
+ const sanitizer = this;
22
+ JSON.stringify(this.obj, function(key, value) {
23
+ if (key === "") {
24
+ return value;
25
+ }
26
+ const parent = this;
27
+ if (parent !== sanitizer.currentPath.value) {
28
+ sanitizer.exit(parent);
29
+ }
30
+ if (typeof value === "object" && value !== null) {
31
+ sanitizer.enter(key, value);
32
+ return value;
33
+ }
34
+ sanitizer.currentPath.data[key] = value;
35
+ return value;
36
+ });
37
+ return this.copy;
38
+ }
39
+ enter(key, value) {
40
+ const { currentPath: parentPath } = this;
41
+ const data = parentPath.data[key] = Array.isArray(value) ? [] : {};
42
+ this.currentPath = {
43
+ key,
44
+ value,
45
+ parent: parentPath,
46
+ data
47
+ };
48
+ }
49
+ exit(parent) {
50
+ while (this.currentPath.value !== parent) {
51
+ this.currentPath = this.currentPath.parent || this.currentPath;
52
+ }
53
+ }
54
+ }
55
+ function sanitize(obj) {
56
+ return new Sanitizer(obj).sanitize();
57
+ }
58
+ function isUserVisibleError(error) {
59
+ return error instanceof Error && "type" in error && error.type === "user-visible";
60
+ }
61
+ function throwUserlandError(error) {
62
+ logError(error);
63
+ throw buildUserlandError(error);
64
+ }
65
+ function emitError(callback, error) {
66
+ logError(error);
67
+ callback({ data: void 0, error: buildUserlandError(error) });
68
+ }
69
+ function buildUserlandError(error) {
70
+ if (isUserVisibleError(error)) {
71
+ return error.data;
72
+ }
73
+ return new Error("Internal error in Lightning Data Service adapter occurred.");
74
+ }
75
+ function logError(error) {
76
+ if (isUserVisibleError(error)) {
77
+ return;
78
+ }
79
+ console.error("OneStore Command threw an error that we did not expect", error);
80
+ }
81
+ const supportedCachePolicyTypes = ["no-cache", "only-if-cached"];
82
+ function requestContextIsSupportedCachePolicy(requestContext) {
83
+ return typeof requestContext === "object" && requestContext !== null && "cachePolicy" in requestContext && typeof requestContext.cachePolicy === "object" && requestContext.cachePolicy !== null && "type" in requestContext.cachePolicy && typeof requestContext.cachePolicy.type === "string" && supportedCachePolicyTypes.includes(
84
+ requestContext.cachePolicy.type
85
+ );
86
+ }
87
+ function getOverridesForLegacyRequestContext(requestContext) {
88
+ if (requestContextIsSupportedCachePolicy(requestContext)) {
89
+ return { cacheControlConfig: { type: requestContext.cachePolicy.type } };
90
+ }
91
+ return {};
92
+ }
93
+ class CommandWireAdapterConstructor {
94
+ constructor(callback, sourceContext, options) {
95
+ this.callback = callback;
96
+ this.connected = false;
97
+ this.exposeRefresh = false;
98
+ if (!(options == null ? void 0 : options.skipEmptyEmit)) {
99
+ this.emit();
100
+ }
101
+ }
102
+ connect() {
103
+ this.connected = true;
104
+ this.invokeAdapter();
105
+ }
106
+ disconnect() {
107
+ this.unsubscribe();
108
+ this.connected = false;
109
+ }
110
+ update(config, _context) {
111
+ this.unsubscribe();
112
+ this.config = sanitize(config);
113
+ this.invokeAdapter();
114
+ }
115
+ emit(result) {
116
+ try {
117
+ if (result === void 0) {
118
+ this.callback({ data: void 0, error: void 0 });
119
+ } else {
120
+ const consumerEmittedRefresh = () => {
121
+ if (!this.refresh) {
122
+ return Promise.resolve();
123
+ }
124
+ return new Promise((resolve, reject) => {
125
+ if (!this.refresh) {
126
+ resolve();
127
+ return;
128
+ }
129
+ this.refresh().then((res) => {
130
+ if (res.isOk()) {
131
+ resolve();
132
+ } else {
133
+ reject(
134
+ new Error(
135
+ "Internal error in Lightning Data Service adapter occurred: Failed to refresh data"
136
+ )
137
+ );
138
+ }
139
+ });
140
+ });
141
+ };
142
+ let consumerEmittedData = {
143
+ data: void 0,
144
+ error: void 0
145
+ };
146
+ if (this.exposeRefresh && this.refresh) {
147
+ consumerEmittedData.refresh = consumerEmittedRefresh;
148
+ }
149
+ if (result.isErr()) {
150
+ if (isSubscribableResult(result)) {
151
+ consumerEmittedData.error = result.error.failure;
152
+ } else {
153
+ consumerEmittedData.error = result.error;
154
+ }
155
+ } else {
156
+ if (isSubscribableResult(result)) {
157
+ deepFreeze(result.value.data);
158
+ consumerEmittedData.data = result.value.data;
159
+ } else {
160
+ deepFreeze(result.value);
161
+ consumerEmittedData.data = result.value;
162
+ }
163
+ }
164
+ this.callback(consumerEmittedData);
165
+ }
166
+ } catch (e) {
167
+ this.handleExecutionThrow(e);
168
+ }
169
+ }
170
+ invokeAdapter() {
171
+ if (!this.connected || this.config === void 0) {
172
+ return;
173
+ }
174
+ if (this.configSchema) {
175
+ try {
176
+ assertIsValid(this.config, this.configSchema);
177
+ } catch (err2) {
178
+ if (isIncompleteConfigError(err2)) {
179
+ return;
180
+ }
181
+ throw err2;
182
+ }
183
+ }
184
+ const initialConfig = this.config;
185
+ const command = this.getCommand();
186
+ try {
187
+ command.execute().then((result) => {
188
+ if (!this.connected || this.config !== initialConfig) {
189
+ return;
190
+ }
191
+ this.refresh = void 0;
192
+ if (result.isOk()) {
193
+ if (isSubscribableResult(result)) {
194
+ const value = result.value;
195
+ this.unsubscriber = value.subscribe((updatedResult) => {
196
+ if (!this.connected || this.config !== initialConfig) {
197
+ this.unsubscribe();
198
+ return;
199
+ }
200
+ this.emit(updatedResult);
201
+ });
202
+ this.refresh = value.refresh;
203
+ this.emit(ok(value.data));
204
+ } else {
205
+ this.emit(result);
206
+ }
207
+ } else {
208
+ if (isSubscribableResult(result)) {
209
+ const value = result.error;
210
+ this.unsubscriber = value.subscribe((updatedResult) => {
211
+ if (!this.connected || this.config !== initialConfig) {
212
+ this.unsubscribe();
213
+ return;
214
+ }
215
+ this.emit(updatedResult);
216
+ });
217
+ this.refresh = value.refresh;
218
+ this.emit(result);
219
+ } else {
220
+ this.unsubscriber = () => {
221
+ };
222
+ this.emit(result);
223
+ }
224
+ }
225
+ });
226
+ } catch (e) {
227
+ this.handleExecutionThrow(e);
228
+ }
229
+ }
230
+ handleExecutionThrow(error) {
231
+ emitError(this.callback, error);
232
+ }
233
+ unsubscribe() {
234
+ if (this.unsubscriber) {
235
+ this.unsubscriber();
236
+ delete this.unsubscriber;
237
+ }
238
+ }
239
+ }
240
+ function isIncompleteConfigError(err2) {
241
+ return err2 instanceof MissingRequiredPropertyError || err2 instanceof JsonSchemaViolationError && err2.validationErrors.find(
242
+ (validationError) => validationError instanceof MissingRequiredPropertyError
243
+ ) !== void 0;
244
+ }
245
+ function buildAsyncImperativeInvoker(getCommand) {
246
+ return async (...params) => {
247
+ const command = getCommand({ params, assertIsValid });
248
+ try {
249
+ return command.execute().then(
250
+ (result) => {
251
+ if (result.isOk()) {
252
+ deepFreeze(result.value);
253
+ return isSubscribableResult(result) ? result.value.data : result.value;
254
+ }
255
+ throw toError(
256
+ isSubscribableResult(result) ? result.error.failure : result.error
257
+ );
258
+ },
259
+ (e) => {
260
+ throwUserlandError(e);
261
+ }
262
+ );
263
+ } catch (e) {
264
+ throwUserlandError(e);
265
+ }
266
+ };
267
+ }
268
+ function buildAsyncQueryImperativeInvoker(getCommand) {
269
+ const baseInvoker = buildAsyncImperativeInvoker(getCommand);
270
+ return async (...params) => ({ data: await baseInvoker(...params) });
271
+ }
272
+ function buildAsyncImperativeSubscribableInvoker(getCommand, exposeRefresh = false) {
273
+ return async (...params) => {
274
+ const command = getCommand({ params, assertIsValid });
275
+ let result;
276
+ try {
277
+ result = await command.execute();
278
+ } catch (e) {
279
+ throwUserlandError(e);
280
+ }
281
+ if (!isSubscribableResult(result)) {
282
+ console.error(
283
+ "Non-subscribable result encountered - please use correct operation type"
284
+ );
285
+ throw new Error("Internal error in Lightning Data Service adapter occurred");
286
+ }
287
+ if (result.isOk()) {
288
+ deepFreeze(result.value.data);
289
+ const api = {
290
+ data: result.value.data,
291
+ subscribe: (cb) => {
292
+ result.value.subscribe((result2) => {
293
+ if (result2.isErr()) {
294
+ return cb({ data: void 0, error: toError(result2.error) });
295
+ }
296
+ return cb({ data: result2.value, error: void 0 });
297
+ });
298
+ }
299
+ };
300
+ if (exposeRefresh) {
301
+ return {
302
+ ...api,
303
+ refresh: () => {
304
+ return result.value.refresh().then((res) => {
305
+ if (res.isOk()) {
306
+ return void 0;
307
+ }
308
+ throw res.error;
309
+ });
310
+ }
311
+ };
312
+ } else {
313
+ return api;
314
+ }
315
+ } else {
316
+ throw toError(result.error.failure);
317
+ }
318
+ };
319
+ }
320
+ function buildAsyncImperativeLegacyInvoker(getCommand) {
321
+ const invoke = async (config, requestContext, callback) => {
322
+ const command = getCommand({ config, assertIsValid });
323
+ try {
324
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
325
+ const result = await command.execute(overrides);
326
+ if (result.isOk()) {
327
+ deepFreeze(result.value);
328
+ callback({ data: result.value.data, error: void 0 });
329
+ } else {
330
+ callback({ data: void 0, error: toError(result.error.failure) });
331
+ }
332
+ } catch (error) {
333
+ emitError(callback, error);
334
+ }
335
+ };
336
+ const subscribe = (config, requestContext, callback) => {
337
+ const command = getCommand({ config, assertIsValid });
338
+ let unsubscribe = () => {
339
+ };
340
+ try {
341
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
342
+ command.execute(overrides).then(
343
+ (result) => {
344
+ if (!result.isOk()) {
345
+ callback({ data: void 0, error: toError(result.error.failure) });
346
+ return;
347
+ }
348
+ unsubscribe = result.value.subscribe((res) => {
349
+ if (res.isOk()) {
350
+ callback({ data: res.value, error: void 0 });
351
+ } else {
352
+ callback({ data: void 0, error: toError(res.error) });
353
+ }
354
+ });
355
+ callback({ data: result.value.data, error: void 0 });
356
+ },
357
+ (e) => {
358
+ emitError(callback, e);
359
+ }
360
+ );
361
+ } catch (e) {
362
+ emitError(callback, e);
363
+ }
364
+ return () => {
365
+ unsubscribe();
366
+ };
367
+ };
368
+ return { invoke, subscribe };
369
+ }
370
+ class GraphQLCommandErrorWithData extends Error {
371
+ constructor(data) {
372
+ super();
373
+ this.data = data;
374
+ }
375
+ }
376
+ function throwGraphQLError(error) {
377
+ logError(error);
378
+ if (isUserVisibleError(error)) {
379
+ throw new GraphQLCommandErrorWithData(error.data);
380
+ }
381
+ throw new Error("Internal error in GraphQL adapter occurred");
382
+ }
383
+ function findExecutableOperation(document, operationName) {
384
+ const operations = document.definitions.filter(
385
+ (def) => def.kind === Kind.OPERATION_DEFINITION
386
+ );
387
+ if (operations.length === 0) {
388
+ return void 0;
389
+ }
390
+ if (operations.length === 1 && !operationName) {
391
+ return operations[0];
392
+ }
393
+ if (operationName) {
394
+ return operations.find((op) => {
395
+ var _a;
396
+ return ((_a = op.name) == null ? void 0 : _a.value) === operationName;
397
+ });
398
+ }
399
+ return void 0;
400
+ }
401
+ function validateGraphQLOperations(config, options) {
402
+ const executableOperation = findExecutableOperation(config.query, config.operationName);
403
+ if (executableOperation) {
404
+ const operationType = executableOperation.operation;
405
+ if (!options.acceptedOperations.includes(operationType)) {
406
+ const operationTypeCapitalized = operationType.charAt(0).toUpperCase() + operationType.slice(1);
407
+ throw new Error(
408
+ `${operationTypeCapitalized} operations are not supported in this context`
409
+ );
410
+ }
411
+ }
412
+ }
413
+ function resolveAst(ast) {
414
+ if (ast === null || ast === void 0) {
415
+ return;
416
+ }
417
+ const result = astResolver(ast);
418
+ if (result === void 0) {
419
+ throw new Error("Could not resolve AST. Did you parse the query with gql?");
420
+ }
421
+ return result;
422
+ }
423
+ function wrapConfigAndVerify(config, options) {
424
+ if (config == null ? void 0 : config.query) {
425
+ config = { ...config, query: resolveAst(config.query) };
426
+ if (config.query === void 0) {
427
+ throw new Error("Internal error in GraphQL adapter occurred: Unable to resolve query");
428
+ }
429
+ validateGraphQLOperations(config, {
430
+ acceptedOperations: (options == null ? void 0 : options.acceptedOperations) ?? ["query"]
431
+ });
432
+ }
433
+ return config;
434
+ }
435
+ function toGraphQLResponseFromFailure(failure) {
436
+ if (isUserVisibleError(failure)) {
437
+ return {
438
+ data: failure.data.data,
439
+ errors: failure.data.errors
440
+ };
441
+ }
442
+ logError(failure);
443
+ return {
444
+ data: void 0,
445
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
446
+ };
447
+ }
448
+ class GraphQLCommandWireAdapterConstructor extends CommandWireAdapterConstructor {
449
+ emit(result) {
450
+ try {
451
+ if (result === void 0) {
452
+ this.callback({ data: void 0, errors: void 0 });
453
+ } else {
454
+ const consumerEmittedRefresh = () => {
455
+ if (!this.refresh) {
456
+ return Promise.resolve();
457
+ }
458
+ return new Promise((resolve, reject) => {
459
+ if (!this.refresh) {
460
+ resolve();
461
+ return;
462
+ }
463
+ this.refresh().then((res) => {
464
+ if (res.isOk()) {
465
+ resolve();
466
+ } else {
467
+ reject(
468
+ new Error(
469
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
470
+ )
471
+ );
472
+ }
473
+ });
474
+ });
475
+ };
476
+ let consumerEmittedData = {
477
+ data: void 0,
478
+ errors: void 0
479
+ };
480
+ if (this.exposeRefresh && this.refresh) {
481
+ consumerEmittedData.refresh = consumerEmittedRefresh;
482
+ }
483
+ if (result.isErr()) {
484
+ const failure = isSubscribableResult(result) ? result.error.failure : result.error;
485
+ const resp = toGraphQLResponseFromFailure(failure);
486
+ consumerEmittedData.data = resp.data;
487
+ consumerEmittedData.errors = resp.errors;
488
+ } else {
489
+ consumerEmittedData.data = result.value.data;
490
+ }
491
+ deepFreeze(consumerEmittedData);
492
+ this.callback(consumerEmittedData);
493
+ }
494
+ } catch (e) {
495
+ logError(e);
496
+ this.handleExecutionThrow(e);
497
+ }
498
+ }
499
+ handleExecutionThrow(e) {
500
+ logError(e);
501
+ this.callback({
502
+ data: void 0,
503
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
504
+ });
505
+ }
506
+ update(config, _context) {
507
+ this.unsubscribe();
508
+ const resolvedQuery = resolveAst(config.query);
509
+ if (resolvedQuery) {
510
+ validateGraphQLOperations(
511
+ { query: resolvedQuery, operationName: config == null ? void 0 : config.operationName },
512
+ { acceptedOperations: ["query"] }
513
+ );
514
+ }
515
+ this.config = {
516
+ ...sanitize(config),
517
+ query: resolvedQuery
518
+ };
519
+ this.invokeAdapter();
520
+ }
521
+ }
522
+ function buildAsyncGraphQLImperativeInvoker(getCommand, exposeRefresh = false) {
523
+ return async (...params) => {
524
+ try {
525
+ if (params.length) {
526
+ params[0] = wrapConfigAndVerify(params[0]);
527
+ }
528
+ const command = getCommand({ params, assertIsValid });
529
+ const result = await command.execute();
530
+ const consumerEmittedData = {
531
+ data: void 0,
532
+ errors: void 0
533
+ };
534
+ if (result.isOk()) {
535
+ deepFreeze(result.value);
536
+ consumerEmittedData.data = result.value.data.data;
537
+ consumerEmittedData.subscribe = (cb) => {
538
+ result.value.subscribe((res) => {
539
+ const consumerEmittedData2 = {
540
+ data: void 0,
541
+ errors: void 0
542
+ };
543
+ if (res.isOk()) {
544
+ consumerEmittedData2.data = res.value.data;
545
+ } else {
546
+ if (isUserVisibleError(res.error)) {
547
+ consumerEmittedData2.data = res.error.data.data;
548
+ consumerEmittedData2.errors = res.error.data.errors;
549
+ } else {
550
+ logError(res.error);
551
+ consumerEmittedData2.errors = [
552
+ {
553
+ message: "Internal error in GraphQL adapter occurred",
554
+ locations: []
555
+ }
556
+ ];
557
+ }
558
+ }
559
+ cb(consumerEmittedData2);
560
+ });
561
+ };
562
+ if (exposeRefresh) {
563
+ consumerEmittedData.refresh = () => {
564
+ return new Promise((resolve, reject) => {
565
+ try {
566
+ result.value.refresh().then((res) => {
567
+ if (res.isOk()) {
568
+ resolve();
569
+ } else {
570
+ reject(
571
+ new Error(
572
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
573
+ )
574
+ );
575
+ }
576
+ });
577
+ } catch (error) {
578
+ logError(error);
579
+ reject(
580
+ new Error(
581
+ "Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data"
582
+ )
583
+ );
584
+ }
585
+ });
586
+ };
587
+ }
588
+ } else {
589
+ const resp = toGraphQLResponseFromFailure(result.error.failure);
590
+ consumerEmittedData.data = resp.data;
591
+ consumerEmittedData.errors = resp.errors;
592
+ }
593
+ return consumerEmittedData;
594
+ } catch (error) {
595
+ logError(error);
596
+ return {
597
+ data: void 0,
598
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
599
+ };
600
+ }
601
+ };
602
+ }
603
+ function buildAsyncGraphQLMutationInvoker(getCommand) {
604
+ return async (...params) => {
605
+ try {
606
+ if (params.length) {
607
+ params[0] = wrapConfigAndVerify(params[0], { acceptedOperations: ["mutation"] });
608
+ }
609
+ const command = getCommand({ params, assertIsValid });
610
+ const result = await command.execute({ cacheControlConfig: { type: "no-cache" } });
611
+ if (result.isOk()) {
612
+ deepFreeze(result.value);
613
+ return result.value.data;
614
+ } else {
615
+ return toGraphQLResponseFromFailure(result.error.failure);
616
+ }
617
+ } catch (error) {
618
+ logError(error);
619
+ return {
620
+ data: void 0,
621
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
622
+ };
623
+ }
624
+ };
625
+ }
626
+ function buildAsyncGraphQLImperativeLegacyInvoker(getCommand) {
627
+ const invoke = async (config, requestContext, callback) => {
628
+ config = wrapConfigAndVerify(config);
629
+ const command = getCommand({ config, assertIsValid });
630
+ try {
631
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
632
+ const result = await command.execute(overrides);
633
+ const consumerEmittedData = {
634
+ data: void 0,
635
+ errors: void 0
636
+ };
637
+ if (result.isOk()) {
638
+ deepFreeze(result.value);
639
+ consumerEmittedData.data = result.value.data.data;
640
+ } else {
641
+ const { data, errors } = toGraphQLResponseFromFailure(result.error.failure);
642
+ consumerEmittedData.data = data;
643
+ consumerEmittedData.errors = errors;
644
+ }
645
+ callback(consumerEmittedData);
646
+ } catch (error) {
647
+ logError(error);
648
+ callback({
649
+ data: void 0,
650
+ errors: [{ message: "Internal error in GraphQL adapter occurred", locations: [] }]
651
+ });
652
+ }
653
+ };
654
+ const subscribe = (config, requestContext, callback) => {
655
+ config = wrapConfigAndVerify(config);
656
+ const command = getCommand({ config, assertIsValid });
657
+ let unsubscribe = () => {
658
+ };
659
+ const overrides = getOverridesForLegacyRequestContext(requestContext);
660
+ command.execute(overrides).then((result) => {
661
+ const consumerEmittedData = {
662
+ data: void 0,
663
+ errors: void 0
664
+ };
665
+ if (result.isOk()) {
666
+ deepFreeze(result.value);
667
+ consumerEmittedData.data = result.value.data.data;
668
+ unsubscribe = result.value.subscribe(
669
+ (res) => {
670
+ handleEmit(res, callback);
671
+ }
672
+ );
673
+ } else {
674
+ const { data, errors } = toGraphQLResponseFromFailure(result.error.failure);
675
+ consumerEmittedData.data = data;
676
+ consumerEmittedData.errors = errors;
677
+ unsubscribe = result.error.subscribe(
678
+ (res) => {
679
+ handleEmit(res, callback);
680
+ }
681
+ );
682
+ }
683
+ callback(consumerEmittedData);
684
+ });
685
+ return () => {
686
+ unsubscribe();
687
+ };
688
+ };
689
+ return { invoke, subscribe };
690
+ }
691
+ function handleEmit(res, callback) {
692
+ const consumerEmittedData = {
693
+ data: void 0,
694
+ errors: void 0
695
+ };
696
+ if (res.isOk()) {
697
+ consumerEmittedData.data = res.value.data;
698
+ } else {
699
+ const { data, errors } = toGraphQLResponseFromFailure(res.error);
700
+ consumerEmittedData.data = data;
701
+ consumerEmittedData.errors = errors;
702
+ }
703
+ callback(consumerEmittedData);
704
+ }
705
+ export {
706
+ CommandWireAdapterConstructor,
707
+ GraphQLCommandErrorWithData,
708
+ GraphQLCommandWireAdapterConstructor,
709
+ buildAsyncGraphQLImperativeInvoker,
710
+ buildAsyncGraphQLImperativeLegacyInvoker,
711
+ buildAsyncGraphQLMutationInvoker,
712
+ buildAsyncImperativeInvoker,
713
+ buildAsyncImperativeLegacyInvoker,
714
+ buildAsyncImperativeSubscribableInvoker,
715
+ buildAsyncQueryImperativeInvoker,
716
+ resolveAst,
717
+ throwGraphQLError
718
+ };
719
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/sanitize.ts","../src/utils.ts","../src/CommandWireAdapterConstructor.ts","../src/imperative.ts","../src/graphql-utils.ts","../src/graphql-wire.ts","../src/graphql-imperative.ts","../src/graphql-mutation.ts","../src/graphql-imperative-legacy.ts"],"sourcesContent":["interface CurrentPath {\n key: string;\n value: object;\n parent: CurrentPath | null;\n data: any;\n}\n\nclass Sanitizer<T extends object> {\n obj: T;\n copy: T;\n currentPath: CurrentPath;\n\n constructor(obj: T) {\n this.obj = obj;\n this.copy = {} as T;\n\n this.currentPath = {\n key: '',\n value: obj,\n parent: null,\n data: this.copy,\n };\n }\n\n sanitize(): T {\n const sanitizer = this;\n\n JSON.stringify(this.obj, function (key, value) {\n if (key === '') {\n return value;\n }\n\n const parent = this;\n if (parent !== sanitizer.currentPath.value) {\n sanitizer.exit(parent);\n }\n if (typeof value === 'object' && value !== null) {\n sanitizer.enter(key, value);\n return value;\n }\n sanitizer.currentPath.data[key] = value;\n\n return value;\n });\n\n return this.copy;\n }\n\n private enter(key: string, value: any) {\n const { currentPath: parentPath } = this;\n const data = (parentPath.data[key] = Array.isArray(value) ? [] : {});\n this.currentPath = {\n key,\n value,\n parent: parentPath,\n data,\n };\n }\n\n private exit(parent: any) {\n while (this.currentPath.value !== parent) {\n this.currentPath = this.currentPath.parent || this.currentPath;\n }\n }\n}\n\n/**\n * Returns a sanitized version of an object by recursively unwrapping the Proxies.\n *\n * All the data coming from LWC-land need to be sanitized first.\n */\nexport default function sanitize<T extends object>(obj: T): T {\n return new Sanitizer(obj).sanitize();\n}\n","import type { Callback, IInternalError, IUserVisibleError } from '@conduit-client/utils';\n\nexport function isInternalError<Data = undefined>(error: unknown): error is IInternalError<Data> {\n return error instanceof Error && 'type' in error && error.type === 'internal';\n}\n\nexport function isUserVisibleError<Data = undefined>(\n error: unknown\n): error is IUserVisibleError<Data> {\n return error instanceof Error && 'type' in error && error.type === 'user-visible';\n}\n\nexport function throwUserlandError(error: unknown): never {\n logError(error);\n throw buildUserlandError(error);\n}\n\nexport function emitError(callback: Callback<any>, error: unknown): void {\n logError(error);\n callback({ data: undefined, error: buildUserlandError(error) });\n}\n\nexport function buildUserlandError(error: unknown): Error {\n if (isUserVisibleError<Error>(error)) {\n return error.data;\n }\n\n return new Error('Internal error in Lightning Data Service adapter occurred.');\n}\n\nexport function logError(error: unknown): void {\n if (isUserVisibleError(error)) {\n return;\n }\n\n console.error('OneStore Command threw an error that we did not expect', error);\n}\n\nexport const supportedCachePolicyTypes = ['no-cache', 'only-if-cached'] as const;\nexport type SupportedCachePolicyType = (typeof supportedCachePolicyTypes)[number];\n\nexport type CachePolicy = {\n cachePolicy: {\n type: SupportedCachePolicyType;\n };\n};\n\n/**\n * Type guard for legacy requestContext objects used with imperative-legacy bindings.\n *\n * When this function returns true, it indicates the caller requested a supported\n * cache policy override. Currently the only supported policy is `no-cache`.\n *\n * This helper is intentionally low-level; prefer using\n * {@link getOverridesForLegacyRequestContext} at call sites to construct the\n * proper `execute` overrides for Commands.\n */\nexport function requestContextIsSupportedCachePolicy(\n requestContext: unknown\n): requestContext is CachePolicy {\n return (\n typeof requestContext === 'object' &&\n requestContext !== null &&\n 'cachePolicy' in requestContext &&\n typeof requestContext.cachePolicy === 'object' &&\n requestContext.cachePolicy !== null &&\n 'type' in requestContext.cachePolicy &&\n typeof requestContext.cachePolicy.type === 'string' &&\n supportedCachePolicyTypes.includes(\n requestContext.cachePolicy.type as SupportedCachePolicyType\n )\n );\n}\n\nexport type LegacyExecuteOverrides = {\n cacheControlConfig?: { type: SupportedCachePolicyType };\n};\n\n/**\n * Builds the `execute` overrides for legacy imperative invokers based on the\n * provided requestContext. Encapsulates all hard-coded knowledge of supported\n * cache policies for legacy adapters.\n *\n * - If {@link requestContextIsSupportedCachePolicy} matches `no-cache`, returns\n * `{ cacheControlConfig: { type: 'no-cache' } }`.\n * - Otherwise returns `{}`.\n *\n * Use this in `buildAsyncImperativeLegacyInvoker` and GraphQL legacy invokers\n * to centralize override behavior.\n */\nexport function getOverridesForLegacyRequestContext(\n requestContext: unknown\n): LegacyExecuteOverrides {\n if (requestContextIsSupportedCachePolicy(requestContext)) {\n return { cacheControlConfig: { type: requestContext.cachePolicy.type } };\n }\n return {};\n}\n","import { type Command } from '@conduit-client/command-base/v1';\nimport {\n toError,\n deepFreeze,\n type Result,\n ok,\n isSubscribableResult,\n err,\n} from '@conduit-client/utils';\nimport {\n type WireAdapter,\n type WireConfigValue,\n type WireContextValue,\n type WireDataCallback,\n} from '@conduit-client/lwc-types';\nimport {\n assertIsValid,\n MissingRequiredPropertyError,\n type JSONSchema,\n JsonSchemaViolationError,\n} from '@conduit-client/jsonschema-validate';\nimport sanitize from './sanitize';\nimport type {\n SyncOrAsync,\n Unsubscribe,\n SubscribableResult,\n CommandError,\n} from '@conduit-client/utils';\nimport { emitError } from './utils';\n\ntype MaybeSubscribableResultCommand<Data, Error> = Command<\n SyncOrAsync<Result<Data, Error> | SubscribableResult<Data, Error>>\n>;\nexport type SubscribableResultCommand<Data, Error> = Command<\n SyncOrAsync<SubscribableResult<Data, Error>>\n>;\nexport type ResultCommand<Data, Error> = Command<SyncOrAsync<Result<Data, Error>>>;\nexport type WireAdapterCompatibleCommand<Data, Error> =\n | SubscribableResultCommand<Data, Error>\n | ResultCommand<Data, Error>\n | MaybeSubscribableResultCommand<Data, Error>;\n\n/**\n * Binds a Command to a LWC wire adapter.\n * @see https://lwc.dev/guide/wire_adapter\n */\nexport abstract class CommandWireAdapterConstructor<\n Data,\n Config extends WireConfigValue = WireConfigValue,\n CommandType extends WireAdapterCompatibleCommand<\n Data,\n CommandError\n > = WireAdapterCompatibleCommand<Data, CommandError>,\n> implements WireAdapter\n{\n connected = false;\n config?: Config;\n unsubscriber?: Unsubscribe;\n exposeRefresh = false;\n\n abstract configSchema?: JSONSchema;\n abstract getCommand(): CommandType;\n protected refresh?: () => SyncOrAsync<Result<void, unknown>>;\n\n constructor(\n protected callback: WireDataCallback,\n sourceContext?: {\n tagName?: string;\n },\n options?: {\n skipEmptyEmit?: true;\n }\n ) {\n if (!options?.skipEmptyEmit) {\n this.emit();\n }\n }\n\n connect(): void {\n this.connected = true;\n this.invokeAdapter();\n }\n\n disconnect(): void {\n this.unsubscribe();\n this.connected = false;\n }\n\n update(config: Config, _context?: WireContextValue): void {\n this.unsubscribe();\n this.config = sanitize<Config>(config);\n this.invokeAdapter();\n }\n\n protected emit(result?: Result<Data, unknown> | SubscribableResult<Data, unknown>) {\n try {\n if (result === undefined) {\n this.callback({ data: undefined, error: undefined });\n } else {\n const consumerEmittedRefresh = (): Promise<void> => {\n if (!this.refresh) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n if (!this.refresh) {\n resolve();\n return;\n }\n this.refresh().then((res) => {\n if (res.isOk()) {\n resolve();\n } else {\n reject(\n new Error(\n 'Internal error in Lightning Data Service adapter occurred: Failed to refresh data'\n )\n );\n }\n });\n });\n };\n\n let consumerEmittedData = {\n data: undefined,\n error: undefined,\n } as {\n data: Data | undefined;\n error: unknown | undefined;\n refresh?: () => Promise<void>;\n };\n\n if (this.exposeRefresh && this.refresh) {\n consumerEmittedData.refresh = consumerEmittedRefresh;\n }\n\n if (result.isErr()) {\n if (isSubscribableResult(result)) {\n consumerEmittedData.error = result.error.failure;\n } else {\n consumerEmittedData.error = result.error;\n }\n } else {\n if (isSubscribableResult(result)) {\n deepFreeze(result.value.data);\n consumerEmittedData.data = result.value.data;\n } else {\n deepFreeze(result.value);\n consumerEmittedData.data = result.value;\n }\n }\n\n this.callback(consumerEmittedData);\n }\n } catch (e) {\n this.handleExecutionThrow(e);\n }\n }\n\n protected invokeAdapter() {\n if (!this.connected || this.config === undefined) {\n return;\n }\n\n if (this.configSchema) {\n try {\n assertIsValid<unknown>(this.config, this.configSchema);\n } catch (err) {\n if (isIncompleteConfigError(err)) {\n // config is incomplete, wait for updated config\n return;\n }\n\n throw err;\n }\n }\n\n const initialConfig = this.config;\n const command = this.getCommand();\n\n try {\n command.execute().then((result) => {\n // config changed or component disconnected before result came back, ignore result\n if (!this.connected || this.config !== initialConfig) {\n return;\n }\n\n this.refresh = undefined;\n\n if (result.isOk()) {\n if (isSubscribableResult<Data, unknown>(result)) {\n const value = result.value;\n this.unsubscriber = value.subscribe((updatedResult) => {\n if (!this.connected || this.config !== initialConfig) {\n this.unsubscribe();\n return;\n }\n\n this.emit(updatedResult);\n });\n this.refresh = value.refresh;\n this.emit(ok(value.data));\n } else {\n this.emit(result);\n }\n } else {\n if (isSubscribableResult(result)) {\n const value = result.error;\n this.unsubscriber = value.subscribe((updatedResult) => {\n if (!this.connected || this.config !== initialConfig) {\n this.unsubscribe();\n return;\n }\n\n this.emit(updatedResult);\n });\n this.refresh = value.refresh;\n this.emit(result);\n } else {\n this.unsubscriber = () => {};\n this.emit(result);\n }\n }\n });\n } catch (e: unknown) {\n this.handleExecutionThrow(e);\n }\n }\n\n protected handleExecutionThrow(error: unknown) {\n emitError(this.callback, error);\n }\n\n protected unsubscribe() {\n if (this.unsubscriber) {\n this.unsubscriber();\n delete this.unsubscriber;\n }\n }\n}\n\nfunction isIncompleteConfigError(err: unknown): boolean {\n return (\n err instanceof MissingRequiredPropertyError ||\n (err instanceof JsonSchemaViolationError &&\n err.validationErrors.find(\n (validationError) => validationError instanceof MissingRequiredPropertyError\n ) !== undefined)\n );\n}\n","import { assertIsValid, type JSONSchema } from '@conduit-client/jsonschema-validate';\nimport { type Command } from '@conduit-client/command-base/v1';\nimport { toError, deepFreeze, isSubscribableResult } from '@conduit-client/utils';\nimport type {\n SyncOrAsync,\n Result,\n SubscribableResult,\n Unsubscribe,\n Callback,\n} from '@conduit-client/utils';\nimport { emitError, throwUserlandError, getOverridesForLegacyRequestContext } from './utils';\nimport type { LegacyExecuteOverrides } from './utils';\n\ntype MaybeSubscribableResultCommand<Data> = Command<\n SyncOrAsync<Result<Data, unknown> | SubscribableResult<Data, unknown>>\n>;\ntype SubscribableResultCommand<Data, Params extends Array<any> = []> = Command<\n SyncOrAsync<SubscribableResult<Data, unknown>>,\n Params\n>;\ntype ResultCommand<Data> = Command<SyncOrAsync<Result<Data, unknown>>>;\ntype ImperativeCommand<Data> =\n | SubscribableResultCommand<Data>\n | ResultCommand<Data>\n | MaybeSubscribableResultCommand<Data>;\n\n/**\n * Returns an async function wrapper around an `ImperativeCommand`. Handles\n * both subscribable and non-subscribable commands, but only returns regular data.\n *\n * @typeParam Params parameters accepted by the generated function\n * @typeParam Config Command config type\n * @typeParam Data data returned by the Command\n * @param getCommand utility function that constructs an instance of the Command from\n * the supplied parameters; the function should do any necessary parameter checking\n * and throw errors as appropriate\n * @returns A PromiseLike containing the result of command execution\n */\nexport function buildAsyncImperativeInvoker<Params extends Array<any>, Data>(\n getCommand: (options: {\n params: Params;\n // utility to validate data against a JSONSchema\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => ImperativeCommand<Data>\n): (...params: Params) => DefaultImperativeResult<Data> {\n return async (...params: Params) => {\n const command = getCommand({ params, assertIsValid });\n try {\n return command.execute().then(\n (result) => {\n if (result.isOk()) {\n deepFreeze(result.value);\n // For subscribable results processed by this invoker, only return data\n return isSubscribableResult(result) ? result.value.data : result.value;\n }\n\n throw toError(\n isSubscribableResult(result) ? result.error.failure : result.error\n );\n },\n (e) => {\n throwUserlandError(e);\n }\n );\n } catch (e) {\n throwUserlandError(e);\n }\n };\n}\n\n/**\n * Returns an async function wrapper around a query `Command`. Handles\n * both subscribable and non-subscribable commands, but only returns regular data.\n *\n * @typeParam Params parameters accepted by the generated function\n * @typeParam Config Command config type\n * @typeParam Data data returned by the Command\n * @param getCommand utility function that constructs an instance of the Command from\n * the supplied parameters; the function should do any necessary parameter checking\n * and throw errors as appropriate\n * @returns A PromiseLike containing the result of command execution\n */\nexport function buildAsyncQueryImperativeInvoker<Params extends Array<any>, Data>(\n getCommand: (options: {\n params: Params;\n // utility to validate data against a JSONSchema\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => ImperativeCommand<Data>\n): (...params: Params) => QueryImperativeResult<Data> {\n const baseInvoker = buildAsyncImperativeInvoker(getCommand);\n return async (...params: Params) => ({ data: await baseInvoker(...params) });\n}\n\nexport type DefaultImperativeResult<Data> = PromiseLike<Data>;\nexport type QueryImperativeResult<Data> = PromiseLike<{ data: Data }>;\n\nexport type SubscribableImperativeResult<Data> = PromiseLike<{\n data: Data;\n subscribe: (cb: Callback<any>) => void;\n}>;\n\nexport type SubscribableRefreshableImperativeResult<Data> = PromiseLike<{\n data: Data;\n subscribe: (cb: Callback<any>) => void;\n refresh: () => PromiseLike<void>;\n}>;\n\nexport type MaybeRefreshableSubscribableImperativeResult<Data> =\n | SubscribableImperativeResult<Data>\n | SubscribableRefreshableImperativeResult<Data>;\n\n/**\n * Returns an async function wrapper around an `ImperativeCommand`. Handles\n * only subscribable commands and returns a subscribable result.\n *\n * @typeParam Params parameters accepted by the generated function\n * @typeParam Config Command config type\n * @typeParam Data data returned by the Command\n * @param getCommand utility function that constructs an instance of the Command from\n * the supplied parameters; the function should do any necessary parameter checking\n * and throw errors as appropriate\n * @param exposeRefresh whether to expose a `refresh` method on the result returned by\n * the generated function. The default is `false`.\n * @returns A PromiseLike containing the subscribable result of command execution\n */\nexport function buildAsyncImperativeSubscribableInvoker<Params extends Array<any>, Data>(\n getCommand: (options: {\n params: Params;\n // utility to validate data against a JSONSchema\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => ImperativeCommand<Data>,\n exposeRefresh = false\n): (...params: Params) => MaybeRefreshableSubscribableImperativeResult<Data> {\n return async (...params: Params) => {\n const command = getCommand({ params, assertIsValid });\n let result: Result<Data, unknown> | SubscribableResult<Data, unknown>;\n try {\n result = await command.execute();\n } catch (e) {\n throwUserlandError(e);\n }\n\n if (!isSubscribableResult(result)) {\n console.error(\n 'Non-subscribable result encountered - please use correct operation type'\n );\n throw new Error('Internal error in Lightning Data Service adapter occurred');\n }\n if (result.isOk()) {\n deepFreeze(result.value.data);\n\n const api = {\n data: result.value.data,\n subscribe: (cb: Callback<any>) => {\n result.value.subscribe((result) => {\n if (result.isErr()) {\n return cb({ data: undefined, error: toError(result.error) });\n }\n\n return cb({ data: result.value, error: undefined });\n });\n },\n };\n\n if (exposeRefresh) {\n return {\n ...api,\n refresh: () => {\n return result.value.refresh().then((res) => {\n if (res.isOk()) {\n return undefined;\n }\n throw res.error;\n });\n },\n };\n } else {\n return api;\n }\n } else {\n throw toError(result.error.failure);\n }\n };\n}\n\ntype LegacyImperativeCallbackResult<Data> =\n | { data: Data; error: undefined }\n | { data: undefined; error: Error };\n\ntype LegacyImperativeAdapterInvokeType<Config, Data> = (\n config: Config,\n context: unknown,\n callback: (result: LegacyImperativeCallbackResult<Data>) => void\n) => void;\n\ntype LegacyImperativeAdapterSubscribeType<Config, Data> = (\n config: Config,\n context: unknown,\n callback: (result: LegacyImperativeCallbackResult<Data>) => void\n) => Unsubscribe;\n\nexport type LegacyImperativeShape<Config, Data> = {\n invoke: LegacyImperativeAdapterInvokeType<Config, Data>;\n subscribe: LegacyImperativeAdapterSubscribeType<Config, Data>;\n};\n\nexport function buildAsyncImperativeLegacyInvoker<Config, Data>(\n getCommand: (options: {\n config: Config;\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => SubscribableResultCommand<Data, [LegacyExecuteOverrides?]>\n): LegacyImperativeShape<Config, Data> {\n const invoke: LegacyImperativeAdapterInvokeType<Config, Data> = async (\n config: Config,\n requestContext: unknown,\n callback: (result: LegacyImperativeCallbackResult<Data>) => void\n ) => {\n const command = getCommand({ config, assertIsValid });\n\n try {\n const overrides = getOverridesForLegacyRequestContext(requestContext);\n const result = await command.execute(overrides);\n if (result.isOk()) {\n deepFreeze(result.value);\n callback({ data: result.value.data, error: undefined });\n } else {\n callback({ data: undefined, error: toError(result.error.failure) });\n }\n } catch (error) {\n emitError(callback, error);\n }\n };\n\n const subscribe: LegacyImperativeAdapterSubscribeType<Config, Data> = (\n config: Config,\n requestContext: unknown,\n callback: (result: LegacyImperativeCallbackResult<Data>) => void\n ) => {\n const command = getCommand({ config, assertIsValid });\n\n let unsubscribe: Unsubscribe = () => {};\n\n try {\n const overrides = getOverridesForLegacyRequestContext(requestContext);\n command.execute(overrides).then(\n (result: Awaited<ReturnType<typeof command.execute>>) => {\n if (!result.isOk()) {\n callback({ data: undefined, error: toError(result.error.failure) });\n return;\n }\n\n unsubscribe = result.value.subscribe((res: Result<Data, unknown>) => {\n if (res.isOk()) {\n callback({ data: res.value, error: undefined });\n } else {\n callback({ data: undefined, error: toError(res.error) });\n }\n });\n\n callback({ data: result.value.data, error: undefined });\n },\n (e: unknown) => {\n emitError(callback, e);\n }\n );\n } catch (e) {\n emitError(callback, e);\n }\n\n return () => {\n unsubscribe();\n };\n };\n\n return { invoke, subscribe };\n}\n","import { SubscribableResultCommand } from './CommandWireAdapterConstructor';\nimport {\n Callback,\n deepFreeze,\n Result,\n SubscribableResult,\n IErrorWithData,\n isSubscribableResult,\n} from '@conduit-client/utils';\nimport {\n type GraphQLCommandError,\n type GraphQLResponse,\n} from '@conduit-client/graphql-normalization/v1';\nimport {\n astResolver,\n DocumentNode,\n Kind,\n OperationDefinitionNode,\n} from '@conduit-client/onestore-graphql-parser/v1';\nimport { isUserVisibleError, logError } from './utils';\n\nexport type GraphQLCommand = SubscribableResultCommand<GraphQLResponse, GraphQLCommandError>;\n\nexport class GraphQLCommandErrorWithData extends Error implements IErrorWithData<GraphQLResponse> {\n constructor(public data: GraphQLResponse) {\n super();\n }\n}\n\nexport function throwGraphQLError(error: unknown): never {\n logError(error);\n if (isUserVisibleError<GraphQLResponse>(error)) {\n throw new GraphQLCommandErrorWithData(error.data);\n }\n throw new Error('Internal error in GraphQL adapter occurred');\n}\n\n/**\n * Finds the executable operation from a GraphQL document based on operationName\n * @param document The GraphQL DocumentNode\n * @param operationName Optional operation name to select specific operation\n * @returns The executable operation or undefined if none found\n */\nfunction findExecutableOperation(\n document: DocumentNode,\n operationName?: string\n): OperationDefinitionNode | undefined {\n const operations = document.definitions.filter(\n (def) => def.kind === Kind.OPERATION_DEFINITION\n ) as OperationDefinitionNode[];\n\n if (operations.length === 0) {\n return undefined;\n }\n\n if (operations.length === 1 && !operationName) {\n return operations[0];\n }\n\n if (operationName) {\n return operations.find((op) => op.name?.value === operationName);\n }\n\n // Multiple operations found but no operation name provided\n // In this case, we can't determine which operation will be executed\n // so we can't validate. Let GraphQL execution handle this error.\n return undefined;\n}\n\n/**\n * Validates a GraphQL config and rejects operations not in the accepted list\n * @param config The GraphQL config containing query and operationName\n * @param options Options containing acceptedOperations array\n * @throws Error if the executable operation is not in acceptedOperations\n */\nexport function validateGraphQLOperations(\n config: { query: DocumentNode; operationName?: string },\n options: { acceptedOperations: ('query' | 'mutation' | 'subscription')[] }\n): void {\n const executableOperation = findExecutableOperation(config.query, config.operationName);\n\n if (executableOperation) {\n const operationType = executableOperation.operation;\n if (!options.acceptedOperations.includes(operationType)) {\n const operationTypeCapitalized =\n operationType.charAt(0).toUpperCase() + operationType.slice(1);\n throw new Error(\n `${operationTypeCapitalized} operations are not supported in this context`\n );\n }\n }\n}\n\nexport function resolveAst(ast: any): DocumentNode | undefined {\n if (ast === null || ast === undefined) {\n return;\n }\n const result = astResolver(ast);\n if (result === undefined) {\n throw new Error('Could not resolve AST. Did you parse the query with gql?');\n }\n return result;\n}\n\nexport function wrapConfigAndVerify(\n config: any,\n options?: { acceptedOperations?: ('query' | 'mutation' | 'subscription')[] }\n): any {\n if (config?.query) {\n config = { ...config, query: resolveAst(config.query) };\n if (config.query === undefined) {\n throw new Error('Internal error in GraphQL adapter occurred: Unable to resolve query');\n }\n // Validate the resolved query for operation types, considering operationName\n validateGraphQLOperations(config, {\n acceptedOperations: options?.acceptedOperations ?? ['query'],\n });\n }\n return config;\n}\n\nexport function formatGraphQLData(data: GraphQLResponse): GraphQLResponse {\n // extensions should always be omitted\n // errors should be omitted when there are no errors\n\n if (data.errors === undefined || data.errors.length === 0) {\n return {\n data: data.data,\n errors: undefined,\n } satisfies GraphQLResponse;\n }\n\n return {\n data: data.data,\n errors: data.errors,\n } satisfies GraphQLResponse;\n}\n\n/**\n * Maps a command failure (unknown or user-visible) into a GraphQLResponse suitable for consumers.\n */\nexport function toGraphQLResponseFromFailure(failure: unknown): {\n data: GraphQLResponse['data'];\n errors: GraphQLResponse['errors'];\n} {\n if (isUserVisibleError<GraphQLResponse>(failure)) {\n return {\n data: failure.data.data,\n errors: failure.data.errors,\n };\n }\n logError(failure);\n return {\n data: undefined,\n errors: [{ message: 'Internal error in GraphQL adapter occurred', locations: [] }],\n };\n}\n","import { WireConfigValue, WireContextValue } from '@conduit-client/lwc-types';\nimport { CommandWireAdapterConstructor } from './CommandWireAdapterConstructor';\nimport {\n Result,\n SubscribableResult,\n deepFreeze,\n err,\n isSubscribableResult,\n} from '@conduit-client/utils';\nimport {\n type GraphQLCommandError,\n type GraphQLResponse,\n} from '@conduit-client/graphql-normalization/v1';\nimport {\n GraphQLCommand,\n resolveAst,\n validateGraphQLOperations,\n toGraphQLResponseFromFailure,\n} from './graphql-utils';\nimport sanitize from './sanitize';\nimport { logError } from './utils';\n\nexport abstract class GraphQLCommandWireAdapterConstructor<\n Config extends WireConfigValue = WireConfigValue,\n> extends CommandWireAdapterConstructor<GraphQLResponse, Config, GraphQLCommand> {\n protected emit(\n result?:\n | SubscribableResult<GraphQLResponse, GraphQLCommandError>\n | Result<GraphQLResponse, GraphQLCommandError>\n | undefined\n ): void {\n try {\n if (result === undefined) {\n this.callback({ data: undefined, errors: undefined });\n } else {\n const consumerEmittedRefresh = (): Promise<void> => {\n if (!this.refresh) {\n return Promise.resolve();\n }\n return new Promise((resolve, reject) => {\n if (!this.refresh) {\n resolve();\n return;\n }\n this.refresh().then((res) => {\n if (res.isOk()) {\n resolve();\n } else {\n reject(\n new Error(\n 'Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data'\n )\n );\n }\n });\n });\n };\n\n let consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: unknown | undefined;\n refresh?: () => Promise<void>;\n };\n\n if (this.exposeRefresh && this.refresh) {\n consumerEmittedData.refresh = consumerEmittedRefresh;\n }\n\n if (result.isErr()) {\n const failure = isSubscribableResult(result)\n ? result.error.failure\n : result.error;\n const resp = toGraphQLResponseFromFailure(failure);\n consumerEmittedData.data = resp.data;\n consumerEmittedData.errors = resp.errors;\n } else {\n consumerEmittedData.data = result.value.data;\n }\n\n deepFreeze(consumerEmittedData);\n this.callback(consumerEmittedData);\n }\n } catch (e) {\n logError(e);\n this.handleExecutionThrow(e);\n }\n }\n\n protected handleExecutionThrow(e: unknown): void {\n logError(e);\n this.callback({\n data: undefined,\n errors: [{ message: 'Internal error in GraphQL adapter occurred', locations: [] }],\n } satisfies GraphQLResponse);\n }\n\n update(config: Config, _context?: WireContextValue): void {\n this.unsubscribe();\n\n const resolvedQuery = resolveAst(config.query);\n if (resolvedQuery) {\n // Validate the resolved query for operation types, considering operationName\n validateGraphQLOperations(\n { query: resolvedQuery, operationName: (config as any)?.operationName },\n { acceptedOperations: ['query'] }\n );\n }\n\n this.config = {\n ...sanitize<Config>(config),\n query: resolvedQuery,\n };\n this.invokeAdapter();\n }\n}\n","import { Callback, deepFreeze } from '@conduit-client/utils';\nimport { JSONSchema, assertIsValid } from '@conduit-client/jsonschema-validate';\nimport { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';\nimport { GraphQLCommand, wrapConfigAndVerify, toGraphQLResponseFromFailure } from './graphql-utils';\nimport { isUserVisibleError, logError } from './utils';\n\nexport type SubscribableRefreshableGraphQLImperativeResult = Promise<\n GraphQLResponse & {\n subscribe?: (cb: Callback<any>) => void;\n refresh?: () => PromiseLike<void>;\n }\n>;\n\nexport function buildAsyncGraphQLImperativeInvoker<Params extends Array<any>>(\n getCommand: (options: {\n params: Params;\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => GraphQLCommand,\n exposeRefresh = false\n): (...params: Params) => SubscribableRefreshableGraphQLImperativeResult {\n return async (...params: Params) => {\n try {\n if (params.length) {\n params[0] = wrapConfigAndVerify(params[0]);\n }\n const command = getCommand({ params, assertIsValid });\n const result = await command.execute();\n\n const consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: any | undefined;\n subscribe: (cb: Callback<any>) => void;\n refresh: () => PromiseLike<void>;\n };\n\n if (result.isOk()) {\n deepFreeze(result.value);\n consumerEmittedData.data = result.value.data.data;\n consumerEmittedData.subscribe = (cb: Callback<any>) => {\n result.value.subscribe((res) => {\n const consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: any | undefined;\n };\n if (res.isOk()) {\n consumerEmittedData.data = res.value.data;\n } else {\n if (isUserVisibleError<GraphQLResponse>(res.error)) {\n consumerEmittedData.data = res.error.data.data;\n consumerEmittedData.errors = res.error.data.errors;\n } else {\n logError(res.error);\n consumerEmittedData.errors = [\n {\n message: 'Internal error in GraphQL adapter occurred',\n locations: [],\n },\n ];\n }\n }\n cb(consumerEmittedData);\n });\n };\n if (exposeRefresh) {\n consumerEmittedData.refresh = () => {\n return new Promise((resolve, reject) => {\n try {\n result.value.refresh().then((res) => {\n if (res.isOk()) {\n resolve();\n } else {\n reject(\n new Error(\n 'Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data'\n )\n );\n }\n });\n } catch (error) {\n logError(error);\n reject(\n new Error(\n 'Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data'\n )\n );\n }\n });\n };\n }\n } else {\n const resp = toGraphQLResponseFromFailure(result.error.failure);\n consumerEmittedData.data = resp.data;\n consumerEmittedData.errors = resp.errors;\n }\n\n return consumerEmittedData;\n } catch (error) {\n logError(error);\n return {\n data: undefined,\n errors: [{ message: 'Internal error in GraphQL adapter occurred', locations: [] }],\n };\n }\n };\n}\n","import { deepFreeze } from '@conduit-client/utils';\nimport { JSONSchema, assertIsValid } from '@conduit-client/jsonschema-validate';\nimport { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';\nimport { GraphQLCommand, wrapConfigAndVerify, toGraphQLResponseFromFailure } from './graphql-utils';\nimport { logError, type LegacyExecuteOverrides } from './utils';\nimport type { Command } from '@conduit-client/command-base/v1';\n\nexport type GraphQLMutationResult = Promise<GraphQLResponse>;\n\nexport function buildAsyncGraphQLMutationInvoker<Params extends Array<any>>(\n getCommand: (options: {\n params: Params;\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => Command<ReturnType<GraphQLCommand['execute']>, [LegacyExecuteOverrides?]>\n): (...params: Params) => GraphQLMutationResult {\n return async (...params: Params) => {\n try {\n if (params.length) {\n params[0] = wrapConfigAndVerify(params[0], { acceptedOperations: ['mutation'] });\n }\n const command = getCommand({ params, assertIsValid });\n const result = await command.execute({ cacheControlConfig: { type: 'no-cache' } });\n\n if (result.isOk()) {\n deepFreeze(result.value);\n return result.value.data;\n } else {\n return toGraphQLResponseFromFailure(result.error.failure);\n }\n } catch (error) {\n logError(error);\n return {\n data: undefined,\n errors: [{ message: 'Internal error in GraphQL adapter occurred', locations: [] }],\n } satisfies GraphQLResponse;\n }\n };\n}\n","import { deepFreeze, Result, Unsubscribe } from '@conduit-client/utils';\nimport { JSONSchema, assertIsValid } from '@conduit-client/jsonschema-validate';\nimport {\n GraphQLCommandError,\n type GraphQLResponse,\n} from '@conduit-client/graphql-normalization/v1';\nimport { GraphQLCommand, wrapConfigAndVerify, toGraphQLResponseFromFailure } from './graphql-utils';\nimport type { Command } from '@conduit-client/command-base/v1';\nimport { isUserVisibleError, logError, getOverridesForLegacyRequestContext } from './utils';\nimport type { LegacyExecuteOverrides } from './utils';\n\ntype LegacyGraphQLImperativeAdapterInvokeType<Config> = (\n config: Config,\n context: unknown,\n callback: (result: GraphQLResponse) => void\n) => void;\n\ntype LegacyGraphQLImperativeAdapterSubscribeType<Config> = (\n config: Config,\n context: unknown,\n callback: (result: GraphQLResponse) => void\n) => Unsubscribe;\n\nexport type LegacyGraphQLImperativeShape<Config> = {\n invoke: LegacyGraphQLImperativeAdapterInvokeType<Config>;\n subscribe: LegacyGraphQLImperativeAdapterSubscribeType<Config>;\n};\n\nexport function buildAsyncGraphQLImperativeLegacyInvoker<Config>(\n getCommand: (options: {\n config: Config;\n assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;\n }) => Command<ReturnType<GraphQLCommand['execute']>, [LegacyExecuteOverrides?]>\n): LegacyGraphQLImperativeShape<Config> {\n const invoke: LegacyGraphQLImperativeAdapterInvokeType<Config> = async (\n config: Config,\n requestContext: unknown,\n callback: (result: GraphQLResponse) => void\n ) => {\n config = wrapConfigAndVerify(config);\n const command = getCommand({ config, assertIsValid });\n\n try {\n const overrides = getOverridesForLegacyRequestContext(requestContext);\n const result: Awaited<ReturnType<typeof command.execute>> =\n await command.execute(overrides);\n\n const consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: any | undefined;\n };\n\n if (result.isOk()) {\n deepFreeze(result.value);\n consumerEmittedData.data = result.value.data.data;\n } else {\n const { data, errors } = toGraphQLResponseFromFailure(result.error.failure);\n consumerEmittedData.data = data;\n consumerEmittedData.errors = errors;\n }\n\n callback(consumerEmittedData);\n } catch (error) {\n logError(error);\n callback({\n data: undefined,\n errors: [{ message: 'Internal error in GraphQL adapter occurred', locations: [] }],\n } satisfies GraphQLResponse);\n }\n };\n\n const subscribe: LegacyGraphQLImperativeAdapterSubscribeType<Config> = (\n config: Config,\n requestContext: unknown,\n callback: (result: GraphQLResponse) => void\n ) => {\n config = wrapConfigAndVerify(config);\n const command = getCommand({ config, assertIsValid });\n\n let unsubscribe: Unsubscribe = () => {};\n\n const overrides = getOverridesForLegacyRequestContext(requestContext);\n command.execute(overrides).then((result: Awaited<ReturnType<typeof command.execute>>) => {\n const consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: any | undefined;\n };\n\n if (result.isOk()) {\n deepFreeze(result.value);\n consumerEmittedData.data = result.value.data.data;\n unsubscribe = result.value.subscribe(\n (res: Result<GraphQLResponse<Record<string, any>>, GraphQLCommandError>) => {\n handleEmit(res, callback);\n }\n );\n } else {\n const { data, errors } = toGraphQLResponseFromFailure(result.error.failure);\n consumerEmittedData.data = data;\n consumerEmittedData.errors = errors;\n unsubscribe = result.error.subscribe(\n (res: Result<GraphQLResponse<Record<string, any>>, GraphQLCommandError>) => {\n handleEmit(res, callback);\n }\n );\n }\n\n callback(consumerEmittedData);\n });\n\n return () => {\n unsubscribe();\n };\n };\n\n return { invoke, subscribe };\n}\n\nfunction handleEmit(\n res: Result<GraphQLResponse<Record<string, any>>, GraphQLCommandError>,\n callback: (result: GraphQLResponse) => void\n) {\n const consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse | undefined;\n errors: any | undefined;\n };\n if (res.isOk()) {\n consumerEmittedData.data = res.value.data;\n } else {\n const { data, errors } = toGraphQLResponseFromFailure(res.error);\n consumerEmittedData.data = data;\n consumerEmittedData.errors = errors;\n }\n callback(consumerEmittedData);\n}\n"],"names":["err","result","consumerEmittedData"],"mappings":";;;;;;;;AAOA,MAAM,UAA4B;AAAA,EAK9B,YAAY,KAAQ;AAChB,SAAK,MAAM;AACX,SAAK,OAAO,CAAA;AAEZ,SAAK,cAAc;AAAA,MACf,KAAK;AAAA,MACL,OAAO;AAAA,MACP,QAAQ;AAAA,MACR,MAAM,KAAK;AAAA,IAAA;AAAA,EAEnB;AAAA,EAEA,WAAc;AACV,UAAM,YAAY;AAEl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KAAK,CAAC,WAAwD;AACrF,YAAM,sBAAsB;AAAA,QACxB,MAAM;AAAA,QACN,QAAQ;AAAA,MAAA;AAMZ,UAAI,OAAO,QAAQ;AACf,mBAAW,OAAO,KAAK;AACvB,4BAAoB,OAAO,OAAO,MAAM,KAAK;AAC7C,sBAAc,OAAO,MAAM;AAAA,UACvB,CAAC,QAA2E;AACxE,uBAAW,KAAK,QAAQ;AAAA,UAC5B;AAAA,QAAA;AAAA,MAER,OAAO;AACH,cAAM,EAAE,MAAM,OAAA,IAAW,6BAA6B,OAAO,MAAM,OAAO;AAC1E,4BAAoB,OAAO;AAC3B,4BAAoB,SAAS;AAC7B,sBAAc,OAAO,MAAM;AAAA,UACvB,CAAC,QAA2E;AACxE,uBAAW,KAAK,QAAQ;AAAA,UAC5B;AAAA,QAAA;AAAA,MAER;AAEA,eAAS,mBAAmB;AAAA,IAChC,CAAC;AAED,WAAO,MAAM;AACT,kBAAA;AAAA,IACJ;AAAA,EACJ;AAEA,SAAO,EAAE,QAAQ,UAAA;AACrB;AAEA,SAAS,WACL,KACA,UACF;AACE,QAAM,sBAAsB;AAAA,IACxB,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAKZ,MAAI,IAAI,QAAQ;AACZ,wBAAoB,OAAO,IAAI,MAAM;AAAA,EACzC,OAAO;AACH,UAAM,EAAE,MAAM,OAAA,IAAW,6BAA6B,IAAI,KAAK;AAC/D,wBAAoB,OAAO;AAC3B,wBAAoB,SAAS;AAAA,EACjC;AACA,WAAS,mBAAmB;AAChC;"}
@@ -0,0 +1,36 @@
1
+ import { type Command } from '@conduit-client/command-base/v1';
2
+ import { type Result } from '@conduit-client/utils';
3
+ import { type WireAdapter, type WireConfigValue, type WireContextValue, type WireDataCallback } from '@conduit-client/lwc-types';
4
+ import { type JSONSchema } from '@conduit-client/jsonschema-validate';
5
+ import type { SyncOrAsync, Unsubscribe, SubscribableResult, CommandError } from '@conduit-client/utils';
6
+ type MaybeSubscribableResultCommand<Data, Error> = Command<SyncOrAsync<Result<Data, Error> | SubscribableResult<Data, Error>>>;
7
+ export type SubscribableResultCommand<Data, Error> = Command<SyncOrAsync<SubscribableResult<Data, Error>>>;
8
+ export type ResultCommand<Data, Error> = Command<SyncOrAsync<Result<Data, Error>>>;
9
+ export type WireAdapterCompatibleCommand<Data, Error> = SubscribableResultCommand<Data, Error> | ResultCommand<Data, Error> | MaybeSubscribableResultCommand<Data, Error>;
10
+ /**
11
+ * Binds a Command to a LWC wire adapter.
12
+ * @see https://lwc.dev/guide/wire_adapter
13
+ */
14
+ export declare abstract class CommandWireAdapterConstructor<Data, Config extends WireConfigValue = WireConfigValue, CommandType extends WireAdapterCompatibleCommand<Data, CommandError> = WireAdapterCompatibleCommand<Data, CommandError>> implements WireAdapter {
15
+ protected callback: WireDataCallback;
16
+ connected: boolean;
17
+ config?: Config;
18
+ unsubscriber?: Unsubscribe;
19
+ exposeRefresh: boolean;
20
+ abstract configSchema?: JSONSchema;
21
+ abstract getCommand(): CommandType;
22
+ protected refresh?: () => SyncOrAsync<Result<void, unknown>>;
23
+ constructor(callback: WireDataCallback, sourceContext?: {
24
+ tagName?: string;
25
+ }, options?: {
26
+ skipEmptyEmit?: true;
27
+ });
28
+ connect(): void;
29
+ disconnect(): void;
30
+ update(config: Config, _context?: WireContextValue): void;
31
+ protected emit(result?: Result<Data, unknown> | SubscribableResult<Data, unknown>): void;
32
+ protected invokeAdapter(): void;
33
+ protected handleExecutionThrow(error: unknown): void;
34
+ protected unsubscribe(): void;
35
+ }
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import { Unsubscribe } from '@conduit-client/utils';
2
+ import { JSONSchema } from '@conduit-client/jsonschema-validate';
3
+ import { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
4
+ import { GraphQLCommand } from './graphql-utils';
5
+ import type { Command } from '@conduit-client/command-base/v1';
6
+ import type { LegacyExecuteOverrides } from './utils';
7
+ type LegacyGraphQLImperativeAdapterInvokeType<Config> = (config: Config, context: unknown, callback: (result: GraphQLResponse) => void) => void;
8
+ type LegacyGraphQLImperativeAdapterSubscribeType<Config> = (config: Config, context: unknown, callback: (result: GraphQLResponse) => void) => Unsubscribe;
9
+ export type LegacyGraphQLImperativeShape<Config> = {
10
+ invoke: LegacyGraphQLImperativeAdapterInvokeType<Config>;
11
+ subscribe: LegacyGraphQLImperativeAdapterSubscribeType<Config>;
12
+ };
13
+ export declare function buildAsyncGraphQLImperativeLegacyInvoker<Config>(getCommand: (options: {
14
+ config: Config;
15
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
16
+ }) => Command<ReturnType<GraphQLCommand['execute']>, [LegacyExecuteOverrides?]>): LegacyGraphQLImperativeShape<Config>;
17
+ export {};
@@ -0,0 +1,12 @@
1
+ import { Callback } from '@conduit-client/utils';
2
+ import { JSONSchema } from '@conduit-client/jsonschema-validate';
3
+ import { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
4
+ import { GraphQLCommand } from './graphql-utils';
5
+ export type SubscribableRefreshableGraphQLImperativeResult = Promise<GraphQLResponse & {
6
+ subscribe?: (cb: Callback<any>) => void;
7
+ refresh?: () => PromiseLike<void>;
8
+ }>;
9
+ export declare function buildAsyncGraphQLImperativeInvoker<Params extends Array<any>>(getCommand: (options: {
10
+ params: Params;
11
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
12
+ }) => GraphQLCommand, exposeRefresh?: boolean): (...params: Params) => SubscribableRefreshableGraphQLImperativeResult;
@@ -0,0 +1,10 @@
1
+ import { JSONSchema } from '@conduit-client/jsonschema-validate';
2
+ import { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
3
+ import { GraphQLCommand } from './graphql-utils';
4
+ import { type LegacyExecuteOverrides } from './utils';
5
+ import type { Command } from '@conduit-client/command-base/v1';
6
+ export type GraphQLMutationResult = Promise<GraphQLResponse>;
7
+ export declare function buildAsyncGraphQLMutationInvoker<Params extends Array<any>>(getCommand: (options: {
8
+ params: Params;
9
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
10
+ }) => Command<ReturnType<GraphQLCommand['execute']>, [LegacyExecuteOverrides?]>): (...params: Params) => GraphQLMutationResult;
@@ -0,0 +1,34 @@
1
+ import { SubscribableResultCommand } from './CommandWireAdapterConstructor';
2
+ import { IErrorWithData } from '@conduit-client/utils';
3
+ import { type GraphQLCommandError, type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
4
+ import { DocumentNode } from '@conduit-client/onestore-graphql-parser/v1';
5
+ export type GraphQLCommand = SubscribableResultCommand<GraphQLResponse, GraphQLCommandError>;
6
+ export declare class GraphQLCommandErrorWithData extends Error implements IErrorWithData<GraphQLResponse> {
7
+ data: GraphQLResponse;
8
+ constructor(data: GraphQLResponse);
9
+ }
10
+ export declare function throwGraphQLError(error: unknown): never;
11
+ /**
12
+ * Validates a GraphQL config and rejects operations not in the accepted list
13
+ * @param config The GraphQL config containing query and operationName
14
+ * @param options Options containing acceptedOperations array
15
+ * @throws Error if the executable operation is not in acceptedOperations
16
+ */
17
+ export declare function validateGraphQLOperations(config: {
18
+ query: DocumentNode;
19
+ operationName?: string;
20
+ }, options: {
21
+ acceptedOperations: ('query' | 'mutation' | 'subscription')[];
22
+ }): void;
23
+ export declare function resolveAst(ast: any): DocumentNode | undefined;
24
+ export declare function wrapConfigAndVerify(config: any, options?: {
25
+ acceptedOperations?: ('query' | 'mutation' | 'subscription')[];
26
+ }): any;
27
+ export declare function formatGraphQLData(data: GraphQLResponse): GraphQLResponse;
28
+ /**
29
+ * Maps a command failure (unknown or user-visible) into a GraphQLResponse suitable for consumers.
30
+ */
31
+ export declare function toGraphQLResponseFromFailure(failure: unknown): {
32
+ data: GraphQLResponse['data'];
33
+ errors: GraphQLResponse['errors'];
34
+ };
@@ -0,0 +1,10 @@
1
+ import { WireConfigValue, WireContextValue } from '@conduit-client/lwc-types';
2
+ import { CommandWireAdapterConstructor } from './CommandWireAdapterConstructor';
3
+ import { Result, SubscribableResult } from '@conduit-client/utils';
4
+ import { type GraphQLCommandError, type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
5
+ import { GraphQLCommand } from './graphql-utils';
6
+ export declare abstract class GraphQLCommandWireAdapterConstructor<Config extends WireConfigValue = WireConfigValue> extends CommandWireAdapterConstructor<GraphQLResponse, Config, GraphQLCommand> {
7
+ protected emit(result?: SubscribableResult<GraphQLResponse, GraphQLCommandError> | Result<GraphQLResponse, GraphQLCommandError> | undefined): void;
8
+ protected handleExecutionThrow(e: unknown): void;
9
+ update(config: Config, _context?: WireContextValue): void;
10
+ }
@@ -0,0 +1,90 @@
1
+ import { type JSONSchema } from '@conduit-client/jsonschema-validate';
2
+ import { type Command } from '@conduit-client/command-base/v1';
3
+ import type { SyncOrAsync, Result, SubscribableResult, Unsubscribe, Callback } from '@conduit-client/utils';
4
+ import type { LegacyExecuteOverrides } from './utils';
5
+ type MaybeSubscribableResultCommand<Data> = Command<SyncOrAsync<Result<Data, unknown> | SubscribableResult<Data, unknown>>>;
6
+ type SubscribableResultCommand<Data, Params extends Array<any> = []> = Command<SyncOrAsync<SubscribableResult<Data, unknown>>, Params>;
7
+ type ResultCommand<Data> = Command<SyncOrAsync<Result<Data, unknown>>>;
8
+ type ImperativeCommand<Data> = SubscribableResultCommand<Data> | ResultCommand<Data> | MaybeSubscribableResultCommand<Data>;
9
+ /**
10
+ * Returns an async function wrapper around an `ImperativeCommand`. Handles
11
+ * both subscribable and non-subscribable commands, but only returns regular data.
12
+ *
13
+ * @typeParam Params parameters accepted by the generated function
14
+ * @typeParam Config Command config type
15
+ * @typeParam Data data returned by the Command
16
+ * @param getCommand utility function that constructs an instance of the Command from
17
+ * the supplied parameters; the function should do any necessary parameter checking
18
+ * and throw errors as appropriate
19
+ * @returns A PromiseLike containing the result of command execution
20
+ */
21
+ export declare function buildAsyncImperativeInvoker<Params extends Array<any>, Data>(getCommand: (options: {
22
+ params: Params;
23
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
24
+ }) => ImperativeCommand<Data>): (...params: Params) => DefaultImperativeResult<Data>;
25
+ /**
26
+ * Returns an async function wrapper around a query `Command`. Handles
27
+ * both subscribable and non-subscribable commands, but only returns regular data.
28
+ *
29
+ * @typeParam Params parameters accepted by the generated function
30
+ * @typeParam Config Command config type
31
+ * @typeParam Data data returned by the Command
32
+ * @param getCommand utility function that constructs an instance of the Command from
33
+ * the supplied parameters; the function should do any necessary parameter checking
34
+ * and throw errors as appropriate
35
+ * @returns A PromiseLike containing the result of command execution
36
+ */
37
+ export declare function buildAsyncQueryImperativeInvoker<Params extends Array<any>, Data>(getCommand: (options: {
38
+ params: Params;
39
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
40
+ }) => ImperativeCommand<Data>): (...params: Params) => QueryImperativeResult<Data>;
41
+ export type DefaultImperativeResult<Data> = PromiseLike<Data>;
42
+ export type QueryImperativeResult<Data> = PromiseLike<{
43
+ data: Data;
44
+ }>;
45
+ export type SubscribableImperativeResult<Data> = PromiseLike<{
46
+ data: Data;
47
+ subscribe: (cb: Callback<any>) => void;
48
+ }>;
49
+ export type SubscribableRefreshableImperativeResult<Data> = PromiseLike<{
50
+ data: Data;
51
+ subscribe: (cb: Callback<any>) => void;
52
+ refresh: () => PromiseLike<void>;
53
+ }>;
54
+ export type MaybeRefreshableSubscribableImperativeResult<Data> = SubscribableImperativeResult<Data> | SubscribableRefreshableImperativeResult<Data>;
55
+ /**
56
+ * Returns an async function wrapper around an `ImperativeCommand`. Handles
57
+ * only subscribable commands and returns a subscribable result.
58
+ *
59
+ * @typeParam Params parameters accepted by the generated function
60
+ * @typeParam Config Command config type
61
+ * @typeParam Data data returned by the Command
62
+ * @param getCommand utility function that constructs an instance of the Command from
63
+ * the supplied parameters; the function should do any necessary parameter checking
64
+ * and throw errors as appropriate
65
+ * @param exposeRefresh whether to expose a `refresh` method on the result returned by
66
+ * the generated function. The default is `false`.
67
+ * @returns A PromiseLike containing the subscribable result of command execution
68
+ */
69
+ export declare function buildAsyncImperativeSubscribableInvoker<Params extends Array<any>, Data>(getCommand: (options: {
70
+ params: Params;
71
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
72
+ }) => ImperativeCommand<Data>, exposeRefresh?: boolean): (...params: Params) => MaybeRefreshableSubscribableImperativeResult<Data>;
73
+ type LegacyImperativeCallbackResult<Data> = {
74
+ data: Data;
75
+ error: undefined;
76
+ } | {
77
+ data: undefined;
78
+ error: Error;
79
+ };
80
+ type LegacyImperativeAdapterInvokeType<Config, Data> = (config: Config, context: unknown, callback: (result: LegacyImperativeCallbackResult<Data>) => void) => void;
81
+ type LegacyImperativeAdapterSubscribeType<Config, Data> = (config: Config, context: unknown, callback: (result: LegacyImperativeCallbackResult<Data>) => void) => Unsubscribe;
82
+ export type LegacyImperativeShape<Config, Data> = {
83
+ invoke: LegacyImperativeAdapterInvokeType<Config, Data>;
84
+ subscribe: LegacyImperativeAdapterSubscribeType<Config, Data>;
85
+ };
86
+ export declare function buildAsyncImperativeLegacyInvoker<Config, Data>(getCommand: (options: {
87
+ config: Config;
88
+ assertIsValid: <T>(data: unknown, schema: JSONSchema) => asserts data is T;
89
+ }) => SubscribableResultCommand<Data, [LegacyExecuteOverrides?]>): LegacyImperativeShape<Config, Data>;
90
+ export {};
@@ -0,0 +1,8 @@
1
+ export * from './CommandWireAdapterConstructor';
2
+ export * from './imperative';
3
+ export type { WireAdapterConstructor } from '@conduit-client/lwc-types';
4
+ export { GraphQLCommandWireAdapterConstructor } from './graphql-wire';
5
+ export { buildAsyncGraphQLImperativeInvoker, type SubscribableRefreshableGraphQLImperativeResult, } from './graphql-imperative';
6
+ export { buildAsyncGraphQLMutationInvoker, type GraphQLMutationResult } from './graphql-mutation';
7
+ export { buildAsyncGraphQLImperativeLegacyInvoker, type LegacyGraphQLImperativeShape, } from './graphql-imperative-legacy';
8
+ export { type GraphQLCommand, GraphQLCommandErrorWithData, throwGraphQLError, resolveAst, } from './graphql-utils';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns a sanitized version of an object by recursively unwrapping the Proxies.
3
+ *
4
+ * All the data coming from LWC-land need to be sanitized first.
5
+ */
6
+ export default function sanitize<T extends object>(obj: T): T;
@@ -0,0 +1,43 @@
1
+ import type { Callback, IInternalError, IUserVisibleError } from '@conduit-client/utils';
2
+ export declare function isInternalError<Data = undefined>(error: unknown): error is IInternalError<Data>;
3
+ export declare function isUserVisibleError<Data = undefined>(error: unknown): error is IUserVisibleError<Data>;
4
+ export declare function throwUserlandError(error: unknown): never;
5
+ export declare function emitError(callback: Callback<any>, error: unknown): void;
6
+ export declare function buildUserlandError(error: unknown): Error;
7
+ export declare function logError(error: unknown): void;
8
+ export declare const supportedCachePolicyTypes: readonly ["no-cache", "only-if-cached"];
9
+ export type SupportedCachePolicyType = (typeof supportedCachePolicyTypes)[number];
10
+ export type CachePolicy = {
11
+ cachePolicy: {
12
+ type: SupportedCachePolicyType;
13
+ };
14
+ };
15
+ /**
16
+ * Type guard for legacy requestContext objects used with imperative-legacy bindings.
17
+ *
18
+ * When this function returns true, it indicates the caller requested a supported
19
+ * cache policy override. Currently the only supported policy is `no-cache`.
20
+ *
21
+ * This helper is intentionally low-level; prefer using
22
+ * {@link getOverridesForLegacyRequestContext} at call sites to construct the
23
+ * proper `execute` overrides for Commands.
24
+ */
25
+ export declare function requestContextIsSupportedCachePolicy(requestContext: unknown): requestContext is CachePolicy;
26
+ export type LegacyExecuteOverrides = {
27
+ cacheControlConfig?: {
28
+ type: SupportedCachePolicyType;
29
+ };
30
+ };
31
+ /**
32
+ * Builds the `execute` overrides for legacy imperative invokers based on the
33
+ * provided requestContext. Encapsulates all hard-coded knowledge of supported
34
+ * cache policies for legacy adapters.
35
+ *
36
+ * - If {@link requestContextIsSupportedCachePolicy} matches `no-cache`, returns
37
+ * `{ cacheControlConfig: { type: 'no-cache' } }`.
38
+ * - Otherwise returns `{}`.
39
+ *
40
+ * Use this in `buildAsyncImperativeLegacyInvoker` and GraphQL legacy invokers
41
+ * to centralize override behavior.
42
+ */
43
+ export declare function getOverridesForLegacyRequestContext(requestContext: unknown): LegacyExecuteOverrides;
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@conduit-client/lwc-bindings",
3
+ "version": "5.67.0-dev1",
4
+ "private": false,
5
+ "description": "Luvio LWC Bindings",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/salesforce-experience-platform-emu/luvio-next.git",
10
+ "directory": "packages/@conduit-client/lwc-bindings"
11
+ },
12
+ "license": "SEE LICENSE IN LICENSE.txt",
13
+ "main": "dist/index.js",
14
+ "types": "dist/types/index.d.ts",
15
+ "files": [
16
+ "dist/"
17
+ ],
18
+ "scripts": {
19
+ "build": "vite build && tsc --build --emitDeclarationOnly",
20
+ "clean": "rm -rf dist",
21
+ "test": "vitest run",
22
+ "test:size": "size-limit",
23
+ "watch": "npm run build --watch"
24
+ },
25
+ "dependencies": {
26
+ "@conduit-client/command-base": "5.67.0-dev1",
27
+ "@conduit-client/jsonschema-validate": "5.67.0-dev1",
28
+ "@conduit-client/lwc-types": "5.67.0-dev1",
29
+ "@conduit-client/service-cache-control": "5.67.0-dev1",
30
+ "@conduit-client/utils": "5.67.0-dev1"
31
+ },
32
+ "devDependencies": {
33
+ "@conduit-client/command-cache-control": "5.67.0-dev1",
34
+ "@conduit-client/graphql-normalization": "5.67.0-dev1",
35
+ "@conduit-client/service-cache": "5.67.0-dev1",
36
+ "@conduit-client/service-pubsub": "5.67.0-dev1"
37
+ },
38
+ "volta": {
39
+ "extends": "../../../package.json"
40
+ },
41
+ "size-limit": [
42
+ {
43
+ "path": "./dist/index.js",
44
+ "limit": "4 kB"
45
+ }
46
+ ]
47
+ }