@cardanvil/frame-kit 0.2.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 +137 -0
- package/dist/authoring/index.d.ts +2 -0
- package/dist/authoring/index.js +2 -0
- package/dist/authoring/layoutDefaults.d.ts +6 -0
- package/dist/authoring/layoutDefaults.js +80 -0
- package/dist/authoring/omit.d.ts +2 -0
- package/dist/authoring/omit.js +14 -0
- package/dist/cli/api.d.ts +34 -0
- package/dist/cli/api.js +188 -0
- package/dist/cli/build.d.ts +36 -0
- package/dist/cli/build.js +222 -0
- package/dist/cli/bundle.d.ts +23 -0
- package/dist/cli/bundle.js +58 -0
- package/dist/cli/devUrl.d.ts +10 -0
- package/dist/cli/devUrl.js +41 -0
- package/dist/cli/discover.d.ts +25 -0
- package/dist/cli/discover.js +116 -0
- package/dist/cli/emitSchemas.d.ts +2 -0
- package/dist/cli/emitSchemas.js +13 -0
- package/dist/cli/errors.d.ts +8 -0
- package/dist/cli/errors.js +11 -0
- package/dist/cli/frameIndex.d.ts +115 -0
- package/dist/cli/frameIndex.js +104 -0
- package/dist/cli/hash.d.ts +14 -0
- package/dist/cli/hash.js +32 -0
- package/dist/cli/imageSize.d.ts +13 -0
- package/dist/cli/imageSize.js +72 -0
- package/dist/cli/index.d.ts +18 -0
- package/dist/cli/index.js +18 -0
- package/dist/cli/loadFrame.d.ts +24 -0
- package/dist/cli/loadFrame.js +90 -0
- package/dist/cli/main.d.ts +2 -0
- package/dist/cli/main.js +228 -0
- package/dist/cli/report.d.ts +35 -0
- package/dist/cli/report.js +74 -0
- package/dist/cli/schema.d.ts +33 -0
- package/dist/cli/schema.js +51 -0
- package/dist/cli/stableJson.d.ts +11 -0
- package/dist/cli/stableJson.js +27 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/manifest/contract.d.ts +10503 -0
- package/dist/manifest/contract.js +87 -0
- package/dist/manifest/deserialize.d.ts +19 -0
- package/dist/manifest/deserialize.js +23 -0
- package/dist/manifest/index.d.ts +4 -0
- package/dist/manifest/index.js +4 -0
- package/dist/manifest/serialize.d.ts +35 -0
- package/dist/manifest/serialize.js +44 -0
- package/dist/manifest/testFrame.d.ts +9 -0
- package/dist/manifest/testFrame.js +53 -0
- package/dist/manifest/walk.d.ts +21 -0
- package/dist/manifest/walk.js +111 -0
- package/dist/schema/assetUrl.d.ts +27 -0
- package/dist/schema/assetUrl.js +28 -0
- package/dist/schema/frame.d.ts +26467 -0
- package/dist/schema/frame.js +312 -0
- package/dist/schema/frameAssets.d.ts +539 -0
- package/dist/schema/frameAssets.js +183 -0
- package/dist/schema/frameMeta.d.ts +24 -0
- package/dist/schema/frameMeta.js +48 -0
- package/dist/schema/index.d.ts +5 -0
- package/dist/schema/index.js +5 -0
- package/dist/schema/layout.d.ts +101 -0
- package/dist/schema/layout.js +59 -0
- package/package.json +62 -0
- package/schema/frame-index.schema.json +233 -0
- package/schema/frame-meta.schema.json +54 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** Renders a problem as one line: `frame › path — message`. */
|
|
2
|
+
export function formatProblem(problem) {
|
|
3
|
+
const where = [problem.frame, problem.path].filter(Boolean).join(" › ");
|
|
4
|
+
return where ? `${where} — ${problem.message}` : problem.message;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* GitHub Actions workflow-command form, which turns a problem into an inline
|
|
8
|
+
* annotation on the pull request diff. Emitting these from here is why neither
|
|
9
|
+
* CI workflow needs a reporting step of its own.
|
|
10
|
+
*/
|
|
11
|
+
function toAnnotation(problem) {
|
|
12
|
+
const parts = [
|
|
13
|
+
problem.file ? `file=${problem.file}` : undefined,
|
|
14
|
+
problem.frame ? `title=${problem.frame}` : undefined,
|
|
15
|
+
].filter((part) => part !== undefined);
|
|
16
|
+
const head = `::${problem.severity} ${parts.join(",")}`;
|
|
17
|
+
// Newlines terminate a workflow command, so they have to be escaped.
|
|
18
|
+
const body = formatProblem(problem).replace(/\r?\n/g, "%0A");
|
|
19
|
+
return `${head}::${body}`;
|
|
20
|
+
}
|
|
21
|
+
export class Reporter {
|
|
22
|
+
problems = [];
|
|
23
|
+
add(problem) {
|
|
24
|
+
this.problems.push(problem);
|
|
25
|
+
}
|
|
26
|
+
error(problem) {
|
|
27
|
+
this.add({ ...problem, severity: "error" });
|
|
28
|
+
}
|
|
29
|
+
warn(problem) {
|
|
30
|
+
this.add({ ...problem, severity: "warning" });
|
|
31
|
+
}
|
|
32
|
+
get errors() {
|
|
33
|
+
return this.problems.filter((problem) => problem.severity === "error");
|
|
34
|
+
}
|
|
35
|
+
get warnings() {
|
|
36
|
+
return this.problems.filter((problem) => problem.severity === "warning");
|
|
37
|
+
}
|
|
38
|
+
get ok() {
|
|
39
|
+
return this.errors.length === 0;
|
|
40
|
+
}
|
|
41
|
+
/** Human-readable lines for a terminal. */
|
|
42
|
+
toText() {
|
|
43
|
+
return this.problems
|
|
44
|
+
.map((problem) => `${problem.severity}: ${formatProblem(problem)}`)
|
|
45
|
+
.join("\n");
|
|
46
|
+
}
|
|
47
|
+
/** Workflow commands, one per problem. Empty outside GitHub Actions. */
|
|
48
|
+
toAnnotations() {
|
|
49
|
+
return this.problems.map(toAnnotation).join("\n");
|
|
50
|
+
}
|
|
51
|
+
toMarkdown() {
|
|
52
|
+
if (this.problems.length === 0) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
const rows = this.problems.map((problem) => {
|
|
56
|
+
const cells = [
|
|
57
|
+
problem.severity,
|
|
58
|
+
problem.frame ?? "",
|
|
59
|
+
problem.path ?? problem.file ?? "",
|
|
60
|
+
problem.message.replace(/\r?\n/g, " ").replaceAll("|", String.raw `\|`),
|
|
61
|
+
];
|
|
62
|
+
return `| ${cells.join(" | ")} |`;
|
|
63
|
+
});
|
|
64
|
+
return [
|
|
65
|
+
"| | Frame | Where | Problem |",
|
|
66
|
+
"| --- | --- | --- | --- |",
|
|
67
|
+
...rows,
|
|
68
|
+
].join("\n");
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** True when running inside GitHub Actions, where annotations are understood. */
|
|
72
|
+
export function inGitHubActions() {
|
|
73
|
+
return process.env.GITHUB_ACTIONS === "true";
|
|
74
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The formats this package defines, and what each is called on disk.
|
|
3
|
+
*
|
|
4
|
+
* Useful to anything that is not TypeScript — an editor offering completion in
|
|
5
|
+
* `frame.meta.json`, or a marketplace validating an index it fetched.
|
|
6
|
+
* TypeScript consumers should use the zod schemas directly instead.
|
|
7
|
+
*/
|
|
8
|
+
declare const SCHEMA_FILES: {
|
|
9
|
+
/** A frame descriptor. Authors write these by hand, so completion helps. */
|
|
10
|
+
readonly meta: "frame-meta.schema.json";
|
|
11
|
+
/** A release index. What an aggregator validates before trusting a repo. */
|
|
12
|
+
readonly index: "frame-index.schema.json";
|
|
13
|
+
/** A `.cardframe`'s frame.json. Large — emitted on request, not shipped. */
|
|
14
|
+
readonly manifest: "frame-manifest.schema.json";
|
|
15
|
+
/** A frame object. Large — emitted on request, not shipped. */
|
|
16
|
+
readonly frame: "frame.schema.json";
|
|
17
|
+
};
|
|
18
|
+
export type SchemaName = keyof typeof SCHEMA_FILES;
|
|
19
|
+
export declare const SCHEMA_NAMES: SchemaName[];
|
|
20
|
+
/**
|
|
21
|
+
* Emitted with the *input* view: these describe documents being written or
|
|
22
|
+
* read, where a field with a default is optional. The output view would mark
|
|
23
|
+
* those required, which is wrong for a document an author is authoring.
|
|
24
|
+
*/
|
|
25
|
+
export declare function toJsonSchema(name: SchemaName): unknown;
|
|
26
|
+
export declare function schemaFilename(name: SchemaName): string;
|
|
27
|
+
/**
|
|
28
|
+
* The schemas small enough, and useful enough, to ship in the package. The
|
|
29
|
+
* other two are hundreds of kilobytes and have no consumer that could not use
|
|
30
|
+
* the zod schema instead.
|
|
31
|
+
*/
|
|
32
|
+
export declare const SHIPPED_SCHEMAS: SchemaName[];
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { FrameManifestSchema } from "../manifest/contract.js";
|
|
3
|
+
import { FrameSchema } from "../schema/frame.js";
|
|
4
|
+
import { FrameMetaSchema } from "../schema/frameMeta.js";
|
|
5
|
+
import { FrameIndexSchema } from "./frameIndex.js";
|
|
6
|
+
/**
|
|
7
|
+
* The formats this package defines, and what each is called on disk.
|
|
8
|
+
*
|
|
9
|
+
* Useful to anything that is not TypeScript — an editor offering completion in
|
|
10
|
+
* `frame.meta.json`, or a marketplace validating an index it fetched.
|
|
11
|
+
* TypeScript consumers should use the zod schemas directly instead.
|
|
12
|
+
*/
|
|
13
|
+
const SCHEMA_FILES = {
|
|
14
|
+
/** A frame descriptor. Authors write these by hand, so completion helps. */
|
|
15
|
+
meta: "frame-meta.schema.json",
|
|
16
|
+
/** A release index. What an aggregator validates before trusting a repo. */
|
|
17
|
+
index: "frame-index.schema.json",
|
|
18
|
+
/** A `.cardframe`'s frame.json. Large — emitted on request, not shipped. */
|
|
19
|
+
manifest: "frame-manifest.schema.json",
|
|
20
|
+
/** A frame object. Large — emitted on request, not shipped. */
|
|
21
|
+
frame: "frame.schema.json",
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Annotated as `z.ZodType` on purpose. Without it TypeScript inlines each
|
|
25
|
+
* schema's full inferred type into this module's declarations, which turns a
|
|
26
|
+
* fifty-line file into a megabyte of .d.ts.
|
|
27
|
+
*/
|
|
28
|
+
const SCHEMAS = {
|
|
29
|
+
meta: FrameMetaSchema,
|
|
30
|
+
index: FrameIndexSchema,
|
|
31
|
+
manifest: FrameManifestSchema,
|
|
32
|
+
frame: FrameSchema,
|
|
33
|
+
};
|
|
34
|
+
export const SCHEMA_NAMES = Object.keys(SCHEMA_FILES);
|
|
35
|
+
/**
|
|
36
|
+
* Emitted with the *input* view: these describe documents being written or
|
|
37
|
+
* read, where a field with a default is optional. The output view would mark
|
|
38
|
+
* those required, which is wrong for a document an author is authoring.
|
|
39
|
+
*/
|
|
40
|
+
export function toJsonSchema(name) {
|
|
41
|
+
return z.toJSONSchema(SCHEMAS[name], { io: "input" });
|
|
42
|
+
}
|
|
43
|
+
export function schemaFilename(name) {
|
|
44
|
+
return SCHEMA_FILES[name];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The schemas small enough, and useful enough, to ship in the package. The
|
|
48
|
+
* other two are hundreds of kilobytes and have no consumer that could not use
|
|
49
|
+
* the zod schema instead.
|
|
50
|
+
*/
|
|
51
|
+
export const SHIPPED_SCHEMAS = ["meta", "index"];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON with object keys sorted, recursively.
|
|
3
|
+
*
|
|
4
|
+
* A manifest's bytes should depend only on the frame, never on the order zod
|
|
5
|
+
* happened to build an object in — so two builds of the same source produce an
|
|
6
|
+
* identical `frame.json`, and diffing two releases is diffing text.
|
|
7
|
+
*
|
|
8
|
+
* Arrays keep their order: `assets` is already sorted by path, and layout
|
|
9
|
+
* ordering is meaningful.
|
|
10
|
+
*/
|
|
11
|
+
export declare function stableStringify(value: unknown): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON with object keys sorted, recursively.
|
|
3
|
+
*
|
|
4
|
+
* A manifest's bytes should depend only on the frame, never on the order zod
|
|
5
|
+
* happened to build an object in — so two builds of the same source produce an
|
|
6
|
+
* identical `frame.json`, and diffing two releases is diffing text.
|
|
7
|
+
*
|
|
8
|
+
* Arrays keep their order: `assets` is already sorted by path, and layout
|
|
9
|
+
* ordering is meaningful.
|
|
10
|
+
*/
|
|
11
|
+
export function stableStringify(value) {
|
|
12
|
+
return `${JSON.stringify(sortKeys(value), null, 2)}\n`;
|
|
13
|
+
}
|
|
14
|
+
function sortKeys(value) {
|
|
15
|
+
if (Array.isArray(value)) {
|
|
16
|
+
return value.map(sortKeys);
|
|
17
|
+
}
|
|
18
|
+
if (value === null || typeof value !== "object") {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
const source = value;
|
|
22
|
+
const sorted = {};
|
|
23
|
+
for (const key of Object.keys(source).sort()) {
|
|
24
|
+
sorted[key] = sortKeys(source[key]);
|
|
25
|
+
}
|
|
26
|
+
return sorted;
|
|
27
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED