@sealcode/sealgen 0.17.19 → 0.17.20
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/templates/shared/item-delete.d.ts +1 -1
- package/lib/add-verbose-crud.js +6 -18
- package/lib/templates/shared/item-delete.js +2 -4
- package/package.json +1 -1
- package/src/add-verbose-crud.ts +6 -21
- package/src/templates/shared/item-delete.ts +3 -4
- package/lib/templates/shared/confirm-item-delete.js +0 -74
- package/src/templates/shared/confirm-item-delete.ts +0 -78
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string,
|
|
1
|
+
export declare function itemDeleteTemplate(delete_action_name: string, collection_name: string, list_action_name: string, importPath: (path: string) => string): Promise<string>;
|
package/lib/add-verbose-crud.js
CHANGED
|
@@ -5,12 +5,11 @@ 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 { importPath } from "./utils/import-path.js";
|
|
8
|
+
import { curryImportPath, importPath } from "./utils/import-path.js";
|
|
9
9
|
import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
|
|
10
10
|
import { generateRoutes } from "./generate-routes.js";
|
|
11
11
|
import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
|
|
12
12
|
import { editItemFormTemplate } from "./templates/shared/collection-edit-form.js";
|
|
13
|
-
import { askItemDeleteTemplate } from "./templates/shared/confirm-item-delete.js";
|
|
14
13
|
import { itemDeleteTemplate } from "./templates/shared/item-delete.js";
|
|
15
14
|
async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
16
15
|
const target_locreq = _locreq(app_directory);
|
|
@@ -40,7 +39,6 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
40
39
|
const list_action_name = toPascalCase(collection_name) + "CRUDList";
|
|
41
40
|
const create_action_name = toPascalCase(collection_name) + "CRUDCreate";
|
|
42
41
|
const edit_action_name = toPascalCase(collection_name) + "CRUDEdit";
|
|
43
|
-
const delete_ask_action_name = toPascalCase(collection_name) + "CRUDDeleteAsk";
|
|
44
42
|
const delete_action_name = toPascalCase(collection_name) + "CRUDDelete";
|
|
45
43
|
const list_path = target_locreq.resolve(
|
|
46
44
|
`src/back/routes/${escape_url_params(url)}/index.list.tsx`
|
|
@@ -50,7 +48,7 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
50
48
|
list_action_name,
|
|
51
49
|
list_path,
|
|
52
50
|
{
|
|
53
|
-
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${
|
|
51
|
+
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
|
|
54
52
|
list_path,
|
|
55
53
|
"src/back/routes/urls.ts"
|
|
56
54
|
)}";`,
|
|
@@ -66,7 +64,7 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
66
64
|
})}
|
|
67
65
|
<td><div class="sealious-list__actions">
|
|
68
66
|
<a href={${edit_action_name}URL(item.id)}>Edit</a>
|
|
69
|
-
<a href={${
|
|
67
|
+
<a data-turbo-method="POST" data-turbo-confirm="Delete item?" href={${delete_action_name}URL(item.id)}>Delete</a>
|
|
70
68
|
</div>
|
|
71
69
|
</td>
|
|
72
70
|
</tr>;
|
|
@@ -102,25 +100,15 @@ async function addVerboseCRUD(params, app_directory = process.cwd()) {
|
|
|
102
100
|
list_action_name
|
|
103
101
|
);
|
|
104
102
|
await writeFile(edit_path, edit_content);
|
|
105
|
-
const delete_ask_path = target_locreq.resolve(
|
|
106
|
-
`src/back/routes/${escape_url_params(url)}/[id]/delete-ask.page.tsx`
|
|
107
|
-
);
|
|
108
|
-
const delete_ask_content = await askItemDeleteTemplate(
|
|
109
|
-
delete_ask_action_name,
|
|
110
|
-
collection_name,
|
|
111
|
-
delete_ask_path,
|
|
112
|
-
list_action_name,
|
|
113
|
-
delete_action_name
|
|
114
|
-
);
|
|
115
|
-
await writeFile(delete_ask_path, delete_ask_content);
|
|
116
103
|
const delete_path = target_locreq.resolve(
|
|
117
104
|
`src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
|
|
118
105
|
);
|
|
106
|
+
const base_import_path = curryImportPath(delete_path);
|
|
119
107
|
const delete_content = await itemDeleteTemplate(
|
|
120
108
|
delete_action_name,
|
|
121
109
|
collection_name,
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
list_action_name,
|
|
111
|
+
base_import_path
|
|
124
112
|
);
|
|
125
113
|
await writeFile(delete_path, delete_content);
|
|
126
114
|
await generateRoutes();
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
2
|
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
function itemDeleteTemplate(delete_action_name, collection_name,
|
|
5
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
3
|
+
function itemDeleteTemplate(delete_action_name, collection_name, list_action_name, importPath) {
|
|
6
4
|
const result = `import type { Context } from "koa";
|
|
7
5
|
import { Mountable } from "@sealcode/sealgen";
|
|
8
6
|
import type Router from "@koa/router";
|
|
@@ -25,7 +23,7 @@ export default new (class ${delete_action_name}Redirect extends Mountable {
|
|
|
25
23
|
};
|
|
26
24
|
|
|
27
25
|
mount(router: Router, path: string) {
|
|
28
|
-
router.
|
|
26
|
+
router.post(path, async (ctx) => {
|
|
29
27
|
await ctx.$app.collections["${toKebabCase(
|
|
30
28
|
collection_name
|
|
31
29
|
)}"].removeByID(ctx.$context, ctx.params.id!);
|
package/package.json
CHANGED
package/src/add-verbose-crud.ts
CHANGED
|
@@ -5,12 +5,11 @@ 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 { importPath } from "./utils/import-path.js";
|
|
8
|
+
import { curryImportPath, importPath } from "./utils/import-path.js";
|
|
9
9
|
import { sharedCrudFormFields } from "./templates/shared/shared-crud-form-fields.js";
|
|
10
10
|
import { generateRoutes } from "./generate-routes.js";
|
|
11
11
|
import { createItemFormTemplate } from "./templates/shared/collection-create-form.js";
|
|
12
12
|
import { editItemFormTemplate } from "./templates/shared/collection-edit-form.js";
|
|
13
|
-
import { askItemDeleteTemplate } from "./templates/shared/confirm-item-delete.js";
|
|
14
13
|
import { itemDeleteTemplate } from "./templates/shared/item-delete.js";
|
|
15
14
|
|
|
16
15
|
export async function addVerboseCRUD(
|
|
@@ -50,8 +49,6 @@ export async function addVerboseCRUD(
|
|
|
50
49
|
const list_action_name = toPascalCase(collection_name) + "CRUDList";
|
|
51
50
|
const create_action_name = toPascalCase(collection_name) + "CRUDCreate";
|
|
52
51
|
const edit_action_name = toPascalCase(collection_name) + "CRUDEdit";
|
|
53
|
-
const delete_ask_action_name =
|
|
54
|
-
toPascalCase(collection_name) + "CRUDDeleteAsk";
|
|
55
52
|
const delete_action_name = toPascalCase(collection_name) + "CRUDDelete";
|
|
56
53
|
|
|
57
54
|
/* create the list endpoint */
|
|
@@ -63,7 +60,7 @@ export async function addVerboseCRUD(
|
|
|
63
60
|
list_action_name,
|
|
64
61
|
list_path,
|
|
65
62
|
{
|
|
66
|
-
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${
|
|
63
|
+
post_import_js: `import { ${create_action_name}URL, ${edit_action_name}URL, ${delete_action_name}URL } from "${importPath(
|
|
67
64
|
list_path,
|
|
68
65
|
"src/back/routes/urls.ts"
|
|
69
66
|
)}";`,
|
|
@@ -81,7 +78,7 @@ export async function addVerboseCRUD(
|
|
|
81
78
|
})}
|
|
82
79
|
<td><div class="sealious-list__actions">
|
|
83
80
|
<a href={${edit_action_name}URL(item.id)}>Edit</a>
|
|
84
|
-
<a href={${
|
|
81
|
+
<a data-turbo-method="POST" data-turbo-confirm="Delete item?" href={${delete_action_name}URL(item.id)}>Delete</a>
|
|
85
82
|
</div>
|
|
86
83
|
</td>
|
|
87
84
|
</tr>;
|
|
@@ -124,28 +121,16 @@ export async function addVerboseCRUD(
|
|
|
124
121
|
);
|
|
125
122
|
await writeFile(edit_path, edit_content);
|
|
126
123
|
|
|
127
|
-
/* create the confirm delete endpoint */
|
|
128
|
-
const delete_ask_path = target_locreq.resolve(
|
|
129
|
-
`src/back/routes/${escape_url_params(url)}/[id]/delete-ask.page.tsx`
|
|
130
|
-
);
|
|
131
|
-
const delete_ask_content = await askItemDeleteTemplate(
|
|
132
|
-
delete_ask_action_name,
|
|
133
|
-
collection_name,
|
|
134
|
-
delete_ask_path,
|
|
135
|
-
list_action_name,
|
|
136
|
-
delete_action_name
|
|
137
|
-
);
|
|
138
|
-
await writeFile(delete_ask_path, delete_ask_content);
|
|
139
|
-
|
|
140
124
|
/* create the actual delete endpoint */
|
|
141
125
|
const delete_path = target_locreq.resolve(
|
|
142
126
|
`src/back/routes/${escape_url_params(url)}/[id]/delete.page.tsx`
|
|
143
127
|
);
|
|
128
|
+
const base_import_path = curryImportPath(delete_path);
|
|
144
129
|
const delete_content = await itemDeleteTemplate(
|
|
145
130
|
delete_action_name,
|
|
146
131
|
collection_name,
|
|
147
|
-
|
|
148
|
-
|
|
132
|
+
list_action_name,
|
|
133
|
+
base_import_path
|
|
149
134
|
);
|
|
150
135
|
await writeFile(delete_path, delete_content);
|
|
151
136
|
|
|
@@ -5,10 +5,9 @@ import { formatWithPrettier } from "../../utils/prettier.js";
|
|
|
5
5
|
export function itemDeleteTemplate(
|
|
6
6
|
delete_action_name: string,
|
|
7
7
|
collection_name: string,
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
list_action_name: string,
|
|
9
|
+
importPath: (path: string) => string
|
|
10
10
|
): Promise<string> {
|
|
11
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
12
11
|
const result = `import type { Context } from "koa";
|
|
13
12
|
import { Mountable } from "@sealcode/sealgen";
|
|
14
13
|
import type Router from "@koa/router";
|
|
@@ -31,7 +30,7 @@ export default new (class ${delete_action_name}Redirect extends Mountable {
|
|
|
31
30
|
};
|
|
32
31
|
|
|
33
32
|
mount(router: Router, path: string) {
|
|
34
|
-
router.
|
|
33
|
+
router.post(path, async (ctx) => {
|
|
35
34
|
await ctx.$app.collections["${toKebabCase(
|
|
36
35
|
collection_name
|
|
37
36
|
)}"].removeByID(ctx.$context, ctx.params.id!);
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
|
-
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
async function askItemDeleteTemplate(ask_delete_action_name, collection_name, newfilefullpath, list_action_name, delete_action_name) {
|
|
5
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
6
|
-
const result = `import type { Context } from "koa";
|
|
7
|
-
import { Page } from "@sealcode/sealgen";
|
|
8
|
-
import type { CollectionItem } from "sealious";
|
|
9
|
-
import { TempstreamJSX } from "tempstream";
|
|
10
|
-
import { ${delete_action_name}URL } from "${importPath(
|
|
11
|
-
"src/back/routes/urls.js"
|
|
12
|
-
)}";
|
|
13
|
-
import html from "${importPath("src/back/html.ts")}";
|
|
14
|
-
import { ${toPascalCase(collection_name)} as ${toPascalCase(
|
|
15
|
-
collection_name
|
|
16
|
-
)}Collection } from "${importPath("src/back/collections/collections.js")}";
|
|
17
|
-
|
|
18
|
-
export const actionName = "${ask_delete_action_name}";
|
|
19
|
-
|
|
20
|
-
export default new (class ${ask_delete_action_name}Page extends Page {
|
|
21
|
-
canAccess = async (ctx: Context) => {
|
|
22
|
-
const policy = ${toPascalCase(
|
|
23
|
-
collection_name
|
|
24
|
-
)}Collection.getPolicy("edit");
|
|
25
|
-
const response = await policy.check(ctx.$context);
|
|
26
|
-
return { canAccess: response?.allowed || false, message: response?.reason || "" };
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
getItemTitle(_ctx: Context, item: CollectionItem<typeof ${toPascalCase(
|
|
30
|
-
collection_name
|
|
31
|
-
)}Collection>){
|
|
32
|
-
return item.get("name")
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async render(ctx: Context) {
|
|
36
|
-
const id = ctx.params.id
|
|
37
|
-
if(!id){throw new Error("Could not read the id param from the URL")}
|
|
38
|
-
const { items: [item] } =
|
|
39
|
-
await ctx.$app.collections["${toKebabCase(
|
|
40
|
-
collection_name
|
|
41
|
-
)}"].list(ctx.$context).ids([id]).fetch();
|
|
42
|
-
|
|
43
|
-
if (!item) {
|
|
44
|
-
throw new Error("Item with given id not found");
|
|
45
|
-
}
|
|
46
|
-
return html(
|
|
47
|
-
ctx,
|
|
48
|
-
"Delete?",
|
|
49
|
-
<div>
|
|
50
|
-
<div class="confirm-delete-page confirm-delete-page--${toKebabCase(
|
|
51
|
-
collection_name
|
|
52
|
-
)}">
|
|
53
|
-
<span>
|
|
54
|
-
Are you sure you want to remove: {" "}
|
|
55
|
-
<b>{this.getItemTitle(ctx, item)}</b>
|
|
56
|
-
</span>
|
|
57
|
-
<form action={${delete_action_name}URL(item.id)}>
|
|
58
|
-
<button type="submit">
|
|
59
|
-
remove
|
|
60
|
-
</button>
|
|
61
|
-
<input type="hidden" name="id" value={item?.id} />
|
|
62
|
-
</form>
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
})();
|
|
68
|
-
`;
|
|
69
|
-
return await formatWithPrettier(result);
|
|
70
|
-
}
|
|
71
|
-
export {
|
|
72
|
-
askItemDeleteTemplate
|
|
73
|
-
};
|
|
74
|
-
//# sourceMappingURL=confirm-item-delete.js.map
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { toKebabCase, toPascalCase } from "js-convert-case";
|
|
2
|
-
import { curryImportPath } from "../../utils/import-path.js";
|
|
3
|
-
import { formatWithPrettier } from "../../utils/prettier.js";
|
|
4
|
-
|
|
5
|
-
export async function askItemDeleteTemplate(
|
|
6
|
-
ask_delete_action_name: string,
|
|
7
|
-
collection_name: string,
|
|
8
|
-
newfilefullpath: string,
|
|
9
|
-
list_action_name: string,
|
|
10
|
-
delete_action_name: string
|
|
11
|
-
): Promise<string> {
|
|
12
|
-
const importPath = curryImportPath(newfilefullpath);
|
|
13
|
-
const result = `import type { Context } from "koa";
|
|
14
|
-
import { Page } from "@sealcode/sealgen";
|
|
15
|
-
import type { CollectionItem } from "sealious";
|
|
16
|
-
import { TempstreamJSX } from "tempstream";
|
|
17
|
-
import { ${delete_action_name}URL } from "${importPath(
|
|
18
|
-
"src/back/routes/urls.js"
|
|
19
|
-
)}";
|
|
20
|
-
import html from "${importPath("src/back/html.ts")}";
|
|
21
|
-
import { ${toPascalCase(collection_name)} as ${toPascalCase(
|
|
22
|
-
collection_name
|
|
23
|
-
)}Collection } from "${importPath("src/back/collections/collections.js")}";
|
|
24
|
-
|
|
25
|
-
export const actionName = "${ask_delete_action_name}";
|
|
26
|
-
|
|
27
|
-
export default new (class ${ask_delete_action_name}Page extends Page {
|
|
28
|
-
canAccess = async (ctx: Context) => {
|
|
29
|
-
const policy = ${toPascalCase(
|
|
30
|
-
collection_name
|
|
31
|
-
)}Collection.getPolicy("edit");
|
|
32
|
-
const response = await policy.check(ctx.$context);
|
|
33
|
-
return { canAccess: response?.allowed || false, message: response?.reason || "" };
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
getItemTitle(_ctx: Context, item: CollectionItem<typeof ${toPascalCase(
|
|
37
|
-
collection_name
|
|
38
|
-
)}Collection>){
|
|
39
|
-
return item.get("name")
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
async render(ctx: Context) {
|
|
43
|
-
const id = ctx.params.id
|
|
44
|
-
if(!id){throw new Error("Could not read the id param from the URL")}
|
|
45
|
-
const { items: [item] } =
|
|
46
|
-
await ctx.$app.collections["${toKebabCase(
|
|
47
|
-
collection_name
|
|
48
|
-
)}"].list(ctx.$context).ids([id]).fetch();
|
|
49
|
-
|
|
50
|
-
if (!item) {
|
|
51
|
-
throw new Error("Item with given id not found");
|
|
52
|
-
}
|
|
53
|
-
return html(
|
|
54
|
-
ctx,
|
|
55
|
-
"Delete?",
|
|
56
|
-
<div>
|
|
57
|
-
<div class="confirm-delete-page confirm-delete-page--${toKebabCase(
|
|
58
|
-
collection_name
|
|
59
|
-
)}">
|
|
60
|
-
<span>
|
|
61
|
-
Are you sure you want to remove: {" "}
|
|
62
|
-
<b>{this.getItemTitle(ctx, item)}</b>
|
|
63
|
-
</span>
|
|
64
|
-
<form action={${delete_action_name}URL(item.id)}>
|
|
65
|
-
<button type="submit">
|
|
66
|
-
remove
|
|
67
|
-
</button>
|
|
68
|
-
<input type="hidden" name="id" value={item?.id} />
|
|
69
|
-
</form>
|
|
70
|
-
</div>
|
|
71
|
-
</div>
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
})();
|
|
75
|
-
`;
|
|
76
|
-
|
|
77
|
-
return await formatWithPrettier(result);
|
|
78
|
-
}
|