@servable/tools 1.2.1 → 1.3.1

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
@@ -3,7 +3,7 @@
3
3
  "type": "module",
4
4
  "source": "src/index.js",
5
5
  "main": "src/index.js",
6
- "version": "1.2.1",
6
+ "version": "1.3.1",
7
7
  "description": "Servable tools is a utility that builds a feature's manifest and documents it.",
8
8
  "author": "Servable Community",
9
9
  "license": "ISC",
@@ -12,6 +12,9 @@ import directoryFilesRecursive from '../../lib/directoryFilesRecursive.js'
12
12
  import { FeatureEnum } from '../../manifest/data/1.0.0/enums.js'
13
13
 
14
14
  import triggerItems from './lib/triggerItems.js'
15
+ import fs from 'fs'
16
+ import fspath from 'path'
17
+ import semver from 'semver'
15
18
 
16
19
  export default class FeatureLoaderV1_0_0 extends BaseClass {
17
20
 
@@ -825,25 +828,54 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
825
828
  }
826
829
 
827
830
  async routes() {
828
- const cacheKey = 'routes'
829
- if (this._valueInCache(cacheKey)) {
830
- return this._valueInCache(cacheKey)
831
- }
832
-
833
831
  let path = `${this.path}/routes`
834
832
  if (!(await checkFileExists(path))) {
835
833
  return null
836
834
  }
837
835
 
838
- const data = (await directoryGlob({
839
- path: `${path}/**/*.js`, globOptions: {
840
- mark: true,
841
- ignore: ['**/lib/**']
836
+ let data = {}
837
+ const items = await fs.promises.readdir(path)
838
+ if (!items || !items.length) {
839
+ return null
840
+ }
841
+
842
+ for (let i = 0; i < items.length; i++) {
843
+ const item = items[i]
844
+ if (!item) {
845
+ continue
842
846
  }
843
- }))
847
+
848
+ if (item[0] !== 'v') {
849
+ continue
850
+ }
851
+
852
+ if (!semver.valid(semver.coerce(item))) {
853
+ continue
854
+ }
855
+ const __path = fspath.join(path, item)
856
+ const _stat = await fs.promises.stat(__path)
857
+ if (!_stat) {
858
+ continue
859
+ }
860
+
861
+ const isDir = _stat.isDirectory()
862
+ if (!isDir) {
863
+ continue
864
+ }
865
+
866
+ let _data = (await directoryGlob({
867
+ path: `${__path}/**/*.js`, globOptions: {
868
+ mark: true,
869
+ ignore: ['**/lib/**']
870
+ }
871
+ }))
872
+ data[item] = _data
873
+ }
874
+
844
875
  return data
845
876
  }
846
877
 
878
+
847
879
  async liveQueries() {
848
880
  let path = `${this.path}/livequeries`
849
881
  if (!(await checkFileExists(path))) {
@@ -12,6 +12,9 @@ import directoryFilesRecursive from '../../lib/directoryFilesRecursive.js'
12
12
  import { FeatureEnum } from '../../manifest/data/1.0.0/enums.js'
13
13
 
14
14
  import triggerItems from './lib/triggerItems.js'
15
+ import fs from 'fs'
16
+ import fspath from 'path'
17
+ import semver from 'semver'
15
18
 
16
19
  export default class FeatureLoaderV1_1_0 extends BaseClass {
17
20
 
@@ -830,16 +833,50 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
830
833
  return null
831
834
  }
832
835
 
833
- const data = (await directoryGlob({
834
- path: `${path}/**/*.js`, globOptions: {
835
- mark: true,
836
- ignore: ['**/lib/**']
836
+ let data = {}
837
+ const items = await fs.promises.readdir(path)
838
+ if (!items || !items.length) {
839
+ return null
840
+ }
841
+
842
+ for (let i = 0; i < items.length; i++) {
843
+ const item = items[i]
844
+ if (!item) {
845
+ continue
837
846
  }
838
- }))
847
+
848
+ if (item[0] !== 'v') {
849
+ continue
850
+ }
851
+
852
+ if (!semver.valid(semver.coerce(item))) {
853
+ continue
854
+ }
855
+ const __path = fspath.join(path, item)
856
+ const _stat = await fs.promises.stat(__path)
857
+ if (!_stat) {
858
+ continue
859
+ }
860
+
861
+ const isDir = _stat.isDirectory()
862
+ if (!isDir) {
863
+ continue
864
+ }
865
+
866
+ let _data = (await directoryGlob({
867
+ path: `${__path}/**/*.js`, globOptions: {
868
+ mark: true,
869
+ ignore: ['**/lib/**']
870
+ }
871
+ }))
872
+ data[item] = _data
873
+ }
874
+
839
875
  return data
840
876
  }
841
877
 
842
878
  async targetRoutes() {
879
+ //#TODO:
843
880
  let path = `${this.path}/target/routes`
844
881
  if (!(await checkFileExists(path))) {
845
882
  return null
@@ -133,7 +133,7 @@ export const fetchObject = async ({
133
133
  export const destroyRowsWithQuery = async ({ query, limitPerBatch } = {}) => {
134
134
  query
135
135
  .limit(limitPerBatch)
136
- .find()
136
+ .find({ useMasterKey: true })
137
137
  .then(function (results) {
138
138
  return Servable.App.Object.destroyAll(results).then(function () {
139
139
  return Promise.resolve(results.length);
@@ -24,10 +24,40 @@ export default async (props) => {
24
24
 
25
25
  //#TODO: feature.loader
26
26
  const _classLevelPermissions = await feature.loader.schemaClassLevelPermissions()
27
- if (_classLevelPermissions) {
28
- const __classLevelPermissions = preserveMostRestricted([_classSchema.classLevelPermissions, _classLevelPermissions])
29
- _classSchema.classLevelPermissions = __classLevelPermissions
27
+ let __classLevelPermissions
28
+ if (_classLevelPermissions && Object.keys(_classLevelPermissions).length) {
29
+ __classLevelPermissions = preserveMostRestricted([_classSchema.classLevelPermissions, _classLevelPermissions])
30
+ } else {
31
+ __classLevelPermissions = {
32
+ "find": {
33
+ "role:admin": true
34
+ },
35
+ "count": {
36
+ "role:admin": true
37
+ },
38
+ "get": {
39
+ "role:admin": true
40
+ },
41
+ "create": {
42
+ "role:admin": true
43
+ },
44
+ "update": {
45
+ "role:admin": true
46
+ },
47
+ "delete": {
48
+ "role:admin": true
49
+ },
50
+ "addField": {
51
+ "role:admin": true
52
+ },
53
+ "protectedFields": {
54
+ "*": []
55
+ }
56
+ }
30
57
  }
58
+
59
+
60
+ _classSchema.classLevelPermissions = __classLevelPermissions
31
61
  } catch (e) {
32
62
  console.error(e)
33
63
  }
@@ -1,68 +1,96 @@
1
1
  export default (items) => {
2
- const permissions = dedupePermissions(items)
3
- const protectedFields = dedupeProtectedFields(items)
2
+ let permissions = dedupePermissions(items)
3
+ const protectedFields = dedupeProtectedFields(items)
4
4
 
5
- return {
6
- ...permissions,
7
- protectedFields
8
- }
5
+ permissions = {
6
+ "find": {
7
+ "role:admin": true
8
+ },
9
+ "count": {
10
+ "role:admin": true
11
+ },
12
+ "get": {
13
+ "role:admin": true
14
+ },
15
+ "create": {
16
+ "role:admin": true
17
+ },
18
+ "update": {
19
+ "role:admin": true
20
+ },
21
+ "delete": {
22
+ "role:admin": true
23
+ },
24
+ "addField": {
25
+ "role:admin": true
26
+ },
27
+ "protectedFields": {
28
+ "*": []
29
+ },
30
+ ...permissions
31
+ }
32
+
33
+ return {
34
+ ...permissions,
35
+ protectedFields
36
+ }
9
37
  }
10
38
 
11
39
  const dedupeProtectedFields = (items) => {
12
- const a = items[0].protectedFields ? items[0].protectedFields : {}
13
- const b = items[1].protectedFields ? items[1].protectedFields : {}
14
- const aKeys = Object.keys(a)
15
- const bKeys = Object.keys(b)
40
+ const a = items[0].protectedFields ? items[0].protectedFields : {}
41
+ const b = items[1].protectedFields ? items[1].protectedFields : {}
42
+ const aKeys = Object.keys(a)
43
+ const bKeys = Object.keys(b)
16
44
 
17
- const result = {}
18
- const keys = [...(new Set([...aKeys, ...bKeys]))]
19
- keys.forEach(key => {
20
- result[key] = [
21
- ...(a[key] ? a[key] : []),
22
- ...(b[key] ? b[key] : []),
23
- ]
24
- result[key] = result[key].filter(a => a)
25
- })
45
+ const result = {}
46
+ const keys = [...(new Set([...aKeys, ...bKeys]))]
47
+ keys.forEach(key => {
48
+ result[key] = [
49
+ ...(a[key] ? a[key] : []),
50
+ ...(b[key] ? b[key] : []),
51
+ ]
52
+ result[key] = result[key].filter(a => a)
53
+ })
26
54
 
27
- return result
55
+ return result
28
56
  }
29
57
 
30
58
  const dedupePermissions = (items) => {
31
- const a = items[0] ? items[0] : {}
32
- const b = items[1] ? items[1] : {}
33
- const aKeys = Object.keys(a).filter(a => a !== "protectedFields")
34
- const bKeys = Object.keys(b).filter(a => a !== "protectedFields")
35
- const result = {}
36
- const keys = [...(new Set([...aKeys, ...bKeys]))]
37
- keys.forEach(key => {
38
- result[key] = dedupePermission(a[key], b[key])
39
- })
59
+ const a = items[0] ? items[0] : {}
60
+ const b = items[1] ? items[1] : {}
61
+ const aKeys = Object.keys(a).filter(a => a !== "protectedFields")
62
+ const bKeys = Object.keys(b).filter(a => a !== "protectedFields")
63
+ const result = {}
64
+ const keys = [...(new Set([...aKeys, ...bKeys]))]
65
+ keys.forEach(key => {
66
+ result[key] = dedupePermission(a[key], b[key])
67
+ })
40
68
 
41
- return result
69
+ return result
42
70
  }
43
71
 
44
72
  const dedupePermission = (a, b) => {
45
- if (!a) {
46
- return b
47
- }
73
+ if (!a) {
74
+ return b
75
+ }
48
76
 
49
- if (!b) {
50
- return a
51
- }
77
+ if (!b) {
78
+ return a
79
+ }
52
80
 
53
- const aKeys = Object.keys(a)
54
- const bKeys = Object.keys(b)
55
- const result = {}
56
- const keys = [...(new Set([...aKeys, ...bKeys]))]
81
+ const aKeys = Object.keys(a)
82
+ const bKeys = Object.keys(b)
83
+ const result = {}
84
+ const keys = [...(new Set([...aKeys, ...bKeys]))]
57
85
 
58
- keys.forEach(key => {
59
- if (key === 'requiresAuthentication') {
60
- result.requiresAuthentication = (a.requiresAuthentication || b.aRequiresAuthentication)
61
- delete result["*"]
62
- }
86
+ keys.forEach(key => {
87
+ if (key === 'requiresAuthentication') {
88
+ result.requiresAuthentication = (a.requiresAuthentication || b.aRequiresAuthentication)
89
+ delete result["*"]
90
+ }
63
91
 
64
- result[key] = b.hasOwnProperty(key) ? b[key] : a[key]
65
- })
92
+ result[key] = b.hasOwnProperty(key) ? b[key] : a[key]
93
+ })
66
94
 
67
- return result
68
- }
95
+ return result
96
+ }