@fkn/lib 0.9.46 → 0.9.48
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-B-6Pn0b5.cjs → account-generation-9VhfEDoW.cjs} +1 -1
- package/{account-generation-XNWOvLea.js → account-generation-hUekEHGW.js} +1 -1
- package/account.cjs +1 -1
- package/account.js +2 -2
- package/{api-DOXb_WrB.d.ts → api-Cpi-qz1j.d.ts} +108 -24
- package/api-DMnVye0K.cjs +3 -0
- package/{api-DIgTslNb.js → api-ySazPAwN.js} +97 -59
- package/api.cjs +1 -1
- package/api.d.ts +2 -2
- package/api.js +1 -1
- package/busy-BXbVH595.cjs +1 -0
- package/{busy-B189uX--.js → busy-DsMWrSzc.js} +6 -3
- 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 +2 -2
- package/cloud/net.cjs +1 -1
- package/cloud/net.d.ts +1 -1
- package/cloud/net.js +2 -2
- package/{cloud-v5x4uhDC.js → cloud-B4_qsdaE.js} +14 -18
- package/{cloud-CUzZFzG3.cjs → cloud-BmwojOb5.cjs} +1 -1
- package/{cloud-DSx-jDFk.d.ts → cloud-DK3DtdsU.d.ts} +4 -4
- package/cloud.cjs +1 -1
- package/cloud.d.ts +4 -4
- package/cloud.js +2 -2
- package/{contract-BmLpSueo.d.ts → contract-XlEPwc7b.d.ts} +127 -46
- package/contract.cjs +1 -1
- package/contract.d.ts +4 -4
- package/contract.js +6 -9
- package/dgram.cjs +1 -1
- package/dgram.d.ts +3 -3
- package/dgram.js +19 -19
- package/dns.cjs +1 -1
- package/dns.d.ts +1 -1
- package/dns.js +1 -1
- package/{extension-C2tBRE9i.d.ts → extension-C4Don9vi.d.ts} +6 -6
- package/{extension-BnVG0YL4.js → extension-hOZN6A1U.js} +4 -4
- package/{extension-3bxlAW8M.cjs → extension-uAlpUogG.cjs} +1 -1
- package/extension.cjs +1 -1
- package/extension.d.ts +2 -2
- 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-BY0Csn2V.js +515 -0
- package/fs-DnF1cQuE.cjs +1 -0
- package/{fs-KA1Mgisv.d.ts → fs-lKZe5xIo.d.ts} +1 -1
- package/fs.cjs +1 -1
- package/fs.d.ts +2 -2
- package/fs.js +2 -2
- package/http.d.ts +1 -1
- package/{index-DKr9L2RI.d.ts → index-D9x6A-Gx.d.ts} +1 -1
- package/{index-B98wvTaI.d.ts → index-DlBWSKwV.d.ts} +92 -32
- package/index.cjs +1 -1
- package/index.d.ts +12 -9
- package/index.js +60 -60
- package/lib-5z-jA7ND.cjs +53 -0
- package/{lib-BFwrzgpu.js → lib-Dhq4W2V8.js} +662 -491
- package/links.cjs +1 -0
- package/links.d.ts +65 -0
- package/links.js +187 -0
- package/{net-BFjtzAK0.d.ts → net-C2Yz0job.d.ts} +5 -5
- package/net.cjs +1 -1
- package/net.d.ts +1 -1
- package/net.js +11 -12
- package/{node-fs-CK2wWIYS.js → node-fs-DY2fO5zd.js} +1 -1
- package/{node-fs-nfX7wisL.cjs → node-fs-vsWuoMGa.cjs} +1 -1
- package/opfs.cjs +1 -1
- package/opfs.js +1 -1
- package/package.json +6 -1
- package/packages.cjs +1 -1
- package/packages.d.ts +1 -1
- package/packages.js +2 -2
- package/{proxy-Dixbk1WL.js → proxy-BXkxwBxK.js} +2 -2
- package/{proxy-BrsMJmiK.d.ts → proxy-BZ-YFeXe.d.ts} +2 -2
- package/{proxy-CFK-KiwE.cjs → proxy-BfkfFsNI.cjs} +1 -1
- package/rooms.cjs +1 -1
- package/rooms.d.ts +1 -1
- package/rooms.js +13 -21
- package/{storage-BLBsmkmp.d.ts → storage-B_mXNAdB.d.ts} +4 -5
- package/{storage-Dn1gTLSZ.js → storage-C6F9SnDM.js} +2 -2
- package/{storage-D2cUJlVH.cjs → storage-DmRIhg1P.cjs} +1 -1
- package/utils-BpHmMkIR.cjs +1 -0
- package/{utils-C-cAd4r4.js → utils-Cyq8uJiy.js} +7 -9
- package/{wire-BwA4JjZH.d.ts → wire-Fk5pJaoy.d.ts} +8 -1
- package/wire.cjs +1 -1
- package/wire.d.ts +2 -2
- package/wire.js +2 -2
- package/api--LOXTOpv.cjs +0 -3
- package/busy-Dv8wzE5M.cjs +0 -1
- package/fs-CVnmXRf7.js +0 -513
- package/fs-p0bOOj5n.cjs +0 -1
- package/lib-47LPHYgB.cjs +0 -53
- package/utils-BvgGdrgN.cjs +0 -1
package/links.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DMnVye0K.cjs"),n=require("./contract.cjs"),r=require("./account-generation-9VhfEDoW.cjs"),i=require("./storage-DmRIhg1P.cjs");var a=e.t({LINK_EXPIRES_MS:()=>n.LINK_EXPIRES_MS,available:()=>_,create:()=>v,list:()=>x,open:()=>b,revoke:()=>S}),o={notALink:`links: the link is not one fkn.app made`,badExpiry:`links: the expiry is not one a link can carry`,notAFile:`links: the file is not a Blob or a ReadableStream`,badSize:`links: a stream needs the size it will deliver, a whole number of bytes`,badName:`links: the name or type is not one a link can carry`,tooLarge:`links: the file is too large for a link`,shortStream:`links: the stream did not deliver the size it declared`,badKey:`links: the key is not 32 bytes base64url`,keyTaken:`links: the key already names a link`,gone:`links: the link is no longer available`,integrity:`links: the file does not match its link`,needsAccount:`links: making a link needs an account`,notCreator:`links: only the app that made the link can revoke it`,quota:`links: storage quota exceeded`,tooMany:`links: too many links`,tooManyThisHour:`links: too many links made this hour, try again later`,rateLimited:`links: this link is opened too often, try again later`,accountChanged:`links: the signed-in account changed`,unavailable:`links: links are unavailable`},s=new Map([[o.notALink,`invalid`],[o.badExpiry,`invalid`],[o.notAFile,`invalid`],[o.badSize,`invalid`],[o.badName,`invalid`],[o.tooLarge,`invalid`],[o.shortStream,`invalid`],[o.badKey,`invalid`],[o.keyTaken,`invalid`],[o.gone,`not-found`],[o.integrity,`integrity`],[o.needsAccount,`denied`],[o.notCreator,`denied`],[o.quota,`quota`],[o.tooMany,`too-many`],[o.tooManyThisHour,`too-many`],[o.rateLimited,`rate-limited`],[o.accountChanged,`account-changed`],[o.unavailable,`unavailable`]]),c=new Set(s.values()),l=(e,t)=>Object.assign(Error(t),{code:e}),u=e=>e instanceof Error&&c.has(e.code),d=e=>{if(u(e))return e;let t=e instanceof Error?e.message:``,n=s.get(t);return n?l(n,t):l(`unavailable`,o.unavailable)},f=async()=>{if(!t.l)return;let e=(await t.s(`a link`).catch(()=>void 0))?.links;return typeof e?.create==`function`?e:void 0},p=()=>{throw l(`unavailable`,o.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),c.has(e.error)?l(e.error,e.message):l(`unavailable`,o.unavailable))},g=async e=>{try{return await i.p(e)}catch(e){throw i.c(e)?l(`account-changed`,o.accountChanged):e instanceof Error&&/not connected|not signed in/i.test(e.message)?l(`denied`,o.needsAccount):l(`unavailable`,o.unavailable)}},_=async()=>{let e=await f();return e?Promise.resolve(e.available()).catch(()=>!1):!1},v=async(e,t={})=>{let r=i.o(),a=Date.now(),{signal:s,onProgress:c,key:u}=t;s?.throwIfAborted();let d=typeof Blob<`u`&&e instanceof Blob,_=typeof ReadableStream<`u`&&e instanceof ReadableStream;if(!d&&!_)throw l(`invalid`,o.notAFile);let v=d?e.size:t.size;if(typeof v!=`number`||!Number.isSafeInteger(v)||v<0||d&&t.size!==void 0&&t.size!==v)throw l(`invalid`,o.badSize);let y=t.name??(typeof File<`u`&&e instanceof File?e.name:``),b=t.type??(d?e.type:``);if(typeof y!=`string`||typeof b!=`string`)throw l(`invalid`,o.badName);let x=typeof File<`u`&&e instanceof File?e.lastModified:a,S=t.expires,C;if(S!=null&&(typeof S!=`number`||!Number.isFinite(S)||(C=Math.round(S-a),C<n.LINK_EXPIRES_MS.min||C>n.LINK_EXPIRES_MS.max)))throw l(`invalid`,o.badExpiry);if(c!==void 0&&typeof c!=`function`)throw l(`invalid`,o.notAFile);let w=await f();if(!w)throw l(`unavailable`,o.unavailable);let T=await g(r);s?.throwIfAborted();let E=Promise.resolve(w.create(e,{name:y,type:b,lastModified:x,size:v,...C===void 0?{}:{expiresIn:C},...u===void 0?{}:{key:u},accountPin:T,...s?{signal:s}:{},...c?{onProgress:e=>{try{c(e)}catch{}}}:{}})).catch(p);E.catch(()=>{});let D=s?await Promise.race([E,new Promise((e,t)=>s.addEventListener(`abort`,()=>t(s.reason),{once:!0}))]):await E;return m(D)?h(D,s,r):D},y=(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))}},b=async(e,n={})=>{if(typeof e!=`string`)throw l(`invalid`,o.notALink);let{signal:r}=n;r?.throwIfAborted();let i=async()=>{let n=await f();if(!n)throw l(`unavailable`,o.unavailable);let i=t.c()?.epoch,a=await Promise.resolve(n.open(e,r?{signal:r}:void 0)).catch(p);return m(a)?h(a,r):{handle:a,epoch:i}},a=await i(),s=async()=>{let e=t.c()?.epoch;return a.epoch!==void 0&&e!==void 0&&e!==a.epoch&&(a=await i()),a.handle},{name:c,type:u,size:g,lastModified:_}=a.handle,v=(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})},b=(e,t)=>({name:c,type:u,size:t-e,lastModified:_,stream:()=>v(e,t),arrayBuffer:async()=>{let n=new Uint8Array(t-e),r=v(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=y(t-e,n,r);return b(e+i.from,e+i.to)}});return b(0,g)},x=async()=>{let e=i.o(),t=await f();if(!t)throw l(`unavailable`,o.unavailable);let n=await g(e),r=await Promise.resolve(t.list({accountPin:n})).catch(p);return m(r)?h(r,void 0,e):r.links},S=async e=>{let t=i.o();if(typeof e!=`string`||!e)throw l(`invalid`,o.notALink);let n=await f();if(!n)throw l(`unavailable`,o.unavailable);let r=await g(t),a=await Promise.resolve(n.revoke(e,{accountPin:r})).catch(p);m(a)&&h(a,void 0,t)};exports.LINK_EXPIRES_MS=n.LINK_EXPIRES_MS,exports.available=_,exports.create=v,exports.list=x,exports.open=b,exports.revoke=S,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
package/links.d.ts
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { A as Link, F as LinksErrorCode, L as ListedLink, P as LinkProgress, j as LinkCreateOptions, k as LINK_EXPIRES_MS } from "./contract-XlEPwc7b.js";
|
|
2
|
+
declare namespace links_d_exports {
|
|
3
|
+
export { LINK_EXPIRES_MS, Link, LinkCreateOptions, LinkProgress, LinkedFile, LinksError, LinksErrorCode, ListedLink, available, create, list, open, revoke };
|
|
4
|
+
}
|
|
5
|
+
/** Thrown by every member of this namespace except on an aborted signal. Match on `code`, never on the message. */
|
|
6
|
+
export type LinksError = Error & {
|
|
7
|
+
code: LinksErrorCode;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The file an opened link names, shaped like a `File`: the same four fields, `stream`, `arrayBuffer`
|
|
11
|
+
* and `slice`. Every read is by range and each 1 MiB record is checked before it is handed over, so a
|
|
12
|
+
* `slice` near the end of a large file fetches only that end.
|
|
13
|
+
*/
|
|
14
|
+
export type LinkedFile = {
|
|
15
|
+
name: string;
|
|
16
|
+
type: string;
|
|
17
|
+
size: number;
|
|
18
|
+
lastModified: number;
|
|
19
|
+
/** errors with `integrity` on the first record that is not what the link sealed */
|
|
20
|
+
stream: () => ReadableStream<Uint8Array>;
|
|
21
|
+
arrayBuffer: () => Promise<ArrayBuffer>;
|
|
22
|
+
/** `Blob.slice`'s arguments, negative ones counted from the end, and the same shape back */
|
|
23
|
+
slice: (start?: number, end?: number) => LinkedFile;
|
|
24
|
+
};
|
|
25
|
+
/** Whether a link can be made here now. Opening needs no account and does not depend on this. Answers rather than rejecting. */
|
|
26
|
+
export declare const available: () => Promise<boolean>;
|
|
27
|
+
/**
|
|
28
|
+
* Seals a file in the broker and uploads it, then answers its link. Needs a signed-in account, and
|
|
29
|
+
* counts the sealed size (28 bytes more per 1 MiB) against the account's storage from the moment it
|
|
30
|
+
* starts until the link is revoked, expires or the upload is aborted. The account the call belongs to
|
|
31
|
+
* is the one this page is on when it is made, as for every storage call.
|
|
32
|
+
*
|
|
33
|
+
* `data` is a `Blob` (a `File` included) or a `ReadableStream<Uint8Array>` with its `size`. An upload
|
|
34
|
+
* survives the network dropping a part, not a reload: a reload starts the file again, and the upload
|
|
35
|
+
* left behind stops counting within the hour, or at once from `revoke` or the account's settings.
|
|
36
|
+
*
|
|
37
|
+
* Refused `invalid` for an expiry outside `LINK_EXPIRES_MS`, a stream without its size or one that
|
|
38
|
+
* delivers another, a file past the service's part ceiling, a `key` that is not 32 bytes base64url or
|
|
39
|
+
* one that already names a link; `denied` with no account; `quota`; `too-many` past the account's live
|
|
40
|
+
* links or this hour's creations; `account-changed`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const create: (data: Blob | ReadableStream<Uint8Array>, options?: LinkCreateOptions) => Promise<Link>;
|
|
43
|
+
/**
|
|
44
|
+
* Opens a link made by any app, with no account: the broker reads the key from the link and fetches
|
|
45
|
+
* the sealed file by range. Refused `invalid` for a link fkn.app did not make, `not-found` for one
|
|
46
|
+
* that is missing, revoked, expired, still uploading or turned off (one answer for all of them),
|
|
47
|
+
* `integrity` when the file does not match its link, `rate-limited` past the link's daily opens.
|
|
48
|
+
*
|
|
49
|
+
* Opening counts once per viewer per link per day; reading the same opened file again, by `slice` or
|
|
50
|
+
* a second `stream()`, counts nothing more. A broker replaced while the file is held is asked to open
|
|
51
|
+
* it again on the next read.
|
|
52
|
+
*/
|
|
53
|
+
export declare const open: (url: string, options?: {
|
|
54
|
+
signal?: AbortSignal;
|
|
55
|
+
}) => Promise<LinkedFile>;
|
|
56
|
+
/** This app's links, newest first, uploads in progress included, as the service holds them: no name and no url. */
|
|
57
|
+
export declare const list: () => Promise<ListedLink[]>;
|
|
58
|
+
/**
|
|
59
|
+
* Revokes a link by its url or its id: every copy of the link stops opening, and an upload in
|
|
60
|
+
* progress is aborted and stops counting. Only the app that made the link (the same app once it is
|
|
61
|
+
* verified) revokes it, `denied` otherwise. A link already gone resolves.
|
|
62
|
+
*/
|
|
63
|
+
export declare const revoke: (target: string) => Promise<void>;
|
|
64
|
+
//#endregion
|
|
65
|
+
export { LINK_EXPIRES_MS, type Link, type LinkCreateOptions, type LinkProgress, type LinksErrorCode, type ListedLink, links_d_exports as t };
|
package/links.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
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 };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { o as TcpSocketOption } from "./wire-
|
|
3
|
-
import "./api-
|
|
1
|
+
import { Mt as TcpSocketListenerResult, Pt as TcpSocketResult, tt as Resolvers } from "./contract-XlEPwc7b.js";
|
|
2
|
+
import { o as TcpSocketOption } from "./wire-Fk5pJaoy.js";
|
|
3
|
+
import "./api-Cpi-qz1j.js";
|
|
4
4
|
import { AddressInfo, ListenOptions, Server, ServerOpts, Socket, SocketConnectOpts, SocketConstructorOpts } from "net";
|
|
5
5
|
import { DuplexOptions, Stream } from "stream";
|
|
6
6
|
import { EventEmitter } from "events";
|
|
@@ -126,13 +126,13 @@ declare class Server$1 extends EventEmitter implements Server {
|
|
|
126
126
|
[Symbol.asyncDispose](): Promise<void>;
|
|
127
127
|
}
|
|
128
128
|
declare const connect: (options: SocketConnectOpts, connectionListener?: () => void) => Socket$2;
|
|
129
|
-
declare const createConnection:
|
|
129
|
+
declare const createConnection: typeof connect;
|
|
130
130
|
declare const createServer: (options?: ServerOpts | ((socket: Socket$2) => void), connectionListener?: (socket: Socket$2) => void) => Server$1;
|
|
131
131
|
declare const _default: {
|
|
132
132
|
Socket: typeof Socket$2;
|
|
133
133
|
Server: typeof Server$1;
|
|
134
134
|
connect: typeof connect;
|
|
135
|
-
createConnection: typeof
|
|
135
|
+
createConnection: typeof connect;
|
|
136
136
|
createServer: typeof createServer;
|
|
137
137
|
isIP: typeof isIP;
|
|
138
138
|
isIPv4: typeof isIPv4;
|
package/net.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./api-DMnVye0K.cjs"),n=require("./busy-BXbVH595.cjs"),r=require("./utils-BpHmMkIR.cjs");require("./wire.cjs");let i=require("stream"),a=require("events");var o=e.t({Server:()=>c,Socket:()=>s,_default:()=>f,connect:()=>l,createConnection:()=>u,createServer:()=>d,default:()=>f,isIP:()=>r.t,isIPv4:()=>r.n,isIPv6:()=>r.r}),s=class extends i.Stream.Duplex{_localAddress;_remoteAddress;_webVPNTcpSocketPromise;constructor(e){if(e?.fd!==void 0)throw Error(`FKN WebVPN does not support file descriptors`);super(e),e?.connection&&this.__webvpn_tcp_socket_init__(e.connection)}_busyRelease;__webvpn_tcp_socket_init__(e,t){return this._busyRelease??=n.t(`tcp socket`),t&&(this._localAddress={address:t.localAddress,family:t.localFamily,port:t.localPort},this._remoteAddress={address:t.remoteAddress,family:t.remoteFamily,port:t.remotePort}),this._webVPNTcpSocketPromise=e.then(e=>{let t=e.dataReadableStream.getReader(),n=e.dataWritableStream.getWriter();return this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},this._remoteAddress={address:e.remoteAddress,family:e.remoteFamily,port:e.remotePort},{...e,reader:t,writer:n}}).catch(e=>{this.emit(`error`,e)}),this._webVPNTcpSocketPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`connect`)}),this._webVPNTcpSocketPromise}_read(e){if(!this._webVPNTcpSocketPromise)throw Error(`Socket not connected`);this._webVPNTcpSocketPromise.then(e=>{if(!e){this.push(null);return}e.reader.read().then(({value:e,done:t})=>{if(t){this.push(null);return}this._restartTimeoutTimer(),this.push(e)}).catch(e=>{this.destroy(e)})})}_write(e,t,n){if(!this._webVPNTcpSocketPromise){n(Error(`Socket not connected`));return}this._webVPNTcpSocketPromise.then(async t=>{if(!t)throw Error(`Socket not connected`);await t.writer.ready,await t.writer.write(e),this._restartTimeoutTimer(),n()}).catch(n)}connect(...e){let n=r.o(...e),i=this.__webvpn_tcp_socket_init__(t.s(`an outbound tcp socket`).then(e=>e.cloud.webvpn.tcpSocket({remoteAddress:n.host??`localhost`,remotePort:n.port})));return n.callback&&i.then(e=>{e&&n.callback.call(this)}),this}_final(e){if(!this._webVPNTcpSocketPromise){e();return}this._webVPNTcpSocketPromise.then(async e=>{e&&await e.writer.close()}).then(()=>e(),t=>e(t))}_destroy(e,t){if(this._timeoutTimer&&clearTimeout(this._timeoutTimer),this._busyRelease?.(),!this._webVPNTcpSocketPromise){t(e);return}this._webVPNTcpSocketPromise.then(async e=>{e&&await(this._resetRequested?e.resetAndDestroy():e.destroy())}).then(()=>t(e),()=>t(e))}destroySoon(){if(this.writableFinished){this.destroy();return}this.once(`finish`,()=>this.destroy()),this.end()}_resetRequested=!1;resetAndDestroy(){return this._resetRequested=!0,this.destroy(),this}_timeoutMs;_timeoutTimer;_restartTimeoutTimer(){this._timeoutTimer&&clearTimeout(this._timeoutTimer),this._timeoutMs&&(this._timeoutTimer=setTimeout(()=>this.emit(`timeout`),this._timeoutMs))}setTimeout(e,t){return t&&this.on(`timeout`,t),this._timeoutMs=e,this._restartTimeoutTimer(),this}setNoDelay(e){let t=e??!0;return this._setTcpOption({type:0,value:t}),this}setKeepAlive(e,t){let n=e??!1,r=t!==void 0&&t>0?Math.max(1,Math.round(t/1e3)):0;return this._setTcpOption({type:2,enabled:n,initialDelaySeconds:r}),this}setSendBufferSize(e){return this._setTcpOption({type:3,value:e}),this}setRecvBufferSize(e){return this._setTcpOption({type:4,value:e}),this}_typeOfService;getTypeOfService(){return this._typeOfService??0}setTypeOfService(e){return this._typeOfService=e,this}_setTcpOption(e){if(!this._webVPNTcpSocketPromise){this.emit(`error`,Error(`Cannot set socket option before connect`));return}this._webVPNTcpSocketPromise.then(async t=>{if(t)try{await t.setOption(e)}catch(e){this.emit(`error`,e)}})}write(e,t,...n){return super.write(e,t,...n)}address(){return this._localAddress??{}}unref(){return this}ref(){return this}autoSelectFamilyAttemptedAddresses;bufferSize;bytesRead;bytesWritten;connecting;pending;get localAddress(){if(!this._localAddress)throw Error(`Socket is not connected`);return this._localAddress.address}get localPort(){if(!this._localAddress)throw Error(`Socket is not connected`);return this._localAddress.port}get localFamily(){if(!this._localAddress)throw Error(`Socket is not connected`);return this._localAddress.family}readyState;get remoteAddress(){if(!this._remoteAddress)throw Error(`Socket is not connected`);return this._remoteAddress.address}get remotePort(){if(!this._remoteAddress)throw Error(`Socket is not connected`);return this._remoteAddress.port}get remoteFamily(){if(!this._remoteAddress)throw Error(`Socket is not connected`);return this._remoteAddress.family}timeout},c=class extends a.EventEmitter{_localAddress;_webVPNTcpSocketListenerPromise;constructor(e,t){super(e),t&&this.on(`connection`,t),e?.connection&&this.__webvpn_tcp_socket_listener_init__(e.connection)}_busyRelease;__webvpn_tcp_socket_listener_init__(e){return this._busyRelease??=n.t(`tcp server`),this._webVPNTcpSocketListenerPromise=e.then(e=>(this._localAddress={address:e.localAddress,family:e.localFamily,port:e.localPort},e)).catch(e=>{this.emit(`error`,e)}),this._webVPNTcpSocketListenerPromise.then(e=>{if(!e){this._busyRelease?.();return}this.emit(`listening`)}),this._webVPNTcpSocketListenerPromise}listen(...e){let n=r.o(...e);this._closeEmitted=!1;let i=e=>{let t=new s;t.__webvpn_tcp_socket_init__(Promise.resolve(e),e),this.emit(`connection`,t)},a=e=>{this._localAddress=void 0;try{e&&this.listenerCount(`error`)>0&&this.emit(`error`,e)}finally{this._emitClose()}},o=e=>t.s(`a tcp listener`).then(t=>t.cloud.webvpn.tcpSocketListener({localAddress:e,localPort:n.port,onConnection:i,onClose:a})),c=n.host?o(n.host):o(`::`).catch(()=>o(`0.0.0.0`)),l=this.__webvpn_tcp_socket_listener_init__(c);return n.callback&&l.then(e=>{e&&n.callback.call(this)}),this}_closeEmitted=!1;_emitClose(){this._closeEmitted||(this._closeEmitted=!0,this._busyRelease?.(),this.emit(`close`))}close(e){return this._webVPNTcpSocketListenerPromise&&this._webVPNTcpSocketListenerPromise.then(async t=>{if(t)try{await t.close(),this._localAddress=void 0,this._emitClose(),e&&e()}catch(t){this._localAddress=void 0,this._emitClose(),e&&e(t)}}),this}address(){return this._localAddress??null}getConnections(e){throw Error(`Method not implemented.`)}ref(){return this}unref(){return this}maxConnections;connections;listening;async[Symbol.asyncDispose](){}},l=(e,t)=>new s().connect(e,t),u=l,d=(e,t)=>{typeof e==`function`&&(t=e,e=void 0);let n=new c(e);return t&&n.on(`connection`,t),n},f={Socket:s,Server:c,connect:l,createConnection:u,createServer:d,isIP:r.t,isIPv4:r.n,isIPv6:r.r};exports.Server=c,exports.Socket=s,exports._default=f,exports.default=f,exports.connect=l,exports.createConnection=u,exports.createServer=d,exports.isIP=r.t,exports.isIPv4=r.n,exports.isIPv6=r.r,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|
package/net.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-
|
|
1
|
+
import { a as createConnection, c as isIP, i as connect, l as isIPv4, n as Socket, o as createServer, r as _default, t as Server, u as isIPv6 } from "./net-C2Yz0job.js";
|
|
2
2
|
export { Server, Socket, _default, _default as default, connect, createConnection, createServer, isIP, isIPv4, isIPv6 };
|
package/net.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import { s as t } from "./api-
|
|
3
|
-
import { t as n } from "./busy-
|
|
4
|
-
import {
|
|
2
|
+
import { s as t } from "./api-ySazPAwN.js";
|
|
3
|
+
import { t as n } from "./busy-DsMWrSzc.js";
|
|
4
|
+
import { n as r, o as i, r as a, t as o } from "./utils-Cyq8uJiy.js";
|
|
5
5
|
import "./wire.js";
|
|
6
6
|
import { Stream as s } from "stream";
|
|
7
7
|
import { EventEmitter as c } from "events";
|
|
@@ -15,8 +15,8 @@ var l = /* @__PURE__ */ e({
|
|
|
15
15
|
createServer: () => m,
|
|
16
16
|
default: () => h,
|
|
17
17
|
isIP: () => o,
|
|
18
|
-
isIPv4: () =>
|
|
19
|
-
isIPv6: () =>
|
|
18
|
+
isIPv4: () => r,
|
|
19
|
+
isIPv6: () => a
|
|
20
20
|
}), u = class extends s.Duplex {
|
|
21
21
|
_localAddress;
|
|
22
22
|
_remoteAddress;
|
|
@@ -27,7 +27,7 @@ var l = /* @__PURE__ */ e({
|
|
|
27
27
|
}
|
|
28
28
|
_busyRelease;
|
|
29
29
|
__webvpn_tcp_socket_init__(e, t) {
|
|
30
|
-
|
|
30
|
+
return this._busyRelease ??= n("tcp socket"), t && (this._localAddress = {
|
|
31
31
|
address: t.localAddress,
|
|
32
32
|
family: t.localFamily,
|
|
33
33
|
port: t.localPort
|
|
@@ -52,8 +52,7 @@ var l = /* @__PURE__ */ e({
|
|
|
52
52
|
};
|
|
53
53
|
}).catch((e) => {
|
|
54
54
|
this.emit("error", e);
|
|
55
|
-
}),
|
|
56
|
-
return this._webVPNTcpSocketPromise.then((e) => {
|
|
55
|
+
}), this._webVPNTcpSocketPromise.then((e) => {
|
|
57
56
|
if (!e) {
|
|
58
57
|
this._busyRelease?.();
|
|
59
58
|
return;
|
|
@@ -300,7 +299,7 @@ var l = /* @__PURE__ */ e({
|
|
|
300
299
|
connections;
|
|
301
300
|
listening;
|
|
302
301
|
async [Symbol.asyncDispose]() {}
|
|
303
|
-
}, f = (e, t) => new u().connect(e, t), p =
|
|
302
|
+
}, f = (e, t) => new u().connect(e, t), p = f, m = (e, t) => {
|
|
304
303
|
typeof e == "function" && (t = e, e = void 0);
|
|
305
304
|
let n = new d(e);
|
|
306
305
|
return t && n.on("connection", t), n;
|
|
@@ -311,8 +310,8 @@ var l = /* @__PURE__ */ e({
|
|
|
311
310
|
createConnection: p,
|
|
312
311
|
createServer: m,
|
|
313
312
|
isIP: o,
|
|
314
|
-
isIPv4:
|
|
315
|
-
isIPv6:
|
|
313
|
+
isIPv4: r,
|
|
314
|
+
isIPv6: a
|
|
316
315
|
};
|
|
317
316
|
//#endregion
|
|
318
|
-
export { d as Server, u as Socket, h as _default, h as default, f as connect, p as createConnection, m as createServer, o as isIP,
|
|
317
|
+
export { d as Server, u as Socket, h as _default, h as default, f as connect, p as createConnection, m as createServer, o as isIP, r as isIPv4, a as isIPv6, l as t };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./busy-
|
|
1
|
+
const e=require("./busy-BXbVH595.cjs");let t=require("buffer");var n={json:`application/json`,txt:`text/plain`,html:`text/html`,htm:`text/html`,css:`text/css`,js:`text/javascript`,mjs:`text/javascript`,xml:`application/xml`,csv:`text/csv`,md:`text/markdown`,svg:`image/svg+xml`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,pdf:`application/pdf`,wasm:`application/wasm`},r=(e,t)=>{if(t)return t;let r=e.split(`/`).pop()??``,i=r.lastIndexOf(`.`);if(!(i<=0))return n[r.slice(i+1).toLowerCase()]},i=(e,t)=>({size:e,mtimeMs:t,mtime:new Date(t),atimeMs:t,ctimeMs:t,mode:420,isFile:()=>!0,isDirectory:()=>!1,isSymbolicLink:()=>!1}),a=(e=0)=>({size:0,mtimeMs:e,mtime:new Date(e),atimeMs:e,ctimeMs:e,mode:493,isFile:()=>!1,isDirectory:()=>!0,isSymbolicLink:()=>!1}),o=(e,t,n)=>{let r=Error(`${e}: ${{ENOENT:`no such file or directory`,EEXIST:`file already exists`,ENOTDIR:`not a directory`,EISDIR:`illegal operation on a directory`,ENOTEMPTY:`directory not empty`,ERR_FS_EISDIR:`is a directory`}[e]??e}, ${n} '${t}'`);return r.code=e,r.path=t,r.syscall=n,r},s=e=>{let t=[];for(let n of e.split(`/`))if(n&&n!==`.`){if(n===`..`){t.pop();continue}t.push(n)}return t.join(`/`)},c=e=>e.split(`/`).slice(0,-1).join(`/`),l=e=>typeof e==`string`?e:e instanceof URL?decodeURIComponent(e.pathname):e.toString(),u=e=>typeof e==`string`?e:e?.encoding??void 0,d=e=>typeof e==`object`?e?.contentType:void 0,f=e=>typeof e==`object`&&!!e?.recursive,p=(e,n)=>{let r=u(n);return r?t.Buffer.from(e).toString(r):t.Buffer.from(e)},m=(e,n)=>{if(typeof e==`string`)return new Uint8Array(t.Buffer.from(e,u(n)??`utf8`));if(e instanceof Uint8Array)return e.slice();if(e instanceof ArrayBuffer)return new Uint8Array(e).slice();if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();throw TypeError(`The "data" argument must be of type string, Buffer, TypedArray, or DataView`)},h=t=>{let n=new Map([[``,{kind:`dir`,mtimeMs:0}]]),l=new Map,u=new Map,d=()=>t.captureAccount?{pin:t.captureAccount()}:{};e.i(`unsaved files`,()=>l.size>0||u.size>0);let f=new Set,p=()=>Date.now(),m=e=>{if(!e)return;let t=e.split(`/`),r=``;for(let e of t){r=r?`${r}/${e}`:e;let t=n.get(r);if(!t)n.set(r,{kind:`dir`,mtimeMs:p()});else if(t.kind===`file`)throw o(`ENOTDIR`,r,`mkdir`)}},h,g=0,_=async()=>{let e=d(),r=await t.list(e).catch(()=>[]),i=new Set,a=!1;for(let o of r){let r=s(o.path);if(i.add(r),!u.has(r)&&(!l.has(r)||f.has(r)))try{let i=await(await t.readFile(o.path,e)).arrayBuffer();if(u.has(r)||l.has(r)&&!f.has(r))continue;m(c(r));let a=Date.parse(o.updatedAt??``);n.set(r,{kind:`file`,data:new Uint8Array(i),mtimeMs:Number.isFinite(a)?a:p(),contentType:o.contentType??void 0}),f.delete(r),l.delete(r)}catch{a=!0,f.add(r)}}for(let e of f)i.has(e)||f.delete(e);g=a?Date.now():0},v=()=>(h&&(g===0||Date.now()-g<5e3)||(h=_()),h),y=async()=>{h=void 0,g=0,await v()},b=async()=>{let e=[...l].map(async([e,i])=>{if(f.has(e))return;let a=n.get(e);if(a?.kind!==`file`){l.delete(e);return}let o=a.data,s=r(e,a.contentType);try{await t.writeFile(e,o,s?{contentType:s,...i}:i);let r=n.get(e);r?.kind===`file`&&r.data===o&&l.delete(e)}catch{}}),i=[...u].map(async([e,n])=>{try{await t.remove(e,n),u.get(e)===n&&u.delete(e)}catch{}});await Promise.all([...e,...i])},x,S=()=>{x||=setTimeout(()=>{x=void 0,b().catch(()=>{})},250)};typeof addEventListener<`u`&&(addEventListener(`pagehide`,()=>{b().catch(()=>{})}),addEventListener(`visibilitychange`,()=>{typeof document<`u`&&document.visibilityState===`hidden`&&b().catch(()=>{})}));let C=e=>e.kind===`file`?i(e.data.byteLength,e.mtimeMs):a(e.mtimeMs),w=e=>Object.assign(Error(`storage: ${e} exists but could not be read, retry once its scope is available`),{code:`FKN_E2E_LOCKED`}),T=e=>{let t=s(e);return n.has(t)||f.has(t)},E=e=>{let t=s(e),r=n.get(t);if(!r)throw f.has(t)?w(e):o(`ENOENT`,e,`stat`);return C(r)},D=e=>{let t=s(e),r=n.get(t);if(!r)throw f.has(t)?w(e):o(`ENOENT`,e,`open`);if(r.kind===`dir`)throw o(`EISDIR`,e,`read`);return r.data},O=(e,t)=>{let n=new Uint8Array(e.byteLength+t.byteLength);return n.set(e,0),n.set(t,e.byteLength),n},k=(e,t,r,i)=>{let a=s(e);if(!a)throw o(`EISDIR`,e,`open`);if(f.has(a))throw w(e);let h=n.get(a);if(h?.kind===`dir`)throw o(`EISDIR`,e,`open`);m(c(a));let g=r&&h?.kind===`file`?O(h.data,t):t;n.set(a,{kind:`file`,data:g,mtimeMs:p(),contentType:i??(h?.kind===`file`?h.contentType:void 0)}),l.set(a,d()),u.delete(a),S()},A=(e,t)=>{let r=s(e);if(r){if(n.has(r)){if(t)return;throw o(`EEXIST`,e,`mkdir`)}if(!t&&!n.has(c(r)))throw o(`ENOENT`,e,`mkdir`);m(r)}},j=e=>{let t=s(e),r=n.get(t);if(!r)throw o(`ENOENT`,e,`scandir`);if(r.kind===`file`)throw o(`ENOTDIR`,e,`scandir`);let i=t?`${t}/`:``,a=new Set;for(let e of[...n.keys(),...f]){if(!e||!e.startsWith(i))continue;let t=e.slice(i.length);t&&a.add(t.split(`/`)[0])}return[...a]},M=(e,{op:t,recursive:r,force:i})=>{let a=d(),c=s(e),p=n.get(c);if(!p&&f.has(c)){if(t===`rmdir`)throw o(`ENOTDIR`,e,`rmdir`);f.delete(c),l.delete(c),u.set(c,a),S();return}if(!p){if(i||t===`rmdir`&&r)return;throw o(`ENOENT`,e,t===`rmdir`?`rmdir`:`unlink`)}if(t===`unlink`&&p.kind===`dir`)throw o(`EISDIR`,e,`unlink`);if(t===`rmdir`&&p.kind===`file`)throw o(`ENOTDIR`,e,`rmdir`);if(t===`rm`&&p.kind===`dir`&&!r)throw o(`ERR_FS_EISDIR`,e,`rm`);let m=`${c}/`,h=[...n.keys()].filter(e=>e.startsWith(m));if(h.length&&!r)throw o(`ENOTEMPTY`,e,`rmdir`);for(let e of[c,...h]){let t=n.get(e);n.delete(e),t?.kind===`file`&&(l.delete(e),u.set(e,a))}S()};return{mount:v,remount:y,flush:b,exists:T,stat:E,readFile:D,writeFile:k,mkdir:A,readdir:j,remove:M,rename:(e,t)=>{let r=d(),i=s(e),a=s(t);if(!i)throw o(`EBUSY`,e,`rename`);if(a===i||a.startsWith(`${i}/`))throw o(`EINVAL`,e,`rename`);if(f.has(i))throw w(e);if(f.has(a))throw w(t);let p=n.get(i);if(!p)throw o(`ENOENT`,e,`rename`);let h=n.get(a);if(h){if(h.kind!==p.kind)throw o(p.kind===`dir`?`ENOTDIR`:`EISDIR`,t,`rename`);M(a,{op:`rm`,recursive:!0,force:!0})}m(c(a));let g=`${i}/`,_=[i,...[...n.keys()].filter(e=>e.startsWith(g))];for(let e of _){let t=a+e.slice(i.length),o=n.get(e);n.set(t,o),n.delete(e),o.kind===`file`&&(l.set(t,r),u.delete(t),l.delete(e),u.set(e,r))}S()}}},g=(e,t)=>typeof e==`function`?e:t,_=e=>typeof e==`function`?void 0:e,v=(e,t)=>{e.then(e=>t(null,e),e=>t(e))},y=e=>{let t=h(e),n=(e,n)=>p(t.readFile(l(e)),n),r=(e,n,r)=>t.writeFile(l(e),m(n,r),!1,d(r)),i=(e,n,r)=>t.writeFile(l(e),m(n,r),!0,d(r)),a=e=>t.exists(l(e)),s=e=>t.stat(l(e)),c=e=>t.readdir(l(e)),u=(e,n)=>t.mkdir(l(e),f(n)),v=(e,n)=>t.remove(l(e),{op:`rm`,...n}),y=(e,n)=>t.remove(l(e),{op:`rmdir`,...n}),b=e=>t.remove(l(e),{op:`unlink`}),x=(e,n)=>t.rename(l(e),l(n)),S=(e,n)=>{t.mount().finally(()=>{let t;try{t=e()}catch(e){n(e);return}n(null,t)})},C=e=>t.mount().then(()=>e());return{available:e.available,readFileSync:n,writeFileSync:r,appendFileSync:i,existsSync:a,statSync:s,lstatSync:s,readdirSync:c,mkdirSync:u,rmSync:v,rmdirSync:y,unlinkSync:b,renameSync:x,readFile:(e,n,r)=>S(()=>p(t.readFile(l(e)),_(n)),g(n,r)),writeFile:(e,n,r,i)=>S(()=>t.writeFile(l(e),m(n,_(r)),!1,d(_(r))),g(r,i)),appendFile:(e,n,r,i)=>S(()=>t.writeFile(l(e),m(n,_(r)),!0,d(_(r))),g(r,i)),stat:(e,n)=>S(()=>t.stat(l(e)),n),readdir:(e,n,r)=>S(()=>t.readdir(l(e)),g(n,r)),mkdir:(e,n,r)=>S(()=>t.mkdir(l(e),f(_(n))),g(n,r)),rm:(e,n,r)=>S(()=>t.remove(l(e),{op:`rm`,..._(n)}),g(n,r)),unlink:(e,n)=>S(()=>t.remove(l(e),{op:`unlink`}),n),rename:(e,n,r)=>S(()=>t.rename(l(e),l(n)),r),exists:(e,n)=>{t.mount().finally(()=>n(t.exists(l(e))))},promises:{readFile:(e,n)=>C(()=>p(t.readFile(l(e)),n)),writeFile:(e,n,r)=>C(()=>t.writeFile(l(e),m(n,r),!1,d(r))),appendFile:(e,n,r)=>C(()=>t.writeFile(l(e),m(n,r),!0,d(r))),stat:e=>C(()=>t.stat(l(e))),lstat:e=>C(()=>t.stat(l(e))),readdir:e=>C(()=>t.readdir(l(e))),mkdir:(e,n)=>C(()=>t.mkdir(l(e),f(n))),rm:(e,n)=>C(()=>t.remove(l(e),{op:`rm`,...n})),rmdir:(e,n)=>C(()=>t.remove(l(e),{op:`rmdir`,...n})),unlink:e=>C(()=>t.remove(l(e),{op:`unlink`})),rename:(e,n)=>C(()=>t.rename(l(e),l(n))),access:e=>C(()=>{if(!t.exists(l(e)))throw o(`ENOENT`,l(e),`access`)})},mount:t.mount,flush:t.flush,remount:t.remount}},b=e=>{let t=()=>e.captureAccount?{pin:e.captureAccount()}:{},n=async(t,n)=>{let r=await e.readFile(l(t));return p(new Uint8Array(await r.arrayBuffer()),n)},c=async(t,n,i)=>{let a=l(t),o=r(a,d(i));await e.writeFile(a,m(n,i),o?{contentType:o}:void 0)},u=t=>e.remove(l(t)),f=async(n,r)=>{let i=t(),a=s(l(n)),o=s(l(r));if(a===o)return;let c=await e.readFile(a,i);await e.writeFile(o,c,i),await e.remove(a,i)},h=async t=>{let n=s(l(t)),r=n?`${n}/`:``,i=new Set;for(let t of await e.list()){let e=s(t.path);if(r&&!e.startsWith(r))continue;let n=e.slice(r.length);n&&i.add(n.split(`/`)[0])}return[...i]},y=async(e,t)=>{},b=async(n,r)=>{let i=t(),a=s(l(n));if(!r?.recursive){await e.remove(l(n),i);return}let o=`${a}/`,c=await e.list(i);await Promise.all(c.filter(e=>{let t=s(e.path);return t===a||t.startsWith(o)}).map(t=>e.remove(t.path,i).catch(()=>{})))},x=async t=>{let n=s(l(t)),r=await e.list(),c=r.find(e=>s(e.path)===n);if(c){let e=Date.parse(c.updatedAt??``);return i(c.size,Number.isFinite(e)?e:0)}if(r.some(e=>s(e.path).startsWith(`${n}/`)))return a();throw o(`ENOENT`,l(t),`stat`)},S={readFile:n,writeFile:c,unlink:u,rename:f,readdir:h,mkdir:y,rm:b,rmdir:b,stat:x,lstat:x,access:async e=>{await x(e)}};return{available:e.available,promises:S,readFile:(e,t,r)=>v(n(e,_(t)),g(t,r)),writeFile:(e,t,n,r)=>v(c(e,t,_(n)),g(n,r)),unlink:(e,t)=>v(u(e),t),rename:(e,t,n)=>v(f(e,t),n),readdir:(e,t,n)=>v(h(e),g(t,n)),mkdir:(e,t,n)=>v(y(),g(t,n)),rm:(e,t,n)=>v(b(e,_(t)),g(t,n)),stat:(e,t)=>v(x(e),t)}};function x(e,t){return t.memfs?y(e):b(e)}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return x}});
|
package/opfs.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./node-fs-
|
|
1
|
+
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require("./rolldown-runtime-BIInC43l.cjs"),t=require("./node-fs-vsWuoMGa.cjs"),n=require("./opfs-CXMESVLc.cjs");var r=e.t({appendFile:()=>b,appendFileSync:()=>c,available:()=>a,default:()=>i,exists:()=>D,existsSync:()=>l,flush:()=>A,lstatSync:()=>d,mkdir:()=>C,mkdirSync:()=>p,mount:()=>k,promises:()=>O,readFile:()=>v,readFileSync:()=>o,readdir:()=>S,readdirSync:()=>f,remount:()=>j,rename:()=>E,renameSync:()=>_,rm:()=>w,rmSync:()=>m,rmdirSync:()=>h,stat:()=>x,statSync:()=>u,unlink:()=>T,unlinkSync:()=>g,writeFile:()=>y,writeFileSync:()=>s}),i=t.t(n.r,{memfs:!0}),{available:a,readFileSync:o,writeFileSync:s,appendFileSync:c,existsSync:l,statSync:u,lstatSync:d,readdirSync:f,mkdirSync:p,rmSync:m,rmdirSync:h,unlinkSync:g,renameSync:_,readFile:v,writeFile:y,appendFile:b,stat:x,readdir:S,mkdir:C,rm:w,unlink:T,rename:E,exists:D,promises:O,mount:k,flush:A,remount:j}=i;exports.appendFile=b,exports.appendFileSync=c,exports.available=a,exports.default=i,exports.exists=D,exports.existsSync=l,exports.flush=A,exports.lstatSync=d,exports.mkdir=C,exports.mkdirSync=p,exports.mount=k,exports.promises=O,exports.readFile=v,exports.readFileSync=o,exports.readdir=S,exports.readdirSync=f,exports.remount=j,exports.rename=E,exports.renameSync=_,exports.rm=w,exports.rmSync=m,exports.rmdirSync=h,exports.stat=x,exports.statSync=u,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return r}}),exports.unlink=T,exports.unlinkSync=g,exports.writeFile=y,exports.writeFileSync=s;
|
package/opfs.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fkn/lib",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.48",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"types": "index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -115,6 +115,11 @@
|
|
|
115
115
|
"import": "./rooms.js",
|
|
116
116
|
"require": "./rooms.cjs"
|
|
117
117
|
},
|
|
118
|
+
"./links": {
|
|
119
|
+
"types": "./links.d.ts",
|
|
120
|
+
"import": "./links.js",
|
|
121
|
+
"require": "./links.cjs"
|
|
122
|
+
},
|
|
118
123
|
"./react": {
|
|
119
124
|
"types": "./react.d.ts",
|
|
120
125
|
"import": "./react.js",
|
package/packages.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-DMnVye0K.cjs"),n=require("./busy-BXbVH595.cjs");let r=require("osra");var i=e.t({attach:()=>j,connect:()=>T,hide:()=>w,install:()=>p,isVisible:()=>G,list:()=>m,mount:()=>A,onConnect:()=>W,onVisibilityChange:()=>K,pick:()=>f,search:()=>d,show:()=>C,uninstall:()=>h}),a=`fkn-packages-connection`,o=3e4,s=(e,t)=>Object.assign(Error(t),{code:e}),c=async()=>{if(!t.l)throw s(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return t.o},l=(e,t,n)=>(0,r.expose)(e??{},{transport:t,key:a,unregisterSignal:n}),u=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw s(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let c=new AbortController,u=new Promise((e,n)=>{let a=setTimeout(()=>n(s(`timeout`,`packages.connect: the package did not complete the connection`)),o);c.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(s(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:c.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(s(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:c.signal}),i?.then(()=>n(s(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([l(e,t,a.signal),u])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{c.abort()}},d=async e=>{let t=await(await c()).packages.search(e);if(`error`in t)throw s(t.error,t.message);return t.results},f=async(e,t)=>{let n=await(await c()).packages.pick(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?[]:n.results},p=async(e,t)=>{let n=await(await c()).packages.install(e,t);if(`error`in n)throw s(n.error,n.message);return`declined`in n?null:n.installed},m=async()=>(await(await c()).packages.list()).results,h=async e=>{let t=await(await c()).packages.uninstall(e);if(`error`in t)throw s(t.error,t.message)},g=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),_=(e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}},v=(e,t)=>{let n=t;for(let t=e.parentElement;t;t=t.parentElement){let e=getComputedStyle(t);if((e.overflowX!==`visible`||e.overflowY!==`visible`)&&(n=_(n,g(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},y=e=>{let t=getComputedStyle(e),n=[t.borderTopLeftRadius,t.borderTopRightRadius,t.borderBottomRightRadius,t.borderBottomLeftRadius];if(n.some(e=>e.includes(`%`)||e.includes(` `)))return;let r=n.map(e=>{let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:0});return r.some(e=>e>0)?r:void 0},b=(e,t)=>{if(!e)return!1;let n=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height;return n(e.rect,t.rect)&&n(e.clip,t.clip)&&((e,t)=>e===t||!!e&&!!t&&e.every((e,n)=>e===t[n]))(e.radius,t.radius)},x=new Map;n.i(`package view`,()=>x.size>0);var S=async(e,t)=>{let n=x.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;x.delete(e)}let r=await(await c()).packages.hide(e);if(`error`in r)throw s(r.error,r.message)},C=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw s(`invalid`,`packages.show: pass an element or a rect`);let i=(await c()).packages,a=()=>{if(!n)return{rect:g(r)};let e=g(n.getBoundingClientRect());return{rect:e,clip:v(n,e),radius:y(n)}},o=!0,l,u=0,d=async t=>{l=t;let n=await i.show(e,t);if(`error`in n)throw o=!1,s(n.error,n.message)};await d(a());let f=()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{}),u=requestAnimationFrame(f)};n&&(u=requestAnimationFrame(f));let p={element:n,stop:()=>{o=!1,cancelAnimationFrame(u)}},m=x.get(e)??new Set;return m.add(p),x.set(e,m),{hide:()=>{S(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();b(l,e)||d(e).catch(()=>{})}}},w=async(e,t={})=>S(e,t.element),T=(async(e,r={})=>{let i=await(await c()).packages.connect(e,{protocol:r.protocol,...r.path===void 0?{}:{path:r.path}});if(`error`in i)throw s(i.error,i.message);let a=n.t(`package connection`),o=t.c()?.epoch??0,l=t.u((e,t)=>{t!==o&&(a(),l())});Promise.resolve(i.closed).then(()=>{a(),l()},()=>{a(),l()});let{port:d,closed:f}=i;if(r.raw)return{closed:f,port:d};let p=await u(r.payload,d,{signal:r.signal,closed:f});return r.signal&&r.signal.addEventListener(`abort`,()=>{try{d.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:p,closed:f,port:d}}),E=[`allow-scripts`,`allow-same-origin`],D=e=>{let t=e.getAttribute(`sandbox`);if(t!==null){let e=new Set(t.toLowerCase().split(/\s+/).filter(Boolean)),n=E.filter(t=>!e.has(t));if(n.length)throw s(`invalid`,`packages.mount: the iframe's sandbox attribute must include ${n.join(` and `)}, or the package cannot start`)}if(globalThis.crossOriginIsolated&&!new Set((e.getAttribute(`allow`)??``).toLowerCase().split(`;`).map(e=>e.trim().split(/\s+/)[0]).filter(Boolean)).has(`cross-origin-isolated`))throw s(`invalid`,`packages.mount: this page is cross-origin isolated, so the iframe's allow attribute must include 'cross-origin-isolated' to hand that down to the package`)},O=3e4,k=(e,t)=>new Promise((n,r)=>{let i=e=>{clearTimeout(o),window.removeEventListener(`message`,a),e?r(e):n()},a=n=>{if(n.source!==e.contentWindow||n.origin!==t)return;let r=n.data;if(r?.type===`fkn-packages-ready`)return i();r?.type===`fkn-packages-failed`&&i(s(`unavailable`,typeof r.message==`string`&&r.message?r.message:`packages.mount: the package failed to boot`))},o=setTimeout(()=>i(s(`timeout`,`packages.mount: the package did not register a connection handler`)),O);window.addEventListener(`message`,a)}),A=async(e,t)=>{let{iframe:r}=t;if(!(r instanceof HTMLIFrameElement))throw s(`invalid`,`packages.mount: pass the iframe to load the package into`);if(!r.isConnected)throw s(`invalid`,`packages.mount: the iframe must be in the document before mounting into it`);D(r);let i=await(await c()).packages.frame(e);if(`error`in i)throw s(i.error,i.message);r.src=i.url;let a={done:!1},o=()=>{},l=new Promise(e=>{o=e}),d=n.t(`mounted package`),f=()=>{if(!a.done){a.done=!0,d();try{r.contentWindow?.postMessage({type:`fkn-packages-close`},i.origin)}catch{}r.src=`about:blank`,o()}};try{await k(r,i.origin)}catch(e){throw f(),e}let p=new MessageChannel,m=r.contentWindow;if(!m)throw f(),s(`unavailable`,`packages.mount: the frame was detached before it could connect`);m.postMessage({type:`fkn-packages-port`,from:i.from,protocol:t.protocol,uri:i.uri,name:i.name,version:i.version},i.origin,[p.port2]);try{m.postMessage({type:`fkn-packages-visibility`,visible:!0},i.origin)}catch{}if(t.raw)return{closed:l,port:p.port1,frame:r,unmount:f};try{return{remote:await u(t.payload,p.port1,{signal:t.signal,closed:l}),closed:l,port:p.port1,frame:r,unmount:f}}catch(e){throw f(),e}},j=(e,t,n)=>u(t,e,{signal:n?.signal}),M=null,N=!1,P=new Set,F=[],I=new Map,L=!1,R=!1,z=e=>{let t=I.get(e);t&&(I.delete(e),t())},B=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},V=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&z(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw B(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>I.set(e.port,t)),o=await l(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},H=()=>{L||typeof window>`u`||window.parent===window||(L=!0,window.addEventListener(`message`,e=>{if(e.source!==window.parent)return;let t=e.data;if(t?.type===`fkn-packages-port`){let n=e.ports[0];if(!n)return;let r={port:n,from:typeof t.from==`string`?t.from:``,protocol:typeof t.protocol==`string`?t.protocol:null,uri:typeof t.uri==`string`?t.uri:``,name:typeof t.name==`string`?t.name:``,version:typeof t.version==`string`?t.version:``};M?V(r,M).catch(e=>console.warn(`packages.onConnect:`,e)):F.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...I.keys()])z(e);if(t?.type===`fkn-packages-visibility`){N=t.visible===!0;for(let e of P)try{e(N)}catch{}}}))},U=()=>{R||typeof window>`u`||window.parent===window||(R=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},W=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};H();let n={createPayload:e,handler:t};for(M=n,U();F.length&&M===n;)V(F.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{M===n&&(M=null)}}},G=()=>N,K=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};H(),P.add(e);try{e(N)}catch{}return{unsubscribe:()=>{P.delete(e)}}};exports.attach=j,exports.connect=T,exports.hide=w,exports.install=p,exports.isVisible=G,exports.list=m,exports.mount=A,exports.onConnect=W,exports.onVisibilityChange=K,exports.pick=f,exports.search=d,exports.show=C,Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return i}}),exports.uninstall=h;
|
package/packages.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { At as SurfaceRect, E as InstalledPackage, G as PackagesErrorCode, J as Placement, T as InstallOptions, U as PackageQuery, W as PackageResult, et as Radii, m as ConnectOptions, q as PickOptions } from "./contract-XlEPwc7b.js";
|
|
2
2
|
import { Remote } from "osra";
|
|
3
3
|
declare namespace packages_d_exports {
|
|
4
4
|
export { AppConnectOptions, Connect, ConnectOptions, ConnectPayload, IncomingConnection, IncomingConnectionInfo, InstallOptions, InstalledPackage, MountOptions, MountedPackage, PackageConnection, PackageQuery, PackageResult, PackageView, PackagesError, PackagesErrorCode, PickOptions, Placement, Radii, RawPackageConnection, ShowOptions, SurfaceRect, attach, connect, hide, install, isVisible, list, mount, onConnect, onVisibilityChange, pick, search, show, uninstall };
|
package/packages.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as e } from "./rolldown-runtime-Dy4uBu1J.js";
|
|
2
|
-
import { c as t, l as n, o as r, u as i } from "./api-
|
|
3
|
-
import {
|
|
2
|
+
import { c as t, l as n, o as r, u as i } from "./api-ySazPAwN.js";
|
|
3
|
+
import { i as a, t as o } from "./busy-DsMWrSzc.js";
|
|
4
4
|
import { expose as s } from "osra";
|
|
5
5
|
//#region src/packages.ts
|
|
6
6
|
var c = /* @__PURE__ */ e({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { o as e, p as t } from "./api-
|
|
2
|
-
import { t as n } from "./busy-
|
|
1
|
+
import { o as e, p as t } from "./api-ySazPAwN.js";
|
|
2
|
+
import { t as n } from "./busy-DsMWrSzc.js";
|
|
3
3
|
//#region src/proxy.ts
|
|
4
4
|
var r = typeof FinalizationRegistry > "u" ? void 0 : new FinalizationRegistry((e) => e()), i = (e) => {
|
|
5
5
|
let t = e.body;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./api-
|
|
1
|
+
import { tt as Resolvers } from "./contract-XlEPwc7b.js";
|
|
2
|
+
import "./api-Cpi-qz1j.js";
|
|
3
3
|
//#region src/proxy.d.ts
|
|
4
4
|
type ProxyFetch = Resolvers['cloud']['fetch'];
|
|
5
5
|
type FetchParameters = Parameters<ProxyFetch>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require("./api
|
|
1
|
+
const e=require("./api-DMnVye0K.cjs"),t=require("./busy-BXbVH595.cjs");var n=typeof FinalizationRegistry>`u`?void 0:new FinalizationRegistry(e=>e()),r=e=>{let r=e.body;if(!r)return e;let i=t.t(`streamed response`),a=r.getReader(),o=new ReadableStream({pull:async e=>{try{let{done:t,value:n}=await a.read();if(t){i(),e.close();return}e.enqueue(n)}catch(t){i(),e.error(t)}},cancel:async e=>{i(),await a.cancel(e).catch(()=>{})}}),s=new Response(o,{status:e.status,statusText:e.statusText,headers:e.headers});return n?.register(s,i),s},i=async e=>{if(e!=null)return typeof e==`string`||e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e:new Request(`https://body.invalid/`,{method:`POST`,body:e,duplex:`half`}).arrayBuffer()},a=async e=>{if(e.method===`GET`||e.method===`HEAD`)return;let t=await e.clone().arrayBuffer();return t.byteLength?t:void 0},o=async(t,n)=>{if(e.p(t),typeof t==`object`&&t&&!(t instanceof URL)&&typeof t.url==`string`){let o=t,s={};o.headers.forEach((e,t)=>{s[t]=e});let c=await i(n?.body===void 0?await a(o):n.body);return e.o.then(e=>e.cloud.fetch(o.url,{...n,method:n?.method??o.method,headers:n?.headers??s,body:c})).then(r)}let o=t instanceof URL?t.href:t,s=await i(n?.body);return e.o.then(e=>e.cloud.fetch(o,n?.body===void 0?n:{...n,body:s})).then(r)};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return o}});
|