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