orgnote-api 0.17.1 → 0.17.2
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/api.d.ts +112 -0
- package/dist/api.js +1 -0
- package/dist/encryption/__tests__/encryption-keys.d.ts +3 -0
- package/{encryption/__tests__/encryption-keys.ts → dist/encryption/__tests__/encryption-keys.js} +0 -2
- package/dist/encryption/__tests__/encryption.spec.d.ts +1 -0
- package/dist/encryption/__tests__/encryption.spec.js +287 -0
- package/dist/encryption/__tests__/note-encryption.spec.d.ts +1 -0
- package/dist/encryption/__tests__/note-encryption.spec.js +364 -0
- package/dist/encryption/encryption.d.ts +27 -0
- package/dist/encryption/encryption.js +156 -0
- package/dist/encryption/index.js +2 -0
- package/dist/encryption/note-encryption.d.ts +12 -0
- package/dist/encryption/note-encryption.js +42 -0
- package/dist/files-api.d.ts +7 -0
- package/dist/files-api.js +22 -0
- package/dist/index.js +5 -0
- package/dist/models/command.d.ts +29 -0
- package/dist/models/command.js +1 -0
- package/dist/models/completion.d.ts +22 -0
- package/dist/models/completion.js +1 -0
- package/dist/models/default-commands.d.ts +30 -0
- package/dist/models/default-commands.js +41 -0
- package/dist/models/editor.d.ts +23 -0
- package/dist/models/editor.js +1 -0
- package/dist/models/encryption.d.ts +31 -0
- package/dist/models/encryption.js +1 -0
- package/dist/models/extension.d.ts +34 -0
- package/dist/models/extension.js +1 -0
- package/dist/models/file-system.d.ts +23 -0
- package/dist/models/file-system.js +1 -0
- package/dist/models/index.js +13 -0
- package/dist/models/modal.d.ts +10 -0
- package/dist/models/modal.js +1 -0
- package/dist/models/note.d.ts +23 -0
- package/dist/models/note.js +1 -0
- package/dist/models/sync.d.ts +34 -0
- package/dist/models/sync.js +1 -0
- package/dist/models/theme-variables.d.ts +192 -0
- package/dist/models/theme-variables.js +194 -0
- package/{models/vue-component.ts → dist/models/vue-component.d.ts} +1 -1
- package/dist/models/vue-component.js +1 -0
- package/dist/models/widget-type.d.ts +5 -0
- package/dist/models/widget-type.js +6 -0
- package/dist/models/widget.d.ts +51 -0
- package/dist/models/widget.js +1 -0
- package/dist/remote-api/api.d.ts +1525 -0
- package/{remote-api/api.ts → dist/remote-api/api.js} +246 -1149
- package/dist/remote-api/base.d.ts +66 -0
- package/{remote-api/base.ts → dist/remote-api/base.js} +13 -36
- package/dist/remote-api/common.d.ts +65 -0
- package/{remote-api/common.ts → dist/remote-api/common.js} +31 -48
- package/{remote-api/configuration.ts → dist/remote-api/configuration.d.ts} +3 -22
- package/dist/remote-api/configuration.js +95 -0
- package/dist/remote-api/index.d.ts +13 -0
- package/{remote-api/index.ts → dist/remote-api/index.js} +0 -3
- package/dist/tools/__tests__/find-files-diff.spec.d.ts +1 -0
- package/dist/tools/__tests__/find-files-diff.spec.js +110 -0
- package/dist/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
- package/dist/tools/__tests__/find-note-files-diff.spec.js +168 -0
- package/dist/tools/__tests__/get-file-name.spec.d.ts +1 -0
- package/{tools/__tests__/get-file-name.spec.ts → dist/tools/__tests__/get-file-name.spec.js} +4 -8
- package/dist/tools/__tests__/get-string-path.spec.d.ts +1 -0
- package/dist/tools/__tests__/get-string-path.spec.js +27 -0
- package/dist/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
- package/{tools/__tests__/is-gpg-encrypted.spec.ts → dist/tools/__tests__/is-gpg-encrypted.spec.js} +4 -8
- package/dist/tools/__tests__/is-org-file.spec.d.ts +1 -0
- package/dist/tools/__tests__/is-org-file.spec.js +54 -0
- package/dist/tools/__tests__/join.spec.d.ts +1 -0
- package/dist/tools/__tests__/join.spec.js +14 -0
- package/dist/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
- package/dist/tools/__tests__/read-org-files-recursively.spec.js +51 -0
- package/dist/tools/extend-notes-files-diff.d.ts +3 -0
- package/dist/tools/extend-notes-files-diff.js +21 -0
- package/dist/tools/find-notes-files-diff.d.ts +5 -0
- package/dist/tools/find-notes-files-diff.js +108 -0
- package/dist/tools/get-file-name.d.ts +2 -0
- package/dist/tools/get-file-name.js +6 -0
- package/dist/tools/get-string-path.d.ts +1 -0
- package/dist/tools/get-string-path.js +6 -0
- package/dist/tools/index.js +6 -0
- package/dist/tools/is-gpg-encrypted.d.ts +1 -0
- package/dist/tools/is-gpg-encrypted.js +6 -0
- package/dist/tools/is-org-file.d.ts +2 -0
- package/dist/tools/is-org-file.js +4 -0
- package/dist/tools/join.d.ts +1 -0
- package/dist/tools/join.js +3 -0
- package/dist/tools/mock-server.d.ts +1 -0
- package/dist/tools/mock-server.js +12 -0
- package/package.json +6 -14
- package/api.ts +0 -123
- package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -215
- package/encryption/__tests__/encryption.spec.ts +0 -355
- package/encryption/__tests__/note-encryption.spec.ts +0 -424
- package/encryption/encryption.ts +0 -265
- package/encryption/note-encryption.ts +0 -78
- package/files-api.ts +0 -25
- package/models/command.ts +0 -45
- package/models/completion.ts +0 -30
- package/models/default-commands.ts +0 -44
- package/models/editor.ts +0 -27
- package/models/encryption.ts +0 -54
- package/models/extension.ts +0 -45
- package/models/file-system.ts +0 -30
- package/models/modal.ts +0 -12
- package/models/note.ts +0 -26
- package/models/sync.ts +0 -43
- package/models/theme-variables.ts +0 -194
- package/models/widget-type.ts +0 -5
- package/models/widget.ts +0 -59
- package/remote-api/.gitignore +0 -4
- package/remote-api/.npmignore +0 -1
- package/remote-api/.openapi-generator/FILES +0 -8
- package/remote-api/.openapi-generator/VERSION +0 -1
- package/remote-api/.openapi-generator-ignore +0 -23
- package/remote-api/git_push.sh +0 -57
- package/tools/__tests__/__snapshots__/join.spec.ts.snap +0 -9
- package/tools/__tests__/find-files-diff.spec.ts +0 -177
- package/tools/__tests__/find-note-files-diff.spec.ts +0 -207
- package/tools/__tests__/get-string-path.spec.ts +0 -32
- package/tools/__tests__/is-org-file.spec.ts +0 -62
- package/tools/__tests__/join.spec.ts +0 -16
- package/tools/__tests__/read-org-files-recursively.spec.ts +0 -61
- package/tools/extend-notes-files-diff.ts +0 -35
- package/tools/find-notes-files-diff.ts +0 -185
- package/tools/get-file-name.ts +0 -7
- package/tools/get-string-path.ts +0 -6
- package/tools/is-gpg-encrypted.ts +0 -6
- package/tools/is-org-file.ts +0 -7
- package/tools/join.ts +0 -3
- package/tools/mock-server.ts +0 -16
- /package/{encryption/index.ts → dist/encryption/index.d.ts} +0 -0
- /package/{index.ts → dist/index.d.ts} +0 -0
- /package/{models/index.ts → dist/models/index.d.ts} +0 -0
- /package/{tools/index.ts → dist/tools/index.d.ts} +0 -0
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi } from 'vitest';
|
|
2
|
-
import { readOrgFilesRecursively } from '../find-notes-files-diff';
|
|
3
|
-
import { FileScanParams } from '../../models';
|
|
4
|
-
|
|
5
|
-
// NOTE: AI generated
|
|
6
|
-
const mockReadDir = vi.fn();
|
|
7
|
-
const mockFileInfo = vi.fn();
|
|
8
|
-
|
|
9
|
-
describe('readOrgFilesRecursively', () => {
|
|
10
|
-
it('should read .org files recursively from a directory', async () => {
|
|
11
|
-
const mockFileSystem: FileScanParams = {
|
|
12
|
-
fileInfo: mockFileInfo,
|
|
13
|
-
readDir: mockReadDir,
|
|
14
|
-
dirPath: '/root',
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Set up fake file system structure
|
|
18
|
-
mockReadDir.mockImplementation(async (path) => {
|
|
19
|
-
switch (path) {
|
|
20
|
-
case '/root':
|
|
21
|
-
return [
|
|
22
|
-
{ name: 'file1.org', type: 'file', size: 100, mtime: Date.now() },
|
|
23
|
-
{ name: 'subdir', type: 'directory', size: 0, mtime: Date.now() },
|
|
24
|
-
{ name: 'file2.txt', type: 'file', size: 200, mtime: Date.now() },
|
|
25
|
-
];
|
|
26
|
-
case '/root/subdir':
|
|
27
|
-
return [
|
|
28
|
-
{ name: 'file3.org', type: 'file', size: 100, mtime: Date.now() },
|
|
29
|
-
{ name: 'file4.md', type: 'file', size: 150, mtime: Date.now() },
|
|
30
|
-
];
|
|
31
|
-
default:
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// Execute the function
|
|
37
|
-
const orgFiles = await readOrgFilesRecursively(mockFileSystem);
|
|
38
|
-
|
|
39
|
-
// Check results
|
|
40
|
-
expect(orgFiles).toEqual(['/root/file1.org', '/root/subdir/file3.org']);
|
|
41
|
-
expect(mockReadDir).toHaveBeenCalledTimes(2);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('should return an empty array if no .org files are found', async () => {
|
|
45
|
-
const mockFileSystem: FileScanParams = {
|
|
46
|
-
fileInfo: mockFileInfo,
|
|
47
|
-
readDir: mockReadDir,
|
|
48
|
-
dirPath: '/emptyDir',
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// Set up fake file system structure with no .org files
|
|
52
|
-
mockReadDir.mockResolvedValue([]);
|
|
53
|
-
|
|
54
|
-
// Execute the function
|
|
55
|
-
const orgFiles = await readOrgFilesRecursively(mockFileSystem);
|
|
56
|
-
|
|
57
|
-
// Check results
|
|
58
|
-
expect(orgFiles).toEqual([]);
|
|
59
|
-
expect(mockReadDir).toHaveBeenCalledWith('/emptyDir');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { HandlersCreatingNote, HandlersSyncNotesRequest } from 'src/remote-api';
|
|
2
|
-
import { NoteChange, NoteChanges, FileSystem } from '../models';
|
|
3
|
-
import { isOrgGpgFile } from './is-org-file';
|
|
4
|
-
|
|
5
|
-
export async function extendNotesFilesDiff(
|
|
6
|
-
changes: NoteChanges,
|
|
7
|
-
readFile: FileSystem['readFile']
|
|
8
|
-
): Promise<HandlersSyncNotesRequest> {
|
|
9
|
-
const upsertedNotesFromLastSync: NoteChange[] = [
|
|
10
|
-
...changes.updated,
|
|
11
|
-
...changes.created,
|
|
12
|
-
];
|
|
13
|
-
|
|
14
|
-
const notesFromLastSync: HandlersCreatingNote[] = [];
|
|
15
|
-
|
|
16
|
-
for (const nc of upsertedNotesFromLastSync) {
|
|
17
|
-
const encrypted = isOrgGpgFile(nc.filePath);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const noteIdsFromLastSync = new Set(notesFromLastSync.map((n) => n.id));
|
|
21
|
-
|
|
22
|
-
const deletedNotesIdsWithoutRename = changes.deleted.reduce<string[]>(
|
|
23
|
-
(acc, nc) => {
|
|
24
|
-
if (!noteIdsFromLastSync.has(nc.id)) {
|
|
25
|
-
acc.push(nc.id);
|
|
26
|
-
}
|
|
27
|
-
return acc;
|
|
28
|
-
},
|
|
29
|
-
[]
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
return {
|
|
33
|
-
deletedNotesIds: deletedNotesIdsWithoutRename,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SyncParams,
|
|
3
|
-
Changes,
|
|
4
|
-
StoredNoteInfo,
|
|
5
|
-
NoteChanges,
|
|
6
|
-
FileScanParams,
|
|
7
|
-
FileSystem,
|
|
8
|
-
NoteChange,
|
|
9
|
-
} from 'src/models';
|
|
10
|
-
import { getStringPath } from './get-string-path';
|
|
11
|
-
import { isOrgFile } from './is-org-file';
|
|
12
|
-
import { join } from './join';
|
|
13
|
-
|
|
14
|
-
export async function findNoteFilesDiff({
|
|
15
|
-
fileInfo,
|
|
16
|
-
readDir,
|
|
17
|
-
lastSync,
|
|
18
|
-
storedNotesInfo,
|
|
19
|
-
dirPath,
|
|
20
|
-
}: SyncParams): Promise<NoteChanges> {
|
|
21
|
-
const orgFilePaths = await readOrgFilesRecursively({
|
|
22
|
-
fileInfo,
|
|
23
|
-
readDir,
|
|
24
|
-
dirPath,
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
const filesFromLastSync = await getOrgFilesFromLastSync(
|
|
28
|
-
orgFilePaths,
|
|
29
|
-
fileInfo,
|
|
30
|
-
lastSync
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
const deleted = findDeletedNotes(orgFilePaths, storedNotesInfo);
|
|
34
|
-
|
|
35
|
-
const [created, updated] = await findUpdatedCreatedNotes(
|
|
36
|
-
fileInfo,
|
|
37
|
-
filesFromLastSync,
|
|
38
|
-
storedNotesInfo
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
deleted,
|
|
43
|
-
created,
|
|
44
|
-
updated,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function getOrgFilesFromLastSync(
|
|
49
|
-
filePaths: string[],
|
|
50
|
-
fileInfo: FileSystem['fileInfo'],
|
|
51
|
-
lastSync?: Date
|
|
52
|
-
): Promise<string[]> {
|
|
53
|
-
if (!lastSync) {
|
|
54
|
-
return filePaths;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return Promise.all(
|
|
58
|
-
filePaths.filter(async (filePath) => {
|
|
59
|
-
const stats = await fileInfo(filePath);
|
|
60
|
-
return (
|
|
61
|
-
new Date(stats.mtime) > lastSync || new Date(stats.ctime) > lastSync
|
|
62
|
-
);
|
|
63
|
-
})
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function findDeletedNotes(
|
|
68
|
-
filePaths: string[],
|
|
69
|
-
storedNotesInfo: StoredNoteInfo[]
|
|
70
|
-
): NoteChange[] {
|
|
71
|
-
const uniqueFilePaths = new Set(filePaths);
|
|
72
|
-
|
|
73
|
-
return storedNotesInfo.reduce((acc, storedNote) => {
|
|
74
|
-
const storedNotePath = getStringPath(storedNote.filePath);
|
|
75
|
-
if (uniqueFilePaths.has(storedNotePath)) {
|
|
76
|
-
return acc;
|
|
77
|
-
}
|
|
78
|
-
acc.push({
|
|
79
|
-
filePath: storedNotePath,
|
|
80
|
-
id: storedNote.id,
|
|
81
|
-
});
|
|
82
|
-
return acc;
|
|
83
|
-
}, []);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function findUpdatedCreatedNotes(
|
|
87
|
-
fileInfo: FileSystem['fileInfo'],
|
|
88
|
-
orgFilePaths: string[],
|
|
89
|
-
storedNotesInfo: StoredNoteInfo[]
|
|
90
|
-
): Promise<[NoteChange[], NoteChange[]]> {
|
|
91
|
-
const created: NoteChange[] = [];
|
|
92
|
-
const updated: NoteChange[] = [];
|
|
93
|
-
|
|
94
|
-
const storedNotesInfoMap = getStoredNotesInfoMap(storedNotesInfo);
|
|
95
|
-
|
|
96
|
-
for (const f of orgFilePaths) {
|
|
97
|
-
const found = storedNotesInfoMap[f];
|
|
98
|
-
if (!found) {
|
|
99
|
-
created.push({ filePath: f });
|
|
100
|
-
continue;
|
|
101
|
-
}
|
|
102
|
-
const fileUpdatedTime = new Date((await fileInfo(f))?.mtime);
|
|
103
|
-
if (found.updatedAt < fileUpdatedTime) {
|
|
104
|
-
updated.push({ filePath: f });
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return [created, updated];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function getStoredNotesInfoMap(storedNotesInfo: StoredNoteInfo[]): {
|
|
112
|
-
[key: string]: StoredNoteInfo;
|
|
113
|
-
} {
|
|
114
|
-
return storedNotesInfo.reduce((acc, n) => {
|
|
115
|
-
acc[getStringPath(n.filePath)] = n;
|
|
116
|
-
return acc;
|
|
117
|
-
}, {});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export async function readOrgFilesRecursively({
|
|
121
|
-
fileInfo,
|
|
122
|
-
readDir,
|
|
123
|
-
dirPath,
|
|
124
|
-
}: FileScanParams): Promise<string[]> {
|
|
125
|
-
const files = await readDir(dirPath);
|
|
126
|
-
|
|
127
|
-
const collectedPaths: string[] = [];
|
|
128
|
-
const getFullPath = (p: string) => join(dirPath, p);
|
|
129
|
-
|
|
130
|
-
for (const f of files) {
|
|
131
|
-
if (f.type === 'directory') {
|
|
132
|
-
const subDirFiles = await readOrgFilesRecursively({
|
|
133
|
-
fileInfo,
|
|
134
|
-
readDir,
|
|
135
|
-
dirPath: getFullPath(f.name),
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
collectedPaths.push(...subDirFiles);
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (!isOrgFile(f.name)) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
collectedPaths.push(getFullPath(f.name));
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return collectedPaths;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export function findFilesDiff(
|
|
153
|
-
filePaths: string[],
|
|
154
|
-
storedNotesInfo: StoredNoteInfo[],
|
|
155
|
-
updatedTimeGetter: (filePath: string) => Date
|
|
156
|
-
): Changes {
|
|
157
|
-
const existingFilePaths = new Set<string>(filePaths);
|
|
158
|
-
|
|
159
|
-
const storedNotesPathSet = new Set<string>(
|
|
160
|
-
storedNotesInfo.map((n) => getStringPath(n.filePath))
|
|
161
|
-
);
|
|
162
|
-
const changedFiles: Changes = { deleted: [], created: [], updated: [] };
|
|
163
|
-
|
|
164
|
-
storedNotesInfo.forEach((storedNote) => {
|
|
165
|
-
const fullPath = getStringPath(storedNote.filePath);
|
|
166
|
-
if (!existingFilePaths.has(fullPath)) {
|
|
167
|
-
changedFiles.deleted.push(fullPath);
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const updatedTime = updatedTimeGetter(fullPath);
|
|
172
|
-
if (updatedTime > new Date(storedNote.updatedAt)) {
|
|
173
|
-
changedFiles.updated.push(fullPath);
|
|
174
|
-
}
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
filePaths.forEach((filePath) => {
|
|
178
|
-
if (!storedNotesPathSet.has(filePath)) {
|
|
179
|
-
changedFiles.created.push(filePath);
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
return changedFiles;
|
|
185
|
-
}
|
package/tools/get-file-name.ts
DELETED
package/tools/get-string-path.ts
DELETED
package/tools/is-org-file.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const orgFileExtenstionRegex = /\.org(\.gpg)?$/;
|
|
2
|
-
export const isOrgFile = (fileName: string): boolean =>
|
|
3
|
-
orgFileExtenstionRegex.test(fileName);
|
|
4
|
-
|
|
5
|
-
const orgGpgFileExtenstionRegex = /\.org\.gpg$/;
|
|
6
|
-
export const isOrgGpgFile = (fileName: string): boolean =>
|
|
7
|
-
orgGpgFileExtenstionRegex.test(fileName);
|
package/tools/join.ts
DELETED
package/tools/mock-server.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
export const mockServer = <T extends (...params: any[]) => any>(
|
|
4
|
-
fn?: T,
|
|
5
|
-
defaultValue?: ReturnType<T>
|
|
6
|
-
) => {
|
|
7
|
-
if (!fn) {
|
|
8
|
-
return (() => {}) as () => ReturnType<T>;
|
|
9
|
-
}
|
|
10
|
-
return (...params: Parameters<T>): ReturnType<T> => {
|
|
11
|
-
if (process.env.CLIENT) {
|
|
12
|
-
return fn(...params);
|
|
13
|
-
}
|
|
14
|
-
return defaultValue;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|