velocious 1.0.486 → 1.0.487
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/README.md +1 -0
- package/build/configuration-types.js +19 -1
- package/build/configuration.js +25 -2
- package/build/environment-handlers/base.js +9 -0
- package/build/environment-handlers/node.js +105 -19
- package/build/packages/velocious-package.js +115 -0
- package/build/src/configuration-types.d.ts +57 -2
- package/build/src/configuration-types.d.ts.map +1 -1
- package/build/src/configuration-types.js +18 -2
- package/build/src/configuration.d.ts +9 -1
- package/build/src/configuration.d.ts.map +1 -1
- package/build/src/configuration.js +21 -3
- package/build/src/environment-handlers/base.d.ts +6 -0
- package/build/src/environment-handlers/base.d.ts.map +1 -1
- package/build/src/environment-handlers/base.js +9 -1
- package/build/src/environment-handlers/node.d.ts +18 -0
- package/build/src/environment-handlers/node.d.ts.map +1 -1
- package/build/src/environment-handlers/node.js +94 -19
- package/build/src/packages/velocious-package.d.ts +69 -0
- package/build/src/packages/velocious-package.d.ts.map +1 -0
- package/build/src/packages/velocious-package.js +101 -0
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/configuration-types.js +19 -1
- package/src/configuration.js +25 -2
- package/src/environment-handlers/base.js +9 -0
- package/src/environment-handlers/node.js +105 -19
- package/src/packages/velocious-package.js +115 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
|
|
3
|
+
import restArgsError from "../utils/rest-args-error.js"
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A Velocious package (engine): an external npm package that contributes data
|
|
7
|
+
* models, frontend-model resources and migrations to a consuming app. The app
|
|
8
|
+
* lists packages in `Configuration({packages: [...]})`; the framework then loads
|
|
9
|
+
* the package's `src/models`, discovers its `src/resources`, runs its
|
|
10
|
+
* `src/database/migrations`, and generates its frontend models into the app.
|
|
11
|
+
*/
|
|
12
|
+
export default class VelociousPackage {
|
|
13
|
+
/**
|
|
14
|
+
* Wraps a plain descriptor as a VelociousPackage (or returns it unchanged when
|
|
15
|
+
* it already is one), so packages can be listed without importing this class.
|
|
16
|
+
* @param {VelociousPackage | import("../configuration-types.js").VelociousPackageDescriptor} descriptor - Package or plain descriptor.
|
|
17
|
+
* @returns {VelociousPackage} - The package instance.
|
|
18
|
+
*/
|
|
19
|
+
static from(descriptor) {
|
|
20
|
+
if (descriptor instanceof VelociousPackage) {
|
|
21
|
+
return descriptor
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return new VelociousPackage(descriptor)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Derives the containing directory of a module url without Node's `path`/`url`
|
|
29
|
+
* modules, so this class stays safe to import in browser/Expo bundles.
|
|
30
|
+
* @param {string} url - A module url (usually `import.meta.url`).
|
|
31
|
+
* @returns {string} - The directory path that contains the module.
|
|
32
|
+
*/
|
|
33
|
+
static _directoryFromUrl(url) {
|
|
34
|
+
const directoryUrl = new URL(".", url)
|
|
35
|
+
|
|
36
|
+
return decodeURIComponent(directoryUrl.pathname).replace(/\/$/, "")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Runs constructor.
|
|
41
|
+
* @param {import("../configuration-types.js").VelociousPackageDescriptor} args - Package descriptor.
|
|
42
|
+
*/
|
|
43
|
+
constructor({name, url, path, modelsPath, resourcesPath, migrationsPath, ...restArgs}) {
|
|
44
|
+
restArgsError(restArgs)
|
|
45
|
+
|
|
46
|
+
if (!name) {
|
|
47
|
+
throw new Error("A velocious package requires a name.")
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!path && !url) {
|
|
51
|
+
throw new Error(`Velocious package "${name}" requires a "path" or a "url" (usually import.meta.url).`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
this._name = name
|
|
55
|
+
this._path = path || VelociousPackage._directoryFromUrl(/** @type {string} */ (url))
|
|
56
|
+
this._modelsPath = modelsPath
|
|
57
|
+
this._resourcesPath = resourcesPath
|
|
58
|
+
this._migrationsPath = migrationsPath
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Runs get name.
|
|
63
|
+
* @returns {string} - The package name.
|
|
64
|
+
*/
|
|
65
|
+
getName() {
|
|
66
|
+
return this._name
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Runs get path.
|
|
71
|
+
* @returns {string} - The package root directory (the one that contains `src`).
|
|
72
|
+
*/
|
|
73
|
+
getPath() {
|
|
74
|
+
return this._path
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Runs get models path.
|
|
79
|
+
* @returns {string} - The package's models directory.
|
|
80
|
+
*/
|
|
81
|
+
getModelsPath() {
|
|
82
|
+
return this._modelsPath || `${this._path}/src/models`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Runs get resources path.
|
|
87
|
+
* @returns {string} - The package's frontend-model resources directory.
|
|
88
|
+
*/
|
|
89
|
+
getResourcesPath() {
|
|
90
|
+
return this._resourcesPath || `${this._path}/src/resources`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Runs get migrations path.
|
|
95
|
+
* @returns {string} - The package's migrations directory.
|
|
96
|
+
*/
|
|
97
|
+
getMigrationsPath() {
|
|
98
|
+
return this._migrationsPath || `${this._path}/src/database/migrations`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Derives the internal backend-project entry the framework appends so the
|
|
103
|
+
* existing resource-discovery + frontend-model generation machinery picks up
|
|
104
|
+
* this package. Generated frontend models are written to the app's output.
|
|
105
|
+
* @param {{frontendModelsOutputPath: string | undefined}} args - The app's frontend-models output path.
|
|
106
|
+
* @returns {import("../configuration-types.js").BackendProjectConfiguration} - The derived backend project.
|
|
107
|
+
*/
|
|
108
|
+
toBackendProjectConfiguration({frontendModelsOutputPath}) {
|
|
109
|
+
return {
|
|
110
|
+
frontendModelsOutputPath,
|
|
111
|
+
path: this.getPath(),
|
|
112
|
+
resourcesPath: this.getResourcesPath()
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|