@byearlybird/starling 0.12.0 → 0.13.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.
@@ -1,199 +0,0 @@
1
- import { a as AnyObject, c as StarlingDocument } from "./index-BIpu-1zO.js";
2
-
3
- //#region src/database/standard-schema.d.ts
4
- /** The Standard Schema interface. */
5
- interface StandardSchemaV1<Input = unknown, Output = Input> {
6
- /** The Standard Schema properties. */
7
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
8
- }
9
- declare namespace StandardSchemaV1 {
10
- /** The Standard Schema properties interface. */
11
- interface Props<Input = unknown, Output = Input> {
12
- /** The version number of the standard. */
13
- readonly version: 1;
14
- /** The vendor name of the schema library. */
15
- readonly vendor: string;
16
- /** Validates unknown input values. */
17
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
18
- /** Inferred types associated with the schema. */
19
- readonly types?: Types<Input, Output> | undefined;
20
- }
21
- /** The result interface of the validate function. */
22
- type Result<Output> = SuccessResult<Output> | FailureResult;
23
- /** The result interface if validation succeeds. */
24
- interface SuccessResult<Output> {
25
- /** The typed output value. */
26
- readonly value: Output;
27
- /** The non-existent issues. */
28
- readonly issues?: undefined;
29
- }
30
- /** The result interface if validation fails. */
31
- interface FailureResult {
32
- /** The issues of failed validation. */
33
- readonly issues: ReadonlyArray<Issue>;
34
- }
35
- /** The issue interface of the failure output. */
36
- interface Issue {
37
- /** The error message of the issue. */
38
- readonly message: string;
39
- /** The path of the issue, if any. */
40
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
41
- }
42
- /** The path segment interface of the issue. */
43
- interface PathSegment {
44
- /** The key representing a path segment. */
45
- readonly key: PropertyKey;
46
- }
47
- /** The Standard Schema types interface. */
48
- interface Types<Input = unknown, Output = Input> {
49
- /** The input type of the schema. */
50
- readonly input: Input;
51
- /** The output type of the schema. */
52
- readonly output: Output;
53
- }
54
- /** Infers the input type of a Standard Schema. */
55
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
56
- /** Infers the output type of a Standard Schema. */
57
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
58
- }
59
- //#endregion
60
- //#region src/database/types.d.ts
61
- type AnyObjectSchema<T extends AnyObject = AnyObject> = StandardSchemaV1<T>;
62
- type SchemasMap = Record<string, AnyObjectSchema>;
63
- //#endregion
64
- //#region src/database/collection.d.ts
65
- /**
66
- * Symbols for internal collection methods used by transactions.
67
- * These are not part of the public Collection type.
68
- */
69
- declare const CollectionInternals: {
70
- readonly getPendingMutations: symbol;
71
- readonly emitMutations: symbol;
72
- readonly replaceData: symbol;
73
- readonly data: symbol;
74
- };
75
- /** Shorthand for extracting the data type from a schema */
76
- type InferData<T extends AnyObjectSchema> = StandardSchemaV1.InferOutput<T>;
77
- type MutationBatch<T> = {
78
- added: Array<{
79
- id: string;
80
- item: T;
81
- }>;
82
- updated: Array<{
83
- id: string;
84
- before: T;
85
- after: T;
86
- }>;
87
- removed: Array<{
88
- id: string;
89
- item: T;
90
- }>;
91
- };
92
- type CollectionMutationEvent<T> = MutationBatch<T>;
93
- type Collection<T extends AnyObjectSchema> = {
94
- get(id: string, opts?: {
95
- includeDeleted?: boolean;
96
- }): InferData<T> | null;
97
- getAll(opts?: {
98
- includeDeleted?: boolean;
99
- }): InferData<T>[];
100
- find<U = InferData<T>>(filter: (item: InferData<T>) => boolean, opts?: {
101
- map?: (item: InferData<T>) => U;
102
- sort?: (a: U, b: U) => number;
103
- }): U[];
104
- add(item: StandardSchemaV1.InferInput<T>): InferData<T>;
105
- update(id: string, updates: Partial<StandardSchemaV1.InferInput<T>>): void;
106
- remove(id: string): void;
107
- merge(document: StarlingDocument<InferData<T>>): void;
108
- toDocument(): StarlingDocument<InferData<T>>;
109
- on(event: "mutation", handler: (payload: CollectionMutationEvent<InferData<T>>) => void): () => void;
110
- };
111
- declare class IdNotFoundError extends Error {
112
- constructor(id: string);
113
- }
114
- declare class DuplicateIdError extends Error {
115
- constructor(id: string);
116
- }
117
- //#endregion
118
- //#region src/database/query.d.ts
119
- /** Read-only collection handle for queries */
120
- type QueryCollectionHandle<T extends AnyObjectSchema> = Pick<Collection<T>, "get" | "getAll" | "find">;
121
- /** Query context with read-only collection handles */
122
- type QueryContext<Schemas extends SchemasMap> = { [K in keyof Schemas]: QueryCollectionHandle<Schemas[K]> };
123
- /** Handle returned by db.query() for managing the reactive query */
124
- type QueryHandle<R> = {
125
- /** Current query result */
126
- readonly result: R;
127
- /** Subscribe to result changes. Returns unsubscribe function. */
128
- subscribe(callback: (result: R) => void): () => void;
129
- /** Stop tracking and clean up subscriptions */
130
- dispose(): void;
131
- };
132
- //#endregion
133
- //#region src/database/transaction.d.ts
134
- /** Transaction-safe collection handle that excludes event subscription and serialization */
135
- type TransactionCollectionHandle<T extends AnyObjectSchema> = Omit<Collection<T>, "on" | "toDocument">;
136
- type TransactionCollectionHandles<Schemas extends SchemasMap> = { [K in keyof Schemas]: TransactionCollectionHandle<Schemas[K]> };
137
- type TransactionContext<Schemas extends SchemasMap> = TransactionCollectionHandles<Schemas> & {
138
- rollback(): void;
139
- };
140
- //#endregion
141
- //#region src/database/db.d.ts
142
- type Collections<Schemas extends SchemasMap> = { [K in keyof Schemas]: Collection<Schemas[K]> };
143
- type CollectionConfigMap<Schemas extends SchemasMap> = { [K in keyof Schemas]: CollectionConfig<Schemas[K]> };
144
- type MutationEnvelope<Schemas extends SchemasMap> = { [K in keyof Schemas]: {
145
- collection: K;
146
- } & MutationBatch<StandardSchemaV1.InferOutput<Schemas[K]>> }[keyof Schemas];
147
- type DatabaseMutationEvent<Schemas extends SchemasMap> = MutationEnvelope<Schemas>;
148
- type CollectionConfig<T extends AnyObjectSchema> = {
149
- schema: T;
150
- getId: (item: StandardSchemaV1.InferOutput<T>) => string;
151
- };
152
- type DatabasePlugin<Schemas extends SchemasMap> = {
153
- handlers: {
154
- init?: (db: Database<Schemas>) => Promise<unknown> | unknown;
155
- dispose?: (db: Database<Schemas>) => Promise<unknown> | unknown;
156
- };
157
- };
158
- type DbConfig<Schemas extends SchemasMap> = {
159
- name: string;
160
- schema: CollectionConfigMap<Schemas>;
161
- version?: number;
162
- };
163
- type Database<Schemas extends SchemasMap> = Collections<Schemas> & {
164
- name: string;
165
- version: number;
166
- begin<R>(callback: (tx: TransactionContext<Schemas>) => R): R;
167
- query<R>(callback: (ctx: QueryContext<Schemas>) => R): QueryHandle<R>;
168
- toDocuments(): { [K in keyof Schemas]: StarlingDocument<StandardSchemaV1.InferOutput<Schemas[K]>> };
169
- on(event: "mutation", handler: (payload: DatabaseMutationEvent<Schemas>) => unknown): () => void;
170
- use(plugin: DatabasePlugin<Schemas>): Database<Schemas>;
171
- init(): Promise<Database<Schemas>>;
172
- dispose(): Promise<void>;
173
- collectionKeys(): (keyof Schemas)[];
174
- };
175
- /**
176
- * Create a typed database instance with collection access.
177
- * @param config - Database configuration
178
- * @param config.name - Database name used for persistence and routing
179
- * @param config.schema - Collection schema definitions
180
- * @param config.version - Optional database version, defaults to 1
181
- * @returns A database instance with typed collection properties
182
- *
183
- * @example
184
- * ```typescript
185
- * const db = await createDatabase({
186
- * name: "my-app",
187
- * schema: {
188
- * tasks: { schema: taskSchema, getId: (task) => task.id },
189
- * },
190
- * })
191
- * .use(idbPlugin())
192
- * .init();
193
- *
194
- * const task = db.tasks.add({ title: 'Learn Starling' });
195
- * ```
196
- */
197
- declare function createDatabase<Schemas extends SchemasMap>(config: DbConfig<Schemas>): Database<Schemas>;
198
- //#endregion
199
- export { createDatabase as a, QueryCollectionHandle as c, Collection as d, CollectionInternals as f, StandardSchemaV1 as g, SchemasMap as h, DbConfig as i, QueryContext as l, IdNotFoundError as m, Database as n, TransactionCollectionHandle as o, DuplicateIdError as p, DatabasePlugin as r, TransactionContext as s, CollectionConfig as t, QueryHandle as u };
@@ -1,265 +0,0 @@
1
- //#region src/core/clock/clock.d.ts
2
- /**
3
- * A Hybrid Logical Clock that generates monotonically increasing eventstamps.
4
- * Combines wall-clock time with a counter for handling clock stalls and a
5
- * random nonce for tie-breaking.
6
- *
7
- * The clock automatically increments the counter when the wall clock doesn't
8
- * advance, ensuring eventstamps are always unique and monotonic.
9
- *
10
- * @example
11
- * ```typescript
12
- * const clock = createClock();
13
- * const stamp1 = clock.now();
14
- * const stamp2 = clock.now();
15
- * ```
16
- */
17
- type Clock = ReturnType<typeof createClock>;
18
- /**
19
- * Create a new Clock instance.
20
- * @param initialState - Optional initial state for the clock
21
- */
22
- declare function createClock(initialState?: {
23
- counter: number;
24
- lastMs: number;
25
- lastNonce: string;
26
- }): {
27
- now: () => string;
28
- latest: () => string;
29
- forward: (eventstamp: string) => void;
30
- };
31
- /**
32
- * Create a Clock from an eventstamp string.
33
- * @param eventstamp - Eventstamp string to decode and initialize clock from
34
- * @throws Error if eventstamp is invalid
35
- */
36
- declare function createClockFromEventstamp(eventstamp: string): Clock;
37
- //#endregion
38
- //#region src/core/clock/errors.d.ts
39
- declare class InvalidEventstampError extends Error {
40
- constructor(eventstamp: string);
41
- }
42
- //#endregion
43
- //#region src/core/clock/eventstamp.d.ts
44
- /**
45
- * Validates whether a string is a properly formatted eventstamp.
46
- * Expected format: YYYY-MM-DDTHH:mm:ss.SSSZ|HHHH+|HHHH
47
- * where HHHH+ represents 4 or more hex characters for the counter,
48
- * and HHHH represents exactly 4 hex characters for the nonce.
49
- */
50
- declare function isValidEventstamp(stamp: string): boolean;
51
- declare const MIN_EVENTSTAMP: string;
52
- /**
53
- * Find the maximum eventstamp from an array of eventstamps.
54
- * Returns MIN_EVENTSTAMP if the array is empty.
55
- * @param eventstamps - Array of eventstamp strings
56
- * @returns The maximum eventstamp
57
- */
58
- declare function maxEventstamp(eventstamps: string[]): string;
59
- //#endregion
60
- //#region src/core/document/resource.d.ts
61
- /**
62
- * Resource object structure representing a single stored entity.
63
- * Resources are the primary unit of storage and synchronization in Starling.
64
- *
65
- * Each resource has a unique identifier, attributes containing the data,
66
- * and metadata for tracking deletion state and eventstamps.
67
- * The resource type is stored at the document level.
68
- */
69
- type ResourceObject<T extends AnyObject> = {
70
- /** Unique identifier for this resource */
71
- id: string;
72
- /** The resource's data as a nested object structure */
73
- attributes: T;
74
- /** Metadata for tracking deletion and eventstamps */
75
- meta: {
76
- /** Flat map of dot-separated paths to eventstamps (e.g., "user.address.street": "2025-11-18...") */
77
- eventstamps: Record<string, string>;
78
- /** The greatest eventstamp in this resource (including deletedAt if applicable) */
79
- latest: string;
80
- /** Eventstamp when this resource was soft-deleted, or null if not deleted */
81
- deletedAt: string | null;
82
- };
83
- };
84
- declare function makeResource<T extends AnyObject>(id: string, obj: T, eventstamp: string, deletedAt?: string | null): ResourceObject<T>;
85
- declare function mergeResources<T extends AnyObject>(into: ResourceObject<T>, from: ResourceObject<T>): ResourceObject<T>;
86
- declare function deleteResource<T extends AnyObject>(resource: ResourceObject<T>, eventstamp: string): ResourceObject<T>;
87
- //#endregion
88
- //#region src/core/document/document.d.ts
89
- /**
90
- * Base constraint for all document data in Starling.
91
- * Documents must be plain JavaScript objects with string keys.
92
- */
93
- type AnyObject = Record<string, unknown>;
94
- /**
95
- * A Starling document represents the complete state of a collection:
96
- * - Resource type identifier
97
- * - Latest eventstamp for clock synchronization
98
- * - Map of resources keyed by ID
99
- *
100
- * Documents are the unit of synchronization between replicas.
101
- */
102
- type StarlingDocument<T extends AnyObject> = {
103
- /** Resource type for this homogeneous collection */
104
- type: string;
105
- /** Latest eventstamp observed by this document for clock synchronization */
106
- latest: string;
107
- /** Map of resources keyed by ID for efficient lookups */
108
- resources: Record<string, ResourceObject<T>>;
109
- };
110
- /**
111
- * Change tracking information returned by mergeDocuments.
112
- * Categorizes resources by mutation type for hook notifications.
113
- */
114
- type DocumentChanges<T extends AnyObject> = {
115
- /** Resources that were newly added (didn't exist before or were previously deleted) */
116
- added: Map<string, ResourceObject<T>>;
117
- /** Resources that were modified (existed before and changed) */
118
- updated: Map<string, ResourceObject<T>>;
119
- /** Resources that were deleted (newly marked with deletedAt) */
120
- deleted: Set<string>;
121
- };
122
- /**
123
- * Result of merging two Starling documents.
124
- */
125
- type MergeDocumentsResult<T extends AnyObject> = {
126
- /** The merged document with updated resources and forwarded clock */
127
- document: StarlingDocument<T>;
128
- /** Change tracking for plugin hook notifications */
129
- changes: DocumentChanges<T>;
130
- };
131
- /**
132
- * Merges two Starling documents using field-level Last-Write-Wins semantics.
133
- *
134
- * The merge operation:
135
- * 1. Forwards the clock to the newest eventstamp from either document
136
- * 2. Merges each resource pair using field-level LWW (via mergeResources)
137
- * 3. Tracks what changed for hook notifications (added/updated/deleted)
138
- *
139
- * Deletion is final: once a resource is deleted, updates to it are merged into
140
- * the resource's attributes but don't restore visibility. Only new resources or
141
- * transitions into the deleted state are tracked.
142
- *
143
- * @param into - The base document to merge into
144
- * @param from - The source document to merge from
145
- * @returns Merged document and categorized changes
146
- *
147
- * @example
148
- * ```typescript
149
- * const into = {
150
- * type: "items",
151
- * latest: "2025-01-01T00:00:00.000Z|0001|a1b2",
152
- * resources: { "doc1": { id: "doc1", attributes: {...}, meta: {...} } }
153
- * };
154
- *
155
- * const from = {
156
- * type: "items",
157
- * latest: "2025-01-01T00:05:00.000Z|0001|c3d4",
158
- * resources: {
159
- * "doc1": { id: "doc1", attributes: {...}, meta: {...} }, // updated
160
- * "doc2": { id: "doc2", attributes: {...}, meta: {...} } // new
161
- * }
162
- * };
163
- *
164
- * const result = mergeDocuments(into, from);
165
- * // result.document.latest === "2025-01-01T00:05:00.000Z|0001|c3d4"
166
- * // result.changes.added has "doc2"
167
- * // result.changes.updated has "doc1"
168
- * ```
169
- */
170
- declare function mergeDocuments<T extends AnyObject>(into: StarlingDocument<T>, from: StarlingDocument<T>): MergeDocumentsResult<T>;
171
- /**
172
- * Creates an empty Starling document with the given type and eventstamp.
173
- * Useful for initializing new stores or testing.
174
- *
175
- * @param type - Resource type identifier for this collection
176
- * @param eventstamp - Initial clock value for this document
177
- * @returns Empty document
178
- *
179
- * @example
180
- * ```typescript
181
- * const empty = makeDocument("tasks", "2025-01-01T00:00:00.000Z|0000|0000");
182
- * ```
183
- */
184
- declare function makeDocument<T extends AnyObject>(type: string, eventstamp: string): StarlingDocument<T>;
185
- //#endregion
186
- //#region src/core/document/utils.d.ts
187
- /**
188
- * Convert a StarlingDocument's resources into a Map keyed by resource ID.
189
- * @param document - StarlingDocument containing resource data
190
- * @returns Map of resource ID to ResourceObject
191
- */
192
- declare function documentToMap<T extends AnyObject>(document: StarlingDocument<T>): Map<string, ResourceObject<T>>;
193
- /**
194
- * Convert a Map of resources into a StarlingDocument.
195
- * @param type - Resource type identifier for this collection
196
- * @param resources - Map of resource ID to ResourceObject
197
- * @param fallbackEventstamp - Eventstamp to include when computing the max (optional)
198
- * @returns StarlingDocument representation of the resources
199
- */
200
- declare function mapToDocument<T extends AnyObject>(type: string, resources: Map<string, ResourceObject<T>>, fallbackEventstamp?: string): StarlingDocument<T>;
201
- //#endregion
202
- //#region src/core/resource-map/resource-map.d.ts
203
- /**
204
- * A ResourceMap container for storing and managing ResourceObjects.
205
- *
206
- * This factory function creates a ResourceMap with state-based replication
207
- * and automatic convergence via Last-Write-Wins conflict resolution.
208
- * It stores complete resource snapshots with encoded metadata, including deletion markers.
209
- *
210
- * ResourceMap does NOT filter based on deletion status—it stores and returns
211
- * all ResourceObjects including deleted ones. The Store class is responsible
212
- * for filtering what's visible to users.
213
- *
214
- * @example
215
- * ```typescript
216
- * const resourceMap = createMap("todos");
217
- * resourceMap.set("id1", { name: "Alice" });
218
- * const resource = resourceMap.get("id1"); // ResourceObject with metadata
219
- * ```
220
- */
221
- declare function createMap<T extends AnyObject>(resourceType: string, initialMap?: Map<string, ResourceObject<T>>, eventstamp?: string): {
222
- /**
223
- * Check if a resource exists by ID (regardless of deletion status).
224
- * @param id - Resource ID
225
- */
226
- has(id: string): boolean;
227
- /**
228
- * Get a resource by ID (regardless of deletion status).
229
- * @returns The raw resource with metadata (including deletedAt flag), or undefined if not found
230
- */
231
- get(id: string): ResourceObject<T> | undefined;
232
- /**
233
- * Iterate over all resources (including deleted) as [id, resource] tuples.
234
- */
235
- entries(): IterableIterator<readonly [string, ResourceObject<T>]>;
236
- /**
237
- * Set a resource using field-level Last-Write-Wins merge.
238
- * Creates a new resource if it doesn't exist, or merges with existing resource.
239
- * @param id - Resource ID (provided by caller, not generated)
240
- * @param object - Data to set (partial fields are merged, full objects replace)
241
- */
242
- set(id: string, object: Partial<T>): void;
243
- delete(id: string): void;
244
- /**
245
- * Clone the internal map of encoded resources.
246
- */
247
- cloneMap(): Map<string, ResourceObject<T>>;
248
- /**
249
- * Export the current state as a StarlingDocument snapshot.
250
- */
251
- toDocument(): StarlingDocument<T>;
252
- /**
253
- * Merge another document into this ResourceMap using field-level Last-Write-Wins.
254
- * @returns The merge result containing the merged document and tracked changes
255
- * @param document - StarlingDocument from another replica or storage
256
- */
257
- merge(document: StarlingDocument<T>): MergeDocumentsResult<T>;
258
- };
259
- /**
260
- * Create a ResourceMap from a StarlingDocument snapshot.
261
- * @param document - StarlingDocument containing resource data
262
- */
263
- declare function createMapFromDocument<U extends AnyObject>(document: StarlingDocument<U>): ReturnType<typeof createMap<U>>;
264
- //#endregion
265
- export { maxEventstamp as _, AnyObject as a, createClock as b, StarlingDocument as c, ResourceObject as d, deleteResource as f, isValidEventstamp as g, MIN_EVENTSTAMP as h, mapToDocument as i, makeDocument as l, mergeResources as m, createMapFromDocument as n, DocumentChanges as o, makeResource as p, documentToMap as r, MergeDocumentsResult as s, createMap as t, mergeDocuments as u, InvalidEventstampError as v, createClockFromEventstamp as x, Clock as y };
@@ -1,139 +0,0 @@
1
- import { a as AnyObject, c as StarlingDocument } from "./index-BIpu-1zO.js";
2
- import { h as SchemasMap, r as DatabasePlugin } from "./db-DY3UcmfV.js";
3
-
4
- //#region src/plugins/http/index.d.ts
5
-
6
- /**
7
- * Context provided to the onRequest hook
8
- */
9
- type RequestContext<T extends AnyObject = AnyObject> = {
10
- collection: string;
11
- operation: "GET" | "PATCH";
12
- url: string;
13
- document?: StarlingDocument<T>;
14
- };
15
- /**
16
- * Result returned by the onRequest hook
17
- */
18
- type RequestHookResult<T extends AnyObject = AnyObject> = {
19
- skip: true;
20
- } | {
21
- headers?: Record<string, string>;
22
- document?: StarlingDocument<T>;
23
- } | undefined;
24
- /**
25
- * Result returned by the onResponse hook
26
- */
27
- type ResponseHookResult<T extends AnyObject = AnyObject> = {
28
- document: StarlingDocument<T>;
29
- } | {
30
- skip: true;
31
- } | undefined;
32
- /**
33
- * Configuration for the HTTP plugin
34
- */
35
- type HttpPluginConfig<_Schemas extends SchemasMap> = {
36
- /**
37
- * Base URL for the HTTP server (e.g., "https://api.example.com")
38
- */
39
- baseUrl: string;
40
- /**
41
- * Interval in milliseconds to poll for server updates
42
- * @default 5000
43
- */
44
- pollingInterval?: number;
45
- /**
46
- * Delay in milliseconds to debounce local mutations before pushing
47
- * @default 1000
48
- */
49
- debounceDelay?: number;
50
- /**
51
- * Hook called before each HTTP request
52
- * Return { skip: true } to abort the request
53
- * Return { headers } to add custom headers
54
- * Return { document } to transform the document (PATCH only)
55
- */
56
- onRequest?: <T extends AnyObject>(context: RequestContext<T>) => RequestHookResult<T>;
57
- /**
58
- * Hook called after each successful HTTP response
59
- * Return { skip: true } to skip merging the response
60
- * Return { document } to transform the document before merging
61
- */
62
- onResponse?: <T extends AnyObject>(context: {
63
- collection: string;
64
- document: StarlingDocument<T>;
65
- }) => ResponseHookResult<T>;
66
- /**
67
- * Retry configuration for failed requests
68
- */
69
- retry?: {
70
- /**
71
- * Maximum number of retry attempts
72
- * @default 3
73
- */
74
- maxAttempts?: number;
75
- /**
76
- * Initial delay in milliseconds before first retry
77
- * @default 1000
78
- */
79
- initialDelay?: number;
80
- /**
81
- * Maximum delay in milliseconds between retries
82
- * @default 30000
83
- */
84
- maxDelay?: number;
85
- };
86
- };
87
- /**
88
- * Create an HTTP sync plugin for Starling databases.
89
- *
90
- * The plugin:
91
- * - Fetches all collections from the server on init (single attempt)
92
- * - Polls the server at regular intervals to fetch updates (with retry)
93
- * - Debounces local mutations and pushes them to the server (with retry)
94
- * - Supports request/response hooks for authentication, encryption, etc.
95
- *
96
- * @param config - HTTP plugin configuration
97
- * @returns A DatabasePlugin instance
98
- *
99
- * @example
100
- * ```typescript
101
- * const db = await createDatabase({
102
- * name: "my-app",
103
- * schema: {
104
- * tasks: { schema: taskSchema, getId: (task) => task.id },
105
- * },
106
- * })
107
- * .use(httpPlugin({
108
- * baseUrl: "https://api.example.com",
109
- * onRequest: () => ({
110
- * headers: { Authorization: `Bearer ${token}` }
111
- * })
112
- * }))
113
- * .init();
114
- * ```
115
- *
116
- * @example With encryption
117
- * ```typescript
118
- * const db = await createDatabase({
119
- * name: "my-app",
120
- * schema: {
121
- * tasks: { schema: taskSchema, getId: (task) => task.id },
122
- * },
123
- * })
124
- * .use(httpPlugin({
125
- * baseUrl: "https://api.example.com",
126
- * onRequest: ({ document }) => ({
127
- * headers: { Authorization: `Bearer ${token}` },
128
- * document: document ? encrypt(document) : undefined
129
- * }),
130
- * onResponse: ({ document }) => ({
131
- * document: decrypt(document)
132
- * })
133
- * }))
134
- * .init();
135
- * ```
136
- */
137
- declare function httpPlugin<Schemas extends SchemasMap>(config: HttpPluginConfig<Schemas>): DatabasePlugin<Schemas>;
138
- //#endregion
139
- export { HttpPluginConfig, RequestContext, RequestHookResult, ResponseHookResult, httpPlugin };