opacacms 0.1.12 → 0.1.13

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 (217) hide show
  1. package/dist/admin/index.js +0 -4
  2. package/dist/admin/webcomponent.d.ts +0 -1
  3. package/dist/admin/webcomponent.js +0 -4
  4. package/dist/admin.css +1 -0
  5. package/package.json +8 -2
  6. package/bun.lock +0 -34
  7. package/dist/admin/index.css +0 -47
  8. package/dist/admin/webcomponent.css +0 -47
  9. package/global.d.ts +0 -11
  10. package/src/admin/api-client.ts +0 -63
  11. package/src/admin/auth-client.ts +0 -40
  12. package/src/admin/custom-field.ts +0 -179
  13. package/src/admin/index.ts +0 -15
  14. package/src/admin/react.tsx +0 -72
  15. package/src/admin/router.ts +0 -9
  16. package/src/admin/stores/admin-queries.ts +0 -121
  17. package/src/admin/stores/auth.ts +0 -61
  18. package/src/admin/stores/column-visibility.ts +0 -67
  19. package/src/admin/stores/config.ts +0 -15
  20. package/src/admin/stores/media.ts +0 -95
  21. package/src/admin/stores/query.ts +0 -13
  22. package/src/admin/stores/ui.ts +0 -29
  23. package/src/admin/ui/admin-client.tsx +0 -283
  24. package/src/admin/ui/admin-layout.tsx +0 -276
  25. package/src/admin/ui/components/ColumnVisibilityToggle.tsx +0 -141
  26. package/src/admin/ui/components/DataDetailSheet.tsx +0 -141
  27. package/src/admin/ui/components/DataDetailView.tsx +0 -175
  28. package/src/admin/ui/components/Table.tsx +0 -67
  29. package/src/admin/ui/components/fields/ArrayField.tsx +0 -166
  30. package/src/admin/ui/components/fields/BlocksField.tsx +0 -202
  31. package/src/admin/ui/components/fields/BooleanField.tsx +0 -50
  32. package/src/admin/ui/components/fields/CollapsibleField.tsx +0 -75
  33. package/src/admin/ui/components/fields/DateField.tsx +0 -45
  34. package/src/admin/ui/components/fields/FileField.tsx +0 -322
  35. package/src/admin/ui/components/fields/GroupField.tsx +0 -50
  36. package/src/admin/ui/components/fields/JoinField.tsx +0 -23
  37. package/src/admin/ui/components/fields/NumberField.tsx +0 -46
  38. package/src/admin/ui/components/fields/RadioField.tsx +0 -62
  39. package/src/admin/ui/components/fields/RelationshipField.tsx +0 -278
  40. package/src/admin/ui/components/fields/RowField.tsx +0 -40
  41. package/src/admin/ui/components/fields/SelectField.tsx +0 -59
  42. package/src/admin/ui/components/fields/TabsField.tsx +0 -101
  43. package/src/admin/ui/components/fields/TextAreaField.tsx +0 -54
  44. package/src/admin/ui/components/fields/TextField.tsx +0 -49
  45. package/src/admin/ui/components/fields/VirtualField.tsx +0 -53
  46. package/src/admin/ui/components/fields/index.tsx +0 -371
  47. package/src/admin/ui/components/fields/richtext-editor/index.tsx +0 -211
  48. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +0 -142
  49. package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +0 -95
  50. package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +0 -226
  51. package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +0 -16
  52. package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +0 -184
  53. package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +0 -240
  54. package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +0 -40
  55. package/src/admin/ui/components/fields/utils.ts +0 -1
  56. package/src/admin/ui/components/link.tsx +0 -41
  57. package/src/admin/ui/components/media/AssetManagerModal.tsx +0 -334
  58. package/src/admin/ui/components/toast.tsx +0 -72
  59. package/src/admin/ui/components/ui/accordion.tsx +0 -51
  60. package/src/admin/ui/components/ui/alert-dialog.tsx +0 -98
  61. package/src/admin/ui/components/ui/blocks.tsx +0 -32
  62. package/src/admin/ui/components/ui/breadcrumbs.tsx +0 -59
  63. package/src/admin/ui/components/ui/button.tsx +0 -26
  64. package/src/admin/ui/components/ui/collapsible.tsx +0 -124
  65. package/src/admin/ui/components/ui/dialog.tsx +0 -79
  66. package/src/admin/ui/components/ui/group.tsx +0 -20
  67. package/src/admin/ui/components/ui/index.ts +0 -17
  68. package/src/admin/ui/components/ui/input.tsx +0 -12
  69. package/src/admin/ui/components/ui/join.tsx +0 -53
  70. package/src/admin/ui/components/ui/label.tsx +0 -11
  71. package/src/admin/ui/components/ui/radio-group.tsx +0 -75
  72. package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +0 -122
  73. package/src/admin/ui/components/ui/relationship.tsx +0 -58
  74. package/src/admin/ui/components/ui/scroll-area.tsx +0 -19
  75. package/src/admin/ui/components/ui/select.tsx +0 -187
  76. package/src/admin/ui/components/ui/separator.tsx +0 -21
  77. package/src/admin/ui/components/ui/sheet.tsx +0 -106
  78. package/src/admin/ui/components/ui/tabs.tsx +0 -116
  79. package/src/admin/ui/components/ui/utils.ts +0 -3
  80. package/src/admin/ui/hooks/use-debounce.ts +0 -15
  81. package/src/admin/ui/styles/_locale-switcher.scss +0 -33
  82. package/src/admin/ui/styles/accordion.scss +0 -60
  83. package/src/admin/ui/styles/animations.scss +0 -41
  84. package/src/admin/ui/styles/asset-manager.scss +0 -547
  85. package/src/admin/ui/styles/badge.scss +0 -13
  86. package/src/admin/ui/styles/base.scss +0 -22
  87. package/src/admin/ui/styles/button.scss +0 -161
  88. package/src/admin/ui/styles/card.scss +0 -13
  89. package/src/admin/ui/styles/collapsible.scss +0 -75
  90. package/src/admin/ui/styles/data-detail.scss +0 -92
  91. package/src/admin/ui/styles/dialog.scss +0 -102
  92. package/src/admin/ui/styles/empty-state.scss +0 -22
  93. package/src/admin/ui/styles/group.scss +0 -19
  94. package/src/admin/ui/styles/index.scss +0 -33
  95. package/src/admin/ui/styles/input.scss +0 -80
  96. package/src/admin/ui/styles/label.scss +0 -12
  97. package/src/admin/ui/styles/layout.scss +0 -56
  98. package/src/admin/ui/styles/lexical.scss +0 -469
  99. package/src/admin/ui/styles/loading.scss +0 -102
  100. package/src/admin/ui/styles/media-registry.scss +0 -597
  101. package/src/admin/ui/styles/pagination.scss +0 -20
  102. package/src/admin/ui/styles/radio-group.scss +0 -66
  103. package/src/admin/ui/styles/row.scss +0 -17
  104. package/src/admin/ui/styles/scrollbar.scss +0 -36
  105. package/src/admin/ui/styles/select.scss +0 -121
  106. package/src/admin/ui/styles/separator.scss +0 -14
  107. package/src/admin/ui/styles/sheet.scss +0 -152
  108. package/src/admin/ui/styles/sidebar.scss +0 -148
  109. package/src/admin/ui/styles/switch.scss +0 -59
  110. package/src/admin/ui/styles/table.scss +0 -207
  111. package/src/admin/ui/styles/tabs.scss +0 -62
  112. package/src/admin/ui/styles/toast.scss +0 -45
  113. package/src/admin/ui/styles/variables.scss +0 -24
  114. package/src/admin/ui/views/collection-list-view.tsx +0 -720
  115. package/src/admin/ui/views/dashboard-view.tsx +0 -263
  116. package/src/admin/ui/views/document-edit-view.tsx +0 -384
  117. package/src/admin/ui/views/global-edit-view.tsx +0 -226
  118. package/src/admin/ui/views/init-view.tsx +0 -182
  119. package/src/admin/ui/views/login-view.tsx +0 -123
  120. package/src/admin/ui/views/media-registry-view.tsx +0 -1104
  121. package/src/admin/ui/views/settings-view.tsx +0 -729
  122. package/src/admin/webcomponent.tsx +0 -15
  123. package/src/auth/index.ts +0 -194
  124. package/src/auth/migrations.ts +0 -87
  125. package/src/auth/premissions.ts +0 -46
  126. package/src/cli/commands/generate-types.ts +0 -116
  127. package/src/cli/commands/init.ts +0 -95
  128. package/src/cli/commands/migrate-commands.ts +0 -160
  129. package/src/cli/commands/seed-command.ts +0 -11
  130. package/src/cli/d1-mock.ts +0 -101
  131. package/src/cli/index.test.ts +0 -84
  132. package/src/cli/index.ts +0 -183
  133. package/src/cli/r2-mock.ts +0 -217
  134. package/src/cli/seeding.ts +0 -409
  135. package/src/client.ts +0 -181
  136. package/src/config-utils.ts +0 -102
  137. package/src/config.ts +0 -49
  138. package/src/db/adapter.ts +0 -53
  139. package/src/db/better-sqlite.ts +0 -657
  140. package/src/db/bun-sqlite.ts +0 -666
  141. package/src/db/d1.ts +0 -721
  142. package/src/db/index.ts +0 -10
  143. package/src/db/kysely/data-mapper.ts +0 -142
  144. package/src/db/kysely/field-mapper.ts +0 -149
  145. package/src/db/kysely/migration-generator.ts +0 -223
  146. package/src/db/kysely/query-builder.ts +0 -92
  147. package/src/db/kysely/schema-builder.ts +0 -439
  148. package/src/db/kysely/sql-utils.ts +0 -13
  149. package/src/db/postgres.ts +0 -631
  150. package/src/db/sqlite.ts +0 -670
  151. package/src/db/system-schema.ts +0 -121
  152. package/src/index.ts +0 -13
  153. package/src/runtimes/README.md +0 -59
  154. package/src/runtimes/bun.ts +0 -49
  155. package/src/runtimes/cloudflare-workers.ts +0 -38
  156. package/src/runtimes/next.ts +0 -26
  157. package/src/runtimes/node.ts +0 -52
  158. package/src/schema/collection.ts +0 -184
  159. package/src/schema/fields/base.ts +0 -164
  160. package/src/schema/fields/index.ts +0 -427
  161. package/src/schema/global.ts +0 -145
  162. package/src/schema/index.ts +0 -4
  163. package/src/schema/infer.ts +0 -72
  164. package/src/server/admin-router.ts +0 -20
  165. package/src/server/admin.ts +0 -142
  166. package/src/server/assets.ts +0 -306
  167. package/src/server/collection-router.ts +0 -55
  168. package/src/server/handlers.ts +0 -722
  169. package/src/server/middlewares/admin.ts +0 -27
  170. package/src/server/middlewares/auth.ts +0 -89
  171. package/src/server/middlewares/context.ts +0 -17
  172. package/src/server/middlewares/cors.ts +0 -24
  173. package/src/server/middlewares/database-init.ts +0 -74
  174. package/src/server/middlewares/rate-limit.ts +0 -77
  175. package/src/server/router.ts +0 -47
  176. package/src/server/setup-middlewares.ts +0 -58
  177. package/src/server/system-router.ts +0 -35
  178. package/src/server.ts +0 -9
  179. package/src/storage/adapters/cloudflare-r2.ts +0 -136
  180. package/src/storage/adapters/local.ts +0 -146
  181. package/src/storage/adapters/s3.ts +0 -186
  182. package/src/storage/errors.ts +0 -46
  183. package/src/storage/index.ts +0 -5
  184. package/src/storage/types.ts +0 -39
  185. package/src/types.ts +0 -577
  186. package/src/utils/lexical.ts +0 -37
  187. package/src/utils/logger.ts +0 -73
  188. package/src/validation.ts +0 -429
  189. package/src/validator.ts +0 -179
  190. package/test/admin-custom-field.test.ts +0 -162
  191. package/test/admin-react-field.test.tsx +0 -134
  192. package/test/api-features.test.ts +0 -78
  193. package/test/api.test.ts +0 -178
  194. package/test/auth.test.ts +0 -62
  195. package/test/cli-integration.test.ts +0 -148
  196. package/test/cli.test.ts +0 -25
  197. package/test/db/postgres.test.ts +0 -95
  198. package/test/db/sqlite-filter.test.ts +0 -53
  199. package/test/db/sqlite.test.ts +0 -82
  200. package/test/engine-features.test.ts +0 -79
  201. package/test/globals.test.ts +0 -74
  202. package/test/integration-tmp/db-app/opacacms.config.ts +0 -15
  203. package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +0 -25
  204. package/test/integration-tmp/my-test-app/index.ts +0 -8
  205. package/test/integration-tmp/my-test-app/opacacms.config.ts +0 -16
  206. package/test/integration-tmp/my-test-app/package.json +0 -12
  207. package/test/populate.test.ts +0 -79
  208. package/test/runtimes.test.ts +0 -43
  209. package/test/schema-builder.test.ts +0 -107
  210. package/test/schema-features.test.ts +0 -63
  211. package/test/seeding.test.ts +0 -68
  212. package/test/storage/local.test.ts +0 -72
  213. package/test/storage/s3.test.ts +0 -60
  214. package/test/structural-data.test.ts +0 -100
  215. package/test/test-setup.ts +0 -11
  216. package/test/validation.test.ts +0 -162
  217. 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";