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.
Files changed (59) hide show
  1. package/dist/admin/auth-client.d.ts +41 -41
  2. package/dist/admin/index.js +1 -1
  3. package/dist/admin/react.js +1 -1
  4. package/dist/admin/vue.js +1 -1
  5. package/dist/auth/index.d.ts +43 -48
  6. package/dist/{chunk-g9bxb6h0.js → chunk-2fm4kv2q.js} +1 -1
  7. package/dist/chunk-2vbfc4q8.js +6 -0
  8. package/dist/{chunk-adq2b75c.js → chunk-40tky6qh.js} +2 -2
  9. package/dist/{chunk-e0g6gn7n.js → chunk-49e16hjg.js} +3 -3
  10. package/dist/{chunk-fnsf1dfm.js → chunk-526a3gqx.js} +1 -1
  11. package/dist/{chunk-sqsfk9p4.js → chunk-6m1jhxmd.js} +1 -1
  12. package/dist/{chunk-6bywt602.js → chunk-8sqjbsgt.js} +1 -26
  13. package/dist/{chunk-n1twhqmf.js → chunk-acghejk8.js} +1 -1
  14. package/dist/{chunk-m24yqkeq.js → chunk-b1g8jmth.js} +3 -3
  15. package/dist/{chunk-5422w4eq.js → chunk-cm5rvcnn.js} +5 -5
  16. package/dist/{chunk-941zxavt.js → chunk-h2y2t07h.js} +4 -4
  17. package/dist/{chunk-6qs0g65f.js → chunk-h8v093av.js} +1 -1
  18. package/dist/{chunk-m5ems3hh.js → chunk-hthm9srb.js} +1 -1
  19. package/dist/{chunk-2k3ysje3.js → chunk-nch158fe.js} +1 -1
  20. package/dist/{chunk-naqcqj8n.js → chunk-pj31j6j0.js} +4 -4
  21. package/dist/{chunk-qsh2nqz3.js → chunk-pw2a9war.js} +3 -3
  22. package/dist/{chunk-j8js1y0h.js → chunk-r5k7jw66.js} +1 -1
  23. package/dist/{chunk-48ywpd0a.js → chunk-vmz9ncf1.js} +1 -1
  24. package/dist/{chunk-qhdsjek6.js → chunk-wry3rqh0.js} +3 -3
  25. package/dist/cli/commands/init.d.ts +1 -6
  26. package/dist/cli/index.js +6793 -6
  27. package/dist/client.js +3 -3
  28. package/dist/db/better-sqlite.js +4 -4
  29. package/dist/db/bun-sqlite.js +4 -4
  30. package/dist/db/d1.js +4 -4
  31. package/dist/db/index.js +8 -8
  32. package/dist/db/postgres.js +4 -4
  33. package/dist/db/sqlite.js +4 -4
  34. package/dist/index.js +7 -7
  35. package/dist/runtimes/bun.js +6 -6
  36. package/dist/runtimes/cloudflare-workers.js +6 -6
  37. package/dist/runtimes/next.js +6 -6
  38. package/dist/runtimes/node.js +6 -6
  39. package/dist/schema/index.js +3 -3
  40. package/dist/server.js +6 -6
  41. package/dist/storage/index.js +1 -1
  42. package/package.json +4 -2
  43. package/dist/chunk-1qm0m8r8.js +0 -413
  44. package/dist/chunk-3j9zjfmn.js +0 -376
  45. package/dist/chunk-56n342hs.js +0 -95
  46. package/dist/chunk-5b8r0v8c.js +0 -47
  47. package/dist/chunk-63yg00vx.js +0 -263
  48. package/dist/chunk-7rr5p01g.js +0 -581
  49. package/dist/chunk-d0tb1xjw.js +0 -93
  50. package/dist/chunk-d7cgd6vn.js +0 -318
  51. package/dist/chunk-ec4jhybj.js +0 -1137
  52. package/dist/chunk-fatyf6f7.js +0 -221
  53. package/dist/chunk-gyaf5kgf.js +0 -10
  54. package/dist/chunk-h6dhexzr.js +0 -94
  55. package/dist/chunk-majsbncm.js +0 -98
  56. package/dist/chunk-mp2gt9yh.js +0 -237
  57. package/dist/chunk-r0ms5tk1.js +0 -76
  58. package/dist/chunk-rwqwsanx.js +0 -75
  59. package/dist/chunk-x7bnzswh.js +0 -174
@@ -1,376 +0,0 @@
1
- import {
2
- logger
3
- } from "./chunk-jq1drsen.js";
4
- import {
5
- __require
6
- } from "./chunk-6bywt602.js";
7
-
8
- // src/cli/core/seeding/auto-seed.ts
9
- import { faker } from "@faker-js/faker";
10
- var defaultFieldGenerators = {
11
- text: () => faker.lorem.words(3),
12
- textarea: () => faker.lorem.paragraph(),
13
- number: () => faker.number.int({ min: 1, max: 1000 }),
14
- richtext: () => JSON.stringify({
15
- root: {
16
- children: [
17
- {
18
- children: [
19
- {
20
- detail: 0,
21
- format: 0,
22
- mode: "normal",
23
- style: "",
24
- text: faker.lorem.sentence(),
25
- type: "text",
26
- version: 1
27
- }
28
- ],
29
- direction: "ltr",
30
- format: "",
31
- indent: 0,
32
- type: "heading",
33
- tag: "h1",
34
- version: 1
35
- },
36
- {
37
- children: [
38
- {
39
- detail: 0,
40
- format: 0,
41
- mode: "normal",
42
- style: "",
43
- text: faker.lorem.paragraphs(2),
44
- type: "text",
45
- version: 1
46
- }
47
- ],
48
- direction: "ltr",
49
- format: "",
50
- indent: 0,
51
- type: "paragraph",
52
- version: 1
53
- }
54
- ],
55
- direction: "ltr",
56
- format: "",
57
- indent: 0,
58
- type: "root",
59
- version: 1
60
- }
61
- }),
62
- boolean: () => faker.datatype.boolean(),
63
- date: () => faker.date.recent().toISOString(),
64
- email: () => faker.internet.email(),
65
- json: () => ({ [faker.lorem.word()]: faker.lorem.sentence() }),
66
- select: () => faker.lorem.word(),
67
- radio: () => faker.lorem.word(),
68
- blocks: () => []
69
- };
70
- async function getRandomIds(db, relationTo, count = 1) {
71
- const tryFetch = async (target) => {
72
- try {
73
- const result = await db.find(target, {}, { limit: 50 });
74
- return result.docs || [];
75
- } catch (e) {
76
- const msg = String(e.message || e).toLowerCase();
77
- if (msg.includes("no such table"))
78
- return null;
79
- throw e;
80
- }
81
- };
82
- try {
83
- let docs = await tryFetch(relationTo);
84
- if (docs === null && relationTo === "users") {
85
- docs = await tryFetch("_users");
86
- }
87
- if (!docs || docs.length === 0) {
88
- if (!relationTo.startsWith("_") && docs !== null) {
89
- console.warn(`[Seeding] No documents found in '${relationTo}' for relationship.`);
90
- }
91
- return [];
92
- }
93
- if (docs.length === 0) {
94
- if (!relationTo.startsWith("_")) {
95
- console.warn(`[Seeding] No documents found in '${relationTo}' for relationship.`);
96
- }
97
- return [];
98
- }
99
- const shuffled = [...docs].sort(() => 0.5 - Math.random());
100
- const selected = shuffled.slice(0, count).map((doc) => doc.id);
101
- return selected;
102
- } catch (_e) {
103
- return [];
104
- }
105
- }
106
- async function generateDataForFields(fields, db, locales = []) {
107
- const record = {};
108
- for (const field of fields) {
109
- if (field.type === "row" || field.type === "collapsible") {
110
- Object.assign(record, await generateDataForFields(field.fields, db, locales));
111
- continue;
112
- }
113
- if (field.type === "tabs") {
114
- for (const tab of field.tabs) {
115
- Object.assign(record, await generateDataForFields(tab.fields, db, locales));
116
- }
117
- continue;
118
- }
119
- if (field.type === "group" && field.name) {
120
- record[field.name] = await generateDataForFields(field.fields, db, locales);
121
- continue;
122
- }
123
- if (field.name) {
124
- const isLocalized = !!field.localized && locales.length > 0;
125
- const generateFieldValue = async () => {
126
- if (field.type === "relationship" && "relationTo" in field) {
127
- if (field.hasMany) {
128
- const count = faker.number.int({ min: 1, max: 3 });
129
- return await getRandomIds(db, field.relationTo, count);
130
- }
131
- const ids = await getRandomIds(db, field.relationTo, 1);
132
- return ids[0] || null;
133
- }
134
- if (field.type === "blocks" && field.blocks) {
135
- const blockCount = faker.number.int({ min: 1, max: 3 });
136
- const generatedBlocks = [];
137
- for (let i = 0;i < blockCount; i++) {
138
- const blockType = field.blocks[faker.number.int({ min: 0, max: field.blocks.length - 1 })];
139
- if (!blockType)
140
- continue;
141
- const blockData = await generateDataForFields(blockType.fields, db, locales);
142
- generatedBlocks.push({
143
- ...blockData,
144
- blockType: blockType.slug,
145
- id: faker.string.uuid()
146
- });
147
- }
148
- return generatedBlocks;
149
- }
150
- const generator = defaultFieldGenerators[field.type];
151
- if (generator) {
152
- if (field.type === "select" || field.type === "radio") {
153
- const options = field.options;
154
- const choices = options?.choices || [];
155
- if (choices.length > 0) {
156
- const choice = choices[Math.floor(Math.random() * choices.length)];
157
- if (choice) {
158
- return typeof choice === "string" ? choice : choice.value;
159
- }
160
- }
161
- }
162
- return generator();
163
- }
164
- return null;
165
- };
166
- if (isLocalized) {
167
- const localizedValue = {};
168
- for (const locale of locales) {
169
- localizedValue[locale] = await generateFieldValue();
170
- }
171
- record[field.name] = localizedValue;
172
- } else {
173
- record[field.name] = await generateFieldValue();
174
- }
175
- }
176
- }
177
- return record;
178
- }
179
- async function generateRecord(db, collection, locales = []) {
180
- const autoData = await generateDataForFields(collection.fields, db, locales);
181
- if (collection.seed && typeof collection.seed === "function") {
182
- const seedData = await collection.seed(faker);
183
- return { ...autoData, ...seedData };
184
- }
185
- return autoData;
186
- }
187
- function sortCollections(collections) {
188
- const sorted = [];
189
- const visited = new Set;
190
- const visiting = new Set;
191
- const visit = (collection) => {
192
- if (visited.has(collection.slug))
193
- return;
194
- if (visiting.has(collection.slug)) {
195
- throw new Error(`Circular dependency detected: ${collection.slug}`);
196
- }
197
- visiting.add(collection.slug);
198
- const deps = [];
199
- const findDeps = (fields) => {
200
- for (const f of fields) {
201
- if (f.type === "relationship" && "relationTo" in f) {
202
- deps.push(f.relationTo);
203
- } else if (f.type === "blocks" && f.blocks) {
204
- for (const b of f.blocks) {
205
- findDeps(b.fields);
206
- }
207
- } else if ("fields" in f && f.fields) {
208
- findDeps(f.fields);
209
- } else if ("tabs" in f && f.tabs) {
210
- for (const t of f.tabs) {
211
- findDeps(t.fields);
212
- }
213
- }
214
- }
215
- };
216
- findDeps(collection.fields);
217
- for (const depSlug of deps) {
218
- const depColl = collections.find((c) => c.slug === depSlug);
219
- if (depColl)
220
- visit(depColl);
221
- }
222
- visiting.delete(collection.slug);
223
- visited.add(collection.slug);
224
- sorted.push(collection);
225
- };
226
- for (const collection of collections) {
227
- visit(collection);
228
- }
229
- return sorted;
230
- }
231
- async function autoSeed(config, countPerCollection = 10, reset = false, type = "all", targetTable) {
232
- const { collections, db, globals, storages, serverURL } = config;
233
- const locales = config.i18n?.locales || [];
234
- logger.info(`Starting automatic seed (${logger.bold(countPerCollection.toString())} records per collection)...`);
235
- const { getSystemCollections } = await import("./chunk-adq2b75c.js");
236
- const systemCollections = getSystemCollections().filter((c) => c.slug === "_assets");
237
- const allCollections = [...systemCollections, ...collections];
238
- let collectionsToSeed = sortCollections(allCollections);
239
- if (type === "assets") {
240
- collectionsToSeed = collectionsToSeed.filter((c) => c.slug === "_assets");
241
- logger.info("\uD83D\uDCC1 Seeding only assets...");
242
- } else if (type === "collections") {
243
- collectionsToSeed = collectionsToSeed.filter((c) => c.slug !== "_assets");
244
- logger.info("\uD83D\uDCDA Seeding user collections...");
245
- }
246
- if (targetTable) {
247
- collectionsToSeed = collectionsToSeed.filter((c) => c.slug === targetTable);
248
- if (collectionsToSeed.length === 0) {
249
- console.warn(`[OpacaCMS] Collection/Table "${targetTable}" not found in schema. Skipping...`);
250
- return;
251
- }
252
- } else {
253
- collectionsToSeed = collectionsToSeed.filter((c) => c.seed && typeof c.seed === "function" || c.slug === "_assets" || c.slug === "users" || c.slug === "_users");
254
- logger.info(`\uD83D\uDD0D Seeding ${logger.bold(collectionsToSeed.length.toString())} collections with custom seed logic...`);
255
- }
256
- await db.connect();
257
- await db.migrate(allCollections, globals || []);
258
- try {
259
- if (reset) {
260
- logger.info("\uD83E\uDDF9 Resetting data (cleaning existing records)...");
261
- const reversed = [...collectionsToSeed].reverse();
262
- for (const collection of reversed) {
263
- logger.log(` ${logger.format("gray", "delete")} ${collection.slug}`);
264
- await db.deleteMany?.(collection.slug, {});
265
- }
266
- }
267
- const storageAdapter = storages.default || storages;
268
- for (const collection of collectionsToSeed) {
269
- logger.info(`Seeding ${logger.bold(collection.slug)}...`);
270
- const isAssetCollection = collection.slug === "_assets";
271
- for (let i = 0;i < countPerCollection; i++) {
272
- let data;
273
- if (isAssetCollection) {
274
- const id = faker.string.uuid();
275
- const width = faker.number.int({ min: 400, max: 1200 });
276
- const height = faker.number.int({ min: 300, max: 800 });
277
- const color = faker.color.rgb({ prefix: "" });
278
- const textColor = faker.color.rgb({ prefix: "" });
279
- const usePicsum = Math.random() > 0.5;
280
- let imageUrl = "";
281
- if (usePicsum) {
282
- const categories = ["nature", "city", "tech", "people", "animals", "architecture"];
283
- const category = faker.helpers.arrayElement(categories);
284
- imageUrl = `https://picsum.photos/seed/${category}-${id}/${width}/${height}`;
285
- } else {
286
- imageUrl = `https://placehold.co/${width}x${height}/${color}/${textColor}.png?text=Seed+${i}`;
287
- }
288
- const res = await fetch(imageUrl);
289
- if (!res.ok) {
290
- throw new Error(`Failed to fetch placeholder image: ${imageUrl}`);
291
- }
292
- const arrayBuffer = await res.arrayBuffer();
293
- const mime_type = res.headers.get("content-type")?.split(";")[0] || "image/png";
294
- const extMap = {
295
- "image/jpeg": "jpg",
296
- "image/png": "png",
297
- "image/webp": "webp",
298
- "image/gif": "gif",
299
- "image/svg+xml": "svg"
300
- };
301
- const ext = extMap[mime_type] || "png";
302
- const fileRecord = {
303
- filename: `seed-image-${i}.${ext}`,
304
- original_filename: `seed-image-${i}.${ext}`,
305
- mime_type,
306
- filesize: arrayBuffer.byteLength,
307
- buffer: new Uint8Array(arrayBuffer)
308
- };
309
- const uploadAdapter = storageAdapter;
310
- const uploaded = await uploadAdapter.upload(fileRecord, {
311
- generateUniqueName: true,
312
- customMetadata: {
313
- sourceUrl: imageUrl
314
- }
315
- });
316
- data = {
317
- id,
318
- key: uploaded.filename,
319
- filename: uploaded.filename,
320
- originalFilename: fileRecord.original_filename,
321
- mimeType: uploaded.mime_type,
322
- filesize: uploaded.filesize,
323
- width,
324
- height,
325
- bucket: "default",
326
- url: uploaded.url,
327
- thumbnailUrl: uploaded.url,
328
- altText: faker.lorem.sentence()
329
- };
330
- const baseURL = serverURL || "http://localhost:8787";
331
- logger.debug(`[Asset] Source: ${imageUrl}`);
332
- logger.debug(`[Asset] Seeded: ${baseURL}/api/assets/${id}/view (${uploaded.filename})`);
333
- } else {
334
- data = await generateRecord(db, collection, locales);
335
- }
336
- await db.create(collection.slug, data);
337
- }
338
- }
339
- if (globals && globals.length > 0) {
340
- logger.info("\uD83C\uDF0D Seeding globals...");
341
- for (const global of globals) {
342
- if (!targetTable && (!global.seed || typeof global.seed !== "function")) {
343
- continue;
344
- }
345
- logger.info(`Seeding global ${logger.bold(global.slug)}...`);
346
- const autoData = await generateDataForFields(global.fields, db, locales);
347
- let data;
348
- if (global.seed && typeof global.seed === "function") {
349
- const seedData = await global.seed(faker);
350
- data = { ...autoData, ...seedData };
351
- } else {
352
- data = autoData;
353
- }
354
- const existing = await db.find(global.slug, {}, { limit: 1 });
355
- if (existing.docs && existing.docs.length > 0) {
356
- if (reset) {
357
- await db.deleteMany?.(global.slug, {});
358
- await db.create(global.slug, data);
359
- } else {
360
- await db.update(global.slug, existing.docs[0].id, data);
361
- }
362
- } else {
363
- await db.create(global.slug, data);
364
- }
365
- }
366
- }
367
- logger.success("Seeding completed successfully! ✨");
368
- } finally {}
369
- }
370
- export {
371
- sortCollections,
372
- getRandomIds,
373
- generateRecord,
374
- defaultFieldGenerators,
375
- autoSeed
376
- };
@@ -1,95 +0,0 @@
1
- import {
2
- require_picocolors
3
- } from "./chunk-rwqwsanx.js";
4
- import {
5
- Gt,
6
- R,
7
- Vt,
8
- Wt,
9
- be
10
- } from "./chunk-ec4jhybj.js";
11
- import {
12
- loadConfig,
13
- resolveConfigPath
14
- } from "./chunk-majsbncm.js";
15
- import {
16
- defineCommand
17
- } from "./chunk-1qm0m8r8.js";
18
- import {
19
- __toESM
20
- } from "./chunk-6bywt602.js";
21
-
22
- // src/cli/commands/doctor.ts
23
- import fs from "node:fs";
24
- var import_picocolors = __toESM(require_picocolors(), 1);
25
- var doctor_default = defineCommand({
26
- meta: {
27
- name: "doctor",
28
- description: "Diagnose your OpacaCMS project configuration and database connection"
29
- },
30
- args: {
31
- config: {
32
- type: "string",
33
- alias: "c",
34
- description: "Path to the OpacaCMS configuration file"
35
- }
36
- },
37
- async run({ args }) {
38
- console.log();
39
- Wt(import_picocolors.default.bgMagenta(import_picocolors.default.white(" OpacaCMS Doctor ")));
40
- const s = be();
41
- s.start("Locating configuration file...");
42
- let configPath;
43
- try {
44
- configPath = resolveConfigPath(args.config);
45
- s.stop(`Config found at ${import_picocolors.default.green(configPath)}`);
46
- } catch (err) {
47
- s.stop(import_picocolors.default.red("Config file not found."));
48
- R.error("Could not find opacacms.config.ts or similar.");
49
- Gt(import_picocolors.default.red("Diagnosis failed."));
50
- process.exit(1);
51
- }
52
- s.start("Loading configuration...");
53
- let opaca;
54
- try {
55
- opaca = await loadConfig(configPath);
56
- s.stop(`Configuration loaded successfully. App Name: ${import_picocolors.default.cyan(opaca.appName || "Unknown")}`);
57
- } catch (err) {
58
- s.stop(import_picocolors.default.red("Failed to load configuration."));
59
- R.error(err.message);
60
- Gt(import_picocolors.default.red("Diagnosis failed."));
61
- process.exit(1);
62
- }
63
- s.start("Verifying database connection...");
64
- try {
65
- if (!opaca.db)
66
- throw new Error("No database configured in config.db");
67
- const tables = await opaca.db.kysely.introspection.getTables();
68
- s.stop(`Database connected successfully. Found ${import_picocolors.default.green(tables.length)} tables.`);
69
- } catch (err) {
70
- s.stop(import_picocolors.default.red("Database connection failed."));
71
- R.error(err.message);
72
- }
73
- s.start("Checking dependencies...");
74
- try {
75
- const pkgPath = `${process.cwd()}/package.json`;
76
- if (fs.existsSync(pkgPath)) {
77
- const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
78
- const deps = { ...pkg.dependencies, ...pkg.devDependencies };
79
- if (!deps.opacacms) {
80
- R.warn(import_picocolors.default.yellow("opacacms is missing from package.json"));
81
- }
82
- s.stop(`Dependencies checked.`);
83
- } else {
84
- s.stop(import_picocolors.default.yellow("package.json not found."));
85
- }
86
- } catch (err) {
87
- s.stop(import_picocolors.default.red("Error checking dependencies."));
88
- }
89
- Vt(`Everything seems to be in order! Run \`opacacms dev\` to start.`, "Diagnosis Complete");
90
- Gt("Doctor out.");
91
- }
92
- });
93
- export {
94
- doctor_default as default
95
- };
@@ -1,47 +0,0 @@
1
- // src/utils/string.ts
2
- function sanitizeGraphQLName(name) {
3
- return name.replace(/[^_a-zA-Z0-9]/g, "_");
4
- }
5
- function getRandomMigrationName() {
6
- const adjectives = [
7
- "vibrant",
8
- "snarky",
9
- "brave",
10
- "swift",
11
- "silent",
12
- "funky",
13
- "mystic",
14
- "loyal",
15
- "nimble",
16
- "eager",
17
- "wild",
18
- "chill",
19
- "golden",
20
- "magic",
21
- "smart",
22
- "fierce"
23
- ];
24
- const nouns = [
25
- "vulture",
26
- "badger",
27
- "falcon",
28
- "otter",
29
- "lynx",
30
- "panda",
31
- "fox",
32
- "lemur",
33
- "cobra",
34
- "whale",
35
- "eagle",
36
- "tiger",
37
- "koala",
38
- "bison",
39
- "raven",
40
- "shark"
41
- ];
42
- const adj = adjectives[Math.floor(Math.random() * adjectives.length)];
43
- const noun = nouns[Math.floor(Math.random() * nouns.length)];
44
- return `${adj}_${noun}`;
45
- }
46
-
47
- export { sanitizeGraphQLName, getRandomMigrationName };