orgnote-api 0.17.1 → 0.17.3

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.
Files changed (137) hide show
  1. package/README.md +158 -0
  2. package/api.d.ts +112 -0
  3. package/api.js +1 -0
  4. package/encryption/__tests__/encryption-keys.d.ts +3 -0
  5. package/encryption/__tests__/{encryption-keys.ts → encryption-keys.js} +0 -2
  6. package/encryption/__tests__/encryption.spec.d.ts +1 -0
  7. package/encryption/__tests__/encryption.spec.js +287 -0
  8. package/encryption/__tests__/note-encryption.spec.d.ts +1 -0
  9. package/encryption/__tests__/note-encryption.spec.js +364 -0
  10. package/encryption/encryption.d.ts +27 -0
  11. package/encryption/encryption.js +156 -0
  12. package/encryption/index.js +2 -0
  13. package/encryption/note-encryption.d.ts +12 -0
  14. package/encryption/note-encryption.js +42 -0
  15. package/files-api.d.ts +7 -0
  16. package/files-api.js +22 -0
  17. package/index.js +5 -0
  18. package/models/command.d.ts +29 -0
  19. package/models/command.js +1 -0
  20. package/models/completion.d.ts +22 -0
  21. package/models/completion.js +1 -0
  22. package/models/default-commands.d.ts +30 -0
  23. package/models/default-commands.js +41 -0
  24. package/models/editor.d.ts +23 -0
  25. package/models/editor.js +1 -0
  26. package/models/encryption.d.ts +31 -0
  27. package/models/encryption.js +1 -0
  28. package/models/extension.d.ts +34 -0
  29. package/models/extension.js +1 -0
  30. package/models/file-system.d.ts +23 -0
  31. package/models/file-system.js +1 -0
  32. package/models/index.js +13 -0
  33. package/models/modal.d.ts +10 -0
  34. package/models/modal.js +1 -0
  35. package/models/note.d.ts +23 -0
  36. package/models/note.js +1 -0
  37. package/models/sync.d.ts +34 -0
  38. package/models/sync.js +1 -0
  39. package/models/theme-variables.d.ts +192 -0
  40. package/models/theme-variables.js +194 -0
  41. package/models/{vue-component.ts → vue-component.d.ts} +1 -1
  42. package/models/vue-component.js +1 -0
  43. package/models/widget-type.d.ts +5 -0
  44. package/models/widget-type.js +6 -0
  45. package/models/widget.d.ts +51 -0
  46. package/models/widget.js +1 -0
  47. package/package.json +8 -17
  48. package/remote-api/api.d.ts +1525 -0
  49. package/remote-api/{api.ts → api.js} +246 -1149
  50. package/remote-api/base.d.ts +66 -0
  51. package/remote-api/{base.ts → base.js} +13 -36
  52. package/remote-api/common.d.ts +65 -0
  53. package/remote-api/{common.ts → common.js} +31 -48
  54. package/remote-api/{configuration.ts → configuration.d.ts} +3 -22
  55. package/remote-api/configuration.js +95 -0
  56. package/remote-api/index.d.ts +13 -0
  57. package/remote-api/{index.ts → index.js} +0 -3
  58. package/tools/__tests__/find-files-diff.spec.d.ts +1 -0
  59. package/tools/__tests__/find-files-diff.spec.js +110 -0
  60. package/tools/__tests__/find-note-files-diff.spec.d.ts +1 -0
  61. package/tools/__tests__/find-note-files-diff.spec.js +168 -0
  62. package/tools/__tests__/get-file-name.spec.d.ts +1 -0
  63. package/tools/__tests__/{get-file-name.spec.ts → get-file-name.spec.js} +4 -8
  64. package/tools/__tests__/get-string-path.spec.d.ts +1 -0
  65. package/tools/__tests__/get-string-path.spec.js +27 -0
  66. package/tools/__tests__/is-gpg-encrypted.spec.d.ts +1 -0
  67. package/tools/__tests__/{is-gpg-encrypted.spec.ts → is-gpg-encrypted.spec.js} +4 -8
  68. package/tools/__tests__/is-org-file.spec.d.ts +1 -0
  69. package/tools/__tests__/is-org-file.spec.js +54 -0
  70. package/tools/__tests__/join.spec.d.ts +1 -0
  71. package/tools/__tests__/join.spec.js +14 -0
  72. package/tools/__tests__/read-org-files-recursively.spec.d.ts +1 -0
  73. package/tools/__tests__/read-org-files-recursively.spec.js +51 -0
  74. package/tools/extend-notes-files-diff.d.ts +3 -0
  75. package/tools/extend-notes-files-diff.js +21 -0
  76. package/tools/find-notes-files-diff.d.ts +5 -0
  77. package/tools/find-notes-files-diff.js +108 -0
  78. package/tools/get-file-name.d.ts +2 -0
  79. package/tools/get-file-name.js +6 -0
  80. package/tools/get-string-path.d.ts +1 -0
  81. package/tools/get-string-path.js +6 -0
  82. package/tools/index.js +6 -0
  83. package/tools/is-gpg-encrypted.d.ts +1 -0
  84. package/tools/is-gpg-encrypted.js +6 -0
  85. package/tools/is-org-file.d.ts +2 -0
  86. package/tools/is-org-file.js +4 -0
  87. package/tools/join.d.ts +1 -0
  88. package/tools/join.js +3 -0
  89. package/tools/mock-server.d.ts +1 -0
  90. package/tools/mock-server.js +12 -0
  91. package/LICENSE +0 -674
  92. package/README.org +0 -97
  93. package/api.ts +0 -123
  94. package/encryption/__tests__/__snapshots__/note-encryption.spec.ts.snap +0 -215
  95. package/encryption/__tests__/encryption.spec.ts +0 -355
  96. package/encryption/__tests__/note-encryption.spec.ts +0 -424
  97. package/encryption/encryption.ts +0 -265
  98. package/encryption/note-encryption.ts +0 -78
  99. package/files-api.ts +0 -25
  100. package/models/command.ts +0 -45
  101. package/models/completion.ts +0 -30
  102. package/models/default-commands.ts +0 -44
  103. package/models/editor.ts +0 -27
  104. package/models/encryption.ts +0 -54
  105. package/models/extension.ts +0 -45
  106. package/models/file-system.ts +0 -30
  107. package/models/modal.ts +0 -12
  108. package/models/note.ts +0 -26
  109. package/models/sync.ts +0 -43
  110. package/models/theme-variables.ts +0 -194
  111. package/models/widget-type.ts +0 -5
  112. package/models/widget.ts +0 -59
  113. package/remote-api/.gitignore +0 -4
  114. package/remote-api/.npmignore +0 -1
  115. package/remote-api/.openapi-generator/FILES +0 -8
  116. package/remote-api/.openapi-generator/VERSION +0 -1
  117. package/remote-api/.openapi-generator-ignore +0 -23
  118. package/remote-api/git_push.sh +0 -57
  119. package/tools/__tests__/__snapshots__/join.spec.ts.snap +0 -9
  120. package/tools/__tests__/find-files-diff.spec.ts +0 -177
  121. package/tools/__tests__/find-note-files-diff.spec.ts +0 -207
  122. package/tools/__tests__/get-string-path.spec.ts +0 -32
  123. package/tools/__tests__/is-org-file.spec.ts +0 -62
  124. package/tools/__tests__/join.spec.ts +0 -16
  125. package/tools/__tests__/read-org-files-recursively.spec.ts +0 -61
  126. package/tools/extend-notes-files-diff.ts +0 -35
  127. package/tools/find-notes-files-diff.ts +0 -185
  128. package/tools/get-file-name.ts +0 -7
  129. package/tools/get-string-path.ts +0 -6
  130. package/tools/is-gpg-encrypted.ts +0 -6
  131. package/tools/is-org-file.ts +0 -7
  132. package/tools/join.ts +0 -3
  133. package/tools/mock-server.ts +0 -16
  134. /package/encryption/{index.ts → index.d.ts} +0 -0
  135. /package/{index.ts → index.d.ts} +0 -0
  136. /package/models/{index.ts → index.d.ts} +0 -0
  137. /package/tools/{index.ts → 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
- }
@@ -1,7 +0,0 @@
1
- export const getFileName = (path: string): string => {
2
- return path.split('/').pop();
3
- };
4
-
5
- export const getFileNameWithoutExtension = (path: string): string => {
6
- return getFileName(path).split('.').shift();
7
- };
@@ -1,6 +0,0 @@
1
- export function getStringPath(path: string | string[]): string {
2
- if (Array.isArray(path)) {
3
- return `${path.join('/')}`;
4
- }
5
- return path;
6
- }
@@ -1,6 +0,0 @@
1
- export function isGpgEncrypted(text: string | Uint8Array): boolean {
2
- if (text instanceof Uint8Array) {
3
- return true;
4
- }
5
- return text.startsWith('-----BEGIN PGP MESSAGE-----');
6
- }
@@ -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
@@ -1,3 +0,0 @@
1
- export function join(...path: string[]): string {
2
- return path.join('/').replace(/\/+/g, '/').replace(/\/+$/, '');
3
- }
@@ -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