@static-suite/static-suite-data-server 0.0.10 → 0.0.11

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 CHANGED
@@ -358,6 +358,7 @@ Received parameters:
358
358
  - `toUniqueId`: a unique id representing the date until which those changes are obtained.
359
359
  - `updated`: a list of updated files (both newly added and changed files).
360
360
  - `deleted`: a list of deleted files.
361
+ - `all`: a list of all updated and deleted files, sorted by its unique id.
361
362
 
362
363
  #### `onStoreItemBeforeUpdate({ store, logger, dependencyTagger, relativeFilepath, storeItem }): void`
363
364
 
@@ -406,11 +407,11 @@ Received parameters:
406
407
  - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
407
408
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
408
409
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
409
-
410
410
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
411
411
  - `toUniqueId`: a unique id representing the date until which those changes are obtained.
412
412
  - `updated`: a list of updated files (both newly added and changed files).
413
413
  - `deleted`: a list of deleted files.
414
+ - `all`: a list of all updated and deleted files, sorted by its unique id.
414
415
 
415
416
  #### `onDumpCreate(options: OnDumpHookOptions): Dump`
416
417
 
@@ -358,6 +358,7 @@ Received parameters:
358
358
  - `toUniqueId`: a unique id representing the date until which those changes are obtained.
359
359
  - `updated`: a list of updated files (both newly added and changed files).
360
360
  - `deleted`: a list of deleted files.
361
+ - `all`: a list of all updated and deleted files, sorted by its unique id.
361
362
 
362
363
  #### `onStoreItemBeforeUpdate({ store, logger, dependencyTagger, relativeFilepath, storeItem }): void`
363
364
 
@@ -406,11 +407,11 @@ Received parameters:
406
407
  - `logger`: the logger service width several functions to log messages: `error()`, `warn()`, `info()`, `error()`
407
408
  - `dependencyTagger`: the dependency tagger service. See [Dependency Tags](#dependency-tags) section.
408
409
  - `changedFiles`: a group of changed files in Static Suite's data dir, an object with the following keys:
409
-
410
410
  - `fromUniqueId`: a unique id representing the date from which those changes are obtained.
411
411
  - `toUniqueId`: a unique id representing the date until which those changes are obtained.
412
412
  - `updated`: a list of updated files (both newly added and changed files).
413
413
  - `deleted`: a list of deleted files.
414
+ - `all`: a list of all updated and deleted files, sorted by its unique id.
414
415
 
415
416
  #### `onDumpCreate(options: OnDumpHookOptions): Dump`
416
417
 
@@ -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,cAuH5B,CAAC"}
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.updated.forEach(file => {
77
- storeManager_1.storeManager.update(file);
78
- const fileContent = store_1.store.data.get(file);
79
- storeManager_1.storeManager.parseSingleFileIncludes(file, fileContent);
80
- });
81
- changedFiles.deleted.forEach(file => {
82
- storeManager_1.storeManager.remove(file);
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,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;IAClB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,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
+ {"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,EAAE,YAAY,EAAe,MAAM,iBAAiB,CAAC;AAO5D;;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;CAkChB,CAAC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-suite/static-suite-data-server",
3
- "version": "0.0.10",
3
+ "version": "0.0.11",
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",
@@ -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.updated.forEach(file => {
104
- storeManager.update(file);
105
- const fileContent = store.data.get(file);
106
- storeManager.parseSingleFileIncludes(file, fileContent);
107
- });
108
- changedFiles.deleted.forEach(file => {
109
- storeManager.remove(file);
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,