@techspokes/typescript-wsdl-client 0.6.3 → 0.7.1

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 (53) hide show
  1. package/README.md +296 -166
  2. package/dist/cli.js +239 -1
  3. package/dist/compiler/schemaCompiler.d.ts +54 -0
  4. package/dist/compiler/schemaCompiler.d.ts.map +1 -1
  5. package/dist/compiler/schemaCompiler.js +74 -7
  6. package/dist/config.d.ts +23 -0
  7. package/dist/config.d.ts.map +1 -1
  8. package/dist/emit/catalogEmitter.d.ts +18 -0
  9. package/dist/emit/catalogEmitter.d.ts.map +1 -1
  10. package/dist/emit/catalogEmitter.js +31 -0
  11. package/dist/emit/clientEmitter.d.ts +17 -0
  12. package/dist/emit/clientEmitter.d.ts.map +1 -1
  13. package/dist/emit/clientEmitter.js +33 -3
  14. package/dist/emit/typesEmitter.d.ts +16 -5
  15. package/dist/emit/typesEmitter.d.ts.map +1 -1
  16. package/dist/emit/typesEmitter.js +30 -5
  17. package/dist/emit/utilsEmitter.d.ts +18 -0
  18. package/dist/emit/utilsEmitter.d.ts.map +1 -1
  19. package/dist/emit/utilsEmitter.js +30 -0
  20. package/dist/index.d.ts +22 -0
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +36 -1
  23. package/dist/loader/fetch.d.ts +31 -0
  24. package/dist/loader/fetch.d.ts.map +1 -1
  25. package/dist/loader/fetch.js +31 -0
  26. package/dist/loader/wsdlLoader.d.ts +32 -0
  27. package/dist/loader/wsdlLoader.d.ts.map +1 -1
  28. package/dist/loader/wsdlLoader.js +80 -9
  29. package/dist/openapi/buildPaths.d.ts +74 -0
  30. package/dist/openapi/buildPaths.d.ts.map +1 -0
  31. package/dist/openapi/buildPaths.js +66 -0
  32. package/dist/openapi/buildSchemas.d.ts +44 -0
  33. package/dist/openapi/buildSchemas.d.ts.map +1 -0
  34. package/dist/openapi/buildSchemas.js +196 -0
  35. package/dist/openapi/casing.d.ts +38 -0
  36. package/dist/openapi/casing.d.ts.map +1 -0
  37. package/dist/openapi/casing.js +49 -0
  38. package/dist/openapi/generateOpenAPI.d.ts +61 -0
  39. package/dist/openapi/generateOpenAPI.d.ts.map +1 -0
  40. package/dist/openapi/generateOpenAPI.js +315 -0
  41. package/dist/openapi/security.d.ts +82 -0
  42. package/dist/openapi/security.d.ts.map +1 -0
  43. package/dist/openapi/security.js +145 -0
  44. package/dist/pipeline.d.ts +37 -0
  45. package/dist/pipeline.d.ts.map +1 -0
  46. package/dist/pipeline.js +72 -0
  47. package/dist/util/tools.d.ts +100 -7
  48. package/dist/util/tools.d.ts.map +1 -1
  49. package/dist/util/tools.js +85 -7
  50. package/dist/xsd/primitives.d.ts +33 -0
  51. package/dist/xsd/primitives.d.ts.map +1 -1
  52. package/dist/xsd/primitives.js +59 -7
  53. package/package.json +7 -2
@@ -1,20 +1,113 @@
1
+ /**
2
+ * Utility Functions for TypeScript WSDL Client Generator
3
+ *
4
+ * This module provides a collection of helper functions used throughout the codebase
5
+ * for common tasks such as:
6
+ *
7
+ * - XML node processing and traversal
8
+ * - Name formatting and conversion between different cases
9
+ * - QName (qualified name) resolution with namespace handling
10
+ * - Array normalization and manipulation
11
+ * - Client name derivation from various sources
12
+ *
13
+ * These utilities create a consistent approach to handling common operations across
14
+ * the different modules of the generator.
15
+ */
1
16
  import type { CompiledCatalog } from "../compiler/schemaCompiler.js";
2
- /** Normalize a possibly-single value into an array. */
17
+ /**
18
+ * Normalizes a possibly-single value into an array
19
+ *
20
+ * XML parsers often return single items directly and multiple items as arrays.
21
+ * This function ensures consistent array treatment regardless of the input.
22
+ *
23
+ * @template T - Type of the array elements
24
+ * @param {T|T[]|undefined|null} x - Value to normalize
25
+ * @returns {T[]} - Array containing the value(s) or empty array if null/undefined
26
+ */
3
27
  export declare function normalizeArray<T>(x: T | T[] | undefined | null): T[];
4
- /** Collect direct children whose LOCAL name matches (prefix-agnostic). */
28
+ /**
29
+ * Collects direct children whose local name matches (prefix-agnostic)
30
+ *
31
+ * XML namespaces can cause the same element to appear with different prefixes.
32
+ * This function finds elements by their local name, ignoring namespace prefixes.
33
+ *
34
+ * @param {any} node - Parent XML node to search within
35
+ * @param {string} local - Local name to match (without namespace prefix)
36
+ * @returns {any[]} - Array of matching child nodes
37
+ */
5
38
  export declare function getChildrenWithLocalName(node: any, local: string): any[];
6
- /** Return the first direct child whose LOCAL name matches (prefix-agnostic). */
39
+ /**
40
+ * Returns the first direct child whose local name matches (prefix-agnostic)
41
+ *
42
+ * Similar to getChildrenWithLocalName but returns only the first matching node.
43
+ * Useful for elements that should appear only once in a valid document.
44
+ *
45
+ * @param {any} node - Parent XML node to search within
46
+ * @param {string} local - Local name to match (without namespace prefix)
47
+ * @returns {any|undefined} - First matching child node or undefined if none found
48
+ */
7
49
  export declare function getFirstWithLocalName(node: any, local: string): any | undefined;
8
- /** Simple PascalCase helper used across emitters/parsers. */
50
+ /**
51
+ * Converts a string to PascalCase format for TypeScript type names
52
+ *
53
+ * This function handles various input formats and produces valid TypeScript identifiers:
54
+ * - Converts separators (spaces, dashes, dots, etc.) to camelCase boundaries
55
+ * - Preserves underscores as literal characters
56
+ * - Removes invalid identifier characters
57
+ * - Ensures the result is a valid TypeScript identifier (not starting with numbers)
58
+ * - Avoids collision with TypeScript reserved keywords
59
+ *
60
+ * @param {string} s - Input string to convert to PascalCase
61
+ * @returns {string} - Valid TypeScript identifier in PascalCase
62
+ */
9
63
  export declare function pascal(s: string): string;
64
+ /**
65
+ * Resolves a qualified name (QName) to its namespace and local parts
66
+ *
67
+ * XML uses qualified names (prefix:localName) to reference elements in namespaces.
68
+ * This function resolves the prefix to its full namespace URI using the provided prefixes map.
69
+ *
70
+ * @param {string} qname - Qualified name (e.g., "xs:string" or "myPrefix:elementName")
71
+ * @param {string} defaultNS - Default namespace to use if no prefix is present
72
+ * @param {Record<string, string>} prefixes - Map of namespace prefixes to full URIs
73
+ * @returns {{ns: string, local: string}} - Object containing namespace URI and local name
74
+ */
10
75
  export declare function resolveQName(qname: string, defaultNS: string, prefixes: Record<string, string>): {
11
76
  ns: string;
12
77
  local: string;
13
78
  };
14
- /** Derive a SOAP client class name from CompilerOptions and compiled catalog. */
79
+ /**
80
+ * Derives a SOAP client class name from various sources
81
+ *
82
+ * This function uses a hierarchy of sources to determine an appropriate class name:
83
+ * 1. Explicit override from compiler options (highest priority)
84
+ * 2. Service name from the WSDL document
85
+ * 3. WSDL filename without extension
86
+ * 4. Default fallback name ("GeneratedSOAPClient")
87
+ *
88
+ * @param {CompiledCatalog} compiled - The compiled WSDL catalog
89
+ * @returns {string} - Appropriate class name for the generated SOAP client
90
+ */
15
91
  export declare function deriveClientName(compiled: CompiledCatalog): string;
16
- /** Explode a PascalCase string into its constituent segments. */
92
+ /**
93
+ * Explodes a PascalCase string into its constituent segments
94
+ *
95
+ * This function breaks a PascalCase identifier into individual words
96
+ * by inserting underscores at camelCase transitions and then splitting.
97
+ *
98
+ * @param {string} s - PascalCase string to explode
99
+ * @returns {string[]} - Array of individual segments
100
+ */
17
101
  export declare function explodePascal(s: string): string[];
18
- /** Convert a PascalCase string to snake_case (lowercase + underscores). */
102
+ /**
103
+ * Convert a PascalCase string to snake_case (lowercase + underscores).
104
+ *
105
+ * This function takes a PascalCase string, explodes it into its component segments,
106
+ * converts each segment to lowercase, and joins them with underscores to form a
107
+ * snake_case string.
108
+ *
109
+ * @param {string} s - PascalCase string to convert
110
+ * @returns {string} - snake_case version of the input string
111
+ */
19
112
  export declare function pascalToSnakeCase(s: string): string;
20
113
  //# sourceMappingURL=tools.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/util/tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,uDAAuD;AACvD,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,EAAE,CAGpE;AAED,0EAA0E;AAC1E,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,CASxE;AAED,gFAAgF;AAChF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAK/E;AAED,6DAA6D;AAC7D,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CA6BxC;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAS/B;AAED,iFAAiF;AACjF,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,GACxB,MAAM,CAWR;AAED,iEAAiE;AACjE,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAMjD;AAED,2EAA2E;AAC3E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD"}
1
+ {"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/util/tools.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,+BAA+B,CAAC;AAEnE;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,SAAS,GAAG,IAAI,GAAG,CAAC,EAAE,CAGpE;AAED;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,EAAE,CASxE;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAK/E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CA6BxC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC/B;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAS/B;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,eAAe,GACxB,MAAM,CAWR;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAMjD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAInD"}
@@ -1,10 +1,28 @@
1
- /** Normalize a possibly-single value into an array. */
1
+ /**
2
+ * Normalizes a possibly-single value into an array
3
+ *
4
+ * XML parsers often return single items directly and multiple items as arrays.
5
+ * This function ensures consistent array treatment regardless of the input.
6
+ *
7
+ * @template T - Type of the array elements
8
+ * @param {T|T[]|undefined|null} x - Value to normalize
9
+ * @returns {T[]} - Array containing the value(s) or empty array if null/undefined
10
+ */
2
11
  export function normalizeArray(x) {
3
12
  if (x == null)
4
13
  return [];
5
14
  return Array.isArray(x) ? x : [x];
6
15
  }
7
- /** Collect direct children whose LOCAL name matches (prefix-agnostic). */
16
+ /**
17
+ * Collects direct children whose local name matches (prefix-agnostic)
18
+ *
19
+ * XML namespaces can cause the same element to appear with different prefixes.
20
+ * This function finds elements by their local name, ignoring namespace prefixes.
21
+ *
22
+ * @param {any} node - Parent XML node to search within
23
+ * @param {string} local - Local name to match (without namespace prefix)
24
+ * @returns {any[]} - Array of matching child nodes
25
+ */
8
26
  export function getChildrenWithLocalName(node, local) {
9
27
  const out = [];
10
28
  for (const [k, v] of Object.entries(node || {})) {
@@ -15,7 +33,16 @@ export function getChildrenWithLocalName(node, local) {
15
33
  }
16
34
  return out;
17
35
  }
18
- /** Return the first direct child whose LOCAL name matches (prefix-agnostic). */
36
+ /**
37
+ * Returns the first direct child whose local name matches (prefix-agnostic)
38
+ *
39
+ * Similar to getChildrenWithLocalName but returns only the first matching node.
40
+ * Useful for elements that should appear only once in a valid document.
41
+ *
42
+ * @param {any} node - Parent XML node to search within
43
+ * @param {string} local - Local name to match (without namespace prefix)
44
+ * @returns {any|undefined} - First matching child node or undefined if none found
45
+ */
19
46
  export function getFirstWithLocalName(node, local) {
20
47
  for (const [k, v] of Object.entries(node || {})) {
21
48
  if (k === local || k.endsWith(`:${local}`))
@@ -23,7 +50,19 @@ export function getFirstWithLocalName(node, local) {
23
50
  }
24
51
  return undefined;
25
52
  }
26
- /** Simple PascalCase helper used across emitters/parsers. */
53
+ /**
54
+ * Converts a string to PascalCase format for TypeScript type names
55
+ *
56
+ * This function handles various input formats and produces valid TypeScript identifiers:
57
+ * - Converts separators (spaces, dashes, dots, etc.) to camelCase boundaries
58
+ * - Preserves underscores as literal characters
59
+ * - Removes invalid identifier characters
60
+ * - Ensures the result is a valid TypeScript identifier (not starting with numbers)
61
+ * - Avoids collision with TypeScript reserved keywords
62
+ *
63
+ * @param {string} s - Input string to convert to PascalCase
64
+ * @returns {string} - Valid TypeScript identifier in PascalCase
65
+ */
27
66
  export function pascal(s) {
28
67
  const raw = String(s ?? "");
29
68
  // Split on underscores to preserve them literally
@@ -55,6 +94,17 @@ export function pascal(s) {
55
94
  }
56
95
  return out;
57
96
  }
97
+ /**
98
+ * Resolves a qualified name (QName) to its namespace and local parts
99
+ *
100
+ * XML uses qualified names (prefix:localName) to reference elements in namespaces.
101
+ * This function resolves the prefix to its full namespace URI using the provided prefixes map.
102
+ *
103
+ * @param {string} qname - Qualified name (e.g., "xs:string" or "myPrefix:elementName")
104
+ * @param {string} defaultNS - Default namespace to use if no prefix is present
105
+ * @param {Record<string, string>} prefixes - Map of namespace prefixes to full URIs
106
+ * @returns {{ns: string, local: string}} - Object containing namespace URI and local name
107
+ */
58
108
  export function resolveQName(qname, defaultNS, prefixes) {
59
109
  if (!qname)
60
110
  return { ns: defaultNS, local: "" };
@@ -66,7 +116,18 @@ export function resolveQName(qname, defaultNS, prefixes) {
66
116
  }
67
117
  return { ns: defaultNS, local: qname };
68
118
  }
69
- /** Derive a SOAP client class name from CompilerOptions and compiled catalog. */
119
+ /**
120
+ * Derives a SOAP client class name from various sources
121
+ *
122
+ * This function uses a hierarchy of sources to determine an appropriate class name:
123
+ * 1. Explicit override from compiler options (highest priority)
124
+ * 2. Service name from the WSDL document
125
+ * 3. WSDL filename without extension
126
+ * 4. Default fallback name ("GeneratedSOAPClient")
127
+ *
128
+ * @param {CompiledCatalog} compiled - The compiled WSDL catalog
129
+ * @returns {string} - Appropriate class name for the generated SOAP client
130
+ */
70
131
  export function deriveClientName(compiled) {
71
132
  const overrideName = (compiled.options.clientName || "").trim();
72
133
  const svcName = compiled.serviceName ? pascal(compiled.serviceName) : "";
@@ -79,7 +140,15 @@ export function deriveClientName(compiled) {
79
140
  return overrideName
80
141
  || ((svcName || fileBase) ? `${svcName || fileBase}` : "GeneratedSOAPClient");
81
142
  }
82
- /** Explode a PascalCase string into its constituent segments. */
143
+ /**
144
+ * Explodes a PascalCase string into its constituent segments
145
+ *
146
+ * This function breaks a PascalCase identifier into individual words
147
+ * by inserting underscores at camelCase transitions and then splitting.
148
+ *
149
+ * @param {string} s - PascalCase string to explode
150
+ * @returns {string[]} - Array of individual segments
151
+ */
83
152
  export function explodePascal(s) {
84
153
  // insert underscores between camel‐transitions
85
154
  const withUnderscores = String(s)
@@ -87,7 +156,16 @@ export function explodePascal(s) {
87
156
  .replace(/([A-Z])([A-Z][a-z])/g, '$1_$2');
88
157
  return withUnderscores.split('_').filter(Boolean);
89
158
  }
90
- /** Convert a PascalCase string to snake_case (lowercase + underscores). */
159
+ /**
160
+ * Convert a PascalCase string to snake_case (lowercase + underscores).
161
+ *
162
+ * This function takes a PascalCase string, explodes it into its component segments,
163
+ * converts each segment to lowercase, and joins them with underscores to form a
164
+ * snake_case string.
165
+ *
166
+ * @param {string} s - PascalCase string to convert
167
+ * @returns {string} - snake_case version of the input string
168
+ */
91
169
  export function pascalToSnakeCase(s) {
92
170
  return explodePascal(s)
93
171
  .map(seg => seg.toLowerCase())
@@ -1,8 +1,41 @@
1
+ /**
2
+ * XSD to TypeScript Primitive Type Mapping
3
+ *
4
+ * This module defines how XML Schema (XSD) primitive types are mapped to TypeScript types.
5
+ * It provides a configurable mapping system with safe defaults that prioritizes
6
+ * data integrity over convenience:
7
+ *
8
+ * Key design decisions:
9
+ * - 64-bit integers (long/unsignedLong) default to string to prevent overflow in JavaScript number
10
+ * - Arbitrary-precision decimal types default to string to prevent loss of precision
11
+ * - Date/time types default to string (no automatic Date parsing/conversion)
12
+ * - Configurable options allow users to override defaults when appropriate for their use case
13
+ */
14
+ /**
15
+ * Configuration options for XSD primitive type mapping
16
+ *
17
+ * @interface PrimitiveOptions
18
+ * @property {string} [int64As] - How to map xs:long/xs:unsignedLong (default: "string")
19
+ * @property {string} [bigIntegerAs] - How to map xs:integer family (default: "string")
20
+ * @property {string} [decimalAs] - How to map xs:decimal (default: "string")
21
+ * @property {string} [dateAs] - How to map xs:date/xs:time family (default: "string")
22
+ */
1
23
  export type PrimitiveOptions = {
2
24
  int64As?: "string" | "number" | "bigint";
3
25
  bigIntegerAs?: "string" | "number";
4
26
  decimalAs?: "string" | "number";
5
27
  dateAs?: "string" | "Date";
6
28
  };
29
+ /**
30
+ * Maps an XSD QName to the corresponding TypeScript primitive type
31
+ *
32
+ * This function is the main entry point for determining the TypeScript type
33
+ * corresponding to an XSD primitive type. It uses the local part of the QName
34
+ * and the configured mapping options to return the correct TypeScript type.
35
+ *
36
+ * @param {string} xsdQName - The XSD QName to map (e.g., "xs:int")
37
+ * @param {PrimitiveOptions} [options] - Optional custom mapping options
38
+ * @returns {string} - The corresponding TypeScript primitive type
39
+ */
7
40
  export declare function xsdToTsPrimitive(xsdQName: string, options?: PrimitiveOptions): string;
8
41
  //# sourceMappingURL=primitives.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/xsd/primitives.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,gBAAgB,GAAG;IAC3B,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACzC,YAAY,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACnC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC9B,CAAC;AA+EF,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAwCrF"}
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/xsd/primitives.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;IACzC,YAAY,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IACnC,SAAS,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAChC,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;CAC5B,CAAC;AAgHF;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,MAAM,CAyCrF"}
@@ -1,15 +1,39 @@
1
- // Centralized XSD → TypeScript primitive mapping with safe defaults.
2
- // Rationale:
3
- // - 64-bit integers (long/unsignedLong) can overflow JS number → default to string
4
- // - Arbitrary-precision decimal (money) may lose precision in JS number default to string
5
- // - Dates/times stay as string by default (no runtime Date parsing in a generator)
1
+ /**
2
+ * XSD to TypeScript Primitive Type Mapping
3
+ *
4
+ * This module defines how XML Schema (XSD) primitive types are mapped to TypeScript types.
5
+ * It provides a configurable mapping system with safe defaults that prioritizes
6
+ * data integrity over convenience:
7
+ *
8
+ * Key design decisions:
9
+ * - 64-bit integers (long/unsignedLong) default to string to prevent overflow in JavaScript number
10
+ * - Arbitrary-precision decimal types default to string to prevent loss of precision
11
+ * - Date/time types default to string (no automatic Date parsing/conversion)
12
+ * - Configurable options allow users to override defaults when appropriate for their use case
13
+ */
14
+ /**
15
+ * Default primitive mapping options that prioritize data integrity over convenience
16
+ *
17
+ * These defaults ensure that no data is lost in the TypeScript representation, even
18
+ * for edge cases like very large integers or high-precision decimals.
19
+ */
6
20
  const DEFAULTS = {
7
21
  int64As: "string",
8
22
  bigIntegerAs: "string",
9
23
  decimalAs: "string",
10
24
  dateAs: "string",
11
25
  };
12
- // Helper to choose ts type for integer families depending on magnitude
26
+ /**
27
+ * Determines the appropriate TypeScript type for XSD integer families
28
+ *
29
+ * This function categorizes integer types by their potential size range:
30
+ * - 64-bit or arbitrary-precision integers use the configured type (default: string)
31
+ * - 32-bit or smaller integers use the native number type
32
+ *
33
+ * @param {string} local - Local name of the XSD type (e.g., "int", "long", "integer")
34
+ * @param {Required<PrimitiveOptions>} opts - Primitive mapping options
35
+ * @returns {string} - Appropriate TypeScript type for the integer type
36
+ */
13
37
  function intFamily(local, opts) {
14
38
  // 64-bit or unbounded families → configurable
15
39
  const int64 = new Set(["long", "unsignedLong"]);
@@ -34,14 +58,28 @@ function intFamily(local, opts) {
34
58
  return "number";
35
59
  return "number";
36
60
  }
61
+ /**
62
+ * Determines the appropriate TypeScript type for XSD decimal types
63
+ *
64
+ * @param {string} local - Local name of the XSD type (e.g., "decimal")
65
+ * @param {Required<PrimitiveOptions>} opts - Primitive mapping options
66
+ * @returns {string} - Appropriate TypeScript type for the decimal type
67
+ */
37
68
  function decimalFamily(local, opts) {
38
69
  // xs:decimal and derived decimals (if any) → configurable
39
70
  if (local === "decimal")
40
71
  return opts.decimalAs;
41
72
  return "number";
42
73
  }
74
+ /**
75
+ * Determines the appropriate TypeScript type for XSD date/time types
76
+ *
77
+ * @param {string} local - Local name of the XSD type (e.g., "date", "dateTime")
78
+ * @param {Required<PrimitiveOptions>} opts - Primitive mapping options
79
+ * @returns {string} - Appropriate TypeScript type for the date/time type
80
+ */
43
81
  function dateFamily(local, opts) {
44
- // You can choose "Date", but generator wont parse at runtime; its just type-level.
82
+ // You can choose "Date", but generator won't parse at runtime; it's just type-level.
45
83
  const s = opts.dateAs;
46
84
  switch (local) {
47
85
  case "date":
@@ -61,6 +99,9 @@ function dateFamily(local, opts) {
61
99
  return "string";
62
100
  }
63
101
  }
102
+ /**
103
+ * Set of XSD types that map to string in TypeScript
104
+ */
64
105
  const STRING_LIKE = new Set([
65
106
  "string",
66
107
  "normalizedString",
@@ -77,6 +118,17 @@ const STRING_LIKE = new Set([
77
118
  "hexBinary",
78
119
  "base64Binary", // could be "string" or a branded type
79
120
  ]);
121
+ /**
122
+ * Maps an XSD QName to the corresponding TypeScript primitive type
123
+ *
124
+ * This function is the main entry point for determining the TypeScript type
125
+ * corresponding to an XSD primitive type. It uses the local part of the QName
126
+ * and the configured mapping options to return the correct TypeScript type.
127
+ *
128
+ * @param {string} xsdQName - The XSD QName to map (e.g., "xs:int")
129
+ * @param {PrimitiveOptions} [options] - Optional custom mapping options
130
+ * @returns {string} - The corresponding TypeScript primitive type
131
+ */
80
132
  export function xsdToTsPrimitive(xsdQName, options) {
81
133
  const opts = { ...DEFAULTS, ...(options || {}) };
82
134
  // Expect formats like "xs:int". Fall back to string if unknown.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@techspokes/typescript-wsdl-client",
3
- "version": "0.6.3",
3
+ "version": "0.7.1",
4
4
  "description": "TypeScript WSDL → SOAP client generator with full xs:attribute support, complex types, sequences, inheritance, and namespace-collision merging.",
5
5
  "keywords": [
6
6
  "wsdl",
@@ -47,6 +47,7 @@
47
47
  "scripts": {
48
48
  "build": "tsc -p tsconfig.json",
49
49
  "clean": "rimraf dist",
50
+ "clean:tmp": "rimraf tmp",
50
51
  "dev": "tsx src/cli.ts",
51
52
  "watch": "tsx watch src/cli.ts",
52
53
  "typecheck": "tsc --noEmit",
@@ -54,9 +55,11 @@
54
55
  "test": "exit 0",
55
56
  "smoke": "tsx src/cli.ts --help",
56
57
  "smoke:gen": "rimraf tmp && tsx src/cli.ts --wsdl examples/minimal/weather.wsdl --out tmp && tsc -p tsconfig.smoke.json",
57
- "ci": "npm run build && npm run typecheck && npm run smoke && npm run smoke:gen"
58
+ "smoke:pipeline": "tsx src/cli.ts pipeline --wsdl examples/minimal/weather.wsdl --out tmp --clean --format both --tag-style service --openapi-out tmp/openapi --servers https://example.com/api",
59
+ "ci": "npm run build && npm run typecheck && npm run smoke && npm run smoke:gen && npm run smoke:pipeline"
58
60
  },
59
61
  "devDependencies": {
62
+ "@types/js-yaml": "^4.0.9",
60
63
  "@types/node": "^24.3.0",
61
64
  "@types/yargs": "^17.0.33",
62
65
  "rimraf": "^6.0.0",
@@ -64,7 +67,9 @@
64
67
  "typescript": "^5.6.3"
65
68
  },
66
69
  "dependencies": {
70
+ "@apidevtools/swagger-parser": "^10.0.3",
67
71
  "fast-xml-parser": "^5.2.5",
72
+ "js-yaml": "^4.1.0",
68
73
  "soap": "^1.3.0",
69
74
  "yargs": "^18.0.0"
70
75
  },