@1upvision/sdk 0.1.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/dist/bridge/worker-bridge.d.ts +17 -0
- package/dist/bridge/worker-bridge.d.ts.map +1 -0
- package/dist/bridge/worker-bridge.js +85 -0
- package/dist/components/Box.d.ts +8 -0
- package/dist/components/Box.d.ts.map +1 -0
- package/dist/components/Box.js +4 -0
- package/dist/components/Button.d.ts +11 -0
- package/dist/components/Button.d.ts.map +1 -0
- package/dist/components/Button.js +4 -0
- package/dist/components/CompactView.d.ts +9 -0
- package/dist/components/CompactView.d.ts.map +1 -0
- package/dist/components/CompactView.js +4 -0
- package/dist/components/Dropdown.d.ts +15 -0
- package/dist/components/Dropdown.d.ts.map +1 -0
- package/dist/components/Dropdown.js +4 -0
- package/dist/components/Image.d.ts +11 -0
- package/dist/components/Image.d.ts.map +1 -0
- package/dist/components/Image.js +4 -0
- package/dist/components/List.d.ts +9 -0
- package/dist/components/List.d.ts.map +1 -0
- package/dist/components/List.js +4 -0
- package/dist/components/NumberField.d.ts +14 -0
- package/dist/components/NumberField.d.ts.map +1 -0
- package/dist/components/NumberField.js +4 -0
- package/dist/components/Text.d.ts +9 -0
- package/dist/components/Text.d.ts.map +1 -0
- package/dist/components/Text.js +4 -0
- package/dist/components/TextArea.d.ts +13 -0
- package/dist/components/TextArea.d.ts.map +1 -0
- package/dist/components/TextArea.js +4 -0
- package/dist/components/TextField.d.ts +12 -0
- package/dist/components/TextField.d.ts.map +1 -0
- package/dist/components/TextField.js +4 -0
- package/dist/components/Toggle.d.ts +11 -0
- package/dist/components/Toggle.d.ts.map +1 -0
- package/dist/components/Toggle.js +4 -0
- package/dist/components/index.d.ts +23 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/index.js +11 -0
- package/dist/hooks/useExtensionContext.d.ts +7 -0
- package/dist/hooks/useExtensionContext.d.ts.map +1 -0
- package/dist/hooks/useExtensionContext.js +11 -0
- package/dist/hooks/useExtensionStorage.d.ts +5 -0
- package/dist/hooks/useExtensionStorage.d.ts.map +1 -0
- package/dist/hooks/useExtensionStorage.js +30 -0
- package/dist/hooks/useVisionState.d.ts +2 -0
- package/dist/hooks/useVisionState.d.ts.map +1 -0
- package/dist/hooks/useVisionState.js +3 -0
- package/dist/index.d.ts +29 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/renderer/callback-registry.d.ts +9 -0
- package/dist/renderer/callback-registry.d.ts.map +1 -0
- package/dist/renderer/callback-registry.js +24 -0
- package/dist/renderer/reconciler.d.ts +23 -0
- package/dist/renderer/reconciler.d.ts.map +1 -0
- package/dist/renderer/reconciler.js +333 -0
- package/dist/renderer/render.d.ts +10 -0
- package/dist/renderer/render.d.ts.map +1 -0
- package/dist/renderer/render.js +38 -0
- package/dist/server/functions.d.ts +81 -0
- package/dist/server/functions.d.ts.map +1 -0
- package/dist/server/functions.js +31 -0
- package/dist/server/index.d.ts +7 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +3 -0
- package/dist/server/schema.d.ts +30 -0
- package/dist/server/schema.d.ts.map +1 -0
- package/dist/server/schema.js +35 -0
- package/dist/server/validators.d.ts +28 -0
- package/dist/server/validators.d.ts.map +1 -0
- package/dist/server/validators.js +126 -0
- package/dist/worker-runtime.js +9342 -0
- package/package.json +47 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export class ValidationError extends Error {
|
|
2
|
+
path;
|
|
3
|
+
constructor(message, path = "$") {
|
|
4
|
+
super(`${path}: ${message}`);
|
|
5
|
+
this.path = path;
|
|
6
|
+
this.name = "ValidationError";
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function createValidator(kind, parseFn, isOptional = false) {
|
|
10
|
+
return {
|
|
11
|
+
kind,
|
|
12
|
+
isOptional,
|
|
13
|
+
parse(value, path = "$") {
|
|
14
|
+
return parseFn(value, path);
|
|
15
|
+
},
|
|
16
|
+
optional() {
|
|
17
|
+
return createValidator(kind, (value, path) => {
|
|
18
|
+
if (value === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
return parseFn(value, path);
|
|
21
|
+
}, true);
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function typeOfValue(value) {
|
|
26
|
+
if (value === null)
|
|
27
|
+
return "null";
|
|
28
|
+
if (Array.isArray(value))
|
|
29
|
+
return "array";
|
|
30
|
+
return typeof value;
|
|
31
|
+
}
|
|
32
|
+
function assertRecord(value, path) {
|
|
33
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
34
|
+
throw new ValidationError(`expected object, received ${typeOfValue(value)}`, path);
|
|
35
|
+
}
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function parseShape(shape, value, path) {
|
|
39
|
+
const record = assertRecord(value, path);
|
|
40
|
+
const parsed = {};
|
|
41
|
+
for (const [key, validator] of Object.entries(shape)) {
|
|
42
|
+
const nextPath = `${path}.${key}`;
|
|
43
|
+
parsed[key] = validator.parse(record[key], nextPath);
|
|
44
|
+
}
|
|
45
|
+
const knownKeys = new Set(Object.keys(shape));
|
|
46
|
+
for (const key of Object.keys(record)) {
|
|
47
|
+
if (!knownKeys.has(key)) {
|
|
48
|
+
throw new ValidationError(`unknown key \"${key}\"`, path);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return parsed;
|
|
52
|
+
}
|
|
53
|
+
export const v = {
|
|
54
|
+
string() {
|
|
55
|
+
return createValidator("string", (value, path) => {
|
|
56
|
+
if (typeof value !== "string") {
|
|
57
|
+
throw new ValidationError(`expected string, received ${typeOfValue(value)}`, path);
|
|
58
|
+
}
|
|
59
|
+
return value;
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
number() {
|
|
63
|
+
return createValidator("number", (value, path) => {
|
|
64
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
65
|
+
throw new ValidationError(`expected finite number, received ${typeOfValue(value)}`, path);
|
|
66
|
+
}
|
|
67
|
+
return value;
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
boolean() {
|
|
71
|
+
return createValidator("boolean", (value, path) => {
|
|
72
|
+
if (typeof value !== "boolean") {
|
|
73
|
+
throw new ValidationError(`expected boolean, received ${typeOfValue(value)}`, path);
|
|
74
|
+
}
|
|
75
|
+
return value;
|
|
76
|
+
});
|
|
77
|
+
},
|
|
78
|
+
literal(value) {
|
|
79
|
+
return createValidator("literal", (input, path) => {
|
|
80
|
+
if (input !== value) {
|
|
81
|
+
throw new ValidationError(`expected literal ${JSON.stringify(value)}, received ${JSON.stringify(input)}`, path);
|
|
82
|
+
}
|
|
83
|
+
return value;
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
any() {
|
|
87
|
+
return createValidator("any", (value) => value);
|
|
88
|
+
},
|
|
89
|
+
nullable(validator) {
|
|
90
|
+
return createValidator(validator.kind, (value, path) => {
|
|
91
|
+
if (value === null)
|
|
92
|
+
return null;
|
|
93
|
+
return validator.parse(value, path);
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
optional(validator) {
|
|
97
|
+
return validator.optional();
|
|
98
|
+
},
|
|
99
|
+
array(validator) {
|
|
100
|
+
return createValidator("array", (value, path) => {
|
|
101
|
+
if (!Array.isArray(value)) {
|
|
102
|
+
throw new ValidationError(`expected array, received ${typeOfValue(value)}`, path);
|
|
103
|
+
}
|
|
104
|
+
return value.map((entry, index) => validator.parse(entry, `${path}[${index}]`));
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
object(shape) {
|
|
108
|
+
return createValidator("object", (value, path) => parseShape(shape, value, path));
|
|
109
|
+
},
|
|
110
|
+
union(...validators) {
|
|
111
|
+
return createValidator("union", (value, path) => {
|
|
112
|
+
const failures = [];
|
|
113
|
+
for (const validator of validators) {
|
|
114
|
+
try {
|
|
115
|
+
return validator.parse(value, path);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
failures.push(error instanceof Error
|
|
119
|
+
? error.message
|
|
120
|
+
: "unknown validation error");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
throw new ValidationError(`value did not match any union variant (${failures.join("; ")})`, path);
|
|
124
|
+
});
|
|
125
|
+
},
|
|
126
|
+
};
|