@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.
Files changed (79) hide show
  1. package/docs/layer-node.md +155 -0
  2. package/package.json +68 -4
  3. package/script/build.ts +9 -0
  4. package/script/pack.ts +5 -0
  5. package/src/abort.test.ts +16 -0
  6. package/src/abort.ts +9 -0
  7. package/src/activity-calendar.test.ts +136 -0
  8. package/src/activity-calendar.ts +50 -0
  9. package/src/artifact.test.ts +29 -0
  10. package/src/artifact.ts +95 -0
  11. package/src/base64.test.ts +12 -0
  12. package/src/base64.ts +29 -0
  13. package/src/binary.test.ts +19 -0
  14. package/src/binary.ts +30 -0
  15. package/src/bom.test.ts +21 -0
  16. package/src/bom.ts +46 -0
  17. package/src/cross-spawn-spawner.ts +694 -0
  18. package/src/duration.ts +22 -0
  19. package/src/effect/app-node-platform.ts +40 -0
  20. package/src/effect/app-node.ts +14 -0
  21. package/src/effect/layer-node.ts +360 -0
  22. package/src/effect-flock.ts +313 -0
  23. package/src/encode.test.ts +32 -0
  24. package/src/encode.ts +39 -0
  25. package/src/execute-output.test.ts +36 -0
  26. package/src/execute-output.ts +23 -0
  27. package/src/flock.ts +346 -0
  28. package/src/fs-util.ts +271 -0
  29. package/src/glob.ts +38 -0
  30. package/src/global-roots.ts +19 -0
  31. package/src/global-roots.workerd.ts +16 -0
  32. package/src/global.ts +88 -0
  33. package/src/hash.ts +11 -0
  34. package/src/heap-snapshot.ts +44 -0
  35. package/src/no-timeout-fetch.test.ts +33 -0
  36. package/src/no-timeout-fetch.ts +5 -0
  37. package/src/npm-config.ts +41 -0
  38. package/src/npm.ts +557 -0
  39. package/src/observability/logging.ts +179 -0
  40. package/src/observability/otlp.ts +109 -0
  41. package/src/observability/shared.ts +8 -0
  42. package/src/observability.ts +60 -0
  43. package/src/open.test.ts +16 -0
  44. package/src/open.ts +12 -0
  45. package/src/patch.ts +382 -0
  46. package/src/path.test.ts +89 -0
  47. package/src/path.ts +149 -0
  48. package/src/process-signal.test.ts +38 -0
  49. package/src/process-signal.ts +23 -0
  50. package/src/process.ts +270 -0
  51. package/src/qr.ts +323 -0
  52. package/src/record.ts +3 -0
  53. package/src/retry.test.ts +87 -0
  54. package/src/retry.ts +51 -0
  55. package/src/runtime/import.bun.ts +10 -0
  56. package/src/runtime/import.node.ts +61 -0
  57. package/src/runtime/import.workerd.ts +9 -0
  58. package/src/runtime-import.ts +1 -0
  59. package/src/session-mention.test.ts +19 -0
  60. package/src/session-mention.ts +24 -0
  61. package/src/session-title-fallback.ts +36 -0
  62. package/src/session-turn.test.ts +131 -0
  63. package/src/session-turn.ts +82 -0
  64. package/src/teardown.ts +19 -0
  65. package/src/text-boundary.test.ts +39 -0
  66. package/src/text-boundary.ts +36 -0
  67. package/src/uuid.test.ts +80 -0
  68. package/src/uuid.ts +15 -0
  69. package/test/fixtures/qr.json +625 -0
  70. package/test/glob.test.ts +11 -0
  71. package/test/global-roots.test.ts +62 -0
  72. package/test/global.test.ts +99 -0
  73. package/test/observability-otlp.test.ts +45 -0
  74. package/test/qr.test.ts +113 -0
  75. package/test/session-title-fallback.test.ts +49 -0
  76. package/tsconfig.build.json +12 -0
  77. package/tsconfig.dist.json +10 -0
  78. package/tsconfig.json +14 -0
  79. 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
+ }
@@ -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
+ }