kubernetes-fluent-client 3.5.6 → 3.6.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/cli.js +9 -16
- package/dist/fetch.js +5 -8
- package/dist/fluent/index.d.ts +2 -1
- package/dist/fluent/index.d.ts.map +1 -1
- package/dist/fluent/index.js +27 -29
- package/dist/fluent/shared-types.d.ts +49 -0
- package/dist/fluent/shared-types.d.ts.map +1 -0
- package/dist/fluent/shared-types.js +23 -0
- package/dist/fluent/types.d.ts +2 -37
- package/dist/fluent/types.d.ts.map +1 -1
- package/dist/fluent/types.js +1 -14
- package/dist/fluent/utils.d.ts +1 -1
- package/dist/fluent/utils.d.ts.map +1 -1
- package/dist/fluent/utils.js +25 -35
- package/dist/fluent/watch.d.ts +1 -8
- package/dist/fluent/watch.d.ts.map +1 -1
- package/dist/fluent/watch.js +23 -43
- package/dist/generate.js +22 -65
- package/dist/helpers.js +5 -10
- package/dist/index.js +13 -60
- package/dist/kinds.js +2 -7
- package/dist/normalization.d.ts +97 -0
- package/dist/normalization.d.ts.map +1 -0
- package/dist/normalization.js +152 -0
- package/dist/patch.js +1 -2
- package/dist/postProcessing.d.ts +6 -127
- package/dist/postProcessing.d.ts.map +1 -1
- package/dist/postProcessing.js +24 -279
- package/dist/types.d.ts +3 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -5
- package/dist/upstream.js +2 -53
- package/package.json +11 -8
- package/src/cli.ts +1 -3
- package/src/fluent/index.ts +12 -11
- package/src/fluent/shared-types.ts +55 -0
- package/src/fluent/types.ts +3 -54
- package/src/fluent/utils.ts +2 -2
- package/src/fluent/watch.ts +2 -21
- package/src/normalization.ts +181 -0
- package/src/postProcessing.ts +11 -239
- package/src/types.ts +3 -4
- package/dist/fileSystem.d.ts +0 -11
- package/dist/fileSystem.d.ts.map +0 -1
- package/dist/fileSystem.js +0 -52
- package/src/fileSystem.ts +0 -25
package/dist/fluent/watch.js
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const utils_1 = require("./utils");
|
|
12
|
-
const stream_1 = require("stream");
|
|
13
|
-
var WatchEvent;
|
|
3
|
+
import { EventEmitter } from "events";
|
|
4
|
+
import { fetch } from "undici";
|
|
5
|
+
import { fetch as wrappedFetch } from "../fetch";
|
|
6
|
+
import { k8sCfg, pathBuilder, getHeaders } from "./utils";
|
|
7
|
+
import { Readable } from "stream";
|
|
8
|
+
import { WatchPhase, FetchMethods } from "./shared-types";
|
|
9
|
+
export var WatchEvent;
|
|
14
10
|
(function (WatchEvent) {
|
|
15
11
|
/** Watch is connected successfully */
|
|
16
12
|
WatchEvent["CONNECT"] = "connect";
|
|
@@ -40,11 +36,11 @@ var WatchEvent;
|
|
|
40
36
|
WatchEvent["INC_RESYNC_FAILURE_COUNT"] = "inc_resync_failure_count";
|
|
41
37
|
/** Initialize a relist window */
|
|
42
38
|
WatchEvent["INIT_CACHE_MISS"] = "init_cache_miss";
|
|
43
|
-
})(WatchEvent || (
|
|
39
|
+
})(WatchEvent || (WatchEvent = {}));
|
|
44
40
|
const NONE = 50;
|
|
45
41
|
const OVERRIDE = 100;
|
|
46
42
|
/** A wrapper around the Kubernetes watch API. */
|
|
47
|
-
class Watcher {
|
|
43
|
+
export class Watcher {
|
|
48
44
|
// User-provided properties
|
|
49
45
|
#model;
|
|
50
46
|
#filters;
|
|
@@ -61,7 +57,7 @@ class Watcher {
|
|
|
61
57
|
// Create a stream to read the response body
|
|
62
58
|
#stream;
|
|
63
59
|
// Create an EventEmitter to emit events
|
|
64
|
-
#events = new
|
|
60
|
+
#events = new EventEmitter();
|
|
65
61
|
// Create a timer to relist the watch
|
|
66
62
|
$relistTimer;
|
|
67
63
|
// Create a timer to resync the watch
|
|
@@ -130,21 +126,6 @@ class Watcher {
|
|
|
130
126
|
this.#streamCleanup();
|
|
131
127
|
this.#abortController.abort();
|
|
132
128
|
}
|
|
133
|
-
/**
|
|
134
|
-
* Get a unique ID for the watch based on the model and filters.
|
|
135
|
-
* This is useful for caching the watch data or resource versions.
|
|
136
|
-
*
|
|
137
|
-
* @returns the watch CacheID
|
|
138
|
-
*/
|
|
139
|
-
getCacheID() {
|
|
140
|
-
// Build the URL, we don't care about the server URL or resourceVersion
|
|
141
|
-
const url = (0, utils_1.pathBuilder)("https://ignore", this.#model, this.#filters, false);
|
|
142
|
-
// Hash and truncate the ID to 10 characters, cache the result
|
|
143
|
-
return (0, crypto_1.createHash)("sha224")
|
|
144
|
-
.update(url.pathname + url.search)
|
|
145
|
-
.digest("hex")
|
|
146
|
-
.substring(0, 10);
|
|
147
|
-
}
|
|
148
129
|
/**
|
|
149
130
|
* Subscribe to watch events. This is an EventEmitter that emits the following events:
|
|
150
131
|
*
|
|
@@ -166,9 +147,9 @@ class Watcher {
|
|
|
166
147
|
*/
|
|
167
148
|
#buildURL = async (isWatch, resourceVersion, continueToken) => {
|
|
168
149
|
// Build the path and query params for the resource, excluding the name
|
|
169
|
-
const { opts, serverUrl } = await (
|
|
150
|
+
const { opts, serverUrl } = await k8sCfg(FetchMethods.GET);
|
|
170
151
|
const k8sUrl = serverUrl instanceof URL ? serverUrl.toString() : serverUrl;
|
|
171
|
-
const url =
|
|
152
|
+
const url = pathBuilder(k8sUrl, this.#model, this.#filters, true);
|
|
172
153
|
// Enable the watch query param
|
|
173
154
|
if (isWatch) {
|
|
174
155
|
url.searchParams.set("watch", "true");
|
|
@@ -198,7 +179,7 @@ class Watcher {
|
|
|
198
179
|
try {
|
|
199
180
|
const { opts, serverUrl } = await this.#buildURL(false, undefined, continueToken);
|
|
200
181
|
// Make the request to list the resources
|
|
201
|
-
const response = await (
|
|
182
|
+
const response = await wrappedFetch(serverUrl, opts);
|
|
202
183
|
const list = response.data;
|
|
203
184
|
// If the request fails, emit an error event and return
|
|
204
185
|
if (!response.ok) {
|
|
@@ -224,7 +205,7 @@ class Watcher {
|
|
|
224
205
|
if (!alreadyExists) {
|
|
225
206
|
this.#events.emit(WatchEvent.CACHE_MISS, this.#latestRelistWindow);
|
|
226
207
|
// Send added event. Use void here because we don't care about the result (no consequences here if it fails)
|
|
227
|
-
void this.#process(item,
|
|
208
|
+
void this.#process(item, WatchPhase.Added);
|
|
228
209
|
continue;
|
|
229
210
|
}
|
|
230
211
|
// Check if the resource version has changed for items that already exist
|
|
@@ -234,7 +215,7 @@ class Watcher {
|
|
|
234
215
|
if (itemRV > cachedRV) {
|
|
235
216
|
this.#events.emit(WatchEvent.CACHE_MISS, this.#latestRelistWindow);
|
|
236
217
|
// Send a modified event if the resource version has changed
|
|
237
|
-
void this.#process(item,
|
|
218
|
+
void this.#process(item, WatchPhase.Modified);
|
|
238
219
|
}
|
|
239
220
|
}
|
|
240
221
|
// If there is a continue token, call the list function again with the same removed items
|
|
@@ -246,7 +227,7 @@ class Watcher {
|
|
|
246
227
|
// Otherwise, process the removed items
|
|
247
228
|
for (const item of removedItems.values()) {
|
|
248
229
|
this.#events.emit(WatchEvent.CACHE_MISS, this.#latestRelistWindow);
|
|
249
|
-
void this.#process(item,
|
|
230
|
+
void this.#process(item, WatchPhase.Deleted);
|
|
250
231
|
}
|
|
251
232
|
}
|
|
252
233
|
}
|
|
@@ -264,12 +245,12 @@ class Watcher {
|
|
|
264
245
|
try {
|
|
265
246
|
switch (phase) {
|
|
266
247
|
// If the event is added or modified, update the cache
|
|
267
|
-
case
|
|
268
|
-
case
|
|
248
|
+
case WatchPhase.Added:
|
|
249
|
+
case WatchPhase.Modified:
|
|
269
250
|
this.#cache.set(payload.metadata.uid, payload);
|
|
270
251
|
break;
|
|
271
252
|
// If the event is deleted, remove the item from the cache
|
|
272
|
-
case
|
|
253
|
+
case WatchPhase.Deleted:
|
|
273
254
|
this.#cache.delete(payload.metadata.uid);
|
|
274
255
|
break;
|
|
275
256
|
}
|
|
@@ -290,7 +271,7 @@ class Watcher {
|
|
|
290
271
|
// Update the last seen time
|
|
291
272
|
this.#lastSeenTime = Date.now();
|
|
292
273
|
// If the watch is too old, remove the resourceVersion and reload the watch
|
|
293
|
-
if (phase ===
|
|
274
|
+
if (phase === WatchPhase.Error && payload.code === 410) {
|
|
294
275
|
throw {
|
|
295
276
|
name: "TooOld",
|
|
296
277
|
message: this.#resourceVersion,
|
|
@@ -317,8 +298,8 @@ class Watcher {
|
|
|
317
298
|
await this.#list();
|
|
318
299
|
// Build the URL and request options
|
|
319
300
|
const { opts, serverUrl } = await this.#buildURL(true, this.#resourceVersion);
|
|
320
|
-
const response = await
|
|
321
|
-
headers: await
|
|
301
|
+
const response = await fetch(serverUrl, {
|
|
302
|
+
headers: await getHeaders(),
|
|
322
303
|
...opts,
|
|
323
304
|
});
|
|
324
305
|
const url = serverUrl instanceof URL ? serverUrl : new URL(serverUrl);
|
|
@@ -334,7 +315,7 @@ class Watcher {
|
|
|
334
315
|
// Reset the retry count
|
|
335
316
|
this.#resyncFailureCount = 0;
|
|
336
317
|
this.#events.emit(WatchEvent.INC_RESYNC_FAILURE_COUNT, this.#resyncFailureCount);
|
|
337
|
-
this.#stream =
|
|
318
|
+
this.#stream = Readable.from(body);
|
|
338
319
|
const decoder = new TextDecoder();
|
|
339
320
|
let buffer = "";
|
|
340
321
|
// Listen for events and call the callback function
|
|
@@ -436,4 +417,3 @@ class Watcher {
|
|
|
436
417
|
}
|
|
437
418
|
};
|
|
438
419
|
}
|
|
439
|
-
exports.Watcher = Watcher;
|
package/dist/generate.js
CHANGED
|
@@ -1,55 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.convertCRDtoTS = convertCRDtoTS;
|
|
39
|
-
exports.prepareInputData = prepareInputData;
|
|
40
|
-
exports.generateTypes = generateTypes;
|
|
41
|
-
exports.writeGeneratedFile = writeGeneratedFile;
|
|
42
|
-
exports.readOrFetchCrd = readOrFetchCrd;
|
|
43
|
-
exports.resolveFilePath = resolveFilePath;
|
|
44
|
-
exports.tryParseUrl = tryParseUrl;
|
|
45
|
-
exports.generate = generate;
|
|
46
|
-
const client_node_1 = require("@kubernetes/client-node");
|
|
47
|
-
const fs = __importStar(require("fs"));
|
|
48
|
-
const path = __importStar(require("path"));
|
|
49
|
-
const quicktype_core_1 = require("quicktype-core");
|
|
50
|
-
const fetch_1 = require("./fetch");
|
|
51
|
-
const fluent_1 = require("./fluent");
|
|
52
|
-
const upstream_1 = require("./upstream");
|
|
3
|
+
import { loadAllYaml } from "@kubernetes/client-node";
|
|
4
|
+
import * as fs from "fs";
|
|
5
|
+
import * as path from "path";
|
|
6
|
+
import { FetchingJSONSchemaStore, InputData, JSONSchemaInput, quicktype, } from "quicktype-core";
|
|
7
|
+
import { fetch } from "./fetch";
|
|
8
|
+
import { K8s } from "./fluent";
|
|
9
|
+
import { CustomResourceDefinition } from "./upstream";
|
|
53
10
|
/**
|
|
54
11
|
* Converts a CustomResourceDefinition to TypeScript types
|
|
55
12
|
*
|
|
@@ -57,7 +14,7 @@ const upstream_1 = require("./upstream");
|
|
|
57
14
|
* @param opts - The options for generating the TypeScript types.
|
|
58
15
|
* @returns A promise that resolves to a record of generated TypeScript types.
|
|
59
16
|
*/
|
|
60
|
-
async function convertCRDtoTS(crd, opts) {
|
|
17
|
+
export async function convertCRDtoTS(crd, opts) {
|
|
61
18
|
const name = crd.spec.names.kind;
|
|
62
19
|
const results = {};
|
|
63
20
|
const output = [];
|
|
@@ -90,13 +47,13 @@ async function convertCRDtoTS(crd, opts) {
|
|
|
90
47
|
* @param schema - The JSON schema as a string.
|
|
91
48
|
* @returns A promise that resolves to the input data for quicktype.
|
|
92
49
|
*/
|
|
93
|
-
async function prepareInputData(name, schema) {
|
|
50
|
+
export async function prepareInputData(name, schema) {
|
|
94
51
|
// Create a new JSONSchemaInput
|
|
95
|
-
const schemaInput = new
|
|
52
|
+
const schemaInput = new JSONSchemaInput(new FetchingJSONSchemaStore());
|
|
96
53
|
// Add the schema to the input
|
|
97
54
|
await schemaInput.addSource({ name, schema });
|
|
98
55
|
// Create a new InputData object
|
|
99
|
-
const inputData = new
|
|
56
|
+
const inputData = new InputData();
|
|
100
57
|
inputData.addInput(schemaInput);
|
|
101
58
|
return inputData;
|
|
102
59
|
}
|
|
@@ -106,10 +63,10 @@ async function prepareInputData(name, schema) {
|
|
|
106
63
|
* @param inputData - The input data for quicktype.
|
|
107
64
|
* @returns A promise that resolves to an array of generated TypeScript type lines.
|
|
108
65
|
*/
|
|
109
|
-
async function generateTypes(inputData) {
|
|
66
|
+
export async function generateTypes(inputData) {
|
|
110
67
|
// If the language is not specified, default to TypeScript
|
|
111
68
|
// Generate the types
|
|
112
|
-
const out = await
|
|
69
|
+
const out = await quicktype({
|
|
113
70
|
inputData,
|
|
114
71
|
lang: "ts",
|
|
115
72
|
rendererOptions: { "just-types": "true" },
|
|
@@ -124,7 +81,7 @@ async function generateTypes(inputData) {
|
|
|
124
81
|
* @param content - The content to write to the file.
|
|
125
82
|
* @param language - The programming language of the file.
|
|
126
83
|
*/
|
|
127
|
-
function writeGeneratedFile(fileName, directory, content, language) {
|
|
84
|
+
export function writeGeneratedFile(fileName, directory, content, language) {
|
|
128
85
|
language = language || "ts";
|
|
129
86
|
if (!directory)
|
|
130
87
|
return;
|
|
@@ -138,25 +95,25 @@ function writeGeneratedFile(fileName, directory, content, language) {
|
|
|
138
95
|
* @param opts - The options for generating the TypeScript types.
|
|
139
96
|
* @returns A promise that resolves to an array of CustomResourceDefinition objects.
|
|
140
97
|
*/
|
|
141
|
-
async function readOrFetchCrd(opts) {
|
|
98
|
+
export async function readOrFetchCrd(opts) {
|
|
142
99
|
try {
|
|
143
100
|
const filePath = resolveFilePath(opts.source);
|
|
144
101
|
if (fs.existsSync(filePath)) {
|
|
145
102
|
opts.logFn(`Attempting to load ${opts.source} as a local file`);
|
|
146
103
|
const content = fs.readFileSync(filePath, "utf8");
|
|
147
|
-
return
|
|
104
|
+
return loadAllYaml(content);
|
|
148
105
|
}
|
|
149
106
|
const url = tryParseUrl(opts.source);
|
|
150
107
|
if (url) {
|
|
151
108
|
opts.logFn(`Attempting to load ${opts.source} as a URL`);
|
|
152
|
-
const { ok, data } = await
|
|
109
|
+
const { ok, data } = await fetch(url.href);
|
|
153
110
|
if (ok) {
|
|
154
|
-
return
|
|
111
|
+
return loadAllYaml(data);
|
|
155
112
|
}
|
|
156
113
|
}
|
|
157
114
|
// Fallback to Kubernetes cluster
|
|
158
115
|
opts.logFn(`Attempting to read ${opts.source} from the Kubernetes cluster`);
|
|
159
|
-
return [await
|
|
116
|
+
return [await K8s(CustomResourceDefinition).Get(opts.source)];
|
|
160
117
|
}
|
|
161
118
|
catch (error) {
|
|
162
119
|
opts.logFn(`Error loading CRD: ${error.message}`);
|
|
@@ -169,7 +126,7 @@ async function readOrFetchCrd(opts) {
|
|
|
169
126
|
* @param source - The source path to resolve.
|
|
170
127
|
* @returns The resolved file path.
|
|
171
128
|
*/
|
|
172
|
-
function resolveFilePath(source) {
|
|
129
|
+
export function resolveFilePath(source) {
|
|
173
130
|
return source.startsWith("/") ? source : path.join(process.cwd(), source);
|
|
174
131
|
}
|
|
175
132
|
/**
|
|
@@ -178,7 +135,7 @@ function resolveFilePath(source) {
|
|
|
178
135
|
* @param source - The source string to parse as a URL.
|
|
179
136
|
* @returns The parsed URL object or null if parsing fails.
|
|
180
137
|
*/
|
|
181
|
-
function tryParseUrl(source) {
|
|
138
|
+
export function tryParseUrl(source) {
|
|
182
139
|
try {
|
|
183
140
|
return new URL(source);
|
|
184
141
|
}
|
|
@@ -192,7 +149,7 @@ function tryParseUrl(source) {
|
|
|
192
149
|
* @param opts - The options for generating the TypeScript types.
|
|
193
150
|
* @returns A promise that resolves to a record of generated TypeScript types.
|
|
194
151
|
*/
|
|
195
|
-
async function generate(opts) {
|
|
152
|
+
export async function generate(opts) {
|
|
196
153
|
const crds = (await readOrFetchCrd(opts)).filter(crd => !!crd);
|
|
197
154
|
const allResults = [];
|
|
198
155
|
opts.logFn("");
|
package/dist/helpers.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
5
|
-
exports.fromEnv = fromEnv;
|
|
6
|
-
exports.waitForCluster = waitForCluster;
|
|
7
|
-
exports.hasLogs = hasLogs;
|
|
8
|
-
const client_node_1 = require("@kubernetes/client-node");
|
|
3
|
+
import { KubeConfig } from "@kubernetes/client-node";
|
|
9
4
|
/**
|
|
10
5
|
* Sleep for a number of seconds.
|
|
11
6
|
*
|
|
@@ -31,7 +26,7 @@ function sleep(seconds) {
|
|
|
31
26
|
* @returns The value of the environment variable.
|
|
32
27
|
* @throws An error if the environment variable is not set.
|
|
33
28
|
*/
|
|
34
|
-
function fromEnv(name) {
|
|
29
|
+
export function fromEnv(name) {
|
|
35
30
|
let envValue;
|
|
36
31
|
// Check for Node.js or Bun
|
|
37
32
|
if (typeof process !== "undefined" && typeof process.env !== "undefined") {
|
|
@@ -56,8 +51,8 @@ function fromEnv(name) {
|
|
|
56
51
|
* @param seconds The number of seconds to wait for the cluster to be ready.
|
|
57
52
|
* @returns The current cluster.
|
|
58
53
|
*/
|
|
59
|
-
async function waitForCluster(seconds = 30) {
|
|
60
|
-
const kubeConfig = new
|
|
54
|
+
export async function waitForCluster(seconds = 30) {
|
|
55
|
+
const kubeConfig = new KubeConfig();
|
|
61
56
|
kubeConfig.loadFromDefault();
|
|
62
57
|
const cluster = kubeConfig.getCurrentCluster();
|
|
63
58
|
if (!cluster) {
|
|
@@ -77,7 +72,7 @@ async function waitForCluster(seconds = 30) {
|
|
|
77
72
|
* @param kind The kind of Kubernetes object.
|
|
78
73
|
* @returns boolean.
|
|
79
74
|
*/
|
|
80
|
-
function hasLogs(kind) {
|
|
75
|
+
export function hasLogs(kind) {
|
|
81
76
|
let hasSelector = false;
|
|
82
77
|
switch (kind) {
|
|
83
78
|
case "Pod":
|
package/dist/index.js
CHANGED
|
@@ -1,70 +1,23 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
|
|
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 () {
|
|
21
|
-
var ownKeys = function(o) {
|
|
22
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
-
var ar = [];
|
|
24
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
-
return ar;
|
|
26
|
-
};
|
|
27
|
-
return ownKeys(o);
|
|
28
|
-
};
|
|
29
|
-
return function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
|
-
};
|
|
36
|
-
})();
|
|
37
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
38
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
39
|
-
};
|
|
40
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
-
exports.waitForCluster = exports.fromEnv = exports.models = exports.GenericKind = exports.modelToGroupVersionKind = exports.RegisterKind = exports.K8s = exports.WatchEvent = exports.fetchStatus = exports.kind = void 0;
|
|
42
|
-
require("./patch");
|
|
3
|
+
import "./patch";
|
|
43
4
|
// Export kinds as a single object
|
|
44
|
-
|
|
45
|
-
|
|
5
|
+
import * as kind from "./upstream";
|
|
6
|
+
/** kind is a collection of K8s types to be used within a K8s call: `K8s(kind.Secret).Apply({})`. */
|
|
7
|
+
export { kind };
|
|
46
8
|
// Export the node-fetch wrapper
|
|
47
|
-
|
|
48
|
-
Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
|
|
9
|
+
export { fetch } from "./fetch";
|
|
49
10
|
// Export the HTTP status codes
|
|
50
|
-
|
|
51
|
-
Object.defineProperty(exports, "fetchStatus", { enumerable: true, get: function () { return http_status_codes_1.StatusCodes; } });
|
|
11
|
+
export { StatusCodes as fetchStatus } from "http-status-codes";
|
|
52
12
|
// Export the Watch Config and Event types
|
|
53
|
-
|
|
54
|
-
Object.defineProperty(exports, "WatchEvent", { enumerable: true, get: function () { return watch_1.WatchEvent; } });
|
|
13
|
+
export { WatchEvent } from "./fluent/watch";
|
|
55
14
|
// Export the fluent API entrypoint
|
|
56
|
-
|
|
57
|
-
Object.defineProperty(exports, "K8s", { enumerable: true, get: function () { return fluent_1.K8s; } });
|
|
15
|
+
export { K8s } from "./fluent";
|
|
58
16
|
// Export helpers for working with K8s types
|
|
59
|
-
|
|
60
|
-
Object.defineProperty(exports, "RegisterKind", { enumerable: true, get: function () { return kinds_1.RegisterKind; } });
|
|
61
|
-
Object.defineProperty(exports, "modelToGroupVersionKind", { enumerable: true, get: function () { return kinds_1.modelToGroupVersionKind; } });
|
|
17
|
+
export { RegisterKind, modelToGroupVersionKind } from "./kinds";
|
|
62
18
|
// Export the GenericKind interface for CRD registration
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
__exportStar(require("./types"), exports);
|
|
19
|
+
export { GenericKind } from "./types";
|
|
20
|
+
export * from "./types";
|
|
66
21
|
// Export the upstream raw models
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
Object.defineProperty(exports, "fromEnv", { enumerable: true, get: function () { return helpers_1.fromEnv; } });
|
|
70
|
-
Object.defineProperty(exports, "waitForCluster", { enumerable: true, get: function () { return helpers_1.waitForCluster; } });
|
|
22
|
+
export * as models from "@kubernetes/client-node/dist/gen/models/all";
|
|
23
|
+
export { fromEnv, waitForCluster } from "./helpers";
|
package/dist/kinds.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
2
|
// SPDX-FileCopyrightText: 2023-Present The Kubernetes Fluent Client Authors
|
|
4
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.RegisterKind = void 0;
|
|
6
|
-
exports.modelToGroupVersionKind = modelToGroupVersionKind;
|
|
7
3
|
const gvkMap = {
|
|
8
4
|
/**
|
|
9
5
|
* Represents a K8s Event resource (new Event in the events.k8s.io API)
|
|
@@ -551,7 +547,7 @@ const gvkMap = {
|
|
|
551
547
|
* @param key The name of the model
|
|
552
548
|
* @returns The GroupVersionKind for the model
|
|
553
549
|
*/
|
|
554
|
-
function modelToGroupVersionKind(key) {
|
|
550
|
+
export function modelToGroupVersionKind(key) {
|
|
555
551
|
return gvkMap[key];
|
|
556
552
|
}
|
|
557
553
|
/**
|
|
@@ -560,7 +556,7 @@ function modelToGroupVersionKind(key) {
|
|
|
560
556
|
* @param model Used to match the GroupVersionKind and define the type-data for the request
|
|
561
557
|
* @param groupVersionKind Contains the match parameters to determine the request should be handled
|
|
562
558
|
*/
|
|
563
|
-
const RegisterKind = (model, groupVersionKind) => {
|
|
559
|
+
export const RegisterKind = (model, groupVersionKind) => {
|
|
564
560
|
const name = model.name;
|
|
565
561
|
// Do not allow overwriting existing GVKs
|
|
566
562
|
if (gvkMap[name]) {
|
|
@@ -569,4 +565,3 @@ const RegisterKind = (model, groupVersionKind) => {
|
|
|
569
565
|
// Set the GVK
|
|
570
566
|
gvkMap[name] = groupVersionKind;
|
|
571
567
|
};
|
|
572
|
-
exports.RegisterKind = RegisterKind;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { GenerateOptions } from "./generate";
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes indentation for TypeScript lines to a consistent format.
|
|
4
|
+
*
|
|
5
|
+
* @param lines The generated TypeScript lines.
|
|
6
|
+
* @returns The lines with normalized indentation.
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeIndentation(lines: string[]): string[];
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes the indentation of a single line to use two spaces instead of four.
|
|
11
|
+
*
|
|
12
|
+
* @param line The line of code to normalize.
|
|
13
|
+
* @returns The line with normalized indentation.
|
|
14
|
+
*/
|
|
15
|
+
export declare function normalizeLineIndentation(line: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Normalizes spacing between property names and types in TypeScript lines.
|
|
18
|
+
*
|
|
19
|
+
* @param lines The generated TypeScript lines.
|
|
20
|
+
* @returns The lines with normalized property spacing.
|
|
21
|
+
*/
|
|
22
|
+
export declare function normalizePropertySpacing(lines: string[]): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Processes a single line inside a class extending `GenericKind`.
|
|
25
|
+
*
|
|
26
|
+
* @param line The current line of code.
|
|
27
|
+
* @param genericKindProperties The list of properties from `GenericKind`.
|
|
28
|
+
* @param foundInterfaces The set of found interfaces in the file.
|
|
29
|
+
* @returns The modified line.
|
|
30
|
+
*/
|
|
31
|
+
export declare function modifyAndNormalizeClassProperties(line: string, genericKindProperties: string[], foundInterfaces: Set<string>): string;
|
|
32
|
+
/**
|
|
33
|
+
* Normalizes lines after processing, including indentation, spacing, and removing unnecessary lines.
|
|
34
|
+
*
|
|
35
|
+
* @param lines The lines of the file content.
|
|
36
|
+
* @param opts The options for processing.
|
|
37
|
+
* @returns The normalized lines.
|
|
38
|
+
*/
|
|
39
|
+
export declare function normalizeIndentationAndSpacing(lines: string[], opts: GenerateOptions): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Removes lines containing `[property: string]: any;` from TypeScript files.
|
|
42
|
+
*
|
|
43
|
+
* @param lines The generated TypeScript lines.
|
|
44
|
+
* @param opts The options for processing.
|
|
45
|
+
* @returns The lines with `[property: string]: any;` removed.
|
|
46
|
+
*/
|
|
47
|
+
export declare function removePropertyStringAny(lines: string[], opts: GenerateOptions): string[];
|
|
48
|
+
/**
|
|
49
|
+
* Applies ESLint and property modifiers to a line of code.
|
|
50
|
+
*
|
|
51
|
+
* @param line - The current line of code.
|
|
52
|
+
* @param genericKindProperties - The list of properties from `GenericKind`.
|
|
53
|
+
* @param foundInterfaces - The set of found interfaces in the file.
|
|
54
|
+
* @returns The modified line.
|
|
55
|
+
*/
|
|
56
|
+
export declare function modifyPropertiesAndAddEslintDirective(line: string, genericKindProperties: string[], foundInterfaces: Set<string>): string;
|
|
57
|
+
/**
|
|
58
|
+
* Adds an ESLint disable comment for `[key: string]: any` if it's not part of `GenericKind`.
|
|
59
|
+
*
|
|
60
|
+
* @param line The current line of code.
|
|
61
|
+
* @param genericKindProperties The list of properties from `GenericKind`.
|
|
62
|
+
* @returns The modified line with the ESLint disable comment.
|
|
63
|
+
*/
|
|
64
|
+
export declare function processEslintDisable(line: string, genericKindProperties: string[]): string;
|
|
65
|
+
/**
|
|
66
|
+
* Applies property modifiers to a line of code.
|
|
67
|
+
*
|
|
68
|
+
* @param line The current line of code.
|
|
69
|
+
* @param genericKindProperties The list of properties from `GenericKind`.
|
|
70
|
+
* @param foundInterfaces The set of found interfaces in the file.
|
|
71
|
+
* @returns The modified line.
|
|
72
|
+
*/
|
|
73
|
+
export declare function addDeclareAndOptionalModifiersToProperties(line: string, genericKindProperties: string[], foundInterfaces: Set<string>): string;
|
|
74
|
+
/**
|
|
75
|
+
* Adds the `declare` keyword to `GenericKind` properties.
|
|
76
|
+
*
|
|
77
|
+
* @param line The current line of code.
|
|
78
|
+
* @param genericKindProperties The list of properties from `GenericKind`.
|
|
79
|
+
* @returns The modified line with the `declare` keyword, if applicable.
|
|
80
|
+
*/
|
|
81
|
+
export declare function addDeclareToGenericKindProperties(line: string, genericKindProperties: string[]): string;
|
|
82
|
+
/**
|
|
83
|
+
* Makes a property optional if its type matches one of the found interfaces and it is not already optional.
|
|
84
|
+
*
|
|
85
|
+
* @param line The current line of code.
|
|
86
|
+
* @param foundInterfaces The set of found interfaces in the file.
|
|
87
|
+
* @returns The modified line with the optional `?` symbol.
|
|
88
|
+
*/
|
|
89
|
+
export declare function makePropertiesOptional(line: string, foundInterfaces: Set<string>): string;
|
|
90
|
+
/**
|
|
91
|
+
* Generates a regular expression to match a property pattern in TypeScript.
|
|
92
|
+
*
|
|
93
|
+
* @param prop The property name to match.
|
|
94
|
+
* @returns A regular expression to match the property pattern.
|
|
95
|
+
*/
|
|
96
|
+
export declare function getPropertyPattern(prop: string): RegExp;
|
|
97
|
+
//# sourceMappingURL=normalization.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalization.d.ts","sourceRoot":"","sources":["../src/normalization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAE9D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAGlE;AAED;;;;;;;GAOG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,MAAM,EAAE,EAC/B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAC3B,MAAM,CAIR;AAED;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,EAAE,CAI/F;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,EAAE,CAKxF;AAED;;;;;;;GAOG;AACH,wBAAgB,qCAAqC,CACnD,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,MAAM,EAAE,EAC/B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAC3B,MAAM,CAIR;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,GAAG,MAAM,CAK1F;AAED;;;;;;;GAOG;AACH,wBAAgB,0CAA0C,CACxD,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,MAAM,EAAE,EAC/B,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAC3B,MAAM,CAKR;AAED;;;;;;GAMG;AACH,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,MAAM,EACZ,qBAAqB,EAAE,MAAM,EAAE,GAC9B,MAAM,CAQR;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAYzF;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAIvD"}
|