@live-change/scope-service 0.9.65 → 0.9.66
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 +9 -3
- package/indexes.js +98 -6
- package/package.json +5 -5
package/config.js
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import definition from './definition.js'
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
objectScopePathsRoles = ['reader', 'writer', 'admin', 'owner']
|
|
4
|
+
objectScopePathsRoles = ['reader', 'writer', 'admin', 'owner'],
|
|
5
|
+
scopeObjectRoles = ['reader', 'writer', 'admin', 'owner'],
|
|
6
|
+
objectScopesRoles = ['reader', 'writer', 'admin', 'owner']
|
|
5
7
|
} = definition.config
|
|
6
8
|
|
|
7
9
|
definition.clientConfig = {
|
|
8
|
-
objectScopePathsRoles: ['reader', 'writer', 'admin', 'owner']
|
|
10
|
+
objectScopePathsRoles: ['reader', 'writer', 'admin', 'owner'],
|
|
11
|
+
scopeObjectRoles: ['reader', 'writer', 'admin', 'owner'],
|
|
12
|
+
objectScopesRoles: ['reader', 'writer', 'admin', 'owner']
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
const config = {
|
|
12
|
-
objectScopePathsRoles
|
|
16
|
+
objectScopePathsRoles,
|
|
17
|
+
scopeObjectRoles,
|
|
18
|
+
objectScopesRoles
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
export default config
|
package/indexes.js
CHANGED
|
@@ -6,7 +6,7 @@ const config = definition.config
|
|
|
6
6
|
import { Scope } from './scopes.js'
|
|
7
7
|
|
|
8
8
|
//*
|
|
9
|
-
const pathByObjectAndScopeIndex = definition.index({
|
|
9
|
+
export const pathByObjectAndScopeIndex = definition.index({
|
|
10
10
|
name: 'pathByObjectAndScope', /// there can be multiple paths for the same scope -> object pairs
|
|
11
11
|
async function(input, output, { scopesTableName, pathsByAncestorDescendantRelationIndexName }) {
|
|
12
12
|
/// Can be optimized by using a ScopeIndexer for indexing scope using range changes
|
|
@@ -44,7 +44,7 @@ const pathByObjectAndScopeIndex = definition.index({
|
|
|
44
44
|
})
|
|
45
45
|
|
|
46
46
|
//*
|
|
47
|
-
const pathByScopeAndObjectIndex = definition.index({
|
|
47
|
+
export const pathByScopeAndObjectIndex = definition.index({
|
|
48
48
|
name: 'pathByScopeAndObject',
|
|
49
49
|
async function(input, output, { pathByObjectAndScopeIndexName }) {
|
|
50
50
|
await (await input.index(pathByObjectAndScopeIndexName))
|
|
@@ -68,7 +68,7 @@ const pathByScopeAndObjectIndex = definition.index({
|
|
|
68
68
|
})
|
|
69
69
|
|
|
70
70
|
//*
|
|
71
|
-
const scopeByObjectIndex = definition.index({
|
|
71
|
+
export const scopeByObjectIndex = definition.index({
|
|
72
72
|
name: 'scopeByObject',
|
|
73
73
|
async function(input, output, { pathByObjectAndScopeIndexName }) {
|
|
74
74
|
await (await input.index(pathByObjectAndScopeIndexName))
|
|
@@ -86,12 +86,12 @@ const scopeByObjectIndex = definition.index({
|
|
|
86
86
|
//*/
|
|
87
87
|
|
|
88
88
|
//*
|
|
89
|
-
const objectByScopeIndex = definition.index({
|
|
89
|
+
export const objectByScopeIndex = definition.index({
|
|
90
90
|
name: 'objectByScope',
|
|
91
91
|
async function(input, output, { scopeByObjectIndexName }) {
|
|
92
92
|
await (await input.index(scopeByObjectIndexName))
|
|
93
93
|
.map(({ id, objectType, object, scopeType, scope }) => ({
|
|
94
|
-
id: [
|
|
94
|
+
id: [scopeType, scope, objectType, object].map(v => JSON.stringify(v)).join(':'),
|
|
95
95
|
scopeType, scope, objectType, object
|
|
96
96
|
}))
|
|
97
97
|
.to(output)
|
|
@@ -133,4 +133,96 @@ definition.view({
|
|
|
133
133
|
range
|
|
134
134
|
)
|
|
135
135
|
}
|
|
136
|
-
})
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
definition.view({
|
|
139
|
+
name: 'objectScopes',
|
|
140
|
+
properties: {
|
|
141
|
+
objectType: {
|
|
142
|
+
type: 'type'
|
|
143
|
+
},
|
|
144
|
+
object: {
|
|
145
|
+
type: 'any'
|
|
146
|
+
},
|
|
147
|
+
scopeType: {
|
|
148
|
+
type: 'type'
|
|
149
|
+
},
|
|
150
|
+
...App.rangeProperties
|
|
151
|
+
},
|
|
152
|
+
accessControl: {
|
|
153
|
+
roles: config.objectScopeRoles
|
|
154
|
+
},
|
|
155
|
+
daoPath(params, { client, service }, method) {
|
|
156
|
+
const { objectType, object, scopeType } = params
|
|
157
|
+
const range = App.extractRange(params)
|
|
158
|
+
if(!range.limit || range.limit > 1000) range.limit = 1000
|
|
159
|
+
const allParams = [objectType, object, scopeType]
|
|
160
|
+
const path = scopeByObjectIndex.rangePath(
|
|
161
|
+
allParams.slice(0, allParams.findIndex(p => p === undefined)),
|
|
162
|
+
range
|
|
163
|
+
)
|
|
164
|
+
return path
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
definition.view({
|
|
169
|
+
name: 'scopeObjects',
|
|
170
|
+
properties: {
|
|
171
|
+
scopeType: {
|
|
172
|
+
type: 'type'
|
|
173
|
+
},
|
|
174
|
+
scope: {
|
|
175
|
+
type: 'any'
|
|
176
|
+
},
|
|
177
|
+
objectType: {
|
|
178
|
+
type: 'type'
|
|
179
|
+
},
|
|
180
|
+
...App.rangeProperties
|
|
181
|
+
},
|
|
182
|
+
accessControl: {
|
|
183
|
+
roles: config.scopeObjectRoles,
|
|
184
|
+
objects: ({ scopeType, scope }) => {
|
|
185
|
+
return [{ objectType: scopeType, object: scope }]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
daoPath(params, { client, service }, method) {
|
|
189
|
+
const { scopeType, scope, objectType } = params
|
|
190
|
+
const range = App.extractRange(params)
|
|
191
|
+
if(!range.limit || range.limit > 1000) range.limit = 1000
|
|
192
|
+
const allParams = [scopeType, scope, objectType]
|
|
193
|
+
const path = ['database', 'query', service.databaseName, `(${
|
|
194
|
+
async (input, output, { indexName, scopeType, scope, objectType }) => {
|
|
195
|
+
const index = await input.index(indexName)
|
|
196
|
+
const prefixParts = objectType ? [scopeType, scope, objectType] : [scopeType, scope]
|
|
197
|
+
const prefix = prefixParts.map(v => JSON.stringify(v)).join(':')
|
|
198
|
+
const range = {
|
|
199
|
+
gte: prefix + ':',
|
|
200
|
+
lte: prefix + '_\xFF\xFF\xFF\xFF'
|
|
201
|
+
}
|
|
202
|
+
output.debug('range', range)
|
|
203
|
+
await index
|
|
204
|
+
.range(range)
|
|
205
|
+
.map(async (indexObj, id, timestamp) => {
|
|
206
|
+
if(!indexObj) return null
|
|
207
|
+
const anyIndexObj = indexObj
|
|
208
|
+
const tableName = anyIndexObj.objectType
|
|
209
|
+
const table = input.table(tableName)
|
|
210
|
+
const result = await table.objectGet(anyIndexObj.object)
|
|
211
|
+
return {
|
|
212
|
+
...result,
|
|
213
|
+
to: result.id,
|
|
214
|
+
id: anyIndexObj.id,
|
|
215
|
+
//from: anyIndexObj
|
|
216
|
+
}
|
|
217
|
+
})
|
|
218
|
+
.to(output)
|
|
219
|
+
}
|
|
220
|
+
})`, { indexName: 'scope_objectByScope', scopeType, scope, objectType }]
|
|
221
|
+
/* const path = objectByScopeIndex.rangePath(
|
|
222
|
+
allParams.slice(0, allParams.findIndex(p => p === undefined)),
|
|
223
|
+
range
|
|
224
|
+
) */
|
|
225
|
+
console.log('path', path)
|
|
226
|
+
return path
|
|
227
|
+
}
|
|
228
|
+
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/scope-service",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/access-control-service": "^0.9.
|
|
26
|
-
"@live-change/framework": "^0.9.
|
|
27
|
-
"@live-change/relations-plugin": "^0.9.
|
|
25
|
+
"@live-change/access-control-service": "^0.9.66",
|
|
26
|
+
"@live-change/framework": "^0.9.66",
|
|
27
|
+
"@live-change/relations-plugin": "^0.9.66"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "8c76cb48a8cb459f3cfe08983f5b288c10e5f688"
|
|
30
30
|
}
|