@voxgig/sdkgen 4.5.3 → 4.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 (248) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/action/check.js +15 -0
  3. package/dist/action/check.js.map +1 -1
  4. package/dist/cmp/AgentGuide.js +1 -1
  5. package/dist/cmp/AgentGuide.js.map +1 -1
  6. package/dist/cmp/AgentGuideContent.d.ts +1 -1
  7. package/dist/cmp/AgentGuideContent.js +8 -2
  8. package/dist/cmp/AgentGuideContent.js.map +1 -1
  9. package/dist/cmp/Feature.js +22 -0
  10. package/dist/cmp/Feature.js.map +1 -1
  11. package/dist/cmp/FeatureDocs.d.ts +1 -1
  12. package/dist/cmp/FeatureDocs.js +6 -1
  13. package/dist/cmp/FeatureDocs.js.map +1 -1
  14. package/dist/cmp/ReadmeExplanation.js +3 -1
  15. package/dist/cmp/ReadmeExplanation.js.map +1 -1
  16. package/dist/cmp/ReadmeFeatures.js +1 -1
  17. package/dist/cmp/ReadmeFeatures.js.map +1 -1
  18. package/dist/cmp/ReadmeRefFeatures.js +1 -1
  19. package/dist/cmp/ReadmeRefFeatures.js.map +1 -1
  20. package/dist/cmp/TestControl.d.ts +4 -0
  21. package/dist/cmp/TestControl.js +51 -0
  22. package/dist/cmp/TestControl.js.map +1 -0
  23. package/dist/helpers/applicability.d.ts +6 -0
  24. package/dist/helpers/applicability.js +103 -0
  25. package/dist/helpers/applicability.js.map +1 -0
  26. package/dist/helpers/collectDeps.js +4 -2
  27. package/dist/helpers/collectDeps.js.map +1 -1
  28. package/dist/helpers/featureSource.d.ts +3 -1
  29. package/dist/helpers/featureSource.js +105 -0
  30. package/dist/helpers/featureSource.js.map +1 -1
  31. package/dist/helpers/serverVars.d.ts +2 -1
  32. package/dist/helpers/serverVars.js +17 -0
  33. package/dist/helpers/serverVars.js.map +1 -1
  34. package/dist/sdkgen.d.ts +5 -3
  35. package/dist/sdkgen.js +16 -4
  36. package/dist/sdkgen.js.map +1 -1
  37. package/dist/tsconfig.tsbuildinfo +1 -1
  38. package/dist/utility.d.ts +2 -1
  39. package/dist/utility.js +59 -1
  40. package/dist/utility.js.map +1 -1
  41. package/model/sdkgen.aon +97 -0
  42. package/package.json +1 -1
  43. package/project/.sdk/model/feature/feature-index.aon +1 -0
  44. package/project/.sdk/model/feature/secrets.aon +200 -0
  45. package/project/.sdk/model/target/ts.aon +8 -1
  46. package/project/.sdk/src/cmp/c/Config_c.ts +5 -1
  47. package/project/.sdk/src/cmp/cpp/Config_cpp.ts +5 -1
  48. package/project/.sdk/src/cmp/cpp/Main_cpp.ts +2 -1
  49. package/project/.sdk/src/cmp/cpp/Test_cpp.ts +5 -1
  50. package/project/.sdk/src/cmp/csharp/Config_csharp.ts +5 -1
  51. package/project/.sdk/src/cmp/csharp/Main_csharp.ts +2 -1
  52. package/project/.sdk/src/cmp/csharp/TestDirect_csharp.ts +30 -6
  53. package/project/.sdk/src/cmp/csharp/TestEntity_csharp.ts +29 -5
  54. package/project/.sdk/src/cmp/csharp/Test_csharp.ts +5 -1
  55. package/project/.sdk/src/cmp/dart/Config_dart.ts +5 -1
  56. package/project/.sdk/src/cmp/dart/Main_dart.ts +2 -1
  57. package/project/.sdk/src/cmp/dart/TestDirect_dart.ts +23 -6
  58. package/project/.sdk/src/cmp/dart/TestEntity_dart.ts +28 -7
  59. package/project/.sdk/src/cmp/dart/Test_dart.ts +5 -1
  60. package/project/.sdk/src/cmp/elixir/Config_elixir.ts +5 -1
  61. package/project/.sdk/src/cmp/elixir/Main_elixir.ts +5 -1
  62. package/project/.sdk/src/cmp/go/Config_go.ts +5 -1
  63. package/project/.sdk/src/cmp/go/Main_go.ts +8 -3
  64. package/project/.sdk/src/cmp/go/ReadmeQuick_go.ts +16 -3
  65. package/project/.sdk/src/cmp/go/ReadmeTopQuick_go.ts +16 -3
  66. package/project/.sdk/src/cmp/go/TestDirect_go.ts +28 -4
  67. package/project/.sdk/src/cmp/go/TestEntity_go.ts +43 -10
  68. package/project/.sdk/src/cmp/go/Test_go.ts +5 -1
  69. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +5 -5
  70. package/project/.sdk/src/cmp/java/Config_java.ts +22 -1
  71. package/project/.sdk/src/cmp/java/Main_java.ts +7 -2
  72. package/project/.sdk/src/cmp/java/ReadmeQuick_java.ts +17 -3
  73. package/project/.sdk/src/cmp/java/ReadmeTopQuick_java.ts +17 -3
  74. package/project/.sdk/src/cmp/java/TestDirect_java.ts +23 -4
  75. package/project/.sdk/src/cmp/java/TestEntity_java.ts +29 -4
  76. package/project/.sdk/src/cmp/java/Test_java.ts +5 -1
  77. package/project/.sdk/src/cmp/js/Config_js.ts +5 -1
  78. package/project/.sdk/src/cmp/js/Main_js.ts +7 -2
  79. package/project/.sdk/src/cmp/js/Package_js.ts +4 -1
  80. package/project/.sdk/src/cmp/js/TestDirect_js.ts +30 -5
  81. package/project/.sdk/src/cmp/js/TestEntity_js.ts +35 -5
  82. package/project/.sdk/src/cmp/js/Test_js.ts +5 -1
  83. package/project/.sdk/src/cmp/js/fragment/Direct.test.fragment.js +7 -1
  84. package/project/.sdk/src/cmp/js/fragment/Entity.test.fragment.js +7 -1
  85. package/project/.sdk/src/cmp/kotlin/Config_kotlin.ts +5 -1
  86. package/project/.sdk/src/cmp/kotlin/Main_kotlin.ts +2 -1
  87. package/project/.sdk/src/cmp/kotlin/Test_kotlin.ts +5 -1
  88. package/project/.sdk/src/cmp/lean/Config_lean.ts +5 -1
  89. package/project/.sdk/src/cmp/lua/Config_lua.ts +5 -1
  90. package/project/.sdk/src/cmp/lua/Main_lua.ts +7 -2
  91. package/project/.sdk/src/cmp/lua/Package_lua.ts +4 -1
  92. package/project/.sdk/src/cmp/lua/TestDirect_lua.ts +28 -4
  93. package/project/.sdk/src/cmp/lua/TestEntity_lua.ts +24 -4
  94. package/project/.sdk/src/cmp/lua/Test_lua.ts +5 -1
  95. package/project/.sdk/src/cmp/ocaml/Config_ocaml.ts +5 -1
  96. package/project/.sdk/src/cmp/ocaml/Gitignore_ocaml.ts +1 -0
  97. package/project/.sdk/src/cmp/perl/Main_perl.ts +7 -2
  98. package/project/.sdk/src/cmp/perl/TestDirect_perl.ts +25 -4
  99. package/project/.sdk/src/cmp/perl/TestEntity_perl.ts +24 -4
  100. package/project/.sdk/src/cmp/perl/Test_perl.ts +5 -1
  101. package/project/.sdk/src/cmp/perl/utility_perl.ts +10 -0
  102. package/project/.sdk/src/cmp/php/Config_php.ts +5 -1
  103. package/project/.sdk/src/cmp/php/Main_php.ts +7 -2
  104. package/project/.sdk/src/cmp/php/TestDirect_php.ts +24 -5
  105. package/project/.sdk/src/cmp/php/TestEntity_php.ts +28 -4
  106. package/project/.sdk/src/cmp/php/Test_php.ts +5 -1
  107. package/project/.sdk/src/cmp/py/Config_py.ts +5 -1
  108. package/project/.sdk/src/cmp/py/Main_py.ts +7 -2
  109. package/project/.sdk/src/cmp/py/ReadmeQuick_py.ts +16 -3
  110. package/project/.sdk/src/cmp/py/ReadmeTopQuick_py.ts +16 -3
  111. package/project/.sdk/src/cmp/py/TestDirect_py.ts +24 -5
  112. package/project/.sdk/src/cmp/py/TestEntity_py.ts +23 -3
  113. package/project/.sdk/src/cmp/py/Test_py.ts +5 -1
  114. package/project/.sdk/src/cmp/rb/Config_rb.ts +5 -1
  115. package/project/.sdk/src/cmp/rb/Main_rb.ts +7 -2
  116. package/project/.sdk/src/cmp/rb/TestDirect_rb.ts +24 -5
  117. package/project/.sdk/src/cmp/rb/TestEntity_rb.ts +24 -4
  118. package/project/.sdk/src/cmp/rb/Test_rb.ts +5 -1
  119. package/project/.sdk/src/cmp/rb/utility_rb.ts +3 -1
  120. package/project/.sdk/src/cmp/rust/Config_rust.ts +5 -1
  121. package/project/.sdk/src/cmp/rust/Main_rust.ts +7 -2
  122. package/project/.sdk/src/cmp/rust/TestDirect_rust.ts +31 -4
  123. package/project/.sdk/src/cmp/rust/TestEntity_rust.ts +37 -4
  124. package/project/.sdk/src/cmp/rust/Test_rust.ts +5 -1
  125. package/project/.sdk/src/cmp/scala/Config_scala.ts +5 -1
  126. package/project/.sdk/src/cmp/scala/Main_scala.ts +7 -2
  127. package/project/.sdk/src/cmp/scala/Test_scala.ts +5 -1
  128. package/project/.sdk/src/cmp/swift/Config_swift.ts +5 -1
  129. package/project/.sdk/src/cmp/ts/Config_ts.ts +55 -9
  130. package/project/.sdk/src/cmp/ts/Main_ts.ts +67 -3
  131. package/project/.sdk/src/cmp/ts/Package_ts.ts +4 -1
  132. package/project/.sdk/src/cmp/ts/ReadmeModel_ts.ts +15 -3
  133. package/project/.sdk/src/cmp/ts/ReadmeQuick_ts.ts +18 -5
  134. package/project/.sdk/src/cmp/ts/ReadmeTopQuick_ts.ts +19 -5
  135. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +75 -8
  136. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +36 -5
  137. package/project/.sdk/src/cmp/ts/Test_ts.ts +5 -1
  138. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +9 -2
  139. package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -2
  140. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +7 -0
  141. package/project/.sdk/src/cmp/zig/Config_zig.ts +5 -1
  142. package/project/.sdk/tm/c/utility/make_options.c +22 -0
  143. package/project/.sdk/tm/clojure/src/sdk/core.clj +18 -1
  144. package/project/.sdk/tm/cpp/utility/pipeline.hpp +23 -0
  145. package/project/.sdk/tm/csharp/test/CustomUtilityTest.cs +15 -0
  146. package/project/.sdk/tm/csharp/test/Runner.cs +45 -0
  147. package/project/.sdk/tm/csharp/utility/MakeOptions.cs +23 -0
  148. package/project/.sdk/tm/dart/lib/utility/MakeOptionsUtility.dart +22 -0
  149. package/project/.sdk/tm/dart/test/utility.dart +39 -0
  150. package/project/.sdk/tm/elixir/lib/projectname/utility.ex +19 -0
  151. package/project/.sdk/tm/go/core/context.go +1 -1
  152. package/project/.sdk/tm/go/feature/cost_feature.go +1 -1
  153. package/project/.sdk/tm/go/feature/paging_feature.go +5 -5
  154. package/project/.sdk/tm/go/feature/test_feature.go +12 -5
  155. package/project/.sdk/tm/go/test/custom_utility_test.go +15 -0
  156. package/project/.sdk/tm/go/test/feature_corpus_test.go +7 -0
  157. package/project/.sdk/tm/go/test/runner_test.go +46 -0
  158. package/project/.sdk/tm/go/test/struct_runner_test.go +7 -7
  159. package/project/.sdk/tm/go/test/struct_utility_test.go +63 -27
  160. package/project/.sdk/tm/go/utility/fetcher.go +2 -2
  161. package/project/.sdk/tm/go/utility/make_options.go +24 -5
  162. package/project/.sdk/tm/go/utility/make_point.go +1 -1
  163. package/project/.sdk/tm/go/utility/make_spec.go +17 -1
  164. package/project/.sdk/tm/go/utility/prepare_auth.go +1 -1
  165. package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +370 -307
  166. package/project/.sdk/tm/go/utility/transform_request.go +29 -1
  167. package/project/.sdk/tm/go/utility/transform_response.go +20 -1
  168. package/project/.sdk/tm/java/test/CustomUtilityTest.java +10 -0
  169. package/project/.sdk/tm/java/test/FeatureCorpusTest.java +7 -0
  170. package/project/.sdk/tm/java/test/PrimaryUtilityTest.java +6 -0
  171. package/project/.sdk/tm/java/test/RunnerSupport.java +43 -0
  172. package/project/.sdk/tm/java/utility/MakeOptions.java +84 -1
  173. package/project/.sdk/tm/js/src/utility/MakeOptionsUtility.js +24 -0
  174. package/project/.sdk/tm/js/src/utility/StructUtility.js +2076 -1837
  175. package/project/.sdk/tm/js/test/feature/Corpus.test.js +9 -0
  176. package/project/.sdk/tm/js/test/sdk-test-control.json +19 -0
  177. package/project/.sdk/tm/js/test/utility.js +91 -1
  178. package/project/.sdk/tm/kotlin/utility/MakeOptions.kt +21 -0
  179. package/project/.sdk/tm/lean/src/SdkUtility.lean +12 -1
  180. package/project/.sdk/tm/lua/test/runner.lua +40 -0
  181. package/project/.sdk/tm/ocaml/sdk_runtime.ml +11 -0
  182. package/project/.sdk/tm/ocaml/test/harness.ml +14 -4
  183. package/project/.sdk/tm/perl/t/runner.pm +30 -0
  184. package/project/.sdk/tm/perl/utility/make_options.pm +18 -0
  185. package/project/.sdk/tm/php/test/FeatureCorpusTest.php +10 -1
  186. package/project/.sdk/tm/php/test/Runner.php +36 -0
  187. package/project/.sdk/tm/php/utility/MakeOptions.php +24 -0
  188. package/project/.sdk/tm/py/pkg/utility/make_options.py +20 -0
  189. package/project/.sdk/tm/py/test/runner.py +32 -0
  190. package/project/.sdk/tm/py/test/test_feature_corpus.py +10 -1
  191. package/project/.sdk/tm/rb/test/feature_corpus_test.rb +9 -1
  192. package/project/.sdk/tm/rb/test/runner.rb +25 -0
  193. package/project/.sdk/tm/rb/utility/make_options.rb +17 -0
  194. package/project/.sdk/tm/rust/tests/common/mod.rs +32 -0
  195. package/project/.sdk/tm/rust/utility/make_options.rs +26 -1
  196. package/project/.sdk/tm/scala/utility/Make.scala +17 -0
  197. package/project/.sdk/tm/swift/Sources/ProjectNameSDK/utility/MakeOptions.swift +21 -0
  198. package/project/.sdk/tm/ts/src/feature/secrets/SecretsFeature.ts +419 -0
  199. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/Sekreto.ts +387 -0
  200. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/Sigv4.ts +175 -0
  201. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/index.ts +51 -0
  202. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/Registry.ts +90 -0
  203. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/addr.ts +48 -0
  204. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/aws.ts +219 -0
  205. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/azuresecrets.ts +144 -0
  206. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/boru.ts +113 -0
  207. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/doppler.ts +77 -0
  208. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/dotenv.ts +51 -0
  209. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/env.ts +31 -0
  210. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/file.ts +54 -0
  211. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/gcpsecrets.ts +118 -0
  212. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/hashicorp.ts +159 -0
  213. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/http.ts +66 -0
  214. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/infisical.ts +107 -0
  215. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/memory.ts +33 -0
  216. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/onepassword.ts +120 -0
  217. package/project/.sdk/tm/ts/src/feature/secrets/sekreto/provider/support.ts +176 -0
  218. package/project/.sdk/tm/ts/src/utility/MakeOptionsUtility.ts +18 -0
  219. package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1321 -710
  220. package/project/.sdk/tm/ts/test/feature/Corpus.test.ts +9 -0
  221. package/project/.sdk/tm/ts/test/feature/secrets/Secrets.test.ts +764 -0
  222. package/project/.sdk/tm/ts/test/omni.test.ts +84 -0
  223. package/project/.sdk/tm/ts/test/omni.ts +86 -0
  224. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +6 -2
  225. package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +2 -2
  226. package/project/.sdk/tm/ts/test/utility.ts +122 -0
  227. package/project/.sdk/tm/ts/test/vendor/omni/Runner.ts +694 -0
  228. package/project/.sdk/tm/ts/test/vendor/omni/Util.ts +244 -0
  229. package/project/.sdk/tm/ts/test/vendor/omni/compat.ts +188 -0
  230. package/project/.sdk/tm/ts/test/vendor/omni/index.ts +38 -0
  231. package/project/.sdk/tm/zig/core/utility.zig +24 -1
  232. package/project/sdkgen-package.json +2 -1
  233. package/src/action/check.ts +18 -0
  234. package/src/cmp/AgentGuide.ts +1 -1
  235. package/src/cmp/AgentGuideContent.ts +9 -2
  236. package/src/cmp/Feature.ts +24 -0
  237. package/src/cmp/FeatureDocs.ts +7 -1
  238. package/src/cmp/ReadmeExplanation.ts +4 -1
  239. package/src/cmp/ReadmeFeatures.ts +1 -1
  240. package/src/cmp/ReadmeRefFeatures.ts +1 -1
  241. package/src/cmp/TestControl.ts +64 -0
  242. package/src/helpers/applicability.ts +123 -0
  243. package/src/helpers/collectDeps.ts +5 -1
  244. package/src/helpers/featureSource.ts +130 -0
  245. package/src/helpers/serverVars.ts +19 -0
  246. package/src/sdkgen.ts +16 -1
  247. package/src/utility.ts +71 -1
  248. package/project/.sdk/tm/ts/test/runner.ts +0 -425
@@ -1,425 +0,0 @@
1
- // VERSION: @voxgig/struct 0.0.10
2
- // This test utility runs the JSON-specified tests in build/test/test.json.
3
- // (or .sdk/test/test.json if used in a @voxgig/sdkgen project)
4
-
5
- import { readFileSync } from 'node:fs'
6
- import { join } from 'node:path'
7
- import { deepStrictEqual, fail, AssertionError } from 'node:assert'
8
-
9
- const NULLMARK = '__NULL__' // Value is JSON null
10
- const UNDEFMARK = '__UNDEF__' // Value is not present (thus, undefined).
11
- const EXISTSMARK = '__EXISTS__' // Value exists (not undefined).
12
-
13
-
14
- type Subject = (...args: any[]) => any
15
- type RunSet = (testspec: any, testsubject: Function) => Promise<any>
16
- type RunSetFlags = (testspec: any, flags: Record<string, boolean>, testsubject: Function)
17
- => Promise<any>
18
-
19
-
20
- type RunPack = {
21
- spec: Record<string, any>
22
- runset: RunSet
23
- runsetflags: RunSetFlags
24
- subject: Subject
25
- client: any
26
- }
27
-
28
-
29
- type TestPack = {
30
- name?: string
31
- client: any
32
- subject: Subject
33
- utility: any
34
- }
35
-
36
- type Flags = Record<string, boolean>
37
-
38
-
39
- type Utility = {
40
- struct: any
41
- makeContext: (ctxmap: Record<string, any>, basectx?: any) => any
42
- }
43
-
44
-
45
- type Client = {
46
- utility: () => Utility
47
- }
48
-
49
-
50
- async function makeRunner(testfile: string, client: Client) {
51
-
52
- return async function runner(
53
- name: string,
54
- store?: any,
55
- ): Promise<RunPack> {
56
- store = store || {}
57
-
58
- const utility = client.utility()
59
- const structUtils = utility.struct
60
-
61
- let spec = resolveSpec(name, testfile)
62
- let clients = await resolveClients(client, spec, store, structUtils)
63
- let subject = resolveSubject(name, utility)
64
-
65
- let runsetflags: RunSetFlags = async (
66
- testspec: any,
67
- flags: Flags,
68
- testsubject: Function
69
- ) => {
70
- subject = testsubject || subject
71
- flags = resolveFlags(flags)
72
- const testspecmap = fixJSON(testspec, flags)
73
-
74
- const testset: any[] = testspecmap.set
75
- for (let entry of testset) {
76
- try {
77
- entry = resolveEntry(entry, flags)
78
-
79
- let testpack = resolveTestPack(name, entry, subject, client, clients)
80
- let args = resolveArgs(entry, testpack, utility, structUtils)
81
-
82
- let res = await testpack.subject(...args)
83
- res = fixJSON(res, flags)
84
- entry.res = res
85
-
86
- checkResult(entry, args, res, structUtils)
87
- }
88
- catch (err: any) {
89
- if (err instanceof AssertionError) {
90
- throw err
91
- }
92
- handleError(entry, err, structUtils)
93
- }
94
- }
95
- }
96
-
97
- let runset: RunSet = async (
98
- testspec: any,
99
- testsubject: Function
100
- ) => runsetflags(testspec, {}, testsubject)
101
-
102
- const runpack: RunPack = {
103
- spec,
104
- runset,
105
- runsetflags,
106
- subject,
107
- client,
108
- }
109
-
110
- return runpack
111
- }
112
- }
113
-
114
- function resolveSpec(name: string, testfile: string): Record<string, any> {
115
- const alltests =
116
- JSON.parse(readFileSync(join(__dirname, testfile), 'utf8'))
117
-
118
- let spec = alltests.primary?.[name] || alltests[name] || alltests
119
- return spec
120
- }
121
-
122
-
123
- async function resolveClients(
124
- client: any,
125
- spec: Record<string, any>,
126
- store: any,
127
- structUtils: Record<string, any>
128
- ):
129
- Promise<Record<string, any>> {
130
-
131
- const clients: Record<string, any> = {}
132
- if (spec.DEF && spec.DEF.client) {
133
- for (let cn in spec.DEF.client) {
134
- const cdef = spec.DEF.client[cn]
135
- const copts = cdef.test.options || {}
136
- if ('object' === typeof store && structUtils?.inject) {
137
- structUtils.inject(copts, store)
138
- }
139
-
140
- clients[cn] = await client.tester(copts)
141
- }
142
- }
143
- return clients
144
- }
145
-
146
-
147
- function resolveSubject(name: string, container: any) {
148
- const subject = container[name] || container.struct[name]
149
- return subject
150
- }
151
-
152
-
153
- function resolveFlags(flags?: Flags): Flags {
154
- if (null == flags) {
155
- flags = {}
156
- }
157
- flags.null = null == flags.null ? true : !!flags.null
158
- return flags
159
- }
160
-
161
-
162
- function resolveEntry(entry: any, flags: Flags): any {
163
- entry.out = null == entry.out && flags.null ? NULLMARK : entry.out
164
- return entry
165
- }
166
-
167
-
168
- function checkResult(entry: any, args: any[], res: any, structUtils: Record<string, any>) {
169
- let matched = false
170
-
171
- if (entry.err) {
172
- return fail('Expected error did not occur: ' + entry.err +
173
- '\n\nENTRY: ' + safeStringify(entry))
174
- }
175
-
176
- if (entry.match) {
177
- const result = { in: entry.in, args, out: entry.res, ctx: entry.ctx }
178
- match(
179
- entry.match,
180
- result,
181
- structUtils
182
- )
183
-
184
- matched = true
185
- }
186
-
187
- const out = entry.out
188
-
189
- if (out === res) {
190
- return
191
- }
192
-
193
- // NOTE: allow match with no out.
194
- if (matched && (NULLMARK === out || null == out)) {
195
- return
196
- }
197
-
198
- deepStrictEqual(null != res ? JSON.parse(safeStringify(res)) : res, entry.out)
199
- }
200
-
201
-
202
- // Handle errors from test execution
203
- function handleError(entry: any, err: any, structUtils: Record<string, any>) {
204
- entry.thrown = err
205
-
206
- const entry_err = entry.err
207
-
208
- if (null != entry_err) {
209
- if (true === entry_err || matchval(entry_err, err.message, structUtils)) {
210
- if (entry.match) {
211
- match(
212
- entry.match,
213
- { in: entry.in, out: entry.res, ctx: entry.ctx, err: fixJSON(err, { null: true }) },
214
- structUtils
215
- )
216
- }
217
- return
218
- }
219
-
220
- fail('ERROR MATCH: [' + structUtils.stringify(entry_err) +
221
- '] <=> [' + err.message + ']')
222
- }
223
-
224
- // Unexpected error (test didn't specify an error expectation)
225
- else if (err instanceof AssertionError) {
226
- fail(err.message + '\n\nENTRY: ' + safeStringify(entry))
227
- }
228
- else {
229
- fail(err.stack + '\n\nENTRY: ' + safeStringify(entry))
230
- }
231
- }
232
-
233
-
234
- function resolveArgs(
235
- entry: any,
236
- testpack: TestPack,
237
- utility: Utility,
238
- structUtils: Record<string, any>
239
- ): any[] {
240
- let args: any[] = []
241
-
242
- if (entry.ctx) {
243
- args = [entry.ctx]
244
- }
245
- else if (entry.args) {
246
- args = entry.args
247
- }
248
- else {
249
- args = [structUtils.clone(entry.in)]
250
- }
251
-
252
- if (entry.ctx || entry.args) {
253
- let first = args[0]
254
- if (structUtils.ismap(first)) {
255
- first = structUtils.clone(first)
256
- first = utility.makeContext(first)
257
- args[0] = first
258
- entry.ctx = first
259
-
260
- first.client = testpack.client
261
- first.utility = testpack.utility
262
- }
263
- }
264
-
265
- return args
266
- }
267
-
268
-
269
- function resolveTestPack(
270
- name: string,
271
- entry: any,
272
- subject: Subject,
273
- client: any,
274
- clients: Record<string, any>
275
- ) {
276
- const testpack: TestPack = {
277
- name,
278
- client,
279
- subject,
280
- utility: client.utility(),
281
- }
282
-
283
- if (entry.client) {
284
- testpack.client = clients[entry.client]
285
- testpack.utility = testpack.client.utility()
286
- testpack.subject = resolveSubject(name, testpack.utility)
287
- }
288
-
289
- return testpack
290
- }
291
-
292
-
293
- function match(
294
- check: any,
295
- basex: any,
296
- structUtils: Record<string, any>
297
- ) {
298
- const cbase = structUtils.clone(basex)
299
-
300
- structUtils.walk(check, (_key: any, val: any, _parent: any, path: any) => {
301
- if (!structUtils.isnode(val)) {
302
- let baseval = structUtils.getpath(cbase, path)
303
-
304
- if (baseval === val) {
305
- return val
306
- }
307
-
308
- // Explicit undefined expected
309
- if (UNDEFMARK === val && undefined === baseval) {
310
- return val
311
- }
312
-
313
- // Explicit defined expected
314
- if (EXISTSMARK === val && null != baseval) {
315
- return val
316
- }
317
-
318
- if (!matchval(val, baseval, structUtils)) {
319
- fail('MATCH: ' + path.join('.') +
320
- ': [' + structUtils.stringify(val) +
321
- '] <=> [' + structUtils.stringify(baseval) + ']')
322
- }
323
- }
324
-
325
- return val
326
- })
327
- }
328
-
329
-
330
- function matchval(
331
- check: any,
332
- base: any,
333
- structUtils: Record<string, any>
334
- ) {
335
- let pass = check === base
336
-
337
- if (!pass) {
338
-
339
- if ('string' === typeof check) {
340
- let basestr = structUtils.stringify(base)
341
-
342
- let rem = check.match(/^\/(.+)\/$/)
343
- if (rem) {
344
- pass = new RegExp(rem[1]).test(basestr)
345
- }
346
- else {
347
- pass = basestr.toLowerCase().includes(structUtils.stringify(check).toLowerCase())
348
- }
349
- }
350
- else if ('function' === typeof check) {
351
- pass = true
352
- }
353
- }
354
-
355
- return pass
356
- }
357
-
358
-
359
- function safeStringify(val: any): string {
360
- const seen = new WeakSet()
361
- return JSON.stringify(val, (_k, v) => {
362
- if ('object' === typeof v && null !== v) {
363
- if (seen.has(v)) return '[Circular]'
364
- seen.add(v)
365
- }
366
- if (v instanceof Error) {
367
- return { name: v.name, message: v.message }
368
- }
369
- return v
370
- }, 2)
371
- }
372
-
373
-
374
- function fixJSON(val: any, flags?: Flags): any {
375
- if (null == val) {
376
- return flags?.null ? NULLMARK : val
377
- }
378
-
379
- const seen = new WeakSet()
380
- const replacer = (_k: string, v: any) => {
381
- if (null == v && flags?.null) {
382
- return NULLMARK
383
- }
384
-
385
- if (v instanceof Error) {
386
- return {
387
- ...v,
388
- name: v.name,
389
- message: v.message,
390
- }
391
- }
392
-
393
- if ('object' === typeof v && null !== v) {
394
- if (seen.has(v)) return '[Circular]'
395
- seen.add(v)
396
- }
397
-
398
- return v
399
- }
400
-
401
- return JSON.parse(JSON.stringify(val, replacer))
402
- }
403
-
404
-
405
- function nullModifier(
406
- val: any,
407
- key: any,
408
- parent: any
409
- ) {
410
- if ("__NULL__" === val) {
411
- parent[key] = null
412
- }
413
- else if ('string' === typeof val) {
414
- parent[key] = val.replaceAll('__NULL__', 'null')
415
- }
416
- }
417
-
418
-
419
- export {
420
- NULLMARK,
421
- EXISTSMARK,
422
- nullModifier,
423
- makeRunner,
424
- }
425
-