@dimah-s3/db 2.0.0-beta.1 → 2.0.0-beta.2
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/README.md +1 -1
- package/dist/cli.js +12 -16
- package/dist/cli.js.map +1 -1
- package/dist/client/db-client.d.ts +1 -1
- package/dist/client/db-client.d.ts.map +1 -1
- package/dist/client/db-object-source.d.ts +5 -4
- package/dist/client/db-object-source.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +27 -12
- package/dist/client/index.js.map +1 -1
- package/dist/drizzle/mysql.d.ts +44 -12
- package/dist/drizzle/mysql.d.ts.map +1 -1
- package/dist/drizzle/mysql.js +11 -8
- package/dist/drizzle/mysql.js.map +1 -1
- package/dist/drizzle/pg.d.ts +42 -12
- package/dist/drizzle/pg.d.ts.map +1 -1
- package/dist/drizzle/pg.js +13 -7
- package/dist/drizzle/pg.js.map +1 -1
- package/dist/drizzle/shared.d.ts +1 -1
- package/dist/drizzle/sqlite.d.ts +44 -12
- package/dist/drizzle/sqlite.d.ts.map +1 -1
- package/dist/drizzle/sqlite.js +13 -7
- package/dist/drizzle/sqlite.js.map +1 -1
- package/dist/folder-path.d.ts +9 -2
- package/dist/folder-path.d.ts.map +1 -1
- package/dist/fuma-db.d.ts +6 -5
- package/dist/fuma-db.d.ts.map +1 -1
- package/dist/index.js +347 -170
- package/dist/index.js.map +1 -1
- package/dist/plugin/create-database-endpoints.d.ts +38 -18
- package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
- package/dist/plugin/create-database-lifecycle-hooks.d.ts +1 -1
- package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
- package/dist/plugin/db.d.ts.map +1 -1
- package/dist/plugin/object-access.d.ts +1 -1
- package/dist/plugin/object-access.d.ts.map +1 -1
- package/dist/plugin/public-stores.d.ts +4 -7
- package/dist/plugin/public-stores.d.ts.map +1 -1
- package/dist/plugin/schemas.d.ts +21 -12
- package/dist/plugin/schemas.d.ts.map +1 -1
- package/dist/plugin/to-db-client-object.d.ts.map +1 -1
- package/dist/schema/schema.d.ts +9 -8
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/store/folder-store.d.ts +41 -14
- package/dist/store/folder-store.d.ts.map +1 -1
- package/dist/store/list-cursor.d.ts +1 -1
- package/dist/store/list-cursor.d.ts.map +1 -1
- package/dist/store/map-row.d.ts +1 -1
- package/dist/store/map-row.d.ts.map +1 -1
- package/dist/store/object-store.d.ts +5 -5
- package/dist/store/object-store.d.ts.map +1 -1
- package/dist/types/client.d.ts +47 -18
- package/dist/types/client.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +6 -1
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/storage-object.d.ts +8 -7
- package/dist/types/storage-object.d.ts.map +1 -1
- package/package.json +5 -5
- package/prisma/dimah-s3.prisma +14 -13
- package/sql/mysql.sql +12 -11
- package/sql/pg.sql +10 -10
- package/sql/sqlite.sql +10 -9
- package/src/drizzle/mysql.ts +10 -7
- package/src/drizzle/pg.ts +12 -6
- package/src/drizzle/sqlite.ts +12 -6
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ Create the schema with one of:
|
|
|
23
23
|
- Plain SQL: run [`sql/<dialect>.sql`](./sql).
|
|
24
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
25
|
|
|
26
|
-
The package reads schema `2.
|
|
26
|
+
The package reads schema `2.1.0` and does not upgrade a 1.x or `2.0.0` 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
27
|
|
|
28
28
|
## Server
|
|
29
29
|
|
package/dist/cli.js
CHANGED
|
@@ -14,8 +14,8 @@ var storageObject = table("storage_object", {
|
|
|
14
14
|
key: column("key", "string"),
|
|
15
15
|
/** Named dimah-s3 route that created the object. */
|
|
16
16
|
route: column("route", "string"),
|
|
17
|
-
/**
|
|
18
|
-
|
|
17
|
+
/** Folder that holds the object. `null` is the root. */
|
|
18
|
+
folderId: column("folder_id", "string").nullable(),
|
|
19
19
|
filename: column("filename", "string"),
|
|
20
20
|
contentType: column("content_type", "string").nullable(),
|
|
21
21
|
/** Verified size from HeadObject, set on confirm. */
|
|
@@ -43,19 +43,20 @@ var storageObject = table("storage_object", {
|
|
|
43
43
|
var storageFolder = table("storage_folder", {
|
|
44
44
|
id: idColumn("id", "varchar(255)").defaultTo$("auto"),
|
|
45
45
|
scope: column("scope", "string"),
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
/** Path of the containing folder. `null` is the root. */
|
|
49
|
-
parent: column("parent", "string").nullable(),
|
|
46
|
+
/** Id of the containing folder. `""` is the root. */
|
|
47
|
+
parentId: column("parent_id", "string"),
|
|
50
48
|
/** Last segment of `path`. */
|
|
51
49
|
name: column("name", "string"),
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
/** Full folder path. */
|
|
51
|
+
path: column("path", "string"),
|
|
52
|
+
createdAt: column("created_at", "timestamp").defaultTo$("now"),
|
|
53
|
+
updatedAt: column("updated_at", "timestamp").defaultTo$("now")
|
|
54
|
+
}).unique("storage_folder_scope_path_uk", ["scope", "path"]).unique("storage_folder_scope_parent_name_uk", ["scope", "parentId", "name"]);
|
|
54
55
|
var schemaIndexes = [
|
|
55
56
|
{
|
|
56
57
|
name: "storage_object_scope_folder_idx",
|
|
57
58
|
table: "storage_object",
|
|
58
|
-
columns: ["scope", "status", "
|
|
59
|
+
columns: ["scope", "status", "folder_id", "created_at"]
|
|
59
60
|
},
|
|
60
61
|
{
|
|
61
62
|
name: "storage_object_scope_updated_idx",
|
|
@@ -76,11 +77,6 @@ var schemaIndexes = [
|
|
|
76
77
|
name: "storage_object_status_expires_idx",
|
|
77
78
|
table: "storage_object",
|
|
78
79
|
columns: ["status", "expires_at"]
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
name: "storage_folder_scope_parent_idx",
|
|
82
|
-
table: "storage_folder",
|
|
83
|
-
columns: ["scope", "parent"]
|
|
84
80
|
}
|
|
85
81
|
];
|
|
86
82
|
var custom = (sql) => ({ type: "custom", sql });
|
|
@@ -90,7 +86,7 @@ var predecessor = schema({
|
|
|
90
86
|
tables: {}
|
|
91
87
|
});
|
|
92
88
|
var dbSchema = schema({
|
|
93
|
-
version: "2.
|
|
89
|
+
version: "2.1.0",
|
|
94
90
|
tables: {
|
|
95
91
|
storageObject,
|
|
96
92
|
storageFolder
|
|
@@ -120,7 +116,7 @@ function runCli(client) {
|
|
|
120
116
|
db: client,
|
|
121
117
|
command: "dimah-s3-db",
|
|
122
118
|
description: "FumaDB CLI for @dimah-s3/db",
|
|
123
|
-
version: "2.0.0-beta.
|
|
119
|
+
version: "2.0.0-beta.2"
|
|
124
120
|
});
|
|
125
121
|
return main();
|
|
126
122
|
}
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,EAAO,MAAA,CAAO,OAAA,EAAS,QAAQ,CA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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
|
+
{"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,IAA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AA,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 /** Folder that holds the object. `null` is the root. */\n folderId: column(\"folder_id\", \"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/**\n * One row per folder, so an empty folder still lists. `parentId` is `\"\"` at\n * the root: a nullable parent cannot be unique on PostgreSQL, MySQL, and\n * SQLite, and the root is not a row. `path` is a cache of `name` joined\n * through the parents, rewritten when a folder is renamed or moved.\n */\nconst storageFolder = table(\"storage_folder\", {\n id: idColumn(\"id\", \"varchar(255)\").defaultTo$(\"auto\"),\n scope: column(\"scope\", \"string\"),\n /** Id of the containing folder. `\"\"` is the root. */\n parentId: column(\"parent_id\", \"string\"),\n /** Last segment of `path`. */\n name: column(\"name\", \"string\"),\n /** Full folder path. */\n path: column(\"path\", \"string\"),\n createdAt: column(\"created_at\", \"timestamp\").defaultTo$(\"now\"),\n updatedAt: column(\"updated_at\", \"timestamp\").defaultTo$(\"now\"),\n})\n .unique(\"storage_folder_scope_path_uk\", [\"scope\", \"path\"])\n .unique(\"storage_folder_scope_parent_name_uk\", [\"scope\", \"parentId\", \"name\"]);\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_id\", \"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\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.1.0`. The migration creates the\n * secondary indexes after the tables, because FumaDB cannot declare them.\n */\nexport const dbSchema = schema({\n version: \"2.1.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"]}
|
|
@@ -12,7 +12,7 @@ import type { DbClientActions } from "../types/client.js";
|
|
|
12
12
|
* plugins: [dbClient()],
|
|
13
13
|
* });
|
|
14
14
|
*
|
|
15
|
-
* const page = await s3Client.db.listObjects({
|
|
15
|
+
* const page = await s3Client.db.listObjects({ folderId: "" });
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
18
|
* The server resolves the scope from the request, so no action takes one.
|
|
@@ -1 +1 @@
|
|
|
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,+
|
|
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,+LAwCjD"}
|
|
@@ -4,10 +4,11 @@ export type DbObjectSourceActions<TClientAttributes = never> = Pick<DbClientActi
|
|
|
4
4
|
/**
|
|
5
5
|
* A `useObjectList` source over `api.db`.
|
|
6
6
|
*
|
|
7
|
-
* With `folders` on (the default), `parent` is a folder
|
|
8
|
-
*
|
|
9
|
-
* the open folder, and "New folder" calls
|
|
10
|
-
* `folders: false`, the list is flat and has no
|
|
7
|
+
* With `folders` on (the default), `parent` is a folder id: each page lists
|
|
8
|
+
* one folder, the first page carries its child folders and the breadcrumb
|
|
9
|
+
* trail, uploads go to the open folder, and "New folder" calls
|
|
10
|
+
* `api.db.createFolder`. With `folders: false`, the list is flat and has no
|
|
11
|
+
* folder actions.
|
|
11
12
|
*
|
|
12
13
|
* `search` matches the filename on the server. `sort` maps `name` to
|
|
13
14
|
* `filename`; `size` and `updatedAt` keep their names, and other fields keep
|
|
@@ -1 +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
|
|
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;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,iBAAiB,GAAG,KAAK,EACtD,EAAE,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,EAC5C,OAAO,GAAE,qBAA0B,GAClC,cAAc,CAAC,iBAAiB,CAAC,CAwDnC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { dbClient } from "./db-client";
|
|
2
2
|
export { dbObjectSource, type DbObjectSourceActions } from "./db-object-source";
|
|
3
|
-
export type { DbClientActions,
|
|
3
|
+
export type { DbClientActions, DbClientCreateFolderInput, DbClientDeleteFolderInput, DbClientFolder, DbClientGetInput, DbClientListInput, DbClientListResponse, DbClientObject, DbClientObjectStatus, DbClientUpdateFolderInput, DbClientUpdateInput, DbListSort, DbListSortField, DbObjectSource, DbObjectSourceFile, DbObjectSourceFolder, DbObjectSourceOptions, DbObjectSourcePage, DbObjectSourceQueryInput, DbQuota, DbUsage, } from "../types/client.js";
|
|
4
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,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,YAAY,EACV,eAAe,EACf,cAAc,EACd,
|
|
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,yBAAyB,EACzB,yBAAyB,EACzB,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,cAAc,EACd,oBAAoB,EACpB,yBAAyB,EACzB,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"}
|
package/dist/client/index.js
CHANGED
|
@@ -5,8 +5,8 @@ function call(options) {
|
|
|
5
5
|
return { signal: options?.signal, headers: options?.headers };
|
|
6
6
|
}
|
|
7
7
|
function listQuery(input) {
|
|
8
|
-
if (input?.
|
|
9
|
-
return { ...input,
|
|
8
|
+
if (input?.folderId !== null) return input;
|
|
9
|
+
return { ...input, folderId: "" };
|
|
10
10
|
}
|
|
11
11
|
function dbClient() {
|
|
12
12
|
return defineClientPlugin({
|
|
@@ -30,6 +30,11 @@ function dbClient() {
|
|
|
30
30
|
body: input,
|
|
31
31
|
...call(options)
|
|
32
32
|
}),
|
|
33
|
+
updateFolder: (input, options) => $fetch(pluginPath("db", "folder"), {
|
|
34
|
+
method: "PATCH",
|
|
35
|
+
body: input,
|
|
36
|
+
...call(options)
|
|
37
|
+
}),
|
|
33
38
|
deleteFolder: (input, options) => $fetch(pluginPath("db", "folder"), {
|
|
34
39
|
method: "DELETE",
|
|
35
40
|
query: input,
|
|
@@ -38,11 +43,14 @@ function dbClient() {
|
|
|
38
43
|
})
|
|
39
44
|
});
|
|
40
45
|
}
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
var FOLDER_NAME_MAX_LENGTH = 255;
|
|
47
|
+
var INVALID_CHARACTER = /[\p{Cc}\p{Cs}]/u;
|
|
48
|
+
function characterCount(value) {
|
|
49
|
+
return Array.from(value).length;
|
|
43
50
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
51
|
+
function isFolderName(name) {
|
|
52
|
+
const length = characterCount(name);
|
|
53
|
+
return length >= 1 && length <= FOLDER_NAME_MAX_LENGTH && name !== "." && name !== ".." && !name.includes("/") && !INVALID_CHARACTER.test(name);
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
// src/client/db-object-source.ts
|
|
@@ -71,7 +79,7 @@ function dbObjectSource(db, options = {}) {
|
|
|
71
79
|
getFile: toFile,
|
|
72
80
|
async query({ parent, cursor, sort, search, signal }) {
|
|
73
81
|
const input = {};
|
|
74
|
-
if (folders) input.
|
|
82
|
+
if (folders) input.folderId = parent ?? "";
|
|
75
83
|
if (cursor) input.cursor = cursor;
|
|
76
84
|
if (search) input.search = search;
|
|
77
85
|
const listSort = toListSort(sort);
|
|
@@ -86,7 +94,13 @@ function dbObjectSource(db, options = {}) {
|
|
|
86
94
|
nextCursor: page.nextCursor,
|
|
87
95
|
...page.folders && {
|
|
88
96
|
folders: page.folders.map((folder) => ({
|
|
89
|
-
id: folder.
|
|
97
|
+
id: folder.id,
|
|
98
|
+
name: folder.name
|
|
99
|
+
}))
|
|
100
|
+
},
|
|
101
|
+
...page.trail && {
|
|
102
|
+
trail: page.trail.map((folder) => ({
|
|
103
|
+
id: folder.id,
|
|
90
104
|
name: folder.name
|
|
91
105
|
}))
|
|
92
106
|
},
|
|
@@ -96,16 +110,17 @@ function dbObjectSource(db, options = {}) {
|
|
|
96
110
|
};
|
|
97
111
|
if (!folders) return source;
|
|
98
112
|
source.uploadOptions = (parent) => ({
|
|
99
|
-
metadata: {
|
|
113
|
+
metadata: { folderId: parent ?? "" }
|
|
100
114
|
});
|
|
101
115
|
const createFolder = db.createFolder?.bind(db);
|
|
102
116
|
if (createFolder) {
|
|
103
117
|
source.createFolder = async ({ parent, name }) => {
|
|
104
|
-
if (name
|
|
118
|
+
if (!isFolderName(name)) throw s3Error("FOLDER_INVALID");
|
|
105
119
|
const { folder } = await createFolder({
|
|
106
|
-
|
|
120
|
+
parentId: parent,
|
|
121
|
+
name
|
|
107
122
|
});
|
|
108
|
-
return { id: folder.
|
|
123
|
+
return { id: folder.id, name: folder.name };
|
|
109
124
|
};
|
|
110
125
|
}
|
|
111
126
|
return source;
|
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":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AAQ,GAAA,CAAI,CAAC,MAAA,MAAY;AAAA,YACrC,IAAI,MAAA,CAAO,IAAA;AAAA,YACX,MAAM,MAAA,CAAO;AAAA,WACf,CAAE;AAAA,SACJ;AAAA,QACA,GAAI,IAAA,CAAK,KAAA,IAAS,EAAE,KAAA,EAAO,EAAE,GAAG,IAAA,CAAK,KAAA,EAAO,GAAG,IAAA,CAAK,MAAA,EAAO;AAAE,OAC/D;AAAA,IACF;AAAA,GACF;AACA,EAAA,IAAI,CAAC,SAAS,OAAO,MAAA;AAErB,EAAA,MAAA,CAAO,aAAA,GAAgB,CAAC,MAAA,MAAY;AAAA,IAClC,QAAA,EAAU,EAAE,MAAA,EAAQ,YAAA,CAAa,MAAM,CAAA;AAAE,GAC3C,CAAA;AACA,EAAA,MAAM,YAAA,GAAe,EAAA,CAAG,YAAA,EAAc,IAAA,CAAK,EAAE,CAAA;AAC7C,EAAA,IAAI,YAAA,EAAc;AAChB,IAAA,MAAA,CAAO,YAAA,GAAe,OAAO,EAAE,MAAA,EAAQ,MAAK,KAAM;AAEhD,MAAA,IAAI,KAAK,QAAA,CAAS,GAAG,CAAA,EAAG,MAAMA,QAAQ,gBAAgB,CAAA;AACtD,MAAA,MAAM,EAAE,MAAA,EAAO,GAAI,MAAM,YAAA,CAAa;AAAA,QACpC,IAAA,EAAM,cAAA,CAAe,MAAA,EAAQ,IAAI;AAAA,OAClC,CAAA;AACD,MAAA,OAAO,EAAE,EAAA,EAAI,MAAA,CAAO,IAAA,EAAM,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,IAC9C,CAAA;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import {\n defineClientPlugin,\n pluginPath,\n type S3RequestOptions,\n} from \"@dimah-s3/core\";\nimport type { db } from \"@/plugin/db\";\nimport type {\n DbClientActions,\n DbClientFolder,\n DbClientListInput,\n DbClientListResponse,\n DbClientObject,\n} from \"@/types/client\";\n\n/** The per-call options better-fetch reads: the abort signal and headers. */\nfunction call(options: S3RequestOptions | undefined) {\n return { signal: options?.signal, headers: options?.headers };\n}\n\n/** The list query on the wire, where the root folder is `\"\"`. */\nfunction listQuery(input: DbClientListInput | undefined) {\n if (input?.folder !== null) return input;\n return { ...input, folder: \"\" };\n}\n\n/**\n * Client plugin for the server `db()` endpoints. Its actions are\n * {@link DbClientActions} on `api.db`. Pass `TClientAttributes` to type the\n * `attributes` the plugin's `attributes.toClient` returns.\n *\n * ```ts\n * import { createS3Client } from \"@dimah-s3/react\";\n * import { dbClient } from \"@dimah-s3/db/client\";\n *\n * export const s3Client = createS3Client({\n * plugins: [dbClient()],\n * });\n *\n * const page = await s3Client.db.listObjects({ folder: \"\" });\n * ```\n *\n * The server resolves the scope from the request, so no action takes one.\n * Server code skips HTTP and uses `s3.db.objects` and `s3.db.folders`.\n */\nexport function dbClient<TClientAttributes = never>() {\n return defineClientPlugin({\n id: \"db\",\n $InferServerPlugin: {} as ReturnType<typeof db>,\n getActions: ($fetch): DbClientActions<TClientAttributes> => ({\n listObjects: (input, options) =>\n $fetch<DbClientListResponse<TClientAttributes>>(\n pluginPath(\"db\", \"objects\"),\n { method: \"GET\", query: listQuery(input), ...call(options) },\n ),\n getObject: (input, options) =>\n $fetch<{ object: DbClientObject<TClientAttributes> }>(\n pluginPath(\"db\", \"object\"),\n { method: \"GET\", query: input, ...call(options) },\n ),\n updateObject: (input, options) =>\n $fetch<{ object: DbClientObject<TClientAttributes> }>(\n pluginPath(\"db\", \"object\"),\n { method: \"PATCH\", body: input, ...call(options) },\n ),\n createFolder: (input, options) =>\n $fetch<{ folder: DbClientFolder }>(pluginPath(\"db\", \"folder\"), {\n method: \"POST\",\n body: input,\n ...call(options),\n }),\n deleteFolder: (input, options) =>\n $fetch<{ path: string }>(pluginPath(\"db\", \"folder\"), {\n method: \"DELETE\",\n query: input,\n ...call(options),\n }),\n }),\n });\n}\n","import { s3Error } from \"@dimah-s3/core\";\n\n/**\n * Logical folder paths. A path is NFC-normalized and `/`-separated, with no\n * leading or trailing `/`. `null` is the root in types and JSON. On the wire\n * (`?folder=`, `clientMetadata.folder`) the root is `\"\"`.\n */\n\n/** Longest folder path, in characters. */\nexport const FOLDER_PATH_MAX_LENGTH = 1024;\n\n/** Longest folder name (one path segment), in characters. */\nexport const FOLDER_NAME_MAX_LENGTH = 255;\n\n/** Most segments in a folder path. Each one is a row the server keeps. */\nexport const FOLDER_MAX_DEPTH = 32;\n\n/** Control characters and lone surrogates. */\nconst INVALID_CHARACTER = /[\\p{Cc}\\p{Cs}]/u;\n\n/** Counts code points, so a character outside the BMP counts once. */\nfunction characterCount(value: string): number {\n return Array.from(value).length;\n}\n\nfunction isValidName(name: string): boolean {\n const length = characterCount(name);\n return (\n length >= 1 &&\n length <= FOLDER_NAME_MAX_LENGTH &&\n name !== \".\" &&\n name !== \"..\" &&\n !INVALID_CHARACTER.test(name)\n );\n}\n\n/**\n * Returns the NFC form of `path`, or `null` when it is not a valid folder\n * path. The root (`\"\"`) is not a folder path.\n */\nexport function normalizeFolderPath(path: string): string | null {\n if (!path.isWellFormed()) return null;\n const normalized = path.normalize(\"NFC\");\n if (characterCount(normalized) > FOLDER_PATH_MAX_LENGTH) return null;\n const names = normalized.split(\"/\");\n if (names.length > FOLDER_MAX_DEPTH) return null;\n return names.every(isValidName) ? normalized : null;\n}\n\n/**\n * Reads a wire folder value. `\"\"` is the root and returns `null`.\n * @throws `FOLDER_INVALID` when the value is not a valid folder path.\n */\nexport function parseFolder(value: string): string | null {\n if (value === \"\") return null;\n const path = normalizeFolderPath(value);\n if (path === null) throw s3Error(\"FOLDER_INVALID\");\n return path;\n}\n\n/** Writes a folder for the wire. The root becomes `\"\"`. */\nexport function formatFolder(folder: string | null): string {\n return folder ?? \"\";\n}\n\n/** Appends `name` to `parent`. The result is not validated. */\nexport function joinFolderPath(parent: string | null, name: string): string {\n return parent === null ? name : `${parent}/${name}`;\n}\n\n/** The folder that contains `path`. `null` for a top-level folder. */\nexport function parentFolderPath(path: string): string | null {\n const index = path.lastIndexOf(\"/\");\n return index === -1 ? null : path.slice(0, index);\n}\n\n/** The last segment of `path`. */\nexport function folderName(path: string): string {\n return path.slice(path.lastIndexOf(\"/\") + 1);\n}\n\n/** Every folder from the top level down to `path` itself. */\nexport function folderAncestors(path: string): string[] {\n const segments = path.split(\"/\");\n return segments.map((_, index) => segments.slice(0, index + 1).join(\"/\"));\n}\n","import { s3Error } from \"@dimah-s3/core\";\nimport { formatFolder, joinFolderPath } from \"@/folder-path\";\nimport type {\n DbClientActions,\n DbClientListInput,\n DbClientObject,\n DbListSort,\n DbListSortField,\n DbObjectSource,\n DbObjectSourceFile,\n DbObjectSourceOptions,\n DbObjectSourceQueryInput,\n} from \"@/types/client\";\n\n/** The `api.db` actions {@link dbObjectSource} calls. */\nexport type DbObjectSourceActions<TClientAttributes = never> = Pick<\n DbClientActions<TClientAttributes>,\n \"listObjects\"\n> &\n Partial<Pick<DbClientActions<TClientAttributes>, \"createFolder\">>;\n\n/** List sort fields and the `listObjects` columns they order by. */\nconst SORT_FIELDS = new Map<string, DbListSortField>([\n [\"name\", \"filename\"],\n [\"size\", \"size\"],\n [\"updatedAt\", \"updatedAt\"],\n]);\n\nfunction toListSort(\n sort: DbObjectSourceQueryInput[\"sort\"],\n): DbListSort | undefined {\n const field = sort ? SORT_FIELDS.get(sort.field) : undefined;\n return sort && field ? { field, direction: sort.direction } : undefined;\n}\n\nfunction toFile(object: DbClientObject<unknown>): DbObjectSourceFile {\n return {\n name: object.filename,\n objectKey: object.key,\n size: object.size,\n contentType: object.contentType,\n updatedAt: object.updatedAt,\n };\n}\n\n/**\n * A `useObjectList` source over `api.db`.\n *\n * With `folders` on (the default), `parent` is a folder path: each page\n * lists one folder, the first page carries its child folders, uploads go to\n * the open folder, and \"New folder\" calls `api.db.createFolder`. With\n * `folders: false`, the list is flat and has no folder actions.\n *\n * `search` matches the filename on the server. `sort` maps `name` to\n * `filename`; `size` and `updatedAt` keep their names, and other fields keep\n * the server's order (newest first). `usage` is the scope total with its\n * caps, not the open folder's.\n *\n * ```ts\n * const list = useObjectList({\n * ...dbObjectSource(api.db, { route: \"docs\" }),\n * queryKey: [\"docs\"],\n * });\n * ```\n */\nexport function dbObjectSource<TClientAttributes = never>(\n db: DbObjectSourceActions<TClientAttributes>,\n options: DbObjectSourceOptions = {},\n): DbObjectSource<TClientAttributes> {\n const folders = options.folders !== false;\n\n const source: DbObjectSource<TClientAttributes> = {\n getKey: (item) => item.id,\n getFile: toFile,\n async query({ parent, cursor, sort, search, signal }) {\n const input: DbClientListInput = {};\n if (folders) input.folder = formatFolder(parent);\n if (cursor) input.cursor = cursor;\n if (search) input.search = search;\n const listSort = toListSort(sort);\n if (listSort) input.sort = listSort;\n if (options.route) input.route = options.route;\n if (options.status) input.status = options.status;\n if (options.contentType) input.contentType = options.contentType;\n if (options.limit !== undefined) input.limit = options.limit;\n\n const page = await db.listObjects(input, { signal });\n return {\n items: page.objects,\n nextCursor: page.nextCursor,\n ...(page.folders && {\n folders: page.folders.map((folder) => ({\n id: folder.path,\n name: folder.name,\n })),\n }),\n ...(page.usage && { usage: { ...page.usage, ...page.limits } }),\n };\n },\n };\n if (!folders) return source;\n\n source.uploadOptions = (parent) => ({\n metadata: { folder: formatFolder(parent) },\n });\n const createFolder = db.createFolder?.bind(db);\n if (createFolder) {\n source.createFolder = async ({ parent, name }) => {\n // A `/` would create a nested folder instead of a child of `parent`.\n if (name.includes(\"/\")) throw s3Error(\"FOLDER_INVALID\");\n const { folder } = await createFolder({\n path: joinFolderPath(parent, name),\n });\n return { id: folder.path, name: folder.name };\n };\n }\n return source;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/client/db-client.ts","../../src/folder-path.ts","../../src/client/db-object-source.ts"],"names":["s3Error"],"mappings":";;;AAeA,SAAS,KAAK,OAAA,EAAuC;AACnD,EAAA,OAAO,EAAE,MAAA,EAAQ,OAAA,EAAS,MAAA,EAAQ,OAAA,EAAS,SAAS,OAAA,EAAQ;AAC9D;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AA,EAAU,MAAA;AAAA,QACV;AAAA,OACD,CAAA;AACD,MAAA,OAAO,EAAE,EAAA,EAAI,MAAA,CAAO,EAAA,EAAI,IAAA,EAAM,OAAO,IAAA,EAAK;AAAA,IAC5C,CAAA;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT","file":"index.js","sourcesContent":["import {\n defineClientPlugin,\n pluginPath,\n type S3RequestOptions,\n} from \"@dimah-s3/core\";\nimport type { db } from \"@/plugin/db\";\nimport type {\n DbClientActions,\n DbClientFolder,\n DbClientListInput,\n DbClientListResponse,\n DbClientObject,\n} from \"@/types/client\";\n\n/** The per-call options better-fetch reads: the abort signal and headers. */\nfunction call(options: S3RequestOptions | undefined) {\n return { signal: options?.signal, headers: options?.headers };\n}\n\n/** The list query on the wire, where the root folder is `\"\"`. */\nfunction listQuery(input: DbClientListInput | undefined) {\n if (input?.folderId !== null) return input;\n return { ...input, folderId: \"\" };\n}\n\n/**\n * Client plugin for the server `db()` endpoints. Its actions are\n * {@link DbClientActions} on `api.db`. Pass `TClientAttributes` to type the\n * `attributes` the plugin's `attributes.toClient` returns.\n *\n * ```ts\n * import { createS3Client } from \"@dimah-s3/react\";\n * import { dbClient } from \"@dimah-s3/db/client\";\n *\n * export const s3Client = createS3Client({\n * plugins: [dbClient()],\n * });\n *\n * const page = await s3Client.db.listObjects({ folderId: \"\" });\n * ```\n *\n * The server resolves the scope from the request, so no action takes one.\n * Server code skips HTTP and uses `s3.db.objects` and `s3.db.folders`.\n */\nexport function dbClient<TClientAttributes = never>() {\n return defineClientPlugin({\n id: \"db\",\n $InferServerPlugin: {} as ReturnType<typeof db>,\n getActions: ($fetch): DbClientActions<TClientAttributes> => ({\n listObjects: (input, options) =>\n $fetch<DbClientListResponse<TClientAttributes>>(\n pluginPath(\"db\", \"objects\"),\n { method: \"GET\", query: listQuery(input), ...call(options) },\n ),\n getObject: (input, options) =>\n $fetch<{ object: DbClientObject<TClientAttributes> }>(\n pluginPath(\"db\", \"object\"),\n { method: \"GET\", query: input, ...call(options) },\n ),\n updateObject: (input, options) =>\n $fetch<{ object: DbClientObject<TClientAttributes> }>(\n pluginPath(\"db\", \"object\"),\n { method: \"PATCH\", body: input, ...call(options) },\n ),\n createFolder: (input, options) =>\n $fetch<{ folder: DbClientFolder }>(pluginPath(\"db\", \"folder\"), {\n method: \"POST\",\n body: input,\n ...call(options),\n }),\n updateFolder: (input, options) =>\n $fetch<{ folder: DbClientFolder }>(pluginPath(\"db\", \"folder\"), {\n method: \"PATCH\",\n body: input,\n ...call(options),\n }),\n deleteFolder: (input, options) =>\n $fetch<{ id: string }>(pluginPath(\"db\", \"folder\"), {\n method: \"DELETE\",\n query: input,\n ...call(options),\n }),\n }),\n });\n}\n","import { s3Error } from \"@dimah-s3/core\";\n\n/**\n * Logical folder paths. A path is NFC-normalized and `/`-separated, with no\n * leading or trailing `/`. `null` is the root. The wire addresses a folder\n * by id; the path is the cached label of that id.\n */\n\n/** Longest folder path, in characters. */\nexport const FOLDER_PATH_MAX_LENGTH = 1024;\n\n/** Longest folder name (one path segment), in characters. */\nexport const FOLDER_NAME_MAX_LENGTH = 255;\n\n/** Most segments in a folder path. Each one is a row the server keeps. */\nexport const FOLDER_MAX_DEPTH = 32;\n\n/** Control characters and lone surrogates. */\nconst INVALID_CHARACTER = /[\\p{Cc}\\p{Cs}]/u;\n\n/** Counts code points, so a character outside the BMP counts once. */\nfunction characterCount(value: string): number {\n return Array.from(value).length;\n}\n\n/** True when `name` can be one segment of a folder path. */\nexport function isFolderName(name: string): boolean {\n const length = characterCount(name);\n return (\n length >= 1 &&\n length <= FOLDER_NAME_MAX_LENGTH &&\n name !== \".\" &&\n name !== \"..\" &&\n !name.includes(\"/\") &&\n !INVALID_CHARACTER.test(name)\n );\n}\n\n/**\n * Returns the NFC form of `path`, or `null` when it is not a valid folder\n * path. The root (`\"\"`) is not a folder path.\n */\nexport function normalizeFolderPath(path: string): string | null {\n if (!path.isWellFormed()) return null;\n const normalized = path.normalize(\"NFC\");\n if (characterCount(normalized) > FOLDER_PATH_MAX_LENGTH) return null;\n const names = normalized.split(\"/\");\n if (names.length > FOLDER_MAX_DEPTH) return null;\n return names.every(isFolderName) ? normalized : null;\n}\n\n/**\n * Reads a wire folder value. `\"\"` is the root and returns `null`.\n * @throws `FOLDER_INVALID` when the value is not a valid folder path.\n */\nexport function parseFolder(value: string): string | null {\n if (value === \"\") return null;\n const path = normalizeFolderPath(value);\n if (path === null) throw s3Error(\"FOLDER_INVALID\");\n return path;\n}\n\n/** Writes a folder for the wire. The root becomes `\"\"`. */\nexport function formatFolder(folder: string | null): string {\n return folder ?? \"\";\n}\n\n/**\n * The path of `name` inside `parent`. `null` when `name` is not a folder\n * name or the joined path is too long or too deep.\n */\nexport function childFolderPath(\n parent: string | null,\n name: string,\n): string | null {\n if (!isFolderName(name)) return null;\n return normalizeFolderPath(joinFolderPath(parent, name));\n}\n\n/** Appends `name` to `parent`. The result is not validated. */\nexport function joinFolderPath(parent: string | null, name: string): string {\n return parent === null ? name : `${parent}/${name}`;\n}\n\n/** The folder that contains `path`. `null` for a top-level folder. */\nexport function parentFolderPath(path: string): string | null {\n const index = path.lastIndexOf(\"/\");\n return index === -1 ? null : path.slice(0, index);\n}\n\n/** The last segment of `path`. */\nexport function folderName(path: string): string {\n return path.slice(path.lastIndexOf(\"/\") + 1);\n}\n\n/** Every folder from the top level down to `path` itself. */\nexport function folderAncestors(path: string): string[] {\n const segments = path.split(\"/\");\n return segments.map((_, index) => segments.slice(0, index + 1).join(\"/\"));\n}\n","import { s3Error } from \"@dimah-s3/core\";\nimport { isFolderName } from \"@/folder-path\";\nimport type {\n DbClientActions,\n DbClientListInput,\n DbClientObject,\n DbListSort,\n DbListSortField,\n DbObjectSource,\n DbObjectSourceFile,\n DbObjectSourceOptions,\n DbObjectSourceQueryInput,\n} from \"@/types/client\";\n\n/** The `api.db` actions {@link dbObjectSource} calls. */\nexport type DbObjectSourceActions<TClientAttributes = never> = Pick<\n DbClientActions<TClientAttributes>,\n \"listObjects\"\n> &\n Partial<Pick<DbClientActions<TClientAttributes>, \"createFolder\">>;\n\n/** List sort fields and the `listObjects` columns they order by. */\nconst SORT_FIELDS = new Map<string, DbListSortField>([\n [\"name\", \"filename\"],\n [\"size\", \"size\"],\n [\"updatedAt\", \"updatedAt\"],\n]);\n\nfunction toListSort(\n sort: DbObjectSourceQueryInput[\"sort\"],\n): DbListSort | undefined {\n const field = sort ? SORT_FIELDS.get(sort.field) : undefined;\n return sort && field ? { field, direction: sort.direction } : undefined;\n}\n\nfunction toFile(object: DbClientObject<unknown>): DbObjectSourceFile {\n return {\n name: object.filename,\n objectKey: object.key,\n size: object.size,\n contentType: object.contentType,\n updatedAt: object.updatedAt,\n };\n}\n\n/**\n * A `useObjectList` source over `api.db`.\n *\n * With `folders` on (the default), `parent` is a folder id: each page lists\n * one folder, the first page carries its child folders and the breadcrumb\n * trail, uploads go to the open folder, and \"New folder\" calls\n * `api.db.createFolder`. With `folders: false`, the list is flat and has no\n * folder actions.\n *\n * `search` matches the filename on the server. `sort` maps `name` to\n * `filename`; `size` and `updatedAt` keep their names, and other fields keep\n * the server's order (newest first). `usage` is the scope total with its\n * caps, not the open folder's.\n *\n * ```ts\n * const list = useObjectList({\n * ...dbObjectSource(api.db, { route: \"docs\" }),\n * queryKey: [\"docs\"],\n * });\n * ```\n */\nexport function dbObjectSource<TClientAttributes = never>(\n db: DbObjectSourceActions<TClientAttributes>,\n options: DbObjectSourceOptions = {},\n): DbObjectSource<TClientAttributes> {\n const folders = options.folders !== false;\n\n const source: DbObjectSource<TClientAttributes> = {\n getKey: (item) => item.id,\n getFile: toFile,\n async query({ parent, cursor, sort, search, signal }) {\n const input: DbClientListInput = {};\n if (folders) input.folderId = parent ?? \"\";\n if (cursor) input.cursor = cursor;\n if (search) input.search = search;\n const listSort = toListSort(sort);\n if (listSort) input.sort = listSort;\n if (options.route) input.route = options.route;\n if (options.status) input.status = options.status;\n if (options.contentType) input.contentType = options.contentType;\n if (options.limit !== undefined) input.limit = options.limit;\n\n const page = await db.listObjects(input, { signal });\n return {\n items: page.objects,\n nextCursor: page.nextCursor,\n ...(page.folders && {\n folders: page.folders.map((folder) => ({\n id: folder.id,\n name: folder.name,\n })),\n }),\n ...(page.trail && {\n trail: page.trail.map((folder) => ({\n id: folder.id,\n name: folder.name,\n })),\n }),\n ...(page.usage && { usage: { ...page.usage, ...page.limits } }),\n };\n },\n };\n if (!folders) return source;\n\n source.uploadOptions = (parent) => ({\n metadata: { folderId: parent ?? \"\" },\n });\n const createFolder = db.createFolder?.bind(db);\n if (createFolder) {\n source.createFolder = async ({ parent, name }) => {\n // A `/` would be a nested path. The server creates one folder.\n if (!isFolderName(name)) throw s3Error(\"FOLDER_INVALID\");\n const { folder } = await createFolder({\n parentId: parent,\n name,\n });\n return { id: folder.id, name: folder.name };\n };\n }\n return source;\n}\n"]}
|
package/dist/drizzle/mysql.d.ts
CHANGED
|
@@ -85,7 +85,7 @@ export declare const storageObject: import("drizzle-orm/mysql-core").MySqlTableW
|
|
|
85
85
|
identity: undefined;
|
|
86
86
|
generated: undefined;
|
|
87
87
|
}, {}>;
|
|
88
|
-
|
|
88
|
+
folderId: MySqlColumn<{
|
|
89
89
|
name: string;
|
|
90
90
|
tableName: "storage_object";
|
|
91
91
|
dataType: "string";
|
|
@@ -398,14 +398,14 @@ export declare const storageFolder: import("drizzle-orm/mysql-core").MySqlTableW
|
|
|
398
398
|
identity: undefined;
|
|
399
399
|
generated: undefined;
|
|
400
400
|
}, {}>;
|
|
401
|
-
|
|
401
|
+
parentId: MySqlColumn<{
|
|
402
402
|
name: string;
|
|
403
403
|
tableName: "storage_folder";
|
|
404
404
|
dataType: "string";
|
|
405
405
|
data: string;
|
|
406
406
|
driverParam: string | number;
|
|
407
407
|
notNull: true;
|
|
408
|
-
hasDefault:
|
|
408
|
+
hasDefault: true;
|
|
409
409
|
isPrimaryKey: false;
|
|
410
410
|
isAutoincrement: false;
|
|
411
411
|
hasRuntimeDefault: false;
|
|
@@ -414,13 +414,13 @@ export declare const storageFolder: import("drizzle-orm/mysql-core").MySqlTableW
|
|
|
414
414
|
identity: undefined;
|
|
415
415
|
generated: undefined;
|
|
416
416
|
}, {}>;
|
|
417
|
-
|
|
417
|
+
name: MySqlColumn<{
|
|
418
418
|
name: string;
|
|
419
419
|
tableName: "storage_folder";
|
|
420
420
|
dataType: "string";
|
|
421
421
|
data: string;
|
|
422
422
|
driverParam: string | number;
|
|
423
|
-
notNull:
|
|
423
|
+
notNull: true;
|
|
424
424
|
hasDefault: false;
|
|
425
425
|
isPrimaryKey: false;
|
|
426
426
|
isAutoincrement: false;
|
|
@@ -430,7 +430,7 @@ export declare const storageFolder: import("drizzle-orm/mysql-core").MySqlTableW
|
|
|
430
430
|
identity: undefined;
|
|
431
431
|
generated: undefined;
|
|
432
432
|
}, {}>;
|
|
433
|
-
|
|
433
|
+
path: MySqlColumn<{
|
|
434
434
|
name: string;
|
|
435
435
|
tableName: "storage_folder";
|
|
436
436
|
dataType: "string";
|
|
@@ -462,6 +462,22 @@ export declare const storageFolder: import("drizzle-orm/mysql-core").MySqlTableW
|
|
|
462
462
|
identity: undefined;
|
|
463
463
|
generated: undefined;
|
|
464
464
|
}, {}>;
|
|
465
|
+
updatedAt: MySqlColumn<{
|
|
466
|
+
name: string;
|
|
467
|
+
tableName: "storage_folder";
|
|
468
|
+
dataType: "object date";
|
|
469
|
+
data: Date;
|
|
470
|
+
driverParam: string | number;
|
|
471
|
+
notNull: true;
|
|
472
|
+
hasDefault: true;
|
|
473
|
+
isPrimaryKey: false;
|
|
474
|
+
isAutoincrement: false;
|
|
475
|
+
hasRuntimeDefault: true;
|
|
476
|
+
enumValues: undefined;
|
|
477
|
+
baseColumn: never;
|
|
478
|
+
identity: undefined;
|
|
479
|
+
generated: undefined;
|
|
480
|
+
}, {}>;
|
|
465
481
|
};
|
|
466
482
|
dialect: 'mysql';
|
|
467
483
|
isAlias: false;
|
|
@@ -600,7 +616,7 @@ export declare const dimahS3Tables: {
|
|
|
600
616
|
identity: undefined;
|
|
601
617
|
generated: undefined;
|
|
602
618
|
}, {}>;
|
|
603
|
-
|
|
619
|
+
folderId: MySqlColumn<{
|
|
604
620
|
name: string;
|
|
605
621
|
tableName: "storage_object";
|
|
606
622
|
dataType: "string";
|
|
@@ -912,14 +928,14 @@ export declare const dimahS3Tables: {
|
|
|
912
928
|
identity: undefined;
|
|
913
929
|
generated: undefined;
|
|
914
930
|
}, {}>;
|
|
915
|
-
|
|
931
|
+
parentId: MySqlColumn<{
|
|
916
932
|
name: string;
|
|
917
933
|
tableName: "storage_folder";
|
|
918
934
|
dataType: "string";
|
|
919
935
|
data: string;
|
|
920
936
|
driverParam: string | number;
|
|
921
937
|
notNull: true;
|
|
922
|
-
hasDefault:
|
|
938
|
+
hasDefault: true;
|
|
923
939
|
isPrimaryKey: false;
|
|
924
940
|
isAutoincrement: false;
|
|
925
941
|
hasRuntimeDefault: false;
|
|
@@ -928,13 +944,13 @@ export declare const dimahS3Tables: {
|
|
|
928
944
|
identity: undefined;
|
|
929
945
|
generated: undefined;
|
|
930
946
|
}, {}>;
|
|
931
|
-
|
|
947
|
+
name: MySqlColumn<{
|
|
932
948
|
name: string;
|
|
933
949
|
tableName: "storage_folder";
|
|
934
950
|
dataType: "string";
|
|
935
951
|
data: string;
|
|
936
952
|
driverParam: string | number;
|
|
937
|
-
notNull:
|
|
953
|
+
notNull: true;
|
|
938
954
|
hasDefault: false;
|
|
939
955
|
isPrimaryKey: false;
|
|
940
956
|
isAutoincrement: false;
|
|
@@ -944,7 +960,7 @@ export declare const dimahS3Tables: {
|
|
|
944
960
|
identity: undefined;
|
|
945
961
|
generated: undefined;
|
|
946
962
|
}, {}>;
|
|
947
|
-
|
|
963
|
+
path: MySqlColumn<{
|
|
948
964
|
name: string;
|
|
949
965
|
tableName: "storage_folder";
|
|
950
966
|
dataType: "string";
|
|
@@ -976,6 +992,22 @@ export declare const dimahS3Tables: {
|
|
|
976
992
|
identity: undefined;
|
|
977
993
|
generated: undefined;
|
|
978
994
|
}, {}>;
|
|
995
|
+
updatedAt: MySqlColumn<{
|
|
996
|
+
name: string;
|
|
997
|
+
tableName: "storage_folder";
|
|
998
|
+
dataType: "object date";
|
|
999
|
+
data: Date;
|
|
1000
|
+
driverParam: string | number;
|
|
1001
|
+
notNull: true;
|
|
1002
|
+
hasDefault: true;
|
|
1003
|
+
isPrimaryKey: false;
|
|
1004
|
+
isAutoincrement: false;
|
|
1005
|
+
hasRuntimeDefault: true;
|
|
1006
|
+
enumValues: undefined;
|
|
1007
|
+
baseColumn: never;
|
|
1008
|
+
identity: undefined;
|
|
1009
|
+
generated: undefined;
|
|
1010
|
+
}, {}>;
|
|
979
1011
|
};
|
|
980
1012
|
dialect: 'mysql';
|
|
981
1013
|
isAlias: false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mysql.d.ts","sourceRoot":"","sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":"AAmBA,OAAO,EASL,KAAK,WAAW,EACjB,MAAM,wBAAwB,CAAC;AAEhC,KAAK,mBAAmB,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;AAqCxE,8DAA8D;AAC9D,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2DzB,CAAC;AAEF,6EAA6E;AAC7E,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAIzB,CAAC"}
|
package/dist/drizzle/mysql.js
CHANGED
|
@@ -3,7 +3,7 @@ import { sql } from 'drizzle-orm';
|
|
|
3
3
|
import { mysqlTable, text, json, varchar, uniqueIndex, index, datetime, bigint } from 'drizzle-orm/mysql-core';
|
|
4
4
|
|
|
5
5
|
// src/drizzle/mysql.ts
|
|
6
|
-
var SCHEMA_VERSION = "2.
|
|
6
|
+
var SCHEMA_VERSION = "2.1.0";
|
|
7
7
|
var BINARY = "utf8mb4_bin";
|
|
8
8
|
function id() {
|
|
9
9
|
return string("id").primaryKey().$defaultFn(() => createId());
|
|
@@ -31,7 +31,7 @@ var storageObject = mysqlTable(
|
|
|
31
31
|
bucket: string("bucket").notNull(),
|
|
32
32
|
key: string("key", 1024).notNull(),
|
|
33
33
|
route: string("route").notNull(),
|
|
34
|
-
|
|
34
|
+
folderId: string("folder_id"),
|
|
35
35
|
filename: varchar("filename", { length: 255 }).collate("utf8mb4_unicode_ci").notNull(),
|
|
36
36
|
contentType: string("content_type"),
|
|
37
37
|
size: byteCount("size"),
|
|
@@ -57,7 +57,7 @@ var storageObject = mysqlTable(
|
|
|
57
57
|
index("storage_object_scope_folder_idx").on(
|
|
58
58
|
table.scope,
|
|
59
59
|
table.status,
|
|
60
|
-
|
|
60
|
+
table.folderId,
|
|
61
61
|
table.createdAt
|
|
62
62
|
),
|
|
63
63
|
index("storage_object_scope_updated_idx").on(
|
|
@@ -86,19 +86,22 @@ var storageFolder = mysqlTable(
|
|
|
86
86
|
{
|
|
87
87
|
id: id(),
|
|
88
88
|
scope: string("scope").notNull(),
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
/** `""` is the root. */
|
|
90
|
+
parentId: string("parent_id").notNull().default(""),
|
|
91
91
|
name: string("name").notNull(),
|
|
92
|
-
|
|
92
|
+
path: string("path", 1024).notNull(),
|
|
93
|
+
createdAt: timestampNow("created_at"),
|
|
94
|
+
updatedAt: timestampNow("updated_at")
|
|
93
95
|
},
|
|
94
96
|
(table) => [
|
|
95
97
|
uniqueIndex("storage_folder_scope_path_uk").on(
|
|
96
98
|
table.scope,
|
|
97
99
|
prefix(table.path, 512)
|
|
98
100
|
),
|
|
99
|
-
|
|
101
|
+
uniqueIndex("storage_folder_scope_parent_name_uk").on(
|
|
100
102
|
table.scope,
|
|
101
|
-
|
|
103
|
+
table.parentId,
|
|
104
|
+
table.name
|
|
102
105
|
)
|
|
103
106
|
]
|
|
104
107
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/drizzle/mysql.ts"],"names":[],"mappings":";;;;;AAiCA,IAAM,cAAA,GAAiB,OAAA;AAGvB,IAAM,MAAA,GAAS,aAAA;AAEf,SAAS,EAAA,GAAK;AACZ,EAAA,OAAO,MAAA,CAAO,IAAI,CAAA,CACf,UAAA,GACA,UAAA,CAAW,MAAM,UAAU,CAAA;AAChC;AAEA,SAAS,MAAA,CAAO,IAAA,EAAc,MAAA,GAAS,GAAA,EAAK;AAC1C,EAAA,OAAO,QAAQ,IAAA,EAAM,EAAE,QAAQ,CAAA,CAAE,QAAQ,MAAM,CAAA;AACjD;AAEA,SAAS,UAAU,IAAA,EAAc;AAC/B,EAAA,OAAO,SAAS,IAAA,EAAM,EAAE,MAAM,MAAA,EAAQ,G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AAkB,WAAW,2BAAA,EAA6B;AAAA,EACrE,GAAA,EAAK,MAAA,CAAO,KAAK,CAAA,CAAE,UAAA,EAAW;AAAA,EAC9B,OAAA,EAAS,IAAA,CAAK,OAAO,CAAA,CAAE,OAAA,CAAQ,MAAM,CAAA,CAAE,OAAA,EAAQ,CAAE,OAAA,CAAQ,cAAc;AACzE,CAAC;AAOM,IAAM,aAAA,GAAgB;AAAA,EAC3B,aAAA;AAAA,EACA,aAAA;AAAA,EACA,yBAAA,EAA2B;AAC7B","file":"mysql.js","sourcesContent":["/**\n * Drizzle schema for @dimah-s3/db on MySQL 8. Copy this file into your app\n * (`db/schema.ts`) to own the tables and add columns. Keep the table names,\n * the column names, and the `dimahS3Tables` keys: the adapter finds the\n * tables by those keys. A column you add must be nullable or have a default.\n * The plugin does not read or write it.\n *\n * Import `dimahS3Tables` from `@dimah-s3/db/drizzle/mysql` when the tables\n * stay as they are. `drizzle-kit` then follows that import, and a later push\n * drops a column that is not part of it.\n *\n * Columns, collations and indexes match `sql/mysql.sql`, including the\n * prefix indexes on `key`, `folder`, `path` and `parent`. Keys, folders and\n * scopes compare byte for byte (`utf8mb4_bin`), and file names\n * case-insensitively (`utf8mb4_unicode_ci`). Requires `drizzle-orm` and\n * `@paralleldrive/cuid2`.\n */\nimport { createId } from \"@paralleldrive/cuid2\";\nimport { sql } from \"drizzle-orm\";\nimport {\n bigint,\n datetime,\n index,\n json,\n mysqlTable,\n text,\n uniqueIndex,\n varchar,\n type MySqlColumn,\n} from \"drizzle-orm/mysql-core\";\n\ntype StorageObjectStatus = \"pending\" | \"active\" | \"deleted\" | \"purging\";\n\nconst SCHEMA_VERSION = \"2.1.0\";\n\n/** Collation of every text column but `filename`: byte for byte. */\nconst BINARY = \"utf8mb4_bin\";\n\nfunction id() {\n return string(\"id\")\n .primaryKey()\n .$defaultFn(() => createId());\n}\n\nfunction string(name: string, length = 255) {\n return varchar(name, { length }).collate(BINARY);\n}\n\nfunction timestamp(name: string) {\n return datetime(name, { mode: \"date\", fsp: 3 });\n}\n\nfunction timestampNow(name: string) {\n return timestamp(name)\n .notNull()\n .default(sql`CURRENT_TIMESTAMP(3)`)\n .$defaultFn(() => new Date());\n}\n\nfunction byteCount(name: string) {\n return bigint(name, { mode: \"number\" });\n}\n\n/** An index on the first `length` characters of a long column. */\nfunction prefix(column: MySqlColumn, length: number) {\n return sql`${column}(${sql.raw(String(length))})`;\n}\n\n/** The `storage_object` table: one row per tracked object. */\nexport const storageObject = mysqlTable(\n \"storage_object\",\n {\n id: id(),\n scope: string(\"scope\").notNull(),\n bucket: string(\"bucket\").notNull(),\n key: string(\"key\", 1024).notNull(),\n route: string(\"route\").notNull(),\n folderId: string(\"folder_id\"),\n filename: varchar(\"filename\", { length: 255 })\n .collate(\"utf8mb4_unicode_ci\")\n .notNull(),\n contentType: string(\"content_type\"),\n size: byteCount(\"size\"),\n declaredSize: byteCount(\"declared_size\"),\n eTag: string(\"e_tag\"),\n status: string(\"status\", 16).$type<StorageObjectStatus>().notNull(),\n s3Metadata: json(\"s3_metadata\").$type<Record<string, string>>(),\n attributes: json(\"attributes\"),\n acl: string(\"acl\"),\n uploadId: text(\"upload_id\").collate(BINARY),\n uploadToken: string(\"upload_token\", 64),\n expiresAt: timestamp(\"expires_at\"),\n confirmedAt: timestamp(\"confirmed_at\"),\n createdAt: timestampNow(\"created_at\"),\n updatedAt: timestampNow(\"updated_at\"),\n deletedAt: timestamp(\"deleted_at\"),\n },\n (table) => [\n uniqueIndex(\"storage_object_bucket_key_uk\").on(\n table.bucket,\n prefix(table.key, 512),\n ),\n index(\"storage_object_scope_folder_idx\").on(\n table.scope,\n table.status,\n table.folderId,\n table.createdAt,\n ),\n index(\"storage_object_scope_updated_idx\").on(\n table.scope,\n table.status,\n table.updatedAt,\n ),\n index(\"storage_object_scope_filename_idx\").on(\n table.scope,\n table.status,\n table.filename,\n ),\n index(\"storage_object_scope_size_idx\").on(\n table.scope,\n table.status,\n table.size,\n ),\n index(\"storage_object_status_expires_idx\").on(\n table.status,\n table.expiresAt,\n ),\n ],\n);\n\n/** The `storage_folder` table: one row per folder, so empty folders list. */\nexport const storageFolder = mysqlTable(\n \"storage_folder\",\n {\n id: id(),\n scope: string(\"scope\").notNull(),\n /** `\"\"` is the root. */\n parentId: string(\"parent_id\").notNull().default(\"\"),\n name: string(\"name\").notNull(),\n path: string(\"path\", 1024).notNull(),\n createdAt: timestampNow(\"created_at\"),\n updatedAt: timestampNow(\"updated_at\"),\n },\n (table) => [\n uniqueIndex(\"storage_folder_scope_path_uk\").on(\n table.scope,\n prefix(table.path, 512),\n ),\n uniqueIndex(\"storage_folder_scope_parent_name_uk\").on(\n table.scope,\n table.parentId,\n table.name,\n ),\n ],\n);\n\n/**\n * The FumaDB settings table. The Drizzle adapter reads the schema version\n * from the default of its `version` column, which is stored as `value`.\n */\nexport const dimahS3Settings = mysqlTable(\"private_dimah_s3_settings\", {\n key: string(\"key\").primaryKey(),\n version: text(\"value\").collate(BINARY).notNull().default(SCHEMA_VERSION),\n});\n\n/**\n * Every @dimah-s3/db table. Spread it into your Drizzle schema and keep its\n * keys, because the FumaDB Drizzle adapter finds tables by them:\n * `drizzle({ client, relations: defineRelations({ ...dimahS3Tables }) })`.\n */\nexport const dimahS3Tables = {\n storageObject,\n storageFolder,\n private_dimah_s3_settings: dimahS3Settings,\n};\n"]}
|