@sealcode/sealgen 0.15.31 → 0.15.32
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/add-crud.d.ts +3 -0
- package/@types/src/page/mountable-with-fields.d.ts +5 -1
- package/@types/src/page/mountable-with-fields.test.d.ts +1 -0
- package/@types/src/templates/shared/collection-create-form.d.ts +1 -0
- package/@types/src/templates/shared/collection-list.d.ts +15 -0
- package/@types/src/templates/shared/shared-crud-form-fields.d.ts +1 -0
- package/@types/src/utils/write-file.d.ts +1 -0
- package/lib/page/mountable-with-fields.test.js +25 -0
- package/lib/templates/list.js +3 -3
- package/package.json +1 -1
- package/src/forms/fields/collection-field.ts +1 -1
- package/src/page/mountable-with-fields.test.ts +25 -0
- package/src/page/mountable-with-fields.ts +7 -3
- package/src/templates/list.ts +3 -3
|
@@ -10,6 +10,7 @@ export type PageErrorMessage = {
|
|
|
10
10
|
message: string;
|
|
11
11
|
};
|
|
12
12
|
export type Fields = Record<string, FormField<boolean, any>>;
|
|
13
|
+
type Resolved<T> = T extends Promise<infer X> ? X : never;
|
|
13
14
|
export declare abstract class MountableWithFields<F extends Fields = Fields> extends Mountable {
|
|
14
15
|
fields: F;
|
|
15
16
|
field_names_prefix: string;
|
|
@@ -32,6 +33,9 @@ export declare abstract class MountableWithFields<F extends Fields = Fields> ext
|
|
|
32
33
|
renderError(_: Context, error: PageErrorMessage): Promise<FlatTemplatable>;
|
|
33
34
|
renderMessages(_: Context, data: FormData<keyof Fields>): FlatTemplatable;
|
|
34
35
|
abstract extractRawValues(ctx: Context): Promise<Record<string, FormDataValue>>;
|
|
35
|
-
getParsedValues(ctx: Context): Promise<
|
|
36
|
+
getParsedValues(ctx: Context): Promise<{
|
|
37
|
+
[field in keyof F]: Resolved<ReturnType<F[field]["getValue"]>>["parsed"];
|
|
38
|
+
}>;
|
|
36
39
|
getDatabaseValues(ctx: Context): Promise<ShapeToType<FieldsToShape<F>>>;
|
|
37
40
|
}
|
|
41
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createItemFormTemplate(create_action_name: string, newfilefullpath: string, collection_name: string, list_action: string): Promise<string>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function makeDefaultFilterFields(collection_fields: {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
}[]): string;
|
|
5
|
+
export declare function makeDefaultDisplayFields(collection_fields: {
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
}[]): string;
|
|
9
|
+
declare const default_hooks: {
|
|
10
|
+
pre_header_html: string;
|
|
11
|
+
post_header_html: string;
|
|
12
|
+
post_import_js: string;
|
|
13
|
+
};
|
|
14
|
+
export declare function collectionListTemplate(collection_name: string, action_name: string, newfilefullpath: string, _hooks?: Partial<typeof default_hooks>): Promise<string>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function sharedCrudFormFields(collection_name: string, newfilefullpath: string): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function writeFile(path: string, content: string): Promise<void>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Form } from "../forms/form.js";
|
|
2
|
+
import { FieldTypes } from "sealious";
|
|
3
|
+
import { CollectionField } from "../forms/fields/collection-field.js";
|
|
4
|
+
describe("mountable-with-fields", () => {
|
|
5
|
+
it("properly types the getParsedValues method", () => {
|
|
6
|
+
const fields = { name: new CollectionField(true, new FieldTypes.Text()) };
|
|
7
|
+
new class extends Form {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.fields = fields;
|
|
11
|
+
this.controls = [];
|
|
12
|
+
}
|
|
13
|
+
async onSubmit(ctx, form_values) {
|
|
14
|
+
const data = await this.getParsedValues(ctx);
|
|
15
|
+
data.name?.trim();
|
|
16
|
+
const { parsed: data2 } = await this.fields.name.getValue(
|
|
17
|
+
ctx,
|
|
18
|
+
form_values.raw_values
|
|
19
|
+
);
|
|
20
|
+
data2?.trim();
|
|
21
|
+
}
|
|
22
|
+
}();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
//# sourceMappingURL=mountable-with-fields.test.js.map
|
package/lib/templates/list.js
CHANGED
|
@@ -29,7 +29,7 @@ const listTemplate = async (action_name, newfilefullpath) => {
|
|
|
29
29
|
]);
|
|
30
30
|
const importPath = curryImportPath(newfilefullpath);
|
|
31
31
|
const result = `import type { Context } from "koa";
|
|
32
|
-
import type { CollectionItem } from "sealious";
|
|
32
|
+
import type { CollectionItem, ItemListResult } from "sealious";
|
|
33
33
|
import type { FlatTemplatable } from "tempstream";
|
|
34
34
|
import { TempstreamJSX } from "tempstream";
|
|
35
35
|
import { ${uppercase_collection} } from "${importPath(
|
|
@@ -98,7 +98,7 @@ ${collection_fields.map((field) => {
|
|
|
98
98
|
] as {
|
|
99
99
|
field: string;
|
|
100
100
|
label: string;
|
|
101
|
-
format?: (value: unknown) => FlatTemplatable;
|
|
101
|
+
format?: (value: unknown, item: CollectionItem<typeof Opinions>) => FlatTemplatable;
|
|
102
102
|
}[];
|
|
103
103
|
|
|
104
104
|
export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
@@ -152,7 +152,7 @@ async getFilterValues(ctx: Context) {
|
|
|
152
152
|
{displayFields.map(({ field, format }) => {
|
|
153
153
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
|
154
154
|
const value = item.get(field as any);
|
|
155
|
-
return <td>{format ? format(value) : value}</td>;
|
|
155
|
+
return <td>{format ? format(value, item) : value}</td>;
|
|
156
156
|
})}
|
|
157
157
|
</tr>;
|
|
158
158
|
}
|
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Context } from "koa";
|
|
2
|
+
import { Form } from "../forms/form.js";
|
|
3
|
+
import { FieldTypes } from "sealious";
|
|
4
|
+
import { CollectionField } from "../forms/fields/collection-field.js";
|
|
5
|
+
import { FormData } from "../forms/form-types.js";
|
|
6
|
+
|
|
7
|
+
describe("mountable-with-fields", () => {
|
|
8
|
+
it("properly types the getParsedValues method", () => {
|
|
9
|
+
const fields = { name: new CollectionField(true, new FieldTypes.Text()) };
|
|
10
|
+
new (class extends Form<typeof fields, void> {
|
|
11
|
+
fields = fields;
|
|
12
|
+
controls = [];
|
|
13
|
+
async onSubmit(ctx: Context, form_values: FormData) {
|
|
14
|
+
const data = await this.getParsedValues(ctx);
|
|
15
|
+
// this should not throw a Typescript error
|
|
16
|
+
data.name?.trim();
|
|
17
|
+
const { parsed: data2 } = await this.fields.name.getValue(
|
|
18
|
+
ctx,
|
|
19
|
+
form_values.raw_values
|
|
20
|
+
);
|
|
21
|
+
data2?.trim();
|
|
22
|
+
}
|
|
23
|
+
})();
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -18,6 +18,8 @@ export type PageErrorMessage = { type: "access" | "internal"; message: string };
|
|
|
18
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
19
|
export type Fields = Record<string, FormField<boolean, any>>;
|
|
20
20
|
|
|
21
|
+
type Resolved<T> = T extends Promise<infer X> ? X : never;
|
|
22
|
+
|
|
21
23
|
export abstract class MountableWithFields<
|
|
22
24
|
F extends Fields = Fields
|
|
23
25
|
> extends Mountable {
|
|
@@ -134,9 +136,11 @@ export abstract class MountableWithFields<
|
|
|
134
136
|
ctx: Context
|
|
135
137
|
): Promise<Record<string, FormDataValue>>;
|
|
136
138
|
|
|
137
|
-
async getParsedValues(
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
async getParsedValues(ctx: Context): Promise<{
|
|
140
|
+
[field in keyof F]: Resolved<
|
|
141
|
+
ReturnType<F[field]["getValue"]>
|
|
142
|
+
>["parsed"];
|
|
143
|
+
}> {
|
|
140
144
|
const raw_values = await this.extractRawValues(ctx);
|
|
141
145
|
const result: Record<string, unknown> = {};
|
|
142
146
|
const promises = Object.entries(this.fields).map(
|
package/src/templates/list.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const listTemplate = async (
|
|
|
35
35
|
]);
|
|
36
36
|
const importPath = curryImportPath(newfilefullpath);
|
|
37
37
|
const result = `import type { Context } from "koa";
|
|
38
|
-
import type { CollectionItem } from "sealious";
|
|
38
|
+
import type { CollectionItem, ItemListResult } from "sealious";
|
|
39
39
|
import type { FlatTemplatable } from "tempstream";
|
|
40
40
|
import { TempstreamJSX } from "tempstream";
|
|
41
41
|
import { ${uppercase_collection} } from "${importPath(
|
|
@@ -113,7 +113,7 @@ ${collection_fields
|
|
|
113
113
|
] as {
|
|
114
114
|
field: string;
|
|
115
115
|
label: string;
|
|
116
|
-
format?: (value: unknown) => FlatTemplatable;
|
|
116
|
+
format?: (value: unknown, item: CollectionItem<typeof Opinions>) => FlatTemplatable;
|
|
117
117
|
}[];
|
|
118
118
|
|
|
119
119
|
export default new (class ${action_name}Page extends SealiousItemListPage<
|
|
@@ -167,7 +167,7 @@ async getFilterValues(ctx: Context) {
|
|
|
167
167
|
{displayFields.map(({ field, format }) => {
|
|
168
168
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/consistent-type-assertions, @typescript-eslint/no-explicit-any
|
|
169
169
|
const value = item.get(field as any);
|
|
170
|
-
return <td>{format ? format(value) : value}</td>;
|
|
170
|
+
return <td>{format ? format(value, item) : value}</td>;
|
|
171
171
|
})}
|
|
172
172
|
</tr>;
|
|
173
173
|
}
|