@unchainedshop/core-warehousing 4.8.4 → 5.0.0-alpha.1
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, assertDocumentDBCompatMode, } 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) {
|
|
@@ -41,6 +40,9 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
41
40
|
registerEvents(WAREHOUSING_PROVIDER_EVENTS);
|
|
42
41
|
const WarehousingProviders = await WarehousingProvidersCollection(db);
|
|
43
42
|
const TokenSurrogates = await TokenSurrogateCollection(db);
|
|
43
|
+
const allProviders = memoizeWithTTL(async function () {
|
|
44
|
+
return WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray();
|
|
45
|
+
}, allProvidersTtlMs);
|
|
44
46
|
return {
|
|
45
47
|
count: async (query = {}) => {
|
|
46
48
|
const providerCount = await WarehousingProviders.countDocuments(buildFindSelector(query));
|
|
@@ -83,11 +85,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
83
85
|
const providers = WarehousingProviders.find(buildFindSelector(query), options);
|
|
84
86
|
return providers.toArray();
|
|
85
87
|
},
|
|
86
|
-
allProviders
|
|
87
|
-
return WarehousingProviders.find({ deleted: null }, { sort: { created: 1 } }).toArray();
|
|
88
|
-
}, {
|
|
89
|
-
cache: allProvidersCache,
|
|
90
|
-
}),
|
|
88
|
+
allProviders,
|
|
91
89
|
providerExists: async ({ warehousingProviderId, }) => {
|
|
92
90
|
const providerCount = await WarehousingProviders.countDocuments(generateDbFilterById(warehousingProviderId, { deleted: null }), { limit: 1 });
|
|
93
91
|
return !!providerCount;
|
|
@@ -155,7 +153,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
155
153
|
const warehousingProvider = (await WarehousingProviders.findOne({
|
|
156
154
|
_id: warehousingProviderId,
|
|
157
155
|
}));
|
|
158
|
-
|
|
156
|
+
allProviders.clear();
|
|
159
157
|
await emit('WAREHOUSING_PROVIDER_CREATE', { warehousingProvider });
|
|
160
158
|
return warehousingProvider;
|
|
161
159
|
},
|
|
@@ -168,7 +166,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
168
166
|
}, { returnDocument: 'after' });
|
|
169
167
|
if (!warehousingProvider)
|
|
170
168
|
return null;
|
|
171
|
-
|
|
169
|
+
allProviders.clear();
|
|
172
170
|
await emit('WAREHOUSING_PROVIDER_UPDATE', { warehousingProvider });
|
|
173
171
|
return warehousingProvider;
|
|
174
172
|
},
|
|
@@ -180,7 +178,7 @@ export const configureWarehousingModule = async ({ db }) => {
|
|
|
180
178
|
}, { returnDocument: 'after' });
|
|
181
179
|
if (!warehousingProvider)
|
|
182
180
|
return null;
|
|
183
|
-
|
|
181
|
+
allProviders.clear();
|
|
184
182
|
await emit('WAREHOUSING_PROVIDER_REMOVE', { warehousingProvider });
|
|
185
183
|
return warehousingProvider;
|
|
186
184
|
},
|
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.1",
|
|
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",
|