@pol-studios/db 1.0.10 → 1.0.12
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-CL6alnkb.d.ts +755 -0
- package/dist/UserMetadataContext-B8gVWGMl.d.ts +35 -0
- package/dist/UserMetadataContext-DntmpK41.d.ts +33 -0
- package/dist/auth/context.d.ts +3 -2
- package/dist/auth/context.js +5 -4
- package/dist/auth/guards.js +2 -2
- package/dist/auth/hooks.d.ts +3 -3
- package/dist/auth/hooks.js +6 -5
- package/dist/auth/index.d.ts +3 -2
- package/dist/auth/index.js +8 -6
- package/dist/{canvas-UVNDA54X.node → canvas-C4TBBDUL.node} +0 -0
- package/dist/{canvas-75Y7XMF3.js → canvas-ZQNCL7JL.js} +2 -2
- package/dist/chunk-5EFDS7SR.js +205 -0
- package/dist/chunk-5EFDS7SR.js.map +1 -0
- package/dist/{chunk-BRTW7CO5.js → chunk-7SCJNYTE.js} +1 -9
- package/dist/chunk-7SCJNYTE.js.map +1 -0
- package/dist/chunk-DJ6VLEAL.js +247 -0
- package/dist/chunk-DJ6VLEAL.js.map +1 -0
- package/dist/{chunk-Y3INY2CS.js → chunk-GC3TBUWE.js} +1 -1
- package/dist/chunk-GC3TBUWE.js.map +1 -0
- package/dist/{chunk-7HG6G25H.js → chunk-H3LNH2NT.js} +169 -268
- package/dist/chunk-H3LNH2NT.js.map +1 -0
- package/dist/{chunk-USJYMRUO.js → chunk-HAWJTZCK.js} +2 -2
- package/dist/chunk-HAWJTZCK.js.map +1 -0
- package/dist/chunk-JAATANS3.js +429 -0
- package/dist/chunk-JAATANS3.js.map +1 -0
- package/dist/chunk-LNJ3WF7V.js +470 -0
- package/dist/chunk-LNJ3WF7V.js.map +1 -0
- package/dist/chunk-N26IEHZT.js +79 -0
- package/dist/chunk-N26IEHZT.js.map +1 -0
- package/dist/chunk-NSIAAYW3.js +1 -0
- package/dist/chunk-NSIAAYW3.js.map +1 -0
- package/dist/chunk-NZON56CB.js +3864 -0
- package/dist/chunk-NZON56CB.js.map +1 -0
- package/dist/{chunk-O3K7R32P.js → chunk-OQ7U6EQ3.js} +118 -123
- package/dist/chunk-OQ7U6EQ3.js.map +1 -0
- package/dist/chunk-SM73S2DY.js +11 -0
- package/dist/chunk-SM73S2DY.js.map +1 -0
- package/dist/{chunk-JUVE3DWY.js → chunk-TKWR5AAY.js} +47 -65
- package/dist/chunk-TKWR5AAY.js.map +1 -0
- package/dist/{chunk-2IFGILT3.js → chunk-U5UNPBKB.js} +76 -107
- package/dist/chunk-U5UNPBKB.js.map +1 -0
- package/dist/chunk-WGDJ4IXR.js +921 -0
- package/dist/chunk-WGDJ4IXR.js.map +1 -0
- package/dist/chunk-WVF7RUW5.js +186 -0
- package/dist/chunk-WVF7RUW5.js.map +1 -0
- package/dist/{chunk-ZTSBF536.js → chunk-X3HZLNBV.js} +637 -435
- package/dist/chunk-X3HZLNBV.js.map +1 -0
- package/dist/{chunk-EL45Z26M.js → chunk-XU3SBFAG.js} +1219 -208
- package/dist/chunk-XU3SBFAG.js.map +1 -0
- package/dist/chunk-ZVBHWU7O.js +1412 -0
- package/dist/chunk-ZVBHWU7O.js.map +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +42 -23
- package/dist/client/index.js.map +1 -1
- package/dist/core/index.d.ts +19 -0
- package/dist/{index-BFu5_dS8.d.ts → database.types-ChFCG-4M.d.ts} +1 -177
- package/dist/gen/index.js +4 -2
- package/dist/hooks/index.d.ts +10 -3
- package/dist/hooks/index.js +8 -10
- package/dist/index-CQLyNG6A.d.ts +433 -0
- package/dist/index.d.ts +12 -8
- package/dist/index.js +92 -48
- package/dist/index.native.d.ts +373 -33
- package/dist/index.native.js +79 -47
- package/dist/index.web.d.ts +10 -7
- package/dist/index.web.js +83 -78
- package/dist/index.web.js.map +1 -1
- package/dist/mutation/index.d.ts +2 -2
- package/dist/mutation/index.js +307 -122
- package/dist/mutation/index.js.map +1 -1
- package/dist/parser/index.js +2 -2
- package/dist/{pdf-3TIGQRLA.js → pdf-PHXP7RHD.js} +2 -2
- package/dist/powersync-bridge/index.d.ts +284 -0
- package/dist/powersync-bridge/index.js +22 -0
- package/dist/powersync-bridge/index.js.map +1 -0
- package/dist/query/index.js +5 -5
- package/dist/realtime/index.js +252 -128
- package/dist/realtime/index.js.map +1 -1
- package/dist/{UserMetadataContext-BYYqA6LI.d.ts → setupAuthContext-Kv-THH-h.d.ts} +1 -29
- package/dist/types/index.d.ts +5 -1
- package/dist/types/index.js +10 -5
- package/dist/{useBatchUpsert-CSQVX7w8.d.ts → useBatchUpsert-9OYjibLh.d.ts} +1 -1
- package/dist/{useDbCount-RGCuHmHp.d.ts → useDbCount-BG356T9i.d.ts} +3 -719
- package/dist/{useReceiptAI-Bn0czE7C.d.ts → useReceiptAI-6HkRpRml.d.ts} +1 -1
- package/dist/{useResolveFeedback-CpZPP8Pw.d.ts → useResolveFeedback-BWmatBlE.d.ts} +26 -45
- package/dist/{useSupabase-pPhUZHcl.d.ts → useSupabase-DvWVuHHE.d.ts} +2 -1
- package/dist/with-auth/index.d.ts +704 -0
- package/dist/with-auth/index.js +1221 -0
- package/dist/with-auth/index.js.map +1 -0
- package/package.json +25 -10
- package/dist/chunk-2IFGILT3.js.map +0 -1
- package/dist/chunk-3M2U6TXH.js +0 -928
- package/dist/chunk-3M2U6TXH.js.map +0 -1
- package/dist/chunk-5ZYAEGCJ.js +0 -416
- package/dist/chunk-5ZYAEGCJ.js.map +0 -1
- package/dist/chunk-7HG6G25H.js.map +0 -1
- package/dist/chunk-7XT7K4QT.js +0 -2687
- package/dist/chunk-7XT7K4QT.js.map +0 -1
- package/dist/chunk-AWFMICFV.js +0 -158
- package/dist/chunk-AWFMICFV.js.map +0 -1
- package/dist/chunk-BRTW7CO5.js.map +0 -1
- package/dist/chunk-EL45Z26M.js.map +0 -1
- package/dist/chunk-ERGF2FCE.js +0 -903
- package/dist/chunk-ERGF2FCE.js.map +0 -1
- package/dist/chunk-GK7B66LY.js +0 -135
- package/dist/chunk-GK7B66LY.js.map +0 -1
- package/dist/chunk-GQI6WJGI.js +0 -172
- package/dist/chunk-GQI6WJGI.js.map +0 -1
- package/dist/chunk-JUVE3DWY.js.map +0 -1
- package/dist/chunk-O3K7R32P.js.map +0 -1
- package/dist/chunk-SEY5UO2T.js +0 -89
- package/dist/chunk-SEY5UO2T.js.map +0 -1
- package/dist/chunk-USJYMRUO.js.map +0 -1
- package/dist/chunk-XX3IWSPM.js +0 -189
- package/dist/chunk-XX3IWSPM.js.map +0 -1
- package/dist/chunk-Y3INY2CS.js.map +0 -1
- package/dist/chunk-ZTSBF536.js.map +0 -1
- /package/dist/{canvas-75Y7XMF3.js.map → canvas-ZQNCL7JL.js.map} +0 -0
- /package/dist/{pdf-3TIGQRLA.js.map → pdf-PHXP7RHD.js.map} +0 -0
|
@@ -2,23 +2,25 @@ import {
|
|
|
2
2
|
createAdapterAutoDetector,
|
|
3
3
|
createAdapterRegistry,
|
|
4
4
|
createSupabaseAdapter
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-NZON56CB.js";
|
|
6
6
|
import {
|
|
7
7
|
DataLayerContext
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-ZVBHWU7O.js";
|
|
9
9
|
import {
|
|
10
|
-
QueryExecutor
|
|
11
|
-
|
|
10
|
+
QueryExecutor,
|
|
11
|
+
extractRelationNames,
|
|
12
|
+
parseSelect
|
|
13
|
+
} from "./chunk-X3HZLNBV.js";
|
|
12
14
|
import {
|
|
13
15
|
getSupabaseUrl
|
|
14
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-GC3TBUWE.js";
|
|
15
17
|
import {
|
|
16
18
|
isNullOrWhitespace,
|
|
17
19
|
newUuid
|
|
18
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-OQ7U6EQ3.js";
|
|
19
21
|
import {
|
|
20
22
|
useSupabase
|
|
21
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-5EFDS7SR.js";
|
|
22
24
|
import {
|
|
23
25
|
__commonJS,
|
|
24
26
|
__toESM
|
|
@@ -999,7 +1001,139 @@ var require_es = __commonJS({
|
|
|
999
1001
|
}
|
|
1000
1002
|
});
|
|
1001
1003
|
|
|
1004
|
+
// ../../../node_modules/.pnpm/is-plain-obj@2.1.0/node_modules/is-plain-obj/index.js
|
|
1005
|
+
var require_is_plain_obj = __commonJS({
|
|
1006
|
+
"../../../node_modules/.pnpm/is-plain-obj@2.1.0/node_modules/is-plain-obj/index.js"(exports, module) {
|
|
1007
|
+
"use strict";
|
|
1008
|
+
module.exports = (value) => {
|
|
1009
|
+
if (Object.prototype.toString.call(value) !== "[object Object]") {
|
|
1010
|
+
return false;
|
|
1011
|
+
}
|
|
1012
|
+
const prototype = Object.getPrototypeOf(value);
|
|
1013
|
+
return prototype === null || prototype === Object.prototype;
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
});
|
|
1017
|
+
|
|
1018
|
+
// ../../../node_modules/.pnpm/merge-options@3.0.4/node_modules/merge-options/index.js
|
|
1019
|
+
var require_merge_options = __commonJS({
|
|
1020
|
+
"../../../node_modules/.pnpm/merge-options@3.0.4/node_modules/merge-options/index.js"(exports, module) {
|
|
1021
|
+
"use strict";
|
|
1022
|
+
var isOptionObject = require_is_plain_obj();
|
|
1023
|
+
var { hasOwnProperty } = Object.prototype;
|
|
1024
|
+
var { propertyIsEnumerable } = Object;
|
|
1025
|
+
var defineProperty = (object, name, value) => Object.defineProperty(object, name, {
|
|
1026
|
+
value,
|
|
1027
|
+
writable: true,
|
|
1028
|
+
enumerable: true,
|
|
1029
|
+
configurable: true
|
|
1030
|
+
});
|
|
1031
|
+
var globalThis2 = exports;
|
|
1032
|
+
var defaultMergeOptions = {
|
|
1033
|
+
concatArrays: false,
|
|
1034
|
+
ignoreUndefined: false
|
|
1035
|
+
};
|
|
1036
|
+
var getEnumerableOwnPropertyKeys = (value) => {
|
|
1037
|
+
const keys = [];
|
|
1038
|
+
for (const key in value) {
|
|
1039
|
+
if (hasOwnProperty.call(value, key)) {
|
|
1040
|
+
keys.push(key);
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
if (Object.getOwnPropertySymbols) {
|
|
1044
|
+
const symbols = Object.getOwnPropertySymbols(value);
|
|
1045
|
+
for (const symbol of symbols) {
|
|
1046
|
+
if (propertyIsEnumerable.call(value, symbol)) {
|
|
1047
|
+
keys.push(symbol);
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
return keys;
|
|
1052
|
+
};
|
|
1053
|
+
function clone(value) {
|
|
1054
|
+
if (Array.isArray(value)) {
|
|
1055
|
+
return cloneArray(value);
|
|
1056
|
+
}
|
|
1057
|
+
if (isOptionObject(value)) {
|
|
1058
|
+
return cloneOptionObject(value);
|
|
1059
|
+
}
|
|
1060
|
+
return value;
|
|
1061
|
+
}
|
|
1062
|
+
function cloneArray(array) {
|
|
1063
|
+
const result = array.slice(0, 0);
|
|
1064
|
+
getEnumerableOwnPropertyKeys(array).forEach((key) => {
|
|
1065
|
+
defineProperty(result, key, clone(array[key]));
|
|
1066
|
+
});
|
|
1067
|
+
return result;
|
|
1068
|
+
}
|
|
1069
|
+
function cloneOptionObject(object) {
|
|
1070
|
+
const result = Object.getPrototypeOf(object) === null ? /* @__PURE__ */ Object.create(null) : {};
|
|
1071
|
+
getEnumerableOwnPropertyKeys(object).forEach((key) => {
|
|
1072
|
+
defineProperty(result, key, clone(object[key]));
|
|
1073
|
+
});
|
|
1074
|
+
return result;
|
|
1075
|
+
}
|
|
1076
|
+
var mergeKeys = (merged, source, keys, config) => {
|
|
1077
|
+
keys.forEach((key) => {
|
|
1078
|
+
if (typeof source[key] === "undefined" && config.ignoreUndefined) {
|
|
1079
|
+
return;
|
|
1080
|
+
}
|
|
1081
|
+
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
|
|
1082
|
+
defineProperty(merged, key, merge2(merged[key], source[key], config));
|
|
1083
|
+
} else {
|
|
1084
|
+
defineProperty(merged, key, clone(source[key]));
|
|
1085
|
+
}
|
|
1086
|
+
});
|
|
1087
|
+
return merged;
|
|
1088
|
+
};
|
|
1089
|
+
var concatArrays = (merged, source, config) => {
|
|
1090
|
+
let result = merged.slice(0, 0);
|
|
1091
|
+
let resultIndex = 0;
|
|
1092
|
+
[merged, source].forEach((array) => {
|
|
1093
|
+
const indices = [];
|
|
1094
|
+
for (let k = 0; k < array.length; k++) {
|
|
1095
|
+
if (!hasOwnProperty.call(array, k)) {
|
|
1096
|
+
continue;
|
|
1097
|
+
}
|
|
1098
|
+
indices.push(String(k));
|
|
1099
|
+
if (array === merged) {
|
|
1100
|
+
defineProperty(result, resultIndex++, array[k]);
|
|
1101
|
+
} else {
|
|
1102
|
+
defineProperty(result, resultIndex++, clone(array[k]));
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter((key) => !indices.includes(key)), config);
|
|
1106
|
+
});
|
|
1107
|
+
return result;
|
|
1108
|
+
};
|
|
1109
|
+
function merge2(merged, source, config) {
|
|
1110
|
+
if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
|
|
1111
|
+
return concatArrays(merged, source, config);
|
|
1112
|
+
}
|
|
1113
|
+
if (!isOptionObject(source) || !isOptionObject(merged)) {
|
|
1114
|
+
return clone(source);
|
|
1115
|
+
}
|
|
1116
|
+
return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config);
|
|
1117
|
+
}
|
|
1118
|
+
module.exports = function(...options) {
|
|
1119
|
+
const config = merge2(clone(defaultMergeOptions), this !== globalThis2 && this || {}, defaultMergeOptions);
|
|
1120
|
+
let merged = { _: {} };
|
|
1121
|
+
for (const option of options) {
|
|
1122
|
+
if (option === void 0) {
|
|
1123
|
+
continue;
|
|
1124
|
+
}
|
|
1125
|
+
if (!isOptionObject(option)) {
|
|
1126
|
+
throw new TypeError("`" + option + "` is not an Option Object");
|
|
1127
|
+
}
|
|
1128
|
+
merged = merge2(merged, { _: option }, config);
|
|
1129
|
+
}
|
|
1130
|
+
return merged._;
|
|
1131
|
+
};
|
|
1132
|
+
}
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1002
1135
|
// src/useDbUpload.ts
|
|
1136
|
+
import { c as _c } from "react/compiler-runtime";
|
|
1003
1137
|
import { useMutation } from "@tanstack/react-query";
|
|
1004
1138
|
import { Upload } from "tus-js-client";
|
|
1005
1139
|
function sanitizeStorageKey(path) {
|
|
@@ -1007,7 +1141,11 @@ function sanitizeStorageKey(path) {
|
|
|
1007
1141
|
return cleaned.trim().replace(/\s+/g, "-").replace(/[^A-Za-z0-9\-_.\/]/g, "");
|
|
1008
1142
|
}
|
|
1009
1143
|
async function uploadFile(supabase, bucketName, fileName, fileBody, fileOptions, requestOptions) {
|
|
1010
|
-
const {
|
|
1144
|
+
const {
|
|
1145
|
+
data: {
|
|
1146
|
+
session
|
|
1147
|
+
}
|
|
1148
|
+
} = await supabase.auth.getSession();
|
|
1011
1149
|
if (session === null) throw new Error("User needs to be logged in.");
|
|
1012
1150
|
const contentType = "type" in fileBody ? fileBody.type : fileOptions.contentType;
|
|
1013
1151
|
if (contentType === void 0) {
|
|
@@ -1052,42 +1190,60 @@ async function uploadFile(supabase, bucketName, fileName, fileBody, fileOptions,
|
|
|
1052
1190
|
});
|
|
1053
1191
|
});
|
|
1054
1192
|
}
|
|
1055
|
-
function useDbAttachmentUpload(bucketId,
|
|
1056
|
-
|
|
1193
|
+
function useDbAttachmentUpload(bucketId, t0) {
|
|
1194
|
+
const $ = _c(6);
|
|
1195
|
+
let t1;
|
|
1196
|
+
if ($[0] !== t0) {
|
|
1197
|
+
t1 = t0 === void 0 ? {
|
|
1198
|
+
onUploadProgress: _temp
|
|
1199
|
+
} : t0;
|
|
1200
|
+
$[0] = t0;
|
|
1201
|
+
$[1] = t1;
|
|
1202
|
+
} else {
|
|
1203
|
+
t1 = $[1];
|
|
1057
1204
|
}
|
|
1058
|
-
|
|
1205
|
+
const options = t1;
|
|
1059
1206
|
const supabase = useSupabase();
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
bucketId,
|
|
1071
|
-
filePath,
|
|
1072
|
-
item.file,
|
|
1073
|
-
{
|
|
1207
|
+
let t2;
|
|
1208
|
+
if ($[2] !== bucketId || $[3] !== options || $[4] !== supabase) {
|
|
1209
|
+
t2 = {
|
|
1210
|
+
mutationFn: async (item) => {
|
|
1211
|
+
const directory = item.directory ?? newUuid();
|
|
1212
|
+
const originalName = item.fileName ?? ("name" in item.file ? String(item.file.name) : "") ?? ("fileName" in item.file ? String(item.file.fileName) : "");
|
|
1213
|
+
if (isNullOrWhitespace(originalName)) {
|
|
1214
|
+
throw new Error("file must have a valid name");
|
|
1215
|
+
}
|
|
1216
|
+
const filePath = `${directory}/${sanitizeStorageKey(originalName)}`;
|
|
1217
|
+
await uploadFile(supabase, bucketId, filePath, item.file, {
|
|
1074
1218
|
upsert: item.upsert,
|
|
1075
1219
|
cacheControl: item.cacheControl,
|
|
1076
1220
|
contentType: item.contentType,
|
|
1077
1221
|
duplex: item.duplex
|
|
1078
|
-
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1222
|
+
}, {
|
|
1223
|
+
...options,
|
|
1224
|
+
onUploadProgress: item.onUploadProgress ?? _temp2
|
|
1225
|
+
});
|
|
1226
|
+
return {
|
|
1227
|
+
bucketId,
|
|
1228
|
+
path: filePath,
|
|
1229
|
+
contentType: item.contentType
|
|
1230
|
+
};
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
$[2] = bucketId;
|
|
1234
|
+
$[3] = options;
|
|
1235
|
+
$[4] = supabase;
|
|
1236
|
+
$[5] = t2;
|
|
1237
|
+
} else {
|
|
1238
|
+
t2 = $[5];
|
|
1239
|
+
}
|
|
1240
|
+
const uploadMutation = useMutation(t2);
|
|
1089
1241
|
return uploadMutation;
|
|
1090
1242
|
}
|
|
1243
|
+
function _temp2() {
|
|
1244
|
+
}
|
|
1245
|
+
function _temp() {
|
|
1246
|
+
}
|
|
1091
1247
|
|
|
1092
1248
|
// src/utils/type-transformer.ts
|
|
1093
1249
|
function transformValueFromStorage(value, columnInfo) {
|
|
@@ -1162,15 +1318,9 @@ function transformWithRelations(row, schema, tableName) {
|
|
|
1162
1318
|
const result = {};
|
|
1163
1319
|
for (const [key, value] of Object.entries(row)) {
|
|
1164
1320
|
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
1165
|
-
result[key] = transformWithRelations(
|
|
1166
|
-
value,
|
|
1167
|
-
schema,
|
|
1168
|
-
key
|
|
1169
|
-
);
|
|
1321
|
+
result[key] = transformWithRelations(value, schema, key);
|
|
1170
1322
|
} else if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") {
|
|
1171
|
-
result[key] = value.map(
|
|
1172
|
-
(item) => transformWithRelations(item, schema, key)
|
|
1173
|
-
);
|
|
1323
|
+
result[key] = value.map((item) => transformWithRelations(item, schema, key));
|
|
1174
1324
|
} else if (columnMap) {
|
|
1175
1325
|
const columnInfo = columnMap.get(key);
|
|
1176
1326
|
if (columnInfo) {
|
|
@@ -1226,24 +1376,16 @@ var PowerSyncAdapter = class {
|
|
|
1226
1376
|
* @returns Promise resolving to query results with optional count
|
|
1227
1377
|
*/
|
|
1228
1378
|
async query(table, options = {}) {
|
|
1229
|
-
const rawData = await this.executor.execute(
|
|
1230
|
-
table,
|
|
1231
|
-
options
|
|
1232
|
-
);
|
|
1379
|
+
const rawData = await this.executor.execute(table, options);
|
|
1233
1380
|
const hasRelations = options.select && options.select.includes("(") && options.select !== "*";
|
|
1234
|
-
const data = hasRelations ? rawData.map(
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
this.schema,
|
|
1243
|
-
table
|
|
1244
|
-
);
|
|
1245
|
-
const count = options.limit !== void 0 ? await this.executor.count(table, { where: options.where }) : void 0;
|
|
1246
|
-
return { data, count };
|
|
1381
|
+
const data = hasRelations ? rawData.map((row) => transformWithRelations(row, this.schema, table)) : transformResultsFromStorage(rawData, this.schema, table);
|
|
1382
|
+
const count = options.limit !== void 0 ? await this.executor.count(table, {
|
|
1383
|
+
where: options.where
|
|
1384
|
+
}) : void 0;
|
|
1385
|
+
return {
|
|
1386
|
+
data,
|
|
1387
|
+
count
|
|
1388
|
+
};
|
|
1247
1389
|
}
|
|
1248
1390
|
/**
|
|
1249
1391
|
* Query a single record by ID.
|
|
@@ -1254,19 +1396,11 @@ var PowerSyncAdapter = class {
|
|
|
1254
1396
|
* @returns Promise resolving to the record or null if not found
|
|
1255
1397
|
*/
|
|
1256
1398
|
async queryById(table, id, options) {
|
|
1257
|
-
const rawResult = await this.executor.executeById(
|
|
1258
|
-
table,
|
|
1259
|
-
id,
|
|
1260
|
-
options
|
|
1261
|
-
);
|
|
1399
|
+
const rawResult = await this.executor.executeById(table, id, options);
|
|
1262
1400
|
if (!rawResult) {
|
|
1263
1401
|
return null;
|
|
1264
1402
|
}
|
|
1265
|
-
return transformWithRelations(
|
|
1266
|
-
rawResult,
|
|
1267
|
-
this.schema,
|
|
1268
|
-
table
|
|
1269
|
-
);
|
|
1403
|
+
return transformWithRelations(rawResult, this.schema, table);
|
|
1270
1404
|
}
|
|
1271
1405
|
/**
|
|
1272
1406
|
* Subscribe to changes on a query using PowerSync's native watch() API.
|
|
@@ -1287,37 +1421,37 @@ var PowerSyncAdapter = class {
|
|
|
1287
1421
|
}
|
|
1288
1422
|
const abortController = new AbortController();
|
|
1289
1423
|
const builder = this.executor.getBuilder();
|
|
1290
|
-
const {
|
|
1424
|
+
const {
|
|
1425
|
+
sql,
|
|
1426
|
+
params
|
|
1427
|
+
} = builder.build(table, "*", {
|
|
1291
1428
|
where: options.where,
|
|
1292
1429
|
orderBy: options.orderBy,
|
|
1293
1430
|
limit: options.limit,
|
|
1294
1431
|
offset: options.offset
|
|
1295
1432
|
});
|
|
1433
|
+
let watchTables = [table];
|
|
1434
|
+
if (options.select && options.select !== "*") {
|
|
1435
|
+
const parsed = parseSelect(options.select);
|
|
1436
|
+
const relationNames = extractRelationNames(parsed);
|
|
1437
|
+
watchTables = [table, ...relationNames];
|
|
1438
|
+
}
|
|
1296
1439
|
const schema = this.schema;
|
|
1297
|
-
this.db.watch(
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
const rawData = results.rows?._array ?? [];
|
|
1303
|
-
const data = transformResultsFromStorage(
|
|
1304
|
-
rawData,
|
|
1305
|
-
schema,
|
|
1306
|
-
table
|
|
1307
|
-
);
|
|
1308
|
-
callback(data);
|
|
1309
|
-
},
|
|
1310
|
-
onError: (error) => {
|
|
1311
|
-
console.error(`PowerSync subscription error for ${table}:`, error);
|
|
1312
|
-
}
|
|
1440
|
+
this.db.watch(sql, params, {
|
|
1441
|
+
onResult: (results) => {
|
|
1442
|
+
const rawData = results.rows?._array ?? [];
|
|
1443
|
+
const data = transformResultsFromStorage(rawData, schema, table);
|
|
1444
|
+
callback(data);
|
|
1313
1445
|
},
|
|
1314
|
-
{
|
|
1315
|
-
|
|
1316
|
-
tables: [table],
|
|
1317
|
-
throttleMs: 100
|
|
1318
|
-
// Throttle to prevent excessive re-queries
|
|
1446
|
+
onError: (error) => {
|
|
1447
|
+
console.error(`PowerSync subscription error for ${table}:`, error);
|
|
1319
1448
|
}
|
|
1320
|
-
|
|
1449
|
+
}, {
|
|
1450
|
+
signal: abortController.signal,
|
|
1451
|
+
tables: watchTables,
|
|
1452
|
+
throttleMs: 100
|
|
1453
|
+
// Throttle to prevent excessive re-queries
|
|
1454
|
+
});
|
|
1321
1455
|
return () => {
|
|
1322
1456
|
abortController.abort();
|
|
1323
1457
|
};
|
|
@@ -1332,7 +1466,9 @@ var PowerSyncAdapter = class {
|
|
|
1332
1466
|
const poll = async () => {
|
|
1333
1467
|
if (!isActive) return;
|
|
1334
1468
|
try {
|
|
1335
|
-
const {
|
|
1469
|
+
const {
|
|
1470
|
+
data
|
|
1471
|
+
} = await this.query(table, options);
|
|
1336
1472
|
callback(data);
|
|
1337
1473
|
} catch (error) {
|
|
1338
1474
|
console.error(`PowerSync subscription error for ${table}:`, error);
|
|
@@ -1356,7 +1492,21 @@ var PowerSyncAdapter = class {
|
|
|
1356
1492
|
* @returns Promise resolving to the inserted record
|
|
1357
1493
|
*/
|
|
1358
1494
|
async insert(table, data) {
|
|
1359
|
-
|
|
1495
|
+
if (__DEV__) {
|
|
1496
|
+
console.log(`[PowerSyncAdapter] insert called:`, {
|
|
1497
|
+
table,
|
|
1498
|
+
dataKeys: Object.keys(data),
|
|
1499
|
+
hasId: "id" in data
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
const result = await this.executor.insert(table, data);
|
|
1503
|
+
if (__DEV__) {
|
|
1504
|
+
console.log(`[PowerSyncAdapter] insert completed:`, {
|
|
1505
|
+
table,
|
|
1506
|
+
resultId: result?.id ?? "unknown"
|
|
1507
|
+
});
|
|
1508
|
+
}
|
|
1509
|
+
return result;
|
|
1360
1510
|
}
|
|
1361
1511
|
/**
|
|
1362
1512
|
* Update an existing record by ID.
|
|
@@ -1367,7 +1517,22 @@ var PowerSyncAdapter = class {
|
|
|
1367
1517
|
* @returns Promise resolving to the updated record
|
|
1368
1518
|
*/
|
|
1369
1519
|
async update(table, id, data) {
|
|
1370
|
-
|
|
1520
|
+
if (__DEV__) {
|
|
1521
|
+
console.log(`[PowerSyncAdapter] update called:`, {
|
|
1522
|
+
table,
|
|
1523
|
+
id,
|
|
1524
|
+
dataKeys: Object.keys(data)
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
const result = await this.executor.update(table, id, data);
|
|
1528
|
+
if (__DEV__) {
|
|
1529
|
+
console.log(`[PowerSyncAdapter] update completed:`, {
|
|
1530
|
+
table,
|
|
1531
|
+
id,
|
|
1532
|
+
resultId: result?.id ?? "unknown"
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
return result;
|
|
1371
1536
|
}
|
|
1372
1537
|
/**
|
|
1373
1538
|
* Upsert (insert or update) a record.
|
|
@@ -1379,7 +1544,22 @@ var PowerSyncAdapter = class {
|
|
|
1379
1544
|
* @returns Promise resolving to the upserted record
|
|
1380
1545
|
*/
|
|
1381
1546
|
async upsert(table, data) {
|
|
1382
|
-
|
|
1547
|
+
if (__DEV__) {
|
|
1548
|
+
console.log(`[PowerSyncAdapter] upsert called:`, {
|
|
1549
|
+
table,
|
|
1550
|
+
dataKeys: Object.keys(data),
|
|
1551
|
+
hasId: "id" in data,
|
|
1552
|
+
idValue: data?.id ?? "none"
|
|
1553
|
+
});
|
|
1554
|
+
}
|
|
1555
|
+
const result = await this.executor.upsert(table, data);
|
|
1556
|
+
if (__DEV__) {
|
|
1557
|
+
console.log(`[PowerSyncAdapter] upsert completed:`, {
|
|
1558
|
+
table,
|
|
1559
|
+
resultId: result?.id ?? "unknown"
|
|
1560
|
+
});
|
|
1561
|
+
}
|
|
1562
|
+
return result;
|
|
1383
1563
|
}
|
|
1384
1564
|
/**
|
|
1385
1565
|
* Delete a record by ID.
|
|
@@ -1430,12 +1610,7 @@ function createPowerSyncAdapter(db, schema) {
|
|
|
1430
1610
|
}
|
|
1431
1611
|
|
|
1432
1612
|
// src/providers/DataLayerProvider.tsx
|
|
1433
|
-
import {
|
|
1434
|
-
useState,
|
|
1435
|
-
useEffect,
|
|
1436
|
-
useMemo,
|
|
1437
|
-
useCallback
|
|
1438
|
-
} from "react";
|
|
1613
|
+
import { useState, useEffect, useMemo, useCallback } from "react";
|
|
1439
1614
|
import { jsx } from "react/jsx-runtime";
|
|
1440
1615
|
var defaultSyncStatus = {
|
|
1441
1616
|
isConnected: false,
|
|
@@ -1465,40 +1640,31 @@ function DataLayerProvider({
|
|
|
1465
1640
|
supabaseClient,
|
|
1466
1641
|
queryClient,
|
|
1467
1642
|
onInitialized,
|
|
1468
|
-
onError
|
|
1643
|
+
onError,
|
|
1644
|
+
powerSyncSyncStatus
|
|
1469
1645
|
}) {
|
|
1470
|
-
const [registry] = useState(
|
|
1471
|
-
|
|
1472
|
-
);
|
|
1473
|
-
const [autoDetector, setAutoDetector] = useState(
|
|
1474
|
-
null
|
|
1475
|
-
);
|
|
1646
|
+
const [registry] = useState(() => createAdapterRegistry(config));
|
|
1647
|
+
const [autoDetector, setAutoDetector] = useState(null);
|
|
1476
1648
|
const [status, setStatus] = useState({
|
|
1477
1649
|
isInitialized: false,
|
|
1478
1650
|
currentBackend: null,
|
|
1479
1651
|
powerSyncStatus: "unavailable" /* UNAVAILABLE */,
|
|
1480
|
-
isOnline: typeof navigator !== "undefined" ? navigator.onLine : true,
|
|
1652
|
+
isOnline: powerSyncSyncStatus?.isOnline ?? (typeof navigator !== "undefined" ? navigator.onLine : true),
|
|
1481
1653
|
lastDetection: null,
|
|
1482
|
-
error: null
|
|
1654
|
+
error: null,
|
|
1655
|
+
hasSynced: powerSyncSyncStatus?.hasSynced ?? false
|
|
1483
1656
|
});
|
|
1484
1657
|
useEffect(() => {
|
|
1485
1658
|
try {
|
|
1486
|
-
const detector = createAdapterAutoDetector(
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
);
|
|
1659
|
+
const detector = createAdapterAutoDetector(powerSyncInstance, supabaseClient, {
|
|
1660
|
+
preferPowerSync: true,
|
|
1661
|
+
useOnlineUntilSynced: config.initialSync?.useOnlineUntilSynced ?? true
|
|
1662
|
+
});
|
|
1491
1663
|
setAutoDetector(detector);
|
|
1492
|
-
const supabaseAdapter = createSupabaseAdapter(
|
|
1493
|
-
supabaseClient,
|
|
1494
|
-
config.schema
|
|
1495
|
-
);
|
|
1664
|
+
const supabaseAdapter = createSupabaseAdapter(supabaseClient, config.schema);
|
|
1496
1665
|
registry.setSupabaseAdapter(supabaseAdapter);
|
|
1497
1666
|
if (powerSyncInstance) {
|
|
1498
|
-
const powerSyncAdapter = createPowerSyncAdapter(
|
|
1499
|
-
powerSyncInstance,
|
|
1500
|
-
config.schema
|
|
1501
|
-
);
|
|
1667
|
+
const powerSyncAdapter = createPowerSyncAdapter(powerSyncInstance, config.schema);
|
|
1502
1668
|
registry.setPowerSyncAdapter(powerSyncAdapter);
|
|
1503
1669
|
}
|
|
1504
1670
|
registry.initialize({
|
|
@@ -1507,6 +1673,10 @@ function DataLayerProvider({
|
|
|
1507
1673
|
queryClient,
|
|
1508
1674
|
schema: config.schema
|
|
1509
1675
|
});
|
|
1676
|
+
registry.initializeAutoDetection(detector);
|
|
1677
|
+
if (powerSyncSyncStatus) {
|
|
1678
|
+
detector.updateSyncStatus(powerSyncSyncStatus);
|
|
1679
|
+
}
|
|
1510
1680
|
const detection = detector.detect();
|
|
1511
1681
|
setStatus({
|
|
1512
1682
|
isInitialized: true,
|
|
@@ -1514,7 +1684,8 @@ function DataLayerProvider({
|
|
|
1514
1684
|
powerSyncStatus: detection.powerSyncStatus,
|
|
1515
1685
|
isOnline: detection.isOnline,
|
|
1516
1686
|
lastDetection: detection,
|
|
1517
|
-
error: null
|
|
1687
|
+
error: null,
|
|
1688
|
+
hasSynced: powerSyncSyncStatus?.hasSynced ?? false
|
|
1518
1689
|
});
|
|
1519
1690
|
} catch (error) {
|
|
1520
1691
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
@@ -1524,17 +1695,16 @@ function DataLayerProvider({
|
|
|
1524
1695
|
}));
|
|
1525
1696
|
onError?.(err);
|
|
1526
1697
|
}
|
|
1527
|
-
}, [
|
|
1528
|
-
powerSyncInstance,
|
|
1529
|
-
supabaseClient,
|
|
1530
|
-
queryClient,
|
|
1531
|
-
config.schema,
|
|
1532
|
-
registry,
|
|
1533
|
-
onError
|
|
1534
|
-
]);
|
|
1698
|
+
}, [powerSyncInstance, supabaseClient, queryClient, config.schema, registry, onError, powerSyncSyncStatus]);
|
|
1535
1699
|
useEffect(() => {
|
|
1700
|
+
if (powerSyncSyncStatus?.isOnline !== void 0) {
|
|
1701
|
+
return;
|
|
1702
|
+
}
|
|
1536
1703
|
const handleOnline = () => {
|
|
1537
|
-
setStatus((prev) => ({
|
|
1704
|
+
setStatus((prev) => ({
|
|
1705
|
+
...prev,
|
|
1706
|
+
isOnline: true
|
|
1707
|
+
}));
|
|
1538
1708
|
if (autoDetector) {
|
|
1539
1709
|
const detection = autoDetector.detect();
|
|
1540
1710
|
setStatus((prev) => ({
|
|
@@ -1546,7 +1716,10 @@ function DataLayerProvider({
|
|
|
1546
1716
|
}
|
|
1547
1717
|
};
|
|
1548
1718
|
const handleOffline = () => {
|
|
1549
|
-
setStatus((prev) => ({
|
|
1719
|
+
setStatus((prev) => ({
|
|
1720
|
+
...prev,
|
|
1721
|
+
isOnline: false
|
|
1722
|
+
}));
|
|
1550
1723
|
if (autoDetector) {
|
|
1551
1724
|
const detection = autoDetector.detect();
|
|
1552
1725
|
setStatus((prev) => ({
|
|
@@ -1566,7 +1739,7 @@ function DataLayerProvider({
|
|
|
1566
1739
|
window.removeEventListener("offline", handleOffline);
|
|
1567
1740
|
};
|
|
1568
1741
|
}
|
|
1569
|
-
}, [autoDetector]);
|
|
1742
|
+
}, [autoDetector, powerSyncSyncStatus?.isOnline]);
|
|
1570
1743
|
useEffect(() => {
|
|
1571
1744
|
if (!autoDetector) return;
|
|
1572
1745
|
const unsubscribe = autoDetector.addListener((detection) => {
|
|
@@ -1580,6 +1753,18 @@ function DataLayerProvider({
|
|
|
1580
1753
|
});
|
|
1581
1754
|
return unsubscribe;
|
|
1582
1755
|
}, [autoDetector]);
|
|
1756
|
+
useEffect(() => {
|
|
1757
|
+
if (!autoDetector) return;
|
|
1758
|
+
autoDetector.updateSyncStatus(powerSyncSyncStatus ?? null);
|
|
1759
|
+
setStatus((prev) => ({
|
|
1760
|
+
...prev,
|
|
1761
|
+
hasSynced: powerSyncSyncStatus?.hasSynced ?? false,
|
|
1762
|
+
// Only update isOnline if powerSyncSyncStatus provides it (React Native via NetInfo)
|
|
1763
|
+
...powerSyncSyncStatus?.isOnline !== void 0 && {
|
|
1764
|
+
isOnline: powerSyncSyncStatus.isOnline
|
|
1765
|
+
}
|
|
1766
|
+
}));
|
|
1767
|
+
}, [autoDetector, powerSyncSyncStatus?.hasSynced, powerSyncSyncStatus?.connected, powerSyncSyncStatus?.connecting, powerSyncSyncStatus?.isOnline]);
|
|
1583
1768
|
useEffect(() => {
|
|
1584
1769
|
if (status.isInitialized && !status.error && onInitialized) {
|
|
1585
1770
|
const contextValue2 = buildContextValue();
|
|
@@ -1588,12 +1773,9 @@ function DataLayerProvider({
|
|
|
1588
1773
|
}
|
|
1589
1774
|
}
|
|
1590
1775
|
}, [status.isInitialized, status.error]);
|
|
1591
|
-
const getAdapter = useCallback(
|
|
1592
|
-
(table)
|
|
1593
|
-
|
|
1594
|
-
},
|
|
1595
|
-
[registry]
|
|
1596
|
-
);
|
|
1776
|
+
const getAdapter = useCallback((table) => {
|
|
1777
|
+
return registry.getAdapter(table);
|
|
1778
|
+
}, [registry]);
|
|
1597
1779
|
const buildContextValue = useCallback(() => {
|
|
1598
1780
|
if (!status.isInitialized) return null;
|
|
1599
1781
|
return {
|
|
@@ -1607,19 +1789,8 @@ function DataLayerProvider({
|
|
|
1607
1789
|
syncStatus: defaultSyncStatus,
|
|
1608
1790
|
syncControl: defaultSyncControl
|
|
1609
1791
|
};
|
|
1610
|
-
}, [
|
|
1611
|
-
|
|
1612
|
-
getAdapter,
|
|
1613
|
-
powerSyncInstance,
|
|
1614
|
-
supabaseClient,
|
|
1615
|
-
queryClient,
|
|
1616
|
-
config.schema,
|
|
1617
|
-
status
|
|
1618
|
-
]);
|
|
1619
|
-
const contextValue = useMemo(
|
|
1620
|
-
() => buildContextValue(),
|
|
1621
|
-
[buildContextValue]
|
|
1622
|
-
);
|
|
1792
|
+
}, [registry, getAdapter, powerSyncInstance, supabaseClient, queryClient, config.schema, status]);
|
|
1793
|
+
const contextValue = useMemo(() => buildContextValue(), [buildContextValue]);
|
|
1623
1794
|
useEffect(() => {
|
|
1624
1795
|
return () => {
|
|
1625
1796
|
registry.dispose();
|
|
@@ -4062,30 +4233,30 @@ var useSupabaseUpload = (options) => {
|
|
|
4062
4233
|
}
|
|
4063
4234
|
return false;
|
|
4064
4235
|
}, [errors.length, successes.length, files.length]);
|
|
4065
|
-
const onDrop = useCallback3(
|
|
4066
|
-
(
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
);
|
|
4236
|
+
const onDrop = useCallback3((acceptedFiles, fileRejections) => {
|
|
4237
|
+
const validFiles = acceptedFiles.filter((file) => !files.find((x) => x.name === file.name)).map((file_0) => {
|
|
4238
|
+
file_0.preview = URL.createObjectURL(file_0);
|
|
4239
|
+
file_0.errors = [];
|
|
4240
|
+
return file_0;
|
|
4241
|
+
});
|
|
4242
|
+
const invalidFiles = fileRejections.map(({
|
|
4243
|
+
file: file_1,
|
|
4244
|
+
errors: errors_0
|
|
4245
|
+
}) => {
|
|
4246
|
+
file_1.preview = URL.createObjectURL(file_1);
|
|
4247
|
+
file_1.errors = errors_0;
|
|
4248
|
+
return file_1;
|
|
4249
|
+
});
|
|
4250
|
+
const newFiles = [...files, ...validFiles, ...invalidFiles];
|
|
4251
|
+
setFiles(newFiles);
|
|
4252
|
+
}, [files, setFiles]);
|
|
4082
4253
|
const dropzoneProps = useDropzone({
|
|
4083
4254
|
onDrop,
|
|
4084
4255
|
noClick: true,
|
|
4085
|
-
accept: allowedMimeTypes.reduce(
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
),
|
|
4256
|
+
accept: allowedMimeTypes.reduce((acc, type) => ({
|
|
4257
|
+
...acc,
|
|
4258
|
+
[type]: []
|
|
4259
|
+
}), {}),
|
|
4089
4260
|
maxSize: maxFileSize,
|
|
4090
4261
|
maxFiles,
|
|
4091
4262
|
multiple: maxFiles !== 1
|
|
@@ -4093,30 +4264,31 @@ var useSupabaseUpload = (options) => {
|
|
|
4093
4264
|
const supabase = useSupabase();
|
|
4094
4265
|
const onUpload = useCallback3(async () => {
|
|
4095
4266
|
setLoading(true);
|
|
4096
|
-
const filesWithErrors = errors.map((
|
|
4097
|
-
const filesToUpload = filesWithErrors.length > 0 ? [
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
}
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4267
|
+
const filesWithErrors = errors.map((x_0) => x_0.name);
|
|
4268
|
+
const filesToUpload = filesWithErrors.length > 0 ? [...files.filter((f) => filesWithErrors.includes(f.name)), ...files.filter((f_0) => !successes.includes(f_0.name))] : files;
|
|
4269
|
+
const responses = await Promise.all(filesToUpload.map(async (file_2) => {
|
|
4270
|
+
const {
|
|
4271
|
+
error
|
|
4272
|
+
} = await supabase.storage.from(bucketName).upload(!!path ? `${path}/${file_2.name}` : file_2.name, file_2, {
|
|
4273
|
+
cacheControl: cacheControl.toString(),
|
|
4274
|
+
upsert
|
|
4275
|
+
});
|
|
4276
|
+
if (error) {
|
|
4277
|
+
return {
|
|
4278
|
+
name: file_2.name,
|
|
4279
|
+
message: error.message
|
|
4280
|
+
};
|
|
4281
|
+
} else {
|
|
4282
|
+
return {
|
|
4283
|
+
name: file_2.name,
|
|
4284
|
+
message: void 0
|
|
4285
|
+
};
|
|
4286
|
+
}
|
|
4287
|
+
}));
|
|
4288
|
+
const responseErrors = responses.filter((x_1) => x_1.message !== void 0);
|
|
4115
4289
|
setErrors(responseErrors);
|
|
4116
|
-
const responseSuccesses = responses.filter((
|
|
4117
|
-
const newSuccesses = Array.from(
|
|
4118
|
-
/* @__PURE__ */ new Set([...successes, ...responseSuccesses.map((x) => x.name)])
|
|
4119
|
-
);
|
|
4290
|
+
const responseSuccesses = responses.filter((x_2) => x_2.message === void 0);
|
|
4291
|
+
const newSuccesses = Array.from(/* @__PURE__ */ new Set([...successes, ...responseSuccesses.map((x_3) => x_3.name)]));
|
|
4120
4292
|
setSuccesses(newSuccesses);
|
|
4121
4293
|
setLoading(false);
|
|
4122
4294
|
}, [files, path, bucketName, errors, successes]);
|
|
@@ -4126,15 +4298,15 @@ var useSupabaseUpload = (options) => {
|
|
|
4126
4298
|
}
|
|
4127
4299
|
if (files.length <= maxFiles) {
|
|
4128
4300
|
let changed = false;
|
|
4129
|
-
const
|
|
4130
|
-
if (
|
|
4131
|
-
|
|
4301
|
+
const newFiles_0 = files.map((file_3) => {
|
|
4302
|
+
if (file_3.errors.some((e_0) => e_0.code === "too-many-files")) {
|
|
4303
|
+
file_3.errors = file_3.errors.filter((e) => e.code !== "too-many-files");
|
|
4132
4304
|
changed = true;
|
|
4133
4305
|
}
|
|
4134
|
-
return
|
|
4306
|
+
return file_3;
|
|
4135
4307
|
});
|
|
4136
4308
|
if (changed) {
|
|
4137
|
-
setFiles(
|
|
4309
|
+
setFiles(newFiles_0);
|
|
4138
4310
|
}
|
|
4139
4311
|
}
|
|
4140
4312
|
}, [files.length, setFiles, maxFiles]);
|
|
@@ -4154,13 +4326,852 @@ var useSupabaseUpload = (options) => {
|
|
|
4154
4326
|
};
|
|
4155
4327
|
};
|
|
4156
4328
|
|
|
4329
|
+
// src/conflicts/ConflictContext.tsx
|
|
4330
|
+
import { c as _c2 } from "react/compiler-runtime";
|
|
4331
|
+
import { createContext, useEffect as useEffect4, useReducer as useReducer2, useRef as useRef2 } from "react";
|
|
4332
|
+
|
|
4333
|
+
// ../../../node_modules/.pnpm/merge-options@3.0.4/node_modules/merge-options/index.mjs
|
|
4334
|
+
var import_index = __toESM(require_merge_options(), 1);
|
|
4335
|
+
var merge_options_default = import_index.default;
|
|
4336
|
+
|
|
4337
|
+
// ../../../node_modules/.pnpm/@react-native-async-storage+async-storage@2.2.0_react-native@0.81.5_@babel+core@7.28.0_@react_2hvarrbjesownckmm5rnp7ulv4/node_modules/@react-native-async-storage/async-storage/lib/module/AsyncStorage.js
|
|
4338
|
+
var merge = merge_options_default.bind({
|
|
4339
|
+
concatArrays: true,
|
|
4340
|
+
ignoreUndefined: true
|
|
4341
|
+
});
|
|
4342
|
+
function mergeLocalStorageItem(key, value) {
|
|
4343
|
+
const oldValue = window.localStorage.getItem(key);
|
|
4344
|
+
if (oldValue) {
|
|
4345
|
+
const oldObject = JSON.parse(oldValue);
|
|
4346
|
+
const newObject = JSON.parse(value);
|
|
4347
|
+
const nextValue = JSON.stringify(merge(oldObject, newObject));
|
|
4348
|
+
window.localStorage.setItem(key, nextValue);
|
|
4349
|
+
} else {
|
|
4350
|
+
window.localStorage.setItem(key, value);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
function createPromise(getValue, callback) {
|
|
4354
|
+
return new Promise((resolve, reject) => {
|
|
4355
|
+
try {
|
|
4356
|
+
const value = getValue();
|
|
4357
|
+
callback?.(null, value);
|
|
4358
|
+
resolve(value);
|
|
4359
|
+
} catch (err) {
|
|
4360
|
+
callback?.(err);
|
|
4361
|
+
reject(err);
|
|
4362
|
+
}
|
|
4363
|
+
});
|
|
4364
|
+
}
|
|
4365
|
+
function createPromiseAll(promises, callback, processResult) {
|
|
4366
|
+
return Promise.all(promises).then((result) => {
|
|
4367
|
+
const value = processResult?.(result) ?? null;
|
|
4368
|
+
callback?.(null, value);
|
|
4369
|
+
return Promise.resolve(value);
|
|
4370
|
+
}, (errors) => {
|
|
4371
|
+
callback?.(errors);
|
|
4372
|
+
return Promise.reject(errors);
|
|
4373
|
+
});
|
|
4374
|
+
}
|
|
4375
|
+
var AsyncStorage = {
|
|
4376
|
+
/**
|
|
4377
|
+
* Fetches `key` value.
|
|
4378
|
+
*/
|
|
4379
|
+
getItem: (key, callback) => {
|
|
4380
|
+
return createPromise(() => window.localStorage.getItem(key), callback);
|
|
4381
|
+
},
|
|
4382
|
+
/**
|
|
4383
|
+
* Sets `value` for `key`.
|
|
4384
|
+
*/
|
|
4385
|
+
setItem: (key, value, callback) => {
|
|
4386
|
+
return createPromise(() => window.localStorage.setItem(key, value), callback);
|
|
4387
|
+
},
|
|
4388
|
+
/**
|
|
4389
|
+
* Removes a `key`
|
|
4390
|
+
*/
|
|
4391
|
+
removeItem: (key, callback) => {
|
|
4392
|
+
return createPromise(() => window.localStorage.removeItem(key), callback);
|
|
4393
|
+
},
|
|
4394
|
+
/**
|
|
4395
|
+
* Merges existing value with input value, assuming they are stringified JSON.
|
|
4396
|
+
*/
|
|
4397
|
+
mergeItem: (key, value, callback) => {
|
|
4398
|
+
return createPromise(() => mergeLocalStorageItem(key, value), callback);
|
|
4399
|
+
},
|
|
4400
|
+
/**
|
|
4401
|
+
* Erases *all* AsyncStorage for the domain.
|
|
4402
|
+
*/
|
|
4403
|
+
clear: (callback) => {
|
|
4404
|
+
return createPromise(() => window.localStorage.clear(), callback);
|
|
4405
|
+
},
|
|
4406
|
+
/**
|
|
4407
|
+
* Gets *all* keys known to the app, for all callers, libraries, etc.
|
|
4408
|
+
*/
|
|
4409
|
+
getAllKeys: (callback) => {
|
|
4410
|
+
return createPromise(() => {
|
|
4411
|
+
const numberOfKeys = window.localStorage.length;
|
|
4412
|
+
const keys = [];
|
|
4413
|
+
for (let i = 0; i < numberOfKeys; i += 1) {
|
|
4414
|
+
const key = window.localStorage.key(i) || "";
|
|
4415
|
+
keys.push(key);
|
|
4416
|
+
}
|
|
4417
|
+
return keys;
|
|
4418
|
+
}, callback);
|
|
4419
|
+
},
|
|
4420
|
+
/**
|
|
4421
|
+
* (stub) Flushes any pending requests using a single batch call to get the data.
|
|
4422
|
+
*/
|
|
4423
|
+
flushGetRequests: () => void 0,
|
|
4424
|
+
/**
|
|
4425
|
+
* multiGet resolves to an array of key-value pair arrays that matches the
|
|
4426
|
+
* input format of multiSet.
|
|
4427
|
+
*
|
|
4428
|
+
* multiGet(['k1', 'k2']) -> [['k1', 'val1'], ['k2', 'val2']]
|
|
4429
|
+
*/
|
|
4430
|
+
multiGet: (keys, callback) => {
|
|
4431
|
+
const promises = keys.map((key) => AsyncStorage.getItem(key));
|
|
4432
|
+
const processResult = (result) => result.map((value, i) => [keys[i], value]);
|
|
4433
|
+
return createPromiseAll(promises, callback, processResult);
|
|
4434
|
+
},
|
|
4435
|
+
/**
|
|
4436
|
+
* Takes an array of key-value array pairs.
|
|
4437
|
+
* multiSet([['k1', 'val1'], ['k2', 'val2']])
|
|
4438
|
+
*/
|
|
4439
|
+
multiSet: (keyValuePairs, callback) => {
|
|
4440
|
+
const promises = keyValuePairs.map((item) => AsyncStorage.setItem(item[0], item[1]));
|
|
4441
|
+
return createPromiseAll(promises, callback);
|
|
4442
|
+
},
|
|
4443
|
+
/**
|
|
4444
|
+
* Delete all the keys in the `keys` array.
|
|
4445
|
+
*/
|
|
4446
|
+
multiRemove: (keys, callback) => {
|
|
4447
|
+
const promises = keys.map((key) => AsyncStorage.removeItem(key));
|
|
4448
|
+
return createPromiseAll(promises, callback);
|
|
4449
|
+
},
|
|
4450
|
+
/**
|
|
4451
|
+
* Takes an array of key-value array pairs and merges them with existing
|
|
4452
|
+
* values, assuming they are stringified JSON.
|
|
4453
|
+
*
|
|
4454
|
+
* multiMerge([['k1', 'val1'], ['k2', 'val2']])
|
|
4455
|
+
*/
|
|
4456
|
+
multiMerge: (keyValuePairs, callback) => {
|
|
4457
|
+
const promises = keyValuePairs.map((item) => AsyncStorage.mergeItem(item[0], item[1]));
|
|
4458
|
+
return createPromiseAll(promises, callback);
|
|
4459
|
+
}
|
|
4460
|
+
};
|
|
4461
|
+
var AsyncStorage_default = AsyncStorage;
|
|
4462
|
+
|
|
4463
|
+
// ../../../node_modules/.pnpm/@react-native-async-storage+async-storage@2.2.0_react-native@0.81.5_@babel+core@7.28.0_@react_2hvarrbjesownckmm5rnp7ulv4/node_modules/@react-native-async-storage/async-storage/lib/module/index.js
|
|
4464
|
+
var module_default = AsyncStorage_default;
|
|
4465
|
+
|
|
4466
|
+
// src/conflicts/storage.ts
|
|
4467
|
+
var CONFLICT_STORAGE_KEY = "@pol/conflicts";
|
|
4468
|
+
var TTL_MS = 24 * 60 * 60 * 1e3;
|
|
4469
|
+
async function saveConflicts(conflicts, existingTimestamps) {
|
|
4470
|
+
try {
|
|
4471
|
+
const now = Date.now();
|
|
4472
|
+
const persisted = conflicts.map((conflict) => {
|
|
4473
|
+
const key = `${conflict.table}:${conflict.recordId}`;
|
|
4474
|
+
const existingSavedAt = existingTimestamps?.get(key);
|
|
4475
|
+
return {
|
|
4476
|
+
conflict,
|
|
4477
|
+
savedAt: existingSavedAt ?? now
|
|
4478
|
+
// Preserve existing timestamp or use new
|
|
4479
|
+
};
|
|
4480
|
+
});
|
|
4481
|
+
await module_default.setItem(CONFLICT_STORAGE_KEY, JSON.stringify(persisted));
|
|
4482
|
+
} catch (error) {
|
|
4483
|
+
console.warn("[ConflictStorage] Failed to save conflicts:", error);
|
|
4484
|
+
}
|
|
4485
|
+
}
|
|
4486
|
+
async function loadConflicts() {
|
|
4487
|
+
try {
|
|
4488
|
+
const data = await module_default.getItem(CONFLICT_STORAGE_KEY);
|
|
4489
|
+
if (!data) return {
|
|
4490
|
+
conflicts: [],
|
|
4491
|
+
timestamps: /* @__PURE__ */ new Map()
|
|
4492
|
+
};
|
|
4493
|
+
const persisted = JSON.parse(data);
|
|
4494
|
+
const now = Date.now();
|
|
4495
|
+
const valid = persisted.filter((p) => now - p.savedAt < TTL_MS);
|
|
4496
|
+
if (valid.length !== persisted.length) {
|
|
4497
|
+
await module_default.setItem(CONFLICT_STORAGE_KEY, JSON.stringify(valid));
|
|
4498
|
+
}
|
|
4499
|
+
const timestamps = /* @__PURE__ */ new Map();
|
|
4500
|
+
for (const p of valid) {
|
|
4501
|
+
const key = `${p.conflict.table}:${p.conflict.recordId}`;
|
|
4502
|
+
timestamps.set(key, p.savedAt);
|
|
4503
|
+
}
|
|
4504
|
+
const conflicts = valid.map((p) => ({
|
|
4505
|
+
...p.conflict,
|
|
4506
|
+
conflicts: p.conflict.conflicts.map((fc) => ({
|
|
4507
|
+
...fc,
|
|
4508
|
+
changedAt: new Date(fc.changedAt)
|
|
4509
|
+
// Restore Date object from JSON string
|
|
4510
|
+
}))
|
|
4511
|
+
}));
|
|
4512
|
+
return {
|
|
4513
|
+
conflicts,
|
|
4514
|
+
timestamps
|
|
4515
|
+
};
|
|
4516
|
+
} catch (error) {
|
|
4517
|
+
console.warn("[ConflictStorage] Failed to load conflicts:", error);
|
|
4518
|
+
return {
|
|
4519
|
+
conflicts: [],
|
|
4520
|
+
timestamps: /* @__PURE__ */ new Map()
|
|
4521
|
+
};
|
|
4522
|
+
}
|
|
4523
|
+
}
|
|
4524
|
+
async function clearPersistedConflicts() {
|
|
4525
|
+
try {
|
|
4526
|
+
await module_default.removeItem(CONFLICT_STORAGE_KEY);
|
|
4527
|
+
} catch (error) {
|
|
4528
|
+
console.warn("[ConflictStorage] Failed to clear conflicts:", error);
|
|
4529
|
+
}
|
|
4530
|
+
}
|
|
4531
|
+
|
|
4532
|
+
// src/conflicts/ConflictContext.tsx
|
|
4533
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
4534
|
+
var ConflictContext = createContext(null);
|
|
4535
|
+
var initialState2 = {
|
|
4536
|
+
pendingConflicts: [],
|
|
4537
|
+
resolutions: /* @__PURE__ */ new Map()
|
|
4538
|
+
};
|
|
4539
|
+
function conflictKey(table, recordId) {
|
|
4540
|
+
return `${table}:${recordId}`;
|
|
4541
|
+
}
|
|
4542
|
+
function conflictReducer(state, action) {
|
|
4543
|
+
switch (action.type) {
|
|
4544
|
+
case "ADD_CONFLICT": {
|
|
4545
|
+
const existingIndex = state.pendingConflicts.findIndex((c) => c.recordId === action.conflict.recordId && c.table === action.conflict.table);
|
|
4546
|
+
if (existingIndex >= 0) {
|
|
4547
|
+
const updated = [...state.pendingConflicts];
|
|
4548
|
+
updated[existingIndex] = action.conflict;
|
|
4549
|
+
return {
|
|
4550
|
+
...state,
|
|
4551
|
+
pendingConflicts: updated
|
|
4552
|
+
};
|
|
4553
|
+
}
|
|
4554
|
+
return {
|
|
4555
|
+
...state,
|
|
4556
|
+
pendingConflicts: [...state.pendingConflicts, action.conflict]
|
|
4557
|
+
};
|
|
4558
|
+
}
|
|
4559
|
+
case "LOAD_CONFLICTS": {
|
|
4560
|
+
const existingKeys = new Set(state.pendingConflicts.map((c) => conflictKey(c.table, c.recordId)));
|
|
4561
|
+
const newConflicts = action.conflicts.filter((c) => !existingKeys.has(conflictKey(c.table, c.recordId)));
|
|
4562
|
+
return {
|
|
4563
|
+
...state,
|
|
4564
|
+
pendingConflicts: [...state.pendingConflicts, ...newConflicts]
|
|
4565
|
+
};
|
|
4566
|
+
}
|
|
4567
|
+
case "RESOLVE_CONFLICT": {
|
|
4568
|
+
const key = conflictKey(action.table, action.recordId);
|
|
4569
|
+
const newResolutions = new Map(state.resolutions);
|
|
4570
|
+
newResolutions.set(key, action.resolution);
|
|
4571
|
+
return {
|
|
4572
|
+
...state,
|
|
4573
|
+
// Remove the resolved conflict from pending
|
|
4574
|
+
pendingConflicts: state.pendingConflicts.filter((c) => conflictKey(c.table, c.recordId) !== key),
|
|
4575
|
+
resolutions: newResolutions
|
|
4576
|
+
};
|
|
4577
|
+
}
|
|
4578
|
+
case "RESOLVE_ALL": {
|
|
4579
|
+
const newResolutions = new Map(state.resolutions);
|
|
4580
|
+
for (const conflict of state.pendingConflicts) {
|
|
4581
|
+
const key = conflictKey(conflict.table, conflict.recordId);
|
|
4582
|
+
newResolutions.set(key, action.resolution);
|
|
4583
|
+
}
|
|
4584
|
+
return {
|
|
4585
|
+
pendingConflicts: [],
|
|
4586
|
+
resolutions: newResolutions
|
|
4587
|
+
};
|
|
4588
|
+
}
|
|
4589
|
+
case "REMOVE_CONFLICT": {
|
|
4590
|
+
const key = conflictKey(action.table, action.recordId);
|
|
4591
|
+
return {
|
|
4592
|
+
...state,
|
|
4593
|
+
pendingConflicts: state.pendingConflicts.filter((c) => conflictKey(c.table, c.recordId) !== key),
|
|
4594
|
+
resolutions: (() => {
|
|
4595
|
+
const newResolutions = new Map(state.resolutions);
|
|
4596
|
+
newResolutions.delete(key);
|
|
4597
|
+
return newResolutions;
|
|
4598
|
+
})()
|
|
4599
|
+
};
|
|
4600
|
+
}
|
|
4601
|
+
case "CLEAR_RESOLVED": {
|
|
4602
|
+
return {
|
|
4603
|
+
...state,
|
|
4604
|
+
resolutions: /* @__PURE__ */ new Map()
|
|
4605
|
+
};
|
|
4606
|
+
}
|
|
4607
|
+
case "CLEAR_ALL":
|
|
4608
|
+
return initialState2;
|
|
4609
|
+
default:
|
|
4610
|
+
return state;
|
|
4611
|
+
}
|
|
4612
|
+
}
|
|
4613
|
+
function ConflictProvider(t0) {
|
|
4614
|
+
const $ = _c2(29);
|
|
4615
|
+
const {
|
|
4616
|
+
children,
|
|
4617
|
+
conflictBus
|
|
4618
|
+
} = t0;
|
|
4619
|
+
const [state, dispatch] = useReducer2(conflictReducer, initialState2);
|
|
4620
|
+
const hasFinishedLoadingRef = useRef2(false);
|
|
4621
|
+
let t1;
|
|
4622
|
+
if ($[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4623
|
+
t1 = /* @__PURE__ */ new Map();
|
|
4624
|
+
$[0] = t1;
|
|
4625
|
+
} else {
|
|
4626
|
+
t1 = $[0];
|
|
4627
|
+
}
|
|
4628
|
+
const savedAtTimestampsRef = useRef2(t1);
|
|
4629
|
+
let t2;
|
|
4630
|
+
let t3;
|
|
4631
|
+
if ($[1] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4632
|
+
t2 = () => {
|
|
4633
|
+
if (hasFinishedLoadingRef.current) {
|
|
4634
|
+
return;
|
|
4635
|
+
}
|
|
4636
|
+
loadConflicts().then((t42) => {
|
|
4637
|
+
const {
|
|
4638
|
+
conflicts,
|
|
4639
|
+
timestamps
|
|
4640
|
+
} = t42;
|
|
4641
|
+
savedAtTimestampsRef.current = timestamps;
|
|
4642
|
+
if (conflicts.length > 0) {
|
|
4643
|
+
dispatch({
|
|
4644
|
+
type: "LOAD_CONFLICTS",
|
|
4645
|
+
conflicts
|
|
4646
|
+
});
|
|
4647
|
+
}
|
|
4648
|
+
}).catch(_temp3).finally(() => {
|
|
4649
|
+
hasFinishedLoadingRef.current = true;
|
|
4650
|
+
});
|
|
4651
|
+
};
|
|
4652
|
+
t3 = [];
|
|
4653
|
+
$[1] = t2;
|
|
4654
|
+
$[2] = t3;
|
|
4655
|
+
} else {
|
|
4656
|
+
t2 = $[1];
|
|
4657
|
+
t3 = $[2];
|
|
4658
|
+
}
|
|
4659
|
+
useEffect4(t2, t3);
|
|
4660
|
+
let t4;
|
|
4661
|
+
let t5;
|
|
4662
|
+
if ($[3] !== state.pendingConflicts) {
|
|
4663
|
+
t4 = () => {
|
|
4664
|
+
if (!hasFinishedLoadingRef.current) {
|
|
4665
|
+
return;
|
|
4666
|
+
}
|
|
4667
|
+
if (state.pendingConflicts.length > 0) {
|
|
4668
|
+
const now = Date.now();
|
|
4669
|
+
const updatedTimestamps = new Map(savedAtTimestampsRef.current);
|
|
4670
|
+
for (const conflict of state.pendingConflicts) {
|
|
4671
|
+
const key = `${conflict.table}:${conflict.recordId}`;
|
|
4672
|
+
if (!updatedTimestamps.has(key)) {
|
|
4673
|
+
updatedTimestamps.set(key, now);
|
|
4674
|
+
}
|
|
4675
|
+
}
|
|
4676
|
+
const currentKeys = new Set(state.pendingConflicts.map(_temp22));
|
|
4677
|
+
for (const key_0 of updatedTimestamps.keys()) {
|
|
4678
|
+
if (!currentKeys.has(key_0)) {
|
|
4679
|
+
updatedTimestamps.delete(key_0);
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
savedAtTimestampsRef.current = updatedTimestamps;
|
|
4683
|
+
saveConflicts(state.pendingConflicts, updatedTimestamps);
|
|
4684
|
+
} else {
|
|
4685
|
+
savedAtTimestampsRef.current = /* @__PURE__ */ new Map();
|
|
4686
|
+
clearPersistedConflicts();
|
|
4687
|
+
}
|
|
4688
|
+
};
|
|
4689
|
+
t5 = [state.pendingConflicts];
|
|
4690
|
+
$[3] = state.pendingConflicts;
|
|
4691
|
+
$[4] = t4;
|
|
4692
|
+
$[5] = t5;
|
|
4693
|
+
} else {
|
|
4694
|
+
t4 = $[4];
|
|
4695
|
+
t5 = $[5];
|
|
4696
|
+
}
|
|
4697
|
+
useEffect4(t4, t5);
|
|
4698
|
+
let t6;
|
|
4699
|
+
if ($[6] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4700
|
+
t6 = (conflict_0) => {
|
|
4701
|
+
dispatch({
|
|
4702
|
+
type: "ADD_CONFLICT",
|
|
4703
|
+
conflict: conflict_0
|
|
4704
|
+
});
|
|
4705
|
+
};
|
|
4706
|
+
$[6] = t6;
|
|
4707
|
+
} else {
|
|
4708
|
+
t6 = $[6];
|
|
4709
|
+
}
|
|
4710
|
+
const addConflict = t6;
|
|
4711
|
+
let t7;
|
|
4712
|
+
let t8;
|
|
4713
|
+
if ($[7] !== conflictBus) {
|
|
4714
|
+
t7 = () => {
|
|
4715
|
+
if (!conflictBus) {
|
|
4716
|
+
return;
|
|
4717
|
+
}
|
|
4718
|
+
const unsubscribeConflict = conflictBus.onConflict((conflict_1) => {
|
|
4719
|
+
dispatch({
|
|
4720
|
+
type: "ADD_CONFLICT",
|
|
4721
|
+
conflict: conflict_1
|
|
4722
|
+
});
|
|
4723
|
+
});
|
|
4724
|
+
return () => {
|
|
4725
|
+
unsubscribeConflict();
|
|
4726
|
+
};
|
|
4727
|
+
};
|
|
4728
|
+
t8 = [conflictBus];
|
|
4729
|
+
$[7] = conflictBus;
|
|
4730
|
+
$[8] = t7;
|
|
4731
|
+
$[9] = t8;
|
|
4732
|
+
} else {
|
|
4733
|
+
t7 = $[8];
|
|
4734
|
+
t8 = $[9];
|
|
4735
|
+
}
|
|
4736
|
+
useEffect4(t7, t8);
|
|
4737
|
+
let t9;
|
|
4738
|
+
if ($[10] !== conflictBus) {
|
|
4739
|
+
t9 = (table, recordId, resolution) => {
|
|
4740
|
+
dispatch({
|
|
4741
|
+
type: "RESOLVE_CONFLICT",
|
|
4742
|
+
table,
|
|
4743
|
+
recordId,
|
|
4744
|
+
resolution
|
|
4745
|
+
});
|
|
4746
|
+
conflictBus?.emitResolution(table, recordId, resolution);
|
|
4747
|
+
};
|
|
4748
|
+
$[10] = conflictBus;
|
|
4749
|
+
$[11] = t9;
|
|
4750
|
+
} else {
|
|
4751
|
+
t9 = $[11];
|
|
4752
|
+
}
|
|
4753
|
+
const resolveConflict = t9;
|
|
4754
|
+
let t10;
|
|
4755
|
+
if ($[12] !== conflictBus || $[13] !== state.pendingConflicts) {
|
|
4756
|
+
t10 = (resolution_0) => {
|
|
4757
|
+
const conflictsToResolve = [...state.pendingConflicts];
|
|
4758
|
+
dispatch({
|
|
4759
|
+
type: "RESOLVE_ALL",
|
|
4760
|
+
resolution: resolution_0
|
|
4761
|
+
});
|
|
4762
|
+
for (const conflict_2 of conflictsToResolve) {
|
|
4763
|
+
conflictBus?.emitResolution(conflict_2.table, conflict_2.recordId, resolution_0);
|
|
4764
|
+
}
|
|
4765
|
+
};
|
|
4766
|
+
$[12] = conflictBus;
|
|
4767
|
+
$[13] = state.pendingConflicts;
|
|
4768
|
+
$[14] = t10;
|
|
4769
|
+
} else {
|
|
4770
|
+
t10 = $[14];
|
|
4771
|
+
}
|
|
4772
|
+
const resolveAll = t10;
|
|
4773
|
+
let t11;
|
|
4774
|
+
if ($[15] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4775
|
+
t11 = (table_0, recordId_0) => {
|
|
4776
|
+
dispatch({
|
|
4777
|
+
type: "REMOVE_CONFLICT",
|
|
4778
|
+
table: table_0,
|
|
4779
|
+
recordId: recordId_0
|
|
4780
|
+
});
|
|
4781
|
+
};
|
|
4782
|
+
$[15] = t11;
|
|
4783
|
+
} else {
|
|
4784
|
+
t11 = $[15];
|
|
4785
|
+
}
|
|
4786
|
+
const removeConflict = t11;
|
|
4787
|
+
let t12;
|
|
4788
|
+
if ($[16] !== state.resolutions) {
|
|
4789
|
+
t12 = (table_1, recordId_1) => state.resolutions.get(conflictKey(table_1, recordId_1));
|
|
4790
|
+
$[16] = state.resolutions;
|
|
4791
|
+
$[17] = t12;
|
|
4792
|
+
} else {
|
|
4793
|
+
t12 = $[17];
|
|
4794
|
+
}
|
|
4795
|
+
const getResolution = t12;
|
|
4796
|
+
let t13;
|
|
4797
|
+
if ($[18] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4798
|
+
t13 = () => {
|
|
4799
|
+
dispatch({
|
|
4800
|
+
type: "CLEAR_RESOLVED"
|
|
4801
|
+
});
|
|
4802
|
+
};
|
|
4803
|
+
$[18] = t13;
|
|
4804
|
+
} else {
|
|
4805
|
+
t13 = $[18];
|
|
4806
|
+
}
|
|
4807
|
+
const clearResolved = t13;
|
|
4808
|
+
let t14;
|
|
4809
|
+
if ($[19] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel")) {
|
|
4810
|
+
t14 = () => {
|
|
4811
|
+
dispatch({
|
|
4812
|
+
type: "CLEAR_ALL"
|
|
4813
|
+
});
|
|
4814
|
+
clearPersistedConflicts();
|
|
4815
|
+
};
|
|
4816
|
+
$[19] = t14;
|
|
4817
|
+
} else {
|
|
4818
|
+
t14 = $[19];
|
|
4819
|
+
}
|
|
4820
|
+
const clearAll = t14;
|
|
4821
|
+
const t15 = state.pendingConflicts.length > 0;
|
|
4822
|
+
let t16;
|
|
4823
|
+
if ($[20] !== getResolution || $[21] !== resolveAll || $[22] !== resolveConflict || $[23] !== state.pendingConflicts || $[24] !== t15) {
|
|
4824
|
+
t16 = {
|
|
4825
|
+
pendingConflicts: state.pendingConflicts,
|
|
4826
|
+
addConflict,
|
|
4827
|
+
resolveConflict,
|
|
4828
|
+
resolveAll,
|
|
4829
|
+
removeConflict,
|
|
4830
|
+
getResolution,
|
|
4831
|
+
clearResolved,
|
|
4832
|
+
clearAll,
|
|
4833
|
+
hasConflicts: t15
|
|
4834
|
+
};
|
|
4835
|
+
$[20] = getResolution;
|
|
4836
|
+
$[21] = resolveAll;
|
|
4837
|
+
$[22] = resolveConflict;
|
|
4838
|
+
$[23] = state.pendingConflicts;
|
|
4839
|
+
$[24] = t15;
|
|
4840
|
+
$[25] = t16;
|
|
4841
|
+
} else {
|
|
4842
|
+
t16 = $[25];
|
|
4843
|
+
}
|
|
4844
|
+
const value = t16;
|
|
4845
|
+
let t17;
|
|
4846
|
+
if ($[26] !== children || $[27] !== value) {
|
|
4847
|
+
t17 = /* @__PURE__ */ jsx2(ConflictContext.Provider, { value, children });
|
|
4848
|
+
$[26] = children;
|
|
4849
|
+
$[27] = value;
|
|
4850
|
+
$[28] = t17;
|
|
4851
|
+
} else {
|
|
4852
|
+
t17 = $[28];
|
|
4853
|
+
}
|
|
4854
|
+
return t17;
|
|
4855
|
+
}
|
|
4856
|
+
function _temp22(c) {
|
|
4857
|
+
return `${c.table}:${c.recordId}`;
|
|
4858
|
+
}
|
|
4859
|
+
function _temp3(err) {
|
|
4860
|
+
console.warn("[ConflictProvider] Failed to load conflicts:", err);
|
|
4861
|
+
}
|
|
4862
|
+
|
|
4863
|
+
// src/conflicts/useConflictState.ts
|
|
4864
|
+
import { c as _c3 } from "react/compiler-runtime";
|
|
4865
|
+
import { useContext } from "react";
|
|
4866
|
+
function useConflictState() {
|
|
4867
|
+
const context = useContext(ConflictContext);
|
|
4868
|
+
if (!context) {
|
|
4869
|
+
throw new Error("useConflictState must be used within a ConflictProvider. Wrap your app with <ConflictProvider> to enable conflict management.");
|
|
4870
|
+
}
|
|
4871
|
+
return context;
|
|
4872
|
+
}
|
|
4873
|
+
function usePendingConflicts() {
|
|
4874
|
+
const $ = _c3(2);
|
|
4875
|
+
const context = useContext(ConflictContext);
|
|
4876
|
+
let t0;
|
|
4877
|
+
if ($[0] !== context?.pendingConflicts) {
|
|
4878
|
+
t0 = context?.pendingConflicts ?? [];
|
|
4879
|
+
$[0] = context?.pendingConflicts;
|
|
4880
|
+
$[1] = t0;
|
|
4881
|
+
} else {
|
|
4882
|
+
t0 = $[1];
|
|
4883
|
+
}
|
|
4884
|
+
return t0;
|
|
4885
|
+
}
|
|
4886
|
+
function useHasConflicts() {
|
|
4887
|
+
const context = useContext(ConflictContext);
|
|
4888
|
+
return context?.hasConflicts ?? false;
|
|
4889
|
+
}
|
|
4890
|
+
function useConflictForRecord(table, recordId) {
|
|
4891
|
+
const $ = _c3(4);
|
|
4892
|
+
const conflicts = usePendingConflicts();
|
|
4893
|
+
let t0;
|
|
4894
|
+
if ($[0] !== conflicts || $[1] !== recordId || $[2] !== table) {
|
|
4895
|
+
t0 = conflicts.find((c) => c.table === table && c.recordId === recordId) ?? null;
|
|
4896
|
+
$[0] = conflicts;
|
|
4897
|
+
$[1] = recordId;
|
|
4898
|
+
$[2] = table;
|
|
4899
|
+
$[3] = t0;
|
|
4900
|
+
} else {
|
|
4901
|
+
t0 = $[3];
|
|
4902
|
+
}
|
|
4903
|
+
return t0;
|
|
4904
|
+
}
|
|
4905
|
+
function useConflictsForTable(table) {
|
|
4906
|
+
const $ = _c3(5);
|
|
4907
|
+
const conflicts = usePendingConflicts();
|
|
4908
|
+
let t0;
|
|
4909
|
+
if ($[0] !== conflicts || $[1] !== table) {
|
|
4910
|
+
let t1;
|
|
4911
|
+
if ($[3] !== table) {
|
|
4912
|
+
t1 = (c) => c.table === table;
|
|
4913
|
+
$[3] = table;
|
|
4914
|
+
$[4] = t1;
|
|
4915
|
+
} else {
|
|
4916
|
+
t1 = $[4];
|
|
4917
|
+
}
|
|
4918
|
+
t0 = conflicts.filter(t1);
|
|
4919
|
+
$[0] = conflicts;
|
|
4920
|
+
$[1] = table;
|
|
4921
|
+
$[2] = t0;
|
|
4922
|
+
} else {
|
|
4923
|
+
t0 = $[2];
|
|
4924
|
+
}
|
|
4925
|
+
return t0;
|
|
4926
|
+
}
|
|
4927
|
+
function useConflictCountByTable() {
|
|
4928
|
+
const $ = _c3(2);
|
|
4929
|
+
const conflicts = usePendingConflicts();
|
|
4930
|
+
let counts;
|
|
4931
|
+
if ($[0] !== conflicts) {
|
|
4932
|
+
counts = /* @__PURE__ */ new Map();
|
|
4933
|
+
for (const conflict of conflicts) {
|
|
4934
|
+
counts.set(conflict.table, (counts.get(conflict.table) ?? 0) + 1);
|
|
4935
|
+
}
|
|
4936
|
+
$[0] = conflicts;
|
|
4937
|
+
$[1] = counts;
|
|
4938
|
+
} else {
|
|
4939
|
+
counts = $[1];
|
|
4940
|
+
}
|
|
4941
|
+
return counts;
|
|
4942
|
+
}
|
|
4943
|
+
|
|
4944
|
+
// src/conflicts/useConflictResolution.ts
|
|
4945
|
+
import { c as _c4 } from "react/compiler-runtime";
|
|
4946
|
+
function useConflictResolution(conflict) {
|
|
4947
|
+
const $ = _c4(28);
|
|
4948
|
+
const {
|
|
4949
|
+
resolveConflict
|
|
4950
|
+
} = useConflictState();
|
|
4951
|
+
let t0;
|
|
4952
|
+
if ($[0] !== conflict.recordId || $[1] !== conflict.table || $[2] !== resolveConflict) {
|
|
4953
|
+
t0 = (resolution) => {
|
|
4954
|
+
resolveConflict(conflict.table, conflict.recordId, resolution);
|
|
4955
|
+
};
|
|
4956
|
+
$[0] = conflict.recordId;
|
|
4957
|
+
$[1] = conflict.table;
|
|
4958
|
+
$[2] = resolveConflict;
|
|
4959
|
+
$[3] = t0;
|
|
4960
|
+
} else {
|
|
4961
|
+
t0 = $[3];
|
|
4962
|
+
}
|
|
4963
|
+
const resolve = t0;
|
|
4964
|
+
let t1;
|
|
4965
|
+
if ($[4] !== resolve) {
|
|
4966
|
+
t1 = () => {
|
|
4967
|
+
resolve({
|
|
4968
|
+
action: "keep-server"
|
|
4969
|
+
});
|
|
4970
|
+
};
|
|
4971
|
+
$[4] = resolve;
|
|
4972
|
+
$[5] = t1;
|
|
4973
|
+
} else {
|
|
4974
|
+
t1 = $[5];
|
|
4975
|
+
}
|
|
4976
|
+
const keepServer = t1;
|
|
4977
|
+
let t2;
|
|
4978
|
+
if ($[6] !== resolve) {
|
|
4979
|
+
t2 = () => {
|
|
4980
|
+
resolve({
|
|
4981
|
+
action: "overwrite"
|
|
4982
|
+
});
|
|
4983
|
+
};
|
|
4984
|
+
$[6] = resolve;
|
|
4985
|
+
$[7] = t2;
|
|
4986
|
+
} else {
|
|
4987
|
+
t2 = $[7];
|
|
4988
|
+
}
|
|
4989
|
+
const overwrite = t2;
|
|
4990
|
+
let t3;
|
|
4991
|
+
if ($[8] !== conflict.nonConflictingChanges || $[9] !== resolve) {
|
|
4992
|
+
t3 = () => {
|
|
4993
|
+
resolve({
|
|
4994
|
+
action: "partial",
|
|
4995
|
+
fields: conflict.nonConflictingChanges
|
|
4996
|
+
});
|
|
4997
|
+
};
|
|
4998
|
+
$[8] = conflict.nonConflictingChanges;
|
|
4999
|
+
$[9] = resolve;
|
|
5000
|
+
$[10] = t3;
|
|
5001
|
+
} else {
|
|
5002
|
+
t3 = $[10];
|
|
5003
|
+
}
|
|
5004
|
+
const syncNonConflicting = t3;
|
|
5005
|
+
let t4;
|
|
5006
|
+
if ($[11] !== resolve) {
|
|
5007
|
+
t4 = (fields) => {
|
|
5008
|
+
resolve({
|
|
5009
|
+
action: "partial",
|
|
5010
|
+
fields
|
|
5011
|
+
});
|
|
5012
|
+
};
|
|
5013
|
+
$[11] = resolve;
|
|
5014
|
+
$[12] = t4;
|
|
5015
|
+
} else {
|
|
5016
|
+
t4 = $[12];
|
|
5017
|
+
}
|
|
5018
|
+
const syncFields = t4;
|
|
5019
|
+
let t5;
|
|
5020
|
+
if ($[13] !== conflict.conflicts) {
|
|
5021
|
+
t5 = new Set(conflict.conflicts.map(_temp4));
|
|
5022
|
+
$[13] = conflict.conflicts;
|
|
5023
|
+
$[14] = t5;
|
|
5024
|
+
} else {
|
|
5025
|
+
t5 = $[14];
|
|
5026
|
+
}
|
|
5027
|
+
const conflictFieldSet = t5;
|
|
5028
|
+
let t6;
|
|
5029
|
+
if ($[15] !== conflictFieldSet) {
|
|
5030
|
+
t6 = (field) => conflictFieldSet.has(field);
|
|
5031
|
+
$[15] = conflictFieldSet;
|
|
5032
|
+
$[16] = t6;
|
|
5033
|
+
} else {
|
|
5034
|
+
t6 = $[16];
|
|
5035
|
+
}
|
|
5036
|
+
const hasFieldConflict = t6;
|
|
5037
|
+
let t7;
|
|
5038
|
+
if ($[17] !== conflict.conflicts) {
|
|
5039
|
+
t7 = (field_0) => {
|
|
5040
|
+
const fc = conflict.conflicts.find((c_0) => c_0.field === field_0);
|
|
5041
|
+
if (!fc) {
|
|
5042
|
+
return null;
|
|
5043
|
+
}
|
|
5044
|
+
return {
|
|
5045
|
+
localValue: fc.localValue,
|
|
5046
|
+
serverValue: fc.serverValue,
|
|
5047
|
+
changedBy: fc.changedBy,
|
|
5048
|
+
changedAt: fc.changedAt
|
|
5049
|
+
};
|
|
5050
|
+
};
|
|
5051
|
+
$[17] = conflict.conflicts;
|
|
5052
|
+
$[18] = t7;
|
|
5053
|
+
} else {
|
|
5054
|
+
t7 = $[18];
|
|
5055
|
+
}
|
|
5056
|
+
const getFieldConflict = t7;
|
|
5057
|
+
let t8;
|
|
5058
|
+
if ($[19] !== conflict || $[20] !== getFieldConflict || $[21] !== hasFieldConflict || $[22] !== keepServer || $[23] !== overwrite || $[24] !== resolve || $[25] !== syncFields || $[26] !== syncNonConflicting) {
|
|
5059
|
+
t8 = {
|
|
5060
|
+
conflict,
|
|
5061
|
+
resolve,
|
|
5062
|
+
keepServer,
|
|
5063
|
+
overwrite,
|
|
5064
|
+
syncNonConflicting,
|
|
5065
|
+
syncFields,
|
|
5066
|
+
hasFieldConflict,
|
|
5067
|
+
getFieldConflict
|
|
5068
|
+
};
|
|
5069
|
+
$[19] = conflict;
|
|
5070
|
+
$[20] = getFieldConflict;
|
|
5071
|
+
$[21] = hasFieldConflict;
|
|
5072
|
+
$[22] = keepServer;
|
|
5073
|
+
$[23] = overwrite;
|
|
5074
|
+
$[24] = resolve;
|
|
5075
|
+
$[25] = syncFields;
|
|
5076
|
+
$[26] = syncNonConflicting;
|
|
5077
|
+
$[27] = t8;
|
|
5078
|
+
} else {
|
|
5079
|
+
t8 = $[27];
|
|
5080
|
+
}
|
|
5081
|
+
return t8;
|
|
5082
|
+
}
|
|
5083
|
+
function _temp4(c) {
|
|
5084
|
+
return c.field;
|
|
5085
|
+
}
|
|
5086
|
+
function useBulkConflictResolution() {
|
|
5087
|
+
const $ = _c4(13);
|
|
5088
|
+
const {
|
|
5089
|
+
resolveAll,
|
|
5090
|
+
resolveConflict,
|
|
5091
|
+
pendingConflicts,
|
|
5092
|
+
clearResolved
|
|
5093
|
+
} = useConflictState();
|
|
5094
|
+
let t0;
|
|
5095
|
+
if ($[0] !== resolveAll) {
|
|
5096
|
+
t0 = () => {
|
|
5097
|
+
resolveAll({
|
|
5098
|
+
action: "keep-server"
|
|
5099
|
+
});
|
|
5100
|
+
};
|
|
5101
|
+
$[0] = resolveAll;
|
|
5102
|
+
$[1] = t0;
|
|
5103
|
+
} else {
|
|
5104
|
+
t0 = $[1];
|
|
5105
|
+
}
|
|
5106
|
+
const resolveAllKeepServer = t0;
|
|
5107
|
+
let t1;
|
|
5108
|
+
if ($[2] !== resolveAll) {
|
|
5109
|
+
t1 = () => {
|
|
5110
|
+
resolveAll({
|
|
5111
|
+
action: "overwrite"
|
|
5112
|
+
});
|
|
5113
|
+
};
|
|
5114
|
+
$[2] = resolveAll;
|
|
5115
|
+
$[3] = t1;
|
|
5116
|
+
} else {
|
|
5117
|
+
t1 = $[3];
|
|
5118
|
+
}
|
|
5119
|
+
const resolveAllOverwrite = t1;
|
|
5120
|
+
let t2;
|
|
5121
|
+
if ($[4] !== pendingConflicts || $[5] !== resolveConflict) {
|
|
5122
|
+
t2 = () => {
|
|
5123
|
+
for (const conflict of pendingConflicts) {
|
|
5124
|
+
resolveConflict(conflict.table, conflict.recordId, {
|
|
5125
|
+
action: "partial",
|
|
5126
|
+
fields: conflict.nonConflictingChanges
|
|
5127
|
+
});
|
|
5128
|
+
}
|
|
5129
|
+
};
|
|
5130
|
+
$[4] = pendingConflicts;
|
|
5131
|
+
$[5] = resolveConflict;
|
|
5132
|
+
$[6] = t2;
|
|
5133
|
+
} else {
|
|
5134
|
+
t2 = $[6];
|
|
5135
|
+
}
|
|
5136
|
+
const resolveAllSyncNonConflicting = t2;
|
|
5137
|
+
let t3;
|
|
5138
|
+
if ($[7] !== clearResolved || $[8] !== pendingConflicts.length || $[9] !== resolveAllKeepServer || $[10] !== resolveAllOverwrite || $[11] !== resolveAllSyncNonConflicting) {
|
|
5139
|
+
t3 = {
|
|
5140
|
+
resolveAllKeepServer,
|
|
5141
|
+
resolveAllOverwrite,
|
|
5142
|
+
resolveAllSyncNonConflicting,
|
|
5143
|
+
clearResolved,
|
|
5144
|
+
conflictCount: pendingConflicts.length
|
|
5145
|
+
};
|
|
5146
|
+
$[7] = clearResolved;
|
|
5147
|
+
$[8] = pendingConflicts.length;
|
|
5148
|
+
$[9] = resolveAllKeepServer;
|
|
5149
|
+
$[10] = resolveAllOverwrite;
|
|
5150
|
+
$[11] = resolveAllSyncNonConflicting;
|
|
5151
|
+
$[12] = t3;
|
|
5152
|
+
} else {
|
|
5153
|
+
t3 = $[12];
|
|
5154
|
+
}
|
|
5155
|
+
return t3;
|
|
5156
|
+
}
|
|
5157
|
+
|
|
4157
5158
|
export {
|
|
4158
5159
|
sanitizeStorageKey,
|
|
4159
5160
|
useDbAttachmentUpload,
|
|
4160
5161
|
PowerSyncAdapter,
|
|
4161
5162
|
createPowerSyncAdapter,
|
|
4162
5163
|
DataLayerProvider,
|
|
4163
|
-
useSupabaseUpload
|
|
5164
|
+
useSupabaseUpload,
|
|
5165
|
+
ConflictContext,
|
|
5166
|
+
ConflictProvider,
|
|
5167
|
+
useConflictState,
|
|
5168
|
+
usePendingConflicts,
|
|
5169
|
+
useHasConflicts,
|
|
5170
|
+
useConflictForRecord,
|
|
5171
|
+
useConflictsForTable,
|
|
5172
|
+
useConflictCountByTable,
|
|
5173
|
+
useConflictResolution,
|
|
5174
|
+
useBulkConflictResolution
|
|
4164
5175
|
};
|
|
4165
5176
|
/*! Bundled license information:
|
|
4166
5177
|
|
|
@@ -4191,4 +5202,4 @@ object-assign/index.js:
|
|
|
4191
5202
|
@license MIT
|
|
4192
5203
|
*)
|
|
4193
5204
|
*/
|
|
4194
|
-
//# sourceMappingURL=chunk-
|
|
5205
|
+
//# sourceMappingURL=chunk-XU3SBFAG.js.map
|