@live-change/scope-service 0.9.62 → 0.9.63

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/LICENSE.md ADDED
@@ -0,0 +1,11 @@
1
+ Copyright 2019-2024 Michał Łaszczewski
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+
7
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+
9
+ 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
10
+
11
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/config.js CHANGED
@@ -1,15 +1,15 @@
1
1
  import definition from './definition.js'
2
2
 
3
3
  const {
4
-
4
+ objectScopePathsRoles = ['reader', 'writer', 'admin', 'owner']
5
5
  } = definition.config
6
6
 
7
7
  definition.clientConfig = {
8
-
8
+ objectScopePathsRoles: ['reader', 'writer', 'admin', 'owner']
9
9
  }
10
10
 
11
11
  const config = {
12
-
12
+ objectScopePathsRoles
13
13
  }
14
14
 
15
15
  export default config
package/indexes.js CHANGED
@@ -6,8 +6,8 @@ const config = definition.config
6
6
  import { Scope } from './scopes.js'
7
7
 
8
8
  //*
9
- const scopesByObjectIndex = definition.index({
10
- name: 'scopesByObject',
9
+ const pathByObjectAndScopeIndex = definition.index({
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
13
13
  const scopesTable = await input.table(scopesTableName)
@@ -22,8 +22,11 @@ const scopesByObjectIndex = definition.index({
22
22
  //output.debug('scope', scope, 'path', path)
23
23
  if(!(scope && path)) return null
24
24
  const { ancestorType, ancestor, descendantType, descendant, intermediate } = path
25
+ const identifier = [descendantType, descendant, ancestorType, ancestor].map(v => JSON.stringify(v)).join(':')
26
+ const hash = sha256(identifier + JSON.stringify(intermediate), 'base64').slice(0, 10)
27
+ const id = identifier + '_' + hash
25
28
  return {
26
- id: [descendantType, descendant, ancestorType, ancestor].map(v => JSON.stringify(v)).join(':'),
29
+ id,
27
30
  scopeType: ancestorType,
28
31
  scope: ancestor,
29
32
  objectType: descendantType,
@@ -39,23 +42,95 @@ const scopesByObjectIndex = definition.index({
39
42
  pathsByAncestorDescendantRelationIndexName: 'accessControl_pathsByAncestorDescendantRelation'
40
43
  }
41
44
  })
45
+
42
46
  //*
43
- const objectsByScopeIndex = definition.index({
44
- name: 'objectsByScope',
45
- async function(input, output, { scopesByObjectIndexName }) {
46
- (await input.index(scopesByObjectIndexName))
47
- .map(async ({ scopeType, scope, objectType, object, intermediate }) => ({ // when single parameter, it will ignore null by default
48
- id: [scopeType, scope, objectType, object].map(v => JSON.stringify(v)).join(':'),
49
- objectType,
50
- object,
51
- scopeType,
52
- scope,
53
- intermediate: intermediate.toReversed()
47
+ const pathByScopeAndObjectIndex = definition.index({
48
+ name: 'pathByScopeAndObject',
49
+ async function(input, output, { pathByObjectAndScopeIndexName }) {
50
+ await (await input.index(pathByObjectAndScopeIndexName))
51
+ .map(async ({ id, scopeType, scope, objectType, object, intermediate }) => {
52
+ const identifier = [scopeType, scope, objectType, object].map(v => JSON.stringify(v)).join(':')
53
+ const hash = id.slice(id.lastIndexOf('_')+1)
54
+ return { // when single parameter, it will ignore null by default
55
+ id: identifier + '_' + hash,
56
+ objectType,
57
+ object,
58
+ scopeType,
59
+ scope,
60
+ intermediate: intermediate.toReversed()
61
+ }
62
+ })
63
+ .to(output)
64
+ },
65
+ parameters: {
66
+ pathByObjectAndScopeIndexName: 'scope_pathByObjectAndScope'
67
+ }
68
+ })
69
+
70
+ //*
71
+ const scopeByObjectIndex = definition.index({
72
+ name: 'scopeByObject',
73
+ async function(input, output, { pathByObjectAndScopeIndexName }) {
74
+ await (await input.index(pathByObjectAndScopeIndexName))
75
+ .groupExisting(async ({ id }) => id.slice(0, id.lastIndexOf('_')+1))
76
+ .map(({ id, objectType, object, scopeType, scope }) => ({
77
+ id: id.slice(0, id.lastIndexOf('_')),
78
+ objectType, object, scopeType, scope
54
79
  }))
55
80
  .to(output)
56
81
  },
57
82
  parameters: {
58
- scopesByObjectIndexName: 'scope_scopesByObject'
83
+ pathByObjectAndScopeIndexName: 'scope_pathByObjectAndScope'
59
84
  }
60
85
  })
61
- //*/
86
+ //*/
87
+
88
+ //*
89
+ const objectByScopeIndex = definition.index({
90
+ name: 'objectByScope',
91
+ async function(input, output, { scopeByObjectIndexName }) {
92
+ await (await input.index(scopeByObjectIndexName))
93
+ .map(({ id, objectType, object, scopeType, scope }) => ({
94
+ id: [objectType, object, scopeType, scope].map(v => JSON.stringify(v)).join(':'),
95
+ scopeType, scope, objectType, object
96
+ }))
97
+ .to(output)
98
+ },
99
+ parameters: {
100
+ scopeByObjectIndexName: 'scope_scopeByObject'
101
+ }
102
+ })
103
+
104
+ //*/
105
+
106
+ definition.view({
107
+ name: 'objectScopePaths',
108
+ properties: {
109
+ objectType: {
110
+ type: 'type'
111
+ },
112
+ object: {
113
+ type: 'any'
114
+ },
115
+ scopeType: {
116
+ type: 'type'
117
+ },
118
+ scope: {
119
+ type: 'any'
120
+ },
121
+ ...App.rangeProperties
122
+ },
123
+ accessControl: {
124
+ roles: config.objectScopePathRoles
125
+ },
126
+ daoPath(params, { client, service }, method) {
127
+ const { objectType, object, scopeType, scope } = params
128
+ const range = App.extractRange(params)
129
+ if(!range.limit || range.limit > 1000) range.limit = 1000
130
+ const allParams = [objectType, object, scopeType, scope]
131
+ return pathByObjectAndScopeIndex.rangePath(
132
+ allParams.slice(0, allParams.findIndex(p => p === undefined)),
133
+ range
134
+ )
135
+ }
136
+ })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/scope-service",
3
- "version": "0.9.62",
3
+ "version": "0.9.63",
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.62",
26
- "@live-change/framework": "^0.9.62",
27
- "@live-change/relations-plugin": "^0.9.62"
25
+ "@live-change/access-control-service": "^0.9.63",
26
+ "@live-change/framework": "^0.9.63",
27
+ "@live-change/relations-plugin": "^0.9.63"
28
28
  },
29
- "gitHead": "b1b605b7f1fa4fc3de4720afbb401e2cfff080cf"
29
+ "gitHead": "89b9647aeaff9fc66add1f07d225fe4f44d91a39"
30
30
  }