@live-change/balance-service 0.8.58 → 0.8.60
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/config.js +4 -2
- package/operation.js +112 -0
- package/package.json +4 -4
package/config.js
CHANGED
|
@@ -13,12 +13,14 @@ const {
|
|
|
13
13
|
return value + change >= 0
|
|
14
14
|
},
|
|
15
15
|
nextRecalculateTime = (value) => null, // no recalculation by default, will be used with vector balances
|
|
16
|
-
recalculate = (value, time) => value // no recalculation by default, will be used with vector balances
|
|
16
|
+
recalculate = (value, time) => value, // no recalculation by default, will be used with vector balances
|
|
17
|
+
|
|
18
|
+
readerRoles = ['owner', 'admin'],
|
|
17
19
|
} = definition.config
|
|
18
20
|
|
|
19
21
|
const config = {
|
|
20
22
|
currencyType, currencyAdd, changePossible, currencyNegate,
|
|
21
|
-
nextRecalculateTime, recalculate
|
|
23
|
+
nextRecalculateTime, recalculate, readerRoles
|
|
22
24
|
}
|
|
23
25
|
|
|
24
26
|
export default config
|
package/operation.js
CHANGED
|
@@ -45,10 +45,122 @@ const Operation = definition.model({
|
|
|
45
45
|
default: () => new Date(),
|
|
46
46
|
},
|
|
47
47
|
},
|
|
48
|
+
indexes: {
|
|
49
|
+
/* byCauseAndTime: {
|
|
50
|
+
function: async (input, output, { tableName }) => {
|
|
51
|
+
const table = await input.table(tableName)
|
|
52
|
+
const mapper = obj => obj ? {
|
|
53
|
+
id: [
|
|
54
|
+
obj.causeType,
|
|
55
|
+
obj.cause,
|
|
56
|
+
obj.updatedAt ?? obj.createdAt
|
|
57
|
+
].map(v => JSON.stringify(v)).join(':')+'_'+obj.id,
|
|
58
|
+
to: obj.id
|
|
59
|
+
} : null
|
|
60
|
+
await table.onChange(async (object, oldObject) => {
|
|
61
|
+
await output.change(mapper(object), mapper(oldObject))
|
|
62
|
+
})
|
|
63
|
+
},
|
|
64
|
+
parameters: {
|
|
65
|
+
tableName: definition.name + '_Operation'
|
|
66
|
+
}
|
|
67
|
+
},*/
|
|
68
|
+
byCauseStateAndTime: {
|
|
69
|
+
function: async (input, output, { tableName }) => {
|
|
70
|
+
const table = await input.table(tableName)
|
|
71
|
+
const mapper = obj => obj ? {
|
|
72
|
+
id: [
|
|
73
|
+
obj.causeType,
|
|
74
|
+
obj.cause,
|
|
75
|
+
obj.state,
|
|
76
|
+
obj.updatedAt ?? obj.createdAt
|
|
77
|
+
].map(v => JSON.stringify(v)).join(':')+'_'+obj.id,
|
|
78
|
+
to: obj.id
|
|
79
|
+
} : null
|
|
80
|
+
await table.onChange(async (object, oldObject) => {
|
|
81
|
+
await output.change(mapper(object), mapper(oldObject))
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
parameters: {
|
|
85
|
+
tableName: definition.name + '_Operation'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
byBalanceAndTime: {
|
|
89
|
+
function: async (input, output, { tableName }) => {
|
|
90
|
+
const table = await input.table(tableName)
|
|
91
|
+
const mapper = obj => obj ? {
|
|
92
|
+
id: [
|
|
93
|
+
obj.balance,
|
|
94
|
+
obj.updatedAt ?? obj.createdAt
|
|
95
|
+
].map(v => JSON.stringify(v)).join(':')+'_'+obj.id,
|
|
96
|
+
to: obj.id
|
|
97
|
+
} : null
|
|
98
|
+
await table.onChange(async (object, oldObject) => {
|
|
99
|
+
await output.change(mapper(object), mapper(oldObject))
|
|
100
|
+
})
|
|
101
|
+
},
|
|
102
|
+
parameters: {
|
|
103
|
+
tableName: definition.name + '_Operation'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
byBalanceStateAndTime: {
|
|
107
|
+
function: async (input, output, { tableName }) => {
|
|
108
|
+
const table = await input.table(tableName)
|
|
109
|
+
const mapper = obj => obj ? {
|
|
110
|
+
id: [
|
|
111
|
+
obj.balance,
|
|
112
|
+
obj.state,
|
|
113
|
+
obj.updatedAt ?? obj.createdAt
|
|
114
|
+
].map(v => JSON.stringify(v)).join(':')+'_'+obj.id,
|
|
115
|
+
to: obj.id
|
|
116
|
+
} : null
|
|
117
|
+
await table.onChange(async (object, oldObject) => {
|
|
118
|
+
await output.change(mapper(object), mapper(oldObject))
|
|
119
|
+
})
|
|
120
|
+
},
|
|
121
|
+
parameters: {
|
|
122
|
+
tableName: definition.name + '_Operation'
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
}
|
|
48
126
|
})
|
|
49
127
|
|
|
50
128
|
export { Operation }
|
|
51
129
|
|
|
130
|
+
definition.view({
|
|
131
|
+
name: 'operationsByBalance',
|
|
132
|
+
properties: {
|
|
133
|
+
balance: {
|
|
134
|
+
type: Balance,
|
|
135
|
+
validation: ['nonEmpty']
|
|
136
|
+
},
|
|
137
|
+
state: {
|
|
138
|
+
type: String
|
|
139
|
+
},
|
|
140
|
+
...App.rangeProperties
|
|
141
|
+
},
|
|
142
|
+
returns: {
|
|
143
|
+
type: Array,
|
|
144
|
+
of: {
|
|
145
|
+
type: Operation
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
accessControl: {
|
|
149
|
+
roles: config.readerRoles,
|
|
150
|
+
objects: async (params) => {
|
|
151
|
+
return [{ objectType: definition.name + '_Balance', object: params.balance }]
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async daoPath(params, { client, service }, method) {
|
|
155
|
+
const range = App.extractRange(params)
|
|
156
|
+
const { balance, state } = params
|
|
157
|
+
if(state) {
|
|
158
|
+
return Operation.indexRangePath('byBalanceStateAndTime', [balance, state], range)
|
|
159
|
+
} else {
|
|
160
|
+
return Operation.indexRangePath('byBalanceAndTime', balance, range)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
})
|
|
52
164
|
|
|
53
165
|
definition.trigger({
|
|
54
166
|
name: "startOperation",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/balance-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.60",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.8.
|
|
25
|
-
"@live-change/relations-plugin": "^0.8.
|
|
24
|
+
"@live-change/framework": "^0.8.60",
|
|
25
|
+
"@live-change/relations-plugin": "^0.8.60",
|
|
26
26
|
"lru-cache": "^7.12.0",
|
|
27
27
|
"pluralize": "^8.0.0",
|
|
28
28
|
"progress-stream": "^2.0.0",
|
|
29
29
|
"prosemirror-model": "^1.18.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "88bd85bdcd412560abb0aa13f9f3e9c30cbc5455",
|
|
32
32
|
"type": "module"
|
|
33
33
|
}
|