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
package/src/types.ts
ADDED
|
@@ -0,0 +1,577 @@
|
|
|
1
|
+
import type { Session, User } from "better-auth";
|
|
2
|
+
import type { Context } from "hono";
|
|
3
|
+
import type { icons } from "lucide-react";
|
|
4
|
+
import type {
|
|
5
|
+
AdminConfig,
|
|
6
|
+
CollectionHooks,
|
|
7
|
+
FieldType,
|
|
8
|
+
AccessConfig as ValidationAccessConfig,
|
|
9
|
+
ApiConfig as ValidationApiConfig,
|
|
10
|
+
Collection as ValidationCollection,
|
|
11
|
+
Field as ValidationField,
|
|
12
|
+
Global as ValidationGlobal,
|
|
13
|
+
OpacaConfig as ValidationOpacaConfig,
|
|
14
|
+
} from "./validation";
|
|
15
|
+
|
|
16
|
+
export type { FieldType };
|
|
17
|
+
|
|
18
|
+
export type IconName = keyof typeof icons;
|
|
19
|
+
|
|
20
|
+
// --- Field Types ---
|
|
21
|
+
|
|
22
|
+
export interface BaseField {
|
|
23
|
+
name: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
placeholder?: string;
|
|
26
|
+
required?: boolean;
|
|
27
|
+
unique?: boolean;
|
|
28
|
+
localized?: boolean;
|
|
29
|
+
defaultValue?: unknown;
|
|
30
|
+
validate?: (value: unknown) => boolean | string;
|
|
31
|
+
access?: FieldAccessConfig;
|
|
32
|
+
admin?: {
|
|
33
|
+
description?: string;
|
|
34
|
+
condition?: (data: Record<string, unknown>, siblingData: Record<string, unknown>) => boolean;
|
|
35
|
+
hidden?: boolean;
|
|
36
|
+
readOnly?: boolean;
|
|
37
|
+
width?: string;
|
|
38
|
+
style?: any;
|
|
39
|
+
className?: string;
|
|
40
|
+
components?: {
|
|
41
|
+
Field?: string;
|
|
42
|
+
Cell?: string;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
references?: {
|
|
46
|
+
table: string;
|
|
47
|
+
column: string;
|
|
48
|
+
onDelete?: "cascade" | "set null" | "restrict" | "no action";
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface TextField extends BaseField {
|
|
53
|
+
type: "text";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface SlugField extends BaseField {
|
|
57
|
+
type: "slug";
|
|
58
|
+
from: string;
|
|
59
|
+
format?: (value: string) => string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface TextAreaField extends BaseField {
|
|
63
|
+
type: "textarea";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface NumberField extends BaseField {
|
|
67
|
+
type: "number";
|
|
68
|
+
options?: {
|
|
69
|
+
min?: number;
|
|
70
|
+
max?: number;
|
|
71
|
+
step?: number;
|
|
72
|
+
[key: string]: any;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface RichTextField extends BaseField {
|
|
77
|
+
type: "richtext";
|
|
78
|
+
options?: {
|
|
79
|
+
defaultMode?: "simple" | "notion";
|
|
80
|
+
[key: string]: any;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface RelationshipField extends BaseField {
|
|
85
|
+
type: "relationship";
|
|
86
|
+
relationTo: string;
|
|
87
|
+
hasMany?: boolean;
|
|
88
|
+
displayField?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface SelectField extends BaseField {
|
|
92
|
+
type: "select";
|
|
93
|
+
options?: {
|
|
94
|
+
choices: (string | { label: string; value: string })[];
|
|
95
|
+
[key: string]: any;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface RadioField extends BaseField {
|
|
100
|
+
type: "radio";
|
|
101
|
+
options: {
|
|
102
|
+
choices: (string | { label: string; value: string })[];
|
|
103
|
+
[key: string]: unknown;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export interface DateField extends BaseField {
|
|
108
|
+
type: "date";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export interface BooleanField extends BaseField {
|
|
112
|
+
type: "boolean";
|
|
113
|
+
options?: {
|
|
114
|
+
display?: "switch" | "toggle" | "checkbox" | "select";
|
|
115
|
+
[key: string]: unknown;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export interface JSONField extends BaseField {
|
|
120
|
+
type: "json";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export interface FileField extends BaseField {
|
|
124
|
+
type: "file";
|
|
125
|
+
bucket?: string;
|
|
126
|
+
options?: {
|
|
127
|
+
allowedmime_types?: string[];
|
|
128
|
+
maxFileSize?: number;
|
|
129
|
+
metaFields?: Field[];
|
|
130
|
+
[key: string]: unknown;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export interface BlocksField extends BaseField {
|
|
135
|
+
type: "blocks";
|
|
136
|
+
blocks: {
|
|
137
|
+
slug: string;
|
|
138
|
+
fields: Field[];
|
|
139
|
+
label?: string;
|
|
140
|
+
}[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export interface GroupField extends BaseField {
|
|
144
|
+
type: "group";
|
|
145
|
+
fields: Field[];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export interface RowField extends Omit<BaseField, "name"> {
|
|
149
|
+
type: "row";
|
|
150
|
+
name?: string; // Allow optional name for row
|
|
151
|
+
fields: Field[];
|
|
152
|
+
label?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface CollapsibleField extends Omit<BaseField, "name"> {
|
|
156
|
+
type: "collapsible";
|
|
157
|
+
name?: string; // Allow optional name for collapsible
|
|
158
|
+
label: string;
|
|
159
|
+
fields: Field[];
|
|
160
|
+
options?: {
|
|
161
|
+
initiallyCollapsed?: boolean;
|
|
162
|
+
useAsTitle?: string;
|
|
163
|
+
[key: string]: any;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export interface ArrayField extends BaseField {
|
|
168
|
+
type: "array";
|
|
169
|
+
fields: Field[];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface TabsField extends Omit<BaseField, "name"> {
|
|
173
|
+
type: "tabs";
|
|
174
|
+
name?: string; // Allow optional name for tabs
|
|
175
|
+
tabs: {
|
|
176
|
+
label: string;
|
|
177
|
+
fields: Field[];
|
|
178
|
+
}[];
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export interface JoinField extends Omit<BaseField, "name"> {
|
|
182
|
+
type: "join";
|
|
183
|
+
name?: string; // join requires name, but schema-generator tests assume optional
|
|
184
|
+
collection: string;
|
|
185
|
+
on: string;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface VirtualField extends BaseField {
|
|
189
|
+
type: "virtual";
|
|
190
|
+
resolve: (args: {
|
|
191
|
+
data: any;
|
|
192
|
+
req: any;
|
|
193
|
+
user: User;
|
|
194
|
+
session: Session;
|
|
195
|
+
apiKey?: ApiKey;
|
|
196
|
+
}) => any | Promise<any>;
|
|
197
|
+
returnType?: "string" | "number" | "boolean" | "json";
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
export type Field =
|
|
201
|
+
| TextField
|
|
202
|
+
| SlugField
|
|
203
|
+
| TextAreaField
|
|
204
|
+
| NumberField
|
|
205
|
+
| RichTextField
|
|
206
|
+
| RelationshipField
|
|
207
|
+
| SelectField
|
|
208
|
+
| VirtualField
|
|
209
|
+
| RadioField
|
|
210
|
+
| DateField
|
|
211
|
+
| BooleanField
|
|
212
|
+
| JSONField
|
|
213
|
+
| FileField
|
|
214
|
+
| BlocksField
|
|
215
|
+
| GroupField
|
|
216
|
+
| RowField
|
|
217
|
+
| CollapsibleField
|
|
218
|
+
| TabsField
|
|
219
|
+
| JoinField
|
|
220
|
+
| ArrayField;
|
|
221
|
+
|
|
222
|
+
export interface ApiKey {
|
|
223
|
+
id: string;
|
|
224
|
+
name: string | null;
|
|
225
|
+
permissions?: Record<string, string[]> | null;
|
|
226
|
+
referenceId: string;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export interface AccessArgs {
|
|
230
|
+
req: Context;
|
|
231
|
+
user: User | null;
|
|
232
|
+
session: Session | null;
|
|
233
|
+
apiKey?: ApiKey | null;
|
|
234
|
+
data?: unknown;
|
|
235
|
+
operation?: "read" | "create" | "update" | "delete";
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export interface FieldAccessConfig {
|
|
239
|
+
/** If true, the field is removed from API and UI. */
|
|
240
|
+
hidden?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
241
|
+
/** If true, the data is shown but cannot be edited. */
|
|
242
|
+
readOnly?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
243
|
+
/** If true, the input is visually disabled. */
|
|
244
|
+
disabled?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
export interface AccessConfig
|
|
248
|
+
extends Omit<ValidationAccessConfig, "read" | "create" | "update" | "delete"> {
|
|
249
|
+
read?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
250
|
+
create?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
251
|
+
update?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
252
|
+
delete?: boolean | ((args: AccessArgs) => boolean | Promise<boolean>);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export type { CollectionHooks };
|
|
256
|
+
|
|
257
|
+
export interface Collection
|
|
258
|
+
extends Omit<
|
|
259
|
+
ValidationCollection,
|
|
260
|
+
"fields" | "hooks" | "access" | "admin" | "apiPath" | "versions" | "webhooks"
|
|
261
|
+
> {
|
|
262
|
+
fields: Field[];
|
|
263
|
+
apiPath?: string;
|
|
264
|
+
hooks?: CollectionHooks;
|
|
265
|
+
access?: AccessConfig;
|
|
266
|
+
icon?: IconName;
|
|
267
|
+
versions?: {
|
|
268
|
+
drafts?: boolean;
|
|
269
|
+
maxRevisions?: number;
|
|
270
|
+
autosave?: boolean;
|
|
271
|
+
};
|
|
272
|
+
webhooks?: {
|
|
273
|
+
events: string[];
|
|
274
|
+
url: string;
|
|
275
|
+
headers?: Record<string, string>;
|
|
276
|
+
}[];
|
|
277
|
+
admin?:
|
|
278
|
+
| {
|
|
279
|
+
defaultColumns?: string[];
|
|
280
|
+
useAsTitle?: string;
|
|
281
|
+
hidden?: boolean;
|
|
282
|
+
disableAdmin?: boolean;
|
|
283
|
+
views?: {
|
|
284
|
+
name: string;
|
|
285
|
+
filter: Record<string, any>;
|
|
286
|
+
defaultColumns?: string[];
|
|
287
|
+
}[];
|
|
288
|
+
bulkActions?: {
|
|
289
|
+
label: string;
|
|
290
|
+
action: (args: { selectedIds: string[]; db: DatabaseAdapter }) => Promise<unknown>;
|
|
291
|
+
}[];
|
|
292
|
+
}
|
|
293
|
+
| boolean;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export interface Global extends Omit<ValidationGlobal, "fields" | "access"> {
|
|
297
|
+
fields: Field[];
|
|
298
|
+
access?: AccessConfig;
|
|
299
|
+
label?: string;
|
|
300
|
+
icon?: IconName;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export interface OpacaConfig<Resource extends string = string>
|
|
304
|
+
extends Omit<
|
|
305
|
+
ValidationOpacaConfig,
|
|
306
|
+
"collections" | "globals" | "admin" | "api" | "access" | "trustedOrigins" | "auth" | "i18n"
|
|
307
|
+
> {
|
|
308
|
+
collections: Collection[];
|
|
309
|
+
globals?: Global[];
|
|
310
|
+
db: DatabaseAdapter;
|
|
311
|
+
admin?: AdminConfig;
|
|
312
|
+
api?: ApiConfig;
|
|
313
|
+
access?: OpacaAccessConfig<Resource>;
|
|
314
|
+
trustedOrigins?: string[] | ((request?: Request) => string[] | Promise<string[]>);
|
|
315
|
+
auth?: OpacaAuthConfig;
|
|
316
|
+
i18n?: {
|
|
317
|
+
locales: string[];
|
|
318
|
+
defaultLocale: string;
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface OpacaAuthConfig {
|
|
323
|
+
/**
|
|
324
|
+
* Defines the primary identity strategies for accessing the CMS.
|
|
325
|
+
*/
|
|
326
|
+
strategies?: {
|
|
327
|
+
emailPassword?: boolean; // Defaults to true
|
|
328
|
+
magicLink?: {
|
|
329
|
+
enabled: boolean;
|
|
330
|
+
sendEmail: (data: { email: string; url: string; token: string }) => Promise<void>;
|
|
331
|
+
};
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Strictly typed social providers.
|
|
336
|
+
* Only the providers explicitly supported by the OpacaCMS UI are allowed.
|
|
337
|
+
*/
|
|
338
|
+
socialProviders?: {
|
|
339
|
+
github?: {
|
|
340
|
+
clientId: string;
|
|
341
|
+
clientSecret: string;
|
|
342
|
+
};
|
|
343
|
+
google?: {
|
|
344
|
+
clientId: string;
|
|
345
|
+
clientSecret: string;
|
|
346
|
+
};
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Session configuration overrides.
|
|
351
|
+
*/
|
|
352
|
+
session?: {
|
|
353
|
+
expiresInDays?: number; // Defaults to 30
|
|
354
|
+
updateAgeSeconds?: number; // Defaults to 86400 (1 day)
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Declaring plugins statically by configuration.
|
|
359
|
+
*/
|
|
360
|
+
features?: {
|
|
361
|
+
apiKeys?: {
|
|
362
|
+
enabled: boolean;
|
|
363
|
+
};
|
|
364
|
+
mfa?: {
|
|
365
|
+
enabled: boolean;
|
|
366
|
+
issuer: string;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface OpacaAccessConfig<Resource extends string = string> {
|
|
372
|
+
/**
|
|
373
|
+
* Define roles and their permissions.
|
|
374
|
+
* Key is the role name (e.g., 'editor').
|
|
375
|
+
* Value is a map of resource names to allowed actions.
|
|
376
|
+
*/
|
|
377
|
+
roles: Record<string, Partial<Record<Resource | "user" | "session", string[]>>>;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export interface ApiConfig {
|
|
381
|
+
maxLimit?: number;
|
|
382
|
+
rateLimit?: {
|
|
383
|
+
windowMs?: number;
|
|
384
|
+
limit?: number;
|
|
385
|
+
enabled?: boolean;
|
|
386
|
+
store?: any;
|
|
387
|
+
provider?: (c: Context) => any;
|
|
388
|
+
keyGenerator?: (c: Context) => string | Promise<string>;
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export type { AdminConfig };
|
|
393
|
+
|
|
394
|
+
export interface FindOptions {
|
|
395
|
+
limit?: number;
|
|
396
|
+
page?: number;
|
|
397
|
+
sort?: string;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
export interface PaginatedResult<T> {
|
|
401
|
+
docs: T[];
|
|
402
|
+
folders?: string[];
|
|
403
|
+
totalDocs: number;
|
|
404
|
+
limit: number;
|
|
405
|
+
totalPages: number;
|
|
406
|
+
page: number;
|
|
407
|
+
pagingCounter: number;
|
|
408
|
+
hasPrevPage: boolean;
|
|
409
|
+
hasNextPage: boolean;
|
|
410
|
+
prevPage: number | null;
|
|
411
|
+
nextPage: number | null;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
export interface DatabaseAdapter {
|
|
415
|
+
name: string;
|
|
416
|
+
connect(): Promise<void>;
|
|
417
|
+
disconnect(): Promise<void>;
|
|
418
|
+
/**
|
|
419
|
+
* Internal ORM instance (e.g. Drizzle instance)
|
|
420
|
+
*/
|
|
421
|
+
readonly db?: unknown;
|
|
422
|
+
readonly raw?: unknown;
|
|
423
|
+
unsafe(sql: string, params?: unknown[]): Promise<unknown>;
|
|
424
|
+
count(collection: string, query?: Record<string, unknown>): Promise<number>;
|
|
425
|
+
|
|
426
|
+
// CRUD
|
|
427
|
+
create<T extends object>(collection: string, data: Partial<T>): Promise<T>;
|
|
428
|
+
find<T extends object>(
|
|
429
|
+
collection: string,
|
|
430
|
+
query?: Record<string, unknown>,
|
|
431
|
+
options?: FindOptions,
|
|
432
|
+
): Promise<PaginatedResult<T>>;
|
|
433
|
+
findOne<T extends object>(collection: string, query: Record<string, unknown>): Promise<T | null>;
|
|
434
|
+
update<T extends object>(
|
|
435
|
+
collection: string,
|
|
436
|
+
query: Record<string, unknown>,
|
|
437
|
+
data: Partial<T>,
|
|
438
|
+
): Promise<T>;
|
|
439
|
+
updateMany?<T extends object>(
|
|
440
|
+
collection: string,
|
|
441
|
+
query: Record<string, unknown>,
|
|
442
|
+
data: Partial<T>,
|
|
443
|
+
): Promise<number>;
|
|
444
|
+
delete(collection: string, query: Record<string, unknown>): Promise<boolean>;
|
|
445
|
+
deleteMany?(collection: string, query: Record<string, unknown>): Promise<number>;
|
|
446
|
+
|
|
447
|
+
// Globals
|
|
448
|
+
findGlobal?<T extends object>(slug: string): Promise<T | null>;
|
|
449
|
+
updateGlobal?<T extends object>(slug: string, data: Partial<T>): Promise<T>;
|
|
450
|
+
|
|
451
|
+
// Schema management
|
|
452
|
+
migrate(collections: Collection[], globals?: Global[]): Promise<void>;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Run file-based migrations from the migrations directory.
|
|
456
|
+
*/
|
|
457
|
+
runMigrations?(): Promise<void>;
|
|
458
|
+
|
|
459
|
+
/**
|
|
460
|
+
* Wether to automatically push schema changes to the database (on the fly).
|
|
461
|
+
* Defaults to true in development, false in production.
|
|
462
|
+
*/
|
|
463
|
+
push?: boolean;
|
|
464
|
+
pushDestructive?: boolean;
|
|
465
|
+
migrationDir?: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
/**
|
|
469
|
+
* Serializable version of a collection, safe for Next.js Client Components.
|
|
470
|
+
* Strips out hooks and access functions.
|
|
471
|
+
*/
|
|
472
|
+
export interface SerializableCollection {
|
|
473
|
+
slug: string;
|
|
474
|
+
apiPath?: string;
|
|
475
|
+
label?: string;
|
|
476
|
+
icon?: IconName;
|
|
477
|
+
versions?: {
|
|
478
|
+
drafts?: boolean;
|
|
479
|
+
maxRevisions?: number;
|
|
480
|
+
autosave?: boolean;
|
|
481
|
+
};
|
|
482
|
+
fields: {
|
|
483
|
+
name?: string;
|
|
484
|
+
type: FieldType;
|
|
485
|
+
label?: string;
|
|
486
|
+
localized?: boolean;
|
|
487
|
+
admin?: {
|
|
488
|
+
description?: string;
|
|
489
|
+
hidden?: boolean;
|
|
490
|
+
readOnly?: boolean;
|
|
491
|
+
components?: {
|
|
492
|
+
Field?: string;
|
|
493
|
+
Cell?: string;
|
|
494
|
+
};
|
|
495
|
+
};
|
|
496
|
+
required?: boolean;
|
|
497
|
+
unique?: boolean;
|
|
498
|
+
defaultValue?: unknown;
|
|
499
|
+
options?: {
|
|
500
|
+
defaultMode?: "simple" | "notion";
|
|
501
|
+
[key: string]: unknown;
|
|
502
|
+
};
|
|
503
|
+
fields?: SerializableCollection["fields"];
|
|
504
|
+
relationTo?: string;
|
|
505
|
+
hasMany?: boolean;
|
|
506
|
+
displayField?: string;
|
|
507
|
+
collection?: string;
|
|
508
|
+
on?: string;
|
|
509
|
+
blocks?: {
|
|
510
|
+
slug: string;
|
|
511
|
+
fields: SerializableCollection["fields"];
|
|
512
|
+
label?: string;
|
|
513
|
+
}[];
|
|
514
|
+
tabs?: {
|
|
515
|
+
label: string;
|
|
516
|
+
fields: SerializableCollection["fields"];
|
|
517
|
+
}[];
|
|
518
|
+
}[];
|
|
519
|
+
timestamps?: boolean | { createdAt?: string; updatedAt?: string };
|
|
520
|
+
auth?: boolean;
|
|
521
|
+
admin?:
|
|
522
|
+
| {
|
|
523
|
+
defaultColumns?: string[];
|
|
524
|
+
useAsTitle?: string;
|
|
525
|
+
hidden?: boolean;
|
|
526
|
+
disableAdmin?: boolean;
|
|
527
|
+
views?: {
|
|
528
|
+
name: string;
|
|
529
|
+
filter: Record<string, any>;
|
|
530
|
+
defaultColumns?: string[];
|
|
531
|
+
}[];
|
|
532
|
+
}
|
|
533
|
+
| boolean;
|
|
534
|
+
hidden?: boolean;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Serializable version of the config, safe for Next.js Client Components.
|
|
539
|
+
* Strips out database adapter and functions.
|
|
540
|
+
*/
|
|
541
|
+
export interface SerializableConfig {
|
|
542
|
+
appName?: string;
|
|
543
|
+
serverURL?: string;
|
|
544
|
+
i18n?: {
|
|
545
|
+
locales: string[];
|
|
546
|
+
defaultLocale: string;
|
|
547
|
+
};
|
|
548
|
+
collections: SerializableCollection[];
|
|
549
|
+
globals?: {
|
|
550
|
+
slug: string;
|
|
551
|
+
label?: string;
|
|
552
|
+
icon?: IconName;
|
|
553
|
+
fields: {
|
|
554
|
+
name?: string;
|
|
555
|
+
type: FieldType;
|
|
556
|
+
label?: string;
|
|
557
|
+
required?: boolean;
|
|
558
|
+
defaultValue?: unknown;
|
|
559
|
+
options?: {
|
|
560
|
+
defaultMode?: "simple" | "notion";
|
|
561
|
+
[key: string]: unknown;
|
|
562
|
+
};
|
|
563
|
+
fields?: SerializableCollection["fields"];
|
|
564
|
+
blocks?: {
|
|
565
|
+
slug: string;
|
|
566
|
+
fields: SerializableCollection["fields"];
|
|
567
|
+
label?: string;
|
|
568
|
+
}[];
|
|
569
|
+
tabs?: {
|
|
570
|
+
label: string;
|
|
571
|
+
fields: SerializableCollection["fields"];
|
|
572
|
+
}[];
|
|
573
|
+
}[];
|
|
574
|
+
}[];
|
|
575
|
+
needsInit?: boolean;
|
|
576
|
+
storages?: Record<string, unknown>;
|
|
577
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts Lexical JSON state to plain text.
|
|
3
|
+
* Useful for displaying previews in tables or search results.
|
|
4
|
+
*/
|
|
5
|
+
export function lexicalToPlainText(jsonString: string): string {
|
|
6
|
+
if (!jsonString) return "";
|
|
7
|
+
|
|
8
|
+
try {
|
|
9
|
+
const data = JSON.parse(jsonString);
|
|
10
|
+
if (!data.root || !data.root.children) return "";
|
|
11
|
+
|
|
12
|
+
return traverseNodes(data.root.children);
|
|
13
|
+
} catch (err) {
|
|
14
|
+
// If it's not valid JSON, it might already be plain text or a different format
|
|
15
|
+
if (typeof jsonString === "string" && !jsonString.startsWith("{")) {
|
|
16
|
+
return jsonString;
|
|
17
|
+
}
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function traverseNodes(children: any[]): string {
|
|
23
|
+
let text = "";
|
|
24
|
+
for (const child of children) {
|
|
25
|
+
if (child.text) {
|
|
26
|
+
text += child.text;
|
|
27
|
+
} else if (child.children) {
|
|
28
|
+
text += traverseNodes(child.children);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Add space for block-level elements
|
|
32
|
+
if (child.type === "paragraph" || child.type === "heading" || child.type === "listitem") {
|
|
33
|
+
text += " ";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return text.trim();
|
|
37
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Logger Utility for OpacaCMS.
|
|
3
|
+
* Standardizes console output across the package with ANSI colors and standard prefixes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const RESET = "\x1b[0m";
|
|
7
|
+
const BLUE = "\x1b[34m";
|
|
8
|
+
const GREEN = "\x1b[32m";
|
|
9
|
+
const YELLOW = "\x1b[33m";
|
|
10
|
+
const RED = "\x1b[31m";
|
|
11
|
+
const GRAY = "\x1b[90m";
|
|
12
|
+
|
|
13
|
+
const PREFIX = `${BLUE}[OpacaCMS]${RESET}`;
|
|
14
|
+
|
|
15
|
+
export const logger = {
|
|
16
|
+
/**
|
|
17
|
+
* General information logging.
|
|
18
|
+
* Useful for successful operations, initialization steps, etc.
|
|
19
|
+
*/
|
|
20
|
+
info: (message: string, ...args: any[]) => {
|
|
21
|
+
console.log(`${PREFIX} ${message}`, ...args);
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Action logging. Usually highlighted in green.
|
|
26
|
+
* e.g., "Created table users", "Connected to DB"
|
|
27
|
+
*/
|
|
28
|
+
success: (message: string, ...args: any[]) => {
|
|
29
|
+
console.log(`${PREFIX} ${GREEN}${message}${RESET}`, ...args);
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Dim/Debug logging.
|
|
34
|
+
* e.g., "Starting schema push...", "Syncing database..."
|
|
35
|
+
*/
|
|
36
|
+
debug: (message: string, ...args: any[]) => {
|
|
37
|
+
console.log(`${PREFIX} ${GRAY}${message}${RESET}`, ...args);
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Warning logging.
|
|
42
|
+
* For non-fatal errors or deprecated warnings.
|
|
43
|
+
*/
|
|
44
|
+
warn: (message: string, ...args: any[]) => {
|
|
45
|
+
console.warn(`${PREFIX} ${YELLOW}Warning: ${message}${RESET}`, ...args);
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Error logging.
|
|
50
|
+
* For fatal errors, exceptions, and validation failures.
|
|
51
|
+
*/
|
|
52
|
+
error: (message: string, ...args: any[]) => {
|
|
53
|
+
console.error(`${PREFIX} ${RED}Error: ${message}${RESET}`, ...args);
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Raw formatting function if manual concatenation is needed.
|
|
58
|
+
*/
|
|
59
|
+
format: (color: "green" | "red" | "yellow" | "gray", msg: string) => {
|
|
60
|
+
switch (color) {
|
|
61
|
+
case "green":
|
|
62
|
+
return `${GREEN}${msg}${RESET}`;
|
|
63
|
+
case "red":
|
|
64
|
+
return `${RED}${msg}${RESET}`;
|
|
65
|
+
case "yellow":
|
|
66
|
+
return `${YELLOW}${msg}${RESET}`;
|
|
67
|
+
case "gray":
|
|
68
|
+
return `${GRAY}${msg}${RESET}`;
|
|
69
|
+
default:
|
|
70
|
+
return msg;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|