@unchainedshop/core-currencies 4.0.0-rc.9 → 4.0.0
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/CurrenciesCollection.d.ts +1 -1
- package/lib/db/CurrenciesCollection.d.ts.map +1 -1
- package/lib/db/CurrenciesCollection.js +14 -10
- package/lib/db/CurrenciesCollection.js.map +1 -1
- package/lib/db/CurrenciesSchema.d.ts +3 -0
- package/lib/db/CurrenciesSchema.d.ts.map +1 -0
- package/lib/db/CurrenciesSchema.js +10 -0
- package/lib/db/CurrenciesSchema.js.map +1 -0
- package/lib/module/configureCurrenciesModule.d.ts +6 -5
- package/lib/module/configureCurrenciesModule.d.ts.map +1 -1
- package/lib/module/configureCurrenciesModule.js +10 -3
- package/lib/module/configureCurrenciesModule.js.map +1 -1
- package/package.json +3 -3
- package/src/db/CurrenciesCollection.ts +16 -11
- package/src/module/configureCurrenciesModule.ts +18 -10
- package/tsconfig.json +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrenciesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,
|
|
1
|
+
{"version":3,"file":"CurrenciesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAEP,eAAe,EAEhB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,eAAe,CAAC;AAEpB,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG;IACrD,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAU,IAAI,OAAO,CAAC,EAAE,0CA4BxD,CAAC"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
2
|
export const CurrenciesCollection = async (db) => {
|
|
3
3
|
const Currencies = db.collection('currencies');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
if (!isDocumentDBCompatModeEnabled()) {
|
|
5
|
+
await buildDbIndexes(Currencies, [
|
|
6
|
+
{
|
|
7
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
8
|
+
options: {
|
|
9
|
+
weights: {
|
|
10
|
+
_id: 8,
|
|
11
|
+
isoCode: 6,
|
|
12
|
+
},
|
|
13
|
+
name: 'currencies_fulltext_search',
|
|
12
14
|
},
|
|
13
|
-
name: 'currencies_fulltext_search',
|
|
14
15
|
},
|
|
15
|
-
|
|
16
|
+
]);
|
|
17
|
+
}
|
|
18
|
+
await buildDbIndexes(Currencies, [
|
|
19
|
+
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
16
20
|
{
|
|
17
21
|
index: {
|
|
18
22
|
deleted: 1,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrenciesCollection.js","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAgBhC,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IAC3D,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAW,YAAY,CAAC,CAAC;IAEzD,MAAM,cAAc,CAAW,UAAU,EAAE;
|
|
1
|
+
{"version":3,"file":"CurrenciesCollection.js","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EAEd,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAgBhC,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EAAE,EAAc,EAAE,EAAE;IAC3D,MAAM,UAAU,GAAG,EAAE,CAAC,UAAU,CAAW,YAAY,CAAC,CAAC;IAEzD,IAAI,CAAC,6BAA6B,EAAE,EAAE,CAAC;QACrC,MAAM,cAAc,CAAW,UAAU,EAAE;YACzC;gBACE,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;gBACvC,OAAO,EAAE;oBACP,OAAO,EAAE;wBACP,GAAG,EAAE,CAAC;wBACN,OAAO,EAAE,CAAC;qBACX;oBACD,IAAI,EAAE,4BAA4B;iBACnC;aACF;SACF,CAAC,CAAC;IACL,CAAC;IAED,MAAM,cAAc,CAAW,UAAU,EAAE;QACzC,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;QACpD;YACE,KAAK,EAAE;gBACL,OAAO,EAAE,CAAC;aACX;SACF;KACF,CAAC,CAAC;IAEH,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CurrenciesSchema.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,gBAAgB,cAS5B,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
+
import SimpleSchema from 'simpl-schema';
|
|
3
|
+
export const CurrenciesSchema = new SimpleSchema({
|
|
4
|
+
isoCode: { type: String, required: true },
|
|
5
|
+
isActive: Boolean,
|
|
6
|
+
contractAddress: { type: String, required: false },
|
|
7
|
+
decimals: { type: Number, required: false },
|
|
8
|
+
...Schemas.timestampFields,
|
|
9
|
+
}, { requiredByDefault: false });
|
|
10
|
+
//# sourceMappingURL=CurrenciesSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CurrenciesSchema.js","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAC9C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,OAAO;IACjB,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAClD,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC3C,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -3,10 +3,11 @@ import { SortOption } from '@unchainedshop/utils';
|
|
|
3
3
|
import { Currency, CurrencyQuery } from '../db/CurrenciesCollection.js';
|
|
4
4
|
export declare const buildFindSelector: ({ includeInactive, contractAddress, queryString, ...rest }: CurrencyQuery) => mongodb.Filter<Currency>;
|
|
5
5
|
export declare const configureCurrenciesModule: ({ db }: ModuleInput<Record<string, never>>) => Promise<{
|
|
6
|
-
findCurrency: (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
findCurrency: (params: {
|
|
7
|
+
isoCode: string;
|
|
8
|
+
} | {
|
|
9
|
+
currencyId: string;
|
|
10
|
+
}) => Promise<mongodb.WithId<Currency> | null>;
|
|
10
11
|
findCurrencies: ({ limit, offset, sort, ...query }: CurrencyQuery & {
|
|
11
12
|
limit?: number;
|
|
12
13
|
offset?: number;
|
|
@@ -16,7 +17,7 @@ export declare const configureCurrenciesModule: ({ db }: ModuleInput<Record<stri
|
|
|
16
17
|
currencyExists: ({ currencyId }: {
|
|
17
18
|
currencyId: string;
|
|
18
19
|
}) => Promise<boolean>;
|
|
19
|
-
create: (doc: Currency) => Promise<string>;
|
|
20
|
+
create: (doc: Omit<Currency, "_id" | "created"> & Pick<Partial<Currency>, "_id" | "created">) => Promise<string>;
|
|
20
21
|
update: (currencyId: string, doc: Partial<Currency>) => Promise<string>;
|
|
21
22
|
delete: (currencyId: string) => Promise<number>;
|
|
22
23
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCurrenciesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EAEX,OAAO,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAiB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAwB,QAAQ,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9F,eAAO,MAAM,iBAAiB,GAAI,4DAK/B,aAAa,6BAYf,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAU,QAAQ,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"configureCurrenciesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,WAAW,EAEX,OAAO,EACR,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAiB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAwB,QAAQ,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAI9F,eAAO,MAAM,iBAAiB,GAAI,4DAK/B,aAAa,6BAYf,CAAC;AAEF,eAAO,MAAM,yBAAyB,GAAU,QAAQ,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;2BAQhF;QACE,OAAO,EAAE,MAAM,CAAC;KACjB,GACD;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;wDAczB,aAAa,GAAG;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;KACrB,KAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;mBAUF,aAAa;qCAKK;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE;kBAWtD,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;yBAc1D,MAAM,OAAO,OAAO,CAAC,QAAQ,CAAC;yBAc9B,MAAM;EAapC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC"}
|
|
@@ -22,8 +22,13 @@ export const configureCurrenciesModule = async ({ db }) => {
|
|
|
22
22
|
registerEvents(CURRENCY_EVENTS);
|
|
23
23
|
const Currencies = await CurrenciesCollection(db);
|
|
24
24
|
return {
|
|
25
|
-
findCurrency: async (
|
|
26
|
-
|
|
25
|
+
findCurrency: async (params) => {
|
|
26
|
+
if ('currencyId' in params) {
|
|
27
|
+
return Currencies.findOne(generateDbFilterById(params.currencyId));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return Currencies.findOne({ isoCode: params.isoCode });
|
|
31
|
+
}
|
|
27
32
|
},
|
|
28
33
|
findCurrencies: async ({ limit, offset, sort, ...query }) => {
|
|
29
34
|
const defaultSort = [{ key: 'created', value: SortDirection.ASC }];
|
|
@@ -57,11 +62,13 @@ export const configureCurrenciesModule = async ({ db }) => {
|
|
|
57
62
|
return currencyId;
|
|
58
63
|
},
|
|
59
64
|
update: async (currencyId, doc) => {
|
|
65
|
+
if (doc.isoCode) {
|
|
66
|
+
doc.isoCode = doc.isoCode.toUpperCase();
|
|
67
|
+
}
|
|
60
68
|
await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
61
69
|
$set: {
|
|
62
70
|
updated: new Date(),
|
|
63
71
|
...doc,
|
|
64
|
-
isoCode: doc.isoCode.toUpperCase(),
|
|
65
72
|
},
|
|
66
73
|
});
|
|
67
74
|
await emit('CURRENCY_UPDATE', { currencyId });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,EAElB,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAc,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAA2B,MAAM,+BAA+B,CAAC;AAE9F,MAAM,eAAe,GAAa,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAE5F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,eAAe,GAAG,KAAK,EACvB,eAAe,EACf,WAAW,EACX,GAAG,IAAI,EACO,EAAE,EAAE;IAClB,MAAM,QAAQ,GAA6B;QACzC,GAAG,IAAI;QACP,OAAO,EAAE,IAAI;KACd,CAAC;IACF,IAAI,CAAC,eAAe;QAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,IAAI,e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AI,IAAI,EAAE;oBACnB,GAAG,GAAG;iBACP;aACF,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,UAAkB,EAAE,EAAE;YACnC,MAAM,EAAE,aAAa,EAAE,YAAY,EAAE,GAAG,MAAM,UAAU,CAAC,SAAS,CAChE,oBAAoB,CAAC,UAAU,CAAC,EAChC;gBACE,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,IAAI,EAAE;iBACpB;aACF,CACF,CAAC;YACF,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-currencies",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"main": "lib/currencies-index.js",
|
|
5
5
|
"types": "lib/currencies-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^4.0.0
|
|
35
|
-
"@unchainedshop/utils": "^4.0.0
|
|
34
|
+
"@unchainedshop/events": "^4.0.0",
|
|
35
|
+
"@unchainedshop/utils": "^4.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^24.0.13",
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
} from '@unchainedshop/mongodb';
|
|
7
7
|
|
|
8
8
|
export type Currency = {
|
|
9
|
-
_id
|
|
9
|
+
_id: string;
|
|
10
10
|
isoCode: string;
|
|
11
11
|
isActive: boolean;
|
|
12
12
|
contractAddress?: string;
|
|
@@ -22,18 +22,23 @@ export type CurrencyQuery = mongodb.Filter<Currency> & {
|
|
|
22
22
|
export const CurrenciesCollection = async (db: mongodb.Db) => {
|
|
23
23
|
const Currencies = db.collection<Currency>('currencies');
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if (!isDocumentDBCompatModeEnabled()) {
|
|
26
|
+
await buildDbIndexes<Currency>(Currencies, [
|
|
27
|
+
{
|
|
28
|
+
index: { isoCode: 'text', _id: 'text' },
|
|
29
|
+
options: {
|
|
30
|
+
weights: {
|
|
31
|
+
_id: 8,
|
|
32
|
+
isoCode: 6,
|
|
33
|
+
},
|
|
34
|
+
name: 'currencies_fulltext_search',
|
|
33
35
|
},
|
|
34
|
-
name: 'currencies_fulltext_search',
|
|
35
36
|
},
|
|
36
|
-
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
await buildDbIndexes<Currency>(Currencies, [
|
|
41
|
+
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
37
42
|
{
|
|
38
43
|
index: {
|
|
39
44
|
deleted: 1,
|
|
@@ -37,14 +37,18 @@ export const configureCurrenciesModule = async ({ db }: ModuleInput<Record<strin
|
|
|
37
37
|
const Currencies = await CurrenciesCollection(db);
|
|
38
38
|
|
|
39
39
|
return {
|
|
40
|
-
findCurrency: async (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
findCurrency: async (
|
|
41
|
+
params:
|
|
42
|
+
| {
|
|
43
|
+
isoCode: string;
|
|
44
|
+
}
|
|
45
|
+
| { currencyId: string },
|
|
46
|
+
) => {
|
|
47
|
+
if ('currencyId' in params) {
|
|
48
|
+
return Currencies.findOne(generateDbFilterById(params.currencyId));
|
|
49
|
+
} else {
|
|
50
|
+
return Currencies.findOne({ isoCode: params.isoCode });
|
|
51
|
+
}
|
|
48
52
|
},
|
|
49
53
|
|
|
50
54
|
findCurrencies: async ({
|
|
@@ -81,7 +85,9 @@ export const configureCurrenciesModule = async ({ db }: ModuleInput<Record<strin
|
|
|
81
85
|
return !!currencyCount;
|
|
82
86
|
},
|
|
83
87
|
|
|
84
|
-
create: async (
|
|
88
|
+
create: async (
|
|
89
|
+
doc: Omit<Currency, '_id' | 'created'> & Pick<Partial<Currency>, '_id' | 'created'>,
|
|
90
|
+
) => {
|
|
85
91
|
await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
86
92
|
const { insertedId: currencyId } = await Currencies.insertOne({
|
|
87
93
|
_id: generateDbObjectId(),
|
|
@@ -95,11 +101,13 @@ export const configureCurrenciesModule = async ({ db }: ModuleInput<Record<strin
|
|
|
95
101
|
},
|
|
96
102
|
|
|
97
103
|
update: async (currencyId: string, doc: Partial<Currency>) => {
|
|
104
|
+
if (doc.isoCode) {
|
|
105
|
+
doc.isoCode = doc.isoCode.toUpperCase();
|
|
106
|
+
}
|
|
98
107
|
await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
99
108
|
$set: {
|
|
100
109
|
updated: new Date(),
|
|
101
110
|
...doc,
|
|
102
|
-
isoCode: doc.isoCode.toUpperCase(),
|
|
103
111
|
},
|
|
104
112
|
});
|
|
105
113
|
await emit('CURRENCY_UPDATE', { currencyId });
|