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
package/models/widget.ts DELETED
@@ -1,59 +0,0 @@
1
- import type { ChangeSpec } from '@codemirror/state';
2
- import { EditorView } from '@codemirror/view';
3
- import type { NodeType, OrgNode } from 'org-mode-ast';
4
-
5
- export type EmbeddedWidget = {
6
- destroy: () => void;
7
- refresh?: (...args: unknown[]) => void;
8
- };
9
-
10
- export interface WidgetBuilderParams {
11
- wrap: HTMLElement;
12
- orgNode: OrgNode;
13
- rootNodeSrc: () => OrgNode;
14
- onUpdateFn?: (newVal: string) => void;
15
- editorView: EditorView;
16
- readonly?: boolean;
17
- }
18
-
19
- export type WidgetBuilder = (params: WidgetBuilderParams) => EmbeddedWidget;
20
-
21
- export interface CommonEmbeddedWidget {
22
- satisfied?: (orgNode: OrgNode) => boolean;
23
- widgetBuilder?: WidgetBuilder;
24
- viewUpdater?: (orgNode: OrgNode, newVal: string) => ViewUpdateSchema;
25
- ignoreEvent?: boolean;
26
- showRangeOffset?: [number, number];
27
- }
28
-
29
- export interface MultilineEmbeddedWidget extends CommonEmbeddedWidget {
30
- widgetBuilder: WidgetBuilder;
31
- suppressEdit?: boolean;
32
- }
33
-
34
- export type MultilineEmbeddedWidgets = {
35
- [key in NodeType]?: MultilineEmbeddedWidget;
36
- };
37
-
38
- export type ViewUpdateSchema = ChangeSpec;
39
-
40
- export interface InlineEmbeddedWidget extends CommonEmbeddedWidget {
41
- classBuilder?: (orgNode: OrgNode) => string;
42
- decorationType: 'mark' | 'widget' | 'replace' | 'line';
43
- ignoreEditing?: boolean;
44
- side?: number;
45
- wrapComponent?: string;
46
- inclusive?: boolean;
47
- }
48
-
49
- export type InlineEmbeddedWidgets = {
50
- [key in NodeType]?: InlineEmbeddedWidget;
51
- };
52
-
53
- export type EmbeddedWidgetBuilder = (
54
- wrap: HTMLElement,
55
- dynamicProps?: { [key: string]: unknown }
56
- ) => EmbeddedWidget;
57
-
58
- export type OrgLineClass = { class: string | ((orgNode: OrgNode) => string) };
59
- export type OrgLineClasses = { [key in NodeType]?: OrgLineClass };
@@ -1,4 +0,0 @@
1
- wwwroot/*.js
2
- node_modules
3
- typings
4
- dist
@@ -1 +0,0 @@
1
- # empty npmignore to ensure all required files (e.g., in the dist folder) are published by npm
@@ -1,8 +0,0 @@
1
- .gitignore
2
- .npmignore
3
- api.ts
4
- base.ts
5
- common.ts
6
- configuration.ts
7
- git_push.sh
8
- index.ts
@@ -1 +0,0 @@
1
- 7.7.0
@@ -1,23 +0,0 @@
1
- # OpenAPI Generator Ignore
2
- # Generated by openapi-generator https://github.com/openapitools/openapi-generator
3
-
4
- # Use this file to prevent files from being overwritten by the generator.
5
- # The patterns follow closely to .gitignore or .dockerignore.
6
-
7
- # As an example, the C# client generator defines ApiClient.cs.
8
- # You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
9
- #ApiClient.cs
10
-
11
- # You can match any string of characters against a directory, file or extension with a single asterisk (*):
12
- #foo/*/qux
13
- # The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
14
-
15
- # You can recursively match patterns against a directory, file or extension with a double asterisk (**):
16
- #foo/**/qux
17
- # This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
18
-
19
- # You can also negate patterns with an exclamation (!).
20
- # For example, you can ignore all files in a docs folder with the file extension .md:
21
- #docs/*.md
22
- # Then explicitly reverse the ignore rule for a single file:
23
- #!docs/README.md
@@ -1,57 +0,0 @@
1
- #!/bin/sh
2
- # ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
3
- #
4
- # Usage example: /bin/sh ./git_push.sh wing328 openapi-petstore-perl "minor update" "gitlab.com"
5
-
6
- git_user_id=$1
7
- git_repo_id=$2
8
- release_note=$3
9
- git_host=$4
10
-
11
- if [ "$git_host" = "" ]; then
12
- git_host="github.com"
13
- echo "[INFO] No command line input provided. Set \$git_host to $git_host"
14
- fi
15
-
16
- if [ "$git_user_id" = "" ]; then
17
- git_user_id="GIT_USER_ID"
18
- echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id"
19
- fi
20
-
21
- if [ "$git_repo_id" = "" ]; then
22
- git_repo_id="GIT_REPO_ID"
23
- echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id"
24
- fi
25
-
26
- if [ "$release_note" = "" ]; then
27
- release_note="Minor update"
28
- echo "[INFO] No command line input provided. Set \$release_note to $release_note"
29
- fi
30
-
31
- # Initialize the local directory as a Git repository
32
- git init
33
-
34
- # Adds the files in the local repository and stages them for commit.
35
- git add .
36
-
37
- # Commits the tracked changes and prepares them to be pushed to a remote repository.
38
- git commit -m "$release_note"
39
-
40
- # Sets the new remote
41
- git_remote=$(git remote)
42
- if [ "$git_remote" = "" ]; then # git remote not defined
43
-
44
- if [ "$GIT_TOKEN" = "" ]; then
45
- echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment."
46
- git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git
47
- else
48
- git remote add origin https://${git_user_id}:"${GIT_TOKEN}"@${git_host}/${git_user_id}/${git_repo_id}.git
49
- fi
50
-
51
- fi
52
-
53
- git pull origin master
54
-
55
- # Pushes (Forces) the changes in the local repository up to the remote repository
56
- echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git"
57
- git push origin master 2>&1 | grep -v 'To https'
@@ -1,9 +0,0 @@
1
- // Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
2
-
3
- exports[`Should join file paths 1`] = `"dir1/subdir2/file"`;
4
-
5
- exports[`Should join file paths 2`] = `"dir2/file"`;
6
-
7
- exports[`Should join file paths 3`] = `"/dri3/subdir2/file"`;
8
-
9
- exports[`Should join file paths 4`] = `"file"`;
@@ -1,177 +0,0 @@
1
- import { afterEach, beforeEach, expect, test } from 'vitest';
2
- import { mkdirSync, rmdirSync, statSync, utimesSync, writeFileSync } from 'fs';
3
- import { join } from 'path';
4
- import { findFilesDiff } from '../find-notes-files-diff';
5
- import { StoredNoteInfo } from '../../models';
6
-
7
- const testFilesFolder = 'src/tools/__tests__/miscellaneous2/';
8
-
9
- function initFiles(): void {
10
- mkdirSync(testFilesFolder);
11
- mkdirSync(testFilesFolder + '/nested-folder');
12
- }
13
-
14
- function cleanFiles(): void {
15
- try {
16
- rmdirSync(testFilesFolder, { recursive: true });
17
- } catch (e) {}
18
- }
19
-
20
- function createTestFile(
21
- content: string,
22
- fileName: string,
23
- updated: Date
24
- ): void {
25
- const filePath = join(testFilesFolder, fileName);
26
-
27
- writeFileSync(filePath, content);
28
-
29
- const time = updated.getTime() / 1000; // Convert to seconds
30
- utimesSync(filePath, time, time);
31
- }
32
-
33
- beforeEach(() => initFiles());
34
- afterEach(() => cleanFiles());
35
-
36
- test('Should find files diff', () => {
37
- createTestFile(`unchanged file!`, 'org-file.org', new Date('2021-01-01'));
38
- createTestFile(
39
- `changed org file 2!`,
40
- 'org-file2.org',
41
- new Date('2022-01-01')
42
- );
43
- createTestFile(
44
- `deleted org in the nested folder file!`,
45
- 'nested-folder/org-file3.org',
46
- new Date('2021-01-01')
47
- );
48
- createTestFile(
49
- `created file in the nested folder!`,
50
- 'nested-folder/org-file4.org',
51
- new Date('2021-02-01')
52
- );
53
-
54
- const storedNoteInfos: StoredNoteInfo[] = [
55
- {
56
- filePath: [testFilesFolder + 'deleted-org-file.org'],
57
- id: 'deleted-org-file.org',
58
- updatedAt: new Date('2021-01-01'),
59
- },
60
- {
61
- filePath: [testFilesFolder + 'org-file.org'],
62
- id: 'org-file.org',
63
- updatedAt: new Date('2021-01-01'),
64
- },
65
- {
66
- filePath: [testFilesFolder + 'org-file2.org'],
67
- id: 'org-file2.org',
68
- updatedAt: new Date('2021-01-01'),
69
- },
70
- {
71
- filePath: [testFilesFolder + 'nested-folder/org-file3.org'],
72
- id: 'nested-folder/org-file3.org',
73
- updatedAt: new Date('2021-01-01'),
74
- },
75
- ];
76
-
77
- const changedFiles = findFilesDiff(
78
- [
79
- testFilesFolder + 'org-file.org',
80
- testFilesFolder + 'org-file2.org',
81
- testFilesFolder + 'nested-folder/org-file3.org',
82
- testFilesFolder + 'nested-folder/org-file4.org',
83
- ],
84
- storedNoteInfos,
85
- (filePath: string) => new Date(statSync(filePath).mtime)
86
- );
87
-
88
- expect(changedFiles).toEqual({
89
- created: [testFilesFolder + 'nested-folder/org-file4.org'],
90
- updated: [testFilesFolder + 'org-file2.org'],
91
- deleted: [testFilesFolder + 'deleted-org-file.org'],
92
- });
93
- });
94
-
95
- test('Should find files diff when folder was renamed', () => {
96
- createTestFile(
97
- `nested file!`,
98
- 'nested-folder/org-file.org',
99
- new Date('2021-01-01')
100
- );
101
- createTestFile(
102
- `nested file2!`,
103
- 'nested-folder/org-file-2.org',
104
- new Date('2021-01-01')
105
- );
106
-
107
- const storedNoteInfos: StoredNoteInfo[] = [
108
- {
109
- filePath: [testFilesFolder + 'nested-folder/org-file.org'],
110
- id: 'nested-folder/org-file.org',
111
- updatedAt: new Date('2021-01-01'),
112
- },
113
- {
114
- filePath: [testFilesFolder + 'nested-folder/org-file2.org'],
115
- id: 'nested-folder/org-file2.org',
116
- updatedAt: new Date('2021-01-01'),
117
- },
118
- ];
119
-
120
- rmdirSync(testFilesFolder + 'nested-folder', { recursive: true });
121
-
122
- const changedFiles = findFilesDiff(
123
- [],
124
- storedNoteInfos,
125
- (filePath: string) => new Date(statSync(filePath).mtime)
126
- );
127
-
128
- expect(changedFiles).toMatchInlineSnapshot(`
129
- {
130
- "created": [],
131
- "deleted": [
132
- "src/tools/__tests__/miscellaneous2/nested-folder/org-file.org",
133
- "src/tools/__tests__/miscellaneous2/nested-folder/org-file2.org",
134
- ],
135
- "updated": [],
136
- }
137
- `);
138
- });
139
-
140
- test('Should find created note when nested folder created', () => {
141
- mkdirSync(testFilesFolder + 'new-nested-folder');
142
- createTestFile(
143
- `new nested file!`,
144
- 'new-nested-folder/org-file.org',
145
- new Date('2023-01-01')
146
- );
147
-
148
- const storedNoteInfos: StoredNoteInfo[] = [];
149
-
150
- const changedFiles = findFilesDiff(
151
- [testFilesFolder + 'new-nested-folder/org-file.org'],
152
- storedNoteInfos,
153
- (filePath: string) => new Date(statSync(filePath).mtime)
154
- );
155
-
156
- expect(changedFiles).toEqual({
157
- created: [testFilesFolder + 'new-nested-folder/org-file.org'],
158
- updated: [],
159
- deleted: [],
160
- });
161
- });
162
-
163
- test('Should find nothing when no files provided', () => {
164
- const storedNoteInfos: StoredNoteInfo[] = [];
165
-
166
- const changedFiles = findFilesDiff(
167
- [],
168
- storedNoteInfos,
169
- (filePath: string) => new Date(statSync(filePath).mtime)
170
- );
171
-
172
- expect(changedFiles).toEqual({
173
- created: [],
174
- updated: [],
175
- deleted: [],
176
- });
177
- });
@@ -1,207 +0,0 @@
1
- import { mkdirSync, writeFileSync, utimesSync, readdirSync } from 'fs';
2
- import { afterEach, beforeEach, test, expect } from 'vitest';
3
- import { FileInfo, StoredNoteInfo } from '../../models';
4
- import { findNoteFilesDiff } from '../find-notes-files-diff';
5
- import { statSync } from 'fs';
6
- import { Stats } from 'fs';
7
- import { rmSync } from 'fs';
8
- import { getFileName } from '../get-file-name';
9
- import { join } from '../join';
10
-
11
- const testFilesFolder = 'src/tools/__tests__/miscellaneous/';
12
- const nestedFolder = 'nested-folder/';
13
- const fn = (fileName: string) => `${testFilesFolder}${fileName}`;
14
- const fns = (fileName: string) =>
15
- `${testFilesFolder}${nestedFolder}${fileName}`;
16
-
17
- function initFiles(): void {
18
- mkdirSync(testFilesFolder.slice(0, -1));
19
- mkdirSync(fn(nestedFolder));
20
- }
21
-
22
- function cleanFiles(): void {
23
- try {
24
- rmSync(testFilesFolder, { recursive: true });
25
- } catch (e) {}
26
- }
27
-
28
- function createTestFile(
29
- filePath: string,
30
- updated: Date,
31
- content: string
32
- ): void {
33
- writeFileSync(filePath, content);
34
-
35
- const time = updated.getTime() / 1000; // Convert to seconds
36
- utimesSync(filePath, time, time);
37
- }
38
-
39
- beforeEach(() => initFiles());
40
- afterEach(() => cleanFiles());
41
-
42
- const fileStatToFileInfo = (path: string, stat: Stats): FileInfo => ({
43
- path,
44
- name: getFileName(path),
45
- type: stat.isFile() ? 'file' : 'directory',
46
- size: stat.size,
47
- atime: stat.atime.getTime(),
48
- mtime: stat.mtime.getTime(),
49
- ctime: stat.ctime.getTime(),
50
- });
51
-
52
- test('Should sync notes files', async () => {
53
- const files = [
54
- [fn('file-1.org')],
55
- [fn('file-2.org')],
56
- [fn('file-9.org'), new Date('2024-10-10')],
57
- [fns('file-3.org')],
58
- [fns('file-4.org'), new Date('2024-08-09')],
59
- ] as const;
60
-
61
- files.forEach(([f, d], i) =>
62
- createTestFile(
63
- f,
64
- d ?? new Date('2024-01-01'),
65
- `:PROPERTIES:
66
- :ID: ${i + 1}
67
- :PROPERTIES:
68
-
69
- * Hello world from note:
70
- - ${f}`
71
- )
72
- );
73
-
74
- const storedNotesInfo: StoredNoteInfo[] = [
75
- {
76
- id: '2',
77
- filePath: fn('file-1.org').split('/'),
78
- updatedAt: new Date('2024-01-01'),
79
- },
80
- {
81
- id: '3',
82
- filePath: fns('file-3.org').split('/'),
83
- updatedAt: new Date('2024-01-01'),
84
- },
85
- {
86
- id: '9',
87
- filePath: fn('file-9.org').split('/'),
88
- updatedAt: new Date('2020-01-01'),
89
- },
90
- {
91
- id: '10',
92
- filePath: fns('file-10.org').split('/'),
93
- updatedAt: new Date('2020-01-01'),
94
- },
95
- ];
96
-
97
- const notesFilesDiff = await findNoteFilesDiff({
98
- fileInfo: async (path: string) => {
99
- const stats = statSync(path);
100
-
101
- const fileInfo: FileInfo = fileStatToFileInfo(path, stats);
102
-
103
- return Promise.resolve(fileInfo);
104
- },
105
- readDir: async (path: string) => {
106
- const dirents = readdirSync(path, { withFileTypes: true });
107
-
108
- const fileInfos: FileInfo[] = dirents.map((dirent) => {
109
- const stats = statSync(join(path, dirent.name));
110
- const fileInfo = fileStatToFileInfo(join(path, dirent.name), stats);
111
- return fileInfo;
112
- });
113
-
114
- return Promise.resolve(fileInfos);
115
- },
116
- storedNotesInfo,
117
- dirPath: testFilesFolder,
118
- });
119
-
120
- expect(notesFilesDiff).toMatchInlineSnapshot(`
121
- {
122
- "created": [
123
- {
124
- "filePath": "src/tools/__tests__/miscellaneous/file-2.org",
125
- },
126
- {
127
- "filePath": "src/tools/__tests__/miscellaneous/nested-folder/file-4.org",
128
- },
129
- ],
130
- "deleted": [
131
- {
132
- "filePath": "src/tools/__tests__/miscellaneous/nested-folder/file-10.org",
133
- "id": "10",
134
- },
135
- ],
136
- "updated": [
137
- {
138
- "filePath": "src/tools/__tests__/miscellaneous/file-9.org",
139
- },
140
- ],
141
- }
142
- `);
143
- });
144
-
145
- test('Should detect no changes when all files match stored info', async () => {
146
- const files = [
147
- [fn('file-1.org'), new Date('2024-01-01')],
148
- [fn('file-2.org'), new Date('2024-01-01')],
149
- [fns('file-3.org'), new Date('2024-01-01')],
150
- ] as const;
151
-
152
- files.forEach(([f, d], i) =>
153
- createTestFile(
154
- f,
155
- d ?? new Date('2024-01-01'),
156
- `:PROPERTIES:
157
- :ID: ${i + 1}
158
- :PROPERTIES:
159
-
160
- * Note:
161
- - ${f}`
162
- )
163
- );
164
-
165
- const storedNotesInfo: StoredNoteInfo[] = [
166
- {
167
- id: '1',
168
- filePath: fn('file-1.org').split('/'),
169
- updatedAt: new Date('2024-01-01'),
170
- },
171
- {
172
- id: '2',
173
- filePath: fn('file-2.org').split('/'),
174
- updatedAt: new Date('2024-01-01'),
175
- },
176
- {
177
- id: '3',
178
- filePath: fns('file-3.org').split('/'),
179
- updatedAt: new Date('2024-01-01'),
180
- },
181
- ];
182
-
183
- const notesFilesDiff = await findNoteFilesDiff({
184
- fileInfo: async (path: string) => {
185
- const stats = statSync(path);
186
- const fileInfo: FileInfo = fileStatToFileInfo(path, stats);
187
- return Promise.resolve(fileInfo);
188
- },
189
- readDir: async (path: string) => {
190
- const dirents = readdirSync(path, { withFileTypes: true });
191
- const fileInfos: FileInfo[] = dirents.map((dirent) => {
192
- const stats = statSync(join(path, dirent.name));
193
- const fileInfo = fileStatToFileInfo(join(path, dirent.name), stats);
194
- return fileInfo;
195
- });
196
- return Promise.resolve(fileInfos);
197
- },
198
- storedNotesInfo,
199
- dirPath: testFilesFolder,
200
- });
201
-
202
- expect(notesFilesDiff).toEqual({
203
- created: [],
204
- updated: [],
205
- deleted: [],
206
- });
207
- });
@@ -1,32 +0,0 @@
1
- import { getStringPath } from '../get-string-path';
2
- import { test, expect } from 'vitest';
3
-
4
- test('should return the same string if path is a string', () => {
5
- const path = 'some/path';
6
- const result = getStringPath(path);
7
- expect(result).toBe('some/path');
8
- });
9
-
10
- test('should join array elements with "/" if path is an array', () => {
11
- const path = ['some', 'path'];
12
- const result = getStringPath(path);
13
- expect(result).toBe('some/path');
14
- });
15
-
16
- test('should return an empty string if path is an empty array', () => {
17
- const path: string[] = [];
18
- const result = getStringPath(path);
19
- expect(result).toBe('');
20
- });
21
-
22
- test('should handle array with one element correctly', () => {
23
- const path = ['single'];
24
- const result = getStringPath(path);
25
- expect(result).toBe('single');
26
- });
27
-
28
- test('should handle array with multiple elements correctly', () => {
29
- const path = ['this', 'is', 'a', 'test'];
30
- const result = getStringPath(path);
31
- expect(result).toBe('this/is/a/test');
32
- });
@@ -1,62 +0,0 @@
1
- import { test, expect } from 'vitest';
2
- import { isOrgFile, isOrgGpgFile } from '../is-org-file';
3
-
4
- test('Should return true for org files', () => {
5
- const files = [
6
- 'myNote.org',
7
- 'my_note.org',
8
- '123.org',
9
- 'some_long_note#4123$123eqasdasd.org.gpg',
10
- 'some_long_note#4123$123eqasdasd.org',
11
- 'note with space.org',
12
- 'note with space.org.gpg',
13
- ];
14
-
15
- files.forEach((file) => {
16
- expect(isOrgFile(file), file).toBe(true);
17
- });
18
- });
19
-
20
- test('Should not return true for non-org files', () => {
21
- const files = [
22
- 'myNote.md',
23
- 'my_note.md',
24
- '123.md',
25
- 'some_long_note#4123$123eqasdas',
26
- 'note.org.file',
27
- 'org',
28
- 'org.',
29
- 'text.gpg',
30
- ];
31
-
32
- files.forEach((file) => {
33
- expect(isOrgFile(file), file).toBe(false);
34
- });
35
- });
36
-
37
- test('Should return true for org.gpg files', () => {
38
- const gpgFiles = [
39
- 'myNote.org.gpg',
40
- 'my_note.org.gpg',
41
- '123.org.gpg',
42
- 'org.org.gpg',
43
- 'gp_org.org.gpg',
44
- ];
45
-
46
- gpgFiles.forEach((file) => {
47
- expect(isOrgGpgFile(file), file).toBe(true);
48
- });
49
- });
50
-
51
- test('Should not return true for not .org.gpg files', () => {
52
- const notGpgFiles = [
53
- 'myNote.org',
54
- 'my_note.org',
55
- '123.org',
56
- 'some_gpg_file.txt',
57
- ];
58
-
59
- notGpgFiles.forEach((file) => {
60
- expect(isOrgGpgFile(file), file).toBe(false);
61
- });
62
- });
@@ -1,16 +0,0 @@
1
- import { test, expect } from 'vitest';
2
- import { join } from '../join';
3
-
4
- test('Should join file paths', () => {
5
- const samples = [
6
- ['dir1', 'subdir2', 'file'],
7
- ['dir2/', '/file'],
8
- ['/dri3', 'subdir2/', 'file'],
9
- ['file'],
10
- ];
11
-
12
- samples.forEach((sample) => {
13
- const result = join(...sample);
14
- expect(result).toMatchSnapshot();
15
- });
16
- });