@sonicjs-cms/core 1.0.0-alpha.1 → 1.0.0-alpha.2
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-24PWAFUT.cjs +776 -0
- package/dist/chunk-24PWAFUT.cjs.map +1 -0
- package/dist/chunk-4URGXJP7.js +3 -0
- package/dist/{chunk-PZ5AY32C.js.map → chunk-4URGXJP7.js.map} +1 -1
- package/dist/chunk-ALTMI5Y2.cjs +4 -0
- package/dist/{chunk-Q7SFCCGT.cjs.map → chunk-ALTMI5Y2.cjs.map} +1 -1
- package/dist/chunk-CXZDAR6S.js +2360 -0
- package/dist/chunk-CXZDAR6S.js.map +1 -0
- package/dist/chunk-EMMSS5I5.cjs +37 -0
- package/dist/chunk-EMMSS5I5.cjs.map +1 -0
- package/dist/chunk-G3PMV62Z.js +33 -0
- package/dist/chunk-G3PMV62Z.js.map +1 -0
- package/dist/chunk-L3NXO7Y4.cjs +3093 -0
- package/dist/chunk-L3NXO7Y4.cjs.map +1 -0
- package/dist/chunk-NRSL6BQI.js +3086 -0
- package/dist/chunk-NRSL6BQI.js.map +1 -0
- package/dist/chunk-PTQZ5FEI.js +755 -0
- package/dist/chunk-PTQZ5FEI.js.map +1 -0
- package/dist/chunk-WJ7QYVR2.cjs +2416 -0
- package/dist/chunk-WJ7QYVR2.cjs.map +1 -0
- package/dist/collection-config-FLlGtsh9.d.cts +107 -0
- package/dist/collection-config-FLlGtsh9.d.ts +107 -0
- package/dist/index-BlsY5XNH.d.ts +8333 -0
- package/dist/index-D45jaIlr.d.cts +8333 -0
- package/dist/index.cjs +327 -630
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -7961
- package/dist/index.d.ts +13 -7961
- package/dist/index.js +8 -592
- package/dist/index.js.map +1 -1
- package/dist/middleware.cjs +84 -4
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.d.cts +203 -5
- package/dist/middleware.d.ts +203 -5
- package/dist/middleware.js +3 -6
- package/dist/middleware.js.map +1 -1
- package/dist/plugin-UzmDImQc.d.cts +357 -0
- package/dist/plugin-UzmDImQc.d.ts +357 -0
- package/dist/plugins.cjs +28 -4
- package/dist/plugins.cjs.map +1 -1
- package/dist/plugins.d.cts +326 -4
- package/dist/plugins.d.ts +326 -4
- package/dist/plugins.js +3 -6
- package/dist/plugins.js.map +1 -1
- package/dist/routes.cjs +1 -1
- package/dist/routes.js +1 -1
- package/dist/services.cjs +68 -4
- package/dist/services.cjs.map +1 -1
- package/dist/services.d.cts +5 -8
- package/dist/services.d.ts +5 -8
- package/dist/services.js +3 -6
- package/dist/services.js.map +1 -1
- package/dist/templates.cjs +1 -1
- package/dist/templates.js +1 -1
- package/dist/types.cjs +1 -1
- package/dist/types.d.cts +6 -462
- package/dist/types.d.ts +6 -462
- package/dist/types.js +1 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-PZ5AY32C.js +0 -9
- package/dist/chunk-Q7SFCCGT.cjs +0 -11
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import './chunk-4URGXJP7.js';
|
|
2
|
+
export { AuthManager, PermissionManager, bootstrapMiddleware, cacheHeaders, compressionMiddleware, detailedLoggingMiddleware, getActivePlugins, isPluginActive, logActivity, loggingMiddleware, optionalAuth, performanceLoggingMiddleware, requireActivePlugin, requireActivePlugins, requireAnyPermission, requireAuth, requirePermission, requireRole, securityHeaders, securityLoggingMiddleware } from './chunk-PTQZ5FEI.js';
|
|
3
|
+
import { schema_exports } from './chunk-CXZDAR6S.js';
|
|
4
|
+
export { Logger, MigrationService, PluginBootstrapService, PluginService as PluginServiceClass, apiTokens, cleanupRemovedCollections, collections, content, contentVersions, fullCollectionSync, getAvailableCollectionNames, getLogger, getManagedCollections, initLogger, insertCollectionSchema, insertContentSchema, insertLogConfigSchema, insertMediaSchema, insertPluginActivityLogSchema, insertPluginAssetSchema, insertPluginHookSchema, insertPluginRouteSchema, insertPluginSchema, insertSystemLogSchema, insertUserSchema, insertWorkflowHistorySchema, isCollectionManaged, loadCollectionConfig, loadCollectionConfigs, logConfig, media, pluginActivityLog, pluginAssets, pluginHooks, pluginRoutes, plugins, selectCollectionSchema, selectContentSchema, selectLogConfigSchema, selectMediaSchema, selectPluginActivityLogSchema, selectPluginAssetSchema, selectPluginHookSchema, selectPluginRouteSchema, selectPluginSchema, selectSystemLogSchema, selectUserSchema, selectWorkflowHistorySchema, syncCollection, syncCollections, systemLogs, users, validateCollectionConfig, workflowHistory } from './chunk-CXZDAR6S.js';
|
|
5
|
+
export { HookSystemImpl, HookUtils, PluginManager as PluginManagerClass, PluginRegistryImpl, PluginValidator as PluginValidatorClass, ScopedHookSystem as ScopedHookSystemClass } from './chunk-NRSL6BQI.js';
|
|
1
6
|
export { QueryFilterBuilder, TemplateRenderer, buildQuery, escapeHtml, metricsTracker, renderTemplate, sanitizeInput, sanitizeObject, templateRenderer } from './chunk-JIINOD2W.js';
|
|
2
7
|
export { HOOKS } from './chunk-LOUJRBXV.js';
|
|
3
|
-
import
|
|
8
|
+
import './chunk-G3PMV62Z.js';
|
|
4
9
|
import { Hono } from 'hono';
|
|
5
10
|
import { drizzle } from 'drizzle-orm/d1';
|
|
6
|
-
import { sqliteTable, integer, text } from 'drizzle-orm/sqlite-core';
|
|
7
|
-
import { z } from 'zod/v4';
|
|
8
|
-
import { getTableColumns, getViewSelectedFields, isTable, is, Column, SQL, isView } from 'drizzle-orm';
|
|
9
11
|
|
|
10
12
|
function createSonicJSApp(config = {}) {
|
|
11
13
|
const app = new Hono();
|
|
@@ -62,599 +64,13 @@ function setupCoreMiddleware(_app) {
|
|
|
62
64
|
function setupCoreRoutes(_app) {
|
|
63
65
|
console.warn("setupCoreRoutes is deprecated. Use createSonicJSApp() instead.");
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
// src/db/schema.ts
|
|
67
|
-
var schema_exports = {};
|
|
68
|
-
__export(schema_exports, {
|
|
69
|
-
apiTokens: () => apiTokens,
|
|
70
|
-
collections: () => collections,
|
|
71
|
-
content: () => content,
|
|
72
|
-
contentVersions: () => contentVersions,
|
|
73
|
-
insertCollectionSchema: () => insertCollectionSchema,
|
|
74
|
-
insertContentSchema: () => insertContentSchema,
|
|
75
|
-
insertLogConfigSchema: () => insertLogConfigSchema,
|
|
76
|
-
insertMediaSchema: () => insertMediaSchema,
|
|
77
|
-
insertPluginActivityLogSchema: () => insertPluginActivityLogSchema,
|
|
78
|
-
insertPluginAssetSchema: () => insertPluginAssetSchema,
|
|
79
|
-
insertPluginHookSchema: () => insertPluginHookSchema,
|
|
80
|
-
insertPluginRouteSchema: () => insertPluginRouteSchema,
|
|
81
|
-
insertPluginSchema: () => insertPluginSchema,
|
|
82
|
-
insertSystemLogSchema: () => insertSystemLogSchema,
|
|
83
|
-
insertUserSchema: () => insertUserSchema,
|
|
84
|
-
insertWorkflowHistorySchema: () => insertWorkflowHistorySchema,
|
|
85
|
-
logConfig: () => logConfig,
|
|
86
|
-
media: () => media,
|
|
87
|
-
pluginActivityLog: () => pluginActivityLog,
|
|
88
|
-
pluginAssets: () => pluginAssets,
|
|
89
|
-
pluginHooks: () => pluginHooks,
|
|
90
|
-
pluginRoutes: () => pluginRoutes,
|
|
91
|
-
plugins: () => plugins,
|
|
92
|
-
selectCollectionSchema: () => selectCollectionSchema,
|
|
93
|
-
selectContentSchema: () => selectContentSchema,
|
|
94
|
-
selectLogConfigSchema: () => selectLogConfigSchema,
|
|
95
|
-
selectMediaSchema: () => selectMediaSchema,
|
|
96
|
-
selectPluginActivityLogSchema: () => selectPluginActivityLogSchema,
|
|
97
|
-
selectPluginAssetSchema: () => selectPluginAssetSchema,
|
|
98
|
-
selectPluginHookSchema: () => selectPluginHookSchema,
|
|
99
|
-
selectPluginRouteSchema: () => selectPluginRouteSchema,
|
|
100
|
-
selectPluginSchema: () => selectPluginSchema,
|
|
101
|
-
selectSystemLogSchema: () => selectSystemLogSchema,
|
|
102
|
-
selectUserSchema: () => selectUserSchema,
|
|
103
|
-
selectWorkflowHistorySchema: () => selectWorkflowHistorySchema,
|
|
104
|
-
systemLogs: () => systemLogs,
|
|
105
|
-
users: () => users,
|
|
106
|
-
workflowHistory: () => workflowHistory
|
|
107
|
-
});
|
|
108
|
-
var CONSTANTS = {
|
|
109
|
-
INT8_MIN: -128,
|
|
110
|
-
INT8_MAX: 127,
|
|
111
|
-
INT8_UNSIGNED_MAX: 255,
|
|
112
|
-
INT16_MIN: -32768,
|
|
113
|
-
INT16_MAX: 32767,
|
|
114
|
-
INT16_UNSIGNED_MAX: 65535,
|
|
115
|
-
INT24_MIN: -8388608,
|
|
116
|
-
INT24_MAX: 8388607,
|
|
117
|
-
INT24_UNSIGNED_MAX: 16777215,
|
|
118
|
-
INT32_MIN: -2147483648,
|
|
119
|
-
INT32_MAX: 2147483647,
|
|
120
|
-
INT32_UNSIGNED_MAX: 4294967295,
|
|
121
|
-
INT48_MIN: -140737488355328,
|
|
122
|
-
INT48_MAX: 140737488355327,
|
|
123
|
-
INT48_UNSIGNED_MAX: 281474976710655,
|
|
124
|
-
INT64_MIN: -9223372036854775808n,
|
|
125
|
-
INT64_MAX: 9223372036854775807n,
|
|
126
|
-
INT64_UNSIGNED_MAX: 18446744073709551615n
|
|
127
|
-
};
|
|
128
|
-
function isColumnType(column, columnTypes) {
|
|
129
|
-
return columnTypes.includes(column.columnType);
|
|
130
|
-
}
|
|
131
|
-
function isWithEnum(column) {
|
|
132
|
-
return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
|
|
133
|
-
}
|
|
134
|
-
var isPgEnum = isWithEnum;
|
|
135
|
-
var literalSchema = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
136
|
-
var jsonSchema = z.union([
|
|
137
|
-
literalSchema,
|
|
138
|
-
z.record(z.string(), z.any()),
|
|
139
|
-
z.array(z.any())
|
|
140
|
-
]);
|
|
141
|
-
var bufferSchema = z.custom((v) => v instanceof Buffer);
|
|
142
|
-
function columnToSchema(column, factory) {
|
|
143
|
-
const z$1 = z;
|
|
144
|
-
const coerce = {};
|
|
145
|
-
let schema;
|
|
146
|
-
if (isWithEnum(column)) {
|
|
147
|
-
schema = column.enumValues.length ? z$1.enum(column.enumValues) : z$1.string();
|
|
148
|
-
}
|
|
149
|
-
if (!schema) {
|
|
150
|
-
if (isColumnType(column, ["PgGeometry", "PgPointTuple"])) {
|
|
151
|
-
schema = z$1.tuple([z$1.number(), z$1.number()]);
|
|
152
|
-
} else if (isColumnType(column, ["PgGeometryObject", "PgPointObject"])) {
|
|
153
|
-
schema = z$1.object({ x: z$1.number(), y: z$1.number() });
|
|
154
|
-
} else if (isColumnType(column, ["PgHalfVector", "PgVector"])) {
|
|
155
|
-
schema = z$1.array(z$1.number());
|
|
156
|
-
schema = column.dimensions ? schema.length(column.dimensions) : schema;
|
|
157
|
-
} else if (isColumnType(column, ["PgLine"])) {
|
|
158
|
-
schema = z$1.tuple([z$1.number(), z$1.number(), z$1.number()]);
|
|
159
|
-
} else if (isColumnType(column, ["PgLineABC"])) {
|
|
160
|
-
schema = z$1.object({
|
|
161
|
-
a: z$1.number(),
|
|
162
|
-
b: z$1.number(),
|
|
163
|
-
c: z$1.number()
|
|
164
|
-
});
|
|
165
|
-
} else if (isColumnType(column, ["PgArray"])) {
|
|
166
|
-
schema = z$1.array(columnToSchema(column.baseColumn));
|
|
167
|
-
schema = column.size ? schema.length(column.size) : schema;
|
|
168
|
-
} else if (column.dataType === "array") {
|
|
169
|
-
schema = z$1.array(z$1.any());
|
|
170
|
-
} else if (column.dataType === "number") {
|
|
171
|
-
schema = numberColumnToSchema(column, z$1, coerce);
|
|
172
|
-
} else if (column.dataType === "bigint") {
|
|
173
|
-
schema = bigintColumnToSchema(column, z$1, coerce);
|
|
174
|
-
} else if (column.dataType === "boolean") {
|
|
175
|
-
schema = coerce === true || coerce.boolean ? z$1.coerce.boolean() : z$1.boolean();
|
|
176
|
-
} else if (column.dataType === "date") {
|
|
177
|
-
schema = coerce === true || coerce.date ? z$1.coerce.date() : z$1.date();
|
|
178
|
-
} else if (column.dataType === "string") {
|
|
179
|
-
schema = stringColumnToSchema(column, z$1, coerce);
|
|
180
|
-
} else if (column.dataType === "json") {
|
|
181
|
-
schema = jsonSchema;
|
|
182
|
-
} else if (column.dataType === "custom") {
|
|
183
|
-
schema = z$1.any();
|
|
184
|
-
} else if (column.dataType === "buffer") {
|
|
185
|
-
schema = bufferSchema;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (!schema) {
|
|
189
|
-
schema = z$1.any();
|
|
190
|
-
}
|
|
191
|
-
return schema;
|
|
192
|
-
}
|
|
193
|
-
function numberColumnToSchema(column, z2, coerce) {
|
|
194
|
-
let unsigned = column.getSQLType().includes("unsigned");
|
|
195
|
-
let min;
|
|
196
|
-
let max;
|
|
197
|
-
let integer2 = false;
|
|
198
|
-
if (isColumnType(column, ["MySqlTinyInt", "SingleStoreTinyInt"])) {
|
|
199
|
-
min = unsigned ? 0 : CONSTANTS.INT8_MIN;
|
|
200
|
-
max = unsigned ? CONSTANTS.INT8_UNSIGNED_MAX : CONSTANTS.INT8_MAX;
|
|
201
|
-
integer2 = true;
|
|
202
|
-
} else if (isColumnType(column, [
|
|
203
|
-
"PgSmallInt",
|
|
204
|
-
"PgSmallSerial",
|
|
205
|
-
"MySqlSmallInt",
|
|
206
|
-
"SingleStoreSmallInt"
|
|
207
|
-
])) {
|
|
208
|
-
min = unsigned ? 0 : CONSTANTS.INT16_MIN;
|
|
209
|
-
max = unsigned ? CONSTANTS.INT16_UNSIGNED_MAX : CONSTANTS.INT16_MAX;
|
|
210
|
-
integer2 = true;
|
|
211
|
-
} else if (isColumnType(column, [
|
|
212
|
-
"PgReal",
|
|
213
|
-
"MySqlFloat",
|
|
214
|
-
"MySqlMediumInt",
|
|
215
|
-
"SingleStoreMediumInt",
|
|
216
|
-
"SingleStoreFloat"
|
|
217
|
-
])) {
|
|
218
|
-
min = unsigned ? 0 : CONSTANTS.INT24_MIN;
|
|
219
|
-
max = unsigned ? CONSTANTS.INT24_UNSIGNED_MAX : CONSTANTS.INT24_MAX;
|
|
220
|
-
integer2 = isColumnType(column, ["MySqlMediumInt", "SingleStoreMediumInt"]);
|
|
221
|
-
} else if (isColumnType(column, [
|
|
222
|
-
"PgInteger",
|
|
223
|
-
"PgSerial",
|
|
224
|
-
"MySqlInt",
|
|
225
|
-
"SingleStoreInt"
|
|
226
|
-
])) {
|
|
227
|
-
min = unsigned ? 0 : CONSTANTS.INT32_MIN;
|
|
228
|
-
max = unsigned ? CONSTANTS.INT32_UNSIGNED_MAX : CONSTANTS.INT32_MAX;
|
|
229
|
-
integer2 = true;
|
|
230
|
-
} else if (isColumnType(column, [
|
|
231
|
-
"PgDoublePrecision",
|
|
232
|
-
"MySqlReal",
|
|
233
|
-
"MySqlDouble",
|
|
234
|
-
"SingleStoreReal",
|
|
235
|
-
"SingleStoreDouble",
|
|
236
|
-
"SQLiteReal"
|
|
237
|
-
])) {
|
|
238
|
-
min = unsigned ? 0 : CONSTANTS.INT48_MIN;
|
|
239
|
-
max = unsigned ? CONSTANTS.INT48_UNSIGNED_MAX : CONSTANTS.INT48_MAX;
|
|
240
|
-
} else if (isColumnType(column, [
|
|
241
|
-
"PgBigInt53",
|
|
242
|
-
"PgBigSerial53",
|
|
243
|
-
"MySqlBigInt53",
|
|
244
|
-
"MySqlSerial",
|
|
245
|
-
"SingleStoreBigInt53",
|
|
246
|
-
"SingleStoreSerial",
|
|
247
|
-
"SQLiteInteger"
|
|
248
|
-
])) {
|
|
249
|
-
unsigned = unsigned || isColumnType(column, ["MySqlSerial", "SingleStoreSerial"]);
|
|
250
|
-
min = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
|
|
251
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
252
|
-
integer2 = true;
|
|
253
|
-
} else if (isColumnType(column, ["MySqlYear", "SingleStoreYear"])) {
|
|
254
|
-
min = 1901;
|
|
255
|
-
max = 2155;
|
|
256
|
-
integer2 = true;
|
|
257
|
-
} else {
|
|
258
|
-
min = Number.MIN_SAFE_INTEGER;
|
|
259
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
260
|
-
}
|
|
261
|
-
let schema = coerce === true || coerce?.number ? integer2 ? z2.coerce.number() : z2.coerce.number().int() : integer2 ? z2.int() : z2.number();
|
|
262
|
-
schema = schema.gte(min).lte(max);
|
|
263
|
-
return schema;
|
|
264
|
-
}
|
|
265
|
-
function bigintColumnToSchema(column, z2, coerce) {
|
|
266
|
-
const unsigned = column.getSQLType().includes("unsigned");
|
|
267
|
-
const min = unsigned ? 0n : CONSTANTS.INT64_MIN;
|
|
268
|
-
const max = unsigned ? CONSTANTS.INT64_UNSIGNED_MAX : CONSTANTS.INT64_MAX;
|
|
269
|
-
const schema = coerce === true || coerce?.bigint ? z2.coerce.bigint() : z2.bigint();
|
|
270
|
-
return schema.gte(min).lte(max);
|
|
271
|
-
}
|
|
272
|
-
function stringColumnToSchema(column, z2, coerce) {
|
|
273
|
-
if (isColumnType(column, ["PgUUID"])) {
|
|
274
|
-
return z2.uuid();
|
|
275
|
-
}
|
|
276
|
-
let max;
|
|
277
|
-
let regex;
|
|
278
|
-
let fixed = false;
|
|
279
|
-
if (isColumnType(column, ["PgVarchar", "SQLiteText"])) {
|
|
280
|
-
max = column.length;
|
|
281
|
-
} else if (isColumnType(column, ["MySqlVarChar", "SingleStoreVarChar"])) {
|
|
282
|
-
max = column.length ?? CONSTANTS.INT16_UNSIGNED_MAX;
|
|
283
|
-
} else if (isColumnType(column, ["MySqlText", "SingleStoreText"])) {
|
|
284
|
-
if (column.textType === "longtext") {
|
|
285
|
-
max = CONSTANTS.INT32_UNSIGNED_MAX;
|
|
286
|
-
} else if (column.textType === "mediumtext") {
|
|
287
|
-
max = CONSTANTS.INT24_UNSIGNED_MAX;
|
|
288
|
-
} else if (column.textType === "text") {
|
|
289
|
-
max = CONSTANTS.INT16_UNSIGNED_MAX;
|
|
290
|
-
} else {
|
|
291
|
-
max = CONSTANTS.INT8_UNSIGNED_MAX;
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (isColumnType(column, [
|
|
295
|
-
"PgChar",
|
|
296
|
-
"MySqlChar",
|
|
297
|
-
"SingleStoreChar"
|
|
298
|
-
])) {
|
|
299
|
-
max = column.length;
|
|
300
|
-
fixed = true;
|
|
301
|
-
}
|
|
302
|
-
if (isColumnType(column, ["PgBinaryVector"])) {
|
|
303
|
-
regex = /^[01]+$/;
|
|
304
|
-
max = column.dimensions;
|
|
305
|
-
}
|
|
306
|
-
let schema = coerce === true || coerce?.string ? z2.coerce.string() : z2.string();
|
|
307
|
-
schema = regex ? schema.regex(regex) : schema;
|
|
308
|
-
return max && fixed ? schema.length(max) : max ? schema.max(max) : schema;
|
|
309
|
-
}
|
|
310
|
-
function getColumns(tableLike) {
|
|
311
|
-
return isTable(tableLike) ? getTableColumns(tableLike) : getViewSelectedFields(tableLike);
|
|
312
|
-
}
|
|
313
|
-
function handleColumns(columns, refinements, conditions, factory) {
|
|
314
|
-
const columnSchemas = {};
|
|
315
|
-
for (const [key, selected] of Object.entries(columns)) {
|
|
316
|
-
if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === "object") {
|
|
317
|
-
const columns2 = isTable(selected) || isView(selected) ? getColumns(selected) : selected;
|
|
318
|
-
columnSchemas[key] = handleColumns(columns2, refinements[key] ?? {}, conditions);
|
|
319
|
-
continue;
|
|
320
|
-
}
|
|
321
|
-
const refinement = refinements[key];
|
|
322
|
-
if (refinement !== void 0 && typeof refinement !== "function") {
|
|
323
|
-
columnSchemas[key] = refinement;
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
const column = is(selected, Column) ? selected : void 0;
|
|
327
|
-
const schema = column ? columnToSchema(column) : z.any();
|
|
328
|
-
const refined = typeof refinement === "function" ? refinement(schema) : schema;
|
|
329
|
-
if (conditions.never(column)) {
|
|
330
|
-
continue;
|
|
331
|
-
} else {
|
|
332
|
-
columnSchemas[key] = refined;
|
|
333
|
-
}
|
|
334
|
-
if (column) {
|
|
335
|
-
if (conditions.nullable(column)) {
|
|
336
|
-
columnSchemas[key] = columnSchemas[key].nullable();
|
|
337
|
-
}
|
|
338
|
-
if (conditions.optional(column)) {
|
|
339
|
-
columnSchemas[key] = columnSchemas[key].optional();
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
return z.object(columnSchemas);
|
|
344
|
-
}
|
|
345
|
-
function handleEnum(enum_, factory) {
|
|
346
|
-
const zod = z;
|
|
347
|
-
return zod.enum(enum_.enumValues);
|
|
348
|
-
}
|
|
349
|
-
var selectConditions = {
|
|
350
|
-
never: () => false,
|
|
351
|
-
optional: () => false,
|
|
352
|
-
nullable: (column) => !column.notNull
|
|
353
|
-
};
|
|
354
|
-
var insertConditions = {
|
|
355
|
-
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always",
|
|
356
|
-
optional: (column) => !column.notNull || column.notNull && column.hasDefault,
|
|
357
|
-
nullable: (column) => !column.notNull
|
|
358
|
-
};
|
|
359
|
-
var createSelectSchema = (entity, refine) => {
|
|
360
|
-
if (isPgEnum(entity)) {
|
|
361
|
-
return handleEnum(entity);
|
|
362
|
-
}
|
|
363
|
-
const columns = getColumns(entity);
|
|
364
|
-
return handleColumns(columns, {}, selectConditions);
|
|
365
|
-
};
|
|
366
|
-
var createInsertSchema = (entity, refine) => {
|
|
367
|
-
const columns = getColumns(entity);
|
|
368
|
-
return handleColumns(columns, refine ?? {}, insertConditions);
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
// src/db/schema.ts
|
|
372
|
-
var users = sqliteTable("users", {
|
|
373
|
-
id: text("id").primaryKey(),
|
|
374
|
-
email: text("email").notNull().unique(),
|
|
375
|
-
username: text("username").notNull().unique(),
|
|
376
|
-
firstName: text("first_name").notNull(),
|
|
377
|
-
lastName: text("last_name").notNull(),
|
|
378
|
-
passwordHash: text("password_hash"),
|
|
379
|
-
// Hashed password, nullable for OAuth users
|
|
380
|
-
role: text("role").notNull().default("viewer"),
|
|
381
|
-
// 'admin', 'editor', 'author', 'viewer'
|
|
382
|
-
avatar: text("avatar"),
|
|
383
|
-
isActive: integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
384
|
-
lastLoginAt: integer("last_login_at"),
|
|
385
|
-
createdAt: integer("created_at").notNull(),
|
|
386
|
-
updatedAt: integer("updated_at").notNull()
|
|
387
|
-
});
|
|
388
|
-
var collections = sqliteTable("collections", {
|
|
389
|
-
id: text("id").primaryKey(),
|
|
390
|
-
name: text("name").notNull().unique(),
|
|
391
|
-
displayName: text("display_name").notNull(),
|
|
392
|
-
description: text("description"),
|
|
393
|
-
schema: text("schema", { mode: "json" }).notNull(),
|
|
394
|
-
// JSON schema definition
|
|
395
|
-
isActive: integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
396
|
-
managed: integer("managed", { mode: "boolean" }).notNull().default(false),
|
|
397
|
-
// Config-managed collections cannot be edited in UI
|
|
398
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
399
|
-
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
400
|
-
});
|
|
401
|
-
var content = sqliteTable("content", {
|
|
402
|
-
id: text("id").primaryKey(),
|
|
403
|
-
collectionId: text("collection_id").notNull().references(() => collections.id),
|
|
404
|
-
slug: text("slug").notNull(),
|
|
405
|
-
title: text("title").notNull(),
|
|
406
|
-
data: text("data", { mode: "json" }).notNull(),
|
|
407
|
-
// JSON content data
|
|
408
|
-
status: text("status").notNull().default("draft"),
|
|
409
|
-
// 'draft', 'published', 'archived'
|
|
410
|
-
publishedAt: integer("published_at", { mode: "timestamp" }),
|
|
411
|
-
authorId: text("author_id").notNull().references(() => users.id),
|
|
412
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
413
|
-
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
414
|
-
});
|
|
415
|
-
var contentVersions = sqliteTable("content_versions", {
|
|
416
|
-
id: text("id").primaryKey(),
|
|
417
|
-
contentId: text("content_id").notNull().references(() => content.id),
|
|
418
|
-
version: integer("version").notNull(),
|
|
419
|
-
data: text("data", { mode: "json" }).notNull(),
|
|
420
|
-
authorId: text("author_id").notNull().references(() => users.id),
|
|
421
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
422
|
-
});
|
|
423
|
-
var media = sqliteTable("media", {
|
|
424
|
-
id: text("id").primaryKey(),
|
|
425
|
-
filename: text("filename").notNull(),
|
|
426
|
-
originalName: text("original_name").notNull(),
|
|
427
|
-
mimeType: text("mime_type").notNull(),
|
|
428
|
-
size: integer("size").notNull(),
|
|
429
|
-
width: integer("width"),
|
|
430
|
-
height: integer("height"),
|
|
431
|
-
folder: text("folder").notNull().default("uploads"),
|
|
432
|
-
r2Key: text("r2_key").notNull(),
|
|
433
|
-
// R2 storage key
|
|
434
|
-
publicUrl: text("public_url").notNull(),
|
|
435
|
-
// CDN URL
|
|
436
|
-
thumbnailUrl: text("thumbnail_url"),
|
|
437
|
-
alt: text("alt"),
|
|
438
|
-
caption: text("caption"),
|
|
439
|
-
tags: text("tags", { mode: "json" }),
|
|
440
|
-
// JSON array of tags
|
|
441
|
-
uploadedBy: text("uploaded_by").notNull().references(() => users.id),
|
|
442
|
-
uploadedAt: integer("uploaded_at").notNull(),
|
|
443
|
-
updatedAt: integer("updated_at"),
|
|
444
|
-
publishedAt: integer("published_at"),
|
|
445
|
-
scheduledAt: integer("scheduled_at"),
|
|
446
|
-
archivedAt: integer("archived_at"),
|
|
447
|
-
deletedAt: integer("deleted_at")
|
|
448
|
-
});
|
|
449
|
-
var apiTokens = sqliteTable("api_tokens", {
|
|
450
|
-
id: text("id").primaryKey(),
|
|
451
|
-
name: text("name").notNull(),
|
|
452
|
-
token: text("token").notNull().unique(),
|
|
453
|
-
userId: text("user_id").notNull().references(() => users.id),
|
|
454
|
-
permissions: text("permissions", { mode: "json" }).notNull(),
|
|
455
|
-
// Array of permissions
|
|
456
|
-
expiresAt: integer("expires_at", { mode: "timestamp" }),
|
|
457
|
-
lastUsedAt: integer("last_used_at", { mode: "timestamp" }),
|
|
458
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
459
|
-
});
|
|
460
|
-
var workflowHistory = sqliteTable("workflow_history", {
|
|
461
|
-
id: text("id").primaryKey(),
|
|
462
|
-
contentId: text("content_id").notNull().references(() => content.id),
|
|
463
|
-
action: text("action").notNull(),
|
|
464
|
-
fromStatus: text("from_status").notNull(),
|
|
465
|
-
toStatus: text("to_status").notNull(),
|
|
466
|
-
userId: text("user_id").notNull().references(() => users.id),
|
|
467
|
-
comment: text("comment"),
|
|
468
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
469
|
-
});
|
|
470
|
-
var plugins = sqliteTable("plugins", {
|
|
471
|
-
id: text("id").primaryKey(),
|
|
472
|
-
name: text("name").notNull().unique(),
|
|
473
|
-
displayName: text("display_name").notNull(),
|
|
474
|
-
description: text("description"),
|
|
475
|
-
version: text("version").notNull(),
|
|
476
|
-
author: text("author").notNull(),
|
|
477
|
-
category: text("category").notNull(),
|
|
478
|
-
icon: text("icon"),
|
|
479
|
-
status: text("status").notNull().default("inactive"),
|
|
480
|
-
// 'active', 'inactive', 'error'
|
|
481
|
-
isCore: integer("is_core", { mode: "boolean" }).notNull().default(false),
|
|
482
|
-
settings: text("settings", { mode: "json" }),
|
|
483
|
-
permissions: text("permissions", { mode: "json" }),
|
|
484
|
-
dependencies: text("dependencies", { mode: "json" }),
|
|
485
|
-
downloadCount: integer("download_count").notNull().default(0),
|
|
486
|
-
rating: integer("rating").notNull().default(0),
|
|
487
|
-
installedAt: integer("installed_at").notNull(),
|
|
488
|
-
activatedAt: integer("activated_at"),
|
|
489
|
-
lastUpdated: integer("last_updated").notNull(),
|
|
490
|
-
errorMessage: text("error_message"),
|
|
491
|
-
createdAt: integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3)),
|
|
492
|
-
updatedAt: integer("updated_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
493
|
-
});
|
|
494
|
-
var pluginHooks = sqliteTable("plugin_hooks", {
|
|
495
|
-
id: text("id").primaryKey(),
|
|
496
|
-
pluginId: text("plugin_id").notNull().references(() => plugins.id),
|
|
497
|
-
hookName: text("hook_name").notNull(),
|
|
498
|
-
handlerName: text("handler_name").notNull(),
|
|
499
|
-
priority: integer("priority").notNull().default(10),
|
|
500
|
-
isActive: integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
501
|
-
createdAt: integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
502
|
-
});
|
|
503
|
-
var pluginRoutes = sqliteTable("plugin_routes", {
|
|
504
|
-
id: text("id").primaryKey(),
|
|
505
|
-
pluginId: text("plugin_id").notNull().references(() => plugins.id),
|
|
506
|
-
path: text("path").notNull(),
|
|
507
|
-
method: text("method").notNull(),
|
|
508
|
-
handlerName: text("handler_name").notNull(),
|
|
509
|
-
middleware: text("middleware", { mode: "json" }),
|
|
510
|
-
isActive: integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
511
|
-
createdAt: integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
512
|
-
});
|
|
513
|
-
var pluginAssets = sqliteTable("plugin_assets", {
|
|
514
|
-
id: text("id").primaryKey(),
|
|
515
|
-
pluginId: text("plugin_id").notNull().references(() => plugins.id),
|
|
516
|
-
assetType: text("asset_type").notNull(),
|
|
517
|
-
// 'css', 'js', 'image', 'font'
|
|
518
|
-
assetPath: text("asset_path").notNull(),
|
|
519
|
-
loadOrder: integer("load_order").notNull().default(100),
|
|
520
|
-
loadLocation: text("load_location").notNull().default("footer"),
|
|
521
|
-
// 'header', 'footer'
|
|
522
|
-
isActive: integer("is_active", { mode: "boolean" }).notNull().default(true),
|
|
523
|
-
createdAt: integer("created_at").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
524
|
-
});
|
|
525
|
-
var pluginActivityLog = sqliteTable("plugin_activity_log", {
|
|
526
|
-
id: text("id").primaryKey(),
|
|
527
|
-
pluginId: text("plugin_id").notNull().references(() => plugins.id),
|
|
528
|
-
action: text("action").notNull(),
|
|
529
|
-
userId: text("user_id"),
|
|
530
|
-
details: text("details", { mode: "json" }),
|
|
531
|
-
timestamp: integer("timestamp").notNull().$defaultFn(() => Math.floor(Date.now() / 1e3))
|
|
532
|
-
});
|
|
533
|
-
var insertUserSchema = createInsertSchema(users, {
|
|
534
|
-
email: (schema) => schema.email(),
|
|
535
|
-
firstName: (schema) => schema.min(1),
|
|
536
|
-
lastName: (schema) => schema.min(1),
|
|
537
|
-
username: (schema) => schema.min(3)
|
|
538
|
-
});
|
|
539
|
-
var selectUserSchema = createSelectSchema(users);
|
|
540
|
-
var insertCollectionSchema = createInsertSchema(collections, {
|
|
541
|
-
name: (schema) => schema.min(1).regex(/^[a-z0-9_]+$/, "Collection name must be lowercase with underscores"),
|
|
542
|
-
displayName: (schema) => schema.min(1)
|
|
543
|
-
});
|
|
544
|
-
var selectCollectionSchema = createSelectSchema(collections);
|
|
545
|
-
var insertContentSchema = createInsertSchema(content, {
|
|
546
|
-
slug: (schema) => schema.min(1).regex(/^[a-zA-Z0-9_-]+$/, "Slug must contain only letters, numbers, underscores, and hyphens"),
|
|
547
|
-
title: (schema) => schema.min(1),
|
|
548
|
-
status: (schema) => schema
|
|
549
|
-
});
|
|
550
|
-
var selectContentSchema = createSelectSchema(content);
|
|
551
|
-
var insertMediaSchema = createInsertSchema(media, {
|
|
552
|
-
filename: (schema) => schema.min(1),
|
|
553
|
-
originalName: (schema) => schema.min(1),
|
|
554
|
-
mimeType: (schema) => schema.min(1),
|
|
555
|
-
size: (schema) => schema.positive(),
|
|
556
|
-
r2Key: (schema) => schema.min(1),
|
|
557
|
-
publicUrl: (schema) => schema.url(),
|
|
558
|
-
folder: (schema) => schema.min(1)
|
|
559
|
-
});
|
|
560
|
-
var selectMediaSchema = createSelectSchema(media);
|
|
561
|
-
var insertWorkflowHistorySchema = createInsertSchema(workflowHistory, {
|
|
562
|
-
action: (schema) => schema.min(1),
|
|
563
|
-
fromStatus: (schema) => schema.min(1),
|
|
564
|
-
toStatus: (schema) => schema.min(1)
|
|
565
|
-
});
|
|
566
|
-
var selectWorkflowHistorySchema = createSelectSchema(workflowHistory);
|
|
567
|
-
var insertPluginSchema = createInsertSchema(plugins, {
|
|
568
|
-
name: (schema) => schema.min(1),
|
|
569
|
-
displayName: (schema) => schema.min(1),
|
|
570
|
-
version: (schema) => schema.min(1),
|
|
571
|
-
author: (schema) => schema.min(1),
|
|
572
|
-
category: (schema) => schema.min(1)
|
|
573
|
-
});
|
|
574
|
-
var selectPluginSchema = createSelectSchema(plugins);
|
|
575
|
-
var insertPluginHookSchema = createInsertSchema(pluginHooks, {
|
|
576
|
-
hookName: (schema) => schema.min(1),
|
|
577
|
-
handlerName: (schema) => schema.min(1)
|
|
578
|
-
});
|
|
579
|
-
var selectPluginHookSchema = createSelectSchema(pluginHooks);
|
|
580
|
-
var insertPluginRouteSchema = createInsertSchema(pluginRoutes, {
|
|
581
|
-
path: (schema) => schema.min(1),
|
|
582
|
-
method: (schema) => schema.min(1),
|
|
583
|
-
handlerName: (schema) => schema.min(1)
|
|
584
|
-
});
|
|
585
|
-
var selectPluginRouteSchema = createSelectSchema(pluginRoutes);
|
|
586
|
-
var insertPluginAssetSchema = createInsertSchema(pluginAssets, {
|
|
587
|
-
assetType: (schema) => schema.min(1),
|
|
588
|
-
assetPath: (schema) => schema.min(1)
|
|
589
|
-
});
|
|
590
|
-
var selectPluginAssetSchema = createSelectSchema(pluginAssets);
|
|
591
|
-
var insertPluginActivityLogSchema = createInsertSchema(pluginActivityLog, {
|
|
592
|
-
action: (schema) => schema.min(1)
|
|
593
|
-
});
|
|
594
|
-
var selectPluginActivityLogSchema = createSelectSchema(pluginActivityLog);
|
|
595
|
-
var systemLogs = sqliteTable("system_logs", {
|
|
596
|
-
id: text("id").primaryKey(),
|
|
597
|
-
level: text("level").notNull(),
|
|
598
|
-
// 'debug', 'info', 'warn', 'error', 'fatal'
|
|
599
|
-
category: text("category").notNull(),
|
|
600
|
-
// 'auth', 'api', 'workflow', 'plugin', 'media', 'system', etc.
|
|
601
|
-
message: text("message").notNull(),
|
|
602
|
-
data: text("data", { mode: "json" }),
|
|
603
|
-
// Additional structured data
|
|
604
|
-
userId: text("user_id").references(() => users.id),
|
|
605
|
-
sessionId: text("session_id"),
|
|
606
|
-
requestId: text("request_id"),
|
|
607
|
-
ipAddress: text("ip_address"),
|
|
608
|
-
userAgent: text("user_agent"),
|
|
609
|
-
method: text("method"),
|
|
610
|
-
// HTTP method for API logs
|
|
611
|
-
url: text("url"),
|
|
612
|
-
// Request URL for API logs
|
|
613
|
-
statusCode: integer("status_code"),
|
|
614
|
-
// HTTP status code for API logs
|
|
615
|
-
duration: integer("duration"),
|
|
616
|
-
// Request duration in milliseconds
|
|
617
|
-
stackTrace: text("stack_trace"),
|
|
618
|
-
// Error stack trace for error logs
|
|
619
|
-
tags: text("tags", { mode: "json" }),
|
|
620
|
-
// Array of tags for categorization
|
|
621
|
-
source: text("source"),
|
|
622
|
-
// Source component/module that generated the log
|
|
623
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
624
|
-
});
|
|
625
|
-
var logConfig = sqliteTable("log_config", {
|
|
626
|
-
id: text("id").primaryKey(),
|
|
627
|
-
category: text("category").notNull().unique(),
|
|
628
|
-
enabled: integer("enabled", { mode: "boolean" }).notNull().default(true),
|
|
629
|
-
level: text("level").notNull().default("info"),
|
|
630
|
-
// minimum log level to store
|
|
631
|
-
retention: integer("retention").notNull().default(30),
|
|
632
|
-
// days to keep logs
|
|
633
|
-
maxSize: integer("max_size").default(1e4),
|
|
634
|
-
// max number of logs per category
|
|
635
|
-
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date()),
|
|
636
|
-
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => /* @__PURE__ */ new Date())
|
|
637
|
-
});
|
|
638
|
-
var insertSystemLogSchema = createInsertSchema(systemLogs, {
|
|
639
|
-
level: (schema) => schema.min(1),
|
|
640
|
-
category: (schema) => schema.min(1),
|
|
641
|
-
message: (schema) => schema.min(1)
|
|
642
|
-
});
|
|
643
|
-
var selectSystemLogSchema = createSelectSchema(systemLogs);
|
|
644
|
-
var insertLogConfigSchema = createInsertSchema(logConfig, {
|
|
645
|
-
category: (schema) => schema.min(1),
|
|
646
|
-
level: (schema) => schema.min(1)
|
|
647
|
-
});
|
|
648
|
-
var selectLogConfigSchema = createSelectSchema(logConfig);
|
|
649
|
-
|
|
650
|
-
// src/db/index.ts
|
|
651
67
|
function createDb(d1) {
|
|
652
68
|
return drizzle(d1, { schema: schema_exports });
|
|
653
69
|
}
|
|
654
70
|
|
|
655
71
|
// src/index.ts
|
|
656
|
-
var VERSION = "1.0.0-alpha.
|
|
72
|
+
var VERSION = "1.0.0-alpha.2";
|
|
657
73
|
|
|
658
|
-
export { VERSION,
|
|
74
|
+
export { VERSION, createDb, createSonicJSApp, setupCoreMiddleware, setupCoreRoutes };
|
|
659
75
|
//# sourceMappingURL=index.js.map
|
|
660
76
|
//# sourceMappingURL=index.js.map
|