@techspokes/typescript-wsdl-client 0.6.3 → 0.7.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.
Files changed (53) hide show
  1. package/README.md +242 -166
  2. package/dist/cli.js +223 -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 +207 -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 +57 -0
  39. package/dist/openapi/generateOpenAPI.d.ts.map +1 -0
  40. package/dist/openapi/generateOpenAPI.js +174 -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
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Authentication scheme types supported in the OpenAPI specification
3
+ *
4
+ * @property {"none"} string No authentication required
5
+ * @property {"basic"} string HTTP Basic authentication
6
+ * @property {"bearer"} string HTTP Bearer token authentication
7
+ * @property {"apiKey"} string API key authentication
8
+ * @property {"oauth2"} string OAuth 2.0 authentication
9
+ */
10
+ export type AuthScheme = "none" | "basic" | "bearer" | "apiKey" | "oauth2";
11
+ /**
12
+ * Security configuration schema for the OpenAPI generation
13
+ *
14
+ * @interface SecurityConfig
15
+ * @property {Object} [global] - Global security settings applied to all operations by default
16
+ * @property {AuthScheme} [global.scheme] - Default authentication scheme
17
+ * @property {Object} [global.apiKey] - API key configuration (when scheme is "apiKey")
18
+ * @property {Object} [global.bearer] - Bearer token configuration (when scheme is "bearer")
19
+ * @property {Object} [global.basic] - Basic auth configuration (when scheme is "basic")
20
+ * @property {Object} [global.oauth2] - OAuth2 configuration (when scheme is "oauth2")
21
+ * @property {Array<Object>} [global.headers] - Global security headers
22
+ * @property {Record<string, Object>} [overrides] - Operation-specific security overrides
23
+ */
24
+ export type SecurityConfig = {
25
+ global?: {
26
+ scheme?: AuthScheme;
27
+ apiKey?: {
28
+ in: "header" | "query" | "cookie";
29
+ name: string;
30
+ };
31
+ bearer?: {
32
+ bearerFormat?: string;
33
+ };
34
+ basic?: Record<string, never>;
35
+ oauth2?: {
36
+ flows: Record<string, any>;
37
+ };
38
+ headers?: Array<{
39
+ name: string;
40
+ required?: boolean;
41
+ schema?: any;
42
+ }>;
43
+ };
44
+ overrides?: Record<string, {
45
+ scheme?: AuthScheme;
46
+ headers?: Array<{
47
+ name: string;
48
+ required?: boolean;
49
+ schema?: any;
50
+ }>;
51
+ }>;
52
+ };
53
+ /**
54
+ * Built security components for OpenAPI generation
55
+ *
56
+ * @interface BuiltSecurity
57
+ * @property {Record<string, any>} [securitySchemes] - Security schemes defined for the API
58
+ * @property {Record<string, any>} headerParameters - Header parameters for security
59
+ * @property {Record<string, any[]>} opSecurity - Operation security requirements
60
+ * @property {Record<string, string[]>} opHeaderParameters - Operation-specific header parameters
61
+ */
62
+ export type BuiltSecurity = {
63
+ securitySchemes?: Record<string, any>;
64
+ headerParameters: Record<string, any>;
65
+ opSecurity: Record<string, any[] | undefined>;
66
+ opHeaderParameters: Record<string, string[]>;
67
+ };
68
+ /**
69
+ * Load security configuration from a JSON file
70
+ *
71
+ * @param {string} [filePath] - Path to the security configuration file
72
+ * @returns {SecurityConfig|undefined} Parsed security configuration object or undefined if loading failed
73
+ */
74
+ export declare function loadSecurityConfig(filePath?: string): SecurityConfig | undefined;
75
+ /**
76
+ * Build security schemes and parameters for OpenAPI generation
77
+ *
78
+ * @param {SecurityConfig} [cfg] - Security configuration object
79
+ * @returns {BuiltSecurity} Object containing built security schemes and parameters
80
+ */
81
+ export declare function buildSecurity(cfg?: SecurityConfig): BuiltSecurity;
82
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../src/openapi/security.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,MAAM,MAA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,SAAS,CAAC,CAAC;IAC9C,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CAC9C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAShF;AAeD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,CAAC,EAAE,cAAc,GAAG,aAAa,CA+FjE"}
@@ -0,0 +1,145 @@
1
+ /**
2
+ * OpenAPI Security Configuration
3
+ *
4
+ * This module handles security scheme generation for the OpenAPI specification.
5
+ * It provides functionality to define authentication and authorization requirements
6
+ * for the API, including:
7
+ *
8
+ * - Basic authentication
9
+ * - Bearer token authentication
10
+ * - API key authentication
11
+ * - OAuth2 flows
12
+ * - Custom security headers
13
+ *
14
+ * The module supports both global security requirements and operation-specific
15
+ * security overrides through an external JSON configuration file.
16
+ */
17
+ import fs from "node:fs";
18
+ /**
19
+ * Load security configuration from a JSON file
20
+ *
21
+ * @param {string} [filePath] - Path to the security configuration file
22
+ * @returns {SecurityConfig|undefined} Parsed security configuration object or undefined if loading failed
23
+ */
24
+ export function loadSecurityConfig(filePath) {
25
+ if (!filePath)
26
+ return undefined;
27
+ try {
28
+ const raw = fs.readFileSync(filePath, "utf8");
29
+ return JSON.parse(raw);
30
+ }
31
+ catch (e) {
32
+ console.warn(`⚠️ Failed to read security config '${filePath}': ${e instanceof Error ? e.message : String(e)}`);
33
+ return undefined;
34
+ }
35
+ }
36
+ /**
37
+ * Generate a canonical parameter component name from a header name
38
+ *
39
+ * @param {string} headerName - Original header name
40
+ * @returns {string} Canonicalized component name
41
+ */
42
+ function makeParamComponentName(headerName) {
43
+ return headerName
44
+ .replace(/[^A-Za-z0-9]+/g, "_")
45
+ .replace(/^_+|_+$/g, "")
46
+ || "X_Header";
47
+ }
48
+ /**
49
+ * Build security schemes and parameters for OpenAPI generation
50
+ *
51
+ * @param {SecurityConfig} [cfg] - Security configuration object
52
+ * @returns {BuiltSecurity} Object containing built security schemes and parameters
53
+ */
54
+ export function buildSecurity(cfg) {
55
+ const securitySchemes = {};
56
+ const headerParameters = {};
57
+ const opSecurity = {};
58
+ const opHeaderParameters = {};
59
+ if (!cfg || !cfg.global) {
60
+ return { securitySchemes: undefined, headerParameters, opSecurity, opHeaderParameters };
61
+ }
62
+ const global = cfg.global;
63
+ const schemeName = "defaultAuth";
64
+ const scheme = global.scheme || "none";
65
+ const hasGlobal = scheme !== "none";
66
+ if (scheme !== "none") {
67
+ switch (scheme) {
68
+ case "basic":
69
+ securitySchemes[schemeName] = { type: "http", scheme: "basic" };
70
+ break;
71
+ case "bearer":
72
+ securitySchemes[schemeName] = { type: "http", scheme: "bearer", ...(global.bearer || {}) };
73
+ break;
74
+ case "apiKey":
75
+ securitySchemes[schemeName] = { type: "apiKey", ...(global.apiKey || { in: "header", name: "X-API-Key" }) };
76
+ break;
77
+ case "oauth2":
78
+ securitySchemes[schemeName] = { type: "oauth2", ...(global.oauth2 || { flows: {} }) };
79
+ break;
80
+ }
81
+ }
82
+ // Global headers
83
+ for (const h of global.headers || []) {
84
+ const compName = makeParamComponentName(h.name);
85
+ headerParameters[compName] = {
86
+ name: h.name,
87
+ in: "header",
88
+ required: !!h.required,
89
+ schema: h.schema || { type: "string" },
90
+ };
91
+ }
92
+ // Default op security (inherit global scheme)
93
+ // (If scheme is none we omit entirely)
94
+ // Overrides can set scheme to none to remove security
95
+ for (const [opName, override] of Object.entries(cfg.overrides || {})) {
96
+ const oScheme = override.scheme ?? scheme;
97
+ if (oScheme === "none") {
98
+ opSecurity[opName] = undefined;
99
+ }
100
+ else if (oScheme === scheme) {
101
+ opSecurity[opName] = hasGlobal ? [{ [schemeName]: [] }] : undefined;
102
+ }
103
+ else {
104
+ // Different scheme per operation -> create ad-hoc component name
105
+ const altName = `${schemeName}_${oScheme}`;
106
+ if (!securitySchemes[altName]) {
107
+ switch (oScheme) {
108
+ case "basic":
109
+ securitySchemes[altName] = { type: "http", scheme: "basic" };
110
+ break;
111
+ case "bearer":
112
+ securitySchemes[altName] = { type: "http", scheme: "bearer" };
113
+ break;
114
+ case "apiKey":
115
+ securitySchemes[altName] = { type: "apiKey", ...(global.apiKey || { in: "header", name: "X-API-Key" }) };
116
+ break;
117
+ case "oauth2":
118
+ securitySchemes[altName] = { type: "oauth2", ...(global.oauth2 || { flows: {} }) };
119
+ break;
120
+ }
121
+ }
122
+ opSecurity[opName] = [{ [altName]: [] }];
123
+ }
124
+ // Per-op headers merge global + override specific headers
125
+ const headers = [...(global.headers || []), ...(override.headers || [])];
126
+ opHeaderParameters[opName] = headers.map(h => makeParamComponentName(h.name));
127
+ for (const h of override.headers || []) {
128
+ const compName = makeParamComponentName(h.name);
129
+ if (!headerParameters[compName]) {
130
+ headerParameters[compName] = {
131
+ name: h.name,
132
+ in: "header",
133
+ required: !!h.required,
134
+ schema: h.schema || { type: "string" },
135
+ };
136
+ }
137
+ }
138
+ }
139
+ return {
140
+ securitySchemes: Object.keys(securitySchemes).length ? securitySchemes : undefined,
141
+ headerParameters,
142
+ opSecurity,
143
+ opHeaderParameters
144
+ };
145
+ }
@@ -0,0 +1,37 @@
1
+ import { type GenerateOpenAPIOptions } from "./openapi/generateOpenAPI.js";
2
+ import type { CompilerOptions } from "./config.js";
3
+ /**
4
+ * Configuration options for the generation pipeline
5
+ *
6
+ * @interface PipelineOptions
7
+ * @property {string} wsdl - Path or URL to the WSDL file to process
8
+ * @property {string} outDir - Output directory for generated TypeScript artifacts
9
+ * @property {Partial<CompilerOptions>} [compiler] - Compiler options for type generation
10
+ * @property {object} [openapi] - OpenAPI generation configuration (optional)
11
+ * @property {string} [openapi.outFile] - Optional output path for OpenAPI specification
12
+ */
13
+ export interface PipelineOptions {
14
+ wsdl: string;
15
+ outDir: string;
16
+ compiler?: Partial<CompilerOptions>;
17
+ openapi?: Omit<GenerateOpenAPIOptions, "wsdl" | "catalogFile" | "compiledCatalog"> & {
18
+ outFile?: string;
19
+ };
20
+ }
21
+ /**
22
+ * Runs the complete generation pipeline from WSDL to TypeScript artifacts and optionally OpenAPI
23
+ *
24
+ * This function orchestrates the entire process:
25
+ * 1. Loads and parses the WSDL from file or URL
26
+ * 2. Compiles the WSDL into an internal catalog representation
27
+ * 3. Emits TypeScript client code, types, and utilities
28
+ * 4. Optionally emits a JSON catalog for introspection
29
+ * 5. Optionally generates an OpenAPI 3.1 specification
30
+ *
31
+ * @param {PipelineOptions} opts - Configuration options for the pipeline
32
+ * @returns {Promise<{compiled: any}>} - The compiled catalog for potential further processing
33
+ */
34
+ export declare function runGenerationPipeline(opts: PipelineOptions): Promise<{
35
+ compiled: import("./compiler/schemaCompiler.js").CompiledCatalog;
36
+ }>;
37
+ //# sourceMappingURL=pipeline.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../src/pipeline.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAkB,KAAK,sBAAsB,EAAC,MAAM,8BAA8B,CAAC;AAC1F,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAGjD;;;;;;;;;GASG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAAC;IACpC,OAAO,CAAC,EAAE,IAAI,CAAC,sBAAsB,EAAE,MAAM,GAAG,aAAa,GAAG,iBAAiB,CAAC,GAAG;QAAE,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3G;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,eAAe;;GAgDhE"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * TypeScript WSDL Client Generation Pipeline
3
+ *
4
+ * This file implements the high-level generation pipeline that orchestrates the entire
5
+ * process of converting a WSDL file into TypeScript client code and optionally an OpenAPI
6
+ * specification. It serves as an integration layer between the various stages of the generation
7
+ * process.
8
+ */
9
+ import path from "node:path";
10
+ import fs from "node:fs";
11
+ import { loadWsdl } from "./loader/wsdlLoader.js";
12
+ import { compileCatalog } from "./compiler/schemaCompiler.js";
13
+ import { emitClient } from "./emit/clientEmitter.js";
14
+ import { emitTypes } from "./emit/typesEmitter.js";
15
+ import { emitUtils } from "./emit/utilsEmitter.js";
16
+ import { emitCatalog } from "./emit/catalogEmitter.js";
17
+ import { generateOpenAPI } from "./openapi/generateOpenAPI.js";
18
+ import { TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS } from "./config.js";
19
+ /**
20
+ * Runs the complete generation pipeline from WSDL to TypeScript artifacts and optionally OpenAPI
21
+ *
22
+ * This function orchestrates the entire process:
23
+ * 1. Loads and parses the WSDL from file or URL
24
+ * 2. Compiles the WSDL into an internal catalog representation
25
+ * 3. Emits TypeScript client code, types, and utilities
26
+ * 4. Optionally emits a JSON catalog for introspection
27
+ * 5. Optionally generates an OpenAPI 3.1 specification
28
+ *
29
+ * @param {PipelineOptions} opts - Configuration options for the pipeline
30
+ * @returns {Promise<{compiled: any}>} - The compiled catalog for potential further processing
31
+ */
32
+ export async function runGenerationPipeline(opts) {
33
+ // Merge provided compiler options with defaults, ensuring required fields are set
34
+ const finalCompiler = {
35
+ ...TYPESCRIPT_WSDL_CLIENT_DEFAULT_COMPLIER_OPTIONS,
36
+ catalog: opts.compiler?.catalog ?? true, // default to emitting catalog in pipeline mode
37
+ ...(opts.compiler || {}),
38
+ wsdl: opts.wsdl,
39
+ out: opts.outDir,
40
+ };
41
+ // Step 1: Load and parse the WSDL document
42
+ const wsdlCatalog = await loadWsdl(opts.wsdl);
43
+ // Step 2: Compile the WSDL into a structured catalog
44
+ const compiled = compileCatalog(wsdlCatalog, finalCompiler);
45
+ // Step 3: Ensure the output directory exists
46
+ fs.mkdirSync(opts.outDir, { recursive: true });
47
+ // Step 4: Emit TypeScript artifacts
48
+ emitClient(path.join(opts.outDir, "client.ts"), compiled);
49
+ emitTypes(path.join(opts.outDir, "types.ts"), compiled);
50
+ emitUtils(path.join(opts.outDir, "utils.ts"), compiled);
51
+ // Step 5: Optionally emit the JSON catalog for introspection
52
+ if (finalCompiler.catalog) {
53
+ emitCatalog(path.join(opts.outDir, "catalog.json"), compiled);
54
+ }
55
+ // Step 6: Optionally generate OpenAPI specification
56
+ if (opts.openapi) {
57
+ // Determine output path for OpenAPI specification
58
+ let resolvedOut = opts.openapi.outFile;
59
+ if (!resolvedOut) {
60
+ const yamlPreferred = !!opts.openapi.asYaml;
61
+ resolvedOut = path.join(opts.outDir, yamlPreferred ? "openapi.yaml" : "openapi.json");
62
+ }
63
+ // Generate the OpenAPI specification using the compiled catalog
64
+ await generateOpenAPI({
65
+ ...opts.openapi,
66
+ compiledCatalog: compiled,
67
+ outFile: resolvedOut,
68
+ });
69
+ }
70
+ // Return the compiled catalog for potential further processing
71
+ return { compiled };
72
+ }
@@ -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,E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AAE,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"}