@pol-studios/db 1.0.19 → 1.0.22
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/dist/DataLayerContext-ZmLPYR_s.d.ts +825 -0
- package/dist/EntityPermissions-DwFt4tUd.d.ts +35 -0
- package/dist/FilterConfig-Bt2Ek74z.d.ts +99 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +48 -0
- package/dist/auth/context.js +2 -2
- package/dist/auth/guards.d.ts +180 -0
- package/dist/auth/hooks.d.ts +312 -0
- package/dist/auth/hooks.js +3 -3
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +3 -3
- package/dist/{chunk-2T6WTCP4.js → chunk-3EVWXMUV.js} +54 -155
- package/dist/chunk-3EVWXMUV.js.map +1 -0
- package/dist/{chunk-YERWPV6B.js → chunk-3FHAKRDV.js} +145 -19
- package/dist/{chunk-YERWPV6B.js.map → chunk-3FHAKRDV.js.map} +1 -1
- package/dist/{chunk-X3HZLNBV.js → chunk-FKRACEHV.js} +2 -962
- package/dist/chunk-FKRACEHV.js.map +1 -0
- package/dist/{chunk-N26IEHZT.js → chunk-FZF26ZRB.js} +18 -2
- package/dist/{chunk-N26IEHZT.js.map → chunk-FZF26ZRB.js.map} +1 -1
- package/dist/chunk-HTJ2FQW5.js +963 -0
- package/dist/chunk-HTJ2FQW5.js.map +1 -0
- package/dist/{chunk-R5B2XMN5.js → chunk-I4BDZDHX.js} +1614 -2141
- package/dist/chunk-I4BDZDHX.js.map +1 -0
- package/dist/{chunk-36DVUMQD.js → chunk-LPC64MD4.js} +2 -2
- package/dist/{chunk-72WV3ALS.js → chunk-OUUQSI3Y.js} +2 -2
- package/dist/{chunk-RMRYGICS.js → chunk-WP6TIVPH.js} +4 -4
- package/dist/client/index.d.ts +16 -0
- package/dist/core/index.d.ts +568 -0
- package/dist/database.types-ChFCG-4M.d.ts +8604 -0
- package/dist/executor-CB4KHyYG.d.ts +507 -0
- package/dist/gen/index.d.ts +1099 -0
- package/dist/hooks/index.d.ts +119 -0
- package/dist/hooks/index.js +1 -1
- package/dist/index-2YySlz7X.d.ts +433 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +14 -95
- package/dist/index.native.d.ts +775 -0
- package/dist/index.native.js +17 -96
- package/dist/index.web.d.ts +438 -0
- package/dist/index.web.js +585 -46
- package/dist/index.web.js.map +1 -1
- package/dist/mutation/index.d.ts +58 -0
- package/dist/parser/index.d.ts +366 -0
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/powersync-bridge/index.js +1 -1
- package/dist/query/index.d.ts +723 -0
- package/dist/query/index.js +10 -8
- package/dist/realtime/index.d.ts +44 -0
- package/dist/select-query-parser-BwyHum1L.d.ts +352 -0
- package/dist/setupAuthContext-Kv-THH-h.d.ts +61 -0
- package/dist/types/index.d.ts +10 -0
- package/dist/types-CYr9JiUE.d.ts +62 -0
- package/dist/useBatchUpsert-9OYjibLh.d.ts +24 -0
- package/dist/useDbCount-s-aR9YeV.d.ts +1082 -0
- package/dist/useDbQuery-C-TL8jY1.d.ts +19 -0
- package/dist/useReceiptAI-6HkRpRml.d.ts +58 -0
- package/dist/useResolveFeedback-DTGcHpCs.d.ts +882 -0
- package/dist/useSupabase-DvWVuHHE.d.ts +28 -0
- package/dist/with-auth/index.d.ts +704 -0
- package/dist/with-auth/index.js +4 -4
- package/package.json +50 -1
- package/dist/chunk-2T6WTCP4.js.map +0 -1
- package/dist/chunk-R5B2XMN5.js.map +0 -1
- package/dist/chunk-X3HZLNBV.js.map +0 -1
- /package/dist/{chunk-36DVUMQD.js.map → chunk-LPC64MD4.js.map} +0 -0
- /package/dist/{chunk-72WV3ALS.js.map → chunk-OUUQSI3Y.js.map} +0 -0
- /package/dist/{chunk-RMRYGICS.js.map → chunk-WP6TIVPH.js.map} +0 -0
|
@@ -0,0 +1,775 @@
|
|
|
1
|
+
export { C as CompositeTypes, c as Constants, D as Database, E as Enums, J as Json, T as Tables, a as TablesInsert, b as TablesUpdate } from './database.types-ChFCG-4M.js';
|
|
2
|
+
export { a as FilterConfig, F as FilterConfigOption, G as Group, P as PropertyType, S as SortConfig, T as TableInfo, V as ValueForPropertyType, W as WhereFilter } from './FilterConfig-Bt2Ek74z.js';
|
|
3
|
+
export { r as BackendSelectionResult, B as BooleanOperator, l as ClarificationQuestion, k as ClarificationSuggestion, C as CombinedProviderStatus, j as ComputedSortConfig, n as DataLayerWithPowerSyncProps, D as DbChangeLog, E as EnhancedSyncControl, a as EnhancedSyncStatus, e as Filter, d as FilterConditionType, m as FilterContextType, f as FilterGroup, g as FilterInput, F as FilterOperator, h as FilterState, H as HasPowerSyncConfig, O as OrderColumn, i as Pagination, P as PowerSyncEnabledConfig, b as PowerSyncEnabledContextValue, q as PowerSyncTables, Q as QueryState, S as Sort, U as UseDataLayerWithPowerSync, p as UseSyncControlWithPowerSync, o as UseSyncStatusWithPowerSync, V as ValueOrArrayForPropertyType, c as createCombinedStatus } from './index-2YySlz7X.js';
|
|
4
|
+
export { A as AIOptions, k as AIResponse, y as AlertProps, B as BUCKETS, v as BucketName, C as CustomPageQueryResult, D as DEFAULT_QUERY_TIMEOUT, Y as FeedbackListItem, Z as FeedbackListParams, L as LiveChangeContext, z as LiveChangeContextProvider, m as ServerAvailabilityState, t as StorageObjectMetadata, $ as SubmitFeedbackParams, S as SupabaseAdapter, T as TIMEOUT_ERROR_MESSAGE, q as UpdateOptions, U as UseMutationSuccessOptions, w as createInCondition, i as createSupabaseAdapter, r as executeAdvanceQuery, j as getErrorBody, g as getSupabaseUrl, x as isTimeoutError, n as newTimeActivity, s as setSupabaseUrl, l as useAI, a0 as useApplyFeedback, b as useAutosaveState, Q as useChangelogById, R as useChangelogBySlug, V as useChangelogEntries, W as useChangelogMedia, O as useChangelogs, F as useDeleteChangelog, I as useDeleteChangelogEntry, M as useDeleteChangelogMedia, X as useFeedbackList, a as useLatestOperationLog, u as useLiveChangeTracking, J as useMultiDeleteChangelogEntries, H as useMultiUpsertChangelogEntries, f as useMutationSuccess, h as useMutationSuccessRN, P as usePublishedChangelogs, a1 as useResolveFeedback, p as useSearchQuery, o as useServerAvailability, e as useStoragePath, d as useStorageUrl, _ as useSubmitFeedback, c as useToastError, N as useUploadChangelogMedia, E as useUpsertChangelog, G as useUpsertChangelogEntry, K as useUpsertChangelogMedia } from './useResolveFeedback-DTGcHpCs.js';
|
|
5
|
+
export { D as DatabaseTypes, P as PublicTableNames, R as ResolveRowType, S as SchemaNames, l as SchemaTableNames, T as TableIdentifier, U as UseAdvanceQueryOptions, m as UseAdvanceQueryResult, n as UseDbCountOptions, o as UseDbCountResult, p as UseDbInfiniteQueryOptions, q as UseDbInfiniteQueryResult, r as UseDbQueryOptions, s as UseDbQueryResult, u as useAdvanceQuery, a as useDataLayer, d as useDbCount, d as useDbCountV3, e as useDbDeleteV3, f as useDbInfiniteQuery, f as useDbInfiniteQueryV3, g as useDbInsertV3, i as useDbQueryById, h as useDbQueryV3, j as useDbUpdateV3, k as useDbUpsert, k as useDbUpsertV3, k as useUpsert } from './useDbCount-s-aR9YeV.js';
|
|
6
|
+
export { useOnlineStatus, useSyncControl, useSyncStatus } from './hooks/index.js';
|
|
7
|
+
export { u as useBatchDelete, a as useBatchUpsert } from './useBatchUpsert-9OYjibLh.js';
|
|
8
|
+
import { DatabaseSchema, QueryOptions, DataLayerConfig } from './core/index.js';
|
|
9
|
+
export { AdapterRegistry as AdapterRegistryInterface, AutoStrategy, BuiltQuery, CachedStrategy, ColumnInfo, ColumnType, ConnectionConfig, DataAdapter, DataLayerHooks, DeleteMutationResult, ExtractInsert, ExtractRow, ExtractUpdate, FailedUpload, HybridStrategy, MutationHookResult, MutationResult, OrderBy, ParsedSelect, PowerSyncStrategy, QueryResult, QuerySingleResult, RelationshipInfo, RelationshipType, ResolvedRelationship, ScopeDefinition, SelectColumn, SelectRelation, SupabaseStrategy, SyncControl, SyncMode, SyncScope, SyncStatus, TableNames, TableSchema, TableStrategy, UseDbMutationHook, UseDbQueryByIdHook, UseDbQueryHook, WhereClause, WhereOperators } from './core/index.js';
|
|
10
|
+
import { T as TableDataAdapter, C as CapableDataAdapter, c as AdapterCapabilities, A as AdapterQueryResult, p as DataLayerContextValue, S as SyncStatusInfo } from './DataLayerContext-ZmLPYR_s.js';
|
|
11
|
+
export { f as ADAPTER_STRATEGIES, i as AdapterAutoDetector, a as AdapterConfig, d as AdapterDependencies, b as AdapterFactory, g as AdapterRegistry, e as AdapterStrategyType, k as AutoDetectionResult, l as AutoDetectorOptions, m as BackendChangeListener, B as BackendStatus, D as DataLayerContext, n as DataLayerCoreContext, q as DataLayerCoreContextValue, s as DataLayerStatus, o as DataLayerStatusContext, r as DataLayerStatusContextValue, j as createAdapterAutoDetector, h as createAdapterRegistry } from './DataLayerContext-ZmLPYR_s.js';
|
|
12
|
+
import { Q as QueryExecutor, P as PowerSyncDatabase$1 } from './executor-CB4KHyYG.js';
|
|
13
|
+
import * as react from 'react';
|
|
14
|
+
import react__default, { ReactNode, JSX } from 'react';
|
|
15
|
+
import { SupabaseClient } from '@supabase/supabase-js';
|
|
16
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
17
|
+
export { C as ClientInstanceId, S as SupabaseDatabaseTypes, a as SupabaseProvider, T as TypedSupabaseClient, U as UserSessionId, c as createNewSupabaseClient, u as default, o as onSupabaseInitialized, s as setDefaultOptions, t as typedSupabase, u as useSupabase } from './useSupabase-DvWVuHHE.js';
|
|
18
|
+
export { e as UserMetadataContextProvider, c as UserMetadataContextType, a as UserMetadataInsert, U as UserMetadataRow, b as UserMetadataUpdate, u as useLiveChangesIndicator, h as useSetUserMetadata, f as useUserMetadata, i as useUserMetadataState, g as useUserMetadataValue, d as userMetadataContext } from './UserMetadataContext-B8gVWGMl.js';
|
|
19
|
+
import * as react_dropzone from 'react-dropzone';
|
|
20
|
+
import { FileRejection, FileError } from 'react-dropzone';
|
|
21
|
+
export { AnyPostgrestResponse, FilterDefinition, FilterDefinitions, FilterFn, NestedPath, OPERATOR_MAP, OperatorFn, OrderDefinition, Path, PostgrestFilter, PostgrestFilterOperator, PostgrestHasMorePaginationCacheData, PostgrestHasMorePaginationResponse, PostgrestPaginationCacheData, PostgrestPaginationResponse, PostgrestParser, PostgrestQueryParser, PostgrestQueryParserOptions, SUPPORTED_OPERATORS, ValueType, binarySearch, buildSortedComparator, denormalize, encodeObject, extractPathsFromFilters, filterFilterDefinitionsByPaths, findFilters, findIndexOrdered, findLastIndex, get, getTable, groupPathsRecursive, ifDateGetTime, isAndFilter, isAnyPostgrestResponse, isFilterDefinition, isISODateString, isNestedPath, isNotNull, isObject, isOrFilter, isPostgrestBuilder, isPostgrestHasMorePaginationCacheData, isPostgrestHasMorePaginationResponse, isPostgrestPaginationCacheData, isPostgrestPaginationResponse, parseOrderByKey, parseSelectParam, parseValue, removeAliasFromDeclaration, removeFirstPathElement, setFilterValue, sortSearchParams } from './parser/index.js';
|
|
22
|
+
export { G as GetResult, S as SelectQueryError } from './select-query-parser-BwyHum1L.js';
|
|
23
|
+
export { F as Fetch, i as GenericFunction, g as GenericNonUpdatableView, j as GenericSchema, G as GenericTable, f as GenericUpdatableView, h as GenericView, P as PostgrestError, d as PostgrestMaybeSingleResponse, e as PostgrestResponse, b as PostgrestResponseFailure, a as PostgrestResponseSuccess, c as PostgrestSingleResponse, k as Prettify } from './types-CYr9JiUE.js';
|
|
24
|
+
export { Accessory, Address, AdvanceQuery, AdvanceQueryNotificationSetting, AdvancedQueryView, BillableService, BillingDetails, CachedEmbedding, Changelog, ChangelogEntry, ChangelogMedia, ChargeTable, Circuit, Client, Comment, CommentReaction, CommentRead, CommentSection, CommentTag, CommonNote, CommonNoteCategory, CommonNoteSubCategory, ControlComponent, ControlComponentDatasheet, Controller, CoreSavedQuery, CoreSavedQueryAccess, Currency, CurrencyUsdConversion, DataExchangeImport, Datasheet, Dimension, DimmerModule, DimmerRack, Embedding, EquipmentConfigurationGroup, EquipmentFixture, EquipmentFixtureConfiguration, EquipmentFixtureConfigurationAccessoryEntry, EquipmentFixtureConfigurationControlComponentEntry, EquipmentFixtureCost, EquipmentFixtureDatasheet, EquipmentFixtureDimension, EquipmentFixtureDocument, EquipmentFixtureLampConfiguration, EquipmentFixtureListing, EquipmentFixtureMode, EquipmentFixtureModeChannel, EquipmentFixturePreset, EquipmentFixtureUnit, EquipmentFixtureUnitControl, EquipmentFixtureUnitLocation, EquipmentFixtureUnitLocationTag, EquipmentFixtureUnitLocationTagValue, EquipmentFixtureUnitPatternEntry, EquipmentFixtureWeight, EquipmentType, EquipmentUnitMediaContent, Expense, ExpenseLineItem, ExpenseReport, Fixture, FixtureCatalog, FixtureCatalogItem, FixtureCategory, FixtureTag, GlobalExpenseReport, HighlightServer, HighlightServerInstance, HighlightServerInstanceLog, HighlightServerInstanceOptions, HighlightServerInstanceStatus, HighlightServerRequest, Invoice, InvoiceSummaryTable, InvoiceTerm, InvoiceTermCondition, Lamp, LampCategory, LampCurrentListing, LampType, LicenseAssignment, Logo, Manufacturer, ManufacturerTag, ManufacturerToTag, OperationLog, OrderHinted, Organization, OrganizationUser, OrganizationUserAccess, ParameterMappingProfile, ParameterMappingProfileAssignment, Pattern, PaymentCustomer, PaymentInvoice, PaymentPaymentIntents, PaymentPlan, PaymentProduct, PaymentProductFeature, PaymentSubscription, PaymentSubscriptionPlan, PhaseActivityBucket, ProfileConfig as Profile, ProfileConfig, ProfileTimeBank, Project, ProjectDatabase, ProjectDatabaseEquipmentConfigurationGroup, ProjectDatabaseExcelParameterAssignment, ProjectDatabaseGroup, ProjectDatabaseParameterMappingProfile, ProjectDefaultRateByTitle, ProjectDocument, ProjectDocumentLineItem, PunchList, PunchListAccess, PunchListItem, PunchListItemAssignment, PunchListItemAttachedEntity, PunchListItemAttachment, PunchListItemCheckListItem, PunchListPage, PunchListPageAccess, PunchListUserOrderHint, QrCode, RetainageItem, RevitEquipmentUnitChange, RevitImport, RevitValueChangedEvent, Role, Service, ServiceCosts, ServiceStorageHourly, SmartCode, SmartCodeTag, Subtask, SystemBroadcastChannel, SystemBroadcastChannelThrottle, SystemConfiguration, SystemEmailNotification, SystemEvent, SystemEventListener, SystemEventWorker, SystemGlobalVariables, SystemHealthCheck, SystemInAppNotification, SystemLog, SystemMutedTopic, SystemNotification, SystemPushNotification, SystemSubscriber, SystemSupportAccess, SystemSupportTeam, SystemTask, SystemTaskAttempt, SystemTaskAttemptAccess, SystemTemp, SystemTicket, SystemTicketAttachment, SystemTicketComment, SystemTicketCommentAttachment, SystemUserPushTokens, Tag, Task, TaxCategory, Ticket, TicketAttachment, TicketComment, TicketCommentAttachment, TimeActivity, TimeBankTransaction, UserMetadata, UserTimesheet, WeeklyTimesheet, WorkEstimation, WorkEstimationLineItem, WorkingPhase, WorkingPhaseBillingItemDailySummary, WorkingPhaseBillingItemLatestSummary, WorkingPhaseCategory, WorkingPhaseDailySummary, WorkingPhaseRoleRate, WorkingPhaseSummary } from './gen/index.js';
|
|
25
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
26
|
+
import 'moment';
|
|
27
|
+
import '@supabase/functions-js';
|
|
28
|
+
import '@supabase/postgrest-js';
|
|
29
|
+
import './useDbQuery-C-TL8jY1.js';
|
|
30
|
+
import '@pol-studios/utils';
|
|
31
|
+
import '@supabase-cache-helpers/postgrest-react-query';
|
|
32
|
+
import '@supabase/storage-js';
|
|
33
|
+
import '@supabase/supabase-js/dist/module/lib/types.js';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* PowerSync Adapter
|
|
37
|
+
*
|
|
38
|
+
* Wraps the QueryExecutor to execute queries against PowerSync's local SQLite database.
|
|
39
|
+
* Implements the TableDataAdapter interface for use with the V3 data layer.
|
|
40
|
+
*
|
|
41
|
+
* This adapter provides offline-first data access by querying the local SQLite
|
|
42
|
+
* database that PowerSync keeps synchronized with Supabase.
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Handler interface for PowerSync watch callbacks.
|
|
47
|
+
*/
|
|
48
|
+
interface WatchHandler {
|
|
49
|
+
onResult: (results: {
|
|
50
|
+
rows?: {
|
|
51
|
+
_array: Record<string, unknown>[];
|
|
52
|
+
};
|
|
53
|
+
}) => void;
|
|
54
|
+
onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Options for PowerSync watch operations.
|
|
58
|
+
*/
|
|
59
|
+
interface SQLWatchOptions {
|
|
60
|
+
signal?: AbortSignal;
|
|
61
|
+
tables?: string[];
|
|
62
|
+
throttleMs?: number;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Extended PowerSync database interface that includes watch functionality.
|
|
66
|
+
* This extends the base interface from the executor to add reactive query support.
|
|
67
|
+
*
|
|
68
|
+
* The watch method is optional to maintain backward compatibility with databases
|
|
69
|
+
* that don't support reactive queries. When not available, subscribe will fall
|
|
70
|
+
* back to polling.
|
|
71
|
+
*/
|
|
72
|
+
interface PowerSyncDatabase {
|
|
73
|
+
getAll<T>(sql: string, params?: unknown[]): Promise<T[]>;
|
|
74
|
+
get<T>(sql: string, params?: unknown[]): Promise<T | null>;
|
|
75
|
+
execute(sql: string, params?: unknown[]): Promise<{
|
|
76
|
+
rowsAffected: number;
|
|
77
|
+
}>;
|
|
78
|
+
/**
|
|
79
|
+
* Watch a SQL query for changes.
|
|
80
|
+
* Executes the query and invokes the handler whenever the underlying data changes.
|
|
81
|
+
* Optional - if not available, subscribe will fall back to polling.
|
|
82
|
+
*/
|
|
83
|
+
watch?(sql: string, parameters?: unknown[], handler?: WatchHandler, options?: SQLWatchOptions): void;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* PowerSyncAdapter implements the TableDataAdapter interface by delegating
|
|
87
|
+
* all operations to the QueryExecutor.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* const adapter = createPowerSyncAdapter(powerSyncDb, schema);
|
|
91
|
+
*
|
|
92
|
+
* // Query with filtering and pagination
|
|
93
|
+
* const { data, count } = await adapter.query<EquipmentUnit>("EquipmentUnit", {
|
|
94
|
+
* where: { status: "active" },
|
|
95
|
+
* orderBy: [{ field: "name", direction: "asc" }],
|
|
96
|
+
* limit: 10
|
|
97
|
+
* });
|
|
98
|
+
*
|
|
99
|
+
* // Query with relations
|
|
100
|
+
* const { data } = await adapter.query<EquipmentUnitWithRelations>("EquipmentUnit", {
|
|
101
|
+
* select: "*, EquipmentFixture(*), ProjectDatabase(name)"
|
|
102
|
+
* });
|
|
103
|
+
*/
|
|
104
|
+
/**
|
|
105
|
+
* Function type for resolving table names to PowerSync aliases.
|
|
106
|
+
* Used to map schema-qualified names like "core.Profile" to aliases like "CoreProfile".
|
|
107
|
+
*/
|
|
108
|
+
type TableNameResolver = (table: string) => string;
|
|
109
|
+
declare class PowerSyncAdapter implements TableDataAdapter, CapableDataAdapter {
|
|
110
|
+
private db;
|
|
111
|
+
private schema;
|
|
112
|
+
/**
|
|
113
|
+
* Unique identifier for this adapter type
|
|
114
|
+
*/
|
|
115
|
+
readonly name = "powersync";
|
|
116
|
+
/**
|
|
117
|
+
* Capabilities supported by this adapter
|
|
118
|
+
*/
|
|
119
|
+
readonly capabilities: AdapterCapabilities;
|
|
120
|
+
/**
|
|
121
|
+
* The underlying query executor
|
|
122
|
+
*/
|
|
123
|
+
private executor;
|
|
124
|
+
/**
|
|
125
|
+
* Optional custom table name resolver.
|
|
126
|
+
* If not provided, uses default auto-alias generation.
|
|
127
|
+
*/
|
|
128
|
+
private tableNameResolver?;
|
|
129
|
+
/**
|
|
130
|
+
* Create a new PowerSyncAdapter
|
|
131
|
+
*
|
|
132
|
+
* @param db - PowerSync database instance
|
|
133
|
+
* @param schema - Database schema for relationship resolution
|
|
134
|
+
* @param tableNameResolver - Optional custom resolver for table names to PowerSync aliases
|
|
135
|
+
*/
|
|
136
|
+
constructor(db: PowerSyncDatabase, schema: DatabaseSchema, tableNameResolver?: TableNameResolver);
|
|
137
|
+
/**
|
|
138
|
+
* Resolve a table name to its PowerSync alias.
|
|
139
|
+
* Schema-qualified names like "chat.Conversation" become "Conversation" (schema stripped).
|
|
140
|
+
* Unqualified names pass through unchanged.
|
|
141
|
+
*
|
|
142
|
+
* @param table - Original table name (may be schema-qualified)
|
|
143
|
+
* @returns The PowerSync alias to use in SQLite queries
|
|
144
|
+
*/
|
|
145
|
+
private resolveTableName;
|
|
146
|
+
/**
|
|
147
|
+
* Execute a query and return results with optional count for pagination.
|
|
148
|
+
*
|
|
149
|
+
* @param table - The table name to query
|
|
150
|
+
* @param options - Query options (select, where, orderBy, limit, offset)
|
|
151
|
+
* @returns Promise resolving to query results with optional count
|
|
152
|
+
*/
|
|
153
|
+
query<T>(table: string, options?: QueryOptions): Promise<AdapterQueryResult<T>>;
|
|
154
|
+
/**
|
|
155
|
+
* Query a single record by ID.
|
|
156
|
+
*
|
|
157
|
+
* @param table - The table name to query
|
|
158
|
+
* @param id - The record ID
|
|
159
|
+
* @param options - Optional query options (mainly for select)
|
|
160
|
+
* @returns Promise resolving to the record or null if not found
|
|
161
|
+
*/
|
|
162
|
+
queryById<T>(table: string, id: string, options?: Pick<QueryOptions, "select">): Promise<T | null>;
|
|
163
|
+
/**
|
|
164
|
+
* Subscribe to changes on a query using PowerSync's native watch() API.
|
|
165
|
+
*
|
|
166
|
+
* This uses PowerSync's reactive query watching which efficiently detects
|
|
167
|
+
* changes to the underlying data and re-executes the query only when needed.
|
|
168
|
+
*
|
|
169
|
+
* If the database doesn't support watch(), falls back to polling every 5 seconds.
|
|
170
|
+
*
|
|
171
|
+
* @param table - The table name to watch
|
|
172
|
+
* @param options - Query options to filter what to watch
|
|
173
|
+
* @param callback - Function called with updated data
|
|
174
|
+
* @returns Unsubscribe function
|
|
175
|
+
*/
|
|
176
|
+
subscribe<T>(table: string, options: QueryOptions, callback: (data: T[]) => void): () => void;
|
|
177
|
+
/**
|
|
178
|
+
* Fallback polling-based subscription for databases that don't support watch().
|
|
179
|
+
*
|
|
180
|
+
* @internal
|
|
181
|
+
*/
|
|
182
|
+
private subscribeWithPolling;
|
|
183
|
+
/**
|
|
184
|
+
* Insert a new record.
|
|
185
|
+
*
|
|
186
|
+
* @param table - The table name
|
|
187
|
+
* @param data - The data to insert
|
|
188
|
+
* @returns Promise resolving to the inserted record
|
|
189
|
+
*/
|
|
190
|
+
insert<T>(table: string, data: Partial<T>): Promise<T>;
|
|
191
|
+
/**
|
|
192
|
+
* Update an existing record by ID.
|
|
193
|
+
*
|
|
194
|
+
* @param table - The table name
|
|
195
|
+
* @param id - The record ID to update
|
|
196
|
+
* @param data - The data to update
|
|
197
|
+
* @returns Promise resolving to the updated record
|
|
198
|
+
*/
|
|
199
|
+
update<T>(table: string, id: string, data: Partial<T>): Promise<T>;
|
|
200
|
+
/**
|
|
201
|
+
* Upsert (insert or update) a record.
|
|
202
|
+
* If the record has an ID and exists, it will be updated.
|
|
203
|
+
* Otherwise, a new record will be inserted.
|
|
204
|
+
*
|
|
205
|
+
* @param table - The table name
|
|
206
|
+
* @param data - The data to upsert
|
|
207
|
+
* @returns Promise resolving to the upserted record
|
|
208
|
+
*/
|
|
209
|
+
upsert<T>(table: string, data: Partial<T>): Promise<T>;
|
|
210
|
+
/**
|
|
211
|
+
* Delete a record by ID.
|
|
212
|
+
*
|
|
213
|
+
* @param table - The table name
|
|
214
|
+
* @param id - The record ID to delete
|
|
215
|
+
* @returns Promise that resolves when deletion is complete
|
|
216
|
+
*/
|
|
217
|
+
delete(table: string, id: string): Promise<void>;
|
|
218
|
+
/**
|
|
219
|
+
* Get the underlying QueryExecutor for advanced use cases.
|
|
220
|
+
*
|
|
221
|
+
* This allows direct access to the executor for operations that
|
|
222
|
+
* may not be covered by the TableDataAdapter interface.
|
|
223
|
+
*
|
|
224
|
+
* @returns The QueryExecutor instance
|
|
225
|
+
*/
|
|
226
|
+
getExecutor(): QueryExecutor;
|
|
227
|
+
/**
|
|
228
|
+
* Get the raw PowerSync database for advanced use cases.
|
|
229
|
+
*
|
|
230
|
+
* This allows direct SQL execution when the adapter methods
|
|
231
|
+
* are not sufficient.
|
|
232
|
+
*
|
|
233
|
+
* @returns The PowerSyncDatabase instance
|
|
234
|
+
*/
|
|
235
|
+
getDatabase(): PowerSyncDatabase;
|
|
236
|
+
/**
|
|
237
|
+
* Get the database schema.
|
|
238
|
+
*
|
|
239
|
+
* @returns The DatabaseSchema used for relationship resolution
|
|
240
|
+
*/
|
|
241
|
+
getSchema(): DatabaseSchema;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Create a new PowerSyncAdapter instance.
|
|
245
|
+
*
|
|
246
|
+
* This is the recommended way to create a PowerSyncAdapter as it provides
|
|
247
|
+
* a cleaner API and allows for future enhancements without breaking changes.
|
|
248
|
+
*
|
|
249
|
+
* @param db - PowerSync database instance
|
|
250
|
+
* @param schema - Database schema for relationship resolution
|
|
251
|
+
* @returns A new PowerSyncAdapter instance
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* import { createPowerSyncAdapter } from "./adapters/powersync-adapter";
|
|
255
|
+
*
|
|
256
|
+
* const adapter = createPowerSyncAdapter(powerSyncDb, databaseSchema);
|
|
257
|
+
*
|
|
258
|
+
* // Use the adapter
|
|
259
|
+
* const { data } = await adapter.query("EquipmentUnit", {
|
|
260
|
+
* where: { status: "active" }
|
|
261
|
+
* });
|
|
262
|
+
*/
|
|
263
|
+
declare function createPowerSyncAdapter(db: PowerSyncDatabase, schema: DatabaseSchema): PowerSyncAdapter;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* V3 Data Layer Provider
|
|
267
|
+
*
|
|
268
|
+
* React context provider that initializes adapters, manages the PowerSync lifecycle,
|
|
269
|
+
* and provides context for all V3 hooks. This is the main entry point for the V3
|
|
270
|
+
* data layer in a React application.
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Props for DataLayerProvider
|
|
275
|
+
*/
|
|
276
|
+
interface DataLayerProviderProps {
|
|
277
|
+
/** Data layer configuration */
|
|
278
|
+
config: DataLayerConfig;
|
|
279
|
+
/** Children to render */
|
|
280
|
+
children: ReactNode;
|
|
281
|
+
/**
|
|
282
|
+
* Optional PowerSync database instance.
|
|
283
|
+
*
|
|
284
|
+
* This accepts any object that implements the PowerSyncDatabase interface,
|
|
285
|
+
* including the AbstractPowerSyncDatabase from @pol-studios/powersync.
|
|
286
|
+
*
|
|
287
|
+
* When using with @pol-studios/powersync, pass the `db` value from usePowerSync():
|
|
288
|
+
* @example
|
|
289
|
+
* ```tsx
|
|
290
|
+
* // With @pol-studios/powersync
|
|
291
|
+
* const { db, isReady } = usePowerSync();
|
|
292
|
+
*
|
|
293
|
+
* if (!isReady) return <Loading />;
|
|
294
|
+
*
|
|
295
|
+
* return (
|
|
296
|
+
* <DataLayerProvider
|
|
297
|
+
* config={config}
|
|
298
|
+
* powerSyncInstance={db}
|
|
299
|
+
* supabaseClient={supabase}
|
|
300
|
+
* queryClient={queryClient}
|
|
301
|
+
* >
|
|
302
|
+
* {children}
|
|
303
|
+
* </DataLayerProvider>
|
|
304
|
+
* );
|
|
305
|
+
* ```
|
|
306
|
+
*/
|
|
307
|
+
powerSyncInstance?: PowerSyncDatabase$1 | null;
|
|
308
|
+
/** Supabase client (required) */
|
|
309
|
+
supabaseClient: SupabaseClient;
|
|
310
|
+
/** React Query client (required) */
|
|
311
|
+
queryClient: QueryClient;
|
|
312
|
+
/** Callback when initialization completes */
|
|
313
|
+
onInitialized?: (context: DataLayerContextValue) => void;
|
|
314
|
+
/** Callback when error occurs */
|
|
315
|
+
onError?: (error: Error) => void;
|
|
316
|
+
/**
|
|
317
|
+
* Current sync status from @pol-studios/powersync.
|
|
318
|
+
* Pass the status object from useSyncStatus() hook.
|
|
319
|
+
* When hasSynced is false and useOnlineUntilSynced is true (default),
|
|
320
|
+
* queries will use Supabase until initial sync completes.
|
|
321
|
+
*/
|
|
322
|
+
powerSyncSyncStatus?: SyncStatusInfo;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Provider component for the V3 data layer.
|
|
326
|
+
*
|
|
327
|
+
* This provider:
|
|
328
|
+
* - Creates and manages the AdapterRegistry
|
|
329
|
+
* - Initializes the AdapterAutoDetector for backend selection
|
|
330
|
+
* - Sets up Supabase and PowerSync adapters
|
|
331
|
+
* - Tracks online/offline status
|
|
332
|
+
* - Provides context for all V3 hooks
|
|
333
|
+
*
|
|
334
|
+
* @example
|
|
335
|
+
* ```tsx
|
|
336
|
+
* import { DataLayerProvider } from "@pol-studios/db";
|
|
337
|
+
*
|
|
338
|
+
* function App() {
|
|
339
|
+
* return (
|
|
340
|
+
* <DataLayerProvider
|
|
341
|
+
* config={dataLayerConfig}
|
|
342
|
+
* supabaseClient={supabase}
|
|
343
|
+
* queryClient={queryClient}
|
|
344
|
+
* powerSyncInstance={powerSyncDb}
|
|
345
|
+
* >
|
|
346
|
+
* <YourApp />
|
|
347
|
+
* </DataLayerProvider>
|
|
348
|
+
* );
|
|
349
|
+
* }
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
declare function DataLayerProvider({ config, children, powerSyncInstance, supabaseClient, queryClient, onInitialized, onError, powerSyncSyncStatus, }: DataLayerProviderProps): JSX.Element;
|
|
353
|
+
|
|
354
|
+
interface FileWithPreview extends File {
|
|
355
|
+
preview?: string;
|
|
356
|
+
errors: readonly FileError[];
|
|
357
|
+
}
|
|
358
|
+
type UseSupabaseUploadOptions = {
|
|
359
|
+
/**
|
|
360
|
+
* Name of bucket to upload files to in your Supabase project
|
|
361
|
+
*/
|
|
362
|
+
bucketName: string;
|
|
363
|
+
/**
|
|
364
|
+
* Folder to upload files to in the specified bucket within your Supabase project.
|
|
365
|
+
*
|
|
366
|
+
* Defaults to uploading files to the root of the bucket
|
|
367
|
+
*
|
|
368
|
+
* e.g If specified path is `test`, your file will be uploaded as `test/file_name`
|
|
369
|
+
*/
|
|
370
|
+
path?: string;
|
|
371
|
+
/**
|
|
372
|
+
* Allowed MIME types for each file upload (e.g `image/png`, `text/html`, etc). Wildcards are also supported (e.g `image/*`).
|
|
373
|
+
*
|
|
374
|
+
* Defaults to allowing uploading of all MIME types.
|
|
375
|
+
*/
|
|
376
|
+
allowedMimeTypes?: string[];
|
|
377
|
+
/**
|
|
378
|
+
* Maximum upload size of each file allowed in bytes. (e.g 1000 bytes = 1 KB)
|
|
379
|
+
*/
|
|
380
|
+
maxFileSize?: number;
|
|
381
|
+
/**
|
|
382
|
+
* Maximum number of files allowed per upload.
|
|
383
|
+
*/
|
|
384
|
+
maxFiles?: number;
|
|
385
|
+
/**
|
|
386
|
+
* The number of seconds the asset is cached in the browser and in the Supabase CDN.
|
|
387
|
+
*
|
|
388
|
+
* This is set in the Cache-Control: max-age=<seconds> header. Defaults to 3600 seconds.
|
|
389
|
+
*/
|
|
390
|
+
cacheControl?: number;
|
|
391
|
+
/**
|
|
392
|
+
* When set to true, the file is overwritten if it exists.
|
|
393
|
+
*
|
|
394
|
+
* When set to false, an error is thrown if the object already exists. Defaults to `false`
|
|
395
|
+
*/
|
|
396
|
+
upsert?: boolean;
|
|
397
|
+
};
|
|
398
|
+
type UseSupabaseUploadReturn = ReturnType<typeof useSupabaseUpload>;
|
|
399
|
+
declare const useSupabaseUpload: (options: UseSupabaseUploadOptions) => {
|
|
400
|
+
open: () => void;
|
|
401
|
+
isFocused: boolean;
|
|
402
|
+
isDragActive: boolean;
|
|
403
|
+
isDragAccept: boolean;
|
|
404
|
+
isDragReject: boolean;
|
|
405
|
+
isFileDialogActive: boolean;
|
|
406
|
+
acceptedFiles: readonly react_dropzone.FileWithPath[];
|
|
407
|
+
fileRejections: readonly FileRejection[];
|
|
408
|
+
rootRef: React.RefObject<HTMLElement>;
|
|
409
|
+
inputRef: React.RefObject<HTMLInputElement>;
|
|
410
|
+
getRootProps: <T extends react_dropzone.DropzoneRootProps>(props?: T) => T;
|
|
411
|
+
getInputProps: <T extends react_dropzone.DropzoneInputProps>(props?: T) => T;
|
|
412
|
+
files: FileWithPreview[];
|
|
413
|
+
setFiles: react.Dispatch<react.SetStateAction<FileWithPreview[]>>;
|
|
414
|
+
successes: string[];
|
|
415
|
+
isSuccess: boolean;
|
|
416
|
+
loading: boolean;
|
|
417
|
+
errors: {
|
|
418
|
+
name: string;
|
|
419
|
+
message: string;
|
|
420
|
+
}[];
|
|
421
|
+
setErrors: react.Dispatch<react.SetStateAction<{
|
|
422
|
+
name: string;
|
|
423
|
+
message: string;
|
|
424
|
+
}[]>>;
|
|
425
|
+
onUpload: () => Promise<void>;
|
|
426
|
+
maxFileSize: number;
|
|
427
|
+
maxFiles: number;
|
|
428
|
+
allowedMimeTypes: string[];
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Conflict Types for @pol-studios/db
|
|
433
|
+
*
|
|
434
|
+
* Canonical type definitions for conflict detection and resolution.
|
|
435
|
+
* These types are shared between @pol-studios/db and @pol-studios/powersync.
|
|
436
|
+
*/
|
|
437
|
+
/**
|
|
438
|
+
* Represents a field-level conflict where both local and server changed the same field.
|
|
439
|
+
*/
|
|
440
|
+
interface FieldConflict {
|
|
441
|
+
/** The field name that has conflicting changes */
|
|
442
|
+
field: string;
|
|
443
|
+
/** The local (pending) value */
|
|
444
|
+
localValue: unknown;
|
|
445
|
+
/** The current server value */
|
|
446
|
+
serverValue: unknown;
|
|
447
|
+
/** User who made the server change (from AuditLog.changeBy) */
|
|
448
|
+
changedBy: string | null;
|
|
449
|
+
/** When the server change occurred (from AuditLog.changeAt) */
|
|
450
|
+
changedAt: Date;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Result of checking for conflicts between local changes and server state.
|
|
454
|
+
*/
|
|
455
|
+
interface ConflictCheckResult {
|
|
456
|
+
/** Whether any field conflicts were detected */
|
|
457
|
+
hasConflict: boolean;
|
|
458
|
+
/** List of field-level conflicts */
|
|
459
|
+
conflicts: FieldConflict[];
|
|
460
|
+
/** Fields that can safely sync (no server changes) */
|
|
461
|
+
nonConflictingChanges: string[];
|
|
462
|
+
/** The table name */
|
|
463
|
+
table: string;
|
|
464
|
+
/** The record ID */
|
|
465
|
+
recordId: string;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* User's resolution choice for a conflict.
|
|
469
|
+
*/
|
|
470
|
+
type ConflictResolution = {
|
|
471
|
+
action: 'overwrite';
|
|
472
|
+
} | {
|
|
473
|
+
action: 'keep-server';
|
|
474
|
+
} | {
|
|
475
|
+
action: 'partial';
|
|
476
|
+
fields: string[];
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Interface for ConflictBus from @pol-studios/powersync.
|
|
481
|
+
* Defined here to avoid circular dependency between packages.
|
|
482
|
+
*/
|
|
483
|
+
interface ConflictBusInterface {
|
|
484
|
+
onConflict: (listener: (conflict: ConflictCheckResult) => void) => () => void;
|
|
485
|
+
onResolution: (listener: (table: string, recordId: string, resolution: ConflictResolution) => void) => () => void;
|
|
486
|
+
emitConflict: (conflict: ConflictCheckResult) => void;
|
|
487
|
+
emitResolution: (table: string, recordId: string, resolution: ConflictResolution) => void;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Context value provided to consumers.
|
|
491
|
+
*/
|
|
492
|
+
interface ConflictContextValue {
|
|
493
|
+
/** Current conflict state */
|
|
494
|
+
pendingConflicts: ConflictCheckResult[];
|
|
495
|
+
/** Add a conflict (called by connector) */
|
|
496
|
+
addConflict: (conflict: ConflictCheckResult) => void;
|
|
497
|
+
/** Resolve a single conflict by table and record ID */
|
|
498
|
+
resolveConflict: (table: string, recordId: string, resolution: ConflictResolution) => void;
|
|
499
|
+
/** Resolve all pending conflicts with the same resolution */
|
|
500
|
+
resolveAll: (resolution: ConflictResolution) => void;
|
|
501
|
+
/** Remove a conflict by table and record ID (after sync completes) */
|
|
502
|
+
removeConflict: (table: string, recordId: string) => void;
|
|
503
|
+
/** Get resolution for a specific table and record */
|
|
504
|
+
getResolution: (table: string, recordId: string) => ConflictResolution | undefined;
|
|
505
|
+
/** Clear all resolved conflicts from the resolutions map */
|
|
506
|
+
clearResolved: () => void;
|
|
507
|
+
/** Clear all conflicts (resolved and pending) */
|
|
508
|
+
clearAll: () => void;
|
|
509
|
+
/** Whether there are any pending conflicts */
|
|
510
|
+
hasConflicts: boolean;
|
|
511
|
+
}
|
|
512
|
+
declare const ConflictContext: react__default.Context<ConflictContextValue>;
|
|
513
|
+
interface ConflictProviderProps {
|
|
514
|
+
children: react__default.ReactNode;
|
|
515
|
+
/**
|
|
516
|
+
* Optional: Event bus for receiving conflicts from the connector.
|
|
517
|
+
* When provided, the provider will:
|
|
518
|
+
* - Subscribe to conflict events and add them to state
|
|
519
|
+
* - Emit resolution events when conflicts are resolved
|
|
520
|
+
*/
|
|
521
|
+
conflictBus?: ConflictBusInterface;
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Provider component for conflict state management.
|
|
525
|
+
*
|
|
526
|
+
* Wrap your app with this provider to enable conflict detection and resolution.
|
|
527
|
+
*
|
|
528
|
+
* @example
|
|
529
|
+
* ```tsx
|
|
530
|
+
* <PowerSyncProvider connector={connector}>
|
|
531
|
+
* <ConflictProvider>
|
|
532
|
+
* <App />
|
|
533
|
+
* </ConflictProvider>
|
|
534
|
+
* </PowerSyncProvider>
|
|
535
|
+
* ```
|
|
536
|
+
*/
|
|
537
|
+
declare function ConflictProvider({ children, conflictBus }: ConflictProviderProps): react_jsx_runtime.JSX.Element;
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Conflict State Hooks for @pol-studios/db
|
|
541
|
+
*
|
|
542
|
+
* Provides hooks for accessing and filtering conflict state.
|
|
543
|
+
*/
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Hook to access the full conflict state and actions.
|
|
547
|
+
*
|
|
548
|
+
* @throws Error if used outside of ConflictProvider
|
|
549
|
+
* @returns Full conflict context value
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```tsx
|
|
553
|
+
* function ConflictManager() {
|
|
554
|
+
* const { pendingConflicts, resolveAll, clearResolved } = useConflictState();
|
|
555
|
+
*
|
|
556
|
+
* return (
|
|
557
|
+
* <View>
|
|
558
|
+
* <Text>{pendingConflicts.length} conflicts pending</Text>
|
|
559
|
+
* <Button onPress={() => resolveAll({ action: 'keep-server' })}>
|
|
560
|
+
* Accept All Server Changes
|
|
561
|
+
* </Button>
|
|
562
|
+
* </View>
|
|
563
|
+
* );
|
|
564
|
+
* }
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
declare function useConflictState(): ConflictContextValue;
|
|
568
|
+
/**
|
|
569
|
+
* Hook to get only pending conflicts (read-only).
|
|
570
|
+
*
|
|
571
|
+
* Use this when you only need to display conflicts without resolution actions.
|
|
572
|
+
*
|
|
573
|
+
* @returns Array of pending conflicts
|
|
574
|
+
*
|
|
575
|
+
* @example
|
|
576
|
+
* ```tsx
|
|
577
|
+
* function ConflictBadge() {
|
|
578
|
+
* const conflicts = usePendingConflicts();
|
|
579
|
+
* if (conflicts.length === 0) return null;
|
|
580
|
+
* return <Badge count={conflicts.length} />;
|
|
581
|
+
* }
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
declare function usePendingConflicts(): ConflictCheckResult[];
|
|
585
|
+
/**
|
|
586
|
+
* Hook to check if there are any pending conflicts.
|
|
587
|
+
*
|
|
588
|
+
* Optimized for conditional rendering - only triggers re-render on boolean change.
|
|
589
|
+
*
|
|
590
|
+
* @returns True if there are pending conflicts
|
|
591
|
+
*
|
|
592
|
+
* @example
|
|
593
|
+
* ```tsx
|
|
594
|
+
* function App() {
|
|
595
|
+
* const hasConflicts = useHasConflicts();
|
|
596
|
+
* return (
|
|
597
|
+
* <>
|
|
598
|
+
* {hasConflicts && <ConflictBanner />}
|
|
599
|
+
* <MainContent />
|
|
600
|
+
* </>
|
|
601
|
+
* );
|
|
602
|
+
* }
|
|
603
|
+
* ```
|
|
604
|
+
*/
|
|
605
|
+
declare function useHasConflicts(): boolean;
|
|
606
|
+
/**
|
|
607
|
+
* Hook to get a specific conflict by table and record ID.
|
|
608
|
+
*
|
|
609
|
+
* Returns null if no conflict exists for the record.
|
|
610
|
+
*
|
|
611
|
+
* @param table - The table name
|
|
612
|
+
* @param recordId - The record ID to look up
|
|
613
|
+
* @returns The conflict for this record, or null
|
|
614
|
+
*
|
|
615
|
+
* @example
|
|
616
|
+
* ```tsx
|
|
617
|
+
* function RecordEditor({ table, recordId }: { table: string; recordId: string }) {
|
|
618
|
+
* const conflict = useConflictForRecord(table, recordId);
|
|
619
|
+
*
|
|
620
|
+
* if (conflict) {
|
|
621
|
+
* return <ConflictWarning conflict={conflict} />;
|
|
622
|
+
* }
|
|
623
|
+
*
|
|
624
|
+
* return <EditForm recordId={recordId} />;
|
|
625
|
+
* }
|
|
626
|
+
* ```
|
|
627
|
+
*/
|
|
628
|
+
declare function useConflictForRecord(table: string, recordId: string): ConflictCheckResult | null;
|
|
629
|
+
/**
|
|
630
|
+
* Hook to get conflicts filtered by table name.
|
|
631
|
+
*
|
|
632
|
+
* Useful for showing conflicts scoped to a specific entity type.
|
|
633
|
+
*
|
|
634
|
+
* @param table - The table name to filter by
|
|
635
|
+
* @returns Conflicts for the specified table
|
|
636
|
+
*
|
|
637
|
+
* @example
|
|
638
|
+
* ```tsx
|
|
639
|
+
* function EquipmentConflicts() {
|
|
640
|
+
* const conflicts = useConflictsForTable('EquipmentFixtureUnit');
|
|
641
|
+
* return (
|
|
642
|
+
* <FlatList
|
|
643
|
+
* data={conflicts}
|
|
644
|
+
* renderItem={({ item }) => <ConflictCard conflict={item} />}
|
|
645
|
+
* />
|
|
646
|
+
* );
|
|
647
|
+
* }
|
|
648
|
+
* ```
|
|
649
|
+
*/
|
|
650
|
+
declare function useConflictsForTable(table: string): ConflictCheckResult[];
|
|
651
|
+
/**
|
|
652
|
+
* Hook to get conflict count by table.
|
|
653
|
+
*
|
|
654
|
+
* Returns a map of table names to conflict counts for summary display.
|
|
655
|
+
*
|
|
656
|
+
* @returns Map of table name to conflict count
|
|
657
|
+
*
|
|
658
|
+
* @example
|
|
659
|
+
* ```tsx
|
|
660
|
+
* function ConflictSummary() {
|
|
661
|
+
* const countByTable = useConflictCountByTable();
|
|
662
|
+
* return (
|
|
663
|
+
* <View>
|
|
664
|
+
* {Array.from(countByTable.entries()).map(([table, count]) => (
|
|
665
|
+
* <Text key={table}>{table}: {count} conflicts</Text>
|
|
666
|
+
* ))}
|
|
667
|
+
* </View>
|
|
668
|
+
* );
|
|
669
|
+
* }
|
|
670
|
+
* ```
|
|
671
|
+
*/
|
|
672
|
+
declare function useConflictCountByTable(): Map<string, number>;
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* Conflict Resolution Hook for @pol-studios/db
|
|
676
|
+
*
|
|
677
|
+
* Provides methods for resolving individual conflicts.
|
|
678
|
+
*/
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Return type for useConflictResolution hook.
|
|
682
|
+
*/
|
|
683
|
+
interface UseConflictResolutionReturn {
|
|
684
|
+
/** The conflict being resolved */
|
|
685
|
+
conflict: ConflictCheckResult;
|
|
686
|
+
/** Resolve with a specific resolution */
|
|
687
|
+
resolve: (resolution: ConflictResolution) => void;
|
|
688
|
+
/** Accept server changes, discard local */
|
|
689
|
+
keepServer: () => void;
|
|
690
|
+
/** Overwrite server with local changes */
|
|
691
|
+
overwrite: () => void;
|
|
692
|
+
/** Only sync fields that don't conflict */
|
|
693
|
+
syncNonConflicting: () => void;
|
|
694
|
+
/** Sync specific fields only */
|
|
695
|
+
syncFields: (fields: string[]) => void;
|
|
696
|
+
/** Check if a specific field has a conflict */
|
|
697
|
+
hasFieldConflict: (field: string) => boolean;
|
|
698
|
+
/** Get conflict info for a specific field */
|
|
699
|
+
getFieldConflict: (field: string) => {
|
|
700
|
+
localValue: unknown;
|
|
701
|
+
serverValue: unknown;
|
|
702
|
+
changedBy: string | null;
|
|
703
|
+
changedAt: Date;
|
|
704
|
+
} | null;
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* Hook for resolving a specific conflict.
|
|
708
|
+
*
|
|
709
|
+
* Provides convenience methods for common resolution patterns.
|
|
710
|
+
*
|
|
711
|
+
* @param conflict - The conflict to resolve
|
|
712
|
+
* @returns Resolution methods and utilities
|
|
713
|
+
*
|
|
714
|
+
* @example
|
|
715
|
+
* ```tsx
|
|
716
|
+
* function ConflictCard({ conflict }: { conflict: ConflictCheckResult }) {
|
|
717
|
+
* const {
|
|
718
|
+
* keepServer,
|
|
719
|
+
* overwrite,
|
|
720
|
+
* syncNonConflicting,
|
|
721
|
+
* hasFieldConflict,
|
|
722
|
+
* getFieldConflict,
|
|
723
|
+
* } = useConflictResolution(conflict);
|
|
724
|
+
*
|
|
725
|
+
* return (
|
|
726
|
+
* <Card>
|
|
727
|
+
* <Text>Conflict on {conflict.table}</Text>
|
|
728
|
+
* {conflict.conflicts.map(fc => (
|
|
729
|
+
* <View key={fc.field}>
|
|
730
|
+
* <Text>{fc.field}</Text>
|
|
731
|
+
* <Text>Yours: {String(fc.localValue)}</Text>
|
|
732
|
+
* <Text>Theirs: {String(fc.serverValue)} by {fc.changedBy}</Text>
|
|
733
|
+
* </View>
|
|
734
|
+
* ))}
|
|
735
|
+
* <Button onPress={keepServer}>Keep Theirs</Button>
|
|
736
|
+
* <Button onPress={overwrite}>Use Mine</Button>
|
|
737
|
+
* <Button onPress={syncNonConflicting}>Sync Safe Fields Only</Button>
|
|
738
|
+
* </Card>
|
|
739
|
+
* );
|
|
740
|
+
* }
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
declare function useConflictResolution(conflict: ConflictCheckResult): UseConflictResolutionReturn;
|
|
744
|
+
/**
|
|
745
|
+
* Hook for bulk conflict resolution.
|
|
746
|
+
*
|
|
747
|
+
* Provides methods for resolving multiple conflicts at once.
|
|
748
|
+
*
|
|
749
|
+
* @returns Bulk resolution methods
|
|
750
|
+
*
|
|
751
|
+
* @example
|
|
752
|
+
* ```tsx
|
|
753
|
+
* function ConflictSummary() {
|
|
754
|
+
* const conflicts = usePendingConflicts();
|
|
755
|
+
* const { resolveAllKeepServer, resolveAllOverwrite } = useBulkConflictResolution();
|
|
756
|
+
*
|
|
757
|
+
* return (
|
|
758
|
+
* <View>
|
|
759
|
+
* <Text>{conflicts.length} conflicts</Text>
|
|
760
|
+
* <Button onPress={resolveAllKeepServer}>Accept All Server Changes</Button>
|
|
761
|
+
* <Button onPress={resolveAllOverwrite}>Overwrite All with Mine</Button>
|
|
762
|
+
* </View>
|
|
763
|
+
* );
|
|
764
|
+
* }
|
|
765
|
+
* ```
|
|
766
|
+
*/
|
|
767
|
+
declare function useBulkConflictResolution(): {
|
|
768
|
+
resolveAllKeepServer: () => void;
|
|
769
|
+
resolveAllOverwrite: () => void;
|
|
770
|
+
resolveAllSyncNonConflicting: () => void;
|
|
771
|
+
clearResolved: () => void;
|
|
772
|
+
conflictCount: number;
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
export { AdapterCapabilities, AdapterQueryResult, CapableDataAdapter, type ConflictCheckResult, ConflictContext, type ConflictContextValue, ConflictProvider, type ConflictProviderProps, type ConflictResolution, DataLayerConfig, DataLayerContextValue, DataLayerProvider, type DataLayerProviderProps, DatabaseSchema, type FieldConflict, PowerSyncAdapter, QueryOptions, SyncStatusInfo, TableDataAdapter, type UseConflictResolutionReturn, type UseSupabaseUploadOptions, type UseSupabaseUploadReturn, createPowerSyncAdapter, useBulkConflictResolution, useConflictCountByTable, useConflictForRecord, useConflictResolution, useConflictState, useConflictsForTable, useHasConflicts, usePendingConflicts, useSupabaseUpload };
|