@webda/compiler 4.0.0-beta.3
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/LICENSE +166 -0
- package/README.md +125 -0
- package/lib/compiler.d.ts +88 -0
- package/lib/compiler.d.ts.map +1 -0
- package/lib/compiler.js +230 -0
- package/lib/compiler.js.map +1 -0
- package/lib/configuration.d.ts +35 -0
- package/lib/configuration.d.ts.map +1 -0
- package/lib/configuration.js +170 -0
- package/lib/configuration.js.map +1 -0
- package/lib/definition.d.ts +787 -0
- package/lib/definition.d.ts.map +1 -0
- package/lib/definition.js +189 -0
- package/lib/definition.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -0
- package/lib/module.d.ts +36 -0
- package/lib/module.d.ts.map +1 -0
- package/lib/module.js +119 -0
- package/lib/module.js.map +1 -0
- package/lib/morpher/capabilities.d.ts +35 -0
- package/lib/morpher/capabilities.d.ts.map +1 -0
- package/lib/morpher/capabilities.js +66 -0
- package/lib/morpher/capabilities.js.map +1 -0
- package/lib/morpher/imports.d.ts +10 -0
- package/lib/morpher/imports.d.ts.map +1 -0
- package/lib/morpher/imports.js +97 -0
- package/lib/morpher/imports.js.map +1 -0
- package/lib/morpher/morpher.d.ts +34 -0
- package/lib/morpher/morpher.d.ts.map +1 -0
- package/lib/morpher/morpher.js +87 -0
- package/lib/morpher/morpher.js.map +1 -0
- package/lib/operations.d.ts +29 -0
- package/lib/operations.d.ts.map +1 -0
- package/lib/operations.js +197 -0
- package/lib/operations.js.map +1 -0
- package/lib/schema-backend.d.ts +55 -0
- package/lib/schema-backend.d.ts.map +1 -0
- package/lib/schema-backend.js +86 -0
- package/lib/schema-backend.js.map +1 -0
- package/lib/session-types.d.ts +14 -0
- package/lib/session-types.d.ts.map +1 -0
- package/lib/session-types.js +79 -0
- package/lib/session-types.js.map +1 -0
- package/lib/shell-build-dispatch.d.ts +54 -0
- package/lib/shell-build-dispatch.d.ts.map +1 -0
- package/lib/shell-build-dispatch.js +77 -0
- package/lib/shell-build-dispatch.js.map +1 -0
- package/lib/shell.d.ts +3 -0
- package/lib/shell.d.ts.map +1 -0
- package/lib/shell.js +297 -0
- package/lib/shell.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { FileUtils, JSONUtils } from "@webda/utils";
|
|
2
|
+
import { relative, dirname } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Generate regex based on a service name
|
|
5
|
+
*
|
|
6
|
+
* The regex will ensure the namespace is optional
|
|
7
|
+
*
|
|
8
|
+
* @param app - the application to resolve namespaces
|
|
9
|
+
* @param type - the service type name
|
|
10
|
+
* @returns regex pattern string
|
|
11
|
+
*/
|
|
12
|
+
function getServiceTypePattern(app, type) {
|
|
13
|
+
const split = app.completeNamespace(type).split("/");
|
|
14
|
+
return `^(${split[0]}/)?${split[1]}$`;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Generate the configuration and deployment schemas
|
|
18
|
+
*
|
|
19
|
+
* @param app to use for application metadata
|
|
20
|
+
* @param filename to save config schema to
|
|
21
|
+
* @param deploymentFilename to save deployment schema to
|
|
22
|
+
* @param full to keep all required
|
|
23
|
+
* @param configFile - optional config file path to update $schema reference
|
|
24
|
+
*/
|
|
25
|
+
export function generateConfigurationSchemas(app, filename = ".webda/config.schema.json", deploymentFilename = ".webda/deployment.schema.json", full = false, configFile) {
|
|
26
|
+
// Build the base configuration schema structure
|
|
27
|
+
let res = {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: {
|
|
30
|
+
$schema: { type: "string" },
|
|
31
|
+
$import: {
|
|
32
|
+
anyOf: [{ type: "string" }, { items: { type: "string" }, type: "array" }],
|
|
33
|
+
description: "Include other configuration files"
|
|
34
|
+
},
|
|
35
|
+
version: { type: "number" },
|
|
36
|
+
parameters: {
|
|
37
|
+
type: "object",
|
|
38
|
+
additionalProperties: true,
|
|
39
|
+
description: "Global parameters shared between all services"
|
|
40
|
+
},
|
|
41
|
+
services: {
|
|
42
|
+
type: "object",
|
|
43
|
+
additionalProperties: {
|
|
44
|
+
oneOf: []
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
models: {
|
|
48
|
+
type: "object",
|
|
49
|
+
additionalProperties: true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
definitions: {}
|
|
53
|
+
};
|
|
54
|
+
// Add the definition for types
|
|
55
|
+
res.definitions.ServicesType = {
|
|
56
|
+
type: "string",
|
|
57
|
+
enum: Object.keys(app.getModdas() || {})
|
|
58
|
+
};
|
|
59
|
+
const addServiceSchema = (type) => {
|
|
60
|
+
return serviceType => {
|
|
61
|
+
const key = `${type}$${serviceType.replace(/\//g, "$")}`;
|
|
62
|
+
const definition = (res.definitions[key] = app.getSchema(serviceType));
|
|
63
|
+
/* should try to mock the getSchema */
|
|
64
|
+
/* c8 ignore next 3 */
|
|
65
|
+
if (!definition) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
definition.title ??= serviceType;
|
|
69
|
+
if (definition.properties?.type) {
|
|
70
|
+
definition.properties.type.pattern = getServiceTypePattern(app, serviceType);
|
|
71
|
+
}
|
|
72
|
+
res.properties.services.additionalProperties.oneOf.push({
|
|
73
|
+
$ref: `#/definitions/${key}`
|
|
74
|
+
});
|
|
75
|
+
delete res.definitions[key]["$schema"];
|
|
76
|
+
// Flatten definition (might not be the best idea)
|
|
77
|
+
for (const def in definition.definitions) {
|
|
78
|
+
res.definitions[def] ??= definition.definitions[def];
|
|
79
|
+
}
|
|
80
|
+
delete definition.definitions;
|
|
81
|
+
// Remove mandatory depending on option
|
|
82
|
+
if (!full) {
|
|
83
|
+
res.definitions[key]["required"] = ["type"];
|
|
84
|
+
}
|
|
85
|
+
// Predefine beans
|
|
86
|
+
if (type === "BeanType") {
|
|
87
|
+
res.properties.services.properties ??= {};
|
|
88
|
+
res.properties.services[definition.title] = {
|
|
89
|
+
$ref: `#/definitions/${key}`
|
|
90
|
+
};
|
|
91
|
+
res.definitions[key].required ??= [];
|
|
92
|
+
res.definitions[key].required = res.definitions[key].required.filter(p => p !== "type");
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
Object.keys(app.getModdas()).forEach(addServiceSchema("ServiceType"));
|
|
97
|
+
Object.keys(app.getModules().beans || {}).forEach(addServiceSchema("BeanType"));
|
|
98
|
+
FileUtils.save(res, filename);
|
|
99
|
+
// Build the deployment schema
|
|
100
|
+
// Ensure builtin deployers are there
|
|
101
|
+
const definitions = JSONUtils.duplicate(res.definitions);
|
|
102
|
+
res = {
|
|
103
|
+
properties: {
|
|
104
|
+
parameters: {
|
|
105
|
+
type: "object",
|
|
106
|
+
additionalProperties: true
|
|
107
|
+
},
|
|
108
|
+
resources: {
|
|
109
|
+
type: "object",
|
|
110
|
+
additionalProperties: true
|
|
111
|
+
},
|
|
112
|
+
services: {
|
|
113
|
+
type: "object",
|
|
114
|
+
additionalProperties: false,
|
|
115
|
+
properties: {}
|
|
116
|
+
},
|
|
117
|
+
units: {
|
|
118
|
+
type: "array",
|
|
119
|
+
items: { oneOf: [] }
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
definitions: res.definitions
|
|
123
|
+
};
|
|
124
|
+
const appServices = app.getConfiguration().services;
|
|
125
|
+
Object.keys(appServices || {}).forEach(k => {
|
|
126
|
+
if (!appServices[k]) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const key = `Service$${k}`;
|
|
130
|
+
res.properties.services.properties[k] = {
|
|
131
|
+
type: "object",
|
|
132
|
+
oneOf: [
|
|
133
|
+
{ $ref: `#/definitions/${key}` },
|
|
134
|
+
...Object.keys(definitions)
|
|
135
|
+
.filter(name => name.startsWith("ServiceType"))
|
|
136
|
+
.map(dkey => ({ $ref: `#/definitions/${dkey}` }))
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
Object.keys(app.getDeployers()).forEach(serviceType => {
|
|
141
|
+
const key = `DeployerType$${serviceType.replace(/\//g, "$")}`;
|
|
142
|
+
const definition = (res.definitions[key] = app.getSchema(serviceType));
|
|
143
|
+
if (!definition) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
definition.title = serviceType;
|
|
147
|
+
if (definition.properties?.type) {
|
|
148
|
+
definition.properties.type.pattern = getServiceTypePattern(app, serviceType);
|
|
149
|
+
}
|
|
150
|
+
res.properties.units.items.oneOf.push({
|
|
151
|
+
$ref: `#/definitions/${key}`
|
|
152
|
+
});
|
|
153
|
+
delete definition["$schema"];
|
|
154
|
+
// Remove mandatory depending on option
|
|
155
|
+
if (!full) {
|
|
156
|
+
definition["required"] = ["type"];
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
FileUtils.save(res, deploymentFilename);
|
|
160
|
+
// Ensure $schema is set in the configuration file
|
|
161
|
+
if (configFile) {
|
|
162
|
+
const config = FileUtils.load(configFile);
|
|
163
|
+
const schemaRef = relative(dirname(configFile), filename);
|
|
164
|
+
if (config.$schema !== schemaRef) {
|
|
165
|
+
config.$schema = schemaRef;
|
|
166
|
+
FileUtils.save(config, configFile);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
//# sourceMappingURL=configuration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configuration.js","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAc9C;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,GAA4B,EAAE,IAAY;IACvE,MAAM,KAAK,GAAG,GAAG,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACrD,OAAO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