There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat(native): NotifyEvent types
LongYinan8c84daec2bd5
diff --git a/packages/native/__tests__/fs.spec.mts b/packages/native/__tests__/fs.spec.mtsindex 463eb8d081..13e68d3020 100644--- a/packages/native/__tests__/fs.spec.mts+++ b/packages/native/__tests__/fs.spec.mts@@ -57,7 +57,7 @@ test('fs watch', { concurrency: false }, async t => {const defer = new Subject<void>();const subscription = watcher.subscribe(event => {- if (event.type.remove) {+ if (typeof event.type === 'object' && 'rename' in event.type) {assert.deepEqual(event.paths, [fixture]);assert.deepEqual(event.type, {remove: {diff --git a/packages/native/event.d.ts b/packages/native/event.d.tsnew file mode 100644index 0000000000..b7ba335486--- /dev/null+++ b/packages/native/event.d.ts@@ -0,0 +1,43 @@+export interface NotifyEvent {+ type: EventKind;+ paths: string[];+}++export type EventKind =+ | 'any'+ | 'other'+ | {+ remove: {+ kind: 'any' | 'file' | 'folder' | 'other';+ };+ }+ | {+ create: {+ kind: 'any' | 'file' | 'folder' | 'other';+ };+ }+ | {+ modify:+ | {+ kind: 'any' | 'other';+ }+ | {+ kind: 'data';+ mode: 'any' | 'size' | 'content' | 'other';+ }+ | {+ kind: 'metadata';+ mode:+ | 'any'+ | 'access-time'+ | 'write-time'+ | 'permissions'+ | 'ownership'+ | 'extended'+ | 'other';+ }+ | {+ kind: 'rename';+ mode: 'any' | 'to' | 'from' | 'both' | 'other';+ };+ };diff --git a/packages/native/index.d.ts b/packages/native/index.d.tsindex 5ab29c2023..711134bf3e 100644--- a/packages/native/index.d.ts+++ b/packages/native/index.d.ts@@ -27,6 +27,7 @@ export function watch(options?: WatchOptions | undefined | null): FSWatcher;export class Subscription {+ toString(): string;unsubscribe(): void;}export type FSWatcher = FsWatcher;@@ -34,11 +35,8 @@ export class FsWatcher {get kind(): WatcherKind;toString(): string;subscribe(- callback: (value: any) => any,- errorCallback?: (- err: Error | null,- value: undefined- ) => any | undefined | null+ callback: (event: import('./event').NotifyEvent) => void,+ errorCallback?: (err: Error) => void): Subscription;close(): void;}diff --git a/packages/native/package.json b/packages/native/package.jsonindex d694f971d1..5cb90bc3f3 100644--- a/packages/native/package.json+++ b/packages/native/package.json@@ -32,7 +32,7 @@"build": "napi build --platform --release","build:debug": "napi build --platform","universal": "napi universal",- "test": "cross-env TS_NODE_PROJECT=./tsconfig.json node --test --loader ts-node/esm --experimental-specifier-resolution=node ./__tests__/**/*.mts",+ "test": "cross-env TS_NODE_TRANSPILE_ONLY=1 TS_NODE_PROJECT=./tsconfig.json node --test --loader ts-node/esm --experimental-specifier-resolution=node ./__tests__/**/*.mts","version": "napi version"},"version": "0.6.0-canary.0"diff --git a/packages/native/src/fs.rs b/packages/native/src/fs.rsindex f1b6f91332..0c31ff99a6 100644--- a/packages/native/src/fs.rs+++ b/packages/native/src/fs.rs@@ -122,8 +122,9 @@ impl FSWatcher {#[napi]pub fn subscribe(&mut self,+ #[napi(ts_arg_type = "(event: import('./event').NotifyEvent) => void")]callback: ThreadsafeFunction<serde_json::Value, ErrorStrategy::Fatal>,- error_callback: Option<ThreadsafeFunction<()>>,+ #[napi(ts_arg_type = "(err: Error) => void")] error_callback: Option<ThreadsafeFunction<()>>,) -> Subscription {let uuid = uuid::Uuid::new_v4();let mut event_emitter = self.event_emitter.lock();