@nice-code/action 0.23.0 → 0.24.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/README.md +18 -21
- package/build/{ActionPayload.types-B-OSg09t.d.mts → AcceptorHandler-11-QMdx2.d.mts} +967 -1346
- package/build/{ActionPayload.types-DIOeVapm.d.cts → AcceptorHandler-CxD0c1BE.d.cts} +967 -1346
- package/build/{ActionDevtoolsCore-BjbhFqc0.d.mts → ActionDevtoolsCore-37JP4bOG.d.cts} +2 -2
- package/build/{ActionDevtoolsCore-kk7oZBv9.d.cts → ActionDevtoolsCore-Cgq-go1R.d.mts} +2 -2
- package/build/advanced/index.cjs +115 -0
- package/build/advanced/index.cjs.map +1 -0
- package/build/advanced/index.d.cts +344 -0
- package/build/advanced/index.d.mts +344 -0
- package/build/advanced/index.mjs +88 -0
- package/build/advanced/index.mjs.map +1 -0
- package/build/{httpAcceptorCarrier-hYPuoNuP.cjs → createHibernatableWsServerAdapter-BNi4k9j3.cjs} +258 -470
- package/build/createHibernatableWsServerAdapter-BNi4k9j3.cjs.map +1 -0
- package/build/{httpAcceptorCarrier-DJVxzDVd.mjs → createHibernatableWsServerAdapter-C07RfUTH.mjs} +233 -421
- package/build/createHibernatableWsServerAdapter-C07RfUTH.mjs.map +1 -0
- package/build/devtools/browser/index.d.cts +1 -1
- package/build/devtools/browser/index.d.mts +1 -1
- package/build/devtools/server/index.d.cts +1 -1
- package/build/devtools/server/index.d.mts +1 -1
- package/build/httpAcceptorCarrier-C3S_bDkL.cjs +454 -0
- package/build/httpAcceptorCarrier-C3S_bDkL.cjs.map +1 -0
- package/build/httpAcceptorCarrier-DPBEuewS.mjs +401 -0
- package/build/httpAcceptorCarrier-DPBEuewS.mjs.map +1 -0
- package/build/index.cjs +69 -449
- package/build/index.cjs.map +1 -1
- package/build/index.d.cts +2 -2
- package/build/index.d.mts +2 -2
- package/build/index.mjs +13 -365
- package/build/index.mjs.map +1 -1
- package/build/platform/cloudflare/index.cjs +1 -1
- package/build/platform/cloudflare/index.cjs.map +1 -1
- package/build/platform/cloudflare/index.d.cts +3 -3
- package/build/platform/cloudflare/index.d.mts +3 -3
- package/build/platform/cloudflare/index.mjs +1 -1
- package/build/platform/cloudflare/index.mjs.map +1 -1
- package/build/react-query/index.d.cts +1 -1
- package/build/react-query/index.d.mts +1 -1
- package/package.json +15 -4
- package/build/httpAcceptorCarrier-DJVxzDVd.mjs.map +0 -1
- package/build/httpAcceptorCarrier-hYPuoNuP.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ The pieces:
|
|
|
31
31
|
| **ActionDomain** | A named group of typed actions (your API surface) |
|
|
32
32
|
| **ActionSchema** | Input/output schema + declared error types for one action |
|
|
33
33
|
| **ActionRuntime** | One per runtime; identifies it and dispatches actions to handlers |
|
|
34
|
-
| **Channel** | The transport-agnostic routing contract between two runtimes, declared *by role* (`toAcceptor` / `toConnector`)
|
|
34
|
+
| **Channel** | The transport-agnostic routing contract + binary wire identity between two runtimes, declared *by role* (`toAcceptor` / `toConnector`) with `defineChannel`. Security is a per-transport choice, not a channel one |
|
|
35
35
|
| **Carrier** | How bytes actually move: `wsCarrier` / `httpCarrier` / `inMemoryCarrier` / `rtcCarrier` (connector side), `wsAcceptorCarrier` / `httpAcceptorCarrier` (acceptor side) |
|
|
36
36
|
| **Transport** | A carrier wrapped with a security policy (handshake + optional encryption, or plain). You don't build these directly — `connectChannel` / `serveChannel` apply the policy to each carrier for you |
|
|
37
37
|
| **RuntimeCoordinate** | Identifies an environment (frontend, backend, worker…) and is how actions are routed |
|
|
@@ -130,30 +130,21 @@ Define it once in code shared by both ends:
|
|
|
130
130
|
import { defineChannel } from "@nice-code/action";
|
|
131
131
|
|
|
132
132
|
export const appChannel = defineChannel({
|
|
133
|
-
toAcceptor: [userDomain],
|
|
134
|
-
toConnector: [],
|
|
133
|
+
toAcceptor: [userDomain, lobbyDomain], // client → server requests
|
|
134
|
+
toConnector: [lobbyDomain], // server → client pushes (lobbyDomain is bidirectional)
|
|
135
135
|
});
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
import { defineSecureChannel } from "@nice-code/action";
|
|
144
|
-
|
|
145
|
-
export const appChannel = defineSecureChannel({
|
|
146
|
-
toAcceptor: [userDomain, lobbyDomain], // requests
|
|
147
|
-
toConnector: [lobbyDomain], // pushes (lobbyDomain is bidirectional)
|
|
148
|
-
});
|
|
149
|
-
```
|
|
138
|
+
A channel carries both its routing (`toAcceptor` / `toConnector` domains) **and** its wire identity — the
|
|
139
|
+
positional binary wire dictionary and a version derived from the domains, so the per-connection codec and
|
|
140
|
+
version can never drift between the two ends. Whether a given transport actually runs encrypted is a
|
|
141
|
+
per-transport choice (`secure` on `connectChannel`'s transports and the acceptor's `securityLevel`), not a
|
|
142
|
+
property of the channel — so this one definition serves both plain and secure transports.
|
|
150
143
|
|
|
151
144
|
> The lists are **positional** for the binary wire dictionary — **add new domains to the end** of their
|
|
152
145
|
> list. Reordering shifts the version, and a stale peer is then cleanly rejected by the handshake instead
|
|
153
146
|
> of silently misrouting a frame.
|
|
154
147
|
|
|
155
|
-
A secure channel is still an ordinary channel, so it works anywhere a channel is expected.
|
|
156
|
-
|
|
157
148
|
---
|
|
158
149
|
|
|
159
150
|
## Runtimes & handlers
|
|
@@ -353,7 +344,7 @@ export const lobbyDomain = appRoot.createChildDomain({
|
|
|
353
344
|
},
|
|
354
345
|
});
|
|
355
346
|
|
|
356
|
-
export const appChannel =
|
|
347
|
+
export const appChannel = defineChannel({
|
|
357
348
|
toAcceptor: [userDomain, lobbyDomain], // start_feed flows here
|
|
358
349
|
toConnector: [lobbyDomain], // position_update pushes back here
|
|
359
350
|
});
|
|
@@ -694,18 +685,24 @@ try {
|
|
|
694
685
|
crypto identity for you. The pieces below are what they're built on; reach for them only for the rare
|
|
695
686
|
routing that isn't a single channel.
|
|
696
687
|
|
|
688
|
+
> Most of these live under the **`@nice-code/action/advanced`** subpath, not the main entry — the default
|
|
689
|
+
> `@nice-code/action` export stays focused on the high-level API (`acceptChannel` /
|
|
690
|
+
> `acceptChannelConnections` and the carriers remain on the main entry). Import the raw handler classes
|
|
691
|
+
> (`AcceptorHandler`, `ConnectorHandler`, …), the transport classes/codec, and the handshake primitives
|
|
692
|
+
> from `@nice-code/action/advanced`.
|
|
693
|
+
|
|
697
694
|
- **Carriers vs transports.** A *carrier* (`wsCarrier`, `httpCarrier`, `inMemoryCarrier`, `rtcCarrier`) is
|
|
698
695
|
raw byte movement; a *transport* wraps one with a security policy. You name carriers in
|
|
699
696
|
`connectChannel`'s `transports` (the `secure` flag picks the policy) and in `serveChannel`'s `carriers`;
|
|
700
697
|
the transport wrapping happens internally, so there's no separate transport-builder to call.
|
|
701
698
|
|
|
702
|
-
- **`acceptChannel(runtime, channel, { clientEnv,
|
|
699
|
+
- **`acceptChannel(runtime, channel, { clientEnv, storage, send, ... })`** — build the secure
|
|
703
700
|
`AcceptorHandler` for a channel by hand (the accept-in counterpart to a single transport), when you're
|
|
704
701
|
not using `serveChannel`. Pair it with **`acceptChannelConnections(handler, channel, cases)`** to
|
|
705
702
|
register connection-aware execution — each case receives the request *and* the originating connection:
|
|
706
703
|
|
|
707
704
|
```ts
|
|
708
|
-
const acceptor = acceptChannel(runtime, appChannel, { clientEnv,
|
|
705
|
+
const acceptor = acceptChannel(runtime, appChannel, { clientEnv, storage, send });
|
|
709
706
|
const cases = acceptChannelConnections(acceptor, appChannel, {
|
|
710
707
|
join: ({ input }, conn) => { if (conn != null) rooms.add(input.roomId, conn); return { ok: true }; },
|
|
711
708
|
});
|
|
@@ -720,7 +717,7 @@ routing that isn't a single channel.
|
|
|
720
717
|
`AcceptorHandler`.
|
|
721
718
|
|
|
722
719
|
- **`createBinaryWireAdapter(domains)`** / **`createBinaryWireSessionFactory(domains)`** — the positional
|
|
723
|
-
binary codecs `
|
|
720
|
+
binary codecs `defineChannel` builds for you; useful for custom carriers.
|
|
724
721
|
|
|
725
722
|
- **`createInMemoryChannelPair()` / `inMemoryCarrier`** — wire two runtimes together in-process (tests,
|
|
726
723
|
same-process peers) with no network.
|