@pol-studios/db 1.0.17 → 1.0.19

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