-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinary-types.ts
More file actions
149 lines (136 loc) · 4.13 KB
/
binary-types.ts
File metadata and controls
149 lines (136 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/**
* @fileoverview Public option / result interfaces for dlx binary
* operations. Split out of `dlx/binary.ts` so consumers can import
* these types without pulling in the implementation.
*
* - `DlxBinaryOptions` — options for `dlxBinary` / `downloadBinary`
* - `DlxBinaryResult` — what `dlxBinary` returns
* - `DlxMetadata` — on-disk metadata schema for a cached binary
*/
import type { HashSpec } from './integrity'
import type { spawn } from '../spawn/spawn'
import type { SpawnOptions } from '../spawn/types'
export interface DlxBinaryOptions {
/**
* URL to download the binary from.
*/
url: string
/**
* Optional name for the cached binary (defaults to URL hash).
*/
name?: string | undefined
/**
* Expected hash for verification. Accepts either:
* - A bare sha512 SRI string (`sha512-<base64>`), sniffed as integrity.
* - A bare sha256 hex string (64 hex chars), sniffed as checksum.
* - An explicit `{ type: 'integrity' | 'checksum', value }` object.
*
* This is the preferred field. `integrity` and `sha256` remain as
* lower-level escapes; if both `hash` and one of those is set, `hash`
* wins for the matching flavor.
*/
hash?: HashSpec | undefined
/**
* Expected SRI integrity hash (sha512-<base64>) for verification.
* Lower-level alternative to `hash`.
*/
integrity?: string | undefined
/**
* Expected SHA-256 hex checksum for verification.
* Passed to httpDownload for inline verification during download.
* This is more secure than post-download verification as it fails early.
* Lower-level alternative to `hash`.
*/
sha256?: string | undefined
/**
* Cache TTL in milliseconds (default: 7 days).
*/
cacheTtl?: number | undefined
/**
* Force re-download even if cached.
* Aligns with npm/npx --force flag.
*/
force?: boolean | undefined
/**
* Skip confirmation prompts (auto-approve).
* Aligns with npx --yes/-y flag.
*/
yes?: boolean | undefined
/**
* Suppress output (quiet mode).
* Aligns with npx --quiet/-q and pnpm --silent/-s flags.
*/
quiet?: boolean | undefined
/**
* Additional spawn options.
*/
spawnOptions?: SpawnOptions | undefined
}
export interface DlxBinaryResult {
/** Path to the cached binary. */
binaryPath: string
/** Whether the binary was newly downloaded. */
downloaded: boolean
/** The spawn promise for the running process. */
spawnPromise: ReturnType<typeof spawn>
}
/**
* Metadata structure for cached binaries (.dlx-metadata.json).
* Unified schema shared across TypeScript (dlxBinary) and C++ stub extractor.
*
* Fields:
* - version: Schema version (currently "1.0.0")
* - cache_key: First 16 chars of SHA-512 hash (matches directory name)
* - timestamp: Unix timestamp in milliseconds
* - integrity: SRI hash (sha512-<base64>, aligned with npm)
* - size: Size of cached binary in bytes
* - source: Origin information
* - type: "download" | "extract" | "package"
* - url: Download URL (if type is "download")
* - path: Source binary path (if type is "extract")
* - spec: Package spec (if type is "package")
* - update_check: Update checking metadata (optional)
* - last_check: Timestamp of last update check
* - last_notification: Timestamp of last user notification
* - latest_known: Latest known version string
*
* Example:
* ```json
* {
* "version": "1.0.0",
* "cache_key": "a1b2c3d4e5f67890",
* "timestamp": 1730332800000,
* "integrity": "sha512-abc123base64...",
* "size": 15000000,
* "source": {
* "type": "download",
* "url": "https://example.com/binary"
* },
* "update_check": {
* "last_check": 1730332800000,
* "last_notification": 1730246400000,
* "latest_known": "2.1.0"
* }
* }
* ```
*
* @internal This interface documents the metadata file format.
*/
export interface DlxMetadata {
version: string
cache_key: string
timestamp: number
integrity: string
size: number
source?: {
type: 'download' | 'extract' | 'package'
url?: string
path?: string
spec?: string
}
update_check?: {
last_check: number
last_notification: number
latest_known: string
}
}