@ai0x0/utils 0.0.37 → 0.0.38
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/README.md +42 -1
- package/es/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-delete-action.js +54 -0
- package/es/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-get-action.js +64 -0
- package/es/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/es/backend/sqlite/actions/create-get-list-action.js +56 -0
- package/es/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/es/backend/sqlite/actions/create-post-action.js +31 -0
- package/es/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/es/backend/sqlite/actions/create-put-action.js +74 -0
- package/es/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/es/backend/sqlite/actions/get-list-data.js +75 -0
- package/es/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/es/backend/sqlite/actions/get-list-query.js +215 -0
- package/es/backend/sqlite/actions/index.d.ts +6 -0
- package/es/backend/sqlite/actions/index.js +6 -0
- package/es/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/es/backend/sqlite/actions/transform-body.js +9 -0
- package/es/backend/sqlite/errors.d.ts +4 -0
- package/es/backend/sqlite/errors.js +31 -0
- package/es/backend/sqlite/index.d.ts +5 -0
- package/es/backend/sqlite/index.js +5 -0
- package/es/backend/sqlite/route-operation/delete-operation.d.ts +10 -0
- package/es/backend/sqlite/route-operation/delete-operation.js +112 -0
- package/es/backend/sqlite/route-operation/get-list-operation.d.ts +22 -0
- package/es/backend/sqlite/route-operation/get-list-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-operation.d.ts +16 -0
- package/es/backend/sqlite/route-operation/get-operation.js +122 -0
- package/es/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/es/backend/sqlite/route-operation/get-table-name.js +11 -0
- package/es/backend/sqlite/route-operation/index.d.ts +5 -0
- package/es/backend/sqlite/route-operation/index.js +5 -0
- package/es/backend/sqlite/route-operation/post-operation.d.ts +13 -0
- package/es/backend/sqlite/route-operation/post-operation.js +137 -0
- package/es/backend/sqlite/route-operation/put-operation.d.ts +14 -0
- package/es/backend/sqlite/route-operation/put-operation.js +144 -0
- package/es/backend/sqlite/schemas/index.d.ts +68 -0
- package/es/backend/sqlite/schemas/index.js +133 -0
- package/es/backend/sqlite/types.d.ts +16 -0
- package/es/backend/sqlite/types.js +1 -0
- package/lib/backend/sqlite/actions/create-delete-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-delete-action.js +53 -0
- package/lib/backend/sqlite/actions/create-get-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-get-action.js +65 -0
- package/lib/backend/sqlite/actions/create-get-list-action.d.ts +11 -0
- package/lib/backend/sqlite/actions/create-get-list-action.js +63 -0
- package/lib/backend/sqlite/actions/create-post-action.d.ts +6 -0
- package/lib/backend/sqlite/actions/create-post-action.js +39 -0
- package/lib/backend/sqlite/actions/create-put-action.d.ts +8 -0
- package/lib/backend/sqlite/actions/create-put-action.js +60 -0
- package/lib/backend/sqlite/actions/get-list-data.d.ts +9 -0
- package/lib/backend/sqlite/actions/get-list-data.js +51 -0
- package/lib/backend/sqlite/actions/get-list-query.d.ts +19 -0
- package/lib/backend/sqlite/actions/get-list-query.js +165 -0
- package/lib/backend/sqlite/actions/index.d.ts +6 -0
- package/lib/backend/sqlite/actions/index.js +44 -0
- package/lib/backend/sqlite/actions/transform-body.d.ts +1 -0
- package/lib/backend/sqlite/actions/transform-body.js +49 -0
- package/lib/backend/sqlite/errors.d.ts +4 -0
- package/lib/backend/sqlite/errors.js +35 -0
- package/lib/backend/sqlite/index.d.ts +5 -0
- package/lib/backend/sqlite/index.js +31 -0
- package/lib/backend/sqlite/route-operation/delete-operation.d.ts +10 -0
- package/lib/backend/sqlite/route-operation/delete-operation.js +91 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.d.ts +22 -0
- package/lib/backend/sqlite/route-operation/get-list-operation.js +108 -0
- package/lib/backend/sqlite/route-operation/get-operation.d.ts +16 -0
- package/lib/backend/sqlite/route-operation/get-operation.js +107 -0
- package/lib/backend/sqlite/route-operation/get-table-name.d.ts +3 -0
- package/lib/backend/sqlite/route-operation/get-table-name.js +35 -0
- package/lib/backend/sqlite/route-operation/index.d.ts +5 -0
- package/lib/backend/sqlite/route-operation/index.js +31 -0
- package/lib/backend/sqlite/route-operation/post-operation.d.ts +13 -0
- package/lib/backend/sqlite/route-operation/post-operation.js +94 -0
- package/lib/backend/sqlite/route-operation/put-operation.d.ts +14 -0
- package/lib/backend/sqlite/route-operation/put-operation.js +103 -0
- package/lib/backend/sqlite/schemas/index.d.ts +68 -0
- package/lib/backend/sqlite/schemas/index.js +113 -0
- package/lib/backend/sqlite/types.d.ts +16 -0
- package/lib/backend/sqlite/types.js +17 -0
- package/package.json +3 -1
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc2) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/sqlite/actions/get-list-query.ts
|
|
20
|
+
var get_list_query_exports = {};
|
|
21
|
+
__export(get_list_query_exports, {
|
|
22
|
+
getListQuery: () => getListQuery
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(get_list_query_exports);
|
|
25
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
26
|
+
function getListQuery({
|
|
27
|
+
db,
|
|
28
|
+
fields,
|
|
29
|
+
jsonArrayFields,
|
|
30
|
+
params,
|
|
31
|
+
relations,
|
|
32
|
+
table
|
|
33
|
+
}) {
|
|
34
|
+
const {
|
|
35
|
+
page = 1,
|
|
36
|
+
pageSize = 10,
|
|
37
|
+
orderBy = "createdAt",
|
|
38
|
+
orderDir = "desc",
|
|
39
|
+
...filters
|
|
40
|
+
} = params;
|
|
41
|
+
function buildBaseQuery(table2, fields2, relations2) {
|
|
42
|
+
let queryFields = { ...fields2 };
|
|
43
|
+
if (relations2 == null ? void 0 : relations2.length) {
|
|
44
|
+
for (const { select } of relations2) {
|
|
45
|
+
queryFields = { ...queryFields, ...select };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const query2 = db.select(queryFields).from(table2);
|
|
49
|
+
if (relations2 == null ? void 0 : relations2.length) {
|
|
50
|
+
query2.groupBy(
|
|
51
|
+
table2.id,
|
|
52
|
+
...relations2.filter(({ groupBy }) => groupBy).filter(({ table: table3 }) => table3).map(({ table: table3 }) => table3.id)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return query2;
|
|
56
|
+
}
|
|
57
|
+
function findTargetColumn(key, table2, relations2) {
|
|
58
|
+
var _a;
|
|
59
|
+
return (_a = [table2].concat(
|
|
60
|
+
(relations2 == null ? void 0 : relations2.filter(({ table: table3 }) => table3).map(({ table: table3 }) => table3)) || []
|
|
61
|
+
).find((table3) => table3[key])) == null ? void 0 : _a[key];
|
|
62
|
+
}
|
|
63
|
+
function addCondition(conditions2, key, value, targetColumn) {
|
|
64
|
+
const isIdField = /id/i.test(key);
|
|
65
|
+
const isJsonArray = jsonArrayFields == null ? void 0 : jsonArrayFields.includes(key);
|
|
66
|
+
if (typeof value === "string") {
|
|
67
|
+
if (value.includes(",")) {
|
|
68
|
+
const values = value.split(",").map((val) => val.trim()).filter(Boolean);
|
|
69
|
+
if (values.length > 0) {
|
|
70
|
+
if (isJsonArray) {
|
|
71
|
+
conditions2.push(
|
|
72
|
+
import_drizzle_orm.sql`
|
|
73
|
+
EXISTS (
|
|
74
|
+
SELECT 1 FROM json_each(${targetColumn}) tag
|
|
75
|
+
WHERE tag.value LIKE ${`%${values[0]}%`}
|
|
76
|
+
)
|
|
77
|
+
`
|
|
78
|
+
);
|
|
79
|
+
} else if (isIdField) {
|
|
80
|
+
conditions2.push((0, import_drizzle_orm.inArray)(targetColumn, values));
|
|
81
|
+
} else {
|
|
82
|
+
conditions2.push(
|
|
83
|
+
(0, import_drizzle_orm.or)(
|
|
84
|
+
...values.map((val) => (0, import_drizzle_orm.like)(targetColumn, `%${val}%`))
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
if (isJsonArray) {
|
|
91
|
+
conditions2.push(
|
|
92
|
+
import_drizzle_orm.sql`
|
|
93
|
+
EXISTS (
|
|
94
|
+
SELECT 1 FROM json_each(${targetColumn}) tag
|
|
95
|
+
WHERE tag.value LIKE ${`%${value}%`}
|
|
96
|
+
)
|
|
97
|
+
`
|
|
98
|
+
);
|
|
99
|
+
} else if (isIdField) {
|
|
100
|
+
conditions2.push((0, import_drizzle_orm.eq)(targetColumn, value));
|
|
101
|
+
} else {
|
|
102
|
+
conditions2.push((0, import_drizzle_orm.like)(targetColumn, `%${value}%`));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
conditions2.push((0, import_drizzle_orm.eq)(targetColumn, value));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
function buildConditions(filters2, table2, relations2) {
|
|
110
|
+
const conditions2 = [];
|
|
111
|
+
for (const [key, value] of Object.entries(filters2)) {
|
|
112
|
+
if (!value) {
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
if (key.endsWith("AtFrom") || key.endsWith("AtTo")) {
|
|
116
|
+
const baseFieldName = key.replace(/(AtFrom|AtTo)$/, "");
|
|
117
|
+
const targetColumn2 = findTargetColumn(
|
|
118
|
+
`${baseFieldName}At`,
|
|
119
|
+
table2,
|
|
120
|
+
relations2
|
|
121
|
+
);
|
|
122
|
+
if (!targetColumn2) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
if (key.endsWith("AtFrom")) {
|
|
126
|
+
conditions2.push((0, import_drizzle_orm.gte)(targetColumn2, new Date(value)));
|
|
127
|
+
} else if (key.endsWith("AtTo")) {
|
|
128
|
+
conditions2.push((0, import_drizzle_orm.lte)(targetColumn2, new Date(value)));
|
|
129
|
+
}
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
const targetColumn = findTargetColumn(
|
|
133
|
+
key,
|
|
134
|
+
table2,
|
|
135
|
+
relations2
|
|
136
|
+
);
|
|
137
|
+
if (!targetColumn) {
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
addCondition(conditions2, key, value, targetColumn);
|
|
141
|
+
}
|
|
142
|
+
return conditions2;
|
|
143
|
+
}
|
|
144
|
+
function buildOrderBy(table2, orderBy2, orderDir2) {
|
|
145
|
+
const orderColumn = table2[orderBy2];
|
|
146
|
+
return orderDir2 === "asc" ? (0, import_drizzle_orm.asc)(orderColumn) : (0, import_drizzle_orm.desc)(orderColumn);
|
|
147
|
+
}
|
|
148
|
+
const baseQuery = buildBaseQuery(table, fields, relations);
|
|
149
|
+
const conditions = buildConditions(filters, table, relations);
|
|
150
|
+
const query = baseQuery.where(conditions.length > 0 ? (0, import_drizzle_orm.and)(...conditions) : void 0).orderBy(buildOrderBy(table, orderBy, orderDir)).limit(pageSize).offset((page - 1) * pageSize);
|
|
151
|
+
const countQuery = db.select({ count: import_drizzle_orm.sql`COUNT(DISTINCT ${table.id})` }).from(table).where(conditions.length > 0 ? (0, import_drizzle_orm.and)(...conditions) : void 0);
|
|
152
|
+
if (relations == null ? void 0 : relations.length) {
|
|
153
|
+
for (const { table: relationTable, sql: joinSql } of relations) {
|
|
154
|
+
if (relationTable) {
|
|
155
|
+
query.leftJoin(relationTable, joinSql);
|
|
156
|
+
countQuery.leftJoin(relationTable, joinSql);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return { countQuery, query };
|
|
161
|
+
}
|
|
162
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
163
|
+
0 && (module.exports = {
|
|
164
|
+
getListQuery
|
|
165
|
+
});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createDeleteAction } from "./create-delete-action.js";
|
|
2
|
+
export { createGetAction } from "./create-get-action.js";
|
|
3
|
+
export { createGetListAction } from "./create-get-list-action.js";
|
|
4
|
+
export { createPostAction } from "./create-post-action.js";
|
|
5
|
+
export { createPutAction } from "./create-put-action.js";
|
|
6
|
+
export { getListQuery } from "./get-list-query.js";
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/sqlite/actions/index.ts
|
|
20
|
+
var actions_exports = {};
|
|
21
|
+
__export(actions_exports, {
|
|
22
|
+
createDeleteAction: () => import_create_delete_action.createDeleteAction,
|
|
23
|
+
createGetAction: () => import_create_get_action.createGetAction,
|
|
24
|
+
createGetListAction: () => import_create_get_list_action.createGetListAction,
|
|
25
|
+
createPostAction: () => import_create_post_action.createPostAction,
|
|
26
|
+
createPutAction: () => import_create_put_action.createPutAction,
|
|
27
|
+
getListQuery: () => import_get_list_query.getListQuery
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(actions_exports);
|
|
30
|
+
var import_create_delete_action = require("./create-delete-action");
|
|
31
|
+
var import_create_get_action = require("./create-get-action");
|
|
32
|
+
var import_create_get_list_action = require("./create-get-list-action");
|
|
33
|
+
var import_create_post_action = require("./create-post-action");
|
|
34
|
+
var import_create_put_action = require("./create-put-action");
|
|
35
|
+
var import_get_list_query = require("./get-list-query");
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
createDeleteAction,
|
|
39
|
+
createGetAction,
|
|
40
|
+
createGetListAction,
|
|
41
|
+
createPostAction,
|
|
42
|
+
createPutAction,
|
|
43
|
+
getListQuery
|
|
44
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const transformBody: <T extends Record<string, unknown>>(body: T) => T;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/backend/sqlite/actions/transform-body.ts
|
|
30
|
+
var transform_body_exports = {};
|
|
31
|
+
__export(transform_body_exports, {
|
|
32
|
+
transformBody: () => transformBody
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(transform_body_exports);
|
|
35
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
36
|
+
var transformBody = (body) => {
|
|
37
|
+
for (const key in body) {
|
|
38
|
+
if (key.endsWith("At")) {
|
|
39
|
+
body[key] = (0, import_dayjs.default)(
|
|
40
|
+
body[key]
|
|
41
|
+
).toDate();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return body;
|
|
45
|
+
};
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
transformBody
|
|
49
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/backend/sqlite/errors.ts
|
|
20
|
+
var errors_exports = {};
|
|
21
|
+
__export(errors_exports, {
|
|
22
|
+
HttpError: () => HttpError
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(errors_exports);
|
|
25
|
+
var HttpError = class extends Error {
|
|
26
|
+
constructor(status, message) {
|
|
27
|
+
super(message);
|
|
28
|
+
this.name = "HttpError";
|
|
29
|
+
this.status = status;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
HttpError
|
|
35
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/backend/sqlite/index.ts
|
|
17
|
+
var sqlite_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(sqlite_exports);
|
|
19
|
+
__reExport(sqlite_exports, require("./actions"), module.exports);
|
|
20
|
+
__reExport(sqlite_exports, require("./route-operation"), module.exports);
|
|
21
|
+
__reExport(sqlite_exports, require("./schemas"), module.exports);
|
|
22
|
+
__reExport(sqlite_exports, require("./errors"), module.exports);
|
|
23
|
+
__reExport(sqlite_exports, require("./types"), module.exports);
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
...require("./actions"),
|
|
27
|
+
...require("./route-operation"),
|
|
28
|
+
...require("./schemas"),
|
|
29
|
+
...require("./errors"),
|
|
30
|
+
...require("./types")
|
|
31
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TypedNextResponse } from "next-rest-framework";
|
|
2
|
+
import { BaseTable } from "../types.js";
|
|
3
|
+
export interface DeleteOperationOptions<TTable extends BaseTable> {
|
|
4
|
+
table: TTable;
|
|
5
|
+
summary?: string;
|
|
6
|
+
onSuccess?: () => Promise<void>;
|
|
7
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
8
|
+
byCreator?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const createDeleteOperation: any;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/backend/sqlite/route-operation/delete-operation.ts
|
|
30
|
+
var delete_operation_exports = {};
|
|
31
|
+
__export(delete_operation_exports, {
|
|
32
|
+
createDeleteOperation: () => createDeleteOperation
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(delete_operation_exports);
|
|
35
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
36
|
+
var import_zod = require("zod");
|
|
37
|
+
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
|
+
var import_actions = require("../actions");
|
|
39
|
+
var import_errors = require("../errors");
|
|
40
|
+
var createDeleteOperation = ({
|
|
41
|
+
db,
|
|
42
|
+
getSession
|
|
43
|
+
}) => ({
|
|
44
|
+
table,
|
|
45
|
+
summary,
|
|
46
|
+
onSuccess,
|
|
47
|
+
onError,
|
|
48
|
+
byCreator = true
|
|
49
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
50
|
+
method: "DELETE",
|
|
51
|
+
openApiOperation: {
|
|
52
|
+
summary,
|
|
53
|
+
tags: [(0, import_get_table_name.default)(table)]
|
|
54
|
+
}
|
|
55
|
+
}).input({
|
|
56
|
+
body: import_zod.z.object({
|
|
57
|
+
id: import_zod.z.string()
|
|
58
|
+
}),
|
|
59
|
+
contentType: "application/json"
|
|
60
|
+
}).handler(async (req) => {
|
|
61
|
+
try {
|
|
62
|
+
const body = await req.json();
|
|
63
|
+
if (byCreator) {
|
|
64
|
+
const { userId } = await getSession(req) || {};
|
|
65
|
+
body.creatorId = userId;
|
|
66
|
+
}
|
|
67
|
+
const data = await (0, import_actions.createDeleteAction)({ table, db })(body);
|
|
68
|
+
await (onSuccess == null ? void 0 : onSuccess());
|
|
69
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
70
|
+
status: 200
|
|
71
|
+
});
|
|
72
|
+
} catch (e) {
|
|
73
|
+
if (!(e instanceof import_errors.HttpError)) {
|
|
74
|
+
console.error(e);
|
|
75
|
+
}
|
|
76
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
77
|
+
if (response) {
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
80
|
+
if (e instanceof import_errors.HttpError) {
|
|
81
|
+
return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
|
|
82
|
+
status: e.status
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
throw e;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
createDeleteOperation
|
|
91
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
|
+
import { BaseTable, GetListRelations } from "../types.js";
|
|
4
|
+
export interface GetListOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
jsonArrayFields?: string[];
|
|
7
|
+
querySchema: Q;
|
|
8
|
+
relations?: GetListRelations;
|
|
9
|
+
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
10
|
+
byCreator?: boolean;
|
|
11
|
+
summary?: string;
|
|
12
|
+
table: TTable;
|
|
13
|
+
onSuccess?: <D extends T>(_data: {
|
|
14
|
+
data: z.infer<D>[];
|
|
15
|
+
total: number;
|
|
16
|
+
}) => Promise<{
|
|
17
|
+
data: z.infer<T>[];
|
|
18
|
+
total: number;
|
|
19
|
+
}>;
|
|
20
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
21
|
+
}
|
|
22
|
+
export declare const createGetListOperation: any;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/backend/sqlite/route-operation/get-list-operation.ts
|
|
30
|
+
var get_list_operation_exports = {};
|
|
31
|
+
__export(get_list_operation_exports, {
|
|
32
|
+
createGetListOperation: () => createGetListOperation
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(get_list_operation_exports);
|
|
35
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
36
|
+
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
37
|
+
var import_schemas = require("../schemas");
|
|
38
|
+
var import_actions = require("../actions");
|
|
39
|
+
var createGetListOperation = ({
|
|
40
|
+
db,
|
|
41
|
+
getSession
|
|
42
|
+
}) => ({
|
|
43
|
+
querySchema,
|
|
44
|
+
bodySchema,
|
|
45
|
+
table,
|
|
46
|
+
summary,
|
|
47
|
+
relations,
|
|
48
|
+
jsonArrayFields,
|
|
49
|
+
setParams,
|
|
50
|
+
onSuccess,
|
|
51
|
+
onError,
|
|
52
|
+
byCreator = true
|
|
53
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
54
|
+
method: "GET",
|
|
55
|
+
openApiOperation: {
|
|
56
|
+
summary,
|
|
57
|
+
tags: [(0, import_get_table_name.default)(table)]
|
|
58
|
+
}
|
|
59
|
+
}).input({
|
|
60
|
+
query: querySchema
|
|
61
|
+
}).outputs([
|
|
62
|
+
{
|
|
63
|
+
body: (0, import_schemas.listBodySchema)(bodySchema),
|
|
64
|
+
contentType: "application/json",
|
|
65
|
+
status: 200
|
|
66
|
+
}
|
|
67
|
+
]).handler(async (req) => {
|
|
68
|
+
try {
|
|
69
|
+
const params = await (setParams == null ? void 0 : setParams(
|
|
70
|
+
req
|
|
71
|
+
)) || {};
|
|
72
|
+
if (byCreator) {
|
|
73
|
+
const { userId } = await getSession(req) || {};
|
|
74
|
+
params.creatorId = userId;
|
|
75
|
+
}
|
|
76
|
+
let result = await (0, import_actions.createGetListAction)({
|
|
77
|
+
bodySchema,
|
|
78
|
+
db,
|
|
79
|
+
jsonArrayFields,
|
|
80
|
+
relations,
|
|
81
|
+
table
|
|
82
|
+
})(
|
|
83
|
+
Object.assign(
|
|
84
|
+
Object.fromEntries(new URL(req.url).searchParams),
|
|
85
|
+
params
|
|
86
|
+
)
|
|
87
|
+
);
|
|
88
|
+
if (onSuccess) {
|
|
89
|
+
result = await onSuccess(result);
|
|
90
|
+
}
|
|
91
|
+
return import_next_rest_framework.TypedNextResponse.json(
|
|
92
|
+
result,
|
|
93
|
+
{ status: 200 }
|
|
94
|
+
);
|
|
95
|
+
} catch (e) {
|
|
96
|
+
console.error(e);
|
|
97
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
98
|
+
if (response) {
|
|
99
|
+
return response;
|
|
100
|
+
} else {
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
createGetListOperation
|
|
108
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
3
|
+
import { BaseTable, GetListRelations } from "../types.js";
|
|
4
|
+
export interface GetOperationOptions<T extends ZodSchema, Q extends ZodSchema, TTable extends BaseTable> {
|
|
5
|
+
bodySchema: T;
|
|
6
|
+
jsonArrayFields?: string[];
|
|
7
|
+
querySchema: Q;
|
|
8
|
+
relations?: GetListRelations;
|
|
9
|
+
setParams?: (_req: TypedNextRequest<"GET", "application/json", unknown, z.infer<Q>>) => Promise<Record<string, unknown>>;
|
|
10
|
+
onSuccess?: (_data: z.infer<T>) => Promise<z.infer<T>>;
|
|
11
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
12
|
+
summary?: string;
|
|
13
|
+
table: TTable;
|
|
14
|
+
byCreator?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const createGetOperation: any;
|