@livestore/utils 0.4.0-dev.7 → 0.4.0-dev.9

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.
@@ -1,8 +1,8 @@
1
1
  import { Transferable } from '@effect/platform'
2
- import type { SchemaAST } from 'effect'
3
2
  import { Effect, Hash, ParseResult, Schema } from 'effect'
4
3
  import type { ParseError } from 'effect/ParseResult'
5
4
  import type { ParseOptions } from 'effect/SchemaAST'
5
+ import * as SchemaAST from 'effect/SchemaAST'
6
6
 
7
7
  import { shouldNeverHappen } from '../../mod.ts'
8
8
 
@@ -23,6 +23,21 @@ export const hash = (schema: Schema.Schema<any>) => {
23
23
  }
24
24
  }
25
25
 
26
+ const resolveStructAst = (ast: SchemaAST.AST): SchemaAST.AST => {
27
+ if (SchemaAST.isTransformation(ast)) {
28
+ return resolveStructAst(ast.from)
29
+ }
30
+
31
+ return ast
32
+ }
33
+
34
+ export const getResolvedPropertySignatures = (
35
+ schema: Schema.Schema.AnyNoContext,
36
+ ): ReadonlyArray<SchemaAST.PropertySignature> => {
37
+ const resolvedAst = resolveStructAst(schema.ast)
38
+ return SchemaAST.getPropertySignatures(resolvedAst)
39
+ }
40
+
26
41
  export const encodeWithTransferables =
27
42
  <A, I, R>(schema: Schema.Schema<A, I, R>, options?: ParseOptions | undefined) =>
28
43
  (a: A, overrideOptions?: ParseOptions | undefined): Effect.Effect<[I, Transferable[]], ParseError, R> =>
@@ -1,6 +1,21 @@
1
1
  import '../global.ts'
2
2
 
3
- export { AiError, AiLanguageModel, AiModel, AiTool, AiToolkit, McpSchema, McpServer } from '@effect/ai'
3
+ export {
4
+ AiError,
5
+ LanguageModel,
6
+ LanguageModel as AiLanguageModel,
7
+ McpSchema,
8
+ McpServer,
9
+ Model,
10
+ Model as AiModel,
11
+ Prompt,
12
+ Tool,
13
+ Tool as AiTool,
14
+ Toolkit,
15
+ Toolkit as AiToolkit,
16
+ } from '@effect/ai'
17
+ // export { DevTools as EffectDevtools } from '@effect/experimental'
18
+ export { Sse } from '@effect/experimental'
4
19
  export * as Otlp from '@effect/opentelemetry/Otlp'
5
20
  export {
6
21
  Command,
@@ -122,22 +137,19 @@ export { TreeFormatter } from 'effect/ParseResult'
122
137
  export type { Serializable, SerializableWithResult } from 'effect/Schema'
123
138
  export * as SchemaAST from 'effect/SchemaAST'
124
139
  export * as BucketQueue from './BucketQueue.ts'
140
+ export * as Effect from './Effect.ts'
141
+ export * from './Error.ts'
125
142
  export * as Logger from './Logger.ts'
126
143
  export * as OtelTracer from './OtelTracer.ts'
127
144
  export * as RpcClient from './RpcClient.ts'
145
+ export * as Schedule from './Schedule.ts'
146
+ export * as Scheduler from './Scheduler.ts'
128
147
  export * as Schema from './Schema/index.ts'
148
+ export * as ServiceContext from './ServiceContext.ts'
129
149
  export * as Stream from './Stream.ts'
130
150
  export * as Subscribable from './Subscribable.ts'
131
151
  export * as SubscriptionRef from './SubscriptionRef.ts'
132
152
  export * as TaskTracing from './TaskTracing.ts'
133
153
  export * as WebChannel from './WebChannel/mod.ts'
134
- export * as WebSocket from './WebSocket.ts'
135
-
136
- // export { DevTools as EffectDevtools } from '@effect/experimental'
137
-
138
- export * as Effect from './Effect.ts'
139
- export * from './Error.ts'
140
- export * as Schedule from './Schedule.ts'
141
- export * as Scheduler from './Scheduler.ts'
142
- export * as ServiceContext from './ServiceContext.ts'
143
154
  export * as WebLock from './WebLock.ts'
155
+ export * as WebSocket from './WebSocket.ts'
package/src/misc.ts CHANGED
@@ -10,7 +10,7 @@ export const isDevEnv = () => {
10
10
  }
11
11
 
12
12
  // @ts-expect-error Only exists in Expo / RN
13
- if (typeof globalThis !== 'undefined' && globalThis.__DEV__) {
13
+ if (globalThis?.__DEV__) {
14
14
  return true
15
15
  }
16
16
 
@@ -15,6 +15,15 @@ import * as Scope from 'effect/Scope'
15
15
 
16
16
  // Parent death monitoring setup
17
17
  let parentDeathDetectionEnabled = false
18
+ let parentDeathTimer: NodeJS.Timeout | null = null
19
+
20
+ const stopParentDeathMonitoring = () => {
21
+ parentDeathDetectionEnabled = false
22
+ if (parentDeathTimer) {
23
+ clearTimeout(parentDeathTimer)
24
+ parentDeathTimer = null
25
+ }
26
+ }
18
27
 
19
28
  const setupParentDeathMonitoring = (parentPid: number) => {
20
29
  if (parentDeathDetectionEnabled) return
@@ -25,12 +34,13 @@ const setupParentDeathMonitoring = (parentPid: number) => {
25
34
 
26
35
  // Check if parent is still alive every 2 seconds (more conservative)
27
36
  const checkParentAlive = () => {
37
+ if (!parentDeathDetectionEnabled) return
28
38
  try {
29
39
  // Send signal 0 to check if process exists (doesn't actually send signal)
30
40
  process.kill(parentPid, 0)
31
41
  // If we reach here, parent is still alive, reset failure counter and check again later
32
42
  consecutiveFailures = 0
33
- setTimeout(checkParentAlive, 2000)
43
+ parentDeathTimer = setTimeout(checkParentAlive, 2000)
34
44
  } catch {
35
45
  consecutiveFailures++
36
46
  console.warn(`[Worker ${process.pid}] Parent check failed (${consecutiveFailures}/${maxFailures})`)
@@ -41,13 +51,13 @@ const setupParentDeathMonitoring = (parentPid: number) => {
41
51
  process.exit(0)
42
52
  } else {
43
53
  // Try again sooner on failure
44
- setTimeout(checkParentAlive, 1000)
54
+ parentDeathTimer = setTimeout(checkParentAlive, 1000)
45
55
  }
46
56
  }
47
57
  }
48
58
 
49
59
  // Start monitoring after a longer initial delay to let things settle
50
- setTimeout(checkParentAlive, 5000)
60
+ parentDeathTimer = setTimeout(checkParentAlive, 5000)
51
61
  }
52
62
 
53
63
  const platformRunnerImpl = Runner.PlatformRunner.of({
@@ -101,6 +111,8 @@ const platformRunnerImpl = Runner.PlatformRunner.of({
101
111
  FiberSet.unsafeAdd(fiberSet, fiber)
102
112
  }
103
113
  } else {
114
+ // Graceful shutdown requested by parent: stop monitoring and close port
115
+ stopParentDeathMonitoring()
104
116
  Deferred.unsafeDone(closeLatch, Exit.void)
105
117
  port.close()
106
118
  }
@@ -1,3 +0,0 @@
1
- import { Schema } from 'effect';
2
- export declare const MsgPack: <A, I>(schema: Schema.Schema<A, I>) => Schema.transform<typeof Schema.Uint8ArrayFromSelf, Schema.Schema<A, I, never>>;
3
- //# sourceMappingURL=msgpack.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msgpack.d.ts","sourceRoot":"","sources":["../../../src/effect/Schema/msgpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,CAAC,EAAE,QAAQ,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,mFAIrD,CAAA"}
@@ -1,7 +0,0 @@
1
- import { Schema } from 'effect';
2
- import * as msgpack from 'msgpackr';
3
- export const MsgPack = (schema) => Schema.transform(Schema.Uint8ArrayFromSelf, schema, {
4
- encode: (decoded) => msgpack.pack(decoded),
5
- decode: (encodedBytes) => msgpack.unpack(encodedBytes),
6
- });
7
- //# sourceMappingURL=msgpack.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"msgpack.js","sourceRoot":"","sources":["../../../src/effect/Schema/msgpack.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,KAAK,OAAO,MAAM,UAAU,CAAA;AAEnC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAO,MAA2B,EAAE,EAAE,CAC3D,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,kBAAkB,EAAE,MAAM,EAAE;IAClD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;IAC1C,MAAM,EAAE,CAAC,YAAY,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;CACvD,CAAC,CAAA"}