@arrirpc/codegen-ts 0.65.2 → 0.67.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 +18 -7
- package/dist/index.d.cts +13 -5
- package/dist/index.d.mts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.mjs +11 -8
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -231,7 +231,7 @@ function tsObjectFromSchema(schema, context) {
|
|
|
231
231
|
});
|
|
232
232
|
if (prop.content)
|
|
233
233
|
subContentParts.push(prop.content);
|
|
234
|
-
const fieldName = validVarName(codegenUtils.camelCase(key));
|
|
234
|
+
const fieldName = validVarName(codegenUtils.camelCase(key, { normalize: true }));
|
|
235
235
|
fieldParts.push(
|
|
236
236
|
`${getJsDocComment(subSchema.metadata)}${fieldName}: ${prop.typeName},`
|
|
237
237
|
);
|
|
@@ -275,7 +275,7 @@ function tsObjectFromSchema(schema, context) {
|
|
|
275
275
|
});
|
|
276
276
|
if (prop.content)
|
|
277
277
|
subContentParts.push(prop.content);
|
|
278
|
-
const fieldName = validVarName(codegenUtils.camelCase(key));
|
|
278
|
+
const fieldName = validVarName(codegenUtils.camelCase(key, { normalize: true }));
|
|
279
279
|
fieldParts.push(
|
|
280
280
|
`${getJsDocComment(subSchema.metadata)}${fieldName}?: ${prop.typeName},`
|
|
281
281
|
);
|
|
@@ -285,15 +285,15 @@ function tsObjectFromSchema(schema, context) {
|
|
|
285
285
|
${prop.fromJsonTemplate(`input.${key}`, tempKey)}
|
|
286
286
|
}`);
|
|
287
287
|
if (hasKey) {
|
|
288
|
-
toJsonParts.push(`if (typeof input.${
|
|
288
|
+
toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
|
|
289
289
|
json += \`,"${key}":\`;
|
|
290
|
-
${prop.toJsonTemplate(`input.${
|
|
290
|
+
${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
|
|
291
291
|
}`);
|
|
292
292
|
} else {
|
|
293
|
-
toJsonParts.push(`if (typeof input.${
|
|
293
|
+
toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
|
|
294
294
|
if (_hasKey) json += ',';
|
|
295
295
|
json += '"${key}":';
|
|
296
|
-
${prop.toJsonTemplate(`input.${
|
|
296
|
+
${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
|
|
297
297
|
_hasKey = true;
|
|
298
298
|
}`);
|
|
299
299
|
}
|
|
@@ -898,6 +898,9 @@ function tsRefFromSchema(schema, context) {
|
|
|
898
898
|
};
|
|
899
899
|
}
|
|
900
900
|
|
|
901
|
+
function defineRpcGenerator(fn) {
|
|
902
|
+
return fn;
|
|
903
|
+
}
|
|
901
904
|
function tsRpcFromDefinition(def, context) {
|
|
902
905
|
const customFn = context.rpcGenerators[def.transport];
|
|
903
906
|
if (customFn)
|
|
@@ -1080,7 +1083,7 @@ function getServiceName(context) {
|
|
|
1080
1083
|
|
|
1081
1084
|
const typescriptClientGenerator = codegenUtils.defineGeneratorPlugin(
|
|
1082
1085
|
(options) => ({
|
|
1083
|
-
|
|
1086
|
+
run: async (def) => {
|
|
1084
1087
|
if (!options.clientName) {
|
|
1085
1088
|
throw new Error("Name is requires");
|
|
1086
1089
|
}
|
|
@@ -1239,5 +1242,13 @@ function tsTypeFromSchema(schema, context) {
|
|
|
1239
1242
|
}
|
|
1240
1243
|
|
|
1241
1244
|
exports.createTypescriptClient = createTypescriptClient;
|
|
1245
|
+
exports.defineRpcGenerator = defineRpcGenerator;
|
|
1246
|
+
exports.getJsDocComment = getJsDocComment;
|
|
1247
|
+
exports.getRpcKey = getRpcKey;
|
|
1248
|
+
exports.getTsTypeName = getTsTypeName;
|
|
1249
|
+
exports.httpRpcFromDefinition = httpRpcFromDefinition;
|
|
1250
|
+
exports.tsRpcFromDefinition = tsRpcFromDefinition;
|
|
1242
1251
|
exports.tsTypeFromSchema = tsTypeFromSchema;
|
|
1243
1252
|
exports.typescriptClientGenerator = typescriptClientGenerator;
|
|
1253
|
+
exports.validVarName = validVarName;
|
|
1254
|
+
exports.wsRpcFromDefinition = wsRpcFromDefinition;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
|
|
2
|
-
import { RpcDefinition,
|
|
2
|
+
import { RpcDefinition, HttpRpcDefinition, WsRpcDefinition, Schema, AppDefinition } from '@arrirpc/codegen-utils';
|
|
3
3
|
import prettier from 'prettier';
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type RpcGenerator = (def: RpcDefinition, context: CodegenContext) => string;
|
|
6
|
+
declare function defineRpcGenerator(fn: RpcGenerator): RpcGenerator;
|
|
7
|
+
declare function tsRpcFromDefinition(def: RpcDefinition, context: CodegenContext): string;
|
|
8
|
+
declare function httpRpcFromDefinition(def: HttpRpcDefinition, context: CodegenContext): string;
|
|
9
|
+
declare function wsRpcFromDefinition(def: WsRpcDefinition, context: CodegenContext): string;
|
|
10
|
+
declare function getRpcKey(context: CodegenContext): string;
|
|
6
11
|
|
|
7
12
|
interface TsProperty {
|
|
8
13
|
typeName: string;
|
|
@@ -27,8 +32,11 @@ interface CodegenContext {
|
|
|
27
32
|
sse: boolean;
|
|
28
33
|
ws: boolean;
|
|
29
34
|
};
|
|
30
|
-
rpcGenerators: Record<string,
|
|
35
|
+
rpcGenerators: Record<string, RpcGenerator>;
|
|
31
36
|
}
|
|
37
|
+
declare function getJsDocComment(metadata: Schema["metadata"]): string;
|
|
38
|
+
declare function validVarName(name: string): string;
|
|
39
|
+
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
32
40
|
|
|
33
41
|
interface TypescriptGeneratorOptions {
|
|
34
42
|
clientName: string;
|
|
@@ -38,10 +46,10 @@ interface TypescriptGeneratorOptions {
|
|
|
38
46
|
/**
|
|
39
47
|
* Override the default functions used for creating procedures
|
|
40
48
|
*/
|
|
41
|
-
rpcGenerators?: Record<RpcDefinition["transport"],
|
|
49
|
+
rpcGenerators?: Record<RpcDefinition["transport"], RpcGenerator>;
|
|
42
50
|
}
|
|
43
51
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
44
52
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
45
53
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
46
54
|
|
|
47
|
-
export { type TypescriptGeneratorOptions, createTypescriptClient, tsTypeFromSchema, typescriptClientGenerator };
|
|
55
|
+
export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
|
|
2
|
-
import { RpcDefinition,
|
|
2
|
+
import { RpcDefinition, HttpRpcDefinition, WsRpcDefinition, Schema, AppDefinition } from '@arrirpc/codegen-utils';
|
|
3
3
|
import prettier from 'prettier';
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type RpcGenerator = (def: RpcDefinition, context: CodegenContext) => string;
|
|
6
|
+
declare function defineRpcGenerator(fn: RpcGenerator): RpcGenerator;
|
|
7
|
+
declare function tsRpcFromDefinition(def: RpcDefinition, context: CodegenContext): string;
|
|
8
|
+
declare function httpRpcFromDefinition(def: HttpRpcDefinition, context: CodegenContext): string;
|
|
9
|
+
declare function wsRpcFromDefinition(def: WsRpcDefinition, context: CodegenContext): string;
|
|
10
|
+
declare function getRpcKey(context: CodegenContext): string;
|
|
6
11
|
|
|
7
12
|
interface TsProperty {
|
|
8
13
|
typeName: string;
|
|
@@ -27,8 +32,11 @@ interface CodegenContext {
|
|
|
27
32
|
sse: boolean;
|
|
28
33
|
ws: boolean;
|
|
29
34
|
};
|
|
30
|
-
rpcGenerators: Record<string,
|
|
35
|
+
rpcGenerators: Record<string, RpcGenerator>;
|
|
31
36
|
}
|
|
37
|
+
declare function getJsDocComment(metadata: Schema["metadata"]): string;
|
|
38
|
+
declare function validVarName(name: string): string;
|
|
39
|
+
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
32
40
|
|
|
33
41
|
interface TypescriptGeneratorOptions {
|
|
34
42
|
clientName: string;
|
|
@@ -38,10 +46,10 @@ interface TypescriptGeneratorOptions {
|
|
|
38
46
|
/**
|
|
39
47
|
* Override the default functions used for creating procedures
|
|
40
48
|
*/
|
|
41
|
-
rpcGenerators?: Record<RpcDefinition["transport"],
|
|
49
|
+
rpcGenerators?: Record<RpcDefinition["transport"], RpcGenerator>;
|
|
42
50
|
}
|
|
43
51
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
44
52
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
45
53
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
46
54
|
|
|
47
|
-
export { type TypescriptGeneratorOptions, createTypescriptClient, tsTypeFromSchema, typescriptClientGenerator };
|
|
55
|
+
export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import * as _arrirpc_codegen_utils from '@arrirpc/codegen-utils';
|
|
2
|
-
import { RpcDefinition,
|
|
2
|
+
import { RpcDefinition, HttpRpcDefinition, WsRpcDefinition, Schema, AppDefinition } from '@arrirpc/codegen-utils';
|
|
3
3
|
import prettier from 'prettier';
|
|
4
4
|
|
|
5
|
-
type
|
|
5
|
+
type RpcGenerator = (def: RpcDefinition, context: CodegenContext) => string;
|
|
6
|
+
declare function defineRpcGenerator(fn: RpcGenerator): RpcGenerator;
|
|
7
|
+
declare function tsRpcFromDefinition(def: RpcDefinition, context: CodegenContext): string;
|
|
8
|
+
declare function httpRpcFromDefinition(def: HttpRpcDefinition, context: CodegenContext): string;
|
|
9
|
+
declare function wsRpcFromDefinition(def: WsRpcDefinition, context: CodegenContext): string;
|
|
10
|
+
declare function getRpcKey(context: CodegenContext): string;
|
|
6
11
|
|
|
7
12
|
interface TsProperty {
|
|
8
13
|
typeName: string;
|
|
@@ -27,8 +32,11 @@ interface CodegenContext {
|
|
|
27
32
|
sse: boolean;
|
|
28
33
|
ws: boolean;
|
|
29
34
|
};
|
|
30
|
-
rpcGenerators: Record<string,
|
|
35
|
+
rpcGenerators: Record<string, RpcGenerator>;
|
|
31
36
|
}
|
|
37
|
+
declare function getJsDocComment(metadata: Schema["metadata"]): string;
|
|
38
|
+
declare function validVarName(name: string): string;
|
|
39
|
+
declare function getTsTypeName(schema: Schema, context: CodegenContext): string;
|
|
32
40
|
|
|
33
41
|
interface TypescriptGeneratorOptions {
|
|
34
42
|
clientName: string;
|
|
@@ -38,10 +46,10 @@ interface TypescriptGeneratorOptions {
|
|
|
38
46
|
/**
|
|
39
47
|
* Override the default functions used for creating procedures
|
|
40
48
|
*/
|
|
41
|
-
rpcGenerators?: Record<RpcDefinition["transport"],
|
|
49
|
+
rpcGenerators?: Record<RpcDefinition["transport"], RpcGenerator>;
|
|
42
50
|
}
|
|
43
51
|
declare const typescriptClientGenerator: _arrirpc_codegen_utils.GeneratorPlugin<TypescriptGeneratorOptions>;
|
|
44
52
|
declare function createTypescriptClient(def: AppDefinition, options: TypescriptGeneratorOptions): Promise<string>;
|
|
45
53
|
declare function tsTypeFromSchema(schema: Schema, context: CodegenContext): TsProperty;
|
|
46
54
|
|
|
47
|
-
export { type TypescriptGeneratorOptions, createTypescriptClient, tsTypeFromSchema, typescriptClientGenerator };
|
|
55
|
+
export { type CodegenContext, type RpcGenerator, type TsProperty, type TypescriptGeneratorOptions, createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
package/dist/index.mjs
CHANGED
|
@@ -225,7 +225,7 @@ function tsObjectFromSchema(schema, context) {
|
|
|
225
225
|
});
|
|
226
226
|
if (prop.content)
|
|
227
227
|
subContentParts.push(prop.content);
|
|
228
|
-
const fieldName = validVarName(camelCase(key));
|
|
228
|
+
const fieldName = validVarName(camelCase(key, { normalize: true }));
|
|
229
229
|
fieldParts.push(
|
|
230
230
|
`${getJsDocComment(subSchema.metadata)}${fieldName}: ${prop.typeName},`
|
|
231
231
|
);
|
|
@@ -269,7 +269,7 @@ function tsObjectFromSchema(schema, context) {
|
|
|
269
269
|
});
|
|
270
270
|
if (prop.content)
|
|
271
271
|
subContentParts.push(prop.content);
|
|
272
|
-
const fieldName = validVarName(camelCase(key));
|
|
272
|
+
const fieldName = validVarName(camelCase(key, { normalize: true }));
|
|
273
273
|
fieldParts.push(
|
|
274
274
|
`${getJsDocComment(subSchema.metadata)}${fieldName}?: ${prop.typeName},`
|
|
275
275
|
);
|
|
@@ -279,15 +279,15 @@ function tsObjectFromSchema(schema, context) {
|
|
|
279
279
|
${prop.fromJsonTemplate(`input.${key}`, tempKey)}
|
|
280
280
|
}`);
|
|
281
281
|
if (hasKey) {
|
|
282
|
-
toJsonParts.push(`if (typeof input.${
|
|
282
|
+
toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
|
|
283
283
|
json += \`,"${key}":\`;
|
|
284
|
-
${prop.toJsonTemplate(`input.${
|
|
284
|
+
${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
|
|
285
285
|
}`);
|
|
286
286
|
} else {
|
|
287
|
-
toJsonParts.push(`if (typeof input.${
|
|
287
|
+
toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
|
|
288
288
|
if (_hasKey) json += ',';
|
|
289
289
|
json += '"${key}":';
|
|
290
|
-
${prop.toJsonTemplate(`input.${
|
|
290
|
+
${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
|
|
291
291
|
_hasKey = true;
|
|
292
292
|
}`);
|
|
293
293
|
}
|
|
@@ -892,6 +892,9 @@ function tsRefFromSchema(schema, context) {
|
|
|
892
892
|
};
|
|
893
893
|
}
|
|
894
894
|
|
|
895
|
+
function defineRpcGenerator(fn) {
|
|
896
|
+
return fn;
|
|
897
|
+
}
|
|
895
898
|
function tsRpcFromDefinition(def, context) {
|
|
896
899
|
const customFn = context.rpcGenerators[def.transport];
|
|
897
900
|
if (customFn)
|
|
@@ -1074,7 +1077,7 @@ function getServiceName(context) {
|
|
|
1074
1077
|
|
|
1075
1078
|
const typescriptClientGenerator = defineGeneratorPlugin(
|
|
1076
1079
|
(options) => ({
|
|
1077
|
-
|
|
1080
|
+
run: async (def) => {
|
|
1078
1081
|
if (!options.clientName) {
|
|
1079
1082
|
throw new Error("Name is requires");
|
|
1080
1083
|
}
|
|
@@ -1232,4 +1235,4 @@ function tsTypeFromSchema(schema, context) {
|
|
|
1232
1235
|
return tsAnyFromSchema(schema, context);
|
|
1233
1236
|
}
|
|
1234
1237
|
|
|
1235
|
-
export { createTypescriptClient, tsTypeFromSchema, typescriptClientGenerator };
|
|
1238
|
+
export { createTypescriptClient, defineRpcGenerator, getJsDocComment, getRpcKey, getTsTypeName, httpRpcFromDefinition, tsRpcFromDefinition, tsTypeFromSchema, typescriptClientGenerator, validVarName, wsRpcFromDefinition };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arrirpc/codegen-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.67.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.67.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {}
|
|
29
29
|
}
|