@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
package/lib/mount.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Middlewares } from "sealious";
|
|
2
|
-
async function handleHtmlPromise(ctx, next) {
|
|
3
|
-
await next();
|
|
4
|
-
if (ctx.body instanceof Promise) {
|
|
5
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
6
|
-
ctx.body = await ctx.body;
|
|
7
|
-
}
|
|
8
|
-
ctx.set("content-type", "text/html;charset=utf-8");
|
|
9
|
-
}
|
|
10
|
-
export function mount(router, url, mountable, use_dummy_app = false) {
|
|
11
|
-
const raw_url = typeof url === "string" ? url : url.rawURL;
|
|
12
|
-
const args = use_dummy_app
|
|
13
|
-
? [
|
|
14
|
-
async (ctx, next) => {
|
|
15
|
-
// this dummy is a temporary solution it's ilustrating the ways that
|
|
16
|
-
// sealgen is coupled with sealious. Definitely room for improvement in this
|
|
17
|
-
// regard
|
|
18
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
19
|
-
ctx.$app = {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
21
|
-
Logger: new Proxy({}, {
|
|
22
|
-
get: (_target, prop) => {
|
|
23
|
-
if (prop === "info") {
|
|
24
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
25
|
-
return () => { };
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
-
return () => { };
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
}),
|
|
33
|
-
getString: (x) => x,
|
|
34
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
|
-
};
|
|
36
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
37
|
-
await next();
|
|
38
|
-
},
|
|
39
|
-
Middlewares.parseBody(),
|
|
40
|
-
handleHtmlPromise,
|
|
41
|
-
]
|
|
42
|
-
: [
|
|
43
|
-
Middlewares.extractContext(),
|
|
44
|
-
Middlewares.parseBody(),
|
|
45
|
-
handleHtmlPromise,
|
|
46
|
-
];
|
|
47
|
-
router.use(raw_url, ...args);
|
|
48
|
-
mountable.init();
|
|
49
|
-
// to automatically add trailing slashes:
|
|
50
|
-
router.get(raw_url.slice(0, -1), async (ctx, next) => {
|
|
51
|
-
const url2 = ctx.URL;
|
|
52
|
-
if (!url2.pathname.endsWith("/")) {
|
|
53
|
-
url2.pathname += "/";
|
|
54
|
-
ctx.redirect(url2.href);
|
|
55
|
-
}
|
|
56
|
-
await next();
|
|
57
|
-
});
|
|
58
|
-
router.use(raw_url, async (ctx, next) => {
|
|
59
|
-
ctx.set("content-type", "text/html;charset=utf-8");
|
|
60
|
-
const access_result = await mountable.canAccess(ctx);
|
|
61
|
-
if (!access_result.canAccess) {
|
|
62
|
-
ctx.status = 403;
|
|
63
|
-
ctx.body = access_result.message || "no access";
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
await next();
|
|
67
|
-
});
|
|
68
|
-
mountable.mount(router, raw_url);
|
|
69
|
-
}
|
|
70
|
-
//# sourceMappingURL=mount.js.map
|
package/lib/notifier.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import WebSocket from "ws";
|
|
2
|
-
export function make_notifier(port) {
|
|
3
|
-
const server = new WebSocket.Server({
|
|
4
|
-
port,
|
|
5
|
-
});
|
|
6
|
-
let sockets = [];
|
|
7
|
-
server.on("connection", function (socket) {
|
|
8
|
-
sockets.push(socket);
|
|
9
|
-
// When a socket closes, or disconnects, remove it from the array.
|
|
10
|
-
socket.on("close", function () {
|
|
11
|
-
sockets = sockets.filter((s) => s !== socket);
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
console.log("build notifier listening on websocket at port " + port);
|
|
15
|
-
return function notify(message) {
|
|
16
|
-
sockets.forEach((s) => s.send(message));
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=notifier.js.map
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export function peopleWhoCan(action, collection) {
|
|
2
|
-
return async function (ctx) {
|
|
3
|
-
const policy = collection.getPolicy(action);
|
|
4
|
-
const result = await policy.check(ctx.$context);
|
|
5
|
-
if (!result) {
|
|
6
|
-
ctx.status = 403;
|
|
7
|
-
return { canAccess: false, message: "Not allowed" };
|
|
8
|
-
}
|
|
9
|
-
if (!result.allowed) {
|
|
10
|
-
ctx.status = 403;
|
|
11
|
-
return { canAccess: false, message: result.reason };
|
|
12
|
-
}
|
|
13
|
-
return { canAccess: true, message: "" };
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=access-control.js.map
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export const BooleanListFilter = (value, field) => {
|
|
2
|
-
return /* HTML */ `<label>
|
|
3
|
-
${field.name}
|
|
4
|
-
<select name="filter[${field.name}]" autocomplete="off">
|
|
5
|
-
<option value="true" ${value == "true" ? "selected" : ""}>
|
|
6
|
-
True
|
|
7
|
-
</option>
|
|
8
|
-
<option value="false" ${value == "false" ? "selected" : ""}>
|
|
9
|
-
False
|
|
10
|
-
</option>
|
|
11
|
-
<option
|
|
12
|
-
value=""
|
|
13
|
-
${value == "null" ||
|
|
14
|
-
value == "" ||
|
|
15
|
-
value == "undefined" ||
|
|
16
|
-
value == undefined
|
|
17
|
-
? "selected"
|
|
18
|
-
: ""}
|
|
19
|
-
>
|
|
20
|
-
-
|
|
21
|
-
</option>
|
|
22
|
-
</select>
|
|
23
|
-
</label>`;
|
|
24
|
-
};
|
|
25
|
-
export const SimpleTextFilter = (value, field) => {
|
|
26
|
-
return /* HTML */ `<label>
|
|
27
|
-
${field.name}
|
|
28
|
-
<input
|
|
29
|
-
type="text"
|
|
30
|
-
name="${field.name}"
|
|
31
|
-
${value ? `value="${value}"` : value}
|
|
32
|
-
/>
|
|
33
|
-
</label>`;
|
|
34
|
-
};
|
|
35
|
-
export const DefaultListFilters = {
|
|
36
|
-
boolean: BooleanListFilter,
|
|
37
|
-
text: SimpleTextFilter,
|
|
38
|
-
fallback: SimpleTextFilter,
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=default-list-filters.js.map
|
package/lib/page/list.js
DELETED
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { Page } from "./page.js";
|
|
3
|
-
import { NumberField, SimpleFormField, } from "../forms/fields/field.js";
|
|
4
|
-
import { naturalNumbers, UrlWithNewParams } from "../utils/utils.js";
|
|
5
|
-
import { makeHiddenInputs } from "../make-hidden-inputs.js";
|
|
6
|
-
import qs from "qs";
|
|
7
|
-
export const BasePagePropsShape = {};
|
|
8
|
-
export const BaseListPageFields = {
|
|
9
|
-
page: new NumberField(false, 1),
|
|
10
|
-
itemsPerPage: new NumberField(false, 12),
|
|
11
|
-
sort: new SimpleFormField(false),
|
|
12
|
-
};
|
|
13
|
-
const SORT_SEPARATOR = ":";
|
|
14
|
-
function decodeSort(s) {
|
|
15
|
-
if (typeof s !== "string" || !s.includes(SORT_SEPARATOR)) {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
let order = s.split(SORT_SEPARATOR)[1];
|
|
19
|
-
const field = s.split(SORT_SEPARATOR)[0];
|
|
20
|
-
if (order !== "asc" && order !== "desc") {
|
|
21
|
-
order = "asc";
|
|
22
|
-
return {
|
|
23
|
-
field,
|
|
24
|
-
order: order,
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return { field, order };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function encodeSort(field, order) {
|
|
32
|
-
return [field, order].join(SORT_SEPARATOR);
|
|
33
|
-
}
|
|
34
|
-
export class ListPage extends Page {
|
|
35
|
-
constructor() {
|
|
36
|
-
super(...arguments);
|
|
37
|
-
this.filterFields = {};
|
|
38
|
-
this.filterControls = [];
|
|
39
|
-
}
|
|
40
|
-
init() {
|
|
41
|
-
super.init();
|
|
42
|
-
for (const [fieldname, field] of Object.entries(this.filterFields)) {
|
|
43
|
-
field.init(fieldname);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
renderListContainer(_, content) {
|
|
47
|
-
return tempstream `<div>${content}</div>`;
|
|
48
|
-
}
|
|
49
|
-
async getPaginationConfig(ctx) {
|
|
50
|
-
const values = await this.extractRawValues(ctx);
|
|
51
|
-
const { parsed: page } = await this.fields.page.getValue(ctx, values);
|
|
52
|
-
const { parsed: itemsPerPage } = await this.fields.itemsPerPage.getValue(ctx, values);
|
|
53
|
-
return { page, itemsPerPage };
|
|
54
|
-
}
|
|
55
|
-
async renderItems(ctx, values, items) {
|
|
56
|
-
if (!values) {
|
|
57
|
-
values = await this.extractRawValues(ctx);
|
|
58
|
-
}
|
|
59
|
-
const { itemsPerPage, page } = await this.getPaginationConfig(ctx);
|
|
60
|
-
const items_promise = this.getItems(ctx, page, itemsPerPage, values);
|
|
61
|
-
return tempstream `${(items
|
|
62
|
-
? Promise.resolve(items)
|
|
63
|
-
: items_promise).then((items) => items.map((item, index) => this.renderItem(ctx, item, index)))}`;
|
|
64
|
-
}
|
|
65
|
-
async render(ctx) {
|
|
66
|
-
const values = await this.extractRawValues(ctx);
|
|
67
|
-
return tempstream `${this.renderPagination(ctx, values)}
|
|
68
|
-
${this.renderFilters(ctx)}
|
|
69
|
-
${this.renderListContainer(ctx, this.renderItems(ctx, values))}`;
|
|
70
|
-
}
|
|
71
|
-
async renderPagination(ctx, values) {
|
|
72
|
-
const { itemsPerPage, page } = await this.getPaginationConfig(ctx);
|
|
73
|
-
const totalIems = await this.getTotalPages(ctx, itemsPerPage, values);
|
|
74
|
-
return tempstream /* HTML */ `<div class="list-pagination">
|
|
75
|
-
<div class="list-pagination__left">
|
|
76
|
-
${page > 1
|
|
77
|
-
? this.renderPageButton(ctx, 1, "Pierwsza strona")
|
|
78
|
-
: ""}
|
|
79
|
-
${page > 1
|
|
80
|
-
? this.renderPageButton(ctx, page - 1, "Poprzednia strona")
|
|
81
|
-
: ""}
|
|
82
|
-
</div>
|
|
83
|
-
<div class="list-pagination__center">
|
|
84
|
-
<select
|
|
85
|
-
title="choose page"
|
|
86
|
-
onchange="if (this.value) Turbo.visit(this.value)"
|
|
87
|
-
>
|
|
88
|
-
${Array.from(naturalNumbers(1, totalIems)).map((n) => /* HTML */ `<option
|
|
89
|
-
value="${UrlWithNewParams(ctx,
|
|
90
|
-
//eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
91
|
-
this.propsParser.overwriteProp(ctx, {
|
|
92
|
-
page: n,
|
|
93
|
-
}))}"
|
|
94
|
-
${page === n ? "selected" : ""}
|
|
95
|
-
>
|
|
96
|
-
${n}
|
|
97
|
-
</option>`)}
|
|
98
|
-
</select>
|
|
99
|
-
</div>
|
|
100
|
-
<div class="list-pagination__right">
|
|
101
|
-
${page < totalIems
|
|
102
|
-
? this.renderPageButton(ctx, page + 1, "Następna strona")
|
|
103
|
-
: ""}
|
|
104
|
-
${page < totalIems
|
|
105
|
-
? this.renderPageButton(ctx, totalIems, "Ostatnia strona")
|
|
106
|
-
: ""}
|
|
107
|
-
</div>
|
|
108
|
-
</div>`;
|
|
109
|
-
}
|
|
110
|
-
renderPageButton(ctx, page, text) {
|
|
111
|
-
return /* HTML */ `<a
|
|
112
|
-
href="${UrlWithNewParams(ctx,
|
|
113
|
-
//eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
114
|
-
this.propsParser.overwriteProp(ctx, {
|
|
115
|
-
page,
|
|
116
|
-
}))}"
|
|
117
|
-
>${text}</a
|
|
118
|
-
>`;
|
|
119
|
-
}
|
|
120
|
-
async getFilterValues(ctx) {
|
|
121
|
-
const filter = {};
|
|
122
|
-
const raw_values = await this.extractRawValues(ctx);
|
|
123
|
-
for (const [fieldname, field] of Object.entries(this.filterFields)) {
|
|
124
|
-
// eslint-disable-next-line no-await-in-loop
|
|
125
|
-
const { parsed } = await field.getValue(ctx, raw_values);
|
|
126
|
-
filter[fieldname] = field.mapToFilter(parsed);
|
|
127
|
-
}
|
|
128
|
-
return filter;
|
|
129
|
-
}
|
|
130
|
-
async getSort(ctx) {
|
|
131
|
-
const { sort } = await this.extractRawValues(ctx);
|
|
132
|
-
const decoded = decodeSort(sort);
|
|
133
|
-
if (decoded === null) {
|
|
134
|
-
return this.getDefaultSort(ctx);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
return decoded;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
makeSortLink(ctx, field, order) {
|
|
141
|
-
const url = new URL(ctx.url, "https://example.com");
|
|
142
|
-
const params = qs.parse(url.search.slice(1));
|
|
143
|
-
params.sort = encodeSort(field, order);
|
|
144
|
-
url.search = qs.stringify(params);
|
|
145
|
-
return url.pathname + url.search;
|
|
146
|
-
}
|
|
147
|
-
async renderFilters(ctx) {
|
|
148
|
-
const values = await this.extractRawValues(ctx);
|
|
149
|
-
return tempstream /* HTML */ `<form method="GET">
|
|
150
|
-
${makeHiddenInputs(ctx, this.fields, values, [
|
|
151
|
-
"page",
|
|
152
|
-
...Object.values(this.filterFields).map((f) => f.name),
|
|
153
|
-
])}
|
|
154
|
-
${this.filterControls.map((control) => {
|
|
155
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
156
|
-
return control.render(this.makeFormControlContext(ctx, { raw_values: values, messages: [] }, false));
|
|
157
|
-
})}
|
|
158
|
-
</form>`;
|
|
159
|
-
}
|
|
160
|
-
async renderHeading(ctx, field, label = field) {
|
|
161
|
-
const current_sort = await this.getSort(ctx);
|
|
162
|
-
const current_order = current_sort?.field == field ? current_sort.order : null;
|
|
163
|
-
const order = current_order == "desc" ? "asc" : "desc";
|
|
164
|
-
return /* HTML */ `<th>
|
|
165
|
-
<a href="${this.makeSortLink(ctx, field, order)}"
|
|
166
|
-
>${label}
|
|
167
|
-
${(current_order && (current_order == "asc" ? "↑" : "↓")) ||
|
|
168
|
-
""}</a
|
|
169
|
-
>
|
|
170
|
-
</th>`;
|
|
171
|
-
}
|
|
172
|
-
getDefaultSort(_) {
|
|
173
|
-
return null;
|
|
174
|
-
}
|
|
175
|
-
renderTableHead(ctx, fields) {
|
|
176
|
-
return tempstream /* HTML */ `<thead>
|
|
177
|
-
<tr>
|
|
178
|
-
${fields.map(({ label, field }) => this.renderHeading(ctx, field, label))}
|
|
179
|
-
</tr>
|
|
180
|
-
</thead>`;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
//# sourceMappingURL=list.js.map
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { FormControlContext, } from "../forms/controls/form-control.js";
|
|
3
|
-
import { Mountable } from "./mountable.js";
|
|
4
|
-
export class MountableWithFields extends Mountable {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
this.field_names_prefix = ""; // useful for multiform, where many forms are merged into one and field assignment is made using the prefix
|
|
8
|
-
this.form_id = ""; // all fields within this mountable will be tied to form of this id
|
|
9
|
-
if (!this.fields)
|
|
10
|
-
this.fields = {};
|
|
11
|
-
}
|
|
12
|
-
init() {
|
|
13
|
-
for (const [name, field] of Object.entries(this.fields)) {
|
|
14
|
-
field.init(name);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
makeFormControlContext(ctx, data, validate, field_name_prefix = this.field_names_prefix, form_id = this.form_id) {
|
|
18
|
-
return new FormControlContext(ctx, data.raw_values, data.messages, field_name_prefix, form_id, validate);
|
|
19
|
-
}
|
|
20
|
-
// this one is meant to be overwritten
|
|
21
|
-
async validateValues(ctx, data) {
|
|
22
|
-
return {
|
|
23
|
-
valid: true,
|
|
24
|
-
error: "",
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
async validate(ctx, values) {
|
|
28
|
-
const field_errors = {};
|
|
29
|
-
let valid = true;
|
|
30
|
-
const form_messages = [];
|
|
31
|
-
await Promise.all(Object.entries(values)
|
|
32
|
-
.filter(([fieldname]) => fieldname in this.fields)
|
|
33
|
-
.map(async ([key]) => {
|
|
34
|
-
const field = this.fields[key];
|
|
35
|
-
const { valid: fieldvalid, message: fieldmessage } = await field.getValue(ctx, values);
|
|
36
|
-
if (!fieldvalid) {
|
|
37
|
-
valid = false;
|
|
38
|
-
field_errors[field.name] = fieldmessage;
|
|
39
|
-
}
|
|
40
|
-
}));
|
|
41
|
-
const formValidationResult = await this.validateValues(ctx, values);
|
|
42
|
-
if (!formValidationResult.valid) {
|
|
43
|
-
form_messages.push({
|
|
44
|
-
type: "error",
|
|
45
|
-
text: formValidationResult.error,
|
|
46
|
-
});
|
|
47
|
-
valid = false;
|
|
48
|
-
}
|
|
49
|
-
return { valid, field_errors, form_messages };
|
|
50
|
-
}
|
|
51
|
-
renderControls(fctx) {
|
|
52
|
-
return tempstream /* HTML */ `${this.controls.map((control) => control.render(fctx))}`;
|
|
53
|
-
}
|
|
54
|
-
async renderError(_, error) {
|
|
55
|
-
return error.message;
|
|
56
|
-
}
|
|
57
|
-
renderMessages(_, data) {
|
|
58
|
-
return tempstream /* HTML */ `<div class="form-messages">
|
|
59
|
-
${data.messages.map((message) => `<div class="form-message form-message--${message.type}">${message.text}</div>`)}
|
|
60
|
-
</div>`;
|
|
61
|
-
}
|
|
62
|
-
async getParsedValues(ctx) {
|
|
63
|
-
const raw_values = await this.extractRawValues(ctx);
|
|
64
|
-
const result = {};
|
|
65
|
-
const promises = Object.entries(this.fields).map(async ([key, field]) => {
|
|
66
|
-
const { parsed } = await field.getValue(ctx, raw_values);
|
|
67
|
-
result[key] = parsed;
|
|
68
|
-
});
|
|
69
|
-
await Promise.all(promises);
|
|
70
|
-
return result;
|
|
71
|
-
}
|
|
72
|
-
async getDatabaseValues(ctx) {
|
|
73
|
-
const raw_values = await this.extractRawValues(ctx);
|
|
74
|
-
const result = {};
|
|
75
|
-
const promises = Object.entries(this.fields).map(async ([key, field]) => {
|
|
76
|
-
const db_value = await field.getDatabaseValue(ctx, raw_values);
|
|
77
|
-
if (db_value !== undefined) {
|
|
78
|
-
result[key] = db_value;
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
await Promise.all(promises);
|
|
82
|
-
return result;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
//# sourceMappingURL=mountable-with-fields.js.map
|
package/lib/page/mountable.js
DELETED
package/lib/page/page.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { tempstream } from "tempstream";
|
|
2
|
-
import { AllQueryParams } from "../index.js";
|
|
3
|
-
import { MountableWithFields, } from "./mountable-with-fields.js";
|
|
4
|
-
export class Page extends MountableWithFields {
|
|
5
|
-
constructor() {
|
|
6
|
-
super(...arguments);
|
|
7
|
-
this.propsParser = new AllQueryParams();
|
|
8
|
-
this.controls = [];
|
|
9
|
-
}
|
|
10
|
-
mount(router, path) {
|
|
11
|
-
router.get(path, async (ctx) => {
|
|
12
|
-
ctx.body = await this.render(ctx);
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
async canAccess(_) {
|
|
17
|
-
return { canAccess: true, message: "" };
|
|
18
|
-
}
|
|
19
|
-
async renderError(_, error) {
|
|
20
|
-
return tempstream /* HTML */ `<div>${error.message}</div>`;
|
|
21
|
-
}
|
|
22
|
-
async extractRawValues(ctx) {
|
|
23
|
-
return this.propsParser.decode(ctx) || {};
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=page.js.map
|
package/lib/page/props-parser.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import merge from "merge";
|
|
2
|
-
// page props parser is only tasked with getting the raw props from *somewhere*
|
|
3
|
-
// and being able to put new values back to that somewhere. Parsing to numbers
|
|
4
|
-
// or any other exotic types is done by fields logic.
|
|
5
|
-
export class PagePropsParser {
|
|
6
|
-
overwriteProp(ctx, new_props) {
|
|
7
|
-
const result = {};
|
|
8
|
-
merge.recursive(result, this.decode(ctx), new_props);
|
|
9
|
-
return result;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
export class AllQueryParams extends PagePropsParser {
|
|
13
|
-
decode(ctx) {
|
|
14
|
-
return ctx.query;
|
|
15
|
-
}
|
|
16
|
-
encode(props) {
|
|
17
|
-
return props;
|
|
18
|
-
}
|
|
19
|
-
getHTMLInputName(prop_name) {
|
|
20
|
-
return prop_name;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//# sourceMappingURL=props-parser.js.map
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ListPage } from "./list.js";
|
|
2
|
-
import { peopleWhoCan } from "./access-control.js";
|
|
3
|
-
import qs from "qs";
|
|
4
|
-
import { is, predicates } from "@sealcode/ts-predicates";
|
|
5
|
-
export class SealiousItemListPage extends ListPage {
|
|
6
|
-
constructor(collection) {
|
|
7
|
-
super();
|
|
8
|
-
this.collection = collection;
|
|
9
|
-
this.canAccess = peopleWhoCan("list", this.collection);
|
|
10
|
-
}
|
|
11
|
-
async getContextForList(ctx) {
|
|
12
|
-
return ctx.$context;
|
|
13
|
-
}
|
|
14
|
-
async getTotalPages(ctx, itemsPerPage) {
|
|
15
|
-
const query = this.collection.list(await this.getContextForList(ctx));
|
|
16
|
-
await this.addFilter(ctx, query);
|
|
17
|
-
const { items } = await query.fetch();
|
|
18
|
-
return Math.ceil(items.length / itemsPerPage);
|
|
19
|
-
}
|
|
20
|
-
async addFilter(ctx, list) {
|
|
21
|
-
const filters = await this.getFilterValues(ctx);
|
|
22
|
-
for (const key in filters) {
|
|
23
|
-
if (filters[key] === undefined || filters[key] == "") {
|
|
24
|
-
delete filters[key];
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (Object.keys(filters).length) {
|
|
28
|
-
list.filter(filters);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
async makeQuery(ctx) {
|
|
32
|
-
const query = this.collection.list(await this.getContextForList(ctx));
|
|
33
|
-
const sort = await this.getSort(ctx);
|
|
34
|
-
if (sort) {
|
|
35
|
-
query.sort({ [sort.field]: sort.order });
|
|
36
|
-
}
|
|
37
|
-
return query;
|
|
38
|
-
}
|
|
39
|
-
async getItems(ctx, page, itemsPerPage) {
|
|
40
|
-
const query = await this.makeQuery(ctx);
|
|
41
|
-
await this.addFilter(ctx, query);
|
|
42
|
-
const { items } = await query
|
|
43
|
-
.paginate({ items: itemsPerPage, page })
|
|
44
|
-
.fetch();
|
|
45
|
-
return items;
|
|
46
|
-
}
|
|
47
|
-
async getFilterValues(ctx) {
|
|
48
|
-
const query_params = qs.parse(ctx.search.slice(1));
|
|
49
|
-
const _filter_values = query_params?.filter || {};
|
|
50
|
-
let filter_values = is(_filter_values, predicates.record(predicates.string, predicates.string))
|
|
51
|
-
? _filter_values
|
|
52
|
-
: {};
|
|
53
|
-
return filter_values;
|
|
54
|
-
}
|
|
55
|
-
async renderItem(_, item, index) {
|
|
56
|
-
return `<div>${item.id}</div>`;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
//# sourceMappingURL=sealious-list.js.map
|
|
@@ -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
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises";
|
|
2
|
-
import { extname } from "node:path";
|
|
3
|
-
const generate_names = (function* generate_names() {
|
|
4
|
-
const base_name = "____unique_import_";
|
|
5
|
-
let count = 0;
|
|
6
|
-
while (true) {
|
|
7
|
-
yield `${base_name}${count}`;
|
|
8
|
-
count++;
|
|
9
|
-
}
|
|
10
|
-
})();
|
|
11
|
-
export const remove_named_imports = {
|
|
12
|
-
name: "remove-named-imports",
|
|
13
|
-
setup(build) {
|
|
14
|
-
build.onLoad({ filter: /.*/ }, async ({ path }) => {
|
|
15
|
-
const named_and_default_regex = /^import\s+((\S+),\s+)?({\s*[^}]+})\s+from\s+("[^"]+");\s*$/gm;
|
|
16
|
-
const old_content = await fs.readFile(path, "utf-8");
|
|
17
|
-
const contents = old_content.replace(named_and_default_regex, (_, default_import_name, __, all_named, module_path) => {
|
|
18
|
-
/* eslint-disable */
|
|
19
|
-
const new_name = generate_names.next().value;
|
|
20
|
-
const result = `import * as ${new_name} from ${module_path}${default_import_name
|
|
21
|
-
? `; const ${default_import_name.replace(",", "")} = ${new_name}.default || ${new_name};`
|
|
22
|
-
: ""};` +
|
|
23
|
-
all_named
|
|
24
|
-
.match(/[a-zA-Z_$][^,}]+/g)
|
|
25
|
-
.map((importname) => {
|
|
26
|
-
if (importname.startsWith("default as")) {
|
|
27
|
-
return `const ${importname.replace("default as ", "")} = ${new_name}?.default || ${new_name};`;
|
|
28
|
-
}
|
|
29
|
-
if (importname.match(/([^{]*)\sas\s([^}]*)/)) {
|
|
30
|
-
// is "import {asdfas as somethong_else}
|
|
31
|
-
const [_, original, named] = importname.match(/([^{]*)\sas\s([^}]*)/);
|
|
32
|
-
return `const ${named} = ${new_name}?.default.${original} || ${new_name}?.${original}`;
|
|
33
|
-
}
|
|
34
|
-
return `const ${importname} = ${new_name}?.default?.${importname} || ${new_name}?.${importname};`;
|
|
35
|
-
})
|
|
36
|
-
.join("; ");
|
|
37
|
-
return result;
|
|
38
|
-
/* eslint-enable */
|
|
39
|
-
});
|
|
40
|
-
return {
|
|
41
|
-
contents,
|
|
42
|
-
loader: extname(path) === ".tsx" ? "tsx" : "ts",
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
//# sourceMappingURL=remove-named-imports.js.map
|
package/lib/run.js
DELETED