@raisindb/functions-types 0.1.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 (3) hide show
  1. package/index.d.ts +2 -0
  2. package/package.json +23 -0
  3. package/raisin.d.ts +407 -0
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /// <reference path="./raisin.d.ts" />
2
+ export {};
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@raisindb/functions-types",
3
+ "version": "0.1.1",
4
+ "description": "TypeScript type definitions for the RaisinDB server-side function runtime (QuickJS)",
5
+ "license": "MIT",
6
+ "types": "raisin.d.ts",
7
+ "files": [
8
+ "raisin.d.ts",
9
+ "index.d.ts"
10
+ ],
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/raisindb/raisindb",
14
+ "directory": "packages/raisindb-functions-types"
15
+ },
16
+ "keywords": [
17
+ "raisindb",
18
+ "functions",
19
+ "types",
20
+ "typescript",
21
+ "quickjs"
22
+ ]
23
+ }
package/raisin.d.ts ADDED
@@ -0,0 +1,407 @@
1
+ /**
2
+ * RaisinDB Server-Side Function Runtime Type Definitions
3
+ *
4
+ * These types describe the `raisin` global object available inside
5
+ * RaisinDB server-side functions (QuickJS runtime).
6
+ *
7
+ * This is NOT Node.js — no `Buffer`, `fs`, `require()`, or npm modules.
8
+ *
9
+ * Available globals (beyond the raisin.* API):
10
+ * - ES module imports with relative paths: import { foo } from './utils.js'
11
+ * - W3C Fetch API: fetch(), Request, Response, Headers, ReadableStream, AbortController, FormData
12
+ * - Timers: setTimeout, clearTimeout, setInterval, clearInterval
13
+ * - Console: console.log, console.debug, console.warn, console.error
14
+ *
15
+ * Auto-generated from: crates/raisin-functions/src/runtime/bindings/
16
+ */
17
+
18
+ // ==========================================================================
19
+ // Resource & Node Types (from api_wrapper.js — not in the bindings registry)
20
+ // ==========================================================================
21
+
22
+ /**
23
+ * A binary file resource attached to a node property.
24
+ * Returned by `node.getResource('./file')`.
25
+ *
26
+ * Provides built-in server-side image resizing and PDF processing.
27
+ * This is NOT Node.js — no Buffer, fs, require(), or npm modules.
28
+ * fetch() IS available (W3C Fetch API). ES module imports with relative paths are supported.
29
+ * Use resource.resize() for images and resource.processDocument() for PDFs.
30
+ */
31
+ declare class Resource {
32
+ /** Unique identifier */
33
+ readonly uuid: string;
34
+ /** Original filename */
35
+ readonly name: string;
36
+ /** File size in bytes */
37
+ readonly size: number;
38
+ /** MIME type (e.g., "image/jpeg", "application/pdf") */
39
+ readonly mimeType: string;
40
+ /** Storage metadata */
41
+ readonly metadata: Record<string, any>;
42
+ /** Internal storage key */
43
+ readonly storageKey: string | null;
44
+
45
+ /** Get binary data as base64 string. */
46
+ getBinary(): Promise<string>;
47
+
48
+ /** Get as data URL (data:mime;base64,...). */
49
+ toDataUrl(): Promise<string>;
50
+
51
+ /**
52
+ * Resize image server-side. Returns a NEW Resource with the resized data.
53
+ * This is the ONLY way to create thumbnails. Do NOT use sharp, jimp, Canvas,
54
+ * or any external library — they do not exist in this runtime.
55
+ *
56
+ * @example
57
+ * const resource = node.getResource('./file');
58
+ * const thumbnail = await resource.resize({ maxWidth: 200, format: 'jpeg', quality: 80 });
59
+ * await node.addResource('./thumbnail', thumbnail);
60
+ */
61
+ resize(options: ResizeOptions): Promise<Resource>;
62
+
63
+ /**
64
+ * Convert a PDF page to an image. Returns a new Resource.
65
+ * Only works with PDF files (mimeType contains "pdf").
66
+ */
67
+ toImage(options?: PdfToImageOptions): Promise<Resource>;
68
+
69
+ /** Get page count for PDF files. Only works with PDFs. */
70
+ getPageCount(): Promise<number>;
71
+
72
+ /**
73
+ * Process PDF document server-side: extract text, OCR, generate thumbnail.
74
+ * Uses storage-key-based API (no base64 overhead). Only works with PDFs.
75
+ *
76
+ * @example
77
+ * const resource = node.getResource('./file');
78
+ * const result = await resource.processDocument({ generateThumbnail: true, thumbnailWidth: 200 });
79
+ * if (result.thumbnail) {
80
+ * await node.addResource('./thumbnail', result.thumbnail);
81
+ * }
82
+ */
83
+ processDocument(options?: ProcessDocumentOptions): Promise<DocumentResult>;
84
+ }
85
+
86
+ interface ResizeOptions {
87
+ /** Maximum width in pixels */
88
+ maxWidth?: number;
89
+ /** Maximum height in pixels */
90
+ maxHeight?: number;
91
+ /** Output format */
92
+ format?: 'jpeg' | 'png' | 'webp';
93
+ /** Quality 1-100 (JPEG/WebP only) */
94
+ quality?: number;
95
+ }
96
+
97
+ interface PdfToImageOptions {
98
+ /** Page number (0-indexed, default 0) */
99
+ page?: number;
100
+ /** Maximum width in pixels */
101
+ maxWidth?: number;
102
+ /** Output format (default 'jpeg') */
103
+ format?: 'jpeg' | 'png' | 'webp';
104
+ /** Quality 1-100 */
105
+ quality?: number;
106
+ }
107
+
108
+ interface ProcessDocumentOptions {
109
+ /** Enable OCR for scanned PDFs */
110
+ ocr?: boolean;
111
+ /** OCR languages (default ["eng"]) */
112
+ ocrLanguages?: string[];
113
+ /** Generate a thumbnail of the first page */
114
+ generateThumbnail?: boolean;
115
+ /** Thumbnail width in pixels */
116
+ thumbnailWidth?: number;
117
+ }
118
+
119
+ interface DocumentResult {
120
+ /** Extracted text content */
121
+ text: string;
122
+ /** Number of pages */
123
+ pageCount: number;
124
+ /** Whether the PDF appears to be scanned */
125
+ isScanned: boolean;
126
+ /** Whether OCR was used */
127
+ ocrUsed: boolean;
128
+ /** Extraction method used */
129
+ extractionMethod: string;
130
+ /** Thumbnail Resource (if generateThumbnail was true) */
131
+ thumbnail?: Resource;
132
+ }
133
+
134
+ /**
135
+ * A node returned by raisin.nodes.get() and similar methods.
136
+ * Includes helper methods for binary resource operations.
137
+ */
138
+ interface RaisinNode {
139
+ id: string;
140
+ path: string;
141
+ name: string;
142
+ node_type: string;
143
+ archetype?: string;
144
+ properties: Record<string, any>;
145
+ created_at?: string;
146
+ updated_at?: string;
147
+
148
+ /**
149
+ * Get a Resource handle for a binary property.
150
+ * @param propertyPath - e.g., "./file" or "file"
151
+ * @returns Resource with resize(), processDocument(), etc., or null if not present
152
+ */
153
+ getResource(propertyPath: string): Resource | null;
154
+
155
+ /**
156
+ * Upload/store a Resource on a node property.
157
+ * @param propertyPath - Target property, e.g., "./thumbnail"
158
+ * @param data - Resource (from resize()), or { base64, mimeType, name }
159
+ */
160
+ addResource(propertyPath: string, data: Resource | ResourceUploadData | string): Promise<any>;
161
+ }
162
+
163
+ interface ResourceUploadData {
164
+ base64: string;
165
+ mimeType: string;
166
+ name?: string;
167
+ }
168
+
169
+ interface NodeCreateData {
170
+ name?: string;
171
+ path?: string;
172
+ node_type: string;
173
+ properties?: Record<string, any>;
174
+ }
175
+
176
+ /** Execution context available as raisin.context */
177
+ interface ExecutionContext {
178
+ tenant_id: string;
179
+ repo_id: string;
180
+ branch: string;
181
+ workspace_id: string;
182
+ actor?: string;
183
+ execution_id?: string;
184
+ }
185
+
186
+ /** Context passed to every function handler */
187
+ interface FunctionContext {
188
+ flow_input: {
189
+ event: {
190
+ node_id: string;
191
+ node_type: string;
192
+ node_path: string;
193
+ event_type: string;
194
+ };
195
+ workspace: string;
196
+ };
197
+ }
198
+
199
+ interface NotifyOptions {
200
+ title: string;
201
+ body?: string;
202
+ recipient?: string;
203
+ recipientId?: string;
204
+ priority?: 'low' | 'normal' | 'high';
205
+ type?: string;
206
+ link?: string;
207
+ data?: Record<string, any>;
208
+ }
209
+
210
+ interface HttpOptions {
211
+ method?: string;
212
+ headers?: Record<string, string>;
213
+ body?: any;
214
+ params?: Record<string, string>;
215
+ timeout?: number;
216
+ }
217
+
218
+ interface HttpResponse {
219
+ status: number;
220
+ headers: Record<string, string>;
221
+ body: any;
222
+ }
223
+
224
+ interface AiCompletionRequest {
225
+ model: string;
226
+ messages: Array<{ role: 'system' | 'user' | 'assistant'; content: string }>;
227
+ response_format?: { type: 'json_object'; schema?: any };
228
+ temperature?: number;
229
+ max_tokens?: number;
230
+ }
231
+
232
+ interface AiEmbedRequest {
233
+ model: string;
234
+ input: string | string[];
235
+ input_type?: 'search_document' | 'search_query';
236
+ }
237
+
238
+ // ==========================================================================
239
+ // The raisin Global Object (auto-generated from bindings registry)
240
+ // ==========================================================================
241
+
242
+ declare namespace raisin {
243
+ namespace ai {
244
+ function completion(request: any): Promise<any>;
245
+ function listModels(): Promise<any[]>;
246
+ function getDefaultModel(useCase: string): Promise<any | null>;
247
+ function embed(request: any): Promise<any>;
248
+ }
249
+
250
+ namespace crypto {
251
+ function uuid(): Promise<string>;
252
+ }
253
+
254
+ namespace date {
255
+ function now(): Promise<string>;
256
+ function timestamp(): Promise<number>;
257
+ function timestampMillis(): Promise<number>;
258
+ function parse(dateStr: string, format?: string | null): Promise<number>;
259
+ function format(timestamp: number, format?: string | null): Promise<string>;
260
+ function addDays(timestamp: number, days: number): Promise<number>;
261
+ function diffDays(ts1: number, ts2: number): Promise<number>;
262
+ }
263
+
264
+ namespace events {
265
+ function emit(eventType: string, data: any): Promise<void>;
266
+ }
267
+
268
+ namespace functions {
269
+ function execute(functionPath: string, arguments: any, context: any): Promise<any>;
270
+ function call(functionPath: string, arguments: any): Promise<any>;
271
+ }
272
+
273
+ namespace http {
274
+ /** Make an HTTP request. */
275
+ function request(method: string, url: string, options?: HttpOptions): Promise<HttpResponse>;
276
+ /** HTTP GET */
277
+ function get(url: string, options?: HttpOptions): Promise<HttpResponse>;
278
+ /** HTTP POST */
279
+ function post(url: string, options?: HttpOptions): Promise<HttpResponse>;
280
+ /** HTTP PUT */
281
+ function put(url: string, options?: HttpOptions): Promise<HttpResponse>;
282
+ /** HTTP PATCH */
283
+ function patch(url: string, options?: HttpOptions): Promise<HttpResponse>;
284
+ /** HTTP DELETE */
285
+ function delete(url: string, options?: HttpOptions): Promise<HttpResponse>;
286
+ }
287
+
288
+ namespace nodes {
289
+ function get(workspace: string, path: string): Promise<RaisinNode | null>;
290
+ function getById(workspace: string, id: string): Promise<RaisinNode | null>;
291
+ function create(workspace: string, parentPath: string, data: any): Promise<RaisinNode>;
292
+ function update(workspace: string, path: string, data: any): Promise<RaisinNode>;
293
+ function delete(workspace: string, path: string): Promise<void>;
294
+ function updateProperty(workspace: string, nodePath: string, propertyPath: string, value: any): Promise<void>;
295
+ function move(workspace: string, nodePath: string, newParentPath: string): Promise<RaisinNode>;
296
+ function query(workspace: string, query: any): Promise<RaisinNode[]>;
297
+ function getChildren(workspace: string, parentPath: string, limit?: number | null): Promise<RaisinNode[]>;
298
+ function addResource(workspace: string, nodePath: string, propertyPath: string, uploadData: any): Promise<any>;
299
+ /**
300
+ * Start a transaction for atomic multi-node operations.
301
+ * @example
302
+ * const tx = raisin.nodes.beginTransaction();
303
+ * tx.create(workspace, parentPath, data);
304
+ * tx.commit();
305
+ */
306
+ function beginTransaction(): Transaction;
307
+ }
308
+
309
+ namespace pdf {
310
+ function processFromStorage(storageKey: string, options: any): Promise<any>;
311
+ }
312
+
313
+ namespace resources {
314
+ function getBinary(storageKey: string): Promise<string>;
315
+ }
316
+
317
+ namespace sql {
318
+ function query(sql: string, params: any[]): Promise<any>;
319
+ function execute(sql: string, params: any[]): Promise<number>;
320
+ }
321
+
322
+ namespace tasks {
323
+ function create(request: any): Promise<any>;
324
+ function update(task_id: string, updates: any): Promise<any>;
325
+ function complete(task_id: string, response: any): Promise<any>;
326
+ function query(query: any): Promise<any[]>;
327
+ }
328
+
329
+ // Transaction methods are accessed via raisin.nodes.beginTransaction()
330
+ /** Send a notification to a user. */
331
+ function notify(options: NotifyOptions): Promise<any>;
332
+
333
+ /** Admin methods that bypass row-level security. Requires requiresAdmin: true in function metadata. */
334
+ namespace admin {
335
+ namespace nodes {
336
+ function get(workspace: string, path: string): Promise<any | null>;
337
+ function getById(workspace: string, id: string): Promise<any | null>;
338
+ function create(workspace: string, parentPath: string, data: any): Promise<any>;
339
+ function update(workspace: string, path: string, data: any): Promise<any>;
340
+ function delete(workspace: string, path: string): Promise<void>;
341
+ function updateProperty(workspace: string, nodePath: string, propertyPath: string, value: any): Promise<void>;
342
+ function query(workspace: string, query: any): Promise<any[]>;
343
+ function getChildren(workspace: string, parentPath: string, limit?: number | null): Promise<any[]>;
344
+ }
345
+ namespace sql {
346
+ function query(sql: string, params: any[]): Promise<any>;
347
+ function execute(sql: string, params: any[]): Promise<number>;
348
+ }
349
+ }
350
+
351
+ /** Execution context with tenant, repo, branch, workspace info. */
352
+ const context: ExecutionContext;
353
+
354
+ /**
355
+ * Escalate to admin context (bypasses RLS).
356
+ * Requires `requiresAdmin: true` in function .node.yaml metadata.
357
+ */
358
+ function asAdmin(): typeof raisin.admin;
359
+ }
360
+
361
+ // ==========================================================================
362
+ // Transaction (returned by raisin.nodes.beginTransaction())
363
+ // ==========================================================================
364
+
365
+ interface Transaction {
366
+ create(workspace: string, parentPath: string, data: NodeCreateData): any;
367
+ add(workspace: string, data: NodeCreateData): any;
368
+ put(workspace: string, data: NodeCreateData): void;
369
+ upsert(workspace: string, data: NodeCreateData): void;
370
+ createDeep(workspace: string, parentPath: string, data: NodeCreateData, parentNodeType?: string): any;
371
+ upsertDeep(workspace: string, data: NodeCreateData, parentNodeType?: string): void;
372
+ update(workspace: string, path: string, data: Partial<NodeCreateData>): void;
373
+ delete(workspace: string, path: string): void;
374
+ deleteById(workspace: string, id: string): void;
375
+ get(workspace: string, id: string): RaisinNode | null;
376
+ getByPath(workspace: string, path: string): RaisinNode | null;
377
+ listChildren(workspace: string, parentPath: string): RaisinNode[];
378
+ updateProperty(workspace: string, nodePath: string, propertyPath: string, value: any): void;
379
+ setActor(actor: string): void;
380
+ setMessage(message: string): void;
381
+ commit(): void;
382
+ rollback(): void;
383
+ }
384
+
385
+ // ==========================================================================
386
+ // Console (logging)
387
+ // ==========================================================================
388
+
389
+ declare namespace console {
390
+ function log(...args: any[]): void;
391
+ function debug(...args: any[]): void;
392
+ function warn(...args: any[]): void;
393
+ function error(...args: any[]): void;
394
+ }
395
+
396
+ // ==========================================================================
397
+ // W3C Fetch API (built-in — no import needed)
398
+ // ==========================================================================
399
+
400
+ declare function fetch(input: string | Request, init?: RequestInit): Promise<Response>;
401
+ declare function setTimeout(callback: () => void, ms?: number): number;
402
+ declare function clearTimeout(id: number): void;
403
+ declare function setInterval(callback: () => void, ms?: number): number;
404
+ declare function clearInterval(id: number): void;
405
+
406
+ /** Standard function export pattern: module.exports = { handler }; */
407
+ declare var module: { exports: Record<string, any> };