@voxgig/create-sdkgen 0.0.3 → 0.0.5
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/run-create-sdkgen.js +73 -12
- package/dist/create-sdkgen.d.ts +5 -2
- package/dist/create-sdkgen.js +10 -2
- package/dist/create-sdkgen.js.map +1 -1
- package/dist/standard/ModelSdk.js +21 -14
- package/dist/standard/ModelSdk.js.map +1 -1
- package/dist/standard/Root.js +13 -47
- package/dist/standard/Root.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/src/create-sdkgen.ts +21 -4
- package/src/standard/ModelSdk.ts +30 -15
- package/src/standard/Root.ts +15 -54
- package/tm/standard/build/doc.js +23 -0
- package/tm/standard/build/sdk.js +2 -5
- package/tm/standard/def/DEFINITION.md +3 -1
- package/tm/standard/model/.model-config/model-config.jsonic +3 -1
- package/tm/standard/model/go.jsonic +1 -1
- package/tm/standard/model/js.jsonic +1 -1
- package/tm/standard/model/php.jsonic +1 -1
- package/tm/standard/model/py.jsonic +1 -1
- package/tm/standard/model/rb.jsonic +1 -1
- package/tm/standard/package.json +6 -5
- package/tm/standard/src/DocStaticRoot.ts +32 -0
- package/tm/standard/src/Root.ts +9 -7
- package/tm/standard/src/js/Entity_js.ts +91 -30
- package/tm/standard/src/js/Main_js.ts +34 -8
- package/tm/standard/src/js/Quick_js.ts +21 -12
- package/src/standard/ModelSdk.ts~ +0 -1
- package/src/standard/Root.ts~ +0 -3
- package/tm/standard/model/sdk.jsonic.off +0 -60
package/bin/run-create-sdkgen.js
CHANGED
|
@@ -5,6 +5,8 @@ const { statSync } = require('node:fs')
|
|
|
5
5
|
const { parseArgs } = require('node:util')
|
|
6
6
|
|
|
7
7
|
const { Gubu, Fault } = require('gubu')
|
|
8
|
+
const { Aontu, Context } = require('aontu')
|
|
9
|
+
|
|
8
10
|
|
|
9
11
|
const Pkg = require('../package.json')
|
|
10
12
|
|
|
@@ -63,18 +65,8 @@ function generate(options) {
|
|
|
63
65
|
})
|
|
64
66
|
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const model = {
|
|
69
|
-
name: options.name,
|
|
70
|
-
year: new Date().getFullYear(),
|
|
71
|
-
def: {
|
|
72
|
-
filepath: options.def || 'def.yml'
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
model.def.filename = Path.basename(model.def.filepath)
|
|
77
|
-
|
|
68
|
+
const model = resolveModel(options)
|
|
69
|
+
|
|
78
70
|
const spec = {
|
|
79
71
|
// TODO: move to CreateSdkGen options
|
|
80
72
|
spec: options.spec,
|
|
@@ -85,6 +77,8 @@ function generate(options) {
|
|
|
85
77
|
if(options.watch) {
|
|
86
78
|
spec.watch = [
|
|
87
79
|
'../tm',
|
|
80
|
+
'../feature',
|
|
81
|
+
'../def',
|
|
88
82
|
'../dist',
|
|
89
83
|
]
|
|
90
84
|
createSdkGen.watch(spec)
|
|
@@ -96,6 +90,57 @@ function generate(options) {
|
|
|
96
90
|
}
|
|
97
91
|
|
|
98
92
|
|
|
93
|
+
function resolveModel(options) {
|
|
94
|
+
|
|
95
|
+
const typespec = `
|
|
96
|
+
name: string
|
|
97
|
+
year: number
|
|
98
|
+
def: filepath: string
|
|
99
|
+
feature: &: {
|
|
100
|
+
active: *false | boolean
|
|
101
|
+
}
|
|
102
|
+
`
|
|
103
|
+
|
|
104
|
+
const features = options.feature.map(name=>`feature:${name}:active:true`)
|
|
105
|
+
|
|
106
|
+
const src = [
|
|
107
|
+
typespec,
|
|
108
|
+
`name: ${options.name}`,
|
|
109
|
+
`year: ${new Date().getFullYear()}`,
|
|
110
|
+
`def: filepath: "${options.def || 'def.yml'}"`,
|
|
111
|
+
'' === options.model ? '' : `@"${options.model}"`,
|
|
112
|
+
...(options.set||[]),
|
|
113
|
+
...(features||[]),
|
|
114
|
+
].join('\n')
|
|
115
|
+
const aopts = {}
|
|
116
|
+
const root = Aontu(src, aopts)
|
|
117
|
+
const hasErr = root.err && 0 < root.err.length
|
|
118
|
+
|
|
119
|
+
// TODO: collect all errors
|
|
120
|
+
if (hasErr) {
|
|
121
|
+
// console.log('ERROR ROOT', root.err)
|
|
122
|
+
throw root.err[0].msg
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
let genctx = new Context({ root })
|
|
126
|
+
const model = root.gen(genctx)
|
|
127
|
+
|
|
128
|
+
// TODO: collect all errors
|
|
129
|
+
if (genctx.err && 0 < genctx.err.length) {
|
|
130
|
+
// console.log(genctx.err)
|
|
131
|
+
// console.log('ERROR GEN', genctx.err)
|
|
132
|
+
throw new Error(JSON.stringify(genctx.err[0]))
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
model.def.filename = Path.basename(model.def.filepath)
|
|
136
|
+
|
|
137
|
+
// console.log('MODEL')
|
|
138
|
+
// console.dir(model,{depth:null})
|
|
139
|
+
|
|
140
|
+
return model
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
99
144
|
function resolveOptions() {
|
|
100
145
|
|
|
101
146
|
const args = parseArgs({
|
|
@@ -113,12 +158,24 @@ function resolveOptions() {
|
|
|
113
158
|
default: '',
|
|
114
159
|
},
|
|
115
160
|
|
|
161
|
+
set: {
|
|
162
|
+
type: 'string',
|
|
163
|
+
short: 's',
|
|
164
|
+
multiple: true,
|
|
165
|
+
},
|
|
166
|
+
|
|
116
167
|
model: {
|
|
117
168
|
type: 'string',
|
|
118
169
|
short: 'm',
|
|
119
170
|
default: '',
|
|
120
171
|
},
|
|
121
172
|
|
|
173
|
+
feature: {
|
|
174
|
+
type: 'string',
|
|
175
|
+
short: 't',
|
|
176
|
+
multiple: true,
|
|
177
|
+
},
|
|
178
|
+
|
|
122
179
|
watch: {
|
|
123
180
|
type: 'boolean',
|
|
124
181
|
short: 'w',
|
|
@@ -147,6 +204,8 @@ function resolveOptions() {
|
|
|
147
204
|
folder: '' === args.values.folder ? args.positionals[0] : args.values.folder,
|
|
148
205
|
def: args.values.def,
|
|
149
206
|
model: args.values.model,
|
|
207
|
+
feature: args.values.feature,
|
|
208
|
+
set: args.values.set,
|
|
150
209
|
watch: !!args.values.watch,
|
|
151
210
|
debug: !!args.values.debug,
|
|
152
211
|
help: !!args.values.help,
|
|
@@ -163,6 +222,8 @@ function validateOptions(rawOptions) {
|
|
|
163
222
|
folder: String,
|
|
164
223
|
def: '',
|
|
165
224
|
model: '',
|
|
225
|
+
feature: [String],
|
|
226
|
+
set: [String],
|
|
166
227
|
watch: Boolean,
|
|
167
228
|
debug: Boolean,
|
|
168
229
|
help: Boolean,
|
package/dist/create-sdkgen.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ type FullCreateSdkGenOptions = {
|
|
|
6
6
|
rootpath: string;
|
|
7
7
|
};
|
|
8
8
|
type CreateSdkGenOptions = Partial<FullCreateSdkGenOptions>;
|
|
9
|
-
|
|
9
|
+
type GenerateSpec = {
|
|
10
|
+
watch: string[];
|
|
11
|
+
};
|
|
12
|
+
declare function CreateSdkGen(opts: FullCreateSdkGenOptions): {
|
|
10
13
|
generate: (spec: any) => Promise<void>;
|
|
11
|
-
watch: (spec:
|
|
14
|
+
watch: (spec: GenerateSpec) => Promise<void>;
|
|
12
15
|
};
|
|
13
16
|
export type { CreateSdkGenOptions, };
|
|
14
17
|
export { CreateSdkGen, };
|
package/dist/create-sdkgen.js
CHANGED
|
@@ -28,18 +28,20 @@ exports.CreateSdkGen = CreateSdkGen;
|
|
|
28
28
|
const Fs = __importStar(require("node:fs"));
|
|
29
29
|
const chokidar_1 = require("chokidar");
|
|
30
30
|
const JostracaModule = __importStar(require("jostraca"));
|
|
31
|
-
const { Jostraca } = JostracaModule;
|
|
31
|
+
const { each, names, Jostraca } = JostracaModule;
|
|
32
32
|
function CreateSdkGen(opts) {
|
|
33
33
|
const fs = opts.fs || Fs;
|
|
34
34
|
const folder = opts.folder || '.';
|
|
35
35
|
const jostraca = Jostraca();
|
|
36
36
|
const rootpath = opts.rootpath;
|
|
37
37
|
async function generate(spec) {
|
|
38
|
-
|
|
38
|
+
const now = Date.now();
|
|
39
|
+
// console.log('CREATE SDK', now, new Date(now), spec)
|
|
39
40
|
const { model } = spec;
|
|
40
41
|
const ctx$ = { fs, folder, meta: { spec } };
|
|
41
42
|
clear();
|
|
42
43
|
const { Root } = require(rootpath);
|
|
44
|
+
completeModel(model);
|
|
43
45
|
try {
|
|
44
46
|
await jostraca.generate(ctx$, () => Root({ model }));
|
|
45
47
|
}
|
|
@@ -76,6 +78,12 @@ function CreateSdkGen(opts) {
|
|
|
76
78
|
watch,
|
|
77
79
|
};
|
|
78
80
|
}
|
|
81
|
+
function completeModel(model) {
|
|
82
|
+
names(model, model.name);
|
|
83
|
+
each(model.feature, (feature) => {
|
|
84
|
+
names(feature, feature.key$);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
79
87
|
// Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
|
|
80
88
|
function clearRequire(path) {
|
|
81
89
|
let filePath = require.resolve(path);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-sdkgen.js","sourceRoot":"","sources":["../src/create-sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"create-sdkgen.js","sourceRoot":"","sources":["../src/create-sdkgen.ts"],"names":[],"mappings":";AAAA,oDAAoD;;;;;;;;;;;;;;;;;;;;;;;;;AAgJlD,oCAAY;AA9Id,4CAA6B;AAE7B,uCAAoC;AAEpC,yDAA0C;AAoB1C,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,cAAc,CAAA;AAGhD,SAAS,YAAY,CAAC,IAA6B;IACjD,MAAM,EAAE,GAAG,IAAI,CAAC,EAAE,IAAI,EAAE,CAAA;IACxB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,GAAG,CAAA;IACjC,MAAM,QAAQ,GAAG,QAAQ,EAAE,CAA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AK,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC;QAC9D,IAAI,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAA;QAEtD,OAAO,CAAC,EAAE,EAAE,CAAC;YACX,IAAI,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,QAAQ,EAAE,CAAC;gBAC/D,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;YACtD,CAAC;QACH,CAAC;IACH,CAAC;AAEH,CAAC"}
|
|
@@ -9,6 +9,9 @@ const ModelSdk = (0, jostraca_1.cmp)(function ModelSdk(props) {
|
|
|
9
9
|
// const def = ctx$.fs.readFileSync(model.def.filepath)
|
|
10
10
|
(0, jostraca_1.File)({ name: 'sdk.jsonic' }, () => {
|
|
11
11
|
(0, jostraca_1.Content)(`
|
|
12
|
+
|
|
13
|
+
@"../node_modules/@voxgig/sdkgen/model/sdkgen.jsonic"
|
|
14
|
+
|
|
12
15
|
name: '${model.name}'
|
|
13
16
|
|
|
14
17
|
@"api.jsonic"
|
|
@@ -28,26 +31,14 @@ main: sdk: build: go: @"go.jsonic"
|
|
|
28
31
|
|
|
29
32
|
|
|
30
33
|
|
|
31
|
-
main: sdk: test: quick: entity: name:
|
|
34
|
+
main: sdk: test: quick: entity: name: foo
|
|
32
35
|
|
|
33
36
|
|
|
34
37
|
main: sdk: entity: $.main.api.entity
|
|
35
38
|
|
|
36
39
|
|
|
37
|
-
main: sdk: entity: &: {
|
|
38
|
-
name: .$KEY
|
|
39
|
-
publish: *true | boolean
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
main: sdk: options: &: {
|
|
45
|
-
name: .$KEY
|
|
46
|
-
publish: *true | boolean
|
|
47
|
-
}
|
|
48
|
-
|
|
49
40
|
|
|
50
|
-
main: sdk:
|
|
41
|
+
main: sdk: option: {
|
|
51
42
|
|
|
52
43
|
endpoint: {
|
|
53
44
|
kind: *String | string
|
|
@@ -65,6 +56,22 @@ main: sdk: options: {
|
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
58
|
`);
|
|
59
|
+
(0, jostraca_1.each)(model.feature).filter((feature) => feature.active).map((feature) => {
|
|
60
|
+
(0, jostraca_1.Content)(`
|
|
61
|
+
main: sdk: feature: ${feature.name}: {
|
|
62
|
+
active: true
|
|
63
|
+
config: {
|
|
64
|
+
`);
|
|
65
|
+
(0, jostraca_1.Fragment)({
|
|
66
|
+
from: `${__dirname}/../../feature/standard/${feature.name}/${feature.name}-config.jsonic`,
|
|
67
|
+
indent: ' '
|
|
68
|
+
});
|
|
69
|
+
(0, jostraca_1.Content)(`
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
`);
|
|
74
|
+
});
|
|
68
75
|
});
|
|
69
76
|
});
|
|
70
77
|
exports.ModelSdk = ModelSdk;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ModelSdk.js","sourceRoot":"","sources":["../../src/standard/ModelSdk.ts"],"names":[],"mappings":";;;AACA,uCAWiB;AAIjB,MAAM,QAAQ,GAAG,IAAA,cAAG,EAAC,SAAS,QAAQ,CAAC,KAAU;IAC/C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,CAAA;IAGvC,mCAAmC;IAEnC,mBAAmB;IACnB,uDAAuD;IAGvD,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;QAChC,IAAA,kBAAO,EAAC
|
|
1
|
+
{"version":3,"file":"ModelSdk.js","sourceRoot":"","sources":["../../src/standard/ModelSdk.ts"],"names":[],"mappings":";;;AACA,uCAWiB;AAIjB,MAAM,QAAQ,GAAG,IAAA,cAAG,EAAC,SAAS,QAAQ,CAAC,KAAU;IAC/C,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,EAAE,GAAG,KAAK,CAAA;IAGvC,mCAAmC;IAEnC,mBAAmB;IACnB,uDAAuD;IAGvD,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,GAAG,EAAE;QAChC,IAAA,kBAAO,EAAC;;;;SAIH,KAAK,CAAC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA8BL,KAAK,CAAC,IAAI;;;;;cAKV,KAAK,CAAC,IAAI;;;;;;;;CAQvB,CAAC,CAAA;QAGE,IAAA,eAAI,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,OAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE;YAEhF,IAAA,kBAAO,EACL;sBACc,OAAO,CAAC,IAAI;;;CAGjC,CAAC,CAAA;YAEI,IAAA,mBAAQ,EAAC;gBACP,IAAI,EACF,GAAG,SAAS,2BAA2B,OAAO,CAAC,IAAI,IAAI,OAAO,CAAC,IAAI,gBAAgB;gBACrF,MAAM,EAAE,MAAM;aACf,CAAC,CAAA;YAEF,IAAA,kBAAO,EAAC;;;;CAIb,CAAC,CAAA;QACE,CAAC,CAAC,CAAA;IAEJ,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAC,CAAA;AAIA,4BAAQ"}
|
package/dist/standard/Root.js
CHANGED
|
@@ -7,70 +7,36 @@ exports.Root = void 0;
|
|
|
7
7
|
const node_path_1 = __importDefault(require("node:path"));
|
|
8
8
|
const jostraca_1 = require("jostraca");
|
|
9
9
|
const ModelSdk_1 = require("./ModelSdk");
|
|
10
|
+
// TODO: rename to RootSdk
|
|
10
11
|
const Root = (0, jostraca_1.cmp)(function Root(props) {
|
|
11
12
|
const { model, ctx$ } = props;
|
|
12
13
|
const { folder, meta } = ctx$;
|
|
13
14
|
const { spec } = meta;
|
|
14
|
-
|
|
15
|
-
// console.log('SPEC', spec)
|
|
16
|
-
(0, jostraca_1.names)(model, model.name);
|
|
17
|
-
// console.log('MODEL')
|
|
18
|
-
// console.dir(model, { depth: null })
|
|
15
|
+
// names(model, model.name)
|
|
19
16
|
ctx$.model = model;
|
|
20
|
-
/*
|
|
21
|
-
let createInfo = { exclude: [], last: Number.MAX_SAFE_INTEGER }
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
createInfo = JSON.parse(ctx$.fs.readFileSync(
|
|
26
|
-
Path.join(folder, '.voxgig', 'create-sdkgen.json'), 'utf8'))
|
|
27
|
-
}
|
|
28
|
-
catch (err: any) {
|
|
29
|
-
console.log(err)
|
|
30
|
-
// TODO: file not foound ignored, handle others!
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
ctx$.info = createInfo
|
|
34
|
-
|
|
35
|
-
console.log('INFO', ctx$.info)
|
|
36
|
-
*/
|
|
37
17
|
(0, jostraca_1.Project)({ folder }, () => {
|
|
38
|
-
// TODO: perhaps remove the need for this, create top level folder in Project
|
|
39
|
-
// would keep paths indo of project folder name
|
|
40
|
-
// Folder({ name: Path.basename(folder) }, () => {
|
|
41
|
-
// File({ name: 'foo.txt' }, () => {
|
|
42
|
-
// Content('FOO')
|
|
43
|
-
// })
|
|
44
18
|
// console.log('FOLDER', folder)
|
|
45
|
-
(0, jostraca_1.Copy)({
|
|
19
|
+
(0, jostraca_1.Copy)({
|
|
20
|
+
from: __dirname + '/../../tm/standard',
|
|
21
|
+
exclude: ['.env.local']
|
|
22
|
+
});
|
|
46
23
|
const def = model.def.filepath;
|
|
47
24
|
if (null != def && '' !== def) {
|
|
48
25
|
(0, jostraca_1.Folder)({ name: 'def' }, () => {
|
|
49
26
|
(0, jostraca_1.Copy)({ from: def, name: node_path_1.default.basename(def) });
|
|
50
27
|
});
|
|
51
28
|
}
|
|
52
|
-
(0, jostraca_1.Folder)({ name: '.voxgig' }, () => { });
|
|
53
29
|
(0, jostraca_1.Folder)({ name: 'model' }, () => {
|
|
54
30
|
(0, ModelSdk_1.ModelSdk)({});
|
|
55
31
|
});
|
|
32
|
+
(0, jostraca_1.Folder)({ name: 'feature' }, () => {
|
|
33
|
+
(0, jostraca_1.each)(model.feature).map((feature) => {
|
|
34
|
+
(0, jostraca_1.Folder)({ name: feature.name }, () => {
|
|
35
|
+
(0, jostraca_1.Copy)({ from: __dirname + '/../../feature/standard/' + feature.name });
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
});
|
|
56
39
|
});
|
|
57
|
-
/*
|
|
58
|
-
// TODO: need mechanism to ensure this is last
|
|
59
|
-
setTimeout(() => {
|
|
60
|
-
try {
|
|
61
|
-
const info = {
|
|
62
|
-
last: Date.now(),
|
|
63
|
-
exclude: ctx$.info.exclude,
|
|
64
|
-
}
|
|
65
|
-
ctx$.fs.writeFileSync(Path.join(folder, '.voxgig', 'create-sdkgen.json'),
|
|
66
|
-
JSON.stringify(info, null, 2))
|
|
67
|
-
}
|
|
68
|
-
catch (err: any) {
|
|
69
|
-
console.log(err)
|
|
70
|
-
// TODO: file not foound ignored, handle others!
|
|
71
|
-
}
|
|
72
|
-
}, 777)
|
|
73
|
-
*/
|
|
74
40
|
});
|
|
75
41
|
exports.Root = Root;
|
|
76
42
|
//# sourceMappingURL=Root.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Root.js","sourceRoot":"","sources":["../../src/standard/Root.ts"],"names":[],"mappings":";;;;;;AAEA,0DAA4B;AAG5B,uCAWiB;AAGjB,yCAAqC;AAGrC,MAAM,IAAI,GAAG,IAAA,cAAG,EAAC,SAAS,IAAI,CAAC,KAAU;IACvC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAA;IAE7B,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAA;I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AAE,SAAS,EAAE,EAAE,GAAG,EAAE;YAC/B,IAAA,eAAI,EAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,OAAY,EAAE,EAAE;gBACvC,IAAA,iBAAM,EAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,EAAE,GAAG,EAAE;oBAClC,IAAA,eAAI,EAAC,EAAE,IAAI,EAAE,SAAS,GAAG,0BAA0B,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC,CAAA;gBACvE,CAAC,CAAC,CAAA;YACJ,CAAC,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IAEJ,CAAC,CAAC,CAAA;AAEJ,CAAC,CAAC,CAAA;AAIA,oBAAI"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/create-sdkgen.ts","../src/utility.ts","../src/standard/modelsdk.ts","../src/standard/root.ts"],"version":"5.6.
|
|
1
|
+
{"root":["../src/create-sdkgen.ts","../src/utility.ts","../src/standard/modelsdk.ts","../src/standard/root.ts"],"version":"5.6.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voxgig/create-sdkgen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"main": "dist/create-sdkgen.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"types": "dist/create-sdkgen.d.ts",
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
],
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@hapi/code": "^9.0.3",
|
|
43
|
-
"@types/node": "22.
|
|
44
|
-
"esbuild": "^0.
|
|
45
|
-
"memfs": "^4.
|
|
46
|
-
"typescript": "^5.6.
|
|
43
|
+
"@types/node": "22.7.6",
|
|
44
|
+
"esbuild": "^0.24.0",
|
|
45
|
+
"memfs": "^4.14.0",
|
|
46
|
+
"typescript": "^5.6.3"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"aontu": "^0.22.0",
|
|
50
|
-
"chokidar": "^4.0.
|
|
50
|
+
"chokidar": "^4.0.1",
|
|
51
51
|
"gubu": "^8.3.0",
|
|
52
|
-
"jostraca": "^0.
|
|
52
|
+
"jostraca": "^0.7.7"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/create-sdkgen.ts
CHANGED
|
@@ -19,17 +19,23 @@ type FullCreateSdkGenOptions = {
|
|
|
19
19
|
type CreateSdkGenOptions = Partial<FullCreateSdkGenOptions>
|
|
20
20
|
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
type GenerateSpec = {
|
|
23
|
+
watch: string[]
|
|
24
|
+
}
|
|
25
|
+
|
|
23
26
|
|
|
27
|
+
const { each, names, Jostraca } = JostracaModule
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
|
|
30
|
+
function CreateSdkGen(opts: FullCreateSdkGenOptions) {
|
|
26
31
|
const fs = opts.fs || Fs
|
|
27
32
|
const folder = opts.folder || '.'
|
|
28
33
|
const jostraca = Jostraca()
|
|
29
34
|
const rootpath = opts.rootpath as string
|
|
30
35
|
|
|
31
36
|
async function generate(spec: any) {
|
|
32
|
-
|
|
37
|
+
const now = Date.now()
|
|
38
|
+
// console.log('CREATE SDK', now, new Date(now), spec)
|
|
33
39
|
|
|
34
40
|
const { model } = spec
|
|
35
41
|
|
|
@@ -38,6 +44,8 @@ function CreateSdkGen(opts: CreateSdkGenOptions) {
|
|
|
38
44
|
clear()
|
|
39
45
|
const { Root } = require(rootpath)
|
|
40
46
|
|
|
47
|
+
completeModel(model)
|
|
48
|
+
|
|
41
49
|
try {
|
|
42
50
|
await jostraca.generate(ctx$, () => Root({ model }))
|
|
43
51
|
}
|
|
@@ -48,7 +56,7 @@ function CreateSdkGen(opts: CreateSdkGenOptions) {
|
|
|
48
56
|
}
|
|
49
57
|
|
|
50
58
|
|
|
51
|
-
async function watch(spec:
|
|
59
|
+
async function watch(spec: GenerateSpec) {
|
|
52
60
|
const fsw = new FSWatcher()
|
|
53
61
|
let last_change_time = 0
|
|
54
62
|
|
|
@@ -89,6 +97,15 @@ function CreateSdkGen(opts: CreateSdkGenOptions) {
|
|
|
89
97
|
}
|
|
90
98
|
|
|
91
99
|
|
|
100
|
+
function completeModel(model: any) {
|
|
101
|
+
names(model, model.name)
|
|
102
|
+
|
|
103
|
+
each(model.feature, (feature: any) => {
|
|
104
|
+
names(feature, feature.key$)
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
92
109
|
// Adapted from https://github.com/sindresorhus/import-fresh - Thanks!
|
|
93
110
|
function clearRequire(path: string) {
|
|
94
111
|
let filePath = require.resolve(path)
|
package/src/standard/ModelSdk.ts
CHANGED
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
|
|
7
7
|
Project,
|
|
8
8
|
Folder,
|
|
9
|
-
|
|
9
|
+
Fragment,
|
|
10
10
|
File,
|
|
11
11
|
Content,
|
|
12
12
|
|
|
@@ -26,6 +26,9 @@ const ModelSdk = cmp(function ModelSdk(props: any) {
|
|
|
26
26
|
|
|
27
27
|
File({ name: 'sdk.jsonic' }, () => {
|
|
28
28
|
Content(`
|
|
29
|
+
|
|
30
|
+
@"../node_modules/@voxgig/sdkgen/model/sdkgen.jsonic"
|
|
31
|
+
|
|
29
32
|
name: '${model.name}'
|
|
30
33
|
|
|
31
34
|
@"api.jsonic"
|
|
@@ -45,26 +48,14 @@ main: sdk: build: go: @"go.jsonic"
|
|
|
45
48
|
|
|
46
49
|
|
|
47
50
|
|
|
48
|
-
main: sdk: test: quick: entity: name:
|
|
51
|
+
main: sdk: test: quick: entity: name: foo
|
|
49
52
|
|
|
50
53
|
|
|
51
54
|
main: sdk: entity: $.main.api.entity
|
|
52
55
|
|
|
53
56
|
|
|
54
|
-
main: sdk: entity: &: {
|
|
55
|
-
name: .$KEY
|
|
56
|
-
publish: *true | boolean
|
|
57
|
-
}
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
main: sdk: options: &: {
|
|
62
|
-
name: .$KEY
|
|
63
|
-
publish: *true | boolean
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
main: sdk: options: {
|
|
58
|
+
main: sdk: option: {
|
|
68
59
|
|
|
69
60
|
endpoint: {
|
|
70
61
|
kind: *String | string
|
|
@@ -82,6 +73,30 @@ main: sdk: options: {
|
|
|
82
73
|
}
|
|
83
74
|
}
|
|
84
75
|
`)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
each(model.feature).filter((feature: any) => feature.active).map((feature: any) => {
|
|
79
|
+
|
|
80
|
+
Content(
|
|
81
|
+
`
|
|
82
|
+
main: sdk: feature: ${feature.name}: {
|
|
83
|
+
active: true
|
|
84
|
+
config: {
|
|
85
|
+
`)
|
|
86
|
+
|
|
87
|
+
Fragment({
|
|
88
|
+
from:
|
|
89
|
+
`${__dirname}/../../feature/standard/${feature.name}/${feature.name}-config.jsonic`,
|
|
90
|
+
indent: ' '
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
Content(`
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
`)
|
|
98
|
+
})
|
|
99
|
+
|
|
85
100
|
})
|
|
86
101
|
|
|
87
102
|
})
|
package/src/standard/Root.ts
CHANGED
|
@@ -20,53 +20,24 @@ import {
|
|
|
20
20
|
import { ModelSdk } from './ModelSdk'
|
|
21
21
|
|
|
22
22
|
|
|
23
|
+
// TODO: rename to RootSdk
|
|
23
24
|
const Root = cmp(function Root(props: any) {
|
|
24
25
|
const { model, ctx$ } = props
|
|
25
26
|
|
|
26
27
|
const { folder, meta } = ctx$
|
|
27
28
|
const { spec } = meta
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// console.log('SPEC', spec)
|
|
32
|
-
|
|
33
|
-
names(model, model.name)
|
|
34
|
-
|
|
35
|
-
// console.log('MODEL')
|
|
36
|
-
// console.dir(model, { depth: null })
|
|
30
|
+
// names(model, model.name)
|
|
37
31
|
|
|
38
32
|
ctx$.model = model
|
|
39
33
|
|
|
40
|
-
/*
|
|
41
|
-
let createInfo = { exclude: [], last: Number.MAX_SAFE_INTEGER }
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
createInfo = JSON.parse(ctx$.fs.readFileSync(
|
|
46
|
-
Path.join(folder, '.voxgig', 'create-sdkgen.json'), 'utf8'))
|
|
47
|
-
}
|
|
48
|
-
catch (err: any) {
|
|
49
|
-
console.log(err)
|
|
50
|
-
// TODO: file not foound ignored, handle others!
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
ctx$.info = createInfo
|
|
54
|
-
|
|
55
|
-
console.log('INFO', ctx$.info)
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
34
|
Project({ folder }, () => {
|
|
59
35
|
|
|
60
|
-
// TODO: perhaps remove the need for this, create top level folder in Project
|
|
61
|
-
// would keep paths indo of project folder name
|
|
62
|
-
// Folder({ name: Path.basename(folder) }, () => {
|
|
63
|
-
|
|
64
|
-
// File({ name: 'foo.txt' }, () => {
|
|
65
|
-
// Content('FOO')
|
|
66
|
-
// })
|
|
67
|
-
|
|
68
36
|
// console.log('FOLDER', folder)
|
|
69
|
-
Copy({
|
|
37
|
+
Copy({
|
|
38
|
+
from: __dirname + '/../../tm/standard',
|
|
39
|
+
exclude: ['.env.local']
|
|
40
|
+
})
|
|
70
41
|
|
|
71
42
|
const def = model.def.filepath
|
|
72
43
|
if (null != def && '' !== def) {
|
|
@@ -75,30 +46,20 @@ const Root = cmp(function Root(props: any) {
|
|
|
75
46
|
})
|
|
76
47
|
}
|
|
77
48
|
|
|
78
|
-
Folder({ name: '.voxgig' }, () => { })
|
|
79
|
-
|
|
80
49
|
Folder({ name: 'model' }, () => {
|
|
81
50
|
ModelSdk({})
|
|
82
51
|
})
|
|
52
|
+
|
|
53
|
+
Folder({ name: 'feature' }, () => {
|
|
54
|
+
each(model.feature).map((feature: any) => {
|
|
55
|
+
Folder({ name: feature.name }, () => {
|
|
56
|
+
Copy({ from: __dirname + '/../../feature/standard/' + feature.name })
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
})
|
|
60
|
+
|
|
83
61
|
})
|
|
84
62
|
|
|
85
|
-
/*
|
|
86
|
-
// TODO: need mechanism to ensure this is last
|
|
87
|
-
setTimeout(() => {
|
|
88
|
-
try {
|
|
89
|
-
const info = {
|
|
90
|
-
last: Date.now(),
|
|
91
|
-
exclude: ctx$.info.exclude,
|
|
92
|
-
}
|
|
93
|
-
ctx$.fs.writeFileSync(Path.join(folder, '.voxgig', 'create-sdkgen.json'),
|
|
94
|
-
JSON.stringify(info, null, 2))
|
|
95
|
-
}
|
|
96
|
-
catch (err: any) {
|
|
97
|
-
console.log(err)
|
|
98
|
-
// TODO: file not foound ignored, handle others!
|
|
99
|
-
}
|
|
100
|
-
}, 777)
|
|
101
|
-
*/
|
|
102
63
|
})
|
|
103
64
|
|
|
104
65
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
const { DocGen } = require('@voxgig/docgen')
|
|
3
|
+
|
|
4
|
+
try {
|
|
5
|
+
const config = {
|
|
6
|
+
root: __dirname+'/../dist/DocStaticRoot.js',
|
|
7
|
+
folder: __dirname+'/../doc',
|
|
8
|
+
def: __dirname+'/../def/$$def.filename$$',
|
|
9
|
+
meta: {
|
|
10
|
+
name: '$$name$$'
|
|
11
|
+
},
|
|
12
|
+
model: {
|
|
13
|
+
folder: __dirname+'/../model',
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// console.log('DOC BUILD', config)
|
|
18
|
+
|
|
19
|
+
module.exports = DocGen.makeBuild(config)
|
|
20
|
+
}
|
|
21
|
+
catch(e) {
|
|
22
|
+
console.log('DOC ERROR', e)
|
|
23
|
+
}
|
package/tm/standard/build/sdk.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
|
|
2
2
|
const { SdkGen } = require('@voxgig/sdkgen')
|
|
3
|
-
const { Root } = require('../dist/Root')
|
|
4
|
-
|
|
5
3
|
|
|
6
4
|
try {
|
|
7
5
|
const config = {
|
|
6
|
+
root: __dirname+'/../dist/Root.js',
|
|
8
7
|
folder: __dirname+'/../sdk',
|
|
9
8
|
def: __dirname+'/../def/$$def.filename$$',
|
|
10
9
|
meta: {
|
|
@@ -12,12 +11,10 @@ try {
|
|
|
12
11
|
},
|
|
13
12
|
model: {
|
|
14
13
|
folder: __dirname+'/../model',
|
|
15
|
-
|
|
16
|
-
entity: {}
|
|
17
14
|
},
|
|
18
15
|
}
|
|
19
16
|
|
|
20
|
-
module.exports = SdkGen.makeBuild(
|
|
17
|
+
module.exports = SdkGen.makeBuild(config)
|
|
21
18
|
|
|
22
19
|
}
|
|
23
20
|
catch(e) {
|
package/tm/standard/package.json
CHANGED
|
@@ -20,11 +20,12 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@voxgig/model": "^3.
|
|
24
|
-
"@voxgig/sdkgen": "^0.
|
|
23
|
+
"@voxgig/model": "^3.5.0",
|
|
24
|
+
"@voxgig/sdkgen": "^0.12.0",
|
|
25
|
+
"@voxgig/docgen": "^0.2.2",
|
|
25
26
|
"@voxgig/util": "^0.0.3",
|
|
26
|
-
"@types/node": "22.5
|
|
27
|
-
"@stoplight/prism-cli": "^5.
|
|
28
|
-
"typescript": "^5.
|
|
27
|
+
"@types/node": "22.7.5",
|
|
28
|
+
"@stoplight/prism-cli": "^5.10.0",
|
|
29
|
+
"typescript": "^5.6.3"
|
|
29
30
|
}
|
|
30
31
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
import {
|
|
3
|
+
names,
|
|
4
|
+
cmp,
|
|
5
|
+
each,
|
|
6
|
+
|
|
7
|
+
Project,
|
|
8
|
+
Folder,
|
|
9
|
+
|
|
10
|
+
Index,
|
|
11
|
+
} from '@voxgig/docgen'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
const Root = cmp(function Root(props: any) {
|
|
15
|
+
const { model, ctx$ } = props
|
|
16
|
+
|
|
17
|
+
names(model, model.name)
|
|
18
|
+
|
|
19
|
+
ctx$.model = model
|
|
20
|
+
|
|
21
|
+
Project({}, () => {
|
|
22
|
+
|
|
23
|
+
Index({})
|
|
24
|
+
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
Root
|
|
31
|
+
}
|
|
32
|
+
|
package/tm/standard/src/Root.ts
CHANGED
|
@@ -9,26 +9,22 @@ import {
|
|
|
9
9
|
|
|
10
10
|
Main,
|
|
11
11
|
Entity,
|
|
12
|
+
Feature,
|
|
12
13
|
Readme,
|
|
13
14
|
|
|
14
15
|
} from '@voxgig/sdkgen'
|
|
15
16
|
|
|
16
|
-
// import { Readme } from './Readme'
|
|
17
|
-
// import { Main } from './Main'
|
|
18
|
-
// import { Entity } from './Entity'
|
|
19
|
-
|
|
20
17
|
|
|
21
18
|
const Root = cmp(function Root(props: any) {
|
|
22
19
|
const { model, ctx$ } = props
|
|
23
20
|
|
|
24
21
|
names(model, model.name)
|
|
25
22
|
|
|
26
|
-
// console.dir(model, { depth: null })
|
|
27
|
-
|
|
28
23
|
ctx$.model = model
|
|
29
24
|
|
|
30
25
|
const build = model.main.sdk.build
|
|
31
26
|
const entity = model.main.sdk.entity
|
|
27
|
+
const feature = model.main.sdk.feature
|
|
32
28
|
|
|
33
29
|
Project({}, () => {
|
|
34
30
|
|
|
@@ -40,11 +36,17 @@ const Root = cmp(function Root(props: any) {
|
|
|
40
36
|
|
|
41
37
|
each(entity, (entity: any) => {
|
|
42
38
|
names(entity, entity.name)
|
|
43
|
-
// console.log('ENTITY', entity.name)
|
|
44
39
|
|
|
45
40
|
Entity({ build, entity })
|
|
46
41
|
})
|
|
47
42
|
|
|
43
|
+
each(feature).filter((feature: any) => feature.active).map((feature: any) => {
|
|
44
|
+
names(feature, feature.name)
|
|
45
|
+
|
|
46
|
+
Feature({ build, feature })
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
|
|
48
50
|
Main({ build })
|
|
49
51
|
|
|
50
52
|
Readme({ build })
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
// Entity 1
|
|
3
3
|
|
|
4
|
-
import { cmp, File, Content, Folder } from '@voxgig/sdkgen'
|
|
4
|
+
import { cmp, each, File, Content, Folder } from '@voxgig/sdkgen'
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
const Entity = cmp(function Entity(props: any) {
|
|
@@ -13,13 +13,34 @@ const Entity = cmp(function Entity(props: any) {
|
|
|
13
13
|
|
|
14
14
|
File({ name: entity.Name + '.' + build.name }, () => {
|
|
15
15
|
|
|
16
|
+
const modifyRequest = each(model.main.sdk.feature).map((feature: any) => {
|
|
17
|
+
if(feature.name == 'ratelimiter') {
|
|
18
|
+
return `
|
|
19
|
+
await this.sdk().features.${feature.name}.tryAcquire()`
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
return `
|
|
23
|
+
spec = this.sdk().features.${feature.name}.modifyRequest(ctx)
|
|
24
|
+
`
|
|
25
|
+
}).join('')
|
|
26
|
+
|
|
27
|
+
const modifyResult = each(model.main.sdk.feature).map((feature: any) => {
|
|
28
|
+
if(feature.name == 'ratelimiter') {
|
|
29
|
+
return ''
|
|
30
|
+
}
|
|
31
|
+
return `
|
|
32
|
+
ctx.result = this.sdk().features.${feature.name}.modifyResult(ctx)
|
|
33
|
+
`
|
|
34
|
+
}).join('')
|
|
35
|
+
|
|
16
36
|
Content(`
|
|
17
37
|
// ${model.Name} ${build.Name} ${entity.Name} 1
|
|
18
38
|
|
|
19
39
|
class ${entity.Name} {
|
|
20
40
|
def
|
|
41
|
+
sdk
|
|
21
42
|
data
|
|
22
|
-
|
|
43
|
+
query
|
|
23
44
|
|
|
24
45
|
constructor(sdk,data) {
|
|
25
46
|
this.sdk = ()=>sdk
|
|
@@ -31,92 +52,132 @@ class ${entity.Name} {
|
|
|
31
52
|
}
|
|
32
53
|
|
|
33
54
|
|
|
34
|
-
async handleResult(
|
|
55
|
+
async handleResult(ctx, res, spec, handler) {
|
|
35
56
|
const status = res.status
|
|
36
57
|
|
|
37
58
|
if(200 === status) {
|
|
38
|
-
|
|
59
|
+
ctx.result = await res.json()
|
|
39
60
|
// TODO: error
|
|
40
|
-
|
|
61
|
+
|
|
62
|
+
${modifyResult}
|
|
63
|
+
return handler(ctx.result)
|
|
41
64
|
}
|
|
42
65
|
else {
|
|
43
|
-
throw new Error('HTTP-ERROR: '+op+': ${entity.name}: '+status)
|
|
66
|
+
throw new Error('HTTP-ERROR: '+ctx.op+': ${entity.name}: '+status)
|
|
44
67
|
}
|
|
45
68
|
}
|
|
69
|
+
`)
|
|
46
70
|
|
|
47
|
-
|
|
71
|
+
Content(`
|
|
48
72
|
async save(data) {
|
|
49
|
-
const
|
|
73
|
+
const ctx = {op:'save',entity:this}
|
|
50
74
|
this.data = data
|
|
75
|
+
this.query = {}
|
|
51
76
|
// TODO: validate data
|
|
52
77
|
|
|
53
|
-
|
|
78
|
+
let spec = ctx.spec = this.sdk().fetchSpec(ctx,this)
|
|
79
|
+
${modifyRequest}
|
|
54
80
|
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
55
81
|
|
|
56
|
-
return this.handleResult(
|
|
82
|
+
return this.handleResult(ctx, res, spec, (json)=>{
|
|
57
83
|
this.data = json
|
|
58
84
|
return this
|
|
59
85
|
})
|
|
60
86
|
}
|
|
61
87
|
|
|
88
|
+
`)
|
|
89
|
+
|
|
90
|
+
Content(`
|
|
62
91
|
async create(data) {
|
|
63
|
-
const
|
|
92
|
+
const ctx = {op:'create',entity:this}
|
|
64
93
|
this.data = data
|
|
94
|
+
this.query = {}
|
|
65
95
|
// TODO: validate data
|
|
66
96
|
|
|
67
|
-
|
|
97
|
+
let spec = ctx.spec = this.sdk().fetchSpec(ctx,this)
|
|
98
|
+
${modifyRequest}
|
|
99
|
+
|
|
100
|
+
if(this.sdk().options.debug) {
|
|
101
|
+
console.log('FETCH-create', spec)
|
|
102
|
+
}
|
|
103
|
+
|
|
68
104
|
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
69
105
|
|
|
70
|
-
return this.handleResult(
|
|
106
|
+
return this.handleResult(ctx, res, spec, (json)=>{
|
|
71
107
|
this.data = json
|
|
72
108
|
return this
|
|
73
109
|
})
|
|
74
110
|
}
|
|
75
111
|
|
|
76
112
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
113
|
+
`)
|
|
114
|
+
|
|
115
|
+
Content(`
|
|
116
|
+
async load(query) {
|
|
117
|
+
const ctx = {op:'load',entity:this}
|
|
118
|
+
this.data = {}
|
|
119
|
+
this.query = query || {}
|
|
120
|
+
|
|
121
|
+
let spec = ctx.spec = this.sdk().fetchSpec(ctx,this)
|
|
122
|
+
${modifyRequest}
|
|
123
|
+
|
|
124
|
+
if(this.sdk().options.debug) {
|
|
125
|
+
console.log('FETCH-load', spec)
|
|
126
|
+
}
|
|
82
127
|
|
|
83
|
-
const spec = this.sdk().fetchSpec(op,this)
|
|
84
128
|
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
85
129
|
|
|
86
|
-
|
|
130
|
+
return this.handleResult(ctx, res, spec, (json)=>{
|
|
87
131
|
this.data = json
|
|
88
132
|
return this
|
|
89
133
|
})
|
|
90
134
|
}
|
|
91
135
|
|
|
92
136
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
137
|
+
`)
|
|
138
|
+
|
|
139
|
+
Content(`
|
|
140
|
+
async remove(query) {
|
|
141
|
+
const ctx = {op:'remove',entity:this}
|
|
142
|
+
this.data = {}
|
|
143
|
+
this.query = query || {}
|
|
97
144
|
|
|
98
|
-
|
|
145
|
+
let spec = ctx.spec = this.sdk().fetchSpec(ctx,this)
|
|
146
|
+
${modifyRequest}
|
|
99
147
|
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
100
148
|
|
|
101
|
-
return this.handleResult(
|
|
149
|
+
return this.handleResult(ctx, res, spec, (json)=>{
|
|
102
150
|
this.data = json
|
|
103
151
|
return null
|
|
104
152
|
})
|
|
105
153
|
}
|
|
106
154
|
|
|
155
|
+
`)
|
|
107
156
|
|
|
157
|
+
Content(`
|
|
108
158
|
async list(query) {
|
|
109
|
-
const
|
|
110
|
-
|
|
159
|
+
const ctx = {op:'list',entity:this}
|
|
160
|
+
this.data = {}
|
|
161
|
+
this.query = query || {}
|
|
162
|
+
|
|
163
|
+
let spec = ctx.spec = this.sdk().fetchSpec(ctx,this)
|
|
164
|
+
${modifyRequest}
|
|
165
|
+
|
|
166
|
+
if(this.sdk().options.debug) {
|
|
167
|
+
console.log('FETCH-load', spec)
|
|
168
|
+
}
|
|
111
169
|
|
|
112
|
-
const spec = this.sdk().fetchSpec(op,this)
|
|
113
170
|
const res = await this.sdk().options.fetch(spec.url,spec)
|
|
114
171
|
|
|
115
|
-
return this.handleResult(
|
|
172
|
+
return this.handleResult(ctx, res, spec, (json)=>{
|
|
116
173
|
return json.list.map(data=>this.sdk().${entity.Name}(data))
|
|
117
174
|
})
|
|
118
175
|
}
|
|
119
176
|
|
|
177
|
+
`)
|
|
178
|
+
|
|
179
|
+
Content(`
|
|
180
|
+
|
|
120
181
|
}
|
|
121
182
|
|
|
122
183
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
import { cmp, each,
|
|
3
|
+
import { cmp, each, names, File, Content, Copy, Folder } from '@voxgig/sdkgen'
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { MainEntity } from './MainEntity_js'
|
|
@@ -11,7 +11,7 @@ const Main = cmp(async function Main(props: any) {
|
|
|
11
11
|
const { build } = props
|
|
12
12
|
const { model } = props.ctx$
|
|
13
13
|
|
|
14
|
-
const entity = model.main.sdk
|
|
14
|
+
const { entity, feature } = model.main.sdk
|
|
15
15
|
|
|
16
16
|
Copy({ from: 'tm/' + build.name + '/package.json', name: 'package.json' })
|
|
17
17
|
|
|
@@ -25,8 +25,16 @@ const Main = cmp(async function Main(props: any) {
|
|
|
25
25
|
// ${model.Name} ${build.Name} SDK
|
|
26
26
|
`)
|
|
27
27
|
|
|
28
|
+
each(feature, (feature: any) => {
|
|
29
|
+
names(feature, feature.name)
|
|
30
|
+
Content(`
|
|
31
|
+
const { ${feature.Name + 'Feature'} } = require('./${feature.name}/${feature.Name}Feature')
|
|
32
|
+
`)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
|
|
28
36
|
each(entity, (entity: any) => {
|
|
29
|
-
entity
|
|
37
|
+
names(entity, entity.name)
|
|
30
38
|
Content(`
|
|
31
39
|
const { ${entity.Name} } = require('./${entity.Name}')
|
|
32
40
|
`)
|
|
@@ -38,11 +46,16 @@ const { ${entity.Name} } = require('./${entity.Name}')
|
|
|
38
46
|
a + ('String' === opt.kind ?
|
|
39
47
|
` required('string','${opt.name}',options)\n` : ''), '')
|
|
40
48
|
|
|
49
|
+
const features = each(feature).map((feature: any) => `
|
|
50
|
+
${feature.name}: new ${feature.Name}Feature(this, ${JSON.stringify(feature.config || {})})
|
|
51
|
+
`).join(',\n')
|
|
52
|
+
|
|
41
53
|
|
|
42
54
|
Content(`
|
|
43
55
|
|
|
44
56
|
class ${model.Name}SDK {
|
|
45
57
|
options
|
|
58
|
+
features
|
|
46
59
|
|
|
47
60
|
static make(options) {
|
|
48
61
|
return new ${model.Name}SDK(options)
|
|
@@ -54,7 +67,11 @@ class ${model.Name}SDK {
|
|
|
54
67
|
|
|
55
68
|
${validate_options}
|
|
56
69
|
|
|
57
|
-
this.options.fetch = this.options.fetch || fetch
|
|
70
|
+
this.options.fetch = this.options.fetch || fetch
|
|
71
|
+
|
|
72
|
+
this.features = {
|
|
73
|
+
${features}
|
|
74
|
+
}
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
|
|
@@ -81,16 +98,25 @@ ${validate_options}
|
|
|
81
98
|
return JSON.stringify(msg)
|
|
82
99
|
}
|
|
83
100
|
|
|
84
|
-
fetchSpec(
|
|
85
|
-
const
|
|
101
|
+
fetchSpec(ctx) {
|
|
102
|
+
const { op } = ctx
|
|
103
|
+
const method = this.method(op, ctx.entity)
|
|
104
|
+
|
|
105
|
+
let qpairs = Object.entries(ctx.entity.query)
|
|
106
|
+
.filter(entry=>!entry[0].includes('$'))
|
|
107
|
+
.reduce((qp,entry)=>
|
|
108
|
+
(qp.push(encodeURIComponent(entry[0])+'='+encodeURIComponent(entry[1])),qp),[])
|
|
109
|
+
|
|
110
|
+
let query = 0===qpairs.length?'':'?'+(qpairs.join('&'))
|
|
111
|
+
|
|
86
112
|
const spec = {
|
|
87
|
-
url: this.endpoint(op,
|
|
113
|
+
url: this.endpoint(op, ctx.entity)+query,
|
|
88
114
|
method,
|
|
89
115
|
headers: {
|
|
90
116
|
'content-type': 'application/json',
|
|
91
117
|
'authorization': 'Bearer '+this.options.apikey
|
|
92
118
|
},
|
|
93
|
-
body: 'GET' === method || 'DELETE' === method ? undefined : this.body(op,
|
|
119
|
+
body: 'GET' === method || 'DELETE' === method ? undefined : this.body(op, ctx.entity),
|
|
94
120
|
}
|
|
95
121
|
return spec
|
|
96
122
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
import { names, getx, cmp, File, Content } from '@voxgig/sdkgen'
|
|
2
|
+
import { names, getx, each, cmp, File, Content } from '@voxgig/sdkgen'
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
const Quick = cmp(function Quick(props: any) {
|
|
@@ -8,14 +8,22 @@ const Quick = cmp(function Quick(props: any) {
|
|
|
8
8
|
|
|
9
9
|
// get quick entity from build config
|
|
10
10
|
|
|
11
|
-
// console.log('CONFIG 2')
|
|
12
|
-
// console.dir(spec.config, { depth: null })
|
|
13
11
|
|
|
12
|
+
let entmap = getx(spec.config.guideModel, 'guide entity?test:quick:active=true')
|
|
13
|
+
let ent: any = Object.values(entmap)[0]
|
|
14
|
+
ent.name = Object.keys(entmap)[0]
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
names(ent, ent.key$)
|
|
16
|
+
ent = ent || {}
|
|
17
|
+
names(ent, ent.name)// , ent.key$ || 'name')
|
|
18
|
+
|
|
19
|
+
// TODO: selected features should be active by default!
|
|
20
|
+
|
|
21
|
+
const featureOptions = each(model.main.sdk.feature)
|
|
22
|
+
.filter((f: any) => f.active)
|
|
23
|
+
.reduce((a: any, f: any) => a + `\n ${f.name}: { active: true },`, '')
|
|
24
|
+
|
|
25
|
+
// console.log('QUICK', ent, featureOptions)
|
|
17
26
|
|
|
18
|
-
console.log('ENT 3', ent)
|
|
19
27
|
|
|
20
28
|
File({ name: 'quick.' + build.name }, () => {
|
|
21
29
|
|
|
@@ -31,29 +39,30 @@ async function run() {
|
|
|
31
39
|
const client = ${model.Name}SDK.make({
|
|
32
40
|
endpoint: process.env.${model.NAME}_ENDPOINT,
|
|
33
41
|
apikey: process.env.${model.NAME}_APIKEY,
|
|
42
|
+
${featureOptions}
|
|
34
43
|
})
|
|
35
44
|
|
|
36
45
|
let out
|
|
37
46
|
|
|
38
47
|
`)
|
|
39
48
|
|
|
40
|
-
if (ent.test
|
|
49
|
+
if (ent.test?.quick.create) {
|
|
41
50
|
Content(`
|
|
42
|
-
out = await client.${ent.Name}().create(${JSON.stringify(ent.test
|
|
51
|
+
out = await client.${ent.Name}().create(${JSON.stringify(ent.test?.quick.create)})
|
|
43
52
|
console.log('${ent.Name}.load', out)
|
|
44
53
|
`)
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
if (ent.test
|
|
56
|
+
if (ent.test?.quick.load) {
|
|
48
57
|
Content(`
|
|
49
|
-
out = await client.${ent.Name}().load(${JSON.stringify(ent.test
|
|
58
|
+
out = await client.${ent.Name}().load(${JSON.stringify(ent.test?.quick.load)})
|
|
50
59
|
console.log('${ent.Name}.load', out)
|
|
51
60
|
`)
|
|
52
61
|
}
|
|
53
62
|
|
|
54
|
-
if (ent.test
|
|
63
|
+
if (ent.test?.quick.list) {
|
|
55
64
|
Content(`
|
|
56
|
-
out = await client.${ent.Name}().list(${JSON.stringify(ent.test
|
|
65
|
+
out = await client.${ent.Name}().list(${JSON.stringify(ent.test?.quick.list)})
|
|
57
66
|
console.log('${ent.Name}.list', out)
|
|
58
67
|
`)
|
|
59
68
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/src/standard/Root.ts~
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
name: '$$name$$'
|
|
3
|
-
|
|
4
|
-
@"api.jsonic"
|
|
5
|
-
@"def.jsonic"
|
|
6
|
-
|
|
7
|
-
main: sdk: build: &: { name: .$KEY }
|
|
8
|
-
|
|
9
|
-
main: sdk: build: js: @"js.jsonic"
|
|
10
|
-
|
|
11
|
-
main: sdk: build: rb: @"rb.jsonic"
|
|
12
|
-
|
|
13
|
-
main: sdk: build: py: @"py.jsonic"
|
|
14
|
-
|
|
15
|
-
main: sdk: build: php: @"php.jsonic"
|
|
16
|
-
|
|
17
|
-
main: sdk: build: go: @"go.jsonic"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
main: sdk: test: quick: entity: name: $$test.quick.entity.name$$
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
main: sdk: entity: $.main.api.entity
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
main: sdk: entity: &: {
|
|
28
|
-
name: .$KEY
|
|
29
|
-
publish: *true | boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
main: sdk: options: &: {
|
|
35
|
-
name: .$KEY
|
|
36
|
-
publish: *true | boolean
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
main: sdk: options: {
|
|
41
|
-
|
|
42
|
-
endpoint: {
|
|
43
|
-
kind: *String | string
|
|
44
|
-
short: "$$Name$$ API URL"
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
apikey: {
|
|
48
|
-
kind: *String | string
|
|
49
|
-
short: "$$Name$$ API Key"
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
fetch: {
|
|
53
|
-
kind: *Any | string
|
|
54
|
-
publish: false
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|