@conduit-client/generator-ts 3.8.0 → 3.9.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
|
@@ -3266,8 +3266,14 @@ const OPTIONAL_SERVICE_REQUEST_TYPE = {
|
|
|
3266
3266
|
exportedSymbol: "OptionalServiceRequest",
|
|
3267
3267
|
isType: true
|
|
3268
3268
|
};
|
|
3269
|
-
const
|
|
3269
|
+
const REQUESTED_SERVICES_TYPE = {
|
|
3270
3270
|
module: "@conduit-client/service-provisioner/v1",
|
|
3271
|
+
exportedSymbol: "RequestedServices",
|
|
3272
|
+
isType: true
|
|
3273
|
+
};
|
|
3274
|
+
const INIT_BINDINGS_EXPORTS = {
|
|
3275
|
+
module: "@conduit-client/bindings-utils/v1",
|
|
3276
|
+
exportedSymbol: "initBindingsExports",
|
|
3271
3277
|
isType: false
|
|
3272
3278
|
};
|
|
3273
3279
|
const INSTRUMENT_COMMAND_DESCRIPTOR = {
|
|
@@ -3438,6 +3444,8 @@ class BindingsGenerator {
|
|
|
3438
3444
|
this.typeInvalidationDeclarationSymbol = Symbol.for("typeInvalidationDeclaration");
|
|
3439
3445
|
this.typeInvalidationDefinitionSymbol = Symbol.for("typeInvalidationDefinition");
|
|
3440
3446
|
this.rootTypesInstantiationSymbol = Symbol.for("rootTypesInstantiation");
|
|
3447
|
+
this.exportsTypeMembersSymbol = Symbol.for("exportsTypeMembers");
|
|
3448
|
+
this.exportsAssignmentsSymbol = Symbol.for("exportsAssignments");
|
|
3441
3449
|
}
|
|
3442
3450
|
/**
|
|
3443
3451
|
* Template for generating the binding structure in the output file.
|
|
@@ -3451,21 +3459,33 @@ class BindingsGenerator {
|
|
|
3451
3459
|
*
|
|
3452
3460
|
* @returns {Code[]} An array of code blocks forming the template for the binding output file.
|
|
3453
3461
|
*/
|
|
3454
|
-
get
|
|
3462
|
+
get coreTemplate() {
|
|
3455
3463
|
return [
|
|
3456
3464
|
this.bindingsServicesDeclarationSymbol,
|
|
3457
3465
|
this.adapterDeclarationSymbol,
|
|
3458
3466
|
this.typeInvalidationDeclarationSymbol,
|
|
3459
|
-
code`
|
|
3467
|
+
code`export type BindingsExports = {`,
|
|
3468
|
+
this.exportsTypeMembersSymbol,
|
|
3469
|
+
code`};`,
|
|
3470
|
+
code`export const exports = {} as BindingsExports;`,
|
|
3471
|
+
code`export const serviceRequirements=`,
|
|
3460
3472
|
this.serviceRequirementsSymbol,
|
|
3461
|
-
code
|
|
3462
|
-
code
|
|
3463
|
-
(services) => {`,
|
|
3473
|
+
code` as const;`,
|
|
3474
|
+
code`export function initGeneratedBindings(services: ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>, exports: BindingsExports) {`,
|
|
3464
3475
|
this.typeRegistryInstantiationSymbol,
|
|
3465
3476
|
this.rootTypesInstantiationSymbol,
|
|
3466
3477
|
this.typeInvalidationDefinitionSymbol,
|
|
3467
3478
|
this.adapterInvocationSymbol,
|
|
3468
|
-
|
|
3479
|
+
this.exportsAssignmentsSymbol,
|
|
3480
|
+
code`}`
|
|
3481
|
+
];
|
|
3482
|
+
}
|
|
3483
|
+
get wrapperTemplate() {
|
|
3484
|
+
return [
|
|
3485
|
+
code`export * from './bindings-core';`,
|
|
3486
|
+
code`import { exports, serviceRequirements, initGeneratedBindings } from './bindings-core';`,
|
|
3487
|
+
code`export const ready = ${INIT_BINDINGS_EXPORTS}({ serviceRequirements, exports, init: initGeneratedBindings }).ready;`,
|
|
3488
|
+
code`export default exports;`
|
|
3469
3489
|
];
|
|
3470
3490
|
}
|
|
3471
3491
|
get serviceDependencies() {
|
|
@@ -3593,20 +3613,23 @@ class BindingsGenerator {
|
|
|
3593
3613
|
* This method coordinates with individual binding generators to compile the necessary elements into a single file.
|
|
3594
3614
|
*/
|
|
3595
3615
|
build() {
|
|
3596
|
-
const
|
|
3597
|
-
const
|
|
3598
|
-
|
|
3616
|
+
const coreFilename = "artifacts/bindings-core.ts";
|
|
3617
|
+
const coreFile = this.services.file.build(coreFilename);
|
|
3618
|
+
coreFile.template = this.coreTemplate;
|
|
3619
|
+
const wrapperFilename = "artifacts/bindings.ts";
|
|
3620
|
+
const wrapperFile = this.services.file.build(wrapperFilename);
|
|
3621
|
+
wrapperFile.template = this.wrapperTemplate;
|
|
3599
3622
|
if (this.hasRESTNormalization) {
|
|
3600
3623
|
const { typeRegistryGenerator } = this.services;
|
|
3601
|
-
|
|
3624
|
+
coreFile.pushTo(
|
|
3602
3625
|
this.typeRegistryInstantiationSymbol,
|
|
3603
3626
|
code`const typeRegistry = new ${typeRegistryGenerator.build()}(services);`
|
|
3604
3627
|
);
|
|
3605
3628
|
const { declarations, definitions } = this.buildTypeInvalidation(
|
|
3606
3629
|
typeRegistryGenerator.invalidatableTypes
|
|
3607
3630
|
);
|
|
3608
|
-
|
|
3609
|
-
|
|
3631
|
+
coreFile.pushTo(this.typeInvalidationDeclarationSymbol, declarations);
|
|
3632
|
+
coreFile.pushTo(this.typeInvalidationDefinitionSymbol, definitions);
|
|
3610
3633
|
}
|
|
3611
3634
|
if (this.hasGraphQL) {
|
|
3612
3635
|
const { graphqlTypeRegistryGenerator } = this.services;
|
|
@@ -3628,13 +3651,13 @@ class BindingsGenerator {
|
|
|
3628
3651
|
schemaModel: firstGraphQLCommand.schema,
|
|
3629
3652
|
type: mutationTypeModel
|
|
3630
3653
|
}) : void 0;
|
|
3631
|
-
|
|
3654
|
+
coreFile.pushTo(
|
|
3632
3655
|
this.rootTypesInstantiationSymbol,
|
|
3633
3656
|
code`const graphqlTypeRegistry = new ${graphqlTypeRegistry}(services);
|
|
3634
3657
|
const ${QUERY_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${queryType.propertyName};`
|
|
3635
3658
|
);
|
|
3636
3659
|
if (mutationType) {
|
|
3637
|
-
|
|
3660
|
+
coreFile.pushTo(
|
|
3638
3661
|
this.rootTypesInstantiationSymbol,
|
|
3639
3662
|
code`const ${MUTATION_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${mutationType.propertyName};`
|
|
3640
3663
|
);
|
|
@@ -3646,10 +3669,10 @@ class BindingsGenerator {
|
|
|
3646
3669
|
})
|
|
3647
3670
|
);
|
|
3648
3671
|
bindingGenerators.forEach((generator) => {
|
|
3649
|
-
|
|
3672
|
+
coreFile.pushTo(this.adapterDeclarationSymbol, generator.buildDeclaration());
|
|
3650
3673
|
});
|
|
3651
|
-
|
|
3652
|
-
|
|
3674
|
+
coreFile.pushTo(this.serviceRequirementsSymbol, this.buildRequirements());
|
|
3675
|
+
coreFile.pushTo(
|
|
3653
3676
|
this.adapterInvocationSymbol,
|
|
3654
3677
|
Code.join(
|
|
3655
3678
|
bindingGenerators.flatMap((generator) => {
|
|
@@ -3665,6 +3688,35 @@ class BindingsGenerator {
|
|
|
3665
3688
|
""
|
|
3666
3689
|
)
|
|
3667
3690
|
);
|
|
3691
|
+
const exportNames = [
|
|
3692
|
+
...bindingGenerators.map((g) => {
|
|
3693
|
+
var _a;
|
|
3694
|
+
return (_a = g.binding) == null ? void 0 : _a.identifier;
|
|
3695
|
+
}).filter(Boolean)
|
|
3696
|
+
];
|
|
3697
|
+
if (this.hasRESTNormalization) {
|
|
3698
|
+
const { typeRegistryGenerator } = this.services;
|
|
3699
|
+
exportNames.push(
|
|
3700
|
+
...typeRegistryGenerator.invalidatableTypes.map(({ propertyName }) => {
|
|
3701
|
+
return `invalidate${toTypeScriptSafeIdentifier(propertyName)}`;
|
|
3702
|
+
})
|
|
3703
|
+
);
|
|
3704
|
+
}
|
|
3705
|
+
const uniqueExportNames = Array.from(new Set(exportNames));
|
|
3706
|
+
coreFile.pushTo(
|
|
3707
|
+
this.exportsTypeMembersSymbol,
|
|
3708
|
+
Code.join(
|
|
3709
|
+
uniqueExportNames.map((name) => code`${name}: typeof ${code`${name}`};`),
|
|
3710
|
+
"\n"
|
|
3711
|
+
)
|
|
3712
|
+
);
|
|
3713
|
+
coreFile.pushTo(
|
|
3714
|
+
this.exportsAssignmentsSymbol,
|
|
3715
|
+
Code.join(
|
|
3716
|
+
uniqueExportNames.map((name) => code`exports.${code`${name}`} = ${code`${name}`};`),
|
|
3717
|
+
"\n"
|
|
3718
|
+
)
|
|
3719
|
+
);
|
|
3668
3720
|
}
|
|
3669
3721
|
buildTypeInvalidation(typesWithNormalization) {
|
|
3670
3722
|
return typesWithNormalization.reduce(
|