@servable/tools 1.0.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.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +33 -0
  3. package/package.json +106 -0
  4. package/src/config/candidates/featureCandidates/index.js +48 -0
  5. package/src/config/candidates/index.js +18 -0
  6. package/src/config/index.js +2 -0
  7. package/src/config/validate/feature/index.js +7 -0
  8. package/src/config/validate/index.js +5 -0
  9. package/src/document/1.0.0/all/build/class/index.js +67 -0
  10. package/src/document/1.0.0/all/build/feature/index.js +135 -0
  11. package/src/document/1.0.0/all/index.js +17 -0
  12. package/src/document/1.0.0/all/write/class/index.js +25 -0
  13. package/src/document/1.0.0/all/write/feature/index.js +43 -0
  14. package/src/document/1.0.0/all/write/index.js +10 -0
  15. package/src/document/1.0.0/all/write/utils/chunk.js +19 -0
  16. package/src/document/1.0.0/chunks/build/class/class.js +20 -0
  17. package/src/document/1.0.0/chunks/build/class/functions.js +21 -0
  18. package/src/document/1.0.0/chunks/build/class/lib.js +21 -0
  19. package/src/document/1.0.0/chunks/build/class/seed.js +21 -0
  20. package/src/document/1.0.0/chunks/build/class/triggers.js +26 -0
  21. package/src/document/1.0.0/chunks/build/feature/afterInit.js +20 -0
  22. package/src/document/1.0.0/chunks/build/feature/beforeInit.js +20 -0
  23. package/src/document/1.0.0/chunks/build/feature/class.js +42 -0
  24. package/src/document/1.0.0/chunks/build/feature/config.js +20 -0
  25. package/src/document/1.0.0/chunks/build/feature/functions.js +20 -0
  26. package/src/document/1.0.0/chunks/build/feature/lib.js +21 -0
  27. package/src/document/1.0.0/chunks/build/feature/liveClasses.js +20 -0
  28. package/src/document/1.0.0/chunks/build/feature/schema.js +206 -0
  29. package/src/document/1.0.0/chunks/build/feature/seed.js +20 -0
  30. package/src/document/1.0.0/chunks/build/feature/system.js +20 -0
  31. package/src/document/1.0.0/chunks/build/feature/triggers.js +20 -0
  32. package/src/document/1.0.0/generateGithubReadme/build/chunks/_generateBadge.js +4 -0
  33. package/src/document/1.0.0/generateGithubReadme/build/chunks/_githubPackage.js +4 -0
  34. package/src/document/1.0.0/generateGithubReadme/build/chunks/adapters.js +40 -0
  35. package/src/document/1.0.0/generateGithubReadme/build/chunks/apis.js +39 -0
  36. package/src/document/1.0.0/generateGithubReadme/build/chunks/categories.js +32 -0
  37. package/src/document/1.0.0/generateGithubReadme/build/chunks/dependencies/build.js +29 -0
  38. package/src/document/1.0.0/generateGithubReadme/build/chunks/dependencies/index.js +40 -0
  39. package/src/document/1.0.0/generateGithubReadme/build/chunks/footer.js +33 -0
  40. package/src/document/1.0.0/generateGithubReadme/build/chunks/githubTags.js +42 -0
  41. package/src/document/1.0.0/generateGithubReadme/build/chunks/install.js +29 -0
  42. package/src/document/1.0.0/generateGithubReadme/build/chunks/packages.js +26 -0
  43. package/src/document/1.0.0/generateGithubReadme/build/chunks/registry.js +42 -0
  44. package/src/document/1.0.0/generateGithubReadme/build/chunks/usage.js +68 -0
  45. package/src/document/1.0.0/generateGithubReadme/build/index.js +224 -0
  46. package/src/document/1.0.0/generateGithubReadme/index.js +28 -0
  47. package/src/document/1.1.0/all/build/class/index.js +67 -0
  48. package/src/document/1.1.0/all/build/feature/index.js +135 -0
  49. package/src/document/1.1.0/all/index.js +17 -0
  50. package/src/document/1.1.0/all/write/class/index.js +25 -0
  51. package/src/document/1.1.0/all/write/feature/index.js +43 -0
  52. package/src/document/1.1.0/all/write/index.js +10 -0
  53. package/src/document/1.1.0/all/write/utils/chunk.js +19 -0
  54. package/src/document/1.1.0/chunks/build/class/class.js +20 -0
  55. package/src/document/1.1.0/chunks/build/class/functions.js +21 -0
  56. package/src/document/1.1.0/chunks/build/class/lib.js +21 -0
  57. package/src/document/1.1.0/chunks/build/class/seed.js +21 -0
  58. package/src/document/1.1.0/chunks/build/class/triggers.js +26 -0
  59. package/src/document/1.1.0/chunks/build/feature/afterInit.js +20 -0
  60. package/src/document/1.1.0/chunks/build/feature/beforeInit.js +20 -0
  61. package/src/document/1.1.0/chunks/build/feature/class.js +42 -0
  62. package/src/document/1.1.0/chunks/build/feature/config.js +20 -0
  63. package/src/document/1.1.0/chunks/build/feature/functions.js +20 -0
  64. package/src/document/1.1.0/chunks/build/feature/lib.js +21 -0
  65. package/src/document/1.1.0/chunks/build/feature/liveClasses.js +20 -0
  66. package/src/document/1.1.0/chunks/build/feature/schema.js +206 -0
  67. package/src/document/1.1.0/chunks/build/feature/seed.js +20 -0
  68. package/src/document/1.1.0/chunks/build/feature/system.js +20 -0
  69. package/src/document/1.1.0/chunks/build/feature/triggers.js +20 -0
  70. package/src/document/1.1.0/generateGithubReadme/build/chunks/_generateBadge.js +4 -0
  71. package/src/document/1.1.0/generateGithubReadme/build/chunks/_githubPackage.js +4 -0
  72. package/src/document/1.1.0/generateGithubReadme/build/chunks/adapters.js +40 -0
  73. package/src/document/1.1.0/generateGithubReadme/build/chunks/apis.js +39 -0
  74. package/src/document/1.1.0/generateGithubReadme/build/chunks/categories.js +32 -0
  75. package/src/document/1.1.0/generateGithubReadme/build/chunks/dependencies/build.js +29 -0
  76. package/src/document/1.1.0/generateGithubReadme/build/chunks/dependencies/index.js +40 -0
  77. package/src/document/1.1.0/generateGithubReadme/build/chunks/footer.js +33 -0
  78. package/src/document/1.1.0/generateGithubReadme/build/chunks/githubTags.js +42 -0
  79. package/src/document/1.1.0/generateGithubReadme/build/chunks/install.js +29 -0
  80. package/src/document/1.1.0/generateGithubReadme/build/chunks/packages.js +26 -0
  81. package/src/document/1.1.0/generateGithubReadme/build/chunks/registry.js +42 -0
  82. package/src/document/1.1.0/generateGithubReadme/build/chunks/usage.js +68 -0
  83. package/src/document/1.1.0/generateGithubReadme/build/index.js +224 -0
  84. package/src/document/1.1.0/generateGithubReadme/index.js +28 -0
  85. package/src/document/gateway/all/index.js +23 -0
  86. package/src/document/gateway/generateGithubReadme/index.js +24 -0
  87. package/src/domain/feature/factory/absoluteModuleSrcPath.js +10 -0
  88. package/src/domain/feature/factory/featurePath.js +41 -0
  89. package/src/domain/feature/factory/index.js +71 -0
  90. package/src/domain/feature/index.js +117 -0
  91. package/src/domain/feature/lib/instancesPathIdUniqueId.js +17 -0
  92. package/src/domain/featureInstance/factory/getLoaderWithPayload.js +7 -0
  93. package/src/domain/featureInstance/factory/index.js +65 -0
  94. package/src/domain/featureInstance/factory/instancesWithPath.js +12 -0
  95. package/src/domain/featureInstance/index.js +199 -0
  96. package/src/domain/featureLoader/base.js +100 -0
  97. package/src/domain/featureLoader/factory/getModule.js +40 -0
  98. package/src/domain/featureLoader/factory/index.js +9 -0
  99. package/src/domain/featureLoader/lib/importJSDefault.js +12 -0
  100. package/src/domain/featureLoader/lib/importJSONDefault.js +14 -0
  101. package/src/domain/featureLoader/lib/mergeClassFeatures.js +17 -0
  102. package/src/domain/featureLoader/lib/triggerItems.js +8 -0
  103. package/src/domain/featureLoader/v1.0.0.js +861 -0
  104. package/src/domain/featureLoader/v1.1.0.js +871 -0
  105. package/src/domain/lib/checkFileExists.js +6 -0
  106. package/src/domain/servable/index.js +19 -0
  107. package/src/domain/servable/parse/index.js +5 -0
  108. package/src/domain/servable/parse/utils/index.js +216 -0
  109. package/src/index.js +29 -0
  110. package/src/lib/adaptConfig/basic.js +85 -0
  111. package/src/lib/adaptFeaturePayload.js +18 -0
  112. package/src/lib/checkFileExists.js +6 -0
  113. package/src/lib/cleanFeatures.js +25 -0
  114. package/src/lib/directories.js +49 -0
  115. package/src/lib/directoryFilesRecursive.js +83 -0
  116. package/src/lib/directoryGlob.js +14 -0
  117. package/src/lib/ensureDirectoryExists.js +14 -0
  118. package/src/lib/featureApiVersion.js +30 -0
  119. package/src/lib/foldersInFolder.js +46 -0
  120. package/src/lib/getModuleDir.js +19 -0
  121. package/src/lib/importFileAsText.js +15 -0
  122. package/src/lib/importJSONAsync.js +16 -0
  123. package/src/lib/sanitizePath.js +4 -0
  124. package/src/manifest/access/accessChildInTreeWithRoute.js +49 -0
  125. package/src/manifest/access/index.js +58 -0
  126. package/src/manifest/data/1.0.0/class.json +233 -0
  127. package/src/manifest/data/1.0.0/enums.js +255 -0
  128. package/src/manifest/data/1.0.0/feature.json +503 -0
  129. package/src/manifest/data/1.0.0/schema.json +145 -0
  130. package/src/manifest/data/1.1.0/class.json +233 -0
  131. package/src/manifest/data/1.1.0/enums.js +267 -0
  132. package/src/manifest/data/1.1.0/feature.json +542 -0
  133. package/src/manifest/data/1.1.0/schema.json +145 -0
  134. package/src/manifest/extract/extractAst.js +36 -0
  135. package/src/manifest/extract/extractItem.js +70 -0
  136. package/src/manifest/extract/formatFile.js +22 -0
  137. package/src/manifest/extract/index.js +23 -0
  138. package/src/manifest/extract/route/extractFileWithVariants.js +38 -0
  139. package/src/manifest/extract/route/extractFiles.js +87 -0
  140. package/src/manifest/extract/route/imageToBase64.js +42 -0
  141. package/src/manifest/extract/route/index.js +102 -0
  142. package/src/manifest/extract/templateDataForId.js +44 -0
  143. package/src/schema/build/buildFeature/classStruct/extractFeaturesFeatures.js +29 -0
  144. package/src/schema/build/buildFeature/classStruct/featureInClassClassSchema.js +36 -0
  145. package/src/schema/build/buildFeature/classStruct/index.js +62 -0
  146. package/src/schema/build/buildFeature/classStruct/preserveMostRestricted.js +68 -0
  147. package/src/schema/build/buildFeature/extractClassesFeature.js +49 -0
  148. package/src/schema/build/buildFeature/index.js +119 -0
  149. package/src/schema/build/index.js +54 -0
  150. package/src/schema/build/lib/getFeaturesLiveClasses.js +14 -0
  151. package/src/schema/build/lib/updateFeaturesExcerpt.js +24 -0
  152. package/src/schema/index.js +57 -0
  153. package/src/schema/validate/handleFeature/computeVersions.js +48 -0
  154. package/src/schema/validate/handleFeature/index.js +5 -0
  155. package/src/schema/validate/index.js +52 -0
@@ -0,0 +1,871 @@
1
+ import BaseClass from './base.js'
2
+
3
+ import directories from '../../lib/directories.js'
4
+ import cleanFeatures from '../../lib/cleanFeatures.js'
5
+ import mergeClassFeatures from './lib/mergeClassFeatures.js'
6
+
7
+ import importJSONAsync from '../../lib/importJSONAsync.js'
8
+ import directoryGlob from '../../lib/directoryGlob.js'
9
+
10
+ import checkFileExists from '../../lib/checkFileExists.js'
11
+ import directoryFilesRecursive from '../../lib/directoryFilesRecursive.js'
12
+ import { FeatureEnum } from '../../manifest/data/1.0.0/enums.js'
13
+
14
+ import triggerItems from './lib/triggerItems.js'
15
+
16
+ export default class FeatureLoaderV1_1_0 extends BaseClass {
17
+
18
+ async getClass({ className }) {
19
+ const cacheKey = 'class'
20
+ if (this._valueInCache(cacheKey)) {
21
+ return this._valueInCache(cacheKey)
22
+ }
23
+
24
+ const path = `${this.path}/models/${className.toLowerCase()}target/class/index.js`
25
+ // const path = `${this.path}/models/${className.toLowerCase()}target/class/index.js`
26
+
27
+ 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))) {
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
+ }
45
+ }
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
50
+ }
51
+
52
+
53
+ async afterInit() {
54
+ const main = await this.main()
55
+ return main ? main.afterInit : null
56
+ }
57
+
58
+ async beforeInit() {
59
+ const main = await this.main()
60
+ return main ? main.beforeInit : null
61
+ }
62
+
63
+ async main() {
64
+
65
+ const path = `${this.path}/main.js`
66
+ if (!(await checkFileExists(path))) {
67
+ return null
68
+ }
69
+
70
+ const a = await this._importJSDefault({ path, })
71
+ return a
72
+ }
73
+
74
+ configFolder() {
75
+ return `${this.path}/config`
76
+ }
77
+
78
+
79
+ async configDataFiles() {
80
+ const cacheKey = 'configData'
81
+ if (this._valueInCache(cacheKey)) {
82
+ return this._valueInCache(cacheKey)
83
+ }
84
+
85
+ const path = this.configFolder()
86
+ const result = {}
87
+
88
+ const valuesPath = `${path}/entries.json`
89
+ if ((await checkFileExists(valuesPath))) {
90
+ result.entries = await importJSONAsync(valuesPath)
91
+ }
92
+
93
+ const conditionsPath = `${path}/conditions.json`
94
+ if ((await checkFileExists(conditionsPath))) {
95
+ result.conditions = await importJSONAsync(conditionsPath)
96
+ }
97
+
98
+ const groupsPath = `${path}/groups.json`
99
+ if ((await checkFileExists(groupsPath))) {
100
+ result.groups = await importJSONAsync(groupsPath)
101
+ }
102
+
103
+ return result
104
+ }
105
+
106
+
107
+ seedFolder() {
108
+ return `${this.path}/seed`
109
+ }
110
+
111
+ async seedMode() {
112
+ const cacheKey = 'seedMode'
113
+ if (this._valueInCache(cacheKey)) {
114
+ return this._valueInCache(cacheKey)
115
+ }
116
+
117
+ const seedFolder = this.seedFolder()
118
+ let _path = `${seedFolder}/index.js`
119
+ if (await checkFileExists(_path)) {
120
+ return 'manual'
121
+ }
122
+
123
+ //Auto not handled yet for features
124
+ // _path = `${seedFolder}/transformer.js`
125
+ // if (await checkFileExists(_path)) {
126
+ // return 'auto'
127
+ // }
128
+
129
+ return 'none'
130
+ }
131
+
132
+ async seedManual() {
133
+ const cacheKey = 'seedManual'
134
+ if (this._valueInCache(cacheKey)) {
135
+ return this._valueInCache(cacheKey)
136
+ }
137
+ let _path = `${this.path}/seed/index.js`
138
+ if (!(await checkFileExists(_path))) {
139
+ return null
140
+ }
141
+
142
+ const data = (await import(_path)).default
143
+ //this.cache[cacheKey] = data
144
+ return data
145
+ }
146
+
147
+ async seedMetadata() {
148
+ const cacheKey = 'seedMetadata'
149
+ if (this._valueInCache(cacheKey)) {
150
+ return this._valueInCache(cacheKey)
151
+ }
152
+
153
+ const path = `${this.seedFolder()}/metadata.json`
154
+ if (!(await checkFileExists(path))) {
155
+ return null
156
+ }
157
+
158
+ const data = await importJSONAsync(path)
159
+ //this.cache[cacheKey] = data
160
+ return data
161
+ }
162
+
163
+
164
+
165
+
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+
176
+
177
+
178
+ async triggers() {
179
+ const cacheKey = 'triggers'
180
+ if (this._valueInCache(cacheKey)) {
181
+ return this._valueInCache(cacheKey)
182
+ }
183
+
184
+ const prefix = `${this.path}/triggers`
185
+
186
+ const data = {}
187
+ for (var i = 0; i < triggerItems.length; i++) {
188
+ const item = triggerItems[i]
189
+ const path = `${prefix}/${item}.js`
190
+ if (!(await checkFileExists(path))) {
191
+ continue
192
+ }
193
+
194
+ const itemData = (await import(path))
195
+ if (!itemData || !itemData.default) {
196
+ continue
197
+ }
198
+
199
+ data[item] = itemData.default
200
+ }
201
+
202
+ if (Object.keys(data).length > 0) {
203
+ return data
204
+ }
205
+
206
+ return this.triggersMerged()
207
+ }
208
+
209
+ async triggersMerged() {
210
+ const cacheKey = 'triggers'
211
+ if (this._valueInCache(cacheKey)) {
212
+ return this._valueInCache(cacheKey)
213
+ }
214
+
215
+ const path = `${this.path}/triggers/index.js`
216
+ if (!(await checkFileExists(path))) {
217
+ return null
218
+ }
219
+
220
+ const data = (await import(path))
221
+ // this.cache[cacheKey] = data
222
+ return data
223
+ }
224
+
225
+ async triggersMetadata() {
226
+ const cacheKey = 'triggersMetadata'
227
+ if (this._valueInCache(cacheKey)) {
228
+ return this._valueInCache(cacheKey)
229
+ }
230
+
231
+ const path = `${this.path}/triggers/metadata.json`
232
+ if (!(await checkFileExists(path))) {
233
+ return null
234
+ }
235
+
236
+ const data = await importJSONAsync(path)
237
+ this.cache[cacheKey] = data
238
+ return data
239
+ }
240
+
241
+
242
+
243
+
244
+ async classesSchemas(props) {
245
+ // if (this.valueInCache('classes')) {
246
+ // return this.valueInCache('classes')
247
+ // }
248
+
249
+ const schema = await this.schemaRaw(props)
250
+ if (schema && schema.managed) {
251
+ return schema.managed.classes
252
+ }
253
+
254
+ const schemaPath = await this._schemaPath()
255
+ let path = `${schemaPath}/classes.js`
256
+
257
+ if ((await checkFileExists(path))) {
258
+ const classes = await (await import(path)).default({ feature: this.featureInstance })
259
+ // this.cache['classes'] = classes
260
+ return classes
261
+ }
262
+
263
+ path = `${schemaPath}/classes.json`
264
+ if (!(await checkFileExists(path))) {
265
+ return []
266
+ }
267
+
268
+ const classes = await importJSONAsync(path)
269
+ // this.cache['classes'] = classes
270
+ return classes
271
+ }
272
+
273
+ async schemaFields(props) {
274
+ // const cacheKey = 'schemaFields'
275
+ // if (this.valueInCache(cacheKey)) {
276
+ // return this.valueInCache(cacheKey)
277
+ // }
278
+ const schema = await this.schemaRaw(props)
279
+ if (schema && schema.target) {
280
+ return schema.target.fields
281
+ }
282
+
283
+ const schemaPath = await this._schemaPath()
284
+ const path = `${schemaPath}/fields.json`
285
+ if (!(await checkFileExists(path))) {
286
+ return null
287
+ }
288
+
289
+ return this._importJSONDefault({ path, })
290
+ }
291
+
292
+ async schemaIndexes(props) {
293
+ // const cacheKey = 'schemaIndexes'
294
+ // if (this.valueInCache(cacheKey)) {
295
+ // return this.valueInCache(cacheKey)
296
+ // }
297
+ const schema = await this.schemaRaw(props)
298
+ if (schema && schema.target) {
299
+ return schema.target.indexes
300
+ }
301
+
302
+ const schemaPath = await this._schemaPath()
303
+ const path = `${schemaPath}/indexes.json`
304
+
305
+ if (!(await checkFileExists(path))) {
306
+ return null
307
+ }
308
+
309
+ return this._importJSONDefault({ path, })
310
+ }
311
+
312
+ async schemaRaw(props = {}) {
313
+ const { ad } = props
314
+ const a = await this._accessManifestItem({
315
+ item: FeatureEnum.Schema,
316
+ })
317
+ // const cacheKey = 'schemaIndexes'
318
+ // if (this.valueInCache(cacheKey)) {
319
+ // return this.valueInCache(cacheKey)
320
+ // }
321
+
322
+ const schemaPath = await this._schemaPath()
323
+
324
+ //#TODO: A dynamic schema needs features to be instantiated per class as to avoid class defintion collusions and edge case.
325
+ // let path = `${schemaPath}/index.js`
326
+
327
+ // if ((await checkFileExists(path))) {
328
+ // let data = (await import(path)).default
329
+ // //#TODO: don't use up feature params
330
+ // data = await data({ ...props, params: this.featureInstance.params })
331
+ // return data
332
+ // }
333
+
334
+ let path = `${schemaPath}/index.json`
335
+
336
+ if (!(await checkFileExists(path))) {
337
+ return null
338
+ }
339
+
340
+ const b = await this._importJSONDefault({ path, })
341
+ return b
342
+ }
343
+
344
+ async schemaClassLevelPermissions(props) {
345
+ // const cacheKey = 'schemaClassLevelPermissions'
346
+ // if (this.valueInCache(cacheKey)) {
347
+ // return this.valueInCache(cacheKey)
348
+ // }
349
+
350
+ const schema = await this.schemaRaw(props)
351
+ if (schema && schema.target) {
352
+ return schema.target.classLevelPermissions
353
+ }
354
+
355
+ const schemaPath = await this._schemaPath()
356
+ const path = `${schemaPath}/classlevelpermissions.json`
357
+
358
+ if (!(await checkFileExists(path))) {
359
+ return null
360
+ }
361
+
362
+ return this._importJSONDefault({ path, })
363
+ }
364
+
365
+ async _schemaPath() {
366
+ //let version = this.currentFeatureVersion ? this.currentFeatureVersion : this.featureInstanceVersion
367
+ let version = this.featureInstance.version
368
+ let versions = await this.schemaVersions()
369
+
370
+ if (!version) {
371
+ return `${this.path}/schema`
372
+ }
373
+
374
+ if (!versions
375
+ || !versions.length) {
376
+ return `${this.path}/schema`
377
+ }
378
+
379
+ if (versions
380
+ && versions.length
381
+ && !versions.includes(version)) {
382
+ return `${this.path}/schema`
383
+ }
384
+
385
+ if (versions
386
+ && versions.length
387
+ && version === 'latest') {
388
+ version = versions[versions.length - 1] //#TODO: sort by semver
389
+ }
390
+
391
+ const path = `${this.path}/schema/${version}`
392
+ return path
393
+ }
394
+
395
+
396
+ async schemaVersions() {
397
+ const cacheKey = '_schemaVersions'
398
+ if (this._valueInCache(cacheKey)) {
399
+ return this._valueInCache(cacheKey)
400
+ }
401
+ const items = await directories({ path: `${this.path}/schema` })
402
+ if (!items || !items.length) {
403
+ return null
404
+ }
405
+ let data = items.map(i => i.name)
406
+ data = data.sort()
407
+ this.cache[cacheKey] = data
408
+ return data
409
+ }
410
+
411
+ async schemaVersionOf({ version, subPath }) {
412
+ const cacheKey = `_schemaVersionOf${subPath}`
413
+ if (this._valueInCache(cacheKey)) {
414
+ return this._valueInCache(cacheKey)
415
+ }
416
+
417
+ const versions = await this.schemaVersions()
418
+ if (!versions || !versions.includes(version)) {
419
+ return null
420
+ }
421
+
422
+ const path = `${this.path}/schema/${version}/${subPath}`
423
+ if (!(await checkFileExists(path))) {
424
+ return null
425
+ }
426
+
427
+ const data = await import(path)
428
+ this.cache[cacheKey] = data
429
+ return data
430
+ }
431
+
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()}target/class/features.js`
452
+
453
+ if ((await checkFileExists(path))) {
454
+
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
+
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
+
469
+
470
+ async ownFeatures() {
471
+ const cacheKey = 'ownFeatures'
472
+ if (this._valueInCache(cacheKey)) {
473
+ return this._valueInCache(cacheKey)
474
+ }
475
+
476
+ let path = `${this.path}target/class/features.js`
477
+ if (!(await checkFileExists(path))) {
478
+ return null
479
+ }
480
+
481
+ const data = (await import(path)).default
482
+
483
+ //this.cache[cacheKey] = data
484
+ return data
485
+ }
486
+
487
+ async ownFeaturesClass() {
488
+ const cacheKey = 'ownFeaturesClass'
489
+ if (this._valueInCache(cacheKey)) {
490
+ return this._valueInCache(cacheKey)
491
+ }
492
+
493
+ const path = `${this.path}target/class/index.js`
494
+ if (!(await checkFileExists(path))) {
495
+ return null
496
+ }
497
+ // const _data = (await import(path))
498
+ return this._importJSDefault({ path, })
499
+ }
500
+
501
+ async liveClasses() {
502
+ const cacheKey = 'liveclasses'
503
+ if (this._valueInCache(cacheKey)) {
504
+ return this._valueInCache(cacheKey)
505
+ }
506
+
507
+ const path = `${this.path}/liveclasses.js`
508
+ if (!(await checkFileExists(path))) {
509
+ return null
510
+ }
511
+
512
+ return this._importJSDefault({ path, })
513
+ }
514
+
515
+ async systemDockerCompose() {
516
+ const cacheKey = 'systemDockerCompose'
517
+ if (this._valueInCache(cacheKey)) {
518
+ return this._valueInCache(cacheKey)
519
+ }
520
+
521
+ const path = `${this.path}/system/docker/docker-compose.yaml`
522
+ if (!(await checkFileExists(path))) {
523
+ return null
524
+ }
525
+
526
+ const data = (await import(path))
527
+ //this.cache[cacheKey] = data
528
+ return data
529
+ }
530
+
531
+ async systemDockerComposeExists() {
532
+ const path = this.systemDockerComposePath()
533
+ return checkFileExists(path)
534
+ }
535
+
536
+ systemDockerComposePath() {
537
+ return `${this.systemDockerComposeDirPath()}/docker-compose.yaml`
538
+ }
539
+
540
+ systemDockerDataPath() {
541
+ return `${this.systemDockerComposeDirPath()}/data`
542
+ }
543
+
544
+ systemDockerComposeDirPath() {
545
+ return `${this.path}/system/docker`
546
+ }
547
+
548
+ configDirPath_obs() {
549
+ return `${this.path}/config`
550
+ }
551
+
552
+ async configData_obs() {
553
+ // const cacheKey = 'schemaClassLevelPermissions'
554
+ // if (this.valueInCache(cacheKey)) {
555
+ // return this.valueInCache(cacheKey)
556
+ // }
557
+
558
+ const schemaPath = await this._schemaPath()
559
+ const path = `${this.configDirPath_obs()}/index.json`
560
+
561
+ if (!(await checkFileExists(path))) {
562
+ return null
563
+ }
564
+
565
+ return this._importJSONDefault({ path, })
566
+ }
567
+
568
+ async systemDockerPayloadAdapter() {
569
+ const cacheKey = 'systemDockerPayloadAdapter'
570
+ if (this._valueInCache(cacheKey)) {
571
+ return this._valueInCache(cacheKey)
572
+ }
573
+
574
+ const path = `${this.path}/system/docker/adaptpayload.js`
575
+ if (!(await checkFileExists(path))) {
576
+ return null
577
+ }
578
+
579
+ return this._importJSDefault({ path, })
580
+ }
581
+
582
+
583
+
584
+ async functions() {
585
+ const cacheKey = 'functions'
586
+ if (this._valueInCache(cacheKey)) {
587
+ return this._valueInCache(cacheKey)
588
+ }
589
+
590
+ let path = `${this.path}/cloudCode`
591
+ if (!(await checkFileExists(path))) {
592
+ path = `${this.path}/functions`
593
+ if (!(await checkFileExists(path))) {
594
+ path = `${this.path}/cloudcode`
595
+ if (!(await checkFileExists(path))) {
596
+ return null
597
+ }
598
+ }
599
+ }
600
+
601
+ const data = (await directoryFilesRecursive({ path }))
602
+ //this.cache[cacheKey] = data
603
+ return data
604
+ }
605
+
606
+
607
+ async services() {
608
+ let path = `${this.path}/services`
609
+ if (!(await checkFileExists(path))) {
610
+ return null
611
+ }
612
+
613
+ const data = (await directoryFilesRecursive({ path }))
614
+ //this.cache[cacheKey] = data
615
+ return data
616
+ }
617
+
618
+ async routes() {
619
+ let path = `${this.path}/routes`
620
+ if (!(await checkFileExists(path))) {
621
+ return null
622
+ }
623
+
624
+ const data = (await directoryGlob({ path: `${path}/**/*.js` }))
625
+ return data
626
+ }
627
+
628
+ async targetRoutes() {
629
+ let path = `${this.path}/target/routes`
630
+ if (!(await checkFileExists(path))) {
631
+ return null
632
+ }
633
+
634
+ const data = (await directoryGlob({ path: `${path}/**/*.js` }))
635
+ return data
636
+ }
637
+
638
+
639
+ async jobFiles() {
640
+ const cacheKey = 'jobFiles'
641
+ if (this._valueInCache(cacheKey)) {
642
+ return this._valueInCache(cacheKey)
643
+ }
644
+
645
+ const path = `${this.path}/jobs_`
646
+ if (!(await checkFileExists(path))) {
647
+ return null
648
+ }
649
+
650
+ const data = (await directoryFilesRecursive({ path }))
651
+ //this.cache[cacheKey] = data
652
+ return data
653
+ }
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
+ }
871
+