opacacms 0.2.1 → 0.3.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/README.md +31 -22
- package/dist/admin/auth-client.d.ts +39 -39
- package/dist/admin/index.d.ts +2 -2
- package/dist/admin/index.js +15 -10520
- package/dist/admin/plugin-client.d.ts +65 -0
- package/dist/admin/react.d.ts +2 -2
- package/dist/admin/react.js +34 -4
- package/dist/admin/stores/ui.d.ts +19 -4
- package/dist/admin/ui/components/PluginSettingsForm.d.ts +2 -2
- package/dist/admin/ui/components/custom-alert.d.ts +7 -0
- package/dist/admin/ui/components/{DetailSheet.d.ts → detail-sheet.d.ts} +1 -2
- package/dist/admin/ui/components/fields/FieldLabel.d.ts +1 -1
- package/dist/admin/ui/components/fields/RelationshipField.d.ts +1 -1
- package/dist/admin/ui/components/media/AssetManagerModal.d.ts +2 -2
- package/dist/admin/ui/components/plugin-iframe.d.ts +7 -0
- package/dist/admin/ui/components/ui/accordion.d.ts +17 -7
- package/dist/admin/ui/components/ui/alert-dialog.d.ts +16 -12
- package/dist/admin/ui/components/ui/button.d.ts +11 -7
- package/dist/admin/ui/components/ui/relationship.d.ts +1 -1
- package/dist/admin/ui/components/ui/sheet.d.ts +14 -27
- package/dist/admin/ui/components/ui/tooltip.d.ts +7 -0
- package/dist/admin/ui/components/versions-sheet.d.ts +4 -5
- package/dist/admin/ui/views/collection-list-view.d.ts +1 -1
- package/dist/admin/ui/views/dashboard-view.d.ts +1 -1
- package/dist/admin/ui/views/media-registry-view.d.ts +3 -3
- package/dist/admin/ui/views/settings-view.d.ts +2 -2
- package/dist/admin/vue.js +27 -4
- package/dist/admin/webcomponent.js +66 -16
- package/dist/admin.css +1 -1
- package/dist/auth/index.d.ts +43 -43
- package/dist/{chunk-7y1nbmw6.js → chunk-1bd7fz7n.js} +32 -2
- package/dist/chunk-1qm0m8r8.js +413 -0
- package/dist/chunk-2k3ysje3.js +31 -0
- package/dist/{chunk-jdfw4v3r.js → chunk-3j9zjfmn.js} +95 -30
- package/dist/{chunk-byq8g0rd.js → chunk-48ywpd0a.js} +16 -22
- package/dist/{chunk-tfnaf41w.js → chunk-5422w4eq.js} +41 -25
- package/dist/chunk-56n342hs.js +95 -0
- package/dist/chunk-5b8r0v8c.js +47 -0
- package/dist/chunk-63yg00vx.js +263 -0
- package/dist/{chunk-8sqjbsgt.js → chunk-6bywt602.js} +26 -1
- package/dist/{chunk-v9z61v3g.js → chunk-6qs0g65f.js} +43 -3
- package/dist/chunk-7rr5p01g.js +581 -0
- package/dist/{chunk-2es275xs.js → chunk-941zxavt.js} +867 -322
- package/dist/{chunk-51z3x7kq.js → chunk-a3qae86h.js} +1 -1
- package/dist/{chunk-3rdhbedb.js → chunk-adq2b75c.js} +2 -2
- package/dist/chunk-d0tb1xjw.js +93 -0
- package/dist/chunk-d7cgd6vn.js +318 -0
- package/dist/{chunk-6d1vdfwa.js → chunk-e0g6gn7n.js} +54 -75
- package/dist/chunk-ec4jhybj.js +1137 -0
- package/dist/chunk-fatyf6f7.js +221 -0
- package/dist/{chunk-526a3gqx.js → chunk-fnsf1dfm.js} +1 -1
- package/dist/chunk-g9bxb6h0.js +205 -0
- package/dist/chunk-gyaf5kgf.js +10 -0
- package/dist/{chunk-9kxpbcb1.js → chunk-h6dhexzr.js} +16 -7
- package/dist/{chunk-dykn5hr6.js → chunk-j8js1y0h.js} +31 -74
- package/dist/{chunk-t0zg026p.js → chunk-jq1drsen.js} +12 -1
- package/dist/{chunk-b3kr8w41.js → chunk-m24yqkeq.js} +38 -26
- package/dist/chunk-m5ems3hh.js +410 -0
- package/dist/{chunk-8scgdznr.js → chunk-m83ybzf8.js} +15 -18
- package/dist/chunk-majsbncm.js +98 -0
- package/dist/chunk-mp2gt9yh.js +237 -0
- package/dist/chunk-n1twhqmf.js +54 -0
- package/dist/{chunk-bygjkgrx.js → chunk-naqcqj8n.js} +57 -80
- package/dist/chunk-q5sb5dcr.js +15 -0
- package/dist/{chunk-06ks4ggh.js → chunk-qhdsjek6.js} +49 -89
- package/dist/{chunk-n133qpsm.js → chunk-qsh2nqz3.js} +50 -81
- package/dist/chunk-r0ms5tk1.js +76 -0
- package/dist/chunk-rwqwsanx.js +75 -0
- package/dist/chunk-sqsfk9p4.js +700 -0
- package/dist/{chunk-5gvbp2qa.js → chunk-x7bnzswh.js} +25 -18
- package/dist/cli/commands/dev.d.ts +8 -0
- package/dist/cli/commands/doctor.d.ts +8 -0
- package/dist/cli/commands/generate.d.ts +26 -0
- package/dist/cli/commands/init.d.ts +13 -1
- package/dist/cli/commands/migrate.d.ts +33 -0
- package/dist/cli/commands/plugin.d.ts +13 -0
- package/dist/cli/commands/seed.d.ts +21 -0
- package/dist/cli/{commands/migrate-commands.d.ts → core/migrations/migrate-logic.d.ts} +2 -2
- package/dist/cli/core/migrations/schema-diff-engine.d.ts +12 -0
- package/dist/cli/core/migrations/schema-diff.d.ts +11 -0
- package/dist/cli/{seeding.d.ts → core/seeding/auto-seed.d.ts} +7 -4
- package/dist/cli/core/seeding/seed-logic.d.ts +2 -0
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.js +6 -170
- package/dist/client/RichText.d.ts +5 -0
- package/dist/client/rich-text-utils.d.ts +5 -0
- package/dist/client.js +3 -2
- package/dist/config.d.ts +3 -3
- package/dist/db/better-sqlite.d.ts +2 -3
- package/dist/db/better-sqlite.js +6 -5
- package/dist/db/bun-sqlite.d.ts +2 -3
- package/dist/db/bun-sqlite.js +6 -5
- package/dist/db/d1.d.ts +13 -7
- package/dist/db/d1.js +6 -5
- package/dist/db/index.d.ts +2 -2
- package/dist/db/index.js +10 -12
- package/dist/db/kysely/factory.d.ts +29 -0
- package/dist/db/kysely/plugins/audit-logging.d.ts +48 -0
- package/dist/db/kysely/plugins/auto-timestamps.d.ts +38 -0
- package/dist/db/kysely/plugins/cursor-pagination.d.ts +42 -0
- package/dist/db/kysely/plugins/deadlock-handler.d.ts +47 -0
- package/dist/db/kysely/plugins/draft-swapper.d.ts +33 -0
- package/dist/db/kysely/plugins/field-masking.d.ts +45 -0
- package/dist/db/kysely/plugins/fts-normalizer.d.ts +38 -0
- package/dist/db/kysely/plugins/i18n-fallback.d.ts +48 -0
- package/dist/db/kysely/plugins/id-generation.d.ts +42 -0
- package/dist/db/kysely/plugins/index.d.ts +16 -0
- package/dist/db/kysely/plugins/json-flattener.d.ts +38 -0
- package/dist/db/kysely/plugins/relationship-preloading.d.ts +39 -0
- package/dist/db/kysely/plugins/slug-generation.d.ts +37 -0
- package/dist/db/kysely/plugins/soft-delete.d.ts +42 -0
- package/dist/db/kysely/plugins/tree-resolver.d.ts +39 -0
- package/dist/db/kysely/plugins/virtual-field-resolver.d.ts +54 -0
- package/dist/db/kysely/plugins/zod-coercion.d.ts +34 -0
- package/dist/db/kysely/snapshot/snapshot-manager.d.ts +18 -0
- package/dist/db/postgres.d.ts +2 -2
- package/dist/db/postgres.js +6 -5
- package/dist/db/sqlite.d.ts +2 -3
- package/dist/db/sqlite.js +6 -5
- package/dist/index.d.ts +3 -0
- package/dist/index.js +161 -7
- package/dist/runtimes/bun.js +9 -6
- package/dist/runtimes/cloudflare-workers.d.ts +3 -1
- package/dist/runtimes/cloudflare-workers.js +36 -7
- package/dist/runtimes/next.js +8 -5
- package/dist/runtimes/node.js +9 -6
- package/dist/schema/collection.d.ts +116 -70
- package/dist/schema/compiler.d.ts +6 -0
- package/dist/schema/global.d.ts +38 -71
- package/dist/schema/index.d.ts +5 -4
- package/dist/schema/index.js +35 -550
- package/dist/schema/zod.d.ts +564 -0
- package/dist/server/admin-router.d.ts +1 -1
- package/dist/server/collection-router.d.ts +1 -1
- package/dist/server/graphql.d.ts +6 -0
- package/dist/server/handlers.d.ts +25 -7
- package/dist/server/middlewares/auth.d.ts +1 -1
- package/dist/server/plugins-loader.d.ts +1 -1
- package/dist/server/router.d.ts +2 -2
- package/dist/server/routers/admin.d.ts +1 -1
- package/dist/server/routers/auth.d.ts +1 -1
- package/dist/server/routers/collections.d.ts +4 -1
- package/dist/server/routers/plugins.d.ts +2 -2
- package/dist/server/setup-middlewares.d.ts +1 -1
- package/dist/server/system-router.d.ts +1 -1
- package/dist/server.js +11 -6
- package/dist/storage/adapters/cloudflare-r2.d.ts +11 -2
- package/dist/storage/index.js +5 -5
- package/dist/types.d.ts +253 -42
- package/dist/utils/context.d.ts +14 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/string.d.ts +10 -0
- package/dist/utils/webhooks-engine.d.ts +24 -0
- package/dist/validation.d.ts +67 -1
- package/dist/validator.d.ts +1 -0
- package/package.json +50 -11
- package/src/cli/index.ts +117 -0
- package/dist/chunk-6qq3ne6b.js +0 -288
- package/dist/chunk-6v1fw7q7.js +0 -126
- package/dist/chunk-7a9kn0np.js +0 -116
- package/dist/chunk-bexcv7xe.js +0 -36
- package/dist/chunk-d3ffeqp9.js +0 -87
- package/dist/chunk-fj19qccp.js +0 -78
- package/dist/chunk-g1jb60xd.js +0 -17
- package/dist/chunk-j53pz21t.js +0 -20
- package/dist/chunk-mkn49zmy.js +0 -102
- package/dist/chunk-r39em4yj.js +0 -29
- package/dist/chunk-rsf0tpy1.js +0 -8
- package/dist/chunk-srsac177.js +0 -85
- package/dist/chunk-twpvxfce.js +0 -64
- package/dist/chunk-ywm4t2gm.js +0 -19
- package/dist/cli/commands/plugin-sync.d.ts +0 -1
- package/dist/cli/commands/seed-command.d.ts +0 -2
- package/dist/plugins/ui-bridge.d.ts +0 -12
- package/dist/schema/fields/base.d.ts +0 -84
- package/dist/schema/fields/index.d.ts +0 -147
- package/dist/schema/infer.d.ts +0 -55
- /package/dist/admin/ui/components/{ColumnVisibilityToggle.d.ts → column-visibility-toggle.d.ts} +0 -0
- /package/dist/admin/ui/components/{DataDetailView.d.ts → data-detail-view.d.ts} +0 -0
- /package/dist/cli/{d1-mock.d.ts → core/mocks/d1-mock.d.ts} +0 -0
- /package/dist/cli/{r2-mock.d.ts → core/mocks/r2-mock.d.ts} +0 -0
- /package/dist/cli/{commands → core/plugins}/plugin-build.d.ts +0 -0
- /package/dist/cli/{commands → core/plugins}/plugin-init.d.ts +0 -0
- /package/dist/cli/{commands → core/types}/generate-types.d.ts +0 -0
- /package/dist/{schema/fields/validation.test.d.ts → cli/seeding.test.d.ts} +0 -0
package/dist/chunk-6v1fw7q7.js
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
logger
|
|
3
|
-
} from "./chunk-t0zg026p.js";
|
|
4
|
-
import {
|
|
5
|
-
__require
|
|
6
|
-
} from "./chunk-8sqjbsgt.js";
|
|
7
|
-
|
|
8
|
-
// src/cli/commands/migrate-commands.ts
|
|
9
|
-
import fs from "node:fs";
|
|
10
|
-
import { relative, resolve } from "node:path";
|
|
11
|
-
import { spawnSync } from "node:child_process";
|
|
12
|
-
async function migrateCreateCommand(opaca, migrationName = "migration", outDir) {
|
|
13
|
-
const db = opaca.db;
|
|
14
|
-
const migrationDir = outDir || db.migrationDir || "./migrations";
|
|
15
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
16
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
17
|
-
fs.mkdirSync(fullMigrationDir, { recursive: true });
|
|
18
|
-
}
|
|
19
|
-
const timestamp = new Date().toISOString().replace(/[-:T]/g, "").split(".")[0];
|
|
20
|
-
const { generateMigrationCode, generateSQLCode } = await import("./chunk-6qq3ne6b.js");
|
|
21
|
-
const { getSystemCollections } = await import("./chunk-3rdhbedb.js");
|
|
22
|
-
let dialect = "sqlite";
|
|
23
|
-
if (db.name === "postgres")
|
|
24
|
-
dialect = "postgres";
|
|
25
|
-
if (db.name === "d1")
|
|
26
|
-
dialect = "d1";
|
|
27
|
-
const isD1 = dialect === "d1";
|
|
28
|
-
const fileName = `${timestamp}_${migrationName}.${isD1 ? "sql" : "ts"}`;
|
|
29
|
-
const filePath = resolve(fullMigrationDir, fileName);
|
|
30
|
-
const allCollections = [...getSystemCollections(), ...opaca.collections || []];
|
|
31
|
-
const template = isD1 ? generateSQLCode(allCollections, opaca.globals || []) : generateMigrationCode(allCollections, opaca.globals || [], dialect);
|
|
32
|
-
fs.writeFileSync(filePath, template);
|
|
33
|
-
logger.success(`\uD83D\uDE80 Migration created successfully at ${relative(process.cwd(), filePath)}`);
|
|
34
|
-
}
|
|
35
|
-
async function migrateRunCommand(db) {
|
|
36
|
-
logger.info("\uD83C\uDFAC Running migrations...");
|
|
37
|
-
if (db.runMigrations) {
|
|
38
|
-
await db.connect();
|
|
39
|
-
try {
|
|
40
|
-
await db.runMigrations();
|
|
41
|
-
logger.success("✅ Migrations applied successfully!");
|
|
42
|
-
} catch (error) {
|
|
43
|
-
logger.error(`❌ Failed to run migrations: ${error.message}`);
|
|
44
|
-
throw error;
|
|
45
|
-
} finally {}
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error(`Adapter ${db.name} does not support running migrations.`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
async function migrateStatusCommand(opaca) {
|
|
51
|
-
logger.info("\uD83D\uDCCA Checking migration status...");
|
|
52
|
-
const db = opaca.db;
|
|
53
|
-
const migrationDir = db.migrationDir || "./migrations";
|
|
54
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
55
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
56
|
-
logger.info("No migrations directory found.");
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const migrationFiles = fs.readdirSync(fullMigrationDir).filter((f) => f.endsWith(".ts") || f.endsWith(".sql")).sort();
|
|
60
|
-
let appliedMigrations = [];
|
|
61
|
-
try {
|
|
62
|
-
await db.connect();
|
|
63
|
-
const rows = await db.unsafe("SELECT name FROM kysely_migration").catch(() => []);
|
|
64
|
-
appliedMigrations = rows.map((r) => r.name);
|
|
65
|
-
} catch (e) {} finally {}
|
|
66
|
-
console.log(`
|
|
67
|
-
Found ${migrationFiles.length} migration files in ${migrationDir}:`);
|
|
68
|
-
for (const file of migrationFiles) {
|
|
69
|
-
const name = file.replace(/\.(ts|sql)$/, "");
|
|
70
|
-
const isApplied = appliedMigrations.includes(name);
|
|
71
|
-
console.log(` ${isApplied ? "✅ [Applied] " : "❌ [Pending] "} ${file}`);
|
|
72
|
-
}
|
|
73
|
-
const pending = migrationFiles.filter((f) => !appliedMigrations.includes(f.replace(/\.(ts|sql)$/, "")));
|
|
74
|
-
if (pending.length > 0) {
|
|
75
|
-
console.log(`
|
|
76
|
-
\uD83D\uDCA1 You have ${pending.length} pending migrations. Run 'opacacms migrate' to apply them.`);
|
|
77
|
-
} else {
|
|
78
|
-
console.log(`
|
|
79
|
-
✨ All migrations are up to date.`);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
async function migrateD1Command(migrationDir, isRemote, binding = "DB") {
|
|
83
|
-
const fullMigrationDir = resolve(process.cwd(), migrationDir);
|
|
84
|
-
if (!fs.existsSync(fullMigrationDir)) {
|
|
85
|
-
throw new Error(`[OpacaCMS] Migration directory not found: ${fullMigrationDir}`);
|
|
86
|
-
}
|
|
87
|
-
const migrations = fs.readdirSync(fullMigrationDir).filter((file) => file.endsWith(".sql")).sort();
|
|
88
|
-
if (migrations.length === 0) {
|
|
89
|
-
console.log(`[OpacaCMS] No SQL migrations found in ${fullMigrationDir}`);
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
console.log(`[OpacaCMS] Found ${migrations.length} migrations. Applying to ${isRemote ? "\uD83C\uDF0A REMOTE (Cloudflare D1)" : "\uD83D\uDCBB LOCAL (SQLite)"}...`);
|
|
93
|
-
for (const migration of migrations) {
|
|
94
|
-
const filePath = resolve(fullMigrationDir, migration);
|
|
95
|
-
console.log(`
|
|
96
|
-
[OpacaCMS] \uD83D\uDCE6 Applying: ${migration}...`);
|
|
97
|
-
const wranglerArgs = [
|
|
98
|
-
"wrangler",
|
|
99
|
-
"d1",
|
|
100
|
-
"execute",
|
|
101
|
-
binding,
|
|
102
|
-
"--file",
|
|
103
|
-
filePath,
|
|
104
|
-
isRemote ? "--remote" : "--local",
|
|
105
|
-
"--yes"
|
|
106
|
-
];
|
|
107
|
-
const result = spawnSync("bun", ["x", ...wranglerArgs], {
|
|
108
|
-
stdio: "inherit",
|
|
109
|
-
shell: false,
|
|
110
|
-
cwd: process.cwd()
|
|
111
|
-
});
|
|
112
|
-
if (result.status !== 0) {
|
|
113
|
-
console.error(`[OpacaCMS] ❌ Failed to apply migration: ${migration}`);
|
|
114
|
-
} else {
|
|
115
|
-
console.log(`[OpacaCMS] ✅ Success: ${migration}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
console.log(`
|
|
119
|
-
[OpacaCMS] ✨ Database migration process completed!`);
|
|
120
|
-
}
|
|
121
|
-
export {
|
|
122
|
-
migrateStatusCommand,
|
|
123
|
-
migrateRunCommand,
|
|
124
|
-
migrateD1Command,
|
|
125
|
-
migrateCreateCommand
|
|
126
|
-
};
|
package/dist/chunk-7a9kn0np.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import"./chunk-8sqjbsgt.js";
|
|
2
|
-
|
|
3
|
-
// src/cli/commands/generate-types.ts
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
import { resolve } from "node:path";
|
|
6
|
-
async function generateTypesCommand(url, token, out) {
|
|
7
|
-
console.log(`[OpacaCMS] Fetching metadata from ${url}/api/__admin/metadata...`);
|
|
8
|
-
let data;
|
|
9
|
-
try {
|
|
10
|
-
const res = await fetch(`${url.replace(/\/$/, "")}/api/__admin/metadata`, {
|
|
11
|
-
headers: {
|
|
12
|
-
Authorization: `Bearer ${token}`
|
|
13
|
-
}
|
|
14
|
-
});
|
|
15
|
-
if (!res.ok) {
|
|
16
|
-
if (res.status === 401 || res.status === 403) {
|
|
17
|
-
throw new Error("Authentication failed. Ensure your API Key is correct and has the necessary permissions.");
|
|
18
|
-
}
|
|
19
|
-
const errorText = await res.text().catch(() => "Unknown error");
|
|
20
|
-
throw new Error(`Server responded with ${res.status}: ${errorText}`);
|
|
21
|
-
}
|
|
22
|
-
data = await res.json();
|
|
23
|
-
} catch (err) {
|
|
24
|
-
console.error(`[OpacaCMS] Failed to fetch metadata: ${err.message}`);
|
|
25
|
-
process.exit(1);
|
|
26
|
-
}
|
|
27
|
-
console.log(`[OpacaCMS] Successfully fetched metadata for ${data.collections.length} collections and ${data.globals?.length || 0} globals.`);
|
|
28
|
-
let dtsContent = `// Automatically generated by OpacaCMS CLI
|
|
29
|
-
// Do not edit this file manually
|
|
30
|
-
|
|
31
|
-
export interface OpacaAsset {
|
|
32
|
-
assetId: string;
|
|
33
|
-
url: string;
|
|
34
|
-
filename: string;
|
|
35
|
-
mime_type: string;
|
|
36
|
-
filesize: number;
|
|
37
|
-
meta?: Record<string, any>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface OpacaCollections {
|
|
41
|
-
collections: {
|
|
42
|
-
`;
|
|
43
|
-
for (const collection of data.collections) {
|
|
44
|
-
dtsContent += ` "${collection.slug}": {
|
|
45
|
-
`;
|
|
46
|
-
dtsContent += ` id: string | number;
|
|
47
|
-
`;
|
|
48
|
-
for (const field of collection.fields) {
|
|
49
|
-
const typeStr = mapFieldToTsType(field.type);
|
|
50
|
-
const isOptional = field.required ? "" : "?";
|
|
51
|
-
dtsContent += ` ${field.name}${isOptional}: ${typeStr};
|
|
52
|
-
`;
|
|
53
|
-
}
|
|
54
|
-
if (collection.timestamps) {
|
|
55
|
-
dtsContent += ` createdAt: string;
|
|
56
|
-
`;
|
|
57
|
-
dtsContent += ` updatedAt: string;
|
|
58
|
-
`;
|
|
59
|
-
}
|
|
60
|
-
dtsContent += ` };
|
|
61
|
-
`;
|
|
62
|
-
}
|
|
63
|
-
dtsContent += ` };
|
|
64
|
-
`;
|
|
65
|
-
if (data.globals && data.globals.length > 0) {
|
|
66
|
-
dtsContent += ` globals: {
|
|
67
|
-
`;
|
|
68
|
-
for (const globalConf of data.globals) {
|
|
69
|
-
dtsContent += ` "${globalConf.slug}": {
|
|
70
|
-
`;
|
|
71
|
-
for (const field of globalConf.fields) {
|
|
72
|
-
const typeStr = mapFieldToTsType(field.type);
|
|
73
|
-
const isOptional = field.required ? "" : "?";
|
|
74
|
-
dtsContent += ` ${field.name}${isOptional}: ${typeStr};
|
|
75
|
-
`;
|
|
76
|
-
}
|
|
77
|
-
dtsContent += ` };
|
|
78
|
-
`;
|
|
79
|
-
}
|
|
80
|
-
dtsContent += ` };
|
|
81
|
-
`;
|
|
82
|
-
} else {
|
|
83
|
-
dtsContent += ` globals: Record<string, any>;
|
|
84
|
-
`;
|
|
85
|
-
}
|
|
86
|
-
dtsContent += `}
|
|
87
|
-
`;
|
|
88
|
-
const outputPath = resolve(process.cwd(), out || "opaca-types.d.ts");
|
|
89
|
-
fs.writeFileSync(outputPath, dtsContent);
|
|
90
|
-
console.log(`[OpacaCMS] Types successfully generated at ${outputPath}`);
|
|
91
|
-
}
|
|
92
|
-
function mapFieldToTsType(type) {
|
|
93
|
-
switch (type) {
|
|
94
|
-
case "text":
|
|
95
|
-
case "textarea":
|
|
96
|
-
case "richtext":
|
|
97
|
-
case "select":
|
|
98
|
-
case "date":
|
|
99
|
-
return "string";
|
|
100
|
-
case "number":
|
|
101
|
-
return "number";
|
|
102
|
-
case "boolean":
|
|
103
|
-
return "boolean";
|
|
104
|
-
case "json":
|
|
105
|
-
return "any | any[]";
|
|
106
|
-
case "file":
|
|
107
|
-
return "OpacaAsset";
|
|
108
|
-
case "relationship":
|
|
109
|
-
return "string | number | any";
|
|
110
|
-
default:
|
|
111
|
-
return "any";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
export {
|
|
115
|
-
generateTypesCommand
|
|
116
|
-
};
|
package/dist/chunk-bexcv7xe.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineCustomField
|
|
3
|
-
} from "./chunk-rqyjjqgy.js";
|
|
4
|
-
|
|
5
|
-
// src/admin/react.tsx
|
|
6
|
-
import React from "react";
|
|
7
|
-
import { createRoot } from "react-dom/client";
|
|
8
|
-
function defineReactField(tagName, Component) {
|
|
9
|
-
defineCustomField(tagName, {
|
|
10
|
-
mount: (container, props) => {
|
|
11
|
-
const el = container;
|
|
12
|
-
const root = createRoot(el);
|
|
13
|
-
el._opacaReactRoot = root;
|
|
14
|
-
root.render(React.createElement(Component, props));
|
|
15
|
-
},
|
|
16
|
-
update: (container, props) => {
|
|
17
|
-
const el = container;
|
|
18
|
-
const root = el._opacaReactRoot;
|
|
19
|
-
if (root) {
|
|
20
|
-
root.render(React.createElement(Component, props));
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
unmount: (container) => {
|
|
24
|
-
const el = container;
|
|
25
|
-
const root = el._opacaReactRoot;
|
|
26
|
-
if (root) {
|
|
27
|
-
setTimeout(() => {
|
|
28
|
-
root.unmount();
|
|
29
|
-
delete el._opacaReactRoot;
|
|
30
|
-
}, 0);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { defineReactField };
|
package/dist/chunk-d3ffeqp9.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
// src/client.ts
|
|
2
|
-
class OpacaError extends Error {
|
|
3
|
-
status;
|
|
4
|
-
data;
|
|
5
|
-
constructor(message, status, data = {}) {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "OpacaError";
|
|
8
|
-
this.status = status;
|
|
9
|
-
this.data = data;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function createClient(configOrOptions) {
|
|
13
|
-
const options = configOrOptions.serverURL ? { baseURL: configOrOptions.serverURL } : configOrOptions;
|
|
14
|
-
const baseURL = options.baseURL.replace(/\/$/, "");
|
|
15
|
-
const getHeaders = () => {
|
|
16
|
-
const headers = {
|
|
17
|
-
"Content-Type": "application/json"
|
|
18
|
-
};
|
|
19
|
-
if (options.token) {
|
|
20
|
-
headers.Authorization = `Bearer ${options.token}`;
|
|
21
|
-
}
|
|
22
|
-
return headers;
|
|
23
|
-
};
|
|
24
|
-
const fetcher = async (path, init) => {
|
|
25
|
-
const res = await fetch(`${baseURL}${path}`, {
|
|
26
|
-
...init,
|
|
27
|
-
credentials: "include",
|
|
28
|
-
headers: {
|
|
29
|
-
...getHeaders(),
|
|
30
|
-
...init?.headers
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
if (!res.ok) {
|
|
34
|
-
const errorData = await res.json().catch(() => ({}));
|
|
35
|
-
throw new OpacaError(errorData.message || `API Error: ${res.status}`, res.status, errorData);
|
|
36
|
-
}
|
|
37
|
-
return res.json();
|
|
38
|
-
};
|
|
39
|
-
const client = {
|
|
40
|
-
getMetadata: () => fetcher("/api/__admin/metadata"),
|
|
41
|
-
getCollections: () => fetcher("/api/__admin/collections"),
|
|
42
|
-
getSetupStatus: () => fetcher("/api/__admin/setup"),
|
|
43
|
-
collections: new Proxy({}, {
|
|
44
|
-
get(_, collectionSlug) {
|
|
45
|
-
return {
|
|
46
|
-
find: (query) => {
|
|
47
|
-
const searchParams = new URLSearchParams;
|
|
48
|
-
if (query) {
|
|
49
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
50
|
-
searchParams.append(key, typeof value === "object" ? JSON.stringify(value) : String(value));
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
const queryString = searchParams.toString();
|
|
54
|
-
return fetcher(`/api/${String(collectionSlug)}${queryString ? `?${queryString}` : ""}`);
|
|
55
|
-
},
|
|
56
|
-
findOne: (id) => fetcher(`/api/${String(collectionSlug)}/${id}`),
|
|
57
|
-
list: () => fetcher(`/api/${String(collectionSlug)}`),
|
|
58
|
-
create: (data) => fetcher(`/api/${String(collectionSlug)}`, {
|
|
59
|
-
method: "POST",
|
|
60
|
-
body: JSON.stringify(data)
|
|
61
|
-
}),
|
|
62
|
-
update: (id, data) => fetcher(`/api/${String(collectionSlug)}/${id}`, {
|
|
63
|
-
method: "PATCH",
|
|
64
|
-
body: JSON.stringify(data)
|
|
65
|
-
}),
|
|
66
|
-
delete: (id) => fetcher(`/api/${String(collectionSlug)}/${id}`, {
|
|
67
|
-
method: "DELETE"
|
|
68
|
-
})
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
}),
|
|
72
|
-
globals: new Proxy({}, {
|
|
73
|
-
get(_, globalSlug) {
|
|
74
|
-
return {
|
|
75
|
-
get: () => fetcher(`/api/globals/${String(globalSlug)}`),
|
|
76
|
-
update: (data) => fetcher(`/api/globals/${String(globalSlug)}`, {
|
|
77
|
-
method: "PATCH",
|
|
78
|
-
body: JSON.stringify(data)
|
|
79
|
-
})
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
})
|
|
83
|
-
};
|
|
84
|
-
return client;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export { OpacaError, createClient };
|
package/dist/chunk-fj19qccp.js
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
pluginSyncCommand
|
|
3
|
-
} from "./chunk-twpvxfce.js";
|
|
4
|
-
import {
|
|
5
|
-
logger
|
|
6
|
-
} from "./chunk-t0zg026p.js";
|
|
7
|
-
import {
|
|
8
|
-
__require
|
|
9
|
-
} from "./chunk-8sqjbsgt.js";
|
|
10
|
-
|
|
11
|
-
// src/cli/commands/plugin-build.ts
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import path from "node:path";
|
|
14
|
-
async function pluginBuildCommand(projectRoot) {
|
|
15
|
-
const srcDir = path.resolve(projectRoot, "src");
|
|
16
|
-
const distDir = path.resolve(projectRoot, "dist");
|
|
17
|
-
if (!fs.existsSync(srcDir)) {
|
|
18
|
-
logger.error(`No 'src' directory found in ${projectRoot}.`);
|
|
19
|
-
process.exit(1);
|
|
20
|
-
}
|
|
21
|
-
logger.info("Syncing plugin UI...");
|
|
22
|
-
await pluginSyncCommand(projectRoot, false);
|
|
23
|
-
const entryFiles = ["index.tsx", "index.ts", "plugin.tsx", "plugin.ts"];
|
|
24
|
-
let mainEntry = "";
|
|
25
|
-
for (const file of entryFiles) {
|
|
26
|
-
const fullPath = path.join(srcDir, file);
|
|
27
|
-
if (fs.existsSync(fullPath)) {
|
|
28
|
-
mainEntry = fullPath;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (!mainEntry) {
|
|
33
|
-
logger.error(`Could not find a main entry file in ${srcDir}`);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
logger.info(`Building plugin entry: ${path.basename(mainEntry)}...`);
|
|
37
|
-
if (!fs.existsSync(distDir)) {
|
|
38
|
-
fs.mkdirSync(distDir, { recursive: true });
|
|
39
|
-
}
|
|
40
|
-
const buildResult = await Bun.build({
|
|
41
|
-
entrypoints: [mainEntry],
|
|
42
|
-
outdir: distDir,
|
|
43
|
-
target: "node",
|
|
44
|
-
format: "esm",
|
|
45
|
-
external: [
|
|
46
|
-
"opacacms",
|
|
47
|
-
"opacacms/types",
|
|
48
|
-
"opacacms/plugins",
|
|
49
|
-
"opacacms/schema",
|
|
50
|
-
"hono",
|
|
51
|
-
"zod",
|
|
52
|
-
"react",
|
|
53
|
-
"react-dom"
|
|
54
|
-
]
|
|
55
|
-
});
|
|
56
|
-
if (!buildResult.success) {
|
|
57
|
-
logger.error("Plugin build failed.");
|
|
58
|
-
for (const msg of buildResult.logs) {
|
|
59
|
-
console.error(msg);
|
|
60
|
-
}
|
|
61
|
-
process.exit(1);
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
logger.info("Generating type declarations...");
|
|
65
|
-
const { execSync } = await import("node:child_process");
|
|
66
|
-
execSync("bunx tsc --emitDeclarationOnly --outDir dist", {
|
|
67
|
-
cwd: projectRoot,
|
|
68
|
-
stdio: "ignore"
|
|
69
|
-
});
|
|
70
|
-
logger.success("Types generated.");
|
|
71
|
-
} catch (err) {
|
|
72
|
-
logger.warn("Failed to generate types. Make sure typescript is installed.");
|
|
73
|
-
}
|
|
74
|
-
logger.success(`Plugin built successfully in ${distDir}!`);
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
pluginBuildCommand
|
|
78
|
-
};
|
package/dist/chunk-g1jb60xd.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-8sqjbsgt.js";
|
|
4
|
-
|
|
5
|
-
// src/cli/commands/seed-command.ts
|
|
6
|
-
async function seedCommand(opaca, count, reset, type) {
|
|
7
|
-
const { autoSeed } = await import("./chunk-jdfw4v3r.js");
|
|
8
|
-
try {
|
|
9
|
-
await autoSeed(opaca, count, reset, type);
|
|
10
|
-
} catch (error) {
|
|
11
|
-
console.error(`[OpacaCMS] Seeding failed: ${error.message}`);
|
|
12
|
-
throw error;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
seedCommand
|
|
17
|
-
};
|
package/dist/chunk-j53pz21t.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
$isAuthPending,
|
|
3
|
-
$isAuthenticated,
|
|
4
|
-
$session,
|
|
5
|
-
$user,
|
|
6
|
-
login,
|
|
7
|
-
logout,
|
|
8
|
-
syncSession
|
|
9
|
-
} from "./chunk-byq8g0rd.js";
|
|
10
|
-
import"./chunk-8scgdznr.js";
|
|
11
|
-
import"./chunk-8sqjbsgt.js";
|
|
12
|
-
export {
|
|
13
|
-
syncSession,
|
|
14
|
-
logout,
|
|
15
|
-
login,
|
|
16
|
-
$user,
|
|
17
|
-
$session,
|
|
18
|
-
$isAuthenticated,
|
|
19
|
-
$isAuthPending
|
|
20
|
-
};
|
package/dist/chunk-mkn49zmy.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
logger
|
|
3
|
-
} from "./chunk-t0zg026p.js";
|
|
4
|
-
import"./chunk-8sqjbsgt.js";
|
|
5
|
-
|
|
6
|
-
// src/cli/commands/plugin-init.ts
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import path from "node:path";
|
|
9
|
-
async function pluginInitCommand(pluginName) {
|
|
10
|
-
if (!pluginName) {
|
|
11
|
-
logger.error("Please provide a plugin name. Usage: opacacms plugin:init <plugin_name>");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
const targetDir = path.resolve(process.cwd(), pluginName);
|
|
15
|
-
if (fs.existsSync(targetDir)) {
|
|
16
|
-
logger.error(`Directory ${targetDir} already exists.`);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
}
|
|
19
|
-
logger.info(`Initializing new plugin in ${targetDir}...`);
|
|
20
|
-
fs.mkdirSync(targetDir, { recursive: true });
|
|
21
|
-
fs.mkdirSync(path.join(targetDir, "src"), { recursive: true });
|
|
22
|
-
const packageJson = {
|
|
23
|
-
name: pluginName,
|
|
24
|
-
version: "1.0.0",
|
|
25
|
-
description: "An OpacaCMS plugin",
|
|
26
|
-
main: "dist/index.js",
|
|
27
|
-
types: "dist/index.d.ts",
|
|
28
|
-
scripts: {
|
|
29
|
-
build: "opacacms plugin:build",
|
|
30
|
-
dev: "bun run build --watch"
|
|
31
|
-
},
|
|
32
|
-
peerDependencies: {
|
|
33
|
-
opacacms: "workspace:*"
|
|
34
|
-
},
|
|
35
|
-
devDependencies: {
|
|
36
|
-
typescript: "^5.0.0",
|
|
37
|
-
"@types/node": "^20.0.0"
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
fs.writeFileSync(path.join(targetDir, "package.json"), JSON.stringify(packageJson, null, 2), "utf-8");
|
|
41
|
-
const tsconfig = {
|
|
42
|
-
compilerOptions: {
|
|
43
|
-
target: "ESNext",
|
|
44
|
-
module: "ESNext",
|
|
45
|
-
moduleResolution: "bundler",
|
|
46
|
-
strict: true,
|
|
47
|
-
esModuleInterop: true,
|
|
48
|
-
skipLibCheck: true,
|
|
49
|
-
forceConsistentCasingInFileNames: true,
|
|
50
|
-
outDir: "./dist",
|
|
51
|
-
declaration: true,
|
|
52
|
-
jsx: "react"
|
|
53
|
-
},
|
|
54
|
-
include: ["src/**/*"]
|
|
55
|
-
};
|
|
56
|
-
fs.writeFileSync(path.join(targetDir, "tsconfig.json"), JSON.stringify(tsconfig, null, 2), "utf-8");
|
|
57
|
-
const indexTsx = `import type { OpacaPlugin, OpacaPluginContext } from 'opacacms/types';
|
|
58
|
-
import { definePlugin } from 'opacacms/plugins';
|
|
59
|
-
|
|
60
|
-
export const myPlugin = (): OpacaPlugin => definePlugin({
|
|
61
|
-
name: '${pluginName}',
|
|
62
|
-
label: 'My Custom Plugin',
|
|
63
|
-
description: 'A great new plugin for OpacaCMS.',
|
|
64
|
-
version: '1.0.0',
|
|
65
|
-
icon: 'Box',
|
|
66
|
-
|
|
67
|
-
onInit: (ctx: OpacaPluginContext) => {
|
|
68
|
-
ctx.logger.info('[${pluginName}] Plugin initialized!');
|
|
69
|
-
return ctx.config;
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
adminUI: {
|
|
73
|
-
component: 'my-plugin-dashboard',
|
|
74
|
-
// The CLI will automatically compile dashboard.tsx into this 'source' field during build.
|
|
75
|
-
source: '',
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
`;
|
|
79
|
-
fs.writeFileSync(path.join(targetDir, "src", "index.tsx"), indexTsx, "utf-8");
|
|
80
|
-
const dashboardTsx = `class MyPluginDashboard extends HTMLElement {
|
|
81
|
-
connectedCallback() {
|
|
82
|
-
this.innerHTML = \`
|
|
83
|
-
<div style="padding: 2rem; font-family: sans-serif;">
|
|
84
|
-
<h2>Welcome to ${pluginName} Dashboard!</h2>
|
|
85
|
-
<p>This UI component is built as a self-contained Web Component.</p>
|
|
86
|
-
</div>
|
|
87
|
-
\`;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
customElements.define('my-plugin-dashboard', MyPluginDashboard);
|
|
92
|
-
`;
|
|
93
|
-
fs.writeFileSync(path.join(targetDir, "src", "dashboard.tsx"), dashboardTsx, "utf-8");
|
|
94
|
-
logger.success(`Plugin ${pluginName} initialized successfully!`);
|
|
95
|
-
logger.info(`Next steps:
|
|
96
|
-
cd ${pluginName}
|
|
97
|
-
bun install
|
|
98
|
-
bun run build`);
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
pluginInitCommand
|
|
102
|
-
};
|
package/dist/chunk-r39em4yj.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
defineCustomField
|
|
3
|
-
} from "./chunk-rqyjjqgy.js";
|
|
4
|
-
|
|
5
|
-
// src/admin/vue.tsx
|
|
6
|
-
function defineVueField(tagName, Component, options) {
|
|
7
|
-
defineCustomField(tagName, {
|
|
8
|
-
mount: (container, props) => {
|
|
9
|
-
const app = options.createApp(Component, props);
|
|
10
|
-
container._opacaVueApp = app;
|
|
11
|
-
app.mount(container);
|
|
12
|
-
},
|
|
13
|
-
update: (container, props) => {
|
|
14
|
-
const app = container._opacaVueApp;
|
|
15
|
-
if (app && app._instance) {
|
|
16
|
-
Object.assign(app._instance.props, props);
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
unmount: (container) => {
|
|
20
|
-
const app = container._opacaVueApp;
|
|
21
|
-
if (app) {
|
|
22
|
-
app.unmount();
|
|
23
|
-
delete container._opacaVueApp;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export { defineVueField };
|