@kubernetesjs/react 0.6.1
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 +21 -0
- package/README.md +94 -0
- package/context.d.ts +20 -0
- package/context.js +87 -0
- package/esm/context.js +50 -0
- package/esm/index.js +8075 -0
- package/index.d.ts +647 -0
- package/index.js +8723 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Dan Lynch <pyramation@gmail.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# KubernetesJS
|
|
2
|
+
|
|
3
|
+
<p align="center" width="100%">
|
|
4
|
+
<img src="https://github.com/hyperweb-io/interweb-utils/assets/545047/89c743c4-be88-409f-9a77-4b02cd7fe9a4" width="80">
|
|
5
|
+
<br/>
|
|
6
|
+
TypeScript Client for Kubernetes
|
|
7
|
+
<br />
|
|
8
|
+
<a href="https://github.com/hyperweb-io/kubernetesjs/actions/workflows/ci.yml">
|
|
9
|
+
<img height="20" src="https://github.com/hyperweb-io/kubernetesjs/actions/workflows/ci.yml/badge.svg"/>
|
|
10
|
+
</a>
|
|
11
|
+
<a href="https://github.com/hyperweb-io/kubernetesjs/blob/main/LICENSE">
|
|
12
|
+
<img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/>
|
|
13
|
+
</a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
KubernetesJS is a **fully-typed**, zero-dependency TypeScript library designed to simplify interactions with Kubernetes APIs. With comprehensive TypeScript support, it provides a strongly-typed interface that makes managing Kubernetes resources clear and predictable, ideal for TypeScript developers looking to integrate Kubernetes management into their applications.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **π Fully Typed**: Complete TypeScript definitions for all functions and models for an enhanced development experience.
|
|
22
|
+
- **π Zero Dependencies**: Works out of the box without the need for additional installations.
|
|
23
|
+
- **π‘ Full Kubernetes API Coverage**: Supports all Kubernetes API endpoints with detailed TypeScript types.
|
|
24
|
+
- **π Cross-Platform**: Works with both Node.js and browser environments.
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
To install KubernetesJS, you can use npm or yarn:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install kubernetesjs
|
|
32
|
+
# or
|
|
33
|
+
yarn add kubernetesjs
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Example
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import { KubernetesClient } from "kubernetesjs";
|
|
41
|
+
|
|
42
|
+
const client = new KubernetesClient({
|
|
43
|
+
restEndpoint: 'http://127.0.0.1:8001'
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const result = await client.listCoreV1NamespacedPod({
|
|
47
|
+
path: { namespace: 'default' }
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
if (result.items && result.items.length) {
|
|
51
|
+
result.items.forEach(item => {
|
|
52
|
+
console.log('NODE:', item.spec.nodeName);
|
|
53
|
+
|
|
54
|
+
const initContainers = item.status.initContainerStatuses?.map(ic => ({
|
|
55
|
+
image: ic.image,
|
|
56
|
+
name: ic.name,
|
|
57
|
+
ready: ic.ready,
|
|
58
|
+
state: ic.state
|
|
59
|
+
}));
|
|
60
|
+
|
|
61
|
+
const containers = item.status.containerStatuses?.map(c => ({
|
|
62
|
+
image: c.image,
|
|
63
|
+
name: c.name,
|
|
64
|
+
ready: c.ready,
|
|
65
|
+
state: c.state
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
console.log({ containers });
|
|
69
|
+
console.log({ initContainers });
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Related
|
|
75
|
+
|
|
76
|
+
Checkout these related projects:
|
|
77
|
+
|
|
78
|
+
* [`schema-typescript`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-typescript)
|
|
79
|
+
Provides robust tools for handling JSON schemas and converting them to TypeScript interfaces with ease and efficiency.
|
|
80
|
+
* [`@schema-typescript/cli`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/cli)
|
|
81
|
+
CLI is the command line utility for `schema-typescript`.
|
|
82
|
+
* [`schema-sdk`](https://github.com/hyperweb-io/schema-typescript/tree/main/packages/schema-sdk)
|
|
83
|
+
Provides robust tools for handling OpenAPI schemas and converting them to TypeScript clients with ease and efficiency.
|
|
84
|
+
* [`starship`](https://github.com/hyperweb-io/starship) Unified Testing and Development for the Interchain.
|
|
85
|
+
|
|
86
|
+
## Credits
|
|
87
|
+
|
|
88
|
+
π Built by Hyperweb β if you like our tools, please checkout and contribute to [our github βοΈ](https://github.com/hyperweb-io)
|
|
89
|
+
|
|
90
|
+
## Disclaimer
|
|
91
|
+
|
|
92
|
+
AS DESCRIBED IN THE LICENSES, THE SOFTWARE IS PROVIDED βAS ISβ, AT YOUR OWN RISK, AND WITHOUT WARRANTIES OF ANY KIND.
|
|
93
|
+
|
|
94
|
+
No developer or entity involved in creating this software will be liable for any claims or damages whatsoever associated with your use, inability to use, or your interaction with other users of the code, including any direct, indirect, incidental, special, exemplary, punitive or consequential damages, or loss of profits, cryptocurrencies, tokens, or anything else of value.
|
package/context.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { KubernetesClient } from 'kubernetesjs';
|
|
3
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
4
|
+
export interface KubernetesConfig {
|
|
5
|
+
restEndpoint: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
interface KubernetesContextValue {
|
|
9
|
+
client: KubernetesClient;
|
|
10
|
+
config: KubernetesConfig;
|
|
11
|
+
updateConfig: (config: Partial<KubernetesConfig>) => void;
|
|
12
|
+
}
|
|
13
|
+
declare const queryClient: QueryClient;
|
|
14
|
+
interface KubernetesProviderProps {
|
|
15
|
+
children: React.ReactNode;
|
|
16
|
+
initialConfig?: Partial<KubernetesConfig>;
|
|
17
|
+
}
|
|
18
|
+
export declare function KubernetesProvider({ children, initialConfig }: KubernetesProviderProps): React.JSX.Element;
|
|
19
|
+
export declare function useKubernetes(): KubernetesContextValue;
|
|
20
|
+
export { queryClient };
|
package/context.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.queryClient = void 0;
|
|
37
|
+
exports.KubernetesProvider = KubernetesProvider;
|
|
38
|
+
exports.useKubernetes = useKubernetes;
|
|
39
|
+
const react_1 = __importStar(require("react"));
|
|
40
|
+
const kubernetesjs_1 = require("kubernetesjs");
|
|
41
|
+
const react_query_1 = require("@tanstack/react-query");
|
|
42
|
+
// Create context
|
|
43
|
+
const KubernetesContext = (0, react_1.createContext)(undefined);
|
|
44
|
+
// Query client for TanStack Query
|
|
45
|
+
const queryClient = new react_query_1.QueryClient({
|
|
46
|
+
defaultOptions: {
|
|
47
|
+
queries: {
|
|
48
|
+
refetchOnWindowFocus: false,
|
|
49
|
+
retry: 3,
|
|
50
|
+
staleTime: 30 * 1000, // 30 seconds
|
|
51
|
+
gcTime: 5 * 60 * 1000, // 5 minutes
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
exports.queryClient = queryClient;
|
|
56
|
+
// Provider component
|
|
57
|
+
function KubernetesProvider({ children, initialConfig }) {
|
|
58
|
+
const [config, setConfig] = (0, react_1.useState)({
|
|
59
|
+
restEndpoint: initialConfig?.restEndpoint,
|
|
60
|
+
headers: initialConfig?.headers || {},
|
|
61
|
+
});
|
|
62
|
+
// Create client instance
|
|
63
|
+
const client = (0, react_1.useMemo)(() => {
|
|
64
|
+
return new kubernetesjs_1.KubernetesClient({
|
|
65
|
+
restEndpoint: config.restEndpoint,
|
|
66
|
+
});
|
|
67
|
+
}, [config.restEndpoint]);
|
|
68
|
+
// Update config function
|
|
69
|
+
const updateConfig = (newConfig) => {
|
|
70
|
+
setConfig(prev => ({ ...prev, ...newConfig }));
|
|
71
|
+
};
|
|
72
|
+
const contextValue = {
|
|
73
|
+
client,
|
|
74
|
+
config,
|
|
75
|
+
updateConfig,
|
|
76
|
+
};
|
|
77
|
+
return (react_1.default.createElement(react_query_1.QueryClientProvider, { client: queryClient },
|
|
78
|
+
react_1.default.createElement(KubernetesContext.Provider, { value: contextValue }, children)));
|
|
79
|
+
}
|
|
80
|
+
// Hook to use Kubernetes context
|
|
81
|
+
function useKubernetes() {
|
|
82
|
+
const context = (0, react_1.useContext)(KubernetesContext);
|
|
83
|
+
if (!context) {
|
|
84
|
+
throw new Error('useKubernetes must be used within a KubernetesProvider');
|
|
85
|
+
}
|
|
86
|
+
return context;
|
|
87
|
+
}
|
package/esm/context.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React, { createContext, useContext, useMemo, useState } from 'react';
|
|
2
|
+
import { KubernetesClient } from 'kubernetesjs';
|
|
3
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
4
|
+
// Create context
|
|
5
|
+
const KubernetesContext = createContext(undefined);
|
|
6
|
+
// Query client for TanStack Query
|
|
7
|
+
const queryClient = new QueryClient({
|
|
8
|
+
defaultOptions: {
|
|
9
|
+
queries: {
|
|
10
|
+
refetchOnWindowFocus: false,
|
|
11
|
+
retry: 3,
|
|
12
|
+
staleTime: 30 * 1000, // 30 seconds
|
|
13
|
+
gcTime: 5 * 60 * 1000, // 5 minutes
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
// Provider component
|
|
18
|
+
export function KubernetesProvider({ children, initialConfig }) {
|
|
19
|
+
const [config, setConfig] = useState({
|
|
20
|
+
restEndpoint: initialConfig?.restEndpoint,
|
|
21
|
+
headers: initialConfig?.headers || {},
|
|
22
|
+
});
|
|
23
|
+
// Create client instance
|
|
24
|
+
const client = useMemo(() => {
|
|
25
|
+
return new KubernetesClient({
|
|
26
|
+
restEndpoint: config.restEndpoint,
|
|
27
|
+
});
|
|
28
|
+
}, [config.restEndpoint]);
|
|
29
|
+
// Update config function
|
|
30
|
+
const updateConfig = (newConfig) => {
|
|
31
|
+
setConfig(prev => ({ ...prev, ...newConfig }));
|
|
32
|
+
};
|
|
33
|
+
const contextValue = {
|
|
34
|
+
client,
|
|
35
|
+
config,
|
|
36
|
+
updateConfig,
|
|
37
|
+
};
|
|
38
|
+
return (React.createElement(QueryClientProvider, { client: queryClient },
|
|
39
|
+
React.createElement(KubernetesContext.Provider, { value: contextValue }, children)));
|
|
40
|
+
}
|
|
41
|
+
// Hook to use Kubernetes context
|
|
42
|
+
export function useKubernetes() {
|
|
43
|
+
const context = useContext(KubernetesContext);
|
|
44
|
+
if (!context) {
|
|
45
|
+
throw new Error('useKubernetes must be used within a KubernetesProvider');
|
|
46
|
+
}
|
|
47
|
+
return context;
|
|
48
|
+
}
|
|
49
|
+
// Export query client for use in hooks
|
|
50
|
+
export { queryClient };
|