@sealcode/sealgen 0.18.0 → 0.18.2

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.
@@ -35,8 +35,8 @@ export declare abstract class StatefulPage<State extends Record<string, unknown>
35
35
  abstract getInitialState(ctx: Context): State | Promise<State>;
36
36
  abstract render(ctx: Context, state: State, inputs: Record<string, string>): Templatable | Promise<Templatable>;
37
37
  canAccess(): Promise<{
38
- readonly canAccess: true;
39
- readonly message: "";
38
+ canAccess: boolean;
39
+ message: string;
40
40
  }>;
41
41
  constructor();
42
42
  abstract wrapInLayout(ctx: Context, content: Templatable, state: State): Templatable;
@@ -1,21 +1,25 @@
1
1
  import { curryImportPath } from "../utils/import-path.js";
2
+ import { formatWithPrettier } from "../utils/prettier.js";
2
3
  async function statefulPageTemplate(action_name, newfilefullpath) {
3
4
  const rel = curryImportPath(newfilefullpath);
4
- return `import { TempstreamJSX, Templatable } from "tempstream";
5
+ return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
5
6
  import { Context } from "koa";
6
- import { StatefulPage } from "@sealcode/sealgen";
7
+ import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
7
8
  import html from "${rel("src/back/html.js")}";
8
9
 
9
10
  export const actionName = "${action_name}";
10
11
 
11
12
  const actions = {
12
- add: (state: State, inputs: Record<string, string>) => {
13
+ add: ({ state, inputs }: StatefulPageActionArgument<State>) => {
13
14
  return {
14
15
  ...state,
15
16
  elements: [...state.elements, inputs.element_to_add || "new element"],
16
17
  };
17
18
  },
18
- remove: (state: State, _: unknown, index_to_remove: number) => {
19
+ remove: ({
20
+ state,
21
+ args: [index_to_remove],
22
+ }: StatefulPageActionArgument<State, [number]>) => {
19
23
  return {
20
24
  ...state,
21
25
  elements: state.elements.filter((_, index) => index != index_to_remove),
@@ -35,7 +39,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
35
39
  }
36
40
 
37
41
  wrapInLayout(ctx: Context, content: Templatable): Templatable {
38
- return html(ctx, "${action_name}", content);
42
+ return html({ctx, title: "${action_name}", body: <>{content}</>, description: "${action_name}"});
39
43
  }
40
44
 
41
45
  render(ctx: Context, state: State, inputs: Record<string, string>) {
@@ -60,7 +64,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
60
64
  );
61
65
  }
62
66
  })();
63
- `;
67
+ `);
64
68
  }
65
69
  export {
66
70
  statefulPageTemplate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.18.0",
3
+ "version": "0.18.2",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -67,7 +67,7 @@ export abstract class StatefulPage<
67
67
  inputs: Record<string, string>
68
68
  ): Templatable | Promise<Templatable>;
69
69
 
70
- async canAccess() {
70
+ async canAccess(): Promise<{ canAccess: boolean; message: string }> {
71
71
  return <const>{ canAccess: true, message: "" };
72
72
  }
73
73
 
@@ -1,25 +1,29 @@
1
1
  import { curryImportPath } from "../utils/import-path.js";
2
+ import { formatWithPrettier } from "../utils/prettier.js";
2
3
 
3
4
  export async function statefulPageTemplate(
4
5
  action_name: string,
5
6
  newfilefullpath: string
6
7
  ): Promise<string> {
7
8
  const rel = curryImportPath(newfilefullpath);
8
- return `import { TempstreamJSX, Templatable } from "tempstream";
9
+ return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
9
10
  import { Context } from "koa";
10
- import { StatefulPage } from "@sealcode/sealgen";
11
+ import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
11
12
  import html from "${rel("src/back/html.js")}";
12
13
 
13
14
  export const actionName = "${action_name}";
14
15
 
15
16
  const actions = {
16
- add: (state: State, inputs: Record<string, string>) => {
17
+ add: ({ state, inputs }: StatefulPageActionArgument<State>) => {
17
18
  return {
18
19
  ...state,
19
20
  elements: [...state.elements, inputs.element_to_add || "new element"],
20
21
  };
21
22
  },
22
- remove: (state: State, _: unknown, index_to_remove: number) => {
23
+ remove: ({
24
+ state,
25
+ args: [index_to_remove],
26
+ }: StatefulPageActionArgument<State, [number]>) => {
23
27
  return {
24
28
  ...state,
25
29
  elements: state.elements.filter((_, index) => index != index_to_remove),
@@ -39,7 +43,7 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
39
43
  }
40
44
 
41
45
  wrapInLayout(ctx: Context, content: Templatable): Templatable {
42
- return html(ctx, "${action_name}", content);
46
+ return html({ctx, title: "${action_name}", body: <>{content}</>, description: "${action_name}"});
43
47
  }
44
48
 
45
49
  render(ctx: Context, state: State, inputs: Record<string, string>) {
@@ -64,5 +68,5 @@ export default new (class ${action_name}Page extends StatefulPage<State, typeof
64
68
  );
65
69
  }
66
70
  })();
67
- `;
71
+ `);
68
72
  }