@fkn/lib 0.9.40 → 0.9.41
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/account-generation-CSnZiN18.cjs +1 -0
- package/account-generation-D7TpIoKt.js +28 -0
- package/account.cjs +1 -1
- package/account.d.ts +11 -0
- package/account.js +5 -17
- package/{api-BE5zPvFZ.d.ts → api-Cbty0JUM.d.ts} +15 -13
- package/api.d.ts +2 -2
- package/cloud/dns.d.ts +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fs/promises.d.ts +1 -1
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.d.ts +4 -4
- package/cloud/fs.js +31 -24
- package/cloud/net.d.ts +1 -1
- package/{cloud-5eldoFxK.d.ts → cloud-4t1WoEZn.d.ts} +3 -3
- package/cloud.d.ts +4 -4
- package/{contract-Cvr_8gCL.d.ts → contract-BRc2ptdC.d.ts} +29 -7
- package/contract.d.ts +2 -2
- package/dgram.d.ts +2 -2
- package/dns.d.ts +1 -1
- package/fs/promises.cjs +1 -1
- package/fs/promises.d.ts +1 -1
- package/fs/promises.js +1 -1
- package/fs-BTyRnUPI.cjs +1 -0
- package/{fs--NhtUyYa.d.ts → fs-D0MMRnHC.d.ts} +8 -4
- package/fs-q7Kg51hq.js +513 -0
- package/fs.cjs +1 -1
- package/fs.d.ts +4 -3
- package/fs.js +4 -2
- package/http.d.ts +1 -1
- package/{index-kuPqkS_-.d.ts → index-D2lvaQDs.d.ts} +28 -38
- package/index.cjs +1 -1
- package/index.d.ts +3 -3
- package/index.js +1 -1
- package/{messages-C66ghz_A.d.ts → messages-CRcziTuC.d.ts} +17 -1
- package/messages.cjs +1 -1
- package/messages.d.ts +2 -2
- package/messages.js +2 -2
- package/{net-zThwNoA8.d.ts → net-CcEZP6Bb.d.ts} +2 -2
- package/net.d.ts +1 -1
- package/{node-fs-BZy9bzKd.js → node-fs-CK2wWIYS.js} +140 -137
- package/node-fs-nfX7wisL.cjs +1 -0
- package/opfs.cjs +1 -1
- package/opfs.js +1 -1
- package/package.json +1 -1
- package/packages.d.ts +1 -1
- package/{proxy-Dc0gDOxz.d.ts → proxy-D6YtsO1g.d.ts} +2 -2
- package/rooms.d.ts +1 -1
- package/storage-BS5WMO4f.cjs +1 -0
- package/storage-BVr2Rb-d.d.ts +167 -0
- package/storage-BWmGrO6a.js +123 -0
- package/fs-CaQFRiIT.cjs +0 -1
- package/fs-D3IsGdnN.js +0 -360
- package/node-fs-BNTPsX5c.cjs +0 -1
- package/storage-BJd-mWHE.cjs +0 -1
- package/storage-DSvL-t80.js +0 -67
- package/storage-ZrY4Y4L5.d.ts +0 -88
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
//#region src/fs/types.d.ts
|
|
2
|
+
type FileEntry$1 = {
|
|
3
|
+
path: string;
|
|
4
|
+
size: number;
|
|
5
|
+
contentType: string | null;
|
|
6
|
+
updatedAt: string | null;
|
|
7
|
+
};
|
|
8
|
+
type WriteData$1 = Blob | ArrayBuffer | Uint8Array | string;
|
|
9
|
+
/**
|
|
10
|
+
* Which account a cloud call belongs to. Library plumbing that app code never passes: an operation of
|
|
11
|
+
* several calls (a rename, a mount, a queue drain) captures one when it starts, so none of its calls
|
|
12
|
+
* can land in an account the realm switched to meanwhile.
|
|
13
|
+
*
|
|
14
|
+
* `{ generation }` is a ticket from `captureAccount()`: its calls carry that generation's pin. `{ pin }`
|
|
15
|
+
* is a pin a queued entry was stamped with, sent as is.
|
|
16
|
+
*/
|
|
17
|
+
type PinFrom = {
|
|
18
|
+
readonly generation: number;
|
|
19
|
+
} | {
|
|
20
|
+
readonly pin: string;
|
|
21
|
+
};
|
|
22
|
+
type PinOptions = {
|
|
23
|
+
pin?: PinFrom;
|
|
24
|
+
};
|
|
25
|
+
type FileSystem = {
|
|
26
|
+
available: () => Promise<boolean>;
|
|
27
|
+
list: (opts?: PinOptions) => Promise<FileEntry$1[]>;
|
|
28
|
+
readFile: (path: string, opts?: PinOptions) => Promise<Blob>;
|
|
29
|
+
writeFile: (path: string, data: WriteData$1, opts?: {
|
|
30
|
+
contentType?: string;
|
|
31
|
+
} & PinOptions) => Promise<void>;
|
|
32
|
+
remove: (path: string, opts?: PinOptions) => Promise<void>;
|
|
33
|
+
/** Captures the account generation this realm is on now; absent on a backing with no account. */
|
|
34
|
+
captureAccount?: () => PinFrom;
|
|
35
|
+
};
|
|
36
|
+
declare namespace storage_d_exports {
|
|
37
|
+
export { AccountTicket, CloudAvailability, EncryptionStatus, FileEntry, SealedRead, StorageAccountChangedError, StorageAccountPinUnsupportedError, StorageLockedError, StorageNotFoundError, StorageQuota, WriteData, availability, available, captureAccount, encryption, isAccountChanged, isInvalidPin, isNotFound, knownPin, list, pinFor, quota, readFile, readFileSealed, remove, unlock, writeFile };
|
|
38
|
+
}
|
|
39
|
+
type FileEntry = {
|
|
40
|
+
path: string;
|
|
41
|
+
size: number;
|
|
42
|
+
contentType: string | null;
|
|
43
|
+
updatedAt: string;
|
|
44
|
+
encryption: string | null;
|
|
45
|
+
};
|
|
46
|
+
type StorageQuota = {
|
|
47
|
+
usedBytes: number;
|
|
48
|
+
limitBytes: number;
|
|
49
|
+
remaining: number;
|
|
50
|
+
objects: number;
|
|
51
|
+
maxObjects: number;
|
|
52
|
+
};
|
|
53
|
+
type EncryptionStatus = {
|
|
54
|
+
unlocked: boolean;
|
|
55
|
+
enrolled: boolean;
|
|
56
|
+
keyEpoch: number | null;
|
|
57
|
+
};
|
|
58
|
+
type WriteData = Blob | ArrayBuffer | Uint8Array | string;
|
|
59
|
+
declare class StorageLockedError extends Error {
|
|
60
|
+
code: string;
|
|
61
|
+
constructor();
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* There is no object at this path. Test `err.code === STORAGE_NOT_FOUND`, never the message.
|
|
65
|
+
*
|
|
66
|
+
* Absence arrives from two places that word it completely differently: the api refusing to presign
|
|
67
|
+
* a path with no committed row says "Not found", and a presign that succeeded followed by an object
|
|
68
|
+
* fetch that 404s says "storage: read failed (404)". Neither is a fault, both mean the same thing,
|
|
69
|
+
* and matching either by hand means matching both. Ripple matched only the first, so a missing
|
|
70
|
+
* backup read as a transient failure, retried forever, and a library went un-backed-up for a day
|
|
71
|
+
* without a single error anywhere.
|
|
72
|
+
*
|
|
73
|
+
* The distinction matters more than it sounds. "There is nothing here" is safe to overwrite;
|
|
74
|
+
* "I could not tell you" is not, and a caller that confuses them either never writes a first
|
|
75
|
+
* backup or destroys a real one.
|
|
76
|
+
*/
|
|
77
|
+
declare class StorageNotFoundError extends Error {
|
|
78
|
+
code: string;
|
|
79
|
+
constructor(message?: string);
|
|
80
|
+
}
|
|
81
|
+
/** Whether an error from this module means the path is empty, as opposed to unreadable. */
|
|
82
|
+
declare const isNotFound: (error: unknown) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* The signed-in account is not the one this call belongs to, so the call was refused and nothing was
|
|
85
|
+
* read, written or removed. Test `err.code === STORAGE_ACCOUNT_CHANGED`, or `isAccountChanged(err)`.
|
|
86
|
+
*
|
|
87
|
+
* Every storage call (list, read, write, remove) carries a pin of the account this page was on when
|
|
88
|
+
* the call was made, captured synchronously in the call itself. So a call made before this page
|
|
89
|
+
* learned of an account switch never lands in the new account: FKN refuses it, or the library refuses
|
|
90
|
+
* it before sending. The library never retries it under the new account by itself.
|
|
91
|
+
*
|
|
92
|
+
* What stays the app's to check is work it started before the notification and resumes after it (an
|
|
93
|
+
* await between reading state and writing it back). Keep a counter that an `account.onChange` handler
|
|
94
|
+
* bumps and compare it synchronously right before the storage call: the pin is captured in that same
|
|
95
|
+
* synchronous step, so the check and the call are atomic.
|
|
96
|
+
*
|
|
97
|
+
* The notification also fires when the connection is renewed without a switch, so this can be thrown
|
|
98
|
+
* for a call that would have landed in the same account. Either way the answer is the same: re-read
|
|
99
|
+
* what the app is acting on, then call again.
|
|
100
|
+
*/
|
|
101
|
+
declare class StorageAccountChangedError extends Error {
|
|
102
|
+
code: string;
|
|
103
|
+
constructor(message?: string);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The FKN broker this page reached is older than the account pin, so no storage call was sent: an
|
|
107
|
+
* unpinned call could land in an account the app did not mean. It goes away once fkn.app updates.
|
|
108
|
+
*/
|
|
109
|
+
declare class StorageAccountPinUnsupportedError extends Error {
|
|
110
|
+
code: string;
|
|
111
|
+
constructor(message?: string);
|
|
112
|
+
}
|
|
113
|
+
/** Whether an error from this module means the account changed under the call, which was not made. */
|
|
114
|
+
declare const isAccountChanged: (error: unknown) => boolean;
|
|
115
|
+
/** Whether the api could not read a pin at all (a queued entry's record damaged on the device). */
|
|
116
|
+
declare const isInvalidPin: (error: unknown) => boolean;
|
|
117
|
+
/** One account generation of this realm, captured when an operation started. */
|
|
118
|
+
type AccountTicket = {
|
|
119
|
+
readonly generation: number;
|
|
120
|
+
};
|
|
121
|
+
/** The account generation this realm is on now. Synchronous, so it is captured before any await. */
|
|
122
|
+
declare const captureAccount: () => AccountTicket;
|
|
123
|
+
/** The pin a ticket's generation carries, if it was already taken. */
|
|
124
|
+
declare const knownPin: (ticket: AccountTicket) => string | undefined;
|
|
125
|
+
/** The pin a ticket's generation carries, taking it if need be; refused once the generation has moved. */
|
|
126
|
+
declare const pinFor: (ticket: AccountTicket) => Promise<string>;
|
|
127
|
+
declare const available: () => Promise<boolean>;
|
|
128
|
+
type CloudAvailability = 'connected' | 'disconnected' | 'unknown';
|
|
129
|
+
/**
|
|
130
|
+
* Whether the cloud half is backed by an account, as three answers rather than two:
|
|
131
|
+
* 'disconnected' is an ANSWER (signed out, or the api refusing the stored token), 'unknown'
|
|
132
|
+
* means nobody could be asked, including a broker that never came up. Always settles within
|
|
133
|
+
* the probe deadline. A caller owing data to the cloud may drop that obligation only on
|
|
134
|
+
* 'disconnected'; treating 'unknown' the same silently loses the write.
|
|
135
|
+
*/
|
|
136
|
+
declare const availability: () => Promise<CloudAvailability>;
|
|
137
|
+
declare const list: (opts?: PinOptions) => Promise<FileEntry[]>;
|
|
138
|
+
declare const quota: () => Promise<StorageQuota>;
|
|
139
|
+
declare const readFile: (path: string, opts?: PinOptions) => Promise<Blob>;
|
|
140
|
+
/** The bytes of a cloud object and the seal time they carry, as an ISO string or null. */
|
|
141
|
+
type SealedRead = {
|
|
142
|
+
data: Uint8Array;
|
|
143
|
+
sealedAt: string | null;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* A cloud read that also reports when the copy was sealed.
|
|
147
|
+
*
|
|
148
|
+
* `sealedAt` is an ISO string, or null when the envelope carries no such field (one written before
|
|
149
|
+
* the seal time existed) or when the data plane is older than this call. The value is
|
|
150
|
+
* AUTHENTICATED, so the server can neither forge nor alter it, and it is the WRITER's own claim
|
|
151
|
+
* about when it sealed, so on its own it does not prove this copy is the newest one: an older but
|
|
152
|
+
* perfectly authentic copy of the same path is still authentic. An app that needs that answer keeps
|
|
153
|
+
* a high-water mark per path and compares. Do not confuse it with the `updatedAt` on a listing,
|
|
154
|
+
* which is the server's hint and is fine for display and nothing else.
|
|
155
|
+
*
|
|
156
|
+
* The bytes and the stamp come from ONE read of ONE envelope, which is what makes the stamp
|
|
157
|
+
* describe the bytes returned beside it. `readFile` is unchanged and unaffected.
|
|
158
|
+
*/
|
|
159
|
+
declare const readFileSealed: (path: string, opts?: PinOptions) => Promise<SealedRead>;
|
|
160
|
+
declare const writeFile: (path: string, data: WriteData, opts?: {
|
|
161
|
+
contentType?: string;
|
|
162
|
+
} & PinOptions) => Promise<void>;
|
|
163
|
+
declare const remove: (path: string, opts?: PinOptions) => Promise<void>;
|
|
164
|
+
declare const encryption: () => Promise<EncryptionStatus>;
|
|
165
|
+
declare const unlock: () => Promise<boolean>;
|
|
166
|
+
//#endregion
|
|
167
|
+
export { unlock as _, StorageAccountChangedError as a, PinOptions as b, StorageNotFoundError as c, captureAccount as d, encryption as f, storage_d_exports as g, quota as h, SealedRead as i, StorageQuota as l, isNotFound as m, EncryptionStatus as n, StorageAccountPinUnsupportedError as o, isAccountChanged as p, FileEntry as r, StorageLockedError as s, CloudAvailability as t, availability as u, FileEntry$1 as v, WriteData$1 as x, FileSystem as y };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
+
import { a as t } from "./api-Dp-2AT3u.js";
|
|
3
|
+
import { STORAGE_ACCOUNT_CHANGED as n, STORAGE_ACCOUNT_PIN_UNSUPPORTED as r, STORAGE_NOT_FOUND as i } from "./messages.js";
|
|
4
|
+
import { n as a, r as o, t as s } from "./account-generation-D7TpIoKt.js";
|
|
5
|
+
//#region src/storage.ts
|
|
6
|
+
var c = /* @__PURE__ */ e({
|
|
7
|
+
StorageAccountChangedError: () => f,
|
|
8
|
+
StorageAccountPinUnsupportedError: () => p,
|
|
9
|
+
StorageLockedError: () => l,
|
|
10
|
+
StorageNotFoundError: () => u,
|
|
11
|
+
availability: () => N,
|
|
12
|
+
available: () => O,
|
|
13
|
+
captureAccount: () => _,
|
|
14
|
+
encryption: () => V,
|
|
15
|
+
isAccountChanged: () => m,
|
|
16
|
+
isInvalidPin: () => h,
|
|
17
|
+
isNotFound: () => d,
|
|
18
|
+
knownPin: () => C,
|
|
19
|
+
list: () => P,
|
|
20
|
+
pinFor: () => w,
|
|
21
|
+
quota: () => F,
|
|
22
|
+
readFile: () => I,
|
|
23
|
+
readFileSealed: () => R,
|
|
24
|
+
remove: () => B,
|
|
25
|
+
unlock: () => H,
|
|
26
|
+
writeFile: () => z
|
|
27
|
+
}), l = class extends Error {
|
|
28
|
+
code = "FKN_E2E_LOCKED";
|
|
29
|
+
constructor() {
|
|
30
|
+
super("storage locked: connect the app again to open encrypted data");
|
|
31
|
+
}
|
|
32
|
+
}, u = class extends Error {
|
|
33
|
+
code = i;
|
|
34
|
+
constructor(e = "storage: no object at that path") {
|
|
35
|
+
super(e);
|
|
36
|
+
}
|
|
37
|
+
}, d = (e) => e?.code === i, f = class extends Error {
|
|
38
|
+
code = n;
|
|
39
|
+
constructor(e = "storage: the signed-in account changed, so this call was not made") {
|
|
40
|
+
super(e);
|
|
41
|
+
}
|
|
42
|
+
}, p = class extends Error {
|
|
43
|
+
code = r;
|
|
44
|
+
constructor(e = "storage: the FKN broker cannot pin calls to an account yet, so nothing was sent") {
|
|
45
|
+
super(e);
|
|
46
|
+
}
|
|
47
|
+
}, m = (e) => e?.code === "FKN_ACCOUNT_CHANGED" || e instanceof Error && e.message.startsWith("fkn:account-changed"), h = (e) => e instanceof Error && e.message.startsWith("fkn:account-pin-invalid"), g = (e) => {
|
|
48
|
+
throw e instanceof Error && e.message.startsWith("fkn:e2e-locked") ? new l() : d(e) ? new u(e.message) : m(e) ? new f() : e instanceof Error && e.message.startsWith("fkn:account-pin-unsupported") ? new p() : e instanceof Error && (/^not found$/i.test(e.message) || /\(404\)$/.test(e.message)) ? new u(e.message) : e;
|
|
49
|
+
}, _ = () => (a(), { generation: s() }), v = /* @__PURE__ */ new Map(), y = null, b = (e) => typeof e?.accountPin == "function", x = (e, t) => {
|
|
50
|
+
let n = Promise.resolve(t.accountPin()).then((t) => {
|
|
51
|
+
if (typeof t != "string" || !t) throw Error("storage: the broker answered no account pin");
|
|
52
|
+
return s() === e && v.set(e, t), t;
|
|
53
|
+
});
|
|
54
|
+
return y = {
|
|
55
|
+
generation: e,
|
|
56
|
+
pin: n
|
|
57
|
+
}, n.catch(() => {
|
|
58
|
+
y?.pin === n && (y = null);
|
|
59
|
+
}), n;
|
|
60
|
+
}, S = async (e, t) => {
|
|
61
|
+
let n = v.get(e.generation);
|
|
62
|
+
if (n !== void 0) return n;
|
|
63
|
+
if (e.generation !== s()) throw new f();
|
|
64
|
+
let r = await (y?.generation === e.generation ? y.pin : x(e.generation, t)).catch(g);
|
|
65
|
+
if (e.generation !== s()) throw new f();
|
|
66
|
+
return r;
|
|
67
|
+
}, C = (e) => v.get(e.generation), w = async (e) => {
|
|
68
|
+
let n = (await t).cloud.fs;
|
|
69
|
+
if (!b(n)) throw new p();
|
|
70
|
+
return S(e, n);
|
|
71
|
+
}, T = (e) => {
|
|
72
|
+
for (let [t, n] of v) if (n === e) return t;
|
|
73
|
+
}, E = (e) => e?.pin ?? _(), D = async (e, n) => {
|
|
74
|
+
let r = (await t).cloud.fs;
|
|
75
|
+
if (!b(r)) throw new p();
|
|
76
|
+
let i = "pin" in e ? e.pin : await S(e, r);
|
|
77
|
+
if (!b(r)) throw new p();
|
|
78
|
+
return n(r, { accountPin: i }).catch((t) => {
|
|
79
|
+
if (m(t)) {
|
|
80
|
+
let t = "generation" in e ? e.generation : T(i);
|
|
81
|
+
t !== void 0 && o(t);
|
|
82
|
+
}
|
|
83
|
+
return g(t);
|
|
84
|
+
});
|
|
85
|
+
}, O = () => t.then((e) => e.cloud.fs.available()).catch(() => !1), k = 8e3, A = 1e3, j = !1, M = async () => {
|
|
86
|
+
let e = (await t).cloud.fs;
|
|
87
|
+
return typeof e.availability == "function" ? e.availability() : await e.available() ? "connected" : "disconnected";
|
|
88
|
+
}, N = async () => {
|
|
89
|
+
let e = j ? A : k, t = await new Promise((t) => {
|
|
90
|
+
let n = setTimeout(() => t("timeout"), e);
|
|
91
|
+
M().then((e) => {
|
|
92
|
+
clearTimeout(n), t(e);
|
|
93
|
+
}, () => {
|
|
94
|
+
clearTimeout(n), t("unknown");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return t === "timeout" ? (j = !0, "unknown") : (j = !1, t);
|
|
98
|
+
}, P = (e) => D(E(e), (e, t) => e.list(t)), F = () => t.then((e) => e.cloud.fs.quota()), I = async (e, t) => {
|
|
99
|
+
let n = await D(E(t), (t, n) => t.readFile(e, n));
|
|
100
|
+
return new Blob([n]);
|
|
101
|
+
}, L = (e) => {
|
|
102
|
+
if (e === null || !Number.isFinite(e)) return null;
|
|
103
|
+
let t = new Date(e);
|
|
104
|
+
return Number.isNaN(t.getTime()) ? null : t.toISOString();
|
|
105
|
+
}, R = async (e, t) => D(E(t), async (t, n) => {
|
|
106
|
+
let r = t;
|
|
107
|
+
if (typeof r.readFileSealed != "function") return {
|
|
108
|
+
data: await t.readFile(e, n),
|
|
109
|
+
sealedAt: null
|
|
110
|
+
};
|
|
111
|
+
let i = await r.readFileSealed(e, n);
|
|
112
|
+
return {
|
|
113
|
+
data: i.bytes,
|
|
114
|
+
sealedAt: L(i.sealedAt)
|
|
115
|
+
};
|
|
116
|
+
}), z = async (e, t, n) => {
|
|
117
|
+
let r = E(n), i = t instanceof Blob ? new Uint8Array(await t.arrayBuffer()) : t;
|
|
118
|
+
await D(r, (t, r) => t.writeFile(e, i, n?.contentType ?? null, r));
|
|
119
|
+
}, B = async (e, t) => {
|
|
120
|
+
await D(E(t), (t, n) => t.remove(e, n));
|
|
121
|
+
}, V = () => t.then((e) => e.cloud.fs.encryption()), H = () => t.then((e) => e.cloud.fs.unlock());
|
|
122
|
+
//#endregion
|
|
123
|
+
export { B as _, N as a, z as b, m as c, C as d, P as f, R as g, I as h, u as i, h as l, F as m, p as n, _ as o, w as p, l as r, V as s, f as t, d as u, c as v, H as y };
|
package/fs-CaQFRiIT.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./busy-Dv8wzE5M.cjs"),n=require("./node-fs-BNTPsX5c.cjs"),r=require("./storage-BJd-mWHE.cjs"),i=require("./opfs-CXMESVLc.cjs");var a=e.t({adopt:()=>I,adoptable:()=>L,available:()=>u,list:()=>re,onConflict:()=>le,pending:()=>C,pendingDeletes:()=>w,pull:()=>ce,readFile:()=>ie,readFileSealed:()=>ae,remove:()=>se,replicating:()=>T,writeFile:()=>oe}),o,s=async()=>await(o??=i.t().catch(()=>!1))?!0:(o=void 0,!1),c=()=>r.r().catch(()=>`unknown`),l=async()=>await c()===`connected`,u=async()=>await s()||await l(),d=`fkn:fs:pending`,f=`fkn:fs:pending-delete`,p=`fkn:fs:adopt-declined`,m=!0,h=new Map,g=e=>{try{let t=localStorage.getItem(e);if(!t)return{};let n=JSON.parse(t);return Array.isArray(n)?Object.fromEntries(n.filter(e=>typeof e==`string`).map(e=>[e,null])):n&&typeof n==`object`?n:{}}catch{return{}}},_=(e,t)=>{try{Object.keys(t).length?localStorage.setItem(e,JSON.stringify(t)):localStorage.removeItem(e)}catch{}},v=()=>g(d),y=(e,t)=>{let n=v();e in n||(n[e]=t===void 0?h.get(e)??null:t,_(d,n))},b=e=>{let t=v();e in t&&(delete t[e],_(d,t),D()||(k=O))},x=()=>g(f),ee=e=>{let t=x();e in t||(t[e]=h.get(e)??null,_(f,t))},S=e=>{let t=x();e in t&&(delete t[e],_(f,t),D()||(k=O))},C=()=>Object.keys(v()),w=()=>Object.keys(x()),T=()=>m,E=null;t.r(`storage replication`,()=>E!==null||R!==null);var D=()=>Object.keys(v()).length>0||Object.keys(x()).length>0,O=6e4,te=6e5,k=O,A=null,j=()=>{!A&&typeof window<`u`&&D()&&(A=setTimeout(()=>{A=null,M()},k),k=Math.min(k*2,te))},M=()=>{!E&&D()&&(E=F(!1).then(e=>{if(!D()){k=O;return}e.failed.length&&j()}).catch(()=>{j()}).finally(()=>{E=null}))},ne=null,N=()=>ne??=Promise.resolve().then(()=>require("./api.cjs")).then(e=>e.apiPromise),re=async()=>{U();let e=await c(),t=e===`connected`,[n,a]=await Promise.all([s().then(e=>e?i.n():[]).catch(()=>[]),t?r.o().then(e=>({ok:!0,entries:e})).catch(()=>({ok:!1,entries:[]})):Promise.resolve({ok:e===`disconnected`,entries:[]})]);e!==`unknown`&&(m=a.ok),a.ok&&e!==`unknown`&&(h=new Map(a.entries.map(e=>[e.path,e.updatedAt])));let o=new Map,l=e=>{let t=Date.parse(e.updatedAt??``);return Number.isFinite(t)?t:0},u=e=>{let t=o.get(e.path);(!t||l(e)>=l(t))&&o.set(e.path,e)};for(let e of n)u(e);for(let e of a.entries)u(e);return a.ok&&t&&(me(n,a.entries).catch(()=>{}),D()?M():z({local:n,remote:a.entries}).catch(()=>{})),[...o.values()]},ie=async e=>{if(await s())try{return await i.i(e)}catch(e){if(e?.name!==`NotFoundError`)throw e}let t=await r.c(e);return await s()&&i.o(e,t).catch(()=>{}),t},ae=async e=>{if(await s())try{let t=await i.i(e);return{data:new Uint8Array(await t.arrayBuffer()),sealedAt:null}}catch(e){if(e?.name!==`NotFoundError`)throw e}return r.l(e)},oe=async(e,t,n)=>{let a=t instanceof Blob?t:new Blob([t],n?.contentType?{type:n.contentType}:void 0);if(await s()){await i.o(e,a,n),U();let t=h.get(e)??null,o=await c();if(o===`disconnected`)return;if(o===`unknown`||!m){y(e,t),j();return}r.p(e,a,n).then(()=>b(e)).catch(n=>{y(e,t),j(),console.warn(`fs: cloud replicate failed, queued for adopt()`,n)});return}let o=await c();if(o===`connected`)return r.p(e,a,n);throw Error(o===`unknown`?`fs: cloud unreachable`:`fs: no storage backend available`)},se=async e=>{U();let t=[];await s()&&t.push(i.a(e).catch(()=>{}));let n=await c();if(n===`connected`?t.push(r.u(e).then(()=>S(e)).catch(t=>{ee(e),j(),console.warn(`fs: cloud delete failed, queued for retry`,t)})):n===`unknown`&&t.length&&h.has(e)&&(ee(e),j()),!t.length)throw Error(n===`unknown`?`fs: cloud unreachable`:`fs: no storage backend available`);b(e),await Promise.all(t)},ce=async e=>{let t=await r.c(e);return await s()&&await i.o(e,t),t},P=null,le=e=>(P=e,()=>{P===e&&(P=null)}),ue=async e=>{let t=await(await N()).cloud.fs.promptConflict({path:e.path,local:e.local,cloud:e.cloud}).catch(()=>null);return t===`local`?e.readLocal():t===`cloud`?e.readCloud():null},de=async e=>{if(P)try{return await P(e)}catch{return null}return ue(e)},F=async e=>{let t={uploaded:[],kept:[],resolved:[],unresolved:[],deleted:[],failed:[]},n=await c();if(n===`unknown`)throw Error(`fs: cloud unreachable`);if(n!==`connected`)throw Error(`fs: this needs a signed-in account`);let a=await s(),[o,l]=await Promise.all([a?i.n():Promise.resolve([]),r.o()]),u=new Map(l.map(e=>[e.path,e])),d=v();if(a)for(let e of Object.keys(d))o.some(t=>t.path===e)||b(e);for(let[e,n]of Object.entries(x())){let i=u.get(e);if(!i){S(e);continue}if(o.some(t=>t.path===e)){S(e);continue}if(i.updatedAt!==n){S(e);continue}try{await r.u(e),S(e),t.deleted.push(e)}catch(n){t.failed.push({path:e,error:n instanceof Error?n.message:String(n)})}}for(let n of o){let a=u.get(n.path),o=n.path in d;if(!o&&(a||!e)){a&&t.kept.push(n.path);continue}if(o&&a&&a.updatedAt!==d[n.path]){let e=null,o=null,s=await de({path:n.path,local:{size:n.size,updatedAt:n.updatedAt},cloud:{size:a.size,updatedAt:a.updatedAt},readLocal:()=>e??=i.i(n.path),readCloud:()=>o??=r.c(n.path)});if(s==null){t.unresolved.push(n.path);continue}try{let a=e!==null&&s===await e,c=o!==null&&s===await o;c||await r.p(n.path,s,n.contentType?{contentType:n.contentType}:void 0),a||await i.o(n.path,s),b(n.path),t.resolved.push({path:n.path,choice:a?`local`:c?`cloud`:`merged`})}catch(e){if(e?.code===`FKN_E2E_LOCKED`)throw e;t.failed.push({path:n.path,error:e instanceof Error?e.message:String(e)})}continue}try{let e=await i.i(n.path);await r.p(n.path,e,n.contentType?{contentType:n.contentType}:void 0),b(n.path),t.uploaded.push(n.path)}catch(e){if(y(n.path),e?.code===`FKN_E2E_LOCKED`)throw e;t.failed.push({path:n.path,error:e instanceof Error?e.message:String(e)})}}return t},I=async()=>{for(;E;)await E;let e=F(!0);E=e.then(()=>{},()=>{});try{return await e}finally{E=null}},L=async()=>{if(!await l()||!await s())return{paths:[],bytes:0};let[e,t]=await Promise.all([i.n(),r.o()]),n=new Set(t.map(e=>e.path)),a=e.filter(e=>!n.has(e.path));return{paths:a.map(e=>e.path),bytes:a.reduce((e,t)=>e+t.size,0)}},fe=()=>new Set(Object.keys(g(p))),pe=e=>{let t=g(p);for(let n of e)t[n]=null;_(p,t)},R=null,z=e=>R||(R=(async()=>{if(!await l())return;let t=e??(await s()?{local:await i.n(),remote:await r.o()}:null);if(!t)return;let n=new Set(t.remote.map(e=>e.path)),a=fe(),o=t.local.filter(e=>!n.has(e.path)&&!a.has(e.path));if(!o.length)return;let c=await N(),u=o.reduce((e,t)=>e+t.size,0);if(!await c.cloud.fs.promptAdopt({files:o.length,bytes:u}).catch(()=>!1)){pe(o.map(e=>e.path));return}await I()})().catch(()=>{}).finally(()=>{R=null}),R),B=null,V=!1,me=async(e,t)=>{let n=new Set(t.map(e=>e.path)),r=e.filter(e=>!n.has(e.path)),i=await N(),a=async()=>{await I().catch(()=>{});let e=await L().catch(()=>({paths:[],bytes:0}));await i.cloud.fs.setAdoptSource({files:e.paths.length,bytes:e.bytes},a).catch(()=>{})},o={files:r.length,bytes:r.reduce((e,t)=>e+t.size,0)};B=()=>{i.cloud.fs.setAdoptSource(o,a).catch(()=>{})},V||(V=!0,Promise.resolve().then(()=>require("./api.cjs")).then(e=>e.onApiEpoch((e,t)=>{t>1&&B?.()})).catch(()=>{})),await i.cloud.fs.setAdoptSource(o,a)},H=!1,U=()=>{H||typeof window>`u`||(H=!0,window.addEventListener(`online`,()=>{M()}),Promise.resolve().then(()=>require("./account.cjs")).then(e=>e.onChange(()=>{z().catch(()=>{}),M()})).catch(()=>{}))},he=e.t({adopt:()=>q,adoptable:()=>J,appendFile:()=>je,appendFileSync:()=>be,available:()=>_e,default:()=>$,exists:()=>Re,existsSync:()=>xe,flush:()=>Ve,lstatSync:()=>Ce,mkdir:()=>Pe,mkdirSync:()=>we,mount:()=>Be,onConflict:()=>Q,pending:()=>Y,pendingDeletes:()=>X,promises:()=>ze,pull:()=>G,readFile:()=>ke,readFileSealed:()=>K,readFileSync:()=>ve,readdir:()=>Ne,readdirSync:()=>W,remount:()=>He,rename:()=>Le,renameSync:()=>Oe,replicating:()=>Z,rm:()=>Fe,rmSync:()=>Te,rmdirSync:()=>Ee,stat:()=>Me,statSync:()=>Se,unlink:()=>Ie,unlinkSync:()=>De,writeFile:()=>Ae,writeFileSync:()=>ye}),ge=n.t(a,{memfs:!0}),{available:_e,readFileSync:ve,writeFileSync:ye,appendFileSync:be,existsSync:xe,statSync:Se,lstatSync:Ce,readdirSync:W,mkdirSync:we,rmSync:Te,rmdirSync:Ee,unlinkSync:De,renameSync:Oe,readFile:ke,writeFile:Ae,appendFile:je,stat:Me,readdir:Ne,mkdir:Pe,rm:Fe,unlink:Ie,rename:Le,exists:Re,promises:ze,mount:Be,flush:Ve,remount:He}=ge,G=ce,K=ae,q=I,J=L,Y=C,X=w,Z=T,Q=le,$={...ge,pull:G,readFileSealed:K,adopt:q,adoptable:J,pending:Y,pendingDeletes:X,replicating:Z,onConflict:Q};Object.defineProperty(exports,"A",{enumerable:!0,get:function(){return Te}}),Object.defineProperty(exports,"C",{enumerable:!0,get:function(){return Ne}}),Object.defineProperty(exports,"D",{enumerable:!0,get:function(){return Oe}}),Object.defineProperty(exports,"E",{enumerable:!0,get:function(){return Le}}),Object.defineProperty(exports,"F",{enumerable:!0,get:function(){return De}}),Object.defineProperty(exports,"I",{enumerable:!0,get:function(){return Ae}}),Object.defineProperty(exports,"L",{enumerable:!0,get:function(){return ye}}),Object.defineProperty(exports,"M",{enumerable:!0,get:function(){return Me}}),Object.defineProperty(exports,"N",{enumerable:!0,get:function(){return Se}}),Object.defineProperty(exports,"O",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"P",{enumerable:!0,get:function(){return Ie}}),Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return ve}}),Object.defineProperty(exports,"T",{enumerable:!0,get:function(){return He}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return _e}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return ke}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return Ve}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return Ce}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return Pe}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return Y}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return Q}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return be}}),Object.defineProperty(exports,"j",{enumerable:!0,get:function(){return Ee}}),Object.defineProperty(exports,"k",{enumerable:!0,get:function(){return Fe}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return Be}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return J}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return Re}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return we}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return je}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return xe}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return ze}}),Object.defineProperty(exports,"w",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return G}});
|
package/fs-D3IsGdnN.js
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import { r as t } from "./busy-B189uX--.js";
|
|
3
|
-
import { t as n } from "./node-fs-BZy9bzKd.js";
|
|
4
|
-
import { c as r, l as i, o as a, p as o, r as s, u as c } from "./storage-DSvL-t80.js";
|
|
5
|
-
import { a as l, i as u, n as d, o as f, t as p } from "./opfs-D0goLAQW.js";
|
|
6
|
-
//#region src/fs/hybrid.ts
|
|
7
|
-
var m = /* @__PURE__ */ e({
|
|
8
|
-
adopt: () => V,
|
|
9
|
-
adoptable: () => H,
|
|
10
|
-
available: () => te,
|
|
11
|
-
list: () => ce,
|
|
12
|
-
onConflict: () => z,
|
|
13
|
-
pending: () => re,
|
|
14
|
-
pendingDeletes: () => ie,
|
|
15
|
-
pull: () => pe,
|
|
16
|
-
readFile: () => le,
|
|
17
|
-
readFileSealed: () => ue,
|
|
18
|
-
remove: () => fe,
|
|
19
|
-
replicating: () => ae,
|
|
20
|
-
writeFile: () => de
|
|
21
|
-
}), ee, h = async () => await (ee ??= p().catch(() => !1)) ? !0 : (ee = void 0, !1), g = () => s().catch(() => "unknown"), _ = async () => await g() === "connected", te = async () => await h() || await _(), v = "fkn:fs:pending", y = "fkn:fs:pending-delete", b = "fkn:fs:adopt-declined", x = !0, S = /* @__PURE__ */ new Map(), C = (e) => {
|
|
22
|
-
try {
|
|
23
|
-
let t = localStorage.getItem(e);
|
|
24
|
-
if (!t) return {};
|
|
25
|
-
let n = JSON.parse(t);
|
|
26
|
-
return Array.isArray(n) ? Object.fromEntries(n.filter((e) => typeof e == "string").map((e) => [e, null])) : n && typeof n == "object" ? n : {};
|
|
27
|
-
} catch {
|
|
28
|
-
return {};
|
|
29
|
-
}
|
|
30
|
-
}, w = (e, t) => {
|
|
31
|
-
try {
|
|
32
|
-
Object.keys(t).length ? localStorage.setItem(e, JSON.stringify(t)) : localStorage.removeItem(e);
|
|
33
|
-
} catch {}
|
|
34
|
-
}, T = () => C(v), E = (e, t) => {
|
|
35
|
-
let n = T();
|
|
36
|
-
e in n || (n[e] = t === void 0 ? S.get(e) ?? null : t, w(v, n));
|
|
37
|
-
}, D = (e) => {
|
|
38
|
-
let t = T();
|
|
39
|
-
e in t && (delete t[e], w(v, t), j() || (N = M));
|
|
40
|
-
}, O = () => C(y), ne = (e) => {
|
|
41
|
-
let t = O();
|
|
42
|
-
e in t || (t[e] = S.get(e) ?? null, w(y, t));
|
|
43
|
-
}, k = (e) => {
|
|
44
|
-
let t = O();
|
|
45
|
-
e in t && (delete t[e], w(y, t), j() || (N = M));
|
|
46
|
-
}, re = () => Object.keys(T()), ie = () => Object.keys(O()), ae = () => x, A = null;
|
|
47
|
-
t("storage replication", () => A !== null || U !== null);
|
|
48
|
-
var j = () => Object.keys(T()).length > 0 || Object.keys(O()).length > 0, M = 6e4, oe = 6e5, N = M, P = null, F = () => {
|
|
49
|
-
!P && typeof window < "u" && j() && (P = setTimeout(() => {
|
|
50
|
-
P = null, I();
|
|
51
|
-
}, N), N = Math.min(N * 2, oe));
|
|
52
|
-
}, I = () => {
|
|
53
|
-
!A && j() && (A = B(!1).then((e) => {
|
|
54
|
-
if (!j()) {
|
|
55
|
-
N = M;
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
e.failed.length && F();
|
|
59
|
-
}).catch(() => {
|
|
60
|
-
F();
|
|
61
|
-
}).finally(() => {
|
|
62
|
-
A = null;
|
|
63
|
-
}));
|
|
64
|
-
}, se = null, L = () => se ??= import("./api.js").then((e) => e.apiPromise), ce = async () => {
|
|
65
|
-
W();
|
|
66
|
-
let e = await g(), t = e === "connected", [n, r] = await Promise.all([h().then((e) => e ? d() : []).catch(() => []), t ? a().then((e) => ({
|
|
67
|
-
ok: !0,
|
|
68
|
-
entries: e
|
|
69
|
-
})).catch(() => ({
|
|
70
|
-
ok: !1,
|
|
71
|
-
entries: []
|
|
72
|
-
})) : Promise.resolve({
|
|
73
|
-
ok: e === "disconnected",
|
|
74
|
-
entries: []
|
|
75
|
-
})]);
|
|
76
|
-
e !== "unknown" && (x = r.ok), r.ok && e !== "unknown" && (S = new Map(r.entries.map((e) => [e.path, e.updatedAt])));
|
|
77
|
-
let i = /* @__PURE__ */ new Map(), o = (e) => {
|
|
78
|
-
let t = Date.parse(e.updatedAt ?? "");
|
|
79
|
-
return Number.isFinite(t) ? t : 0;
|
|
80
|
-
}, s = (e) => {
|
|
81
|
-
let t = i.get(e.path);
|
|
82
|
-
(!t || o(e) >= o(t)) && i.set(e.path, e);
|
|
83
|
-
};
|
|
84
|
-
for (let e of n) s(e);
|
|
85
|
-
for (let e of r.entries) s(e);
|
|
86
|
-
return r.ok && t && (xe(n, r.entries).catch(() => {}), j() ? I() : ve({
|
|
87
|
-
local: n,
|
|
88
|
-
remote: r.entries
|
|
89
|
-
}).catch(() => {})), [...i.values()];
|
|
90
|
-
}, le = async (e) => {
|
|
91
|
-
if (await h()) try {
|
|
92
|
-
return await u(e);
|
|
93
|
-
} catch (e) {
|
|
94
|
-
if (e?.name !== "NotFoundError") throw e;
|
|
95
|
-
}
|
|
96
|
-
let t = await r(e);
|
|
97
|
-
return await h() && f(e, t).catch(() => {}), t;
|
|
98
|
-
}, ue = async (e) => {
|
|
99
|
-
if (await h()) try {
|
|
100
|
-
let t = await u(e);
|
|
101
|
-
return {
|
|
102
|
-
data: new Uint8Array(await t.arrayBuffer()),
|
|
103
|
-
sealedAt: null
|
|
104
|
-
};
|
|
105
|
-
} catch (e) {
|
|
106
|
-
if (e?.name !== "NotFoundError") throw e;
|
|
107
|
-
}
|
|
108
|
-
return i(e);
|
|
109
|
-
}, de = async (e, t, n) => {
|
|
110
|
-
let r = t instanceof Blob ? t : new Blob([t], n?.contentType ? { type: n.contentType } : void 0);
|
|
111
|
-
if (await h()) {
|
|
112
|
-
await f(e, r, n), W();
|
|
113
|
-
let t = S.get(e) ?? null, i = await g();
|
|
114
|
-
if (i === "disconnected") return;
|
|
115
|
-
if (i === "unknown" || !x) {
|
|
116
|
-
E(e, t), F();
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
o(e, r, n).then(() => D(e)).catch((n) => {
|
|
120
|
-
E(e, t), F(), console.warn("fs: cloud replicate failed, queued for adopt()", n);
|
|
121
|
-
});
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
let i = await g();
|
|
125
|
-
if (i === "connected") return o(e, r, n);
|
|
126
|
-
throw Error(i === "unknown" ? "fs: cloud unreachable" : "fs: no storage backend available");
|
|
127
|
-
}, fe = async (e) => {
|
|
128
|
-
W();
|
|
129
|
-
let t = [];
|
|
130
|
-
await h() && t.push(l(e).catch(() => {}));
|
|
131
|
-
let n = await g();
|
|
132
|
-
if (n === "connected" ? t.push(c(e).then(() => k(e)).catch((t) => {
|
|
133
|
-
ne(e), F(), console.warn("fs: cloud delete failed, queued for retry", t);
|
|
134
|
-
})) : n === "unknown" && t.length && S.has(e) && (ne(e), F()), !t.length) throw Error(n === "unknown" ? "fs: cloud unreachable" : "fs: no storage backend available");
|
|
135
|
-
D(e), await Promise.all(t);
|
|
136
|
-
}, pe = async (e) => {
|
|
137
|
-
let t = await r(e);
|
|
138
|
-
return await h() && await f(e, t), t;
|
|
139
|
-
}, R = null, z = (e) => (R = e, () => {
|
|
140
|
-
R === e && (R = null);
|
|
141
|
-
}), me = async (e) => {
|
|
142
|
-
let t = await (await L()).cloud.fs.promptConflict({
|
|
143
|
-
path: e.path,
|
|
144
|
-
local: e.local,
|
|
145
|
-
cloud: e.cloud
|
|
146
|
-
}).catch(() => null);
|
|
147
|
-
return t === "local" ? e.readLocal() : t === "cloud" ? e.readCloud() : null;
|
|
148
|
-
}, he = async (e) => {
|
|
149
|
-
if (R) try {
|
|
150
|
-
return await R(e);
|
|
151
|
-
} catch {
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
return me(e);
|
|
155
|
-
}, B = async (e) => {
|
|
156
|
-
let t = {
|
|
157
|
-
uploaded: [],
|
|
158
|
-
kept: [],
|
|
159
|
-
resolved: [],
|
|
160
|
-
unresolved: [],
|
|
161
|
-
deleted: [],
|
|
162
|
-
failed: []
|
|
163
|
-
}, n = await g();
|
|
164
|
-
if (n === "unknown") throw Error("fs: cloud unreachable");
|
|
165
|
-
if (n !== "connected") throw Error("fs: this needs a signed-in account");
|
|
166
|
-
let i = await h(), [s, l] = await Promise.all([i ? d() : Promise.resolve([]), a()]), p = new Map(l.map((e) => [e.path, e])), m = T();
|
|
167
|
-
if (i) for (let e of Object.keys(m)) s.some((t) => t.path === e) || D(e);
|
|
168
|
-
for (let [e, n] of Object.entries(O())) {
|
|
169
|
-
let r = p.get(e);
|
|
170
|
-
if (!r) {
|
|
171
|
-
k(e);
|
|
172
|
-
continue;
|
|
173
|
-
}
|
|
174
|
-
if (s.some((t) => t.path === e)) {
|
|
175
|
-
k(e);
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
if (r.updatedAt !== n) {
|
|
179
|
-
k(e);
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
try {
|
|
183
|
-
await c(e), k(e), t.deleted.push(e);
|
|
184
|
-
} catch (n) {
|
|
185
|
-
t.failed.push({
|
|
186
|
-
path: e,
|
|
187
|
-
error: n instanceof Error ? n.message : String(n)
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
for (let n of s) {
|
|
192
|
-
let i = p.get(n.path), a = n.path in m;
|
|
193
|
-
if (!a && (i || !e)) {
|
|
194
|
-
i && t.kept.push(n.path);
|
|
195
|
-
continue;
|
|
196
|
-
}
|
|
197
|
-
if (a && i && i.updatedAt !== m[n.path]) {
|
|
198
|
-
let e = null, a = null, s = await he({
|
|
199
|
-
path: n.path,
|
|
200
|
-
local: {
|
|
201
|
-
size: n.size,
|
|
202
|
-
updatedAt: n.updatedAt
|
|
203
|
-
},
|
|
204
|
-
cloud: {
|
|
205
|
-
size: i.size,
|
|
206
|
-
updatedAt: i.updatedAt
|
|
207
|
-
},
|
|
208
|
-
readLocal: () => e ??= u(n.path),
|
|
209
|
-
readCloud: () => a ??= r(n.path)
|
|
210
|
-
});
|
|
211
|
-
if (s == null) {
|
|
212
|
-
t.unresolved.push(n.path);
|
|
213
|
-
continue;
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
let r = e !== null && s === await e, i = a !== null && s === await a;
|
|
217
|
-
i || await o(n.path, s, n.contentType ? { contentType: n.contentType } : void 0), r || await f(n.path, s), D(n.path), t.resolved.push({
|
|
218
|
-
path: n.path,
|
|
219
|
-
choice: r ? "local" : i ? "cloud" : "merged"
|
|
220
|
-
});
|
|
221
|
-
} catch (e) {
|
|
222
|
-
if (e?.code === "FKN_E2E_LOCKED") throw e;
|
|
223
|
-
t.failed.push({
|
|
224
|
-
path: n.path,
|
|
225
|
-
error: e instanceof Error ? e.message : String(e)
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
let e = await u(n.path);
|
|
232
|
-
await o(n.path, e, n.contentType ? { contentType: n.contentType } : void 0), D(n.path), t.uploaded.push(n.path);
|
|
233
|
-
} catch (e) {
|
|
234
|
-
if (E(n.path), e?.code === "FKN_E2E_LOCKED") throw e;
|
|
235
|
-
t.failed.push({
|
|
236
|
-
path: n.path,
|
|
237
|
-
error: e instanceof Error ? e.message : String(e)
|
|
238
|
-
});
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
return t;
|
|
242
|
-
}, V = async () => {
|
|
243
|
-
for (; A;) await A;
|
|
244
|
-
let e = B(!0);
|
|
245
|
-
A = e.then(() => {}, () => {});
|
|
246
|
-
try {
|
|
247
|
-
return await e;
|
|
248
|
-
} finally {
|
|
249
|
-
A = null;
|
|
250
|
-
}
|
|
251
|
-
}, H = async () => {
|
|
252
|
-
if (!await _() || !await h()) return {
|
|
253
|
-
paths: [],
|
|
254
|
-
bytes: 0
|
|
255
|
-
};
|
|
256
|
-
let [e, t] = await Promise.all([d(), a()]), n = new Set(t.map((e) => e.path)), r = e.filter((e) => !n.has(e.path));
|
|
257
|
-
return {
|
|
258
|
-
paths: r.map((e) => e.path),
|
|
259
|
-
bytes: r.reduce((e, t) => e + t.size, 0)
|
|
260
|
-
};
|
|
261
|
-
}, ge = () => new Set(Object.keys(C(b))), _e = (e) => {
|
|
262
|
-
let t = C(b);
|
|
263
|
-
for (let n of e) t[n] = null;
|
|
264
|
-
w(b, t);
|
|
265
|
-
}, U = null, ve = (e) => U || (U = (async () => {
|
|
266
|
-
if (!await _()) return;
|
|
267
|
-
let t = e ?? (await h() ? {
|
|
268
|
-
local: await d(),
|
|
269
|
-
remote: await a()
|
|
270
|
-
} : null);
|
|
271
|
-
if (!t) return;
|
|
272
|
-
let n = new Set(t.remote.map((e) => e.path)), r = ge(), i = t.local.filter((e) => !n.has(e.path) && !r.has(e.path));
|
|
273
|
-
if (!i.length) return;
|
|
274
|
-
let o = await L(), s = i.reduce((e, t) => e + t.size, 0);
|
|
275
|
-
if (!await o.cloud.fs.promptAdopt({
|
|
276
|
-
files: i.length,
|
|
277
|
-
bytes: s
|
|
278
|
-
}).catch(() => !1)) {
|
|
279
|
-
_e(i.map((e) => e.path));
|
|
280
|
-
return;
|
|
281
|
-
}
|
|
282
|
-
await V();
|
|
283
|
-
})().catch(() => {}).finally(() => {
|
|
284
|
-
U = null;
|
|
285
|
-
}), U), ye = null, be = !1, xe = async (e, t) => {
|
|
286
|
-
let n = new Set(t.map((e) => e.path)), r = e.filter((e) => !n.has(e.path)), i = await L(), a = async () => {
|
|
287
|
-
await V().catch(() => {});
|
|
288
|
-
let e = await H().catch(() => ({
|
|
289
|
-
paths: [],
|
|
290
|
-
bytes: 0
|
|
291
|
-
}));
|
|
292
|
-
await i.cloud.fs.setAdoptSource({
|
|
293
|
-
files: e.paths.length,
|
|
294
|
-
bytes: e.bytes
|
|
295
|
-
}, a).catch(() => {});
|
|
296
|
-
}, o = {
|
|
297
|
-
files: r.length,
|
|
298
|
-
bytes: r.reduce((e, t) => e + t.size, 0)
|
|
299
|
-
};
|
|
300
|
-
ye = () => {
|
|
301
|
-
i.cloud.fs.setAdoptSource(o, a).catch(() => {});
|
|
302
|
-
}, be || (be = !0, import("./api.js").then((e) => e.onApiEpoch((e, t) => {
|
|
303
|
-
t > 1 && ye?.();
|
|
304
|
-
})).catch(() => {})), await i.cloud.fs.setAdoptSource(o, a);
|
|
305
|
-
}, Se = !1, W = () => {
|
|
306
|
-
Se || typeof window > "u" || (Se = !0, window.addEventListener("online", () => {
|
|
307
|
-
I();
|
|
308
|
-
}), import("./account.js").then((e) => e.onChange(() => {
|
|
309
|
-
ve().catch(() => {}), I();
|
|
310
|
-
})).catch(() => {}));
|
|
311
|
-
}, Ce = /* @__PURE__ */ e({
|
|
312
|
-
adopt: () => J,
|
|
313
|
-
adoptable: () => Y,
|
|
314
|
-
appendFile: () => Be,
|
|
315
|
-
appendFileSync: () => Oe,
|
|
316
|
-
available: () => Te,
|
|
317
|
-
default: () => Ze,
|
|
318
|
-
exists: () => qe,
|
|
319
|
-
existsSync: () => ke,
|
|
320
|
-
flush: () => G,
|
|
321
|
-
lstatSync: () => je,
|
|
322
|
-
mkdir: () => Ue,
|
|
323
|
-
mkdirSync: () => Ne,
|
|
324
|
-
mount: () => Ye,
|
|
325
|
-
onConflict: () => $,
|
|
326
|
-
pending: () => X,
|
|
327
|
-
pendingDeletes: () => Z,
|
|
328
|
-
promises: () => Je,
|
|
329
|
-
pull: () => K,
|
|
330
|
-
readFile: () => Re,
|
|
331
|
-
readFileSealed: () => q,
|
|
332
|
-
readFileSync: () => Ee,
|
|
333
|
-
readdir: () => He,
|
|
334
|
-
readdirSync: () => Me,
|
|
335
|
-
remount: () => Xe,
|
|
336
|
-
rename: () => Ke,
|
|
337
|
-
renameSync: () => Le,
|
|
338
|
-
replicating: () => Q,
|
|
339
|
-
rm: () => We,
|
|
340
|
-
rmSync: () => Pe,
|
|
341
|
-
rmdirSync: () => Fe,
|
|
342
|
-
stat: () => Ve,
|
|
343
|
-
statSync: () => Ae,
|
|
344
|
-
unlink: () => Ge,
|
|
345
|
-
unlinkSync: () => Ie,
|
|
346
|
-
writeFile: () => ze,
|
|
347
|
-
writeFileSync: () => De
|
|
348
|
-
}), we = n(m, { memfs: !0 }), { available: Te, readFileSync: Ee, writeFileSync: De, appendFileSync: Oe, existsSync: ke, statSync: Ae, lstatSync: je, readdirSync: Me, mkdirSync: Ne, rmSync: Pe, rmdirSync: Fe, unlinkSync: Ie, renameSync: Le, readFile: Re, writeFile: ze, appendFile: Be, stat: Ve, readdir: He, mkdir: Ue, rm: We, unlink: Ge, rename: Ke, exists: qe, promises: Je, mount: Ye, flush: G, remount: Xe } = we, K = pe, q = ue, J = V, Y = H, X = re, Z = ie, Q = ae, $ = z, Ze = {
|
|
349
|
-
...we,
|
|
350
|
-
pull: K,
|
|
351
|
-
readFileSealed: q,
|
|
352
|
-
adopt: J,
|
|
353
|
-
adoptable: Y,
|
|
354
|
-
pending: X,
|
|
355
|
-
pendingDeletes: Z,
|
|
356
|
-
replicating: Q,
|
|
357
|
-
onConflict: $
|
|
358
|
-
};
|
|
359
|
-
//#endregion
|
|
360
|
-
export { Pe as A, He as C, Le as D, Ke as E, Ie as F, ze as I, De as L, Ve as M, Ae as N, Q as O, Ge as P, Ee as S, Xe as T, Z as _, Te as a, Re as b, G as c, je as d, Ue as f, X as g, $ as h, Oe as i, Fe as j, We as k, Ze as l, Ye as m, Y as n, qe as o, Ne as p, Be as r, ke as s, J as t, Ce as u, Je as v, Me as w, q as x, K as y };
|