@zyro-sec/util 1.0.2 → 1.0.4
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/docs/layer-node.md +155 -155
- package/package.json +1 -1
- package/script/build.ts +9 -9
- package/script/pack.ts +5 -5
- package/src/abort.ts +9 -9
- package/src/activity-calendar.ts +50 -50
- package/src/artifact.ts +95 -95
- package/src/base64.ts +29 -29
- package/src/binary.ts +30 -30
- package/src/bom.ts +46 -46
- package/src/cross-spawn-spawner.ts +694 -694
- package/src/duration.ts +22 -22
- package/src/effect/app-node-platform.ts +40 -40
- package/src/effect/app-node.ts +14 -14
- package/src/effect/layer-node.ts +360 -360
- package/src/effect-flock.ts +313 -313
- package/src/encode.ts +39 -39
- package/src/execute-output.ts +23 -23
- package/src/flock.ts +346 -346
- package/src/fs-util.ts +271 -271
- package/src/glob.ts +38 -38
- package/src/global-roots.ts +19 -19
- package/src/global-roots.workerd.ts +16 -16
- package/src/global.ts +88 -88
- package/src/hash.ts +11 -11
- package/src/heap-snapshot.ts +44 -44
- package/src/no-timeout-fetch.ts +5 -5
- package/src/npm-config.ts +41 -41
- package/src/npm.ts +557 -557
- package/src/observability/logging.ts +179 -179
- package/src/observability/otlp.ts +109 -109
- package/src/observability/shared.ts +8 -8
- package/src/observability.ts +60 -60
- package/src/open.ts +12 -12
- package/src/patch.ts +382 -382
- package/src/path.ts +149 -149
- package/src/process-signal.ts +23 -23
- package/src/process.ts +270 -270
- package/src/qr.ts +323 -323
- package/src/record.ts +3 -3
- package/src/retry.ts +51 -51
- package/src/runtime/import.bun.ts +10 -10
- package/src/runtime/import.node.ts +61 -61
- package/src/runtime/import.workerd.ts +9 -9
- package/src/runtime-import.ts +1 -1
- package/src/session-mention.ts +24 -24
- package/src/session-title-fallback.ts +36 -36
- package/src/session-turn.ts +82 -82
- package/src/teardown.ts +19 -19
- package/src/text-boundary.ts +36 -36
- package/src/uuid.ts +15 -15
- package/test/fixtures/qr.json +625 -625
- package/tsconfig.build.json +12 -12
- package/tsconfig.dist.json +10 -10
- package/tsconfig.json +14 -14
- package/src/abort.test.ts +0 -16
- package/src/activity-calendar.test.ts +0 -136
- package/src/artifact.test.ts +0 -29
- package/src/base64.test.ts +0 -12
- package/src/binary.test.ts +0 -19
- package/src/bom.test.ts +0 -21
- package/src/encode.test.ts +0 -32
- package/src/execute-output.test.ts +0 -36
- package/src/no-timeout-fetch.test.ts +0 -33
- package/src/open.test.ts +0 -16
- package/src/path.test.ts +0 -89
- package/src/process-signal.test.ts +0 -38
- package/src/retry.test.ts +0 -87
- package/src/session-mention.test.ts +0 -19
- package/src/session-turn.test.ts +0 -131
- package/src/text-boundary.test.ts +0 -39
- package/src/uuid.test.ts +0 -80
- package/test/glob.test.ts +0 -11
- package/test/global-roots.test.ts +0 -62
- package/test/global.test.ts +0 -99
- package/test/observability-otlp.test.ts +0 -45
- package/test/qr.test.ts +0 -113
- package/test/session-title-fallback.test.ts +0 -49
package/src/duration.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/** Compact elapsed time, e.g. `850ms`, `12.4s`, `3m 5s`, `2h 10m` or `1d 4h`. */
|
|
2
|
-
export function duration(input: number) {
|
|
3
|
-
if (input < 1000) {
|
|
4
|
-
return `${input}ms`
|
|
5
|
-
}
|
|
6
|
-
if (input < 60000) {
|
|
7
|
-
return `${(input / 1000).toFixed(1)}s`
|
|
8
|
-
}
|
|
9
|
-
if (input < 3600000) {
|
|
10
|
-
const minutes = Math.floor(input / 60000)
|
|
11
|
-
const seconds = Math.floor((input % 60000) / 1000)
|
|
12
|
-
return `${minutes}m ${seconds}s`
|
|
13
|
-
}
|
|
14
|
-
if (input < 86400000) {
|
|
15
|
-
const hours = Math.floor(input / 3600000)
|
|
16
|
-
const minutes = Math.floor((input % 3600000) / 60000)
|
|
17
|
-
return `${hours}h ${minutes}m`
|
|
18
|
-
}
|
|
19
|
-
const days = Math.floor(input / 86400000)
|
|
20
|
-
const hours = Math.floor((input % 86400000) / 3600000)
|
|
21
|
-
return `${days}d ${hours}h`
|
|
22
|
-
}
|
|
1
|
+
/** Compact elapsed time, e.g. `850ms`, `12.4s`, `3m 5s`, `2h 10m` or `1d 4h`. */
|
|
2
|
+
export function duration(input: number) {
|
|
3
|
+
if (input < 1000) {
|
|
4
|
+
return `${input}ms`
|
|
5
|
+
}
|
|
6
|
+
if (input < 60000) {
|
|
7
|
+
return `${(input / 1000).toFixed(1)}s`
|
|
8
|
+
}
|
|
9
|
+
if (input < 3600000) {
|
|
10
|
+
const minutes = Math.floor(input / 60000)
|
|
11
|
+
const seconds = Math.floor((input % 60000) / 1000)
|
|
12
|
+
return `${minutes}m ${seconds}s`
|
|
13
|
+
}
|
|
14
|
+
if (input < 86400000) {
|
|
15
|
+
const hours = Math.floor(input / 3600000)
|
|
16
|
+
const minutes = Math.floor((input % 3600000) / 60000)
|
|
17
|
+
return `${hours}h ${minutes}m`
|
|
18
|
+
}
|
|
19
|
+
const days = Math.floor(input / 86400000)
|
|
20
|
+
const hours = Math.floor((input % 86400000) / 3600000)
|
|
21
|
+
return `${days}d ${hours}h`
|
|
22
|
+
}
|
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
// Deep imports: the @effect/platform-node barrel eagerly pulls in undici,
|
|
2
|
-
// ioredis, and node:sqlite, which runtimes such as workerd cannot load.
|
|
3
|
-
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"
|
|
4
|
-
import * as NodePath from "@effect/platform-node/NodePath"
|
|
5
|
-
import { Effect, FileSystem, Layer, Path } from "effect"
|
|
6
|
-
import { FetchHttpClient, HttpClient } from "effect/http"
|
|
7
|
-
import { makeGlobalNode } from "./app-node.js"
|
|
8
|
-
|
|
9
|
-
export const filesystem = makeGlobalNode({ service: FileSystem.FileSystem, layer: NodeFileSystem.layer, deps: [] })
|
|
10
|
-
export const path = makeGlobalNode({ service: Path.Path, layer: NodePath.layer, deps: [] })
|
|
11
|
-
// `RequestInfo | URL`, spelled out because not every runtime declares `RequestInfo` globally.
|
|
12
|
-
export type Fetch = (input: Request | string | URL, init?: RequestInit) => Promise<Response>
|
|
13
|
-
/**
|
|
14
|
-
* The fetch behind `httpClient`, AI SDK providers and remote MCP servers: `fetch` when given, so an embedder can route requests through
|
|
15
|
-
* e.g. a Service Binding, otherwise the `FetchHttpClient.Fetch` in scope when the graph is built.
|
|
16
|
-
*/
|
|
17
|
-
export const fetchLayer = (fetch?: Fetch) =>
|
|
18
|
-
Layer.effect(
|
|
19
|
-
FetchHttpClient.Fetch,
|
|
20
|
-
Effect.gen(function* () {
|
|
21
|
-
// Bun's `typeof fetch` adds `preconnect`, which nothing here calls.
|
|
22
|
-
return fetch ? (fetch as typeof globalThis.fetch) : yield* FetchHttpClient.Fetch
|
|
23
|
-
}),
|
|
24
|
-
)
|
|
25
|
-
export const httpFetch = makeGlobalNode({ service: FetchHttpClient.Fetch, layer: fetchLayer(), deps: [] })
|
|
26
|
-
// Provided per request, so a caller's context can't swap `httpFetch` for another fetch.
|
|
27
|
-
export const httpClient = makeGlobalNode({
|
|
28
|
-
service: HttpClient.HttpClient,
|
|
29
|
-
layer: Layer.effect(
|
|
30
|
-
HttpClient.HttpClient,
|
|
31
|
-
Effect.gen(function* () {
|
|
32
|
-
const fetch = yield* FetchHttpClient.Fetch
|
|
33
|
-
const client = yield* HttpClient.HttpClient.pipe(Effect.provide(FetchHttpClient.layer))
|
|
34
|
-
return HttpClient.transformResponse(client, Effect.provideService(FetchHttpClient.Fetch, fetch))
|
|
35
|
-
}),
|
|
36
|
-
),
|
|
37
|
-
deps: [httpFetch],
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
export * as LayerNodePlatform from "./app-node-platform.js"
|
|
1
|
+
// Deep imports: the @effect/platform-node barrel eagerly pulls in undici,
|
|
2
|
+
// ioredis, and node:sqlite, which runtimes such as workerd cannot load.
|
|
3
|
+
import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem"
|
|
4
|
+
import * as NodePath from "@effect/platform-node/NodePath"
|
|
5
|
+
import { Effect, FileSystem, Layer, Path } from "effect"
|
|
6
|
+
import { FetchHttpClient, HttpClient } from "effect/http"
|
|
7
|
+
import { makeGlobalNode } from "./app-node.js"
|
|
8
|
+
|
|
9
|
+
export const filesystem = makeGlobalNode({ service: FileSystem.FileSystem, layer: NodeFileSystem.layer, deps: [] })
|
|
10
|
+
export const path = makeGlobalNode({ service: Path.Path, layer: NodePath.layer, deps: [] })
|
|
11
|
+
// `RequestInfo | URL`, spelled out because not every runtime declares `RequestInfo` globally.
|
|
12
|
+
export type Fetch = (input: Request | string | URL, init?: RequestInit) => Promise<Response>
|
|
13
|
+
/**
|
|
14
|
+
* The fetch behind `httpClient`, AI SDK providers and remote MCP servers: `fetch` when given, so an embedder can route requests through
|
|
15
|
+
* e.g. a Service Binding, otherwise the `FetchHttpClient.Fetch` in scope when the graph is built.
|
|
16
|
+
*/
|
|
17
|
+
export const fetchLayer = (fetch?: Fetch) =>
|
|
18
|
+
Layer.effect(
|
|
19
|
+
FetchHttpClient.Fetch,
|
|
20
|
+
Effect.gen(function* () {
|
|
21
|
+
// Bun's `typeof fetch` adds `preconnect`, which nothing here calls.
|
|
22
|
+
return fetch ? (fetch as typeof globalThis.fetch) : yield* FetchHttpClient.Fetch
|
|
23
|
+
}),
|
|
24
|
+
)
|
|
25
|
+
export const httpFetch = makeGlobalNode({ service: FetchHttpClient.Fetch, layer: fetchLayer(), deps: [] })
|
|
26
|
+
// Provided per request, so a caller's context can't swap `httpFetch` for another fetch.
|
|
27
|
+
export const httpClient = makeGlobalNode({
|
|
28
|
+
service: HttpClient.HttpClient,
|
|
29
|
+
layer: Layer.effect(
|
|
30
|
+
HttpClient.HttpClient,
|
|
31
|
+
Effect.gen(function* () {
|
|
32
|
+
const fetch = yield* FetchHttpClient.Fetch
|
|
33
|
+
const client = yield* HttpClient.HttpClient.pipe(Effect.provide(FetchHttpClient.layer))
|
|
34
|
+
return HttpClient.transformResponse(client, Effect.provideService(FetchHttpClient.Fetch, fetch))
|
|
35
|
+
}),
|
|
36
|
+
),
|
|
37
|
+
deps: [httpFetch],
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export * as LayerNodePlatform from "./app-node-platform.js"
|
package/src/effect/app-node.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { LayerNode } from "./layer-node.js"
|
|
2
|
-
|
|
3
|
-
export const tags = LayerNode.tags({
|
|
4
|
-
location: ["global"],
|
|
5
|
-
global: [],
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
export type GlobalGraph<A, E = never> = LayerNode.Graph<A, E, (typeof tags.values)["global"]>
|
|
9
|
-
export type LocationGraph<A, E = never> = LayerNode.Graph<A, E, (typeof tags.values)["location" | "global"]>
|
|
10
|
-
|
|
11
|
-
export const makeGlobalNode = tags.make("global")
|
|
12
|
-
export const makeLocationNode = tags.make("location")
|
|
13
|
-
|
|
14
|
-
export * as Node from "./app-node.js"
|
|
1
|
+
import { LayerNode } from "./layer-node.js"
|
|
2
|
+
|
|
3
|
+
export const tags = LayerNode.tags({
|
|
4
|
+
location: ["global"],
|
|
5
|
+
global: [],
|
|
6
|
+
})
|
|
7
|
+
|
|
8
|
+
export type GlobalGraph<A, E = never> = LayerNode.Graph<A, E, (typeof tags.values)["global"]>
|
|
9
|
+
export type LocationGraph<A, E = never> = LayerNode.Graph<A, E, (typeof tags.values)["location" | "global"]>
|
|
10
|
+
|
|
11
|
+
export const makeGlobalNode = tags.make("global")
|
|
12
|
+
export const makeLocationNode = tags.make("location")
|
|
13
|
+
|
|
14
|
+
export * as Node from "./app-node.js"
|