jotdb 0.1.8 → 0.1.9

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.
@@ -0,0 +1,6 @@
1
+ export { JotDB } from './index';
2
+ export default {
3
+ async fetch(request, env) {
4
+ return env.ASSETS.fetch(request);
5
+ },
6
+ };
@@ -0,0 +1,107 @@
1
+ import { Hono } from 'hono';
2
+ import { DurableObject } from "cloudflare:workers";
3
+ type SchemaType = "string" | "number" | "boolean" | "email" | "array" | "object" | "any";
4
+ interface FieldDescriptor {
5
+ type: SchemaType;
6
+ default?: unknown;
7
+ optional?: boolean;
8
+ }
9
+ type FieldSpec = SchemaType | FieldDescriptor;
10
+ type ObjectSchema = Record<string, FieldSpec>;
11
+ type ArraySchema = {
12
+ __arrayType: SchemaType | ObjectSchema;
13
+ };
14
+ type SchemaDefinition = ObjectSchema | ArraySchema;
15
+ interface JotDBOptions {
16
+ autoStrip: boolean;
17
+ readOnly: boolean;
18
+ }
19
+ interface AuditLogEntry {
20
+ timestamp: number;
21
+ action: string;
22
+ keys: string[];
23
+ }
24
+ export declare class JotDB extends DurableObject {
25
+ private data;
26
+ private rawSchema;
27
+ private zodSchema;
28
+ private options;
29
+ private auditLog;
30
+ private store;
31
+ constructor(state: any, env: Env);
32
+ load(): Promise<void>;
33
+ save(): Promise<void>;
34
+ isArrayMode(): boolean;
35
+ private inferSchemaFromValue;
36
+ push(item: unknown): Promise<void>;
37
+ private applyDefaultsForObjectSchema;
38
+ setAll(objOrArr: Record<string, unknown> | unknown[]): Promise<void>;
39
+ getAll(): Promise<unknown>;
40
+ logAudit(action: string, keys: string[] | string): Promise<void>;
41
+ get<T = unknown>(key: string): Promise<T | undefined>;
42
+ delete(key: string): Promise<void>;
43
+ clear(): Promise<void>;
44
+ keys(): Promise<string[]>;
45
+ has(key: string): Promise<boolean>;
46
+ getSchema(): Promise<SchemaDefinition>;
47
+ private warnSchemaDiff;
48
+ setSchema(schemaObj: SchemaDefinition): Promise<void>;
49
+ /**
50
+ * Non-destructively merge additional fields into the current object schema.
51
+ * Useful for additive schema evolution without a full migration.
52
+ * Throws if the current schema is an array schema.
53
+ * New fields with `default` are backfilled into existing stored data.
54
+ * New fields without `default` and without `optional: true` will cause
55
+ * existing stored objects to fail validation on next write — prefer adding
56
+ * `default` or `optional: true` for safe rollouts.
57
+ */
58
+ extendSchema(partial: ObjectSchema): Promise<void>;
59
+ /**
60
+ * Validate arbitrary data (or current stored data if omitted) against the
61
+ * current schema without throwing. Returns `{ ok, errors, data }` where
62
+ * `data` is the (possibly default-applied / coerced) parsed result on
63
+ * success. If no schema is set, returns `{ ok: true }`.
64
+ */
65
+ validate(data?: unknown): Promise<{
66
+ ok: boolean;
67
+ errors?: string[];
68
+ data?: unknown;
69
+ }>;
70
+ /**
71
+ * Apply a transform to the stored data. For object mode, `fn` is called once
72
+ * with the entire object and must return the new object. For array mode, `fn`
73
+ * is called once per item and must return the replacement item (return
74
+ * undefined to drop the item).
75
+ * If a schema is set, the resulting data is validated before being saved;
76
+ * on validation failure the original data is left untouched and the function
77
+ * throws. Records an audit entry on success.
78
+ */
79
+ migrate(fn: (value: any, key?: string | number) => any): Promise<void>;
80
+ setOptions(opts: Partial<JotDBOptions>): Promise<void>;
81
+ getOptions(): Promise<JotDBOptions>;
82
+ getAuditLog(): Promise<AuditLogEntry[]>;
83
+ clearAuditLog(): Promise<void>;
84
+ private buildZodSchema;
85
+ private applyObjectDefaults;
86
+ fetch(request: Request): Promise<Response>;
87
+ scan<T = unknown>(prefix?: string, options?: {
88
+ limit?: number;
89
+ cursor?: string;
90
+ }): Promise<{
91
+ items: T[];
92
+ cursor?: string;
93
+ }>;
94
+ append<T = unknown>(stream: string, value: T): Promise<string>;
95
+ appendCapped<T = unknown>(stream: string, value: T, max: number): Promise<string>;
96
+ retention(prefix: string, maxAgeMs: number): Promise<void>;
97
+ set(key: string, value: unknown): Promise<void>;
98
+ }
99
+ export interface Env {
100
+ JOTDB: DurableObjectNamespace;
101
+ BENCH_TOKEN: string;
102
+ HTTP_ENABLED?: string;
103
+ }
104
+ declare const app: Hono<{
105
+ Bindings: Env;
106
+ }, import("hono/types").BlankSchema, "/">;
107
+ export default app;