@sealpixel/core 1.0.0-rc.2 → 1.0.0-rc.21

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.
Files changed (91) hide show
  1. package/LICENSE.md +2 -2
  2. package/dist/assets.d.ts +0 -1
  3. package/dist/assets.js.map +1 -1
  4. package/dist/canonical-json.d.ts +0 -1
  5. package/dist/canonical-json.js.map +1 -1
  6. package/dist/compile.d.ts +0 -1
  7. package/dist/compile.js.map +1 -1
  8. package/dist/embedded.d.ts +0 -1
  9. package/dist/embedded.js.map +1 -1
  10. package/dist/errors.d.ts +1 -2
  11. package/dist/errors.js.map +1 -1
  12. package/dist/external-kernel.d.ts +0 -1
  13. package/dist/external-kernel.js.map +1 -1
  14. package/dist/generated/geometry.d.ts +1 -2
  15. package/dist/generated/geometry.js.map +1 -1
  16. package/dist/generated/output.d.ts +0 -1
  17. package/dist/generated/output.js.map +1 -1
  18. package/dist/generated/plan.d.ts +18 -7
  19. package/dist/generated/plan.js.map +1 -1
  20. package/dist/history.d.ts +2 -1
  21. package/dist/history.js +5 -1
  22. package/dist/history.js.map +1 -1
  23. package/dist/image-size.d.ts +4 -3
  24. package/dist/image-size.js +5 -3
  25. package/dist/image-size.js.map +1 -1
  26. package/dist/index.d.ts +4 -4
  27. package/dist/index.js +2 -1
  28. package/dist/index.js.map +1 -1
  29. package/dist/inline-renderer.d.ts +4 -5
  30. package/dist/inline-renderer.js +7 -7
  31. package/dist/inline-renderer.js.map +1 -1
  32. package/dist/manifest.d.ts +127 -0
  33. package/dist/manifest.js +115 -0
  34. package/dist/manifest.js.map +1 -0
  35. package/dist/options.d.ts +0 -1
  36. package/dist/options.js.map +1 -1
  37. package/dist/plan.d.ts +0 -1
  38. package/dist/plan.js +1 -1
  39. package/dist/plan.js.map +1 -1
  40. package/dist/plugin.d.ts +0 -1
  41. package/dist/plugin.js.map +1 -1
  42. package/dist/registry.d.ts +0 -1
  43. package/dist/registry.js +10 -1
  44. package/dist/registry.js.map +1 -1
  45. package/dist/render.d.ts +21 -1
  46. package/dist/render.js +148 -12
  47. package/dist/render.js.map +1 -1
  48. package/dist/renderer-core.d.ts +24 -17
  49. package/dist/renderer-core.js +36 -22
  50. package/dist/renderer-core.js.map +1 -1
  51. package/dist/renderer.d.ts +5 -6
  52. package/dist/renderer.js.map +1 -1
  53. package/dist/session.d.ts +30 -50
  54. package/dist/session.js +142 -169
  55. package/dist/session.js.map +1 -1
  56. package/dist/types.d.ts +18 -3
  57. package/dist/types.js.map +1 -1
  58. package/dist/worker-protocol.d.ts +8 -8
  59. package/dist/worker-protocol.js.map +1 -1
  60. package/dist/worker-renderer.d.ts +4 -5
  61. package/dist/worker-renderer.js +15 -6
  62. package/dist/worker-renderer.js.map +1 -1
  63. package/dist/worker.d.ts +0 -1
  64. package/dist/worker.js +6 -6
  65. package/dist/worker.js.map +1 -1
  66. package/package.json +6 -6
  67. package/dist/assets.d.ts.map +0 -1
  68. package/dist/canonical-json.d.ts.map +0 -1
  69. package/dist/compile.d.ts.map +0 -1
  70. package/dist/embedded.d.ts.map +0 -1
  71. package/dist/errors.d.ts.map +0 -1
  72. package/dist/external-kernel.d.ts.map +0 -1
  73. package/dist/generated/geometry.d.ts.map +0 -1
  74. package/dist/generated/output.d.ts.map +0 -1
  75. package/dist/generated/plan.d.ts.map +0 -1
  76. package/dist/history.d.ts.map +0 -1
  77. package/dist/image-size.d.ts.map +0 -1
  78. package/dist/index.d.ts.map +0 -1
  79. package/dist/inline-renderer.d.ts.map +0 -1
  80. package/dist/options.d.ts.map +0 -1
  81. package/dist/plan.d.ts.map +0 -1
  82. package/dist/plugin.d.ts.map +0 -1
  83. package/dist/registry.d.ts.map +0 -1
  84. package/dist/render.d.ts.map +0 -1
  85. package/dist/renderer-core.d.ts.map +0 -1
  86. package/dist/renderer.d.ts.map +0 -1
  87. package/dist/session.d.ts.map +0 -1
  88. package/dist/types.d.ts.map +0 -1
  89. package/dist/worker-protocol.d.ts.map +0 -1
  90. package/dist/worker-renderer.d.ts.map +0 -1
  91. package/dist/worker.d.ts.map +0 -1
@@ -0,0 +1,127 @@
1
+ import { z } from 'zod';
2
+ import type { RenderPlan } from './plan.js';
3
+ import type { EditLog } from './types.js';
4
+ /**
5
+ * The render manifest: what a render was made from and the hash of what it
6
+ * produced, so that anyone with the original can check the result later.
7
+ *
8
+ * Version 1. `render({ manifest: true })` writes it, `verify()` in
9
+ * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The
10
+ * fields are public API: a field is added with a default, never renamed or
11
+ * removed, and an incompatible change bumps `version`. The native CLI's
12
+ * `sealpixel_core::manifest` is the same format.
13
+ */
14
+ export declare const MANIFEST_VERSION = 1;
15
+ /** Which build produced the pixels. `kind` is `wasm` here, `native` for the CLI. */
16
+ export interface RendererIdentity {
17
+ kind: 'wasm' | 'native';
18
+ version: string;
19
+ /** sha256 of the WebAssembly binary or the native executable, when the loader saw its bytes. */
20
+ binarySha256: string | null;
21
+ }
22
+ export interface RenderManifest {
23
+ version: 1;
24
+ source: {
25
+ /** The size after EXIF orientation, as the edit log states it. */
26
+ width: number;
27
+ height: number;
28
+ /** sha256 of the original's bytes. */
29
+ hash: string;
30
+ mimeType?: string;
31
+ };
32
+ /** `{ log, index }` as the editor keeps it. Absent in a manifest the native CLI wrote. */
33
+ editLog?: {
34
+ log: EditLog;
35
+ index: number;
36
+ };
37
+ /** sha256 of `editLog` in canonical JSON: the text `embedEditLog` stores in a file. */
38
+ editLogHash?: string;
39
+ /** The core plan, when every stage of the render ran in the core. */
40
+ plan?: RenderPlan;
41
+ /** The stages that ran outside the core, when any did: then there is no `plan`. */
42
+ kernels?: string[];
43
+ /** The plugin versions the log was compiled with. */
44
+ plugins: Record<string, number>;
45
+ renderer: RendererIdentity;
46
+ output: {
47
+ /** The encoder options in the core's form: `{ "format": "png", ... }`, never with `embed`. */
48
+ options: Record<string, unknown>;
49
+ /** The file holds the edit log, as `embedEditLog: true` stores it. */
50
+ embedEditLog?: boolean;
51
+ width: number;
52
+ height: number;
53
+ /** sha256 over the rendered pixels, before encoding. Survives any change to the file. */
54
+ pixelHash: string;
55
+ /** sha256 of the encoded bytes as the renderer wrote them. */
56
+ byteHash: string;
57
+ };
58
+ /** One id for this render. See `renderHash()`. */
59
+ renderHash: string;
60
+ }
61
+ /**
62
+ * The manifest as untrusted input: the shape, the hashes and the numbers. The
63
+ * edit log inside it is only an object here; `verify()` parses it with the
64
+ * registry, and the core checks the plan when it renders.
65
+ */
66
+ export declare const RenderManifestSchema: z.ZodObject<{
67
+ version: z.ZodLiteral<1>;
68
+ source: z.ZodObject<{
69
+ width: z.ZodNumber;
70
+ height: z.ZodNumber;
71
+ hash: z.ZodString;
72
+ mimeType: z.ZodOptional<z.ZodString>;
73
+ }, z.core.$strip>;
74
+ editLog: z.ZodOptional<z.ZodObject<{
75
+ log: z.ZodRecord<z.ZodString, z.ZodUnknown>;
76
+ index: z.ZodNumber;
77
+ }, z.core.$strip>>;
78
+ editLogHash: z.ZodOptional<z.ZodString>;
79
+ plan: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
80
+ kernels: z.ZodOptional<z.ZodArray<z.ZodString>>;
81
+ plugins: z.ZodRecord<z.ZodString, z.ZodNumber>;
82
+ renderer: z.ZodObject<{
83
+ kind: z.ZodEnum<{
84
+ wasm: "wasm";
85
+ native: "native";
86
+ }>;
87
+ version: z.ZodString;
88
+ binarySha256: z.ZodNullable<z.ZodString>;
89
+ }, z.core.$strip>;
90
+ output: z.ZodObject<{
91
+ options: z.ZodRecord<z.ZodString, z.ZodUnknown>;
92
+ embedEditLog: z.ZodOptional<z.ZodBoolean>;
93
+ width: z.ZodNumber;
94
+ height: z.ZodNumber;
95
+ pixelHash: z.ZodString;
96
+ byteHash: z.ZodString;
97
+ }, z.core.$strip>;
98
+ renderHash: z.ZodString;
99
+ }, z.core.$strip>;
100
+ /** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */
101
+ export declare function parseRenderManifest(input: unknown): RenderManifest;
102
+ /**
103
+ * The id of a render: a sha256 over the facts the manifest states, in a
104
+ * fixed text form that every runtime builds with string operations alone,
105
+ * so no canonical-JSON rules are needed to agree on it. `verify` does not
106
+ * recompute it; it checks the facts.
107
+ *
108
+ * ```text
109
+ * sealpixel-render/1
110
+ * <source hash>
111
+ * <edit log hash, or the plan hash for a manifest without a log>
112
+ * <plugins as id@version, sorted by id, joined by ','>
113
+ * <renderer kind> <renderer version> <binary sha256 or '-'>
114
+ * <pixel hash>
115
+ * <byte hash>
116
+ * ```
117
+ */
118
+ export declare function renderHash(sha256Hex: (bytes: Uint8Array) => string, facts: {
119
+ sourceHash: string;
120
+ editsHash: string;
121
+ plugins: Record<string, number>;
122
+ renderer: RendererIdentity;
123
+ pixelHash: string;
124
+ byteHash: string;
125
+ }): string;
126
+ /** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */
127
+ export declare function editLogHash(sha256Hex: (bytes: Uint8Array) => string, log: EditLog, index: number): string;
@@ -0,0 +1,115 @@
1
+ import { z } from 'zod';
2
+ import { canonicalJson } from './canonical-json.js';
3
+ import { SealpixelError } from './errors.js';
4
+ /**
5
+ * The render manifest: what a render was made from and the hash of what it
6
+ * produced, so that anyone with the original can check the result later.
7
+ *
8
+ * Version 1. `render({ manifest: true })` writes it, `verify()` in
9
+ * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The
10
+ * fields are public API: a field is added with a default, never renamed or
11
+ * removed, and an incompatible change bumps `version`. The native CLI's
12
+ * `sealpixel_core::manifest` is the same format.
13
+ */
14
+ export const MANIFEST_VERSION = 1;
15
+ const sha256 = z.string().regex(/^[0-9a-f]{64}$/);
16
+ /**
17
+ * The manifest as untrusted input: the shape, the hashes and the numbers. The
18
+ * edit log inside it is only an object here; `verify()` parses it with the
19
+ * registry, and the core checks the plan when it renders.
20
+ */
21
+ export const RenderManifestSchema = z.object({
22
+ version: z.literal(1),
23
+ source: z.object({
24
+ width: z.number().int().positive(),
25
+ height: z.number().int().positive(),
26
+ hash: sha256,
27
+ mimeType: z.string().optional(),
28
+ }),
29
+ editLog: z
30
+ .object({
31
+ log: z.record(z.string(), z.unknown()),
32
+ index: z.number().int().nonnegative(),
33
+ })
34
+ .optional(),
35
+ editLogHash: sha256.optional(),
36
+ plan: z.record(z.string(), z.unknown()).optional(),
37
+ kernels: z.array(z.string()).optional(),
38
+ plugins: z.record(z.string(), z.number().int()),
39
+ renderer: z.object({
40
+ kind: z.enum(['wasm', 'native']),
41
+ version: z.string(),
42
+ binarySha256: sha256.nullable(),
43
+ }),
44
+ output: z.object({
45
+ options: z.record(z.string(), z.unknown()),
46
+ embedEditLog: z.boolean().optional(),
47
+ width: z.number().int().positive(),
48
+ height: z.number().int().positive(),
49
+ pixelHash: sha256,
50
+ byteHash: sha256,
51
+ }),
52
+ renderHash: sha256,
53
+ });
54
+ /** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */
55
+ export function parseRenderManifest(input) {
56
+ const result = RenderManifestSchema.safeParse(input);
57
+ if (!result.success) {
58
+ const issue = result.error.issues[0];
59
+ throw new SealpixelError('INVALID_REQUEST', `manifest: ${issue ? `${issue.path.join('.') || '(root)'}: ${issue.message}` : 'invalid'}`);
60
+ }
61
+ return result.data;
62
+ }
63
+ /**
64
+ * The id of a render: a sha256 over the facts the manifest states, in a
65
+ * fixed text form that every runtime builds with string operations alone,
66
+ * so no canonical-JSON rules are needed to agree on it. `verify` does not
67
+ * recompute it; it checks the facts.
68
+ *
69
+ * ```text
70
+ * sealpixel-render/1
71
+ * <source hash>
72
+ * <edit log hash, or the plan hash for a manifest without a log>
73
+ * <plugins as id@version, sorted by id, joined by ','>
74
+ * <renderer kind> <renderer version> <binary sha256 or '-'>
75
+ * <pixel hash>
76
+ * <byte hash>
77
+ * ```
78
+ */
79
+ export function renderHash(sha256Hex, facts) {
80
+ const plugins = Object.keys(facts.plugins)
81
+ .sort(byCodePoint)
82
+ .map((id) => `${id}@${facts.plugins[id]}`)
83
+ .join(',');
84
+ const renderer = `${facts.renderer.kind} ${facts.renderer.version} ${facts.renderer.binarySha256 ?? '-'}`;
85
+ const text = [
86
+ `sealpixel-render/${MANIFEST_VERSION}`,
87
+ facts.sourceHash,
88
+ facts.editsHash,
89
+ plugins,
90
+ renderer,
91
+ facts.pixelHash,
92
+ facts.byteHash,
93
+ ].join('\n');
94
+ return sha256Hex(new TextEncoder().encode(text));
95
+ }
96
+ /**
97
+ * Code point order, which is the byte order of UTF-8 and the order a Rust
98
+ * `BTreeMap<String, _>` iterates in. JavaScript's default sort compares
99
+ * UTF-16 code units, which differs for characters outside the basic plane.
100
+ */
101
+ function byCodePoint(a, b) {
102
+ const x = Array.from(a, (c) => c.codePointAt(0) ?? 0);
103
+ const y = Array.from(b, (c) => c.codePointAt(0) ?? 0);
104
+ for (let i = 0; i < Math.min(x.length, y.length); i++) {
105
+ const d = (x[i] ?? 0) - (y[i] ?? 0);
106
+ if (d !== 0)
107
+ return d;
108
+ }
109
+ return x.length - y.length;
110
+ }
111
+ /** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */
112
+ export function editLogHash(sha256Hex, log, index) {
113
+ return sha256Hex(new TextEncoder().encode(canonicalJson({ log, index })));
114
+ }
115
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAI7C;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC;AA+ClC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAA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,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;AAC7B,CAAC;AAED,6FAA6F;AAC7F,MAAM,UAAU,WAAW,CACzB,SAAwC,EACxC,GAAY,EACZ,KAAa;IAEb,OAAO,SAAS,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;AAC5E,CAAC","sourcesContent":["import { z } from 'zod';\nimport { canonicalJson } from './canonical-json.js';\nimport { SealpixelError } from './errors.js';\nimport type { RenderPlan } from './plan.js';\nimport type { EditLog } from './types.js';\n\n/**\n * The render manifest: what a render was made from and the hash of what it\n * produced, so that anyone with the original can check the result later.\n *\n * Version 1. `render({ manifest: true })` writes it, `verify()` in\n * `@sealpixel/render` and `sealpixel verify` in the native CLI read it. The\n * fields are public API: a field is added with a default, never renamed or\n * removed, and an incompatible change bumps `version`. The native CLI's\n * `sealpixel_core::manifest` is the same format.\n */\nexport const MANIFEST_VERSION = 1;\n\n/** Which build produced the pixels. `kind` is `wasm` here, `native` for the CLI. */\nexport interface RendererIdentity {\n kind: 'wasm' | 'native';\n version: string;\n /** sha256 of the WebAssembly binary or the native executable, when the loader saw its bytes. */\n binarySha256: string | null;\n}\n\nexport interface RenderManifest {\n version: 1;\n source: {\n /** The size after EXIF orientation, as the edit log states it. */\n width: number;\n height: number;\n /** sha256 of the original's bytes. */\n hash: string;\n mimeType?: string;\n };\n /** `{ log, index }` as the editor keeps it. Absent in a manifest the native CLI wrote. */\n editLog?: { log: EditLog; index: number };\n /** sha256 of `editLog` in canonical JSON: the text `embedEditLog` stores in a file. */\n editLogHash?: string;\n /** The core plan, when every stage of the render ran in the core. */\n plan?: RenderPlan;\n /** The stages that ran outside the core, when any did: then there is no `plan`. */\n kernels?: string[];\n /** The plugin versions the log was compiled with. */\n plugins: Record<string, number>;\n renderer: RendererIdentity;\n output: {\n /** The encoder options in the core's form: `{ \"format\": \"png\", ... }`, never with `embed`. */\n options: Record<string, unknown>;\n /** The file holds the edit log, as `embedEditLog: true` stores it. */\n embedEditLog?: boolean;\n width: number;\n height: number;\n /** sha256 over the rendered pixels, before encoding. Survives any change to the file. */\n pixelHash: string;\n /** sha256 of the encoded bytes as the renderer wrote them. */\n byteHash: string;\n };\n /** One id for this render. See `renderHash()`. */\n renderHash: string;\n}\n\nconst sha256 = z.string().regex(/^[0-9a-f]{64}$/);\n\n/**\n * The manifest as untrusted input: the shape, the hashes and the numbers. The\n * edit log inside it is only an object here; `verify()` parses it with the\n * registry, and the core checks the plan when it renders.\n */\nexport const RenderManifestSchema = z.object({\n version: z.literal(1),\n source: z.object({\n width: z.number().int().positive(),\n height: z.number().int().positive(),\n hash: sha256,\n mimeType: z.string().optional(),\n }),\n editLog: z\n .object({\n log: z.record(z.string(), z.unknown()),\n index: z.number().int().nonnegative(),\n })\n .optional(),\n editLogHash: sha256.optional(),\n plan: z.record(z.string(), z.unknown()).optional(),\n kernels: z.array(z.string()).optional(),\n plugins: z.record(z.string(), z.number().int()),\n renderer: z.object({\n kind: z.enum(['wasm', 'native']),\n version: z.string(),\n binarySha256: sha256.nullable(),\n }),\n output: z.object({\n options: z.record(z.string(), z.unknown()),\n embedEditLog: z.boolean().optional(),\n width: z.number().int().positive(),\n height: z.number().int().positive(),\n pixelHash: sha256,\n byteHash: sha256,\n }),\n renderHash: sha256,\n});\n\n/** Parses an untrusted manifest. Throws `INVALID_REQUEST` with the first problem. */\nexport function parseRenderManifest(input: unknown): RenderManifest {\n const result = RenderManifestSchema.safeParse(input);\n if (!result.success) {\n const issue = result.error.issues[0];\n throw new SealpixelError(\n 'INVALID_REQUEST',\n `manifest: ${issue ? `${issue.path.join('.') || '(root)'}: ${issue.message}` : 'invalid'}`,\n );\n }\n return result.data as unknown as RenderManifest;\n}\n\n/**\n * The id of a render: a sha256 over the facts the manifest states, in a\n * fixed text form that every runtime builds with string operations alone,\n * so no canonical-JSON rules are needed to agree on it. `verify` does not\n * recompute it; it checks the facts.\n *\n * ```text\n * sealpixel-render/1\n * <source hash>\n * <edit log hash, or the plan hash for a manifest without a log>\n * <plugins as id@version, sorted by id, joined by ','>\n * <renderer kind> <renderer version> <binary sha256 or '-'>\n * <pixel hash>\n * <byte hash>\n * ```\n */\nexport function renderHash(\n sha256Hex: (bytes: Uint8Array) => string,\n facts: {\n sourceHash: string;\n editsHash: string;\n plugins: Record<string, number>;\n renderer: RendererIdentity;\n pixelHash: string;\n byteHash: string;\n },\n): string {\n const plugins = Object.keys(facts.plugins)\n .sort(byCodePoint)\n .map((id) => `${id}@${facts.plugins[id]}`)\n .join(',');\n const renderer = `${facts.renderer.kind} ${facts.renderer.version} ${facts.renderer.binarySha256 ?? '-'}`;\n const text = [\n `sealpixel-render/${MANIFEST_VERSION}`,\n facts.sourceHash,\n facts.editsHash,\n plugins,\n renderer,\n facts.pixelHash,\n facts.byteHash,\n ].join('\\n');\n return sha256Hex(new TextEncoder().encode(text));\n}\n\n/**\n * Code point order, which is the byte order of UTF-8 and the order a Rust\n * `BTreeMap<String, _>` iterates in. JavaScript's default sort compares\n * UTF-16 code units, which differs for characters outside the basic plane.\n */\nfunction byCodePoint(a: string, b: string): number {\n const x = Array.from(a, (c) => c.codePointAt(0) ?? 0);\n const y = Array.from(b, (c) => c.codePointAt(0) ?? 0);\n for (let i = 0; i < Math.min(x.length, y.length); i++) {\n const d = (x[i] ?? 0) - (y[i] ?? 0);\n if (d !== 0) return d;\n }\n return x.length - y.length;\n}\n\n/** The hash `editLogHash` and the embedded log share: canonical JSON of `{ log, index }`. */\nexport function editLogHash(\n sha256Hex: (bytes: Uint8Array) => string,\n log: EditLog,\n index: number,\n): string {\n return sha256Hex(new TextEncoder().encode(canonicalJson({ log, index })));\n}\n"]}
package/dist/options.d.ts CHANGED
@@ -10,4 +10,3 @@ export type PluginOptionsMap = Readonly<Record<string, unknown>>;
10
10
  export declare function configurePlugins(plugins: readonly AnyPlugin[], options: PluginOptionsMap | null | undefined): readonly AnyPlugin[];
11
11
  /** The resolved options of every plugin that has any, keyed by id. */
12
12
  export declare function pluginOptionsOf(plugins: readonly AnyPlugin[]): Record<string, unknown>;
13
- //# sourceMappingURL=options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAM7C;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA6B,EAC7B,OAA4C;IAE5C,IAAI,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC;IAClE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9C,KAAK,MAAM,EAAE,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QACtC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,cAAc,CACtB,iBAAiB,EACjB,0BAA0B,EAAE,qBAAqB,CAClD,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;QAC5B,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACnC,IAAI,OAAO,KAAK,SAAS;YAAE,OAAO,MAAM,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YACtB,MAAM,IAAI,cAAc,CACtB,iBAAiB,EACjB,0BAA0B,MAAM,CAAC,EAAE,kBAAkB,CACtD,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,SAAS,CAAC,OAA2C,CAAC,CAAC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IAAI,cAAc,CACtB,iBAAiB,EACjB,0BAA0B,MAAM,CAAC,EAAE,kBAAkB,CACtD,CAAC;QACJ,CAAC;QACD,OAAO,MAAM,CAAC,SAAS,CAAC,OAA2C,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;AACL,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,eAAe,CAAC,OAA6B;IAC3D,MAAM,GAAG,GAA4B,EAAE,CAAC;IACxC,KAAK,MAAM,CAAC,IAAI,OAAO;QAAE,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS;YAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC;IAC5E,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { SealpixelError } from './errors.js';\nimport type { AnyPlugin } from './plugin.js';\n\n/** `{ pluginId: partialOptions }`, as accepted by the element, the wrappers and the server. */\nexport type PluginOptionsMap = Readonly<Record<string, unknown>>;\n\n/**\n * Applies `options[plugin.id]` to each plugin through its `configure()`.\n * Plugins without an entry are returned as they are. An entry for an unknown\n * plugin id, or for a plugin without options, is an error: silently ignoring\n * it would hide a typo in a security-relevant constraint.\n */\nexport function configurePlugins(\n plugins: readonly AnyPlugin[],\n options: PluginOptionsMap | null | undefined,\n): readonly AnyPlugin[] {\n if (!options || Object.keys(options).length === 0) return plugins;\n const ids = new Set(plugins.map((p) => p.id));\n for (const id of Object.keys(options)) {\n if (!ids.has(id)) {\n throw new SealpixelError(\n 'INVALID_REQUEST',\n `pluginOptions: plugin \"${id}\" is not registered`,\n );\n }\n }\n return plugins.map((plugin) => {\n const partial = options[plugin.id];\n if (partial === undefined) return plugin;\n if (!plugin.configure) {\n throw new SealpixelError(\n 'INVALID_REQUEST',\n `pluginOptions: plugin \"${plugin.id}\" has no options`,\n );\n }\n return plugin.configure(partial as Partial<Record<string, unknown>>);\n });\n}\n\n/** The resolved options of every plugin that has any, keyed by id. */\nexport function pluginOptionsOf(plugins: readonly AnyPlugin[]): Record<string, unknown> {\n const out: Record<string, unknown> = {};\n for (const p of plugins) if (p.options !== undefined) out[p.id] = p.options;\n return out;\n}\n"]}
package/dist/plan.d.ts CHANGED
@@ -13,4 +13,3 @@ export declare function toRenderPlan(log: EditLog, actual: {
13
13
  width: number;
14
14
  height: number;
15
15
  }, stages?: Stage[]): RenderPlan;
16
- //# sourceMappingURL=plan.d.ts.map
package/dist/plan.js CHANGED
@@ -8,7 +8,7 @@ export function toRenderPlan(log, actual, stages = []) {
8
8
  return {
9
9
  version: PLAN_VERSION,
10
10
  source: { width: log.source.width, height: log.source.height },
11
- proxyScale: actual.width / log.source.width,
11
+ bufferScale: actual.width / log.source.width,
12
12
  stages,
13
13
  };
14
14
  }
package/dist/plan.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAoBA,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAY,EACZ,MAAyC,EACzC,SAAkB,EAAE;IAEpB,OAAO;QACL,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE;QAC9D,UAAU,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK;QAC3C,MAAM;KACP,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"plan.js","sourceRoot":"","sources":["../src/plan.ts"],"names":[],"mappings":"AAoBA,oDAAoD;AACpD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAC;AAE9B;;;GAGG;AACH,MAAM,UAAU,YAAY,CAC1B,GAAY,EACZ,MAAyC,EACzC,SAAkB,EAAE;IAEpB,OAAO;QACL,OAAO,EAAE,YAAY;QACrB,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE;QAC9D,WAAW,EAAE,MAAM,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK;QAC5C,MAAM;KACP,CAAC;AACJ,CAAC","sourcesContent":["import type { RenderPlan, Stage } from './generated/plan.js';\nimport type { EditLog } from './types.js';\n\nexport type { Geometry, Size, StageGeometry } from './generated/geometry.js';\nexport type {\n ChromaSubsampling,\n Format as CoreFormat,\n OutputOptions as CoreOutputOptions,\n} from './generated/output.js';\nexport type {\n ColorStage,\n CropStage,\n Fit,\n Rect as PlanRect,\n RenderPlan,\n ResizeStage,\n SourceInfo,\n Stage,\n} from './generated/plan.js';\n\n/** Mirrors `sealpixel_core::plan::PLAN_VERSION`. */\nexport const PLAN_VERSION = 1;\n\n/**\n * Builds the plan for `log` executed on a buffer of `actual` size. Until the\n * plugin registry lands (S1.9) every log compiles to the identity plan.\n */\nexport function toRenderPlan(\n log: EditLog,\n actual: { width: number; height: number },\n stages: Stage[] = [],\n): RenderPlan {\n return {\n version: PLAN_VERSION,\n source: { width: log.source.width, height: log.source.height },\n bufferScale: actual.width / log.source.width,\n stages,\n };\n}\n"]}
package/dist/plugin.d.ts CHANGED
@@ -197,4 +197,3 @@ export interface SealpixelPlugin<Id extends string = string, Doc = unknown, Opti
197
197
  export type AnyPlugin = SealpixelPlugin<string, any, any>;
198
198
  /** Core stage kinds a `kernel: { kind: 'core' }` plugin may target. */
199
199
  export type CoreStageName = Stage['kind'];
200
- //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Plugin contract. These are types only; `@sealpixel/plugin-sdk` provides the\n * `definePlugin` / `defineOperation` helpers and deterministic math, and\n * `@sealpixel/core` provides the registry that consumes plugins.\n */\nimport type { RgbaBuffer } from '@sealpixel/wasm';\nimport type { Size, Stage } from './plan.js';\nimport type { Operation, OperationBase, SourceDescriptor } from './types.js';\n\n/** Augmented by plugins: `declare module '@sealpixel/core' { interface DocumentRegistry { finetune: FinetuneDoc } }`. */\n// biome-ignore lint/suspicious/noEmptyInterface: augmentation target\nexport interface DocumentRegistry {}\n/** Derived state: one slice per plugin, keyed by plugin id. */\nexport type Document = { [K in keyof DocumentRegistry]: DocumentRegistry[K] };\n\n/** Runtime validator for one operation. Structural so any zod-like schema works. */\nexport interface OperationSchema<Op> {\n /** Returns the parsed value or throws. */\n parse(value: unknown): Op;\n /** Optional non-throwing variant used for aggregated error reporting. */\n safeParse?(value: unknown): { success: true; data: Op } | { success: false; error: unknown };\n}\n\nexport interface OperationDef<Doc, Op extends OperationBase<string> = OperationBase<string>> {\n type: Op['type'];\n schema: OperationSchema<Op>;\n /** Pure: returns the plugin's next document slice. */\n reduce: (slice: Doc, op: Op) => Doc;\n /**\n * Upgrades an op written by an older plugin version. Called with the raw\n * value before validation. Return the op in the current shape.\n */\n migrate?: (fromVersion: number, op: unknown) => unknown;\n}\n\nexport interface PlanContext {\n /** The plugin's resolved options (see `SealpixelPlugin.options`). */\n options?: unknown;\n /** Logical (full-resolution) size at this stage's input. */\n logical: Size;\n /** Actual buffer size at this stage's input. */\n actual: Size;\n /** `actual.width / logical.width`. */\n scale: number;\n /** `truth` or `preview`. Plugins may cheapen work in preview. */\n mode: 'truth' | 'preview';\n}\n\n/**\n * Parameters a plugin contributes to its stage. For a core kernel this is the\n * core stage minus `kind`; stages with the same name are shallow-merged in\n * plugin order, which is how finetune and filter share one `color` stage.\n */\nexport type StageParams = Record<string, unknown>;\n\nexport interface KernelContext {\n logical: Size;\n actual: Size;\n scale: number;\n mode: 'truth' | 'preview';\n /** Resolves a declared asset by id; throws if unknown or hash mismatch. */\n asset: (id: string) => Uint8Array;\n signal: AbortSignal;\n}\n\nexport type KernelDef =\n /** First-party only: the kernel is compiled into the core wasm. */\n | { kind: 'core' }\n /** Plain JavaScript. Determinism is the author's responsibility. */\n | {\n kind: 'js';\n run: (\n image: RgbaBuffer,\n params: StageParams,\n ctx: KernelContext,\n ) => RgbaBuffer | Promise<RgbaBuffer>;\n }\n /** Separate WebAssembly module implementing the kernel ABI. */\n | { kind: 'wasm'; module: () => Promise<WebAssembly.Module>; export?: string };\n\nexport interface AssetDeclaration {\n id: string;\n /** sha256 of the bytes; the resolver verifies it on both client and server. */\n hash: string;\n /** Where the default resolver fetches it from. */\n url?: string;\n}\n\n/**\n * UI contribution. Consumed by `@sealpixel/ui`, which calls the functions with\n * its `UiToolContext`. Parameters are typed `never` here so a plugin can\n * declare the context shape it needs without depending on the UI package.\n */\nexport interface ToolDef {\n id?: string;\n icon: unknown;\n /** i18n key or literal label. */\n label: string;\n panel: (ctx: never) => unknown;\n overlay?: (ctx: never) => unknown;\n activate?: (ctx: never) => void;\n deactivate?: (ctx: never) => void;\n shortcuts?: Record<string, (ctx: never) => void>;\n preview?: (ctx: never) => PreviewHint;\n}\n\nexport type PreviewHint = { css: string } | { none: true };\n\nexport interface ToolContext {\n document: Document;\n dispatch: (op: Operation) => void;\n t: (key: string, params?: Record<string, string | number>) => string;\n}\n\n/** Runtime validator for a plugin's options. Structural so any zod-like schema works. */\nexport interface OptionsSchema<Options> {\n parse(value: unknown): Options;\n safeParse?(value: unknown): { success: true; data: Options } | { success: false; error: unknown };\n}\n\n/** Context handed to `validate`: the resolved options and the slice before the op. */\nexport interface ValidateContext<Doc, Options> {\n options: Options;\n slice: Doc;\n /** All slices as reduced so far. */\n document: Document;\n /** The source image the log belongs to (dimensions in pixels). */\n source: SourceDescriptor;\n}\n\nexport interface ValidateDocumentContext<Options> {\n options: Options;\n document: Document;\n source: SourceDescriptor;\n}\n\nexport interface SealpixelPlugin<Id extends string = string, Doc = unknown, Options = unknown> {\n /** Namespaced id such as `acme.invert`. Op types are `<id>.<verb>`. */\n id: Id;\n /** Bumped when the op schema or the kernel output changes. */\n version: number;\n // biome-ignore lint/suspicious/noExplicitAny: heterogeneous op types are erased at the registry boundary\n operations: ReadonlyArray<OperationDef<Doc, any>>;\n initialDocument: Doc;\n stage: { name: string; order: number };\n /** Returns this plugin's stage parameters, or `null` to contribute nothing. */\n toPlan: (slice: Doc, ctx: PlanContext) => StageParams | null;\n kernel: KernelDef;\n tool?: () => Promise<ToolDef>;\n assets?: AssetDeclaration[];\n /**\n * Resolved options: defaults merged with what `configure()` received.\n * Options tune behaviour and constrain edits; they never carry pixel data\n * so a render never depends on them.\n */\n options?: Options;\n /** Validates a full options object. Used by `configure()` and the docs generator. */\n optionsSchema?: OptionsSchema<Options>;\n /** One-line descriptions per top-level option key, for generated documentation. */\n optionsDescribe?: Readonly<Record<string, string>>;\n /** The defaults `configure()` merges over. */\n optionsDefaults?: Options;\n /** Returns a new plugin instance with `partial` merged over the current options. */\n configure?: (partial: Partial<Options>) => SealpixelPlugin<Id, Doc, Options>;\n /**\n * Constraint check for one operation against the options. Return a message\n * to reject the op (`OPTION_VIOLATION`), or null to accept. Runs in\n * `parseEditLog`, in `session.dispatch` and on the server.\n */\n validate?: (op: Operation, ctx: ValidateContext<Doc, Options>) => string | null;\n /**\n * Constraint check for the final state, for example a locked watermark that\n * must be present. Runs before export and before every server render.\n */\n validateDocument?: (slice: Doc, ctx: ValidateDocumentContext<Options>) => string | null;\n /**\n * Operations the editor dispatches when a source loads with an empty log,\n * so option defaults (a default preset, a locked watermark) become part of\n * the log instead of hidden state. Ids are assigned by the caller.\n */\n initialOps?: (ctx: { options: Options; source: SourceDescriptor }) => Omit<Operation, 'id'>[];\n}\n\n/**\n * A plugin with its document type erased. Registries accept this so plugins\n * with concrete `Doc` types can be mixed in one array.\n */\n// biome-ignore lint/suspicious/noExplicitAny: erased at the registry boundary\nexport type AnyPlugin = SealpixelPlugin<string, any, any>;\n\n/** Core stage kinds a `kernel: { kind: 'core' }` plugin may target. */\nexport type CoreStageName = Stage['kind'];\n"]}
@@ -55,4 +55,3 @@ export interface Registry {
55
55
  initialOps(source: SourceDescriptor): Omit<Operation, 'id'>[];
56
56
  }
57
57
  export declare function createRegistry(plugins: readonly AnyPlugin[]): Registry;
58
- //# sourceMappingURL=registry.d.ts.map
package/dist/registry.js CHANGED
@@ -130,10 +130,19 @@ export function createRegistry(plugins) {
130
130
  });
131
131
  if (issues.length > 0)
132
132
  return { ok: false, issues };
133
+ // Every op of a registered plugin is now in its current schema. Record that
134
+ // version, or the next parse migrates the ops again, including ops appended
135
+ // since in the current schema.
136
+ const plugins = { ...shape.data.plugins };
137
+ for (const [id, written] of Object.entries(plugins)) {
138
+ const plugin = byId.get(id);
139
+ if (plugin && written < plugin.version)
140
+ plugins[id] = plugin.version;
141
+ }
133
142
  const log = {
134
143
  version: 1,
135
144
  source: stripUndefined(shape.data.source),
136
- plugins: { ...shape.data.plugins },
145
+ plugins,
137
146
  ...(shape.data.assets
138
147
  ? { assets: shape.data.assets.map((a) => stripUndefined(a)) }
139
148
  : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AA0D7C,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACrB,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IAClC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE;IACnC,IAAI,EAAE,CAAC;SACJ,MAAM,EAAE;SACR,KAAK,CAAC,gBAAgB,CAAC;SACvB,QAAQ,EAAE;IACb,QAAQ,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AAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;IACnC,CAAC;AACH,CAAC;AAED,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC5D,MAAM,MAAM,GAAI,KAAgE,CAAC,MAAM,CAAC;QACxF,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,QAAQ,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAmB,KAAQ;IAChD,OAAO,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAM,CAAC;AAC3F,CAAC","sourcesContent":["import { z } from 'zod';\nimport { SealpixelError } from './errors.js';\nimport type { AnyPlugin, AssetDeclaration, Document, OperationDef } from './plugin.js';\nimport type { EditLog, Operation, SourceDescriptor } from './types.js';\n\nexport interface ParseOptions {\n /**\n * Keep ops whose type is unknown instead of failing. They are ignored by\n * `compile`. Only for forward-compatible previews; servers must not set it.\n */\n tolerateUnknown?: boolean;\n}\n\nexport interface ParseIssue {\n /** Index into `ops`, or -1 for a top-level problem. */\n index: number;\n code: 'INVALID_EDIT_LOG' | 'UNKNOWN_PLUGIN' | 'UNKNOWN_OPERATION' | 'OPTION_VIOLATION';\n message: string;\n}\n\nexport type ParseResult = { ok: true; log: EditLog } | { ok: false; issues: ParseIssue[] };\n\nexport interface RegisteredOperation {\n plugin: AnyPlugin;\n // biome-ignore lint/suspicious/noExplicitAny: erased at the registry boundary\n def: OperationDef<any, any>;\n}\n\n/** Plugins plus everything derived from them: schemas, reducers, stage order. */\nexport interface Registry {\n /** Sorted by stage order, then id. */\n readonly plugins: readonly AnyPlugin[];\n readonly byId: ReadonlyMap<string, AnyPlugin>;\n readonly byOpType: ReadonlyMap<string, RegisteredOperation>;\n /** `{ pluginId: version }` for every registered plugin. */\n pluginVersions(): Record<string, number>;\n initialDocument(): Document;\n /** Validates and migrates an unknown value into an `EditLog`. Throws `SealpixelError`. */\n parseEditLog(value: unknown, options?: ParseOptions): EditLog;\n safeParseEditLog(value: unknown, options?: ParseOptions): ParseResult;\n /**\n * Runs the owning plugin's `validate` for one op against the document it\n * would apply to. Returns the violation message, or null.\n */\n validateOperation(op: Operation, document: Document, source: SourceDescriptor): string | null;\n /**\n * Runs every plugin's `validateDocument` over a compiled document. Returns\n * all violations; empty when the state satisfies the configured options.\n */\n validateDocument(\n document: Document,\n source: SourceDescriptor,\n ): { plugin: string; message: string }[];\n /** `{ pluginId: options }` for every plugin with options. */\n pluginOptions(): Record<string, unknown>;\n /** Ops that seed an empty log from option defaults, in stage order. */\n initialOps(source: SourceDescriptor): Omit<Operation, 'id'>[];\n}\n\nconst SourceSchema = z.object({\n id: z.string().min(1),\n width: z.number().int().positive(),\n height: z.number().int().positive(),\n hash: z\n .string()\n .regex(/^[0-9a-f]{64}$/)\n .optional(),\n mimeType: z.string().optional(),\n});\n\nconst AssetSchema = z\n .object({\n id: z.string().min(1),\n hash: z.string().regex(/^[0-9a-f]{64}$/),\n url: z.string().min(1).optional(),\n })\n .strict();\n\nconst LogShape = z.object({\n version: z.literal(1),\n source: SourceSchema,\n plugins: z.record(z.string(), z.number().int().positive()).default({}),\n assets: z.array(AssetSchema).max(1000).optional(),\n ops: z.array(z.unknown()).default([]),\n});\n\nexport function createRegistry(plugins: readonly AnyPlugin[]): Registry {\n const byId = new Map<string, AnyPlugin>();\n const byOpType = new Map<string, RegisteredOperation>();\n for (const plugin of plugins) {\n if (byId.has(plugin.id)) {\n throw new SealpixelError('INVALID_EDIT_LOG', `plugin \"${plugin.id}\" registered twice`);\n }\n byId.set(plugin.id, plugin);\n for (const def of plugin.operations) {\n if (byOpType.has(def.type)) {\n throw new SealpixelError('INVALID_EDIT_LOG', `operation \"${def.type}\" registered twice`);\n }\n byOpType.set(def.type, { plugin, def });\n }\n }\n const sorted = [...plugins].sort(\n (a, b) => a.stage.order - b.stage.order || a.id.localeCompare(b.id),\n );\n const initialDocument = () =>\n Object.fromEntries(sorted.map((p) => [p.id, p.initialDocument])) as Document;\n\n const validateOperation = (\n op: Operation,\n document: Document,\n source: SourceDescriptor,\n ): string | null => {\n const entry = byOpType.get(op.type);\n if (!entry?.plugin.validate) return null;\n const slice = (document as Record<string, unknown>)[entry.plugin.id];\n return entry.plugin.validate(op, { options: entry.plugin.options, slice, document, source });\n };\n\n const validateDocument = (document: Document, source: SourceDescriptor) => {\n const out: { plugin: string; message: string }[] = [];\n for (const plugin of sorted) {\n if (!plugin.validateDocument) continue;\n const slice = (document as Record<string, unknown>)[plugin.id];\n const message = plugin.validateDocument(slice, { options: plugin.options, document, source });\n if (message) out.push({ plugin: plugin.id, message });\n }\n return out;\n };\n\n const safeParseEditLog = (value: unknown, options: ParseOptions = {}): ParseResult => {\n const shape = LogShape.safeParse(value);\n if (!shape.success) {\n return {\n ok: false,\n issues: shape.error.issues.map((i) => ({\n index: -1,\n code: 'INVALID_EDIT_LOG',\n message: `${i.path.join('.') || '(root)'}: ${i.message}`,\n })),\n };\n }\n const issues: ParseIssue[] = [];\n const ops: Operation[] = [];\n // Slices reduced so far, so constraints can look at the state an op applies to.\n const document = initialDocument() as Record<string, unknown>;\n shape.data.ops.forEach((raw, index) => {\n const type =\n typeof raw === 'object' && raw !== null ? (raw as { type?: unknown }).type : undefined;\n if (typeof type !== 'string') {\n issues.push({ index, code: 'INVALID_EDIT_LOG', message: 'op has no string \"type\"' });\n return;\n }\n const entry = byOpType.get(type);\n if (!entry) {\n if (options.tolerateUnknown) {\n ops.push(raw as Operation);\n return;\n }\n const pluginId = type.slice(0, type.lastIndexOf('.'));\n issues.push(\n byId.has(pluginId)\n ? { index, code: 'UNKNOWN_OPERATION', message: `unknown operation \"${type}\"` }\n : { index, code: 'UNKNOWN_PLUGIN', message: `plugin \"${pluginId}\" is not registered` },\n );\n return;\n }\n const written = shape.data.plugins[entry.plugin.id];\n let candidate: unknown = raw;\n if (written !== undefined && written < entry.plugin.version) {\n if (!entry.def.migrate) {\n issues.push({\n index,\n code: 'INVALID_EDIT_LOG',\n message: `op \"${type}\" was written by ${entry.plugin.id} v${written}; v${entry.plugin.version} has no migration`,\n });\n return;\n }\n candidate = entry.def.migrate(written, raw);\n }\n const parsed = entry.def.schema.safeParse\n ? entry.def.schema.safeParse(candidate)\n : tryParse(entry.def.schema.parse, candidate);\n if (parsed.success) {\n const op = parsed.data as Operation;\n const violation = validateOperation(\n op,\n document as Document,\n stripUndefined(shape.data.source) as SourceDescriptor,\n );\n if (violation) {\n issues.push({ index, code: 'OPTION_VIOLATION', message: `op \"${type}\": ${violation}` });\n return;\n }\n ops.push(op);\n document[entry.plugin.id] = entry.def.reduce(document[entry.plugin.id], op);\n } else {\n issues.push({\n index,\n code: 'INVALID_EDIT_LOG',\n message: `op \"${type}\": ${describeError(parsed.error)}`,\n });\n }\n });\n if (issues.length > 0) return { ok: false, issues };\n // Every op of a registered plugin is now in its current schema. Record that\n // version, or the next parse migrates the ops again, including ops appended\n // since in the current schema.\n const plugins = { ...shape.data.plugins };\n for (const [id, written] of Object.entries(plugins)) {\n const plugin = byId.get(id);\n if (plugin && written < plugin.version) plugins[id] = plugin.version;\n }\n const log: EditLog = {\n version: 1,\n source: stripUndefined(shape.data.source) as SourceDescriptor,\n plugins,\n ...(shape.data.assets\n ? { assets: shape.data.assets.map((a) => stripUndefined(a) as AssetDeclaration) }\n : {}),\n ops,\n };\n return { ok: true, log };\n };\n\n return {\n plugins: sorted,\n byId,\n byOpType,\n pluginVersions: () => Object.fromEntries(sorted.map((p) => [p.id, p.version])),\n pluginOptions: () =>\n Object.fromEntries(\n sorted.filter((p) => p.options !== undefined).map((p) => [p.id, p.options]),\n ),\n initialDocument,\n initialOps: (source) =>\n sorted.flatMap((p) => p.initialOps?.({ options: p.options, source }) ?? []),\n validateOperation,\n validateDocument,\n safeParseEditLog,\n parseEditLog: (value, options) => {\n const result = safeParseEditLog(value, options);\n if (result.ok) return result.log;\n const first = result.issues[0];\n const code = result.issues.every((i) => i.code === 'UNKNOWN_PLUGIN')\n ? 'UNKNOWN_PLUGIN'\n : result.issues.some((i) => i.code === 'OPTION_VIOLATION')\n ? 'OPTION_VIOLATION'\n : 'INVALID_EDIT_LOG';\n throw new SealpixelError(\n code,\n first ? `${first.message}` : 'invalid edit log',\n result.issues,\n );\n },\n };\n}\n\nfunction tryParse<T>(\n parse: (v: unknown) => T,\n value: unknown,\n): { success: true; data: T } | { success: false; error: unknown } {\n try {\n return { success: true, data: parse(value) };\n } catch (error) {\n return { success: false, error };\n }\n}\n\nfunction describeError(error: unknown): string {\n if (error && typeof error === 'object' && 'issues' in error) {\n const issues = (error as { issues: { path: PropertyKey[]; message: string }[] }).issues;\n return issues.map((i) => `${i.path.join('.') || '(root)'}: ${i.message}`).join('; ');\n }\n return error instanceof Error ? error.message : String(error);\n}\n\nfunction stripUndefined<T extends object>(value: T): T {\n return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined)) as T;\n}\n"]}
package/dist/render.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { type RgbaBuffer, type SealpixelWasm } from '@sealpixel/wasm';
2
+ import { type RenderPlan, type Stage } from './plan.js';
2
3
  import { type Registry } from './registry.js';
3
4
  import type { EditLog, OutputOptions, RenderOptions, RenderResult, RenderSource } from './types.js';
4
5
  /**
@@ -20,6 +21,25 @@ export interface PipelineOptions {
20
21
  * call, every external kernel runs in between on the RGBA buffer.
21
22
  */
22
23
  export declare function runPipeline(wasm: SealpixelWasm, registry: Registry, image: RgbaBuffer, log: EditLog, options: PipelineOptions): Promise<RgbaBuffer>;
24
+ /**
25
+ * The core plan of a truth render of `ops[0..upTo)`, when every stage runs in
26
+ * the core, and otherwise the stages that run outside it. What a render
27
+ * manifest records, and what a C2PA manifest definition is made from.
28
+ */
29
+ export declare function compileCorePlan(log: EditLog, registry: Registry, upTo?: number): {
30
+ /** The one core plan, when every stage runs in the core. */
31
+ plan?: RenderPlan;
32
+ /** The core stages in order, whatever runs between them. */
33
+ coreStages: Stage[];
34
+ kernels: {
35
+ name: string;
36
+ order: number;
37
+ }[];
38
+ };
23
39
  /** Maps the public output options onto the Rust `OutputOptions` JSON. */
24
40
  export declare function toCoreOutput(output: OutputOptions): Record<string, unknown>;
25
- //# sourceMappingURL=render.d.ts.map
41
+ /**
42
+ * The inverse of `toCoreOutput`, for the options a render manifest records.
43
+ * `embed` is not an option here: `embedEditLog` regenerates it from the log.
44
+ */
45
+ export declare function fromCoreOutput(core: Record<string, unknown>): OutputOptions;