@sealcode/sealgen 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@types/src/forms/controls/array.d.ts +1 -1
- package/@types/src/forms/controls/derived-frame.d.ts +1 -1
- package/@types/src/forms/controls/form-control.d.ts +1 -1
- package/@types/src/forms/controls/multiple-files.d.ts +11 -11
- package/@types/src/forms/fields/file.d.ts +4 -4
- package/@types/src/forms/form.d.ts +1 -1
- package/@types/src/forms/multiform.d.ts +1 -1
- package/@types/src/index.d.ts +2 -2
- package/@types/src/mount.d.ts +1 -1
- package/@types/src/page/mountable.d.ts +1 -1
- package/@types/src/page/page.d.ts +1 -1
- package/@types/src/page/stateful-page.d.ts +1 -1
- package/dist/forms/controls/multiple-files.js +4 -2
- package/dist/forms/controls/photo.js +2 -2
- package/dist/forms/fields/file.js +5 -5
- package/dist/mount.js +4 -4
- package/package.json +2 -2
- package/src/forms/controls/multiple-files.ts +21 -19
- package/src/forms/controls/photo.ts +2 -2
- package/src/forms/fields/file.ts +7 -7
- package/src/index.ts +2 -2
- package/src/mount.ts +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
-
/// <reference types="koa__router"
|
|
2
|
+
/// <reference types="koa__router" />
|
|
3
3
|
import Router from "@koa/router";
|
|
4
4
|
import { Context } from "koa";
|
|
5
5
|
import { Field, FieldsetOutput } from "sealious";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
-
/// <reference types="koa__router"
|
|
3
|
+
/// <reference types="koa__router" />
|
|
4
4
|
import Router from "@koa/router";
|
|
5
5
|
import { Context } from "koa";
|
|
6
6
|
import { ParsedUrlQuery } from "querystring";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
/// <reference types="koa__router"
|
|
1
|
+
/// <reference types="koa__router" />
|
|
2
2
|
/// <reference types="node" resolution-mode="require"/>
|
|
3
3
|
import Router from "@koa/router";
|
|
4
|
-
import
|
|
4
|
+
import { CollectionItem, File as SealiousFile, Field as SealiousField, Collection } from "sealious";
|
|
5
5
|
import { Context } from "koa";
|
|
6
6
|
import { FlatTemplatable } from "tempstream";
|
|
7
7
|
import { MultipleFiles as MultipleFilesField } from "../fields/multiple-files.js";
|
|
@@ -10,7 +10,7 @@ import { FormControlContext } from "./form-control.js";
|
|
|
10
10
|
export type MultipleFilesOptions = {
|
|
11
11
|
label?: string;
|
|
12
12
|
uploadLabel?: string;
|
|
13
|
-
getAdditionalFields: (ctx: Context, file:
|
|
13
|
+
getAdditionalFields: (ctx: Context, file: SealiousFile) => Promise<Record<string, unknown>>;
|
|
14
14
|
};
|
|
15
15
|
export declare class MultipleFiles extends FormFieldControl {
|
|
16
16
|
field: MultipleFilesField;
|
|
@@ -19,18 +19,18 @@ export declare class MultipleFiles extends FormFieldControl {
|
|
|
19
19
|
getClassModifiers(): string[];
|
|
20
20
|
mount(router: Router): void;
|
|
21
21
|
deleteFileAssociation(ctx: Context, file_item_id: string): Promise<void>;
|
|
22
|
-
addFileAssociation(ctx: Context, file:
|
|
22
|
+
addFileAssociation(ctx: Context, file: SealiousFile): Promise<void>;
|
|
23
23
|
getFrameRelativeURL(): string;
|
|
24
24
|
getFrameID(): string;
|
|
25
25
|
renderFrame(ctx: Context, content?: FlatTemplatable): import("stream").Readable;
|
|
26
26
|
render(fctx: FormControlContext): FlatTemplatable | Promise<FlatTemplatable>;
|
|
27
|
-
getReferencingCollection():
|
|
28
|
-
getFileField():
|
|
29
|
-
extractFileFromItem(item:
|
|
30
|
-
renderFileItemPreview(_fileItem:
|
|
31
|
-
renderFileItem(fileItem:
|
|
32
|
-
renderFileRemoveButton(fileItem:
|
|
33
|
-
getFileItems(ctx: Context): Promise<
|
|
27
|
+
getReferencingCollection(): Collection;
|
|
28
|
+
getFileField(): SealiousField | null;
|
|
29
|
+
extractFileFromItem(item: CollectionItem): Promise<SealiousFile | null>;
|
|
30
|
+
renderFileItemPreview(_fileItem: CollectionItem, file: SealiousFile): Promise<FlatTemplatable>;
|
|
31
|
+
renderFileItem(fileItem: CollectionItem, file: SealiousFile): Promise<FlatTemplatable>;
|
|
32
|
+
renderFileRemoveButton(fileItem: CollectionItem): FlatTemplatable;
|
|
33
|
+
getFileItems(ctx: Context): Promise<CollectionItem<any>[]>;
|
|
34
34
|
getInputAttributes(): {
|
|
35
35
|
type: string;
|
|
36
36
|
name: string;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
|
-
import
|
|
2
|
+
import { File as SealiousFile } from "sealious";
|
|
3
3
|
import { FormDataValue } from "../form-types.js";
|
|
4
4
|
import { FieldParseResult, FormField } from "./field.js";
|
|
5
5
|
export type FileContainer = {
|
|
6
|
-
old:
|
|
7
|
-
new:
|
|
6
|
+
old: SealiousFile | null;
|
|
7
|
+
new: SealiousFile | null;
|
|
8
8
|
};
|
|
9
9
|
export declare class File<Required extends boolean> extends FormField<Required, FileContainer> {
|
|
10
10
|
parse(ctx: Context, raw_value: FormDataValue): Promise<FieldParseResult<FileContainer>>;
|
|
11
|
-
getDatabaseValue(ctx: Context, data: Record<string, FormDataValue>): Promise<
|
|
11
|
+
getDatabaseValue(ctx: Context, data: Record<string, FormDataValue>): Promise<SealiousFile | undefined>;
|
|
12
12
|
getEmptyValue(): {
|
|
13
13
|
old: null;
|
|
14
14
|
new: null;
|
package/@types/src/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { App, Context as SealiousContext } from "sealious";
|
|
2
2
|
import { FormDataValue } from "./forms/form-types.js";
|
|
3
3
|
declare module "koa" {
|
|
4
4
|
interface BaseContext {
|
|
5
|
-
$context:
|
|
5
|
+
$context: SealiousContext;
|
|
6
6
|
$app: App;
|
|
7
7
|
$body: Record<string, FormDataValue>;
|
|
8
8
|
}
|
package/@types/src/mount.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
File as SealiousFile
|
|
3
|
+
} from "sealious";
|
|
2
4
|
import { inputWrapper } from "../../utils/input-wrapper.js";
|
|
3
5
|
import { tempstream } from "tempstream";
|
|
4
6
|
import { FormFieldControl } from "./form-field-control.js";
|
|
@@ -105,7 +107,7 @@ class MultipleFiles extends FormFieldControl {
|
|
|
105
107
|
if (!sealious_field) {
|
|
106
108
|
return null;
|
|
107
109
|
}
|
|
108
|
-
return await
|
|
110
|
+
return await SealiousFile.fromID(
|
|
109
111
|
item.collection.app,
|
|
110
112
|
item.get(sealious_field.name).id
|
|
111
113
|
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tempstream } from "tempstream";
|
|
2
2
|
import { File } from "./file.js";
|
|
3
|
-
import
|
|
3
|
+
import { File as SealiousFile } from "sealious";
|
|
4
4
|
class Photo extends File {
|
|
5
5
|
constructor(field, imageRouter, options) {
|
|
6
6
|
super(field, options);
|
|
@@ -20,7 +20,7 @@ class Photo extends File {
|
|
|
20
20
|
if (!id) {
|
|
21
21
|
return empty_container;
|
|
22
22
|
}
|
|
23
|
-
const file = await
|
|
23
|
+
const file = await SealiousFile.fromID(ctx.$app, id);
|
|
24
24
|
return tempstream`<div class="${class_name}">
|
|
25
25
|
${this.imageRouter.image({
|
|
26
26
|
resolutions: [100],
|
|
@@ -4,19 +4,19 @@ import {
|
|
|
4
4
|
is,
|
|
5
5
|
predicates
|
|
6
6
|
} from "@sealcode/ts-predicates";
|
|
7
|
-
import
|
|
7
|
+
import { File as SealiousFile } from "sealious";
|
|
8
8
|
import { FormField } from "./field.js";
|
|
9
9
|
class File extends FormField {
|
|
10
10
|
async parse(ctx, raw_value) {
|
|
11
11
|
let result;
|
|
12
|
-
if (raw_value instanceof
|
|
12
|
+
if (raw_value instanceof SealiousFile || is(raw_value, predicates.object) && hasShape(
|
|
13
13
|
{
|
|
14
14
|
filename: predicates.string,
|
|
15
15
|
id: predicates.string
|
|
16
16
|
},
|
|
17
17
|
raw_value
|
|
18
18
|
) && raw_value.id) {
|
|
19
|
-
const file = await
|
|
19
|
+
const file = await SealiousFile.fromID(
|
|
20
20
|
ctx.$app,
|
|
21
21
|
raw_value.id
|
|
22
22
|
);
|
|
@@ -35,12 +35,12 @@ class File extends FormField {
|
|
|
35
35
|
const old_file = hasFieldOfType(raw_value, "old", predicates.object) && hasShape(
|
|
36
36
|
{ id: predicates.string, filename: predicates.string },
|
|
37
37
|
raw_value.old
|
|
38
|
-
) && raw_value.old.id ? await
|
|
38
|
+
) && raw_value.old.id ? await SealiousFile.fromID(ctx.$app, raw_value.old.id) : null;
|
|
39
39
|
const new_file = hasFieldOfType(
|
|
40
40
|
raw_value,
|
|
41
41
|
"new",
|
|
42
42
|
predicates.array(predicates.object)
|
|
43
|
-
) && raw_value.new[0] instanceof
|
|
43
|
+
) && raw_value.new[0] instanceof SealiousFile ? raw_value.new[0] : null;
|
|
44
44
|
result = {
|
|
45
45
|
parsable: true,
|
|
46
46
|
error: null,
|
package/dist/mount.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Middlewares as SealiousMiddlewares } from "sealious";
|
|
2
2
|
async function handleHtmlPromise(ctx, next) {
|
|
3
3
|
await next();
|
|
4
4
|
if (ctx.body instanceof Promise) {
|
|
@@ -31,11 +31,11 @@ function mount(router, url, mountable, use_dummy_app = false) {
|
|
|
31
31
|
};
|
|
32
32
|
await next();
|
|
33
33
|
},
|
|
34
|
-
|
|
34
|
+
SealiousMiddlewares.parseBody(),
|
|
35
35
|
handleHtmlPromise
|
|
36
36
|
] : [
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
SealiousMiddlewares.extractContext(),
|
|
38
|
+
SealiousMiddlewares.parseBody(),
|
|
39
39
|
handleHtmlPromise
|
|
40
40
|
];
|
|
41
41
|
router.use(raw_url, ...args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sealcode/sealgen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Module to automate adding routes and collections to a sealious application",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -71,6 +71,6 @@
|
|
|
71
71
|
"peerDependencies": {
|
|
72
72
|
"koa": "^2.13.0",
|
|
73
73
|
"koa-responsive-image-router": "^0.2.6",
|
|
74
|
-
"sealious": "^0.
|
|
74
|
+
"sealious": "^0.18.0"
|
|
75
75
|
}
|
|
76
76
|
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import Router from "@koa/router";
|
|
2
|
-
import
|
|
2
|
+
import {
|
|
3
|
+
CollectionItem,
|
|
4
|
+
File as SealiousFile,
|
|
5
|
+
Field as SealiousField,
|
|
6
|
+
Collection,
|
|
7
|
+
} from "sealious";
|
|
3
8
|
import { Context } from "koa";
|
|
4
9
|
import { inputWrapper } from "../../utils/input-wrapper.js";
|
|
5
10
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
@@ -14,7 +19,7 @@ export type MultipleFilesOptions = {
|
|
|
14
19
|
uploadLabel?: string;
|
|
15
20
|
getAdditionalFields: (
|
|
16
21
|
ctx: Context,
|
|
17
|
-
file:
|
|
22
|
+
file: SealiousFile
|
|
18
23
|
) => Promise<Record<string, unknown>>;
|
|
19
24
|
};
|
|
20
25
|
|
|
@@ -52,7 +57,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
52
57
|
);
|
|
53
58
|
|
|
54
59
|
router.post(this.getFrameRelativeURL() + "/add", async (ctx) => {
|
|
55
|
-
let files = ctx.$body.files as
|
|
60
|
+
let files = ctx.$body.files as SealiousFile | SealiousFile[];
|
|
56
61
|
if (!files || !is(files, predicates.object)) {
|
|
57
62
|
ctx.body = "Missing files";
|
|
58
63
|
return;
|
|
@@ -64,7 +69,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
64
69
|
files.map((file) =>
|
|
65
70
|
this.addFileAssociation(
|
|
66
71
|
ctx,
|
|
67
|
-
file as unknown as
|
|
72
|
+
file as unknown as SealiousFile
|
|
68
73
|
)
|
|
69
74
|
)
|
|
70
75
|
);
|
|
@@ -81,7 +86,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
81
86
|
].removeByID(ctx.$context, file_item_id);
|
|
82
87
|
}
|
|
83
88
|
|
|
84
|
-
async addFileAssociation(ctx: Context, file:
|
|
89
|
+
async addFileAssociation(ctx: Context, file: SealiousFile) {
|
|
85
90
|
const file_field = this.getFileField();
|
|
86
91
|
if (!file_field) {
|
|
87
92
|
throw new Error("No file field in referencing collection");
|
|
@@ -130,7 +135,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
130
135
|
return result;
|
|
131
136
|
}
|
|
132
137
|
|
|
133
|
-
getFileField():
|
|
138
|
+
getFileField(): SealiousField | null {
|
|
134
139
|
for (const [_, field] of Object.entries(
|
|
135
140
|
this.getReferencingCollection().fields
|
|
136
141
|
)) {
|
|
@@ -142,28 +147,28 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
142
147
|
}
|
|
143
148
|
|
|
144
149
|
async extractFileFromItem(
|
|
145
|
-
item:
|
|
146
|
-
): Promise<
|
|
150
|
+
item: CollectionItem
|
|
151
|
+
): Promise<SealiousFile | null> {
|
|
147
152
|
const sealious_field = this.getFileField();
|
|
148
153
|
if (!sealious_field) {
|
|
149
154
|
return null;
|
|
150
155
|
}
|
|
151
|
-
return await
|
|
152
|
-
(item.collection as
|
|
156
|
+
return await SealiousFile.fromID(
|
|
157
|
+
(item.collection as Collection).app,
|
|
153
158
|
item.get(sealious_field.name).id
|
|
154
159
|
);
|
|
155
160
|
}
|
|
156
161
|
|
|
157
162
|
async renderFileItemPreview(
|
|
158
|
-
_fileItem:
|
|
159
|
-
file:
|
|
163
|
+
_fileItem: CollectionItem,
|
|
164
|
+
file: SealiousFile
|
|
160
165
|
): Promise<FlatTemplatable> {
|
|
161
166
|
return file.filename || "no filename";
|
|
162
167
|
}
|
|
163
168
|
|
|
164
169
|
async renderFileItem(
|
|
165
|
-
fileItem:
|
|
166
|
-
file:
|
|
170
|
+
fileItem: CollectionItem,
|
|
171
|
+
file: SealiousFile
|
|
167
172
|
): Promise<FlatTemplatable> {
|
|
168
173
|
return tempstream/* HTML */ `<li class="file-list-item">
|
|
169
174
|
<a
|
|
@@ -177,7 +182,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
177
182
|
</li>`;
|
|
178
183
|
}
|
|
179
184
|
|
|
180
|
-
renderFileRemoveButton(fileItem:
|
|
185
|
+
renderFileRemoveButton(fileItem: CollectionItem): FlatTemplatable {
|
|
181
186
|
return /* HTML */ ` <form
|
|
182
187
|
data-turbo-frame="${this.getFrameID()}"
|
|
183
188
|
action="${this.getFrameRelativeURL()}/delete/${fileItem.id}"
|
|
@@ -221,10 +226,7 @@ export class MultipleFiles extends FormFieldControl {
|
|
|
221
226
|
await this.extractFileFromItem(item),
|
|
222
227
|
])
|
|
223
228
|
)
|
|
224
|
-
).filter(([_, f]) => f !== null) as [
|
|
225
|
-
Sealious.CollectionItem,
|
|
226
|
-
Sealious.File
|
|
227
|
-
][];
|
|
229
|
+
).filter(([_, f]) => f !== null) as [CollectionItem, SealiousFile][];
|
|
228
230
|
|
|
229
231
|
return inputWrapper(
|
|
230
232
|
["multiple-files", this.field.name, ...this.getClassModifiers()],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "koa";
|
|
2
2
|
import { FlatTemplatable, tempstream } from "tempstream";
|
|
3
3
|
import { File } from "./file.js";
|
|
4
|
-
import
|
|
4
|
+
import { File as SealiousFile } from "sealious";
|
|
5
5
|
import { FormField } from "../fields/field.js";
|
|
6
6
|
import { SimpleInputOptions } from "./simple-input.js";
|
|
7
7
|
import { FormControlContext } from "./form-control.js";
|
|
@@ -34,7 +34,7 @@ export class Photo extends File {
|
|
|
34
34
|
if (!id) {
|
|
35
35
|
return empty_container;
|
|
36
36
|
}
|
|
37
|
-
const file = await
|
|
37
|
+
const file = await SealiousFile.fromID(ctx.$app, id);
|
|
38
38
|
return tempstream/* HTML */ `<div class="${class_name}">
|
|
39
39
|
${this.imageRouter.image({
|
|
40
40
|
resolutions: [100],
|
package/src/forms/fields/file.ts
CHANGED
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
predicates,
|
|
6
6
|
} from "@sealcode/ts-predicates";
|
|
7
7
|
import { Context } from "koa";
|
|
8
|
-
import
|
|
8
|
+
import { File as SealiousFile } from "sealious";
|
|
9
9
|
import { FormDataValue } from "../form-types.js";
|
|
10
10
|
import { FieldParseResult, FormField } from "./field.js";
|
|
11
11
|
|
|
12
12
|
export type FileContainer = {
|
|
13
|
-
old:
|
|
14
|
-
new:
|
|
13
|
+
old: SealiousFile | null;
|
|
14
|
+
new: SealiousFile | null;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
export class File<Required extends boolean> extends FormField<
|
|
@@ -24,7 +24,7 @@ export class File<Required extends boolean> extends FormField<
|
|
|
24
24
|
): Promise<FieldParseResult<FileContainer>> {
|
|
25
25
|
let result;
|
|
26
26
|
if (
|
|
27
|
-
raw_value instanceof
|
|
27
|
+
raw_value instanceof SealiousFile ||
|
|
28
28
|
(is(raw_value, predicates.object) &&
|
|
29
29
|
hasShape(
|
|
30
30
|
{
|
|
@@ -35,7 +35,7 @@ export class File<Required extends boolean> extends FormField<
|
|
|
35
35
|
) &&
|
|
36
36
|
raw_value.id)
|
|
37
37
|
) {
|
|
38
|
-
const file = await
|
|
38
|
+
const file = await SealiousFile.fromID(
|
|
39
39
|
ctx.$app,
|
|
40
40
|
raw_value.id as string
|
|
41
41
|
);
|
|
@@ -58,14 +58,14 @@ export class File<Required extends boolean> extends FormField<
|
|
|
58
58
|
raw_value.old
|
|
59
59
|
) &&
|
|
60
60
|
raw_value.old.id
|
|
61
|
-
? await
|
|
61
|
+
? await SealiousFile.fromID(ctx.$app, raw_value.old.id)
|
|
62
62
|
: null;
|
|
63
63
|
const new_file =
|
|
64
64
|
hasFieldOfType(
|
|
65
65
|
raw_value,
|
|
66
66
|
"new",
|
|
67
67
|
predicates.array(predicates.object)
|
|
68
|
-
) && raw_value.new[0] instanceof
|
|
68
|
+
) && raw_value.new[0] instanceof SealiousFile
|
|
69
69
|
? raw_value.new[0]
|
|
70
70
|
: null;
|
|
71
71
|
result = {
|
package/src/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { App, Context as SealiousContext } from "sealious";
|
|
2
2
|
import { FormDataValue } from "./forms/form-types.js";
|
|
3
3
|
|
|
4
4
|
declare module "koa" {
|
|
5
5
|
interface BaseContext {
|
|
6
|
-
$context:
|
|
6
|
+
$context: SealiousContext;
|
|
7
7
|
$app: App;
|
|
8
8
|
$body: Record<string, FormDataValue>;
|
|
9
9
|
}
|
package/src/mount.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Router from "@koa/router";
|
|
2
2
|
import Koa, { BaseContext, Context } from "koa";
|
|
3
|
-
import
|
|
3
|
+
import { Middlewares as SealiousMiddlewares } from "sealious";
|
|
4
4
|
import { Mountable } from "./page/mountable.js";
|
|
5
5
|
|
|
6
6
|
async function handleHtmlPromise(ctx: Context, next: Koa.Next) {
|
|
@@ -48,12 +48,12 @@ export function mount(
|
|
|
48
48
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
49
49
|
await next();
|
|
50
50
|
},
|
|
51
|
-
|
|
51
|
+
SealiousMiddlewares.parseBody(),
|
|
52
52
|
handleHtmlPromise,
|
|
53
53
|
]
|
|
54
54
|
: [
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
SealiousMiddlewares.extractContext(),
|
|
56
|
+
SealiousMiddlewares.parseBody(),
|
|
57
57
|
handleHtmlPromise,
|
|
58
58
|
];
|
|
59
59
|
|