@livestore/utils 0.3.1 → 0.3.2-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/NoopTracer.d.ts +1 -0
- package/dist/NoopTracer.d.ts.map +1 -1
- package/dist/NoopTracer.js +1 -1
- package/dist/NoopTracer.js.map +1 -1
- package/dist/base64.js +2 -1
- package/dist/base64.js.map +1 -1
- package/dist/cuid/cuid.browser.js +12 -9
- package/dist/cuid/cuid.browser.js.map +1 -1
- package/dist/cuid/cuid.node.js +17 -10
- package/dist/cuid/cuid.node.js.map +1 -1
- package/dist/effect/WebChannel/WebChannel.d.ts +10 -14
- package/dist/effect/WebChannel/WebChannel.d.ts.map +1 -1
- package/dist/effect/WebChannel/WebChannel.js +1 -2
- package/dist/effect/WebChannel/WebChannel.js.map +1 -1
- package/dist/effect/WebLock.d.ts +1 -1
- package/dist/effect/WebLock.d.ts.map +1 -1
- package/dist/effect/WebLock.js.map +1 -1
- package/dist/fast-deep-equal.d.ts.map +1 -1
- package/dist/fast-deep-equal.js +9 -7
- package/dist/fast-deep-equal.js.map +1 -1
- package/dist/index.d.ts +10 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -11
- package/dist/index.js.map +1 -1
- package/dist/misc.d.ts.map +1 -1
- package/dist/misc.js +3 -2
- package/dist/misc.js.map +1 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.d.ts.map +1 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js +3 -2
- package/dist/node/ChildProcessRunner/ChildProcessRunner.js.map +1 -1
- package/dist/node/ChildProcessRunner/ChildProcessRunnerTest/schema.d.ts +4 -4
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts +1 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.d.ts.map +1 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js +0 -1
- package/dist/node/ChildProcessRunner/ChildProcessWorker.js.map +1 -1
- package/package.json +46 -40
- package/src/NoopTracer.ts +2 -1
- package/src/base64.ts +2 -2
- package/src/cuid/cuid.browser.ts +20 -20
- package/src/cuid/cuid.node.ts +34 -34
- package/src/effect/WebChannel/WebChannel.ts +12 -16
- package/src/effect/WebLock.ts +1 -1
- package/src/fast-deep-equal.ts +9 -8
- package/src/index.ts +16 -11
- package/src/misc.ts +3 -2
- package/src/node/ChildProcessRunner/ChildProcessRunner.ts +1 -1
- package/src/node/ChildProcessRunner/ChildProcessWorker.ts +1 -4
package/src/fast-deep-equal.ts
CHANGED
|
@@ -6,14 +6,16 @@
|
|
|
6
6
|
export const deepEqual = <T>(a: T, b: T): boolean => {
|
|
7
7
|
if (a === b) return true
|
|
8
8
|
|
|
9
|
-
if (a && b && typeof a
|
|
9
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
10
10
|
if (a.constructor !== b.constructor) return false
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
let length: number
|
|
13
|
+
let i: any
|
|
14
|
+
let keys: any
|
|
13
15
|
if (Array.isArray(a)) {
|
|
14
16
|
length = a.length
|
|
15
17
|
// @ts-expect-error ...
|
|
16
|
-
if (length
|
|
18
|
+
if (length !== b.length) return false
|
|
17
19
|
for (i = length; i-- !== 0; )
|
|
18
20
|
// @ts-expect-error ...
|
|
19
21
|
if (!deepEqual(a[i], b[i])) return false
|
|
@@ -37,7 +39,7 @@ export const deepEqual = <T>(a: T, b: T): boolean => {
|
|
|
37
39
|
// @ts-expect-error ...
|
|
38
40
|
length = a.length
|
|
39
41
|
// @ts-expect-error ...
|
|
40
|
-
if (length
|
|
42
|
+
if (length !== b.length) return false
|
|
41
43
|
for (i = length; i-- !== 0; )
|
|
42
44
|
// @ts-expect-error ...
|
|
43
45
|
if (a[i] !== b[i]) return false
|
|
@@ -53,12 +55,10 @@ export const deepEqual = <T>(a: T, b: T): boolean => {
|
|
|
53
55
|
length = keys.length
|
|
54
56
|
if (length !== Object.keys(b).length) return false
|
|
55
57
|
|
|
56
|
-
for (i = length; i-- !== 0; )
|
|
57
|
-
// @ts-expect-error ...
|
|
58
|
-
if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false
|
|
58
|
+
for (i = length; i-- !== 0; ) if (!Object.hasOwn(b, keys[i])) return false
|
|
59
59
|
|
|
60
60
|
for (i = length; i-- !== 0; ) {
|
|
61
|
-
|
|
61
|
+
const key = keys[i]
|
|
62
62
|
|
|
63
63
|
// @ts-expect-error ...
|
|
64
64
|
if (!deepEqual(a[key], b[key])) return false
|
|
@@ -68,5 +68,6 @@ export const deepEqual = <T>(a: T, b: T): boolean => {
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
// true if both NaN, false otherwise
|
|
71
|
+
// biome-ignore lint/suspicious/noSelfCompare: comparing to itself is fine here
|
|
71
72
|
return a !== a && b !== b
|
|
72
73
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './object/index.js'
|
|
4
|
-
export * from './promise.js'
|
|
5
|
-
export * from './time.js'
|
|
6
|
-
export * from './NoopTracer.js'
|
|
7
|
-
export * from './set.js'
|
|
1
|
+
export { default as prettyBytes } from 'pretty-bytes'
|
|
2
|
+
export * as base64 from './base64.js'
|
|
8
3
|
export * from './browser.js'
|
|
9
4
|
export * from './Deferred.js'
|
|
10
|
-
export * from './misc.js'
|
|
11
5
|
export * from './env.js'
|
|
12
6
|
export * from './fast-deep-equal.js'
|
|
13
|
-
export *
|
|
14
|
-
export
|
|
7
|
+
export * from './guards.js'
|
|
8
|
+
export * from './misc.js'
|
|
9
|
+
export * from './NoopTracer.js'
|
|
10
|
+
export * from './object/index.js'
|
|
11
|
+
export * from './promise.js'
|
|
12
|
+
export * from './set.js'
|
|
13
|
+
export * from './string.js'
|
|
14
|
+
export * from './time.js'
|
|
15
15
|
|
|
16
16
|
import type * as otel from '@opentelemetry/api'
|
|
17
17
|
import type { Types } from 'effect'
|
|
@@ -53,6 +53,7 @@ export const debugCatch = <T>(try_: () => T): T => {
|
|
|
53
53
|
try {
|
|
54
54
|
return try_()
|
|
55
55
|
} catch (e: any) {
|
|
56
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
56
57
|
debugger
|
|
57
58
|
throw e
|
|
58
59
|
}
|
|
@@ -87,31 +88,35 @@ export const isReadonlyArray = <I, T>(value: ReadonlyArray<I> | T): value is Rea
|
|
|
87
88
|
*/
|
|
88
89
|
/* eslint-disable-next-line prefer-arrow/prefer-arrow-functions */
|
|
89
90
|
export function casesHandled(unexpectedCase: never): never {
|
|
91
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
90
92
|
debugger
|
|
91
93
|
throw new Error(`A case was not handled for value: ${truncate(objectToString(unexpectedCase), 1000)}`)
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
export const assertNever = (failIfFalse: boolean, msg?: string): void => {
|
|
95
97
|
if (failIfFalse === false) {
|
|
98
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
96
99
|
debugger
|
|
97
100
|
throw new Error(`This should never happen: ${msg}`)
|
|
98
101
|
}
|
|
99
102
|
}
|
|
100
103
|
|
|
101
104
|
export const debuggerPipe = <T>(val: T): T => {
|
|
105
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
102
106
|
debugger
|
|
103
107
|
return val
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
const truncate = (str: string, length: number): string => {
|
|
107
111
|
if (str.length > length) {
|
|
108
|
-
return str.slice(0, length)
|
|
112
|
+
return `${str.slice(0, length)}...`
|
|
109
113
|
} else {
|
|
110
114
|
return str
|
|
111
115
|
}
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
export const notYetImplemented = (msg?: string): never => {
|
|
119
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
115
120
|
debugger
|
|
116
121
|
throw new Error(`Not yet implemented: ${msg}`)
|
|
117
122
|
}
|
package/src/misc.ts
CHANGED
|
@@ -26,7 +26,7 @@ export const objectToString = (error: any): string => {
|
|
|
26
26
|
} catch (e: any) {
|
|
27
27
|
console.log(error)
|
|
28
28
|
|
|
29
|
-
return
|
|
29
|
+
return `Error while printing error: ${e}`
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -38,7 +38,7 @@ export const tryAsFunctionAndNew = <TArg, TResult>(
|
|
|
38
38
|
// @ts-expect-error try out as constructor
|
|
39
39
|
return new fnOrConstructor(arg)
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
41
|
-
} catch (
|
|
41
|
+
} catch (_e) {
|
|
42
42
|
// @ts-expect-error try out as function
|
|
43
43
|
return fnOrConstructor(arg)
|
|
44
44
|
}
|
|
@@ -50,6 +50,7 @@ export const envTruish = (env: string | undefined) =>
|
|
|
50
50
|
export const shouldNeverHappen = (msg?: string, ...args: any[]): never => {
|
|
51
51
|
console.error(msg, ...args)
|
|
52
52
|
if (isDevEnv()) {
|
|
53
|
+
// biome-ignore lint/suspicious/noDebugger: debugging
|
|
53
54
|
debugger
|
|
54
55
|
}
|
|
55
56
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable prefer-arrow/prefer-arrow-functions */
|
|
2
1
|
import process from 'node:process'
|
|
3
2
|
|
|
4
3
|
import { WorkerError } from '@effect/platform/WorkerError'
|
|
@@ -30,6 +29,7 @@ const platformRunnerImpl = Runner.PlatformRunner.of({
|
|
|
30
29
|
Effect.sync(() => port.postMessage([1, message] /*, transfers as any*/))
|
|
31
30
|
|
|
32
31
|
const run = Effect.fnUntraced(function* <A, E, R>(
|
|
32
|
+
// biome-ignore lint/suspicious/noConfusingVoidType: need to support void
|
|
33
33
|
handler: (portId: number, message: I) => Effect.Effect<A, E, R> | void,
|
|
34
34
|
) {
|
|
35
35
|
const runtime = (yield* Effect.interruptible(Effect.runtime<R | Scope.Scope>())).pipe(
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type * as ChildProcess from 'node:child_process'
|
|
3
2
|
import * as Worker from '@effect/platform/Worker'
|
|
4
3
|
import { WorkerError } from '@effect/platform/WorkerError'
|
|
5
|
-
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
6
|
-
import type * as ChildProcess from 'child_process'
|
|
7
4
|
import * as Deferred from 'effect/Deferred'
|
|
8
5
|
import * as Effect from 'effect/Effect'
|
|
9
6
|
import * as Exit from 'effect/Exit'
|