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
7 changes: 4 additions & 3 deletions examples/callbacks/notify-fetch-data.callback.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { logger } from "examples/drive";
import { getInfoItem } from "examples/info-items-manager";

import { TFetchDataCallback } from "@/types/callbacks.type";
import { sleep } from "@/utils";

type TCallback = (data: boolean, path: string, errorHandler?: () => void) => Promise<{ finished: boolean; progress: number }>;

export const fetchDataCallback = async (id: string, callback: TCallback) => {
export const fetchDataCallback = async (id: string, callback: Parameters<TFetchDataCallback>[1]) => {
logger.info({ fn: "fetchDataCallback", id });
const path = await getInfoItem(id);

let finish = false;
Expand Down
3 changes: 1 addition & 2 deletions examples/get-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ const { data } = z.object({ file: z.string() }).safeParse(argv);
if (data) {
const path = data.file;
const state = drive.getPlaceholderState(path);
const pendingStates = drive.getPlaceholderWithStatePending();
logger.info({ state, pendingStates });
logger.info({ state });
} else {
logger.error("Por favor especifica un archivo con --file <path>");
}
8 changes: 4 additions & 4 deletions examples/handlers/handle-change-size.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { drive, logger } from "examples/drive";
import { v4 } from "uuid";

import { QueueItem } from "@/queue/queueManager";

export const handleChangeSize = async (task: QueueItem) => {
try {
logger.info({ fn: "handleChangeSize", path: task.path });
const result = Math.random().toString(36).substring(2, 7);
drive.convertToPlaceholder(task.path, result);
drive.updateFileIdentity(task.path, result, false);
drive.updateSyncStatus(task.path, task.isFolder, true);
const id = v4();
drive.convertToPlaceholder(task.path, id);
drive.updateFileIdentity(task.path, id, false);
} catch (error) {
logger.error("handleChangeSize", error);
}
Expand Down
5 changes: 4 additions & 1 deletion examples/populate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { v4 } from "uuid";

import settings from "./settings";

const rootFile1 = join(settings.syncRootPath, v4());
const rootFileName1 = v4();
const rootZipFileName = `${v4()}.zip`;
const rootFile1 = join(settings.syncRootPath, rootFileName1);
const rootFile2ChangeSize = join(settings.syncRootPath, `change-size-${v4()}.txt`);
const rootFile3 = join(settings.syncRootPath, `${v4()}.txt`);
const rootFile3Moved = join(settings.syncRootPath, `moved-${v4()}.txt`);
Expand All @@ -22,6 +24,7 @@ execSync(`echo Hello, world! > ${rootFile2ChangeSize}`);
execSync(`echo Hello, world! >> ${rootFile2ChangeSize}`); // Sync
execSync(`echo Hello, world! > ${rootFile3}`);
execSync(`type nul > ${rootFile4}`); // No sync (0 bytes)
execSync(`cd ${settings.syncRootPath} && tar -cf ${rootZipFileName} ${rootFileName1}`); // Sync
execSync(`mv ${rootFile3} ${rootFile3Moved}`); // Sync
execSync(`mkdir ${rootFolder1}`); // Sync
execSync(`mkdir ${rootFolder2}`); // Cloud (no files inside)
Expand Down
12 changes: 7 additions & 5 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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";
import { Addon } from "@/addon-wrapper";
import { QueueManager } from "@/queue/queue-manager";
import { QueueItem, typeQueue, HandleAction, HandleActions } from "@/queue/queueManager";
import { Callbacks } from "@/types/callbacks.type";
import { PinState, SyncState } from "@/types/placeholder.type";
import VirtualDrive from "@/virtual-drive";

export { Addon, VirtualDrive, QueueItem, typeQueue, HandleAction, HandleActions, QueueManager };
export { Addon, VirtualDrive, QueueItem, typeQueue, HandleAction, HandleActions, QueueManager, Callbacks, PinState, SyncState };
19 changes: 0 additions & 19 deletions jest.config.js

This file was deleted.

11 changes: 3 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"types": "dist/index.d.ts",
"scripts": {
"========== Testing ==========": "",
"test": "jest",
"vitest": "vitest",
"vitest:once": "yarn vitest --run",
"vitest:one": "yarn vitest related x",
"test": "vitest",
"test:once": "yarn vitest --run",
"test:one": "yarn vitest related x",
"========== Build ==========": "",
"clean": "node-gyp clean",
"build:gyp": "node-gyp configure build",
Expand All @@ -29,15 +28,11 @@
"gypfile": true,
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^5.2.1",
"@types/jest": "^29.5.12",
"@types/lodash.chunk": "^4.2.9",
"@types/node": "^20.5.0",
"@types/yargs": "^17.0.32",
"jest": "^29.7.0",
"jest-mock-extended": "^4.0.0-beta1",
"nodemon": "^3.1.9",
"prettier": "^3.4.2",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsc-alias": "^1.8.10",
"typescript": "^5.1.6",
Expand Down
5 changes: 0 additions & 5 deletions src/addon-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,4 @@ export class Addon {
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);
}
}
1 change: 0 additions & 1 deletion src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export type TAddon = {
path: string,
): any;
hydrateFile(path: string): Promise<z.infer<typeof addonZod.hydrateFile>>;
getPlaceholderAttribute(path: string): z.infer<typeof addonZod.getPlaceholderAttribute>;
dehydrateFile(path: string): z.infer<typeof addonZod.dehydrateFile>;
connectSyncRoot(path: string, callbacks: InputSyncCallbacks): z.infer<typeof addonZod.connectSyncRoot>;
convertToPlaceholder(path: string, id: string): z.infer<typeof addonZod.convertToPlaceholder>;
Expand Down
5 changes: 0 additions & 5 deletions src/addon/addon-zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ export const addonZod = {
convertToPlaceholder: z.boolean(),
dehydrateFile: z.boolean(),
getFileIdentity: z.string(),
getPlaceholderAttribute: z.object({ attribute: z.union([z.literal(0), z.literal(1), z.literal(2)]) }).transform(({ attribute }) => {
if (attribute === 1) return "NOT_PINNED";
if (attribute === 2) return "PINNED";
return "OTHER";
}),
getPlaceholderState: z.object({ pinState: z.nativeEnum(PinState), syncState: z.nativeEnum(SyncState) }),
getPlaceholderWithStatePending: z.array(z.string()),
hydrateFile: z.undefined(),
Expand Down
7 changes: 6 additions & 1 deletion src/types/callbacks.type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
export type NapiCallbackFunction = (...args: any[]) => any;

export type TFetchDataCallback = (
id: string,
callback: (data: boolean, path: string, errorHandler?: () => void) => Promise<{ finished: boolean; progress: number }>,
) => void;

export type InputSyncCallbacks = {
fetchDataCallback?: NapiCallbackFunction;
fetchDataCallback: TFetchDataCallback;
validateDataCallback?: NapiCallbackFunction;
cancelFetchDataCallback?: NapiCallbackFunction;
fetchPlaceholdersCallback?: NapiCallbackFunction;
Expand Down
47 changes: 33 additions & 14 deletions src/types/placeholder.type.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
// Enum para SyncState
export enum SyncState {
/**
* Status that occurs when an error occurs while reading the status.
*/
Undefined = -1,
NotInSync = 0,
InSync = 1,
}

// Enum para PinState
export enum PinState {
/**
* The pin state is derived from the state of the parent folder.
* For example new remote files start out in this state, following the state of their parent folder.
* This state is used purely for resetting pin states to their derived value.
* The effective state for an item will never be "Inherited".
*/
Inherited = 0,

/**
* The file shall be available and up to date locally. Also known as "pinned".
* Pinned dehydrated files shall be hydrated as soon as possible.
*/
AlwaysLocal = 1,

/**
* File shall be a dehydrated placeholder, filled on demand.
* Also known as "unpinned". Unpinned hydrated files shall be dehydrated as soon as possible.
* If a unpinned file becomes hydrated
* (such as due to an implicit hydration where the user requested access to the file's data)
* Its pin state changes to Unspecified.
*/
OnlineOnly = 2,
Unspecified = 3,
Excluded = 4,
}

// Tipo para combinar ambos estados en un objeto de estado
export type Status = {
pinState: PinState;
syncState: SyncState;
};
/**
* The user hasn't made a decision.
* The client or platform may hydrate or dehydrate as they see fit.
* New remote files in unspecified directories start unspecified, and dehydrated (which is an arbitrary decision).
*/
Unspecified = 3,

export enum Attributes {
OTHER = 0,
NOT_PINNED = 1,
PINNED = 2,
/**
* The file will never be synced to the cloud.
* Useful for ignored files to indicate to the OS the file will never besynced
*/
Excluded = 4,
}
Loading