@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,76 @@
|
|
|
1
|
+
import { hash } from "immutable"
|
|
2
|
+
import { Kind } from "../api-kind"
|
|
3
|
+
import { InstrumentsError } from "../error"
|
|
4
|
+
export type RefKey<Kind extends string = string, Name extends string = string> = RefKey.RefKey<
|
|
5
|
+
Kind,
|
|
6
|
+
Name
|
|
7
|
+
>
|
|
8
|
+
export namespace RefKey {
|
|
9
|
+
export function make<K extends string, Name extends string>(
|
|
10
|
+
kind: Kind.Identifier<K>,
|
|
11
|
+
name: Name
|
|
12
|
+
): RefKey<K, Name> {
|
|
13
|
+
return new RefKey(kind, name)
|
|
14
|
+
}
|
|
15
|
+
export type Input = RefKey | RefKey["string"]
|
|
16
|
+
export type Format<Kind extends string, Name extends string> = `${Kind}/${Name}`
|
|
17
|
+
const separator = "/"
|
|
18
|
+
export interface Parsed {
|
|
19
|
+
kind: string
|
|
20
|
+
name: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function parse(ref: string) {
|
|
24
|
+
const result = tryParse(ref)
|
|
25
|
+
if (!result) {
|
|
26
|
+
throw new InstrumentsError(`Could not parse reference key: ${ref}`)
|
|
27
|
+
}
|
|
28
|
+
return result
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function tryParse(ref: string): Parsed | undefined {
|
|
32
|
+
if (typeof ref !== "string") {
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
if (ref == null) {
|
|
36
|
+
return undefined
|
|
37
|
+
}
|
|
38
|
+
if (typeof ref === "object") {
|
|
39
|
+
return undefined
|
|
40
|
+
}
|
|
41
|
+
const [kind, name] = ref.split(separator).map(s => s.trim())
|
|
42
|
+
if (!kind || !name) {
|
|
43
|
+
return undefined
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
kind,
|
|
47
|
+
name
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export class RefKey<K extends string = string, Name extends string = string> {
|
|
51
|
+
constructor(
|
|
52
|
+
readonly kind: Kind.Identifier<K>,
|
|
53
|
+
readonly name: Name
|
|
54
|
+
) {}
|
|
55
|
+
|
|
56
|
+
get string(): Format<K, Name> {
|
|
57
|
+
return [this.kind.name, this.name].join(separator) as Format<K, Name>
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
equals(other: RefKey): boolean {
|
|
61
|
+
if (other == null) {
|
|
62
|
+
return false
|
|
63
|
+
}
|
|
64
|
+
if (typeof other !== "object") {
|
|
65
|
+
return false
|
|
66
|
+
}
|
|
67
|
+
return this.kind.equals(other.kind) && this.name === other.name
|
|
68
|
+
}
|
|
69
|
+
hashCode() {
|
|
70
|
+
return hash(this.string)
|
|
71
|
+
}
|
|
72
|
+
toString() {
|
|
73
|
+
return this.string
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { Doddle } from "doddle"
|
|
2
|
+
import { hash, List } from "immutable"
|
|
3
|
+
import { ProxyOperationError } from "../error"
|
|
4
|
+
import { RefKey } from "../ref-key/ref-key"
|
|
5
|
+
|
|
6
|
+
export type ForwardRef<T extends object> = ForwardRef.Core<T> & T
|
|
7
|
+
export namespace ForwardRef {
|
|
8
|
+
export function is(x: any): boolean {
|
|
9
|
+
return "__reference_props__" in x
|
|
10
|
+
}
|
|
11
|
+
export function make<T extends object>(props: Props<T>): ForwardRef<T> {
|
|
12
|
+
const core = new Core(props)
|
|
13
|
+
return new Proxy(core, new Handler(core)) as ForwardRef<T>
|
|
14
|
+
}
|
|
15
|
+
export interface Props<Referenced extends object> {
|
|
16
|
+
readonly key: RefKey
|
|
17
|
+
readonly namespace?: string
|
|
18
|
+
readonly origin: object
|
|
19
|
+
readonly resolver: Doddle<Referenced>
|
|
20
|
+
readonly class: Function
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class Core<T extends object> {
|
|
24
|
+
#props: Props<T>
|
|
25
|
+
constructor(props: Props<T>) {
|
|
26
|
+
this.#props = props
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
equals(other: any) {
|
|
30
|
+
const resolved = this.#props.resolver.pull() as any
|
|
31
|
+
if (ForwardRef.is(other)) {
|
|
32
|
+
return other.equals(resolved)
|
|
33
|
+
}
|
|
34
|
+
if ("equals" in resolved) {
|
|
35
|
+
return resolved.equals(other)
|
|
36
|
+
}
|
|
37
|
+
return resolved === other
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
hashCode() {
|
|
41
|
+
return hash(List.of(this.#props.key, this.#props.origin))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get __reference_props__() {
|
|
45
|
+
return this.#props
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
class Handler<T extends object> implements ProxyHandler<T> {
|
|
50
|
+
get _props() {
|
|
51
|
+
return this._core.__reference_props__
|
|
52
|
+
}
|
|
53
|
+
constructor(private readonly _core: Core<T>) {}
|
|
54
|
+
|
|
55
|
+
get(target: T, prop: PropertyKey) {
|
|
56
|
+
const { _props, _core } = this
|
|
57
|
+
if (Reflect.has(_core, prop)) {
|
|
58
|
+
return Reflect.get(_core, prop)
|
|
59
|
+
}
|
|
60
|
+
const resource = _props.resolver.pull() as any
|
|
61
|
+
const result = Reflect.get(resource, prop)
|
|
62
|
+
if (typeof result === "function") {
|
|
63
|
+
return result.bind(resource)
|
|
64
|
+
}
|
|
65
|
+
return result
|
|
66
|
+
}
|
|
67
|
+
getPrototypeOf(target: T) {
|
|
68
|
+
const { _props } = this
|
|
69
|
+
return _props.class.prototype
|
|
70
|
+
}
|
|
71
|
+
has(target: T, prop: PropertyKey) {
|
|
72
|
+
const { _props, _core } = this
|
|
73
|
+
if (Reflect.has(_core, prop)) {
|
|
74
|
+
return true
|
|
75
|
+
}
|
|
76
|
+
const resource = _props.resolver.pull() as any
|
|
77
|
+
return Reflect.has(resource, prop)
|
|
78
|
+
}
|
|
79
|
+
getOwnPropertyDescriptor(_: T, p: string | symbol): PropertyDescriptor | undefined {
|
|
80
|
+
const { _core, _props } = this
|
|
81
|
+
const desc = Object.getOwnPropertyDescriptor(_core, p)
|
|
82
|
+
if (desc) {
|
|
83
|
+
desc.configurable = false
|
|
84
|
+
return desc
|
|
85
|
+
}
|
|
86
|
+
const resource = _props.resolver.pull() as any
|
|
87
|
+
const resourceDesc = Object.getOwnPropertyDescriptor(resource, p)
|
|
88
|
+
return resourceDesc
|
|
89
|
+
}
|
|
90
|
+
get referant() {
|
|
91
|
+
return this._core.__reference_props__.key.string
|
|
92
|
+
}
|
|
93
|
+
#createImmutableError(action: string) {
|
|
94
|
+
return new ProxyOperationError(
|
|
95
|
+
`Tried to ${action} a forward reference to ${this.referant}, but it cannot be modified.`
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
defineProperty(_: any, property: string | symbol, desc: PropertyDescriptor): boolean {
|
|
100
|
+
throw this.#createImmutableError(`define property ${String(property)} on`)
|
|
101
|
+
}
|
|
102
|
+
deleteProperty(_: T, p: string | symbol): boolean {
|
|
103
|
+
throw this.#createImmutableError(`delete property ${String(p)} from`)
|
|
104
|
+
}
|
|
105
|
+
preventExtensions(): boolean {
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
isExtensible(): boolean {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
set(_: T, p: string | symbol): boolean {
|
|
112
|
+
throw this.#createImmutableError(`set property ${String(p)} on`)
|
|
113
|
+
}
|
|
114
|
+
ownKeys(): ArrayLike<string | symbol> {
|
|
115
|
+
const pulled = this._props.resolver.pull() as any
|
|
116
|
+
return [...Reflect.ownKeys(this._core), ...Reflect.ownKeys(pulled)]
|
|
117
|
+
}
|
|
118
|
+
setPrototypeOf(): boolean {
|
|
119
|
+
throw this.#createImmutableError(`set the prototype of`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Kind } from "../api-kind"
|
|
2
|
+
import type { RefKey } from "../ref-key"
|
|
3
|
+
|
|
4
|
+
export type Kinded = { kind: Kind.Kind }
|
|
5
|
+
export type Refable<Kind extends string, Name extends string> = {
|
|
6
|
+
node: {
|
|
7
|
+
key: RefKey<Kind, Name>
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export type LiveRefable<Object extends Kinded = Kinded, Name extends string = string> = Object &
|
|
11
|
+
Refable<Object["kind"]["name"], Name>
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { Map, Set } from "immutable"
|
|
2
|
+
import { isEmpty, merge } from "lodash"
|
|
3
|
+
import { string, type Parjser } from "parjs"
|
|
4
|
+
import { mapConst, or } from "parjs/combinators"
|
|
5
|
+
import { InstrumentsError } from "../error"
|
|
6
|
+
import type { UnitParser, UnitValue } from "../units"
|
|
7
|
+
import { createResourceParser } from "./parser"
|
|
8
|
+
import type { mt_Resource_Input_Map, mt_Resource_Unit_Map, ReqLimit } from "./types"
|
|
9
|
+
|
|
10
|
+
export class ResourcesMap<const RM extends mt_Resource_Unit_Map<RM>> {
|
|
11
|
+
constructor(private _map: Map<string, ReqLimit>) {}
|
|
12
|
+
|
|
13
|
+
toObject() {
|
|
14
|
+
const kubernetesForm = this._map.map((value, key) => {
|
|
15
|
+
const result = {} as any
|
|
16
|
+
if (value.request) {
|
|
17
|
+
result.requests = {
|
|
18
|
+
[key]: value.request.str
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (value.limit) {
|
|
22
|
+
result.limits = {
|
|
23
|
+
[key]: value.limit.str
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
if (!isEmpty(result)) {
|
|
27
|
+
return result
|
|
28
|
+
}
|
|
29
|
+
return undefined
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
return merge({}, ...kubernetesForm.values())
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export class ResourcesSpec<const RM extends mt_Resource_Unit_Map<RM>> {
|
|
37
|
+
readonly _unitParsers: Map<string, Parjser<UnitValue | undefined>>
|
|
38
|
+
readonly _reqLimitParsers: Map<string, Parjser<ReqLimit>>
|
|
39
|
+
constructor(_unitMap: Map<string, UnitParser>) {
|
|
40
|
+
const questionMarkParser = string("?").pipe(mapConst(undefined))
|
|
41
|
+
this._unitParsers = _unitMap.map(parser => parser.parser.pipe(or(questionMarkParser)))
|
|
42
|
+
this._reqLimitParsers = _unitMap.map(parser => createResourceParser(parser))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private _parseUnitValue(resource: string, input: string): UnitValue | undefined {
|
|
46
|
+
const pUnitValue = this._unitParsers.get(input)
|
|
47
|
+
if (!pUnitValue) {
|
|
48
|
+
throw new InstrumentsError(`No parser found for ${input}`)
|
|
49
|
+
}
|
|
50
|
+
return pUnitValue.parse(input).value
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
private _parseReqLimit(resource: string, input: string): ReqLimit {
|
|
54
|
+
const pReqLimit = this._reqLimitParsers.get(resource)
|
|
55
|
+
if (!pReqLimit) {
|
|
56
|
+
throw new InstrumentsError(`No parser found for ${resource}`)
|
|
57
|
+
}
|
|
58
|
+
return pReqLimit.parse(input).value
|
|
59
|
+
}
|
|
60
|
+
__INPUT__!: mt_Resource_Input_Map<RM>
|
|
61
|
+
|
|
62
|
+
parse<const R extends mt_Resource_Input_Map<RM>>(input: R): ResourcesMap<RM> {
|
|
63
|
+
const allKeys = Set([...Object.keys(input), ...this._unitParsers.keys()]).toMap()
|
|
64
|
+
const map = allKeys.map((_, key) => {
|
|
65
|
+
const value = input[key as keyof R]
|
|
66
|
+
const pUnitValue = this._unitParsers.get(key)
|
|
67
|
+
if (!pUnitValue) {
|
|
68
|
+
throw new InstrumentsError(`No parser found for ${String(key)}`)
|
|
69
|
+
}
|
|
70
|
+
if (!value) {
|
|
71
|
+
throw new InstrumentsError(`No value found for ${String(key)}`)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (Array.isArray(value)) {
|
|
75
|
+
const [req, limit] = value.map(v => {
|
|
76
|
+
return pUnitValue.parse(v as any).value
|
|
77
|
+
})
|
|
78
|
+
return {
|
|
79
|
+
request: req,
|
|
80
|
+
limit: limit
|
|
81
|
+
}
|
|
82
|
+
} else if (typeof value === "string") {
|
|
83
|
+
return this._parseReqLimit(key as string, value)
|
|
84
|
+
} else {
|
|
85
|
+
return {
|
|
86
|
+
request: this._parseUnitValue(key as string, value.request),
|
|
87
|
+
limit: this._parseUnitValue(key as string, value.limit)
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
})
|
|
91
|
+
return new ResourcesMap(map as Map<string, ReqLimit>)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
static make<const RM extends mt_Resource_Unit_Map<RM>>(unitMap: {
|
|
95
|
+
[K in keyof RM]: UnitParser<RM[K]>
|
|
96
|
+
}) {
|
|
97
|
+
return new ResourcesSpec<RM>(Map(unitMap) as Map<string, UnitParser>)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { manySepBy, map, must } from "parjs/combinators"
|
|
2
|
+
import type { UnitParser } from "../units/unit-parser"
|
|
3
|
+
import type { ReqLimit } from "./types"
|
|
4
|
+
|
|
5
|
+
export function createResourceParser(pUnitValue: UnitParser) {
|
|
6
|
+
return pUnitValue.parser.pipe(
|
|
7
|
+
manySepBy("--->", 2),
|
|
8
|
+
must(x => {
|
|
9
|
+
if (x.length !== 2) {
|
|
10
|
+
return {
|
|
11
|
+
kind: "Hard",
|
|
12
|
+
reason: "Expected exactly 2 values"
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return true
|
|
16
|
+
}),
|
|
17
|
+
map(([a, b]) => {
|
|
18
|
+
return {
|
|
19
|
+
request: a,
|
|
20
|
+
limit: b
|
|
21
|
+
} as ReqLimit
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { UnitValue } from "../units/unit-parser"
|
|
2
|
+
export type _limit_term<Unit extends string> = `${number}${Unit}` | "?"
|
|
3
|
+
|
|
4
|
+
export interface InputReqLimitObject<Unit extends string> {
|
|
5
|
+
readonly request: _limit_term<Unit>
|
|
6
|
+
readonly limit: _limit_term<Unit>
|
|
7
|
+
}
|
|
8
|
+
export type InputReqLimitArray<Unit extends string> = [_limit_term<Unit>, _limit_term<Unit>]
|
|
9
|
+
export type mt_Resource_Unit_Map<T> = Record<keyof T, string>
|
|
10
|
+
|
|
11
|
+
export type InputReqLimitString<U extends string> = `${_limit_term<U>}--->${_limit_term<U>}`
|
|
12
|
+
|
|
13
|
+
export interface ReqLimit<Unit extends string = string> {
|
|
14
|
+
readonly request?: UnitValue<Unit>
|
|
15
|
+
readonly limit?: UnitValue<Unit>
|
|
16
|
+
}
|
|
17
|
+
export type InputReqLimit<Unit extends string> =
|
|
18
|
+
| InputReqLimitString<Unit>
|
|
19
|
+
| InputReqLimitObject<Unit>
|
|
20
|
+
| InputReqLimitArray<Unit>
|
|
21
|
+
export type mt_Resource_Input_Map<ResourceUnit extends mt_Resource_Unit_Map<ResourceUnit>> = {
|
|
22
|
+
[K in keyof ResourceUnit]: InputReqLimit<ResourceUnit[K]>
|
|
23
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import dayjs from "dayjs"
|
|
2
|
+
import simpleGit from "simple-git"
|
|
3
|
+
|
|
4
|
+
export interface GitTraceOptions {
|
|
5
|
+
cwd: string
|
|
6
|
+
absolute: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface GitTraceProps {
|
|
10
|
+
commit: {
|
|
11
|
+
sha: string
|
|
12
|
+
message: string
|
|
13
|
+
author: string
|
|
14
|
+
date: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class GitTrace {
|
|
18
|
+
private constructor(readonly props: GitTraceProps) {}
|
|
19
|
+
|
|
20
|
+
get text() {
|
|
21
|
+
const hashPart = this.props.commit.sha.slice(0, 7)
|
|
22
|
+
const shortDate = dayjs(this.props.commit.date).format("YYYY-MM-DD")
|
|
23
|
+
const shortMessage = this.props.commit.message.split("\n")[0].slice(0, 20)
|
|
24
|
+
const author = this.props.commit.author
|
|
25
|
+
return `${hashPart} '${shortMessage}⋯' (${author}@${shortDate})`
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static async make(options?: Partial<GitTraceOptions>) {
|
|
29
|
+
options = {
|
|
30
|
+
cwd: ".",
|
|
31
|
+
absolute: false,
|
|
32
|
+
...options
|
|
33
|
+
}
|
|
34
|
+
const sg = simpleGit(options.cwd)
|
|
35
|
+
const isRepo = await sg.checkIsRepo()
|
|
36
|
+
if (!isRepo) {
|
|
37
|
+
return undefined
|
|
38
|
+
}
|
|
39
|
+
const l = await sg.log({
|
|
40
|
+
maxCount: 1
|
|
41
|
+
})
|
|
42
|
+
return new GitTrace({
|
|
43
|
+
commit: {
|
|
44
|
+
sha: l.latest!.hash,
|
|
45
|
+
message: l.latest!.message,
|
|
46
|
+
author: l.latest!.author_name,
|
|
47
|
+
date: l.latest!.date
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defaults } from "lodash"
|
|
2
|
+
import { relative, resolve } from "path"
|
|
3
|
+
import StackTracey from "stacktracey"
|
|
4
|
+
|
|
5
|
+
export interface TraceFormatOptions {
|
|
6
|
+
cwd: string
|
|
7
|
+
absolute: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class Trace {
|
|
11
|
+
readonly trace: StackTracey.Entry
|
|
12
|
+
constructor(trace: StackTracey) {
|
|
13
|
+
const findGoodFrame = (e: StackTracey.Entry) => {
|
|
14
|
+
return !e.native && e.file && !e.file.includes("node:")
|
|
15
|
+
}
|
|
16
|
+
this.trace = trace.filter(x => !!findGoodFrame(x)).at(0)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
format(inOptions?: Partial<TraceFormatOptions>) {
|
|
20
|
+
const e = this.trace
|
|
21
|
+
const options = defaults(inOptions, {
|
|
22
|
+
cwd: ".",
|
|
23
|
+
absolute: false
|
|
24
|
+
}) as TraceFormatOptions
|
|
25
|
+
options.cwd = resolve(options.cwd)
|
|
26
|
+
const sourcePath = options.absolute ? e.file : relative(options.cwd, e.file)
|
|
27
|
+
const relativeToCwd = relative(options.cwd, sourcePath)
|
|
28
|
+
const sourceLocation = `${relativeToCwd}:${e.line}:${e.column}`
|
|
29
|
+
return sourceLocation
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Set } from "immutable"
|
|
2
|
+
import { int, letter, type Parjser } from "parjs"
|
|
3
|
+
import { many1, map, stringify, then } from "parjs/combinators"
|
|
4
|
+
import { InstrumentsError } from "../error"
|
|
5
|
+
const pUnit = letter().pipe(many1(2), stringify())
|
|
6
|
+
|
|
7
|
+
const pValueUnit = int().pipe(
|
|
8
|
+
then(pUnit),
|
|
9
|
+
map(arr => {
|
|
10
|
+
const [value, unit] = arr
|
|
11
|
+
return { value, unit }
|
|
12
|
+
})
|
|
13
|
+
)
|
|
14
|
+
export class UnitValue<Unit extends string = string> {
|
|
15
|
+
constructor(
|
|
16
|
+
readonly unit: Unit,
|
|
17
|
+
readonly value: number,
|
|
18
|
+
readonly type: string
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
get str() {
|
|
22
|
+
return `${this.value}${this.unit}`
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
toString() {
|
|
26
|
+
return this.str
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class UnitParser<const Unit extends string = string> {
|
|
31
|
+
readonly parser: Parjser<UnitValue<Unit>>
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly unitType: string,
|
|
34
|
+
private readonly _units: Set<Unit>
|
|
35
|
+
) {
|
|
36
|
+
this.parser = pValueUnit.pipe(
|
|
37
|
+
map(({ value, unit }) => {
|
|
38
|
+
const gotType = this._units.has(unit as any)
|
|
39
|
+
if (!gotType) {
|
|
40
|
+
throw new InstrumentsError(
|
|
41
|
+
`Unit ${unit} is not a valid unit of type ${this.unitType}`
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
return new UnitValue<Unit>(unit as any, value, this.unitType)
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
parse = (input: `${number}${Unit}`) => {
|
|
50
|
+
const pUnitValue = this.parser
|
|
51
|
+
const result = pUnitValue.parse(input)
|
|
52
|
+
if (result.kind !== "OK") {
|
|
53
|
+
throw new InstrumentsError(`Failed to parse ${this.unitType}`, {
|
|
54
|
+
more: result.trace.toString()
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
return result.value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static make<const Unit extends string>(unitType: string, units: Set<Unit>) {
|
|
61
|
+
return new UnitParser<Unit>(unitType, units)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Set } from "immutable"
|
|
2
|
+
import { UnitParser } from "./unit-parser"
|
|
3
|
+
|
|
4
|
+
export type G = `${number}G`
|
|
5
|
+
export const G = (n: number) => `${n}G` as G
|
|
6
|
+
|
|
7
|
+
export type M = `${number}M`
|
|
8
|
+
export const M = (n: number) => `${n}M` as M
|
|
9
|
+
|
|
10
|
+
export type K = `${number}K`
|
|
11
|
+
export const K = (n: number) => `${n}K` as K
|
|
12
|
+
|
|
13
|
+
export type T = `${number}T`
|
|
14
|
+
export const T = (n: number) => `${n}T` as T
|
|
15
|
+
|
|
16
|
+
export type Gi = `${number}Gi`
|
|
17
|
+
export const Gi = (n: number) => `${n}Gi` as Gi
|
|
18
|
+
|
|
19
|
+
export type Mi = `${number}Mi`
|
|
20
|
+
export const Mi = (n: number) => `${n}Mi` as Mi
|
|
21
|
+
|
|
22
|
+
export type Ki = `${number}Ki`
|
|
23
|
+
export const Ki = (n: number) => `${n}Ki` as Ki
|
|
24
|
+
|
|
25
|
+
export type m = `${number}m`
|
|
26
|
+
export const m = (n: number) => `${n}m` as m
|
|
27
|
+
|
|
28
|
+
export type h = `${number}h`
|
|
29
|
+
export const h = (n: number) => `${n}h` as h
|
|
30
|
+
|
|
31
|
+
export type d = `${number}d`
|
|
32
|
+
export const d = (n: number) => `${n * 24}h` as d
|
|
33
|
+
|
|
34
|
+
export type s = `${number}s`
|
|
35
|
+
export const s = (n: number) => `${n}s` as s
|
|
36
|
+
|
|
37
|
+
export type ms = `${number}ms`
|
|
38
|
+
export const ms = (n: number) => `${n}ms` as ms
|
|
39
|
+
|
|
40
|
+
export interface UnitDefinition<Unit extends string> {}
|
|
41
|
+
|
|
42
|
+
export namespace Unit {
|
|
43
|
+
export type Data = M | G | T | K | Mi | Gi | Ki
|
|
44
|
+
export type Cpu = m
|
|
45
|
+
export type Time = m | h | d | s | ms
|
|
46
|
+
export type Any = Data | Cpu | Time
|
|
47
|
+
|
|
48
|
+
export const Cpu = UnitParser.make("cpu", Set(["m"]))
|
|
49
|
+
|
|
50
|
+
export const Data = UnitParser.make("data", Set(["M", "G", "T", "K", "Mi", "Gi", "Ki"]))
|
|
51
|
+
|
|
52
|
+
export const Time = UnitParser.make("time", Set(["m", "h", "d", "s", "ms"]))
|
|
53
|
+
}
|