@mizchi/k1c 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 +21 -0
- package/README.md +150 -0
- package/dist/canary/dispatcher-template.d.ts +17 -0
- package/dist/canary/dispatcher-template.js +42 -0
- package/dist/canary/effects-cloudflare.d.ts +9 -0
- package/dist/canary/effects-cloudflare.js +66 -0
- package/dist/canary/rollout-command.d.ts +15 -0
- package/dist/canary/rollout-command.js +92 -0
- package/dist/canary/runtime.d.ts +59 -0
- package/dist/canary/runtime.js +138 -0
- package/dist/canary/state-machine.d.ts +72 -0
- package/dist/canary/state-machine.js +161 -0
- package/dist/cli/args.d.ts +51 -0
- package/dist/cli/args.js +239 -0
- package/dist/cli/canary-integration.d.ts +11 -0
- package/dist/cli/canary-integration.js +101 -0
- package/dist/cli/format.d.ts +4 -0
- package/dist/cli/format.js +44 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +158 -0
- package/dist/cli/run.d.ts +16 -0
- package/dist/cli/run.js +246 -0
- package/dist/manifest/lower.d.ts +22 -0
- package/dist/manifest/lower.js +913 -0
- package/dist/manifest/parse.d.ts +22 -0
- package/dist/manifest/parse.js +106 -0
- package/dist/manifest/schemas.d.ts +10359 -0
- package/dist/manifest/schemas.js +309 -0
- package/dist/manifest/types.d.ts +246 -0
- package/dist/manifest/types.js +12 -0
- package/dist/providers/configmap.d.ts +8 -0
- package/dist/providers/configmap.js +29 -0
- package/dist/providers/custom-domain.d.ts +11 -0
- package/dist/providers/custom-domain.js +120 -0
- package/dist/providers/d1-database.d.ts +9 -0
- package/dist/providers/d1-database.js +106 -0
- package/dist/providers/dispatch-namespace.d.ts +8 -0
- package/dist/providers/dispatch-namespace.js +100 -0
- package/dist/providers/dns-record.d.ts +14 -0
- package/dist/providers/dns-record.js +136 -0
- package/dist/providers/errors.d.ts +8 -0
- package/dist/providers/errors.js +64 -0
- package/dist/providers/hyperdrive.d.ts +27 -0
- package/dist/providers/hyperdrive.js +168 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.js +36 -0
- package/dist/providers/kv-namespace.d.ts +8 -0
- package/dist/providers/kv-namespace.js +90 -0
- package/dist/providers/logpush-job.d.ts +17 -0
- package/dist/providers/logpush-job.js +181 -0
- package/dist/providers/queue.d.ts +10 -0
- package/dist/providers/queue.js +124 -0
- package/dist/providers/r2-bucket.d.ts +11 -0
- package/dist/providers/r2-bucket.js +98 -0
- package/dist/providers/registry.d.ts +9 -0
- package/dist/providers/registry.js +22 -0
- package/dist/providers/secret.d.ts +8 -0
- package/dist/providers/secret.js +30 -0
- package/dist/providers/types.d.ts +69 -0
- package/dist/providers/types.js +12 -0
- package/dist/providers/vectorize.d.ts +11 -0
- package/dist/providers/vectorize.js +110 -0
- package/dist/providers/worker.d.ts +106 -0
- package/dist/providers/worker.js +430 -0
- package/dist/providers/workflow.d.ts +10 -0
- package/dist/providers/workflow.js +103 -0
- package/dist/reconciler/apply.d.ts +10 -0
- package/dist/reconciler/apply.js +114 -0
- package/dist/reconciler/fake-provider.d.ts +48 -0
- package/dist/reconciler/fake-provider.js +83 -0
- package/dist/reconciler/plan.d.ts +6 -0
- package/dist/reconciler/plan.js +124 -0
- package/dist/reconciler/topo.d.ts +10 -0
- package/dist/reconciler/topo.js +53 -0
- package/dist/reconciler/types.d.ts +54 -0
- package/dist/reconciler/types.js +8 -0
- package/package.json +61 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { K1cResource } from './types.ts';
|
|
2
|
+
export declare class ManifestParseError extends Error {
|
|
3
|
+
constructor(message: string, options?: {
|
|
4
|
+
cause?: unknown;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
export interface ParseRef {
|
|
8
|
+
readonly apiVersion: string;
|
|
9
|
+
readonly kind: string;
|
|
10
|
+
readonly namespace: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}
|
|
13
|
+
export interface ParseWarning {
|
|
14
|
+
readonly ref: ParseRef | null;
|
|
15
|
+
readonly message: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ParseResult {
|
|
18
|
+
readonly resources: ReadonlyArray<K1cResource>;
|
|
19
|
+
readonly warnings: ReadonlyArray<ParseWarning>;
|
|
20
|
+
}
|
|
21
|
+
export declare function parseManifest(text: string): ParseResult;
|
|
22
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { parseAllDocuments } from 'yaml';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { k1cResourceSchema } from "./schemas.js";
|
|
4
|
+
export class ManifestParseError extends Error {
|
|
5
|
+
constructor(message, options) {
|
|
6
|
+
super(message, options);
|
|
7
|
+
this.name = 'ManifestParseError';
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
const OUT_OF_SCOPE = new Map([
|
|
11
|
+
['Pod', 'Pod is not supported. Wrap workloads in a Deployment instead.'],
|
|
12
|
+
['DaemonSet', 'DaemonSet is not supported on Cloudflare; the edge is implicitly global.'],
|
|
13
|
+
['NetworkPolicy', 'NetworkPolicy is not supported. Use Service Bindings or WAF.'],
|
|
14
|
+
['Endpoints', 'Endpoints is an internal Service detail and not user-applied.'],
|
|
15
|
+
['EndpointSlice', 'EndpointSlice is an internal Service detail and not user-applied.'],
|
|
16
|
+
]);
|
|
17
|
+
const NOOP_WITH_WARNING = new Map([
|
|
18
|
+
['HorizontalPodAutoscaler', 'HPA is no-op on Cloudflare; Workers auto-scale automatically.'],
|
|
19
|
+
['PodDisruptionBudget', 'PodDisruptionBudget has no effect on Cloudflare Workers.'],
|
|
20
|
+
['LimitRange', 'LimitRange has no effect; account-level limits apply instead.'],
|
|
21
|
+
['ResourceQuota', 'ResourceQuota has no effect; account-level limits apply instead.'],
|
|
22
|
+
]);
|
|
23
|
+
export function parseManifest(text) {
|
|
24
|
+
const docs = parseAllDocuments(text);
|
|
25
|
+
const resources = [];
|
|
26
|
+
const warnings = [];
|
|
27
|
+
for (const doc of docs) {
|
|
28
|
+
if (doc.errors.length > 0) {
|
|
29
|
+
const first = doc.errors[0];
|
|
30
|
+
throw new ManifestParseError(`YAML parse error: ${first.message}`, { cause: first });
|
|
31
|
+
}
|
|
32
|
+
const data = doc.toJS();
|
|
33
|
+
if (data == null)
|
|
34
|
+
continue;
|
|
35
|
+
if (typeof data !== 'object' || Array.isArray(data)) {
|
|
36
|
+
throw new ManifestParseError(`expected mapping at document root, got ${Array.isArray(data) ? 'array' : typeof data}`);
|
|
37
|
+
}
|
|
38
|
+
const obj = data;
|
|
39
|
+
const kind = obj['kind'];
|
|
40
|
+
if (typeof kind !== 'string' || kind.length === 0) {
|
|
41
|
+
throw new ManifestParseError('manifest is missing required field "kind"');
|
|
42
|
+
}
|
|
43
|
+
const outOfScope = OUT_OF_SCOPE.get(kind);
|
|
44
|
+
if (outOfScope !== undefined) {
|
|
45
|
+
throw new ManifestParseError(`${kind} is not supported: ${outOfScope}`);
|
|
46
|
+
}
|
|
47
|
+
const noopReason = NOOP_WITH_WARNING.get(kind);
|
|
48
|
+
if (noopReason !== undefined) {
|
|
49
|
+
warnings.push({ ref: extractRef(obj), message: noopReason });
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
const parsed = parseAndValidate(obj, kind);
|
|
53
|
+
const withDefaults = applyDefaults(parsed);
|
|
54
|
+
resources.push(withDefaults);
|
|
55
|
+
}
|
|
56
|
+
return { resources, warnings };
|
|
57
|
+
}
|
|
58
|
+
function parseAndValidate(obj, kind) {
|
|
59
|
+
const result = k1cResourceSchema.safeParse(obj);
|
|
60
|
+
if (result.success)
|
|
61
|
+
return result.data;
|
|
62
|
+
const issue = result.error.issues[0];
|
|
63
|
+
if (issue?.code === 'invalid_union_discriminator') {
|
|
64
|
+
const apiVersion = obj['apiVersion'];
|
|
65
|
+
throw new ManifestParseError(`unknown kind: ${kind} (apiVersion=${typeof apiVersion === 'string' ? apiVersion : '?'})`, { cause: result.error });
|
|
66
|
+
}
|
|
67
|
+
throw new ManifestParseError(formatZodError(result.error, kind), { cause: result.error });
|
|
68
|
+
}
|
|
69
|
+
function applyDefaults(resource) {
|
|
70
|
+
if (resource.metadata.namespace)
|
|
71
|
+
return resource;
|
|
72
|
+
return {
|
|
73
|
+
...resource,
|
|
74
|
+
metadata: { ...resource.metadata, namespace: 'default' },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function extractRef(obj) {
|
|
78
|
+
const apiVersion = obj['apiVersion'];
|
|
79
|
+
const kind = obj['kind'];
|
|
80
|
+
const metadata = obj['metadata'];
|
|
81
|
+
if (typeof apiVersion !== 'string')
|
|
82
|
+
return null;
|
|
83
|
+
if (typeof kind !== 'string')
|
|
84
|
+
return null;
|
|
85
|
+
if (typeof metadata !== 'object' || metadata === null)
|
|
86
|
+
return null;
|
|
87
|
+
const meta = metadata;
|
|
88
|
+
const name = meta['name'];
|
|
89
|
+
const namespace = meta['namespace'];
|
|
90
|
+
if (typeof name !== 'string')
|
|
91
|
+
return null;
|
|
92
|
+
return {
|
|
93
|
+
apiVersion,
|
|
94
|
+
kind,
|
|
95
|
+
namespace: typeof namespace === 'string' ? namespace : 'default',
|
|
96
|
+
name,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function formatZodError(error, kind) {
|
|
100
|
+
const lines = error.issues.map((issue) => {
|
|
101
|
+
const path = issue.path.length === 0 ? '<root>' : issue.path.join('.');
|
|
102
|
+
return ` at ${path}: ${issue.message}`;
|
|
103
|
+
});
|
|
104
|
+
return `${kind} validation failed:\n${lines.join('\n')}`;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=parse.js.map
|