@arrirpc/codegen-ts 0.76.4 → 0.77.1

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/README.md CHANGED
@@ -20,11 +20,14 @@ export default defineConfig({
20
20
 
21
21
  **Options:**
22
22
 
23
- | Name | Description |
24
- | --------------------- | ---------------------------------------------------- |
25
- | clientName (required) | The name of the generated client |
26
- | outputFile (required) | Path to a file that will be created by the generator |
27
- | prettierOptions | Formatting options for the generated code |
23
+ | Name | Description |
24
+ | --------------------- | ---------------------------------------------------------- |
25
+ | outputFile (required) | Path to a file that will be created by the generator |
26
+ | clientName | The name of the generated client |
27
+ | typePrefix | Add a prefix to the generated type names |
28
+ | rootService | Set the root service of the generated client |
29
+ | prettierOptions | Formatting options for the generated code |
30
+ | rpcGenerators | Override the default function used for creating procedures |
28
31
 
29
32
  ### 2) Install the TS client library
30
33
 
package/dist/index.cjs CHANGED
@@ -1109,7 +1109,7 @@ const typescriptClientGenerator = codegenUtils.defineGeneratorPlugin(
1109
1109
  async function createTypescriptClient(def, options) {
1110
1110
  const types = [];
1111
1111
  const context = {
1112
- clientName: options.clientName,
1112
+ clientName: options.clientName ?? "Client",
1113
1113
  typePrefix: options.typePrefix ?? "",
1114
1114
  generatedTypes: [],
1115
1115
  instancePath: "",
@@ -1121,7 +1121,10 @@ async function createTypescriptClient(def, options) {
1121
1121
  },
1122
1122
  rpcGenerators: options.rpcGenerators ?? {}
1123
1123
  };
1124
- const serviceDefinitions = codegenUtils.unflattenProcedures(def.procedures);
1124
+ const serviceDefinitions = codegenUtils.unflattenProcedures(
1125
+ def.procedures,
1126
+ options.rootService
1127
+ );
1125
1128
  const mainService = tsServiceFromDefinition(serviceDefinitions, context);
1126
1129
  for (const key of Object.keys(def.definitions)) {
1127
1130
  const typeDef = def.definitions[key];
package/dist/index.d.cts CHANGED
@@ -32,24 +32,50 @@ interface CodegenContext {
32
32
  sse: boolean;
33
33
  ws: boolean;
34
34
  };
35
- rpcGenerators: Record<string, RpcGenerator>;
35
+ rpcGenerators: Partial<Record<string, RpcGenerator>>;
36
36
  }
37
37
  declare function getJsDocComment(metadata: Schema['metadata']): string;
38
38
  declare function validVarName(name: string): string;
39
39
  declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
40
40
 
41
41
  interface TypescriptGeneratorOptions {
42
- clientName: string;
42
+ /**
43
+ * Defaults to 'Client'
44
+ */
45
+ clientName?: string;
43
46
  outputFile: string;
47
+ /**
48
+ * Add a prefix to the generated types
49
+ */
44
50
  typePrefix?: string;
51
+ /**
52
+ * Set the root service of the generated client
53
+ *
54
+ * __Example:__
55
+ *
56
+ * Given the following procedures:
57
+ * - users.getUser
58
+ * - users.updateUser
59
+ * - posts.getPost
60
+ * - posts.updatePosts
61
+ *
62
+ * Setting the rootService to `posts` means the generated client will only have the following procedures:
63
+ * - getPost
64
+ * - updatePosts
65
+ */
66
+ rootService?: string;
67
+ /**
68
+ * Options for how to format the outputted typescript code
69
+ */
45
70
  prettierOptions?: Omit<prettier.Config, 'parser'>;
46
71
  /**
47
72
  * Override the default functions used for creating procedures
48
73
  */
49
- rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator>;
74
+ rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
50
75
  }
51
76
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
52
77
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
53
78
  declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
54
79
 
55
- export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
80
+ export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
81
+ export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
package/dist/index.d.mts CHANGED
@@ -32,24 +32,50 @@ interface CodegenContext {
32
32
  sse: boolean;
33
33
  ws: boolean;
34
34
  };
35
- rpcGenerators: Record<string, RpcGenerator>;
35
+ rpcGenerators: Partial<Record<string, RpcGenerator>>;
36
36
  }
37
37
  declare function getJsDocComment(metadata: Schema['metadata']): string;
38
38
  declare function validVarName(name: string): string;
39
39
  declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
40
40
 
41
41
  interface TypescriptGeneratorOptions {
42
- clientName: string;
42
+ /**
43
+ * Defaults to 'Client'
44
+ */
45
+ clientName?: string;
43
46
  outputFile: string;
47
+ /**
48
+ * Add a prefix to the generated types
49
+ */
44
50
  typePrefix?: string;
51
+ /**
52
+ * Set the root service of the generated client
53
+ *
54
+ * __Example:__
55
+ *
56
+ * Given the following procedures:
57
+ * - users.getUser
58
+ * - users.updateUser
59
+ * - posts.getPost
60
+ * - posts.updatePosts
61
+ *
62
+ * Setting the rootService to `posts` means the generated client will only have the following procedures:
63
+ * - getPost
64
+ * - updatePosts
65
+ */
66
+ rootService?: string;
67
+ /**
68
+ * Options for how to format the outputted typescript code
69
+ */
45
70
  prettierOptions?: Omit<prettier.Config, 'parser'>;
46
71
  /**
47
72
  * Override the default functions used for creating procedures
48
73
  */
49
- rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator>;
74
+ rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
50
75
  }
51
76
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
52
77
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
53
78
  declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
54
79
 
55
- export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
80
+ export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
81
+ export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
package/dist/index.d.ts CHANGED
@@ -32,24 +32,50 @@ interface CodegenContext {
32
32
  sse: boolean;
33
33
  ws: boolean;
34
34
  };
35
- rpcGenerators: Record<string, RpcGenerator>;
35
+ rpcGenerators: Partial<Record<string, RpcGenerator>>;
36
36
  }
37
37
  declare function getJsDocComment(metadata: Schema['metadata']): string;
38
38
  declare function validVarName(name: string): string;
39
39
  declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
40
40
 
41
41
  interface TypescriptGeneratorOptions {
42
- clientName: string;
42
+ /**
43
+ * Defaults to 'Client'
44
+ */
45
+ clientName?: string;
43
46
  outputFile: string;
47
+ /**
48
+ * Add a prefix to the generated types
49
+ */
44
50
  typePrefix?: string;
51
+ /**
52
+ * Set the root service of the generated client
53
+ *
54
+ * __Example:__
55
+ *
56
+ * Given the following procedures:
57
+ * - users.getUser
58
+ * - users.updateUser
59
+ * - posts.getPost
60
+ * - posts.updatePosts
61
+ *
62
+ * Setting the rootService to `posts` means the generated client will only have the following procedures:
63
+ * - getPost
64
+ * - updatePosts
65
+ */
66
+ rootService?: string;
67
+ /**
68
+ * Options for how to format the outputted typescript code
69
+ */
45
70
  prettierOptions?: Omit<prettier.Config, 'parser'>;
46
71
  /**
47
72
  * Override the default functions used for creating procedures
48
73
  */
49
- rpcGenerators?: Record<RpcDefinition['transport'], RpcGenerator>;
74
+ rpcGenerators?: Partial<Record<RpcDefinition['transport'], RpcGenerator>>;
50
75
  }
51
76
  declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
52
77
  declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
53
78
  declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
54
79
 
55
- export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
80
+ export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
81
+ export type { CodegenContext, RpcGenerator, TsProperty, TypescriptGeneratorOptions };
package/dist/index.mjs CHANGED
@@ -1103,7 +1103,7 @@ const typescriptClientGenerator = defineGeneratorPlugin(
1103
1103
  async function createTypescriptClient(def, options) {
1104
1104
  const types = [];
1105
1105
  const context = {
1106
- clientName: options.clientName,
1106
+ clientName: options.clientName ?? "Client",
1107
1107
  typePrefix: options.typePrefix ?? "",
1108
1108
  generatedTypes: [],
1109
1109
  instancePath: "",
@@ -1115,7 +1115,10 @@ async function createTypescriptClient(def, options) {
1115
1115
  },
1116
1116
  rpcGenerators: options.rpcGenerators ?? {}
1117
1117
  };
1118
- const serviceDefinitions = unflattenProcedures(def.procedures);
1118
+ const serviceDefinitions = unflattenProcedures(
1119
+ def.procedures,
1120
+ options.rootService
1121
+ );
1119
1122
  const mainService = tsServiceFromDefinition(serviceDefinitions, context);
1120
1123
  for (const key of Object.keys(def.definitions)) {
1121
1124
  const typeDef = def.definitions[key];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/codegen-ts",
3
- "version": "0.76.4",
3
+ "version": "0.77.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -23,6 +23,6 @@
23
23
  ],
24
24
  "dependencies": {
25
25
  "prettier": "^3.5.3",
26
- "@arrirpc/codegen-utils": "0.76.4"
26
+ "@arrirpc/codegen-utils": "0.77.1"
27
27
  }
28
28
  }