@voxgig/sdkgen 0.26.1 → 0.28.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/bin/voxgig-sdkgen +1 -1
- package/dist/cmp/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/model/sdkgen.jsonic +1 -1
- package/package.json +3 -3
- package/project/.sdk/model/feature/log.jsonic +1 -1
- package/project/.sdk/model/feature/test.jsonic +1 -1
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/ts.jsonic +3 -3
- package/project/.sdk/src/cmp/go/Config_go.ts +119 -0
- package/project/.sdk/src/cmp/go/EntityOperation_go.ts +48 -0
- package/project/.sdk/src/cmp/go/Entity_go.ts +67 -0
- package/project/.sdk/src/cmp/go/MainEntity_go.ts +22 -0
- package/project/.sdk/src/cmp/go/Main_go.ts +209 -0
- package/project/.sdk/src/cmp/go/Package_go.ts +89 -0
- package/project/.sdk/src/cmp/go/TestDirect_go.ts +373 -0
- package/project/.sdk/src/cmp/go/TestEntity_go.ts +341 -0
- package/project/.sdk/src/cmp/go/Test_go.ts +37 -0
- package/project/.sdk/src/cmp/go/fragment/Entity.fragment.go +146 -0
- package/project/.sdk/src/cmp/go/fragment/EntityCreateOp.fragment.go +35 -0
- package/project/.sdk/src/cmp/go/fragment/EntityListOp.fragment.go +26 -0
- package/project/.sdk/src/cmp/go/fragment/EntityLoadOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityRemoveOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/EntityUpdateOp.fragment.go +38 -0
- package/project/.sdk/src/cmp/go/fragment/Main.fragment.go +250 -0
- package/project/.sdk/src/cmp/go/fragment/SdkError.fragment.go +22 -0
- package/project/.sdk/src/cmp/go/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/go/utility_go.ts +88 -0
- package/project/.sdk/src/cmp/js/fragment/EntityCreateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityListOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityLoadOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityRemoveOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/EntityUpdateOp.fragment.js +6 -6
- package/project/.sdk/src/cmp/js/fragment/Main.fragment.js +85 -1
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +1 -1
- package/project/.sdk/src/cmp/ts/Main_ts.ts +4 -4
- package/project/.sdk/src/cmp/ts/SdkError_ts.ts +42 -0
- package/project/.sdk/src/cmp/ts/TestDirect_ts.ts +288 -0
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +14 -6
- package/project/.sdk/src/cmp/ts/Test_ts.ts +2 -0
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +13 -13
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +12 -12
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +102 -6
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/tm/go/Makefile +10 -0
- package/project/.sdk/tm/go/core/context.go +267 -0
- package/project/.sdk/tm/go/core/control.go +7 -0
- package/project/.sdk/tm/go/core/error.go +25 -0
- package/project/.sdk/tm/go/core/helpers.go +33 -0
- package/project/.sdk/tm/go/core/operation.go +61 -0
- package/project/.sdk/tm/go/core/response.go +55 -0
- package/project/.sdk/tm/go/core/result.go +73 -0
- package/project/.sdk/tm/go/core/spec.go +97 -0
- package/project/.sdk/tm/go/core/target.go +102 -0
- package/project/.sdk/tm/go/core/types.go +44 -0
- package/project/.sdk/tm/go/core/utility_type.go +54 -0
- package/project/.sdk/tm/go/feature/base_feature.go +40 -0
- package/project/.sdk/tm/go/feature/test_feature.go +196 -0
- package/project/.sdk/tm/go/src/feature/README.md +1 -0
- package/project/.sdk/tm/go/src/feature/base/.gitkeep +0 -0
- package/project/.sdk/tm/go/src/feature/test/.gitkeep +0 -0
- package/project/.sdk/tm/go/test/custom_utility_test.go +80 -0
- package/project/.sdk/tm/go/test/exists_test.go +16 -0
- package/project/.sdk/tm/go/test/primary_utility_test.go +899 -0
- package/project/.sdk/tm/go/test/runner_test.go +428 -0
- package/project/.sdk/tm/go/test/struct_runner_test.go +1094 -0
- package/project/.sdk/tm/go/test/struct_utility_test.go +1423 -0
- package/project/.sdk/tm/go/utility/clean.go +7 -0
- package/project/.sdk/tm/go/utility/done.go +20 -0
- package/project/.sdk/tm/go/utility/feature_add.go +10 -0
- package/project/.sdk/tm/go/utility/feature_hook.go +30 -0
- package/project/.sdk/tm/go/utility/feature_init.go +30 -0
- package/project/.sdk/tm/go/utility/fetcher.go +102 -0
- package/project/.sdk/tm/go/utility/make_context.go +7 -0
- package/project/.sdk/tm/go/utility/make_error.go +69 -0
- package/project/.sdk/tm/go/utility/make_fetch_def.go +44 -0
- package/project/.sdk/tm/go/utility/make_options.go +130 -0
- package/project/.sdk/tm/go/utility/make_request.go +59 -0
- package/project/.sdk/tm/go/utility/make_response.go +46 -0
- package/project/.sdk/tm/go/utility/make_result.go +55 -0
- package/project/.sdk/tm/go/utility/make_spec.go +68 -0
- package/project/.sdk/tm/go/utility/make_target.go +95 -0
- package/project/.sdk/tm/go/utility/make_url.go +41 -0
- package/project/.sdk/tm/go/utility/param.go +66 -0
- package/project/.sdk/tm/go/utility/prepare_auth.go +40 -0
- package/project/.sdk/tm/go/utility/prepare_body.go +14 -0
- package/project/.sdk/tm/go/utility/prepare_headers.go +22 -0
- package/project/.sdk/tm/go/utility/prepare_method.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_params.go +41 -0
- package/project/.sdk/tm/go/utility/prepare_path.go +21 -0
- package/project/.sdk/tm/go/utility/prepare_query.go +47 -0
- package/project/.sdk/tm/go/utility/register.go +39 -0
- package/project/.sdk/tm/go/utility/result_basic.go +31 -0
- package/project/.sdk/tm/go/utility/result_body.go +17 -0
- package/project/.sdk/tm/go/utility/result_headers.go +22 -0
- package/project/.sdk/tm/go/utility/struct/go.mod +3 -0
- package/project/.sdk/tm/go/utility/struct/voxgigstruct.go +4891 -0
- package/project/.sdk/tm/go/utility/transform_request.go +32 -0
- package/project/.sdk/tm/go/utility/transform_response.go +45 -0
- package/project/.sdk/tm/js/src/feature/log/LogFeature.js +2 -2
- package/project/.sdk/tm/ts/src/Context.ts +144 -0
- package/project/.sdk/tm/ts/src/Control.ts +20 -0
- package/project/.sdk/tm/ts/src/Operation.ts +24 -0
- package/project/.sdk/tm/ts/src/Response.ts +26 -0
- package/project/.sdk/tm/ts/src/Result.ts +30 -0
- package/project/.sdk/tm/ts/src/Spec.ts +40 -0
- package/project/.sdk/tm/ts/src/Target.ts +36 -0
- package/project/.sdk/tm/ts/src/feature/base/BaseFeature.ts +1 -1
- package/project/.sdk/tm/ts/src/feature/log/LogFeature.ts +2 -2
- package/project/.sdk/tm/ts/src/feature/test/TestFeature.ts +7 -7
- package/project/.sdk/tm/ts/src/types.ts +15 -205
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +2 -3
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{InitfeatureUtility.ts → FeatureInitUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +5 -3
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +4 -4
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +10 -7
- package/project/.sdk/tm/ts/src/utility/MakeRequestUtility.ts +66 -0
- package/project/.sdk/tm/ts/src/utility/MakeResponseUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{ResultUtility.ts → MakeResultUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{SelectionUtility.ts → MakeTargetUtility.ts} +22 -24
- package/project/.sdk/tm/ts/src/utility/{FullurlUtility.ts → MakeUrlUtility.ts} +7 -8
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +21 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +4 -4
- package/project/.sdk/tm/ts/src/utility/{BodyUtility.ts → PrepareBodyUtility.ts} +7 -7
- package/project/.sdk/tm/ts/src/utility/{HeadersUtility.ts → PrepareHeadersUtility.ts} +5 -7
- package/project/.sdk/tm/ts/src/utility/{MethodUtility.ts → PrepareMethodUtility.ts} +6 -6
- package/project/.sdk/tm/ts/src/utility/PrepareParamsUtility.ts +37 -0
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +11 -6
- package/project/.sdk/tm/ts/src/utility/{ResbodyUtility.ts → ResultBodyUtility.ts} +4 -3
- package/project/.sdk/tm/ts/src/utility/{ResheadersUtility.ts → ResultHeadersUtility.ts} +4 -3
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +10 -7
- package/project/.sdk/tm/ts/src/utility/Utility.ts +47 -62
- package/project/.sdk/tm/ts/test/runner.ts +25 -4
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +386 -175
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/Main.ts +8 -2
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +0 -37
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +0 -27
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +0 -83
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -61
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -68
- /package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +0 -0
- /package/project/.sdk/tm/ts/src/utility/{ContextUtility.ts → MakeContextUtility.ts} +0 -0
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { Package } from './Package_ts'
|
|
22
22
|
import { Config } from './Config_ts'
|
|
23
23
|
import { MainEntity } from './MainEntity_ts'
|
|
24
|
-
|
|
24
|
+
import { SdkError } from './SdkError_ts'
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
const Main = cmp(async function Main(props: any) {
|
|
@@ -35,10 +35,10 @@ const Main = cmp(async function Main(props: any) {
|
|
|
35
35
|
|
|
36
36
|
Package({ target })
|
|
37
37
|
|
|
38
|
-
// Test({ target })
|
|
39
|
-
|
|
40
38
|
Folder({ name: 'src' }, () => {
|
|
41
39
|
|
|
40
|
+
SdkError({ target })
|
|
41
|
+
|
|
42
42
|
File({ name: model.const.Name + 'SDK.' + target.name }, () => {
|
|
43
43
|
|
|
44
44
|
Line(`// ${model.const.Name} ${target.Name} SDK\n`)
|
|
@@ -55,7 +55,7 @@ const Main = cmp(async function Main(props: any) {
|
|
|
55
55
|
'#BuildFeatures': ({ indent }: any) => {
|
|
56
56
|
List({ item: feature, line: false }, ({ item }: any) =>
|
|
57
57
|
Line({ indent },
|
|
58
|
-
`
|
|
58
|
+
`featureAdd(this._rootctx, new ${item.Name}Feature())`))
|
|
59
59
|
},
|
|
60
60
|
|
|
61
61
|
'#Feature-Hook': ({ name, indent }: any) => Content({ indent }, `
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
File,
|
|
7
|
+
Fragment,
|
|
8
|
+
cmp,
|
|
9
|
+
} from '@voxgig/sdkgen'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
Model,
|
|
14
|
+
} from '@voxgig/apidef'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
const SdkError = cmp(async function SdkError(props: any) {
|
|
20
|
+
const ctx$ = props.ctx$
|
|
21
|
+
const target = props.target
|
|
22
|
+
|
|
23
|
+
const model: Model = ctx$.model
|
|
24
|
+
|
|
25
|
+
const ff = Path.normalize(__dirname + '/../../../src/cmp/ts/fragment/')
|
|
26
|
+
|
|
27
|
+
File({ name: model.const.Name + 'Error.' + target.ext }, () => {
|
|
28
|
+
|
|
29
|
+
Fragment({
|
|
30
|
+
from: ff + 'SdkError.fragment.ts',
|
|
31
|
+
|
|
32
|
+
replace: {
|
|
33
|
+
...ctx$.stdrep,
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
SdkError
|
|
42
|
+
}
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
nom,
|
|
4
|
+
} from '@voxgig/apidef'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
Content,
|
|
9
|
+
File,
|
|
10
|
+
Folder,
|
|
11
|
+
Fragment,
|
|
12
|
+
Slot,
|
|
13
|
+
cmp,
|
|
14
|
+
} from '@voxgig/sdkgen'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
import {
|
|
18
|
+
projectPath
|
|
19
|
+
} from './utility_ts'
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
const TestDirect = cmp(function TestDirect(props: any) {
|
|
23
|
+
const ctx$ = props.ctx$
|
|
24
|
+
const model = ctx$.model
|
|
25
|
+
const stdrep = ctx$.stdrep
|
|
26
|
+
|
|
27
|
+
const target = props.target
|
|
28
|
+
const entity = props.entity
|
|
29
|
+
|
|
30
|
+
const ff = projectPath('src/cmp/ts/fragment/')
|
|
31
|
+
|
|
32
|
+
const PROJECTNAME = model.Name.toUpperCase()
|
|
33
|
+
const entidEnvVar = `${PROJECTNAME}_TEST_${entity.Name.toUpperCase()}_ENTID`
|
|
34
|
+
|
|
35
|
+
const opnames = Object.keys(entity.op)
|
|
36
|
+
const hasLoad = opnames.includes('load')
|
|
37
|
+
const hasList = opnames.includes('list')
|
|
38
|
+
|
|
39
|
+
if (!hasLoad && !hasList) {
|
|
40
|
+
return
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
Folder({ name: entity.name }, () => {
|
|
44
|
+
|
|
45
|
+
File({ name: nom(entity, 'Name') + 'Direct.test.' + target.name }, () => {
|
|
46
|
+
|
|
47
|
+
Fragment({
|
|
48
|
+
from: ff + 'Direct.test.fragment.ts',
|
|
49
|
+
replace: {
|
|
50
|
+
SdkName: nom(model.const, 'Name'),
|
|
51
|
+
EntityName: nom(entity, 'Name'),
|
|
52
|
+
entityname: entity.name,
|
|
53
|
+
...stdrep,
|
|
54
|
+
}
|
|
55
|
+
}, () => {
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Slot({ name: 'directSetup' }, () => {
|
|
59
|
+
Content(`
|
|
60
|
+
function directSetup(mockres?: any) {
|
|
61
|
+
const calls: any[] = []
|
|
62
|
+
|
|
63
|
+
const env = envOverride({
|
|
64
|
+
'${entidEnvVar}': {},
|
|
65
|
+
'${PROJECTNAME}_TEST_LIVE': 'FALSE',
|
|
66
|
+
'${PROJECTNAME}_APIKEY': 'NONE',
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
const live = 'TRUE' === env.${PROJECTNAME}_TEST_LIVE
|
|
70
|
+
|
|
71
|
+
if (live) {
|
|
72
|
+
const client = new ${nom(model.const, 'Name')}SDK({
|
|
73
|
+
apikey: env.${PROJECTNAME}_APIKEY,
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
let idmap: any = env['${entidEnvVar}']
|
|
77
|
+
if ('string' === typeof idmap && idmap.startsWith('{')) {
|
|
78
|
+
idmap = JSON.parse(idmap)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return { client, calls, live, idmap }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const mockFetch = async (url: string, init: any) => {
|
|
85
|
+
calls.push({ url, init })
|
|
86
|
+
return {
|
|
87
|
+
status: 200,
|
|
88
|
+
statusText: 'OK',
|
|
89
|
+
headers: {},
|
|
90
|
+
json: async () => (null != mockres ? mockres : { id: 'direct01' }),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const client = new ${nom(model.const, 'Name')}SDK({
|
|
95
|
+
base: 'http://localhost:8080',
|
|
96
|
+
system: { fetch: mockFetch },
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
return { client, calls, live, idmap: {} as any }
|
|
100
|
+
}
|
|
101
|
+
`)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
Slot({ name: 'direct' }, () => {
|
|
106
|
+
|
|
107
|
+
if (hasLoad) {
|
|
108
|
+
generateDirectLoad(model, entity)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (hasList) {
|
|
112
|
+
generateDirectList(model, entity)
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
function generateDirectLoad(model: any, entity: any) {
|
|
123
|
+
const loadOp = entity.op.load
|
|
124
|
+
const loadTarget = loadOp.targets[0]
|
|
125
|
+
|
|
126
|
+
if (null == loadTarget) {
|
|
127
|
+
return
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const loadPath = (loadTarget.parts || []).join('/')
|
|
131
|
+
const loadParams = loadTarget.args?.params || []
|
|
132
|
+
|
|
133
|
+
// Get list info for live mode bootstrapping
|
|
134
|
+
const listOp = entity.op.list
|
|
135
|
+
const listTarget = listOp?.targets?.[0]
|
|
136
|
+
const listPath = listTarget ? (listTarget.parts || []).join('/') : ''
|
|
137
|
+
const listParams = listTarget?.args?.params || []
|
|
138
|
+
const hasList = null != listTarget
|
|
139
|
+
|
|
140
|
+
// Ancestor params (not 'id') for live mode
|
|
141
|
+
const ancestorParams = loadParams.filter((p: any) => p.name !== 'id')
|
|
142
|
+
|
|
143
|
+
const paramAsserts = loadParams.map((p: any, i: number) =>
|
|
144
|
+
' assert(calls[0].url.includes(\'direct0' + (i + 1) + '\'))\n').join('')
|
|
145
|
+
|
|
146
|
+
// Build live list params
|
|
147
|
+
const liveListParams = listParams.map((p: any) => {
|
|
148
|
+
const key = p.name === 'id'
|
|
149
|
+
? entity.name + '01'
|
|
150
|
+
: p.name.replace(/_id$/, '') + '01'
|
|
151
|
+
return { name: p.name, key }
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
// Build live ancestor params for load
|
|
155
|
+
const liveAncestorParams = ancestorParams.map((p: any) => {
|
|
156
|
+
const key = p.name.replace(/_id$/, '') + '01'
|
|
157
|
+
return { name: p.name, key }
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
let liveParamsBlock = ''
|
|
161
|
+
if (hasList) {
|
|
162
|
+
const listParamLines = liveListParams.map((lp: any) =>
|
|
163
|
+
` ${lp.name}: setup.idmap['${lp.key}'],`).join('\n')
|
|
164
|
+
const ancestorParamLines = liveAncestorParams.map((lp: any) =>
|
|
165
|
+
` params.${lp.name} = setup.idmap['${lp.key}']`).join('\n')
|
|
166
|
+
|
|
167
|
+
liveParamsBlock = ` if (setup.live) {
|
|
168
|
+
const listResult: any = await client.direct({
|
|
169
|
+
path: '${listPath}',
|
|
170
|
+
method: 'GET',
|
|
171
|
+
params: {
|
|
172
|
+
${listParamLines}
|
|
173
|
+
},
|
|
174
|
+
})
|
|
175
|
+
assert(listResult.ok === true)
|
|
176
|
+
const listData = listResult.data
|
|
177
|
+
if (!Array.isArray(listData) || listData.length === 0) {
|
|
178
|
+
return // skip: no entities to load in live mode
|
|
179
|
+
}
|
|
180
|
+
params.id = listData[0].id
|
|
181
|
+
${ancestorParamLines}
|
|
182
|
+
} else {
|
|
183
|
+
${loadParams.map((p: any, i: number) => ` params.${p.name} = 'direct0${i + 1}'`).join('\n')}
|
|
184
|
+
}`
|
|
185
|
+
} else {
|
|
186
|
+
liveParamsBlock = ` if (!setup.live) {
|
|
187
|
+
${loadParams.map((p: any, i: number) => ` params.${p.name} = 'direct0${i + 1}'`).join('\n')}
|
|
188
|
+
}`
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
Content(`
|
|
192
|
+
test('direct-load-${entity.name}', async () => {
|
|
193
|
+
const setup = directSetup({ id: 'direct01' })
|
|
194
|
+
const { client, calls } = setup
|
|
195
|
+
|
|
196
|
+
const params: any = {}
|
|
197
|
+
${liveParamsBlock}
|
|
198
|
+
|
|
199
|
+
const result: any = await client.direct({
|
|
200
|
+
path: '${loadPath}',
|
|
201
|
+
method: 'GET',
|
|
202
|
+
params,
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
assert(result.ok === true)
|
|
206
|
+
assert(result.status === 200)
|
|
207
|
+
assert(null != result.data)
|
|
208
|
+
|
|
209
|
+
if (!setup.live) {
|
|
210
|
+
assert(result.data.id === 'direct01')
|
|
211
|
+
assert(calls.length === 1)
|
|
212
|
+
assert(calls[0].init.method === 'GET')
|
|
213
|
+
${paramAsserts} }
|
|
214
|
+
})
|
|
215
|
+
`)
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
function generateDirectList(model: any, entity: any) {
|
|
220
|
+
const listOp = entity.op.list
|
|
221
|
+
const listTarget = listOp.targets[0]
|
|
222
|
+
|
|
223
|
+
if (null == listTarget) {
|
|
224
|
+
return
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
const listPath = (listTarget.parts || []).join('/')
|
|
228
|
+
const listParams = listTarget.args?.params || []
|
|
229
|
+
|
|
230
|
+
// Build live params
|
|
231
|
+
const liveParams = listParams.map((p: any) => {
|
|
232
|
+
const key = p.name === 'id'
|
|
233
|
+
? entity.name + '01'
|
|
234
|
+
: p.name.replace(/_id$/, '') + '01'
|
|
235
|
+
return { name: p.name, key }
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
const paramAsserts = listParams.map((p: any, i: number) =>
|
|
239
|
+
' assert(calls[0].url.includes(\'direct0' + (i + 1) + '\'))\n').join('')
|
|
240
|
+
|
|
241
|
+
let paramsBlock = ''
|
|
242
|
+
if (listParams.length > 0) {
|
|
243
|
+
const liveLines = liveParams.map((lp: any) =>
|
|
244
|
+
` params.${lp.name} = setup.idmap['${lp.key}']`).join('\n')
|
|
245
|
+
const mockLines = listParams.map((p: any, i: number) =>
|
|
246
|
+
` params.${p.name} = 'direct0${i + 1}'`).join('\n')
|
|
247
|
+
|
|
248
|
+
paramsBlock = ` const params: any = {}
|
|
249
|
+
if (setup.live) {
|
|
250
|
+
${liveLines}
|
|
251
|
+
} else {
|
|
252
|
+
${mockLines}
|
|
253
|
+
}
|
|
254
|
+
`
|
|
255
|
+
} else {
|
|
256
|
+
paramsBlock = ` const params: any = {}
|
|
257
|
+
`
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
Content(`
|
|
261
|
+
test('direct-list-${entity.name}', async () => {
|
|
262
|
+
const setup = directSetup([{ id: 'direct01' }, { id: 'direct02' }])
|
|
263
|
+
const { client, calls } = setup
|
|
264
|
+
|
|
265
|
+
${paramsBlock}
|
|
266
|
+
const result: any = await client.direct({
|
|
267
|
+
path: '${listPath}',
|
|
268
|
+
method: 'GET',
|
|
269
|
+
params,
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
assert(result.ok === true)
|
|
273
|
+
assert(result.status === 200)
|
|
274
|
+
assert(Array.isArray(result.data))
|
|
275
|
+
|
|
276
|
+
if (!setup.live) {
|
|
277
|
+
assert(result.data.length === 2)
|
|
278
|
+
assert(calls.length === 1)
|
|
279
|
+
assert(calls[0].init.method === 'GET')
|
|
280
|
+
${paramAsserts} }
|
|
281
|
+
})
|
|
282
|
+
`)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
export {
|
|
287
|
+
TestDirect
|
|
288
|
+
}
|
|
@@ -189,10 +189,18 @@ const generateCreate: OpGen = (
|
|
|
189
189
|
Content(`
|
|
190
190
|
// CREATE
|
|
191
191
|
const ${entvar} = client.${nom(entity, 'Name')}()
|
|
192
|
-
|
|
193
|
-
|
|
192
|
+
let ${datavar} = setup.data.new.${entity.name}['${ref}']
|
|
193
|
+
`)
|
|
194
|
+
|
|
195
|
+
each(step.match, (mi: any) => {
|
|
196
|
+
Content(` ${datavar}['${mi.key$}'] = setup.idmap['${mi.val$}']
|
|
197
|
+
`)
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
Content(`
|
|
201
|
+
${datavar} = await ${entvar}.create(${datavar})
|
|
194
202
|
assert(null != ${datavar}.id)
|
|
195
|
-
|
|
203
|
+
`)
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
|
|
@@ -211,11 +219,11 @@ const generateList: OpGen = (
|
|
|
211
219
|
Content(`
|
|
212
220
|
// LIST
|
|
213
221
|
const ${matchvar}: any = {}
|
|
214
|
-
|
|
222
|
+
`)
|
|
215
223
|
|
|
216
224
|
each(step.match, (mi: any) => {
|
|
217
|
-
Content(` ${matchvar}['${mi.key$}'] = setup.idmap['${mi.
|
|
218
|
-
|
|
225
|
+
Content(` ${matchvar}['${mi.key$}'] = setup.idmap['${mi.val$}']
|
|
226
|
+
`)
|
|
219
227
|
})
|
|
220
228
|
|
|
221
229
|
Content(`
|
|
@@ -13,6 +13,7 @@ import { cmp, each, Folder } from '@voxgig/sdkgen'
|
|
|
13
13
|
|
|
14
14
|
// import { Quick } from './Quick_ts'
|
|
15
15
|
// import { TestMain } from './TestMain_ts'
|
|
16
|
+
import { TestDirect } from './TestDirect_ts'
|
|
16
17
|
import { TestEntity } from './TestEntity_ts'
|
|
17
18
|
|
|
18
19
|
|
|
@@ -27,6 +28,7 @@ const Test = cmp(function Test(props: any) {
|
|
|
27
28
|
Folder({ name: 'entity' }, () => {
|
|
28
29
|
each(model.main[KIT].entity, (entity: ModelEntity) => {
|
|
29
30
|
TestEntity({ target, entity })
|
|
31
|
+
TestDirect({ target, entity })
|
|
30
32
|
})
|
|
31
33
|
})
|
|
32
34
|
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
|
|
2
|
+
const envlocal = __dirname + '/../../../.env.local'
|
|
3
|
+
require('dotenv').config({ quiet: true, path: [envlocal] })
|
|
4
|
+
|
|
5
|
+
import { test, describe } from 'node:test'
|
|
6
|
+
import assert from 'node:assert'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import { ProjectNameSDK } from '../../..'
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
envOverride,
|
|
13
|
+
} from '../../utility'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
describe('EntityNameDirect', async () => {
|
|
17
|
+
|
|
18
|
+
test('direct-exists', async () => {
|
|
19
|
+
const sdk = new ProjectNameSDK({
|
|
20
|
+
system: { fetch: async () => ({}) }
|
|
21
|
+
})
|
|
22
|
+
assert('function' === typeof sdk.direct)
|
|
23
|
+
assert('function' === typeof sdk.prepare)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
// <[SLOT:direct]>
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
// <[SLOT:directSetup]>
|
|
@@ -18,11 +18,11 @@ class EntityOperation {
|
|
|
18
18
|
done,
|
|
19
19
|
error,
|
|
20
20
|
featureHook,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
makeTarget,
|
|
22
|
+
makeRequest,
|
|
23
|
+
makeResponse,
|
|
24
|
+
makeResult,
|
|
25
|
+
makeSpec,
|
|
26
26
|
} = utility
|
|
27
27
|
|
|
28
28
|
let fres: Promise<any> | undefined = undefined
|
|
@@ -38,15 +38,15 @@ class EntityOperation {
|
|
|
38
38
|
try {
|
|
39
39
|
// #PreSelection-Hook
|
|
40
40
|
|
|
41
|
-
ctx.out.
|
|
42
|
-
if (ctx.out.
|
|
43
|
-
return error(ctx, ctx.out.
|
|
41
|
+
ctx.out.target = makeTarget(ctx)
|
|
42
|
+
if (ctx.out.target instanceof Error) {
|
|
43
|
+
return error(ctx, ctx.out.target)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreSpec-Hook
|
|
48
48
|
|
|
49
|
-
ctx.out.spec =
|
|
49
|
+
ctx.out.spec = makeSpec(ctx)
|
|
50
50
|
if (ctx.out.spec instanceof Error) {
|
|
51
51
|
return error(ctx, ctx.out.spec)
|
|
52
52
|
}
|
|
@@ -54,7 +54,7 @@ class EntityOperation {
|
|
|
54
54
|
|
|
55
55
|
// #PreRequest-Hook
|
|
56
56
|
|
|
57
|
-
ctx.out.request = await
|
|
57
|
+
ctx.out.request = await makeRequest(ctx)
|
|
58
58
|
if (ctx.out.request instanceof Error) {
|
|
59
59
|
return error(ctx, ctx.out.request)
|
|
60
60
|
}
|
|
@@ -62,7 +62,7 @@ class EntityOperation {
|
|
|
62
62
|
|
|
63
63
|
// #PreResponse-Hook
|
|
64
64
|
|
|
65
|
-
ctx.out.response = await
|
|
65
|
+
ctx.out.response = await makeResponse(ctx)
|
|
66
66
|
if (ctx.out.response instanceof Error) {
|
|
67
67
|
return error(ctx, ctx.out.response)
|
|
68
68
|
}
|
|
@@ -70,7 +70,7 @@ class EntityOperation {
|
|
|
70
70
|
|
|
71
71
|
// #PreResult-Hook
|
|
72
72
|
|
|
73
|
-
ctx.out.result = await
|
|
73
|
+
ctx.out.result = await makeResult(ctx)
|
|
74
74
|
if (ctx.out.result instanceof Error) {
|
|
75
75
|
return error(ctx, ctx.out.result)
|
|
76
76
|
}
|
|
@@ -19,11 +19,11 @@ class EntityOperation {
|
|
|
19
19
|
done,
|
|
20
20
|
error,
|
|
21
21
|
featureHook,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
makeTarget,
|
|
23
|
+
makeRequest,
|
|
24
|
+
makeResponse,
|
|
25
|
+
makeResult,
|
|
26
|
+
makeSpec,
|
|
27
27
|
} = utility
|
|
28
28
|
|
|
29
29
|
let fres: Promise<any> | undefined = undefined
|
|
@@ -39,15 +39,15 @@ class EntityOperation {
|
|
|
39
39
|
try {
|
|
40
40
|
// #PreSelection-Hook
|
|
41
41
|
|
|
42
|
-
ctx.out.
|
|
43
|
-
if (ctx.out.
|
|
44
|
-
return error(ctx, ctx.out.
|
|
42
|
+
ctx.out.target = makeTarget(ctx)
|
|
43
|
+
if (ctx.out.target instanceof Error) {
|
|
44
|
+
return error(ctx, ctx.out.target)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
// #PreSpec-Hook
|
|
49
49
|
|
|
50
|
-
ctx.out.spec =
|
|
50
|
+
ctx.out.spec = makeSpec(ctx)
|
|
51
51
|
if (ctx.out.spec instanceof Error) {
|
|
52
52
|
return error(ctx, ctx.out.spec)
|
|
53
53
|
}
|
|
@@ -55,7 +55,7 @@ class EntityOperation {
|
|
|
55
55
|
|
|
56
56
|
// #PreRequest-Hook
|
|
57
57
|
|
|
58
|
-
ctx.out.request = await
|
|
58
|
+
ctx.out.request = await makeRequest(ctx)
|
|
59
59
|
if (ctx.out.request instanceof Error) {
|
|
60
60
|
return error(ctx, ctx.out.request)
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ class EntityOperation {
|
|
|
63
63
|
|
|
64
64
|
// #PreResponse-Hook
|
|
65
65
|
|
|
66
|
-
ctx.out.response = await
|
|
66
|
+
ctx.out.response = await makeResponse(ctx)
|
|
67
67
|
if (ctx.out.response instanceof Error) {
|
|
68
68
|
return error(ctx, ctx.out.response)
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ class EntityOperation {
|
|
|
71
71
|
|
|
72
72
|
// #PreResult-Hook
|
|
73
73
|
|
|
74
|
-
ctx.out.result = await
|
|
74
|
+
ctx.out.result = await makeResult(ctx)
|
|
75
75
|
if (ctx.out.result instanceof Error) {
|
|
76
76
|
return error(ctx, ctx.out.result)
|
|
77
77
|
}
|
|
@@ -19,11 +19,11 @@ class EntityOperation {
|
|
|
19
19
|
done,
|
|
20
20
|
error,
|
|
21
21
|
featureHook,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
makeTarget,
|
|
23
|
+
makeRequest,
|
|
24
|
+
makeResponse,
|
|
25
|
+
makeResult,
|
|
26
|
+
makeSpec,
|
|
27
27
|
} = utility
|
|
28
28
|
|
|
29
29
|
let fres: Promise<any> | undefined = undefined
|
|
@@ -39,15 +39,15 @@ class EntityOperation {
|
|
|
39
39
|
try {
|
|
40
40
|
// #PreSelection-Hook
|
|
41
41
|
|
|
42
|
-
ctx.out.
|
|
43
|
-
if (ctx.out.
|
|
44
|
-
return error(ctx, ctx.out.
|
|
42
|
+
ctx.out.target = makeTarget(ctx)
|
|
43
|
+
if (ctx.out.target instanceof Error) {
|
|
44
|
+
return error(ctx, ctx.out.target)
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
// #PreSpec-Hook
|
|
49
49
|
|
|
50
|
-
ctx.out.spec =
|
|
50
|
+
ctx.out.spec = makeSpec(ctx)
|
|
51
51
|
if (ctx.out.spec instanceof Error) {
|
|
52
52
|
return error(ctx, ctx.out.spec)
|
|
53
53
|
}
|
|
@@ -55,7 +55,7 @@ class EntityOperation {
|
|
|
55
55
|
|
|
56
56
|
// #PreRequest-Hook
|
|
57
57
|
|
|
58
|
-
ctx.out.request = await
|
|
58
|
+
ctx.out.request = await makeRequest(ctx)
|
|
59
59
|
if (ctx.out.request instanceof Error) {
|
|
60
60
|
return error(ctx, ctx.out.request)
|
|
61
61
|
}
|
|
@@ -63,7 +63,7 @@ class EntityOperation {
|
|
|
63
63
|
|
|
64
64
|
// #PreResponse-Hook
|
|
65
65
|
|
|
66
|
-
ctx.out.response = await
|
|
66
|
+
ctx.out.response = await makeResponse(ctx)
|
|
67
67
|
if (ctx.out.response instanceof Error) {
|
|
68
68
|
return error(ctx, ctx.out.response)
|
|
69
69
|
}
|
|
@@ -71,7 +71,7 @@ class EntityOperation {
|
|
|
71
71
|
|
|
72
72
|
// #PreResult-Hook
|
|
73
73
|
|
|
74
|
-
ctx.out.result = await
|
|
74
|
+
ctx.out.result = await makeResult(ctx)
|
|
75
75
|
if (ctx.out.result instanceof Error) {
|
|
76
76
|
return error(ctx, ctx.out.result)
|
|
77
77
|
}
|
|
@@ -19,11 +19,11 @@ class EntityOperation {
|
|
|
19
19
|
done,
|
|
20
20
|
error,
|
|
21
21
|
featureHook,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
makeTarget,
|
|
23
|
+
makeRequest,
|
|
24
|
+
makeResponse,
|
|
25
|
+
makeResult,
|
|
26
|
+
makeSpec,
|
|
27
27
|
} = utility
|
|
28
28
|
|
|
29
29
|
let fres: Promise<any> | undefined = undefined
|
|
@@ -38,17 +38,17 @@ class EntityOperation {
|
|
|
38
38
|
|
|
39
39
|
try {
|
|
40
40
|
|
|
41
|
-
// #
|
|
41
|
+
// #PreTarget-Hook
|
|
42
42
|
|
|
43
|
-
ctx.out.
|
|
44
|
-
if (ctx.out.
|
|
45
|
-
return error(ctx, ctx.out.
|
|
43
|
+
ctx.out.target = makeTarget(ctx)
|
|
44
|
+
if (ctx.out.target instanceof Error) {
|
|
45
|
+
return error(ctx, ctx.out.target)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
// #PreSpec-Hook
|
|
50
50
|
|
|
51
|
-
ctx.out.spec =
|
|
51
|
+
ctx.out.spec = makeSpec(ctx)
|
|
52
52
|
if (ctx.out.spec instanceof Error) {
|
|
53
53
|
return error(ctx, ctx.out.spec)
|
|
54
54
|
}
|
|
@@ -56,7 +56,7 @@ class EntityOperation {
|
|
|
56
56
|
|
|
57
57
|
// #PreRequest-Hook
|
|
58
58
|
|
|
59
|
-
ctx.out.request = await
|
|
59
|
+
ctx.out.request = await makeRequest(ctx)
|
|
60
60
|
if (ctx.out.request instanceof Error) {
|
|
61
61
|
return error(ctx, ctx.out.request)
|
|
62
62
|
}
|
|
@@ -64,7 +64,7 @@ class EntityOperation {
|
|
|
64
64
|
|
|
65
65
|
// #PreResponse-Hook
|
|
66
66
|
|
|
67
|
-
ctx.out.response = await
|
|
67
|
+
ctx.out.response = await makeResponse(ctx)
|
|
68
68
|
if (ctx.out.response instanceof Error) {
|
|
69
69
|
return error(ctx, ctx.out.response)
|
|
70
70
|
}
|
|
@@ -72,7 +72,7 @@ class EntityOperation {
|
|
|
72
72
|
|
|
73
73
|
// #PreResult-Hook
|
|
74
74
|
|
|
75
|
-
ctx.out.result = await
|
|
75
|
+
ctx.out.result = await makeResult(ctx)
|
|
76
76
|
if (ctx.out.result instanceof Error) {
|
|
77
77
|
return error(ctx, ctx.out.result)
|
|
78
78
|
}
|