@arrirpc/codegen-ts 0.66.0 → 0.68.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/README.md CHANGED
@@ -53,6 +53,10 @@ const client = new MyClient({
53
53
  Authorization: "<some-token>",
54
54
  };
55
55
  },
56
+ // optional
57
+ onError: (err) => {
58
+ // do something
59
+ },
56
60
  });
57
61
 
58
62
  await client.myProcedure();
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.${key} !== 'undefined') {
288
+ toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
289
289
  json += \`,"${key}":\`;
290
- ${prop.toJsonTemplate(`input.${key}`, "json", key)}
290
+ ${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
291
291
  }`);
292
292
  } else {
293
- toJsonParts.push(`if (typeof input.${key} !== 'undefined') {
293
+ toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
294
294
  if (_hasKey) json += ',';
295
295
  json += '"${key}":';
296
- ${prop.toJsonTemplate(`input.${key}`, "json", key)}
296
+ ${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
297
297
  _hasKey = true;
298
298
  }`);
299
299
  }
@@ -933,6 +933,7 @@ function httpRpcFromDefinition(def, context) {
933
933
  url: \`\${this._baseUrl}${def.path}\`,
934
934
  method: "${def.method.toLowerCase()}",
935
935
  headers: this._headers,
936
+ onError: this._onError,
936
937
  ${params ? "params: params," : ""}
937
938
  responseFromJson: ${response ? `$$${response}.fromJson` : "() => {}"},
938
939
  responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
@@ -940,7 +941,7 @@ function httpRpcFromDefinition(def, context) {
940
941
  clientVersion: "${context.versionNumber}",
941
942
  },
942
943
  options,
943
- )
944
+ );
944
945
  }`;
945
946
  }
946
947
  return `${getJsDocComment({
@@ -951,6 +952,7 @@ function httpRpcFromDefinition(def, context) {
951
952
  url: \`\${this._baseUrl}${def.path}\`,
952
953
  method: "${def.method.toLowerCase()}",
953
954
  headers: this._headers,
955
+ onError: this._onError,
954
956
  ${params ? "params: params," : ""}
955
957
  responseFromJson: ${response ? `$$${response}.fromJson` : "() => {}"},
956
958
  responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
@@ -1050,15 +1052,18 @@ function tsServiceFromDefinition(def, context) {
1050
1052
  content: `export class ${serviceName} {
1051
1053
  private readonly _baseUrl: string;
1052
1054
  private readonly _headers: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
1055
+ private readonly _onError?: (err: unknown) => void;
1053
1056
  ${subServices.map((service) => ` ${service.key}: ${service.name};`).join("\n")}
1054
1057
  constructor(
1055
1058
  options: {
1056
1059
  baseUrl?: string;
1057
1060
  headers?: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
1061
+ onError?: (err: unknown) => void;
1058
1062
  } = {},
1059
1063
  ) {
1060
1064
  this._baseUrl = options.baseUrl ?? "";
1061
1065
  this._headers = options.headers ?? {};
1066
+ this._onError = options.onError;
1062
1067
  ${subServices.map((service) => ` this.${service.key} = new ${service.name}(options);`).join("\n")}
1063
1068
  }
1064
1069
  ${rpcParts.map((rpc) => ` ${rpc}`).join("\n")}
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.${key} !== 'undefined') {
282
+ toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
283
283
  json += \`,"${key}":\`;
284
- ${prop.toJsonTemplate(`input.${key}`, "json", key)}
284
+ ${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
285
285
  }`);
286
286
  } else {
287
- toJsonParts.push(`if (typeof input.${key} !== 'undefined') {
287
+ toJsonParts.push(`if (typeof input.${fieldName} !== 'undefined') {
288
288
  if (_hasKey) json += ',';
289
289
  json += '"${key}":';
290
- ${prop.toJsonTemplate(`input.${key}`, "json", key)}
290
+ ${prop.toJsonTemplate(`input.${fieldName}`, "json", key)}
291
291
  _hasKey = true;
292
292
  }`);
293
293
  }
@@ -927,6 +927,7 @@ function httpRpcFromDefinition(def, context) {
927
927
  url: \`\${this._baseUrl}${def.path}\`,
928
928
  method: "${def.method.toLowerCase()}",
929
929
  headers: this._headers,
930
+ onError: this._onError,
930
931
  ${params ? "params: params," : ""}
931
932
  responseFromJson: ${response ? `$$${response}.fromJson` : "() => {}"},
932
933
  responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
@@ -934,7 +935,7 @@ function httpRpcFromDefinition(def, context) {
934
935
  clientVersion: "${context.versionNumber}",
935
936
  },
936
937
  options,
937
- )
938
+ );
938
939
  }`;
939
940
  }
940
941
  return `${getJsDocComment({
@@ -945,6 +946,7 @@ function httpRpcFromDefinition(def, context) {
945
946
  url: \`\${this._baseUrl}${def.path}\`,
946
947
  method: "${def.method.toLowerCase()}",
947
948
  headers: this._headers,
949
+ onError: this._onError,
948
950
  ${params ? "params: params," : ""}
949
951
  responseFromJson: ${response ? `$$${response}.fromJson` : "() => {}"},
950
952
  responseFromString: ${response ? `$$${response}.fromJsonString` : "() => {}"},
@@ -1044,15 +1046,18 @@ function tsServiceFromDefinition(def, context) {
1044
1046
  content: `export class ${serviceName} {
1045
1047
  private readonly _baseUrl: string;
1046
1048
  private readonly _headers: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
1049
+ private readonly _onError?: (err: unknown) => void;
1047
1050
  ${subServices.map((service) => ` ${service.key}: ${service.name};`).join("\n")}
1048
1051
  constructor(
1049
1052
  options: {
1050
1053
  baseUrl?: string;
1051
1054
  headers?: HeaderMap | (() => HeaderMap | Promise<HeaderMap>);
1055
+ onError?: (err: unknown) => void;
1052
1056
  } = {},
1053
1057
  ) {
1054
1058
  this._baseUrl = options.baseUrl ?? "";
1055
1059
  this._headers = options.headers ?? {};
1060
+ this._onError = options.onError;
1056
1061
  ${subServices.map((service) => ` this.${service.key} = new ${service.name}(options);`).join("\n")}
1057
1062
  }
1058
1063
  ${rpcParts.map((rpc) => ` ${rpc}`).join("\n")}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arrirpc/codegen-ts",
3
- "version": "0.66.0",
3
+ "version": "0.68.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -22,8 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "dependencies": {
25
- "prettier": "^3.3.3",
26
- "@arrirpc/codegen-utils": "0.66.0"
27
- },
28
- "devDependencies": {}
25
+ "prettier": "^3.4.1",
26
+ "@arrirpc/codegen-utils": "0.68.0"
27
+ }
29
28
  }