opacacms 0.1.7 → 0.1.8

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 (46) hide show
  1. package/dist/admin/index.js +255 -20
  2. package/dist/admin/webcomponent.js +291 -46
  3. package/dist/cli/index.js +3638 -30
  4. package/dist/client.js +126 -5
  5. package/dist/db/bun-sqlite.js +790 -21
  6. package/dist/db/d1.js +788 -19
  7. package/dist/db/index.js +53 -4
  8. package/dist/db/postgres.js +792 -23
  9. package/dist/db/sqlite.js +788 -19
  10. package/dist/index.js +456 -8
  11. package/dist/runtimes/bun.js +1909 -8
  12. package/dist/runtimes/cloudflare-workers.js +1910 -9
  13. package/dist/runtimes/next.js +1908 -7
  14. package/dist/runtimes/node.js +1909 -8
  15. package/dist/schema/collection.d.ts +3 -7
  16. package/dist/schema/fields/index.d.ts +24 -25
  17. package/dist/schema/global.d.ts +9 -9
  18. package/dist/schema/index.d.ts +30 -4
  19. package/dist/schema/index.js +546 -1
  20. package/dist/server.js +2246 -17
  21. package/dist/storage/index.js +40 -1
  22. package/package.json +1 -1
  23. package/dist/chunk-16vgcf3k.js +0 -88
  24. package/dist/chunk-2yz1nsxs.js +0 -126
  25. package/dist/chunk-5gvbp2qa.js +0 -167
  26. package/dist/chunk-62ev8gnc.js +0 -41
  27. package/dist/chunk-6ew02s0c.js +0 -472
  28. package/dist/chunk-7a9kn0np.js +0 -116
  29. package/dist/chunk-8sqjbsgt.js +0 -42
  30. package/dist/chunk-9kxpbcb1.js +0 -85
  31. package/dist/chunk-cvdd4eqh.js +0 -110
  32. package/dist/chunk-d3ffeqp9.js +0 -87
  33. package/dist/chunk-fa5mg0hr.js +0 -96
  34. package/dist/chunk-j4d50hrx.js +0 -20
  35. package/dist/chunk-jwjk85ze.js +0 -15
  36. package/dist/chunk-m09hahe2.js +0 -250
  37. package/dist/chunk-s8mqwnm1.js +0 -14
  38. package/dist/chunk-srsac177.js +0 -85
  39. package/dist/chunk-v521d72w.js +0 -10
  40. package/dist/chunk-vtvqfhgy.js +0 -2442
  41. package/dist/chunk-xa7rjsn2.js +0 -20
  42. package/dist/chunk-xg35h5a3.js +0 -15
  43. package/dist/chunk-y8hc6nm4.js +0 -17
  44. package/dist/chunk-ybbbqj63.js +0 -130
  45. package/dist/chunk-yr32cp7h.js +0 -1603
  46. package/dist/chunk-zvwb67nd.js +0 -332
@@ -1,12 +1,5 @@
1
1
  import type { Collection as BaseCollection, IconName } from "../types";
2
2
  import type { AccessRules, InferFields } from "./infer";
3
- /**
4
- * Factory for creating Collections.
5
- * Using a class with static methods for better ESM/Turbopack resolution.
6
- */
7
- export declare class Collection {
8
- static create(slug: string): CollectionBuilder<{}>;
9
- }
10
3
  /**
11
4
  * The Fluent API Collection Builder.
12
5
  */
@@ -102,3 +95,6 @@ export declare class CollectionBuilder<TFields extends Record<string, any> = {}>
102
95
  */
103
96
  build(): BaseCollection;
104
97
  }
98
+ export declare const Collection: {
99
+ create: (slug: string) => CollectionBuilder<{}>;
100
+ };
@@ -1,29 +1,4 @@
1
1
  import { FieldBuilder } from "./base";
2
- /**
3
- * The Field Factory object containing methods to instantiate specific field builders.
4
- * Using a class with static methods for better ESM/Turbopack resolution.
5
- */
6
- export declare class Field {
7
- static text: <N extends string>(name: N) => TextFieldBuilder<N>;
8
- static slug: <N extends string>(name: N) => SlugFieldBuilder<N>;
9
- static textarea: <N extends string>(name: N) => TextAreaFieldBuilder<N>;
10
- static number: <N extends string>(name: N) => NumberFieldBuilder<N>;
11
- static boolean: <N extends string>(name: N) => BooleanFieldBuilder<N>;
12
- static date: <N extends string>(name: N) => DateFieldBuilder<N>;
13
- static select: <N extends string>(name: N) => SelectFieldBuilder<N>;
14
- static radio: <N extends string>(name: N) => RadioFieldBuilder<N>;
15
- static richText: <N extends string>(name: N) => RichTextFieldBuilder<N>;
16
- static relationship: <N extends string>(name: N) => RelationshipFieldBuilder<N>;
17
- static join: <N extends string>(name: N) => JoinFieldBuilder<N>;
18
- static file: <N extends string>(name: N) => FileFieldBuilder<N>;
19
- static array: <N extends string>(name: N) => ArrayFieldBuilder<N, any[]>;
20
- static group: <N extends string, TSub extends readonly FieldBuilder<any, any, any, any>[]>(name: N, fields?: TSub) => GroupFieldBuilder<N, any, TSub>;
21
- static tabs: () => TabsFieldBuilder<[]>;
22
- static collapsible: <N extends string, S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => CollapsibleFieldBuilder<ExtractNames<S>, S>;
23
- static row: <S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => RowFieldBuilder<S>;
24
- static blocks: <N extends string, TSub extends readonly BlockBuilder<any, any, any>[]>(name: N, ...blocks: TSub) => BlocksFieldBuilder<N, TSub>;
25
- static block: <N extends string>(slug: N) => BlockBuilder<N, string, any[]>;
26
- }
27
2
  export declare class TextFieldBuilder<TName extends string> extends FieldBuilder<"text", TName, string> {
28
3
  constructor(name: TName);
29
4
  }
@@ -123,4 +98,28 @@ export declare class BlocksFieldBuilder<TName extends string, TBlocks extends re
123
98
  constructor(name: TName);
124
99
  blocks<NewBlocks extends readonly BlockBuilder<any, any, any>[]>(...blocks: NewBlocks): BlocksFieldBuilder<TName, NewBlocks>;
125
100
  }
101
+ /**
102
+ * The Field Factory object containing methods to instantiate specific field builders.
103
+ */
104
+ export declare const Field: {
105
+ text: <N extends string>(name: N) => TextFieldBuilder<N>;
106
+ slug: <N extends string>(name: N) => SlugFieldBuilder<N>;
107
+ textarea: <N extends string>(name: N) => TextAreaFieldBuilder<N>;
108
+ number: <N extends string>(name: N) => NumberFieldBuilder<N>;
109
+ boolean: <N extends string>(name: N) => BooleanFieldBuilder<N>;
110
+ date: <N extends string>(name: N) => DateFieldBuilder<N>;
111
+ select: <N extends string>(name: N) => SelectFieldBuilder<N>;
112
+ radio: <N extends string>(name: N) => RadioFieldBuilder<N>;
113
+ richText: <N extends string>(name: N) => RichTextFieldBuilder<N>;
114
+ relationship: <N extends string>(name: N) => RelationshipFieldBuilder<N>;
115
+ join: <N extends string>(name: N) => JoinFieldBuilder<N>;
116
+ file: <N extends string>(name: N) => FileFieldBuilder<N>;
117
+ array: <N extends string>(name: N) => ArrayFieldBuilder<N, any[]>;
118
+ group: <N extends string, TSub extends readonly FieldBuilder<any, any, any, any>[]>(name: N, fields?: TSub) => GroupFieldBuilder<N, any, TSub>;
119
+ tabs: () => TabsFieldBuilder<[]>;
120
+ collapsible: <N extends string, S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => CollapsibleFieldBuilder<ExtractNames<S>, S>;
121
+ row: <S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => RowFieldBuilder<S>;
122
+ blocks: <N extends string, TSub extends readonly BlockBuilder<any, any, any>[]>(name: N, ...blocks: TSub) => BlocksFieldBuilder<N, TSub>;
123
+ block: <N extends string>(slug: N) => BlockBuilder<N, string, any[]>;
124
+ };
126
125
  export * from "./base";
@@ -1,18 +1,12 @@
1
1
  import type { AccessConfig, Global as GlobalType, IconName } from "../types";
2
2
  import { type FieldBuilder } from "./fields/base";
3
3
  import type { InferFields } from "./infer";
4
- /**
5
- * Singleton factory for creating Globals.
6
- * Using a class with static methods for better ESM/Turbopack resolution.
7
- */
8
- export declare class Global {
9
- static create(slug: string): GlobalBuilder<{}>;
10
- }
4
+ export type Global = GlobalType;
11
5
  /**
12
6
  * A Fluent API Builder for defining OpacaCMS Globals.
13
7
  */
14
8
  export declare class GlobalBuilder<TFields extends Record<string, any> = {}> {
15
- protected config: Partial<GlobalType>;
9
+ protected config: Partial<Global>;
16
10
  protected _fields: FieldBuilder<any, any>[];
17
11
  constructor(slug: string);
18
12
  /**
@@ -78,5 +72,11 @@ export declare class GlobalBuilder<TFields extends Record<string, any> = {}> {
78
72
  /**
79
73
  * Compiles the builder down into the raw Global object expected by OpacaCMS.
80
74
  */
81
- build(): GlobalType;
75
+ build(): Global;
82
76
  }
77
+ /**
78
+ * Singleton factory for creating Globals.
79
+ */
80
+ export declare const Global: {
81
+ create: (slug: string) => GlobalBuilder<{}>;
82
+ };
@@ -1,4 +1,30 @@
1
- export { Collection, CollectionBuilder } from "./collection";
2
- export { Field, FieldBuilder } from "./fields/index";
3
- export { Global, GlobalBuilder } from "./global";
4
- export type { AccessRules, InferFields } from "./infer";
1
+ import { CollectionBuilder } from "./collection";
2
+ import { FieldBuilder, TextFieldBuilder, SlugFieldBuilder, TextAreaFieldBuilder, NumberFieldBuilder, BooleanFieldBuilder, RichTextFieldBuilder, RelationshipFieldBuilder, JoinFieldBuilder, FileFieldBuilder, ArrayFieldBuilder, GroupFieldBuilder, TabsFieldBuilder, CollapsibleFieldBuilder, RowFieldBuilder, BlockBuilder, BlocksFieldBuilder, VirtualFieldBuilder } from "./fields/index";
3
+ import { GlobalBuilder } from "./global";
4
+ import type { AccessRules, InferFields } from "./infer";
5
+ export declare const Collection: {
6
+ create: (slug: string) => CollectionBuilder<{}>;
7
+ };
8
+ export declare const Field: {
9
+ text: <N extends string>(name: N) => TextFieldBuilder<N>;
10
+ slug: <N extends string>(name: N) => SlugFieldBuilder<N>;
11
+ textarea: <N extends string>(name: N) => TextAreaFieldBuilder<N>;
12
+ number: <N extends string>(name: N) => NumberFieldBuilder<N>;
13
+ boolean: <N extends string>(name: N) => BooleanFieldBuilder<N>;
14
+ richText: <N extends string>(name: N) => RichTextFieldBuilder<N>;
15
+ relationship: <N extends string>(name: N) => RelationshipFieldBuilder<N>;
16
+ join: <N extends string>(name: N) => JoinFieldBuilder<N>;
17
+ file: <N extends string>(name: N) => FileFieldBuilder<N>;
18
+ array: <N extends string>(name: N) => ArrayFieldBuilder<N, any[]>;
19
+ group: <N extends string, TSub extends readonly FieldBuilder<any, any, any, any>[]>(name: N, fields?: TSub) => GroupFieldBuilder<N, any, TSub>;
20
+ tabs: () => TabsFieldBuilder<[]>;
21
+ collapsible: <S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => CollapsibleFieldBuilder<any, S>;
22
+ row: <S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => RowFieldBuilder<S>;
23
+ blocks: <N extends string, TSub extends readonly BlockBuilder<any, any, any>[]>(name: N, ...blocks: TSub) => BlocksFieldBuilder<N, TSub>;
24
+ block: <N extends string>(slug: N) => BlockBuilder<N, string, any[]>;
25
+ };
26
+ export declare const Global: {
27
+ create: (slug: string) => GlobalBuilder<{}>;
28
+ };
29
+ export { CollectionBuilder, FieldBuilder, GlobalBuilder, VirtualFieldBuilder };
30
+ export type { AccessRules, InferFields };
@@ -1,5 +1,550 @@
1
- import"../chunk-8sqjbsgt.js";
1
+ import { createRequire } from "node:module";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ function __accessProp(key) {
7
+ return this[key];
8
+ }
9
+ var __toCommonJS = (from) => {
10
+ var entry = (__moduleCache ??= new WeakMap).get(from), desc;
11
+ if (entry)
12
+ return entry;
13
+ entry = __defProp({}, "__esModule", { value: true });
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (var key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(entry, key))
17
+ __defProp(entry, key, {
18
+ get: __accessProp.bind(from, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ __moduleCache.set(from, entry);
23
+ return entry;
24
+ };
25
+ var __moduleCache;
26
+ var __returnValue = (v) => v;
27
+ function __exportSetter(name, newValue) {
28
+ this[name] = __returnValue.bind(null, newValue);
29
+ }
30
+ var __export = (target, all) => {
31
+ for (var name in all)
32
+ __defProp(target, name, {
33
+ get: all[name],
34
+ enumerable: true,
35
+ configurable: true,
36
+ set: __exportSetter.bind(all, name)
37
+ });
38
+ };
39
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
40
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
41
+
42
+ // src/schema/fields/base.ts
43
+ class FieldBuilder {
44
+ type;
45
+ name;
46
+ config = {};
47
+ constructor(type, name) {
48
+ this.type = type;
49
+ this.name = name;
50
+ this.config = { type, name };
51
+ }
52
+ label(label) {
53
+ this.config.label = label;
54
+ return this;
55
+ }
56
+ placeholder(text) {
57
+ this.config.placeholder = text;
58
+ return this;
59
+ }
60
+ required(val = true) {
61
+ this.config.required = val;
62
+ return this;
63
+ }
64
+ unique(val = true) {
65
+ this.config.unique = val;
66
+ return this;
67
+ }
68
+ localized(val = true) {
69
+ this.config.localized = val;
70
+ return this;
71
+ }
72
+ defaultValue(val) {
73
+ this.config.defaultValue = val;
74
+ return this;
75
+ }
76
+ validate(fn) {
77
+ this.config.validate = fn;
78
+ return this;
79
+ }
80
+ access(config) {
81
+ this.config.access = config;
82
+ return this;
83
+ }
84
+ description(text) {
85
+ this._ensureAdmin();
86
+ this.config.admin.description = text;
87
+ return this;
88
+ }
89
+ admin(opts) {
90
+ this._ensureAdmin();
91
+ this.config.admin = { ...this.config.admin, ...opts };
92
+ return this;
93
+ }
94
+ hidden(val = true) {
95
+ this._ensureAdmin();
96
+ this.config.admin.hidden = val;
97
+ return this;
98
+ }
99
+ readOnly(val = true) {
100
+ this._ensureAdmin();
101
+ this.config.admin.readOnly = val;
102
+ return this;
103
+ }
104
+ extend(opts) {
105
+ this.config = { ...this.config, ...opts };
106
+ return this;
107
+ }
108
+ _ensureAdmin() {
109
+ if (!this.config.admin) {
110
+ this.config.admin = {};
111
+ }
112
+ }
113
+ _ensureOptions() {
114
+ if (!this.config.options) {
115
+ this.config.options = {};
116
+ }
117
+ }
118
+ build() {
119
+ return this.config;
120
+ }
121
+ }
122
+
123
+ // src/schema/fields/virtual.ts
124
+ class VirtualFieldBuilder extends FieldBuilder {
125
+ constructor(name) {
126
+ super("virtual", name);
127
+ }
128
+ resolve(fn) {
129
+ this.config.resolve = fn;
130
+ return this;
131
+ }
132
+ returnType(type) {
133
+ this.config.returnType = type;
134
+ return this;
135
+ }
136
+ }
137
+
138
+ // src/schema/collection.ts
139
+ class CollectionBuilder {
140
+ slug;
141
+ config = {
142
+ fields: [],
143
+ timestamps: true
144
+ };
145
+ fieldBuilders = [];
146
+ constructor(slug) {
147
+ this.slug = slug;
148
+ this.config.slug = slug;
149
+ }
150
+ label(label) {
151
+ this.config.label = label;
152
+ return this;
153
+ }
154
+ icon(iconName) {
155
+ this.config.icon = iconName;
156
+ return this;
157
+ }
158
+ useAsTitle(fieldName) {
159
+ this._ensureAdmin();
160
+ this.config.admin.useAsTitle = fieldName;
161
+ return this;
162
+ }
163
+ timestamps(val = true) {
164
+ this.config.timestamps = val;
165
+ return this;
166
+ }
167
+ fields(fields) {
168
+ const nextBuilder = new CollectionBuilder(this.config.slug);
169
+ nextBuilder.config = { ...this.config };
170
+ nextBuilder.fieldBuilders = [...fields];
171
+ return nextBuilder;
172
+ }
173
+ access(rules) {
174
+ this.config.access = rules;
175
+ return this;
176
+ }
177
+ virtual(name, options) {
178
+ const builder = new VirtualFieldBuilder(name);
179
+ if (options.label)
180
+ builder.label(options.label);
181
+ if (options.resolve)
182
+ builder.resolve(options.resolve);
183
+ if (options.returnType)
184
+ builder.returnType(options.returnType);
185
+ const nextBuilder = new CollectionBuilder(this.config.slug);
186
+ nextBuilder.config = { ...this.config };
187
+ nextBuilder.fieldBuilders = [...this.fieldBuilders, builder];
188
+ return nextBuilder;
189
+ }
190
+ computed(name, options) {
191
+ return this.virtual(name, options);
192
+ }
193
+ admin(opts) {
194
+ if (typeof opts === "boolean") {
195
+ this.config.admin = opts;
196
+ } else {
197
+ this.config.admin = { ...this.config.admin, ...opts };
198
+ }
199
+ return this;
200
+ }
201
+ versions(opts) {
202
+ this.config.versions = opts;
203
+ return this;
204
+ }
205
+ webhooks(webhooks) {
206
+ this.config.webhooks = webhooks;
207
+ return this;
208
+ }
209
+ extend(preset) {
210
+ return this;
211
+ }
212
+ _ensureAdmin() {
213
+ if (!this.config.admin || typeof this.config.admin === "boolean") {
214
+ this.config.admin = {};
215
+ }
216
+ }
217
+ build() {
218
+ const compiledFields = this.fieldBuilders.map((builder) => builder.build());
219
+ return {
220
+ ...this.config,
221
+ fields: compiledFields
222
+ };
223
+ }
224
+ }
225
+
226
+ // src/schema/fields/index.ts
227
+ class TextFieldBuilder extends FieldBuilder {
228
+ constructor(name) {
229
+ super("text", name);
230
+ }
231
+ }
232
+
233
+ class SlugFieldBuilder extends FieldBuilder {
234
+ constructor(name) {
235
+ super("slug", name);
236
+ }
237
+ from(sourceField) {
238
+ this.config.from = sourceField;
239
+ return this;
240
+ }
241
+ format(fn) {
242
+ this.config.format = fn;
243
+ return this;
244
+ }
245
+ }
246
+
247
+ class TextAreaFieldBuilder extends FieldBuilder {
248
+ constructor(name) {
249
+ super("textarea", name);
250
+ }
251
+ }
252
+
253
+ class NumberFieldBuilder extends FieldBuilder {
254
+ constructor(name) {
255
+ super("number", name);
256
+ }
257
+ min(val) {
258
+ this._ensureOptions();
259
+ this.config.options.min = val;
260
+ return this;
261
+ }
262
+ max(val) {
263
+ this._ensureOptions();
264
+ this.config.options.max = val;
265
+ return this;
266
+ }
267
+ }
268
+
269
+ class BooleanFieldBuilder extends FieldBuilder {
270
+ constructor(name) {
271
+ super("boolean", name);
272
+ }
273
+ display(type) {
274
+ this._ensureOptions();
275
+ this.config.options.display = type;
276
+ return this;
277
+ }
278
+ }
279
+
280
+ class RichTextFieldBuilder extends FieldBuilder {
281
+ constructor(name) {
282
+ super("richtext", name);
283
+ }
284
+ mode(mode) {
285
+ this._ensureOptions();
286
+ this.config.options.defaultMode = mode;
287
+ return this;
288
+ }
289
+ }
290
+
291
+ class RelationshipFieldBuilder extends FieldBuilder {
292
+ constructor(name) {
293
+ super("relationship", name);
294
+ }
295
+ to(collection) {
296
+ this.config.relationTo = typeof collection === "string" ? collection : collection.slug;
297
+ return this;
298
+ }
299
+ single() {
300
+ this.config.hasMany = false;
301
+ return this;
302
+ }
303
+ many() {
304
+ this.config.hasMany = true;
305
+ return this;
306
+ }
307
+ displayField(field) {
308
+ this.config.displayField = field;
309
+ return this;
310
+ }
311
+ }
312
+
313
+ class FileFieldBuilder extends FieldBuilder {
314
+ constructor(name) {
315
+ super("file", name);
316
+ }
317
+ bucket(bucketName) {
318
+ this.config.bucket = bucketName;
319
+ return this;
320
+ }
321
+ allowedmime_types(types) {
322
+ this._ensureOptions();
323
+ this.config.options.allowedmime_types = types;
324
+ return this;
325
+ }
326
+ maxSize(bytes) {
327
+ this._ensureOptions();
328
+ this.config.options.maxFileSize = bytes;
329
+ return this;
330
+ }
331
+ }
332
+ class TabsFieldBuilder extends FieldBuilder {
333
+ constructor() {
334
+ super("tabs", "");
335
+ this.config.tabs = [];
336
+ }
337
+ tab(label, ...fields) {
338
+ this.config.tabs.push({
339
+ label,
340
+ fields: fields.map((f) => f.build())
341
+ });
342
+ return this;
343
+ }
344
+ }
345
+
346
+ class CollapsibleFieldBuilder extends FieldBuilder {
347
+ constructor(fields) {
348
+ super("collapsible", "");
349
+ this.config.fields = fields ? fields.map((f) => f.build()) : [];
350
+ this._ensureOptions();
351
+ }
352
+ initiallyCollapsed(val = true) {
353
+ this.config.options.initiallyCollapsed = val;
354
+ return this;
355
+ }
356
+ useAsTitle(fieldName) {
357
+ this.config.options.useAsTitle = fieldName;
358
+ return this;
359
+ }
360
+ fields(...fields) {
361
+ this.config.fields = fields.map((f) => f.build());
362
+ return this;
363
+ }
364
+ }
365
+
366
+ class JoinFieldBuilder extends FieldBuilder {
367
+ constructor(name) {
368
+ super("join", name);
369
+ }
370
+ collection(collectionSlug) {
371
+ this.config.collection = collectionSlug;
372
+ return this;
373
+ }
374
+ on(fieldName) {
375
+ this.config.on = fieldName;
376
+ return this;
377
+ }
378
+ }
379
+
380
+ class ArrayFieldBuilder extends FieldBuilder {
381
+ constructor(name) {
382
+ super("array", name);
383
+ }
384
+ of(...fields) {
385
+ this.config.fields = fields.map((f) => f.build());
386
+ return this;
387
+ }
388
+ }
389
+
390
+ class GroupFieldBuilder extends FieldBuilder {
391
+ constructor(name, fields) {
392
+ super("group", name);
393
+ if (fields) {
394
+ this.config.fields = fields.map((f) => f.build());
395
+ }
396
+ }
397
+ fields(...fields) {
398
+ this.config.fields = fields.map((f) => f.build());
399
+ return this;
400
+ }
401
+ }
402
+
403
+ class RowFieldBuilder extends FieldBuilder {
404
+ constructor(fields) {
405
+ super("row", "");
406
+ if (fields) {
407
+ this.config.fields = fields.map((f) => f.build());
408
+ }
409
+ }
410
+ fields(...fields) {
411
+ this.config.fields = fields.map((f) => f.build());
412
+ return this;
413
+ }
414
+ }
415
+
416
+ class BlockBuilder {
417
+ config;
418
+ constructor(slug) {
419
+ this.config = { slug, fields: [] };
420
+ }
421
+ label(label) {
422
+ this.config.label = label;
423
+ return this;
424
+ }
425
+ fields(...fields) {
426
+ this.config.fields = fields.map((f) => f.build());
427
+ return this;
428
+ }
429
+ build() {
430
+ return this.config;
431
+ }
432
+ }
433
+
434
+ class BlocksFieldBuilder extends FieldBuilder {
435
+ constructor(name) {
436
+ super("blocks", name);
437
+ }
438
+ blocks(...blocks) {
439
+ this.config.blocks = blocks.map((b) => b.build());
440
+ return this;
441
+ }
442
+ }
443
+
444
+ // src/schema/global.ts
445
+ class GlobalBuilder {
446
+ config = {};
447
+ _fields = [];
448
+ constructor(slug) {
449
+ this.config.slug = slug;
450
+ this.config.fields = [];
451
+ this.config.timestamps = true;
452
+ }
453
+ timestamps(enabled = true) {
454
+ this.config.timestamps = enabled;
455
+ return this;
456
+ }
457
+ label(label) {
458
+ this.config.label = label;
459
+ return this;
460
+ }
461
+ icon(iconName) {
462
+ this.config.icon = iconName;
463
+ return this;
464
+ }
465
+ fields(fields) {
466
+ const nextBuilder = new GlobalBuilder(this.config.slug);
467
+ nextBuilder.config = { ...this.config };
468
+ nextBuilder._fields = [...fields];
469
+ nextBuilder.config.fields = fields.map((f) => f.build());
470
+ return nextBuilder;
471
+ }
472
+ access(rules) {
473
+ this.config.access = rules;
474
+ return this;
475
+ }
476
+ virtual(name, options) {
477
+ const builder = new VirtualFieldBuilder(name);
478
+ if (options.label)
479
+ builder.label(options.label);
480
+ if (options.resolve)
481
+ builder.resolve(options.resolve);
482
+ if (options.returnType)
483
+ builder.returnType(options.returnType);
484
+ const nextBuilder = new GlobalBuilder(this.config.slug);
485
+ nextBuilder.config = { ...this.config };
486
+ nextBuilder._fields = [...this._fields, builder];
487
+ nextBuilder.config.fields = nextBuilder._fields.map((f) => f.build());
488
+ return nextBuilder;
489
+ }
490
+ computed(name, options) {
491
+ return this.virtual(name, options);
492
+ }
493
+ extend(opts) {
494
+ this.config = { ...this.config, ...opts };
495
+ return this;
496
+ }
497
+ build() {
498
+ if (!this.config.slug) {
499
+ throw new Error("Globals must have a slug.");
500
+ }
501
+ if (!this.config.fields || this.config.fields.length === 0) {
502
+ throw new Error(`Global "${this.config.slug}" must have at least one field.`);
503
+ }
504
+ return this.config;
505
+ }
506
+ }
507
+
508
+ // src/schema/index.ts
509
+ var Collection = {
510
+ create: (slug) => new CollectionBuilder(slug)
511
+ };
512
+ var Field = {
513
+ text: (name) => new TextFieldBuilder(name),
514
+ slug: (name) => new SlugFieldBuilder(name),
515
+ textarea: (name) => new TextAreaFieldBuilder(name),
516
+ number: (name) => new NumberFieldBuilder(name),
517
+ boolean: (name) => new BooleanFieldBuilder(name),
518
+ richText: (name) => new RichTextFieldBuilder(name),
519
+ relationship: (name) => new RelationshipFieldBuilder(name),
520
+ join: (name) => new JoinFieldBuilder(name),
521
+ file: (name) => new FileFieldBuilder(name),
522
+ array: (name) => new ArrayFieldBuilder(name),
523
+ group: (name, fields) => {
524
+ const builder = new GroupFieldBuilder(name);
525
+ if (fields)
526
+ builder.fields(...fields);
527
+ return builder;
528
+ },
529
+ tabs: () => new TabsFieldBuilder,
530
+ collapsible: (fields) => {
531
+ return new CollapsibleFieldBuilder(fields);
532
+ },
533
+ row: (fields) => {
534
+ return new RowFieldBuilder(fields);
535
+ },
536
+ blocks: (name, ...blocks) => {
537
+ const builder = new BlocksFieldBuilder(name);
538
+ builder.blocks(...blocks);
539
+ return builder;
540
+ },
541
+ block: (slug) => new BlockBuilder(slug)
542
+ };
543
+ var Global = {
544
+ create: (slug) => new GlobalBuilder(slug)
545
+ };
2
546
  export {
547
+ VirtualFieldBuilder,
3
548
  GlobalBuilder,
4
549
  Global,
5
550
  FieldBuilder,