@arrirpc/codegen-ts 0.63.3 → 0.65.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 +21 -9
- package/dist/index.d.cts +8 -1
- package/dist/index.d.mts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +21 -9
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -88,7 +88,8 @@ function tsArrayFromSchema(schema, context) {
|
|
|
88
88
|
discriminatorKey: "",
|
|
89
89
|
discriminatorValue: "",
|
|
90
90
|
versionNumber: context.versionNumber,
|
|
91
|
-
usedFeatures: context.usedFeatures
|
|
91
|
+
usedFeatures: context.usedFeatures,
|
|
92
|
+
rpcGenerators: context.rpcGenerators
|
|
92
93
|
});
|
|
93
94
|
const typeName = `(${innerType.typeName})[]`;
|
|
94
95
|
const defaultValue = schema.nullable ? "null" : "[]";
|
|
@@ -225,7 +226,8 @@ function tsObjectFromSchema(schema, context) {
|
|
|
225
226
|
discriminatorKey: "",
|
|
226
227
|
discriminatorValue: "",
|
|
227
228
|
versionNumber: context.versionNumber,
|
|
228
|
-
usedFeatures: context.usedFeatures
|
|
229
|
+
usedFeatures: context.usedFeatures,
|
|
230
|
+
rpcGenerators: context.rpcGenerators
|
|
229
231
|
});
|
|
230
232
|
if (prop.content)
|
|
231
233
|
subContentParts.push(prop.content);
|
|
@@ -268,7 +270,8 @@ function tsObjectFromSchema(schema, context) {
|
|
|
268
270
|
discriminatorKey: "",
|
|
269
271
|
discriminatorValue: "",
|
|
270
272
|
versionNumber: context.versionNumber,
|
|
271
|
-
usedFeatures: context.usedFeatures
|
|
273
|
+
usedFeatures: context.usedFeatures,
|
|
274
|
+
rpcGenerators: context.rpcGenerators
|
|
272
275
|
});
|
|
273
276
|
if (prop.content)
|
|
274
277
|
subContentParts.push(prop.content);
|
|
@@ -396,7 +399,8 @@ function tsTaggedUnionFromSchema(schema, context) {
|
|
|
396
399
|
discriminatorKey,
|
|
397
400
|
discriminatorValue: key,
|
|
398
401
|
versionNumber: context.versionNumber,
|
|
399
|
-
usedFeatures: context.usedFeatures
|
|
402
|
+
usedFeatures: context.usedFeatures,
|
|
403
|
+
rpcGenerators: context.rpcGenerators
|
|
400
404
|
});
|
|
401
405
|
subTypes.push({ value: key, data: subType });
|
|
402
406
|
}
|
|
@@ -789,7 +793,8 @@ function tsRecordFromSchema(schema, context) {
|
|
|
789
793
|
discriminatorKey: "",
|
|
790
794
|
discriminatorValue: "",
|
|
791
795
|
versionNumber: context.versionNumber,
|
|
792
|
-
usedFeatures: context.usedFeatures
|
|
796
|
+
usedFeatures: context.usedFeatures,
|
|
797
|
+
rpcGenerators: context.rpcGenerators
|
|
793
798
|
});
|
|
794
799
|
const typeName = `Record<string, ${innerType.typeName}>`;
|
|
795
800
|
const defaultValue = schema.nullable ? "null" : "{}";
|
|
@@ -894,6 +899,9 @@ function tsRefFromSchema(schema, context) {
|
|
|
894
899
|
}
|
|
895
900
|
|
|
896
901
|
function tsRpcFromDefinition(def, context) {
|
|
902
|
+
const customFn = context.rpcGenerators[def.transport];
|
|
903
|
+
if (customFn)
|
|
904
|
+
return customFn(def, context);
|
|
897
905
|
switch (def.transport) {
|
|
898
906
|
case "http":
|
|
899
907
|
return httpRpcFromDefinition(def, context);
|
|
@@ -995,7 +1003,8 @@ function tsServiceFromDefinition(def, context) {
|
|
|
995
1003
|
discriminatorKey: "",
|
|
996
1004
|
discriminatorValue: "",
|
|
997
1005
|
versionNumber: context.versionNumber,
|
|
998
|
-
usedFeatures: context.usedFeatures
|
|
1006
|
+
usedFeatures: context.usedFeatures,
|
|
1007
|
+
rpcGenerators: context.rpcGenerators
|
|
999
1008
|
});
|
|
1000
1009
|
if (subService.content) {
|
|
1001
1010
|
subServices.push(subService);
|
|
@@ -1013,7 +1022,8 @@ function tsServiceFromDefinition(def, context) {
|
|
|
1013
1022
|
discriminatorKey: "",
|
|
1014
1023
|
discriminatorValue: "",
|
|
1015
1024
|
versionNumber: context.versionNumber,
|
|
1016
|
-
usedFeatures: context.usedFeatures
|
|
1025
|
+
usedFeatures: context.usedFeatures,
|
|
1026
|
+
rpcGenerators: context.rpcGenerators
|
|
1017
1027
|
});
|
|
1018
1028
|
if (rpc) {
|
|
1019
1029
|
rpcParts.push(rpc);
|
|
@@ -1103,7 +1113,8 @@ async function createTypescriptClient(def, options) {
|
|
|
1103
1113
|
usedFeatures: {
|
|
1104
1114
|
sse: false,
|
|
1105
1115
|
ws: false
|
|
1106
|
-
}
|
|
1116
|
+
},
|
|
1117
|
+
rpcGenerators: options.rpcGenerators ?? {}
|
|
1107
1118
|
};
|
|
1108
1119
|
const serviceDefinitions = codegenUtils.unflattenProcedures(def.procedures);
|
|
1109
1120
|
const mainService = tsServiceFromDefinition(serviceDefinitions, context);
|
|
@@ -1119,7 +1130,8 @@ async function createTypescriptClient(def, options) {
|
|
|
1119
1130
|
discriminatorKey: "",
|
|
1120
1131
|
discriminatorValue: "",
|
|
1121
1132
|
versionNumber: context.versionNumber,
|
|
1122
|
-
usedFeatures: context.usedFeatures
|
|
1133
|
+
usedFeatures: context.usedFeatures,
|
|
1134
|
+
rpcGenerators: context.rpcGenerators
|
|
1123
1135
|
});
|
|
1124
1136
|
if (result2.content) {
|
|
1125
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
|
@@ -82,7 +82,8 @@ function tsArrayFromSchema(schema, context) {
|
|
|
82
82
|
discriminatorKey: "",
|
|
83
83
|
discriminatorValue: "",
|
|
84
84
|
versionNumber: context.versionNumber,
|
|
85
|
-
usedFeatures: context.usedFeatures
|
|
85
|
+
usedFeatures: context.usedFeatures,
|
|
86
|
+
rpcGenerators: context.rpcGenerators
|
|
86
87
|
});
|
|
87
88
|
const typeName = `(${innerType.typeName})[]`;
|
|
88
89
|
const defaultValue = schema.nullable ? "null" : "[]";
|
|
@@ -219,7 +220,8 @@ function tsObjectFromSchema(schema, context) {
|
|
|
219
220
|
discriminatorKey: "",
|
|
220
221
|
discriminatorValue: "",
|
|
221
222
|
versionNumber: context.versionNumber,
|
|
222
|
-
usedFeatures: context.usedFeatures
|
|
223
|
+
usedFeatures: context.usedFeatures,
|
|
224
|
+
rpcGenerators: context.rpcGenerators
|
|
223
225
|
});
|
|
224
226
|
if (prop.content)
|
|
225
227
|
subContentParts.push(prop.content);
|
|
@@ -262,7 +264,8 @@ function tsObjectFromSchema(schema, context) {
|
|
|
262
264
|
discriminatorKey: "",
|
|
263
265
|
discriminatorValue: "",
|
|
264
266
|
versionNumber: context.versionNumber,
|
|
265
|
-
usedFeatures: context.usedFeatures
|
|
267
|
+
usedFeatures: context.usedFeatures,
|
|
268
|
+
rpcGenerators: context.rpcGenerators
|
|
266
269
|
});
|
|
267
270
|
if (prop.content)
|
|
268
271
|
subContentParts.push(prop.content);
|
|
@@ -390,7 +393,8 @@ function tsTaggedUnionFromSchema(schema, context) {
|
|
|
390
393
|
discriminatorKey,
|
|
391
394
|
discriminatorValue: key,
|
|
392
395
|
versionNumber: context.versionNumber,
|
|
393
|
-
usedFeatures: context.usedFeatures
|
|
396
|
+
usedFeatures: context.usedFeatures,
|
|
397
|
+
rpcGenerators: context.rpcGenerators
|
|
394
398
|
});
|
|
395
399
|
subTypes.push({ value: key, data: subType });
|
|
396
400
|
}
|
|
@@ -783,7 +787,8 @@ function tsRecordFromSchema(schema, context) {
|
|
|
783
787
|
discriminatorKey: "",
|
|
784
788
|
discriminatorValue: "",
|
|
785
789
|
versionNumber: context.versionNumber,
|
|
786
|
-
usedFeatures: context.usedFeatures
|
|
790
|
+
usedFeatures: context.usedFeatures,
|
|
791
|
+
rpcGenerators: context.rpcGenerators
|
|
787
792
|
});
|
|
788
793
|
const typeName = `Record<string, ${innerType.typeName}>`;
|
|
789
794
|
const defaultValue = schema.nullable ? "null" : "{}";
|
|
@@ -888,6 +893,9 @@ function tsRefFromSchema(schema, context) {
|
|
|
888
893
|
}
|
|
889
894
|
|
|
890
895
|
function tsRpcFromDefinition(def, context) {
|
|
896
|
+
const customFn = context.rpcGenerators[def.transport];
|
|
897
|
+
if (customFn)
|
|
898
|
+
return customFn(def, context);
|
|
891
899
|
switch (def.transport) {
|
|
892
900
|
case "http":
|
|
893
901
|
return httpRpcFromDefinition(def, context);
|
|
@@ -989,7 +997,8 @@ function tsServiceFromDefinition(def, context) {
|
|
|
989
997
|
discriminatorKey: "",
|
|
990
998
|
discriminatorValue: "",
|
|
991
999
|
versionNumber: context.versionNumber,
|
|
992
|
-
usedFeatures: context.usedFeatures
|
|
1000
|
+
usedFeatures: context.usedFeatures,
|
|
1001
|
+
rpcGenerators: context.rpcGenerators
|
|
993
1002
|
});
|
|
994
1003
|
if (subService.content) {
|
|
995
1004
|
subServices.push(subService);
|
|
@@ -1007,7 +1016,8 @@ function tsServiceFromDefinition(def, context) {
|
|
|
1007
1016
|
discriminatorKey: "",
|
|
1008
1017
|
discriminatorValue: "",
|
|
1009
1018
|
versionNumber: context.versionNumber,
|
|
1010
|
-
usedFeatures: context.usedFeatures
|
|
1019
|
+
usedFeatures: context.usedFeatures,
|
|
1020
|
+
rpcGenerators: context.rpcGenerators
|
|
1011
1021
|
});
|
|
1012
1022
|
if (rpc) {
|
|
1013
1023
|
rpcParts.push(rpc);
|
|
@@ -1097,7 +1107,8 @@ async function createTypescriptClient(def, options) {
|
|
|
1097
1107
|
usedFeatures: {
|
|
1098
1108
|
sse: false,
|
|
1099
1109
|
ws: false
|
|
1100
|
-
}
|
|
1110
|
+
},
|
|
1111
|
+
rpcGenerators: options.rpcGenerators ?? {}
|
|
1101
1112
|
};
|
|
1102
1113
|
const serviceDefinitions = unflattenProcedures(def.procedures);
|
|
1103
1114
|
const mainService = tsServiceFromDefinition(serviceDefinitions, context);
|
|
@@ -1113,7 +1124,8 @@ async function createTypescriptClient(def, options) {
|
|
|
1113
1124
|
discriminatorKey: "",
|
|
1114
1125
|
discriminatorValue: "",
|
|
1115
1126
|
versionNumber: context.versionNumber,
|
|
1116
|
-
usedFeatures: context.usedFeatures
|
|
1127
|
+
usedFeatures: context.usedFeatures,
|
|
1128
|
+
rpcGenerators: context.rpcGenerators
|
|
1117
1129
|
});
|
|
1118
1130
|
if (result2.content) {
|
|
1119
1131
|
types.push(result2.content);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/codegen-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.65.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.
|
|
26
|
+
"@arrirpc/codegen-utils": "0.65.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {}
|
|
29
29
|
}
|