kombinate 0.0.0-stage → 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 Mateusz Paduszyński
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # kombinate
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A Kubernetes manifest generator in TypeScript. Define your resources in a `kombination.ts` file, get fully type-checked YAML on stdout.
4
+
5
+ No templating. No `${values}` strings. Just TypeScript:
6
+
7
+ - **Type safety** — your manifests are checked by the real TypeScript compiler before anything is rendered. If your `kombination.ts` doesn't compile, nothing builds.
8
+ - **Plain TypeScript instead of templating** — use variables, loops, functions, and npm packages to compose and reshape resources however you like.
9
+ - **Asset imports** — embed files (configs, secrets, scripts) directly into manifests via `?utf8` / `?base64` imports.
10
+ - **Bring your own typings** — `KubeResource` is intentionally loose, so you can use any external typings package for fully type-safe manifests, e.g. [`kubernetypes`](https://www.npmjs.com/package/kubernetypes).
11
+
12
+ ## Installation
13
+
14
+ Requires Node >= 24.22 and TypeScript `^5.9.3 || ^6.x` (peer dependency).
15
+
16
+ ## Quick start
17
+
18
+ Create a `kombination.ts` in your project:
19
+
20
+ ```ts
21
+ // my-app/kombination.ts
22
+ import { defineKombination } from 'kombinate';
23
+
24
+ const deployment = {
25
+ apiVersion: 'apps/v1',
26
+ kind: 'Deployment',
27
+ metadata: { name: 'my-app' },
28
+ spec: {/* ... */},
29
+ };
30
+
31
+ export default defineKombination({
32
+ resources: [deployment],
33
+ });
34
+ ```
35
+
36
+ Then build:
37
+
38
+ ```bash
39
+ npx kombinate build my-app > manifests.yaml
40
+ # or from inside the directory:
41
+ npx kombinate build > manifests.yaml
42
+
43
+ kubectl apply -f manifests.yaml
44
+ ```
45
+
46
+ Output is a multi-document YAML stream:
47
+
48
+ ```yaml
49
+ ---
50
+ apiVersion: apps/v1
51
+ kind: Deployment
52
+ metadata:
53
+ name: my-app
54
+ ...
55
+ ```
56
+
57
+ ## CLI
58
+
59
+ ```
60
+ kombinate build [dir]
61
+ ```
62
+
63
+ - `dir` defaults to `.` and must contain a `kombination.ts` file.
64
+ - The nearest `tsconfig.json` is discovered and its compiler options are used for type-checking (`skipLibCheck` and `noEmit` are forced). Warnings and errors are reported with full diagnostics; a build with type errors fails.
65
+ - Rendered YAML is written to stdout — redirect it to a file or pipe it straight into `kubectl apply -f -`.
66
+ - Exit codes: `0` success, `1` build error, `2` usage error.
67
+
68
+ ## Library API
69
+
70
+ ### `defineKombination`
71
+
72
+ Factory used in `kombination.ts` as the default export. It brands the object so the CLI can validate it.
73
+
74
+ ```ts
75
+ import { defineKombination } from 'kombinate';
76
+
77
+ export default defineKombination({
78
+ resources: [/* KubeResource[] */],
79
+ });
80
+ ```
81
+
82
+ ### `KubeResource`
83
+
84
+ An intentionally loose type — anything with `apiVersion` and `kind`, plus optional `metadata` (`name`, `namespace`, `labels`, `annotations`). Arbitrary fields (e.g. `spec`) are allowed via an index signature, so any Kubernetes object shape works. Since resources are just plain objects, you are free to compose, reshape, and derive them with regular TypeScript before passing them to `defineKombination`.
85
+
86
+ ## Asset imports
87
+
88
+ Import files as strings using query suffixes — handy for embedding `ConfigMap` / `Secret` data:
89
+
90
+ ```ts
91
+ import config from './app-config.yaml?utf8'; // file content as UTF-8 text
92
+ import cert from './tls.crt?base64'; // file content as base64
93
+ ```
94
+
95
+ For type-checking to know about these modules, enable the `kombinate/types` types in your `tsconfig.json`:
96
+
97
+ ```json
98
+ {
99
+ "compilerOptions": {
100
+ "types": ["kombinate/types"]
101
+ }
102
+ }
103
+ ```
104
+
105
+ (or add `/// <reference types="kombinate/types" />` somewhere in your project).
106
+
107
+ ## License
108
+
109
+ [MIT](./LICENSE)
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from 'node:fs';
3
+ import { stat } from 'node:fs/promises';
4
+ import { join, resolve } from 'node:path';
5
+ import { fileURLToPath, pathToFileURL } from 'node:url';
6
+ import { tsImport } from 'tsx/esm/api';
7
+ import ts from 'typescript';
8
+ import yaml from 'yaml';
9
+ import { isKombination } from '../lib/index.js';
10
+ process.exitCode = await main(process.argv.slice(2));
11
+ async function main(argv) {
12
+ const minNodeVersion = '24.22.0';
13
+ if (!nodeVersionGreaterThan(minNodeVersion)) {
14
+ process.stderr.write(`kombinate[error]: Node.js >= ${minNodeVersion} is required (found ${process.versions.node})\n`);
15
+ return 1;
16
+ }
17
+ const [cmd, ...args] = argv;
18
+ if (cmd !== 'build' || args.length > 1) {
19
+ process.stderr.write(`Usage: kombinate build [dir]\n`);
20
+ return 2;
21
+ }
22
+ const [dir = '.'] = args;
23
+ let resources;
24
+ try {
25
+ resources = await build(process.cwd(), dir);
26
+ }
27
+ catch (err) {
28
+ process.stderr.write(`kombinate[error]: ${errorMessage(err)}\n`);
29
+ return 1;
30
+ }
31
+ for (const resource of resources) {
32
+ process.stdout.write(`---\n${resource}`);
33
+ }
34
+ return 0;
35
+ }
36
+ async function build(cwd, dir) {
37
+ const kombinationDir = resolve(dir);
38
+ const kombinationFile = join(kombinationDir, 'kombination.ts');
39
+ let kombinationExists;
40
+ try {
41
+ kombinationExists = (await stat(kombinationFile)).isFile();
42
+ }
43
+ catch {
44
+ kombinationExists = false;
45
+ }
46
+ if (!kombinationExists) {
47
+ fatal(`unable to find 'kombination.ts' in directory '${kombinationDir}'`);
48
+ }
49
+ const tsconfigFile = ts.findConfigFile(kombinationDir, ts.sys.fileExists);
50
+ if (tsconfigFile === undefined) {
51
+ fatal(`unable to find tsconfig for kombination '${kombinationFile}'`);
52
+ }
53
+ const { config: json, error } = ts.readConfigFile(tsconfigFile, ts.sys.readFile);
54
+ if (error !== undefined) {
55
+ const message = ts.flattenDiagnosticMessageText(error.messageText, '\n');
56
+ fatal(`unable to read tsconfig from '${tsconfigFile}': ${message}`);
57
+ }
58
+ const tsconfigJson = { ...json, include: [], exclude: [], files: [''] };
59
+ const { options, errors } = ts.parseJsonConfigFileContent(tsconfigJson, ts.sys, kombinationDir, undefined, tsconfigFile);
60
+ if (errors.length > 0) {
61
+ const message = errors.map(({ messageText }) => ts.flattenDiagnosticMessageText(messageText, '\n')).join('\n');
62
+ fatal(`unable to parse tsconfig from '${tsconfigFile}': ${message}`);
63
+ }
64
+ const program = ts.createProgram({
65
+ rootNames: [kombinationFile],
66
+ options: {
67
+ ...options,
68
+ skipLibCheck: true,
69
+ noEmit: true,
70
+ },
71
+ });
72
+ const diagnostics = ts.getPreEmitDiagnostics(program);
73
+ if (diagnostics.length > 0) {
74
+ const message = ts.formatDiagnostics(diagnostics, {
75
+ getCanonicalFileName: (file) => file,
76
+ getNewLine: () => ts.sys.newLine,
77
+ getCurrentDirectory: () => cwd,
78
+ });
79
+ fatal(`typecheck failed for kombination '${kombinationFile}':\n${message.trimEnd()}`);
80
+ }
81
+ const { registerHooks } = process.getBuiltinModule('node:module');
82
+ registerHooks(assetsHooksOptions('utf8'));
83
+ registerHooks(assetsHooksOptions('base64'));
84
+ let module;
85
+ try {
86
+ module = await tsImport(kombinationFile, {
87
+ parentURL: pathToFileURL(kombinationFile).toString(),
88
+ tsconfig: tsconfigFile,
89
+ });
90
+ }
91
+ catch (err) {
92
+ fatal(`unable to import kombination '${kombinationFile}'`, importErrorStacktrace(kombinationFile, err));
93
+ }
94
+ if (!isModuleWithDefaultExport(module)) {
95
+ fatal(`kombination '${kombinationFile}' doesn't have default export`);
96
+ }
97
+ if (!isKombination(module.default)) {
98
+ fatal(`default export of kombination '${kombinationFile}' is not Kombination`);
99
+ }
100
+ const resources = [];
101
+ for (const resource of module.default.resources) {
102
+ try {
103
+ resources.push(yaml.stringify(resource, { logLevel: 'silent', sortMapEntries: true }));
104
+ }
105
+ catch (err) {
106
+ const name = `${resource.apiVersion}/${resource.kind}/${resource.metadata?.name ?? '<anonymous>'}`;
107
+ fatal(`unable to render resource '${name}'`, err);
108
+ }
109
+ }
110
+ return resources;
111
+ }
112
+ function nodeVersionGreaterThan(minVersion) {
113
+ const current = process.versions.node.split('.').map(Number);
114
+ const min = minVersion.split('.').map(Number);
115
+ for (let i = 0; i < 3; i++) {
116
+ if ((current[i] ?? 0) !== (min[i] ?? 0)) {
117
+ return (current[i] ?? 0) > (min[i] ?? 0);
118
+ }
119
+ }
120
+ return true;
121
+ }
122
+ function assetsHooksOptions(encoding) {
123
+ return {
124
+ resolve(specifier, context, nextResolve) {
125
+ if (!specifier.endsWith(`?${encoding}`)) {
126
+ return nextResolve(specifier, context);
127
+ }
128
+ const resolved = nextResolve(specifier.slice(0, -encoding.length), context);
129
+ return { ...resolved, url: `${resolved.url}?${encoding}` };
130
+ },
131
+ load(rawUrl, context, nextLoad) {
132
+ const url = new URL(rawUrl);
133
+ if (!url.searchParams.has(encoding)) {
134
+ return nextLoad(rawUrl, context);
135
+ }
136
+ url.searchParams.delete(encoding);
137
+ url.searchParams.delete('tsx-namespace');
138
+ const file = fileURLToPath(url.href);
139
+ let content;
140
+ try {
141
+ content = readFileSync(file, encoding);
142
+ }
143
+ catch (err) {
144
+ fatal(`unable to read asset '${file}'`, err);
145
+ }
146
+ return {
147
+ format: 'module',
148
+ source: `export default ${JSON.stringify(content)};`,
149
+ shortCircuit: true,
150
+ };
151
+ },
152
+ };
153
+ }
154
+ function isModuleWithDefaultExport(x) {
155
+ return x !== null && typeof x === 'object' && 'default' in x;
156
+ }
157
+ function fatal(message, cause) {
158
+ throw new Error(message, { cause });
159
+ }
160
+ function importErrorStacktrace(kombinationFile, err) {
161
+ if (err instanceof Error) {
162
+ if (err.stack !== undefined) {
163
+ const lines = err.stack.split('\n');
164
+ const stackStart = lines.findIndex((line) => line.indexOf(kombinationFile) !== -1);
165
+ const stack = lines.slice(0, stackStart + 1).join('\n');
166
+ if (err.cause !== undefined) {
167
+ return `${stack}\n[caused by] ${importErrorStacktrace(kombinationFile, err.cause)}`;
168
+ }
169
+ return stack;
170
+ }
171
+ return errorMessage(err);
172
+ }
173
+ return '';
174
+ }
175
+ function errorMessage(err) {
176
+ if (err instanceof Error) {
177
+ return err.cause ? `${err.message}: ${errorMessage(err.cause)}` : err.message;
178
+ }
179
+ try {
180
+ return String(err);
181
+ }
182
+ catch {
183
+ return '<unknown error>';
184
+ }
185
+ }
@@ -0,0 +1 @@
1
+ export * from './kombination.js';
@@ -0,0 +1 @@
1
+ export * from './kombination.js';
@@ -0,0 +1,20 @@
1
+ export type Kombination = {
2
+ readonly [KOMBINATION]: true;
3
+ readonly resources: readonly KubeResource[];
4
+ };
5
+ export declare function defineKombination(spec: {
6
+ resources: KubeResource[];
7
+ }): Kombination;
8
+ export type KubeResource = {
9
+ apiVersion: string;
10
+ kind: string;
11
+ metadata?: {
12
+ name?: string;
13
+ namespace?: string;
14
+ labels?: Record<string, string>;
15
+ annotations?: Record<string, string>;
16
+ };
17
+ [x: string]: unknown;
18
+ };
19
+ declare const KOMBINATION: unique symbol;
20
+ export {};
@@ -0,0 +1,7 @@
1
+ export function defineKombination(spec) {
2
+ return { [KOMBINATION]: true, resources: spec.resources };
3
+ }
4
+ export function isKombination(x) {
5
+ return x !== null && typeof x === 'object' && KOMBINATION in x && x[KOMBINATION] === true;
6
+ }
7
+ const KOMBINATION = Symbol.for('KOMBINATION');
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "kombinate",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "TypeScript-based Kubernetes manifest generator",
6
+ "author": "Mateusz Paduszyński <paduszym@gmail.com>",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "kombinate",
10
+ "kubernetes",
11
+ "generator",
12
+ "typescript"
13
+ ],
14
+ "homepage": "https://github.com/paduszym/kombinate/tree/main/packages/kombinate",
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/paduszym/kombinate.git",
18
+ "directory": "packages/kombinate"
19
+ },
20
+ "bugs": {
21
+ "url": "https://github.com/paduszym/kombinate/issues"
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "types.d.ts"
26
+ ],
27
+ "bin": {
28
+ "kombinate": "./dist/bin/kombinate.js"
29
+ },
30
+ "engines": {
31
+ "node": ">=24.22"
32
+ },
33
+ "dependencies": {
34
+ "tslib": "2.9.1",
35
+ "tsx": "4.23.15",
36
+ "yaml": "2.9.1"
37
+ },
38
+ "peerDependencies": {
39
+ "typescript": "^5.9.3 || ^6.x"
40
+ },
41
+ "exports": {
42
+ ".": {
43
+ "types": "./dist/lib/index.d.ts",
44
+ "import": "./dist/lib/index.js"
45
+ },
46
+ "./types": {
47
+ "types": "./types.d.ts"
48
+ }
49
+ }
50
+ }
package/types.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /*
2
+ * SPDX-License-Identifier: MIT
3
+ * Copyright (c) 2026 Mateusz Paduszyński
4
+ */
5
+ declare module '*?utf8' {
6
+ const content: string;
7
+ export default content;
8
+ }
9
+
10
+ declare module '*?base64' {
11
+ const content: string;
12
+ export default content;
13
+ }