@k8ts/instruments 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +7 -0
- package/README.md +3 -0
- package/dist/_embedder/base.d.ts +11 -0
- package/dist/_embedder/base.d.ts.map +1 -0
- package/dist/_embedder/base.js +39 -0
- package/dist/_embedder/base.js.map +1 -0
- package/dist/_embedder/index.d.ts +2 -0
- package/dist/_embedder/index.d.ts.map +1 -0
- package/dist/_embedder/index.js +18 -0
- package/dist/_embedder/index.js.map +1 -0
- package/dist/_string/index.d.ts +6 -0
- package/dist/_string/index.d.ts.map +1 -0
- package/dist/_string/index.js +22 -0
- package/dist/_string/index.js.map +1 -0
- package/dist/_string/markers.d.ts +3 -0
- package/dist/_string/markers.d.ts.map +1 -0
- package/dist/_string/markers.js +48 -0
- package/dist/_string/markers.js.map +1 -0
- package/dist/_string/post-processor.d.ts +7 -0
- package/dist/_string/post-processor.d.ts.map +1 -0
- package/dist/_string/post-processor.js +30 -0
- package/dist/_string/post-processor.js.map +1 -0
- package/dist/_string/pretty-objects.d.ts +27 -0
- package/dist/_string/pretty-objects.d.ts.map +1 -0
- package/dist/_string/pretty-objects.js +192 -0
- package/dist/_string/pretty-objects.js.map +1 -0
- package/dist/_string/pretty-print.d.ts +2 -0
- package/dist/_string/pretty-print.d.ts.map +1 -0
- package/dist/_string/pretty-print.js +27 -0
- package/dist/_string/pretty-print.js.map +1 -0
- package/dist/_string/super-script.d.ts +2 -0
- package/dist/_string/super-script.d.ts.map +1 -0
- package/dist/_string/super-script.js +20 -0
- package/dist/_string/super-script.js.map +1 -0
- package/dist/api-kind/index.d.ts +43 -0
- package/dist/api-kind/index.d.ts.map +1 -0
- package/dist/api-kind/index.js +102 -0
- package/dist/api-kind/index.js.map +1 -0
- package/dist/cmd/cli-command.d.ts +23 -0
- package/dist/cmd/cli-command.d.ts.map +1 -0
- package/dist/cmd/cli-command.js +73 -0
- package/dist/cmd/cli-command.js.map +1 -0
- package/dist/cmd/cli-term.d.ts +25 -0
- package/dist/cmd/cli-term.d.ts.map +1 -0
- package/dist/cmd/cli-term.js +55 -0
- package/dist/cmd/cli-term.js.map +1 -0
- package/dist/cmd/index.d.ts +3 -0
- package/dist/cmd/index.d.ts.map +1 -0
- package/dist/cmd/index.js +7 -0
- package/dist/cmd/index.js.map +1 -0
- package/dist/cmd/types.d.ts +5 -0
- package/dist/cmd/types.d.ts.map +1 -0
- package/dist/cmd/types.js +3 -0
- package/dist/cmd/types.js.map +1 -0
- package/dist/displayers/displayers.d.ts +33 -0
- package/dist/displayers/displayers.d.ts.map +1 -0
- package/dist/displayers/displayers.js +129 -0
- package/dist/displayers/displayers.js.map +1 -0
- package/dist/displayers/index.d.ts +2 -0
- package/dist/displayers/index.d.ts.map +1 -0
- package/dist/displayers/index.js +18 -0
- package/dist/displayers/index.js.map +1 -0
- package/dist/env/env.d.ts +20 -0
- package/dist/env/env.d.ts.map +1 -0
- package/dist/env/env.js +68 -0
- package/dist/env/env.js.map +1 -0
- package/dist/env/index.d.ts +3 -0
- package/dist/env/index.d.ts.map +1 -0
- package/dist/env/index.js +7 -0
- package/dist/env/index.js.map +1 -0
- package/dist/env/types.d.ts +4 -0
- package/dist/env/types.d.ts.map +1 -0
- package/dist/env/types.js +3 -0
- package/dist/env/types.js.map +1 -0
- package/dist/env/validate-name.d.ts +2 -0
- package/dist/env/validate-name.d.ts.map +1 -0
- package/dist/env/validate-name.js +12 -0
- package/dist/env/validate-name.js.map +1 -0
- package/dist/error.d.ts +8 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +20 -0
- package/dist/error.js.map +1 -0
- package/dist/forward-exports/delayed-exports.d.ts +18 -0
- package/dist/forward-exports/delayed-exports.d.ts.map +1 -0
- package/dist/forward-exports/delayed-exports.js +119 -0
- package/dist/forward-exports/delayed-exports.js.map +1 -0
- package/dist/forward-exports/index.d.ts +2 -0
- package/dist/forward-exports/index.d.ts.map +1 -0
- package/dist/forward-exports/index.js +18 -0
- package/dist/forward-exports/index.js.map +1 -0
- package/dist/graph/base-node.d.ts +34 -0
- package/dist/graph/base-node.d.ts.map +1 -0
- package/dist/graph/base-node.js +102 -0
- package/dist/graph/base-node.js.map +1 -0
- package/dist/graph/base-origin-entity.d.ts +19 -0
- package/dist/graph/base-origin-entity.d.ts.map +1 -0
- package/dist/graph/base-origin-entity.js +105 -0
- package/dist/graph/base-origin-entity.js.map +1 -0
- package/dist/graph/dependencies.d.ts +12 -0
- package/dist/graph/dependencies.d.ts.map +1 -0
- package/dist/graph/dependencies.js +82 -0
- package/dist/graph/dependencies.js.map +1 -0
- package/dist/graph/index.d.ts +7 -0
- package/dist/graph/index.d.ts.map +1 -0
- package/dist/graph/index.js +23 -0
- package/dist/graph/index.js.map +1 -0
- package/dist/graph/origin-node.d.ts +32 -0
- package/dist/graph/origin-node.d.ts.map +1 -0
- package/dist/graph/origin-node.js +161 -0
- package/dist/graph/origin-node.js.map +1 -0
- package/dist/graph/relations.d.ts +26 -0
- package/dist/graph/relations.d.ts.map +1 -0
- package/dist/graph/relations.js +38 -0
- package/dist/graph/relations.js.map +1 -0
- package/dist/graph/resource-node.d.ts +28 -0
- package/dist/graph/resource-node.d.ts.map +1 -0
- package/dist/graph/resource-node.js +144 -0
- package/dist/graph/resource-node.js.map +1 -0
- package/dist/image/family.d.ts +26 -0
- package/dist/image/family.d.ts.map +1 -0
- package/dist/image/family.js +63 -0
- package/dist/image/family.js.map +1 -0
- package/dist/image/index.d.ts +2 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +9 -0
- package/dist/image/index.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/dist/index.js.map +1 -0
- package/dist/kind-map/index.d.ts +44 -0
- package/dist/kind-map/index.d.ts.map +1 -0
- package/dist/kind-map/index.js +123 -0
- package/dist/kind-map/index.js.map +1 -0
- package/dist/manifest/index.d.ts +46 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +21 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest-builder.d.ts +45 -0
- package/dist/manifest/manifest-builder.d.ts.map +1 -0
- package/dist/manifest/manifest-builder.js +66 -0
- package/dist/manifest/manifest-builder.js.map +1 -0
- package/dist/ports/error.d.ts +5 -0
- package/dist/ports/error.d.ts.map +1 -0
- package/dist/ports/error.js +13 -0
- package/dist/ports/error.js.map +1 -0
- package/dist/ports/index.d.ts +7 -0
- package/dist/ports/index.d.ts.map +1 -0
- package/dist/ports/index.js +13 -0
- package/dist/ports/index.js.map +1 -0
- package/dist/ports/map.d.ts +13 -0
- package/dist/ports/map.d.ts.map +1 -0
- package/dist/ports/map.js +38 -0
- package/dist/ports/map.js.map +1 -0
- package/dist/ports/set.d.ts +18 -0
- package/dist/ports/set.d.ts.map +1 -0
- package/dist/ports/set.js +60 -0
- package/dist/ports/set.js.map +1 -0
- package/dist/ports/tools/entry.d.ts +6 -0
- package/dist/ports/tools/entry.d.ts.map +1 -0
- package/dist/ports/tools/entry.js +36 -0
- package/dist/ports/tools/entry.js.map +1 -0
- package/dist/ports/tools/parse.d.ts +3 -0
- package/dist/ports/tools/parse.d.ts.map +1 -0
- package/dist/ports/tools/parse.js +35 -0
- package/dist/ports/tools/parse.js.map +1 -0
- package/dist/ports/types.d.ts +37 -0
- package/dist/ports/types.d.ts.map +1 -0
- package/dist/ports/types.js +3 -0
- package/dist/ports/types.js.map +1 -0
- package/dist/producer/index.d.ts +2 -0
- package/dist/producer/index.d.ts.map +1 -0
- package/dist/producer/index.js +18 -0
- package/dist/producer/index.js.map +1 -0
- package/dist/producer/producer.d.ts +6 -0
- package/dist/producer/producer.d.ts.map +1 -0
- package/dist/producer/producer.js +13 -0
- package/dist/producer/producer.js.map +1 -0
- package/dist/ref-key/index.d.ts +2 -0
- package/dist/ref-key/index.d.ts.map +1 -0
- package/dist/ref-key/index.js +18 -0
- package/dist/ref-key/index.js.map +1 -0
- package/dist/ref-key/ref-key.d.ts +23 -0
- package/dist/ref-key/ref-key.d.ts.map +1 -0
- package/dist/ref-key/ref-key.js +67 -0
- package/dist/ref-key/ref-key.js.map +1 -0
- package/dist/reference/forward-ref.d.ts +22 -0
- package/dist/reference/forward-ref.d.ts.map +1 -0
- package/dist/reference/forward-ref.js +126 -0
- package/dist/reference/forward-ref.js.map +1 -0
- package/dist/reference/index.d.ts +4 -0
- package/dist/reference/index.d.ts.map +1 -0
- package/dist/reference/index.js +8 -0
- package/dist/reference/index.js.map +1 -0
- package/dist/reference/refable.d.ts +12 -0
- package/dist/reference/refable.d.ts.map +1 -0
- package/dist/reference/refable.js +3 -0
- package/dist/reference/refable.js.map +1 -0
- package/dist/resources/index.d.ts +3 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +19 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/objects.d.ts +22 -0
- package/dist/resources/objects.d.ts.map +1 -0
- package/dist/resources/objects.js +93 -0
- package/dist/resources/objects.js.map +1 -0
- package/dist/resources/parser.d.ts +4 -0
- package/dist/resources/parser.d.ts.map +1 -0
- package/dist/resources/parser.js +21 -0
- package/dist/resources/parser.js.map +1 -0
- package/dist/resources/types.d.ts +18 -0
- package/dist/resources/types.d.ts.map +1 -0
- package/dist/resources/types.js +3 -0
- package/dist/resources/types.js.map +1 -0
- package/dist/src.tsbuildinfo +1 -0
- package/dist/test.tsbuildinfo +1 -0
- package/dist/tracing/git.d.ts +19 -0
- package/dist/tracing/git.d.ts.map +1 -0
- package/dist/tracing/git.js +45 -0
- package/dist/tracing/git.js.map +1 -0
- package/dist/tracing/index.d.ts +4 -0
- package/dist/tracing/index.d.ts.map +1 -0
- package/dist/tracing/index.js +20 -0
- package/dist/tracing/index.js.map +1 -0
- package/dist/tracing/trace.d.ts +11 -0
- package/dist/tracing/trace.d.ts.map +1 -0
- package/dist/tracing/trace.js +27 -0
- package/dist/tracing/trace.js.map +1 -0
- package/dist/tracing/traced.d.ts +4 -0
- package/dist/tracing/traced.d.ts.map +1 -0
- package/dist/tracing/traced.js +6 -0
- package/dist/tracing/traced.js.map +1 -0
- package/dist/units/index.d.ts +3 -0
- package/dist/units/index.d.ts.map +1 -0
- package/dist/units/index.js +22 -0
- package/dist/units/index.js.map +1 -0
- package/dist/units/unit-parser.d.ts +19 -0
- package/dist/units/unit-parser.d.ts.map +1 -0
- package/dist/units/unit-parser.js +53 -0
- package/dist/units/unit-parser.js.map +1 -0
- package/dist/units/units.d.ts +37 -0
- package/dist/units/units.d.ts.map +1 -0
- package/dist/units/units.js +36 -0
- package/dist/units/units.js.map +1 -0
- package/package.json +89 -0
- package/src/_embedder/base.ts +42 -0
- package/src/_embedder/index.ts +1 -0
- package/src/_string/index.ts +5 -0
- package/src/_string/markers.ts +47 -0
- package/src/_string/post-processor.ts +25 -0
- package/src/_string/pretty-objects.ts +65 -0
- package/src/_string/pretty-print.ts +24 -0
- package/src/_string/super-script.ts +17 -0
- package/src/api-kind/index.ts +134 -0
- package/src/cmd/cli-command.ts +89 -0
- package/src/cmd/cli-term.ts +60 -0
- package/src/cmd/index.ts +2 -0
- package/src/cmd/types.ts +4 -0
- package/src/displayers/displayers.ts +147 -0
- package/src/displayers/index.ts +1 -0
- package/src/env/env.ts +74 -0
- package/src/env/index.ts +2 -0
- package/src/env/types.ts +7 -0
- package/src/env/validate-name.ts +10 -0
- package/src/error.ts +15 -0
- package/src/forward-exports/delayed-exports.ts +155 -0
- package/src/forward-exports/index.ts +1 -0
- package/src/graph/base-node.ts +125 -0
- package/src/graph/base-origin-entity.ts +44 -0
- package/src/graph/dependencies.ts +27 -0
- package/src/graph/index.ts +6 -0
- package/src/graph/origin-node.ts +118 -0
- package/src/graph/relations.ts +62 -0
- package/src/graph/resource-node.ts +104 -0
- package/src/image/family.ts +71 -0
- package/src/image/index.ts +1 -0
- package/src/index.ts +18 -0
- package/src/kind-map/index.ts +150 -0
- package/src/manifest/index.ts +53 -0
- package/src/manifest/manifest-builder.ts +98 -0
- package/src/ports/error.ts +8 -0
- package/src/ports/index.ts +8 -0
- package/src/ports/map.ts +41 -0
- package/src/ports/set.ts +79 -0
- package/src/ports/tools/entry.ts +43 -0
- package/src/ports/tools/parse.ts +40 -0
- package/src/ports/types.ts +42 -0
- package/src/producer/index.ts +1 -0
- package/src/producer/producer.ts +18 -0
- package/src/ref-key/index.ts +1 -0
- package/src/ref-key/ref-key.ts +76 -0
- package/src/reference/forward-ref.ts +122 -0
- package/src/reference/index.ts +3 -0
- package/src/reference/refable.ts +11 -0
- package/src/resources/index.ts +2 -0
- package/src/resources/objects.ts +99 -0
- package/src/resources/parser.ts +24 -0
- package/src/resources/types.ts +23 -0
- package/src/tracing/git.ts +51 -0
- package/src/tracing/index.ts +3 -0
- package/src/tracing/trace.ts +31 -0
- package/src/tracing/traced.ts +4 -0
- package/src/tsconfig.json +10 -0
- package/src/units/index.ts +2 -0
- package/src/units/unit-parser.ts +63 -0
- package/src/units/units.ts +53 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./git"), exports);
|
|
18
|
+
__exportStar(require("./trace"), exports);
|
|
19
|
+
__exportStar(require("./traced"), exports);
|
|
20
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAqB;AACrB,0CAAuB;AACvB,2CAAwB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import StackTracey from "stacktracey";
|
|
2
|
+
export interface TraceFormatOptions {
|
|
3
|
+
cwd: string;
|
|
4
|
+
absolute: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class Trace {
|
|
7
|
+
readonly trace: StackTracey.Entry;
|
|
8
|
+
constructor(trace: StackTracey);
|
|
9
|
+
format(inOptions?: Partial<TraceFormatOptions>): string;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=trace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.d.ts","sourceRoot":"","sources":["../../src/tracing/trace.ts"],"names":[],"mappings":"AAEA,OAAO,WAAW,MAAM,aAAa,CAAA;AAErC,MAAM,WAAW,kBAAkB;IAC/B,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,OAAO,CAAA;CACpB;AAED,qBAAa,KAAK;IACd,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,KAAK,CAAA;gBACrB,KAAK,EAAE,WAAW;IAO9B,MAAM,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC;CAYjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Trace = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
class Trace {
|
|
7
|
+
constructor(trace) {
|
|
8
|
+
const findGoodFrame = (e) => {
|
|
9
|
+
return !e.native && e.file && !e.file.includes("node:");
|
|
10
|
+
};
|
|
11
|
+
this.trace = trace.filter(x => !!findGoodFrame(x)).at(0);
|
|
12
|
+
}
|
|
13
|
+
format(inOptions) {
|
|
14
|
+
const e = this.trace;
|
|
15
|
+
const options = (0, lodash_1.defaults)(inOptions, {
|
|
16
|
+
cwd: ".",
|
|
17
|
+
absolute: false
|
|
18
|
+
});
|
|
19
|
+
options.cwd = (0, path_1.resolve)(options.cwd);
|
|
20
|
+
const sourcePath = options.absolute ? e.file : (0, path_1.relative)(options.cwd, e.file);
|
|
21
|
+
const relativeToCwd = (0, path_1.relative)(options.cwd, sourcePath);
|
|
22
|
+
const sourceLocation = `${relativeToCwd}:${e.line}:${e.column}`;
|
|
23
|
+
return sourceLocation;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.Trace = Trace;
|
|
27
|
+
//# sourceMappingURL=trace.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trace.js","sourceRoot":"","sources":["../../src/tracing/trace.ts"],"names":[],"mappings":";;;AAAA,mCAAiC;AACjC,+BAAwC;AAQxC,MAAa,KAAK;IAEd,YAAY,KAAkB;QAC1B,MAAM,aAAa,GAAG,CAAC,CAAoB,EAAE,EAAE;YAC3C,OAAO,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAA;QAC3D,CAAC,CAAA;QACD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;IAC5D,CAAC;IAED,MAAM,CAAC,SAAuC;QAC1C,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAA;QACpB,MAAM,OAAO,GAAG,IAAA,iBAAQ,EAAC,SAAS,EAAE;YAChC,GAAG,EAAE,GAAG;YACR,QAAQ,EAAE,KAAK;SAClB,CAAuB,CAAA;QACxB,OAAO,CAAC,GAAG,GAAG,IAAA,cAAO,EAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAClC,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAA,eAAQ,EAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;QAC5E,MAAM,aAAa,GAAG,IAAA,eAAQ,EAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAA;QACvD,MAAM,cAAc,GAAG,GAAG,aAAa,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,MAAM,EAAE,CAAA;QAC/D,OAAO,cAAc,CAAA;IACzB,CAAC;CACJ;AArBD,sBAqBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.d.ts","sourceRoot":"","sources":["../../src/tracing/traced.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAE/B,eAAO,MAAM,aAAa,yBAAwC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traced.js","sourceRoot":"","sources":["../../src/tracing/traced.ts"],"names":[],"mappings":";;;AAAA,4CAAuC;AAG1B,QAAA,aAAa,GAAG,IAAI,oBAAQ,CAAgB,QAAQ,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/units/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAA;AACrD,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.UnitValue = exports.UnitParser = void 0;
|
|
18
|
+
var unit_parser_1 = require("./unit-parser");
|
|
19
|
+
Object.defineProperty(exports, "UnitParser", { enumerable: true, get: function () { return unit_parser_1.UnitParser; } });
|
|
20
|
+
Object.defineProperty(exports, "UnitValue", { enumerable: true, get: function () { return unit_parser_1.UnitValue; } });
|
|
21
|
+
__exportStar(require("./units"), exports);
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/units/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6CAAqD;AAA5C,yGAAA,UAAU,OAAA;AAAE,wGAAA,SAAS,OAAA;AAC9B,0CAAuB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Set } from "immutable";
|
|
2
|
+
import { type Parjser } from "parjs";
|
|
3
|
+
export declare class UnitValue<Unit extends string = string> {
|
|
4
|
+
readonly unit: Unit;
|
|
5
|
+
readonly value: number;
|
|
6
|
+
readonly type: string;
|
|
7
|
+
constructor(unit: Unit, value: number, type: string);
|
|
8
|
+
get str(): string;
|
|
9
|
+
toString(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare class UnitParser<const Unit extends string = string> {
|
|
12
|
+
private readonly unitType;
|
|
13
|
+
private readonly _units;
|
|
14
|
+
readonly parser: Parjser<UnitValue<Unit>>;
|
|
15
|
+
constructor(unitType: string, _units: Set<Unit>);
|
|
16
|
+
parse: (input: `${number}${Unit}`) => UnitValue<Unit>;
|
|
17
|
+
static make<const Unit extends string>(unitType: string, units: Set<Unit>): UnitParser<Unit>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=unit-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-parser.d.ts","sourceRoot":"","sources":["../../src/units/unit-parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAC/B,OAAO,EAAe,KAAK,OAAO,EAAE,MAAM,OAAO,CAAA;AAYjD,qBAAa,SAAS,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAE3C,QAAQ,CAAC,IAAI,EAAE,IAAI;IACnB,QAAQ,CAAC,KAAK,EAAE,MAAM;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM;gBAFZ,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM;IAGzB,IAAI,GAAG,WAEN;IAED,QAAQ;CAGX;AAED,qBAAa,UAAU,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM;IAGlD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAH3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAA;gBAEpB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC;IAetC,KAAK,GAAI,OAAO,GAAG,MAAM,GAAG,IAAI,EAAE,qBASjC;IAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,SAAS,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,CAAC,IAAI,CAAC;CAG5E"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UnitParser = exports.UnitValue = void 0;
|
|
4
|
+
const parjs_1 = require("parjs");
|
|
5
|
+
const combinators_1 = require("parjs/combinators");
|
|
6
|
+
const error_1 = require("../error");
|
|
7
|
+
const pUnit = (0, parjs_1.letter)().pipe((0, combinators_1.many1)(2), (0, combinators_1.stringify)());
|
|
8
|
+
const pValueUnit = (0, parjs_1.int)().pipe((0, combinators_1.then)(pUnit), (0, combinators_1.map)(arr => {
|
|
9
|
+
const [value, unit] = arr;
|
|
10
|
+
return { value, unit };
|
|
11
|
+
}));
|
|
12
|
+
class UnitValue {
|
|
13
|
+
constructor(unit, value, type) {
|
|
14
|
+
this.unit = unit;
|
|
15
|
+
this.value = value;
|
|
16
|
+
this.type = type;
|
|
17
|
+
}
|
|
18
|
+
get str() {
|
|
19
|
+
return `${this.value}${this.unit}`;
|
|
20
|
+
}
|
|
21
|
+
toString() {
|
|
22
|
+
return this.str;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.UnitValue = UnitValue;
|
|
26
|
+
class UnitParser {
|
|
27
|
+
constructor(unitType, _units) {
|
|
28
|
+
this.unitType = unitType;
|
|
29
|
+
this._units = _units;
|
|
30
|
+
this.parse = (input) => {
|
|
31
|
+
const pUnitValue = this.parser;
|
|
32
|
+
const result = pUnitValue.parse(input);
|
|
33
|
+
if (result.kind !== "OK") {
|
|
34
|
+
throw new error_1.InstrumentsError(`Failed to parse ${this.unitType}`, {
|
|
35
|
+
more: result.trace.toString()
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
return result.value;
|
|
39
|
+
};
|
|
40
|
+
this.parser = pValueUnit.pipe((0, combinators_1.map)(({ value, unit }) => {
|
|
41
|
+
const gotType = this._units.has(unit);
|
|
42
|
+
if (!gotType) {
|
|
43
|
+
throw new error_1.InstrumentsError(`Unit ${unit} is not a valid unit of type ${this.unitType}`);
|
|
44
|
+
}
|
|
45
|
+
return new UnitValue(unit, value, this.unitType);
|
|
46
|
+
}));
|
|
47
|
+
}
|
|
48
|
+
static make(unitType, units) {
|
|
49
|
+
return new UnitParser(unitType, units);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.UnitParser = UnitParser;
|
|
53
|
+
//# sourceMappingURL=unit-parser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit-parser.js","sourceRoot":"","sources":["../../src/units/unit-parser.ts"],"names":[],"mappings":";;;AACA,iCAAiD;AACjD,mDAA+D;AAC/D,oCAA2C;AAC3C,MAAM,KAAK,GAAG,IAAA,cAAM,GAAE,CAAC,IAAI,CAAC,IAAA,mBAAK,EAAC,CAAC,CAAC,EAAE,IAAA,uBAAS,GAAE,CAAC,CAAA;AAElD,MAAM,UAAU,GAAG,IAAA,WAAG,GAAE,CAAC,IAAI,CACzB,IAAA,kBAAI,EAAC,KAAK,CAAC,EACX,IAAA,iBAAG,EAAC,GAAG,CAAC,EAAE;IACN,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,GAAG,CAAA;IACzB,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAA;AAC1B,CAAC,CAAC,CACL,CAAA;AACD,MAAa,SAAS;IAClB,YACa,IAAU,EACV,KAAa,EACb,IAAY;QAFZ,SAAI,GAAJ,IAAI,CAAM;QACV,UAAK,GAAL,KAAK,CAAQ;QACb,SAAI,GAAJ,IAAI,CAAQ;IACtB,CAAC;IAEJ,IAAI,GAAG;QACH,OAAO,G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,CAAO,QAAQ,EAAE,KAAK,CAAC,CAAA;IAChD,CAAC;CACJ;AAjCD,gCAiCC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { UnitParser } from "./unit-parser";
|
|
2
|
+
export type G = `${number}G`;
|
|
3
|
+
export declare const G: (n: number) => G;
|
|
4
|
+
export type M = `${number}M`;
|
|
5
|
+
export declare const M: (n: number) => M;
|
|
6
|
+
export type K = `${number}K`;
|
|
7
|
+
export declare const K: (n: number) => K;
|
|
8
|
+
export type T = `${number}T`;
|
|
9
|
+
export declare const T: (n: number) => T;
|
|
10
|
+
export type Gi = `${number}Gi`;
|
|
11
|
+
export declare const Gi: (n: number) => Gi;
|
|
12
|
+
export type Mi = `${number}Mi`;
|
|
13
|
+
export declare const Mi: (n: number) => Mi;
|
|
14
|
+
export type Ki = `${number}Ki`;
|
|
15
|
+
export declare const Ki: (n: number) => Ki;
|
|
16
|
+
export type m = `${number}m`;
|
|
17
|
+
export declare const m: (n: number) => m;
|
|
18
|
+
export type h = `${number}h`;
|
|
19
|
+
export declare const h: (n: number) => h;
|
|
20
|
+
export type d = `${number}d`;
|
|
21
|
+
export declare const d: (n: number) => d;
|
|
22
|
+
export type s = `${number}s`;
|
|
23
|
+
export declare const s: (n: number) => s;
|
|
24
|
+
export type ms = `${number}ms`;
|
|
25
|
+
export declare const ms: (n: number) => ms;
|
|
26
|
+
export interface UnitDefinition<Unit extends string> {
|
|
27
|
+
}
|
|
28
|
+
export declare namespace Unit {
|
|
29
|
+
type Data = M | G | T | K | Mi | Gi | Ki;
|
|
30
|
+
type Cpu = m;
|
|
31
|
+
type Time = m | h | d | s | ms;
|
|
32
|
+
type Any = Data | Cpu | Time;
|
|
33
|
+
const Cpu: UnitParser<"m">;
|
|
34
|
+
const Data: UnitParser<"G" | "K" | "M" | "T" | "Mi" | "Gi" | "Ki">;
|
|
35
|
+
const Time: UnitParser<"d" | "h" | "m" | "s" | "ms">;
|
|
36
|
+
}
|
|
37
|
+
//# source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,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,GAAG,CAAA;AAC5B,eAAO,MAAM,CAAC,GAAI,GAAG,MAAM,KAAqB,CAAC,CAAA;AAEjD,MAAM,MAAM,CAAC,GAAG,GAAG,MAAM,GAAG,CAAA;AAC5B,eAAO,MAAM,CAAC,GAAI,GAAG,MAAM,KAAgB,CAAC,CAAA;AAE5C,MAAM,MAAM,EAAE,GAAG,GAAG,MAAM,IAAI,CAAA;AAC9B,eAAO,MAAM,EAAE,GAAI,GAAG,MAAM,KAAiB,EAAE,CAAA;AAE/C,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,MAAM;CAAI;AAEvD,yBAAiB,IAAI,CAAC;IAClB,KAAY,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAA;IAC/C,KAAY,GAAG,GAAG,CAAC,CAAA;IACnB,KAAY,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAA;IACrC,KAAY,GAAG,GAAG,IAAI,GAAG,GAAG,GAAG,IAAI,CAAA;IAE5B,MAAM,GAAG,iBAAqC,CAAA;IAE9C,MAAM,IAAI,wDAAuE,CAAA;IAEjF,MAAM,IAAI,0CAA2D,CAAA;CAC/E"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Unit = exports.ms = exports.s = exports.d = exports.h = exports.m = exports.Ki = exports.Mi = exports.Gi = exports.T = exports.K = exports.M = exports.G = void 0;
|
|
4
|
+
const immutable_1 = require("immutable");
|
|
5
|
+
const unit_parser_1 = require("./unit-parser");
|
|
6
|
+
const G = (n) => `${n}G`;
|
|
7
|
+
exports.G = G;
|
|
8
|
+
const M = (n) => `${n}M`;
|
|
9
|
+
exports.M = M;
|
|
10
|
+
const K = (n) => `${n}K`;
|
|
11
|
+
exports.K = K;
|
|
12
|
+
const T = (n) => `${n}T`;
|
|
13
|
+
exports.T = T;
|
|
14
|
+
const Gi = (n) => `${n}Gi`;
|
|
15
|
+
exports.Gi = Gi;
|
|
16
|
+
const Mi = (n) => `${n}Mi`;
|
|
17
|
+
exports.Mi = Mi;
|
|
18
|
+
const Ki = (n) => `${n}Ki`;
|
|
19
|
+
exports.Ki = Ki;
|
|
20
|
+
const m = (n) => `${n}m`;
|
|
21
|
+
exports.m = m;
|
|
22
|
+
const h = (n) => `${n}h`;
|
|
23
|
+
exports.h = h;
|
|
24
|
+
const d = (n) => `${n * 24}h`;
|
|
25
|
+
exports.d = d;
|
|
26
|
+
const s = (n) => `${n}s`;
|
|
27
|
+
exports.s = s;
|
|
28
|
+
const ms = (n) => `${n}ms`;
|
|
29
|
+
exports.ms = ms;
|
|
30
|
+
var Unit;
|
|
31
|
+
(function (Unit) {
|
|
32
|
+
Unit.Cpu = unit_parser_1.UnitParser.make("cpu", (0, immutable_1.Set)(["m"]));
|
|
33
|
+
Unit.Data = unit_parser_1.UnitParser.make("data", (0, immutable_1.Set)(["M", "G", "T", "K", "Mi", "Gi", "Ki"]));
|
|
34
|
+
Unit.Time = unit_parser_1.UnitParser.make("time", (0, immutable_1.Set)(["m", "h", "d", "s", "ms"]));
|
|
35
|
+
})(Unit || (exports.Unit = Unit = {}));
|
|
36
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units/units.ts"],"names":[],"mappings":";;;AAAA,yCAA+B;AAC/B,+CAA0C;AAGnC,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,GAAQ,CAAA;AAA/B,QAAA,CAAC,KAA8B;AAGrC,MAAM,CAAC,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,GAAG,CAAC,GAAQ,CAAA;AAA/B,QAAA,CAAC,KAA8B;AAGrC,MAAM,C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GAAG,wBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAA,eAAG,EAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;IAE3E,SAAI,GAAG,wBAAU,CAAC,IAAI,CAAC,MAAM,EAAE,IAAA,eAAG,EAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,CAAC,CAAA;AAChF,CAAC,EAXgB,IAAI,oBAAJ,IAAI,QAWpB"}
|
package/package.json
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@k8ts/instruments",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A collection of utilities and core components for k8ts.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"kubernetes",
|
|
7
|
+
"typescript",
|
|
8
|
+
"manifests",
|
|
9
|
+
"build",
|
|
10
|
+
"helm",
|
|
11
|
+
"cdk8s"
|
|
12
|
+
],
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/GregRos/k8ts/issues"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "github:GregRos/k8ts",
|
|
19
|
+
"directory": "packages/instruments"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"author": "GregRos <gregros@gregros.dev>",
|
|
23
|
+
"contributors": [
|
|
24
|
+
{
|
|
25
|
+
"name": "GregRos",
|
|
26
|
+
"email": "gregros@gregros.dev"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"require": "./dist/index.js",
|
|
33
|
+
"import": "./dist/index.js",
|
|
34
|
+
"default": "./dist/index.js",
|
|
35
|
+
"types": "./dist/index.d.ts"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"main": "dist/index.js",
|
|
39
|
+
"types": "dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"src",
|
|
42
|
+
"dist",
|
|
43
|
+
"package.json",
|
|
44
|
+
"LICENSE.md",
|
|
45
|
+
"README.md",
|
|
46
|
+
"tsconfig.json"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "tsc -b .",
|
|
50
|
+
"build:clean": "run-s clean build",
|
|
51
|
+
"watch": "tsc -b . --watch",
|
|
52
|
+
"clean": "shx rm -rf dist",
|
|
53
|
+
"test": "jest",
|
|
54
|
+
"test:coverage": "jest --coverage"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@k8ts/metadata": "workspace:^",
|
|
58
|
+
"chalk": "4.1.2",
|
|
59
|
+
"dayjs": "^1.11.13",
|
|
60
|
+
"doddle": "^5.0.0-beta.13",
|
|
61
|
+
"immutable": "^5.0.3",
|
|
62
|
+
"lodash": "^4.17.21",
|
|
63
|
+
"parjs": "^1.3.9",
|
|
64
|
+
"simple-git": "^3.27.0",
|
|
65
|
+
"stacktracey": "^2.1.8"
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@swc/core": "^1.11.11",
|
|
69
|
+
"@swc/jest": "^0.2.37",
|
|
70
|
+
"@types/jest": "^29.5.12",
|
|
71
|
+
"@types/lodash": "^4.17.16",
|
|
72
|
+
"@types/node": "20.9.1",
|
|
73
|
+
"declare-it": "^2.1.0",
|
|
74
|
+
"jest": "^29.7.0",
|
|
75
|
+
"npm-run-all": "^4.1.5",
|
|
76
|
+
"shx": "^0.3.4",
|
|
77
|
+
"ts-jest": "^29.2.6",
|
|
78
|
+
"ts-node": "^10.9.2",
|
|
79
|
+
"typescript": "^5.8.2",
|
|
80
|
+
"yamprint": "^0.8.4"
|
|
81
|
+
},
|
|
82
|
+
"peerDependencies": {
|
|
83
|
+
"@k8ts/metadata": "^0.1.0"
|
|
84
|
+
},
|
|
85
|
+
"packageManager": "yarn@4.1.1",
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=16.0.0"
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export class Embedder<Target extends object, Value> {
|
|
2
|
+
private _symbol!: symbol
|
|
3
|
+
constructor(readonly name: string) {
|
|
4
|
+
this._symbol = Symbol.for(`build.k8ts.org/${name}`)
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
[Symbol.toStringTag]() {
|
|
8
|
+
return `Embedder(${this.name})`
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toString() {
|
|
12
|
+
return this[Symbol.toStringTag]()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
set(target: Target, data: Value) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(target, this._symbol)) {
|
|
17
|
+
throw new Error(`Decorator ${this.name} already set!`)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Object.defineProperty(target, this._symbol, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
value: data,
|
|
23
|
+
writable: true,
|
|
24
|
+
configurable: true
|
|
25
|
+
})
|
|
26
|
+
return this
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
tryGet(target: Target): Value | undefined {
|
|
30
|
+
return Reflect.get(target, this._symbol) as Value
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get(target: Target): Value {
|
|
34
|
+
const input = this.tryGet(target)
|
|
35
|
+
if (!input) {
|
|
36
|
+
throw new Error(
|
|
37
|
+
`Target of type ${target.constructor.name} doesn't have any embedded data for ${this.name}!`
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
return input
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./base"
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import chalk from "chalk"
|
|
2
|
+
|
|
3
|
+
const interchangeable = {
|
|
4
|
+
diamond: "◆",
|
|
5
|
+
star: "★",
|
|
6
|
+
four_shapes: "❖",
|
|
7
|
+
four_star: "✦",
|
|
8
|
+
star_circled_filled: "✪",
|
|
9
|
+
|
|
10
|
+
aster: "✱",
|
|
11
|
+
helm: "☸ ",
|
|
12
|
+
ball_circled: "◉",
|
|
13
|
+
lines_circled: "◍ ",
|
|
14
|
+
plus_circled: "⊕ ",
|
|
15
|
+
|
|
16
|
+
triangle_down: "▼",
|
|
17
|
+
dot_triangled: "◬",
|
|
18
|
+
diamond_diamonded: "◈",
|
|
19
|
+
circle_squared_filled: "◙",
|
|
20
|
+
triangle_filled_half: "◭",
|
|
21
|
+
heart_arrow: "❥",
|
|
22
|
+
bullet_squared_filled: "◘",
|
|
23
|
+
copyright: "©",
|
|
24
|
+
section: "§",
|
|
25
|
+
paragraph: "¶",
|
|
26
|
+
weird_circle: "¤",
|
|
27
|
+
euro: "€",
|
|
28
|
+
yen: "¥",
|
|
29
|
+
plus_filled: "✚",
|
|
30
|
+
mac_char: "⌘ "
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const colors = [chalk.red, chalk.green, chalk.yellow, chalk.blue, chalk.magenta, chalk.cyan]
|
|
34
|
+
|
|
35
|
+
const numbered = Object.values(interchangeable)
|
|
36
|
+
|
|
37
|
+
export function getMarkerForIndex(index: number, alias: string) {
|
|
38
|
+
const clamedIndex = index % numbered.length
|
|
39
|
+
const multiplier = Math.floor(index / numbered.length)
|
|
40
|
+
const char = numbered[clamedIndex]
|
|
41
|
+
const color = colors[multiplier % colors.length]
|
|
42
|
+
const marker = [char, alias].join(" ")
|
|
43
|
+
const colored = color(marker)
|
|
44
|
+
return colored
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const external = "∃"
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
type K8tsToken = `K8TS_TOK_${string}`
|
|
2
|
+
export class TextPostProcessor {
|
|
3
|
+
private tokens = new Map<K8tsToken, string>()
|
|
4
|
+
private _genToken(): K8tsToken {
|
|
5
|
+
const randomKey = Math.random().toString(36).slice(2, 8)
|
|
6
|
+
const token = `K8TS_TOK_${randomKey}` as K8tsToken
|
|
7
|
+
if (this.tokens.has(token)) {
|
|
8
|
+
return this._genToken()
|
|
9
|
+
}
|
|
10
|
+
return token
|
|
11
|
+
}
|
|
12
|
+
token(text: string) {
|
|
13
|
+
const token = this._genToken()
|
|
14
|
+
this.tokens.set(token, text)
|
|
15
|
+
return token
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
render(text: string) {
|
|
19
|
+
let result = text
|
|
20
|
+
for (const [token, value] of this.tokens.entries()) {
|
|
21
|
+
result = result.replaceAll(token, value)
|
|
22
|
+
}
|
|
23
|
+
return result
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import chalk from "chalk"
|
|
2
|
+
import { displayers } from "../displayers"
|
|
3
|
+
|
|
4
|
+
@displayers({
|
|
5
|
+
simple: s => s.text,
|
|
6
|
+
pretty: attr => chalk.yellowBright(attr.text)
|
|
7
|
+
})
|
|
8
|
+
export class Attr {
|
|
9
|
+
constructor(readonly text: string) {}
|
|
10
|
+
}
|
|
11
|
+
@displayers({
|
|
12
|
+
simple: s => s.text,
|
|
13
|
+
pretty: verb => chalk.bgGreen.bold.white(` ${verb.text} `)
|
|
14
|
+
})
|
|
15
|
+
export class Verb {
|
|
16
|
+
constructor(readonly text: string) {}
|
|
17
|
+
}
|
|
18
|
+
@displayers({
|
|
19
|
+
simple: s => `${s.num} ${s.noun}`,
|
|
20
|
+
pretty(self) {
|
|
21
|
+
const { num, noun } = self
|
|
22
|
+
const nounForm = num > 1 ? `${noun}s` : noun
|
|
23
|
+
return `${chalk.red(num)} ${chalk.green(nounForm)}`
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
export class Quantity {
|
|
27
|
+
constructor(
|
|
28
|
+
readonly num: number,
|
|
29
|
+
readonly noun: string
|
|
30
|
+
) {}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@displayers({
|
|
34
|
+
simple: s => s.name,
|
|
35
|
+
pretty: refName => chalk.bgGrey.bold.white(` ${refName.name} `)
|
|
36
|
+
})
|
|
37
|
+
export class RefName {
|
|
38
|
+
constructor(readonly name: string) {}
|
|
39
|
+
}
|
|
40
|
+
@displayers({
|
|
41
|
+
simple: s => s.text,
|
|
42
|
+
pretty: dest => chalk.blueBright(dest.text)
|
|
43
|
+
})
|
|
44
|
+
export class Dest {
|
|
45
|
+
constructor(readonly text: string) {}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function verb(verb: string) {
|
|
49
|
+
return new Verb(verb)
|
|
50
|
+
}
|
|
51
|
+
export function attr(attr: string) {
|
|
52
|
+
return new Attr(attr)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function quantity(num: number, noun: string) {
|
|
56
|
+
return new Quantity(num, noun)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function dest(text: string) {
|
|
60
|
+
return new Dest(text)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function ref(name: string) {
|
|
64
|
+
return new RefName(name)
|
|
65
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Displayers } from "../displayers"
|
|
2
|
+
|
|
3
|
+
export function pretty(templateArgs: TemplateStringsArray, ...args: any[]) {
|
|
4
|
+
args = args.map(arg => {
|
|
5
|
+
const [format, target] = Array.isArray(arg) ? arg : [undefined, arg]
|
|
6
|
+
const x = Displayers.tryGet(target)
|
|
7
|
+
if (x) {
|
|
8
|
+
return x.pretty(format)
|
|
9
|
+
}
|
|
10
|
+
return target
|
|
11
|
+
})
|
|
12
|
+
const splat = templateArgs
|
|
13
|
+
.map((x, i) => {
|
|
14
|
+
const arg = args[i]
|
|
15
|
+
if (arg) {
|
|
16
|
+
return [x, arg]
|
|
17
|
+
}
|
|
18
|
+
return x
|
|
19
|
+
})
|
|
20
|
+
.flat()
|
|
21
|
+
.filter(x => x !== undefined)
|
|
22
|
+
const result = splat.join("")
|
|
23
|
+
return result
|
|
24
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const digits = ["⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹"]
|
|
2
|
+
|
|
3
|
+
export function toSuperScript(n: number): string {
|
|
4
|
+
if (n < 0) {
|
|
5
|
+
return "⁻" + toSuperScript(-n)
|
|
6
|
+
}
|
|
7
|
+
const num = []
|
|
8
|
+
while (n >= 0) {
|
|
9
|
+
const digit = n % 10
|
|
10
|
+
n = Math.floor(n / 10)
|
|
11
|
+
num.unshift(digits[digit])
|
|
12
|
+
if (n === 0) {
|
|
13
|
+
break
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return num.join("")
|
|
17
|
+
}
|