@k8ts/instruments 0.2.1 → 0.4.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/dist/data-sources/index.d.ts +37 -0
- package/dist/data-sources/index.d.ts.map +1 -0
- package/dist/data-sources/index.js +104 -0
- package/dist/data-sources/index.js.map +1 -0
- package/dist/graph/base-node.d.ts +6 -4
- package/dist/graph/base-node.d.ts.map +1 -1
- package/dist/graph/base-node.js +16 -7
- package/dist/graph/base-node.js.map +1 -1
- package/dist/graph/dependencies.d.ts +2 -2
- package/dist/graph/dependencies.d.ts.map +1 -1
- package/dist/graph/dependencies.js +8 -8
- package/dist/graph/dependencies.js.map +1 -1
- package/dist/graph/origin-node.d.ts +1 -1
- package/dist/graph/origin-node.d.ts.map +1 -1
- package/dist/graph/origin-node.js +1 -1
- package/dist/graph/origin-node.js.map +1 -1
- package/dist/graph/relations.d.ts +2 -2
- package/dist/graph/relations.d.ts.map +1 -1
- package/dist/graph/relations.js.map +1 -1
- package/dist/graph/resource-node.d.ts +1 -1
- package/dist/graph/resource-node.d.ts.map +1 -1
- package/dist/graph/resource-node.js +1 -1
- package/dist/graph/resource-node.js.map +1 -1
- package/dist/image/family.d.ts +10 -6
- package/dist/image/family.d.ts.map +1 -1
- package/dist/image/family.js +158 -43
- package/dist/image/family.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/manifest/manifest-builder.d.ts +7 -11
- package/dist/manifest/manifest-builder.d.ts.map +1 -1
- package/dist/manifest/manifest-builder.js +2 -2
- package/dist/manifest/manifest-builder.js.map +1 -1
- package/dist/ports/set.d.ts +2 -2
- package/dist/ports/set.d.ts.map +1 -1
- package/dist/ports/set.js +15 -1
- package/dist/ports/set.js.map +1 -1
- package/dist/ports/types.d.ts +2 -2
- package/dist/ports/types.d.ts.map +1 -1
- package/dist/src.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/data-sources/index.ts +126 -0
- package/src/graph/base-node.ts +20 -10
- package/src/graph/dependencies.ts +2 -2
- package/src/graph/origin-node.ts +1 -1
- package/src/graph/relations.ts +2 -2
- package/src/graph/resource-node.ts +1 -1
- package/src/image/family.ts +45 -29
- package/src/index.ts +1 -0
- package/src/manifest/manifest-builder.ts +6 -5
- package/src/ports/set.ts +17 -3
- package/src/ports/types.ts +5 -3
package/src/graph/base-node.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { hash, Set } from "immutable"
|
|
|
3
3
|
import { Kind } from "../api-kind"
|
|
4
4
|
import { RefKey } from "../ref-key"
|
|
5
5
|
import { ForwardRef } from "../reference"
|
|
6
|
-
import {
|
|
6
|
+
import { Relation } from "./dependencies"
|
|
7
7
|
|
|
8
8
|
export interface BaseEntity<Node extends BaseNode<Node>> {
|
|
9
9
|
readonly node: Node
|
|
@@ -17,13 +17,14 @@ export abstract class BaseNode<
|
|
|
17
17
|
Node extends BaseNode<Node, Entity>,
|
|
18
18
|
Entity extends BaseEntity<Node> = BaseEntity<Node>
|
|
19
19
|
> {
|
|
20
|
+
private _eqProxy = {}
|
|
20
21
|
abstract readonly key: RefKey
|
|
21
22
|
get kind() {
|
|
22
23
|
return this.key.kind
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
abstract readonly kids: Seq<Node>
|
|
26
|
-
abstract readonly
|
|
27
|
+
abstract readonly relations: Seq<Relation<Node>>
|
|
27
28
|
abstract readonly parent: Node | null
|
|
28
29
|
protected get _asNode() {
|
|
29
30
|
return this as any as Node
|
|
@@ -41,11 +42,11 @@ export abstract class BaseNode<
|
|
|
41
42
|
return this.key.name
|
|
42
43
|
}
|
|
43
44
|
get isRoot() {
|
|
44
|
-
return this.parent === null
|
|
45
|
+
return this.parent === null && this._entity.kind.name !== "PodTemplate"
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
hashCode() {
|
|
48
|
-
return hash(this)
|
|
49
|
+
return hash(this._eqProxy)
|
|
49
50
|
}
|
|
50
51
|
equals(other: any) {
|
|
51
52
|
if (ForwardRef.is(other)) {
|
|
@@ -97,25 +98,34 @@ export abstract class BaseNode<
|
|
|
97
98
|
return this.equals(other) || Set(this.ancestors).has(other._asNode)
|
|
98
99
|
}
|
|
99
100
|
|
|
100
|
-
|
|
101
|
-
return this.
|
|
101
|
+
hasRelationTo(other: Node): boolean {
|
|
102
|
+
return this.recursiveRelations.some(x => x.needed.equals(other)).pull()
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
readonly
|
|
105
|
+
readonly recursiveRelationsSubtree = seq((): Seq<Relation<Node>> => {
|
|
106
|
+
const self = this
|
|
107
|
+
return seq(function* () {
|
|
108
|
+
for (const child of [self, ...self.descendants] as Node[]) {
|
|
109
|
+
yield* child.recursiveRelations
|
|
110
|
+
}
|
|
111
|
+
}) as any
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
readonly recursiveRelations = seq(() => {
|
|
105
115
|
let resources = Set<Node>()
|
|
106
|
-
const recurseIntoDependency = function* (root:
|
|
116
|
+
const recurseIntoDependency = function* (root: Relation<Node>): Iterable<Relation<Node>> {
|
|
107
117
|
yield root
|
|
108
118
|
if (resources.has(root.needed)) {
|
|
109
119
|
return
|
|
110
120
|
}
|
|
111
121
|
resources = resources.add(root.needed)
|
|
112
122
|
|
|
113
|
-
const ownDeps = root.needed.
|
|
123
|
+
const ownDeps = root.needed.relations
|
|
114
124
|
for (const needsEdge of ownDeps) {
|
|
115
125
|
yield* recurseIntoDependency(needsEdge)
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
|
-
return seq(recurseIntoDependency.bind(null, new
|
|
128
|
+
return seq(recurseIntoDependency.bind(null, new Relation<Node>("self", this._asNode)))
|
|
119
129
|
.after(() => {
|
|
120
130
|
resources = Set()
|
|
121
131
|
})
|
|
@@ -9,7 +9,7 @@ export namespace Dependencies {
|
|
|
9
9
|
}
|
|
10
10
|
export function dependencies(record: Dependencies.Input) {
|
|
11
11
|
return Object.entries(record).map(([key, value]) => {
|
|
12
|
-
return new
|
|
12
|
+
return new Relation(key, value.node)
|
|
13
13
|
})
|
|
14
14
|
}
|
|
15
15
|
@displayers({
|
|
@@ -19,7 +19,7 @@ export function dependencies(record: Dependencies.Input) {
|
|
|
19
19
|
return [`${chalk.gray.italic.white(`${dep.why}`)}`, "➜ ", chalk.italic(`${neededFmt}`)]
|
|
20
20
|
}
|
|
21
21
|
})
|
|
22
|
-
export class
|
|
22
|
+
export class Relation<Node extends BaseNode<Node>> {
|
|
23
23
|
constructor(
|
|
24
24
|
readonly why: string,
|
|
25
25
|
readonly needed: Node
|
package/src/graph/origin-node.ts
CHANGED
package/src/graph/relations.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Embedder } from "../_embedder/base"
|
|
2
|
-
import { Dependencies, dependencies,
|
|
2
|
+
import { Dependencies, dependencies, Relation } from "./dependencies"
|
|
3
3
|
import { ResourceEntity, ResourceNode } from "./resource-node"
|
|
4
4
|
|
|
5
5
|
export namespace Relations {
|
|
6
6
|
export interface Out {
|
|
7
|
-
needs: () => Iterable<
|
|
7
|
+
needs: () => Iterable<Relation<ResourceNode>>
|
|
8
8
|
parent: () => ResourceNode | null
|
|
9
9
|
kids: () => ResourceNode[]
|
|
10
10
|
}
|
package/src/image/family.ts
CHANGED
|
@@ -1,67 +1,83 @@
|
|
|
1
|
+
import { displayers } from "../displayers"
|
|
2
|
+
|
|
1
3
|
export type JoinIfNotEmpty<A extends string, J extends string, B extends string> = A extends ""
|
|
2
4
|
? B
|
|
3
5
|
: B extends ""
|
|
4
6
|
? A
|
|
5
7
|
: `${A}${J}${B}`
|
|
8
|
+
@displayers({
|
|
9
|
+
simple: s => s._url
|
|
10
|
+
})
|
|
6
11
|
export class ImageHost<Text extends string = string> {
|
|
7
12
|
private readonly _url: Text
|
|
8
13
|
constructor(source: Text) {
|
|
9
14
|
this._url = source
|
|
10
|
-
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
author<Author extends string>(name: Author) {
|
|
18
|
+
return new ImageAuthor<JoinIfNotEmpty<Text, "/", Author>>(this.toString(), name)
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
image<Image extends string>(name: Image) {
|
|
14
|
-
return new BaseImage<JoinIfNotEmpty<Text, "/", Image>>(this, name)
|
|
22
|
+
return new BaseImage<JoinIfNotEmpty<Text, "/", Image>>(this.toString(), name)
|
|
15
23
|
}
|
|
16
24
|
|
|
17
25
|
get [Symbol.toStringTag]() {
|
|
18
26
|
return this._url
|
|
19
27
|
}
|
|
20
28
|
}
|
|
29
|
+
@displayers({
|
|
30
|
+
simple: s => s._url
|
|
31
|
+
})
|
|
32
|
+
export class ImageAuthor<Text extends string = string> {
|
|
33
|
+
private readonly _url: Text
|
|
34
|
+
constructor(base: string, name: string) {
|
|
35
|
+
this._url = base === "" ? (name as Text) : ([base, name].join("/") as Text)
|
|
36
|
+
}
|
|
21
37
|
|
|
38
|
+
image<Image extends string>(name: Image) {
|
|
39
|
+
return new BaseImage<JoinIfNotEmpty<Text, "/", Image>>(this.toString(), name)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
@displayers({
|
|
43
|
+
simple: s => {
|
|
44
|
+
if (!s._base) {
|
|
45
|
+
return s._name
|
|
46
|
+
}
|
|
47
|
+
return [s._base, s._name].join("/")
|
|
48
|
+
}
|
|
49
|
+
})
|
|
22
50
|
export class BaseImage<Text extends string = string> {
|
|
23
51
|
constructor(
|
|
24
|
-
private readonly
|
|
52
|
+
private readonly _base: string,
|
|
25
53
|
private readonly _name: string
|
|
26
|
-
) {
|
|
27
|
-
this.toString = () => this[Symbol.toStringTag]
|
|
28
|
-
}
|
|
54
|
+
) {}
|
|
29
55
|
|
|
30
56
|
tag<Tag extends string>(tag: Tag) {
|
|
31
57
|
return new TaggedImage<JoinIfNotEmpty<Text, ":", Tag>>(this, tag)
|
|
32
58
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
59
|
+
}
|
|
60
|
+
@displayers({
|
|
61
|
+
simple: s => {
|
|
62
|
+
const fam = s._family.toString()
|
|
63
|
+
if (s._tag === "") {
|
|
64
|
+
return fam
|
|
37
65
|
}
|
|
38
|
-
return [
|
|
66
|
+
return [fam, s._tag].join(":")
|
|
39
67
|
}
|
|
40
|
-
}
|
|
41
|
-
|
|
68
|
+
})
|
|
42
69
|
export class TaggedImage<Text extends string = string> {
|
|
43
70
|
constructor(
|
|
44
71
|
private readonly _family: BaseImage<string>,
|
|
45
72
|
private readonly _tag: string
|
|
46
|
-
) {
|
|
47
|
-
this.toString = () => this.text
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
get text() {
|
|
51
|
-
const fam = this._family[Symbol.toStringTag]
|
|
52
|
-
if (this._tag === "") {
|
|
53
|
-
return fam
|
|
54
|
-
}
|
|
55
|
-
return [fam, this._tag].join(":")
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
get [Symbol.toStringTag]() {
|
|
59
|
-
return this.text
|
|
60
|
-
}
|
|
73
|
+
) {}
|
|
61
74
|
}
|
|
62
75
|
|
|
63
76
|
export namespace Image {
|
|
64
|
-
export function
|
|
77
|
+
export function author<Author extends string>(name: Author) {
|
|
78
|
+
return new ImageHost("").author(name)
|
|
79
|
+
}
|
|
80
|
+
export function name<Name extends `${string}/${string}`>(name: Name) {
|
|
65
81
|
return new ImageHost("").image(name)
|
|
66
82
|
}
|
|
67
83
|
|
package/src/index.ts
CHANGED
|
@@ -8,12 +8,13 @@ import {
|
|
|
8
8
|
import { Embedder } from "../_embedder/base"
|
|
9
9
|
import { MetadataEntity } from "../graph/resource-node"
|
|
10
10
|
|
|
11
|
+
type MaybePromise<T> = T | Promise<T>
|
|
11
12
|
export namespace ManifestBuilder {
|
|
12
13
|
export interface Out {
|
|
13
|
-
body: () => PreManifest
|
|
14
|
-
metadata: () => ManifestMetadata
|
|
14
|
+
body: () => MaybePromise<PreManifest>
|
|
15
|
+
metadata: () => Partial<ManifestMetadata>
|
|
15
16
|
ident: () => ManifestIdentFields
|
|
16
|
-
manifest: () => BaseManifest
|
|
17
|
+
manifest: () => MaybePromise<BaseManifest>
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export type In<Target extends MetadataEntity = MetadataEntity> = Partial<{
|
|
@@ -52,11 +53,11 @@ class BuilderDecorator {
|
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
55
|
|
|
55
|
-
manifest(trait: ManifestBuilder.Out, self: MetadataEntity) {
|
|
56
|
+
async manifest(trait: ManifestBuilder.Out, self: MetadataEntity) {
|
|
56
57
|
const mani = {
|
|
57
58
|
...trait.ident(),
|
|
58
59
|
metadata: trait.metadata(),
|
|
59
|
-
...trait.body()
|
|
60
|
+
...(await trait.body())
|
|
60
61
|
}
|
|
61
62
|
ManifestSourceEmbedder.set(mani, self)
|
|
62
63
|
return mani
|
package/src/ports/set.ts
CHANGED
|
@@ -28,8 +28,11 @@ export class PortSet<Names extends string = never> {
|
|
|
28
28
|
protocol: InputProtocol
|
|
29
29
|
): PortSet<Names | Name>
|
|
30
30
|
add<Name extends string>(name: Name, entry: InputPortSetEntry): PortSet<Names | Name>
|
|
31
|
-
add<InNames extends string>(input
|
|
31
|
+
add<InNames extends string>(input?: InputPortSetRecord<InNames>): PortSet<Names | InNames>
|
|
32
32
|
add(a: any, b?: any, c?: any): any {
|
|
33
|
+
if (!a) {
|
|
34
|
+
return this
|
|
35
|
+
}
|
|
33
36
|
if (c) {
|
|
34
37
|
return this._apply(map => map.set(a, { name: a, port: +b, protocol: c.toUpperCase() }))
|
|
35
38
|
}
|
|
@@ -63,17 +66,28 @@ export class PortSet<Names extends string = never> {
|
|
|
63
66
|
if (!(entry.name in mapping)) {
|
|
64
67
|
throw new PortError(`Port ${entry.name} not found in mapping`)
|
|
65
68
|
}
|
|
69
|
+
const portIn = mapping[entry.name as keyof typeof mapping]
|
|
70
|
+
let portVal: number
|
|
71
|
+
if (typeof portIn === "boolean") {
|
|
72
|
+
portVal = entry.port
|
|
73
|
+
} else if (typeof portIn === "number") {
|
|
74
|
+
portVal = portIn
|
|
75
|
+
} else {
|
|
76
|
+
throw new PortError(
|
|
77
|
+
`Port ${entry.name} mapping value must be a number or boolean`
|
|
78
|
+
)
|
|
79
|
+
}
|
|
66
80
|
return {
|
|
67
81
|
name: entry.name,
|
|
68
82
|
protocol: entry.protocol,
|
|
69
83
|
source: entry.port,
|
|
70
|
-
target:
|
|
84
|
+
target: portVal as any
|
|
71
85
|
}
|
|
72
86
|
})
|
|
73
87
|
)
|
|
74
88
|
}
|
|
75
89
|
|
|
76
|
-
static make<Names extends string>(input
|
|
90
|
+
static make<Names extends string>(input?: InputPortSetRecord<Names>) {
|
|
77
91
|
return new PortSet().add(input)
|
|
78
92
|
}
|
|
79
93
|
}
|
package/src/ports/types.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface InputPortMapEntry {
|
|
|
37
37
|
export type InputPortSetRecord<Names extends string = string> = {
|
|
38
38
|
[K in Names]: InputPortSetSpec
|
|
39
39
|
}
|
|
40
|
-
export type InputPortMapping<Names extends string = string> =
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
export type InputPortMapping<Names extends string = string> = [Names] extends [never]
|
|
41
|
+
? never
|
|
42
|
+
: {
|
|
43
|
+
[K in Names]: number | true
|
|
44
|
+
}
|