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