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,410 @@
1
+ import {
2
+ __esm,
3
+ __export
4
+ } from "./chunk-6bywt602.js";
5
+
6
+ // src/schema/zod.ts
7
+ import * as zOriginal from "zod";
8
+ var z, $ZodOptional, $ZodNullable, $ZodDefault, $ZodString, $ZodNumber, $ZodBoolean, $ZodDate, $ZodEnum, $ZodObject, $ZodArray, $ZodDiscriminatedUnion;
9
+ var init_zod = __esm(() => {
10
+ zOriginal.ZodType.prototype.unique = function() {
11
+ return this.meta({ opaca: { unique: true } });
12
+ };
13
+ zOriginal.ZodType.prototype.localized = function() {
14
+ return this.meta({ opaca: { localized: true } });
15
+ };
16
+ zOriginal.ZodType.prototype.required = function(condition) {
17
+ if (condition) {
18
+ return this.optional().meta({ opaca: { requiredCondition: condition } });
19
+ }
20
+ return this;
21
+ };
22
+ zOriginal.ZodType.prototype.condition = function(fn) {
23
+ return this.meta({ opaca: { admin: { condition: fn } } });
24
+ };
25
+ zOriginal.ZodType.prototype.cms = function(meta) {
26
+ const current = this.meta() || {};
27
+ return this.meta({
28
+ ...current,
29
+ opaca: {
30
+ ...current.opaca,
31
+ ...meta,
32
+ admin: {
33
+ ...current.opaca?.admin,
34
+ ...meta?.admin
35
+ }
36
+ }
37
+ });
38
+ };
39
+ z = {
40
+ ...zOriginal,
41
+ helpers: (schemaOrType) => {
42
+ return {
43
+ condition: (schema, fn) => schema.condition(fn),
44
+ required: (schema, fn) => schema.required(fn),
45
+ meta: (schema, meta) => {
46
+ let s = schema;
47
+ if (meta.condition)
48
+ s = s.condition(meta.condition);
49
+ if (meta.required)
50
+ s = s.required(meta.required);
51
+ return s.cms(meta);
52
+ },
53
+ cms: function(schema, meta) {
54
+ return this.meta(schema, meta);
55
+ }
56
+ };
57
+ },
58
+ text: (options) => zOriginal.string().meta({
59
+ opaca: {
60
+ unique: options?.unique,
61
+ localized: options?.localized,
62
+ admin: { component: "text", label: options?.label, description: options?.description }
63
+ }
64
+ }),
65
+ slug: (options) => zOriginal.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Invalid slug format").meta({
66
+ opaca: {
67
+ admin: { component: "slug", label: options.label, slugOptions: options }
68
+ }
69
+ }),
70
+ relationship: (collection, options) => {
71
+ const base = zOriginal.string();
72
+ const schema = options?.hasMany ? zOriginal.array(base.optional().nullable()) : base;
73
+ return schema.meta({
74
+ opaca: {
75
+ admin: {
76
+ component: "relationship",
77
+ label: options?.label,
78
+ relationTo: collection,
79
+ hasMany: options?.hasMany || false,
80
+ displayField: options?.displayField
81
+ }
82
+ }
83
+ });
84
+ },
85
+ richText: (options) => zOriginal.union([zOriginal.string(), zOriginal.object({})]).meta({
86
+ opaca: {
87
+ admin: {
88
+ component: "richtext",
89
+ label: options?.label,
90
+ choices: options?.mode ? [options.mode] : undefined
91
+ }
92
+ }
93
+ }),
94
+ file: (options) => zOriginal.object({
95
+ id: zOriginal.string(),
96
+ url: zOriginal.string(),
97
+ filename: zOriginal.string(),
98
+ mime_type: zOriginal.string(),
99
+ filesize: zOriginal.number()
100
+ }).meta({
101
+ opaca: {
102
+ admin: { component: "file", label: options?.label, fileOptions: options }
103
+ }
104
+ }),
105
+ textarea: (options) => zOriginal.string().meta({
106
+ opaca: {
107
+ localized: options?.localized,
108
+ admin: { component: "textarea", label: options?.label, description: options?.description }
109
+ }
110
+ }),
111
+ number: (options) => zOriginal.number().meta({
112
+ opaca: {
113
+ admin: { component: "number", label: options?.label, description: options?.description }
114
+ }
115
+ }),
116
+ boolean: (options) => zOriginal.preprocess((val) => {
117
+ if (val === "true" || val === 1)
118
+ return true;
119
+ if (val === "false" || val === 0)
120
+ return false;
121
+ return val;
122
+ }, zOriginal.boolean()).meta({
123
+ opaca: {
124
+ admin: { component: "boolean", label: options?.label, description: options?.description }
125
+ }
126
+ }),
127
+ date: (options) => zOriginal.date().meta({
128
+ opaca: {
129
+ admin: { component: "date", label: options?.label, description: options?.description }
130
+ }
131
+ }),
132
+ select: (choices, options) => {
133
+ const values = choices.map((c) => typeof c === "string" ? c : c.value);
134
+ return zOriginal.enum(values).meta({
135
+ opaca: {
136
+ admin: {
137
+ component: "select",
138
+ label: options?.label,
139
+ description: options?.description,
140
+ choices: typeof choices[0] === "string" ? undefined : choices
141
+ }
142
+ }
143
+ });
144
+ },
145
+ radio: (choices, options) => {
146
+ const values = choices.map((c) => typeof c === "string" ? c : c.value);
147
+ return zOriginal.enum(values).meta({
148
+ opaca: {
149
+ admin: {
150
+ component: "radio",
151
+ label: options?.label,
152
+ description: options?.description,
153
+ choices: typeof choices[0] === "string" ? undefined : choices
154
+ }
155
+ }
156
+ });
157
+ },
158
+ password: (options) => zOriginal.string().meta({
159
+ opaca: {
160
+ hash: { algorithm: options?.algorithm || "argon2" },
161
+ admin: { component: "text", label: options?.label, hidden: true }
162
+ }
163
+ }),
164
+ join: (collection, on, options) => zOriginal.array(zOriginal.any()).optional().meta({
165
+ opaca: {
166
+ virtual: true,
167
+ admin: { component: "join", label: options?.label, relationTo: collection }
168
+ }
169
+ }),
170
+ group: (shape, options) => zOriginal.object(shape).meta({
171
+ opaca: { admin: { component: "group", label: options?.label } }
172
+ }),
173
+ row: (shape, options) => zOriginal.object(shape).meta({
174
+ opaca: { admin: { component: "row", label: options?.label } }
175
+ }),
176
+ collapsible: (shape, options) => zOriginal.object(shape).meta({
177
+ opaca: {
178
+ admin: {
179
+ component: "collapsible",
180
+ label: options?.label,
181
+ initiallyCollapsed: options?.initiallyCollapsed
182
+ }
183
+ }
184
+ }),
185
+ tabs: (tabsConfig, options) => {
186
+ let mergedShape = {};
187
+ const metaTabs = [];
188
+ for (const [tabLabel, zodObj] of Object.entries(tabsConfig)) {
189
+ mergedShape = { ...mergedShape, ...zodObj.shape };
190
+ metaTabs.push({ label: tabLabel, fields: Object.keys(zodObj.shape) });
191
+ }
192
+ return zOriginal.object(mergedShape).meta({
193
+ opaca: {
194
+ admin: { component: "tabs", label: options?.label, tabsConfig: metaTabs }
195
+ }
196
+ });
197
+ },
198
+ blocks: (blockSchemas, options) => zOriginal.array(zOriginal.discriminatedUnion("blockType", blockSchemas)).meta({
199
+ opaca: { admin: { component: "blocks", label: options?.label } }
200
+ }),
201
+ localized: (schema) => {
202
+ return schema.meta({
203
+ opaca: { localized: true }
204
+ });
205
+ },
206
+ ui: (component, adminConfig) => {
207
+ return zOriginal.any().meta({
208
+ opaca: {
209
+ admin: {
210
+ component: "ui",
211
+ customComponent: component,
212
+ ...adminConfig
213
+ }
214
+ }
215
+ });
216
+ },
217
+ cms: (schema, meta) => schema.meta({ opaca: meta })
218
+ };
219
+ $ZodOptional = zOriginal.ZodOptional;
220
+ $ZodNullable = zOriginal.ZodNullable;
221
+ $ZodDefault = zOriginal.ZodDefault;
222
+ $ZodString = zOriginal.ZodString;
223
+ $ZodNumber = zOriginal.ZodNumber;
224
+ $ZodBoolean = zOriginal.ZodBoolean;
225
+ $ZodDate = zOriginal.ZodDate;
226
+ $ZodEnum = zOriginal.ZodEnum;
227
+ $ZodObject = zOriginal.ZodObject;
228
+ $ZodArray = zOriginal.ZodArray;
229
+ $ZodDiscriminatedUnion = zOriginal.ZodDiscriminatedUnion;
230
+ });
231
+
232
+ // src/schema/compiler.ts
233
+ var exports_compiler = {};
234
+ __export(exports_compiler, {
235
+ zodToOpacaFields: () => zodToOpacaFields
236
+ });
237
+ function zodToOpacaFields(schema, currentPath = "") {
238
+ if (!schema || !schema._def) {
239
+ return [];
240
+ }
241
+ let innerSchema = schema;
242
+ let meta = {};
243
+ while (innerSchema && innerSchema._def && ["optional", "nullable", "default"].includes(innerSchema._def.type)) {
244
+ const currentMeta = typeof innerSchema.meta === "function" ? innerSchema.meta() : innerSchema._def.meta;
245
+ if (currentMeta?.opaca) {
246
+ meta = { ...currentMeta.opaca, ...meta };
247
+ }
248
+ innerSchema = innerSchema._def.innerType;
249
+ }
250
+ if (innerSchema && innerSchema._def) {
251
+ const finalMeta = typeof innerSchema.meta === "function" ? innerSchema.meta() : innerSchema._def.meta;
252
+ if (finalMeta?.opaca) {
253
+ meta = { ...finalMeta.opaca, ...meta };
254
+ }
255
+ }
256
+ const def = schema._def;
257
+ const defaultValue = def.type === "default" && typeof def.defaultValue === "function" ? def.defaultValue() : def.defaultValue;
258
+ const baseConfig = {
259
+ name: currentPath,
260
+ label: meta.admin?.label || currentPath,
261
+ required: !schema.isOptional(),
262
+ unique: meta.unique || false,
263
+ localized: meta.localized || false,
264
+ virtual: meta.virtual || meta.isVirtual || false,
265
+ requiredCondition: meta.requiredCondition || meta.required,
266
+ condition: meta.condition || meta.admin?.condition,
267
+ defaultValue,
268
+ admin: {
269
+ ...meta.admin,
270
+ condition: meta.condition || meta.admin?.condition,
271
+ requiredCondition: meta.requiredCondition || meta.required
272
+ },
273
+ ...meta.admin,
274
+ ...meta
275
+ };
276
+ const OPACA_TYPES = [
277
+ "text",
278
+ "slug",
279
+ "textarea",
280
+ "number",
281
+ "richtext",
282
+ "relationship",
283
+ "select",
284
+ "radio",
285
+ "date",
286
+ "boolean",
287
+ "json",
288
+ "file",
289
+ "blocks",
290
+ "group",
291
+ "row",
292
+ "collapsible",
293
+ "tabs",
294
+ "join",
295
+ "array",
296
+ "virtual",
297
+ "ui"
298
+ ];
299
+ const type = innerSchema._def.type;
300
+ if (type === "string") {
301
+ const component = meta.admin?.component;
302
+ return [
303
+ {
304
+ ...baseConfig,
305
+ type: component && OPACA_TYPES.includes(component) ? component : "text"
306
+ }
307
+ ];
308
+ }
309
+ if (type === "number") {
310
+ return [{ ...baseConfig, type: "number" }];
311
+ }
312
+ if (type === "boolean") {
313
+ return [{ ...baseConfig, type: "boolean" }];
314
+ }
315
+ if (type === "date") {
316
+ return [{ ...baseConfig, type: "date" }];
317
+ }
318
+ if (type === "enum") {
319
+ const component = meta.admin?.component;
320
+ const choices = innerSchema._def.values || Object.values(innerSchema.enum || {});
321
+ return [
322
+ {
323
+ ...baseConfig,
324
+ type: component && OPACA_TYPES.includes(component) ? component : "select",
325
+ options: {
326
+ choices
327
+ }
328
+ }
329
+ ];
330
+ }
331
+ if (type === "object") {
332
+ const shape = innerSchema.shape;
333
+ const nestedFields = Object.entries(shape).flatMap(([key, val]) => zodToOpacaFields(val, key));
334
+ if (currentPath === "") {
335
+ return nestedFields;
336
+ }
337
+ const component = meta.admin?.component || "group";
338
+ if (component === "tabs" && meta.admin?.tabsConfig) {
339
+ return [
340
+ {
341
+ ...baseConfig,
342
+ type: "tabs",
343
+ tabs: meta.admin.tabsConfig.map((t) => ({
344
+ label: t.label,
345
+ fields: nestedFields.filter((f) => t.fields.includes(f.name))
346
+ }))
347
+ }
348
+ ];
349
+ }
350
+ return [
351
+ {
352
+ ...baseConfig,
353
+ type: component,
354
+ fields: nestedFields
355
+ }
356
+ ];
357
+ }
358
+ if (type === "array") {
359
+ const elementSchema = innerSchema._def.element;
360
+ const component = meta.admin?.component || "array";
361
+ const isDiscUnion = elementSchema && elementSchema._def.type === "union" && elementSchema._def.discriminator;
362
+ if (component === "blocks" || isDiscUnion) {
363
+ let blocks = [];
364
+ if (isDiscUnion) {
365
+ const options = elementSchema._def.options;
366
+ blocks = options.map((obj) => {
367
+ const discriminator = elementSchema._def.discriminator;
368
+ const shape = obj.shape;
369
+ const discriminatorField = shape?.[discriminator];
370
+ const slug = discriminatorField?._def.values?.[0] || "block";
371
+ return {
372
+ slug,
373
+ fields: zodToOpacaFields(obj)
374
+ };
375
+ });
376
+ }
377
+ return [
378
+ {
379
+ ...baseConfig,
380
+ type: "blocks",
381
+ blocks
382
+ }
383
+ ];
384
+ }
385
+ return [
386
+ {
387
+ ...baseConfig,
388
+ type: "array",
389
+ fields: elementSchema ? zodToOpacaFields(elementSchema, "") : []
390
+ }
391
+ ];
392
+ }
393
+ if (meta.admin?.component) {
394
+ return [
395
+ {
396
+ ...baseConfig,
397
+ type: meta.admin.component
398
+ }
399
+ ];
400
+ }
401
+ return [
402
+ {
403
+ ...baseConfig,
404
+ type: "json"
405
+ }
406
+ ];
407
+ }
408
+ var init_compiler = () => {};
409
+
410
+ export { z, $ZodOptional, $ZodNullable, $ZodDefault, $ZodString, $ZodNumber, $ZodBoolean, $ZodDate, $ZodEnum, $ZodObject, $ZodArray, $ZodDiscriminatedUnion, init_zod, zodToOpacaFields, exports_compiler, init_compiler };
@@ -20,25 +20,22 @@ var $customSidebarItems = atom([]);
20
20
  function registerSidebarItem(item) {
21
21
  const current = $customSidebarItems.get();
22
22
  if (!current.find((i) => i.path === item.path)) {
23
- if (item.render && !item.component) {
24
- item.component = `opaca-plugin-render-${Math.random().toString(36).substring(2, 9)}`;
25
- if (typeof customElements !== "undefined" && !customElements.get(item.component)) {
26
- const componentName = item.component;
27
- const renderFn = item.render;
28
-
29
- class OpacaGenericPlugin extends HTMLElement {
30
- connectedCallback() {
31
- const serverUrl = this.getAttribute("server-url") || "";
32
- const config = JSON.parse(this.getAttribute("config") || "{}");
33
- const user = JSON.parse(this.getAttribute("user") || "{}");
34
- this.innerHTML = renderFn(serverUrl, config, user);
35
- }
36
- }
37
- customElements.define(componentName, OpacaGenericPlugin);
38
- }
39
- }
40
23
  $customSidebarItems.set([...current, item]);
41
24
  }
42
25
  }
26
+ var $activeAlert = atom(null);
27
+ function openAlert(options) {
28
+ $activeAlert.set(options);
29
+ }
30
+ function closeAlert() {
31
+ $activeAlert.set(null);
32
+ }
33
+ var $activeSheet = atom(null);
34
+ function openSheet(options) {
35
+ $activeSheet.set(options);
36
+ }
37
+ function closeSheet() {
38
+ $activeSheet.set(null);
39
+ }
43
40
 
44
- export { $toasts, $isSidebarCollapsed, toggleSidebar, notify, clearToast, $customSidebarItems, registerSidebarItem };
41
+ export { $toasts, $isSidebarCollapsed, toggleSidebar, notify, clearToast, $customSidebarItems, registerSidebarItem, $activeAlert, openAlert, closeAlert, $activeSheet, openSheet, closeSheet };
@@ -0,0 +1,98 @@
1
+ import {
2
+ defineCommand,
3
+ runMain
4
+ } from "./chunk-1qm0m8r8.js";
5
+ import {
6
+ __require
7
+ } from "./chunk-6bywt602.js";
8
+
9
+ // src/cli/index.ts
10
+ import fs from "node:fs";
11
+ import { resolve } from "node:path";
12
+ import { pathToFileURL } from "node:url";
13
+ async function loadConfig(configPath) {
14
+ if (!fs.existsSync(configPath)) {
15
+ throw new Error(`Config file not found at ${configPath}`);
16
+ }
17
+ const configUrl = pathToFileURL(configPath).href;
18
+ const mod = await import(configUrl);
19
+ if (!mod.default) {
20
+ throw new Error(`The configuration file at ${configPath} must have a 'default' export.`);
21
+ }
22
+ const namedExports = Object.keys(mod).filter((k) => k !== "default" && k !== "__esModule");
23
+ if (namedExports.length > 0) {
24
+ throw new Error(`Named exports are not allowed in the configuration file. Found: ${namedExports.join(", ")}.`);
25
+ }
26
+ let opaca = mod.default;
27
+ if (typeof opaca === "function") {
28
+ const { createD1Mock } = await import("./chunk-h6dhexzr.js");
29
+ const { createR2Mock } = await import("./chunk-x7bnzswh.js");
30
+ const mockDb = createD1Mock();
31
+ const mockBucket = createR2Mock();
32
+ const mockSecureBucket = createR2Mock();
33
+ opaca = await opaca({
34
+ DB: mockDb,
35
+ BUCKET: mockBucket,
36
+ SECURE_BUCKET: mockSecureBucket,
37
+ OPACA_SECRET: "cli-secret"
38
+ }, { url: "http://localhost:3000" });
39
+ }
40
+ if (opaca?.fetch) {
41
+ throw new Error("Default export is a Hono application. The CLI requires the configuration object.");
42
+ }
43
+ if (!opaca.db) {
44
+ throw new Error("No database adapter found in config");
45
+ }
46
+ return opaca;
47
+ }
48
+ function resolveConfigPath(explicitPath) {
49
+ let configPath = explicitPath ? resolve(process.cwd(), explicitPath) : "";
50
+ if (!configPath) {
51
+ const defaults = [
52
+ "opaca.config.ts",
53
+ "opaca.config.js",
54
+ "opacacms.config.ts",
55
+ "opacacms.config.js",
56
+ "src/opaca.config.ts",
57
+ "src/opacacms.config.js"
58
+ ];
59
+ for (const d of defaults) {
60
+ if (fs.existsSync(resolve(process.cwd(), d))) {
61
+ configPath = resolve(process.cwd(), d);
62
+ break;
63
+ }
64
+ }
65
+ }
66
+ if (!configPath || !fs.existsSync(configPath)) {
67
+ throw new Error("Config file not found. Use -c or --config to specify path.");
68
+ }
69
+ return configPath;
70
+ }
71
+ var mainCommand = defineCommand({
72
+ meta: {
73
+ name: "opacacms",
74
+ version: "0.1.0",
75
+ description: "OpacaCMS CLI - The Headless CMS that doesn't get in your way."
76
+ },
77
+ args: {
78
+ config: {
79
+ type: "string",
80
+ alias: "c",
81
+ description: "Path to the OpacaCMS configuration file"
82
+ }
83
+ },
84
+ subCommands: {
85
+ init: () => import("./chunk-fatyf6f7.js").then((m) => m.default),
86
+ migrate: () => import("./chunk-d7cgd6vn.js").then((m) => m.default),
87
+ seed: () => import("./chunk-d0tb1xjw.js").then((m) => m.default),
88
+ generate: () => import("./chunk-mp2gt9yh.js").then((m) => m.default),
89
+ plugin: () => import("./chunk-63yg00vx.js").then((m) => m.default),
90
+ doctor: () => import("./chunk-56n342hs.js").then((m) => m.default),
91
+ dev: () => import("./chunk-r0ms5tk1.js").then((m) => m.default)
92
+ }
93
+ });
94
+ if (__require.main == __require.module) {
95
+ runMain(mainCommand);
96
+ }
97
+
98
+ export { loadConfig, resolveConfigPath };