@truefoundry/tfy-infra-engine 0.1.3 → 0.1.4
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/README.md +18 -12
- package/dist/index.d.mts +29 -31
- package/dist/index.d.ts +29 -31
- package/dist/index.js +38 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -45
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
var EngineErrorCode = /* @__PURE__ */ ((EngineErrorCode2) => {
|
|
3
3
|
EngineErrorCode2["TEMPLATE_NOT_FOUND"] = "TEMPLATE_NOT_FOUND";
|
|
4
4
|
EngineErrorCode2["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
5
|
-
EngineErrorCode2["GITHUB_NOT_FOUND"] = "GITHUB_NOT_FOUND";
|
|
6
|
-
EngineErrorCode2["GITHUB_RATE_LIMITED"] = "GITHUB_RATE_LIMITED";
|
|
7
5
|
EngineErrorCode2["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
|
|
8
6
|
EngineErrorCode2["HTTPS_AUTH_FAILED"] = "HTTPS_AUTH_FAILED";
|
|
9
7
|
EngineErrorCode2["SCHEMA_INVALID"] = "SCHEMA_INVALID";
|
|
10
8
|
EngineErrorCode2["INPUT_VALIDATION_FAILED"] = "INPUT_VALIDATION_FAILED";
|
|
11
|
-
EngineErrorCode2["
|
|
12
|
-
EngineErrorCode2["
|
|
9
|
+
EngineErrorCode2["BUNDLE_NOT_FOUND"] = "BUNDLE_NOT_FOUND";
|
|
10
|
+
EngineErrorCode2["BUNDLE_INVALID"] = "BUNDLE_INVALID";
|
|
13
11
|
EngineErrorCode2["TEMPLATE_SYNTAX_ERROR"] = "TEMPLATE_SYNTAX_ERROR";
|
|
14
12
|
EngineErrorCode2["TOFU_NOT_FOUND"] = "TOFU_NOT_FOUND";
|
|
15
13
|
EngineErrorCode2["TOFU_FMT_FAILED"] = "TOFU_FMT_FAILED";
|
|
@@ -54,12 +52,12 @@ var EngineError = class _EngineError extends Error {
|
|
|
54
52
|
// src/schema/validator.ts
|
|
55
53
|
import Ajv from "ajv";
|
|
56
54
|
|
|
57
|
-
// src/schema/
|
|
58
|
-
var
|
|
55
|
+
// src/schema/bundle-schema.ts
|
|
56
|
+
var bundleSchema = {
|
|
59
57
|
$schema: "http://json-schema.org/draft-07/schema#",
|
|
60
58
|
type: "object",
|
|
61
59
|
properties: {
|
|
62
|
-
|
|
60
|
+
metadata: {
|
|
63
61
|
type: "object",
|
|
64
62
|
properties: {
|
|
65
63
|
name: { type: "string", minLength: 1 },
|
|
@@ -69,7 +67,7 @@ var templateJsonSchema = {
|
|
|
69
67
|
required: ["name", "version"],
|
|
70
68
|
additionalProperties: false
|
|
71
69
|
},
|
|
72
|
-
|
|
70
|
+
jsonSchema: {
|
|
73
71
|
type: "object",
|
|
74
72
|
description: "JSON Schema Draft-07 defining template inputs",
|
|
75
73
|
properties: {
|
|
@@ -80,7 +78,7 @@ var templateJsonSchema = {
|
|
|
80
78
|
required: ["type", "properties"]
|
|
81
79
|
}
|
|
82
80
|
},
|
|
83
|
-
required: ["
|
|
81
|
+
required: ["metadata", "jsonSchema"]
|
|
84
82
|
};
|
|
85
83
|
|
|
86
84
|
// src/schema/validator.ts
|
|
@@ -89,54 +87,51 @@ var ajv = new Ajv({
|
|
|
89
87
|
strict: false,
|
|
90
88
|
validateSchema: false
|
|
91
89
|
});
|
|
92
|
-
var validate = ajv.compile(
|
|
93
|
-
function
|
|
90
|
+
var validate = ajv.compile(bundleSchema);
|
|
91
|
+
function validateBundle(data) {
|
|
94
92
|
if (!data || typeof data !== "object" || Array.isArray(data)) {
|
|
95
|
-
throw new EngineError(
|
|
96
|
-
"template.json must be a JSON object",
|
|
97
|
-
"TEMPLATE_JSON_INVALID" /* TEMPLATE_JSON_INVALID */
|
|
98
|
-
);
|
|
93
|
+
throw new EngineError("bundle must be a JSON object", "BUNDLE_INVALID" /* BUNDLE_INVALID */);
|
|
99
94
|
}
|
|
100
95
|
const valid = validate(data);
|
|
101
96
|
if (!valid) {
|
|
102
97
|
const message = formatAjvErrors(validate.errors ?? []);
|
|
103
|
-
throw new EngineError(message, "
|
|
98
|
+
throw new EngineError(message, "BUNDLE_INVALID" /* BUNDLE_INVALID */);
|
|
104
99
|
}
|
|
105
100
|
const record = data;
|
|
106
|
-
const
|
|
101
|
+
const metadataBlock = record["metadata"];
|
|
107
102
|
const metadata = {
|
|
108
|
-
name:
|
|
109
|
-
version:
|
|
110
|
-
...
|
|
103
|
+
name: metadataBlock["name"],
|
|
104
|
+
version: metadataBlock["version"],
|
|
105
|
+
...metadataBlock["description"] !== void 0 ? { description: metadataBlock["description"] } : {}
|
|
111
106
|
};
|
|
112
|
-
const jsonSchema = record["
|
|
107
|
+
const jsonSchema = record["jsonSchema"];
|
|
113
108
|
return { metadata, jsonSchema };
|
|
114
109
|
}
|
|
115
110
|
function formatAjvErrors(errors) {
|
|
116
111
|
const first = errors[0];
|
|
117
112
|
if (!first) {
|
|
118
|
-
return "
|
|
113
|
+
return "bundle validation failed";
|
|
119
114
|
}
|
|
120
115
|
const path = first.instancePath || "";
|
|
121
116
|
if (first.keyword === "required") {
|
|
122
117
|
const prop = first.params["missingProperty"];
|
|
123
|
-
return `
|
|
118
|
+
return `bundle must have a "${prop}" key`;
|
|
124
119
|
}
|
|
125
120
|
if (first.keyword === "type") {
|
|
126
121
|
const expected = first.params["type"];
|
|
127
|
-
return `
|
|
122
|
+
return `bundle${path ? ` "${dotPath(path)}"` : ""} must be ${expected}`;
|
|
128
123
|
}
|
|
129
|
-
if (first.keyword === "pattern" && path === "/
|
|
130
|
-
return `
|
|
124
|
+
if (first.keyword === "pattern" && path === "/metadata/version") {
|
|
125
|
+
return `bundle "metadata.version" must be semver format (x.y.z)`;
|
|
131
126
|
}
|
|
132
|
-
if (first.keyword === "minLength" && path === "/
|
|
133
|
-
return `
|
|
127
|
+
if (first.keyword === "minLength" && path === "/metadata/name") {
|
|
128
|
+
return `bundle "metadata.name" must be a non-empty string`;
|
|
134
129
|
}
|
|
135
130
|
if (first.keyword === "const") {
|
|
136
131
|
const expected = first.params["allowedValue"];
|
|
137
|
-
return `
|
|
132
|
+
return `bundle "${dotPath(path)}" must be ${JSON.stringify(expected)}`;
|
|
138
133
|
}
|
|
139
|
-
return `
|
|
134
|
+
return `bundle validation failed at ${path || "/"}: ${first.message ?? "unknown error"}`;
|
|
140
135
|
}
|
|
141
136
|
function dotPath(jsonPointer) {
|
|
142
137
|
return jsonPointer.replace(/^\//, "").replace(/\//g, ".");
|
|
@@ -654,7 +649,7 @@ function computeAggregateHash(files) {
|
|
|
654
649
|
}
|
|
655
650
|
|
|
656
651
|
// src/render/manifest.ts
|
|
657
|
-
var ENGINE_VERSION = "0.1.
|
|
652
|
+
var ENGINE_VERSION = "0.1.4";
|
|
658
653
|
function generateManifest(opts) {
|
|
659
654
|
const { files, template, inputs, formatted, intentId, platformPrefix = "tfy_" } = opts;
|
|
660
655
|
const manifestFiles = [];
|
|
@@ -959,8 +954,11 @@ var HclEngineImpl = class {
|
|
|
959
954
|
/**
|
|
960
955
|
* Upgrade: Update an existing cluster to new templates.
|
|
961
956
|
*
|
|
962
|
-
* Pipeline: validate envelope → drift detection (FR-028) →
|
|
963
|
-
*
|
|
957
|
+
* Pipeline: validate envelope → drift detection (FR-028) → validate inputs →
|
|
958
|
+
* render → format → hash + manifest.
|
|
959
|
+
*
|
|
960
|
+
* The engine always renders new files regardless of source mismatch.
|
|
961
|
+
* Callers (CLI/Server) enforce blocking policy via `sourceBlocked` flag (FR-029).
|
|
964
962
|
*/
|
|
965
963
|
async upgrade(envelope, currentFiles, previousManifest) {
|
|
966
964
|
const validatedEnvelope = this.validateEnvelopeOrThrow(envelope);
|
|
@@ -969,14 +967,6 @@ var HclEngineImpl = class {
|
|
|
969
967
|
const incomingSource = validatedEnvelope.template.source;
|
|
970
968
|
const driftReport = buildDriftReport(currentFiles, previousManifest, prefix, incomingSource);
|
|
971
969
|
const sourceBlocked = driftReport.summary.sourceMismatches > 0;
|
|
972
|
-
if (sourceBlocked) {
|
|
973
|
-
return {
|
|
974
|
-
files: currentFiles,
|
|
975
|
-
manifest: previousManifest,
|
|
976
|
-
driftReport,
|
|
977
|
-
sourceBlocked: true
|
|
978
|
-
};
|
|
979
|
-
}
|
|
980
970
|
const { renderedFiles, template, formatted, inputsWithDefaults } = await this.renderPipeline(
|
|
981
971
|
validatedEnvelope,
|
|
982
972
|
options
|
|
@@ -989,7 +979,7 @@ var HclEngineImpl = class {
|
|
|
989
979
|
formatted,
|
|
990
980
|
prefix
|
|
991
981
|
);
|
|
992
|
-
return { files: fileMap, manifest, driftReport, sourceBlocked
|
|
982
|
+
return { files: fileMap, manifest, driftReport, sourceBlocked };
|
|
993
983
|
}
|
|
994
984
|
/**
|
|
995
985
|
* Verify: Check integrity of existing files against a Manifest.
|
|
@@ -1147,14 +1137,14 @@ export {
|
|
|
1147
1137
|
DEFAULT_PREFIX,
|
|
1148
1138
|
EngineError,
|
|
1149
1139
|
EngineErrorCode,
|
|
1140
|
+
bundleSchema,
|
|
1150
1141
|
canonicalHash,
|
|
1151
1142
|
classifyFile,
|
|
1152
1143
|
createEngine,
|
|
1153
1144
|
getCanonicalHashScriptPath,
|
|
1154
1145
|
isTofuAvailable,
|
|
1155
1146
|
parseHeader,
|
|
1156
|
-
|
|
1157
|
-
validateJsonSchemaStructure
|
|
1158
|
-
validateTemplateJson
|
|
1147
|
+
validateBundle,
|
|
1148
|
+
validateJsonSchemaStructure
|
|
1159
1149
|
};
|
|
1160
1150
|
//# sourceMappingURL=index.mjs.map
|