@event-driven-io/emmett 0.38.4 → 0.38.6

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.cjs CHANGED
@@ -199,24 +199,117 @@ var arrayUtils = {
199
199
  };
200
200
 
201
201
  // src/utils/deepEquals.ts
202
- var deepEquals = (left, right) => {
203
- if (isEquatable(left)) {
204
- return left.equals(right);
202
+ var isPrimitive = (value) => {
203
+ const type = typeof value;
204
+ return value === null || value === void 0 || type === "boolean" || type === "number" || type === "string" || type === "symbol" || type === "bigint";
205
+ };
206
+ var compareArrays = (left, right) => {
207
+ if (left.length !== right.length) {
208
+ return false;
205
209
  }
206
- if (Array.isArray(left)) {
207
- return Array.isArray(right) && left.length === right.length && left.every((val, index) => deepEquals(val, right[index]));
210
+ for (let i = 0; i < left.length; i++) {
211
+ const leftHas = i in left;
212
+ const rightHas = i in right;
213
+ if (leftHas !== rightHas) return false;
214
+ if (leftHas && !deepEquals(left[i], right[i])) return false;
208
215
  }
209
- if (typeof left !== "object" || typeof right !== "object" || left === null || right === null) {
210
- return left === right;
216
+ return true;
217
+ };
218
+ var compareDates = (left, right) => {
219
+ return left.getTime() === right.getTime();
220
+ };
221
+ var compareRegExps = (left, right) => {
222
+ return left.toString() === right.toString();
223
+ };
224
+ var compareErrors = (left, right) => {
225
+ if (left.message !== right.message || left.name !== right.name) {
226
+ return false;
227
+ }
228
+ const leftKeys = Object.keys(left);
229
+ const rightKeys = Object.keys(right);
230
+ if (leftKeys.length !== rightKeys.length) return false;
231
+ const rightKeySet = new Set(rightKeys);
232
+ for (const key of leftKeys) {
233
+ if (!rightKeySet.has(key)) return false;
234
+ if (!deepEquals(left[key], right[key])) return false;
235
+ }
236
+ return true;
237
+ };
238
+ var compareMaps = (left, right) => {
239
+ if (left.size !== right.size) return false;
240
+ for (const [key, value] of left) {
241
+ if (isPrimitive(key)) {
242
+ if (!right.has(key) || !deepEquals(value, right.get(key))) {
243
+ return false;
244
+ }
245
+ } else {
246
+ let found = false;
247
+ for (const [rightKey, rightValue] of right) {
248
+ if (deepEquals(key, rightKey) && deepEquals(value, rightValue)) {
249
+ found = true;
250
+ break;
251
+ }
252
+ }
253
+ if (!found) return false;
254
+ }
211
255
  }
212
- if (Array.isArray(right)) return false;
256
+ return true;
257
+ };
258
+ var compareSets = (left, right) => {
259
+ if (left.size !== right.size) return false;
260
+ for (const leftItem of left) {
261
+ if (isPrimitive(leftItem)) {
262
+ if (!right.has(leftItem)) return false;
263
+ } else {
264
+ let found = false;
265
+ for (const rightItem of right) {
266
+ if (deepEquals(leftItem, rightItem)) {
267
+ found = true;
268
+ break;
269
+ }
270
+ }
271
+ if (!found) return false;
272
+ }
273
+ }
274
+ return true;
275
+ };
276
+ var compareArrayBuffers = (left, right) => {
277
+ if (left.byteLength !== right.byteLength) return false;
278
+ const leftView = new Uint8Array(left);
279
+ const rightView = new Uint8Array(right);
280
+ for (let i = 0; i < leftView.length; i++) {
281
+ if (leftView[i] !== rightView[i]) return false;
282
+ }
283
+ return true;
284
+ };
285
+ var compareTypedArrays = (left, right) => {
286
+ if (left.constructor !== right.constructor) return false;
287
+ if (left.byteLength !== right.byteLength) return false;
288
+ const leftArray = new Uint8Array(
289
+ left.buffer,
290
+ left.byteOffset,
291
+ left.byteLength
292
+ );
293
+ const rightArray = new Uint8Array(
294
+ right.buffer,
295
+ right.byteOffset,
296
+ right.byteLength
297
+ );
298
+ for (let i = 0; i < leftArray.length; i++) {
299
+ if (leftArray[i] !== rightArray[i]) return false;
300
+ }
301
+ return true;
302
+ };
303
+ var compareObjects = (left, right) => {
213
304
  const keys1 = Object.keys(left);
214
305
  const keys2 = Object.keys(right);
215
- if (keys1.length !== keys2.length || !keys1.every((key) => keys2.includes(key)))
306
+ if (keys1.length !== keys2.length) {
216
307
  return false;
217
- for (const key in left) {
218
- if (left[key] instanceof Function && right[key] instanceof Function)
308
+ }
309
+ for (const key of keys1) {
310
+ if (left[key] instanceof Function && right[key] instanceof Function) {
219
311
  continue;
312
+ }
220
313
  const isEqual = deepEquals(left[key], right[key]);
221
314
  if (!isEqual) {
222
315
  return false;
@@ -224,8 +317,88 @@ var deepEquals = (left, right) => {
224
317
  }
225
318
  return true;
226
319
  };
320
+ var getType = (value) => {
321
+ if (value === null) return "null";
322
+ if (value === void 0) return "undefined";
323
+ const primitiveType = typeof value;
324
+ if (primitiveType !== "object") return primitiveType;
325
+ if (Array.isArray(value)) return "array";
326
+ if (value instanceof Boolean) return "boxed-boolean";
327
+ if (value instanceof Number) return "boxed-number";
328
+ if (value instanceof String) return "boxed-string";
329
+ if (value instanceof Date) return "date";
330
+ if (value instanceof RegExp) return "regexp";
331
+ if (value instanceof Error) return "error";
332
+ if (value instanceof Map) return "map";
333
+ if (value instanceof Set) return "set";
334
+ if (value instanceof ArrayBuffer) return "arraybuffer";
335
+ if (value instanceof DataView) return "dataview";
336
+ if (value instanceof WeakMap) return "weakmap";
337
+ if (value instanceof WeakSet) return "weakset";
338
+ if (ArrayBuffer.isView(value)) return "typedarray";
339
+ return "object";
340
+ };
341
+ var deepEquals = (left, right) => {
342
+ if (left === right) return true;
343
+ if (isEquatable(left)) {
344
+ return left.equals(right);
345
+ }
346
+ const leftType = getType(left);
347
+ const rightType = getType(right);
348
+ if (leftType !== rightType) return false;
349
+ switch (leftType) {
350
+ case "null":
351
+ case "undefined":
352
+ case "boolean":
353
+ case "number":
354
+ case "bigint":
355
+ case "string":
356
+ case "symbol":
357
+ case "function":
358
+ return left === right;
359
+ case "array":
360
+ return compareArrays(left, right);
361
+ case "date":
362
+ return compareDates(left, right);
363
+ case "regexp":
364
+ return compareRegExps(left, right);
365
+ case "error":
366
+ return compareErrors(left, right);
367
+ case "map":
368
+ return compareMaps(
369
+ left,
370
+ right
371
+ );
372
+ case "set":
373
+ return compareSets(left, right);
374
+ case "arraybuffer":
375
+ return compareArrayBuffers(left, right);
376
+ case "dataview":
377
+ case "weakmap":
378
+ case "weakset":
379
+ return false;
380
+ case "typedarray":
381
+ return compareTypedArrays(
382
+ left,
383
+ right
384
+ );
385
+ case "boxed-boolean":
386
+ return left.valueOf() === right.valueOf();
387
+ case "boxed-number":
388
+ return left.valueOf() === right.valueOf();
389
+ case "boxed-string":
390
+ return left.valueOf() === right.valueOf();
391
+ case "object":
392
+ return compareObjects(
393
+ left,
394
+ right
395
+ );
396
+ default:
397
+ return false;
398
+ }
399
+ };
227
400
  var isEquatable = (left) => {
228
- return left && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
401
+ return left !== null && left !== void 0 && typeof left === "object" && "equals" in left && typeof left["equals"] === "function";
229
402
  };
230
403
 
231
404
  // src/utils/iterators.ts
@@ -1602,6 +1775,7 @@ var CommandHandler = (options) => async (store, id, handle, handleOptions) => as
1602
1775
  evolve,
1603
1776
  initialState,
1604
1777
  read: {
1778
+ ...handleOptions ? handleOptions : {},
1605
1779
  // expected stream version is passed to fail fast
1606
1780
  // if stream is in the wrong state
1607
1781
  expectedStreamVersion: _nullishCoalesce(_optionalChain([handleOptions, 'optionalAccess', _87 => _87.expectedStreamVersion]), () => ( NO_CONCURRENCY_CHECK))