@servable/tools 1.1.4 → 1.1.6

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.1.4",
6
+ "version": "1.1.6",
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",
@@ -15,6 +15,8 @@ import triggerItems from './lib/triggerItems.js'
15
15
 
16
16
  export default class FeatureLoaderV1_0_0 extends BaseClass {
17
17
 
18
+ // #region class
19
+
18
20
  async getClass({ className }) {
19
21
  const cacheKey = 'class'
20
22
  if (this._valueInCache(cacheKey)) {
@@ -22,31 +24,12 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
22
24
  }
23
25
 
24
26
  const path = `${this.path}/classes/${className.toLowerCase()}/class/index.js`
25
- // const path = `${this.path}/classes/${className.toLowerCase()}/class/index.js`
26
27
 
27
28
  if (!(await checkFileExists(path))) {
28
- //console.log('class>', className, 'file does not exist', path)
29
- const externalClassesPath = `${this.path}/classes/external`
30
- if (!(await checkFileExists(externalClassesPath))) {
31
- return null
32
- }
33
- try {
34
- const data = (await import(externalClassesPath)).default
35
- if (!data) {
36
- //console.log('class>', className, 'data null')
37
- return null
38
- }
39
- // //console.log('class>', className, 'dataff', data)
40
- return data[className]
41
- } catch (e) {
42
- console.error(e)
43
- return null
44
- }
29
+ return null
45
30
  }
46
- // //console.log('class>', className, 'file exists')
47
- const dd = await this._importJSDefault({ path, })
48
- // //console.log('class>', className, 'file exists', dd)
49
- return dd
31
+
32
+ return this._importJSDefault({ path, })
50
33
  }
51
34
 
52
35
  async classFunctions({ className }) {
@@ -64,7 +47,6 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
64
47
  }
65
48
 
66
49
  const data = (await directoryFilesRecursive({ path }))
67
- //this.cache[cacheKey] = data
68
50
  return data
69
51
  }
70
52
 
@@ -224,6 +206,85 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
224
206
  return result
225
207
  }
226
208
 
209
+
210
+ classConfigFolder({ className }) {
211
+ return `${this.path}/classes/${className.toLowerCase()}/config`
212
+ }
213
+
214
+ async classConfigDataFiles({ className }) {
215
+ const cacheKey = 'classConfigDataFiles'
216
+ if (this._valueInCache(cacheKey)) {
217
+ return this._valueInCache(cacheKey)
218
+ }
219
+
220
+ const path = this.classConfigFolder({ className })
221
+ const result = {}
222
+
223
+ const valuesPath = `${path}/entries.json`
224
+ if ((await checkFileExists(valuesPath))) {
225
+ result.entries = await importJSONAsync(valuesPath)
226
+ }
227
+
228
+ const conditionsPath = `${path}/conditions.json`
229
+ if ((await checkFileExists(conditionsPath))) {
230
+ result.conditions = await importJSONAsync(conditionsPath)
231
+ }
232
+
233
+ const groupsPath = `${path}/groups.json`
234
+ if ((await checkFileExists(groupsPath))) {
235
+ result.groups = await importJSONAsync(groupsPath)
236
+ }
237
+
238
+ return result
239
+ }
240
+
241
+
242
+ async classFeatures({ className, withFeaturesFeatures = false }) {
243
+ const cacheKey = 'class'
244
+ // //console.log('classFeatures>', className, 'enter')
245
+ if (this._valueInCache(cacheKey)) {
246
+ return this._valueInCache(cacheKey)
247
+ }
248
+ const items = []
249
+ const seedMode = await this.classSeedMode({ className })
250
+ // //console.log('classFeatures>', className, 'seedmode', seedMode)
251
+ if (seedMode === 'auto') {
252
+ items.push({ id: 'servableautoseedable' })
253
+ }
254
+ const _class = await this.getClass({ className })
255
+ if (!_class) {
256
+ //console.log('classFeatures>', className, 'no _class')
257
+ return items
258
+ }
259
+
260
+ let data = mergeClassFeatures({ items, _class, withFeaturesFeatures })
261
+ const path = `${this.path}/classes/${className.toLowerCase()}/class/protocols.js`
262
+
263
+ if ((await checkFileExists(path))) {
264
+
265
+ let _data = (await import(path)).default
266
+ // //console.log('classFeatures>', className, '_data', _data)
267
+ _data = _data ? _data : []
268
+ data = [...data,
269
+ ..._data]
270
+ }
271
+
272
+ //this.cache[cacheKey] = data
273
+ data = cleanFeatures(data)
274
+ // result = _.uniq(result, a => a.id)
275
+ // //console.log('classFeatures>', className, 'finaldata', data)
276
+ return data
277
+ }
278
+
279
+ // #endregion
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+
227
288
  async afterInit() {
228
289
  const cacheKey = 'afterInit'
229
290
  if (this._valueInCache(cacheKey)) {
@@ -284,37 +345,6 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
284
345
  return result
285
346
  }
286
347
 
287
- classConfigFolder({ className }) {
288
- return `${this.path}/classes/${className.toLowerCase()}/config`
289
- }
290
-
291
- async classConfigDataFiles({ className }) {
292
- const cacheKey = 'classConfigDataFiles'
293
- if (this._valueInCache(cacheKey)) {
294
- return this._valueInCache(cacheKey)
295
- }
296
-
297
- const path = this.classConfigFolder({ className })
298
- const result = {}
299
-
300
- const valuesPath = `${path}/entries.json`
301
- if ((await checkFileExists(valuesPath))) {
302
- result.entries = await importJSONAsync(valuesPath)
303
- }
304
-
305
- const conditionsPath = `${path}/conditions.json`
306
- if ((await checkFileExists(conditionsPath))) {
307
- result.conditions = await importJSONAsync(conditionsPath)
308
- }
309
-
310
- const groupsPath = `${path}/groups.json`
311
- if ((await checkFileExists(groupsPath))) {
312
- result.groups = await importJSONAsync(groupsPath)
313
- }
314
-
315
- return result
316
- }
317
-
318
348
  seedFolder() {
319
349
  return `${this.path}/seed`
320
350
  }
@@ -451,6 +481,7 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
451
481
 
452
482
 
453
483
 
484
+ //#region schema
454
485
 
455
486
  async classesSchemas(props) {
456
487
  // if (this.valueInCache('classes')) {
@@ -640,42 +671,9 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
640
671
  return data
641
672
  }
642
673
 
643
- async classFeatures({ className, withFeaturesFeatures = false }) {
644
- const cacheKey = 'class'
645
- // //console.log('classFeatures>', className, 'enter')
646
- if (this._valueInCache(cacheKey)) {
647
- return this._valueInCache(cacheKey)
648
- }
649
- const items = []
650
- const seedMode = await this.classSeedMode({ className })
651
- // //console.log('classFeatures>', className, 'seedmode', seedMode)
652
- if (seedMode === 'auto') {
653
- items.push({ id: 'servableautoseedable' })
654
- }
655
- const _class = await this.getClass({ className })
656
- if (!_class) {
657
- //console.log('classFeatures>', className, 'no _class')
658
- return items
659
- }
674
+ //#endregion
660
675
 
661
- let data = mergeClassFeatures({ items, _class, withFeaturesFeatures })
662
- const path = `${this.path}/classes/${className.toLowerCase()}/class/protocols.js`
663
676
 
664
- if ((await checkFileExists(path))) {
665
-
666
- let _data = (await import(path)).default
667
- // //console.log('classFeatures>', className, '_data', _data)
668
- _data = _data ? _data : []
669
- data = [...data,
670
- ..._data]
671
- }
672
-
673
- //this.cache[cacheKey] = data
674
- data = cleanFeatures(data)
675
- // result = _.uniq(result, a => a.id)
676
- // //console.log('classFeatures>', className, 'finaldata', data)
677
- return data
678
- }
679
677
 
680
678
 
681
679
  async ownFeatures() {
@@ -722,7 +720,7 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
722
720
 
723
721
  return this._importJSDefault({ path, })
724
722
  }
725
-
723
+ //#region system
726
724
  async systemDockerCompose() {
727
725
  const cacheKey = 'systemDockerCompose'
728
726
  if (this._valueInCache(cacheKey)) {
@@ -790,7 +788,7 @@ export default class FeatureLoaderV1_0_0 extends BaseClass {
790
788
  return this._importJSDefault({ path, })
791
789
  }
792
790
 
793
-
791
+ //#endregion
794
792
 
795
793
  async functions() {
796
794
  const cacheKey = 'functions'
@@ -15,6 +15,8 @@ import triggerItems from './lib/triggerItems.js'
15
15
 
16
16
  export default class FeatureLoaderV1_1_0 extends BaseClass {
17
17
 
18
+ // #region class
19
+
18
20
  async getClass({ className }) {
19
21
  const cacheKey = 'class'
20
22
  if (this._valueInCache(cacheKey)) {
@@ -22,33 +24,269 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
22
24
  }
23
25
 
24
26
  const path = `${this.path}/models/${className.toLowerCase()}/class.js`
25
- // const path = `${this.path}/models/${className.toLowerCase()}target/class.js`
26
27
 
27
28
  if (!(await checkFileExists(path))) {
28
- //console.log('class>', className, 'file does not exist', path)
29
- const externalClassesPath = `${this.path}/models/external`
30
- if (!(await checkFileExists(externalClassesPath))) {
29
+ return null
30
+ }
31
+
32
+ return this._importJSDefault({ path, })
33
+ }
34
+
35
+
36
+ async classFunctions({ className }) {
37
+ const cacheKey = 'classFunctions'
38
+ if (this._valueInCache(cacheKey)) {
39
+ return this._valueInCache(cacheKey)
40
+ }
41
+
42
+ let path = `${this.path}/models/${className.toLowerCase()}/functions`
43
+ if (!(await checkFileExists(path))) {
44
+ path = `${this.path}/models/${className.toLowerCase()}/cloudCode`
45
+ if (!(await checkFileExists(path))) {
31
46
  return null
32
47
  }
33
- try {
34
- const data = (await import(externalClassesPath)).default
35
- if (!data) {
36
- //console.log('class>', className, 'data null')
37
- return null
38
- }
39
- // //console.log('class>', className, 'dataff', data)
40
- return data[className]
41
- } catch (e) {
42
- console.error(e)
43
- return null
48
+ }
49
+
50
+ const data = (await directoryFilesRecursive({ path }))
51
+ return data
52
+ }
53
+
54
+ async classTriggers({ className }) {
55
+ const cacheKey = 'classTriggers'
56
+ if (this._valueInCache(cacheKey)) {
57
+ return this._valueInCache(cacheKey)
58
+ }
59
+
60
+ const prefix = `${this.path}/models/${className.toLowerCase()}/triggers`
61
+
62
+ const data = {}
63
+ for (var i = 0; i < triggerItems.length; i++) {
64
+ const item = triggerItems[i]
65
+ const path = `${prefix}/${item}.js`
66
+ if (!(await checkFileExists(path))) {
67
+ continue
68
+ }
69
+
70
+ const itemData = (await import(path))
71
+ if (!itemData || !itemData.default) {
72
+ continue
44
73
  }
74
+
75
+ data[item] = itemData.default
76
+ }
77
+
78
+ if (Object.keys(data).length > 0) {
79
+ return data
80
+ }
81
+
82
+ return this.classTriggersMerged({ className })
83
+ }
84
+
85
+
86
+
87
+
88
+ async classTriggersMerged({ className }) {
89
+ const cacheKey = 'classTriggers'
90
+ if (this._valueInCache(cacheKey)) {
91
+ return this._valueInCache(cacheKey)
92
+ }
93
+
94
+ const path = `${this.path}/models/${className.toLowerCase()}/triggers/index.js`
95
+ if (!(await checkFileExists(path))) {
96
+ return null
97
+ }
98
+
99
+ const data = (await import(path))
100
+ //this.cache[cacheKey] = data
101
+ return data
102
+ }
103
+
104
+ async classJobs({ className }) {
105
+ const cacheKey = 'classJobs'
106
+ if (this._valueInCache(cacheKey)) {
107
+ return this._valueInCache(cacheKey)
108
+ }
109
+
110
+ const path = `${this.path}/models/${className.toLowerCase()}/jobs`
111
+ if (!(await checkFileExists(path))) {
112
+ return null
113
+ }
114
+
115
+ const data = (await directoryFilesRecursive({ path }))
116
+ //this.cache[cacheKey] = data
117
+ return data
118
+ }
119
+
120
+ classSeedFolder({ className }) {
121
+ return `${this.path}/models/${className.toLowerCase()}/seed`
122
+ }
123
+
124
+ async classSeedMode(props) {
125
+ const cacheKey = 'classSeedMode'
126
+ if (this._valueInCache(cacheKey)) {
127
+ return this._valueInCache(cacheKey)
128
+ }
129
+
130
+ const classSeedFolder = this.classSeedFolder(props)
131
+ let _path = `${classSeedFolder}/index.js`
132
+ if ((await checkFileExists(_path))) {
133
+ return 'manual'
134
+ }
135
+
136
+ _path = `${classSeedFolder}/transformer.js`
137
+ if ((await checkFileExists(_path))) {
138
+ return 'auto'
139
+ }
140
+
141
+ return 'none'
142
+ }
143
+
144
+ async classSeedManual(props) {
145
+ const cacheKey = 'classSeedManual'
146
+ if (this._valueInCache(cacheKey)) {
147
+ return this._valueInCache(cacheKey)
148
+ }
149
+
150
+ const classSeedFolder = this.classSeedFolder(props)
151
+ let _path = `${classSeedFolder}/index.js`
152
+ if (!(await checkFileExists(_path))) {
153
+ return null
154
+ }
155
+
156
+ const data = (await import(_path)).default
157
+ //this.cache[cacheKey] = data
158
+ return data
159
+ }
160
+
161
+ async classSeedMetadata(props) {
162
+ const cacheKey = 'classSeedMetadata'
163
+ if (this._valueInCache(cacheKey)) {
164
+ return this._valueInCache(cacheKey)
165
+ }
166
+
167
+ const classSeedFolder = this.classSeedFolder(props)
168
+
169
+ const _path = `${classSeedFolder}/metadata.json`
170
+ if (!(await checkFileExists(_path))) {
171
+ return null
172
+ }
173
+
174
+ const data = await importJSONAsync(_path)
175
+ //this.cache[cacheKey] = data
176
+ return data
177
+ }
178
+
179
+ async classSeedAutoFiles(props) {
180
+ const { className } = props
181
+ const cacheKey = 'classSeedAutoFiles'
182
+ if (this._valueInCache(cacheKey)) {
183
+ return this._valueInCache(cacheKey)
184
+ }
185
+
186
+ const path = this.classSeedFolder({ className })
187
+ const result = {}
188
+
189
+ let _path = `${path}/data.json`
190
+ if ((await checkFileExists(_path))) {
191
+ result.data = await importJSONAsync(_path)
192
+ }
193
+
194
+ _path = `${path}/transformer.js`
195
+ if ((await checkFileExists(_path))) {
196
+ result.transformer = (await import(_path)).default
197
+ // console.log("[Servable]", result.transformer)
198
+ }
199
+
200
+ _path = `${path}/validator.js`
201
+ if ((await checkFileExists(_path))) {
202
+ result.validator = (await import(_path)).default
45
203
  }
46
- // //console.log('class>', className, 'file exists')
47
- const dd = await this._importJSDefault({ path, })
48
- // //console.log('class>', className, 'file exists', dd)
49
- return dd
204
+
205
+ _path = `${path}/ref.js`
206
+ if ((await checkFileExists(_path))) {
207
+ result.uniqueRef = (await import(_path)).default
208
+ }
209
+
210
+ return result
211
+ }
212
+
213
+ classConfigFolder({ className }) {
214
+ return `${this.path}/models/${className.toLowerCase()}/config`
50
215
  }
51
216
 
217
+ async classConfigDataFiles({ className }) {
218
+ const cacheKey = 'classConfigDataFiles'
219
+ if (this._valueInCache(cacheKey)) {
220
+ return this._valueInCache(cacheKey)
221
+ }
222
+
223
+ const path = this.classConfigFolder({ className })
224
+ const result = {}
225
+
226
+ const valuesPath = `${path}/entries.json`
227
+ if ((await checkFileExists(valuesPath))) {
228
+ result.entries = await importJSONAsync(valuesPath)
229
+ }
230
+
231
+ const conditionsPath = `${path}/conditions.json`
232
+ if ((await checkFileExists(conditionsPath))) {
233
+ result.conditions = await importJSONAsync(conditionsPath)
234
+ }
235
+
236
+ const groupsPath = `${path}/groups.json`
237
+ if ((await checkFileExists(groupsPath))) {
238
+ result.groups = await importJSONAsync(groupsPath)
239
+ }
240
+
241
+ return result
242
+ }
243
+
244
+
245
+ async classFeatures({ className, withFeaturesFeatures = false }) {
246
+ const cacheKey = 'class'
247
+ // //console.log('classFeatures>', className, 'enter')
248
+ if (this._valueInCache(cacheKey)) {
249
+ return this._valueInCache(cacheKey)
250
+ }
251
+ const items = []
252
+ const seedMode = await this.classSeedMode({ className })
253
+ // //console.log('classFeatures>', className, 'seedmode', seedMode)
254
+ if (seedMode === 'auto') {
255
+ items.push({ id: 'servableautoseedable' })
256
+ }
257
+ const _class = await this.getClass({ className })
258
+ if (!_class) {
259
+ //console.log('classFeatures>', className, 'no _class')
260
+ return items
261
+ }
262
+
263
+ let data = mergeClassFeatures({ items, _class, withFeaturesFeatures })
264
+ const path = `${this.path}/models/${className.toLowerCase()}/features.js`
265
+
266
+ if ((await checkFileExists(path))) {
267
+
268
+ let _data = (await import(path)).default
269
+ // //console.log('classFeatures>', className, '_data', _data)
270
+ _data = _data ? _data : []
271
+ data = [...data,
272
+ ..._data]
273
+ }
274
+
275
+ //this.cache[cacheKey] = data
276
+ data = cleanFeatures(data)
277
+ // result = _.uniq(result, a => a.id)
278
+ // //console.log('classFeatures>', className, 'finaldata', data)
279
+ return data
280
+ }
281
+
282
+ // #endregion
283
+
284
+
285
+
286
+
287
+
288
+
289
+
52
290
 
53
291
  async afterInit() {
54
292
  const main = await this.main()
@@ -181,7 +419,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
181
419
  return this._valueInCache(cacheKey)
182
420
  }
183
421
 
184
- const prefix = `${this.path}/triggers`
422
+ const prefix = `${this.path}/target/triggers`
185
423
 
186
424
  const data = {}
187
425
  for (var i = 0; i < triggerItems.length; i++) {
@@ -212,7 +450,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
212
450
  return this._valueInCache(cacheKey)
213
451
  }
214
452
 
215
- const path = `${this.path}/triggers/index.js`
453
+ const path = `${this.path}/target/triggers/index.js`
216
454
  if (!(await checkFileExists(path))) {
217
455
  return null
218
456
  }
@@ -228,7 +466,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
228
466
  return this._valueInCache(cacheKey)
229
467
  }
230
468
 
231
- const path = `${this.path}/triggers/metadata.json`
469
+ const path = `${this.path}/target/triggers/metadata.json`
232
470
  if (!(await checkFileExists(path))) {
233
471
  return null
234
472
  }
@@ -240,6 +478,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
240
478
 
241
479
 
242
480
 
481
+ //#region schema
243
482
 
244
483
  async classesSchemas(props) {
245
484
  // if (this.valueInCache('classes')) {
@@ -429,42 +668,10 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
429
668
  return data
430
669
  }
431
670
 
432
- async classFeatures({ className, withFeaturesFeatures = false }) {
433
- const cacheKey = 'class'
434
- // //console.log('classFeatures>', className, 'enter')
435
- if (this._valueInCache(cacheKey)) {
436
- return this._valueInCache(cacheKey)
437
- }
438
- const items = []
439
- const seedMode = await this.classSeedMode({ className })
440
- // //console.log('classFeatures>', className, 'seedmode', seedMode)
441
- if (seedMode === 'auto') {
442
- items.push({ id: 'servableautoseedable' })
443
- }
444
- const _class = await this.getClass({ className })
445
- if (!_class) {
446
- //console.log('classFeatures>', className, 'no _class')
447
- return items
448
- }
449
-
450
- let data = mergeClassFeatures({ items, _class, withFeaturesFeatures })
451
- const path = `${this.path}/models/${className.toLowerCase()}/features.js`
671
+ //#endregion
452
672
 
453
- if ((await checkFileExists(path))) {
454
673
 
455
- let _data = (await import(path)).default
456
- // //console.log('classFeatures>', className, '_data', _data)
457
- _data = _data ? _data : []
458
- data = [...data,
459
- ..._data]
460
- }
461
674
 
462
- //this.cache[cacheKey] = data
463
- data = cleanFeatures(data)
464
- // result = _.uniq(result, a => a.id)
465
- // //console.log('classFeatures>', className, 'finaldata', data)
466
- return data
467
- }
468
675
 
469
676
 
470
677
  async ownFeatures() {
@@ -473,7 +680,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
473
680
  return this._valueInCache(cacheKey)
474
681
  }
475
682
 
476
- let path = `${this.path}/features.js`
683
+ let path = `${this.path}/target/features.js`
477
684
  if (!(await checkFileExists(path))) {
478
685
  return null
479
686
  }
@@ -490,7 +697,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
490
697
  return this._valueInCache(cacheKey)
491
698
  }
492
699
 
493
- const path = `${this.path}/class.js`
700
+ const path = `${this.path}/target/class.js`
494
701
  if (!(await checkFileExists(path))) {
495
702
  return null
496
703
  }
@@ -503,7 +710,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
503
710
  if (this._valueInCache(cacheKey)) {
504
711
  return this._valueInCache(cacheKey)
505
712
  }
506
-
713
+ //#TODO
507
714
  const path = `${this.path}/liveclasses.js`
508
715
  if (!(await checkFileExists(path))) {
509
716
  return null
@@ -512,6 +719,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
512
719
  return this._importJSDefault({ path, })
513
720
  }
514
721
 
722
+ //#region system
515
723
  async systemDockerCompose() {
516
724
  const cacheKey = 'systemDockerCompose'
517
725
  if (this._valueInCache(cacheKey)) {
@@ -579,6 +787,7 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
579
787
  return this._importJSDefault({ path, })
580
788
  }
581
789
 
790
+ //#endregion
582
791
 
583
792
 
584
793
  async functions() {
@@ -651,221 +860,5 @@ export default class FeatureLoaderV1_1_0 extends BaseClass {
651
860
  //this.cache[cacheKey] = data
652
861
  return data
653
862
  }
654
-
655
-
656
-
657
-
658
-
659
- // #region class
660
-
661
- async classTriggersMerged({ className }) {
662
- const cacheKey = 'classTriggers'
663
- if (this._valueInCache(cacheKey)) {
664
- return this._valueInCache(cacheKey)
665
- }
666
-
667
- const path = `${this.path}/models/${className.toLowerCase()}/triggers/index.js`
668
- if (!(await checkFileExists(path))) {
669
- return null
670
- }
671
-
672
- const data = (await import(path))
673
- //this.cache[cacheKey] = data
674
- return data
675
- }
676
-
677
- async classJobs({ className }) {
678
- const cacheKey = 'classJobs'
679
- if (this._valueInCache(cacheKey)) {
680
- return this._valueInCache(cacheKey)
681
- }
682
-
683
- const path = `${this.path}/models/${className.toLowerCase()}/jobs_`
684
- if (!(await checkFileExists(path))) {
685
- return null
686
- }
687
-
688
- const data = (await directoryFilesRecursive({ path }))
689
- //this.cache[cacheKey] = data
690
- return data
691
- }
692
-
693
- classSeedFolder({ className }) {
694
- return `${this.path}/models/${className.toLowerCase()}/seed`
695
- }
696
-
697
- async classSeedMode(props) {
698
- const cacheKey = 'classSeedMode'
699
- if (this._valueInCache(cacheKey)) {
700
- return this._valueInCache(cacheKey)
701
- }
702
-
703
- const classSeedFolder = this.classSeedFolder(props)
704
- let _path = `${classSeedFolder}/index.js`
705
- if ((await checkFileExists(_path))) {
706
- return 'manual'
707
- }
708
-
709
- _path = `${classSeedFolder}/transformer.js`
710
- if ((await checkFileExists(_path))) {
711
- return 'auto'
712
- }
713
-
714
- return 'none'
715
- }
716
-
717
- async classSeedManual(props) {
718
- const cacheKey = 'classSeedManual'
719
- if (this._valueInCache(cacheKey)) {
720
- return this._valueInCache(cacheKey)
721
- }
722
-
723
- const classSeedFolder = this.classSeedFolder(props)
724
- let _path = `${classSeedFolder}/index.js`
725
- if (!(await checkFileExists(_path))) {
726
- return null
727
- }
728
-
729
- const data = (await import(_path)).default
730
- //this.cache[cacheKey] = data
731
- return data
732
- }
733
-
734
- async classSeedMetadata(props) {
735
- const cacheKey = 'classSeedMetadata'
736
- if (this._valueInCache(cacheKey)) {
737
- return this._valueInCache(cacheKey)
738
- }
739
-
740
- const classSeedFolder = this.classSeedFolder(props)
741
-
742
- const _path = `${classSeedFolder}/metadata.json`
743
- if (!(await checkFileExists(_path))) {
744
- return null
745
- }
746
-
747
- const data = await importJSONAsync(_path)
748
- //this.cache[cacheKey] = data
749
- return data
750
- }
751
-
752
- async classSeedAutoFiles(props) {
753
- const { className } = props
754
- const cacheKey = 'classSeedAutoFiles'
755
- if (this._valueInCache(cacheKey)) {
756
- return this._valueInCache(cacheKey)
757
- }
758
-
759
- const path = this.classSeedFolder({ className })
760
- const result = {}
761
-
762
- let _path = `${path}/data.json`
763
- if ((await checkFileExists(_path))) {
764
- result.data = await importJSONAsync(_path)
765
- }
766
-
767
- _path = `${path}/transformer.js`
768
- if ((await checkFileExists(_path))) {
769
- result.transformer = (await import(_path)).default
770
- // console.log("[Servable]", result.transformer)
771
- }
772
-
773
- _path = `${path}/validator.js`
774
- if ((await checkFileExists(_path))) {
775
- result.validator = (await import(_path)).default
776
- }
777
-
778
- _path = `${path}/ref.js`
779
- if ((await checkFileExists(_path))) {
780
- result.uniqueRef = (await import(_path)).default
781
- }
782
-
783
- return result
784
- }
785
-
786
- classConfigFolder({ className }) {
787
- return `${this.path}/models/${className.toLowerCase()}/config`
788
- }
789
-
790
- async classConfigDataFiles({ className }) {
791
- const cacheKey = 'classConfigDataFiles'
792
- if (this._valueInCache(cacheKey)) {
793
- return this._valueInCache(cacheKey)
794
- }
795
-
796
- const path = this.classConfigFolder({ className })
797
- const result = {}
798
-
799
- const valuesPath = `${path}/entries.json`
800
- if ((await checkFileExists(valuesPath))) {
801
- result.entries = await importJSONAsync(valuesPath)
802
- }
803
-
804
- const conditionsPath = `${path}/conditions.json`
805
- if ((await checkFileExists(conditionsPath))) {
806
- result.conditions = await importJSONAsync(conditionsPath)
807
- }
808
-
809
- const groupsPath = `${path}/groups.json`
810
- if ((await checkFileExists(groupsPath))) {
811
- result.groups = await importJSONAsync(groupsPath)
812
- }
813
-
814
- return result
815
- }
816
-
817
-
818
- async classFunctions({ className }) {
819
- const cacheKey = 'classFunctions'
820
- if (this._valueInCache(cacheKey)) {
821
- return this._valueInCache(cacheKey)
822
- }
823
-
824
- let path = `${this.path}/models/${className.toLowerCase()}/functions`
825
- if (!(await checkFileExists(path))) {
826
- path = `${this.path}/models/${className.toLowerCase()}/cloudCode`
827
- if (!(await checkFileExists(path))) {
828
- return null
829
- }
830
- }
831
-
832
- const data = (await directoryFilesRecursive({ path }))
833
- //this.cache[cacheKey] = data
834
- return data
835
- }
836
-
837
- async classTriggers({ className }) {
838
- const cacheKey = 'classTriggers'
839
- if (this._valueInCache(cacheKey)) {
840
- return this._valueInCache(cacheKey)
841
- }
842
-
843
- const prefix = `${this.path}/models/${className.toLowerCase()}/triggers`
844
-
845
-
846
- const data = {}
847
- for (var i = 0; i < triggerItems.length; i++) {
848
- const item = triggerItems[i]
849
- const path = `${prefix}/${item}.js`
850
- if (!(await checkFileExists(path))) {
851
- continue
852
- }
853
-
854
- const itemData = (await import(path))
855
- if (!itemData || !itemData.default) {
856
- continue
857
- }
858
-
859
- data[item] = itemData.default
860
- }
861
-
862
- if (Object.keys(data).length > 0) {
863
- return data
864
- }
865
-
866
- return this.classTriggersMerged({ className })
867
- }
868
-
869
- // #endregion
870
863
  }
871
864
 
@@ -60,6 +60,29 @@ export const performBatchOnQuery = async ({
60
60
  } while (loops < expectedLoops || currentBatchResultsLength === batchSize);
61
61
  };
62
62
 
63
+ export const performBatchOnQueryPerGroup = async ({
64
+ query,
65
+ batchSize = 100,
66
+ action
67
+ }) => {
68
+ const count = await query.count({ useMasterKey: true });
69
+ const expectedLoops = parseInt(count / batchSize);
70
+ let currentBatchResultsLength = 0;
71
+ let loops = 0;
72
+
73
+ do {
74
+ query.skip(batchSize * loops);
75
+ query.limit(batchSize);
76
+ const items = await query.find({ useMasterKey: true });
77
+ if (items && items.length) {
78
+ await action({ items })
79
+ }
80
+
81
+ currentBatchResultsLength = items.length;
82
+ loops++;
83
+ } while (loops < expectedLoops || currentBatchResultsLength === batchSize);
84
+ };
85
+
63
86
  export const fetchObjectIfNeeded = async ({
64
87
  object,
65
88
  className,
@@ -111,8 +134,8 @@ export const destroyRowsWithQuery = async ({ query, limitPerBatch } = {}) => {
111
134
  query
112
135
  .limit(limitPerBatch)
113
136
  .find()
114
- .then(function(results) {
115
- return Servable.App.Object.destroyAll(results).then(function() {
137
+ .then(function (results) {
138
+ return Servable.App.Object.destroyAll(results).then(function () {
116
139
  return Promise.resolve(results.length);
117
140
  });
118
141
  });
@@ -122,7 +145,7 @@ export const destroyAllRowsWithQuery = async ({
122
145
  query,
123
146
  limitPerBatch = 1000
124
147
  } = {}) => {
125
- return destroyRowsWithQuery({ query, limitPerBatch }).then(function(count) {
148
+ return destroyRowsWithQuery({ query, limitPerBatch }).then(function (count) {
126
149
  return count
127
150
  ? destroyAllRowsWithQuery({ query, limitPerBatch })
128
151
  : Promise.resolve();