@korajs/server 1.0.0-beta.6 → 1.0.0-beta.7

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/dist/index.js CHANGED
@@ -2536,6 +2536,20 @@ function warnIfMultiTenantWithoutScopes(auth, resolvedScopes, schema) {
2536
2536
  "[kora] An authenticated session resolved to no sync scopes, so every user will sync every other user's data. Return per-user sync scopes from your auth provider (for example KoraAuthProvider's resolveScopes) to isolate tenants. Note: declaring sync rules in your schema is not enough on its own \u2014 the per-user values come from the auth provider. (This warning is expected for single-tenant apps where all authenticated users are meant to share the same data.)"
2537
2537
  );
2538
2538
  }
2539
+ function stableStringify(value) {
2540
+ if (Array.isArray(value)) {
2541
+ return `[${value.map((item) => stableStringify(item)).join(",")}]`;
2542
+ }
2543
+ if (value && typeof value === "object") {
2544
+ const record = value;
2545
+ const entries = Object.keys(record).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`);
2546
+ return `{${entries.join(",")}}`;
2547
+ }
2548
+ return JSON.stringify(value);
2549
+ }
2550
+ function sameScopeMap(a, b) {
2551
+ return stableStringify(a ?? null) === stableStringify(b ?? null);
2552
+ }
2539
2553
  var ClientSession = class _ClientSession {
2540
2554
  state = "connected";
2541
2555
  clientNodeId = null;
@@ -2888,6 +2902,9 @@ var ClientSession = class _ClientSession {
2888
2902
  }
2889
2903
  this.resumeDeltaCursor = msg.deltaCursor ? decodeDeltaCursor(msg.deltaCursor) : null;
2890
2904
  this.clientDeliveryWatermark = msg.lastDeliverySequence ?? null;
2905
+ if (this.clientDeliveryWatermark !== null && !sameScopeMap(msg.syncScope, this.authContext?.scopes)) {
2906
+ this.clientDeliveryWatermark = 0;
2907
+ }
2891
2908
  const clientUsesWatermark = this.clientDeliveryWatermark !== null;
2892
2909
  let serverMaxDelivery = 0;
2893
2910
  if (clientUsesWatermark) {