@arrirpc/codegen-ts 0.63.2 → 0.64.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.
package/dist/index.cjs CHANGED
@@ -68,9 +68,12 @@ function getTsTypeName(schema, context) {
68
68
  );
69
69
  return validVarName(name2);
70
70
  }
71
- const name = codegenUtils.pascalCase(context.instancePath.split("/").join("_"), {
72
- normalize: true
73
- });
71
+ const name = codegenUtils.pascalCase(
72
+ context.instancePath.split("/").join("_").split("[").join("_").split("]").join("_"),
73
+ {
74
+ normalize: true
75
+ }
76
+ );
74
77
  return validVarName(name);
75
78
  }
76
79
 
@@ -85,7 +88,8 @@ function tsArrayFromSchema(schema, context) {
85
88
  discriminatorKey: "",
86
89
  discriminatorValue: "",
87
90
  versionNumber: context.versionNumber,
88
- usedFeatures: context.usedFeatures
91
+ usedFeatures: context.usedFeatures,
92
+ rpcGenerators: context.rpcGenerators
89
93
  });
90
94
  const typeName = `(${innerType.typeName})[]`;
91
95
  const defaultValue = schema.nullable ? "null" : "[]";
@@ -222,7 +226,8 @@ function tsObjectFromSchema(schema, context) {
222
226
  discriminatorKey: "",
223
227
  discriminatorValue: "",
224
228
  versionNumber: context.versionNumber,
225
- usedFeatures: context.usedFeatures
229
+ usedFeatures: context.usedFeatures,
230
+ rpcGenerators: context.rpcGenerators
226
231
  });
227
232
  if (prop.content)
228
233
  subContentParts.push(prop.content);
@@ -265,7 +270,8 @@ function tsObjectFromSchema(schema, context) {
265
270
  discriminatorKey: "",
266
271
  discriminatorValue: "",
267
272
  versionNumber: context.versionNumber,
268
- usedFeatures: context.usedFeatures
273
+ usedFeatures: context.usedFeatures,
274
+ rpcGenerators: context.rpcGenerators
269
275
  });
270
276
  if (prop.content)
271
277
  subContentParts.push(prop.content);
@@ -393,7 +399,8 @@ function tsTaggedUnionFromSchema(schema, context) {
393
399
  discriminatorKey,
394
400
  discriminatorValue: key,
395
401
  versionNumber: context.versionNumber,
396
- usedFeatures: context.usedFeatures
402
+ usedFeatures: context.usedFeatures,
403
+ rpcGenerators: context.rpcGenerators
397
404
  });
398
405
  subTypes.push({ value: key, data: subType });
399
406
  }
@@ -786,7 +793,8 @@ function tsRecordFromSchema(schema, context) {
786
793
  discriminatorKey: "",
787
794
  discriminatorValue: "",
788
795
  versionNumber: context.versionNumber,
789
- usedFeatures: context.usedFeatures
796
+ usedFeatures: context.usedFeatures,
797
+ rpcGenerators: context.rpcGenerators
790
798
  });
791
799
  const typeName = `Record<string, ${innerType.typeName}>`;
792
800
  const defaultValue = schema.nullable ? "null" : "{}";
@@ -891,6 +899,9 @@ function tsRefFromSchema(schema, context) {
891
899
  }
892
900
 
893
901
  function tsRpcFromDefinition(def, context) {
902
+ const customFn = context.rpcGenerators[def.transport];
903
+ if (customFn)
904
+ return customFn(def, context);
894
905
  switch (def.transport) {
895
906
  case "http":
896
907
  return httpRpcFromDefinition(def, context);
@@ -992,7 +1003,8 @@ function tsServiceFromDefinition(def, context) {
992
1003
  discriminatorKey: "",
993
1004
  discriminatorValue: "",
994
1005
  versionNumber: context.versionNumber,
995
- usedFeatures: context.usedFeatures
1006
+ usedFeatures: context.usedFeatures,
1007
+ rpcGenerators: context.rpcGenerators
996
1008
  });
997
1009
  if (subService.content) {
998
1010
  subServices.push(subService);
@@ -1010,7 +1022,8 @@ function tsServiceFromDefinition(def, context) {
1010
1022
  discriminatorKey: "",
1011
1023
  discriminatorValue: "",
1012
1024
  versionNumber: context.versionNumber,
1013
- usedFeatures: context.usedFeatures
1025
+ usedFeatures: context.usedFeatures,
1026
+ rpcGenerators: context.rpcGenerators
1014
1027
  });
1015
1028
  if (rpc) {
1016
1029
  rpcParts.push(rpc);
@@ -1100,7 +1113,8 @@ async function createTypescriptClient(def, options) {
1100
1113
  usedFeatures: {
1101
1114
  sse: false,
1102
1115
  ws: false
1103
- }
1116
+ },
1117
+ rpcGenerators: options.rpcGenerators ?? {}
1104
1118
  };
1105
1119
  const serviceDefinitions = codegenUtils.unflattenProcedures(def.procedures);
1106
1120
  const mainService = tsServiceFromDefinition(serviceDefinitions, context);
@@ -1116,7 +1130,8 @@ async function createTypescriptClient(def, options) {
1116
1130
  discriminatorKey: "",
1117
1131
  discriminatorValue: "",
1118
1132
  versionNumber: context.versionNumber,
1119
- usedFeatures: context.usedFeatures
1133
+ usedFeatures: context.usedFeatures,
1134
+ rpcGenerators: context.rpcGenerators
1120
1135
  });
1121
1136
  if (result2.content) {
1122
1137
  types.push(result2.content);
package/dist/index.d.cts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
2
- import { AppDefinition, Schema } from '@arrirpc/codegen-utils';
2
+ import { RpcDefinition, AppDefinition, Schema } from '@arrirpc/codegen-utils';
3
3
  import prettier from 'prettier';
4
4
 
5
+ type RpcGeneratorFunction = (def: RpcDefinition, context: CodegenContext) => string;
6
+
5
7
  interface TsProperty {
6
8
  typeName: string;
7
9
  defaultValue: string;
@@ -25,6 +27,7 @@ interface CodegenContext {
25
27
  sse: boolean;
26
28
  ws: boolean;
27
29
  };
30
+ rpcGenerators: Record<string, RpcGeneratorFunction>;
28
31
  }
29
32
 
30
33
  interface TypescriptGeneratorOptions {
@@ -32,6 +35,10 @@ interface TypescriptGeneratorOptions {
32
35
  outputFile: string;
33
36
  typePrefix?: string;
34
37
  prettierOptions?: Omit<prettier.Config, "parser">;
38
+ /**
39
+ * Override the default functions used for creating procedures
40
+ */
41
+ rpcGenerators?: Record<RpcDefinition["transport"], RpcGeneratorFunction>;
35
42
  }
36
43
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
37
44
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
package/dist/index.d.mts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
2
- import { AppDefinition, Schema } from '@arrirpc/codegen-utils';
2
+ import { RpcDefinition, AppDefinition, Schema } from '@arrirpc/codegen-utils';
3
3
  import prettier from 'prettier';
4
4
 
5
+ type RpcGeneratorFunction = (def: RpcDefinition, context: CodegenContext) => string;
6
+
5
7
  interface TsProperty {
6
8
  typeName: string;
7
9
  defaultValue: string;
@@ -25,6 +27,7 @@ interface CodegenContext {
25
27
  sse: boolean;
26
28
  ws: boolean;
27
29
  };
30
+ rpcGenerators: Record<string, RpcGeneratorFunction>;
28
31
  }
29
32
 
30
33
  interface TypescriptGeneratorOptions {
@@ -32,6 +35,10 @@ interface TypescriptGeneratorOptions {
32
35
  outputFile: string;
33
36
  typePrefix?: string;
34
37
  prettierOptions?: Omit<prettier.Config, "parser">;
38
+ /**
39
+ * Override the default functions used for creating procedures
40
+ */
41
+ rpcGenerators?: Record<RpcDefinition["transport"], RpcGeneratorFunction>;
35
42
  }
36
43
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
37
44
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
2
- import { AppDefinition, Schema } from '@arrirpc/codegen-utils';
2
+ import { RpcDefinition, AppDefinition, Schema } from '@arrirpc/codegen-utils';
3
3
  import prettier from 'prettier';
4
4
 
5
+ type RpcGeneratorFunction = (def: RpcDefinition, context: CodegenContext) => string;
6
+
5
7
  interface TsProperty {
6
8
  typeName: string;
7
9
  defaultValue: string;
@@ -25,6 +27,7 @@ interface CodegenContext {
25
27
  sse: boolean;
26
28
  ws: boolean;
27
29
  };
30
+ rpcGenerators: Record<string, RpcGeneratorFunction>;
28
31
  }
29
32
 
30
33
  interface TypescriptGeneratorOptions {
@@ -32,6 +35,10 @@ interface TypescriptGeneratorOptions {
32
35
  outputFile: string;
33
36
  typePrefix?: string;
34
37
  prettierOptions?: Omit<prettier.Config, "parser">;
38
+ /**
39
+ * Override the default functions used for creating procedures
40
+ */
41
+ rpcGenerators?: Record<RpcDefinition["transport"], RpcGeneratorFunction>;
35
42
  }
36
43
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
37
44
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
package/dist/index.mjs CHANGED
@@ -62,9 +62,12 @@ function getTsTypeName(schema, context) {
62
62
  );
63
63
  return validVarName(name2);
64
64
  }
65
- const name = pascalCase(context.instancePath.split("/").join("_"), {
66
- normalize: true
67
- });
65
+ const name = pascalCase(
66
+ context.instancePath.split("/").join("_").split("[").join("_").split("]").join("_"),
67
+ {
68
+ normalize: true
69
+ }
70
+ );
68
71
  return validVarName(name);
69
72
  }
70
73
 
@@ -79,7 +82,8 @@ function tsArrayFromSchema(schema, context) {
79
82
  discriminatorKey: "",
80
83
  discriminatorValue: "",
81
84
  versionNumber: context.versionNumber,
82
- usedFeatures: context.usedFeatures
85
+ usedFeatures: context.usedFeatures,
86
+ rpcGenerators: context.rpcGenerators
83
87
  });
84
88
  const typeName = `(${innerType.typeName})[]`;
85
89
  const defaultValue = schema.nullable ? "null" : "[]";
@@ -216,7 +220,8 @@ function tsObjectFromSchema(schema, context) {
216
220
  discriminatorKey: "",
217
221
  discriminatorValue: "",
218
222
  versionNumber: context.versionNumber,
219
- usedFeatures: context.usedFeatures
223
+ usedFeatures: context.usedFeatures,
224
+ rpcGenerators: context.rpcGenerators
220
225
  });
221
226
  if (prop.content)
222
227
  subContentParts.push(prop.content);
@@ -259,7 +264,8 @@ function tsObjectFromSchema(schema, context) {
259
264
  discriminatorKey: "",
260
265
  discriminatorValue: "",
261
266
  versionNumber: context.versionNumber,
262
- usedFeatures: context.usedFeatures
267
+ usedFeatures: context.usedFeatures,
268
+ rpcGenerators: context.rpcGenerators
263
269
  });
264
270
  if (prop.content)
265
271
  subContentParts.push(prop.content);
@@ -387,7 +393,8 @@ function tsTaggedUnionFromSchema(schema, context) {
387
393
  discriminatorKey,
388
394
  discriminatorValue: key,
389
395
  versionNumber: context.versionNumber,
390
- usedFeatures: context.usedFeatures
396
+ usedFeatures: context.usedFeatures,
397
+ rpcGenerators: context.rpcGenerators
391
398
  });
392
399
  subTypes.push({ value: key, data: subType });
393
400
  }
@@ -780,7 +787,8 @@ function tsRecordFromSchema(schema, context) {
780
787
  discriminatorKey: "",
781
788
  discriminatorValue: "",
782
789
  versionNumber: context.versionNumber,
783
- usedFeatures: context.usedFeatures
790
+ usedFeatures: context.usedFeatures,
791
+ rpcGenerators: context.rpcGenerators
784
792
  });
785
793
  const typeName = `Record<string, ${innerType.typeName}>`;
786
794
  const defaultValue = schema.nullable ? "null" : "{}";
@@ -885,6 +893,9 @@ function tsRefFromSchema(schema, context) {
885
893
  }
886
894
 
887
895
  function tsRpcFromDefinition(def, context) {
896
+ const customFn = context.rpcGenerators[def.transport];
897
+ if (customFn)
898
+ return customFn(def, context);
888
899
  switch (def.transport) {
889
900
  case "http":
890
901
  return httpRpcFromDefinition(def, context);
@@ -986,7 +997,8 @@ function tsServiceFromDefinition(def, context) {
986
997
  discriminatorKey: "",
987
998
  discriminatorValue: "",
988
999
  versionNumber: context.versionNumber,
989
- usedFeatures: context.usedFeatures
1000
+ usedFeatures: context.usedFeatures,
1001
+ rpcGenerators: context.rpcGenerators
990
1002
  });
991
1003
  if (subService.content) {
992
1004
  subServices.push(subService);
@@ -1004,7 +1016,8 @@ function tsServiceFromDefinition(def, context) {
1004
1016
  discriminatorKey: "",
1005
1017
  discriminatorValue: "",
1006
1018
  versionNumber: context.versionNumber,
1007
- usedFeatures: context.usedFeatures
1019
+ usedFeatures: context.usedFeatures,
1020
+ rpcGenerators: context.rpcGenerators
1008
1021
  });
1009
1022
  if (rpc) {
1010
1023
  rpcParts.push(rpc);
@@ -1094,7 +1107,8 @@ async function createTypescriptClient(def, options) {
1094
1107
  usedFeatures: {
1095
1108
  sse: false,
1096
1109
  ws: false
1097
- }
1110
+ },
1111
+ rpcGenerators: options.rpcGenerators ?? {}
1098
1112
  };
1099
1113
  const serviceDefinitions = unflattenProcedures(def.procedures);
1100
1114
  const mainService = tsServiceFromDefinition(serviceDefinitions, context);
@@ -1110,7 +1124,8 @@ async function createTypescriptClient(def, options) {
1110
1124
  discriminatorKey: "",
1111
1125
  discriminatorValue: "",
1112
1126
  versionNumber: context.versionNumber,
1113
- usedFeatures: context.usedFeatures
1127
+ usedFeatures: context.usedFeatures,
1128
+ rpcGenerators: context.rpcGenerators
1114
1129
  });
1115
1130
  if (result2.content) {
1116
1131
  types.push(result2.content);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/codegen-ts",
3
- "version": "0.63.2",
3
+ "version": "0.64.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -23,7 +23,7 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "prettier": "^3.3.3",
26
- "@arrirpc/codegen-utils": "0.63.2"
26
+ "@arrirpc/codegen-utils": "0.64.0"
27
27
  },
28
28
  "devDependencies": {}
29
29
  }