@rexeus/typeweaver-types 0.10.2 → 0.10.4

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
@@ -35,6 +35,7 @@ node_path = __toESM(node_path);
35
35
  let node_url = require("node:url");
36
36
  let _rexeus_typeweaver_gen = require("@rexeus/typeweaver-gen");
37
37
  let _rexeus_typeweaver_zod_to_ts = require("@rexeus/typeweaver-zod-to-ts");
38
+ let polycase = require("polycase");
38
39
  let _rexeus_typeweaver_core = require("@rexeus/typeweaver-core");
39
40
  //#region src/requestGenerator.ts
40
41
  const moduleDir$4 = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
@@ -50,7 +51,7 @@ function writeRequestType(templateFilePath, resourceName, operation, context) {
50
51
  operationId
51
52
  });
52
53
  const content = context.renderTemplate(templateFilePath, {
53
- pascalCaseOperationId: (0, _rexeus_typeweaver_gen.toPascalCase)(operationId),
54
+ pascalCaseOperationId: (0, polycase.pascalCase)(operationId),
54
55
  method,
55
56
  headerTsType: header ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(header)) : void 0,
56
57
  queryTsType: query ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(query)) : void 0,
@@ -12845,7 +12846,7 @@ function writeRequestValidator(templateFilePath, resourceName, operation, contex
12845
12846
  resourceName,
12846
12847
  operationId
12847
12848
  });
12848
- const pascalCaseOperationId = (0, _rexeus_typeweaver_gen.toPascalCase)(operationId);
12849
+ const pascalCaseOperationId = (0, polycase.pascalCase)(operationId);
12849
12850
  const content = context.renderTemplate(templateFilePath, {
12850
12851
  pascalCaseOperationId,
12851
12852
  operationId,
@@ -12868,21 +12869,22 @@ const moduleDir$2 = node_path.default.dirname((0, node_url.fileURLToPath)(requir
12868
12869
  function generate$1(context) {
12869
12870
  const templateFile = node_path.default.join(moduleDir$2, "templates", "Response.ejs");
12870
12871
  const canonicalResponseTemplateFile = node_path.default.join(moduleDir$2, "templates", "SharedResponse.ejs");
12871
- for (const response of context.normalizedSpec.responses) writeCanonicalResponseType(canonicalResponseTemplateFile, response, context);
12872
- for (const resource of context.normalizedSpec.resources) for (const operation of resource.operations) writeResponseType(templateFile, resource, operation, context);
12872
+ const responseFactoryTemplateFile = node_path.default.join(moduleDir$2, "templates", "ResponseFactory.ejs");
12873
+ for (const response of context.normalizedSpec.responses) writeCanonicalResponseType(canonicalResponseTemplateFile, responseFactoryTemplateFile, response, context);
12874
+ for (const resource of context.normalizedSpec.resources) for (const operation of resource.operations) writeResponseType(templateFile, responseFactoryTemplateFile, resource, operation, context);
12873
12875
  }
12874
- function writeResponseType(templateFile, resource, operation, context) {
12876
+ function writeResponseType(templateFile, responseFactoryTemplateFile, resource, operation, context) {
12875
12877
  const outputPaths = context.getOperationOutputPaths({
12876
12878
  resourceName: resource.name,
12877
12879
  operationId: operation.operationId
12878
12880
  });
12879
- const pascalCaseOperationId = (0, _rexeus_typeweaver_gen.toPascalCase)(operation.operationId);
12881
+ const pascalCaseOperationId = (0, polycase.pascalCase)(operation.operationId);
12880
12882
  const ownResponses = [];
12881
12883
  const canonicalResponses = [];
12882
12884
  for (const responseUsage of operation.responses) {
12883
12885
  if (responseUsage.source === "canonical") {
12884
12886
  canonicalResponses.push({
12885
- name: responseUsage.responseName,
12887
+ identifierName: (0, polycase.pascalCase)(responseUsage.responseName),
12886
12888
  path: context.getCanonicalResponseImportPath({
12887
12889
  importerDir: outputPaths.outputDir,
12888
12890
  responseName: responseUsage.responseName
@@ -12890,7 +12892,7 @@ function writeResponseType(templateFile, resource, operation, context) {
12890
12892
  });
12891
12893
  continue;
12892
12894
  }
12893
- ownResponses.push(createOwnResponseTemplateData(responseUsage.response));
12895
+ ownResponses.push(createOwnResponseTemplateData(responseUsage.response, responseFactoryTemplateFile, context));
12894
12896
  }
12895
12897
  const content = context.renderTemplate(templateFile, {
12896
12898
  operationId: operation.operationId,
@@ -12904,30 +12906,51 @@ function writeResponseType(templateFile, resource, operation, context) {
12904
12906
  const relativePath = node_path.default.relative(context.outputDir, outputPaths.responseFile);
12905
12907
  context.writeFile(relativePath, content);
12906
12908
  }
12907
- function createOwnResponseTemplateData(response) {
12909
+ function createOwnResponseTemplateData(response, responseFactoryTemplateFile, context) {
12910
+ const hasHeader = response.header !== void 0;
12911
+ const hasBody = response.body !== void 0;
12912
+ const factoryData = {
12913
+ identifierName: (0, polycase.pascalCase)(response.name),
12914
+ typeValue: response.name,
12915
+ statusCodeKey: _rexeus_typeweaver_core.HttpStatusCode[response.statusCode],
12916
+ hasHeader,
12917
+ hasBody
12918
+ };
12908
12919
  return {
12909
- name: response.name,
12920
+ ...factoryData,
12910
12921
  body: response.body ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(response.body)) : void 0,
12911
12922
  header: response.header ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(response.header)) : void 0,
12912
12923
  statusCode: response.statusCode,
12913
- statusCodeKey: _rexeus_typeweaver_core.HttpStatusCode[response.statusCode]
12924
+ factory: renderResponseFactory(responseFactoryTemplateFile, factoryData, context, " ")
12914
12925
  };
12915
12926
  }
12916
- function writeCanonicalResponseType(templateFile, response, context) {
12917
- const pascalCaseName = (0, _rexeus_typeweaver_gen.toPascalCase)(response.name);
12927
+ function writeCanonicalResponseType(templateFile, responseFactoryTemplateFile, response, context) {
12928
+ const pascalCaseName = (0, polycase.pascalCase)(response.name);
12918
12929
  const headerTsType = response.header ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(response.header)) : void 0;
12919
12930
  const bodyTsType = response.body ? (0, _rexeus_typeweaver_zod_to_ts.print)((0, _rexeus_typeweaver_zod_to_ts.fromZod)(response.body)) : void 0;
12931
+ const factoryData = {
12932
+ identifierName: pascalCaseName,
12933
+ typeValue: response.name,
12934
+ statusCodeKey: _rexeus_typeweaver_core.HttpStatusCode[response.statusCode],
12935
+ hasHeader: response.header !== void 0,
12936
+ hasBody: response.body !== void 0
12937
+ };
12920
12938
  const content = context.renderTemplate(templateFile, {
12921
12939
  coreDir: context.coreDir,
12922
- httpStatusCode: _rexeus_typeweaver_core.HttpStatusCode,
12923
12940
  headerTsType,
12924
12941
  bodyTsType,
12925
- pascalCaseName,
12926
- sharedResponse: response
12942
+ ...factoryData,
12943
+ factory: renderResponseFactory(responseFactoryTemplateFile, factoryData, context, "")
12927
12944
  });
12928
12945
  const relativePath = node_path.default.relative(context.outputDir, context.getCanonicalResponseOutputFile(response.name));
12929
12946
  context.writeFile(relativePath, content);
12930
12947
  }
12948
+ function renderResponseFactory(templateFile, data, context, indentation) {
12949
+ return context.renderTemplate(templateFile, {
12950
+ ...data,
12951
+ indentation
12952
+ });
12953
+ }
12931
12954
  //#endregion
12932
12955
  //#region src/responseValidationGenerator.ts
12933
12956
  const moduleDir$1 = node_path.default.dirname((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
@@ -12942,7 +12965,7 @@ function writeResponseValidator(templateFilePath, resource, operation, context)
12942
12965
  resourceName: resource.name,
12943
12966
  operationId: operation.operationId
12944
12967
  });
12945
- const pascalCaseOperationId = (0, _rexeus_typeweaver_gen.toPascalCase)(operation.operationId);
12968
+ const pascalCaseOperationId = (0, polycase.pascalCase)(operation.operationId);
12946
12969
  const ownResponses = [];
12947
12970
  const sharedResponses = [];
12948
12971
  const allStatusCodes = /* @__PURE__ */ new Map();
@@ -12950,7 +12973,7 @@ function writeResponseValidator(templateFilePath, resource, operation, context)
12950
12973
  const response = responseUsage.source === "canonical" ? context.getCanonicalResponse(responseUsage.responseName) : responseUsage.response;
12951
12974
  allStatusCodes.set(response.statusCode, response.statusCodeName);
12952
12975
  const templateData = {
12953
- definitionVariableName: `${(0, _rexeus_typeweaver_gen.toCamelCase)(response.name)}Definition`,
12976
+ definitionVariableName: `${(0, polycase.camelCase)(response.name)}Definition`,
12954
12977
  name: response.name,
12955
12978
  hasBody: response.body !== void 0,
12956
12979
  hasHeader: response.header !== void 0,
package/dist/index.mjs CHANGED
@@ -1,7 +1,8 @@
1
1
  import path from "node:path";
2
2
  import { fileURLToPath } from "node:url";
3
- import { BasePlugin, toCamelCase, toPascalCase } from "@rexeus/typeweaver-gen";
3
+ import { BasePlugin } from "@rexeus/typeweaver-gen";
4
4
  import { fromZod, print } from "@rexeus/typeweaver-zod-to-ts";
5
+ import { camelCase, pascalCase } from "polycase";
5
6
  import { HttpStatusCode } from "@rexeus/typeweaver-core";
6
7
  //#region \0rolldown/runtime.js
7
8
  var __defProp = Object.defineProperty;
@@ -29,7 +30,7 @@ function writeRequestType(templateFilePath, resourceName, operation, context) {
29
30
  operationId
30
31
  });
31
32
  const content = context.renderTemplate(templateFilePath, {
32
- pascalCaseOperationId: toPascalCase(operationId),
33
+ pascalCaseOperationId: pascalCase(operationId),
33
34
  method,
34
35
  headerTsType: header ? print(fromZod(header)) : void 0,
35
36
  queryTsType: query ? print(fromZod(query)) : void 0,
@@ -12824,7 +12825,7 @@ function writeRequestValidator(templateFilePath, resourceName, operation, contex
12824
12825
  resourceName,
12825
12826
  operationId
12826
12827
  });
12827
- const pascalCaseOperationId = toPascalCase(operationId);
12828
+ const pascalCaseOperationId = pascalCase(operationId);
12828
12829
  const content = context.renderTemplate(templateFilePath, {
12829
12830
  pascalCaseOperationId,
12830
12831
  operationId,
@@ -12847,21 +12848,22 @@ const moduleDir$2 = path.dirname(fileURLToPath(import.meta.url));
12847
12848
  function generate$1(context) {
12848
12849
  const templateFile = path.join(moduleDir$2, "templates", "Response.ejs");
12849
12850
  const canonicalResponseTemplateFile = path.join(moduleDir$2, "templates", "SharedResponse.ejs");
12850
- for (const response of context.normalizedSpec.responses) writeCanonicalResponseType(canonicalResponseTemplateFile, response, context);
12851
- for (const resource of context.normalizedSpec.resources) for (const operation of resource.operations) writeResponseType(templateFile, resource, operation, context);
12851
+ const responseFactoryTemplateFile = path.join(moduleDir$2, "templates", "ResponseFactory.ejs");
12852
+ for (const response of context.normalizedSpec.responses) writeCanonicalResponseType(canonicalResponseTemplateFile, responseFactoryTemplateFile, response, context);
12853
+ for (const resource of context.normalizedSpec.resources) for (const operation of resource.operations) writeResponseType(templateFile, responseFactoryTemplateFile, resource, operation, context);
12852
12854
  }
12853
- function writeResponseType(templateFile, resource, operation, context) {
12855
+ function writeResponseType(templateFile, responseFactoryTemplateFile, resource, operation, context) {
12854
12856
  const outputPaths = context.getOperationOutputPaths({
12855
12857
  resourceName: resource.name,
12856
12858
  operationId: operation.operationId
12857
12859
  });
12858
- const pascalCaseOperationId = toPascalCase(operation.operationId);
12860
+ const pascalCaseOperationId = pascalCase(operation.operationId);
12859
12861
  const ownResponses = [];
12860
12862
  const canonicalResponses = [];
12861
12863
  for (const responseUsage of operation.responses) {
12862
12864
  if (responseUsage.source === "canonical") {
12863
12865
  canonicalResponses.push({
12864
- name: responseUsage.responseName,
12866
+ identifierName: pascalCase(responseUsage.responseName),
12865
12867
  path: context.getCanonicalResponseImportPath({
12866
12868
  importerDir: outputPaths.outputDir,
12867
12869
  responseName: responseUsage.responseName
@@ -12869,7 +12871,7 @@ function writeResponseType(templateFile, resource, operation, context) {
12869
12871
  });
12870
12872
  continue;
12871
12873
  }
12872
- ownResponses.push(createOwnResponseTemplateData(responseUsage.response));
12874
+ ownResponses.push(createOwnResponseTemplateData(responseUsage.response, responseFactoryTemplateFile, context));
12873
12875
  }
12874
12876
  const content = context.renderTemplate(templateFile, {
12875
12877
  operationId: operation.operationId,
@@ -12883,30 +12885,51 @@ function writeResponseType(templateFile, resource, operation, context) {
12883
12885
  const relativePath = path.relative(context.outputDir, outputPaths.responseFile);
12884
12886
  context.writeFile(relativePath, content);
12885
12887
  }
12886
- function createOwnResponseTemplateData(response) {
12888
+ function createOwnResponseTemplateData(response, responseFactoryTemplateFile, context) {
12889
+ const hasHeader = response.header !== void 0;
12890
+ const hasBody = response.body !== void 0;
12891
+ const factoryData = {
12892
+ identifierName: pascalCase(response.name),
12893
+ typeValue: response.name,
12894
+ statusCodeKey: HttpStatusCode[response.statusCode],
12895
+ hasHeader,
12896
+ hasBody
12897
+ };
12887
12898
  return {
12888
- name: response.name,
12899
+ ...factoryData,
12889
12900
  body: response.body ? print(fromZod(response.body)) : void 0,
12890
12901
  header: response.header ? print(fromZod(response.header)) : void 0,
12891
12902
  statusCode: response.statusCode,
12892
- statusCodeKey: HttpStatusCode[response.statusCode]
12903
+ factory: renderResponseFactory(responseFactoryTemplateFile, factoryData, context, " ")
12893
12904
  };
12894
12905
  }
12895
- function writeCanonicalResponseType(templateFile, response, context) {
12896
- const pascalCaseName = toPascalCase(response.name);
12906
+ function writeCanonicalResponseType(templateFile, responseFactoryTemplateFile, response, context) {
12907
+ const pascalCaseName = pascalCase(response.name);
12897
12908
  const headerTsType = response.header ? print(fromZod(response.header)) : void 0;
12898
12909
  const bodyTsType = response.body ? print(fromZod(response.body)) : void 0;
12910
+ const factoryData = {
12911
+ identifierName: pascalCaseName,
12912
+ typeValue: response.name,
12913
+ statusCodeKey: HttpStatusCode[response.statusCode],
12914
+ hasHeader: response.header !== void 0,
12915
+ hasBody: response.body !== void 0
12916
+ };
12899
12917
  const content = context.renderTemplate(templateFile, {
12900
12918
  coreDir: context.coreDir,
12901
- httpStatusCode: HttpStatusCode,
12902
12919
  headerTsType,
12903
12920
  bodyTsType,
12904
- pascalCaseName,
12905
- sharedResponse: response
12921
+ ...factoryData,
12922
+ factory: renderResponseFactory(responseFactoryTemplateFile, factoryData, context, "")
12906
12923
  });
12907
12924
  const relativePath = path.relative(context.outputDir, context.getCanonicalResponseOutputFile(response.name));
12908
12925
  context.writeFile(relativePath, content);
12909
12926
  }
12927
+ function renderResponseFactory(templateFile, data, context, indentation) {
12928
+ return context.renderTemplate(templateFile, {
12929
+ ...data,
12930
+ indentation
12931
+ });
12932
+ }
12910
12933
  //#endregion
12911
12934
  //#region src/responseValidationGenerator.ts
12912
12935
  const moduleDir$1 = path.dirname(fileURLToPath(import.meta.url));
@@ -12921,7 +12944,7 @@ function writeResponseValidator(templateFilePath, resource, operation, context)
12921
12944
  resourceName: resource.name,
12922
12945
  operationId: operation.operationId
12923
12946
  });
12924
- const pascalCaseOperationId = toPascalCase(operation.operationId);
12947
+ const pascalCaseOperationId = pascalCase(operation.operationId);
12925
12948
  const ownResponses = [];
12926
12949
  const sharedResponses = [];
12927
12950
  const allStatusCodes = /* @__PURE__ */ new Map();
@@ -12929,7 +12952,7 @@ function writeResponseValidator(templateFilePath, resource, operation, context)
12929
12952
  const response = responseUsage.source === "canonical" ? context.getCanonicalResponse(responseUsage.responseName) : responseUsage.response;
12930
12953
  allStatusCodes.set(response.statusCode, response.statusCodeName);
12931
12954
  const templateData = {
12932
- definitionVariableName: `${toCamelCase(response.name)}Definition`,
12955
+ definitionVariableName: `${camelCase(response.name)}Definition`,
12933
12956
  name: response.name,
12934
12957
  hasBody: response.body !== void 0,
12935
12958
  hasHeader: response.header !== void 0,