@zyro-sec/util 0.0.0-stage → 1.0.1
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 -0
- package/package.json +68 -4
- package/script/build.ts +9 -0
- package/script/pack.ts +5 -0
- package/src/abort.test.ts +16 -0
- package/src/abort.ts +9 -0
- package/src/activity-calendar.test.ts +136 -0
- package/src/activity-calendar.ts +50 -0
- package/src/artifact.test.ts +29 -0
- package/src/artifact.ts +95 -0
- package/src/base64.test.ts +12 -0
- package/src/base64.ts +29 -0
- package/src/binary.test.ts +19 -0
- package/src/binary.ts +30 -0
- package/src/bom.test.ts +21 -0
- package/src/bom.ts +46 -0
- package/src/cross-spawn-spawner.ts +694 -0
- package/src/duration.ts +22 -0
- package/src/effect/app-node-platform.ts +40 -0
- package/src/effect/app-node.ts +14 -0
- package/src/effect/layer-node.ts +360 -0
- package/src/effect-flock.ts +313 -0
- package/src/encode.test.ts +32 -0
- package/src/encode.ts +39 -0
- package/src/execute-output.test.ts +36 -0
- package/src/execute-output.ts +23 -0
- package/src/flock.ts +346 -0
- package/src/fs-util.ts +271 -0
- package/src/glob.ts +38 -0
- package/src/global-roots.ts +19 -0
- package/src/global-roots.workerd.ts +16 -0
- package/src/global.ts +88 -0
- package/src/hash.ts +11 -0
- package/src/heap-snapshot.ts +44 -0
- package/src/no-timeout-fetch.test.ts +33 -0
- package/src/no-timeout-fetch.ts +5 -0
- package/src/npm-config.ts +41 -0
- package/src/npm.ts +557 -0
- package/src/observability/logging.ts +179 -0
- package/src/observability/otlp.ts +109 -0
- package/src/observability/shared.ts +8 -0
- package/src/observability.ts +60 -0
- package/src/open.test.ts +16 -0
- package/src/open.ts +12 -0
- package/src/patch.ts +382 -0
- package/src/path.test.ts +89 -0
- package/src/path.ts +149 -0
- package/src/process-signal.test.ts +38 -0
- package/src/process-signal.ts +23 -0
- package/src/process.ts +270 -0
- package/src/qr.ts +323 -0
- package/src/record.ts +3 -0
- package/src/retry.test.ts +87 -0
- package/src/retry.ts +51 -0
- package/src/runtime/import.bun.ts +10 -0
- package/src/runtime/import.node.ts +61 -0
- package/src/runtime/import.workerd.ts +9 -0
- package/src/runtime-import.ts +1 -0
- package/src/session-mention.test.ts +19 -0
- package/src/session-mention.ts +24 -0
- package/src/session-title-fallback.ts +36 -0
- package/src/session-turn.test.ts +131 -0
- package/src/session-turn.ts +82 -0
- package/src/teardown.ts +19 -0
- package/src/text-boundary.test.ts +39 -0
- package/src/text-boundary.ts +36 -0
- package/src/uuid.test.ts +80 -0
- package/src/uuid.ts +15 -0
- package/test/fixtures/qr.json +625 -0
- package/test/glob.test.ts +11 -0
- package/test/global-roots.test.ts +62 -0
- package/test/global.test.ts +99 -0
- package/test/observability-otlp.test.ts +45 -0
- package/test/qr.test.ts +113 -0
- package/test/session-title-fallback.test.ts +49 -0
- package/tsconfig.build.json +12 -0
- package/tsconfig.dist.json +10 -0
- package/tsconfig.json +14 -0
- package/README.md +0 -3
package/src/binary.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export namespace Binary {
|
|
2
|
+
export function search<T>(array: T[], id: string, compare: (item: T) => string) {
|
|
3
|
+
let left = 0
|
|
4
|
+
let right = array.length - 1
|
|
5
|
+
|
|
6
|
+
while (left <= right) {
|
|
7
|
+
const middle = Math.floor((left + right) / 2)
|
|
8
|
+
const value = compare(array[middle])
|
|
9
|
+
if (value === id) return { found: true, index: middle }
|
|
10
|
+
if (value < id) left = middle + 1
|
|
11
|
+
else right = middle - 1
|
|
12
|
+
}
|
|
13
|
+
return { found: false, index: left }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function insert<T>(array: T[], item: T, compare: (item: T) => string) {
|
|
17
|
+
const id = compare(item)
|
|
18
|
+
let left = 0
|
|
19
|
+
let right = array.length
|
|
20
|
+
|
|
21
|
+
while (left < right) {
|
|
22
|
+
const middle = Math.floor((left + right) / 2)
|
|
23
|
+
if (compare(array[middle]) < id) left = middle + 1
|
|
24
|
+
else right = middle
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
array.splice(left, 0, item)
|
|
28
|
+
return array
|
|
29
|
+
}
|
|
30
|
+
}
|
package/src/bom.test.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { expect, test } from "bun:test"
|
|
2
|
+
import { Bom } from "./bom.js"
|
|
3
|
+
|
|
4
|
+
test.each([
|
|
5
|
+
{ prefix: "", bom: false, expected: undefined },
|
|
6
|
+
{ prefix: "", bom: true, expected: "\uFEFF" },
|
|
7
|
+
{ prefix: "\uFEFF", bom: false, expected: "" },
|
|
8
|
+
{ prefix: "\uFEFF", bom: true, expected: undefined },
|
|
9
|
+
{ prefix: "\uFEFF\uFEFF", bom: false, expected: "" },
|
|
10
|
+
{ prefix: "\uFEFF\uFEFF", bom: true, expected: "\uFEFF" },
|
|
11
|
+
])("syncBytes(%j)", (row) => {
|
|
12
|
+
const encoder = new TextEncoder()
|
|
13
|
+
const text = "a\uFEFF\u00e9"
|
|
14
|
+
const input = encoder.encode(row.prefix + text)
|
|
15
|
+
|
|
16
|
+
expect(Bom.syncBytes(input, row.bom)).toEqual({
|
|
17
|
+
text,
|
|
18
|
+
bytes: row.expected === undefined ? undefined : encoder.encode(row.expected + text),
|
|
19
|
+
})
|
|
20
|
+
expect(input).toEqual(encoder.encode(row.prefix + text))
|
|
21
|
+
})
|
package/src/bom.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
export * as Bom from "./bom.js"
|
|
2
|
+
|
|
3
|
+
import { Effect } from "effect"
|
|
4
|
+
import type { FSUtil } from "./fs-util.js"
|
|
5
|
+
|
|
6
|
+
const code = 0xfeff
|
|
7
|
+
const value = String.fromCharCode(code)
|
|
8
|
+
|
|
9
|
+
export function split(text: string) {
|
|
10
|
+
const stripped = text.replace(/^\uFEFF+/, "")
|
|
11
|
+
return { bom: stripped.length !== text.length, text: stripped }
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function join(text: string, bom: boolean) {
|
|
15
|
+
const stripped = split(text).text
|
|
16
|
+
return bom ? value + stripped : stripped
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function has(content: Uint8Array) {
|
|
20
|
+
return content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function decodeBytes(content: Uint8Array) {
|
|
24
|
+
return split(decode(content))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function syncBytes(content: Uint8Array, bom: boolean) {
|
|
28
|
+
const decoded = decode(content)
|
|
29
|
+
const current = split(decoded)
|
|
30
|
+
const canonical = bom ? value + current.text : current.text
|
|
31
|
+
return { text: current.text, bytes: decoded === canonical ? undefined : new TextEncoder().encode(canonical) }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const readFile = Effect.fn("Bom.readFile")(function* (fs: FSUtil.Interface, filepath: string) {
|
|
35
|
+
return decodeBytes(yield* fs.readFile(filepath))
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
export const syncFile = Effect.fn("Bom.syncFile")(function* (fs: FSUtil.Interface, filepath: string, bom: boolean) {
|
|
39
|
+
const synced = syncBytes(yield* fs.readFile(filepath), bom)
|
|
40
|
+
if (synced.bytes) yield* fs.writeWithDirs(filepath, synced.bytes)
|
|
41
|
+
return synced.text
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
function decode(content: Uint8Array) {
|
|
45
|
+
return new TextDecoder("utf-8", { ignoreBOM: true }).decode(content)
|
|
46
|
+
}
|