Skip to content

Commit 7a8f3e5

Browse files
authored
Implement File based datastore for windows (#281)
1 parent 80e17ff commit 7a8f3e5

File tree

18 files changed

+904
-146
lines changed

18 files changed

+904
-146
lines changed

THIRD-PARTY-LICENSES.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39172,6 +39172,33 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
3917239172
THE SOFTWARE.
3917339173

3917439174

39175+
******************************
39176+
39177+
async-mutex
39178+
0.5.0 <https://github.com/DirtyHairy/async-mutex>
39179+
The MIT License (MIT)
39180+
39181+
Copyright (c) 2016 Christian Speckner <[email protected]>
39182+
39183+
Permission is hereby granted, free of charge, to any person obtaining a copy
39184+
of this software and associated documentation files (the "Software"), to deal
39185+
in the Software without restriction, including without limitation the rights
39186+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
39187+
copies of the Software, and to permit persons to whom the Software is
39188+
furnished to do so, subject to the following conditions:
39189+
39190+
The above copyright notice and this permission notice shall be included in
39191+
all copies or substantial portions of the Software.
39192+
39193+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39194+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39195+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
39196+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39197+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39198+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
39199+
THE SOFTWARE.
39200+
39201+
3917539202
******************************
3917639203

3917739204
asynckit
@@ -39984,6 +40011,13 @@ The above copyright notice and this permission notice shall be included in all c
3998440011
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3998540012

3998640013

40014+
******************************
40015+
40016+
cfn-guard
40017+
3.1.1 <https://github.com/aws-cloudformation/cloudformation-guard>
40018+
license: Apache-2.0
40019+
authors: undefined
40020+
3998740021
******************************
3998840022

3998940023
chalk

package-lock.json

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"@opentelemetry/sdk-trace-node": "2.0.1",
7373
"@tree-sitter-grammars/tree-sitter-yaml": "0.7.1",
7474
"archiver": "7.0.1",
75+
"async-mutex": "0.5.0",
7576
"axios": "1.11.0",
7677
"cfn-guard": "https://gitpkg.now.sh/aws-cloudformation/cloudformation-guard/guard/ts-lib?33d9931",
7778
"deep-object-diff": "1.1.9",

sbom/sbom.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ Name,SPDXID,Version,DownloadLocation,License
238238
"archiver","SPDXRef-Package-archiver-7.0.1","7.0.1","https://registry.npmjs.org/archiver/-/archiver-7.0.1.tgz","MIT"
239239
"archiver-utils","SPDXRef-Package-archiver-utils-5.0.2","5.0.2","https://registry.npmjs.org/archiver-utils/-/archiver-utils-5.0.2.tgz","MIT"
240240
"async","SPDXRef-Package-async-3.2.6","3.2.6","https://registry.npmjs.org/async/-/async-3.2.6.tgz","MIT"
241+
"async-mutex","SPDXRef-Package-async-mutex-0.5.0","0.5.0","https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz","MIT"
241242
"asynckit","SPDXRef-Package-asynckit-0.4.0","0.4.0","https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz","MIT"
242243
"atomic-sleep","SPDXRef-Package-atomic-sleep-1.0.0","1.0.0","https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz","MIT"
243244
"axios","SPDXRef-Package-axios-1.11.0","1.11.0","https://registry.npmjs.org/axios/-/axios-1.11.0.tgz","MIT"
@@ -253,6 +254,7 @@ Name,SPDXID,Version,DownloadLocation,License
253254
"buffer-crc32","SPDXRef-Package-buffer-crc32-0.2.13","0.2.13","https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz","MIT"
254255
"buffer-equal-constant-time","SPDXRef-Package-buffer-equal-constant-time-1.0.1","1.0.1","https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz","BSD-3-Clause"
255256
"camelcase","SPDXRef-Package-camelcase-6.3.0","6.3.0","https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz","MIT"
257+
"cfn-guard","SPDXRef-Package-cfn-guard-3.1.1","3.1.1","https://gitpkg.now.sh/aws-cloudformation/cloudformation-guard/guard/ts-lib?33d9931","Apache-2.0"
256258
"cjs-module-lexer","SPDXRef-Package-cjs-module-lexer-1.4.3","1.4.3","https://registry.npmjs.org/cjs-module-lexer/-/cjs-module-lexer-1.4.3.tgz","MIT"
257259
"cliui","SPDXRef-Package-cliui-8.0.1","8.0.1","https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz","ISC"
258260
"cohere-ai","SPDXRef-Package-cohere-ai-7.18.1","7.18.1","https://registry.npmjs.org/cohere-ai/-/cohere-ai-7.18.1.tgz","NOASSERTION"

sbom/sbom.json

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"dataLicense": "CC0-1.0",
44
"SPDXID": "SPDXRef-DOCUMENT",
55
"name": "@aws/[email protected]",
6-
"documentNamespace": "http://spdx.org/spdxdocs/@aws%2fcloudformation-languageserver-0.0.5-10917d5e-8766-4203-8433-0b4cdad240a9",
6+
"documentNamespace": "http://spdx.org/spdxdocs/@aws%2fcloudformation-languageserver-0.0.5-20c6d2ff-852b-42ee-ae45-8990f987420e",
77
"creationInfo": {
8-
"created": "2025-11-07T17:17:43.925Z",
8+
"created": "2025-11-18T08:08:30.548Z",
99
"creators": [
1010
"Tool: npm/cli-10.9.2"
1111
]
@@ -6499,6 +6499,30 @@
64996499
}
65006500
]
65016501
},
6502+
{
6503+
"name": "async-mutex",
6504+
"SPDXID": "SPDXRef-Package-async-mutex-0.5.0",
6505+
"versionInfo": "0.5.0",
6506+
"packageFileName": "node_modules/async-mutex",
6507+
"description": "A mutex for guarding async workflows",
6508+
"downloadLocation": "https://registry.npmjs.org/async-mutex/-/async-mutex-0.5.0.tgz",
6509+
"filesAnalyzed": false,
6510+
"homepage": "https://github.com/DirtyHairy/async-mutex#readme",
6511+
"licenseDeclared": "MIT",
6512+
"externalRefs": [
6513+
{
6514+
"referenceCategory": "PACKAGE-MANAGER",
6515+
"referenceType": "purl",
6516+
"referenceLocator": "pkg:npm/[email protected]"
6517+
}
6518+
],
6519+
"checksums": [
6520+
{
6521+
"algorithm": "SHA512",
6522+
"checksumValue": "d40f78075f23909dc362adbce2884fc685db7d30391ec43bfcc7f80c485cc8bc77073dbb461e7d89271b07a10f88ff81fa3a2e7ba602c5c31749b142d6d64ac0"
6523+
}
6524+
]
6525+
},
65026526
{
65036527
"name": "asynckit",
65046528
"SPDXID": "SPDXRef-Package-asynckit-0.4.0",
@@ -6811,6 +6835,30 @@
68116835
}
68126836
]
68136837
},
6838+
{
6839+
"name": "cfn-guard",
6840+
"SPDXID": "SPDXRef-Package-cfn-guard-3.1.1",
6841+
"versionInfo": "3.1.1",
6842+
"packageFileName": "node_modules/cfn-guard",
6843+
"description": "AWS CloudFormation Guard is an open-source general-purpose policy-as-code evaluation tool. It provides developers with a simple-to-use, yet powerful and expressive domain-specific language (DSL) to define policies and enables developers to validate JSON- or YAML- formatted structured data with those policies.",
6844+
"downloadLocation": "https://gitpkg.now.sh/aws-cloudformation/cloudformation-guard/guard/ts-lib?33d9931",
6845+
"filesAnalyzed": false,
6846+
"homepage": "https://github.com/aws-cloudformation/cloudformation-guard#readme",
6847+
"licenseDeclared": "Apache-2.0",
6848+
"externalRefs": [
6849+
{
6850+
"referenceCategory": "PACKAGE-MANAGER",
6851+
"referenceType": "purl",
6852+
"referenceLocator": "pkg:npm/[email protected]"
6853+
}
6854+
],
6855+
"checksums": [
6856+
{
6857+
"algorithm": "SHA512",
6858+
"checksumValue": "8a14a9a96126ad074c8947b0658a1615cf4919774a26387adb4fca48315491aaed5f1ffa99e0116873bea5166fc588249f4845438fc8299db6b41e81edba4dde"
6859+
}
6860+
]
6861+
},
68146862
{
68156863
"name": "cjs-module-lexer",
68166864
"SPDXID": "SPDXRef-Package-cjs-module-lexer-1.4.3",
@@ -11632,11 +11680,21 @@
1163211680
"relatedSpdxElement": "SPDXRef-Package-aws.cloudformation-languageserver-0.0.5",
1163311681
"relationshipType": "DEPENDENCY_OF"
1163411682
},
11683+
{
11684+
"spdxElementId": "SPDXRef-Package-async-mutex-0.5.0",
11685+
"relatedSpdxElement": "SPDXRef-Package-aws.cloudformation-languageserver-0.0.5",
11686+
"relationshipType": "DEPENDENCY_OF"
11687+
},
1163511688
{
1163611689
"spdxElementId": "SPDXRef-Package-axios-1.11.0",
1163711690
"relatedSpdxElement": "SPDXRef-Package-aws.cloudformation-languageserver-0.0.5",
1163811691
"relationshipType": "DEPENDENCY_OF"
1163911692
},
11693+
{
11694+
"spdxElementId": "SPDXRef-Package-cfn-guard-3.1.1",
11695+
"relatedSpdxElement": "SPDXRef-Package-aws.cloudformation-languageserver-0.0.5",
11696+
"relationshipType": "DEPENDENCY_OF"
11697+
},
1164011698
{
1164111699
"spdxElementId": "SPDXRef-Package-deep-object-diff-1.1.9",
1164211700
"relatedSpdxElement": "SPDXRef-Package-aws.cloudformation-languageserver-0.0.5",

src/datastore/DataStore.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import { pathToArtifact } from '../utils/ArtifactsDir';
12
import { Closeable } from '../utils/Closeable';
3+
import { isWindows } from '../utils/Environment';
4+
import { FileStoreFactory } from './FileStore';
25
import { LMDBStoreFactory } from './LMDB';
36
import { MemoryStoreFactory } from './MemoryStore';
47

@@ -24,14 +27,14 @@ export interface DataStore {
2427
clear(): Promise<void>;
2528

2629
keys(limit: number): ReadonlyArray<string>;
27-
28-
stats(): unknown;
2930
}
3031

3132
export interface DataStoreFactory extends Closeable {
3233
get(store: StoreName): DataStore;
3334

3435
storeNames(): ReadonlyArray<string>;
36+
37+
close(): Promise<void>;
3538
}
3639

3740
export interface DataStoreFactoryProvider extends Closeable {
@@ -56,21 +59,26 @@ export class MemoryDataStoreFactoryProvider implements DataStoreFactoryProvider
5659

5760
export class MultiDataStoreFactoryProvider implements DataStoreFactoryProvider {
5861
private readonly memoryStoreFactory: MemoryStoreFactory;
59-
private readonly lmdbStoreFactory: LMDBStoreFactory;
62+
private readonly persistedStore: DataStoreFactory;
63+
64+
constructor(rootDir: string = pathToArtifact()) {
65+
if (isWindows) {
66+
this.persistedStore = new FileStoreFactory(rootDir);
67+
} else {
68+
this.persistedStore = new LMDBStoreFactory(rootDir);
69+
}
6070

61-
constructor(lmdbStore?: LMDBStoreFactory, memStore?: MemoryStoreFactory) {
62-
this.lmdbStoreFactory = lmdbStore ?? new LMDBStoreFactory();
63-
this.memoryStoreFactory = memStore ?? new MemoryStoreFactory();
71+
this.memoryStoreFactory = new MemoryStoreFactory();
6472
}
6573

6674
get(store: StoreName, persistence: Persistence): DataStore {
6775
if (persistence === Persistence.memory) {
6876
return this.memoryStoreFactory.get(store);
6977
}
70-
return this.lmdbStoreFactory.get(store);
78+
return this.persistedStore.get(store);
7179
}
7280

7381
close(): Promise<void> {
74-
return this.lmdbStoreFactory.close();
82+
return this.persistedStore.close();
7583
}
7684
}

src/datastore/FileStore.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { existsSync, mkdirSync } from 'fs';
2+
import { join } from 'path';
3+
import { Logger } from 'pino';
4+
import { LoggerFactory } from '../telemetry/LoggerFactory';
5+
import { ScopedTelemetry } from '../telemetry/ScopedTelemetry';
6+
import { Telemetry } from '../telemetry/TelemetryDecorator';
7+
import { DataStore, DataStoreFactory, StoreName } from './DataStore';
8+
import { EncryptedFileStore } from './file/EncryptedFileStore';
9+
import { encryptionKey } from './file/Encryption';
10+
11+
export class FileStoreFactory implements DataStoreFactory {
12+
private readonly log: Logger;
13+
@Telemetry({ scope: 'FileStore.Global' }) private readonly telemetry!: ScopedTelemetry;
14+
15+
private readonly stores = new Map<StoreName, EncryptedFileStore>();
16+
private readonly fileDbDir: string;
17+
private readonly metricsInterval: NodeJS.Timeout;
18+
19+
constructor(rootDir: string) {
20+
this.log = LoggerFactory.getLogger('FileStore.Global');
21+
22+
this.fileDbDir = join(rootDir, 'filedb', `${Version}`);
23+
if (!existsSync(this.fileDbDir)) {
24+
mkdirSync(this.fileDbDir, { recursive: true });
25+
}
26+
27+
this.metricsInterval = setInterval(() => {
28+
this.emitMetrics();
29+
}, 60 * 1000);
30+
this.log.info(`Initialized FileStore v${Version}`);
31+
}
32+
33+
get(store: StoreName): DataStore {
34+
let val = this.stores.get(store);
35+
if (!val) {
36+
val = new EncryptedFileStore(encryptionKey(Version), store, this.fileDbDir);
37+
this.stores.set(store, val);
38+
}
39+
return val;
40+
}
41+
42+
storeNames(): ReadonlyArray<string> {
43+
return [...this.stores.keys()];
44+
}
45+
46+
close(): Promise<void> {
47+
clearInterval(this.metricsInterval);
48+
return Promise.resolve();
49+
}
50+
51+
private emitMetrics(): void {
52+
this.telemetry.histogram('version', Version);
53+
this.telemetry.histogram('env.entries', this.stores.size);
54+
55+
let totalBytes = 0;
56+
for (const [name, store] of this.stores.entries()) {
57+
const stats = store.stats();
58+
59+
totalBytes += stats.totalSize;
60+
this.telemetry.histogram(`store.${name}.entries`, stats.entries);
61+
this.telemetry.histogram(`store.${name}.size.bytes`, stats.totalSize, {
62+
unit: 'By',
63+
});
64+
}
65+
66+
this.telemetry.histogram('total.size.bytes', totalBytes, {
67+
unit: 'By',
68+
});
69+
}
70+
}
71+
72+
const Version = 1;

0 commit comments

Comments
 (0)