opacacms 0.2.0 → 0.3.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.
Files changed (187) hide show
  1. package/README.md +31 -22
  2. package/dist/admin/auth-client.d.ts +39 -39
  3. package/dist/admin/index.d.ts +2 -2
  4. package/dist/admin/index.js +15 -10520
  5. package/dist/admin/plugin-client.d.ts +65 -0
  6. package/dist/admin/react.d.ts +2 -2
  7. package/dist/admin/react.js +34 -4
  8. package/dist/admin/stores/ui.d.ts +19 -4
  9. package/dist/admin/ui/components/PluginSettingsForm.d.ts +2 -2
  10. package/dist/admin/ui/components/custom-alert.d.ts +7 -0
  11. package/dist/admin/ui/components/{DetailSheet.d.ts → detail-sheet.d.ts} +1 -2
  12. package/dist/admin/ui/components/fields/FieldLabel.d.ts +1 -1
  13. package/dist/admin/ui/components/fields/RelationshipField.d.ts +1 -1
  14. package/dist/admin/ui/components/media/AssetManagerModal.d.ts +2 -2
  15. package/dist/admin/ui/components/plugin-iframe.d.ts +7 -0
  16. package/dist/admin/ui/components/ui/accordion.d.ts +17 -7
  17. package/dist/admin/ui/components/ui/alert-dialog.d.ts +16 -12
  18. package/dist/admin/ui/components/ui/button.d.ts +11 -7
  19. package/dist/admin/ui/components/ui/relationship.d.ts +1 -1
  20. package/dist/admin/ui/components/ui/sheet.d.ts +14 -27
  21. package/dist/admin/ui/components/ui/tooltip.d.ts +7 -0
  22. package/dist/admin/ui/components/versions-sheet.d.ts +4 -5
  23. package/dist/admin/ui/views/collection-list-view.d.ts +1 -1
  24. package/dist/admin/ui/views/dashboard-view.d.ts +1 -1
  25. package/dist/admin/ui/views/media-registry-view.d.ts +3 -3
  26. package/dist/admin/ui/views/settings-view.d.ts +2 -2
  27. package/dist/admin/vue.js +27 -4
  28. package/dist/admin/webcomponent.js +20 -2
  29. package/dist/admin.css +1 -1
  30. package/dist/auth/index.d.ts +43 -43
  31. package/dist/{chunk-7y1nbmw6.js → chunk-1bd7fz7n.js} +32 -2
  32. package/dist/chunk-1qm0m8r8.js +413 -0
  33. package/dist/chunk-2k3ysje3.js +31 -0
  34. package/dist/chunk-3j9zjfmn.js +376 -0
  35. package/dist/{chunk-byq8g0rd.js → chunk-48ywpd0a.js} +16 -22
  36. package/dist/{chunk-esrg9qj0.js → chunk-5422w4eq.js} +70 -54
  37. package/dist/chunk-56n342hs.js +95 -0
  38. package/dist/chunk-5b8r0v8c.js +47 -0
  39. package/dist/chunk-63yg00vx.js +263 -0
  40. package/dist/{chunk-8sqjbsgt.js → chunk-6bywt602.js} +26 -1
  41. package/dist/{chunk-v9z61v3g.js → chunk-6qs0g65f.js} +43 -3
  42. package/dist/chunk-7rr5p01g.js +581 -0
  43. package/dist/{chunk-51z3x7kq.js → chunk-a3qae86h.js} +1 -1
  44. package/dist/{chunk-3rdhbedb.js → chunk-adq2b75c.js} +2 -2
  45. package/dist/chunk-d0tb1xjw.js +93 -0
  46. package/dist/chunk-d7cgd6vn.js +318 -0
  47. package/dist/{chunk-0bq155dy.js → chunk-e0g6gn7n.js} +89 -100
  48. package/dist/chunk-ec4jhybj.js +1137 -0
  49. package/dist/chunk-fatyf6f7.js +221 -0
  50. package/dist/{chunk-526a3gqx.js → chunk-fnsf1dfm.js} +1 -1
  51. package/dist/chunk-g9bxb6h0.js +205 -0
  52. package/dist/chunk-gyaf5kgf.js +10 -0
  53. package/dist/{chunk-9kxpbcb1.js → chunk-h6dhexzr.js} +16 -7
  54. package/dist/{chunk-dykn5hr6.js → chunk-j8js1y0h.js} +31 -74
  55. package/dist/{chunk-t0zg026p.js → chunk-jq1drsen.js} +12 -1
  56. package/dist/{chunk-b3kr8w41.js → chunk-m24yqkeq.js} +38 -26
  57. package/dist/chunk-m5ems3hh.js +410 -0
  58. package/dist/{chunk-8scgdznr.js → chunk-m83ybzf8.js} +15 -18
  59. package/dist/chunk-majsbncm.js +98 -0
  60. package/dist/chunk-mp2gt9yh.js +237 -0
  61. package/dist/chunk-n1twhqmf.js +54 -0
  62. package/dist/{chunk-gmee4mdc.js → chunk-naqcqj8n.js} +92 -106
  63. package/dist/chunk-q5sb5dcr.js +15 -0
  64. package/dist/{chunk-d1asgtke.js → chunk-qhdsjek6.js} +90 -121
  65. package/dist/{chunk-0gtxnxmd.js → chunk-qsh2nqz3.js} +85 -105
  66. package/dist/chunk-r0ms5tk1.js +76 -0
  67. package/dist/chunk-rwqwsanx.js +75 -0
  68. package/dist/chunk-sqsfk9p4.js +700 -0
  69. package/dist/{chunk-5gvbp2qa.js → chunk-x7bnzswh.js} +25 -18
  70. package/dist/{chunk-kc4jfnv7.js → chunk-z3ffn2b7.js} +851 -324
  71. package/dist/cli/commands/dev.d.ts +8 -0
  72. package/dist/cli/commands/doctor.d.ts +8 -0
  73. package/dist/cli/commands/generate.d.ts +26 -0
  74. package/dist/cli/commands/init.d.ts +13 -1
  75. package/dist/cli/commands/migrate.d.ts +33 -0
  76. package/dist/cli/commands/plugin.d.ts +13 -0
  77. package/dist/cli/commands/seed.d.ts +21 -0
  78. package/dist/cli/{commands/migrate-commands.d.ts → core/migrations/migrate-logic.d.ts} +2 -2
  79. package/dist/cli/core/migrations/schema-diff-engine.d.ts +12 -0
  80. package/dist/cli/core/migrations/schema-diff.d.ts +11 -0
  81. package/dist/cli/{seeding.d.ts → core/seeding/auto-seed.d.ts} +7 -4
  82. package/dist/cli/core/seeding/seed-logic.d.ts +2 -0
  83. package/dist/cli/index.d.ts +4 -0
  84. package/dist/cli/index.js +6 -170
  85. package/dist/client/RichText.d.ts +5 -0
  86. package/dist/client/rich-text-utils.d.ts +5 -0
  87. package/dist/client.js +3 -2
  88. package/dist/config.d.ts +3 -3
  89. package/dist/db/adapter.d.ts +2 -2
  90. package/dist/db/better-sqlite.d.ts +3 -3
  91. package/dist/db/better-sqlite.js +6 -5
  92. package/dist/db/bun-sqlite.d.ts +3 -3
  93. package/dist/db/bun-sqlite.js +6 -5
  94. package/dist/db/d1.d.ts +13 -7
  95. package/dist/db/d1.js +6 -5
  96. package/dist/db/index.d.ts +2 -2
  97. package/dist/db/index.js +10 -12
  98. package/dist/db/kysely/factory.d.ts +29 -0
  99. package/dist/db/kysely/plugins/audit-logging.d.ts +48 -0
  100. package/dist/db/kysely/plugins/auto-timestamps.d.ts +38 -0
  101. package/dist/db/kysely/plugins/cursor-pagination.d.ts +42 -0
  102. package/dist/db/kysely/plugins/deadlock-handler.d.ts +47 -0
  103. package/dist/db/kysely/plugins/draft-swapper.d.ts +33 -0
  104. package/dist/db/kysely/plugins/field-masking.d.ts +45 -0
  105. package/dist/db/kysely/plugins/fts-normalizer.d.ts +38 -0
  106. package/dist/db/kysely/plugins/i18n-fallback.d.ts +48 -0
  107. package/dist/db/kysely/plugins/id-generation.d.ts +42 -0
  108. package/dist/db/kysely/plugins/index.d.ts +16 -0
  109. package/dist/db/kysely/plugins/json-flattener.d.ts +38 -0
  110. package/dist/db/kysely/plugins/relationship-preloading.d.ts +39 -0
  111. package/dist/db/kysely/plugins/slug-generation.d.ts +37 -0
  112. package/dist/db/kysely/plugins/soft-delete.d.ts +42 -0
  113. package/dist/db/kysely/plugins/tree-resolver.d.ts +39 -0
  114. package/dist/db/kysely/plugins/virtual-field-resolver.d.ts +54 -0
  115. package/dist/db/kysely/plugins/zod-coercion.d.ts +34 -0
  116. package/dist/db/kysely/snapshot/snapshot-manager.d.ts +18 -0
  117. package/dist/db/postgres.d.ts +4 -4
  118. package/dist/db/postgres.js +6 -5
  119. package/dist/db/sqlite.d.ts +3 -3
  120. package/dist/db/sqlite.js +6 -5
  121. package/dist/index.d.ts +3 -0
  122. package/dist/index.js +161 -7
  123. package/dist/runtimes/bun.js +9 -6
  124. package/dist/runtimes/cloudflare-workers.d.ts +3 -1
  125. package/dist/runtimes/cloudflare-workers.js +36 -7
  126. package/dist/runtimes/next.js +8 -5
  127. package/dist/runtimes/node.js +9 -6
  128. package/dist/schema/collection.d.ts +116 -70
  129. package/dist/schema/compiler.d.ts +6 -0
  130. package/dist/schema/global.d.ts +38 -71
  131. package/dist/schema/index.d.ts +5 -4
  132. package/dist/schema/index.js +35 -550
  133. package/dist/schema/zod.d.ts +564 -0
  134. package/dist/server/admin-router.d.ts +1 -1
  135. package/dist/server/collection-router.d.ts +1 -1
  136. package/dist/server/graphql.d.ts +6 -0
  137. package/dist/server/handlers.d.ts +25 -7
  138. package/dist/server/middlewares/auth.d.ts +1 -1
  139. package/dist/server/plugins-loader.d.ts +1 -1
  140. package/dist/server/router.d.ts +2 -2
  141. package/dist/server/routers/admin.d.ts +1 -1
  142. package/dist/server/routers/auth.d.ts +1 -1
  143. package/dist/server/routers/collections.d.ts +4 -1
  144. package/dist/server/routers/plugins.d.ts +2 -2
  145. package/dist/server/setup-middlewares.d.ts +1 -1
  146. package/dist/server/system-router.d.ts +1 -1
  147. package/dist/server.js +11 -6
  148. package/dist/storage/adapters/cloudflare-r2.d.ts +11 -2
  149. package/dist/storage/index.js +39 -30
  150. package/dist/types.d.ts +255 -44
  151. package/dist/utils/context.d.ts +14 -0
  152. package/dist/utils/logger.d.ts +2 -0
  153. package/dist/utils/string.d.ts +10 -0
  154. package/dist/utils/webhooks-engine.d.ts +24 -0
  155. package/dist/validation.d.ts +67 -1
  156. package/dist/validator.d.ts +1 -0
  157. package/package.json +36 -33
  158. package/src/cli/index.ts +117 -0
  159. package/dist/chunk-6qq3ne6b.js +0 -288
  160. package/dist/chunk-6v1fw7q7.js +0 -126
  161. package/dist/chunk-7a9kn0np.js +0 -116
  162. package/dist/chunk-bexcv7xe.js +0 -36
  163. package/dist/chunk-d3ffeqp9.js +0 -87
  164. package/dist/chunk-fj19qccp.js +0 -78
  165. package/dist/chunk-j53pz21t.js +0 -20
  166. package/dist/chunk-mkn49zmy.js +0 -102
  167. package/dist/chunk-qb6ztvw9.js +0 -17
  168. package/dist/chunk-r39em4yj.js +0 -29
  169. package/dist/chunk-rsf0tpy1.js +0 -8
  170. package/dist/chunk-srsac177.js +0 -85
  171. package/dist/chunk-swtcpvhf.js +0 -2442
  172. package/dist/chunk-twpvxfce.js +0 -64
  173. package/dist/chunk-ywm4t2gm.js +0 -19
  174. package/dist/cli/commands/plugin-sync.d.ts +0 -1
  175. package/dist/cli/commands/seed-command.d.ts +0 -2
  176. package/dist/plugins/ui-bridge.d.ts +0 -12
  177. package/dist/schema/fields/base.d.ts +0 -84
  178. package/dist/schema/fields/index.d.ts +0 -147
  179. package/dist/schema/infer.d.ts +0 -55
  180. /package/dist/admin/ui/components/{ColumnVisibilityToggle.d.ts → column-visibility-toggle.d.ts} +0 -0
  181. /package/dist/admin/ui/components/{DataDetailView.d.ts → data-detail-view.d.ts} +0 -0
  182. /package/dist/cli/{d1-mock.d.ts → core/mocks/d1-mock.d.ts} +0 -0
  183. /package/dist/cli/{r2-mock.d.ts → core/mocks/r2-mock.d.ts} +0 -0
  184. /package/dist/cli/{commands → core/plugins}/plugin-build.d.ts +0 -0
  185. /package/dist/cli/{commands → core/plugins}/plugin-init.d.ts +0 -0
  186. /package/dist/cli/{commands → core/types}/generate-types.d.ts +0 -0
  187. /package/dist/{schema/fields/validation.test.d.ts → cli/seeding.test.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { Context } from "hono";
2
- import type { Collection, Global, OpacaConfig } from "../types";
2
+ import type { Collection, Global, OpacaConfig, WebhookConfig } from "../types";
3
3
  /**
4
4
  * Hydrates a document with virtual fields and nested fields.
5
5
  * @param doc document to hydrate
@@ -20,12 +20,10 @@ export declare function parsePopulate(populate: string | any): Record<string, an
20
20
  export declare const populateDoc: (db: any, fields: any[], doc: any, populate: Record<string, any>, config: OpacaConfig) => Promise<any>;
21
21
  /**
22
22
  * Creates handlers for a collection
23
- * @param config opaca config
24
- * @param collection collection config
25
- * @param getAuth auth function
26
- * @returns collection handlers
23
+ * Creates a standard set of CRUD handlers for a given collection.
24
+ * These handlers manage database operations, access control, versioning, and webhooks.
27
25
  */
28
- export declare function createHandlers(config: OpacaConfig, collection: Collection, getAuth?: () => any): {
26
+ export declare function createHandlers(collection: Collection, config: OpacaConfig): {
29
27
  find(c: Context): Promise<(Response & import("hono").TypedResponse<{
30
28
  message: string;
31
29
  }, 403, "json">) | (Response & import("hono").TypedResponse<{
@@ -40,6 +38,8 @@ export declare function createHandlers(config: OpacaConfig, collection: Collecti
40
38
  hasNextPage: boolean;
41
39
  prevPage: number | null;
42
40
  nextPage: number | null;
41
+ nextCursor?: string | null | undefined;
42
+ prevCursor?: string | null | undefined;
43
43
  }, import("hono/utils/http-status").ContentfulStatusCode, "json">)>;
44
44
  findOne(c: Context): Promise<Response & import("hono").TypedResponse<any, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
45
45
  create(c: Context): Promise<(Response & import("hono").TypedResponse<{
@@ -60,7 +60,9 @@ export declare function createHandlers(config: OpacaConfig, collection: Collecti
60
60
  }, import("hono/utils/http-status").ContentfulStatusCode, "json">>;
61
61
  findVersions(c: Context): Promise<(Response & import("hono").TypedResponse<{
62
62
  message: string;
63
- }, 403, "json">) | (Response & import("hono").TypedResponse<never, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
63
+ }, 403, "json">) | (Response & import("hono").TypedResponse<{
64
+ docs: any;
65
+ }, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
64
66
  message: string;
65
67
  error: any;
66
68
  }, 500, "json">)>;
@@ -73,6 +75,22 @@ export declare function createHandlers(config: OpacaConfig, collection: Collecti
73
75
  error: any;
74
76
  }, 500, "json">)>;
75
77
  };
78
+ /**
79
+ * Creates a handler for an incoming webhook configuration.
80
+ * Manages signature verification, payload mapping, and automatic record upserts.
81
+ */
82
+ export declare function createIncomingWebhookHandler(webhookConfig: Extract<WebhookConfig, {
83
+ type: "incoming";
84
+ }>, collection: Collection, config: OpacaConfig): (c: Context) => Promise<(Response & import("hono").TypedResponse<{
85
+ message: string;
86
+ }, 401, "json">) | (Response & import("hono").TypedResponse<{
87
+ success: true;
88
+ operation: "create" | "update";
89
+ id: any;
90
+ }, import("hono/utils/http-status").ContentfulStatusCode, "json">) | (Response & import("hono").TypedResponse<{
91
+ message: string;
92
+ error: any;
93
+ }, 500, "json">)>;
76
94
  /**
77
95
  * Creates handlers for global collections
78
96
  * @param config opaca config
@@ -1,6 +1,6 @@
1
- import type { Session, User } from "../../types";
2
1
  import type { MiddlewareHandler } from "hono";
3
2
  import type { Auth } from "../../auth";
3
+ import type { Session, User } from "../../types";
4
4
  export type AuthContextVariables = {
5
5
  user: User | null;
6
6
  session: Session | null;
@@ -1,6 +1,6 @@
1
1
  import type { OpacaConfig } from "@/types";
2
2
  /**
3
- * Loads all plugin settings from the `_opaca_plugin_settings` collection.
3
+ * Loads all plugin settings from the `_plugin_settings` collection.
4
4
  * Returns a Record where keys are plugin names and values are their configurations.
5
5
  */
6
6
  export declare function loadPluginSettings(config: OpacaConfig): Promise<Record<string, any>>;
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
- import type { OpacaConfig } from "../types";
3
2
  import { type ApiContextVariables } from "../server/setup-middlewares";
3
+ import type { OpacaConfig } from "../types";
4
4
  export type { ApiContextVariables } from "../server/setup-middlewares";
5
- export declare function createAPIRouter(config: OpacaConfig, settings?: Record<string, any>): Hono<{
5
+ export declare function createAPIRouter(config: OpacaConfig, settings?: Record<string, any>, env?: any): Hono<{
6
6
  Variables: ApiContextVariables;
7
7
  }>;
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
2
  import type { Auth } from "../../auth";
3
- import type { OpacaConfig } from "../../types";
4
3
  import type { ApiContextVariables } from "../../server/router";
4
+ import type { OpacaConfig } from "../../types";
5
5
  export declare function createAdminRouter(config: OpacaConfig, settings: Record<string, any>, state: {
6
6
  auth: Auth | undefined;
7
7
  }): Hono<{
@@ -1,7 +1,7 @@
1
1
  import { Hono } from "hono";
2
2
  import type { Auth } from "../../auth";
3
- import type { OpacaConfig } from "../../types";
4
3
  import type { ApiContextVariables } from "../../server/router";
4
+ import type { OpacaConfig } from "../../types";
5
5
  export declare function createAuthRouter(config: OpacaConfig, state: {
6
6
  auth: Auth | undefined;
7
7
  }): Hono<{
@@ -1,12 +1,15 @@
1
1
  import { Hono } from "hono";
2
2
  import type { Auth } from "../../auth";
3
- import type { OpacaConfig } from "../../types";
4
3
  import type { ApiContextVariables } from "../../server/router";
4
+ import type { OpacaConfig } from "../../types";
5
5
  export declare function mountCollectionRoutes(router: Hono<{
6
6
  Variables: ApiContextVariables;
7
7
  }>, config: OpacaConfig, state: {
8
8
  auth: Auth | undefined;
9
9
  }): void;
10
+ export declare function mountIncomingWebhookRoutes(router: Hono<{
11
+ Variables: ApiContextVariables;
12
+ }>, config: OpacaConfig): void;
10
13
  export declare function mountGlobalRoutes(router: Hono<{
11
14
  Variables: ApiContextVariables;
12
15
  }>, config: OpacaConfig, state: {
@@ -11,8 +11,8 @@ import type { ApiContextVariables } from "../setup-middlewares";
11
11
  */
12
12
  export declare function mountPluginRoutes(config: OpacaConfig, settings: Record<string, any>, logger: typeof import("../../utils/logger").logger, router: Hono<{
13
13
  Variables: ApiContextVariables;
14
- }>): void;
14
+ }>, env?: any): void;
15
15
  /**
16
16
  * Fires the onInitComplete hook for all plugins.
17
17
  */
18
- export declare function firePluginInitComplete(config: OpacaConfig, settings: Record<string, any>, logger: typeof import("../../utils/logger").logger): void;
18
+ export declare function firePluginInitComplete(config: OpacaConfig, settings: Record<string, any>, logger: typeof import("../../utils/logger").logger, env?: any): void;
@@ -1,8 +1,8 @@
1
1
  import type { Hono } from "hono";
2
2
  import type { Auth } from "../auth";
3
- import type { OpacaConfig } from "../types";
4
3
  import { type AuthContextVariables } from "../server/middlewares/auth";
5
4
  import { type OpacaContextVariables } from "../server/middlewares/context";
5
+ import type { OpacaConfig } from "../types";
6
6
  export type ApiContextVariables = OpacaContextVariables & AuthContextVariables;
7
7
  export declare function setupMiddlewares(router: Hono<{
8
8
  Variables: ApiContextVariables;
@@ -1,6 +1,6 @@
1
1
  import { Hono } from "hono";
2
- import type { OpacaConfig } from "../types";
3
2
  import type { ApiContextVariables } from "../server/router";
3
+ import type { OpacaConfig } from "../types";
4
4
  export declare function createSystemRouter(config: OpacaConfig): Hono<{
5
5
  Variables: ApiContextVariables;
6
6
  }, import("hono/types").BlankSchema, "/">;
package/dist/server.js CHANGED
@@ -3,26 +3,31 @@ import {
3
3
  createAdminHandlers,
4
4
  createGlobalHandlers,
5
5
  createHandlers,
6
+ createIncomingWebhookHandler,
6
7
  hydrateDoc,
7
8
  parsePopulate,
8
9
  populateDoc
9
- } from "./chunk-kc4jfnv7.js";
10
+ } from "./chunk-z3ffn2b7.js";
10
11
  import {
11
12
  defineConfig
12
- } from "./chunk-7y1nbmw6.js";
13
- import"./chunk-b3kr8w41.js";
13
+ } from "./chunk-1bd7fz7n.js";
14
+ import"./chunk-m24yqkeq.js";
15
+ import"./chunk-5b8r0v8c.js";
16
+ import"./chunk-m5ems3hh.js";
14
17
  import {
15
18
  BaseDatabaseAdapter
16
19
  } from "./chunk-s8mqwnm1.js";
20
+ import"./chunk-q5sb5dcr.js";
17
21
  import"./chunk-qxt9vge8.js";
18
- import"./chunk-v9z61v3g.js";
19
- import"./chunk-t0zg026p.js";
20
- import"./chunk-8sqjbsgt.js";
22
+ import"./chunk-jq1drsen.js";
23
+ import"./chunk-6qs0g65f.js";
24
+ import"./chunk-6bywt602.js";
21
25
  export {
22
26
  populateDoc,
23
27
  parsePopulate,
24
28
  hydrateDoc,
25
29
  defineConfig,
30
+ createIncomingWebhookHandler,
26
31
  createHandlers,
27
32
  createGlobalHandlers,
28
33
  createAdminHandlers,
@@ -1,6 +1,15 @@
1
- import type { R2Bucket } from "@cloudflare/workers-types";
2
1
  import type { StorageAdapter, StorageAdapterConfig } from "../types";
2
+ /**
3
+ * A compatible interface for R2Bucket that avoids version mismatches
4
+ * between different @cloudflare/workers-types versions.
5
+ */
6
+ export interface OpacaR2Bucket {
7
+ put(key: string, value: any, options?: any): Promise<any>;
8
+ get(key: string, options?: any): Promise<any>;
9
+ delete(key: string): Promise<any>;
10
+ head(key: string): Promise<any>;
11
+ }
3
12
  export interface R2AdapterConfig extends StorageAdapterConfig {
4
- bucketBinding: R2Bucket;
13
+ bucketBinding: OpacaR2Bucket;
5
14
  }
6
15
  export declare function createR2Storage(config: R2AdapterConfig): StorageAdapter;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __require
3
- } from "../chunk-8sqjbsgt.js";
3
+ } from "../chunk-6bywt602.js";
4
4
 
5
5
  // src/storage/errors.ts
6
6
  class StorageError extends Error {
@@ -146,8 +146,8 @@ function createLocalAdapter(config) {
146
146
  if (!fullPath.startsWith(path.resolve(config.uploadDir))) {
147
147
  throw new StorageError("local", "upload", "Path traversal attempt detected.");
148
148
  }
149
- if (file.buffer && typeof Bun !== "undefined") {
150
- await Bun.write(fullPath, file.buffer);
149
+ if (file.buffer && typeof globalThis.Bun !== "undefined") {
150
+ await globalThis.Bun.write(fullPath, file.buffer);
151
151
  } else if (file.buffer) {
152
152
  await fs.writeFile(fullPath, file.buffer);
153
153
  } else if (file.stream) {
@@ -201,8 +201,8 @@ function createLocalAdapter(config) {
201
201
  },
202
202
  async download(filename) {
203
203
  const fullPath = getFullPath(path.basename(filename));
204
- if (typeof Bun !== "undefined") {
205
- return Bun.file(fullPath).stream();
204
+ if (typeof globalThis.Bun !== "undefined") {
205
+ return globalThis.Bun.file(fullPath).stream();
206
206
  }
207
207
  const nodeStream = __require("node:fs").createReadStream(fullPath);
208
208
  return new ReadableStream({
@@ -219,21 +219,25 @@ function createLocalAdapter(config) {
219
219
  };
220
220
  }
221
221
  // src/storage/adapters/s3.ts
222
- import {
223
- DeleteObjectCommand,
224
- GetObjectCommand,
225
- HeadObjectCommand,
226
- PutObjectCommand,
227
- S3Client
228
- } from "@aws-sdk/client-s3";
229
- import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
230
222
  function createS3Adapter(config) {
231
- const s3Client = new S3Client({
232
- region: config.region,
233
- endpoint: config.endpoint,
234
- credentials: config.credentials,
235
- forcePathStyle: config.forcePathStyle
236
- });
223
+ let _s3Client = null;
224
+ let _sdk = null;
225
+ const getSdk = async () => {
226
+ if (_sdk)
227
+ return _sdk;
228
+ const [clientS3, presigner] = await Promise.all([
229
+ import("@aws-sdk/client-s3"),
230
+ import("@aws-sdk/s3-request-presigner")
231
+ ]);
232
+ _sdk = { ...clientS3, ...presigner };
233
+ _s3Client = new _sdk.S3Client({
234
+ region: config.region,
235
+ endpoint: config.endpoint,
236
+ credentials: config.credentials,
237
+ forcePathStyle: config.forcePathStyle
238
+ });
239
+ return _sdk;
240
+ };
237
241
  const getFullKey = (filename) => {
238
242
  if (config.prefix) {
239
243
  const p = config.prefix.replace(/\/$/, "");
@@ -252,6 +256,7 @@ function createS3Adapter(config) {
252
256
  name: "s3",
253
257
  async upload(file, options) {
254
258
  try {
259
+ const sdk = await getSdk();
255
260
  if (options?.allowedmime_types && !options.allowedmime_types.includes(file.mime_type)) {
256
261
  throw new Invalidmime_typeError("s3", options.allowedmime_types, file.mime_type);
257
262
  }
@@ -267,7 +272,7 @@ function createS3Adapter(config) {
267
272
  }
268
273
  const key = getFullKey(finalFilename);
269
274
  const body = file.buffer || file.stream;
270
- const command = new PutObjectCommand({
275
+ const command = new sdk.PutObjectCommand({
271
276
  Bucket: config.bucket,
272
277
  Key: key,
273
278
  Body: body,
@@ -275,7 +280,7 @@ function createS3Adapter(config) {
275
280
  ContentLength: file.filesize,
276
281
  ACL: config.acl || "private"
277
282
  });
278
- await s3Client.send(command);
283
+ await _s3Client.send(command);
279
284
  return {
280
285
  filename: finalFilename,
281
286
  mime_type: file.mime_type,
@@ -290,22 +295,24 @@ function createS3Adapter(config) {
290
295
  },
291
296
  async delete(filename) {
292
297
  try {
293
- const command = new DeleteObjectCommand({
298
+ const sdk = await getSdk();
299
+ const command = new sdk.DeleteObjectCommand({
294
300
  Bucket: config.bucket,
295
301
  Key: getFullKey(filename)
296
302
  });
297
- await s3Client.send(command);
303
+ await _s3Client.send(command);
298
304
  } catch (error) {
299
305
  throw new StorageError("s3", "delete", `Failed to delete ${filename} from S3 bucket ${config.bucket}`, error);
300
306
  }
301
307
  },
302
308
  async exists(filename) {
303
309
  try {
304
- const command = new HeadObjectCommand({
310
+ const sdk = await getSdk();
311
+ const command = new sdk.HeadObjectCommand({
305
312
  Bucket: config.bucket,
306
313
  Key: getFullKey(filename)
307
314
  });
308
- await s3Client.send(command);
315
+ await _s3Client.send(command);
309
316
  return true;
310
317
  } catch (error) {
311
318
  if (error.name === "NotFound" || error.$metadata?.httpStatusCode === 404)
@@ -315,24 +322,26 @@ function createS3Adapter(config) {
315
322
  },
316
323
  async generatePresignedUrl(filename, operation, expiresInSeconds = 3600) {
317
324
  try {
325
+ const sdk = await getSdk();
318
326
  let command;
319
327
  if (operation === "write") {
320
- command = new PutObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
328
+ command = new sdk.PutObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
321
329
  } else {
322
- command = new GetObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
330
+ command = new sdk.GetObjectCommand({ Bucket: config.bucket, Key: getFullKey(filename) });
323
331
  }
324
- return await getSignedUrl(s3Client, command, { expiresIn: expiresInSeconds });
332
+ return await sdk.getSignedUrl(_s3Client, command, { expiresIn: expiresInSeconds });
325
333
  } catch (error) {
326
334
  throw new StorageError("s3", "presign", `Failed to generate presigned URL for ${filename}`, error);
327
335
  }
328
336
  },
329
337
  async download(filename) {
330
338
  try {
331
- const command = new GetObjectCommand({
339
+ const sdk = await getSdk();
340
+ const command = new sdk.GetObjectCommand({
332
341
  Bucket: config.bucket,
333
342
  Key: getFullKey(filename)
334
343
  });
335
- const response = await s3Client.send(command);
344
+ const response = await _s3Client.send(command);
336
345
  if (!response.Body) {
337
346
  throw new StorageError("s3", "download", `File not found: ${filename}`);
338
347
  }