@xplane/utils 0.0.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.
@@ -0,0 +1,135 @@
1
+ import { KubeConfig, KubernetesObject } from "@kubernetes/client-node";
2
+
3
+ //#region src/watcher/types.d.ts
4
+ /**
5
+ * Reference to a single Crossplane Composite Resource (XR) the watcher should track.
6
+ */
7
+ interface XrRef {
8
+ /** API group, e.g. `platform.example.com`. Empty string for the core group. */
9
+ group: string;
10
+ /** API version, e.g. `v1alpha1`. */
11
+ version: string;
12
+ /** Resource plural, e.g. `xprojects`. */
13
+ plural: string;
14
+ /** Resource kind, e.g. `XProject`. */
15
+ kind: string;
16
+ /** Whether the resource is namespaced. */
17
+ namespaced: boolean;
18
+ /** Object name. */
19
+ name: string;
20
+ /** Namespace; required when `namespaced` is true. */
21
+ namespace?: string;
22
+ }
23
+ /** A composed resource entry as published in `status.xplane.emittedResources`. */
24
+ interface EmittedResource {
25
+ apiVersion: string;
26
+ kind: string;
27
+ /** Construct path within the composition (also the Crossplane composed-resource key). */
28
+ nodePath: string;
29
+ /** Kubernetes `metadata.name`, when known. */
30
+ name?: string;
31
+ /** Kubernetes `metadata.namespace`, when present. */
32
+ namespace?: string;
33
+ ready: boolean;
34
+ }
35
+ /** A blocked resource entry as published in `status.xplane.blockedResources`. */
36
+ interface BlockedResource {
37
+ apiVersion: string;
38
+ kind: string;
39
+ /** Construct path within the composition (also the Crossplane composed-resource key). */
40
+ nodePath: string;
41
+ /** Kubernetes `metadata.name`, when known. */
42
+ name?: string;
43
+ /** Kubernetes `metadata.namespace`, when present. */
44
+ namespace?: string;
45
+ waitingFor?: string[];
46
+ }
47
+ /** The compact observability payload set on the XR when `emitXplaneStatus = true`. */
48
+ interface XplaneStatus {
49
+ emittedResources: EmittedResource[];
50
+ blockedResources: BlockedResource[];
51
+ }
52
+ /** A `spec.resourceRefs` / `status.resourceRefs` entry on a Crossplane XR. */
53
+ interface ResourceRef {
54
+ apiVersion: string;
55
+ kind: string;
56
+ name: string;
57
+ }
58
+ /** Snapshot of an XR's state as observed by the watcher. */
59
+ interface XrSnapshot {
60
+ /** The full XR object from the API server. */
61
+ object: KubernetesObject;
62
+ /** True when a `Ready` condition with `status: "True"` is present. */
63
+ ready: boolean;
64
+ /** Reason of the `Ready` condition, if any. */
65
+ readyReason?: string;
66
+ /** Message of the `Ready` condition, if any. */
67
+ readyMessage?: string;
68
+ /** True when a `Responsive` condition reports `status: "False"` with reason `WatchCircuitOpen`. */
69
+ updatesThrottled?: boolean;
70
+ /** Present when the `Synced` condition is `status: "False"` with reason `ReconcileError` — a fatal reconcile failure. */
71
+ syncError?: {
72
+ reason: string;
73
+ message: string;
74
+ };
75
+ /** Parsed `status.xplane` payload, if present. */
76
+ xplane?: XplaneStatus;
77
+ /** Parsed `status.resourceRefs` (composed resources). */
78
+ resourceRefs: ResourceRef[];
79
+ }
80
+ /** A condensed view of a Kubernetes Event tied to the watched XR. */
81
+ interface KubernetesEvent {
82
+ type: string;
83
+ reason: string;
84
+ message: string;
85
+ count: number;
86
+ firstTimestamp?: string;
87
+ lastTimestamp?: string;
88
+ involvedKind?: string;
89
+ involvedName?: string;
90
+ }
91
+ /** Stream item emitted by the XR watcher. */
92
+ type XrEvent = {
93
+ type: 'snapshot';
94
+ snapshot: XrSnapshot;
95
+ } | {
96
+ type: 'k8s-event';
97
+ event: KubernetesEvent;
98
+ } | {
99
+ type: 'ready';
100
+ snapshot: XrSnapshot;
101
+ } | {
102
+ type: 'error';
103
+ error: Error;
104
+ } | {
105
+ type: 'end';
106
+ };
107
+ //#endregion
108
+ //#region src/watcher/xr-watcher.d.ts
109
+ interface CreateXrWatcherOptions {
110
+ kubeConfig: KubeConfig;
111
+ ref: XrRef;
112
+ /** Disable subscribing to Kubernetes Events for the XR. Defaults to `false`. */
113
+ disableEvents?: boolean;
114
+ /** Aborts both the XR and Events watches and closes the iterable. */
115
+ signal?: AbortSignal;
116
+ }
117
+ interface XrWatcher extends AsyncIterable<XrEvent> {
118
+ /** Resolves with the first ready snapshot. Rejects on error or end-before-ready. */
119
+ readonly ready: Promise<XrSnapshot>;
120
+ /** Resolves when the watcher's background tasks have all settled. */
121
+ readonly done: Promise<void>;
122
+ /** Aborts the watcher and closes the iterable. Idempotent. */
123
+ stop(): void;
124
+ }
125
+ /**
126
+ * Subscribe to live updates of a single XR. Emits a `snapshot` on every observed
127
+ * change, a one-shot `ready` when the XR's `Ready` condition first becomes True,
128
+ * and (unless disabled) `k8s-event` items for Kubernetes Events targeting the XR.
129
+ *
130
+ * The watcher uses list-then-watch with auto-reconnect — no polling.
131
+ */
132
+ declare function createXrWatcher(opts: CreateXrWatcherOptions): XrWatcher;
133
+ //#endregion
134
+ export { EmittedResource as a, XplaneStatus as c, XrSnapshot as d, BlockedResource as i, XrEvent as l, XrWatcher as n, KubernetesEvent as o, createXrWatcher as r, ResourceRef as s, CreateXrWatcherOptions as t, XrRef as u };
135
+ //# sourceMappingURL=xr-watcher-EiWHVp3o.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xr-watcher-EiWHVp3o.d.mts","names":[],"sources":["../src/watcher/types.ts","../src/watcher/xr-watcher.ts"],"mappings":";;;;;AAKA;UAAiB,KAAA;;EAEf,KAAA;EAAA;EAEA,OAAA;EAEA;EAAA,MAAA;EAIA;EAFA,IAAA;EAMA;EAJA,UAAA;EAIS;EAFT,IAAA;EAM8B;EAJ9B,SAAA;AAAA;;UAIe,eAAA;EACf,UAAA;EACA,IAAA;EAMA;EAJA,QAAA;EAKK;EAHL,IAAA;EAOe;EALf,SAAA;EACA,KAAA;AAAA;;UAIe,eAAA;EACf,UAAA;EACA,IAAA;EAMA;EAJA,QAAA;EAKU;EAHV,IAAA;EAOe;EALf,SAAA;EACA,UAAA;AAAA;;UAIe,YAAA;EACf,gBAAA,EAAkB,eAAA;EAClB,gBAAA,EAAkB,eAAe;AAAA;AAAA;AAAA,UAIlB,WAAA;EACf,UAAA;EACA,IAAA;EACA,IAAA;AAAA;;UAIe,UAAA;EAJX;EAMJ,MAAA,EAAQ,gBAAA;EAFO;EAIf,KAAA;;EAEA,WAAA;EAQS;EANT,YAAA;EAQyB;EANzB,gBAAA;EARA;EAUA,SAAA;IAAc,MAAA;IAAgB,OAAA;EAAA;EAF9B;EAIA,MAAA,GAAS,YAAA;EAFK;EAId,YAAA,EAAc,WAAA;AAAA;;UAIC,eAAA;EACf,IAAA;EACA,MAAA;EACA,OAAA;EACA,KAAA;EACA,cAAA;EACA,aAAA;EACA,YAAA;EACA,YAAA;AAAA;;KAIU,OAAA;EACN,IAAA;EAAkB,QAAA,EAAU,UAAA;AAAA;EAC5B,IAAA;EAAmB,KAAA,EAAO,eAAA;AAAA;EAC1B,IAAA;EAAe,QAAA,EAAU,UAAA;AAAA;EACzB,IAAA;EAAe,KAAA,EAAO,KAAA;AAAA;EACtB,IAAA;AAAA;;;UC5FW,sBAAA;EACf,UAAA,EAAY,UAAA;EACZ,GAAA,EAAK,KAAA;;EAEL,aAAA;EDJA;ECMA,MAAA,GAAS,WAAA;AAAA;AAAA,UAGM,SAAA,SAAkB,aAAA,CAAc,OAAA;EDD/C;EAAA,SCGS,KAAA,EAAO,OAAA,CAAQ,UAAA;EDCxB;EAAA,SCCS,IAAA,EAAM,OAAA;EDDN;ECGT,IAAA;AAAA;;;;;;;;iBAUc,eAAA,CAAgB,IAAA,EAAM,sBAAA,GAAyB,SAAS"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@xplane/utils",
3
+ "version": "0.0.0",
4
+ "type": "module",
5
+ "description": "CLI and library to watch Crossplane XRs in real time (events, status.xplane, readiness)",
6
+ "license": "Apache-2.0",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/sv-oss/xplane",
10
+ "directory": "packages/utils"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "bin": {
16
+ "xplane-utils": "./dist/cli.mjs"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.mjs",
21
+ "types": "./dist/index.d.mts"
22
+ },
23
+ "./render": {
24
+ "import": "./dist/render/index.mjs",
25
+ "types": "./dist/render/index.d.mts"
26
+ }
27
+ },
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "scripts": {
32
+ "build": "tsdown",
33
+ "test": "vitest run",
34
+ "test:watch": "vitest",
35
+ "typecheck": "tsc --noEmit",
36
+ "clean": "rm -rf dist .turbo"
37
+ },
38
+ "dependencies": {
39
+ "@kubernetes/client-node": "^1.4.0",
40
+ "chalk": "^5.3.0",
41
+ "citty": "0.2.2",
42
+ "log-update": "^7.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^25.8.0",
46
+ "@vitest/coverage-v8": "4.1.6",
47
+ "tsdown": "^0.22.0",
48
+ "typescript": "6.0.3",
49
+ "vitest": "4.1.6"
50
+ }
51
+ }