@conduit-client/generator-ts 3.17.0 → 3.17.2

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.
@@ -96,6 +96,11 @@ export declare abstract class CommandGenerator {
96
96
  * Override (e.g. GraphQL) when the constructor has a fixed param list with no rest.
97
97
  */
98
98
  protected getBuildCommandClassConstructorParams(): Code;
99
+ /**
100
+ * Additional generic type args for the Generated declare class that surface
101
+ * public constructor fields (config, typeRegistry, etc.) on InstanceType<>.
102
+ */
103
+ protected getBuildCommandClassConstructorFieldGenerics(): Code;
99
104
  protected buildCommandTypeGenerics(): Code;
100
105
  protected buildExtraServices(): Code | undefined;
101
106
  protected generateAfterRequestHooks(): Code;
@@ -42,8 +42,10 @@ export declare class BindingsGenerator {
42
42
  protected typeInvalidationDefinitionSymbol: symbol;
43
43
  protected rootTypesInstantiationSymbol: symbol;
44
44
  protected exportsTypeMembersSymbol: symbol;
45
- protected exportsAssignmentsSymbol: symbol;
46
45
  protected initGeneratedBindingsExtraParamsSymbol: symbol;
46
+ protected returnStatementSymbol: symbol;
47
+ protected wrapperDeclarationsSymbol: symbol;
48
+ protected wrapperAssignmentsSymbol: symbol;
47
49
  /**
48
50
  * Template for generating the binding structure in the output file.
49
51
  * Includes placeholders for adapter declarations, service requirements, and adapter invocations.
@@ -57,7 +59,7 @@ export declare class BindingsGenerator {
57
59
  * @returns {Code[]} An array of code blocks forming the template for the binding output file.
58
60
  */
59
61
  get coreTemplate(): (symbol | Code)[];
60
- get wrapperTemplate(): Code[];
62
+ get wrapperTemplate(): (symbol | Code)[];
61
63
  protected get serviceDependencies(): ServiceDependency[];
62
64
  /**
63
65
  * Builds the binding file, generating declarations, requirements, and invocations for each command model.
package/dist/v1/index.js CHANGED
@@ -2249,9 +2249,9 @@ class CommandGenerator {
2249
2249
  }
2250
2250
  get commandConstructorArgs() {
2251
2251
  if (this.commandModel.invalidationConfigs.length > 0) {
2252
- return code`private config: Config, private typeRegistry: ${this.services.typeRegistryGenerator.build()}`;
2252
+ return code`public config: Config, public typeRegistry: ${this.services.typeRegistryGenerator.build()}`;
2253
2253
  }
2254
- return code`private config: Config`;
2254
+ return code`public config: Config`;
2255
2255
  }
2256
2256
  get exposeSubscribeAndRefresh() {
2257
2257
  if (this.commandModel.exposeRefresh && this.commandModel.cacheStrategy.type === "none") {
@@ -2332,7 +2332,8 @@ class CommandGenerator {
2332
2332
  file.pushTo(this.commandClassBodySymbol, ...this.classBody);
2333
2333
  const generatedClass = this.commandGeneratedClass;
2334
2334
  if (generatedClass) {
2335
- const constructorSignature = code`new (${this.getBuildCommandClassConstructorParams()}) => ${generatedClass}<${this.getBuildCommandClassReturnTypeGenerics()}>`;
2335
+ const fieldGenerics = this.getBuildCommandClassConstructorFieldGenerics();
2336
+ const constructorSignature = code`new (${this.getBuildCommandClassConstructorParams()}) => ${generatedClass}<${this.getBuildCommandClassReturnTypeGenerics()}, ${fieldGenerics}>`;
2336
2337
  file.pushTo(this.commandBuildCommandClassReturnTypeSymbol, constructorSignature);
2337
2338
  file.pushTo(
2338
2339
  this.commandBuildCommandClassReturnAssertionSymbol,
@@ -2369,6 +2370,16 @@ class CommandGenerator {
2369
2370
  getBuildCommandClassConstructorParams() {
2370
2371
  return code`${this.commandTypeConstructorArgs}, ...args: CommandConstructorParams`;
2371
2372
  }
2373
+ /**
2374
+ * Additional generic type args for the Generated declare class that surface
2375
+ * public constructor fields (config, typeRegistry, etc.) on InstanceType<>.
2376
+ */
2377
+ getBuildCommandClassConstructorFieldGenerics() {
2378
+ if (this.commandModel.invalidationConfigs.length > 0) {
2379
+ return code`Config, ${this.services.typeRegistryGenerator.build()}`;
2380
+ }
2381
+ return code`Config`;
2382
+ }
2372
2383
  buildCommandTypeGenerics() {
2373
2384
  var _a;
2374
2385
  const extraServicesCode = this.buildExtraServices();
@@ -2965,7 +2976,7 @@ class ImperativeAdapterBindingGenerator {
2965
2976
  };
2966
2977
  }
2967
2978
  buildDeclaration() {
2968
- return code`export let ${this.binding.identifier}:${this.bindingTypeCode};`;
2979
+ return code`let ${this.binding.identifier}:${this.bindingTypeCode};`;
2969
2980
  }
2970
2981
  get bindingTypeCode() {
2971
2982
  return code`(config:${this.commandConfigTypeImport}, options?: ${this.commandOptionsTypeImport})=>${this.returnShape}<${this.responseTypeCode}>`;
@@ -3016,7 +3027,7 @@ class ImperativeAdapterBindingGenerator {
3016
3027
  const requiresTypeRegistry = this.commandModel.cacheStrategy.type === "normalized" || this.commandModel.invalidationConfigs.length > 0;
3017
3028
  const typeRegistry = requiresTypeRegistry ? "typeRegistry," : "";
3018
3029
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3019
- ${this.binding.identifier}=${this.invoker}<Parameters<typeof ${this.binding.identifier}>,${this.responseTypeCode}>(
3030
+ const ${this.binding.identifier}=${this.invoker}<Parameters<BindingsExports["${this.binding.identifier}"]>,${this.responseTypeCode}>(
3020
3031
  ({params,assertIsValid})=>{
3021
3032
  const config=params[0];
3022
3033
  const options=params[1];
@@ -3067,7 +3078,7 @@ class ImperativeAdapterLegacyBindingGenerator {
3067
3078
  );
3068
3079
  }
3069
3080
  buildDeclaration() {
3070
- return code`export let ${this.binding.identifier}:${LEGACY_IMPERATIVE_RETURN_SHAPE}<${this.commandConfigTypeImport},${this.responseTypeCode}>;`;
3081
+ return code`let ${this.binding.identifier}:${LEGACY_IMPERATIVE_RETURN_SHAPE}<${this.commandConfigTypeImport},${this.responseTypeCode}>;`;
3071
3082
  }
3072
3083
  get localCommandConstructorName() {
3073
3084
  return `${this.binding.identifier}_ctor`;
@@ -3078,7 +3089,7 @@ class ImperativeAdapterLegacyBindingGenerator {
3078
3089
  buildInvocation(servicesName = "services") {
3079
3090
  const requiresTypeRegistry = this.commandModel.cacheStrategy.type === "normalized" || this.commandModel.invalidationConfigs.length > 0;
3080
3091
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3081
- ${this.binding.identifier}=services.${LEGACY_IMPERATIVE_BINDINGS}.bind<${this.commandConfigTypeImport},${this.responseTypeCode}>(
3092
+ const ${this.binding.identifier}=services.${LEGACY_IMPERATIVE_BINDINGS}.bind<${this.commandConfigTypeImport},${this.responseTypeCode}>(
3082
3093
  ({config,assertIsValid})=>{
3083
3094
  const _:<T>(data:unknown,_:${JSON_SCHEMA_TYPE$3})=>asserts data is T=assertIsValid;
3084
3095
  _<${this.commandConfigTypeImport}>(config,${this.commandConfigSchemaImport});
@@ -3127,7 +3138,7 @@ class GraphQLImperativeAdapterLegacyBindingGenerator {
3127
3138
  );
3128
3139
  }
3129
3140
  buildDeclaration() {
3130
- return code`export let ${this.binding.identifier}:${LEGACY_GRAPHQL_IMPERATIVE_RETURN_SHAPE}<${this.commandConfigTypeImport}>;`;
3141
+ return code`let ${this.binding.identifier}:${LEGACY_GRAPHQL_IMPERATIVE_RETURN_SHAPE}<${this.commandConfigTypeImport}>;`;
3131
3142
  }
3132
3143
  get localCommandConstructorName() {
3133
3144
  return `${this.binding.identifier}_ctor`;
@@ -3137,7 +3148,7 @@ class GraphQLImperativeAdapterLegacyBindingGenerator {
3137
3148
  }
3138
3149
  buildInvocation(servicesName = "services") {
3139
3150
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3140
- ${this.binding.identifier}=services.${GRAPHQL_LEGACY_IMPERATIVE_BINDINGS}.bind<${this.commandConfigTypeImport}>(
3151
+ const ${this.binding.identifier}=services.${GRAPHQL_LEGACY_IMPERATIVE_BINDINGS}.bind<${this.commandConfigTypeImport}>(
3141
3152
  ({config,assertIsValid})=>{
3142
3153
  const _:<T>(data:unknown,_:${JSON_SCHEMA_TYPE$2})=>asserts data is T=assertIsValid;
3143
3154
  _<${this.commandConfigTypeImport}>(config,${this.commandConfigSchemaImport});
@@ -3184,7 +3195,7 @@ class WireAdapterBindingGenerator {
3184
3195
  );
3185
3196
  }
3186
3197
  buildDeclaration() {
3187
- return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR$1}<${this.commandConfigTypeImport}, ${WIRE_ADAPTER_RESULT}<${this.responseTypeCode}>, {}>;`;
3198
+ return code`let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR$1}<${this.commandConfigTypeImport}, ${WIRE_ADAPTER_RESULT}<${this.responseTypeCode}>, {}>;`;
3188
3199
  }
3189
3200
  get localCommandConstructorName() {
3190
3201
  return `${this.binding.identifier}_ctor`;
@@ -3194,7 +3205,7 @@ class WireAdapterBindingGenerator {
3194
3205
  }
3195
3206
  buildInvocation(servicesName = "services") {
3196
3207
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3197
- ${this.binding.identifier}=services.${LWC_WIRE_BINDINGS}.bind<${this.responseTypeCode}, ${this.commandConfigTypeImport}>(
3208
+ const ${this.binding.identifier}=services.${LWC_WIRE_BINDINGS}.bind<${this.responseTypeCode}, ${this.commandConfigTypeImport}>(
3198
3209
  (config: ${this.commandConfigTypeImport}) => new ${this.localCommandConstructorName}(config!,${this.getTypeRegistryArgument()}${servicesName}),${this.commandConfigSchemaImport},${this.commandModel.exposeRefresh});`;
3199
3210
  }
3200
3211
  getTypeRegistryArgument() {
@@ -3247,7 +3258,7 @@ class GraphQLImperativeAdapterBindingGenerator {
3247
3258
  };
3248
3259
  }
3249
3260
  buildDeclaration() {
3250
- return code`export let ${this.binding.identifier}:${this.bindingTypeCode};`;
3261
+ return code`let ${this.binding.identifier}:${this.bindingTypeCode};`;
3251
3262
  }
3252
3263
  get bindingTypeCode() {
3253
3264
  return code`(config:${this.commandConfigTypeImport}, options?: ${this.commandOptionsTypeImport})=>${this.returnShape}`;
@@ -3275,7 +3286,7 @@ class GraphQLImperativeAdapterBindingGenerator {
3275
3286
  }
3276
3287
  buildInvocation(servicesName = "services") {
3277
3288
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3278
- ${this.binding.identifier}=${this.invoker}<Parameters<typeof ${this.binding.identifier}>>(
3289
+ const ${this.binding.identifier}=${this.invoker}<Parameters<BindingsExports["${this.binding.identifier}"]>>(
3279
3290
  ({params,assertIsValid})=>{
3280
3291
  const config=params[0];
3281
3292
  const options=params[1];
@@ -3326,7 +3337,7 @@ class GraphQLWireAdapterBindingGenerator {
3326
3337
  );
3327
3338
  }
3328
3339
  buildDeclaration() {
3329
- return code`export let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR}<${this.commandConfigTypeImport}, ${GRAPHQL_WIRE_ADAPTER_RESULT}, {}>;`;
3340
+ return code`let ${this.binding.identifier}:${WIRE_ADAPTER_CONSTRUCTOR}<${this.commandConfigTypeImport}, ${GRAPHQL_WIRE_ADAPTER_RESULT}, {}>;`;
3330
3341
  }
3331
3342
  get localCommandConstructorName() {
3332
3343
  return `${this.binding.identifier}_ctor`;
@@ -3336,7 +3347,7 @@ class GraphQLWireAdapterBindingGenerator {
3336
3347
  }
3337
3348
  buildInvocation(servicesName = "services") {
3338
3349
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3339
- ${this.binding.identifier}=services.${GRAPHQL_WIRE_BINDINGS}.bind<${this.commandConfigTypeImport}>((config: ${this.commandConfigTypeImport}) => new ${this.localCommandConstructorName}(config,${QUERY_TYPE_VARIABLE_NAME},${servicesName}), ${this.commandConfigSchemaImport}, ${this.commandModel.exposeRefresh});`;
3350
+ const ${this.binding.identifier}=services.${GRAPHQL_WIRE_BINDINGS}.bind<${this.commandConfigTypeImport}>((config: ${this.commandConfigTypeImport}) => new ${this.localCommandConstructorName}(config,${QUERY_TYPE_VARIABLE_NAME},${servicesName}), ${this.commandConfigSchemaImport}, ${this.commandModel.exposeRefresh});`;
3340
3351
  }
3341
3352
  }
3342
3353
  const GRAPHQL_MUTATION_RESULT = {
@@ -3382,7 +3393,7 @@ class GraphQLMutationAdapterBindingGenerator {
3382
3393
  };
3383
3394
  }
3384
3395
  buildDeclaration() {
3385
- return code`export let ${this.binding.identifier}:${this.bindingTypeCode};`;
3396
+ return code`let ${this.binding.identifier}:${this.bindingTypeCode};`;
3386
3397
  }
3387
3398
  get bindingTypeCode() {
3388
3399
  return code`(config:${this.commandConfigTypeImport}, options?: ${this.commandOptionsTypeImport})=>${this.returnShape}`;
@@ -3401,7 +3412,7 @@ class GraphQLMutationAdapterBindingGenerator {
3401
3412
  }
3402
3413
  buildInvocation(servicesName = "services") {
3403
3414
  return code`const ${this.localCommandConstructorName} = services.instrumentCommand(${this.classBuilderImport}(${servicesName}.${this.commandModel.serviceDependencies.baseClass.localName}), '${this.commandModel.className}');
3404
- ${this.binding.identifier}=${this.invoker}<Parameters<typeof ${this.binding.identifier}>>(
3415
+ const ${this.binding.identifier}=${this.invoker}<Parameters<BindingsExports["${this.binding.identifier}"]>>(
3405
3416
  ({params,assertIsValid})=>{
3406
3417
  const config=params[0];
3407
3418
  const options=params[1];
@@ -3602,10 +3613,12 @@ class BindingsGenerator {
3602
3613
  this.typeInvalidationDefinitionSymbol = Symbol.for("typeInvalidationDefinition");
3603
3614
  this.rootTypesInstantiationSymbol = Symbol.for("rootTypesInstantiation");
3604
3615
  this.exportsTypeMembersSymbol = Symbol.for("exportsTypeMembers");
3605
- this.exportsAssignmentsSymbol = Symbol.for("exportsAssignments");
3606
3616
  this.initGeneratedBindingsExtraParamsSymbol = Symbol.for(
3607
3617
  "initGeneratedBindingsExtraParams"
3608
3618
  );
3619
+ this.returnStatementSymbol = Symbol.for("returnStatement");
3620
+ this.wrapperDeclarationsSymbol = Symbol.for("wrapperDeclarations");
3621
+ this.wrapperAssignmentsSymbol = Symbol.for("wrapperAssignments");
3609
3622
  }
3610
3623
  /**
3611
3624
  * Template for generating the binding structure in the output file.
@@ -3627,27 +3640,31 @@ class BindingsGenerator {
3627
3640
  code`export type BindingsExports = {`,
3628
3641
  this.exportsTypeMembersSymbol,
3629
3642
  code`};`,
3630
- code`export const exports = {} as BindingsExports;`,
3631
3643
  code`export const serviceRequirements=`,
3632
3644
  this.serviceRequirementsSymbol,
3633
3645
  code` as const;`,
3634
- code`export function initGeneratedBindings<S extends ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>>(services: S, exports: BindingsExports`,
3646
+ code`export function initGeneratedBindings<S extends ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>>(services: S`,
3635
3647
  this.initGeneratedBindingsExtraParamsSymbol,
3636
- code`) {`,
3648
+ code`): BindingsExports {`,
3637
3649
  this.typeRegistryInstantiationSymbol,
3638
3650
  this.rootTypesInstantiationSymbol,
3639
3651
  this.typeInvalidationDefinitionSymbol,
3640
3652
  this.adapterInvocationSymbol,
3641
- this.exportsAssignmentsSymbol,
3653
+ this.returnStatementSymbol,
3642
3654
  code`}`
3643
3655
  ];
3644
3656
  }
3645
3657
  get wrapperTemplate() {
3646
3658
  return [
3647
- code`export * from './bindings-core';`,
3648
- code`import { exports, serviceRequirements, initGeneratedBindings } from './bindings-core';`,
3649
- code`export const ready = ${INIT_BINDINGS_EXPORTS}({ serviceRequirements, exports, init: initGeneratedBindings }).ready;`,
3650
- code`export default exports;`
3659
+ code`import { serviceRequirements, initGeneratedBindings, type BindingsExports } from './bindings-core';`,
3660
+ this.wrapperDeclarationsSymbol,
3661
+ code`${INIT_BINDINGS_EXPORTS}({`,
3662
+ code`serviceRequirements,`,
3663
+ code`init: (services) => {`,
3664
+ code`const result = initGeneratedBindings(services);`,
3665
+ this.wrapperAssignmentsSymbol,
3666
+ code`},`,
3667
+ code`});`
3651
3668
  ];
3652
3669
  }
3653
3670
  get serviceDependencies() {
@@ -3884,9 +3901,25 @@ class BindingsGenerator {
3884
3901
  )
3885
3902
  );
3886
3903
  coreFile.pushTo(
3887
- this.exportsAssignmentsSymbol,
3904
+ this.returnStatementSymbol,
3905
+ code`return {${Code.join(
3906
+ uniqueExportNames.map((name) => code`${name},`),
3907
+ " "
3908
+ )}};`
3909
+ );
3910
+ wrapperFile.pushTo(
3911
+ this.wrapperDeclarationsSymbol,
3888
3912
  Code.join(
3889
- uniqueExportNames.map((name) => code`exports.${code`${name}`} = ${code`${name}`};`),
3913
+ uniqueExportNames.map(
3914
+ (name) => code`export let ${code`${name}`}: BindingsExports['${name}'];`
3915
+ ),
3916
+ "\n"
3917
+ )
3918
+ );
3919
+ wrapperFile.pushTo(
3920
+ this.wrapperAssignmentsSymbol,
3921
+ Code.join(
3922
+ uniqueExportNames.map((name) => code`${code`${name}`} = result.${code`${name}`};`),
3890
3923
  "\n"
3891
3924
  )
3892
3925
  );
@@ -3990,10 +4023,10 @@ class BindingsGenerator {
3990
4023
  (acc, { propertyName, typeClassRef }) => {
3991
4024
  const invalidateFunctionName = code`invalidate${toTypeScriptSafeIdentifier(propertyName)}`;
3992
4025
  acc.declarations.push(
3993
- code`export let ${invalidateFunctionName}: ${typeClassRef}["invalidate"];`
4026
+ code`let ${invalidateFunctionName}: ${typeClassRef}["invalidate"];`
3994
4027
  );
3995
4028
  acc.definitions.push(
3996
- code`${invalidateFunctionName} = (configs) => typeRegistry.${toTypeScriptSafeIdentifier(propertyName)}.invalidate(configs);`
4029
+ code`const ${invalidateFunctionName}: ${typeClassRef}["invalidate"] = (configs) => typeRegistry.${toTypeScriptSafeIdentifier(propertyName)}.invalidate(configs);`
3997
4030
  );
3998
4031
  return acc;
3999
4032
  },
@@ -4293,7 +4326,10 @@ function NormalizedCacheControlGeneratorMixin(Base, commandBaseClass, commandGen
4293
4326
  return code`config: Config, typeRegistry: ${this.services.typeRegistryGenerator.build()}`;
4294
4327
  }
4295
4328
  get commandConstructorArgs() {
4296
- return code`private config: Config, private typeRegistry: ${this.services.typeRegistryGenerator.build()}`;
4329
+ return code`public config: Config, public typeRegistry: ${this.services.typeRegistryGenerator.build()}`;
4330
+ }
4331
+ getBuildCommandClassConstructorFieldGenerics() {
4332
+ return code`Config, ${this.services.typeRegistryGenerator.build()}`;
4297
4333
  }
4298
4334
  buildCommandTypeGenerics() {
4299
4335
  const extraServicesCode = this.buildExtraServices();
@@ -4493,8 +4529,11 @@ function GraphQLNormalizedCacheControlGeneratorMixin(Base, commandBaseClass, com
4493
4529
  getBuildCommandClassReturnTypeGenerics() {
4494
4530
  return this.buildCommandTypeGenerics();
4495
4531
  }
4532
+ getBuildCommandClassConstructorFieldGenerics() {
4533
+ return code`CommandConfig, DocumentRootType, ${NAMED_CACHE_CONTROLLER_SERVICE} & ${NAMED_PUBSUB_SERVICE$3} & ${this.buildNetworkServicesCode()} & object`;
4534
+ }
4496
4535
  get commandConstructorArgs() {
4497
- return code`protected config: CommandConfig, protected documentRootType: DocumentRootType, protected services: ${NAMED_CACHE_CONTROLLER_SERVICE} & ${NAMED_PUBSUB_SERVICE$3} & ${this.buildNetworkServicesCode()} & object`;
4536
+ return code`public config: CommandConfig, public documentRootType: DocumentRootType, public services: ${NAMED_CACHE_CONTROLLER_SERVICE} & ${NAMED_PUBSUB_SERVICE$3} & ${this.buildNetworkServicesCode()} & object`;
4498
4537
  }
4499
4538
  get commandConstructorBody() {
4500
4539
  return code`super(config, documentRootType, services);`;