@unchainedshop/core-currencies 4.3.3 → 4.4.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/README.md +72 -2
- package/lib/currencies-index.d.ts +2 -3
- package/lib/currencies-index.js +2 -3
- package/lib/db/CurrenciesCollection.d.ts +1 -2
- package/lib/db/CurrenciesCollection.js +1 -2
- package/lib/module/configureCurrenciesModule.d.ts +3 -4
- package/lib/module/configureCurrenciesModule.js +2 -3
- package/package.json +10 -9
- package/lib/currencies-index.d.ts.map +0 -1
- package/lib/currencies-index.js.map +0 -1
- package/lib/db/CurrenciesCollection.d.ts.map +0 -1
- package/lib/db/CurrenciesCollection.js.map +0 -1
- package/lib/db/CurrenciesSchema.d.ts +0 -3
- package/lib/db/CurrenciesSchema.d.ts.map +0 -1
- package/lib/db/CurrenciesSchema.js +0 -10
- package/lib/db/CurrenciesSchema.js.map +0 -1
- package/lib/module/configureCurrenciesModule.d.ts.map +0 -1
- package/lib/module/configureCurrenciesModule.js.map +0 -1
- package/src/currencies-index.ts +0 -2
- package/src/db/CurrenciesCollection.ts +0 -50
- package/src/module/buildFindSelector.test.ts +0 -39
- package/src/module/configureCurrenciesModule.ts +0 -132
- package/tsconfig.json +0 -10
package/README.md
CHANGED
|
@@ -1,3 +1,73 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://npmjs.com/package/@unchainedshop/core-currencies)
|
|
2
|
+
[](https://opensource.org/licenses/EUPL-1.2)
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
# @unchainedshop/core-currencies
|
|
5
|
+
|
|
6
|
+
Currency management module for the Unchained Engine. Manages supported currencies with ISO codes and optional blockchain contract addresses.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @unchainedshop/core-currencies
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
import { configureCurrenciesModule } from '@unchainedshop/core-currencies';
|
|
18
|
+
|
|
19
|
+
const currenciesModule = await configureCurrenciesModule({ db });
|
|
20
|
+
|
|
21
|
+
// Create a currency
|
|
22
|
+
const currencyId = await currenciesModule.create({
|
|
23
|
+
isoCode: 'CHF',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Find currencies
|
|
27
|
+
const currencies = await currenciesModule.findCurrencies({ includeInactive: false });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## API Overview
|
|
31
|
+
|
|
32
|
+
### Module Configuration
|
|
33
|
+
|
|
34
|
+
| Export | Description |
|
|
35
|
+
|--------|-------------|
|
|
36
|
+
| `configureCurrenciesModule` | Configure and return the currencies module |
|
|
37
|
+
|
|
38
|
+
### Queries
|
|
39
|
+
|
|
40
|
+
| Method | Description |
|
|
41
|
+
|--------|-------------|
|
|
42
|
+
| `findCurrency` | Find currency by ID or ISO code |
|
|
43
|
+
| `findCurrencies` | Find currencies with filtering, sorting, and pagination |
|
|
44
|
+
| `count` | Count currencies matching query |
|
|
45
|
+
| `currencyExists` | Check if a currency exists |
|
|
46
|
+
|
|
47
|
+
### Mutations
|
|
48
|
+
|
|
49
|
+
| Method | Description |
|
|
50
|
+
|--------|-------------|
|
|
51
|
+
| `create` | Create a new currency |
|
|
52
|
+
| `update` | Update an existing currency |
|
|
53
|
+
| `delete` | Soft delete a currency |
|
|
54
|
+
|
|
55
|
+
### Types
|
|
56
|
+
|
|
57
|
+
| Export | Description |
|
|
58
|
+
|--------|-------------|
|
|
59
|
+
| `Currency` | Currency document type |
|
|
60
|
+
| `CurrencyQuery` | Query parameters type |
|
|
61
|
+
| `CurrenciesModule` | Module interface type |
|
|
62
|
+
|
|
63
|
+
## Events
|
|
64
|
+
|
|
65
|
+
| Event | Description |
|
|
66
|
+
|-------|-------------|
|
|
67
|
+
| `CURRENCY_CREATE` | Emitted when a currency is created |
|
|
68
|
+
| `CURRENCY_UPDATE` | Emitted when a currency is updated |
|
|
69
|
+
| `CURRENCY_REMOVE` | Emitted when a currency is removed |
|
|
70
|
+
|
|
71
|
+
## License
|
|
72
|
+
|
|
73
|
+
EUPL-1.2
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './module/configureCurrenciesModule.
|
|
2
|
-
export * from './db/CurrenciesCollection.
|
|
3
|
-
//# sourceMappingURL=currencies-index.d.ts.map
|
|
1
|
+
export * from './module/configureCurrenciesModule.ts';
|
|
2
|
+
export * from './db/CurrenciesCollection.ts';
|
package/lib/currencies-index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
//# sourceMappingURL=currencies-index.js.map
|
|
1
|
+
export * from "./module/configureCurrenciesModule.js";
|
|
2
|
+
export * from "./db/CurrenciesCollection.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mongodb, TimestampFields } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, type TimestampFields } from '@unchainedshop/mongodb';
|
|
2
2
|
export type Currency = {
|
|
3
3
|
_id: string;
|
|
4
4
|
isoCode: string;
|
|
@@ -12,4 +12,3 @@ export type CurrencyQuery = mongodb.Filter<Currency> & {
|
|
|
12
12
|
queryString?: string;
|
|
13
13
|
};
|
|
14
14
|
export declare const CurrenciesCollection: (db: mongodb.Db) => Promise<mongodb.Collection<Currency>>;
|
|
15
|
-
//# sourceMappingURL=CurrenciesCollection.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
1
|
+
import { mongodb, buildDbIndexes, isDocumentDBCompatModeEnabled, } from '@unchainedshop/mongodb';
|
|
2
2
|
export const CurrenciesCollection = async (db) => {
|
|
3
3
|
const Currencies = db.collection('currencies');
|
|
4
4
|
if (!isDocumentDBCompatModeEnabled()) {
|
|
@@ -25,4 +25,3 @@ export const CurrenciesCollection = async (db) => {
|
|
|
25
25
|
]);
|
|
26
26
|
return Currencies;
|
|
27
27
|
};
|
|
28
|
-
//# sourceMappingURL=CurrenciesCollection.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ModuleInput, mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { SortOption } from '@unchainedshop/utils';
|
|
3
|
-
import { Currency, CurrencyQuery } from '../db/CurrenciesCollection.
|
|
1
|
+
import { type ModuleInput, mongodb } from '@unchainedshop/mongodb';
|
|
2
|
+
import { type SortOption } from '@unchainedshop/utils';
|
|
3
|
+
import { type Currency, type CurrencyQuery } from '../db/CurrenciesCollection.ts';
|
|
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
6
|
findCurrency: (params: {
|
|
@@ -22,4 +22,3 @@ export declare const configureCurrenciesModule: ({ db }: ModuleInput<Record<stri
|
|
|
22
22
|
delete: (currencyId: string) => Promise<number>;
|
|
23
23
|
}>;
|
|
24
24
|
export type CurrenciesModule = Awaited<ReturnType<typeof configureCurrenciesModule>>;
|
|
25
|
-
//# sourceMappingURL=configureCurrenciesModule.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import { generateDbFilterById, buildSortOptions, generateDbObjectId, assertDocumentDBCompatMode, } from '@unchainedshop/mongodb';
|
|
2
|
+
import { generateDbFilterById, buildSortOptions, generateDbObjectId, assertDocumentDBCompatMode, mongodb, } from '@unchainedshop/mongodb';
|
|
3
3
|
import { SortDirection } from '@unchainedshop/utils';
|
|
4
|
-
import { CurrenciesCollection } from
|
|
4
|
+
import { CurrenciesCollection } from "../db/CurrenciesCollection.js";
|
|
5
5
|
const CURRENCY_EVENTS = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
|
|
6
6
|
export const buildFindSelector = ({ includeInactive = false, contractAddress, queryString, ...rest }) => {
|
|
7
7
|
const selector = {
|
|
@@ -85,4 +85,3 @@ export const configureCurrenciesModule = async ({ db }) => {
|
|
|
85
85
|
},
|
|
86
86
|
};
|
|
87
87
|
};
|
|
88
|
-
//# sourceMappingURL=configureCurrenciesModule.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-currencies",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"main": "lib/currencies-index.js",
|
|
5
5
|
"types": "lib/currencies-index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
"build": "tsc -b",
|
|
10
10
|
"prepublishOnly": "npm run clean && npm run build",
|
|
11
11
|
"watch": "tsc -w",
|
|
12
|
-
"test": "
|
|
13
|
-
"test:watch": "
|
|
12
|
+
"test": "node --test",
|
|
13
|
+
"test:watch": "node --test --watch"
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
@@ -22,8 +22,10 @@
|
|
|
22
22
|
"core"
|
|
23
23
|
],
|
|
24
24
|
"authors": [
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"Pascal Kaufmann",
|
|
26
|
+
"Mikael Araya",
|
|
27
|
+
"Vedran Rudelj",
|
|
28
|
+
"Joël Meiller"
|
|
27
29
|
],
|
|
28
30
|
"license": "EUPL-1.2",
|
|
29
31
|
"bugs": {
|
|
@@ -31,12 +33,11 @@
|
|
|
31
33
|
},
|
|
32
34
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
35
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^4.
|
|
35
|
-
"@unchainedshop/utils": "^4.
|
|
36
|
+
"@unchainedshop/events": "^4.4.0",
|
|
37
|
+
"@unchainedshop/utils": "^4.4.0"
|
|
36
38
|
},
|
|
37
39
|
"devDependencies": {
|
|
38
|
-
"@types/node": "^
|
|
39
|
-
"tsx": "^4.20.3",
|
|
40
|
+
"@types/node": "^25.0.0",
|
|
40
41
|
"typescript": "^5.8.3"
|
|
41
42
|
}
|
|
42
43
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"currencies-index.d.ts","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"currencies-index.js","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,8BAA8B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1 +0,0 @@
|
|
|
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;KACj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CAAC,WAAW,EAAE,CAAC;YAC1C,CAAC;YACD,MAAM,UAAU,CAAC,SAAS,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE;gBAC3D,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,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/src/currencies-index.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
mongodb,
|
|
3
|
-
buildDbIndexes,
|
|
4
|
-
TimestampFields,
|
|
5
|
-
isDocumentDBCompatModeEnabled,
|
|
6
|
-
} from '@unchainedshop/mongodb';
|
|
7
|
-
|
|
8
|
-
export type Currency = {
|
|
9
|
-
_id: string;
|
|
10
|
-
isoCode: string;
|
|
11
|
-
isActive: boolean;
|
|
12
|
-
contractAddress?: string;
|
|
13
|
-
decimals?: number;
|
|
14
|
-
} & TimestampFields;
|
|
15
|
-
|
|
16
|
-
export type CurrencyQuery = mongodb.Filter<Currency> & {
|
|
17
|
-
includeInactive?: boolean;
|
|
18
|
-
contractAddress?: string;
|
|
19
|
-
queryString?: string;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
export const CurrenciesCollection = async (db: mongodb.Db) => {
|
|
23
|
-
const Currencies = db.collection<Currency>('currencies');
|
|
24
|
-
|
|
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',
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await buildDbIndexes<Currency>(Currencies, [
|
|
41
|
-
{ index: { isoCode: 1 }, options: { unique: true } },
|
|
42
|
-
{
|
|
43
|
-
index: {
|
|
44
|
-
deleted: 1,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
]);
|
|
48
|
-
|
|
49
|
-
return Currencies;
|
|
50
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { describe, it } from 'node:test';
|
|
2
|
-
import assert from 'node:assert';
|
|
3
|
-
import { buildFindSelector } from './configureCurrenciesModule.js';
|
|
4
|
-
|
|
5
|
-
describe('buildFindSelector', () => {
|
|
6
|
-
it('should return correct filter object', () => {
|
|
7
|
-
assert.deepStrictEqual(
|
|
8
|
-
buildFindSelector({
|
|
9
|
-
contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
|
|
10
|
-
includeInactive: true,
|
|
11
|
-
queryString: 'hello world',
|
|
12
|
-
}),
|
|
13
|
-
{
|
|
14
|
-
deleted: null,
|
|
15
|
-
contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
|
|
16
|
-
$text: { $search: 'hello world' },
|
|
17
|
-
},
|
|
18
|
-
);
|
|
19
|
-
assert.deepStrictEqual(
|
|
20
|
-
buildFindSelector({
|
|
21
|
-
contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
|
|
22
|
-
includeInactive: true,
|
|
23
|
-
}),
|
|
24
|
-
{
|
|
25
|
-
deleted: null,
|
|
26
|
-
contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
|
|
27
|
-
},
|
|
28
|
-
);
|
|
29
|
-
assert.deepStrictEqual(buildFindSelector({ includeInactive: true, queryString: 'hello world' }), {
|
|
30
|
-
deleted: null,
|
|
31
|
-
$text: { $search: 'hello world' },
|
|
32
|
-
});
|
|
33
|
-
assert.deepStrictEqual(buildFindSelector({ queryString: 'hello world' }), {
|
|
34
|
-
deleted: null,
|
|
35
|
-
isActive: true,
|
|
36
|
-
$text: { $search: 'hello world' },
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
});
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import {
|
|
3
|
-
generateDbFilterById,
|
|
4
|
-
buildSortOptions,
|
|
5
|
-
generateDbObjectId,
|
|
6
|
-
ModuleInput,
|
|
7
|
-
assertDocumentDBCompatMode,
|
|
8
|
-
mongodb,
|
|
9
|
-
} from '@unchainedshop/mongodb';
|
|
10
|
-
import { SortDirection, SortOption } from '@unchainedshop/utils';
|
|
11
|
-
import { CurrenciesCollection, Currency, CurrencyQuery } from '../db/CurrenciesCollection.js';
|
|
12
|
-
|
|
13
|
-
const CURRENCY_EVENTS: string[] = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
|
|
14
|
-
|
|
15
|
-
export const buildFindSelector = ({
|
|
16
|
-
includeInactive = false,
|
|
17
|
-
contractAddress,
|
|
18
|
-
queryString,
|
|
19
|
-
...rest
|
|
20
|
-
}: CurrencyQuery) => {
|
|
21
|
-
const selector: mongodb.Filter<Currency> = {
|
|
22
|
-
...rest,
|
|
23
|
-
deleted: null,
|
|
24
|
-
};
|
|
25
|
-
if (!includeInactive) selector.isActive = true;
|
|
26
|
-
if (contractAddress) selector.contractAddress = contractAddress;
|
|
27
|
-
if (queryString) {
|
|
28
|
-
assertDocumentDBCompatMode();
|
|
29
|
-
selector.$text = { $search: queryString };
|
|
30
|
-
}
|
|
31
|
-
return selector;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const configureCurrenciesModule = async ({ db }: ModuleInput<Record<string, never>>) => {
|
|
35
|
-
registerEvents(CURRENCY_EVENTS);
|
|
36
|
-
|
|
37
|
-
const Currencies = await CurrenciesCollection(db);
|
|
38
|
-
|
|
39
|
-
return {
|
|
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
|
-
}
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
findCurrencies: async ({
|
|
55
|
-
limit,
|
|
56
|
-
offset,
|
|
57
|
-
sort,
|
|
58
|
-
...query
|
|
59
|
-
}: CurrencyQuery & {
|
|
60
|
-
limit?: number;
|
|
61
|
-
offset?: number;
|
|
62
|
-
sort?: SortOption[];
|
|
63
|
-
}): Promise<Currency[]> => {
|
|
64
|
-
const defaultSort = [{ key: 'created', value: SortDirection.ASC }] as SortOption[];
|
|
65
|
-
const currencies = Currencies.find(buildFindSelector(query), {
|
|
66
|
-
skip: offset,
|
|
67
|
-
limit,
|
|
68
|
-
sort: buildSortOptions(sort || defaultSort),
|
|
69
|
-
});
|
|
70
|
-
return currencies.toArray();
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
count: async (query: CurrencyQuery) => {
|
|
74
|
-
const count = await Currencies.countDocuments(buildFindSelector(query));
|
|
75
|
-
return count;
|
|
76
|
-
},
|
|
77
|
-
|
|
78
|
-
currencyExists: async ({ currencyId }: { currencyId: string }) => {
|
|
79
|
-
const currencyCount = await Currencies.countDocuments(
|
|
80
|
-
generateDbFilterById(currencyId, { deleted: null }),
|
|
81
|
-
{
|
|
82
|
-
limit: 1,
|
|
83
|
-
},
|
|
84
|
-
);
|
|
85
|
-
return !!currencyCount;
|
|
86
|
-
},
|
|
87
|
-
|
|
88
|
-
create: async (
|
|
89
|
-
doc: Omit<Currency, '_id' | 'created'> & Pick<Partial<Currency>, '_id' | 'created'>,
|
|
90
|
-
) => {
|
|
91
|
-
await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
92
|
-
const { insertedId: currencyId } = await Currencies.insertOne({
|
|
93
|
-
_id: generateDbObjectId(),
|
|
94
|
-
created: new Date(),
|
|
95
|
-
...doc,
|
|
96
|
-
isoCode: doc.isoCode.toUpperCase(),
|
|
97
|
-
isActive: true,
|
|
98
|
-
});
|
|
99
|
-
await emit('CURRENCY_CREATE', { currencyId });
|
|
100
|
-
return currencyId;
|
|
101
|
-
},
|
|
102
|
-
|
|
103
|
-
update: async (currencyId: string, doc: Partial<Currency>) => {
|
|
104
|
-
if (doc.isoCode) {
|
|
105
|
-
doc.isoCode = doc.isoCode.toUpperCase();
|
|
106
|
-
}
|
|
107
|
-
await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
108
|
-
$set: {
|
|
109
|
-
updated: new Date(),
|
|
110
|
-
...doc,
|
|
111
|
-
},
|
|
112
|
-
});
|
|
113
|
-
await emit('CURRENCY_UPDATE', { currencyId });
|
|
114
|
-
return currencyId;
|
|
115
|
-
},
|
|
116
|
-
|
|
117
|
-
delete: async (currencyId: string) => {
|
|
118
|
-
const { modifiedCount: deletedCount } = await Currencies.updateOne(
|
|
119
|
-
generateDbFilterById(currencyId),
|
|
120
|
-
{
|
|
121
|
-
$set: {
|
|
122
|
-
deleted: new Date(),
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
);
|
|
126
|
-
await emit('CURRENCY_REMOVE', { currencyId });
|
|
127
|
-
return deletedCount;
|
|
128
|
-
},
|
|
129
|
-
};
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
export type CurrenciesModule = Awaited<ReturnType<typeof configureCurrenciesModule>>;
|