@voxgig/sdkgen 1.3.18 → 1.4.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.
- 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 +3 -3
- 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/c/utility/prepare_method.c +18 -0
- package/project/.sdk/tm/clojure/src/sdk/core.clj +9 -1
- package/project/.sdk/tm/cpp/utility/pipeline.hpp +13 -0
- package/project/.sdk/tm/csharp/Makefile +6 -6
- package/project/.sdk/tm/csharp/utility/PrepareMethod.cs +11 -0
- package/project/.sdk/tm/dart/Makefile +3 -3
- package/project/.sdk/tm/dart/lib/utility/PrepareMethodUtility.dart +10 -0
- package/project/.sdk/tm/elixir/lib/projectname/utility.ex +8 -1
- 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/go/utility/prepare_method.go +14 -1
- package/project/.sdk/tm/haskell/src/SdkRuntime.hs +13 -4
- package/project/.sdk/tm/java/Makefile +6 -6
- package/project/.sdk/tm/java/utility/PrepareMethod.java +9 -0
- package/project/.sdk/tm/js/Makefile +6 -6
- package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +39 -1
- package/project/.sdk/tm/js/src/utility/PrepareMethodUtility.js +9 -0
- package/project/.sdk/tm/js/test/utility/PrimaryUtility.test.js +5 -0
- package/project/.sdk/tm/kotlin/Makefile +6 -6
- package/project/.sdk/tm/kotlin/utility/Prepare.kt +9 -0
- package/project/.sdk/tm/lean/src/SdkUtility.lean +6 -1
- 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/lua/utility/prepare_method.lua +11 -0
- package/project/.sdk/tm/ocaml/sdk_runtime.ml +9 -3
- package/project/.sdk/tm/perl/Makefile +6 -6
- package/project/.sdk/tm/perl/utility/prepare_method.pm +17 -0
- 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/php/utility/PrepareMethod.php +11 -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/py/utility/prepare_method.py +10 -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/rb/utility/prepare_method.rb +10 -1
- package/project/.sdk/tm/rust/Makefile +6 -6
- package/project/.sdk/tm/rust/utility/prepare_method.rs +12 -0
- package/project/.sdk/tm/scala/utility/Prepare.scala +14 -8
- package/project/.sdk/tm/swift/Makefile +6 -6
- package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/Prepare.swift +8 -0
- package/project/.sdk/tm/ts/Makefile +6 -6
- package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +39 -1
- package/project/.sdk/tm/ts/src/utility/PrepareMethodUtility.ts +9 -0
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +4 -0
- package/project/.sdk/tm/zig/core/utility.zig +15 -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
|
@@ -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,
|