@voxgig/sdkgen 1.3.18 → 1.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cmp/Deploy.js +16 -16
- package/dist/cmp/Deploy.js.map +1 -1
- package/dist/cmp/ReadmeTop.js +13 -11
- package/dist/cmp/ReadmeTop.js.map +1 -1
- package/dist/helpers/naming.d.ts +3 -1
- package/dist/helpers/naming.js +65 -0
- package/dist/helpers/naming.js.map +1 -1
- package/dist/helpers/serverVars.d.ts +10 -0
- package/dist/helpers/serverVars.js +87 -0
- package/dist/helpers/serverVars.js.map +1 -0
- package/dist/sdkgen.d.ts +3 -2
- package/dist/sdkgen.js +6 -1
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/project/.sdk/model/target/go-cli.aontu +2 -2
- package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +22 -15
- package/project/.sdk/src/cmp/go/Config_go.ts +10 -1
- package/project/.sdk/src/cmp/go-cli/Main_go-cli.ts +54 -35
- package/project/.sdk/src/cmp/go-cli/fragment/main.fragment.go +7 -7
- package/project/.sdk/src/cmp/go-cli/fragment/words.fragment.go +21 -18
- package/project/.sdk/src/cmp/js/Config_js.ts +11 -0
- package/project/.sdk/src/cmp/js/fragment/Config.fragment.js +2 -2
- package/project/.sdk/src/cmp/js/fragment/Direct.test.fragment.js +4 -0
- package/project/.sdk/src/cmp/lua/Config_lua.ts +10 -1
- package/project/.sdk/src/cmp/php/Config_php.ts +13 -2
- package/project/.sdk/src/cmp/py/Config_py.ts +10 -1
- package/project/.sdk/src/cmp/rb/Config_rb.ts +12 -1
- package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +25 -18
- package/project/.sdk/src/cmp/swift/EntityTypes_swift.ts +10 -3
- package/project/.sdk/src/cmp/ts/Config_ts.ts +11 -0
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +2 -2
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +4 -0
- package/project/.sdk/tm/csharp/Makefile +6 -6
- package/project/.sdk/tm/dart/Makefile +3 -3
- package/project/.sdk/tm/go/Makefile +6 -6
- package/project/.sdk/tm/go/test/primary_utility_test.go +5 -0
- package/project/.sdk/tm/go/utility/make_options.go +48 -0
- package/project/.sdk/tm/java/Makefile +6 -6
- package/project/.sdk/tm/js/Makefile +6 -6
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +39 -1
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +5 -0
- package/project/.sdk/tm/kotlin/Makefile +6 -6
- package/project/.sdk/tm/lua/Makefile +7 -7
- package/project/.sdk/tm/lua/feature/test_feature.lua +29 -1
- package/project/.sdk/tm/lua/test/primary_utility_test.lua +4 -0
- package/project/.sdk/tm/lua/utility/make_options.lua +39 -0
- package/project/.sdk/tm/perl/Makefile +6 -6
- package/project/.sdk/tm/php/Makefile +6 -6
- package/project/.sdk/tm/php/feature/TestFeature.php +30 -2
- package/project/.sdk/tm/php/test/PrimaryUtilityTest.php +5 -0
- package/project/.sdk/tm/php/utility/MakeOptions.php +44 -0
- package/project/.sdk/tm/py/Makefile +6 -6
- package/project/.sdk/tm/py/test/test_primary_utility.py +5 -0
- package/project/.sdk/tm/py/utility/make_options.py +42 -0
- package/project/.sdk/tm/rb/Makefile +6 -6
- package/project/.sdk/tm/rb/test/primary_utility_test.rb +4 -0
- package/project/.sdk/tm/rb/utility/make_options.rb +37 -0
- package/project/.sdk/tm/rust/Makefile +6 -6
- package/project/.sdk/tm/swift/Makefile +6 -6
- package/project/.sdk/tm/ts/Makefile +6 -6
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +39 -1
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +4 -0
- package/src/cmp/Deploy.ts +16 -16
- package/src/cmp/ReadmeTop.ts +13 -11
- package/src/helpers/naming.ts +71 -0
- package/src/helpers/serverVars.ts +105 -0
- package/src/sdkgen.ts +6 -1
package/src/helpers/naming.ts
CHANGED
|
@@ -126,6 +126,75 @@ function rbSafeTypeName(Name: string): string {
|
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
|
|
129
|
+
// Swift SDK-OWNED TYPE NAMES — a third hazard, distinct from both sets above.
|
|
130
|
+
//
|
|
131
|
+
// The keyword sets guard local bindings; the Ruby set guards clobbering the
|
|
132
|
+
// LANGUAGE's core. This set guards clobbering OUR OWN runtime, because Swift
|
|
133
|
+
// has no namespacing WITHIN a module: every type the swift templates declare
|
|
134
|
+
// and every generated entity type land in the same module. Two declarations
|
|
135
|
+
// of one name is a hard error, not a silent override:
|
|
136
|
+
//
|
|
137
|
+
// // core/Response.swift (template)
|
|
138
|
+
// public final class Response { ... } // transport wrapper
|
|
139
|
+
// // entity/<Prefix>Types.swift (generated from a spec schema named Response)
|
|
140
|
+
// public struct Response { ... }
|
|
141
|
+
// -> error: invalid redeclaration of 'Response'
|
|
142
|
+
// -> error: 'Response' is ambiguous for type lookup (every core file)
|
|
143
|
+
//
|
|
144
|
+
// Found 2026-08-07: the Hook0 spec has a `Response` schema, which took the
|
|
145
|
+
// whole swift target down. `Response` is merely the first collision to be
|
|
146
|
+
// hit — every name below is equally exposed.
|
|
147
|
+
//
|
|
148
|
+
// Sourced by scanning BOTH `tm/swift/Sources/*/` (templates) and
|
|
149
|
+
// `src/cmp/swift/*.ts` (components) for top-level type declarations —
|
|
150
|
+
// regardless of access level. `internal` is Swift's default and is still
|
|
151
|
+
// module-wide, and `open class BaseFeature` is not `public` either, so an
|
|
152
|
+
// access-level filter under-collects and silently reopens the bug.
|
|
153
|
+
//
|
|
154
|
+
// Nested types (a `typealias Element` inside a struct) and the separate Tests
|
|
155
|
+
// module (`ReadmeExamplesTest`) do NOT share this namespace and are excluded.
|
|
156
|
+
//
|
|
157
|
+
// `swift-sdk-types.test.ts` re-derives this list from the templates and fails
|
|
158
|
+
// on drift, so adding a public type to a swift template cannot silently
|
|
159
|
+
// reopen the bug.
|
|
160
|
+
const SWIFT_SDK_TYPES = new Set<string>([
|
|
161
|
+
// core runtime
|
|
162
|
+
'Context', 'Control', 'Entity', 'Operation', 'Point', 'Response', 'Result',
|
|
163
|
+
'SdkConfig', 'Spec', 'Utility',
|
|
164
|
+
// struct library
|
|
165
|
+
'Injection', 'Injector', 'JSON', 'JSONParseError', 'Modify',
|
|
166
|
+
'OrderedDictionary', 'Sentinel', 'Value', 'VList', 'VMap', 'WalkApply',
|
|
167
|
+
// function/callback aliases
|
|
168
|
+
'FetcherFunc', 'Formatter', 'NativeCall0', 'NativeRef', 'SystemFetch',
|
|
169
|
+
// features
|
|
170
|
+
'AuditFeature', 'BaseFeature', 'CacheFeature', 'ClienttrackFeature',
|
|
171
|
+
'DebugFeature', 'IdempotencyFeature', 'LogFeature', 'MetricsBucket',
|
|
172
|
+
'MetricsFeature', 'NetsimFeature', 'PagingFeature', 'ProxyFeature',
|
|
173
|
+
'RatelimitFeature', 'RbacFeature', 'RetryFeature', 'StreamingFeature',
|
|
174
|
+
'TelemetryFeature', 'TestFeature', 'TimeoutFeature',
|
|
175
|
+
])
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
// Does `Name` collide with a type the swift SDK runtime already declares?
|
|
179
|
+
function isSwiftSdkType(Name: string): boolean {
|
|
180
|
+
return SWIFT_SDK_TYPES.has(Name)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
// A module-safe Swift type name for a generated type: unchanged, unless the
|
|
185
|
+
// swift runtime already declares it, in which case `Type` is appended
|
|
186
|
+
// (`Response` -> `ResponseType`). Mirrors rbSafeTypeName deliberately — same
|
|
187
|
+
// suffix, same "only rename on an actual collision" rule, so SDKs that do not
|
|
188
|
+
// collide are byte-identical to before.
|
|
189
|
+
//
|
|
190
|
+
// Applied ONLY to the bare entity data type. Per-op type names already carry
|
|
191
|
+
// their own suffix (`ResponseCreateData`, `ResponseLoadMatch`) and the entity
|
|
192
|
+
// CLASS is separately suffixed (`ResponseEntity`), so neither ever collided.
|
|
193
|
+
function swiftSafeTypeName(Name: string): string {
|
|
194
|
+
return isSwiftSdkType(Name) ? Name + 'Type' : Name
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
129
198
|
// Is `name` a reserved word (an illegal identifier) in the target language?
|
|
130
199
|
function isReservedName(name: string, lang: string): boolean {
|
|
131
200
|
const set = RESERVED[lang]
|
|
@@ -189,6 +258,8 @@ export {
|
|
|
189
258
|
exampleVarName,
|
|
190
259
|
isRbCoreConstant,
|
|
191
260
|
rbSafeTypeName,
|
|
261
|
+
isSwiftSdkType,
|
|
262
|
+
swiftSafeTypeName,
|
|
192
263
|
jsProp,
|
|
193
264
|
jsOptProp,
|
|
194
265
|
jsKey,
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// OpenAPI server-variable support (templated server URLs).
|
|
2
|
+
//
|
|
3
|
+
// A spec may declare its server URL as a template over named variables:
|
|
4
|
+
//
|
|
5
|
+
// servers:
|
|
6
|
+
// - url: https://{tenant_id}.hanko.io
|
|
7
|
+
// variables:
|
|
8
|
+
// tenant_id: { default: '', description: '...' }
|
|
9
|
+
//
|
|
10
|
+
// The generated SDKs carry the template verbatim in `options.base` and
|
|
11
|
+
// resolve it AT CONSTRUCTION via the `server` options block:
|
|
12
|
+
//
|
|
13
|
+
// new SDK({ server: { tenant_id: 'my-tenant' } })
|
|
14
|
+
//
|
|
15
|
+
// Resolution rules (identical in every target runtime):
|
|
16
|
+
// - each `{name}` in base is replaced with options.server[name],
|
|
17
|
+
// falling back to the spec default emitted into the SDK's Config;
|
|
18
|
+
// - a variable that resolves to '' is an ERROR at construction — the
|
|
19
|
+
// URL cannot work without it — EXCEPT in test mode, where the
|
|
20
|
+
// deterministic value `test-<name>` is substituted so offline tests
|
|
21
|
+
// never require configuration.
|
|
22
|
+
//
|
|
23
|
+
// This module is the emission-side half: it parses the spec's variables
|
|
24
|
+
// out of the model so Config emitters can write the `server` defaults
|
|
25
|
+
// block, and docs can name the required variables.
|
|
26
|
+
|
|
27
|
+
// One declared server variable. `required` is true when the spec gives no
|
|
28
|
+
// usable default — the caller MUST supply it for live use.
|
|
29
|
+
type ServerVar = {
|
|
30
|
+
name: string
|
|
31
|
+
dflt: string
|
|
32
|
+
required: boolean
|
|
33
|
+
description: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Match {name} placeholders in a server URL template. OpenAPI variable
|
|
38
|
+
// names are restricted to word characters in practice; a brace group that
|
|
39
|
+
// is not a well-formed name is left untouched rather than guessed at.
|
|
40
|
+
const SERVER_VAR_RE = /\{([A-Za-z0-9_]+)\}/g
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
// Parse the server variables declared on servers[0] of the model
|
|
44
|
+
// (main.<KIT>.info.servers.0). Variables are returned in URL order —
|
|
45
|
+
// the order their placeholders appear in the template — with declared
|
|
46
|
+
// variables that never appear in the URL appended after (harmless, but
|
|
47
|
+
// kept so docs can still describe them). Returns [] when the URL has no
|
|
48
|
+
// placeholders.
|
|
49
|
+
function serverVariables(model: any): ServerVar[] {
|
|
50
|
+
const info = model?.main?.kit?.info || model?.main?.KIT?.info
|
|
51
|
+
const server = info?.servers?.[0]
|
|
52
|
+
const url: string = server?.url || ''
|
|
53
|
+
const declared = server?.variables || {}
|
|
54
|
+
|
|
55
|
+
const out: ServerVar[] = []
|
|
56
|
+
const seen = new Set<string>()
|
|
57
|
+
|
|
58
|
+
SERVER_VAR_RE.lastIndex = 0
|
|
59
|
+
let m: RegExpExecArray | null
|
|
60
|
+
while (null != (m = SERVER_VAR_RE.exec(url))) {
|
|
61
|
+
const name = m[1]
|
|
62
|
+
if (seen.has(name)) { continue }
|
|
63
|
+
seen.add(name)
|
|
64
|
+
const decl = declared[name] || {}
|
|
65
|
+
const dflt = 'string' === typeof decl.default ? decl.default : ''
|
|
66
|
+
out.push({
|
|
67
|
+
name,
|
|
68
|
+
dflt,
|
|
69
|
+
required: '' === dflt,
|
|
70
|
+
description: 'string' === typeof decl.description ? decl.description : '',
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Declared-but-unreferenced variables: not substitutable, never required.
|
|
75
|
+
for (const name of Object.keys(declared)) {
|
|
76
|
+
if (seen.has(name)) { continue }
|
|
77
|
+
seen.add(name)
|
|
78
|
+
const decl = declared[name] || {}
|
|
79
|
+
out.push({
|
|
80
|
+
name,
|
|
81
|
+
dflt: 'string' === typeof decl.default ? decl.default : '',
|
|
82
|
+
required: false,
|
|
83
|
+
description: 'string' === typeof decl.description ? decl.description : '',
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return out
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
// Does the model's server URL contain any {name} placeholders at all?
|
|
92
|
+
function hasServerVariables(model: any): boolean {
|
|
93
|
+
const info = model?.main?.kit?.info || model?.main?.KIT?.info
|
|
94
|
+
const url: string = info?.servers?.[0]?.url || ''
|
|
95
|
+
SERVER_VAR_RE.lastIndex = 0
|
|
96
|
+
return SERVER_VAR_RE.test(url)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
export {
|
|
101
|
+
serverVariables,
|
|
102
|
+
hasServerVariables,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export type { ServerVar }
|
package/src/sdkgen.ts
CHANGED
|
@@ -52,7 +52,8 @@ import { collectDeps } from './helpers/collectDeps'
|
|
|
52
52
|
import type { DepEntry } from './helpers/collectDeps'
|
|
53
53
|
import { canonToType, canonKey } from './helpers/canonType'
|
|
54
54
|
import { OP_SUFFIX, opTypeName, opParams, opRequestShape, entityIdField, entityDataIdField, entityOps, entityPrimaryOp, pickExampleEntity, entityClassName, entityTypeCollisions, warnEntityTypeCollisions, deriveEntityNames, entityCollection } from './helpers/opShape'
|
|
55
|
-
import { isReservedName, safeVarName, exampleVarName, isRbCoreConstant, rbSafeTypeName, jsProp, jsOptProp, jsKey } from './helpers/naming'
|
|
55
|
+
import { isReservedName, safeVarName, exampleVarName, isRbCoreConstant, rbSafeTypeName, isSwiftSdkType, swiftSafeTypeName, jsProp, jsOptProp, jsKey } from './helpers/naming'
|
|
56
|
+
import { serverVariables, hasServerVariables } from './helpers/serverVars'
|
|
56
57
|
import {
|
|
57
58
|
packageName,
|
|
58
59
|
installCommand,
|
|
@@ -480,6 +481,10 @@ export {
|
|
|
480
481
|
exampleVarName,
|
|
481
482
|
isRbCoreConstant,
|
|
482
483
|
rbSafeTypeName,
|
|
484
|
+
isSwiftSdkType,
|
|
485
|
+
swiftSafeTypeName,
|
|
486
|
+
serverVariables,
|
|
487
|
+
hasServerVariables,
|
|
483
488
|
jsProp,
|
|
484
489
|
jsOptProp,
|
|
485
490
|
jsKey,
|