opacacms 0.3.1 → 0.3.3
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/admin/auth-client.d.ts +41 -41
- package/dist/admin/index.js +1 -1
- package/dist/admin/react.js +1 -1
- package/dist/admin/vue.js +1 -1
- package/dist/auth/index.d.ts +43 -48
- package/dist/{chunk-g9bxb6h0.js → chunk-2fm4kv2q.js} +1 -1
- package/dist/chunk-2vbfc4q8.js +6 -0
- package/dist/{chunk-adq2b75c.js → chunk-40tky6qh.js} +2 -2
- package/dist/{chunk-e0g6gn7n.js → chunk-49e16hjg.js} +3 -3
- package/dist/{chunk-fnsf1dfm.js → chunk-526a3gqx.js} +1 -1
- package/dist/{chunk-sqsfk9p4.js → chunk-6m1jhxmd.js} +1 -1
- package/dist/{chunk-6bywt602.js → chunk-8sqjbsgt.js} +1 -26
- package/dist/{chunk-n1twhqmf.js → chunk-acghejk8.js} +1 -1
- package/dist/{chunk-m24yqkeq.js → chunk-b1g8jmth.js} +3 -3
- package/dist/{chunk-5422w4eq.js → chunk-cm5rvcnn.js} +5 -5
- package/dist/{chunk-941zxavt.js → chunk-h2y2t07h.js} +4 -4
- package/dist/{chunk-6qs0g65f.js → chunk-h8v093av.js} +1 -1
- package/dist/{chunk-m5ems3hh.js → chunk-hthm9srb.js} +1 -1
- package/dist/{chunk-2k3ysje3.js → chunk-nch158fe.js} +1 -1
- package/dist/{chunk-naqcqj8n.js → chunk-pj31j6j0.js} +4 -4
- package/dist/{chunk-qsh2nqz3.js → chunk-pw2a9war.js} +3 -3
- package/dist/{chunk-j8js1y0h.js → chunk-r5k7jw66.js} +1 -1
- package/dist/{chunk-48ywpd0a.js → chunk-vmz9ncf1.js} +1 -1
- package/dist/{chunk-qhdsjek6.js → chunk-wry3rqh0.js} +3 -3
- package/dist/cli/commands/init.d.ts +1 -6
- package/dist/cli/index.js +6793 -6
- package/dist/client.js +3 -3
- package/dist/db/better-sqlite.js +4 -4
- package/dist/db/bun-sqlite.js +4 -4
- package/dist/db/d1.js +4 -4
- package/dist/db/index.js +8 -8
- package/dist/db/postgres.js +4 -4
- package/dist/db/sqlite.js +4 -4
- package/dist/index.js +7 -7
- package/dist/runtimes/bun.js +6 -6
- package/dist/runtimes/cloudflare-workers.js +6 -6
- package/dist/runtimes/next.js +6 -6
- package/dist/runtimes/node.js +6 -6
- package/dist/schema/index.js +3 -3
- package/dist/server.js +6 -6
- package/dist/storage/index.js +1 -1
- package/package.json +4 -2
- package/dist/chunk-1qm0m8r8.js +0 -413
- package/dist/chunk-3j9zjfmn.js +0 -376
- package/dist/chunk-56n342hs.js +0 -95
- package/dist/chunk-5b8r0v8c.js +0 -47
- package/dist/chunk-63yg00vx.js +0 -263
- package/dist/chunk-7rr5p01g.js +0 -581
- package/dist/chunk-d0tb1xjw.js +0 -93
- package/dist/chunk-d7cgd6vn.js +0 -318
- package/dist/chunk-ec4jhybj.js +0 -1137
- package/dist/chunk-fatyf6f7.js +0 -221
- package/dist/chunk-gyaf5kgf.js +0 -10
- package/dist/chunk-h6dhexzr.js +0 -94
- package/dist/chunk-majsbncm.js +0 -98
- package/dist/chunk-mp2gt9yh.js +0 -237
- package/dist/chunk-r0ms5tk1.js +0 -76
- package/dist/chunk-rwqwsanx.js +0 -75
- package/dist/chunk-x7bnzswh.js +0 -174
package/dist/chunk-d7cgd6vn.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
generateDiffCode
|
|
3
|
-
} from "./chunk-7rr5p01g.js";
|
|
4
|
-
import {
|
|
5
|
-
require_picocolors
|
|
6
|
-
} from "./chunk-rwqwsanx.js";
|
|
7
|
-
import {
|
|
8
|
-
Gt,
|
|
9
|
-
R,
|
|
10
|
-
Wt,
|
|
11
|
-
be
|
|
12
|
-
} from "./chunk-ec4jhybj.js";
|
|
13
|
-
import {
|
|
14
|
-
loadConfig,
|
|
15
|
-
resolveConfigPath
|
|
16
|
-
} from "./chunk-majsbncm.js";
|
|
17
|
-
import {
|
|
18
|
-
defineCommand
|
|
19
|
-
} from "./chunk-1qm0m8r8.js";
|
|
20
|
-
import {
|
|
21
|
-
getRandomMigrationName
|
|
22
|
-
} from "./chunk-5b8r0v8c.js";
|
|
23
|
-
import"./chunk-qxt9vge8.js";
|
|
24
|
-
import {
|
|
25
|
-
logger
|
|
26
|
-
} from "./chunk-jq1drsen.js";
|
|
27
|
-
import"./chunk-6qs0g65f.js";
|
|
28
|
-
import {
|
|
29
|
-
__require,
|
|
30
|
-
__toESM
|
|
31
|
-
} from "./chunk-6bywt602.js";
|
|
32
|
-
|
|
33
|
-
// src/cli/commands/migrate.ts
|
|
34
|
-
import fs2 from "node:fs";
|
|
35
|
-
import { relative as relative2, resolve as resolve2 } from "node:path";
|
|
36
|
-
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
37
|
-
|
|
38
|
-
// src/cli/core/migrations/migrate-logic.ts
|
|
39
|
-
import { spawnSync } from "node:child_process";
|
|
40
|
-
import fs from "node:fs";
|
|
41
|
-
import { relative, resolve } from "node:path";
|
|
42
|
-
async function migrateCreateCommand(opaca, migrationName, outDir) {
|
|
43
|
-
const db = opaca.db;
|
|
44
|
-
const migrationDir = outDir || db.migrationDir || "./migrations";
|
|
45
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
46
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
47
|
-
fs.mkdirSync(fullMigrationDir, { recursive: true });
|
|
48
|
-
}
|
|
49
|
-
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").split(".")[0];
|
|
50
|
-
const { generateDiffCode: generateDiffCode2 } = await import("./chunk-gyaf5kgf.js");
|
|
51
|
-
let dialect = "sqlite";
|
|
52
|
-
if (db.name === "postgres")
|
|
53
|
-
dialect = "postgres";
|
|
54
|
-
if (db.name === "d1")
|
|
55
|
-
dialect = "d1";
|
|
56
|
-
const isD1 = dialect === "d1";
|
|
57
|
-
const name = !migrationName || migrationName === "migration" ? getRandomMigrationName() : migrationName;
|
|
58
|
-
const snapshotName = `${timestamp}_${name}`;
|
|
59
|
-
const fileName = `${snapshotName}.${isD1 ? "sql" : "ts"}`;
|
|
60
|
-
const filePath = resolve(fullMigrationDir, fileName);
|
|
61
|
-
const result = await generateDiffCode2(opaca, dialect, migrationDir, snapshotName, {
|
|
62
|
-
saveSnapshot: true,
|
|
63
|
-
interactive: true
|
|
64
|
-
});
|
|
65
|
-
if (!result.hasChanges) {
|
|
66
|
-
logger.info("✨ No schema changes detected. Migration not created.");
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
let template = "";
|
|
70
|
-
if (isD1) {
|
|
71
|
-
template = `-- OpacaCMS Auto-generated SQL Migration
|
|
72
|
-
-- Migration: ${snapshotName}
|
|
73
|
-
|
|
74
|
-
-- UP
|
|
75
|
-
${result.upCode}
|
|
76
|
-
`;
|
|
77
|
-
} else {
|
|
78
|
-
template = `import { type OpacaMigrationDb, sql } from 'opacacms/db';
|
|
79
|
-
|
|
80
|
-
export async function up(db: OpacaMigrationDb): Promise<void> {
|
|
81
|
-
${result.upCode}}
|
|
82
|
-
|
|
83
|
-
export async function down(db: OpacaMigrationDb): Promise<void> {
|
|
84
|
-
${result.downCode}}
|
|
85
|
-
`;
|
|
86
|
-
}
|
|
87
|
-
fs.writeFileSync(filePath, template);
|
|
88
|
-
logger.success(`\uD83D\uDE80 Migration created successfully at ${relative(process.cwd(), filePath)}`);
|
|
89
|
-
return true;
|
|
90
|
-
}
|
|
91
|
-
async function migrateRunCommand(db) {
|
|
92
|
-
logger.info("\uD83C\uDFAC Running migrations...");
|
|
93
|
-
if (db.runMigrations) {
|
|
94
|
-
await db.connect();
|
|
95
|
-
try {
|
|
96
|
-
await db.runMigrations();
|
|
97
|
-
logger.success("✅ Migrations applied successfully!");
|
|
98
|
-
} catch (error) {
|
|
99
|
-
logger.error(`❌ Failed to run migrations: ${error.message}`);
|
|
100
|
-
throw error;
|
|
101
|
-
} finally {}
|
|
102
|
-
} else {
|
|
103
|
-
throw new Error(`Adapter ${db.name} does not support running migrations.`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
async function migrateStatusCommand(opaca) {
|
|
107
|
-
logger.info("\uD83D\uDCCA Checking migration status...");
|
|
108
|
-
const db = opaca.db;
|
|
109
|
-
const migrationDir = db.migrationDir || "./migrations";
|
|
110
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
111
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
112
|
-
logger.info("No migrations directory found.");
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const migrationFiles = fs.readdirSync(fullMigrationDir).filter((f) => f.endsWith(".ts") || f.endsWith(".sql")).sort();
|
|
116
|
-
let appliedMigrations = [];
|
|
117
|
-
try {
|
|
118
|
-
await db.connect();
|
|
119
|
-
const rows = await db.unsafe("SELECT name FROM kysely_migration").catch(() => []);
|
|
120
|
-
appliedMigrations = rows.map((r) => r.name);
|
|
121
|
-
} catch (e) {} finally {}
|
|
122
|
-
console.log(`
|
|
123
|
-
Found ${migrationFiles.length} migration files in ${migrationDir}:`);
|
|
124
|
-
for (const file of migrationFiles) {
|
|
125
|
-
const name = file.replace(/\.(ts|sql)$/, "");
|
|
126
|
-
const isApplied = appliedMigrations.includes(name);
|
|
127
|
-
console.log(` ${isApplied ? "✅ [Applied] " : "❌ [Pending] "} ${file}`);
|
|
128
|
-
}
|
|
129
|
-
const pending = migrationFiles.filter((f) => !appliedMigrations.includes(f.replace(/\.(ts|sql)$/, "")));
|
|
130
|
-
if (pending.length > 0) {
|
|
131
|
-
console.log(`
|
|
132
|
-
\uD83D\uDCA1 You have ${pending.length} pending migrations. Run 'opacacms migrate' to apply them.`);
|
|
133
|
-
} else {
|
|
134
|
-
console.log(`
|
|
135
|
-
✨ All migrations are up to date.`);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
async function migrateD1Command(migrationDir, isRemote, binding = "DB") {
|
|
139
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
140
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
141
|
-
throw new Error(`[OpacaCMS] Migration directory not found: ${fullMigrationDir}`);
|
|
142
|
-
}
|
|
143
|
-
const migrations = fs.readdirSync(fullMigrationDir).filter((file) => file.endsWith(".sql")).sort();
|
|
144
|
-
if (migrations.length === 0) {
|
|
145
|
-
console.log(`[OpacaCMS] No SQL migrations found in ${fullMigrationDir}`);
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
console.log(`[OpacaCMS] Found ${migrations.length} migrations. Applying to ${isRemote ? "\uD83C\uDF0A REMOTE (Cloudflare D1)" : "\uD83D\uDCBB LOCAL (SQLite)"}...`);
|
|
149
|
-
for (const migration of migrations) {
|
|
150
|
-
const filePath = resolve(fullMigrationDir, migration);
|
|
151
|
-
console.log(`
|
|
152
|
-
[OpacaCMS] \uD83D\uDCE6 Applying: ${migration}...`);
|
|
153
|
-
const wranglerArgs = [
|
|
154
|
-
"wrangler",
|
|
155
|
-
"d1",
|
|
156
|
-
"execute",
|
|
157
|
-
binding,
|
|
158
|
-
"--file",
|
|
159
|
-
filePath,
|
|
160
|
-
isRemote ? "--remote" : "--local",
|
|
161
|
-
"--yes"
|
|
162
|
-
];
|
|
163
|
-
const result = spawnSync("bun", ["x", ...wranglerArgs], {
|
|
164
|
-
stdio: "inherit",
|
|
165
|
-
shell: false,
|
|
166
|
-
cwd: process.cwd()
|
|
167
|
-
});
|
|
168
|
-
if (result.status !== 0) {
|
|
169
|
-
console.error(`[OpacaCMS] ❌ Failed to apply migration: ${migration}`);
|
|
170
|
-
} else {
|
|
171
|
-
console.log(`[OpacaCMS] ✅ Success: ${migration}`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
console.log(`
|
|
175
|
-
[OpacaCMS] ✨ Database migration process completed!`);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/cli/commands/migrate.ts
|
|
179
|
-
var migrate_default = defineCommand({
|
|
180
|
-
meta: {
|
|
181
|
-
name: "migrate",
|
|
182
|
-
description: "Manage database migrations"
|
|
183
|
-
},
|
|
184
|
-
args: {
|
|
185
|
-
config: {
|
|
186
|
-
type: "string",
|
|
187
|
-
alias: "c",
|
|
188
|
-
description: "Path to the OpacaCMS configuration file"
|
|
189
|
-
},
|
|
190
|
-
action: {
|
|
191
|
-
type: "positional",
|
|
192
|
-
description: "Action to perform: run (default), create, diff, status, d1",
|
|
193
|
-
required: false
|
|
194
|
-
},
|
|
195
|
-
name: {
|
|
196
|
-
type: "positional",
|
|
197
|
-
description: "Name of the migration (for create)",
|
|
198
|
-
required: false
|
|
199
|
-
},
|
|
200
|
-
out: {
|
|
201
|
-
type: "string",
|
|
202
|
-
alias: "o",
|
|
203
|
-
description: "Output directory for migrations"
|
|
204
|
-
},
|
|
205
|
-
remote: {
|
|
206
|
-
type: "boolean",
|
|
207
|
-
description: "Apply migrations to remote D1"
|
|
208
|
-
},
|
|
209
|
-
binding: {
|
|
210
|
-
type: "string",
|
|
211
|
-
alias: "b",
|
|
212
|
-
description: "D1 database binding name",
|
|
213
|
-
default: "DB"
|
|
214
|
-
}
|
|
215
|
-
},
|
|
216
|
-
async run({ args }) {
|
|
217
|
-
console.log();
|
|
218
|
-
Wt(import_picocolors.default.bgMagenta(import_picocolors.default.white(" OpacaCMS Migrations ")));
|
|
219
|
-
const s = be();
|
|
220
|
-
const action = args.action || "run";
|
|
221
|
-
let opaca;
|
|
222
|
-
if (action !== "d1") {
|
|
223
|
-
s.start("Loading configuration...");
|
|
224
|
-
try {
|
|
225
|
-
const configPath = resolveConfigPath(args.config);
|
|
226
|
-
opaca = await loadConfig(configPath);
|
|
227
|
-
s.stop(`Configuration loaded. DB: ${import_picocolors.default.cyan(opaca.db.name)}`);
|
|
228
|
-
} catch (err) {
|
|
229
|
-
s.stop(import_picocolors.default.red("Failed to load configuration."));
|
|
230
|
-
R.error(err.message);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
try {
|
|
235
|
-
if (action === "create") {
|
|
236
|
-
const name = !args.name || args.name === "migration" ? getRandomMigrationName() : args.name;
|
|
237
|
-
s.start(`Generating baseline migration '${name}'...`);
|
|
238
|
-
const created = await migrateCreateCommand(opaca, name, args.out);
|
|
239
|
-
if (created) {
|
|
240
|
-
s.stop(`Baseline migration created successfully!`);
|
|
241
|
-
} else {
|
|
242
|
-
s.stop(`Operation aborted. No changes detected.`);
|
|
243
|
-
}
|
|
244
|
-
} else if (action === "diff") {
|
|
245
|
-
let name = args.name || "migration";
|
|
246
|
-
if (name === "migration") {
|
|
247
|
-
name = getRandomMigrationName();
|
|
248
|
-
}
|
|
249
|
-
s.start(`Analyzing schema for differences...`);
|
|
250
|
-
let dialect = "sqlite";
|
|
251
|
-
if (opaca.db.name === "postgres")
|
|
252
|
-
dialect = "postgres";
|
|
253
|
-
if (opaca.db.name === "d1")
|
|
254
|
-
dialect = "d1";
|
|
255
|
-
const migrationDir = opaca.db.migrationDir || "./migrations";
|
|
256
|
-
const { hasChanges, upCode, downCode } = await generateDiffCode(opaca, dialect, migrationDir, "diff_check", { saveSnapshot: false, interactive: false });
|
|
257
|
-
if (!hasChanges) {
|
|
258
|
-
s.stop(`Schema is already up to date. No migration generated.`);
|
|
259
|
-
} else {
|
|
260
|
-
s.start(`Generating diff migration '${name}'...`);
|
|
261
|
-
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").split(".")[0];
|
|
262
|
-
const isD1 = dialect === "d1";
|
|
263
|
-
const fileName = `${timestamp}_${name}.${isD1 ? "sql" : "ts"}`;
|
|
264
|
-
const migrationDir2 = args.out || opaca.db.migrationDir || "./migrations";
|
|
265
|
-
const fullMigrationDir = resolve2(process.cwd(), migrationDir2);
|
|
266
|
-
if (!fs2.existsSync(fullMigrationDir)) {
|
|
267
|
-
fs2.mkdirSync(fullMigrationDir, { recursive: true });
|
|
268
|
-
}
|
|
269
|
-
const filePath = resolve2(fullMigrationDir, fileName);
|
|
270
|
-
let template = "";
|
|
271
|
-
if (isD1) {
|
|
272
|
-
template = `-- OpacaCMS Auto-generated SQL Diff Migration
|
|
273
|
-
|
|
274
|
-
${upCode}`;
|
|
275
|
-
} else {
|
|
276
|
-
template = `import { type OpacaMigrationDb, sql } from 'opacacms/db';
|
|
277
|
-
|
|
278
|
-
export async function up(db: OpacaMigrationDb): Promise<void> {
|
|
279
|
-
${upCode}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export async function down(db: OpacaMigrationDb): Promise<void> {
|
|
283
|
-
${downCode}
|
|
284
|
-
}
|
|
285
|
-
`;
|
|
286
|
-
}
|
|
287
|
-
fs2.writeFileSync(filePath, template);
|
|
288
|
-
s.stop(`Diff migration created successfully at ${relative2(process.cwd(), filePath)}!`);
|
|
289
|
-
}
|
|
290
|
-
} else if (action === "run") {
|
|
291
|
-
s.start(`Applying pending migrations...`);
|
|
292
|
-
await migrateRunCommand(opaca.db);
|
|
293
|
-
s.stop(`Migrations applied successfully!`);
|
|
294
|
-
} else if (action === "status") {
|
|
295
|
-
s.start(`Checking migration status...`);
|
|
296
|
-
await migrateStatusCommand(opaca);
|
|
297
|
-
s.stop(`Migration status checked.`);
|
|
298
|
-
} else if (action === "d1") {
|
|
299
|
-
s.start(`Applying D1 migrations...`);
|
|
300
|
-
await migrateD1Command(args.out || "./migrations", !!args.remote, args.binding);
|
|
301
|
-
s.stop(`D1 migrations processed!`);
|
|
302
|
-
} else {
|
|
303
|
-
R.error(`Unknown migration action: ${action}`);
|
|
304
|
-
process.exit(1);
|
|
305
|
-
}
|
|
306
|
-
Gt("Done! \uD83D\uDE80");
|
|
307
|
-
} catch (err) {
|
|
308
|
-
if (s)
|
|
309
|
-
s.stop(import_picocolors.default.red("Migration failed."));
|
|
310
|
-
R.error(err.message);
|
|
311
|
-
Gt(import_picocolors.default.red("Operation aborted."));
|
|
312
|
-
process.exit(1);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
});
|
|
316
|
-
export {
|
|
317
|
-
migrate_default as default
|
|
318
|
-
};
|