@sealcode/sealgen 0.19.22 → 0.19.24

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.
@@ -30,6 +30,7 @@ export type StatefulPageActionArgument<State extends Record<string, unknown>, Ar
30
30
  export type StatefulPageAction<State extends Record<string, unknown>, Args extends unknown[] = unknown[]> = (obj: StatefulPageActionArgument<State, Args>) => State | Promise<State>;
31
31
  export type ExtractStatefulPageActionArgs<X> = X extends StatefulPageAction<any, infer Args> ? Args : never;
32
32
  export declare abstract class StatefulPage<State extends Record<string, unknown>, Actions extends Record<string, StatefulPageAction<State>>> extends Mountable {
33
+ form_id?: string | undefined;
33
34
  abstract actions: Actions;
34
35
  abstract getInitialState(ctx: Context): State | Promise<State>;
35
36
  abstract render(ctx: Context, state: State, inputs: Record<string, string>): Templatable | Promise<Templatable>;
@@ -37,7 +38,7 @@ export declare abstract class StatefulPage<State extends Record<string, unknown>
37
38
  canAccess: boolean;
38
39
  message: string;
39
40
  }>;
40
- constructor();
41
+ constructor(form_id?: string | undefined);
41
42
  abstract wrapInLayout(ctx: Context, content: Templatable, state: State): Templatable;
42
43
  wrapInForm(context: Context, state: State, content: Templatable): Promise<Templatable>;
43
44
  extractActionAndLabel<ActionName extends keyof Actions>(action_description: StatefulPageActionDescription<ActionName>): {
@@ -1 +1 @@
1
- export declare function LongRunningProcessTemplate(action_name: string, newfilefullpath: string): Promise<string>;
1
+ export declare function LongRunningProcessTemplate(action_name: string): Promise<string>;
@@ -1 +1 @@
1
- export declare function multiformTemplate(action_name: string, newfilefullpath: string): Promise<string>;
1
+ export declare function multiformTemplate(action_name: string): Promise<string>;
@@ -1 +1 @@
1
- export declare function testTemplate(action_name: string, new_file_fullpath: string): Promise<string>;
1
+ export declare function testTemplate(action_name: string): Promise<string>;
@@ -1 +1 @@
1
- export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string, list_action_name: string, importPath: (path: string) => string): Promise<string>;
1
+ export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string, list_action_name: string): Promise<string>;
@@ -1 +1 @@
1
- export declare function statefulPageTemplate(action_name: string, newfilefullpath: string): Promise<string>;
1
+ export declare function statefulPageTemplate(action_name: string): Promise<string>;
package/lib/add-crud.js CHANGED
@@ -5,7 +5,6 @@ import { toKebabCase, toPascalCase } from "js-convert-case";
5
5
  import { listCollections } from "./utils/list-collections.js";
6
6
  import { collectionListTemplate } from "./templates/shared/collection-list.js";
7
7
  import { writeFile } from "./utils/write-file.js";
8
- import { curryImportPath, importPath } from "./utils/import-path.js";
9
8
  import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
10
9
  import { generateRoutes } from "./generate-routes.js";
11
10
  import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
@@ -48,10 +47,7 @@ async function addCRUD(params, app_directory = process.cwd()) {
48
47
  list_action_name,
49
48
  list_path,
50
49
  {
51
- post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
52
- list_path,
53
- "src/back/routes/urls.ts"
54
- )}";`,
50
+ post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "src/back/routes/urls.js";`,
55
51
  post_header_html: `<a href={${create_action_name}URL}> Create </a>`,
56
52
  render_item: (collection_name2) => ` async renderItem(ctx: Context, item: CollectionItem<typeof ${toPascalCase(
57
53
  collection_name2
@@ -100,12 +96,10 @@ async function addCRUD(params, app_directory = process.cwd()) {
100
96
  const delete_path = target_locreq.resolve(
101
97
  `src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
102
98
  );
103
- const base_import_path = curryImportPath(delete_path);
104
99
  const delete_content = await itemDeleteTemplate(
105
100
  delete_action_name,
106
101
  collection_name,
107
- list_action_name,
108
- base_import_path
102
+ list_action_name
109
103
  );
110
104
  await writeFile(delete_path, delete_content);
111
105
  await generateRoutes();
@@ -10,7 +10,7 @@ describe("add crud test", () => {
10
10
  after(async () => {
11
11
  await page.close();
12
12
  });
13
- it("Generate simple sealious crud", async function() {
13
+ it.only("Generate simple sealious crud", async function() {
14
14
  const test_app = await RealAppTest.init();
15
15
  const path = "/sample";
16
16
  await test_app.runSealgenCommand(`add-collection --collection_name=sealcode-test`);
@@ -79,13 +79,13 @@ class StatefulPage extends Mountable {
79
79
  );
80
80
  }
81
81
  makeActionCallback(action_description, ...args) {
82
- return `(()=>{const form = this.closest('form'); form.action='${this.makeActionURL(
82
+ return `(()=>{const form = this.form; form.action='${this.makeActionURL(
83
83
  action_description,
84
84
  ...args
85
85
  )}'; form.requestSubmit()})()`;
86
86
  }
87
87
  rerender() {
88
- return "this.closest('form').requestSubmit()";
88
+ return "this.form.requestSubmit()";
89
89
  }
90
90
  async preprocessState(values) {
91
91
  return values;
@@ -187,9 +187,6 @@ class StatefulPage extends Mountable {
187
187
  ),
188
188
  page: this
189
189
  });
190
- console.debug("stateful-page.ts:320");
191
- console.log("NEW STATUS!!! AFTER ACTION");
192
- console.dir(new_state, { depth: 7 });
193
190
  ctx.body = this.render(ctx, new_state, inputs);
194
191
  } else {
195
192
  ctx.body = this.render(ctx, state, inputs);
@@ -1,12 +1,10 @@
1
1
  import { toSentenceCase } from "js-convert-case";
2
- import { curryImportPath } from "../utils/import-path.js";
3
- async function LongRunningProcessTemplate(action_name, newfilefullpath) {
4
- const rel = curryImportPath(newfilefullpath);
2
+ async function LongRunningProcessTemplate(action_name) {
5
3
  return `import { Context } from "koa";
6
4
  import { TempstreamJSX } from "tempstream";
7
5
  import { Page } from "@sealcode/sealgen";
8
6
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
9
- import html from "${rel("src/back/html.js")}";
7
+ import html from "src/back/html.js";
10
8
  import { LongRunningProcess } from "sealious";
11
9
 
12
10
  export const actionName = "${action_name}";
@@ -1,8 +1,6 @@
1
- import { curryImportPath } from "../utils/utils.js";
2
- async function multiformTemplate(action_name, newfilefullpath) {
3
- const rel = curryImportPath(newfilefullpath);
1
+ async function multiformTemplate(action_name) {
4
2
  return `import { Context } from "koa";
5
- import html from "${rel("src/back/html.js")}";
3
+ import html from "src/back/html.js";
6
4
  import { Controls, Fields, Form, FormMessage, Multiform } from "@sealcode/sealgen";
7
5
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
8
6
  import { FlatTemplatable } from "tempstream";
@@ -1,12 +1,8 @@
1
- import { curryImportPath } from "../utils/import-path.js";
2
1
  import { formatWithPrettier } from "../utils/prettier.js";
3
- async function testTemplate(action_name, new_file_fullpath) {
4
- const rel = curryImportPath(new_file_fullpath);
5
- const content = `import { withProdApp } from "${rel(
6
- "src/back/test_utils/with-prod-app.js"
7
- )}";
8
- import { ${action_name}URL } from "${rel("src/back/routes/urls.js")}";
9
- import { getBrowser } from "${rel("src/back/test_utils/browser-creator.js")}";
2
+ async function testTemplate(action_name) {
3
+ const content = `import { withProdApp } from ""src/back/test_utils/with-prod-app.js";
4
+ import { ${action_name}URL } from "src/back/routes/urls.js";
5
+ import { getBrowser } from "src/back/test_utils/browser-creator.js";
10
6
  import type { Browser, BrowserContext, Page } from "@playwright/test";
11
7
 
12
8
  describe("${action_name}", () => {
@@ -1,18 +1,14 @@
1
1
  import { toKebabCase, toPascalCase } from "js-convert-case";
2
2
  import { formatWithPrettier } from "../../utils/prettier.js";
3
- function itemDeleteTemplate(delete_action_name, collection_name, list_action_name, importPath) {
3
+ function itemDeleteTemplate(delete_action_name, collection_name, list_action_name) {
4
4
  const result = `import type { Context } from "koa";
5
5
  import { Mountable } from "@sealcode/sealgen";
6
6
  import type Router from "@koa/router";
7
7
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
8
8
 
9
- import { ${toPascalCase(collection_name)} } from "${importPath(
10
- "src/back/collections/collections.js"
11
- )}";
9
+ import { ${toPascalCase(collection_name)} } from "src/back/collections/collections.js";
12
10
 
13
- import { ${list_action_name}URL } from "${importPath(
14
- "src/back/routes/urls.js"
15
- )}";
11
+ import { ${list_action_name}URL } from "src/back/routes/urls.js";
16
12
 
17
13
  export const actionName = "${delete_action_name}";
18
14
  export const breadcrumbLabel: BreadcrumbLabel = "${delete_action_name}";
@@ -1,12 +1,10 @@
1
- import { curryImportPath } from "../utils/import-path.js";
2
1
  import { formatWithPrettier } from "../utils/prettier.js";
3
- async function statefulPageTemplate(action_name, newfilefullpath) {
4
- const rel = curryImportPath(newfilefullpath);
2
+ async function statefulPageTemplate(action_name) {
5
3
  return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
6
4
  import { Context } from "koa";
7
5
  import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
8
6
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
9
- import html from "${rel("src/back/html.js")}";
7
+ import html from "src/back/html.js";
10
8
 
11
9
  export const actionName = "${action_name}";
12
10
  export const breadcrumbLabel: BreadcrumbLabel = "${action_name}";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sealcode/sealgen",
3
- "version": "0.19.22",
3
+ "version": "0.19.24",
4
4
  "description": "Module to automate adding routes and collections to a sealious application",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
package/src/add-crud.ts CHANGED
@@ -5,7 +5,6 @@ import { toKebabCase, toPascalCase } from "js-convert-case";
5
5
  import { listCollections } from "./utils/list-collections.js";
6
6
  import { collectionListTemplate } from "./templates/shared/collection-list.js";
7
7
  import { writeFile } from "./utils/write-file.js";
8
- import { curryImportPath, importPath } from "./utils/import-path.js";
9
8
  import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
10
9
  import { generateRoutes } from "./generate-routes.js";
11
10
  import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
@@ -57,10 +56,7 @@ export async function addCRUD(
57
56
  list_action_name,
58
57
  list_path,
59
58
  {
60
- post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
61
- list_path,
62
- "src/back/routes/urls.ts"
63
- )}";`,
59
+ post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "src/back/routes/urls.js";`,
64
60
  post_header_html: `<a href={${create_action_name}URL}> Create </a>`,
65
61
  render_item: (
66
62
  collection_name: string
@@ -119,12 +115,10 @@ export async function addCRUD(
119
115
  const delete_path = target_locreq.resolve(
120
116
  `src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
121
117
  );
122
- const base_import_path = curryImportPath(delete_path);
123
118
  const delete_content = await itemDeleteTemplate(
124
119
  delete_action_name,
125
120
  collection_name,
126
- list_action_name,
127
- base_import_path
121
+ list_action_name
128
122
  );
129
123
  await writeFile(delete_path, delete_content);
130
124
 
@@ -173,14 +173,14 @@ export abstract class StatefulPage<
173
173
  | ActionName,
174
174
  ...args: ExtractStatefulPageActionArgs<Actions[ActionName]>
175
175
  ) {
176
- return `(()=>{const form = this.closest('form'); form.action='${this.makeActionURL(
176
+ return `(()=>{const form = this.form; form.action='${this.makeActionURL(
177
177
  action_description,
178
178
  ...args
179
179
  )}'; form.requestSubmit()})()`;
180
180
  }
181
181
 
182
182
  rerender() {
183
- return "this.closest('form').requestSubmit()";
183
+ return "this.form.requestSubmit()";
184
184
  }
185
185
 
186
186
  async preprocessState(values: State): Promise<State> {
@@ -1,16 +1,13 @@
1
1
  import { toSentenceCase } from "js-convert-case";
2
- import { curryImportPath } from "../utils/import-path.js";
3
2
 
4
3
  export async function LongRunningProcessTemplate(
5
- action_name: string,
6
- newfilefullpath: string
4
+ action_name: string
7
5
  ): Promise<string> {
8
- const rel = curryImportPath(newfilefullpath);
9
6
  return `import { Context } from "koa";
10
7
  import { TempstreamJSX } from "tempstream";
11
8
  import { Page } from "@sealcode/sealgen";
12
9
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
13
- import html from "${rel("src/back/html.js")}";
10
+ import html from "src/back/html.js";
14
11
  import { LongRunningProcess } from "sealious";
15
12
 
16
13
  export const actionName = "${action_name}";
@@ -1,12 +1,6 @@
1
- import { curryImportPath } from "../utils/utils.js";
2
-
3
- export async function multiformTemplate(
4
- action_name: string,
5
- newfilefullpath: string
6
- ): Promise<string> {
7
- const rel = curryImportPath(newfilefullpath);
1
+ export async function multiformTemplate(action_name: string): Promise<string> {
8
2
  return `import { Context } from "koa";
9
- import html from "${rel("src/back/html.js")}";
3
+ import html from "src/back/html.js";
10
4
  import { Controls, Fields, Form, FormMessage, Multiform } from "@sealcode/sealgen";
11
5
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
12
6
  import { FlatTemplatable } from "tempstream";
@@ -1,16 +1,9 @@
1
- import { curryImportPath } from "../utils/import-path.js";
2
1
  import { formatWithPrettier } from "../utils/prettier.js";
3
2
 
4
- export async function testTemplate(
5
- action_name: string,
6
- new_file_fullpath: string
7
- ) {
8
- const rel = curryImportPath(new_file_fullpath);
9
- const content = `import { withProdApp } from "${rel(
10
- "src/back/test_utils/with-prod-app.js"
11
- )}";
12
- import { ${action_name}URL } from "${rel("src/back/routes/urls.js")}";
13
- import { getBrowser } from "${rel("src/back/test_utils/browser-creator.js")}";
3
+ export async function testTemplate(action_name: string) {
4
+ const content = `import { withProdApp } from ""src/back/test_utils/with-prod-app.js";
5
+ import { ${action_name}URL } from "src/back/routes/urls.js";
6
+ import { getBrowser } from "src/back/test_utils/browser-creator.js";
14
7
  import type { Browser, BrowserContext, Page } from "@playwright/test";
15
8
 
16
9
  describe("${action_name}", () => {
@@ -4,21 +4,16 @@ import { formatWithPrettier } from "../../utils/prettier.js";
4
4
  export function itemDeleteTemplate(
5
5
  delete_action_name: string,
6
6
  collection_name: string,
7
- list_action_name: string,
8
- importPath: (path: string) => string
7
+ list_action_name: string
9
8
  ): Promise<string> {
10
9
  const result = `import type { Context } from "koa";
11
10
  import { Mountable } from "@sealcode/sealgen";
12
11
  import type Router from "@koa/router";
13
12
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
14
13
 
15
- import { ${toPascalCase(collection_name)} } from "${importPath(
16
- "src/back/collections/collections.js"
17
- )}";
14
+ import { ${toPascalCase(collection_name)} } from "src/back/collections/collections.js";
18
15
 
19
- import { ${list_action_name}URL } from "${importPath(
20
- "src/back/routes/urls.js"
21
- )}";
16
+ import { ${list_action_name}URL } from "src/back/routes/urls.js";
22
17
 
23
18
  export const actionName = "${delete_action_name}";
24
19
  export const breadcrumbLabel: BreadcrumbLabel = "${delete_action_name}";
@@ -1,16 +1,13 @@
1
- import { curryImportPath } from "../utils/import-path.js";
2
1
  import { formatWithPrettier } from "../utils/prettier.js";
3
2
 
4
3
  export async function statefulPageTemplate(
5
- action_name: string,
6
- newfilefullpath: string
4
+ action_name: string
7
5
  ): Promise<string> {
8
- const rel = curryImportPath(newfilefullpath);
9
6
  return formatWithPrettier(`import { TempstreamJSX, Templatable } from "tempstream";
10
7
  import { Context } from "koa";
11
8
  import { StatefulPage, StatefulPageActionArgument } from "@sealcode/sealgen";
12
9
  import type { BreadcrumbLabel } from "@sealcode/sealgen";
13
- import html from "${rel("src/back/html.js")}";
10
+ import html from "src/back/html.js";
14
11
 
15
12
  export const actionName = "${action_name}";
16
13
  export const breadcrumbLabel: BreadcrumbLabel = "${action_name}";