@sealcode/sealgen 0.15.43 → 0.15.44

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.
@@ -1,7 +1,6 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { FlatTemplatable } from "tempstream";
3
2
  export declare function toggleModal(options: {
4
3
  name: string;
5
4
  contentWrapped: (id: string) => FlatTemplatable | Promise<FlatTemplatable>;
6
5
  contentUnwrapped: (id: string) => FlatTemplatable | Promise<FlatTemplatable>;
7
- }): import("stream").Readable;
6
+ }): Promise<string>;
@@ -26,10 +26,10 @@ export declare class StructuredArray<Subfields extends Record<string, Field<any>
26
26
  getDefaultItemBody(): Promise<{}>;
27
27
  makeSubfield(_field_name: string): FormField;
28
28
  renderItemControl(ctx: Context, form_id: string, control: FormControl | UnboundControlStorage, item: FieldsetOutput<Subfields>, index: number): Promise<(string | number | import("stream").Readable | null) | (string | number | import("stream").Readable | null)[] | Promise<string | number | import("stream").Readable | null>[]>;
29
- renderItem(ctx: Context, form_id: string, item: FieldsetOutput<Subfields>, index: number): Promise<import("stream").Readable>;
29
+ renderItem(ctx: Context, form_id: string, item: FieldsetOutput<Subfields>, index: number): Promise<string>;
30
30
  getItems(ctx: Context, raw_values: Record<string, FormDataValue>): Promise<FieldsetOutput<Subfields>[]>;
31
- _render(ctx: Context, form_id: string, raw_values: Record<string, FormDataValue>): Promise<import("stream").Readable>;
32
- render(fctx: FormControlContext): Promise<import("stream").Readable>;
31
+ _render(ctx: Context, form_id: string, raw_values: Record<string, FormDataValue>): Promise<string>;
32
+ render(fctx: FormControlContext): Promise<string>;
33
33
  getTargetItemID(ctx: Context): Promise<string>;
34
34
  mount(router: Router): void;
35
35
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { Context } from "koa";
3
2
  import { PickFromListField } from "../fields/pick-from-list.js";
4
3
  import { FormControlContext } from "./form-control.js";
@@ -19,5 +18,5 @@ export declare class Autocomplete extends SimpleInput<string | null> {
19
18
  getInputAttributes(fctx: FormControlContext): Promise<{
20
19
  list: string;
21
20
  }>;
22
- postInput(ctx: Context): Promise<import("stream").Readable>;
21
+ postInput(ctx: Context): Promise<string>;
23
22
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { CheckboxedListField } from "../fields/checkboxed-list.js";
3
2
  import { FormControlContext } from "./form-control.js";
4
3
  import { FormFieldControl } from "./form-field-control.js";
@@ -10,5 +9,5 @@ export declare class CheckboxedListInput extends FormFieldControl {
10
9
  constructor(field: CheckboxedListField<boolean>, options?: {
11
10
  label: string;
12
11
  });
13
- render(fctx: FormControlContext): Promise<import("stream").Readable>;
12
+ render(fctx: FormControlContext): Promise<string>;
14
13
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { FlatTemplatable } from "tempstream";
3
2
  import { FieldGroup } from "./field-group.js";
4
3
  import { FormControl } from "./form-control.js";
@@ -15,7 +14,7 @@ export declare class CollapsibleFieldGroup extends FieldGroup {
15
14
  options: CollapsibleFieldGroupOptions;
16
15
  collapseID: string;
17
16
  constructor(controls: FormControl[], options?: CollapsibleFieldGroupOptions);
18
- getGroupLabelProps(): import("stream").Readable;
17
+ getGroupLabelProps(): Promise<string>;
19
18
  preLabelContainer(): FlatTemplatable;
20
19
  postLabel(): FlatTemplatable;
21
20
  }
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
2
  /// <reference types="koa__router" />
4
3
  import Router from "@koa/router";
5
4
  import { Context } from "koa";
@@ -17,6 +16,6 @@ export declare class DerivedFrame extends Derived<{
17
16
  generateFrameContent: (ctx: FormControlContext, args: ParsedUrlQuery) => Promise<FlatTemplatable>;
18
17
  frame_id: string;
19
18
  constructor(frame_name: string, fields: FormField[], generateFrameContent: (ctx: FormControlContext, args: ParsedUrlQuery) => Promise<FlatTemplatable>, frame_id?: string);
20
- renderBackendResponseFrame(_ctx: Context, content: FlatTemplatable): import("stream").Readable;
19
+ renderBackendResponseFrame(_ctx: Context, content: FlatTemplatable): Promise<string>;
21
20
  mount(router: Router): void;
22
21
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  import { Context } from "koa";
3
2
  import { FilePointer } from "@sealcode/file-manager";
4
3
  import { FlatTemplatable } from "tempstream";
@@ -9,6 +8,6 @@ import { SimpleInput } from "./simple-input.js";
9
8
  export declare class File extends SimpleInput<FileContainer> {
10
9
  getType(): string;
11
10
  renderFilePreview(_ctx: Context, file: FilePointer | null): Promise<FlatTemplatable>;
12
- preInput(fctx: FormControlContext, data: Record<string, FormDataValue>): Promise<import("stream").Readable>;
11
+ preInput(fctx: FormControlContext, data: Record<string, FormDataValue>): Promise<string>;
13
12
  getInputAttributes(fctx: FormControlContext): Promise<Record<string, string | boolean>>;
14
13
  }
@@ -1,5 +1,4 @@
1
1
  /// <reference types="koa__router" />
2
- /// <reference types="node" resolution-mode="require"/>
3
2
  import Router from "@koa/router";
4
3
  import { Collection, CollectionItem, Field as SealiousField } from "sealious";
5
4
  import { Context } from "koa";
@@ -23,7 +22,7 @@ export declare class MultipleFiles extends FormFieldControl {
23
22
  addFileAssociation(ctx: Context, file: FilePointer): Promise<void>;
24
23
  getFrameRelativeURL(): string;
25
24
  getFrameID(): string;
26
- renderFrame(_ctx: Context, content?: FlatTemplatable): import("stream").Readable;
25
+ renderFrame(_ctx: Context, content?: FlatTemplatable): Promise<string>;
27
26
  render(fctx: FormControlContext): FlatTemplatable | Promise<FlatTemplatable>;
28
27
  getReferencingCollection(): Collection;
29
28
  getFileField(): SealiousField<any> | null;
@@ -8,7 +8,7 @@ import { Form } from "../form.js";
8
8
  import { FormControl, FormControlContext } from "./form-control.js";
9
9
  export type TableControlOptions<F extends Record<string, FormField>> = {
10
10
  render_fields: {
11
- [field_name in keyof F]: (fctx: FormControlContext, name: string, value: string) => string;
11
+ [field_name in keyof F]: (fctx: FormControlContext, name: string, value: string) => FlatTemplatable | Promise<FlatTemplatable>;
12
12
  };
13
13
  allow_removing?: boolean;
14
14
  label_add?: string;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- import { Readable } from "stream";
3
1
  import { FlatTemplatable } from "tempstream";
4
2
  export declare function getRequiredClass(isRequired: boolean): string;
5
- export declare function inputWrapper(type: string, modifiers: string[], input: FlatTemplatable): Readable;
3
+ export declare function inputWrapper(type: string, modifiers: string[], input: FlatTemplatable): Promise<string>;
@@ -1,5 +1,6 @@
1
1
  import { hasShape, is, predicates } from "@sealcode/ts-predicates";
2
2
  import qs from "qs";
3
+ import { tempstream } from "tempstream";
3
4
  import { FormControl } from "./form-control.js";
4
5
  class Table extends FormControl {
5
6
  constructor(table_field, options) {
@@ -16,79 +17,76 @@ class Table extends FormControl {
16
17
  if (!rows) {
17
18
  rows = [];
18
19
  }
19
- return (
20
- /* HTML */
21
- `<turbo-frame
20
+ return tempstream`<turbo-frame
22
21
  id="${this.getFrameID()}"
23
22
  class="${[
24
- "form-input__wrapper",
25
- "form-input__wrapper--type--table",
26
- "form-input__wrapper--options-count--" + rows.length.toString(),
27
- ...rows.length >= 5 ? ["form-input__wrapper--options-count--5-or-more"] : [],
28
- ...rows.length >= 10 ? ["form-input__wrapper--options-count--10-or-more"] : [],
29
- ...rows.length >= 15 ? ["form-input__wrapper--options-count--15-or-more"] : [],
30
- ...rows.length >= 20 ? ["form-input__wrapper--options-count--20-or-more"] : []
31
- ].join(" ")}"
23
+ "form-input__wrapper",
24
+ "form-input__wrapper--type--table",
25
+ "form-input__wrapper--options-count--" + rows.length.toString(),
26
+ ...rows.length >= 5 ? ["form-input__wrapper--options-count--5-or-more"] : [],
27
+ ...rows.length >= 10 ? ["form-input__wrapper--options-count--10-or-more"] : [],
28
+ ...rows.length >= 15 ? ["form-input__wrapper--options-count--15-or-more"] : [],
29
+ ...rows.length >= 20 ? ["form-input__wrapper--options-count--20-or-more"] : []
30
+ ].join(" ")}"
32
31
  >
33
32
  <label>${this.options.label}</label>
34
33
  <div class="table__wrapper">
35
34
  <table>
36
35
  <tbody>
37
36
  ${rows?.map((row, row_index) => {
38
- return (
39
- /* HTML */
40
- `<tr>
37
+ return (
38
+ /* HTML */
39
+ tempstream`<tr>
41
40
  ${Object.entries(this.table_field.columns).map(([key]) => {
42
- return `<td>${this.options.render_fields[key](
43
- fctx,
44
- `${this.table_field.name}[${row_index}][${key}]`,
45
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
46
- row[key]
47
- )}</td>`;
48
- }).join("")}
41
+ return tempstream`<td>${this.options.render_fields[key](
42
+ fctx,
43
+ `${this.table_field.name}[${row_index}][${key}]`,
44
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
45
+ row[key]
46
+ )}</td>`;
47
+ })}
49
48
  ${this.options.allow_removing ? (
50
- /* HTML */
51
- `<td>
52
- <input
53
- type="submit"
54
- data-turbo-frame="${this.getFrameID()}"
55
- value="${this.options.label_remove || "remove"}"
56
- form="${fctx.form_id}"
57
- formnovalidate
58
- formaction="${this.getActionURL(
59
- this.table_field.name,
60
- {
61
- remove: {
62
- index: row_index
63
- }
49
+ /* HTML */
50
+ `<td>
51
+ <input
52
+ type="submit"
53
+ data-turbo-frame="${this.getFrameID()}"
54
+ value="${this.options.label_remove || "remove"}"
55
+ form="${fctx.form_id}"
56
+ formnovalidate
57
+ formaction="${this.getActionURL(
58
+ this.table_field.name,
59
+ {
60
+ remove: {
61
+ index: row_index
64
62
  }
65
- )}"
66
- />
67
- </td>`
68
- ) : ""}
63
+ }
64
+ )}"
65
+ />
66
+ </td>`
67
+ ) : ""}
69
68
  </tr>`
70
- );
71
- }).join("")}
69
+ );
70
+ })}
72
71
  </tbody>
73
72
  </table>
74
73
  ${this.options.allow_adding ? (
75
- /* HTML */
76
- `<input
74
+ /* HTML */
75
+ `<input
77
76
  type="submit"
78
77
  value="${this.options.label_add || "add"}"
79
78
  form="${fctx.form_id}"
80
79
  formnovalidate
81
80
  formaction="${this.getActionURL(
82
- this.table_field.name,
83
- {
84
- insert: { index: rows.length, value: {} }
85
- }
86
- )}"
81
+ this.table_field.name,
82
+ {
83
+ insert: { index: rows.length, value: {} }
84
+ }
85
+ )}"
87
86
  />`
88
- ) : ""}
87
+ ) : ""}
89
88
  </div>
90
- </turbo-frame>`
91
- );
89
+ </turbo-frame>`;
92
90
  }
93
91
  getFrameID() {
94
92
  return `array-frame-${this.table_field.name}`;
@@ -147,7 +145,7 @@ class Table extends FormControl {
147
145
  }
148
146
  ctx.override_reaction = {
149
147
  action: "stay",
150
- content: form.render(
148
+ content: await form.render(
151
149
  ctx,
152
150
  {
153
151
  raw_values: await form.extractRawValues(ctx),
@@ -9,7 +9,7 @@ const file_handler = async (_, { name, is_required }, importPath, { is_required_
9
9
  },
10
10
  field: `${name}: new Fields.File(${is_required_expr}, TheFileManager)`,
11
11
  initial_value_edit: `{old: item.get("${name}")}`,
12
- pre_edit: `const ${tempname} = data.${name}.new || data.${name}.old;
12
+ pre_edit: `const ${tempname} = data.["${name}"]?.new || data.["${name}"]?.old;
13
13
  if(!${tempname}){
14
14
  throw new Error("Missing field: ${name}")
15
15
  }`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.15.43",
3
+ "version": "0.15.44",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -74,7 +74,7 @@
74
74
  "prettier": "^2.7.1",
75
75
  "prompts": "^2.4.2",
76
76
  "recursive-readdir": "^2.2.3",
77
- "tempstream": "^0.3.4",
77
+ "tempstream": "^0.4.0",
78
78
  "tiny-glob": "^0.2.9",
79
79
  "ws": "^8.16.0",
80
80
  "yargs": "^17.6.2"
@@ -5,7 +5,7 @@ import Router from "@koa/router";
5
5
  import { hasShape, is, predicates } from "@sealcode/ts-predicates";
6
6
  import { Context } from "koa";
7
7
  import qs from "qs";
8
- import { FlatTemplatable } from "tempstream";
8
+ import { FlatTemplatable, tempstream } from "tempstream";
9
9
  import { FormField } from "../fields/field.js";
10
10
  import { Table as TableField } from "../fields/table.js";
11
11
  import { FormReaction } from "../form-types.js";
@@ -18,7 +18,7 @@ export type TableControlOptions<F extends Record<string, FormField>> = {
18
18
  fctx: FormControlContext,
19
19
  name: string,
20
20
  value: string
21
- ) => string;
21
+ ) => FlatTemplatable | Promise<FlatTemplatable>;
22
22
  };
23
23
  allow_removing?: boolean;
24
24
  label_add?: string;
@@ -51,7 +51,7 @@ export class Table<F extends Record<string, FormField>> extends FormControl {
51
51
  if (!rows) {
52
52
  rows = [];
53
53
  }
54
- return /* HTML */ `<turbo-frame
54
+ return tempstream/* HTML */ `<turbo-frame
55
55
  id="${this.getFrameID()}"
56
56
  class="${[
57
57
  "form-input__wrapper",
@@ -75,45 +75,44 @@ export class Table<F extends Record<string, FormField>> extends FormControl {
75
75
  <div class="table__wrapper">
76
76
  <table>
77
77
  <tbody>
78
- ${rows
79
- ?.map((row, row_index) => {
80
- return /* HTML */ `<tr>
81
- ${Object.entries(this.table_field.columns)
82
- .map(([key]) => {
83
- return `<td>${this.options.render_fields[
84
- key
85
- ](
86
- fctx,
87
- `${this.table_field.name}[${row_index}][${key}]`,
88
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
89
- row[key] as string
90
- )}</td>`;
91
- })
92
- .join("")}
93
- ${this.options.allow_removing
94
- ? /* HTML */ `<td>
95
- <input
96
- type="submit"
97
- data-turbo-frame="${this.getFrameID()}"
98
- value="${this.options
99
- .label_remove ||
100
- "remove"}"
101
- form="${fctx.form_id}"
102
- formnovalidate
103
- formaction="${this.getActionURL(
104
- this.table_field.name,
105
- {
106
- remove: {
107
- index: row_index,
108
- },
109
- }
110
- )}"
111
- />
112
- </td>`
113
- : ""}
78
+ ${rows?.map((row, row_index) => {
79
+ return /* HTML */ tempstream`<tr>
80
+ ${Object.entries(this.table_field.columns).map(([key]) => {
81
+ return tempstream`<td>${this.options.render_fields[
82
+ key
83
+ ](
84
+ fctx,
85
+ `${this.table_field.name}[${row_index}][${key}]`,
86
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
87
+ row[key] as string
88
+ )}</td>`;
89
+ })}
90
+ ${
91
+ this.options.allow_removing
92
+ ? /* HTML */ `<td>
93
+ <input
94
+ type="submit"
95
+ data-turbo-frame="${this.getFrameID()}"
96
+ value="${this.options
97
+ .label_remove ||
98
+ "remove"}"
99
+ form="${fctx.form_id}"
100
+ formnovalidate
101
+ formaction="${this.getActionURL(
102
+ this.table_field
103
+ .name,
104
+ {
105
+ remove: {
106
+ index: row_index,
107
+ },
108
+ }
109
+ )}"
110
+ />
111
+ </td>`
112
+ : ""
113
+ }
114
114
  </tr>`;
115
- })
116
- .join("")}
115
+ })}
117
116
  </tbody>
118
117
  </table>
119
118
  ${this.options.allow_adding
@@ -202,7 +201,7 @@ export class Table<F extends Record<string, FormField>> extends FormControl {
202
201
  }
203
202
  ctx.override_reaction = {
204
203
  action: "stay",
205
- content: form.render(
204
+ content: await form.render(
206
205
  ctx,
207
206
  {
208
207
  raw_values: await form.extractRawValues(ctx),
@@ -17,7 +17,7 @@ export const file_handler: FieldHandler<
17
17
  },
18
18
  field: `${name}: new Fields.File(${is_required_expr}, TheFileManager)`,
19
19
  initial_value_edit: `{old: item.get("${name}")}`,
20
- pre_edit: `const ${tempname} = data.${name}.new || data.${name}.old;
20
+ pre_edit: `const ${tempname} = data.["${name}"]?.new || data.["${name}"]?.old;
21
21
  if(!${tempname}){
22
22
  throw new Error("Missing field: ${name}")
23
23
  }`,
@@ -1,4 +1,3 @@
1
- import { Readable } from "stream";
2
1
  import { FlatTemplatable, tempstream } from "tempstream";
3
2
 
4
3
  export function getRequiredClass(isRequired: boolean): string {
@@ -13,7 +12,7 @@ export function inputWrapper(
13
12
  type: string,
14
13
  modifiers: string[],
15
14
  input: FlatTemplatable
16
- ): Readable {
15
+ ): Promise<string> {
17
16
  return tempstream/* HTML */ `<div
18
17
  class="form-input form-input--type-${type} form-input__wrapper ${getModifierClasses(
19
18
  modifiers