@dreamboard-games/sdk 0.4.0-alpha.0 → 0.4.0-alpha.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.
- package/README.md +8 -1
- package/REFERENCE.md +488 -108
- package/dist/attributes-BrZtP9az.d.ts +53 -0
- package/dist/browser-interaction.d.ts +44 -42
- package/dist/browser-interaction.js +2 -1
- package/dist/{chunk-4G7552LO.js → chunk-3K362ZKR.js} +17 -12
- package/dist/chunk-3K362ZKR.js.map +1 -0
- package/dist/{chunk-U5KBV2BA.js → chunk-7LZZEI25.js} +444 -223
- package/dist/chunk-7LZZEI25.js.map +1 -0
- package/dist/{chunk-Q5O7GPVY.js → chunk-7W6TQO3X.js} +18 -10
- package/dist/chunk-7W6TQO3X.js.map +1 -0
- package/dist/chunk-AEUXCFGM.js +124 -0
- package/dist/chunk-AEUXCFGM.js.map +1 -0
- package/dist/{chunk-P7F4L2FF.js → chunk-CZMFAS3E.js} +327 -248
- package/dist/chunk-CZMFAS3E.js.map +1 -0
- package/dist/{chunk-MNKDSGIA.js → chunk-IUGKW2GS.js} +2 -2
- package/dist/{chunk-MNKDSGIA.js.map → chunk-IUGKW2GS.js.map} +1 -1
- package/dist/{chunk-QLG6VEMW.js → chunk-MALRKLRR.js} +19 -11
- package/dist/chunk-MALRKLRR.js.map +1 -0
- package/dist/{chunk-2LDZ5C3T.js → chunk-XJYUSD5F.js} +2 -2
- package/dist/{chunk-NBAEEHAU.js → chunk-XXBSIPJX.js} +5952 -5364
- package/dist/chunk-XXBSIPJX.js.map +1 -0
- package/dist/codegen.d.ts +3 -1
- package/dist/codegen.js +1 -1
- package/dist/{components-DaIqi9QM.d.ts → components-Dqr_LuZJ.d.ts} +1 -65
- package/dist/index.js +1 -1
- package/dist/package-set.d.ts +2 -2
- package/dist/package-set.js +1 -1
- package/dist/reducer/advanced.d.ts +2 -2
- package/dist/reducer/advanced.js +1 -1
- package/dist/reducer-contract.js +1 -1
- package/dist/reducer.d.ts +7 -7
- package/dist/reducer.js +190 -183
- package/dist/reducer.js.map +1 -1
- package/dist/runtime/primitives.d.ts +4 -3
- package/dist/runtime/primitives.js +5 -4
- package/dist/runtime/workspace-contract.d.ts +10 -69
- package/dist/runtime/workspace-contract.js +6 -5
- package/dist/runtime-json-CQ9QbLZ5.d.ts +5 -0
- package/dist/runtime.d.ts +70 -5
- package/dist/runtime.js +483 -129
- package/dist/runtime.js.map +1 -1
- package/dist/testing.d.ts +509 -2
- package/dist/testing.js +481 -1
- package/dist/testing.js.map +1 -1
- package/dist/{attributes-BeRyboMS.d.ts → types-BqzHkNMA.d.ts} +1 -51
- package/dist/types.d.ts +4 -2
- package/dist/ui/components.d.ts +1 -1
- package/dist/ui/components.js +1 -1
- package/dist/ui/plugin-styles.css +1 -1
- package/dist/{ui-contract-BUC6iS3s.d.ts → ui-contract-W2-kxObe.d.ts} +2 -1
- package/dist/ui.d.ts +3 -7
- package/dist/ui.js +2 -2
- package/dist/{views-B0hlW6IT.d.ts → views-fn2RuXOx.d.ts} +59 -44
- package/package.json +31 -13
- package/dist/chunk-4G7552LO.js.map +0 -1
- package/dist/chunk-NBAEEHAU.js.map +0 -1
- package/dist/chunk-P7F4L2FF.js.map +0 -1
- package/dist/chunk-Q5O7GPVY.js.map +0 -1
- package/dist/chunk-QLG6VEMW.js.map +0 -1
- package/dist/chunk-U5KBV2BA.js.map +0 -1
- /package/dist/{chunk-2LDZ5C3T.js.map → chunk-XJYUSD5F.js.map} +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
// src/runtime-json.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
var JsonValidationError = class extends Error {
|
|
4
|
+
constructor(code, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.code = code;
|
|
7
|
+
this.name = "JsonValidationError";
|
|
8
|
+
}
|
|
9
|
+
code;
|
|
10
|
+
};
|
|
11
|
+
var TRANSPORT_JSON_LIMITS = {
|
|
12
|
+
maxDepth: 64,
|
|
13
|
+
maxNodes: 1e5,
|
|
14
|
+
maxStringBytes: 1048576,
|
|
15
|
+
maxCollectionEntries: 5e4
|
|
16
|
+
};
|
|
17
|
+
var BROWSER_ATTRIBUTE_JSON_LIMITS = {
|
|
18
|
+
maxDepth: 32,
|
|
19
|
+
maxNodes: 1e4,
|
|
20
|
+
maxStringBytes: 65536,
|
|
21
|
+
maxCollectionEntries: 5e3
|
|
22
|
+
};
|
|
23
|
+
function jsonError(code, label, detail) {
|
|
24
|
+
return new JsonValidationError(code, `${label} ${detail}.`);
|
|
25
|
+
}
|
|
26
|
+
function requirePlainObject(value, label) {
|
|
27
|
+
const prototype = Object.getPrototypeOf(value);
|
|
28
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
29
|
+
throw jsonError("non-json", label, "contains a non-plain object");
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
function assertJsonWithinLimits(root, limits, label) {
|
|
34
|
+
const stack = [
|
|
35
|
+
{ value: root, depth: 0 }
|
|
36
|
+
];
|
|
37
|
+
const seen = /* @__PURE__ */ new WeakSet();
|
|
38
|
+
const encoder = new TextEncoder();
|
|
39
|
+
let nodes = 0;
|
|
40
|
+
let stringBytes = 0;
|
|
41
|
+
let collectionEntries = 0;
|
|
42
|
+
while (stack.length > 0) {
|
|
43
|
+
const item = stack.pop();
|
|
44
|
+
if (!item) continue;
|
|
45
|
+
const { value, depth } = item;
|
|
46
|
+
nodes += 1;
|
|
47
|
+
if (nodes > limits.maxNodes) {
|
|
48
|
+
throw jsonError("nodes", label, "exceeds the node limit");
|
|
49
|
+
}
|
|
50
|
+
if (depth > limits.maxDepth) {
|
|
51
|
+
throw jsonError("depth", label, "exceeds the depth limit");
|
|
52
|
+
}
|
|
53
|
+
switch (typeof value) {
|
|
54
|
+
case "string":
|
|
55
|
+
stringBytes += encoder.encode(value).byteLength;
|
|
56
|
+
if (stringBytes > limits.maxStringBytes) {
|
|
57
|
+
throw jsonError(
|
|
58
|
+
"string-bytes",
|
|
59
|
+
label,
|
|
60
|
+
"exceeds the string-byte limit"
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
continue;
|
|
64
|
+
case "number":
|
|
65
|
+
if (!Number.isFinite(value)) {
|
|
66
|
+
throw jsonError("non-json", label, "contains a non-finite number");
|
|
67
|
+
}
|
|
68
|
+
continue;
|
|
69
|
+
case "boolean":
|
|
70
|
+
continue;
|
|
71
|
+
case "object":
|
|
72
|
+
if (value === null) continue;
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
throw jsonError("non-json", label, "contains a non-JSON value");
|
|
76
|
+
}
|
|
77
|
+
if (seen.has(value)) {
|
|
78
|
+
throw jsonError("cycle", label, "contains a cycle");
|
|
79
|
+
}
|
|
80
|
+
seen.add(value);
|
|
81
|
+
const children = Array.isArray(value) ? value : Object.values(requirePlainObject(value, label));
|
|
82
|
+
collectionEntries += children.length;
|
|
83
|
+
if (collectionEntries > limits.maxCollectionEntries) {
|
|
84
|
+
throw jsonError(
|
|
85
|
+
"collection-entries",
|
|
86
|
+
label,
|
|
87
|
+
"exceeds the collection-entry limit"
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
for (const child of children) {
|
|
91
|
+
stack.push({ value: child, depth: depth + 1 });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
var RuntimeJsonSchema = z.lazy(
|
|
96
|
+
() => z.union([
|
|
97
|
+
z.null(),
|
|
98
|
+
z.boolean(),
|
|
99
|
+
z.number().finite(),
|
|
100
|
+
z.string(),
|
|
101
|
+
z.array(RuntimeJsonSchema),
|
|
102
|
+
z.record(z.string(), RuntimeJsonSchema)
|
|
103
|
+
])
|
|
104
|
+
);
|
|
105
|
+
function parseJsonWithLimits(value, limits, label) {
|
|
106
|
+
assertJsonWithinLimits(value, limits, label);
|
|
107
|
+
return RuntimeJsonSchema.parse(value);
|
|
108
|
+
}
|
|
109
|
+
function parseBrowserAttributeJson(value) {
|
|
110
|
+
return parseJsonWithLimits(
|
|
111
|
+
value,
|
|
112
|
+
BROWSER_ATTRIBUTE_JSON_LIMITS,
|
|
113
|
+
"Browser interaction attribute"
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export {
|
|
118
|
+
TRANSPORT_JSON_LIMITS,
|
|
119
|
+
BROWSER_ATTRIBUTE_JSON_LIMITS,
|
|
120
|
+
assertJsonWithinLimits,
|
|
121
|
+
RuntimeJsonSchema,
|
|
122
|
+
parseBrowserAttributeJson
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=chunk-AEUXCFGM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/runtime-json.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport type RuntimeJson =\n | null\n | boolean\n | number\n | string\n | RuntimeJson[]\n | { [key: string]: RuntimeJson };\n\nexport type JsonLimits = {\n maxDepth: number;\n maxNodes: number;\n maxStringBytes: number;\n maxCollectionEntries: number;\n};\n\nexport type JsonValidationCode =\n | \"cycle\"\n | \"depth\"\n | \"nodes\"\n | \"string-bytes\"\n | \"collection-entries\"\n | \"non-json\";\n\nexport class JsonValidationError extends Error {\n constructor(\n public readonly code: JsonValidationCode,\n message: string,\n ) {\n super(message);\n this.name = \"JsonValidationError\";\n }\n}\n\nexport const TRANSPORT_JSON_LIMITS = {\n maxDepth: 64,\n maxNodes: 100_000,\n maxStringBytes: 1_048_576,\n maxCollectionEntries: 50_000,\n} as const satisfies JsonLimits;\n\nexport const BROWSER_ATTRIBUTE_JSON_LIMITS = {\n maxDepth: 32,\n maxNodes: 10_000,\n maxStringBytes: 65_536,\n maxCollectionEntries: 5_000,\n} as const satisfies JsonLimits;\n\nfunction jsonError(\n code: JsonValidationCode,\n label: string,\n detail: string,\n): JsonValidationError {\n return new JsonValidationError(code, `${label} ${detail}.`);\n}\n\nfunction requirePlainObject(\n value: object,\n label: string,\n): Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw jsonError(\"non-json\", label, \"contains a non-plain object\");\n }\n return value as Record<string, unknown>;\n}\n\nexport function assertJsonWithinLimits(\n root: unknown,\n limits: JsonLimits,\n label: string,\n): void {\n const stack: Array<{ value: unknown; depth: number }> = [\n { value: root, depth: 0 },\n ];\n const seen = new WeakSet<object>();\n const encoder = new TextEncoder();\n let nodes = 0;\n let stringBytes = 0;\n let collectionEntries = 0;\n\n while (stack.length > 0) {\n const item = stack.pop();\n if (!item) continue;\n const { value, depth } = item;\n\n nodes += 1;\n if (nodes > limits.maxNodes) {\n throw jsonError(\"nodes\", label, \"exceeds the node limit\");\n }\n if (depth > limits.maxDepth) {\n throw jsonError(\"depth\", label, \"exceeds the depth limit\");\n }\n\n switch (typeof value) {\n case \"string\":\n stringBytes += encoder.encode(value).byteLength;\n if (stringBytes > limits.maxStringBytes) {\n throw jsonError(\n \"string-bytes\",\n label,\n \"exceeds the string-byte limit\",\n );\n }\n continue;\n case \"number\":\n if (!Number.isFinite(value)) {\n throw jsonError(\"non-json\", label, \"contains a non-finite number\");\n }\n continue;\n case \"boolean\":\n continue;\n case \"object\":\n if (value === null) continue;\n break;\n default:\n throw jsonError(\"non-json\", label, \"contains a non-JSON value\");\n }\n\n if (seen.has(value)) {\n throw jsonError(\"cycle\", label, \"contains a cycle\");\n }\n seen.add(value);\n\n const children = Array.isArray(value)\n ? value\n : Object.values(requirePlainObject(value, label));\n collectionEntries += children.length;\n if (collectionEntries > limits.maxCollectionEntries) {\n throw jsonError(\n \"collection-entries\",\n label,\n \"exceeds the collection-entry limit\",\n );\n }\n for (const child of children) {\n stack.push({ value: child, depth: depth + 1 });\n }\n }\n}\n\nexport const RuntimeJsonSchema: z.ZodType<RuntimeJson> = z.lazy(() =>\n z.union([\n z.null(),\n z.boolean(),\n z.number().finite(),\n z.string(),\n z.array(RuntimeJsonSchema),\n z.record(z.string(), RuntimeJsonSchema),\n ]),\n);\n\nexport function parseJsonWithLimits(\n value: unknown,\n limits: JsonLimits,\n label: string,\n): RuntimeJson {\n assertJsonWithinLimits(value, limits, label);\n return RuntimeJsonSchema.parse(value);\n}\n\nexport function parseTransportJson(value: unknown): RuntimeJson {\n return parseJsonWithLimits(value, TRANSPORT_JSON_LIMITS, \"Runtime payload\");\n}\n\nexport function parseBrowserAttributeJson(value: unknown): RuntimeJson {\n return parseJsonWithLimits(\n value,\n BROWSER_ATTRIBUTE_JSON_LIMITS,\n \"Browser interaction attribute\",\n );\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAyBX,IAAM,sBAAN,cAAkC,MAAM;AAAA,EAC7C,YACkB,MAChB,SACA;AACA,UAAM,OAAO;AAHG;AAIhB,SAAK,OAAO;AAAA,EACd;AAAA,EALkB;AAMpB;AAEO,IAAM,wBAAwB;AAAA,EACnC,UAAU;AAAA,EACV,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,sBAAsB;AACxB;AAEO,IAAM,gCAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,UAAU;AAAA,EACV,gBAAgB;AAAA,EAChB,sBAAsB;AACxB;AAEA,SAAS,UACP,MACA,OACA,QACqB;AACrB,SAAO,IAAI,oBAAoB,MAAM,GAAG,KAAK,IAAI,MAAM,GAAG;AAC5D;AAEA,SAAS,mBACP,OACA,OACyB;AACzB,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,MAAI,cAAc,OAAO,aAAa,cAAc,MAAM;AACxD,UAAM,UAAU,YAAY,OAAO,6BAA6B;AAAA,EAClE;AACA,SAAO;AACT;AAEO,SAAS,uBACd,MACA,QACA,OACM;AACN,QAAM,QAAkD;AAAA,IACtD,EAAE,OAAO,MAAM,OAAO,EAAE;AAAA,EAC1B;AACA,QAAM,OAAO,oBAAI,QAAgB;AACjC,QAAM,UAAU,IAAI,YAAY;AAChC,MAAI,QAAQ;AACZ,MAAI,cAAc;AAClB,MAAI,oBAAoB;AAExB,SAAO,MAAM,SAAS,GAAG;AACvB,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