@conduit-client/generator-ts 3.7.1 → 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 template(): (symbol | Code)[];
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
@@ -2422,7 +2422,7 @@ const FETCH_RESPONSE$1 = {
2422
2422
  exportedSymbol: "FetchResponse",
2423
2423
  isType: true
2424
2424
  };
2425
- const COERCE_RESPONSE_TO_FETCH_RESPONSE = {
2425
+ const COERCE_RESPONSE_TO_FETCH_RESPONSE$1 = {
2426
2426
  module: "@conduit-client/utils",
2427
2427
  exportedSymbol: "coerceResponseToFetchResponse",
2428
2428
  isType: false
@@ -2578,7 +2578,7 @@ class HttpCommandGenerator extends CommandGenerator {
2578
2578
  generateCoerceError() {
2579
2579
  if (this.commandModel.errorStrategy.type === "fetchResponse") {
2580
2580
  return code`async coerceError(errorResponse: Response):Promise<${FETCH_RESPONSE$1}<unknown>>{
2581
- return ${COERCE_RESPONSE_TO_FETCH_RESPONSE}(errorResponse)
2581
+ return ${COERCE_RESPONSE_TO_FETCH_RESPONSE$1}(errorResponse)
2582
2582
  }`;
2583
2583
  }
2584
2584
  return code``;
@@ -2594,6 +2594,11 @@ const CONVERT_AURA_ERRORS_TO_FETCH_RESPONSE = {
2594
2594
  exportedSymbol: "getFetchResponseFromAuraError",
2595
2595
  isType: false
2596
2596
  };
2597
+ const COERCE_RESPONSE_TO_FETCH_RESPONSE = {
2598
+ module: "@conduit-client/utils",
2599
+ exportedSymbol: "coerceResponseToFetchResponse",
2600
+ isType: false
2601
+ };
2597
2602
  const AURA_COMMAND_BASE_CLASS = {
2598
2603
  module: "@conduit-client/command-aura-network/v1",
2599
2604
  exportedSymbol: "AuraNetworkCommand",
@@ -2686,7 +2691,15 @@ class AuraCommandGenerator extends HttpCommandGenerator {
2686
2691
  */
2687
2692
  generateCoerceError() {
2688
2693
  if (this.commandModel.errorStrategy.type === "fetchResponse") {
2689
- return code`protected override coerceAuraErrors(auraErrors: any[]):${FETCH_RESPONSE}<unknown>{return ${CONVERT_AURA_ERRORS_TO_FETCH_RESPONSE}(auraErrors[0])}`;
2694
+ return code`
2695
+ protected override coerceAuraErrors(auraErrors: any[]):${FETCH_RESPONSE}<unknown>{
2696
+ return ${CONVERT_AURA_ERRORS_TO_FETCH_RESPONSE}(auraErrors[0])
2697
+ }
2698
+
2699
+ protected override async coerceError(errorResponse: Response):Promise<${FETCH_RESPONSE}<unknown>>{
2700
+ return ${COERCE_RESPONSE_TO_FETCH_RESPONSE}(errorResponse)
2701
+ }
2702
+ `;
2690
2703
  }
2691
2704
  return code``;
2692
2705
  }
@@ -3253,8 +3266,14 @@ const OPTIONAL_SERVICE_REQUEST_TYPE = {
3253
3266
  exportedSymbol: "OptionalServiceRequest",
3254
3267
  isType: true
3255
3268
  };
3256
- const GET_SERVICES = {
3269
+ const REQUESTED_SERVICES_TYPE = {
3257
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",
3258
3277
  isType: false
3259
3278
  };
3260
3279
  const INSTRUMENT_COMMAND_DESCRIPTOR = {
@@ -3425,6 +3444,8 @@ class BindingsGenerator {
3425
3444
  this.typeInvalidationDeclarationSymbol = Symbol.for("typeInvalidationDeclaration");
3426
3445
  this.typeInvalidationDefinitionSymbol = Symbol.for("typeInvalidationDefinition");
3427
3446
  this.rootTypesInstantiationSymbol = Symbol.for("rootTypesInstantiation");
3447
+ this.exportsTypeMembersSymbol = Symbol.for("exportsTypeMembers");
3448
+ this.exportsAssignmentsSymbol = Symbol.for("exportsAssignments");
3428
3449
  }
3429
3450
  /**
3430
3451
  * Template for generating the binding structure in the output file.
@@ -3438,21 +3459,33 @@ class BindingsGenerator {
3438
3459
  *
3439
3460
  * @returns {Code[]} An array of code blocks forming the template for the binding output file.
3440
3461
  */
3441
- get template() {
3462
+ get coreTemplate() {
3442
3463
  return [
3443
3464
  this.bindingsServicesDeclarationSymbol,
3444
3465
  this.adapterDeclarationSymbol,
3445
3466
  this.typeInvalidationDeclarationSymbol,
3446
- code`const serviceRequirements=`,
3467
+ code`export type BindingsExports = {`,
3468
+ this.exportsTypeMembersSymbol,
3469
+ code`};`,
3470
+ code`export const exports = {} as BindingsExports;`,
3471
+ code`export const serviceRequirements=`,
3447
3472
  this.serviceRequirementsSymbol,
3448
- code`;`,
3449
- code`${GET_SERVICES}(serviceRequirements).then(
3450
- (services) => {`,
3473
+ code` as const;`,
3474
+ code`export function initGeneratedBindings(services: ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>, exports: BindingsExports) {`,
3451
3475
  this.typeRegistryInstantiationSymbol,
3452
3476
  this.rootTypesInstantiationSymbol,
3453
3477
  this.typeInvalidationDefinitionSymbol,
3454
3478
  this.adapterInvocationSymbol,
3455
- code`},(_err) => {});`
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;`
3456
3489
  ];
3457
3490
  }
3458
3491
  get serviceDependencies() {
@@ -3580,20 +3613,23 @@ class BindingsGenerator {
3580
3613
  * This method coordinates with individual binding generators to compile the necessary elements into a single file.
3581
3614
  */
3582
3615
  build() {
3583
- const filename = "artifacts/bindings.ts";
3584
- const file = this.services.file.build(filename);
3585
- file.template = this.template;
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;
3586
3622
  if (this.hasRESTNormalization) {
3587
3623
  const { typeRegistryGenerator } = this.services;
3588
- file.pushTo(
3624
+ coreFile.pushTo(
3589
3625
  this.typeRegistryInstantiationSymbol,
3590
3626
  code`const typeRegistry = new ${typeRegistryGenerator.build()}(services);`
3591
3627
  );
3592
3628
  const { declarations, definitions } = this.buildTypeInvalidation(
3593
3629
  typeRegistryGenerator.invalidatableTypes
3594
3630
  );
3595
- file.pushTo(this.typeInvalidationDeclarationSymbol, declarations);
3596
- file.pushTo(this.typeInvalidationDefinitionSymbol, definitions);
3631
+ coreFile.pushTo(this.typeInvalidationDeclarationSymbol, declarations);
3632
+ coreFile.pushTo(this.typeInvalidationDefinitionSymbol, definitions);
3597
3633
  }
3598
3634
  if (this.hasGraphQL) {
3599
3635
  const { graphqlTypeRegistryGenerator } = this.services;
@@ -3615,13 +3651,13 @@ class BindingsGenerator {
3615
3651
  schemaModel: firstGraphQLCommand.schema,
3616
3652
  type: mutationTypeModel
3617
3653
  }) : void 0;
3618
- file.pushTo(
3654
+ coreFile.pushTo(
3619
3655
  this.rootTypesInstantiationSymbol,
3620
3656
  code`const graphqlTypeRegistry = new ${graphqlTypeRegistry}(services);
3621
3657
  const ${QUERY_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${queryType.propertyName};`
3622
3658
  );
3623
3659
  if (mutationType) {
3624
- file.pushTo(
3660
+ coreFile.pushTo(
3625
3661
  this.rootTypesInstantiationSymbol,
3626
3662
  code`const ${MUTATION_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${mutationType.propertyName};`
3627
3663
  );
@@ -3633,10 +3669,10 @@ class BindingsGenerator {
3633
3669
  })
3634
3670
  );
3635
3671
  bindingGenerators.forEach((generator) => {
3636
- file.pushTo(this.adapterDeclarationSymbol, generator.buildDeclaration());
3672
+ coreFile.pushTo(this.adapterDeclarationSymbol, generator.buildDeclaration());
3637
3673
  });
3638
- file.pushTo(this.serviceRequirementsSymbol, this.buildRequirements());
3639
- file.pushTo(
3674
+ coreFile.pushTo(this.serviceRequirementsSymbol, this.buildRequirements());
3675
+ coreFile.pushTo(
3640
3676
  this.adapterInvocationSymbol,
3641
3677
  Code.join(
3642
3678
  bindingGenerators.flatMap((generator) => {
@@ -3652,6 +3688,35 @@ class BindingsGenerator {
3652
3688
  ""
3653
3689
  )
3654
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
+ );
3655
3720
  }
3656
3721
  buildTypeInvalidation(typesWithNormalization) {
3657
3722
  return typesWithNormalization.reduce(