opacacms 0.1.1 → 0.1.2

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 (212) hide show
  1. package/package.json +36 -1
  2. package/bun.lock +0 -34
  3. package/global.d.ts +0 -11
  4. package/src/admin/api-client.ts +0 -63
  5. package/src/admin/auth-client.ts +0 -40
  6. package/src/admin/custom-field.ts +0 -179
  7. package/src/admin/index.ts +0 -15
  8. package/src/admin/react.tsx +0 -72
  9. package/src/admin/router.ts +0 -9
  10. package/src/admin/stores/admin-queries.ts +0 -121
  11. package/src/admin/stores/auth.ts +0 -61
  12. package/src/admin/stores/column-visibility.ts +0 -67
  13. package/src/admin/stores/config.ts +0 -15
  14. package/src/admin/stores/media.ts +0 -95
  15. package/src/admin/stores/query.ts +0 -13
  16. package/src/admin/stores/ui.ts +0 -29
  17. package/src/admin/ui/admin-client.tsx +0 -283
  18. package/src/admin/ui/admin-layout.tsx +0 -276
  19. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  20. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  21. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  22. package/src/admin/ui/components/Table.tsx +0 -67
  23. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  24. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  25. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  26. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  27. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  28. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  29. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  30. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  31. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  32. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  33. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  34. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  35. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  36. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  37. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  38. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  39. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  40. package/src/admin/ui/components/fields/index.tsx +0 -371
  41. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  42. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  43. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  44. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  45. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  46. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  47. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  48. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  49. package/src/admin/ui/components/fields/utils.ts +0 -1
  50. package/src/admin/ui/components/link.tsx +0 -41
  51. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  52. package/src/admin/ui/components/toast.tsx +0 -72
  53. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  54. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  55. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  56. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  57. package/src/admin/ui/components/ui/button.tsx +0 -26
  58. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  59. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  60. package/src/admin/ui/components/ui/group.tsx +0 -20
  61. package/src/admin/ui/components/ui/index.ts +0 -17
  62. package/src/admin/ui/components/ui/input.tsx +0 -12
  63. package/src/admin/ui/components/ui/join.tsx +0 -53
  64. package/src/admin/ui/components/ui/label.tsx +0 -11
  65. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  66. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  67. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  68. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  69. package/src/admin/ui/components/ui/select.tsx +0 -187
  70. package/src/admin/ui/components/ui/separator.tsx +0 -21
  71. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  72. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  73. package/src/admin/ui/components/ui/utils.ts +0 -3
  74. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  75. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  76. package/src/admin/ui/styles/accordion.scss +0 -60
  77. package/src/admin/ui/styles/animations.scss +0 -41
  78. package/src/admin/ui/styles/asset-manager.scss +0 -547
  79. package/src/admin/ui/styles/badge.scss +0 -13
  80. package/src/admin/ui/styles/base.scss +0 -22
  81. package/src/admin/ui/styles/button.scss +0 -161
  82. package/src/admin/ui/styles/card.scss +0 -13
  83. package/src/admin/ui/styles/collapsible.scss +0 -75
  84. package/src/admin/ui/styles/data-detail.scss +0 -92
  85. package/src/admin/ui/styles/dialog.scss +0 -102
  86. package/src/admin/ui/styles/empty-state.scss +0 -22
  87. package/src/admin/ui/styles/group.scss +0 -19
  88. package/src/admin/ui/styles/index.scss +0 -33
  89. package/src/admin/ui/styles/input.scss +0 -80
  90. package/src/admin/ui/styles/label.scss +0 -12
  91. package/src/admin/ui/styles/layout.scss +0 -56
  92. package/src/admin/ui/styles/lexical.scss +0 -469
  93. package/src/admin/ui/styles/loading.scss +0 -102
  94. package/src/admin/ui/styles/media-registry.scss +0 -597
  95. package/src/admin/ui/styles/pagination.scss +0 -20
  96. package/src/admin/ui/styles/radio-group.scss +0 -66
  97. package/src/admin/ui/styles/row.scss +0 -17
  98. package/src/admin/ui/styles/scrollbar.scss +0 -36
  99. package/src/admin/ui/styles/select.scss +0 -121
  100. package/src/admin/ui/styles/separator.scss +0 -14
  101. package/src/admin/ui/styles/sheet.scss +0 -152
  102. package/src/admin/ui/styles/sidebar.scss +0 -148
  103. package/src/admin/ui/styles/switch.scss +0 -59
  104. package/src/admin/ui/styles/table.scss +0 -207
  105. package/src/admin/ui/styles/tabs.scss +0 -62
  106. package/src/admin/ui/styles/toast.scss +0 -45
  107. package/src/admin/ui/styles/variables.scss +0 -24
  108. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  109. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  110. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  111. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  112. package/src/admin/ui/views/init-view.tsx +0 -182
  113. package/src/admin/ui/views/login-view.tsx +0 -123
  114. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  115. package/src/admin/ui/views/settings-view.tsx +0 -729
  116. package/src/admin/webcomponent.tsx +0 -15
  117. package/src/auth/index.ts +0 -194
  118. package/src/auth/migrations.ts +0 -87
  119. package/src/auth/premissions.ts +0 -46
  120. package/src/cli/commands/generate-types.ts +0 -116
  121. package/src/cli/commands/init.ts +0 -95
  122. package/src/cli/commands/migrate-commands.ts +0 -160
  123. package/src/cli/commands/seed-command.ts +0 -11
  124. package/src/cli/d1-mock.ts +0 -101
  125. package/src/cli/index.test.ts +0 -84
  126. package/src/cli/index.ts +0 -183
  127. package/src/cli/r2-mock.ts +0 -217
  128. package/src/cli/seeding.ts +0 -409
  129. package/src/client.ts +0 -181
  130. package/src/config-utils.ts +0 -102
  131. package/src/config.ts +0 -49
  132. package/src/db/adapter.ts +0 -53
  133. package/src/db/better-sqlite.ts +0 -630
  134. package/src/db/bun-sqlite.ts +0 -646
  135. package/src/db/d1.ts +0 -711
  136. package/src/db/index.ts +0 -2
  137. package/src/db/kysely/data-mapper.ts +0 -142
  138. package/src/db/kysely/field-mapper.ts +0 -148
  139. package/src/db/kysely/migration-generator.ts +0 -223
  140. package/src/db/kysely/query-builder.ts +0 -92
  141. package/src/db/kysely/schema-builder.ts +0 -439
  142. package/src/db/kysely/sql-utils.ts +0 -13
  143. package/src/db/migration.ts +0 -40
  144. package/src/db/postgres.ts +0 -621
  145. package/src/db/sqlite.ts +0 -658
  146. package/src/db/system-schema.ts +0 -121
  147. package/src/index.ts +0 -11
  148. package/src/runtimes/README.md +0 -59
  149. package/src/runtimes/bun.ts +0 -49
  150. package/src/runtimes/cloudflare-workers.ts +0 -38
  151. package/src/runtimes/next.ts +0 -26
  152. package/src/runtimes/node.ts +0 -52
  153. package/src/schema/collection.ts +0 -184
  154. package/src/schema/fields/base.ts +0 -164
  155. package/src/schema/fields/index.ts +0 -427
  156. package/src/schema/global.ts +0 -145
  157. package/src/schema/index.ts +0 -4
  158. package/src/schema/infer.ts +0 -72
  159. package/src/server/admin-router.ts +0 -20
  160. package/src/server/admin.ts +0 -142
  161. package/src/server/assets.ts +0 -306
  162. package/src/server/collection-router.ts +0 -55
  163. package/src/server/handlers.ts +0 -722
  164. package/src/server/middlewares/admin.ts +0 -27
  165. package/src/server/middlewares/auth.ts +0 -89
  166. package/src/server/middlewares/context.ts +0 -17
  167. package/src/server/middlewares/cors.ts +0 -24
  168. package/src/server/middlewares/database-init.ts +0 -74
  169. package/src/server/middlewares/rate-limit.ts +0 -71
  170. package/src/server/router.ts +0 -47
  171. package/src/server/setup-middlewares.ts +0 -58
  172. package/src/server/system-router.ts +0 -35
  173. package/src/server.ts +0 -9
  174. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  175. package/src/storage/adapters/local.ts +0 -146
  176. package/src/storage/adapters/s3.ts +0 -186
  177. package/src/storage/errors.ts +0 -46
  178. package/src/storage/index.ts +0 -6
  179. package/src/storage/types.ts +0 -39
  180. package/src/types.ts +0 -605
  181. package/src/utils/lexical.ts +0 -37
  182. package/src/utils/logger.ts +0 -73
  183. package/src/validation.ts +0 -429
  184. package/src/validator.ts +0 -179
  185. package/test/admin-custom-field.test.ts +0 -162
  186. package/test/admin-react-field.test.tsx +0 -134
  187. package/test/api-features.test.ts +0 -78
  188. package/test/api.test.ts +0 -178
  189. package/test/auth.test.ts +0 -62
  190. package/test/cli-integration.test.ts +0 -148
  191. package/test/cli.test.ts +0 -25
  192. package/test/db/postgres.test.ts +0 -95
  193. package/test/db/sqlite-filter.test.ts +0 -53
  194. package/test/db/sqlite.test.ts +0 -82
  195. package/test/engine-features.test.ts +0 -79
  196. package/test/globals.test.ts +0 -74
  197. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  198. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  199. package/test/integration-tmp/my-test-app/index.ts +0 -8
  200. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  201. package/test/integration-tmp/my-test-app/package.json +0 -12
  202. package/test/populate.test.ts +0 -79
  203. package/test/runtimes.test.ts +0 -43
  204. package/test/schema-builder.test.ts +0 -107
  205. package/test/schema-features.test.ts +0 -63
  206. package/test/seeding.test.ts +0 -68
  207. package/test/storage/local.test.ts +0 -72
  208. package/test/storage/s3.test.ts +0 -60
  209. package/test/structural-data.test.ts +0 -100
  210. package/test/test-setup.ts +0 -11
  211. package/test/validation.test.ts +0 -162
  212. package/tsconfig.json +0 -42
@@ -1,164 +0,0 @@
1
- import type { BaseField, FieldAccessConfig } from "../../types";
2
-
3
- /**
4
- * The base class for all Fluent API Field Builders.
5
- * Accumulates configuration state linearly.
6
- *
7
- * @template TType The literal string type of the field (e.g., 'text', 'relationship').
8
- * @template TName The literal string name of the field.
9
- * @template TValue The TypeScript literal value type this field produces (e.g., string, number).
10
- */
11
- export abstract class FieldBuilder<
12
- TType extends string,
13
- TName extends string = string,
14
- TValue = any,
15
- TSubFields extends readonly any[] = any[],
16
- > {
17
- // Brands for type inference (never used at runtime)
18
- public declare readonly __type: TType;
19
- public declare readonly __name: TName;
20
- public declare readonly __value: TValue;
21
- public declare readonly __sub: TSubFields;
22
-
23
- protected config: Partial<BaseField & Record<string, any>> = {};
24
-
25
- constructor(
26
- public readonly type: TType,
27
- public readonly name: TName,
28
- ) {
29
- this.config = { type, name };
30
- }
31
-
32
- /**
33
- * Defines a user-friendly label for the Admin UI.
34
- */
35
- public label(label: string): this {
36
- this.config.label = label;
37
- return this;
38
- }
39
-
40
- /**
41
- * Sets the placeholder text for the input field.
42
- */
43
- public placeholder(text: string): this {
44
- this.config.placeholder = text;
45
- return this;
46
- }
47
-
48
- /**
49
- * Marks the field as strictly required.
50
- */
51
- public required(val = true): this {
52
- this.config.required = val;
53
- return this;
54
- }
55
-
56
- /**
57
- * Marks the field as unique within the database table.
58
- */
59
- public unique(val = true): this {
60
- this.config.unique = val;
61
- return this;
62
- }
63
-
64
- /**
65
- * Enables native field-level internationalization.
66
- */
67
- public localized(val = true): this {
68
- this.config.localized = val;
69
- return this;
70
- }
71
-
72
- /**
73
- * Sets a default value for the field.
74
- */
75
- public defaultValue(val: TValue): this {
76
- this.config.defaultValue = val;
77
- return this;
78
- }
79
-
80
- /**
81
- * A custom validation callback function.
82
- */
83
- public validate(fn: (value: unknown) => boolean | string): this {
84
- this.config.validate = fn;
85
- return this;
86
- }
87
-
88
- /**
89
- * Configure granular access control for this specific field.
90
- */
91
- public access(config: FieldAccessConfig): this {
92
- this.config.access = config;
93
- return this;
94
- }
95
-
96
- /**
97
- * Add a descriptive text below the field in the Admin UI.
98
- */
99
- public description(text: string): this {
100
- this._ensureAdmin();
101
- this.config.admin!.description = text;
102
- return this;
103
- }
104
-
105
- /**
106
- * Override Admin UI with custom React components.
107
- */
108
- public admin(opts: NonNullable<BaseField["admin"]>): this {
109
- this._ensureAdmin();
110
- this.config.admin = { ...this.config.admin, ...opts };
111
- return this;
112
- }
113
-
114
- /**
115
- * Completely hide the field from the Admin UI and API responses (depending on access).
116
- */
117
- public hidden(val = true): this {
118
- this._ensureAdmin();
119
- this.config.admin!.hidden = val;
120
- return this;
121
- }
122
-
123
- /**
124
- * Mark the field as read-only in the Admin UI.
125
- */
126
- public readOnly(val = true): this {
127
- this._ensureAdmin();
128
- this.config.admin!.readOnly = val;
129
- return this;
130
- }
131
-
132
- /**
133
- * Spreads arbitrary runtime configuration for any non-strongly-typed features.
134
- */
135
- public extend(opts: Record<string, any>): this {
136
- this.config = { ...this.config, ...opts };
137
- return this;
138
- }
139
-
140
- /**
141
- * Helper to ensure the `admin` options object is initialized.
142
- */
143
- protected _ensureAdmin() {
144
- if (!this.config.admin) {
145
- this.config.admin = {};
146
- }
147
- }
148
-
149
- /**
150
- * Helper to ensure the `options` object is initialized.
151
- */
152
- protected _ensureOptions() {
153
- if (!this.config.options) {
154
- this.config.options = {};
155
- }
156
- }
157
-
158
- /**
159
- * Compiles the accumulated builder state down into the raw Object structure expected by OpacaCMS.
160
- */
161
- public build(): any {
162
- return this.config;
163
- }
164
- }
@@ -1,427 +0,0 @@
1
- import { FieldBuilder } from "./base";
2
-
3
- export class TextFieldBuilder<TName extends string> extends FieldBuilder<"text", TName, string> {
4
- constructor(name: TName) {
5
- super("text", name);
6
- }
7
- }
8
-
9
- export class SlugFieldBuilder<TName extends string> extends FieldBuilder<"slug", TName, string> {
10
- constructor(name: TName) {
11
- super("slug", name);
12
- }
13
-
14
- public from(sourceField: string): this {
15
- (this.config as any).from = sourceField;
16
- return this;
17
- }
18
-
19
- public format(fn: (val: string) => string): this {
20
- (this.config as any).format = fn;
21
- return this;
22
- }
23
- }
24
-
25
- export class TextAreaFieldBuilder<TName extends string> extends FieldBuilder<
26
- "textarea",
27
- TName,
28
- string
29
- > {
30
- constructor(name: TName) {
31
- super("textarea", name);
32
- }
33
- }
34
-
35
- export class NumberFieldBuilder<TName extends string> extends FieldBuilder<
36
- "number",
37
- TName,
38
- number
39
- > {
40
- constructor(name: TName) {
41
- super("number", name);
42
- }
43
-
44
- public min(val: number): this {
45
- this._ensureOptions();
46
- this.config.options!.min = val;
47
- return this;
48
- }
49
-
50
- public max(val: number): this {
51
- this._ensureOptions();
52
- this.config.options!.max = val;
53
- return this;
54
- }
55
- }
56
-
57
- export class BooleanFieldBuilder<TName extends string> extends FieldBuilder<
58
- "boolean",
59
- TName,
60
- boolean
61
- > {
62
- constructor(name: TName) {
63
- super("boolean", name);
64
- }
65
-
66
- public display(type: "switch" | "toggle" | "checkbox" | "select"): this {
67
- this._ensureOptions();
68
- this.config.options!.display = type;
69
- return this;
70
- }
71
- }
72
-
73
- export class RichTextFieldBuilder<TName extends string> extends FieldBuilder<
74
- "richtext",
75
- TName,
76
- string
77
- > {
78
- constructor(name: TName) {
79
- super("richtext", name);
80
- }
81
-
82
- public mode(mode: "simple" | "notion"): this {
83
- this._ensureOptions();
84
- this.config.options!.defaultMode = mode;
85
- return this;
86
- }
87
- }
88
-
89
- export class RelationshipFieldBuilder<TName extends string> extends FieldBuilder<
90
- "relationship",
91
- TName,
92
- string | string[]
93
- > {
94
- constructor(name: TName) {
95
- super("relationship", name);
96
- }
97
-
98
- public to(collection: string | { slug: string }): this {
99
- this.config.relationTo = typeof collection === "string" ? collection : collection.slug;
100
- return this;
101
- }
102
-
103
- public single(): this {
104
- this.config.hasMany = false;
105
- return this;
106
- }
107
-
108
- public many(): this {
109
- this.config.hasMany = true;
110
- return this;
111
- }
112
-
113
- public displayField(field: string): this {
114
- this.config.displayField = field;
115
- return this;
116
- }
117
- }
118
-
119
- export class FileFieldBuilder<TName extends string> extends FieldBuilder<"file", TName, unknown> {
120
- constructor(name: TName) {
121
- super("file", name);
122
- }
123
-
124
- public bucket(bucketName: string): this {
125
- this.config.bucket = bucketName;
126
- return this;
127
- }
128
-
129
- public allowedmime_types(types: string[]): this {
130
- this._ensureOptions();
131
- this.config.options!.allowedmime_types = types;
132
- return this;
133
- }
134
-
135
- public maxSize(bytes: number): this {
136
- this._ensureOptions();
137
- this.config.options!.maxFileSize = bytes;
138
- return this;
139
- }
140
- }
141
-
142
- export class DateFieldBuilder<TName extends string> extends FieldBuilder<
143
- "date",
144
- TName,
145
- string | Date
146
- > {
147
- constructor(name: TName) {
148
- super("date", name);
149
- }
150
- }
151
-
152
- export class SelectFieldBuilder<TName extends string> extends FieldBuilder<
153
- "select",
154
- TName,
155
- string
156
- > {
157
- constructor(name: TName) {
158
- super("select", name);
159
- }
160
-
161
- public choices(choices: string[] | { label: string; value: string }[]): this {
162
- this._ensureOptions();
163
- this.config.options!.choices = choices;
164
- return this;
165
- }
166
- }
167
-
168
- export class RadioFieldBuilder<TName extends string> extends FieldBuilder<"radio", TName, string> {
169
- constructor(name: TName) {
170
- super("radio", name);
171
- }
172
-
173
- public choices(choices: string[] | { label: string; value: string }[]): this {
174
- this._ensureOptions();
175
- this.config.options.choices = choices;
176
- return this;
177
- }
178
- }
179
-
180
- export class TabsFieldBuilder<TTabs extends readonly any[] = []> extends FieldBuilder<
181
- "tabs",
182
- "",
183
- unknown,
184
- TTabs
185
- > {
186
- constructor() {
187
- super("tabs", "");
188
- this.config.tabs = [];
189
- }
190
-
191
- public tab<TLabel extends string, TSub extends readonly FieldBuilder<any, any, any, any>[]>(
192
- label: TLabel,
193
- ...fields: TSub
194
- ): TabsFieldBuilder<[...TTabs, { label: TLabel; fields: TSub }]> {
195
- this.config.tabs.push({
196
- label,
197
- fields: fields.map((f) => f.build()),
198
- });
199
- return this as any;
200
- }
201
- }
202
-
203
- export class CollapsibleFieldBuilder<
204
- TNames extends string = string,
205
- TSub extends readonly any[] = any[],
206
- > extends FieldBuilder<"collapsible", "", unknown, TSub> {
207
- constructor(fields?: FieldBuilder<any, TNames, any, any>[]) {
208
- super("collapsible", "");
209
- this.config.fields = fields ? fields.map((f) => f.build()) : [];
210
- this._ensureOptions();
211
- }
212
-
213
- public initiallyCollapsed(val = true): this {
214
- this.config.options!.initiallyCollapsed = val;
215
- return this;
216
- }
217
-
218
- public useAsTitle(fieldName: TNames | (string & {})): this {
219
- this.config.options!.useAsTitle = fieldName;
220
- return this;
221
- }
222
-
223
- public fields<NewSub extends readonly FieldBuilder<any, any, any>[]>(
224
- ...fields: NewSub
225
- ): CollapsibleFieldBuilder<ExtractNames<NewSub>, NewSub> {
226
- this.config.fields = fields.map((f) => f.build());
227
- return this as any;
228
- }
229
- }
230
-
231
- type ExtractNames<T extends readonly any[]> = T[number]["name"];
232
-
233
- export class JoinFieldBuilder<TName extends string> extends FieldBuilder<"join", TName, any[]> {
234
- constructor(name: TName) {
235
- super("join", name);
236
- }
237
-
238
- public collection(collectionSlug: string): this {
239
- this.config.collection = collectionSlug;
240
- return this;
241
- }
242
-
243
- public on(fieldName: string): this {
244
- this.config.on = fieldName;
245
- return this;
246
- }
247
- }
248
-
249
- export class ArrayFieldBuilder<
250
- TName extends string,
251
- TSub extends readonly any[] = any[],
252
- > extends FieldBuilder<"array", TName, unknown[], TSub> {
253
- constructor(name: TName) {
254
- super("array", name);
255
- }
256
-
257
- public of<NewSub extends readonly FieldBuilder<any, any, any, any>[]>(
258
- ...fields: NewSub
259
- ): ArrayFieldBuilder<TName, NewSub> {
260
- this.config.fields = fields.map((f) => f.build());
261
- return this as any;
262
- }
263
- }
264
-
265
- export class GroupFieldBuilder<
266
- TName extends string,
267
- TNames extends string = string,
268
- TSub extends readonly any[] = any[],
269
- > extends FieldBuilder<"group", TName, Record<string, any>, TSub> {
270
- constructor(name: TName, fields?: FieldBuilder<any, TNames, any, any>[]) {
271
- super("group", name);
272
- if (fields) {
273
- this.config.fields = fields.map((f) => f.build());
274
- }
275
- }
276
-
277
- public fields<NewSub extends readonly FieldBuilder<any, any, any, any>[]>(
278
- ...fields: NewSub
279
- ): GroupFieldBuilder<TName, ExtractNames<NewSub>, NewSub> {
280
- this.config.fields = fields.map((f) => f.build());
281
- return this as any;
282
- }
283
- }
284
-
285
- export class RowFieldBuilder<TSub extends readonly any[] = any[]> extends FieldBuilder<
286
- "row",
287
- "",
288
- unknown,
289
- TSub
290
- > {
291
- constructor(fields?: FieldBuilder<any, any, any, any>[]) {
292
- super("row", "");
293
- if (fields) {
294
- this.config.fields = fields.map((f) => f.build());
295
- }
296
- }
297
-
298
- public fields<NewSub extends readonly FieldBuilder<any, any, any, any>[]>(
299
- ...fields: NewSub
300
- ): RowFieldBuilder<NewSub> {
301
- this.config.fields = fields.map((f) => f.build());
302
- return this as any;
303
- }
304
- }
305
-
306
- // Block Builder for Blocks Field
307
- export class BlockBuilder<
308
- TSlug extends string,
309
- TNames extends string = string,
310
- TSub extends readonly any[] = any[],
311
- > {
312
- private config: Record<string, any>;
313
-
314
- constructor(slug: TSlug) {
315
- this.config = { slug, fields: [] };
316
- }
317
-
318
- public label(label: string): this {
319
- this.config.label = label;
320
- return this;
321
- }
322
-
323
- public fields<NewSub extends readonly FieldBuilder<any, any, any, any>[]>(
324
- ...fields: NewSub
325
- ): BlockBuilder<TSlug, ExtractNames<NewSub>, NewSub> {
326
- this.config.fields = fields.map((f) => f.build());
327
- return this as any;
328
- }
329
-
330
- public build() {
331
- return this.config;
332
- }
333
- }
334
-
335
- export class VirtualFieldBuilder<TName extends string, TData = any> extends FieldBuilder<
336
- "virtual",
337
- TName,
338
- any
339
- > {
340
- constructor(name: TName) {
341
- super("virtual", name);
342
- }
343
-
344
- public resolve(
345
- fn: (args: {
346
- data: TData;
347
- req: any;
348
- user: any;
349
- session: any;
350
- apiKey?: any;
351
- }) => any | Promise<any>,
352
- ): this {
353
- this.config.resolve = fn;
354
- return this;
355
- }
356
-
357
- public returnType(type: "string" | "number" | "boolean" | "json"): this {
358
- this.config.returnType = type;
359
- return this;
360
- }
361
- }
362
-
363
- export class BlocksFieldBuilder<
364
- TName extends string,
365
- TBlocks extends readonly any[] = any[],
366
- > extends FieldBuilder<"blocks", TName, any[], TBlocks> {
367
- constructor(name: TName) {
368
- super("blocks", name);
369
- }
370
-
371
- public blocks<NewBlocks extends readonly BlockBuilder<any, any, any>[]>(
372
- ...blocks: NewBlocks
373
- ): BlocksFieldBuilder<TName, NewBlocks> {
374
- this.config.blocks = blocks.map((b) => b.build());
375
- return this as any;
376
- }
377
- }
378
-
379
- /**
380
- * The Field Factory object containing methods to instantiate specific field builders.
381
- */
382
- export const Field = {
383
- text: <N extends string>(name: N) => new TextFieldBuilder<N>(name),
384
- slug: <N extends string>(name: N) => new SlugFieldBuilder<N>(name),
385
- textarea: <N extends string>(name: N) => new TextAreaFieldBuilder<N>(name),
386
- number: <N extends string>(name: N) => new NumberFieldBuilder<N>(name),
387
- boolean: <N extends string>(name: N) => new BooleanFieldBuilder<N>(name),
388
- date: <N extends string>(name: N) => new DateFieldBuilder<N>(name),
389
- select: <N extends string>(name: N) => new SelectFieldBuilder<N>(name),
390
- radio: <N extends string>(name: N) => new RadioFieldBuilder<N>(name),
391
- richText: <N extends string>(name: N) => new RichTextFieldBuilder<N>(name),
392
- relationship: <N extends string>(name: N) => new RelationshipFieldBuilder<N>(name),
393
- join: <N extends string>(name: N) => new JoinFieldBuilder<N>(name),
394
- file: <N extends string>(name: N) => new FileFieldBuilder<N>(name),
395
- array: <N extends string>(name: N) => new ArrayFieldBuilder<N>(name),
396
- group: <N extends string, TSub extends readonly FieldBuilder<any, any, any, any>[]>(
397
- name: N,
398
- fields?: TSub,
399
- ) => {
400
- const builder = new GroupFieldBuilder<N, any, TSub>(name);
401
- if (fields) builder.fields(...(fields as any));
402
- return builder;
403
- },
404
- tabs: () => new TabsFieldBuilder(),
405
- collapsible: <N extends string, S extends readonly FieldBuilder<any, any, any, any>[]>(
406
- fields?: S,
407
- ) => {
408
- const builder = new CollapsibleFieldBuilder<ExtractNames<S>, S>(fields as any);
409
- return builder;
410
- },
411
- row: <S extends readonly FieldBuilder<any, any, any, any>[]>(fields?: S) => {
412
- const builder = new RowFieldBuilder<S>(fields as any);
413
- return builder;
414
- },
415
- blocks: <N extends string, TSub extends readonly BlockBuilder<any, any, any>[]>(
416
- name: N,
417
- ...blocks: TSub
418
- ) => {
419
- const builder = new BlocksFieldBuilder<N, TSub>(name);
420
- builder.blocks(...(blocks as any));
421
- return builder;
422
- },
423
- block: <N extends string>(slug: N) => new BlockBuilder<N>(slug),
424
- };
425
-
426
- // Also export the base builders if extensions are needed
427
- export * from "./base";