@voxgig/sdkgen 0.25.0 → 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 +6 -6
- package/dist/action/action.js +1 -2
- package/dist/action/action.js.map +1 -1
- package/dist/action/feature.js +4 -2
- package/dist/action/feature.js.map +1 -1
- package/dist/action/target.js +4 -2
- package/dist/action/target.js.map +1 -1
- package/dist/cmp/Entity.js +2 -1
- package/dist/cmp/Entity.js.map +1 -1
- package/dist/cmp/Feature.js +11 -9
- package/dist/cmp/Feature.js.map +1 -1
- package/dist/cmp/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- package/dist/cmp/Main.js +6 -2
- package/dist/cmp/Main.js.map +1 -1
- package/dist/cmp/ReadmeEntity.js +2 -1
- package/dist/cmp/ReadmeEntity.js.map +1 -1
- package/dist/cmp/Test.d.ts +2 -0
- package/dist/cmp/Test.js +17 -0
- package/dist/cmp/Test.js.map +1 -0
- package/dist/sdkgen.d.ts +2 -1
- package/dist/sdkgen.js +17 -28
- package/dist/sdkgen.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types.d.ts +3 -1
- package/dist/types.js +4 -0
- package/dist/types.js.map +1 -1
- package/model/sdkgen.jsonic +9 -9
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +3 -3
- package/project/.sdk/model/feature/test.jsonic +8 -3
- package/project/.sdk/model/target/go.jsonic +19 -4
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +5 -5
- 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/Main_js.ts +3 -3
- package/project/.sdk/src/cmp/js/Quick_js.ts +1 -1
- 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/Config_ts.ts +53 -6
- package/project/.sdk/src/cmp/ts/EntityOperation_ts.ts +3 -21
- package/project/.sdk/src/cmp/ts/Entity_ts.ts +3 -5
- package/project/.sdk/src/cmp/ts/Main_ts.ts +23 -13
- package/project/.sdk/src/cmp/ts/Package_ts.ts +30 -11
- 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 +349 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +23 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- package/project/.sdk/src/cmp/ts/fragment/Direct.test.fragment.ts +30 -0
- package/project/.sdk/src/cmp/ts/fragment/Entity.fragment.ts +50 -38
- package/project/.sdk/src/cmp/ts/fragment/Entity.test.fragment.ts +9 -7
- package/project/.sdk/src/cmp/ts/fragment/EntityCreateOp.fragment.ts +47 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityListOp.fragment.ts +49 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityLoadOp.fragment.ts +50 -33
- package/project/.sdk/src/cmp/ts/fragment/EntityRemoveOp.fragment.ts +51 -32
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +166 -34
- package/project/.sdk/src/cmp/ts/fragment/SdkError.fragment.ts +25 -0
- package/project/.sdk/src/cmp/ts/tsconfig.json +15 -0
- package/project/.sdk/src/cmp/ts/utility_ts.ts +55 -1
- 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 +158 -104
- package/project/.sdk/tm/ts/src/types.ts +18 -78
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +3 -4
- package/project/.sdk/tm/ts/src/utility/{AddfeatureUtility.ts → FeatureAddUtility.ts} +2 -2
- package/project/.sdk/tm/ts/src/utility/{FeaturehookUtility.ts → FeatureHookUtility.ts} +8 -5
- package/project/.sdk/tm/ts/src/utility/FeatureInitUtility.ts +15 -0
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +20 -2
- package/project/.sdk/tm/ts/src/utility/MakeContextUtility.ts +27 -0
- package/project/.sdk/tm/ts/src/utility/{ErrorUtility.ts → MakeErrorUtility.ts} +10 -6
- package/project/.sdk/tm/ts/src/utility/MakeFetchDefUtility.ts +46 -0
- package/project/.sdk/tm/ts/src/utility/{OptionsUtility.ts → MakeOptionsUtility.ts} +32 -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/MakeResultUtility.ts +56 -0
- package/project/.sdk/tm/ts/src/utility/MakeSpecUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/MakeTargetUtility.ts +76 -0
- package/project/.sdk/tm/ts/src/utility/MakeUrlUtility.ts +61 -0
- package/project/.sdk/tm/ts/src/utility/{FindparamUtility.ts → ParamUtility.ts} +28 -8
- package/project/.sdk/tm/ts/src/utility/{AuthUtility.ts → PrepareAuthUtility.ts} +10 -4
- package/project/.sdk/tm/ts/src/utility/PrepareBodyUtility.ts +32 -0
- 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 +17 -0
- package/project/.sdk/tm/ts/src/utility/PrepareQueryUtility.ts +30 -0
- package/project/.sdk/tm/ts/src/utility/{ResbasicUtility.ts → ResultBasicUtility.ts} +12 -7
- package/project/.sdk/tm/ts/src/utility/ResultBodyUtility.ts +22 -0
- package/project/.sdk/tm/ts/src/utility/ResultHeadersUtility.ts +26 -0
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1113 -525
- package/project/.sdk/tm/ts/src/utility/{ReqformUtility.ts → TransformRequestUtility.ts} +9 -7
- package/project/.sdk/tm/ts/src/utility/{ResformUtility.ts → TransformResponseUtility.ts} +11 -8
- package/project/.sdk/tm/ts/src/utility/Utility.ts +52 -65
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +36 -13
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +385 -168
- package/project/.sdk/tm/ts/test/utility/StructUtility.test.ts +433 -189
- package/src/action/action.ts +1 -2
- package/src/action/feature.ts +7 -2
- package/src/action/target.ts +7 -7
- package/src/cmp/Entity.ts +7 -1
- package/src/cmp/Feature.ts +11 -9
- package/src/cmp/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +12 -2
- package/src/cmp/ReadmeEntity.ts +6 -1
- package/src/cmp/Test.ts +31 -0
- package/src/sdkgen.ts +19 -34
- package/src/types.ts +10 -1
- package/project/.sdk/src/cmp/ts/EntityTest_ts.ts +0 -180
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +0 -29
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +0 -67
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +0 -46
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +0 -13
- package/project/.sdk/tm/ts/src/utility/JoinurlUtility.ts +0 -15
- package/project/.sdk/tm/ts/src/utility/OperatorUtility.ts +0 -90
- 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 -66
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +0 -19
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +0 -23
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +0 -30
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +0 -36
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +0 -61
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
|
|
2
|
+
import * as Path from 'node:path'
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
clone,
|
|
7
|
+
walk,
|
|
8
|
+
} from '@voxgig/struct'
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function projectPath(suffix?: string): string {
|
|
12
|
+
return Path.normalize(Path.join(__dirname, '../../..', suffix ?? ''))
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function formatGoMap(obj: any, indent: number = 0): string {
|
|
17
|
+
if (obj == null) {
|
|
18
|
+
return 'nil'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const pad = '\t'.repeat(indent)
|
|
22
|
+
const padInner = '\t'.repeat(indent + 1)
|
|
23
|
+
|
|
24
|
+
if (Array.isArray(obj)) {
|
|
25
|
+
if (obj.length === 0) {
|
|
26
|
+
return '[]any{}'
|
|
27
|
+
}
|
|
28
|
+
const items = obj.map(v => padInner + formatGoValue(v, indent + 1)).join(',\n')
|
|
29
|
+
return `[]any{\n${items},\n${pad}}`
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof obj === 'object') {
|
|
33
|
+
const entries = Object.entries(obj)
|
|
34
|
+
if (entries.length === 0) {
|
|
35
|
+
return 'map[string]any{}'
|
|
36
|
+
}
|
|
37
|
+
const items = entries
|
|
38
|
+
.map(([k, v]) => `${padInner}"${k}": ${formatGoValue(v, indent + 1)}`)
|
|
39
|
+
.join(',\n')
|
|
40
|
+
return `map[string]any{\n${items},\n${pad}}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return formatGoValue(obj, indent)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
function formatGoValue(val: any, indent: number = 0): string {
|
|
48
|
+
if (val === null || val === undefined) {
|
|
49
|
+
return 'nil'
|
|
50
|
+
}
|
|
51
|
+
if (typeof val === 'string') {
|
|
52
|
+
return `"${val.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"`
|
|
53
|
+
}
|
|
54
|
+
if (typeof val === 'number') {
|
|
55
|
+
if (Number.isInteger(val)) {
|
|
56
|
+
return String(val)
|
|
57
|
+
}
|
|
58
|
+
return String(val)
|
|
59
|
+
}
|
|
60
|
+
if (typeof val === 'boolean') {
|
|
61
|
+
return val ? 'true' : 'false'
|
|
62
|
+
}
|
|
63
|
+
if (Array.isArray(val)) {
|
|
64
|
+
return formatGoMap(val, indent)
|
|
65
|
+
}
|
|
66
|
+
if (typeof val === 'object') {
|
|
67
|
+
return formatGoMap(val, indent)
|
|
68
|
+
}
|
|
69
|
+
return String(val)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
function clean(o: any) {
|
|
74
|
+
return walk(clone(o), (k: any, v: any, p: any) => {
|
|
75
|
+
if (null != k && k.endsWith('$')) {
|
|
76
|
+
delete p[k]
|
|
77
|
+
}
|
|
78
|
+
return v
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export {
|
|
84
|
+
clean,
|
|
85
|
+
formatGoMap,
|
|
86
|
+
formatGoValue,
|
|
87
|
+
projectPath,
|
|
88
|
+
}
|
|
@@ -17,8 +17,8 @@ const Main = cmp(async function Main(props: any) {
|
|
|
17
17
|
const { target } = props
|
|
18
18
|
const { model } = props.ctx$
|
|
19
19
|
|
|
20
|
-
const { entity } = model.main.
|
|
21
|
-
const { feature } = model.main.
|
|
20
|
+
const { entity } = model.main.kit
|
|
21
|
+
const { feature } = model.main.kit
|
|
22
22
|
|
|
23
23
|
Package({ target })
|
|
24
24
|
|
|
@@ -72,7 +72,7 @@ const Main = cmp(async function Main(props: any) {
|
|
|
72
72
|
}, () => {
|
|
73
73
|
each(entity, (entity: any) => {
|
|
74
74
|
// console.log('ENTITY', entity.name)
|
|
75
|
-
MainEntity({ target, entity, entitySDK: model.main.
|
|
75
|
+
MainEntity({ target, entity, entitySDK: model.main.kit.entity[entity.name] })
|
|
76
76
|
})
|
|
77
77
|
})
|
|
78
78
|
})
|
|
@@ -21,7 +21,7 @@ const Quick = cmp(function Quick(props: any) {
|
|
|
21
21
|
|
|
22
22
|
// TODO: selected features should be active by default!
|
|
23
23
|
|
|
24
|
-
const featureOptions = each(model.main.
|
|
24
|
+
const featureOptions = each(model.main.kit.feature)
|
|
25
25
|
.filter((f: any) => f.active)
|
|
26
26
|
.reduce((a: any, f: any) => a + `\n ${f.name}: { active: true },`, '')
|
|
27
27
|
|
|
@@ -4,7 +4,7 @@ async create(data) {
|
|
|
4
4
|
let entity = this
|
|
5
5
|
let client = this.#client
|
|
6
6
|
const utility = this.#utility
|
|
7
|
-
const { operator,
|
|
7
|
+
const { operator, makeSpec, makeRequest, makeResponse, makeResult, error, struct, done } = utility
|
|
8
8
|
|
|
9
9
|
let op = {
|
|
10
10
|
entity: 'Name',
|
|
@@ -22,7 +22,7 @@ async create(data) {
|
|
|
22
22
|
let ctx = { client, op, utility, entity }
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
// #
|
|
25
|
+
// #PreTarget-Hook
|
|
26
26
|
|
|
27
27
|
await operator(ctx)
|
|
28
28
|
|
|
@@ -31,22 +31,22 @@ async create(data) {
|
|
|
31
31
|
|
|
32
32
|
this.#data = ctx.op.data
|
|
33
33
|
|
|
34
|
-
await
|
|
34
|
+
await makeSpec(ctx)
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
// #PreRequest-Hook
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await makeRequest(ctx)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// #PreResponse-Hook
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await makeResponse(ctx)
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreResult-Hook
|
|
48
48
|
|
|
49
|
-
await
|
|
49
|
+
await makeResult(ctx)
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
// #PostOperation-Hook
|
|
@@ -4,7 +4,7 @@ async list(match) {
|
|
|
4
4
|
let entity = this
|
|
5
5
|
let client = this.#client
|
|
6
6
|
const utility = this.#utility
|
|
7
|
-
const { operator,
|
|
7
|
+
const { operator, makeSpec, makeRequest, makeResponse, makeResult, error, struct, done } = utility
|
|
8
8
|
|
|
9
9
|
let op = {
|
|
10
10
|
entity: 'Name',
|
|
@@ -22,7 +22,7 @@ async list(match) {
|
|
|
22
22
|
let ctx = { client, entity, op, utility}
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
// #
|
|
25
|
+
// #PreTarget-Hook
|
|
26
26
|
|
|
27
27
|
await operator(ctx)
|
|
28
28
|
|
|
@@ -31,22 +31,22 @@ async list(match) {
|
|
|
31
31
|
|
|
32
32
|
this.#match = ctx.op.match
|
|
33
33
|
|
|
34
|
-
await
|
|
34
|
+
await makeSpec(ctx)
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
// #PreRequest-Hook
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await makeRequest(ctx)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// #PreResponse-Hook
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await makeResponse(ctx)
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreResult-Hook
|
|
48
48
|
|
|
49
|
-
await
|
|
49
|
+
await makeResult(ctx)
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
// #PostOperation-Hook
|
|
@@ -4,7 +4,7 @@ async load(match) {
|
|
|
4
4
|
const entity = this
|
|
5
5
|
const client = this.#client
|
|
6
6
|
const utility = this.#utility
|
|
7
|
-
const { operator,
|
|
7
|
+
const { operator, makeSpec, makeRequest, makeResponse, makeResult, error, struct, done } = utility
|
|
8
8
|
|
|
9
9
|
const op = {
|
|
10
10
|
entity: 'Name',
|
|
@@ -22,7 +22,7 @@ async load(match) {
|
|
|
22
22
|
let ctx = { client, entity, op, utility}
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
// #
|
|
25
|
+
// #PreTarget-Hook
|
|
26
26
|
|
|
27
27
|
await operator(ctx)
|
|
28
28
|
|
|
@@ -31,22 +31,22 @@ async load(match) {
|
|
|
31
31
|
|
|
32
32
|
this.#match = op.match
|
|
33
33
|
|
|
34
|
-
await
|
|
34
|
+
await makeSpec(ctx)
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
// #PreRequest-Hook
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await makeRequest(ctx)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// #PreResponse-Hook
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await makeResponse(ctx)
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreResult-Hook
|
|
48
48
|
|
|
49
|
-
await
|
|
49
|
+
await makeResult(ctx)
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
// #PostOperation-Hook
|
|
@@ -4,7 +4,7 @@ async remove(match) {
|
|
|
4
4
|
let entity = this
|
|
5
5
|
let client = this.#client
|
|
6
6
|
const utility = this.#utility
|
|
7
|
-
const { operator,
|
|
7
|
+
const { operator, makeSpec, makeRequest, makeResponse, makeResult, error, struct, done } = utility
|
|
8
8
|
|
|
9
9
|
let op = {
|
|
10
10
|
entity: 'Name',
|
|
@@ -22,7 +22,7 @@ async remove(match) {
|
|
|
22
22
|
let ctx = {client, entity, op, utility}
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
// #
|
|
25
|
+
// #PreTarget-Hook
|
|
26
26
|
|
|
27
27
|
await operator(ctx)
|
|
28
28
|
|
|
@@ -31,22 +31,22 @@ async remove(match) {
|
|
|
31
31
|
|
|
32
32
|
this.#data = op.data
|
|
33
33
|
|
|
34
|
-
await
|
|
34
|
+
await makeSpec(ctx)
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
// #PreRequest-Hook
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await makeRequest(ctx)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// #PreResponse-Hook
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await makeResponse(ctx)
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreResult-Hook
|
|
48
48
|
|
|
49
|
-
await
|
|
49
|
+
await makeResult(ctx)
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
// #PostOperation-Hook
|
|
@@ -4,7 +4,7 @@ async update(data) {
|
|
|
4
4
|
let entity = this
|
|
5
5
|
let client = this.#client
|
|
6
6
|
const utility = this.#utility
|
|
7
|
-
const { operator,
|
|
7
|
+
const { operator, makeSpec, makeRequest, makeResponse, makeResult, error, struct, done } = utility
|
|
8
8
|
|
|
9
9
|
let op = {
|
|
10
10
|
entity: 'Name',
|
|
@@ -22,7 +22,7 @@ async update(data) {
|
|
|
22
22
|
let ctx = {client, entity, op, utility}
|
|
23
23
|
|
|
24
24
|
|
|
25
|
-
// #
|
|
25
|
+
// #PreTarget-Hook
|
|
26
26
|
|
|
27
27
|
await operator(ctx)
|
|
28
28
|
|
|
@@ -31,22 +31,22 @@ async update(data) {
|
|
|
31
31
|
|
|
32
32
|
this.#data = op.data
|
|
33
33
|
|
|
34
|
-
await
|
|
34
|
+
await makeSpec(ctx)
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
// #PreRequest-Hook
|
|
38
38
|
|
|
39
|
-
await
|
|
39
|
+
await makeRequest(ctx)
|
|
40
40
|
|
|
41
41
|
|
|
42
42
|
// #PreResponse-Hook
|
|
43
43
|
|
|
44
|
-
await
|
|
44
|
+
await makeResponse(ctx)
|
|
45
45
|
|
|
46
46
|
|
|
47
47
|
// #PreResult-Hook
|
|
48
48
|
|
|
49
|
-
await
|
|
49
|
+
await makeResult(ctx)
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
// #PostOperation-Hook
|
|
@@ -10,7 +10,7 @@ class NameSDK {
|
|
|
10
10
|
|
|
11
11
|
constructor(options) {
|
|
12
12
|
|
|
13
|
-
this.#options = this.#utility.
|
|
13
|
+
this.#options = this.#utility.makeOptions({
|
|
14
14
|
client: this,
|
|
15
15
|
utility: this.#utility,
|
|
16
16
|
config: Config,
|
|
@@ -55,6 +55,90 @@ class NameSDK {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
|
|
58
|
+
async prepare(fetchargs) {
|
|
59
|
+
const utility = this.#utility
|
|
60
|
+
const { headers, auth, fullurl } = utility
|
|
61
|
+
|
|
62
|
+
fetchargs = fetchargs || {}
|
|
63
|
+
|
|
64
|
+
const options = this.options()
|
|
65
|
+
|
|
66
|
+
const spec = {
|
|
67
|
+
base: options.base,
|
|
68
|
+
prefix: options.prefix,
|
|
69
|
+
suffix: options.suffix,
|
|
70
|
+
path: fetchargs.path || '',
|
|
71
|
+
method: fetchargs.method || 'GET',
|
|
72
|
+
params: fetchargs.params || {},
|
|
73
|
+
query: fetchargs.query || {},
|
|
74
|
+
headers: headers({ client: this, utility }),
|
|
75
|
+
body: fetchargs.body,
|
|
76
|
+
step: 'start',
|
|
77
|
+
alias: {},
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Merge user-provided headers over SDK defaults.
|
|
81
|
+
if (fetchargs.headers) {
|
|
82
|
+
const uheaders = fetchargs.headers
|
|
83
|
+
for (let key in uheaders) {
|
|
84
|
+
spec.headers[key] = uheaders[key]
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Apply SDK auth.
|
|
89
|
+
const ctx = { client: this, op: { params: [] }, spec, utility }
|
|
90
|
+
auth(ctx)
|
|
91
|
+
|
|
92
|
+
// Build URL.
|
|
93
|
+
const url = fullurl(ctx)
|
|
94
|
+
|
|
95
|
+
const fetchdef = {
|
|
96
|
+
url,
|
|
97
|
+
method: spec.method,
|
|
98
|
+
headers: { ...spec.headers },
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (null != spec.body) {
|
|
102
|
+
fetchdef.body =
|
|
103
|
+
'object' === typeof spec.body ? JSON.stringify(spec.body) : spec.body
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return fetchdef
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
async direct(fetchargs) {
|
|
111
|
+
const fetchdef = await this.prepare(fetchargs)
|
|
112
|
+
if (fetchdef instanceof Error) {
|
|
113
|
+
return fetchdef
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const options = this.options()
|
|
117
|
+
const fetch = options.system.fetch
|
|
118
|
+
|
|
119
|
+
try {
|
|
120
|
+
const response = await fetch(fetchdef.url, fetchdef)
|
|
121
|
+
|
|
122
|
+
if (null == response) {
|
|
123
|
+
return { ok: false, err: new Error('response: undefined') }
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const status = response.status
|
|
127
|
+
const json = 'function' === typeof response.json ? await response.json() : response.json
|
|
128
|
+
|
|
129
|
+
return {
|
|
130
|
+
ok: status >= 200 && status < 300,
|
|
131
|
+
status,
|
|
132
|
+
headers: response.headers,
|
|
133
|
+
data: json,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
catch (err) {
|
|
137
|
+
return { ok: false, err }
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
58
142
|
// <[SLOT]>
|
|
59
143
|
}
|
|
60
144
|
|
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
|
|
2
2
|
import * as Path from 'node:path'
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
import {
|
|
5
|
-
|
|
6
|
-
File,
|
|
6
|
+
Content,
|
|
7
|
+
File,
|
|
8
|
+
Fragment,
|
|
9
|
+
Line,
|
|
10
|
+
cmp,
|
|
11
|
+
each,
|
|
12
|
+
indent,
|
|
7
13
|
} from '@voxgig/sdkgen'
|
|
8
14
|
|
|
9
15
|
|
|
16
|
+
import {
|
|
17
|
+
KIT,
|
|
18
|
+
Model,
|
|
19
|
+
getModelPath,
|
|
20
|
+
nom,
|
|
21
|
+
} from '@voxgig/apidef'
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
import {
|
|
25
|
+
clean,
|
|
26
|
+
formatJson,
|
|
27
|
+
} from './utility_ts'
|
|
10
28
|
|
|
11
29
|
|
|
12
30
|
const Config = cmp(async function Config(props: any) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
31
|
+
const ctx$ = props.ctx$
|
|
32
|
+
const target = props.target
|
|
33
|
+
|
|
34
|
+
const model: Model = ctx$.model
|
|
35
|
+
|
|
36
|
+
const entity = getModelPath(model, `main.${KIT}.entity`)
|
|
37
|
+
const feature = getModelPath(model, `main.${KIT}.feature`)
|
|
15
38
|
|
|
16
39
|
const ff = Path.normalize(__dirname + '/../../../src/cmp/ts/fragment/')
|
|
17
40
|
|
|
18
|
-
const headers = model
|
|
41
|
+
const headers = getModelPath(model, `main.${KIT}.config.headers`) || {}
|
|
19
42
|
|
|
20
43
|
File({ name: 'Config.' + target.ext }, () => {
|
|
21
44
|
|
|
@@ -23,13 +46,37 @@ const Config = cmp(async function Config(props: any) {
|
|
|
23
46
|
from: ff + 'Config.fragment.ts',
|
|
24
47
|
|
|
25
48
|
replace: {
|
|
49
|
+
|
|
26
50
|
"'HEADERS'": indent(JSON.stringify(headers, null, 2), 4).trim(),
|
|
51
|
+
|
|
52
|
+
'// #ImportFeatures': () => each(feature, (f: any) => {
|
|
53
|
+
Line(`import { ${nom(f, 'Name')}Feature } from ` +
|
|
54
|
+
`'./feature/${f.name}/${nom(f, 'Name')}Feature'`)
|
|
55
|
+
}),
|
|
56
|
+
|
|
57
|
+
'// #FeatureClasses': () => each(feature, (f: any) => {
|
|
58
|
+
Line(` ${f.name}: ${nom(f, 'Name')}Feature`)
|
|
59
|
+
}),
|
|
60
|
+
|
|
61
|
+
'// #FeatureConfigs': () => each(feature, (f: any) => {
|
|
62
|
+
Line(` ${f.name}: ${formatJson(f.config, { margin: 4 })}`)
|
|
63
|
+
}),
|
|
64
|
+
|
|
65
|
+
|
|
27
66
|
'// #EntityConfigs': () => each(entity, (entity: any) => {
|
|
28
67
|
Content(`
|
|
29
68
|
${entity.name}: {
|
|
30
69
|
},
|
|
31
70
|
`)
|
|
32
|
-
})
|
|
71
|
+
}),
|
|
72
|
+
|
|
73
|
+
"'ENTITYMAP'": formatJson(Object.values(entity)
|
|
74
|
+
.reduce((a: any, n: any) => (a[n.name] = clean({
|
|
75
|
+
fields: n.fields,
|
|
76
|
+
name: n.name,
|
|
77
|
+
op: n.op,
|
|
78
|
+
relations: n.relations,
|
|
79
|
+
}), a), {}), { margin: 2 }).trim(),
|
|
33
80
|
}
|
|
34
81
|
})
|
|
35
82
|
})
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
|
|
8
8
|
import { jsonify } from '@voxgig/struct'
|
|
9
9
|
|
|
10
|
-
import { formatJSONSrc } from './utility_ts'
|
|
10
|
+
import { formatJSONSrc, formatJson } from './utility_ts'
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
const EntityOperation = cmp(function Operation(props: any) {
|
|
@@ -22,17 +22,6 @@ const EntityOperation = cmp(function Operation(props: any) {
|
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const entop = entity.op[opname]
|
|
25
|
-
const path = entop.path
|
|
26
|
-
|
|
27
|
-
// // TODO: move up to to common Entity
|
|
28
|
-
// const params = JSON.stringify((path.match(/\{[^}]+\}/g) || [])
|
|
29
|
-
// .map((p: string) => p.substring(1, p.length - 1))
|
|
30
|
-
// .filter((p: string) => null != p && '' !== p))
|
|
31
|
-
|
|
32
|
-
// const aliasmap = JSON.stringify(entitySDK.alias.field)
|
|
33
|
-
const aliasmap = JSON.stringify(entity.alias.field)
|
|
34
|
-
|
|
35
|
-
// const hasp = '' != entop.place
|
|
36
25
|
|
|
37
26
|
Fragment({
|
|
38
27
|
from: ff + '/Entity' + camelify(opname) + 'Op.fragment.ts',
|
|
@@ -43,17 +32,10 @@ const EntityOperation = cmp(function Operation(props: any) {
|
|
|
43
32
|
SdkName: model.const.Name,
|
|
44
33
|
EntityName: entity.Name,
|
|
45
34
|
entityname: entity.name,
|
|
46
|
-
|
|
47
|
-
"['PATHALT']": entop.pathalt,
|
|
48
|
-
"['PARAM-LIST']": jsonify(Object.keys(entop.param)),
|
|
49
|
-
"{ 'ALIAS': 'MAP' }": aliasmap,
|
|
50
|
-
"'REQFORM'": formatJSONSrc(JSON.stringify(entop.reqform)),
|
|
51
|
-
"'RESFORM'": formatJSONSrc(JSON.stringify(entop.resform)),
|
|
52
|
-
"'VALIDATE'": formatJSONSrc(JSON.stringify(entop.validate)),
|
|
53
|
-
|
|
35
|
+
"['TARGETS']": formatJson(entop.targets, { margin: 6 }).trim(),
|
|
54
36
|
'#Feature-Hook': ({ name, indent }: any) =>
|
|
55
37
|
Content({ indent }, `
|
|
56
|
-
fres =
|
|
38
|
+
fres = featureHook(ctx, '${name}')
|
|
57
39
|
if (fres instanceof Promise) { await fres }
|
|
58
40
|
`)
|
|
59
41
|
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from '@voxgig/sdkgen'
|
|
8
8
|
|
|
9
9
|
import { EntityOperation } from './EntityOperation_ts'
|
|
10
|
-
import { EntityTest } from './EntityTest_ts'
|
|
10
|
+
// import { EntityTest } from './EntityTest_ts'
|
|
11
11
|
|
|
12
12
|
|
|
13
13
|
const Entity = cmp(function Entity(props: any) {
|
|
@@ -19,7 +19,6 @@ const Entity = cmp(function Entity(props: any) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
names(entrep, entity.Name, 'EntityName')
|
|
22
|
-
// console.log('ENTREP', entrep)
|
|
23
22
|
|
|
24
23
|
const ff = Path.normalize(__dirname + '/../../../src/cmp/ts/fragment/')
|
|
25
24
|
|
|
@@ -46,7 +45,7 @@ const Entity = cmp(function Entity(props: any) {
|
|
|
46
45
|
|
|
47
46
|
'#Feature-Hook': ({ name, indent }: any) =>
|
|
48
47
|
Content({ indent }, `
|
|
49
|
-
fres =
|
|
48
|
+
fres = featureHook(ctx, '${name}')
|
|
50
49
|
if (fres instanceof Promise) { await fres }
|
|
51
50
|
`.trim()),
|
|
52
51
|
|
|
@@ -57,8 +56,7 @@ if (fres instanceof Promise) { await fres }
|
|
|
57
56
|
})
|
|
58
57
|
})
|
|
59
58
|
|
|
60
|
-
|
|
61
|
-
EntityTest({ target, entity, entrep, ff })
|
|
59
|
+
// EntityTest({ target, entity, entrep, ff })
|
|
62
60
|
})
|
|
63
61
|
|
|
64
62
|
|
|
@@ -7,33 +7,42 @@ import {
|
|
|
7
7
|
} from '@voxgig/sdkgen'
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
import type {
|
|
11
|
+
ModelEntity
|
|
12
|
+
} from '@voxgig/apidef'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
KIT,
|
|
17
|
+
getModelPath
|
|
18
|
+
} from '@voxgig/apidef'
|
|
19
|
+
|
|
20
|
+
|
|
10
21
|
import { Package } from './Package_ts'
|
|
11
22
|
import { Config } from './Config_ts'
|
|
12
23
|
import { MainEntity } from './MainEntity_ts'
|
|
13
|
-
import {
|
|
24
|
+
import { SdkError } from './SdkError_ts'
|
|
14
25
|
|
|
15
26
|
|
|
16
27
|
const Main = cmp(async function Main(props: any) {
|
|
28
|
+
|
|
29
|
+
// Needs type: target object
|
|
17
30
|
const { target } = props
|
|
18
31
|
const { model } = props.ctx$
|
|
19
32
|
|
|
20
|
-
const
|
|
21
|
-
const
|
|
33
|
+
const entity: ModelEntity = getModelPath(model, `main.${KIT}.entity`)
|
|
34
|
+
const feature = getModelPath(model, `main.${KIT}.feature`)
|
|
22
35
|
|
|
23
36
|
Package({ target })
|
|
24
37
|
|
|
25
|
-
Test({ target })
|
|
26
|
-
|
|
27
38
|
Folder({ name: 'src' }, () => {
|
|
28
39
|
|
|
40
|
+
SdkError({ target })
|
|
41
|
+
|
|
29
42
|
File({ name: model.const.Name + 'SDK.' + target.name }, () => {
|
|
30
43
|
|
|
31
44
|
Line(`// ${model.const.Name} ${target.Name} SDK\n`)
|
|
32
45
|
|
|
33
|
-
List({ item: feature }, ({ item }: any) =>
|
|
34
|
-
Line(`import { ${item.Name + 'Feature'} } ` +
|
|
35
|
-
`from './feature/${item.name}/${item.Name}Feature'`))
|
|
36
|
-
|
|
37
46
|
List({ item: entity }, ({ item }: any) =>
|
|
38
47
|
Line(`import { ${item.Name}Entity } from './entity/${item.Name}Entity'`))
|
|
39
48
|
|
|
@@ -46,11 +55,11 @@ const Main = cmp(async function Main(props: any) {
|
|
|
46
55
|
'#BuildFeatures': ({ indent }: any) => {
|
|
47
56
|
List({ item: feature, line: false }, ({ item }: any) =>
|
|
48
57
|
Line({ indent },
|
|
49
|
-
`
|
|
58
|
+
`featureAdd(this._rootctx, new ${item.Name}Feature())`))
|
|
50
59
|
},
|
|
51
60
|
|
|
52
61
|
'#Feature-Hook': ({ name, indent }: any) => Content({ indent }, `
|
|
53
|
-
fres =
|
|
62
|
+
fres = featureHook(ctx, '${name}')
|
|
54
63
|
if (fres instanceof Promise) { await fres }
|
|
55
64
|
`),
|
|
56
65
|
|
|
@@ -69,8 +78,9 @@ if (fres instanceof Promise) { await fres }
|
|
|
69
78
|
|
|
70
79
|
// Entities
|
|
71
80
|
() => {
|
|
72
|
-
each(entity, (entity:
|
|
73
|
-
const
|
|
81
|
+
each(entity, (entity: ModelEntity) => {
|
|
82
|
+
const entitySDK = getModelPath(model, `main.${KIT}.entity.${entity.name}`)
|
|
83
|
+
const entprops = { target, entity, entitySDK }
|
|
74
84
|
MainEntity(entprops)
|
|
75
85
|
})
|
|
76
86
|
})
|