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

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 (85) hide show
  1. package/README.md +19 -10
  2. package/dist/adapters/drizzle.d.ts +2 -3
  3. package/dist/adapters/drizzle.d.ts.map +1 -1
  4. package/dist/adapters/kysely.d.ts +1 -1
  5. package/dist/adapters/prisma.d.ts +1 -1
  6. package/dist/cli.d.ts +18 -13
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +57 -84
  9. package/dist/cli.js.map +1 -1
  10. package/dist/client/db-client.d.ts +1 -1
  11. package/dist/client/db-client.d.ts.map +1 -1
  12. package/dist/client/db-object-source.d.ts +15 -9
  13. package/dist/client/db-object-source.d.ts.map +1 -1
  14. package/dist/client/index.d.ts +3 -3
  15. package/dist/client/index.d.ts.map +1 -1
  16. package/dist/client/index.js +101 -21
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/folder-path.d.ts +17 -4
  19. package/dist/folder-path.d.ts.map +1 -1
  20. package/dist/fuma-db.d.ts +23 -23
  21. package/dist/fuma-db.d.ts.map +1 -1
  22. package/dist/index.d.ts +10 -9
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +843 -268
  25. package/dist/index.js.map +1 -1
  26. package/dist/plugin/create-database-endpoints.d.ts +46 -22
  27. package/dist/plugin/create-database-endpoints.d.ts.map +1 -1
  28. package/dist/plugin/create-database-lifecycle-hooks.d.ts +4 -4
  29. package/dist/plugin/create-database-lifecycle-hooks.d.ts.map +1 -1
  30. package/dist/plugin/db.d.ts +10 -2
  31. package/dist/plugin/db.d.ts.map +1 -1
  32. package/dist/plugin/object-access.d.ts +2 -2
  33. package/dist/plugin/object-access.d.ts.map +1 -1
  34. package/dist/plugin/public-stores.d.ts +5 -8
  35. package/dist/plugin/public-stores.d.ts.map +1 -1
  36. package/dist/plugin/quota.d.ts +1 -1
  37. package/dist/plugin/record.d.ts +58 -0
  38. package/dist/plugin/record.d.ts.map +1 -0
  39. package/dist/plugin/schemas.d.ts +25 -11
  40. package/dist/plugin/schemas.d.ts.map +1 -1
  41. package/dist/plugin/scope.d.ts +2 -0
  42. package/dist/plugin/scope.d.ts.map +1 -1
  43. package/dist/plugin/to-db-client-object.d.ts.map +1 -1
  44. package/dist/schema/schema.d.ts +48 -49
  45. package/dist/schema/schema.d.ts.map +1 -1
  46. package/dist/store/create-db-store.d.ts +2 -2
  47. package/dist/store/create-db-store.d.ts.map +1 -1
  48. package/dist/store/folder-store.d.ts +73 -15
  49. package/dist/store/folder-store.d.ts.map +1 -1
  50. package/dist/store/list-cursor.d.ts +3 -1
  51. package/dist/store/list-cursor.d.ts.map +1 -1
  52. package/dist/store/map-row.d.ts +3 -9
  53. package/dist/store/map-row.d.ts.map +1 -1
  54. package/dist/store/object-store.d.ts +42 -10
  55. package/dist/store/object-store.d.ts.map +1 -1
  56. package/dist/store/search-name.d.ts +7 -0
  57. package/dist/store/search-name.d.ts.map +1 -0
  58. package/dist/types/client.d.ts +114 -23
  59. package/dist/types/client.d.ts.map +1 -1
  60. package/dist/types/plugin.d.ts +19 -7
  61. package/dist/types/plugin.d.ts.map +1 -1
  62. package/dist/types/storage-object.d.ts +8 -7
  63. package/dist/types/storage-object.d.ts.map +1 -1
  64. package/package.json +15 -33
  65. package/dist/drizzle/mysql.d.ts +0 -1025
  66. package/dist/drizzle/mysql.d.ts.map +0 -1
  67. package/dist/drizzle/mysql.js +0 -117
  68. package/dist/drizzle/mysql.js.map +0 -1
  69. package/dist/drizzle/pg.d.ts +0 -964
  70. package/dist/drizzle/pg.d.ts.map +0 -1
  71. package/dist/drizzle/pg.js +0 -98
  72. package/dist/drizzle/pg.js.map +0 -1
  73. package/dist/drizzle/shared.d.ts +0 -7
  74. package/dist/drizzle/shared.d.ts.map +0 -1
  75. package/dist/drizzle/sqlite.d.ts +0 -1024
  76. package/dist/drizzle/sqlite.d.ts.map +0 -1
  77. package/dist/drizzle/sqlite.js +0 -101
  78. package/dist/drizzle/sqlite.js.map +0 -1
  79. package/prisma/dimah-s3.prisma +0 -80
  80. package/sql/mysql.sql +0 -59
  81. package/sql/pg.sql +0 -53
  82. package/sql/sqlite.sql +0 -54
  83. package/src/drizzle/mysql.ts +0 -172
  84. package/src/drizzle/pg.ts +0 -140
  85. package/src/drizzle/sqlite.ts +0 -144
@@ -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?.folder !== null) return input;
9
- return { ...input, folder: "" };
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,15 @@ function dbClient() {
38
43
  })
39
44
  });
40
45
  }
41
- function formatFolder(folder) {
42
- return folder ?? "";
46
+ var FOLDER_NAME_MAX_LENGTH = 255;
47
+ var INVALID_CHARACTER = /[\p{Cc}\p{Cs}]/u;
48
+ new TextEncoder();
49
+ function characterCount(value) {
50
+ return Array.from(value).length;
43
51
  }
44
- function joinFolderPath(parent, name) {
45
- return parent === null ? name : `${parent}/${name}`;
52
+ function isFolderName(name) {
53
+ const length = characterCount(name);
54
+ return length >= 1 && length <= FOLDER_NAME_MAX_LENGTH && name !== "." && name !== ".." && !name.includes("/") && !INVALID_CHARACTER.test(name);
46
55
  }
47
56
 
48
57
  // src/client/db-object-source.ts
@@ -55,23 +64,52 @@ function toListSort(sort) {
55
64
  const field = sort ? SORT_FIELDS.get(sort.field) : void 0;
56
65
  return sort && field ? { field, direction: sort.direction } : void 0;
57
66
  }
58
- function toFile(object) {
59
- return {
60
- name: object.filename,
61
- objectKey: object.key,
62
- size: object.size,
63
- contentType: object.contentType,
64
- updatedAt: object.updatedAt
67
+ function locationsOf(folders) {
68
+ const byId = new Map(folders.map((folder) => [folder.id, folder]));
69
+ const cache = /* @__PURE__ */ new Map();
70
+ const trailTo = (folderId) => {
71
+ if (folderId === null) return [];
72
+ const cached = cache.get(folderId);
73
+ if (cached) return cached;
74
+ const chain = [];
75
+ const seen = /* @__PURE__ */ new Set();
76
+ let current = byId.get(folderId);
77
+ while (current && !seen.has(current.id)) {
78
+ seen.add(current.id);
79
+ chain.unshift({ id: current.id, name: current.name });
80
+ current = current.parentId === null ? void 0 : byId.get(current.parentId);
81
+ }
82
+ cache.set(folderId, chain);
83
+ return chain;
65
84
  };
85
+ return trailTo;
66
86
  }
67
87
  function dbObjectSource(db, options = {}) {
68
88
  const folders = options.folders !== false;
89
+ const searchBelow = folders && options.recursiveSearch !== false;
90
+ const locations = /* @__PURE__ */ new WeakMap();
91
+ const toFile = (object) => {
92
+ const file = {
93
+ name: object.filename,
94
+ objectKey: object.key,
95
+ size: object.size,
96
+ contentType: object.contentType,
97
+ updatedAt: object.updatedAt
98
+ };
99
+ const location = locations.get(object);
100
+ if (location) file.location = location;
101
+ return file;
102
+ };
69
103
  const source = {
70
104
  getKey: (item) => item.id,
71
105
  getFile: toFile,
72
- async query({ parent, cursor, sort, search, signal }) {
106
+ async query({ parent, cursor, sort, search, searchScope, signal }) {
73
107
  const input = {};
74
- if (folders) input.folder = formatFolder(parent);
108
+ const recursive = searchBelow && search !== "";
109
+ if (folders) {
110
+ input.folderId = recursive && searchScope === "all" ? "" : parent ?? "";
111
+ }
112
+ if (recursive) input.recursive = true;
75
113
  if (cursor) input.cursor = cursor;
76
114
  if (search) input.search = search;
77
115
  const listSort = toListSort(sort);
@@ -81,31 +119,73 @@ function dbObjectSource(db, options = {}) {
81
119
  if (options.contentType) input.contentType = options.contentType;
82
120
  if (options.limit !== void 0) input.limit = options.limit;
83
121
  const page = await db.listObjects(input, { signal });
122
+ const locate = recursive ? locationsOf([
123
+ ...page.locations ?? [],
124
+ ...page.trail ?? [],
125
+ ...page.folders ?? []
126
+ ]) : null;
127
+ if (locate) {
128
+ for (const object of page.objects) {
129
+ locations.set(object, locate(object.folderId));
130
+ }
131
+ }
84
132
  return {
85
133
  items: page.objects,
86
134
  nextCursor: page.nextCursor,
87
135
  ...page.folders && {
88
136
  folders: page.folders.map((folder) => ({
89
- id: folder.path,
137
+ id: folder.id,
138
+ name: folder.name,
139
+ ...locate && { location: locate(folder.parentId) }
140
+ }))
141
+ },
142
+ ...page.trail && {
143
+ trail: page.trail.map((folder) => ({
144
+ id: folder.id,
90
145
  name: folder.name
91
146
  }))
92
147
  },
93
- ...page.usage && { usage: { ...page.usage, ...page.limits } }
148
+ ...page.usage && { usage: { ...page.usage, ...page.limits } },
149
+ ...page.total !== void 0 && { total: page.total }
94
150
  };
95
151
  }
96
152
  };
153
+ if (searchBelow) source.searchScopes = ["folder", "all"];
154
+ const updateObject = db.updateObject?.bind(db);
155
+ if (updateObject) {
156
+ source.renameFile = async ({ item, name }) => {
157
+ const { object } = await updateObject({
158
+ key: item.key,
159
+ bucket: item.bucket,
160
+ filename: name
161
+ });
162
+ return object;
163
+ };
164
+ }
97
165
  if (!folders) return source;
98
166
  source.uploadOptions = (parent) => ({
99
- metadata: { folder: formatFolder(parent) }
167
+ metadata: { folderId: parent ?? "" }
100
168
  });
101
169
  const createFolder = db.createFolder?.bind(db);
102
170
  if (createFolder) {
103
171
  source.createFolder = async ({ parent, name }) => {
104
- if (name.includes("/")) throw s3Error("FOLDER_INVALID");
172
+ if (!isFolderName(name)) throw s3Error("FOLDER_INVALID");
105
173
  const { folder } = await createFolder({
106
- path: joinFolderPath(parent, name)
174
+ parentId: parent,
175
+ name
176
+ });
177
+ return { id: folder.id, name: folder.name };
178
+ };
179
+ }
180
+ const updateFolder = db.updateFolder?.bind(db);
181
+ if (updateFolder) {
182
+ source.renameFolder = async ({ folder, name }) => {
183
+ if (!isFolderName(name)) throw s3Error("FOLDER_INVALID");
184
+ const { folder: updated } = await updateFolder({
185
+ id: folder.id,
186
+ name
107
187
  });
108
- return { id: folder.path, name: folder.name };
188
+ return { id: updated.id, name: updated.name };
109
189
  };
110
190
  }
111
191
  return source;
@@ -1 +1 @@
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;AAGA,SAAS,UAAU,KAAA,EAAsC;AACvD,EAAA,IAAI,KAAA,EAAO,MAAA,KAAW,IAAA,EAAM,OAAO,KAAA;AACnC,EAAA,OAAO,EAAE,GAAG,KAAA,EAAO,MAAA,EAAQ,EAAA,EAAG;AAChC;AAqBO,SAAS,QAAA,GAAsC;AACpD,EAAA,OAAO,kBAAA,CAAmB;AAAA,IACxB,EAAA,EAAI,IAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,UAAA,EAAY,CAAC,MAAA,MAAgD;AAAA,MAC3D,WAAA,EAAa,CAAC,KAAA,EAAO,OAAA,KACnB,MAAA;AAAA,QACE,UAAA,CAAW,MAAM,SAAS,CAAA;AAAA,QAC1B,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,SAAA,CAAU,KAAK,CAAA,EAAG,GAAG,IAAA,CAAK,OAAO,CAAA;AAAE,OAC7D;AAAA,MACF,SAAA,EAAW,CAAC,KAAA,EAAO,OAAA,KACjB,MAAA;AAAA,QACE,UAAA,CAAW,MAAM,QAAQ,CAAA;AAAA,QACzB,EAAE,QAAQ,KAAA,EAAO,KAAA,EAAO,OAAO,GAAG,IAAA,CAAK,OAAO,CAAA;AAAE,OAClD;AAAA,MACF,YAAA,EAAc,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ACF;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;AAGA,SAAS,UAAU,KAAA,EAAsC;AACvD,EAAA,IAAI,KAAA,EAAO,QAAA,KAAa,IAAA,EAAM,OAAO,KAAA;AACrC,EAAA,OAAO,EAAE,GAAG,KAAA,EAAO,QAAA,EAAU,EAAA,EAAG;AAClC;AAqBO,SAAS,QAAA,GAAsC;AACpD,EAAA,OAAO,kBAAA,CAAmB;AAAA,IACxB,EAAA,EAAI,IAAA;AAAA,IACJ,oBAAoB,EAAC;AAAA,IACrB,UAAA,EAAY,CAAC,MAAA,MAAgD;AAAA,MAC3D,WAAA,EAAa,CAAC,KAAA,EAAO,OAAA,KACnB,MAAA;AAAA,QACE,UAAA,CAAW,MAAM,SAAS,CAAA;AAAA,QAC1B,EAAE,MAAA,EAAQ,KAAA,EAAO,KAAA,EAAO,SAAA,CAAU,KAAK,CAAA,EAAG,GAAG,IAAA,CAAK,OAAO,CAAA;AAAE,OAC7D;AAAA,MACF,SAAA,EAAW,CAAC,KAAA,EAAO,OAAA,KACjB,MAAA;AAAA,QACE,UAAA,CAAW,MAAM,QAAQ,CAAA;AAAA,QACzB,EAAE,QAAQ,KAAA,EAAO,KAAA,EAAO,OAAO,GAAG,IAAA,CAAK,OAAO,CAAA;AAAE,OAClD;AAAA,MACF,YAAA,EAAc,CAAC,KAAA,EAAO,OAAA,KACpB,MAAA;AAAA,QACE,UAAA,CAAW,MAAM,QAAQ,CAAA;AAAA,QACzB,EAAE,QAAQ,OAAA,EAAS,IAAA,EAAM,OAAO,GAAG,IAAA,CAAK,OAAO,CAAA;AAAE,OACnD;AAAA,MACF,YAAA,EAAc,CAAC,KAAA,EA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";\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/**\n * Longest folder path, in UTF-8 bytes, like an S3 key. With the longest scope,\n * the `(scope, path)` unique key stays under PostgreSQL's 2704-byte limit\n * for a btree entry.\n */\nexport const FOLDER_PATH_MAX_BYTES = 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\nconst utf8 = new TextEncoder();\n\n/** Counts code points, so a character outside the BMP counts once. */\nexport function 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 (utf8.encode(normalized).byteLength > FOLDER_PATH_MAX_BYTES) 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 DbClientFolder,\n DbClientListInput,\n DbClientObject,\n DbListSort,\n DbListSortField,\n DbObjectSource,\n DbObjectSourceFile,\n DbObjectSourceFolder,\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<\n Pick<\n DbClientActions<TClientAttributes>,\n \"createFolder\" | \"updateObject\" | \"updateFolder\"\n >\n >;\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\n/**\n * The path to each folder in `folders`, root excluded, by walking\n * `parentId`. A folder whose parent is missing gets the part that is known.\n */\nfunction locationsOf(\n folders: readonly DbClientFolder[],\n): (folderId: string | null) => DbObjectSourceFolder[] {\n const byId = new Map(folders.map((folder) => [folder.id, folder]));\n const cache = new Map<string, DbObjectSourceFolder[]>();\n const trailTo = (folderId: string | null): DbObjectSourceFolder[] => {\n if (folderId === null) return [];\n const cached = cache.get(folderId);\n if (cached) return cached;\n const chain: DbObjectSourceFolder[] = [];\n const seen = new Set<string>();\n let current = byId.get(folderId);\n while (current && !seen.has(current.id)) {\n seen.add(current.id);\n chain.unshift({ id: current.id, name: current.name });\n current =\n current.parentId === null ? undefined : byId.get(current.parentId);\n }\n cache.set(folderId, chain);\n return chain;\n };\n return trailTo;\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`. Rename calls `api.db.updateObject` (`filename`) or\n * `api.db.updateFolder` (`name`) and leaves the object key as it is. With\n * `folders: false`, the list is flat: file rename stays, and folder actions\n * do not.\n *\n * `search` runs on the server and ignores case and accents. With `folders`\n * on it is recursive: `searchScope: \"folder\"` looks in the open folder and\n * every folder below it, `\"all\"` in the whole scope, and each result's\n * `location` says where it lives. `sort` maps `name` to `filename`; `size`\n * and `updatedAt` keep their names, and other fields keep the server's\n * order (newest first). `usage` is the scope total with its caps, not the\n * 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 const searchBelow = folders && options.recursiveSearch !== false;\n // Where each row of a search lives. Keyed by the row object, so `getFile`\n // reads it for the rows a query returned and stays pure.\n const locations = new WeakMap<object, DbObjectSourceFolder[]>();\n const toFile = (object: DbClientObject<TClientAttributes>) => {\n const file: DbObjectSourceFile = {\n name: object.filename,\n objectKey: object.key,\n size: object.size,\n contentType: object.contentType,\n updatedAt: object.updatedAt,\n };\n const location = locations.get(object);\n if (location) file.location = location;\n return file;\n };\n\n const source: DbObjectSource<TClientAttributes> = {\n getKey: (item) => item.id,\n getFile: toFile,\n async query({ parent, cursor, sort, search, searchScope, signal }) {\n const input: DbClientListInput = {};\n // A search reaches the folders below; a listing shows one folder.\n const recursive = searchBelow && search !== \"\";\n if (folders) {\n input.folderId =\n recursive && searchScope === \"all\" ? \"\" : (parent ?? \"\");\n }\n if (recursive) input.recursive = true;\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 const locate = recursive\n ? locationsOf([\n ...(page.locations ?? []),\n ...(page.trail ?? []),\n ...(page.folders ?? []),\n ])\n : null;\n if (locate) {\n for (const object of page.objects) {\n locations.set(object, locate(object.folderId));\n }\n }\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 ...(locate && { location: locate(folder.parentId) }),\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 ...(page.total !== undefined && { total: page.total }),\n };\n },\n };\n if (searchBelow) source.searchScopes = [\"folder\", \"all\"];\n\n const updateObject = db.updateObject?.bind(db);\n if (updateObject) {\n source.renameFile = async ({ item, name }) => {\n const { object } = await updateObject({\n key: item.key,\n bucket: item.bucket,\n filename: name,\n });\n return object;\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 const updateFolder = db.updateFolder?.bind(db);\n if (updateFolder) {\n source.renameFolder = async ({ folder, name }) => {\n // A `/` would be a nested path. The server renames one folder.\n if (!isFolderName(name)) throw s3Error(\"FOLDER_INVALID\");\n const { folder: updated } = await updateFolder({\n id: folder.id,\n name,\n });\n return { id: updated.id, name: updated.name };\n };\n }\n return source;\n}\n"]}
@@ -1,14 +1,22 @@
1
1
  /**
2
2
  * Logical folder paths. A path is NFC-normalized and `/`-separated, with no
3
- * leading or trailing `/`. `null` is the root in types and JSON. On the wire
4
- * (`?folder=`, `clientMetadata.folder`) the root is `""`.
3
+ * leading or trailing `/`. `null` is the root. The wire addresses a folder
4
+ * by id; the path is the cached label of that id.
5
5
  */
6
- /** Longest folder path, in characters. */
7
- export declare const FOLDER_PATH_MAX_LENGTH = 1024;
6
+ /**
7
+ * Longest folder path, in UTF-8 bytes, like an S3 key. With the longest scope,
8
+ * the `(scope, path)` unique key stays under PostgreSQL's 2704-byte limit
9
+ * for a btree entry.
10
+ */
11
+ export declare const FOLDER_PATH_MAX_BYTES = 1024;
8
12
  /** Longest folder name (one path segment), in characters. */
9
13
  export declare const FOLDER_NAME_MAX_LENGTH = 255;
10
14
  /** Most segments in a folder path. Each one is a row the server keeps. */
11
15
  export declare const FOLDER_MAX_DEPTH = 32;
16
+ /** Counts code points, so a character outside the BMP counts once. */
17
+ export declare function characterCount(value: string): number;
18
+ /** True when `name` can be one segment of a folder path. */
19
+ export declare function isFolderName(name: string): boolean;
12
20
  /**
13
21
  * Returns the NFC form of `path`, or `null` when it is not a valid folder
14
22
  * path. The root (`""`) is not a folder path.
@@ -21,6 +29,11 @@ export declare function normalizeFolderPath(path: string): string | null;
21
29
  export declare function parseFolder(value: string): string | null;
22
30
  /** Writes a folder for the wire. The root becomes `""`. */
23
31
  export declare function formatFolder(folder: string | null): string;
32
+ /**
33
+ * The path of `name` inside `parent`. `null` when `name` is not a folder
34
+ * name or the joined path is too long or too deep.
35
+ */
36
+ export declare function childFolderPath(parent: string | null, name: string): string | null;
24
37
  /** Appends `name` to `parent`. The result is not validated. */
25
38
  export declare function joinFolderPath(parent: string | null, name: string): string;
26
39
  /** The folder that contains `path`. `null` for a top-level folder. */
@@ -1 +1 @@
1
- {"version":3,"file":"folder-path.d.ts","sourceRoot":"","sources":["../src/folder-path.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAEH,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,6DAA6D;AAC7D,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAE1C,0EAA0E;AAC1E,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAqBnC;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAO/D;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKxD;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAE1D;AAED,+DAA+D;AAC/D,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,MA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E,MAAM,GAAG,MAAM,GAAG,IAAI,CAG5D;AAED,kCAAkC;AAClC,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,6DAA6D;AAC7D,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAGtD"}
package/dist/fuma-db.d.ts CHANGED
@@ -2,29 +2,27 @@ import { type InferFumaDB } from "fumadb";
2
2
  /**
3
3
  * The @dimah-s3/db FumaDB library. Call `DimahS3DB.client(adapter)` with an
4
4
  * adapter from `@dimah-s3/db/adapters/*` to get a {@link DimahS3DbClient}.
5
- *
6
- * `predecessor` is empty. FumaDB skips `up` on the first schema, and the
7
- * indexes are created in {@link dbSchema}'s `up`.
8
5
  */
9
- export declare const DimahS3DB: import("fumadb").FumaDBFactory<(import("fumadb/schema").Schema<"0.0.1", {}> | import("fumadb/schema").Schema<"2.0.0", {
6
+ export declare const DimahS3DB: import("fumadb").FumaDBFactory<import("fumadb/schema").Schema<"2.2.0", {
10
7
  storageObject: import("fumadb/schema").Table<{
11
8
  id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
12
- scope: import("fumadb/schema").Column<"string", string, string>;
13
- bucket: import("fumadb/schema").Column<"string", string, string>;
14
- key: import("fumadb/schema").Column<"string", string, string>;
15
- route: import("fumadb/schema").Column<"string", string, string>;
16
- folder: import("fumadb/schema").Column<"string", string | null, string | null>;
17
- filename: import("fumadb/schema").Column<"string", string, string>;
18
- contentType: import("fumadb/schema").Column<"string", string | null, string | null>;
19
- size: import("fumadb/schema").Column<"bigint", number | null, string | number | bigint | null>;
20
- declaredSize: import("fumadb/schema").Column<"bigint", number | null, string | number | bigint | null>;
21
- eTag: import("fumadb/schema").Column<"string", string | null, string | null>;
22
- status: import("fumadb/schema").Column<"string", string, string>;
9
+ scope: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
10
+ bucket: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
11
+ key: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
12
+ route: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
13
+ folderId: import("fumadb/schema").Column<`varchar(${number})`, string | null, string | null>;
14
+ filename: import("fumadb/schema").Column<"varchar(255)", string, string>;
15
+ searchName: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
16
+ contentType: import("fumadb/schema").Column<`varchar(${number})`, string | null, string | null>;
17
+ size: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
18
+ declaredSize: import("fumadb/schema").Column<"bigint", bigint | null, bigint | null>;
19
+ eTag: import("fumadb/schema").Column<`varchar(${number})`, string | null, string | null>;
20
+ status: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
23
21
  s3Metadata: import("fumadb/schema").Column<"json", unknown, unknown>;
24
22
  attributes: import("fumadb/schema").Column<"json", unknown, unknown>;
25
- acl: import("fumadb/schema").Column<"string", string | null, string | null>;
23
+ acl: import("fumadb/schema").Column<`varchar(${number})`, string | null, string | null>;
26
24
  uploadId: import("fumadb/schema").Column<"string", string | null, string | null>;
27
- uploadToken: import("fumadb/schema").Column<"string", string | null, string | null>;
25
+ uploadToken: import("fumadb/schema").Column<`varchar(${number})`, string | null, string | null>;
28
26
  expiresAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
29
27
  confirmedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date | null>;
30
28
  createdAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
@@ -33,15 +31,17 @@ export declare const DimahS3DB: import("fumadb").FumaDBFactory<(import("fumadb/s
33
31
  }, {}>;
34
32
  storageFolder: import("fumadb/schema").Table<{
35
33
  id: import("fumadb/schema").IdColumn<"varchar(255)", string | null, string>;
36
- scope: import("fumadb/schema").Column<"string", string, string>;
37
- path: import("fumadb/schema").Column<"string", string, string>;
38
- parent: import("fumadb/schema").Column<"string", string | null, string | null>;
39
- name: import("fumadb/schema").Column<"string", string, string>;
34
+ scope: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
35
+ parentId: import("fumadb/schema").Column<`varchar(${number})`, string | null, string>;
36
+ name: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
37
+ searchName: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
38
+ path: import("fumadb/schema").Column<`varchar(${number})`, string, string>;
40
39
  createdAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
40
+ updatedAt: import("fumadb/schema").Column<"timestamp", Date | null, Date>;
41
41
  }, {}>;
42
- }>)[]>;
42
+ }>[]>;
43
43
  /** FumaDB client for the @dimah-s3/db schema. */
44
44
  export type DimahS3DbClient = InferFumaDB<typeof DimahS3DB>;
45
45
  /** The schema version the stores read and write. */
46
- export declare const DB_SCHEMA_VERSION: "2.0.0";
46
+ export declare const DB_SCHEMA_VERSION: "2.2.0";
47
47
  //# sourceMappingURL=fuma-db.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fuma-db.d.ts","sourceRoot":"","sources":["../src/fuma-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGlD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;MAGpB,CAAC;AAEH,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,SAAS,CAAC,CAAC;AAE5D,oDAAoD;AACpD,eAAO,MAAM,iBAAiB,SAAmB,CAAC"}
1
+ {"version":3,"file":"fuma-db.d.ts","sourceRoot":"","sources":["../src/fuma-db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGlD;;;GAGG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAGpB,CAAC;AAEH,iDAAiD;AACjD,MAAM,MAAM,eAAe,GAAG,WAAW,CAAC,OAAO,SAAS,CAAC,CAAC;AAE5D,oDAAoD;AACpD,eAAO,MAAM,iBAAiB,SAAmB,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,10 +1,11 @@
1
- export { DB_SCHEMA_VERSION, DimahS3DB, type DimahS3DbClient } from "./fuma-db";
2
- export { db, type DbPluginContext } from "./plugin/db";
3
- export type { PruneDeletedOptions, PurgeStaleOptions, PurgeStaleResult, } from "./plugin/purge";
4
- export type { DbFolders, DbObjects } from "./plugin/public-stores";
5
- export type { AuthorizeContext, DbAttributesOptions, DbPluginOptions, DbQuotaOption, DbRouteOptions, ScopeContext, ScopeOperation, } from "./types/plugin";
6
- export type { StorageFolder, StorageObject, StorageObjectStatus, } from "./types/storage-object";
7
- export type { DbClientFolder, DbClientObject, DbListSort, DbListSortField, DbQuota, DbUsage, } from "./types/client";
8
- export type { StandardSchemaV1 } from "./standard-schema";
9
- export type { ListObjectsInput, ListObjectsPage, ObjectFilter, ObjectRef, UpdateObjectInput, } from "./store/object-store";
1
+ export { DB_SCHEMA_VERSION, DimahS3DB, type DimahS3DbClient } from "./fuma-db.js";
2
+ export { db, type DbPluginContext } from "./plugin/db.js";
3
+ export type { PruneDeletedOptions, PurgeStaleOptions, PurgeStaleResult, } from "./plugin/purge.js";
4
+ export type { RecordObjectCall, RecordObjectInput } from "./plugin/record.js";
5
+ export type { DbFolders, DbObjects } from "./plugin/public-stores.js";
6
+ export type { AuthorizeContext, DbAttributesOptions, DbPluginOptions, DbQuotaOption, DbRouteOptions, ScopeContext, ScopeOperation, } from "./types/plugin.js";
7
+ export type { StorageFolder, StorageObject, StorageObjectStatus, } from "./types/storage-object.js";
8
+ export type { DbClientFolder, DbClientObject, DbListSort, DbListSortField, DbQuota, DbUsage, } from "./types/client.js";
9
+ export type { StandardSchemaV1 } from "./standard-schema.js";
10
+ export type { ListObjectsInput, ListObjectsPage, ObjectFilter, ObjectRef, UpdateObjectInput, } from "./store/object-store.js";
10
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAG/E,OAAO,EAAE,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,cAAc,EACd,cAAc,EACd,UAAU,EACV,eAAe,EACf,OAAO,EACP,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,KAAK,eAAe,EAAE,MAAM,WAAW,CAAC;AAG/E,OAAO,EAAE,EAAE,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACvD,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAC3E,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnE,YAAY,EACV,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,cAAc,EACd,YAAY,EACZ,cAAc,GACf,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACV,aAAa,EACb,aAAa,EACb,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAChC,YAAY,EACV,cAAc,EACd,cAAc,EACd,UAAU,EACV,eAAe,EACf,OAAO,EACP,OAAO,GACR,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,sBAAsB,CAAC"}