opacacms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bun.lock +34 -0
- package/dist/admin/api-client.d.ts +8 -0
- package/dist/admin/auth-client.d.ts +940 -0
- package/dist/admin/custom-field.d.ts +71 -0
- package/dist/admin/index.d.ts +11 -0
- package/dist/admin/react.d.ts +3 -0
- package/dist/admin/router.d.ts +7 -0
- package/dist/admin/stores/admin-queries.d.ts +32 -0
- package/dist/admin/stores/auth.d.ts +33 -0
- package/dist/admin/stores/column-visibility.d.ts +21 -0
- package/dist/admin/stores/config.d.ts +7 -0
- package/dist/admin/stores/media.d.ts +44 -0
- package/dist/admin/stores/query.d.ts +4 -0
- package/dist/admin/stores/ui.d.ts +11 -0
- package/dist/admin/ui/admin-client.d.ts +7 -0
- package/dist/admin/ui/admin-layout.d.ts +14 -0
- package/dist/admin/ui/components/ColumnVisibilityToggle.d.ts +10 -0
- package/dist/admin/ui/components/DataDetailSheet.d.ts +13 -0
- package/dist/admin/ui/components/DataDetailView.d.ts +9 -0
- package/dist/admin/ui/components/Table.d.ts +10 -0
- package/dist/admin/ui/components/fields/ArrayField.d.ts +13 -0
- package/dist/admin/ui/components/fields/BlocksField.d.ts +17 -0
- package/dist/admin/ui/components/fields/BooleanField.d.ts +13 -0
- package/dist/admin/ui/components/fields/CollapsibleField.d.ts +16 -0
- package/dist/admin/ui/components/fields/DateField.d.ts +13 -0
- package/dist/admin/ui/components/fields/FileField.d.ts +23 -0
- package/dist/admin/ui/components/fields/GroupField.d.ts +13 -0
- package/dist/admin/ui/components/fields/JoinField.d.ts +15 -0
- package/dist/admin/ui/components/fields/NumberField.d.ts +14 -0
- package/dist/admin/ui/components/fields/RadioField.d.ts +17 -0
- package/dist/admin/ui/components/fields/RelationshipField.d.ts +16 -0
- package/dist/admin/ui/components/fields/RowField.d.ts +12 -0
- package/dist/admin/ui/components/fields/SelectField.d.ts +18 -0
- package/dist/admin/ui/components/fields/TabsField.d.ts +15 -0
- package/dist/admin/ui/components/fields/TextAreaField.d.ts +14 -0
- package/dist/admin/ui/components/fields/TextField.d.ts +14 -0
- package/dist/admin/ui/components/fields/VirtualField.d.ts +8 -0
- package/dist/admin/ui/components/fields/index.d.ts +28 -0
- package/dist/admin/ui/components/fields/richtext-editor/index.d.ts +10 -0
- package/dist/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.d.ts +7 -0
- package/dist/admin/ui/components/fields/richtext-editor/nodes/ImageNode.d.ts +27 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.d.ts +5 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.d.ts +1 -0
- package/dist/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.d.ts +5 -0
- package/dist/admin/ui/components/fields/utils.d.ts +1 -0
- package/dist/admin/ui/components/link.d.ts +8 -0
- package/dist/admin/ui/components/media/AssetManagerModal.d.ts +17 -0
- package/dist/admin/ui/components/toast.d.ts +10 -0
- package/dist/admin/ui/components/ui/accordion.d.ts +11 -0
- package/dist/admin/ui/components/ui/alert-dialog.d.ts +12 -0
- package/dist/admin/ui/components/ui/blocks.d.ts +5 -0
- package/dist/admin/ui/components/ui/breadcrumbs.d.ts +7 -0
- package/dist/admin/ui/components/ui/button.d.ts +7 -0
- package/dist/admin/ui/components/ui/collapsible.d.ts +16 -0
- package/dist/admin/ui/components/ui/dialog.d.ts +27 -0
- package/dist/admin/ui/components/ui/group.d.ts +6 -0
- package/dist/admin/ui/components/ui/index.d.ts +17 -0
- package/dist/admin/ui/components/ui/input.d.ts +5 -0
- package/dist/admin/ui/components/ui/join.d.ts +7 -0
- package/dist/admin/ui/components/ui/label.d.ts +3 -0
- package/dist/admin/ui/components/ui/radio-group.d.ts +13 -0
- package/dist/admin/ui/components/ui/relationship-detail-sheet.d.ts +9 -0
- package/dist/admin/ui/components/ui/relationship.d.ts +8 -0
- package/dist/admin/ui/components/ui/scroll-area.d.ts +7 -0
- package/dist/admin/ui/components/ui/select.d.ts +37 -0
- package/dist/admin/ui/components/ui/separator.d.ts +8 -0
- package/dist/admin/ui/components/ui/sheet.d.ts +28 -0
- package/dist/admin/ui/components/ui/tabs.d.ts +17 -0
- package/dist/admin/ui/components/ui/utils.d.ts +1 -0
- package/dist/admin/ui/hooks/use-debounce.d.ts +1 -0
- package/dist/admin/ui/views/collection-list-view.d.ts +5 -0
- package/dist/admin/ui/views/dashboard-view.d.ts +10 -0
- package/dist/admin/ui/views/document-edit-view.d.ts +7 -0
- package/dist/admin/ui/views/global-edit-view.d.ts +19 -0
- package/dist/admin/ui/views/init-view.d.ts +4 -0
- package/dist/admin/ui/views/login-view.d.ts +4 -0
- package/dist/admin/ui/views/media-registry-view.d.ts +7 -0
- package/dist/admin/ui/views/settings-view.d.ts +7 -0
- package/dist/admin/webcomponent.d.ts +1 -0
- package/dist/api.d.ts +6 -0
- package/dist/auth/index.d.ts +2107 -0
- package/dist/auth/migrations.d.ts +5 -0
- package/dist/auth/premissions.d.ts +6 -0
- package/dist/chunk-16vgcf3k.js +88 -0
- package/dist/chunk-2zm8cy1w.js +9482 -0
- package/dist/chunk-5gvbp2qa.js +167 -0
- package/dist/chunk-62ev8gnc.js +41 -0
- package/dist/chunk-6dhs73zq.js +126 -0
- package/dist/chunk-6ew02s0c.js +472 -0
- package/dist/chunk-7a9kn0np.js +116 -0
- package/dist/chunk-8gkhn1d4.js +309 -0
- package/dist/chunk-8sqjbsgt.js +42 -0
- package/dist/chunk-9kxpbcb1.js +85 -0
- package/dist/chunk-cvdd4eqh.js +110 -0
- package/dist/chunk-d3ffeqp9.js +87 -0
- package/dist/chunk-dy5t83hr.js +261 -0
- package/dist/chunk-f3nvxn63.js +17 -0
- package/dist/chunk-hmhcense.js +1352 -0
- package/dist/chunk-j4d50hrx.js +20 -0
- package/dist/chunk-jwjk85ze.js +15 -0
- package/dist/chunk-kwp83w8b.js +250 -0
- package/dist/chunk-s8mqwnm1.js +14 -0
- package/dist/chunk-srsac177.js +85 -0
- package/dist/chunk-v521d72w.js +10 -0
- package/dist/chunk-xa7rjsn2.js +20 -0
- package/dist/chunk-xg35h5a3.js +15 -0
- package/dist/chunk-ybbbqj63.js +130 -0
- package/dist/chunk-zvwb67nd.js +332 -0
- package/dist/cli/commands/generate-types.d.ts +1 -0
- package/dist/cli/commands/init.d.ts +1 -0
- package/dist/cli/commands/migrate-commands.d.ts +5 -0
- package/dist/cli/commands/seed-command.d.ts +2 -0
- package/dist/cli/d1-mock.d.ts +30 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.test.d.ts +1 -0
- package/dist/cli/r2-mock.d.ts +46 -0
- package/dist/cli/seeding.d.ts +17 -0
- package/dist/client.d.ts +51 -0
- package/dist/config-utils.d.ts +6 -0
- package/dist/config.d.ts +10 -0
- package/dist/db/adapter.d.ts +34 -0
- package/dist/db/better-sqlite.d.ts +40 -0
- package/dist/db/bun-sqlite.d.ts +40 -0
- package/dist/db/d1.d.ts +42 -0
- package/dist/db/kysely/data-mapper.d.ts +6 -0
- package/dist/db/kysely/field-mapper.d.ts +22 -0
- package/dist/db/kysely/migration-generator.d.ts +9 -0
- package/dist/db/kysely/query-builder.d.ts +9 -0
- package/dist/db/kysely/schema-builder.d.ts +15 -0
- package/dist/db/kysely/sql-utils.d.ts +1 -0
- package/dist/db/postgres.d.ts +51 -0
- package/dist/db/sqlite.d.ts +41 -0
- package/dist/db/system-schema.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/runtimes/bun.d.ts +17 -0
- package/dist/runtimes/cloudflare-workers.d.ts +10 -0
- package/dist/runtimes/next.d.ts +16 -0
- package/dist/runtimes/node.d.ts +18 -0
- package/dist/schema/collection.d.ts +100 -0
- package/dist/schema/fields/base.d.ts +83 -0
- package/dist/schema/fields/index.d.ts +135 -0
- package/dist/schema/global.d.ts +82 -0
- package/dist/schema/index.d.ts +4 -0
- package/dist/schema/infer.d.ts +55 -0
- package/dist/server/admin-router.d.ts +9 -0
- package/dist/server/admin.d.ts +18 -0
- package/dist/server/assets.d.ts +47 -0
- package/dist/server/collection-router.d.ts +14 -0
- package/dist/server/handlers.d.ts +76 -0
- package/dist/server/middlewares/admin.d.ts +6 -0
- package/dist/server/middlewares/auth.d.ts +16 -0
- package/dist/server/middlewares/context.d.ts +9 -0
- package/dist/server/middlewares/cors.d.ts +3 -0
- package/dist/server/middlewares/database-init.d.ts +11 -0
- package/dist/server/middlewares/rate-limit.d.ts +3 -0
- package/dist/server/router.d.ts +7 -0
- package/dist/server/setup-middlewares.d.ts +17 -0
- package/dist/server/system-router.d.ts +9 -0
- package/dist/server.d.ts +6 -0
- package/dist/src/admin/index.css +47 -0
- package/dist/src/admin/index.js +176 -0
- package/dist/src/admin/webcomponent.js +19 -0
- package/dist/src/api.js +27 -0
- package/dist/src/cli/index.js +157 -0
- package/dist/src/client.js +9 -0
- package/dist/src/db/bun-sqlite.js +523 -0
- package/dist/src/db/d1.js +568 -0
- package/dist/src/db/postgres.js +520 -0
- package/dist/src/db/sqlite.js +534 -0
- package/dist/src/index.js +20 -0
- package/dist/src/runtimes/bun.js +36 -0
- package/dist/src/runtimes/cloudflare-workers.js +29 -0
- package/dist/src/runtimes/next.js +26 -0
- package/dist/src/runtimes/node.js +38 -0
- package/dist/src/server.js +27 -0
- package/dist/src/storage/index.js +355 -0
- package/dist/storage/adapters/cloudflare-r2.d.ts +6 -0
- package/dist/storage/adapters/local.d.ts +6 -0
- package/dist/storage/adapters/s3.d.ts +13 -0
- package/dist/storage/errors.d.ts +12 -0
- package/dist/storage/index.d.ts +5 -0
- package/dist/storage/types.d.ts +31 -0
- package/dist/types.d.ts +484 -0
- package/dist/utils/lexical.d.ts +5 -0
- package/dist/utils/logger.d.ts +35 -0
- package/dist/validation.d.ts +300 -0
- package/dist/validator.d.ts +9 -0
- package/global.d.ts +11 -0
- package/package.json +151 -0
- package/src/admin/api-client.ts +63 -0
- package/src/admin/auth-client.ts +40 -0
- package/src/admin/custom-field.ts +179 -0
- package/src/admin/index.ts +15 -0
- package/src/admin/react.tsx +72 -0
- package/src/admin/router.ts +9 -0
- package/src/admin/stores/admin-queries.ts +121 -0
- package/src/admin/stores/auth.ts +61 -0
- package/src/admin/stores/column-visibility.ts +67 -0
- package/src/admin/stores/config.ts +15 -0
- package/src/admin/stores/media.ts +95 -0
- package/src/admin/stores/query.ts +13 -0
- package/src/admin/stores/ui.ts +29 -0
- package/src/admin/ui/admin-client.tsx +283 -0
- package/src/admin/ui/admin-layout.tsx +276 -0
- package/src/admin/ui/components/ColumnVisibilityToggle.tsx +141 -0
- package/src/admin/ui/components/DataDetailSheet.tsx +141 -0
- package/src/admin/ui/components/DataDetailView.tsx +175 -0
- package/src/admin/ui/components/Table.tsx +67 -0
- package/src/admin/ui/components/fields/ArrayField.tsx +166 -0
- package/src/admin/ui/components/fields/BlocksField.tsx +202 -0
- package/src/admin/ui/components/fields/BooleanField.tsx +50 -0
- package/src/admin/ui/components/fields/CollapsibleField.tsx +75 -0
- package/src/admin/ui/components/fields/DateField.tsx +45 -0
- package/src/admin/ui/components/fields/FileField.tsx +322 -0
- package/src/admin/ui/components/fields/GroupField.tsx +50 -0
- package/src/admin/ui/components/fields/JoinField.tsx +23 -0
- package/src/admin/ui/components/fields/NumberField.tsx +46 -0
- package/src/admin/ui/components/fields/RadioField.tsx +62 -0
- package/src/admin/ui/components/fields/RelationshipField.tsx +278 -0
- package/src/admin/ui/components/fields/RowField.tsx +40 -0
- package/src/admin/ui/components/fields/SelectField.tsx +59 -0
- package/src/admin/ui/components/fields/TabsField.tsx +101 -0
- package/src/admin/ui/components/fields/TextAreaField.tsx +54 -0
- package/src/admin/ui/components/fields/TextField.tsx +49 -0
- package/src/admin/ui/components/fields/VirtualField.tsx +53 -0
- package/src/admin/ui/components/fields/index.tsx +371 -0
- package/src/admin/ui/components/fields/richtext-editor/index.tsx +211 -0
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageComponent.tsx +142 -0
- package/src/admin/ui/components/fields/richtext-editor/nodes/ImageNode.tsx +95 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/ComponentPickerPlugin.tsx +226 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/EditableSyncPlugin.tsx +16 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/NotionToolbarPlugin.tsx +184 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/SimpleToolbarPlugin.tsx +240 -0
- package/src/admin/ui/components/fields/richtext-editor/plugins/ValueSyncPlugin.tsx +40 -0
- package/src/admin/ui/components/fields/utils.ts +1 -0
- package/src/admin/ui/components/link.tsx +41 -0
- package/src/admin/ui/components/media/AssetManagerModal.tsx +334 -0
- package/src/admin/ui/components/toast.tsx +72 -0
- package/src/admin/ui/components/ui/accordion.tsx +51 -0
- package/src/admin/ui/components/ui/alert-dialog.tsx +98 -0
- package/src/admin/ui/components/ui/blocks.tsx +32 -0
- package/src/admin/ui/components/ui/breadcrumbs.tsx +59 -0
- package/src/admin/ui/components/ui/button.tsx +26 -0
- package/src/admin/ui/components/ui/collapsible.tsx +124 -0
- package/src/admin/ui/components/ui/dialog.tsx +79 -0
- package/src/admin/ui/components/ui/group.tsx +20 -0
- package/src/admin/ui/components/ui/index.ts +17 -0
- package/src/admin/ui/components/ui/input.tsx +12 -0
- package/src/admin/ui/components/ui/join.tsx +53 -0
- package/src/admin/ui/components/ui/label.tsx +11 -0
- package/src/admin/ui/components/ui/radio-group.tsx +75 -0
- package/src/admin/ui/components/ui/relationship-detail-sheet.tsx +122 -0
- package/src/admin/ui/components/ui/relationship.tsx +58 -0
- package/src/admin/ui/components/ui/scroll-area.tsx +19 -0
- package/src/admin/ui/components/ui/select.tsx +187 -0
- package/src/admin/ui/components/ui/separator.tsx +21 -0
- package/src/admin/ui/components/ui/sheet.tsx +106 -0
- package/src/admin/ui/components/ui/tabs.tsx +116 -0
- package/src/admin/ui/components/ui/utils.ts +3 -0
- package/src/admin/ui/hooks/use-debounce.ts +15 -0
- package/src/admin/ui/styles/_locale-switcher.scss +33 -0
- package/src/admin/ui/styles/accordion.scss +60 -0
- package/src/admin/ui/styles/animations.scss +41 -0
- package/src/admin/ui/styles/asset-manager.scss +547 -0
- package/src/admin/ui/styles/badge.scss +13 -0
- package/src/admin/ui/styles/base.scss +22 -0
- package/src/admin/ui/styles/button.scss +161 -0
- package/src/admin/ui/styles/card.scss +13 -0
- package/src/admin/ui/styles/collapsible.scss +75 -0
- package/src/admin/ui/styles/data-detail.scss +92 -0
- package/src/admin/ui/styles/dialog.scss +102 -0
- package/src/admin/ui/styles/empty-state.scss +22 -0
- package/src/admin/ui/styles/group.scss +19 -0
- package/src/admin/ui/styles/index.scss +33 -0
- package/src/admin/ui/styles/input.scss +80 -0
- package/src/admin/ui/styles/label.scss +12 -0
- package/src/admin/ui/styles/layout.scss +56 -0
- package/src/admin/ui/styles/lexical.scss +469 -0
- package/src/admin/ui/styles/loading.scss +102 -0
- package/src/admin/ui/styles/media-registry.scss +597 -0
- package/src/admin/ui/styles/pagination.scss +20 -0
- package/src/admin/ui/styles/radio-group.scss +66 -0
- package/src/admin/ui/styles/row.scss +17 -0
- package/src/admin/ui/styles/scrollbar.scss +36 -0
- package/src/admin/ui/styles/select.scss +121 -0
- package/src/admin/ui/styles/separator.scss +14 -0
- package/src/admin/ui/styles/sheet.scss +152 -0
- package/src/admin/ui/styles/sidebar.scss +148 -0
- package/src/admin/ui/styles/switch.scss +59 -0
- package/src/admin/ui/styles/table.scss +207 -0
- package/src/admin/ui/styles/tabs.scss +62 -0
- package/src/admin/ui/styles/toast.scss +45 -0
- package/src/admin/ui/styles/variables.scss +24 -0
- package/src/admin/ui/views/collection-list-view.tsx +720 -0
- package/src/admin/ui/views/dashboard-view.tsx +263 -0
- package/src/admin/ui/views/document-edit-view.tsx +384 -0
- package/src/admin/ui/views/global-edit-view.tsx +226 -0
- package/src/admin/ui/views/init-view.tsx +182 -0
- package/src/admin/ui/views/login-view.tsx +123 -0
- package/src/admin/ui/views/media-registry-view.tsx +1104 -0
- package/src/admin/ui/views/settings-view.tsx +729 -0
- package/src/admin/webcomponent.tsx +15 -0
- package/src/api.ts +9 -0
- package/src/auth/index.ts +194 -0
- package/src/auth/migrations.ts +87 -0
- package/src/auth/premissions.ts +46 -0
- package/src/cli/commands/generate-types.ts +116 -0
- package/src/cli/commands/init.ts +95 -0
- package/src/cli/commands/migrate-commands.ts +160 -0
- package/src/cli/commands/seed-command.ts +11 -0
- package/src/cli/d1-mock.ts +101 -0
- package/src/cli/index.test.ts +84 -0
- package/src/cli/index.ts +183 -0
- package/src/cli/r2-mock.ts +217 -0
- package/src/cli/seeding.ts +405 -0
- package/src/client.ts +181 -0
- package/src/config-utils.ts +102 -0
- package/src/config.ts +49 -0
- package/src/db/adapter.ts +53 -0
- package/src/db/better-sqlite.ts +630 -0
- package/src/db/bun-sqlite.ts +646 -0
- package/src/db/d1.ts +711 -0
- package/src/db/kysely/data-mapper.ts +142 -0
- package/src/db/kysely/field-mapper.ts +148 -0
- package/src/db/kysely/migration-generator.ts +223 -0
- package/src/db/kysely/query-builder.ts +92 -0
- package/src/db/kysely/schema-builder.ts +439 -0
- package/src/db/kysely/sql-utils.ts +13 -0
- package/src/db/postgres.ts +621 -0
- package/src/db/sqlite.ts +658 -0
- package/src/db/system-schema.ts +121 -0
- package/src/index.ts +13 -0
- package/src/runtimes/README.md +59 -0
- package/src/runtimes/bun.ts +49 -0
- package/src/runtimes/cloudflare-workers.ts +38 -0
- package/src/runtimes/next.ts +26 -0
- package/src/runtimes/node.ts +52 -0
- package/src/schema/collection.ts +184 -0
- package/src/schema/fields/base.ts +164 -0
- package/src/schema/fields/index.ts +427 -0
- package/src/schema/global.ts +145 -0
- package/src/schema/index.ts +4 -0
- package/src/schema/infer.ts +72 -0
- package/src/server/admin-router.ts +20 -0
- package/src/server/admin.ts +142 -0
- package/src/server/assets.ts +306 -0
- package/src/server/collection-router.ts +55 -0
- package/src/server/handlers.ts +722 -0
- package/src/server/middlewares/admin.ts +27 -0
- package/src/server/middlewares/auth.ts +89 -0
- package/src/server/middlewares/context.ts +17 -0
- package/src/server/middlewares/cors.ts +24 -0
- package/src/server/middlewares/database-init.ts +74 -0
- package/src/server/middlewares/rate-limit.ts +71 -0
- package/src/server/router.ts +47 -0
- package/src/server/setup-middlewares.ts +58 -0
- package/src/server/system-router.ts +35 -0
- package/src/server.ts +9 -0
- package/src/storage/adapters/cloudflare-r2.ts +136 -0
- package/src/storage/adapters/local.ts +146 -0
- package/src/storage/adapters/s3.ts +186 -0
- package/src/storage/errors.ts +46 -0
- package/src/storage/index.ts +5 -0
- package/src/storage/types.ts +39 -0
- package/src/types.ts +577 -0
- package/src/utils/lexical.ts +37 -0
- package/src/utils/logger.ts +73 -0
- package/src/validation.ts +429 -0
- package/src/validator.ts +179 -0
- package/test/admin-custom-field.test.ts +162 -0
- package/test/admin-react-field.test.tsx +134 -0
- package/test/api-features.test.ts +78 -0
- package/test/api.test.ts +178 -0
- package/test/auth.test.ts +62 -0
- package/test/cli-integration.test.ts +146 -0
- package/test/cli.test.ts +25 -0
- package/test/db/postgres.test.ts +95 -0
- package/test/db/sqlite-filter.test.ts +53 -0
- package/test/db/sqlite.test.ts +82 -0
- package/test/engine-features.test.ts +79 -0
- package/test/globals.test.ts +74 -0
- package/test/integration-tmp/db-app/opacacms.config.ts +15 -0
- package/test/integration-tmp/my-sqlite-app/opacacms.config.ts +25 -0
- package/test/integration-tmp/my-test-app/index.ts +8 -0
- package/test/integration-tmp/my-test-app/opacacms.config.ts +16 -0
- package/test/integration-tmp/my-test-app/package.json +12 -0
- package/test/populate.test.ts +79 -0
- package/test/runtimes.test.ts +43 -0
- package/test/schema-builder.test.ts +107 -0
- package/test/schema-features.test.ts +63 -0
- package/test/seeding.test.ts +68 -0
- package/test/storage/local.test.ts +72 -0
- package/test/storage/s3.test.ts +60 -0
- package/test/structural-data.test.ts +100 -0
- package/test/test-setup.ts +11 -0
- package/test/validation.test.ts +162 -0
- package/tsconfig.json +42 -0
|
@@ -0,0 +1,164 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,427 @@
|
|
|
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";
|