@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.
Files changed (54) hide show
  1. package/dist/data-sources/index.d.ts +37 -0
  2. package/dist/data-sources/index.d.ts.map +1 -0
  3. package/dist/data-sources/index.js +104 -0
  4. package/dist/data-sources/index.js.map +1 -0
  5. package/dist/graph/base-node.d.ts +6 -4
  6. package/dist/graph/base-node.d.ts.map +1 -1
  7. package/dist/graph/base-node.js +16 -7
  8. package/dist/graph/base-node.js.map +1 -1
  9. package/dist/graph/dependencies.d.ts +2 -2
  10. package/dist/graph/dependencies.d.ts.map +1 -1
  11. package/dist/graph/dependencies.js +8 -8
  12. package/dist/graph/dependencies.js.map +1 -1
  13. package/dist/graph/origin-node.d.ts +1 -1
  14. package/dist/graph/origin-node.d.ts.map +1 -1
  15. package/dist/graph/origin-node.js +1 -1
  16. package/dist/graph/origin-node.js.map +1 -1
  17. package/dist/graph/relations.d.ts +2 -2
  18. package/dist/graph/relations.d.ts.map +1 -1
  19. package/dist/graph/relations.js.map +1 -1
  20. package/dist/graph/resource-node.d.ts +1 -1
  21. package/dist/graph/resource-node.d.ts.map +1 -1
  22. package/dist/graph/resource-node.js +1 -1
  23. package/dist/graph/resource-node.js.map +1 -1
  24. package/dist/image/family.d.ts +10 -6
  25. package/dist/image/family.d.ts.map +1 -1
  26. package/dist/image/family.js +158 -43
  27. package/dist/image/family.js.map +1 -1
  28. package/dist/index.d.ts +1 -0
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +1 -0
  31. package/dist/index.js.map +1 -1
  32. package/dist/manifest/manifest-builder.d.ts +7 -11
  33. package/dist/manifest/manifest-builder.d.ts.map +1 -1
  34. package/dist/manifest/manifest-builder.js +2 -2
  35. package/dist/manifest/manifest-builder.js.map +1 -1
  36. package/dist/ports/set.d.ts +2 -2
  37. package/dist/ports/set.d.ts.map +1 -1
  38. package/dist/ports/set.js +15 -1
  39. package/dist/ports/set.js.map +1 -1
  40. package/dist/ports/types.d.ts +2 -2
  41. package/dist/ports/types.d.ts.map +1 -1
  42. package/dist/src.tsbuildinfo +1 -1
  43. package/package.json +3 -3
  44. package/src/data-sources/index.ts +126 -0
  45. package/src/graph/base-node.ts +20 -10
  46. package/src/graph/dependencies.ts +2 -2
  47. package/src/graph/origin-node.ts +1 -1
  48. package/src/graph/relations.ts +2 -2
  49. package/src/graph/resource-node.ts +1 -1
  50. package/src/image/family.ts +45 -29
  51. package/src/index.ts +1 -0
  52. package/src/manifest/manifest-builder.ts +6 -5
  53. package/src/ports/set.ts +17 -3
  54. package/src/ports/types.ts +5 -3
@@ -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 { NeedsEdge } from "./dependencies"
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 needs: Seq<NeedsEdge<Node>>
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
- isNeeding(other: Node): boolean {
101
- return this.needsGraph.some(x => x.needed.equals(other)).pull()
101
+ hasRelationTo(other: Node): boolean {
102
+ return this.recursiveRelations.some(x => x.needed.equals(other)).pull()
102
103
  }
103
104
 
104
- readonly needsGraph = seq(() => {
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: NeedsEdge<Node>): Iterable<NeedsEdge<Node>> {
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.needs
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 NeedsEdge<Node>("self", this._asNode)))
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 NeedsEdge(key, value.node)
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 NeedsEdge<Node extends BaseNode<Node>> {
22
+ export class Relation<Node extends BaseNode<Node>> {
23
23
  constructor(
24
24
  readonly why: string,
25
25
  readonly needed: Node
@@ -54,7 +54,7 @@ export class Origin extends BaseNode<Origin, OriginEntity> implements Iterable<R
54
54
  private _kindMap: KindMap
55
55
  private _attached = [] as ResourceNode[]
56
56
 
57
- get needs() {
57
+ get relations() {
58
58
  return seq.empty()
59
59
  }
60
60
  [Symbol.iterator]() {
@@ -1,10 +1,10 @@
1
1
  import { Embedder } from "../_embedder/base"
2
- import { Dependencies, dependencies, NeedsEdge } from "./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<NeedsEdge<ResourceNode>>
7
+ needs: () => Iterable<Relation<ResourceNode>>
8
8
  parent: () => ResourceNode | null
9
9
  kids: () => ResourceNode[]
10
10
  }
@@ -30,7 +30,7 @@ import { Relations } from "./relations"
30
30
  }
31
31
  })
32
32
  export class ResourceNode extends BaseNode<ResourceNode, ResourceEntity> {
33
- get needs() {
33
+ get relations() {
34
34
  return seq(this._relations.needs)
35
35
  }
36
36
 
@@ -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
- this.toString = () => this[Symbol.toStringTag]
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 _source: ImageHost,
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
- get [Symbol.toStringTag]() {
35
- if (this._source[Symbol.toStringTag] === "") {
36
- return this._name
59
+ }
60
+ @displayers({
61
+ simple: s => {
62
+ const fam = s._family.toString()
63
+ if (s._tag === "") {
64
+ return fam
37
65
  }
38
- return [this._source, this._name].join("/")
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 name<Name extends string>(name: Name) {
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
@@ -2,6 +2,7 @@ export * from "./_embedder"
2
2
  export * from "./_string"
3
3
  export * from "./api-kind"
4
4
  export * from "./cmd"
5
+ export * from "./data-sources"
5
6
  export * from "./displayers"
6
7
  export * from "./env"
7
8
  export * from "./forward-exports"
@@ -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: InputPortSetRecord<InNames>): PortSet<Names | InNames>
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: mapping[entry.name as keyof typeof mapping]
84
+ target: portVal as any
71
85
  }
72
86
  })
73
87
  )
74
88
  }
75
89
 
76
- static make<Names extends string>(input: InputPortSetRecord<Names>) {
90
+ static make<Names extends string>(input?: InputPortSetRecord<Names>) {
77
91
  return new PortSet().add(input)
78
92
  }
79
93
  }
@@ -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
- [K in Names]: number
42
- }
40
+ export type InputPortMapping<Names extends string = string> = [Names] extends [never]
41
+ ? never
42
+ : {
43
+ [K in Names]: number | true
44
+ }