@fkn/lib 0.9.48 → 0.9.49

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.
Files changed (49) hide show
  1. package/{storage-C6F9SnDM.js → account-storage-C31d68BN.js} +2 -2
  2. package/{storage-DmRIhg1P.cjs → account-storage-C6hcXjG0.cjs} +1 -1
  3. package/{storage-B_mXNAdB.d.ts → account-storage-DHl6bXdb.d.ts} +2 -2
  4. package/{api-Cpi-qz1j.d.ts → api-wnOQJEK6.d.ts} +34 -42
  5. package/api.d.ts +2 -2
  6. package/cloud/dns.d.ts +1 -1
  7. package/cloud/fetch.d.ts +1 -1
  8. package/cloud/fs/promises.d.ts +1 -1
  9. package/cloud/fs.cjs +1 -1
  10. package/cloud/fs.d.ts +3 -3
  11. package/cloud/fs.js +12 -12
  12. package/cloud/net.d.ts +1 -1
  13. package/{cloud-DK3DtdsU.d.ts → cloud-CWHjH89l.d.ts} +3 -3
  14. package/cloud.d.ts +4 -4
  15. package/{contract-XlEPwc7b.d.ts → contract-DGuGXxKd.d.ts} +119 -82
  16. package/contract.cjs +1 -1
  17. package/contract.d.ts +2 -2
  18. package/contract.js +69 -3
  19. package/dgram.d.ts +2 -2
  20. package/dns.d.ts +1 -1
  21. package/fs/promises.cjs +1 -1
  22. package/fs/promises.d.ts +1 -1
  23. package/fs/promises.js +1 -1
  24. package/{fs-lKZe5xIo.d.ts → fs-BZv2djbS.d.ts} +2 -2
  25. package/{fs-BY0Csn2V.js → fs-ClnOPmRF.js} +39 -39
  26. package/fs-zERmcLRS.cjs +1 -0
  27. package/fs.cjs +1 -1
  28. package/fs.d.ts +3 -3
  29. package/fs.js +2 -2
  30. package/http.d.ts +1 -1
  31. package/{index-D9x6A-Gx.d.ts → index-DawD_N1P.d.ts} +2 -2
  32. package/index.cjs +1 -1
  33. package/index.d.ts +5 -6
  34. package/index.js +39 -40
  35. package/{messages-d7pvCXPn.d.ts → messages-AdPfdoLV.d.ts} +1 -1
  36. package/messages.d.ts +1 -1
  37. package/{net-C2Yz0job.d.ts → net-C2sulnNU.d.ts} +2 -2
  38. package/net.d.ts +1 -1
  39. package/package.json +5 -5
  40. package/packages.d.ts +1 -1
  41. package/{proxy-BZ-YFeXe.d.ts → proxy-MVuD49E2.d.ts} +2 -2
  42. package/rooms.d.ts +1 -1
  43. package/storage.cjs +1 -0
  44. package/storage.d.ts +69 -0
  45. package/storage.js +137 -0
  46. package/fs-DnF1cQuE.cjs +0 -1
  47. package/links.cjs +0 -1
  48. package/links.d.ts +0 -65
  49. package/links.js +0 -187
package/links.js DELETED
@@ -1,187 +0,0 @@
1
- import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
2
- import { c as t, l as n, s as r } from "./api-ySazPAwN.js";
3
- import { LINK_EXPIRES_MS as i } from "./contract.js";
4
- import { r as a } from "./account-generation-hUekEHGW.js";
5
- import { c as o, o as s, p as c } from "./storage-C6F9SnDM.js";
6
- //#region src/links.ts
7
- var l = /* @__PURE__ */ e({
8
- LINK_EXPIRES_MS: () => i,
9
- available: () => x,
10
- create: () => S,
11
- list: () => T,
12
- open: () => w,
13
- revoke: () => E
14
- }), u = {
15
- notALink: "links: the link is not one fkn.app made",
16
- badExpiry: "links: the expiry is not one a link can carry",
17
- notAFile: "links: the file is not a Blob or a ReadableStream",
18
- badSize: "links: a stream needs the size it will deliver, a whole number of bytes",
19
- badName: "links: the name or type is not one a link can carry",
20
- tooLarge: "links: the file is too large for a link",
21
- shortStream: "links: the stream did not deliver the size it declared",
22
- badKey: "links: the key is not 32 bytes base64url",
23
- keyTaken: "links: the key already names a link",
24
- gone: "links: the link is no longer available",
25
- integrity: "links: the file does not match its link",
26
- needsAccount: "links: making a link needs an account",
27
- notCreator: "links: only the app that made the link can revoke it",
28
- quota: "links: storage quota exceeded",
29
- tooMany: "links: too many links",
30
- tooManyThisHour: "links: too many links made this hour, try again later",
31
- rateLimited: "links: this link is opened too often, try again later",
32
- accountChanged: "links: the signed-in account changed",
33
- unavailable: "links: links are unavailable"
34
- }, d = /* @__PURE__ */ new Map([
35
- [u.notALink, "invalid"],
36
- [u.badExpiry, "invalid"],
37
- [u.notAFile, "invalid"],
38
- [u.badSize, "invalid"],
39
- [u.badName, "invalid"],
40
- [u.tooLarge, "invalid"],
41
- [u.shortStream, "invalid"],
42
- [u.badKey, "invalid"],
43
- [u.keyTaken, "invalid"],
44
- [u.gone, "not-found"],
45
- [u.integrity, "integrity"],
46
- [u.needsAccount, "denied"],
47
- [u.notCreator, "denied"],
48
- [u.quota, "quota"],
49
- [u.tooMany, "too-many"],
50
- [u.tooManyThisHour, "too-many"],
51
- [u.rateLimited, "rate-limited"],
52
- [u.accountChanged, "account-changed"],
53
- [u.unavailable, "unavailable"]
54
- ]), f = new Set(d.values()), p = (e, t) => Object.assign(Error(t), { code: e }), m = (e) => e instanceof Error && f.has(e.code), h = (e) => {
55
- if (m(e)) return e;
56
- let t = e instanceof Error ? e.message : "", n = d.get(t);
57
- return n ? p(n, t) : p("unavailable", u.unavailable);
58
- }, g = async () => {
59
- if (!n) return;
60
- let e = (await r("a link").catch(() => void 0))?.links;
61
- return typeof e?.create == "function" ? e : void 0;
62
- }, _ = () => {
63
- throw p("unavailable", u.unavailable);
64
- }, v = (e) => typeof e == "object" && !!e && typeof e.error == "string" && typeof e.message == "string", y = (e, t, n) => {
65
- throw e.error === "aborted" ? t?.reason ?? new DOMException("The operation was aborted.", "AbortError") : (e.error === "account-changed" && n && a(n.generation), f.has(e.error) ? p(e.error, e.message) : p("unavailable", u.unavailable));
66
- }, b = async (e) => {
67
- try {
68
- return await c(e);
69
- } catch (e) {
70
- throw o(e) ? p("account-changed", u.accountChanged) : e instanceof Error && /not connected|not signed in/i.test(e.message) ? p("denied", u.needsAccount) : p("unavailable", u.unavailable);
71
- }
72
- }, x = async () => {
73
- let e = await g();
74
- return e ? Promise.resolve(e.available()).catch(() => !1) : !1;
75
- }, S = async (e, t = {}) => {
76
- let n = s(), r = Date.now(), { signal: a, onProgress: o, key: c } = t;
77
- a?.throwIfAborted();
78
- let l = typeof Blob < "u" && e instanceof Blob, d = typeof ReadableStream < "u" && e instanceof ReadableStream;
79
- if (!l && !d) throw p("invalid", u.notAFile);
80
- let f = l ? e.size : t.size;
81
- if (typeof f != "number" || !Number.isSafeInteger(f) || f < 0 || l && t.size !== void 0 && t.size !== f) throw p("invalid", u.badSize);
82
- let m = t.name ?? (typeof File < "u" && e instanceof File ? e.name : ""), h = t.type ?? (l ? e.type : "");
83
- if (typeof m != "string" || typeof h != "string") throw p("invalid", u.badName);
84
- let x = typeof File < "u" && e instanceof File ? e.lastModified : r, S = t.expires, C;
85
- if (S != null && (typeof S != "number" || !Number.isFinite(S) || (C = Math.round(S - r), C < i.min || C > i.max))) throw p("invalid", u.badExpiry);
86
- if (o !== void 0 && typeof o != "function") throw p("invalid", u.notAFile);
87
- let w = await g();
88
- if (!w) throw p("unavailable", u.unavailable);
89
- let T = await b(n);
90
- a?.throwIfAborted();
91
- let E = Promise.resolve(w.create(e, {
92
- name: m,
93
- type: h,
94
- lastModified: x,
95
- size: f,
96
- ...C === void 0 ? {} : { expiresIn: C },
97
- ...c === void 0 ? {} : { key: c },
98
- accountPin: T,
99
- ...a ? { signal: a } : {},
100
- ...o ? { onProgress: (e) => {
101
- try {
102
- o(e);
103
- } catch {}
104
- } } : {}
105
- })).catch(_);
106
- E.catch(() => {});
107
- let D = a ? await Promise.race([E, new Promise((e, t) => a.addEventListener("abort", () => t(a.reason), { once: !0 }))]) : await E;
108
- return v(D) ? y(D, a, n) : D;
109
- }, C = (e, t, n) => {
110
- let r = (t, n) => {
111
- if (t === void 0) return n;
112
- let r = Math.trunc(Number.isFinite(t) ? t : t > 0 ? e : -e);
113
- return r < 0 ? Math.max(e + r, 0) : Math.min(r, e);
114
- }, i = r(t, 0);
115
- return {
116
- from: i,
117
- to: Math.max(i, r(n, e))
118
- };
119
- }, w = async (e, n = {}) => {
120
- if (typeof e != "string") throw p("invalid", u.notALink);
121
- let { signal: r } = n;
122
- r?.throwIfAborted();
123
- let i = async () => {
124
- let n = await g();
125
- if (!n) throw p("unavailable", u.unavailable);
126
- let i = t()?.epoch, a = await Promise.resolve(n.open(e, r ? { signal: r } : void 0)).catch(_);
127
- return v(a) ? y(a, r) : {
128
- handle: a,
129
- epoch: i
130
- };
131
- }, a = await i(), o = async () => {
132
- let e = t()?.epoch;
133
- return a.epoch !== void 0 && e !== void 0 && e !== a.epoch && (a = await i()), a.handle;
134
- }, { name: s, type: c, size: l, lastModified: d } = a.handle, f = (e, t) => {
135
- let n;
136
- return new ReadableStream({
137
- pull: async (r) => {
138
- try {
139
- if (!n) {
140
- let r = await o(), i = await Promise.resolve(r.read(e, t)).catch(_);
141
- if (v(i)) return y(i);
142
- n = i.getReader();
143
- }
144
- let { value: i, done: a } = await n.read();
145
- a ? r.close() : r.enqueue(i);
146
- } catch (e) {
147
- throw h(e);
148
- }
149
- },
150
- cancel: (e) => n?.cancel(e)
151
- }, { highWaterMark: 0 });
152
- }, m = (e, t) => ({
153
- name: s,
154
- type: c,
155
- size: t - e,
156
- lastModified: d,
157
- stream: () => f(e, t),
158
- arrayBuffer: async () => {
159
- let n = new Uint8Array(t - e), r = f(e, t).getReader(), i = 0;
160
- for (;;) {
161
- let { value: e, done: t } = await r.read();
162
- if (t) break;
163
- n.set(e, i), i += e.length;
164
- }
165
- return n.buffer;
166
- },
167
- slice: (n, r) => {
168
- let i = C(t - e, n, r);
169
- return m(e + i.from, e + i.to);
170
- }
171
- });
172
- return m(0, l);
173
- }, T = async () => {
174
- let e = s(), t = await g();
175
- if (!t) throw p("unavailable", u.unavailable);
176
- let n = await b(e), r = await Promise.resolve(t.list({ accountPin: n })).catch(_);
177
- return v(r) ? y(r, void 0, e) : r.links;
178
- }, E = async (e) => {
179
- let t = s();
180
- if (typeof e != "string" || !e) throw p("invalid", u.notALink);
181
- let n = await g();
182
- if (!n) throw p("unavailable", u.unavailable);
183
- let r = await b(t), i = await Promise.resolve(n.revoke(e, { accountPin: r })).catch(_);
184
- v(i) && y(i, void 0, t);
185
- };
186
- //#endregion
187
- export { i as LINK_EXPIRES_MS, x as available, S as create, T as list, w as open, E as revoke, l as t };