@unchainedshop/core-warehousing 4.8.21 → 4.8.23
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.
|
@@ -31,7 +31,7 @@ export declare const configureWarehousingModule: ({ db }: ModuleInput<Record<str
|
|
|
31
31
|
walletAddresses: string[];
|
|
32
32
|
}, options?: mongodb.FindOptions) => Promise<TokenSurrogate[]>;
|
|
33
33
|
findProviders: (query?: WarehousingProviderQuery, options?: mongodb.FindOptions) => Promise<WarehousingProvider[]>;
|
|
34
|
-
allProviders: ()
|
|
34
|
+
allProviders: import("@unchainedshop/utils/lib/memoize-with-ttl.js").MemoizedWithTTL<[], mongodb.WithId<WarehousingProvider>[]>;
|
|
35
35
|
providerExists: ({ warehousingProviderId, }: {
|
|
36
36
|
warehousingProviderId: string;
|
|
37
37
|
}) => Promise<boolean>;
|
|
@@ -2,8 +2,7 @@ import { emit, registerEvents } from '@unchainedshop/events';
|
|
|
2
2
|
import { generateDbFilterById, generateDbObjectId, escapeRegexString, } from '@unchainedshop/mongodb';
|
|
3
3
|
import { WarehousingProvidersCollection, } from "../db/WarehousingProvidersCollection.js";
|
|
4
4
|
import { TokenSurrogateCollection } from "../db/TokenSurrogateCollection.js";
|
|
5
|
-
import
|
|
6
|
-
import ExpiryMap from 'expiry-map';
|
|
5
|
+
import { memoizeWithTTL } from '@unchainedshop/utils';
|
|
7
6
|
const WAREHOUSING_PROVIDER_EVENTS = [
|
|
8
7
|
'WAREHOUSING_PROVIDER_CREATE',
|
|
9
8
|
'WAREHOUSING_PROVIDER_UPDATE',
|
|
@@ -11,7 +10,6 @@ const WAREHOUSING_PROVIDER_EVENTS = [
|
|
|
11
10
|
'TOKEN_OWNERSHIP_CHANGED',
|
|
12
11
|
'TOKEN_INVALIDATED',
|
|
13
12
|
];
|
|
14
|
-
const allProvidersCache = new ExpiryMap(process.env.NODE_ENV === 'production' ? 60000 : 1);
|
|
15
13
|
export const buildFindSelector = ({ includeDeleted = false, queryString, warehousingProviderIds, type, } = {}) => {
|
|
16
14
|
const selector = includeDeleted ? {} : { deleted: null };
|
|
17
15
|
if (warehousingProviderIds) {
|
|
@@ -39,6 +37,7 @@ export const buildTokenFindSelector = ({ queryString, walletAddressExists, ...re
|
|
|
39
37
|
export const configureWarehousingModule = async ({ db }) => {
|
|
40
38
|
registerEvents(WAREHOUSING_PROVIDER_EVENTS);
|
|
41
39
|
const WarehousingProviders = await WarehousingProvidersCollection(db);
|
|
40
|
+
const allProviders = memoizeWithTTL(async () => WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray(), { ttl: process.env.NODE_ENV === 'production' ? 60000 : 1 });
|
|
42
41
|
const TokenSurrogates = await TokenSurrogateCollection(db);
|
|
43
42
|
return {
|
|
44
43
|
count: async (query = {}) => {
|
|
@@ -82,11 +81,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
82
81
|
const providers = WarehousingProviders.find(buildFindSelector(query), options);
|
|
83
82
|
return providers.toArray();
|
|
84
83
|
},
|
|
85
|
-
allProviders
|
|
86
|
-
return WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray();
|
|
87
|
-
}, {
|
|
88
|
-
cache: allProvidersCache,
|
|
89
|
-
}),
|
|
84
|
+
allProviders,
|
|
90
85
|
providerExists: async ({ warehousingProviderId, }) => {
|
|
91
86
|
const providerCount = await WarehousingProviders.countDocuments(generateDbFilterById(warehousingProviderId, { deleted: null }), { limit: 1 });
|
|
92
87
|
return !!providerCount;
|
|
@@ -151,7 +146,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
151
146
|
const warehousingProvider = (await WarehousingProviders.findOne({
|
|
152
147
|
_id: warehousingProviderId,
|
|
153
148
|
}));
|
|
154
|
-
|
|
149
|
+
allProviders.clear();
|
|
155
150
|
await emit('WAREHOUSING_PROVIDER_CREATE', { warehousingProvider });
|
|
156
151
|
return warehousingProvider;
|
|
157
152
|
},
|
|
@@ -164,7 +159,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
164
159
|
}, { returnDocument: 'after' });
|
|
165
160
|
if (!warehousingProvider)
|
|
166
161
|
return null;
|
|
167
|
-
|
|
162
|
+
allProviders.clear();
|
|
168
163
|
await emit('WAREHOUSING_PROVIDER_UPDATE', { warehousingProvider });
|
|
169
164
|
return warehousingProvider;
|
|
170
165
|
},
|
|
@@ -176,7 +171,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
176
171
|
}, { returnDocument: 'after' });
|
|
177
172
|
if (!warehousingProvider)
|
|
178
173
|
return null;
|
|
179
|
-
|
|
174
|
+
allProviders.clear();
|
|
180
175
|
await emit('WAREHOUSING_PROVIDER_REMOVE', { warehousingProvider });
|
|
181
176
|
return warehousingProvider;
|
|
182
177
|
},
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-warehousing",
|
|
3
3
|
"description": "Inventory and stock management module for the Unchained Engine",
|
|
4
|
-
"version": "4.8.
|
|
4
|
+
"version": "4.8.23",
|
|
5
5
|
"main": "lib/warehousing-index.js",
|
|
6
6
|
"types": "lib/warehousing-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -36,10 +36,8 @@
|
|
|
36
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@unchainedshop/events": "^4.8.12",
|
|
39
|
-
"@unchainedshop/
|
|
40
|
-
"@unchainedshop/utils": "^4.8.12"
|
|
41
|
-
"expiry-map": "^2.0.0",
|
|
42
|
-
"p-memoize": "^8.0.0"
|
|
39
|
+
"@unchainedshop/mongodb": "^4.8.12",
|
|
40
|
+
"@unchainedshop/utils": "^4.8.12"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
43
|
"@types/node": "^26.2.0",
|