@telorun/assert 0.1.4 → 0.1.5
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/module-context.d.ts +3 -1
- package/dist/module-context.js +23 -32
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +20 -3
- package/package.json +2 -2
package/dist/module-context.d.ts
CHANGED
|
@@ -5,10 +5,12 @@ export declare const schema: import("@sinclair/typebox").TObject<{
|
|
|
5
5
|
name: import("@sinclair/typebox").TString;
|
|
6
6
|
module: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
7
7
|
}>;
|
|
8
|
-
|
|
8
|
+
resources: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TObject<{
|
|
9
9
|
variables: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
|
|
10
10
|
secrets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
|
|
11
11
|
}>>>;
|
|
12
|
+
variables: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
|
|
13
|
+
secrets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TAny>>;
|
|
12
14
|
}>;
|
|
13
15
|
type ModuleContextManifest = Static<typeof schema>;
|
|
14
16
|
export declare function create(manifest: ModuleContextManifest, ctx: ResourceContext): Promise<Runnable>;
|
package/dist/module-context.js
CHANGED
|
@@ -8,7 +8,9 @@ export const schema = Type.Object({
|
|
|
8
8
|
name: Type.String(),
|
|
9
9
|
module: Type.Optional(Type.String()),
|
|
10
10
|
}),
|
|
11
|
-
|
|
11
|
+
resources: Type.Optional(Type.Record(Type.String(), ImportEntry)),
|
|
12
|
+
variables: Type.Optional(Type.Record(Type.String(), Type.Any())),
|
|
13
|
+
secrets: Type.Optional(Type.Record(Type.String(), Type.Any())),
|
|
12
14
|
});
|
|
13
15
|
const useColor = process.stderr.isTTY;
|
|
14
16
|
const c = (code, text) => (useColor ? `\x1b[${code}m${text}\x1b[0m` : text);
|
|
@@ -38,56 +40,45 @@ export async function create(manifest, ctx) {
|
|
|
38
40
|
return {
|
|
39
41
|
run: async () => {
|
|
40
42
|
const declaringModule = manifest.metadata.module ?? "default";
|
|
41
|
-
const
|
|
43
|
+
const resourcesToCheck = manifest.resources ?? {};
|
|
42
44
|
const failures = [];
|
|
43
45
|
const passed = [];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (!
|
|
46
|
+
const { resources } = ctx.moduleContext;
|
|
47
|
+
for (const [alias, expected] of Object.entries(resourcesToCheck)) {
|
|
48
|
+
if (!ctx.resolveModuleAlias(declaringModule, alias)) {
|
|
47
49
|
failures.push(`Import alias '${alias}' not found in module '${declaringModule}'`);
|
|
48
50
|
continue;
|
|
49
51
|
}
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (!deepEqual(actualValue, expectedValue)) {
|
|
57
|
-
failures.push(`imports.${alias}.variables.${key}: expected ${yellow(JSON.stringify(expectedValue))}, got ${red(JSON.stringify(actualValue))}`);
|
|
52
|
+
const snap = resources[alias] ?? {};
|
|
53
|
+
const path = `resources.${alias}`;
|
|
54
|
+
for (const [key, expectedValue] of Object.entries(expected.variables ?? {})) {
|
|
55
|
+
const actual = snap?.variables?.[key];
|
|
56
|
+
if (deepEqual(actual, expectedValue)) {
|
|
57
|
+
passed.push(`${path}.variables.${key}`);
|
|
58
58
|
}
|
|
59
59
|
else {
|
|
60
|
-
|
|
60
|
+
failures.push(`${path}.variables.${key}: expected ${yellow(JSON.stringify(expectedValue))}, got ${red(JSON.stringify(actual))}`);
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
|
-
for (const [key] of Object.entries(
|
|
64
|
-
const
|
|
65
|
-
if (
|
|
66
|
-
|
|
63
|
+
for (const [key, expectedValue] of Object.entries(expected.secrets ?? {})) {
|
|
64
|
+
const actual = snap?.secrets?.[key];
|
|
65
|
+
if (deepEqual(actual, expectedValue)) {
|
|
66
|
+
passed.push(`${path}.secrets.${key}`);
|
|
67
67
|
}
|
|
68
68
|
else {
|
|
69
|
-
|
|
69
|
+
failures.push(`${path}.secrets.${key}: ${dim("value mismatch")}`);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
const name = manifest.metadata.name;
|
|
74
|
+
const passedLines = passed.map((p) => ` ${green("✓")} ${dim(p)}\n`).join("");
|
|
74
75
|
if (failures.length > 0) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
report += ` ${green("✓")} ${dim(p)}\n`;
|
|
78
|
-
}
|
|
79
|
-
for (const f of failures) {
|
|
80
|
-
report += ` ${red("✗")} ${f}\n`;
|
|
81
|
-
}
|
|
82
|
-
process.stderr.write(report);
|
|
76
|
+
const failedLines = failures.map((f) => ` ${red("✗")} ${f}\n`).join("");
|
|
77
|
+
process.stderr.write(bold(red(`Assert.ModuleContext.${name}: assertion failed`)) + "\n" + passedLines + failedLines);
|
|
83
78
|
ctx.requestExit(1);
|
|
84
79
|
}
|
|
85
80
|
else {
|
|
86
|
-
|
|
87
|
-
for (const p of passed) {
|
|
88
|
-
report += ` ${green("✓")} ${dim(p)}\n`;
|
|
89
|
-
}
|
|
90
|
-
process.stdout.write(report);
|
|
81
|
+
process.stdout.write(bold(green(`Assert.ModuleContext.${name}: assertion passed`)) + "\n" + passedLines);
|
|
91
82
|
}
|
|
92
83
|
},
|
|
93
84
|
};
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ResourceContext } from "@telorun/sdk";
|
|
2
2
|
import { Static } from "@sinclair/typebox";
|
|
3
3
|
export declare const schema: import("@sinclair/typebox").TObject<{
|
|
4
|
+
metadata: import("@sinclair/typebox").TObject<{
|
|
5
|
+
name: import("@sinclair/typebox").TString;
|
|
6
|
+
}>;
|
|
4
7
|
schema: import("@sinclair/typebox").TObject<{
|
|
5
8
|
type: import("@sinclair/typebox").TString;
|
|
6
9
|
}>;
|
package/dist/schema.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { Type } from "@sinclair/typebox";
|
|
2
2
|
export const schema = Type.Object({
|
|
3
|
+
metadata: Type.Object({
|
|
4
|
+
name: Type.String(),
|
|
5
|
+
}),
|
|
3
6
|
schema: Type.Object({
|
|
4
7
|
type: Type.String(),
|
|
5
8
|
}),
|
|
6
|
-
}
|
|
9
|
+
});
|
|
10
|
+
const useColor = process.stderr.isTTY;
|
|
11
|
+
const c = (code, text) => (useColor ? `\x1b[${code}m${text}\x1b[0m` : text);
|
|
12
|
+
const bold = (t) => c("1", t);
|
|
13
|
+
const red = (t) => c("31", t);
|
|
14
|
+
const green = (t) => c("32", t);
|
|
15
|
+
const dim = (t) => c("2", t);
|
|
7
16
|
export async function create(manifest, ctx) {
|
|
8
17
|
const validator = ctx.createSchemaValidator(manifest.schema);
|
|
18
|
+
const name = manifest.metadata.name;
|
|
9
19
|
return {
|
|
10
20
|
invoke: (data) => {
|
|
11
|
-
|
|
12
|
-
|
|
21
|
+
try {
|
|
22
|
+
validator.validate(data);
|
|
23
|
+
process.stdout.write(bold(green(`Assert.Schema.${name}: assertion passed`)) + "\n" + ` ${green("✓")} ${dim(JSON.stringify(data))}\n`);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
process.stderr.write(bold(red(`Assert.Schema.${name}: assertion failed`)) + "\n" + ` ${red("✗")} ${err?.message ?? String(err)}\n`);
|
|
28
|
+
throw err;
|
|
29
|
+
}
|
|
13
30
|
},
|
|
14
31
|
};
|
|
15
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telorun/assert",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./schema": "./src/schema.ts",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@sinclair/typebox": "^0.34.48",
|
|
15
|
-
"@telorun/sdk": "0.2.
|
|
15
|
+
"@telorun/sdk": "0.2.6"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@types/node": "^20.0.0",
|