@dimah-s3/db 1.7.1 → 2.0.0-beta.1

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 (120) hide show
  1. package/README.md +62 -17
  2. package/dist/adapters/drizzle.d.ts +8 -0
  3. package/dist/adapters/drizzle.d.ts.map +1 -0
  4. package/dist/adapters/drizzle.js +3 -0
  5. package/dist/adapters/drizzle.js.map +1 -0
  6. package/dist/adapters/kysely.d.ts +7 -0
  7. package/dist/adapters/kysely.d.ts.map +1 -0
  8. package/dist/adapters/kysely.js +3 -0
  9. package/dist/adapters/kysely.js.map +1 -0
  10. package/dist/adapters/prisma.d.ts +7 -0
  11. package/dist/adapters/prisma.d.ts.map +1 -0
  12. package/dist/adapters/prisma.js +3 -0
  13. package/dist/adapters/prisma.js.map +1 -0
  14. package/dist/cli.d.ts +32 -4
  15. package/dist/cli.d.ts.map +1 -1
  16. package/dist/cli.js +135 -4
  17. package/dist/cli.js.map +1 -1
  18. package/dist/client/db-client.d.ts +9 -85
  19. package/dist/client/db-client.d.ts.map +1 -1
  20. package/dist/client/db-object-source.d.ts +25 -0
  21. package/dist/client/db-object-source.d.ts.map +1 -0
  22. package/dist/client/index.d.ts +3 -3
  23. package/dist/client/index.d.ts.map +1 -1
  24. package/dist/client/index.js +96 -42
  25. package/dist/client/index.js.map +1 -1
  26. package/dist/drizzle/mysql.d.ts +1025 -0
  27. package/dist/drizzle/mysql.d.ts.map +1 -0
  28. package/dist/drizzle/mysql.js +117 -0
  29. package/dist/drizzle/mysql.js.map +1 -0
  30. package/dist/drizzle/pg.d.ts +964 -0
  31. package/dist/drizzle/pg.d.ts.map +1 -0
  32. package/dist/drizzle/pg.js +98 -0
  33. package/dist/drizzle/pg.js.map +1 -0
  34. package/dist/drizzle/shared.d.ts +7 -0
  35. package/dist/drizzle/shared.d.ts.map +1 -0
  36. package/dist/drizzle/sqlite.d.ts +1024 -0
  37. package/dist/drizzle/sqlite.d.ts.map +1 -0
  38. package/dist/drizzle/sqlite.js +101 -0
  39. package/dist/drizzle/sqlite.js.map +1 -0
  40. package/dist/folder-path.d.ts +32 -0
  41. package/dist/folder-path.d.ts.map +1 -0
  42. package/dist/fuma-db.d.ts +30 -9
  43. package/dist/fuma-db.d.ts.map +1 -1
  44. package/dist/index.d.ts +9 -13
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1419 -623
  47. package/dist/index.js.map +1 -1
  48. package/dist/plugin/create-database-endpoints.d.ts +105 -21
  49. package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
  50. package/dist/plugin/create-database-lifecycle-hooks.d.ts +37 -19
  51. package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
  52. package/dist/plugin/db.d.ts +29 -118
  53. package/dist/plugin/db.d.ts.map +1 -1
  54. package/dist/plugin/object-access.d.ts +46 -0
  55. package/dist/plugin/object-access.d.ts.map +1 -0
  56. package/dist/plugin/public-stores.d.ts +33 -0
  57. package/dist/plugin/public-stores.d.ts.map +1 -0
  58. package/dist/plugin/purge.d.ts +49 -0
  59. package/dist/plugin/purge.d.ts.map +1 -0
  60. package/dist/plugin/quota.d.ts +25 -0
  61. package/dist/plugin/quota.d.ts.map +1 -0
  62. package/dist/plugin/schemas.d.ts +69 -0
  63. package/dist/plugin/schemas.d.ts.map +1 -0
  64. package/dist/plugin/scope.d.ts +31 -0
  65. package/dist/plugin/scope.d.ts.map +1 -0
  66. package/dist/plugin/to-db-client-object.d.ts +8 -4
  67. package/dist/plugin/to-db-client-object.d.ts.map +1 -1
  68. package/dist/schema/schema.d.ts +73 -0
  69. package/dist/schema/schema.d.ts.map +1 -0
  70. package/dist/standard-schema.d.ts +42 -0
  71. package/dist/standard-schema.d.ts.map +1 -0
  72. package/dist/store/create-db-store.d.ts +17 -0
  73. package/dist/store/create-db-store.d.ts.map +1 -0
  74. package/dist/store/folder-store.d.ts +36 -0
  75. package/dist/store/folder-store.d.ts.map +1 -0
  76. package/dist/store/list-cursor.d.ts +26 -4
  77. package/dist/store/list-cursor.d.ts.map +1 -1
  78. package/dist/store/map-row.d.ts +17 -8
  79. package/dist/store/map-row.d.ts.map +1 -1
  80. package/dist/store/object-store.d.ts +208 -0
  81. package/dist/store/object-store.d.ts.map +1 -0
  82. package/dist/store/schema-version.d.ts +7 -0
  83. package/dist/store/schema-version.d.ts.map +1 -0
  84. package/dist/types/client.d.ts +209 -0
  85. package/dist/types/client.d.ts.map +1 -0
  86. package/dist/types/plugin.d.ts +112 -0
  87. package/dist/types/plugin.d.ts.map +1 -0
  88. package/dist/types/storage-object.d.ts +40 -85
  89. package/dist/types/storage-object.d.ts.map +1 -1
  90. package/package.json +53 -11
  91. package/prisma/dimah-s3.prisma +80 -0
  92. package/sql/mysql.sql +59 -0
  93. package/sql/pg.sql +53 -0
  94. package/sql/sqlite.sql +54 -0
  95. package/src/drizzle/mysql.ts +172 -0
  96. package/src/drizzle/pg.ts +140 -0
  97. package/src/drizzle/sqlite.ts +144 -0
  98. package/dist/client/db-object-list-accessors.d.ts +0 -36
  99. package/dist/client/db-object-list-accessors.d.ts.map +0 -1
  100. package/dist/client/db-object-query.d.ts +0 -40
  101. package/dist/client/db-object-query.d.ts.map +0 -1
  102. package/dist/errors.d.ts +0 -6
  103. package/dist/errors.d.ts.map +0 -1
  104. package/dist/hooks/create-object-access-guard.d.ts +0 -51
  105. package/dist/hooks/create-object-access-guard.d.ts.map +0 -1
  106. package/dist/hooks/create-quota-guard.d.ts +0 -28
  107. package/dist/hooks/create-quota-guard.d.ts.map +0 -1
  108. package/dist/jobs/purge-stale-pending.d.ts +0 -31
  109. package/dist/jobs/purge-stale-pending.d.ts.map +0 -1
  110. package/dist/plugin/list-query-schema.d.ts +0 -21
  111. package/dist/plugin/list-query-schema.d.ts.map +0 -1
  112. package/dist/plugin/memoize-scope-resolver.d.ts +0 -8
  113. package/dist/plugin/memoize-scope-resolver.d.ts.map +0 -1
  114. package/dist/schema/v1.d.ts +0 -31
  115. package/dist/schema/v1.d.ts.map +0 -1
  116. package/dist/store/storage-object-store.d.ts +0 -137
  117. package/dist/store/storage-object-store.d.ts.map +0 -1
  118. package/src/schema/examples/README.md +0 -10
  119. package/src/schema/examples/drizzle.ts +0 -92
  120. package/src/schema/examples/schema.prisma +0 -55
package/README.md CHANGED
@@ -1,38 +1,83 @@
1
1
  # @dimah-s3/db
2
2
 
3
- Optional FumaDB persistence for [dimah-s3](https://github.com/dimah-kz/dimah-s3) — `storage_object` table via the `db()` plugin.
3
+ **2.0 beta.** Install with `@beta`. `@latest` stays on 1.x, and betas can include breaking changes until 2.0.0.
4
4
 
5
- **Docs:** [Database Setup](https://s3.dimah.dev/docs/db/setup) · [Database Lifecycle Hooks](https://s3.dimah.dev/docs/db/lifecycle-hooks) · [llms.txt](https://s3.dimah.dev/llms.txt) · **Example:** [`examples/with-db`](../../examples/with-db)
5
+ Optional database plugin for [dimah-s3](https://github.com/dimah-kz/dimah-s3). It tracks each upload in a `storage_object` table, binds uploads to the caller's scope, and adds logical folders, listings, and quotas.
6
+
7
+ **Docs:** [Database Setup](https://v2.s3.dimah.dev/docs/db/setup) · [Lifecycle Hooks](https://v2.s3.dimah.dev/docs/db/lifecycle-hooks) · [API](https://v2.s3.dimah.dev/docs/db/api) · [Purge](https://v2.s3.dimah.dev/docs/db/purge) · [llms.txt](https://v2.s3.dimah.dev/llms.txt) · **Example:** [`examples/with-db`](../../examples/with-db)
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm add @dimah-s3/db@beta @dimah-s3/server@beta
13
+ ```
14
+
15
+ You do not install `fumadb`: the adapters ship from `@dimah-s3/db/adapters/*`.
16
+
17
+ ## Tables
18
+
19
+ Create the schema with one of:
20
+
21
+ - Drizzle: copy `src/drizzle/{sqlite,pg,mysql}.ts` from the package into your schema so you can add columns. Or import `dimahS3Tables` from `@dimah-s3/db/drizzle/{sqlite,pg,mysql}` when the tables stay as they are.
22
+ - Prisma: copy [`prisma/dimah-s3.prisma`](./prisma/dimah-s3.prisma) into your schema.
23
+ - Plain SQL: run [`sql/<dialect>.sql`](./sql).
24
+ - Kysely: call `migrate(client)` from `@dimah-s3/db/cli`. It creates the tables and the indexes. The FumaDB CLI from `runCli` does the same only with `migrate:up`; its `migrate` command jumps straight to the latest schema and skips the indexes.
25
+
26
+ The package reads schema `2.0.0` and does not upgrade a 1.x database: create the tables on a new database. A database at another schema version throws on the first query. Call `s3.db.checkSchema()` at startup to fail fast.
27
+
28
+ ## Server
6
29
 
7
30
  ```ts
8
31
  import { DimahS3DB, db } from "@dimah-s3/db";
32
+ import { drizzleAdapter } from "@dimah-s3/db/adapters/drizzle";
9
33
  import { dimahS3, route } from "@dimah-s3/server";
10
- import { drizzleAdapter } from "fumadb/adapters/drizzle";
11
-
12
- export const dimahS3Db = DimahS3DB.client(
13
- drizzleAdapter({ db: drizzleDb, provider: "sqlite" }),
14
- );
15
34
 
16
35
  export const s3 = dimahS3({
17
36
  client: awsS3,
18
37
  bucket: process.env.S3_BUCKET!,
19
38
  plugins: [
20
39
  db({
21
- client: dimahS3Db,
22
- resolveScope: async (request) => {
23
- const session = await getSession(request);
24
- return session ? `user:${session.userId}` : null;
25
- },
40
+ client: DimahS3DB.client(
41
+ drizzleAdapter({ db: drizzleDb, provider: "sqlite" }),
42
+ ),
43
+ getSession: (request) => auth.getSession(request),
44
+ resolveScope: ({ session }) =>
45
+ session ? `user:${session.userId}` : null,
46
+ quota: { maxBytes: 1024 ** 3, maxFiles: 1000 },
26
47
  }),
27
48
  ],
28
49
  routes: {
29
- uploads: route({
30
- upload: true,
31
- }),
50
+ uploads: route({ upload: true, download: true, delete: true }),
32
51
  },
33
52
  });
34
53
 
35
- s3.db.objects.listByScope({ scope });
54
+ await s3.db.objects.list({ scope: "user:1", folder: null });
55
+ await s3.db.purgeStale();
36
56
  ```
37
57
 
38
- Copy-paste schemas (with indexes): [`drizzle.ts`](./src/schema/examples/drizzle.ts) · [`schema.prisma`](./src/schema/examples/schema.prisma)
58
+ - `resolveScope` returns the owner of the request, or `null` to reject it with `UNAUTHORIZED`.
59
+ - `authorize` runs after it and returns `false` to reject with `FORBIDDEN`.
60
+ - `quota` is checked at upload and again with the verified size at confirm.
61
+ - `plugins: { db: false }` on a route turns tracking off. `plugins: { db: { replace: "overwrite" } }` lets an upload replace an active object at the same key; the object stays listed and downloadable until the new upload is confirmed.
62
+
63
+ ## Browser
64
+
65
+ ```ts
66
+ import { dbClient, dbObjectSource } from "@dimah-s3/db/client";
67
+ import { createS3Client, useObjectList } from "@dimah-s3/react";
68
+
69
+ export const s3Client = createS3Client({ plugins: [dbClient()] });
70
+
71
+ const list = useObjectList({
72
+ ...dbObjectSource(s3Client.db, { route: "uploads" }),
73
+ queryKey: ["uploads"],
74
+ });
75
+ ```
76
+
77
+ `dbObjectSource` lists one folder at a time. Uploads go to the open folder, and "New folder" calls `api.db.createFolder`. Pass `folders: false` for a flat list.
78
+
79
+ `api.db` also has `getObject`, `updateObject` (rename, move, or set `attributes`), and `deleteFolder`.
80
+
81
+ ## License
82
+
83
+ MIT
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The FumaDB Drizzle adapter. Pass a Drizzle instance whose schema includes
3
+ * the tables from `src/drizzle/<dialect>.ts`, copied into the app or
4
+ * imported as `dimahS3Tables` from `@dimah-s3/db/drizzle/<dialect>`:
5
+ * `DimahS3DB.client(drizzleAdapter({ db, provider: "postgresql" }))`.
6
+ */
7
+ export { drizzleAdapter, type DrizzleConfig } from "fumadb/adapters/drizzle";
8
+ //# sourceMappingURL=drizzle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/adapters/drizzle.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { drizzleAdapter } from 'fumadb/adapters/drizzle';
2
+ //# sourceMappingURL=drizzle.js.map
3
+ //# sourceMappingURL=drizzle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"drizzle.js","sourcesContent":[]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The FumaDB Kysely adapter. It can also migrate the schema:
3
+ * `DimahS3DB.client(kyselyAdapter({ db, provider: "postgresql" }))`.
4
+ */
5
+ export { kyselyAdapter } from "fumadb/adapters/kysely";
6
+ export type { KyselyConfig } from "fumadb";
7
+ //# sourceMappingURL=kysely.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kysely.d.ts","sourceRoot":"","sources":["../../src/adapters/kysely.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { kyselyAdapter } from 'fumadb/adapters/kysely';
2
+ //# sourceMappingURL=kysely.js.map
3
+ //# sourceMappingURL=kysely.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"kysely.js","sourcesContent":[]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The FumaDB Prisma adapter. Pass a Prisma client generated with the models
3
+ * from `prisma/dimah-s3.prisma`:
4
+ * `DimahS3DB.client(prismaAdapter({ prisma, provider: "postgresql" }))`.
5
+ */
6
+ export { prismaAdapter, type PrismaConfig } from "fumadb/adapters/prisma";
7
+ //# sourceMappingURL=prisma.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/adapters/prisma.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { prismaAdapter } from 'fumadb/adapters/prisma';
2
+ //# sourceMappingURL=prisma.js.map
3
+ //# sourceMappingURL=prisma.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"prisma.js","sourcesContent":[]}
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,33 @@
1
- import type { InferFumaDB } from "fumadb";
2
- import type { DimahS3DB } from "./fuma-db";
3
- /** Run the interactive FumaDB CLI (generate schema, migrate when using Kysely, etc.). */
4
- export declare function runCli(db: InferFumaDB<typeof DimahS3DB>): Promise<void>;
1
+ import { type DimahS3DbClient } from "./fuma-db";
2
+ /**
3
+ * Runs the interactive FumaDB CLI: generate the ORM schema, or migrate when
4
+ * the client uses the Kysely adapter. Prefer {@link migrate}. Only
5
+ * `migrate:up`, one version at a time, runs the steps the schema needs,
6
+ * including the indexes. The CLI `migrate` command jumps to the latest
7
+ * schema and skips them.
8
+ *
9
+ * ```ts
10
+ * // scripts/db.ts
11
+ * import { runCli } from "@dimah-s3/db/cli";
12
+ * import { dimahS3Db } from "../lib/s3";
13
+ *
14
+ * await runCli(dimahS3Db);
15
+ * ```
16
+ */
17
+ export declare function runCli(client: DimahS3DbClient): Promise<void>;
18
+ /**
19
+ * Creates the schema this package reads, one version at a time, so the
20
+ * schema's own steps run (the indexes among them). It needs the Kysely
21
+ * adapter; with Drizzle or Prisma, use your ORM's migrations or the files
22
+ * in `sql/`. It does not upgrade a database at another version.
23
+ *
24
+ * ```ts
25
+ * import { DimahS3DB } from "@dimah-s3/db";
26
+ * import { kyselyAdapter } from "@dimah-s3/db/adapters/kysely";
27
+ * import { migrate } from "@dimah-s3/db/cli";
28
+ *
29
+ * await migrate(DimahS3DB.client(kyselyAdapter({ db: kysely, provider: "postgresql" })));
30
+ * ```
31
+ */
32
+ export declare function migrate(client: DimahS3DbClient): Promise<void>;
5
33
  //# sourceMappingURL=cli.d.ts.map
package/dist/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAI3C,yFAAyF;AACzF,wBAAgB,MAAM,CAAC,EAAE,EAAE,WAAW,CAAC,OAAO,SAAS,CAAC,iBASvD"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAYpE;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAS7D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBpE"}
package/dist/cli.js CHANGED
@@ -1,16 +1,147 @@
1
1
  import { createCli } from 'fumadb/cli';
2
+ import { fumadb } from 'fumadb';
3
+ import { table, column, idColumn, schema } from 'fumadb/schema';
2
4
 
3
5
  // src/cli.ts
4
- function runCli(db) {
6
+ function byteCount(name) {
7
+ return column(name, "bigint").nullable();
8
+ }
9
+ var storageObject = table("storage_object", {
10
+ id: idColumn("id", "varchar(255)").defaultTo$("auto"),
11
+ /** Owner, for example `user:123` or `org:acme`. */
12
+ scope: column("scope", "string"),
13
+ bucket: column("bucket", "string"),
14
+ key: column("key", "string"),
15
+ /** Named dimah-s3 route that created the object. */
16
+ route: column("route", "string"),
17
+ /** Logical folder path. `null` is the root. */
18
+ folder: column("folder", "string").nullable(),
19
+ filename: column("filename", "string"),
20
+ contentType: column("content_type", "string").nullable(),
21
+ /** Verified size from HeadObject, set on confirm. */
22
+ size: byteCount("size"),
23
+ /** Size the client declared before confirm. Quota counts it while pending. */
24
+ declaredSize: byteCount("declared_size"),
25
+ eTag: column("e_tag", "string").nullable(),
26
+ status: column("status", "string"),
27
+ /** S3 user metadata of the verified object. */
28
+ s3Metadata: column("s3_metadata", "json").nullable(),
29
+ /** App attributes, validated by the plugin's `attributes.schema`. */
30
+ attributes: column("attributes", "json").nullable(),
31
+ acl: column("acl", "string").nullable(),
32
+ /** Multipart upload ID while the row is pending. */
33
+ uploadId: column("upload_id", "string").nullable(),
34
+ /** Token of the upload ticket that wrote the row. Confirm and purge match it. */
35
+ uploadToken: column("upload_token", "string").nullable(),
36
+ /** Confirm deadline of a pending row (the upload ticket's expiry). */
37
+ expiresAt: column("expires_at", "timestamp").nullable(),
38
+ confirmedAt: column("confirmed_at", "timestamp").nullable(),
39
+ createdAt: column("created_at", "timestamp").defaultTo$("now"),
40
+ updatedAt: column("updated_at", "timestamp").defaultTo$("now"),
41
+ deletedAt: column("deleted_at", "timestamp").nullable()
42
+ }).unique("storage_object_bucket_key_uk", ["bucket", "key"]);
43
+ var storageFolder = table("storage_folder", {
44
+ id: idColumn("id", "varchar(255)").defaultTo$("auto"),
45
+ scope: column("scope", "string"),
46
+ /** Full folder path. */
47
+ path: column("path", "string"),
48
+ /** Path of the containing folder. `null` is the root. */
49
+ parent: column("parent", "string").nullable(),
50
+ /** Last segment of `path`. */
51
+ name: column("name", "string"),
52
+ createdAt: column("created_at", "timestamp").defaultTo$("now")
53
+ }).unique("storage_folder_scope_path_uk", ["scope", "path"]);
54
+ var schemaIndexes = [
55
+ {
56
+ name: "storage_object_scope_folder_idx",
57
+ table: "storage_object",
58
+ columns: ["scope", "status", "folder", "created_at"]
59
+ },
60
+ {
61
+ name: "storage_object_scope_updated_idx",
62
+ table: "storage_object",
63
+ columns: ["scope", "status", "updated_at"]
64
+ },
65
+ {
66
+ name: "storage_object_scope_filename_idx",
67
+ table: "storage_object",
68
+ columns: ["scope", "status", "filename"]
69
+ },
70
+ {
71
+ name: "storage_object_scope_size_idx",
72
+ table: "storage_object",
73
+ columns: ["scope", "status", "size"]
74
+ },
75
+ {
76
+ name: "storage_object_status_expires_idx",
77
+ table: "storage_object",
78
+ columns: ["status", "expires_at"]
79
+ },
80
+ {
81
+ name: "storage_folder_scope_parent_idx",
82
+ table: "storage_folder",
83
+ columns: ["scope", "parent"]
84
+ }
85
+ ];
86
+ var custom = (sql) => ({ type: "custom", sql });
87
+ var PREDECESSOR_VERSION = "0.0.1";
88
+ var predecessor = schema({
89
+ version: PREDECESSOR_VERSION,
90
+ tables: {}
91
+ });
92
+ var dbSchema = schema({
93
+ version: "2.0.0",
94
+ tables: {
95
+ storageObject,
96
+ storageFolder
97
+ },
98
+ async up({ auto }) {
99
+ const indexes = schemaIndexes.map((index) => {
100
+ const columns = index.columns.map((name) => `"${name}"`).join(", ");
101
+ return custom(
102
+ `CREATE INDEX IF NOT EXISTS "${index.name}" ON "${index.table}" (${columns})`
103
+ );
104
+ });
105
+ return [...await auto(), ...indexes];
106
+ }
107
+ });
108
+
109
+ // src/fuma-db.ts
110
+ fumadb({
111
+ namespace: "dimah_s3",
112
+ schemas: [predecessor, dbSchema]
113
+ });
114
+ var DB_SCHEMA_VERSION = dbSchema.version;
115
+
116
+ // src/cli.ts
117
+ var RESUMABLE = /* @__PURE__ */ new Set([PREDECESSOR_VERSION, DB_SCHEMA_VERSION]);
118
+ function runCli(client) {
5
119
  const { main } = createCli({
6
- db,
120
+ db: client,
7
121
  command: "dimah-s3-db",
8
122
  description: "FumaDB CLI for @dimah-s3/db",
9
- version: "1.7.1"
123
+ version: "2.0.0-beta.1"
10
124
  });
11
125
  return main();
12
126
  }
127
+ async function migrate(client) {
128
+ let version;
129
+ try {
130
+ version = await client.version();
131
+ } catch {
132
+ version = void 0;
133
+ }
134
+ if (version !== void 0 && !RESUMABLE.has(version)) {
135
+ throw new Error(
136
+ `[dimah-s3/db] The database is at schema ${version}, which this package does not upgrade. Create schema ${DB_SCHEMA_VERSION} on a new database.`
137
+ );
138
+ }
139
+ const migrator = client.createMigrator();
140
+ for (let next = await migrator.next(); next; next = await migrator.next()) {
141
+ await (await migrator.up()).execute();
142
+ }
143
+ }
13
144
 
14
- export { runCli };
145
+ export { migrate, runCli };
15
146
  //# sourceMappingURL=cli.js.map
16
147
  //# sourceMappingURL=cli.js.map
package/dist/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/cli.ts"],"names":[],"mappings":";;;AAOO,SAAS,OAAO,EAAA,EAAmC;AACxD,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,SAAA,CAAU;AAAA,IACzB,EAAA;AAAA,IACA,OAAA,EAAS,aAAA;AAAA,IACT,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,OAAO,IAAA,EAAK;AACd","file":"cli.js","sourcesContent":["import { createCli } from \"fumadb/cli\";\nimport type { InferFumaDB } from \"fumadb\";\nimport type { DimahS3DB } from \"./fuma-db\";\n\ndeclare const __DIMAH_S3_DB_VERSION__: string;\n\n/** Run the interactive FumaDB CLI (generate schema, migrate when using Kysely, etc.). */\nexport function runCli(db: InferFumaDB<typeof DimahS3DB>) {\n const { main } = createCli({\n db,\n command: \"dimah-s3-db\",\n description: \"FumaDB CLI for @dimah-s3/db\",\n version: __DIMAH_S3_DB_VERSION__,\n });\n\n return main();\n}\n"]}
1
+ {"version":3,"sources":["../src/schema/schema.ts","../src/fuma-db.ts","../src/cli.ts"],"names":[],"mappings":";;;;;AASA,SAAS,UAAU,IAAA,EAAc;AAC/B,EAAA,OAAO,MAAA,CAAO,IAAA,EAAM,QAAQ,CAAA,CAAE,QAAA,EAAS;AAKzC;AAOA,IAAM,aAAA,GAAgB,MAAM,gBAAA,EAAkB;AAAA,EAC5C,IAAI,QAAA,CAAS,IAAA,EAAM,cAAc,CAAA,CAAE,WAAW,MAAM,CAAA;AAAA;AAAA,EAEpD,KAAA,EAAO,MAAA,CAAO,OAAA,EAAS,QAAQ,CAAA;AAAA,EAC/B,MAAA,EAAQ,MAAA,CAAO,QAAA,EAAU,QAAQ,CAAA;AAAA,EACjC,GAAA,EAAK,MAAA,CAAO,KAAA,EAAO,QAAQ,CAAA;AAAA;AAAA,EAE3B,KAAA,EAA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,EAAW,UAAA;AAAA,EACX,OAAA,EAAS,CAAC,WAAA,EAAa,QAAQ;AACjC,CAAC;AAMM,IAAM,oBAAoB,QAAA,CAAS,OAAA;;;ACR1C,IAAM,4BAAY,IAAI,GAAA,CAAY,CAAC,mBAAA,EAAqB,iBAAiB,CAAC,CAAA;AAiBnE,SAAS,OAAO,MAAA,EAAwC;AAC7D,EAAA,MAAM,EAAE,IAAA,EAAK,GAAI,SAAA,CAAU;AAAA,IACzB,EAAA,EAAI,MAAA;AAAA,IACJ,OAAA,EAAS,aAAA;AAAA,IACT,WAAA,EAAa,6BAAA;AAAA,IACb,OAAA,EAAS;AAAA,GACV,CAAA;AAED,EAAA,OAAO,IAAA,EAAK;AACd;AAgBA,eAAsB,QAAQ,MAAA,EAAwC;AACpE,EAAA,IAAI,OAAA;AACJ,EAAA,IAAI;AACF,IAAA,OAAA,GAAU,MAAM,OAAO,OAAA,EAAQ;AAAA,EACjC,CAAA,CAAA,MAAQ;AACN,IAAA,OAAA,GAAU,MAAA;AAAA,EACZ;AACA,EAAA,IAAI,YAAY,MAAA,IAAa,CAAC,SAAA,CAAU,GAAA,CAAI,OAAO,CAAA,EAAG;AACpD,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,wCAAA,EAA2C,OAAO,CAAA,qDAAA,EAAwD,iBAAiB,CAAA,mBAAA;AAAA,KAC7H;AAAA,EACF;AACA,EAAA,MAAM,QAAA,GAAW,OAAO,cAAA,EAAe;AACvC,EAAA,KAAA,IAAS,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK,EAAG,MAAM,IAAA,GAAO,MAAM,QAAA,CAAS,IAAA,EAAK,EAAG;AACzE,IAAA,MAAA,CAAO,MAAM,QAAA,CAAS,EAAA,EAAG,EAAG,OAAA,EAAQ;AAAA,EACtC;AACF","file":"cli.js","sourcesContent":["import { column, idColumn, schema, table, type Column } from \"fumadb/schema\";\n\n/**\n * A byte count. The column is a `bigint` (int8 on PostgreSQL and MySQL), but\n * values are bound as numbers so SQLite stores a number instead of FumaDB's\n * 8-byte blob, which would sort after every number: INTEGER in the shipped\n * SQL, or REAL in a column FumaDB created, compared by value either way.\n * Drivers read int8 back as a number, a bigint, or a string.\n */\nfunction byteCount(name: string) {\n return column(name, \"bigint\").nullable() as unknown as Column<\n \"bigint\",\n number | null,\n number | bigint | string | null\n >;\n}\n\n/**\n * One row per tracked object:\n * `pending` (presigned) → `active` (confirmed) → `deleted` (soft delete).\n * `purging` marks a stale pending row that purge has claimed.\n */\nconst storageObject = table(\"storage_object\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n /** Owner, for example `user:123` or `org:acme`. */\n scope: column(\"scope\", \"string\"),\n bucket: column(\"bucket\", \"string\"),\n key: column(\"key\", \"string\"),\n /** Named dimah-s3 route that created the object. */\n route: column(\"route\", \"string\"),\n /** Logical folder path. `null` is the root. */\n folder: column(\"folder\", \"string\").nullable(),\n filename: column(\"filename\", \"string\"),\n contentType: column(\"content_type\", \"string\").nullable(),\n /** Verified size from HeadObject, set on confirm. */\n size: byteCount(\"size\"),\n /** Size the client declared before confirm. Quota counts it while pending. */\n declaredSize: byteCount(\"declared_size\"),\n eTag: column(\"e_tag\", \"string\").nullable(),\n status: column(\"status\", \"string\"),\n /** S3 user metadata of the verified object. */\n s3Metadata: column(\"s3_metadata\", \"json\").nullable(),\n /** App attributes, validated by the plugin's `attributes.schema`. */\n attributes: column(\"attributes\", \"json\").nullable(),\n acl: column(\"acl\", \"string\").nullable(),\n /** Multipart upload ID while the row is pending. */\n uploadId: column(\"upload_id\", \"string\").nullable(),\n /** Token of the upload ticket that wrote the row. Confirm and purge match it. */\n uploadToken: column(\"upload_token\", \"string\").nullable(),\n /** Confirm deadline of a pending row (the upload ticket's expiry). */\n expiresAt: column(\"expires_at\", \"timestamp\").nullable(),\n confirmedAt: column(\"confirmed_at\", \"timestamp\").nullable(),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n updatedAt: column(\"updated_at\", \"timestamp\").defaultTo$(\"now\"),\n deletedAt: column(\"deleted_at\", \"timestamp\").nullable(),\n}).unique(\"storage_object_bucket_key_uk\", [\"bucket\", \"key\"]);\n\n/** One row per folder, so an empty folder still lists. */\nconst storageFolder = table(\"storage_folder\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n scope: column(\"scope\", \"string\"),\n /** Full folder path. */\n path: column(\"path\", \"string\"),\n /** Path of the containing folder. `null` is the root. */\n parent: column(\"parent\", \"string\").nullable(),\n /** Last segment of `path`. */\n name: column(\"name\", \"string\"),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n}).unique(\"storage_folder_scope_path_uk\", [\"scope\", \"path\"]);\n\n/** A secondary index, by SQL table and column names. */\nexport type SchemaIndex = {\n name: string;\n table: \"storage_object\" | \"storage_folder\";\n columns: readonly string[];\n};\n\n/**\n * Secondary indexes. FumaDB cannot declare them, so {@link dbSchema}'s\n * migration, the SQL files, the Drizzle tables, and the Prisma schema carry\n * them.\n */\nexport const schemaIndexes: readonly SchemaIndex[] = [\n {\n name: \"storage_object_scope_folder_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"folder\", \"created_at\"],\n },\n {\n name: \"storage_object_scope_updated_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"updated_at\"],\n },\n {\n name: \"storage_object_scope_filename_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"filename\"],\n },\n {\n name: \"storage_object_scope_size_idx\",\n table: \"storage_object\",\n columns: [\"scope\", \"status\", \"size\"],\n },\n {\n name: \"storage_object_status_expires_idx\",\n table: \"storage_object\",\n columns: [\"status\", \"expires_at\"],\n },\n {\n name: \"storage_folder_scope_parent_idx\",\n table: \"storage_folder\",\n columns: [\"scope\", \"parent\"],\n },\n];\n\nconst custom = (sql: string) => ({ type: \"custom\" as const, sql });\n\n/**\n * FumaDB runs `up` only when migrating from the previous entry, and skips\n * `up` on the first one. This empty entry exists so {@link dbSchema} can\n * create the indexes on a new database. A finished database is at\n * {@link dbSchema}.\n */\nexport const PREDECESSOR_VERSION = \"0.0.1\";\n\nexport const predecessor = schema({\n version: PREDECESSOR_VERSION,\n tables: {},\n});\n\n/**\n * The @dimah-s3/db schema, version `2.0.0`. The migration creates the\n * secondary indexes after the tables, because FumaDB cannot declare them.\n */\nexport const dbSchema = schema({\n version: \"2.0.0\",\n tables: {\n storageObject,\n storageFolder,\n },\n async up({ auto }) {\n const indexes = schemaIndexes.map((index) => {\n const columns = index.columns.map((name) => `\"${name}\"`).join(\", \");\n return custom(\n `CREATE INDEX IF NOT EXISTS \"${index.name}\" ON \"${index.table}\" (${columns})`,\n );\n });\n return [...(await auto()), ...indexes];\n },\n});\n","import { fumadb, type InferFumaDB } from \"fumadb\";\nimport { dbSchema, predecessor } from \"./schema/schema\";\n\n/**\n * The @dimah-s3/db FumaDB library. Call `DimahS3DB.client(adapter)` with an\n * adapter from `@dimah-s3/db/adapters/*` to get a {@link DimahS3DbClient}.\n *\n * `predecessor` is empty. FumaDB skips `up` on the first schema, and the\n * indexes are created in {@link dbSchema}'s `up`.\n */\nexport const DimahS3DB = fumadb({\n namespace: \"dimah_s3\",\n schemas: [predecessor, dbSchema],\n});\n\n/** FumaDB client for the @dimah-s3/db schema. */\nexport type DimahS3DbClient = InferFumaDB<typeof DimahS3DB>;\n\n/** The schema version the stores read and write. */\nexport const DB_SCHEMA_VERSION = dbSchema.version;\n","import { createCli } from \"fumadb/cli\";\nimport { DB_SCHEMA_VERSION, type DimahS3DbClient } from \"./fuma-db\";\nimport { PREDECESSOR_VERSION } from \"./schema/schema\";\n\ndeclare const __DIMAH_S3_DB_VERSION__: string;\n\n/**\n * Versions `migrate` may continue from: an empty database, a migration that\n * stopped on the empty predecessor, or a database already at\n * {@link DB_SCHEMA_VERSION}.\n */\nconst RESUMABLE = new Set<string>([PREDECESSOR_VERSION, DB_SCHEMA_VERSION]);\n\n/**\n * Runs the interactive FumaDB CLI: generate the ORM schema, or migrate when\n * the client uses the Kysely adapter. Prefer {@link migrate}. Only\n * `migrate:up`, one version at a time, runs the steps the schema needs,\n * including the indexes. The CLI `migrate` command jumps to the latest\n * schema and skips them.\n *\n * ```ts\n * // scripts/db.ts\n * import { runCli } from \"@dimah-s3/db/cli\";\n * import { dimahS3Db } from \"../lib/s3\";\n *\n * await runCli(dimahS3Db);\n * ```\n */\nexport function runCli(client: DimahS3DbClient): Promise<void> {\n const { main } = createCli({\n db: client,\n command: \"dimah-s3-db\",\n description: \"FumaDB CLI for @dimah-s3/db\",\n version: __DIMAH_S3_DB_VERSION__,\n });\n\n return main();\n}\n\n/**\n * Creates the schema this package reads, one version at a time, so the\n * schema's own steps run (the indexes among them). It needs the Kysely\n * adapter; with Drizzle or Prisma, use your ORM's migrations or the files\n * in `sql/`. It does not upgrade a database at another version.\n *\n * ```ts\n * import { DimahS3DB } from \"@dimah-s3/db\";\n * import { kyselyAdapter } from \"@dimah-s3/db/adapters/kysely\";\n * import { migrate } from \"@dimah-s3/db/cli\";\n *\n * await migrate(DimahS3DB.client(kyselyAdapter({ db: kysely, provider: \"postgresql\" })));\n * ```\n */\nexport async function migrate(client: DimahS3DbClient): Promise<void> {\n let version: string | undefined;\n try {\n version = await client.version();\n } catch {\n version = undefined;\n }\n if (version !== undefined && !RESUMABLE.has(version)) {\n throw new Error(\n `[dimah-s3/db] The database is at schema ${version}, which this package does not upgrade. Create schema ${DB_SCHEMA_VERSION} on a new database.`,\n );\n }\n const migrator = client.createMigrator();\n for (let next = await migrator.next(); next; next = await migrator.next()) {\n await (await migrator.up()).execute();\n }\n}\n"]}
@@ -1,98 +1,22 @@
1
- import type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject } from "../types/storage-object.js";
2
- export type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, } from "../types/storage-object.js";
1
+ import type { DbClientActions } from "../types/client.js";
3
2
  /**
4
- * Client plugin for the server `db()` endpoints.
3
+ * Client plugin for the server `db()` endpoints. Its actions are
4
+ * {@link DbClientActions} on `api.db`. Pass `TClientAttributes` to type the
5
+ * `attributes` the plugin's `attributes.toClient` returns.
5
6
  *
6
7
  * ```ts
7
8
  * import { createS3Client } from "@dimah-s3/react";
8
9
  * import { dbClient } from "@dimah-s3/db/client";
9
10
  *
10
- * export const { api, useApi } = createS3Client({
11
+ * export const s3Client = createS3Client({
11
12
  * plugins: [dbClient()],
12
13
  * });
13
14
  *
14
- * await api.db.listObjects({ limit: 50 });
15
+ * const page = await s3Client.db.listObjects({ folder: "" });
15
16
  * ```
16
17
  *
17
- * Server code does not use `listObjects` — it calls `s3.db.objects.listByScope`
18
- * and `getScopeUsage` directly (no HTTP round-trip). `listObjects` is the browser
19
- * wrapper for `GET /db/objects`.
18
+ * The server resolves the scope from the request, so no action takes one.
19
+ * Server code skips HTTP and uses `s3.db.objects` and `s3.db.folders`.
20
20
  */
21
- export declare function dbClient(): import("@dimah-s3/core").S3ClientPlugin<"db", {
22
- /**
23
- * List the caller's objects and usage. Scope comes from server `resolveScope`
24
- * — not a parameter here. For another scope, use `listByScope` on the server.
25
- * Pass `init.signal` to cancel the request.
26
- */
27
- listObjects: (input?: DbClientListInput, init?: {
28
- signal?: AbortSignal;
29
- }) => Promise<DbClientListResponse>;
30
- getObject: (input: DbClientGetInput) => Promise<{
31
- object: DbClientObject;
32
- }>;
33
- }, import("@dimah-s3/server").DimahS3Plugin<"db", {
34
- objects: import("..").StorageObjectStore;
35
- client: import("fumadb").FumaDB<import("fumadb/schema").Schema<"1.0.0", {
36
- storageObject: import("fumadb/schema").Table<{
37
- id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
38
- scope: import("fumadb/schema").Column<"string", string, string>;
39
- bucket: import("fumadb/schema").Column<"string", string, string>;
40
- key: import("fumadb/schema").Column<"string", string, string>;
41
- route: import("fumadb/schema").Column<"string", string, string>;
42
- contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
43
- size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
44
- eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
45
- filename: import("fumadb/schema").Column<"string", string | null, string | null>;
46
- status: import("fumadb/schema").Column<"string", string, string>;
47
- metadata: import("fumadb/schema").Column<"json", unknown, unknown>;
48
- acl: import("fumadb/schema").Column<"string", string | null, string | null>;
49
- uploadId: import("fumadb/schema").Column<"string", string | null, string | null>;
50
- declaredSize: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
51
- confirmedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
52
- expiresAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
53
- createdAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
54
- updatedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
55
- deletedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
56
- }, {}>;
57
- }>[]> | import("..").StorageObjectStore;
58
- }, {
59
- objects: import("better-call").StrictEndpoint<string, {
60
- use: import("better-call").MiddlewareHandler[];
61
- } & {
62
- method: "GET";
63
- } & {
64
- query: import("better-call").StandardSchemaV1<{
65
- status?: "active" | "deleted" | "pending" | undefined;
66
- limit?: string | number | undefined;
67
- offset?: string | number | undefined;
68
- cursor?: string | undefined;
69
- route?: string | undefined;
70
- contentType?: string | undefined;
71
- prefix?: string | undefined;
72
- }, {
73
- status?: "active" | "deleted" | "pending" | undefined;
74
- limit?: string | number | undefined;
75
- offset?: string | number | undefined;
76
- cursor?: string | undefined;
77
- route?: string | undefined;
78
- contentType?: string | undefined;
79
- prefix?: string | undefined;
80
- }>;
81
- }, DbClientListResponse>;
82
- object: import("better-call").StrictEndpoint<string, {
83
- use: import("better-call").MiddlewareHandler[];
84
- } & {
85
- method: "GET";
86
- } & {
87
- query: import("better-call").StandardSchemaV1<{
88
- key: string;
89
- bucket?: string | undefined;
90
- }, {
91
- key: string;
92
- bucket?: string | undefined;
93
- }>;
94
- }, {
95
- object: DbClientObject;
96
- }>;
97
- }>>;
21
+ export declare function dbClient<TClientAttributes = never>(): import("@dimah-s3/core").S3ClientPlugin<"db", DbClientActions<TClientAttributes>, import("@dimah-s3/server/plugins").DimahS3Plugin<"db", import("../plugin/db.js").DbPluginContext<unknown>>>;
98
22
  //# 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,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;;;;OAIG;0BAEO,iBAAiB,SAClB;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE;uBAOd,gBAAgB;gBAChB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMtC"}
1
+ {"version":3,"file":"db-client.d.ts","sourceRoot":"","sources":["../../src/client/db-client.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,eAAe,EAKhB,MAAM,gBAAgB,CAAC;AAaxB;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,iBAAiB,GAAG,KAAK,+LAkCjD"}
@@ -0,0 +1,25 @@
1
+ import type { DbClientActions, DbObjectSource, DbObjectSourceOptions } from "../types/client.js";
2
+ /** The `api.db` actions {@link dbObjectSource} calls. */
3
+ export type DbObjectSourceActions<TClientAttributes = never> = Pick<DbClientActions<TClientAttributes>, "listObjects"> & Partial<Pick<DbClientActions<TClientAttributes>, "createFolder">>;
4
+ /**
5
+ * A `useObjectList` source over `api.db`.
6
+ *
7
+ * With `folders` on (the default), `parent` is a folder path: each page
8
+ * lists one folder, the first page carries its child folders, uploads go to
9
+ * the open folder, and "New folder" calls `api.db.createFolder`. With
10
+ * `folders: false`, the list is flat and has no folder actions.
11
+ *
12
+ * `search` matches the filename on the server. `sort` maps `name` to
13
+ * `filename`; `size` and `updatedAt` keep their names, and other fields keep
14
+ * the server's order (newest first). `usage` is the scope total with its
15
+ * caps, not the open folder's.
16
+ *
17
+ * ```ts
18
+ * const list = useObjectList({
19
+ * ...dbObjectSource(api.db, { route: "docs" }),
20
+ * queryKey: ["docs"],
21
+ * });
22
+ * ```
23
+ */
24
+ export declare function dbObjectSource<TClientAttributes = never>(db: DbObjectSourceActions<TClientAttributes>, options?: DbObjectSourceOptions): DbObjectSource<TClientAttributes>;
25
+ //# sourceMappingURL=db-object-source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db-object-source.d.ts","sourceRoot":"","sources":["../../src/client/db-object-source.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EAKf,cAAc,EAEd,qBAAqB,EAEtB,MAAM,gBAAgB,CAAC;AAExB,yDAAyD;AACzD,MAAM,MAAM,qBAAqB,CAAC,iBAAiB,GAAG,KAAK,IAAI,IAAI,CACjE,eAAe,CAAC,iBAAiB,CAAC,EAClC,aAAa,CACd,GACC,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;AA0BpE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,cAAc,CAAC,iBAAiB,GAAG,KAAK,EACtD,EAAE,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,EAC5C,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAAC,iBAAiB,CAAC,CAiDnC"}
@@ -1,5 +1,5 @@
1
1
  export { dbClient } from "./db-client";
2
- export { dbObjectQuery, type DbObjectListSource, type DbObjectQueryInput, type DbObjectQueryOptions, type DbObjectQueryPage, } from "./db-object-query";
3
- export { dbObjectListAccessors, type DbObjectListAccessors, type DbObjectListAccessorsOptions, } from "./db-object-list-accessors";
4
- export type { DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, } from "./db-client";
2
+ export { dbObjectSource, type DbObjectSourceActions } from "./db-object-source";
3
+ export type { DbClientActions, DbClientFolder, DbClientFolderInput, DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, DbClientObjectStatus, DbClientUpdateInput, DbListSort, DbListSortField, DbObjectSource, DbObjectSourceFile, DbObjectSourceFolder, DbObjectSourceOptions, DbObjectSourcePage, DbObjectSourceQueryInput, DbQuota, DbUsage, } from "../types/client.js";
4
+ export type { StorageObjectStatus } from "../types/storage-object.js";
5
5
  //# 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,OAAO,EACL,aAAa,EACb,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,iBAAiB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,qBAAqB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,4BAA4B,GAClC,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,gBAAgB,EAChB,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,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,YAAY,EACV,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EAClB,wBAAwB,EACxB,OAAO,EACP,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC"}