@wasm-gaming/engine-specs 0.2.7 → 0.3.1

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 (48) hide show
  1. package/README.md +63 -54
  2. package/demo/app.html +227 -0
  3. package/demo/canvas-renderer.js +153 -0
  4. package/demo/components/asset-picker.html +137 -0
  5. package/demo/components/call-log.html +33 -0
  6. package/demo/components/engine-header.html +78 -0
  7. package/demo/components/lifecycle-bar.html +69 -0
  8. package/demo/components/property-table.html +119 -0
  9. package/demo/demo.css +26 -130
  10. package/demo/demo.sdk.js +405 -203
  11. package/demo/index.html +7 -56
  12. package/demo/tsconfig.json +17 -0
  13. package/dist/engine-specs.d.ts +106 -0
  14. package/dist/engine-specs.d.ts.map +1 -0
  15. package/dist/engine-specs.js +3 -0
  16. package/dist/engine-specs.js.map +1 -0
  17. package/package.json +7 -12
  18. package/src/engine-specs.ts +117 -0
  19. package/demo/README.md +0 -155
  20. package/demo/checksums.js +0 -101
  21. package/demo/components/drop-area.html +0 -171
  22. package/demo/components/esc-menu.html +0 -540
  23. package/demo/components/launcher.html +0 -220
  24. package/demo/components/sdk-info.html +0 -54
  25. package/demo/demo.js +0 -622
  26. package/demo/sdk.js +0 -19
  27. package/demo/storage.js +0 -88
  28. package/dist/engine.d.ts +0 -427
  29. package/dist/engine.d.ts.map +0 -1
  30. package/dist/engine.js +0 -83
  31. package/dist/engine.js.map +0 -1
  32. package/dist/index.d.ts +0 -13
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/index.js +0 -12
  35. package/dist/index.js.map +0 -1
  36. package/dist/manifest.d.ts +0 -69
  37. package/dist/manifest.d.ts.map +0 -1
  38. package/dist/manifest.js +0 -8
  39. package/dist/manifest.js.map +0 -1
  40. package/dist/validate.d.ts +0 -10
  41. package/dist/validate.d.ts.map +0 -1
  42. package/dist/validate.js +0 -79
  43. package/dist/validate.js.map +0 -1
  44. package/schema/engine-manifest.schema.json +0 -74
  45. package/src/engine.ts +0 -516
  46. package/src/index.ts +0 -55
  47. package/src/manifest.ts +0 -82
  48. package/src/validate.ts +0 -92
package/src/validate.ts DELETED
@@ -1,92 +0,0 @@
1
- // Runtime validation of an EngineManifest against the contract.
2
- // Engine CIs can run this to fail a build that drifts from the spec; hosts can run
3
- // it on manifests fetched from Releases before trusting them.
4
-
5
- import { z } from 'zod';
6
- import type { EngineManifest } from './manifest.js';
7
-
8
- export interface ValidationResult {
9
- valid: boolean;
10
- errors: string[];
11
- }
12
-
13
- const AssetValidationSchema = z.object({
14
- bytes: z.int().nonnegative().optional(),
15
- sha1: z.string().optional(),
16
- }).strict();
17
-
18
- const AssetSpecSchema = z.object({
19
- key: z.string().min(1),
20
- mountPath: z.string().regex(/^\//),
21
- required: z.boolean(),
22
- accept: z.array(z.string()).optional(),
23
- validate: AssetValidationSchema.optional(),
24
- description: z.string().optional(),
25
- }).strict();
26
-
27
- const InputSchema = z.union([
28
- z.string(),
29
- z.record(z.string(), z.string()),
30
- ]);
31
-
32
- const VideoSpecSchema = z.object({
33
- baseWidth: z.int().positive(),
34
- baseHeight: z.int().positive(),
35
- aspect: z.string().optional(),
36
- }).strict();
37
-
38
- const EngineArtifactsSchema = z.object({
39
- wasm: z.string(),
40
- js: z.string(),
41
- data: z.string().optional(),
42
- }).strict();
43
-
44
- const EngineCapabilitiesSchema = z.object({
45
- saveStates: z.boolean().optional(),
46
- sram: z.boolean().optional(),
47
- coreSelectable: z.boolean().optional(),
48
- }).strict();
49
-
50
- const EngineManifestSchema = z.object({
51
- id: z.string().min(1),
52
- version: z.string().min(1),
53
- name: z.string().optional(),
54
- description: z.string().optional(),
55
- artifacts: EngineArtifactsSchema,
56
- assets: z.array(AssetSpecSchema),
57
- input: InputSchema,
58
- video: VideoSpecSchema,
59
- options: z.record(z.string(), z.unknown()).optional(),
60
- capabilities: EngineCapabilitiesSchema,
61
- }).strict();
62
-
63
- function formatIssuePath(path: PropertyKey[]): string {
64
- if (path.length === 0) return 'manifest';
65
-
66
- let out = 'manifest';
67
- for (const part of path) {
68
- if (typeof part === 'number') out += `[${part}]`;
69
- else if (typeof part === 'string') out += `.${part}`;
70
- else out += '.[symbol]';
71
- }
72
- return out;
73
- }
74
-
75
- /** Validate an unknown value as an EngineManifest. Never throws. */
76
- export function validateManifest(input: unknown): ValidationResult {
77
- const result = EngineManifestSchema.safeParse(input);
78
- if (result.success) return { valid: true, errors: [] };
79
-
80
- const errors = result.error.issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`);
81
- return { valid: false, errors };
82
- }
83
-
84
- /** Validate and throw on failure. Returns the value narrowed to EngineManifest. */
85
- export function assertManifest(input: unknown): EngineManifest {
86
- const result = EngineManifestSchema.safeParse(input);
87
- if (!result.success) {
88
- const errors = result.error.issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`);
89
- throw new Error(`Invalid EngineManifest:\n- ${errors.join('\n- ')}`);
90
- }
91
- return result.data as EngineManifest;
92
- }