@sonicjs-cms/core 2.0.0-beta.3 → 2.0.1
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/dist/{chunk-4MZPFGLT.cjs → chunk-5FDDDD4J.cjs} +4385 -352
- package/dist/chunk-5FDDDD4J.cjs.map +1 -0
- package/dist/chunk-5XTB4FE5.js +1030 -0
- package/dist/chunk-5XTB4FE5.js.map +1 -0
- package/dist/{chunk-ET5I4GBD.cjs → chunk-ALOS2CBJ.cjs} +194 -4
- package/dist/chunk-ALOS2CBJ.cjs.map +1 -0
- package/dist/{chunk-7N3HK7ZK.js → chunk-CDBVZEWR.js} +7 -904
- package/dist/chunk-CDBVZEWR.js.map +1 -0
- package/dist/chunk-EGFHFM4N.cjs +76 -0
- package/dist/chunk-EGFHFM4N.cjs.map +1 -0
- package/dist/chunk-KM4AJFXI.cjs +101 -0
- package/dist/chunk-KM4AJFXI.cjs.map +1 -0
- package/dist/{chunk-RNR4HA23.cjs → chunk-LEG4KNFP.cjs} +6 -945
- package/dist/chunk-LEG4KNFP.cjs.map +1 -0
- package/dist/{chunk-P3VS4DV3.js → chunk-O46XKBFM.js} +193 -5
- package/dist/chunk-O46XKBFM.js.map +1 -0
- package/dist/chunk-P2PTTBO5.js +74 -0
- package/dist/chunk-P2PTTBO5.js.map +1 -0
- package/dist/{chunk-Q3KCKPHE.js → chunk-QSF34IYQ.js} +4244 -214
- package/dist/chunk-QSF34IYQ.js.map +1 -0
- package/dist/chunk-SRCY43RN.cjs +1076 -0
- package/dist/chunk-SRCY43RN.cjs.map +1 -0
- package/dist/chunk-TY3NHEBN.js +80 -0
- package/dist/chunk-TY3NHEBN.js.map +1 -0
- package/dist/index.cjs +196 -196
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -9
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +22 -22
- package/dist/middleware.js +2 -2
- package/dist/routes.cjs +34 -22
- package/dist/routes.js +5 -5
- package/dist/services.cjs +28 -28
- package/dist/services.js +2 -2
- package/dist/templates.cjs +24 -24
- package/dist/templates.js +2 -2
- package/package.json +2 -16
- package/dist/chunk-3MNMOLSA.js +0 -133
- package/dist/chunk-3MNMOLSA.js.map +0 -1
- package/dist/chunk-4MZPFGLT.cjs.map +0 -1
- package/dist/chunk-4XI3YBKU.cjs +0 -266
- package/dist/chunk-4XI3YBKU.cjs.map +0 -1
- package/dist/chunk-7N3HK7ZK.js.map +0 -1
- package/dist/chunk-AGOE25LF.cjs +0 -137
- package/dist/chunk-AGOE25LF.cjs.map +0 -1
- package/dist/chunk-BUKT6HP5.cjs +0 -776
- package/dist/chunk-BUKT6HP5.cjs.map +0 -1
- package/dist/chunk-ET5I4GBD.cjs.map +0 -1
- package/dist/chunk-LU6J53IX.js +0 -262
- package/dist/chunk-LU6J53IX.js.map +0 -1
- package/dist/chunk-P3VS4DV3.js.map +0 -1
- package/dist/chunk-Q3KCKPHE.js.map +0 -1
- package/dist/chunk-RNR4HA23.cjs.map +0 -1
- package/dist/chunk-WESS2U3K.js +0 -755
- package/dist/chunk-WESS2U3K.js.map +0 -1
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var chunkIGJUBJBW_cjs = require('./chunk-IGJUBJBW.cjs');
|
|
4
|
-
var sqliteCore = require('drizzle-orm/sqlite-core');
|
|
5
|
-
var v4 = require('zod/v4');
|
|
6
|
-
var drizzleOrm = require('drizzle-orm');
|
|
7
|
-
var d1 = require('drizzle-orm/d1');
|
|
8
|
-
|
|
9
3
|
// src/services/collection-loader.ts
|
|
10
4
|
async function loadCollectionConfigs() {
|
|
11
|
-
const
|
|
5
|
+
const collections = [];
|
|
12
6
|
try {
|
|
13
7
|
const modules = undefined?.("../collections/*.collection.ts", { eager: true }) || {};
|
|
14
8
|
for (const [path, module] of Object.entries(modules)) {
|
|
@@ -28,14 +22,14 @@ async function loadCollectionConfigs() {
|
|
|
28
22
|
managed: config.managed !== void 0 ? config.managed : true,
|
|
29
23
|
isActive: config.isActive !== void 0 ? config.isActive : true
|
|
30
24
|
};
|
|
31
|
-
|
|
25
|
+
collections.push(normalizedConfig);
|
|
32
26
|
console.log(`\u2713 Loaded collection config: ${config.name}`);
|
|
33
27
|
} catch (error) {
|
|
34
28
|
console.error(`Error loading collection from ${path}:`, error);
|
|
35
29
|
}
|
|
36
30
|
}
|
|
37
|
-
console.log(`Loaded ${
|
|
38
|
-
return
|
|
31
|
+
console.log(`Loaded ${collections.length} collection configuration(s)`);
|
|
32
|
+
return collections;
|
|
39
33
|
} catch (error) {
|
|
40
34
|
console.error("Error loading collection configurations:", error);
|
|
41
35
|
return [];
|
|
@@ -983,897 +977,6 @@ INSERT OR IGNORE INTO content (
|
|
|
983
977
|
}
|
|
984
978
|
};
|
|
985
979
|
|
|
986
|
-
// src/db/schema.ts
|
|
987
|
-
var schema_exports = {};
|
|
988
|
-
chunkIGJUBJBW_cjs.__export(schema_exports, {
|
|
989
|
-
apiTokens: () => apiTokens,
|
|
990
|
-
collections: () => collections,
|
|
991
|
-
content: () => content,
|
|
992
|
-
contentVersions: () => contentVersions,
|
|
993
|
-
insertCollectionSchema: () => insertCollectionSchema,
|
|
994
|
-
insertContentSchema: () => insertContentSchema,
|
|
995
|
-
insertLogConfigSchema: () => insertLogConfigSchema,
|
|
996
|
-
insertMediaSchema: () => insertMediaSchema,
|
|
997
|
-
insertPluginActivityLogSchema: () => insertPluginActivityLogSchema,
|
|
998
|
-
insertPluginAssetSchema: () => insertPluginAssetSchema,
|
|
999
|
-
insertPluginHookSchema: () => insertPluginHookSchema,
|
|
1000
|
-
insertPluginRouteSchema: () => insertPluginRouteSchema,
|
|
1001
|
-
insertPluginSchema: () => insertPluginSchema,
|
|
1002
|
-
insertSystemLogSchema: () => insertSystemLogSchema,
|
|
1003
|
-
insertUserSchema: () => insertUserSchema,
|
|
1004
|
-
insertWorkflowHistorySchema: () => insertWorkflowHistorySchema,
|
|
1005
|
-
logConfig: () => logConfig,
|
|
1006
|
-
media: () => media,
|
|
1007
|
-
pluginActivityLog: () => pluginActivityLog,
|
|
1008
|
-
pluginAssets: () => pluginAssets,
|
|
1009
|
-
pluginHooks: () => pluginHooks,
|
|
1010
|
-
pluginRoutes: () => pluginRoutes,
|
|
1011
|
-
plugins: () => plugins,
|
|
1012
|
-
selectCollectionSchema: () => selectCollectionSchema,
|
|
1013
|
-
selectContentSchema: () => selectContentSchema,
|
|
1014
|
-
selectLogConfigSchema: () => selectLogConfigSchema,
|
|
1015
|
-
selectMediaSchema: () => selectMediaSchema,
|
|
1016
|
-
selectPluginActivityLogSchema: () => selectPluginActivityLogSchema,
|
|
1017
|
-
selectPluginAssetSchema: () => selectPluginAssetSchema,
|
|
1018
|
-
selectPluginHookSchema: () => selectPluginHookSchema,
|
|
1019
|
-
selectPluginRouteSchema: () => selectPluginRouteSchema,
|
|
1020
|
-
selectPluginSchema: () => selectPluginSchema,
|
|
1021
|
-
selectSystemLogSchema: () => selectSystemLogSchema,
|
|
1022
|
-
selectUserSchema: () => selectUserSchema,
|
|
1023
|
-
selectWorkflowHistorySchema: () => selectWorkflowHistorySchema,
|
|
1024
|
-
systemLogs: () => systemLogs,
|
|
1025
|
-
users: () => users,
|
|
1026
|
-
workflowHistory: () => workflowHistory
|
|
1027
|
-
});
|
|
1028
|
-
var CONSTANTS = {
|
|
1029
|
-
INT8_MIN: -128,
|
|
1030
|
-
INT8_MAX: 127,
|
|
1031
|
-
INT8_UNSIGNED_MAX: 255,
|
|
1032
|
-
INT16_MIN: -32768,
|
|
1033
|
-
INT16_MAX: 32767,
|
|
1034
|
-
INT16_UNSIGNED_MAX: 65535,
|
|
1035
|
-
INT24_MIN: -8388608,
|
|
1036
|
-
INT24_MAX: 8388607,
|
|
1037
|
-
INT24_UNSIGNED_MAX: 16777215,
|
|
1038
|
-
INT32_MIN: -2147483648,
|
|
1039
|
-
INT32_MAX: 2147483647,
|
|
1040
|
-
INT32_UNSIGNED_MAX: 4294967295,
|
|
1041
|
-
INT48_MIN: -140737488355328,
|
|
1042
|
-
INT48_MAX: 140737488355327,
|
|
1043
|
-
INT48_UNSIGNED_MAX: 281474976710655,
|
|
1044
|
-
INT64_MIN: -9223372036854775808n,
|
|
1045
|
-
INT64_MAX: 9223372036854775807n,
|
|
1046
|
-
INT64_UNSIGNED_MAX: 18446744073709551615n
|
|
1047
|
-
};
|
|
1048
|
-
function isColumnType(column, columnTypes) {
|
|
1049
|
-
return columnTypes.includes(column.columnType);
|
|
1050
|
-
}
|
|
1051
|
-
function isWithEnum(column) {
|
|
1052
|
-
return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
|
|
1053
|
-
}
|
|
1054
|
-
var isPgEnum = isWithEnum;
|
|
1055
|
-
var literalSchema = v4.z.union([v4.z.string(), v4.z.number(), v4.z.boolean(), v4.z.null()]);
|
|
1056
|
-
var jsonSchema = v4.z.union([
|
|
1057
|
-
literalSchema,
|
|
1058
|
-
v4.z.record(v4.z.string(), v4.z.any()),
|
|
1059
|
-
v4.z.array(v4.z.any())
|
|
1060
|
-
]);
|
|
1061
|
-
var bufferSchema = v4.z.custom((v) => v instanceof Buffer);
|
|
1062
|
-
function columnToSchema(column, factory) {
|
|
1063
|
-
const z$1 = v4.z;
|
|
1064
|
-
const coerce = {};
|
|
1065
|
-
let schema;
|
|
1066
|
-
if (isWithEnum(column)) {
|
|
1067
|
-
schema = column.enumValues.length ? z$1.enum(column.enumValues) : z$1.string();
|
|
1068
|
-
}
|
|
1069
|
-
if (!schema) {
|
|
1070
|
-
if (isColumnType(column, ["PgGeometry", "PgPointTuple"])) {
|
|
1071
|
-
schema = z$1.tuple([z$1.number(), z$1.number()]);
|
|
1072
|
-
} else if (isColumnType(column, ["PgGeometryObject", "PgPointObject"])) {
|
|
1073
|
-
schema = z$1.object({ x: z$1.number(), y: z$1.number() });
|
|
1074
|
-
} else if (isColumnType(column, ["PgHalfVector", "PgVector"])) {
|
|
1075
|
-
schema = z$1.array(z$1.number());
|
|
1076
|
-
schema = column.dimensions ? schema.length(column.dimensions) : schema;
|
|
1077
|
-
} else if (isColumnType(column, ["PgLine"])) {
|
|
1078
|
-
schema = z$1.tuple([z$1.number(), z$1.number(), z$1.number()]);
|
|
1079
|
-
} else if (isColumnType(column, ["PgLineABC"])) {
|
|
1080
|
-
schema = z$1.object({
|
|
1081
|
-
a: z$1.number(),
|
|
1082
|
-
b: z$1.number(),
|
|
1083
|
-
c: z$1.number()
|
|
1084
|
-
});
|
|
1085
|
-
} else if (isColumnType(column, ["PgArray"])) {
|
|
1086
|
-
schema = z$1.array(columnToSchema(column.baseColumn));
|
|
1087
|
-
schema = column.size ? schema.length(column.size) : schema;
|
|
1088
|
-
} else if (column.dataType === "array") {
|
|
1089
|
-
schema = z$1.array(z$1.any());
|
|
1090
|
-
} else if (column.dataType === "number") {
|
|
1091
|
-
schema = numberColumnToSchema(column, z$1, coerce);
|
|
1092
|
-
} else if (column.dataType === "bigint") {
|
|
1093
|
-
schema = bigintColumnToSchema(column, z$1, coerce);
|
|
1094
|
-
} else if (column.dataType === "boolean") {
|
|
1095
|
-
schema = coerce === true || coerce.boolean ? z$1.coerce.boolean() : z$1.boolean();
|
|
1096
|
-
} else if (column.dataType === "date") {
|
|
1097
|
-
schema = coerce === true || coerce.date ? z$1.coerce.date() : z$1.date();
|
|
1098
|
-
} else if (column.dataType === "string") {
|
|
1099
|
-
schema = stringColumnToSchema(column, z$1, coerce);
|
|
1100
|
-
} else if (column.dataType === "json") {
|
|
1101
|
-
schema = jsonSchema;
|
|
1102
|
-
} else if (column.dataType === "custom") {
|
|
1103
|
-
schema = z$1.any();
|
|
1104
|
-
} else if (column.dataType === "buffer") {
|
|
1105
|
-
schema = bufferSchema;
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
if (!schema) {
|
|
1109
|
-
schema = z$1.any();
|
|
1110
|
-
}
|
|
1111
|
-
return schema;
|
|
1112
|
-
}
|
|
1113
|
-
function numberColumnToSchema(column, z2, coerce) {
|
|
1114
|
-
let unsigned = column.getSQLType().includes("unsigned");
|
|
1115
|
-
let min;
|
|
1116
|
-
let max;
|
|
1117
|
-
let integer2 = false;
|
|
1118
|
-
if (isColumnType(column, ["MySqlTinyInt", "SingleStoreTinyInt"])) {
|
|
1119
|
-
min = unsigned ? 0 : CONSTANTS.INT8_MIN;
|
|
1120
|
-
max = unsigned ? CONSTANTS.INT8_UNSIGNED_MAX : CONSTANTS.INT8_MAX;
|
|
1121
|
-
integer2 = true;
|
|
1122
|
-
} else if (isColumnType(column, [
|
|
1123
|
-
"PgSmallInt",
|
|
1124
|
-
"PgSmallSerial",
|
|
1125
|
-
"MySqlSmallInt",
|
|
1126
|
-
"SingleStoreSmallInt"
|
|
1127
|
-
])) {
|
|
1128
|
-
min = unsigned ? 0 : CONSTANTS.INT16_MIN;
|
|
1129
|
-
max = unsigned ? CONSTANTS.INT16_UNSIGNED_MAX : CONSTANTS.INT16_MAX;
|
|
1130
|
-
integer2 = true;
|
|
1131
|
-
} else if (isColumnType(column, [
|
|
1132
|
-
"PgReal",
|
|
1133
|
-
"MySqlFloat",
|
|
1134
|
-
"MySqlMediumInt",
|
|
1135
|
-
"SingleStoreMediumInt",
|
|
1136
|
-
"SingleStoreFloat"
|
|
1137
|
-
])) {
|
|
1138
|
-
min = unsigned ? 0 : CONSTANTS.INT24_MIN;
|
|
1139
|
-
max = unsigned ? CONSTANTS.INT24_UNSIGNED_MAX : CONSTANTS.INT24_MAX;
|
|
1140
|
-
integer2 = isColumnType(column, ["MySqlMediumInt", "SingleStoreMediumInt"]);
|
|
1141
|
-
} else if (isColumnType(column, [
|
|
1142
|
-
"PgInteger",
|
|
1143
|
-
"PgSerial",
|
|
1144
|
-
"MySqlInt",
|
|
1145
|
-
"SingleStoreInt"
|
|
1146
|
-
])) {
|
|
1147
|
-
min = unsigned ? 0 : CONSTANTS.INT32_MIN;
|
|
1148
|
-
max = unsigned ? CONSTANTS.INT32_UNSIGNED_MAX : CONSTANTS.INT32_MAX;
|
|
1149
|
-
integer2 = true;
|
|
1150
|
-
} else if (isColumnType(column, [
|
|
1151
|
-
"PgDoublePrecision",
|
|
1152
|
-
"MySqlReal",
|
|
1153
|
-
"MySqlDouble",
|
|
1154
|
-
"SingleStoreReal",
|
|
1155
|
-
"SingleStoreDouble",
|
|
1156
|
-
"SQLiteReal"
|
|
1157
|
-
])) {
|
|
1158
|
-
min = unsigned ? 0 : CONSTANTS.INT48_MIN;
|
|
1159
|
-
max = unsigned ? CONSTANTS.INT48_UNSIGNED_MAX : CONSTANTS.INT48_MAX;
|
|
1160
|
-
} else if (isColumnType(column, [
|
|
1161
|
-
"PgBigInt53",
|
|
1162
|
-
"PgBigSerial53",
|
|
1163
|
-
"MySqlBigInt53",
|
|
1164
|
-
"MySqlSerial",
|
|
1165
|
-
"SingleStoreBigInt53",
|
|
1166
|
-
"SingleStoreSerial",
|
|
1167
|
-
"SQLiteInteger"
|
|
1168
|
-
])) {
|
|
1169
|
-
unsigned = unsigned || isColumnType(column, ["MySqlSerial", "SingleStoreSerial"]);
|
|
1170
|
-
min = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
|
|
1171
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
1172
|
-
integer2 = true;
|
|
1173
|
-
} else if (isColumnType(column, ["MySqlYear", "SingleStoreYear"])) {
|
|
1174
|
-
min = 1901;
|
|
1175
|
-
max = 2155;
|
|
1176
|
-
integer2 = true;
|
|
1177
|
-
} else {
|
|
1178
|
-
min = Number.MIN_SAFE_INTEGER;
|
|
1179
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
1180
|
-
}
|
|
1181
|
-
let schema = coerce === true || coerce?.number ? integer2 ? z2.coerce.number() : z2.coerce.number().int() : integer2 ? z2.int() : z2.number();
|
|
1182
|
-
schema = schema.gte(min).lte(max);
|
|
1183
|
-
return schema;
|
|
1184
|
-
}
|
|
1185
|
-
function bigintColumnToSchema(column, z2, coerce) {
|
|
1186
|
-
const unsigned = column.getSQLType().includes("unsigned");
|
|
1187
|
-
const min = unsigned ? 0n : CONSTANTS.INT64_MIN;
|
|
1188
|
-
const max = unsigned ? CONSTANTS.INT64_UNSIGNED_MAX : CONSTANTS.INT64_MAX;
|
|
1189
|
-
const schema = coerce === true || coerce?.bigint ? z2.coerce.bigint() : z2.bigint();
|
|
1190
|
-
return schema.gte(min).lte(max);
|
|
1191
|
-
}
|
|
1192
|
-
function stringColumnToSchema(column, z2, coerce) {
|
|
1193
|
-
if (isColumnType(column, ["PgUUID"])) {
|
|
1194
|
-
return z2.uuid();
|
|
1195
|
-
}
|
|
1196
|
-
let max;
|
|
1197
|
-
let regex;
|
|
1198
|
-
let fixed = false;
|
|
1199
|
-
if (isColumnType(column, ["PgVarchar", "SQLiteText"])) {
|
|
1200
|
-
max = column.length;
|
|
1201
|
-
} else if (isColumnType(column, ["MySqlVarChar", "SingleStoreVarChar"])) {
|
|
1202
|
-
max = column.length ?? CONSTANTS.INT16_UNSIGNED_MAX;
|
|
1203
|
-
} else if (isColumnType(column, ["MySqlText", "SingleStoreText"])) {
|
|
1204
|
-
if (column.textType === "longtext") {
|
|
1205
|
-
max = CONSTANTS.INT32_UNSIGNED_MAX;
|
|
1206
|
-
} else if (column.textType === "mediumtext") {
|
|
1207
|
-
max = CONSTANTS.INT24_UNSIGNED_MAX;
|
|
1208
|
-
} else if (column.textType === "text") {
|
|
1209
|
-
max = CONSTANTS.INT16_UNSIGNED_MAX;
|
|
1210
|
-
} else {
|
|
1211
|
-
max = CONSTANTS.INT8_UNSIGNED_MAX;
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
if (isColumnType(column, [
|
|
1215
|
-
"PgChar",
|
|
1216
|
-
"MySqlChar",
|
|
1217
|
-
"SingleStoreChar"
|
|
1218
|
-
])) {
|
|
1219
|
-
max = column.length;
|
|
1220
|
-
fixed = true;
|
|
1221
|
-
}
|
|
1222
|
-
if (isColumnType(column, ["PgBinaryVector"])) {
|
|
1223
|
-
regex = /^[01]+$/;
|
|
1224
|
-
max = column.dimensions;
|
|
1225
|
-
}
|
|
1226
|
-
let schema = coerce === true || coerce?.string ? z2.coerce.string() : z2.string();
|
|
1227
|
-
schema = regex ? schema.regex(regex) : schema;
|
|
1228
|
-
return max && fixed ? schema.length(max) : max ? schema.max(max) : schema;
|
|
1229
|
-
}
|
|
1230
|
-
function getColumns(tableLike) {
|
|
1231
|
-
return drizzleOrm.isTable(tableLike) ? drizzleOrm.getTableColumns(tableLike) : drizzleOrm.getViewSelectedFields(tableLike);
|
|
1232
|
-
}
|
|
1233
|
-
function handleColumns(columns, refinements, conditions, factory) {
|
|
1234
|
-
const columnSchemas = {};
|
|
1235
|
-
for (const [key, selected] of Object.entries(columns)) {
|
|
1236
|
-
if (!drizzleOrm.is(selected, drizzleOrm.Column) && !drizzleOrm.is(selected, drizzleOrm.SQL) && !drizzleOrm.is(selected, drizzleOrm.SQL.Aliased) && typeof selected === "object") {
|
|
1237
|
-
const columns2 = drizzleOrm.isTable(selected) || drizzleOrm.isView(selected) ? getColumns(selected) : selected;
|
|
1238
|
-
columnSchemas[key] = handleColumns(columns2, refinements[key] ?? {}, conditions);
|
|
1239
|
-
continue;
|
|
1240
|
-
}
|
|
1241
|
-
const refinement = refinements[key];
|
|
1242
|
-
if (refinement !== void 0 && typeof refinement !== "function") {
|
|
1243
|
-
columnSchemas[key] = refinement;
|
|
1244
|
-
continue;
|
|
1245
|
-
}
|
|
1246
|
-
const column = drizzleOrm.is(selected, drizzleOrm.Column) ? selected : void 0;
|
|
1247
|
-
const schema = column ? columnToSchema(column) : v4.z.any();
|
|
1248
|
-
const refined = typeof refinement === "function" ? refinement(schema) : schema;
|
|
1249
|
-
if (conditions.never(column)) {
|
|
1250
|
-
continue;
|
|
1251
|
-
} else {
|
|
1252
|
-
columnSchemas[key] = refined;
|
|
1253
|
-
}
|
|
1254
|
-
if (column) {
|
|
1255
|
-
if (conditions.nullable(column)) {
|
|
1256
|
-
columnSchemas[key] = columnSchemas[key].nullable();
|
|
1257
|
-
}
|
|
1258
|
-
if (conditions.optional(column)) {
|
|
1259
|
-
columnSchemas[key] = columnSchemas[key].optional();
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
}
|
|
1263
|
-
return v4.z.object(columnSchemas);
|
|
1264
|
-
}
|
|
1265
|
-
function handleEnum(enum_, factory) {
|
|
1266
|
-
const zod = v4.z;
|
|
1267
|
-
return zod.enum(enum_.enumValues);
|
|
1268
|
-
}
|
|
1269
|
-
var selectConditions = {
|
|
1270
|
-
never: () => false,
|
|
1271
|
-
optional: () => false,
|
|
1272
|
-
nullable: (column) => !column.notNull
|
|
1273
|
-
};
|
|
1274
|
-
var insertConditions = {
|
|
1275
|
-
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always",
|
|
1276
|
-
optional: (column) => !column.notNull || column.notNull && column.hasDefault,
|
|
1277
|
-
nullable: (column) => !column.notNull
|
|
1278
|
-
};
|
|
1279
|
-
var createSelectSchema = (entity, refine) => {
|
|
1280
|
-
if (isPgEnum(entity)) {
|
|
1281
|
-
return handleEnum(entity);
|
|
1282
|
-
}
|
|
1283
|
-
const columns = getColumns(entity);
|
|
1284
|
-
return handleColumns(columns, {}, selectConditions);
|
|
1285
|
-
};
|
|
1286
|
-
var createInsertSchema = (entity, refine) => {
|
|
1287
|
-
const columns = getColumns(entity);
|
|
1288
|
-
return handleColumns(columns, refine ?? {}, insertConditions);
|
|
1289
|
-
};
|
|
1290
|
-
|
|
1291
|
-
// src/db/schema.ts
|
|
1292
|
-
var users = sqliteCore.sqliteTable("users", {
|
|
1293
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1294
|
-
email: sqliteCore.text("email").notNull().unique(),
|
|
1295
|
-
username: sqliteCore.text("username").notNull().unique(),
|
|
1296
|
-
firstName: sqliteCore.text("first_name").notNull(),
|
|
1297
|
-
lastName: sqliteCore.text("last_name").notNull(),
|
|
1298
|
-
passwordHash: sqliteCore.text("password_hash"),
|
|
1299
|
-
// Hashed password, nullable for OAuth users
|
|
1300
|
-
role: sqliteCore.text("role").notNull().default("viewer"),
|
|
1301
|
-
// 'admin', 'editor', 'author', 'viewer'
|
|
1302
|
-
avatar: sqliteCore.text("avatar"),
|
|
1303
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
1304
|
-
lastLoginAt: sqliteCore.integer("last_login_at"),
|
|
1305
|
-
createdAt: sqliteCore.integer("created_at").notNull(),
|
|
1306
|
-
updatedAt: sqliteCore.integer("updated_at").notNull()
|
|
1307
|
-
});
|
|
1308
|
-
var collections = sqliteCore.sqliteTable("collections", {
|
|
1309
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1310
|
-
name: sqliteCore.text("name").notNull().unique(),
|
|
1311
|
-
displayName: sqliteCore.text("display_name").notNull(),
|
|
1312
|
-
description: sqliteCore.text("description"),
|
|
1313
|
-
schema: sqliteCore.text("schema", { mode: "json" }).notNull(),
|
|
1314
|
-
// JSON schema definition
|
|
1315
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
1316
|
-
managed: sqliteCore.integer("managed", { mode: "boolean" }).notNull().default(false),
|
|
1317
|
-
// Config-managed collections cannot be edited in UI
|
|
1318
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
1319
|
-
updatedAt: sqliteCore.integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1320
|
-
});
|
|
1321
|
-
var content = sqliteCore.sqliteTable("content", {
|
|
1322
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1323
|
-
collectionId: sqliteCore.text("collection_id").notNull().references(() => collections.id),
|
|
1324
|
-
slug: sqliteCore.text("slug").notNull(),
|
|
1325
|
-
title: sqliteCore.text("title").notNull(),
|
|
1326
|
-
data: sqliteCore.text("data", { mode: "json" }).notNull(),
|
|
1327
|
-
// JSON content data
|
|
1328
|
-
status: sqliteCore.text("status").notNull().default("draft"),
|
|
1329
|
-
// 'draft', 'published', 'archived'
|
|
1330
|
-
publishedAt: sqliteCore.integer("published_at", { mode: "timestamp" }),
|
|
1331
|
-
authorId: sqliteCore.text("author_id").notNull().references(() => users.id),
|
|
1332
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
1333
|
-
updatedAt: sqliteCore.integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1334
|
-
});
|
|
1335
|
-
var contentVersions = sqliteCore.sqliteTable("content_versions", {
|
|
1336
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1337
|
-
contentId: sqliteCore.text("content_id").notNull().references(() => content.id),
|
|
1338
|
-
version: sqliteCore.integer("version").notNull(),
|
|
1339
|
-
data: sqliteCore.text("data", { mode: "json" }).notNull(),
|
|
1340
|
-
authorId: sqliteCore.text("author_id").notNull().references(() => users.id),
|
|
1341
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1342
|
-
});
|
|
1343
|
-
var media = sqliteCore.sqliteTable("media", {
|
|
1344
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1345
|
-
filename: sqliteCore.text("filename").notNull(),
|
|
1346
|
-
originalName: sqliteCore.text("original_name").notNull(),
|
|
1347
|
-
mimeType: sqliteCore.text("mime_type").notNull(),
|
|
1348
|
-
size: sqliteCore.integer("size").notNull(),
|
|
1349
|
-
width: sqliteCore.integer("width"),
|
|
1350
|
-
height: sqliteCore.integer("height"),
|
|
1351
|
-
folder: sqliteCore.text("folder").notNull().default("uploads"),
|
|
1352
|
-
r2Key: sqliteCore.text("r2_key").notNull(),
|
|
1353
|
-
// R2 storage key
|
|
1354
|
-
publicUrl: sqliteCore.text("public_url").notNull(),
|
|
1355
|
-
// CDN URL
|
|
1356
|
-
thumbnailUrl: sqliteCore.text("thumbnail_url"),
|
|
1357
|
-
alt: sqliteCore.text("alt"),
|
|
1358
|
-
caption: sqliteCore.text("caption"),
|
|
1359
|
-
tags: sqliteCore.text("tags", { mode: "json" }),
|
|
1360
|
-
// JSON array of tags
|
|
1361
|
-
uploadedBy: sqliteCore.text("uploaded_by").notNull().references(() => users.id),
|
|
1362
|
-
uploadedAt: sqliteCore.integer("uploaded_at").notNull(),
|
|
1363
|
-
updatedAt: sqliteCore.integer("updated_at"),
|
|
1364
|
-
publishedAt: sqliteCore.integer("published_at"),
|
|
1365
|
-
scheduledAt: sqliteCore.integer("scheduled_at"),
|
|
1366
|
-
archivedAt: sqliteCore.integer("archived_at"),
|
|
1367
|
-
deletedAt: sqliteCore.integer("deleted_at")
|
|
1368
|
-
});
|
|
1369
|
-
var apiTokens = sqliteCore.sqliteTable("api_tokens", {
|
|
1370
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1371
|
-
name: sqliteCore.text("name").notNull(),
|
|
1372
|
-
token: sqliteCore.text("token").notNull().unique(),
|
|
1373
|
-
userId: sqliteCore.text("user_id").notNull().references(() => users.id),
|
|
1374
|
-
permissions: sqliteCore.text("permissions", { mode: "json" }).notNull(),
|
|
1375
|
-
// Array of permissions
|
|
1376
|
-
expiresAt: sqliteCore.integer("expires_at", { mode: "timestamp" }),
|
|
1377
|
-
lastUsedAt: sqliteCore.integer("last_used_at", { mode: "timestamp" }),
|
|
1378
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1379
|
-
});
|
|
1380
|
-
var workflowHistory = sqliteCore.sqliteTable("workflow_history", {
|
|
1381
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1382
|
-
contentId: sqliteCore.text("content_id").notNull().references(() => content.id),
|
|
1383
|
-
action: sqliteCore.text("action").notNull(),
|
|
1384
|
-
fromStatus: sqliteCore.text("from_status").notNull(),
|
|
1385
|
-
toStatus: sqliteCore.text("to_status").notNull(),
|
|
1386
|
-
userId: sqliteCore.text("user_id").notNull().references(() => users.id),
|
|
1387
|
-
comment: sqliteCore.text("comment"),
|
|
1388
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1389
|
-
});
|
|
1390
|
-
var plugins = sqliteCore.sqliteTable("plugins", {
|
|
1391
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1392
|
-
name: sqliteCore.text("name").notNull().unique(),
|
|
1393
|
-
displayName: sqliteCore.text("display_name").notNull(),
|
|
1394
|
-
description: sqliteCore.text("description"),
|
|
1395
|
-
version: sqliteCore.text("version").notNull(),
|
|
1396
|
-
author: sqliteCore.text("author").notNull(),
|
|
1397
|
-
category: sqliteCore.text("category").notNull(),
|
|
1398
|
-
icon: sqliteCore.text("icon"),
|
|
1399
|
-
status: sqliteCore.text("status").notNull().default("inactive"),
|
|
1400
|
-
// 'active', 'inactive', 'error'
|
|
1401
|
-
isCore: sqliteCore.integer("is_core", { mode: "boolean" }).notNull().default(false),
|
|
1402
|
-
settings: sqliteCore.text("settings", { mode: "json" }),
|
|
1403
|
-
permissions: sqliteCore.text("permissions", { mode: "json" }),
|
|
1404
|
-
dependencies: sqliteCore.text("dependencies", { mode: "json" }),
|
|
1405
|
-
downloadCount: sqliteCore.integer("download_count").notNull().default(0),
|
|
1406
|
-
rating: sqliteCore.integer("rating").notNull().default(0),
|
|
1407
|
-
installedAt: sqliteCore.integer("installed_at").notNull(),
|
|
1408
|
-
activatedAt: sqliteCore.integer("activated_at"),
|
|
1409
|
-
lastUpdated: sqliteCore.integer("last_updated").notNull(),
|
|
1410
|
-
errorMessage: sqliteCore.text("error_message"),
|
|
1411
|
-
createdAt: sqliteCore.integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3)),
|
|
1412
|
-
updatedAt: sqliteCore.integer("updated_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
1413
|
-
});
|
|
1414
|
-
var pluginHooks = sqliteCore.sqliteTable("plugin_hooks", {
|
|
1415
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1416
|
-
pluginId: sqliteCore.text("plugin_id").notNull().references(() => plugins.id),
|
|
1417
|
-
hookName: sqliteCore.text("hook_name").notNull(),
|
|
1418
|
-
handlerName: sqliteCore.text("handler_name").notNull(),
|
|
1419
|
-
priority: sqliteCore.integer("priority").notNull().default(10),
|
|
1420
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
1421
|
-
createdAt: sqliteCore.integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
1422
|
-
});
|
|
1423
|
-
var pluginRoutes = sqliteCore.sqliteTable("plugin_routes", {
|
|
1424
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1425
|
-
pluginId: sqliteCore.text("plugin_id").notNull().references(() => plugins.id),
|
|
1426
|
-
path: sqliteCore.text("path").notNull(),
|
|
1427
|
-
method: sqliteCore.text("method").notNull(),
|
|
1428
|
-
handlerName: sqliteCore.text("handler_name").notNull(),
|
|
1429
|
-
middleware: sqliteCore.text("middleware", { mode: "json" }),
|
|
1430
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
1431
|
-
createdAt: sqliteCore.integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
1432
|
-
});
|
|
1433
|
-
var pluginAssets = sqliteCore.sqliteTable("plugin_assets", {
|
|
1434
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1435
|
-
pluginId: sqliteCore.text("plugin_id").notNull().references(() => plugins.id),
|
|
1436
|
-
assetType: sqliteCore.text("asset_type").notNull(),
|
|
1437
|
-
// 'css', 'js', 'image', 'font'
|
|
1438
|
-
assetPath: sqliteCore.text("asset_path").notNull(),
|
|
1439
|
-
loadOrder: sqliteCore.integer("load_order").notNull().default(100),
|
|
1440
|
-
loadLocation: sqliteCore.text("load_location").notNull().default("footer"),
|
|
1441
|
-
// 'header', 'footer'
|
|
1442
|
-
isActive: sqliteCore.integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
1443
|
-
createdAt: sqliteCore.integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
1444
|
-
});
|
|
1445
|
-
var pluginActivityLog = sqliteCore.sqliteTable("plugin_activity_log", {
|
|
1446
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1447
|
-
pluginId: sqliteCore.text("plugin_id").notNull().references(() => plugins.id),
|
|
1448
|
-
action: sqliteCore.text("action").notNull(),
|
|
1449
|
-
userId: sqliteCore.text("user_id"),
|
|
1450
|
-
details: sqliteCore.text("details", { mode: "json" }),
|
|
1451
|
-
timestamp: sqliteCore.integer("timestamp").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
1452
|
-
});
|
|
1453
|
-
var insertUserSchema = createInsertSchema(users, {
|
|
1454
|
-
email: (schema) => schema.email(),
|
|
1455
|
-
firstName: (schema) => schema.min(1),
|
|
1456
|
-
lastName: (schema) => schema.min(1),
|
|
1457
|
-
username: (schema) => schema.min(3)
|
|
1458
|
-
});
|
|
1459
|
-
var selectUserSchema = createSelectSchema(users);
|
|
1460
|
-
var insertCollectionSchema = createInsertSchema(collections, {
|
|
1461
|
-
name: (schema) => schema.min(1).regex(/^[a-z0-9_]+$/, "Collection name must be lowercase with underscores"),
|
|
1462
|
-
displayName: (schema) => schema.min(1)
|
|
1463
|
-
});
|
|
1464
|
-
var selectCollectionSchema = createSelectSchema(collections);
|
|
1465
|
-
var insertContentSchema = createInsertSchema(content, {
|
|
1466
|
-
slug: (schema) => schema.min(1).regex(/^[a-zA-Z0-9_-]+$/, "Slug must contain only letters, numbers, underscores, and hyphens"),
|
|
1467
|
-
title: (schema) => schema.min(1),
|
|
1468
|
-
status: (schema) => schema
|
|
1469
|
-
});
|
|
1470
|
-
var selectContentSchema = createSelectSchema(content);
|
|
1471
|
-
var insertMediaSchema = createInsertSchema(media, {
|
|
1472
|
-
filename: (schema) => schema.min(1),
|
|
1473
|
-
originalName: (schema) => schema.min(1),
|
|
1474
|
-
mimeType: (schema) => schema.min(1),
|
|
1475
|
-
size: (schema) => schema.positive(),
|
|
1476
|
-
r2Key: (schema) => schema.min(1),
|
|
1477
|
-
publicUrl: (schema) => schema.url(),
|
|
1478
|
-
folder: (schema) => schema.min(1)
|
|
1479
|
-
});
|
|
1480
|
-
var selectMediaSchema = createSelectSchema(media);
|
|
1481
|
-
var insertWorkflowHistorySchema = createInsertSchema(workflowHistory, {
|
|
1482
|
-
action: (schema) => schema.min(1),
|
|
1483
|
-
fromStatus: (schema) => schema.min(1),
|
|
1484
|
-
toStatus: (schema) => schema.min(1)
|
|
1485
|
-
});
|
|
1486
|
-
var selectWorkflowHistorySchema = createSelectSchema(workflowHistory);
|
|
1487
|
-
var insertPluginSchema = createInsertSchema(plugins, {
|
|
1488
|
-
name: (schema) => schema.min(1),
|
|
1489
|
-
displayName: (schema) => schema.min(1),
|
|
1490
|
-
version: (schema) => schema.min(1),
|
|
1491
|
-
author: (schema) => schema.min(1),
|
|
1492
|
-
category: (schema) => schema.min(1)
|
|
1493
|
-
});
|
|
1494
|
-
var selectPluginSchema = createSelectSchema(plugins);
|
|
1495
|
-
var insertPluginHookSchema = createInsertSchema(pluginHooks, {
|
|
1496
|
-
hookName: (schema) => schema.min(1),
|
|
1497
|
-
handlerName: (schema) => schema.min(1)
|
|
1498
|
-
});
|
|
1499
|
-
var selectPluginHookSchema = createSelectSchema(pluginHooks);
|
|
1500
|
-
var insertPluginRouteSchema = createInsertSchema(pluginRoutes, {
|
|
1501
|
-
path: (schema) => schema.min(1),
|
|
1502
|
-
method: (schema) => schema.min(1),
|
|
1503
|
-
handlerName: (schema) => schema.min(1)
|
|
1504
|
-
});
|
|
1505
|
-
var selectPluginRouteSchema = createSelectSchema(pluginRoutes);
|
|
1506
|
-
var insertPluginAssetSchema = createInsertSchema(pluginAssets, {
|
|
1507
|
-
assetType: (schema) => schema.min(1),
|
|
1508
|
-
assetPath: (schema) => schema.min(1)
|
|
1509
|
-
});
|
|
1510
|
-
var selectPluginAssetSchema = createSelectSchema(pluginAssets);
|
|
1511
|
-
var insertPluginActivityLogSchema = createInsertSchema(pluginActivityLog, {
|
|
1512
|
-
action: (schema) => schema.min(1)
|
|
1513
|
-
});
|
|
1514
|
-
var selectPluginActivityLogSchema = createSelectSchema(pluginActivityLog);
|
|
1515
|
-
var systemLogs = sqliteCore.sqliteTable("system_logs", {
|
|
1516
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1517
|
-
level: sqliteCore.text("level").notNull(),
|
|
1518
|
-
// 'debug', 'info', 'warn', 'error', 'fatal'
|
|
1519
|
-
category: sqliteCore.text("category").notNull(),
|
|
1520
|
-
// 'auth', 'api', 'workflow', 'plugin', 'media', 'system', etc.
|
|
1521
|
-
message: sqliteCore.text("message").notNull(),
|
|
1522
|
-
data: sqliteCore.text("data", { mode: "json" }),
|
|
1523
|
-
// Additional structured data
|
|
1524
|
-
userId: sqliteCore.text("user_id").references(() => users.id),
|
|
1525
|
-
sessionId: sqliteCore.text("session_id"),
|
|
1526
|
-
requestId: sqliteCore.text("request_id"),
|
|
1527
|
-
ipAddress: sqliteCore.text("ip_address"),
|
|
1528
|
-
userAgent: sqliteCore.text("user_agent"),
|
|
1529
|
-
method: sqliteCore.text("method"),
|
|
1530
|
-
// HTTP method for API logs
|
|
1531
|
-
url: sqliteCore.text("url"),
|
|
1532
|
-
// Request URL for API logs
|
|
1533
|
-
statusCode: sqliteCore.integer("status_code"),
|
|
1534
|
-
// HTTP status code for API logs
|
|
1535
|
-
duration: sqliteCore.integer("duration"),
|
|
1536
|
-
// Request duration in milliseconds
|
|
1537
|
-
stackTrace: sqliteCore.text("stack_trace"),
|
|
1538
|
-
// Error stack trace for error logs
|
|
1539
|
-
tags: sqliteCore.text("tags", { mode: "json" }),
|
|
1540
|
-
// Array of tags for categorization
|
|
1541
|
-
source: sqliteCore.text("source"),
|
|
1542
|
-
// Source component/module that generated the log
|
|
1543
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1544
|
-
});
|
|
1545
|
-
var logConfig = sqliteCore.sqliteTable("log_config", {
|
|
1546
|
-
id: sqliteCore.text("id").primaryKey(),
|
|
1547
|
-
category: sqliteCore.text("category").notNull().unique(),
|
|
1548
|
-
enabled: sqliteCore.integer("enabled", { mode: "boolean" }).notNull().default(true),
|
|
1549
|
-
level: sqliteCore.text("level").notNull().default("info"),
|
|
1550
|
-
// minimum log level to store
|
|
1551
|
-
retention: sqliteCore.integer("retention").notNull().default(30),
|
|
1552
|
-
// days to keep logs
|
|
1553
|
-
maxSize: sqliteCore.integer("max_size").default(1e4),
|
|
1554
|
-
// max number of logs per category
|
|
1555
|
-
createdAt: sqliteCore.integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
1556
|
-
updatedAt: sqliteCore.integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
1557
|
-
});
|
|
1558
|
-
var insertSystemLogSchema = createInsertSchema(systemLogs, {
|
|
1559
|
-
level: (schema) => schema.min(1),
|
|
1560
|
-
category: (schema) => schema.min(1),
|
|
1561
|
-
message: (schema) => schema.min(1)
|
|
1562
|
-
});
|
|
1563
|
-
var selectSystemLogSchema = createSelectSchema(systemLogs);
|
|
1564
|
-
var insertLogConfigSchema = createInsertSchema(logConfig, {
|
|
1565
|
-
category: (schema) => schema.min(1),
|
|
1566
|
-
level: (schema) => schema.min(1)
|
|
1567
|
-
});
|
|
1568
|
-
var selectLogConfigSchema = createSelectSchema(logConfig);
|
|
1569
|
-
var Logger = class {
|
|
1570
|
-
db;
|
|
1571
|
-
enabled = true;
|
|
1572
|
-
configCache = /* @__PURE__ */ new Map();
|
|
1573
|
-
lastConfigRefresh = 0;
|
|
1574
|
-
configRefreshInterval = 6e4;
|
|
1575
|
-
// 1 minute
|
|
1576
|
-
constructor(database) {
|
|
1577
|
-
this.db = d1.drizzle(database);
|
|
1578
|
-
}
|
|
1579
|
-
/**
|
|
1580
|
-
* Log a debug message
|
|
1581
|
-
*/
|
|
1582
|
-
async debug(category, message, data, context) {
|
|
1583
|
-
return this.log("debug", category, message, data, context);
|
|
1584
|
-
}
|
|
1585
|
-
/**
|
|
1586
|
-
* Log an info message
|
|
1587
|
-
*/
|
|
1588
|
-
async info(category, message, data, context) {
|
|
1589
|
-
return this.log("info", category, message, data, context);
|
|
1590
|
-
}
|
|
1591
|
-
/**
|
|
1592
|
-
* Log a warning message
|
|
1593
|
-
*/
|
|
1594
|
-
async warn(category, message, data, context) {
|
|
1595
|
-
return this.log("warn", category, message, data, context);
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Log an error message
|
|
1599
|
-
*/
|
|
1600
|
-
async error(category, message, error, context) {
|
|
1601
|
-
const errorData = error instanceof Error ? {
|
|
1602
|
-
name: error.name,
|
|
1603
|
-
message: error.message,
|
|
1604
|
-
stack: error.stack
|
|
1605
|
-
} : error;
|
|
1606
|
-
return this.log("error", category, message, errorData, {
|
|
1607
|
-
...context,
|
|
1608
|
-
stackTrace: error instanceof Error ? error.stack : void 0
|
|
1609
|
-
});
|
|
1610
|
-
}
|
|
1611
|
-
/**
|
|
1612
|
-
* Log a fatal message
|
|
1613
|
-
*/
|
|
1614
|
-
async fatal(category, message, error, context) {
|
|
1615
|
-
const errorData = error instanceof Error ? {
|
|
1616
|
-
name: error.name,
|
|
1617
|
-
message: error.message,
|
|
1618
|
-
stack: error.stack
|
|
1619
|
-
} : error;
|
|
1620
|
-
return this.log("fatal", category, message, errorData, {
|
|
1621
|
-
...context,
|
|
1622
|
-
stackTrace: error instanceof Error ? error.stack : void 0
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
/**
|
|
1626
|
-
* Log an API request
|
|
1627
|
-
*/
|
|
1628
|
-
async logRequest(method, url, statusCode, duration, context) {
|
|
1629
|
-
const level = statusCode >= 500 ? "error" : statusCode >= 400 ? "warn" : "info";
|
|
1630
|
-
return this.log(level, "api", `${method} ${url} - ${statusCode}`, {
|
|
1631
|
-
method,
|
|
1632
|
-
url,
|
|
1633
|
-
statusCode,
|
|
1634
|
-
duration
|
|
1635
|
-
}, {
|
|
1636
|
-
...context,
|
|
1637
|
-
method,
|
|
1638
|
-
url,
|
|
1639
|
-
statusCode,
|
|
1640
|
-
duration
|
|
1641
|
-
});
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Log an authentication event
|
|
1645
|
-
*/
|
|
1646
|
-
async logAuth(action, userId, success = true, context) {
|
|
1647
|
-
const level = success ? "info" : "warn";
|
|
1648
|
-
return this.log(level, "auth", `Authentication ${action}: ${success ? "success" : "failed"}`, {
|
|
1649
|
-
action,
|
|
1650
|
-
success,
|
|
1651
|
-
userId
|
|
1652
|
-
}, {
|
|
1653
|
-
...context,
|
|
1654
|
-
userId,
|
|
1655
|
-
tags: ["authentication", action]
|
|
1656
|
-
});
|
|
1657
|
-
}
|
|
1658
|
-
/**
|
|
1659
|
-
* Log a security event
|
|
1660
|
-
*/
|
|
1661
|
-
async logSecurity(event, severity, context) {
|
|
1662
|
-
const level = severity === "critical" ? "fatal" : severity === "high" ? "error" : "warn";
|
|
1663
|
-
return this.log(level, "security", `Security event: ${event}`, {
|
|
1664
|
-
event,
|
|
1665
|
-
severity
|
|
1666
|
-
}, {
|
|
1667
|
-
...context,
|
|
1668
|
-
tags: ["security", severity]
|
|
1669
|
-
});
|
|
1670
|
-
}
|
|
1671
|
-
/**
|
|
1672
|
-
* Core logging method
|
|
1673
|
-
*/
|
|
1674
|
-
async log(level, category, message, data, context) {
|
|
1675
|
-
if (!this.enabled) return;
|
|
1676
|
-
try {
|
|
1677
|
-
const config = await this.getConfig(category);
|
|
1678
|
-
if (!config || !config.enabled || !this.shouldLog(level, config.level)) {
|
|
1679
|
-
return;
|
|
1680
|
-
}
|
|
1681
|
-
const logEntry = {
|
|
1682
|
-
id: crypto.randomUUID(),
|
|
1683
|
-
level,
|
|
1684
|
-
category,
|
|
1685
|
-
message,
|
|
1686
|
-
data: data ? JSON.stringify(data) : null,
|
|
1687
|
-
userId: context?.userId || null,
|
|
1688
|
-
sessionId: context?.sessionId || null,
|
|
1689
|
-
requestId: context?.requestId || null,
|
|
1690
|
-
ipAddress: context?.ipAddress || null,
|
|
1691
|
-
userAgent: context?.userAgent || null,
|
|
1692
|
-
method: context?.method || null,
|
|
1693
|
-
url: context?.url || null,
|
|
1694
|
-
statusCode: context?.statusCode || null,
|
|
1695
|
-
duration: context?.duration || null,
|
|
1696
|
-
stackTrace: context?.stackTrace || null,
|
|
1697
|
-
tags: context?.tags ? JSON.stringify(context.tags) : null,
|
|
1698
|
-
source: context?.source || null,
|
|
1699
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
1700
|
-
};
|
|
1701
|
-
await this.db.insert(systemLogs).values(logEntry);
|
|
1702
|
-
if (config.maxSize) {
|
|
1703
|
-
await this.cleanupCategory(category, config.maxSize);
|
|
1704
|
-
}
|
|
1705
|
-
} catch (error) {
|
|
1706
|
-
console.error("Logger error:", error);
|
|
1707
|
-
}
|
|
1708
|
-
}
|
|
1709
|
-
/**
|
|
1710
|
-
* Get logs with filtering and pagination
|
|
1711
|
-
*/
|
|
1712
|
-
async getLogs(filter = {}) {
|
|
1713
|
-
try {
|
|
1714
|
-
const conditions = [];
|
|
1715
|
-
if (filter.level && filter.level.length > 0) {
|
|
1716
|
-
conditions.push(drizzleOrm.inArray(systemLogs.level, filter.level));
|
|
1717
|
-
}
|
|
1718
|
-
if (filter.category && filter.category.length > 0) {
|
|
1719
|
-
conditions.push(drizzleOrm.inArray(systemLogs.category, filter.category));
|
|
1720
|
-
}
|
|
1721
|
-
if (filter.userId) {
|
|
1722
|
-
conditions.push(drizzleOrm.eq(systemLogs.userId, filter.userId));
|
|
1723
|
-
}
|
|
1724
|
-
if (filter.source) {
|
|
1725
|
-
conditions.push(drizzleOrm.eq(systemLogs.source, filter.source));
|
|
1726
|
-
}
|
|
1727
|
-
if (filter.search) {
|
|
1728
|
-
conditions.push(
|
|
1729
|
-
drizzleOrm.like(systemLogs.message, `%${filter.search}%`)
|
|
1730
|
-
);
|
|
1731
|
-
}
|
|
1732
|
-
if (filter.startDate) {
|
|
1733
|
-
conditions.push(drizzleOrm.gte(systemLogs.createdAt, filter.startDate));
|
|
1734
|
-
}
|
|
1735
|
-
if (filter.endDate) {
|
|
1736
|
-
conditions.push(drizzleOrm.lte(systemLogs.createdAt, filter.endDate));
|
|
1737
|
-
}
|
|
1738
|
-
const whereClause = conditions.length > 0 ? drizzleOrm.and(...conditions) : void 0;
|
|
1739
|
-
const totalResult = await this.db.select({ count: drizzleOrm.count() }).from(systemLogs).where(whereClause);
|
|
1740
|
-
const total = totalResult[0]?.count || 0;
|
|
1741
|
-
const sortColumn = filter.sortBy === "level" ? systemLogs.level : filter.sortBy === "category" ? systemLogs.category : systemLogs.createdAt;
|
|
1742
|
-
const sortFn = filter.sortOrder === "asc" ? drizzleOrm.asc : drizzleOrm.desc;
|
|
1743
|
-
const logs = await this.db.select().from(systemLogs).where(whereClause).orderBy(sortFn(sortColumn)).limit(filter.limit || 50).offset(filter.offset || 0);
|
|
1744
|
-
return { logs, total };
|
|
1745
|
-
} catch (error) {
|
|
1746
|
-
console.error("Error getting logs:", error);
|
|
1747
|
-
return { logs: [], total: 0 };
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
/**
|
|
1751
|
-
* Get log configuration for a category
|
|
1752
|
-
*/
|
|
1753
|
-
async getConfig(category) {
|
|
1754
|
-
try {
|
|
1755
|
-
const now = Date.now();
|
|
1756
|
-
if (this.configCache.has(category) && now - this.lastConfigRefresh < this.configRefreshInterval) {
|
|
1757
|
-
return this.configCache.get(category) || null;
|
|
1758
|
-
}
|
|
1759
|
-
const configs = await this.db.select().from(logConfig).where(drizzleOrm.eq(logConfig.category, category));
|
|
1760
|
-
const config = configs[0] || null;
|
|
1761
|
-
if (config) {
|
|
1762
|
-
this.configCache.set(category, config);
|
|
1763
|
-
this.lastConfigRefresh = now;
|
|
1764
|
-
}
|
|
1765
|
-
return config;
|
|
1766
|
-
} catch (error) {
|
|
1767
|
-
console.error("Error getting log config:", error);
|
|
1768
|
-
return null;
|
|
1769
|
-
}
|
|
1770
|
-
}
|
|
1771
|
-
/**
|
|
1772
|
-
* Update log configuration
|
|
1773
|
-
*/
|
|
1774
|
-
async updateConfig(category, updates) {
|
|
1775
|
-
try {
|
|
1776
|
-
await this.db.update(logConfig).set({
|
|
1777
|
-
...updates,
|
|
1778
|
-
updatedAt: /* @__PURE__ */ new Date()
|
|
1779
|
-
}).where(drizzleOrm.eq(logConfig.category, category));
|
|
1780
|
-
this.configCache.delete(category);
|
|
1781
|
-
} catch (error) {
|
|
1782
|
-
console.error("Error updating log config:", error);
|
|
1783
|
-
}
|
|
1784
|
-
}
|
|
1785
|
-
/**
|
|
1786
|
-
* Get all log configurations
|
|
1787
|
-
*/
|
|
1788
|
-
async getAllConfigs() {
|
|
1789
|
-
try {
|
|
1790
|
-
return await this.db.select().from(logConfig);
|
|
1791
|
-
} catch (error) {
|
|
1792
|
-
console.error("Error getting log configs:", error);
|
|
1793
|
-
return [];
|
|
1794
|
-
}
|
|
1795
|
-
}
|
|
1796
|
-
/**
|
|
1797
|
-
* Clean up old logs for a category
|
|
1798
|
-
*/
|
|
1799
|
-
async cleanupCategory(category, maxSize) {
|
|
1800
|
-
try {
|
|
1801
|
-
const countResult = await this.db.select({ count: drizzleOrm.count() }).from(systemLogs).where(drizzleOrm.eq(systemLogs.category, category));
|
|
1802
|
-
const currentCount = countResult[0]?.count || 0;
|
|
1803
|
-
if (currentCount > maxSize) {
|
|
1804
|
-
const cutoffLogs = await this.db.select({ createdAt: systemLogs.createdAt }).from(systemLogs).where(drizzleOrm.eq(systemLogs.category, category)).orderBy(drizzleOrm.desc(systemLogs.createdAt)).limit(1).offset(maxSize - 1);
|
|
1805
|
-
if (cutoffLogs[0]) {
|
|
1806
|
-
await this.db.delete(systemLogs).where(
|
|
1807
|
-
drizzleOrm.and(
|
|
1808
|
-
drizzleOrm.eq(systemLogs.category, category),
|
|
1809
|
-
drizzleOrm.lte(systemLogs.createdAt, cutoffLogs[0].createdAt)
|
|
1810
|
-
)
|
|
1811
|
-
);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
} catch (error) {
|
|
1815
|
-
console.error("Error cleaning up logs:", error);
|
|
1816
|
-
}
|
|
1817
|
-
}
|
|
1818
|
-
/**
|
|
1819
|
-
* Clean up logs based on retention policy
|
|
1820
|
-
*/
|
|
1821
|
-
async cleanupByRetention() {
|
|
1822
|
-
try {
|
|
1823
|
-
const configs = await this.getAllConfigs();
|
|
1824
|
-
for (const config of configs) {
|
|
1825
|
-
if (config.retention > 0) {
|
|
1826
|
-
const cutoffDate = /* @__PURE__ */ new Date();
|
|
1827
|
-
cutoffDate.setDate(cutoffDate.getDate() - config.retention);
|
|
1828
|
-
await this.db.delete(systemLogs).where(
|
|
1829
|
-
drizzleOrm.and(
|
|
1830
|
-
drizzleOrm.eq(systemLogs.category, config.category),
|
|
1831
|
-
drizzleOrm.lte(systemLogs.createdAt, cutoffDate)
|
|
1832
|
-
)
|
|
1833
|
-
);
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
} catch (error) {
|
|
1837
|
-
console.error("Error cleaning up logs by retention:", error);
|
|
1838
|
-
}
|
|
1839
|
-
}
|
|
1840
|
-
/**
|
|
1841
|
-
* Check if a log level should be recorded based on configuration
|
|
1842
|
-
*/
|
|
1843
|
-
shouldLog(level, configLevel) {
|
|
1844
|
-
const levels = ["debug", "info", "warn", "error", "fatal"];
|
|
1845
|
-
const levelIndex = levels.indexOf(level);
|
|
1846
|
-
const configLevelIndex = levels.indexOf(configLevel);
|
|
1847
|
-
return levelIndex >= configLevelIndex;
|
|
1848
|
-
}
|
|
1849
|
-
/**
|
|
1850
|
-
* Enable or disable logging
|
|
1851
|
-
*/
|
|
1852
|
-
setEnabled(enabled) {
|
|
1853
|
-
this.enabled = enabled;
|
|
1854
|
-
}
|
|
1855
|
-
/**
|
|
1856
|
-
* Check if logging is enabled
|
|
1857
|
-
*/
|
|
1858
|
-
isEnabled() {
|
|
1859
|
-
return this.enabled;
|
|
1860
|
-
}
|
|
1861
|
-
};
|
|
1862
|
-
var loggerInstance = null;
|
|
1863
|
-
function getLogger(database) {
|
|
1864
|
-
if (!loggerInstance && database) {
|
|
1865
|
-
loggerInstance = new Logger(database);
|
|
1866
|
-
}
|
|
1867
|
-
if (!loggerInstance) {
|
|
1868
|
-
throw new Error("Logger not initialized. Call getLogger with a database instance first.");
|
|
1869
|
-
}
|
|
1870
|
-
return loggerInstance;
|
|
1871
|
-
}
|
|
1872
|
-
function initLogger(database) {
|
|
1873
|
-
loggerInstance = new Logger(database);
|
|
1874
|
-
return loggerInstance;
|
|
1875
|
-
}
|
|
1876
|
-
|
|
1877
980
|
// src/services/plugin-service.ts
|
|
1878
981
|
var PluginService = class {
|
|
1879
982
|
constructor(db) {
|
|
@@ -2357,60 +1460,18 @@ var PluginBootstrapService = class {
|
|
|
2357
1460
|
}
|
|
2358
1461
|
};
|
|
2359
1462
|
|
|
2360
|
-
exports.Logger = Logger;
|
|
2361
1463
|
exports.MigrationService = MigrationService;
|
|
2362
1464
|
exports.PluginBootstrapService = PluginBootstrapService;
|
|
2363
1465
|
exports.PluginService = PluginService;
|
|
2364
|
-
exports.apiTokens = apiTokens;
|
|
2365
1466
|
exports.cleanupRemovedCollections = cleanupRemovedCollections;
|
|
2366
|
-
exports.collections = collections;
|
|
2367
|
-
exports.content = content;
|
|
2368
|
-
exports.contentVersions = contentVersions;
|
|
2369
1467
|
exports.fullCollectionSync = fullCollectionSync;
|
|
2370
1468
|
exports.getAvailableCollectionNames = getAvailableCollectionNames;
|
|
2371
|
-
exports.getLogger = getLogger;
|
|
2372
1469
|
exports.getManagedCollections = getManagedCollections;
|
|
2373
|
-
exports.initLogger = initLogger;
|
|
2374
|
-
exports.insertCollectionSchema = insertCollectionSchema;
|
|
2375
|
-
exports.insertContentSchema = insertContentSchema;
|
|
2376
|
-
exports.insertLogConfigSchema = insertLogConfigSchema;
|
|
2377
|
-
exports.insertMediaSchema = insertMediaSchema;
|
|
2378
|
-
exports.insertPluginActivityLogSchema = insertPluginActivityLogSchema;
|
|
2379
|
-
exports.insertPluginAssetSchema = insertPluginAssetSchema;
|
|
2380
|
-
exports.insertPluginHookSchema = insertPluginHookSchema;
|
|
2381
|
-
exports.insertPluginRouteSchema = insertPluginRouteSchema;
|
|
2382
|
-
exports.insertPluginSchema = insertPluginSchema;
|
|
2383
|
-
exports.insertSystemLogSchema = insertSystemLogSchema;
|
|
2384
|
-
exports.insertUserSchema = insertUserSchema;
|
|
2385
|
-
exports.insertWorkflowHistorySchema = insertWorkflowHistorySchema;
|
|
2386
1470
|
exports.isCollectionManaged = isCollectionManaged;
|
|
2387
1471
|
exports.loadCollectionConfig = loadCollectionConfig;
|
|
2388
1472
|
exports.loadCollectionConfigs = loadCollectionConfigs;
|
|
2389
|
-
exports.logConfig = logConfig;
|
|
2390
|
-
exports.media = media;
|
|
2391
|
-
exports.pluginActivityLog = pluginActivityLog;
|
|
2392
|
-
exports.pluginAssets = pluginAssets;
|
|
2393
|
-
exports.pluginHooks = pluginHooks;
|
|
2394
|
-
exports.pluginRoutes = pluginRoutes;
|
|
2395
|
-
exports.plugins = plugins;
|
|
2396
|
-
exports.schema_exports = schema_exports;
|
|
2397
|
-
exports.selectCollectionSchema = selectCollectionSchema;
|
|
2398
|
-
exports.selectContentSchema = selectContentSchema;
|
|
2399
|
-
exports.selectLogConfigSchema = selectLogConfigSchema;
|
|
2400
|
-
exports.selectMediaSchema = selectMediaSchema;
|
|
2401
|
-
exports.selectPluginActivityLogSchema = selectPluginActivityLogSchema;
|
|
2402
|
-
exports.selectPluginAssetSchema = selectPluginAssetSchema;
|
|
2403
|
-
exports.selectPluginHookSchema = selectPluginHookSchema;
|
|
2404
|
-
exports.selectPluginRouteSchema = selectPluginRouteSchema;
|
|
2405
|
-
exports.selectPluginSchema = selectPluginSchema;
|
|
2406
|
-
exports.selectSystemLogSchema = selectSystemLogSchema;
|
|
2407
|
-
exports.selectUserSchema = selectUserSchema;
|
|
2408
|
-
exports.selectWorkflowHistorySchema = selectWorkflowHistorySchema;
|
|
2409
1473
|
exports.syncCollection = syncCollection;
|
|
2410
1474
|
exports.syncCollections = syncCollections;
|
|
2411
|
-
exports.systemLogs = systemLogs;
|
|
2412
|
-
exports.users = users;
|
|
2413
1475
|
exports.validateCollectionConfig = validateCollectionConfig;
|
|
2414
|
-
|
|
2415
|
-
//# sourceMappingURL=chunk-
|
|
2416
|
-
//# sourceMappingURL=chunk-RNR4HA23.cjs.map
|
|
1476
|
+
//# sourceMappingURL=chunk-LEG4KNFP.cjs.map
|
|
1477
|
+
//# sourceMappingURL=chunk-LEG4KNFP.cjs.map
|