@static-suite/static-suite-data-server 0.0.10 → 0.0.12
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 +48 -1
- package/dist/http/README.md +48 -1
- package/dist/http/routes/index.d.ts.map +1 -1
- package/dist/http/routes/index.js +2 -0
- package/dist/http/routes/subset.d.ts +4 -0
- package/dist/http/routes/subset.d.ts.map +1 -0
- package/dist/http/routes/subset.js +42 -0
- package/dist/lib/store/dataDir/dataDirManager.d.ts.map +1 -1
- package/dist/lib/store/dataDir/dataDirManager.js +10 -7
- package/dist/lib/store/store.types.d.ts +1 -1
- package/dist/lib/store/store.types.d.ts.map +1 -1
- package/dist/lib/store/workDir/workDir.types.d.ts +11 -0
- package/dist/lib/store/workDir/workDir.types.d.ts.map +1 -1
- package/dist/lib/store/workDir/workDirHelper.d.ts.map +1 -1
- package/dist/lib/store/workDir/workDirHelper.js +21 -6
- package/dist/static-suite-data-server.d.ts +1 -1
- package/package.json +1 -1
- package/src/http/routes/index.ts +2 -0
- package/src/http/routes/subset.ts +43 -0
- package/src/lib/store/dataDir/dataDirManager.ts +10 -7
- package/src/lib/store/store.types.ts +1 -1
- package/src/lib/store/workDir/__tests__/workDirHelper.test.ts +12 -0
- package/src/lib/store/workDir/workDir.types.ts +14 -0
- package/src/lib/store/workDir/workDirHelper.ts +24 -7
package/README.md
CHANGED
|
@@ -163,6 +163,52 @@ const results = store.data
|
|
|
163
163
|
.items.filter(article => article.data.content.title.includes('foo'));
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
+
### Getting a subset of files via HTTP
|
|
167
|
+
|
|
168
|
+
It is also possible to get a subset of files via HTTP, querying the HTTP endpoint `/subset` with the following options passed as query strings:
|
|
169
|
+
|
|
170
|
+
- `dir`: optional base directory to filter files. It requires a trailing slash, but not a leading slash, e.g.- `en/entity/node/article/`
|
|
171
|
+
- `variant`: Optional name of a variant file.
|
|
172
|
+
- Use `_main` to obtain the default variant.
|
|
173
|
+
- Use any other string, e.g.- `card`, to obtain the card variant.
|
|
174
|
+
- Use "null" to avoid searching for any variant.
|
|
175
|
+
- Defaults to `_main`.
|
|
176
|
+
- `ext`: Optional file extension, without dots. Defaults to `json`.
|
|
177
|
+
- `recursive`: Optional flag to search for files recursively. Defaults to `true`.
|
|
178
|
+
- `as`: Optional flag to get the subset as filenames or URLs. Possible values: `filename` or `url`. Defaults to `filename`.
|
|
179
|
+
|
|
180
|
+
#### Return value
|
|
181
|
+
|
|
182
|
+
An array of filenames in the subset.
|
|
183
|
+
|
|
184
|
+
```http
|
|
185
|
+
// Get a subset of all nodes in English with "json" extension.
|
|
186
|
+
http://localhost:57471/subset?dir=en/entity/node/
|
|
187
|
+
|
|
188
|
+
// Return value
|
|
189
|
+
[
|
|
190
|
+
"en/entity/node/article/1.json",
|
|
191
|
+
"en/entity/node/page/4.json",
|
|
192
|
+
"en/entity/node/gallery/6.json",
|
|
193
|
+
...
|
|
194
|
+
]
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
An array of URLs in the subset.
|
|
198
|
+
|
|
199
|
+
```http
|
|
200
|
+
// Get a subset of all nodes in English with "json" extension.
|
|
201
|
+
http://localhost:57471/subset?dir=en/entity/node/&as=url
|
|
202
|
+
|
|
203
|
+
// Return value
|
|
204
|
+
[
|
|
205
|
+
"/path/to/public/url-1",
|
|
206
|
+
"/path/to/public/url-2",
|
|
207
|
+
"/path/to/public/url-3",
|
|
208
|
+
...
|
|
209
|
+
]
|
|
210
|
+
```
|
|
211
|
+
|
|
166
212
|
### Indexes
|
|
167
213
|
|
|
168
214
|
Apart from the main data Map, files are also automatically stored in two more maps (indexes) to be able to access them faster:
|
|
@@ -358,6 +404,7 @@ Received parameters:
|
|
|
358
404
|
- `toUniqueId`: a unique id representing the date until which those changes are obtained.
|
|
359
405
|
- `updated`: a list of updated files (both newly added and changed files).
|
|
360
406
|
- `deleted`: a list of deleted files.
|
|
407
|
+
- `all`: a list of all updated and deleted files, sorted by its unique id.
|
|
361
408
|
|
|
362
409
|
#### `onStoreItemBeforeUpdate({ store, logger, dependencyTagger, relativeFilepath, storeItem }): void`
|
|
363
410
|
|
|
@@ -406,11 +453,11 @@ Received parameters:
|
|
|
406
453
|
- `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
|
|
407
454
|
- `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
|
|
408
455
|
- `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
|
|
409
|
-
|
|
410
456
|
- `fromUniqueId`: a unique id representing the date from which those changes are obtained.
|
|
411
457
|
- `toUniqueId`: a unique id representing the date until which those changes are obtained.
|
|
412
458
|
- `updated`: a list of updated files (both newly added and changed files).
|
|
413
459
|
- `deleted`: a list of deleted files.
|
|
460
|
+
- `all`: a list of all updated and deleted files, sorted by its unique id.
|
|
414
461
|
|
|
415
462
|
#### `onDumpCreate(options: OnDumpHookOptions): Dump`
|
|
416
463
|
|
package/dist/http/README.md
CHANGED
|
@@ -163,6 +163,52 @@ const results = store.data
|
|
|
163
163
|
.items.filter(article => article.data.content.title.includes('foo'));
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
+
### Getting a subset of files via HTTP
|
|
167
|
+
|
|
168
|
+
It is also possible to get a subset of files via HTTP, querying the HTTP endpoint `/subset` with the following options passed as query strings:
|
|
169
|
+
|
|
170
|
+
- `dir`: optional base directory to filter files. It requires a trailing slash, but not a leading slash, e.g.- `en/entity/node/article/`
|
|
171
|
+
- `variant`: Optional name of a variant file.
|
|
172
|
+
- Use `_main` to obtain the default variant.
|
|
173
|
+
- Use any other string, e.g.- `card`, to obtain the card variant.
|
|
174
|
+
- Use "null" to avoid searching for any variant.
|
|
175
|
+
- Defaults to `_main`.
|
|
176
|
+
- `ext`: Optional file extension, without dots. Defaults to `json`.
|
|
177
|
+
- `recursive`: Optional flag to search for files recursively. Defaults to `true`.
|
|
178
|
+
- `as`: Optional flag to get the subset as filenames or URLs. Possible values: `filename` or `url`. Defaults to `filename`.
|
|
179
|
+
|
|
180
|
+
#### Return value
|
|
181
|
+
|
|
182
|
+
An array of filenames in the subset.
|
|
183
|
+
|
|
184
|
+
```http
|
|
185
|
+
// Get a subset of all nodes in English with "json" extension.
|
|
186
|
+
http://localhost:57471/subset?dir=en/entity/node/
|
|
187
|
+
|
|
188
|
+
// Return value
|
|
189
|
+
[
|
|
190
|
+
"en/entity/node/article/1.json",
|
|
191
|
+
"en/entity/node/page/4.json",
|
|
192
|
+
"en/entity/node/gallery/6.json",
|
|
193
|
+
...
|
|
194
|
+
]
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
An array of URLs in the subset.
|
|
198
|
+
|
|
199
|
+
```http
|
|
200
|
+
// Get a subset of all nodes in English with "json" extension.
|
|
201
|
+
http://localhost:57471/subset?dir=en/entity/node/&as=url
|
|
202
|
+
|
|
203
|
+
// Return value
|
|
204
|
+
[
|
|
205
|
+
"/path/to/public/url-1",
|
|
206
|
+
"/path/to/public/url-2",
|
|
207
|
+
"/path/to/public/url-3",
|
|
208
|
+
...
|
|
209
|
+
]
|
|
210
|
+
```
|
|
211
|
+
|
|
166
212
|
### Indexes
|
|
167
213
|
|
|
168
214
|
Apart from the main data Map, files are also automatically stored in two more maps (indexes) to be able to access them faster:
|
|
@@ -358,6 +404,7 @@ Received parameters:
|
|
|
358
404
|
- `toUniqueId`: a unique id representing the date until which those changes are obtained.
|
|
359
405
|
- `updated`: a list of updated files (both newly added and changed files).
|
|
360
406
|
- `deleted`: a list of deleted files.
|
|
407
|
+
- `all`: a list of all updated and deleted files, sorted by its unique id.
|
|
361
408
|
|
|
362
409
|
#### `onStoreItemBeforeUpdate({ store, logger, dependencyTagger, relativeFilepath, storeItem }): void`
|
|
363
410
|
|
|
@@ -406,11 +453,11 @@ Received parameters:
|
|
|
406
453
|
- `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
|
|
407
454
|
- `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
|
|
408
455
|
- `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
|
|
409
|
-
|
|
410
456
|
- `fromUniqueId`: a unique id representing the date from which those changes are obtained.
|
|
411
457
|
- `toUniqueId`: a unique id representing the date until which those changes are obtained.
|
|
412
458
|
- `updated`: a list of updated files (both newly added and changed files).
|
|
413
459
|
- `deleted`: a list of deleted files.
|
|
460
|
+
- `all`: a list of all updated and deleted files, sorted by its unique id.
|
|
414
461
|
|
|
415
462
|
#### `onDumpCreate(options: OnDumpHookOptions): Dump`
|
|
416
463
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/routes/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/http/routes/index.ts"],"names":[],"mappings":"AAmCA,QAAA,MAAM,MAAM,4CAAW,CAAC;AAiCxB,eAAe,MAAM,CAAC"}
|
|
@@ -12,6 +12,7 @@ const dump_1 = require("./dump");
|
|
|
12
12
|
const dependency_1 = require("./dependency");
|
|
13
13
|
const indexUrl_1 = require("./indexUrl");
|
|
14
14
|
const indexUUID_1 = require("./indexUUID");
|
|
15
|
+
const subset_1 = require("./subset");
|
|
15
16
|
const routes = (0, express_1.Router)();
|
|
16
17
|
routes.get('/', home_1.home);
|
|
17
18
|
routes.get('/docs', docs_1.docs);
|
|
@@ -42,4 +43,5 @@ routes.get('/dependency', dependency_1.dependencyIndex);
|
|
|
42
43
|
routes.get(['/data/*', '/data'], data_1.data);
|
|
43
44
|
routes.get(['/index/url/*', '/index/url'], indexUrl_1.indexUrl);
|
|
44
45
|
routes.get(['/index/uuid/*', '/index/uuid'], indexUUID_1.indexUUID);
|
|
46
|
+
routes.get('/subset', subset_1.subset);
|
|
45
47
|
exports.default = routes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subset.d.ts","sourceRoot":"","sources":["../../../src/http/routes/subset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAK5C,QAAA,MAAM,MAAM,QAAS,OAAO,OAAO,QAAQ,KAAG,IAmC7C,CAAC;AAEF,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.subset = void 0;
|
|
4
|
+
const store_1 = require("../../lib/store");
|
|
5
|
+
const dataDir_1 = require("../../lib/store/dataDir");
|
|
6
|
+
const subset = (req, res) => {
|
|
7
|
+
dataDir_1.dataDirManager.update();
|
|
8
|
+
const options = {};
|
|
9
|
+
if (req.query.dir) {
|
|
10
|
+
options.dir = req.query.dir;
|
|
11
|
+
}
|
|
12
|
+
if (req.query.variant) {
|
|
13
|
+
if (req.query.variant === 'null') {
|
|
14
|
+
options.variant = undefined;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
options.variant = req.query.variant;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (req.query.ext) {
|
|
21
|
+
options.ext = req.query.ext;
|
|
22
|
+
}
|
|
23
|
+
if (req.query.recursive) {
|
|
24
|
+
options.recursive = req.query.recursive === 'true';
|
|
25
|
+
}
|
|
26
|
+
const returnedSubset = store_1.store.data.subset(options);
|
|
27
|
+
let result;
|
|
28
|
+
if (req.query.as === 'url') {
|
|
29
|
+
result = returnedSubset.items
|
|
30
|
+
.map(item => item.data?.content?.url?.path)
|
|
31
|
+
.filter(path => !!path);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result = returnedSubset.filenames;
|
|
35
|
+
}
|
|
36
|
+
res.status(200);
|
|
37
|
+
res.set({
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
});
|
|
40
|
+
res.send(result);
|
|
41
|
+
};
|
|
42
|
+
exports.subset = subset;
|
|
@@ -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,cA0H5B,CAAC"}
|
|
@@ -56,6 +56,7 @@ exports.dataDirManager = {
|
|
|
56
56
|
update: () => {
|
|
57
57
|
const dataDirModificationUniqueId = exports.dataDirManager.getModificationUniqueId();
|
|
58
58
|
let changedFiles = {
|
|
59
|
+
all: [],
|
|
59
60
|
updated: [],
|
|
60
61
|
deleted: [],
|
|
61
62
|
fromUniqueId: store_1.store.currentUniqueId,
|
|
@@ -73,13 +74,15 @@ exports.dataDirManager = {
|
|
|
73
74
|
dependencyManager_1.dependencyManager.trackInvalidatedFilepaths();
|
|
74
75
|
changedFiles = workDir_1.workDirHelper.getChangedFilesBetween(storeLastUniqueId, dataDirModificationUniqueId);
|
|
75
76
|
hook_1.hookManager.invokeOnStoreChangeStart(changedFiles);
|
|
76
|
-
changedFiles.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
changedFiles.all.forEach(changedData => {
|
|
78
|
+
if (changedData.type === 'updated') {
|
|
79
|
+
storeManager_1.storeManager.update(changedData.file);
|
|
80
|
+
const fileContent = store_1.store.data.get(changedData.file);
|
|
81
|
+
storeManager_1.storeManager.parseSingleFileIncludes(changedData.file, fileContent);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
storeManager_1.storeManager.remove(changedData.file);
|
|
85
|
+
}
|
|
83
86
|
});
|
|
84
87
|
// Clear all store subsets and queries, since they are stale.
|
|
85
88
|
// In fact, the subset cache should be cleared only when files
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"store.types.d.ts","sourceRoot":"","sources":["../../../src/lib/store/store.types.ts"],"names":[],"mappings":"AAAA,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;;GAEG;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;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;;;;;;;OAQG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"store.types.d.ts","sourceRoot":"","sources":["../../../src/lib/store/store.types.ts"],"names":[],"mappings":"AAAA,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;;GAEG;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;;GAEG;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;;GAEG;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;IAE5C;;;;;;;;;;OAUG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IAEnC;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAAC;IAEnC;;;;;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"}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An item for all changed files in Static Suite's data dir.
|
|
3
|
+
*/
|
|
4
|
+
export type allChangesItem = {
|
|
5
|
+
file: string;
|
|
6
|
+
type: 'updated' | 'deleted';
|
|
7
|
+
};
|
|
1
8
|
/**
|
|
2
9
|
* A group of changed files in Static Suite's data dir.
|
|
3
10
|
*/
|
|
@@ -18,6 +25,10 @@ export type ChangedFiles = {
|
|
|
18
25
|
* A list of deleted files.
|
|
19
26
|
*/
|
|
20
27
|
deleted: string[];
|
|
28
|
+
/**
|
|
29
|
+
* A list of all changed files, sorted by its timestamp.
|
|
30
|
+
*/
|
|
31
|
+
all: allChangesItem[];
|
|
21
32
|
};
|
|
22
33
|
/**
|
|
23
34
|
* Information from a Static Suite's log line.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workDir.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/workDir/workDir.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"workDir.types.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/workDir/workDir.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,SAAS,GAAG,SAAS,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;IAElB;;OAEG;IACH,GAAG,EAAE,cAAc,EAAE,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,SAAS,EAAE,OAAO,GAAG,QAAQ,CAAC;IAE9B;;OAEG;IACH,IAAI,EAAE;QACJ;;WAEG;QACH,EAAE,EAAE,MAAM,CAAC;QAEX;;WAEG;QACH,KAAK,EAAE,MAAM,CAAC;QAEd;;WAEG;QACH,YAAY,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workDirHelper.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/workDir/workDirHelper.ts"],"names":[],"mappings":"AAGA,OAAO,
|
|
1
|
+
{"version":3,"file":"workDirHelper.d.ts","sourceRoot":"","sources":["../../../../src/lib/store/workDir/workDirHelper.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,YAAY,EAAe,MAAM,iBAAiB,CAAC;AAO5E;;GAEG;AACH,eAAO,MAAM,iBAAiB,qCAAqC,CAAC;AAEpE,eAAO,MAAM,aAAa;IACxB;;;;OAIG;mCAC0B,MAAM,GAAG,IAAI;IAsB1C;;;;;;;;;;;OAWG;2CAEa,MAAM,cACR,MAAM,KACjB,YAAY;CAmDhB,CAAC"}
|
|
@@ -61,19 +61,34 @@ exports.workDirHelper = {
|
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
const lineDataArray = Object.values(lineData);
|
|
64
|
+
const lineDataByUniqueId = {};
|
|
65
|
+
lineDataArray.forEach(lineDataGroup => {
|
|
66
|
+
if (!lineDataByUniqueId[lineDataGroup.uniqueId]) {
|
|
67
|
+
lineDataByUniqueId[lineDataGroup.uniqueId] = [];
|
|
68
|
+
}
|
|
69
|
+
lineDataByUniqueId[lineDataGroup.uniqueId].push(lineDataGroup);
|
|
70
|
+
});
|
|
71
|
+
const sortedUniqueIds = Object.keys(lineDataByUniqueId).sort();
|
|
72
|
+
const all = [];
|
|
73
|
+
sortedUniqueIds.forEach(sortedUniqueId => {
|
|
74
|
+
lineDataByUniqueId[sortedUniqueId].forEach(data => {
|
|
75
|
+
all.push({
|
|
76
|
+
file: data.file.relativePath,
|
|
77
|
+
type: data.operation === 'write' ? 'updated' : 'deleted',
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
all.forEach(data => {
|
|
82
|
+
logger_1.logger.debug(`Found ${data.type} file "${data.file}"`);
|
|
83
|
+
});
|
|
64
84
|
const updated = lineDataArray
|
|
65
85
|
.filter(data => data.operation === 'write')
|
|
66
86
|
.map(data => data.file.relativePath);
|
|
67
|
-
updated.forEach(file => {
|
|
68
|
-
logger_1.logger.debug(`Found updated file "${file}"`);
|
|
69
|
-
});
|
|
70
87
|
const deleted = lineDataArray
|
|
71
88
|
.filter(data => data.operation === 'delete')
|
|
72
89
|
.map(data => data.file.relativePath);
|
|
73
|
-
deleted.forEach(file => {
|
|
74
|
-
logger_1.logger.debug(`Found deleted file "${file}"`);
|
|
75
|
-
});
|
|
76
90
|
return {
|
|
91
|
+
all,
|
|
77
92
|
updated,
|
|
78
93
|
deleted,
|
|
79
94
|
fromUniqueId,
|
package/package.json
CHANGED
package/src/http/routes/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
} from './dependency';
|
|
32
32
|
import { indexUrl } from './indexUrl';
|
|
33
33
|
import { indexUUID } from './indexUUID';
|
|
34
|
+
import { subset } from './subset';
|
|
34
35
|
|
|
35
36
|
const routes = Router();
|
|
36
37
|
|
|
@@ -63,5 +64,6 @@ routes.get('/dependency', dependencyIndex);
|
|
|
63
64
|
routes.get(['/data/*', '/data'], data);
|
|
64
65
|
routes.get(['/index/url/*', '/index/url'], indexUrl);
|
|
65
66
|
routes.get(['/index/uuid/*', '/index/uuid'], indexUUID);
|
|
67
|
+
routes.get('/subset', subset);
|
|
66
68
|
|
|
67
69
|
export default routes;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Request, Response } from 'express';
|
|
2
|
+
import { StoreSubsetOptions } from 'lib/store/store.types';
|
|
3
|
+
import { store } from '../../lib/store';
|
|
4
|
+
import { dataDirManager } from '../../lib/store/dataDir';
|
|
5
|
+
|
|
6
|
+
const subset = (req: Request, res: Response): void => {
|
|
7
|
+
dataDirManager.update();
|
|
8
|
+
const options: StoreSubsetOptions = {};
|
|
9
|
+
if (req.query.dir) {
|
|
10
|
+
options.dir = req.query.dir as string;
|
|
11
|
+
}
|
|
12
|
+
if (req.query.variant) {
|
|
13
|
+
if (req.query.variant === 'null') {
|
|
14
|
+
options.variant = undefined;
|
|
15
|
+
} else {
|
|
16
|
+
options.variant = req.query.variant as string;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (req.query.ext) {
|
|
20
|
+
options.ext = req.query.ext as string;
|
|
21
|
+
}
|
|
22
|
+
if (req.query.recursive) {
|
|
23
|
+
options.recursive = req.query.recursive === 'true';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const returnedSubset = store.data.subset(options);
|
|
27
|
+
let result;
|
|
28
|
+
if (req.query.as === 'url') {
|
|
29
|
+
result = returnedSubset.items
|
|
30
|
+
.map(item => item.data?.content?.url?.path)
|
|
31
|
+
.filter(path => !!path);
|
|
32
|
+
} else {
|
|
33
|
+
result = returnedSubset.filenames;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
res.status(200);
|
|
37
|
+
res.set({
|
|
38
|
+
'Content-Type': 'application/json',
|
|
39
|
+
});
|
|
40
|
+
res.send(result);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { subset };
|
|
@@ -75,6 +75,7 @@ export const dataDirManager: DataDirManager = {
|
|
|
75
75
|
dataDirManager.getModificationUniqueId();
|
|
76
76
|
|
|
77
77
|
let changedFiles: ChangedFiles = {
|
|
78
|
+
all: [],
|
|
78
79
|
updated: [],
|
|
79
80
|
deleted: [],
|
|
80
81
|
fromUniqueId: store.currentUniqueId,
|
|
@@ -100,14 +101,16 @@ export const dataDirManager: DataDirManager = {
|
|
|
100
101
|
dataDirModificationUniqueId,
|
|
101
102
|
);
|
|
102
103
|
hookManager.invokeOnStoreChangeStart(changedFiles);
|
|
103
|
-
changedFiles.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
changedFiles.all.forEach(changedData => {
|
|
105
|
+
if (changedData.type === 'updated') {
|
|
106
|
+
storeManager.update(changedData.file);
|
|
107
|
+
const fileContent = store.data.get(changedData.file);
|
|
108
|
+
storeManager.parseSingleFileIncludes(changedData.file, fileContent);
|
|
109
|
+
} else {
|
|
110
|
+
storeManager.remove(changedData.file);
|
|
111
|
+
}
|
|
110
112
|
});
|
|
113
|
+
|
|
111
114
|
// Clear all store subsets and queries, since they are stale.
|
|
112
115
|
// In fact, the subset cache should be cleared only when files
|
|
113
116
|
// are added or deleted, but not when they are simply updated.
|
|
@@ -24,6 +24,18 @@ describe('workDirHelper test', () => {
|
|
|
24
24
|
'es/config/static_export.settings.json',
|
|
25
25
|
'es/entity/node/recipe/9.json',
|
|
26
26
|
],
|
|
27
|
+
all: [
|
|
28
|
+
{ file: 'es/entity/node/article/10.json', type: 'deleted' },
|
|
29
|
+
{ file: 'en/entity/node/article/10.json', type: 'updated' },
|
|
30
|
+
{
|
|
31
|
+
file: 'es/config/static_export.settings.json',
|
|
32
|
+
type: 'updated',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
file: 'es/entity/node/recipe/9.json',
|
|
36
|
+
type: 'updated',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
27
39
|
});
|
|
28
40
|
});
|
|
29
41
|
});
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An item for all changed files in Static Suite's data dir.
|
|
3
|
+
*/
|
|
4
|
+
export type allChangesItem = {
|
|
5
|
+
file: string;
|
|
6
|
+
type: 'updated' | 'deleted';
|
|
7
|
+
};
|
|
8
|
+
|
|
1
9
|
/**
|
|
2
10
|
* A group of changed files in Static Suite's data dir.
|
|
3
11
|
*/
|
|
@@ -16,10 +24,16 @@ export type ChangedFiles = {
|
|
|
16
24
|
* A list of updated files (both newly added and changed files).
|
|
17
25
|
*/
|
|
18
26
|
updated: string[];
|
|
27
|
+
|
|
19
28
|
/**
|
|
20
29
|
* A list of deleted files.
|
|
21
30
|
*/
|
|
22
31
|
deleted: string[];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A list of all changed files, sorted by its timestamp.
|
|
35
|
+
*/
|
|
36
|
+
all: allChangesItem[];
|
|
23
37
|
};
|
|
24
38
|
|
|
25
39
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { logger } from '../../utils/logger';
|
|
3
3
|
import { isUniqueId } from '../../utils/string';
|
|
4
|
-
import { ChangedFiles, LogLineData } from './workDir.types';
|
|
4
|
+
import { allChangesItem, ChangedFiles, LogLineData } from './workDir.types';
|
|
5
5
|
import {
|
|
6
6
|
getLogFile,
|
|
7
7
|
getChangedLinesBetween,
|
|
@@ -69,21 +69,38 @@ export const workDirHelper = {
|
|
|
69
69
|
});
|
|
70
70
|
const lineDataArray: LogLineData[] = Object.values(lineData);
|
|
71
71
|
|
|
72
|
+
const lineDataByUniqueId: Record<string, LogLineData[]> = {};
|
|
73
|
+
lineDataArray.forEach(lineDataGroup => {
|
|
74
|
+
if (!lineDataByUniqueId[lineDataGroup.uniqueId]) {
|
|
75
|
+
lineDataByUniqueId[lineDataGroup.uniqueId] = [];
|
|
76
|
+
}
|
|
77
|
+
lineDataByUniqueId[lineDataGroup.uniqueId].push(lineDataGroup);
|
|
78
|
+
});
|
|
79
|
+
const sortedUniqueIds = Object.keys(lineDataByUniqueId).sort();
|
|
80
|
+
const all: allChangesItem[] = [];
|
|
81
|
+
sortedUniqueIds.forEach(sortedUniqueId => {
|
|
82
|
+
lineDataByUniqueId[sortedUniqueId].forEach(data => {
|
|
83
|
+
all.push({
|
|
84
|
+
file: data.file.relativePath,
|
|
85
|
+
type: data.operation === 'write' ? 'updated' : 'deleted',
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
all.forEach(data => {
|
|
91
|
+
logger.debug(`Found ${data.type} file "${data.file}"`);
|
|
92
|
+
});
|
|
93
|
+
|
|
72
94
|
const updated = lineDataArray
|
|
73
95
|
.filter(data => data.operation === 'write')
|
|
74
96
|
.map(data => data.file.relativePath);
|
|
75
|
-
updated.forEach(file => {
|
|
76
|
-
logger.debug(`Found updated file "${file}"`);
|
|
77
|
-
});
|
|
78
97
|
|
|
79
98
|
const deleted = lineDataArray
|
|
80
99
|
.filter(data => data.operation === 'delete')
|
|
81
100
|
.map(data => data.file.relativePath);
|
|
82
|
-
deleted.forEach(file => {
|
|
83
|
-
logger.debug(`Found deleted file "${file}"`);
|
|
84
|
-
});
|
|
85
101
|
|
|
86
102
|
return {
|
|
103
|
+
all,
|
|
87
104
|
updated,
|
|
88
105
|
deleted,
|
|
89
106
|
fromUniqueId,
|