@im-nobsidian/core 0.1.2 → 0.1.4

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
@@ -2,6 +2,26 @@ import { z } from 'zod';
2
2
  import { Client } from '@notionhq/client';
3
3
  import { PageObjectResponse, BlockObjectResponse, PageMarkdownResponse, PartialBlockObjectResponse } from '@notionhq/client/build/src/api-endpoints.js';
4
4
 
5
+ declare const DatabaseSyncSchema: z.ZodObject<{
6
+ databaseId: z.ZodString;
7
+ localFolder: z.ZodString;
8
+ propertyMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
9
+ pullFilter: z.ZodOptional<z.ZodUnknown>;
10
+ titleProperty: z.ZodDefault<z.ZodString>;
11
+ }, "strip", z.ZodTypeAny, {
12
+ databaseId: string;
13
+ localFolder: string;
14
+ titleProperty: string;
15
+ propertyMapping?: Record<string, string> | undefined;
16
+ pullFilter?: unknown;
17
+ }, {
18
+ databaseId: string;
19
+ localFolder: string;
20
+ propertyMapping?: Record<string, string> | undefined;
21
+ pullFilter?: unknown;
22
+ titleProperty?: string | undefined;
23
+ }>;
24
+ type DatabaseSyncConfig = z.infer<typeof DatabaseSyncSchema>;
5
25
  declare const ConfigSchema: z.ZodObject<{
6
26
  version: z.ZodLiteral<1>;
7
27
  notion: z.ZodObject<{
@@ -10,18 +30,51 @@ declare const ConfigSchema: z.ZodObject<{
10
30
  workspaceId: z.ZodOptional<z.ZodString>;
11
31
  parentMode: z.ZodDefault<z.ZodEnum<["page", "database"]>>;
12
32
  databaseId: z.ZodOptional<z.ZodString>;
33
+ databases: z.ZodDefault<z.ZodArray<z.ZodObject<{
34
+ databaseId: z.ZodString;
35
+ localFolder: z.ZodString;
36
+ propertyMapping: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
37
+ pullFilter: z.ZodOptional<z.ZodUnknown>;
38
+ titleProperty: z.ZodDefault<z.ZodString>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ databaseId: string;
41
+ localFolder: string;
42
+ titleProperty: string;
43
+ propertyMapping?: Record<string, string> | undefined;
44
+ pullFilter?: unknown;
45
+ }, {
46
+ databaseId: string;
47
+ localFolder: string;
48
+ propertyMapping?: Record<string, string> | undefined;
49
+ pullFilter?: unknown;
50
+ titleProperty?: string | undefined;
51
+ }>, "many">>;
13
52
  }, "strip", z.ZodTypeAny, {
14
53
  token: string;
15
54
  rootPageId: string;
16
55
  parentMode: "page" | "database";
17
- workspaceId?: string | undefined;
56
+ databases: {
57
+ databaseId: string;
58
+ localFolder: string;
59
+ titleProperty: string;
60
+ propertyMapping?: Record<string, string> | undefined;
61
+ pullFilter?: unknown;
62
+ }[];
18
63
  databaseId?: string | undefined;
64
+ workspaceId?: string | undefined;
19
65
  }, {
20
66
  token: string;
21
67
  rootPageId: string;
68
+ databaseId?: string | undefined;
22
69
  workspaceId?: string | undefined;
23
70
  parentMode?: "page" | "database" | undefined;
24
- databaseId?: string | undefined;
71
+ databases?: {
72
+ databaseId: string;
73
+ localFolder: string;
74
+ propertyMapping?: Record<string, string> | undefined;
75
+ pullFilter?: unknown;
76
+ titleProperty?: string | undefined;
77
+ }[] | undefined;
25
78
  }>;
26
79
  sync: z.ZodObject<{
27
80
  direction: z.ZodDefault<z.ZodEnum<["push", "pull", "both"]>>;
@@ -29,18 +82,21 @@ declare const ConfigSchema: z.ZodObject<{
29
82
  autoSync: z.ZodDefault<z.ZodBoolean>;
30
83
  autoSyncInterval: z.ZodDefault<z.ZodNumber>;
31
84
  deleteSync: z.ZodDefault<z.ZodBoolean>;
85
+ syncFiles: z.ZodDefault<z.ZodBoolean>;
32
86
  }, "strip", z.ZodTypeAny, {
33
87
  direction: "push" | "pull" | "both";
34
88
  conflictStrategy: "local-first" | "remote-first" | "manual" | "duplicate";
35
89
  autoSync: boolean;
36
90
  autoSyncInterval: number;
37
91
  deleteSync: boolean;
92
+ syncFiles: boolean;
38
93
  }, {
39
94
  direction?: "push" | "pull" | "both" | undefined;
40
95
  conflictStrategy?: "local-first" | "remote-first" | "manual" | "duplicate" | undefined;
41
96
  autoSync?: boolean | undefined;
42
97
  autoSyncInterval?: number | undefined;
43
98
  deleteSync?: boolean | undefined;
99
+ syncFiles?: boolean | undefined;
44
100
  }>;
45
101
  paths: z.ZodObject<{
46
102
  include: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
@@ -93,8 +149,15 @@ declare const ConfigSchema: z.ZodObject<{
93
149
  token: string;
94
150
  rootPageId: string;
95
151
  parentMode: "page" | "database";
96
- workspaceId?: string | undefined;
152
+ databases: {
153
+ databaseId: string;
154
+ localFolder: string;
155
+ titleProperty: string;
156
+ propertyMapping?: Record<string, string> | undefined;
157
+ pullFilter?: unknown;
158
+ }[];
97
159
  databaseId?: string | undefined;
160
+ workspaceId?: string | undefined;
98
161
  };
99
162
  sync: {
100
163
  direction: "push" | "pull" | "both";
@@ -102,6 +165,7 @@ declare const ConfigSchema: z.ZodObject<{
102
165
  autoSync: boolean;
103
166
  autoSyncInterval: number;
104
167
  deleteSync: boolean;
168
+ syncFiles: boolean;
105
169
  };
106
170
  paths: {
107
171
  include: string[];
@@ -125,9 +189,16 @@ declare const ConfigSchema: z.ZodObject<{
125
189
  notion: {
126
190
  token: string;
127
191
  rootPageId: string;
192
+ databaseId?: string | undefined;
128
193
  workspaceId?: string | undefined;
129
194
  parentMode?: "page" | "database" | undefined;
130
- databaseId?: string | undefined;
195
+ databases?: {
196
+ databaseId: string;
197
+ localFolder: string;
198
+ propertyMapping?: Record<string, string> | undefined;
199
+ pullFilter?: unknown;
200
+ titleProperty?: string | undefined;
201
+ }[] | undefined;
131
202
  };
132
203
  sync: {
133
204
  direction?: "push" | "pull" | "both" | undefined;
@@ -135,6 +206,7 @@ declare const ConfigSchema: z.ZodObject<{
135
206
  autoSync?: boolean | undefined;
136
207
  autoSyncInterval?: number | undefined;
137
208
  deleteSync?: boolean | undefined;
209
+ syncFiles?: boolean | undefined;
138
210
  };
139
211
  paths: {
140
212
  include?: string[] | undefined;
@@ -340,12 +412,19 @@ declare class StateDB {
340
412
  updateStatus(id: string, status: SyncStatus): void;
341
413
  updateHash(id: string, hash: string, snapshot?: Buffer | null): void;
342
414
  setNotionLastEdited(id: string, lastEdited: string): void;
415
+ setNotionParentId(id: string, parentId: string): void;
343
416
  delete(id: string): void;
344
417
  resolveWikilink(text: string): WikilinkEntry | null;
345
418
  resolvePageId(pageId: string): WikilinkEntry | null;
346
419
  upsertWikilink(entry: WikilinkEntry): void;
347
420
  getMeta(key: string): string | null;
348
421
  setMeta(key: string, value: string): void;
422
+ isFileRegistered(localPath: string): boolean;
423
+ getFileRegistry(localPath: string): FileRegistryEntry | null;
424
+ getFilesByPageId(notionPageId: string): FileRegistryEntry[];
425
+ registerFile(entry: RegisterFileInput): void;
426
+ deleteFileRegistry(localPath: string): void;
427
+ private mapFileRegistryRow;
349
428
  storePreserveMarkers(path: string, markers: PreserveMarker[]): void;
350
429
  getPreserveMarkers(path: string): PreserveMarker[];
351
430
  transaction<T>(fn: () => T): T;
@@ -364,6 +443,23 @@ interface UpsertSyncRecord {
364
443
  readonly status: SyncRecord["status"];
365
444
  readonly baseSnapshot?: Buffer | null;
366
445
  }
446
+ interface FileRegistryEntry {
447
+ readonly id: string;
448
+ readonly localPath: string;
449
+ readonly notionPageId: string;
450
+ readonly fileUploadId: string;
451
+ readonly fileType: string;
452
+ readonly fileHash: string;
453
+ readonly fileSize: number;
454
+ }
455
+ interface RegisterFileInput {
456
+ readonly localPath: string;
457
+ readonly notionPageId: string;
458
+ readonly fileUploadId: string;
459
+ readonly fileType: string;
460
+ readonly fileHash: string;
461
+ readonly fileSize: number;
462
+ }
367
463
 
368
464
  interface NotionClientOptions {
369
465
  readonly token: string;
@@ -394,6 +490,12 @@ declare class NotionClient {
394
490
  updatePageProperties(pageId: string, properties: Record<string, unknown>): Promise<PageObjectResponse>;
395
491
  getPageMarkdown(pageId: string): Promise<PageMarkdownResponse>;
396
492
  replacePageMarkdown(pageId: string, markdown: string): Promise<PageMarkdownResponse>;
493
+ updatePageMarkdownPartial(pageId: string, patches: Array<{
494
+ oldStr: string;
495
+ newStr: string;
496
+ replaceAll?: boolean;
497
+ }>): Promise<PageMarkdownResponse>;
498
+ movePage(pageId: string, newParentId: string, newParentType: "page" | "database"): Promise<PageObjectResponse>;
397
499
  getDatabaseSchema(databaseId: string): Promise<Record<string, {
398
500
  id: string;
399
501
  type: string;
@@ -401,10 +503,13 @@ declare class NotionClient {
401
503
  queryDatabase(databaseId: string, options?: {
402
504
  startCursor?: string;
403
505
  pageSize?: number;
506
+ filter?: unknown;
404
507
  }): Promise<{
405
508
  results: PageObjectResponse[];
406
509
  nextCursor: string | null;
407
510
  }>;
511
+ queryAllDatabasePages(databaseId: string, filter?: unknown): Promise<PageObjectResponse[]>;
512
+ getDataSourceId(databaseId: string): Promise<string>;
408
513
  archivePage(pageId: string): Promise<void>;
409
514
  listChildren(blockId: string, options?: {
410
515
  startCursor?: string;
@@ -573,6 +678,11 @@ declare class ChangeDetector {
573
678
  private detectMoves;
574
679
  }
575
680
 
681
+ interface NonMdFileInfo {
682
+ readonly path: string;
683
+ readonly size: number;
684
+ readonly mtime: string;
685
+ }
576
686
  interface VaultFS {
577
687
  readFile(path: string): Promise<string>;
578
688
  readBinary(path: string): Promise<Buffer>;
@@ -583,6 +693,7 @@ interface VaultFS {
583
693
  exists(path: string): Promise<boolean>;
584
694
  ensureFolder(path: string): Promise<void>;
585
695
  listMarkdownFiles(): Promise<FileInfo[]>;
696
+ listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
586
697
  }
587
698
 
588
699
  declare class SyncOrchestrator {
@@ -594,6 +705,8 @@ declare class SyncOrchestrator {
594
705
  private readonly pipeline;
595
706
  private readonly blockConverter;
596
707
  private readonly imageHandler;
708
+ private readonly fileHandler;
709
+ private readonly databaseSyncer;
597
710
  private readonly propertyMapper;
598
711
  private dbSchemaLoaded;
599
712
  constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS);
@@ -607,6 +720,7 @@ declare class SyncOrchestrator {
607
720
  private pushCreate;
608
721
  private pushUpdate;
609
722
  private pushDelete;
723
+ private pushMove;
610
724
  private detectRemoteChanges;
611
725
  private pullCreate;
612
726
  private pullUpdate;
@@ -617,6 +731,7 @@ declare class SyncOrchestrator {
617
731
  private resolveParentPath;
618
732
  private pushCreatePage;
619
733
  private pushUpdatePage;
734
+ private computePatches;
620
735
  private fetchPageMarkdown;
621
736
  private extractParentId;
622
737
  private cleanupInterruptedSync;
@@ -642,8 +757,10 @@ declare class NodeVaultFS implements VaultFS {
642
757
  exists(path: string): Promise<boolean>;
643
758
  ensureFolder(path: string): Promise<void>;
644
759
  listMarkdownFiles(): Promise<FileInfo[]>;
760
+ listNonMarkdownFiles(): Promise<NonMdFileInfo[]>;
645
761
  private matchesPattern;
646
762
  private isExcluded;
763
+ private walkDirNonMd;
647
764
  private walkDir;
648
765
  }
649
766
 
@@ -675,6 +792,37 @@ declare class ImageHandler {
675
792
  private guessExtension;
676
793
  }
677
794
 
795
+ type NotionBlockType = "image" | "pdf" | "video" | "audio" | "file";
796
+ interface FileUploadResult {
797
+ readonly localPath: string;
798
+ readonly fileUploadId: string;
799
+ readonly blockType: NotionBlockType;
800
+ }
801
+ interface FileDownloadResult {
802
+ readonly url: string;
803
+ readonly localPath: string;
804
+ readonly hash: string;
805
+ readonly size: number;
806
+ }
807
+ declare class FileHandler {
808
+ private readonly vaultFs;
809
+ private readonly notionClient;
810
+ private readonly stateDb;
811
+ private readonly sema;
812
+ constructor(vaultFs: VaultFS, notionClient: NotionClient, stateDb: StateDB);
813
+ pushFilesForFolder(folderPageId: string, folderPath: string): Promise<FileUploadResult[]>;
814
+ pushAllFiles(): Promise<FileUploadResult[]>;
815
+ downloadFileBlock(url: string, filename: string, targetFolder: string): Promise<FileDownloadResult>;
816
+ downloadFileBlocks(blocks: Array<{
817
+ type: string;
818
+ url: string;
819
+ caption?: string;
820
+ }>, targetFolder: string): Promise<FileDownloadResult[]>;
821
+ private uploadFile;
822
+ private createFileBlock;
823
+ private extractFilename;
824
+ }
825
+
678
826
  declare class ConversionPipeline {
679
827
  private readonly preProcessors;
680
828
  private readonly postProcessors;
@@ -685,6 +833,27 @@ declare class ConversionPipeline {
685
833
  convertToMarkdown(content: string, context: ConversionContext, metadata?: ProcessorMetadata): string;
686
834
  }
687
835
 
836
+ interface DatabaseSyncResult {
837
+ created: number;
838
+ updated: number;
839
+ failed: FailedOperation[];
840
+ }
841
+ declare class DatabaseSyncer {
842
+ private readonly config;
843
+ private readonly stateDb;
844
+ private readonly notionClient;
845
+ private readonly vaultFs;
846
+ private readonly pipeline;
847
+ private readonly imageHandler;
848
+ private readonly propertyMapper;
849
+ constructor(config: Config, stateDb: StateDB, notionClient: NotionClient, vaultFs: VaultFS, pipeline: ConversionPipeline, imageHandler: ImageHandler);
850
+ pullAll(): Promise<DatabaseSyncResult>;
851
+ pushAll(): Promise<DatabaseSyncResult>;
852
+ private pullDatabase;
853
+ private pullDatabasePage;
854
+ private pushDatabase;
855
+ }
856
+
688
857
  declare class BlockConverter {
689
858
  private n2m;
690
859
  private client;
@@ -975,4 +1144,4 @@ interface PipelineOptions {
975
1144
  }
976
1145
  declare function createDefaultPipeline(options?: PipelineOptions): ConversionPipeline;
977
1146
 
978
- export { BlockConverter, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, DEFAULT_CONFIG, EmbedResolver, type FailedOperation, type FileInfo, type FileSystemEntry, type FileType, FileWatcher, FrontmatterExtractor, FrontmatterGenerator, HtmlAnnotationStripper, type ImageDownloadResult, ImageHandler, type ImageReference, InlineDBParser, type LocalChange, LocalImageRestorer, type Logger, type MappingResult, type MappingType, MathNormalizer, MentionToWikilink, type MergeConflictRegion, type MergeResult, NodeVaultFS, type NotionBlock, NotionBlockBuilder, NotionClient, type NotionClientOptions, type NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCreationPlan, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, 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 WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, generateId, getLogger, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, threeWayMerge };
1147
+ export { BlockConverter, CalloutRestorer, CalloutTransformer, ChangeDetector, ColorAnnotator, type Config, ConfigManager, ConfigSchema, type Conflict, ConflictResolver, type ConflictStrategy, type ConversionContext, type ConversionPath, ConversionPipeline, type ConversionResult, DEFAULT_CONFIG, type DatabaseSyncConfig, type DatabaseSyncResult, DatabaseSyncer, EmbedResolver, type FailedOperation, type FileDownloadResult, FileHandler, type FileInfo, type FileSystemEntry, type FileType, type FileUploadResult, FileWatcher, FrontmatterExtractor, FrontmatterGenerator, 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 NotionPageNode, type NotionRichText, type RichTextItem as NotionRichTextItem, type OperationType, type PageCreationPlan, type PathFilterConfig, type PreserveMarker, PreserveMarkerCollector, PreserveMarkerInjector, type Processor, type ProcessorInput, type ProcessorMetadata, type ProcessorOutput, type ProgressCallback, PropertiesTableInjector, PropertiesTableRestorer, PropertyMapper, 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 WatchSyncOptions, WatchSyncService, type WikilinkEntry, WikilinkResolver, computeBufferHash, computeHash, createDefaultPipeline, generateId, getLogger, normalizeNotionId, notionIdsEqual, sanitizeFileName, setLogger, threeWayMerge };