@liveblocks/core 1.0.0 → 1.0.1-test2

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -2
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -274,6 +274,7 @@ function wrapWithTitle(method) {
274
274
  ...args
275
275
  );
276
276
  }
277
+ var warnWithTitle = wrapWithTitle("warn");
277
278
  var errorWithTitle = wrapWithTitle("error");
278
279
 
279
280
  // src/lib/deprecation.ts
@@ -2614,6 +2615,16 @@ function findNonSerializableValue(value, path = "") {
2614
2615
  return false;
2615
2616
  }
2616
2617
 
2618
+ // src/lib/debug.ts
2619
+ function captureStackTrace(msg, traceRoot) {
2620
+ const errorLike = { name: msg };
2621
+ if (typeof Error.captureStackTrace !== "function") {
2622
+ return void 0;
2623
+ }
2624
+ Error.captureStackTrace(errorLike, traceRoot);
2625
+ return errorLike.stack;
2626
+ }
2627
+
2617
2628
  // src/lib/Json.ts
2618
2629
  function isJsonScalar(data) {
2619
2630
  return data === null || typeof data === "string" || typeof data === "number" || typeof data === "boolean";
@@ -2938,6 +2949,16 @@ function makeStateMachine(state, config, mockedEffects) {
2938
2949
  generateOpId: () => `${getConnectionId()}:${state.opClock++}`,
2939
2950
  dispatch(ops, reverse, storageUpdates) {
2940
2951
  const activeBatch = state.activeBatch;
2952
+ if (process.env.NODE_ENV !== "production") {
2953
+ const stackTrace = captureStackTrace("Storage mutation", this.dispatch);
2954
+ if (stackTrace) {
2955
+ ops.forEach((op) => {
2956
+ if (op.opId) {
2957
+ nn(state.opStackTraces).set(op.opId, stackTrace);
2958
+ }
2959
+ });
2960
+ }
2961
+ }
2941
2962
  if (activeBatch) {
2942
2963
  activeBatch.ops.push(...ops);
2943
2964
  storageUpdates.forEach((value, key) => {
@@ -3172,7 +3193,11 @@ function makeStateMachine(state, config, mockedEffects) {
3172
3193
  if (isLocal) {
3173
3194
  source = 0 /* UNDOREDO_RECONNECT */;
3174
3195
  } else {
3175
- const deleted = state.unacknowledgedOps.delete(nn(op.opId));
3196
+ const opId = nn(op.opId);
3197
+ if (process.env.NODE_ENV !== "production") {
3198
+ nn(state.opStackTraces).delete(opId);
3199
+ }
3200
+ const deleted = state.unacknowledgedOps.delete(opId);
3176
3201
  source = deleted ? 2 /* ACK */ : 1 /* REMOTE */;
3177
3202
  }
3178
3203
  const applyOpResult = applyOp(op, source);
@@ -3516,6 +3541,7 @@ function makeStateMachine(state, config, mockedEffects) {
3516
3541
  others: []
3517
3542
  };
3518
3543
  batchUpdates(() => {
3544
+ var _a2;
3519
3545
  for (const message of messages) {
3520
3546
  switch (message.type) {
3521
3547
  case 101 /* USER_JOINED */: {
@@ -3580,6 +3606,21 @@ function makeStateMachine(state, config, mockedEffects) {
3580
3606
  message.reason
3581
3607
  );
3582
3608
  if (process.env.NODE_ENV !== "production") {
3609
+ const traces = /* @__PURE__ */ new Set();
3610
+ for (const opId of message.opIds) {
3611
+ const trace = (_a2 = state.opStackTraces) == null ? void 0 : _a2.get(opId);
3612
+ if (trace) {
3613
+ traces.add(trace);
3614
+ }
3615
+ }
3616
+ if (traces.size > 0) {
3617
+ warnWithTitle(
3618
+ "The following function calls caused the rejected storage mutations:",
3619
+ `
3620
+
3621
+ ${Array.from(traces).join("\n\n")}`
3622
+ );
3623
+ }
3583
3624
  throw new Error(
3584
3625
  `Storage mutations rejected by server: ${message.reason}`
3585
3626
  );
@@ -4063,7 +4104,8 @@ function defaultState(initialPresence, initialStorage) {
4063
4104
  redoStack: [],
4064
4105
  pausedHistory: null,
4065
4106
  activeBatch: null,
4066
- unacknowledgedOps: /* @__PURE__ */ new Map()
4107
+ unacknowledgedOps: /* @__PURE__ */ new Map(),
4108
+ opStackTraces: process.env.NODE_ENV !== "production" ? /* @__PURE__ */ new Map() : void 0
4067
4109
  };
4068
4110
  }
4069
4111
  function createRoom(options, config) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/core",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-test2",
4
4
  "description": "Shared code and foundational internals for Liveblocks",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",