@bemoje/fs 0.0.12 → 0.1.0

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 (151) hide show
  1. package/README.md +6 -34
  2. package/package.json +9 -9
  3. package/src/index.d.ts +35 -0
  4. package/src/index.js +39 -0
  5. package/src/index.js.map +1 -0
  6. package/src/lib/AppData.d.ts +10 -0
  7. package/src/lib/AppData.js +24 -0
  8. package/src/lib/AppData.js.map +1 -0
  9. package/src/lib/JsonFile.d.ts +78 -0
  10. package/src/lib/JsonFile.js +146 -0
  11. package/src/lib/JsonFile.js.map +1 -0
  12. package/src/lib/LogFile.d.ts +50 -0
  13. package/src/lib/LogFile.js +158 -0
  14. package/src/lib/LogFile.js.map +1 -0
  15. package/src/lib/{absoluteToRelativePath.ts → absoluteToRelativePath.d.ts} +13 -20
  16. package/src/lib/absoluteToRelativePath.js +25 -0
  17. package/src/lib/absoluteToRelativePath.js.map +1 -0
  18. package/src/lib/appendLineToFile.d.ts +11 -0
  19. package/src/lib/appendLineToFile.js +28 -0
  20. package/src/lib/appendLineToFile.js.map +1 -0
  21. package/src/lib/{cleanDirectorySync.ts → cleanDirectorySync.d.ts} +16 -24
  22. package/src/lib/cleanDirectorySync.js +29 -0
  23. package/src/lib/cleanDirectorySync.js.map +1 -0
  24. package/src/lib/{createDirectory.ts → createDirectory.d.ts} +1 -5
  25. package/src/lib/createDirectory.js +25 -0
  26. package/src/lib/createDirectory.js.map +1 -0
  27. package/src/lib/{createDirectorySync.ts → createDirectorySync.d.ts} +1 -6
  28. package/src/lib/createDirectorySync.js +20 -0
  29. package/src/lib/createDirectorySync.js.map +1 -0
  30. package/src/lib/{createFileExtensionFilter.ts → createFileExtensionFilter.d.ts} +1 -14
  31. package/src/lib/createFileExtensionFilter.js +32 -0
  32. package/src/lib/createFileExtensionFilter.js.map +1 -0
  33. package/src/lib/{cwdpath.ts → cwdpath.d.ts} +12 -16
  34. package/src/lib/cwdpath.js +21 -0
  35. package/src/lib/cwdpath.js.map +1 -0
  36. package/src/lib/{deleteDirectory.ts → deleteDirectory.d.ts} +1 -5
  37. package/src/lib/deleteDirectory.js +23 -0
  38. package/src/lib/deleteDirectory.js.map +1 -0
  39. package/src/lib/{deleteDirectorySafe.ts → deleteDirectorySafe.d.ts} +1 -5
  40. package/src/lib/deleteDirectorySafe.js +25 -0
  41. package/src/lib/deleteDirectorySafe.js.map +1 -0
  42. package/src/lib/{deleteDirectorySafeSync.ts → deleteDirectorySafeSync.d.ts} +1 -7
  43. package/src/lib/deleteDirectorySafeSync.js +23 -0
  44. package/src/lib/deleteDirectorySafeSync.js.map +1 -0
  45. package/src/lib/{deleteDirectorySync.ts → deleteDirectorySync.d.ts} +1 -6
  46. package/src/lib/deleteDirectorySync.js +22 -0
  47. package/src/lib/deleteDirectorySync.js.map +1 -0
  48. package/src/lib/{ensureValidWindowsPath.ts → ensureValidWindowsPath.d.ts} +22 -57
  49. package/src/lib/ensureValidWindowsPath.js +54 -0
  50. package/src/lib/ensureValidWindowsPath.js.map +1 -0
  51. package/src/lib/getDiskDrivesWindows.d.ts +1 -0
  52. package/src/lib/getDiskDrivesWindows.js +19 -0
  53. package/src/lib/getDiskDrivesWindows.js.map +1 -0
  54. package/src/lib/getDownloadsDirectory.d.ts +1 -0
  55. package/src/lib/getDownloadsDirectory.js +11 -0
  56. package/src/lib/getDownloadsDirectory.js.map +1 -0
  57. package/src/lib/getHomeDirectory.d.ts +1 -0
  58. package/src/lib/getHomeDirectory.js +13 -0
  59. package/src/lib/getHomeDirectory.js.map +1 -0
  60. package/src/lib/getLastMofifiedFileIn.d.ts +1 -0
  61. package/src/lib/getLastMofifiedFileIn.js +22 -0
  62. package/src/lib/getLastMofifiedFileIn.js.map +1 -0
  63. package/src/lib/getRootDir.d.ts +1 -0
  64. package/src/lib/getRootDir.js +10 -0
  65. package/src/lib/getRootDir.js.map +1 -0
  66. package/src/lib/isWindows.d.ts +1 -0
  67. package/src/lib/isWindows.js +8 -0
  68. package/src/lib/isWindows.js.map +1 -0
  69. package/src/lib/{normalizeFileExtension.ts → normalizeFileExtension.d.ts} +22 -29
  70. package/src/lib/normalizeFileExtension.js +36 -0
  71. package/src/lib/normalizeFileExtension.js.map +1 -0
  72. package/src/lib/readFileLastLines.d.ts +7 -0
  73. package/src/lib/readFileLastLines.js +18 -0
  74. package/src/lib/readFileLastLines.js.map +1 -0
  75. package/src/lib/{readJsonFile.ts → readJsonFile.d.ts} +12 -16
  76. package/src/lib/readJsonFile.js +23 -0
  77. package/src/lib/readJsonFile.js.map +1 -0
  78. package/src/lib/{readJsonFileSync.ts → readJsonFileSync.d.ts} +12 -16
  79. package/src/lib/readJsonFileSync.js +21 -0
  80. package/src/lib/readJsonFileSync.js.map +1 -0
  81. package/src/lib/readPackageJson.d.ts +1 -0
  82. package/src/lib/readPackageJson.js +15 -0
  83. package/src/lib/readPackageJson.js.map +1 -0
  84. package/src/lib/removeIllegalFilenameCharacters.d.ts +1 -0
  85. package/src/lib/removeIllegalFilenameCharacters.js +8 -0
  86. package/src/lib/removeIllegalFilenameCharacters.js.map +1 -0
  87. package/src/lib/tempFile.d.ts +6 -0
  88. package/src/lib/tempFile.js +26 -0
  89. package/src/lib/tempFile.js.map +1 -0
  90. package/src/lib/types/IEnsureValidWindowsPathOptions.d.ts +10 -0
  91. package/src/lib/types/IEnsureValidWindowsPathOptions.js +3 -0
  92. package/src/lib/types/IEnsureValidWindowsPathOptions.js.map +1 -0
  93. package/src/lib/types/ILogFileData.d.ts +5 -0
  94. package/src/lib/types/ILogFileData.js +3 -0
  95. package/src/lib/types/ILogFileData.js.map +1 -0
  96. package/src/lib/unzipFile.d.ts +1 -0
  97. package/src/lib/unzipFile.js +12 -0
  98. package/src/lib/unzipFile.js.map +1 -0
  99. package/src/lib/unzipMergeFiles.d.ts +4 -0
  100. package/src/lib/unzipMergeFiles.js +29 -0
  101. package/src/lib/unzipMergeFiles.js.map +1 -0
  102. package/src/lib/wipeDirectorySafe.d.ts +1 -0
  103. package/src/lib/wipeDirectorySafe.js +14 -0
  104. package/src/lib/wipeDirectorySafe.js.map +1 -0
  105. package/src/lib/{writeJsonFile.ts → writeJsonFile.d.ts} +1 -5
  106. package/src/lib/writeJsonFile.js +25 -0
  107. package/src/lib/writeJsonFile.js.map +1 -0
  108. package/src/lib/{writeJsonFileSync.ts → writeJsonFileSync.d.ts} +1 -5
  109. package/src/lib/writeJsonFileSync.js +22 -0
  110. package/src/lib/writeJsonFileSync.js.map +1 -0
  111. package/LICENSE +0 -21
  112. package/jest.config.ts +0 -13
  113. package/project.json +0 -30
  114. package/src/index.ts +0 -35
  115. package/src/lib/AppData.ts +0 -25
  116. package/src/lib/JsonFile.ts +0 -158
  117. package/src/lib/LogFile.ts +0 -117
  118. package/src/lib/absoluteToRelativePath.test.ts +0 -11
  119. package/src/lib/appendLineToFile.test.ts +0 -49
  120. package/src/lib/appendLineToFile.ts +0 -21
  121. package/src/lib/cleanDirectorySync.test.ts +0 -57
  122. package/src/lib/createDirectory.test.ts +0 -14
  123. package/src/lib/createDirectorySync.test.ts +0 -14
  124. package/src/lib/createFileExtensionFilter.test.ts +0 -17
  125. package/src/lib/cwdpath.test.ts +0 -48
  126. package/src/lib/deleteDirectory.test.ts +0 -24
  127. package/src/lib/deleteDirectorySafe.test.ts +0 -40
  128. package/src/lib/deleteDirectorySafeSync.test.ts +0 -30
  129. package/src/lib/deleteDirectorySync.test.ts +0 -23
  130. package/src/lib/ensureValidWindowsPath.test.ts +0 -80
  131. package/src/lib/getDiskDrivesWindows.ts +0 -13
  132. package/src/lib/getDownloadsDirectory.ts +0 -6
  133. package/src/lib/getHomeDirectory.ts +0 -7
  134. package/src/lib/getLastMofifiedFileIn.ts +0 -15
  135. package/src/lib/getRootDir.ts +0 -5
  136. package/src/lib/isWindows.ts +0 -3
  137. package/src/lib/normalizeFileExtension.test.ts +0 -15
  138. package/src/lib/readFileLastLines.ts +0 -12
  139. package/src/lib/readJsonFile.test.ts +0 -34
  140. package/src/lib/readJsonFileSync.test.ts +0 -36
  141. package/src/lib/readPackageJson.ts +0 -9
  142. package/src/lib/removeIllegalFilenameCharacters.ts +0 -3
  143. package/src/lib/tempFile.ts +0 -20
  144. package/src/lib/types/IEnsureValidWindowsPathOptions.ts +0 -10
  145. package/src/lib/types/ILogFileData.ts +0 -5
  146. package/src/lib/unzipFile.ts +0 -5
  147. package/src/lib/unzipMergeFiles.ts +0 -20
  148. package/src/lib/wipeDirectorySafe.ts +0 -7
  149. package/src/lib/writeJsonFile.test.ts +0 -26
  150. package/src/lib/writeJsonFileSync.test.ts +0 -28
  151. package/tsconfig.spec.json +0 -9
package/README.md CHANGED
@@ -1,39 +1,11 @@
1
- # @bemoje/fs
2
- Tools for working with the local filesystem in nodejs.
1
+ # fs
3
2
 
4
- ![GitHub Top Language](https://img.shields.io/github/languages/top/bemoje/https://github.com/bemoje/tsmono)
3
+ This library was generated with [Nx](https://nx.dev).
5
4
 
6
- ##### Github
7
- ![GitHub Last Commit](https://img.shields.io/github/last-commit/bemoje/https://github.com/bemoje/tsmono?color=red)
8
- ![GitHub Stars](https://img.shields.io/github/stars/bemoje/https://github.com/bemoje/tsmono)
9
- ![GitHub Forks](https://img.shields.io/github/forks/bemoje/https://github.com/bemoje/tsmono)
10
- ![GitHub Watchers](https://img.shields.io/github/watchers/bemoje/https://github.com/bemoje/tsmono)
11
- ![GitHub Repo Size](https://img.shields.io/github/repo-size/bemoje/https://github.com/bemoje/tsmono)
5
+ ## Building
12
6
 
13
- ##### NPM
14
- <span><a href="https://npmjs.org/@bemoje/fs" title="View this project on NPM"><img src="https://img.shields.io/npm/v/@bemoje/fs" alt="NPM Version" /></a></span>
15
- <span><a href="https://npmjs.org/@bemoje/fs" title="NPM Downloads"><img src="https://img.shields.io/npm/dt/@bemoje/fs" alt="NPM Downloads" /></a></span>
7
+ Run `nx build fs` to build the library.
16
8
 
17
- ## Documentation
18
- [fs docs](https://bemoje.github.io/tsmono/modules/fs.html)
9
+ ## Running unit tests
19
10
 
20
- ##### Donate
21
- <span><a href="https://www.patreon.com/user?u=40752770" title="Donate using Patreon"><img src="https://img.shields.io/badge/patreon-donate-yellow.svg" alt="Patreon Donation" /></a></span>
22
-
23
- ## Installation
24
- This library is published in the NPM registry and can be installed using any compatible package manager.
25
-
26
- #### NPM
27
- ```sh
28
- npm install @bemoje/fs
29
- ```
30
-
31
-
32
- ## Issues
33
- Please let me know of any bugs or [issues](https://github.com/bemoje/https://github.com/bemoje/tsmono/issues).
34
-
35
- ## Contribute
36
- Contributors are welcome to open a [pull request](https://github.com/bemoje/https://github.com/bemoje/tsmono/pulls).
37
-
38
- ## License
39
- Released under the [MIT License](./LICENSE).
11
+ Run `nx test fs` to execute the unit tests via [Jest](https://jestjs.io).
package/package.json CHANGED
@@ -1,13 +1,9 @@
1
1
  {
2
2
  "name": "@bemoje/fs",
3
- "version": "0.0.12",
3
+ "version": "0.1.0",
4
4
  "description": "Tools for working with the local filesystem in nodejs.",
5
- "main": "src/index.ts",
6
- "module": "dist/index.esm.js",
7
- "types": "dist/types/index.d.ts",
8
- "scripts": {
9
- "build": "rimraf dist && rollup --config ./rollup.config.js --bundleConfigAsCjs"
10
- },
5
+ "main": "./src/index.js",
6
+ "scripts": {},
11
7
  "author": {
12
8
  "name": "Benjamin Møller Jensen",
13
9
  "email": "bemoje@bemoje.net",
@@ -19,7 +15,8 @@
19
15
  "@bemoje/string": "latest",
20
16
  "appdata-path": "^1.0.0",
21
17
  "extract-zip": "^2.0.1",
22
- "read-last-lines": "^1.8.0"
18
+ "read-last-lines": "^1.8.0",
19
+ "tslib": "^2.3.0"
23
20
  },
24
21
  "repository": {
25
22
  "type": "git",
@@ -35,5 +32,8 @@
35
32
  "homepage": "https://github.com/bemoje/tsmono",
36
33
  "devDependencies": {
37
34
  "@types/extract-zip": "^2.0.1"
38
- }
35
+ },
36
+ "type": "commonjs",
37
+ "typings": "./src/index.d.ts",
38
+ "types": "./src/index.d.ts"
39
39
  }
package/src/index.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ export * from './lib/absoluteToRelativePath';
2
+ export * from './lib/AppData';
3
+ export * from './lib/appendLineToFile';
4
+ export * from './lib/cleanDirectorySync';
5
+ export * from './lib/createDirectory';
6
+ export * from './lib/createDirectorySync';
7
+ export * from './lib/createFileExtensionFilter';
8
+ export * from './lib/cwdpath';
9
+ export * from './lib/deleteDirectory';
10
+ export * from './lib/deleteDirectorySafe';
11
+ export * from './lib/deleteDirectorySafeSync';
12
+ export * from './lib/deleteDirectorySync';
13
+ export * from './lib/ensureValidWindowsPath';
14
+ export * from './lib/getDiskDrivesWindows';
15
+ export * from './lib/getDownloadsDirectory';
16
+ export * from './lib/getHomeDirectory';
17
+ export * from './lib/getLastMofifiedFileIn';
18
+ export * from './lib/getRootDir';
19
+ export * from './lib/isWindows';
20
+ export * from './lib/JsonFile';
21
+ export * from './lib/LogFile';
22
+ export * from './lib/normalizeFileExtension';
23
+ export * from './lib/readFileLastLines';
24
+ export * from './lib/readJsonFile';
25
+ export * from './lib/readJsonFileSync';
26
+ export * from './lib/readPackageJson';
27
+ export * from './lib/removeIllegalFilenameCharacters';
28
+ export * from './lib/tempFile';
29
+ export * from './lib/types/IEnsureValidWindowsPathOptions';
30
+ export * from './lib/types/ILogFileData';
31
+ export * from './lib/unzipFile';
32
+ export * from './lib/unzipMergeFiles';
33
+ export * from './lib/wipeDirectorySafe';
34
+ export * from './lib/writeJsonFile';
35
+ export * from './lib/writeJsonFileSync';
package/src/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./lib/absoluteToRelativePath"), exports);
5
+ tslib_1.__exportStar(require("./lib/AppData"), exports);
6
+ tslib_1.__exportStar(require("./lib/appendLineToFile"), exports);
7
+ tslib_1.__exportStar(require("./lib/cleanDirectorySync"), exports);
8
+ tslib_1.__exportStar(require("./lib/createDirectory"), exports);
9
+ tslib_1.__exportStar(require("./lib/createDirectorySync"), exports);
10
+ tslib_1.__exportStar(require("./lib/createFileExtensionFilter"), exports);
11
+ tslib_1.__exportStar(require("./lib/cwdpath"), exports);
12
+ tslib_1.__exportStar(require("./lib/deleteDirectory"), exports);
13
+ tslib_1.__exportStar(require("./lib/deleteDirectorySafe"), exports);
14
+ tslib_1.__exportStar(require("./lib/deleteDirectorySafeSync"), exports);
15
+ tslib_1.__exportStar(require("./lib/deleteDirectorySync"), exports);
16
+ tslib_1.__exportStar(require("./lib/ensureValidWindowsPath"), exports);
17
+ tslib_1.__exportStar(require("./lib/getDiskDrivesWindows"), exports);
18
+ tslib_1.__exportStar(require("./lib/getDownloadsDirectory"), exports);
19
+ tslib_1.__exportStar(require("./lib/getHomeDirectory"), exports);
20
+ tslib_1.__exportStar(require("./lib/getLastMofifiedFileIn"), exports);
21
+ tslib_1.__exportStar(require("./lib/getRootDir"), exports);
22
+ tslib_1.__exportStar(require("./lib/isWindows"), exports);
23
+ tslib_1.__exportStar(require("./lib/JsonFile"), exports);
24
+ tslib_1.__exportStar(require("./lib/LogFile"), exports);
25
+ tslib_1.__exportStar(require("./lib/normalizeFileExtension"), exports);
26
+ tslib_1.__exportStar(require("./lib/readFileLastLines"), exports);
27
+ tslib_1.__exportStar(require("./lib/readJsonFile"), exports);
28
+ tslib_1.__exportStar(require("./lib/readJsonFileSync"), exports);
29
+ tslib_1.__exportStar(require("./lib/readPackageJson"), exports);
30
+ tslib_1.__exportStar(require("./lib/removeIllegalFilenameCharacters"), exports);
31
+ tslib_1.__exportStar(require("./lib/tempFile"), exports);
32
+ tslib_1.__exportStar(require("./lib/types/IEnsureValidWindowsPathOptions"), exports);
33
+ tslib_1.__exportStar(require("./lib/types/ILogFileData"), exports);
34
+ tslib_1.__exportStar(require("./lib/unzipFile"), exports);
35
+ tslib_1.__exportStar(require("./lib/unzipMergeFiles"), exports);
36
+ tslib_1.__exportStar(require("./lib/wipeDirectorySafe"), exports);
37
+ tslib_1.__exportStar(require("./lib/writeJsonFile"), exports);
38
+ tslib_1.__exportStar(require("./lib/writeJsonFileSync"), exports);
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/fs/src/index.ts"],"names":[],"mappings":";;;AAAA,uEAA4C;AAC5C,wDAA6B;AAC7B,iEAAsC;AACtC,mEAAwC;AACxC,gEAAqC;AACrC,oEAAyC;AACzC,0EAA+C;AAC/C,wDAA6B;AAC7B,gEAAqC;AACrC,oEAAyC;AACzC,wEAA6C;AAC7C,oEAAyC;AACzC,uEAA4C;AAC5C,qEAA0C;AAC1C,sEAA2C;AAC3C,iEAAsC;AACtC,sEAA2C;AAC3C,2DAAgC;AAChC,0DAA+B;AAC/B,yDAA8B;AAC9B,wDAA6B;AAC7B,uEAA4C;AAC5C,kEAAuC;AACvC,6DAAkC;AAClC,iEAAsC;AACtC,gEAAqC;AACrC,gFAAqD;AACrD,yDAA8B;AAC9B,qFAA0D;AAC1D,mEAAwC;AACxC,0DAA+B;AAC/B,gEAAqC;AACrC,kEAAuC;AACvC,8DAAmC;AACnC,kEAAuC"}
@@ -0,0 +1,10 @@
1
+ import { JsonFile } from './JsonFile';
2
+ import { LogFile } from './LogFile';
3
+ import { ILogFileData } from './types/ILogFileData';
4
+ export declare class AppData<A extends Record<string, unknown>, C extends Record<string, unknown>> {
5
+ directory: string;
6
+ app: JsonFile<A>;
7
+ user: JsonFile<C>;
8
+ history: LogFile<ILogFileData<C>>;
9
+ constructor(appAuthor: string, appName: string, configName: string);
10
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AppData = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const appdata_path_1 = tslib_1.__importDefault(require("appdata-path"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const JsonFile_1 = require("./JsonFile");
8
+ const LogFile_1 = require("./LogFile");
9
+ class AppData {
10
+ constructor(appAuthor, appName, configName) {
11
+ this.directory = path_1.default.join((0, appdata_path_1.default)(), appAuthor, appName, configName);
12
+ this.app = new JsonFile_1.JsonFile(path_1.default.join(this.directory, 'appdata.json'), false);
13
+ this.user = new JsonFile_1.JsonFile(path_1.default.join(this.directory, 'config.json'), true);
14
+ this.history = new LogFile_1.LogFile(path_1.default.join(this.directory, 'history.log'));
15
+ this.app.on('set', (time, k, v) => tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ yield this.history.append({ source: 'app', key: k, value: v }, time);
17
+ }));
18
+ this.user.on('set', (time, k, v) => tslib_1.__awaiter(this, void 0, void 0, function* () {
19
+ yield this.history.append({ source: 'user', key: k, value: v }, time);
20
+ }));
21
+ }
22
+ }
23
+ exports.AppData = AppData;
24
+ //# sourceMappingURL=AppData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AppData.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/AppData.ts"],"names":[],"mappings":";;;;AAAA,wEAAyC;AACzC,wDAAuB;AACvB,yCAAqC;AACrC,uCAAmC;AAGnC,MAAa,OAAO;IAMlB,YAAY,SAAiB,EAAE,OAAe,EAAE,UAAkB;QAChE,IAAI,CAAC,SAAS,GAAG,cAAI,CAAC,IAAI,CAAC,IAAA,sBAAc,GAAE,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAA;QAC5E,IAAI,CAAC,GAAG,GAAG,IAAI,mBAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,EAAE,KAAK,CAAC,CAAA;QACzE,IAAI,CAAC,IAAI,GAAG,IAAI,mBAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,IAAI,CAAC,CAAA;QACxE,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAC,cAAI,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAA;QACpE,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAO,IAAI,EAAE,CAAS,EAAE,CAAI,EAAE,EAAE;YACjD,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACtE,CAAC,CAAA,CAAC,CAAA;QACF,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,CAAO,IAAI,EAAE,CAAS,EAAE,CAAI,EAAE,EAAE;YAClD,MAAM,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,IAAI,CAAC,CAAA;QACvE,CAAC,CAAA,CAAC,CAAA;IACJ,CAAC;CACF;AAlBD,0BAkBC"}
@@ -0,0 +1,78 @@
1
+ /// <reference types="node" />
2
+ import EventEmitter from 'events';
3
+ /**
4
+ * Represents a JSON file manager that ensures immutable data since everything is serialized and deserialized before receiving or returning any data.
5
+ */
6
+ export declare class JsonFile<T extends Record<string, any>> extends EventEmitter {
7
+ #private;
8
+ /**
9
+ * The filepath of the JSON file.
10
+ */
11
+ readonly filepath: string;
12
+ /**
13
+ * Determines whether the JSON file should be pretty-printed.
14
+ */
15
+ prettyPrint: boolean;
16
+ /**
17
+ * Gets the data stored in the JSON file.
18
+ * @returns A deep copy of the data.
19
+ */
20
+ get data(): T;
21
+ /**
22
+ * Constructs a new instance of the JsonFile class.
23
+ * @param filepath - The filepath of the JSON file.
24
+ * @param prettyPrint - Determines whether the JSON file should be pretty-printed.
25
+ */
26
+ constructor(filepath: string, prettyPrint?: boolean);
27
+ /**
28
+ * Gets the value associated with the specified key.
29
+ * @param key - The key to retrieve the value for.
30
+ * @returns The value associated with the key.
31
+ */
32
+ get(key: keyof T): any;
33
+ /**
34
+ * Sets the value associated with the specified key.
35
+ * @param key - The key to set the value for.
36
+ * @param value - The value to set.
37
+ */
38
+ set(key: keyof T, value: any): void;
39
+ /**
40
+ * Checks if the specified key exists in the JSON file.
41
+ * @param key - The key to check.
42
+ * @returns True if the key exists, false otherwise.
43
+ */
44
+ has(key: keyof T): boolean;
45
+ /**
46
+ * Deletes the value associated with the specified key.
47
+ * @param key - The key to delete.
48
+ */
49
+ delete(key: keyof T): void;
50
+ /**
51
+ * Gets the value associated with the specified key, or sets it to the provided default value if it doesn't exist.
52
+ * @param key - The key to get or set.
53
+ * @param getValue - A function that returns the default value if the key doesn't exist.
54
+ * @returns The value associated with the key, or the default value if it doesn't exist.
55
+ */
56
+ getOrElse(key: string, getValue: () => any): any;
57
+ /**
58
+ * Clears all the data in the JSON file.
59
+ */
60
+ clear(): void;
61
+ /**
62
+ * Assigns new data to the JSON file.
63
+ * @param data - The data to assign.
64
+ */
65
+ assign(data: T): void;
66
+ /**
67
+ * Ensures that the directory containing the JSON file exists.
68
+ */
69
+ ensureDirectoryExists(): void;
70
+ /**
71
+ * Saves the data to the JSON file.
72
+ */
73
+ saveFile(): void;
74
+ /**
75
+ * Loads the data from the JSON file.
76
+ */
77
+ loadFile(): void;
78
+ }
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var _JsonFile_data;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.JsonFile = void 0;
5
+ const tslib_1 = require("tslib");
6
+ const events_1 = tslib_1.__importDefault(require("events"));
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const path_1 = tslib_1.__importDefault(require("path"));
9
+ const readJsonFileSync_1 = require("./readJsonFileSync");
10
+ const writeJsonFileSync_1 = require("./writeJsonFileSync");
11
+ /**
12
+ * Represents a JSON file manager that ensures immutable data since everything is serialized and deserialized before receiving or returning any data.
13
+ */
14
+ class JsonFile extends events_1.default {
15
+ /**
16
+ * Gets the data stored in the JSON file.
17
+ * @returns A deep copy of the data.
18
+ */
19
+ get data() {
20
+ return JSON.parse(JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")));
21
+ }
22
+ /**
23
+ * Constructs a new instance of the JsonFile class.
24
+ * @param filepath - The filepath of the JSON file.
25
+ * @param prettyPrint - Determines whether the JSON file should be pretty-printed.
26
+ */
27
+ constructor(filepath, prettyPrint = false) {
28
+ super();
29
+ /**
30
+ * The data stored in the JSON file.
31
+ */
32
+ _JsonFile_data.set(this, void 0);
33
+ this.filepath = filepath;
34
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, {}, "f");
35
+ this.prettyPrint = prettyPrint;
36
+ this.ensureDirectoryExists();
37
+ if (fs_1.default.existsSync(this.filepath)) {
38
+ this.loadFile();
39
+ }
40
+ else {
41
+ (0, writeJsonFileSync_1.writeJsonFileSync)(this.filepath, tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), this.prettyPrint);
42
+ }
43
+ }
44
+ /**
45
+ * Gets the value associated with the specified key.
46
+ * @param key - The key to retrieve the value for.
47
+ * @returns The value associated with the key.
48
+ */
49
+ get(key) {
50
+ return JSON.parse(JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]));
51
+ }
52
+ /**
53
+ * Sets the value associated with the specified key.
54
+ * @param key - The key to set the value for.
55
+ * @param value - The value to set.
56
+ */
57
+ set(key, value) {
58
+ if (tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] === value)
59
+ return;
60
+ const json = JSON.stringify(value);
61
+ if (json === JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]))
62
+ return;
63
+ value = JSON.parse(json);
64
+ tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] = value;
65
+ this.saveFile();
66
+ this.emit('set', Date.now(), key, value);
67
+ }
68
+ /**
69
+ * Checks if the specified key exists in the JSON file.
70
+ * @param key - The key to check.
71
+ * @returns True if the key exists, false otherwise.
72
+ */
73
+ has(key) {
74
+ return tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] !== undefined;
75
+ }
76
+ /**
77
+ * Deletes the value associated with the specified key.
78
+ * @param key - The key to delete.
79
+ */
80
+ delete(key) {
81
+ delete tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key];
82
+ this.saveFile();
83
+ this.emit('set', Date.now(), key, void 0);
84
+ }
85
+ /**
86
+ * Gets the value associated with the specified key, or sets it to the provided default value if it doesn't exist.
87
+ * @param key - The key to get or set.
88
+ * @param getValue - A function that returns the default value if the key doesn't exist.
89
+ * @returns The value associated with the key, or the default value if it doesn't exist.
90
+ */
91
+ getOrElse(key, getValue) {
92
+ if (this.has(key)) {
93
+ return JSON.parse(JSON.stringify(this.get(key)));
94
+ }
95
+ const value = JSON.parse(JSON.stringify(getValue()));
96
+ this.set(key, value);
97
+ return value;
98
+ }
99
+ /**
100
+ * Clears all the data in the JSON file.
101
+ */
102
+ clear() {
103
+ const time = Date.now();
104
+ for (const key of Object.keys(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"))) {
105
+ this.emit('set', time, key, void 0);
106
+ }
107
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, {}, "f");
108
+ fs_1.default.writeFileSync(this.filepath, '{}', 'utf8');
109
+ }
110
+ /**
111
+ * Assigns new data to the JSON file.
112
+ * @param data - The data to assign.
113
+ */
114
+ assign(data) {
115
+ data = JSON.parse(JSON.stringify(data));
116
+ const time = Date.now();
117
+ for (const [key, value] of Object.entries(data)) {
118
+ if (tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key] && JSON.stringify(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f")[key]) !== JSON.stringify(value)) {
119
+ this.emit('set', time, key, value);
120
+ }
121
+ }
122
+ Object.assign(tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), data);
123
+ this.saveFile();
124
+ }
125
+ /**
126
+ * Ensures that the directory containing the JSON file exists.
127
+ */
128
+ ensureDirectoryExists() {
129
+ fs_1.default.mkdirSync(path_1.default.dirname(this.filepath), { recursive: true });
130
+ }
131
+ /**
132
+ * Saves the data to the JSON file.
133
+ */
134
+ saveFile() {
135
+ (0, writeJsonFileSync_1.writeJsonFileSync)(this.filepath, tslib_1.__classPrivateFieldGet(this, _JsonFile_data, "f"), this.prettyPrint);
136
+ }
137
+ /**
138
+ * Loads the data from the JSON file.
139
+ */
140
+ loadFile() {
141
+ tslib_1.__classPrivateFieldSet(this, _JsonFile_data, (0, readJsonFileSync_1.readJsonFileSync)(this.filepath), "f");
142
+ }
143
+ }
144
+ exports.JsonFile = JsonFile;
145
+ _JsonFile_data = new WeakMap();
146
+ //# sourceMappingURL=JsonFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JsonFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/JsonFile.ts"],"names":[],"mappings":";;;;;AAAA,4DAAiC;AACjC,oDAAmB;AACnB,wDAAuB;AACvB,yDAAqD;AACrD,2DAAuD;AAEvD;;GAEG;AACH,MAAa,QAAwC,SAAQ,gBAAY;IAgBvE;;;OAGG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,+BAAA,IAAI,sBAAM,CAAC,CAAC,CAAA;IAC/C,CAAC;IAED;;;;OAIG;IACH,YAAY,QAAgB,EAAE,WAAW,GAAG,KAAK;QAC/C,KAAK,EAAE,CAAA;QAxBT;;WAEG;QACH,iCAAQ;QAsBN,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,+BAAA,IAAI,kBAAS,EAAO,MAAA,CAAA;QACpB,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,qBAAqB,EAAE,CAAA;QAC5B,IAAI,YAAE,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;YAChC,IAAI,CAAC,QAAQ,EAAE,CAAA;SAChB;aAAM;YACL,IAAA,qCAAiB,EAA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AK,CAAC,EAAE;gBAChF,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAC,CAAA;aACnC;SACF;QACD,MAAM,CAAC,MAAM,CAAC,+BAAA,IAAI,sBAAM,EAAE,IAAI,CAAC,CAAA;QAC/B,IAAI,CAAC,QAAQ,EAAE,CAAA;IACjB,CAAC;IAED;;OAEG;IACH,qBAAqB;QACnB,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAChE,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,IAAA,qCAAiB,EAAC,IAAI,CAAC,QAAQ,EAAE,+BAAA,IAAI,sBAAM,EAAE,IAAI,CAAC,WAAW,CAAC,CAAA;IAChE,CAAC;IAED;;OAEG;IACH,QAAQ;QACN,+BAAA,IAAI,kBAAS,IAAA,mCAAgB,EAAC,IAAI,CAAC,QAAQ,CAAM,MAAA,CAAA;IACnD,CAAC;CACF;AApJD,4BAoJC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Represents a log file manager that appends log entries to a file.
3
+ * It does not ensure extremely precise ordering of log entries' timestamps if used asynchronously. It logs them as they are received.
4
+ */
5
+ export declare class LogFile<T> {
6
+ /**
7
+ * The path to the log file.
8
+ */
9
+ filepath: string;
10
+ /**
11
+ * Creates a new instance of the LogFile class.
12
+ * @param filepath - The path to the log file.
13
+ */
14
+ constructor(filepath: string);
15
+ /**
16
+ * Appends a log entry to the log file.
17
+ * @param data - The data to be logged.
18
+ * @param time - The timestamp of the log entry. Defaults to the current time.
19
+ * @returns A promise that resolves when the log entry is appended.
20
+ */
21
+ append(data: T, time?: number): Promise<void>;
22
+ /**
23
+ * Resets the log file by removing it.
24
+ */
25
+ reset(): void;
26
+ /**
27
+ * Reads the log entire file and returns an array of log entries, sorted by timestamp in descending order.
28
+ * @returns An array of log entries, sorted by timestamp in descending order.
29
+ */
30
+ readFile(): [number, T][];
31
+ /**
32
+ * Returns an async generator that yields the timestamps of log entries in the log file.
33
+ * @yields The timestamps of log entries.
34
+ */
35
+ keys(): AsyncGenerator<number>;
36
+ /**
37
+ * Returns an async generator that yields the values of log entries in the log file.
38
+ * @yields The values of log entries.
39
+ */
40
+ values(): AsyncGenerator<T>;
41
+ /**
42
+ * Returns an async generator that yields the entries (timestamp and value) of log entries in the log file.
43
+ * @yields The entries (timestamp and value) of log entries.
44
+ */
45
+ entries(): AsyncGenerator<[number, T]>;
46
+ /**
47
+ * Ensures that the directory containing the log file exists.
48
+ */
49
+ ensureDirectoryExists(): void;
50
+ }
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogFile = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
+ const readline_1 = tslib_1.__importDefault(require("readline"));
8
+ /**
9
+ * Represents a log file manager that appends log entries to a file.
10
+ * It does not ensure extremely precise ordering of log entries' timestamps if used asynchronously. It logs them as they are received.
11
+ */
12
+ class LogFile {
13
+ /**
14
+ * Creates a new instance of the LogFile class.
15
+ * @param filepath - The path to the log file.
16
+ */
17
+ constructor(filepath) {
18
+ this.filepath = filepath;
19
+ this.ensureDirectoryExists();
20
+ }
21
+ /**
22
+ * Appends a log entry to the log file.
23
+ * @param data - The data to be logged.
24
+ * @param time - The timestamp of the log entry. Defaults to the current time.
25
+ * @returns A promise that resolves when the log entry is appended.
26
+ */
27
+ append(data, time = Date.now()) {
28
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
29
+ yield fs_1.default.promises.appendFile(this.filepath, time + '|' + JSON.stringify(data) + '\n', 'utf8');
30
+ });
31
+ }
32
+ /**
33
+ * Resets the log file by removing it.
34
+ */
35
+ reset() {
36
+ fs_1.default.rmSync(this.filepath);
37
+ }
38
+ /**
39
+ * Reads the log entire file and returns an array of log entries, sorted by timestamp in descending order.
40
+ * @returns An array of log entries, sorted by timestamp in descending order.
41
+ */
42
+ readFile() {
43
+ const data = fs_1.default.readFileSync(this.filepath, 'utf8');
44
+ const lines = data.split('\n');
45
+ const result = [];
46
+ for (const line of lines) {
47
+ const i = line.indexOf('|');
48
+ if (i === -1)
49
+ continue;
50
+ const time = parseInt(line.substring(0, i));
51
+ const data = JSON.parse(line.substring(i + 1));
52
+ result.push([time, data]);
53
+ }
54
+ return result.sort((a, b) => b[0] - a[0]);
55
+ }
56
+ /**
57
+ * Returns an async generator that yields the timestamps of log entries in the log file.
58
+ * @yields The timestamps of log entries.
59
+ */
60
+ keys() {
61
+ return tslib_1.__asyncGenerator(this, arguments, function* keys_1() {
62
+ var _a, e_1, _b, _c;
63
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
64
+ const rl = readline_1.default.createInterface({
65
+ input: fileStream,
66
+ crlfDelay: Infinity,
67
+ });
68
+ try {
69
+ for (var _d = true, rl_1 = tslib_1.__asyncValues(rl), rl_1_1; rl_1_1 = yield tslib_1.__await(rl_1.next()), _a = rl_1_1.done, !_a; _d = true) {
70
+ _c = rl_1_1.value;
71
+ _d = false;
72
+ const line = _c;
73
+ const i = line.indexOf('|');
74
+ const time = parseInt(line.substring(0, i));
75
+ yield yield tslib_1.__await(time);
76
+ }
77
+ }
78
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
79
+ finally {
80
+ try {
81
+ if (!_d && !_a && (_b = rl_1.return)) yield tslib_1.__await(_b.call(rl_1));
82
+ }
83
+ finally { if (e_1) throw e_1.error; }
84
+ }
85
+ });
86
+ }
87
+ /**
88
+ * Returns an async generator that yields the values of log entries in the log file.
89
+ * @yields The values of log entries.
90
+ */
91
+ values() {
92
+ return tslib_1.__asyncGenerator(this, arguments, function* values_1() {
93
+ var _a, e_2, _b, _c;
94
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
95
+ const rl = readline_1.default.createInterface({
96
+ input: fileStream,
97
+ crlfDelay: Infinity,
98
+ });
99
+ try {
100
+ for (var _d = true, rl_2 = tslib_1.__asyncValues(rl), rl_2_1; rl_2_1 = yield tslib_1.__await(rl_2.next()), _a = rl_2_1.done, !_a; _d = true) {
101
+ _c = rl_2_1.value;
102
+ _d = false;
103
+ const line = _c;
104
+ const i = line.indexOf('|');
105
+ const data = JSON.parse(line.substring(i + 1));
106
+ yield yield tslib_1.__await(data);
107
+ }
108
+ }
109
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
110
+ finally {
111
+ try {
112
+ if (!_d && !_a && (_b = rl_2.return)) yield tslib_1.__await(_b.call(rl_2));
113
+ }
114
+ finally { if (e_2) throw e_2.error; }
115
+ }
116
+ });
117
+ }
118
+ /**
119
+ * Returns an async generator that yields the entries (timestamp and value) of log entries in the log file.
120
+ * @yields The entries (timestamp and value) of log entries.
121
+ */
122
+ entries() {
123
+ return tslib_1.__asyncGenerator(this, arguments, function* entries_1() {
124
+ var _a, e_3, _b, _c;
125
+ const fileStream = fs_1.default.createReadStream(this.filepath, 'utf8');
126
+ const rl = readline_1.default.createInterface({
127
+ input: fileStream,
128
+ crlfDelay: Infinity,
129
+ });
130
+ try {
131
+ for (var _d = true, rl_3 = tslib_1.__asyncValues(rl), rl_3_1; rl_3_1 = yield tslib_1.__await(rl_3.next()), _a = rl_3_1.done, !_a; _d = true) {
132
+ _c = rl_3_1.value;
133
+ _d = false;
134
+ const line = _c;
135
+ const i = line.indexOf('|');
136
+ const time = parseInt(line.substring(0, i));
137
+ const data = JSON.parse(line.substring(i + 1));
138
+ yield yield tslib_1.__await([time, data]);
139
+ }
140
+ }
141
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
142
+ finally {
143
+ try {
144
+ if (!_d && !_a && (_b = rl_3.return)) yield tslib_1.__await(_b.call(rl_3));
145
+ }
146
+ finally { if (e_3) throw e_3.error; }
147
+ }
148
+ });
149
+ }
150
+ /**
151
+ * Ensures that the directory containing the log file exists.
152
+ */
153
+ ensureDirectoryExists() {
154
+ fs_1.default.mkdirSync(path_1.default.dirname(this.filepath), { recursive: true });
155
+ }
156
+ }
157
+ exports.LogFile = LogFile;
158
+ //# sourceMappingURL=LogFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LogFile.js","sourceRoot":"","sources":["../../../../../packages/fs/src/lib/LogFile.ts"],"names":[],"mappings":";;;;AAAA,oDAAmB;AACnB,wDAAuB;AACvB,gEAA+B;AAE/B;;;GAGG;AACH,MAAa,OAAO;IAMlB;;;OAGG;IACH,YAAY,QAAgB;QAC1B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,qBAAqB,EAAE,CAAA;IAC9B,CAAC;IAED;;;;;OAKG;IACG,MAAM,CAAC,IAAO,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,EAAE;;YACrC,MAAM,YAAE,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,GAAG,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,CAAA;QAC/F,CAAC;KAAA;IAED;;OAEG;IACH,KAAK;QACH,YAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC1B,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,MAAM,IAAI,GAAG,YAAE,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAA;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC9B,MAAM,MAAM,GAAG,EAAmB,CAAA;QAClC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;YAC3B,IAAI,CAAC,KAAK,CAAC,CAAC;gBAAE,SAAQ;YACtB,MAAM,IAAI,GAAG,QAAQ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