@voxgig/sdkgen 0.24.0 → 0.26.1
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/FeatureHook.js +2 -1
- package/dist/cmp/FeatureHook.js.map +1 -1
- 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 +8 -8
- package/package.json +8 -6
- package/project/.sdk/model/feature/log.jsonic +2 -2
- package/project/.sdk/model/feature/test.jsonic +7 -2
- package/project/.sdk/model/target/js.jsonic +2 -2
- package/project/.sdk/model/target/ts.jsonic +2 -2
- 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/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 +22 -12
- package/project/.sdk/src/cmp/ts/Package_ts.ts +32 -12
- package/project/.sdk/src/cmp/ts/TestEntity_ts.ts +341 -2
- package/project/.sdk/src/cmp/ts/TestMain_ts.ts +0 -3
- package/project/.sdk/src/cmp/ts/Test_ts.ts +21 -3
- package/project/.sdk/src/cmp/ts/fragment/Config.fragment.ts +38 -5
- 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 +50 -31
- package/project/.sdk/src/cmp/ts/fragment/EntityUpdateOp.fragment.ts +51 -31
- package/project/.sdk/src/cmp/ts/fragment/Main.fragment.ts +70 -34
- 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/ts/src/feature/test/TestFeature.ts +158 -104
- package/project/.sdk/tm/ts/src/types.ts +164 -34
- package/project/.sdk/tm/ts/src/utility/AuthUtility.ts +8 -2
- package/project/.sdk/tm/ts/src/utility/BodyUtility.ts +9 -6
- package/project/.sdk/tm/ts/src/utility/CleanUtility.ts +17 -31
- package/project/.sdk/tm/ts/src/utility/ContextUtility.ts +14 -54
- package/project/.sdk/tm/ts/src/utility/DoneUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ErrorUtility.ts +7 -3
- package/project/.sdk/tm/ts/src/utility/FeaturehookUtility.ts +8 -5
- package/project/.sdk/tm/ts/src/utility/FetcherUtility.ts +18 -2
- package/project/.sdk/tm/ts/src/utility/FindparamUtility.ts +12 -5
- package/project/.sdk/tm/ts/src/utility/FullurlUtility.ts +21 -5
- package/project/.sdk/tm/ts/src/utility/InitfeatureUtility.ts +3 -1
- package/project/.sdk/tm/ts/src/utility/OperationUtility.ts +23 -0
- package/project/.sdk/tm/ts/src/utility/OptionsUtility.ts +25 -3
- package/project/.sdk/tm/ts/src/utility/ParamsUtility.ts +10 -10
- package/project/.sdk/tm/ts/src/utility/PreparePathUtility.ts +18 -0
- package/project/.sdk/tm/ts/src/utility/QueryUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/ReqformUtility.ts +2 -2
- package/project/.sdk/tm/ts/src/utility/RequestUtility.ts +20 -3
- package/project/.sdk/tm/ts/src/utility/ResbasicUtility.ts +1 -1
- package/project/.sdk/tm/ts/src/utility/ResbodyUtility.ts +5 -3
- package/project/.sdk/tm/ts/src/utility/ResformUtility.ts +3 -3
- package/project/.sdk/tm/ts/src/utility/ResheadersUtility.ts +9 -7
- package/project/.sdk/tm/ts/src/utility/ResponseUtility.ts +35 -4
- package/project/.sdk/tm/ts/src/utility/ResultUtility.ts +24 -4
- package/project/.sdk/tm/ts/src/utility/SelectionUtility.ts +78 -0
- package/project/.sdk/tm/ts/src/utility/SpecUtility.ts +34 -27
- package/project/.sdk/tm/ts/src/utility/StructUtility.ts +1117 -509
- package/project/.sdk/tm/ts/src/utility/Utility.ts +10 -8
- package/project/.sdk/tm/ts/test/exists.test.ts +0 -1
- package/project/.sdk/tm/ts/test/runner.ts +12 -10
- package/project/.sdk/tm/ts/test/utility/Custom.test.ts +30 -29
- package/project/.sdk/tm/ts/test/utility/PrimaryUtility.test.ts +53 -47
- 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/FeatureHook.ts +6 -1
- package/src/cmp/Main.ts +4 -0
- 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/OperatorUtility.ts +0 -90
|
@@ -1,81 +1,104 @@
|
|
|
1
1
|
|
|
2
|
-
import
|
|
2
|
+
import { inspect } from 'node:util'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { Context, Feature } from './types'
|
|
5
|
+
|
|
6
|
+
import { config } from './Config'
|
|
5
7
|
import { Utility } from './utility/Utility'
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
import { BaseFeature } from './feature/base/BaseFeature'
|
|
9
11
|
|
|
10
|
-
const utility = new Utility()
|
|
11
12
|
|
|
13
|
+
const stdutil = new Utility()
|
|
12
14
|
|
|
13
|
-
class ProjectNameSDK {
|
|
14
|
-
#options: any
|
|
15
|
-
#utility = utility
|
|
16
15
|
|
|
16
|
+
class ProjectNameSDK {
|
|
17
|
+
_mode: string = 'live'
|
|
18
|
+
_options: any
|
|
19
|
+
_utility = new Utility()
|
|
17
20
|
_features: Feature[]
|
|
18
|
-
|
|
21
|
+
_rootctx: Context
|
|
19
22
|
|
|
20
23
|
constructor(options?: any) {
|
|
21
24
|
|
|
22
|
-
|
|
25
|
+
this._rootctx = this._utility.makeContext({
|
|
23
26
|
client: this,
|
|
24
|
-
utility: this
|
|
25
|
-
config
|
|
27
|
+
utility: this._utility,
|
|
28
|
+
config,
|
|
26
29
|
options,
|
|
30
|
+
shared: new WeakMap()
|
|
27
31
|
})
|
|
28
32
|
|
|
29
|
-
this
|
|
33
|
+
this._options = this._utility.options(this._rootctx)
|
|
34
|
+
|
|
35
|
+
const struct = this._utility.struct
|
|
36
|
+
const getpath = struct.getpath
|
|
37
|
+
const items = struct.items
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
if (true === getpath(this._options.feature, 'test.active')) {
|
|
40
|
+
this._mode = 'test'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this._rootctx.options = this._options
|
|
32
44
|
|
|
33
45
|
this._features = []
|
|
34
46
|
|
|
35
|
-
const addfeature = this
|
|
36
|
-
const initfeature = this
|
|
47
|
+
const addfeature = this._utility.addfeature
|
|
48
|
+
const initfeature = this._utility.initfeature
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
items(this._options.feature, (fitem: [string, any]) => {
|
|
51
|
+
const fname = fitem[0]
|
|
52
|
+
const fopts = fitem[1]
|
|
53
|
+
if (fopts.active) {
|
|
54
|
+
addfeature(this._rootctx, this._rootctx.config.makeFeature(fname))
|
|
55
|
+
}
|
|
56
|
+
})
|
|
39
57
|
|
|
40
|
-
if (null != this
|
|
41
|
-
for (let f of this
|
|
42
|
-
addfeature(
|
|
58
|
+
if (null != this._options.extend) {
|
|
59
|
+
for (let f of this._options.extend) {
|
|
60
|
+
addfeature(this._rootctx, f)
|
|
43
61
|
}
|
|
44
62
|
}
|
|
45
63
|
|
|
46
64
|
for (let f of this._features) {
|
|
47
|
-
initfeature(
|
|
65
|
+
initfeature(this._rootctx, f)
|
|
48
66
|
}
|
|
49
67
|
|
|
50
|
-
const
|
|
51
|
-
|
|
68
|
+
const featureHook = this._utility.featureHook
|
|
69
|
+
featureHook(this._rootctx, 'PostConstruct')
|
|
52
70
|
}
|
|
53
71
|
|
|
54
72
|
|
|
55
73
|
options() {
|
|
56
|
-
return
|
|
74
|
+
return this._utility.struct.clone(this._options)
|
|
57
75
|
}
|
|
58
76
|
|
|
59
77
|
|
|
60
78
|
utility() {
|
|
61
|
-
return
|
|
79
|
+
return this._utility.struct.clone(this._utility)
|
|
62
80
|
}
|
|
63
81
|
|
|
64
82
|
|
|
65
83
|
// <[SLOT]>
|
|
66
84
|
|
|
67
85
|
|
|
68
|
-
static test(
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
86
|
+
static test(testoptsarg?: any, sdkoptsarg?: any) {
|
|
87
|
+
const struct = stdutil.struct
|
|
88
|
+
const setpath = struct.setpath
|
|
89
|
+
const getdef = struct.getdef
|
|
90
|
+
const clone = struct.clone
|
|
91
|
+
const setprop = struct.setprop
|
|
92
|
+
|
|
93
|
+
const sdkopts = getdef(clone(sdkoptsarg), {})
|
|
94
|
+
const testopts = getdef(clone(testoptsarg), {})
|
|
95
|
+
setprop(testopts, 'active', true)
|
|
96
|
+
setpath(sdkopts, 'feature.test', testopts)
|
|
72
97
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
sdkopts.feature.test = testopts || {}
|
|
76
|
-
sdkopts.feature.test.active = true
|
|
98
|
+
const testsdk = new ProjectNameSDK(sdkopts)
|
|
99
|
+
testsdk._mode = 'test'
|
|
77
100
|
|
|
78
|
-
return
|
|
101
|
+
return testsdk
|
|
79
102
|
}
|
|
80
103
|
|
|
81
104
|
|
|
@@ -83,6 +106,19 @@ class ProjectNameSDK {
|
|
|
83
106
|
return ProjectNameSDK.test(testopts, sdkopts)
|
|
84
107
|
}
|
|
85
108
|
|
|
109
|
+
|
|
110
|
+
toJSON() {
|
|
111
|
+
return { name: 'ProjectName' }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
toString() {
|
|
115
|
+
return 'ProjectName ' + this._utility.struct.jsonify(this.toJSON())
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[inspect.custom]() {
|
|
119
|
+
return this.toString()
|
|
120
|
+
}
|
|
121
|
+
|
|
86
122
|
}
|
|
87
123
|
|
|
88
124
|
|
|
@@ -91,11 +127,11 @@ class ProjectNameEntity {
|
|
|
91
127
|
}
|
|
92
128
|
|
|
93
129
|
|
|
94
|
-
|
|
95
130
|
const SDK = ProjectNameSDK
|
|
96
131
|
|
|
132
|
+
|
|
97
133
|
export {
|
|
98
|
-
|
|
134
|
+
stdutil,
|
|
99
135
|
|
|
100
136
|
BaseFeature,
|
|
101
137
|
ProjectNameEntity,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"esModuleInterop": true,
|
|
4
|
+
"module": "nodenext",
|
|
5
|
+
"noEmitOnError": true,
|
|
6
|
+
"outDir":"../dist",
|
|
7
|
+
"rootDir":".",
|
|
8
|
+
"resolveJsonModule": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"strict": true,
|
|
11
|
+
"target": "es2022",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"declarationDir": "../dist"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,10 +1,64 @@
|
|
|
1
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
|
+
|
|
2
16
|
function formatJSONSrc(jsonsrc: string) {
|
|
3
17
|
return jsonsrc
|
|
4
18
|
.replace(/([{:\[,])/g, '$1 ')
|
|
5
19
|
.replace(/([}\]])/g, ' $1')
|
|
6
20
|
}
|
|
7
21
|
|
|
22
|
+
|
|
23
|
+
function formatJson(obj: any, flags?: { line?: boolean, margin?: number }): string {
|
|
24
|
+
const marginSize = flags?.margin ?? 0
|
|
25
|
+
const marginStr = ' '.repeat(marginSize)
|
|
26
|
+
|
|
27
|
+
let json: string
|
|
28
|
+
|
|
29
|
+
if (flags?.line) {
|
|
30
|
+
// One line with spaces for clarity
|
|
31
|
+
json = JSON.stringify(obj)
|
|
32
|
+
.replace(/([{:\[,])/g, '$1 ')
|
|
33
|
+
.replace(/([}\]])/g, ' $1')
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Pretty printed with 2-space indentation
|
|
37
|
+
json = JSON.stringify(obj, null, 2)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Add margin to the left of every line
|
|
41
|
+
if (marginSize > 0) {
|
|
42
|
+
json = json.split('\n').map(line => marginStr + line).join('\n')
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return json
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
function clean(o: any) {
|
|
50
|
+
return walk(clone(o), (k: any, v: any, p: any) => {
|
|
51
|
+
if (null != k && k.endsWith('$')) {
|
|
52
|
+
delete p[k]
|
|
53
|
+
}
|
|
54
|
+
return v
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
8
59
|
export {
|
|
9
|
-
|
|
60
|
+
clean,
|
|
61
|
+
formatJSONSrc,
|
|
62
|
+
formatJson,
|
|
63
|
+
projectPath,
|
|
10
64
|
}
|
|
@@ -5,6 +5,9 @@ import type { ProjectNameSDK } from '../../ProjectNameSDK'
|
|
|
5
5
|
import { BaseFeature } from '../base/BaseFeature'
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
const S_NOT_FOUND = 'Not found'
|
|
9
|
+
|
|
10
|
+
|
|
8
11
|
class TestFeature extends BaseFeature {
|
|
9
12
|
version = '0.0.1'
|
|
10
13
|
name = 'test'
|
|
@@ -18,137 +21,188 @@ class TestFeature extends BaseFeature {
|
|
|
18
21
|
this._client = ctx.client
|
|
19
22
|
this._options = options
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
24
|
+
const struct = ctx.utility.struct
|
|
25
|
+
const walk = struct.walk
|
|
26
|
+
const size = struct.size
|
|
27
|
+
const setprop = struct.setprop
|
|
25
28
|
|
|
26
29
|
const entity = this._options.entity
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
this._client._mode = 'test'
|
|
32
|
+
|
|
33
|
+
// Ensure entity ids are correct.
|
|
34
|
+
walk(entity, (k: any, v: any, _parent: any, path: any) => {
|
|
30
35
|
if (2 === size(path)) {
|
|
31
36
|
setprop(v, 'id', k)
|
|
32
37
|
}
|
|
33
38
|
return v
|
|
34
39
|
})
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
41
|
+
const self = this
|
|
42
|
+
|
|
43
|
+
function testFetcher(ctx: any, _fullurl: string, _fetchdef: any) {
|
|
44
|
+
const struct = ctx.utility.struct
|
|
45
|
+
const findparam = ctx.utility.findparam
|
|
46
|
+
|
|
47
|
+
const getprop = struct.getprop
|
|
48
|
+
const clone = struct.clone
|
|
49
|
+
const merge = struct.merge
|
|
50
|
+
const getelem = struct.getelem
|
|
51
|
+
const select = struct.select
|
|
52
|
+
const delprop = struct.delprop
|
|
53
|
+
const getdef = struct.getdef
|
|
54
|
+
|
|
55
|
+
function respond(status: number, data?: any, res?: any) {
|
|
56
|
+
const out = merge([
|
|
57
|
+
{
|
|
58
|
+
status,
|
|
59
|
+
statusText: 'OK',
|
|
60
|
+
json: async () => data,
|
|
61
|
+
body: 'not-used',
|
|
62
|
+
},
|
|
63
|
+
getdef(res, {})
|
|
64
|
+
])
|
|
65
|
+
|
|
66
|
+
const headers: any = getprop(out, 'headers', {})
|
|
67
|
+
|
|
68
|
+
// JS specific iterator.
|
|
69
|
+
out.headers = {
|
|
70
|
+
forEach(callback: any) {
|
|
71
|
+
Object.keys(headers).forEach((key) => {
|
|
72
|
+
callback(headers[key], key, this)
|
|
73
|
+
})
|
|
59
74
|
}
|
|
60
|
-
|
|
61
|
-
return out
|
|
62
75
|
}
|
|
63
76
|
|
|
77
|
+
return out
|
|
78
|
+
}
|
|
64
79
|
|
|
65
|
-
const op = ctx.op
|
|
66
|
-
const entmap = entity[op.entity]
|
|
67
|
-
|
|
68
|
-
const qand: any[] = []
|
|
69
|
-
const q = { '`$AND`': qand }
|
|
70
|
-
|
|
71
|
-
for (let k of keysof(ctx.reqmatch)) {
|
|
72
|
-
const v = findparam(ctx, k)
|
|
73
|
-
const ka = getprop(op.alias, k)
|
|
74
|
-
|
|
75
|
-
let qor: any = [{ [k]: v }]
|
|
76
|
-
if (null != ka) {
|
|
77
|
-
qor.push({ [ka]: v })
|
|
78
|
-
}
|
|
79
80
|
|
|
80
|
-
|
|
81
|
+
const op = ctx.op
|
|
82
|
+
const entmap = getprop(entity, op.entity, {})
|
|
81
83
|
|
|
82
|
-
|
|
84
|
+
if ('load' === op.name) {
|
|
85
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
86
|
+
const found = select(entmap, args)
|
|
87
|
+
const ent = getelem(found, 0)
|
|
88
|
+
if (null == ent) {
|
|
89
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
83
90
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
else {
|
|
92
|
+
delprop(ent, '$KEY')
|
|
93
|
+
const out = clone(ent)
|
|
94
|
+
return respond(200, out)
|
|
87
95
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
delprop(ent, '$KEY')
|
|
97
|
-
return respond(200, clone(ent))
|
|
98
|
-
}
|
|
96
|
+
}
|
|
97
|
+
else if ('list' === op.name) {
|
|
98
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
99
|
+
const found = select(entmap, args)
|
|
100
|
+
if (null == found) {
|
|
101
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
99
102
|
}
|
|
100
|
-
else
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
found.map((ent: any) => delprop(ent, '$KEY'))
|
|
107
|
-
return respond(200, clone(found))
|
|
108
|
-
}
|
|
103
|
+
else {
|
|
104
|
+
found.map((ent: any) => delprop(ent, '$KEY'))
|
|
105
|
+
const out = clone(found)
|
|
106
|
+
return respond(200, out)
|
|
109
107
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
merge([ent, (ctx.reqdata || {})])
|
|
118
|
-
delprop(ent, '$KEY')
|
|
119
|
-
return respond(200, clone(ent))
|
|
120
|
-
}
|
|
108
|
+
}
|
|
109
|
+
else if ('update' === op.name) {
|
|
110
|
+
const args = self.buildArgs(ctx, op, ctx.reqdata)
|
|
111
|
+
const found = select(entmap, args)
|
|
112
|
+
const ent = getelem(found, 0)
|
|
113
|
+
if (null == ent) {
|
|
114
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
121
115
|
}
|
|
122
|
-
else
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
delprop(entmap, getprop(ent, 'id'))
|
|
130
|
-
return respond(200)
|
|
131
|
-
}
|
|
116
|
+
else {
|
|
117
|
+
merge([ent, (ctx.reqdata || {})])
|
|
118
|
+
delprop(ent, '$KEY')
|
|
119
|
+
const out = clone(ent)
|
|
120
|
+
return respond(200, out)
|
|
132
121
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
}
|
|
123
|
+
else if ('remove' === op.name) {
|
|
124
|
+
const args = self.buildArgs(ctx, op, ctx.reqmatch)
|
|
125
|
+
const found = select(entmap, args)
|
|
126
|
+
const ent = getelem(found, 0)
|
|
127
|
+
if (null == ent) {
|
|
128
|
+
return respond(404, undefined, { statusText: S_NOT_FOUND })
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
delprop(entmap, getprop(ent, 'id'))
|
|
132
|
+
return respond(200)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if ('create' === op.name) {
|
|
136
|
+
const args = self.buildArgs(ctx, op, ctx.reqdata)
|
|
137
|
+
let id = findparam(ctx, 'id')
|
|
138
|
+
if (null == id) {
|
|
139
|
+
id = ((1e4 * Math.random() | 0).toString(16) +
|
|
140
|
+
(1e4 * Math.random() | 0).toString(16) +
|
|
141
|
+
(1e4 * Math.random() | 0).toString(16) +
|
|
142
|
+
(1e4 * Math.random() | 0).toString(16)).padEnd(16, '0')
|
|
145
143
|
}
|
|
144
|
+
|
|
145
|
+
const ent = clone(ctx.reqdata)
|
|
146
|
+
setprop(ent, 'id', id)
|
|
147
|
+
setprop(entmap, id, ent)
|
|
148
|
+
delprop(ent, '$KEY')
|
|
149
|
+
const out = clone(ent)
|
|
150
|
+
return respond(200, out)
|
|
146
151
|
}
|
|
147
152
|
}
|
|
153
|
+
|
|
154
|
+
ctx.utility.fetcher = testFetcher
|
|
148
155
|
}
|
|
149
|
-
}
|
|
150
156
|
|
|
151
157
|
|
|
158
|
+
buildArgs(ctx: any, op: any, args: any): any {
|
|
159
|
+
const struct = ctx.utility.struct
|
|
160
|
+
const findparam = ctx.utility.findparam
|
|
161
|
+
|
|
162
|
+
const getprop = struct.getprop
|
|
163
|
+
const keysof = struct.keysof
|
|
164
|
+
const getpath = struct.getpath
|
|
165
|
+
const getelem = struct.getelem
|
|
166
|
+
const select = struct.select
|
|
167
|
+
const transform = struct.transform
|
|
168
|
+
const isempty = struct.isempty
|
|
169
|
+
|
|
170
|
+
const opname = getprop(op, 'name')
|
|
171
|
+
const alt =
|
|
172
|
+
getelem(getpath(ctx.config, [
|
|
173
|
+
'entity', getprop(ctx.entity, 'name'), 'op', opname, 'alts']), -1)
|
|
174
|
+
|
|
175
|
+
const reqd = transform(
|
|
176
|
+
select(getpath(alt, ['args', 'param']), { reqd: true }),
|
|
177
|
+
['`$EACH`', '', '`$KEY.name`']
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
const qand: any[] = []
|
|
181
|
+
const q = { '`$AND`': qand }
|
|
182
|
+
|
|
183
|
+
for (let k of keysof(args)) {
|
|
184
|
+
if ('id' === k || !isempty(select(reqd, k))) {
|
|
185
|
+
const v = findparam(ctx, k)
|
|
186
|
+
const ka = getprop(op.alias, k)
|
|
187
|
+
|
|
188
|
+
let qor: any = [{ [k]: v }]
|
|
189
|
+
if (null != ka) {
|
|
190
|
+
qor.push({ [ka]: v })
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
qor = { '`$OR`': qor }
|
|
194
|
+
|
|
195
|
+
qand.push(qor)
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if (ctx.ctrl.explain) {
|
|
200
|
+
ctx.ctrl.explain.test = { query: q }
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return q
|
|
204
|
+
}
|
|
205
|
+
}
|
|
152
206
|
|
|
153
207
|
|
|
154
208
|
export {
|