@couch-kit/client 0.12.0 → 0.13.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/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @couch-kit/client
2
2
 
3
+ ## 0.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#158](https://github.com/faluciano/react-native-couch-kit/pull/158) [`509ea7c`](https://github.com/faluciano/react-native-couch-kit/commit/509ea7c02aa6f2e56ebf01e781d6de74f0ded021) Thanks [@faluciano](https://github.com/faluciano)! - Let the relay assign room codes
8
+
9
+ `RelayDisplayHost`'s `roomId` is now optional. Omit it and the relay mints an
10
+ unused six-character code, reported through the new `onRoomCode` callback and
11
+ the `roomCode` getter.
12
+
13
+ A display could never check its own code for collisions — only the relay knows
14
+ which codes are live — so a self-chosen code could land on a game already in
15
+ progress, and did so only after it was on screen. Minted codes are drawn from
16
+ the CSPRNG over a 32-character alphabet without `O`/`0` or `I`/`1`, giving about
17
+ 1.07 billion codes.
18
+
19
+ Existing callers that pass `roomId` keep their current behaviour, including
20
+ `ROOM_EXISTS` when the code is taken. New callers should expect the code to
21
+ arrive one round trip after connecting rather than being known up front:
22
+
23
+ ```ts
24
+ const [roomCode, setRoomCode] = useState<string | null>(null);
25
+ new RelayDisplayHost({ url, onRoomCode: setRoomCode, reducer, initialState });
26
+ ```
27
+
28
+ Relays need a matching update to mint: both bundled implementations
29
+ (`services/relay`, `services/relay-worker`) support it. A display that omits
30
+ `roomId` against an older relay gets `MALFORMED`.
31
+
3
32
  ## 0.12.0
4
33
 
5
34
  ### Minor Changes
package/dist/index.js CHANGED
@@ -345,9 +345,10 @@ var RelayErrorCodes = {
345
345
  function relayRoomUrl(url, roomId) {
346
346
  const trimmed = url.replace(/\/+$/, "");
347
347
  const [base, query] = trimmed.split("?", 2);
348
- const path = `${base}/r/${encodeURIComponent(roomId)}`;
348
+ const path = roomId === undefined ? `${base}${RELAY_MINT_PATH}` : `${base}/r/${encodeURIComponent(roomId)}`;
349
349
  return query ? `${path}?${query}` : path;
350
350
  }
351
+ var RELAY_MINT_PATH = "/new";
351
352
  // src/relay-transport.ts
352
353
  var POLICY_CLOSE_CODE = 1008;
353
354
 
@@ -647,5 +648,6 @@ export {
647
648
  SESSION_SECRET_KEY,
648
649
  RelayMessageTypes,
649
650
  RelayErrorCodes,
650
- RelayClientTransport
651
+ RelayClientTransport,
652
+ RELAY_MINT_PATH
651
653
  };
@@ -119,8 +119,19 @@ export type RelayMessage = RelayClientMessage | RelayServerMessage;
119
119
  * that keep every room in one process (the Bun reference server) ignore the
120
120
  * path, so this is safe to send to either.
121
121
  *
122
+ * Passing no room code addresses {@link RELAY_MINT_PATH} instead, asking the
123
+ * relay to allocate one; the code comes back in `ROOM_CREATED`.
124
+ *
122
125
  * @param url - Base relay URL, e.g. `wss://relay.example.com`.
123
- * @param roomId - Room code to address.
126
+ * @param roomId - Room code to address, or omitted to have one minted.
127
+ */
128
+ export declare function relayRoomUrl(url: string, roomId?: string): string;
129
+ /**
130
+ * Path that asks the relay to allocate a room code.
131
+ *
132
+ * Reserved, so it can never be mistaken for a room code. Single-process relays
133
+ * ignore the path and mint from the `CREATE_ROOM` message alone; sharded relays
134
+ * need it, because they must choose the shard before any frame arrives.
124
135
  */
125
- export declare function relayRoomUrl(url: string, roomId: string): string;
136
+ export declare const RELAY_MINT_PATH = "/new";
126
137
  //# sourceMappingURL=relay-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"relay-protocol.d.ts","sourceRoot":"","sources":["../src/relay-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,iBAAiB;IAC5B,8DAA8D;aAC9D,WAAW,EAAE,aAAa;IAC1B,0EAA0E;aAC1E,YAAY,EAAE,cAAc;IAC5B,4CAA4C;aAC5C,SAAS,EAAE,WAAW;IACtB,qEAAqE;aACrE,WAAW,EAAE,aAAa;IAC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AO,iBAAiB,CAAC,WAAW,CAAC;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,qCAAqC;AACrC,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,OAAO,iBAAiB,CAAC,SAAS,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,OAAO,iBAAiB,CAAC,IAAI,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6CAA6C;AAC7C,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,OAAO,iBAAiB,CAAC,KAAK,CAAC;IACrC,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,kDAAkD;AAClD,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB,eAAe,GACf,WAAW,CAAC;AAEhB,kDAAkD;AAClD,MAAM,MAAM,kBAAkB,GAC1B,kBAAkB,GAClB,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,WAAW,GACX,iBAAiB,CAAC;AAEtB,gCAAgC;AAChC,MAAM,MAAM,YAAY,GAAG,kBAAkB,GAAG,kBAAkB,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAQjE;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/client",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
@@ -144,12 +144,27 @@ export type RelayMessage = RelayClientMessage | RelayServerMessage;
144
144
  * that keep every room in one process (the Bun reference server) ignore the
145
145
  * path, so this is safe to send to either.
146
146
  *
147
+ * Passing no room code addresses {@link RELAY_MINT_PATH} instead, asking the
148
+ * relay to allocate one; the code comes back in `ROOM_CREATED`.
149
+ *
147
150
  * @param url - Base relay URL, e.g. `wss://relay.example.com`.
148
- * @param roomId - Room code to address.
151
+ * @param roomId - Room code to address, or omitted to have one minted.
149
152
  */
150
- export function relayRoomUrl(url: string, roomId: string): string {
153
+ export function relayRoomUrl(url: string, roomId?: string): string {
151
154
  const trimmed = url.replace(/\/+$/, "");
152
155
  const [base, query] = trimmed.split("?", 2);
153
- const path = `${base}/r/${encodeURIComponent(roomId)}`;
156
+ const path =
157
+ roomId === undefined
158
+ ? `${base}${RELAY_MINT_PATH}`
159
+ : `${base}/r/${encodeURIComponent(roomId)}`;
154
160
  return query ? `${path}?${query}` : path;
155
161
  }
162
+
163
+ /**
164
+ * Path that asks the relay to allocate a room code.
165
+ *
166
+ * Reserved, so it can never be mistaken for a room code. Single-process relays
167
+ * ignore the path and mint from the `CREATE_ROOM` message alone; sharded relays
168
+ * need it, because they must choose the shard before any frame arrives.
169
+ */
170
+ export const RELAY_MINT_PATH = "/new";