kubernetes-fluent-client 3.5.6 → 3.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.
Files changed (58) hide show
  1. package/dist/cli.js +11 -16
  2. package/dist/fetch.js +5 -8
  3. package/dist/fluent/index.d.ts +3 -2
  4. package/dist/fluent/index.d.ts.map +1 -1
  5. package/dist/fluent/index.js +27 -29
  6. package/dist/fluent/shared-types.d.ts +49 -0
  7. package/dist/fluent/shared-types.d.ts.map +1 -0
  8. package/dist/fluent/shared-types.js +23 -0
  9. package/dist/fluent/types.d.ts +3 -38
  10. package/dist/fluent/types.d.ts.map +1 -1
  11. package/dist/fluent/types.js +1 -14
  12. package/dist/fluent/utils.d.ts +2 -2
  13. package/dist/fluent/utils.d.ts.map +1 -1
  14. package/dist/fluent/utils.js +25 -35
  15. package/dist/fluent/watch.d.ts +2 -9
  16. package/dist/fluent/watch.d.ts.map +1 -1
  17. package/dist/fluent/watch.js +23 -43
  18. package/dist/generate.d.ts +2 -2
  19. package/dist/generate.d.ts.map +1 -1
  20. package/dist/generate.js +22 -65
  21. package/dist/helpers.js +5 -10
  22. package/dist/index.d.ts +10 -10
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +13 -60
  25. package/dist/kinds.d.ts +1 -1
  26. package/dist/kinds.d.ts.map +1 -1
  27. package/dist/kinds.js +2 -7
  28. package/dist/normalization.d.ts +97 -0
  29. package/dist/normalization.d.ts.map +1 -0
  30. package/dist/normalization.js +152 -0
  31. package/dist/patch.js +1 -2
  32. package/dist/postProcessing.d.ts +8 -129
  33. package/dist/postProcessing.d.ts.map +1 -1
  34. package/dist/postProcessing.js +29 -280
  35. package/dist/types.d.ts +3 -2
  36. package/dist/types.d.ts.map +1 -1
  37. package/dist/types.js +1 -5
  38. package/dist/upstream.d.ts +1 -1
  39. package/dist/upstream.d.ts.map +1 -1
  40. package/dist/upstream.js +2 -53
  41. package/package.json +15 -14
  42. package/src/cli.ts +6 -6
  43. package/src/fluent/index.ts +19 -18
  44. package/src/fluent/shared-types.ts +55 -0
  45. package/src/fluent/types.ts +4 -55
  46. package/src/fluent/utils.ts +5 -5
  47. package/src/fluent/watch.ts +11 -24
  48. package/src/generate.ts +4 -4
  49. package/src/index.ts +10 -10
  50. package/src/kinds.ts +1 -1
  51. package/src/normalization.ts +181 -0
  52. package/src/postProcessing.ts +27 -244
  53. package/src/types.ts +3 -4
  54. package/src/upstream.ts +1 -1
  55. package/dist/fileSystem.d.ts +0 -11
  56. package/dist/fileSystem.d.ts.map +0 -1
  57. package/dist/fileSystem.js +0 -52
  58. package/src/fileSystem.ts +0 -25
@@ -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
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.Watcher = exports.WatchEvent = void 0;
6
- const crypto_1 = require("crypto");
7
- const events_1 = require("events");
8
- const undici_1 = require("undici");
9
- const fetch_1 = require("../fetch");
10
- const types_1 = require("./types");
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.js";
6
+ import { k8sCfg, pathBuilder, getHeaders } from "./utils.js";
7
+ import { Readable } from "stream";
8
+ import { WatchPhase, FetchMethods, } from "./shared-types.js";
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 || (exports.WatchEvent = 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 events_1.EventEmitter();
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 (0, utils_1.k8sCfg)("GET");
150
+ const { opts, serverUrl } = await k8sCfg(FetchMethods.GET);
170
151
  const k8sUrl = serverUrl instanceof URL ? serverUrl.toString() : serverUrl;
171
- const url = (0, utils_1.pathBuilder)(k8sUrl, this.#model, this.#filters, true);
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 (0, fetch_1.fetch)(serverUrl, opts);
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, types_1.WatchPhase.Added);
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, types_1.WatchPhase.Modified);
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, types_1.WatchPhase.Deleted);
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 types_1.WatchPhase.Added:
268
- case types_1.WatchPhase.Modified:
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 types_1.WatchPhase.Deleted:
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 === types_1.WatchPhase.Error && payload.code === 410) {
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 (0, undici_1.fetch)(serverUrl, {
321
- headers: await (0, utils_1.getHeaders)(),
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 = stream_1.Readable.from(body);
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;
@@ -1,6 +1,6 @@
1
1
  import { InputData, TargetLanguage } from "quicktype-core";
2
- import { CustomResourceDefinition } from "./upstream";
3
- import { LogFn } from "./types";
2
+ import { CustomResourceDefinition } from "./upstream.js";
3
+ import { LogFn } from "./types.js";
4
4
  export interface GenerateOptions {
5
5
  source: string;
6
6
  directory?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAMA,OAAO,EAEL,SAAS,EAET,cAAc,EAEf,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC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GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAW3E;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EAAE,EACjB,QAAQ,EAAE,MAAM,GAAG,cAAc,GAChC,IAAI,CAON;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,wBAAwB,EAAE,CAAC,CA0B/F;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAMtD;AAED;;;;;GAKG;AACH,wBAAsB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAC5D;IACE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,wBAAwB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB,EAAE,CACJ,CA8BA"}
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
- 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 () {
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.js";
8
+ import { K8s } from "./fluent/index.js";
9
+ import { CustomResourceDefinition } from "./upstream.js";
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 quicktype_core_1.JSONSchemaInput(new quicktype_core_1.FetchingJSONSchemaStore());
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 quicktype_core_1.InputData();
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 (0, quicktype_core_1.quicktype)({
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 (0, client_node_1.loadAllYaml)(content);
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 (0, fetch_1.fetch)(url.href);
109
+ const { ok, data } = await fetch(url.href);
153
110
  if (ok) {
154
- return (0, client_node_1.loadAllYaml)(data);
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 (0, fluent_1.K8s)(upstream_1.CustomResourceDefinition).Get(opts.source)];
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
- Object.defineProperty(exports, "__esModule", { value: true });
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 client_node_1.KubeConfig();
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.d.ts CHANGED
@@ -1,14 +1,14 @@
1
- import "./patch";
2
- import * as kind from "./upstream";
1
+ import "./patch.js";
2
+ import * as kind from "./upstream.js";
3
3
  /** kind is a collection of K8s types to be used within a K8s call: `K8s(kind.Secret).Apply({})`. */
4
4
  export { kind };
5
- export { fetch } from "./fetch";
5
+ export { fetch } from "./fetch.js";
6
6
  export { StatusCodes as fetchStatus } from "http-status-codes";
7
- export { WatchCfg, WatchEvent } from "./fluent/watch";
8
- export { K8s } from "./fluent";
9
- export { RegisterKind, modelToGroupVersionKind } from "./kinds";
10
- export { GenericKind } from "./types";
11
- export * from "./types";
12
- export * as models from "@kubernetes/client-node/dist/gen/models/all";
13
- export { fromEnv, waitForCluster } from "./helpers";
7
+ export { WatchCfg, WatchEvent } from "./fluent/watch.js";
8
+ export { K8s } from "./fluent/index.js";
9
+ export { RegisterKind, modelToGroupVersionKind } from "./kinds.js";
10
+ export { GenericKind } from "./types.js";
11
+ export * from "./types.js";
12
+ export * as models from "@kubernetes/client-node/dist/gen/models/all.js";
13
+ export { fromEnv, waitForCluster } from "./helpers.js";
14
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,SAAS,CAAC;AAGjB,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGtD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAG/B,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAGhE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,cAAc,SAAS,CAAC;AAGxB,OAAO,KAAK,MAAM,MAAM,6CAA6C,CAAC;AAEtE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,YAAY,CAAC;AAGpB,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AAEtC,oGAAoG;AACpG,OAAO,EAAE,IAAI,EAAE,CAAC;AAGhB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,EAAE,WAAW,IAAI,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAG/D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAGzD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAGxC,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,MAAM,MAAM,gDAAgD,CAAC;AAEzE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
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
- 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 () {
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.js";
43
4
  // Export kinds as a single object
44
- const kind = __importStar(require("./upstream"));
45
- exports.kind = kind;
5
+ import * as kind from "./upstream.js";
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
- var fetch_1 = require("./fetch");
48
- Object.defineProperty(exports, "fetch", { enumerable: true, get: function () { return fetch_1.fetch; } });
9
+ export { fetch } from "./fetch.js";
49
10
  // Export the HTTP status codes
50
- var http_status_codes_1 = require("http-status-codes");
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
- var watch_1 = require("./fluent/watch");
54
- Object.defineProperty(exports, "WatchEvent", { enumerable: true, get: function () { return watch_1.WatchEvent; } });
13
+ export { WatchEvent } from "./fluent/watch.js";
55
14
  // Export the fluent API entrypoint
56
- var fluent_1 = require("./fluent");
57
- Object.defineProperty(exports, "K8s", { enumerable: true, get: function () { return fluent_1.K8s; } });
15
+ export { K8s } from "./fluent/index.js";
58
16
  // Export helpers for working with K8s types
59
- var kinds_1 = require("./kinds");
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.js";
62
18
  // Export the GenericKind interface for CRD registration
63
- var types_1 = require("./types");
64
- Object.defineProperty(exports, "GenericKind", { enumerable: true, get: function () { return types_1.GenericKind; } });
65
- __exportStar(require("./types"), exports);
19
+ export { GenericKind } from "./types.js";
20
+ export * from "./types.js";
66
21
  // Export the upstream raw models
67
- exports.models = __importStar(require("@kubernetes/client-node/dist/gen/models/all"));
68
- var helpers_1 = require("./helpers");
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.js";
23
+ export { fromEnv, waitForCluster } from "./helpers.js";
package/dist/kinds.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { GenericClass, GroupVersionKind } from "./types";
1
+ import { GenericClass, GroupVersionKind } from "./types.js";
2
2
  /**
3
3
  * Converts a model name to a GroupVersionKind
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAukBzD;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAErE;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,YAAY,EAAE,kBAAkB,gBAAgB,SAUnF,CAAC"}
1
+ {"version":3,"file":"kinds.d.ts","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAukB5D;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAErE;AAED;;;;;GAKG;AACH,eAAO,MAAM,YAAY,GAAI,OAAO,YAAY,EAAE,kBAAkB,gBAAgB,SAUnF,CAAC"}
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.js";
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