@livestore/utils 0.0.10 → 0.0.13

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 (44) hide show
  1. package/dist/.tsbuildinfo.json +1 -1
  2. package/dist/effect/Effect.d.ts +3 -3
  3. package/dist/effect/Effect.d.ts.map +1 -1
  4. package/dist/effect/Effect.js +2 -4
  5. package/dist/effect/Effect.js.map +1 -1
  6. package/dist/effect/Error.d.ts +4 -3
  7. package/dist/effect/Error.d.ts.map +1 -1
  8. package/dist/effect/Error.js +2 -2
  9. package/dist/effect/Error.js.map +1 -1
  10. package/dist/effect/Schedule.d.ts +2 -3
  11. package/dist/effect/Schedule.d.ts.map +1 -1
  12. package/dist/effect/Schedule.js +2 -4
  13. package/dist/effect/Schedule.js.map +1 -1
  14. package/dist/effect/ServiceContext.d.ts +2 -4
  15. package/dist/effect/ServiceContext.d.ts.map +1 -1
  16. package/dist/effect/ServiceContext.js +1 -7
  17. package/dist/effect/ServiceContext.js.map +1 -1
  18. package/dist/effect/index.d.ts +3 -45
  19. package/dist/effect/index.d.ts.map +1 -1
  20. package/dist/effect/index.js +3 -52
  21. package/dist/effect/index.js.map +1 -1
  22. package/dist/global.d.ts +1 -1
  23. package/dist/global.d.ts.map +1 -1
  24. package/dist/index.d.ts +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +12 -16
  27. package/dist/index.js.map +1 -1
  28. package/dist/object/index.js +1 -1
  29. package/dist/object/index.js.map +1 -1
  30. package/package.json +18 -20
  31. package/src/effect/Effect.ts +3 -5
  32. package/src/effect/Error.ts +5 -2
  33. package/src/effect/Schedule.ts +2 -4
  34. package/src/effect/ServiceContext.ts +2 -8
  35. package/src/effect/index.ts +47 -58
  36. package/src/global.ts +1 -1
  37. package/src/index.ts +12 -14
  38. package/src/object/index.ts +1 -1
  39. package/tsconfig.json +2 -5
  40. package/dist/effect/Layer.d.ts +0 -20
  41. package/dist/effect/Layer.d.ts.map +0 -1
  42. package/dist/effect/Layer.js +0 -12
  43. package/dist/effect/Layer.js.map +0 -1
  44. package/src/effect/Layer.ts +0 -42
@@ -1,65 +1,54 @@
1
1
  import '../global.js'
2
2
 
3
- // io
4
- export * as Effect from './Effect.js'
5
- export * as Scope from '@effect/io/Scope'
6
- export * as Schedule from './Schedule.js'
7
- export * as Layer from './Layer.js'
8
- export * as Ref from '@effect/io/Ref'
9
- export * as SynchronizedRef from '@effect/io/SynchronizedRef'
10
- export * as Queue from '@effect/io/Queue'
11
- export * as Fiber from '@effect/io/Fiber'
12
- export * as FiberId from '@effect/io/FiberId'
13
- export * as RuntimeFlags from '@effect/io/RuntimeFlags'
14
- export * as Hub from '@effect/io/Hub'
15
- export * as Exit from '@effect/io/Exit'
16
- export * as Cause from '@effect/io/Cause'
17
- export * as Runtime from '@effect/io/Runtime'
18
- export * as Scheduler from '@effect/io/Scheduler'
19
- export * as FiberRef from '@effect/io/FiberRef'
20
- export * as FiberRefs from '@effect/io/FiberRefs'
21
- export * as FiberRefsPatch from '@effect/io/FiberRefsPatch'
22
- export * as Deferred from '@effect/io/Deferred'
23
- export * as Metric from '@effect/io/Metric'
24
- export * as MetricState from '@effect/io/MetricState'
25
- export * as Request from '@effect/io/Request'
26
- export * as Tracer from '@effect/io/Tracer'
27
-
28
- // data
29
- export * as Context from '@effect/data/Context'
30
- export * as Data from '@effect/data/Data'
31
- export { TaggedClass as Tagged } from '@effect/data/Data'
32
- export * as Either from '@effect/data/Either'
33
- export * as Brand from '@effect/data/Brand'
34
- export * as Hash from '@effect/data/Hash'
35
- export * as Equal from '@effect/data/Equal'
36
- export * as Ord from '@effect/data/Order'
37
- export * as Chunk from '@effect/data/Chunk'
38
- export * as Duration from '@effect/data/Duration'
39
- export * as ReadonlyArray from '@effect/data/ReadonlyArray'
40
- export * as ReadonlyRecord from '@effect/data/ReadonlyRecord'
41
- export * as SortedMap from '@effect/data/SortedMap'
42
- export * as HashMap from '@effect/data/HashMap'
43
- export * as HashSet from '@effect/data/HashSet'
44
- export * as MutableHashSet from '@effect/data/MutableHashSet'
45
- export * as Option from '@effect/data/Option'
46
- export { pipe, identity } from '@effect/data/Function'
3
+ export {
4
+ Scope,
5
+ Ref,
6
+ SynchronizedRef,
7
+ Queue,
8
+ Fiber,
9
+ FiberId,
10
+ RuntimeFlags,
11
+ PubSub,
12
+ Exit,
13
+ Cause,
14
+ Runtime,
15
+ Scheduler,
16
+ FiberRef,
17
+ FiberRefs,
18
+ FiberRefsPatch,
19
+ Deferred,
20
+ Metric,
21
+ MetricState,
22
+ Request,
23
+ Tracer,
24
+ Context,
25
+ Data,
26
+ Either,
27
+ Brand,
28
+ Hash,
29
+ Equal,
30
+ Chunk,
31
+ Duration,
32
+ ReadonlyArray,
33
+ ReadonlyRecord,
34
+ SortedMap,
35
+ HashMap,
36
+ HashSet,
37
+ MutableHashSet,
38
+ Option,
39
+ Layer,
40
+ Stream,
41
+ Channel,
42
+ SubscriptionRef,
43
+ pipe,
44
+ identity,
45
+ Match,
46
+ } from 'effect'
47
47
 
48
- // stream
49
- export * as Stream from '@effect/stream/Stream'
50
- export * as Channel from '@effect/stream/Channel'
51
- export * as SubscriptionRef from '@effect/stream/SubscriptionRef'
52
-
53
- // schema
54
48
  export * as Schema from '@effect/schema/Schema'
49
+ export * as OtelTracer from '@effect/opentelemetry/Tracer'
55
50
 
56
- // match
57
- export * as Match from '@effect/match'
58
-
59
- // error
51
+ export * as Effect from './Effect.js'
52
+ export * as Schedule from './Schedule.js'
60
53
  export * from './Error.js'
61
-
62
- // ServiceContext
63
54
  export * as ServiceContext from './ServiceContext.js'
64
-
65
- export * as OtelTracer from '@effect/opentelemetry/Tracer'
package/src/global.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  declare global {
2
- export type TODO = any
2
+ export type TODO<_Reason extends string = 'unknown'> = any
3
3
  }
4
4
 
5
5
  export {}
package/src/index.ts CHANGED
@@ -71,7 +71,7 @@ export const prop =
71
71
  obj[key]
72
72
 
73
73
  export const objectToString = (error: any): string => {
74
- const stack = typeof process !== 'undefined' && process.env.CL_DEBUG ? error.stack : undefined
74
+ const stack = error.stack
75
75
  const str = error.toString()
76
76
  const stackStr = stack ? `\n${stack}` : ''
77
77
  if (str !== '[object Object]') return str + stackStr
@@ -199,19 +199,17 @@ export const assertTag = <TObj extends { _tag: string }, TTag extends TObj['_tag
199
199
  return obj as any
200
200
  }
201
201
 
202
- export const getEnv = (varName: string) => {
203
- let value: string | undefined
202
+ export const memoize = <T extends (...args: any[]) => any>(fn: T): T => {
203
+ const cache = new Map<string, ReturnType<T>>()
204
204
 
205
- // @ts-expect-error `import.meta.env` might not be defined
206
- if (import.meta.env !== undefined) {
207
- // @ts-expect-error `import.meta.env` might not be defined
208
- value = import.meta.env[varName]
209
- // eslint-disable-next-line unicorn/no-negated-condition
210
- } else if (globalThis.process?.env !== undefined) {
211
- value = globalThis.process.env[varName]
212
- } else {
213
- throw new Error(`No environment variables found (neither import.meta.env nor process.env)`)
214
- }
205
+ return ((...args: any[]) => {
206
+ const key = JSON.stringify(args)
207
+ if (cache.has(key)) {
208
+ return cache.get(key)
209
+ }
215
210
 
216
- return value
211
+ const result = fn(...args)
212
+ cache.set(key, result)
213
+ return result
214
+ }) as any
217
215
  }
@@ -1,4 +1,4 @@
1
- import { pipe } from '@effect/data/Function'
1
+ import { pipe } from 'effect'
2
2
 
3
3
  export * from './pick.js'
4
4
  export * from './omit.js'
package/tsconfig.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "extends": "../../../tsconfig.base.json",
3
3
  "compilerOptions": {
4
- "module": "ES2020",
5
4
  "rootDir": "./src",
6
5
  "outDir": "./dist",
7
6
  "tsBuildInfoFile": "./dist/.tsbuildinfo.json"
8
7
  },
9
- "include": [
10
- "./src"
11
- ],
8
+ "include": ["./src"],
12
9
  "references": []
13
- }
10
+ }
@@ -1,20 +0,0 @@
1
- export * from '@effect/io/Layer';
2
- import type * as Context from '@effect/data/Context';
3
- import * as Effect from '@effect/io/Effect';
4
- import * as Layer from '@effect/io/Layer';
5
- import type * as Tracer from '@effect/io/Tracer';
6
- export declare const span: (name: string, options?: {
7
- readonly attributes?: Record<string, Tracer.AttributeValue>;
8
- readonly links?: ReadonlyArray<Tracer.SpanLink>;
9
- readonly parent?: Tracer.ParentSpan;
10
- readonly root?: boolean;
11
- readonly context?: Context.Context<never>;
12
- }, onEnd?: ((span: Tracer.Span) => Effect.Effect<never, never, void>) | undefined) => Layer.Layer<never, never, never>;
13
- export declare const withSpan: (name: string, options?: {
14
- readonly attributes?: Record<string, Tracer.AttributeValue>;
15
- readonly links?: ReadonlyArray<Tracer.SpanLink>;
16
- readonly parent?: Tracer.ParentSpan;
17
- readonly root?: boolean;
18
- readonly context?: Context.Context<never>;
19
- }, onEnd?: ((span: Tracer.Span) => Effect.Effect<never, never, void>) | undefined) => <C, E, A>(layer: Layer.Layer<C, E, A>) => Layer.Layer<C, E, A>;
20
- //# sourceMappingURL=Layer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../src/effect/Layer.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAChC,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAEpD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,eAAO,MAAM,IAAI,SACT,MAAM,YACF;IACR,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,cAAc,CAAC,CAAA;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,OAAO,QAAQ,CAAC,CAAA;IAC/C,QAAQ,OAAO,CAAC,EAAE,OAAO,UAAU,CAAA;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAA;CAC1C,kBACc,OAAO,IAAI,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,kBAC/D,WAAW,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CASjC,CAAA;AAED,eAAO,MAAM,QAAQ,SAEX,MAAM,YACF;IACR,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,MAAM,EAAE,OAAO,cAAc,CAAC,CAAA;IAC3D,QAAQ,CAAC,KAAK,CAAC,EAAE,cAAc,OAAO,QAAQ,CAAC,CAAA;IAC/C,QAAQ,OAAO,CAAC,EAAE,OAAO,UAAU,CAAA;IACnC,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAA;IACvB,QAAQ,CAAC,OAAO,CAAC,EAAE,eAAe,CAAC,KAAK,CAAC,CAAA;CAC1C,kBACc,OAAO,IAAI,KAAK,aAAa,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,CAAC,gFAGX,CAAA"}
@@ -1,12 +0,0 @@
1
- export * from '@effect/io/Layer';
2
- import { pipe } from '@effect/data/Function';
3
- import * as Effect from '@effect/io/Effect';
4
- import * as Layer from '@effect/io/Layer';
5
- export const span = (name, options, onEnd) => {
6
- const scopedEffect = pipe(
7
- // eslint-disable-next-line react-hooks/rules-of-hooks
8
- Effect.useSpanScoped(name, options), Effect.tap((span) => Effect.withParentSpanScoped(span)), Effect.tap((span) => (onEnd ? Effect.addFinalizer(() => onEnd(span)) : Effect.unit)));
9
- return Layer.scopedDiscard(scopedEffect);
10
- };
11
- export const withSpan = (name, options, onEnd) => (layer) => Layer.provideMerge(span(name, options, onEnd), layer);
12
- //# sourceMappingURL=Layer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Layer.js","sourceRoot":"","sources":["../../src/effect/Layer.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAA;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AAGzC,MAAM,CAAC,MAAM,IAAI,GAAG,CAClB,IAAY,EACZ,OAMC,EACD,KAAgE,EAC9B,EAAE;IACpC,MAAM,YAAY,GAAG,IAAI;IACvB,sDAAsD;IACtD,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,OAAO,CAAC,EACnC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC,EACvD,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CACrF,CAAA;IAED,OAAO,KAAK,CAAC,aAAa,CAAC,YAAY,CAAC,CAAA;AAC1C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,QAAQ,GACnB,CACE,IAAY,EACZ,OAMC,EACD,KAAgE,EAChE,EAAE,CACJ,CAAU,KAA2B,EAAwB,EAAE,CAC7D,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,CAAC,CAAA"}
@@ -1,42 +0,0 @@
1
- export * from '@effect/io/Layer'
2
- import type * as Context from '@effect/data/Context'
3
- import { pipe } from '@effect/data/Function'
4
- import * as Effect from '@effect/io/Effect'
5
- import * as Layer from '@effect/io/Layer'
6
- import type * as Tracer from '@effect/io/Tracer'
7
-
8
- export const span = (
9
- name: string,
10
- options?: {
11
- readonly attributes?: Record<string, Tracer.AttributeValue>
12
- readonly links?: ReadonlyArray<Tracer.SpanLink>
13
- readonly parent?: Tracer.ParentSpan
14
- readonly root?: boolean
15
- readonly context?: Context.Context<never>
16
- },
17
- onEnd?: (span: Tracer.Span) => Effect.Effect<never, never, void>,
18
- ): Layer.Layer<never, never, never> => {
19
- const scopedEffect = pipe(
20
- // eslint-disable-next-line react-hooks/rules-of-hooks
21
- Effect.useSpanScoped(name, options),
22
- Effect.tap((span) => Effect.withParentSpanScoped(span)),
23
- Effect.tap((span) => (onEnd ? Effect.addFinalizer(() => onEnd(span)) : Effect.unit)),
24
- )
25
-
26
- return Layer.scopedDiscard(scopedEffect)
27
- }
28
-
29
- export const withSpan =
30
- (
31
- name: string,
32
- options?: {
33
- readonly attributes?: Record<string, Tracer.AttributeValue>
34
- readonly links?: ReadonlyArray<Tracer.SpanLink>
35
- readonly parent?: Tracer.ParentSpan
36
- readonly root?: boolean
37
- readonly context?: Context.Context<never>
38
- },
39
- onEnd?: (span: Tracer.Span) => Effect.Effect<never, never, void>,
40
- ) =>
41
- <C, E, A>(layer: Layer.Layer<C, E, A>): Layer.Layer<C, E, A> =>
42
- Layer.provideMerge(span(name, options, onEnd), layer)