@conduit-client/service-bindings-lwc 3.19.2 → 3.19.4
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.
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { type GraphQLCommandError, type GraphQLResponse, type GraphQLCommand } from '@conduit-client/graphql-normalization/v1';
|
|
2
|
-
import { type JSONSchema } from '@conduit-client/jsonschema-validate';
|
|
2
|
+
import { type JsonSchemaViolationError, type JSONSchema } from '@conduit-client/jsonschema-validate';
|
|
3
3
|
import { type WireAdapterConstructor, type WireConfigValue, type WireContextValue, type GraphQLWireAdapterResult } from '@conduit-client/lwc-types';
|
|
4
4
|
import { CommandWireAdapterConstructor, type GetCommand } from './utils';
|
|
5
5
|
import type { Result, ServiceDescriptor, SubscribableResult, NamedService } from '@conduit-client/utils';
|
|
6
6
|
export declare abstract class GraphQLCommandWireAdapterConstructor<Config extends WireConfigValue = WireConfigValue> extends CommandWireAdapterConstructor<GraphQLResponse, Config, GraphQLCommand> {
|
|
7
7
|
protected emit(result?: SubscribableResult<GraphQLResponse, GraphQLCommandError> | Result<GraphQLResponse, GraphQLCommandError> | undefined): void;
|
|
8
|
-
protected handleExecutionThrow(
|
|
8
|
+
protected handleExecutionThrow(error: unknown): void;
|
|
9
|
+
protected handleConfigSchemaViolation(error: JsonSchemaViolationError): void;
|
|
9
10
|
update(config: Config, _context?: WireContextValue): void;
|
|
10
11
|
}
|
|
11
12
|
export declare class LWCGraphQLWireBindingsService {
|
package/dist/types/v1/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type JSONSchema } from '@conduit-client/jsonschema-validate';
|
|
1
|
+
import { type JSONSchema, JsonSchemaViolationError } from '@conduit-client/jsonschema-validate';
|
|
2
2
|
import { type WireAdapter, type WireConfigValue, type WireContextValue, type WireDataCallback } from '@conduit-client/lwc-types';
|
|
3
3
|
import { type SyncOrAsync, type Unsubscribe, type SubscribableResult, type CommandError, type Result } from '@conduit-client/utils';
|
|
4
4
|
import { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';
|
|
@@ -30,6 +30,14 @@ export declare abstract class CommandWireAdapterConstructor<Data, Config extends
|
|
|
30
30
|
protected emit(result?: Result<Data, unknown> | SubscribableResult<Data, unknown>): void;
|
|
31
31
|
protected invokeAdapter(): void;
|
|
32
32
|
protected handleExecutionThrow(error: unknown): void;
|
|
33
|
+
/**
|
|
34
|
+
* Hook for subclasses to handle a JsonSchemaViolationError from the config
|
|
35
|
+
* schema assertion. The default re-throws so legacy non-GraphQL wire
|
|
36
|
+
* adapters keep their existing throw behavior. Overrides are expected to
|
|
37
|
+
* either emit an error result or re-throw — silently returning will
|
|
38
|
+
* swallow the error.
|
|
39
|
+
*/
|
|
40
|
+
protected handleConfigSchemaViolation(error: JsonSchemaViolationError): void;
|
|
33
41
|
protected unsubscribe(): void;
|
|
34
42
|
}
|
|
35
43
|
/**
|
package/dist/v1/index.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* For full license text, see the LICENSE.txt file
|
|
5
5
|
*/
|
|
6
6
|
import { emitError } from "@conduit-client/bindings-utils/v1";
|
|
7
|
-
import { assertIsValid,
|
|
7
|
+
import { assertIsValid, JsonSchemaViolationError, MissingRequiredPropertyError } from "@conduit-client/jsonschema-validate";
|
|
8
8
|
import { isSubscribableResult, deepFreeze, ok, isUserVisibleError, logError } from "@conduit-client/utils";
|
|
9
|
-
import { resolveAndValidateGraphQLConfig } from "@conduit-client/onestore-graphql-parser/v1";
|
|
9
|
+
import { toGraphQLErrorResponse, resolveAndValidateGraphQLConfig } from "@conduit-client/onestore-graphql-parser/v1";
|
|
10
10
|
class Sanitizer {
|
|
11
11
|
constructor(obj) {
|
|
12
12
|
this.obj = obj;
|
|
@@ -149,6 +149,10 @@ class CommandWireAdapterConstructor {
|
|
|
149
149
|
if (isIncompleteConfigError(err)) {
|
|
150
150
|
return;
|
|
151
151
|
}
|
|
152
|
+
if (err instanceof JsonSchemaViolationError) {
|
|
153
|
+
this.handleConfigSchemaViolation(err);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
152
156
|
throw err;
|
|
153
157
|
}
|
|
154
158
|
}
|
|
@@ -201,6 +205,16 @@ class CommandWireAdapterConstructor {
|
|
|
201
205
|
handleExecutionThrow(error) {
|
|
202
206
|
emitError(this.callback, error);
|
|
203
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Hook for subclasses to handle a JsonSchemaViolationError from the config
|
|
210
|
+
* schema assertion. The default re-throws so legacy non-GraphQL wire
|
|
211
|
+
* adapters keep their existing throw behavior. Overrides are expected to
|
|
212
|
+
* either emit an error result or re-throw — silently returning will
|
|
213
|
+
* swallow the error.
|
|
214
|
+
*/
|
|
215
|
+
handleConfigSchemaViolation(error) {
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
204
218
|
unsubscribe() {
|
|
205
219
|
if (this.unsubscriber) {
|
|
206
220
|
this.unsubscriber();
|
|
@@ -293,16 +307,14 @@ class GraphQLCommandWireAdapterConstructor extends CommandWireAdapterConstructor
|
|
|
293
307
|
this.callback(consumerEmittedData);
|
|
294
308
|
}
|
|
295
309
|
} catch (e) {
|
|
296
|
-
logError(e);
|
|
297
310
|
this.handleExecutionThrow(e);
|
|
298
311
|
}
|
|
299
312
|
}
|
|
300
|
-
handleExecutionThrow(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
});
|
|
313
|
+
handleExecutionThrow(error) {
|
|
314
|
+
this.callback(toGraphQLErrorResponse(error));
|
|
315
|
+
}
|
|
316
|
+
handleConfigSchemaViolation(error) {
|
|
317
|
+
this.handleExecutionThrow(error);
|
|
306
318
|
}
|
|
307
319
|
update(config, _context) {
|
|
308
320
|
this.unsubscribe();
|
package/dist/v1/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/v1/sanitize.ts","../../src/v1/utils.ts","../../src/v1/wire.ts","../../src/v1/graphql-wire.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 { emitError } from '@conduit-client/bindings-utils/v1';\nimport {\n assertIsValid,\n MissingRequiredPropertyError,\n type JSONSchema,\n JsonSchemaViolationError,\n} from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapter,\n type WireConfigValue,\n type WireContextValue,\n type WireDataCallback,\n} from '@conduit-client/lwc-types';\n\nimport {\n type SyncOrAsync,\n type Unsubscribe,\n type SubscribableResult,\n type CommandError,\n deepFreeze,\n type Result,\n ok,\n isSubscribableResult,\n logError,\n isUserVisibleError,\n} from '@conduit-client/utils';\nimport { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';\nimport sanitize from './sanitize';\nimport type {\n SubscribableResultCommand,\n ResultCommand,\n MaybeSubscribableResultCommand,\n} from '@conduit-client/bindings-utils/v1';\n\nexport type WireAdapterCompatibleCommand<Data, Error> =\n | SubscribableResultCommand<Data, Error>\n | ResultCommand<Data, Error>\n | MaybeSubscribableResultCommand<Data, Error>;\n\nexport function 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\nexport type GetCommand<\n Data,\n Config extends WireConfigValue = WireConfigValue,\n CommandType extends WireAdapterCompatibleCommand<\n Data,\n CommandError\n > = WireAdapterCompatibleCommand<Data, CommandError>,\n> = (condig: Config) => CommandType;\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\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 { type JSONSchema } from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapterConstructor,\n type WireAdapterResult,\n type WireConfigValue,\n} from '@conduit-client/lwc-types';\nimport { CommandWireAdapterConstructor, type GetCommand } from './utils';\nimport type { NamedService, ServiceDescriptor } from '@conduit-client/utils';\n\nexport class LWCWireBindingsService {\n bind<Data, Config extends WireConfigValue = WireConfigValue>(\n getCommand: GetCommand<Data, Config>,\n configSchema?: JSONSchema,\n exposeRefresh = false\n ): WireAdapterConstructor<Config, WireAdapterResult<Data>, {}> {\n return class extends CommandWireAdapterConstructor<Data, Config> {\n configSchema = configSchema;\n exposeRefresh = exposeRefresh;\n getCommand() {\n return getCommand(this.config!);\n }\n };\n }\n}\n\nexport type LWCWireBindingsServiceDescriptor = ServiceDescriptor<\n LWCWireBindingsService,\n 'lwcWireBindings',\n '1.0'\n>;\n\nexport type NamedLWCWireBindingsService<Name extends string = 'lwcWireBindings'> = NamedService<\n Name,\n LWCWireBindingsService\n>;\n\nexport function buildServiceDescriptor(): LWCWireBindingsServiceDescriptor {\n return {\n type: 'lwcWireBindings',\n version: '1.0',\n service: new LWCWireBindingsService(),\n };\n}\n","import {\n deepFreeze,\n isSubscribableResult,\n logError,\n isUserVisibleError,\n} from '@conduit-client/utils';\nimport {\n type GraphQLCommandError,\n type GraphQLResponse,\n type GraphQLCommand,\n} from '@conduit-client/graphql-normalization/v1';\nimport {\n type ResolveAndValidateOptions,\n resolveAndValidateGraphQLConfig,\n} from '@conduit-client/onestore-graphql-parser/v1';\nimport { type JSONSchema } from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapterConstructor,\n type WireConfigValue,\n type WireContextValue,\n type GraphQLWireAdapterResult,\n} from '@conduit-client/lwc-types';\nimport {\n CommandWireAdapterConstructor,\n type GetCommand,\n toGraphQLResponseFromFailure,\n} from './utils';\nimport sanitize from './sanitize';\nimport type {\n Result,\n ServiceDescriptor,\n SubscribableResult,\n NamedService,\n} from '@conduit-client/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 return;\n }\n\n if (isUserVisibleError(res.error)) {\n resolve();\n return;\n }\n\n reject(\n new Error(\n 'Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data'\n )\n );\n });\n });\n };\n\n let consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse['data'];\n errors: GraphQLResponse['errors'];\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 // Centralized parsing error handling (handles null/undefined query)\n const options: ResolveAndValidateOptions = {\n acceptedOperations: ['query'],\n };\n const result = resolveAndValidateGraphQLConfig(config, options);\n\n if (!result) {\n return;\n }\n\n if (result.isErr()) {\n const error = result.error;\n // Emit error response for actual parsing errors\n this.callback({\n data: undefined,\n errors: error.errors,\n } satisfies GraphQLResponse);\n return;\n }\n\n // Sanitize everything except query (DocumentNode must not be sanitized for AST resolution)\n const { query, ...rest } = result.value;\n this.config = {\n query,\n ...sanitize(rest),\n } as unknown as Config;\n this.invokeAdapter();\n }\n}\n\nexport class LWCGraphQLWireBindingsService {\n bind<Config extends WireConfigValue = WireConfigValue>(\n getCommand: GetCommand<GraphQLResponse, Config, GraphQLCommand>,\n configSchema?: JSONSchema,\n exposeRefresh = false\n ): WireAdapterConstructor<Config, GraphQLWireAdapterResult, {}> {\n return class extends GraphQLCommandWireAdapterConstructor<Config> {\n configSchema = configSchema;\n exposeRefresh = exposeRefresh;\n getCommand() {\n return getCommand(this.config!);\n }\n };\n }\n}\n\nexport type LWCGraphQLWireBindingsServiceDescriptor = ServiceDescriptor<\n LWCGraphQLWireBindingsService,\n 'lwcGraphQLWireBindings',\n '1.0'\n>;\n\nexport type NamedLWCGraphQLWireBindingsService<Name extends string = 'lwcGraphQLWireBindings'> =\n NamedService<Name, LWCGraphQLWireBindingsService>;\n\nexport function buildServiceDescriptor(): LWCGraphQLWireBindingsServiceDescriptor {\n return {\n type: 'lwcGraphQLWireBindings',\n version: '1.0',\n service: new LWCGraphQLWireBindingsService(),\n };\n}\n"],"names":["buildServiceDescriptor"],"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;AAElB,SAAK,UAAU,KAAK,KAAK,SAAU,KAAK,OAAO;AAC3C,UAAI,QAAQ,IAAI;AACZ,eAAO;AAAA,MACX;AAEA,YAAM,SAAS;AACf,UAAI,WAAW,UAAU,YAAY,OAAO;AACxC,kBAAU,KAAK,MAAM;AAAA,MACzB;AACA,UAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC7C,kBAAU,MAAM,KAAK,KAAK;AAC1B,eAAO;AAAA,MACX;AACA,gBAAU,YAAY,KAAK,GAAG,IAAI;AAElC,aAAO;AAAA,IACX,CAAC;AAED,WAAO,KAAK;AAAA,EAChB;AAAA,EAEQ,MAAM,KAAa,OAAY;AACnC,UAAM,EAAE,aAAa,WAAA,IAAe;AACpC,UAAM,OAAQ,WAAW,KAAK,GAAG,IAAI,MAAM,QAAQ,KAAK,IAAI,CAAA,IAAK,CAAA;AACjE,SAAK,cAAc;AAAA,MACf;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,MACR;AAAA,IAAA;AAAA,EAER;AAAA,EAEQ,KAAK,QAAa;AACtB,WAAO,KAAK,YAAY,UAAU,QAAQ;AACtC,WAAK,cAAc,KAAK,YAAY,UAAU,KAAK;AAAA,IACvD;AAAA,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;AAAA,IACN,SAAS;AAAA,IACT,SAAS,IAAI,8BAAA;AAAA,EAA8B;AAEnD;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/v1/sanitize.ts","../../src/v1/utils.ts","../../src/v1/wire.ts","../../src/v1/graphql-wire.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 { emitError } from '@conduit-client/bindings-utils/v1';\nimport {\n assertIsValid,\n MissingRequiredPropertyError,\n type JSONSchema,\n JsonSchemaViolationError,\n} from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapter,\n type WireConfigValue,\n type WireContextValue,\n type WireDataCallback,\n} from '@conduit-client/lwc-types';\n\nimport {\n type SyncOrAsync,\n type Unsubscribe,\n type SubscribableResult,\n type CommandError,\n deepFreeze,\n type Result,\n ok,\n isSubscribableResult,\n logError,\n isUserVisibleError,\n} from '@conduit-client/utils';\nimport { type GraphQLResponse } from '@conduit-client/graphql-normalization/v1';\nimport sanitize from './sanitize';\nimport type {\n SubscribableResultCommand,\n ResultCommand,\n MaybeSubscribableResultCommand,\n} from '@conduit-client/bindings-utils/v1';\n\nexport type WireAdapterCompatibleCommand<Data, Error> =\n | SubscribableResultCommand<Data, Error>\n | ResultCommand<Data, Error>\n | MaybeSubscribableResultCommand<Data, Error>;\n\nexport function 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\nexport type GetCommand<\n Data,\n Config extends WireConfigValue = WireConfigValue,\n CommandType extends WireAdapterCompatibleCommand<\n Data,\n CommandError\n > = WireAdapterCompatibleCommand<Data, CommandError>,\n> = (condig: Config) => CommandType;\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 if (err instanceof JsonSchemaViolationError) {\n this.handleConfigSchemaViolation(err);\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 /**\n * Hook for subclasses to handle a JsonSchemaViolationError from the config\n * schema assertion. The default re-throws so legacy non-GraphQL wire\n * adapters keep their existing throw behavior. Overrides are expected to\n * either emit an error result or re-throw — silently returning will\n * swallow the error.\n */\n protected handleConfigSchemaViolation(error: JsonSchemaViolationError): void {\n throw error;\n }\n\n protected unsubscribe() {\n if (this.unsubscriber) {\n this.unsubscriber();\n delete this.unsubscriber;\n }\n }\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 { type JSONSchema } from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapterConstructor,\n type WireAdapterResult,\n type WireConfigValue,\n} from '@conduit-client/lwc-types';\nimport { CommandWireAdapterConstructor, type GetCommand } from './utils';\nimport type { NamedService, ServiceDescriptor } from '@conduit-client/utils';\n\nexport class LWCWireBindingsService {\n bind<Data, Config extends WireConfigValue = WireConfigValue>(\n getCommand: GetCommand<Data, Config>,\n configSchema?: JSONSchema,\n exposeRefresh = false\n ): WireAdapterConstructor<Config, WireAdapterResult<Data>, {}> {\n return class extends CommandWireAdapterConstructor<Data, Config> {\n configSchema = configSchema;\n exposeRefresh = exposeRefresh;\n getCommand() {\n return getCommand(this.config!);\n }\n };\n }\n}\n\nexport type LWCWireBindingsServiceDescriptor = ServiceDescriptor<\n LWCWireBindingsService,\n 'lwcWireBindings',\n '1.0'\n>;\n\nexport type NamedLWCWireBindingsService<Name extends string = 'lwcWireBindings'> = NamedService<\n Name,\n LWCWireBindingsService\n>;\n\nexport function buildServiceDescriptor(): LWCWireBindingsServiceDescriptor {\n return {\n type: 'lwcWireBindings',\n version: '1.0',\n service: new LWCWireBindingsService(),\n };\n}\n","import { deepFreeze, isSubscribableResult, isUserVisibleError } from '@conduit-client/utils';\nimport {\n type GraphQLCommandError,\n type GraphQLResponse,\n type GraphQLCommand,\n} from '@conduit-client/graphql-normalization/v1';\nimport {\n type ResolveAndValidateOptions,\n resolveAndValidateGraphQLConfig,\n toGraphQLErrorResponse,\n} from '@conduit-client/onestore-graphql-parser/v1';\nimport {\n type JsonSchemaViolationError,\n type JSONSchema,\n} from '@conduit-client/jsonschema-validate';\nimport {\n type WireAdapterConstructor,\n type WireConfigValue,\n type WireContextValue,\n type GraphQLWireAdapterResult,\n} from '@conduit-client/lwc-types';\nimport {\n CommandWireAdapterConstructor,\n type GetCommand,\n toGraphQLResponseFromFailure,\n} from './utils';\nimport sanitize from './sanitize';\nimport type {\n Result,\n ServiceDescriptor,\n SubscribableResult,\n NamedService,\n} from '@conduit-client/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 return;\n }\n\n if (isUserVisibleError(res.error)) {\n resolve();\n return;\n }\n\n reject(\n new Error(\n 'Internal error in GraphQL adapter occurred: Failed to refresh GraphQL data'\n )\n );\n });\n });\n };\n\n let consumerEmittedData = {\n data: undefined,\n errors: undefined,\n } as {\n data: GraphQLResponse['data'];\n errors: GraphQLResponse['errors'];\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 this.handleExecutionThrow(e);\n }\n }\n\n protected handleExecutionThrow(error: unknown): void {\n this.callback(toGraphQLErrorResponse(error));\n }\n\n protected handleConfigSchemaViolation(error: JsonSchemaViolationError): void {\n this.handleExecutionThrow(error);\n }\n\n update(config: Config, _context?: WireContextValue): void {\n this.unsubscribe();\n\n // Centralized parsing error handling (handles null/undefined query)\n const options: ResolveAndValidateOptions = {\n acceptedOperations: ['query'],\n };\n const result = resolveAndValidateGraphQLConfig(config, options);\n\n if (!result) {\n return;\n }\n\n if (result.isErr()) {\n const error = result.error;\n // Emit error response for actual parsing errors\n this.callback({\n data: undefined,\n errors: error.errors,\n } satisfies GraphQLResponse);\n return;\n }\n\n // Sanitize everything except query (DocumentNode must not be sanitized for AST resolution)\n const { query, ...rest } = result.value;\n this.config = {\n query,\n ...sanitize(rest),\n } as unknown as Config;\n this.invokeAdapter();\n }\n}\n\nexport class LWCGraphQLWireBindingsService {\n bind<Config extends WireConfigValue = WireConfigValue>(\n getCommand: GetCommand<GraphQLResponse, Config, GraphQLCommand>,\n configSchema?: JSONSchema,\n exposeRefresh = false\n ): WireAdapterConstructor<Config, GraphQLWireAdapterResult, {}> {\n return class extends GraphQLCommandWireAdapterConstructor<Config> {\n configSchema = configSchema;\n exposeRefresh = exposeRefresh;\n getCommand() {\n return getCommand(this.config!);\n }\n };\n }\n}\n\nexport type LWCGraphQLWireBindingsServiceDescriptor = ServiceDescriptor<\n LWCGraphQLWireBindingsService,\n 'lwcGraphQLWireBindings',\n '1.0'\n>;\n\nexport type NamedLWCGraphQLWireBindingsService<Name extends string = 'lwcGraphQLWireBindings'> =\n NamedService<Name, LWCGraphQLWireBindingsService>;\n\nexport function buildServiceDescriptor(): LWCGraphQLWireBindingsServiceDescriptor {\n return {\n type: 'lwcGraphQLWireBindings',\n version: '1.0',\n service: new LWCGraphQLWireBindingsService(),\n };\n}\n"],"names":["buildServiceDescriptor"],"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;AAElB,SAAK,UAAU,KAAK,KAAK,SAAU,KAAK,OAAO;AAC3C,UAAI,QAAQ,IAAI;AACZ,eAAO;AAAA,MACX;AAEA,YAAM,SAAS;AACf,UAAI,WAAW,UAAU,YAAY,OAAO;AACxC,kBAAU,KAAK,MAAM;AAAA,MACzB;AACA,UAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC7C,kBAAU,MAAM,KAAK,KAAK;AAC1B,eAAO;AAAA,MACX;AACA,gBAAU,YAAY,KAAK,GAAG,IAAI;A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,MAAM;AAAA,QACN,QAAQ,MAAM;AAAA,MAAA,CACS;AAC3B;AAAA,IACJ;AAGA,UAAM,EAAE,OAAO,GAAG,KAAA,IAAS,OAAO;AAClC,SAAK,SAAS;AAAA,MACV;AAAA,MACA,GAAG,SAAS,IAAI;AAAA,IAAA;AAEpB,SAAK,cAAA;AAAA,EACT;AACJ;AAEO,MAAM,8BAA8B;AAAA,EACvC,KACI,YACA,cACA,gBAAgB,OAC4C;AAC5D,WAAO,cAAc,qCAA6C;AAAA,MAA3D,cAAA;AAAA,cAAA,GAAA,SAAA;AACH,aAAA,eAAe;AACf,aAAA,gBAAgB;AAAA,MAAA;AAAA,MAChB,aAAa;AACT,eAAO,WAAW,KAAK,MAAO;AAAA,MAClC;AAAA,IAAA;AAAA,EAER;AACJ;AAWO,SAAS,yBAAkE;AAC9E,SAAO;AAAA,IACH,MAAM;AAAA,IACN,SAAS;AAAA,IACT,SAAS,IAAI,8BAAA;AAAA,EAA8B;AAEnD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@conduit-client/service-bindings-lwc",
|
|
3
|
-
"version": "3.19.
|
|
3
|
+
"version": "3.19.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Conduit services for LWC bindings",
|
|
6
6
|
"type": "module",
|
|
@@ -31,14 +31,14 @@
|
|
|
31
31
|
"watch": "npm run build --watch"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@conduit-client/bindings-utils": "3.19.
|
|
35
|
-
"@conduit-client/jsonschema-validate": "3.19.
|
|
36
|
-
"@conduit-client/onestore-graphql-parser": "3.19.
|
|
37
|
-
"@conduit-client/utils": "3.19.
|
|
34
|
+
"@conduit-client/bindings-utils": "3.19.4",
|
|
35
|
+
"@conduit-client/jsonschema-validate": "3.19.4",
|
|
36
|
+
"@conduit-client/onestore-graphql-parser": "3.19.4",
|
|
37
|
+
"@conduit-client/utils": "3.19.4"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@conduit-client/graphql-normalization": "3.19.
|
|
41
|
-
"@conduit-client/lwc-types": "3.19.
|
|
40
|
+
"@conduit-client/graphql-normalization": "3.19.4",
|
|
41
|
+
"@conduit-client/lwc-types": "3.19.4"
|
|
42
42
|
},
|
|
43
43
|
"volta": {
|
|
44
44
|
"extends": "../../../../package.json"
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"size-limit": [
|
|
47
47
|
{
|
|
48
48
|
"path": "./dist/v1/index.js",
|
|
49
|
-
"limit": "2 kB"
|
|
49
|
+
"limit": "2.05 kB"
|
|
50
50
|
}
|
|
51
51
|
]
|
|
52
52
|
}
|