@unchainedshop/utils 1.2.2 → 1.2.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/lib/db/build-sort-option.d.ts +4 -0
- package/lib/{buildSortOption.js → db/build-sort-option.js} +1 -1
- package/lib/db/build-sort-option.js.map +1 -0
- package/lib/db/check-id.d.ts +2 -2
- package/lib/db/check-id.js.map +1 -1
- package/lib/db/generate-db-filter-by-id.d.ts +3 -4
- package/lib/db/generate-db-filter-by-id.js.map +1 -1
- package/lib/db/generate-db-mutations.d.ts +2 -1
- package/lib/db/generate-db-mutations.js.map +1 -1
- package/lib/find-localized-text.d.ts +3 -1
- package/lib/find-localized-text.js +3 -3
- package/lib/find-localized-text.js.map +1 -1
- package/lib/find-preserving-ids.js.map +1 -1
- package/lib/find-unused-slug.d.ts +7 -7
- package/lib/find-unused-slug.js +1 -1
- package/lib/find-unused-slug.js.map +1 -1
- package/lib/locale-helpers.d.ts +5 -5
- package/lib/locale-helpers.js.map +1 -1
- package/lib/object-invert.d.ts +1 -1
- package/lib/object-invert.js.map +1 -1
- package/lib/pipe-promises.d.ts +1 -1
- package/lib/pipe-promises.js.map +1 -1
- package/lib/slugify.d.ts +1 -1
- package/lib/slugify.js.map +1 -1
- package/lib/utils-index.d.ts +71 -36
- package/lib/utils-index.js +1 -1
- package/lib/utils-index.js.map +1 -1
- package/package.json +4 -4
- package/src/{buildSortOption.ts → db/build-sort-option.ts} +2 -1
- package/src/db/check-id.ts +9 -1
- package/src/db/generate-db-filter-by-id.ts +4 -4
- package/src/db/generate-db-mutations.ts +6 -11
- package/src/{find-localized-text.js → find-localized-text.ts} +13 -7
- package/src/find-preserving-ids.ts +3 -1
- package/src/{find-unused-slug.js → find-unused-slug.ts} +13 -2
- package/src/{locale-helpers.js → locale-helpers.ts} +0 -0
- package/src/{object-invert.js → object-invert.ts} +0 -0
- package/src/{pipe-promises.js → pipe-promises.ts} +0 -0
- package/src/{slugify.js → slugify.ts} +1 -1
- package/src/{utils-index.js → utils-index.ts} +1 -1
- package/lib/buildSortOption.d.ts +0 -5
- package/lib/buildSortOption.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-sort-option.js","sourceRoot":"","sources":["../../src/db/build-sort-option.ts"],"names":[],"mappings":"AAGA,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,OAA0B,EAAE,EAAQ,EAAE;IAC9D,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;QAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|
package/lib/db/check-id.d.ts
CHANGED
package/lib/db/check-id.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"check-id.js","sourceRoot":"","sources":["../../src/db/check-id.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"check-id.js","sourceRoot":"","sources":["../../src/db/check-id.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAa,EACb,KAKa,EACP,EAAE;IACR,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC7B,MAAM,KAAK,IAAI,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;KAC1C;AACH,CAAC,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { Filter,
|
|
2
|
-
export declare const generateDbFilterById:
|
|
3
|
-
[x: string]: any;
|
|
1
|
+
import { Filter, _ID } from '@unchainedshop/types/common';
|
|
2
|
+
export declare const generateDbFilterById: <T extends {
|
|
4
3
|
_id?: _ID;
|
|
5
|
-
}>;
|
|
4
|
+
}>(id: unknown, query?: Filter<T>) => Filter<T>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-filter-by-id.js","sourceRoot":"","sources":["../../src/db/generate-db-filter-by-id.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAW,EACX,
|
|
1
|
+
{"version":3,"file":"generate-db-filter-by-id.js","sourceRoot":"","sources":["../../src/db/generate-db-filter-by-id.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,EAAW,EACX,QAAmB,EAAE,EACV,EAAE;IACb,MAAM,GAAG,GAAG,EAAE,IAAI,IAAI,CAAC,CAAC,kDAAkD;IAC1E,OAAO,EAAE,GAAG,EAAE,GAAG,KAAK,EAAE,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Collection,
|
|
1
|
+
import { Collection, _ID, TimestampFields } from '@unchainedshop/types/common';
|
|
2
|
+
import { ModuleCreateMutation, ModuleMutations } from '@unchainedshop/types/core';
|
|
2
3
|
export declare const generateDbMutations: <T extends TimestampFields & {
|
|
3
4
|
_id?: _ID;
|
|
4
5
|
}>(collection: Collection<T>, schema: SimpleSchema, options?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-db-mutations.js","sourceRoot":"","sources":["../../src/db/generate-db-mutations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-db-mutations.js","sourceRoot":"","sources":["../../src/db/generate-db-mutations.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AA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ACb,MAAM,MAAM,GAAG,oBAAoB,CAAI,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC/D,MAAM,QAAQ,GAAG,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,IAAI,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC;gBACtE,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;gBAC5D,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAE1D,OAAO,MAAM,CAAC,aAAa,CAAC;YAC9B,CAAC;KACN,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
import 'abort-controller/polyfill';
|
|
2
|
+
import { Collection, Filter, Locale, Document } from '@unchainedshop/types/common';
|
|
3
|
+
declare const findLocalizedText: <T extends Document>(collection: Collection<T>, selector: Filter<T>, locale: Locale) => Promise<T>;
|
|
1
4
|
export default findLocalizedText;
|
|
2
|
-
declare function findLocalizedText(collection: any, selector: any, locale: any): Promise<any>;
|
|
@@ -12,20 +12,20 @@ const extendSelectorWithLocale = (selector, locale) => {
|
|
|
12
12
|
};
|
|
13
13
|
const findLocalizedText = async (collection, selector, locale) => {
|
|
14
14
|
const cacheKey = JSON.stringify({
|
|
15
|
-
n: collection.
|
|
15
|
+
n: collection.collectionName,
|
|
16
16
|
s: selector,
|
|
17
17
|
l: locale,
|
|
18
18
|
});
|
|
19
19
|
const cachedText = textCache.get(cacheKey);
|
|
20
20
|
if (cachedText)
|
|
21
21
|
return cachedText;
|
|
22
|
-
const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale));
|
|
22
|
+
const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale), {});
|
|
23
23
|
if (exactTranslation) {
|
|
24
24
|
textCache.set(cacheKey, exactTranslation);
|
|
25
25
|
return exactTranslation;
|
|
26
26
|
}
|
|
27
27
|
if (systemLocale.normalized !== locale.normalized) {
|
|
28
|
-
const fallbackTranslation = await collection.findOne(extendSelectorWithLocale(selector, systemLocale));
|
|
28
|
+
const fallbackTranslation = await collection.findOne(extendSelectorWithLocale(selector, systemLocale), {});
|
|
29
29
|
if (fallbackTranslation) {
|
|
30
30
|
textCache.set(cacheKey, fallbackTranslation);
|
|
31
31
|
return fallbackTranslation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-localized-text.js","sourceRoot":"","sources":["../src/find-localized-text.
|
|
1
|
+
{"version":3,"file":"find-localized-text.js","sourceRoot":"","sources":["../src/find-localized-text.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC;AACnC,OAAO,GAAG,MAAM,WAAW,CAAC;AAE5B,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAEjC,MAAM,GAAG,GAAG,QAAQ,KAAK,YAAY,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,yBAAyB;AAEhF,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AAE/C,MAAM,wBAAwB,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;IACpD,MAAM,cAAc,GAAG;QACrB,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE;KACtD,CAAC;IACF,OAAO,EAAE,GAAG,cAAc,EAAE,GAAG,QAAQ,EAAE,CAAC;AAC5C,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC7B,UAAyB,EACzB,QAAmB,EACnB,MAAc,EACF,EAAE;IACd,MAAM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AI,EAAE,MAAM,EAAE,KAAK,EAAE;KAC3B,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAElB,MAAM,kBAAkB,GAAG,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC,OAAO,EAAE,CAAC;IACjD,OAAO,KAAiB,CAAC;AAC3B,CAAC,CAAC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
declare
|
|
2
|
-
slugify:
|
|
3
|
-
})
|
|
4
|
-
title
|
|
5
|
-
existingSlug:
|
|
6
|
-
newSlug
|
|
7
|
-
}) =>
|
|
1
|
+
declare const _default: (checkSlugIsUniqueFn: (slug: string) => Promise<boolean>, { slugify }: {
|
|
2
|
+
slugify?: (text: string) => string;
|
|
3
|
+
}) => (params: {
|
|
4
|
+
title?: string;
|
|
5
|
+
existingSlug: string;
|
|
6
|
+
newSlug?: string;
|
|
7
|
+
}) => Promise<string>;
|
|
8
8
|
export default _default;
|
package/lib/find-unused-slug.js
CHANGED
|
@@ -9,7 +9,7 @@ const incrementSuffixedSlug = (slugIncludingSuffix, delimiter = DELIMITER) => {
|
|
|
9
9
|
return addSuffixToSlug(slugWithoutSuffix, suffixedIndex + 1);
|
|
10
10
|
};
|
|
11
11
|
export default (checkSlugIsUniqueFn, { slugify }) => {
|
|
12
|
-
const findUnusedSlug = async ({ title, existingSlug, newSlug }) => {
|
|
12
|
+
const findUnusedSlug = async ({ title, existingSlug, newSlug, }) => {
|
|
13
13
|
const slug = newSlug || existingSlug || `${slugify(title)}`;
|
|
14
14
|
if (!(await checkSlugIsUniqueFn(slug))) {
|
|
15
15
|
const isSlugAlreadySuffixed = !!newSlug;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"find-unused-slug.js","sourceRoot":"","sources":["../src/find-unused-slug.
|
|
1
|
+
{"version":3,"file":"find-unused-slug.js","sourceRoot":"","sources":["../src/find-unused-slug.ts"],"names":[],"m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.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
1
|
+
import localePkg from 'locale';
|
|
2
|
+
export declare const systemLocale: localePkg.Locale;
|
|
3
|
+
export declare const resolveBestSupported: (acceptLanguage: any, supportedLocales: any) => localePkg.Locale;
|
|
4
|
+
export declare const resolveBestCountry: (localeCountry: any, shopCountry: any, countries: any) => any;
|
|
5
|
+
export declare const resolveUserRemoteAddress: (req: any) => {
|
|
5
6
|
remoteAddress: any;
|
|
6
7
|
remotePort: any;
|
|
7
8
|
};
|
|
8
|
-
import localePkg from "locale";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"locale-helpers.js","sourceRoot":"","sources":["../src/locale-helpers.
|
|
1
|
+
{"version":3,"file":"locale-helpers.js","sourceRoot":"","sources":["../src/locale-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,QAAQ,CAAC;AAE/B,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;AAEtC,MAAM,EAAE,cAAc,GAAG,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;AAExE,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,IAAI,iBAAiB,EAAE,CAAC,CAAC;AAEjF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,cAAc,EAAE,gBAAgB,EAAE,EAAE;IACvE,MAAM,YAAY,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC,CAAC;IACjD,MAAM,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;IACvD,IAAI,CAAC,UAAU;QAAE,OAAO,YAAY,CAAC;IACrC,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE;IAC1E,IAAI,WAAW,EAAE;QACf,MAAM,eAAe,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,YAAY,EAAE,OAAO,EAAE,EAAE;YACjE,IAAI,WAAW,KAAK,OAAO,CAAC,OAAO,EAAE;gBACnC,OAAO,OAAO,CAAC,OAAO,CAAC;aACxB;YACD,OAAO,YAAY,CAAC;QACtB,CAAC,EAAE,IAAI,CAAC,CAAC;QACT,IAAI,eAAe,EAAE;YACnB,OAAO,eAAe,CAAC;SACxB;KACF;IACD,OAAO,aAAa,IAAI,YAAY,CAAC,OAAO,CAAC;AAC/C,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,GAAG,EAAE,EAAE;IAC9C,MAAM,aAAa,GACjB,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC;QACxB,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC;QAC9B,GAAG,CAAC,UAAU,CAAC,aAAa;QAC5B,GAAG,CAAC,MAAM,CAAC,aAAa;QACxB,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,CAAC;IAEtC,MAAM,UAAU,GACd,GAAG,CAAC,UAAU,EAAE,UAAU,IAAI,GAAG,CAAC,MAAM,EAAE,UAAU,IAAI,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC;IAE7F,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC;AACvC,CAAC,CAAC"}
|
package/lib/object-invert.d.ts
CHANGED
package/lib/object-invert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-invert.js","sourceRoot":"","sources":["../src/object-invert.
|
|
1
|
+
{"version":3,"file":"object-invert.js","sourceRoot":"","sources":["../src/object-invert.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,CAAC,YAAY,EAAE,EAAE,CACvC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,EAAE;IACpD,MAAM,MAAM,GAAG,WAAW,CAAC;IAC3B,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,GAAG,CAAC;IAChC,OAAO,MAAM,CAAC;AAChB,CAAC,EAAE,EAAE,CAAC,CAAC;AAET,eAAe,eAAe,CAAC"}
|
package/lib/pipe-promises.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare
|
|
1
|
+
declare const _default: (fns: any) => (initialValue: any) => any;
|
|
2
2
|
export default _default;
|
package/lib/pipe-promises.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipe-promises.js","sourceRoot":"","sources":["../src/pipe-promises.
|
|
1
|
+
{"version":3,"file":"pipe-promises.js","sourceRoot":"","sources":["../src/pipe-promises.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,YAAY,EAAE,EAAE,CACvC,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,CAAC"}
|
package/lib/slugify.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default function slugify(text:
|
|
1
|
+
export default function slugify(text: string): string;
|
package/lib/slugify.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slugify.js","sourceRoot":"","sources":["../src/slugify.
|
|
1
|
+
{"version":3,"file":"slugify.js","sourceRoot":"","sources":["../src/slugify.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,OAAO,CAAC,IAAY;IAC1C,OAAO,IAAI;SACR,QAAQ,EAAE;SACV,WAAW,EAAE;SACb,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,wBAAwB;SAC7C,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,4BAA4B;SACpD,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,mCAAmC;SACxD,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,4BAA4B;SAC/C,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,0BAA0B;AACnD,CAAC"}
|
package/lib/utils-index.d.ts
CHANGED
|
@@ -1,36 +1,71 @@
|
|
|
1
|
-
export { default as findLocalizedText } from
|
|
2
|
-
export * from
|
|
3
|
-
export { default as objectInvert } from
|
|
4
|
-
export { default as findUnusedSlug } from
|
|
5
|
-
export { default as slugify } from
|
|
6
|
-
export { default as pipePromises } from
|
|
7
|
-
export { default as generateRandomHash } from
|
|
8
|
-
export { default as randomValueHex } from
|
|
9
|
-
export { default as buildSortOptions } from
|
|
10
|
-
export { checkId } from
|
|
11
|
-
export { generateDbObjectId } from
|
|
12
|
-
export { generateDbFilterById } from
|
|
13
|
-
export { generateDbMutations } from
|
|
14
|
-
export { buildDbIndexes } from
|
|
15
|
-
export { findPreservingIds } from
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
1
|
+
export { default as findLocalizedText } from './find-localized-text';
|
|
2
|
+
export * from './locale-helpers';
|
|
3
|
+
export { default as objectInvert } from './object-invert';
|
|
4
|
+
export { default as findUnusedSlug } from './find-unused-slug';
|
|
5
|
+
export { default as slugify } from './slugify';
|
|
6
|
+
export { default as pipePromises } from './pipe-promises';
|
|
7
|
+
export { default as generateRandomHash } from './generate-random-hash';
|
|
8
|
+
export { default as randomValueHex } from './random-value-hex';
|
|
9
|
+
export { default as buildSortOptions } from './db/build-sort-option';
|
|
10
|
+
export { checkId } from './db/check-id';
|
|
11
|
+
export { generateDbObjectId } from './db/generate-db-object-id';
|
|
12
|
+
export { generateDbFilterById } from './db/generate-db-filter-by-id';
|
|
13
|
+
export { generateDbMutations } from './db/generate-db-mutations';
|
|
14
|
+
export { buildDbIndexes } from './db/build-db-indexes';
|
|
15
|
+
export { findPreservingIds } from './find-preserving-ids';
|
|
16
|
+
declare const Schemas: {
|
|
17
|
+
timestampFields: {
|
|
18
|
+
created: {
|
|
19
|
+
type: DateConstructor;
|
|
20
|
+
required: boolean;
|
|
21
|
+
};
|
|
22
|
+
createdBy: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
};
|
|
25
|
+
updated: {
|
|
26
|
+
type: DateConstructor;
|
|
27
|
+
};
|
|
28
|
+
updatedBy: {
|
|
29
|
+
type: StringConstructor;
|
|
30
|
+
};
|
|
31
|
+
deleted: {
|
|
32
|
+
type: DateConstructor;
|
|
33
|
+
};
|
|
34
|
+
deletedBy: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
contextFields: {
|
|
39
|
+
context: {
|
|
40
|
+
type: ObjectConstructor;
|
|
41
|
+
blackbox: boolean;
|
|
42
|
+
required: boolean;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
logFields: {
|
|
46
|
+
log: ArrayConstructor;
|
|
47
|
+
'log.$': {
|
|
48
|
+
type: ObjectConstructor;
|
|
49
|
+
};
|
|
50
|
+
'log.$.date': {
|
|
51
|
+
type: DateConstructor;
|
|
52
|
+
};
|
|
53
|
+
'log.$.status': {
|
|
54
|
+
type: StringConstructor;
|
|
55
|
+
};
|
|
56
|
+
'log.$.info': {
|
|
57
|
+
type: StringConstructor;
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
Address: any;
|
|
61
|
+
Contact: any;
|
|
62
|
+
User: any;
|
|
63
|
+
};
|
|
64
|
+
export { Schemas };
|
|
65
|
+
export { BaseAdapter } from './director/BaseAdapter';
|
|
66
|
+
export { BaseDirector } from './director/BaseDirector';
|
|
67
|
+
export { BasePricingAdapter } from './director/BasePricingAdapter';
|
|
68
|
+
export { BasePricingDirector } from './director/BasePricingDirector';
|
|
69
|
+
export { BasePricingSheet } from './director/BasePricingSheet';
|
|
70
|
+
export { BaseDiscountAdapter } from './director/BaseDiscountAdapter';
|
|
71
|
+
export { BaseDiscountDirector } from './director/BaseDiscountDirector';
|
package/lib/utils-index.js
CHANGED
|
@@ -10,7 +10,7 @@ export { default as slugify } from './slugify';
|
|
|
10
10
|
export { default as pipePromises } from './pipe-promises';
|
|
11
11
|
export { default as generateRandomHash } from './generate-random-hash';
|
|
12
12
|
export { default as randomValueHex } from './random-value-hex';
|
|
13
|
-
export { default as buildSortOptions } from './
|
|
13
|
+
export { default as buildSortOptions } from './db/build-sort-option';
|
|
14
14
|
/*
|
|
15
15
|
* Db utils
|
|
16
16
|
*/
|
package/lib/utils-index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../src/utils-index.
|
|
1
|
+
{"version":3,"file":"utils-index.js","sourceRoot":"","sources":["../src/utils-index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AACrE,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,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 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.12",
|
|
4
4
|
"main": "lib/utils-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/utils-index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@unchainedshop/logger": "
|
|
32
|
+
"@unchainedshop/logger": "1.x",
|
|
33
33
|
"abort-controller": "3.0.0",
|
|
34
34
|
"bson": "^4.6.4",
|
|
35
35
|
"hashids": "^2.2.10",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"simpl-schema": "^1.12.2"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"@types/node": "^16.11.
|
|
42
|
-
"@unchainedshop/types": "
|
|
41
|
+
"@types/node": "^16.11.48",
|
|
42
|
+
"@unchainedshop/types": "1.x",
|
|
43
43
|
"typescript": "^4.7.4"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { SortOption } from '@unchainedshop/types/api';
|
|
2
|
+
import { Sort } from '@unchainedshop/types/common';
|
|
2
3
|
|
|
3
4
|
const SORT_DIRECTIONS = {
|
|
4
5
|
ASC: 1,
|
|
5
6
|
DESC: -1,
|
|
6
7
|
};
|
|
7
8
|
|
|
8
|
-
const buildSortOptions = (sort: Array<SortOption> = []):
|
|
9
|
+
const buildSortOptions = (sort: Array<SortOption> = []): Sort => {
|
|
9
10
|
const sortBy = {};
|
|
10
11
|
sort?.forEach(({ key, value }) => {
|
|
11
12
|
sortBy[key] = SORT_DIRECTIONS[value];
|
package/src/db/check-id.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
export const checkId = (
|
|
1
|
+
export const checkId = (
|
|
2
|
+
value: string,
|
|
3
|
+
error?:
|
|
4
|
+
| {
|
|
5
|
+
message: string;
|
|
6
|
+
path?: string | undefined;
|
|
7
|
+
}
|
|
8
|
+
| undefined,
|
|
9
|
+
): void => {
|
|
2
10
|
if (typeof value !== 'string') {
|
|
3
11
|
throw error || { message: 'Invalid id' };
|
|
4
12
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Filter,
|
|
1
|
+
import { Filter, _ID } from '@unchainedshop/types/common';
|
|
2
2
|
|
|
3
|
-
export const generateDbFilterById = (
|
|
3
|
+
export const generateDbFilterById = <T extends { _id?: _ID }>(
|
|
4
4
|
id: unknown,
|
|
5
|
-
query:
|
|
6
|
-
): Filter<
|
|
5
|
+
query: Filter<T> = {},
|
|
6
|
+
): Filter<T> => {
|
|
7
7
|
const _id = id || null; // never undefined, else it will get the first one
|
|
8
8
|
return { _id, ...query };
|
|
9
9
|
};
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import SimpleSchema from 'simpl-schema';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
ModuleCreateMutation,
|
|
6
|
-
_ID,
|
|
7
|
-
Update,
|
|
8
|
-
TimestampFields,
|
|
9
|
-
} from '@unchainedshop/types/common';
|
|
2
|
+
import { Collection, _ID, Update, TimestampFields } from '@unchainedshop/types/common';
|
|
3
|
+
import { ModuleCreateMutation, ModuleMutations } from '@unchainedshop/types/core';
|
|
4
|
+
|
|
10
5
|
import { checkId } from './check-id';
|
|
11
6
|
import { generateDbObjectId } from './generate-db-object-id';
|
|
12
7
|
import { generateDbFilterById } from './generate-db-filter-by-id';
|
|
@@ -29,7 +24,7 @@ export const generateDbMutations = <T extends TimestampFields & { _id?: _ID }>(
|
|
|
29
24
|
|
|
30
25
|
const deletePermanently = async (_id) => {
|
|
31
26
|
checkId(_id);
|
|
32
|
-
const filter = generateDbFilterById(_id);
|
|
27
|
+
const filter = generateDbFilterById<T>(_id);
|
|
33
28
|
const result = await collection.deleteOne(filter);
|
|
34
29
|
return result.deletedCount;
|
|
35
30
|
};
|
|
@@ -75,7 +70,7 @@ export const generateDbMutations = <T extends TimestampFields & { _id?: _ID }>(
|
|
|
75
70
|
}
|
|
76
71
|
|
|
77
72
|
schema.validate(modifier, { modifier: true });
|
|
78
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
73
|
+
const filter = generateDbFilterById<T>(_id, { deleted: null });
|
|
79
74
|
await collection.updateOne(filter, modifier);
|
|
80
75
|
|
|
81
76
|
return _id;
|
|
@@ -90,7 +85,7 @@ export const generateDbMutations = <T extends TimestampFields & { _id?: _ID }>(
|
|
|
90
85
|
return deletePermanently(_id);
|
|
91
86
|
}
|
|
92
87
|
checkId(_id);
|
|
93
|
-
const filter = generateDbFilterById(_id, { deleted: null });
|
|
88
|
+
const filter = generateDbFilterById<T>(_id, { deleted: null });
|
|
94
89
|
const modifier = { $set: { deleted: new Date(), deletedBy: userId } };
|
|
95
90
|
const values = schema.clean(modifier, { isModifier: true });
|
|
96
91
|
const result = await collection.updateOne(filter, values);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import 'abort-controller/polyfill';
|
|
2
2
|
import LRU from 'lru-cache';
|
|
3
|
+
import { Collection, Filter, Locale, Document } from '@unchainedshop/types/common';
|
|
3
4
|
import { systemLocale } from './locale-helpers';
|
|
4
5
|
|
|
5
6
|
const { NODE_ENV } = process.env;
|
|
@@ -15,36 +16,41 @@ const extendSelectorWithLocale = (selector, locale) => {
|
|
|
15
16
|
return { ...localeSelector, ...selector };
|
|
16
17
|
};
|
|
17
18
|
|
|
18
|
-
const findLocalizedText = async
|
|
19
|
+
const findLocalizedText = async <T extends Document>(
|
|
20
|
+
collection: Collection<T>,
|
|
21
|
+
selector: Filter<T>,
|
|
22
|
+
locale: Locale,
|
|
23
|
+
): Promise<T> => {
|
|
19
24
|
const cacheKey = JSON.stringify({
|
|
20
|
-
n: collection.
|
|
25
|
+
n: collection.collectionName, // eslint-disable-line
|
|
21
26
|
s: selector,
|
|
22
27
|
l: locale,
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
const cachedText = textCache.get(cacheKey);
|
|
26
31
|
|
|
27
|
-
if (cachedText) return cachedText;
|
|
32
|
+
if (cachedText) return cachedText as T;
|
|
28
33
|
|
|
29
|
-
const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale));
|
|
34
|
+
const exactTranslation = await collection.findOne(extendSelectorWithLocale(selector, locale), {});
|
|
30
35
|
if (exactTranslation) {
|
|
31
36
|
textCache.set(cacheKey, exactTranslation);
|
|
32
|
-
return exactTranslation;
|
|
37
|
+
return exactTranslation as T;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
if (systemLocale.normalized !== locale.normalized) {
|
|
36
41
|
const fallbackTranslation = await collection.findOne(
|
|
37
42
|
extendSelectorWithLocale(selector, systemLocale),
|
|
43
|
+
{},
|
|
38
44
|
);
|
|
39
45
|
if (fallbackTranslation) {
|
|
40
46
|
textCache.set(cacheKey, fallbackTranslation);
|
|
41
|
-
return fallbackTranslation;
|
|
47
|
+
return fallbackTranslation as T;
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
const foundText = await collection.findOne(selector, {});
|
|
46
52
|
textCache.set(cacheKey, foundText);
|
|
47
|
-
return foundText;
|
|
53
|
+
return foundText as T;
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
export default findLocalizedText;
|
|
@@ -13,7 +13,9 @@ const sortBySequence = {
|
|
|
13
13
|
const defaultSort = AMAZON_DOCUMENTDB_COMPAT_MODE ? sortBySequence : sortByIndex;
|
|
14
14
|
|
|
15
15
|
export const findPreservingIds =
|
|
16
|
-
<T>(
|
|
16
|
+
<T>(
|
|
17
|
+
collection: Collection<T>,
|
|
18
|
+
): ((selector: Query, ids: Array<string>, options?: FindOptions) => Promise<Array<T>>) =>
|
|
17
19
|
async (selector: Query, ids: Array<string>, options?: FindOptions): Promise<Array<T>> => {
|
|
18
20
|
const { skip, limit, sort = defaultSort } = options || {};
|
|
19
21
|
const filteredSelector = {
|
|
@@ -11,8 +11,19 @@ const incrementSuffixedSlug = (slugIncludingSuffix, delimiter = DELIMITER) => {
|
|
|
11
11
|
return addSuffixToSlug(slugWithoutSuffix, suffixedIndex + 1);
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export default (
|
|
15
|
-
|
|
14
|
+
export default (
|
|
15
|
+
checkSlugIsUniqueFn: (slug: string) => Promise<boolean>,
|
|
16
|
+
{ slugify }: { slugify?: (text: string) => string },
|
|
17
|
+
): ((params: { title?: string; existingSlug: string; newSlug?: string }) => Promise<string>) => {
|
|
18
|
+
const findUnusedSlug = async ({
|
|
19
|
+
title,
|
|
20
|
+
existingSlug,
|
|
21
|
+
newSlug,
|
|
22
|
+
}: {
|
|
23
|
+
title?: string;
|
|
24
|
+
existingSlug?: string;
|
|
25
|
+
newSlug?: string;
|
|
26
|
+
}) => {
|
|
16
27
|
const slug = newSlug || existingSlug || `${slugify(title)}`;
|
|
17
28
|
if (!(await checkSlugIsUniqueFn(slug))) {
|
|
18
29
|
const isSlugAlreadySuffixed = !!newSlug;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -11,7 +11,7 @@ export { default as slugify } from './slugify';
|
|
|
11
11
|
export { default as pipePromises } from './pipe-promises';
|
|
12
12
|
export { default as generateRandomHash } from './generate-random-hash';
|
|
13
13
|
export { default as randomValueHex } from './random-value-hex';
|
|
14
|
-
export { default as buildSortOptions } from './
|
|
14
|
+
export { default as buildSortOptions } from './db/build-sort-option';
|
|
15
15
|
|
|
16
16
|
/*
|
|
17
17
|
* Db utils
|
package/lib/buildSortOption.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"buildSortOption.js","sourceRoot":"","sources":["../src/buildSortOption.ts"],"names":[],"mappings":"AAEA,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC,CAAC;CACT,CAAC;AAEF,MAAM,gBAAgB,GAAG,CAAC,OAA0B,EAAE,EAAsC,EAAE;IAC5F,MAAM,MAAM,GAAG,EAAE,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE;QAC/B,MAAM,CAAC,GAAG,CAAC,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|