@fkn/lib 0.9.29 → 0.9.31
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/{api-CxrIIOW8.d.ts → api-LKxHamsI.d.ts} +471 -3
- 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.d.ts +2 -2
- package/cloud/net.d.ts +1 -1
- package/{cloud-BpruQ4I2.d.ts → cloud-BYw0XBF4.d.ts} +3 -3
- package/cloud.d.ts +4 -4
- package/{contract-DLyjkumA.d.ts → contract-CSdeTq_Y.d.ts} +72 -8
- package/contract.d.ts +2 -2
- package/dgram.d.ts +2 -2
- package/dns.d.ts +1 -1
- package/{fs-CBVaShOR.d.ts → fs-CYcErwc4.d.ts} +1 -1
- package/http.d.ts +1 -1
- package/index.d.ts +2 -2
- package/{messages-DvpKMTsY.d.ts → messages-C66ghz_A.d.ts} +3 -1
- package/messages.cjs +1 -1
- package/messages.d.ts +2 -2
- package/messages.js +2 -2
- package/{net-DOkodxE3.d.ts → net-DtRM2eKo.d.ts} +2 -2
- package/net.d.ts +1 -1
- package/package.json +1 -1
- package/packages.d.ts +1 -1
- package/{proxy-YNFaF0dC.d.ts → proxy-AooDS--C.d.ts} +2 -2
- package/rooms.cjs +1 -1
- package/rooms.d.ts +33 -9
- package/rooms.js +117 -72
package/rooms.js
CHANGED
|
@@ -3,18 +3,24 @@ import { c as t, l as n, o as r } from "./api-DLvscoll.js";
|
|
|
3
3
|
import { t as i } from "./busy-B189uX--.js";
|
|
4
4
|
//#region src/rooms.ts
|
|
5
5
|
var a = /* @__PURE__ */ e({
|
|
6
|
-
available: () =>
|
|
7
|
-
create: () =>
|
|
8
|
-
join: () =>
|
|
6
|
+
available: () => m,
|
|
7
|
+
create: () => g,
|
|
8
|
+
join: () => _,
|
|
9
|
+
open: () => h
|
|
9
10
|
}), o = {
|
|
10
|
-
noSuchRoom: "rooms: no such room",
|
|
11
11
|
wrongKey: "rooms: wrong room key",
|
|
12
12
|
inviteNoKey: "rooms: the invite carries no key",
|
|
13
|
+
badName: "rooms: the name is not one a room can have",
|
|
14
|
+
badKeyOption: "rooms: the key is not 32 bytes base64url",
|
|
13
15
|
noSuchMember: "rooms: no such member",
|
|
16
|
+
noSuchMessage: "rooms: no such message",
|
|
14
17
|
roomFull: "rooms: the room is full",
|
|
15
|
-
tooManyRooms: "rooms: too many rooms",
|
|
16
18
|
tooManyConnections: "rooms: too many connections",
|
|
17
19
|
tooManyBlocks: "rooms: too many blocks",
|
|
20
|
+
tooManyClaims: "rooms: too many claims",
|
|
21
|
+
mailboxFull: "rooms: the mailbox is full",
|
|
22
|
+
outOfStorage: "rooms: the owner is out of storage",
|
|
23
|
+
outOfQuota: "rooms: out of daily bandwidth",
|
|
18
24
|
blocked: "rooms: you are blocked from this room",
|
|
19
25
|
cannotSend: "rooms: you cannot send here",
|
|
20
26
|
permissionDenied: "rooms: permission denied",
|
|
@@ -22,121 +28,160 @@ var a = /* @__PURE__ */ e({
|
|
|
22
28
|
ownerNotRemovable: "rooms: the owner cannot be removed",
|
|
23
29
|
ownerKeepsEvery: "rooms: the owner keeps every permission",
|
|
24
30
|
removeYourself: "rooms: you cannot remove yourself",
|
|
31
|
+
needsAccount: "rooms: claiming needs an account",
|
|
32
|
+
needsPremium: "rooms: claiming needs premium",
|
|
33
|
+
nameClaimed: "rooms: the name is claimed",
|
|
34
|
+
notClaimed: "rooms: the room is not claimed",
|
|
35
|
+
noMailbox: "rooms: the room keeps no messages",
|
|
36
|
+
badLimit: "rooms: the limit is out of range",
|
|
25
37
|
tooFast: "rooms: sending too fast",
|
|
26
38
|
tooLarge: "rooms: the message is too large",
|
|
27
39
|
unavailable: "rooms: rooms are unavailable",
|
|
28
40
|
notEnabled: "rooms: rooms are not available",
|
|
29
41
|
alreadyJoined: "rooms: already joined",
|
|
42
|
+
notJoined: "rooms: not joined",
|
|
30
43
|
malformed: "rooms: malformed frame",
|
|
31
44
|
ended: "rooms: the room has ended"
|
|
32
|
-
}, s = (e, t) => Object.assign(Error(t), { code: e }), c = (e) => e instanceof Error && typeof e.code == "string", l =
|
|
45
|
+
}, s = (e, t) => Object.assign(Error(t), { code: e }), c = (e) => e instanceof Error && typeof e.code == "string", l = {
|
|
46
|
+
send: !0,
|
|
47
|
+
receive: !0,
|
|
48
|
+
maxMessageBytes: 262144
|
|
49
|
+
}, u = async () => {
|
|
33
50
|
if (!t) return;
|
|
34
51
|
let e = (await r("a room").catch(() => void 0))?.rooms;
|
|
35
|
-
return typeof e?.
|
|
36
|
-
},
|
|
52
|
+
return typeof e?.open == "function" ? e : void 0;
|
|
53
|
+
}, d = () => {
|
|
37
54
|
throw s("unavailable", o.unavailable);
|
|
38
|
-
},
|
|
39
|
-
let t = e.invite, r = e, a = 0,
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}), y = (e) => {
|
|
45
|
-
let t = [...m];
|
|
46
|
-
m.clear();
|
|
55
|
+
}, f = (e) => e === "blocked" ? "blocked" : e === "not-found" ? "ended" : "unavailable", p = async (e) => {
|
|
56
|
+
let t = e.invite, r = e, a = 0, u = e.self, d = e.owner, p = e.claimed, m = e.mailbox, h = await e.defaults().catch(() => l), g = !1, _ = /* @__PURE__ */ new Set(), v = /* @__PURE__ */ new Set(), y = i("room"), b = () => {}, x = () => {}, S = new Promise((e) => {
|
|
57
|
+
x = e;
|
|
58
|
+
}), C = (e) => {
|
|
59
|
+
let t = [...v];
|
|
60
|
+
v.clear();
|
|
47
61
|
for (let n of t) try {
|
|
48
62
|
n(e);
|
|
49
63
|
} catch {}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
if (!
|
|
54
|
-
e.type === "defaults" && (
|
|
55
|
-
id:
|
|
56
|
-
permissions: e.permissions
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
}, w = (e) => {
|
|
65
|
+
g || (g = !0, b(), _.clear(), y(), C(s("closed", o.ended)), x({ reason: e }));
|
|
66
|
+
}, T = (e) => {
|
|
67
|
+
if (!g) {
|
|
68
|
+
e.type === "defaults" && (h = e.defaults), e.type === "permissions" && e.id === u.id && (u = {
|
|
69
|
+
id: u.id,
|
|
70
|
+
permissions: e.permissions,
|
|
71
|
+
maxMessageBytes: e.maxMessageBytes
|
|
72
|
+
}), e.type === "claim" && (p = e.claimed, d = e.owner, p || (m = null));
|
|
73
|
+
for (let t of [..._]) try {
|
|
59
74
|
t(e);
|
|
60
75
|
} catch {}
|
|
61
76
|
}
|
|
62
|
-
},
|
|
63
|
-
Promise.resolve(e.on(
|
|
64
|
-
t === a &&
|
|
77
|
+
}, E = (e, t) => {
|
|
78
|
+
Promise.resolve(e.on(T)).catch(() => {}), Promise.resolve(e.closed).then((e) => {
|
|
79
|
+
t === a && w(e.reason);
|
|
65
80
|
}, () => {});
|
|
66
|
-
},
|
|
67
|
-
if (typeof e?.join != "function") return
|
|
81
|
+
}, D = async (e, n) => {
|
|
82
|
+
if (typeof e?.join != "function") return w("unavailable");
|
|
68
83
|
let i = await e.join(t).catch(() => void 0);
|
|
69
|
-
if (
|
|
70
|
-
if (!i) return
|
|
71
|
-
if ("error" in i) return
|
|
72
|
-
if (i.self.id !==
|
|
73
|
-
r = i,
|
|
84
|
+
if (g || n !== a) return;
|
|
85
|
+
if (!i) return w("unavailable");
|
|
86
|
+
if ("error" in i) return w(f(i.error));
|
|
87
|
+
if (i.self.id !== u.id) return Promise.resolve(i.leave()).catch(() => {}), w("unavailable");
|
|
88
|
+
r = i, u = i.self, d = i.owner, p = i.claimed, m = i.mailbox, E(i, n);
|
|
74
89
|
let o = await i.defaults().catch(() => void 0);
|
|
75
|
-
o && !
|
|
90
|
+
o && !g && n === a && (h = o);
|
|
76
91
|
};
|
|
77
|
-
|
|
92
|
+
b = n((e, t) => {
|
|
78
93
|
let n = a;
|
|
79
|
-
a = t, !(
|
|
80
|
-
}),
|
|
81
|
-
let
|
|
82
|
-
if (
|
|
94
|
+
a = t, !(g || n === 0 || n === t) && (C(s("unavailable", o.unavailable)), D(e.rooms, t));
|
|
95
|
+
}), E(e, a);
|
|
96
|
+
let O = async (e) => {
|
|
97
|
+
if (g) throw s("closed", o.ended);
|
|
83
98
|
let t = () => {}, n = new Promise((e, n) => {
|
|
84
99
|
t = n;
|
|
85
100
|
});
|
|
86
|
-
|
|
101
|
+
v.add(t);
|
|
87
102
|
try {
|
|
88
103
|
return await Promise.race([Promise.resolve(e(r)), n]);
|
|
89
104
|
} catch (e) {
|
|
90
105
|
throw c(e) ? e : s("unavailable", o.unavailable);
|
|
91
106
|
} finally {
|
|
92
|
-
|
|
107
|
+
v.delete(t);
|
|
93
108
|
}
|
|
94
|
-
},
|
|
95
|
-
let t = await
|
|
109
|
+
}, k = async (e) => {
|
|
110
|
+
let t = await O(e);
|
|
96
111
|
if ("error" in t) throw s(t.error, t.message);
|
|
112
|
+
}, A = async (e) => {
|
|
113
|
+
let t = await O(e);
|
|
114
|
+
if (typeof t == "object" && t && "error" in t) throw s(t.error, t.message);
|
|
115
|
+
return t;
|
|
97
116
|
};
|
|
98
117
|
return {
|
|
99
118
|
id: e.id,
|
|
119
|
+
name: e.name,
|
|
100
120
|
key: e.key,
|
|
101
121
|
invite: t,
|
|
102
122
|
get self() {
|
|
103
|
-
return
|
|
123
|
+
return u;
|
|
104
124
|
},
|
|
105
|
-
owner
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
get owner() {
|
|
126
|
+
return d;
|
|
127
|
+
},
|
|
128
|
+
get claimed() {
|
|
129
|
+
return p;
|
|
130
|
+
},
|
|
131
|
+
get mailbox() {
|
|
132
|
+
return m;
|
|
133
|
+
},
|
|
134
|
+
defaults: () => h,
|
|
135
|
+
members: () => O((e) => e.members()),
|
|
136
|
+
send: (e) => k((t) => t.send(e)),
|
|
137
|
+
edit: (e, t) => k((n) => n.edit(e, t)),
|
|
138
|
+
delete: (e, t) => k((n) => n.delete(e, t)),
|
|
139
|
+
backlog: (e, t) => A((n) => n.backlog(e, t)),
|
|
140
|
+
setDefault: (e, t) => k((n) => n.setDefault(e, t)),
|
|
141
|
+
limit: (e, t) => k((n) => n.limit(e, t)),
|
|
142
|
+
grant: (e, t) => k((n) => n.grant(e, t)),
|
|
143
|
+
revoke: (e, t) => k((n) => n.revoke(e, t)),
|
|
144
|
+
remove: (e) => k((t) => t.remove(e)),
|
|
145
|
+
block: (e) => k((t) => t.block(e)),
|
|
146
|
+
unblock: (e) => k((t) => t.unblock(e)),
|
|
147
|
+
claim: () => k((e) => e.claim()),
|
|
148
|
+
release: () => k((e) => e.release()),
|
|
149
|
+
usage: async () => {
|
|
150
|
+
let e = await A((e) => e.usage());
|
|
151
|
+
return m = e, e;
|
|
152
|
+
},
|
|
153
|
+
on: async (e) => g ? () => {} : (_.add(e), () => {
|
|
154
|
+
_.delete(e);
|
|
117
155
|
}),
|
|
118
156
|
leave: async () => {
|
|
119
|
-
await Promise.resolve(r.leave()).catch(() => {}),
|
|
157
|
+
await Promise.resolve(r.leave()).catch(() => {}), w("left");
|
|
120
158
|
},
|
|
121
|
-
closed:
|
|
159
|
+
closed: S
|
|
122
160
|
};
|
|
123
|
-
},
|
|
124
|
-
let e = await
|
|
161
|
+
}, m = async () => {
|
|
162
|
+
let e = await u();
|
|
125
163
|
return e ? e.available().catch(() => !1) : !1;
|
|
126
|
-
},
|
|
127
|
-
|
|
164
|
+
}, h = async (e, t) => {
|
|
165
|
+
if (typeof e != "string" || e.length === 0 || e.length > 72) throw s("invalid", o.badName);
|
|
166
|
+
let n = await u();
|
|
167
|
+
if (!n) throw s("unavailable", o.unavailable);
|
|
168
|
+
let r = await n.open(e, t).catch(d);
|
|
169
|
+
if ("error" in r) throw s(r.error, r.message);
|
|
170
|
+
return p(r);
|
|
171
|
+
}, g = async (e) => {
|
|
172
|
+
let t = await u();
|
|
128
173
|
if (!t) throw s("unavailable", o.unavailable);
|
|
129
|
-
let n = await t.create(e).catch(
|
|
174
|
+
let n = await t.create(e).catch(d);
|
|
130
175
|
if ("error" in n) throw s(n.error, n.message);
|
|
131
|
-
return
|
|
132
|
-
},
|
|
176
|
+
return p(n);
|
|
177
|
+
}, _ = async (e, t) => {
|
|
133
178
|
let n = typeof e == "string" ? e.indexOf(".") : -1;
|
|
134
179
|
if (n <= 0 || n === e.length - 1) throw s("invalid", o.inviteNoKey);
|
|
135
|
-
let r = await
|
|
180
|
+
let r = await u();
|
|
136
181
|
if (!r) throw s("unavailable", o.unavailable);
|
|
137
|
-
let i = await r.join(e, t).catch(
|
|
182
|
+
let i = await r.join(e, t).catch(d);
|
|
138
183
|
if ("error" in i) throw s(i.error, i.message);
|
|
139
|
-
return
|
|
184
|
+
return p(i);
|
|
140
185
|
};
|
|
141
186
|
//#endregion
|
|
142
|
-
export {
|
|
187
|
+
export { m as available, g as create, _ as join, h as open, a as t };
|