Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Addon } from "./src/addon-wrapper";
import { QueueManager } from "./src/queue/queue-manager";
import { QueueItem, typeQueue, HandleAction, HandleActions } from "./src/queue/queueManager";
import VirtualDrive from "./src/virtual-drive";

export { VirtualDrive, QueueItem, typeQueue, HandleAction, HandleActions, QueueManager };
export { Addon, VirtualDrive, QueueItem, typeQueue, HandleAction, HandleActions, QueueManager };
148 changes: 148 additions & 0 deletions src/addon-wrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import { addon } from "./addon";
import { addonZod } from "./addon/addon-zod";
import { Callbacks } from "./types/callbacks.type";

export class Addon {
syncRootPath!: string;

private parseAddonZod<T>(fn: keyof typeof addonZod, data: T) {
const schema = addonZod[fn];
const result = schema.safeParse(data);
if (result.error) console.error(fn, result.error);
return data;
}

registerSyncRoot({
syncRootPath,
providerName,
providerVersion,
providerId,
logoPath,
}: {
syncRootPath: string;
providerName: string;
providerVersion: string;
providerId: string;
logoPath: string;
}) {
this.syncRootPath = syncRootPath;
const result = addon.registerSyncRoot(this.syncRootPath, providerName, providerVersion, providerId, logoPath);
return this.parseAddonZod("registerSyncRoot", result);
}

connectSyncRoot({ callbacks }: { callbacks: Callbacks }) {
const result = addon.connectSyncRoot(this.syncRootPath, callbacks);
return this.parseAddonZod("connectSyncRoot", result);
}

unregisterSyncRoot({ syncRootPath }: { syncRootPath: string }) {
const result = addon.unregisterSyncRoot(syncRootPath);
return this.parseAddonZod("unregisterSyncRoot", result);
}

disconnectSyncRoot() {
addon.disconnectSyncRoot(this.syncRootPath);
}

addLogger({ logPath }: { logPath: string }) {
const result = addon.addLoggerPath(logPath);
return this.parseAddonZod("addLoggerPath", result);
}

getPlaceholderState({ path }: { path: string }) {
const result = addon.getPlaceholderState(path);
return this.parseAddonZod("getPlaceholderState", result);
}

getPlaceholderWithStatePending() {
const result = addon.getPlaceholderWithStatePending(this.syncRootPath);
return this.parseAddonZod("getPlaceholderWithStatePending", result);
}

getFileIdentity({ path }: { path: string }) {
const result = addon.getFileIdentity(path);
return this.parseAddonZod("getFileIdentity", result);
}

async deleteFileSyncRoot({ path }: { path: string }) {
return addon.deleteFileSyncRoot(path);
}

createPlaceholderFile({
fileName,
fileId,
fileSize,
fileAttributes,
creationTime,
lastWriteTime,
lastAccessTime,
basePath,
}: {
fileName: string;
fileId: string;
fileSize: number;
fileAttributes: number;
creationTime: string;
lastWriteTime: string;
lastAccessTime: string;
basePath: string;
}) {
return addon.createPlaceholderFile(fileName, fileId, fileSize, fileAttributes, creationTime, lastWriteTime, lastAccessTime, basePath);
}

createPlaceholderDirectory({
itemName,
itemId,
isDirectory,
itemSize,
fileAttributes,
creationTime,
lastWriteTime,
lastAccessTime,
path,
}: {
itemName: string;
itemId: string;
isDirectory: boolean;
itemSize: number;
fileAttributes: number;
creationTime: string;
lastWriteTime: string;
lastAccessTime: string;
path: string;
}) {
return addon.createEntry(itemName, itemId, isDirectory, itemSize, fileAttributes, creationTime, lastWriteTime, lastAccessTime, path);
}

/**
* @deprecated
*/
updateSyncStatus({ path, isDirectory, sync }: { path: string; isDirectory: boolean; sync: boolean }) {
const result = addon.updateSyncStatus(path, sync, isDirectory);
return this.parseAddonZod("updateSyncStatus", result);
}

convertToPlaceholder({ path, id }: { path: string; id: string }) {
const result = addon.convertToPlaceholder(path, id);
return this.parseAddonZod("convertToPlaceholder", result);
}

updateFileIdentity({ path, id, isDirectory }: { path: string; id: string; isDirectory: boolean }) {
addon.updateFileIdentity(path, id, isDirectory);
}

dehydrateFile({ path }: { path: string }) {
const result = addon.dehydrateFile(path);
return this.parseAddonZod("dehydrateFile", result);
}

async hydrateFile({ path }: { path: string }) {
const result = await addon.hydrateFile(path);
return this.parseAddonZod("hydrateFile", result);
}

getPlaceholderAttribute({ path }: { path: string }) {
const result = addon.getPlaceholderAttribute(path);
return this.parseAddonZod("getPlaceholderAttribute", result);
}
}
7 changes: 3 additions & 4 deletions src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type TAddon = {
fileName: string,
fileId: string,
fileSize: number,
combinedAttributes: number,
fileAttributes: number,
creationTime: string,
lastWriteTime: string,
lastAccessTime: string,
Expand All @@ -25,7 +25,7 @@ export type TAddon = {
fileAttributes: number,
creationTime: string,
lastWriteTime: string,
lastAccessTime: number,
lastAccessTime: string,
path: string,
): any;
hydrateFile(path: string): Promise<z.infer<typeof addonZod.hydrateFile>>;
Expand All @@ -48,9 +48,8 @@ export type TAddon = {
callbacks: any,
logoPath: string,
): z.infer<typeof addonZod.registerSyncRoot>;
registerSyncRootWindowsStorageProvider(path: string, providerName: string, providerVersion: string, providerId: string): any;
unregisterSyncRoot(path: string): z.infer<typeof addonZod.unregisterSyncRoot>;
updateSyncStatus(path: string, sync: boolean, isDirectory: boolean): any;
updateSyncStatus(path: string, sync: boolean, isDirectory: boolean): z.infer<typeof addonZod.updateSyncStatus>;
/**
* TODO: Returns a type in c++ that is not initialized
*/
Expand Down
Loading