@conduit-client/generator-ts 3.15.0 → 3.16.0-dev1

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,5 +1,5 @@
1
- import { Type } from '@conduit-client/model/v1';
2
- import { ICommandModel } from '../../model/base-command-model';
1
+ import type { Type } from '@conduit-client/model/v1';
2
+ import type { ICommandModel } from '../../model/base-command-model';
3
3
  export declare function buildAuraCommandModel(filePath: string, configType: Type, responseType: Type): ICommandModel;
4
4
  export declare function buildAuraResourceCacheCommandModel(filePath: string, configType: Type, responseType: Type): ICommandModel;
5
5
  export declare function buildAuraNormalizedCacheCommandModel(filePath: string, configType: Type, responseType: Type): ICommandModel;
@@ -42,6 +42,8 @@ export declare class BindingsGenerator {
42
42
  protected rootTypesInstantiationSymbol: symbol;
43
43
  protected exportsTypeMembersSymbol: symbol;
44
44
  protected exportsAssignmentsSymbol: symbol;
45
+ protected initGeneratedBindingsExtraParamsSymbol: symbol;
46
+ protected reExportsSymbol: symbol;
45
47
  /**
46
48
  * Template for generating the binding structure in the output file.
47
49
  * Includes placeholders for adapter declarations, service requirements, and adapter invocations.
@@ -62,6 +64,58 @@ export declare class BindingsGenerator {
62
64
  * This method coordinates with individual binding generators to compile the necessary elements into a single file.
63
65
  */
64
66
  build(): void;
67
+ /**
68
+ * Computes a relative import specifier from the bindings-core file to the
69
+ * given generated file path (e.g. `commands/getTestCommand.ts` -> `../commands/getTestCommand`).
70
+ */
71
+ protected relativeImportPath(coreFilename: string, targetFilePath: string): string;
72
+ /**
73
+ * Emits re-export statements from bindings-core so that custom bindings modules
74
+ * can import generated internals from a single stable entry point.
75
+ */
76
+ protected buildReExports(coreFile: {
77
+ filename: string;
78
+ pushTo: (...args: any[]) => any;
79
+ }): void;
80
+ /**
81
+ * Re-exports per-command symbols: `buildCommandClass` (aliased to `build<Pascal>CommandClass`),
82
+ * `CONFIG_SCHEMA` (aliased to `<UPPER>_CONFIG_SCHEMA`), and the `Config` type
83
+ * (aliased to `<Pascal>Config`).
84
+ *
85
+ * The CONFIG_SCHEMA alias uses a simple uppercase of the commandName (e.g. `getItemsByIds`
86
+ * becomes `GETITEMSBYIDS_CONFIG_SCHEMA`) to avoid ambiguity from word-boundary heuristics.
87
+ */
88
+ protected buildCommandReExports(coreFile: {
89
+ filename: string;
90
+ pushTo: (...args: any[]) => any;
91
+ }): void;
92
+ /**
93
+ * Re-exports the `TypeRegistry` (REST) and/or `GraphQLTypeRegistry` (GraphQL) classes
94
+ * so custom bindings can construct or extend them.
95
+ */
96
+ protected buildTypeRegistryReExports(coreFile: {
97
+ filename: string;
98
+ pushTo: (...args: any[]) => any;
99
+ }): void;
100
+ /**
101
+ * Re-exports individual generated type repository classes (e.g. `RecordRepresentationRepository`)
102
+ * so custom bindings can extend or reference them without importing from internal paths.
103
+ *
104
+ * If both REST and GraphQL registries produce a repository with the same exported symbol,
105
+ * the GraphQL version is aliased with a `GraphQL_` prefix to avoid collisions.
106
+ */
107
+ protected buildTypeRepositoryReExports(coreFile: {
108
+ filename: string;
109
+ pushTo: (...args: any[]) => any;
110
+ }): void;
111
+ /**
112
+ * Re-exports all generated entity types so custom bindings can reference
113
+ * domain models (e.g. `api_Item`) without importing from internal paths.
114
+ */
115
+ protected buildEntityTypeReExports(coreFile: {
116
+ filename: string;
117
+ pushTo: (...args: any[]) => any;
118
+ }): void;
65
119
  buildTypeInvalidation(typesWithNormalization: TypeRegistryGenerator['invalidatableTypes']): {
66
120
  definitions: Code[];
67
121
  declarations: Code[];
@@ -4,7 +4,7 @@ import type { NamedFileService, File, ImportableValueReference, ImportableRefere
4
4
  import type { NamedService } from '@conduit-client/utils';
5
5
  import type { GraphQLSchemaModel } from '../model/graphql-schema-model';
6
6
  import type { GraphQLObjectType } from './graphql-type-generator';
7
- type GraphQLTypeRepositoryReference = {
7
+ export type GraphQLTypeRepositoryReference = {
8
8
  propertyName: string;
9
9
  typeClassRef: ImportableValueReference;
10
10
  typeName: string;
@@ -16,6 +16,7 @@ type Options = {
16
16
  export type IGraphQLTypeRegistryGeneratorService = {
17
17
  build(): ImportableValueReference;
18
18
  buildGraphQLType(options: Options): GraphQLTypeRepositoryReference;
19
+ readonly registeredTypes: ReadonlyMap<string, GraphQLTypeRepositoryReference>;
19
20
  };
20
21
  export type NamedGraphQLTypeRegistryGeneratorService<Name extends string = 'graphqlTypeRegistryGenerator'> = NamedService<Name, IGraphQLTypeRegistryGeneratorService>;
21
22
  export declare const NAMED_CACHE_CONTROLLER_SERVICE: ImportableReference;
@@ -35,6 +36,7 @@ export declare class GraphQLTypeRegistryGenerator implements IGraphQLTypeRegistr
35
36
  protected typeInstantiationsSymbol: symbol;
36
37
  protected typeGettersSymbol: symbol;
37
38
  cache: Map<string, GraphQLTypeRepositoryReference>;
39
+ get registeredTypes(): ReadonlyMap<string, GraphQLTypeRepositoryReference>;
38
40
  private get file();
39
41
  private buildFile;
40
42
  get template(): (symbol | import("..").Code)[];
@@ -1,5 +1,6 @@
1
- import { BaseTypeRegistry, Type } from '@conduit-client/model/v1';
1
+ import { BaseTypeRegistry } from '@conduit-client/model/v1';
2
2
  import { NormalizeGeneratorService } from '../../normalize-code-gen/normalize-generator-service';
3
+ import type { Type } from '@conduit-client/model/v1';
3
4
  export declare const baseOptions: {
4
5
  namespace: string;
5
6
  typeRegistryRef: import("../../..").Code;
@@ -6,7 +6,7 @@ import type { INormalizedTypeGenerator } from './normalized-type-generator';
6
6
  import type { NamedService } from '@conduit-client/utils';
7
7
  import type { File, ImportableValueReference, NamedFileService } from '../files';
8
8
  import type { NamedNormalizeGeneratorService } from './normalize-code-gen/normalize-generator-service';
9
- type TypeRepositoryReference = {
9
+ export type TypeRepositoryReference = {
10
10
  propertyName: string;
11
11
  typeClassRef: ImportableValueReference;
12
12
  };
@@ -20,6 +20,7 @@ export type ITypeRegistryGeneratorService = {
20
20
  build(): ImportableValueReference;
21
21
  buildType(type: Type, options: Options): TypeRepositoryReference;
22
22
  invalidatableTypes: TypeRepositoryReference[];
23
+ readonly registeredTypes: ReadonlyMap<string, TypeRepositoryReference>;
23
24
  };
24
25
  export type NamedTypeRegistryGeneratorService<Name extends string = 'typeRegistryGenerator'> = NamedService<Name, ITypeRegistryGeneratorService>;
25
26
  /**
@@ -40,6 +41,7 @@ export declare class TypeRegistryGenerator implements ITypeRegistryGeneratorServ
40
41
  * after all operations precessing is complete.
41
42
  */
42
43
  invalidatableTypes: TypeRepositoryReference[];
44
+ get registeredTypes(): ReadonlyMap<string, TypeRepositoryReference>;
43
45
  private get file();
44
46
  private buildFile;
45
47
  get template(): (symbol | Code)[];
package/dist/v1/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  import * as path from "path";
7
7
  import { resolve } from "path";
8
8
  import * as prettier from "prettier";
9
- import { toTypeScriptSafeIdentifier, JSONStringify, ok, err, stringIsVersion, stableJSONStringify } from "@conduit-client/utils";
9
+ import { toTypeScriptSafeIdentifier, JSONStringify, ok, err, toPascalCase, stringIsVersion, stableJSONStringify } from "@conduit-client/utils";
10
10
  import * as fs from "fs";
11
11
  import { readFileSync } from "fs";
12
12
  import { isAnyType, isRefType, isAllOfType, isOneOfType, isNotType, isObjectType as isObjectType$2, isDiscriminatedObjectType, isArrayType, isScalar, isEnumType as isEnumType$1, isNilType, isCanonicalStringType, isCanonicalNumberType, isBooleanType, typesEqual, isIdentifiableType as isIdentifiableType$1, canonicalizeType } from "@conduit-client/model/v1";
@@ -1453,6 +1453,9 @@ class TypeRegistryGenerator {
1453
1453
  this.cache = /* @__PURE__ */ new Map();
1454
1454
  this.invalidatableTypes = [];
1455
1455
  }
1456
+ get registeredTypes() {
1457
+ return this.cache;
1458
+ }
1456
1459
  get file() {
1457
1460
  return this.buildFile();
1458
1461
  }
@@ -2048,6 +2051,9 @@ class GraphQLTypeRegistryGenerator {
2048
2051
  setGraphQLTypeGenerator(generator) {
2049
2052
  this.graphqlTypeGenerator = generator;
2050
2053
  }
2054
+ get registeredTypes() {
2055
+ return this.cache;
2056
+ }
2051
2057
  get file() {
2052
2058
  if (this._file) {
2053
2059
  return this._file;
@@ -3530,6 +3536,10 @@ class BindingsGenerator {
3530
3536
  this.rootTypesInstantiationSymbol = Symbol.for("rootTypesInstantiation");
3531
3537
  this.exportsTypeMembersSymbol = Symbol.for("exportsTypeMembers");
3532
3538
  this.exportsAssignmentsSymbol = Symbol.for("exportsAssignments");
3539
+ this.initGeneratedBindingsExtraParamsSymbol = Symbol.for(
3540
+ "initGeneratedBindingsExtraParams"
3541
+ );
3542
+ this.reExportsSymbol = Symbol.for("reExports");
3533
3543
  }
3534
3544
  /**
3535
3545
  * Template for generating the binding structure in the output file.
@@ -3555,13 +3565,16 @@ class BindingsGenerator {
3555
3565
  code`export const serviceRequirements=`,
3556
3566
  this.serviceRequirementsSymbol,
3557
3567
  code` as const;`,
3558
- code`export function initGeneratedBindings(services: ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>, exports: BindingsExports) {`,
3568
+ code`export function initGeneratedBindings<S extends ${REQUESTED_SERVICES_TYPE}<typeof serviceRequirements>>(services: S, exports: BindingsExports`,
3569
+ this.initGeneratedBindingsExtraParamsSymbol,
3570
+ code`) {`,
3559
3571
  this.typeRegistryInstantiationSymbol,
3560
3572
  this.rootTypesInstantiationSymbol,
3561
3573
  this.typeInvalidationDefinitionSymbol,
3562
3574
  this.adapterInvocationSymbol,
3563
3575
  this.exportsAssignmentsSymbol,
3564
- code`}`
3576
+ code`}`,
3577
+ this.reExportsSymbol
3565
3578
  ];
3566
3579
  }
3567
3580
  get wrapperTemplate() {
@@ -3705,9 +3718,14 @@ class BindingsGenerator {
3705
3718
  wrapperFile.template = this.wrapperTemplate;
3706
3719
  if (this.hasRESTNormalization) {
3707
3720
  const { typeRegistryGenerator } = this.services;
3721
+ const typeRegistryRef = typeRegistryGenerator.build();
3722
+ coreFile.pushTo(
3723
+ this.initGeneratedBindingsExtraParamsSymbol,
3724
+ code`, typeRegistry?: ${typeRegistryRef}`
3725
+ );
3708
3726
  coreFile.pushTo(
3709
3727
  this.typeRegistryInstantiationSymbol,
3710
- code`const typeRegistry = new ${typeRegistryGenerator.build()}(services);`
3728
+ code`typeRegistry ??= new ${typeRegistryRef}(services);`
3711
3729
  );
3712
3730
  const { declarations, definitions } = this.buildTypeInvalidation(
3713
3731
  typeRegistryGenerator.invalidatableTypes
@@ -3717,7 +3735,11 @@ class BindingsGenerator {
3717
3735
  }
3718
3736
  if (this.hasGraphQL) {
3719
3737
  const { graphqlTypeRegistryGenerator } = this.services;
3720
- const graphqlTypeRegistry = graphqlTypeRegistryGenerator.build();
3738
+ const graphqlTypeRegistryRef = graphqlTypeRegistryGenerator.build();
3739
+ coreFile.pushTo(
3740
+ this.initGeneratedBindingsExtraParamsSymbol,
3741
+ code`, graphqlTypeRegistry?: ${graphqlTypeRegistryRef}`
3742
+ );
3721
3743
  const firstGraphQLCommand = this.commandModels.find(
3722
3744
  (model) => model.operationType === "graphql"
3723
3745
  );
@@ -3737,7 +3759,7 @@ class BindingsGenerator {
3737
3759
  }) : void 0;
3738
3760
  coreFile.pushTo(
3739
3761
  this.rootTypesInstantiationSymbol,
3740
- code`const graphqlTypeRegistry = new ${graphqlTypeRegistry}(services);
3762
+ code`graphqlTypeRegistry ??= new ${graphqlTypeRegistryRef}(services);
3741
3763
  const ${QUERY_TYPE_VARIABLE_NAME} = graphqlTypeRegistry.${queryType.propertyName};`
3742
3764
  );
3743
3765
  if (mutationType) {
@@ -3801,6 +3823,116 @@ class BindingsGenerator {
3801
3823
  "\n"
3802
3824
  )
3803
3825
  );
3826
+ this.buildReExports(coreFile);
3827
+ }
3828
+ /**
3829
+ * Computes a relative import specifier from the bindings-core file to the
3830
+ * given generated file path (e.g. `commands/getTestCommand.ts` -> `../commands/getTestCommand`).
3831
+ */
3832
+ relativeImportPath(coreFilename, targetFilePath) {
3833
+ const rel = path.relative(path.dirname(coreFilename), targetFilePath).replace(/\.ts$/, "");
3834
+ return rel.startsWith(".") ? rel : "./" + rel;
3835
+ }
3836
+ /**
3837
+ * Emits re-export statements from bindings-core so that custom bindings modules
3838
+ * can import generated internals from a single stable entry point.
3839
+ */
3840
+ buildReExports(coreFile) {
3841
+ this.buildCommandReExports(coreFile);
3842
+ this.buildTypeRegistryReExports(coreFile);
3843
+ this.buildTypeRepositoryReExports(coreFile);
3844
+ this.buildEntityTypeReExports(coreFile);
3845
+ }
3846
+ /**
3847
+ * Re-exports per-command symbols: `buildCommandClass` (aliased to `build<Pascal>CommandClass`),
3848
+ * `CONFIG_SCHEMA` (aliased to `<UPPER>_CONFIG_SCHEMA`), and the `Config` type
3849
+ * (aliased to `<Pascal>Config`).
3850
+ *
3851
+ * The CONFIG_SCHEMA alias uses a simple uppercase of the commandName (e.g. `getItemsByIds`
3852
+ * becomes `GETITEMSBYIDS_CONFIG_SCHEMA`) to avoid ambiguity from word-boundary heuristics.
3853
+ */
3854
+ buildCommandReExports(coreFile) {
3855
+ for (const model of this.commandModels) {
3856
+ const pascal = toPascalCase(model.commandName);
3857
+ const upper = model.commandName.toUpperCase();
3858
+ const relPath = this.relativeImportPath(coreFile.filename, model.filePath);
3859
+ coreFile.pushTo(
3860
+ this.reExportsSymbol,
3861
+ code`export { buildCommandClass as build${pascal}CommandClass, CONFIG_SCHEMA as ${upper}_CONFIG_SCHEMA } from "${relPath}";`,
3862
+ code`export type { Config as ${pascal}Config } from "${relPath}";`
3863
+ );
3864
+ }
3865
+ }
3866
+ /**
3867
+ * Re-exports the `TypeRegistry` (REST) and/or `GraphQLTypeRegistry` (GraphQL) classes
3868
+ * so custom bindings can construct or extend them.
3869
+ */
3870
+ buildTypeRegistryReExports(coreFile) {
3871
+ if (this.hasRESTNormalization) {
3872
+ const relPath = this.relativeImportPath(
3873
+ coreFile.filename,
3874
+ "normalization/type-registry.ts"
3875
+ );
3876
+ coreFile.pushTo(this.reExportsSymbol, code`export { TypeRegistry } from "${relPath}";`);
3877
+ }
3878
+ if (this.hasGraphQL) {
3879
+ const relPath = this.relativeImportPath(
3880
+ coreFile.filename,
3881
+ "normalization/graphql-type-registry.ts"
3882
+ );
3883
+ coreFile.pushTo(
3884
+ this.reExportsSymbol,
3885
+ code`export { GraphQLTypeRegistry } from "${relPath}";`
3886
+ );
3887
+ }
3888
+ }
3889
+ /**
3890
+ * Re-exports individual generated type repository classes (e.g. `RecordRepresentationRepository`)
3891
+ * so custom bindings can extend or reference them without importing from internal paths.
3892
+ *
3893
+ * If both REST and GraphQL registries produce a repository with the same exported symbol,
3894
+ * the GraphQL version is aliased with a `GraphQL_` prefix to avoid collisions.
3895
+ */
3896
+ buildTypeRepositoryReExports(coreFile) {
3897
+ const restRepos = this.hasRESTNormalization ? [...this.services.typeRegistryGenerator.registeredTypes.values()] : [];
3898
+ const graphqlRepos = this.hasGraphQL ? [...this.services.graphqlTypeRegistryGenerator.registeredTypes.values()] : [];
3899
+ const restNames = new Set(restRepos.map((r) => r.typeClassRef.exportedSymbol));
3900
+ const graphqlNames = new Set(graphqlRepos.map((r) => r.typeClassRef.exportedSymbol));
3901
+ const conflicts = new Set([...restNames].filter((n) => graphqlNames.has(n)));
3902
+ for (const { typeClassRef } of restRepos) {
3903
+ if (!("filename" in typeClassRef)) continue;
3904
+ const relPath = this.relativeImportPath(coreFile.filename, typeClassRef.filename);
3905
+ coreFile.pushTo(
3906
+ this.reExportsSymbol,
3907
+ code`export { ${typeClassRef.exportedSymbol} } from "${relPath}";`
3908
+ );
3909
+ }
3910
+ for (const { typeClassRef } of graphqlRepos) {
3911
+ if (!("filename" in typeClassRef)) continue;
3912
+ const relPath = this.relativeImportPath(coreFile.filename, typeClassRef.filename);
3913
+ const symbol = typeClassRef.exportedSymbol;
3914
+ if (conflicts.has(symbol)) {
3915
+ coreFile.pushTo(
3916
+ this.reExportsSymbol,
3917
+ code`export { ${symbol} as GraphQL_${symbol} } from "${relPath}";`
3918
+ );
3919
+ } else {
3920
+ coreFile.pushTo(
3921
+ this.reExportsSymbol,
3922
+ code`export { ${symbol} } from "${relPath}";`
3923
+ );
3924
+ }
3925
+ }
3926
+ }
3927
+ /**
3928
+ * Re-exports all generated entity types so custom bindings can reference
3929
+ * domain models (e.g. `api_Item`) without importing from internal paths.
3930
+ */
3931
+ buildEntityTypeReExports(coreFile) {
3932
+ if (this.hasRESTNormalization) {
3933
+ const relPath = this.relativeImportPath(coreFile.filename, "types/types.ts");
3934
+ coreFile.pushTo(this.reExportsSymbol, code`export type * from "${relPath}";`);
3935
+ }
3804
3936
  }
3805
3937
  buildTypeInvalidation(typesWithNormalization) {
3806
3938
  return typesWithNormalization.reduce(
@@ -4233,9 +4365,9 @@ const GRAPHQL_DOCUMENT_ROOT_TYPE_REPOSITORY = {
4233
4365
  exportedSymbol: "GraphQLDocumentRootTypeRepository",
4234
4366
  isType: true
4235
4367
  };
4236
- const DOCUMENT_NODE = {
4368
+ const PARSED_GRAPHQL_DOCUMENT = {
4237
4369
  module: "@conduit-client/onestore-graphql-parser/v1",
4238
- exportedSymbol: "DocumentNode",
4370
+ exportedSymbol: "ParsedGraphQLDocument",
4239
4371
  isType: true
4240
4372
  };
4241
4373
  const GRAPHQL_QUERY_JSON_SCHEMA = {
@@ -4263,6 +4395,11 @@ const NAMED_FETCH_SERVICE$2 = {
4263
4395
  exportedSymbol: "NamedFetchService",
4264
4396
  isType: true
4265
4397
  };
4398
+ const GRAPHQL_REQUEST_PARAMS = {
4399
+ module: "@conduit-client/graphql-normalization/v1",
4400
+ exportedSymbol: "GraphQLRequestParams",
4401
+ isType: true
4402
+ };
4266
4403
  function GraphQLNormalizedCacheControlGeneratorMixin(Base, commandBaseClass, commandGeneratedClass) {
4267
4404
  return class GraphQLNormalizedCacheControl extends Base {
4268
4405
  constructor() {
@@ -4276,6 +4413,11 @@ function GraphQLNormalizedCacheControlGeneratorMixin(Base, commandBaseClass, com
4276
4413
  get template() {
4277
4414
  return [
4278
4415
  code`export type DocumentRootType = ${GRAPHQL_DOCUMENT_ROOT_TYPE_REPOSITORY}<${GRAPHQL_DATA$1}, ${GRAPHQL_DATA$1}>;`,
4416
+ // CommandConfig is the resolved internal config type (query: DocumentNode).
4417
+ // Config (below, from super.template) is the external-facing type (query: ParsedGraphQLDocument).
4418
+ // The binding layer resolves ParsedGraphQLDocument → DocumentNode before calling the command
4419
+ // constructor; the `as unknown as` cast in buildCommandClass bridges the two externally.
4420
+ code`type CommandConfig = ${GRAPHQL_REQUEST_PARAMS} & Record<string, unknown>;`,
4279
4421
  ...super.template
4280
4422
  ];
4281
4423
  }
@@ -4301,7 +4443,7 @@ function GraphQLNormalizedCacheControlGeneratorMixin(Base, commandBaseClass, com
4301
4443
  return this.buildCommandTypeGenerics();
4302
4444
  }
4303
4445
  get commandConstructorArgs() {
4304
- return code`protected config: Config, protected documentRootType: DocumentRootType, protected services: ${NAMED_CACHE_CONTROLLER_SERVICE} & ${NAMED_PUBSUB_SERVICE$3} & ${this.buildNetworkServicesCode()} & object`;
4446
+ return code`protected config: CommandConfig, protected documentRootType: DocumentRootType, protected services: ${NAMED_CACHE_CONTROLLER_SERVICE} & ${NAMED_PUBSUB_SERVICE$3} & ${this.buildNetworkServicesCode()} & object`;
4305
4447
  }
4306
4448
  get commandConstructorBody() {
4307
4449
  return code`super(config, documentRootType, services);`;
@@ -4352,7 +4494,7 @@ function GraphQLNormalizedCacheControlGeneratorMixin(Base, commandBaseClass, com
4352
4494
  }
4353
4495
  buildCommandConfigType() {
4354
4496
  return code`{
4355
- query: ${DOCUMENT_NODE};
4497
+ query: ${PARSED_GRAPHQL_DOCUMENT};
4356
4498
  variables?: Record<string, unknown>;
4357
4499
  operationName?: string;
4358
4500
  } & Record<string, unknown>`;