@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,25 @@
|
|
|
1
|
+
package kumori
|
|
2
|
+
|
|
3
|
+
library
|
|
4
|
+
|
|
5
|
+
alias Resource Volume | CA | Certificate | Secret | Domain | Port
|
|
6
|
+
|
|
7
|
+
type CA string
|
|
8
|
+
type Certificate string
|
|
9
|
+
type Secret string
|
|
10
|
+
type Domain string
|
|
11
|
+
type Port string
|
|
12
|
+
|
|
13
|
+
alias Volume Registered | InlineVolume | DeprecatedVolume
|
|
14
|
+
alias InlineVolume NonReplicated | Persisted | Volatile
|
|
15
|
+
|
|
16
|
+
type Registered string
|
|
17
|
+
type NonReplicated StorageSized
|
|
18
|
+
type Persisted StorageSized
|
|
19
|
+
type Volatile StorageSized
|
|
20
|
+
|
|
21
|
+
// NOTE: These are here to retain backwards compatibility.
|
|
22
|
+
// **Do not use.** Will be removed in the future.
|
|
23
|
+
alias DeprecatedVolume Ephemeral | Persistent
|
|
24
|
+
type Ephemeral StorageSized
|
|
25
|
+
type Persistent string
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package kumori
|
|
2
|
+
|
|
3
|
+
library
|
|
4
|
+
|
|
5
|
+
alias ServiceInterface struct {
|
|
6
|
+
srv? Links
|
|
7
|
+
config? struct open[]
|
|
8
|
+
resource? struct open[Resource]
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
alias service struct {
|
|
12
|
+
srv? Links
|
|
13
|
+
config? struct open[]
|
|
14
|
+
resource? struct open[Resource]
|
|
15
|
+
|
|
16
|
+
role? struct open[Role]
|
|
17
|
+
connect? struct open[Connection]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
alias Role struct {
|
|
21
|
+
artifact any // TODO: service, component or builtin
|
|
22
|
+
config? struct open[]
|
|
23
|
+
resource? struct open[Resource]
|
|
24
|
+
meta? struct open[]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
alias Connection LoadBalancer | FullConnector
|
|
28
|
+
|
|
29
|
+
type LoadBalancer struct {
|
|
30
|
+
from struct { target string, channel string } | []struct { target string, channel string }
|
|
31
|
+
to struct { target string, channel string } | []struct { target string, channel string }
|
|
32
|
+
|
|
33
|
+
meta? any
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type FullConnector ReducedFullConnector | CompleteFullConnector
|
|
37
|
+
|
|
38
|
+
alias ReducedFullConnector struct {
|
|
39
|
+
target string
|
|
40
|
+
channel string
|
|
41
|
+
meta? any
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
alias CompleteFullConnector struct {
|
|
45
|
+
from struct { target string, channel string } | []struct { target string, channel string }
|
|
46
|
+
to struct { target string, channel string } | []struct { target string, channel string }
|
|
47
|
+
|
|
48
|
+
meta? any
|
|
49
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
library
|
|
2
|
+
|
|
3
|
+
alias Links struct {
|
|
4
|
+
client? struct open[Client]
|
|
5
|
+
server? struct open[Server]
|
|
6
|
+
duplex? struct open[Server]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
alias Channel "udp" | "tcp" | "http" | "grpc"
|
|
10
|
+
alias Client Channel
|
|
11
|
+
alias Server Channel | struct { protocol Channel, port number }
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
library
|
|
2
|
+
|
|
3
|
+
alias StorageUnit "k" | "M" | "G" | "T" | "P" | "E" | "Ki" | "Mi" | "Gi" | "Ti" | "Pi" | "Ei"
|
|
4
|
+
alias StorageSized struct {
|
|
5
|
+
size number
|
|
6
|
+
unit StorageUnit
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
alias CPUUnit "m"
|
|
10
|
+
alias CPUSized struct {
|
|
11
|
+
size number
|
|
12
|
+
unit CPUUnit
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
alias RAMUnit "G" | "M" | "Gi" | "Mi"
|
|
16
|
+
alias RAMSized struct {
|
|
17
|
+
size number
|
|
18
|
+
unit RAMUnit
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
alias BandwidthUnit "G" | "M" | "Gi" | "Mi"
|
|
22
|
+
alias BandwidthSized struct {
|
|
23
|
+
size number
|
|
24
|
+
unit BandwidthUnit
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ILogLayer } from "loglayer";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a silent logger that discards all output.
|
|
4
|
+
* Used as default when no logger is provided to library functions.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createSilentLogger(): ILogLayer;
|
|
7
|
+
/**
|
|
8
|
+
* Gets a logger from options or returns silent logger.
|
|
9
|
+
*/
|
|
10
|
+
export declare function getLogger(logger?: ILogLayer): ILogLayer;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { LogLayer } from "loglayer";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a silent logger that discards all output.
|
|
4
|
+
* Used as default when no logger is provided to library functions.
|
|
5
|
+
*/
|
|
6
|
+
export function createSilentLogger() {
|
|
7
|
+
// Create a silent logger using a no-op transport
|
|
8
|
+
const noopTransport = {
|
|
9
|
+
debug: () => { },
|
|
10
|
+
info: () => { },
|
|
11
|
+
warn: () => { },
|
|
12
|
+
error: () => { },
|
|
13
|
+
};
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
return new LogLayer({ transport: noopTransport });
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Gets a logger from options or returns silent logger.
|
|
19
|
+
*/
|
|
20
|
+
export function getLogger(logger) {
|
|
21
|
+
return logger !== null && logger !== void 0 ? logger : createSilentLogger();
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/lib/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,QAAQ,EAAE,MAAM,UAAU,CAAA;AAE9C;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,iDAAiD;IACjD,MAAM,aAAa,GAAG;QACpB,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;QACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;QACd,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;KAChB,CAAA;IAED,8DAA8D;IAC9D,OAAO,IAAI,QAAQ,CAAC,EAAE,SAAS,EAAE,aAAoB,EAAE,CAAC,CAAA;AAC1D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,MAAkB;IAC1C,OAAO,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,kBAAkB,EAAE,CAAA;AACvC,CAAC"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { LibraryOptions, LibraryResult } from "./types.js";
|
|
2
|
+
import { KDSLSchemaV1 } from "../mod/jsonschema/get/kdslschema.js";
|
|
3
|
+
export interface ModuleInitOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Module name (e.g., kumori.systems/my-module)
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* Module version
|
|
10
|
+
*/
|
|
11
|
+
version: string;
|
|
12
|
+
/**
|
|
13
|
+
* Location to create the module under.
|
|
14
|
+
* Defaults to current directory.
|
|
15
|
+
*/
|
|
16
|
+
location?: string;
|
|
17
|
+
/**
|
|
18
|
+
* Location to store cached modules.
|
|
19
|
+
* Defaults to .kumori/mod
|
|
20
|
+
*/
|
|
21
|
+
cacheLocation?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Working directory. Defaults to process.cwd()
|
|
24
|
+
*/
|
|
25
|
+
cwd?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Optional logger for output.
|
|
28
|
+
*/
|
|
29
|
+
logger?: LibraryOptions["logger"];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Initialize a new Kumori module.
|
|
33
|
+
* Creates a new kumori.mod.json file.
|
|
34
|
+
*
|
|
35
|
+
* @param options - Module init options
|
|
36
|
+
* @returns Result with void on success, or string[] of errors
|
|
37
|
+
*/
|
|
38
|
+
export declare function moduleInit(options: ModuleInitOptions): Promise<LibraryResult<void>>;
|
|
39
|
+
export interface ModuleDependencyOptions extends LibraryOptions {
|
|
40
|
+
/**
|
|
41
|
+
* Module URL with @<tag> (e.g. github.com/org/repo@v1.2.3)
|
|
42
|
+
*/
|
|
43
|
+
module: string;
|
|
44
|
+
/**
|
|
45
|
+
* Alias for the dependency
|
|
46
|
+
*/
|
|
47
|
+
alias?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Specify a separate location for the headers module
|
|
50
|
+
*/
|
|
51
|
+
headers?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Remove the dependency
|
|
54
|
+
*/
|
|
55
|
+
remove?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Download the dependency after adding it
|
|
58
|
+
*/
|
|
59
|
+
download?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Add, update, or remove a dependency from the module declaration.
|
|
63
|
+
*
|
|
64
|
+
* @param options - Module dependency options
|
|
65
|
+
* @returns Result with void on success, or string[] of errors
|
|
66
|
+
*/
|
|
67
|
+
export declare function moduleDependency(options: ModuleDependencyOptions): Promise<LibraryResult<void>>;
|
|
68
|
+
export interface ModuleDownloadOptions extends LibraryOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Modules to download. If not specified, downloads all dependencies
|
|
71
|
+
* of the current module.
|
|
72
|
+
*/
|
|
73
|
+
modules?: string[];
|
|
74
|
+
/**
|
|
75
|
+
* Do not log warnings
|
|
76
|
+
*/
|
|
77
|
+
quiet?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Download modules to local cache.
|
|
81
|
+
* With no arguments, downloads all modules needed to build the packages
|
|
82
|
+
* in the current module.
|
|
83
|
+
*
|
|
84
|
+
* @param options - Module download options
|
|
85
|
+
* @returns Result with void on success, or string[] of errors
|
|
86
|
+
*/
|
|
87
|
+
export declare function moduleDownload(options: ModuleDownloadOptions): Promise<LibraryResult<void>>;
|
|
88
|
+
export interface ModuleUpdateOptions {
|
|
89
|
+
/**
|
|
90
|
+
* New module version
|
|
91
|
+
*/
|
|
92
|
+
version?: string;
|
|
93
|
+
/**
|
|
94
|
+
* New cache location
|
|
95
|
+
*/
|
|
96
|
+
cacheLocation?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Location where the module to update is located.
|
|
99
|
+
* Defaults to current directory.
|
|
100
|
+
*/
|
|
101
|
+
path?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Working directory. Defaults to process.cwd()
|
|
104
|
+
*/
|
|
105
|
+
cwd?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Optional logger for output.
|
|
108
|
+
*/
|
|
109
|
+
logger?: LibraryOptions["logger"];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Update an existing Kumori module's version or cache location.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Module update options
|
|
115
|
+
* @returns Result with void on success, or string[] of errors
|
|
116
|
+
*/
|
|
117
|
+
export declare function moduleUpdate(options: ModuleUpdateOptions): Promise<LibraryResult<void>>;
|
|
118
|
+
export interface ModuleChecksumOptions extends LibraryOptions {
|
|
119
|
+
/**
|
|
120
|
+
* Directory containing the module.
|
|
121
|
+
* Defaults to cwd or '.'
|
|
122
|
+
*/
|
|
123
|
+
directory?: string;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Generate SHA-256 checksum for a module.
|
|
127
|
+
*
|
|
128
|
+
* @param options - Module checksum options
|
|
129
|
+
* @returns Result with checksum string on success, or string[] of errors
|
|
130
|
+
*/
|
|
131
|
+
export declare function moduleChecksum(options: ModuleChecksumOptions): Promise<LibraryResult<string>>;
|
|
132
|
+
export interface ModuleSchemaGetOptions extends LibraryOptions {
|
|
133
|
+
/**
|
|
134
|
+
* Unique path of the module where the artifact is defined.
|
|
135
|
+
* Accepts remote targets (e.g., "github.com/MyOrg/component@v1.2.3")
|
|
136
|
+
* or local paths (e.g. "/abs/path/to/module", "../rel/path/to/module").
|
|
137
|
+
*/
|
|
138
|
+
target: string;
|
|
139
|
+
/**
|
|
140
|
+
* Relative path to the package that contains the artifact
|
|
141
|
+
* (e.g., "internal/service"). For artifacts in the module's root package, use ".".
|
|
142
|
+
*/
|
|
143
|
+
packagePath: string;
|
|
144
|
+
/**
|
|
145
|
+
* Name of the target artifact (e.g., "ExampleService").
|
|
146
|
+
*/
|
|
147
|
+
artifactName: string;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Extract JSON Schema for a specified module and artifact.
|
|
151
|
+
* Generates and outputs the JSON Schema that describes a particular Kumori DSL artifact.
|
|
152
|
+
*
|
|
153
|
+
* @param options - Module schema get options
|
|
154
|
+
* @returns Result with schema object on success, or string[] of errors
|
|
155
|
+
*/
|
|
156
|
+
export declare function moduleSchemaGet(options: ModuleSchemaGetOptions): Promise<LibraryResult<KDSLSchemaV1>>;
|
package/dist/lib/mod.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var de=Object.defineProperty,bt=Object.defineProperties;var St=Object.getOwnPropertyDescriptors;var le=Object.getOwnPropertySymbols;var Pt=Object.prototype.hasOwnProperty,Ct=Object.prototype.propertyIsEnumerable;var ue=(t,e)=>(e=Symbol[t])?e:Symbol.for("Symbol."+t);var H=(t,e,r)=>e in t?de(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,f=(t,e)=>{for(var r in e||(e={}))Pt.call(e,r)&&H(t,r,e[r]);if(le)for(var r of le(e))Ct.call(e,r)&&H(t,r,e[r]);return t},y=(t,e)=>bt(t,St(e));var k=(t,e)=>()=>(t&&(e=t(t=0)),e);var R=(t,e)=>{for(var r in e)de(t,r,{get:e[r],enumerable:!0})};var w=(t,e,r)=>(H(t,typeof e!="symbol"?e+"":e,r),r);var ce=(t,e,r)=>{if(e!=null){if(typeof e!="object"&&typeof e!="function")throw TypeError("Object expected");var o;if(r&&(o=e[ue("asyncDispose")]),o===void 0&&(o=e[ue("dispose")]),typeof o!="function")throw TypeError("Object not disposable");t.push([r,o,e])}else r&&t.push([r]);return e},me=(t,e,r)=>{var o=typeof SuppressedError=="function"?SuppressedError:function(n,s,l,d){return d=Error(l),d.name="SuppressedError",d.error=n,d.suppressed=s,d},i=n=>e=r?new o(n,e,"An error was suppressed during disposal"):(r=!0,n),a=n=>{for(;n=t.pop();)try{var s=n[1]&&n[1].call(n[2]);if(n[0])return Promise.resolve(s).then(a,l=>(i(l),a()))}catch(l){i(l)}if(r)throw e};return a()};var Se={};R(Se,{Action:()=>xe,Description:()=>Me,NewModule:()=>be,Register:()=>Le,default:()=>$t});import{Maybe as kt}from"@kumori/kdsl-lsp/util/maybe.js";import{mkdir as Et,writeFile as Ot}from"fs/promises";import{URI as Rt}from"langium";import{NodeFileSystem as _t}from"langium/node";import{LocateModuleManifest as Ft,MOD_FILE as ye}from"@kumori/kdsl-lsp/module/locator.js";import W from"path";function Le(t,e){return t.command("init").summary(It).argument("<name>","module name (e.g., kumori.systems/my-module)").argument("<version>","module version - defaults to 0.0.1").argument("[path]","location to create the module under - defaults to the current directory").argument("[cacheLocation]","location to store cached modules - default to .kumori/mod").description(Me).helpOption(!0).action(xe(e))}function xe(t){return async(...e)=>{await be(t,process.cwd(),...e)}}var $t,It,Me,be,Pe=k(()=>{"use strict";$t={Register:Le};It="initializes a new kumori module",Me=`
|
|
2
|
+
Initializes a new Kumori module, which effectively means to create a new
|
|
3
|
+
kumori.mod.json file or overwrite it in case it already exists.
|
|
4
|
+
It is required to provide a name and a version for the module and optionally
|
|
5
|
+
a location path where the new module is going to be initialized.
|
|
6
|
+
|
|
7
|
+
kdsl mod init kumori.systems/my-module
|
|
8
|
+
|
|
9
|
+
You could as well provide a custom location for the module's local cache,
|
|
10
|
+
where all the dependencies will be downloaded. By default, the cache location
|
|
11
|
+
is set to ".kumori/mod" under the module location.
|
|
12
|
+
|
|
13
|
+
kdsl mod init kumori.systems/my-module ./my-module
|
|
14
|
+
|
|
15
|
+
`.trim();be=async(t,e,...[r,o,i,a])=>{let n=_t.fileSystemProvider();i=i!=null?i:e,W.isAbsolute(i)||(i=W.join(e,i));let s=await Ft(n,Rt.file(i));kt.isSome(s)&&s.value.fsPath===i&&(t.error(`error: module ${i} already exists`),process.exit(1));let l={spec:"kumori/module/v1",kumori:"0.0.1",version:o,module:r,cacheLocation:a,requires:[]},d=W.join(i,ye);await Et(i,{recursive:!0}),await Ot(d,JSON.stringify(l,null,4)),t.info(`creating new ${ye}: module ${r}`)}});import{Result as Nt}from"@kumori/kdsl-lsp/util/result.js";function F(t,e){if(Nt.isErr(e)){for(let r of e.err)t.error(r);process.exit(1)}return e.value}var K=k(()=>{"use strict"});import{ParseQuery as Te}from"@kumori/kdsl-lsp/module/query.js";import{Maybe as V,None as At,Some as Bt}from"@kumori/kdsl-lsp/util/maybe.js";import{Err as D,Ok as Y,Result as E}from"@kumori/kdsl-lsp/util/result.js";import{Version as Ce}from"@kumori/kdsl-lsp/module/version.js";import{ListDependencies as jt}from"@kumori/kdsl-lsp/module/dependency/list.js";import X from"assert";import{LocateDependency as ke}from"@kumori/kdsl-lsp/module/dependency/locate.js";import{ModuleContext as qt}from"@kumori/kdsl-lsp/module/context.js";import{MkdirTemp as Kt}from"@kumori/kdsl-lsp/util/tmp.js";import{ValidateChecksum as Vt}from"@kumori/kdsl-lsp/module/integrity/validate.js";import{URI as Ut,UriUtils as Jt}from"langium";import{mkdir as zt,rename as Gt,rm as Qt}from"fs/promises";import{ForURL as Ht}from"@kumori/kdsl-lsp/module/remote/factory.js";import{SemVer as De}from"@kumori/kdsl-lsp/util/semver.js";import{URL as Wt}from"@kumori/kdsl-lsp/util/url.js";import{DependencyId as Ee}from"@kumori/kdsl-lsp/module/dependency/id.js";async function Oe(t){let e=new Map;return await _e(t,e),e}async function Re(t,e){let r=new Map;console.log(e);for(let o of e){let i=Te(o);if(V.isNone(i)){let l=`invalid download query '${o}': failed to parse`;r.set(o,y(f({},D(l)),{required:!0}));continue}let a=Ce(i.value.Version);if(V.isNone(a)){let l=`invalid download query '${o}': invalid version specifier '${i.value.Version}': failed to parse`;r.set(o,y(f({},D(l)),{required:!0}));continue}if(!Ce.isSemVer(a.value)){let l=`invalid download query '${o}': invalid version specifier '${i.value.Version}': invalid semver`;r.set(o,y(f({},D(l)),{required:!0}));continue}let n=`${i.value.Scheme}://${i.value.Location}`,s=i.value.Version;await Fe(t,n,s,r)}return r}async function _e(t,e){var o;let r=jt(t.Current);for(let i of r.keys()){let a=r.get(i);if(a.length<1)continue;let{target:n,version:s}=a[0];await Fe(t,n,s,e);let l=a.reduce((u,c)=>u||c.interface===void 0,!1),d=Ee(n,s);X(e.has(d)),(o=e.get(d)).required||(o.required=l)}}async function Fe(t,e,r,o){let i=Ee(e,r);if(o.has(i))return;let a=await Yt(t,e,r);if(o.set(i,y(f({},a),{required:!1})),E.isErr(a))return;let n=await ke(t,e,r);X(V.isSome(n));let s=await qt.Move(t,t.FS,n.value.Root);X(E.isOk(s)),t=f(f({},t),s.value),await _e(t,o)}async function Yt(t,e,r){var d=[];try{let o=await ke(t,e,r);if(E.isOk(o))return Y(At);let i=ce(d,await Kt(),!0);let a=await Z(t,e,r,i.Path);if(E.isErr(a))return D(`failed to fetch ${e}@${r}: ${a.err}`);let n=await Vt(t.SumDB,Ut.file(i.Path),t,e,a.value);if(E.isErr(n))return n;let s=`${e}@${r}`;let l=Jt.joinPath(t.Locations.Cache(),s);await zt(l.fsPath,{recursive:!0});await Qt(l.fsPath,{recursive:!0,force:!0});await Gt(i.Path,l.fsPath);return Y(Bt(s))}catch(u){var c=u,g=!0}finally{var v=me(d,c,g);v&&await v}}async function Z(t,e,r,o){let i=`${e}@${r}`,a=Te(i);if(V.isNone(a))return D(`failed to resolve ${i}: invalid download query`);let n=De(a.value.Version),s=new Wt(`${a.value.Scheme}://${a.value.Location}`),l=Ht(t.Remotes,s);if(E.isErr(l))return D(`failed to resolve ${i}': invalid remote ${s}: ${l.err}`);let d=await l.value.Versions(s);if(E.isErr(d))return D(`failed to read ${s}: ${d.err}`);let u=n,c=d.value.filter(h=>De.Compare(h,u)===0);if(c.length===0)return D(`no remote matches for ${s}@v${n}`);if(c.length>1){let h=`[${c.map(String).join(", ")}]`;return D(`ambiguous match for ${s}@v${n}: found ${h}`)}let g=c[0],v=await l.value.Get(s,g.toString(),o);return E.isErr(v)?D(`failed to fetch ${s}@${n.toString()}: ${v.err}`):Y(g)}var ee=k(()=>{"use strict"});var je={};R(je,{Action:()=>Be,Description:()=>Ae,Download:()=>O,Register:()=>Ne,default:()=>ar});import{ModuleContext as Xt}from"@kumori/kdsl-lsp/module/context.js";import{SumDB as Zt}from"@kumori/kdsl-lsp/module/integrity/sumdb.js";import{RemoteFetcherFactory as $e}from"@kumori/kdsl-lsp/module/remote/factory.js";import{Maybe as er}from"@kumori/kdsl-lsp/util/maybe.js";import{Err as Ie,Ok as tr,Result as A}from"@kumori/kdsl-lsp/util/result.js";import{URI as rr}from"langium";import{NodeFileSystem as or}from"langium/node";import{createKumoriServices as ir}from"@kumori/kdsl-lsp/language/kumori.js";import{RegistryManager as nr}from"@kumori/kdsl-lsp/module/registry/manager.js";function Ne(t,e){return t.command("download").alias("dl").summary(sr).argument("[module...]").option("-q, --quiet","do not log warnings").description(Ae).helpOption(!0).action(Be(e))}function Be(t){let e=ir(or).Kumori,r=o=>F(t,o);return async(o,i)=>{await new nr().ensureIndexes(),r(await O(t,e,process.cwd(),o,i))}}var ar,sr,Ae,O,U=k(()=>{"use strict";K();ee();ar={Register:Ne};sr="download modules to local cache",Ae=`
|
|
16
|
+
Downloads the specified modules, which can be module patterns selecting depen-
|
|
17
|
+
dencies of the current module or module queries of the form path@version.
|
|
18
|
+
|
|
19
|
+
With no arguments, download applies to the modules needed to build the packages
|
|
20
|
+
in the current module.
|
|
21
|
+
|
|
22
|
+
The kdsl command will automatically download modules as needed during ordinary
|
|
23
|
+
execution. The "kdsl mod download" command is useful mainly for pre-filling the
|
|
24
|
+
local cache.
|
|
25
|
+
|
|
26
|
+
By default, download writes nothing to standard output. It may print progress
|
|
27
|
+
messages and errors to standard error.
|
|
28
|
+
`.trim();O=async(t,e,r,o,i)=>{let a=e.shared.workspace.FileSystemProvider,n=await Xt(a,rr.file(r));if(A.isErr(n))return Ie([n.err]);let s=await Zt.Open(n.value.Locations.Checksum());if(A.isErr(s))return A.mapErr(s,c=>[c]);let l;o.length?l=await Re(y(f({},n.value),{FS:a,Remotes:$e(),SumDB:s.value}),o):l=await Oe(y(f({},n.value),{FS:a,Remotes:$e(),SumDB:s.value}));let d=[];for(let[c,g]of l){if(A.isOk(g)){er.isSome(g.value)&&t.info(`Downloaded dependency ${c}`);continue}g.required?d.push(`${c}: ${g.err}`):i.quiet||(t.warn(`${c}: ${g.err}`),t.warn(`${c}: not required - continuing`))}return Array.from(l.entries()).filter(([,c])=>A.isErr(c)&&c.required).length>0?Ie(d):tr(void 0)}});var ze={};R(ze,{Action:()=>Ue,Dependency:()=>Je,Description:()=>Ke,Register:()=>Ve,default:()=>fr});import{URI as lr,UriUtils as te}from"langium";import{createKumoriServices as ur}from"@kumori/kdsl-lsp/language/kumori.js";import{NodeFileSystem as dr}from"langium/node";import{Result as B}from"@kumori/kdsl-lsp/util/result.js";import{ModuleContext as cr}from"@kumori/kdsl-lsp/module/context.js";import{writeFile as re}from"fs/promises";import{MOD_FILE as oe}from"@kumori/kdsl-lsp/module/locator.js";import{ParseQuery as qe}from"@kumori/kdsl-lsp/module/query.js";import{RegistryManager as mr}from"@kumori/kdsl-lsp/module/registry/manager.js";function Ve(t,e){return t.command("dependency").alias("dep").argument("<module>","Module URL with @<tag> (e.g. https://github.com/org/repo@v1.2.3)").option("--alias <alias>","Alias for the dependency").option("--headers <module>","Specify a separate location for the headers module").option("--remove","Remove the dependency").option("--download","Download the dependency after adding it").summary(gr).description(Ke).helpOption(!0).showHelpAfterError(!0).action(Ue(e))}function Ue(t){return async(e,r)=>{await new mr().ensureIndexes();try{await Je(t,lr.file(process.cwd()),e,r)}catch(i){throw t.error(`Failed to manage dependency: ${i}`),i}}}var gr,Ke,fr,Je,Ge=k(()=>{"use strict";U();gr="Add, update, or remove a dependency from the module declaration",Ke=`
|
|
29
|
+
Manage dependencies within the current module. It can add, update
|
|
30
|
+
or remove dependencies. Optionally, it can attempt to download the dependency after adding it.
|
|
31
|
+
Dependencies should resolve to a git repository.
|
|
32
|
+
|
|
33
|
+
To add a dependency:
|
|
34
|
+
kdsl mod dep github.com/org/repo@v1.0.0
|
|
35
|
+
|
|
36
|
+
To add a dependency with an alias:
|
|
37
|
+
kdsl mod dep github.com/org/repo@v1.0.0 --alias mydep
|
|
38
|
+
|
|
39
|
+
To update a dependency to a new version:
|
|
40
|
+
kdsl mod dep github.com/org/repo@v1.2.0
|
|
41
|
+
|
|
42
|
+
To remove a dependency:
|
|
43
|
+
kdsl mod dep github.com/org/repo --remove
|
|
44
|
+
|
|
45
|
+
To add a dependency and download it immediately:
|
|
46
|
+
kdsl mod dep github.com/org/repo@v1.0.0 --download
|
|
47
|
+
`.trim(),fr={Register:Ve};Je=async(t,e,r,o)=>{let i=ur(dr).Kumori,a=i.shared.workspace.FileSystemProvider,n=await cr(a,e);if(B.isErr(n))throw new Error(n.err);let s=n.value.Current.Manifest,l=qe(r);if(B.isErr(l))throw new Error(`invalid query '${r}': invalid format`);let d=null;if(o.headers&&(d=qe(o.headers),B.isErr(d)))throw new Error(`invalid query '${o.headers}': invalid format`);let u=d?d.value:null,c=l.value;c.Location.endsWith("/")&&(c.Location=c.Location.replace(/\/+$/,""));let g=o.alias;if(o.remove){let p=s.requires.findIndex(L=>L.target===c.Location&&L.version===c.Version);if(p===-1)throw new Error(`Dependency ${c} not found`);s.requires.splice(p,1),await re(te.joinPath(n.value.Current.Root,oe).fsPath,JSON.stringify(s,void 0,4)),t.info(`Removed dependency ${c.toString()}`);return}if(g&&s.requires.some(p=>p.alias===g&&p.target!==c.Location))throw new Error(`Alias '${g}' is already used by another dependency`);let h=s.requires.find(p=>p.target===c.Location);if(h){if(g?h.alias=g:delete h.alias,u&&(h.headers={target:u.Location,version:u.Version}),await re(te.joinPath(n.value.Current.Root,oe).fsPath,JSON.stringify(s,void 0,4)),o.download){let p=await O(t,i,e.fsPath,[],{quiet:!0});if(B.isErr(p))throw new Error(`Failed to download dependency: ${p.err.join(", ")}`)}t.info(`Updated dependency ${c.Location} to version ${c.Version}`+(g?` (alias: ${g})`:"")+(u?` (headers: ${u})`:""))}else{let p=c.Version,L=f(f({target:c.Location,version:p},g?{alias:g}:{}),u?{headers:{target:u.Location,version:u.Version}}:{});if(s.requires.push(L),await re(te.joinPath(n.value.Current.Root,oe).fsPath,JSON.stringify(s,void 0,4)),o.download){let P=await O(t,i,e.fsPath,[],{quiet:!0});if(B.isErr(P))throw new Error(`Failed to download dependency: ${P.err.join(", ")}`)}t.info(`Added dependency ${c.toString()}`+(g?` (alias: ${g})`:"")+(u?` (headers: ${u})`:"")+" to module manifest")}}});var Ze={};R(Ze,{Action:()=>Ye,Description:()=>We,NewModule:()=>Xe,Register:()=>He,default:()=>Lr});import{Maybe as hr}from"@kumori/kdsl-lsp/util/maybe.js";import{mkdir as pr,writeFile as wr}from"fs/promises";import{URI as Qe}from"langium";import{NodeFileSystem as vr}from"langium/node";import{LocateModuleManifest as yr,MOD_FILE as ie}from"@kumori/kdsl-lsp/module/locator.js";import J from"path";function He(t,e){return t.command("update").summary(Mr).option("-v, --version <version>","new module version").option("-p, --path <location>","location where the module to update is located - defaults to the current directory").option("-c, --cacheLocation <cacheLocation>","new cache location").description(We).helpOption(!0).action(Ye(e))}function Ye(t){return async e=>{await Xe(t,process.cwd(),e)}}var Lr,Mr,We,Xe,et=k(()=>{"use strict";Lr={Register:He};Mr="updates an existing kumori module's version or cache location",We=`
|
|
48
|
+
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
|
|
49
|
+
a new cache location for the module.
|
|
50
|
+
|
|
51
|
+
kdsl mod update -v 1.0.0
|
|
52
|
+
|
|
53
|
+
You could as well provide a new location for the module's local cache,
|
|
54
|
+
where all the dependencies will be downloaded.
|
|
55
|
+
|
|
56
|
+
kdsl mod update -v 1.0.0 -c ./my-mod-cache
|
|
57
|
+
|
|
58
|
+
If the module is not located in the current directory, you can provide a custom location path.
|
|
59
|
+
|
|
60
|
+
kdsl mod update -v 1.0.0 -p ./my-module
|
|
61
|
+
`.trim();Xe=async(t,e,r)=>{var u,c,g;let o=vr.fileSystemProvider(),i=(u=r.path)!=null?u:e;J.isAbsolute(i)||(i=J.join(e,i));let a=await yr(o,Qe.file(i));hr.isSome(a)&&a.value.fsPath===i&&(t.error(`error: module ${i} already exists`),process.exit(1));let n=await o.readFile(Qe.file(J.join(i,ie))),s=JSON.parse(n),l={spec:"kumori/module/v1",kumori:"0.0.1",version:(c=r.version)!=null?c:s.version,module:s.module,cacheLocation:(g=r.cacheLocation)!=null?g:s.cacheLocation,requires:[]},d=J.join(i,ie);await pr(i,{recursive:!0}),await wr(d,JSON.stringify(l,null,4)),t.info(`updated ${ie}: module ${l.module}`)}});var at={};R(at,{Action:()=>it,Check:()=>z,RawCheck:()=>nt,Register:()=>ot,default:()=>_r});import{createKumoriServices as xr}from"@kumori/kdsl-lsp/language/kumori.js";import{URI as br,UriUtils as ae}from"langium";import{NodeFileSystem as Sr}from"langium/node";import{DiagnosticSeverity as tt}from"vscode-languageserver";import{Err as ne,Ok as rt,Result as j}from"@kumori/kdsl-lsp/util/result.js";import{ModuleContext as Pr}from"@kumori/kdsl-lsp/module/context.js";import Cr from"path";import{RegistryManager as Dr}from"@kumori/kdsl-lsp/module/registry/manager.js";function ot(t,e){return t.command("check").argument("[directory]","directory containing a Kumori module").description(kr).summary(Tr).action(it(e))}function it(t){return async e=>{await new Dr().ensureIndexes();let o=xr(Sr).Kumori,i=o.shared.workspace.FileSystemProvider,a=s=>F(t,s),n=a(j.mapErr(await Pr(i,br.file(Cr.resolve(e!=null?e:"."))),s=>[s]));a(await z(t,o,n))}}function Er(t,e){return`lexer error: ${ae.relative(process.cwd(),t.uri.fsPath)}:${e.line||1}:${e.column||1}: ${e.message}`}function Or(t,e){return`parser error: ${ae.relative(process.cwd(),t.uri.fsPath)}:${e.token.startLine||1}:${e.token.startColumn||1}: ${e.message}`}function Rr(t,e){return`diagnostic error: ${ae.relative(process.cwd(),t.uri.fsPath)}:${e.range.start.line+1}:${e.range.start.character+1}: ${e.message}`}var Tr,kr,z,nt,_r,se=k(()=>{"use strict";U();K();Tr="typecheck and validate a module",kr=`
|
|
62
|
+
`.trim();z=async(t,e,r)=>{let o=r.Current.Root,i=await O(t,e,o.fsPath,[],{quiet:!0});if(j.isErr(i))return i;let a=await nt(e,r);if(j.isErr(a)){let n=a.err.warnings.concat(a.err.errors);return ne(n)}return rt(void 0)},nt=async(t,e)=>{let r={errors:[],warnings:[]},o=t.shared.workspace.FileSystemProvider,i=e.Current.Root,a=await j.tryCatchAsync(()=>o.readDirectory(i));if(j.isErr(a)){let d=""+a.err;return a.err instanceof Error&&(d=a.err.message),r.errors.push(`failed to read directory '${i.fsPath}': ${d}`),ne(r)}await t.shared.workspace.WorkspaceManager.initializeWorkspace([{name:"root",uri:i.toString()}]);let s=t.shared.workspace.LangiumDocuments;await t.shared.workspace.DocumentBuilder.build(s.all.toArray(),{validation:!0});for(let d of t.shared.workspace.LangiumDocuments.all){for(let u of d.parseResult.lexerErrors)r.errors.push(Er(d,u));for(let u of d.parseResult.parserErrors)r.errors.push(Or(d,u));for(let u of d.diagnostics||[]){let c=Rr(d,u);u.severity===tt.Error&&r.errors.push(c),u.severity===tt.Warning&&r.warnings.push(c)}}return r.errors.length>0?ne(r):rt(void 0)};_r={Register:ot}});import{AstUtils as Fr,UriUtils as $r}from"langium";function st(t){var o,i;let e=(i=(o=t.node.$cstNode)==null?void 0:o.range)!=null?i:{start:{line:-1,character:-1},end:{line:-1,character:-1}},r=Fr.getDocument(t.node);return`${$r.relative(process.cwd(),r.uri.fsPath)}:${e.start.line+1}:${e.start.character+1}: ${t.message}`}var lt=k(()=>{"use strict"});var Mt={};R(Mt,{Action:()=>wt,Description:()=>pt,GetSchema:()=>yt,LocateModule:()=>vt,Register:()=>ht,ToJSONSchema:()=>Lt,ToJSONSchemaInternal:()=>T,default:()=>so});import{createKumoriServices as Ir}from"@kumori/kdsl-lsp/language/kumori.js";import{ModuleContext as Nr}from"@kumori/kdsl-lsp/module/context.js";import{ParseQuery as Ar}from"@kumori/kdsl-lsp/module/query.js";import{Maybe as ct,None as Br,Some as jr}from"@kumori/kdsl-lsp/util/maybe.js";import{Err as C,Ok as S,Result as M}from"@kumori/kdsl-lsp/util/result.js";import{TempCache as qr}from"@kumori/kdsl-lsp/util/tmp.js";import{NodeFileSystem as mt}from"langium/node";import $ from"path";import{AstUtils as gt,URI as Kr,UriUtils as ft}from"langium";import q from"assert";import{TAny as ut,TBoolean as Vr,TEither as Ur,TFunction as Jr,TList as zr,TNumber as Gr,TOptional as dt,TString as Qr,TStruct as Hr,TTypeDefAlias as Wr,TTypeDefNamed as Yr,TypeSystemError as Xr,TypeToString as Zr}from"@kumori/kdsl-lsp/language/type-system/type.js";import{ModuleDescriptor as eo}from"@kumori/kdsl-lsp/module/descriptor.js";import{isBuiltinArtifact as to,isComponentArtifact as ro,isServiceArtifact as oo}from"@kumori/kdsl-lsp/language/generated/ast.js";import{Scheme as io}from"@kumori/kdsl-lsp/language/builtin/util.js";import{GatherModuleDocuments as no}from"@kumori/kdsl-lsp/module/documents.js";import{RemoteFetcherFactory as ao}from"@kumori/kdsl-lsp/module/remote/factory.js";function ht(t,e){return t.command("get").summary(lo).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").').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 ".".`).argument("<artifact-name>",'Name of the target artifact (e.g., "ExampleService").').description(pt).helpOption(!0).action(wt(e))}function wt(t){return async(e,r,o)=>{let i=Ir(mt).Kumori,a=u=>F(t,u),n=a(await vt(e)),s=i.shared.workspace.FileSystemProvider,l=a(M.mapErr(await Nr(s,Kr.file(n.fsPath)),u=>[u]));a(await z(t,i,l));let d=a(await yt(i,l,r,o));console.log(JSON.stringify(d,null,4))}}async function vt(t){let e=await qr(),r=mt.fileSystemProvider(),o=t;if(t[0]==="."||$.isAbsolute(t)){let u=$.isAbsolute(t)?t:$.resolve(process.cwd(),t);return S({$type:"local",fsPath:u})}let a=Ar(t);if(ct.isNone(a))return C([`invalid remote target '${t}': invalid syntax`]);let n=a.value.Version,s=`${a.value.Location}@${n}`,l=ft.joinPath(e,s),d=await eo(r,l);if(M.isErr(d)){let u=await Z({Remotes:ao()},a.value.Location,n,l.fsPath);if(M.isErr(u))return C([`failed to fetch ${o}: ${u.err}`])}return S({$type:"remote",fsPath:l.fsPath,query:a.value})}async function yt(t,e,r,o){let i=ft.joinPath(e.Current.Root,$.normalize(r)),a=t.references.KumoriPackages.GetPackage(i);if(M.isErr(a))return C([`error: failed to retrieve package: ${i.toString()}`]);let n=new Set(a.value.docs.map(p=>p.uri.toString())),s=t.shared.workspace.IndexManager.allElements(void 0,n).toArray().filter(p=>p.name===o);if(s.length<1)return C([`error: no artifact named defined in ${i.toString()}`]);if(s.length>2)return C([`error: too many matches in ${i.toString()}`]);let l=s[0].node;if(!(ro(l)||oo(l)||to(l)))return C([`invalid reference to node of type: ${l.$type}`]);if(!gt.getDocument(l).uri.fsPath.endsWith(".h.kumori")){if(!l.name.value.ref)return C(["no headers found for component"]);l=l.name.value.ref}let u=t.validation.KumoriTypeSystem,c=t.validation.KumoriValidations.ctx(),[g,v]=u.Infer(c,l);if(v.length>0){let p=[];return v.map(L=>p.concat(L.message)),C([`type inference failed with errors: ${p}`])}let h=await Lt(t,e,g,$.join(e.Current.Manifest.module,r+"@"+o));return M.mapErr(h,p=>p.map(st))}async function Lt(t,e,r,o){return M.map(await T({svcs:t,mod:e},r),i=>f({$schema:"https://json-schema.org/draft/2020-12/schema",$spec:"kumori/schema/v1",$id:o},i))}async function T(t,e){if(ut.is(e))return S({});if(Jr.is(e))return T(t,e.returns);if(dt.is(e))return T(t,e.inner);if(Wr.is(e))return T(t,e.spec);if(Gr.is(e))return e.literal===void 0?S({type:"number"}):S({const:e.literal});if(Qr.is(e))return e.literal===void 0?S({type:"string"}):S({const:e.literal});if(Vr.is(e))return e.literal===void 0?S({type:"boolean"}):S({const:e.literal});if(zr.is(e)){let r=await T(t,e.restriction);return M.isErr(r)?r:S({type:"array",items:r.value})}if(Ur.is(e)){let r=await Promise.all(e.variations.map(a=>T(t,a))),o=r.filter(M.isErr).map(a=>a.err).flat();if(o.length>0)return C(o);let i=r.filter(M.isOk).map(a=>a.value);return q(i.length===r.length),S({oneOf:i})}if(Hr.is(e)){let r=await Promise.all(Object.entries(e.parameters).map(async n=>({key:n[0],value:n[1],schema:await T(t,n[1].value)}))),o=r.map(n=>n.schema).filter(n=>M.isErr(n)).map(n=>n.err).flat(),i=Br;if(e.restriction!==void 0&&!ut.is(e.restriction)){let n=await T(t,e.restriction);M.isOk(n)?i=jr(n.value):o=o.concat(n.err)}if(o.length>0)return C(o);let a={type:"object",properties:Object.fromEntries(r.map(n=>(q(M.isOk(n.schema)),[n.key,n.schema.value]))),required:r.filter(n=>n.value.optional===!1&&!dt.is(n.value.value)).map(n=>n.key)};return ct.isSome(i)&&(a=y(f({},a),{additionalProperties:i.value})),S(a)}if(Yr.is(e)){let r=await T(t,e.spec);return M.isErr(r)?r:S({type:"object",properties:{$kdsl:{const:{NamedType:await uo(t,e)}},inner:r.value},required:["$kdsl","inner"]})}return C([Xr.create({node:e,message:`cannot convert definition to JSONSchema: ${Zr(e)}`})])}var so,lo,pt,uo,xt=k(()=>{"use strict";se();K();lt();ee();so={Register:ht};lo="extracts jsonschema for a specified module and artifact",pt=`
|
|
63
|
+
Generates and outputs the JSON Schema that describes a particular Kumori DSL
|
|
64
|
+
artifact. This schema defines the artifact's configurable properties, resource
|
|
65
|
+
requirements, and overall structure, making it valuable for programmatic
|
|
66
|
+
interaction, validation, or documentation purposes.
|
|
67
|
+
|
|
68
|
+
The command allows you to specify artifacts from both remote/external modules
|
|
69
|
+
and local modules.
|
|
70
|
+
`.trim();uo=async(t,e)=>{let r=e.node;q(r);let o=t.svcs.shared.references.KumoriModules,i=gt.getDocument(r).uri,a=t.svcs.references.KumoriPackages.GetPackage(r),n=t.mod.Current;if(q(M.isOk(a)),i.scheme===io)return{Import:a.value.uri.path.slice(1),Name:e.meta.name};if(!(await no(t.svcs.shared,t.mod.Root.Root)).map(g=>g.fsPath).includes(i.fsPath)){let g=o.getModule(i);q(M.isOk(g)),n=g.value}let u=n.Root,c=a.value.uri.fsPath.slice(u.fsPath.length);return{Import:$.join(n.Manifest.module,c),Name:e.meta.name}}});var b=function(t){return t.info="info",t.warn="warn",t.error="error",t.debug="debug",t.trace="trace",t.fatal="fatal",t}({}),go={[b.trace]:10,[b.debug]:20,[b.info]:30,[b.warn]:40,[b.error]:50,[b.fatal]:60},fo={10:b.trace,20:b.debug,30:b.info,40:b.warn,50:b.error,60:b.fatal};var x=function(t){return t.onBeforeDataOut="onBeforeDataOut",t.shouldSendToLogger="shouldSendToLogger",t.onMetadataCalled="onMetadataCalled",t.onBeforeMessageOut="onBeforeMessageOut",t.onContextCalled="onContextCalled",t}({});var m=function(t){return t.info="info",t.warn="warn",t.error="error",t.debug="debug",t.trace="trace",t.fatal="fatal",t}({}),N={[m.trace]:10,[m.debug]:20,[m.info]:30,[m.warn]:40,[m.error]:50,[m.fatal]:60},vo={10:m.trace,20:m.debug,30:m.info,40:m.warn,50:m.error,60:m.fatal};var ge=class fe{constructor(){w(this,"context",{});w(this,"hasContext",!1)}setContext(e){if(!e){this.context={},this.hasContext=!1;return}this.context=e,this.hasContext=!0}appendContext(e){this.context=f(f({},this.context),e),this.hasContext=!0}getContext(){return this.context}hasContextData(){return this.hasContext}onChildLoggerCreated({parentContextManager:e,childContextManager:r}){if(e.hasContextData()){let o=e.getContext();r.setContext(f({},o))}}clone(){let e=new fe;return e.setContext(f({},this.context)),e.hasContext=this.hasContext,e}};var he=class{constructor(t){w(this,"err");w(this,"metadata");w(this,"structuredLogger");w(this,"hasMetadata");w(this,"pluginManager");this.err=null,this.metadata={},this.structuredLogger=t,this.hasMetadata=!1,this.pluginManager=t.pluginManager}withMetadata(t){let{pluginManager:e,structuredLogger:{_config:{consoleDebug:r}}}=this;if(!t)return r&&console.debug("[LogLayer] withMetadata was called with no metadata; dropping."),this;let o=t;return e.hasPlugins(x.onMetadataCalled)&&(o=e.runOnMetadataCalled(t,this.structuredLogger),!o)?(r&&console.debug("[LogLayer] Metadata was dropped due to plugin returning falsy value."),this):(this.metadata=f(f({},this.metadata),o),this.hasMetadata=!0,this)}withError(t){return this.err=t,this}info(...t){this.structuredLogger.isLevelEnabled(m.info)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.info,t))}warn(...t){this.structuredLogger.isLevelEnabled(m.warn)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.warn,t))}error(...t){this.structuredLogger.isLevelEnabled(m.error)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.error,t))}debug(...t){this.structuredLogger.isLevelEnabled(m.debug)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.debug,t))}trace(...t){this.structuredLogger.isLevelEnabled(m.trace)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.trace,t))}fatal(...t){this.structuredLogger.isLevelEnabled(m.fatal)&&(this.structuredLogger._formatMessage(t),this.formatLog(m.fatal,t))}disableLogging(){return this.structuredLogger.disableLogging(),this}enableLogging(){return this.structuredLogger.enableLogging(),this}formatLog(t,e){let{muteMetadata:r}=this.structuredLogger._config,o=r?!1:this.hasMetadata;this.structuredLogger._formatLog({logLevel:t,params:e,metadata:o?this.metadata:null,err:this.err})}},Dt=[x.onBeforeDataOut,x.onMetadataCalled,x.shouldSendToLogger,x.onBeforeMessageOut,x.onContextCalled],pe=class{constructor(t){w(this,"idToPlugin");w(this,"onBeforeDataOut",[]);w(this,"shouldSendToLogger",[]);w(this,"onMetadataCalled",[]);w(this,"onBeforeMessageOut",[]);w(this,"onContextCalled",[]);this.idToPlugin={},this.mapPlugins(t),this.indexPlugins()}mapPlugins(t){for(let e of t){if(e.id||(e.id=Date.now().toString()+Math.random().toString()),this.idToPlugin[e.id])throw new Error(`[LogLayer] Plugin with id ${e.id} already exists.`);e.registeredAt=Date.now(),this.idToPlugin[e.id]=e}}indexPlugins(){this.onBeforeDataOut=[],this.shouldSendToLogger=[],this.onMetadataCalled=[],this.onBeforeMessageOut=[],this.onContextCalled=[];let t=Object.values(this.idToPlugin).sort((e,r)=>e.registeredAt-r.registeredAt);for(let e of t){if(e.disabled)return;for(let r of Dt)e[r]&&e.id&&this[r].push(e.id)}}hasPlugins(t){return this[t].length>0}countPlugins(t){return t?this[t].length:Object.keys(this.idToPlugin).length}addPlugins(t){this.mapPlugins(t),this.indexPlugins()}enablePlugin(t){let e=this.idToPlugin[t];e&&(e.disabled=!1),this.indexPlugins()}disablePlugin(t){let e=this.idToPlugin[t];e&&(e.disabled=!0),this.indexPlugins()}removePlugin(t){delete this.idToPlugin[t],this.indexPlugins()}runOnBeforeDataOut(t,e){let r=f({},t);for(let o of this.onBeforeDataOut){let i=this.idToPlugin[o];if(i.onBeforeDataOut){let a=i.onBeforeDataOut({data:r.data,logLevel:r.logLevel,error:r.error,metadata:r.metadata,context:r.context},e);a&&(r.data||(r.data={}),Object.assign(r.data,a))}}return r.data}runShouldSendToLogger(t,e){return!this.shouldSendToLogger.some(r=>{var o,i;return!((i=(o=this.idToPlugin[r]).shouldSendToLogger)!=null&&i.call(o,t,e))})}runOnMetadataCalled(t,e){var o,i;let r=f({},t);for(let a of this.onMetadataCalled){let n=(i=(o=this.idToPlugin[a]).onMetadataCalled)==null?void 0:i.call(o,r,e);if(n)r=n;else return null}return r}runOnBeforeMessageOut(t,e){var o,i;let r=[...t.messages];for(let a of this.onBeforeMessageOut){let n=(i=(o=this.idToPlugin[a]).onBeforeMessageOut)==null?void 0:i.call(o,{messages:r,logLevel:t.logLevel},e);n&&(r=n)}return r}runOnContextCalled(t,e){var o,i;let r=f({},t);for(let a of this.onContextCalled){let n=(i=(o=this.idToPlugin[a]).onContextCalled)==null?void 0:i.call(o,r,e);if(n)r=n;else return null}return r}},we=class ve{constructor(e){w(this,"pluginManager");w(this,"idToTransport");w(this,"hasMultipleTransports");w(this,"singleTransport");w(this,"contextManager");w(this,"logLevelEnabledStatus",{info:!0,warn:!0,error:!0,debug:!0,trace:!0,fatal:!0});w(this,"_config");var r;this._config=y(f({},e),{enabled:(r=e.enabled)!=null?r:!0}),this._config.enabled||this.disableLogging(),this.contextManager=new ge,this.pluginManager=new pe(e.plugins||[]),this._config.errorFieldName||(this._config.errorFieldName="err"),this._config.copyMsgOnOnlyError||(this._config.copyMsgOnOnlyError=!1),this._initializeTransports(this._config.transport)}withContextManager(e){return this.contextManager&&typeof this.contextManager[Symbol.dispose]=="function"&&this.contextManager[Symbol.dispose](),this.contextManager=e,this}getContextManager(){return this.contextManager}_initializeTransports(e){if(this.idToTransport)for(let r in this.idToTransport)this.idToTransport[r]&&typeof this.idToTransport[r][Symbol.dispose]=="function"&&this.idToTransport[r][Symbol.dispose]();this.hasMultipleTransports=Array.isArray(e)&&e.length>1,this.singleTransport=this.hasMultipleTransports?null:Array.isArray(e)?e[0]:e,Array.isArray(e)?this.idToTransport=e.reduce((r,o)=>(r[o.id]=o,r),{}):this.idToTransport={[e.id]:e}}withPrefix(e){let r=this.child();return r._config.prefix=e,r}withContext(e){let r=e;return e?this.pluginManager.hasPlugins(x.onContextCalled)&&(r=this.pluginManager.runOnContextCalled(e,this),!r)?(this._config.consoleDebug&&console.debug("[LogLayer] Context was dropped due to plugin returning falsy value."),this):(this.contextManager.appendContext(r),this):(this._config.consoleDebug&&console.debug("[LogLayer] withContext was called with no context; dropping."),this)}clearContext(){return this.contextManager.setContext(void 0),this}getContext(){return this.contextManager.getContext()}addPlugins(e){this.pluginManager.addPlugins(e)}enablePlugin(e){this.pluginManager.enablePlugin(e)}disablePlugin(e){this.pluginManager.disablePlugin(e)}removePlugin(e){this.pluginManager.removePlugin(e)}withMetadata(e){return new he(this).withMetadata(e)}withError(e){return new he(this).withError(e)}child(){let e=new ve(y(f({},this._config),{transport:Array.isArray(this._config.transport)?[...this._config.transport]:this._config.transport})).withPluginManager(this.pluginManager).withContextManager(this.contextManager.clone());return this.contextManager.onChildLoggerCreated({parentContextManager:this.contextManager,childContextManager:e.contextManager,parentLogger:this,childLogger:e}),e}withFreshTransports(e){return this._config.transport=e,this._initializeTransports(e),this}withFreshPlugins(e){return this._config.plugins=e,this.pluginManager=new pe(e),this}withPluginManager(e){return this.pluginManager=e,this}errorOnly(e,r){let o=(r==null?void 0:r.logLevel)||m.error;if(!this.isLevelEnabled(o))return;let{copyMsgOnOnlyError:i}=this._config,a={logLevel:o,err:e};(i&&(r==null?void 0:r.copyMsg)!==!1||(r==null?void 0:r.copyMsg)===!0)&&(e!=null&&e.message)&&(a.params=[e.message]),this._formatLog(a)}metadataOnly(e,r=m.info){if(!this.isLevelEnabled(r))return;let{muteMetadata:o,consoleDebug:i}=this._config;if(o)return;if(!e){i&&console.debug("[LogLayer] metadataOnly was called with no metadata; dropping.");return}let a=e;if(this.pluginManager.hasPlugins(x.onMetadataCalled)&&(a=this.pluginManager.runOnMetadataCalled(e,this),!a)){i&&console.debug("[LogLayer] Metadata was dropped due to plugin returning falsy value.");return}let n={logLevel:r,metadata:a};this._formatLog(n)}info(...e){this.isLevelEnabled(m.info)&&(this._formatMessage(e),this._formatLog({logLevel:m.info,params:e}))}warn(...e){this.isLevelEnabled(m.warn)&&(this._formatMessage(e),this._formatLog({logLevel:m.warn,params:e}))}error(...e){this.isLevelEnabled(m.error)&&(this._formatMessage(e),this._formatLog({logLevel:m.error,params:e}))}debug(...e){this.isLevelEnabled(m.debug)&&(this._formatMessage(e),this._formatLog({logLevel:m.debug,params:e}))}trace(...e){this.isLevelEnabled(m.trace)&&(this._formatMessage(e),this._formatLog({logLevel:m.trace,params:e}))}fatal(...e){this.isLevelEnabled(m.fatal)&&(this._formatMessage(e),this._formatLog({logLevel:m.fatal,params:e}))}raw(e){if(!this.isLevelEnabled(e.logLevel))return;let r={logLevel:e.logLevel,params:e.messages,metadata:e.metadata,err:e.error,context:e.context};this._formatMessage(e.messages),this._formatLog(r)}disableLogging(){for(let e of Object.keys(this.logLevelEnabledStatus))this.logLevelEnabledStatus[e]=!1;return this}enableLogging(){for(let e of Object.keys(this.logLevelEnabledStatus))this.logLevelEnabledStatus[e]=!0;return this}muteContext(){return this._config.muteContext=!0,this}unMuteContext(){return this._config.muteContext=!1,this}muteMetadata(){return this._config.muteMetadata=!0,this}unMuteMetadata(){return this._config.muteMetadata=!1,this}enableIndividualLevel(e){let r=e;return r in this.logLevelEnabledStatus&&(this.logLevelEnabledStatus[r]=!0),this}disableIndividualLevel(e){let r=e;return r in this.logLevelEnabledStatus&&(this.logLevelEnabledStatus[r]=!1),this}setLevel(e){let r=N[e];for(let o of Object.values(m)){let i=o,a=N[o];this.logLevelEnabledStatus[i]=a>=r}return this}isLevelEnabled(e){let r=e;return this.logLevelEnabledStatus[r]}formatContext(e){let{contextFieldName:r,muteContext:o}=this._config;return e&&Object.keys(e).length>0&&!o?r?{[r]:f({},e)}:f({},e):{}}formatMetadata(e=null){let{metadataFieldName:r,muteMetadata:o}=this._config;return e&&!o?r?{[r]:f({},e)}:f({},e):{}}getLoggerInstance(e){let r=this.idToTransport[e];if(r)return r.getLoggerInstance()}_formatMessage(e=[]){let{prefix:r}=this._config;r&&typeof e[0]=="string"&&(e[0]=`${r} ${e[0]}`)}_formatLog({logLevel:e,params:r=[],metadata:o=null,err:i,context:a=null}){var p;let{errorSerializer:n,errorFieldInMetadata:s,muteContext:l,contextFieldName:d,metadataFieldName:u,errorFieldName:c}=this._config,g=a!==null?a:this.contextManager.getContext(),v=!!o||(l?!1:a!==null?Object.keys(a).length>0:this.contextManager.hasContextData()),h={};if(v)if(d&&d===u){let L=this.formatContext(g)[d],P=this.formatMetadata(o)[u];h={[d]:f(f({},L),P)}}else h=f(f({},this.formatContext(g)),this.formatMetadata(o));if(i){let L=n?n(i):i;s&&o&&u?h!=null&&h[u]?h[u][c]=L:h=y(f({},h),{[u]:{[c]:L}}):s&&!o&&u?h=y(f({},h),{[u]:{[c]:L}}):h=y(f({},h),{[c]:L}),v=!0}if(this.pluginManager.hasPlugins(x.onBeforeDataOut)&&(h=this.pluginManager.runOnBeforeDataOut({data:v?h:void 0,logLevel:e,error:i,metadata:o,context:g},this),h&&!v&&(v=!0)),this.pluginManager.hasPlugins(x.onBeforeMessageOut)&&(r=this.pluginManager.runOnBeforeMessageOut({messages:[...r],logLevel:e},this)),this.hasMultipleTransports){let L=this._config.transport.filter(P=>P.enabled).map(async P=>{if(!(this.pluginManager.hasPlugins(x.shouldSendToLogger)&&!this.pluginManager.runShouldSendToLogger({messages:[...r],data:v?h:void 0,logLevel:e,transportId:P.id,error:i,metadata:o,context:g},this)))return P._sendToLogger({logLevel:e,messages:[...r],data:v?h:void 0,hasData:v,error:i,metadata:o,context:g})});Promise.all(L).catch(P=>{this._config.consoleDebug&&console.error("[LogLayer] Error executing transports:",P)})}else{if(!((p=this.singleTransport)!=null&&p.enabled)||this.pluginManager.hasPlugins(x.shouldSendToLogger)&&!this.pluginManager.runShouldSendToLogger({messages:[...r],data:v?h:void 0,logLevel:e,transportId:this.singleTransport.id,error:i,metadata:o,context:g},this))return;this.singleTransport._sendToLogger({logLevel:e,messages:[...r],data:v?h:void 0,hasData:v,error:i,metadata:o,context:g})}}};function Tt(){let t={debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}};return new we({transport:t})}function _(t){return t!=null?t:Tt()}import{URI as co}from"langium";import{Result as G,Err as I,Ok as Q}from"@kumori/kdsl-lsp/util/result.js";async function $n(t){var o;let e=_(t.logger),{NewModule:r}=await Promise.resolve().then(()=>(Pe(),Se));try{let i=(o=t.cwd)!=null?o:process.cwd();return await r(e,i,t.name,t.version,t.location,t.cacheLocation),Q(void 0)}catch(i){return I([String(i)])}}async function In(t){var n;let e=_(t.logger),r=co.file((n=t.cwd)!=null?n:process.cwd()),{Dependency:o}=await Promise.resolve().then(()=>(Ge(),ze)),{RegistryManager:i}=await import("@kumori/kdsl-lsp/module/registry/manager.js");await new i().ensureIndexes();try{return await o(e,r,t.module,{alias:t.alias,headers:t.headers,remove:t.remove?!0:void 0,download:t.download?!0:void 0}),Q(void 0)}catch(s){return I([String(s)])}}async function Nn(t){var a,n;let e=_(t.logger),{Download:r}=await Promise.resolve().then(()=>(U(),je)),{RegistryManager:o}=await import("@kumori/kdsl-lsp/module/registry/manager.js");return await new o().ensureIndexes(),await r(e,t.services,(a=t.cwd)!=null?a:process.cwd(),(n=t.modules)!=null?n:[],{quiet:t.quiet?!0:void 0})}async function An(t){var o;let e=_(t.logger),{NewModule:r}=await Promise.resolve().then(()=>(et(),Ze));try{return await r(e,(o=t.cwd)!=null?o:process.cwd(),{version:t.version,cacheLocation:t.cacheLocation,path:t.path}),Q(void 0)}catch(i){return I([String(i)])}}async function Bn(t){var l,d;let{CalculateChecksum:e}=await import("@kumori/kdsl-lsp/module/integrity/checksum.js"),{ModuleContext:r}=await import("@kumori/kdsl-lsp/module/context.js"),{URI:o}=await import("langium"),i=await import("path"),a=t.services.shared.workspace.FileSystemProvider,n=(d=(l=t.directory)!=null?l:t.cwd)!=null?d:".",s=await r(a,o.file(i.resolve(n)));if(G.isErr(s))return I([s.err]);try{let u=await e(s.value.Current.Root.fsPath);return Q(u)}catch(u){return I([String(u)])}}async function jn(t){let e=_(t.logger),{LocateModule:r,GetSchema:o}=await Promise.resolve().then(()=>(xt(),Mt)),{ModuleContext:i}=await import("@kumori/kdsl-lsp/module/context.js"),{Check:a}=await Promise.resolve().then(()=>(se(),at)),{URI:n}=await import("langium"),s=t.services,l=s.shared.workspace.FileSystemProvider,d=await r(t.target);if(G.isErr(d))return d;let u=await i(l,n.file(d.value.fsPath));if(G.isErr(u))return I([u.err]);let c=await a(e,s,u.value);return G.isErr(c)?c:await o(s,u.value,t.packagePath,t.artifactName)}export{Bn as moduleChecksum,In as moduleDependency,Nn as moduleDownload,$n as moduleInit,jn as moduleSchemaGet,An as moduleUpdate};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../src/lib/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,iCAAiC,CAAA;AAqCjE;;;;;;GAMG;AACH,MAAM,CAAC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,CAAC,CAAC,CAAA;IACrE,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACtB,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;IACvB,CAAC;IAED,wBAAwB;IACxB,MAAM,WAAW,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAA;IACrD,IAAI,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC;QAC9B,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,iBAAiB;IACjB,OAAO,MAAM,SAAS,CACpB,IAAI,EACJ,GAAG,CAAC,KAAK,EACT,OAAO,CAAC,WAAW,EACnB,OAAO,CAAC,YAAY,CACrB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { LibraryOptions, LibraryResult } from "./types.js";
|
|
2
|
+
import { Registry } from "@kumori/kdsl-lsp/module/registry/types.js";
|
|
3
|
+
export interface RegistryAddOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Name selector for matching dependencies
|
|
6
|
+
*/
|
|
7
|
+
selector: string;
|
|
8
|
+
/**
|
|
9
|
+
* Version of the registry specification (git tag)
|
|
10
|
+
*/
|
|
11
|
+
version: string;
|
|
12
|
+
/**
|
|
13
|
+
* URL that contains the registry index for resolving modules
|
|
14
|
+
*/
|
|
15
|
+
url: string;
|
|
16
|
+
/**
|
|
17
|
+
* Optional logger for output.
|
|
18
|
+
*/
|
|
19
|
+
logger?: LibraryOptions["logger"];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Add a registry to the resolver configuration.
|
|
23
|
+
*
|
|
24
|
+
* The selector argument is used to match artifacts. For example, a registry
|
|
25
|
+
* with Index URL "https://github.com/kumori" and selector "kumori.systems"
|
|
26
|
+
* will resolve dependencies starting with "kumori.systems".
|
|
27
|
+
*
|
|
28
|
+
* @param options - Registry add options
|
|
29
|
+
* @returns Result with void on success, or string[] of errors
|
|
30
|
+
*/
|
|
31
|
+
export declare function registryAdd(options: RegistryAddOptions): Promise<LibraryResult<void>>;
|
|
32
|
+
export interface RegistryListOptions {
|
|
33
|
+
/**
|
|
34
|
+
* Optional logger for output.
|
|
35
|
+
*/
|
|
36
|
+
logger?: LibraryOptions["logger"];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* List all configured registries.
|
|
40
|
+
*
|
|
41
|
+
* @param options - Registry list options
|
|
42
|
+
* @returns Result with array of registry objects on success, or string[] of errors
|
|
43
|
+
*/
|
|
44
|
+
export declare function registryList(options?: RegistryListOptions): Promise<LibraryResult<Registry[]>>;
|
|
45
|
+
export interface RegistryRemoveOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Name of the registry to remove
|
|
48
|
+
*/
|
|
49
|
+
name: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional logger for output.
|
|
52
|
+
*/
|
|
53
|
+
logger?: LibraryOptions["logger"];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Remove a configured registry by name.
|
|
57
|
+
*
|
|
58
|
+
* @param options - Registry remove options
|
|
59
|
+
* @returns Result with void on success, or string[] of errors
|
|
60
|
+
*/
|
|
61
|
+
export declare function registryRemove(options: RegistryRemoveOptions): Promise<LibraryResult<void>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var A=Object.defineProperty,N=Object.defineProperties;var I=Object.getOwnPropertyDescriptors;var F=Object.getOwnPropertySymbols;var z=Object.prototype.hasOwnProperty,J=Object.prototype.propertyIsEnumerable;var C=(r,e,t)=>e in r?A(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,a=(r,e)=>{for(var t in e||(e={}))z.call(e,t)&&C(r,t,e[t]);if(F)for(var t of F(e))J.call(e,t)&&C(r,t,e[t]);return r},m=(r,e)=>N(r,I(e));var s=(r,e,t)=>(C(r,typeof e!="symbol"?e+"":e,t),t);var h=function(r){return r.info="info",r.warn="warn",r.error="error",r.debug="debug",r.trace="trace",r.fatal="fatal",r}({}),q={[h.trace]:10,[h.debug]:20,[h.info]:30,[h.warn]:40,[h.error]:50,[h.fatal]:60},G={10:h.trace,20:h.debug,30:h.info,40:h.warn,50:h.error,60:h.fatal};var u=function(r){return r.onBeforeDataOut="onBeforeDataOut",r.shouldSendToLogger="shouldSendToLogger",r.onMetadataCalled="onMetadataCalled",r.onBeforeMessageOut="onBeforeMessageOut",r.onContextCalled="onContextCalled",r}({});var n=function(r){return r.info="info",r.warn="warn",r.error="error",r.debug="debug",r.trace="trace",r.fatal="fatal",r}({}),M={[n.trace]:10,[n.debug]:20,[n.info]:30,[n.warn]:40,[n.error]:50,[n.fatal]:60},X={10:n.trace,20:n.debug,30:n.info,40:n.warn,50:n.error,60:n.fatal};var D=class E{constructor(){s(this,"context",{});s(this,"hasContext",!1)}setContext(e){if(!e){this.context={},this.hasContext=!1;return}this.context=e,this.hasContext=!0}appendContext(e){this.context=a(a({},this.context),e),this.hasContext=!0}getContext(){return this.context}hasContextData(){return this.hasContext}onChildLoggerCreated({parentContextManager:e,childContextManager:t}){if(e.hasContextData()){let i=e.getContext();t.setContext(a({},i))}}clone(){let e=new E;return e.setContext(a({},this.context)),e.hasContext=this.hasContext,e}};var S=class{constructor(r){s(this,"err");s(this,"metadata");s(this,"structuredLogger");s(this,"hasMetadata");s(this,"pluginManager");this.err=null,this.metadata={},this.structuredLogger=r,this.hasMetadata=!1,this.pluginManager=r.pluginManager}withMetadata(r){let{pluginManager:e,structuredLogger:{_config:{consoleDebug:t}}}=this;if(!r)return t&&console.debug("[LogLayer] withMetadata was called with no metadata; dropping."),this;let i=r;return e.hasPlugins(u.onMetadataCalled)&&(i=e.runOnMetadataCalled(r,this.structuredLogger),!i)?(t&&console.debug("[LogLayer] Metadata was dropped due to plugin returning falsy value."),this):(this.metadata=a(a({},this.metadata),i),this.hasMetadata=!0,this)}withError(r){return this.err=r,this}info(...r){this.structuredLogger.isLevelEnabled(n.info)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.info,r))}warn(...r){this.structuredLogger.isLevelEnabled(n.warn)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.warn,r))}error(...r){this.structuredLogger.isLevelEnabled(n.error)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.error,r))}debug(...r){this.structuredLogger.isLevelEnabled(n.debug)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.debug,r))}trace(...r){this.structuredLogger.isLevelEnabled(n.trace)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.trace,r))}fatal(...r){this.structuredLogger.isLevelEnabled(n.fatal)&&(this.structuredLogger._formatMessage(r),this.formatLog(n.fatal,r))}disableLogging(){return this.structuredLogger.disableLogging(),this}enableLogging(){return this.structuredLogger.enableLogging(),this}formatLog(r,e){let{muteMetadata:t}=this.structuredLogger._config,i=t?!1:this.hasMetadata;this.structuredLogger._formatLog({logLevel:r,params:e,metadata:i?this.metadata:null,err:this.err})}},K=[u.onBeforeDataOut,u.onMetadataCalled,u.shouldSendToLogger,u.onBeforeMessageOut,u.onContextCalled],k=class{constructor(r){s(this,"idToPlugin");s(this,"onBeforeDataOut",[]);s(this,"shouldSendToLogger",[]);s(this,"onMetadataCalled",[]);s(this,"onBeforeMessageOut",[]);s(this,"onContextCalled",[]);this.idToPlugin={},this.mapPlugins(r),this.indexPlugins()}mapPlugins(r){for(let e of r){if(e.id||(e.id=Date.now().toString()+Math.random().toString()),this.idToPlugin[e.id])throw new Error(`[LogLayer] Plugin with id ${e.id} already exists.`);e.registeredAt=Date.now(),this.idToPlugin[e.id]=e}}indexPlugins(){this.onBeforeDataOut=[],this.shouldSendToLogger=[],this.onMetadataCalled=[],this.onBeforeMessageOut=[],this.onContextCalled=[];let r=Object.values(this.idToPlugin).sort((e,t)=>e.registeredAt-t.registeredAt);for(let e of r){if(e.disabled)return;for(let t of K)e[t]&&e.id&&this[t].push(e.id)}}hasPlugins(r){return this[r].length>0}countPlugins(r){return r?this[r].length:Object.keys(this.idToPlugin).length}addPlugins(r){this.mapPlugins(r),this.indexPlugins()}enablePlugin(r){let e=this.idToPlugin[r];e&&(e.disabled=!1),this.indexPlugins()}disablePlugin(r){let e=this.idToPlugin[r];e&&(e.disabled=!0),this.indexPlugins()}removePlugin(r){delete this.idToPlugin[r],this.indexPlugins()}runOnBeforeDataOut(r,e){let t=a({},r);for(let i of this.onBeforeDataOut){let o=this.idToPlugin[i];if(o.onBeforeDataOut){let l=o.onBeforeDataOut({data:t.data,logLevel:t.logLevel,error:t.error,metadata:t.metadata,context:t.context},e);l&&(t.data||(t.data={}),Object.assign(t.data,l))}}return t.data}runShouldSendToLogger(r,e){return!this.shouldSendToLogger.some(t=>{var i,o;return!((o=(i=this.idToPlugin[t]).shouldSendToLogger)!=null&&o.call(i,r,e))})}runOnMetadataCalled(r,e){var i,o;let t=a({},r);for(let l of this.onMetadataCalled){let d=(o=(i=this.idToPlugin[l]).onMetadataCalled)==null?void 0:o.call(i,t,e);if(d)t=d;else return null}return t}runOnBeforeMessageOut(r,e){var i,o;let t=[...r.messages];for(let l of this.onBeforeMessageOut){let d=(o=(i=this.idToPlugin[l]).onBeforeMessageOut)==null?void 0:o.call(i,{messages:t,logLevel:r.logLevel},e);d&&(t=d)}return t}runOnContextCalled(r,e){var i,o;let t=a({},r);for(let l of this.onContextCalled){let d=(o=(i=this.idToPlugin[l]).onContextCalled)==null?void 0:o.call(i,t,e);if(d)t=d;else return null}return t}},B=class R{constructor(e){s(this,"pluginManager");s(this,"idToTransport");s(this,"hasMultipleTransports");s(this,"singleTransport");s(this,"contextManager");s(this,"logLevelEnabledStatus",{info:!0,warn:!0,error:!0,debug:!0,trace:!0,fatal:!0});s(this,"_config");var t;this._config=m(a({},e),{enabled:(t=e.enabled)!=null?t:!0}),this._config.enabled||this.disableLogging(),this.contextManager=new D,this.pluginManager=new k(e.plugins||[]),this._config.errorFieldName||(this._config.errorFieldName="err"),this._config.copyMsgOnOnlyError||(this._config.copyMsgOnOnlyError=!1),this._initializeTransports(this._config.transport)}withContextManager(e){return this.contextManager&&typeof this.contextManager[Symbol.dispose]=="function"&&this.contextManager[Symbol.dispose](),this.contextManager=e,this}getContextManager(){return this.contextManager}_initializeTransports(e){if(this.idToTransport)for(let t in this.idToTransport)this.idToTransport[t]&&typeof this.idToTransport[t][Symbol.dispose]=="function"&&this.idToTransport[t][Symbol.dispose]();this.hasMultipleTransports=Array.isArray(e)&&e.length>1,this.singleTransport=this.hasMultipleTransports?null:Array.isArray(e)?e[0]:e,Array.isArray(e)?this.idToTransport=e.reduce((t,i)=>(t[i.id]=i,t),{}):this.idToTransport={[e.id]:e}}withPrefix(e){let t=this.child();return t._config.prefix=e,t}withContext(e){let t=e;return e?this.pluginManager.hasPlugins(u.onContextCalled)&&(t=this.pluginManager.runOnContextCalled(e,this),!t)?(this._config.consoleDebug&&console.debug("[LogLayer] Context was dropped due to plugin returning falsy value."),this):(this.contextManager.appendContext(t),this):(this._config.consoleDebug&&console.debug("[LogLayer] withContext was called with no context; dropping."),this)}clearContext(){return this.contextManager.setContext(void 0),this}getContext(){return this.contextManager.getContext()}addPlugins(e){this.pluginManager.addPlugins(e)}enablePlugin(e){this.pluginManager.enablePlugin(e)}disablePlugin(e){this.pluginManager.disablePlugin(e)}removePlugin(e){this.pluginManager.removePlugin(e)}withMetadata(e){return new S(this).withMetadata(e)}withError(e){return new S(this).withError(e)}child(){let e=new R(m(a({},this._config),{transport:Array.isArray(this._config.transport)?[...this._config.transport]:this._config.transport})).withPluginManager(this.pluginManager).withContextManager(this.contextManager.clone());return this.contextManager.onChildLoggerCreated({parentContextManager:this.contextManager,childContextManager:e.contextManager,parentLogger:this,childLogger:e}),e}withFreshTransports(e){return this._config.transport=e,this._initializeTransports(e),this}withFreshPlugins(e){return this._config.plugins=e,this.pluginManager=new k(e),this}withPluginManager(e){return this.pluginManager=e,this}errorOnly(e,t){let i=(t==null?void 0:t.logLevel)||n.error;if(!this.isLevelEnabled(i))return;let{copyMsgOnOnlyError:o}=this._config,l={logLevel:i,err:e};(o&&(t==null?void 0:t.copyMsg)!==!1||(t==null?void 0:t.copyMsg)===!0)&&(e!=null&&e.message)&&(l.params=[e.message]),this._formatLog(l)}metadataOnly(e,t=n.info){if(!this.isLevelEnabled(t))return;let{muteMetadata:i,consoleDebug:o}=this._config;if(i)return;if(!e){o&&console.debug("[LogLayer] metadataOnly was called with no metadata; dropping.");return}let l=e;if(this.pluginManager.hasPlugins(u.onMetadataCalled)&&(l=this.pluginManager.runOnMetadataCalled(e,this),!l)){o&&console.debug("[LogLayer] Metadata was dropped due to plugin returning falsy value.");return}let d={logLevel:t,metadata:l};this._formatLog(d)}info(...e){this.isLevelEnabled(n.info)&&(this._formatMessage(e),this._formatLog({logLevel:n.info,params:e}))}warn(...e){this.isLevelEnabled(n.warn)&&(this._formatMessage(e),this._formatLog({logLevel:n.warn,params:e}))}error(...e){this.isLevelEnabled(n.error)&&(this._formatMessage(e),this._formatLog({logLevel:n.error,params:e}))}debug(...e){this.isLevelEnabled(n.debug)&&(this._formatMessage(e),this._formatLog({logLevel:n.debug,params:e}))}trace(...e){this.isLevelEnabled(n.trace)&&(this._formatMessage(e),this._formatLog({logLevel:n.trace,params:e}))}fatal(...e){this.isLevelEnabled(n.fatal)&&(this._formatMessage(e),this._formatLog({logLevel:n.fatal,params:e}))}raw(e){if(!this.isLevelEnabled(e.logLevel))return;let t={logLevel:e.logLevel,params:e.messages,metadata:e.metadata,err:e.error,context:e.context};this._formatMessage(e.messages),this._formatLog(t)}disableLogging(){for(let e of Object.keys(this.logLevelEnabledStatus))this.logLevelEnabledStatus[e]=!1;return this}enableLogging(){for(let e of Object.keys(this.logLevelEnabledStatus))this.logLevelEnabledStatus[e]=!0;return this}muteContext(){return this._config.muteContext=!0,this}unMuteContext(){return this._config.muteContext=!1,this}muteMetadata(){return this._config.muteMetadata=!0,this}unMuteMetadata(){return this._config.muteMetadata=!1,this}enableIndividualLevel(e){let t=e;return t in this.logLevelEnabledStatus&&(this.logLevelEnabledStatus[t]=!0),this}disableIndividualLevel(e){let t=e;return t in this.logLevelEnabledStatus&&(this.logLevelEnabledStatus[t]=!1),this}setLevel(e){let t=M[e];for(let i of Object.values(n)){let o=i,l=M[i];this.logLevelEnabledStatus[o]=l>=t}return this}isLevelEnabled(e){let t=e;return this.logLevelEnabledStatus[t]}formatContext(e){let{contextFieldName:t,muteContext:i}=this._config;return e&&Object.keys(e).length>0&&!i?t?{[t]:a({},e)}:a({},e):{}}formatMetadata(e=null){let{metadataFieldName:t,muteMetadata:i}=this._config;return e&&!i?t?{[t]:a({},e)}:a({},e):{}}getLoggerInstance(e){let t=this.idToTransport[e];if(t)return t.getLoggerInstance()}_formatMessage(e=[]){let{prefix:t}=this._config;t&&typeof e[0]=="string"&&(e[0]=`${t} ${e[0]}`)}_formatLog({logLevel:e,params:t=[],metadata:i=null,err:o,context:l=null}){var P;let{errorSerializer:d,errorFieldInMetadata:O,muteContext:j,contextFieldName:v,metadataFieldName:f,errorFieldName:x}=this._config,p=l!==null?l:this.contextManager.getContext(),c=!!i||(j?!1:l!==null?Object.keys(l).length>0:this.contextManager.hasContextData()),g={};if(c)if(v&&v===f){let L=this.formatContext(p)[v],b=this.formatMetadata(i)[f];g={[v]:a(a({},L),b)}}else g=a(a({},this.formatContext(p)),this.formatMetadata(i));if(o){let L=d?d(o):o;O&&i&&f?g!=null&&g[f]?g[f][x]=L:g=m(a({},g),{[f]:{[x]:L}}):O&&!i&&f?g=m(a({},g),{[f]:{[x]:L}}):g=m(a({},g),{[x]:L}),c=!0}if(this.pluginManager.hasPlugins(u.onBeforeDataOut)&&(g=this.pluginManager.runOnBeforeDataOut({data:c?g:void 0,logLevel:e,error:o,metadata:i,context:p},this),g&&!c&&(c=!0)),this.pluginManager.hasPlugins(u.onBeforeMessageOut)&&(t=this.pluginManager.runOnBeforeMessageOut({messages:[...t],logLevel:e},this)),this.hasMultipleTransports){let L=this._config.transport.filter(b=>b.enabled).map(async b=>{if(!(this.pluginManager.hasPlugins(u.shouldSendToLogger)&&!this.pluginManager.runShouldSendToLogger({messages:[...t],data:c?g:void 0,logLevel:e,transportId:b.id,error:o,metadata:i,context:p},this)))return b._sendToLogger({logLevel:e,messages:[...t],data:c?g:void 0,hasData:c,error:o,metadata:i,context:p})});Promise.all(L).catch(b=>{this._config.consoleDebug&&console.error("[LogLayer] Error executing transports:",b)})}else{if(!((P=this.singleTransport)!=null&&P.enabled)||this.pluginManager.hasPlugins(u.shouldSendToLogger)&&!this.pluginManager.runShouldSendToLogger({messages:[...t],data:c?g:void 0,logLevel:e,transportId:this.singleTransport.id,error:o,metadata:i,context:p},this))return;this.singleTransport._sendToLogger({logLevel:e,messages:[...t],data:c?g:void 0,hasData:c,error:o,metadata:i,context:p})}}};function V(){let r={debug:()=>{},info:()=>{},warn:()=>{},error:()=>{}};return new B({transport:r})}function w(r){return r!=null?r:V()}import{RegistryManager as _}from"@kumori/kdsl-lsp/module/registry/manager.js";import{Ok as y,Err as T}from"@kumori/kdsl-lsp/util/result.js";async function Me(r){let e=w(r.logger),t=new _,i={selector:r.selector,version:r.version,indexUrl:r.url};try{return t.add(i),e.info(`Registry '${r.selector}' added at ${r.url}`),y(void 0)}catch(o){return T([`Failed to add registry: ${o}`])}}async function ve(r={}){let e=w(r.logger),t=new _;try{let i=t.list();return e.info("Configured Registries:"),y(i)}catch(i){return T([`Failed to list registries: ${i}`])}}async function xe(r){let e=w(r.logger),t=new _;try{return t.remove(r.name),e.info(`Registry '${r.name}' removed`),y(void 0)}catch(i){return T([`Failed to remove registry: ${i}`])}}export{Me as registryAdd,ve as registryList,xe as registryRemove};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/lib/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAA;AAC7E,OAAO,EAAE,EAAE,EAAE,GAAG,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c,CAClC,OAA8B;IAE9B,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACrC,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAA;IAErC,IAAI,CAAC;QACH,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QAC5B,GAAG,CAAC,IAAI,CAAC,aAAa,OAAO,CAAC,IAAI,WAAW,CAAC,CAAA;QAC9C,OAAO,EAAE,CAAO,SAAS,CAAC,CAAA;IAC5B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC,CAAA;IACnD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ILogLayer } from "loglayer";
|
|
2
|
+
import { KumoriServices } from "@kumori/kdsl-lsp/language/kumori.js";
|
|
3
|
+
import { Result } from "@kumori/kdsl-lsp/util/result.js";
|
|
4
|
+
/**
|
|
5
|
+
* Base options for all library functions
|
|
6
|
+
*/
|
|
7
|
+
export interface LibraryOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Kumori language services instance.
|
|
10
|
+
* Create using: createKumoriServices(NodeFileSystem).Kumori
|
|
11
|
+
*/
|
|
12
|
+
services: KumoriServices;
|
|
13
|
+
/**
|
|
14
|
+
* Optional logger for output.
|
|
15
|
+
* If not provided, a silent logger is used.
|
|
16
|
+
*/
|
|
17
|
+
logger?: ILogLayer;
|
|
18
|
+
/**
|
|
19
|
+
* Working directory. Defaults to process.cwd()
|
|
20
|
+
*/
|
|
21
|
+
cwd?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Standard result type for library functions
|
|
25
|
+
*/
|
|
26
|
+
export type LibraryResult<T> = Result<T, string[]>;
|