@fkn/lib 0.9.53 → 0.9.55
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-BgiEc3fw.js → account-generation-CTB1J33G.js} +4 -3
- package/account-generation-DOuApHq5.cjs +1 -0
- package/{account-storage-IAVrRXTF.cjs → account-storage-CL0wLuQw.cjs} +1 -1
- package/{account-storage-DHl6bXdb.d.ts → account-storage-Co9IvkPr.d.ts} +3 -3
- package/{account-storage-DptsMWKl.js → account-storage-D1RiskV6.js} +2 -2
- package/account.cjs +1 -1
- package/account.d.ts +21 -11
- package/account.js +2 -2
- package/{api-mHRuM_Sd.d.ts → api-BSpQkgnM.d.ts} +1198 -30
- package/{api-CX9w35R2.js → api-BYtMzj8u.js} +1 -1
- package/{api-6wTec7WK.cjs → api-Csb5b8dE.cjs} +1 -1
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -1
- package/cloud/dns.d.ts +1 -1
- package/cloud/fetch.cjs +1 -1
- package/cloud/fetch.d.ts +1 -1
- package/cloud/fetch.js +1 -1
- package/cloud/fs/promises.d.ts +1 -1
- package/cloud/fs.cjs +1 -1
- package/cloud/fs.d.ts +2 -2
- package/cloud/fs.js +1 -1
- package/cloud/net.d.ts +1 -1
- package/{cloud-CMEnCSBw.js → cloud-8sJ1Sg8n.js} +3 -3
- package/{cloud-Dykm74YZ.d.ts → cloud-BslRIoKs.d.ts} +3 -3
- package/{cloud-kg1hOpPJ.cjs → cloud-CI6WMBPa.cjs} +1 -1
- package/cloud.cjs +1 -1
- package/cloud.d.ts +4 -4
- package/cloud.js +2 -2
- package/{contract-BN0cD-Oq.d.ts → contract-DFycgFJK.d.ts} +160 -8
- package/contract.d.ts +2 -2
- package/dgram.cjs +1 -1
- package/dgram.d.ts +2 -2
- package/dgram.js +1 -1
- package/dns.cjs +1 -1
- package/dns.d.ts +1 -1
- package/dns.js +1 -1
- package/{extension-BdAR-wQ0.cjs → extension-BXI3MVXw.cjs} +1 -1
- package/{extension-DiyykwoW.js → extension-BmqjgSIQ.js} +3 -3
- package/extension.cjs +1 -1
- package/extension.js +2 -2
- package/fs/promises.cjs +1 -1
- package/fs/promises.d.ts +1 -1
- package/fs/promises.js +1 -1
- package/{fs-CPsnX6ti.cjs → fs-CPU00CI3.cjs} +1 -1
- package/{fs-BZv2djbS.d.ts → fs-DCJAYoYy.d.ts} +1 -1
- package/{fs-Cd1HK3C3.js → fs-ohcMNiu2.js} +2 -2
- package/fs.cjs +1 -1
- package/fs.d.ts +2 -2
- package/fs.js +2 -2
- package/http.d.ts +1 -1
- package/{index-DawD_N1P.d.ts → index-57lTXnoe.d.ts} +1 -1
- package/index.cjs +1 -1
- package/index.d.ts +4 -4
- package/index.js +5 -5
- package/{lib-C5N2rmbj.js → lib-BGAmzIcU.js} +1 -1
- package/{lib-C0xyv8BQ.cjs → lib-BiQ6cOZ7.cjs} +1 -1
- package/{net-Dq1KyRP0.d.ts → net-eEjhJ0AE.d.ts} +2 -2
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +1 -1
- package/package.json +1 -1
- package/packages.cjs +1 -1
- package/packages.d.ts +15 -2
- package/packages.js +114 -113
- package/{proxy-Cer0Iarp.d.ts → proxy-8hIHeEHD.d.ts} +2 -2
- package/{proxy-DhalpZoN.cjs → proxy-CL8j00ao.cjs} +1 -1
- package/{proxy-v_Z5aPh2.js → proxy-vAsYHMIa.js} +1 -1
- package/rooms.cjs +1 -1
- package/rooms.d.ts +43 -9
- package/rooms.js +167 -94
- package/storage.cjs +1 -1
- package/storage.d.ts +1 -1
- package/storage.js +3 -3
- package/account-generation-C5rMCyt1.cjs +0 -1
package/rooms.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { J as RoomClaimOptions, Q as
|
|
1
|
+
import { $ as RoomEvent, J as RoomClaimOptions, Q as RoomEnvelope, X as RoomDefaults, Y as RoomCreateOptions, Z as RoomEnd, at as RoomMessage, ct as RoomPermissions, dt as RoomsErrorCode, it as RoomMember, lt as RoomSchema, nt as RoomJson, ot as RoomOpenOptions, q as RoomBacklog, rt as RoomMailbox, st as RoomPermission, tt as RoomJoinOptions, ut as RoomType } from "./contract-DFycgFJK.js";
|
|
2
2
|
declare namespace rooms_d_exports {
|
|
3
|
-
export { RoomClaimOptions as ClaimOptions, RoomCreateOptions as CreateOptions, RoomJoinOptions as JoinOptions, RoomOpenOptions as OpenOptions, Room, RoomBacklog, RoomDefaults, RoomEnd, RoomEvent, RoomMailbox, RoomMember, RoomMessage, RoomPermission, RoomPermissions, RoomsError, RoomsErrorCode, available, create, join, open };
|
|
3
|
+
export { RoomClaimOptions as ClaimOptions, RoomCreateOptions as CreateOptions, RoomJoinOptions as JoinOptions, RoomOpenOptions as OpenOptions, Room, RoomBacklog, RoomDefaults, RoomEnd, RoomEnvelope, RoomEvent, RoomJson, RoomMailbox, RoomMember, RoomMessage, RoomPermission, RoomPermissions, RoomSchema, RoomType, RoomsError, RoomsErrorCode, available, create, join, open };
|
|
4
4
|
}
|
|
5
5
|
/** Thrown by every member of this namespace. Match on `code`, never on the message. */
|
|
6
6
|
export type RoomsError = Error & {
|
|
@@ -33,14 +33,48 @@ export type Room = {
|
|
|
33
33
|
readonly mailbox: RoomMailbox | null;
|
|
34
34
|
defaults: () => RoomDefaults;
|
|
35
35
|
members: () => Promise<RoomMember[]>;
|
|
36
|
-
/**
|
|
37
|
-
|
|
36
|
+
/** the room's schema as the room last said, null for a room without one */
|
|
37
|
+
schema: () => RoomSchema | null;
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* `text` is sealed before it leaves the browser. Rejects `too-large` past `self.maxMessageBytes` on the
|
|
40
|
+
* wire, never truncates.
|
|
41
|
+
*
|
|
42
|
+
* In a room with a schema `envelope` is required: it goes in plain beside the sealed text, which may be
|
|
43
|
+
* empty, and the sealed text opens only under it. The app chooses what is sealed at each send: put in
|
|
44
|
+
* the envelope only what every member and FKN may read, and the rest in `text`. The lib writes it with
|
|
45
|
+
* `JSON.stringify` and refuses `invalid` (`rooms: the message does not fit the room's schema`), with
|
|
46
|
+
* nothing sent, one that is not a JSON object with a string `type` or is past 2,048 characters; the room
|
|
47
|
+
* refuses the same for an envelope that does not fit its type, or a send without one. The size counted
|
|
48
|
+
* is the envelope's text and the sealed text together, against `self.maxMessageBytes` and the type's
|
|
49
|
+
* `maxBytes`. The type's sender rule refuses `denied` (`rooms: only the owner sends this type`, `rooms:
|
|
50
|
+
* sending this needs an account`), its per-account limit `full` (`rooms: you have as many of these
|
|
51
|
+
* here as the room allows`), and the room's cap `storage` (`rooms: the mailbox is full`).
|
|
52
|
+
*
|
|
53
|
+
* Without a schema an envelope is refused `invalid` (`rooms: the room has no schema`). An fkn.app older
|
|
54
|
+
* than room schemas refuses one `unavailable` (`rooms: room schemas are not available`) with nothing
|
|
55
|
+
* sent; a send without one goes as before.
|
|
56
|
+
*/
|
|
57
|
+
send: (text: string, envelope?: RoomEnvelope) => Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* replaces a stored message's text: one of your own, or any as the owner. Checked exactly as a send is,
|
|
60
|
+
* `send` and the rate limits included; in a room with a schema `envelope` is required and names the
|
|
61
|
+
* message's own type, so a message stored before the room had a schema is deleted rather than edited.
|
|
62
|
+
* On a room claimed under an app's scope, from another app of the claim's account, it is refused
|
|
63
|
+
* `denied` (`rooms: only the app that claimed the room can change it`), the account's own messages
|
|
64
|
+
* included, as `claim` says.
|
|
65
|
+
*/
|
|
66
|
+
edit: (seq: number, text: string, envelope?: RoomEnvelope) => Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* replaces the room's schema with one of a higher `version`, from the next send on; everyone present
|
|
69
|
+
* hears a `schema` event. The same schema at the same `version` resolves and changes nothing, so set it
|
|
70
|
+
* on every open. A lower `version`, or another schema at the same one, is refused `invalid` (`rooms: the
|
|
71
|
+
* room holds a newer schema`), and one the room cannot take `invalid` (`rooms: the schema is not one a
|
|
72
|
+
* room can take`). From the owner only (`denied`, `rooms: not the room owner`), and on a room claimed
|
|
73
|
+
* under an app's scope only through the app that claimed it (`denied`, `rooms: only the app that
|
|
74
|
+
* claimed the room can change it`), as `claim` says. A schema is never removed. An fkn.app older than
|
|
75
|
+
* room schemas refuses it `unavailable` (`rooms: room schemas are not available`).
|
|
42
76
|
*/
|
|
43
|
-
|
|
77
|
+
setSchema: (schema: RoomSchema) => Promise<void>;
|
|
44
78
|
/**
|
|
45
79
|
* drops stored messages: one of your own, or any range as the owner. On a room claimed under an app's
|
|
46
80
|
* scope, from another app of the claim's account, it is refused `denied` (`rooms: only the app that
|
|
@@ -177,4 +211,4 @@ export declare const create: (options?: RoomCreateOptions) => Promise<Room>;
|
|
|
177
211
|
/** `invite` is `room.invite`: a key and a room id joined by a dot. */
|
|
178
212
|
export declare const join: (invite: string, options?: RoomJoinOptions) => Promise<Room>;
|
|
179
213
|
//#endregion
|
|
180
|
-
export { type RoomClaimOptions as ClaimOptions, type RoomCreateOptions as CreateOptions, type RoomJoinOptions as JoinOptions, type RoomOpenOptions as OpenOptions, type RoomBacklog, type RoomDefaults, type RoomEnd, type RoomEvent, type RoomMailbox, type RoomMember, type RoomMessage, type RoomPermission, type RoomPermissions, type RoomsErrorCode, rooms_d_exports as t };
|
|
214
|
+
export { type RoomClaimOptions as ClaimOptions, type RoomCreateOptions as CreateOptions, type RoomJoinOptions as JoinOptions, type RoomOpenOptions as OpenOptions, type RoomBacklog, type RoomDefaults, type RoomEnd, type RoomEnvelope, type RoomEvent, type RoomJson, type RoomMailbox, type RoomMember, type RoomMessage, type RoomPermission, type RoomPermissions, type RoomSchema, type RoomType, type RoomsErrorCode, rooms_d_exports as t };
|
package/rooms.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import { l as t, s as n, u as r } from "./api-
|
|
2
|
+
import { l as t, s as n, u as r } from "./api-BYtMzj8u.js";
|
|
3
3
|
import { t as i } from "./busy-DsMWrSzc.js";
|
|
4
4
|
import { ROOM_TEMPORARY_MS as a } from "./contract.js";
|
|
5
5
|
//#region src/rooms.ts
|
|
6
6
|
var o = /* @__PURE__ */ e({
|
|
7
|
-
available: () =>
|
|
8
|
-
create: () =>
|
|
9
|
-
join: () =>
|
|
10
|
-
open: () =>
|
|
7
|
+
available: () => w,
|
|
8
|
+
create: () => D,
|
|
9
|
+
join: () => O,
|
|
10
|
+
open: () => E
|
|
11
11
|
}), s = {
|
|
12
12
|
wrongKey: "rooms: wrong room key",
|
|
13
13
|
inviteNoKey: "rooms: the invite carries no key",
|
|
@@ -42,6 +42,15 @@ var o = /* @__PURE__ */ e({
|
|
|
42
42
|
notTemporaryClaimer: "rooms: only the app that claimed the room can set when it expires",
|
|
43
43
|
temporaryUnavailable: "rooms: temporary claims are not available",
|
|
44
44
|
mailboxUnavailable: "rooms: the mailbox switch is not available",
|
|
45
|
+
guestUnavailable: "rooms: guest joins are not available",
|
|
46
|
+
schemasUnavailable: "rooms: room schemas are not available",
|
|
47
|
+
badSchema: "rooms: the schema is not one a room can take",
|
|
48
|
+
newerSchema: "rooms: the room holds a newer schema",
|
|
49
|
+
noSchema: "rooms: the room has no schema",
|
|
50
|
+
misfit: "rooms: the message does not fit the room's schema",
|
|
51
|
+
ownerSends: "rooms: only the owner sends this type",
|
|
52
|
+
accountSends: "rooms: sending this needs an account",
|
|
53
|
+
perAccount: "rooms: you have as many of these here as the room allows",
|
|
45
54
|
tooFast: "rooms: sending too fast",
|
|
46
55
|
tooLarge: "rooms: the message is too large",
|
|
47
56
|
unavailable: "rooms: rooms are unavailable",
|
|
@@ -54,87 +63,131 @@ var o = /* @__PURE__ */ e({
|
|
|
54
63
|
send: !0,
|
|
55
64
|
receive: !0,
|
|
56
65
|
maxMessageBytes: 262144
|
|
57
|
-
}, d = () => ({
|
|
66
|
+
}, d = 2048, f = () => ({
|
|
58
67
|
messages: 0,
|
|
59
68
|
bytes: 0,
|
|
60
69
|
cap: 5e8,
|
|
61
70
|
archived: !1
|
|
62
|
-
}),
|
|
71
|
+
}), p = async () => {
|
|
63
72
|
if (!t) return;
|
|
64
73
|
let e = (await n("a room").catch(() => void 0))?.rooms;
|
|
65
74
|
return typeof e?.open == "function" ? e : void 0;
|
|
66
|
-
},
|
|
75
|
+
}, m = () => {
|
|
67
76
|
throw c("unavailable", s.unavailable);
|
|
68
|
-
},
|
|
77
|
+
}, h = (e) => e === "blocked" ? "blocked" : e === "not-found" ? "ended" : "unavailable", g = (e) => {
|
|
69
78
|
if (e !== void 0 && e !== !1) return e === !0 ? a.default : typeof e != "number" || !Number.isInteger(e) ? null : e >= a.min && e <= a.max ? e : null;
|
|
70
|
-
},
|
|
71
|
-
let
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
79
|
+
}, _ = (e, t) => {
|
|
80
|
+
let n = t ? e?.guest : e;
|
|
81
|
+
return typeof n?.join == "function" ? n : void 0;
|
|
82
|
+
}, v = (e) => {
|
|
83
|
+
let t;
|
|
84
|
+
try {
|
|
85
|
+
t = JSON.stringify(e);
|
|
86
|
+
} catch {}
|
|
87
|
+
let n = t === void 0 ? void 0 : JSON.parse(t), r = typeof n == "object" && !!n && !Array.isArray(n) && typeof n.type == "string";
|
|
88
|
+
if (t === void 0 || !r || t.length > d) throw c("invalid", s.misfit);
|
|
89
|
+
return t;
|
|
90
|
+
}, y = (e) => {
|
|
91
|
+
let t;
|
|
92
|
+
try {
|
|
93
|
+
t = JSON.parse(JSON.stringify(e));
|
|
94
|
+
} catch {}
|
|
95
|
+
if (typeof t != "object" || !t || Array.isArray(t)) throw c("invalid", s.badSchema);
|
|
96
|
+
return t;
|
|
97
|
+
}, b = (e) => e?.schema === void 0 ? e : {
|
|
98
|
+
...e,
|
|
99
|
+
schema: y(e.schema)
|
|
100
|
+
}, x = (e) => {
|
|
101
|
+
if (e.schemas !== !0) throw c("unavailable", s.schemasUnavailable);
|
|
102
|
+
return e;
|
|
103
|
+
}, S = (e) => {
|
|
104
|
+
let t = e?.guest;
|
|
105
|
+
if (t !== void 0 && typeof t != "boolean") throw c("invalid", s.malformed);
|
|
106
|
+
return t === !0;
|
|
107
|
+
}, C = async (e, t) => {
|
|
108
|
+
let n = e.invite, a = e, o = 0, d = e.self, p = e.owner, m = e.claimed, b = e.mailbox, S = 0, C = await e.defaults().catch(() => u), w = e.schemas === !0 ? await Promise.resolve(e.schema()).catch(() => null) : null, T = 0, E = !1, D = /* @__PURE__ */ new Set(), O = /* @__PURE__ */ new Set(), k = i("room"), A = () => {}, j = () => {}, M = new Promise((e) => {
|
|
109
|
+
j = e;
|
|
110
|
+
}), N = (e) => {
|
|
111
|
+
let t = [...O];
|
|
112
|
+
O.clear();
|
|
76
113
|
for (let n of t) try {
|
|
77
114
|
n(e);
|
|
78
115
|
} catch {}
|
|
79
|
-
},
|
|
80
|
-
|
|
81
|
-
},
|
|
82
|
-
if (
|
|
116
|
+
}, P = (e) => {
|
|
117
|
+
E || (E = !0, A(), D.clear(), k(), N(c("closed", s.ended)), j({ reason: e }));
|
|
118
|
+
}, F = (e) => {
|
|
119
|
+
if (E) return;
|
|
83
120
|
let t = e;
|
|
84
|
-
if (t.type === "defaults" && (
|
|
85
|
-
|
|
121
|
+
if (t.type === "defaults" && (C = t.defaults), t.type === "schema" && (T += 1, w = t.schema), t.type === "message" || t.type === "edited") {
|
|
122
|
+
let e = {
|
|
123
|
+
...t.message,
|
|
124
|
+
envelope: t.message.envelope ?? null
|
|
125
|
+
};
|
|
126
|
+
t = t.type === "message" ? {
|
|
127
|
+
...t,
|
|
128
|
+
message: e
|
|
129
|
+
} : {
|
|
130
|
+
type: "edited",
|
|
131
|
+
message: e
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
if (t.type === "permissions" && t.id === d.id && (d = {
|
|
135
|
+
id: d.id,
|
|
86
136
|
permissions: t.permissions,
|
|
87
137
|
maxMessageBytes: t.maxMessageBytes
|
|
88
138
|
}), t.type === "claim") {
|
|
89
|
-
|
|
139
|
+
S += 1;
|
|
90
140
|
let e = t.claimed && t.mailbox !== !1;
|
|
91
141
|
t = {
|
|
92
142
|
type: "claim",
|
|
93
143
|
claimed: t.claimed,
|
|
94
144
|
owner: t.owner,
|
|
95
145
|
mailbox: e
|
|
96
|
-
},
|
|
146
|
+
}, m = t.claimed, p = t.owner, b = e ? f() : null;
|
|
97
147
|
}
|
|
98
|
-
for (let e of [...
|
|
148
|
+
for (let e of [...D]) try {
|
|
99
149
|
e(t);
|
|
100
150
|
} catch {}
|
|
101
|
-
},
|
|
102
|
-
Promise.resolve(e.on(
|
|
103
|
-
t ===
|
|
151
|
+
}, I = (e, t) => {
|
|
152
|
+
Promise.resolve(e.on(F)).catch(() => {}), Promise.resolve(e.closed).then((e) => {
|
|
153
|
+
t === o && P(e.reason);
|
|
104
154
|
}, () => {});
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
if (
|
|
111
|
-
if (
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
155
|
+
}, L = async (e, r) => {
|
|
156
|
+
let i = _(e, t);
|
|
157
|
+
if (!i) return P("unavailable");
|
|
158
|
+
let s = await i.join(n).catch(() => void 0);
|
|
159
|
+
if (E || r !== o) return;
|
|
160
|
+
if (!s) return P("unavailable");
|
|
161
|
+
if ("error" in s) return P(h(s.error));
|
|
162
|
+
if (s.self.id !== d.id) return Promise.resolve(s.leave()).catch(() => {}), P("unavailable");
|
|
163
|
+
a = s, d = s.self, p = s.owner, m = s.claimed, b = s.mailbox, I(s, r);
|
|
164
|
+
let c = await s.defaults().catch(() => void 0);
|
|
165
|
+
if (c && !E && r === o && (C = c), s.schemas !== !0) return;
|
|
166
|
+
let l = await Promise.resolve(s.schema()).catch(() => void 0);
|
|
167
|
+
l !== void 0 && !E && r === o && (w = l);
|
|
115
168
|
};
|
|
116
|
-
|
|
117
|
-
let n =
|
|
118
|
-
|
|
119
|
-
}),
|
|
120
|
-
let
|
|
121
|
-
if (
|
|
122
|
-
let t = () => {},
|
|
169
|
+
A = r((e, t) => {
|
|
170
|
+
let n = o;
|
|
171
|
+
o = t, !(E || n === 0 || n === t) && (N(c("unavailable", s.unavailable)), L(e.rooms, t));
|
|
172
|
+
}), I(e, o);
|
|
173
|
+
let R = async (e) => {
|
|
174
|
+
if (E) throw c("closed", s.ended);
|
|
175
|
+
let t = () => {}, n = new Promise((e, n) => {
|
|
123
176
|
t = n;
|
|
124
177
|
});
|
|
125
|
-
|
|
178
|
+
O.add(t);
|
|
126
179
|
try {
|
|
127
|
-
return await Promise.race([Promise.resolve(e(
|
|
180
|
+
return await Promise.race([Promise.resolve(e(a)), n]);
|
|
128
181
|
} catch (e) {
|
|
129
182
|
throw l(e) ? e : c("unavailable", s.unavailable);
|
|
130
183
|
} finally {
|
|
131
|
-
|
|
184
|
+
O.delete(t);
|
|
132
185
|
}
|
|
133
|
-
},
|
|
134
|
-
let t = await
|
|
186
|
+
}, z = async (e) => {
|
|
187
|
+
let t = await R(e);
|
|
135
188
|
if ("error" in t) throw c(t.error, t.message);
|
|
136
|
-
},
|
|
137
|
-
let t = await
|
|
189
|
+
}, B = async (e) => {
|
|
190
|
+
let t = await R(e);
|
|
138
191
|
if (typeof t == "object" && t && "error" in t) throw c(t.error, t.message);
|
|
139
192
|
return t;
|
|
140
193
|
};
|
|
@@ -142,36 +195,49 @@ var o = /* @__PURE__ */ e({
|
|
|
142
195
|
id: e.id,
|
|
143
196
|
name: e.name,
|
|
144
197
|
key: e.key,
|
|
145
|
-
invite:
|
|
198
|
+
invite: n,
|
|
146
199
|
get self() {
|
|
147
|
-
return
|
|
200
|
+
return d;
|
|
148
201
|
},
|
|
149
202
|
get owner() {
|
|
150
|
-
return
|
|
203
|
+
return p;
|
|
151
204
|
},
|
|
152
205
|
get claimed() {
|
|
153
|
-
return
|
|
206
|
+
return m;
|
|
154
207
|
},
|
|
155
208
|
get mailbox() {
|
|
156
|
-
return
|
|
209
|
+
return b;
|
|
210
|
+
},
|
|
211
|
+
defaults: () => C,
|
|
212
|
+
members: () => R((e) => e.members()),
|
|
213
|
+
schema: () => w,
|
|
214
|
+
send: async (e, t) => {
|
|
215
|
+
if (t === void 0) return z((t) => t.send(e));
|
|
216
|
+
let n = v(t);
|
|
217
|
+
return z((t) => x(t).send(e, n));
|
|
218
|
+
},
|
|
219
|
+
edit: async (e, t, n) => {
|
|
220
|
+
if (n === void 0) return z((n) => n.edit(e, t));
|
|
221
|
+
let r = v(n);
|
|
222
|
+
return z((n) => x(n).edit(e, t, r));
|
|
223
|
+
},
|
|
224
|
+
setSchema: async (e) => {
|
|
225
|
+
let t = y(e), n = T;
|
|
226
|
+
await z((e) => x(e).setSchema(t)), T === n && (w = t);
|
|
157
227
|
},
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
revoke: (e, t) => M((n) => n.revoke(e, t)),
|
|
168
|
-
remove: (e) => M((t) => t.remove(e)),
|
|
169
|
-
block: (e) => M((t) => t.block(e)),
|
|
170
|
-
unblock: (e) => M((t) => t.unblock(e)),
|
|
228
|
+
delete: (e, t) => z((n) => n.delete(e, t)),
|
|
229
|
+
backlog: (e, t) => B((n) => n.backlog(e, t)),
|
|
230
|
+
setDefault: (e, t) => z((n) => n.setDefault(e, t)),
|
|
231
|
+
limit: (e, t) => z((n) => n.limit(e, t)),
|
|
232
|
+
grant: (e, t) => z((n) => n.grant(e, t)),
|
|
233
|
+
revoke: (e, t) => z((n) => n.revoke(e, t)),
|
|
234
|
+
remove: (e) => z((t) => t.remove(e)),
|
|
235
|
+
block: (e) => z((t) => t.block(e)),
|
|
236
|
+
unblock: (e) => z((t) => t.unblock(e)),
|
|
171
237
|
claim: async (e) => {
|
|
172
238
|
let t = e?.description;
|
|
173
239
|
if (t !== void 0 && typeof t != "string") throw c("invalid", s.badDescription);
|
|
174
|
-
let n =
|
|
240
|
+
let n = g(e?.temporary);
|
|
175
241
|
if (n === null) throw c("invalid", s.badTemporary);
|
|
176
242
|
let r = e?.mailbox;
|
|
177
243
|
if (r !== void 0 && typeof r != "boolean") throw c("invalid", s.malformed);
|
|
@@ -180,7 +246,7 @@ var o = /* @__PURE__ */ e({
|
|
|
180
246
|
...n === void 0 ? {} : { temporary: n },
|
|
181
247
|
...r === void 0 ? {} : { mailbox: r }
|
|
182
248
|
};
|
|
183
|
-
return Object.keys(i).length === 0 ?
|
|
249
|
+
return Object.keys(i).length === 0 ? z((e) => e.claim()) : z((e) => {
|
|
184
250
|
if (n !== void 0 && e.temporaryClaims !== !0) throw c("unavailable", s.temporaryUnavailable);
|
|
185
251
|
if (r === !1 && e.mailboxSwitch !== !0) throw c("unavailable", s.mailboxUnavailable);
|
|
186
252
|
return e.claim(i);
|
|
@@ -188,41 +254,48 @@ var o = /* @__PURE__ */ e({
|
|
|
188
254
|
},
|
|
189
255
|
setMailbox: async (e) => {
|
|
190
256
|
if (typeof e != "boolean") throw c("invalid", s.malformed);
|
|
191
|
-
let t =
|
|
192
|
-
await
|
|
257
|
+
let t = S;
|
|
258
|
+
await z((t) => {
|
|
193
259
|
if (t.mailboxSwitch !== !0) throw c("unavailable", s.mailboxUnavailable);
|
|
194
260
|
return t.setMailbox(e);
|
|
195
|
-
}),
|
|
261
|
+
}), S === t && (e ? b === null && (b = f()) : b = null);
|
|
196
262
|
},
|
|
197
|
-
release: () =>
|
|
263
|
+
release: () => z((e) => e.release()),
|
|
198
264
|
usage: async () => {
|
|
199
|
-
let e = await
|
|
200
|
-
return
|
|
265
|
+
let e = await B((e) => e.usage());
|
|
266
|
+
return b = e, e;
|
|
201
267
|
},
|
|
202
|
-
on: async (e) =>
|
|
203
|
-
|
|
268
|
+
on: async (e) => E ? () => {} : (D.add(e), () => {
|
|
269
|
+
D.delete(e);
|
|
204
270
|
}),
|
|
205
271
|
leave: async () => {
|
|
206
|
-
await Promise.resolve(
|
|
272
|
+
await Promise.resolve(a.leave()).catch(() => {}), P("left");
|
|
207
273
|
},
|
|
208
|
-
closed:
|
|
274
|
+
closed: M
|
|
209
275
|
};
|
|
210
|
-
},
|
|
211
|
-
let e = await
|
|
276
|
+
}, w = async () => {
|
|
277
|
+
let e = await p();
|
|
212
278
|
return e ? e.available().catch(() => !1) : !1;
|
|
213
|
-
},
|
|
214
|
-
let
|
|
215
|
-
if (!
|
|
216
|
-
let
|
|
217
|
-
if (
|
|
218
|
-
|
|
219
|
-
|
|
279
|
+
}, T = async (e, t, n) => {
|
|
280
|
+
let r = await p();
|
|
281
|
+
if (!r) throw c("unavailable", s.unavailable);
|
|
282
|
+
let i = _(r, e);
|
|
283
|
+
if (!i) throw c("unavailable", s.guestUnavailable);
|
|
284
|
+
let a = await n(i).catch(m);
|
|
285
|
+
if ("error" in a) throw c(a.error, a.message);
|
|
286
|
+
if (t?.schema !== void 0 && a.schemas !== !0) throw await Promise.resolve(a.leave()).catch(() => {}), c("unavailable", s.schemasUnavailable);
|
|
287
|
+
return C(a, e);
|
|
288
|
+
}, E = async (e, t) => {
|
|
220
289
|
if (typeof e != "string" || e.length === 0 || e.length > 72) throw c("invalid", s.badName);
|
|
221
|
-
|
|
222
|
-
|
|
290
|
+
let n = S(t), r = b(t);
|
|
291
|
+
return T(n, r, (t) => t.open(e, r));
|
|
292
|
+
}, D = async (e) => {
|
|
293
|
+
let t = S(e), n = b(e);
|
|
294
|
+
return T(t, n, (e) => e.create(n));
|
|
295
|
+
}, O = async (e, t) => {
|
|
223
296
|
let n = typeof e == "string" ? e.indexOf(".") : -1;
|
|
224
297
|
if (n <= 0 || n === e.length - 1) throw c("invalid", s.inviteNoKey);
|
|
225
|
-
return
|
|
298
|
+
return T(S(t), void 0, (n) => n.join(e, t));
|
|
226
299
|
};
|
|
227
300
|
//#endregion
|
|
228
|
-
export {
|
|
301
|
+
export { w as available, D as create, O as join, E as open, o as t };
|
package/storage.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-Csb5b8dE.cjs"),n=require("./contract.cjs"),r=require("./account-generation-DOuApHq5.cjs"),i=require("./account-storage-CL0wLuQw.cjs");var a=e.t({available:()=>v,delete:()=>C,get:()=>x,list:()=>S,put:()=>y}),o=new Map(Object.values(n.STORAGE_REFUSALS).map(({code:e,message:t})=>[t,e])),s=new Set(o.values()),c=(e,t)=>Object.assign(Error(t),{code:e}),l=e=>c(n.STORAGE_REFUSALS[e].code,n.STORAGE_REFUSALS[e].message),u=e=>e instanceof Error&&s.has(e.code),d=e=>{if(u(e))return e;let t=e instanceof Error?e.message:``,n=o.get(t);return n?c(n,t):l(`unavailable`)},f=async()=>{if(!t.l)return;let e=(await t.s(`storage`).catch(()=>void 0))?.storage;return typeof e?.put==`function`?e:void 0},p=()=>{throw l(`unavailable`)},m=e=>typeof e==`object`&&!!e&&typeof e.error==`string`&&typeof e.message==`string`,h=(e,t,n)=>{throw e.error===`aborted`?t?.reason??new DOMException(`The operation was aborted.`,`AbortError`):(e.error===`account-changed`&&n&&r.r(n.generation),s.has(e.error)?c(e.error,e.message):l(`unavailable`))},g=async e=>{try{return await i.m(e)}catch(e){throw i.l(e)?l(`accountChanged`):e instanceof Error&&/not connected|not signed in/i.test(e.message)?l(`needsAccount`):l(`unavailable`)}},_=(e,t)=>(e.catch(()=>{}),t?Promise.race([e,new Promise((e,n)=>t.addEventListener(`abort`,()=>n(t.reason),{once:!0}))]):e),v=async()=>{let e=await f();return e?Promise.resolve(e.available()).catch(()=>!1):!1},y=async(e,t={})=>{let n=i.s(),{signal:r,onProgress:a,key:o}=t;r?.throwIfAborted();let s=typeof Blob<`u`&&e instanceof Blob,c=typeof ReadableStream<`u`&&e instanceof ReadableStream;if(!s&&!c)throw l(`notAFile`);let u=s?e.size:t.size;if(typeof u!=`number`||!Number.isSafeInteger(u)||u<0||s&&t.size!==void 0&&t.size!==u)throw l(`badSize`);let d=await f();if(!d)throw l(`unavailable`);let v=await g(n);r?.throwIfAborted();let y=await _(Promise.resolve(d.put(e,{size:u,...o===void 0?{}:{key:o},accountPin:v,...r?{signal:r}:{},...typeof a==`function`?{onProgress:e=>{try{a(e)}catch{}}}:{}})).catch(p),r);return m(y)?h(y,r,n):y},b=(e,t,n)=>{let r=(t,n)=>{if(t===void 0)return n;let r=Math.trunc(Number.isFinite(t)?t:t>0?e:-e);return r<0?Math.max(e+r,0):Math.min(r,e)},i=r(t,0);return{from:i,to:Math.max(i,r(n,e))}},x=async(e,n,r={})=>{if(typeof e!=`string`)throw l(`badUrl`);if(typeof n!=`string`)throw l(`badKey`);let{signal:i}=r;i?.throwIfAborted();let a=async()=>{let r=await f();if(!r)throw l(`unavailable`);let a=t.c()?.epoch,o=await _(Promise.resolve(r.get(e,n,i?{signal:i}:void 0)).catch(p),i);return m(o)?h(o,i):{handle:o,epoch:a}},o=await a(),s=async()=>{let e=t.c()?.epoch;return o.epoch!==void 0&&e!==void 0&&e!==o.epoch&&(o=await a()),o.handle},c=(e,t)=>{let n;return new ReadableStream({pull:async r=>{try{if(!n){let r=await s(),i=await Promise.resolve(r.read(e,t)).catch(p);if(m(i))return h(i);n=i.getReader()}let{value:i,done:a}=await n.read();a?r.close():r.enqueue(i)}catch(e){throw d(e)}},cancel:e=>n?.cancel(e)},{highWaterMark:0})},u=(e,t)=>({size:t-e,stream:()=>c(e,t),arrayBuffer:async()=>{let n=new Uint8Array(t-e),r=c(e,t).getReader(),i=0;for(;;){let{value:e,done:t}=await r.read();if(t)break;n.set(e,i),i+=e.length}return n.buffer},slice:(n,r)=>{let i=b(t-e,n,r);return u(e+i.from,e+i.to)}});return u(0,o.handle.size)},S=async(e={})=>{let t=i.s(),n=await f();if(!n)throw l(`unavailable`);let r=await g(t),{limit:a,cursor:o}=e,s=await Promise.resolve(n.list({accountPin:r,...a===void 0?{}:{limit:a},...o===void 0?{}:{cursor:o}})).catch(p);return m(s)?h(s,void 0,t):s},C=async e=>{let t=i.s();if(typeof e!=`string`)throw l(`badUrl`);let n=await f();if(!n)throw l(`unavailable`);let r=await g(t),a=await Promise.resolve(n.delete(e,{accountPin:r})).catch(p);m(a)&&h(a,void 0,t)};exports.available=v,exports.delete=C,exports.get=x,exports.list=S,exports.put=y,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
package/storage.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dt as StorageProgress, Mt as StoredObject, Nt as StoredPage, Ot as StoragePutOptions, Tt as StorageErrorCode } from "./contract-DFycgFJK.js";
|
|
2
2
|
declare namespace storage_d_exports {
|
|
3
3
|
export { StorageError, StorageErrorCode, StorageProgress, StoragePutOptions, StoredBlob, StoredObject, StoredPage, available, remove as delete, get, list, put };
|
|
4
4
|
}
|
package/storage.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import { c as t, l as n, s as r } from "./api-
|
|
2
|
+
import { c as t, l as n, s as r } from "./api-BYtMzj8u.js";
|
|
3
3
|
import { STORAGE_REFUSALS as i } from "./contract.js";
|
|
4
|
-
import { r as a } from "./account-generation-
|
|
5
|
-
import { l as o, m as s, s as c } from "./account-storage-
|
|
4
|
+
import { r as a } from "./account-generation-CTB1J33G.js";
|
|
5
|
+
import { l as o, m as s, s as c } from "./account-storage-D1RiskV6.js";
|
|
6
6
|
//#region src/storage.ts
|
|
7
7
|
var l = /* @__PURE__ */ e({
|
|
8
8
|
available: () => S,
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
const e=require("./api-6wTec7WK.cjs");var t=0,n=new Set,r=2e3,i=null,a=e=>{e?.switched!==!1&&(t+=1,i&&=(clearTimeout(i.timer),null));for(let e of[...n])try{e()}catch{}},o=!1,s=0,c=()=>{let t=e.c();t&&s!==t.epoch&&(s=t.epoch,Promise.resolve(t.remote.account.onChange(a)).catch(()=>{s===t.epoch&&(s=0)}))},l=()=>{!o&&e.l&&(o=!0,e.u(c))},u=()=>t,d=e=>(n.add(e),l(),()=>{n.delete(e)}),f=e=>{if(e!==t||i?.generation===e)return;let n=setTimeout(()=>{i?.timer===n&&(i=null,t===e&&a({switched:!0}))},r);i={generation:e,timer:n}};Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return f}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}});
|