@dimah-s3/db 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +6 -4
  2. package/dist/cli.js +1 -1
  3. package/dist/client/db-client.d.ts +29 -2
  4. package/dist/client/db-client.d.ts.map +1 -1
  5. package/dist/client/index.d.ts +1 -1
  6. package/dist/client/index.d.ts.map +1 -1
  7. package/dist/client/index.js +4 -0
  8. package/dist/client/index.js.map +1 -1
  9. package/dist/fuma-db.d.ts +1 -0
  10. package/dist/fuma-db.d.ts.map +1 -1
  11. package/dist/hooks/create-object-access-guard.d.ts +11 -4
  12. package/dist/hooks/create-object-access-guard.d.ts.map +1 -1
  13. package/dist/hooks/create-quota-guard.d.ts +22 -0
  14. package/dist/hooks/create-quota-guard.d.ts.map +1 -0
  15. package/dist/index.d.ts +3 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +328 -76
  18. package/dist/index.js.map +1 -1
  19. package/dist/jobs/purge-stale-pending.d.ts +9 -6
  20. package/dist/jobs/purge-stale-pending.d.ts.map +1 -1
  21. package/dist/plugin/create-database-endpoints.d.ts +26 -6
  22. package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
  23. package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
  24. package/dist/plugin/db.d.ts +41 -4
  25. package/dist/plugin/db.d.ts.map +1 -1
  26. package/dist/plugin/list-query-schema.d.ts +8 -0
  27. package/dist/plugin/list-query-schema.d.ts.map +1 -1
  28. package/dist/plugin/to-db-client-object.d.ts.map +1 -1
  29. package/dist/schema/v1.d.ts +2 -0
  30. package/dist/schema/v1.d.ts.map +1 -1
  31. package/dist/store/list-cursor.d.ts +6 -0
  32. package/dist/store/list-cursor.d.ts.map +1 -0
  33. package/dist/store/map-row.d.ts +1 -0
  34. package/dist/store/map-row.d.ts.map +1 -1
  35. package/dist/store/storage-object-store.d.ts +19 -6
  36. package/dist/store/storage-object-store.d.ts.map +1 -1
  37. package/dist/types/storage-object.d.ts +12 -0
  38. package/dist/types/storage-object.d.ts.map +1 -1
  39. package/package.json +15 -10
  40. package/src/schema/examples/drizzle.ts +2 -0
  41. package/src/schema/examples/schema.prisma +2 -0
package/README.md CHANGED
@@ -6,7 +6,7 @@ Optional FumaDB persistence for [dimah-s3](https://github.com/dimah-kz/dimah-s3)
6
6
 
7
7
  ```ts
8
8
  import { DimahS3DB, db } from "@dimah-s3/db";
9
- import { dimahS3 } from "@dimah-s3/server";
9
+ import { dimahS3, route } from "@dimah-s3/server";
10
10
  import { drizzleAdapter } from "fumadb/adapters/drizzle";
11
11
 
12
12
  export const dimahS3Db = DimahS3DB.client(
@@ -16,9 +16,6 @@ export const dimahS3Db = DimahS3DB.client(
16
16
  export const s3 = dimahS3({
17
17
  client: awsS3,
18
18
  bucket: process.env.S3_BUCKET!,
19
- upload: { prefix: "uploads" },
20
- download: true,
21
- delete: true,
22
19
  plugins: [
23
20
  db({
24
21
  client: dimahS3Db,
@@ -28,6 +25,11 @@ export const s3 = dimahS3({
28
25
  },
29
26
  }),
30
27
  ],
28
+ routes: {
29
+ uploads: route({
30
+ upload: true,
31
+ }),
32
+ },
31
33
  });
32
34
 
33
35
  s3.db.objects.listByScope({ scope });
package/dist/cli.js CHANGED
@@ -6,7 +6,7 @@ function runCli(db) {
6
6
  db,
7
7
  command: "dimah-s3-db",
8
8
  description: "FumaDB CLI for @dimah-s3/db",
9
- version: "1.0.1"
9
+ version: "1.1.0"
10
10
  });
11
11
  return main();
12
12
  }
@@ -1,5 +1,5 @@
1
- import type { DbClientListInput, DbClientListResponse } from "../types/storage-object";
2
- export type { DbClientListInput, DbClientListResponse, DbClientObject, } from "../types/storage-object";
1
+ import type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject } from "../types/storage-object";
2
+ export type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, } from "../types/storage-object";
3
3
  /**
4
4
  * Client plugin for the server `db()` endpoints.
5
5
  *
@@ -24,6 +24,9 @@ export declare function dbClient(): import("@dimah-s3/core").S3ClientPlugin<"db"
24
24
  * — not a parameter here. For another scope, use `listByScope` on the server.
25
25
  */
26
26
  listObjects: (input?: DbClientListInput) => Promise<DbClientListResponse>;
27
+ getObject: (input: DbClientGetInput) => Promise<{
28
+ object: DbClientObject;
29
+ }>;
27
30
  }, import("@dimah-s3/server").DimahS3Plugin<"db", {
28
31
  objects: import("..").StorageObjectStore;
29
32
  client: import("fumadb").FumaDB<import("fumadb/schema").Schema<"1.0.0", {
@@ -32,6 +35,7 @@ export declare function dbClient(): import("@dimah-s3/core").S3ClientPlugin<"db"
32
35
  scope: import("fumadb/schema").Column<"string", string, string>;
33
36
  bucket: import("fumadb/schema").Column<"string", string, string>;
34
37
  key: import("fumadb/schema").Column<"string", string, string>;
38
+ route: import("fumadb/schema").Column<"string", string, string>;
35
39
  contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
36
40
  size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
37
41
  eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
@@ -58,11 +62,34 @@ export declare function dbClient(): import("@dimah-s3/core").S3ClientPlugin<"db"
58
62
  status?: "active" | "deleted" | "pending" | undefined;
59
63
  limit?: unknown;
60
64
  offset?: unknown;
65
+ cursor?: string | undefined;
66
+ route?: string | undefined;
67
+ contentType?: string | undefined;
68
+ prefix?: string | undefined;
61
69
  }, {
62
70
  status?: "active" | "deleted" | "pending" | undefined;
63
71
  limit?: unknown;
64
72
  offset?: unknown;
73
+ cursor?: string | undefined;
74
+ route?: string | undefined;
75
+ contentType?: string | undefined;
76
+ prefix?: string | undefined;
65
77
  }>;
66
78
  }, DbClientListResponse>;
79
+ object: import("better-call").StrictEndpoint<string, {
80
+ use: import("better-call").MiddlewareHandler[];
81
+ } & {
82
+ method: "GET";
83
+ } & {
84
+ query: import("better-call").StandardSchemaV1<{
85
+ key: string;
86
+ bucket?: string | undefined;
87
+ }, {
88
+ key: string;
89
+ bucket?: string | undefined;
90
+ }>;
91
+ }, {
92
+ object: DbClientObject;
93
+ }>;
67
94
  }>>;
68
95
  //# sourceMappingURL=db-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"db-client.d.ts","sourceRoot":"","sources":["../../src/client/db-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ;IAKlB;;;OAGG;0BACmB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAO5C"}
1
+ {"version":3,"file":"db-client.d.ts","sourceRoot":"","sources":["../../src/client/db-client.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACf,MAAM,wBAAwB,CAAC;AAEhC,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,QAAQ;IAKlB;;;OAGG;0BACmB,iBAAiB;uBAKpB,gBAAgB;gBAChB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMtC"}
@@ -1,3 +1,3 @@
1
1
  export { dbClient } from "./db-client";
2
- export type { DbClientListInput, DbClientListResponse, DbClientObject, } from "./db-client";
2
+ export type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, } from "./db-client";
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EACV,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,GACf,MAAM,aAAa,CAAC"}
@@ -13,6 +13,10 @@ function dbClient() {
13
13
  listObjects: (input) => $fetch(pluginPath("db", "objects"), {
14
14
  method: "GET",
15
15
  query: input
16
+ }),
17
+ getObject: (input) => $fetch(pluginPath("db", "object"), {
18
+ method: "GET",
19
+ query: input
16
20
  })
17
21
  })
18
22
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/client/db-client.ts"],"names":[],"mappings":";;;AA+BO,SAAS,QAAA,GAAW;AACzB,EAAA,OAAO,kBAAA,CAAmB;AAAA,IACxB,EAAA,EAAI,IAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,UAAA,EAAY,CAAC,MAAA,MAAY;AAAA;AAAA;AAAA;AAAA;AAAA,MAKvB,aAAa,CAAC,KAAA,KACZ,OAA6B,UAAA,CAAW,IAAA,EAAM,SAAS,CAAA,EAAG;AAAA,QACxD,MAAA,EAAQ,KAAA;AAAA,QACR,KAAA,EAAO;AAAA,OACR;AAAA,KACL;AAAA,GACD,CAAA;AACH","file":"index.js","sourcesContent":["import { defineClientPlugin, pluginPath } from \"@dimah-s3/core\";\nimport type { db } from \"@/plugin/db\";\nimport type {\n DbClientListInput,\n DbClientListResponse,\n} from \"@/types/storage-object\";\n\nexport type {\n DbClientListInput,\n DbClientListResponse,\n DbClientObject,\n} from \"@/types/storage-object\";\n\n/**\n * Client plugin for the server `db()` endpoints.\n *\n * ```ts\n * import { createS3Client } from \"@dimah-s3/react\";\n * import { dbClient } from \"@dimah-s3/db/client\";\n *\n * export const { api, useApi } = createS3Client({\n * plugins: [dbClient()],\n * });\n *\n * await api.db.listObjects({ limit: 50 });\n * ```\n *\n * Server code does not use `listObjects` — it calls `s3.db.objects.listByScope`\n * and `getScopeUsage` directly (no HTTP round-trip). `listObjects` is the browser\n * wrapper for `GET /db/objects`.\n */\nexport function dbClient() {\n return defineClientPlugin({\n id: \"db\",\n $InferServerPlugin: {} as ReturnType<typeof db>,\n getActions: ($fetch) => ({\n /**\n * List the caller's objects and usage. Scope comes from server `resolveScope`\n * — not a parameter here. For another scope, use `listByScope` on the server.\n */\n listObjects: (input?: DbClientListInput) =>\n $fetch<DbClientListResponse>(pluginPath(\"db\", \"objects\"), {\n method: \"GET\",\n query: input,\n }),\n }),\n });\n}\n"]}
1
+ {"version":3,"sources":["../../src/client/db-client.ts"],"names":[],"mappings":";;;AAkCO,SAAS,QAAA,GAAW;AACzB,EAAA,OAAO,kBAAA,CAAmB;AAAA,IACxB,EAAA,EAAI,IAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,UAAA,EAAY,CAAC,MAAA,MAAY;AAAA;AAAA;AAAA;AAAA;AAAA,MAKvB,aAAa,CAAC,KAAA,KACZ,OAA6B,UAAA,CAAW,IAAA,EAAM,SAAS,CAAA,EAAG;AAAA,QACxD,MAAA,EAAQ,KAAA;AAAA,QACR,KAAA,EAAO;AAAA,OACR,CAAA;AAAA,MACH,WAAW,CAAC,KAAA,KACV,OAAmC,UAAA,CAAW,IAAA,EAAM,QAAQ,CAAA,EAAG;AAAA,QAC7D,MAAA,EAAQ,KAAA;AAAA,QACR,KAAA,EAAO;AAAA,OACR;AAAA,KACL;AAAA,GACD,CAAA;AACH","file":"index.js","sourcesContent":["import { defineClientPlugin, pluginPath } from \"@dimah-s3/core\";\nimport type { db } from \"@/plugin/db\";\nimport type {\n DbClientGetInput,\n DbClientListInput,\n DbClientListResponse,\n DbClientObject,\n} from \"@/types/storage-object\";\n\nexport type {\n DbClientGetInput,\n DbClientListInput,\n DbClientListResponse,\n DbClientObject,\n} from \"@/types/storage-object\";\n\n/**\n * Client plugin for the server `db()` endpoints.\n *\n * ```ts\n * import { createS3Client } from \"@dimah-s3/react\";\n * import { dbClient } from \"@dimah-s3/db/client\";\n *\n * export const { api, useApi } = createS3Client({\n * plugins: [dbClient()],\n * });\n *\n * await api.db.listObjects({ limit: 50 });\n * ```\n *\n * Server code does not use `listObjects` — it calls `s3.db.objects.listByScope`\n * and `getScopeUsage` directly (no HTTP round-trip). `listObjects` is the browser\n * wrapper for `GET /db/objects`.\n */\nexport function dbClient() {\n return defineClientPlugin({\n id: \"db\",\n $InferServerPlugin: {} as ReturnType<typeof db>,\n getActions: ($fetch) => ({\n /**\n * List the caller's objects and usage. Scope comes from server `resolveScope`\n * — not a parameter here. For another scope, use `listByScope` on the server.\n */\n listObjects: (input?: DbClientListInput) =>\n $fetch<DbClientListResponse>(pluginPath(\"db\", \"objects\"), {\n method: \"GET\",\n query: input,\n }),\n getObject: (input: DbClientGetInput) =>\n $fetch<{ object: DbClientObject }>(pluginPath(\"db\", \"object\"), {\n method: \"GET\",\n query: input,\n }),\n }),\n });\n}\n"]}
package/dist/fuma-db.d.ts CHANGED
@@ -5,6 +5,7 @@ export declare const DimahS3DB: import("fumadb").FumaDBFactory<import("fumadb/sc
5
5
  scope: import("fumadb/schema").Column<"string", string, string>;
6
6
  bucket: import("fumadb/schema").Column<"string", string, string>;
7
7
  key: import("fumadb/schema").Column<"string", string, string>;
8
+ route: import("fumadb/schema").Column<"string", string, string>;
8
9
  contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
9
10
  size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
10
11
  eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
@@ -1 +1 @@
1
- {"version":3,"file":"fuma-db.d.ts","sourceRoot":"","sources":["../src/fuma-db.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;KAGpB,CAAC;AAEH,OAAO,EAAE,EAAE,EAAE,CAAC"}
1
+ {"version":3,"file":"fuma-db.d.ts","sourceRoot":"","sources":["../src/fuma-db.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEjC,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;KAGpB,CAAC;AAEH,OAAO,EAAE,EAAE,EAAE,CAAC"}
@@ -5,9 +5,12 @@ export type ObjectAccessGuardContext = {
5
5
  request: Request;
6
6
  key: string;
7
7
  bucket: string;
8
+ /** Multipart session id — required when {@link CreateObjectAccessGuardOptions.requireUploadId} is set. */
9
+ uploadId?: string;
8
10
  };
9
11
  export type CreateObjectAccessGuardOptions = {
10
- db: DimahS3DbClient | StorageObjectStore;
12
+ /** FumaDB client (`DimahS3DB.client(adapter)`) or a prebuilt objects store. */
13
+ client: DimahS3DbClient | StorageObjectStore;
11
14
  resolveScope: ScopeResolver;
12
15
  /**
13
16
  * Which rows count as accessible.
@@ -15,6 +18,11 @@ export type CreateObjectAccessGuardOptions = {
15
18
  * @default "active"
16
19
  */
17
20
  requireStatus?: StorageObjectStatus | "any";
21
+ /**
22
+ * Require `context.uploadId` to match the pending row's `uploadId`.
23
+ * Use for `upload.multipart.guard`.
24
+ */
25
+ requireUploadId?: boolean;
18
26
  /**
19
27
  * Replace the default `object.scope === scope` ownership check —
20
28
  * e.g. also allow objects whose metadata marks them public.
@@ -23,14 +31,13 @@ export type CreateObjectAccessGuardOptions = {
23
31
  scope: string;
24
32
  }) => boolean | Promise<boolean>;
25
33
  };
26
- export declare function resolveStore(db: DimahS3DbClient | StorageObjectStore): StorageObjectStore;
34
+ export declare function resolveStore(client: DimahS3DbClient | StorageObjectStore): StorageObjectStore;
27
35
  /**
28
36
  * Guard that checks the requested object exists in the DB and belongs to the
29
37
  * caller's scope. Throws `DimahS3Error` (401 / 404 / 403) to reject.
30
38
  *
31
39
  * Usable as `download.guard`, `delete.guard`,
32
- * `upload.confirmGuard`, multipart `partGuard` / `listGuard` /
33
- * `completeGuard` / `abortGuard`, or in your own routes.
40
+ * `upload.confirmGuard`, `upload.multipart.guard`, or in your own routes.
34
41
  */
35
42
  export declare function createObjectAccessGuard(options: CreateObjectAccessGuardOptions): (context: ObjectAccessGuardContext) => Promise<void>;
36
43
  //# sourceMappingURL=create-object-access-guard.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-object-access-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/create-object-access-guard.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,uFAAuF;AACvF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,EAAE,EAAE,eAAe,GAAG,kBAAkB,CAAC;IACzC,YAAY,EAAE,aAAa,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAC5C;;;OAGG;IACH,SAAS,CAAC,EAAE,CACV,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,wBAAwB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAClD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,YAAY,CAC1B,EAAE,EAAE,eAAe,GAAG,kBAAkB,GACvC,kBAAkB,CAEpB;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC,IAAI,CAAC,CAwBtD"}
1
+ {"version":3,"file":"create-object-access-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/create-object-access-guard.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,kBAAkB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAEhC,uFAAuF;AACvF,MAAM,MAAM,wBAAwB,GAAG;IACrC,OAAO,EAAE,OAAO,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,0GAA0G;IAC1G,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,8BAA8B,GAAG;IAC3C,+EAA+E;IAC/E,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC7C,YAAY,EAAE,aAAa,CAAC;IAC5B;;;;OAIG;IACH,aAAa,CAAC,EAAE,mBAAmB,GAAG,KAAK,CAAC;IAC5C;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,CACV,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,wBAAwB,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,KAClD,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACjC,CAAC;AAEF,wBAAgB,YAAY,CAC1B,MAAM,EAAE,eAAe,GAAG,kBAAkB,GAC3C,kBAAkB,CAEpB;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,CAAC,OAAO,EAAE,wBAAwB,KAAK,OAAO,CAAC,IAAI,CAAC,CA6BtD"}
@@ -0,0 +1,22 @@
1
+ import type { DimahS3DbClient, StorageObjectStore } from "../store/storage-object-store";
2
+ import type { ScopeResolver } from "../types/storage-object";
3
+ export type CreateQuotaGuardOptions = {
4
+ client: DimahS3DbClient | StorageObjectStore;
5
+ resolveScope: ScopeResolver;
6
+ maxBytes?: number;
7
+ maxFiles?: number;
8
+ };
9
+ export type QuotaGuardContext = {
10
+ request: Request;
11
+ file?: {
12
+ size?: number;
13
+ };
14
+ replace?: "overwrite";
15
+ };
16
+ /**
17
+ * Reject uploads that would exceed scope usage.
18
+ * Wire as `upload.guard` (after `db()` so ownership still runs), or pass
19
+ * `quota` on {@link db}.
20
+ */
21
+ export declare function createQuotaGuard(options: CreateQuotaGuardOptions): (context: QuotaGuardContext) => Promise<void>;
22
+ //# sourceMappingURL=create-quota-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-quota-guard.d.ts","sourceRoot":"","sources":["../../src/hooks/create-quota-guard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,eAAe,EACf,kBAAkB,EACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,MAAM,uBAAuB,GAAG;IACpC,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAAC;IAC7C,YAAY,EAAE,aAAa,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACzB,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB,CAAC;AASF;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,CAAC,OAAO,EAAE,iBAAiB,KAAK,OAAO,CAAC,IAAI,CAAC,CA0B/C"}
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { DimahS3DB, v1 } from "./fuma-db";
2
- export type { DbClientListInput, DbClientListResponse, DbClientObject, ScopeResolver, StorageObject, StorageObjectStatus, } from "./types/storage-object";
2
+ export type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, ScopeResolver, StorageObject, StorageObjectStatus, } from "./types/storage-object";
3
3
  export { conflict, forbidden, notFound, unauthorized } from "./errors";
4
4
  export { createStorageObjectStore, toPendingMultipartResume, } from "./store/storage-object-store";
5
5
  export type { DimahS3DbClient, FindPendingMultipartInput, ListByScopeInput, MarkActiveInput, ObjectRef, PendingMultipartResume, ScopeUsage, StorageObjectStore, UpsertPendingInput, } from "./store/storage-object-store";
6
- export { mapStorageObjectRow } from "./store/map-row";
7
- export type { StorageObjectRow } from "./store/map-row";
8
6
  export { db } from "./plugin/db";
9
7
  export type { DbPluginContext, DbPluginOptions } from "./plugin/db";
10
8
  export { createObjectAccessGuard } from "./hooks/create-object-access-guard";
11
9
  export type { CreateObjectAccessGuardOptions, ObjectAccessGuardContext, } from "./hooks/create-object-access-guard";
10
+ export { createQuotaGuard } from "./hooks/create-quota-guard";
11
+ export type { CreateQuotaGuardOptions, QuotaGuardContext, } from "./hooks/create-quota-guard";
12
12
  export { purgeStalePendingObjects } from "./jobs/purge-stale-pending";
13
13
  export type { PurgeStalePendingOptions, PurgeStalePendingResult, } from "./jobs/purge-stale-pending";
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAG1C,YAAY,EACV,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGvE,OAAO,EACL,wB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