@getforma/core 0.9.0 → 1.0.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 +20 -1
- package/dist/chunk-DCTOXHPF.cjs +399 -0
- package/dist/chunk-DCTOXHPF.cjs.map +1 -0
- package/dist/chunk-OUVOAYIO.js +359 -0
- package/dist/chunk-OUVOAYIO.js.map +1 -0
- package/dist/{chunk-YMIMKO4W.cjs → chunk-V732ZBCU.cjs} +119 -511
- package/dist/chunk-V732ZBCU.cjs.map +1 -0
- package/dist/{chunk-N522P3G6.js → chunk-VTPFK5TJ.js} +89 -442
- package/dist/chunk-VTPFK5TJ.js.map +1 -0
- package/dist/forma-runtime-csp.js +1 -1
- package/dist/forma-runtime.js +1 -1
- package/dist/formajs-runtime-hardened.global.js +1 -1
- package/dist/formajs-runtime-hardened.global.js.map +1 -1
- package/dist/formajs-runtime.global.js +1 -1
- package/dist/formajs-runtime.global.js.map +1 -1
- package/dist/formajs.global.js +1 -1
- package/dist/formajs.global.js.map +1 -1
- package/dist/http.cjs +225 -0
- package/dist/http.cjs.map +1 -0
- package/dist/http.d.cts +108 -0
- package/dist/http.d.ts +108 -0
- package/dist/http.js +220 -0
- package/dist/http.js.map +1 -0
- package/dist/index.cjs +71 -607
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -458
- package/dist/index.d.ts +4 -458
- package/dist/index.js +7 -523
- package/dist/index.js.map +1 -1
- package/dist/resource-Cd0cGOxS.d.ts +62 -0
- package/dist/resource-DK98lW5e.d.cts +62 -0
- package/dist/runtime-hardened.cjs +3 -111
- package/dist/runtime-hardened.cjs.map +1 -1
- package/dist/runtime-hardened.js +4 -112
- package/dist/runtime-hardened.js.map +1 -1
- package/dist/runtime.cjs +23 -22
- package/dist/runtime.cjs.map +1 -1
- package/dist/runtime.js +2 -1
- package/dist/runtime.js.map +1 -1
- package/dist/server.cjs +179 -0
- package/dist/server.cjs.map +1 -0
- package/dist/server.d.cts +217 -0
- package/dist/server.d.ts +217 -0
- package/dist/server.js +166 -0
- package/dist/server.js.map +1 -0
- package/dist/{signal-B4_wQJHs.d.cts → signal-YlS1kgfh.d.cts} +1 -1
- package/dist/{signal-B4_wQJHs.d.ts → signal-YlS1kgfh.d.ts} +1 -1
- package/dist/storage.cjs +151 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.d.cts +77 -0
- package/dist/storage.d.ts +77 -0
- package/dist/storage.js +147 -0
- package/dist/storage.js.map +1 -0
- package/dist/tc39-compat.d.cts +1 -1
- package/dist/tc39-compat.d.ts +1 -1
- package/package.json +31 -1
- package/dist/chunk-N522P3G6.js.map +0 -1
- package/dist/chunk-YMIMKO4W.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./jsx.d.ts" />
|
|
2
|
-
import { S as SignalGetter } from './signal-
|
|
3
|
-
export { c as createSignal } from './signal-
|
|
2
|
+
import { S as SignalGetter } from './signal-YlS1kgfh.cjs';
|
|
3
|
+
export { a as SignalOptions, b as SignalSetter, c as createSignal } from './signal-YlS1kgfh.cjs';
|
|
4
|
+
export { R as Resource, a as ResourceOptions, c as createResource } from './resource-DK98lW5e.cjs';
|
|
4
5
|
export { getBatchDepth, isComputed, isEffect, isEffectScope, isSignal, trigger } from 'alien-signals';
|
|
5
6
|
|
|
6
7
|
declare function createEffect(fn: () => void | (() => void)): () => void;
|
|
@@ -284,65 +285,6 @@ type Dispatch<A> = (action: A) => void;
|
|
|
284
285
|
*/
|
|
285
286
|
declare function createReducer<S, A>(reducer: (state: S, action: A) => S, initialState: S): [state: SignalGetter<S>, dispatch: Dispatch<A>];
|
|
286
287
|
|
|
287
|
-
/**
|
|
288
|
-
* Forma Reactive - Resource
|
|
289
|
-
*
|
|
290
|
-
* Async data fetching primitive with reactive loading/error state.
|
|
291
|
-
* Tracks a source signal and refetches when it changes.
|
|
292
|
-
*
|
|
293
|
-
* SolidJS equivalent: createResource
|
|
294
|
-
* React equivalent: use() + Suspense (React 19), or useSWR/react-query
|
|
295
|
-
*/
|
|
296
|
-
|
|
297
|
-
interface Resource<T> {
|
|
298
|
-
/** The resolved data (or undefined while loading). */
|
|
299
|
-
(): T | undefined;
|
|
300
|
-
/** True while the fetcher is running. */
|
|
301
|
-
loading: SignalGetter<boolean>;
|
|
302
|
-
/** The error if the fetcher rejected (or undefined). */
|
|
303
|
-
error: SignalGetter<unknown>;
|
|
304
|
-
/** Manually refetch with the current source value. */
|
|
305
|
-
refetch: () => void;
|
|
306
|
-
/** Manually set the data (overrides fetcher result). */
|
|
307
|
-
mutate: (value: T | undefined) => void;
|
|
308
|
-
}
|
|
309
|
-
interface ResourceOptions<T> {
|
|
310
|
-
/** Initial value before first fetch resolves. */
|
|
311
|
-
initialValue?: T;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Create an async resource that fetches data reactively.
|
|
315
|
-
*
|
|
316
|
-
* When `source` changes, the fetcher re-runs automatically.
|
|
317
|
-
* Provides reactive `loading` and `error` signals.
|
|
318
|
-
*
|
|
319
|
-
* ```ts
|
|
320
|
-
* const [userId, setUserId] = createSignal(1);
|
|
321
|
-
*
|
|
322
|
-
* const user = createResource(
|
|
323
|
-
* userId, // source signal
|
|
324
|
-
* (id) => fetch(`/api/users/${id}`).then(r => r.json()), // fetcher
|
|
325
|
-
* );
|
|
326
|
-
*
|
|
327
|
-
* internalEffect(() => {
|
|
328
|
-
* if (user.loading()) console.log('Loading...');
|
|
329
|
-
* else if (user.error()) console.log('Error:', user.error());
|
|
330
|
-
* else console.log('User:', user());
|
|
331
|
-
* });
|
|
332
|
-
*
|
|
333
|
-
* setUserId(2); // automatically refetches
|
|
334
|
-
* ```
|
|
335
|
-
*
|
|
336
|
-
* Without a source signal (static fetch):
|
|
337
|
-
* ```ts
|
|
338
|
-
* const posts = createResource(
|
|
339
|
-
* () => true, // constant source — fetches once
|
|
340
|
-
* () => fetch('/api/posts').then(r => r.json()),
|
|
341
|
-
* );
|
|
342
|
-
* ```
|
|
343
|
-
*/
|
|
344
|
-
declare function createResource<T, S = true>(source: SignalGetter<S>, fetcher: (source: S) => Promise<T>, options?: ResourceOptions<T>): Resource<T>;
|
|
345
|
-
|
|
346
288
|
type ErrorHandler = (error: unknown, info?: {
|
|
347
289
|
source?: string;
|
|
348
290
|
}) => void;
|
|
@@ -1052,400 +994,4 @@ declare function onResize(el: HTMLElement, handler: (entry: ResizeObserverEntry)
|
|
|
1052
994
|
declare function onIntersect(el: HTMLElement, handler: (entry: IntersectionObserverEntry) => void, options?: IntersectionObserverInit): () => void;
|
|
1053
995
|
declare function onMutation(el: HTMLElement, handler: (mutations: MutationRecord[]) => void, options?: MutationObserverInit): () => void;
|
|
1054
996
|
|
|
1055
|
-
|
|
1056
|
-
get(): T | null;
|
|
1057
|
-
set(value: T): void;
|
|
1058
|
-
remove(): void;
|
|
1059
|
-
key: string;
|
|
1060
|
-
}
|
|
1061
|
-
interface StorageOptions<T> {
|
|
1062
|
-
serialize?: (v: T) => string;
|
|
1063
|
-
deserialize?: (s: string) => T;
|
|
1064
|
-
/** Optional validator — return true if the deserialized value is valid. */
|
|
1065
|
-
validate?: (v: unknown) => v is T;
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
/**
|
|
1069
|
-
* Forma Storage - Local
|
|
1070
|
-
*
|
|
1071
|
-
* Typed localStorage wrapper with graceful error handling.
|
|
1072
|
-
* Zero dependencies — native browser APIs only.
|
|
1073
|
-
*/
|
|
1074
|
-
|
|
1075
|
-
/**
|
|
1076
|
-
* Create a typed localStorage wrapper for the given key.
|
|
1077
|
-
*
|
|
1078
|
-
* ```ts
|
|
1079
|
-
* const store = createLocalStorage<{ name: string }>('user');
|
|
1080
|
-
* store.set({ name: 'Alice' });
|
|
1081
|
-
* store.get(); // { name: 'Alice' }
|
|
1082
|
-
* store.remove();
|
|
1083
|
-
* ```
|
|
1084
|
-
*/
|
|
1085
|
-
declare function createLocalStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;
|
|
1086
|
-
|
|
1087
|
-
/**
|
|
1088
|
-
* Forma Storage - Session
|
|
1089
|
-
*
|
|
1090
|
-
* Typed sessionStorage wrapper with graceful error handling.
|
|
1091
|
-
* Zero dependencies — native browser APIs only.
|
|
1092
|
-
*/
|
|
1093
|
-
|
|
1094
|
-
/**
|
|
1095
|
-
* Create a typed sessionStorage wrapper for the given key.
|
|
1096
|
-
*
|
|
1097
|
-
* ```ts
|
|
1098
|
-
* const store = createSessionStorage<{ token: string }>('auth');
|
|
1099
|
-
* store.set({ token: 'abc123' });
|
|
1100
|
-
* store.get(); // { token: 'abc123' }
|
|
1101
|
-
* store.remove();
|
|
1102
|
-
* ```
|
|
1103
|
-
*/
|
|
1104
|
-
declare function createSessionStorage<T>(key: string, options?: StorageOptions<T>): TypedStorage<T>;
|
|
1105
|
-
|
|
1106
|
-
/**
|
|
1107
|
-
* Forma Storage - IndexedDB
|
|
1108
|
-
*
|
|
1109
|
-
* Simplified IndexedDB wrapper with lazy connection and promise-based API.
|
|
1110
|
-
* Zero dependencies — native browser APIs only.
|
|
1111
|
-
*/
|
|
1112
|
-
interface IDBStore<T> {
|
|
1113
|
-
get(key: string): Promise<T | undefined>;
|
|
1114
|
-
set(key: string, value: T): Promise<void>;
|
|
1115
|
-
delete(key: string): Promise<void>;
|
|
1116
|
-
getAll(): Promise<T[]>;
|
|
1117
|
-
keys(): Promise<string[]>;
|
|
1118
|
-
clear(): Promise<void>;
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Create a simplified IndexedDB store.
|
|
1122
|
-
*
|
|
1123
|
-
* ```ts
|
|
1124
|
-
* const store = createIndexedDB<User>('myApp', 'users');
|
|
1125
|
-
* await store.set('u1', { name: 'Alice' });
|
|
1126
|
-
* const user = await store.get('u1'); // { name: 'Alice' }
|
|
1127
|
-
* ```
|
|
1128
|
-
*/
|
|
1129
|
-
declare function createIndexedDB<T>(dbName: string, storeName?: string): IDBStore<T>;
|
|
1130
|
-
|
|
1131
|
-
/**
|
|
1132
|
-
* Forma HTTP - Fetch
|
|
1133
|
-
*
|
|
1134
|
-
* Typed fetch wrapper with reactive signal integration.
|
|
1135
|
-
* Zero dependencies — native browser APIs only.
|
|
1136
|
-
*/
|
|
1137
|
-
interface FetchOptions<T> extends Omit<RequestInit, 'signal'> {
|
|
1138
|
-
base?: string;
|
|
1139
|
-
params?: Record<string, string>;
|
|
1140
|
-
timeout?: number;
|
|
1141
|
-
transform?: (data: unknown) => T;
|
|
1142
|
-
}
|
|
1143
|
-
interface FetchResult<T> {
|
|
1144
|
-
data: () => T | null;
|
|
1145
|
-
error: () => Error | null;
|
|
1146
|
-
loading: () => boolean;
|
|
1147
|
-
refetch: () => Promise<void>;
|
|
1148
|
-
abort: () => void;
|
|
1149
|
-
}
|
|
1150
|
-
/**
|
|
1151
|
-
* Create a reactive fetch that exposes data/error/loading as signals.
|
|
1152
|
-
*
|
|
1153
|
-
* If `url` is a signal getter (function), an effect auto-refetches when it
|
|
1154
|
-
* changes.
|
|
1155
|
-
*
|
|
1156
|
-
* ```ts
|
|
1157
|
-
* const { data, loading, error, refetch, abort } = createFetch<User[]>('/api/users');
|
|
1158
|
-
* ```
|
|
1159
|
-
*/
|
|
1160
|
-
declare function createFetch<T>(url: string | (() => string), options?: FetchOptions<T>): FetchResult<T>;
|
|
1161
|
-
/**
|
|
1162
|
-
* One-shot fetch that returns parsed JSON.
|
|
1163
|
-
*
|
|
1164
|
-
* ```ts
|
|
1165
|
-
* const users = await fetchJSON<User[]>('/api/users');
|
|
1166
|
-
* ```
|
|
1167
|
-
*/
|
|
1168
|
-
declare function fetchJSON<T>(url: string, options?: RequestInit): Promise<T>;
|
|
1169
|
-
|
|
1170
|
-
/**
|
|
1171
|
-
* Forma HTTP - Server-Sent Events
|
|
1172
|
-
*
|
|
1173
|
-
* Reactive SSE wrapper with signal integration.
|
|
1174
|
-
* Zero dependencies — native browser APIs only.
|
|
1175
|
-
*/
|
|
1176
|
-
interface SSEOptions<T = unknown> {
|
|
1177
|
-
withCredentials?: boolean;
|
|
1178
|
-
headers?: Record<string, string>;
|
|
1179
|
-
/** Custom parser for incoming messages. Defaults to JSON.parse with raw data fallback. */
|
|
1180
|
-
parse?: (data: string) => T;
|
|
1181
|
-
}
|
|
1182
|
-
interface SSEConnection<T = unknown> {
|
|
1183
|
-
data: () => T | null;
|
|
1184
|
-
error: () => Event | null;
|
|
1185
|
-
connected: () => boolean;
|
|
1186
|
-
close: () => void;
|
|
1187
|
-
on(event: string, handler: (data: unknown) => void): () => void;
|
|
1188
|
-
}
|
|
1189
|
-
/**
|
|
1190
|
-
* Create a reactive Server-Sent Events connection.
|
|
1191
|
-
*
|
|
1192
|
-
* ```ts
|
|
1193
|
-
* const sse = createSSE<{ message: string }>('/api/events');
|
|
1194
|
-
* createEffect(() => {
|
|
1195
|
-
* const msg = sse.data();
|
|
1196
|
-
* if (msg) console.log(msg.message);
|
|
1197
|
-
* });
|
|
1198
|
-
* ```
|
|
1199
|
-
*/
|
|
1200
|
-
declare function createSSE<T = unknown>(url: string, options?: SSEOptions<T>): SSEConnection<T>;
|
|
1201
|
-
|
|
1202
|
-
/**
|
|
1203
|
-
* Forma HTTP - WebSocket
|
|
1204
|
-
*
|
|
1205
|
-
* Reactive WebSocket wrapper with auto-reconnect and signal integration.
|
|
1206
|
-
* Zero dependencies — native browser APIs only.
|
|
1207
|
-
*/
|
|
1208
|
-
type WSStatus = 'connecting' | 'open' | 'closed' | 'error';
|
|
1209
|
-
interface WSOptions<TReceive = unknown> {
|
|
1210
|
-
protocols?: string | string[];
|
|
1211
|
-
reconnect?: boolean;
|
|
1212
|
-
reconnectInterval?: number;
|
|
1213
|
-
maxReconnects?: number;
|
|
1214
|
-
/** Custom parser for incoming messages. Defaults to JSON.parse with raw data fallback. */
|
|
1215
|
-
parse?: (data: string) => TReceive;
|
|
1216
|
-
}
|
|
1217
|
-
interface WSConnection<TSend = unknown, TReceive = unknown> {
|
|
1218
|
-
data: () => TReceive | null;
|
|
1219
|
-
status: () => WSStatus;
|
|
1220
|
-
send(data: TSend): void;
|
|
1221
|
-
close(): void;
|
|
1222
|
-
on(handler: (data: TReceive) => void): () => void;
|
|
1223
|
-
}
|
|
1224
|
-
/**
|
|
1225
|
-
* Create a reactive WebSocket connection with auto-reconnect.
|
|
1226
|
-
*
|
|
1227
|
-
* ```ts
|
|
1228
|
-
* const ws = createWebSocket<string, ChatMessage>('wss://chat.example.com');
|
|
1229
|
-
* ws.send('hello');
|
|
1230
|
-
* createEffect(() => {
|
|
1231
|
-
* const msg = ws.data();
|
|
1232
|
-
* if (msg) console.log(msg);
|
|
1233
|
-
* });
|
|
1234
|
-
* ```
|
|
1235
|
-
*/
|
|
1236
|
-
declare function createWebSocket<TSend = unknown, TReceive = unknown>(url: string, options?: WSOptions<TReceive>): WSConnection<TSend, TReceive>;
|
|
1237
|
-
|
|
1238
|
-
/**
|
|
1239
|
-
* FormaJS Server - Action
|
|
1240
|
-
*
|
|
1241
|
-
* Creates an action that wraps a server function with optimistic UI support.
|
|
1242
|
-
* The action immediately applies an optimistic update, then reconciles when
|
|
1243
|
-
* the server responds (or rolls back on error).
|
|
1244
|
-
*/
|
|
1245
|
-
|
|
1246
|
-
interface ActionOptions<Args extends unknown[], Result> {
|
|
1247
|
-
/**
|
|
1248
|
-
* Apply an optimistic update immediately when the action is called.
|
|
1249
|
-
* This runs BEFORE the server function.
|
|
1250
|
-
* Store whatever you need to roll back in the return value or via closures.
|
|
1251
|
-
*/
|
|
1252
|
-
optimistic?: (...args: Args) => void;
|
|
1253
|
-
/**
|
|
1254
|
-
* Called when the server function resolves successfully.
|
|
1255
|
-
* Use this to apply the server result to local state.
|
|
1256
|
-
*/
|
|
1257
|
-
onSuccess?: (result: Result, ...args: Args) => void;
|
|
1258
|
-
/**
|
|
1259
|
-
* Called when the server function rejects.
|
|
1260
|
-
* Use this to roll back the optimistic update.
|
|
1261
|
-
*/
|
|
1262
|
-
onError?: (error: unknown, ...args: Args) => void;
|
|
1263
|
-
/**
|
|
1264
|
-
* Resources to refetch after the action completes successfully.
|
|
1265
|
-
* Used with single-flight mutations: if the server response includes
|
|
1266
|
-
* revalidation data, these resources are updated without a refetch.
|
|
1267
|
-
*/
|
|
1268
|
-
invalidates?: Resource<unknown>[];
|
|
1269
|
-
}
|
|
1270
|
-
interface Action<Args extends unknown[], Result> {
|
|
1271
|
-
/** Execute the action. */
|
|
1272
|
-
(...args: Args): Promise<Result>;
|
|
1273
|
-
/** Whether the action is currently in-flight. */
|
|
1274
|
-
pending: () => boolean;
|
|
1275
|
-
/** The last error from the action (or undefined). */
|
|
1276
|
-
error: () => unknown;
|
|
1277
|
-
/** Clear the error state. */
|
|
1278
|
-
clearError: () => void;
|
|
1279
|
-
}
|
|
1280
|
-
/**
|
|
1281
|
-
* Create an action that wraps a server function with optimistic UI.
|
|
1282
|
-
*
|
|
1283
|
-
* ```ts
|
|
1284
|
-
* const addTodo = createAction(
|
|
1285
|
-
* serverCreateTodo,
|
|
1286
|
-
* {
|
|
1287
|
-
* optimistic: (text) => {
|
|
1288
|
-
* // Immediately add to local list
|
|
1289
|
-
* setTodos(prev => [...prev, { text, done: false, id: 'temp' }]);
|
|
1290
|
-
* },
|
|
1291
|
-
* onSuccess: (result) => {
|
|
1292
|
-
* // Replace temp item with server result
|
|
1293
|
-
* setTodos(prev => prev.map(t => t.id === 'temp' ? result : t));
|
|
1294
|
-
* },
|
|
1295
|
-
* onError: (err, text) => {
|
|
1296
|
-
* // Remove the optimistic item
|
|
1297
|
-
* setTodos(prev => prev.filter(t => t.id !== 'temp'));
|
|
1298
|
-
* },
|
|
1299
|
-
* invalidates: [todosResource],
|
|
1300
|
-
* },
|
|
1301
|
-
* );
|
|
1302
|
-
*
|
|
1303
|
-
* // Use:
|
|
1304
|
-
* await addTodo('Buy milk');
|
|
1305
|
-
* ```
|
|
1306
|
-
*/
|
|
1307
|
-
declare function createAction<Args extends unknown[], Result>(serverFn: (...args: Args) => Promise<Result>, options?: ActionOptions<Args, Result>): Action<Args, Result>;
|
|
1308
|
-
|
|
1309
|
-
/**
|
|
1310
|
-
* FormaJS Server - Mutation
|
|
1311
|
-
*
|
|
1312
|
-
* Single-flight mutation pattern: the server response carries both the
|
|
1313
|
-
* mutation result AND fresh data for dependent resources in one round trip.
|
|
1314
|
-
*
|
|
1315
|
-
* Without single-flight:
|
|
1316
|
-
* Client -> Server: createTodo("Buy milk")
|
|
1317
|
-
* Server -> Client: { id: 1, text: "Buy milk" }
|
|
1318
|
-
* Client -> Server: GET /api/todos (refetch to update list)
|
|
1319
|
-
* Server -> Client: [all todos]
|
|
1320
|
-
*
|
|
1321
|
-
* With single-flight:
|
|
1322
|
-
* Client -> Server: createTodo("Buy milk")
|
|
1323
|
-
* Server -> Client: { data: {...}, __revalidate: { "/api/todos": [all todos] } }
|
|
1324
|
-
* (No second request needed!)
|
|
1325
|
-
*/
|
|
1326
|
-
|
|
1327
|
-
interface MutationResponse<T> {
|
|
1328
|
-
/** The mutation result. */
|
|
1329
|
-
data: T;
|
|
1330
|
-
/**
|
|
1331
|
-
* Fresh data for dependent resources, keyed by resource identifier.
|
|
1332
|
-
* When present, the client updates these resources directly instead of refetching.
|
|
1333
|
-
*/
|
|
1334
|
-
__revalidate?: Record<string, unknown>;
|
|
1335
|
-
}
|
|
1336
|
-
/**
|
|
1337
|
-
* Register a resource with a key so it can be revalidated by single-flight mutations.
|
|
1338
|
-
*
|
|
1339
|
-
* ```ts
|
|
1340
|
-
* const todos = createResource(
|
|
1341
|
-
* () => true,
|
|
1342
|
-
* () => fetch('/api/todos').then(r => r.json()),
|
|
1343
|
-
* );
|
|
1344
|
-
* registerResource('/api/todos', todos);
|
|
1345
|
-
* ```
|
|
1346
|
-
*/
|
|
1347
|
-
declare function registerResource(key: string, resource: Resource<unknown>): void;
|
|
1348
|
-
/**
|
|
1349
|
-
* Unregister a resource (call on cleanup/unmount).
|
|
1350
|
-
*/
|
|
1351
|
-
declare function unregisterResource(key: string): void;
|
|
1352
|
-
/**
|
|
1353
|
-
* Apply revalidation data from a single-flight mutation response.
|
|
1354
|
-
* For each key in the revalidate map, find the matching resource
|
|
1355
|
-
* and mutate it directly with the fresh data (skipping a refetch).
|
|
1356
|
-
*/
|
|
1357
|
-
declare function applyRevalidation(revalidateData: Record<string, unknown>): void;
|
|
1358
|
-
/**
|
|
1359
|
-
* Listen for revalidation events dispatched by $$serverFunction.
|
|
1360
|
-
* Call this once during app initialization to enable automatic
|
|
1361
|
-
* single-flight mutation handling.
|
|
1362
|
-
*
|
|
1363
|
-
* ```ts
|
|
1364
|
-
* // In your app entry:
|
|
1365
|
-
* import { enableAutoRevalidation } from 'forma/server/mutation';
|
|
1366
|
-
* enableAutoRevalidation();
|
|
1367
|
-
* ```
|
|
1368
|
-
*/
|
|
1369
|
-
declare function enableAutoRevalidation(): () => void;
|
|
1370
|
-
/**
|
|
1371
|
-
* Wrap a server function response to include revalidation data.
|
|
1372
|
-
* Use this on the server side to enable single-flight mutations.
|
|
1373
|
-
*
|
|
1374
|
-
* ```ts
|
|
1375
|
-
* // Server-side:
|
|
1376
|
-
* async function createTodo(text: string) {
|
|
1377
|
-
* "use server";
|
|
1378
|
-
* const newTodo = await db.insert('todos', { text, done: false });
|
|
1379
|
-
* const allTodos = await db.query('todos');
|
|
1380
|
-
* return withRevalidation(newTodo, {
|
|
1381
|
-
* '/api/todos': allTodos,
|
|
1382
|
-
* });
|
|
1383
|
-
* }
|
|
1384
|
-
* ```
|
|
1385
|
-
*/
|
|
1386
|
-
declare function withRevalidation<T>(data: T, revalidate: Record<string, unknown>): MutationResponse<T>;
|
|
1387
|
-
|
|
1388
|
-
/**
|
|
1389
|
-
* FormaJS Server - RPC Client
|
|
1390
|
-
*
|
|
1391
|
-
* Provides the client-side stub function that replaces "use server" function
|
|
1392
|
-
* bodies after compilation. Each call becomes a fetch POST to the server endpoint.
|
|
1393
|
-
*/
|
|
1394
|
-
/**
|
|
1395
|
-
* Create an RPC stub function for a server function.
|
|
1396
|
-
* This replaces the original function body on the client side.
|
|
1397
|
-
*
|
|
1398
|
-
* @param endpoint - The RPC endpoint path (e.g. "/rpc/createTodo_a1b2c3")
|
|
1399
|
-
* @returns An async function that sends args to the server and returns the result
|
|
1400
|
-
*/
|
|
1401
|
-
declare function $$serverFunction<T extends (...args: unknown[]) => Promise<unknown>>(endpoint: string): T;
|
|
1402
|
-
|
|
1403
|
-
/**
|
|
1404
|
-
* FormaJS Server - RPC Handler
|
|
1405
|
-
*
|
|
1406
|
-
* Server-side registry and request handler for "use server" functions.
|
|
1407
|
-
* Framework-agnostic — works with any Node.js HTTP server, Express, Hono, etc.
|
|
1408
|
-
*/
|
|
1409
|
-
type ServerFunction = (...args: unknown[]) => Promise<unknown>;
|
|
1410
|
-
/**
|
|
1411
|
-
* Register a server function at a specific endpoint.
|
|
1412
|
-
* Called by the server-side compiled output.
|
|
1413
|
-
*/
|
|
1414
|
-
declare function registerServerFunction(endpoint: string, fn: ServerFunction): void;
|
|
1415
|
-
/**
|
|
1416
|
-
* Get a registered server function by endpoint.
|
|
1417
|
-
*/
|
|
1418
|
-
declare function getServerFunction(endpoint: string): ServerFunction | undefined;
|
|
1419
|
-
/**
|
|
1420
|
-
* Get all registered server function endpoints.
|
|
1421
|
-
*/
|
|
1422
|
-
declare function getRegisteredEndpoints(): string[];
|
|
1423
|
-
interface RPCRequest {
|
|
1424
|
-
args: unknown[];
|
|
1425
|
-
}
|
|
1426
|
-
interface RPCResponse {
|
|
1427
|
-
data?: unknown;
|
|
1428
|
-
error?: string;
|
|
1429
|
-
__revalidate?: Record<string, unknown>;
|
|
1430
|
-
}
|
|
1431
|
-
declare function handleRPC(endpoint: string, body: RPCRequest, revalidateData?: Record<string, unknown>): Promise<RPCResponse>;
|
|
1432
|
-
/**
|
|
1433
|
-
* Create a middleware-style handler for use with Express-like frameworks.
|
|
1434
|
-
*
|
|
1435
|
-
* ```ts
|
|
1436
|
-
* import { createRPCMiddleware } from 'forma/server/rpc-handler';
|
|
1437
|
-
* app.use('/rpc', createRPCMiddleware());
|
|
1438
|
-
* ```
|
|
1439
|
-
*/
|
|
1440
|
-
declare function createRPCMiddleware(): (req: {
|
|
1441
|
-
url: string;
|
|
1442
|
-
method: string;
|
|
1443
|
-
body?: unknown;
|
|
1444
|
-
}, res: {
|
|
1445
|
-
json: (data: unknown) => void;
|
|
1446
|
-
status: (code: number) => {
|
|
1447
|
-
json: (data: unknown) => void;
|
|
1448
|
-
};
|
|
1449
|
-
}) => Promise<void>;
|
|
1450
|
-
|
|
1451
|
-
export { $, $$, $$serverFunction, type Action, type ActionOptions, Fragment, type IslandHydrateFn, type MutationResponse, type RPCRequest, type RPCResponse, activateIslands, addClass, applyRevalidation, batch, children, cleanup, closest, createAction, createBus, createComputed, createContext, createEffect, createErrorBoundary, createFetch, createHistory, createIndexedDB, createList, createLocalStorage, createMemo, createPortal, createRPCMiddleware, createReducer, createRef, createResource, createRoot, createSSE, createSessionStorage, createShow, createStore, createSuspense, createSwitch, createText, createWebSocket, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, enableAutoRevalidation, fetchJSON, fragment, getRegisteredEndpoints, getServerFunction, h, handleRPC, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, registerResource, registerServerFunction, removeClass, setAttr, setHTML, setHTMLUnsafe, setStyle, setText, siblings, toggleClass, trackDisposer, unprovide, unregisterResource, untrack, withRevalidation };
|
|
997
|
+
export { $, $$, type CleanupFn, type ComponentDef, type Context, type CreateListOptions, type Dispatch, type ErrorHandler, type EventBus, Fragment, type HistoryControls, type IslandHydrateFn, type KeyOptions, type ListTransitionHooks, type PersistOptions, type ReconcileResult, type Ref, type SetupFn, SignalGetter, type StoreSetter, type SwitchCase, activateIslands, addClass, batch, children, cleanup, closest, createBus, createComputed, createContext, createEffect, createErrorBoundary, createHistory, createList, createMemo, createPortal, createReducer, createRef, createRoot, createShow, createStore, createSuspense, createSwitch, createText, deactivateAllIslands, deactivateIsland, defineComponent, delegate, disposeComponent, fragment, h, hydrateIsland, inject, mount, nextSibling, on, onCleanup, onError, onIntersect, onKey, onMount, onMutation, onResize, onUnmount, parent, persist, prevSibling, provide, reconcileList, removeClass, setAttr, setHTML, setHTMLUnsafe, setStyle, setText, siblings, toggleClass, trackDisposer, unprovide, untrack };
|