feat: expose trash entry size metadata

This commit is contained in:
mirivlad 2026-07-10 08:30:39 +08:00
parent dd9168dad5
commit 5ddf7f2020
9 changed files with 11 additions and 4 deletions

View File

@ -1 +1 @@
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,KAAK,EAAwB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQ3E,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,4BAA4B,CAAC;CAC9C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAetF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CASnF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAAgB,EAAE,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,CA2WlH;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCxF;AAGD,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,CAAC"} {"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../src/test-utils.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,4BAA4B,EAAE,MAAM,SAAS,CAAC;AACzF,OAAO,KAAK,EAAwB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAQ3E,MAAM,WAAW,oBAAoB;IACnC,aAAa,CAAC,EAAE,4BAA4B,CAAC;CAC9C;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,cAAc,CAetF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,WAAW,CASnF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,SAAgB,EAAE,OAAO,GAAE,oBAAyB,GAAG,gBAAgB,CA4WlH;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,OAAO,GAAG;IAAE,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAgCxF;AAGD,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC5B,OAAO,EAAE,EAAE,EAAE,CAAC"}

1
dist/test-utils.js vendored
View File

@ -327,6 +327,7 @@ export function createMockPluginAPI(pluginId = 'test.plugin', options = {}) {
deletedAt: new Date().toISOString(), deletedAt: new Date().toISOString(),
originalType: node.type, originalType: node.type,
basename: baseName(path), basename: baseName(path),
size: node.type === 'file' ? (node.content || '').length : 0,
}; };
const moving = Array.from(files.entries()).filter(([candidate]) => candidate === path || candidate.startsWith(`${path}/`)); const moving = Array.from(files.entries()).filter(([candidate]) => candidate === path || candidate.startsWith(`${path}/`));
trashPayloads.set(trashId, moving.map(([candidate, movingNode]) => ({ trashPayloads.set(trashId, moving.map(([candidate, movingNode]) => ({

File diff suppressed because one or more lines are too long

2
dist/types.d.ts vendored
View File

@ -105,6 +105,8 @@ export interface TrashResult {
trashPath: string; trashPath: string;
trashId: string; trashId: string;
deletedAt: string; deletedAt: string;
/** Original regular-file size in bytes, when the host can provide it. */
size?: number;
} }
export interface TrashEntry extends TrashResult { export interface TrashEntry extends TrashResult {
originalType: FileEntry['type']; originalType: FileEntry['type'];

2
dist/types.d.ts.map vendored

File diff suppressed because one or more lines are too long

View File

@ -32,7 +32,7 @@
{ "name": "vault.watch", "description": "Watch vault file changes", "dangerous": false }, { "name": "vault.watch", "description": "Watch vault file changes", "dangerous": false },
{ "name": "files.read", "description": "List files and read bounded text or byte payloads through the vault Files API", "dangerous": false }, { "name": "files.read", "description": "List files and read bounded text or byte payloads through the vault Files API", "dangerous": false },
{ "name": "files.write", "description": "Create folders, write bounded text or byte payloads, and move paths through the vault Files API", "dangerous": true }, { "name": "files.write", "description": "Create folders, write bounded text or byte payloads, and move paths through the vault Files API", "dangerous": true },
{ "name": "files.delete", "description": "Trash vault files and folders through the vault Files API", "dangerous": true }, { "name": "files.delete", "description": "Trash vault files and folders and permanently delete trash entries through the vault Files API", "dangerous": true },
{ "name": "files.openExternal", "description": "Open vault files and folders in external OS applications", "dangerous": true }, { "name": "files.openExternal", "description": "Open vault files and folders in external OS applications", "dangerous": true },
{ "name": "storage.namespace", "description": "Read/write plugin's own storage namespace", "dangerous": false }, { "name": "storage.namespace", "description": "Read/write plugin's own storage namespace", "dangerous": false },
{ "name": "storage.migrations", "description": "Run database migrations in plugin namespace", "dangerous": false }, { "name": "storage.migrations", "description": "Run database migrations in plugin namespace", "dangerous": false },

View File

@ -351,6 +351,7 @@ describe('VerstakPluginAPI contract', () => {
expect(trash.originalPath).toBe('PlatformTest/two.txt'); expect(trash.originalPath).toBe('PlatformTest/two.txt');
expect(trash.trashId).toBeTruthy(); expect(trash.trashId).toBeTruthy();
expect(trash.trashPath).toMatch(/^\.verstak\/trash\/files\/.+\/two\.txt$/); expect(trash.trashPath).toMatch(/^\.verstak\/trash\/files\/.+\/two\.txt$/);
expect(trash.size).toBe(5);
await expect(api.files.listTrash()).resolves.toEqual([ await expect(api.files.listTrash()).resolves.toEqual([
expect.objectContaining({ originalPath: 'PlatformTest/two.txt', trashId: trash.trashId }), expect.objectContaining({ originalPath: 'PlatformTest/two.txt', trashId: trash.trashId }),
]); ]);

View File

@ -316,6 +316,7 @@ export function createMockPluginAPI(pluginId = 'test.plugin', options: MockPlugi
deletedAt: new Date().toISOString(), deletedAt: new Date().toISOString(),
originalType: node.type, originalType: node.type,
basename: baseName(path), basename: baseName(path),
size: node.type === 'file' ? (node.content || '').length : 0,
}; };
const moving = Array.from(files.entries()).filter(([candidate]) => candidate === path || candidate.startsWith(`${path}/`)); const moving = Array.from(files.entries()).filter(([candidate]) => candidate === path || candidate.startsWith(`${path}/`));
trashPayloads.set(trashId, moving.map(([candidate, movingNode]) => ({ trashPayloads.set(trashId, moving.map(([candidate, movingNode]) => ({

View File

@ -154,6 +154,8 @@ export interface TrashResult {
trashPath: string; trashPath: string;
trashId: string; trashId: string;
deletedAt: string; deletedAt: string;
/** Original regular-file size in bytes, when the host can provide it. */
size?: number;
} }
export interface TrashEntry extends TrashResult { export interface TrashEntry extends TrashResult {