@kumori/kdsl 0.0.14 → 0.0.16

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 (171) hide show
  1. package/dist/build/deployment_spec.d.ts +2586 -0
  2. package/dist/build/deployment_spec.js +293 -0
  3. package/dist/build/deployment_spec.js.map +1 -0
  4. package/dist/build/helpers/builtin.d.ts +17 -0
  5. package/dist/build/helpers/builtin.js +80 -0
  6. package/dist/build/helpers/builtin.js.map +1 -0
  7. package/dist/build/helpers/component.d.ts +17 -0
  8. package/dist/build/helpers/component.js +212 -0
  9. package/dist/build/helpers/component.js.map +1 -0
  10. package/dist/build/helpers/connector.d.ts +13 -0
  11. package/dist/build/helpers/connector.js +189 -0
  12. package/dist/build/helpers/connector.js.map +1 -0
  13. package/dist/build/helpers/deployment.d.ts +326 -0
  14. package/dist/build/helpers/deployment.js +85 -0
  15. package/dist/build/helpers/deployment.js.map +1 -0
  16. package/dist/build/helpers/resource.d.ts +97 -0
  17. package/dist/build/helpers/resource.js +54 -0
  18. package/dist/build/helpers/resource.js.map +1 -0
  19. package/dist/build/helpers/service.d.ts +27 -0
  20. package/dist/build/helpers/service.js +196 -0
  21. package/dist/build/helpers/service.js.map +1 -0
  22. package/dist/build/helpers/utils.d.ts +30 -0
  23. package/dist/build/helpers/utils.js +77 -0
  24. package/dist/build/helpers/utils.js.map +1 -0
  25. package/dist/build/main.d.ts +17 -0
  26. package/dist/build/main.js +188 -0
  27. package/dist/build/main.js.map +1 -0
  28. package/dist/build/solution.d.ts +20 -0
  29. package/dist/build/solution.js +71 -0
  30. package/dist/build/solution.js.map +1 -0
  31. package/dist/check/main.d.ts +21 -0
  32. package/dist/check/main.js +99 -0
  33. package/dist/check/main.js.map +1 -0
  34. package/dist/clean/main.d.ts +11 -0
  35. package/dist/clean/main.js +26 -0
  36. package/dist/clean/main.js.map +1 -0
  37. package/dist/deployment/gen/deployment-template.kumori +33 -0
  38. package/dist/deployment/gen/main.d.ts +15 -0
  39. package/dist/deployment/gen/main.js +158 -0
  40. package/dist/deployment/gen/main.js.map +1 -0
  41. package/dist/deployment/gen/types.d.ts +27 -0
  42. package/dist/deployment/gen/types.js +2 -0
  43. package/dist/deployment/gen/types.js.map +1 -0
  44. package/dist/deployment/main.d.ts +8 -0
  45. package/dist/deployment/main.js +17 -0
  46. package/dist/deployment/main.js.map +1 -0
  47. package/dist/help/main.d.ts +13 -0
  48. package/dist/help/main.js +49 -0
  49. package/dist/help/main.js.map +1 -0
  50. package/dist/help/topic/build.d.ts +2 -0
  51. package/dist/help/topic/build.js +7 -0
  52. package/dist/help/topic/build.js.map +1 -0
  53. package/dist/help/topic/mod_dep.d.ts +2 -0
  54. package/dist/help/topic/mod_dep.js +8 -0
  55. package/dist/help/topic/mod_dep.js.map +1 -0
  56. package/dist/help/topic/mod_dl.d.ts +2 -0
  57. package/dist/help/topic/mod_dl.js +25 -0
  58. package/dist/help/topic/mod_dl.js.map +1 -0
  59. package/dist/index/create/main.d.ts +14 -0
  60. package/dist/index/create/main.js +286 -0
  61. package/dist/index/create/main.js.map +1 -0
  62. package/dist/index/main.d.ts +8 -0
  63. package/dist/index/main.js +17 -0
  64. package/dist/index/main.js.map +1 -0
  65. package/dist/lib/build.d.ts +42 -0
  66. package/dist/lib/build.js +42 -0
  67. package/dist/lib/build.js.map +1 -0
  68. package/dist/lib/check.d.ts +41 -0
  69. package/dist/lib/check.js +45 -0
  70. package/dist/lib/check.js.map +1 -0
  71. package/dist/lib/clean.d.ts +31 -0
  72. package/dist/lib/clean.js +39 -0
  73. package/dist/lib/clean.js.map +1 -0
  74. package/dist/lib/deployment.d.ts +35 -0
  75. package/dist/lib/deployment.js +31 -0
  76. package/dist/lib/deployment.js.map +1 -0
  77. package/dist/lib/index-cmd.d.ts +54 -0
  78. package/dist/lib/index-cmd.js +60 -0
  79. package/dist/lib/index-cmd.js.map +1 -0
  80. package/dist/lib/index.d.ts +58 -0
  81. package/dist/lib/index.js +54 -0
  82. package/dist/lib/index.js.map +1 -0
  83. package/dist/lib/io/lib.kumori +5 -0
  84. package/dist/lib/kumori/builtin/httpinbound.h.kumori +27 -0
  85. package/dist/lib/kumori/builtin/tcpinbound.h.kumori +25 -0
  86. package/dist/lib/kumori/builtin.kumori +18 -0
  87. package/dist/lib/kumori/component.kumori +120 -0
  88. package/dist/lib/kumori/deployment.kumori +16 -0
  89. package/dist/lib/kumori/resource.kumori +25 -0
  90. package/dist/lib/kumori/service.kumori +49 -0
  91. package/dist/lib/kumori/shared.kumori +11 -0
  92. package/dist/lib/kumori/sized.kumori +25 -0
  93. package/dist/lib/logger.d.ts +10 -0
  94. package/dist/lib/logger.js +23 -0
  95. package/dist/lib/logger.js.map +1 -0
  96. package/dist/lib/mod.d.ts +156 -0
  97. package/dist/lib/mod.js +144 -0
  98. package/dist/lib/mod.js.map +1 -0
  99. package/dist/lib/registry.d.ts +61 -0
  100. package/dist/lib/registry.js +67 -0
  101. package/dist/lib/registry.js.map +1 -0
  102. package/dist/lib/sized.kumori +8 -0
  103. package/dist/lib/std.kumori +8 -0
  104. package/dist/lib/strconv/lib.kumori +11 -0
  105. package/dist/lib/types.d.ts +26 -0
  106. package/dist/lib/types.js +2 -0
  107. package/dist/lib/types.js.map +1 -0
  108. package/dist/main.d.ts +1 -0
  109. package/dist/main.js +37 -0
  110. package/dist/main.js.map +1 -0
  111. package/dist/mod/checksum/main.d.ts +11 -0
  112. package/dist/mod/checksum/main.js +33 -0
  113. package/dist/mod/checksum/main.js.map +1 -0
  114. package/dist/mod/dependency/main.d.ts +19 -0
  115. package/dist/mod/dependency/main.js +163 -0
  116. package/dist/mod/dependency/main.js.map +1 -0
  117. package/dist/mod/download/functions.d.ts +53 -0
  118. package/dist/mod/download/functions.js +235 -0
  119. package/dist/mod/download/functions.js.map +1 -0
  120. package/dist/mod/download/main.d.ts +26 -0
  121. package/dist/mod/download/main.js +99 -0
  122. package/dist/mod/download/main.js.map +1 -0
  123. package/dist/mod/init/main.d.ts +13 -0
  124. package/dist/mod/init/main.js +66 -0
  125. package/dist/mod/init/main.js.map +1 -0
  126. package/dist/mod/jsonschema/gen/main.d.ts +11 -0
  127. package/dist/mod/jsonschema/gen/main.js +288 -0
  128. package/dist/mod/jsonschema/gen/main.js.map +1 -0
  129. package/dist/mod/jsonschema/get/kdslschema.d.ts +28 -0
  130. package/dist/mod/jsonschema/get/kdslschema.js +3 -0
  131. package/dist/mod/jsonschema/get/kdslschema.js.map +1 -0
  132. package/dist/mod/jsonschema/get/main.d.ts +76 -0
  133. package/dist/mod/jsonschema/get/main.js +346 -0
  134. package/dist/mod/jsonschema/get/main.js.map +1 -0
  135. package/dist/mod/jsonschema/main.d.ts +8 -0
  136. package/dist/mod/jsonschema/main.js +20 -0
  137. package/dist/mod/jsonschema/main.js.map +1 -0
  138. package/dist/mod/main.d.ts +8 -0
  139. package/dist/mod/main.js +27 -0
  140. package/dist/mod/main.js.map +1 -0
  141. package/dist/mod/update/main.d.ts +17 -0
  142. package/dist/mod/update/main.js +68 -0
  143. package/dist/mod/update/main.js.map +1 -0
  144. package/dist/registry/add.d.ts +15 -0
  145. package/dist/registry/add.js +58 -0
  146. package/dist/registry/add.js.map +1 -0
  147. package/dist/registry/list.d.ts +15 -0
  148. package/dist/registry/list.js +29 -0
  149. package/dist/registry/list.js.map +1 -0
  150. package/dist/registry/main.d.ts +8 -0
  151. package/dist/registry/main.js +21 -0
  152. package/dist/registry/main.js.map +1 -0
  153. package/dist/registry/remove.d.ts +15 -0
  154. package/dist/registry/remove.js +34 -0
  155. package/dist/registry/remove.js.map +1 -0
  156. package/dist/util/err-format.d.ts +2 -0
  157. package/dist/util/err-format.js +10 -0
  158. package/dist/util/err-format.js.map +1 -0
  159. package/dist/util/err-handler.d.ts +3 -0
  160. package/dist/util/err-handler.js +11 -0
  161. package/dist/util/err-handler.js.map +1 -0
  162. package/dist/util.d.ts +2 -0
  163. package/dist/util.js +2 -0
  164. package/dist/util.js.map +1 -0
  165. package/dist/version.d.ts +2 -0
  166. package/dist/version.js +5 -0
  167. package/dist/version.js.map +1 -0
  168. package/out/deployment/gen/deployment-template.kumori +33 -0
  169. package/out/deployment-template.kumori +33 -0
  170. package/out/main.cjs +378 -209
  171. package/package.json +67 -17
@@ -0,0 +1,66 @@
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("init")
11
+ .summary(Summary)
12
+ .argument("<name>", "module name (e.g., kumori.systems/my-module)")
13
+ .argument("<version>", "module version - defaults to 0.0.1")
14
+ .argument("[path]", "location to create the module under - defaults to the current directory")
15
+ .argument("[cacheLocation]", "location to store cached modules - default to .kumori/mod")
16
+ .description(Description)
17
+ .helpOption(true)
18
+ .action(Action(log));
19
+ return c;
20
+ }
21
+ const Summary = `initializes a new kumori module`;
22
+ export const Description = `
23
+ Initializes a new Kumori module, which effectively means to create a new
24
+ kumori.mod.json file or overwrite it in case it already exists.
25
+ It is required to provide a name and a version for the module and optionally
26
+ a location path where the new module is going to be initialized.
27
+
28
+ kdsl mod init kumori.systems/my-module
29
+
30
+ You could as well provide a custom location for the module's local cache,
31
+ where all the dependencies will be downloaded. By default, the cache location
32
+ is set to ".kumori/mod" under the module location.
33
+
34
+ kdsl mod init kumori.systems/my-module ./my-module
35
+
36
+ `.trim();
37
+ export function Action(log) {
38
+ return async (...args) => {
39
+ await NewModule(log, process.cwd(), ...args);
40
+ };
41
+ }
42
+ export const NewModule = async (log, cwd, ...[name, version, location, cacheLocation]) => {
43
+ const fs = NodeFileSystem.fileSystemProvider();
44
+ location = location ?? 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
+ const manifest = {
54
+ spec: "kumori/module/v1",
55
+ kumori: "0.0.1",
56
+ version: version,
57
+ module: name,
58
+ cacheLocation: cacheLocation,
59
+ requires: [],
60
+ };
61
+ const file = path.join(location, MOD_FILE);
62
+ await mkdir(location, { recursive: true });
63
+ await writeFile(file, JSON.stringify(manifest, null, 4));
64
+ log.info(`creating new ${MOD_FILE}: module ${name}`);
65
+ };
66
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../src/mod/init/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,MAAM,CAAC;SACf,OAAO,CAAC,OAAO,CAAC;SAChB,QAAQ,CAAC,QAAQ,EAAE,8CAA8C,CAAC;SAClE,QAAQ,CAAC,WAAW,EAAE,oCAAoC,CAAC;SAC3D,QAAQ,CACP,QAAQ,EACR,yEAAyE,CAC1E;SACA,QAAQ,CACP,iBAAiB,EACjB,2DAA2D,CAC5D;SACA,WAAW,CAAC,WAAW,CAAC;SACxB,UAAU,CAAC,IAAI,CAAC;SAChB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,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,IAAI;QACZ,aAAa,EAAE,aAAa;QAC5B,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,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAA;IACxD,GAAG,CAAC,IAAI,CAAC,gBAAgB,QAAQ,YAAY,IAAI,EAAE,CAAC,CAAA;AACtD,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { ILogLayer } from "loglayer";
2
+ import { CommanderActionParams } from "../../../util.js";
3
+ import { Command } from "@commander-js/extra-typings";
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, string, string], {}, {}>;
9
+ export declare const Description: string;
10
+ export type Exec = CommanderActionParams<ReturnType<typeof Register>>;
11
+ export declare function Action(log: ILogLayer): Exec;
@@ -0,0 +1,288 @@
1
+ var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
2
+ if (value !== null && value !== void 0) {
3
+ if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
4
+ var dispose, inner;
5
+ if (async) {
6
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
7
+ dispose = value[Symbol.asyncDispose];
8
+ }
9
+ if (dispose === void 0) {
10
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
11
+ dispose = value[Symbol.dispose];
12
+ if (async) inner = dispose;
13
+ }
14
+ if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
15
+ if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
16
+ env.stack.push({ value: value, dispose: dispose, async: async });
17
+ }
18
+ else if (async) {
19
+ env.stack.push({ async: true });
20
+ }
21
+ return value;
22
+ };
23
+ var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
24
+ return function (env) {
25
+ function fail(e) {
26
+ env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
27
+ env.hasError = true;
28
+ }
29
+ var r, s = 0;
30
+ function next() {
31
+ while (r = env.stack.pop()) {
32
+ try {
33
+ if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
34
+ if (r.dispose) {
35
+ var result = r.dispose.call(r.value);
36
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
37
+ }
38
+ else s |= 1;
39
+ }
40
+ catch (e) {
41
+ fail(e);
42
+ }
43
+ }
44
+ if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
45
+ if (env.hasError) throw env.error;
46
+ }
47
+ return next();
48
+ };
49
+ })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
50
+ var e = new Error(message);
51
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
+ });
53
+ import { Ajv } from "ajv";
54
+ import { readFile } from "node:fs/promises";
55
+ import { GetSchema, LocateModule } from "../get/main.js";
56
+ import { DefaultErrHandler } from "../../../util/err-handler.js";
57
+ import { createKumoriServices } from "@kumori/kdsl-lsp/language/kumori.js";
58
+ import { NodeFileSystem } from "langium/node";
59
+ import { Result } from "@kumori/kdsl-lsp/util/result.js";
60
+ import { ModuleContext } from "@kumori/kdsl-lsp/module/context.js";
61
+ import { Check } from "../../../check/main.js";
62
+ import { URI } from "langium";
63
+ import { MkdirTemp } from "@kumori/kdsl-lsp/util/tmp.js";
64
+ import assert from "node:assert";
65
+ import path from "node:path";
66
+ import fs from "node:fs/promises";
67
+ import { MOD_FILE } from "@kumori/kdsl-lsp/module/locator.js";
68
+ import { z } from "zod";
69
+ export default { Register };
70
+ export function Register(cmd, log) {
71
+ const c = cmd
72
+ .command("gen")
73
+ .summary(Summary)
74
+ .description(Description)
75
+ .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").`)
76
+ .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 ".".`)
77
+ .argument("<artifact-name>", `Name of the target artifact (e.g., "ExampleService").`)
78
+ .argument("<output-module-name>", `Name of the generated module (e.g., "example.com/my-org/module").`)
79
+ .argument("<json>", `Path to JSON file (TODO: use '-' to read from stdin).`)
80
+ .helpOption(true)
81
+ .action(Action(log));
82
+ return c;
83
+ }
84
+ // TODO: flag to build or generate module source files
85
+ const Summary = `generate deployments from an artifact jsonschema`;
86
+ export const Description = `
87
+ Creates a new Kumori DSL module and initializes a deployment definition within
88
+ it, structured according to a provided JSON Schema. This command is designed to
89
+ streamline the creation of new kmodules that consume or instantiate artifacts
90
+ whose configuration and resource requirements are already defined by a schema.
91
+ `.trim();
92
+ export function Action(log) {
93
+ return async (module, pkg, artifact, _outputName, data) => {
94
+ const env_1 = { stack: [], error: void 0, hasError: false };
95
+ try {
96
+ const svcs = createKumoriServices(NodeFileSystem).Kumori;
97
+ const ErrHandler = (v) => DefaultErrHandler(log, v);
98
+ const loc = ErrHandler(await LocateModule(module));
99
+ const _fs = svcs.shared.workspace.FileSystemProvider;
100
+ const ctx = ErrHandler(Result.mapErr(await ModuleContext(_fs, URI.file(loc.fsPath)), (err) => [
101
+ err,
102
+ ]));
103
+ // The module has been located, it has been downloaded and its context
104
+ // initialized. Now, let's download its dependencies.
105
+ ErrHandler(await Check(log, svcs, ctx));
106
+ // The module and its dependencies are now available. Get me the schema!
107
+ const Schema = ErrHandler(await GetSchema(svcs, ctx, pkg, artifact));
108
+ // TODO: interactive user input instead of file
109
+ // Parse the given file as JSON
110
+ const rawData = await readFile(data);
111
+ const Data = JSON.parse(rawData.toString("utf8"));
112
+ // Ajv is a library that will help us validate the incoming JSON file
113
+ // against the requested artifact's JSON Schema
114
+ const ajv = new Ajv({
115
+ validateSchema: false,
116
+ allErrors: true,
117
+ strict: false,
118
+ });
119
+ const v = ajv.compile(Schema);
120
+ const result = v(Data);
121
+ if (!result) {
122
+ const errs = v.errors ?? [];
123
+ errs.sort((a, b) => {
124
+ const schema = a.schemaPath.localeCompare(b.schemaPath);
125
+ if (schema != 0)
126
+ return schema;
127
+ const path = a.instancePath.localeCompare(b.instancePath);
128
+ return path;
129
+ });
130
+ console.log(JSON.stringify(v.errors, null, 4));
131
+ process.exit(1);
132
+ }
133
+ // TODO: if loc.$type is:
134
+ // - local: include the module under vendor
135
+ // - remote: just include the dependency
136
+ const dependency = (() => {
137
+ switch (loc.$type) {
138
+ case "local":
139
+ return { target: ctx.Current.Manifest.module, version: "0.0.0" };
140
+ case "remote":
141
+ return {
142
+ target: ctx.Current.Manifest.module,
143
+ version: loc.query.Version,
144
+ };
145
+ }
146
+ })();
147
+ // We will write everything first in a temporary directory and
148
+ // then move it to the current location
149
+ // Write kumori.mod.json
150
+ const tmp = __addDisposableResource(env_1, await MkdirTemp(), true);
151
+ const manifest = {
152
+ spec: "kumori/module/v1",
153
+ kumori: "0.0.1",
154
+ version: "0.0.1",
155
+ module: _outputName,
156
+ requires: [dependency],
157
+ };
158
+ const manifestFile = path.join(tmp.Path, MOD_FILE);
159
+ await fs.writeFile(manifestFile, JSON.stringify(manifest, null, 4));
160
+ // Write main.kumori
161
+ const imports = [
162
+ { Alias: "ImportAlias0", Path: path.join(dependency.target, pkg) },
163
+ ];
164
+ const deploymentParts = [];
165
+ const indent = 0;
166
+ const write = (str) => deploymentParts.push(str);
167
+ write("deployment {");
168
+ write("\n" + TAB);
169
+ write(`name "${_outputName}"`);
170
+ write("\n" + TAB);
171
+ write(`artifact ImportAlias0.${artifact}`);
172
+ write("\n" + TAB);
173
+ write(`resilience 0`);
174
+ write("\n" + TAB);
175
+ write(KumoriJSONToKumoriSyntax({ imports }, Data, indent + 1));
176
+ write("}\n");
177
+ const deploymentData = [
178
+ "import (\n" +
179
+ imports.map((s) => `${TAB}${s.Alias} "${s.Path}"`).join("\n") +
180
+ "\n)\n\n",
181
+ ]
182
+ .concat(deploymentParts)
183
+ .join("");
184
+ await fs.writeFile(path.join(tmp.Path, "main.kumori"), deploymentData);
185
+ await fs.cp(tmp.Path, ".", { recursive: true });
186
+ }
187
+ catch (e_1) {
188
+ env_1.error = e_1;
189
+ env_1.hasError = true;
190
+ }
191
+ finally {
192
+ const result_1 = __disposeResources(env_1);
193
+ if (result_1)
194
+ await result_1;
195
+ }
196
+ };
197
+ }
198
+ const kdslNamedType = z.object({
199
+ $kdsl: z.object({
200
+ NamedType: z.object({ Import: z.string(), Name: z.string() }),
201
+ }),
202
+ inner: z.any(),
203
+ });
204
+ const TAB = " ";
205
+ /**
206
+ *
207
+ * @param ctx List of imports
208
+ * @param data Input file as JSON
209
+ * @param indent
210
+ * @returns
211
+ */
212
+ function KumoriJSONToKumoriSyntax(ctx, data, indent = 0) {
213
+ const child = {
214
+ ...ctx,
215
+ parts: [],
216
+ skipScope: true,
217
+ };
218
+ KumoriJSONToKumoriSyntaxInternal(child, data, indent);
219
+ return child.parts.join("");
220
+ }
221
+ /**
222
+ * Parses each object and primitive from the input file (as a JSON)
223
+ * and writes the corresponding output in Kumori syntax
224
+ * @param ctx
225
+ * @param data Input file as JSON
226
+ * @param indent
227
+ * @returns
228
+ */
229
+ function KumoriJSONToKumoriSyntaxInternal(ctx, data, indent = 0) {
230
+ const write = (str) => ctx.parts.push(str);
231
+ // Process primitive values
232
+ switch (typeof data) {
233
+ case "number":
234
+ write(data.toString());
235
+ return;
236
+ case "string":
237
+ write(`"${data}"`);
238
+ return;
239
+ case "boolean":
240
+ write(data ? "true" : "false");
241
+ return;
242
+ }
243
+ // Only objects beyond this point
244
+ assert(typeof data === "object");
245
+ assert(data !== null);
246
+ const subCtx = { ...ctx, skipScope: false };
247
+ // Process special object definitions
248
+ const named = kdslNamedType.safeParse(data);
249
+ if (named.success) {
250
+ let existing = ctx.imports.find((imprt) => imprt.Path === named.data.$kdsl.NamedType.Import);
251
+ if (!existing) {
252
+ ctx.imports.push({
253
+ Path: named.data.$kdsl.NamedType.Import,
254
+ Alias: "ImportAlias" + ctx.imports.length,
255
+ });
256
+ }
257
+ existing = ctx.imports.find((imprt) => imprt.Path === named.data.$kdsl.NamedType.Import);
258
+ assert(existing);
259
+ write(`${existing.Alias}.${named.data.$kdsl.NamedType.Name}(`);
260
+ KumoriJSONToKumoriSyntaxInternal(subCtx, named.data.inner, indent);
261
+ write(")");
262
+ return;
263
+ }
264
+ // Process generic objects
265
+ const entries = Object.entries(data);
266
+ if (!ctx.skipScope) {
267
+ write(`{`);
268
+ if (entries.length) {
269
+ write(`\n${TAB.repeat(indent)}`);
270
+ }
271
+ }
272
+ while (entries.length > 0) {
273
+ const [key, value] = entries.pop();
274
+ write(`${key} `);
275
+ KumoriJSONToKumoriSyntaxInternal(subCtx, value, indent + 1);
276
+ if (entries.length) {
277
+ write(`\n${TAB.repeat(indent)}`);
278
+ }
279
+ else {
280
+ write(`\n${TAB.repeat(indent - 1)}`);
281
+ }
282
+ }
283
+ if (!ctx.skipScope) {
284
+ write(`}`);
285
+ }
286
+ return;
287
+ }
288
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.js","sourceRoot":"","sources":["../../../../src/mod/jsonschema/gen/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAG3C,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,EAAE,oBAAoB,E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ACnB,KAAK,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAClC,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,CAAA;QACtC,CAAC;IACH,CAAC;IACD,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC;QACnB,KAAK,CAAC,GAAG,CAAC,CAAA;IACZ,CAAC;IACD,OAAM;AACR,CAAC"}
@@ -0,0 +1,28 @@
1
+ export type KDSLSchemaV1 = {
2
+ $schema: "https://json-schema.org/draft/2020-12/schema";
3
+ $spec: "kumori/schema/v1";
4
+ $id: string;
5
+ } & KDSLSchemaV1Item;
6
+ export type KDSLSchemaV1Item = {} | {
7
+ type: "string";
8
+ } | {
9
+ type: "number";
10
+ } | {
11
+ type: "boolean";
12
+ } | {
13
+ type: "null";
14
+ } | {
15
+ type: "array";
16
+ items?: KDSLSchemaV1Item | KDSLSchemaV1Item[];
17
+ } | {
18
+ type: "object";
19
+ properties?: {
20
+ [k: string]: KDSLSchemaV1Item;
21
+ };
22
+ required?: string[];
23
+ additionalProperties?: KDSLSchemaV1Item;
24
+ } | {
25
+ const: string | number | boolean;
26
+ } | {
27
+ oneOf: KDSLSchemaV1Item[];
28
+ };
@@ -0,0 +1,3 @@
1
+ export {};
2
+ // TODO: Include more JSON Schema keywords like enum, anyOf, allOf, as necessary
3
+ //# sourceMappingURL=kdslschema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kdslschema.js","sourceRoot":"","sources":["../../../../src/mod/jsonschema/get/kdslschema.ts"],"names":[],"mappings":";AAgCA,gFAAgF"}
@@ -0,0 +1,76 @@
1
+ import { Command } from "@commander-js/extra-typings";
2
+ import { KumoriServices } from "@kumori/kdsl-lsp/language/kumori.js";
3
+ import { ModuleContext } from "@kumori/kdsl-lsp/module/context.js";
4
+ import { Query } from "@kumori/kdsl-lsp/module/query.js";
5
+ import { Result } from "@kumori/kdsl-lsp/util/result.js";
6
+ import { CommanderActionParams } from "../../../util.js";
7
+ import { ILogLayer } from "loglayer";
8
+ import { AstNodeType, TypeSystemError } from "@kumori/kdsl-lsp/language/type-system/type.js";
9
+ import { KDSLSchemaV1Item, KDSLSchemaV1 } from "./kdslschema.js";
10
+ declare const _default: {
11
+ Register: typeof Register;
12
+ };
13
+ export default _default;
14
+ export declare function Register(cmd: Command, log: ILogLayer): Command<[string, string, string], {}, {}>;
15
+ export declare const Description: string;
16
+ export type Exec = CommanderActionParams<ReturnType<typeof Register>>;
17
+ export declare function Action(log: ILogLayer): Exec;
18
+ /**
19
+ * Unique path of the kmodule where the artifact is defined. Accepts:
20
+ *
21
+ * - Remote targets (e.g., `"github.com/MyOrg/component@v1.2.3"`)
22
+ * - Local paths (e.g. `"/abs/path/to/module"`, `"../rel/path/to/module"`). **Relative paths MUST start with `'.'`**.
23
+ */
24
+ type ModuleNameOrPath = string;
25
+ type LocateModuleResult = LocalModule | RemoteModule;
26
+ type LocalModule = {
27
+ $type: "local";
28
+ fsPath: string;
29
+ };
30
+ type RemoteModule = {
31
+ $type: "remote";
32
+ fsPath: string;
33
+ query: Query;
34
+ };
35
+ /**
36
+ * Find the specified module. If it's not a locally-available module, download it
37
+ * into the global temporary directory
38
+ * @param module
39
+ * @returns Result
40
+ */
41
+ export declare function LocateModule(module: ModuleNameOrPath): Promise<Result<LocateModuleResult, string[]>>;
42
+ /**
43
+ * Given an artifact, returns its JSON Schema representation
44
+ * @param svcs
45
+ * @param ctx
46
+ * @param pkg
47
+ * @param artifact
48
+ * @returns
49
+ */
50
+ export declare function GetSchema(svcs: KumoriServices, ctx: ModuleContext, pkg: string, artifact: string): Promise<Result<KDSLSchemaV1, string[]>>;
51
+ /**
52
+ * Provides the JSON Schema representation of the given artifact
53
+ * @param svcs Kumori Services
54
+ * @param mod The context of the module
55
+ * @param node The artifact, as an AST node
56
+ * @param id Identifier to be used in the schema
57
+ * @returns JSON Schema
58
+ */
59
+ export declare function ToJSONSchema(svcs: KumoriServices, mod: ModuleContext, node: AstNodeType, id: string): Promise<Result<KDSLSchemaV1, TypeSystemError[]>>;
60
+ type ToJSONSchemaInternalCtx = {
61
+ svcs: KumoriServices;
62
+ mod: ModuleContext;
63
+ };
64
+ /**
65
+ * Converts a Kumori AST type node into a JSON Schema fragment (`KDSLSchemaV1Item`).
66
+ *
67
+ * This function recursively traverses the given `AstNodeType` and produces the
68
+ * corresponding JSON Schema representation. Each Kumori type maps to a JSON
69
+ * Schema construct.
70
+ *
71
+ * @param ctx Context providing access to services and the current module
72
+ * @param type The Kumori AST type node to translate
73
+ * @returns A `Result` containing either the JSON Schema fragment
74
+ * or a list of `TypeSystemError` if translation failed
75
+ */
76
+ export declare function ToJSONSchemaInternal(ctx: ToJSONSchemaInternalCtx, type: AstNodeType): Promise<Result<KDSLSchemaV1Item, TypeSystemError[]>>;