@scrabble-solver/dictionaries 2.15.8 → 2.15.10
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/LICENSE +1 -1
- package/build/Dictionaries.d.ts +1 -2
- package/build/Dictionaries.js +6 -5
- package/build/index.d.ts +1 -1
- package/build/index.js +2 -5
- package/build/lib/DiskCache.d.ts +1 -2
- package/build/lib/DiskCache.js +7 -6
- package/build/lib/LayeredCache.d.ts +1 -2
- package/build/lib/LayeredCache.js +7 -9
- package/build/lib/MemoryCache.d.ts +1 -2
- package/build/lib/MemoryCache.js +2 -1
- package/build/lib/createAsyncProxy.d.ts +2 -2
- package/build/lib/createAsyncProxy.js +2 -1
- package/build/lib/createCacheTimestampComparator.d.ts +1 -2
- package/build/lib/createCacheTimestampComparator.js +2 -1
- package/build/lib/downloadDictionary.d.ts +1 -2
- package/build/lib/downloadDictionary.js +5 -7
- package/build/lib/getDictionaryFilepath.d.ts +1 -2
- package/build/lib/getDictionaryFilepath.js +2 -1
- package/build/lib/index.d.ts +7 -7
- package/build/lib/index.js +7 -10
- package/build/{types/Cache.d.ts → types.d.ts} +1 -2
- package/package.json +5 -5
- package/src/Dictionaries.ts +3 -4
- package/src/index.ts +2 -1
- package/src/lib/DiskCache.ts +2 -4
- package/src/lib/LayeredCache.ts +4 -6
- package/src/lib/MemoryCache.ts +2 -3
- package/src/lib/createAsyncProxy.ts +1 -3
- package/src/lib/createCacheTimestampComparator.ts +1 -3
- package/src/lib/downloadDictionary.ts +2 -4
- package/src/lib/getDictionaryFilepath.ts +1 -3
- package/src/lib/index.ts +7 -7
- package/src/{types/Cache.ts → types.ts} +1 -3
- package/build/types/index.d.ts +0 -1
- package/build/types/index.js +0 -2
- package/src/types/index.ts +0 -1
- /package/build/{constants/index.d.ts → constants.d.ts} +0 -0
- /package/build/{constants/index.js → constants.js} +0 -0
- /package/build/{types/Cache.js → types.js} +0 -0
- /package/src/{constants/index.ts → constants.ts} +0 -0
package/LICENSE
CHANGED
package/build/Dictionaries.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
|
-
declare class Dictionaries {
|
|
3
|
+
export declare class Dictionaries {
|
|
4
4
|
private readonly cache;
|
|
5
5
|
private readonly downloadDictionaryProxies;
|
|
6
6
|
constructor();
|
|
@@ -10,4 +10,3 @@ declare class Dictionaries {
|
|
|
10
10
|
private getLocalesToUpdate;
|
|
11
11
|
private updateDictionary;
|
|
12
12
|
}
|
|
13
|
-
export default Dictionaries;
|
package/build/Dictionaries.js
CHANGED
|
@@ -3,7 +3,8 @@ 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
|
-
|
|
6
|
+
exports.Dictionaries = void 0;
|
|
7
|
+
const logger_1 = require("@scrabble-solver/logger");
|
|
7
8
|
const types_1 = require("@scrabble-solver/types");
|
|
8
9
|
const fs_1 = __importDefault(require("fs"));
|
|
9
10
|
const constants_1 = require("./constants");
|
|
@@ -20,7 +21,7 @@ class Dictionaries {
|
|
|
20
21
|
return trie;
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
|
-
logger_1.
|
|
24
|
+
logger_1.logger.info('Dictionaries - cache miss', { locale });
|
|
24
25
|
return this.updateDictionary(locale);
|
|
25
26
|
}
|
|
26
27
|
remove() {
|
|
@@ -28,14 +29,14 @@ class Dictionaries {
|
|
|
28
29
|
}
|
|
29
30
|
async update(force) {
|
|
30
31
|
const locales = force ? Object.values(types_1.Locale) : this.getLocalesToUpdate();
|
|
31
|
-
logger_1.
|
|
32
|
+
logger_1.logger.info('Dictionaries - update', { force, locales });
|
|
32
33
|
await Promise.all(locales.map((locale) => this.updateDictionary(locale)));
|
|
33
34
|
}
|
|
34
35
|
getLocalesToUpdate() {
|
|
35
36
|
return Object.values(types_1.Locale).filter((locale) => this.cache.isStale(locale) !== false);
|
|
36
37
|
}
|
|
37
38
|
async updateDictionary(locale) {
|
|
38
|
-
logger_1.
|
|
39
|
+
logger_1.logger.info('Dictionaries - updateDictionary', { locale });
|
|
39
40
|
fs_1.default.mkdirSync(constants_1.OUTPUT_DIRECTORY, { recursive: true });
|
|
40
41
|
const downloadDictionaryProxy = this.downloadDictionaryProxies[locale];
|
|
41
42
|
const trie = await downloadDictionaryProxy();
|
|
@@ -43,4 +44,4 @@ class Dictionaries {
|
|
|
43
44
|
return trie;
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
|
-
exports.
|
|
47
|
+
exports.Dictionaries = Dictionaries;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -13,11 +13,8 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
13
13
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
17
|
exports.dictionaries = void 0;
|
|
21
|
-
const Dictionaries_1 =
|
|
18
|
+
const Dictionaries_1 = require("./Dictionaries");
|
|
22
19
|
__exportStar(require("./lib"), exports);
|
|
23
|
-
exports.dictionaries = new Dictionaries_1.
|
|
20
|
+
exports.dictionaries = new Dictionaries_1.Dictionaries();
|
package/build/lib/DiskCache.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
3
|
import { Cache } from '../types';
|
|
4
|
-
declare class DiskCache implements Cache<Locale, Trie> {
|
|
4
|
+
export declare class DiskCache implements Cache<Locale, Trie> {
|
|
5
5
|
get(locale: Locale): Promise<Trie | undefined>;
|
|
6
6
|
getLastModifiedTimestamp(locale: Locale): number | undefined;
|
|
7
7
|
has(locale: Locale): boolean;
|
|
8
8
|
isStale(locale: Locale): boolean | undefined;
|
|
9
9
|
set(locale: Locale, trie: Trie): Promise<void>;
|
|
10
10
|
}
|
|
11
|
-
export default DiskCache;
|
package/build/lib/DiskCache.js
CHANGED
|
@@ -3,22 +3,23 @@ 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.DiskCache = void 0;
|
|
6
7
|
const trie_1 = require("@kamilmielnik/trie");
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const constants_1 = require("../constants");
|
|
9
|
-
const getDictionaryFilepath_1 =
|
|
10
|
+
const getDictionaryFilepath_1 = require("./getDictionaryFilepath");
|
|
10
11
|
class DiskCache {
|
|
11
12
|
async get(locale) {
|
|
12
13
|
if (!this.has(locale)) {
|
|
13
14
|
return undefined;
|
|
14
15
|
}
|
|
15
|
-
const filepath = (0, getDictionaryFilepath_1.
|
|
16
|
+
const filepath = (0, getDictionaryFilepath_1.getDictionaryFilepath)(locale);
|
|
16
17
|
const serialized = await fs_1.default.promises.readFile(filepath, 'utf-8');
|
|
17
18
|
const trie = trie_1.Trie.deserialize(serialized);
|
|
18
19
|
return trie;
|
|
19
20
|
}
|
|
20
21
|
getLastModifiedTimestamp(locale) {
|
|
21
|
-
const filepath = (0, getDictionaryFilepath_1.
|
|
22
|
+
const filepath = (0, getDictionaryFilepath_1.getDictionaryFilepath)(locale);
|
|
22
23
|
if (!fs_1.default.existsSync(filepath)) {
|
|
23
24
|
return undefined;
|
|
24
25
|
}
|
|
@@ -26,7 +27,7 @@ class DiskCache {
|
|
|
26
27
|
return stats.mtimeMs;
|
|
27
28
|
}
|
|
28
29
|
has(locale) {
|
|
29
|
-
const filepath = (0, getDictionaryFilepath_1.
|
|
30
|
+
const filepath = (0, getDictionaryFilepath_1.getDictionaryFilepath)(locale);
|
|
30
31
|
return fs_1.default.existsSync(filepath);
|
|
31
32
|
}
|
|
32
33
|
isStale(locale) {
|
|
@@ -41,8 +42,8 @@ class DiskCache {
|
|
|
41
42
|
return timeSinceModification > constants_1.CACHE_STALE_THRESHOLD;
|
|
42
43
|
}
|
|
43
44
|
async set(locale, trie) {
|
|
44
|
-
const filepath = (0, getDictionaryFilepath_1.
|
|
45
|
+
const filepath = (0, getDictionaryFilepath_1.getDictionaryFilepath)(locale);
|
|
45
46
|
await fs_1.default.promises.writeFile(filepath, trie.serialize());
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
|
-
exports.
|
|
49
|
+
exports.DiskCache = DiskCache;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
3
|
import { Cache } from '../types';
|
|
4
|
-
declare class LayeredCache implements Cache<Locale, Trie> {
|
|
4
|
+
export declare class LayeredCache implements Cache<Locale, Trie> {
|
|
5
5
|
private readonly layers;
|
|
6
6
|
get(locale: Locale): Promise<Trie | undefined>;
|
|
7
7
|
getLastModifiedTimestamp(locale: Locale): number | undefined;
|
|
@@ -10,4 +10,3 @@ declare class LayeredCache implements Cache<Locale, Trie> {
|
|
|
10
10
|
set(locale: Locale, trie: Trie): Promise<void>;
|
|
11
11
|
private getLastModifiedLayer;
|
|
12
12
|
}
|
|
13
|
-
export default LayeredCache;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
3
|
+
exports.LayeredCache = void 0;
|
|
4
|
+
const createCacheTimestampComparator_1 = require("./createCacheTimestampComparator");
|
|
5
|
+
const DiskCache_1 = require("./DiskCache");
|
|
6
|
+
const MemoryCache_1 = require("./MemoryCache");
|
|
9
7
|
class LayeredCache {
|
|
10
8
|
constructor() {
|
|
11
|
-
this.layers = [new MemoryCache_1.
|
|
9
|
+
this.layers = [new MemoryCache_1.MemoryCache(), new DiskCache_1.DiskCache()];
|
|
12
10
|
}
|
|
13
11
|
async get(locale) {
|
|
14
12
|
const cache = this.getLastModifiedLayer(locale);
|
|
@@ -48,8 +46,8 @@ class LayeredCache {
|
|
|
48
46
|
}
|
|
49
47
|
getLastModifiedLayer(locale) {
|
|
50
48
|
const layers = this.layers.filter((cache) => cache.has(locale));
|
|
51
|
-
const [cached] = [...layers].sort((0, createCacheTimestampComparator_1.
|
|
49
|
+
const [cached] = [...layers].sort((0, createCacheTimestampComparator_1.createCacheTimestampComparator)(locale));
|
|
52
50
|
return cached;
|
|
53
51
|
}
|
|
54
52
|
}
|
|
55
|
-
exports.
|
|
53
|
+
exports.LayeredCache = LayeredCache;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
3
|
import { Cache } from '../types';
|
|
4
|
-
declare class MemoryCache implements Cache<Locale, Trie> {
|
|
4
|
+
export declare class MemoryCache implements Cache<Locale, Trie> {
|
|
5
5
|
private readonly cache;
|
|
6
6
|
private readonly cacheTimestamps;
|
|
7
7
|
get(locale: Locale): Promise<Trie | undefined>;
|
|
@@ -10,4 +10,3 @@ declare class MemoryCache implements Cache<Locale, Trie> {
|
|
|
10
10
|
isStale(locale: Locale): boolean | undefined;
|
|
11
11
|
set(locale: Locale, trie: Trie): Promise<void>;
|
|
12
12
|
}
|
|
13
|
-
export default MemoryCache;
|
package/build/lib/MemoryCache.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryCache = void 0;
|
|
3
4
|
const constants_1 = require("../constants");
|
|
4
5
|
class MemoryCache {
|
|
5
6
|
constructor() {
|
|
@@ -29,4 +30,4 @@ class MemoryCache {
|
|
|
29
30
|
return Promise.resolve();
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
exports.
|
|
33
|
+
exports.MemoryCache = MemoryCache;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
type AsyncCallback<T> = () => Promise<T>;
|
|
2
|
-
declare const createAsyncProxy: <T>(asyncCallback: AsyncCallback<T>) => AsyncCallback<T>;
|
|
3
|
-
export
|
|
2
|
+
export declare const createAsyncProxy: <T>(asyncCallback: AsyncCallback<T>) => AsyncCallback<T>;
|
|
3
|
+
export {};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createAsyncProxy = void 0;
|
|
3
4
|
const createAsyncProxy = (asyncCallback) => {
|
|
4
5
|
let promise = null;
|
|
5
6
|
return async () => {
|
|
@@ -15,4 +16,4 @@ const createAsyncProxy = (asyncCallback) => {
|
|
|
15
16
|
}
|
|
16
17
|
};
|
|
17
18
|
};
|
|
18
|
-
exports.
|
|
19
|
+
exports.createAsyncProxy = createAsyncProxy;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
3
|
import { Cache } from '../types';
|
|
4
|
-
declare const createCacheTimestampComparator: (locale: Locale) => (a: Cache<Locale, Trie>, b: Cache<Locale, Trie>) => number;
|
|
5
|
-
export default createCacheTimestampComparator;
|
|
4
|
+
export declare const createCacheTimestampComparator: (locale: Locale) => (a: Cache<Locale, Trie>, b: Cache<Locale, Trie>) => number;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCacheTimestampComparator = void 0;
|
|
3
4
|
const createCacheTimestampComparator = (locale) => {
|
|
4
5
|
return (a, b) => {
|
|
5
6
|
const aTimestamp = a.getLastModifiedTimestamp(locale);
|
|
@@ -16,4 +17,4 @@ const createCacheTimestampComparator = (locale) => {
|
|
|
16
17
|
return bTimestamp - aTimestamp;
|
|
17
18
|
};
|
|
18
19
|
};
|
|
19
|
-
exports.
|
|
20
|
+
exports.createCacheTimestampComparator = createCacheTimestampComparator;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
2
|
import { Locale } from '@scrabble-solver/types';
|
|
3
|
-
declare const downloadDictionary: (locale: Locale) => Promise<Trie>;
|
|
4
|
-
export default downloadDictionary;
|
|
3
|
+
export declare const downloadDictionary: (locale: Locale) => Promise<Trie>;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadDictionary = void 0;
|
|
6
4
|
const trie_1 = require("@kamilmielnik/trie");
|
|
7
|
-
const logger_1 =
|
|
5
|
+
const logger_1 = require("@scrabble-solver/logger");
|
|
8
6
|
const word_lists_1 = require("@scrabble-solver/word-lists");
|
|
9
7
|
const downloadDictionary = async (locale) => {
|
|
10
|
-
logger_1.
|
|
8
|
+
logger_1.logger.info('downloadDictionary', { locale });
|
|
11
9
|
const words = await (0, word_lists_1.getWordList)(locale);
|
|
12
|
-
logger_1.
|
|
10
|
+
logger_1.logger.info('downloadDictionary - success', { locale });
|
|
13
11
|
const trie = trie_1.Trie.fromArray(words);
|
|
14
12
|
return trie;
|
|
15
13
|
};
|
|
16
|
-
exports.
|
|
14
|
+
exports.downloadDictionary = downloadDictionary;
|
|
@@ -3,9 +3,10 @@ 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.getDictionaryFilepath = void 0;
|
|
6
7
|
const path_1 = __importDefault(require("path"));
|
|
7
8
|
const constants_1 = require("../constants");
|
|
8
9
|
const getDictionaryFilepath = (locale) => {
|
|
9
10
|
return path_1.default.resolve(constants_1.OUTPUT_DIRECTORY, `${locale}.txt`);
|
|
10
11
|
};
|
|
11
|
-
exports.
|
|
12
|
+
exports.getDictionaryFilepath = getDictionaryFilepath;
|
package/build/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
1
|
+
export { createAsyncProxy } from './createAsyncProxy';
|
|
2
|
+
export { createCacheTimestampComparator } from './createCacheTimestampComparator';
|
|
3
|
+
export { DiskCache } from './DiskCache';
|
|
4
|
+
export { downloadDictionary } from './downloadDictionary';
|
|
5
|
+
export { getDictionaryFilepath } from './getDictionaryFilepath';
|
|
6
|
+
export { LayeredCache } from './LayeredCache';
|
|
7
|
+
export { MemoryCache } from './MemoryCache';
|
package/build/lib/index.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.MemoryCache = exports.LayeredCache = exports.getDictionaryFilepath = exports.downloadDictionary = exports.DiskCache = exports.createCacheTimestampComparator = exports.createAsyncProxy = void 0;
|
|
7
4
|
var createAsyncProxy_1 = require("./createAsyncProxy");
|
|
8
|
-
Object.defineProperty(exports, "createAsyncProxy", { enumerable: true, get: function () { return
|
|
5
|
+
Object.defineProperty(exports, "createAsyncProxy", { enumerable: true, get: function () { return createAsyncProxy_1.createAsyncProxy; } });
|
|
9
6
|
var createCacheTimestampComparator_1 = require("./createCacheTimestampComparator");
|
|
10
|
-
Object.defineProperty(exports, "createCacheTimestampComparator", { enumerable: true, get: function () { return
|
|
7
|
+
Object.defineProperty(exports, "createCacheTimestampComparator", { enumerable: true, get: function () { return createCacheTimestampComparator_1.createCacheTimestampComparator; } });
|
|
11
8
|
var DiskCache_1 = require("./DiskCache");
|
|
12
|
-
Object.defineProperty(exports, "DiskCache", { enumerable: true, get: function () { return
|
|
9
|
+
Object.defineProperty(exports, "DiskCache", { enumerable: true, get: function () { return DiskCache_1.DiskCache; } });
|
|
13
10
|
var downloadDictionary_1 = require("./downloadDictionary");
|
|
14
|
-
Object.defineProperty(exports, "downloadDictionary", { enumerable: true, get: function () { return
|
|
11
|
+
Object.defineProperty(exports, "downloadDictionary", { enumerable: true, get: function () { return downloadDictionary_1.downloadDictionary; } });
|
|
15
12
|
var getDictionaryFilepath_1 = require("./getDictionaryFilepath");
|
|
16
|
-
Object.defineProperty(exports, "getDictionaryFilepath", { enumerable: true, get: function () { return
|
|
13
|
+
Object.defineProperty(exports, "getDictionaryFilepath", { enumerable: true, get: function () { return getDictionaryFilepath_1.getDictionaryFilepath; } });
|
|
17
14
|
var LayeredCache_1 = require("./LayeredCache");
|
|
18
|
-
Object.defineProperty(exports, "LayeredCache", { enumerable: true, get: function () { return
|
|
15
|
+
Object.defineProperty(exports, "LayeredCache", { enumerable: true, get: function () { return LayeredCache_1.LayeredCache; } });
|
|
19
16
|
var MemoryCache_1 = require("./MemoryCache");
|
|
20
|
-
Object.defineProperty(exports, "MemoryCache", { enumerable: true, get: function () { return
|
|
17
|
+
Object.defineProperty(exports, "MemoryCache", { enumerable: true, get: function () { return MemoryCache_1.MemoryCache; } });
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
interface Cache<Key extends string, Value> {
|
|
1
|
+
export interface Cache<Key extends string, Value> {
|
|
2
2
|
get(key: Key): Promise<Value | undefined>;
|
|
3
3
|
getLastModifiedTimestamp(key: Key): number | undefined;
|
|
4
4
|
has(key: Key): boolean;
|
|
5
5
|
isStale(key: Key): boolean | undefined;
|
|
6
6
|
set(key: Key, value: Value): Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
export default Cache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/dictionaries",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.10",
|
|
4
4
|
"description": "Scrabble Solver 2 - Dictionaries",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@kamilmielnik/trie": "^4.0.0",
|
|
33
|
-
"@scrabble-solver/logger": "^2.15.
|
|
34
|
-
"@scrabble-solver/types": "^2.15.
|
|
35
|
-
"@scrabble-solver/word-lists": "^2.15.
|
|
33
|
+
"@scrabble-solver/logger": "^2.15.10",
|
|
34
|
+
"@scrabble-solver/types": "^2.15.10",
|
|
35
|
+
"@scrabble-solver/word-lists": "^2.15.10"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "dab5a817c1bde1a3ebf8e8907215adf12af5cb27"
|
|
38
38
|
}
|
package/src/Dictionaries.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
|
-
import logger from '@scrabble-solver/logger';
|
|
2
|
+
import { logger } from '@scrabble-solver/logger';
|
|
3
3
|
import { Locale } from '@scrabble-solver/types';
|
|
4
4
|
import fs from 'fs';
|
|
5
5
|
|
|
@@ -7,8 +7,9 @@ import { OUTPUT_DIRECTORY } from './constants';
|
|
|
7
7
|
import { createAsyncProxy, downloadDictionary, LayeredCache } from './lib';
|
|
8
8
|
import { Cache } from './types';
|
|
9
9
|
|
|
10
|
-
class Dictionaries {
|
|
10
|
+
export class Dictionaries {
|
|
11
11
|
private readonly cache: Cache<Locale, Trie>;
|
|
12
|
+
|
|
12
13
|
private readonly downloadDictionaryProxies: Record<Locale, () => Promise<Trie>>;
|
|
13
14
|
|
|
14
15
|
constructor() {
|
|
@@ -54,5 +55,3 @@ class Dictionaries {
|
|
|
54
55
|
return trie;
|
|
55
56
|
}
|
|
56
57
|
}
|
|
57
|
-
|
|
58
|
-
export default Dictionaries;
|
package/src/index.ts
CHANGED
package/src/lib/DiskCache.ts
CHANGED
|
@@ -5,9 +5,9 @@ import fs from 'fs';
|
|
|
5
5
|
import { CACHE_STALE_THRESHOLD } from '../constants';
|
|
6
6
|
import { Cache } from '../types';
|
|
7
7
|
|
|
8
|
-
import getDictionaryFilepath from './getDictionaryFilepath';
|
|
8
|
+
import { getDictionaryFilepath } from './getDictionaryFilepath';
|
|
9
9
|
|
|
10
|
-
class DiskCache implements Cache<Locale, Trie> {
|
|
10
|
+
export class DiskCache implements Cache<Locale, Trie> {
|
|
11
11
|
public async get(locale: Locale): Promise<Trie | undefined> {
|
|
12
12
|
if (!this.has(locale)) {
|
|
13
13
|
return undefined;
|
|
@@ -55,5 +55,3 @@ class DiskCache implements Cache<Locale, Trie> {
|
|
|
55
55
|
await fs.promises.writeFile(filepath, trie.serialize());
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
export default DiskCache;
|
package/src/lib/LayeredCache.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { Locale } from '@scrabble-solver/types';
|
|
|
3
3
|
|
|
4
4
|
import { Cache } from '../types';
|
|
5
5
|
|
|
6
|
-
import createCacheTimestampComparator from './createCacheTimestampComparator';
|
|
7
|
-
import DiskCache from './DiskCache';
|
|
8
|
-
import MemoryCache from './MemoryCache';
|
|
6
|
+
import { createCacheTimestampComparator } from './createCacheTimestampComparator';
|
|
7
|
+
import { DiskCache } from './DiskCache';
|
|
8
|
+
import { MemoryCache } from './MemoryCache';
|
|
9
9
|
|
|
10
|
-
class LayeredCache implements Cache<Locale, Trie> {
|
|
10
|
+
export class LayeredCache implements Cache<Locale, Trie> {
|
|
11
11
|
private readonly layers = [new MemoryCache(), new DiskCache()];
|
|
12
12
|
|
|
13
13
|
public async get(locale: Locale): Promise<Trie | undefined> {
|
|
@@ -65,5 +65,3 @@ class LayeredCache implements Cache<Locale, Trie> {
|
|
|
65
65
|
return cached;
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
export default LayeredCache;
|
package/src/lib/MemoryCache.ts
CHANGED
|
@@ -4,8 +4,9 @@ import { Locale } from '@scrabble-solver/types';
|
|
|
4
4
|
import { CACHE_STALE_THRESHOLD } from '../constants';
|
|
5
5
|
import { Cache } from '../types';
|
|
6
6
|
|
|
7
|
-
class MemoryCache implements Cache<Locale, Trie> {
|
|
7
|
+
export class MemoryCache implements Cache<Locale, Trie> {
|
|
8
8
|
private readonly cache: Partial<Record<Locale, Trie>> = {};
|
|
9
|
+
|
|
9
10
|
private readonly cacheTimestamps: Partial<Record<Locale, number>> = {};
|
|
10
11
|
|
|
11
12
|
public get(locale: Locale): Promise<Trie | undefined> {
|
|
@@ -37,5 +38,3 @@ class MemoryCache implements Cache<Locale, Trie> {
|
|
|
37
38
|
return Promise.resolve();
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
|
-
|
|
41
|
-
export default MemoryCache;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type AsyncCallback<T> = () => Promise<T>;
|
|
2
2
|
|
|
3
|
-
const createAsyncProxy = <T>(asyncCallback: AsyncCallback<T>): AsyncCallback<T> => {
|
|
3
|
+
export const createAsyncProxy = <T>(asyncCallback: AsyncCallback<T>): AsyncCallback<T> => {
|
|
4
4
|
let promise: Promise<T> | null = null;
|
|
5
5
|
|
|
6
6
|
return async (): Promise<T> => {
|
|
@@ -16,5 +16,3 @@ const createAsyncProxy = <T>(asyncCallback: AsyncCallback<T>): AsyncCallback<T>
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
};
|
|
19
|
-
|
|
20
|
-
export default createAsyncProxy;
|
|
@@ -3,7 +3,7 @@ import { Locale } from '@scrabble-solver/types';
|
|
|
3
3
|
|
|
4
4
|
import { Cache } from '../types';
|
|
5
5
|
|
|
6
|
-
const createCacheTimestampComparator = (locale: Locale) => {
|
|
6
|
+
export const createCacheTimestampComparator = (locale: Locale) => {
|
|
7
7
|
return (a: Cache<Locale, Trie>, b: Cache<Locale, Trie>): number => {
|
|
8
8
|
const aTimestamp = a.getLastModifiedTimestamp(locale);
|
|
9
9
|
const bTimestamp = b.getLastModifiedTimestamp(locale);
|
|
@@ -23,5 +23,3 @@ const createCacheTimestampComparator = (locale: Locale) => {
|
|
|
23
23
|
return bTimestamp - aTimestamp;
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
export default createCacheTimestampComparator;
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
|
-
import logger from '@scrabble-solver/logger';
|
|
2
|
+
import { logger } from '@scrabble-solver/logger';
|
|
3
3
|
import { Locale } from '@scrabble-solver/types';
|
|
4
4
|
import { getWordList } from '@scrabble-solver/word-lists';
|
|
5
5
|
|
|
6
|
-
const downloadDictionary = async (locale: Locale): Promise<Trie> => {
|
|
6
|
+
export const downloadDictionary = async (locale: Locale): Promise<Trie> => {
|
|
7
7
|
logger.info('downloadDictionary', { locale });
|
|
8
8
|
const words = await getWordList(locale);
|
|
9
9
|
logger.info('downloadDictionary - success', { locale });
|
|
10
10
|
const trie = Trie.fromArray(words);
|
|
11
11
|
return trie;
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
export default downloadDictionary;
|
|
@@ -3,8 +3,6 @@ import path from 'path';
|
|
|
3
3
|
|
|
4
4
|
import { OUTPUT_DIRECTORY } from '../constants';
|
|
5
5
|
|
|
6
|
-
const getDictionaryFilepath = (locale: Locale): string => {
|
|
6
|
+
export const getDictionaryFilepath = (locale: Locale): string => {
|
|
7
7
|
return path.resolve(OUTPUT_DIRECTORY, `${locale}.txt`);
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
export default getDictionaryFilepath;
|
package/src/lib/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
1
|
+
export { createAsyncProxy } from './createAsyncProxy';
|
|
2
|
+
export { createCacheTimestampComparator } from './createCacheTimestampComparator';
|
|
3
|
+
export { DiskCache } from './DiskCache';
|
|
4
|
+
export { downloadDictionary } from './downloadDictionary';
|
|
5
|
+
export { getDictionaryFilepath } from './getDictionaryFilepath';
|
|
6
|
+
export { LayeredCache } from './LayeredCache';
|
|
7
|
+
export { MemoryCache } from './MemoryCache';
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
interface Cache<Key extends string, Value> {
|
|
1
|
+
export interface Cache<Key extends string, Value> {
|
|
2
2
|
get(key: Key): Promise<Value | undefined>;
|
|
3
3
|
getLastModifiedTimestamp(key: Key): number | undefined;
|
|
4
4
|
has(key: Key): boolean;
|
|
5
5
|
isStale(key: Key): boolean | undefined;
|
|
6
6
|
set(key: Key, value: Value): Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
export default Cache;
|
package/build/types/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Cache } from './Cache';
|
package/build/types/index.js
DELETED
package/src/types/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default as Cache } from './Cache';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|