opacacms 0.2.0 → 0.3.0

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 (187) hide show
  1. package/README.md +31 -22
  2. package/dist/admin/auth-client.d.ts +39 -39
  3. package/dist/admin/index.d.ts +2 -2
  4. package/dist/admin/index.js +15 -10520
  5. package/dist/admin/plugin-client.d.ts +65 -0
  6. package/dist/admin/react.d.ts +2 -2
  7. package/dist/admin/react.js +34 -4
  8. package/dist/admin/stores/ui.d.ts +19 -4
  9. package/dist/admin/ui/components/PluginSettingsForm.d.ts +2 -2
  10. package/dist/admin/ui/components/custom-alert.d.ts +7 -0
  11. package/dist/admin/ui/components/{DetailSheet.d.ts → detail-sheet.d.ts} +1 -2
  12. package/dist/admin/ui/components/fields/FieldLabel.d.ts +1 -1
  13. package/dist/admin/ui/components/fields/RelationshipField.d.ts +1 -1
  14. package/dist/admin/ui/components/media/AssetManagerModal.d.ts +2 -2
  15. package/dist/admin/ui/components/plugin-iframe.d.ts +7 -0
  16. package/dist/admin/ui/components/ui/accordion.d.ts +17 -7
  17. package/dist/admin/ui/components/ui/alert-dialog.d.ts +16 -12
  18. package/dist/admin/ui/components/ui/button.d.ts +11 -7
  19. package/dist/admin/ui/components/ui/relationship.d.ts +1 -1
  20. package/dist/admin/ui/components/ui/sheet.d.ts +14 -27
  21. package/dist/admin/ui/components/ui/tooltip.d.ts +7 -0
  22. package/dist/admin/ui/components/versions-sheet.d.ts +4 -5
  23. package/dist/admin/ui/views/collection-list-view.d.ts +1 -1
  24. package/dist/admin/ui/views/dashboard-view.d.ts +1 -1
  25. package/dist/admin/ui/views/media-registry-view.d.ts +3 -3
  26. package/dist/admin/ui/views/settings-view.d.ts +2 -2
  27. package/dist/admin/vue.js +27 -4
  28. package/dist/admin/webcomponent.js +20 -2
  29. package/dist/admin.css +1 -1
  30. package/dist/auth/index.d.ts +43 -43
  31. package/dist/{chunk-7y1nbmw6.js → chunk-1bd7fz7n.js} +32 -2
  32. package/dist/chunk-1qm0m8r8.js +413 -0
  33. package/dist/chunk-2k3ysje3.js +31 -0
  34. package/dist/chunk-3j9zjfmn.js +376 -0
  35. package/dist/{chunk-byq8g0rd.js → chunk-48ywpd0a.js} +16 -22
  36. package/dist/{chunk-esrg9qj0.js → chunk-5422w4eq.js} +70 -54
  37. package/dist/chunk-56n342hs.js +95 -0
  38. package/dist/chunk-5b8r0v8c.js +47 -0
  39. package/dist/chunk-63yg00vx.js +263 -0
  40. package/dist/{chunk-8sqjbsgt.js → chunk-6bywt602.js} +26 -1
  41. package/dist/{chunk-v9z61v3g.js → chunk-6qs0g65f.js} +43 -3
  42. package/dist/chunk-7rr5p01g.js +581 -0
  43. package/dist/{chunk-51z3x7kq.js → chunk-a3qae86h.js} +1 -1
  44. package/dist/{chunk-3rdhbedb.js → chunk-adq2b75c.js} +2 -2
  45. package/dist/chunk-d0tb1xjw.js +93 -0
  46. package/dist/chunk-d7cgd6vn.js +318 -0
  47. package/dist/{chunk-0bq155dy.js → chunk-e0g6gn7n.js} +89 -100
  48. package/dist/chunk-ec4jhybj.js +1137 -0
  49. package/dist/chunk-fatyf6f7.js +221 -0
  50. package/dist/{chunk-526a3gqx.js → chunk-fnsf1dfm.js} +1 -1
  51. package/dist/chunk-g9bxb6h0.js +205 -0
  52. package/dist/chunk-gyaf5kgf.js +10 -0
  53. package/dist/{chunk-9kxpbcb1.js → chunk-h6dhexzr.js} +16 -7
  54. package/dist/{chunk-dykn5hr6.js → chunk-j8js1y0h.js} +31 -74
  55. package/dist/{chunk-t0zg026p.js → chunk-jq1drsen.js} +12 -1
  56. package/dist/{chunk-b3kr8w41.js → chunk-m24yqkeq.js} +38 -26
  57. package/dist/chunk-m5ems3hh.js +410 -0
  58. package/dist/{chunk-8scgdznr.js → chunk-m83ybzf8.js} +15 -18
  59. package/dist/chunk-majsbncm.js +98 -0
  60. package/dist/chunk-mp2gt9yh.js +237 -0
  61. package/dist/chunk-n1twhqmf.js +54 -0
  62. package/dist/{chunk-gmee4mdc.js → chunk-naqcqj8n.js} +92 -106
  63. package/dist/chunk-q5sb5dcr.js +15 -0
  64. package/dist/{chunk-d1asgtke.js → chunk-qhdsjek6.js} +90 -121
  65. package/dist/{chunk-0gtxnxmd.js → chunk-qsh2nqz3.js} +85 -105
  66. package/dist/chunk-r0ms5tk1.js +76 -0
  67. package/dist/chunk-rwqwsanx.js +75 -0
  68. package/dist/chunk-sqsfk9p4.js +700 -0
  69. package/dist/{chunk-5gvbp2qa.js → chunk-x7bnzswh.js} +25 -18
  70. package/dist/{chunk-kc4jfnv7.js → chunk-z3ffn2b7.js} +851 -324
  71. package/dist/cli/commands/dev.d.ts +8 -0
  72. package/dist/cli/commands/doctor.d.ts +8 -0
  73. package/dist/cli/commands/generate.d.ts +26 -0
  74. package/dist/cli/commands/init.d.ts +13 -1
  75. package/dist/cli/commands/migrate.d.ts +33 -0
  76. package/dist/cli/commands/plugin.d.ts +13 -0
  77. package/dist/cli/commands/seed.d.ts +21 -0
  78. package/dist/cli/{commands/migrate-commands.d.ts → core/migrations/migrate-logic.d.ts} +2 -2
  79. package/dist/cli/core/migrations/schema-diff-engine.d.ts +12 -0
  80. package/dist/cli/core/migrations/schema-diff.d.ts +11 -0
  81. package/dist/cli/{seeding.d.ts → core/seeding/auto-seed.d.ts} +7 -4
  82. package/dist/cli/core/seeding/seed-logic.d.ts +2 -0
  83. package/dist/cli/index.d.ts +4 -0
  84. package/dist/cli/index.js +6 -170
  85. package/dist/client/RichText.d.ts +5 -0
  86. package/dist/client/rich-text-utils.d.ts +5 -0
  87. package/dist/client.js +3 -2
  88. package/dist/config.d.ts +3 -3
  89. package/dist/db/adapter.d.ts +2 -2
  90. package/dist/db/better-sqlite.d.ts +3 -3
  91. package/dist/db/better-sqlite.js +6 -5
  92. package/dist/db/bun-sqlite.d.ts +3 -3
  93. package/dist/db/bun-sqlite.js +6 -5
  94. package/dist/db/d1.d.ts +13 -7
  95. package/dist/db/d1.js +6 -5
  96. package/dist/db/index.d.ts +2 -2
  97. package/dist/db/index.js +10 -12
  98. package/dist/db/kysely/factory.d.ts +29 -0
  99. package/dist/db/kysely/plugins/audit-logging.d.ts +48 -0
  100. package/dist/db/kysely/plugins/auto-timestamps.d.ts +38 -0
  101. package/dist/db/kysely/plugins/cursor-pagination.d.ts +42 -0
  102. package/dist/db/kysely/plugins/deadlock-handler.d.ts +47 -0
  103. package/dist/db/kysely/plugins/draft-swapper.d.ts +33 -0
  104. package/dist/db/kysely/plugins/field-masking.d.ts +45 -0
  105. package/dist/db/kysely/plugins/fts-normalizer.d.ts +38 -0
  106. package/dist/db/kysely/plugins/i18n-fallback.d.ts +48 -0
  107. package/dist/db/kysely/plugins/id-generation.d.ts +42 -0
  108. package/dist/db/kysely/plugins/index.d.ts +16 -0
  109. package/dist/db/kysely/plugins/json-flattener.d.ts +38 -0
  110. package/dist/db/kysely/plugins/relationship-preloading.d.ts +39 -0
  111. package/dist/db/kysely/plugins/slug-generation.d.ts +37 -0
  112. package/dist/db/kysely/plugins/soft-delete.d.ts +42 -0
  113. package/dist/db/kysely/plugins/tree-resolver.d.ts +39 -0
  114. package/dist/db/kysely/plugins/virtual-field-resolver.d.ts +54 -0
  115. package/dist/db/kysely/plugins/zod-coercion.d.ts +34 -0
  116. package/dist/db/kysely/snapshot/snapshot-manager.d.ts +18 -0
  117. package/dist/db/postgres.d.ts +4 -4
  118. package/dist/db/postgres.js +6 -5
  119. package/dist/db/sqlite.d.ts +3 -3
  120. package/dist/db/sqlite.js +6 -5
  121. package/dist/index.d.ts +3 -0
  122. package/dist/index.js +161 -7
  123. package/dist/runtimes/bun.js +9 -6
  124. package/dist/runtimes/cloudflare-workers.d.ts +3 -1
  125. package/dist/runtimes/cloudflare-workers.js +36 -7
  126. package/dist/runtimes/next.js +8 -5
  127. package/dist/runtimes/node.js +9 -6
  128. package/dist/schema/collection.d.ts +116 -70
  129. package/dist/schema/compiler.d.ts +6 -0
  130. package/dist/schema/global.d.ts +38 -71
  131. package/dist/schema/index.d.ts +5 -4
  132. package/dist/schema/index.js +35 -550
  133. package/dist/schema/zod.d.ts +564 -0
  134. package/dist/server/admin-router.d.ts +1 -1
  135. package/dist/server/collection-router.d.ts +1 -1
  136. package/dist/server/graphql.d.ts +6 -0
  137. package/dist/server/handlers.d.ts +25 -7
  138. package/dist/server/middlewares/auth.d.ts +1 -1
  139. package/dist/server/plugins-loader.d.ts +1 -1
  140. package/dist/server/router.d.ts +2 -2
  141. package/dist/server/routers/admin.d.ts +1 -1
  142. package/dist/server/routers/auth.d.ts +1 -1
  143. package/dist/server/routers/collections.d.ts +4 -1
  144. package/dist/server/routers/plugins.d.ts +2 -2
  145. package/dist/server/setup-middlewares.d.ts +1 -1
  146. package/dist/server/system-router.d.ts +1 -1
  147. package/dist/server.js +11 -6
  148. package/dist/storage/adapters/cloudflare-r2.d.ts +11 -2
  149. package/dist/storage/index.js +39 -30
  150. package/dist/types.d.ts +255 -44
  151. package/dist/utils/context.d.ts +14 -0
  152. package/dist/utils/logger.d.ts +2 -0
  153. package/dist/utils/string.d.ts +10 -0
  154. package/dist/utils/webhooks-engine.d.ts +24 -0
  155. package/dist/validation.d.ts +67 -1
  156. package/dist/validator.d.ts +1 -0
  157. package/package.json +36 -33
  158. package/src/cli/index.ts +117 -0
  159. package/dist/chunk-6qq3ne6b.js +0 -288
  160. package/dist/chunk-6v1fw7q7.js +0 -126
  161. package/dist/chunk-7a9kn0np.js +0 -116
  162. package/dist/chunk-bexcv7xe.js +0 -36
  163. package/dist/chunk-d3ffeqp9.js +0 -87
  164. package/dist/chunk-fj19qccp.js +0 -78
  165. package/dist/chunk-j53pz21t.js +0 -20
  166. package/dist/chunk-mkn49zmy.js +0 -102
  167. package/dist/chunk-qb6ztvw9.js +0 -17
  168. package/dist/chunk-r39em4yj.js +0 -29
  169. package/dist/chunk-rsf0tpy1.js +0 -8
  170. package/dist/chunk-srsac177.js +0 -85
  171. package/dist/chunk-swtcpvhf.js +0 -2442
  172. package/dist/chunk-twpvxfce.js +0 -64
  173. package/dist/chunk-ywm4t2gm.js +0 -19
  174. package/dist/cli/commands/plugin-sync.d.ts +0 -1
  175. package/dist/cli/commands/seed-command.d.ts +0 -2
  176. package/dist/plugins/ui-bridge.d.ts +0 -12
  177. package/dist/schema/fields/base.d.ts +0 -84
  178. package/dist/schema/fields/index.d.ts +0 -147
  179. package/dist/schema/infer.d.ts +0 -55
  180. /package/dist/admin/ui/components/{ColumnVisibilityToggle.d.ts → column-visibility-toggle.d.ts} +0 -0
  181. /package/dist/admin/ui/components/{DataDetailView.d.ts → data-detail-view.d.ts} +0 -0
  182. /package/dist/cli/{d1-mock.d.ts → core/mocks/d1-mock.d.ts} +0 -0
  183. /package/dist/cli/{r2-mock.d.ts → core/mocks/r2-mock.d.ts} +0 -0
  184. /package/dist/cli/{commands → core/plugins}/plugin-build.d.ts +0 -0
  185. /package/dist/cli/{commands → core/plugins}/plugin-init.d.ts +0 -0
  186. /package/dist/cli/{commands → core/types}/generate-types.d.ts +0 -0
  187. /package/dist/{schema/fields/validation.test.d.ts → cli/seeding.test.d.ts} +0 -0
@@ -0,0 +1,376 @@
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,6 +1,7 @@
1
1
  import {
2
2
  notify
3
- } from "./chunk-8scgdznr.js";
3
+ } from "./chunk-m83ybzf8.js";
4
+ import"./chunk-6bywt602.js";
4
5
 
5
6
  // src/admin/stores/auth.ts
6
7
  import { atom, computed } from "nanostores";
@@ -9,24 +10,6 @@ import { atom, computed } from "nanostores";
9
10
  import { createAuthClient } from "better-auth/client";
10
11
  import { adminClient } from "better-auth/client/plugins";
11
12
  var client = null;
12
- var currentURL = null;
13
- var configureAuth = (serverUrl) => {
14
- if (!serverUrl || !serverUrl.startsWith("http"))
15
- return;
16
- const url = serverUrl;
17
- const baseURL = url.replace(/\/$/, "") + "/api/auth";
18
- if (client && currentURL === baseURL)
19
- return;
20
- currentURL = baseURL;
21
- client = createAuthClient({
22
- baseURL,
23
- autoRefresh: true,
24
- fetchOptions: {
25
- credentials: "include"
26
- },
27
- plugins: [adminClient()]
28
- });
29
- };
30
13
  var authClient = new Proxy({}, {
31
14
  get(_, prop) {
32
15
  if (!client) {
@@ -62,7 +45,11 @@ async function login(data) {
62
45
  if (res.error) {
63
46
  throw new Error(res.error.message || "Invalid credentials");
64
47
  }
65
- await syncSession();
48
+ if (res.data) {
49
+ $session.set(res.data);
50
+ } else {
51
+ await syncSession();
52
+ }
66
53
  notify("Logged in successfully", "success");
67
54
  return res;
68
55
  } catch (error) {
@@ -84,5 +71,12 @@ async function logout() {
84
71
  $isAuthPending.set(false);
85
72
  }
86
73
  }
87
-
88
- export { configureAuth, authClient, $session, $isAuthPending, $user, $isAuthenticated, syncSession, login, logout };
74
+ export {
75
+ syncSession,
76
+ logout,
77
+ login,
78
+ $user,
79
+ $session,
80
+ $isAuthenticated,
81
+ $isAuthPending
82
+ };