@tulip-systems/core 0.7.0 → 0.8.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/dist/auth/server.d.mts +3 -3
- package/dist/auth/server.mjs +3 -3
- package/dist/components/editor/components/editor.client.d.mts +4 -3
- package/dist/components/editor/components/editor.client.d.mts.map +1 -1
- package/dist/components/editor/components/editor.client.mjs +5 -2
- package/dist/components/editor/components/editor.client.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/extension.d.mts +4 -4
- package/dist/components/editor/extensions/file-handler/extension.d.mts.map +1 -1
- package/dist/components/editor/extensions/file-handler/extension.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/strategy.d.mts +4 -6
- package/dist/components/editor/extensions/file-handler/strategy.d.mts.map +1 -1
- package/dist/components/editor/extensions/file-handler/strategy.mjs +11 -11
- package/dist/components/editor/extensions/file-handler/strategy.mjs.map +1 -1
- package/dist/components/editor/extensions/file-handler/utils.mjs +1 -1
- package/dist/components/editor/extensions/file-handler/utils.mjs.map +1 -1
- package/dist/components/editor/extensions/image/extension.mjs +9 -9
- package/dist/components/editor/extensions/image/extension.mjs.map +1 -1
- package/dist/components/editor/lib/constants.d.mts +1 -1
- package/dist/components/editor/lib/constants.mjs +1 -1
- package/dist/components/editor/lib/extensions.d.mts +1 -1
- package/dist/components/editor/lib/helpers.d.mts +11 -3
- package/dist/components/editor/lib/helpers.d.mts.map +1 -1
- package/dist/components/editor/lib/helpers.mjs +27 -13
- package/dist/components/editor/lib/helpers.mjs.map +1 -1
- package/dist/components/ui/badge.d.mts +1 -1
- package/dist/components/ui/button-group.d.mts +1 -1
- package/dist/components/ui/button.d.mts +2 -2
- package/dist/components/ui/combobox-dropdown.client.mjs +1 -0
- package/dist/components/ui/combobox-dropdown.client.mjs.map +1 -1
- package/dist/components/ui/combobox.client.mjs +1 -1
- package/dist/components/ui/combobox.client.mjs.map +1 -1
- package/dist/components/ui/field.client.d.mts +1 -1
- package/dist/components/ui/item.d.mts +1 -1
- package/dist/components.d.mts +2 -2
- package/dist/components.mjs +2 -2
- package/dist/config/server.d.mts +1 -3
- package/dist/config/server.mjs +1 -4
- package/dist/config.d.mts +2 -2
- package/dist/config.mjs +1 -1
- package/dist/data-tables/client.d.mts +2 -1
- package/dist/data-tables/client.mjs +2 -1
- package/dist/data-tables.d.mts +1 -1
- package/dist/database/client.d.mts +1 -0
- package/dist/database/client.mjs +1 -0
- package/dist/database/server.d.mts +2 -0
- package/dist/database/server.mjs +3 -0
- package/dist/database.d.mts +3 -0
- package/dist/database.mjs +3 -0
- package/dist/emails/client.d.mts +1 -0
- package/dist/emails/client.mjs +1 -0
- package/dist/emails/server.d.mts +2 -0
- package/dist/emails/server.mjs +3 -0
- package/dist/emails.d.mts +1 -0
- package/dist/emails.mjs +1 -0
- package/dist/lib/utils/markdown.d.mts +10 -0
- package/dist/lib/utils/markdown.d.mts.map +1 -0
- package/dist/lib/utils/markdown.mjs +15 -0
- package/dist/lib/utils/markdown.mjs.map +1 -0
- package/dist/lib/utils/url.mjs +2 -1
- package/dist/lib/utils/url.mjs.map +1 -1
- package/dist/lib/utils/user-agent.mjs +15 -0
- package/dist/lib/utils/user-agent.mjs.map +1 -1
- package/dist/lib.d.mts +2 -2
- package/dist/lib.mjs +2 -2
- package/dist/modules/auth/components/create-first-user-guard.server.d.mts +16 -0
- package/dist/modules/auth/components/create-first-user-guard.server.d.mts.map +1 -0
- package/dist/modules/auth/components/create-first-user-guard.server.mjs +16 -0
- package/dist/modules/auth/components/create-first-user-guard.server.mjs.map +1 -0
- package/dist/modules/auth/components/guard.server.d.mts +2 -2
- package/dist/modules/auth/components/guard.server.mjs +1 -1
- package/dist/modules/auth/components/guard.server.mjs.map +1 -1
- package/dist/modules/auth/db/schema.d.mts +1 -1
- package/dist/modules/auth/db/schema.mjs +2 -2
- package/dist/modules/auth/handler/create-client.client.d.mts +4838 -229
- package/dist/modules/auth/handler/create-client.client.d.mts.map +1 -1
- package/dist/modules/auth/handler/create-client.client.mjs.map +1 -1
- package/dist/modules/auth/handler/proxy.server.mjs +2 -2
- package/dist/modules/auth/handler/proxy.server.mjs.map +1 -1
- package/dist/modules/auth/handler/route.server.d.mts +2 -2
- package/dist/modules/auth/handler/route.server.d.mts.map +1 -1
- package/dist/modules/auth/handler/route.server.mjs.map +1 -1
- package/dist/modules/auth/handler/{init.d.mts → service.server.d.mts} +322 -90
- package/dist/modules/auth/handler/service.server.d.mts.map +1 -0
- package/dist/modules/auth/handler/{init.mjs → service.server.mjs} +19 -8
- package/dist/modules/auth/handler/service.server.mjs.map +1 -0
- package/dist/modules/auth/hooks/use-session.d.mts +9 -4
- package/dist/modules/auth/hooks/use-session.d.mts.map +1 -1
- package/dist/modules/auth/lib/helpers.server.d.mts +1 -1
- package/dist/modules/auth/lib/permissions.d.mts +1 -1
- package/dist/modules/auth/lib/validators.mjs +1 -1
- package/dist/modules/config/lib/context.d.mts +9 -10
- package/dist/modules/config/lib/context.d.mts.map +1 -1
- package/dist/modules/config/lib/context.mjs.map +1 -1
- package/dist/modules/data-tables/lib/converters/search.d.mts +1 -1
- package/dist/modules/data-tables/lib/converters/sorting.d.mts +1 -1
- package/dist/modules/data-tables/server/get-data.server.d.mts +3 -3
- package/dist/modules/data-tables/server/get-data.server.mjs +1 -1
- package/dist/modules/data-tables/server/get-data.server.mjs.map +1 -1
- package/dist/modules/data-tables/strategies/infinite/strategy.d.mts +1 -1
- package/dist/modules/data-tables/strategies/infinite/strategy.mjs +3 -0
- package/dist/modules/data-tables/strategies/infinite/strategy.mjs.map +1 -1
- package/dist/modules/data-tables/tables/data-table/components/row.mjs +5 -15
- package/dist/modules/data-tables/tables/data-table/components/row.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/body.mjs +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/body.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/row.client.mjs +13 -23
- package/dist/modules/data-tables/tables/inline-table/components/row.client.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.d.mts +1 -0
- package/dist/modules/data-tables/tables/inline-table/components/table.d.mts.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.mjs +2 -1
- package/dist/modules/data-tables/tables/inline-table/components/table.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.mts +5 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.d.mts.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.mjs +2 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/context.client.mjs.map +1 -1
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.d.mts +30 -0
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.d.mts.map +1 -0
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.mjs +77 -9
- package/dist/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.mjs.map +1 -1
- package/dist/modules/{config/db → database/lib}/helpers.d.mts +2 -2
- package/dist/modules/database/lib/helpers.d.mts.map +1 -0
- package/dist/modules/{config/db → database/lib}/helpers.mjs +1 -1
- package/dist/modules/database/lib/helpers.mjs.map +1 -0
- package/dist/modules/database/lib/service.server.d.mts +34 -0
- package/dist/modules/database/lib/service.server.d.mts.map +1 -0
- package/dist/modules/database/lib/service.server.mjs +24 -0
- package/dist/modules/database/lib/service.server.mjs.map +1 -0
- package/dist/modules/{config/db → database/lib}/types.d.mts +1 -1
- package/dist/modules/database/lib/types.d.mts.map +1 -0
- package/dist/modules/emails/lib/service.server.d.mts +29 -0
- package/dist/modules/emails/lib/service.server.d.mts.map +1 -0
- package/dist/modules/emails/lib/service.server.mjs +21 -0
- package/dist/modules/emails/lib/service.server.mjs.map +1 -0
- package/dist/modules/inline-edit/components/date-input.client.mjs +1 -1
- package/dist/modules/inline-edit/components/date-input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-picker.client.mjs +1 -0
- package/dist/modules/inline-edit/components/date-picker.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/date-time.client.mjs +1 -0
- package/dist/modules/inline-edit/components/date-time.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/editor.client.mjs +1 -0
- package/dist/modules/inline-edit/components/editor.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-recipient.client.mjs +1 -0
- package/dist/modules/inline-edit/components/input-recipient.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input-toggle.client.mjs +1 -0
- package/dist/modules/inline-edit/components/input-toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/input.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/input.client.mjs +3 -0
- package/dist/modules/inline-edit/components/input.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/select.client.d.mts.map +1 -1
- package/dist/modules/inline-edit/components/select.client.mjs +1 -0
- package/dist/modules/inline-edit/components/select.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/switch.client.mjs +1 -0
- package/dist/modules/inline-edit/components/switch.client.mjs.map +1 -1
- package/dist/modules/inline-edit/components/toggle.client.mjs +1 -0
- package/dist/modules/inline-edit/components/toggle.client.mjs.map +1 -1
- package/dist/modules/inline-edit/lib/variants.d.mts +1 -1
- package/dist/modules/router/handler/context.server.d.mts +12 -10
- package/dist/modules/router/handler/context.server.d.mts.map +1 -1
- package/dist/modules/router/handler/init.server.d.mts +13 -11
- package/dist/modules/router/handler/init.server.d.mts.map +1 -1
- package/dist/modules/router/handler/init.server.mjs +2 -2
- package/dist/modules/router/handler/init.server.mjs.map +1 -1
- package/dist/modules/router/handler/route.server.d.mts +1 -1
- package/dist/modules/storage/components/dropzone.client.d.mts +2 -2
- package/dist/modules/storage/components/dropzone.client.d.mts.map +1 -1
- package/dist/modules/storage/components/dropzone.client.mjs.map +1 -1
- package/dist/modules/storage/components/image-grid.client.d.mts +3 -3
- package/dist/modules/storage/components/image-grid.client.d.mts.map +1 -1
- package/dist/modules/storage/components/image-grid.client.mjs +20 -22
- package/dist/modules/storage/components/image-grid.client.mjs.map +1 -1
- package/dist/modules/storage/components/image.client.d.mts +8 -0
- package/dist/modules/storage/components/image.client.d.mts.map +1 -0
- package/dist/modules/storage/components/image.client.mjs +17 -0
- package/dist/modules/storage/components/image.client.mjs.map +1 -0
- package/dist/modules/storage/components/upload-button.client.d.mts +12 -0
- package/dist/modules/storage/components/upload-button.client.d.mts.map +1 -0
- package/dist/modules/storage/components/upload-button.client.mjs +34 -0
- package/dist/modules/storage/components/upload-button.client.mjs.map +1 -0
- package/dist/modules/storage/components/upload-zone-context.client.d.mts +5 -5
- package/dist/modules/storage/components/upload-zone-context.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone-context.client.mjs +2 -2
- package/dist/modules/storage/components/upload-zone-context.client.mjs.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.d.mts +4 -4
- package/dist/modules/storage/components/upload-zone.client.d.mts.map +1 -1
- package/dist/modules/storage/components/upload-zone.client.mjs +16 -9
- package/dist/modules/storage/components/upload-zone.client.mjs.map +1 -1
- package/dist/modules/storage/lib/constants.d.mts +1 -5
- package/dist/modules/storage/lib/constants.d.mts.map +1 -1
- package/dist/modules/storage/lib/constants.mjs +1 -13
- package/dist/modules/storage/lib/constants.mjs.map +1 -1
- package/dist/modules/storage/lib/helpers.d.mts +14 -28
- package/dist/modules/storage/lib/helpers.d.mts.map +1 -1
- package/dist/modules/storage/lib/helpers.mjs +17 -75
- package/dist/modules/storage/lib/helpers.mjs.map +1 -1
- package/dist/modules/storage/lib/procedures.server.d.mts +1991 -0
- package/dist/modules/{auth/handler/init.d.mts.map → storage/lib/procedures.server.d.mts.map} +1 -1
- package/dist/modules/storage/lib/procedures.server.mjs +22 -0
- package/dist/modules/storage/lib/procedures.server.mjs.map +1 -0
- package/dist/modules/storage/lib/router-handlers.server.d.mts +41 -0
- package/dist/modules/storage/lib/router-handlers.server.d.mts.map +1 -0
- package/dist/modules/storage/lib/router-handlers.server.mjs +124 -0
- package/dist/modules/storage/lib/router-handlers.server.mjs.map +1 -0
- package/dist/modules/storage/lib/schema.d.mts +68 -958
- package/dist/modules/storage/lib/schema.d.mts.map +1 -1
- package/dist/modules/storage/lib/schema.mjs +28 -65
- package/dist/modules/storage/lib/schema.mjs.map +1 -1
- package/dist/modules/storage/lib/service.server.d.mts +2155 -141
- package/dist/modules/storage/lib/service.server.d.mts.map +1 -1
- package/dist/modules/storage/lib/service.server.mjs +453 -242
- package/dist/modules/storage/lib/service.server.mjs.map +1 -1
- package/dist/modules/storage/lib/upload.client.d.mts +58 -0
- package/dist/modules/storage/lib/upload.client.d.mts.map +1 -0
- package/dist/modules/storage/lib/upload.client.mjs +87 -0
- package/dist/modules/storage/lib/upload.client.mjs.map +1 -0
- package/dist/modules/storage/lib/validators.d.mts +297 -835
- package/dist/modules/storage/lib/validators.d.mts.map +1 -1
- package/dist/modules/storage/lib/validators.mjs +32 -76
- package/dist/modules/storage/lib/validators.mjs.map +1 -1
- package/dist/modules/storage/providers/adapters/s3.server.d.mts +19 -0
- package/dist/modules/storage/providers/adapters/s3.server.d.mts.map +1 -0
- package/dist/modules/storage/providers/adapters/s3.server.mjs +173 -0
- package/dist/modules/storage/providers/adapters/s3.server.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/constants.d.mts +6 -0
- package/dist/modules/storage/providers/lib/constants.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/constants.mjs +6 -0
- package/dist/modules/storage/providers/lib/constants.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/errors.d.mts +12 -0
- package/dist/modules/storage/providers/lib/errors.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/errors.mjs +13 -0
- package/dist/modules/storage/providers/lib/errors.mjs.map +1 -0
- package/dist/modules/storage/providers/lib/types.d.mts +21 -0
- package/dist/modules/storage/providers/lib/types.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/validators.d.mts +112 -0
- package/dist/modules/storage/providers/lib/validators.d.mts.map +1 -0
- package/dist/modules/storage/providers/lib/validators.mjs +75 -0
- package/dist/modules/storage/providers/lib/validators.mjs.map +1 -0
- package/dist/router/server.d.mts +1 -1
- package/dist/storage/client.d.mts +4 -2
- package/dist/storage/client.mjs +4 -2
- package/dist/storage/server.d.mts +5 -4
- package/dist/storage/server.mjs +5 -4
- package/dist/storage.d.mts +9 -6
- package/dist/storage.mjs +8 -6
- package/package.json +18 -5
- package/src/components/editor/components/editor.client.tsx +9 -1
- package/src/components/editor/extensions/file-handler/extension.ts +4 -4
- package/src/components/editor/extensions/file-handler/strategy.ts +15 -40
- package/src/components/editor/extensions/file-handler/utils.ts +1 -1
- package/src/components/editor/extensions/image/extension.ts +10 -10
- package/src/components/editor/lib/helpers.ts +28 -11
- package/src/components/ui/combobox-dropdown.client.tsx +1 -0
- package/src/components/ui/combobox.client.tsx +1 -1
- package/src/entry.ts +12 -51
- package/src/lib/entry.ts +1 -5
- package/src/lib/utils/markdown.ts +10 -0
- package/src/lib/utils/url.ts +2 -1
- package/src/lib/utils/user-agent.ts +15 -0
- package/src/modules/auth/components/{guard-first-user.server.tsx → create-first-user-guard.server.tsx} +8 -8
- package/src/modules/auth/components/guard.server.tsx +1 -1
- package/src/modules/auth/entry.server.ts +4 -5
- package/src/modules/auth/handler/create-client.client.ts +2 -2
- package/src/modules/auth/handler/proxy.server.ts +1 -1
- package/src/modules/auth/handler/route.server.ts +2 -2
- package/src/modules/auth/handler/{init.ts → service.server.ts} +30 -9
- package/src/modules/config/entry.server.ts +0 -9
- package/src/modules/config/entry.ts +2 -2
- package/src/modules/config/lib/context.ts +9 -9
- package/src/modules/data-tables/entry.client.ts +1 -0
- package/src/modules/data-tables/server/get-data.server.ts +1 -1
- package/src/modules/data-tables/strategies/infinite/strategy.ts +4 -1
- package/src/modules/data-tables/tables/data-table/components/row.tsx +12 -21
- package/src/modules/data-tables/tables/inline-table/components/body.tsx +1 -1
- package/src/modules/data-tables/tables/inline-table/components/row.client.tsx +24 -30
- package/src/modules/data-tables/tables/inline-table/components/table.tsx +6 -1
- package/src/modules/data-tables/tables/inline-table/hooks/context.client.tsx +5 -0
- package/src/modules/data-tables/tables/inline-table/hooks/use-hotkeys.client.ts +119 -91
- package/src/modules/database/entry.client.ts +0 -0
- package/src/modules/database/entry.server.ts +4 -0
- package/src/modules/database/entry.ts +5 -0
- package/src/modules/database/lib/service.server.ts +33 -0
- package/src/modules/emails/entry.client.ts +0 -0
- package/src/modules/emails/entry.server.ts +4 -0
- package/src/modules/emails/entry.ts +0 -0
- package/src/modules/emails/lib/service.server.ts +29 -0
- package/src/modules/inline-edit/components/date-input.client.tsx +1 -1
- package/src/modules/inline-edit/components/date-picker.client.tsx +1 -0
- package/src/modules/inline-edit/components/date-time.client.tsx +1 -0
- package/src/modules/inline-edit/components/editor.client.tsx +3 -0
- package/src/modules/inline-edit/components/input-recipient.client.tsx +1 -0
- package/src/modules/inline-edit/components/input-toggle.client.tsx +1 -0
- package/src/modules/inline-edit/components/input.client.tsx +3 -0
- package/src/modules/inline-edit/components/select.client.tsx +5 -1
- package/src/modules/inline-edit/components/switch.client.tsx +1 -0
- package/src/modules/inline-edit/components/toggle.client.tsx +1 -0
- package/src/modules/router/handler/init.server.ts +2 -2
- package/src/modules/storage/components/dropzone.client.tsx +1 -1
- package/src/modules/storage/components/image-grid.client.tsx +23 -20
- package/src/modules/storage/components/image.client.tsx +8 -0
- package/src/modules/storage/components/upload-zone-context.client.tsx +11 -8
- package/src/modules/storage/components/upload-zone.client.tsx +22 -16
- package/src/modules/storage/entry.client.ts +3 -1
- package/src/modules/storage/entry.server.ts +9 -3
- package/src/modules/storage/entry.ts +13 -1
- package/src/modules/storage/lib/constants.ts +0 -11
- package/src/modules/storage/lib/helpers.ts +18 -65
- package/src/modules/storage/lib/procedures.server.ts +60 -0
- package/src/modules/storage/lib/router-handlers.server.ts +178 -0
- package/src/modules/storage/lib/schema.ts +26 -97
- package/src/modules/storage/lib/service.server.ts +636 -374
- package/src/modules/storage/lib/upload.client.ts +156 -0
- package/src/modules/storage/lib/validators.ts +50 -111
- package/src/modules/storage/providers/adapters/s3.server.ts +281 -0
- package/src/modules/storage/providers/lib/constants.ts +3 -0
- package/src/modules/storage/providers/lib/errors.ts +21 -0
- package/src/modules/storage/providers/lib/types.ts +28 -0
- package/src/modules/storage/providers/lib/validators.ts +122 -0
- package/dist/lib/config/constants.d.mts +0 -5
- package/dist/lib/config/constants.d.mts.map +0 -1
- package/dist/lib/config/constants.mjs +0 -6
- package/dist/lib/config/constants.mjs.map +0 -1
- package/dist/modules/auth/components/guard-first-user.server.d.mts +0 -18
- package/dist/modules/auth/components/guard-first-user.server.d.mts.map +0 -1
- package/dist/modules/auth/components/guard-first-user.server.mjs +0 -16
- package/dist/modules/auth/components/guard-first-user.server.mjs.map +0 -1
- package/dist/modules/auth/handler/init.mjs.map +0 -1
- package/dist/modules/config/db/helpers.d.mts.map +0 -1
- package/dist/modules/config/db/helpers.mjs.map +0 -1
- package/dist/modules/config/db/init.d.mts +0 -20
- package/dist/modules/config/db/init.d.mts.map +0 -1
- package/dist/modules/config/db/init.mjs +0 -15
- package/dist/modules/config/db/init.mjs.map +0 -1
- package/dist/modules/config/db/types.d.mts.map +0 -1
- package/dist/modules/config/providers/email.d.mts +0 -12
- package/dist/modules/config/providers/email.d.mts.map +0 -1
- package/dist/modules/config/providers/email.mjs +0 -11
- package/dist/modules/config/providers/email.mjs.map +0 -1
- package/dist/modules/storage/config/filters.d.mts +0 -17
- package/dist/modules/storage/config/filters.d.mts.map +0 -1
- package/dist/modules/storage/config/filters.mjs +0 -17
- package/dist/modules/storage/config/filters.mjs.map +0 -1
- package/dist/modules/storage/lib/create-client.server.d.mts +0 -11
- package/dist/modules/storage/lib/create-client.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/create-client.server.mjs +0 -11
- package/dist/modules/storage/lib/create-client.server.mjs.map +0 -1
- package/dist/modules/storage/lib/create-upload.client.d.mts +0 -56
- package/dist/modules/storage/lib/create-upload.client.d.mts.map +0 -1
- package/dist/modules/storage/lib/create-upload.client.mjs +0 -98
- package/dist/modules/storage/lib/create-upload.client.mjs.map +0 -1
- package/dist/modules/storage/lib/proxy.server.d.mts +0 -21
- package/dist/modules/storage/lib/proxy.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/proxy.server.mjs +0 -46
- package/dist/modules/storage/lib/proxy.server.mjs.map +0 -1
- package/dist/modules/storage/lib/router.server.d.mts +0 -31002
- package/dist/modules/storage/lib/router.server.d.mts.map +0 -1
- package/dist/modules/storage/lib/router.server.mjs +0 -86
- package/dist/modules/storage/lib/router.server.mjs.map +0 -1
- package/src/lib/config/constants.ts +0 -1
- package/src/lib/utils/time-picker.ts +0 -139
- package/src/modules/config/db/init.ts +0 -21
- package/src/modules/config/providers/email.ts +0 -13
- package/src/modules/storage/config/filters.ts +0 -12
- package/src/modules/storage/lib/create-client.server.ts +0 -14
- package/src/modules/storage/lib/create-upload.client.ts +0 -134
- package/src/modules/storage/lib/proxy.server.ts +0 -63
- package/src/modules/storage/lib/router.server.ts +0 -182
- /package/src/modules/{config/db → database/lib}/helpers.ts +0 -0
- /package/src/modules/{config/db → database/lib}/types.ts +0 -0
|
@@ -1,304 +1,515 @@
|
|
|
1
1
|
import { ServerError } from "../../router/lib/error.server.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { nodePresignedUrls, nodeVariants, nodes } from "./schema.mjs";
|
|
9
|
-
import { getFileURLSchemaDefaults, getObjectSchema, putObjectSchema } from "./validators.mjs";
|
|
10
|
-
import { addSeconds } from "date-fns";
|
|
11
|
-
import { and, asc, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
|
12
|
-
import { after } from "next/server";
|
|
13
|
-
import { DeleteObjectsCommand, GetObjectCommand, PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
|
|
14
|
-
import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
|
|
2
|
+
import { generateDefaultUUID } from "../../database/lib/helpers.mjs";
|
|
3
|
+
import { storageAssets } from "./schema.mjs";
|
|
4
|
+
import { confirmUploadInputSchema, presignUploadInputSchema, uploadInputSchema } from "./validators.mjs";
|
|
5
|
+
import { StorageAdapterError } from "../providers/lib/errors.mjs";
|
|
6
|
+
import z from "zod";
|
|
7
|
+
import { and, desc, eq, inArray, isNotNull, isNull } from "drizzle-orm";
|
|
15
8
|
|
|
16
9
|
//#region src/modules/storage/lib/service.server.ts
|
|
17
10
|
/**
|
|
18
|
-
* Storage
|
|
11
|
+
* Storage service for working with asset metadata and object storage.
|
|
12
|
+
*
|
|
13
|
+
* Use `Storage.init()` to create a fully configured instance in app code.
|
|
14
|
+
*
|
|
15
|
+
* @param props - Storage configuration, including `db` and `adapter`
|
|
16
|
+
* @returns A ready-to-use `Storage` instance
|
|
17
|
+
* @example
|
|
18
|
+
* const storage = Storage.init({
|
|
19
|
+
* db: drizzle(dbConnection),
|
|
20
|
+
* adapter: new StorageS3Adapter({
|
|
21
|
+
* bucketName: "my-app-uploads",
|
|
22
|
+
* region: "us-east-1",
|
|
23
|
+
* credentials: {
|
|
24
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
25
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
26
|
+
* },
|
|
27
|
+
* }),
|
|
28
|
+
* });
|
|
19
29
|
*/
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
* S3 Client
|
|
23
|
-
*/
|
|
24
|
-
#blob;
|
|
30
|
+
var Storage = class Storage {
|
|
31
|
+
#adapter;
|
|
25
32
|
#db;
|
|
33
|
+
prefix;
|
|
34
|
+
constructor({ db, adapter, prefix }) {
|
|
35
|
+
this.#db = db;
|
|
36
|
+
this.#adapter = adapter;
|
|
37
|
+
this.prefix = prefix ?? "uploads";
|
|
38
|
+
}
|
|
26
39
|
/**
|
|
27
|
-
*
|
|
40
|
+
* Create a storage service instance.
|
|
41
|
+
*
|
|
42
|
+
* This keeps the public API aligned with other Tulip services such as
|
|
43
|
+
* `Database.init()`, `Email.init()`, and `Auth.init()`.
|
|
44
|
+
*
|
|
45
|
+
* @param props - Storage configuration, including `db` and `adapter`
|
|
46
|
+
* @returns A new `Storage` instance
|
|
47
|
+
* @example
|
|
48
|
+
* const storage = Storage.init({
|
|
49
|
+
* db: drizzle(dbConnection),
|
|
50
|
+
* adapter: new StorageS3Adapter({
|
|
51
|
+
* bucketName: "my-app-uploads",
|
|
52
|
+
* region: "us-east-1",
|
|
53
|
+
* credentials: {
|
|
54
|
+
* accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
55
|
+
* secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
56
|
+
* },
|
|
57
|
+
* }),
|
|
58
|
+
* });
|
|
28
59
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
this.#blob = new S3Client(config);
|
|
60
|
+
static init(props) {
|
|
61
|
+
return new Storage(props);
|
|
32
62
|
}
|
|
33
63
|
/**
|
|
34
|
-
*
|
|
64
|
+
* Generates the canonical object key for a storage asset id.
|
|
65
|
+
*
|
|
66
|
+
* This keeps bucket key structure internal to the storage service,
|
|
67
|
+
* so callers only work with asset ids and do not manage object paths.
|
|
68
|
+
*
|
|
69
|
+
* @param input - Storage asset id (UUID)
|
|
70
|
+
* @returns Canonical storage key (e.g. `uploads/<id>`)
|
|
71
|
+
* @example
|
|
72
|
+
* const key = this.#generateKey("019d0051-2c0d-741e-9e3c-e5a5bc4d16a2");
|
|
73
|
+
* // key => "uploads/019d0051-2c0d-741e-9e3c-e5a5bc4d16a2"
|
|
35
74
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
75
|
+
#generateKey(input) {
|
|
76
|
+
const id = z.uuid().parse(input);
|
|
77
|
+
return `${this.prefix}/${id}`;
|
|
38
78
|
}
|
|
39
79
|
/**
|
|
40
|
-
*
|
|
80
|
+
* Builds a query to fetch a storage asset by its ID and the current adapter's provider.
|
|
81
|
+
* @param id - The asset ID to search for
|
|
82
|
+
* @returns A dynamic Drizzle query for fetching a single asset
|
|
83
|
+
* @example
|
|
84
|
+
* let query = storageService.getAssetByIdQuery("asset-123");
|
|
85
|
+
* query = query.where(eq(storageAssets.contentType, "image/png")); // Add additional conditions if needed
|
|
86
|
+
* const [asset] = await query;
|
|
41
87
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return new GetObjectCommand({
|
|
45
|
-
Bucket: BUCKET_NAME,
|
|
46
|
-
Key: getDriveBucketKey(input.id, input.variant),
|
|
47
|
-
ResponseContentDisposition: input.disposition
|
|
48
|
-
});
|
|
88
|
+
getAssetByIdQuery(id) {
|
|
89
|
+
return this.#db.select().from(storageAssets).where(and(eq(storageAssets.id, id), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), isNull(storageAssets.deletedAt))).limit(1).$dynamic();
|
|
49
90
|
}
|
|
50
91
|
/**
|
|
51
|
-
*
|
|
92
|
+
* Fetches a storage asset by its ID.
|
|
93
|
+
* @param id - The asset ID to retrieve
|
|
94
|
+
* @returns The asset object if found, otherwise null
|
|
95
|
+
* @example
|
|
96
|
+
* const asset = await storageService.getAssetById("asset-123");
|
|
97
|
+
* if (asset) {
|
|
98
|
+
* console.log(asset.key, asset.contentType);
|
|
99
|
+
* }
|
|
52
100
|
*/
|
|
53
|
-
async
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
});
|
|
58
|
-
return await this.#blob.send(getCommand);
|
|
101
|
+
async getAssetById(id) {
|
|
102
|
+
const parsedId = z.uuid().parse(id);
|
|
103
|
+
const [asset] = await this.getAssetByIdQuery(parsedId);
|
|
104
|
+
return asset ?? null;
|
|
59
105
|
}
|
|
60
106
|
/**
|
|
61
|
-
*
|
|
107
|
+
* Builds a query to fetch a single ready storage asset by key
|
|
108
|
+
* within the current adapter provider scope.
|
|
109
|
+
*
|
|
110
|
+
* Notes:
|
|
111
|
+
* - Scoped to `this.#adapter.key` to avoid cross-provider leakage.
|
|
112
|
+
* - Targets ready assets by default.
|
|
113
|
+
* - Uniqueness is expected on `(provider, bucket, key)`.
|
|
114
|
+
*
|
|
115
|
+
* @param key - The object key stored in `storage_assets.key`
|
|
116
|
+
* @returns A dynamic Drizzle query returning max 1 row
|
|
117
|
+
* @example
|
|
118
|
+
* let query = storageService.getAssetByKeyQuery("uploads/abc/main");
|
|
119
|
+
* query = query.leftJoin(otherTable, eq(otherTable.assetId, storageAssets.id));
|
|
120
|
+
* const [asset] = await query;
|
|
62
121
|
*/
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return new PutObjectCommand({
|
|
66
|
-
Bucket: BUCKET_NAME,
|
|
67
|
-
Key: getDriveBucketKey(input.id, input.variant),
|
|
68
|
-
Body: input.body,
|
|
69
|
-
ContentType: input.contentType ?? void 0,
|
|
70
|
-
ContentLength: input.size ?? void 0,
|
|
71
|
-
Metadata: { nodeId: input.id }
|
|
72
|
-
});
|
|
122
|
+
getAssetByKeyQuery(key) {
|
|
123
|
+
return this.#db.select().from(storageAssets).where(and(eq(storageAssets.key, key), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), eq(storageAssets.status, "ready"), isNull(storageAssets.deletedAt))).limit(1).$dynamic();
|
|
73
124
|
}
|
|
74
125
|
/**
|
|
75
|
-
*
|
|
126
|
+
* Fetches a single ready storage asset by key.
|
|
127
|
+
*
|
|
128
|
+
* This is the convenience wrapper around `getAssetByKeyQuery`.
|
|
129
|
+
* Use this when you only need the result, not query composition.
|
|
130
|
+
*
|
|
131
|
+
* @param key - Asset key to look up
|
|
132
|
+
* @returns The matching asset or `null` if none is found
|
|
133
|
+
* @example
|
|
134
|
+
* const asset = await storageService.getAssetByKey("uploads/abc/main");
|
|
135
|
+
* if (!asset) return;
|
|
76
136
|
*/
|
|
77
|
-
async
|
|
78
|
-
const
|
|
79
|
-
return
|
|
137
|
+
async getAssetByKey(key) {
|
|
138
|
+
const [result] = await this.getAssetByKeyQuery(key);
|
|
139
|
+
return result ?? null;
|
|
80
140
|
}
|
|
81
141
|
/**
|
|
82
|
-
*
|
|
142
|
+
* Builds a base query for listing storage assets.
|
|
143
|
+
*
|
|
144
|
+
* Scope and defaults:
|
|
145
|
+
* - Scoped to the current adapter provider (`this.#adapter.key`)
|
|
146
|
+
* - Orders by newest first (`createdAt DESC`)
|
|
147
|
+
*
|
|
148
|
+
* This method returns a dynamic query so callers can extend it with
|
|
149
|
+
* custom filters, joins, pagination, and limits.
|
|
150
|
+
*
|
|
151
|
+
* @returns A dynamic Drizzle query for listing assets
|
|
152
|
+
* @example
|
|
153
|
+
* const query = storageService
|
|
154
|
+
* .listAssetsQuery()
|
|
155
|
+
* .limit(50);
|
|
156
|
+
* const assets = await query;
|
|
83
157
|
*/
|
|
84
|
-
|
|
85
|
-
return this.#db.select().from(
|
|
158
|
+
listAssetsQuery() {
|
|
159
|
+
return this.#db.select().from(storageAssets).where(and(eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), isNull(storageAssets.deletedAt))).orderBy(desc(storageAssets.createdAt)).$dynamic();
|
|
86
160
|
}
|
|
87
161
|
/**
|
|
88
|
-
*
|
|
162
|
+
* Lists storage assets using safe default pagination.
|
|
163
|
+
*
|
|
164
|
+
* This is the convenience wrapper around `listAssetsQuery`.
|
|
165
|
+
* Use `listAssetsQuery()` directly when you need custom query composition.
|
|
166
|
+
*
|
|
167
|
+
* @returns Up to 100 storage assets sorted by newest first
|
|
168
|
+
* @example
|
|
169
|
+
* const assets = await storageService.listAssets();
|
|
89
170
|
*/
|
|
90
|
-
async
|
|
91
|
-
|
|
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.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);
|
|
171
|
+
async listAssets() {
|
|
172
|
+
return await this.listAssetsQuery().limit(100) ?? [];
|
|
94
173
|
}
|
|
95
174
|
/**
|
|
96
|
-
*
|
|
175
|
+
* Creates a pending storage asset record and generates a presigned upload URL.
|
|
176
|
+
*
|
|
177
|
+
* Flow:
|
|
178
|
+
* - Validates the input payload
|
|
179
|
+
* - Inserts a `pending` asset in the catalog (`storage_assets`)
|
|
180
|
+
* - Requests a presigned PUT URL from the storage adapter
|
|
181
|
+
* - Marks the asset as `error` if URL generation fails
|
|
182
|
+
*
|
|
183
|
+
* This method is intended for direct-to-storage browser uploads.
|
|
184
|
+
* The upload should be finalized later via a confirm step.
|
|
185
|
+
*
|
|
186
|
+
* @param props - Presign upload input (contentType, size, metadata)
|
|
187
|
+
* @returns The created asset id, key, and presigned URL
|
|
188
|
+
* @throws {ServerError} If intent creation or URL generation fails
|
|
189
|
+
* @example
|
|
190
|
+
* const result = await storageService.presignUpload({
|
|
191
|
+
* contentType: "image/png",
|
|
192
|
+
* size: 120_000,
|
|
193
|
+
* metadata: { uploadToken: crypto.randomUUID() },
|
|
194
|
+
* });
|
|
195
|
+
* // result => { id, uploadId, key, presignedUrl }
|
|
97
196
|
*/
|
|
98
|
-
async
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
nodePresignedUrls.disposition
|
|
125
|
-
],
|
|
126
|
-
set: {
|
|
127
|
-
url,
|
|
128
|
-
expiresAt: addSeconds(/* @__PURE__ */ new Date(), expiresIn)
|
|
129
|
-
}
|
|
197
|
+
async presignUpload(props) {
|
|
198
|
+
const input = presignUploadInputSchema.parse(props);
|
|
199
|
+
const id = generateDefaultUUID();
|
|
200
|
+
const uploadId = input.uploadId ?? generateDefaultUUID();
|
|
201
|
+
const key = this.#generateKey(id);
|
|
202
|
+
const { contentType, size, metadata, name, visibility } = input;
|
|
203
|
+
const [record] = await this.#db.insert(storageAssets).values({
|
|
204
|
+
id,
|
|
205
|
+
uploadId,
|
|
206
|
+
key,
|
|
207
|
+
size,
|
|
208
|
+
contentType,
|
|
209
|
+
name,
|
|
210
|
+
visibility,
|
|
211
|
+
provider: this.#adapter.key,
|
|
212
|
+
bucket: this.#adapter.bucketName,
|
|
213
|
+
status: "pending",
|
|
214
|
+
metadata
|
|
215
|
+
}).returning();
|
|
216
|
+
if (!record) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Failed to create upload intent" });
|
|
217
|
+
try {
|
|
218
|
+
const presignedUrl = await this.#adapter.putObjectURL({
|
|
219
|
+
key,
|
|
220
|
+
contentType,
|
|
221
|
+
size,
|
|
222
|
+
metadata
|
|
130
223
|
});
|
|
131
|
-
|
|
132
|
-
|
|
224
|
+
return {
|
|
225
|
+
...record,
|
|
226
|
+
presignedUrl
|
|
227
|
+
};
|
|
228
|
+
} catch (error) {
|
|
229
|
+
await this.#db.update(storageAssets).set({ status: "error" }).where(eq(storageAssets.id, record.id));
|
|
230
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to generate upload URL" });
|
|
231
|
+
}
|
|
133
232
|
}
|
|
134
233
|
/**
|
|
135
|
-
*
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
234
|
+
* Confirms a direct-to-storage upload by verifying object existence
|
|
235
|
+
* and transitioning the asset from `pending` to `ready`.
|
|
236
|
+
*
|
|
237
|
+
* Flow:
|
|
238
|
+
* - Validates confirm input
|
|
239
|
+
* - Loads the asset record scoped to the current adapter provider
|
|
240
|
+
* - Returns early if asset is already `ready` (idempotent behavior)
|
|
241
|
+
* - Verifies object existence/metadata via `adapter.headObject`
|
|
242
|
+
* - Marks asset as `error` if verification fails
|
|
243
|
+
* - Updates status to `ready` and stores upload metadata
|
|
244
|
+
*
|
|
245
|
+
* @param props - Confirm upload payload containing the asset uploadId
|
|
246
|
+
* @returns The updated storage asset record
|
|
247
|
+
* @throws {ServerError} If the asset is missing, verification fails, or update fails
|
|
248
|
+
* @example
|
|
249
|
+
* const asset = await storageService.confirmUpload("019d0051-2c0d-741e-9e3c-e5a5bc4d16a2");
|
|
250
|
+
* // asset.status === "ready"
|
|
251
|
+
*/
|
|
252
|
+
async confirmUpload(props) {
|
|
253
|
+
const uploadId = confirmUploadInputSchema.parse(props);
|
|
254
|
+
const [record] = await this.#db.select().from(storageAssets).where(and(eq(storageAssets.uploadId, uploadId), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), isNull(storageAssets.deletedAt))).limit(1);
|
|
255
|
+
if (!record) throw new ServerError("NOT_FOUND", { message: "Storage asset not found" });
|
|
256
|
+
if (record.status === "ready") return record;
|
|
257
|
+
let head;
|
|
258
|
+
try {
|
|
259
|
+
head = await this.#adapter.headObject({ key: record.key });
|
|
260
|
+
} catch (error) {
|
|
261
|
+
await this.#db.update(storageAssets).set({ status: "error" }).where(eq(storageAssets.id, record.id));
|
|
262
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to verify uploaded object" });
|
|
263
|
+
}
|
|
264
|
+
const [updated] = await this.#db.update(storageAssets).set({
|
|
265
|
+
status: "ready",
|
|
266
|
+
uploadedAt: /* @__PURE__ */ new Date(),
|
|
267
|
+
size: head.size ?? record.size,
|
|
268
|
+
contentType: head.contentType ?? record.contentType
|
|
269
|
+
}).where(and(eq(storageAssets.id, record.id), eq(storageAssets.status, "pending"))).returning();
|
|
270
|
+
if (!updated) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Failed to confirm upload" });
|
|
271
|
+
return updated;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Uploads an asset directly from the server and persists its catalog record.
|
|
275
|
+
*
|
|
276
|
+
* Flow:
|
|
277
|
+
* - Validates upload input
|
|
278
|
+
* - Creates a `pending` asset record in `storage_assets`
|
|
279
|
+
* - Uploads the object bytes through the storage adapter
|
|
280
|
+
* - Marks the record as `ready` and stores upload metadata
|
|
281
|
+
* - Marks the record as `error` if upload fails
|
|
282
|
+
*
|
|
283
|
+
* This method is intended for server-side uploads (non-presigned flow).
|
|
284
|
+
* For browser direct uploads, use `presignUpload` + `confirmUpload`.
|
|
285
|
+
*
|
|
286
|
+
* @param props - Upload payload (body, contentType, size)
|
|
287
|
+
* @returns The finalized storage asset record
|
|
288
|
+
* @throws {ServerError} If record creation, upload, or finalization fails
|
|
289
|
+
* @example
|
|
290
|
+
* const asset = await storageService.upload({
|
|
291
|
+
* body: fileBuffer,
|
|
292
|
+
* contentType: "application/pdf",
|
|
293
|
+
* size: fileBuffer.byteLength,
|
|
294
|
+
* });
|
|
295
|
+
*/
|
|
296
|
+
async upload(props) {
|
|
297
|
+
const { body, contentType, size, metadata, name, visibility } = uploadInputSchema.parse(props);
|
|
298
|
+
const id = generateDefaultUUID();
|
|
299
|
+
const key = this.#generateKey(id);
|
|
300
|
+
const [record] = await this.#db.insert(storageAssets).values({
|
|
301
|
+
id,
|
|
302
|
+
key,
|
|
303
|
+
size,
|
|
304
|
+
contentType,
|
|
305
|
+
name,
|
|
306
|
+
visibility,
|
|
307
|
+
provider: this.#adapter.key,
|
|
308
|
+
bucket: this.#adapter.bucketName,
|
|
309
|
+
status: "pending",
|
|
310
|
+
metadata
|
|
311
|
+
}).returning();
|
|
312
|
+
if (!record) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Failed to create upload record" });
|
|
313
|
+
try {
|
|
314
|
+
const uploaded = await this.#adapter.putObject({
|
|
315
|
+
key,
|
|
316
|
+
body,
|
|
317
|
+
contentType,
|
|
318
|
+
size,
|
|
319
|
+
metadata
|
|
159
320
|
});
|
|
160
|
-
|
|
321
|
+
const [updated] = await this.#db.update(storageAssets).set({
|
|
322
|
+
status: "ready",
|
|
323
|
+
uploadedAt: /* @__PURE__ */ new Date(),
|
|
324
|
+
size: uploaded.size ?? size ?? record.size,
|
|
325
|
+
contentType: uploaded.contentType ?? contentType ?? record.contentType
|
|
326
|
+
}).where(and(eq(storageAssets.id, record.id), eq(storageAssets.status, "pending"))).returning();
|
|
327
|
+
if (!updated) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Failed to finalize upload" });
|
|
328
|
+
return updated;
|
|
329
|
+
} catch (error) {
|
|
330
|
+
await this.#db.update(storageAssets).set({ status: "error" }).where(and(eq(storageAssets.id, record.id), eq(storageAssets.status, "pending")));
|
|
331
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to upload object" });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Retrieves the object content for a ready storage asset.
|
|
336
|
+
*
|
|
337
|
+
* Flow:
|
|
338
|
+
* - Looks up the asset record by id, scoped to the current adapter provider
|
|
339
|
+
* - Ensures the asset is in `ready` status
|
|
340
|
+
* - Fetches object content from the storage adapter using the stored key
|
|
341
|
+
*
|
|
342
|
+
* @param id - The storage asset id
|
|
343
|
+
* @returns The adapter object response (stream/body + metadata)
|
|
344
|
+
* @throws {ServerError} If the asset does not exist or is not ready
|
|
345
|
+
* @example
|
|
346
|
+
* const object = await storageService.getObject("asset-123");
|
|
347
|
+
* // object.body can be streamed/consumed by caller
|
|
348
|
+
*/
|
|
349
|
+
async getObject(input) {
|
|
350
|
+
const id = z.uuid().parse(input);
|
|
351
|
+
const [record] = await this.#db.select().from(storageAssets).where(and(eq(storageAssets.id, id), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), eq(storageAssets.status, "ready"), isNull(storageAssets.deletedAt))).limit(1);
|
|
352
|
+
if (!record) throw new ServerError("NOT_FOUND", { message: "Storage asset not found" });
|
|
353
|
+
return this.#adapter.getObject(record.key).catch((error) => {
|
|
354
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to retrieve object" });
|
|
161
355
|
});
|
|
162
356
|
}
|
|
163
357
|
/**
|
|
164
|
-
*
|
|
358
|
+
* Generates a presigned read URL for a ready storage asset.
|
|
359
|
+
*
|
|
360
|
+
* Flow:
|
|
361
|
+
* - Validates the asset id
|
|
362
|
+
* - Resolves the asset record scoped to the current adapter provider
|
|
363
|
+
* - Ensures the asset is in `ready` status
|
|
364
|
+
* - Delegates URL signing to the storage adapter using the stored key
|
|
365
|
+
*
|
|
366
|
+
* @param input - Storage asset id (UUID)
|
|
367
|
+
* @param options - Optional URL options (for example expiration/disposition)
|
|
368
|
+
* @returns A presigned URL for reading the object
|
|
369
|
+
* @throws {ServerError} If the asset does not exist or is not ready
|
|
370
|
+
* @example
|
|
371
|
+
* const url = await storageService.getObjectURL("019d0051-2c0d-741e-9e3c-e5a5bc4d16a2", {
|
|
372
|
+
* expiresIn: 3600,
|
|
373
|
+
* });
|
|
165
374
|
*/
|
|
166
|
-
async
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
size: input.size
|
|
375
|
+
async getObjectURL(input, options) {
|
|
376
|
+
const id = z.uuid().parse(input);
|
|
377
|
+
const [record] = await this.#db.select().from(storageAssets).where(and(eq(storageAssets.id, id), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), eq(storageAssets.status, "ready"), isNull(storageAssets.deletedAt))).limit(1);
|
|
378
|
+
if (!record) throw new ServerError("NOT_FOUND", { message: "Storage asset not found" });
|
|
379
|
+
return this.#adapter.getObjectURL(record.key, options).catch((error) => {
|
|
380
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to generate object URL" });
|
|
173
381
|
});
|
|
174
|
-
const presignedUrl = await getSignedUrl(this.#blob, putCommand, { expiresIn: 3600 });
|
|
175
|
-
const [node] = await this.#db.insert(nodes).values({
|
|
176
|
-
...input,
|
|
177
|
-
subtype: inferNodeSubtype(input),
|
|
178
|
-
isPending: true,
|
|
179
|
-
type: "file",
|
|
180
|
-
id: input.id
|
|
181
|
-
}).returning();
|
|
182
|
-
if (!node) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Oep! Er is iets fout gegaan" });
|
|
183
|
-
return {
|
|
184
|
-
id: input.id,
|
|
185
|
-
presignedUrl,
|
|
186
|
-
node
|
|
187
|
-
};
|
|
188
382
|
}
|
|
189
383
|
/**
|
|
190
|
-
*
|
|
384
|
+
* Soft deletes a single storage asset by id.
|
|
385
|
+
*
|
|
386
|
+
* This is a convenience wrapper around `deleteAssets`.
|
|
387
|
+
*
|
|
388
|
+
* @param input - Storage asset id (UUID)
|
|
389
|
+
* @returns The soft-deleted asset record, or null if not found/already deleted
|
|
191
390
|
*/
|
|
192
|
-
async
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
* Generate the preview version of the file
|
|
197
|
-
*/
|
|
198
|
-
await this.generatePreviews(input);
|
|
199
|
-
return result;
|
|
391
|
+
async deleteAsset(input) {
|
|
392
|
+
const id = z.uuid().parse(input);
|
|
393
|
+
const [deleted] = await this.deleteAssets([id]);
|
|
394
|
+
return deleted ?? null;
|
|
200
395
|
}
|
|
201
396
|
/**
|
|
202
|
-
*
|
|
397
|
+
* Soft deletes multiple storage assets by setting `deletedAt`.
|
|
398
|
+
*
|
|
399
|
+
* Flow:
|
|
400
|
+
* - Validates and de-duplicates ids
|
|
401
|
+
* - Resolves provider-scoped active records
|
|
402
|
+
* - Marks matching rows as deleted by setting `deletedAt`
|
|
403
|
+
*
|
|
404
|
+
* @param input - Storage asset ids (UUID[])
|
|
405
|
+
* @returns Soft-deleted asset records
|
|
203
406
|
*/
|
|
204
|
-
async
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*/
|
|
208
|
-
const getCommand = this.#createGetCommand({
|
|
209
|
-
id: input.id,
|
|
210
|
-
variant: "main"
|
|
211
|
-
});
|
|
212
|
-
const response = await this.#blob.send(getCommand);
|
|
213
|
-
const contentType = response.ContentType;
|
|
214
|
-
if (!response.Body) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Oep! Er is iets fout gegaan" });
|
|
215
|
-
/**
|
|
216
|
-
* Transform the main version of the file to a buffer
|
|
217
|
-
*/
|
|
218
|
-
const byteArray = await response.Body.transformToByteArray();
|
|
219
|
-
const buffer = Buffer.from(byteArray);
|
|
220
|
-
/**
|
|
221
|
-
* Generate the preview versions for images
|
|
222
|
-
*/
|
|
223
|
-
if (contentType?.startsWith("image/")) {
|
|
224
|
-
const sharp = await import("sharp");
|
|
225
|
-
await Promise.allSettled(deviceSizes.flatMap(async (width) => {
|
|
226
|
-
const preview = await sharp.default(buffer).resize({ width }).webp().toBuffer();
|
|
227
|
-
return this.#db.transaction(async (tx) => {
|
|
228
|
-
await this.#putObject({
|
|
229
|
-
id: input.id,
|
|
230
|
-
body: preview,
|
|
231
|
-
variant: `preview-${width}`,
|
|
232
|
-
contentType: "image/webp",
|
|
233
|
-
size: preview.byteLength
|
|
234
|
-
});
|
|
235
|
-
await tx.insert(nodeVariants).values({
|
|
236
|
-
nodeId: input.id,
|
|
237
|
-
variant: `preview-${width}`,
|
|
238
|
-
width
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
}));
|
|
242
|
-
}
|
|
407
|
+
async deleteAssets(input) {
|
|
408
|
+
const ids = [...new Set(z.array(z.uuid()).parse(input))];
|
|
409
|
+
if (ids.length === 0) return [];
|
|
410
|
+
return this.#db.update(storageAssets).set({ deletedAt: /* @__PURE__ */ new Date() }).where(and(inArray(storageAssets.id, ids), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), isNull(storageAssets.deletedAt))).returning();
|
|
243
411
|
}
|
|
244
412
|
/**
|
|
245
|
-
*
|
|
413
|
+
* Restores a single soft-deleted storage asset.
|
|
414
|
+
*
|
|
415
|
+
* This is a convenience wrapper around `restoreAssets`.
|
|
416
|
+
*
|
|
417
|
+
* @param input - Storage asset id (UUID)
|
|
418
|
+
* @returns The restored asset record, or null if not found/not deleted
|
|
246
419
|
*/
|
|
247
|
-
async
|
|
248
|
-
const
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}).returning();
|
|
262
|
-
if (!result) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Folder kon niet worden aangemaakt" });
|
|
263
|
-
return result;
|
|
420
|
+
async restoreAsset(input) {
|
|
421
|
+
const id = z.uuid().parse(input);
|
|
422
|
+
const [restored] = await this.restoreAssets([id]);
|
|
423
|
+
return restored ?? null;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Restores multiple soft-deleted storage assets by clearing `deletedAt`.
|
|
427
|
+
*
|
|
428
|
+
* @param input - Storage asset ids (UUID[])
|
|
429
|
+
* @returns Restored asset records
|
|
430
|
+
*/
|
|
431
|
+
async restoreAssets(input) {
|
|
432
|
+
const ids = [...new Set(z.array(z.uuid()).parse(input))];
|
|
433
|
+
if (ids.length === 0) return [];
|
|
434
|
+
return this.#db.update(storageAssets).set({ deletedAt: null }).where(and(inArray(storageAssets.id, ids), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName), isNotNull(storageAssets.deletedAt))).returning();
|
|
264
435
|
}
|
|
265
436
|
/**
|
|
266
|
-
*
|
|
437
|
+
* Hard deletes a single storage asset.
|
|
438
|
+
*
|
|
439
|
+
* This is a convenience wrapper around `purgeAssets`.
|
|
440
|
+
*
|
|
441
|
+
* @param input - Storage asset id (UUID)
|
|
442
|
+
* @returns The purged asset record, or null if not found
|
|
267
443
|
*/
|
|
268
|
-
async
|
|
269
|
-
const
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
if (!result) throw new ServerError("INTERNAL_SERVER_ERROR", { message: "Node kon niet worden gewijzigd" });
|
|
273
|
-
return result;
|
|
444
|
+
async purgeAsset(input) {
|
|
445
|
+
const id = z.uuid().parse(input);
|
|
446
|
+
const [deleted] = await this.purgeAssets([id]);
|
|
447
|
+
return deleted ?? null;
|
|
274
448
|
}
|
|
275
449
|
/**
|
|
276
|
-
*
|
|
450
|
+
* Hard deletes multiple storage assets.
|
|
451
|
+
*
|
|
452
|
+
* Flow:
|
|
453
|
+
* - Validates and de-duplicates ids
|
|
454
|
+
* - Resolves provider-scoped records
|
|
455
|
+
* - Deletes physical objects from the adapter by key
|
|
456
|
+
* - Hard deletes DB records
|
|
457
|
+
*
|
|
458
|
+
* @param input - Storage asset ids (UUID[])
|
|
459
|
+
* @returns Purged asset records
|
|
460
|
+
* @throws {ServerError} If provider deletion fails
|
|
277
461
|
*/
|
|
278
|
-
async
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
462
|
+
async purgeAssets(input) {
|
|
463
|
+
const ids = [...new Set(z.array(z.uuid()).parse(input))];
|
|
464
|
+
if (ids.length === 0) return [];
|
|
465
|
+
const records = await this.#db.select({
|
|
466
|
+
id: storageAssets.id,
|
|
467
|
+
key: storageAssets.key
|
|
468
|
+
}).from(storageAssets).where(and(inArray(storageAssets.id, ids), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName)));
|
|
469
|
+
if (records.length === 0) return [];
|
|
470
|
+
const keys = records.map((r) => r.key);
|
|
471
|
+
try {
|
|
472
|
+
await this.#adapter.deleteObjects(keys);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
throw this.#parseError(error, { fallbackMessage: "Failed to delete storage objects" });
|
|
475
|
+
}
|
|
476
|
+
const deletedIds = records.map((r) => r.id);
|
|
477
|
+
return await this.#db.delete(storageAssets).where(and(inArray(storageAssets.id, deletedIds), eq(storageAssets.provider, this.#adapter.key), eq(storageAssets.bucket, this.#adapter.bucketName))).returning();
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Normalizes unknown adapter/service errors into a consistent `ServerError`.
|
|
481
|
+
*
|
|
482
|
+
* Behavior:
|
|
483
|
+
* - Returns existing `ServerError` instances unchanged
|
|
484
|
+
* - Maps known storage adapter errors to application-level server errors
|
|
485
|
+
* - Falls back to a generic internal server error for unknown failures
|
|
486
|
+
*
|
|
487
|
+
* This keeps adapter-specific errors inside the storage layer while exposing
|
|
488
|
+
* a stable error contract to route handlers and RPC procedures.
|
|
489
|
+
*
|
|
490
|
+
* @param error - The unknown error to normalize
|
|
491
|
+
* @param options - Optional fallback message for non-specific failures
|
|
492
|
+
* @returns A normalized `ServerError`
|
|
493
|
+
*/
|
|
494
|
+
#parseError(error, options) {
|
|
495
|
+
if (error instanceof ServerError) return error;
|
|
496
|
+
if (error instanceof StorageAdapterError) {
|
|
497
|
+
if (error.code === "OBJECT_NOT_FOUND") return new ServerError("NOT_FOUND", {
|
|
498
|
+
message: "Storage asset not found",
|
|
499
|
+
cause: error
|
|
500
|
+
});
|
|
501
|
+
return new ServerError("INTERNAL_SERVER_ERROR", {
|
|
502
|
+
message: options?.fallbackMessage ?? "Storage adapter error",
|
|
503
|
+
cause: error
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
return new ServerError("INTERNAL_SERVER_ERROR", {
|
|
507
|
+
message: options?.fallbackMessage ?? "Unknown storage error",
|
|
508
|
+
cause: error instanceof Error ? error : void 0
|
|
298
509
|
});
|
|
299
510
|
}
|
|
300
511
|
};
|
|
301
512
|
|
|
302
513
|
//#endregion
|
|
303
|
-
export {
|
|
514
|
+
export { Storage };
|
|
304
515
|
//# sourceMappingURL=service.server.mjs.map
|