opacacms 0.2.1 → 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 (185) 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 +16 -16
  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-jdfw4v3r.js → chunk-3j9zjfmn.js} +95 -30
  35. package/dist/{chunk-byq8g0rd.js → chunk-48ywpd0a.js} +16 -22
  36. package/dist/{chunk-tfnaf41w.js → chunk-5422w4eq.js} +41 -25
  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-6d1vdfwa.js → chunk-e0g6gn7n.js} +54 -75
  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-bygjkgrx.js → chunk-naqcqj8n.js} +57 -80
  63. package/dist/chunk-q5sb5dcr.js +15 -0
  64. package/dist/{chunk-06ks4ggh.js → chunk-qhdsjek6.js} +49 -89
  65. package/dist/{chunk-n133qpsm.js → chunk-qsh2nqz3.js} +50 -81
  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-2es275xs.js → chunk-z3ffn2b7.js} +834 -307
  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/better-sqlite.d.ts +2 -3
  90. package/dist/db/better-sqlite.js +6 -5
  91. package/dist/db/bun-sqlite.d.ts +2 -3
  92. package/dist/db/bun-sqlite.js +6 -5
  93. package/dist/db/d1.d.ts +13 -7
  94. package/dist/db/d1.js +6 -5
  95. package/dist/db/index.d.ts +2 -2
  96. package/dist/db/index.js +10 -12
  97. package/dist/db/kysely/factory.d.ts +29 -0
  98. package/dist/db/kysely/plugins/audit-logging.d.ts +48 -0
  99. package/dist/db/kysely/plugins/auto-timestamps.d.ts +38 -0
  100. package/dist/db/kysely/plugins/cursor-pagination.d.ts +42 -0
  101. package/dist/db/kysely/plugins/deadlock-handler.d.ts +47 -0
  102. package/dist/db/kysely/plugins/draft-swapper.d.ts +33 -0
  103. package/dist/db/kysely/plugins/field-masking.d.ts +45 -0
  104. package/dist/db/kysely/plugins/fts-normalizer.d.ts +38 -0
  105. package/dist/db/kysely/plugins/i18n-fallback.d.ts +48 -0
  106. package/dist/db/kysely/plugins/id-generation.d.ts +42 -0
  107. package/dist/db/kysely/plugins/index.d.ts +16 -0
  108. package/dist/db/kysely/plugins/json-flattener.d.ts +38 -0
  109. package/dist/db/kysely/plugins/relationship-preloading.d.ts +39 -0
  110. package/dist/db/kysely/plugins/slug-generation.d.ts +37 -0
  111. package/dist/db/kysely/plugins/soft-delete.d.ts +42 -0
  112. package/dist/db/kysely/plugins/tree-resolver.d.ts +39 -0
  113. package/dist/db/kysely/plugins/virtual-field-resolver.d.ts +54 -0
  114. package/dist/db/kysely/plugins/zod-coercion.d.ts +34 -0
  115. package/dist/db/kysely/snapshot/snapshot-manager.d.ts +18 -0
  116. package/dist/db/postgres.d.ts +2 -2
  117. package/dist/db/postgres.js +6 -5
  118. package/dist/db/sqlite.d.ts +2 -3
  119. package/dist/db/sqlite.js +6 -5
  120. package/dist/index.d.ts +3 -0
  121. package/dist/index.js +161 -7
  122. package/dist/runtimes/bun.js +9 -6
  123. package/dist/runtimes/cloudflare-workers.d.ts +3 -1
  124. package/dist/runtimes/cloudflare-workers.js +36 -7
  125. package/dist/runtimes/next.js +8 -5
  126. package/dist/runtimes/node.js +9 -6
  127. package/dist/schema/collection.d.ts +116 -70
  128. package/dist/schema/compiler.d.ts +6 -0
  129. package/dist/schema/global.d.ts +38 -71
  130. package/dist/schema/index.d.ts +5 -4
  131. package/dist/schema/index.js +35 -550
  132. package/dist/schema/zod.d.ts +564 -0
  133. package/dist/server/admin-router.d.ts +1 -1
  134. package/dist/server/collection-router.d.ts +1 -1
  135. package/dist/server/graphql.d.ts +6 -0
  136. package/dist/server/handlers.d.ts +25 -7
  137. package/dist/server/middlewares/auth.d.ts +1 -1
  138. package/dist/server/plugins-loader.d.ts +1 -1
  139. package/dist/server/router.d.ts +2 -2
  140. package/dist/server/routers/admin.d.ts +1 -1
  141. package/dist/server/routers/auth.d.ts +1 -1
  142. package/dist/server/routers/collections.d.ts +4 -1
  143. package/dist/server/routers/plugins.d.ts +2 -2
  144. package/dist/server/setup-middlewares.d.ts +1 -1
  145. package/dist/server/system-router.d.ts +1 -1
  146. package/dist/server.js +11 -6
  147. package/dist/storage/adapters/cloudflare-r2.d.ts +11 -2
  148. package/dist/storage/index.js +5 -5
  149. package/dist/types.d.ts +253 -42
  150. package/dist/utils/context.d.ts +14 -0
  151. package/dist/utils/logger.d.ts +2 -0
  152. package/dist/utils/string.d.ts +10 -0
  153. package/dist/utils/webhooks-engine.d.ts +24 -0
  154. package/dist/validation.d.ts +67 -1
  155. package/dist/validator.d.ts +1 -0
  156. package/package.json +11 -8
  157. package/src/cli/index.ts +117 -0
  158. package/dist/chunk-6qq3ne6b.js +0 -288
  159. package/dist/chunk-6v1fw7q7.js +0 -126
  160. package/dist/chunk-7a9kn0np.js +0 -116
  161. package/dist/chunk-bexcv7xe.js +0 -36
  162. package/dist/chunk-d3ffeqp9.js +0 -87
  163. package/dist/chunk-fj19qccp.js +0 -78
  164. package/dist/chunk-g1jb60xd.js +0 -17
  165. package/dist/chunk-j53pz21t.js +0 -20
  166. package/dist/chunk-mkn49zmy.js +0 -102
  167. package/dist/chunk-r39em4yj.js +0 -29
  168. package/dist/chunk-rsf0tpy1.js +0 -8
  169. package/dist/chunk-srsac177.js +0 -85
  170. package/dist/chunk-twpvxfce.js +0 -64
  171. package/dist/chunk-ywm4t2gm.js +0 -19
  172. package/dist/cli/commands/plugin-sync.d.ts +0 -1
  173. package/dist/cli/commands/seed-command.d.ts +0 -2
  174. package/dist/plugins/ui-bridge.d.ts +0 -12
  175. package/dist/schema/fields/base.d.ts +0 -84
  176. package/dist/schema/fields/index.d.ts +0 -147
  177. package/dist/schema/infer.d.ts +0 -55
  178. /package/dist/admin/ui/components/{ColumnVisibilityToggle.d.ts → column-visibility-toggle.d.ts} +0 -0
  179. /package/dist/admin/ui/components/{DataDetailView.d.ts → data-detail-view.d.ts} +0 -0
  180. /package/dist/cli/{d1-mock.d.ts → core/mocks/d1-mock.d.ts} +0 -0
  181. /package/dist/cli/{r2-mock.d.ts → core/mocks/r2-mock.d.ts} +0 -0
  182. /package/dist/cli/{commands → core/plugins}/plugin-build.d.ts +0 -0
  183. /package/dist/cli/{commands → core/plugins}/plugin-init.d.ts +0 -0
  184. /package/dist/cli/{commands → core/types}/generate-types.d.ts +0 -0
  185. /package/dist/{schema/fields/validation.test.d.ts → cli/seeding.test.d.ts} +0 -0
@@ -0,0 +1,413 @@
1
+ // ../../node_modules/citty/dist/_chunks/libs/scule.mjs
2
+ var NUMBER_CHAR_RE = /\d/;
3
+ var STR_SPLITTERS = [
4
+ "-",
5
+ "_",
6
+ "/",
7
+ "."
8
+ ];
9
+ function isUppercase(char = "") {
10
+ if (NUMBER_CHAR_RE.test(char))
11
+ return;
12
+ return char !== char.toLowerCase();
13
+ }
14
+ function splitByCase(str, separators) {
15
+ const splitters = separators ?? STR_SPLITTERS;
16
+ const parts = [];
17
+ if (!str || typeof str !== "string")
18
+ return parts;
19
+ let buff = "";
20
+ let previousUpper;
21
+ let previousSplitter;
22
+ for (const char of str) {
23
+ const isSplitter = splitters.includes(char);
24
+ if (isSplitter === true) {
25
+ parts.push(buff);
26
+ buff = "";
27
+ previousUpper = undefined;
28
+ continue;
29
+ }
30
+ const isUpper = isUppercase(char);
31
+ if (previousSplitter === false) {
32
+ if (previousUpper === false && isUpper === true) {
33
+ parts.push(buff);
34
+ buff = char;
35
+ previousUpper = isUpper;
36
+ continue;
37
+ }
38
+ if (previousUpper === true && isUpper === false && buff.length > 1) {
39
+ const lastChar = buff.at(-1);
40
+ parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
41
+ buff = lastChar + char;
42
+ previousUpper = isUpper;
43
+ continue;
44
+ }
45
+ }
46
+ buff += char;
47
+ previousUpper = isUpper;
48
+ previousSplitter = isSplitter;
49
+ }
50
+ parts.push(buff);
51
+ return parts;
52
+ }
53
+ function upperFirst(str) {
54
+ return str ? str[0].toUpperCase() + str.slice(1) : "";
55
+ }
56
+ function lowerFirst(str) {
57
+ return str ? str[0].toLowerCase() + str.slice(1) : "";
58
+ }
59
+ function pascalCase(str, opts) {
60
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
61
+ }
62
+ function camelCase(str, opts) {
63
+ return lowerFirst(pascalCase(str || "", opts));
64
+ }
65
+ function kebabCase(str, joiner) {
66
+ return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
67
+ }
68
+
69
+ // ../../node_modules/citty/dist/index.mjs
70
+ import { parseArgs as parseArgs$1 } from "node:util";
71
+ function toArray(val) {
72
+ if (Array.isArray(val))
73
+ return val;
74
+ return val === undefined ? [] : [val];
75
+ }
76
+ function formatLineColumns(lines, linePrefix = "") {
77
+ const maxLength = [];
78
+ for (const line of lines)
79
+ for (const [i, element] of line.entries())
80
+ maxLength[i] = Math.max(maxLength[i] || 0, element.length);
81
+ return lines.map((l) => l.map((c, i) => linePrefix + c[i === 0 ? "padStart" : "padEnd"](maxLength[i])).join(" ")).join(`
82
+ `);
83
+ }
84
+ function resolveValue(input) {
85
+ return typeof input === "function" ? input() : input;
86
+ }
87
+ var CLIError = class extends Error {
88
+ code;
89
+ constructor(message, code) {
90
+ super(message);
91
+ this.name = "CLIError";
92
+ this.code = code;
93
+ }
94
+ };
95
+ function parseRawArgs(args = [], opts = {}) {
96
+ const booleans = new Set(opts.boolean || []);
97
+ const strings = new Set(opts.string || []);
98
+ const aliasMap = opts.alias || {};
99
+ const defaults = opts.default || {};
100
+ const aliasToMain = /* @__PURE__ */ new Map;
101
+ const mainToAliases = /* @__PURE__ */ new Map;
102
+ for (const [key, value] of Object.entries(aliasMap)) {
103
+ const targets = value;
104
+ for (const target of targets) {
105
+ aliasToMain.set(key, target);
106
+ if (!mainToAliases.has(target))
107
+ mainToAliases.set(target, []);
108
+ mainToAliases.get(target).push(key);
109
+ aliasToMain.set(target, key);
110
+ if (!mainToAliases.has(key))
111
+ mainToAliases.set(key, []);
112
+ mainToAliases.get(key).push(target);
113
+ }
114
+ }
115
+ const options = {};
116
+ function getType(name) {
117
+ if (booleans.has(name))
118
+ return "boolean";
119
+ const aliases = mainToAliases.get(name) || [];
120
+ for (const alias of aliases)
121
+ if (booleans.has(alias))
122
+ return "boolean";
123
+ return "string";
124
+ }
125
+ const allOptions = new Set([
126
+ ...booleans,
127
+ ...strings,
128
+ ...Object.keys(aliasMap),
129
+ ...Object.values(aliasMap).flat(),
130
+ ...Object.keys(defaults)
131
+ ]);
132
+ for (const name of allOptions)
133
+ if (!options[name])
134
+ options[name] = {
135
+ type: getType(name),
136
+ default: defaults[name]
137
+ };
138
+ for (const [alias, main] of aliasToMain.entries())
139
+ if (alias.length === 1 && options[main] && !options[main].short)
140
+ options[main].short = alias;
141
+ const processedArgs = [];
142
+ const negatedFlags = {};
143
+ for (let i = 0;i < args.length; i++) {
144
+ const arg = args[i];
145
+ if (arg === "--") {
146
+ processedArgs.push(...args.slice(i));
147
+ break;
148
+ }
149
+ if (arg.startsWith("--no-")) {
150
+ const flagName = arg.slice(5);
151
+ negatedFlags[flagName] = true;
152
+ continue;
153
+ }
154
+ processedArgs.push(arg);
155
+ }
156
+ let parsed;
157
+ try {
158
+ parsed = parseArgs$1({
159
+ args: processedArgs,
160
+ options: Object.keys(options).length > 0 ? options : undefined,
161
+ allowPositionals: true,
162
+ strict: false
163
+ });
164
+ } catch {
165
+ parsed = {
166
+ values: {},
167
+ positionals: processedArgs
168
+ };
169
+ }
170
+ const out = { _: [] };
171
+ out._ = parsed.positionals;
172
+ for (const [key, value] of Object.entries(parsed.values))
173
+ out[key] = value;
174
+ for (const [name] of Object.entries(negatedFlags)) {
175
+ out[name] = false;
176
+ const mainName = aliasToMain.get(name);
177
+ if (mainName)
178
+ out[mainName] = false;
179
+ const aliases = mainToAliases.get(name);
180
+ if (aliases)
181
+ for (const alias of aliases)
182
+ out[alias] = false;
183
+ }
184
+ for (const [alias, main] of aliasToMain.entries()) {
185
+ if (out[alias] !== undefined && out[main] === undefined)
186
+ out[main] = out[alias];
187
+ if (out[main] !== undefined && out[alias] === undefined)
188
+ out[alias] = out[main];
189
+ }
190
+ return out;
191
+ }
192
+ var noColor = /* @__PURE__ */ (() => {
193
+ const env = globalThis.process?.env ?? {};
194
+ return env.NO_COLOR === "1" || env.TERM === "dumb" || env.TEST || env.CI;
195
+ })();
196
+ var _c = (c, r = 39) => (t) => noColor ? t : `\x1B[${c}m${t}\x1B[${r}m`;
197
+ var bold = /* @__PURE__ */ _c(1, 22);
198
+ var cyan = /* @__PURE__ */ _c(36);
199
+ var gray = /* @__PURE__ */ _c(90);
200
+ var underline = /* @__PURE__ */ _c(4, 24);
201
+ function parseArgs(rawArgs, argsDef) {
202
+ const parseOptions = {
203
+ boolean: [],
204
+ string: [],
205
+ alias: {},
206
+ default: {}
207
+ };
208
+ const args = resolveArgs(argsDef);
209
+ for (const arg of args) {
210
+ if (arg.type === "positional")
211
+ continue;
212
+ if (arg.type === "string" || arg.type === "enum")
213
+ parseOptions.string.push(arg.name);
214
+ else if (arg.type === "boolean")
215
+ parseOptions.boolean.push(arg.name);
216
+ if (arg.default !== undefined)
217
+ parseOptions.default[arg.name] = arg.default;
218
+ if (arg.alias)
219
+ parseOptions.alias[arg.name] = arg.alias;
220
+ const camelName = camelCase(arg.name);
221
+ const kebabName = kebabCase(arg.name);
222
+ if (camelName !== arg.name || kebabName !== arg.name) {
223
+ const existingAliases = toArray(parseOptions.alias[arg.name] || []);
224
+ if (camelName !== arg.name && !existingAliases.includes(camelName))
225
+ existingAliases.push(camelName);
226
+ if (kebabName !== arg.name && !existingAliases.includes(kebabName))
227
+ existingAliases.push(kebabName);
228
+ if (existingAliases.length > 0)
229
+ parseOptions.alias[arg.name] = existingAliases;
230
+ }
231
+ }
232
+ const parsed = parseRawArgs(rawArgs, parseOptions);
233
+ const [...positionalArguments] = parsed._;
234
+ const parsedArgsProxy = new Proxy(parsed, { get(target, prop) {
235
+ return target[prop] ?? target[camelCase(prop)] ?? target[kebabCase(prop)];
236
+ } });
237
+ for (const [, arg] of args.entries())
238
+ if (arg.type === "positional") {
239
+ const nextPositionalArgument = positionalArguments.shift();
240
+ if (nextPositionalArgument !== undefined)
241
+ parsedArgsProxy[arg.name] = nextPositionalArgument;
242
+ else if (arg.default === undefined && arg.required !== false)
243
+ throw new CLIError(`Missing required positional argument: ${arg.name.toUpperCase()}`, "EARG");
244
+ else
245
+ parsedArgsProxy[arg.name] = arg.default;
246
+ } else if (arg.type === "enum") {
247
+ const argument = parsedArgsProxy[arg.name];
248
+ const options = arg.options || [];
249
+ if (argument !== undefined && options.length > 0 && !options.includes(argument))
250
+ throw new CLIError(`Invalid value for argument: ${cyan(`--${arg.name}`)} (${cyan(argument)}). Expected one of: ${options.map((o) => cyan(o)).join(", ")}.`, "EARG");
251
+ } else if (arg.required && parsedArgsProxy[arg.name] === undefined)
252
+ throw new CLIError(`Missing required argument: --${arg.name}`, "EARG");
253
+ return parsedArgsProxy;
254
+ }
255
+ function resolveArgs(argsDef) {
256
+ const args = [];
257
+ for (const [name, argDef] of Object.entries(argsDef || {}))
258
+ args.push({
259
+ ...argDef,
260
+ name,
261
+ alias: toArray(argDef.alias)
262
+ });
263
+ return args;
264
+ }
265
+ function defineCommand(def) {
266
+ return def;
267
+ }
268
+ async function runCommand(cmd, opts) {
269
+ const cmdArgs = await resolveValue(cmd.args || {});
270
+ const parsedArgs = parseArgs(opts.rawArgs, cmdArgs);
271
+ const context = {
272
+ rawArgs: opts.rawArgs,
273
+ args: parsedArgs,
274
+ data: opts.data,
275
+ cmd
276
+ };
277
+ if (typeof cmd.setup === "function")
278
+ await cmd.setup(context);
279
+ let result;
280
+ try {
281
+ const subCommands = await resolveValue(cmd.subCommands);
282
+ if (subCommands && Object.keys(subCommands).length > 0) {
283
+ const subCommandArgIndex = opts.rawArgs.findIndex((arg) => !arg.startsWith("-"));
284
+ const subCommandName = opts.rawArgs[subCommandArgIndex];
285
+ if (subCommandName) {
286
+ if (!subCommands[subCommandName])
287
+ throw new CLIError(`Unknown command ${cyan(subCommandName)}`, "E_UNKNOWN_COMMAND");
288
+ const subCommand = await resolveValue(subCommands[subCommandName]);
289
+ if (subCommand)
290
+ await runCommand(subCommand, { rawArgs: opts.rawArgs.slice(subCommandArgIndex + 1) });
291
+ } else if (!cmd.run)
292
+ throw new CLIError(`No command specified.`, "E_NO_COMMAND");
293
+ }
294
+ if (typeof cmd.run === "function")
295
+ result = await cmd.run(context);
296
+ } finally {
297
+ if (typeof cmd.cleanup === "function")
298
+ await cmd.cleanup(context);
299
+ }
300
+ return { result };
301
+ }
302
+ async function resolveSubCommand(cmd, rawArgs, parent) {
303
+ const subCommands = await resolveValue(cmd.subCommands);
304
+ if (subCommands && Object.keys(subCommands).length > 0) {
305
+ const subCommandArgIndex = rawArgs.findIndex((arg) => !arg.startsWith("-"));
306
+ const subCommandName = rawArgs[subCommandArgIndex];
307
+ const subCommand = await resolveValue(subCommands[subCommandName]);
308
+ if (subCommand)
309
+ return resolveSubCommand(subCommand, rawArgs.slice(subCommandArgIndex + 1), cmd);
310
+ }
311
+ return [cmd, parent];
312
+ }
313
+ async function showUsage(cmd, parent) {
314
+ try {
315
+ console.log(await renderUsage(cmd, parent) + `
316
+ `);
317
+ } catch (error) {
318
+ console.error(error);
319
+ }
320
+ }
321
+ var negativePrefixRe = /^no[-A-Z]/;
322
+ async function renderUsage(cmd, parent) {
323
+ const cmdMeta = await resolveValue(cmd.meta || {});
324
+ const cmdArgs = resolveArgs(await resolveValue(cmd.args || {}));
325
+ const parentMeta = await resolveValue(parent?.meta || {});
326
+ const commandName = `${parentMeta.name ? `${parentMeta.name} ` : ""}` + (cmdMeta.name || process.argv[1]);
327
+ const argLines = [];
328
+ const posLines = [];
329
+ const commandsLines = [];
330
+ const usageLine = [];
331
+ for (const arg of cmdArgs)
332
+ if (arg.type === "positional") {
333
+ const name = arg.name.toUpperCase();
334
+ const isRequired = arg.required !== false && arg.default === undefined;
335
+ const defaultHint = arg.default ? `="${arg.default}"` : "";
336
+ posLines.push([
337
+ cyan(name + defaultHint),
338
+ arg.description || "",
339
+ arg.valueHint ? `<${arg.valueHint}>` : ""
340
+ ]);
341
+ usageLine.push(isRequired ? `<${name}>` : `[${name}]`);
342
+ } else {
343
+ const isRequired = arg.required === true && arg.default === undefined;
344
+ const argStr = [...(arg.alias || []).map((a) => `-${a}`), `--${arg.name}`].join(", ") + (arg.type === "string" && (arg.valueHint || arg.default) ? `=${arg.valueHint ? `<${arg.valueHint}>` : `"${arg.default || ""}"`}` : "") + (arg.type === "enum" && arg.options ? `=<${arg.options.join("|")}>` : "");
345
+ argLines.push([cyan(argStr + (isRequired ? " (required)" : "")), arg.description || ""]);
346
+ if (arg.type === "boolean" && (arg.default === true || arg.negativeDescription) && !negativePrefixRe.test(arg.name)) {
347
+ const negativeArgStr = [...(arg.alias || []).map((a) => `--no-${a}`), `--no-${arg.name}`].join(", ");
348
+ argLines.push([cyan(negativeArgStr + (isRequired ? " (required)" : "")), arg.negativeDescription || ""]);
349
+ }
350
+ if (isRequired)
351
+ usageLine.push(argStr);
352
+ }
353
+ if (cmd.subCommands) {
354
+ const commandNames = [];
355
+ const subCommands = await resolveValue(cmd.subCommands);
356
+ for (const [name, sub] of Object.entries(subCommands)) {
357
+ const meta = await resolveValue((await resolveValue(sub))?.meta);
358
+ if (meta?.hidden)
359
+ continue;
360
+ commandsLines.push([cyan(name), meta?.description || ""]);
361
+ commandNames.push(name);
362
+ }
363
+ usageLine.push(commandNames.join("|"));
364
+ }
365
+ const usageLines = [];
366
+ const version = cmdMeta.version || parentMeta.version;
367
+ usageLines.push(gray(`${cmdMeta.description} (${commandName + (version ? ` v${version}` : "")})`), "");
368
+ const hasOptions = argLines.length > 0 || posLines.length > 0;
369
+ usageLines.push(`${underline(bold("USAGE"))} ${cyan(`${commandName}${hasOptions ? " [OPTIONS]" : ""} ${usageLine.join(" ")}`)}`, "");
370
+ if (posLines.length > 0) {
371
+ usageLines.push(underline(bold("ARGUMENTS")), "");
372
+ usageLines.push(formatLineColumns(posLines, " "));
373
+ usageLines.push("");
374
+ }
375
+ if (argLines.length > 0) {
376
+ usageLines.push(underline(bold("OPTIONS")), "");
377
+ usageLines.push(formatLineColumns(argLines, " "));
378
+ usageLines.push("");
379
+ }
380
+ if (commandsLines.length > 0) {
381
+ usageLines.push(underline(bold("COMMANDS")), "");
382
+ usageLines.push(formatLineColumns(commandsLines, " "));
383
+ usageLines.push("", `Use ${cyan(`${commandName} <command> --help`)} for more information about a command.`);
384
+ }
385
+ return usageLines.filter((l) => typeof l === "string").join(`
386
+ `);
387
+ }
388
+ async function runMain(cmd, opts = {}) {
389
+ const rawArgs = opts.rawArgs || process.argv.slice(2);
390
+ const showUsage$1 = opts.showUsage || showUsage;
391
+ try {
392
+ if (rawArgs.includes("--help") || rawArgs.includes("-h")) {
393
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
394
+ process.exit(0);
395
+ } else if (rawArgs.length === 1 && rawArgs[0] === "--version") {
396
+ const meta = typeof cmd.meta === "function" ? await cmd.meta() : await cmd.meta;
397
+ if (!meta?.version)
398
+ throw new CLIError("No version specified", "E_NO_VERSION");
399
+ console.log(meta.version);
400
+ } else
401
+ await runCommand(cmd, { rawArgs });
402
+ } catch (error) {
403
+ if (error instanceof CLIError) {
404
+ await showUsage$1(...await resolveSubCommand(cmd, rawArgs));
405
+ console.error(error.message);
406
+ } else
407
+ console.error(error, `
408
+ `);
409
+ process.exit(1);
410
+ }
411
+ }
412
+
413
+ export { defineCommand, runMain };
@@ -0,0 +1,31 @@
1
+ import {
2
+ $activeAlert,
3
+ $activeSheet,
4
+ $customSidebarItems,
5
+ $isSidebarCollapsed,
6
+ $toasts,
7
+ clearToast,
8
+ closeAlert,
9
+ closeSheet,
10
+ notify,
11
+ openAlert,
12
+ openSheet,
13
+ registerSidebarItem,
14
+ toggleSidebar
15
+ } from "./chunk-m83ybzf8.js";
16
+ import"./chunk-6bywt602.js";
17
+ export {
18
+ toggleSidebar,
19
+ registerSidebarItem,
20
+ openSheet,
21
+ openAlert,
22
+ notify,
23
+ closeSheet,
24
+ closeAlert,
25
+ clearToast,
26
+ $toasts,
27
+ $isSidebarCollapsed,
28
+ $customSidebarItems,
29
+ $activeSheet,
30
+ $activeAlert
31
+ };
@@ -1,8 +1,11 @@
1
+ import {
2
+ logger
3
+ } from "./chunk-jq1drsen.js";
1
4
  import {
2
5
  __require
3
- } from "./chunk-8sqjbsgt.js";
6
+ } from "./chunk-6bywt602.js";
4
7
 
5
- // src/cli/seeding.ts
8
+ // src/cli/core/seeding/auto-seed.ts
6
9
  import { faker } from "@faker-js/faker";
7
10
  var defaultFieldGenerators = {
8
11
  text: () => faker.lorem.words(3),
@@ -65,9 +68,28 @@ var defaultFieldGenerators = {
65
68
  blocks: () => []
66
69
  };
67
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
+ };
68
82
  try {
69
- const result = await db.find(relationTo, {}, { limit: 50 });
70
- const docs = result.docs || [];
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
+ }
71
93
  if (docs.length === 0) {
72
94
  if (!relationTo.startsWith("_")) {
73
95
  console.warn(`[Seeding] No documents found in '${relationTo}' for relationship.`);
@@ -77,8 +99,7 @@ async function getRandomIds(db, relationTo, count = 1) {
77
99
  const shuffled = [...docs].sort(() => 0.5 - Math.random());
78
100
  const selected = shuffled.slice(0, count).map((doc) => doc.id);
79
101
  return selected;
80
- } catch (e) {
81
- console.error(`[Seeding] Failed to fetch random IDs for ${relationTo}:`, e);
102
+ } catch (_e) {
82
103
  return [];
83
104
  }
84
105
  }
@@ -133,7 +154,9 @@ async function generateDataForFields(fields, db, locales = []) {
133
154
  const choices = options?.choices || [];
134
155
  if (choices.length > 0) {
135
156
  const choice = choices[Math.floor(Math.random() * choices.length)];
136
- return typeof choice === "string" ? choice : choice.value;
157
+ if (choice) {
158
+ return typeof choice === "string" ? choice : choice.value;
159
+ }
137
160
  }
138
161
  }
139
162
  return generator();
@@ -154,7 +177,12 @@ async function generateDataForFields(fields, db, locales = []) {
154
177
  return record;
155
178
  }
156
179
  async function generateRecord(db, collection, locales = []) {
157
- return generateDataForFields(collection.fields, db, 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;
158
186
  }
159
187
  function sortCollections(collections) {
160
188
  const sorted = [];
@@ -170,7 +198,7 @@ function sortCollections(collections) {
170
198
  const deps = [];
171
199
  const findDeps = (fields) => {
172
200
  for (const f of fields) {
173
- if (f.type === "relationship") {
201
+ if (f.type === "relationship" && "relationTo" in f) {
174
202
  deps.push(f.relationTo);
175
203
  } else if (f.type === "blocks" && f.blocks) {
176
204
  for (const b of f.blocks) {
@@ -200,36 +228,46 @@ function sortCollections(collections) {
200
228
  }
201
229
  return sorted;
202
230
  }
203
- async function autoSeed(config, countPerCollection = 10, reset = false, type = "all") {
231
+ async function autoSeed(config, countPerCollection = 10, reset = false, type = "all", targetTable) {
204
232
  const { collections, db, globals, storages, serverURL } = config;
205
- console.log(`\uD83C\uDF31 Starting automatic seed (${countPerCollection} records per collection)...`);
206
- const { getSystemCollections } = await import("./chunk-3rdhbedb.js");
207
- const systemCollections = getSystemCollections().filter((c) => c.slug === "_opaca_assets");
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");
208
237
  const allCollections = [...systemCollections, ...collections];
209
238
  let collectionsToSeed = sortCollections(allCollections);
210
239
  if (type === "assets") {
211
- collectionsToSeed = collectionsToSeed.filter((c) => c.slug === "_opaca_assets");
212
- console.log("\uD83D\uDCC1 Seeding only assets...");
240
+ collectionsToSeed = collectionsToSeed.filter((c) => c.slug === "_assets");
241
+ logger.info("\uD83D\uDCC1 Seeding only assets...");
213
242
  } else if (type === "collections") {
214
- collectionsToSeed = collectionsToSeed.filter((c) => c.slug !== "_opaca_assets");
215
- console.log("\uD83D\uDCDA Seeding only user 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...`);
216
255
  }
217
256
  await db.connect();
218
257
  await db.migrate(allCollections, globals || []);
219
258
  try {
220
259
  if (reset) {
221
- console.log("\uD83E\uDDF9 Resetting data (deleting existing records)...");
260
+ logger.info("\uD83E\uDDF9 Resetting data (cleaning existing records)...");
222
261
  const reversed = [...collectionsToSeed].reverse();
223
262
  for (const collection of reversed) {
224
- console.log(`Cleaning ${collection.slug}...`);
263
+ logger.log(` ${logger.format("gray", "delete")} ${collection.slug}`);
225
264
  await db.deleteMany?.(collection.slug, {});
226
265
  }
227
266
  }
228
- const storageAdapter = storages?.default || storages;
229
- const locales = config.i18n?.locales || [];
267
+ const storageAdapter = storages.default || storages;
230
268
  for (const collection of collectionsToSeed) {
231
- console.log(`Seeding ${collection.slug}...`);
232
- const isAssetCollection = collection.slug === "_opaca_assets";
269
+ logger.info(`Seeding ${logger.bold(collection.slug)}...`);
270
+ const isAssetCollection = collection.slug === "_assets";
233
271
  for (let i = 0;i < countPerCollection; i++) {
234
272
  let data;
235
273
  if (isAssetCollection) {
@@ -268,10 +306,8 @@ async function autoSeed(config, countPerCollection = 10, reset = false, type = "
268
306
  filesize: arrayBuffer.byteLength,
269
307
  buffer: new Uint8Array(arrayBuffer)
270
308
  };
271
- if (!storageAdapter || typeof storageAdapter.upload !== "function") {
272
- throw new Error("Storage adapter is required for seeding assets and must have an 'upload' method.");
273
- }
274
- const uploaded = await storageAdapter.upload(fileRecord, {
309
+ const uploadAdapter = storageAdapter;
310
+ const uploaded = await uploadAdapter.upload(fileRecord, {
275
311
  generateUniqueName: true,
276
312
  customMetadata: {
277
313
  sourceUrl: imageUrl
@@ -292,19 +328,48 @@ async function autoSeed(config, countPerCollection = 10, reset = false, type = "
292
328
  altText: faker.lorem.sentence()
293
329
  };
294
330
  const baseURL = serverURL || "http://localhost:8787";
295
- console.log(`[Asset] Source: ${imageUrl}`);
296
- console.log(`[Asset] Seeded: ${baseURL}/api/assets/${id}/view (${uploaded.filename})`);
331
+ logger.debug(`[Asset] Source: ${imageUrl}`);
332
+ logger.debug(`[Asset] Seeded: ${baseURL}/api/assets/${id}/view (${uploaded.filename})`);
297
333
  } else {
298
334
  data = await generateRecord(db, collection, locales);
299
335
  }
300
336
  await db.create(collection.slug, data);
301
337
  }
302
338
  }
303
- console.log("✅ Seeding completed.");
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! ✨");
304
368
  } finally {}
305
369
  }
306
370
  export {
307
371
  sortCollections,
372
+ getRandomIds,
308
373
  generateRecord,
309
374
  defaultFieldGenerators,
310
375
  autoSeed