@livestore/utils 0.0.54-dev.5 → 0.0.55-dev.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/dist/.tsbuildinfo.json +1 -1
- package/dist/Deferred.d.ts.map +1 -1
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/effect/Effect.d.ts +12 -5
- package/dist/effect/Effect.d.ts.map +1 -1
- package/dist/effect/Effect.js +59 -18
- package/dist/effect/Effect.js.map +1 -1
- package/dist/effect/Error.d.ts +8 -9
- package/dist/effect/Error.d.ts.map +1 -1
- package/dist/effect/Error.js +5 -8
- package/dist/effect/Error.js.map +1 -1
- package/dist/effect/Scheduler.d.ts +4 -0
- package/dist/effect/Scheduler.d.ts.map +1 -0
- package/dist/effect/Scheduler.js +10 -0
- package/dist/effect/Scheduler.js.map +1 -0
- package/dist/effect/Schema/debug-diff.d.ts +13 -0
- package/dist/effect/Schema/debug-diff.d.ts.map +1 -0
- package/dist/effect/Schema/debug-diff.js +51 -0
- package/dist/effect/Schema/debug-diff.js.map +1 -0
- package/dist/effect/Schema/debug-diff.test.d.ts +2 -0
- package/dist/effect/Schema/debug-diff.test.d.ts.map +1 -0
- package/dist/effect/Schema/debug-diff.test.js +91 -0
- package/dist/effect/Schema/debug-diff.test.js.map +1 -0
- package/dist/effect/Schema/index.d.ts +15 -0
- package/dist/effect/Schema/index.d.ts.map +1 -0
- package/dist/effect/Schema/index.js +46 -0
- package/dist/effect/Schema/index.js.map +1 -0
- package/dist/effect/Schema.d.ts.map +1 -1
- package/dist/effect/ServiceContext.d.ts.map +1 -1
- package/dist/effect/Stream.d.ts +2 -0
- package/dist/effect/Stream.d.ts.map +1 -1
- package/dist/effect/Stream.js +11 -1
- package/dist/effect/Stream.js.map +1 -1
- package/dist/effect/SubscriptionRef.d.ts +8 -3
- package/dist/effect/SubscriptionRef.d.ts.map +1 -1
- package/dist/effect/SubscriptionRef.js +2 -2
- package/dist/effect/SubscriptionRef.js.map +1 -1
- package/dist/effect/WebLock.d.ts +5 -1
- package/dist/effect/WebLock.d.ts.map +1 -1
- package/dist/effect/WebLock.js +42 -11
- package/dist/effect/WebLock.js.map +1 -1
- package/dist/effect/browser-worker-tmp/BrowserWorker.d.ts +21 -0
- package/dist/effect/browser-worker-tmp/BrowserWorker.d.ts.map +1 -0
- package/dist/effect/browser-worker-tmp/BrowserWorker.js +17 -0
- package/dist/effect/browser-worker-tmp/BrowserWorker.js.map +1 -0
- package/dist/effect/browser-worker-tmp/BrowserWorkerRunner.d.ts +12 -0
- package/dist/effect/browser-worker-tmp/BrowserWorkerRunner.d.ts.map +1 -0
- package/dist/effect/browser-worker-tmp/BrowserWorkerRunner.js +8 -0
- package/dist/effect/browser-worker-tmp/BrowserWorkerRunner.js.map +1 -0
- package/dist/effect/browser-worker-tmp/internal/worker.d.ts +9 -0
- package/dist/effect/browser-worker-tmp/internal/worker.d.ts.map +1 -0
- package/dist/effect/browser-worker-tmp/internal/worker.js +56 -0
- package/dist/effect/browser-worker-tmp/internal/worker.js.map +1 -0
- package/dist/effect/browser-worker-tmp/internal/workerRunner.d.ts +5 -0
- package/dist/effect/browser-worker-tmp/internal/workerRunner.d.ts.map +1 -0
- package/dist/effect/browser-worker-tmp/internal/workerRunner.js +100 -0
- package/dist/effect/browser-worker-tmp/internal/workerRunner.js.map +1 -0
- package/dist/effect/browser-worker-tmp/port-platform-runner.d.ts +5 -0
- package/dist/effect/browser-worker-tmp/port-platform-runner.d.ts.map +1 -0
- package/dist/effect/browser-worker-tmp/port-platform-runner.js +54 -0
- package/dist/effect/browser-worker-tmp/port-platform-runner.js.map +1 -0
- package/dist/effect/index.d.ts +10 -5
- package/dist/effect/index.d.ts.map +1 -1
- package/dist/effect/index.js +12 -5
- package/dist/effect/index.js.map +1 -1
- package/dist/effect/worker-tmp/Worker.d.ts +290 -0
- package/dist/effect/worker-tmp/Worker.d.ts.map +1 -0
- package/dist/effect/worker-tmp/Worker.js +62 -0
- package/dist/effect/worker-tmp/Worker.js.map +1 -0
- package/dist/effect/worker-tmp/WorkerError.d.ts +63 -0
- package/dist/effect/worker-tmp/WorkerError.d.ts.map +1 -0
- package/dist/effect/worker-tmp/WorkerError.js +52 -0
- package/dist/effect/worker-tmp/WorkerError.js.map +1 -0
- package/dist/effect/worker-tmp/WorkerRunner.d.ts +119 -0
- package/dist/effect/worker-tmp/WorkerRunner.d.ts.map +1 -0
- package/dist/effect/worker-tmp/WorkerRunner.js +32 -0
- package/dist/effect/worker-tmp/WorkerRunner.js.map +1 -0
- package/dist/effect/worker-tmp/internal/worker.d.ts +36 -0
- package/dist/effect/worker-tmp/internal/worker.d.ts.map +1 -0
- package/dist/effect/worker-tmp/internal/worker.js +244 -0
- package/dist/effect/worker-tmp/internal/worker.js.map +1 -0
- package/dist/effect/worker-tmp/internal/workerError.d.ts +4 -0
- package/dist/effect/worker-tmp/internal/workerError.d.ts.map +1 -0
- package/dist/effect/worker-tmp/internal/workerError.js +3 -0
- package/dist/effect/worker-tmp/internal/workerError.js.map +1 -0
- package/dist/effect/worker-tmp/internal/workerRunner.d.ts +21 -0
- package/dist/effect/worker-tmp/internal/workerRunner.d.ts.map +1 -0
- package/dist/effect/worker-tmp/internal/workerRunner.js +137 -0
- package/dist/effect/worker-tmp/internal/workerRunner.js.map +1 -0
- package/dist/fast-deep-equal.d.ts +2 -0
- package/dist/fast-deep-equal.d.ts.map +1 -0
- package/dist/fast-deep-equal.js +79 -0
- package/dist/fast-deep-equal.js.map +1 -0
- package/dist/guards.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -19
- package/dist/index.js.map +1 -1
- package/dist/misc.d.ts +2 -0
- package/dist/misc.d.ts.map +1 -0
- package/dist/misc.js +13 -0
- package/dist/misc.js.map +1 -0
- package/dist/object/index.d.ts.map +1 -1
- package/dist/object/omit.d.ts.map +1 -1
- package/dist/object/pick.d.ts +1 -1
- package/dist/object/pick.d.ts.map +1 -1
- package/dist/promise.d.ts.map +1 -1
- package/dist/set.d.ts.map +1 -1
- package/package.json +18 -17
- package/src/effect/Effect.ts +96 -26
- package/src/effect/Error.ts +5 -14
- package/src/effect/Scheduler.ts +14 -0
- package/src/effect/Schema/debug-diff.test.ts +102 -0
- package/src/effect/Schema/debug-diff.ts +59 -0
- package/src/effect/Schema/index.ts +60 -0
- package/src/effect/Stream.ts +37 -1
- package/src/effect/SubscriptionRef.ts +22 -7
- package/src/effect/WebLock.ts +69 -31
- package/src/effect/browser-worker-tmp/BrowserWorker.ts +26 -0
- package/src/effect/browser-worker-tmp/BrowserWorkerRunner.ts +14 -0
- package/src/effect/browser-worker-tmp/internal/worker.ts +71 -0
- package/src/effect/browser-worker-tmp/internal/workerRunner.ts +119 -0
- package/src/effect/browser-worker-tmp/port-platform-runner.ts +74 -0
- package/src/effect/index.ts +17 -4
- package/src/effect/worker-tmp/Worker.ts +374 -0
- package/src/effect/worker-tmp/WorkerError.ts +79 -0
- package/src/effect/worker-tmp/WorkerRunner.ts +181 -0
- package/src/effect/worker-tmp/internal/worker.ts +417 -0
- package/src/effect/worker-tmp/internal/workerError.ts +6 -0
- package/src/effect/worker-tmp/internal/workerRunner.ts +237 -0
- package/src/fast-deep-equal.ts +72 -0
- package/src/index.ts +21 -22
- package/src/misc.ts +12 -0
- package/src/effect/Schema.ts +0 -18
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/* eslint-disable no-var */
|
|
2
|
+
|
|
3
|
+
// Copied from fast-deep-equal
|
|
4
|
+
// MIT License
|
|
5
|
+
|
|
6
|
+
export const deepEqual = <T>(a: T, b: T): boolean => {
|
|
7
|
+
if (a === b) return true
|
|
8
|
+
|
|
9
|
+
if (a && b && typeof a == 'object' && typeof b == 'object') {
|
|
10
|
+
if (a.constructor !== b.constructor) return false
|
|
11
|
+
|
|
12
|
+
var length, i, keys
|
|
13
|
+
if (Array.isArray(a)) {
|
|
14
|
+
length = a.length
|
|
15
|
+
// @ts-expect-error ...
|
|
16
|
+
if (length != b.length) return false
|
|
17
|
+
for (i = length; i-- !== 0; )
|
|
18
|
+
// @ts-expect-error ...
|
|
19
|
+
if (!deepEqual(a[i], b[i])) return false
|
|
20
|
+
return true
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (a instanceof Map && b instanceof Map) {
|
|
24
|
+
if (a.size !== b.size) return false
|
|
25
|
+
for (i of a.entries()) if (!b.has(i[0])) return false
|
|
26
|
+
for (i of a.entries()) if (!deepEqual(i[1], b.get(i[0]))) return false
|
|
27
|
+
return true
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (a instanceof Set && b instanceof Set) {
|
|
31
|
+
if (a.size !== b.size) return false
|
|
32
|
+
for (i of a.entries()) if (!b.has(i[0])) return false
|
|
33
|
+
return true
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (ArrayBuffer.isView(a) && ArrayBuffer.isView(b)) {
|
|
37
|
+
// @ts-expect-error ...
|
|
38
|
+
length = a.length
|
|
39
|
+
// @ts-expect-error ...
|
|
40
|
+
if (length != b.length) return false
|
|
41
|
+
for (i = length; i-- !== 0; )
|
|
42
|
+
// @ts-expect-error ...
|
|
43
|
+
if (a[i] !== b[i]) return false
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// @ts-expect-error ...
|
|
48
|
+
if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags
|
|
49
|
+
if (a.valueOf !== undefined && a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf()
|
|
50
|
+
if (a.toString !== undefined && a.toString !== Object.prototype.toString) return a.toString() === b.toString()
|
|
51
|
+
|
|
52
|
+
keys = Object.keys(a)
|
|
53
|
+
length = keys.length
|
|
54
|
+
if (length !== Object.keys(b).length) return false
|
|
55
|
+
|
|
56
|
+
for (i = length; i-- !== 0; )
|
|
57
|
+
// @ts-expect-error ...
|
|
58
|
+
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false
|
|
59
|
+
|
|
60
|
+
for (i = length; i-- !== 0; ) {
|
|
61
|
+
var key = keys[i]
|
|
62
|
+
|
|
63
|
+
// @ts-expect-error ...
|
|
64
|
+
if (!deepEqual(a[key], b[key])) return false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return true
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// true if both NaN, false otherwise
|
|
71
|
+
return a !== a && b !== b
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -7,11 +7,15 @@ export * from './NoopTracer.js'
|
|
|
7
7
|
export * from './set.js'
|
|
8
8
|
export * from './browser.js'
|
|
9
9
|
export * from './Deferred.js'
|
|
10
|
+
export * from './misc.js'
|
|
11
|
+
export * from './fast-deep-equal.js'
|
|
10
12
|
export * as base64 from './base64.js'
|
|
11
13
|
export { default as prettyBytes } from 'pretty-bytes'
|
|
12
14
|
|
|
13
15
|
import type * as otel from '@opentelemetry/api'
|
|
14
16
|
|
|
17
|
+
import { objectToString } from './misc.js'
|
|
18
|
+
|
|
15
19
|
export * as dateFns from 'date-fns'
|
|
16
20
|
|
|
17
21
|
export type Prettify<T> = T extends infer U ? { [K in keyof U]: Prettify<U[K]> } : never
|
|
@@ -65,30 +69,11 @@ export const recRemoveUndefinedValues = (val: any): void => {
|
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
export const debugDeepCopy = <T>(val: T): T => JSON.parse(JSON.stringify(val))
|
|
69
|
-
|
|
70
72
|
export const prop =
|
|
71
73
|
<T extends {}, K extends keyof T>(key: K) =>
|
|
72
74
|
(obj: T): T[K] =>
|
|
73
75
|
obj[key]
|
|
74
76
|
|
|
75
|
-
export const objectToString = (error: any): string => {
|
|
76
|
-
const stack = error.stack
|
|
77
|
-
const str = error.toString()
|
|
78
|
-
const stackStr = stack ? `\n${stack}` : ''
|
|
79
|
-
if (str !== '[object Object]') return str + stackStr
|
|
80
|
-
|
|
81
|
-
try {
|
|
82
|
-
return JSON.stringify({ ...error, stack }, null, 2)
|
|
83
|
-
} catch (e: any) {
|
|
84
|
-
console.log(error)
|
|
85
|
-
|
|
86
|
-
return 'Error while printing error: ' + e
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const errorToString = objectToString
|
|
91
|
-
|
|
92
77
|
export const capitalizeFirstLetter = (str: string): string => str.charAt(0).toUpperCase() + str.slice(1)
|
|
93
78
|
|
|
94
79
|
export const isReadonlyArray = <I, T>(value: ReadonlyArray<I> | T): value is ReadonlyArray<I> => Array.isArray(value)
|
|
@@ -104,8 +89,8 @@ export function casesHandled(unexpectedCase: never): never {
|
|
|
104
89
|
}
|
|
105
90
|
|
|
106
91
|
export const shouldNeverHappen = (msg?: string, ...args: any[]): never => {
|
|
107
|
-
|
|
108
|
-
|
|
92
|
+
console.error(msg, ...args)
|
|
93
|
+
if (isDev()) {
|
|
109
94
|
debugger
|
|
110
95
|
}
|
|
111
96
|
|
|
@@ -236,8 +221,22 @@ export const memoizeByRef = <T extends (arg: any) => any>(fn: T): T => {
|
|
|
236
221
|
}) as any
|
|
237
222
|
}
|
|
238
223
|
|
|
239
|
-
export const isNonEmptyString = (str: string | undefined | null)
|
|
224
|
+
export const isNonEmptyString = (str: string | undefined | null): str is string => {
|
|
225
|
+
return typeof str === 'string' && str.length > 0
|
|
226
|
+
}
|
|
240
227
|
|
|
241
228
|
export const isPromise = (value: any): value is Promise<unknown> => typeof value?.then === 'function'
|
|
242
229
|
|
|
243
230
|
export const isIterable = <T>(value: any): value is Iterable<T> => typeof value?.[Symbol.iterator] === 'function'
|
|
231
|
+
|
|
232
|
+
export { objectToString as errorToString } from './misc.js'
|
|
233
|
+
|
|
234
|
+
const isDev = memoizeByRef(() => {
|
|
235
|
+
if (import.meta.env !== undefined) {
|
|
236
|
+
return import.meta.env.DEV || import.meta.env.VITE_DEV
|
|
237
|
+
} else if (typeof process !== 'undefined' && process.env !== undefined) {
|
|
238
|
+
return process.env.DEV
|
|
239
|
+
} else {
|
|
240
|
+
return false
|
|
241
|
+
}
|
|
242
|
+
})
|
package/src/misc.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export const objectToString = (error: any): string => {
|
|
2
|
+
const str = error?.toString()
|
|
3
|
+
if (str !== '[object Object]') return str
|
|
4
|
+
|
|
5
|
+
try {
|
|
6
|
+
return JSON.stringify(error, null, 2)
|
|
7
|
+
} catch (e: any) {
|
|
8
|
+
console.log(error)
|
|
9
|
+
|
|
10
|
+
return 'Error while printing error: ' + e
|
|
11
|
+
}
|
|
12
|
+
}
|
package/src/effect/Schema.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Schema } from '@effect/schema'
|
|
2
|
-
import { Hash } from 'effect'
|
|
3
|
-
|
|
4
|
-
export * from '@effect/schema/Schema'
|
|
5
|
-
|
|
6
|
-
// NOTE this is a temporary workaround until Effect schema has a better way to hash schemas
|
|
7
|
-
// https://github.com/Effect-TS/effect/issues/2719
|
|
8
|
-
// TODO remove this once the issue is resolved
|
|
9
|
-
export const hash = (schema: Schema.Schema<any>) => {
|
|
10
|
-
try {
|
|
11
|
-
return Hash.string(JSON.stringify(schema.ast, null, 2))
|
|
12
|
-
} catch {
|
|
13
|
-
console.warn(
|
|
14
|
-
`Schema hashing failed, falling back to hashing the shortend schema AST string. This is less reliable and may cause false positives.`,
|
|
15
|
-
)
|
|
16
|
-
return Hash.hash(schema.ast.toString())
|
|
17
|
-
}
|
|
18
|
-
}
|