@im-nobsidian/core 0.1.7 → 0.1.9

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.
package/dist/index.d.ts CHANGED
@@ -246,6 +246,8 @@ interface SyncRecord {
246
246
  readonly fileType: FileType;
247
247
  readonly status: SyncStatus;
248
248
  readonly baseSnapshot: Buffer | null;
249
+ readonly localMtime: string | null;
250
+ readonly localFileSize: number | null;
249
251
  readonly version: number;
250
252
  readonly createdAt: string;
251
253
  readonly updatedAt: string;
@@ -279,21 +281,25 @@ interface ProgressItem {
279
281
  type ProgressCallback = (current: number, total: number, item: ProgressItem) => void;
280
282
  interface PushOptions {
281
283
  readonly paths?: string[];
284
+ readonly excludePaths?: string[];
282
285
  readonly force?: boolean;
283
286
  readonly dryRun?: boolean;
284
287
  readonly onProgress?: ProgressCallback;
288
+ readonly signal?: AbortSignal;
285
289
  }
286
290
  interface PullOptions {
287
291
  readonly paths?: string[];
288
292
  readonly force?: boolean;
289
293
  readonly dryRun?: boolean;
290
294
  readonly onProgress?: ProgressCallback;
295
+ readonly signal?: AbortSignal;
291
296
  }
292
297
  interface SyncOptions {
293
298
  readonly paths?: string[];
294
299
  readonly force?: boolean;
295
300
  readonly dryRun?: boolean;
296
301
  readonly onProgress?: ProgressCallback;
302
+ readonly signal?: AbortSignal;
297
303
  }
298
304
  interface PushResult {
299
305
  readonly created: number;
@@ -460,7 +466,35 @@ declare class ConfigManager {
460
466
  isInitialized(): Promise<boolean>;
461
467
  }
462
468
 
463
- declare class StateDB {
469
+ interface IStateDB {
470
+ close(): void;
471
+ getByPath(path: string): SyncRecord | null;
472
+ getByNotionId(pageId: string): SyncRecord | null;
473
+ getByStatus(status: SyncStatus): SyncRecord[];
474
+ getAll(): SyncRecord[];
475
+ upsert(record: UpsertSyncRecord): SyncRecord;
476
+ updateStatus(id: string, status: SyncStatus): void;
477
+ updateHash(id: string, hash: string, snapshot?: Buffer | Uint8Array | null): void;
478
+ setNotionLastEdited(id: string, lastEdited: string): void;
479
+ updateStatCache(id: string, mtime: string, fileSize: number): void;
480
+ setNotionParentId(id: string, parentId: string): void;
481
+ delete(id: string): void;
482
+ resolveWikilink(text: string): WikilinkEntry | null;
483
+ resolvePageId(pageId: string): WikilinkEntry | null;
484
+ upsertWikilink(entry: WikilinkEntry): void;
485
+ getMeta(key: string): string | null;
486
+ setMeta(key: string, value: string): void;
487
+ isFileRegistered(localPath: string): boolean;
488
+ getFileRegistry(localPath: string): FileRegistryEntry | null;
489
+ getFilesByPageId(notionPageId: string): FileRegistryEntry[];
490
+ registerFile(entry: RegisterFileInput): void;
491
+ deleteFileRegistry(localPath: string): void;
492
+ storePreserveMarkers(path: string, markers: PreserveMarker[]): void;
493
+ getPreserveMarkers(path: string): PreserveMarker[];
494
+ transaction<T>(fn: () => T): T;
495
+ }
496
+
497
+ declare class StateDB implements IStateDB {
464
498
  private readonly db;
465
499
  private constructor();
466
500
  static open(dbPath: string): StateDB;
@@ -475,6 +509,7 @@ declare class StateDB {
475
509
  updateStatus(id: string, status: SyncStatus): void;
476
510
  updateHash(id: string, hash: string, snapshot?: Buffer | null): void;
477
511
  setNotionLastEdited(id: string, lastEdited: string): void;
512
+ updateStatCache(id: string, mtime: string, fileSize: number): void;
478
513
  setNotionParentId(id: string, parentId: string): void;
479
514
  delete(id: string): void;
480
515
  resolveWikilink(text: string): WikilinkEntry | null;
@@ -505,6 +540,8 @@ interface UpsertSyncRecord {
505
540
  readonly fileType: SyncRecord["fileType"];
506
541
  readonly status: SyncRecord["status"];
507
542
  readonly baseSnapshot?: Buffer | null;
543
+ readonly localMtime?: string | null;
544
+ readonly localFileSize?: number | null;
508
545
  }
509
546
  interface FileRegistryEntry {
510
547
  readonly id: string;
@@ -528,12 +565,14 @@ interface NotionClientOptions {
528
565
  readonly token: string;
529
566
  readonly concurrency?: number;
530
567
  readonly timeoutMs?: number;
568
+ readonly fetch?: typeof globalThis.fetch;
531
569
  }
532
570
  declare class NotionClient {
533
571
  private readonly client;
534
572
  private readonly sema;
535
573
  private readonly token;
536
574
  private readonly propertyMapper;
575
+ private readonly customFetch?;
537
576
  constructor(options: NotionClientOptions);
538
577
  getInternalClient(): Client;
539
578
  getPage(pageId: string): Promise<PageObjectResponse>;
@@ -604,6 +643,10 @@ declare class NotionClient {
604
643
  results: PageObjectResponse[];
605
644
  nextCursor: string | null;
606
645
  }>;
646
+ searchRecentPages(since: string): Promise<Array<{
647
+ id: string;
648
+ last_edited_time: string;
649
+ }>>;
607
650
  getChildPages(parentId: string): Promise<PageObjectResponse[]>;
608
651
  getChildDatabaseIds(parentId: string): Promise<string[]>;
609
652
  getChildPagesRecursive(parentId: string): Promise<PageObjectResponse[]>;
@@ -751,7 +794,8 @@ interface FileInfo {
751
794
  }
752
795
  declare class ChangeDetector {
753
796
  private readonly stateDb;
754
- constructor(stateDb: StateDB);
797
+ constructor(stateDb: IStateDB);
798
+ detectLocalChangesFast(stats: FileStatInfo[], readFile: (path: string) => Promise<string>): Promise<LocalChange[]>;
755
799
  detectLocalChanges(currentFiles: FileInfo[]): LocalChange[];
756
800
  private detectMoves;
757
801
  }
@@ -761,6 +805,11 @@ interface NonMdFileInfo {
761
805
  readonly size: number;
762
806
  readonly mtime: string;
763
807
  }
808
+ interface FileStatInfo {
809
+ readonly path: string;
810
+ readonly mtime: string;
811
+ readonly size: number;
812
+ }
764
813
  interface VaultFS {
765
814
  readFile(path: string): Promise<string>;
766
815
  readBinary(path: string): Promise<Buffer>;
@@ -771,7 +820,9 @@ interface VaultFS {
771
820
  exists(path: string): Promise<boolean>;
772
821
  ensureFolder(path: string): Promise<void>;
773
822
  listMarkdownFiles(): Promise<FileInfo[]>;
823
+ listMarkdownFileStats(): Promise<FileStatInfo[]>;
774
824
  listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
825
+ getFileStat(path: string): Promise<FileStatInfo | null>;
775
826
  }
776
827
 
777
828
  declare class SyncOrchestrator {
@@ -789,14 +840,22 @@ declare class SyncOrchestrator {
789
840
  private dbSchemaLoaded;
790
841
  private _pullImageCount;
791
842
  private _pullFileCount;
792
- constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS);
843
+ constructor(config: Config, stateDb: IStateDB, notionClient: NotionClient, vaultFs: VaultFS, customFetch?: typeof globalThis.fetch);
793
844
  push(options?: PushOptions): Promise<PushResult>;
794
845
  pull(options?: PullOptions): Promise<PullResult>;
795
846
  sync(options?: SyncOptions): Promise<SyncResult>;
796
847
  status(): Promise<StatusResult>;
848
+ statusLocal(): Promise<StatusResult>;
849
+ fetch(): Promise<{
850
+ newPages: number;
851
+ deletedPages: number;
852
+ modifiedPages: number;
853
+ duration: number;
854
+ }>;
797
855
  private buildConflictsFromRecords;
798
856
  private get isDatabaseMode();
799
857
  private discoverChildDatabases;
858
+ private pullDiscoveredDatabases;
800
859
  private resolveNotionLinks;
801
860
  private ensureDbSchema;
802
861
  private pushCreate;
@@ -804,16 +863,18 @@ declare class SyncOrchestrator {
804
863
  private pushDelete;
805
864
  private pushMove;
806
865
  private detectRemoteChanges;
866
+ private detectRemoteChangesIncremental;
867
+ private isTrackedParent;
807
868
  private pullCreate;
808
869
  private pullUpdate;
809
870
  private pullDelete;
810
871
  private ensureFolderPage;
811
872
  private resolveNotionParent;
873
+ private repairFolderRecords;
812
874
  private isFolderNote;
813
875
  private resolveParentPath;
814
876
  private pushCreatePage;
815
877
  private pushUpdatePage;
816
- private computePatches;
817
878
  private fetchPageMarkdown;
818
879
  private extractParentId;
819
880
  private resolveBlockToPageId;
@@ -840,10 +901,13 @@ declare class NodeVaultFS implements VaultFS {
840
901
  exists(path: string): Promise<boolean>;
841
902
  ensureFolder(path: string): Promise<void>;
842
903
  listMarkdownFiles(): Promise<FileInfo[]>;
904
+ listMarkdownFileStats(): Promise<FileStatInfo[]>;
905
+ getFileStat(path: string): Promise<FileStatInfo | null>;
843
906
  listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
844
907
  private matchesPattern;
845
908
  private isExcluded;
846
909
  private walkDirNonMd;
910
+ private walkDirStats;
847
911
  private walkDir;
848
912
  }
849
913
 
@@ -861,7 +925,9 @@ declare class ImageHandler {
861
925
  private readonly vaultFs;
862
926
  private readonly attachmentFolder;
863
927
  private readonly notionClient?;
864
- constructor(vaultFs: VaultFS, attachmentFolder?: string, notionClient?: NotionClient | undefined);
928
+ private readonly customFetch?;
929
+ constructor(vaultFs: VaultFS, attachmentFolder?: string, notionClient?: NotionClient | undefined, customFetch?: typeof globalThis.fetch);
930
+ private get fetchFn();
865
931
  downloadImage(url: string, pageTitle: string): Promise<ImageDownloadResult>;
866
932
  downloadAllImages(markdown: string, pageTitle: string): Promise<{
867
933
  content: string;
@@ -900,7 +966,7 @@ declare class FileHandler {
900
966
  private readonly notionClient;
901
967
  private readonly stateDb;
902
968
  private readonly sema;
903
- constructor(vaultFs: VaultFS, notionClient: NotionClient, stateDb: StateDB);
969
+ constructor(vaultFs: VaultFS, notionClient: NotionClient, stateDb: IStateDB);
904
970
  pushFilesForFolder(folderPageId: string, folderPath: string): Promise<FileUploadResult[]>;
905
971
  pushAllFiles(): Promise<FileUploadResult[]>;
906
972
  downloadFileBlock(url: string, filename: string, targetFolder: string): Promise<FileDownloadResult>;
@@ -937,7 +1003,7 @@ declare class DatabaseSyncer {
937
1003
  private readonly pipeline;
938
1004
  private readonly imageHandler;
939
1005
  private readonly propertyMapper;
940
- constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS, pipeline: ConversionPipeline, imageHandler: ImageHandler);
1006
+ constructor(config: Config, stateDb: IStateDB, notionClient: NotionClient, vaultFs: VaultFS, pipeline: ConversionPipeline, imageHandler: ImageHandler);
941
1007
  pullAll(): Promise<DatabaseSyncResult>;
942
1008
  pushAll(): Promise<DatabaseSyncResult>;
943
1009
  pullDatabase(dbConfig: DatabaseSyncConfig): Promise<DatabaseSyncResult>;
@@ -1115,7 +1181,7 @@ interface ResolutionResult {
1115
1181
  declare class ConflictResolver {
1116
1182
  private readonly stateDb;
1117
1183
  private readonly vaultFs;
1118
- constructor(stateDb: StateDB, vaultFs: VaultFS);
1184
+ constructor(stateDb: IStateDB, vaultFs: VaultFS);
1119
1185
  resolve(conflict: Conflict, choice: ResolutionChoice): Promise<ResolutionResult>;
1120
1186
  resolveByStrategy(conflict: Conflict, strategy: ConflictStrategy): Promise<ResolutionResult>;
1121
1187
  resolveAll(conflicts: Conflict[], strategy: ConflictStrategy): Promise<ResolutionResult[]>;
@@ -1287,6 +1353,13 @@ declare function getVisibleProperties(viewConfig: ViewConfig): Array<{
1287
1353
  name: string;
1288
1354
  width?: number;
1289
1355
  }>;
1356
+ interface FilterCondition {
1357
+ property: string;
1358
+ operator: "equals" | "contains" | "startsWith" | "isEmpty" | "isNotEmpty" | "gt" | "lt" | "between";
1359
+ value?: string | number | boolean;
1360
+ valueTo?: string | number;
1361
+ }
1362
+ declare function filterEntries(entries: DBEntry[], searchQuery?: string, filters?: FilterCondition[]): DBEntry[];
1290
1363
 
1291
1364
  declare function getNotionColor(color: NotionColor | string): string;
1292
1365
  declare function getNotionBgColor(color: NotionColor | string): string;
@@ -1315,4 +1388,4 @@ interface PipelineOptions {
1315
1388
  }
1316
1389
  declare function createDefaultPipeline(options?: PipelineOptions): ConversionPipeline;
1317
1390
 
1318
- export { BlockConverter, type CalendarEntry, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, type CoverConfig, type DBEntry, DEFAULT_CONFIG, type DatabaseSyncConfig, type DatabaseSyncResult, DatabaseSyncer, type DatabaseViewsConfig, EmbedResolver, EntryEditor, type FailedOperation, type FileDownloadResult, FileHandler, type FileInfo, type FileSystemEntry, type FileType, type FileUploadResult, FileWatcher, FrontmatterExtractor, FrontmatterGenerator, type GroupByConfig, type GroupedEntries, HtmlAnnotationStripper, type ImageDownloadResult, ImageHandler, type ImageReference, InlineDBParser, type LocalChange, LocalImageRestorer, type Logger, type MappingResult, type MappingType, MathNormalizer, MentionToWikilink, type MergeConflictRegion, type MergeResult, NodeVaultFS, type NonMdFileInfo, type NotionBlock, NotionBlockBuilder, NotionClient, type NotionClientOptions, type NotionColor, type NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCover, type PageCreationPlan, type PageIcon, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, type ProgressItem, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, type PropertyOption, type PropertySchema, type PropertyValue, type PullOptions, type PullResult, type PushOptions, type PushResult, type RemoteChange, type ResolutionChoice, type ResolutionResult, type RichTextSegment, StateDB, type StatusResult, type SyncDirection, type SyncOptions, SyncOrchestrator, type SyncRecord, type SyncResult, type SyncStatus, TreeMapper, UnsupportedBlockStripper, type UpsertSyncRecord, type VaultFS, type ViewConfig, ViewDataProvider, type ViewPropertyConfig, type ViewRenderData, type ViewType, type WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, extractCalendarEntries, filterByMonth, generateColorCSS, generateId, getLogger, getNotionBgColor, getNotionColor, getVisibleProperties, groupEntries, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, sortEntries, threeWayMerge };
1391
+ export { BlockConverter, type CalendarEntry, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, type CoverConfig, type DBEntry, DEFAULT_CONFIG, type DatabaseSyncConfig, type DatabaseSyncResult, DatabaseSyncer, type DatabaseViewsConfig, EmbedResolver, EntryEditor, type FailedOperation, type FileDownloadResult, FileHandler, type FileInfo, type FileRegistryEntry, type FileStatInfo, type FileSystemEntry, type FileType, type FileUploadResult, FileWatcher, type FilterCondition, FrontmatterExtractor, FrontmatterGenerator, type GroupByConfig, type GroupedEntries, HtmlAnnotationStripper, type IStateDB, type ImageDownloadResult, ImageHandler, type ImageReference, InlineDBParser, type LocalChange, LocalImageRestorer, type Logger, type MappingResult, type MappingType, MathNormalizer, MentionToWikilink, type MergeConflictRegion, type MergeResult, NodeVaultFS, type NonMdFileInfo, type NotionBlock, NotionBlockBuilder, NotionClient, type NotionClientOptions, type NotionColor, type NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCover, type PageCreationPlan, type PageIcon, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, type ProgressItem, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, type PropertyOption, type PropertySchema, type PropertyValue, type PullOptions, type PullResult, type PushOptions, type PushResult, type RegisterFileInput, type RemoteChange, type ResolutionChoice, type ResolutionResult, type RichTextSegment, StateDB, type StatusResult, type SyncDirection, type SyncOptions, SyncOrchestrator, type SyncRecord, type SyncResult, type SyncStatus, TreeMapper, UnsupportedBlockStripper, type UpsertSyncRecord, type VaultFS, type ViewConfig, ViewDataProvider, type ViewPropertyConfig, type ViewRenderData, type ViewType, type WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, extractCalendarEntries, filterByMonth, filterEntries, generateColorCSS, generateId, getLogger, getNotionBgColor, getNotionColor, getVisibleProperties, groupEntries, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, sortEntries, threeWayMerge };