@conduit-client/generator-ts 3.8.0 → 3.10.0
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.
|
@@ -40,6 +40,8 @@ export declare class BindingsGenerator {
|
|
|
40
40
|
protected typeInvalidationDeclarationSymbol: symbol;
|
|
41
41
|
protected typeInvalidationDefinitionSymbol: symbol;
|
|
42
42
|
protected rootTypesInstantiationSymbol: symbol;
|
|
43
|
+
protected exportsTypeMembersSymbol: symbol;
|
|
44
|
+
protected exportsAssignmentsSymbol: symbol;
|
|
43
45
|
/**
|
|
44
46
|
* Template for generating the binding structure in the output file.
|
|
45
47
|
* Includes placeholders for adapter declarations, service requirements, and adapter invocations.
|
|
@@ -52,7 +54,8 @@ export declare class BindingsGenerator {
|
|
|
52
54
|
*
|
|
53
55
|
* @returns {Code[]} An array of code blocks forming the template for the binding output file.
|
|
54
56
|
*/
|
|
55
|
-
get
|
|
57
|
+
get coreTemplate(): (symbol | Code)[];
|
|
58
|
+
get wrapperTemplate(): Code[];
|
|
56
59
|
protected get serviceDependencies(): ServiceDependency[];
|
|
57
60
|
/**
|
|
58
61
|
* Builds the binding file, generating declarations, requirements, and invocations for each command model.
|
package/dist/v1/index.js
CHANGED
|
@@ -3003,6 +3003,11 @@ const WIRE_ADAPTER_CONSTRUCTOR$1 = {
|
|
|
3003
3003
|
exportedSymbol: "WireAdapterConstructor",
|
|
3004
3004
|
isType: true
|
|
3005
3005
|
};
|
|
3006
|
+
const WIRE_ADAPTER_RESULT = {
|
|
3007
|
+
module: "@conduit-client/service-bindings-lwc/v1",
|
|
3008
|
+
exportedSymbol: "WireAdapterResult",
|
|
3009
|
+
isType: true
|
|
3010
|
+
};
|
|
3006
3011
|
const LWC_WIRE_BINDINGS = "lwcWireBindings";
|
|
3007
3012
|
class WireAdapterBindingGenerator {
|
|
3008
3013
|
constructor(services, commandModel, binding) {
|
|
@@ -3032,7 +3037,7 @@ class WireAdapterBindingGenerator {
|
|
|
3032
3037
|
);
|
|
3033
3038
|
}
|
|
3034
3039
|
buildDeclaration() {
|
|
3035
|
-
return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR$1}<${this.commandConfigTypeImport}, ${this.responseTypeCode}
|
|
3040
|
+
return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR$1}<${this.commandConfigTypeImport}, ${WIRE_ADAPTER_RESULT}<${this.responseTypeCode}>, {}>;`;
|
|
3036
3041
|
}
|
|
3037
3042
|
get localCommandConstructorName() {
|
|
3038
3043
|
return `${this.binding.identifier}_ctor`;
|
|
@@ -3140,6 +3145,11 @@ const WIRE_ADAPTER_CONSTRUCTOR = {
|
|
|
3140
3145
|
exportedSymbol: "WireAdapterConstructor",
|
|
3141
3146
|
isType: true
|
|
3142
3147
|
};
|
|
3148
|
+
const GRAPHQL_WIRE_ADAPTER_RESULT = {
|
|
3149
|
+
module: "@conduit-client/service-bindings-lwc/v1",
|
|
3150
|
+
exportedSymbol: "GraphQLWireAdapterResult",
|
|
3151
|
+
isType: true
|
|
3152
|
+
};
|
|
3143
3153
|
const GRAPHQL_WIRE_BINDINGS = "lwcGraphQLWireBindings";
|
|
3144
3154
|
class GraphQLWireAdapterBindingGenerator {
|
|
3145
3155
|
constructor(services, commandModel, binding) {
|
|
@@ -3169,7 +3179,7 @@ class GraphQLWireAdapterBindingGenerator {
|
|
|
3169
3179
|
);
|
|
3170
3180
|
}
|
|
3171
3181
|
buildDeclaration() {
|
|
3172
|
-
return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR}<${this.commandConfigTypeImport}, ${
|
|
3182
|
+
return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR}<${this.commandConfigTypeImport}, ${GRAPHQL_WIRE_ADAPTER_RESULT}, {}>;`;
|
|
3173
3183
|
}
|
|
3174
3184
|
get localCommandConstructorName() {
|
|
3175
3185
|
return `${this.binding.identifier}_ctor`;
|
|
@@ -3266,8 +3276,14 @@ const OPTIONAL_SERVICE_REQUEST_TYPE = {
|
|
|
3266
3276
|
exportedSymbol: "OptionalServiceRequest",
|
|
3267
3277
|
isType: true
|
|
3268
3278
|
};
|
|
3269
|
-
const
|
|
3279
|
+
const REQUESTED_SERVICES_TYPE = {
|
|
3270
3280
|
module: "@conduit-client/service-provisioner/v1",
|
|
3281
|
+
exportedSymbol: "RequestedServices",
|
|
3282
|
+
isType: true
|
|
3283
|
+
};
|
|
3284
|
+
const INIT_BINDINGS_EXPORTS = {
|
|
3285
|
+
module: "@conduit-client/bindings-utils/v1",
|
|
3286
|
+
exportedSymbol: "initBindingsExports",
|
|
3271
3287
|
isType: false
|
|
3272
3288
|
};
|
|
3273
3289
|
const INSTRUMENT_COMMAND_DESCRIPTOR = {
|
|
@@ -3438,6 +3454,8 @@ class BindingsGenerator {
|
|
|
3438
3454
|
this.typeInvalidationDeclarationSymbol = Symbol.for("typeInvalidationDeclaration");
|
|
3439
3455
|
this.typeInvalidationDefinitionSymbol = Symbol.for("typeInvalidationDefinition");
|
|
3440
3456
|
this.rootTypesInstantiationSymbol = Symbol.for("rootTypesInstantiation");
|
|
3457
|
+
this.exportsTypeMembersSymbol = Symbol.for("exportsTypeMembers");
|
|
3458
|
+
this.exportsAssignmentsSymbol = Symbol.for("exportsAssignments");
|
|
3441
3459
|
}
|
|
3442
3460
|
/**
|
|
3443
3461
|
* Template for generating the binding structure in the output file.
|
|
@@ -3451,21 +3469,33 @@ class BindingsGenerator {
|
|
|
3451
3469
|
*
|
|
3452
3470
|
* @returns {Code[]} An array of code blocks forming the template for the binding output file.
|
|
3453
3471
|
*/
|
|
3454
|
-
get
|
|
3472
|
+
get coreTemplate() {
|
|
3455
3473
|
return [
|
|
3456
3474
|
this.bindingsServicesDeclarationSymbol,
|
|
3457
3475
|
this.adapterDeclarationSymbol,
|
|
3458
3476
|
this.typeInvalidationDeclarationSymbol,
|
|
3459
|
-
code`
|
|
3477
|
+
code`export type BindingsExports = {`,
|
|
3478
|
+
this.exportsTypeMembersSymbol,
|
|
3479
|
+
code`};`,
|
|
3480
|
+
code`export const exports = {} as BindingsExports;`,
|
|
3481
|
+
code`export const serviceRequirements=`,
|
|
3460
3482
|
this.serviceRequirementsSymbol,
|
|
3461
|
-
code
|
|
3462
|
-
code
|
|
3463
|
-
(services) => {`,
|
|
3483
|
+
code` as const;`,
|
|
3484
|
+
code`export function initGeneratedBindings(services: ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>, exports: BindingsExports) {`,
|
|
3464
3485
|
this.typeRegistryInstantiationSymbol,
|
|
3465
3486
|
this.rootTypesInstantiationSymbol,
|
|
3466
3487
|
this.typeInvalidationDefinitionSymbol,
|
|
3467
3488
|
this.adapterInvocationSymbol,
|
|
3468
|
-
|
|
3489
|
+
this.exportsAssignmentsSymbol,
|
|
3490
|
+
code`}`
|
|
3491
|
+
];
|
|
3492
|
+
}
|
|
3493
|
+
get wrapperTemplate() {
|
|
3494
|
+
return [
|
|
3495
|
+
code`export * from './bindings-core';`,
|
|
3496
|
+
code`import { exports, serviceRequirements, initGeneratedBindings } from './bindings-core';`,
|
|
3497
|
+
code`export const ready = ${INIT_BINDINGS_EXPORTS}({ serviceRequirements, exports, init: initGeneratedBindings }).ready;`,
|
|
3498
|
+
code`export default exports;`
|
|
3469
3499
|
];
|
|
3470
3500
|
}
|
|
3471
3501
|
get serviceDependencies() {
|
|
@@ -3593,20 +3623,23 @@ class BindingsGenerator {
|
|
|
3593
3623
|
* This method coordinates with individual binding generators to compile the necessary elements into a single file.
|
|
3594
3624
|
*/
|
|
3595
3625
|
build() {
|
|
3596
|
-
const
|
|
3597
|
-
const
|
|
3598
|
-
|
|
3626
|
+
const coreFilename = "artifacts/bindings-core.ts";
|
|
3627
|
+
const coreFile = this.services.file.build(coreFilename);
|
|
3628
|
+
coreFile.template = this.coreTemplate;
|
|
3629
|
+
const wrapperFilename = "artifacts/bindings.ts";
|
|
3630
|
+
const wrapperFile = this.services.file.build(wrapperFilename);
|
|
3631
|
+
wrapperFile.template = this.wrapperTemplate;
|
|
3599
3632
|
if (this.hasRESTNormalization) {
|
|
3600
3633
|
const { typeRegistryGenerator } = this.services;
|
|
3601
|
-
|
|
3634
|
+
coreFile.pushTo(
|
|
3602
3635
|
this.typeRegistryInstantiationSymbol,
|
|
3603
3636
|
code`const typeRegistry = new ${typeRegistryGenerator.build()}(services);`
|
|
3604
3637
|
);
|
|
3605
3638
|
const { declarations, definitions } = this.buildTypeInvalidation(
|
|
3606
3639
|
typeRegistryGenerator.invalidatableTypes
|
|
3607
3640
|
);
|
|
3608
|
-
|
|
3609
|
-
|
|
3641
|
+
coreFile.pushTo(this.typeInvalidationDeclarationSymbol, declarations);
|
|
3642
|
+
coreFile.pushTo(this.typeInvalidationDefinitionSymbol, definitions);
|
|
3610
3643
|
}
|
|
3611
3644
|
if (this.hasGraphQL) {
|
|
3612
3645
|
const { graphqlTypeRegistryGenerator } = this.services;
|
|
@@ -3628,13 +3661,13 @@ class BindingsGenerator {
|
|
|
3628
3661
|
schemaModel: firstGraphQLCommand.schema,
|
|
3629
3662
|
type: mutationTypeModel
|
|
3630
3663
|
}) : void 0;
|
|
3631
|
-
|
|
3664
|
+
coreFile.pushTo(
|
|
3632
3665
|
this.rootTypesInstantiationSymbol,
|
|
3633
3666
|
code`const graphqlTypeRegistry = new ${graphqlTypeRegistry}(services);
|
|
3634
3667
|
const ${QUERY_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${queryType.propertyName};`
|
|
3635
3668
|
);
|
|
3636
3669
|
if (mutationType) {
|
|
3637
|
-
|
|
3670
|
+
coreFile.pushTo(
|
|
3638
3671
|
this.rootTypesInstantiationSymbol,
|
|
3639
3672
|
code`const ${MUTATION_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${mutationType.propertyName};`
|
|
3640
3673
|
);
|
|
@@ -3646,10 +3679,10 @@ class BindingsGenerator {
|
|
|
3646
3679
|
})
|
|
3647
3680
|
);
|
|
3648
3681
|
bindingGenerators.forEach((generator) => {
|
|
3649
|
-
|
|
3682
|
+
coreFile.pushTo(this.adapterDeclarationSymbol, generator.buildDeclaration());
|
|
3650
3683
|
});
|
|
3651
|
-
|
|
3652
|
-
|
|
3684
|
+
coreFile.pushTo(this.serviceRequirementsSymbol, this.buildRequirements());
|
|
3685
|
+
coreFile.pushTo(
|
|
3653
3686
|
this.adapterInvocationSymbol,
|
|
3654
3687
|
Code.join(
|
|
3655
3688
|
bindingGenerators.flatMap((generator) => {
|
|
@@ -3665,6 +3698,35 @@ class BindingsGenerator {
|
|
|
3665
3698
|
""
|
|
3666
3699
|
)
|
|
3667
3700
|
);
|
|
3701
|
+
const exportNames = [
|
|
3702
|
+
...bindingGenerators.map((g) => {
|
|
3703
|
+
var _a;
|
|
3704
|
+
return (_a = g.binding) == null ? void 0 : _a.identifier;
|
|
3705
|
+
}).filter(Boolean)
|
|
3706
|
+
];
|
|
3707
|
+
if (this.hasRESTNormalization) {
|
|
3708
|
+
const { typeRegistryGenerator } = this.services;
|
|
3709
|
+
exportNames.push(
|
|
3710
|
+
...typeRegistryGenerator.invalidatableTypes.map(({ propertyName }) => {
|
|
3711
|
+
return `invalidate${toTypeScriptSafeIdentifier(propertyName)}`;
|
|
3712
|
+
})
|
|
3713
|
+
);
|
|
3714
|
+
}
|
|
3715
|
+
const uniqueExportNames = Array.from(new Set(exportNames));
|
|
3716
|
+
coreFile.pushTo(
|
|
3717
|
+
this.exportsTypeMembersSymbol,
|
|
3718
|
+
Code.join(
|
|
3719
|
+
uniqueExportNames.map((name) => code`${name}: typeof ${code`${name}`};`),
|
|
3720
|
+
"\n"
|
|
3721
|
+
)
|
|
3722
|
+
);
|
|
3723
|
+
coreFile.pushTo(
|
|
3724
|
+
this.exportsAssignmentsSymbol,
|
|
3725
|
+
Code.join(
|
|
3726
|
+
uniqueExportNames.map((name) => code`exports.${code`${name}`} = ${code`${name}`};`),
|
|
3727
|
+
"\n"
|
|
3728
|
+
)
|
|
3729
|
+
);
|
|
3668
3730
|
}
|
|
3669
3731
|
buildTypeInvalidation(typesWithNormalization) {
|
|
3670
3732
|
return typesWithNormalization.reduce(
|