@couch-kit/core 0.10.0 → 0.10.1

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,11 @@
1
1
  # @couch-kit/core
2
2
 
3
+ ## 0.10.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#208](https://github.com/faluciano/react-native-couch-kit/pull/208) [`99598d6`](https://github.com/faluciano/react-native-couch-kit/commit/99598d6796b0bd3042aa9f3fbd3bf44ee891b890) Thanks [@faluciano](https://github.com/faluciano)! - `replayActions` wraps the reducer it is given with `createGameReducer`. A recording that contains internal actions (`__PLAYER_JOINED__` and the others a host recorder captures) now replays the way it ran. Before, those actions were silently ignored, because a game's own reducer does not handle them. Passing a reducer that is already wrapped is harmless.
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -39,32 +39,32 @@ var __export = (target, all) => {
39
39
  // src/index.ts
40
40
  var exports_src = {};
41
41
  __export(exports_src, {
42
- toErrorMessage: () => toErrorMessage,
43
- replayActions: () => replayActions,
44
- isValidSecret: () => isValidSecret,
45
- generateId: () => generateId,
46
- derivePlayerIdLegacy: () => derivePlayerIdLegacy,
47
- derivePlayerId: () => derivePlayerId,
48
- createGameReducer: () => createGameReducer,
49
- applyMiddleware: () => applyMiddleware,
50
- actionValidator: () => actionValidator,
51
- actionLogger: () => actionLogger,
52
- SYNC_BACKOFF_FACTOR: () => SYNC_BACKOFF_FACTOR,
53
- MessageTypes: () => MessageTypes,
54
- MAX_SYNC_INTERVAL: () => MAX_SYNC_INTERVAL,
55
- MAX_PENDING_PINGS: () => MAX_PENDING_PINGS,
56
- MAX_FRAME_SIZE: () => MAX_FRAME_SIZE,
57
- KEEPALIVE_TIMEOUT: () => KEEPALIVE_TIMEOUT,
58
- KEEPALIVE_INTERVAL: () => KEEPALIVE_INTERVAL,
59
- InternalActionTypes: () => InternalActionTypes,
60
- DEFAULT_WS_PORT_OFFSET: () => DEFAULT_WS_PORT_OFFSET,
61
- DEFAULT_WS_PATH: () => DEFAULT_WS_PATH,
62
- DEFAULT_SYNC_INTERVAL: () => DEFAULT_SYNC_INTERVAL,
63
- DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES,
64
- DEFAULT_MAX_DELAY: () => DEFAULT_MAX_DELAY,
65
- DEFAULT_HTTP_PORT: () => DEFAULT_HTTP_PORT,
42
+ DEFAULT_BASE_DELAY: () => DEFAULT_BASE_DELAY,
66
43
  DEFAULT_DISCONNECT_TIMEOUT: () => DEFAULT_DISCONNECT_TIMEOUT,
67
- DEFAULT_BASE_DELAY: () => DEFAULT_BASE_DELAY
44
+ DEFAULT_HTTP_PORT: () => DEFAULT_HTTP_PORT,
45
+ DEFAULT_MAX_DELAY: () => DEFAULT_MAX_DELAY,
46
+ DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES,
47
+ DEFAULT_SYNC_INTERVAL: () => DEFAULT_SYNC_INTERVAL,
48
+ DEFAULT_WS_PATH: () => DEFAULT_WS_PATH,
49
+ DEFAULT_WS_PORT_OFFSET: () => DEFAULT_WS_PORT_OFFSET,
50
+ InternalActionTypes: () => InternalActionTypes,
51
+ KEEPALIVE_INTERVAL: () => KEEPALIVE_INTERVAL,
52
+ KEEPALIVE_TIMEOUT: () => KEEPALIVE_TIMEOUT,
53
+ MAX_FRAME_SIZE: () => MAX_FRAME_SIZE,
54
+ MAX_PENDING_PINGS: () => MAX_PENDING_PINGS,
55
+ MAX_SYNC_INTERVAL: () => MAX_SYNC_INTERVAL,
56
+ MessageTypes: () => MessageTypes,
57
+ SYNC_BACKOFF_FACTOR: () => SYNC_BACKOFF_FACTOR,
58
+ actionLogger: () => actionLogger,
59
+ actionValidator: () => actionValidator,
60
+ applyMiddleware: () => applyMiddleware,
61
+ createGameReducer: () => createGameReducer,
62
+ derivePlayerId: () => derivePlayerId,
63
+ derivePlayerIdLegacy: () => derivePlayerIdLegacy,
64
+ generateId: () => generateId,
65
+ isValidSecret: () => isValidSecret,
66
+ replayActions: () => replayActions,
67
+ toErrorMessage: () => toErrorMessage
68
68
  });
69
69
  module.exports = __toCommonJS(exports_src);
70
70
 
@@ -393,7 +393,7 @@ function generateId() {
393
393
  if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function") {
394
394
  const bytes = new Uint8Array(16);
395
395
  globalThis.crypto.getRandomValues(bytes);
396
- return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
396
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
397
397
  }
398
398
  const a = Math.random().toString(36).substring(2, 15);
399
399
  const b = Math.random().toString(36).substring(2, 10);
@@ -422,10 +422,11 @@ function toErrorMessage(error) {
422
422
  // src/replay.ts
423
423
  function replayActions(recording, reducer) {
424
424
  const snapshots = [];
425
+ const gameReducer = createGameReducer(reducer);
425
426
  let currentState = recording.initialState;
426
427
  for (let i = 0;i < recording.actions.length; i++) {
427
428
  const { action, timestamp } = recording.actions[i];
428
- currentState = reducer(currentState, action);
429
+ currentState = gameReducer(currentState, action);
429
430
  snapshots.push({
430
431
  state: currentState,
431
432
  action,
package/dist/index.js CHANGED
@@ -323,7 +323,7 @@ function generateId() {
323
323
  if (typeof globalThis.crypto !== "undefined" && typeof globalThis.crypto.getRandomValues === "function") {
324
324
  const bytes = new Uint8Array(16);
325
325
  globalThis.crypto.getRandomValues(bytes);
326
- return Array.from(bytes).map((b2) => b2.toString(16).padStart(2, "0")).join("");
326
+ return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
327
327
  }
328
328
  const a = Math.random().toString(36).substring(2, 15);
329
329
  const b = Math.random().toString(36).substring(2, 10);
@@ -352,10 +352,11 @@ function toErrorMessage(error) {
352
352
  // src/replay.ts
353
353
  function replayActions(recording, reducer) {
354
354
  const snapshots = [];
355
+ const gameReducer = createGameReducer(reducer);
355
356
  let currentState = recording.initialState;
356
357
  for (let i = 0;i < recording.actions.length; i++) {
357
358
  const { action, timestamp } = recording.actions[i];
358
- currentState = reducer(currentState, action);
359
+ currentState = gameReducer(currentState, action);
359
360
  snapshots.push({
360
361
  state: currentState,
361
362
  action,
@@ -372,30 +373,30 @@ function replayActions(recording, reducer) {
372
373
  };
373
374
  }
374
375
  export {
375
- toErrorMessage,
376
- replayActions,
377
- isValidSecret,
378
- generateId,
379
- derivePlayerIdLegacy,
380
- derivePlayerId,
381
- createGameReducer,
382
- applyMiddleware,
383
- actionValidator,
384
- actionLogger,
385
- SYNC_BACKOFF_FACTOR,
386
- MessageTypes,
387
- MAX_SYNC_INTERVAL,
388
- MAX_PENDING_PINGS,
389
- MAX_FRAME_SIZE,
390
- KEEPALIVE_TIMEOUT,
391
- KEEPALIVE_INTERVAL,
392
- InternalActionTypes,
393
- DEFAULT_WS_PORT_OFFSET,
394
- DEFAULT_WS_PATH,
395
- DEFAULT_SYNC_INTERVAL,
396
- DEFAULT_MAX_RETRIES,
397
- DEFAULT_MAX_DELAY,
398
- DEFAULT_HTTP_PORT,
376
+ DEFAULT_BASE_DELAY,
399
377
  DEFAULT_DISCONNECT_TIMEOUT,
400
- DEFAULT_BASE_DELAY
378
+ DEFAULT_HTTP_PORT,
379
+ DEFAULT_MAX_DELAY,
380
+ DEFAULT_MAX_RETRIES,
381
+ DEFAULT_SYNC_INTERVAL,
382
+ DEFAULT_WS_PATH,
383
+ DEFAULT_WS_PORT_OFFSET,
384
+ InternalActionTypes,
385
+ KEEPALIVE_INTERVAL,
386
+ KEEPALIVE_TIMEOUT,
387
+ MAX_FRAME_SIZE,
388
+ MAX_PENDING_PINGS,
389
+ MAX_SYNC_INTERVAL,
390
+ MessageTypes,
391
+ SYNC_BACKOFF_FACTOR,
392
+ actionLogger,
393
+ actionValidator,
394
+ applyMiddleware,
395
+ createGameReducer,
396
+ derivePlayerId,
397
+ derivePlayerIdLegacy,
398
+ generateId,
399
+ isValidSecret,
400
+ replayActions,
401
+ toErrorMessage
401
402
  };
package/lib/replay.d.ts CHANGED
@@ -37,6 +37,12 @@ export interface ReplayResult<S extends IGameState = IGameState> {
37
37
  /**
38
38
  * Replays a recording against a reducer, producing the final state
39
39
  * and intermediate snapshots for each action applied.
40
+ *
41
+ * Pass the game's own reducer, as given to the host. It is wrapped with
42
+ * {@link createGameReducer} here, so recordings that include internal actions
43
+ * (`__PLAYER_JOINED__` and friends, as a host recorder captures) replay the
44
+ * same way they ran. Wrapping an already-wrapped reducer is harmless: the outer
45
+ * layer handles internal actions and the inner never sees them.
40
46
  */
41
47
  export declare function replayActions<S extends IGameState = IGameState, A extends IAction = IAction>(recording: Recording<S, A>, reducer: GameReducer<S, A>): ReplayResult<S>;
42
48
  //# sourceMappingURL=replay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"replay.d.ts","sourceRoot":"","sources":["../src/replay.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,OAAO,GAAG,OAAO;IACzD,MAAM,EAAE,CAAC,CAAC;IACV,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC9D,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CACxB,CAAC,SAAS,UAAU,GAAG,UAAU,EACjC,CAAC,SAAS,OAAO,GAAG,OAAO;IAE3B,YAAY,EAAE,CAAC,CAAC;IAChB,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,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AAC;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,YAAY,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IAC7D,UAAU,EAAE,CAAC,CAAC;IACd,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,CAAC,SAAS,UAAU,GAAG,UAAU,EACjC,CAAC,SAAS,OAAO,GAAG,OAAO,EAC3B,SAAS,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CA6BzE"}
@@ -1 +1 @@
1
- {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoDH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAmGjD"}
1
+ {"version":3,"file":"sha256.d.ts","sourceRoot":"","sources":["../src/sha256.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAoDH;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAiGjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@couch-kit/core",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "publishConfig": {
5
5
  "access": "public",
6
6
  "provenance": true
package/src/replay.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { createGameReducer } from "./reducer.js";
1
2
  import type { GameReducer, IAction, IGameState } from "./types.js";
2
3
 
3
4
  /**
@@ -45,17 +46,24 @@ export interface ReplayResult<S extends IGameState = IGameState> {
45
46
  /**
46
47
  * Replays a recording against a reducer, producing the final state
47
48
  * and intermediate snapshots for each action applied.
49
+ *
50
+ * Pass the game's own reducer, as given to the host. It is wrapped with
51
+ * {@link createGameReducer} here, so recordings that include internal actions
52
+ * (`__PLAYER_JOINED__` and friends, as a host recorder captures) replay the
53
+ * same way they ran. Wrapping an already-wrapped reducer is harmless: the outer
54
+ * layer handles internal actions and the inner never sees them.
48
55
  */
49
56
  export function replayActions<
50
57
  S extends IGameState = IGameState,
51
58
  A extends IAction = IAction,
52
59
  >(recording: Recording<S, A>, reducer: GameReducer<S, A>): ReplayResult<S> {
53
60
  const snapshots: StateSnapshot<S>[] = [];
61
+ const gameReducer = createGameReducer(reducer);
54
62
  let currentState = recording.initialState;
55
63
 
56
64
  for (let i = 0; i < recording.actions.length; i++) {
57
65
  const { action, timestamp } = recording.actions[i];
58
- currentState = reducer(currentState, action);
66
+ currentState = gameReducer(currentState, action);
59
67
 
60
68
  snapshots.push({
61
69
  state: currentState,
package/src/sha256.ts CHANGED
@@ -111,10 +111,8 @@ export function sha256Hex(message: string): string {
111
111
  0;
112
112
  }
113
113
  for (let i = 16; i < 64; i++) {
114
- const s0 =
115
- rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
116
- const s1 =
117
- rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
114
+ const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ (w[i - 15] >>> 3);
115
+ const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ (w[i - 2] >>> 10);
118
116
  w[i] = (w[i - 16] + s0 + w[i - 7] + s1) >>> 0;
119
117
  }
120
118