@unchainedshop/core-currencies 2.0.0-beta7 → 2.0.0-beta9

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/jest.config.js CHANGED
@@ -2,4 +2,13 @@
2
2
  export default {
3
3
  preset: 'ts-jest',
4
4
  testEnvironment: 'node',
5
+ extensionsToTreatAsEsm: ['.ts'],
6
+ transform: {
7
+ '^.+\\.tsx?$': [
8
+ 'ts-jest',
9
+ {
10
+ useESM: true,
11
+ },
12
+ ],
13
+ },
5
14
  };
@@ -3,7 +3,6 @@ import SimpleSchema from 'simpl-schema';
3
3
  export const CurrenciesSchema = new SimpleSchema({
4
4
  isoCode: { type: String, required: true },
5
5
  isActive: Boolean,
6
- authorId: { type: String, required: true },
7
6
  contractAddress: { type: String, required: false },
8
7
  decimals: { type: Number, required: false },
9
8
  ...Schemas.timestampFields,
@@ -1 +1 @@
1
- {"version":3,"file":"CurrenciesSchema.js","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.js"],"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,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IAC1C,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
+ {"version":3,"file":"CurrenciesSchema.js","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.js"],"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,3 +1,9 @@
1
1
  import { ModuleInput } from '@unchainedshop/types/core';
2
- import { CurrenciesModule } from '@unchainedshop/types/currencies';
2
+ import { CurrenciesModule, CurrencyQuery } from '@unchainedshop/types/currencies';
3
+ export declare const buildFindSelector: ({ includeInactive, contractAddress, queryString, }: CurrencyQuery) => {
4
+ isActive?: true;
5
+ deleted: null;
6
+ contractAddress?: string;
7
+ $text?: any;
8
+ };
3
9
  export declare const configureCurrenciesModule: ({ db, }: ModuleInput<Record<string, never>>) => Promise<CurrenciesModule>;
@@ -1,9 +1,10 @@
1
1
  import { emit, registerEvents } from '@unchainedshop/events';
2
2
  import { generateDbMutations, generateDbFilterById, buildSortOptions } from '@unchainedshop/utils';
3
+ import { SortDirection } from '@unchainedshop/types/api';
3
4
  import { CurrenciesCollection } from '../db/CurrenciesCollection';
4
5
  import { CurrenciesSchema } from '../db/CurrenciesSchema';
5
6
  const CURRENCY_EVENTS = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
6
- const buildFindSelector = ({ includeInactive = false, contractAddress, queryString }) => {
7
+ export const buildFindSelector = ({ includeInactive = false, contractAddress, queryString, }) => {
7
8
  const selector = {
8
9
  deleted: null,
9
10
  };
@@ -24,10 +25,11 @@ export const configureCurrenciesModule = async ({ db, }) => {
24
25
  return Currencies.findOne(currencyId ? generateDbFilterById(currencyId) : { isoCode });
25
26
  },
26
27
  findCurrencies: async ({ limit, offset, sort, ...query }) => {
28
+ const defaultSort = [{ key: 'created', value: SortDirection.ASC }];
27
29
  const currencies = Currencies.find(buildFindSelector(query), {
28
30
  skip: offset,
29
31
  limit,
30
- sort: buildSortOptions(sort),
32
+ sort: buildSortOptions(sort || defaultSort),
31
33
  });
32
34
  return currencies.toArray();
33
35
  },
@@ -41,27 +43,31 @@ export const configureCurrenciesModule = async ({ db, }) => {
41
43
  });
42
44
  return !!currencyCount;
43
45
  },
44
- create: async (doc, userId) => {
46
+ create: async (doc) => {
45
47
  await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
46
- const currencyId = await mutations.create({ ...doc, isoCode: doc.isoCode.toUpperCase(), isActive: true }, userId);
47
- emit('CURRENCY_CREATE', { currencyId });
48
+ const currencyId = await mutations.create({
49
+ ...doc,
50
+ isoCode: doc.isoCode.toUpperCase(),
51
+ isActive: true,
52
+ });
53
+ await emit('CURRENCY_CREATE', { currencyId });
48
54
  return currencyId;
49
55
  },
50
- update: async (_id, doc, userId) => {
56
+ update: async (_id, doc) => {
51
57
  const currencyId = await mutations.update(_id, {
52
58
  ...doc,
53
59
  isoCode: doc.isoCode.toUpperCase(),
54
- }, userId);
55
- emit('CURRENCY_UPDATE', { currencyId });
60
+ });
61
+ await emit('CURRENCY_UPDATE', { currencyId });
56
62
  return currencyId;
57
63
  },
58
- delete: async (currencyId, userId) => {
59
- const deletedCount = await mutations.delete(currencyId, userId);
60
- emit('CURRENCY_REMOVE', { currencyId });
64
+ delete: async (currencyId) => {
65
+ const deletedCount = await mutations.delete(currencyId);
66
+ await emit('CURRENCY_REMOVE', { currencyId });
61
67
  return deletedCount;
62
68
  },
63
- deletePermanently: async (_id, userId) => {
64
- return mutations.deletePermanently(_id, userId);
69
+ deletePermanently: async (_id) => {
70
+ return mutations.deletePermanently(_id);
65
71
  },
66
72
  };
67
73
  };
@@ -1 +1 @@
1
- {"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACnG,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,MAAM,eAAe,GAAa,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAE5F,MAAM,iBAAiB,GAAG,CAAC,EAAE,eAAe,GAAG,KAAK,EAAE,eAAe,EAAE,WAAW,EAAiB,EAAE,EAAE;IACrG,MAAM,QAAQ,GAA8E;QAC1F,OAAO,EAAE,IAAI;KACd,CAAC;IACF,IAAI,CAAC,eAAe;QAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,IAAI,eAAe;QAAE,QAAQ,CAAC,eAAe,GAAG,eAAe,CAAC;IAChE,IAAI,WAAW;QAAE,QAAQ,CAAC,KAAK,GAAG,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC;IAC3D,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAAE,EAC9C,EAAE,GACiC,EAA6B,EAAE;IAClE,cAAc,CAAC,eAAe,CAAC,CAAC;IAEhC,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,EAAE,CAAC,CAAC;IAElD,MAAM,SAAS,GAAG,mBAAmB,CACnC,UAAU,EACV,gBAAg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,CAAC,CAAC;YAC3F,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,MAAM,CACvC,EAAE,GAAG,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,EAC9D,MAAM,CACP,CAAC;YACF,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACxC,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAW,EAAE,GAAsB,EAAE,MAAc,EAAE,EAAE;YACpE,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,MAAM,CACvC,GAAG,EACH;gBACE,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;aACnC,EACD,MAAM,CACP,CAAC;YACF,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACxC,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;YACnC,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YACxC,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE;YACvC,OAAO,SAAS,CAAC,iBAAiB,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QAClD,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,oBAAo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,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,GAAW,EAAE,GAAsB,EAAE,EAAE;YACpD,MAAM,UAAU,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,GAAG,EAAE;gBAC7C,GAAG,GAAG;gBACN,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE;aACnC,CAAC,CAAC;YACH,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,UAAU,CAAC;QACpB,CAAC;QAED,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE;YAC3B,MAAM,YAAY,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YACxD,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,YAAY,CAAC;QACtB,CAAC;QAED,iBAAiB,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE;YAC/B,OAAO,SAAS,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QAC1C,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/core-currencies",
3
- "version": "2.0.0-beta7",
3
+ "version": "2.0.0-beta9",
4
4
  "main": "lib/currencies-index.js",
5
5
  "exports": {
6
6
  ".": "./lib/currencies-index.js",
@@ -12,7 +12,8 @@
12
12
  "clean": "rm -rf lib",
13
13
  "build": "npm run clean && tsc",
14
14
  "watch": "tsc -w",
15
- "test": "jest --watch"
15
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
16
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
16
17
  },
17
18
  "repository": {
18
19
  "type": "git",
@@ -30,15 +31,15 @@
30
31
  },
31
32
  "homepage": "https://github.com/unchainedshop/unchained#readme",
32
33
  "dependencies": {
33
- "@unchainedshop/events": "^2.0.0-beta7",
34
- "@unchainedshop/utils": "^2.0.0-beta7",
35
- "simpl-schema": "^3.0.1"
34
+ "@unchainedshop/events": "^2.0.0-beta9",
35
+ "@unchainedshop/utils": "^2.0.0-beta9",
36
+ "simpl-schema": "^3.2.0"
36
37
  },
37
38
  "devDependencies": {
38
- "@types/node": "^18.11.9",
39
- "@unchainedshop/types": "^2.0.0-beta7",
39
+ "@types/node": "^18.11.12",
40
+ "@unchainedshop/types": "^2.0.0-beta9",
40
41
  "jest": "^29.3.1",
41
42
  "ts-jest": "^29.0.3",
42
- "typescript": "^4.8.4"
43
+ "typescript": "^4.9.4"
43
44
  }
44
45
  }
@@ -5,7 +5,6 @@ export const CurrenciesSchema = new SimpleSchema(
5
5
  {
6
6
  isoCode: { type: String, required: true },
7
7
  isActive: Boolean,
8
- authorId: { type: String, required: true },
9
8
  contractAddress: { type: String, required: false },
10
9
  decimals: { type: Number, required: false },
11
10
  ...Schemas.timestampFields,
@@ -2,12 +2,17 @@ import { ModuleInput, ModuleMutations } from '@unchainedshop/types/core';
2
2
  import { CurrenciesModule, Currency, CurrencyQuery } from '@unchainedshop/types/currencies';
3
3
  import { emit, registerEvents } from '@unchainedshop/events';
4
4
  import { generateDbMutations, generateDbFilterById, buildSortOptions } from '@unchainedshop/utils';
5
+ import { SortDirection, SortOption } from '@unchainedshop/types/api';
5
6
  import { CurrenciesCollection } from '../db/CurrenciesCollection';
6
7
  import { CurrenciesSchema } from '../db/CurrenciesSchema';
7
8
 
8
9
  const CURRENCY_EVENTS: string[] = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
9
10
 
10
- const buildFindSelector = ({ includeInactive = false, contractAddress, queryString }: CurrencyQuery) => {
11
+ export const buildFindSelector = ({
12
+ includeInactive = false,
13
+ contractAddress,
14
+ queryString,
15
+ }: CurrencyQuery) => {
11
16
  const selector: { isActive?: true; deleted: null; contractAddress?: string; $text?: any } = {
12
17
  deleted: null,
13
18
  };
@@ -35,10 +40,11 @@ export const configureCurrenciesModule = async ({
35
40
  },
36
41
 
37
42
  findCurrencies: async ({ limit, offset, sort, ...query }) => {
43
+ const defaultSort = [{ key: 'created', value: SortDirection.ASC }] as SortOption[];
38
44
  const currencies = Currencies.find(buildFindSelector(query), {
39
45
  skip: offset,
40
46
  limit,
41
- sort: buildSortOptions(sort),
47
+ sort: buildSortOptions(sort || defaultSort),
42
48
  });
43
49
  return currencies.toArray();
44
50
  },
@@ -58,37 +64,34 @@ export const configureCurrenciesModule = async ({
58
64
  return !!currencyCount;
59
65
  },
60
66
 
61
- create: async (doc: Currency, userId: string) => {
67
+ create: async (doc: Currency) => {
62
68
  await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
63
- const currencyId = await mutations.create(
64
- { ...doc, isoCode: doc.isoCode.toUpperCase(), isActive: true },
65
- userId,
66
- );
67
- emit('CURRENCY_CREATE', { currencyId });
69
+ const currencyId = await mutations.create({
70
+ ...doc,
71
+ isoCode: doc.isoCode.toUpperCase(),
72
+ isActive: true,
73
+ });
74
+ await emit('CURRENCY_CREATE', { currencyId });
68
75
  return currencyId;
69
76
  },
70
77
 
71
- update: async (_id: string, doc: Partial<Currency>, userId: string) => {
72
- const currencyId = await mutations.update(
73
- _id,
74
- {
75
- ...doc,
76
- isoCode: doc.isoCode.toUpperCase(),
77
- },
78
- userId,
79
- );
80
- emit('CURRENCY_UPDATE', { currencyId });
78
+ update: async (_id: string, doc: Partial<Currency>) => {
79
+ const currencyId = await mutations.update(_id, {
80
+ ...doc,
81
+ isoCode: doc.isoCode.toUpperCase(),
82
+ });
83
+ await emit('CURRENCY_UPDATE', { currencyId });
81
84
  return currencyId;
82
85
  },
83
86
 
84
- delete: async (currencyId, userId) => {
85
- const deletedCount = await mutations.delete(currencyId, userId);
86
- emit('CURRENCY_REMOVE', { currencyId });
87
+ delete: async (currencyId) => {
88
+ const deletedCount = await mutations.delete(currencyId);
89
+ await emit('CURRENCY_REMOVE', { currencyId });
87
90
  return deletedCount;
88
91
  },
89
92
 
90
- deletePermanently: async (_id, userId) => {
91
- return mutations.deletePermanently(_id, userId);
93
+ deletePermanently: async (_id) => {
94
+ return mutations.deletePermanently(_id);
92
95
  },
93
96
  };
94
97
  };
@@ -1,47 +1,27 @@
1
- import { assert } from 'chai';
2
- import { initDb } from '@unchainedshop/mongodb';
3
- import { configureCurrenciesModule } from '@unchainedshop/core-currencies';
1
+ import {buildFindSelector} from '../src/module/configureCurrenciesModule'
4
2
 
5
- describe('Test exports', () => {
6
- let module;
3
+ describe('Currency', () => {
4
+
5
+ it('buildFindSelector should return correct filter object', async () => {
7
6
 
8
- before(async () => {
9
- const db = await initDb();
10
- module = await configureCurrenciesModule({ db });
7
+ expect(buildFindSelector({contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A', includeInactive: true, queryString: 'hello world'})).toEqual({
8
+ deleted: null,
9
+ contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
10
+ '$text': { '$search': 'hello world' }
11
+ })
12
+ expect(buildFindSelector({contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A', includeInactive: true})).toEqual({
13
+ deleted: null,
14
+ contractAddress: '0xf12EC0F79a8855d093DeCe22b24c0603f5b8E34A',
15
+ })
16
+ expect(buildFindSelector({includeInactive: true, queryString: 'hello world'})).toEqual({
17
+ deleted: null,
18
+ '$text': { '$search': 'hello world' }
19
+ })
20
+ expect(buildFindSelector({ queryString: 'hello world'})).toEqual({
21
+ deleted: null,
22
+ isActive: true,
23
+ '$text': { '$search': 'hello world' }
24
+ })
11
25
  });
12
26
 
13
- it('Check Bookmarks module', async () => {
14
- assert.ok(module);
15
- assert.isFunction(module.findCurrency);
16
- assert.isFunction(module.findCurrencies);
17
- assert.isFunction(module.currencyExists);
18
- assert.isFunction(module.create);
19
- assert.isFunction(module.update);
20
- assert.isFunction(module.delete);
21
- });
22
-
23
- it('Mutate currency', async () => {
24
- const currencyId = await module.create(
25
- {
26
- authorId: 'Test-User-1',
27
- isoCode: 'CHF',
28
- },
29
- 'Test-User-1'
30
- );
31
-
32
- assert.ok(currencyId);
33
- const currency = await module.findCurrency(currencyId);
34
-
35
- assert.ok(currency);
36
- assert.equal(currency._id, currencyId);
37
- assert.equal(currency.isoCode, 'CHF');
38
- assert.equal(currency.userId, 'Test-User-1');
39
- assert.isDefined(currency.created);
40
- assert.isUndefined(currency.updated);
41
- assert.isUndefined(currency.updatedBy);
42
- assert.equal(currency.createdBy, 'Test-User-1');
43
-
44
- const deletedCount = await module.delete(currencyId);
45
- assert.equal(deletedCount, 1);
46
- });
47
27
  });