@techspokes/typescript-wsdl-client 0.7.14 → 0.8.14

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.
Files changed (60) hide show
  1. package/README.md +1504 -263
  2. package/dist/cli.js +423 -270
  3. package/dist/{emit/clientEmitter.d.ts → client/generateClient.d.ts} +2 -2
  4. package/dist/client/generateClient.d.ts.map +1 -0
  5. package/dist/{emit/clientEmitter.js → client/generateClient.js} +5 -5
  6. package/dist/{emit/typesEmitter.d.ts → client/generateTypes.d.ts} +4 -4
  7. package/dist/client/generateTypes.d.ts.map +1 -0
  8. package/dist/{emit/typesEmitter.js → client/generateTypes.js} +6 -6
  9. package/dist/{emit/utilsEmitter.d.ts → client/generateUtils.d.ts} +4 -4
  10. package/dist/client/generateUtils.d.ts.map +1 -0
  11. package/dist/{emit/utilsEmitter.js → client/generateUtils.js} +7 -7
  12. package/dist/{emit/catalogEmitter.d.ts → compiler/generateCatalog.d.ts} +4 -4
  13. package/dist/compiler/generateCatalog.d.ts.map +1 -0
  14. package/dist/{emit/catalogEmitter.js → compiler/generateCatalog.js} +5 -5
  15. package/dist/compiler/schemaCompiler.d.ts +1 -1
  16. package/dist/compiler/schemaCompiler.js +1 -1
  17. package/dist/config.d.ts +13 -0
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/config.js +17 -0
  20. package/dist/gateway/generateGateway.d.ts +73 -0
  21. package/dist/gateway/generateGateway.d.ts.map +1 -0
  22. package/dist/gateway/generateGateway.js +135 -0
  23. package/dist/gateway/generators.d.ts +90 -0
  24. package/dist/gateway/generators.d.ts.map +1 -0
  25. package/dist/gateway/generators.js +270 -0
  26. package/dist/gateway/helpers.d.ts +115 -0
  27. package/dist/gateway/helpers.d.ts.map +1 -0
  28. package/dist/gateway/helpers.js +224 -0
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +18 -18
  32. package/dist/loader/wsdlLoader.d.ts.map +1 -1
  33. package/dist/loader/wsdlLoader.js +1 -3
  34. package/dist/openapi/generateOpenAPI.d.ts +25 -1
  35. package/dist/openapi/generateOpenAPI.d.ts.map +1 -1
  36. package/dist/openapi/generateOpenAPI.js +28 -27
  37. package/dist/openapi/{buildPaths.d.ts → generatePaths.d.ts} +6 -6
  38. package/dist/openapi/generatePaths.d.ts.map +1 -0
  39. package/dist/openapi/{buildPaths.js → generatePaths.js} +1 -1
  40. package/dist/openapi/{buildSchemas.d.ts → generateSchemas.d.ts} +10 -10
  41. package/dist/openapi/generateSchemas.d.ts.map +1 -0
  42. package/dist/openapi/{buildSchemas.js → generateSchemas.js} +5 -5
  43. package/dist/openapi/security.d.ts.map +1 -1
  44. package/dist/openapi/security.js +2 -1
  45. package/dist/pipeline.d.ts +21 -7
  46. package/dist/pipeline.d.ts.map +1 -1
  47. package/dist/pipeline.js +66 -32
  48. package/dist/util/builder.d.ts +25 -0
  49. package/dist/util/builder.d.ts.map +1 -0
  50. package/dist/util/builder.js +52 -0
  51. package/dist/util/cli.d.ts +106 -0
  52. package/dist/util/cli.d.ts.map +1 -0
  53. package/dist/util/cli.js +164 -0
  54. package/package.json +11 -8
  55. package/dist/emit/catalogEmitter.d.ts.map +0 -1
  56. package/dist/emit/clientEmitter.d.ts.map +0 -1
  57. package/dist/emit/typesEmitter.d.ts.map +0 -1
  58. package/dist/emit/utilsEmitter.d.ts.map +0 -1
  59. package/dist/openapi/buildPaths.d.ts.map +0 -1
  60. package/dist/openapi/buildSchemas.d.ts.map +0 -1
@@ -16,5 +16,5 @@ import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
16
16
  * @param {string} outFile - Path to the output TypeScript file
17
17
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog
18
18
  */
19
- export declare function emitClient(outFile: string, compiled: CompiledCatalog): void;
20
- //# sourceMappingURL=clientEmitter.d.ts.map
19
+ export declare function generateClient(outFile: string, compiled: CompiledCatalog): void;
20
+ //# sourceMappingURL=generateClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateClient.d.ts","sourceRoot":"","sources":["../../src/client/generateClient.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAInE;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QAsWxE"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript SOAP Client Emitter
2
+ * TypeScript SOAP Client Generator
3
3
  *
4
4
  * This module generates a strongly-typed TypeScript SOAP client class from the compiled WSDL catalog.
5
5
  * The generated client wraps the node-soap library with type-safe operation methods and proper
@@ -14,6 +14,7 @@
14
14
  */
15
15
  import fs from "node:fs";
16
16
  import { deriveClientName, pascal, pascalToSnakeCase } from "../util/tools.js";
17
+ import { error, warn } from "../util/cli.js";
17
18
  /**
18
19
  * Generates a TypeScript SOAP client class from a compiled WSDL catalog
19
20
  *
@@ -31,7 +32,7 @@ import { deriveClientName, pascal, pascalToSnakeCase } from "../util/tools.js";
31
32
  * @param {string} outFile - Path to the output TypeScript file
32
33
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog
33
34
  */
34
- export function emitClient(outFile, compiled) {
35
+ export function generateClient(outFile, compiled) {
35
36
  const isValidIdent = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name);
36
37
  const reserved = new Set([
37
38
  "break", "case", "catch", "class", "const", "continue", "debugger", "default", "delete",
@@ -54,7 +55,7 @@ export function emitClient(outFile, compiled) {
54
55
  const inTypeName = op.inputElement ? pascal(op.inputElement.local) : undefined;
55
56
  const outTypeName = op.outputElement ? pascal(op.outputElement.local) : undefined;
56
57
  if (!inTypeName && !outTypeName) {
57
- console.warn(`Operation ${op.name} has no input or output type defined. Skipping method generation.`);
58
+ warn(`Operation ${op.name} has no input or output type defined. Skipping method generation.`);
58
59
  continue;
59
60
  }
60
61
  const inTs = inTypeName ? `T.${inTypeName}` : `any`;
@@ -382,9 +383,8 @@ ${methodsBody}
382
383
  `;
383
384
  try {
384
385
  fs.writeFileSync(outFile, classTemplate.replace(`// noinspection JSAnnotator\n\n`, ''), "utf8");
385
- console.log(`Client class written to ${outFile}`);
386
386
  }
387
387
  catch (e) {
388
- console.log(`Failed to write catalog to ${outFile}`);
388
+ error(`Failed to write client to ${outFile}`);
389
389
  }
390
390
  }
@@ -1,13 +1,13 @@
1
1
  import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
2
2
  /**
3
- * Emits TypeScript interfaces and type aliases from a compiled WSDL catalog
3
+ * Generates TypeScript interfaces and type aliases from a compiled WSDL catalog
4
4
  *
5
5
  * This function generates a TypeScript file containing all the types required to
6
6
  * work with the SOAP service, including:
7
7
  *
8
8
  * - Type aliases for simple types (enums, restrictions, etc.)
9
9
  * - Interfaces for complex types with proper inheritance
10
- * - JSDoc annotations with XML metadata for runtime marshalling
10
+ * - JSDoc annotations with XML metadata for runtime marshaling
11
11
  *
12
12
  * Key design decisions:
13
13
  * - Text node is modeled as "$value" (not "value") to avoid collisions with real elements
@@ -18,5 +18,5 @@ import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
18
18
  * @param {string} outFile - Path to the output TypeScript file
19
19
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog
20
20
  */
21
- export declare function emitTypes(outFile: string, compiled: CompiledCatalog): void;
22
- //# sourceMappingURL=typesEmitter.d.ts.map
21
+ export declare function generateTypes(outFile: string, compiled: CompiledCatalog): void;
22
+ //# sourceMappingURL=generateTypes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateTypes.d.ts","sourceRoot":"","sources":["../../src/client/generateTypes.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAC,eAAe,EAAe,MAAM,+BAA+B,CAAC;AAGjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QA+IvE"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript Types Emitter
2
+ * TypeScript Types Generator
3
3
  *
4
4
  * This module is responsible for transforming the compiled WSDL catalog into TypeScript
5
5
  * type definitions. It generates interfaces for complex types and type aliases for
@@ -13,15 +13,16 @@
13
13
  * - Optional/required markers based on XML schema requirements
14
14
  */
15
15
  import fs from "node:fs";
16
+ import { error } from "../util/cli.js";
16
17
  /**
17
- * Emits TypeScript interfaces and type aliases from a compiled WSDL catalog
18
+ * Generates TypeScript interfaces and type aliases from a compiled WSDL catalog
18
19
  *
19
20
  * This function generates a TypeScript file containing all the types required to
20
21
  * work with the SOAP service, including:
21
22
  *
22
23
  * - Type aliases for simple types (enums, restrictions, etc.)
23
24
  * - Interfaces for complex types with proper inheritance
24
- * - JSDoc annotations with XML metadata for runtime marshalling
25
+ * - JSDoc annotations with XML metadata for runtime marshaling
25
26
  *
26
27
  * Key design decisions:
27
28
  * - Text node is modeled as "$value" (not "value") to avoid collisions with real elements
@@ -32,7 +33,7 @@ import fs from "node:fs";
32
33
  * @param {string} outFile - Path to the output TypeScript file
33
34
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog
34
35
  */
35
- export function emitTypes(outFile, compiled) {
36
+ export function generateTypes(outFile, compiled) {
36
37
  const lines = [];
37
38
  // Convenience lookups
38
39
  const typeNames = new Set(compiled.types.map((t) => t.name));
@@ -162,9 +163,8 @@ export function emitTypes(outFile, compiled) {
162
163
  }
163
164
  try {
164
165
  fs.writeFileSync(outFile, lines.join("\n"), "utf8");
165
- console.log(`Types written to ${outFile}`);
166
166
  }
167
167
  catch (e) {
168
- console.error(`Failed to write types to ${outFile}:`, e);
168
+ error(`Failed to write types to ${outFile}: ${e instanceof Error ? e.message : String(e)}`);
169
169
  }
170
170
  }
@@ -1,6 +1,6 @@
1
1
  import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
2
2
  /**
3
- * Emits utility types and constants for XML serialization/deserialization
3
+ * Generates utility types and constants for XML serialization/deserialization
4
4
  *
5
5
  * This function generates a TypeScript file containing metadata mappings that help
6
6
  * the SOAP client distinguish between XML attributes and child elements during
@@ -9,7 +9,7 @@ import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
9
9
  * 1. A DataTypes interface defining the structure of the metadata
10
10
  * 2. A constant containing the actual mappings extracted from the compiled catalog
11
11
  *
12
- * The metadata is critical for proper XML marshalling and unmarshalling, as it enables
12
+ * The metadata is critical for proper XML marshaling and unmarshalling, as it enables
13
13
  * the client to correctly handle XML attributes vs. child elements, maintain type information
14
14
  * during recursive processing, and ensure that the XML structure matches the WSDL specification.
15
15
  *
@@ -17,5 +17,5 @@ import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
17
17
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog containing metadata
18
18
  * @throws {Error} If metadata is missing or has an invalid structure
19
19
  */
20
- export declare function emitUtils(outFile: string, compiled: CompiledCatalog): void;
21
- //# sourceMappingURL=utilsEmitter.d.ts.map
20
+ export declare function generateUtils(outFile: string, compiled: CompiledCatalog): void;
21
+ //# sourceMappingURL=generateUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateUtils.d.ts","sourceRoot":"","sources":["../../src/client/generateUtils.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAInE;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QAgCvE"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * TypeScript SOAP Client Utilities Emitter
2
+ * TypeScript SOAP Client Utilities Generator
3
3
  *
4
4
  * This module generates utility types and constants needed for the TypeScript SOAP client
5
5
  * to properly handle XML serialization and deserialization. It creates metadata mappings
@@ -12,8 +12,9 @@
12
12
  */
13
13
  import fs from "node:fs";
14
14
  import { deriveClientName, pascalToSnakeCase } from "../util/tools.js";
15
+ import { error } from "../util/cli.js";
15
16
  /**
16
- * Emits utility types and constants for XML serialization/deserialization
17
+ * Generates utility types and constants for XML serialization/deserialization
17
18
  *
18
19
  * This function generates a TypeScript file containing metadata mappings that help
19
20
  * the SOAP client distinguish between XML attributes and child elements during
@@ -22,7 +23,7 @@ import { deriveClientName, pascalToSnakeCase } from "../util/tools.js";
22
23
  * 1. A DataTypes interface defining the structure of the metadata
23
24
  * 2. A constant containing the actual mappings extracted from the compiled catalog
24
25
  *
25
- * The metadata is critical for proper XML marshalling and unmarshalling, as it enables
26
+ * The metadata is critical for proper XML marshaling and unmarshalling, as it enables
26
27
  * the client to correctly handle XML attributes vs. child elements, maintain type information
27
28
  * during recursive processing, and ensure that the XML structure matches the WSDL specification.
28
29
  *
@@ -30,12 +31,12 @@ import { deriveClientName, pascalToSnakeCase } from "../util/tools.js";
30
31
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog containing metadata
31
32
  * @throws {Error} If metadata is missing or has an invalid structure
32
33
  */
33
- export function emitUtils(outFile, compiled) {
34
+ export function generateUtils(outFile, compiled) {
34
35
  const clientName = deriveClientName(compiled);
35
36
  const clientConstant = pascalToSnakeCase(clientName).toUpperCase();
36
37
  const { attrSpec, childType } = compiled.meta;
37
38
  if (!attrSpec || !childType) {
38
- throw new Error("Metadata not found in compiled catalog. Ensure schemaCompiler runs before metaEmitter.");
39
+ throw new Error("Metadata not found in compiled catalog. Ensure schemaCompiler runs before generator.");
39
40
  }
40
41
  if (typeof attrSpec !== "object" || typeof childType !== "object") {
41
42
  throw new Error("Invalid metadata structure. Expected objects for Attributes and ChildrenTypes.");
@@ -55,9 +56,8 @@ export interface ${clientName}DataTypes {
55
56
  export const ${clientConstant}_DATA_TYPES: ${clientName}DataTypes = ${metas} as const;\n`;
56
57
  try {
57
58
  fs.writeFileSync(outFile, dataTypes, "utf8");
58
- console.log(`Utils written to ${outFile}`);
59
59
  }
60
60
  catch (e) {
61
- console.error(`Failed to write utils to ${outFile}:`, e);
61
+ error(`Failed to write utils to ${outFile}: ${e instanceof Error ? e.message : String(e)}`);
62
62
  }
63
63
  }
@@ -1,6 +1,6 @@
1
- import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
1
+ import type { CompiledCatalog } from "./schemaCompiler.js";
2
2
  /**
3
- * Emits the compiled catalog as a JSON file
3
+ * Generates the compiled catalog as a JSON file
4
4
  *
5
5
  * This function writes the complete compiled catalog to a JSON file, preserving all
6
6
  * type definitions, operation information, and metadata in a structured format.
@@ -17,5 +17,5 @@ import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
17
17
  * @param {string} outFile - Path to the output JSON file
18
18
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog to write
19
19
  */
20
- export declare function emitCatalog(outFile: string, compiled: CompiledCatalog): void;
21
- //# sourceMappingURL=catalogEmitter.d.ts.map
20
+ export declare function generateCatalog(outFile: string, compiled: CompiledCatalog): void;
21
+ //# sourceMappingURL=generateCatalog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateCatalog.d.ts","sourceRoot":"","sources":["../../src/compiler/generateCatalog.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC;AAGzD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,eAAe,QAMzE"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Catalog Emitter for TypeScript WSDL Client Generator
2
+ * Catalog Generator for TypeScript WSDL Client Generator
3
3
  *
4
4
  * This module is responsible for writing the complete compiled catalog to a JSON file,
5
5
  * which serves as a structured representation of the WSDL for introspection and further
@@ -12,8 +12,9 @@
12
12
  * - Enabling incremental compilation workflows
13
13
  */
14
14
  import fs from "node:fs";
15
+ import { error } from "../util/cli.js";
15
16
  /**
16
- * Emits the compiled catalog as a JSON file
17
+ * Generates the compiled catalog as a JSON file
17
18
  *
18
19
  * This function writes the complete compiled catalog to a JSON file, preserving all
19
20
  * type definitions, operation information, and metadata in a structured format.
@@ -30,12 +31,11 @@ import fs from "node:fs";
30
31
  * @param {string} outFile - Path to the output JSON file
31
32
  * @param {CompiledCatalog} compiled - The compiled WSDL catalog to write
32
33
  */
33
- export function emitCatalog(outFile, compiled) {
34
+ export function generateCatalog(outFile, compiled) {
34
35
  try {
35
36
  fs.writeFileSync(outFile, JSON.stringify(compiled, null, 2), "utf8");
36
- console.log(`Catalog written to ${outFile}`);
37
37
  }
38
38
  catch (err) {
39
- console.error(`Failed to write catalog to ${outFile}:`, err);
39
+ error(`Failed to write catalog to ${outFile}: ${err instanceof Error ? err.message : String(err)}`);
40
40
  }
41
41
  }
@@ -125,7 +125,7 @@ export type CompiledCatalog = {
125
125
  * 1. Collect and index complexType, simpleType, and element definitions across all schemas.
126
126
  * 2. Recursively compile each named type to a TS interface or alias, handling inheritance,
127
127
  * inline definitions, and XSD primitives.
128
- * 3. Build metadata maps for runtime marshalling (attributes, children, nillable, occurrence).
128
+ * 3. Build metadata maps for runtime marshaling (attributes, children, nillable, occurrence).
129
129
  * 4. Extract WSDL operations: pick the appropriate SOAP binding (v1.1 or v1.2), resolve its
130
130
  * portType reference, then enumerate operations and their soapAction URIs.
131
131
  */
@@ -97,7 +97,7 @@ function collectSecurityFromPolicyNodes(policyNodes) {
97
97
  * 1. Collect and index complexType, simpleType, and element definitions across all schemas.
98
98
  * 2. Recursively compile each named type to a TS interface or alias, handling inheritance,
99
99
  * inline definitions, and XSD primitives.
100
- * 3. Build metadata maps for runtime marshalling (attributes, children, nillable, occurrence).
100
+ * 3. Build metadata maps for runtime marshaling (attributes, children, nillable, occurrence).
101
101
  * 4. Extract WSDL operations: pick the appropriate SOAP binding (v1.1 or v1.2), resolve its
102
102
  * portType reference, then enumerate operations and their soapAction URIs.
103
103
  */
package/dist/config.d.ts CHANGED
@@ -51,4 +51,17 @@ export type CompilerOptions = {
51
51
  * Default compiler options. Users may override selectively.
52
52
  */
53
53
  export declare const TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS: CompilerOptions;
54
+ /**
55
+ * Resolve full compiler options from partial input
56
+ *
57
+ * Merges defaults with user-provided options and required overrides.
58
+ *
59
+ * @param input - Partial compiler options from CLI or API
60
+ * @param required - Required overrides (wsdl, out)
61
+ * @returns Complete compiler options
62
+ */
63
+ export declare function resolveCompilerOptions(input: Partial<CompilerOptions>, required: {
64
+ wsdl: string;
65
+ out: string;
66
+ }): CompilerOptions;
54
67
  //# sourceMappingURL=config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;IAC9B,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,SAAS,EAAE,gBAAgB,CAAC;IAC5B,8FAA8F;IAC9F,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;IAClC,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,+CAA+C,EAAE,eAgB7D,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,oCAAoC;IACpC,GAAG,EAAE,MAAM,CAAC;IACZ,6CAA6C;IAC7C,OAAO,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;IAC9B,0DAA0D;IAC1D,OAAO,EAAE,OAAO,CAAC;IACjB,+EAA+E;IAC/E,SAAS,EAAE,gBAAgB,CAAC;IAC5B,8FAA8F;IAC9F,MAAM,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC;IAClC,gFAAgF;IAChF,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wEAAwE;IACxE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,qEAAqE;IACrE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,+CAA+C,EAAE,eAgB7D,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,CAAC,eAAe,CAAC,EAC/B,QAAQ,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACtC,eAAe,CAOjB"}
package/dist/config.js CHANGED
@@ -18,3 +18,20 @@ export const TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS = {
18
18
  clientName: undefined, // no default
19
19
  nillableAsOptional: false, // CLI default
20
20
  };
21
+ /**
22
+ * Resolve full compiler options from partial input
23
+ *
24
+ * Merges defaults with user-provided options and required overrides.
25
+ *
26
+ * @param input - Partial compiler options from CLI or API
27
+ * @param required - Required overrides (wsdl, out)
28
+ * @returns Complete compiler options
29
+ */
30
+ export function resolveCompilerOptions(input, required) {
31
+ return {
32
+ ...TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS,
33
+ ...input,
34
+ wsdl: required.wsdl,
35
+ out: required.out,
36
+ };
37
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Options for gateway code generation
3
+ *
4
+ * @interface GenerateGatewayOptions
5
+ * @property {string} [openapiFile] - Path to OpenAPI 3.1 JSON or YAML file (exclusive with openapiDocument)
6
+ * @property {any} [openapiDocument] - Pre-loaded OpenAPI document object (exclusive with openapiFile)
7
+ * @property {string} outDir - Output directory for generated gateway code
8
+ * @property {string} [clientDir] - Path to client directory (where client.ts is located) for importing client code
9
+ * @property {string} versionSlug - Version identifier for URN generation (required)
10
+ * @property {string} serviceSlug - Service identifier for URN generation (required)
11
+ * @property {number[]} [defaultResponseStatusCodes] - Status codes to backfill with default response
12
+ * @property {"js"|"ts"|"bare"} [imports] - Import-extension mode for generated TypeScript modules (mirrors global --imports)
13
+ */
14
+ export interface GenerateGatewayOptions {
15
+ openapiFile?: string;
16
+ openapiDocument?: any;
17
+ outDir: string;
18
+ clientDir?: string;
19
+ versionSlug: string;
20
+ serviceSlug: string;
21
+ defaultResponseStatusCodes?: number[];
22
+ imports?: "js" | "ts" | "bare";
23
+ }
24
+ /**
25
+ * Generates Fastify gateway code from an OpenAPI 3.1 specification
26
+ *
27
+ * This function orchestrates the complete gateway generation process:
28
+ * 1. Loads/validates the OpenAPI document
29
+ * 2. Validates version and service slugs are provided
30
+ * 3. Generates model schemas with URN IDs
31
+ * 4. Generates operation schemas with Fastify structure
32
+ * 5. Emits schema registration module
33
+ * 6. Emits route files and aggregator module
34
+ *
35
+ * Contract assumptions (strict validation):
36
+ * - All request/response bodies use $ref to components.schemas (no inline schemas)
37
+ * - Every operation has a default response with application/json content
38
+ * - All schemas referenced by operations exist in components.schemas
39
+ *
40
+ * @param {GenerateGatewayOptions} opts - Generation options
41
+ * @returns {Promise<void>}
42
+ * @throws {Error} If OpenAPI validation fails or contract assumptions are violated
43
+ *
44
+ * @example
45
+ * // From JSON file
46
+ * await generateGateway({
47
+ * openapiFile: "openapi.json",
48
+ * outDir: "gateway",
49
+ * versionSlug: "v1",
50
+ * serviceSlug: "weather"
51
+ * });
52
+ *
53
+ * @example
54
+ * // From YAML file
55
+ * await generateGateway({
56
+ * openapiFile: "openapi.yaml",
57
+ * outDir: "gateway",
58
+ * versionSlug: "v1",
59
+ * serviceSlug: "weather"
60
+ * });
61
+ *
62
+ * @example
63
+ * // From in-memory document
64
+ * await generateGateway({
65
+ * openapiDocument: openapiDoc,
66
+ * outDir: "gateway",
67
+ * versionSlug: "v1",
68
+ * serviceSlug: "weather",
69
+ * defaultResponseStatusCodes: [200, 400, 500]
70
+ * });
71
+ */
72
+ export declare function generateGateway(opts: GenerateGatewayOptions): Promise<void>;
73
+ //# sourceMappingURL=generateGateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateGateway.d.ts","sourceRoot":"","sources":["../../src/gateway/generateGateway.ts"],"names":[],"mappings":"AAiCA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,GAAG,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,0BAA0B,CAAC,EAAE,MAAM,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAqFjF"}
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Fastify Gateway Generator from OpenAPI 3.1
3
+ *
4
+ * This module generates production-ready Fastify gateway code from OpenAPI 3.1 specifications.
5
+ * It creates a complete "slice" (schemas + routes) for a single SOAP service and version,
6
+ * bridging the gap between OpenAPI specs and running Fastify applications.
7
+ *
8
+ * Core capabilities:
9
+ * - Generates JSON Schema files with URN-based IDs for all components
10
+ * - Creates Fastify-compatible operation schemas (body, params, querystring, headers, response)
11
+ * - Emits route registration code with handler stubs
12
+ * - Enforces strict contract validation (no inline schemas, proper $refs)
13
+ *
14
+ * Output structure:
15
+ * {outDir}/
16
+ * schemas/
17
+ * models/ - JSON Schema components (re-ID'd with URNs)
18
+ * operations/ - Fastify operation schemas
19
+ * routes/ - Individual route registration files
20
+ * schemas.ts - Schema registration module
21
+ * routes.ts - Route registration module
22
+ */
23
+ import fs from "node:fs";
24
+ import path from "node:path";
25
+ import * as yaml from "js-yaml";
26
+ import { buildParamSchemasForOperation, getJsonSchemaRefName, isNumericStatus, } from "./helpers.js";
27
+ import { emitModelSchemas, emitOperationSchemas, emitRouteFiles, emitSchemasModule, } from "./generators.js";
28
+ /**
29
+ * Generates Fastify gateway code from an OpenAPI 3.1 specification
30
+ *
31
+ * This function orchestrates the complete gateway generation process:
32
+ * 1. Loads/validates the OpenAPI document
33
+ * 2. Validates version and service slugs are provided
34
+ * 3. Generates model schemas with URN IDs
35
+ * 4. Generates operation schemas with Fastify structure
36
+ * 5. Emits schema registration module
37
+ * 6. Emits route files and aggregator module
38
+ *
39
+ * Contract assumptions (strict validation):
40
+ * - All request/response bodies use $ref to components.schemas (no inline schemas)
41
+ * - Every operation has a default response with application/json content
42
+ * - All schemas referenced by operations exist in components.schemas
43
+ *
44
+ * @param {GenerateGatewayOptions} opts - Generation options
45
+ * @returns {Promise<void>}
46
+ * @throws {Error} If OpenAPI validation fails or contract assumptions are violated
47
+ *
48
+ * @example
49
+ * // From JSON file
50
+ * await generateGateway({
51
+ * openapiFile: "openapi.json",
52
+ * outDir: "gateway",
53
+ * versionSlug: "v1",
54
+ * serviceSlug: "weather"
55
+ * });
56
+ *
57
+ * @example
58
+ * // From YAML file
59
+ * await generateGateway({
60
+ * openapiFile: "openapi.yaml",
61
+ * outDir: "gateway",
62
+ * versionSlug: "v1",
63
+ * serviceSlug: "weather"
64
+ * });
65
+ *
66
+ * @example
67
+ * // From in-memory document
68
+ * await generateGateway({
69
+ * openapiDocument: openapiDoc,
70
+ * outDir: "gateway",
71
+ * versionSlug: "v1",
72
+ * serviceSlug: "weather",
73
+ * defaultResponseStatusCodes: [200, 400, 500]
74
+ * });
75
+ */
76
+ export async function generateGateway(opts) {
77
+ // Validate input sources
78
+ if (!opts.openapiDocument && !opts.openapiFile) {
79
+ throw new Error("Provide one of: openapiDocument or openapiFile");
80
+ }
81
+ if (opts.openapiDocument && opts.openapiFile) {
82
+ throw new Error("Provide only one source: openapiDocument OR openapiFile");
83
+ }
84
+ // Load OpenAPI document
85
+ let doc;
86
+ if (opts.openapiFile) {
87
+ const raw = fs.readFileSync(opts.openapiFile, "utf8");
88
+ const ext = path.extname(opts.openapiFile).toLowerCase();
89
+ // Parse based on file extension
90
+ if (ext === ".yaml" || ext === ".yml") {
91
+ doc = yaml.load(raw);
92
+ }
93
+ else if (ext === ".json") {
94
+ doc = JSON.parse(raw);
95
+ }
96
+ else {
97
+ throw new Error(`Unsupported OpenAPI file extension: ${ext}. Expected .json, .yaml, or .yml`);
98
+ }
99
+ }
100
+ else {
101
+ doc = opts.openapiDocument;
102
+ }
103
+ // Validate OpenAPI document structure
104
+ if (!doc || typeof doc !== "object" || typeof doc.paths !== "object") {
105
+ throw new Error("Invalid OpenAPI document: missing 'paths'");
106
+ }
107
+ if (!doc.components || !doc.components.schemas) {
108
+ throw new Error("Invalid OpenAPI document: missing 'components.schemas'");
109
+ }
110
+ // Validate that version and service slugs are provided
111
+ if (!opts.versionSlug || !opts.serviceSlug) {
112
+ throw new Error("Both versionSlug and serviceSlug are required for gateway generation");
113
+ }
114
+ const versionSlug = opts.versionSlug;
115
+ const serviceSlug = opts.serviceSlug;
116
+ // Set default response status codes if not provided
117
+ const defaultResponseStatusCodes = opts.defaultResponseStatusCodes || [
118
+ 200, 400, 401, 403, 404, 409, 422, 429, 500, 502, 503, 504,
119
+ ];
120
+ // Determine import-extension mode (defaults to "js" like the client/compiler)
121
+ const importsMode = opts.imports ?? "js";
122
+ // Prepare output directories
123
+ const outDir = opts.outDir;
124
+ const modelsDir = path.join(outDir, "schemas", "models");
125
+ const opsDir = path.join(outDir, "schemas", "operations");
126
+ const routesDir = path.join(outDir, "routes");
127
+ // Step 1: Generate model schemas and build URN mapping
128
+ const schemaIdByName = emitModelSchemas(doc.components.schemas, modelsDir, versionSlug, serviceSlug);
129
+ // Step 2: Generate operation schemas
130
+ const operations = emitOperationSchemas(doc, opsDir, versionSlug, serviceSlug, schemaIdByName, defaultResponseStatusCodes, buildParamSchemasForOperation, getJsonSchemaRefName, isNumericStatus);
131
+ // Step 3: Emit schemas.ts module
132
+ emitSchemasModule(outDir, modelsDir, versionSlug, serviceSlug);
133
+ // Step 4: Emit route files and routes.ts module
134
+ emitRouteFiles(outDir, routesDir, versionSlug, serviceSlug, operations, importsMode);
135
+ }
@@ -0,0 +1,90 @@
1
+ import { type OpenAPIDocument } from "./helpers.js";
2
+ /**
3
+ * Emits individual JSON Schema files for each OpenAPI component schema
4
+ *
5
+ * Process:
6
+ * 1. Creates schemas/models/ directory
7
+ * 2. For each component schema:
8
+ * - Generates URN $id: urn:services:{service}:{version}:schemas:models:{slug}
9
+ * - Rewrites all internal $refs to URN format
10
+ * - Writes to {slug}.json
11
+ *
12
+ * @param {Record<string, any>} schemas - OpenAPI components.schemas object
13
+ * @param {string} modelsDir - Output directory for model schema files
14
+ * @param {string} versionSlug - Version slug for URN generation
15
+ * @param {string} serviceSlug - Service slug for URN generation
16
+ * @returns {Record<string, string>} - Map from original schema name to URN ID
17
+ */
18
+ export declare function emitModelSchemas(schemas: Record<string, any>, modelsDir: string, versionSlug: string, serviceSlug: string): Record<string, string>;
19
+ /**
20
+ * Operation metadata for route generation
21
+ */
22
+ export interface OperationMetadata {
23
+ operationSlug: string;
24
+ method: string;
25
+ path: string;
26
+ }
27
+ /**
28
+ * Emits Fastify-compatible operation schema files
29
+ *
30
+ * Schema structure:
31
+ * {
32
+ * "$id": "urn:services:{service}:{version}:schemas:operations:{slug}",
33
+ * "body": { $ref: "..." }, // optional
34
+ * "params": { type: object, ... }, // optional
35
+ * "querystring": { type: object, ... }, // optional
36
+ * "headers": { type: object, ... }, // optional
37
+ * "response": {
38
+ * "200": { $ref: "..." },
39
+ * "400": { $ref: "..." },
40
+ * ...
41
+ * }
42
+ * }
43
+ *
44
+ * @param {OpenAPIDocument} doc - OpenAPI document
45
+ * @param {string} opsDir - Output directory for operation schema files
46
+ * @param {string} versionSlug - Version slug for URN generation
47
+ * @param {string} serviceSlug - Service slug for URN generation
48
+ * @param {Record<string, string>} schemaIdByName - Schema name to URN ID mapping
49
+ * @param {number[]} defaultResponseStatusCodes - Status codes to backfill with default response
50
+ * @param {Function} buildParamSchemas - Function to build param schemas
51
+ * @param {Function} getRefName - Function to extract $ref name
52
+ * @param {Function} isNumeric - Function to check if status code is numeric
53
+ * @returns {OperationMetadata[]} - Array of operation metadata for route generation
54
+ */
55
+ export declare function emitOperationSchemas(doc: OpenAPIDocument, opsDir: string, versionSlug: string, serviceSlug: string, schemaIdByName: Record<string, string>, defaultResponseStatusCodes: number[], buildParamSchemas: (pathItem: any, operation: any, doc: OpenAPIDocument, schemaIdByName: Record<string, string>) => any, getRefName: (schema: any) => string, isNumeric: (code: string) => boolean): OperationMetadata[];
56
+ /**
57
+ * Emits schemas.ts module that registers all model schemas with Fastify
58
+ *
59
+ * Generated code:
60
+ * - Imports all JSON files from schemas/models/
61
+ * - Exports registerSchemas_{version}_{service}(fastify) function
62
+ * - Calls fastify.addSchema for each model schema
63
+ *
64
+ * @param {string} outDir - Root output directory
65
+ * @param {string} modelsDir - Directory containing model schema files
66
+ * @param {string} versionSlug - Version slug for function naming
67
+ * @param {string} serviceSlug - Service slug for function naming
68
+ */
69
+ export declare function emitSchemasModule(outDir: string, modelsDir: string, versionSlug: string, serviceSlug: string): void;
70
+ /**
71
+ * Emits individual route files and routes.ts aggregator module
72
+ *
73
+ * For each operation:
74
+ * - Creates routes/{slug}.ts with registerRoute_{slug} function
75
+ * - Imports operation schema from schemas/operations/{slug}.json
76
+ * - Defines fastify.route() with method, url, schema, and stub handler
77
+ *
78
+ * Then creates routes.ts:
79
+ * - Imports all route registration functions
80
+ * - Exports registerRoutes_{version}_{service}(fastify) function
81
+ *
82
+ * @param {string} outDir - Root output directory
83
+ * @param {string} routesDir - Directory for individual route files
84
+ * @param {string} versionSlug - Version slug for function naming
85
+ * @param {string} serviceSlug - Service slug for function naming
86
+ * @param {OperationMetadata[]} operations - Array of operation metadata
87
+ * @param {"js"|"ts"|"bare"} importsMode - Import-extension mode for generated TypeScript modules
88
+ */
89
+ export declare function emitRouteFiles(outDir: string, routesDir: string, versionSlug: string, serviceSlug: string, operations: OperationMetadata[], importsMode: "js" | "ts" | "bare"): void;
90
+ //# sourceMappingURL=generators.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generators.d.ts","sourceRoot":"","sources":["../../src/gateway/generators.ts"],"names":[],"mappings":"AAcA,OAAO,EAAC,KAAK,eAAe,EAA+B,MAAM,cAAc,CAAC;AAEhF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CA0BxB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,eAAe,EACpB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EACtC,0BAA0B,EAAE,MAAM,EAAE,EACpC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,GAAG,EACvH,UAAU,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,EACnC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GACnC,iBAAiB,EAAE,CA2HrB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,GAClB,IAAI,CAsBN;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,iBAAiB,EAAE,EAC/B,WAAW,EAAE,IAAI,GAAG,IAAI,GAAG,MAAM,GAChC,IAAI,CA0CN"}