@unchainedshop/mongodb 2.12.2 → 3.0.0-alpha2

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.
@@ -1,4 +1,3 @@
1
- import 'abort-controller/polyfill.js';
2
1
  import { Locale } from '@unchainedshop/types/common.js';
3
2
  import type { Collection, Document, Filter } from 'mongodb';
4
3
  export declare const findLocalizedText: <T extends Document>(collection: Collection<T>, selector: Filter<T>, locale: Locale) => Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"find-localized-text.d.ts","sourceRoot":"","sources":["../src/find-localized-text.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAC;AAEtC,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAgB5D,eAAO,MAAM,iBAAiB,GAAU,CAAC,SAAS,QAAQ,cAC5C,UAAU,CAAC,CAAC,CAAC,YACf,MAAM,CAAC,CAAC,CAAC,UACX,MAAM,KACb,OAAO,CAAC,CAAC,CAqCX,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"find-localized-text.d.ts","sourceRoot":"","sources":["../src/find-localized-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAU5D,eAAO,MAAM,iBAAiB,GAAU,CAAC,SAAS,QAAQ,cAC5C,UAAU,CAAC,CAAC,CAAC,YACf,MAAM,CAAC,CAAC,CAAC,UACX,MAAM,KACb,OAAO,CAAC,CAAC,CAwBX,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
@@ -1,9 +1,4 @@
1
- import 'abort-controller/polyfill.js';
2
- import * as lruCache from 'lru-cache';
3
1
  import { systemLocale } from '@unchainedshop/utils';
4
- const { NODE_ENV } = process.env;
5
- const ttl = NODE_ENV === 'production' ? 1000 * 10 : 0; // 10 seconds or 0 seconds
6
- const textCache = new lruCache.LRUCache({ max: 50000, ttl });
7
2
  const extendSelectorWithLocale = (selector, locale) => {
8
3
  const localeSelector = {
9
4
  locale: { $in: [locale.normalized, locale.language] },
@@ -11,19 +6,10 @@ const extendSelectorWithLocale = (selector, locale) => {
11
6
  return { ...localeSelector, ...selector };
12
7
  };
13
8
  export const findLocalizedText = async (collection, selector, locale) => {
14
- const cacheKey = JSON.stringify({
15
- n: collection.collectionName, // eslint-disable-line
16
- s: selector,
17
- l: locale,
18
- });
19
- const cachedText = textCache.get(cacheKey);
20
- if (cachedText)
21
- return cachedText;
22
9
  const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale), {
23
10
  sort: { updated: -1 },
24
11
  });
25
12
  if (exactTranslation) {
26
- textCache.set(cacheKey, exactTranslation);
27
13
  return exactTranslation;
28
14
  }
29
15
  if (systemLocale.normalized !== locale.normalized) {
@@ -31,14 +17,12 @@ export const findLocalizedText = async (collection, selector, locale) => {
31
17
  sort: { updated: -1 },
32
18
  });
33
19
  if (fallbackTranslation) {
34
- textCache.set(cacheKey, fallbackTranslation);
35
20
  return fallbackTranslation;
36
21
  }
37
22
  }
38
23
  const foundText = await collection.findOne(selector, {
39
24
  sort: { updated: -1 },
40
25
  });
41
- textCache.set(cacheKey, foundText);
42
26
  return foundText;
43
27
  };
44
28
  export default findLocalizedText;
@@ -1 +1 @@
1
- {"version":3,"file":"find-localized-text.js","sourceRoot":"","sources":["../src/find-localized-text.ts"],"names":[],"mappings":"AAAA,OAAO,8BAA8B,CAAC;AACtC,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AAGtC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjC,MAAM,GAAG,GAAG,QAAQ,KAA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;KACtB,CAAC,CAAC;IACH,IAAI,gBAAgB,EAAE,CAAC;QACrB,OAAO,gBAAqB,CAAC;IAC/B,CAAC;IAED,IAAI,YAAY,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC;QAClD,MAAM,mBAAmB,GAAG,MAAM,UAAU,CAAC,OAAO,CAClD,wBAAwB,CAAC,QAAQ,EAAE,YAAY,CAAC,EAChD;YACE,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;SACtB,CACF,CAAC;QACF,IAAI,mBAAmB,EAAE,CAAC;YACxB,OAAO,mBAAwB,CAAC;QAClC,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,QAAQ,EAAE;QACnD,IAAI,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,EAAE;KACtB,CAAC,CAAC;IACH,OAAO,SAAc,CAAC;AACxB,CAAC,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/mongodb",
3
- "version": "2.12.2",
3
+ "version": "3.0.0-alpha2",
4
4
  "description": "MongoDB provider for unchained platform",
5
5
  "main": "lib/mongodb-index.js",
6
6
  "exports": {
@@ -31,20 +31,19 @@
31
31
  },
32
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
33
33
  "dependencies": {
34
- "@unchainedshop/utils": "^2.12.2",
35
- "lru-cache": "^11.0.0"
34
+ "@unchainedshop/utils": "^3.0.0-alpha2"
36
35
  },
37
36
  "peerDependencies": {
38
37
  "@mongodb-js/zstd": "^1.2.0",
39
38
  "mongodb": "=6.7.0"
40
39
  },
41
40
  "optionalDependencies": {
42
- "mongodb-memory-server": "^9.3.0"
41
+ "mongodb-memory-server": "^10.0.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@types/node": "^20.14.10",
46
- "@unchainedshop/types": "^2.12.2",
44
+ "@types/node": "^20.14.12",
45
+ "@unchainedshop/types": "^3.0.0-alpha2",
47
46
  "jest": "^29.7.0",
48
- "typescript": "^5.5.3"
47
+ "typescript": "^5.5.4"
49
48
  }
50
49
  }
@@ -1,15 +1,7 @@
1
- import 'abort-controller/polyfill.js';
2
- import * as lruCache from 'lru-cache';
3
1
  import { Locale } from '@unchainedshop/types/common.js';
4
2
  import type { Collection, Document, Filter } from 'mongodb';
5
3
  import { systemLocale } from '@unchainedshop/utils';
6
4
 
7
- const { NODE_ENV } = process.env;
8
-
9
- const ttl = NODE_ENV === 'production' ? 1000 * 10 : 0; // 10 seconds or 0 seconds
10
-
11
- const textCache = new lruCache.LRUCache({ max: 50000, ttl });
12
-
13
5
  const extendSelectorWithLocale = (selector, locale) => {
14
6
  const localeSelector = {
15
7
  locale: { $in: [locale.normalized, locale.language] },
@@ -22,21 +14,10 @@ export const findLocalizedText = async <T extends Document>(
22
14
  selector: Filter<T>,
23
15
  locale: Locale,
24
16
  ): Promise<T> => {
25
- const cacheKey = JSON.stringify({
26
- n: collection.collectionName, // eslint-disable-line
27
- s: selector,
28
- l: locale,
29
- });
30
-
31
- const cachedText = textCache.get(cacheKey);
32
-
33
- if (cachedText) return cachedText as T;
34
-
35
17
  const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale), {
36
18
  sort: { updated: -1 },
37
19
  });
38
20
  if (exactTranslation) {
39
- textCache.set(cacheKey, exactTranslation);
40
21
  return exactTranslation as T;
41
22
  }
42
23
 
@@ -48,7 +29,6 @@ export const findLocalizedText = async <T extends Document>(
48
29
  },
49
30
  );
50
31
  if (fallbackTranslation) {
51
- textCache.set(cacheKey, fallbackTranslation);
52
32
  return fallbackTranslation as T;
53
33
  }
54
34
  }
@@ -56,7 +36,6 @@ export const findLocalizedText = async <T extends Document>(
56
36
  const foundText = await collection.findOne(selector, {
57
37
  sort: { updated: -1 },
58
38
  });
59
- textCache.set(cacheKey, foundText);
60
39
  return foundText as T;
61
40
  };
62
41