@kumori/kdsl 0.0.13 → 0.0.15
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/dist/build/deployment_spec.d.ts +21095 -0
- package/dist/build/deployment_spec.js +292 -0
- package/dist/build/deployment_spec.js.map +1 -0
- package/dist/build/helpers/builtin.d.ts +17 -0
- package/dist/build/helpers/builtin.js +82 -0
- package/dist/build/helpers/builtin.js.map +1 -0
- package/dist/build/helpers/component.d.ts +17 -0
- package/dist/build/helpers/component.js +212 -0
- package/dist/build/helpers/component.js.map +1 -0
- package/dist/build/helpers/connector.d.ts +13 -0
- package/dist/build/helpers/connector.js +190 -0
- package/dist/build/helpers/connector.js.map +1 -0
- package/dist/build/helpers/deployment.d.ts +326 -0
- package/dist/build/helpers/deployment.js +86 -0
- package/dist/build/helpers/deployment.js.map +1 -0
- package/dist/build/helpers/resource.d.ts +97 -0
- package/dist/build/helpers/resource.js +54 -0
- package/dist/build/helpers/resource.js.map +1 -0
- package/dist/build/helpers/service.d.ts +27 -0
- package/dist/build/helpers/service.js +199 -0
- package/dist/build/helpers/service.js.map +1 -0
- package/dist/build/helpers/utils.d.ts +22 -0
- package/dist/build/helpers/utils.js +55 -0
- package/dist/build/helpers/utils.js.map +1 -0
- package/dist/build/main.d.ts +17 -0
- package/dist/build/main.js +139 -0
- package/dist/build/main.js.map +1 -0
- package/dist/build/solution.d.ts +20 -0
- package/dist/build/solution.js +72 -0
- package/dist/build/solution.js.map +1 -0
- package/dist/check/main.d.ts +21 -0
- package/dist/check/main.js +99 -0
- package/dist/check/main.js.map +1 -0
- package/dist/clean/main.d.ts +11 -0
- package/dist/clean/main.js +26 -0
- package/dist/clean/main.js.map +1 -0
- package/dist/help/main.d.ts +13 -0
- package/dist/help/main.js +49 -0
- package/dist/help/main.js.map +1 -0
- package/dist/help/topic/build.d.ts +2 -0
- package/dist/help/topic/build.js +7 -0
- package/dist/help/topic/build.js.map +1 -0
- package/dist/help/topic/mod_dep.d.ts +2 -0
- package/dist/help/topic/mod_dep.js +8 -0
- package/dist/help/topic/mod_dep.js.map +1 -0
- package/dist/help/topic/mod_dl.d.ts +2 -0
- package/dist/help/topic/mod_dl.js +25 -0
- package/dist/help/topic/mod_dl.js.map +1 -0
- package/dist/index/create/main.d.ts +14 -0
- package/dist/index/create/main.js +264 -0
- package/dist/index/create/main.js.map +1 -0
- package/dist/index/main.d.ts +8 -0
- package/dist/index/main.js +17 -0
- package/dist/index/main.js.map +1 -0
- package/dist/lib/build.d.ts +42 -0
- package/dist/lib/build.js +28 -0
- package/dist/lib/build.js.map +1 -0
- package/dist/lib/check.d.ts +41 -0
- package/dist/lib/check.js +15 -0
- package/dist/lib/check.js.map +1 -0
- package/dist/lib/clean.d.ts +31 -0
- package/dist/lib/clean.js +1 -0
- package/dist/lib/clean.js.map +1 -0
- package/dist/lib/index-cmd.d.ts +54 -0
- package/dist/lib/index-cmd.js +57 -0
- package/dist/lib/index-cmd.js.map +1 -0
- package/dist/lib/index.d.ts +56 -0
- package/dist/lib/index.js +117 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/io/lib.kumori +5 -0
- package/dist/lib/kumori/builtin/httpinbound.h.kumori +27 -0
- package/dist/lib/kumori/builtin/tcpinbound.h.kumori +25 -0
- package/dist/lib/kumori/builtin.kumori +18 -0
- package/dist/lib/kumori/component.kumori +120 -0
- package/dist/lib/kumori/deployment.kumori +16 -0
- package/dist/lib/kumori/resource.kumori +25 -0
- package/dist/lib/kumori/service.kumori +49 -0
- package/dist/lib/kumori/shared.kumori +11 -0
- package/dist/lib/kumori/sized.kumori +25 -0
- package/dist/lib/logger.d.ts +10 -0
- package/dist/lib/logger.js +23 -0
- package/dist/lib/logger.js.map +1 -0
- package/dist/lib/mod.d.ts +156 -0
- package/dist/lib/mod.js +70 -0
- package/dist/lib/mod.js.map +1 -0
- package/dist/lib/registry.d.ts +61 -0
- package/dist/lib/registry.js +1 -0
- package/dist/lib/registry.js.map +1 -0
- package/dist/lib/sized.kumori +8 -0
- package/dist/lib/std.kumori +8 -0
- package/dist/lib/strconv/lib.kumori +11 -0
- package/dist/lib/types.d.ts +26 -0
- package/dist/lib/types.js +2 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +35 -0
- package/dist/main.js.map +1 -0
- package/dist/mod/checksum/main.d.ts +11 -0
- package/dist/mod/checksum/main.js +33 -0
- package/dist/mod/checksum/main.js.map +1 -0
- package/dist/mod/dependency/main.d.ts +19 -0
- package/dist/mod/dependency/main.js +156 -0
- package/dist/mod/dependency/main.js.map +1 -0
- package/dist/mod/download/functions.d.ts +53 -0
- package/dist/mod/download/functions.js +235 -0
- package/dist/mod/download/functions.js.map +1 -0
- package/dist/mod/download/main.d.ts +26 -0
- package/dist/mod/download/main.js +89 -0
- package/dist/mod/download/main.js.map +1 -0
- package/dist/mod/init/main.d.ts +13 -0
- package/dist/mod/init/main.js +66 -0
- package/dist/mod/init/main.js.map +1 -0
- package/dist/mod/jsonschema/gen/main.d.ts +11 -0
- package/dist/mod/jsonschema/gen/main.js +281 -0
- package/dist/mod/jsonschema/gen/main.js.map +1 -0
- package/dist/mod/jsonschema/get/kdslschema.d.ts +28 -0
- package/dist/mod/jsonschema/get/kdslschema.js +3 -0
- package/dist/mod/jsonschema/get/kdslschema.js.map +1 -0
- package/dist/mod/jsonschema/get/main.d.ts +76 -0
- package/dist/mod/jsonschema/get/main.js +338 -0
- package/dist/mod/jsonschema/get/main.js.map +1 -0
- package/dist/mod/jsonschema/main.d.ts +8 -0
- package/dist/mod/jsonschema/main.js +20 -0
- package/dist/mod/jsonschema/main.js.map +1 -0
- package/dist/mod/main.d.ts +8 -0
- package/dist/mod/main.js +27 -0
- package/dist/mod/main.js.map +1 -0
- package/dist/mod/update/main.d.ts +17 -0
- package/dist/mod/update/main.js +69 -0
- package/dist/mod/update/main.js.map +1 -0
- package/dist/registry/add.d.ts +15 -0
- package/dist/registry/add.js +53 -0
- package/dist/registry/add.js.map +1 -0
- package/dist/registry/list.d.ts +15 -0
- package/dist/registry/list.js +29 -0
- package/dist/registry/list.js.map +1 -0
- package/dist/registry/main.d.ts +8 -0
- package/dist/registry/main.js +21 -0
- package/dist/registry/main.js.map +1 -0
- package/dist/registry/remove.d.ts +15 -0
- package/dist/registry/remove.js +34 -0
- package/dist/registry/remove.js.map +1 -0
- package/dist/util/err-format.d.ts +2 -0
- package/dist/util/err-format.js +11 -0
- package/dist/util/err-format.js.map +1 -0
- package/dist/util/err-handler.d.ts +3 -0
- package/dist/util/err-handler.js +11 -0
- package/dist/util/err-handler.js.map +1 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.js +2 -0
- package/dist/util.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +6 -0
- package/dist/version.js.map +1 -0
- package/out/lib/build.cjs +29 -0
- package/out/lib/check.cjs +16 -0
- package/out/lib/clean.cjs +2 -0
- package/out/lib/index-cmd.cjs +58 -0
- package/out/lib/index.cjs +118 -0
- package/out/lib/mod.cjs +71 -0
- package/out/lib/registry.cjs +2 -0
- package/out/main.cjs +172 -172
- package/package.json +50 -6
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { createKumoriServices, } from "@kumori/kdsl-lsp/language/kumori.js";
|
|
2
|
+
import { ModuleContext } from "@kumori/kdsl-lsp/module/context.js";
|
|
3
|
+
import { ParseQuery } from "@kumori/kdsl-lsp/module/query.js";
|
|
4
|
+
import { Maybe, None, Some } from "@kumori/kdsl-lsp/util/maybe.js";
|
|
5
|
+
import { Err, Ok, Result } from "@kumori/kdsl-lsp/util/result.js";
|
|
6
|
+
import { TempCache } from "@kumori/kdsl-lsp/util/tmp.js";
|
|
7
|
+
import { NodeFileSystem } from "langium/node";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { Check } from "../../../check/main.js";
|
|
10
|
+
import { AstUtils, URI, UriUtils } from "langium";
|
|
11
|
+
import assert from "assert";
|
|
12
|
+
import { TAny, TBoolean, TEither, TFunction, TList, TNumber, TOptional, TString, TStruct, TTypeDefAlias, TTypeDefNamed, TypeSystemError, TypeToString, } from "@kumori/kdsl-lsp/language/type-system/type.js";
|
|
13
|
+
import { ModuleDescriptor } from "@kumori/kdsl-lsp/module/descriptor.js";
|
|
14
|
+
import { isBuiltinArtifact, isComponentArtifact, isServiceArtifact, } from "@kumori/kdsl-lsp/language/generated/ast.js";
|
|
15
|
+
import { Scheme } from "@kumori/kdsl-lsp/language/builtin/util.js";
|
|
16
|
+
import { GatherModuleDocuments } from "@kumori/kdsl-lsp/module/documents.js";
|
|
17
|
+
import { DefaultErrHandler } from "../../../util/err-handler.js";
|
|
18
|
+
import { FormatTypeSystemError } from "../../../util/err-format.js";
|
|
19
|
+
import { DownloadModuleToDir } from "../../../mod/download/functions.js";
|
|
20
|
+
import { RemoteFetcherFactory } from "@kumori/kdsl-lsp/module/remote/factory.js";
|
|
21
|
+
export default { Register };
|
|
22
|
+
export function Register(cmd, log) {
|
|
23
|
+
const c = cmd
|
|
24
|
+
.command("get")
|
|
25
|
+
.summary(Summary)
|
|
26
|
+
.argument("<target>", `Unique path of the kmodule where the artifact is defined. Accepts remote targets (e.g., "github.com/MyOrg/component@v1.2.3") or local paths (e.g. "/abs/path/to/module", "../rel/path/to/module").`)
|
|
27
|
+
.argument("<package-path>", `Relative path to the package that contains the artifact (e.g., "internal/service"). For artifacts in the module's root package, use ".".`)
|
|
28
|
+
.argument("<artifact-name>", `Name of the target artifact (e.g., "ExampleService").`)
|
|
29
|
+
.description(Description)
|
|
30
|
+
.helpOption(true)
|
|
31
|
+
.action(Action(log));
|
|
32
|
+
return c;
|
|
33
|
+
}
|
|
34
|
+
const Summary = `extracts jsonschema for a specified module and artifact`;
|
|
35
|
+
export const Description = `
|
|
36
|
+
Generates and outputs the JSON Schema that describes a particular Kumori DSL
|
|
37
|
+
artifact. This schema defines the artifact's configurable properties, resource
|
|
38
|
+
requirements, and overall structure, making it valuable for programmatic
|
|
39
|
+
interaction, validation, or documentation purposes.
|
|
40
|
+
|
|
41
|
+
The command allows you to specify artifacts from both remote/external modules
|
|
42
|
+
and local modules.
|
|
43
|
+
`.trim();
|
|
44
|
+
export function Action(log) {
|
|
45
|
+
return async (module, pkg, artifact) => {
|
|
46
|
+
const svcs = createKumoriServices(NodeFileSystem).Kumori;
|
|
47
|
+
const ErrHandler = (v) => DefaultErrHandler(log, v);
|
|
48
|
+
const loc = ErrHandler(await LocateModule(module));
|
|
49
|
+
const fs = svcs.shared.workspace.FileSystemProvider;
|
|
50
|
+
const ctx = ErrHandler(Result.mapErr(await ModuleContext(fs, URI.file(loc.fsPath)), (err) => [
|
|
51
|
+
err,
|
|
52
|
+
]));
|
|
53
|
+
// The module has been located, it has been downloaded and its context
|
|
54
|
+
// initialized. Now, let's download its dependencies.
|
|
55
|
+
ErrHandler(await Check(log, svcs, ctx));
|
|
56
|
+
// The module and its dependencies are now available. Get me the schema!
|
|
57
|
+
const schema = ErrHandler(await GetSchema(svcs, ctx, pkg, artifact));
|
|
58
|
+
console.log(JSON.stringify(schema, null, 4));
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Find the specified module. If it's not a locally-available module, download it
|
|
63
|
+
* into the global temporary directory
|
|
64
|
+
* @param module
|
|
65
|
+
* @returns Result
|
|
66
|
+
*/
|
|
67
|
+
export async function LocateModule(module) {
|
|
68
|
+
const workdir = await TempCache();
|
|
69
|
+
const fs = NodeFileSystem.fileSystemProvider();
|
|
70
|
+
const target = module;
|
|
71
|
+
const isPath = module[0] === "." || path.isAbsolute(module);
|
|
72
|
+
if (isPath) {
|
|
73
|
+
// If the path is relative, build an absolute path based on the current working directory
|
|
74
|
+
const modulePath = path.isAbsolute(module)
|
|
75
|
+
? module
|
|
76
|
+
: path.resolve(process.cwd(), module);
|
|
77
|
+
return Ok({ $type: "local", fsPath: modulePath });
|
|
78
|
+
}
|
|
79
|
+
// Apparently it's a remote target. Check if the reference is valid
|
|
80
|
+
// and download the artifact to the temp cache.
|
|
81
|
+
const remote = ParseQuery(module);
|
|
82
|
+
if (Maybe.isNone(remote)) {
|
|
83
|
+
return Err([`invalid remote target '${module}': invalid syntax`]);
|
|
84
|
+
}
|
|
85
|
+
const version = remote.value.Version;
|
|
86
|
+
const modname = `${remote.value.Location}@${version}`;
|
|
87
|
+
const ModLocation = UriUtils.joinPath(workdir, modname);
|
|
88
|
+
const existing = await ModuleDescriptor(fs, ModLocation);
|
|
89
|
+
if (Result.isErr(existing)) {
|
|
90
|
+
const dlResult = await DownloadModuleToDir({ Remotes: RemoteFetcherFactory() }, remote.value.Location, version, ModLocation.fsPath);
|
|
91
|
+
if (Result.isErr(dlResult)) {
|
|
92
|
+
return Err([`failed to fetch ${target}: ${dlResult.err}`]);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return Ok({
|
|
96
|
+
$type: "remote",
|
|
97
|
+
fsPath: ModLocation.fsPath,
|
|
98
|
+
query: remote.value,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Given an artifact, returns its JSON Schema representation
|
|
103
|
+
* @param svcs
|
|
104
|
+
* @param ctx
|
|
105
|
+
* @param pkg
|
|
106
|
+
* @param artifact
|
|
107
|
+
* @returns
|
|
108
|
+
*/
|
|
109
|
+
export async function GetSchema(svcs, ctx, pkg, artifact) {
|
|
110
|
+
// Validate package + artifact name exists
|
|
111
|
+
const uri = UriUtils.joinPath(ctx.Current.Root, path.normalize(pkg));
|
|
112
|
+
const ref = svcs.references.KumoriPackages.GetPackage(uri);
|
|
113
|
+
if (Result.isErr(ref)) {
|
|
114
|
+
return Err([`error: failed to retrieve package: ${uri.toString()}`]);
|
|
115
|
+
}
|
|
116
|
+
// We want to find the artifact among all package artifacts
|
|
117
|
+
const pkgUris = new Set(ref.value.docs.map((p) => p.uri.toString()));
|
|
118
|
+
const matches = svcs.shared.workspace.IndexManager.allElements(undefined, pkgUris)
|
|
119
|
+
.toArray()
|
|
120
|
+
.filter((n) => n.name === artifact);
|
|
121
|
+
// If no artifact found or more than one were found, then we're done
|
|
122
|
+
if (matches.length < 1) {
|
|
123
|
+
return Err([`error: no artifact named defined in ${uri.toString()}`]);
|
|
124
|
+
}
|
|
125
|
+
if (matches.length > 2) {
|
|
126
|
+
return Err([`error: too many matches in ${uri.toString()}`]);
|
|
127
|
+
}
|
|
128
|
+
// We found our artifact, now let's check if
|
|
129
|
+
// its type is one of the expected ones
|
|
130
|
+
let foundArtifact = matches[0].node;
|
|
131
|
+
if (!(isComponentArtifact(foundArtifact) ||
|
|
132
|
+
isServiceArtifact(foundArtifact) ||
|
|
133
|
+
isBuiltinArtifact(foundArtifact))) {
|
|
134
|
+
return Err([`invalid reference to node of type: ${foundArtifact.$type}`]);
|
|
135
|
+
}
|
|
136
|
+
// The JSON Schema only aims to represent everything that is
|
|
137
|
+
// configurable from the outside. Therefore, we only want to
|
|
138
|
+
// represent the interface (headers)
|
|
139
|
+
const doc = AstUtils.getDocument(foundArtifact);
|
|
140
|
+
if (!doc.uri.fsPath.endsWith(".h.kumori")) {
|
|
141
|
+
if (!foundArtifact.name.value.ref) {
|
|
142
|
+
return Err(["no headers found for component"]);
|
|
143
|
+
}
|
|
144
|
+
// Overwrite the current artifact with its interface
|
|
145
|
+
foundArtifact = foundArtifact.name.value.ref;
|
|
146
|
+
}
|
|
147
|
+
// We have identified our artifact. Now, it'll go through the type system
|
|
148
|
+
// to properly assign it a type.
|
|
149
|
+
const typeService = svcs.validation.KumoriTypeSystem;
|
|
150
|
+
const typesctx = svcs.validation.KumoriValidations.ctx();
|
|
151
|
+
const [node, err] = typeService.Infer(typesctx, foundArtifact);
|
|
152
|
+
if (err.length > 0) {
|
|
153
|
+
const errors = [];
|
|
154
|
+
err.map((e) => errors.concat(e.message));
|
|
155
|
+
return Err([`type inference failed with errors: ${errors}`]);
|
|
156
|
+
}
|
|
157
|
+
const result = await ToJSONSchema(svcs, ctx, node, path.join(ctx.Current.Manifest.module, pkg + "@" + artifact));
|
|
158
|
+
return Result.mapErr(result, (v) => v.map(FormatTypeSystemError));
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provides the JSON Schema representation of the given artifact
|
|
162
|
+
* @param svcs Kumori Services
|
|
163
|
+
* @param mod The context of the module
|
|
164
|
+
* @param node The artifact, as an AST node
|
|
165
|
+
* @param id Identifier to be used in the schema
|
|
166
|
+
* @returns JSON Schema
|
|
167
|
+
*/
|
|
168
|
+
export async function ToJSONSchema(svcs, mod, node, id) {
|
|
169
|
+
return Result.map(await ToJSONSchemaInternal({ svcs, mod }, node), (schema) => (Object.assign({ $schema: "https://json-schema.org/draft/2020-12/schema", $spec: "kumori/schema/v1", $id: id }, schema)));
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Converts a Kumori AST type node into a JSON Schema fragment (`KDSLSchemaV1Item`).
|
|
173
|
+
*
|
|
174
|
+
* This function recursively traverses the given `AstNodeType` and produces the
|
|
175
|
+
* corresponding JSON Schema representation. Each Kumori type maps to a JSON
|
|
176
|
+
* Schema construct.
|
|
177
|
+
*
|
|
178
|
+
* @param ctx Context providing access to services and the current module
|
|
179
|
+
* @param type The Kumori AST type node to translate
|
|
180
|
+
* @returns A `Result` containing either the JSON Schema fragment
|
|
181
|
+
* or a list of `TypeSystemError` if translation failed
|
|
182
|
+
*/
|
|
183
|
+
export async function ToJSONSchemaInternal(ctx, type) {
|
|
184
|
+
// Any accepts everything
|
|
185
|
+
if (TAny.is(type)) {
|
|
186
|
+
return Ok({});
|
|
187
|
+
}
|
|
188
|
+
// Functions translates its return type
|
|
189
|
+
if (TFunction.is(type)) {
|
|
190
|
+
return ToJSONSchemaInternal(ctx, type.returns);
|
|
191
|
+
}
|
|
192
|
+
if (TOptional.is(type)) {
|
|
193
|
+
return ToJSONSchemaInternal(ctx, type.inner);
|
|
194
|
+
}
|
|
195
|
+
if (TTypeDefAlias.is(type)) {
|
|
196
|
+
return ToJSONSchemaInternal(ctx, type.spec);
|
|
197
|
+
}
|
|
198
|
+
// If it's a number, returns type or const if the value is not configurable
|
|
199
|
+
if (TNumber.is(type)) {
|
|
200
|
+
if (type.literal === undefined) {
|
|
201
|
+
return Ok({ type: "number" });
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
return Ok({ const: type.literal });
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
// If it's a string, returns type or const if the value is not configurable
|
|
208
|
+
if (TString.is(type)) {
|
|
209
|
+
if (type.literal === undefined) {
|
|
210
|
+
return Ok({ type: "string" });
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
return Ok({ const: type.literal });
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// If it's a boolean, returns type or const if the value is not configurable
|
|
217
|
+
if (TBoolean.is(type)) {
|
|
218
|
+
if (type.literal === undefined) {
|
|
219
|
+
return Ok({ type: "boolean" });
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
return Ok({ const: type.literal });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
if (TList.is(type)) {
|
|
226
|
+
const r = await ToJSONSchemaInternal(ctx, type.restriction);
|
|
227
|
+
if (Result.isErr(r)) {
|
|
228
|
+
return r;
|
|
229
|
+
}
|
|
230
|
+
return Ok({
|
|
231
|
+
type: "array",
|
|
232
|
+
items: r.value,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
if (TEither.is(type)) {
|
|
236
|
+
const variations = await Promise.all(type.variations.map((v) => ToJSONSchemaInternal(ctx, v)));
|
|
237
|
+
const failures = variations
|
|
238
|
+
.filter(Result.isErr)
|
|
239
|
+
.map((e) => e.err)
|
|
240
|
+
.flat();
|
|
241
|
+
if (failures.length > 0) {
|
|
242
|
+
return Err(failures);
|
|
243
|
+
}
|
|
244
|
+
const oneOf = variations.filter(Result.isOk).map((e) => e.value);
|
|
245
|
+
assert(oneOf.length === variations.length);
|
|
246
|
+
return Ok({ oneOf });
|
|
247
|
+
}
|
|
248
|
+
if (TStruct.is(type)) {
|
|
249
|
+
const params = await Promise.all(Object.entries(type.parameters).map(async (param) => ({
|
|
250
|
+
key: param[0],
|
|
251
|
+
value: param[1],
|
|
252
|
+
schema: await ToJSONSchemaInternal(ctx, param[1].value),
|
|
253
|
+
})));
|
|
254
|
+
let errs = params
|
|
255
|
+
.map((v) => v.schema)
|
|
256
|
+
.filter((v) => Result.isErr(v))
|
|
257
|
+
.map((v) => v.err)
|
|
258
|
+
.flat();
|
|
259
|
+
let restriction = None;
|
|
260
|
+
if (type.restriction !== undefined && !TAny.is(type.restriction)) {
|
|
261
|
+
const schema = await ToJSONSchemaInternal(ctx, type.restriction);
|
|
262
|
+
if (Result.isOk(schema)) {
|
|
263
|
+
restriction = Some(schema.value);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
errs = errs.concat(schema.err);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (errs.length > 0) {
|
|
270
|
+
return Err(errs);
|
|
271
|
+
}
|
|
272
|
+
let schema = {
|
|
273
|
+
type: "object",
|
|
274
|
+
properties: Object.fromEntries(params.map((v) => {
|
|
275
|
+
assert(Result.isOk(v.schema));
|
|
276
|
+
return [v.key, v.schema.value];
|
|
277
|
+
})),
|
|
278
|
+
required: params
|
|
279
|
+
.filter((param) => param.value.optional === false &&
|
|
280
|
+
!TOptional.is(param.value.value))
|
|
281
|
+
.map((param) => param.key),
|
|
282
|
+
};
|
|
283
|
+
if (Maybe.isSome(restriction)) {
|
|
284
|
+
schema = Object.assign(Object.assign({}, schema), { additionalProperties: restriction.value });
|
|
285
|
+
}
|
|
286
|
+
return Ok(schema);
|
|
287
|
+
}
|
|
288
|
+
if (TTypeDefNamed.is(type)) {
|
|
289
|
+
const r = await ToJSONSchemaInternal(ctx, type.spec);
|
|
290
|
+
if (Result.isErr(r))
|
|
291
|
+
return r;
|
|
292
|
+
return Ok({
|
|
293
|
+
type: "object",
|
|
294
|
+
properties: {
|
|
295
|
+
$kdsl: {
|
|
296
|
+
const: { NamedType: await JSONSchemaNamedTypeRef(ctx, type) },
|
|
297
|
+
},
|
|
298
|
+
inner: r.value,
|
|
299
|
+
},
|
|
300
|
+
required: ["$kdsl", "inner"],
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
return Err([
|
|
304
|
+
TypeSystemError.create({
|
|
305
|
+
node: type,
|
|
306
|
+
message: `cannot convert definition to JSONSchema: ${TypeToString(type)}`,
|
|
307
|
+
}),
|
|
308
|
+
]);
|
|
309
|
+
}
|
|
310
|
+
const JSONSchemaNamedTypeRef = async (ctx, type) => {
|
|
311
|
+
const node = type.node;
|
|
312
|
+
assert(node);
|
|
313
|
+
const Mods = ctx.svcs.shared.references.KumoriModules;
|
|
314
|
+
const uri = AstUtils.getDocument(node).uri;
|
|
315
|
+
const pkg = ctx.svcs.references.KumoriPackages.GetPackage(node);
|
|
316
|
+
let desc = ctx.mod.Current;
|
|
317
|
+
assert(Result.isOk(pkg));
|
|
318
|
+
const isStdLib = uri.scheme === Scheme;
|
|
319
|
+
if (isStdLib) {
|
|
320
|
+
return { Import: pkg.value.uri.path.slice(1), Name: type.meta.name };
|
|
321
|
+
}
|
|
322
|
+
const rootDocs = await GatherModuleDocuments(ctx.svcs.shared, ctx.mod.Root.Root);
|
|
323
|
+
const isRootModule = rootDocs.map((uri) => uri.fsPath).includes(uri.fsPath);
|
|
324
|
+
if (!isRootModule) {
|
|
325
|
+
// The remote module MAY not be in accessible from the scope of the current module
|
|
326
|
+
// TODO: if the remote module is a vendored module it should fail (?)
|
|
327
|
+
const mod = Mods.getModule(uri);
|
|
328
|
+
assert(Result.isOk(mod));
|
|
329
|
+
desc = mod.value;
|
|
330
|
+
}
|
|
331
|
+
const from = desc.Root;
|
|
332
|
+
const pkgStr = pkg.value.uri.fsPath.slice(from.fsPath.length);
|
|
333
|
+
return {
|
|
334
|
+
Import: path.join(desc.Manifest.module, pkgStr),
|
|
335
|
+
Name: type.meta.name,
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/mod/jsonschema/get/main.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,GAErB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAA;AAClE,OAAO,EAAE,UAAU,EAAS,MAAM,kCAAkC,CAAA;AACpE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAA;AACjE,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAA;AAE9C,OAAO,EAAE,QAAQ,EAAsB,GAAG,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAErE,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAEL,IAAI,EACJ,QAAQ,EACR,OAAO,EACP,SAAS,EACT,KAAK,EACL,OAAO,EACP,SAAS,EACT,OAAO,EACP,OAAO,EACP,aAAa,EACb,aAAa,EACb,eAAe,EACf,YAAY,GACb,MAAM,+CAA+C,CAAA;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAA;AACxE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,4CAA4C,CAAA;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAE5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,E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,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAA;QACxB,IAAI,GAAG,GAAG,CAAC,KAAK,CAAA;IAClB,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;IACtB,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC7D,OAAO;QACL,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QAC/C,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI;KACrB,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { ILogLayer } from "loglayer";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
Register: typeof Register;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export declare function Register(cmd: Command, log: ILogLayer): Command<[], {}, {}>;
|
|
8
|
+
export declare const Description: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import gen from "./gen/main.js";
|
|
2
|
+
import get from "./get/main.js";
|
|
3
|
+
export default { Register };
|
|
4
|
+
export function Register(cmd, log) {
|
|
5
|
+
const program = cmd
|
|
6
|
+
.command("schema")
|
|
7
|
+
.alias("s")
|
|
8
|
+
.summary(Summary)
|
|
9
|
+
.description(Description)
|
|
10
|
+
.helpCommand(false)
|
|
11
|
+
.helpOption(false);
|
|
12
|
+
gen.Register(program, log);
|
|
13
|
+
get.Register(program, log);
|
|
14
|
+
return program;
|
|
15
|
+
}
|
|
16
|
+
const Summary = `jsonschema processing`;
|
|
17
|
+
export const Description = `
|
|
18
|
+
The schema command provides utilities for working with JSON Schemas of Kumori DSL artifacts.
|
|
19
|
+
`.trim();
|
|
20
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/mod/jsonschema/main.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,eAAe,CAAA;AAC/B,OAAO,GAAG,MAAM,eAAe,CAAA;AAG/B,eAAe,EAAE,QAAQ,EAAE,CAAA;AAC3B,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAc;IACnD,MAAM,OAAO,GAAG,GAAG;SAChB,OAAO,CAAC,QAAQ,CAAC;SACjB,KAAK,CAAC,GAAG,CAAC;SACV,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,WAAW,CAAC;SACxB,WAAW,CAAC,KAAK,CAAC;SAClB,UAAU,CAAC,KAAK,CAAC,CAAA;IAEpB,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAC1B,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE1B,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,OAAO,GAAG,uBAAuB,CAAA;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG;;CAE1B,CAAC,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { ILogLayer } from "loglayer";
|
|
3
|
+
declare const _default: {
|
|
4
|
+
Register: typeof Register;
|
|
5
|
+
};
|
|
6
|
+
export default _default;
|
|
7
|
+
export declare function Register(cmd: Command, log: ILogLayer): Command<[], {}, {}>;
|
|
8
|
+
export declare const Description: string;
|
package/dist/mod/main.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import init from "./init/main.js";
|
|
2
|
+
import dep from "./dependency/main.js";
|
|
3
|
+
import download from "./download/main.js";
|
|
4
|
+
import jsonschema from "./jsonschema/main.js";
|
|
5
|
+
import checksum from "./checksum/main.js";
|
|
6
|
+
import updates from "./update/main.js";
|
|
7
|
+
export default { Register };
|
|
8
|
+
export function Register(cmd, log) {
|
|
9
|
+
const program = cmd
|
|
10
|
+
.command("mod")
|
|
11
|
+
.summary(Summary)
|
|
12
|
+
.description(Description)
|
|
13
|
+
.helpCommand(false)
|
|
14
|
+
.helpOption(false);
|
|
15
|
+
dep.Register(program, log);
|
|
16
|
+
download.Register(program, log);
|
|
17
|
+
init.Register(program, log);
|
|
18
|
+
jsonschema.Register(program, log);
|
|
19
|
+
checksum.Register(program);
|
|
20
|
+
updates.Register(program, log);
|
|
21
|
+
return program;
|
|
22
|
+
}
|
|
23
|
+
const Summary = `module maintenance`;
|
|
24
|
+
export const Description = `
|
|
25
|
+
Provides access to operations on modules.
|
|
26
|
+
`.trim();
|
|
27
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/mod/main.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,gBAAgB,CAAA;AACjC,OAAO,GAAG,MAAM,sBAAsB,CAAA;AACtC,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AACzC,OAAO,UAAU,MAAM,sBAAsB,CAAA;AAC7C,OAAO,QAAQ,MAAM,oBAAoB,CAAA;AACzC,OAAO,OAAO,MAAM,kBAAkB,CAAA;AAGtC,eAAe,EAAE,QAAQ,EAAE,CAAA;AAC3B,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAc;IACnD,MAAM,OAAO,GAAG,GAAG;SAChB,OAAO,CAAC,KAAK,CAAC;SACd,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,WAAW,CAAC;SACxB,WAAW,CAAC,KAAK,CAAC;SAClB,UAAU,CAAC,KAAK,CAAC,CAAA;IAEpB,GAAG,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAC1B,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAC/B,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAC3B,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACjC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;IAC1B,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IAE9B,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,OAAO,GAAG,oBAAoB,CAAA;AACpC,MAAM,CAAC,MAAM,WAAW,GAAG;;CAE1B,CAAC,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { CommanderActionParams } from "../../util.js";
|
|
3
|
+
import { ILogLayer } from "loglayer";
|
|
4
|
+
declare const _default: {
|
|
5
|
+
Register: typeof Register;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function Register(cmd: Command, log: ILogLayer): Command<[], {
|
|
9
|
+
version?: string | undefined;
|
|
10
|
+
path?: string | undefined;
|
|
11
|
+
cacheLocation?: string | undefined;
|
|
12
|
+
}, {}>;
|
|
13
|
+
export declare const Description: string;
|
|
14
|
+
export type Exec = CommanderActionParams<ReturnType<typeof Register>>;
|
|
15
|
+
export declare function Action(log: ILogLayer): Exec;
|
|
16
|
+
export type Params = Parameters<Exec>;
|
|
17
|
+
export declare const NewModule: (log: ILogLayer, cwd: string, options: Params[0]) => Promise<void>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Maybe } from "@kumori/kdsl-lsp/util/maybe.js";
|
|
2
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
3
|
+
import { URI } from "langium";
|
|
4
|
+
import { NodeFileSystem } from "langium/node";
|
|
5
|
+
import { LocateModuleManifest, MOD_FILE, } from "@kumori/kdsl-lsp/module/locator.js";
|
|
6
|
+
import path from "path";
|
|
7
|
+
export default { Register };
|
|
8
|
+
export function Register(cmd, log) {
|
|
9
|
+
const c = cmd
|
|
10
|
+
.command("update")
|
|
11
|
+
.summary(Summary)
|
|
12
|
+
.option("-v, --version <version>", "new module version")
|
|
13
|
+
.option("-p, --path <location>", "location where the module to update is located - defaults to the current directory")
|
|
14
|
+
.option("-c, --cacheLocation <cacheLocation>", "new cache location")
|
|
15
|
+
.description(Description)
|
|
16
|
+
.helpOption(true)
|
|
17
|
+
.action(Action(log));
|
|
18
|
+
return c;
|
|
19
|
+
}
|
|
20
|
+
const Summary = `updates an existing kumori module's version or cache location`;
|
|
21
|
+
export const Description = `
|
|
22
|
+
This command updates an existing Kumori module's version or cache location in the kumori.mod.json file. It is required to provide the new version and optionally
|
|
23
|
+
a new cache location for the module.
|
|
24
|
+
|
|
25
|
+
kdsl mod update -v 1.0.0
|
|
26
|
+
|
|
27
|
+
You could as well provide a new location for the module's local cache,
|
|
28
|
+
where all the dependencies will be downloaded.
|
|
29
|
+
|
|
30
|
+
kdsl mod update -v 1.0.0 -c ./my-mod-cache
|
|
31
|
+
|
|
32
|
+
If the module is not located in the current directory, you can provide a custom location path.
|
|
33
|
+
|
|
34
|
+
kdsl mod update -v 1.0.0 -p ./my-module
|
|
35
|
+
`.trim();
|
|
36
|
+
export function Action(log) {
|
|
37
|
+
return async (options) => {
|
|
38
|
+
await NewModule(log, process.cwd(), options);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export const NewModule = async (log, cwd, options) => {
|
|
42
|
+
var _a, _b, _c;
|
|
43
|
+
const fs = NodeFileSystem.fileSystemProvider();
|
|
44
|
+
let location = (_a = options.path) !== null && _a !== void 0 ? _a : cwd;
|
|
45
|
+
if (!path.isAbsolute(location)) {
|
|
46
|
+
location = path.join(cwd, location);
|
|
47
|
+
}
|
|
48
|
+
const uri = await LocateModuleManifest(fs, URI.file(location));
|
|
49
|
+
if (Maybe.isSome(uri) && uri.value.fsPath === location) {
|
|
50
|
+
log.error(`error: module ${location} already exists`);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
// Read the existing manifest
|
|
54
|
+
const manifestContent = await fs.readFile(URI.file(path.join(location, MOD_FILE)));
|
|
55
|
+
const manifest = JSON.parse(manifestContent);
|
|
56
|
+
const updatedManifest = {
|
|
57
|
+
spec: "kumori/module/v1",
|
|
58
|
+
kumori: "0.0.1",
|
|
59
|
+
version: (_b = options.version) !== null && _b !== void 0 ? _b : manifest.version,
|
|
60
|
+
module: manifest.module,
|
|
61
|
+
cacheLocation: (_c = options.cacheLocation) !== null && _c !== void 0 ? _c : manifest.cacheLocation,
|
|
62
|
+
requires: [],
|
|
63
|
+
};
|
|
64
|
+
const file = path.join(location, MOD_FILE);
|
|
65
|
+
await mkdir(location, { recursive: true });
|
|
66
|
+
await writeFile(file, JSON.stringify(updatedManifest, null, 4));
|
|
67
|
+
log.info(`updated ${MOD_FILE}: module ${updatedManifest.module}`);
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/mod/update/main.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAA;AACtD,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAE7C,OAAO,EACL,oBAAoB,EACpB,QAAQ,GACT,MAAM,oCAAoC,CAAA;AAC3C,OAAO,IAAI,MAAM,MAAM,CAAA;AAIvB,eAAe,EAAE,QAAQ,EAAE,CAAA;AAC3B,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAc;IACnD,MAAM,CAAC,GAAG,GAAG;SACV,OAAO,CAAC,QAAQ,CAAC;SACjB,OAAO,CAAC,OAAO,CAAC;SAChB,MAAM,CAAC,yBAAyB,EAAE,oBAAoB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,IAAI,CAAC,CAAC,CAAC,CAAA;IACjB,CAAC;IAED,6BAA6B;IAC7B,MAAM,eAAe,GAAG,MAAM,EAAE,CAAC,QAAQ,CACvC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CACxC,CAAA;IACD,MAAM,QAAQ,GAAmB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAA;IAE5D,MAAM,eAAe,GAAmB;QACtC,IAAI,EAAE,kBAAkB;QACxB,MAAM,EAAE,OAAO;QACf,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,QAAQ,CAAC,OAAO;QAC5C,MAAM,EAAE,QAAQ,CAAC,MAAM;QACvB,aAAa,EAAE,MAAA,OAAO,CAAC,aAAa,mCAAI,QAAQ,CAAC,aAAa;QAC9D,QAAQ,EAAE,EAAE;KACb,CAAA;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;IAC1C,MAAM,KAAK,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAC1C,MAAM,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IAC/D,GAAG,CAAC,IAAI,CAAC,WAAW,QAAQ,YAAY,eAAe,CAAC,MAAM,EAAE,CAAC,CAAA;AACnE,CAAC,CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { ILogLayer } from "loglayer";
|
|
3
|
+
import { CommanderActionParams } from "../util.js";
|
|
4
|
+
declare const _default: {
|
|
5
|
+
Register: typeof Register;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function Register(cmd: Command, log: ILogLayer): Command<[string, string, string], {}, {}>;
|
|
9
|
+
export declare const Description: string;
|
|
10
|
+
type Exec = CommanderActionParams<ReturnType<typeof Register>>;
|
|
11
|
+
/**
|
|
12
|
+
* Action for the 'add' command. Adds a registry and handles errors.
|
|
13
|
+
* @param log Logging layer
|
|
14
|
+
*/
|
|
15
|
+
export declare function Action(log: ILogLayer): Exec;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { RegistryManager } from "@kumori/kdsl-lsp/module/registry/manager.js";
|
|
2
|
+
export default { Register };
|
|
3
|
+
export function Register(cmd, log) {
|
|
4
|
+
const c = cmd
|
|
5
|
+
.command("add")
|
|
6
|
+
.argument("<selector>", "Name selector for matching dependencies")
|
|
7
|
+
.argument("<version>", "Version of the registry specification. It is a git tag.")
|
|
8
|
+
.argument("<url>", "URL that contains the registry index for resolving modules")
|
|
9
|
+
.summary(Summary)
|
|
10
|
+
.description(Description)
|
|
11
|
+
.action(Action(log));
|
|
12
|
+
return c;
|
|
13
|
+
}
|
|
14
|
+
const Summary = `
|
|
15
|
+
add a new registry
|
|
16
|
+
`.trim();
|
|
17
|
+
export const Description = `
|
|
18
|
+
Add a registry to the resolver configuration. The selector argument is used to match artifacts.
|
|
19
|
+
For example, a registry with Index URL "https://github.com/kumori" and selector "kumori.systems" will
|
|
20
|
+
resolve dependencies starting with "kumori.systems", such as "kumori.systems/postgresql@1.0.0" to
|
|
21
|
+
"https://github.com/kumori/postregsql@1.0.0" to then download the requested artifacts.
|
|
22
|
+
|
|
23
|
+
In practice, at https://github.com/kumori there will be an index file that contains all the supported
|
|
24
|
+
modules and its versions. Each module entry will then contain the actual route to download the artifacts.
|
|
25
|
+
Since index files are stored in a git repository, versioning is supported via git tags.
|
|
26
|
+
|
|
27
|
+
Selectors do not have to be fully qualified domain names. They could be plain strings like "mycompany" to match.
|
|
28
|
+
The given selector will attempt to match the beginning of the requested dependency name.
|
|
29
|
+
|
|
30
|
+
kdsl registry add myreg https://github.com/mycompany my-selector
|
|
31
|
+
`.trim();
|
|
32
|
+
/**
|
|
33
|
+
* Action for the 'add' command. Adds a registry and handles errors.
|
|
34
|
+
* @param log Logging layer
|
|
35
|
+
*/
|
|
36
|
+
export function Action(log) {
|
|
37
|
+
return async (selector, version, url) => {
|
|
38
|
+
const manager = new RegistryManager();
|
|
39
|
+
const registry = {
|
|
40
|
+
selector: selector,
|
|
41
|
+
version: version,
|
|
42
|
+
indexUrl: url,
|
|
43
|
+
};
|
|
44
|
+
try {
|
|
45
|
+
manager.add(registry);
|
|
46
|
+
log.info(`Registry '${selector}' added at ${url}`);
|
|
47
|
+
}
|
|
48
|
+
catch (err) {
|
|
49
|
+
log.error(`Failed to add registry: ${err}`);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=add.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add.js","sourceRoot":"","sources":["../../src/registry/add.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AAE7E,eAAe,EAAE,QAAQ,EAAE,CAAA;AAC3B,MAAM,UAAU,QAAQ,CAAC,GAAY,EAAE,GAAc;IACnD,MAAM,CAAC,GAAG,GAAG;SACV,OAAO,CAAC,KAAK,CAAC;SACd,QAAQ,CAAC,YAAY,EAAE,yCAAyC,CAAC;SACjE,QAAQ,CACP,WAAW,EACX,yDAAyD,CAC1D;SACA,QAAQ,CACP,OAAO,EACP,4DAA4D,CAC7D;SACA,OAAO,CAAC,OAAO,CAAC;SAChB,WAAW,CAAC,WAAW,CAAC;SACxB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;IACtB,OAAO,CAAC,CAAA;AACV,CAAC;AAED,MAAM,OAAO,GAAG;;CAEf,CAAC,IAAI,EAAE,CAAA;AAER,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;CAc1B,CAAC,IAAI,EAAE,CAAA;AAGR;;;GAGG;AACH,MAAM,UAAU,MAAM,CAAC,GAAc;IACnC,OAAO,KAAK,EACV,QAAgB,EAChB,OAAe,EACf,GAAW,EACI,EAAE;QACjB,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;QAErC,MAAM,QAAQ,GAAG;YACf,QAAQ,EAAE,QAAQ;YAClB,OAAO,EAAE,OAAO;YAChB,QAAQ,EAAE,GAAG;SACd,CAAA;QAED,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACrB,GAAG,CAAC,IAAI,CAAC,aAAa,QAAQ,cAAc,GAAG,EAAE,CAAC,CAAA;QACpD,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,GAAG,CAAC,KAAK,CAAC,2BAA2B,GAAG,EAAE,CAAC,CAAA;QAC7C,CAAC;IACH,CAAC,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Command } from "@commander-js/extra-typings";
|
|
2
|
+
import { ILogLayer } from "loglayer";
|
|
3
|
+
import { CommanderActionParams } from "../util.js";
|
|
4
|
+
declare const _default: {
|
|
5
|
+
Register: typeof Register;
|
|
6
|
+
};
|
|
7
|
+
export default _default;
|
|
8
|
+
export declare function Register(cmd: Command, log: ILogLayer): Command<[], {}, {}>;
|
|
9
|
+
export declare const Description: string;
|
|
10
|
+
type Exec = CommanderActionParams<ReturnType<typeof Register>>;
|
|
11
|
+
/**
|
|
12
|
+
* Action for the 'list' command
|
|
13
|
+
* @param log Logging layer
|
|
14
|
+
*/
|
|
15
|
+
export declare function Action(log: ILogLayer): Exec;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { RegistryManager } from "@kumori/kdsl-lsp/module/registry/manager.js";
|
|
2
|
+
export default { Register };
|
|
3
|
+
export function Register(cmd, log) {
|
|
4
|
+
const c = cmd
|
|
5
|
+
.command("list")
|
|
6
|
+
.summary(Summary)
|
|
7
|
+
.description(Description)
|
|
8
|
+
.action(Action(log));
|
|
9
|
+
return c;
|
|
10
|
+
}
|
|
11
|
+
const Summary = `
|
|
12
|
+
list configured registries
|
|
13
|
+
`.trim();
|
|
14
|
+
export const Description = `
|
|
15
|
+
List all configured registries
|
|
16
|
+
`.trim();
|
|
17
|
+
/**
|
|
18
|
+
* Action for the 'list' command
|
|
19
|
+
* @param log Logging layer
|
|
20
|
+
*/
|
|
21
|
+
export function Action(log) {
|
|
22
|
+
return async () => {
|
|
23
|
+
const manager = new RegistryManager();
|
|
24
|
+
const registries = manager.list();
|
|
25
|
+
log.info("Configured Registries:");
|
|
26
|
+
console.log(JSON.stringify(registries, null, 2));
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=list.js.map
|