@ossy/tokens 1.8.0 → 1.9.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/tokens",
3
3
  "description": "Token domain — aggregate and events for the Ossy token model",
4
- "version": "1.8.0",
4
+ "version": "1.9.0",
5
5
  "private": false,
6
6
  "type": "module",
7
7
  "main": "./src/index.js",
@@ -25,5 +25,5 @@
25
25
  "/src",
26
26
  "README.md"
27
27
  ],
28
- "gitHead": "c6697078268867d88553ca0bac08faad5cea1546"
28
+ "gitHead": "24df2bde0d5d8794c5a82b9e802a2594ca73a5d9"
29
29
  }
package/src/index.js CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './token.aggregate.js'
2
2
  export * from './token.events.js'
3
+ export * from './tokens.queries.js'
@@ -0,0 +1,22 @@
1
+ import { Aggregate } from '@ossy/event-store'
2
+ import { createLogger } from '@ossy/observability'
3
+
4
+ const log = createLogger('tokens')
5
+
6
+ export class TokensQueries {
7
+
8
+ static GetTokens(_query = {}) {
9
+ log.info('[TokensQueries][GetTokens] Building query')
10
+ const query = Object.entries({
11
+ ..._query,
12
+ }).reduce((acc, [key, value]) => ({ ...acc, [`state.${key}`]: value }), {})
13
+ log.info(`[TokensQueries][GetTokens] Fetching tokens for ${query['state.subject']} with query ${JSON.stringify(query, null, 2)}`)
14
+ return Aggregate.Collection.find({ ...query, type: 'Token' }, { state: true }).toArray()
15
+ .then(resources => {
16
+ log.info(`[TokensQueries][GetTokens] Found ${resources.length} tokens`)
17
+ return resources
18
+ .map(resource => resource.state)
19
+ })
20
+ }
21
+
22
+ }