reactivated 0.34.1 → 0.35.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/dist/generator/constants.mjs +6 -4
- package/dist/generator/constants.mjs.map +1 -1
- package/dist/generator.mjs +89 -97
- package/dist/generator.mjs.map +1 -1
- package/package.json +1 -1
- package/src/generator/constants.mts +7 -4
- package/src/generator.mts +109 -105
|
@@ -6,7 +6,7 @@ const stdinBuffer = fs.readFileSync(0);
|
|
|
6
6
|
import { Project, VariableDeclarationKind, Writers, } from "ts-morph";
|
|
7
7
|
const schema = JSON.parse(stdinBuffer.toString("utf8"));
|
|
8
8
|
const project = new Project();
|
|
9
|
-
const
|
|
9
|
+
const statemenets = [];
|
|
10
10
|
const { urls, templates, types, values } = schema;
|
|
11
11
|
for (const name of Object.keys(values)) {
|
|
12
12
|
// Top level constants are deprecated.
|
|
@@ -14,7 +14,7 @@ for (const name of Object.keys(values)) {
|
|
|
14
14
|
if (name.includes(".")) {
|
|
15
15
|
continue;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
statemenets.push({
|
|
18
18
|
declarationKind: VariableDeclarationKind.Const,
|
|
19
19
|
isExported: true,
|
|
20
20
|
declarations: [
|
|
@@ -25,7 +25,7 @@ for (const name of Object.keys(values)) {
|
|
|
25
25
|
],
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
statemenets.push({
|
|
29
29
|
declarationKind: VariableDeclarationKind.Const,
|
|
30
30
|
isExported: true,
|
|
31
31
|
declarations: [
|
|
@@ -35,5 +35,7 @@ interfaces.addVariableStatement({
|
|
|
35
35
|
},
|
|
36
36
|
],
|
|
37
37
|
});
|
|
38
|
-
|
|
38
|
+
const constantsSource = project.createSourceFile("");
|
|
39
|
+
constantsSource.addVariableStatements(statemenets);
|
|
40
|
+
process.stdout.write(constantsSource.getText());
|
|
39
41
|
//# sourceMappingURL=constants.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/generator/constants.mts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,wDAAwD;AACxD,qEAAqE;AACrE,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,OAAO,EACH,OAAO,EAIP,uBAAuB,EAEvB,OAAO,GACV,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAExD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,MAAM,
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../src/generator/constants.mts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,wDAAwD;AACxD,qEAAqE;AACrE,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,OAAO,EACH,OAAO,EAIP,uBAAuB,EAEvB,OAAO,GACV,MAAM,UAAU,CAAC;AAElB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AAExD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,MAAM,WAAW,GAAG,EAAE,CAAC;AAEvB,MAAM,EAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAC,GAAG,MAAM,CAAC;AAEhD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;IACpC,sCAAsC;IACtC,+DAA+D;IAC/D,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACpB,SAAS;KACZ;IAED,WAAW,CAAC,IAAI,CAAC;QACb,eAAe,EAAE,uBAAuB,CAAC,KAAK;QAC9C,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE;YACV;gBACI,IAAI;gBACJ,WAAW,EAAE,OAAO,CAAC,SAAS,CAC1B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,EACrC,OAAO,CACV;aACJ;SACJ;KACJ,CAAC,CAAC;CACN;AAED,WAAW,CAAC,IAAI,CAAC;IACb,eAAe,EAAE,uBAAuB,CAAC,KAAK;IAC9C,UAAU,EAAE,IAAI;IAChB,YAAY,EAAE;QACV;YACI,IAAI,EAAE,WAAW;YACjB,WAAW,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC;SAC3E;KACJ;CACJ,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC;AACrD,eAAe,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;AAEnD,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC,CAAC"}
|
package/dist/generator.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "fs";
|
|
|
4
4
|
// json-schema-to-typescript messes up the descriptor even if unused.
|
|
5
5
|
const stdinBuffer = fs.readFileSync(0);
|
|
6
6
|
const { compile } = await import("json-schema-to-typescript");
|
|
7
|
-
import { Project, Scope, VariableDeclarationKind, Writers, } from "ts-morph";
|
|
7
|
+
import { Project, Scope, StructureKind, VariableDeclarationKind, Writers, } from "ts-morph";
|
|
8
8
|
const schema = JSON.parse(stdinBuffer.toString("utf8"));
|
|
9
9
|
const { urls: possibleEmptyUrls, templates, interfaces, rpc: uncastedRpc, types, values, } = schema;
|
|
10
10
|
const rpc = uncastedRpc;
|
|
@@ -23,22 +23,53 @@ const urls = {
|
|
|
23
23
|
};
|
|
24
24
|
const project = new Project();
|
|
25
25
|
const sourceFile = project.createSourceFile("");
|
|
26
|
-
const
|
|
26
|
+
const rpcConstructorStructure = {
|
|
27
|
+
statements: [],
|
|
28
|
+
parameters: [
|
|
29
|
+
{
|
|
30
|
+
name: "requester",
|
|
31
|
+
type: "rpcUtils.Requester",
|
|
32
|
+
isReadonly: false,
|
|
33
|
+
scope: Scope.Public,
|
|
34
|
+
decorators: [],
|
|
35
|
+
hasQuestionToken: false,
|
|
36
|
+
hasOverrideKeyword: false,
|
|
37
|
+
kind: StructureKind.Parameter,
|
|
38
|
+
isRestParameter: false,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
typeParameters: [],
|
|
42
|
+
docs: [],
|
|
43
|
+
kind: StructureKind.Constructor,
|
|
44
|
+
overloads: [],
|
|
45
|
+
};
|
|
46
|
+
const rpcStructure = {
|
|
47
|
+
decorators: [],
|
|
48
|
+
typeParameters: [],
|
|
49
|
+
docs: [],
|
|
50
|
+
isAbstract: false,
|
|
51
|
+
implements: [],
|
|
27
52
|
name: "RPC",
|
|
28
53
|
isExported: true,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
54
|
+
isDefaultExport: false,
|
|
55
|
+
hasDeclareKeyword: false,
|
|
56
|
+
kind: StructureKind.Class,
|
|
57
|
+
ctors: [rpcConstructorStructure],
|
|
58
|
+
properties: [],
|
|
59
|
+
methods: [],
|
|
60
|
+
};
|
|
34
61
|
for (const name of Object.keys(rpc)) {
|
|
35
62
|
const { url, input, output, type, params } = rpc[name];
|
|
36
|
-
const
|
|
63
|
+
const methodStructure = {
|
|
64
|
+
kind: StructureKind.Method,
|
|
37
65
|
name,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
66
|
+
isAsync: true,
|
|
67
|
+
parameters: [],
|
|
68
|
+
statements: [],
|
|
69
|
+
returnType: "",
|
|
70
|
+
};
|
|
71
|
+
rpcConstructorStructure.statements.push(`this.${name} = (this.${name} as any).bind(this);\n`);
|
|
72
|
+
methodStructure.parameters?.push({
|
|
42
73
|
name: "this",
|
|
43
74
|
type: "void",
|
|
44
75
|
});
|
|
@@ -48,17 +79,21 @@ for (const name of Object.keys(rpc)) {
|
|
|
48
79
|
name: (writer) => writer.quote(name),
|
|
49
80
|
};
|
|
50
81
|
if (params.length >= 1) {
|
|
51
|
-
const
|
|
52
|
-
name: "WILL_BE_STRIPPED",
|
|
53
|
-
});
|
|
82
|
+
const paramsProperties = [];
|
|
54
83
|
const iterator = [];
|
|
55
84
|
for (const [paramType, paramName] of params) {
|
|
56
|
-
|
|
85
|
+
paramsProperties.push({ name: paramName, type: "string | number" });
|
|
57
86
|
iterator.push(paramName);
|
|
58
87
|
}
|
|
59
|
-
|
|
88
|
+
methodStructure.parameters?.push({
|
|
60
89
|
name: "params",
|
|
61
|
-
type:
|
|
90
|
+
type: Writers.objectType({ properties: paramsProperties }),
|
|
91
|
+
isReadonly: false,
|
|
92
|
+
decorators: [],
|
|
93
|
+
hasQuestionToken: false,
|
|
94
|
+
hasOverrideKeyword: false,
|
|
95
|
+
kind: StructureKind.Parameter,
|
|
96
|
+
isRestParameter: false,
|
|
62
97
|
});
|
|
63
98
|
Object.assign(initializer, {
|
|
64
99
|
paramsAndIterator: Writers.object({
|
|
@@ -66,24 +101,21 @@ for (const name of Object.keys(rpc)) {
|
|
|
66
101
|
params: "params",
|
|
67
102
|
}),
|
|
68
103
|
});
|
|
69
|
-
// Otherwise our interface will be inserted.
|
|
70
|
-
functionDeclaration.setBodyText("");
|
|
71
104
|
}
|
|
72
105
|
else {
|
|
73
106
|
Object.assign(initializer, { paramsAndIterator: "null" });
|
|
74
107
|
}
|
|
75
108
|
if (input != null) {
|
|
76
|
-
|
|
77
|
-
// isStatic: true,
|
|
109
|
+
rpcStructure.properties?.push({
|
|
78
110
|
name: input,
|
|
79
111
|
type: `_Types["${input}"]`,
|
|
80
112
|
initializer: JSON.stringify(values[input]),
|
|
81
113
|
});
|
|
82
|
-
|
|
114
|
+
methodStructure.parameters?.push({
|
|
83
115
|
name: "input",
|
|
84
116
|
type: `forms.FormOrFormSetValues<_Types["${input}"]>`,
|
|
85
117
|
});
|
|
86
|
-
|
|
118
|
+
methodStructure.returnType = `Promise<rpcUtils.Result<_Types["${output}"], forms.FormOrFormSetErrors<_Types["${input}"]>, _Types["RPCPermission"]>>`;
|
|
87
119
|
Object.assign(initializer, {
|
|
88
120
|
input: Writers.object({
|
|
89
121
|
values: "input",
|
|
@@ -92,67 +124,23 @@ for (const name of Object.keys(rpc)) {
|
|
|
92
124
|
});
|
|
93
125
|
}
|
|
94
126
|
else {
|
|
95
|
-
|
|
127
|
+
methodStructure.returnType = `Promise<rpcUtils.Result<_Types["${output}"], null, _Types["RPCPermission"]>>`;
|
|
96
128
|
Object.assign(initializer, { input: "null" });
|
|
97
129
|
}
|
|
98
|
-
|
|
130
|
+
methodStructure.statements?.push({
|
|
131
|
+
kind: StructureKind.VariableStatement,
|
|
99
132
|
declarationKind: VariableDeclarationKind.Const,
|
|
100
133
|
declarations: [
|
|
101
134
|
{
|
|
102
135
|
name: "options",
|
|
103
136
|
initializer: Writers.object(initializer),
|
|
104
|
-
/*
|
|
105
|
-
x: 123,
|
|
106
|
-
y: (writer) => writer.quote("abc"),
|
|
107
|
-
z: Writers.object({
|
|
108
|
-
one: (writer) => writer.quote("1"),
|
|
109
|
-
}),
|
|
110
|
-
*/
|
|
111
137
|
},
|
|
112
138
|
],
|
|
113
139
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (input != null) {
|
|
118
|
-
functionDeclaration.addParameter({
|
|
119
|
-
name: "input",
|
|
120
|
-
type: `forms.FormOrFormSetValues<_Types["${input}"]>`,
|
|
121
|
-
});
|
|
122
|
-
bodyText = bodyText.concat(`
|
|
123
|
-
const input = ${JSON.stringify({
|
|
124
|
-
type: "form",
|
|
125
|
-
})};
|
|
126
|
-
}
|
|
127
|
-
`);
|
|
128
|
-
}
|
|
129
|
-
else {
|
|
130
|
-
}
|
|
131
|
-
*/
|
|
132
|
-
/*
|
|
133
|
-
if (instance.length === 1) {
|
|
134
|
-
functionDeclaration.addParameter({name: "instance", type: `string | number`});
|
|
135
|
-
functionDeclaration.setBodyText(`return rpcUtils.rpcCall("${url}", input, "${type}", instance)`);
|
|
136
|
-
}
|
|
137
|
-
else if (instance.length >= 2) {
|
|
138
|
-
const instanceInterface = functionDeclaration.addInterface({name: "WILL_BE_STRIPPED"});
|
|
139
|
-
|
|
140
|
-
for (const instanceArg of instance) {
|
|
141
|
-
instanceInterface.addProperty({name: instanceArg, type: "string | number"});
|
|
142
|
-
}
|
|
143
|
-
functionDeclaration.addParameter({name: "instance", type: instanceInterface.getText().replace("interface WILL_BE_STRIPPED", "")});
|
|
144
|
-
functionDeclaration.setBodyText(`const iterator = ${JSON.stringify(instance)}; return rpcUtils.rpcCall("${url}", input, "${type}", {iterator, params: instance})`);
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
functionDeclaration.setBodyText(`return rpcUtils.rpcCall("${url}", input, "${type}")`);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
functionDeclaration.addParameter({name: "input", type: `forms.FormOrFormSetValues<_Types["${input}"]>`});
|
|
151
|
-
functionDeclaration.setReturnType(`Promise<rpcUtils.Result<_Types["${output}"], forms.FormOrFormSetErrors<_Types["${input}"]>>>`);
|
|
152
|
-
functionDeclaration.setIsAsync(true);
|
|
153
|
-
*/
|
|
140
|
+
methodStructure.statements?.push("return rpcUtils.rpcCall((this as any).requester, options)");
|
|
141
|
+
rpcStructure.methods?.push(methodStructure);
|
|
154
142
|
}
|
|
155
|
-
|
|
143
|
+
sourceFile.addClass(rpcStructure);
|
|
156
144
|
if (Object.keys(urls).length !== 0) {
|
|
157
145
|
sourceFile.addVariableStatement({
|
|
158
146
|
declarationKind: VariableDeclarationKind.Const,
|
|
@@ -163,33 +151,34 @@ if (Object.keys(urls).length !== 0) {
|
|
|
163
151
|
},
|
|
164
152
|
],
|
|
165
153
|
});
|
|
166
|
-
const urlMap =
|
|
154
|
+
const urlMap = {
|
|
167
155
|
name: "URLMap",
|
|
168
|
-
|
|
169
|
-
|
|
156
|
+
properties: [],
|
|
157
|
+
// isExported: true,
|
|
158
|
+
};
|
|
170
159
|
const withArguments = [""];
|
|
171
160
|
const withoutArguments = [""];
|
|
161
|
+
const interfaces = [urlMap];
|
|
172
162
|
for (const name of Object.keys(urls)) {
|
|
173
163
|
const properties = urls[name].args;
|
|
174
164
|
const normalizedName = name.replace(/[^\w]/g, "_");
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
name:
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
urlMap.addProperty({
|
|
165
|
+
interfaces.push(...[
|
|
166
|
+
{
|
|
167
|
+
name: normalizedName,
|
|
168
|
+
properties: [
|
|
169
|
+
{ name: "name", type: `'${name}'` },
|
|
170
|
+
{ name: "args", type: `${normalizedName}_args` },
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: `${normalizedName}_args`,
|
|
175
|
+
properties: Object.keys(properties).map((propertyName) => ({
|
|
176
|
+
name: propertyName,
|
|
177
|
+
type: properties[propertyName],
|
|
178
|
+
})),
|
|
179
|
+
},
|
|
180
|
+
]);
|
|
181
|
+
urlMap.properties.push({
|
|
193
182
|
name: normalizedName,
|
|
194
183
|
type: normalizedName,
|
|
195
184
|
});
|
|
@@ -200,6 +189,7 @@ if (Object.keys(urls).length !== 0) {
|
|
|
200
189
|
withArguments.push(normalizedName);
|
|
201
190
|
}
|
|
202
191
|
}
|
|
192
|
+
sourceFile.addInterfaces(interfaces);
|
|
203
193
|
sourceFile.addTypeAlias({ name: "WithArguments", type: withArguments.join("|") });
|
|
204
194
|
sourceFile.addTypeAlias({
|
|
205
195
|
name: "WithoutArguments",
|
|
@@ -264,10 +254,11 @@ export const {Form, FormSet, Widget, useForm, useFormSet, ManagementForm} = form
|
|
|
264
254
|
compile(types, "this is unused").then((ts) => {
|
|
265
255
|
process.stdout.write("/* eslint-disable */\n");
|
|
266
256
|
process.stdout.write(ts);
|
|
257
|
+
const statements = [];
|
|
267
258
|
if (!fs.existsSync("./reactivated-skip-template-check")) {
|
|
268
259
|
for (const name of Object.keys(templates)) {
|
|
269
260
|
const propsName = templates[name];
|
|
270
|
-
|
|
261
|
+
statements.push(`
|
|
271
262
|
|
|
272
263
|
import ${name}Implementation from "@client/templates/${name}"
|
|
273
264
|
export type ${name}Check = Checker<_Types["${propsName}"], typeof ${name}Implementation>;
|
|
@@ -282,7 +273,7 @@ export namespace templates {
|
|
|
282
273
|
}
|
|
283
274
|
for (const name of Object.keys(interfaces)) {
|
|
284
275
|
const propsName = interfaces[name];
|
|
285
|
-
|
|
276
|
+
statements.push(`
|
|
286
277
|
|
|
287
278
|
export namespace interfaces {
|
|
288
279
|
export type ${name} = _Types["${propsName}"];
|
|
@@ -291,6 +282,7 @@ export namespace interfaces {
|
|
|
291
282
|
|
|
292
283
|
`);
|
|
293
284
|
}
|
|
285
|
+
sourceFile.addStatements(statements);
|
|
294
286
|
process.stdout.write(sourceFile.getText());
|
|
295
287
|
});
|
|
296
288
|
//# sourceMappingURL=generator.mjs.map
|
package/dist/generator.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.mjs","sourceRoot":"","sources":["../src/generator.mts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MAAM,IAAI,CAAC;AAGpB,wDAAwD;AACxD,qEAAqE;AACrE,MAAM,WAAW,GAAG,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,MAAM,EAAC,OAAO,EAAC,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAE5D,OAAO,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AC,EAAE;YACvC,MAAM,SAAS,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;YAElC,UAAU,CAAC,IAAI,CAAC;;SAEnB,IAAI,0CAA0C,IAAI;cAC7C,IAAI,2BAA2B,SAAS,cAAc,IAAI;;;kBAGtD,IAAI,cAAc,SAAS;;;;SAIpC,CAAC,CAAC;SACF;KACJ;IAED,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;QACxC,MAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QACnC,UAAU,CAAC,IAAI,CAAC;;;kBAGN,IAAI,cAAc,SAAS;;;;SAIpC,CAAC,CAAC;KACN;IAED,UAAU,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAErC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ const schema = JSON.parse(stdinBuffer.toString("utf8"));
|
|
|
20
20
|
|
|
21
21
|
const project = new Project();
|
|
22
22
|
|
|
23
|
-
const
|
|
23
|
+
const statemenets = [];
|
|
24
24
|
|
|
25
25
|
const {urls, templates, types, values} = schema;
|
|
26
26
|
|
|
@@ -31,7 +31,7 @@ for (const name of Object.keys(values)) {
|
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
statemenets.push({
|
|
35
35
|
declarationKind: VariableDeclarationKind.Const,
|
|
36
36
|
isExported: true,
|
|
37
37
|
declarations: [
|
|
@@ -46,7 +46,7 @@ for (const name of Object.keys(values)) {
|
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
statemenets.push({
|
|
50
50
|
declarationKind: VariableDeclarationKind.Const,
|
|
51
51
|
isExported: true,
|
|
52
52
|
declarations: [
|
|
@@ -57,4 +57,7 @@ interfaces.addVariableStatement({
|
|
|
57
57
|
],
|
|
58
58
|
});
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
const constantsSource = project.createSourceFile("");
|
|
61
|
+
constantsSource.addVariableStatements(statemenets);
|
|
62
|
+
|
|
63
|
+
process.stdout.write(constantsSource.getText());
|
package/src/generator.mts
CHANGED
|
@@ -19,6 +19,13 @@ import {
|
|
|
19
19
|
VariableDeclarationKind,
|
|
20
20
|
WriterFunction,
|
|
21
21
|
Writers,
|
|
22
|
+
InterfaceDeclarationStructure,
|
|
23
|
+
OptionalKind,
|
|
24
|
+
MethodDeclarationStructure,
|
|
25
|
+
PropertyDeclarationStructure,
|
|
26
|
+
ParameterDeclarationStructure,
|
|
27
|
+
StatementedNodeStructure,
|
|
28
|
+
StatementStructures,
|
|
22
29
|
} from "ts-morph";
|
|
23
30
|
|
|
24
31
|
const schema = JSON.parse(stdinBuffer.toString("utf8"));
|
|
@@ -51,27 +58,60 @@ const project = new Project();
|
|
|
51
58
|
|
|
52
59
|
const sourceFile = project.createSourceFile("");
|
|
53
60
|
|
|
54
|
-
const
|
|
61
|
+
const rpcConstructorStructure = {
|
|
62
|
+
statements: [] as string[],
|
|
63
|
+
parameters: [
|
|
64
|
+
{
|
|
65
|
+
name: "requester",
|
|
66
|
+
type: "rpcUtils.Requester",
|
|
67
|
+
isReadonly: false,
|
|
68
|
+
scope: Scope.Public,
|
|
69
|
+
decorators: [],
|
|
70
|
+
hasQuestionToken: false,
|
|
71
|
+
hasOverrideKeyword: false,
|
|
72
|
+
kind: StructureKind.Parameter as const,
|
|
73
|
+
isRestParameter: false,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
typeParameters: [],
|
|
77
|
+
docs: [],
|
|
78
|
+
kind: StructureKind.Constructor as const,
|
|
79
|
+
overloads: [],
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const rpcStructure = {
|
|
83
|
+
decorators: [],
|
|
84
|
+
typeParameters: [],
|
|
85
|
+
docs: [],
|
|
86
|
+
isAbstract: false,
|
|
87
|
+
implements: [],
|
|
55
88
|
name: "RPC",
|
|
56
89
|
isExported: true,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
90
|
+
isDefaultExport: false,
|
|
91
|
+
hasDeclareKeyword: false,
|
|
92
|
+
kind: StructureKind.Class as const,
|
|
93
|
+
ctors: [rpcConstructorStructure],
|
|
94
|
+
properties: [] as OptionalKind<PropertyDeclarationStructure>[],
|
|
95
|
+
methods: [] as OptionalKind<MethodDeclarationStructure>[],
|
|
96
|
+
};
|
|
64
97
|
|
|
65
98
|
for (const name of Object.keys(rpc)) {
|
|
66
99
|
const {url, input, output, type, params} = rpc[name];
|
|
67
|
-
|
|
100
|
+
|
|
101
|
+
const methodStructure = {
|
|
102
|
+
kind: StructureKind.Method as const,
|
|
68
103
|
name,
|
|
69
|
-
|
|
104
|
+
isAsync: true,
|
|
105
|
+
parameters: [] as OptionalKind<ParameterDeclarationStructure>[],
|
|
106
|
+
statements: [] as (string | StatementStructures)[],
|
|
107
|
+
returnType: "",
|
|
108
|
+
};
|
|
70
109
|
|
|
71
|
-
|
|
72
|
-
|
|
110
|
+
rpcConstructorStructure.statements.push(
|
|
111
|
+
`this.${name} = (this.${name} as any).bind(this);\n`,
|
|
112
|
+
);
|
|
73
113
|
|
|
74
|
-
|
|
114
|
+
methodStructure.parameters?.push({
|
|
75
115
|
name: "this",
|
|
76
116
|
type: "void",
|
|
77
117
|
});
|
|
@@ -83,18 +123,22 @@ for (const name of Object.keys(rpc)) {
|
|
|
83
123
|
};
|
|
84
124
|
|
|
85
125
|
if (params.length >= 1) {
|
|
86
|
-
const
|
|
87
|
-
name: "WILL_BE_STRIPPED",
|
|
88
|
-
});
|
|
126
|
+
const paramsProperties = [];
|
|
89
127
|
|
|
90
128
|
const iterator = [];
|
|
91
129
|
for (const [paramType, paramName] of params) {
|
|
92
|
-
|
|
130
|
+
paramsProperties.push({name: paramName, type: "string | number"});
|
|
93
131
|
iterator.push(paramName);
|
|
94
132
|
}
|
|
95
|
-
|
|
133
|
+
methodStructure.parameters?.push({
|
|
96
134
|
name: "params",
|
|
97
|
-
type:
|
|
135
|
+
type: Writers.objectType({properties: paramsProperties}),
|
|
136
|
+
isReadonly: false,
|
|
137
|
+
decorators: [],
|
|
138
|
+
hasQuestionToken: false,
|
|
139
|
+
hasOverrideKeyword: false,
|
|
140
|
+
kind: StructureKind.Parameter as const,
|
|
141
|
+
isRestParameter: false,
|
|
98
142
|
});
|
|
99
143
|
|
|
100
144
|
Object.assign(initializer, {
|
|
@@ -103,26 +147,23 @@ for (const name of Object.keys(rpc)) {
|
|
|
103
147
|
params: "params",
|
|
104
148
|
}),
|
|
105
149
|
});
|
|
106
|
-
// Otherwise our interface will be inserted.
|
|
107
|
-
functionDeclaration.setBodyText("");
|
|
108
150
|
} else {
|
|
109
151
|
Object.assign(initializer, {paramsAndIterator: "null"});
|
|
110
152
|
}
|
|
111
153
|
|
|
112
154
|
if (input != null) {
|
|
113
|
-
|
|
114
|
-
// isStatic: true,
|
|
155
|
+
rpcStructure.properties?.push({
|
|
115
156
|
name: input,
|
|
116
157
|
type: `_Types["${input}"]`,
|
|
117
158
|
initializer: JSON.stringify(values[input]),
|
|
118
159
|
});
|
|
119
|
-
|
|
160
|
+
methodStructure.parameters?.push({
|
|
120
161
|
name: "input",
|
|
121
162
|
type: `forms.FormOrFormSetValues<_Types["${input}"]>`,
|
|
122
163
|
});
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
164
|
+
|
|
165
|
+
methodStructure.returnType = `Promise<rpcUtils.Result<_Types["${output}"], forms.FormOrFormSetErrors<_Types["${input}"]>, _Types["RPCPermission"]>>`;
|
|
166
|
+
|
|
126
167
|
Object.assign(initializer, {
|
|
127
168
|
input: Writers.object({
|
|
128
169
|
values: "input",
|
|
@@ -131,73 +172,27 @@ for (const name of Object.keys(rpc)) {
|
|
|
131
172
|
}),
|
|
132
173
|
});
|
|
133
174
|
} else {
|
|
134
|
-
|
|
135
|
-
`Promise<rpcUtils.Result<_Types["${output}"], null, _Types["RPCPermission"]>>`,
|
|
136
|
-
);
|
|
175
|
+
methodStructure.returnType = `Promise<rpcUtils.Result<_Types["${output}"], null, _Types["RPCPermission"]>>`;
|
|
137
176
|
Object.assign(initializer, {input: "null"});
|
|
138
177
|
}
|
|
139
178
|
|
|
140
|
-
|
|
179
|
+
methodStructure.statements?.push({
|
|
180
|
+
kind: StructureKind.VariableStatement,
|
|
141
181
|
declarationKind: VariableDeclarationKind.Const,
|
|
142
182
|
declarations: [
|
|
143
183
|
{
|
|
144
184
|
name: "options",
|
|
145
185
|
initializer: Writers.object(initializer),
|
|
146
|
-
/*
|
|
147
|
-
x: 123,
|
|
148
|
-
y: (writer) => writer.quote("abc"),
|
|
149
|
-
z: Writers.object({
|
|
150
|
-
one: (writer) => writer.quote("1"),
|
|
151
|
-
}),
|
|
152
|
-
*/
|
|
153
186
|
},
|
|
154
187
|
],
|
|
155
188
|
});
|
|
156
|
-
|
|
157
|
-
|
|
189
|
+
methodStructure.statements?.push(
|
|
190
|
+
"return rpcUtils.rpcCall((this as any).requester, options)",
|
|
158
191
|
);
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (input != null) {
|
|
162
|
-
functionDeclaration.addParameter({
|
|
163
|
-
name: "input",
|
|
164
|
-
type: `forms.FormOrFormSetValues<_Types["${input}"]>`,
|
|
165
|
-
});
|
|
166
|
-
bodyText = bodyText.concat(`
|
|
167
|
-
const input = ${JSON.stringify({
|
|
168
|
-
type: "form",
|
|
169
|
-
})};
|
|
170
|
-
}
|
|
171
|
-
`);
|
|
172
|
-
}
|
|
173
|
-
else {
|
|
174
|
-
}
|
|
175
|
-
*/
|
|
176
|
-
|
|
177
|
-
/*
|
|
178
|
-
if (instance.length === 1) {
|
|
179
|
-
functionDeclaration.addParameter({name: "instance", type: `string | number`});
|
|
180
|
-
functionDeclaration.setBodyText(`return rpcUtils.rpcCall("${url}", input, "${type}", instance)`);
|
|
181
|
-
}
|
|
182
|
-
else if (instance.length >= 2) {
|
|
183
|
-
const instanceInterface = functionDeclaration.addInterface({name: "WILL_BE_STRIPPED"});
|
|
184
|
-
|
|
185
|
-
for (const instanceArg of instance) {
|
|
186
|
-
instanceInterface.addProperty({name: instanceArg, type: "string | number"});
|
|
187
|
-
}
|
|
188
|
-
functionDeclaration.addParameter({name: "instance", type: instanceInterface.getText().replace("interface WILL_BE_STRIPPED", "")});
|
|
189
|
-
functionDeclaration.setBodyText(`const iterator = ${JSON.stringify(instance)}; return rpcUtils.rpcCall("${url}", input, "${type}", {iterator, params: instance})`);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
functionDeclaration.setBodyText(`return rpcUtils.rpcCall("${url}", input, "${type}")`);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
functionDeclaration.addParameter({name: "input", type: `forms.FormOrFormSetValues<_Types["${input}"]>`});
|
|
196
|
-
functionDeclaration.setReturnType(`Promise<rpcUtils.Result<_Types["${output}"], forms.FormOrFormSetErrors<_Types["${input}"]>>>`);
|
|
197
|
-
functionDeclaration.setIsAsync(true);
|
|
198
|
-
*/
|
|
192
|
+
rpcStructure.methods?.push(methodStructure);
|
|
199
193
|
}
|
|
200
|
-
|
|
194
|
+
|
|
195
|
+
sourceFile.addClass(rpcStructure);
|
|
201
196
|
|
|
202
197
|
if (Object.keys(urls).length !== 0) {
|
|
203
198
|
sourceFile.addVariableStatement({
|
|
@@ -210,38 +205,43 @@ if (Object.keys(urls).length !== 0) {
|
|
|
210
205
|
],
|
|
211
206
|
});
|
|
212
207
|
|
|
213
|
-
const urlMap =
|
|
208
|
+
const urlMap = {
|
|
214
209
|
name: "URLMap",
|
|
215
|
-
|
|
216
|
-
|
|
210
|
+
properties: [] as any,
|
|
211
|
+
// isExported: true,
|
|
212
|
+
};
|
|
217
213
|
|
|
218
214
|
const withArguments = [""];
|
|
215
|
+
|
|
219
216
|
const withoutArguments = [""];
|
|
220
217
|
|
|
218
|
+
const interfaces: OptionalKind<InterfaceDeclarationStructure>[] = [urlMap];
|
|
219
|
+
|
|
221
220
|
for (const name of Object.keys(urls)) {
|
|
222
221
|
const properties = urls[name as keyof typeof urls].args;
|
|
223
222
|
const normalizedName = name.replace(/[^\w]/g, "_");
|
|
224
223
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
224
|
+
interfaces.push(
|
|
225
|
+
...[
|
|
226
|
+
{
|
|
227
|
+
name: normalizedName,
|
|
228
|
+
properties: [
|
|
229
|
+
{name: "name", type: `'${name}'`},
|
|
230
|
+
{name: "args", type: `${normalizedName}_args`},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: `${normalizedName}_args`,
|
|
235
|
+
|
|
236
|
+
properties: Object.keys(properties).map((propertyName) => ({
|
|
237
|
+
name: propertyName,
|
|
238
|
+
type: properties[propertyName as keyof typeof properties],
|
|
239
|
+
})),
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
);
|
|
243
243
|
|
|
244
|
-
urlMap.
|
|
244
|
+
urlMap.properties.push({
|
|
245
245
|
name: normalizedName,
|
|
246
246
|
type: normalizedName,
|
|
247
247
|
});
|
|
@@ -252,6 +252,7 @@ if (Object.keys(urls).length !== 0) {
|
|
|
252
252
|
withArguments.push(normalizedName);
|
|
253
253
|
}
|
|
254
254
|
}
|
|
255
|
+
sourceFile.addInterfaces(interfaces);
|
|
255
256
|
sourceFile.addTypeAlias({name: "WithArguments", type: withArguments.join("|")});
|
|
256
257
|
sourceFile.addTypeAlias({
|
|
257
258
|
name: "WithoutArguments",
|
|
@@ -321,12 +322,13 @@ export const {Form, FormSet, Widget, useForm, useFormSet, ManagementForm} = form
|
|
|
321
322
|
compile(types, "this is unused").then((ts) => {
|
|
322
323
|
process.stdout.write("/* eslint-disable */\n");
|
|
323
324
|
process.stdout.write(ts);
|
|
325
|
+
const statements = [];
|
|
324
326
|
|
|
325
327
|
if (!fs.existsSync("./reactivated-skip-template-check")) {
|
|
326
328
|
for (const name of Object.keys(templates)) {
|
|
327
329
|
const propsName = templates[name];
|
|
328
330
|
|
|
329
|
-
|
|
331
|
+
statements.push(`
|
|
330
332
|
|
|
331
333
|
import ${name}Implementation from "@client/templates/${name}"
|
|
332
334
|
export type ${name}Check = Checker<_Types["${propsName}"], typeof ${name}Implementation>;
|
|
@@ -342,7 +344,7 @@ export namespace templates {
|
|
|
342
344
|
|
|
343
345
|
for (const name of Object.keys(interfaces)) {
|
|
344
346
|
const propsName = interfaces[name];
|
|
345
|
-
|
|
347
|
+
statements.push(`
|
|
346
348
|
|
|
347
349
|
export namespace interfaces {
|
|
348
350
|
export type ${name} = _Types["${propsName}"];
|
|
@@ -352,5 +354,7 @@ export namespace interfaces {
|
|
|
352
354
|
`);
|
|
353
355
|
}
|
|
354
356
|
|
|
357
|
+
sourceFile.addStatements(statements);
|
|
358
|
+
|
|
355
359
|
process.stdout.write(sourceFile.getText());
|
|
356
360
|
});
|