@datafn/server 0.0.2 → 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/README.md CHANGED
@@ -5,7 +5,7 @@ HTTP server runtime for DataFn. Provides DFQL query execution, mutations with id
5
5
  ## Installation
6
6
 
7
7
  ```bash
8
- npm install @datafn/server @datafn/core @superfunctions/db @superfunctions/http
8
+ npm install @datafn/server @datafn/core @superfunctions/db @superfunctions/http @superfunctions/http-hono hono @hono/node-server
9
9
  ```
10
10
 
11
11
  ## Features
@@ -23,6 +23,7 @@ npm install @datafn/server @datafn/core @superfunctions/db @superfunctions/http
23
23
  | **Sync: Seed** | Seed data into the database |
24
24
  | **Authorization** | Per-action authorization hook |
25
25
  | **Multi-User Isolation** | Per-user/tenant namespace isolation for change tracking |
26
+ | **Multi-Region Gateway** | Atomic tenant placement, pre-execution cell fencing, signed internal forwarding, bounded stale-epoch retry, and controlled moves |
26
27
  | **REST Endpoints** | Optional REST wrappers over DFQL (GET/POST/PATCH/DELETE) |
27
28
  | **WebSocket** | Real-time cursor broadcast for live updates |
28
29
  | **Plugins** | Hook into queries, mutations, and sync on the server side |
@@ -30,6 +31,12 @@ npm install @datafn/server @datafn/core @superfunctions/db @superfunctions/http
30
31
  | **Payload Limits** | Configurable max query limits, transaction steps, and payload size |
31
32
  | **KV Resource** | Built-in key-value resource auto-included in schema |
32
33
 
34
+ Multi-region gateway mode is opt-in and keeps ownership separate from the
35
+ permission-directory projection. See
36
+ [`multi-region-gateway.mdx`](../docs/content/docs/documentation/multi-region-gateway.mdx)
37
+ for configuration, error, WebSocket, consistency, migration, and operations
38
+ contracts.
39
+
33
40
  ---
34
41
 
35
42
  ## Quick Start
@@ -55,7 +62,7 @@ const server = await createDatafnServer({
55
62
  },
56
63
  ],
57
64
  },
58
- db: drizzleAdapter({ db: myDrizzleInstance, dialect: "postgres" }),
65
+ database: drizzleAdapter({ db: myDrizzleInstance, dialect: "postgres" }),
59
66
  authorize: async (ctx, action, payload) => {
60
67
  return true; // Allow all (replace with real logic)
61
68
  },
@@ -78,7 +85,7 @@ interface DatafnServerConfig<TContext = any> {
78
85
  schema: DatafnSchema;
79
86
 
80
87
  /** Database adapter (e.g. drizzleAdapter, memoryAdapter) */
81
- db?: Adapter;
88
+ database?: Adapter;
82
89
 
83
90
  /** Server-side plugins */
84
91
  plugins?: DatafnPlugin[];
@@ -95,6 +102,9 @@ interface DatafnServerConfig<TContext = any> {
95
102
  payload: unknown,
96
103
  ) => Promise<boolean> | boolean;
97
104
 
105
+ /** Static request context or a request-scoped context factory. */
106
+ context?: TContext | ((request: Request) => Promise<TContext> | TContext);
107
+
98
108
  /** Configurable limits */
99
109
  limits?: {
100
110
  /** Maximum number of records per query (default: 100) */
@@ -122,6 +132,12 @@ interface DatafnServerConfig<TContext = any> {
122
132
  getContext: (ctx: TContext) => AuthContext | Promise<AuthContext>;
123
133
  };
124
134
 
135
+ /** Trusted namespace and optional actor derivation from request context. */
136
+ namespaceProvider?: {
137
+ getNamespace: (ctx: TContext) => string | Promise<string>;
138
+ getActorId?: (ctx: TContext) => string | undefined | Promise<string | undefined>;
139
+ };
140
+
125
141
  /**
126
142
  * Redis adapter for atomic operations (serverSeq, rate limiting, caching).
127
143
  * Used when dbMapping.serverseq = "redis".
@@ -563,7 +579,7 @@ Isolate change tracking per user or tenant. Each namespace gets its own `serverS
563
579
  ```typescript
564
580
  const server = await createDatafnServer({
565
581
  schema,
566
- db: adapter,
582
+ database: adapter,
567
583
  authContextProvider: {
568
584
  getContext: (ctx) => ({
569
585
  userId: ctx.session?.userId,
@@ -595,13 +611,13 @@ The server uses a `SequenceStore` for generating monotonically increasing sequen
595
611
  // Default: use main database
596
612
  const server = await createDatafnServer({
597
613
  schema,
598
- db: adapter,
614
+ database: adapter,
599
615
  });
600
616
 
601
617
  // Redis for high-throughput atomic INCR
602
618
  const server = await createDatafnServer({
603
619
  schema,
604
- db: adapter,
620
+ database: adapter,
605
621
  redis: myRedisAdapter,
606
622
  dbMapping: { serverseq: "redis" },
607
623
  });
@@ -609,7 +625,7 @@ const server = await createDatafnServer({
609
625
  // KV store (e.g. Cloudflare KV, DynamoDB)
610
626
  const server = await createDatafnServer({
611
627
  schema,
612
- db: adapter,
628
+ database: adapter,
613
629
  kvStore: myKVAdapter,
614
630
  dbMapping: { serverseq: "kv" },
615
631
  });
@@ -647,7 +663,7 @@ Enable REST wrappers alongside DFQL endpoints:
647
663
  ```typescript
648
664
  const server = await createDatafnServer({
649
665
  schema,
650
- db: adapter,
666
+ database: adapter,
651
667
  rest: true, // Enable REST endpoints
652
668
  });
653
669
  ```
@@ -668,7 +684,7 @@ const server = await createDatafnServer({
668
684
  The server exposes a WebSocket handler for real-time cursor broadcasts:
669
685
 
670
686
  ```typescript
671
- const server = await createDatafnServer({ schema, db: adapter });
687
+ const server = await createDatafnServer({ schema, database: adapter });
672
688
 
673
689
  // Wire WebSocket connections to server handler
674
690
  wss.on("connection", (ws) => {
@@ -702,7 +718,7 @@ const auditPlugin: DatafnPlugin = {
702
718
 
703
719
  const server = await createDatafnServer({
704
720
  schema,
705
- db: adapter,
721
+ database: adapter,
706
722
  plugins: [auditPlugin],
707
723
  });
708
724
  ```