reactivated 0.21.0-a782 → 0.22.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/generator.js +17 -12
- package/generator.js.map +1 -1
- package/package.json +1 -1
package/generator.js
CHANGED
|
@@ -21,7 +21,7 @@ var stdinBuffer = fs_1.default.readFileSync(0);
|
|
|
21
21
|
var json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
22
22
|
var ts_morph_1 = require("ts-morph");
|
|
23
23
|
var schema = JSON.parse(stdinBuffer.toString("utf8"));
|
|
24
|
-
var possibleEmptyUrls = schema.urls, templates = schema.templates, types = schema.types, values = schema.values;
|
|
24
|
+
var possibleEmptyUrls = schema.urls, templates = schema.templates, interfaces = schema.interfaces, types = schema.types, values = schema.values;
|
|
25
25
|
var urls = __assign(__assign({}, possibleEmptyUrls), { __reactivated_do_not_use: {
|
|
26
26
|
route: "__reactivated_do_not_use",
|
|
27
27
|
args: {},
|
|
@@ -32,9 +32,9 @@ var urls = __assign(__assign({}, possibleEmptyUrls), { __reactivated_do_not_use:
|
|
|
32
32
|
},
|
|
33
33
|
} });
|
|
34
34
|
var project = new ts_morph_1.Project();
|
|
35
|
-
var
|
|
35
|
+
var sourceFile = project.createSourceFile("");
|
|
36
36
|
if (Object.keys(urls).length !== 0) {
|
|
37
|
-
|
|
37
|
+
sourceFile.addVariableStatement({
|
|
38
38
|
declarationKind: ts_morph_1.VariableDeclarationKind.Const,
|
|
39
39
|
declarations: [
|
|
40
40
|
{
|
|
@@ -43,7 +43,7 @@ if (Object.keys(urls).length !== 0) {
|
|
|
43
43
|
},
|
|
44
44
|
],
|
|
45
45
|
});
|
|
46
|
-
var urlMap =
|
|
46
|
+
var urlMap = sourceFile.addInterface({
|
|
47
47
|
name: "URLMap",
|
|
48
48
|
});
|
|
49
49
|
urlMap.setIsExported(true);
|
|
@@ -53,11 +53,11 @@ if (Object.keys(urls).length !== 0) {
|
|
|
53
53
|
var name_1 = _a[_i];
|
|
54
54
|
var properties = urls[name_1].args;
|
|
55
55
|
var normalizedName = name_1.replace(/[^\w]/g, "_");
|
|
56
|
-
var urlInterface =
|
|
56
|
+
var urlInterface = sourceFile.addInterface({
|
|
57
57
|
name: normalizedName,
|
|
58
58
|
properties: [{ name: "name", type: "'".concat(name_1, "'") }],
|
|
59
59
|
});
|
|
60
|
-
var argsInterface =
|
|
60
|
+
var argsInterface = sourceFile.addInterface({
|
|
61
61
|
name: "".concat(normalizedName, "_args"),
|
|
62
62
|
});
|
|
63
63
|
for (var _b = 0, _c = Object.keys(properties); _b < _c.length; _b++) {
|
|
@@ -82,14 +82,14 @@ if (Object.keys(urls).length !== 0) {
|
|
|
82
82
|
withArguments.push(normalizedName);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
sourceFile.addTypeAlias({ name: "WithArguments", type: withArguments.join("|") });
|
|
86
|
+
sourceFile.addTypeAlias({
|
|
87
87
|
name: "WithoutArguments",
|
|
88
88
|
type: withoutArguments.join("|"),
|
|
89
89
|
});
|
|
90
|
-
|
|
90
|
+
sourceFile.addStatements("\n\n type All = WithArguments|WithoutArguments;\n export function reverse<T extends WithoutArguments['name']>(name: T): string;\n export function reverse<T extends WithArguments['name']>(name: T, args: Extract<WithArguments, {name: T}>['args']): string;\n export function reverse<T extends All['name']>(name: T, args?: Extract<WithArguments, {name: T}>['args']): string {\n let route = urls[name].route;\n\n if (args != null) {\n for (const token of Object.keys(args)) {\n route = route.replace(new RegExp('<(.+?:)' + token + '>'), (args as any)[token]);\n }\n }\n return route;\n }");
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
sourceFile.addStatements("\nimport React from \"react\"\nimport createContext from \"reactivated/context\";\nimport * as forms from \"reactivated/forms\";\nimport * as generated from \"reactivated/generated\";\n\n// Note: this needs strict function types to behave correctly with excess properties etc.\nexport type Checker<P, U extends (React.FunctionComponent<P> | React.ComponentClass<P>)> = {};\n\nexport const {Context, Provider, getServerData} = createContext<_Types[\"Context\"]>();\n\nexport const getTemplate = ({template_name}: {template_name: string}) => {\n // This require needs to be *inside* the function to avoid circular dependencies with esbuild.\n const { default: templates, filenames } = require('../../client/templates/**/*');\n const templatePath = \"../../client/templates/\" + template_name + \".tsx\";\n const possibleTemplate: {default: React.ComponentType<any>} | null = templates.find((t: any, index: number) => filenames[index] === templatePath);\n\n if (possibleTemplate == null) {\n throw new Error(\"Template \" + template_name + \".tsx not found\");\n }\n return possibleTemplate.default;\n}\n\nexport const CSRFToken = forms.createCSRFToken(Context);\n\nexport const {createRenderer, Iterator} = forms.bindWidgetType<_Types[\"globals\"][\"Widget\"]>();\nexport type FieldHandler = forms.FieldHandler<_Types[\"globals\"][\"Widget\"]>;\n\nexport const {Form, FormSet, Widget} = forms;\n");
|
|
93
93
|
// tslint:disable-next-line
|
|
94
94
|
(0, json_schema_to_typescript_1.compile)(types, "_Types").then(function (ts) {
|
|
95
95
|
process.stdout.write("/* eslint-disable */\n");
|
|
@@ -97,8 +97,13 @@ interfaces.addStatements("\nimport React from \"react\"\nimport createContext fr
|
|
|
97
97
|
for (var _i = 0, _a = Object.keys(templates); _i < _a.length; _i++) {
|
|
98
98
|
var name_2 = _a[_i];
|
|
99
99
|
var propsName = templates[name_2];
|
|
100
|
-
|
|
100
|
+
sourceFile.addStatements("\n\nimport ".concat(name_2, "Implementation from \"@client/templates/").concat(name_2, "\"\nexport type ").concat(name_2, "Check = Checker<_Types[\"").concat(propsName, "\"], typeof ").concat(name_2, "Implementation>;\n\nexport namespace templates {\n export type ").concat(name_2, " = _Types[\"").concat(propsName, "\"];\n}\n\n\n "));
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
for (var _b = 0, _c = Object.keys(interfaces); _b < _c.length; _b++) {
|
|
103
|
+
var name_3 = _c[_b];
|
|
104
|
+
var propsName = interfaces[name_3];
|
|
105
|
+
sourceFile.addStatements("\n\nexport namespace interfaces {\n export type ".concat(name_3, " = _Types[\"").concat(propsName, "\"];\n}\n\n\n "));
|
|
106
|
+
}
|
|
107
|
+
process.stdout.write(sourceFile.getText());
|
|
103
108
|
});
|
|
104
109
|
//# sourceMappingURL=generator.js.map
|
package/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAoB;AAGpB,wDAAwD;AACxD,qEAAqE;AACrE,IAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,uEAAkD;AAClD,qCAQkB;AAElB,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,IAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["generator.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAoB;AAGpB,wDAAwD;AACxD,qEAAqE;AACrE,IAAM,WAAW,GAAG,YAAE,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEvC,uEAAkD;AAClD,qCAQkB;AAElB,IAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;AACjD,IAAM,iBAAiB,GAA0C,MAAM,KAAhD,EAAE,SAAS,GAA+B,MAAM,UAArC,EAAE,UAAU,GAAmB,MAAM,WAAzB,EAAE,KAAK,GAAY,MAAM,MAAlB,EAAE,MAAM,GAAI,MAAM,OAAV,CAAW;AAE/E,IAAM,IAAI,yBACH,iBAAiB,KACpB,wBAAwB,EAAE;QACtB,KAAK,EAAE,0BAA0B;QACjC,IAAI,EAAE,EAAE;KACX,EACD,6BAA6B,EAAE;QAC3B,KAAK,EAAE,+BAA+B;QACtC,IAAI,EAAE;YACF,CAAC,EAAE,QAAQ;SACd;KACJ,GACJ,CAAC;AAEF,IAAM,O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