@tulip-systems/core 0.5.2 → 0.5.4
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/dist/auth/client.d.mts +3 -3
- package/dist/auth/client.mjs +2 -2
- package/dist/components/client.d.mts +2 -2
- package/dist/components/common/icons.d.mts +2 -2
- package/dist/components/common/icons.d.mts.map +1 -1
- package/dist/components/common/status.d.mts +3 -3
- package/dist/components/common/status.d.mts.map +1 -1
- package/dist/components/editor/components/content.client.d.mts +2 -2
- package/dist/components/editor/components/content.client.d.mts.map +1 -1
- package/dist/components/editor/components/editor.client.d.mts +6 -6
- package/dist/components/editor/components/editor.client.d.mts.map +1 -1
- package/dist/components/editor/components/editor.client.mjs +2 -2
- package/dist/components/editor/components/editor.client.mjs.map +1 -1
- package/dist/components/editor/components/menu.client.d.mts +3 -3
- package/dist/components/editor/components/menu.client.d.mts.map +1 -1
- package/dist/components/editor/components/menu.client.mjs +3 -0
- package/dist/components/editor/components/menu.client.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/extension.d.mts +21 -0
- package/dist/components/editor/extensions/file-handler/extension.d.mts.map +1 -0
- package/dist/components/editor/extensions/file-handler/extension.mjs +40 -0
- package/dist/components/editor/extensions/file-handler/extension.mjs.map +1 -0
- package/dist/components/editor/extensions/file-handler/strategy.d.mts +29 -0
- package/dist/components/editor/extensions/file-handler/strategy.d.mts.map +1 -0
- package/dist/components/editor/extensions/file-handler/strategy.mjs +111 -0
- package/dist/components/editor/extensions/file-handler/strategy.mjs.map +1 -0
- package/dist/components/editor/extensions/file-handler/utils.mjs +50 -0
- package/dist/components/editor/extensions/file-handler/utils.mjs.map +1 -0
- package/dist/components/editor/extensions/image/extension.d.mts +8 -0
- package/dist/components/editor/extensions/image/extension.d.mts.map +1 -0
- package/dist/components/editor/extensions/image/extension.mjs +51 -0
- package/dist/components/editor/extensions/image/extension.mjs.map +1 -0
- package/dist/components/editor/extensions/skeleton/extension.mjs +41 -0
- package/dist/components/editor/extensions/skeleton/extension.mjs.map +1 -0
- package/dist/components/editor/extensions/skeleton/renderer.mjs +25 -0
- package/dist/components/editor/extensions/skeleton/renderer.mjs.map +1 -0
- package/dist/components/editor/lib/constants.d.mts +31 -28
- package/dist/components/editor/lib/constants.d.mts.map +1 -1
- package/dist/components/editor/lib/constants.mjs +17 -5
- package/dist/components/editor/lib/constants.mjs.map +1 -1
- package/dist/components/editor/lib/extensions.d.mts +7 -3
- package/dist/components/editor/lib/extensions.d.mts.map +1 -1
- package/dist/components/editor/lib/extensions.mjs.map +1 -1
- package/dist/components/editor/lib/helpers.d.mts.map +1 -1
- package/dist/components/editor/lib/helpers.mjs +38 -3
- package/dist/components/editor/lib/helpers.mjs.map +1 -1
- package/dist/components/editor/lib/variants.mjs +10 -2
- package/dist/components/editor/lib/variants.mjs.map +1 -1
- package/dist/components/header/back-button.client.d.mts +2 -2
- package/dist/components/header/back-button.client.d.mts.map +1 -1
- package/dist/components/header/bottom-bar.client.d.mts +3 -3
- package/dist/components/header/bottom-bar.client.d.mts.map +1 -1
- package/dist/components/header/breadcrumbs.client.d.mts +7 -7
- package/dist/components/header/breadcrumbs.client.d.mts.map +1 -1
- package/dist/components/header/header.client.d.mts +2 -2
- package/dist/components/header/header.client.d.mts.map +1 -1
- package/dist/components/header/mobile-nav-switcher.client.d.mts +2 -2
- package/dist/components/header/mobile-nav-switcher.client.d.mts.map +1 -1
- package/dist/components/header/top-bar.client.d.mts +4 -4
- package/dist/components/header/top-bar.client.d.mts.map +1 -1
- package/dist/components/layouts/admin-content.client.d.mts +2 -2
- package/dist/components/layouts/admin-content.client.d.mts.map +1 -1
- package/dist/components/layouts/admin-layout.d.mts +2 -2
- package/dist/components/layouts/admin-layout.d.mts.map +1 -1
- package/dist/components/layouts/admin-loading.d.mts +2 -2
- package/dist/components/layouts/admin-loading.d.mts.map +1 -1
- package/dist/components/layouts/empty-page.d.mts +4 -4
- package/dist/components/layouts/empty-page.d.mts.map +1 -1
- package/dist/components/layouts/error-page.d.mts +23 -0
- package/dist/components/layouts/error-page.d.mts.map +1 -0
- package/dist/components/layouts/error-page.mjs +58 -0
- package/dist/components/layouts/error-page.mjs.map +1 -0
- package/dist/components/layouts/list-layout.d.mts +2 -2
- package/dist/components/layouts/list-layout.d.mts.map +1 -1
- package/dist/components/layouts/not-allowed-page.d.mts +22 -0
- package/dist/components/layouts/not-allowed-page.d.mts.map +1 -0
- package/dist/components/layouts/not-allowed-page.mjs +25 -0
- package/dist/components/layouts/not-allowed-page.mjs.map +1 -0
- package/dist/components/layouts/not-found-page.d.mts +3 -3
- package/dist/components/layouts/not-found-page.d.mts.map +1 -1
- package/dist/components/layouts/providers.client.d.mts +2 -2
- package/dist/components/layouts/providers.client.d.mts.map +1 -1
- package/dist/components/layouts/root-layout.server.d.mts +2 -2
- package/dist/components/layouts/root-layout.server.d.mts.map +1 -1
- package/dist/components/layouts/root-loading.d.mts +2 -2
- package/dist/components/layouts/root-loading.d.mts.map +1 -1
- package/dist/components/layouts/tab-layout.d.mts +2 -2
- package/dist/components/layouts/tab-layout.d.mts.map +1 -1
- package/dist/components/lists/data-list.d.mts +5 -5
- package/dist/components/lists/data-list.d.mts.map +1 -1
- package/dist/components/lists/data-stack.d.mts +8 -8
- package/dist/components/lists/data-stack.d.mts.map +1 -1
- package/dist/components/navigation/admin-sidebar-paths.client.d.mts +21 -11
- package/dist/components/navigation/admin-sidebar-paths.client.d.mts.map +1 -1
- package/dist/components/navigation/admin-sidebar-paths.client.mjs +7 -5
- package/dist/components/navigation/admin-sidebar-paths.client.mjs.map +1 -1
- package/dist/components/ui/accordion.d.mts +5 -5
- package/dist/components/ui/accordion.d.mts.map +1 -1
- package/dist/components/ui/alert-dialog.d.mts +12 -12
- package/dist/components/ui/alert-dialog.d.mts.map +1 -1
- package/dist/components/ui/alert.d.mts +6 -6
- package/dist/components/ui/alert.d.mts.map +1 -1
- package/dist/components/ui/aspect-ratio.d.mts +2 -2
- package/dist/components/ui/aspect-ratio.d.mts.map +1 -1
- package/dist/components/ui/avatar.client.d.mts +4 -4
- package/dist/components/ui/avatar.client.d.mts.map +1 -1
- package/dist/components/ui/badge.d.mts +4 -4
- package/dist/components/ui/badge.d.mts.map +1 -1
- package/dist/components/ui/breadcrumb.d.mts +8 -8
- package/dist/components/ui/breadcrumb.d.mts.map +1 -1
- package/dist/components/ui/button.d.mts +5 -5
- package/dist/components/ui/button.d.mts.map +1 -1
- package/dist/components/ui/calendar.d.mts +3 -3
- package/dist/components/ui/calendar.d.mts.map +1 -1
- package/dist/components/ui/card.d.mts +7 -7
- package/dist/components/ui/card.d.mts.map +1 -1
- package/dist/components/ui/carousel.d.mts +6 -6
- package/dist/components/ui/carousel.d.mts.map +1 -1
- package/dist/components/ui/chart.client.d.mts +5 -5
- package/dist/components/ui/chart.client.d.mts.map +1 -1
- package/dist/components/ui/checkbox.d.mts +2 -2
- package/dist/components/ui/checkbox.d.mts.map +1 -1
- package/dist/components/ui/collapsible.client.d.mts +4 -4
- package/dist/components/ui/collapsible.client.d.mts.map +1 -1
- package/dist/components/ui/color-picker.client.d.mts +2 -2
- package/dist/components/ui/color-picker.client.d.mts.map +1 -1
- package/dist/components/ui/combobox-dropdown.client.d.mts +2 -2
- package/dist/components/ui/combobox-dropdown.client.d.mts.map +1 -1
- package/dist/components/ui/combobox.client.d.mts +2 -2
- package/dist/components/ui/combobox.client.d.mts.map +1 -1
- package/dist/components/ui/command.d.mts +10 -10
- package/dist/components/ui/command.d.mts.map +1 -1
- package/dist/components/ui/context-menu.d.mts +16 -16
- package/dist/components/ui/context-menu.d.mts.map +1 -1
- package/dist/components/ui/date-picker.client.d.mts +2 -2
- package/dist/components/ui/date-picker.client.d.mts.map +1 -1
- package/dist/components/ui/dialog.client.d.mts +11 -11
- package/dist/components/ui/dialog.client.d.mts.map +1 -1
- package/dist/components/ui/drawer.client.d.mts +11 -11
- package/dist/components/ui/drawer.client.d.mts.map +1 -1
- package/dist/components/ui/dropdown-menu.d.mts +16 -16
- package/dist/components/ui/form.client.d.mts +7 -7
- package/dist/components/ui/form.client.d.mts.map +1 -1
- package/dist/components/ui/hover-card.client.d.mts +4 -4
- package/dist/components/ui/hover-card.client.d.mts.map +1 -1
- package/dist/components/ui/input-recipient.d.mts +2 -2
- package/dist/components/ui/input.d.mts +2 -2
- package/dist/components/ui/label.d.mts +2 -2
- package/dist/components/ui/navigation-menu.d.mts +11 -11
- package/dist/components/ui/pagination.d.mts +8 -8
- package/dist/components/ui/popover.d.mts +5 -5
- package/dist/components/ui/progress.client.d.mts +2 -2
- package/dist/components/ui/progress.client.d.mts.map +1 -1
- package/dist/components/ui/radio-group.d.mts +3 -3
- package/dist/components/ui/resizable.client.d.mts +4 -4
- package/dist/components/ui/resizable.client.d.mts.map +1 -1
- package/dist/components/ui/scroll-area.d.mts +3 -3
- package/dist/components/ui/select.client.d.mts +11 -11
- package/dist/components/ui/select.client.d.mts.map +1 -1
- package/dist/components/ui/separator.d.mts +2 -2
- package/dist/components/ui/sheet.client.d.mts +9 -9
- package/dist/components/ui/sheet.client.d.mts.map +1 -1
- package/dist/components/ui/sidebar.client.d.mts +26 -26
- package/dist/components/ui/sidebar.client.d.mts.map +1 -1
- package/dist/components/ui/skeleton.d.mts +2 -2
- package/dist/components/ui/slider.d.mts +2 -2
- package/dist/components/ui/sonner.client.d.mts +2 -2
- package/dist/components/ui/switch.d.mts +2 -2
- package/dist/components/ui/tabs.d.mts +5 -5
- package/dist/components/ui/textarea.d.mts +2 -2
- package/dist/components/ui/time-input.client.d.mts +2 -2
- package/dist/components/ui/toggle-group.client.d.mts +3 -3
- package/dist/components/ui/toggle.d.mts +2 -2
- package/dist/components/ui/toggle.d.mts.map +1 -1
- package/dist/components/ui/tooltip.client.d.mts +5 -5
- package/dist/components/ui/tooltip.client.d.mts.map +1 -1
- package/dist/components/ui/tooltip.client.mjs +1 -1
- package/dist/components/ui/tooltip.client.mjs.map +1 -1
- package/dist/components.d.mts +4 -1
- package/dist/components.mjs +5 -2
- package/dist/data-tables.d.mts +2 -2
- package/dist/data-tables.mjs +2 -2
- package/dist/inline-edit/client.d.mts +2 -3
- package/dist/inline-edit/client.mjs +1 -2
- package/dist/lib/client.d.mts +2 -2
- package/dist/lib/client.mjs +2 -2
- package/dist/lib/hooks/use-action.d.mts +2 -2
- package/dist/lib/hooks/use-indicator.d.mts +11 -3
- package/dist/lib/hooks/use-indicator.d.mts.map +1 -1
- package/dist/lib/hooks/use-indicator.mjs +19 -8
- package/dist/lib/hooks/use-indicator.mjs.map +1 -1
- package/dist/modules/auth/components/allowed.client.d.mts +21 -7
- package/dist/modules/auth/components/allowed.client.d.mts.map +1 -1
- package/dist/modules/auth/components/allowed.client.mjs +8 -2
- package/dist/modules/auth/components/allowed.client.mjs.map +1 -1
- package/dist/modules/auth/components/auth-layout.server.d.mts +2 -2
- package/dist/modules/auth/components/auth-layout.server.d.mts.map +1 -1
- package/dist/modules/auth/components/auth-loading.d.mts +2 -2
- package/dist/modules/auth/components/auth-loading.d.mts.map +1 -1
- package/dist/modules/auth/components/create-first-user-page.client.d.mts +2 -2
- package/dist/modules/auth/components/create-first-user-page.client.d.mts.map +1 -1
- package/dist/modules/auth/components/forget-password-page.client.d.mts +2 -2
- package/dist/modules/auth/components/forget-password-page.client.d.mts.map +1 -1
- package/dist/modules/auth/components/guard-first-user.server.d.mts +2 -2
- package/dist/modules/auth/components/guard-first-user.server.d.mts.map +1 -1
- package/dist/modules/auth/components/guard.server.d.mts +2 -2
- package/dist/modules/auth/components/guard.server.d.mts.map +1 -1
- package/dist/modules/auth/components/login-page.client.d.mts +2 -2
- package/dist/modules/auth/components/login-page.client.d.mts.map +1 -1
- package/dist/modules/auth/components/reset-password-page.client.d.mts +2 -2
- package/dist/modules/auth/components/reset-password-page.client.d.mts.map +1 -1
- package/dist/modules/auth/components/update-password-command.d.mts +2 -2
- package/dist/modules/auth/components/update-password-command.d.mts.map +1 -1
- package/dist/modules/auth/db/schema.d.mts +73 -73
- package/dist/modules/auth/db/schema.d.mts.map +1 -1
- package/dist/modules/auth/handler/client.client.d.mts +143 -143
- package/dist/modules/auth/handler/client.client.d.mts.map +1 -1
- package/dist/modules/auth/handler/init.d.mts +131 -131
- package/dist/modules/auth/handler/init.d.mts.map +1 -1
- package/dist/modules/auth/hooks/use-permission.d.mts +48 -4
- package/dist/modules/auth/hooks/use-permission.d.mts.map +1 -1
- package/dist/modules/auth/hooks/use-permission.mjs +51 -4
- package/dist/modules/auth/hooks/use-permission.mjs.map +1 -1
- package/dist/modules/auth/lib/helpers.server.mjs +1 -1
- package/dist/modules/auth/lib/validators.d.mts +2 -2
- package/dist/modules/auth/lib/validators.d.mts.map +1 -1
- package/dist/modules/commands/components/alert-dialog-command.client.d.mts +10 -10
- package/dist/modules/commands/components/click-command.client.d.mts +2 -2
- package/dist/modules/commands/components/command-trigger.client.d.mts +6 -6
- package/dist/modules/commands/components/dialog-command.client.d.mts +8 -8
- package/dist/modules/commands/components/dropdown-command.client.d.mts +5 -5
- package/dist/modules/commands/components/empty-command.client.d.mts +2 -2
- package/dist/modules/commands/components/form-dialog-command.client.d.mts +11 -11
- package/dist/modules/commands/hooks/use-command-menu.client.d.mts.map +1 -1
- package/dist/modules/commands/hooks/use-command-menu.client.mjs +0 -5
- package/dist/modules/commands/hooks/use-command-menu.client.mjs.map +1 -1
- package/dist/modules/commands/hooks/use-command-mutation.client.d.mts +2 -2
- package/dist/modules/commands/menus/context-menu.client.d.mts +2 -2
- package/dist/modules/commands/menus/dropdown-menu.client.d.mts +3 -3
- package/dist/modules/commands/menus/inline-menu.client.d.mts +3 -3
- package/dist/modules/commands/menus/responsive-menu.client.d.mts +3 -3
- package/dist/modules/commands/utils/archive-command.client.d.mts +3 -3
- package/dist/modules/commands/utils/delete-command.client.d.mts +3 -3
- package/dist/modules/config/db/helpers.d.mts +5 -5
- package/dist/modules/config/db/helpers.d.mts.map +1 -1
- package/dist/modules/data-tables/components/cell/common.client.d.mts +5 -5
- package/dist/modules/data-tables/components/column-header.d.mts +2 -2
- package/dist/modules/data-tables/components/filters/combobox.client.d.mts +2 -2
- package/dist/modules/data-tables/components/filters/slider.client.d.mts +2 -2
- package/dist/modules/data-tables/components/header.d.mts +4 -4
- package/dist/modules/data-tables/components/layout.d.mts +2 -2
- package/dist/modules/data-tables/components/search-input.client.d.mts +2 -2
- package/dist/modules/data-tables/components/skeleton.d.mts +2 -2
- package/dist/modules/data-tables/components/table.d.mts +7 -7
- package/dist/modules/data-tables/components/toolbar.d.mts +3 -3
- package/dist/modules/data-tables/hooks/use-context.client.d.mts +2 -2
- package/dist/modules/data-tables/lib/filters/parsers.d.mts +6 -1
- package/dist/modules/data-tables/lib/filters/parsers.d.mts.map +1 -1
- package/dist/modules/data-tables/lib/filters/parsers.mjs +6 -1
- package/dist/modules/data-tables/lib/filters/parsers.mjs.map +1 -1
- package/dist/modules/data-tables/tables/data-table/components/table.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/cells/common.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/cells/drag-handle.client.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/inputs/advanced-select.client.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/inputs/combobox.client.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/inputs/input.client.d.mts +3 -3
- package/dist/modules/data-tables/tables/inline-table/components/inputs/read-only.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/inputs/select.client.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/components/table.d.mts +2 -2
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.mts +2 -2
- package/dist/modules/inline-edit/components/combobox-dropdown.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/combobox-dropdown.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/combobox-dropdown.client.mjs +11 -6
- package/dist/modules/inline-edit/components/combobox-dropdown.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/combobox.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/combobox.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/combobox.client.mjs +7 -5
- package/dist/modules/inline-edit/components/combobox.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-input.client.d.mts +5 -3
- package/dist/modules/inline-edit/components/date-input.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/date-input.client.mjs +26 -13
- package/dist/modules/inline-edit/components/date-input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-picker.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/date-picker.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/date-picker.client.mjs +12 -7
- package/dist/modules/inline-edit/components/date-picker.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/editor.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/editor.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/editor.client.mjs +11 -6
- package/dist/modules/inline-edit/components/editor.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-recipient.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/input-recipient.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/input-recipient.client.mjs +11 -6
- package/dist/modules/inline-edit/components/input-recipient.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-toggle.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/input-toggle.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/input-toggle.client.mjs +9 -7
- package/dist/modules/inline-edit/components/input-toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input.client.d.mts +13 -10
- package/dist/modules/inline-edit/components/input.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/input.client.mjs +35 -19
- package/dist/modules/inline-edit/components/input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/select.client.d.mts +10 -9
- package/dist/modules/inline-edit/components/select.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/select.client.mjs +14 -7
- package/dist/modules/inline-edit/components/select.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/switch.client.d.mts +5 -3
- package/dist/modules/inline-edit/components/switch.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/switch.client.mjs +8 -6
- package/dist/modules/inline-edit/components/switch.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/toggle.client.d.mts +6 -4
- package/dist/modules/inline-edit/components/toggle.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/toggle.client.mjs +9 -7
- package/dist/modules/inline-edit/components/toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/hooks/context.client.d.mts +2 -2
- package/dist/modules/inline-edit/hooks/use-inline.client.d.mts +35 -3
- package/dist/modules/inline-edit/hooks/use-inline.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/hooks/use-inline.client.mjs +71 -9
- package/dist/modules/inline-edit/hooks/use-inline.client.mjs.map +1 -1
- package/dist/modules/inline-edit/lib/variants.d.mts +1 -0
- package/dist/modules/inline-edit/lib/variants.d.mts.map +1 -1
- package/dist/modules/inline-edit/lib/variants.mjs +12 -4
- package/dist/modules/inline-edit/lib/variants.mjs.map +1 -1
- package/dist/modules/router/handler/init.server.d.mts +4 -4
- package/dist/modules/router/handler/init.server.mjs +1 -1
- package/dist/modules/router/lib/query-client.server.d.mts +2 -2
- package/dist/modules/storage/components/dropzone-context.client.d.mts +2 -2
- package/dist/modules/storage/components/dropzone.client.d.mts +5 -5
- package/dist/modules/storage/components/image-grid.client.d.mts +3 -3
- package/dist/modules/storage/components/image-grid.client.mjs +2 -2
- package/dist/modules/storage/components/image-grid.client.mjs.map +1 -1
- package/dist/modules/storage/components/upload-zone-context.client.d.mts +3 -11
- package/dist/modules/storage/components/upload-zone-context.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone-context.client.mjs.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.d.mts +10 -33
- package/dist/modules/storage/components/upload-zone.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.mjs +19 -93
- package/dist/modules/storage/components/upload-zone.client.mjs.map +1 -1
- package/dist/modules/storage/config/filters.d.mts +1 -0
- package/dist/modules/storage/config/filters.d.mts.map +1 -1
- package/dist/modules/storage/config/filters.mjs +1 -0
- package/dist/modules/storage/config/filters.mjs.map +1 -1
- package/dist/modules/storage/lib/create-upload.client.d.mts +56 -0
- package/dist/modules/storage/lib/create-upload.client.d.mts.map +1 -0
- package/dist/modules/storage/lib/create-upload.client.mjs +98 -0
- package/dist/modules/storage/lib/create-upload.client.mjs.map +1 -0
- package/dist/modules/storage/lib/helpers.d.mts +1 -1
- package/dist/modules/storage/lib/router.server.d.mts +3239 -2319
- package/dist/modules/storage/lib/router.server.d.mts.map +1 -1
- package/dist/modules/storage/lib/router.server.mjs +5 -2
- package/dist/modules/storage/lib/router.server.mjs.map +1 -1
- package/dist/modules/storage/lib/schema.d.mts +124 -90
- package/dist/modules/storage/lib/schema.d.mts.map +1 -1
- package/dist/modules/storage/lib/schema.mjs +2 -1
- package/dist/modules/storage/lib/schema.mjs.map +1 -1
- package/dist/modules/storage/lib/service.server.d.mts +28 -39
- package/dist/modules/storage/lib/service.server.d.mts.map +1 -1
- package/dist/modules/storage/lib/service.server.mjs +6 -6
- package/dist/modules/storage/lib/service.server.mjs.map +1 -1
- package/dist/modules/storage/lib/validators.d.mts +166 -86
- package/dist/modules/storage/lib/validators.d.mts.map +1 -1
- package/dist/modules/storage/lib/validators.mjs +2 -1
- package/dist/modules/storage/lib/validators.mjs.map +1 -1
- package/dist/router/server.mjs +1 -1
- package/dist/storage/client.d.mts +2 -1
- package/dist/storage/client.mjs +2 -8
- package/dist/storage.d.mts +2 -2
- package/dist/storage.mjs +1 -1
- package/package.json +4 -3
- package/src/components/editor/components/editor.client.tsx +7 -2
- package/src/components/editor/components/menu.client.tsx +26 -0
- package/src/components/editor/extensions/file-handler/extension.ts +69 -0
- package/src/components/editor/extensions/file-handler/strategy.ts +167 -0
- package/src/components/editor/extensions/file-handler/utils.ts +51 -0
- package/src/components/editor/extensions/image/extension.ts +55 -0
- package/src/components/editor/extensions/skeleton/extension.ts +35 -0
- package/src/components/editor/extensions/skeleton/renderer.tsx +14 -0
- package/src/components/editor/lib/constants.ts +16 -2
- package/src/components/editor/lib/extensions.ts +4 -1
- package/src/components/editor/lib/helpers.ts +39 -3
- package/src/components/editor/lib/utils.ts +32 -0
- package/src/components/editor/lib/variants.ts +72 -1
- package/src/components/entry.ts +4 -1
- package/src/components/layouts/error-page.tsx +61 -0
- package/src/components/layouts/not-allowed-page.tsx +1 -1
- package/src/components/navigation/admin-sidebar-paths.client.tsx +18 -2
- package/src/components/ui/tooltip.client.tsx +1 -1
- package/src/lib/hooks/use-indicator.tsx +27 -18
- package/src/modules/auth/components/allowed.client.tsx +35 -7
- package/src/modules/auth/hooks/use-permission.ts +88 -2
- package/src/modules/commands/hooks/use-command-menu.client.tsx +4 -7
- package/src/modules/data-tables/lib/filters/parsers.ts +14 -0
- package/src/modules/inline-edit/components/combobox-dropdown.client.tsx +21 -12
- package/src/modules/inline-edit/components/combobox.client.tsx +13 -6
- package/src/modules/inline-edit/components/date-input.client.tsx +29 -13
- package/src/modules/inline-edit/components/date-picker.client.tsx +13 -9
- package/src/modules/inline-edit/components/editor.client.tsx +14 -14
- package/src/modules/inline-edit/components/input-recipient.client.tsx +15 -8
- package/src/modules/inline-edit/components/input-toggle.client.tsx +16 -9
- package/src/modules/inline-edit/components/input.client.tsx +38 -24
- package/src/modules/inline-edit/components/select.client.tsx +16 -9
- package/src/modules/inline-edit/components/switch.client.tsx +10 -6
- package/src/modules/inline-edit/components/toggle.client.tsx +13 -9
- package/src/modules/inline-edit/entry.client.ts +0 -1
- package/src/modules/inline-edit/hooks/use-inline.client.tsx +139 -20
- package/src/modules/inline-edit/lib/variants.ts +7 -0
- package/src/modules/storage/components/image-grid.client.tsx +2 -2
- package/src/modules/storage/components/upload-zone-context.client.tsx +3 -4
- package/src/modules/storage/components/upload-zone.client.tsx +17 -116
- package/src/modules/storage/config/filters.ts +1 -0
- package/src/modules/storage/entry.client.ts +2 -1
- package/src/modules/storage/lib/create-upload.client.ts +134 -0
- package/src/modules/storage/lib/router.server.ts +1 -0
- package/src/modules/storage/lib/schema.ts +1 -0
- package/src/modules/storage/lib/service.server.ts +10 -4
- package/src/modules/storage/lib/validators.ts +1 -0
- package/dist/modules/auth/lib/utils.mjs +0 -21
- package/dist/modules/auth/lib/utils.mjs.map +0 -1
- package/dist/modules/inline-edit/components/deprecated-editor.client.d.mts +0 -21
- package/dist/modules/inline-edit/components/deprecated-editor.client.d.mts.map +0 -1
- package/dist/modules/inline-edit/components/deprecated-editor.client.mjs +0 -37
- package/dist/modules/inline-edit/components/deprecated-editor.client.mjs.map +0 -1
- package/dist/storage/client.mjs.map +0 -1
- package/src/modules/inline-edit/components/deprecated-editor.client.tsx +0 -48
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { baseColumns } from "../../config/db/helpers.mjs";
|
|
2
2
|
import { users } from "../../auth/db/schema.mjs";
|
|
3
|
-
import { imageDispositions, imageVariants } from "./constants.mjs";
|
|
4
3
|
import { nodeSubtypes } from "./helpers.mjs";
|
|
4
|
+
import { imageDispositions, imageVariants } from "./constants.mjs";
|
|
5
5
|
import { boolean, pgEnum, pgTable, unique } from "drizzle-orm/pg-core";
|
|
6
6
|
import { relations } from "drizzle-orm";
|
|
7
7
|
|
|
@@ -25,6 +25,7 @@ const nodes = pgTable("nodes", (t) => ({
|
|
|
25
25
|
createdBy: t.uuid().references(() => users.id, { onDelete: "set null" }),
|
|
26
26
|
isPending: t.boolean().default(false).notNull(),
|
|
27
27
|
isDeleted: t.boolean().default(false).notNull(),
|
|
28
|
+
orphanedAt: t.timestamp(),
|
|
28
29
|
parentId: t.uuid().references(() => nodes.id, { onDelete: "cascade" })
|
|
29
30
|
}));
|
|
30
31
|
const nodesRelations = relations(nodes, ({ one, many }) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.mjs","names":[],"sources":["../../../../src/modules/storage/lib/schema.ts"],"sourcesContent":["import { users } from \"@/modules/auth/db/schema\";\nimport { baseColumns } from \"@/modules/config/db/helpers\";\nimport { relations } from \"drizzle-orm\";\nimport { AnyPgColumn, boolean, pgEnum, pgTable, unique } from \"drizzle-orm/pg-core\";\nimport { imageDispositions, imageVariants } from \"./constants\";\nimport { nodeSubtypes } from \"./helpers\";\n\nexport const nodeTypeEnum = pgEnum(\"node_types\", [\"file\", \"folder\"]);\nexport const nodeModeEnum = pgEnum(\"node_mode\", [\"private\", \"public\"]);\n\n/**\n * Node table\n */\nexport const nodes = pgTable(\"nodes\", (t) => ({\n ...baseColumns,\n name: t.text().notNull(),\n namespace: t.text().notNull().default(\"global\"),\n type: nodeTypeEnum(),\n mode: nodeModeEnum().default(\"private\"),\n subtype: t.text({ enum: nodeSubtypes }).notNull().default(\"other\"),\n size: t.integer().default(0),\n contentType: t.varchar({ length: 255 }),\n readonly: boolean().default(false),\n hidden: boolean().default(false),\n createdBy: t.uuid().references(() => users.id, { onDelete: \"set null\" }),\n isPending: t.boolean().default(false).notNull(),\n isDeleted: t.boolean().default(false).notNull(),\n parentId: t.uuid().references((): AnyPgColumn => nodes.id, { onDelete: \"cascade\" }),\n}));\n\nexport const nodesRelations = relations(nodes, ({ one, many }) => ({\n parent: one(nodes, {\n fields: [nodes.parentId],\n references: [nodes.id],\n relationName: \"parent\",\n }),\n children: many(nodes, {\n relationName: \"parent\",\n }),\n urls: many(nodePresignedUrls),\n variants: many(nodeVariants),\n}));\n\n/**\n * Node variants table\n */\nexport const nodeVariants = pgTable(\"node_variants\", (t) => ({\n ...baseColumns,\n nodeId: t\n .uuid()\n .notNull()\n .references(() => nodes.id, { onDelete: \"cascade\" }),\n variant: t.text({ enum: imageVariants }).notNull(),\n width: t.integer().notNull(),\n}));\n\nexport const nodeVariantsRelations = relations(nodeVariants, ({ one }) => ({\n node: one(nodes, {\n fields: [nodeVariants.nodeId],\n references: [nodes.id],\n relationName: \"node\",\n }),\n}));\n\n/**\n * Node presigned urls table\n */\nexport const nodePresignedUrls = pgTable(\n \"node_presigned_urls\",\n (t) => ({\n ...baseColumns,\n url: t.text().notNull().unique(),\n variant: t.text({ enum: imageVariants }).notNull(),\n disposition: t.text({ enum: imageDispositions }).notNull(),\n expiresAt: t.timestamp().notNull(),\n nodeId: t\n .uuid()\n .notNull()\n .references(() => nodes.id, { onDelete: \"cascade\" }),\n variantId: t.uuid().references(() => nodeVariants.id, { onDelete: \"set null\" }),\n }),\n (t) => [unique(\"node_presigned_url_unique\").on(t.nodeId, t.variant, t.disposition)],\n);\n\nexport const nodePresignedUrlsRelations = relations(nodePresignedUrls, ({ one }) => ({\n node: one(nodes, {\n fields: [nodePresignedUrls.nodeId],\n references: [nodes.id],\n relationName: \"node\",\n }),\n}));\n\n/**\n * Drive schema\n **/\nconst driveSchema = {\n nodes,\n nodesRelations,\n nodeVariants,\n nodeVariantsRelations,\n nodePresignedUrls,\n nodePresignedUrlsRelations,\n};\nexport type DriveSchema = typeof driveSchema;\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe,OAAO,cAAc,CAAC,QAAQ,SAAS,CAAC;AACpE,MAAa,eAAe,OAAO,aAAa,CAAC,WAAW,SAAS,CAAC;;;;AAKtE,MAAa,QAAQ,QAAQ,UAAU,OAAO;CAC5C,GAAG;CACH,MAAM,EAAE,MAAM,CAAC,SAAS;CACxB,WAAW,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,SAAS;CAC/C,MAAM,cAAc;CACpB,MAAM,cAAc,CAAC,QAAQ,UAAU;CACvC,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC,CAAC,SAAS,CAAC,QAAQ,QAAQ;CAClE,MAAM,EAAE,SAAS,CAAC,QAAQ,EAAE;CAC5B,aAAa,EAAE,QAAQ,EAAE,QAAQ,KAAK,CAAC;CACvC,UAAU,SAAS,CAAC,QAAQ,MAAM;CAClC,QAAQ,SAAS,CAAC,QAAQ,MAAM;CAChC,WAAW,EAAE,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AAS,CACT,iBAAiB,MAAM,IAAI,EAAE,UAAU,WAAW,CAAC;CACtD,WAAW,EAAE,MAAM,CAAC,iBAAiB,aAAa,IAAI,EAAE,UAAU,YAAY,CAAC;CAChF,IACA,MAAM,CAAC,OAAO,4BAA4B,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CACpF;AAED,MAAa,6BAA6B,UAAU,oBAAoB,EAAE,WAAW,EACnF,MAAM,IAAI,OAAO;CACf,QAAQ,CAAC,kBAAkB,OAAO;CAClC,YAAY,CAAC,MAAM,GAAG;CACtB,cAAc;CACf,CAAC,EACH,EAAE"}
|
|
1
|
+
{"version":3,"file":"schema.mjs","names":[],"sources":["../../../../src/modules/storage/lib/schema.ts"],"sourcesContent":["import { users } from \"@/modules/auth/db/schema\";\nimport { baseColumns } from \"@/modules/config/db/helpers\";\nimport { relations } from \"drizzle-orm\";\nimport { AnyPgColumn, boolean, pgEnum, pgTable, unique } from \"drizzle-orm/pg-core\";\nimport { imageDispositions, imageVariants } from \"./constants\";\nimport { nodeSubtypes } from \"./helpers\";\n\nexport const nodeTypeEnum = pgEnum(\"node_types\", [\"file\", \"folder\"]);\nexport const nodeModeEnum = pgEnum(\"node_mode\", [\"private\", \"public\"]);\n\n/**\n * Node table\n */\nexport const nodes = pgTable(\"nodes\", (t) => ({\n ...baseColumns,\n name: t.text().notNull(),\n namespace: t.text().notNull().default(\"global\"),\n type: nodeTypeEnum(),\n mode: nodeModeEnum().default(\"private\"),\n subtype: t.text({ enum: nodeSubtypes }).notNull().default(\"other\"),\n size: t.integer().default(0),\n contentType: t.varchar({ length: 255 }),\n readonly: boolean().default(false),\n hidden: boolean().default(false),\n createdBy: t.uuid().references(() => users.id, { onDelete: \"set null\" }),\n isPending: t.boolean().default(false).notNull(),\n isDeleted: t.boolean().default(false).notNull(),\n orphanedAt: t.timestamp(),\n parentId: t.uuid().references((): AnyPgColumn => nodes.id, { onDelete: \"cascade\" }),\n}));\n\nexport const nodesRelations = relations(nodes, ({ one, many }) => ({\n parent: one(nodes, {\n fields: [nodes.parentId],\n references: [nodes.id],\n relationName: \"parent\",\n }),\n children: many(nodes, {\n relationName: \"parent\",\n }),\n urls: many(nodePresignedUrls),\n variants: many(nodeVariants),\n}));\n\n/**\n * Node variants table\n */\nexport const nodeVariants = pgTable(\"node_variants\", (t) => ({\n ...baseColumns,\n nodeId: t\n .uuid()\n .notNull()\n .references(() => nodes.id, { onDelete: \"cascade\" }),\n variant: t.text({ enum: imageVariants }).notNull(),\n width: t.integer().notNull(),\n}));\n\nexport const nodeVariantsRelations = relations(nodeVariants, ({ one }) => ({\n node: one(nodes, {\n fields: [nodeVariants.nodeId],\n references: [nodes.id],\n relationName: \"node\",\n }),\n}));\n\n/**\n * Node presigned urls table\n */\nexport const nodePresignedUrls = pgTable(\n \"node_presigned_urls\",\n (t) => ({\n ...baseColumns,\n url: t.text().notNull().unique(),\n variant: t.text({ enum: imageVariants }).notNull(),\n disposition: t.text({ enum: imageDispositions }).notNull(),\n expiresAt: t.timestamp().notNull(),\n nodeId: t\n .uuid()\n .notNull()\n .references(() => nodes.id, { onDelete: \"cascade\" }),\n variantId: t.uuid().references(() => nodeVariants.id, { onDelete: \"set null\" }),\n }),\n (t) => [unique(\"node_presigned_url_unique\").on(t.nodeId, t.variant, t.disposition)],\n);\n\nexport const nodePresignedUrlsRelations = relations(nodePresignedUrls, ({ one }) => ({\n node: one(nodes, {\n fields: [nodePresignedUrls.nodeId],\n references: [nodes.id],\n relationName: \"node\",\n }),\n}));\n\n/**\n * Drive schema\n **/\nconst driveSchema = {\n nodes,\n nodesRelations,\n nodeVariants,\n nodeVariantsRelations,\n nodePresignedUrls,\n nodePresignedUrlsRelations,\n};\nexport type DriveSchema = typeof driveSchema;\n"],"mappings":";;;;;;;;AAOA,MAAa,eAAe,OAAO,cAAc,CAAC,QAAQ,SAAS,CAAC;AACpE,MAAa,eAAe,OAAO,aAAa,CAAC,WAAW,SAAS,CAAC;;;;AAKtE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SAAS,CAAC,SAAS;CAC7B,EAAE;AAEH,MAAa,wBAAwB,UAAU,eAAe,EAAE,WAAW,EACzE,MAAM,IAAI,OAAO;CACf,QAAQ,CAAC,aAAa,OAAO;CAC7B,YAAY,CAAC,MAAM,GAAG;CACtB,cAAc;CACf,CAAC,EACH,EAAE;;;;AAKH,MAAa,oBAAoB,QAC/B,wBACC,OAAO;CACN,GAAG;CACH,KAAK,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ;CAChC,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC,CAAC,SAAS;CAClD,aAAa,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC,CAAC,SAAS;CAC1D,WAAW,EAAE,WAAW,CAAC,SAAS;CAClC,QAAQ,EACL,MAAM,CACN,SAAS,CACT,iBAAiB,MAAM,IAAI,EAAE,UAAU,WAAW,CAAC;CACtD,WAAW,EAAE,MAAM,CAAC,iBAAiB,aAAa,IAAI,EAAE,UAAU,YAAY,CAAC;CAChF,IACA,MAAM,CAAC,OAAO,4BAA4B,CAAC,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,CAAC,CACpF;AAED,MAAa,6BAA6B,UAAU,oBAAoB,EAAE,WAAW,EACnF,MAAM,IAAI,OAAO;CACf,QAAQ,CAAC,kBAAkB,OAAO;CAClC,YAAY,CAAC,MAAM,GAAG;CACtB,cAAc;CACf,CAAC,EACH,EAAE"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { CreateFolderNodeSchema, FileNode, GetFileURLSchema, GetNodesByParentIdInput, Node, PresignFileSchema, PutObjectInput, UpdateNodeSchema, UploadFileSchema } from "./validators.mjs";
|
|
2
|
+
import { BulkActionSchema } from "../../router/lib/validators.mjs";
|
|
3
|
+
import "../../../router.mjs";
|
|
1
4
|
import { TDatabaseSchema } from "../../config/db/types.mjs";
|
|
2
5
|
import { DatabaseClient } from "../../config/db/init.mjs";
|
|
3
6
|
import "../../../config/server.mjs";
|
|
4
|
-
import { BulkActionSchema } from "../../router/lib/validators.mjs";
|
|
5
|
-
import "../../../router.mjs";
|
|
6
|
-
import { CreateFolderNodeSchema, GetFileURLSchema, GetNodesByParentIdInput, Node, PresignFileSchema, PutObjectInput, UpdateNodeSchema, UploadFileSchema } from "./validators.mjs";
|
|
7
7
|
import "../../../config.mjs";
|
|
8
8
|
import * as _aws_sdk_client_s30 from "@aws-sdk/client-s3";
|
|
9
9
|
import { S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
|
|
@@ -52,6 +52,7 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
52
52
|
createdBy: string | null;
|
|
53
53
|
isPending: boolean;
|
|
54
54
|
isDeleted: boolean;
|
|
55
|
+
orphanedAt: Date | null;
|
|
55
56
|
parentId: string | null;
|
|
56
57
|
id: string;
|
|
57
58
|
createdAt: Date;
|
|
@@ -76,6 +77,7 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
76
77
|
createdBy: string | null;
|
|
77
78
|
isPending: boolean;
|
|
78
79
|
isDeleted: boolean;
|
|
80
|
+
orphanedAt: Date | null;
|
|
79
81
|
parentId: string | null;
|
|
80
82
|
id: string;
|
|
81
83
|
createdAt: Date;
|
|
@@ -89,21 +91,22 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
89
91
|
* Upload file to S3 and add it to the database
|
|
90
92
|
**/
|
|
91
93
|
uploadFile(input: UploadFileSchema & Pick<PutObjectInput, "body">): Promise<{
|
|
92
|
-
|
|
93
|
-
readonly: boolean | null;
|
|
94
|
+
size: number | null;
|
|
94
95
|
id: string;
|
|
96
|
+
name: string;
|
|
95
97
|
type: "file" | "folder" | null;
|
|
96
|
-
|
|
97
|
-
updatedAt: Date;
|
|
98
|
+
hidden: boolean | null;
|
|
98
99
|
mode: "private" | "public" | null;
|
|
99
|
-
size: number | null;
|
|
100
100
|
isPending: boolean;
|
|
101
101
|
namespace: string;
|
|
102
102
|
subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
|
|
103
103
|
contentType: string | null;
|
|
104
|
-
|
|
104
|
+
readonly: boolean | null;
|
|
105
|
+
createdAt: Date;
|
|
106
|
+
updatedAt: Date;
|
|
105
107
|
createdBy: string | null;
|
|
106
108
|
isDeleted: boolean;
|
|
109
|
+
orphanedAt: Date | null;
|
|
107
110
|
parentId: string | null;
|
|
108
111
|
}>;
|
|
109
112
|
/**
|
|
@@ -113,21 +116,22 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
113
116
|
id: string;
|
|
114
117
|
presignedUrl: string;
|
|
115
118
|
node: {
|
|
116
|
-
|
|
117
|
-
readonly: boolean | null;
|
|
119
|
+
size: number | null;
|
|
118
120
|
id: string;
|
|
121
|
+
name: string;
|
|
119
122
|
type: "file" | "folder" | null;
|
|
120
|
-
|
|
121
|
-
updatedAt: Date;
|
|
123
|
+
hidden: boolean | null;
|
|
122
124
|
mode: "private" | "public" | null;
|
|
123
|
-
size: number | null;
|
|
124
125
|
isPending: boolean;
|
|
125
126
|
namespace: string;
|
|
126
127
|
subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
|
|
127
128
|
contentType: string | null;
|
|
128
|
-
|
|
129
|
+
readonly: boolean | null;
|
|
130
|
+
createdAt: Date;
|
|
131
|
+
updatedAt: Date;
|
|
129
132
|
createdBy: string | null;
|
|
130
133
|
isDeleted: boolean;
|
|
134
|
+
orphanedAt: Date | null;
|
|
131
135
|
parentId: string | null;
|
|
132
136
|
};
|
|
133
137
|
}>;
|
|
@@ -136,24 +140,7 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
136
140
|
*/
|
|
137
141
|
confirmUpload(input: {
|
|
138
142
|
id: string;
|
|
139
|
-
}): Promise<
|
|
140
|
-
name: string;
|
|
141
|
-
namespace: string;
|
|
142
|
-
type: "file" | "folder" | null;
|
|
143
|
-
mode: "private" | "public" | null;
|
|
144
|
-
subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
|
|
145
|
-
size: number | null;
|
|
146
|
-
contentType: string | null;
|
|
147
|
-
readonly: boolean | null;
|
|
148
|
-
hidden: boolean | null;
|
|
149
|
-
createdBy: string | null;
|
|
150
|
-
isPending: boolean;
|
|
151
|
-
isDeleted: boolean;
|
|
152
|
-
parentId: string | null;
|
|
153
|
-
id: string;
|
|
154
|
-
createdAt: Date;
|
|
155
|
-
updatedAt: Date;
|
|
156
|
-
}>;
|
|
143
|
+
}): Promise<FileNode>;
|
|
157
144
|
/**
|
|
158
145
|
* Generate preview version of the file
|
|
159
146
|
*/
|
|
@@ -164,21 +151,22 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
164
151
|
* Create a new folder
|
|
165
152
|
*/
|
|
166
153
|
createFolder(input: CreateFolderNodeSchema): Promise<{
|
|
167
|
-
|
|
168
|
-
readonly: boolean | null;
|
|
154
|
+
size: number | null;
|
|
169
155
|
id: string;
|
|
156
|
+
name: string;
|
|
170
157
|
type: "file" | "folder" | null;
|
|
171
|
-
|
|
172
|
-
updatedAt: Date;
|
|
158
|
+
hidden: boolean | null;
|
|
173
159
|
mode: "private" | "public" | null;
|
|
174
|
-
size: number | null;
|
|
175
160
|
isPending: boolean;
|
|
176
161
|
namespace: string;
|
|
177
162
|
subtype: "image" | "document" | "spreadsheet" | "video" | "audio" | "archive" | "other";
|
|
178
163
|
contentType: string | null;
|
|
179
|
-
|
|
164
|
+
readonly: boolean | null;
|
|
165
|
+
createdAt: Date;
|
|
166
|
+
updatedAt: Date;
|
|
180
167
|
createdBy: string | null;
|
|
181
168
|
isDeleted: boolean;
|
|
169
|
+
orphanedAt: Date | null;
|
|
182
170
|
parentId: string | null;
|
|
183
171
|
}>;
|
|
184
172
|
/**
|
|
@@ -200,6 +188,7 @@ declare class StorageService<TSchema extends TDatabaseSchema> {
|
|
|
200
188
|
createdBy: string | null;
|
|
201
189
|
isPending: boolean;
|
|
202
190
|
isDeleted: boolean;
|
|
191
|
+
orphanedAt: Date | null;
|
|
203
192
|
parentId: string | null;
|
|
204
193
|
id: string;
|
|
205
194
|
createdAt: Date;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.server.d.mts","names":[],"sources":["../../../../src/modules/storage/lib/service.server.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"service.server.d.mts","names":[],"sources":["../../../../src/modules/storage/lib/service.server.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;KA0CY,qCAAqC;MAC3C,eAAe;UACX;AAFV,CAAA;;;;AAEU,cAMG,cANH,CAAA,gBAMkC,eANlC,CAAA,CAAA;EAAc,CAAA,OAAA;EAMX;;;EAUO,WAAA,CAAA;IAAA,EAAA;IAAA;EAAA,CAAA,EAAU,oBAAV,CAA+B,OAA/B,CAAA;EAA+B;;;EA4BZ,IAAA,CAAA,CAAA,EApBjC,QAoBiC;EAA2C;;;kCAA3C,mBAA2C,QAAA,mBAAA,CAAA,sBAAA;;;;EA0ChC,WAAA,CAAA,EAAA,EAAA,MAAA,CAAA,EAPpB,OAOoB,CAAA;;;;IAAuB,IAAA,EAAA,SAAA,GAAA,QAAA,GAAA,IAAA;IA6B9C,OAAA,EAAA,OAAA,GAAA,UAAA,GAAA,aAAA,GAAA,OAAA,GAAA,OAAA,GAAA,SAAA,GAAA,OAAA;IAAe,IAAA,EAAA,MAAA,GAAA,IAAA;IAA2C,WAAA,EAAA,MAAA,GAAA,IAAA;IAmE3D,QAAA,EAAA,OAAA,GAAA,IAAA;IAAwB,MAAA,EAAA,OAAA,GAAA,IAAA;IAAL,SAAA,EAAA,MAAA,GAAA,IAAA;;;;IAA4B,QAAA,EAAA,MAAA,GAAA,IAAA;IAyC5C,EAAA,EAAA,MAAA;;;;EAAiB;;;EA4DA,kBAAA,CAAA;IAAA,OAAA;IAAA,GAAA;EAAA,CAAA,EArMI,uBAqMJ,CAAA,EArM2B,OAqM3B,CAAA;IAwDlB,IAAA,EAAA,MAAA;;;;IAAsB,OAAA,EAAA,OAAA,GAAA,UAAA,GAAA,aAAA,GAAA,OAAA,GAAA,OAAA,GAAA,SAAA,GAAA,OAAA;IA0CJ,IAAA,EAAA,MAAA,GAAA,IAAA;;;;IAAkB,SAAA,EAAA,MAAA,GAAA,IAAA;IA4BrC,SAAA,EAAA,OAAA;IAAgB,SAAA,EAAA,OAAA;IAAA,UAAA,MAAA,GAAA,IAAA;;;;;;;;;qBAtShB,gBAAe,mBAA2C;;;;oBAmE3D,mBAAmB,KAAK,0BAAuB;;;;;;;;;;;;;;;;;;;;;;uBAyC5C,oBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAqCH,QAAA;;;;;;MAuBG;;;;sBAwDlB,yBAAsB;;;;;;;;;;;;;;;;;;;;;;;;UA0CJ;MAAkB;;;;;;;;;;;;;;;;;;;;;;qBA4BrC,mBAAgB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { ServerError } from "../../router/lib/error.server.mjs";
|
|
1
2
|
import { generateDefaultUUID } from "../../config/db/helpers.mjs";
|
|
2
3
|
import { BUCKET_NAME } from "../../../lib/config/constants.mjs";
|
|
3
|
-
import {
|
|
4
|
+
import { getDriveBucketKey, inferNodeSubtype, isFile, isFolder } from "./helpers.mjs";
|
|
4
5
|
import { convertSearchToQueryParams } from "../../data-tables/lib/converters/search.mjs";
|
|
5
6
|
import { convertOrderByToQueryParams } from "../../data-tables/lib/converters/sorting.mjs";
|
|
6
7
|
import { deviceSizes } from "./constants.mjs";
|
|
7
|
-
import { getDriveBucketKey, inferNodeSubtype, isFile, isFolder } from "./helpers.mjs";
|
|
8
8
|
import { nodePresignedUrls, nodeVariants, nodes } from "./schema.mjs";
|
|
9
9
|
import { getFileURLSchemaDefaults, getObjectSchema, putObjectSchema } from "./validators.mjs";
|
|
10
|
-
import { and, asc, eq, inArray, isNull } from "drizzle-orm";
|
|
10
|
+
import { and, asc, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
|
11
11
|
import { after } from "next/server";
|
|
12
12
|
import { addSeconds } from "date-fns";
|
|
13
13
|
import { DeleteObjectsCommand, GetObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
@@ -66,8 +66,8 @@ var StorageService = class {
|
|
|
66
66
|
Bucket: BUCKET_NAME,
|
|
67
67
|
Key: getDriveBucketKey(input.id, input.variant),
|
|
68
68
|
Body: input.body,
|
|
69
|
-
ContentType: input.contentType ??
|
|
70
|
-
ContentLength: input.size ?? 0,
|
|
69
|
+
ContentType: input.contentType ?? void 0,
|
|
70
|
+
ContentLength: input.size ?? void 0,
|
|
71
71
|
Metadata: { nodeId: input.id }
|
|
72
72
|
});
|
|
73
73
|
}
|
|
@@ -90,7 +90,7 @@ var StorageService = class {
|
|
|
90
90
|
async getNodesByParentId({ filters, ...query }) {
|
|
91
91
|
const orderBy = convertOrderByToQueryParams(query, nodes, asc(nodes.createdAt));
|
|
92
92
|
const search = convertSearchToQueryParams(query, [nodes.name]);
|
|
93
|
-
return this.#db.select().from(nodes).where(and(filters.nodeIds != null ? inArray(nodes.id, filters.nodeIds) : void 0, filters.types != null ? inArray(nodes.type, filters.types) : void 0, filters.isDeleted != null ? eq(nodes.isDeleted, filters.isDeleted) : void 0, filters.hidden != null ? eq(nodes.hidden, filters.hidden) : void 0, filters.parentId ? eq(nodes.parentId, filters.parentId) : isNull(nodes.parentId), eq(nodes.namespace, filters.namespace), search)).orderBy(orderBy);
|
|
93
|
+
return this.#db.select().from(nodes).where(and(filters.nodeIds != null ? inArray(nodes.id, filters.nodeIds) : void 0, filters.types != null ? inArray(nodes.type, filters.types) : void 0, filters.isDeleted != null ? eq(nodes.isDeleted, filters.isDeleted) : void 0, filters.isOrphaned === true ? isNotNull(nodes.orphanedAt) : filters.isOrphaned === false ? isNull(nodes.orphanedAt) : void 0, filters.hidden != null ? eq(nodes.hidden, filters.hidden) : void 0, filters.parentId ? eq(nodes.parentId, filters.parentId) : isNull(nodes.parentId), eq(nodes.namespace, filters.namespace), search)).orderBy(orderBy);
|
|
94
94
|
}
|
|
95
95
|
/**
|
|
96
96
|
* Get file url
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.server.mjs","names":["#db","#blob","#createGetCommand","#putObject","#createPutCommand"],"sources":["../../../../src/modules/storage/lib/service.server.ts"],"sourcesContent":["import { BUCKET_NAME } from \"@/lib/config/constants\";\nimport { generateDefaultUUID, TDatabaseSchema } from \"@/modules/config/entry\";\nimport { DatabaseClient } from \"@/modules/config/entry.server\";\nimport {\n convertOrderByToQueryParams,\n convertSearchToQueryParams,\n} from \"@/modules/data-tables/entry.server\";\nimport { BulkActionSchema } from \"@/modules/router/entry\";\nimport { ServerError } from \"@/modules/router/lib/error.server\";\nimport {\n DeleteObjectsCommand,\n GetObjectCommand,\n PutObjectCommand,\n S3Client,\n S3ClientConfig,\n} from \"@aws-sdk/client-s3\";\nimport { getSignedUrl } from \"@aws-sdk/s3-request-presigner\";\nimport { addSeconds } from \"date-fns\";\nimport { and, asc, eq, inArray, isNull, SQL } from \"drizzle-orm\";\nimport { after } from \"next/server\";\nimport { deviceSizes } from \"./constants\";\nimport { getDriveBucketKey, inferNodeSubtype, isFile, isFolder } from \"./helpers\";\nimport { nodePresignedUrls, nodes, nodeVariants } from \"./schema\";\nimport {\n CreateFolderNodeSchema,\n GetFileURLSchema,\n getFileURLSchemaDefaults,\n GetNodesByParentIdInput,\n GetObjectInput,\n getObjectSchema,\n Node,\n PresignFileSchema,\n PutObjectInput,\n putObjectSchema,\n UpdateNodeSchema,\n UploadFileSchema,\n} from \"./validators\";\n\n/**\n * Storage Service Config\n */\nexport type StorageServiceConfig<TSchema extends TDatabaseSchema> = {\n db: DatabaseClient<TSchema>;\n config: S3ClientConfig;\n};\n\n/**\n * Storage Service\n */\nexport class StorageService<TSchema extends TDatabaseSchema> {\n /**\n * S3 Client\n */\n #blob: S3Client;\n #db: DatabaseClient<TSchema>;\n\n /**\n * Constructor\n */\n constructor({ db, config }: StorageServiceConfig<TSchema>) {\n this.#db = db;\n this.#blob = new S3Client(config);\n }\n\n /**\n * Get Blob\n */\n blob() {\n return this.#blob;\n }\n\n /**\n * Create get command\n */\n #createGetCommand(props: GetObjectInput) {\n const input = getObjectSchema.parse(props);\n\n return new GetObjectCommand({\n Bucket: BUCKET_NAME,\n Key: getDriveBucketKey(input.id, input.variant),\n ResponseContentDisposition: input.disposition,\n });\n }\n\n /**\n * Get object\n */\n async getObject(id: string, options: GetFileURLSchema = getFileURLSchemaDefaults) {\n const getCommand = this.#createGetCommand({ ...options, id });\n\n return await this.#blob.send(getCommand);\n }\n\n /**\n * Create put command\n */\n #createPutCommand(props: PutObjectInput) {\n const input = putObjectSchema.parse(props);\n\n return new PutObjectCommand({\n Bucket: BUCKET_NAME,\n Key: getDriveBucketKey(input.id, input.variant),\n Body: input.body,\n ContentType: input.contentType ?? \"\",\n ContentLength: input.size ?? 0,\n Metadata: {\n nodeId: input.id,\n },\n });\n }\n\n /**\n * Put object\n */\n async #putObject(props: PutObjectInput) {\n const putCommand = this.#createPutCommand(props);\n return await this.#blob.send(putCommand);\n }\n\n /**\n * Get node by id\n */\n async getNodeById(id: string) {\n return this.#db.select().from(nodes).where(eq(nodes.id, id));\n }\n\n /**\n * Get nodes by parent id\n */\n async getNodesByParentId({ filters, ...query }: GetNodesByParentIdInput) {\n const orderBy = convertOrderByToQueryParams(query, nodes, asc(nodes.createdAt));\n const search = convertSearchToQueryParams(query, [nodes.name]);\n\n return this.#db\n .select()\n .from(nodes)\n .where(\n and(\n filters.nodeIds != null ? inArray(nodes.id, filters.nodeIds) : undefined,\n filters.types != null ? inArray(nodes.type, filters.types) : undefined,\n filters.isDeleted != null ? eq(nodes.isDeleted, filters.isDeleted) : undefined,\n filters.hidden != null ? eq(nodes.hidden, filters.hidden) : undefined,\n filters.parentId ? eq(nodes.parentId, filters.parentId) : isNull(nodes.parentId),\n eq(nodes.namespace, filters.namespace),\n search,\n ),\n )\n .orderBy(orderBy as SQL);\n }\n\n /**\n * Get file url\n */\n async getSignedURL(node: Node, options: GetFileURLSchema = getFileURLSchemaDefaults) {\n const [presignedUrl] = await this.#db\n .select({ url: nodePresignedUrls.url, expiresAt: nodePresignedUrls.expiresAt })\n .from(nodePresignedUrls)\n .where(\n and(\n eq(nodePresignedUrls.nodeId, node.id),\n eq(nodePresignedUrls.variant, options.variant),\n eq(nodePresignedUrls.disposition, options.disposition),\n ),\n );\n\n if (presignedUrl && presignedUrl.expiresAt > new Date()) return presignedUrl.url;\n\n const expiresIn = 3600 * 24;\n\n // Get the variants\n const variants = await this.#db\n .select()\n .from(nodeVariants)\n .where(eq(nodeVariants.nodeId, node.id));\n\n // If the requested variant does not exist, fallback to main\n const variantExists = variants.find((v) => v.variant === options.variant);\n const variant = variantExists ? options.variant : \"main\";\n\n console.info(\n `Generating new signed url for file: ${node.id} with variant: ${variant} and disposition: ${options.disposition}`,\n );\n\n // Generate the get command\n const getCommand = this.#createGetCommand({\n id: node.id,\n variant,\n disposition: `${options.disposition}; filename=\"${node.name}\"`,\n });\n\n // Generate the presigned url that expires in 24 hours\n const url = await getSignedUrl(this.#blob, getCommand, { expiresIn });\n\n // Add the presigned url to the database\n after(async () => {\n await this.#db\n .insert(nodePresignedUrls)\n .values({\n nodeId: node.id,\n url,\n variant,\n disposition: options.disposition,\n expiresAt: addSeconds(new Date(), expiresIn),\n })\n .onConflictDoUpdate({\n target: [\n nodePresignedUrls.nodeId,\n nodePresignedUrls.variant,\n nodePresignedUrls.disposition,\n ],\n set: { url, expiresAt: addSeconds(new Date(), expiresIn) },\n });\n });\n\n return url;\n }\n\n /**\n * Upload file to S3 and add it to the database\n **/\n async uploadFile(input: UploadFileSchema & Pick<PutObjectInput, \"body\">) {\n const id = generateDefaultUUID();\n\n return await this.#db.transaction(async (tx) => {\n const [result] = await tx\n .insert(nodes)\n .values({\n id,\n type: \"file\",\n name: input.name,\n namespace: input.namespace,\n parentId: input.parentId,\n size: input.size,\n contentType: input.contentType,\n mode: input.mode,\n subtype: inferNodeSubtype(input),\n })\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n await this.#putObject({\n id,\n body: input.body,\n variant: \"main\",\n name: input.name,\n contentType: input.contentType,\n size: input.size,\n });\n\n return result;\n });\n }\n\n /**\n * Presign a new upload\n */\n async presignUpload(input: PresignFileSchema) {\n // Generate the put command\n const putCommand = this.#createPutCommand({\n id: input.id,\n name: input.name,\n variant: \"main\",\n contentType: input.contentType,\n size: input.size,\n });\n\n // Generate the presigned url\n const presignedUrl = await getSignedUrl(this.#blob, putCommand, { expiresIn: 3600 });\n\n const [node] = await this.#db\n .insert(nodes)\n .values({\n ...input,\n subtype: inferNodeSubtype(input),\n isPending: true,\n type: \"file\",\n id: input.id,\n })\n .returning();\n\n if (!node) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n // Return the result\n return { id: input.id, presignedUrl, node };\n }\n\n /**\n * Confirm a new upload\n */\n async confirmUpload(input: { id: string }) {\n const [result] = await this.#db\n .update(nodes)\n .set({ isPending: false })\n .where(eq(nodes.id, input.id))\n .returning();\n\n if (!result) {\n throw new ServerError(\"NOT_FOUND\", { message: \"File not found\" });\n }\n\n /**\n * Generate the preview version of the file\n */\n // after(async () => {});\n await this.generatePreviews(input);\n\n return result;\n }\n\n /**\n * Generate preview version of the file\n */\n async generatePreviews(input: { id: string }) {\n /**\n * Get the main version of the file\n */\n const getCommand = this.#createGetCommand({ id: input.id, variant: \"main\" });\n\n const response = await this.#blob.send(getCommand);\n const contentType = response.ContentType;\n if (!response.Body) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n /**\n * Transform the main version of the file to a buffer\n */\n const byteArray = await response.Body.transformToByteArray();\n const buffer = Buffer.from(byteArray);\n\n /**\n * Generate the preview versions for images\n */\n if (contentType?.startsWith(\"image/\")) {\n const sharp = await import(\"sharp\");\n\n // Generate the preview versions\n await Promise.allSettled(\n deviceSizes.flatMap(async (width) => {\n // Generate the preview\n const preview = await sharp.default(buffer).resize({ width }).webp().toBuffer();\n\n // Upload the preview and add the variant to the database\n return this.#db.transaction(async (tx) => {\n await this.#putObject({\n id: input.id,\n body: preview,\n variant: `preview-${width}`,\n contentType: \"image/webp\",\n size: preview.byteLength,\n });\n\n await tx.insert(nodeVariants).values({\n nodeId: input.id,\n variant: `preview-${width}`,\n width,\n });\n });\n }),\n );\n }\n }\n\n /**\n * Create a new folder\n */\n async createFolder(input: CreateFolderNodeSchema) {\n const [parent] = input.parentId\n ? await this.#db.select().from(nodes).where(eq(nodes.id, input.parentId))\n : [];\n\n /**\n * Validate\n */\n if (input.parentId && !parent) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Parent not found\" });\n }\n\n if (parent && !isFolder(parent)) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Parent is not a folder\" });\n }\n\n if (parent && parent.namespace !== input.namespace) {\n throw new ServerError(\"BAD_REQUEST\", {\n message: \"Parent is not in the same namespace\",\n });\n }\n\n /**\n * Create the folder\n */\n const [result] = await this.#db\n .insert(nodes)\n .values({ ...input, type: \"folder\" })\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Folder kon niet worden aangemaakt\",\n });\n }\n\n return result;\n }\n\n /**\n * Update a node\n */\n async updateNode(input: { id: string; data: UpdateNodeSchema }) {\n const [node] = await this.#db\n .select({ readonly: nodes.readonly })\n .from(nodes)\n .where(eq(nodes.id, input.id));\n\n if (node?.readonly) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Node is readonly\" });\n }\n\n const [result] = await this.#db\n .update(nodes)\n .set(input.data)\n .where(eq(nodes.id, input.id))\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Node kon niet worden gewijzigd\",\n });\n }\n\n return result;\n }\n\n /**\n * Delete nodes\n */\n async deleteNodes(input: BulkActionSchema) {\n const items = await this.#db\n .select({ id: nodes.id, type: nodes.type, readonly: nodes.readonly })\n .from(nodes)\n .where(inArray(nodes.id, input.ids));\n\n // Check if the nodes are readonly\n if (items.some((item) => item.readonly)) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Nodes are readonly\" });\n }\n\n // Split the nodes into folders and files\n const folders = items.filter(isFolder).map((folder) => folder.id);\n const files = items.filter(isFile).map((file) => file.id);\n\n // Delete command for S3\n const deleteCommand =\n files.length > 0\n ? new DeleteObjectsCommand({\n Bucket: BUCKET_NAME,\n Delete: {\n Objects: files.map((id) => ({ Key: id })),\n },\n })\n : undefined;\n\n /**\n * Delete files and folders in a transaction\n */\n await this.#db.transaction(async (tx) => {\n await tx.delete(nodes).where(inArray(nodes.id, folders));\n await tx.delete(nodes).where(inArray(nodes.id, files));\n\n if (deleteCommand) await this.#blob.send(deleteCommand);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiDA,IAAa,iBAAb,MAA6D;;;;CAI3D;CACA;;;;CAKA,YAAY,EAAE,IAAI,UAAyC;AACzD,QAAKA,KAAM;AACX,QAAKC,OAAQ,IAAI,SAAS,OAAO;;;;;CAMnC,OAAO;AACL,SAAO,MAAKA;;;;;CAMd,kBAAkB,OAAuB;EACvC,MAAM,QAAQ,gBAAgB,MAAM,MAAM;AAE1C,SAAO,IAAI,iBAAiB;GAC1B,QAAQ;GACR,KAAK,kBAAkB,MAAM,IAAI,MAAM,QAAQ;GAC/C,4BAA4B,MAAM;GACnC,CAAC;;;;;CAMJ,MAAM,UAAU,IAAY,UAA4B,0BAA0B;EAChF,MAAM,aAAa,MAAKC,iBAAkB;GAAE,GAAG;GAAS;GAAI,CAAC;AAE7D,SAAO,MAAM,MAAKD,KAAM,KAAK,WAAW;;;;;CAM1C,kBAAkB,OAAuB;EACvC,MAAM,QAAQ,gBAAgB,MAAM,MAAM;AAE1C,SAAO,IA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AE,KAAK,IAAI,EAAE,EAC1C;GACF,CAAC,GACF;;;;AAKN,QAAM,MAAKA,GAAI,YAAY,OAAO,OAAO;AACvC,SAAM,GAAG,OAAO,MAAM,CAAC,MAAM,QAAQ,MAAM,IAAI,QAAQ,CAAC;AACxD,SAAM,GAAG,OAAO,MAAM,CAAC,MAAM,QAAQ,MAAM,IAAI,MAAM,CAAC;AAEtD,OAAI,cAAe,OAAM,MAAKC,KAAM,KAAK,cAAc;IACvD"}
|
|
1
|
+
{"version":3,"file":"service.server.mjs","names":["#db","#blob","#createGetCommand","#putObject","#createPutCommand"],"sources":["../../../../src/modules/storage/lib/service.server.ts"],"sourcesContent":["import { BUCKET_NAME } from \"@/lib/config/constants\";\nimport { generateDefaultUUID, TDatabaseSchema } from \"@/modules/config/entry\";\nimport { DatabaseClient } from \"@/modules/config/entry.server\";\nimport {\n convertOrderByToQueryParams,\n convertSearchToQueryParams,\n} from \"@/modules/data-tables/entry.server\";\nimport { BulkActionSchema } from \"@/modules/router/entry\";\nimport { ServerError } from \"@/modules/router/lib/error.server\";\nimport {\n DeleteObjectsCommand,\n GetObjectCommand,\n PutObjectCommand,\n S3Client,\n S3ClientConfig,\n} from \"@aws-sdk/client-s3\";\nimport { getSignedUrl } from \"@aws-sdk/s3-request-presigner\";\nimport { addSeconds } from \"date-fns\";\nimport { and, asc, eq, inArray, isNotNull, isNull, SQL } from \"drizzle-orm\";\nimport { after } from \"next/server\";\nimport { deviceSizes } from \"./constants\";\nimport { getDriveBucketKey, inferNodeSubtype, isFile, isFolder } from \"./helpers\";\nimport { nodePresignedUrls, nodes, nodeVariants } from \"./schema\";\nimport {\n CreateFolderNodeSchema,\n FileNode,\n GetFileURLSchema,\n getFileURLSchemaDefaults,\n GetNodesByParentIdInput,\n GetObjectInput,\n getObjectSchema,\n Node,\n PresignFileSchema,\n PutObjectInput,\n putObjectSchema,\n UpdateNodeSchema,\n UploadFileSchema,\n} from \"./validators\";\n\n/**\n * Storage Service Config\n */\nexport type StorageServiceConfig<TSchema extends TDatabaseSchema> = {\n db: DatabaseClient<TSchema>;\n config: S3ClientConfig;\n};\n\n/**\n * Storage Service\n */\nexport class StorageService<TSchema extends TDatabaseSchema> {\n /**\n * S3 Client\n */\n #blob: S3Client;\n #db: DatabaseClient<TSchema>;\n\n /**\n * Constructor\n */\n constructor({ db, config }: StorageServiceConfig<TSchema>) {\n this.#db = db;\n this.#blob = new S3Client(config);\n }\n\n /**\n * Get Blob\n */\n blob() {\n return this.#blob;\n }\n\n /**\n * Create get command\n */\n #createGetCommand(props: GetObjectInput) {\n const input = getObjectSchema.parse(props);\n\n return new GetObjectCommand({\n Bucket: BUCKET_NAME,\n Key: getDriveBucketKey(input.id, input.variant),\n ResponseContentDisposition: input.disposition,\n });\n }\n\n /**\n * Get object\n */\n async getObject(id: string, options: GetFileURLSchema = getFileURLSchemaDefaults) {\n const getCommand = this.#createGetCommand({ ...options, id });\n\n return await this.#blob.send(getCommand);\n }\n\n /**\n * Create put command\n */\n #createPutCommand(props: PutObjectInput) {\n const input = putObjectSchema.parse(props);\n\n return new PutObjectCommand({\n Bucket: BUCKET_NAME,\n Key: getDriveBucketKey(input.id, input.variant),\n Body: input.body,\n ContentType: input.contentType ?? undefined,\n ContentLength: input.size ?? undefined,\n Metadata: {\n nodeId: input.id,\n },\n });\n }\n\n /**\n * Put object\n */\n async #putObject(props: PutObjectInput) {\n const putCommand = this.#createPutCommand(props);\n return await this.#blob.send(putCommand);\n }\n\n /**\n * Get node by id\n */\n async getNodeById(id: string) {\n return this.#db.select().from(nodes).where(eq(nodes.id, id));\n }\n\n /**\n * Get nodes by parent id\n */\n async getNodesByParentId({ filters, ...query }: GetNodesByParentIdInput) {\n const orderBy = convertOrderByToQueryParams(query, nodes, asc(nodes.createdAt));\n const search = convertSearchToQueryParams(query, [nodes.name]);\n\n return this.#db\n .select()\n .from(nodes)\n .where(\n and(\n filters.nodeIds != null ? inArray(nodes.id, filters.nodeIds) : undefined,\n filters.types != null ? inArray(nodes.type, filters.types) : undefined,\n filters.isDeleted != null ? eq(nodes.isDeleted, filters.isDeleted) : undefined,\n filters.isOrphaned === true\n ? isNotNull(nodes.orphanedAt)\n : filters.isOrphaned === false\n ? isNull(nodes.orphanedAt)\n : undefined,\n filters.hidden != null ? eq(nodes.hidden, filters.hidden) : undefined,\n filters.parentId ? eq(nodes.parentId, filters.parentId) : isNull(nodes.parentId),\n eq(nodes.namespace, filters.namespace),\n search,\n ),\n )\n .orderBy(orderBy as SQL);\n }\n\n /**\n * Get file url\n */\n async getSignedURL(node: Node, options: GetFileURLSchema = getFileURLSchemaDefaults) {\n const [presignedUrl] = await this.#db\n .select({ url: nodePresignedUrls.url, expiresAt: nodePresignedUrls.expiresAt })\n .from(nodePresignedUrls)\n .where(\n and(\n eq(nodePresignedUrls.nodeId, node.id),\n eq(nodePresignedUrls.variant, options.variant),\n eq(nodePresignedUrls.disposition, options.disposition),\n ),\n );\n\n if (presignedUrl && presignedUrl.expiresAt > new Date()) return presignedUrl.url;\n\n const expiresIn = 3600 * 24;\n\n // Get the variants\n const variants = await this.#db\n .select()\n .from(nodeVariants)\n .where(eq(nodeVariants.nodeId, node.id));\n\n // If the requested variant does not exist, fallback to main\n const variantExists = variants.find((v) => v.variant === options.variant);\n const variant = variantExists ? options.variant : \"main\";\n\n console.info(\n `Generating new signed url for file: ${node.id} with variant: ${variant} and disposition: ${options.disposition}`,\n );\n\n // Generate the get command\n const getCommand = this.#createGetCommand({\n id: node.id,\n variant,\n disposition: `${options.disposition}; filename=\"${node.name}\"`,\n });\n\n // Generate the presigned url that expires in 24 hours\n const url = await getSignedUrl(this.#blob, getCommand, { expiresIn });\n\n // Add the presigned url to the database\n after(async () => {\n await this.#db\n .insert(nodePresignedUrls)\n .values({\n nodeId: node.id,\n url,\n variant,\n disposition: options.disposition,\n expiresAt: addSeconds(new Date(), expiresIn),\n })\n .onConflictDoUpdate({\n target: [\n nodePresignedUrls.nodeId,\n nodePresignedUrls.variant,\n nodePresignedUrls.disposition,\n ],\n set: { url, expiresAt: addSeconds(new Date(), expiresIn) },\n });\n });\n\n return url;\n }\n\n /**\n * Upload file to S3 and add it to the database\n **/\n async uploadFile(input: UploadFileSchema & Pick<PutObjectInput, \"body\">) {\n const id = generateDefaultUUID();\n\n return await this.#db.transaction(async (tx) => {\n const [result] = await tx\n .insert(nodes)\n .values({\n id,\n type: \"file\",\n name: input.name,\n namespace: input.namespace,\n parentId: input.parentId,\n size: input.size,\n contentType: input.contentType,\n mode: input.mode,\n subtype: inferNodeSubtype(input),\n })\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n await this.#putObject({\n id,\n body: input.body,\n variant: \"main\",\n name: input.name,\n contentType: input.contentType,\n size: input.size,\n });\n\n return result;\n });\n }\n\n /**\n * Presign a new upload\n */\n async presignUpload(input: PresignFileSchema) {\n // Generate the put command\n const putCommand = this.#createPutCommand({\n id: input.id,\n name: input.name,\n variant: \"main\",\n contentType: input.contentType,\n size: input.size,\n });\n\n // Generate the presigned url\n const presignedUrl = await getSignedUrl(this.#blob, putCommand, { expiresIn: 3600 });\n\n const [node] = await this.#db\n .insert(nodes)\n .values({\n ...input,\n subtype: inferNodeSubtype(input),\n isPending: true,\n type: \"file\",\n id: input.id,\n })\n .returning();\n\n if (!node) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n // Return the result\n return { id: input.id, presignedUrl, node };\n }\n\n /**\n * Confirm a new upload\n */\n async confirmUpload(input: { id: string }) {\n const [result] = await this.#db\n .update(nodes)\n .set({ isPending: false })\n .where(eq(nodes.id, input.id))\n .returning();\n\n if (!result) {\n throw new ServerError(\"NOT_FOUND\", { message: \"File not found\" });\n }\n\n /**\n * Generate the preview version of the file\n */\n // after(async () => {});\n await this.generatePreviews(input);\n\n return result as FileNode;\n }\n\n /**\n * Generate preview version of the file\n */\n async generatePreviews(input: { id: string }) {\n /**\n * Get the main version of the file\n */\n const getCommand = this.#createGetCommand({ id: input.id, variant: \"main\" });\n\n const response = await this.#blob.send(getCommand);\n const contentType = response.ContentType;\n if (!response.Body) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Oep! Er is iets fout gegaan\",\n });\n }\n\n /**\n * Transform the main version of the file to a buffer\n */\n const byteArray = await response.Body.transformToByteArray();\n const buffer = Buffer.from(byteArray);\n\n /**\n * Generate the preview versions for images\n */\n if (contentType?.startsWith(\"image/\")) {\n const sharp = await import(\"sharp\");\n\n // Generate the preview versions\n await Promise.allSettled(\n deviceSizes.flatMap(async (width) => {\n // Generate the preview\n const preview = await sharp.default(buffer).resize({ width }).webp().toBuffer();\n\n // Upload the preview and add the variant to the database\n return this.#db.transaction(async (tx) => {\n await this.#putObject({\n id: input.id,\n body: preview,\n variant: `preview-${width}`,\n contentType: \"image/webp\",\n size: preview.byteLength,\n });\n\n await tx.insert(nodeVariants).values({\n nodeId: input.id,\n variant: `preview-${width}`,\n width,\n });\n });\n }),\n );\n }\n }\n\n /**\n * Create a new folder\n */\n async createFolder(input: CreateFolderNodeSchema) {\n const [parent] = input.parentId\n ? await this.#db.select().from(nodes).where(eq(nodes.id, input.parentId))\n : [];\n\n /**\n * Validate\n */\n if (input.parentId && !parent) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Parent not found\" });\n }\n\n if (parent && !isFolder(parent)) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Parent is not a folder\" });\n }\n\n if (parent && parent.namespace !== input.namespace) {\n throw new ServerError(\"BAD_REQUEST\", {\n message: \"Parent is not in the same namespace\",\n });\n }\n\n /**\n * Create the folder\n */\n const [result] = await this.#db\n .insert(nodes)\n .values({ ...input, type: \"folder\" })\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Folder kon niet worden aangemaakt\",\n });\n }\n\n return result;\n }\n\n /**\n * Update a node\n */\n async updateNode(input: { id: string; data: UpdateNodeSchema }) {\n const [node] = await this.#db\n .select({ readonly: nodes.readonly })\n .from(nodes)\n .where(eq(nodes.id, input.id));\n\n if (node?.readonly) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Node is readonly\" });\n }\n\n const [result] = await this.#db\n .update(nodes)\n .set(input.data)\n .where(eq(nodes.id, input.id))\n .returning();\n\n if (!result) {\n throw new ServerError(\"INTERNAL_SERVER_ERROR\", {\n message: \"Node kon niet worden gewijzigd\",\n });\n }\n\n return result;\n }\n\n /**\n * Delete nodes\n */\n async deleteNodes(input: BulkActionSchema) {\n const items = await this.#db\n .select({ id: nodes.id, type: nodes.type, readonly: nodes.readonly })\n .from(nodes)\n .where(inArray(nodes.id, input.ids));\n\n // Check if the nodes are readonly\n if (items.some((item) => item.readonly)) {\n throw new ServerError(\"BAD_REQUEST\", { message: \"Nodes are readonly\" });\n }\n\n // Split the nodes into folders and files\n const folders = items.filter(isFolder).map((folder) => folder.id);\n const files = items.filter(isFile).map((file) => file.id);\n\n // Delete command for S3\n const deleteCommand =\n files.length > 0\n ? new DeleteObjectsCommand({\n Bucket: BUCKET_NAME,\n Delete: {\n Objects: files.map((id) => ({ Key: id })),\n },\n })\n : undefined;\n\n /**\n * Delete files and folders in a transaction\n */\n await this.#db.transaction(async (tx) => {\n await tx.delete(nodes).where(inArray(nodes.id, folders));\n await tx.delete(nodes).where(inArray(nodes.id, files));\n\n if (deleteCommand) await this.#blob.send(deleteCommand);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkDA,IAAa,iBAAb,MAA6D;;;;CAI3D;CACA;;;;CAKA,YAAY,EAAE,IAAI,UAAyC;AACzD,QAAKA,KAAM;AACX,QAAKC,OAAQ,IAAI,SAAS,OAAO;;;;;CAMnC,OAAO;AACL,SAAO,MAAKA;;;;;CAMd,kBAAkB,OAAuB;EACvC,MAAM,QAAQ,gBAAgB,MAAM,MAAM;AAE1C,SAAO,IAAI,iBAAiB;GAC1B,QAA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