kubernetes-fluent-client 3.0.4 → 3.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.
Files changed (76) hide show
  1. package/e2e/cli.e2e.test.ts +11 -7
  2. package/package.json +6 -6
  3. package/src/fluent/http2-watch.spec.ts +335 -0
  4. package/src/fluent/watch.ts +174 -35
  5. package/dist/cli.d.ts +0 -3
  6. package/dist/cli.d.ts.map +0 -1
  7. package/dist/cli.js +0 -68
  8. package/dist/fetch.d.ts +0 -22
  9. package/dist/fetch.d.ts.map +0 -1
  10. package/dist/fetch.js +0 -82
  11. package/dist/fetch.test.d.ts +0 -2
  12. package/dist/fetch.test.d.ts.map +0 -1
  13. package/dist/fetch.test.js +0 -97
  14. package/dist/fileSystem.d.ts +0 -11
  15. package/dist/fileSystem.d.ts.map +0 -1
  16. package/dist/fileSystem.js +0 -42
  17. package/dist/fileSystem.test.d.ts +0 -2
  18. package/dist/fileSystem.test.d.ts.map +0 -1
  19. package/dist/fileSystem.test.js +0 -75
  20. package/dist/fluent/index.d.ts +0 -12
  21. package/dist/fluent/index.d.ts.map +0 -1
  22. package/dist/fluent/index.js +0 -228
  23. package/dist/fluent/index.test.d.ts +0 -2
  24. package/dist/fluent/index.test.d.ts.map +0 -1
  25. package/dist/fluent/index.test.js +0 -193
  26. package/dist/fluent/types.d.ts +0 -187
  27. package/dist/fluent/types.d.ts.map +0 -1
  28. package/dist/fluent/types.js +0 -16
  29. package/dist/fluent/utils.d.ts +0 -41
  30. package/dist/fluent/utils.d.ts.map +0 -1
  31. package/dist/fluent/utils.js +0 -153
  32. package/dist/fluent/utils.test.d.ts +0 -2
  33. package/dist/fluent/utils.test.d.ts.map +0 -1
  34. package/dist/fluent/utils.test.js +0 -215
  35. package/dist/fluent/watch.d.ts +0 -86
  36. package/dist/fluent/watch.d.ts.map +0 -1
  37. package/dist/fluent/watch.js +0 -425
  38. package/dist/fluent/watch.spec.d.ts +0 -2
  39. package/dist/fluent/watch.spec.d.ts.map +0 -1
  40. package/dist/fluent/watch.spec.js +0 -261
  41. package/dist/generate.d.ts +0 -84
  42. package/dist/generate.d.ts.map +0 -1
  43. package/dist/generate.js +0 -208
  44. package/dist/generate.test.d.ts +0 -2
  45. package/dist/generate.test.d.ts.map +0 -1
  46. package/dist/generate.test.js +0 -320
  47. package/dist/helpers.d.ts +0 -33
  48. package/dist/helpers.d.ts.map +0 -1
  49. package/dist/helpers.js +0 -103
  50. package/dist/helpers.test.d.ts +0 -2
  51. package/dist/helpers.test.d.ts.map +0 -1
  52. package/dist/helpers.test.js +0 -37
  53. package/dist/index.d.ts +0 -14
  54. package/dist/index.d.ts.map +0 -1
  55. package/dist/index.js +0 -60
  56. package/dist/kinds.d.ts +0 -16
  57. package/dist/kinds.d.ts.map +0 -1
  58. package/dist/kinds.js +0 -570
  59. package/dist/kinds.test.d.ts +0 -2
  60. package/dist/kinds.test.d.ts.map +0 -1
  61. package/dist/kinds.test.js +0 -155
  62. package/dist/patch.d.ts +0 -7
  63. package/dist/patch.d.ts.map +0 -1
  64. package/dist/patch.js +0 -2
  65. package/dist/postProcessing.d.ts +0 -246
  66. package/dist/postProcessing.d.ts.map +0 -1
  67. package/dist/postProcessing.js +0 -497
  68. package/dist/postProcessing.test.d.ts +0 -2
  69. package/dist/postProcessing.test.d.ts.map +0 -1
  70. package/dist/postProcessing.test.js +0 -550
  71. package/dist/types.d.ts +0 -32
  72. package/dist/types.d.ts.map +0 -1
  73. package/dist/types.js +0 -16
  74. package/dist/upstream.d.ts +0 -4
  75. package/dist/upstream.d.ts.map +0 -1
  76. package/dist/upstream.js +0 -56
package/dist/cli.js DELETED
@@ -1,68 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- // SPDX-License-Identifier: Apache-2.0
4
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
5
- var __importDefault = (this && this.__importDefault) || function (mod) {
6
- return (mod && mod.__esModule) ? mod : { "default": mod };
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const helpers_1 = require("yargs/helpers");
10
- const yargs_1 = __importDefault(require("yargs/yargs"));
11
- const generate_1 = require("./generate");
12
- const package_json_1 = require("../package.json");
13
- const postProcessing_1 = require("./postProcessing");
14
- const fileSystem_1 = require("./fileSystem"); // Import your new file system
15
- void (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
16
- .version("version", "Display version number", `kubernetes-fluent-client v${package_json_1.version}`)
17
- .alias("version", "V")
18
- .command("crd [source] [directory]", "generate usable types from a K8s CRD", yargs => {
19
- return yargs
20
- .positional("source", {
21
- describe: "the yaml file path, remote url, or K8s CRD name",
22
- type: "string",
23
- })
24
- .positional("directory", {
25
- describe: "the directory to output the generated types to",
26
- type: "string",
27
- })
28
- .option("plain", {
29
- alias: "p",
30
- type: "boolean",
31
- description: "generate plain types without binding to the fluent client, automatically enabled when an alternate language is specified",
32
- })
33
- .option("language", {
34
- alias: "l",
35
- type: "string",
36
- default: "ts",
37
- description: "the language to generate types in, see https://github.com/glideapps/quicktype#target-languages for a list of supported languages",
38
- })
39
- .option("noPost", {
40
- alias: "x",
41
- type: "boolean",
42
- default: false,
43
- description: "disable post-processing after generating the types",
44
- })
45
- .demandOption(["source", "directory"]);
46
- }, async (argv) => {
47
- const opts = argv;
48
- opts.logFn = console.log;
49
- // Pass the `post` flag to opts
50
- opts.noPost = argv.noPost;
51
- // Use NodeFileSystem as the file system for post-processing
52
- const fileSystem = new fileSystem_1.NodeFileSystem(); // Create an instance of NodeFileSystem
53
- if (!opts.noPost) {
54
- console.log("\n✅ Post-processing has been enabled.\n");
55
- }
56
- try {
57
- // Capture the results returned by generate
58
- const allResults = await (0, generate_1.generate)(opts);
59
- // If noPost is false, run post-processing
60
- if (!opts.noPost) {
61
- await (0, postProcessing_1.postProcessing)(allResults, opts, fileSystem); // Pass the file system to postProcessing
62
- }
63
- }
64
- catch (e) {
65
- console.log(`\n❌ ${e.message}`);
66
- }
67
- })
68
- .parse();
package/dist/fetch.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { RequestInfo, RequestInit } from "node-fetch";
2
- export type FetchResponse<T> = {
3
- data: T;
4
- ok: boolean;
5
- status: number;
6
- statusText: string;
7
- };
8
- /**
9
- * Perform an async HTTP call and return the parsed JSON response, optionally
10
- * as a specific type.
11
- *
12
- * @example
13
- * ```ts
14
- * fetch<string[]>("https://example.com/api/foo");
15
- * ```
16
- *
17
- * @param url The URL or Request object to fetch
18
- * @param init Additional options for the request
19
- * @returns The parsed JSON response
20
- */
21
- export declare function fetch<T>(url: URL | RequestInfo, init?: RequestInit): Promise<FetchResponse<T>>;
22
- //# sourceMappingURL=fetch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../src/fetch.ts"],"names":[],"mappings":"AAIA,OAAiB,EAAc,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE5E,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;IAC7B,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,wBAAsB,KAAK,CAAC,CAAC,EAC3B,GAAG,EAAE,GAAG,GAAG,WAAW,EACtB,IAAI,CAAC,EAAE,WAAW,GACjB,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAwC3B"}
package/dist/fetch.js DELETED
@@ -1,82 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.fetch = fetch;
29
- const http_status_codes_1 = require("http-status-codes");
30
- const node_fetch_1 = __importStar(require("node-fetch"));
31
- /**
32
- * Perform an async HTTP call and return the parsed JSON response, optionally
33
- * as a specific type.
34
- *
35
- * @example
36
- * ```ts
37
- * fetch<string[]>("https://example.com/api/foo");
38
- * ```
39
- *
40
- * @param url The URL or Request object to fetch
41
- * @param init Additional options for the request
42
- * @returns The parsed JSON response
43
- */
44
- async function fetch(url, init) {
45
- let data = undefined;
46
- try {
47
- const resp = await (0, node_fetch_1.default)(url, init);
48
- const contentType = resp.headers.get("content-type") || "";
49
- // Parse the response as JSON if the content type is JSON
50
- if (contentType.includes("application/json")) {
51
- data = await resp.json();
52
- }
53
- else {
54
- // Otherwise, return however the response was read
55
- data = (await resp.text());
56
- }
57
- return {
58
- data,
59
- ok: resp.ok,
60
- status: resp.status,
61
- statusText: resp.statusText,
62
- };
63
- }
64
- catch (e) {
65
- if (e instanceof node_fetch_1.FetchError) {
66
- // Parse the error code from the FetchError or default to 400 (Bad Request)
67
- const status = parseInt(e.code || "400");
68
- return {
69
- data,
70
- ok: false,
71
- status,
72
- statusText: e.message,
73
- };
74
- }
75
- return {
76
- data,
77
- ok: false,
78
- status: http_status_codes_1.StatusCodes.BAD_REQUEST,
79
- statusText: "Unknown error",
80
- };
81
- }
82
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fetch.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch.test.d.ts","sourceRoot":"","sources":["../src/fetch.test.ts"],"names":[],"mappings":""}
@@ -1,97 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- const globals_1 = require("@jest/globals");
9
- const http_status_codes_1 = require("http-status-codes");
10
- const nock_1 = __importDefault(require("nock"));
11
- const fetch_1 = require("./fetch");
12
- (0, globals_1.beforeEach)(() => {
13
- (0, nock_1.default)("https://jsonplaceholder.typicode.com")
14
- .get("/todos/1")
15
- .reply(200, {
16
- userId: 1,
17
- id: 1,
18
- title: "Example title",
19
- completed: false,
20
- })
21
- .post("/todos", {
22
- title: "test todo",
23
- userId: 1,
24
- completed: false,
25
- })
26
- .reply(200, (uri, requestBody) => requestBody)
27
- .get("/todos/empty-null")
28
- .reply(200, undefined)
29
- .get("/todos/empty-string")
30
- .reply(200, "")
31
- .get("/todos/empty-object")
32
- .reply(200, {})
33
- .get("/todos/invalid")
34
- .replyWithError("Something bad happened");
35
- });
36
- (0, globals_1.test)("fetch: should return without type data", async () => {
37
- const url = "https://jsonplaceholder.typicode.com/todos/1";
38
- const { data, ok } = await (0, fetch_1.fetch)(url);
39
- (0, globals_1.expect)(ok).toBe(true);
40
- (0, globals_1.expect)(data["title"]).toBe("Example title");
41
- });
42
- (0, globals_1.test)("fetch: should return parsed JSON response as a specific type", async () => {
43
- const url = "https://jsonplaceholder.typicode.com/todos/1";
44
- const { data, ok } = await (0, fetch_1.fetch)(url);
45
- (0, globals_1.expect)(ok).toBe(true);
46
- (0, globals_1.expect)(data.id).toBe(1);
47
- (0, globals_1.expect)(typeof data.title).toBe("string");
48
- (0, globals_1.expect)(typeof data.completed).toBe("boolean");
49
- });
50
- (0, globals_1.test)("fetch: should handle additional request options", async () => {
51
- const url = "https://jsonplaceholder.typicode.com/todos";
52
- const requestOptions = {
53
- method: "POST",
54
- body: JSON.stringify({
55
- title: "test todo",
56
- userId: 1,
57
- completed: false,
58
- }),
59
- headers: {
60
- "Content-type": "application/json; charset=UTF-8",
61
- },
62
- };
63
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
- const { data, ok } = await (0, fetch_1.fetch)(url, requestOptions);
65
- (0, globals_1.expect)(ok).toBe(true);
66
- (0, globals_1.expect)(data["title"]).toBe("test todo");
67
- (0, globals_1.expect)(data["userId"]).toBe(1);
68
- (0, globals_1.expect)(data["completed"]).toBe(false);
69
- });
70
- (0, globals_1.test)("fetch: should handle empty (null) responses", async () => {
71
- const url = "https://jsonplaceholder.typicode.com/todos/empty-null";
72
- const resp = await (0, fetch_1.fetch)(url);
73
- (0, globals_1.expect)(resp.data).toBe("");
74
- (0, globals_1.expect)(resp.ok).toBe(true);
75
- (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
76
- });
77
- (0, globals_1.test)("fetch: should handle empty (string) responses", async () => {
78
- const url = "https://jsonplaceholder.typicode.com/todos/empty-string";
79
- const resp = await (0, fetch_1.fetch)(url);
80
- (0, globals_1.expect)(resp.data).toBe("");
81
- (0, globals_1.expect)(resp.ok).toBe(true);
82
- (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
83
- });
84
- (0, globals_1.test)("fetch: should handle empty (object) responses", async () => {
85
- const url = "https://jsonplaceholder.typicode.com/todos/empty-object";
86
- const resp = await (0, fetch_1.fetch)(url);
87
- (0, globals_1.expect)(resp.data).toEqual({});
88
- (0, globals_1.expect)(resp.ok).toBe(true);
89
- (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.OK);
90
- });
91
- (0, globals_1.test)("fetch: should handle failed requests without throwing an error", async () => {
92
- const url = "https://jsonplaceholder.typicode.com/todos/invalid";
93
- const resp = await (0, fetch_1.fetch)(url);
94
- (0, globals_1.expect)(resp.data).toBe(undefined);
95
- (0, globals_1.expect)(resp.ok).toBe(false);
96
- (0, globals_1.expect)(resp.status).toBe(http_status_codes_1.StatusCodes.BAD_REQUEST);
97
- });
@@ -1,11 +0,0 @@
1
- export interface FileSystem {
2
- readFile(filePath: string): string;
3
- writeFile(filePath: string, content: string): void;
4
- readdirSync(directory: string): string[];
5
- }
6
- export declare class NodeFileSystem implements FileSystem {
7
- readFile(filePath: string): string;
8
- writeFile(filePath: string, content: string): void;
9
- readdirSync(directory: string): string[];
10
- }
11
- //# sourceMappingURL=fileSystem.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fileSystem.d.ts","sourceRoot":"","sources":["../src/fileSystem.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACnD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;CAC1C;AAGD,qBAAa,cAAe,YAAW,UAAU;IAC/C,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAIlC,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIlD,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;CAGzC"}
@@ -1,42 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.NodeFileSystem = void 0;
29
- const fs = __importStar(require("fs"));
30
- /* eslint class-methods-use-this: "off" */
31
- class NodeFileSystem {
32
- readFile(filePath) {
33
- return fs.readFileSync(filePath, "utf8");
34
- }
35
- writeFile(filePath, content) {
36
- fs.writeFileSync(filePath, content, "utf8");
37
- }
38
- readdirSync(directory) {
39
- return fs.readdirSync(directory);
40
- }
41
- }
42
- exports.NodeFileSystem = NodeFileSystem;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=fileSystem.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fileSystem.test.d.ts","sourceRoot":"","sources":["../src/fileSystem.test.ts"],"names":[],"mappings":""}
@@ -1,75 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5
- if (k2 === undefined) k2 = k;
6
- var desc = Object.getOwnPropertyDescriptor(m, k);
7
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
8
- desc = { enumerable: true, get: function() { return m[k]; } };
9
- }
10
- Object.defineProperty(o, k2, desc);
11
- }) : (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- o[k2] = m[k];
14
- }));
15
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
16
- Object.defineProperty(o, "default", { enumerable: true, value: v });
17
- }) : function(o, v) {
18
- o["default"] = v;
19
- });
20
- var __importStar = (this && this.__importStar) || function (mod) {
21
- if (mod && mod.__esModule) return mod;
22
- var result = {};
23
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
24
- __setModuleDefault(result, mod);
25
- return result;
26
- };
27
- Object.defineProperty(exports, "__esModule", { value: true });
28
- const fs = __importStar(require("fs"));
29
- const fileSystem_1 = require("./fileSystem");
30
- const globals_1 = require("@jest/globals");
31
- // Mock the fs module
32
- globals_1.jest.mock("fs");
33
- (0, globals_1.describe)("NodeFileSystem", () => {
34
- let nodeFileSystem;
35
- (0, globals_1.beforeEach)(() => {
36
- nodeFileSystem = new fileSystem_1.NodeFileSystem();
37
- globals_1.jest.clearAllMocks(); // Clear all mocks before each test
38
- });
39
- (0, globals_1.describe)("readFile", () => {
40
- (0, globals_1.test)("should call fs.readFileSync with correct arguments", () => {
41
- const mockFilePath = "test-file.txt";
42
- const mockFileContent = "This is a test file";
43
- // Mock the fs.readFileSync method to return the mock file content
44
- fs.readFileSync.mockReturnValue(mockFileContent);
45
- const result = nodeFileSystem.readFile(mockFilePath);
46
- // Assert that fs.readFileSync was called with the correct file path and encoding
47
- (0, globals_1.expect)(fs.readFileSync).toHaveBeenCalledWith(mockFilePath, "utf8");
48
- // Assert that the returned content matches the mock file content
49
- (0, globals_1.expect)(result).toBe(mockFileContent);
50
- });
51
- });
52
- (0, globals_1.describe)("writeFile", () => {
53
- (0, globals_1.test)("should call fs.writeFileSync with correct arguments", () => {
54
- const mockFilePath = "test-file.txt";
55
- const mockFileContent = "This is a test file";
56
- // Call the writeFile method
57
- nodeFileSystem.writeFile(mockFilePath, mockFileContent);
58
- // Assert that fs.writeFileSync was called with the correct arguments
59
- (0, globals_1.expect)(fs.writeFileSync).toHaveBeenCalledWith(mockFilePath, mockFileContent, "utf8");
60
- });
61
- });
62
- (0, globals_1.describe)("readdirSync", () => {
63
- (0, globals_1.test)("should call fs.readdirSync with correct arguments and return file list", () => {
64
- const mockDirectoryPath = "test-directory";
65
- const mockFileList = ["file1.txt", "file2.txt"];
66
- // Mock the fs.readdirSync method to return the mock file list
67
- fs.readdirSync.mockReturnValue(mockFileList);
68
- const result = nodeFileSystem.readdirSync(mockDirectoryPath);
69
- // Assert that fs.readdirSync was called with the correct directory path
70
- (0, globals_1.expect)(fs.readdirSync).toHaveBeenCalledWith(mockDirectoryPath);
71
- // Assert that the returned file list matches the mock file list
72
- (0, globals_1.expect)(result).toEqual(mockFileList);
73
- });
74
- });
75
- });
@@ -1,12 +0,0 @@
1
- import { KubernetesObject } from "@kubernetes/client-node";
2
- import { GenericClass } from "../types";
3
- import { Filters, K8sInit } from "./types";
4
- /**
5
- * Kubernetes fluent API inspired by Kubectl. Pass in a model, then call filters and actions on it.
6
- *
7
- * @param model - the model to use for the API
8
- * @param filters - (optional) filter overrides, can also be chained
9
- * @returns a fluent API for the model
10
- */
11
- export declare function K8s<T extends GenericClass, K extends KubernetesObject = InstanceType<T>>(model: T, filters?: Filters): K8sInit<T, K>;
12
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/fluent/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAwB,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAA0B,OAAO,EAAE,OAAO,EAAsB,MAAM,SAAS,CAAC;AAKvF;;;;;;GAMG;AACH,wBAAgB,GAAG,CAAC,CAAC,SAAS,YAAY,EAAE,CAAC,SAAS,gBAAgB,GAAG,YAAY,CAAC,CAAC,CAAC,EACtF,KAAK,EAAE,CAAC,EACR,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CA0Pf"}
@@ -1,228 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.K8s = K8s;
6
- const http_status_codes_1 = require("http-status-codes");
7
- const fetch_1 = require("../fetch");
8
- const kinds_1 = require("../kinds");
9
- const utils_1 = require("./utils");
10
- const watch_1 = require("./watch");
11
- const helpers_1 = require("../helpers");
12
- const upstream_1 = require("../upstream");
13
- /**
14
- * Kubernetes fluent API inspired by Kubectl. Pass in a model, then call filters and actions on it.
15
- *
16
- * @param model - the model to use for the API
17
- * @param filters - (optional) filter overrides, can also be chained
18
- * @returns a fluent API for the model
19
- */
20
- function K8s(model, filters = {}) {
21
- const withFilters = { WithField, WithLabel, Get, Delete, Watch, Logs };
22
- const matchedKind = filters.kindOverride || (0, kinds_1.modelToGroupVersionKind)(model.name);
23
- /**
24
- * @inheritdoc
25
- * @see {@link K8sInit.InNamespace}
26
- */
27
- function InNamespace(namespace) {
28
- if (filters.namespace) {
29
- throw new Error(`Namespace already specified: ${filters.namespace}`);
30
- }
31
- filters.namespace = namespace;
32
- return withFilters;
33
- }
34
- /**
35
- * @inheritdoc
36
- * @see {@link K8sInit.WithField}
37
- */
38
- function WithField(key, value) {
39
- filters.fields = filters.fields || {};
40
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
41
- // @ts-ignore
42
- filters.fields[key] = value;
43
- return withFilters;
44
- }
45
- /**
46
- * @inheritdoc
47
- * @see {@link K8sInit.WithLabel}
48
- */
49
- function WithLabel(key, value = "") {
50
- filters.labels = filters.labels || {};
51
- filters.labels[key] = value;
52
- return withFilters;
53
- }
54
- /**
55
- * Sync the filters with the provided payload.
56
- *
57
- * @param payload - the payload to sync with
58
- */
59
- function syncFilters(payload) {
60
- // Ensure the payload has metadata
61
- payload.metadata = payload.metadata || {};
62
- if (!filters.namespace) {
63
- filters.namespace = payload.metadata.namespace;
64
- }
65
- if (!filters.name) {
66
- filters.name = payload.metadata.name;
67
- }
68
- if (!payload.apiVersion) {
69
- payload.apiVersion = [matchedKind.group, matchedKind.version].filter(Boolean).join("/");
70
- }
71
- if (!payload.kind) {
72
- payload.kind = matchedKind.kind;
73
- }
74
- }
75
- /**
76
- * @inheritdoc
77
- * @see {@link K8sInit.Logs}
78
- */
79
- async function Logs(name) {
80
- let labels = {};
81
- const { kind } = matchedKind;
82
- const { namespace } = filters;
83
- const podList = [];
84
- if (name) {
85
- if (filters.name) {
86
- throw new Error(`Name already specified: ${filters.name}`);
87
- }
88
- filters.name = name;
89
- }
90
- if (!namespace) {
91
- throw new Error("Namespace must be defined");
92
- }
93
- if (!(0, helpers_1.hasLogs)(kind)) {
94
- throw new Error("Kind must be Pod or have a selector");
95
- }
96
- try {
97
- const object = await (0, utils_1.k8sExec)(model, filters, "GET");
98
- if (kind !== "Pod") {
99
- if (kind === "Service") {
100
- const svc = object;
101
- labels = svc.spec.selector ?? {};
102
- }
103
- else if (kind === "ReplicaSet" ||
104
- kind === "Deployment" ||
105
- kind === "StatefulSet" ||
106
- kind === "DaemonSet") {
107
- const rs = object;
108
- labels = rs.spec.selector.matchLabels ?? {};
109
- }
110
- const list = await K8s(upstream_1.Pod, { namespace: filters.namespace, labels }).Get();
111
- list.items.forEach(item => {
112
- return podList.push(item);
113
- });
114
- }
115
- else {
116
- podList.push(object);
117
- }
118
- }
119
- catch {
120
- throw new Error(`Failed to get logs in KFC Logs function`);
121
- }
122
- const podModel = { ...model, name: "V1Pod" };
123
- const logPromises = podList.map(po => (0, utils_1.k8sExec)(podModel, { ...filters, name: po.metadata.name }, "LOG"));
124
- const responses = await Promise.all(logPromises);
125
- const combinedString = responses.reduce((accumulator, currentString, i) => {
126
- const prefixedLines = currentString
127
- .split("\n")
128
- .map(line => {
129
- return line !== "" ? `[pod/${podList[i].metadata.name}] ${line}` : "";
130
- })
131
- .filter(str => str !== "");
132
- return [...accumulator, ...prefixedLines];
133
- }, []);
134
- return combinedString;
135
- }
136
- /**
137
- * @inheritdoc
138
- * @see {@link K8sInit.Get}
139
- */
140
- async function Get(name) {
141
- if (name) {
142
- if (filters.name) {
143
- throw new Error(`Name already specified: ${filters.name}`);
144
- }
145
- filters.name = name;
146
- }
147
- return (0, utils_1.k8sExec)(model, filters, "GET");
148
- }
149
- /**
150
- * @inheritdoc
151
- * @see {@link K8sInit.Delete}
152
- */
153
- async function Delete(filter) {
154
- if (typeof filter === "string") {
155
- filters.name = filter;
156
- }
157
- else if (filter) {
158
- syncFilters(filter);
159
- }
160
- try {
161
- // Try to delete the resource
162
- await (0, utils_1.k8sExec)(model, filters, "DELETE");
163
- }
164
- catch (e) {
165
- // If the resource doesn't exist, ignore the error
166
- if (e.status === http_status_codes_1.StatusCodes.NOT_FOUND) {
167
- return;
168
- }
169
- throw e;
170
- }
171
- }
172
- /**
173
- * @inheritdoc
174
- * @see {@link K8sInit.Apply}
175
- */
176
- async function Apply(resource, applyCfg = { force: false }) {
177
- syncFilters(resource);
178
- return (0, utils_1.k8sExec)(model, filters, "APPLY", resource, applyCfg);
179
- }
180
- /**
181
- * @inheritdoc
182
- * @see {@link K8sInit.Create}
183
- */
184
- async function Create(resource) {
185
- syncFilters(resource);
186
- return (0, utils_1.k8sExec)(model, filters, "POST", resource);
187
- }
188
- /**
189
- * @inheritdoc
190
- * @see {@link K8sInit.Patch}
191
- */
192
- async function Patch(payload) {
193
- // If there are no operations, throw an error
194
- if (payload.length < 1) {
195
- throw new Error("No operations specified");
196
- }
197
- return (0, utils_1.k8sExec)(model, filters, "PATCH", payload);
198
- }
199
- /**
200
- * @inheritdoc
201
- * @see {@link K8sInit.PatchStatus}
202
- */
203
- async function PatchStatus(resource) {
204
- syncFilters(resource);
205
- return (0, utils_1.k8sExec)(model, filters, "PATCH_STATUS", resource);
206
- }
207
- /**
208
- * @inheritdoc
209
- * @see {@link K8sInit.Watch}
210
- */
211
- function Watch(callback, watchCfg) {
212
- return new watch_1.Watcher(model, filters, callback, watchCfg);
213
- }
214
- /**
215
- * @inheritdoc
216
- * @see {@link K8sInit.Raw}
217
- */
218
- async function Raw(url, method = "GET") {
219
- const thing = await (0, utils_1.k8sCfg)(method);
220
- const { opts, serverUrl } = thing;
221
- const resp = await (0, fetch_1.fetch)(`${serverUrl}${url}`, opts);
222
- if (resp.ok) {
223
- return resp.data;
224
- }
225
- throw resp;
226
- }
227
- return { InNamespace, Apply, Create, Patch, PatchStatus, Raw, ...withFilters };
228
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.test.d.ts.map