@voxgig/sdkgen 0.26.1 → 0.30.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 (157) hide show
  1. package/bin/voxgig-sdkgen +1 -1
  2. package/dist/cmp/Feature.js +11 -9
  3. package/dist/cmp/Feature.js.map +1 -1
  4. package/dist/cmp/Main.js +6 -2
  5. package/dist/cmp/Main.js.map +1 -1
  6. package/model/sdkgen.jsonic +1 -1
  7. package/package.json +5 -5
  8. package/project/.sdk/model/feature/log.jsonic +1 -1
  9. package/project/.sdk/model/feature/test.jsonic +1 -1
  10. package/project/.sdk/model/target/go.jsonic +19 -4
  11. package/project/.sdk/model/target/ts.jsonic +3 -3
  12. package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
  13. package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
  14. package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
  15. package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
  16. package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
  17. package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
  18. package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
  19. package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
  20. package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
  21. package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
  22. package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
  23. package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
  24. package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
  25. package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
  26. package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
  27. package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
  28. package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
  29. package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
  30. package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
  31. package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
  32. package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
  33. package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
  34. package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
  35. package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
  36. package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
  37. package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +1 -1
  38. package/project/.sdk/src/cmp/ts/Main_ts.ts +4 -4
  39. package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
  40. package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
  41. package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +14 -6
  42. package/project/.sdk/src/cmp/ts/Test_ts.ts +2 -0
  43. package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
  44. package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +12 -12
  45. package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +12 -12
  46. package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +12 -12
  47. package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +13 -13
  48. package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +12 -12
  49. package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +102 -6
  50. package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
  51. package/project/.sdk/tm/go/Makefile +10 -0
  52. package/project/.sdk/tm/go/core/context.go +267 -0
  53. package/project/.sdk/tm/go/core/control.go +7 -0
  54. package/project/.sdk/tm/go/core/error.go +25 -0
  55. package/project/.sdk/tm/go/core/helpers.go +33 -0
  56. package/project/.sdk/tm/go/core/operation.go +61 -0
  57. package/project/.sdk/tm/go/core/response.go +55 -0
  58. package/project/.sdk/tm/go/core/result.go +73 -0
  59. package/project/.sdk/tm/go/core/spec.go +97 -0
  60. package/project/.sdk/tm/go/core/target.go +102 -0
  61. package/project/.sdk/tm/go/core/types.go +44 -0
  62. package/project/.sdk/tm/go/core/utility_type.go +54 -0
  63. package/project/.sdk/tm/go/feature/base_feature.go +40 -0
  64. package/project/.sdk/tm/go/feature/test_feature.go +196 -0
  65. package/project/.sdk/tm/go/src/feature/README.md +1 -0
  66. package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
  67. package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
  68. package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
  69. package/project/.sdk/tm/go/test/exists_test.go +16 -0
  70. package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
  71. package/project/.sdk/tm/go/test/runner_test.go +428 -0
  72. package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
  73. package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
  74. package/project/.sdk/tm/go/utility/clean.go +7 -0
  75. package/project/.sdk/tm/go/utility/done.go +20 -0
  76. package/project/.sdk/tm/go/utility/feature_add.go +10 -0
  77. package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
  78. package/project/.sdk/tm/go/utility/feature_init.go +30 -0
  79. package/project/.sdk/tm/go/utility/fetcher.go +102 -0
  80. package/project/.sdk/tm/go/utility/make_context.go +7 -0
  81. package/project/.sdk/tm/go/utility/make_error.go +69 -0
  82. package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
  83. package/project/.sdk/tm/go/utility/make_options.go +130 -0
  84. package/project/.sdk/tm/go/utility/make_request.go +59 -0
  85. package/project/.sdk/tm/go/utility/make_response.go +46 -0
  86. package/project/.sdk/tm/go/utility/make_result.go +55 -0
  87. package/project/.sdk/tm/go/utility/make_spec.go +68 -0
  88. package/project/.sdk/tm/go/utility/make_target.go +95 -0
  89. package/project/.sdk/tm/go/utility/make_url.go +41 -0
  90. package/project/.sdk/tm/go/utility/param.go +66 -0
  91. package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
  92. package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
  93. package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
  94. package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
  95. package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
  96. package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
  97. package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
  98. package/project/.sdk/tm/go/utility/register.go +39 -0
  99. package/project/.sdk/tm/go/utility/result_basic.go +31 -0
  100. package/project/.sdk/tm/go/utility/result_body.go +17 -0
  101. package/project/.sdk/tm/go/utility/result_headers.go +22 -0
  102. package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
  103. package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
  104. package/project/.sdk/tm/go/utility/transform_request.go +32 -0
  105. package/project/.sdk/tm/go/utility/transform_response.go +45 -0
  106. package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
  107. package/project/.sdk/tm/ts/src/Context.ts +144 -0
  108. package/project/.sdk/tm/ts/src/Control.ts +20 -0
  109. package/project/.sdk/tm/ts/src/Operation.ts +24 -0
  110. package/project/.sdk/tm/ts/src/Response.ts +26 -0
  111. package/project/.sdk/tm/ts/src/Result.ts +30 -0
  112. package/project/.sdk/tm/ts/src/Spec.ts +40 -0
  113. package/project/.sdk/tm/ts/src/Target.ts +36 -0
  114. package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
  115. package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
  116. package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +7 -7
  117. package/project/.sdk/tm/ts/src/types.ts +15 -205
  118. package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +2 -3
  119. package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
  120. package/project/.sdk/tm/ts/src/utility/{InitfeatureUtility.ts → FeatureInitUtility.ts} +2 -2
  121. package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +5 -3
  122. package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +4 -4
  123. package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
  124. package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +10 -7
  125. package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
  126. package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
  127. package/project/.sdk/tm/ts/src/utility/{ResultUtility.ts → MakeResultUtility.ts} +6 -6
  128. package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
  129. package/project/.sdk/tm/ts/src/utility/{SelectionUtility.ts → MakeTargetUtility.ts} +22 -24
  130. package/project/.sdk/tm/ts/src/utility/{FullurlUtility.ts → MakeUrlUtility.ts} +7 -8
  131. package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +21 -8
  132. package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +4 -4
  133. package/project/.sdk/tm/ts/src/utility/{BodyUtility.ts → PrepareBodyUtility.ts} +7 -7
  134. package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
  135. package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
  136. package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
  137. package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +3 -4
  138. package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
  139. package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +11 -6
  140. package/project/.sdk/tm/ts/src/utility/{ResbodyUtility.ts → ResultBodyUtility.ts} +4 -3
  141. package/project/.sdk/tm/ts/src/utility/{ResheadersUtility.ts → ResultHeadersUtility.ts} +4 -3
  142. package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
  143. package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +10 -7
  144. package/project/.sdk/tm/ts/src/utility/Utility.ts +47 -62
  145. package/project/.sdk/tm/ts/test/runner.ts +25 -4
  146. package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +386 -175
  147. package/src/cmp/Feature.ts +11 -9
  148. package/src/cmp/Main.ts +8 -2
  149. package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
  150. package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +0 -23
  151. package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
  152. package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
  153. package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -83
  154. package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -61
  155. package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -68
  156. /package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +0 -0
  157. /package/project/.sdk/tm/ts/src/utility/{ContextUtility.ts → MakeContextUtility.ts} +0 -0
@@ -0,0 +1,89 @@
1
+
2
+ import {
3
+ Content,
4
+ File,
5
+ cmp,
6
+ each,
7
+ } from '@voxgig/sdkgen'
8
+
9
+
10
+ import {
11
+ KIT,
12
+ Model,
13
+ getModelPath,
14
+ } from '@voxgig/apidef'
15
+
16
+
17
+ const Package = cmp(async function Package(props: any) {
18
+ const ctx$ = props.ctx$
19
+ const target = props.target
20
+
21
+ const model: Model = ctx$.model
22
+
23
+ const feature = getModelPath(model, `main.${KIT}.feature`)
24
+
25
+ // Module name: concatenated lowercase (e.g., voxgigsolardemosdk)
26
+ const orgPrefix = (model.origin || '').replace(/-sdk$/, '').replace(/[^a-z0-9]/gi, '')
27
+ const gomodule = orgPrefix + model.name + 'sdk'
28
+
29
+ File({ name: 'go.mod' }, () => {
30
+ Content(`module ${gomodule}
31
+
32
+ go 1.20
33
+
34
+ `)
35
+
36
+ // Collect dependencies from features
37
+ const deps: Record<string, string> = {}
38
+ const replaceDirs: Record<string, string> = {}
39
+
40
+ each(feature, (f: any) => {
41
+ const goDeps = f.deps?.go
42
+ if (goDeps) {
43
+ each(goDeps, (dep: any) => {
44
+ if (dep.active) {
45
+ deps[dep.key$] = dep.version
46
+ }
47
+ })
48
+ }
49
+ })
50
+
51
+ // Add target-level deps
52
+ const targetDeps = target.deps
53
+ if (targetDeps) {
54
+ each(targetDeps, (dep: any) => {
55
+ if (dep.active !== false) {
56
+ deps[dep.key$] = dep.version || 'v0.0.0'
57
+ if (dep.replace) {
58
+ replaceDirs[dep.key$] = dep.replace
59
+ }
60
+ }
61
+ })
62
+ }
63
+
64
+ if (Object.keys(deps).length > 0) {
65
+ Content(`require (
66
+ `)
67
+ for (const [name, version] of Object.entries(deps)) {
68
+ Content(`\t${name} ${version}
69
+ `)
70
+ }
71
+ Content(`)
72
+ `)
73
+ }
74
+
75
+ if (Object.keys(replaceDirs).length > 0) {
76
+ Content(`
77
+ `)
78
+ for (const [name, dir] of Object.entries(replaceDirs)) {
79
+ Content(`replace ${name} => ${dir}
80
+ `)
81
+ }
82
+ }
83
+ })
84
+ })
85
+
86
+
87
+ export {
88
+ Package
89
+ }
@@ -0,0 +1,373 @@
1
+
2
+ import {
3
+ Content,
4
+ File,
5
+ cmp,
6
+ } from '@voxgig/sdkgen'
7
+
8
+
9
+ const TestDirect = cmp(function TestDirect(props: any) {
10
+ const ctx$ = props.ctx$
11
+ const model = ctx$.model
12
+
13
+ const target = props.target
14
+ const entity = props.entity
15
+ const gomodule = props.gomodule
16
+
17
+ const PROJECTNAME = model.Name.toUpperCase()
18
+
19
+ const opnames = Object.keys(entity.op)
20
+ const hasLoad = opnames.includes('load')
21
+ const hasList = opnames.includes('list')
22
+
23
+ if (!hasLoad && !hasList) {
24
+ return
25
+ }
26
+
27
+ const loadOp = entity.op.load
28
+ const listOp = entity.op.list
29
+
30
+ // Get load target info
31
+ const loadTarget = loadOp?.targets?.[0]
32
+ const loadPath = loadTarget ? (loadTarget.parts || []).join('/') : ''
33
+ const loadParams = loadTarget?.args?.params || []
34
+
35
+ // Get list target info
36
+ const listTarget = listOp?.targets?.[0]
37
+ const listPath = listTarget ? (listTarget.parts || []).join('/') : ''
38
+ const listParams = listTarget?.args?.params || []
39
+
40
+ // Build the ENTID env var name for this entity
41
+ const entidEnvVar = `${PROJECTNAME}_TEST_${entity.Name.toUpperCase()}_ENTID`
42
+
43
+ File({ name: entity.name + '_direct_test.' + target.ext }, () => {
44
+
45
+ Content(`package sdktest
46
+
47
+ import (
48
+ "encoding/json"
49
+ "os"
50
+ "strings"
51
+ "testing"
52
+
53
+ sdk "${gomodule}"
54
+ "${gomodule}/core"
55
+ )
56
+
57
+ func Test${entity.Name}Direct(t *testing.T) {
58
+ `)
59
+
60
+ // Generate list test first (load needs list results in live mode)
61
+ if (hasList && listTarget) {
62
+ const listParamStr = listParams.length > 0
63
+ ? listParams.map((p: any, i: number) =>
64
+ `"${p.name}": "direct0${i + 1}"`).join(', ')
65
+ : ''
66
+
67
+ // Build live params for list
68
+ const listLiveParams = listParams.map((p: any) => {
69
+ const key = p.name === 'id'
70
+ ? entity.name + '01'
71
+ : p.name.replace(/_id$/, '') + '01'
72
+ return { name: p.name, key }
73
+ })
74
+
75
+ Content(` t.Run("direct-list-${entity.name}", func(t *testing.T) {
76
+ setup := ${entity.name}DirectSetup([]any{
77
+ map[string]any{"id": "direct01"},
78
+ map[string]any{"id": "direct02"},
79
+ })
80
+ client := setup.client
81
+
82
+ `)
83
+
84
+ if (listParams.length > 0) {
85
+ Content(` params := map[string]any{}
86
+ `)
87
+ for (const lp of listLiveParams) {
88
+ Content(` if setup.live {
89
+ params["${lp.name}"] = setup.idmap["${lp.key}"]
90
+ } else {
91
+ params["${lp.name}"] = "direct01"
92
+ }
93
+ `)
94
+ }
95
+ Content(`
96
+ result, err := client.Direct(map[string]any{
97
+ "path": "${listPath}",
98
+ "method": "GET",
99
+ "params": params,
100
+ })
101
+ `)
102
+ } else {
103
+ Content(`
104
+ result, err := client.Direct(map[string]any{
105
+ "path": "${listPath}",
106
+ "method": "GET",
107
+ "params": map[string]any{${listParamStr}},
108
+ })
109
+ `)
110
+ }
111
+
112
+ Content(` if err != nil {
113
+ t.Fatalf("direct failed: %v", err)
114
+ }
115
+
116
+ if result["ok"] != true {
117
+ t.Fatalf("expected ok to be true, got %v", result["ok"])
118
+ }
119
+ if core.ToInt(result["status"]) != 200 {
120
+ t.Fatalf("expected status 200, got %v", result["status"])
121
+ }
122
+
123
+ if !setup.live {
124
+ if dataList, ok := result["data"].([]any); ok {
125
+ if len(dataList) != 2 {
126
+ t.Fatalf("expected 2 items, got %d", len(dataList))
127
+ }
128
+ } else {
129
+ t.Fatalf("expected data to be an array, got %T", result["data"])
130
+ }
131
+
132
+ if len(*setup.calls) != 1 {
133
+ t.Fatalf("expected 1 call, got %d", len(*setup.calls))
134
+ }
135
+ `)
136
+
137
+ if (listParams.length > 0) {
138
+ Content(` call := (*setup.calls)[0]
139
+ if initMap, ok := call["init"].(map[string]any); ok {
140
+ if initMap["method"] != "GET" {
141
+ t.Fatalf("expected method GET, got %v", initMap["method"])
142
+ }
143
+ }
144
+ if url, ok := call["url"].(string); ok {
145
+ `)
146
+ for (let i = 0; i < listParams.length; i++) {
147
+ Content(` if !strings.Contains(url, "direct0${i + 1}") {
148
+ t.Fatalf("expected url to contain direct0${i + 1}, got %v", url)
149
+ }
150
+ `)
151
+ }
152
+ Content(` }
153
+ `)
154
+ }
155
+
156
+ Content(` }
157
+ })
158
+
159
+ `)
160
+ }
161
+
162
+ // Generate load test - in live mode, first list to get a real entity ID
163
+ if (hasLoad && loadTarget) {
164
+ const loadParamStr = loadParams.length > 0
165
+ ? loadParams.map((p: any, i: number) =>
166
+ `"${p.name}": "direct0${i + 1}"`).join(', ')
167
+ : ''
168
+
169
+ // Identify ancestor params (not 'id') for live mode
170
+ const ancestorParams = loadParams.filter((p: any) => p.name !== 'id')
171
+
172
+ Content(` t.Run("direct-load-${entity.name}", func(t *testing.T) {
173
+ setup := ${entity.name}DirectSetup(map[string]any{"id": "direct01"})
174
+ client := setup.client
175
+
176
+ `)
177
+
178
+ if (loadParams.length > 0) {
179
+ Content(` params := map[string]any{}
180
+ `)
181
+
182
+ Content(` if setup.live {
183
+ `)
184
+
185
+ // In live mode: first list to get a real entity, then use its ID
186
+ if (hasList) {
187
+ // Build list params from idmap
188
+ Content(` listParams := map[string]any{}
189
+ `)
190
+ for (const p of listParams) {
191
+ const key = p.name === 'id'
192
+ ? entity.name + '01'
193
+ : p.name.replace(/_id$/, '') + '01'
194
+ Content(` listParams["${p.name}"] = setup.idmap["${key}"]
195
+ `)
196
+ }
197
+
198
+ Content(` listResult, listErr := client.Direct(map[string]any{
199
+ "path": "${listPath}",
200
+ "method": "GET",
201
+ "params": listParams,
202
+ })
203
+ if listErr != nil {
204
+ t.Fatalf("list for load setup failed: %v", listErr)
205
+ }
206
+ if listResult["ok"] != true {
207
+ t.Fatalf("list for load setup not ok: %v", listResult)
208
+ }
209
+
210
+ // Get first entity ID from list
211
+ listData, _ := listResult["data"].([]any)
212
+ if len(listData) == 0 {
213
+ t.Skip("no entities to load in live mode")
214
+ }
215
+ firstEnt := core.ToMapAny(listData[0])
216
+ params["id"] = firstEnt["id"]
217
+ `)
218
+ // Set ancestor params from idmap
219
+ for (const p of ancestorParams) {
220
+ const key = p.name.replace(/_id$/, '') + '01'
221
+ Content(` params["${p.name}"] = setup.idmap["${key}"]
222
+ `)
223
+ }
224
+ }
225
+
226
+ Content(` } else {
227
+ `)
228
+ for (let i = 0; i < loadParams.length; i++) {
229
+ Content(` params["${loadParams[i].name}"] = "direct0${i + 1}"
230
+ `)
231
+ }
232
+ Content(` }
233
+ `)
234
+ }
235
+
236
+ Content(`
237
+ result, err := client.Direct(map[string]any{
238
+ "path": "${loadPath}",
239
+ "method": "GET",
240
+ `)
241
+ if (loadParams.length > 0) {
242
+ Content(` "params": params,
243
+ `)
244
+ } else {
245
+ Content(` "params": map[string]any{},
246
+ `)
247
+ }
248
+ Content(` })
249
+ if err != nil {
250
+ t.Fatalf("direct failed: %v", err)
251
+ }
252
+
253
+ if result["ok"] != true {
254
+ t.Fatalf("expected ok to be true, got %v", result["ok"])
255
+ }
256
+ if core.ToInt(result["status"]) != 200 {
257
+ t.Fatalf("expected status 200, got %v", result["status"])
258
+ }
259
+ if result["data"] == nil {
260
+ t.Fatal("expected data to be non-nil")
261
+ }
262
+
263
+ if !setup.live {
264
+ if dataMap, ok := result["data"].(map[string]any); ok {
265
+ if dataMap["id"] != "direct01" {
266
+ t.Fatalf("expected data.id to be direct01, got %v", dataMap["id"])
267
+ }
268
+ }
269
+
270
+ if len(*setup.calls) != 1 {
271
+ t.Fatalf("expected 1 call, got %d", len(*setup.calls))
272
+ }
273
+ call := (*setup.calls)[0]
274
+ if initMap, ok := call["init"].(map[string]any); ok {
275
+ if initMap["method"] != "GET" {
276
+ t.Fatalf("expected method GET, got %v", initMap["method"])
277
+ }
278
+ }
279
+ if url, ok := call["url"].(string); ok {
280
+ `)
281
+
282
+ for (let i = 0; i < loadParams.length; i++) {
283
+ Content(` if !strings.Contains(url, "direct0${i + 1}") {
284
+ t.Fatalf("expected url to contain direct0${i + 1}, got %v", url)
285
+ }
286
+ `)
287
+ }
288
+
289
+ Content(` }
290
+ }
291
+ })
292
+
293
+ `)
294
+ }
295
+
296
+ Content(`}
297
+
298
+ type ${entity.name}DirectSetupResult struct {
299
+ client *sdk.${model.const.Name}SDK
300
+ calls *[]map[string]any
301
+ live bool
302
+ idmap map[string]any
303
+ }
304
+
305
+ func ${entity.name}DirectSetup(mockres any) *${entity.name}DirectSetupResult {
306
+ loadEnvLocal()
307
+
308
+ calls := &[]map[string]any{}
309
+
310
+ env := envOverride(map[string]any{
311
+ "${entidEnvVar}": map[string]any{},
312
+ "${PROJECTNAME}_TEST_LIVE": "FALSE",
313
+ "${PROJECTNAME}_APIKEY": "NONE",
314
+ })
315
+
316
+ live := env["${PROJECTNAME}_TEST_LIVE"] == "TRUE"
317
+
318
+ if live {
319
+ mergedOpts := map[string]any{
320
+ "apikey": env["${PROJECTNAME}_APIKEY"],
321
+ }
322
+ client := sdk.New${model.const.Name}SDK(mergedOpts)
323
+
324
+ idmap := map[string]any{}
325
+ if entidRaw, ok := env["${entidEnvVar}"]; ok {
326
+ if entidStr, ok := entidRaw.(string); ok && strings.HasPrefix(entidStr, "{") {
327
+ json.Unmarshal([]byte(entidStr), &idmap)
328
+ } else if entidMap, ok := entidRaw.(map[string]any); ok {
329
+ idmap = entidMap
330
+ }
331
+ }
332
+
333
+ return &${entity.name}DirectSetupResult{client: client, calls: calls, live: true, idmap: idmap}
334
+ }
335
+
336
+ mockFetch := func(url string, init map[string]any) (map[string]any, error) {
337
+ *calls = append(*calls, map[string]any{"url": url, "init": init})
338
+ return map[string]any{
339
+ "status": 200,
340
+ "statusText": "OK",
341
+ "headers": map[string]any{},
342
+ "json": (func() any)(func() any {
343
+ if mockres != nil {
344
+ return mockres
345
+ }
346
+ return map[string]any{"id": "direct01"}
347
+ }),
348
+ }, nil
349
+ }
350
+
351
+ client := sdk.New${model.const.Name}SDK(map[string]any{
352
+ "base": "http://localhost:8080",
353
+ "system": map[string]any{
354
+ "fetch": (func(string, map[string]any) (map[string]any, error))(mockFetch),
355
+ },
356
+ })
357
+
358
+ return &${entity.name}DirectSetupResult{client: client, calls: calls, live: false, idmap: map[string]any{}}
359
+ }
360
+ `)
361
+
362
+ // Suppress unused import warnings
363
+ Content(`
364
+ var _ = os.Getenv
365
+ var _ = json.Unmarshal
366
+ `)
367
+ })
368
+ })
369
+
370
+
371
+ export {
372
+ TestDirect
373
+ }