@static-suite/static-suite-data-server 1.0.22 → 2.0.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.
- package/README.md +1 -1
- package/dist/bin/serve.js +8 -5
- package/dist/http/README.md +1 -1
- package/dist/http/routes/diff.d.ts +2 -2
- package/dist/http/routes/diff.d.ts.map +1 -1
- package/dist/http/routes/diff.js +6 -6
- package/dist/http/routes/dump.d.ts +2 -2
- package/dist/http/routes/dump.d.ts.map +1 -1
- package/dist/http/routes/dump.js +6 -6
- package/dist/lib/dataServer.d.ts +1 -1
- package/dist/lib/dataServer.d.ts.map +1 -1
- package/dist/lib/dataServer.js +6 -6
- package/dist/lib/store/dataDir/dataDir.types.d.ts +2 -2
- package/dist/lib/store/dataDir/dataDir.types.d.ts.map +1 -1
- package/dist/lib/store/dataDir/dataDirManager.d.ts.map +1 -1
- package/dist/lib/store/dataDir/dataDirManager.js +17 -16
- package/dist/lib/store/diff/diff.types.d.ts +1 -1
- package/dist/lib/store/diff/diff.types.d.ts.map +1 -1
- package/dist/lib/store/diff/diffManager.js +2 -2
- package/dist/lib/store/dump/dump.types.d.ts +1 -1
- package/dist/lib/store/dump/dump.types.d.ts.map +1 -1
- package/dist/lib/store/dump/dumpManager.d.ts.map +1 -1
- package/dist/lib/store/dump/dumpManager.js +4 -2
- package/dist/lib/store/store.types.d.ts +2 -2
- package/dist/lib/store/store.types.d.ts.map +1 -1
- package/dist/lib/store/storeManager.js +6 -6
- package/dist/lib/tsdoc-metadata.json +1 -1
- package/dist/lib/utils/fs/fsUtils.d.ts +29 -0
- package/dist/lib/utils/fs/fsUtils.d.ts.map +1 -1
- package/dist/lib/utils/fs/fsUtils.js +70 -6
- package/dist/static-suite-data-server.d.ts +3 -3
- package/package.json +2 -2
- package/src/bin/serve.ts +20 -18
- package/src/http/routes/diff.ts +7 -7
- package/src/http/routes/dump.ts +7 -7
- package/src/lib/dataServer.ts +7 -7
- package/src/lib/store/dataDir/dataDir.types.ts +2 -2
- package/src/lib/store/dataDir/dataDirManager.ts +25 -16
- package/src/lib/store/diff/diff.types.ts +1 -1
- package/src/lib/store/diff/diffManager.ts +2 -2
- package/src/lib/store/dump/dump.types.ts +1 -1
- package/src/lib/store/dump/dumpManager.ts +4 -2
- package/src/lib/store/store.types.ts +2 -2
- package/src/lib/store/storeManager.ts +9 -9
- package/src/lib/utils/fs/fsUtils.ts +74 -1
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ const {
|
|
|
93
93
|
} = require('@static-suite/static-suite-data-server/dist/lib/');
|
|
94
94
|
|
|
95
95
|
// Init Data Server.
|
|
96
|
-
const { store } = dataServer.init({ dataDir: '../data/prod' });
|
|
96
|
+
const { store } = await dataServer.init({ dataDir: '../data/prod' });
|
|
97
97
|
|
|
98
98
|
// Loop over all articles in english.
|
|
99
99
|
store.data.subset({ dir: 'en/entity/node/article/' }).items.forEach(article => {
|
package/dist/bin/serve.js
CHANGED
|
@@ -84,7 +84,8 @@ const logFileLevel = argv['log-file-level']
|
|
|
84
84
|
? logger_types_1.LogLevel[argv['log-file-level'].toUpperCase()]
|
|
85
85
|
: logLevel;
|
|
86
86
|
// Configure data server.
|
|
87
|
-
dataServer_1.dataServer
|
|
87
|
+
dataServer_1.dataServer
|
|
88
|
+
.init({
|
|
88
89
|
logLevel,
|
|
89
90
|
logFile: argv['log-file']
|
|
90
91
|
? { path: argv['log-file'], level: logFileLevel }
|
|
@@ -96,8 +97,10 @@ dataServer_1.dataServer.init({
|
|
|
96
97
|
taskDir: argv['task-dir'],
|
|
97
98
|
dumpDir: argv['dump-dir'],
|
|
98
99
|
runMode: dataServer_types_1.RunMode[argv['run-mode'].toUpperCase()],
|
|
100
|
+
})
|
|
101
|
+
.then(() => {
|
|
102
|
+
// Start server.
|
|
103
|
+
if (argv._.includes('http')) {
|
|
104
|
+
httpServer_1.httpServer.start(argv['--port']);
|
|
105
|
+
}
|
|
99
106
|
});
|
|
100
|
-
// Start server.
|
|
101
|
-
if (argv._.includes('http')) {
|
|
102
|
-
httpServer_1.httpServer.start(argv['--port']);
|
|
103
|
-
}
|
package/dist/http/README.md
CHANGED
|
@@ -93,7 +93,7 @@ const {
|
|
|
93
93
|
} = require('@static-suite/static-suite-data-server/dist/lib/');
|
|
94
94
|
|
|
95
95
|
// Init Data Server.
|
|
96
|
-
const { store } = dataServer.init({ dataDir: '../data/prod' });
|
|
96
|
+
const { store } = await dataServer.init({ dataDir: '../data/prod' });
|
|
97
97
|
|
|
98
98
|
// Loop over all articles in english.
|
|
99
99
|
store.data.subset({ dir: 'en/entity/node/article/' }).items.forEach(article => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
2
|
declare const diffIndex: (req: Request, res: Response) => void;
|
|
3
|
-
declare const diffIncremental: (req: Request, res: Response) => void
|
|
4
|
-
declare const diffFull: (req: Request, res: Response) => void
|
|
3
|
+
declare const diffIncremental: (req: Request, res: Response) => Promise<void>;
|
|
4
|
+
declare const diffFull: (req: Request, res: Response) => Promise<void>;
|
|
5
5
|
declare const diffReset: (req: Request, res: Response) => void;
|
|
6
6
|
export { diffIndex, diffIncremental, diffFull, diffReset };
|
|
7
7
|
//# sourceMappingURL=diff.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/http/routes/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,QAAA,MAAM,SAAS,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAShD,CAAC;AAeF,QAAA,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"diff.d.ts","sourceRoot":"","sources":["../../../src/http/routes/diff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAI5C,QAAA,MAAM,SAAS,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAShD,CAAC;AAeF,QAAA,MAAM,eAAe,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAExE,CAAC;AAEF,QAAA,MAAM,QAAQ,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAEjE,CAAC;AAEF,QAAA,MAAM,SAAS,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAQhD,CAAC;AAEF,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/http/routes/diff.js
CHANGED
|
@@ -13,19 +13,19 @@ const diffIndex = (req, res) => {
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
exports.diffIndex = diffIndex;
|
|
16
|
-
const diffAction = (req, res, incremental) => {
|
|
17
|
-
const diff = diff_1.diffManager.getDiff({ incremental });
|
|
16
|
+
const diffAction = async (req, res, incremental) => {
|
|
17
|
+
const diff = await diff_1.diffManager.getDiff({ incremental });
|
|
18
18
|
const diffAsJson = (0, object_1.jsonify)(diff);
|
|
19
19
|
res.status(200);
|
|
20
20
|
res.set({ 'Content-Type': 'application/json' });
|
|
21
21
|
res.send(diffAsJson);
|
|
22
22
|
};
|
|
23
|
-
const diffIncremental = (req, res) => {
|
|
24
|
-
diffAction(req, res, true);
|
|
23
|
+
const diffIncremental = async (req, res) => {
|
|
24
|
+
await diffAction(req, res, true);
|
|
25
25
|
};
|
|
26
26
|
exports.diffIncremental = diffIncremental;
|
|
27
|
-
const diffFull = (req, res) => {
|
|
28
|
-
diffAction(req, res, false);
|
|
27
|
+
const diffFull = async (req, res) => {
|
|
28
|
+
await diffAction(req, res, false);
|
|
29
29
|
};
|
|
30
30
|
exports.diffFull = diffFull;
|
|
31
31
|
const diffReset = (req, res) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Request, Response } from 'express';
|
|
2
2
|
declare const dumpIndex: (req: Request, res: Response) => void;
|
|
3
|
-
declare const dumpIncremental: (req: Request, res: Response) => void
|
|
4
|
-
declare const dumpFull: (req: Request, res: Response) => void
|
|
3
|
+
declare const dumpIncremental: (req: Request, res: Response) => Promise<void>;
|
|
4
|
+
declare const dumpFull: (req: Request, res: Response) => Promise<void>;
|
|
5
5
|
declare const dumpMetadataShow: (req: Request, res: Response) => void;
|
|
6
6
|
declare const dumpMetadataReset: (req: Request, res: Response) => void;
|
|
7
7
|
export { dumpIndex, dumpIncremental, dumpFull, dumpMetadataShow, dumpMetadataReset, };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dump.d.ts","sourceRoot":"","sources":["../../../src/http/routes/dump.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,QAAA,MAAM,SAAS,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAShD,CAAC;AAmBF,QAAA,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"dump.d.ts","sourceRoot":"","sources":["../../../src/http/routes/dump.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,QAAA,MAAM,SAAS,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAShD,CAAC;AAmBF,QAAA,MAAM,eAAe,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAExE,CAAC;AAEF,QAAA,MAAM,QAAQ,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,OAAO,CAAC,IAAI,CAEjE,CAAC;AASF,QAAA,MAAM,gBAAgB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAIvD,CAAC;AAEF,QAAA,MAAM,iBAAiB,GAAI,KAAK,OAAO,EAAE,KAAK,QAAQ,KAAG,IAQxD,CAAC;AAEF,OAAO,EACL,SAAS,EACT,eAAe,EACf,QAAQ,EACR,gBAAgB,EAChB,iBAAiB,GAClB,CAAC"}
|
package/dist/http/routes/dump.js
CHANGED
|
@@ -19,8 +19,8 @@ const dumpIndex = (req, res) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
exports.dumpIndex = dumpIndex;
|
|
22
|
-
const dumpAction = (req, res, incremental) => {
|
|
23
|
-
const dump = dump_1.dumpManager.dump({ incremental });
|
|
22
|
+
const dumpAction = async (req, res, incremental) => {
|
|
23
|
+
const dump = await dump_1.dumpManager.dump({ incremental });
|
|
24
24
|
const dumpAsJson = (0, object_1.jsonify)(dump);
|
|
25
25
|
const args = req.query;
|
|
26
26
|
if (args?.noDiff !== undefined) {
|
|
@@ -30,12 +30,12 @@ const dumpAction = (req, res, incremental) => {
|
|
|
30
30
|
res.set({ 'Content-Type': 'application/json' });
|
|
31
31
|
res.send(dumpAsJson);
|
|
32
32
|
};
|
|
33
|
-
const dumpIncremental = (req, res) => {
|
|
34
|
-
dumpAction(req, res, true);
|
|
33
|
+
const dumpIncremental = async (req, res) => {
|
|
34
|
+
await dumpAction(req, res, true);
|
|
35
35
|
};
|
|
36
36
|
exports.dumpIncremental = dumpIncremental;
|
|
37
|
-
const dumpFull = (req, res) => {
|
|
38
|
-
dumpAction(req, res, false);
|
|
37
|
+
const dumpFull = async (req, res) => {
|
|
38
|
+
await dumpAction(req, res, false);
|
|
39
39
|
};
|
|
40
40
|
exports.dumpFull = dumpFull;
|
|
41
41
|
const getMetadata = () => {
|
package/dist/lib/dataServer.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ declare const dataServer: {
|
|
|
18
18
|
*
|
|
19
19
|
* @returns An object with the data store and the queryRunner service.
|
|
20
20
|
*/
|
|
21
|
-
init: (options: DataServerInitOptions) => DataServerReturn
|
|
21
|
+
init: (options: DataServerInitOptions) => Promise<DataServerReturn>;
|
|
22
22
|
};
|
|
23
23
|
export { dataServer, DataServerInitOptions, DataServerReturn, RunMode, LogLevel, LogFile, Store, StoreData, StoreSubset, StoreSubsetOptions, QueryRunner, QuerySuccessfulResponse, QueryErrorResponse, QueryArgs, QueryModule, QueryModuleResult, TaskRunner, CacheStatus, DataDirManager, ChangedFiles, TaskArgs, TaskSuccessfulResponse, TaskErrorResponse, AllChangesItem, };
|
|
24
24
|
//# sourceMappingURL=dataServer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataServer.d.ts","sourceRoot":"","sources":["../../src/lib/dataServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE7E,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,UAAU,EACV,QAAQ,EACR,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAG5B;;;;GAIG;AACH,QAAA,MAAM,UAAU;IACd;;;;;;OAMG;
|
|
1
|
+
{"version":3,"file":"dataServer.d.ts","sourceRoot":"","sources":["../../src/lib/dataServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AAIhE,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE7E,OAAO,EACL,KAAK,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EACnB,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EACL,UAAU,EACV,QAAQ,EACR,sBAAsB,EACtB,iBAAiB,EAClB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,OAAO,EACP,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,oBAAoB,CAAC;AAG5B;;;;GAIG;AACH,QAAA,MAAM,UAAU;IACd;;;;;;OAMG;oBACmB,qBAAqB,KAAG,OAAO,CAAC,gBAAgB,CAAC;CA+CxE,CAAC;AACF,OAAO,EACL,UAAU,EACV,qBAAqB,EACrB,gBAAgB,EAChB,OAAO,EACP,QAAQ,EACR,OAAO,EACP,KAAK,EACL,SAAS,EACT,WAAW,EACX,kBAAkB,EAClB,WAAW,EACX,uBAAuB,EACvB,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,sBAAsB,EACtB,iBAAiB,EACjB,cAAc,GACf,CAAC"}
|
package/dist/lib/dataServer.js
CHANGED
|
@@ -29,7 +29,7 @@ const dataServer = {
|
|
|
29
29
|
*
|
|
30
30
|
* @returns An object with the data store and the queryRunner service.
|
|
31
31
|
*/
|
|
32
|
-
init: (options) => {
|
|
32
|
+
init: async (options) => {
|
|
33
33
|
const startDate = Date.now();
|
|
34
34
|
// Configure logger.
|
|
35
35
|
(0, logger_1.configureLogger)(options.logLevel, options.logFile);
|
|
@@ -43,12 +43,8 @@ const dataServer = {
|
|
|
43
43
|
dumpDir: options.dumpDir,
|
|
44
44
|
runMode: options.runMode,
|
|
45
45
|
});
|
|
46
|
-
// Start watcher.
|
|
47
|
-
if (config.runMode === dataServer_types_1.RunMode.DEV) {
|
|
48
|
-
(0, watcher_1.initWatcher)();
|
|
49
|
-
}
|
|
50
46
|
// Load data from dataDir.
|
|
51
|
-
dataDir_1.dataDirManager.load();
|
|
47
|
+
await dataDir_1.dataDirManager.load();
|
|
52
48
|
// Create and load dump index.
|
|
53
49
|
if (config.dumpDir) {
|
|
54
50
|
if (dumpIndexHelper_1.dumpIndexHelper.isDumpIndexStale() ||
|
|
@@ -57,6 +53,10 @@ const dataServer = {
|
|
|
57
53
|
}
|
|
58
54
|
dumpIndexHelper_1.dumpIndexHelper.loadDumpIndex();
|
|
59
55
|
}
|
|
56
|
+
// Start watcher.
|
|
57
|
+
if (config.runMode === dataServer_types_1.RunMode.DEV) {
|
|
58
|
+
(0, watcher_1.initWatcher)();
|
|
59
|
+
}
|
|
60
60
|
logger_1.logger.info(`Data Server ${package_json_1.version} loaded in ${Date.now() - startDate}ms.`);
|
|
61
61
|
return {
|
|
62
62
|
store: store_1.store,
|
|
@@ -8,7 +8,7 @@ export type DataDirManager = {
|
|
|
8
8
|
* Loads all files inside the data directory into the store.
|
|
9
9
|
*
|
|
10
10
|
*/
|
|
11
|
-
load(): void
|
|
11
|
+
load(): Promise<void>;
|
|
12
12
|
/**
|
|
13
13
|
* Updates the store with changed files since last sync.
|
|
14
14
|
*
|
|
@@ -19,7 +19,7 @@ export type DataDirManager = {
|
|
|
19
19
|
*
|
|
20
20
|
* @returns A group of changed files in Static Suite's data dir.
|
|
21
21
|
*/
|
|
22
|
-
update(): ChangedFiles
|
|
22
|
+
update(): Promise<ChangedFiles>;
|
|
23
23
|
/**
|
|
24
24
|
* Get unique id of last modification of data directory.
|
|
25
25
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDir.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dataDir/dataDir.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,IAAI,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"dataDir.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dataDir/dataDir.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B;;;OAGG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEtB;;;;;;;;;OASG;IACH,MAAM,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAEhC;;;;;;;;;;;OAWG;IACH,uBAAuB,IAAI,MAAM,CAAC;CACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataDirManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dataDir/dataDirManager.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMjD,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"dataDirManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dataDir/dataDirManager.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAMjD,eAAO,MAAM,cAAc,EAAE,cAmI5B,CAAC"}
|
|
@@ -18,7 +18,7 @@ const task_1 = require("../../task");
|
|
|
18
18
|
const dependencyManager_1 = require("../dependency/dependencyManager");
|
|
19
19
|
let initialUniqueIdAlreadySet = false;
|
|
20
20
|
exports.dataDirManager = {
|
|
21
|
-
load: () => {
|
|
21
|
+
load: async () => {
|
|
22
22
|
logger_1.logger.info('Loading data dir...');
|
|
23
23
|
const startDate = Date.now();
|
|
24
24
|
// Reset store, just in case this load is called on an already loaded store.
|
|
@@ -39,12 +39,11 @@ exports.dataDirManager = {
|
|
|
39
39
|
}
|
|
40
40
|
store_1.store.currentUniqueId = modificationUniqueId;
|
|
41
41
|
logger_1.logger.info(`Found unique id: ${store_1.store.currentUniqueId}`);
|
|
42
|
-
// Add all files
|
|
43
|
-
const relativeFilePaths = (0, fs_1.
|
|
42
|
+
// Add all files to store.
|
|
43
|
+
const relativeFilePaths = await (0, fs_1.findFilesInDirAsync)(config_1.config.dataDir);
|
|
44
44
|
const storeHydrationStartDate = Date.now();
|
|
45
|
-
relativeFilePaths.
|
|
46
|
-
|
|
47
|
-
});
|
|
45
|
+
const addPromises = relativeFilePaths.map(relativeFilePath => storeManager_1.storeManager.add(relativeFilePath));
|
|
46
|
+
await Promise.all(addPromises);
|
|
48
47
|
logger_1.logger.debug(`Store map hydrated in ${Date.now() - storeHydrationStartDate}ms.`);
|
|
49
48
|
const includeParserStartDate = Date.now();
|
|
50
49
|
storeManager_1.storeManager.parseIncludes();
|
|
@@ -53,7 +52,7 @@ exports.dataDirManager = {
|
|
|
53
52
|
hook_1.hookManager.invokeOnStoreLoadDone();
|
|
54
53
|
logger_1.logger.info(`${relativeFilePaths.length} files loaded in ${Date.now() - startDate}ms.`);
|
|
55
54
|
},
|
|
56
|
-
update: () => {
|
|
55
|
+
update: async () => {
|
|
57
56
|
const dataDirModificationUniqueId = exports.dataDirManager.getModificationUniqueId();
|
|
58
57
|
let changedFiles = {
|
|
59
58
|
all: [],
|
|
@@ -74,15 +73,17 @@ exports.dataDirManager = {
|
|
|
74
73
|
dependencyManager_1.dependencyManager.trackInvalidatedFilepaths();
|
|
75
74
|
changedFiles = workDir_1.workDirHelper.getChangedFilesBetween(storeLastUniqueId, dataDirModificationUniqueId);
|
|
76
75
|
hook_1.hookManager.invokeOnStoreChangeStart(changedFiles);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
// First, remove all deleted files
|
|
77
|
+
changedFiles.deleted.forEach(deletedFile => {
|
|
78
|
+
storeManager_1.storeManager.remove(deletedFile);
|
|
79
|
+
});
|
|
80
|
+
// Second, update all updated files
|
|
81
|
+
const updatePromises = changedFiles.updated.map(updatedFile => storeManager_1.storeManager.update(updatedFile));
|
|
82
|
+
await Promise.all(updatePromises);
|
|
83
|
+
// Finally, parse includes from updated files
|
|
84
|
+
changedFiles.updated.forEach(updatedFile => {
|
|
85
|
+
const fileContent = store_1.store.data.get(updatedFile);
|
|
86
|
+
storeManager_1.storeManager.parseSingleFileIncludes(updatedFile, fileContent);
|
|
86
87
|
});
|
|
87
88
|
// Clear all store subsets and queries, since they are stale.
|
|
88
89
|
// In fact, the subset cache should be cleared only when files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diff.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/diff/diff.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"diff.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/diff/diff.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAE9B;;;;;;;;;;;;;;;;;OAiBG;IACH,OAAO,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC"}
|
|
@@ -17,10 +17,10 @@ exports.diffManager = {
|
|
|
17
17
|
lastDiffUniqueId = uniqueId;
|
|
18
18
|
dependencyManager_1.dependencyManager.reset();
|
|
19
19
|
},
|
|
20
|
-
getDiff(options = { incremental: true }) {
|
|
20
|
+
async getDiff(options = { incremental: true }) {
|
|
21
21
|
const startDate = microtime_1.default.now();
|
|
22
22
|
// Before getting any diff data, update any pending changes from data dir.
|
|
23
|
-
const changedFiles = dataDirManager_1.dataDirManager.update();
|
|
23
|
+
const changedFiles = await dataDirManager_1.dataDirManager.update();
|
|
24
24
|
const updated = new Set();
|
|
25
25
|
const deleted = new Set();
|
|
26
26
|
const currentDumpUniqueId = dumpMetadataHelper_1.dumpMetadataHelper.getCurrentDumpUniqueId();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dump.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dump/dump.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"dump.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dump/dump.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE1C;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE;QAAE,WAAW,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAExD;;;;;;;OAOG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;OAIG;IACH,OAAO,EAAE,GAAG,CACV,MAAM,EACN;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,CAC7D,CAAC;IAEF;;;;;OAKG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE;QAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,YAAY,EAAE,IAAI,CAAA;KAAE,CAAC,CAAC;IAE1E;;OAEG;IACH,IAAI,EAAE,IAAI,CAAC;CACZ,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,IAAI,EAAE,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CACpB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dumpManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dump/dumpManager.ts"],"names":[],"mappings":"AASA,OAAO,EAAQ,WAAW,EAAE,MAAM,cAAc,CAAC;AAqKjD,eAAO,MAAM,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"dumpManager.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/dump/dumpManager.ts"],"names":[],"mappings":"AASA,OAAO,EAAQ,WAAW,EAAE,MAAM,cAAc,CAAC;AAqKjD,eAAO,MAAM,WAAW,EAAE,WA+EzB,CAAC"}
|
|
@@ -142,10 +142,12 @@ const removeStaleFiles = (diff, dump, filesDumpDir) => {
|
|
|
142
142
|
}
|
|
143
143
|
};
|
|
144
144
|
exports.dumpManager = {
|
|
145
|
-
dump(options = { incremental: true }) {
|
|
145
|
+
async dump(options = { incremental: true }) {
|
|
146
146
|
const startDate = microtime_1.default.now();
|
|
147
147
|
// Diff data is processed and transformed into a dump object.
|
|
148
|
-
const diff = diffManager_1.diffManager.getDiff({
|
|
148
|
+
const diff = await diffManager_1.diffManager.getDiff({
|
|
149
|
+
incremental: options.incremental,
|
|
150
|
+
});
|
|
149
151
|
let dump = {
|
|
150
152
|
execTimeMs: 0,
|
|
151
153
|
fromUniqueId: diff.fromUniqueId,
|
|
@@ -163,7 +163,7 @@ export type StoreManager = {
|
|
|
163
163
|
*
|
|
164
164
|
* @returns The store manager, to allow chaining.
|
|
165
165
|
*/
|
|
166
|
-
add(relativeFilepath: string): StoreManager
|
|
166
|
+
add(relativeFilepath: string): Promise<StoreManager>;
|
|
167
167
|
/**
|
|
168
168
|
* Removes a file from the store.
|
|
169
169
|
*
|
|
@@ -186,7 +186,7 @@ export type StoreManager = {
|
|
|
186
186
|
*
|
|
187
187
|
* @returns The store manager, to allow chaining.
|
|
188
188
|
*/
|
|
189
|
-
update(file: string): StoreManager
|
|
189
|
+
update(file: string): Promise<StoreManager>;
|
|
190
190
|
/**
|
|
191
191
|
* Parses all static and dynamic includes (entity, config, locale, custom and query)
|
|
192
192
|
* from data stored in "store.data".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.types.d.ts","sourceRoot":"","sources":["../../../src/lib/store/store.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAAC;CAClD;AAED;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEtB;;WAEG;QACH,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;;;OASG;IACH,GAAG,CAAC,gBAAgB,EAAE,MAAM,GAAG,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"store.types.d.ts","sourceRoot":"","sources":["../../../src/lib/store/store.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAChD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,MAAM,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAAC;CAClD;AAED;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG;IAClB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,IAAI,EAAE,SAAS,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE7B;;OAEG;IACH,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE;QACL;;WAEG;QACH,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEtB;;WAEG;QACH,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAEvB;;WAEG;QACH,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC1B,CAAC;CACH,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAExB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAEtB;;OAEG;IACH,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAEzB;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;;;;;;;;OASG;IACH,GAAG,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAErD;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IAEnC;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,aAAa,IAAI,YAAY,CAAC;IAE9B;;;;;;;;OAQG;IACH,uBAAuB,CACrB,gBAAgB,EAAE,MAAM,EACxB,WAAW,EAAE,GAAG,GACf,YAAY,CAAC;IAEhB;;;;OAIG;IACH,KAAK,IAAI,YAAY,CAAC;CACvB,CAAC"}
|
|
@@ -17,9 +17,9 @@ const dependencyTagger_1 = require("./dependency/dependencyTagger");
|
|
|
17
17
|
* fileContent: the contents of the stored file
|
|
18
18
|
* previousStoredData: the contents of the previously stored file
|
|
19
19
|
*/
|
|
20
|
-
const setFileIntoStore = (relativeFilepath) => {
|
|
20
|
+
const setFileIntoStore = async (relativeFilepath) => {
|
|
21
21
|
const absoluteFilePath = `${config_1.config.dataDir}/${relativeFilepath}`;
|
|
22
|
-
let fileContent = (0, fs_1.
|
|
22
|
+
let fileContent = await (0, fs_1.getFileContentAsync)(absoluteFilePath);
|
|
23
23
|
// Invoke "process file" hook.
|
|
24
24
|
fileContent = hook_1.hookManager.invokeOnProcessFile({
|
|
25
25
|
relativeFilepath,
|
|
@@ -103,8 +103,8 @@ const setFileIntoStore = (relativeFilepath) => {
|
|
|
103
103
|
return { fileContent: dataToStore, previousStoredData };
|
|
104
104
|
};
|
|
105
105
|
exports.storeManager = {
|
|
106
|
-
add: (relativeFilepath) => {
|
|
107
|
-
const { fileContent } = setFileIntoStore(relativeFilepath);
|
|
106
|
+
add: async (relativeFilepath) => {
|
|
107
|
+
const { fileContent } = await setFileIntoStore(relativeFilepath);
|
|
108
108
|
// Invoke "store add" hook.
|
|
109
109
|
hook_1.hookManager.invokeOnStoreItemAdd({
|
|
110
110
|
relativeFilepath,
|
|
@@ -112,7 +112,7 @@ exports.storeManager = {
|
|
|
112
112
|
});
|
|
113
113
|
return exports.storeManager;
|
|
114
114
|
},
|
|
115
|
-
update: (relativeFilepath) => {
|
|
115
|
+
update: async (relativeFilepath) => {
|
|
116
116
|
const storedData = _1.store.data.get(relativeFilepath);
|
|
117
117
|
if (storedData) {
|
|
118
118
|
hook_1.hookManager.invokeOnStoreItemBeforeUpdate({
|
|
@@ -120,7 +120,7 @@ exports.storeManager = {
|
|
|
120
120
|
storeItem: storedData,
|
|
121
121
|
});
|
|
122
122
|
}
|
|
123
|
-
const { fileContent, previousStoredData } = setFileIntoStore(relativeFilepath);
|
|
123
|
+
const { fileContent, previousStoredData } = await setFileIntoStore(relativeFilepath);
|
|
124
124
|
// Invalidate this item.
|
|
125
125
|
dependencyTagger_1.dependencyTagger.invalidateTags([relativeFilepath]);
|
|
126
126
|
// Invoke "store update" hook.
|
|
@@ -18,6 +18,14 @@ export declare const isJsonFile: (filepath: string) => boolean;
|
|
|
18
18
|
* @returns The file contents as a string if file is found, or null otherwise.
|
|
19
19
|
*/
|
|
20
20
|
export declare const readFile: (filePath: string) => string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Asynchronously reads a file and logs an error on failure.
|
|
23
|
+
*
|
|
24
|
+
* @param filePath - A path to a file.
|
|
25
|
+
*
|
|
26
|
+
* @returns The file contents as a string if file is found, or null otherwise.
|
|
27
|
+
*/
|
|
28
|
+
export declare const readFileAsync: (filePath: string) => Promise<string | null>;
|
|
21
29
|
/**
|
|
22
30
|
* Gets raw and JSON parsed content from a file.
|
|
23
31
|
*
|
|
@@ -28,6 +36,16 @@ export declare const readFile: (filePath: string) => string | null;
|
|
|
28
36
|
* property is null. If file is not found, both properties are null.
|
|
29
37
|
*/
|
|
30
38
|
export declare const getFileContent: (filepath: string) => FileType;
|
|
39
|
+
/**
|
|
40
|
+
* Asynchronously gets raw and JSON parsed content from a file.
|
|
41
|
+
*
|
|
42
|
+
* @param filepath - A path to a file.
|
|
43
|
+
*
|
|
44
|
+
* @returns Object with two properties, "raw" and "json", which contain
|
|
45
|
+
* the raw and json version of the file. If file is not a JSON, the "json"
|
|
46
|
+
* property is null. If file is not found, both properties are null.
|
|
47
|
+
*/
|
|
48
|
+
export declare const getFileContentAsync: (filepath: string) => Promise<FileType>;
|
|
31
49
|
/**
|
|
32
50
|
* Finds all files inside a directory
|
|
33
51
|
*
|
|
@@ -39,6 +57,17 @@ export declare const getFileContent: (filepath: string) => FileType;
|
|
|
39
57
|
* @returns Array of file paths found inside directory
|
|
40
58
|
*/
|
|
41
59
|
export declare const findFilesInDir: (dir: string, glob?: string, options?: fastGlobOptions) => string[];
|
|
60
|
+
/**
|
|
61
|
+
* Asynchronously finds all files inside a directory
|
|
62
|
+
*
|
|
63
|
+
* @param dir - Absolute path to the directory to be scanned
|
|
64
|
+
* @param glob - Optional glob to filter results (default all files recursive '**\/*')
|
|
65
|
+
* @param options - Options for the fast-glob package.
|
|
66
|
+
* See https://www.npmjs.com/package/fast-glob for reference .
|
|
67
|
+
*
|
|
68
|
+
* @returns Array of file paths found inside directory
|
|
69
|
+
*/
|
|
70
|
+
export declare const findFilesInDirAsync: (dir: string, glob?: string, options?: fastGlobOptions) => Promise<string[]>;
|
|
42
71
|
/**
|
|
43
72
|
* Gets a file's modification date and logs an error on failure.
|
|
44
73
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fsUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/fs/fsUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fsUtils.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/fs/fsUtils.ts"],"names":[],"mappings":"AAGA,OAAW,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AAG3D,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC;;;;;;;;GAQG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,MAAM,KAAG,OACd,CAAC;AAEjC;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,GAAI,UAAU,MAAM,KAAG,MAAM,GAAG,IAWpD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,GACxB,UAAU,MAAM,KACf,OAAO,CAAC,MAAM,GAAG,IAAI,CAcvB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,UAAU,MAAM,KAAG,QAUjD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,mBAAmB,GAC9B,UAAU,MAAM,KACf,OAAO,CAAC,QAAQ,CAUlB,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GACzB,KAAK,MAAM,EACX,aAAa,EACb,UAAS,eAAqC,KAC7C,MAAM,EAQR,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,MAAM,EACX,aAAa,EACb,UAAS,eAAqC,KAC7C,OAAO,CAAC,MAAM,EAAE,CAQlB,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,UAAU,MAAM,KAAG,IAAI,GAAG,IAQ7D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,KAAK,MAAM,KAAG,IAUpD,CAAC"}
|
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.removeEmptyDirsUpwards = exports.getModificationDate = exports.findFilesInDir = exports.getFileContent = exports.readFile = exports.isJsonFile = void 0;
|
|
7
|
-
const
|
|
6
|
+
exports.removeEmptyDirsUpwards = exports.getModificationDate = exports.findFilesInDirAsync = exports.findFilesInDir = exports.getFileContentAsync = exports.getFileContent = exports.readFileAsync = exports.readFile = exports.isJsonFile = void 0;
|
|
7
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
10
11
|
const logger_1 = require("../logger");
|
|
@@ -30,7 +31,7 @@ exports.isJsonFile = isJsonFile;
|
|
|
30
31
|
const readFile = (filePath) => {
|
|
31
32
|
let content;
|
|
32
33
|
try {
|
|
33
|
-
content =
|
|
34
|
+
content = node_fs_1.default.readFileSync(filePath, { encoding: 'utf8', flag: 'r' });
|
|
34
35
|
}
|
|
35
36
|
catch (error) {
|
|
36
37
|
// When an error is thrown, content is undefined, so ensure
|
|
@@ -41,6 +42,30 @@ const readFile = (filePath) => {
|
|
|
41
42
|
return content;
|
|
42
43
|
};
|
|
43
44
|
exports.readFile = readFile;
|
|
45
|
+
/**
|
|
46
|
+
* Asynchronously reads a file and logs an error on failure.
|
|
47
|
+
*
|
|
48
|
+
* @param filePath - A path to a file.
|
|
49
|
+
*
|
|
50
|
+
* @returns The file contents as a string if file is found, or null otherwise.
|
|
51
|
+
*/
|
|
52
|
+
const readFileAsync = async (filePath) => {
|
|
53
|
+
let content;
|
|
54
|
+
try {
|
|
55
|
+
content = await promises_1.default.readFile(filePath, {
|
|
56
|
+
encoding: 'utf8',
|
|
57
|
+
flag: 'r',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
// When an error is thrown, content is undefined, so ensure
|
|
62
|
+
// it is converted to null.
|
|
63
|
+
content = null;
|
|
64
|
+
logger_1.logger.error(`Error reading file "${filePath}": ${error}`);
|
|
65
|
+
}
|
|
66
|
+
return content;
|
|
67
|
+
};
|
|
68
|
+
exports.readFileAsync = readFileAsync;
|
|
44
69
|
/**
|
|
45
70
|
* Gets raw and JSON parsed content from a file.
|
|
46
71
|
*
|
|
@@ -62,6 +87,27 @@ const getFileContent = (filepath) => {
|
|
|
62
87
|
return { raw, json };
|
|
63
88
|
};
|
|
64
89
|
exports.getFileContent = getFileContent;
|
|
90
|
+
/**
|
|
91
|
+
* Asynchronously gets raw and JSON parsed content from a file.
|
|
92
|
+
*
|
|
93
|
+
* @param filepath - A path to a file.
|
|
94
|
+
*
|
|
95
|
+
* @returns Object with two properties, "raw" and "json", which contain
|
|
96
|
+
* the raw and json version of the file. If file is not a JSON, the "json"
|
|
97
|
+
* property is null. If file is not found, both properties are null.
|
|
98
|
+
*/
|
|
99
|
+
const getFileContentAsync = async (filepath) => {
|
|
100
|
+
const raw = await (0, exports.readFileAsync)(filepath);
|
|
101
|
+
let json = null;
|
|
102
|
+
if (raw && (0, exports.isJsonFile)(filepath)) {
|
|
103
|
+
json = (0, string_1.parseJsonString)(raw);
|
|
104
|
+
if (!json) {
|
|
105
|
+
logger_1.logger.error(`Error getting JSON from file "${filepath}"`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return { raw, json };
|
|
109
|
+
};
|
|
110
|
+
exports.getFileContentAsync = getFileContentAsync;
|
|
65
111
|
/**
|
|
66
112
|
* Finds all files inside a directory
|
|
67
113
|
*
|
|
@@ -80,6 +126,24 @@ const findFilesInDir = (dir, glob = '**/*', options = { absolute: false }) => {
|
|
|
80
126
|
return files;
|
|
81
127
|
};
|
|
82
128
|
exports.findFilesInDir = findFilesInDir;
|
|
129
|
+
/**
|
|
130
|
+
* Asynchronously finds all files inside a directory
|
|
131
|
+
*
|
|
132
|
+
* @param dir - Absolute path to the directory to be scanned
|
|
133
|
+
* @param glob - Optional glob to filter results (default all files recursive '**\/*')
|
|
134
|
+
* @param options - Options for the fast-glob package.
|
|
135
|
+
* See https://www.npmjs.com/package/fast-glob for reference .
|
|
136
|
+
*
|
|
137
|
+
* @returns Array of file paths found inside directory
|
|
138
|
+
*/
|
|
139
|
+
const findFilesInDirAsync = async (dir, glob = '**/*', options = { absolute: false }) => {
|
|
140
|
+
const startDate = Date.now();
|
|
141
|
+
const files = await (0, fast_glob_1.default)([glob], { cwd: dir, ...options });
|
|
142
|
+
const endDate = Date.now();
|
|
143
|
+
logger_1.logger.debug(`ASYNC ${files.length} files found inside ${dir} in ${endDate - startDate}ms.`);
|
|
144
|
+
return files;
|
|
145
|
+
};
|
|
146
|
+
exports.findFilesInDirAsync = findFilesInDirAsync;
|
|
83
147
|
/**
|
|
84
148
|
* Gets a file's modification date and logs an error on failure.
|
|
85
149
|
*
|
|
@@ -90,7 +154,7 @@ exports.findFilesInDir = findFilesInDir;
|
|
|
90
154
|
const getModificationDate = (filePath) => {
|
|
91
155
|
let modificationDate = null;
|
|
92
156
|
try {
|
|
93
|
-
modificationDate = new Date(
|
|
157
|
+
modificationDate = new Date(node_fs_1.default.statSync(filePath).mtime);
|
|
94
158
|
}
|
|
95
159
|
catch (e) {
|
|
96
160
|
logger_1.logger.error(`Error getting modification date for ${`path`}: ${e}`);
|
|
@@ -104,10 +168,10 @@ exports.getModificationDate = getModificationDate;
|
|
|
104
168
|
* @param dir - Path to a directory
|
|
105
169
|
*/
|
|
106
170
|
const removeEmptyDirsUpwards = (dir) => {
|
|
107
|
-
const isEmpty =
|
|
171
|
+
const isEmpty = node_fs_1.default.readdirSync(dir).length === 0;
|
|
108
172
|
if (isEmpty) {
|
|
109
173
|
try {
|
|
110
|
-
|
|
174
|
+
node_fs_1.default.rmdirSync(dir);
|
|
111
175
|
}
|
|
112
176
|
catch (e) {
|
|
113
177
|
logger_1.logger.debug(`Error deleting empty directory "${dir}": ${e}`);
|
|
@@ -53,7 +53,7 @@ export declare type DataDirManager = {
|
|
|
53
53
|
* Loads all files inside the data directory into the store.
|
|
54
54
|
*
|
|
55
55
|
*/
|
|
56
|
-
load(): void
|
|
56
|
+
load(): Promise<void>;
|
|
57
57
|
/**
|
|
58
58
|
* Updates the store with changed files since last sync.
|
|
59
59
|
*
|
|
@@ -64,7 +64,7 @@ export declare type DataDirManager = {
|
|
|
64
64
|
*
|
|
65
65
|
* @returns A group of changed files in Static Suite's data dir.
|
|
66
66
|
*/
|
|
67
|
-
update(): ChangedFiles
|
|
67
|
+
update(): Promise<ChangedFiles>;
|
|
68
68
|
/**
|
|
69
69
|
* Get unique id of last modification of data directory.
|
|
70
70
|
*
|
|
@@ -93,7 +93,7 @@ export declare const dataServer: {
|
|
|
93
93
|
*
|
|
94
94
|
* @returns An object with the data store and the queryRunner service.
|
|
95
95
|
*/
|
|
96
|
-
init: (options: DataServerInitOptions) => DataServerReturn
|
|
96
|
+
init: (options: DataServerInitOptions) => Promise<DataServerReturn>;
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@static-suite/static-suite-data-server",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A flexible, fast and developer friendly Data Server for Static Suite",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"typings": "./dist/lib/index.d.ts",
|
|
@@ -86,4 +86,4 @@
|
|
|
86
86
|
]
|
|
87
87
|
},
|
|
88
88
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
89
|
-
}
|
|
89
|
+
}
|
package/src/bin/serve.ts
CHANGED
|
@@ -86,21 +86,23 @@ const logFileLevel = argv['log-file-level']
|
|
|
86
86
|
: logLevel;
|
|
87
87
|
|
|
88
88
|
// Configure data server.
|
|
89
|
-
dataServer
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
89
|
+
dataServer
|
|
90
|
+
.init({
|
|
91
|
+
logLevel,
|
|
92
|
+
logFile: argv['log-file']
|
|
93
|
+
? { path: argv['log-file'], level: logFileLevel }
|
|
94
|
+
: undefined,
|
|
95
|
+
dataDir: argv['data-dir'],
|
|
96
|
+
workDir: argv['work-dir'],
|
|
97
|
+
queryDir: argv['query-dir'],
|
|
98
|
+
hookDir: argv['hook-dir'],
|
|
99
|
+
taskDir: argv['task-dir'],
|
|
100
|
+
dumpDir: argv['dump-dir'],
|
|
101
|
+
runMode: RunMode[argv['run-mode'].toUpperCase() as RunModeStrings],
|
|
102
|
+
})
|
|
103
|
+
.then(() => {
|
|
104
|
+
// Start server.
|
|
105
|
+
if (argv._.includes('http')) {
|
|
106
|
+
httpServer.start(argv['--port']);
|
|
107
|
+
}
|
|
108
|
+
});
|
package/src/http/routes/diff.ts
CHANGED
|
@@ -13,12 +13,12 @@ const diffIndex = (req: Request, res: Response): void => {
|
|
|
13
13
|
});
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
const diffAction = (
|
|
16
|
+
const diffAction = async (
|
|
17
17
|
req: Request,
|
|
18
18
|
res: Response,
|
|
19
19
|
incremental: boolean,
|
|
20
|
-
): void => {
|
|
21
|
-
const diff = diffManager.getDiff({ incremental });
|
|
20
|
+
): Promise<void> => {
|
|
21
|
+
const diff = await diffManager.getDiff({ incremental });
|
|
22
22
|
const diffAsJson: any = jsonify(diff);
|
|
23
23
|
|
|
24
24
|
res.status(200);
|
|
@@ -26,12 +26,12 @@ const diffAction = (
|
|
|
26
26
|
res.send(diffAsJson);
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
const diffIncremental = (req: Request, res: Response): void => {
|
|
30
|
-
diffAction(req, res, true);
|
|
29
|
+
const diffIncremental = async (req: Request, res: Response): Promise<void> => {
|
|
30
|
+
await diffAction(req, res, true);
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
const diffFull = (req: Request, res: Response): void => {
|
|
34
|
-
diffAction(req, res, false);
|
|
33
|
+
const diffFull = async (req: Request, res: Response): Promise<void> => {
|
|
34
|
+
await diffAction(req, res, false);
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const diffReset = (req: Request, res: Response): void => {
|
package/src/http/routes/dump.ts
CHANGED
|
@@ -15,12 +15,12 @@ const dumpIndex = (req: Request, res: Response): void => {
|
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
const dumpAction = (
|
|
18
|
+
const dumpAction = async (
|
|
19
19
|
req: Request,
|
|
20
20
|
res: Response,
|
|
21
21
|
incremental: boolean,
|
|
22
|
-
): void => {
|
|
23
|
-
const dump = dumpManager.dump({ incremental });
|
|
22
|
+
): Promise<void> => {
|
|
23
|
+
const dump = await dumpManager.dump({ incremental });
|
|
24
24
|
const dumpAsJson: any = jsonify(dump);
|
|
25
25
|
const args: any = req.query;
|
|
26
26
|
if (args?.noDiff !== undefined) {
|
|
@@ -32,12 +32,12 @@ const dumpAction = (
|
|
|
32
32
|
res.send(dumpAsJson);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
const dumpIncremental = (req: Request, res: Response): void => {
|
|
36
|
-
dumpAction(req, res, true);
|
|
35
|
+
const dumpIncremental = async (req: Request, res: Response): Promise<void> => {
|
|
36
|
+
await dumpAction(req, res, true);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
const dumpFull = (req: Request, res: Response): void => {
|
|
40
|
-
dumpAction(req, res, false);
|
|
39
|
+
const dumpFull = async (req: Request, res: Response): Promise<void> => {
|
|
40
|
+
await dumpAction(req, res, false);
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
const getMetadata = () => {
|
package/src/lib/dataServer.ts
CHANGED
|
@@ -50,7 +50,7 @@ const dataServer = {
|
|
|
50
50
|
*
|
|
51
51
|
* @returns An object with the data store and the queryRunner service.
|
|
52
52
|
*/
|
|
53
|
-
init: (options: DataServerInitOptions): DataServerReturn => {
|
|
53
|
+
init: async (options: DataServerInitOptions): Promise<DataServerReturn> => {
|
|
54
54
|
const startDate = Date.now();
|
|
55
55
|
|
|
56
56
|
// Configure logger.
|
|
@@ -67,13 +67,8 @@ const dataServer = {
|
|
|
67
67
|
runMode: options.runMode,
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
// Start watcher.
|
|
71
|
-
if (config.runMode === RunMode.DEV) {
|
|
72
|
-
initWatcher();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
70
|
// Load data from dataDir.
|
|
76
|
-
dataDirManager.load();
|
|
71
|
+
await dataDirManager.load();
|
|
77
72
|
|
|
78
73
|
// Create and load dump index.
|
|
79
74
|
if (config.dumpDir) {
|
|
@@ -86,6 +81,11 @@ const dataServer = {
|
|
|
86
81
|
dumpIndexHelper.loadDumpIndex();
|
|
87
82
|
}
|
|
88
83
|
|
|
84
|
+
// Start watcher.
|
|
85
|
+
if (config.runMode === RunMode.DEV) {
|
|
86
|
+
initWatcher();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
89
|
logger.info(
|
|
90
90
|
`Data Server ${version} loaded in ${Date.now() - startDate}ms.`,
|
|
91
91
|
);
|
|
@@ -9,7 +9,7 @@ export type DataDirManager = {
|
|
|
9
9
|
* Loads all files inside the data directory into the store.
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
load(): void
|
|
12
|
+
load(): Promise<void>;
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Updates the store with changed files since last sync.
|
|
@@ -21,7 +21,7 @@ export type DataDirManager = {
|
|
|
21
21
|
*
|
|
22
22
|
* @returns A group of changed files in Static Suite's data dir.
|
|
23
23
|
*/
|
|
24
|
-
update(): ChangedFiles
|
|
24
|
+
update(): Promise<ChangedFiles>;
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* Get unique id of last modification of data directory.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import microtime from 'microtime';
|
|
2
2
|
import { config } from '../../config';
|
|
3
3
|
import { store } from '../store';
|
|
4
|
-
import {
|
|
4
|
+
import { findFilesInDirAsync } from '../../utils/fs';
|
|
5
5
|
import { logger } from '../../utils/logger';
|
|
6
6
|
import { unixEpochUniqueId, workDirHelper } from '../workDir';
|
|
7
7
|
import { cache } from '../../utils/cache';
|
|
@@ -16,7 +16,7 @@ import { dependencyManager } from '../dependency/dependencyManager';
|
|
|
16
16
|
let initialUniqueIdAlreadySet = false;
|
|
17
17
|
|
|
18
18
|
export const dataDirManager: DataDirManager = {
|
|
19
|
-
load: () => {
|
|
19
|
+
load: async () => {
|
|
20
20
|
logger.info('Loading data dir...');
|
|
21
21
|
const startDate = Date.now();
|
|
22
22
|
|
|
@@ -43,12 +43,13 @@ export const dataDirManager: DataDirManager = {
|
|
|
43
43
|
store.currentUniqueId = modificationUniqueId;
|
|
44
44
|
logger.info(`Found unique id: ${store.currentUniqueId}`);
|
|
45
45
|
|
|
46
|
-
// Add all files
|
|
47
|
-
const relativeFilePaths =
|
|
46
|
+
// Add all files to store.
|
|
47
|
+
const relativeFilePaths = await findFilesInDirAsync(config.dataDir);
|
|
48
48
|
const storeHydrationStartDate = Date.now();
|
|
49
|
-
relativeFilePaths.
|
|
50
|
-
storeManager.add(relativeFilePath)
|
|
51
|
-
|
|
49
|
+
const addPromises = relativeFilePaths.map(relativeFilePath =>
|
|
50
|
+
storeManager.add(relativeFilePath),
|
|
51
|
+
);
|
|
52
|
+
await Promise.all(addPromises);
|
|
52
53
|
|
|
53
54
|
logger.debug(
|
|
54
55
|
`Store map hydrated in ${Date.now() - storeHydrationStartDate}ms.`,
|
|
@@ -70,7 +71,7 @@ export const dataDirManager: DataDirManager = {
|
|
|
70
71
|
);
|
|
71
72
|
},
|
|
72
73
|
|
|
73
|
-
update: () => {
|
|
74
|
+
update: async () => {
|
|
74
75
|
const dataDirModificationUniqueId =
|
|
75
76
|
dataDirManager.getModificationUniqueId();
|
|
76
77
|
|
|
@@ -101,14 +102,22 @@ export const dataDirManager: DataDirManager = {
|
|
|
101
102
|
dataDirModificationUniqueId,
|
|
102
103
|
);
|
|
103
104
|
hookManager.invokeOnStoreChangeStart(changedFiles);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
105
|
+
|
|
106
|
+
// First, remove all deleted files
|
|
107
|
+
changedFiles.deleted.forEach(deletedFile => {
|
|
108
|
+
storeManager.remove(deletedFile);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// Second, update all updated files
|
|
112
|
+
const updatePromises = changedFiles.updated.map(updatedFile =>
|
|
113
|
+
storeManager.update(updatedFile),
|
|
114
|
+
);
|
|
115
|
+
await Promise.all(updatePromises);
|
|
116
|
+
|
|
117
|
+
// Finally, parse includes from updated files
|
|
118
|
+
changedFiles.updated.forEach(updatedFile => {
|
|
119
|
+
const fileContent = store.data.get(updatedFile);
|
|
120
|
+
storeManager.parseSingleFileIncludes(updatedFile, fileContent);
|
|
112
121
|
});
|
|
113
122
|
|
|
114
123
|
// Clear all store subsets and queries, since they are stale.
|
|
@@ -15,11 +15,11 @@ export const diffManager: DiffManager = {
|
|
|
15
15
|
dependencyManager.reset();
|
|
16
16
|
},
|
|
17
17
|
|
|
18
|
-
getDiff(options = { incremental: true }): Diff {
|
|
18
|
+
async getDiff(options = { incremental: true }): Promise<Diff> {
|
|
19
19
|
const startDate = microtime.now();
|
|
20
20
|
|
|
21
21
|
// Before getting any diff data, update any pending changes from data dir.
|
|
22
|
-
const changedFiles = dataDirManager.update();
|
|
22
|
+
const changedFiles = await dataDirManager.update();
|
|
23
23
|
|
|
24
24
|
const updated = new Set<string>();
|
|
25
25
|
const deleted = new Set<string>();
|
|
@@ -173,11 +173,13 @@ const removeStaleFiles = (
|
|
|
173
173
|
};
|
|
174
174
|
|
|
175
175
|
export const dumpManager: DumpManager = {
|
|
176
|
-
dump(options = { incremental: true }): Dump {
|
|
176
|
+
async dump(options = { incremental: true }): Promise<Dump> {
|
|
177
177
|
const startDate = microtime.now();
|
|
178
178
|
|
|
179
179
|
// Diff data is processed and transformed into a dump object.
|
|
180
|
-
const diff = diffManager.getDiff({
|
|
180
|
+
const diff = await diffManager.getDiff({
|
|
181
|
+
incremental: options.incremental,
|
|
182
|
+
});
|
|
181
183
|
let dump: Dump = {
|
|
182
184
|
execTimeMs: 0,
|
|
183
185
|
fromUniqueId: diff.fromUniqueId,
|
|
@@ -178,7 +178,7 @@ export type StoreManager = {
|
|
|
178
178
|
*
|
|
179
179
|
* @returns The store manager, to allow chaining.
|
|
180
180
|
*/
|
|
181
|
-
add(relativeFilepath: string): StoreManager
|
|
181
|
+
add(relativeFilepath: string): Promise<StoreManager>;
|
|
182
182
|
|
|
183
183
|
/**
|
|
184
184
|
* Removes a file from the store.
|
|
@@ -203,7 +203,7 @@ export type StoreManager = {
|
|
|
203
203
|
*
|
|
204
204
|
* @returns The store manager, to allow chaining.
|
|
205
205
|
*/
|
|
206
|
-
update(file: string): StoreManager
|
|
206
|
+
update(file: string): Promise<StoreManager>;
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* Parses all static and dynamic includes (entity, config, locale, custom and query)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { config } from '../config';
|
|
2
|
-
import {
|
|
2
|
+
import { getFileContentAsync } from '../utils/fs';
|
|
3
3
|
import { Json } from '../utils/object/object.types';
|
|
4
4
|
import { StoreManager } from './store.types';
|
|
5
5
|
import { hookManager } from './hook';
|
|
@@ -17,14 +17,14 @@ import { dependencyTagger } from './dependency/dependencyTagger';
|
|
|
17
17
|
* fileContent: the contents of the stored file
|
|
18
18
|
* previousStoredData: the contents of the previously stored file
|
|
19
19
|
*/
|
|
20
|
-
const setFileIntoStore = (
|
|
20
|
+
const setFileIntoStore = async (
|
|
21
21
|
relativeFilepath: string,
|
|
22
|
-
): {
|
|
22
|
+
): Promise<{
|
|
23
23
|
fileContent: Json | string | null;
|
|
24
24
|
previousStoredData: Json | null;
|
|
25
|
-
} => {
|
|
25
|
+
}> => {
|
|
26
26
|
const absoluteFilePath = `${config.dataDir}/${relativeFilepath}`;
|
|
27
|
-
let fileContent =
|
|
27
|
+
let fileContent = await getFileContentAsync(absoluteFilePath);
|
|
28
28
|
|
|
29
29
|
// Invoke "process file" hook.
|
|
30
30
|
fileContent = hookManager.invokeOnProcessFile({
|
|
@@ -130,8 +130,8 @@ const setFileIntoStore = (
|
|
|
130
130
|
};
|
|
131
131
|
|
|
132
132
|
export const storeManager: StoreManager = {
|
|
133
|
-
add: (relativeFilepath: string): StoreManager => {
|
|
134
|
-
const { fileContent } = setFileIntoStore(relativeFilepath);
|
|
133
|
+
add: async (relativeFilepath: string): Promise<StoreManager> => {
|
|
134
|
+
const { fileContent } = await setFileIntoStore(relativeFilepath);
|
|
135
135
|
|
|
136
136
|
// Invoke "store add" hook.
|
|
137
137
|
hookManager.invokeOnStoreItemAdd({
|
|
@@ -142,7 +142,7 @@ export const storeManager: StoreManager = {
|
|
|
142
142
|
return storeManager;
|
|
143
143
|
},
|
|
144
144
|
|
|
145
|
-
update: (relativeFilepath: string): StoreManager => {
|
|
145
|
+
update: async (relativeFilepath: string): Promise<StoreManager> => {
|
|
146
146
|
const storedData = store.data.get(relativeFilepath);
|
|
147
147
|
if (storedData) {
|
|
148
148
|
hookManager.invokeOnStoreItemBeforeUpdate({
|
|
@@ -152,7 +152,7 @@ export const storeManager: StoreManager = {
|
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
const { fileContent, previousStoredData } =
|
|
155
|
-
setFileIntoStore(relativeFilepath);
|
|
155
|
+
await setFileIntoStore(relativeFilepath);
|
|
156
156
|
|
|
157
157
|
// Invalidate this item.
|
|
158
158
|
dependencyTagger.invalidateTags([relativeFilepath]);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import fsPromises from 'node:fs/promises';
|
|
2
3
|
import path from 'path';
|
|
3
4
|
import fg, { Options as fastGlobOptions } from 'fast-glob';
|
|
4
5
|
import { logger } from '../logger';
|
|
@@ -37,6 +38,31 @@ export const readFile = (filePath: string): string | null => {
|
|
|
37
38
|
return content;
|
|
38
39
|
};
|
|
39
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Asynchronously reads a file and logs an error on failure.
|
|
43
|
+
*
|
|
44
|
+
* @param filePath - A path to a file.
|
|
45
|
+
*
|
|
46
|
+
* @returns The file contents as a string if file is found, or null otherwise.
|
|
47
|
+
*/
|
|
48
|
+
export const readFileAsync = async (
|
|
49
|
+
filePath: string,
|
|
50
|
+
): Promise<string | null> => {
|
|
51
|
+
let content;
|
|
52
|
+
try {
|
|
53
|
+
content = await fsPromises.readFile(filePath, {
|
|
54
|
+
encoding: 'utf8',
|
|
55
|
+
flag: 'r',
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
// When an error is thrown, content is undefined, so ensure
|
|
59
|
+
// it is converted to null.
|
|
60
|
+
content = null;
|
|
61
|
+
logger.error(`Error reading file "${filePath}": ${error}`);
|
|
62
|
+
}
|
|
63
|
+
return content;
|
|
64
|
+
};
|
|
65
|
+
|
|
40
66
|
/**
|
|
41
67
|
* Gets raw and JSON parsed content from a file.
|
|
42
68
|
*
|
|
@@ -58,6 +84,29 @@ export const getFileContent = (filepath: string): FileType => {
|
|
|
58
84
|
return { raw, json };
|
|
59
85
|
};
|
|
60
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Asynchronously gets raw and JSON parsed content from a file.
|
|
89
|
+
*
|
|
90
|
+
* @param filepath - A path to a file.
|
|
91
|
+
*
|
|
92
|
+
* @returns Object with two properties, "raw" and "json", which contain
|
|
93
|
+
* the raw and json version of the file. If file is not a JSON, the "json"
|
|
94
|
+
* property is null. If file is not found, both properties are null.
|
|
95
|
+
*/
|
|
96
|
+
export const getFileContentAsync = async (
|
|
97
|
+
filepath: string,
|
|
98
|
+
): Promise<FileType> => {
|
|
99
|
+
const raw = await readFileAsync(filepath);
|
|
100
|
+
let json = null;
|
|
101
|
+
if (raw && isJsonFile(filepath)) {
|
|
102
|
+
json = parseJsonString(raw);
|
|
103
|
+
if (!json) {
|
|
104
|
+
logger.error(`Error getting JSON from file "${filepath}"`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return { raw, json };
|
|
108
|
+
};
|
|
109
|
+
|
|
61
110
|
/**
|
|
62
111
|
* Finds all files inside a directory
|
|
63
112
|
*
|
|
@@ -82,6 +131,30 @@ export const findFilesInDir = (
|
|
|
82
131
|
return files;
|
|
83
132
|
};
|
|
84
133
|
|
|
134
|
+
/**
|
|
135
|
+
* Asynchronously finds all files inside a directory
|
|
136
|
+
*
|
|
137
|
+
* @param dir - Absolute path to the directory to be scanned
|
|
138
|
+
* @param glob - Optional glob to filter results (default all files recursive '**\/*')
|
|
139
|
+
* @param options - Options for the fast-glob package.
|
|
140
|
+
* See https://www.npmjs.com/package/fast-glob for reference .
|
|
141
|
+
*
|
|
142
|
+
* @returns Array of file paths found inside directory
|
|
143
|
+
*/
|
|
144
|
+
export const findFilesInDirAsync = async (
|
|
145
|
+
dir: string,
|
|
146
|
+
glob = '**/*',
|
|
147
|
+
options: fastGlobOptions = { absolute: false },
|
|
148
|
+
): Promise<string[]> => {
|
|
149
|
+
const startDate = Date.now();
|
|
150
|
+
const files = await fg([glob], { cwd: dir, ...options });
|
|
151
|
+
const endDate = Date.now();
|
|
152
|
+
logger.debug(
|
|
153
|
+
`ASYNC ${files.length} files found inside ${dir} in ${endDate - startDate}ms.`,
|
|
154
|
+
);
|
|
155
|
+
return files;
|
|
156
|
+
};
|
|
157
|
+
|
|
85
158
|
/**
|
|
86
159
|
* Gets a file's modification date and logs an error on failure.
|
|
87
160
|
*
|