@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,333 @@
|
|
|
1
|
+
import { CallbackRegistry } from "./callback-registry";
|
|
2
|
+
// ---------------------------------------------------------------------------
|
|
3
|
+
// Shared callback registry instance
|
|
4
|
+
// ---------------------------------------------------------------------------
|
|
5
|
+
export const callbackRegistry = new CallbackRegistry();
|
|
6
|
+
// ---------------------------------------------------------------------------
|
|
7
|
+
// Helpers
|
|
8
|
+
// ---------------------------------------------------------------------------
|
|
9
|
+
let nodeCounter = 0;
|
|
10
|
+
function nextId() {
|
|
11
|
+
return `node_${++nodeCounter}`;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sanitize props by replacing function values with handler IDs.
|
|
15
|
+
*/
|
|
16
|
+
function sanitizeProps(props) {
|
|
17
|
+
const sanitized = {};
|
|
18
|
+
for (const [key, value] of Object.entries(props)) {
|
|
19
|
+
if (key === "children")
|
|
20
|
+
continue;
|
|
21
|
+
if (typeof value === "function") {
|
|
22
|
+
const handlerId = callbackRegistry.register(value);
|
|
23
|
+
sanitized[`__handler_${key}`] = handlerId;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
sanitized[key] = value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return sanitized;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Deep-strip any values that cannot survive structured clone (postMessage).
|
|
33
|
+
* Functions, Symbols, and circular refs are removed.
|
|
34
|
+
*/
|
|
35
|
+
function deepSanitize(value) {
|
|
36
|
+
if (value === null || value === undefined)
|
|
37
|
+
return value;
|
|
38
|
+
const t = typeof value;
|
|
39
|
+
if (t === "string" || t === "number" || t === "boolean")
|
|
40
|
+
return value;
|
|
41
|
+
if (t === "function" || t === "symbol")
|
|
42
|
+
return undefined;
|
|
43
|
+
if (Array.isArray(value))
|
|
44
|
+
return value.map(deepSanitize);
|
|
45
|
+
if (t === "object") {
|
|
46
|
+
const out = {};
|
|
47
|
+
for (const [k, v] of Object.entries(value)) {
|
|
48
|
+
const sanitized = deepSanitize(v);
|
|
49
|
+
if (sanitized !== undefined) {
|
|
50
|
+
out[k] = sanitized;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Serialize VisionInstance tree to VisionComponentNode[] (strips parent refs).
|
|
59
|
+
* Ensures the output is fully structured-clone safe for postMessage.
|
|
60
|
+
*/
|
|
61
|
+
function serializeTree(instances) {
|
|
62
|
+
return instances.map((inst) => ({
|
|
63
|
+
_id: inst._id,
|
|
64
|
+
type: (typeof inst.type === "function"
|
|
65
|
+
? inst.type.name || "Unknown"
|
|
66
|
+
: inst.type),
|
|
67
|
+
props: deepSanitize(inst.props),
|
|
68
|
+
children: serializeTree(inst.children),
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Priority constants (from react-reconciler/constants for 0.32.0 / React 19)
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
const DefaultEventPriority = 32;
|
|
75
|
+
export function createHostConfig(onCommit) {
|
|
76
|
+
// Track update priority internally (required by React 19 reconciler)
|
|
77
|
+
let currentUpdatePriority = 0;
|
|
78
|
+
return {
|
|
79
|
+
// -----------------------------------------------------------------------
|
|
80
|
+
// Feature flags
|
|
81
|
+
// -----------------------------------------------------------------------
|
|
82
|
+
supportsMutation: true,
|
|
83
|
+
supportsPersistence: false,
|
|
84
|
+
supportsHydration: false,
|
|
85
|
+
supportsResources: false,
|
|
86
|
+
supportsSingletons: false,
|
|
87
|
+
supportsTestSelectors: false,
|
|
88
|
+
isPrimaryRenderer: true,
|
|
89
|
+
warnsIfNotActing: false,
|
|
90
|
+
// -----------------------------------------------------------------------
|
|
91
|
+
// Microtask support (React 19)
|
|
92
|
+
// -----------------------------------------------------------------------
|
|
93
|
+
supportsMicrotasks: true,
|
|
94
|
+
scheduleMicrotask: typeof queueMicrotask === "function"
|
|
95
|
+
? queueMicrotask
|
|
96
|
+
: (fn) => Promise.resolve().then(fn),
|
|
97
|
+
// -----------------------------------------------------------------------
|
|
98
|
+
// Priority management (React 19 — the crash was here)
|
|
99
|
+
// -----------------------------------------------------------------------
|
|
100
|
+
getCurrentUpdatePriority() {
|
|
101
|
+
return currentUpdatePriority;
|
|
102
|
+
},
|
|
103
|
+
setCurrentUpdatePriority(newPriority) {
|
|
104
|
+
currentUpdatePriority = newPriority;
|
|
105
|
+
},
|
|
106
|
+
resolveUpdatePriority() {
|
|
107
|
+
if (currentUpdatePriority !== 0)
|
|
108
|
+
return currentUpdatePriority;
|
|
109
|
+
return DefaultEventPriority;
|
|
110
|
+
},
|
|
111
|
+
getCurrentEventPriority() {
|
|
112
|
+
return DefaultEventPriority;
|
|
113
|
+
},
|
|
114
|
+
shouldAttemptEagerTransition() {
|
|
115
|
+
return false;
|
|
116
|
+
},
|
|
117
|
+
// -----------------------------------------------------------------------
|
|
118
|
+
// Transitions (React 19 form actions / useTransition)
|
|
119
|
+
// -----------------------------------------------------------------------
|
|
120
|
+
NotPendingTransition: null,
|
|
121
|
+
HostTransitionContext: {
|
|
122
|
+
$$typeof: Symbol.for("react.context"),
|
|
123
|
+
_currentValue: null,
|
|
124
|
+
_currentValue2: null,
|
|
125
|
+
Provider: null,
|
|
126
|
+
Consumer: null,
|
|
127
|
+
},
|
|
128
|
+
resetFormInstance() {
|
|
129
|
+
// no-op — no form elements in our headless renderer
|
|
130
|
+
},
|
|
131
|
+
// -----------------------------------------------------------------------
|
|
132
|
+
// Suspense commit stubs (React 19)
|
|
133
|
+
// -----------------------------------------------------------------------
|
|
134
|
+
maySuspendCommit() {
|
|
135
|
+
return false;
|
|
136
|
+
},
|
|
137
|
+
preloadInstance() {
|
|
138
|
+
return true; // already loaded
|
|
139
|
+
},
|
|
140
|
+
startSuspendingCommit() {
|
|
141
|
+
// no-op
|
|
142
|
+
},
|
|
143
|
+
suspendInstance() {
|
|
144
|
+
// no-op
|
|
145
|
+
},
|
|
146
|
+
waitForCommitToBeReady() {
|
|
147
|
+
return null;
|
|
148
|
+
},
|
|
149
|
+
// -----------------------------------------------------------------------
|
|
150
|
+
// Instance creation & tree manipulation
|
|
151
|
+
// -----------------------------------------------------------------------
|
|
152
|
+
createInstance(type, props) {
|
|
153
|
+
// In some cases (e.g. React 19 reconciler edge cases), a function
|
|
154
|
+
// component may arrive here instead of its resolved string type.
|
|
155
|
+
// Extract the name so the serialized tree stays postMessage-safe.
|
|
156
|
+
let resolvedType;
|
|
157
|
+
if (typeof type === "function") {
|
|
158
|
+
resolvedType = type.name || "Unknown";
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
resolvedType = type;
|
|
162
|
+
}
|
|
163
|
+
return {
|
|
164
|
+
_id: nextId(),
|
|
165
|
+
type: resolvedType,
|
|
166
|
+
props: sanitizeProps(props),
|
|
167
|
+
children: [],
|
|
168
|
+
parent: null,
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
createTextInstance(text) {
|
|
172
|
+
return {
|
|
173
|
+
_id: nextId(),
|
|
174
|
+
type: "Text",
|
|
175
|
+
props: { content: text },
|
|
176
|
+
children: [],
|
|
177
|
+
parent: null,
|
|
178
|
+
};
|
|
179
|
+
},
|
|
180
|
+
appendInitialChild(parent, child) {
|
|
181
|
+
child.parent = parent;
|
|
182
|
+
parent.children.push(child);
|
|
183
|
+
},
|
|
184
|
+
appendChild(parent, child) {
|
|
185
|
+
child.parent = parent;
|
|
186
|
+
parent.children.push(child);
|
|
187
|
+
},
|
|
188
|
+
removeChild(parent, child) {
|
|
189
|
+
child.parent = null;
|
|
190
|
+
const idx = parent.children.indexOf(child);
|
|
191
|
+
if (idx !== -1)
|
|
192
|
+
parent.children.splice(idx, 1);
|
|
193
|
+
},
|
|
194
|
+
insertBefore(parent, child, beforeChild) {
|
|
195
|
+
child.parent = parent;
|
|
196
|
+
const idx = parent.children.indexOf(beforeChild);
|
|
197
|
+
if (idx !== -1) {
|
|
198
|
+
parent.children.splice(idx, 0, child);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
parent.children.push(child);
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
appendChildToContainer(container, child) {
|
|
205
|
+
child.parent = null;
|
|
206
|
+
container.children.push(child);
|
|
207
|
+
},
|
|
208
|
+
removeChildFromContainer(container, child) {
|
|
209
|
+
child.parent = null;
|
|
210
|
+
const idx = container.children.indexOf(child);
|
|
211
|
+
if (idx !== -1)
|
|
212
|
+
container.children.splice(idx, 1);
|
|
213
|
+
},
|
|
214
|
+
insertInContainerBefore(container, child, beforeChild) {
|
|
215
|
+
child.parent = null;
|
|
216
|
+
const idx = container.children.indexOf(beforeChild);
|
|
217
|
+
if (idx !== -1) {
|
|
218
|
+
container.children.splice(idx, 0, child);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
container.children.push(child);
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
// -----------------------------------------------------------------------
|
|
225
|
+
// Updates
|
|
226
|
+
// -----------------------------------------------------------------------
|
|
227
|
+
prepareUpdate(_instance, _type, _oldProps, newProps) {
|
|
228
|
+
return newProps;
|
|
229
|
+
},
|
|
230
|
+
commitUpdate(instance, _updatePayload, _type, _oldProps, newProps) {
|
|
231
|
+
for (const [key, value] of Object.entries(instance.props)) {
|
|
232
|
+
if (key.startsWith("__handler_")) {
|
|
233
|
+
callbackRegistry.remove(value);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
instance.props = sanitizeProps(newProps);
|
|
237
|
+
},
|
|
238
|
+
commitTextUpdate(textInstance, _oldText, newText) {
|
|
239
|
+
textInstance.props = { content: newText };
|
|
240
|
+
},
|
|
241
|
+
commitMount() {
|
|
242
|
+
// no-op
|
|
243
|
+
},
|
|
244
|
+
finalizeInitialChildren() {
|
|
245
|
+
return false;
|
|
246
|
+
},
|
|
247
|
+
// -----------------------------------------------------------------------
|
|
248
|
+
// Commit lifecycle
|
|
249
|
+
// -----------------------------------------------------------------------
|
|
250
|
+
prepareForCommit() {
|
|
251
|
+
return null;
|
|
252
|
+
},
|
|
253
|
+
resetAfterCommit(container) {
|
|
254
|
+
const tree = serializeTree(container.children);
|
|
255
|
+
onCommit(tree);
|
|
256
|
+
},
|
|
257
|
+
// -----------------------------------------------------------------------
|
|
258
|
+
// Context & public instance
|
|
259
|
+
// -----------------------------------------------------------------------
|
|
260
|
+
getPublicInstance(instance) {
|
|
261
|
+
return instance;
|
|
262
|
+
},
|
|
263
|
+
getRootHostContext() {
|
|
264
|
+
return {};
|
|
265
|
+
},
|
|
266
|
+
getChildHostContext(parentHostContext) {
|
|
267
|
+
return parentHostContext;
|
|
268
|
+
},
|
|
269
|
+
shouldSetTextContent() {
|
|
270
|
+
return false;
|
|
271
|
+
},
|
|
272
|
+
// -----------------------------------------------------------------------
|
|
273
|
+
// Container operations
|
|
274
|
+
// -----------------------------------------------------------------------
|
|
275
|
+
clearContainer(container) {
|
|
276
|
+
container.children = [];
|
|
277
|
+
},
|
|
278
|
+
preparePortalMount() {
|
|
279
|
+
// no-op
|
|
280
|
+
},
|
|
281
|
+
// -----------------------------------------------------------------------
|
|
282
|
+
// Visibility (hide/unhide for Suspense/Offscreen)
|
|
283
|
+
// -----------------------------------------------------------------------
|
|
284
|
+
hideInstance() {
|
|
285
|
+
// no-op
|
|
286
|
+
},
|
|
287
|
+
hideTextInstance() {
|
|
288
|
+
// no-op
|
|
289
|
+
},
|
|
290
|
+
unhideInstance() {
|
|
291
|
+
// no-op
|
|
292
|
+
},
|
|
293
|
+
unhideTextInstance() {
|
|
294
|
+
// no-op
|
|
295
|
+
},
|
|
296
|
+
// -----------------------------------------------------------------------
|
|
297
|
+
// Timeouts
|
|
298
|
+
// -----------------------------------------------------------------------
|
|
299
|
+
scheduleTimeout: setTimeout,
|
|
300
|
+
cancelTimeout: clearTimeout,
|
|
301
|
+
noTimeout: -1,
|
|
302
|
+
// -----------------------------------------------------------------------
|
|
303
|
+
// Misc required stubs
|
|
304
|
+
// -----------------------------------------------------------------------
|
|
305
|
+
getInstanceFromNode() {
|
|
306
|
+
return null;
|
|
307
|
+
},
|
|
308
|
+
beforeActiveInstanceBlur() {
|
|
309
|
+
// no-op
|
|
310
|
+
},
|
|
311
|
+
afterActiveInstanceBlur() {
|
|
312
|
+
// no-op
|
|
313
|
+
},
|
|
314
|
+
prepareScopeUpdate() {
|
|
315
|
+
// no-op
|
|
316
|
+
},
|
|
317
|
+
getInstanceFromScope() {
|
|
318
|
+
return null;
|
|
319
|
+
},
|
|
320
|
+
detachDeletedInstance() {
|
|
321
|
+
// no-op
|
|
322
|
+
},
|
|
323
|
+
resetTextContent() {
|
|
324
|
+
// no-op
|
|
325
|
+
},
|
|
326
|
+
// Console binding (React 19 dev mode)
|
|
327
|
+
bindToConsole(methodName, args, _badgeName) {
|
|
328
|
+
// eslint-disable-next-line no-console
|
|
329
|
+
return console[methodName];
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
export { serializeTree };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { WorkerBridge } from "../bridge/worker-bridge";
|
|
3
|
+
export declare function setBridge(bridge: WorkerBridge): void;
|
|
4
|
+
export declare function renderExtension(element: React.ReactElement): void;
|
|
5
|
+
export declare const Vision: {
|
|
6
|
+
render(element: React.ReactElement, _options?: {
|
|
7
|
+
target?: "editor" | "layer" | "interactive";
|
|
8
|
+
}): void;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=render.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/renderer/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAM5D,wBAAgB,SAAS,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAEpD;AAED,wBAAgB,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,CAqCjE;AAED,eAAO,MAAM,MAAM;oBAEN,KAAK,CAAC,YAAY,aAChB;QAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAA;KAAE,GACzD,IAAI;CAGR,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ReactReconciler from "react-reconciler";
|
|
2
|
+
import { createHostConfig } from "./reconciler";
|
|
3
|
+
let bridgeInstance = null;
|
|
4
|
+
export function setBridge(bridge) {
|
|
5
|
+
bridgeInstance = bridge;
|
|
6
|
+
}
|
|
7
|
+
export function renderExtension(element) {
|
|
8
|
+
if (!bridgeInstance) {
|
|
9
|
+
throw new Error("Vision SDK: Bridge not initialized. Ensure worker-entry has run before calling render.");
|
|
10
|
+
}
|
|
11
|
+
const bridge = bridgeInstance;
|
|
12
|
+
const onCommit = (tree) => {
|
|
13
|
+
bridge.notify("ui.render", { tree });
|
|
14
|
+
};
|
|
15
|
+
const hostConfig = createHostConfig(onCommit);
|
|
16
|
+
const reconciler = ReactReconciler(hostConfig);
|
|
17
|
+
const container = { children: [] };
|
|
18
|
+
const root = reconciler.createContainer(container, 0, // ConcurrentRoot tag
|
|
19
|
+
null, // hydrationCallbacks
|
|
20
|
+
false, // isStrictMode
|
|
21
|
+
null, // concurrentUpdatesByDefaultOverride
|
|
22
|
+
"", // identifierPrefix
|
|
23
|
+
(error) => console.error(error), // onRecoverableError
|
|
24
|
+
null);
|
|
25
|
+
reconciler.updateContainer(element, root, null, () => {
|
|
26
|
+
bridge.notify("ui.ready");
|
|
27
|
+
});
|
|
28
|
+
// Clear the init timeout since render was called
|
|
29
|
+
const clearInit = globalThis.__visionClearInitTimeout;
|
|
30
|
+
if (typeof clearInit === "function") {
|
|
31
|
+
clearInit();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const Vision = {
|
|
35
|
+
render(element, _options) {
|
|
36
|
+
renderExtension(element);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Infer, ValidatorShape } from "./validators";
|
|
2
|
+
export type FunctionType = "query" | "mutation" | "action";
|
|
3
|
+
export type JsonPrimitive = string | number | boolean | null;
|
|
4
|
+
export type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
5
|
+
export type JsonObject = {
|
|
6
|
+
[key: string]: JsonValue;
|
|
7
|
+
};
|
|
8
|
+
export interface UserIdentity {
|
|
9
|
+
subject: string;
|
|
10
|
+
issuer?: string;
|
|
11
|
+
audience?: string;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export interface AuthApi {
|
|
15
|
+
getUserIdentity(): Promise<UserIdentity | null>;
|
|
16
|
+
hasScope(scope: string): boolean;
|
|
17
|
+
}
|
|
18
|
+
export type QueryOperator = "eq" | "neq" | "lt" | "lte" | "gt" | "gte" | "in";
|
|
19
|
+
export type QueryFilter = {
|
|
20
|
+
field: string;
|
|
21
|
+
op: QueryOperator;
|
|
22
|
+
value: JsonValue;
|
|
23
|
+
};
|
|
24
|
+
export type QueryRequest = {
|
|
25
|
+
index?: {
|
|
26
|
+
name: string;
|
|
27
|
+
values: readonly JsonValue[];
|
|
28
|
+
};
|
|
29
|
+
filters?: readonly QueryFilter[];
|
|
30
|
+
limit?: number;
|
|
31
|
+
offset?: number;
|
|
32
|
+
};
|
|
33
|
+
export interface DbReaderApi {
|
|
34
|
+
get(table: string, id: string): Promise<JsonObject | null>;
|
|
35
|
+
query(table: string, request?: QueryRequest): Promise<readonly JsonObject[]>;
|
|
36
|
+
}
|
|
37
|
+
export interface DbWriterApi extends DbReaderApi {
|
|
38
|
+
insert(table: string, value: JsonObject): Promise<{
|
|
39
|
+
id: string;
|
|
40
|
+
}>;
|
|
41
|
+
patch(table: string, id: string, value: Partial<JsonObject>): Promise<void>;
|
|
42
|
+
delete(table: string, id: string): Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
export interface SecretApi {
|
|
45
|
+
get(name: string): Promise<string | undefined>;
|
|
46
|
+
}
|
|
47
|
+
export interface QueryContext {
|
|
48
|
+
db: DbReaderApi;
|
|
49
|
+
auth: AuthApi;
|
|
50
|
+
}
|
|
51
|
+
export interface MutationContext {
|
|
52
|
+
db: DbWriterApi;
|
|
53
|
+
auth: AuthApi;
|
|
54
|
+
}
|
|
55
|
+
export interface ActionContext {
|
|
56
|
+
db: DbWriterApi;
|
|
57
|
+
auth: AuthApi;
|
|
58
|
+
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
59
|
+
secrets: SecretApi;
|
|
60
|
+
}
|
|
61
|
+
type FunctionArgsShape = ValidatorShape;
|
|
62
|
+
type InferArgs<TArgs extends FunctionArgsShape | undefined> = TArgs extends FunctionArgsShape ? {
|
|
63
|
+
[TKey in keyof TArgs]: Infer<TArgs[TKey]>;
|
|
64
|
+
} : Record<string, never>;
|
|
65
|
+
type FunctionConfig<TArgs extends FunctionArgsShape | undefined, TContext, TResult> = {
|
|
66
|
+
args?: TArgs;
|
|
67
|
+
scope?: string | readonly string[];
|
|
68
|
+
handler(ctx: TContext, args: InferArgs<TArgs>): TResult | Promise<TResult>;
|
|
69
|
+
};
|
|
70
|
+
export type ServerFunctionDefinition<TType extends FunctionType, TArgs extends FunctionArgsShape, TContext, TResult> = {
|
|
71
|
+
readonly type: TType;
|
|
72
|
+
readonly args: TArgs;
|
|
73
|
+
readonly scope: readonly string[];
|
|
74
|
+
readonly handler: (ctx: TContext, args: InferArgs<TArgs>) => TResult | Promise<TResult>;
|
|
75
|
+
parseArgs(input: unknown): InferArgs<TArgs>;
|
|
76
|
+
};
|
|
77
|
+
export declare function query<TArgs extends FunctionArgsShape | undefined, TResult>(config: FunctionConfig<TArgs, QueryContext, TResult>): ServerFunctionDefinition<"query", TArgs extends FunctionArgsShape ? TArgs : {}, QueryContext, TResult>;
|
|
78
|
+
export declare function mutation<TArgs extends FunctionArgsShape | undefined, TResult>(config: FunctionConfig<TArgs, MutationContext, TResult>): ServerFunctionDefinition<"mutation", TArgs extends FunctionArgsShape ? TArgs : {}, MutationContext, TResult>;
|
|
79
|
+
export declare function action<TArgs extends FunctionArgsShape | undefined, TResult>(config: FunctionConfig<TArgs, ActionContext, TResult>): ServerFunctionDefinition<"action", TArgs extends FunctionArgsShape ? TArgs : {}, ActionContext, TResult>;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","s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BAAiB,GAAG,KAAK,GAAG,EAAE,EAC5C,YAAY,EACZ,OAAO,CACR,CAEA;AAED,wBAAgB,QAAQ,CAAC,KAAK,SAAS,iBAAiB,GAAG,SAAS,EAAE,OAAO,EAC3E,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,eAAe,EAAE,OAAO,CAAC,GACtD,wBAAwB,CACzB,UAAU,EACV,KAAK,SAAS,iBAAiB,GAAG,KAAK,GAAG,EAAE,EAC5C,eAAe,EACf,OAAO,CACR,CAEA;AAED,wBAAgB,MAAM,CAAC,KAAK,SAAS,iBAAiB,GAAG,SAAS,EAAE,OAAO,EACzE,MAAM,EAAE,cAAc,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,GACpD,wBAAwB,CACzB,QAAQ,EACR,KAAK,SAAS,iBAAiB,GAAG,KAAK,GAAG,EAAE,EAC5C,aAAa,EACb,OAAO,CACR,CAEA"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { v } from "./validators";
|
|
2
|
+
function normalizeScope(scope) {
|
|
3
|
+
if (!scope)
|
|
4
|
+
return [];
|
|
5
|
+
if (typeof scope === "string")
|
|
6
|
+
return [scope];
|
|
7
|
+
return [...scope];
|
|
8
|
+
}
|
|
9
|
+
function defineFunction(type, config) {
|
|
10
|
+
const argsShape = (config.args ?? {});
|
|
11
|
+
const argsValidator = v.object(argsShape);
|
|
12
|
+
return {
|
|
13
|
+
type,
|
|
14
|
+
args: argsShape,
|
|
15
|
+
scope: normalizeScope(config.scope),
|
|
16
|
+
handler: config.handler,
|
|
17
|
+
parseArgs(input) {
|
|
18
|
+
const rawArgs = input ?? {};
|
|
19
|
+
return argsValidator.parse(rawArgs, "args");
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function query(config) {
|
|
24
|
+
return defineFunction("query", config);
|
|
25
|
+
}
|
|
26
|
+
export function mutation(config) {
|
|
27
|
+
return defineFunction("mutation", config);
|
|
28
|
+
}
|
|
29
|
+
export function action(config) {
|
|
30
|
+
return defineFunction("action", config);
|
|
31
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { action, mutation, query } from "./functions";
|
|
2
|
+
export type { ActionContext, AuthApi, DbReaderApi, DbWriterApi, FunctionType, JsonObject, JsonValue, MutationContext, QueryContext, QueryFilter, QueryOperator, QueryRequest, SecretApi, ServerFunctionDefinition, UserIdentity, } from "./functions";
|
|
3
|
+
export { defineSchema, defineTable } from "./schema";
|
|
4
|
+
export type { InferSchemaTables, InferTableFields, SchemaDefinition, SchemaTables, TableDefinition, TableFields, TableIndex, } from "./schema";
|
|
5
|
+
export { ValidationError, v } from "./validators";
|
|
6
|
+
export type { Infer, Validator, ValidatorShape } from "./validators";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACtD,YAAY,EACV,aAAa,EACb,OAAO,EACP,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACT,eAAe,EACf,YAAY,EACZ,WAAW,EACX,aAAa,EACb,YAAY,EACZ,SAAS,EACT,wBAAwB,EACxB,YAAY,GACb,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EACV,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACZ,eAAe,EACf,WAAW,EACX,UAAU,GACX,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAClD,YAAY,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Infer, Validator } from "./validators";
|
|
2
|
+
type ColumnName<TFields extends TableFields> = Extract<keyof TFields, string>;
|
|
3
|
+
export type TableFields = Record<string, Validator<unknown>>;
|
|
4
|
+
export type InferTableFields<TFields extends TableFields> = {
|
|
5
|
+
[TKey in keyof TFields]: Infer<TFields[TKey]>;
|
|
6
|
+
};
|
|
7
|
+
export type TableIndex<TFields extends TableFields> = {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly columns: readonly ColumnName<TFields>[];
|
|
10
|
+
};
|
|
11
|
+
export declare class TableDefinition<TFields extends TableFields> {
|
|
12
|
+
readonly fields: TFields;
|
|
13
|
+
readonly indexes: readonly TableIndex<TFields>[];
|
|
14
|
+
readonly kind = "table";
|
|
15
|
+
constructor(fields: TFields, indexes?: readonly TableIndex<TFields>[]);
|
|
16
|
+
index(name: string, columns: readonly ColumnName<TFields>[]): TableDefinition<TFields>;
|
|
17
|
+
}
|
|
18
|
+
export type SchemaTables = Record<string, TableDefinition<TableFields>>;
|
|
19
|
+
export type InferSchemaTables<TTables extends SchemaTables> = {
|
|
20
|
+
[TTable in keyof TTables]: InferTableFields<TTables[TTable]["fields"]>;
|
|
21
|
+
};
|
|
22
|
+
export declare class SchemaDefinition<TTables extends SchemaTables> {
|
|
23
|
+
readonly tables: TTables;
|
|
24
|
+
readonly kind = "schema";
|
|
25
|
+
constructor(tables: TTables);
|
|
26
|
+
}
|
|
27
|
+
export declare function defineTable<TFields extends TableFields>(fields: TFields): TableDefinition<TFields>;
|
|
28
|
+
export declare function defineSchema<TTables extends SchemaTables>(tables: TTables): SchemaDefinition<TTables>;
|
|
29
|
+
export {};
|
|
30
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/server/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAErD,KAAK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,OAAO;IAFpC,QAAQ,CAAC,IAAI,YAAY;gBAEJ,MAAM,EAAE,OAAO;CACrC;AAED,wBAAgB,WAAW,CAAC,OAAO,SAAS,WAAW,EACrD,MAAM,EAAE,OAAO,GACd,eAAe,CAAC,OAAO,CAAC,CAE1B;AAED,wBAAgB,YAAY,CAAC,OAAO,SAAS,YAAY,EACvD,MAAM,EAAE,OAAO,GACd,gBAAgB,CAAC,OAAO,CAAC,CAE3B"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export class TableDefinition {
|
|
2
|
+
fields;
|
|
3
|
+
indexes;
|
|
4
|
+
kind = "table";
|
|
5
|
+
constructor(fields, indexes = []) {
|
|
6
|
+
this.fields = fields;
|
|
7
|
+
this.indexes = indexes;
|
|
8
|
+
}
|
|
9
|
+
index(name, columns) {
|
|
10
|
+
if (!name.trim()) {
|
|
11
|
+
throw new Error("Index name cannot be empty");
|
|
12
|
+
}
|
|
13
|
+
if (columns.length === 0) {
|
|
14
|
+
throw new Error("Index must reference at least one column");
|
|
15
|
+
}
|
|
16
|
+
const nextIndex = {
|
|
17
|
+
name,
|
|
18
|
+
columns: [...columns],
|
|
19
|
+
};
|
|
20
|
+
return new TableDefinition(this.fields, [...this.indexes, nextIndex]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export class SchemaDefinition {
|
|
24
|
+
tables;
|
|
25
|
+
kind = "schema";
|
|
26
|
+
constructor(tables) {
|
|
27
|
+
this.tables = tables;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function defineTable(fields) {
|
|
31
|
+
return new TableDefinition(fields);
|
|
32
|
+
}
|
|
33
|
+
export function defineSchema(tables) {
|
|
34
|
+
return new SchemaDefinition(tables);
|
|
35
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class ValidationError extends Error {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
constructor(message: string, path?: string);
|
|
4
|
+
}
|
|
5
|
+
export type Validator<T> = {
|
|
6
|
+
readonly kind: string;
|
|
7
|
+
readonly isOptional: boolean;
|
|
8
|
+
parse(value: unknown, path?: string): T;
|
|
9
|
+
optional(): Validator<T | undefined>;
|
|
10
|
+
};
|
|
11
|
+
export type Infer<TValidator extends Validator<unknown>> = TValidator extends Validator<infer TValue> ? TValue : never;
|
|
12
|
+
export type ValidatorShape = Record<string, Validator<unknown>>;
|
|
13
|
+
export type InferShape<TShape extends ValidatorShape> = {
|
|
14
|
+
[TKey in keyof TShape]: Infer<TShape[TKey]>;
|
|
15
|
+
};
|
|
16
|
+
export declare const v: {
|
|
17
|
+
string(): Validator<string>;
|
|
18
|
+
number(): Validator<number>;
|
|
19
|
+
boolean(): Validator<boolean>;
|
|
20
|
+
literal<TValue extends string | number | boolean | null>(value: TValue): Validator<TValue>;
|
|
21
|
+
any(): Validator<unknown>;
|
|
22
|
+
nullable<TValue>(validator: Validator<TValue>): Validator<TValue | null>;
|
|
23
|
+
optional<TValue>(validator: Validator<TValue>): Validator<TValue | undefined>;
|
|
24
|
+
array<TValue>(validator: Validator<TValue>): Validator<TValue[]>;
|
|
25
|
+
object<TShape extends ValidatorShape>(shape: TShape): Validator<InferShape<TShape>>;
|
|
26
|
+
union<TValidators extends readonly Validator<unknown>[]>(...validators: TValidators): Validator<Infer<TValidators[number]>>;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../../src/server/validators.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,KAAK;IAGtC,QAAQ,CAAC,IAAI;gBADb,OAAO,EAAE,MAAM,EACN,IAAI,SAAM;CAKtB;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,KAAK,CAAC,KAAK,EAAE,O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