@unchainedshop/core-warehousing 4.8.11 → 5.0.0-alpha.2
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,9 @@ 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: () => Promise<mongodb.WithId<WarehousingProvider>[]
|
|
34
|
+
allProviders: (() => Promise<mongodb.WithId<WarehousingProvider>[]>) & {
|
|
35
|
+
clear: () => void;
|
|
36
|
+
};
|
|
35
37
|
providerExists: ({ warehousingProviderId, }: {
|
|
36
38
|
warehousingProviderId: string;
|
|
37
39
|
}) => 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,7 @@ const WAREHOUSING_PROVIDER_EVENTS = [
|
|
|
11
10
|
'TOKEN_OWNERSHIP_CHANGED',
|
|
12
11
|
'TOKEN_INVALIDATED',
|
|
13
12
|
];
|
|
14
|
-
const
|
|
13
|
+
const allProvidersTtlMs = process.env.NODE_ENV === 'production' ? 60000 : 1;
|
|
15
14
|
export const buildFindSelector = ({ includeDeleted = false, queryString, warehousingProviderIds, type, } = {}) => {
|
|
16
15
|
const selector = includeDeleted ? {} : { deleted: null };
|
|
17
16
|
if (warehousingProviderIds) {
|
|
@@ -40,6 +39,9 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
40
39
|
registerEvents(WAREHOUSING_PROVIDER_EVENTS);
|
|
41
40
|
const WarehousingProviders = await WarehousingProvidersCollection(db);
|
|
42
41
|
const TokenSurrogates = await TokenSurrogateCollection(db);
|
|
42
|
+
const allProviders = memoizeWithTTL(async function () {
|
|
43
|
+
return WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray();
|
|
44
|
+
}, allProvidersTtlMs);
|
|
43
45
|
return {
|
|
44
46
|
count: async (query = {}) => {
|
|
45
47
|
const providerCount = await WarehousingProviders.countDocuments(buildFindSelector(query));
|
|
@@ -82,11 +84,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
82
84
|
const providers = WarehousingProviders.find(buildFindSelector(query), options);
|
|
83
85
|
return providers.toArray();
|
|
84
86
|
},
|
|
85
|
-
allProviders
|
|
86
|
-
return WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray();
|
|
87
|
-
}, {
|
|
88
|
-
cache: allProvidersCache,
|
|
89
|
-
}),
|
|
87
|
+
allProviders,
|
|
90
88
|
providerExists: async ({ warehousingProviderId, }) => {
|
|
91
89
|
const providerCount = await WarehousingProviders.countDocuments(generateDbFilterById(warehousingProviderId, { deleted: null }), { limit: 1 });
|
|
92
90
|
return !!providerCount;
|
|
@@ -151,7 +149,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
151
149
|
const warehousingProvider = (await WarehousingProviders.findOne({
|
|
152
150
|
_id: warehousingProviderId,
|
|
153
151
|
}));
|
|
154
|
-
|
|
152
|
+
allProviders.clear();
|
|
155
153
|
await emit('WAREHOUSING_PROVIDER_CREATE', { warehousingProvider });
|
|
156
154
|
return warehousingProvider;
|
|
157
155
|
},
|
|
@@ -164,7 +162,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
164
162
|
}, { returnDocument: 'after' });
|
|
165
163
|
if (!warehousingProvider)
|
|
166
164
|
return null;
|
|
167
|
-
|
|
165
|
+
allProviders.clear();
|
|
168
166
|
await emit('WAREHOUSING_PROVIDER_UPDATE', { warehousingProvider });
|
|
169
167
|
return warehousingProvider;
|
|
170
168
|
},
|
|
@@ -176,7 +174,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
176
174
|
}, { returnDocument: 'after' });
|
|
177
175
|
if (!warehousingProvider)
|
|
178
176
|
return null;
|
|
179
|
-
|
|
177
|
+
allProviders.clear();
|
|
180
178
|
await emit('WAREHOUSING_PROVIDER_REMOVE', { warehousingProvider });
|
|
181
179
|
return warehousingProvider;
|
|
182
180
|
},
|
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
|
+
"version": "5.0.0-alpha.2",
|
|
5
5
|
"main": "lib/warehousing-index.js",
|
|
6
6
|
"types": "lib/warehousing-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -35,11 +35,9 @@
|
|
|
35
35
|
},
|
|
36
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/events": "^
|
|
39
|
-
"@unchainedshop/logger": "^
|
|
40
|
-
"@unchainedshop/utils": "^
|
|
41
|
-
"expiry-map": "^2.0.0",
|
|
42
|
-
"p-memoize": "^8.0.0"
|
|
38
|
+
"@unchainedshop/events": "^5.0.0-alpha.1",
|
|
39
|
+
"@unchainedshop/logger": "^5.0.0-alpha.1",
|
|
40
|
+
"@unchainedshop/utils": "^5.0.0-alpha.1"
|
|
43
41
|
},
|
|
44
42
|
"devDependencies": {
|
|
45
43
|
"@types/node": "^25.0.0",
|