@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,107 @@
|
|
|
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-operation.ts
|
|
30
|
+
var get_operation_exports = {};
|
|
31
|
+
__export(get_operation_exports, {
|
|
32
|
+
createGetOperation: () => createGetOperation
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(get_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_actions = require("../actions");
|
|
38
|
+
var createGetOperation = ({
|
|
39
|
+
getSession,
|
|
40
|
+
db
|
|
41
|
+
}) => ({
|
|
42
|
+
querySchema,
|
|
43
|
+
bodySchema,
|
|
44
|
+
table,
|
|
45
|
+
summary,
|
|
46
|
+
relations,
|
|
47
|
+
setParams,
|
|
48
|
+
jsonArrayFields,
|
|
49
|
+
onSuccess,
|
|
50
|
+
onError,
|
|
51
|
+
byCreator = true
|
|
52
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
53
|
+
method: "GET",
|
|
54
|
+
openApiOperation: {
|
|
55
|
+
summary,
|
|
56
|
+
tags: [(0, import_get_table_name.default)(table)]
|
|
57
|
+
}
|
|
58
|
+
}).input({
|
|
59
|
+
query: querySchema
|
|
60
|
+
}).outputs([
|
|
61
|
+
{
|
|
62
|
+
body: bodySchema,
|
|
63
|
+
contentType: "application/json",
|
|
64
|
+
status: 200
|
|
65
|
+
}
|
|
66
|
+
]).handler(async (req) => {
|
|
67
|
+
try {
|
|
68
|
+
const params = await (setParams == null ? void 0 : setParams(
|
|
69
|
+
req
|
|
70
|
+
)) || {};
|
|
71
|
+
if (byCreator) {
|
|
72
|
+
const { userId } = await getSession(req) || {};
|
|
73
|
+
params.creatorId = userId;
|
|
74
|
+
}
|
|
75
|
+
const rawResult = await (0, import_actions.createGetAction)({
|
|
76
|
+
bodySchema,
|
|
77
|
+
db,
|
|
78
|
+
jsonArrayFields,
|
|
79
|
+
relations,
|
|
80
|
+
table
|
|
81
|
+
})(
|
|
82
|
+
Object.assign(
|
|
83
|
+
Object.fromEntries(new URL(req.url).searchParams),
|
|
84
|
+
params
|
|
85
|
+
)
|
|
86
|
+
);
|
|
87
|
+
let result = rawResult ?? {};
|
|
88
|
+
if (onSuccess) {
|
|
89
|
+
result = await onSuccess(result);
|
|
90
|
+
}
|
|
91
|
+
return import_next_rest_framework.TypedNextResponse.json(result, {
|
|
92
|
+
status: 200
|
|
93
|
+
});
|
|
94
|
+
} catch (e) {
|
|
95
|
+
console.error(e);
|
|
96
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
97
|
+
if (response) {
|
|
98
|
+
return response;
|
|
99
|
+
} else {
|
|
100
|
+
throw e;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
105
|
+
0 && (module.exports = {
|
|
106
|
+
createGetOperation
|
|
107
|
+
});
|
|
@@ -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/route-operation/get-table-name.ts
|
|
20
|
+
var get_table_name_exports = {};
|
|
21
|
+
__export(get_table_name_exports, {
|
|
22
|
+
default: () => get_table_name_default
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(get_table_name_exports);
|
|
25
|
+
function getTableName(table) {
|
|
26
|
+
const symbols = Object.getOwnPropertySymbols(table);
|
|
27
|
+
const nameSymbol = symbols.find(
|
|
28
|
+
(sym) => sym.toString() === "Symbol(drizzle:Name)"
|
|
29
|
+
);
|
|
30
|
+
if (nameSymbol) {
|
|
31
|
+
return table[nameSymbol];
|
|
32
|
+
}
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
var get_table_name_default = getTableName;
|
|
@@ -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/route-operation/index.ts
|
|
17
|
+
var route_operation_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(route_operation_exports);
|
|
19
|
+
__reExport(route_operation_exports, require("./get-operation"), module.exports);
|
|
20
|
+
__reExport(route_operation_exports, require("./get-list-operation"), module.exports);
|
|
21
|
+
__reExport(route_operation_exports, require("./delete-operation"), module.exports);
|
|
22
|
+
__reExport(route_operation_exports, require("./post-operation"), module.exports);
|
|
23
|
+
__reExport(route_operation_exports, require("./put-operation"), module.exports);
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
...require("./get-operation"),
|
|
27
|
+
...require("./get-list-operation"),
|
|
28
|
+
...require("./delete-operation"),
|
|
29
|
+
...require("./post-operation"),
|
|
30
|
+
...require("./put-operation")
|
|
31
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
+
export interface PostOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
5
|
+
bodySchema: IB;
|
|
6
|
+
outputBodySchema?: IB;
|
|
7
|
+
setBody?: (_req: TypedNextRequest<"POST", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
8
|
+
summary?: string;
|
|
9
|
+
onSuccess?: (_data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
10
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
11
|
+
table: TTable;
|
|
12
|
+
}
|
|
13
|
+
export declare const createPostOperation: any;
|
|
@@ -0,0 +1,94 @@
|
|
|
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/post-operation.ts
|
|
30
|
+
var post_operation_exports = {};
|
|
31
|
+
__export(post_operation_exports, {
|
|
32
|
+
createPostOperation: () => createPostOperation
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(post_operation_exports);
|
|
35
|
+
var import_zod = require("zod");
|
|
36
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
37
|
+
var import_get_table_name = __toESM(require("./get-table-name"));
|
|
38
|
+
var import_actions = require("../actions");
|
|
39
|
+
var createPostOperation = ({
|
|
40
|
+
getSession,
|
|
41
|
+
db
|
|
42
|
+
}) => ({
|
|
43
|
+
bodySchema,
|
|
44
|
+
outputBodySchema,
|
|
45
|
+
setBody,
|
|
46
|
+
summary,
|
|
47
|
+
table,
|
|
48
|
+
onSuccess,
|
|
49
|
+
onError
|
|
50
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
51
|
+
method: "POST",
|
|
52
|
+
openApiOperation: {
|
|
53
|
+
summary,
|
|
54
|
+
tags: [(0, import_get_table_name.default)(table)]
|
|
55
|
+
}
|
|
56
|
+
}).input({
|
|
57
|
+
body: bodySchema,
|
|
58
|
+
contentType: "application/json"
|
|
59
|
+
}).outputs([
|
|
60
|
+
{
|
|
61
|
+
body: outputBodySchema || import_zod.z.object({ id: import_zod.z.string() }),
|
|
62
|
+
contentType: "application/json",
|
|
63
|
+
status: 200
|
|
64
|
+
}
|
|
65
|
+
]).handler(async (req) => {
|
|
66
|
+
try {
|
|
67
|
+
const { userId } = await getSession(req) || {};
|
|
68
|
+
const body = await req.json();
|
|
69
|
+
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
70
|
+
req
|
|
71
|
+
)) || {};
|
|
72
|
+
const mergedBody = { ...body, ...extraBody };
|
|
73
|
+
const [raw] = await (0, import_actions.createPostAction)({ bodySchema, db, table })({
|
|
74
|
+
creatorId: userId,
|
|
75
|
+
...mergedBody
|
|
76
|
+
});
|
|
77
|
+
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
78
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
79
|
+
status: 200
|
|
80
|
+
});
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error(e);
|
|
83
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
84
|
+
if (response) {
|
|
85
|
+
return response;
|
|
86
|
+
} else {
|
|
87
|
+
throw e;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
createPostOperation
|
|
94
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { z, ZodSchema } from "zod";
|
|
2
|
+
import { SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import { TypedNextRequest, TypedNextResponse } from "next-rest-framework";
|
|
4
|
+
export interface PutOperationOptions<IB extends ZodSchema, OB extends ZodSchema, TTable extends SQLiteTable> {
|
|
5
|
+
bodySchema: IB;
|
|
6
|
+
outputBodySchema?: OB;
|
|
7
|
+
table: TTable;
|
|
8
|
+
summary?: string;
|
|
9
|
+
setBody?: (_req: TypedNextRequest<"PUT", "application/json", z.infer<IB>>) => Promise<Partial<z.infer<IB>>>;
|
|
10
|
+
onSuccess?: (_data: z.infer<OB>) => Promise<z.infer<OB>>;
|
|
11
|
+
onError?: (_error: Error) => Promise<ReturnType<(typeof TypedNextResponse)["json"]> | undefined>;
|
|
12
|
+
byCreator?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare const createPutOperation: any;
|
|
@@ -0,0 +1,103 @@
|
|
|
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/put-operation.ts
|
|
30
|
+
var put_operation_exports = {};
|
|
31
|
+
__export(put_operation_exports, {
|
|
32
|
+
createPutOperation: () => createPutOperation
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(put_operation_exports);
|
|
35
|
+
var import_zod = require("zod");
|
|
36
|
+
var import_next_rest_framework = require("next-rest-framework");
|
|
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 createPutOperation = ({
|
|
41
|
+
getSession,
|
|
42
|
+
db
|
|
43
|
+
}) => ({
|
|
44
|
+
bodySchema,
|
|
45
|
+
outputBodySchema,
|
|
46
|
+
table,
|
|
47
|
+
summary,
|
|
48
|
+
setBody,
|
|
49
|
+
onSuccess,
|
|
50
|
+
byCreator = true,
|
|
51
|
+
onError
|
|
52
|
+
}) => (0, import_next_rest_framework.routeOperation)({
|
|
53
|
+
method: "PUT",
|
|
54
|
+
openApiOperation: {
|
|
55
|
+
summary,
|
|
56
|
+
tags: [(0, import_get_table_name.default)(table)]
|
|
57
|
+
}
|
|
58
|
+
}).input({
|
|
59
|
+
body: bodySchema,
|
|
60
|
+
contentType: "application/json"
|
|
61
|
+
}).outputs([
|
|
62
|
+
{
|
|
63
|
+
body: outputBodySchema || import_zod.z.void(),
|
|
64
|
+
status: 200,
|
|
65
|
+
contentType: "application/json"
|
|
66
|
+
}
|
|
67
|
+
]).handler(async (req) => {
|
|
68
|
+
try {
|
|
69
|
+
const { userId } = await getSession(req) || {};
|
|
70
|
+
const body = await req.json();
|
|
71
|
+
const extraBody = await (setBody == null ? void 0 : setBody(
|
|
72
|
+
req
|
|
73
|
+
)) || {};
|
|
74
|
+
const mergedBody = { ...body, ...extraBody };
|
|
75
|
+
const raw = await (0, import_actions.createPutAction)({
|
|
76
|
+
bodySchema,
|
|
77
|
+
table,
|
|
78
|
+
db
|
|
79
|
+
})({ editorId: userId, ...mergedBody }, { byCreator });
|
|
80
|
+
const data = onSuccess ? await onSuccess(raw) : raw;
|
|
81
|
+
return import_next_rest_framework.TypedNextResponse.json(data, {
|
|
82
|
+
status: 200
|
|
83
|
+
});
|
|
84
|
+
} catch (e) {
|
|
85
|
+
if (!(e instanceof import_errors.HttpError)) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
}
|
|
88
|
+
const response = await (onError == null ? void 0 : onError(e));
|
|
89
|
+
if (response) {
|
|
90
|
+
return response;
|
|
91
|
+
}
|
|
92
|
+
if (e instanceof import_errors.HttpError) {
|
|
93
|
+
return import_next_rest_framework.TypedNextResponse.json({ message: e.message }, {
|
|
94
|
+
status: e.status
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
throw e;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
createPutOperation
|
|
103
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type SQLiteColumnBuilderBase, type SQLiteTableExtraConfigValue } from "drizzle-orm/sqlite-core";
|
|
3
|
+
import type { BuildExtraConfigColumns } from "drizzle-orm";
|
|
4
|
+
export declare const basicFields: {
|
|
5
|
+
id: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").IsPrimaryKey<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"id", [string, ...string[]], number | undefined>>>>>;
|
|
6
|
+
creatorId: import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"creator_id", [string, ...string[]], number | undefined>;
|
|
7
|
+
editorId: import("drizzle-orm/sqlite-core").SQLiteTextBuilderInitial<"editor_id", [string, ...string[]], number | undefined>;
|
|
8
|
+
accessedAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
|
|
9
|
+
createdAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
|
|
10
|
+
updatedAt: import("drizzle-orm").HasRuntimeDefault<import("drizzle-orm").HasDefault<import("drizzle-orm").NotNull<import("drizzle-orm/sqlite-core").SQLiteTimestampBuilderInitial<string>>>>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 业务侧 insert schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
|
|
14
|
+
* 这些字段由后端在 createPostAction 中自动写入。
|
|
15
|
+
*
|
|
16
|
+
* 使用方式(在业务 schema 中):
|
|
17
|
+
* const insertFooSchema = createInsertSchema(foos)
|
|
18
|
+
* .omit(BASIC_INSERT_OMIT)
|
|
19
|
+
* .extend({ ... });
|
|
20
|
+
*
|
|
21
|
+
* 说明:上游导出为 const 而不是 helper function,是为了避免经过泛型
|
|
22
|
+
* wrapper 后 TS 把 drizzle-zod 推导出的深层条件 Shape 归约成 Omit,
|
|
23
|
+
* 从而在下游 `.extend(...)` 时丢失原有字段类型。
|
|
24
|
+
*/
|
|
25
|
+
export declare const BASIC_INSERT_OMIT: {
|
|
26
|
+
readonly id: true;
|
|
27
|
+
readonly creatorId: true;
|
|
28
|
+
readonly editorId: true;
|
|
29
|
+
readonly accessedAt: true;
|
|
30
|
+
readonly createdAt: true;
|
|
31
|
+
readonly updatedAt: true;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 业务侧 update schema 需要从 drizzle-zod 生成的 schema 中排除的基础字段。
|
|
35
|
+
* update 保留 id(随后用 `.required({ id: true })` 变成必填),其余由
|
|
36
|
+
* 后端 createPutAction 自动维护。
|
|
37
|
+
*/
|
|
38
|
+
export declare const BASIC_UPDATE_OMIT: {
|
|
39
|
+
readonly creatorId: true;
|
|
40
|
+
readonly editorId: true;
|
|
41
|
+
readonly accessedAt: true;
|
|
42
|
+
readonly createdAt: true;
|
|
43
|
+
readonly updatedAt: true;
|
|
44
|
+
};
|
|
45
|
+
export declare const queryListSchema: (schema: any) => z.ZodObject<{
|
|
46
|
+
[x: string]: any;
|
|
47
|
+
}, any>;
|
|
48
|
+
export declare const listBodySchema: (schema: any) => z.ZodObject<{
|
|
49
|
+
total: z.ZodNumber;
|
|
50
|
+
data: z.ZodArray<any>;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
/**
|
|
53
|
+
* 基于 drizzle + drizzle-zod 快速生成带基础字段(id / 创建时间等)的
|
|
54
|
+
* 表定义以及 select / insert / update / query / list zod schema。
|
|
55
|
+
*/
|
|
56
|
+
export declare const createTableSchema: <TTableName extends string, TColumnsMap extends Record<string, SQLiteColumnBuilderBase>>(_options: {
|
|
57
|
+
name: TTableName;
|
|
58
|
+
columns: TColumnsMap;
|
|
59
|
+
extraConfig?: (_self: BuildExtraConfigColumns<TTableName, typeof basicFields & TColumnsMap, "sqlite">) => SQLiteTableExtraConfigValue[];
|
|
60
|
+
}) => {
|
|
61
|
+
table: any;
|
|
62
|
+
selectSchema: any;
|
|
63
|
+
insertSchema: any;
|
|
64
|
+
updateSchema: any;
|
|
65
|
+
querySchema: any;
|
|
66
|
+
queryListSchema: any;
|
|
67
|
+
queryListSelectSchema: any;
|
|
68
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
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/schemas/index.ts
|
|
20
|
+
var schemas_exports = {};
|
|
21
|
+
__export(schemas_exports, {
|
|
22
|
+
BASIC_INSERT_OMIT: () => BASIC_INSERT_OMIT,
|
|
23
|
+
BASIC_UPDATE_OMIT: () => BASIC_UPDATE_OMIT,
|
|
24
|
+
basicFields: () => basicFields,
|
|
25
|
+
createTableSchema: () => createTableSchema,
|
|
26
|
+
listBodySchema: () => listBodySchema,
|
|
27
|
+
queryListSchema: () => queryListSchema
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(schemas_exports);
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var import_sqlite_core = require("drizzle-orm/sqlite-core");
|
|
32
|
+
var import_drizzle_zod = require("drizzle-zod");
|
|
33
|
+
var timestamp = (name) => (0, import_sqlite_core.integer)(name, { mode: "timestamp_ms" });
|
|
34
|
+
var now = () => /* @__PURE__ */ new Date();
|
|
35
|
+
var id = () => crypto.randomUUID();
|
|
36
|
+
var createdAt = () => timestamp("created_at").notNull().$defaultFn(now);
|
|
37
|
+
var updatedAt = () => timestamp("updated_at").notNull().$defaultFn(now);
|
|
38
|
+
var accessedAt = () => timestamp("accessed_at").notNull().$defaultFn(now);
|
|
39
|
+
var basicFields = {
|
|
40
|
+
id: (0, import_sqlite_core.text)("id").primaryKey().$defaultFn(id),
|
|
41
|
+
creatorId: (0, import_sqlite_core.text)("creator_id"),
|
|
42
|
+
editorId: (0, import_sqlite_core.text)("editor_id"),
|
|
43
|
+
accessedAt: accessedAt(),
|
|
44
|
+
createdAt: createdAt(),
|
|
45
|
+
updatedAt: updatedAt()
|
|
46
|
+
};
|
|
47
|
+
var BASIC_INSERT_OMIT = {
|
|
48
|
+
id: true,
|
|
49
|
+
creatorId: true,
|
|
50
|
+
editorId: true,
|
|
51
|
+
accessedAt: true,
|
|
52
|
+
createdAt: true,
|
|
53
|
+
updatedAt: true
|
|
54
|
+
};
|
|
55
|
+
var BASIC_UPDATE_OMIT = {
|
|
56
|
+
creatorId: true,
|
|
57
|
+
editorId: true,
|
|
58
|
+
accessedAt: true,
|
|
59
|
+
createdAt: true,
|
|
60
|
+
updatedAt: true
|
|
61
|
+
};
|
|
62
|
+
var queryListSchema = (schema) => import_zod.z.object({
|
|
63
|
+
current: import_zod.z.string().optional().default("1"),
|
|
64
|
+
// 默认页码为 1
|
|
65
|
+
pageSize: import_zod.z.string().optional().default("10"),
|
|
66
|
+
// 默认每页条数为 10
|
|
67
|
+
createdAtFrom: import_zod.z.string().optional(),
|
|
68
|
+
// 筛选开始日期
|
|
69
|
+
createdAtTo: import_zod.z.string().optional(),
|
|
70
|
+
// 筛选结束日期
|
|
71
|
+
orderBy: import_zod.z.string().optional(),
|
|
72
|
+
creatorId: import_zod.z.string().optional(),
|
|
73
|
+
orderDir: import_zod.z.enum(["asc", "desc"]).optional()
|
|
74
|
+
}).merge(schema);
|
|
75
|
+
var listBodySchema = (schema) => import_zod.z.object({
|
|
76
|
+
total: import_zod.z.number(),
|
|
77
|
+
data: import_zod.z.array(schema)
|
|
78
|
+
});
|
|
79
|
+
var createTableSchema = ({ name, columns, extraConfig }) => {
|
|
80
|
+
const mergedColumns = { ...basicFields, ...columns };
|
|
81
|
+
const table = (0, import_sqlite_core.sqliteTable)(
|
|
82
|
+
name,
|
|
83
|
+
mergedColumns,
|
|
84
|
+
extraConfig
|
|
85
|
+
);
|
|
86
|
+
const selectSchema = (0, import_drizzle_zod.createSelectSchema)(table);
|
|
87
|
+
const insertSchema = (0, import_drizzle_zod.createInsertSchema)((0, import_sqlite_core.sqliteTable)(name, columns));
|
|
88
|
+
const updateSchema = (0, import_drizzle_zod.createUpdateSchema)(
|
|
89
|
+
(0, import_sqlite_core.sqliteTable)(name, { id: (0, import_sqlite_core.text)("id"), ...columns })
|
|
90
|
+
).extend({ id: import_zod.z.string() });
|
|
91
|
+
const querySchema = import_zod.z.object({ id: import_zod.z.string() });
|
|
92
|
+
const queryListWithSchema = queryListSchema(
|
|
93
|
+
import_zod.z.object({}).catchall(import_zod.z.unknown())
|
|
94
|
+
);
|
|
95
|
+
return {
|
|
96
|
+
table,
|
|
97
|
+
selectSchema,
|
|
98
|
+
insertSchema,
|
|
99
|
+
updateSchema,
|
|
100
|
+
querySchema,
|
|
101
|
+
queryListSchema: queryListWithSchema,
|
|
102
|
+
queryListSelectSchema: selectSchema
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
106
|
+
0 && (module.exports = {
|
|
107
|
+
BASIC_INSERT_OMIT,
|
|
108
|
+
BASIC_UPDATE_OMIT,
|
|
109
|
+
basicFields,
|
|
110
|
+
createTableSchema,
|
|
111
|
+
listBodySchema,
|
|
112
|
+
queryListSchema
|
|
113
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AnySQLiteColumn, SQLiteTable } from "drizzle-orm/sqlite-core";
|
|
2
|
+
import { SQL } from "drizzle-orm";
|
|
3
|
+
export interface BaseTable extends SQLiteTable {
|
|
4
|
+
id: AnySQLiteColumn;
|
|
5
|
+
creatorId: AnySQLiteColumn;
|
|
6
|
+
editorId: AnySQLiteColumn;
|
|
7
|
+
accessedAt: AnySQLiteColumn;
|
|
8
|
+
createdAt: AnySQLiteColumn;
|
|
9
|
+
updatedAt: AnySQLiteColumn;
|
|
10
|
+
}
|
|
11
|
+
export type GetListRelations = {
|
|
12
|
+
groupBy?: boolean;
|
|
13
|
+
select?: Record<string, unknown>;
|
|
14
|
+
sql?: SQL;
|
|
15
|
+
table?: BaseTable;
|
|
16
|
+
}[];
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/backend/sqlite/types.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai0x0/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"description": "AI0x0 utils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai0x0"
|
|
@@ -85,6 +85,8 @@
|
|
|
85
85
|
"peerDependencies": {
|
|
86
86
|
"drizzle-orm": "^0.45.2",
|
|
87
87
|
"drizzle-zod": "^0.8.3",
|
|
88
|
+
"next": "^16.0.0",
|
|
89
|
+
"next-rest-framework": "*",
|
|
88
90
|
"zod": "^4.3.6"
|
|
89
91
|
}
|
|
90
92
|
}
|