@livestore/utils 0.0.58-dev.0 → 0.0.58-dev.10

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 (62) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/cuid/cuid.browser.d.ts.map +1 -1
  3. package/dist/cuid/cuid.browser.js +1 -0
  4. package/dist/cuid/cuid.browser.js.map +1 -1
  5. package/dist/effect/Effect.d.ts.map +1 -1
  6. package/dist/effect/Effect.js +4 -3
  7. package/dist/effect/Effect.js.map +1 -1
  8. package/dist/effect/Error.d.ts +1 -1
  9. package/dist/effect/Error.d.ts.map +1 -1
  10. package/dist/effect/Error.js +1 -1
  11. package/dist/effect/Error.js.map +1 -1
  12. package/dist/effect/Schema/debug-diff.d.ts +2 -3
  13. package/dist/effect/Schema/debug-diff.d.ts.map +1 -1
  14. package/dist/effect/Schema/debug-diff.js +8 -8
  15. package/dist/effect/Schema/debug-diff.js.map +1 -1
  16. package/dist/effect/Schema/debug-diff.test.js +1 -1
  17. package/dist/effect/Schema/debug-diff.test.js.map +1 -1
  18. package/dist/effect/Schema/index.d.ts +11 -5
  19. package/dist/effect/Schema/index.d.ts.map +1 -1
  20. package/dist/effect/Schema/index.js +3 -3
  21. package/dist/effect/Schema/index.js.map +1 -1
  22. package/dist/effect/Schema/msgpack.d.ts +1 -1
  23. package/dist/effect/Schema/msgpack.d.ts.map +1 -1
  24. package/dist/effect/Schema/msgpack.js +1 -1
  25. package/dist/effect/Schema/msgpack.js.map +1 -1
  26. package/dist/effect/WebChannel.d.ts +1 -2
  27. package/dist/effect/WebChannel.d.ts.map +1 -1
  28. package/dist/effect/WebChannel.js.map +1 -1
  29. package/dist/effect/index.d.ts +6 -3
  30. package/dist/effect/index.d.ts.map +1 -1
  31. package/dist/effect/index.js +5 -3
  32. package/dist/effect/index.js.map +1 -1
  33. package/dist/index.d.ts +0 -1
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +0 -1
  36. package/dist/index.js.map +1 -1
  37. package/dist/misc.d.ts.map +1 -1
  38. package/dist/misc.js +1 -0
  39. package/dist/misc.js.map +1 -1
  40. package/dist/nanoid/index.d.ts +2 -0
  41. package/dist/nanoid/index.d.ts.map +1 -0
  42. package/dist/nanoid/index.js +2 -0
  43. package/dist/nanoid/index.js.map +1 -0
  44. package/dist/string.d.ts +2 -0
  45. package/dist/string.d.ts.map +1 -1
  46. package/dist/string.js +5 -0
  47. package/dist/string.js.map +1 -1
  48. package/package.json +27 -21
  49. package/src/cuid/cuid.browser.ts +1 -0
  50. package/src/effect/Effect.ts +2 -1
  51. package/src/effect/Error.ts +1 -1
  52. package/src/effect/Schema/debug-diff.test.ts +1 -1
  53. package/src/effect/Schema/debug-diff.ts +11 -12
  54. package/src/effect/Schema/index.ts +19 -5
  55. package/src/effect/Schema/msgpack.ts +1 -1
  56. package/src/effect/WebChannel.ts +1 -2
  57. package/src/effect/index.ts +7 -9
  58. package/src/index.ts +0 -2
  59. package/src/misc.ts +1 -0
  60. package/src/nanoid/index.ts +1 -0
  61. package/src/string.ts +7 -0
  62. package/tsconfig.json +1 -1
package/package.json CHANGED
@@ -1,7 +1,9 @@
1
1
  {
2
2
  "name": "@livestore/utils",
3
- "version": "0.0.58-dev.0",
4
- "sideEffects": false,
3
+ "version": "0.0.58-dev.10",
4
+ "sideEffects": [
5
+ "./dist/global.js"
6
+ ],
5
7
  "type": "module",
6
8
  "exports": {
7
9
  ".": {
@@ -14,6 +16,10 @@
14
16
  "react-native": "./dist/cuid/cuid.browser.js",
15
17
  "browser": "./dist/cuid/cuid.browser.js"
16
18
  },
19
+ "./nanoid": {
20
+ "types": "./dist/nanoid/index.d.ts",
21
+ "default": "./dist/nanoid/index.js"
22
+ },
17
23
  "./effect": {
18
24
  "types": "./dist/effect/index.d.ts",
19
25
  "default": "./dist/effect/index.js"
@@ -26,38 +32,38 @@
26
32
  "./cuid": [
27
33
  "./dist/cuid/cuid.node.d.ts"
28
34
  ],
35
+ "./nanoid": [
36
+ "./dist/nanoid/index.d.ts"
37
+ ],
29
38
  "effect": [
30
39
  "./dist/effect"
31
40
  ]
32
41
  }
33
42
  },
34
43
  "dependencies": {
35
- "date-fns": "^3.6.0",
36
- "msgpackr": "^1.11.0",
37
- "otel-websocket-exporter": "^0.0.29",
44
+ "msgpackr": "^1.11.2",
45
+ "nanoid": "^5.0.7",
38
46
  "pretty-bytes": "^6.1.1",
39
- "effect-db-schema": "0.0.58-dev.0"
47
+ "@livestore/db-schema": "0.0.58-dev.10"
40
48
  },
41
49
  "peerDependencies": {
42
- "@effect/experimental": "^0.24.4",
43
- "@effect/opentelemetry": "^0.36.2",
44
- "@effect/platform": "^0.63.3",
45
- "@effect/platform-browser": "^0.42.3",
46
- "@effect/schema": "^0.72.2",
50
+ "@effect/experimental": "^0.30.13",
51
+ "@effect/opentelemetry": "^0.39.7",
52
+ "@effect/platform": "^0.69.12",
53
+ "@effect/platform-browser": "^0.48.12",
47
54
  "@opentelemetry/api": "^1.9.0",
48
- "effect": "^3.7.2"
55
+ "effect": "^3.10.7"
49
56
  },
50
57
  "devDependencies": {
51
- "@effect/experimental": "0.24.4",
52
- "@effect/opentelemetry": "0.36.2",
53
- "@effect/platform": "0.63.3",
54
- "@effect/platform-browser": "0.42.3",
55
- "@effect/schema": "0.72.2",
58
+ "@effect/experimental": "0.30.13",
59
+ "@effect/opentelemetry": "0.39.7",
60
+ "@effect/platform": "0.69.12",
61
+ "@effect/platform-browser": "0.48.12",
56
62
  "@opentelemetry/api": "^1.9.0",
57
- "@types/node": "^22.0.0",
58
- "@types/web": "^0.0.153",
59
- "effect": "3.7.2",
60
- "vitest": "^2.0.4"
63
+ "@types/node": "^22.8.5",
64
+ "@types/web": "^0.0.175",
65
+ "effect": "3.10.7",
66
+ "vitest": "^2.1.4"
61
67
  },
62
68
  "publishConfig": {
63
69
  "access": "public"
@@ -1,3 +1,4 @@
1
+ /* eslint-disable unicorn/prefer-global-this */
1
2
  /**
2
3
  * Based on:
3
4
  *
@@ -47,7 +47,8 @@ const getThreadName = () => {
47
47
  const globalName = globalThis.name
48
48
  return isNonEmptyString(globalName)
49
49
  ? globalName
50
- : typeof window === 'object'
50
+ : // eslint-disable-next-line unicorn/prefer-global-this
51
+ typeof window === 'object'
51
52
  ? 'Browser Main Thread'
52
53
  : 'unknown-thread'
53
54
  }
@@ -1,4 +1,4 @@
1
- import { Schema } from '@effect/schema'
1
+ import { Schema } from 'effect'
2
2
 
3
3
  export class UnknownError extends Schema.TaggedError<'UnknownError'>()('UnknownError', {
4
4
  cause: Schema.Any,
@@ -1,4 +1,4 @@
1
- import { Schema } from '@effect/schema'
1
+ import { Schema } from 'effect'
2
2
  import { describe, expect, test } from 'vitest'
3
3
 
4
4
  import type { DiffItem } from './debug-diff.js'
@@ -1,11 +1,10 @@
1
- import type { Schema } from '@effect/schema'
2
- import { AST, Equivalence } from '@effect/schema'
1
+ import { Schema, SchemaAST } from 'effect'
3
2
 
4
3
  export type DiffItem = {
5
4
  path: string
6
5
  a: any
7
6
  b: any
8
- ast: AST.AST
7
+ ast: SchemaAST.AST
9
8
  }
10
9
 
11
10
  /**
@@ -19,12 +18,12 @@ export const debugDiff =
19
18
  return bag
20
19
  }
21
20
 
22
- const debugDiffImpl = (ast: AST.AST, a: any, b: any, path: string, bag: DiffItem[]) => {
23
- const eq = Equivalence.make({ ast } as any)
21
+ const debugDiffImpl = (ast: SchemaAST.AST, a: any, b: any, path: string, bag: DiffItem[]) => {
22
+ const eq = Schema.equivalence({ ast } as any)
24
23
  if (eq(a, b) === false) {
25
24
  // bag.push({ path, a, b, ast })
26
25
 
27
- if (AST.isUnion(ast)) {
26
+ if (SchemaAST.isUnion(ast)) {
28
27
  if (isTaggedUnion(ast)) {
29
28
  bag.push({ path, a, b, ast })
30
29
  return
@@ -36,8 +35,8 @@ const debugDiffImpl = (ast: AST.AST, a: any, b: any, path: string, bag: DiffItem
36
35
  } catch {}
37
36
  }
38
37
  }
39
- } else if (AST.isTypeLiteral(ast)) {
40
- const props = AST.getPropertySignatures(ast)
38
+ } else if (SchemaAST.isTypeLiteral(ast)) {
39
+ const props = SchemaAST.getPropertySignatures(ast)
41
40
  for (const prop of props) {
42
41
  debugDiffImpl(prop.type, a[prop.name], b[prop.name], `${path}.${prop.name.toString()}`, bag)
43
42
  }
@@ -48,11 +47,11 @@ const debugDiffImpl = (ast: AST.AST, a: any, b: any, path: string, bag: DiffItem
48
47
  }
49
48
  }
50
49
 
51
- const isTaggedUnion = (ast: AST.AST) => {
52
- if (AST.isUnion(ast)) {
50
+ const isTaggedUnion = (ast: SchemaAST.AST) => {
51
+ if (SchemaAST.isUnion(ast)) {
53
52
  return ast.types.every((type) => {
54
- if (AST.isTypeLiteral(type) === false) return false
55
- const props = AST.getPropertySignatures(type)
53
+ if (SchemaAST.isTypeLiteral(type) === false) return false
54
+ const props = SchemaAST.getPropertySignatures(type)
56
55
  return props.some((prop) => prop.name.toString() === '_tag')
57
56
  })
58
57
  }
@@ -1,10 +1,9 @@
1
1
  import { Transferable } from '@effect/platform'
2
- import { ParseResult, Schema } from '@effect/schema'
3
- import type { ParseOptions } from '@effect/schema/AST'
4
- import type { ParseError } from '@effect/schema/ParseResult'
5
- import { Effect, Hash } from 'effect'
2
+ import { Effect, Hash, ParseResult, Schema } from 'effect'
3
+ import type { ParseError } from 'effect/ParseResult'
4
+ import type { ParseOptions } from 'effect/SchemaAST'
6
5
 
7
- export * from '@effect/schema/Schema'
6
+ export * from 'effect/Schema'
8
7
  export * from './debug-diff.js'
9
8
  export * from './msgpack.js'
10
9
 
@@ -42,3 +41,18 @@ export const swap = <A, I, R>(schema: Schema.Schema<A, I, R>): Schema.Schema<I,
42
41
  })
43
42
 
44
43
  export const Base64FromUint8Array: Schema.Schema<string, Uint8Array> = swap(Schema.Uint8ArrayFromBase64)
44
+
45
+ export interface JsonArray extends ReadonlyArray<JsonValue> {}
46
+ export interface JsonObject {
47
+ [key: string]: JsonValue
48
+ }
49
+ export type JsonValue = string | number | boolean | null | JsonObject | JsonArray
50
+
51
+ export const JsonValue: Schema.Schema<JsonValue> = Schema.Union(
52
+ Schema.String,
53
+ Schema.Number,
54
+ Schema.Boolean,
55
+ Schema.Null,
56
+ Schema.Array(Schema.suspend(() => JsonValue)),
57
+ Schema.Record({ key: Schema.String, value: Schema.suspend(() => JsonValue) }),
58
+ )
@@ -1,4 +1,4 @@
1
- import { Schema } from '@effect/schema'
1
+ import { Schema } from 'effect'
2
2
  import * as msgpack from 'msgpackr'
3
3
 
4
4
  export const MsgPack = <A, I>(schema: Schema.Schema<A, I>) =>
@@ -1,5 +1,4 @@
1
- import type { ParseResult } from '@effect/schema'
2
- import type { Scope } from 'effect'
1
+ import type { ParseResult, Scope } from 'effect'
3
2
  import { Deferred, Effect, Either, Queue, Stream } from 'effect'
4
3
 
5
4
  import * as Schema from './Schema/index.js'
@@ -38,6 +38,7 @@ export {
38
38
  HashMap,
39
39
  HashSet,
40
40
  MutableHashSet,
41
+ MutableHashMap,
41
42
  Option,
42
43
  LogLevel,
43
44
  Logger,
@@ -47,6 +48,7 @@ export {
47
48
  Channel,
48
49
  pipe,
49
50
  identity,
51
+ GlobalValue,
50
52
  Match,
51
53
  } from 'effect'
52
54
 
@@ -58,15 +60,10 @@ export * as SubscriptionRef from './SubscriptionRef.js'
58
60
 
59
61
  export * as WebChannel from './WebChannel.js'
60
62
 
61
- export {
62
- TreeFormatter,
63
- AST as SchemaAST,
64
- Pretty as SchemaPretty,
65
- Equivalence as SchemaEquivalence,
66
- Serializable,
67
- JSONSchema,
68
- ParseResult,
69
- } from '@effect/schema'
63
+ export * as SchemaAST from 'effect/SchemaAST'
64
+ export { TreeFormatter } from 'effect/ParseResult'
65
+ export { ParseResult, Pretty } from 'effect'
66
+ export type { Serializable, SerializableWithResult } from 'effect/Schema'
70
67
  export * as Schema from './Schema/index.js'
71
68
  export * as OtelTracer from '@effect/opentelemetry/Tracer'
72
69
 
@@ -82,6 +79,7 @@ export {
82
79
  HttpClientError,
83
80
  HttpClientRequest,
84
81
  HttpClientResponse,
82
+ FetchHttpClient,
85
83
  } from '@effect/platform'
86
84
  export { BrowserWorker, BrowserWorkerRunner } from '@effect/platform-browser'
87
85
 
package/src/index.ts CHANGED
@@ -16,8 +16,6 @@ import type * as otel from '@opentelemetry/api'
16
16
 
17
17
  import { objectToString } from './misc.js'
18
18
 
19
- export * as dateFns from 'date-fns'
20
-
21
19
  export type Prettify<T> = T extends infer U ? { [K in keyof U]: Prettify<U[K]> } : never
22
20
  export type PrettifyFlat<T> = T extends infer U ? { [K in keyof U]: U[K] } : never
23
21
 
package/src/misc.ts CHANGED
@@ -18,6 +18,7 @@ export const tryAsFunctionAndNew = <TArg, TResult>(
18
18
  try {
19
19
  // @ts-expect-error try out as constructor
20
20
  return new fnOrConstructor(arg)
21
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
21
22
  } catch (e) {
22
23
  // @ts-expect-error try out as function
23
24
  return fnOrConstructor(arg)
@@ -0,0 +1 @@
1
+ export { nanoid } from 'nanoid'
package/src/string.ts CHANGED
@@ -1,2 +1,9 @@
1
1
  export const lowercaseFirstChar = (str: string) => str.charAt(0).toLowerCase() + str.slice(1)
2
2
  export const uppercaseFirstChar = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
3
+
4
+ /** Indents a string each line by `n` characters (default: spaces) */
5
+ export const indent = (str: string, n: number, char = ' '): string =>
6
+ str
7
+ .split('\n')
8
+ .map((line) => char.repeat(n) + line)
9
+ .join('\n')
package/tsconfig.json CHANGED
@@ -6,5 +6,5 @@
6
6
  "tsBuildInfoFile": "./dist/.tsbuildinfo.json"
7
7
  },
8
8
  "include": ["./src"],
9
- "references": [{ "path": "../../effect-db-schema"}]
9
+ "references": [{ "path": "../db-schema"}]
10
10
  }