@sealcode/sealgen 0.4.2 → 0.5.2
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 +9 -9
- package/@types/index.d.ts +2 -2
- package/@types/make-hidden-inputs.d.ts +4 -3
- package/@types/page/access-control.d.ts +2 -2
- package/@types/page/list.d.ts +14 -14
- package/@types/page/mountable.d.ts +8 -8
- package/@types/page/page.d.ts +5 -5
- package/@types/page/props-parser.d.ts +4 -4
- package/@types/utils/get-prettier-config.d.ts +2 -0
- package/@types/utils/prettier.d.ts +2 -0
- package/@types/utils/translate.d.ts +2 -2
- package/@types/utils/url-with-new-params.d.ts +2 -2
- package/lib/build.js +3 -2
- 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 +3 -1
- 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.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-collections.js +22 -1
- package/lib/generate-collections.js.map +1 -1
- package/lib/generate-routes.js +35 -11
- package/lib/generate-routes.js.map +1 -1
- package/lib/index.js +15 -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.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/get-prettier-config.js +36 -0
- package/lib/utils/get-prettier-config.js.map +1 -0
- package/lib/utils/prettier.js +36 -0
- package/lib/utils/prettier.js.map +1 -0
- package/lib/utils/translate.js.map +1 -1
- package/lib/utils/url-with-new-params.js.map +1 -1
- package/package.json +4 -3
- package/src/build.ts +3 -2
- 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 +6 -5
- package/src/forms/fields/checkboxed-list.ts +5 -5
- package/src/forms/fields/collection-field.ts +3 -3
- package/src/forms/fields/field.ts +6 -6
- 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 +9 -9
- package/src/generate-collections.ts +3 -1
- package/src/generate-routes.ts +31 -13
- package/src/index.ts +2 -2
- package/src/make-hidden-inputs.ts +4 -3
- package/src/page/access-control.ts +2 -2
- package/src/page/list.ts +14 -23
- package/src/page/mountable.ts +9 -9
- 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/prettier.ts +13 -0
- package/src/utils/translate.ts +2 -2
- package/src/utils/url-with-new-params.ts +2 -2
package/src/page/list.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context } from "koa";
|
|
2
2
|
import { Collection, CollectionItem, ItemFields, ItemList } from "sealious";
|
|
3
3
|
|
|
4
4
|
import { Templatable, tempstream, FlatTemplatable } from "tempstream";
|
|
@@ -24,22 +24,19 @@ export abstract class ListPage<
|
|
|
24
24
|
F extends typeof BaseListPageFields
|
|
25
25
|
> extends Page<F> {
|
|
26
26
|
abstract getItems(
|
|
27
|
-
ctx:
|
|
27
|
+
ctx: Context,
|
|
28
28
|
page: number,
|
|
29
29
|
itemsPerPage: number,
|
|
30
30
|
values: Record<string, FormDataValue>
|
|
31
31
|
): Promise<ItemType[]>;
|
|
32
32
|
|
|
33
33
|
abstract getTotalPages(
|
|
34
|
-
ctx:
|
|
34
|
+
ctx: Context,
|
|
35
35
|
itemsPerPage: number,
|
|
36
36
|
values: Record<string, FormDataValue>
|
|
37
37
|
): Promise<number>;
|
|
38
38
|
|
|
39
|
-
abstract renderItem(
|
|
40
|
-
ctx: BaseContext,
|
|
41
|
-
item: ItemType
|
|
42
|
-
): Promise<FlatTemplatable>;
|
|
39
|
+
abstract renderItem(ctx: Context, item: ItemType): Promise<FlatTemplatable>;
|
|
43
40
|
|
|
44
41
|
filterFields: Record<string, FormField> = {};
|
|
45
42
|
filterControls: FormFieldControl[] = [];
|
|
@@ -51,11 +48,11 @@ export abstract class ListPage<
|
|
|
51
48
|
}
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
renderListContainer(_:
|
|
51
|
+
renderListContainer(_: Context, content: Templatable): FlatTemplatable {
|
|
55
52
|
return tempstream`<div>${content}</div>`;
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
async render(ctx:
|
|
55
|
+
async render(ctx: Context): Promise<FlatTemplatable> {
|
|
59
56
|
const values = this.extractRawValues(ctx);
|
|
60
57
|
const { parsed: page } = await this.fields.page.getValue(ctx, values);
|
|
61
58
|
const { parsed: itemsPerPage } =
|
|
@@ -73,7 +70,7 @@ export abstract class ListPage<
|
|
|
73
70
|
}
|
|
74
71
|
|
|
75
72
|
async renderPagination(
|
|
76
|
-
ctx:
|
|
73
|
+
ctx: Context,
|
|
77
74
|
values: Record<string, FormDataValue>
|
|
78
75
|
): Promise<FlatTemplatable> {
|
|
79
76
|
const { parsed: page } = await this.fields.page.getValue(ctx, values);
|
|
@@ -112,7 +109,7 @@ export abstract class ListPage<
|
|
|
112
109
|
</center>`;
|
|
113
110
|
}
|
|
114
111
|
|
|
115
|
-
private renderPageButton(ctx:
|
|
112
|
+
private renderPageButton(ctx: Context, page: number, text: string) {
|
|
116
113
|
return /* HTML */ `<a
|
|
117
114
|
href="${UrlWithNewParams(
|
|
118
115
|
ctx,
|
|
@@ -125,7 +122,7 @@ export abstract class ListPage<
|
|
|
125
122
|
>`;
|
|
126
123
|
}
|
|
127
124
|
|
|
128
|
-
async getFilterValues(ctx:
|
|
125
|
+
async getFilterValues(ctx: Context): Promise<Record<string, unknown>> {
|
|
129
126
|
const filter = {} as Record<string, unknown>;
|
|
130
127
|
const raw_values = this.extractRawValues(ctx);
|
|
131
128
|
for (const [fieldname, field] of Object.entries(this.filterFields)) {
|
|
@@ -136,7 +133,7 @@ export abstract class ListPage<
|
|
|
136
133
|
return filter;
|
|
137
134
|
}
|
|
138
135
|
|
|
139
|
-
renderFilters(ctx:
|
|
136
|
+
renderFilters(ctx: Context): FlatTemplatable {
|
|
140
137
|
const values = this.extractRawValues(ctx);
|
|
141
138
|
return tempstream/* HTML */ `<form method="GET">
|
|
142
139
|
${makeHiddenInputs(ctx, this.fields, values, [
|
|
@@ -159,20 +156,14 @@ export abstract class SealiousItemListPage<
|
|
|
159
156
|
super();
|
|
160
157
|
}
|
|
161
158
|
|
|
162
|
-
async getTotalPages(
|
|
163
|
-
ctx: BaseContext,
|
|
164
|
-
itemsPerPage: number
|
|
165
|
-
): Promise<number> {
|
|
159
|
+
async getTotalPages(ctx: Context, itemsPerPage: number): Promise<number> {
|
|
166
160
|
const query = this.collection.list(ctx.$context);
|
|
167
161
|
await this.addFilter(ctx, query);
|
|
168
162
|
const { items } = await query.fetch();
|
|
169
163
|
return Math.ceil(items.length / itemsPerPage);
|
|
170
164
|
}
|
|
171
165
|
|
|
172
|
-
protected async addFilter(
|
|
173
|
-
ctx: BaseContext,
|
|
174
|
-
list: ItemList<C>
|
|
175
|
-
): Promise<void> {
|
|
166
|
+
protected async addFilter(ctx: Context, list: ItemList<C>): Promise<void> {
|
|
176
167
|
const filters = await this.getFilterValues(ctx);
|
|
177
168
|
if (Object.keys(filters).length) {
|
|
178
169
|
list.filter(filters as Partial<ItemFields<C>>);
|
|
@@ -180,7 +171,7 @@ export abstract class SealiousItemListPage<
|
|
|
180
171
|
}
|
|
181
172
|
|
|
182
173
|
async getItems(
|
|
183
|
-
ctx:
|
|
174
|
+
ctx: Context,
|
|
184
175
|
page: number,
|
|
185
176
|
itemsPerPage: number
|
|
186
177
|
): Promise<CollectionItem<C>[]> {
|
|
@@ -193,7 +184,7 @@ export abstract class SealiousItemListPage<
|
|
|
193
184
|
}
|
|
194
185
|
|
|
195
186
|
async renderItem(
|
|
196
|
-
_:
|
|
187
|
+
_: Context,
|
|
197
188
|
item: CollectionItem<C>
|
|
198
189
|
): Promise<FlatTemplatable> {
|
|
199
190
|
return `<div>${item.id}</div>`;
|
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
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,7 +92,7 @@ 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">
|
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 * as prettier from "prettier";
|
|
2
|
+
import { Options } from "prettier";
|
|
3
|
+
import _locreq from "locreq";
|
|
4
|
+
const target_locreq = _locreq(process.cwd());
|
|
5
|
+
|
|
6
|
+
export async function getPrettierConfig(): Promise<Options> {
|
|
7
|
+
return {
|
|
8
|
+
...(await prettier.resolveConfig(
|
|
9
|
+
target_locreq.resolve("src/back/routes")
|
|
10
|
+
)),
|
|
11
|
+
parser: "typescript",
|
|
12
|
+
};
|
|
13
|
+
}
|
package/src/utils/translate.ts
CHANGED
|
@@ -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)}`;
|