@sealcode/sealgen 0.12.0 → 0.12.3
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/notifier.js +1 -1
- package/package.json +2 -2
- package/src/notifier.ts +1 -1
- package/.madgerc +0 -7
- package/coverage/.tmp/coverage-15.json +0 -1
- package/coverage/.tmp/coverage-16.json +0 -1
- package/coverage/.tmp/coverage-17.json +0 -1
- package/coverage/.tmp/coverage-18.json +0 -1
- package/coverage/.tmp/coverage-19.json +0 -1
- package/coverage/.tmp/coverage-20.json +0 -1
- package/coverage/.tmp/coverage-21.json +0 -1
- package/coverage/.tmp/coverage-22.json +0 -1
- package/coverage/.tmp/coverage-23.json +0 -1
- package/coverage/.tmp/coverage-24.json +0 -1
- package/coverage/.tmp/coverage-25.json +0 -1
- package/coverage/.tmp/coverage-26.json +0 -1
- package/lib/add-collection.js +0 -24
- package/lib/add-jdd-component.js +0 -27
- package/lib/add-route.js +0 -65
- package/lib/add-route.test.js +0 -60
- package/lib/build.js +0 -187
- package/lib/cli.js +0 -35
- package/lib/components/components.js +0 -3
- package/lib/components/tabs.js +0 -88
- package/lib/components/toggle-modal.js +0 -46
- package/lib/example.test.js +0 -5
- package/lib/find-css-includes.js +0 -23
- package/lib/forms/controls/array.js +0 -140
- package/lib/forms/controls/autocomplete.js +0 -23
- package/lib/forms/controls/big-radio-group.js +0 -34
- package/lib/forms/controls/checkbox-group.js +0 -29
- package/lib/forms/controls/checkbox.js +0 -24
- package/lib/forms/controls/checkboxed-list-input.js +0 -35
- package/lib/forms/controls/collapsible-checkbox-group.js +0 -13
- package/lib/forms/controls/collapsible-field-group.js +0 -78
- package/lib/forms/controls/controls.js +0 -31
- package/lib/forms/controls/derived-frame.js +0 -52
- package/lib/forms/controls/derived.js +0 -77
- package/lib/forms/controls/dropdown.js +0 -55
- package/lib/forms/controls/editable-collection-subset.js +0 -68
- package/lib/forms/controls/field-group.js +0 -53
- package/lib/forms/controls/file.js +0 -35
- package/lib/forms/controls/form-control.js +0 -14
- package/lib/forms/controls/form-field-control.js +0 -9
- package/lib/forms/controls/form-header.js +0 -14
- package/lib/forms/controls/form-paragraph.js +0 -12
- package/lib/forms/controls/frame.js +0 -25
- package/lib/forms/controls/hidden-input.js +0 -14
- package/lib/forms/controls/html.js +0 -23
- package/lib/forms/controls/multiple-files.js +0 -160
- package/lib/forms/controls/multiple-photos.js +0 -33
- package/lib/forms/controls/number.js +0 -25
- package/lib/forms/controls/photo.js +0 -57
- package/lib/forms/controls/radio.js +0 -25
- package/lib/forms/controls/reverse-single-reference.js +0 -47
- package/lib/forms/controls/simple-input.js +0 -78
- package/lib/forms/controls/textarea.js +0 -33
- package/lib/forms/controls/tickable.js +0 -75
- package/lib/forms/fields/boolean.js +0 -51
- package/lib/forms/fields/boolean.test.js +0 -32
- package/lib/forms/fields/checkboxed-list.js +0 -40
- package/lib/forms/fields/collection-field.js +0 -29
- package/lib/forms/fields/email.js +0 -11
- package/lib/forms/fields/email.test.js +0 -20
- package/lib/forms/fields/enum-multiple.js +0 -47
- package/lib/forms/fields/enum-multiple.test.js +0 -27
- package/lib/forms/fields/enum.js +0 -39
- package/lib/forms/fields/enum.test.js +0 -21
- package/lib/forms/fields/existing-sealious-value.js +0 -16
- package/lib/forms/fields/field.js +0 -81
- package/lib/forms/fields/file.js +0 -53
- package/lib/forms/fields/multiple-files.js +0 -15
- package/lib/forms/fields/number.js +0 -45
- package/lib/forms/fields/number.test.js +0 -30
- package/lib/forms/fields/pick-from-list.js +0 -31
- package/lib/forms/fields/pick-from-list.test.js +0 -17
- package/lib/forms/fields/proxy-field.js +0 -20
- package/lib/forms/fields/regexp.js +0 -40
- package/lib/forms/fields/regexp.test.js +0 -21
- package/lib/forms/fields/reverse-single-reference.js +0 -14
- package/lib/forms/fields/simple-form-field.js +0 -20
- package/lib/forms/fields/structured-array.js +0 -18
- package/lib/forms/form.js +0 -176
- package/lib/forms/form.test.js +0 -1
- package/lib/forms/multiform.js +0 -174
- package/lib/forms/multiform.test.js +0 -426
- package/lib/generate-collections.js +0 -52
- package/lib/generate-components.js +0 -33
- package/lib/generate-routes.js +0 -75
- package/lib/index.js +0 -17
- package/lib/make-env.js +0 -14
- package/lib/make-hidden-inputs.js +0 -14
- package/lib/mount.js +0 -70
- package/lib/notifier.js +0 -19
- package/lib/page/access-control.js +0 -16
- package/lib/page/default-list-filters.js +0 -40
- package/lib/page/list.js +0 -183
- package/lib/page/mountable-with-fields.js +0 -85
- package/lib/page/mountable.js +0 -5
- package/lib/page/page.js +0 -26
- package/lib/page/props-parser.js +0 -23
- package/lib/page/sealious-list.js +0 -59
- package/lib/page/stateful-page.js +0 -97
- package/lib/remove-named-imports.js +0 -47
- package/lib/run.js +0 -2
- package/lib/sanitize.js +0 -10
- package/lib/src/add-collection.js +0 -24
- package/lib/src/add-jdd-component.js +0 -27
- package/lib/src/add-route.js +0 -65
- package/lib/src/add-route.test.js +0 -72
- package/lib/src/build.js +0 -142
- package/lib/src/cli.js +0 -37
- package/lib/src/components/components.js +0 -3
- package/lib/src/components/tabs.js +0 -88
- package/lib/src/components/toggle-modal.js +0 -46
- package/lib/src/example.test.js +0 -5
- package/lib/src/find-css-includes.js +0 -23
- package/lib/src/forms/controls/array.js +0 -141
- package/lib/src/forms/controls/autocomplete.js +0 -23
- package/lib/src/forms/controls/big-radio-group.js +0 -34
- package/lib/src/forms/controls/checkbox-group.js +0 -30
- package/lib/src/forms/controls/checkbox.js +0 -24
- package/lib/src/forms/controls/checkboxed-list-input.js +0 -35
- package/lib/src/forms/controls/collapsible-checkbox-group.js +0 -13
- package/lib/src/forms/controls/collapsible-field-group.js +0 -78
- package/lib/src/forms/controls/controls.js +0 -31
- package/lib/src/forms/controls/derived-frame.js +0 -52
- package/lib/src/forms/controls/derived.js +0 -77
- package/lib/src/forms/controls/dropdown.js +0 -55
- package/lib/src/forms/controls/editable-collection-subset.js +0 -68
- package/lib/src/forms/controls/field-group.js +0 -53
- package/lib/src/forms/controls/file.js +0 -35
- package/lib/src/forms/controls/form-control.js +0 -14
- package/lib/src/forms/controls/form-field-control.js +0 -9
- package/lib/src/forms/controls/form-header.js +0 -14
- package/lib/src/forms/controls/form-paragraph.js +0 -12
- package/lib/src/forms/controls/frame.js +0 -25
- package/lib/src/forms/controls/hidden-input.js +0 -14
- package/lib/src/forms/controls/html.js +0 -23
- package/lib/src/forms/controls/multiple-files.js +0 -160
- package/lib/src/forms/controls/multiple-photos.js +0 -33
- package/lib/src/forms/controls/number.js +0 -25
- package/lib/src/forms/controls/photo.js +0 -57
- package/lib/src/forms/controls/radio.js +0 -25
- package/lib/src/forms/controls/reverse-single-reference.js +0 -47
- package/lib/src/forms/controls/simple-input.js +0 -78
- package/lib/src/forms/controls/textarea.js +0 -33
- package/lib/src/forms/controls/tickable.js +0 -75
- package/lib/src/forms/fields/boolean.js +0 -51
- package/lib/src/forms/fields/boolean.test.js +0 -33
- package/lib/src/forms/fields/checkboxed-list.js +0 -40
- package/lib/src/forms/fields/collection-field.js +0 -29
- package/lib/src/forms/fields/email.js +0 -11
- package/lib/src/forms/fields/email.test.js +0 -20
- package/lib/src/forms/fields/enum-multiple.js +0 -47
- package/lib/src/forms/fields/enum-multiple.test.js +0 -27
- package/lib/src/forms/fields/enum.js +0 -39
- package/lib/src/forms/fields/enum.test.js +0 -21
- package/lib/src/forms/fields/existing-sealious-value.js +0 -16
- package/lib/src/forms/fields/field.js +0 -66
- package/lib/src/forms/fields/fields.js +0 -16
- package/lib/src/forms/fields/file.js +0 -53
- package/lib/src/forms/fields/multiple-files.js +0 -15
- package/lib/src/forms/fields/number.js +0 -45
- package/lib/src/forms/fields/number.test.js +0 -31
- package/lib/src/forms/fields/pick-from-list.js +0 -31
- package/lib/src/forms/fields/pick-from-list.test.js +0 -17
- package/lib/src/forms/fields/proxy-field.js +0 -20
- package/lib/src/forms/fields/regexp.js +0 -40
- package/lib/src/forms/fields/regexp.test.js +0 -21
- package/lib/src/forms/fields/reverse-single-reference.js +0 -14
- package/lib/src/forms/fields/simple-form-field.js +0 -19
- package/lib/src/forms/fields/structured-array.js +0 -18
- package/lib/src/forms/form-types.js +0 -2
- package/lib/src/forms/form.js +0 -176
- package/lib/src/forms/form.test.js +0 -271
- package/lib/src/forms/multiform.js +0 -174
- package/lib/src/forms/multiform.test.js +0 -430
- package/lib/src/generate-collections.js +0 -52
- package/lib/src/generate-components.js +0 -33
- package/lib/src/generate-routes.js +0 -75
- package/lib/src/hehe.test.js +0 -7
- package/lib/src/index.js +0 -19
- package/lib/src/make-env.js +0 -14
- package/lib/src/make-hidden-inputs.js +0 -14
- package/lib/src/mount.js +0 -70
- package/lib/src/notifier.js +0 -19
- package/lib/src/page/access-control.js +0 -16
- package/lib/src/page/default-list-filters.js +0 -40
- package/lib/src/page/list.js +0 -184
- package/lib/src/page/mountable-with-fields.js +0 -85
- package/lib/src/page/mountable.js +0 -5
- package/lib/src/page/page.js +0 -26
- package/lib/src/page/props-parser.js +0 -23
- package/lib/src/page/sealious-list.js +0 -59
- package/lib/src/page/stateful-page.js +0 -97
- package/lib/src/run.js +0 -2
- package/lib/src/sample-index.js +0 -3
- package/lib/src/sample-lib.js +0 -6
- package/lib/src/sanitize.js +0 -10
- package/lib/src/templates/collection.js +0 -12
- package/lib/src/templates/form.js +0 -57
- package/lib/src/templates/jdd-component.js +0 -39
- package/lib/src/templates/list.js +0 -139
- package/lib/src/templates/long-running-process.js +0 -60
- package/lib/src/templates/multiform.js +0 -55
- package/lib/src/templates/page.js +0 -23
- package/lib/src/templates/post.js +0 -22
- package/lib/src/templates/redirect.js +0 -23
- package/lib/src/templates/route-test.js +0 -54
- package/lib/src/templates/stateful-page.js +0 -66
- package/lib/src/templates/templates.js +0 -21
- package/lib/src/test_utils/locator_is_visible.js +0 -11
- package/lib/src/utils/assert-throws.js +0 -17
- package/lib/src/utils/base64.js +0 -7
- package/lib/src/utils/browser-creator.js +0 -10
- package/lib/src/utils/escape-url-params.js +0 -14
- package/lib/src/utils/exec.js +0 -22
- package/lib/src/utils/extract-fields-from-collection.js +0 -26
- package/lib/src/utils/format-external-url.js +0 -11
- package/lib/src/utils/import-path.js +0 -16
- package/lib/src/utils/input-wrapper.js +0 -15
- package/lib/src/utils/list-collections.js +0 -13
- package/lib/src/utils/make-slug.js +0 -6
- package/lib/src/utils/natural-numbers.js +0 -6
- package/lib/src/utils/prettier.js +0 -10
- package/lib/src/utils/question.js +0 -19
- package/lib/src/utils/render-attributes.js +0 -19
- package/lib/src/utils/sleep.js +0 -4
- package/lib/src/utils/translate.js +0 -6
- package/lib/src/utils/url-with-new-params.js +0 -5
- package/lib/src/utils/utils.js +0 -16
- package/lib/src/utils/walk.js +0 -23
- package/lib/src/vitest.config.js +0 -20
- package/lib/templates/collection.js +0 -12
- package/lib/templates/form.js +0 -57
- package/lib/templates/jdd-component.js +0 -39
- package/lib/templates/list.js +0 -139
- package/lib/templates/long-running-process.js +0 -60
- package/lib/templates/multiform.js +0 -55
- package/lib/templates/page.js +0 -23
- package/lib/templates/post.js +0 -22
- package/lib/templates/redirect.js +0 -23
- package/lib/templates/route-test.js +0 -54
- package/lib/templates/stateful-page.js +0 -66
- package/lib/templates/templates.js +0 -21
- package/lib/test_utils/locator_is_visible.js +0 -11
- package/lib/utils/assert-throws.js +0 -17
- package/lib/utils/base64.js +0 -7
- package/lib/utils/browser-creator.js +0 -10
- package/lib/utils/escape-url-params.js +0 -14
- package/lib/utils/exec.js +0 -22
- package/lib/utils/extract-fields-from-collection.js +0 -26
- package/lib/utils/format-external-url.js +0 -11
- package/lib/utils/import-path.js +0 -16
- package/lib/utils/input-wrapper.js +0 -15
- package/lib/utils/list-collections.js +0 -13
- package/lib/utils/make-slug.js +0 -6
- package/lib/utils/natural-numbers.js +0 -6
- package/lib/utils/prettier.js +0 -10
- package/lib/utils/question.js +0 -19
- package/lib/utils/render-attributes.js +0 -19
- package/lib/utils/sleep.js +0 -4
- package/lib/utils/translate.js +0 -6
- package/lib/utils/url-with-new-params.js +0 -5
- package/lib/utils/utils.js +0 -16
- package/lib/utils/walk.js +0 -23
- package/lib/vitest.config.js +0 -22
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { predicates, hasShape, is } from "@sealcode/ts-predicates";
|
|
2
|
-
import deepmerge from "deepmerge";
|
|
3
|
-
import { tempstream } from "tempstream";
|
|
4
|
-
import { from_base64, to_base64 } from "../utils/base64.js";
|
|
5
|
-
import { Mountable } from "./mountable.js";
|
|
6
|
-
export class StatefulPage extends Mountable {
|
|
7
|
-
async canAccess() {
|
|
8
|
-
return { canAccess: true, message: "" };
|
|
9
|
-
}
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
const original_render = this.render.bind(this);
|
|
13
|
-
this.render = async (ctx, state, inputs) => {
|
|
14
|
-
return this.wrapInLayout(ctx, this.wrapInForm(state, await original_render(ctx, state, inputs)));
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
wrapInForm(state, content) {
|
|
18
|
-
return tempstream /* HTML */ `<form action="./" method="POST">
|
|
19
|
-
<input
|
|
20
|
-
name="state"
|
|
21
|
-
type="hidden"
|
|
22
|
-
value="${to_base64(JSON.stringify(state))}"
|
|
23
|
-
/>
|
|
24
|
-
${content}
|
|
25
|
-
</form>`;
|
|
26
|
-
}
|
|
27
|
-
makeActionButton(state, action_description, ...args) {
|
|
28
|
-
let label, action;
|
|
29
|
-
if (is(action_description, predicates.object)) {
|
|
30
|
-
action = action_description.action.toString();
|
|
31
|
-
label = action_description.label || action;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
action = action_description.toString();
|
|
35
|
-
label = action;
|
|
36
|
-
}
|
|
37
|
-
return /* HTML */ `
|
|
38
|
-
<input
|
|
39
|
-
type="submit"
|
|
40
|
-
value=${label}
|
|
41
|
-
formaction="./?action=${action}&args=${to_base64(JSON.stringify(args))}"
|
|
42
|
-
/>
|
|
43
|
-
`;
|
|
44
|
-
}
|
|
45
|
-
extractState(ctx) {
|
|
46
|
-
if (!hasShape({
|
|
47
|
-
action: predicates.maybe(predicates.string),
|
|
48
|
-
state: predicates.string,
|
|
49
|
-
args: predicates.maybe(predicates.string),
|
|
50
|
-
$: predicates.maybe(predicates.object),
|
|
51
|
-
}, ctx.$body)) {
|
|
52
|
-
console.error("Wrong data: ", ctx.$body);
|
|
53
|
-
throw new Error("wrong formdata shape");
|
|
54
|
-
}
|
|
55
|
-
const inputs = Object.fromEntries(Object.entries(ctx.$body).filter(([key]) => !["action", "state", "args", "$"].includes(key)));
|
|
56
|
-
// the "$" key is parsed as dot notation and overrides the state
|
|
57
|
-
const original_state = JSON.parse(from_base64(ctx.$body.state));
|
|
58
|
-
const modified_state = deepmerge(original_state, ctx.$body.$ || {}, {
|
|
59
|
-
arrayMerge: (_target, source, _options) => {
|
|
60
|
-
// https://github.com/TehShrike/deepmerge#user-content-arraymerge-example-combine-arrays
|
|
61
|
-
return source;
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
if (ctx.$body.action && ctx.$body.args) {
|
|
65
|
-
return {
|
|
66
|
-
state: modified_state,
|
|
67
|
-
action: ctx.$body.action,
|
|
68
|
-
inputs,
|
|
69
|
-
action_args: ctx.$body.args,
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
73
|
-
return {
|
|
74
|
-
state: modified_state,
|
|
75
|
-
action: null,
|
|
76
|
-
action_args: null,
|
|
77
|
-
inputs,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
mount(router, path) {
|
|
82
|
-
router.get(path, (ctx) => {
|
|
83
|
-
ctx.body = this.render(ctx, this.getInitialState(), {});
|
|
84
|
-
});
|
|
85
|
-
router.post(path, (ctx) => {
|
|
86
|
-
const { action, state, inputs, action_args } = this.extractState(ctx);
|
|
87
|
-
if (action) {
|
|
88
|
-
ctx.body = this.render(ctx, this.actions[action](state, inputs, ...JSON.parse(from_base64(action_args))), inputs);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
ctx.body = this.render(ctx, state, inputs);
|
|
92
|
-
}
|
|
93
|
-
ctx.status = 433;
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
//# sourceMappingURL=stateful-page.js.map
|
package/lib/src/run.js
DELETED
package/lib/src/sample-index.js
DELETED
package/lib/src/sample-lib.js
DELETED
package/lib/src/sanitize.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export function collectionTemplate(collection_name) {
|
|
2
|
-
return `import { Collection, FieldTypes, Policies } from "sealious";
|
|
3
|
-
|
|
4
|
-
export default class ${collection_name} extends Collection {
|
|
5
|
-
fields = {
|
|
6
|
-
content: new FieldTypes.Text(),
|
|
7
|
-
};
|
|
8
|
-
defaultPolicy = new Policies.Public();
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=collection.js.map
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
-
export async function formTemplate(action_name, newfilefullpath) {
|
|
3
|
-
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { Context } from "koa";
|
|
5
|
-
import { Form, FormData, FormDataValue, Fields, Controls } from "@sealcode/sealgen";
|
|
6
|
-
import html from "${rel("src/back/html.js")}";
|
|
7
|
-
import { Users } from "${rel("src/back/collections/collections.js")}";
|
|
8
|
-
|
|
9
|
-
export const actionName = "${action_name}";
|
|
10
|
-
|
|
11
|
-
const fields = {
|
|
12
|
-
email: new Fields.CollectionField(true, Users.fields.email),
|
|
13
|
-
password: new Fields.SimpleFormField(true),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const ${action_name}Shape = Fields.fieldsToShape(fields);
|
|
17
|
-
|
|
18
|
-
export default new (class ${action_name}Form extends Form<typeof fields, void> {
|
|
19
|
-
defaultSuccessMessage = "Formularz wypełniony poprawnie";
|
|
20
|
-
fields = fields;
|
|
21
|
-
|
|
22
|
-
controls = [
|
|
23
|
-
new Controls.SimpleInput(fields.email, { label: "Email:", type: "email" }),
|
|
24
|
-
new Controls.SimpleInput(fields.password, { label: "Password:", type: "password" }),
|
|
25
|
-
];
|
|
26
|
-
|
|
27
|
-
async validateValues(
|
|
28
|
-
ctx: Context,
|
|
29
|
-
data: Record<string, FormDataValue>
|
|
30
|
-
): Promise<{ valid: boolean; error: string }> {
|
|
31
|
-
// just an example
|
|
32
|
-
const { parsed: email } = await this.fields.email.getValue(ctx, data);
|
|
33
|
-
const { parsed: password } = await this.fields.password.getValue(ctx, data);
|
|
34
|
-
if ((password || "").length > (email || "").length) {
|
|
35
|
-
return { valid: false, error: "Password cannot be longer than email" };
|
|
36
|
-
} else {
|
|
37
|
-
return { valid: true, error: "" };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
42
|
-
async canAccess(_: Context) {
|
|
43
|
-
return { canAccess: true, message: "" };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async onSubmit() {
|
|
47
|
-
//noop
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async render(ctx: Context, data: FormData, show_field_errors: boolean) {
|
|
52
|
-
return html(ctx, "${action_name}", await super.render(ctx, data, show_field_errors));
|
|
53
|
-
}
|
|
54
|
-
})();
|
|
55
|
-
`;
|
|
56
|
-
}
|
|
57
|
-
//# sourceMappingURL=form.js.map
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
export function jddComponentTemplate(component_name) {
|
|
3
|
-
return `import { FlatTemplatable, TempstreamJSX } from "tempstream";
|
|
4
|
-
import {
|
|
5
|
-
Component,
|
|
6
|
-
ComponentArguments,
|
|
7
|
-
ExtractStructuredComponentArgumentsValues,
|
|
8
|
-
JDDContext,
|
|
9
|
-
} from "@sealcode/jdd";
|
|
10
|
-
|
|
11
|
-
const component_arguments = {
|
|
12
|
-
title: new ComponentArguments.ShortText(),
|
|
13
|
-
content: new ComponentArguments.Markdown(),
|
|
14
|
-
} as const;
|
|
15
|
-
|
|
16
|
-
export class ${toPascalCase(component_name)} extends Component<typeof component_arguments> {
|
|
17
|
-
getArguments() {
|
|
18
|
-
return component_arguments;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
toHTML(
|
|
22
|
-
{
|
|
23
|
-
title,
|
|
24
|
-
content,
|
|
25
|
-
}: ExtractStructuredComponentArgumentsValues<typeof component_arguments>,
|
|
26
|
-
{ render_markdown }: JDDContext
|
|
27
|
-
): FlatTemplatable {
|
|
28
|
-
return (
|
|
29
|
-
<div class="${toKebabCase(component_name)}">
|
|
30
|
-
<h2>{title} • ${toPascalCase(component_name)} </h2>
|
|
31
|
-
<div>{render_markdown(content)}</div>
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
`;
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=jdd-component.js.map
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import _locreq from "locreq";
|
|
2
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
3
|
-
import prompts from "prompts";
|
|
4
|
-
import { listCollections } from "../utils/list-collections.js";
|
|
5
|
-
import { extractCollectionClassname } from "../generate-collections.js";
|
|
6
|
-
import extract_fields_from_collection from "../utils/extract-fields-from-collection.js";
|
|
7
|
-
import { DefaultListFilters } from "../page/default-list-filters.js";
|
|
8
|
-
const target_locreq = _locreq(process.cwd());
|
|
9
|
-
export const listTemplate = async (action_name, newfilefullpath) => {
|
|
10
|
-
const response = await prompts({
|
|
11
|
-
type: "autocomplete",
|
|
12
|
-
name: "collection",
|
|
13
|
-
message: "Which sealious collection do you want to list?",
|
|
14
|
-
choices: (await listCollections()).map((collection) => ({
|
|
15
|
-
title: collection,
|
|
16
|
-
value: collection,
|
|
17
|
-
})),
|
|
18
|
-
});
|
|
19
|
-
const collection_name = response.collection;
|
|
20
|
-
const [uppercase_collection, collection_fields] = await Promise.all([
|
|
21
|
-
extractCollectionClassname(target_locreq.resolve("src/back/collections/" + collection_name + ".ts")),
|
|
22
|
-
extract_fields_from_collection(collection_name),
|
|
23
|
-
]);
|
|
24
|
-
const rel = curryImportPath(newfilefullpath);
|
|
25
|
-
return `import { Context } from "koa";
|
|
26
|
-
import { CollectionItem } from "sealious";
|
|
27
|
-
import { FlatTemplatable, TempstreamJSX } from "tempstream";
|
|
28
|
-
import { ${uppercase_collection} } from "${rel("src/back/collections/collections.js")}";
|
|
29
|
-
import html from "${rel("src/back/html.js")}";
|
|
30
|
-
import {
|
|
31
|
-
SealiousItemListPage,
|
|
32
|
-
BaseListPageFields,
|
|
33
|
-
DefaultListFilters,
|
|
34
|
-
ListFilterRender,
|
|
35
|
-
} from "@sealcode/sealgen";;
|
|
36
|
-
import qs from "qs";
|
|
37
|
-
import { is, predicates } from "@sealcode/ts-predicates";
|
|
38
|
-
|
|
39
|
-
export const actionName = "${action_name}";
|
|
40
|
-
|
|
41
|
-
const filterFields = [
|
|
42
|
-
${collection_fields
|
|
43
|
-
.map((field) => ` { field: "${field.name}", render: ${DefaultListFilters[field.type]
|
|
44
|
-
? `DefaultListFilters["${field.type}"]`
|
|
45
|
-
: `DefaultListFilters.fallback`} }`)
|
|
46
|
-
.join(",\n")}
|
|
47
|
-
] as {
|
|
48
|
-
field: keyof (typeof ${uppercase_collection})["fields"];
|
|
49
|
-
render?: ListFilterRender;
|
|
50
|
-
}[];
|
|
51
|
-
|
|
52
|
-
const displayFields = [
|
|
53
|
-
${collection_fields
|
|
54
|
-
.map((field) => {
|
|
55
|
-
if (field.type == "boolean") {
|
|
56
|
-
return ` {
|
|
57
|
-
field: "${field.name}",
|
|
58
|
-
label: "${field.name}",
|
|
59
|
-
format: (v: boolean) => (v ? "YES" : "NO"),
|
|
60
|
-
}`;
|
|
61
|
-
}
|
|
62
|
-
if (field.type == "datetime") {
|
|
63
|
-
return ` {
|
|
64
|
-
field: "${field.name}",
|
|
65
|
-
label: "${field.name}",
|
|
66
|
-
format: (v: number) => {
|
|
67
|
-
const d = new Date();
|
|
68
|
-
d.setTime(v);
|
|
69
|
-
return d.toString().split(" ").slice(1, 5).join(" ");
|
|
70
|
-
},
|
|
71
|
-
}`;
|
|
72
|
-
}
|
|
73
|
-
return ` { field: "${field.name}", label: "${field.name}" }`;
|
|
74
|
-
})
|
|
75
|
-
.join(",\n")}
|
|
76
|
-
];
|
|
77
|
-
|
|
78
|
-
export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
79
|
-
typeof ${uppercase_collection},
|
|
80
|
-
typeof BaseListPageFields
|
|
81
|
-
> {
|
|
82
|
-
fields = BaseListPageFields;
|
|
83
|
-
|
|
84
|
-
async renderFilters(ctx: Context): Promise<FlatTemplatable> {
|
|
85
|
-
const query_params = qs.parse(ctx.search.slice(1));
|
|
86
|
-
query_params.page = "1";
|
|
87
|
-
const filter_values = await this.getFilterValues(ctx);
|
|
88
|
-
return <form>
|
|
89
|
-
{Object.entries(query_params).map(([key, value]) => {
|
|
90
|
-
if (key == "filter") {
|
|
91
|
-
return "";
|
|
92
|
-
}
|
|
93
|
-
return <input
|
|
94
|
-
type="hidden"
|
|
95
|
-
name="\${key}"
|
|
96
|
-
value="\${value}"
|
|
97
|
-
/>;
|
|
98
|
-
})}
|
|
99
|
-
{filterFields.map(({ field, render }) => {
|
|
100
|
-
if (!render) {
|
|
101
|
-
render = DefaultListFilters.fallback;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
render(filter_values[field] || "", this.collection.fields[field]) ||
|
|
106
|
-
""
|
|
107
|
-
);
|
|
108
|
-
})}
|
|
109
|
-
<input type="submit" />
|
|
110
|
-
</form>;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
async renderItem(_: Context, item: CollectionItem<typeof ${uppercase_collection}>) {
|
|
114
|
-
return <tr>
|
|
115
|
-
{displayFields.map(({ field, format }) => {
|
|
116
|
-
const value = item.get(field as any);
|
|
117
|
-
return <td>{format ? format(value) : value}</td>;
|
|
118
|
-
})}
|
|
119
|
-
</tr>;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async render(ctx: Context) {
|
|
123
|
-
return html(
|
|
124
|
-
ctx,
|
|
125
|
-
"${action_name}",
|
|
126
|
-
<div>
|
|
127
|
-
<h2>${action_name} List</h2>
|
|
128
|
-
<table class="sealious-list">
|
|
129
|
-
{this.renderTableHead(ctx, displayFields)}
|
|
130
|
-
<tbody>{super.render(ctx)}</tbody>
|
|
131
|
-
</table>
|
|
132
|
-
</div>
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
})(${uppercase_collection});
|
|
137
|
-
`;
|
|
138
|
-
};
|
|
139
|
-
//# sourceMappingURL=list.js.map
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
-
export async function LongRunningProcessTemplate(action_name, newfilefullpath) {
|
|
3
|
-
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { Context } from "koa";
|
|
5
|
-
import { TempstreamJSX } from "tempstream";
|
|
6
|
-
import { Page } from "@sealcode/sealgen";
|
|
7
|
-
import html from "${rel("src/back/html.js")}";
|
|
8
|
-
import { LongRunningProcess } from "sealious";
|
|
9
|
-
|
|
10
|
-
export const actionName = "${action_name}";
|
|
11
|
-
|
|
12
|
-
export default new (class PatroniteAutoImportStatusPage extends Page {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
14
|
-
async canAccess(_: Context) {
|
|
15
|
-
return { canAccess: true, message: "" };
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
public interval = 2000;
|
|
19
|
-
|
|
20
|
-
async render(ctx: Context) {
|
|
21
|
-
const lpr_id = ctx.params.id;
|
|
22
|
-
const lpr_data = LongRunningProcess.getByID(ctx.$context, lpr_id);
|
|
23
|
-
const render_script = lpr_data.state !== "error" && lpr_data.state !== "finished";
|
|
24
|
-
const script = /* HTML */ \`<script>
|
|
25
|
-
setTimeout(() => {
|
|
26
|
-
document.location = document.location;
|
|
27
|
-
}, \${this.interval});
|
|
28
|
-
</script>\`;
|
|
29
|
-
|
|
30
|
-
return html(
|
|
31
|
-
ctx,
|
|
32
|
-
"PatroniteAutoImportStatus",
|
|
33
|
-
<div>
|
|
34
|
-
{lpr_data.then((lpr_data) => {
|
|
35
|
-
return (
|
|
36
|
-
<div>
|
|
37
|
-
<div>status: {lpr_data.state}</div>
|
|
38
|
-
<div style="height: 20px; width: 100%">
|
|
39
|
-
<div
|
|
40
|
-
style="height: 100%; background-color: green; width: {Math.round(
|
|
41
|
-
lpr_data.progress * 100
|
|
42
|
-
)}%"
|
|
43
|
-
></div>
|
|
44
|
-
</div>
|
|
45
|
-
<div>
|
|
46
|
-
{lpr_data.events.map((e) => (
|
|
47
|
-
<div>{e.message}</div>
|
|
48
|
-
))}
|
|
49
|
-
</div>
|
|
50
|
-
{render_script ? { script } : ""}
|
|
51
|
-
</div>
|
|
52
|
-
);
|
|
53
|
-
})}
|
|
54
|
-
</div>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
})();
|
|
58
|
-
`;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=long-running-process.js.map
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/utils.js";
|
|
2
|
-
export async function multiformTemplate(action_name, newfilefullpath) {
|
|
3
|
-
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { Context } from "koa";
|
|
5
|
-
import html from "${rel("src/back/html.js")}";
|
|
6
|
-
import { Controls, Fields, Form, FormMessage, Multiform } from "@sealcode/sealgen";
|
|
7
|
-
import { FlatTemplatable } from "tempstream";
|
|
8
|
-
|
|
9
|
-
export const actionName = "${action_name}";
|
|
10
|
-
|
|
11
|
-
const fields1 = {
|
|
12
|
-
email: new Fields.SimpleFormField(true),
|
|
13
|
-
password: new Fields.SimpleFormField(true),
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const form1 = new (class extends Form<typeof fields1> {
|
|
17
|
-
defaultSuccessMessage = "Form1 done!";
|
|
18
|
-
controls = [
|
|
19
|
-
new Controls.FormHeader("form1"),
|
|
20
|
-
new Controls.SimpleInput(fields1.email),
|
|
21
|
-
];
|
|
22
|
-
fields = fields1;
|
|
23
|
-
onSubmit() {
|
|
24
|
-
console.log("form1 submit");
|
|
25
|
-
}
|
|
26
|
-
})();
|
|
27
|
-
|
|
28
|
-
const fields2 = {
|
|
29
|
-
name: new Fields.SimpleFormField(true),
|
|
30
|
-
surname: new Fields.SimpleFormField(true),
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const form2 = new (class extends Form<Record<never, unknown>> {
|
|
34
|
-
defaultSuccessMessage = "Form2 done!";
|
|
35
|
-
controls = [new Controls.FormHeader("form2"), new Controls.SimpleInput(fields2.name)];
|
|
36
|
-
fields = fields2;
|
|
37
|
-
onSubmit() {
|
|
38
|
-
console.log("form2 submit");
|
|
39
|
-
}
|
|
40
|
-
})();
|
|
41
|
-
|
|
42
|
-
export default new (class extends Multiform {
|
|
43
|
-
name = "multiform_test";
|
|
44
|
-
forms = { form1, form2 };
|
|
45
|
-
async render(
|
|
46
|
-
ctx: Context,
|
|
47
|
-
messages: FormMessage[],
|
|
48
|
-
prerenderedForms?: Record<string, FlatTemplatable | undefined>
|
|
49
|
-
): Promise<FlatTemplatable> {
|
|
50
|
-
return html(ctx, "${action_name}", await super.render(ctx, messages, prerenderedForms));
|
|
51
|
-
}
|
|
52
|
-
})();
|
|
53
|
-
`;
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=multiform.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
-
export async function pageTemplate(action_name, newfilefullpath) {
|
|
3
|
-
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { Context } from "koa";
|
|
5
|
-
import { TempstreamJSX } from "tempstream";
|
|
6
|
-
import { Page } from "@sealcode/sealgen";
|
|
7
|
-
import html from "${rel("src/back/html.js")}";
|
|
8
|
-
|
|
9
|
-
export const actionName = "${action_name}";
|
|
10
|
-
|
|
11
|
-
export default new (class ${action_name}Page extends Page {
|
|
12
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
13
|
-
async canAccess(_: Context) {
|
|
14
|
-
return { canAccess: true, message: "" };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
async render(ctx: Context) {
|
|
18
|
-
return html(ctx, "${action_name}", <div></div>);
|
|
19
|
-
}
|
|
20
|
-
})();
|
|
21
|
-
`;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=page.js.map
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export async function postTemplate(action_name) {
|
|
2
|
-
return `import { Context } from "koa";
|
|
3
|
-
import { Mountable } from "@sealcode/sealgen";
|
|
4
|
-
import Router from "@koa/router";
|
|
5
|
-
|
|
6
|
-
export const actionName = "${action_name}";
|
|
7
|
-
|
|
8
|
-
export default new (class ${action_name}Redirect extends Mountable {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
async canAccess(_: Context) {
|
|
11
|
-
return { canAccess: true, message: "" };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
mount(router: Router, path: string) {
|
|
15
|
-
router.post(path, async (ctx) => {
|
|
16
|
-
ctx.body = { message: "OK!" }
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
})();
|
|
20
|
-
`;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=post.js.map
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export async function redirectTemplate(action_name) {
|
|
2
|
-
return `import { Context } from "koa";
|
|
3
|
-
import { Mountable } from "@sealcode/sealgen";
|
|
4
|
-
import Router from "@koa/router";
|
|
5
|
-
|
|
6
|
-
export const actionName = "${action_name}";
|
|
7
|
-
|
|
8
|
-
export default new (class ${action_name}Redirect extends Mountable {
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
10
|
-
async canAccess(_: Context) {
|
|
11
|
-
return { canAccess: true, message: "" };
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
mount(router: Router, path: string) {
|
|
15
|
-
router.get(path, async (ctx) => {
|
|
16
|
-
ctx.status = 302;
|
|
17
|
-
ctx.redirect("/new_url");
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
})();
|
|
21
|
-
`;
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=redirect.js.map
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
-
export function testTemplate(action_name, new_file_fullpath) {
|
|
3
|
-
const rel = curryImportPath(new_file_fullpath);
|
|
4
|
-
return `import { withProdApp } from "${rel("src/back/test_utils/with-prod-app.js")}";
|
|
5
|
-
import { VERY_LONG_TEST_TIMEOUT, webhintURL } from "${rel("src/back/test_utils/webhint.js")}";
|
|
6
|
-
import { ${action_name}URL } from "${rel("src/back/routes/urls.js")}";
|
|
7
|
-
import { getBrowser } from "${rel("src/back/test_utils/browser-creator.js")}";
|
|
8
|
-
import { Browser, BrowserContext, Page } from "@playwright/test";
|
|
9
|
-
|
|
10
|
-
describe("${action_name} webhint", () => {
|
|
11
|
-
it(
|
|
12
|
-
"doesn't crash",
|
|
13
|
-
async function () {
|
|
14
|
-
return withProdApp(async ({ base_url, rest_api }) => {
|
|
15
|
-
await rest_api.get(${action_name}URL);
|
|
16
|
-
await webhintURL(base_url + ${action_name}URL);
|
|
17
|
-
// alternatively you can use webhintHTML for faster but less precise scans
|
|
18
|
-
// or for scanning responses of requests that use some form of authorization:
|
|
19
|
-
// const response = await rest_api.get(${action_name}URL);
|
|
20
|
-
// await webhintHTML(response);
|
|
21
|
-
});
|
|
22
|
-
},
|
|
23
|
-
VERY_LONG_TEST_TIMEOUT
|
|
24
|
-
);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
describe("${action_name}", () => {
|
|
28
|
-
let page: Page;
|
|
29
|
-
let browser: Browser;
|
|
30
|
-
let context: BrowserContext;
|
|
31
|
-
|
|
32
|
-
beforeEach(async () => {
|
|
33
|
-
browser = await getBrowser();
|
|
34
|
-
context = await browser.newContext();
|
|
35
|
-
page = await context.newPage();
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
afterEach(async () => {
|
|
39
|
-
await context.close();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it(
|
|
43
|
-
"works as expected",
|
|
44
|
-
async function () {
|
|
45
|
-
return withProdApp(async ({ base_url }) => {
|
|
46
|
-
await page.goto(base_url + ${action_name}URL);
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
VERY_LONG_TEST_TIMEOUT
|
|
50
|
-
);
|
|
51
|
-
});
|
|
52
|
-
`;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=route-test.js.map
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { curryImportPath } from "../utils/import-path.js";
|
|
2
|
-
export async function statefulPageTemplate(action_name, newfilefullpath) {
|
|
3
|
-
const rel = curryImportPath(newfilefullpath);
|
|
4
|
-
return `import { TempstreamJSX, Templatable } from "tempstream";
|
|
5
|
-
import { BaseContext } from "koa";
|
|
6
|
-
import { StatefulPage } from "@sealcode/sealgen";
|
|
7
|
-
import html from "${rel("src/back/html.js")}";
|
|
8
|
-
|
|
9
|
-
export const actionName = "${action_name}";
|
|
10
|
-
|
|
11
|
-
const actions = {
|
|
12
|
-
add: (state: State, inputs: Record<string, string>) => {
|
|
13
|
-
console.log({ inputs });
|
|
14
|
-
return {
|
|
15
|
-
...state,
|
|
16
|
-
elements: [...state.elements, inputs.element_to_add || "new element"],
|
|
17
|
-
};
|
|
18
|
-
},
|
|
19
|
-
remove: (state: State, _: unknown, index_to_remove: number) => {
|
|
20
|
-
return {
|
|
21
|
-
...state,
|
|
22
|
-
elements: state.elements.filter((_, index) => index != index_to_remove),
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
} as const;
|
|
26
|
-
|
|
27
|
-
type State = {
|
|
28
|
-
elements: string[];
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
export default new (class ${action_name}Page extends StatefulPage<State, typeof actions> {
|
|
32
|
-
actions = actions;
|
|
33
|
-
|
|
34
|
-
getInitialState() {
|
|
35
|
-
return { elements: ["one", "two", "three"] };
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
wrapInLayout(ctx: BaseContext, content: Templatable): Templatable {
|
|
39
|
-
return html(ctx, "${action_name}", content);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
render(ctx: BaseContext, state: State, inputs: Record<string, string>) {
|
|
43
|
-
return (
|
|
44
|
-
<div>
|
|
45
|
-
<ul>
|
|
46
|
-
{state.elements.map((e, index) => (
|
|
47
|
-
<li>
|
|
48
|
-
{e} {this.makeActionButton(state, "remove", index)}
|
|
49
|
-
</li>
|
|
50
|
-
))}
|
|
51
|
-
</ul>
|
|
52
|
-
<div>
|
|
53
|
-
<input
|
|
54
|
-
name="element_to_add"
|
|
55
|
-
type="text"
|
|
56
|
-
value={inputs.element_to_add || ""}
|
|
57
|
-
/>
|
|
58
|
-
{this.makeActionButton(state, "add")}
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
})();
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
//# sourceMappingURL=stateful-page.js.map
|