@pol-studios/db 1.0.19 → 1.0.21

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 (36) hide show
  1. package/dist/DataLayerContext-ZmLPYR_s.d.ts +825 -0
  2. package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
  3. package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
  4. package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
  5. package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
  6. package/dist/auth/context.d.ts +48 -0
  7. package/dist/auth/guards.d.ts +180 -0
  8. package/dist/auth/hooks.d.ts +312 -0
  9. package/dist/auth/index.d.ts +11 -0
  10. package/dist/client/index.d.ts +16 -0
  11. package/dist/core/index.d.ts +539 -0
  12. package/dist/database.types-ChFCG-4M.d.ts +8604 -0
  13. package/dist/executor-CB4KHyYG.d.ts +507 -0
  14. package/dist/gen/index.d.ts +1099 -0
  15. package/dist/hooks/index.d.ts +100 -0
  16. package/dist/index-BNKhgDdC.d.ts +433 -0
  17. package/dist/index.d.ts +33 -0
  18. package/dist/index.native.d.ts +793 -0
  19. package/dist/index.web.d.ts +321 -0
  20. package/dist/mutation/index.d.ts +58 -0
  21. package/dist/parser/index.d.ts +366 -0
  22. package/dist/powersync-bridge/index.d.ts +284 -0
  23. package/dist/query/index.d.ts +723 -0
  24. package/dist/realtime/index.d.ts +44 -0
  25. package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
  26. package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
  27. package/dist/types/index.d.ts +10 -0
  28. package/dist/types-CYr9JiUE.d.ts +62 -0
  29. package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
  30. package/dist/useDbCount-Id14x_1P.d.ts +1082 -0
  31. package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
  32. package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
  33. package/dist/useResolveFeedback-Ca2rh_Bs.d.ts +997 -0
  34. package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
  35. package/dist/with-auth/index.d.ts +704 -0
  36. package/package.json +61 -13
@@ -0,0 +1,539 @@
1
+ /**
2
+ * V3 Data Layer Core Types
3
+ *
4
+ * This module defines all type definitions for the V3 PowerSync-based data layer.
5
+ * These types support offline-first sync with Supabase through PowerSync.
6
+ */
7
+ /**
8
+ * Column type mappings for schema definitions
9
+ */
10
+ type ColumnType = "string" | "number" | "boolean" | "date" | "enum";
11
+ /**
12
+ * Information about a database column
13
+ */
14
+ interface ColumnInfo {
15
+ /** Column name */
16
+ name: string;
17
+ /** Column data type */
18
+ type: ColumnType;
19
+ /** Whether the column allows null values */
20
+ isOptional: boolean;
21
+ /** Whether this column is an enum type */
22
+ isEnum?: boolean;
23
+ /** Possible values if this is an enum column */
24
+ enumValues?: string[];
25
+ }
26
+ /**
27
+ * Information about a table relationship (foreign key)
28
+ */
29
+ interface RelationshipInfo {
30
+ /** The foreign key column name in this table */
31
+ foreignKey: string;
32
+ /** The table being referenced */
33
+ referencedTable: string;
34
+ /** The column in the referenced table (typically 'id') */
35
+ referencedColumn: string;
36
+ }
37
+ /**
38
+ * Schema definition for a single table
39
+ */
40
+ interface TableSchema {
41
+ /** Table name */
42
+ name: string;
43
+ /** Column definitions */
44
+ columns: ColumnInfo[];
45
+ /** Foreign key relationships */
46
+ relationships: RelationshipInfo[];
47
+ }
48
+ /**
49
+ * Complete database schema definition
50
+ */
51
+ interface DatabaseSchema {
52
+ schemas: {
53
+ [schemaName: string]: {
54
+ tables: Record<string, TableSchema>;
55
+ views: Record<string, TableSchema>;
56
+ };
57
+ };
58
+ }
59
+ /**
60
+ * Sync scope determines which data is synced locally.
61
+ * "global" means all data accessible to the user.
62
+ * Custom strings reference scope definitions (e.g., "activeProject").
63
+ */
64
+ type SyncScope = "global" | string;
65
+ /**
66
+ * PowerSync strategy - data is synced to local SQLite via PowerSync
67
+ */
68
+ interface PowerSyncStrategy {
69
+ strategy: "powersync";
70
+ /** Which scope controls what data to sync */
71
+ syncScope: SyncScope;
72
+ /**
73
+ * Alias used in PowerSync schema for this table.
74
+ * Required when multiple schemas have tables with the same name.
75
+ * If not provided, auto-generated from schema.Table → SchemaTable (PascalCase).
76
+ * Example: "core.Profile" → "CoreProfile"
77
+ */
78
+ alias?: string;
79
+ }
80
+ /**
81
+ * Supabase strategy - always query directly from Supabase (online only)
82
+ */
83
+ interface SupabaseStrategy {
84
+ strategy: "supabase";
85
+ }
86
+ /**
87
+ * Cached strategy - query Supabase and cache in memory
88
+ */
89
+ interface CachedStrategy {
90
+ strategy: "cached";
91
+ /** How long to cache data in milliseconds */
92
+ cacheTime: number;
93
+ }
94
+ /**
95
+ * Hybrid strategy - use PowerSync for recent data, fallback to cached for older
96
+ */
97
+ interface HybridStrategy {
98
+ strategy: "hybrid";
99
+ /** PowerSync configuration for frequently accessed data */
100
+ powersync: {
101
+ scope: SyncScope;
102
+ /** Optional limit on how many records to sync locally */
103
+ limit?: number;
104
+ };
105
+ /** Fallback for data not synced locally */
106
+ fallback: CachedStrategy;
107
+ /**
108
+ * Alias used in PowerSync schema for this table.
109
+ * See PowerSyncStrategy.alias for details.
110
+ */
111
+ alias?: string;
112
+ }
113
+ /**
114
+ * Auto strategy - automatically selects best backend at runtime
115
+ */
116
+ interface AutoStrategy {
117
+ strategy: "auto";
118
+ /** Prefer PowerSync when available (default: true) */
119
+ preferPowerSync?: boolean;
120
+ }
121
+ /**
122
+ * Union type for all table strategies
123
+ */
124
+ type TableStrategy = PowerSyncStrategy | SupabaseStrategy | CachedStrategy | HybridStrategy | AutoStrategy;
125
+ /**
126
+ * Connection configuration for Supabase and PowerSync
127
+ */
128
+ interface ConnectionConfig {
129
+ supabase: {
130
+ /** Supabase project URL */
131
+ url: string;
132
+ /** Supabase anonymous key */
133
+ anonKey: string;
134
+ };
135
+ powerSync: {
136
+ /** PowerSync service URL */
137
+ url: string;
138
+ };
139
+ }
140
+ /**
141
+ * Definition for a sync scope
142
+ */
143
+ interface ScopeDefinition {
144
+ /**
145
+ * Parameter key used to pass scope values to PowerSync sync rules.
146
+ * For example, "activeProjectIds" would pass selected project IDs to filter sync.
147
+ */
148
+ parameterKey?: string;
149
+ }
150
+ /**
151
+ * Sync mode determines when and how syncing occurs
152
+ */
153
+ type SyncMode =
154
+ /** Manual - only sync when explicitly requested */
155
+ "manual"
156
+ /** On foreground - sync when app comes to foreground */
157
+ | "onForeground"
158
+ /** Periodic - sync at regular intervals */
159
+ | "periodic"
160
+ /** Live - maintain continuous sync connection */
161
+ | "live";
162
+ /**
163
+ * Main configuration for the data layer
164
+ * @template DB - The database types (from generated types)
165
+ */
166
+ interface DataLayerConfig<DB = unknown> {
167
+ /** Database schema definition */
168
+ schema: DatabaseSchema;
169
+ /** Connection configuration */
170
+ connections: ConnectionConfig;
171
+ /** Per-table strategy configuration */
172
+ tables: {
173
+ [tableName: string]: TableStrategy;
174
+ };
175
+ /** Scope definitions */
176
+ scopes: {
177
+ [scopeName: string]: ScopeDefinition;
178
+ };
179
+ /** Default settings */
180
+ defaults: {
181
+ /** Default sync mode */
182
+ syncMode: SyncMode;
183
+ /** Interval for periodic sync in milliseconds (default: 300000 = 5 min) */
184
+ periodicIntervalMs?: number;
185
+ };
186
+ /**
187
+ * Options for initial sync behavior when using PowerSync.
188
+ */
189
+ initialSync?: {
190
+ /**
191
+ * Use Supabase for queries until PowerSync completes initial sync.
192
+ *
193
+ * When true (default): Queries return online data from Supabase while
194
+ * PowerSync is downloading initial data, ensuring users see content
195
+ * immediately. Once sync completes, queries automatically switch to
196
+ * the local PowerSync database for offline-first operation.
197
+ *
198
+ * When false: Queries always use PowerSync (which may be empty during
199
+ * initial sync), showing loading states until data is available locally.
200
+ *
201
+ * @default true
202
+ */
203
+ useOnlineUntilSynced?: boolean;
204
+ };
205
+ }
206
+ /**
207
+ * Comparison operators for where clauses
208
+ */
209
+ interface WhereOperators {
210
+ /** In array of values */
211
+ in?: (string | number)[];
212
+ /** Greater than */
213
+ gt?: number;
214
+ /** Greater than or equal */
215
+ gte?: number;
216
+ /** Less than */
217
+ lt?: number;
218
+ /** Less than or equal */
219
+ lte?: number;
220
+ /** LIKE pattern matching */
221
+ like?: string;
222
+ /** IS NULL check */
223
+ is?: null;
224
+ /** NOT equal */
225
+ neq?: string | number | boolean | null;
226
+ /** NOT in array */
227
+ notIn?: (string | number)[];
228
+ }
229
+ /**
230
+ * Where clause for filtering queries
231
+ */
232
+ interface WhereClause {
233
+ [field: string]: string | number | boolean | null | WhereOperators;
234
+ }
235
+ /**
236
+ * Order by clause for sorting results
237
+ */
238
+ interface OrderBy {
239
+ /** Field to sort by */
240
+ field: string;
241
+ /** Sort direction */
242
+ direction: "asc" | "desc";
243
+ }
244
+ /**
245
+ * Options for query hooks
246
+ */
247
+ interface QueryOptions {
248
+ /**
249
+ * Select clause - supports relation syntax like "*, Relation(*)"
250
+ * Similar to Supabase select syntax
251
+ */
252
+ select?: string;
253
+ /** Where clause for filtering */
254
+ where?: WhereClause;
255
+ /** Order by clauses */
256
+ orderBy?: OrderBy[];
257
+ /** Maximum number of records to return */
258
+ limit?: number;
259
+ /** Number of records to skip */
260
+ offset?: number;
261
+ /**
262
+ * Whether the query is enabled.
263
+ * Set to false to disable the query (useful for conditional fetching)
264
+ */
265
+ enabled?: boolean;
266
+ }
267
+ /**
268
+ * Result returned from query hooks
269
+ * @template T - The type of data being queried
270
+ */
271
+ interface QueryResult<T> {
272
+ /** The queried data (undefined while loading) */
273
+ data: T[] | undefined;
274
+ /** True during initial load with no data */
275
+ isLoading: boolean;
276
+ /** True when no data has been fetched yet */
277
+ isPending: boolean;
278
+ /** True when fetching (including background refetch) */
279
+ isFetching: boolean;
280
+ /** Error if the query failed */
281
+ error: Error | null;
282
+ /** Function to manually refetch data */
283
+ refetch: () => Promise<void>;
284
+ }
285
+ /**
286
+ * Result for a single-item query
287
+ * @template T - The type of data being queried
288
+ */
289
+ interface QuerySingleResult<T> {
290
+ /** The queried data (undefined while loading, null if not found) */
291
+ data: T | null | undefined;
292
+ /** True during initial load with no data */
293
+ isLoading: boolean;
294
+ /** True when no data has been fetched yet */
295
+ isPending: boolean;
296
+ /** True when fetching (including background refetch) */
297
+ isFetching: boolean;
298
+ /** Error if the query failed */
299
+ error: Error | null;
300
+ /** Function to manually refetch data */
301
+ refetch: () => Promise<void>;
302
+ }
303
+ /**
304
+ * Result from a single mutation operation
305
+ * @template T - The type of data being mutated
306
+ */
307
+ interface MutationResult<T> {
308
+ /** Fire-and-forget mutation */
309
+ mutate: (data: Partial<T>) => void;
310
+ /** Async mutation that returns the result */
311
+ mutateAsync: (data: Partial<T>) => Promise<T>;
312
+ /** Whether the mutation is in progress */
313
+ isPending: boolean;
314
+ /** Error if the mutation failed */
315
+ error: Error | null;
316
+ }
317
+ /**
318
+ * Result from a delete mutation
319
+ */
320
+ interface DeleteMutationResult {
321
+ /** Fire-and-forget delete */
322
+ mutate: (id: string) => void;
323
+ /** Async delete */
324
+ mutateAsync: (id: string) => Promise<void>;
325
+ /** Whether the delete is in progress */
326
+ isPending: boolean;
327
+ /** Error if the delete failed */
328
+ error: Error | null;
329
+ }
330
+ /**
331
+ * Complete mutation hook result with all CRUD operations
332
+ * @template T - The type of data being mutated
333
+ */
334
+ interface MutationHookResult<T> {
335
+ /** Upsert operation (insert or update based on primary key) */
336
+ upsert: MutationResult<T>;
337
+ /** Insert operation */
338
+ insert: MutationResult<T>;
339
+ /** Update operation */
340
+ update: MutationResult<T>;
341
+ /** Remove/delete operation */
342
+ remove: DeleteMutationResult;
343
+ /** Whether any mutation is in progress */
344
+ isPending: boolean;
345
+ }
346
+ /**
347
+ * Current sync status
348
+ */
349
+ interface SyncStatus {
350
+ /** Whether connected to PowerSync service */
351
+ isConnected: boolean;
352
+ /** Whether currently syncing data */
353
+ isSyncing: boolean;
354
+ /** When the last successful sync completed */
355
+ lastSyncedAt: Date | null;
356
+ /** Number of local changes pending upload */
357
+ pendingUploads: number;
358
+ /** Any sync error */
359
+ error: Error | null;
360
+ }
361
+ /**
362
+ * Controls for managing sync behavior
363
+ */
364
+ interface SyncControl {
365
+ /** Manually trigger a sync */
366
+ triggerSync: () => Promise<void>;
367
+ /** Start continuous live sync */
368
+ startLiveSync: () => Promise<void>;
369
+ /** Stop continuous sync */
370
+ stopLiveSync: () => void;
371
+ /**
372
+ * Set scope values to control what data is synced
373
+ * @param scopeName - Name of the scope (e.g., "activeProject")
374
+ * @param values - Array of values (e.g., project IDs)
375
+ */
376
+ setScope: (scopeName: string, values: string[]) => Promise<void>;
377
+ }
378
+ /**
379
+ * Interface that all data adapters must implement
380
+ * @template T - The row type
381
+ */
382
+ interface DataAdapter<T = unknown> {
383
+ /** Query multiple records */
384
+ query(options: QueryOptions): Promise<T[]>;
385
+ /** Query a single record by ID */
386
+ queryById(id: string, options?: Pick<QueryOptions, "select">): Promise<T | null>;
387
+ /** Insert a new record */
388
+ insert(data: Partial<T>): Promise<T>;
389
+ /** Update an existing record */
390
+ update(id: string, data: Partial<T>): Promise<T>;
391
+ /** Upsert (insert or update) a record */
392
+ upsert(data: Partial<T>): Promise<T>;
393
+ /** Delete a record */
394
+ delete(id: string): Promise<void>;
395
+ }
396
+ /**
397
+ * Registry of adapters by table name
398
+ */
399
+ interface AdapterRegistry {
400
+ /** Get an adapter for a specific table */
401
+ getAdapter<T>(tableName: string): DataAdapter<T>;
402
+ /** Initialize all adapters (called by Provider) */
403
+ initialize(): Promise<void>;
404
+ /** Clean up adapters */
405
+ dispose(): void;
406
+ }
407
+ /**
408
+ * Type for the useDbQuery hook
409
+ */
410
+ type UseDbQueryHook<DB> = <TableName extends string, T = unknown>(tableName: TableName, options?: QueryOptions) => QueryResult<T>;
411
+ /**
412
+ * Type for the useDbQueryById hook
413
+ */
414
+ type UseDbQueryByIdHook<DB> = <TableName extends string, T = unknown>(tableName: TableName, id: string | null | undefined, options?: Pick<QueryOptions, "select" | "enabled">) => QuerySingleResult<T>;
415
+ /**
416
+ * Type for the useDbMutation hook
417
+ */
418
+ type UseDbMutationHook<DB> = <TableName extends string, T = unknown>(tableName: TableName) => MutationHookResult<T>;
419
+ /**
420
+ * Collection of all V3 hooks
421
+ */
422
+ interface DataLayerHooks<DB> {
423
+ useDbQuery: UseDbQueryHook<DB>;
424
+ useDbQueryById: UseDbQueryByIdHook<DB>;
425
+ useDbMutation: UseDbMutationHook<DB>;
426
+ useSyncStatus: () => SyncStatus;
427
+ useSyncControl: () => SyncControl;
428
+ useOnlineStatus: () => {
429
+ isOnline: boolean;
430
+ isConnected: boolean;
431
+ };
432
+ }
433
+ /**
434
+ * Extract row type from database for a given table
435
+ */
436
+ type ExtractRow<DB, SchemaName extends string = "public", TableName extends string = string> = DB extends {
437
+ [K in SchemaName]: {
438
+ Tables: {
439
+ [T in TableName]: {
440
+ Row: infer R;
441
+ };
442
+ };
443
+ };
444
+ } ? R : unknown;
445
+ /**
446
+ * Extract insert type from database for a given table
447
+ */
448
+ type ExtractInsert<DB, SchemaName extends string = "public", TableName extends string = string> = DB extends {
449
+ [K in SchemaName]: {
450
+ Tables: {
451
+ [T in TableName]: {
452
+ Insert: infer I;
453
+ };
454
+ };
455
+ };
456
+ } ? I : unknown;
457
+ /**
458
+ * Extract update type from database for a given table
459
+ */
460
+ type ExtractUpdate<DB, SchemaName extends string = "public", TableName extends string = string> = DB extends {
461
+ [K in SchemaName]: {
462
+ Tables: {
463
+ [T in TableName]: {
464
+ Update: infer U;
465
+ };
466
+ };
467
+ };
468
+ } ? U : unknown;
469
+ /**
470
+ * Get all table names from a database schema
471
+ */
472
+ type TableNames<DB, SchemaName extends string = "public"> = DB extends {
473
+ [K in SchemaName]: {
474
+ Tables: infer T;
475
+ };
476
+ } ? keyof T & string : string;
477
+ /**
478
+ * A single column in a parsed select statement
479
+ */
480
+ interface SelectColumn {
481
+ /** Column name */
482
+ name: string;
483
+ /** Optional alias for the column */
484
+ alias?: string;
485
+ }
486
+ /**
487
+ * A relation in a parsed select statement (e.g., RelatedTable(*))
488
+ */
489
+ interface SelectRelation {
490
+ /** Relation/table name */
491
+ name: string;
492
+ /** Optional alias for the relation */
493
+ alias?: string;
494
+ /** Columns to select from the relation ("*" or specific columns) */
495
+ columns: "*" | SelectColumn[];
496
+ /** Nested relations within this relation */
497
+ relations: SelectRelation[];
498
+ }
499
+ /**
500
+ * Complete parsed select statement AST
501
+ */
502
+ interface ParsedSelect {
503
+ /** Columns to select ("*" or specific columns) */
504
+ columns: "*" | SelectColumn[];
505
+ /** Relations to include */
506
+ relations: SelectRelation[];
507
+ }
508
+ /**
509
+ * Type of relationship between tables
510
+ * - one-to-many: Parent has many children (e.g., Project -> Tasks)
511
+ * - many-to-one: Child belongs to parent (e.g., Task -> Project)
512
+ */
513
+ type RelationshipType = "one-to-many" | "many-to-one";
514
+ /**
515
+ * A resolved relationship with full context for joining
516
+ */
517
+ interface ResolvedRelationship {
518
+ /** The type of relationship */
519
+ type: RelationshipType;
520
+ /** The table we're querying from */
521
+ fromTable: string;
522
+ /** The related table */
523
+ toTable: string;
524
+ /** The foreign key column name */
525
+ foreignKey: string;
526
+ /** The referenced column (usually "id") */
527
+ referencedColumn: string;
528
+ }
529
+ /**
530
+ * A built SQL query with parameterized values
531
+ */
532
+ interface BuiltQuery {
533
+ /** The SQL query string with ? placeholders */
534
+ sql: string;
535
+ /** Parameters to substitute for ? placeholders */
536
+ params: (string | number | boolean | null)[];
537
+ }
538
+
539
+ export type { AdapterRegistry, AutoStrategy, BuiltQuery, CachedStrategy, ColumnInfo, ColumnType, ConnectionConfig, DataAdapter, DataLayerConfig, DataLayerHooks, DatabaseSchema, DeleteMutationResult, ExtractInsert, ExtractRow, ExtractUpdate, HybridStrategy, MutationHookResult, MutationResult, OrderBy, ParsedSelect, PowerSyncStrategy, QueryOptions, QueryResult, QuerySingleResult, RelationshipInfo, RelationshipType, ResolvedRelationship, ScopeDefinition, SelectColumn, SelectRelation, SupabaseStrategy, SyncControl, SyncMode, SyncScope, SyncStatus, TableNames, TableSchema, TableStrategy, UseDbMutationHook, UseDbQueryByIdHook, UseDbQueryHook, WhereClause, WhereOperators };