@braidlabs/core 0.1.1 → 0.3.0
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/package.json +2 -2
- package/src/adapters/adapter.d.ts +13 -0
- package/src/adapters/adapter.js.map +1 -1
- package/src/adapters/compat-adapter.d.ts +7 -0
- package/src/adapters/compat-adapter.js +24 -16
- package/src/adapters/compat-adapter.js.map +1 -1
- package/src/adapters/contract-adapter.d.ts +21 -0
- package/src/adapters/contract-adapter.js +71 -0
- package/src/adapters/contract-adapter.js.map +1 -0
- package/src/config.d.ts +29 -0
- package/src/config.js +16 -0
- package/src/config.js.map +1 -1
- package/src/context/context-bus.d.ts +63 -3
- package/src/context/context-bus.js +147 -61
- package/src/context/context-bus.js.map +1 -1
- package/src/elements/fragment-slot.d.ts +114 -1
- package/src/elements/fragment-slot.js +743 -60
- package/src/elements/fragment-slot.js.map +1 -1
- package/src/env/create-env.d.ts +20 -8
- package/src/env/create-env.js +48 -16
- package/src/env/create-env.js.map +1 -1
- package/src/env/define-fragment.d.ts +43 -0
- package/src/env/define-fragment.js +23 -0
- package/src/env/define-fragment.js.map +1 -0
- package/src/env/fragment-env.d.ts +20 -1
- package/src/env/fragment-env.js +0 -12
- package/src/env/fragment-env.js.map +1 -1
- package/src/errors.d.ts +1 -1
- package/src/errors.js.map +1 -1
- package/src/index.d.ts +14 -1
- package/src/index.js +7 -1
- package/src/index.js.map +1 -1
- package/src/protocol.d.ts +20 -4
- package/src/protocol.js +23 -7
- package/src/protocol.js.map +1 -1
- package/src/realm/realm-manager.d.ts +19 -2
- package/src/realm/realm-manager.js +32 -7
- package/src/realm/realm-manager.js.map +1 -1
- package/src/realm/sandbox-realm.d.ts +95 -0
- package/src/realm/sandbox-realm.js +194 -0
- package/src/realm/sandbox-realm.js.map +1 -0
- package/src/weave/capabilities.d.ts +71 -0
- package/src/weave/capabilities.js +61 -0
- package/src/weave/capabilities.js.map +1 -0
- package/src/weave/channel.d.ts +63 -0
- package/src/weave/channel.js +189 -0
- package/src/weave/channel.js.map +1 -0
- package/src/weave/closing.d.ts +99 -0
- package/src/weave/closing.js +130 -0
- package/src/weave/closing.js.map +1 -0
- package/src/weave/context-bridge.d.ts +81 -0
- package/src/weave/context-bridge.js +145 -0
- package/src/weave/context-bridge.js.map +1 -0
- package/src/weave/contract.d.ts +89 -0
- package/src/weave/contract.js +143 -0
- package/src/weave/contract.js.map +1 -0
- package/src/weave/envelope.d.ts +80 -0
- package/src/weave/envelope.js +49 -0
- package/src/weave/envelope.js.map +1 -0
- package/src/weave/guest.d.ts +59 -0
- package/src/weave/guest.js +120 -0
- package/src/weave/guest.js.map +1 -0
- package/src/weave/handshake.d.ts +124 -0
- package/src/weave/handshake.js +109 -0
- package/src/weave/handshake.js.map +1 -0
- package/src/weave/liveness.d.ts +90 -0
- package/src/weave/liveness.js +189 -0
- package/src/weave/liveness.js.map +1 -0
- package/src/weave/messages.d.ts +27 -0
- package/src/weave/messages.js +13 -0
- package/src/weave/messages.js.map +1 -0
- package/src/weave/port-backing.d.ts +19 -0
- package/src/weave/port-backing.js +54 -0
- package/src/weave/port-backing.js.map +1 -0
- package/src/weave/same-realm-backing.d.ts +21 -0
- package/src/weave/same-realm-backing.js +44 -0
- package/src/weave/same-realm-backing.js.map +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ChannelBacking } from './channel.js';
|
|
2
|
+
/**
|
|
3
|
+
* The trusted-tier transport: a linked pair of backings that hand envelopes straight to each other.
|
|
4
|
+
*
|
|
5
|
+
* No serialization, no `postMessage`, no clone — a same-origin realm shares a heap with its host, so
|
|
6
|
+
* paying for a structured clone at this layer would be a cost with no buyer. Clone discipline lives
|
|
7
|
+
* one level up, where the *bus* decides what a fragment is allowed to keep a reference to.
|
|
8
|
+
*
|
|
9
|
+
* **Delivery is asynchronous anyway, and that is the whole design.** Dispatching synchronously would
|
|
10
|
+
* be faster and would make this backing behave differently from `port-backing` in the one way that
|
|
11
|
+
* matters most: reentrancy. A synchronous backing lets a handler observe a send completing before
|
|
12
|
+
* its own frame returns, so code written against it works on the trusted tier and deadlocks or
|
|
13
|
+
* reorders on the untrusted one — a bug that would only surface in Phase 5, in a fragment nobody
|
|
14
|
+
* has the source of. Queuing a microtask costs nothing measurable and makes the two transports
|
|
15
|
+
* behave identically.
|
|
16
|
+
*/
|
|
17
|
+
export interface SameRealmBackingPair {
|
|
18
|
+
host: ChannelBacking;
|
|
19
|
+
fragment: ChannelBacking;
|
|
20
|
+
}
|
|
21
|
+
export declare function createSameRealmBackingPair(): SameRealmBackingPair;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function createSameRealmBackingPair() {
|
|
2
|
+
let hostHandler;
|
|
3
|
+
let fragmentHandler;
|
|
4
|
+
let closed = false;
|
|
5
|
+
const deliver = (to, envelope) => {
|
|
6
|
+
if (closed)
|
|
7
|
+
return;
|
|
8
|
+
queueMicrotask(() => {
|
|
9
|
+
if (closed)
|
|
10
|
+
return;
|
|
11
|
+
to()?.(envelope);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
const closeBoth = () => {
|
|
15
|
+
closed = true;
|
|
16
|
+
hostHandler = undefined;
|
|
17
|
+
fragmentHandler = undefined;
|
|
18
|
+
};
|
|
19
|
+
return {
|
|
20
|
+
host: {
|
|
21
|
+
post: (envelope) => deliver(() => fragmentHandler, envelope),
|
|
22
|
+
receive(handler) {
|
|
23
|
+
hostHandler = handler;
|
|
24
|
+
return () => {
|
|
25
|
+
if (hostHandler === handler)
|
|
26
|
+
hostHandler = undefined;
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
close: closeBoth,
|
|
30
|
+
},
|
|
31
|
+
fragment: {
|
|
32
|
+
post: (envelope) => deliver(() => hostHandler, envelope),
|
|
33
|
+
receive(handler) {
|
|
34
|
+
fragmentHandler = handler;
|
|
35
|
+
return () => {
|
|
36
|
+
if (fragmentHandler === handler)
|
|
37
|
+
fragmentHandler = undefined;
|
|
38
|
+
};
|
|
39
|
+
},
|
|
40
|
+
close: closeBoth,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=same-realm-backing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"same-realm-backing.js","sourceRoot":"","sources":["../../../../../libs/core/src/weave/same-realm-backing.ts"],"names":[],"mappings":"AAuBA,MAAM,UAAU,0BAA0B;IACxC,IAAI,WAAuD,CAAC;IAC5D,IAAI,eAA2D,CAAC;IAChE,IAAI,MAAM,GAAG,KAAK,CAAC;IAEnB,MAAM,OAAO,GAAG,CAAC,EAAoD,EAAE,QAAkB,EAAE,EAAE;QAC3F,IAAI,MAAM;YAAE,OAAO;QACnB,cAAc,CAAC,GAAG,EAAE;YAClB,IAAI,MAAM;gBAAE,OAAO;YACnB,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC;QACnB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,SAAS,GAAG,GAAG,EAAE;QACrB,MAAM,GAAG,IAAI,CAAC;QACd,WAAW,GAAG,SAAS,CAAC;QACxB,eAAe,GAAG,SAAS,CAAC;IAC9B,CAAC,CAAC;IAEF,OAAO;QACL,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,eAAe,EAAE,QAAQ,CAAC;YAC5D,OAAO,CAAC,OAAO;gBACb,WAAW,GAAG,OAAO,CAAC;gBACtB,OAAO,GAAG,EAAE;oBACV,IAAI,WAAW,KAAK,OAAO;wBAAE,WAAW,GAAG,SAAS,CAAC;gBACvD,CAAC,CAAC;YACJ,CAAC;YACD,KAAK,EAAE,SAAS;SACjB;QACD,QAAQ,EAAE;YACR,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC;YACxD,OAAO,CAAC,OAAO;gBACb,eAAe,GAAG,OAAO,CAAC;gBAC1B,OAAO,GAAG,EAAE;oBACV,IAAI,eAAe,KAAK,OAAO;wBAAE,eAAe,GAAG,SAAS,CAAC;gBAC/D,CAAC,CAAC;YACJ,CAAC;YACD,KAAK,EAAE,SAAS;SACjB;KACF,CAAC;AACJ,CAAC"}
|