@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,12 @@
1
+
2
+ export default ({ className, instances, path }) => {
3
+ for (var i in instances) {
4
+ const instance = instances[i]
5
+ if ((instance.className === className)
6
+ && (instance.path === path)) {
7
+ return instance
8
+ }
9
+ }
10
+
11
+ return null
12
+ }
@@ -0,0 +1,199 @@
1
+ import instancesPathIdUniqueId from '../feature/lib/instancesPathIdUniqueId.js'
2
+ import semver from 'semver'
3
+ const DEFAULT_VERSION = "1.0.0"
4
+ const DEFAULT_MIMIUM_COMAPATIBLE_VERSION = "0.0.0"
5
+
6
+ export default class FeatureInstance {
7
+ _className = null
8
+ _params = {}
9
+ _instancesPathId = []
10
+ _instancesPathIdString = null
11
+ _loader = null
12
+ _version = DEFAULT_VERSION
13
+ _minimumCompatibleVersion = DEFAULT_MIMIUM_COMAPATIBLE_VERSION
14
+ _loadState = 0
15
+ _module = {}
16
+ _path = null
17
+ _id = null
18
+ _featurePayload = null
19
+ _schema = {
20
+ classes: {
21
+ managed: [],
22
+ all: []
23
+ }
24
+ }
25
+
26
+ constructor(props) {
27
+ const {
28
+ className,
29
+ instancesPathId,
30
+ featurePayload,
31
+ loader
32
+ } = props
33
+ this._loader = loader
34
+ this._loader._featureInstance = this
35
+ this._className = className
36
+ this._params = { ...featurePayload.params }
37
+ this._path = featurePayload.path
38
+ this._id = featurePayload.id
39
+ this._featurePayload = { ...featurePayload }
40
+ this._instancesPathId = [...instancesPathId]
41
+ this._instancesPathIdString = instancesPathIdUniqueId({ instancesPathId, currentFeatureId: this._id })
42
+ console.log(this._instancesPathIdString)
43
+ }
44
+
45
+ async load({ servableConfig } = {}) {
46
+ switch (this.loadState) {
47
+ case 1: {
48
+ return
49
+ }
50
+ default: break
51
+ }
52
+
53
+ this.loadState = 1
54
+ await this.loader.loadExtraction({ servableConfig })
55
+
56
+ try {
57
+ const module = await this.loader.getModule()
58
+ this.module = module
59
+ this.loadState = 2
60
+ } catch (e) {
61
+ this.loadState = 3
62
+ }
63
+
64
+ if (!servableConfig || !servableConfig.versions) {
65
+ return
66
+ }
67
+
68
+ if (!servableConfig.versions[this.id]) {
69
+ return
70
+ }
71
+
72
+ this.version = servableConfig.versions[this.id]
73
+ }
74
+
75
+
76
+ // #region getters and setters
77
+
78
+ get className() {
79
+ return this._className
80
+ }
81
+ set className(value) {
82
+ this._className = value
83
+ }
84
+
85
+ get params() {
86
+ return this._params
87
+ }
88
+ set params(value) {
89
+ this._params = value
90
+ }
91
+
92
+ get featurePayload() {
93
+ return this._featurePayload
94
+ }
95
+ set featurePayload(value) {
96
+ this._featurePayload = value
97
+ }
98
+ // #endregion
99
+
100
+
101
+ toString() {
102
+ return `FeatureInstance: ${this.instancesPathIdString} (${this.path})`
103
+ }
104
+
105
+
106
+ get instancesPathIdString() {
107
+ return this._instancesPathIdString
108
+ }
109
+ set instancesPathIdString(value) {
110
+ this._instancesPathIdString = value
111
+ }
112
+
113
+ get instancesPathId() {
114
+ return this._instancesPathId
115
+ }
116
+ set instancesPathId(value) {
117
+ this._instancesPathId = value
118
+ }
119
+
120
+
121
+ get id() {
122
+ return this._id
123
+ }
124
+ set id(value) {
125
+ this._id = value
126
+ }
127
+
128
+ get path() {
129
+ return this._path
130
+ }
131
+ set path(value) {
132
+ this._path = value
133
+ }
134
+
135
+ get loadState() {
136
+ return this._loadState
137
+ }
138
+ set loadState(value) {
139
+ this._loadState = value
140
+ }
141
+
142
+ get module() {
143
+ return this._module
144
+ }
145
+
146
+ set module(value) {
147
+ this._module = value
148
+ if (this._module) {
149
+ this.version = this._module.version
150
+ this.minimumCompatibleVersion = this._module.minimumCompatibleVersion
151
+ }
152
+ }
153
+
154
+ get version() {
155
+ return this._version
156
+ }
157
+
158
+ set version(value) {
159
+ if (!value || !semver.valid(value)) {
160
+ return
161
+ }
162
+ this._version = semver.clean(value)
163
+ }
164
+
165
+ get minimumCompatibleVersion() {
166
+ return this._minimumCompatibleVersion
167
+ }
168
+
169
+ set minimumCompatibleVersion(value) {
170
+ if (!value || !semver.valid(value)) {
171
+ return
172
+ }
173
+ this._minimumCompatibleVersion = semver.clean(value)
174
+ }
175
+
176
+
177
+
178
+ get loader() {
179
+ return this._loader
180
+ }
181
+
182
+ set loader(value) {
183
+ this._loader = value
184
+ this._loader.feature = this
185
+ }
186
+
187
+ get schema() {
188
+ return this._schema
189
+ }
190
+ set schema(value) {
191
+ this._schema = value
192
+ }
193
+
194
+ // #region loader
195
+ async schemaRaw({ ad } = {}) {
196
+ return this.loader.schemaRaw({ ad: 43 })
197
+ }
198
+ // #endregion
199
+ }
@@ -0,0 +1,100 @@
1
+ import extract from '../../manifest/extract/index.js'
2
+ import { DataTemplateType, FeatureEnum } from '../../manifest/data/1.0.0/enums.js'
3
+ import sanitizePath from '../../lib/sanitizePath.js'
4
+ import importJSDefault from './lib/importJSDefault.js'
5
+ import importJSONDefault from './lib/importJSONDefault.js'
6
+ import access from '../../manifest/access/index.js'
7
+ import fs from 'fs'
8
+
9
+
10
+ export default class FeatureLoader {
11
+ _cache = {}
12
+ _extraClasses = {}
13
+ _extraction = null
14
+
15
+ _path = null
16
+ _featureInstance = null
17
+
18
+ constructor(props) {
19
+ const { path, extraClasses } = props
20
+ this._path = path
21
+ this._extraClasses = extraClasses
22
+ }
23
+
24
+ get path() {
25
+ return this._path
26
+ }
27
+ set path(value) {
28
+ this._path = value
29
+ }
30
+
31
+ get cache() { return this._cache }
32
+ set cache(value) { this._cache = value }
33
+
34
+ get extraction() { return this._extraction }
35
+ set extraction(value) { this._extraction = value }
36
+
37
+
38
+ get featureInstance() { return this._featureInstance }
39
+ set featureInstance(value) { this._featureInstance = value }
40
+
41
+
42
+
43
+ async loadExtraction({ servableConfig } = {}) {
44
+ try {
45
+ this.extraction = await extract({
46
+ path: `${sanitizePath(this.path)}`,
47
+ dataTemplateType: DataTemplateType.Feature
48
+ })
49
+ // const e = JSON.stringify(this.extraction)
50
+ // console.log(this.extraction)
51
+ // console.log(e.length)
52
+ // const a = JSON.parse(e)
53
+ // console.log(a)
54
+
55
+ // const schemaAa = await access({
56
+ // item: FeatureEnum.Schema,
57
+ // extraction: this.extraction,
58
+ // })
59
+ // const schemaB = await access({
60
+ // item: FeatureEnum.Schema,
61
+ // extraction: a,
62
+ // })
63
+ // console.log(schemaAa, schemaB)
64
+ } catch (e) {
65
+ console.info(e)
66
+ }
67
+ }
68
+
69
+ async _accessManifestItem({ item }) {
70
+ return access({
71
+ item,
72
+ extraction: this.extraction,
73
+ })
74
+ }
75
+
76
+ async isValid() {
77
+ const _stat = await fs.promises.stat(this.path)
78
+ if (!_stat || !_stat.isDirectory()) {
79
+ return false
80
+ }
81
+ return true
82
+ }
83
+
84
+ async getModule() {
85
+ const mo = await this._accessManifestItem({
86
+ item: FeatureEnum.Index,
87
+ })
88
+ return mo.data.module
89
+ }
90
+
91
+ async _importJSDefault({ path, cacheKey }) {
92
+ return importJSDefault({ path, cache: this._cache, cacheKey })
93
+ }
94
+
95
+ async _importJSONDefault({ path, cacheKey }) {
96
+ return importJSONDefault({ path, cache: this._cache, cacheKey })
97
+ }
98
+
99
+ _valueInCache(value) { return this.cache[value] }
100
+ }
@@ -0,0 +1,40 @@
1
+ import importJSONAsync from '../../../lib/importJSONAsync.js'
2
+ import checkFileExists from '../../../lib/checkFileExists.js'
3
+ import v1_0_0 from '../v1.0.0.js'
4
+ import v1_1_0 from '../v1.1.0.js'
5
+
6
+ const DEFAULT_LOADER = v1_0_0
7
+
8
+ export default async ({ path, version }) => {
9
+ if (version) {
10
+ return loaderForVersion(version)
11
+ }
12
+
13
+ if (!path) {
14
+ return null
15
+ }
16
+
17
+ let modulePath = `${path}/manifest.json`
18
+ if (!(await checkFileExists(modulePath))) {
19
+ modulePath = `${path}/index.json`
20
+ if (!(await checkFileExists(modulePath))) {
21
+ modulePath = `${path}/module.json`
22
+ if (!(await checkFileExists(modulePath))) {
23
+ return DEFAULT_LOADER
24
+ }
25
+ }
26
+ }
27
+
28
+ const module = await importJSONAsync(modulePath)
29
+ const { apiVersion } = module
30
+ return loaderForVersion(apiVersion)
31
+ }
32
+
33
+ const loaderForVersion = (version) => {
34
+ switch (version) {
35
+ case '1.1.0': {
36
+ return v1_1_0
37
+ }
38
+ default: return DEFAULT_LOADER
39
+ }
40
+ }
@@ -0,0 +1,9 @@
1
+ import getModule from "./getModule.js"
2
+
3
+ export const getByPathAndVersion = async ({ path, version }) => {
4
+ const module = await getModule({ path, version })
5
+ if (!module) {
6
+ return null
7
+ }
8
+ return new module({ path, version })
9
+ }
@@ -0,0 +1,12 @@
1
+
2
+
3
+ export default async ({ path, cache, cacheKey }) => {
4
+ try {
5
+ // console.log("[Servable]", `importJSDefault for path ${path}`)
6
+ return (await import(path)).default
7
+ // console.log("[Servable]", `importJSDefault for path ${path} successful`)
8
+ } catch (e) {
9
+ console.error("[Servable]", `importJSDefault for path ${path}:`, e)
10
+ }
11
+ return null
12
+ }
@@ -0,0 +1,14 @@
1
+ import importJSONAsync from "../../../lib/importJSONAsync.js"
2
+
3
+
4
+ export default async ({ path, cache, cacheKey }) => {
5
+ try {
6
+ // console.log("[Servable]", `importJSONDefault for path ${path}`)
7
+ const data = await importJSONAsync(path)
8
+ // console.log("[Servable]", `importJSONDefault for path ${path} successful`)
9
+ return data
10
+ } catch (e) {
11
+ console.error("[Servable]", `importJSONDefault for path ${path}:`, e)
12
+ }
13
+ return null
14
+ }
@@ -0,0 +1,17 @@
1
+ import cleanFeatures from "../../../lib/cleanFeatures.js"
2
+
3
+
4
+ export default ({ items = [], _class, withFeaturesFeatures }) => {
5
+ let classFeatures = _class.features ? _class.features : []
6
+ if (!withFeaturesFeatures) {
7
+ return cleanFeatures([...items, ...classFeatures])
8
+ }
9
+
10
+ return cleanFeatures([...items])
11
+
12
+ // let inheritedFeatures = _class.inheritedFeatures ? _class.inheritedFeatures : []
13
+ // return cleanFeatures([
14
+ // ...classFeatures,
15
+ // ...inheritedFeatures
16
+ // ])
17
+ }
@@ -0,0 +1,8 @@
1
+ export default [
2
+ 'beforefind',
3
+ 'afterfind',
4
+ 'beforedelete',
5
+ 'afterdelete',
6
+ 'beforesave',
7
+ 'aftersave'
8
+ ]