@sealcode/sealgen 0.4.1 → 0.5.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/@types/forms/controls/checkboxed-list-input.d.ts +2 -2
- package/@types/forms/controls/controls.d.ts +1 -0
- package/@types/forms/controls/dropdown.d.ts +2 -2
- package/@types/forms/controls/editable-collection-subset.d.ts +2 -2
- package/@types/forms/controls/form-control.d.ts +2 -2
- package/@types/forms/controls/form-field-control.d.ts +2 -2
- package/@types/forms/controls/form-header.d.ts +4 -4
- package/@types/forms/controls/html.d.ts +9 -0
- package/@types/forms/controls/simple-input.d.ts +4 -2
- package/@types/forms/fields/checkboxed-list.d.ts +7 -7
- package/@types/forms/fields/collection-field.d.ts +3 -3
- package/@types/forms/fields/field.d.ts +6 -6
- package/@types/forms/fields/number.d.ts +3 -3
- package/@types/forms/fields/pick-from-list.d.ts +7 -7
- package/@types/forms/fields/simple-form-field.d.ts +2 -2
- package/@types/forms/form.d.ts +10 -10
- package/@types/index.d.ts +5 -3
- package/@types/make-hidden-inputs.d.ts +5 -4
- package/@types/page/access-control.d.ts +2 -2
- package/@types/page/list.d.ts +14 -14
- package/@types/page/mountable.d.ts +9 -9
- package/@types/page/page.d.ts +6 -6
- package/@types/page/props-parser.d.ts +4 -4
- package/@types/utils/translate.d.ts +3 -0
- package/@types/utils/url-with-new-params.d.ts +2 -2
- package/lib/build.js +4 -3
- package/lib/build.js.map +1 -1
- package/lib/forms/controls/checkboxed-list-input.js.map +1 -1
- package/lib/forms/controls/controls.js +3 -1
- package/lib/forms/controls/controls.js.map +1 -1
- package/lib/forms/controls/dropdown.js.map +1 -1
- package/lib/forms/controls/editable-collection-subset.js.map +1 -1
- package/lib/forms/controls/form-header.js.map +1 -1
- package/lib/forms/controls/html.js +19 -0
- package/lib/forms/controls/html.js.map +1 -0
- package/lib/forms/controls/simple-input.js +4 -2
- package/lib/forms/controls/simple-input.js.map +1 -1
- package/lib/forms/fields/checkboxed-list.js.map +1 -1
- package/lib/forms/fields/collection-field.js.map +1 -1
- package/lib/forms/fields/field.js +5 -1
- package/lib/forms/fields/field.js.map +1 -1
- package/lib/forms/fields/number.js.map +1 -1
- package/lib/forms/fields/pick-from-list.js.map +1 -1
- package/lib/forms/fields/simple-form-field.js.map +1 -1
- package/lib/forms/form.js.map +1 -1
- package/lib/generate-routes.js +22 -13
- package/lib/generate-routes.js.map +1 -1
- package/lib/index.js +16 -2
- package/lib/index.js.map +1 -1
- package/lib/make-hidden-inputs.js.map +1 -1
- package/lib/page/access-control.js.map +1 -1
- package/lib/page/list.js +2 -1
- package/lib/page/list.js.map +1 -1
- package/lib/page/mountable.js.map +1 -1
- package/lib/page/page.js.map +1 -1
- package/lib/page/props-parser.js.map +1 -1
- package/lib/templates/form.js +9 -16
- package/lib/templates/form.js.map +1 -1
- package/lib/templates/list.js +4 -4
- package/lib/templates/list.js.map +1 -1
- package/lib/templates/page.js +3 -3
- package/lib/templates/route-test.js +1 -1
- package/lib/templates/route-test.js.map +1 -1
- package/lib/utils/translate.js +10 -0
- package/lib/utils/translate.js.map +1 -0
- package/lib/utils/url-with-new-params.js.map +1 -1
- package/package.json +3 -3
- package/src/build.ts +4 -3
- package/src/forms/controls/checkboxed-list-input.ts +2 -2
- package/src/forms/controls/controls.ts +1 -0
- package/src/forms/controls/dropdown.ts +2 -2
- package/src/forms/controls/editable-collection-subset.ts +2 -2
- package/src/forms/controls/form-control.ts +2 -2
- package/src/forms/controls/form-field-control.ts +2 -2
- package/src/forms/controls/form-header.ts +3 -3
- package/src/forms/controls/html.ts +18 -0
- package/src/forms/controls/simple-input.ts +7 -6
- package/src/forms/fields/checkboxed-list.ts +5 -5
- package/src/forms/fields/collection-field.ts +3 -3
- package/src/forms/fields/field.ts +17 -7
- package/src/forms/fields/number.ts +3 -3
- package/src/forms/fields/pick-from-list.ts +5 -5
- package/src/forms/fields/simple-form-field.ts +2 -2
- package/src/forms/form.ts +10 -10
- package/src/generate-routes.ts +34 -13
- package/src/index.ts +5 -3
- package/src/make-hidden-inputs.ts +6 -5
- package/src/page/access-control.ts +2 -2
- package/src/page/list.ts +17 -24
- package/src/page/mountable.ts +11 -11
- package/src/page/page.ts +5 -5
- package/src/page/props-parser.ts +4 -7
- package/src/templates/form.ts +9 -16
- package/src/templates/list.ts +4 -4
- package/src/templates/page.ts +3 -3
- package/src/templates/route-test.ts +1 -1
- package/src/utils/translate.ts +13 -0
- package/src/utils/url-with-new-params.ts +2 -2
package/src/page/mountable.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Router from "@koa/router";
|
|
2
2
|
import { FormControl } from "../forms/controls/form-control";
|
|
3
|
-
import {
|
|
4
|
-
import { FlatTemplatable,
|
|
3
|
+
import { Context } from "koa";
|
|
4
|
+
import { FlatTemplatable, tempstream } from "tempstream";
|
|
5
5
|
import { FormField } from "../forms/fields/field";
|
|
6
6
|
import { FormData, FormDataValue, FormMessage } from "../forms/form";
|
|
7
7
|
|
|
@@ -20,19 +20,19 @@ export abstract class Mountable<F extends Fields = Fields> {
|
|
|
20
20
|
abstract mount(router: Router, path: string): void;
|
|
21
21
|
|
|
22
22
|
abstract canAccess(
|
|
23
|
-
ctx:
|
|
23
|
+
ctx: Context
|
|
24
24
|
): Promise<{ canAccess: boolean; message: string }>;
|
|
25
25
|
|
|
26
26
|
abstract renderError(
|
|
27
|
-
ctx:
|
|
27
|
+
ctx: Context,
|
|
28
28
|
error: PageErrorMessage
|
|
29
|
-
): Promise<
|
|
29
|
+
): Promise<FlatTemplatable>;
|
|
30
30
|
|
|
31
|
-
abstract extractRawValues(ctx:
|
|
31
|
+
abstract extractRawValues(ctx: Context): Record<string, FormDataValue>;
|
|
32
32
|
|
|
33
33
|
// this one is meant to be overwritten
|
|
34
34
|
async validateValues(
|
|
35
|
-
ctx:
|
|
35
|
+
ctx: Context,
|
|
36
36
|
data: Record<string, FormDataValue>
|
|
37
37
|
): Promise<{ valid: boolean; error: string }> {
|
|
38
38
|
return {
|
|
@@ -42,7 +42,7 @@ export abstract class Mountable<F extends Fields = Fields> {
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
protected async validate(
|
|
45
|
-
ctx:
|
|
45
|
+
ctx: Context,
|
|
46
46
|
values: Record<string, FormDataValue>
|
|
47
47
|
): Promise<{
|
|
48
48
|
valid: boolean;
|
|
@@ -83,7 +83,7 @@ export abstract class Mountable<F extends Fields = Fields> {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
public renderControls(
|
|
86
|
-
ctx:
|
|
86
|
+
ctx: Context,
|
|
87
87
|
data: FormData<keyof Fields>
|
|
88
88
|
): FlatTemplatable {
|
|
89
89
|
return tempstream/* HTML */ `${this.controls.map((control) =>
|
|
@@ -92,9 +92,9 @@ export abstract class Mountable<F extends Fields = Fields> {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
public renderMessages(
|
|
95
|
-
_:
|
|
95
|
+
_: Context,
|
|
96
96
|
data: FormData<keyof Fields>
|
|
97
|
-
):
|
|
97
|
+
): FlatTemplatable {
|
|
98
98
|
return tempstream/* HTML */ `<div class="form-messages">
|
|
99
99
|
${data.messages.map(
|
|
100
100
|
(message) =>
|
package/src/page/page.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Router from "@koa/router";
|
|
2
|
-
import {
|
|
2
|
+
import { Context } from "koa";
|
|
3
3
|
|
|
4
4
|
import { FlatTemplatable, Templatable, tempstream } from "tempstream";
|
|
5
5
|
import { AllQueryParams } from "..";
|
|
@@ -21,20 +21,20 @@ export abstract class Page<
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
24
|
-
async canAccess(_:
|
|
24
|
+
async canAccess(_: Context) {
|
|
25
25
|
return { canAccess: true, message: "" };
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
async renderError(
|
|
29
|
-
_:
|
|
29
|
+
_: Context,
|
|
30
30
|
error: PageErrorMessage
|
|
31
31
|
): Promise<FlatTemplatable> {
|
|
32
32
|
return tempstream/* HTML */ `<div>${error.message}</div>`;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
public abstract render(ctx:
|
|
35
|
+
public abstract render(ctx: Context): Promise<FlatTemplatable>;
|
|
36
36
|
|
|
37
|
-
extractRawValues(ctx:
|
|
37
|
+
extractRawValues(ctx: Context): Record<string, FormDataValue> {
|
|
38
38
|
return this.propsParser.decode(ctx);
|
|
39
39
|
}
|
|
40
40
|
}
|
package/src/page/props-parser.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from "koa";
|
|
2
2
|
import merge from "merge";
|
|
3
3
|
import { FormData, FormDataValue } from "..";
|
|
4
4
|
import { BasePageProps } from "./list";
|
|
@@ -10,14 +10,11 @@ export type EncodedProps = Record<string, unknown>;
|
|
|
10
10
|
// or any other exotic types is done by fields logic.
|
|
11
11
|
|
|
12
12
|
export abstract class PagePropsParser<PropsType> {
|
|
13
|
-
abstract decode(ctx:
|
|
13
|
+
abstract decode(ctx: Context): Record<string, FormDataValue>;
|
|
14
14
|
abstract encode(props: Record<string, FormData>): EncodedProps;
|
|
15
15
|
abstract getHTMLInputName(prop_name: string): string;
|
|
16
16
|
|
|
17
|
-
overwriteProp(
|
|
18
|
-
ctx: BaseContext,
|
|
19
|
-
new_props: Partial<PropsType>
|
|
20
|
-
): EncodedProps {
|
|
17
|
+
overwriteProp(ctx: Context, new_props: Partial<PropsType>): EncodedProps {
|
|
21
18
|
const result = {};
|
|
22
19
|
merge.recursive(result, this.decode(ctx), new_props);
|
|
23
20
|
return result;
|
|
@@ -27,7 +24,7 @@ export abstract class PagePropsParser<PropsType> {
|
|
|
27
24
|
export class AllQueryParams<
|
|
28
25
|
PropsType extends BasePageProps
|
|
29
26
|
> extends PagePropsParser<PropsType> {
|
|
30
|
-
decode(ctx:
|
|
27
|
+
decode(ctx: Context): Record<string, FormDataValue> {
|
|
31
28
|
return ctx.query;
|
|
32
29
|
}
|
|
33
30
|
|
package/src/templates/form.ts
CHANGED
|
@@ -5,23 +5,16 @@ export async function formTemplate(
|
|
|
5
5
|
newfilefullpath: string
|
|
6
6
|
): Promise<string> {
|
|
7
7
|
const rel = curryImportPath(newfilefullpath);
|
|
8
|
-
return `import {
|
|
9
|
-
import {
|
|
10
|
-
CollectionField,
|
|
11
|
-
Form,
|
|
12
|
-
FormData,
|
|
13
|
-
FormDataValue,
|
|
14
|
-
SimpleFormField,
|
|
15
|
-
SimpleInput,
|
|
16
|
-
} from "@sealcode/sealgen";
|
|
8
|
+
return `import { Context } from "koa";
|
|
9
|
+
import { Form, FormData, FormDataValue, Fields, Controls } from "@sealcode/sealgen";
|
|
17
10
|
import html from "../html";
|
|
18
11
|
import { Users } from "${rel("src/back/collections/collections")}";
|
|
19
12
|
|
|
20
13
|
export const actionName = "${action_name}";
|
|
21
14
|
|
|
22
15
|
const fields = {
|
|
23
|
-
email: new CollectionField(true, Users.fields.email),
|
|
24
|
-
password: new SimpleFormField(true),
|
|
16
|
+
email: new Fields.CollectionField(true, Users.fields.email),
|
|
17
|
+
password: new Fields.SimpleFormField(true),
|
|
25
18
|
};
|
|
26
19
|
|
|
27
20
|
export default new (class ${action_name}Form extends Form<typeof fields> {
|
|
@@ -29,12 +22,12 @@ export default new (class ${action_name}Form extends Form<typeof fields> {
|
|
|
29
22
|
fields = fields;
|
|
30
23
|
|
|
31
24
|
controls = [
|
|
32
|
-
new SimpleInput(fields.email, { label: "Email:", type: "email" }),
|
|
33
|
-
new SimpleInput(fields.password, { label: "Password:", type: "password" }),
|
|
25
|
+
new Controls.SimpleInput(fields.email, { label: "Email:", type: "email" }),
|
|
26
|
+
new Controls.SimpleInput(fields.password, { label: "Password:", type: "password" }),
|
|
34
27
|
];
|
|
35
28
|
|
|
36
29
|
async validateValues(
|
|
37
|
-
ctx:
|
|
30
|
+
ctx: Context,
|
|
38
31
|
data: Record<string, FormDataValue>
|
|
39
32
|
): Promise<{ valid: boolean; error: string }> {
|
|
40
33
|
// just an example
|
|
@@ -48,7 +41,7 @@ export default new (class ${action_name}Form extends Form<typeof fields> {
|
|
|
48
41
|
}
|
|
49
42
|
|
|
50
43
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
51
|
-
async canAccess(_:
|
|
44
|
+
async canAccess(_: Context) {
|
|
52
45
|
return { canAccess: true, message: "" };
|
|
53
46
|
}
|
|
54
47
|
|
|
@@ -57,7 +50,7 @@ export default new (class ${action_name}Form extends Form<typeof fields> {
|
|
|
57
50
|
return;
|
|
58
51
|
}
|
|
59
52
|
|
|
60
|
-
async render(ctx:
|
|
53
|
+
async render(ctx: Context, data: FormData) {
|
|
61
54
|
return html(ctx, "${action_name}", await super.render(ctx, data));
|
|
62
55
|
}
|
|
63
56
|
})();
|
package/src/templates/list.ts
CHANGED
|
@@ -21,13 +21,13 @@ export const listTemplate = async (
|
|
|
21
21
|
const uppercase_collection =
|
|
22
22
|
collection[0].toLocaleUpperCase() + collection.slice(1);
|
|
23
23
|
const rel = curryImportPath(newfilefullpath);
|
|
24
|
-
return `import {
|
|
24
|
+
return `import { Context } from "koa";
|
|
25
25
|
import { CollectionItem } from "sealious";
|
|
26
26
|
import { tempstream } from "tempstream";
|
|
27
27
|
import { ${uppercase_collection} } from "${rel(
|
|
28
28
|
"src/back/collections/collections"
|
|
29
29
|
)}";
|
|
30
|
-
import
|
|
30
|
+
import { ${uppercase_collection} } from "${rel("src/back/html.ts")}";
|
|
31
31
|
import { SealiousItemListPage, BaseListPageFields } from "@sealcode/sealgen";
|
|
32
32
|
|
|
33
33
|
export const actionName = "${action_name}";
|
|
@@ -43,7 +43,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
43
43
|
filterFields = filterFields;
|
|
44
44
|
filterControls = [];
|
|
45
45
|
|
|
46
|
-
async render(ctx:
|
|
46
|
+
async render(ctx: Context) {
|
|
47
47
|
return html(
|
|
48
48
|
ctx,
|
|
49
49
|
"${uppercase_collection}",
|
|
@@ -64,7 +64,7 @@ export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
|
64
64
|
);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
async renderItem(_:
|
|
67
|
+
async renderItem(_: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
68
68
|
return tempstream\`<tr><td>\${item.id}</td>\${Object.keys(${uppercase_collection}.fields).map(
|
|
69
69
|
(fieldname: keyof typeof ${uppercase_collection}["fields"]) =>
|
|
70
70
|
tempstream\`<td>\${item.get(fieldname)}</td>\`
|
package/src/templates/page.ts
CHANGED
|
@@ -4,7 +4,7 @@ export async function pageTemplate(
|
|
|
4
4
|
newfilefullpath: string
|
|
5
5
|
): Promise<string> {
|
|
6
6
|
const rel = curryImportPath(newfilefullpath);
|
|
7
|
-
return `import {
|
|
7
|
+
return `import { Context } from "koa";
|
|
8
8
|
import { tempstream } from "tempstream";
|
|
9
9
|
import { Page } from "@sealcode/sealgen";
|
|
10
10
|
import html from "${rel("src/back/html")}";
|
|
@@ -13,11 +13,11 @@ export const actionName = "${action_name}";
|
|
|
13
13
|
|
|
14
14
|
export default new (class ${action_name}Page extends Page {
|
|
15
15
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
async canAccess(_:
|
|
16
|
+
async canAccess(_: Context) {
|
|
17
17
|
return { canAccess: true, message: "" };
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
async render(ctx:
|
|
20
|
+
async render(ctx: Context) {
|
|
21
21
|
return html(ctx, "${action_name}", tempstream/* HTML */ \`<div></div>\`);
|
|
22
22
|
}
|
|
23
23
|
})();
|
|
@@ -8,7 +8,7 @@ export function testTemplate(action_name: string, new_file_fullpath: string) {
|
|
|
8
8
|
import { LONG_TEST_TIMEOUT, webhintURL } from "${rel(
|
|
9
9
|
"src/back/test_utils/webhint"
|
|
10
10
|
)}";
|
|
11
|
-
import { ${action_name}URL } from "${rel("src/back/routes/
|
|
11
|
+
import { ${action_name}URL } from "${rel("src/back/routes/urls")}";
|
|
12
12
|
|
|
13
13
|
describe("${action_name}", () => {
|
|
14
14
|
it("doesn't crash", async function () {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Context } from "koa";
|
|
2
|
+
import { Translation } from "sealious";
|
|
3
|
+
|
|
4
|
+
export function t(
|
|
5
|
+
ctx: Context,
|
|
6
|
+
key: string,
|
|
7
|
+
props: any[],
|
|
8
|
+
default_translation: Translation
|
|
9
|
+
) {
|
|
10
|
+
return /* HTML */ `<span translation-key="${key.replace('"', '\\"')}"
|
|
11
|
+
>${ctx.$app.getString(key, props, default_translation)}</span
|
|
12
|
+
>`;
|
|
13
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from "koa";
|
|
2
2
|
import qs from "qs";
|
|
3
3
|
|
|
4
4
|
export function UrlWithNewParams(
|
|
5
|
-
ctx:
|
|
5
|
+
ctx: Context,
|
|
6
6
|
query_params: Record<string, unknown>
|
|
7
7
|
): string {
|
|
8
8
|
return `${ctx.path}?${qs.stringify(query_params)}`;
|