@ricsam/quickjs-test-utils 1.0.15 → 1.0.17
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/dist/cjs/package.json +1 -1
- package/dist/cjs/quickjs-types.cjs +291 -1
- package/dist/cjs/quickjs-types.cjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/mjs/quickjs-types.mjs +291 -1
- package/dist/mjs/quickjs-types.mjs.map +3 -3
- package/dist/types/quickjs-types.d.ts +7 -0
- package/package.json +5 -5
package/dist/cjs/package.json
CHANGED
|
@@ -36,6 +36,7 @@ __export(exports_quickjs_types, {
|
|
|
36
36
|
FS_TYPES: () => FS_TYPES,
|
|
37
37
|
FETCH_TYPES: () => FETCH_TYPES,
|
|
38
38
|
ENCODING_TYPES: () => ENCODING_TYPES,
|
|
39
|
+
CRYPTO_TYPES: () => CRYPTO_TYPES,
|
|
39
40
|
CORE_TYPES: () => CORE_TYPES,
|
|
40
41
|
CONSOLE_TYPES: () => CONSOLE_TYPES
|
|
41
42
|
});
|
|
@@ -1168,6 +1169,294 @@ declare global {
|
|
|
1168
1169
|
function btoa(stringToEncode: string): string;
|
|
1169
1170
|
}
|
|
1170
1171
|
`;
|
|
1172
|
+
var CRYPTO_TYPES = `/**
|
|
1173
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-crypto
|
|
1174
|
+
*
|
|
1175
|
+
* These types define the globals injected by setupCrypto() into a QuickJS context.
|
|
1176
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
1177
|
+
*
|
|
1178
|
+
* @example
|
|
1179
|
+
* // Generate random bytes
|
|
1180
|
+
* const arr = new Uint8Array(16);
|
|
1181
|
+
* crypto.getRandomValues(arr);
|
|
1182
|
+
*
|
|
1183
|
+
* // Generate UUID
|
|
1184
|
+
* const uuid = crypto.randomUUID();
|
|
1185
|
+
*
|
|
1186
|
+
* // Use SubtleCrypto
|
|
1187
|
+
* const key = await crypto.subtle.generateKey(
|
|
1188
|
+
* { name: "AES-GCM", length: 256 },
|
|
1189
|
+
* true,
|
|
1190
|
+
* ["encrypt", "decrypt"]
|
|
1191
|
+
* );
|
|
1192
|
+
*/
|
|
1193
|
+
|
|
1194
|
+
export {};
|
|
1195
|
+
|
|
1196
|
+
declare global {
|
|
1197
|
+
/**
|
|
1198
|
+
* CryptoKey represents a cryptographic key.
|
|
1199
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey
|
|
1200
|
+
*/
|
|
1201
|
+
interface CryptoKey {
|
|
1202
|
+
/**
|
|
1203
|
+
* The type of key: "public", "private", or "secret".
|
|
1204
|
+
*/
|
|
1205
|
+
readonly type: "public" | "private" | "secret";
|
|
1206
|
+
|
|
1207
|
+
/**
|
|
1208
|
+
* Whether the key can be exported.
|
|
1209
|
+
*/
|
|
1210
|
+
readonly extractable: boolean;
|
|
1211
|
+
|
|
1212
|
+
/**
|
|
1213
|
+
* The algorithm used by this key.
|
|
1214
|
+
*/
|
|
1215
|
+
readonly algorithm: KeyAlgorithm;
|
|
1216
|
+
|
|
1217
|
+
/**
|
|
1218
|
+
* The usages allowed for this key.
|
|
1219
|
+
*/
|
|
1220
|
+
readonly usages: ReadonlyArray<KeyUsage>;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
/**
|
|
1224
|
+
* CryptoKey constructor (keys cannot be constructed directly).
|
|
1225
|
+
*/
|
|
1226
|
+
const CryptoKey: {
|
|
1227
|
+
prototype: CryptoKey;
|
|
1228
|
+
};
|
|
1229
|
+
|
|
1230
|
+
/**
|
|
1231
|
+
* SubtleCrypto interface for cryptographic operations.
|
|
1232
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto
|
|
1233
|
+
*/
|
|
1234
|
+
interface SubtleCrypto {
|
|
1235
|
+
/**
|
|
1236
|
+
* Generate a digest (hash) of the given data.
|
|
1237
|
+
*
|
|
1238
|
+
* @param algorithm - Hash algorithm (e.g., "SHA-256", "SHA-384", "SHA-512")
|
|
1239
|
+
* @param data - Data to hash
|
|
1240
|
+
* @returns Promise resolving to the hash as ArrayBuffer
|
|
1241
|
+
*/
|
|
1242
|
+
digest(
|
|
1243
|
+
algorithm: AlgorithmIdentifier,
|
|
1244
|
+
data: BufferSource
|
|
1245
|
+
): Promise<ArrayBuffer>;
|
|
1246
|
+
|
|
1247
|
+
/**
|
|
1248
|
+
* Generate a new cryptographic key or key pair.
|
|
1249
|
+
*
|
|
1250
|
+
* @param algorithm - Key generation algorithm
|
|
1251
|
+
* @param extractable - Whether the key can be exported
|
|
1252
|
+
* @param keyUsages - Allowed key usages
|
|
1253
|
+
* @returns Promise resolving to a CryptoKey or CryptoKeyPair
|
|
1254
|
+
*/
|
|
1255
|
+
generateKey(
|
|
1256
|
+
algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,
|
|
1257
|
+
extractable: boolean,
|
|
1258
|
+
keyUsages: KeyUsage[]
|
|
1259
|
+
): Promise<CryptoKey | CryptoKeyPair>;
|
|
1260
|
+
|
|
1261
|
+
/**
|
|
1262
|
+
* Sign data using a private key.
|
|
1263
|
+
*
|
|
1264
|
+
* @param algorithm - Signing algorithm
|
|
1265
|
+
* @param key - Private key to sign with
|
|
1266
|
+
* @param data - Data to sign
|
|
1267
|
+
* @returns Promise resolving to the signature as ArrayBuffer
|
|
1268
|
+
*/
|
|
1269
|
+
sign(
|
|
1270
|
+
algorithm: AlgorithmIdentifier,
|
|
1271
|
+
key: CryptoKey,
|
|
1272
|
+
data: BufferSource
|
|
1273
|
+
): Promise<ArrayBuffer>;
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Verify a signature.
|
|
1277
|
+
*
|
|
1278
|
+
* @param algorithm - Signing algorithm
|
|
1279
|
+
* @param key - Public key to verify with
|
|
1280
|
+
* @param signature - Signature to verify
|
|
1281
|
+
* @param data - Data that was signed
|
|
1282
|
+
* @returns Promise resolving to true if valid, false otherwise
|
|
1283
|
+
*/
|
|
1284
|
+
verify(
|
|
1285
|
+
algorithm: AlgorithmIdentifier,
|
|
1286
|
+
key: CryptoKey,
|
|
1287
|
+
signature: BufferSource,
|
|
1288
|
+
data: BufferSource
|
|
1289
|
+
): Promise<boolean>;
|
|
1290
|
+
|
|
1291
|
+
/**
|
|
1292
|
+
* Encrypt data.
|
|
1293
|
+
*
|
|
1294
|
+
* @param algorithm - Encryption algorithm
|
|
1295
|
+
* @param key - Encryption key
|
|
1296
|
+
* @param data - Data to encrypt
|
|
1297
|
+
* @returns Promise resolving to encrypted data as ArrayBuffer
|
|
1298
|
+
*/
|
|
1299
|
+
encrypt(
|
|
1300
|
+
algorithm: AlgorithmIdentifier,
|
|
1301
|
+
key: CryptoKey,
|
|
1302
|
+
data: BufferSource
|
|
1303
|
+
): Promise<ArrayBuffer>;
|
|
1304
|
+
|
|
1305
|
+
/**
|
|
1306
|
+
* Decrypt data.
|
|
1307
|
+
*
|
|
1308
|
+
* @param algorithm - Decryption algorithm
|
|
1309
|
+
* @param key - Decryption key
|
|
1310
|
+
* @param data - Data to decrypt
|
|
1311
|
+
* @returns Promise resolving to decrypted data as ArrayBuffer
|
|
1312
|
+
*/
|
|
1313
|
+
decrypt(
|
|
1314
|
+
algorithm: AlgorithmIdentifier,
|
|
1315
|
+
key: CryptoKey,
|
|
1316
|
+
data: BufferSource
|
|
1317
|
+
): Promise<ArrayBuffer>;
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* Import a key from external data.
|
|
1321
|
+
*
|
|
1322
|
+
* @param format - Key format ("raw", "pkcs8", "spki", "jwk")
|
|
1323
|
+
* @param keyData - Key data
|
|
1324
|
+
* @param algorithm - Key algorithm
|
|
1325
|
+
* @param extractable - Whether the key can be exported
|
|
1326
|
+
* @param keyUsages - Allowed key usages
|
|
1327
|
+
* @returns Promise resolving to a CryptoKey
|
|
1328
|
+
*/
|
|
1329
|
+
importKey(
|
|
1330
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1331
|
+
keyData: BufferSource | JsonWebKey,
|
|
1332
|
+
algorithm: AlgorithmIdentifier,
|
|
1333
|
+
extractable: boolean,
|
|
1334
|
+
keyUsages: KeyUsage[]
|
|
1335
|
+
): Promise<CryptoKey>;
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Export a key.
|
|
1339
|
+
*
|
|
1340
|
+
* @param format - Export format ("raw", "pkcs8", "spki", "jwk")
|
|
1341
|
+
* @param key - Key to export
|
|
1342
|
+
* @returns Promise resolving to ArrayBuffer or JsonWebKey
|
|
1343
|
+
*/
|
|
1344
|
+
exportKey(
|
|
1345
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1346
|
+
key: CryptoKey
|
|
1347
|
+
): Promise<ArrayBuffer | JsonWebKey>;
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Derive bits from a key.
|
|
1351
|
+
*
|
|
1352
|
+
* @param algorithm - Derivation algorithm
|
|
1353
|
+
* @param baseKey - Base key for derivation
|
|
1354
|
+
* @param length - Number of bits to derive
|
|
1355
|
+
* @returns Promise resolving to derived bits as ArrayBuffer
|
|
1356
|
+
*/
|
|
1357
|
+
deriveBits(
|
|
1358
|
+
algorithm: AlgorithmIdentifier,
|
|
1359
|
+
baseKey: CryptoKey,
|
|
1360
|
+
length: number
|
|
1361
|
+
): Promise<ArrayBuffer>;
|
|
1362
|
+
|
|
1363
|
+
/**
|
|
1364
|
+
* Derive a new key from a base key.
|
|
1365
|
+
*
|
|
1366
|
+
* @param algorithm - Derivation algorithm
|
|
1367
|
+
* @param baseKey - Base key for derivation
|
|
1368
|
+
* @param derivedKeyType - Type of key to derive
|
|
1369
|
+
* @param extractable - Whether the derived key can be exported
|
|
1370
|
+
* @param keyUsages - Allowed usages for derived key
|
|
1371
|
+
* @returns Promise resolving to a CryptoKey
|
|
1372
|
+
*/
|
|
1373
|
+
deriveKey(
|
|
1374
|
+
algorithm: AlgorithmIdentifier,
|
|
1375
|
+
baseKey: CryptoKey,
|
|
1376
|
+
derivedKeyType: AlgorithmIdentifier,
|
|
1377
|
+
extractable: boolean,
|
|
1378
|
+
keyUsages: KeyUsage[]
|
|
1379
|
+
): Promise<CryptoKey>;
|
|
1380
|
+
|
|
1381
|
+
/**
|
|
1382
|
+
* Wrap a key for secure export.
|
|
1383
|
+
*
|
|
1384
|
+
* @param format - Key format
|
|
1385
|
+
* @param key - Key to wrap
|
|
1386
|
+
* @param wrappingKey - Key to wrap with
|
|
1387
|
+
* @param wrapAlgorithm - Wrapping algorithm
|
|
1388
|
+
* @returns Promise resolving to wrapped key as ArrayBuffer
|
|
1389
|
+
*/
|
|
1390
|
+
wrapKey(
|
|
1391
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1392
|
+
key: CryptoKey,
|
|
1393
|
+
wrappingKey: CryptoKey,
|
|
1394
|
+
wrapAlgorithm: AlgorithmIdentifier
|
|
1395
|
+
): Promise<ArrayBuffer>;
|
|
1396
|
+
|
|
1397
|
+
/**
|
|
1398
|
+
* Unwrap a wrapped key.
|
|
1399
|
+
*
|
|
1400
|
+
* @param format - Key format
|
|
1401
|
+
* @param wrappedKey - Wrapped key data
|
|
1402
|
+
* @param unwrappingKey - Key to unwrap with
|
|
1403
|
+
* @param unwrapAlgorithm - Unwrapping algorithm
|
|
1404
|
+
* @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key
|
|
1405
|
+
* @param extractable - Whether the unwrapped key can be exported
|
|
1406
|
+
* @param keyUsages - Allowed usages for unwrapped key
|
|
1407
|
+
* @returns Promise resolving to a CryptoKey
|
|
1408
|
+
*/
|
|
1409
|
+
unwrapKey(
|
|
1410
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1411
|
+
wrappedKey: BufferSource,
|
|
1412
|
+
unwrappingKey: CryptoKey,
|
|
1413
|
+
unwrapAlgorithm: AlgorithmIdentifier,
|
|
1414
|
+
unwrappedKeyAlgorithm: AlgorithmIdentifier,
|
|
1415
|
+
extractable: boolean,
|
|
1416
|
+
keyUsages: KeyUsage[]
|
|
1417
|
+
): Promise<CryptoKey>;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* Crypto interface providing cryptographic functionality.
|
|
1422
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto
|
|
1423
|
+
*/
|
|
1424
|
+
interface Crypto {
|
|
1425
|
+
/**
|
|
1426
|
+
* SubtleCrypto interface for cryptographic operations.
|
|
1427
|
+
*/
|
|
1428
|
+
readonly subtle: SubtleCrypto;
|
|
1429
|
+
|
|
1430
|
+
/**
|
|
1431
|
+
* Fill a TypedArray with cryptographically random values.
|
|
1432
|
+
*
|
|
1433
|
+
* @param array - TypedArray to fill (max 65536 bytes)
|
|
1434
|
+
* @returns The same array, filled with random values
|
|
1435
|
+
*
|
|
1436
|
+
* @example
|
|
1437
|
+
* const arr = new Uint8Array(16);
|
|
1438
|
+
* crypto.getRandomValues(arr);
|
|
1439
|
+
*/
|
|
1440
|
+
getRandomValues<T extends ArrayBufferView | null>(array: T): T;
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* Generate a random UUID v4.
|
|
1444
|
+
*
|
|
1445
|
+
* @returns A random UUID string
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* const uuid = crypto.randomUUID();
|
|
1449
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
1450
|
+
*/
|
|
1451
|
+
randomUUID(): string;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
/**
|
|
1455
|
+
* Crypto object providing cryptographic functionality.
|
|
1456
|
+
*/
|
|
1457
|
+
const crypto: Crypto;
|
|
1458
|
+
}
|
|
1459
|
+
`;
|
|
1171
1460
|
var TIMERS_TYPES = `/**
|
|
1172
1461
|
* QuickJS Global Type Definitions for @ricsam/quickjs-timers
|
|
1173
1462
|
*
|
|
@@ -1252,6 +1541,7 @@ declare global {
|
|
|
1252
1541
|
var TYPE_DEFINITIONS = {
|
|
1253
1542
|
core: CORE_TYPES,
|
|
1254
1543
|
console: CONSOLE_TYPES,
|
|
1544
|
+
crypto: CRYPTO_TYPES,
|
|
1255
1545
|
encoding: ENCODING_TYPES,
|
|
1256
1546
|
fetch: FETCH_TYPES,
|
|
1257
1547
|
fs: FS_TYPES,
|
|
@@ -1260,4 +1550,4 @@ var TYPE_DEFINITIONS = {
|
|
|
1260
1550
|
};
|
|
1261
1551
|
})
|
|
1262
1552
|
|
|
1263
|
-
//# debugId=
|
|
1553
|
+
//# debugId=0BC014EC5A81951964756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/quickjs-types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * type WebSocketData = { id: number; connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * // server.upgrade knows data should be WebSocketData\n * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * // Type hint - specifies the type of ws.data\n * data: {} as WebSocketData,\n * message(ws, message) {\n * // ws.data is typed as WebSocketData\n * console.log(\"User\", ws.data.id, \"says:\", message);\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface Server<T = unknown> {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: T }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server<T>): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Type hint for WebSocket data. The value is not used at runtime.\n * Specifies the type of \\`ws.data\\` for all handlers and \\`server.upgrade()\\`.\n *\n * @example\n * websocket: {\n * data: {} as { userId: string },\n * message(ws, message) {\n * // ws.data.userId is typed as string\n * }\n * }\n */\n data?: T;\n\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * type WsData = { connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * data: {} as WsData,\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-console globals.\n *\n * Includes: console.log, warn, error, debug, info, trace, dir, table, time, timeEnd, timeLog, count, countReset, clear, assert, group, groupCollapsed, groupEnd\n */\nexport const CONSOLE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-console\n *\n * These types define the globals injected by setupConsole() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-encoding globals.\n *\n * Includes: atob, btoa\n */\nexport const ENCODING_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-timers globals.\n *\n * Includes: setTimeout, setInterval, clearTimeout, clearInterval\n */\nexport const TIMERS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-timers\n *\n * These types define the globals injected by setupTimers() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * const timeoutId = setTimeout(() => {\n * console.log(\"fired!\");\n * }, 1000);\n *\n * clearTimeout(timeoutId);\n *\n * const intervalId = setInterval(() => {\n * console.log(\"tick\");\n * }, 100);\n *\n * clearInterval(intervalId);\n */\n\nexport {};\n\ndeclare global {\n /**\n * Schedule a callback to execute after a delay.\n *\n * @param callback - The function to call after the delay\n * @param ms - The delay in milliseconds (default: 0)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearTimeout\n *\n * @example\n * const id = setTimeout(() => console.log(\"done\"), 1000);\n * setTimeout((a, b) => console.log(a, b), 100, \"hello\", \"world\");\n */\n function setTimeout(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Schedule a callback to execute repeatedly at a fixed interval.\n *\n * @param callback - The function to call at each interval\n * @param ms - The interval in milliseconds (minimum: 4ms)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearInterval\n *\n * @example\n * const id = setInterval(() => console.log(\"tick\"), 1000);\n */\n function setInterval(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Cancel a timeout previously scheduled with setTimeout.\n *\n * @param id - The timer ID returned by setTimeout\n *\n * @example\n * const id = setTimeout(() => {}, 1000);\n * clearTimeout(id);\n */\n function clearTimeout(id: number | undefined): void;\n\n /**\n * Cancel an interval previously scheduled with setInterval.\n *\n * @param id - The timer ID returned by setInterval\n *\n * @example\n * const id = setInterval(() => {}, 1000);\n * clearInterval(id);\n */\n function clearInterval(id: number | undefined): void;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n console: CONSOLE_TYPES,\n encoding: ENCODING_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n timers: TIMERS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
5
|
+
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * type WebSocketData = { id: number; connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * // server.upgrade knows data should be WebSocketData\n * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * // Type hint - specifies the type of ws.data\n * data: {} as WebSocketData,\n * message(ws, message) {\n * // ws.data is typed as WebSocketData\n * console.log(\"User\", ws.data.id, \"says:\", message);\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface Server<T = unknown> {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: T }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server<T>): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Type hint for WebSocket data. The value is not used at runtime.\n * Specifies the type of \\`ws.data\\` for all handlers and \\`server.upgrade()\\`.\n *\n * @example\n * websocket: {\n * data: {} as { userId: string },\n * message(ws, message) {\n * // ws.data.userId is typed as string\n * }\n * }\n */\n data?: T;\n\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * type WsData = { connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * data: {} as WsData,\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-console globals.\n *\n * Includes: console.log, warn, error, debug, info, trace, dir, table, time, timeEnd, timeLog, count, countReset, clear, assert, group, groupCollapsed, groupEnd\n */\nexport const CONSOLE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-console\n *\n * These types define the globals injected by setupConsole() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-encoding globals.\n *\n * Includes: atob, btoa\n */\nexport const ENCODING_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-crypto globals.\n *\n * Includes: crypto.subtle, crypto.getRandomValues, crypto.randomUUID, CryptoKey\n */\nexport const CRYPTO_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-crypto\n *\n * These types define the globals injected by setupCrypto() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Generate random bytes\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n *\n * // Generate UUID\n * const uuid = crypto.randomUUID();\n *\n * // Use SubtleCrypto\n * const key = await crypto.subtle.generateKey(\n * { name: \"AES-GCM\", length: 256 },\n * true,\n * [\"encrypt\", \"decrypt\"]\n * );\n */\n\nexport {};\n\ndeclare global {\n /**\n * CryptoKey represents a cryptographic key.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\n */\n interface CryptoKey {\n /**\n * The type of key: \"public\", \"private\", or \"secret\".\n */\n readonly type: \"public\" | \"private\" | \"secret\";\n\n /**\n * Whether the key can be exported.\n */\n readonly extractable: boolean;\n\n /**\n * The algorithm used by this key.\n */\n readonly algorithm: KeyAlgorithm;\n\n /**\n * The usages allowed for this key.\n */\n readonly usages: ReadonlyArray<KeyUsage>;\n }\n\n /**\n * CryptoKey constructor (keys cannot be constructed directly).\n */\n const CryptoKey: {\n prototype: CryptoKey;\n };\n\n /**\n * SubtleCrypto interface for cryptographic operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\n */\n interface SubtleCrypto {\n /**\n * Generate a digest (hash) of the given data.\n *\n * @param algorithm - Hash algorithm (e.g., \"SHA-256\", \"SHA-384\", \"SHA-512\")\n * @param data - Data to hash\n * @returns Promise resolving to the hash as ArrayBuffer\n */\n digest(\n algorithm: AlgorithmIdentifier,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Generate a new cryptographic key or key pair.\n *\n * @param algorithm - Key generation algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey or CryptoKeyPair\n */\n generateKey(\n algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair>;\n\n /**\n * Sign data using a private key.\n *\n * @param algorithm - Signing algorithm\n * @param key - Private key to sign with\n * @param data - Data to sign\n * @returns Promise resolving to the signature as ArrayBuffer\n */\n sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Verify a signature.\n *\n * @param algorithm - Signing algorithm\n * @param key - Public key to verify with\n * @param signature - Signature to verify\n * @param data - Data that was signed\n * @returns Promise resolving to true if valid, false otherwise\n */\n verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean>;\n\n /**\n * Encrypt data.\n *\n * @param algorithm - Encryption algorithm\n * @param key - Encryption key\n * @param data - Data to encrypt\n * @returns Promise resolving to encrypted data as ArrayBuffer\n */\n encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Decrypt data.\n *\n * @param algorithm - Decryption algorithm\n * @param key - Decryption key\n * @param data - Data to decrypt\n * @returns Promise resolving to decrypted data as ArrayBuffer\n */\n decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Import a key from external data.\n *\n * @param format - Key format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param keyData - Key data\n * @param algorithm - Key algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey\n */\n importKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Export a key.\n *\n * @param format - Export format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param key - Key to export\n * @returns Promise resolving to ArrayBuffer or JsonWebKey\n */\n exportKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey\n ): Promise<ArrayBuffer | JsonWebKey>;\n\n /**\n * Derive bits from a key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param length - Number of bits to derive\n * @returns Promise resolving to derived bits as ArrayBuffer\n */\n deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer>;\n\n /**\n * Derive a new key from a base key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param derivedKeyType - Type of key to derive\n * @param extractable - Whether the derived key can be exported\n * @param keyUsages - Allowed usages for derived key\n * @returns Promise resolving to a CryptoKey\n */\n deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyType: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Wrap a key for secure export.\n *\n * @param format - Key format\n * @param key - Key to wrap\n * @param wrappingKey - Key to wrap with\n * @param wrapAlgorithm - Wrapping algorithm\n * @returns Promise resolving to wrapped key as ArrayBuffer\n */\n wrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer>;\n\n /**\n * Unwrap a wrapped key.\n *\n * @param format - Key format\n * @param wrappedKey - Wrapped key data\n * @param unwrappingKey - Key to unwrap with\n * @param unwrapAlgorithm - Unwrapping algorithm\n * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key\n * @param extractable - Whether the unwrapped key can be exported\n * @param keyUsages - Allowed usages for unwrapped key\n * @returns Promise resolving to a CryptoKey\n */\n unwrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n }\n\n /**\n * Crypto interface providing cryptographic functionality.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n */\n interface Crypto {\n /**\n * SubtleCrypto interface for cryptographic operations.\n */\n readonly subtle: SubtleCrypto;\n\n /**\n * Fill a TypedArray with cryptographically random values.\n *\n * @param array - TypedArray to fill (max 65536 bytes)\n * @returns The same array, filled with random values\n *\n * @example\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n */\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n\n /**\n * Generate a random UUID v4.\n *\n * @returns A random UUID string\n *\n * @example\n * const uuid = crypto.randomUUID();\n * // \"550e8400-e29b-41d4-a716-446655440000\"\n */\n randomUUID(): string;\n }\n\n /**\n * Crypto object providing cryptographic functionality.\n */\n const crypto: Crypto;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-timers globals.\n *\n * Includes: setTimeout, setInterval, clearTimeout, clearInterval\n */\nexport const TIMERS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-timers\n *\n * These types define the globals injected by setupTimers() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * const timeoutId = setTimeout(() => {\n * console.log(\"fired!\");\n * }, 1000);\n *\n * clearTimeout(timeoutId);\n *\n * const intervalId = setInterval(() => {\n * console.log(\"tick\");\n * }, 100);\n *\n * clearInterval(intervalId);\n */\n\nexport {};\n\ndeclare global {\n /**\n * Schedule a callback to execute after a delay.\n *\n * @param callback - The function to call after the delay\n * @param ms - The delay in milliseconds (default: 0)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearTimeout\n *\n * @example\n * const id = setTimeout(() => console.log(\"done\"), 1000);\n * setTimeout((a, b) => console.log(a, b), 100, \"hello\", \"world\");\n */\n function setTimeout(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Schedule a callback to execute repeatedly at a fixed interval.\n *\n * @param callback - The function to call at each interval\n * @param ms - The interval in milliseconds (minimum: 4ms)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearInterval\n *\n * @example\n * const id = setInterval(() => console.log(\"tick\"), 1000);\n */\n function setInterval(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Cancel a timeout previously scheduled with setTimeout.\n *\n * @param id - The timer ID returned by setTimeout\n *\n * @example\n * const id = setTimeout(() => {}, 1000);\n * clearTimeout(id);\n */\n function clearTimeout(id: number | undefined): void;\n\n /**\n * Cancel an interval previously scheduled with setInterval.\n *\n * @param id - The timer ID returned by setInterval\n *\n * @example\n * const id = setInterval(() => {}, 1000);\n * clearInterval(id);\n */\n function clearInterval(id: number | undefined): void;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n console: CONSOLE_TYPES,\n crypto: CRYPTO_TYPES,\n encoding: ENCODING_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n timers: TIMERS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAuGnB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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
1128
|
function btoa(stringToEncode: string): string;
|
|
1129
1129
|
}
|
|
1130
1130
|
`;
|
|
1131
|
+
var CRYPTO_TYPES = `/**
|
|
1132
|
+
* QuickJS Global Type Definitions for @ricsam/quickjs-crypto
|
|
1133
|
+
*
|
|
1134
|
+
* These types define the globals injected by setupCrypto() into a QuickJS context.
|
|
1135
|
+
* Use these types to typecheck user code that will run inside QuickJS.
|
|
1136
|
+
*
|
|
1137
|
+
* @example
|
|
1138
|
+
* // Generate random bytes
|
|
1139
|
+
* const arr = new Uint8Array(16);
|
|
1140
|
+
* crypto.getRandomValues(arr);
|
|
1141
|
+
*
|
|
1142
|
+
* // Generate UUID
|
|
1143
|
+
* const uuid = crypto.randomUUID();
|
|
1144
|
+
*
|
|
1145
|
+
* // Use SubtleCrypto
|
|
1146
|
+
* const key = await crypto.subtle.generateKey(
|
|
1147
|
+
* { name: "AES-GCM", length: 256 },
|
|
1148
|
+
* true,
|
|
1149
|
+
* ["encrypt", "decrypt"]
|
|
1150
|
+
* );
|
|
1151
|
+
*/
|
|
1152
|
+
|
|
1153
|
+
export {};
|
|
1154
|
+
|
|
1155
|
+
declare global {
|
|
1156
|
+
/**
|
|
1157
|
+
* CryptoKey represents a cryptographic key.
|
|
1158
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey
|
|
1159
|
+
*/
|
|
1160
|
+
interface CryptoKey {
|
|
1161
|
+
/**
|
|
1162
|
+
* The type of key: "public", "private", or "secret".
|
|
1163
|
+
*/
|
|
1164
|
+
readonly type: "public" | "private" | "secret";
|
|
1165
|
+
|
|
1166
|
+
/**
|
|
1167
|
+
* Whether the key can be exported.
|
|
1168
|
+
*/
|
|
1169
|
+
readonly extractable: boolean;
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* The algorithm used by this key.
|
|
1173
|
+
*/
|
|
1174
|
+
readonly algorithm: KeyAlgorithm;
|
|
1175
|
+
|
|
1176
|
+
/**
|
|
1177
|
+
* The usages allowed for this key.
|
|
1178
|
+
*/
|
|
1179
|
+
readonly usages: ReadonlyArray<KeyUsage>;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
/**
|
|
1183
|
+
* CryptoKey constructor (keys cannot be constructed directly).
|
|
1184
|
+
*/
|
|
1185
|
+
const CryptoKey: {
|
|
1186
|
+
prototype: CryptoKey;
|
|
1187
|
+
};
|
|
1188
|
+
|
|
1189
|
+
/**
|
|
1190
|
+
* SubtleCrypto interface for cryptographic operations.
|
|
1191
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto
|
|
1192
|
+
*/
|
|
1193
|
+
interface SubtleCrypto {
|
|
1194
|
+
/**
|
|
1195
|
+
* Generate a digest (hash) of the given data.
|
|
1196
|
+
*
|
|
1197
|
+
* @param algorithm - Hash algorithm (e.g., "SHA-256", "SHA-384", "SHA-512")
|
|
1198
|
+
* @param data - Data to hash
|
|
1199
|
+
* @returns Promise resolving to the hash as ArrayBuffer
|
|
1200
|
+
*/
|
|
1201
|
+
digest(
|
|
1202
|
+
algorithm: AlgorithmIdentifier,
|
|
1203
|
+
data: BufferSource
|
|
1204
|
+
): Promise<ArrayBuffer>;
|
|
1205
|
+
|
|
1206
|
+
/**
|
|
1207
|
+
* Generate a new cryptographic key or key pair.
|
|
1208
|
+
*
|
|
1209
|
+
* @param algorithm - Key generation algorithm
|
|
1210
|
+
* @param extractable - Whether the key can be exported
|
|
1211
|
+
* @param keyUsages - Allowed key usages
|
|
1212
|
+
* @returns Promise resolving to a CryptoKey or CryptoKeyPair
|
|
1213
|
+
*/
|
|
1214
|
+
generateKey(
|
|
1215
|
+
algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,
|
|
1216
|
+
extractable: boolean,
|
|
1217
|
+
keyUsages: KeyUsage[]
|
|
1218
|
+
): Promise<CryptoKey | CryptoKeyPair>;
|
|
1219
|
+
|
|
1220
|
+
/**
|
|
1221
|
+
* Sign data using a private key.
|
|
1222
|
+
*
|
|
1223
|
+
* @param algorithm - Signing algorithm
|
|
1224
|
+
* @param key - Private key to sign with
|
|
1225
|
+
* @param data - Data to sign
|
|
1226
|
+
* @returns Promise resolving to the signature as ArrayBuffer
|
|
1227
|
+
*/
|
|
1228
|
+
sign(
|
|
1229
|
+
algorithm: AlgorithmIdentifier,
|
|
1230
|
+
key: CryptoKey,
|
|
1231
|
+
data: BufferSource
|
|
1232
|
+
): Promise<ArrayBuffer>;
|
|
1233
|
+
|
|
1234
|
+
/**
|
|
1235
|
+
* Verify a signature.
|
|
1236
|
+
*
|
|
1237
|
+
* @param algorithm - Signing algorithm
|
|
1238
|
+
* @param key - Public key to verify with
|
|
1239
|
+
* @param signature - Signature to verify
|
|
1240
|
+
* @param data - Data that was signed
|
|
1241
|
+
* @returns Promise resolving to true if valid, false otherwise
|
|
1242
|
+
*/
|
|
1243
|
+
verify(
|
|
1244
|
+
algorithm: AlgorithmIdentifier,
|
|
1245
|
+
key: CryptoKey,
|
|
1246
|
+
signature: BufferSource,
|
|
1247
|
+
data: BufferSource
|
|
1248
|
+
): Promise<boolean>;
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Encrypt data.
|
|
1252
|
+
*
|
|
1253
|
+
* @param algorithm - Encryption algorithm
|
|
1254
|
+
* @param key - Encryption key
|
|
1255
|
+
* @param data - Data to encrypt
|
|
1256
|
+
* @returns Promise resolving to encrypted data as ArrayBuffer
|
|
1257
|
+
*/
|
|
1258
|
+
encrypt(
|
|
1259
|
+
algorithm: AlgorithmIdentifier,
|
|
1260
|
+
key: CryptoKey,
|
|
1261
|
+
data: BufferSource
|
|
1262
|
+
): Promise<ArrayBuffer>;
|
|
1263
|
+
|
|
1264
|
+
/**
|
|
1265
|
+
* Decrypt data.
|
|
1266
|
+
*
|
|
1267
|
+
* @param algorithm - Decryption algorithm
|
|
1268
|
+
* @param key - Decryption key
|
|
1269
|
+
* @param data - Data to decrypt
|
|
1270
|
+
* @returns Promise resolving to decrypted data as ArrayBuffer
|
|
1271
|
+
*/
|
|
1272
|
+
decrypt(
|
|
1273
|
+
algorithm: AlgorithmIdentifier,
|
|
1274
|
+
key: CryptoKey,
|
|
1275
|
+
data: BufferSource
|
|
1276
|
+
): Promise<ArrayBuffer>;
|
|
1277
|
+
|
|
1278
|
+
/**
|
|
1279
|
+
* Import a key from external data.
|
|
1280
|
+
*
|
|
1281
|
+
* @param format - Key format ("raw", "pkcs8", "spki", "jwk")
|
|
1282
|
+
* @param keyData - Key data
|
|
1283
|
+
* @param algorithm - Key algorithm
|
|
1284
|
+
* @param extractable - Whether the key can be exported
|
|
1285
|
+
* @param keyUsages - Allowed key usages
|
|
1286
|
+
* @returns Promise resolving to a CryptoKey
|
|
1287
|
+
*/
|
|
1288
|
+
importKey(
|
|
1289
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1290
|
+
keyData: BufferSource | JsonWebKey,
|
|
1291
|
+
algorithm: AlgorithmIdentifier,
|
|
1292
|
+
extractable: boolean,
|
|
1293
|
+
keyUsages: KeyUsage[]
|
|
1294
|
+
): Promise<CryptoKey>;
|
|
1295
|
+
|
|
1296
|
+
/**
|
|
1297
|
+
* Export a key.
|
|
1298
|
+
*
|
|
1299
|
+
* @param format - Export format ("raw", "pkcs8", "spki", "jwk")
|
|
1300
|
+
* @param key - Key to export
|
|
1301
|
+
* @returns Promise resolving to ArrayBuffer or JsonWebKey
|
|
1302
|
+
*/
|
|
1303
|
+
exportKey(
|
|
1304
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1305
|
+
key: CryptoKey
|
|
1306
|
+
): Promise<ArrayBuffer | JsonWebKey>;
|
|
1307
|
+
|
|
1308
|
+
/**
|
|
1309
|
+
* Derive bits from a key.
|
|
1310
|
+
*
|
|
1311
|
+
* @param algorithm - Derivation algorithm
|
|
1312
|
+
* @param baseKey - Base key for derivation
|
|
1313
|
+
* @param length - Number of bits to derive
|
|
1314
|
+
* @returns Promise resolving to derived bits as ArrayBuffer
|
|
1315
|
+
*/
|
|
1316
|
+
deriveBits(
|
|
1317
|
+
algorithm: AlgorithmIdentifier,
|
|
1318
|
+
baseKey: CryptoKey,
|
|
1319
|
+
length: number
|
|
1320
|
+
): Promise<ArrayBuffer>;
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Derive a new key from a base key.
|
|
1324
|
+
*
|
|
1325
|
+
* @param algorithm - Derivation algorithm
|
|
1326
|
+
* @param baseKey - Base key for derivation
|
|
1327
|
+
* @param derivedKeyType - Type of key to derive
|
|
1328
|
+
* @param extractable - Whether the derived key can be exported
|
|
1329
|
+
* @param keyUsages - Allowed usages for derived key
|
|
1330
|
+
* @returns Promise resolving to a CryptoKey
|
|
1331
|
+
*/
|
|
1332
|
+
deriveKey(
|
|
1333
|
+
algorithm: AlgorithmIdentifier,
|
|
1334
|
+
baseKey: CryptoKey,
|
|
1335
|
+
derivedKeyType: AlgorithmIdentifier,
|
|
1336
|
+
extractable: boolean,
|
|
1337
|
+
keyUsages: KeyUsage[]
|
|
1338
|
+
): Promise<CryptoKey>;
|
|
1339
|
+
|
|
1340
|
+
/**
|
|
1341
|
+
* Wrap a key for secure export.
|
|
1342
|
+
*
|
|
1343
|
+
* @param format - Key format
|
|
1344
|
+
* @param key - Key to wrap
|
|
1345
|
+
* @param wrappingKey - Key to wrap with
|
|
1346
|
+
* @param wrapAlgorithm - Wrapping algorithm
|
|
1347
|
+
* @returns Promise resolving to wrapped key as ArrayBuffer
|
|
1348
|
+
*/
|
|
1349
|
+
wrapKey(
|
|
1350
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1351
|
+
key: CryptoKey,
|
|
1352
|
+
wrappingKey: CryptoKey,
|
|
1353
|
+
wrapAlgorithm: AlgorithmIdentifier
|
|
1354
|
+
): Promise<ArrayBuffer>;
|
|
1355
|
+
|
|
1356
|
+
/**
|
|
1357
|
+
* Unwrap a wrapped key.
|
|
1358
|
+
*
|
|
1359
|
+
* @param format - Key format
|
|
1360
|
+
* @param wrappedKey - Wrapped key data
|
|
1361
|
+
* @param unwrappingKey - Key to unwrap with
|
|
1362
|
+
* @param unwrapAlgorithm - Unwrapping algorithm
|
|
1363
|
+
* @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key
|
|
1364
|
+
* @param extractable - Whether the unwrapped key can be exported
|
|
1365
|
+
* @param keyUsages - Allowed usages for unwrapped key
|
|
1366
|
+
* @returns Promise resolving to a CryptoKey
|
|
1367
|
+
*/
|
|
1368
|
+
unwrapKey(
|
|
1369
|
+
format: "raw" | "pkcs8" | "spki" | "jwk",
|
|
1370
|
+
wrappedKey: BufferSource,
|
|
1371
|
+
unwrappingKey: CryptoKey,
|
|
1372
|
+
unwrapAlgorithm: AlgorithmIdentifier,
|
|
1373
|
+
unwrappedKeyAlgorithm: AlgorithmIdentifier,
|
|
1374
|
+
extractable: boolean,
|
|
1375
|
+
keyUsages: KeyUsage[]
|
|
1376
|
+
): Promise<CryptoKey>;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Crypto interface providing cryptographic functionality.
|
|
1381
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto
|
|
1382
|
+
*/
|
|
1383
|
+
interface Crypto {
|
|
1384
|
+
/**
|
|
1385
|
+
* SubtleCrypto interface for cryptographic operations.
|
|
1386
|
+
*/
|
|
1387
|
+
readonly subtle: SubtleCrypto;
|
|
1388
|
+
|
|
1389
|
+
/**
|
|
1390
|
+
* Fill a TypedArray with cryptographically random values.
|
|
1391
|
+
*
|
|
1392
|
+
* @param array - TypedArray to fill (max 65536 bytes)
|
|
1393
|
+
* @returns The same array, filled with random values
|
|
1394
|
+
*
|
|
1395
|
+
* @example
|
|
1396
|
+
* const arr = new Uint8Array(16);
|
|
1397
|
+
* crypto.getRandomValues(arr);
|
|
1398
|
+
*/
|
|
1399
|
+
getRandomValues<T extends ArrayBufferView | null>(array: T): T;
|
|
1400
|
+
|
|
1401
|
+
/**
|
|
1402
|
+
* Generate a random UUID v4.
|
|
1403
|
+
*
|
|
1404
|
+
* @returns A random UUID string
|
|
1405
|
+
*
|
|
1406
|
+
* @example
|
|
1407
|
+
* const uuid = crypto.randomUUID();
|
|
1408
|
+
* // "550e8400-e29b-41d4-a716-446655440000"
|
|
1409
|
+
*/
|
|
1410
|
+
randomUUID(): string;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* Crypto object providing cryptographic functionality.
|
|
1415
|
+
*/
|
|
1416
|
+
const crypto: Crypto;
|
|
1417
|
+
}
|
|
1418
|
+
`;
|
|
1131
1419
|
var TIMERS_TYPES = `/**
|
|
1132
1420
|
* QuickJS Global Type Definitions for @ricsam/quickjs-timers
|
|
1133
1421
|
*
|
|
@@ -1212,6 +1500,7 @@ declare global {
|
|
|
1212
1500
|
var TYPE_DEFINITIONS = {
|
|
1213
1501
|
core: CORE_TYPES,
|
|
1214
1502
|
console: CONSOLE_TYPES,
|
|
1503
|
+
crypto: CRYPTO_TYPES,
|
|
1215
1504
|
encoding: ENCODING_TYPES,
|
|
1216
1505
|
fetch: FETCH_TYPES,
|
|
1217
1506
|
fs: FS_TYPES,
|
|
@@ -1225,8 +1514,9 @@ export {
|
|
|
1225
1514
|
FS_TYPES,
|
|
1226
1515
|
FETCH_TYPES,
|
|
1227
1516
|
ENCODING_TYPES,
|
|
1517
|
+
CRYPTO_TYPES,
|
|
1228
1518
|
CORE_TYPES,
|
|
1229
1519
|
CONSOLE_TYPES
|
|
1230
1520
|
};
|
|
1231
1521
|
|
|
1232
|
-
//# debugId=
|
|
1522
|
+
//# debugId=371AE13F6A0C858864756E2164756E21
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/quickjs-types.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * type WebSocketData = { id: number; connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * // server.upgrade knows data should be WebSocketData\n * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * // Type hint - specifies the type of ws.data\n * data: {} as WebSocketData,\n * message(ws, message) {\n * // ws.data is typed as WebSocketData\n * console.log(\"User\", ws.data.id, \"says:\", message);\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface Server<T = unknown> {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: T }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server<T>): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Type hint for WebSocket data. The value is not used at runtime.\n * Specifies the type of \\`ws.data\\` for all handlers and \\`server.upgrade()\\`.\n *\n * @example\n * websocket: {\n * data: {} as { userId: string },\n * message(ws, message) {\n * // ws.data.userId is typed as string\n * }\n * }\n */\n data?: T;\n\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * type WsData = { connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * data: {} as WsData,\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-console globals.\n *\n * Includes: console.log, warn, error, debug, info, trace, dir, table, time, timeEnd, timeLog, count, countReset, clear, assert, group, groupCollapsed, groupEnd\n */\nexport const CONSOLE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-console\n *\n * These types define the globals injected by setupConsole() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-encoding globals.\n *\n * Includes: atob, btoa\n */\nexport const ENCODING_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-timers globals.\n *\n * Includes: setTimeout, setInterval, clearTimeout, clearInterval\n */\nexport const TIMERS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-timers\n *\n * These types define the globals injected by setupTimers() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * const timeoutId = setTimeout(() => {\n * console.log(\"fired!\");\n * }, 1000);\n *\n * clearTimeout(timeoutId);\n *\n * const intervalId = setInterval(() => {\n * console.log(\"tick\");\n * }, 100);\n *\n * clearInterval(intervalId);\n */\n\nexport {};\n\ndeclare global {\n /**\n * Schedule a callback to execute after a delay.\n *\n * @param callback - The function to call after the delay\n * @param ms - The delay in milliseconds (default: 0)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearTimeout\n *\n * @example\n * const id = setTimeout(() => console.log(\"done\"), 1000);\n * setTimeout((a, b) => console.log(a, b), 100, \"hello\", \"world\");\n */\n function setTimeout(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Schedule a callback to execute repeatedly at a fixed interval.\n *\n * @param callback - The function to call at each interval\n * @param ms - The interval in milliseconds (minimum: 4ms)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearInterval\n *\n * @example\n * const id = setInterval(() => console.log(\"tick\"), 1000);\n */\n function setInterval(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Cancel a timeout previously scheduled with setTimeout.\n *\n * @param id - The timer ID returned by setTimeout\n *\n * @example\n * const id = setTimeout(() => {}, 1000);\n * clearTimeout(id);\n */\n function clearTimeout(id: number | undefined): void;\n\n /**\n * Cancel an interval previously scheduled with setInterval.\n *\n * @param id - The timer ID returned by setInterval\n *\n * @example\n * const id = setInterval(() => {}, 1000);\n * clearInterval(id);\n */\n function clearInterval(id: number | undefined): void;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n console: CONSOLE_TYPES,\n encoding: ENCODING_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n timers: TIMERS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
5
|
+
"/**\n * QuickJS type definitions as string constants.\n *\n * These are the canonical source for QuickJS global type definitions.\n * The .d.ts files in each package are generated from these strings during build.\n *\n * @example\n * import { TYPE_DEFINITIONS } from \"@ricsam/quickjs-test-utils\";\n *\n * // Use with ts-morph for type checking code strings\n * project.createSourceFile(\"types.d.ts\", TYPE_DEFINITIONS.fetch);\n */\n\n/**\n * Type definitions for @ricsam/quickjs-core globals.\n *\n * Includes: ReadableStream, WritableStream, TransformStream, Blob, File, URL, URLSearchParams, DOMException\n */\nexport const CORE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fetch globals.\n *\n * Includes: Headers, Request, Response, AbortController, AbortSignal, FormData, fetch, serve, Server, ServerWebSocket\n */\nexport const FETCH_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * type WebSocketData = { id: number; connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * // server.upgrade knows data should be WebSocketData\n * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * // Type hint - specifies the type of ws.data\n * data: {} as WebSocketData,\n * message(ws, message) {\n * // ws.data is typed as WebSocketData\n * console.log(\"User\", ws.data.id, \"says:\", message);\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface Server<T = unknown> {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: T }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via \\`server.upgrade(request, { data: ... })\\`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server<T>): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Type hint for WebSocket data. The value is not used at runtime.\n * Specifies the type of \\`ws.data\\` for all handlers and \\`server.upgrade()\\`.\n *\n * @example\n * websocket: {\n * data: {} as { userId: string },\n * message(ws, message) {\n * // ws.data.userId is typed as string\n * }\n * }\n */\n data?: T;\n\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * type WsData = { connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * data: {} as WsData,\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-fs globals.\n *\n * Includes: fs namespace, FileSystemHandle, FileSystemFileHandle, FileSystemDirectoryHandle, FileSystemWritableFileStream\n */\nexport const FS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-test-environment globals.\n *\n * Includes: describe, it, test, expect, beforeAll, afterAll, beforeEach, afterEach\n */\nexport const TEST_ENV_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-test-environment\n *\n * These types define the globals injected by setupTestEnvironment() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * describe(\"Math operations\", () => {\n * it(\"should add numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Test Structure\n // ============================================\n\n /**\n * Define a test suite.\n *\n * @param name - The name of the test suite\n * @param fn - Function containing tests and nested suites\n *\n * @example\n * describe(\"Calculator\", () => {\n * it(\"adds numbers\", () => {\n * expect(1 + 1).toBe(2);\n * });\n * });\n */\n function describe(name: string, fn: () => void): void;\n\n namespace describe {\n /**\n * Skip this suite and all its tests.\n */\n function skip(name: string, fn: () => void): void;\n\n /**\n * Only run this suite (and other .only suites).\n */\n function only(name: string, fn: () => void): void;\n\n /**\n * Mark suite as todo (skipped with different status).\n */\n function todo(name: string, fn?: () => void): void;\n }\n\n /**\n * Define a test case.\n *\n * @param name - The name of the test\n * @param fn - The test function (can be async)\n *\n * @example\n * it(\"should work\", () => {\n * expect(true).toBe(true);\n * });\n *\n * it(\"should work async\", async () => {\n * const result = await Promise.resolve(42);\n * expect(result).toBe(42);\n * });\n */\n function it(name: string, fn: () => void | Promise<void>): void;\n\n namespace it {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n /**\n * Alias for it().\n */\n function test(name: string, fn: () => void | Promise<void>): void;\n\n namespace test {\n /**\n * Skip this test.\n */\n function skip(name: string, fn?: () => void | Promise<void>): void;\n\n /**\n * Only run this test (and other .only tests).\n */\n function only(name: string, fn: () => void | Promise<void>): void;\n\n /**\n * Mark test as todo.\n */\n function todo(name: string, fn?: () => void | Promise<void>): void;\n }\n\n // ============================================\n // Lifecycle Hooks\n // ============================================\n\n /**\n * Run once before all tests in the current suite.\n *\n * @param fn - Setup function (can be async)\n */\n function beforeAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run once after all tests in the current suite.\n *\n * @param fn - Teardown function (can be async)\n */\n function afterAll(fn: () => void | Promise<void>): void;\n\n /**\n * Run before each test in the current suite (and nested suites).\n *\n * @param fn - Setup function (can be async)\n */\n function beforeEach(fn: () => void | Promise<void>): void;\n\n /**\n * Run after each test in the current suite (and nested suites).\n *\n * @param fn - Teardown function (can be async)\n */\n function afterEach(fn: () => void | Promise<void>): void;\n\n // ============================================\n // Assertions\n // ============================================\n\n /**\n * Matchers for assertions.\n */\n interface Matchers<T> {\n /**\n * Strict equality (===).\n */\n toBe(expected: T): void;\n\n /**\n * Deep equality.\n */\n toEqual(expected: unknown): void;\n\n /**\n * Deep equality with type checking.\n */\n toStrictEqual(expected: unknown): void;\n\n /**\n * Check if value is truthy.\n */\n toBeTruthy(): void;\n\n /**\n * Check if value is falsy.\n */\n toBeFalsy(): void;\n\n /**\n * Check if value is null.\n */\n toBeNull(): void;\n\n /**\n * Check if value is undefined.\n */\n toBeUndefined(): void;\n\n /**\n * Check if value is defined (not undefined).\n */\n toBeDefined(): void;\n\n /**\n * Check if value is NaN.\n */\n toBeNaN(): void;\n\n /**\n * Check if number is greater than expected.\n */\n toBeGreaterThan(n: number): void;\n\n /**\n * Check if number is greater than or equal to expected.\n */\n toBeGreaterThanOrEqual(n: number): void;\n\n /**\n * Check if number is less than expected.\n */\n toBeLessThan(n: number): void;\n\n /**\n * Check if number is less than or equal to expected.\n */\n toBeLessThanOrEqual(n: number): void;\n\n /**\n * Check if array/string contains item/substring.\n */\n toContain(item: unknown): void;\n\n /**\n * Check length of array/string.\n */\n toHaveLength(length: number): void;\n\n /**\n * Check if object has property (optionally with value).\n */\n toHaveProperty(key: string, value?: unknown): void;\n\n /**\n * Check if function throws.\n */\n toThrow(expected?: string | RegExp | Error): void;\n\n /**\n * Check if string matches pattern.\n */\n toMatch(pattern: string | RegExp): void;\n\n /**\n * Check if object matches subset of properties.\n */\n toMatchObject(object: object): void;\n\n /**\n * Check if value is instance of class.\n */\n toBeInstanceOf(constructor: Function): void;\n\n /**\n * Negate the matcher.\n */\n not: Matchers<T>;\n\n /**\n * Await promise and check resolved value.\n */\n resolves: Matchers<Awaited<T>>;\n\n /**\n * Await promise and check rejection.\n */\n rejects: Matchers<unknown>;\n }\n\n /**\n * Create an expectation for a value.\n *\n * @param actual - The value to test\n * @returns Matchers for the value\n *\n * @example\n * expect(1 + 1).toBe(2);\n * expect({ a: 1 }).toEqual({ a: 1 });\n * expect(() => { throw new Error(); }).toThrow();\n * expect(promise).resolves.toBe(42);\n */\n function expect<T>(actual: T): Matchers<T>;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-console globals.\n *\n * Includes: console.log, warn, error, debug, info, trace, dir, table, time, timeEnd, timeLog, count, countReset, clear, assert, group, groupCollapsed, groupEnd\n */\nexport const CONSOLE_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-console\n *\n * These types define the globals injected by setupConsole() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-encoding globals.\n *\n * Includes: atob, btoa\n */\nexport const ENCODING_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-crypto globals.\n *\n * Includes: crypto.subtle, crypto.getRandomValues, crypto.randomUUID, CryptoKey\n */\nexport const CRYPTO_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-crypto\n *\n * These types define the globals injected by setupCrypto() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Generate random bytes\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n *\n * // Generate UUID\n * const uuid = crypto.randomUUID();\n *\n * // Use SubtleCrypto\n * const key = await crypto.subtle.generateKey(\n * { name: \"AES-GCM\", length: 256 },\n * true,\n * [\"encrypt\", \"decrypt\"]\n * );\n */\n\nexport {};\n\ndeclare global {\n /**\n * CryptoKey represents a cryptographic key.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\n */\n interface CryptoKey {\n /**\n * The type of key: \"public\", \"private\", or \"secret\".\n */\n readonly type: \"public\" | \"private\" | \"secret\";\n\n /**\n * Whether the key can be exported.\n */\n readonly extractable: boolean;\n\n /**\n * The algorithm used by this key.\n */\n readonly algorithm: KeyAlgorithm;\n\n /**\n * The usages allowed for this key.\n */\n readonly usages: ReadonlyArray<KeyUsage>;\n }\n\n /**\n * CryptoKey constructor (keys cannot be constructed directly).\n */\n const CryptoKey: {\n prototype: CryptoKey;\n };\n\n /**\n * SubtleCrypto interface for cryptographic operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\n */\n interface SubtleCrypto {\n /**\n * Generate a digest (hash) of the given data.\n *\n * @param algorithm - Hash algorithm (e.g., \"SHA-256\", \"SHA-384\", \"SHA-512\")\n * @param data - Data to hash\n * @returns Promise resolving to the hash as ArrayBuffer\n */\n digest(\n algorithm: AlgorithmIdentifier,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Generate a new cryptographic key or key pair.\n *\n * @param algorithm - Key generation algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey or CryptoKeyPair\n */\n generateKey(\n algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair>;\n\n /**\n * Sign data using a private key.\n *\n * @param algorithm - Signing algorithm\n * @param key - Private key to sign with\n * @param data - Data to sign\n * @returns Promise resolving to the signature as ArrayBuffer\n */\n sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Verify a signature.\n *\n * @param algorithm - Signing algorithm\n * @param key - Public key to verify with\n * @param signature - Signature to verify\n * @param data - Data that was signed\n * @returns Promise resolving to true if valid, false otherwise\n */\n verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean>;\n\n /**\n * Encrypt data.\n *\n * @param algorithm - Encryption algorithm\n * @param key - Encryption key\n * @param data - Data to encrypt\n * @returns Promise resolving to encrypted data as ArrayBuffer\n */\n encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Decrypt data.\n *\n * @param algorithm - Decryption algorithm\n * @param key - Decryption key\n * @param data - Data to decrypt\n * @returns Promise resolving to decrypted data as ArrayBuffer\n */\n decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Import a key from external data.\n *\n * @param format - Key format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param keyData - Key data\n * @param algorithm - Key algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey\n */\n importKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Export a key.\n *\n * @param format - Export format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param key - Key to export\n * @returns Promise resolving to ArrayBuffer or JsonWebKey\n */\n exportKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey\n ): Promise<ArrayBuffer | JsonWebKey>;\n\n /**\n * Derive bits from a key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param length - Number of bits to derive\n * @returns Promise resolving to derived bits as ArrayBuffer\n */\n deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer>;\n\n /**\n * Derive a new key from a base key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param derivedKeyType - Type of key to derive\n * @param extractable - Whether the derived key can be exported\n * @param keyUsages - Allowed usages for derived key\n * @returns Promise resolving to a CryptoKey\n */\n deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyType: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Wrap a key for secure export.\n *\n * @param format - Key format\n * @param key - Key to wrap\n * @param wrappingKey - Key to wrap with\n * @param wrapAlgorithm - Wrapping algorithm\n * @returns Promise resolving to wrapped key as ArrayBuffer\n */\n wrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer>;\n\n /**\n * Unwrap a wrapped key.\n *\n * @param format - Key format\n * @param wrappedKey - Wrapped key data\n * @param unwrappingKey - Key to unwrap with\n * @param unwrapAlgorithm - Unwrapping algorithm\n * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key\n * @param extractable - Whether the unwrapped key can be exported\n * @param keyUsages - Allowed usages for unwrapped key\n * @returns Promise resolving to a CryptoKey\n */\n unwrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n }\n\n /**\n * Crypto interface providing cryptographic functionality.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n */\n interface Crypto {\n /**\n * SubtleCrypto interface for cryptographic operations.\n */\n readonly subtle: SubtleCrypto;\n\n /**\n * Fill a TypedArray with cryptographically random values.\n *\n * @param array - TypedArray to fill (max 65536 bytes)\n * @returns The same array, filled with random values\n *\n * @example\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n */\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n\n /**\n * Generate a random UUID v4.\n *\n * @returns A random UUID string\n *\n * @example\n * const uuid = crypto.randomUUID();\n * // \"550e8400-e29b-41d4-a716-446655440000\"\n */\n randomUUID(): string;\n }\n\n /**\n * Crypto object providing cryptographic functionality.\n */\n const crypto: Crypto;\n}\n`;\n\n/**\n * Type definitions for @ricsam/quickjs-timers globals.\n *\n * Includes: setTimeout, setInterval, clearTimeout, clearInterval\n */\nexport const TIMERS_TYPES = `/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-timers\n *\n * These types define the globals injected by setupTimers() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * const timeoutId = setTimeout(() => {\n * console.log(\"fired!\");\n * }, 1000);\n *\n * clearTimeout(timeoutId);\n *\n * const intervalId = setInterval(() => {\n * console.log(\"tick\");\n * }, 100);\n *\n * clearInterval(intervalId);\n */\n\nexport {};\n\ndeclare global {\n /**\n * Schedule a callback to execute after a delay.\n *\n * @param callback - The function to call after the delay\n * @param ms - The delay in milliseconds (default: 0)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearTimeout\n *\n * @example\n * const id = setTimeout(() => console.log(\"done\"), 1000);\n * setTimeout((a, b) => console.log(a, b), 100, \"hello\", \"world\");\n */\n function setTimeout(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Schedule a callback to execute repeatedly at a fixed interval.\n *\n * @param callback - The function to call at each interval\n * @param ms - The interval in milliseconds (minimum: 4ms)\n * @param args - Additional arguments to pass to the callback\n * @returns A timer ID that can be passed to clearInterval\n *\n * @example\n * const id = setInterval(() => console.log(\"tick\"), 1000);\n */\n function setInterval(\n callback: (...args: unknown[]) => void,\n ms?: number,\n ...args: unknown[]\n ): number;\n\n /**\n * Cancel a timeout previously scheduled with setTimeout.\n *\n * @param id - The timer ID returned by setTimeout\n *\n * @example\n * const id = setTimeout(() => {}, 1000);\n * clearTimeout(id);\n */\n function clearTimeout(id: number | undefined): void;\n\n /**\n * Cancel an interval previously scheduled with setInterval.\n *\n * @param id - The timer ID returned by setInterval\n *\n * @example\n * const id = setInterval(() => {}, 1000);\n * clearInterval(id);\n */\n function clearInterval(id: number | undefined): void;\n}\n`;\n\n/**\n * Map of package names to their type definitions.\n */\nexport const TYPE_DEFINITIONS = {\n core: CORE_TYPES,\n console: CONSOLE_TYPES,\n crypto: CRYPTO_TYPES,\n encoding: ENCODING_TYPES,\n fetch: FETCH_TYPES,\n fs: FS_TYPES,\n testEnvironment: TEST_ENV_TYPES,\n timers: TIMERS_TYPES,\n} as const;\n\n/**\n * Type for the keys of TYPE_DEFINITIONS.\n */\nexport type TypeDefinitionKey = keyof typeof TYPE_DEFINITIONS;\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": ";;AAkBO,IAAM,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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AA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAqFrB,IAAM,mBAAmB;AAAA,EAC9B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,UAAU;AAAA,EACV,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,iBAAiB;AAAA,EACjB,QAAQ;AACV;",
|
|
8
|
+
"debugId": "371AE13F6A0C858864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -46,6 +46,12 @@ export declare const CONSOLE_TYPES = "/**\n * QuickJS Global Type Definitions fo
|
|
|
46
46
|
* Includes: atob, btoa
|
|
47
47
|
*/
|
|
48
48
|
export declare const ENCODING_TYPES = "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n";
|
|
49
|
+
/**
|
|
50
|
+
* Type definitions for @ricsam/quickjs-crypto globals.
|
|
51
|
+
*
|
|
52
|
+
* Includes: crypto.subtle, crypto.getRandomValues, crypto.randomUUID, CryptoKey
|
|
53
|
+
*/
|
|
54
|
+
export declare const CRYPTO_TYPES = "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-crypto\n *\n * These types define the globals injected by setupCrypto() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Generate random bytes\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n *\n * // Generate UUID\n * const uuid = crypto.randomUUID();\n *\n * // Use SubtleCrypto\n * const key = await crypto.subtle.generateKey(\n * { name: \"AES-GCM\", length: 256 },\n * true,\n * [\"encrypt\", \"decrypt\"]\n * );\n */\n\nexport {};\n\ndeclare global {\n /**\n * CryptoKey represents a cryptographic key.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\n */\n interface CryptoKey {\n /**\n * The type of key: \"public\", \"private\", or \"secret\".\n */\n readonly type: \"public\" | \"private\" | \"secret\";\n\n /**\n * Whether the key can be exported.\n */\n readonly extractable: boolean;\n\n /**\n * The algorithm used by this key.\n */\n readonly algorithm: KeyAlgorithm;\n\n /**\n * The usages allowed for this key.\n */\n readonly usages: ReadonlyArray<KeyUsage>;\n }\n\n /**\n * CryptoKey constructor (keys cannot be constructed directly).\n */\n const CryptoKey: {\n prototype: CryptoKey;\n };\n\n /**\n * SubtleCrypto interface for cryptographic operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\n */\n interface SubtleCrypto {\n /**\n * Generate a digest (hash) of the given data.\n *\n * @param algorithm - Hash algorithm (e.g., \"SHA-256\", \"SHA-384\", \"SHA-512\")\n * @param data - Data to hash\n * @returns Promise resolving to the hash as ArrayBuffer\n */\n digest(\n algorithm: AlgorithmIdentifier,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Generate a new cryptographic key or key pair.\n *\n * @param algorithm - Key generation algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey or CryptoKeyPair\n */\n generateKey(\n algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair>;\n\n /**\n * Sign data using a private key.\n *\n * @param algorithm - Signing algorithm\n * @param key - Private key to sign with\n * @param data - Data to sign\n * @returns Promise resolving to the signature as ArrayBuffer\n */\n sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Verify a signature.\n *\n * @param algorithm - Signing algorithm\n * @param key - Public key to verify with\n * @param signature - Signature to verify\n * @param data - Data that was signed\n * @returns Promise resolving to true if valid, false otherwise\n */\n verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean>;\n\n /**\n * Encrypt data.\n *\n * @param algorithm - Encryption algorithm\n * @param key - Encryption key\n * @param data - Data to encrypt\n * @returns Promise resolving to encrypted data as ArrayBuffer\n */\n encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Decrypt data.\n *\n * @param algorithm - Decryption algorithm\n * @param key - Decryption key\n * @param data - Data to decrypt\n * @returns Promise resolving to decrypted data as ArrayBuffer\n */\n decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Import a key from external data.\n *\n * @param format - Key format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param keyData - Key data\n * @param algorithm - Key algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey\n */\n importKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Export a key.\n *\n * @param format - Export format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param key - Key to export\n * @returns Promise resolving to ArrayBuffer or JsonWebKey\n */\n exportKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey\n ): Promise<ArrayBuffer | JsonWebKey>;\n\n /**\n * Derive bits from a key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param length - Number of bits to derive\n * @returns Promise resolving to derived bits as ArrayBuffer\n */\n deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer>;\n\n /**\n * Derive a new key from a base key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param derivedKeyType - Type of key to derive\n * @param extractable - Whether the derived key can be exported\n * @param keyUsages - Allowed usages for derived key\n * @returns Promise resolving to a CryptoKey\n */\n deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyType: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Wrap a key for secure export.\n *\n * @param format - Key format\n * @param key - Key to wrap\n * @param wrappingKey - Key to wrap with\n * @param wrapAlgorithm - Wrapping algorithm\n * @returns Promise resolving to wrapped key as ArrayBuffer\n */\n wrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer>;\n\n /**\n * Unwrap a wrapped key.\n *\n * @param format - Key format\n * @param wrappedKey - Wrapped key data\n * @param unwrappingKey - Key to unwrap with\n * @param unwrapAlgorithm - Unwrapping algorithm\n * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key\n * @param extractable - Whether the unwrapped key can be exported\n * @param keyUsages - Allowed usages for unwrapped key\n * @returns Promise resolving to a CryptoKey\n */\n unwrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n }\n\n /**\n * Crypto interface providing cryptographic functionality.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n */\n interface Crypto {\n /**\n * SubtleCrypto interface for cryptographic operations.\n */\n readonly subtle: SubtleCrypto;\n\n /**\n * Fill a TypedArray with cryptographically random values.\n *\n * @param array - TypedArray to fill (max 65536 bytes)\n * @returns The same array, filled with random values\n *\n * @example\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n */\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n\n /**\n * Generate a random UUID v4.\n *\n * @returns A random UUID string\n *\n * @example\n * const uuid = crypto.randomUUID();\n * // \"550e8400-e29b-41d4-a716-446655440000\"\n */\n randomUUID(): string;\n }\n\n /**\n * Crypto object providing cryptographic functionality.\n */\n const crypto: Crypto;\n}\n";
|
|
49
55
|
/**
|
|
50
56
|
* Type definitions for @ricsam/quickjs-timers globals.
|
|
51
57
|
*
|
|
@@ -58,6 +64,7 @@ export declare const TIMERS_TYPES = "/**\n * QuickJS Global Type Definitions for
|
|
|
58
64
|
export declare const TYPE_DEFINITIONS: {
|
|
59
65
|
readonly core: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-core\n *\n * These types define the globals injected by setupCore() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // In your tsconfig.quickjs.json\n * {\n * \"compilerOptions\": {\n * \"lib\": [\"ESNext\", \"DOM\"]\n * }\n * }\n *\n * // Then reference this file or use ts-morph for code strings\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Web Streams API\n // ============================================\n\n /**\n * A readable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream\n */\n const ReadableStream: typeof globalThis.ReadableStream;\n\n /**\n * A writable stream of data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStream\n */\n const WritableStream: typeof globalThis.WritableStream;\n\n /**\n * A transform stream that can be used to pipe data through a transformer.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/TransformStream\n */\n const TransformStream: typeof globalThis.TransformStream;\n\n /**\n * Default reader for ReadableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader\n */\n const ReadableStreamDefaultReader: typeof globalThis.ReadableStreamDefaultReader;\n\n /**\n * Default writer for WritableStream\n * @see https://developer.mozilla.org/en-US/docs/Web/API/WritableStreamDefaultWriter\n */\n const WritableStreamDefaultWriter: typeof globalThis.WritableStreamDefaultWriter;\n\n // ============================================\n // Blob and File APIs\n // ============================================\n\n /**\n * A file-like object of immutable, raw data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Blob\n */\n const Blob: typeof globalThis.Blob;\n\n /**\n * A file object representing a file.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/File\n */\n const File: typeof globalThis.File;\n\n // ============================================\n // URL APIs\n // ============================================\n\n /**\n * Interface for URL manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URL\n */\n const URL: typeof globalThis.URL;\n\n /**\n * Utility for working with URL query strings.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams\n */\n const URLSearchParams: typeof globalThis.URLSearchParams;\n\n // ============================================\n // Error Handling\n // ============================================\n\n /**\n * Exception type for DOM operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n */\n const DOMException: typeof globalThis.DOMException;\n}\n";
|
|
60
66
|
readonly console: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-console\n *\n * These types define the globals injected by setupConsole() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Console interface for logging and debugging.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Console\n */\n interface Console {\n /**\n * Log a message to the console.\n * @param data - Values to log\n */\n log(...data: unknown[]): void;\n\n /**\n * Log a warning message.\n * @param data - Values to log\n */\n warn(...data: unknown[]): void;\n\n /**\n * Log an error message.\n * @param data - Values to log\n */\n error(...data: unknown[]): void;\n\n /**\n * Log a debug message.\n * @param data - Values to log\n */\n debug(...data: unknown[]): void;\n\n /**\n * Log an info message.\n * @param data - Values to log\n */\n info(...data: unknown[]): void;\n\n /**\n * Log a stack trace.\n * @param data - Values to log with the trace\n */\n trace(...data: unknown[]): void;\n\n /**\n * Display an object in a formatted way.\n * @param item - Object to display\n * @param options - Display options\n */\n dir(item: unknown, options?: object): void;\n\n /**\n * Display tabular data.\n * @param tabularData - Data to display as a table\n * @param properties - Optional array of property names to include\n */\n table(tabularData: unknown, properties?: string[]): void;\n\n /**\n * Start a timer.\n * @param label - Timer label (default: \"default\")\n */\n time(label?: string): void;\n\n /**\n * End a timer and log the elapsed time.\n * @param label - Timer label (default: \"default\")\n */\n timeEnd(label?: string): void;\n\n /**\n * Log the elapsed time of a timer without ending it.\n * @param label - Timer label (default: \"default\")\n * @param data - Additional values to log\n */\n timeLog(label?: string, ...data: unknown[]): void;\n\n /**\n * Log an error if the assertion is false.\n * @param condition - Condition to test\n * @param data - Values to log if assertion fails\n */\n assert(condition?: boolean, ...data: unknown[]): void;\n\n /**\n * Increment and log a counter.\n * @param label - Counter label (default: \"default\")\n */\n count(label?: string): void;\n\n /**\n * Reset a counter.\n * @param label - Counter label (default: \"default\")\n */\n countReset(label?: string): void;\n\n /**\n * Clear the console.\n */\n clear(): void;\n\n /**\n * Start an inline group.\n * @param data - Group label\n */\n group(...data: unknown[]): void;\n\n /**\n * Start a collapsed inline group.\n * @param data - Group label\n */\n groupCollapsed(...data: unknown[]): void;\n\n /**\n * End the current inline group.\n */\n groupEnd(): void;\n }\n\n /**\n * Console object for logging and debugging.\n */\n const console: Console;\n}\n";
|
|
67
|
+
readonly crypto: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-crypto\n *\n * These types define the globals injected by setupCrypto() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Generate random bytes\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n *\n * // Generate UUID\n * const uuid = crypto.randomUUID();\n *\n * // Use SubtleCrypto\n * const key = await crypto.subtle.generateKey(\n * { name: \"AES-GCM\", length: 256 },\n * true,\n * [\"encrypt\", \"decrypt\"]\n * );\n */\n\nexport {};\n\ndeclare global {\n /**\n * CryptoKey represents a cryptographic key.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/CryptoKey\n */\n interface CryptoKey {\n /**\n * The type of key: \"public\", \"private\", or \"secret\".\n */\n readonly type: \"public\" | \"private\" | \"secret\";\n\n /**\n * Whether the key can be exported.\n */\n readonly extractable: boolean;\n\n /**\n * The algorithm used by this key.\n */\n readonly algorithm: KeyAlgorithm;\n\n /**\n * The usages allowed for this key.\n */\n readonly usages: ReadonlyArray<KeyUsage>;\n }\n\n /**\n * CryptoKey constructor (keys cannot be constructed directly).\n */\n const CryptoKey: {\n prototype: CryptoKey;\n };\n\n /**\n * SubtleCrypto interface for cryptographic operations.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto\n */\n interface SubtleCrypto {\n /**\n * Generate a digest (hash) of the given data.\n *\n * @param algorithm - Hash algorithm (e.g., \"SHA-256\", \"SHA-384\", \"SHA-512\")\n * @param data - Data to hash\n * @returns Promise resolving to the hash as ArrayBuffer\n */\n digest(\n algorithm: AlgorithmIdentifier,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Generate a new cryptographic key or key pair.\n *\n * @param algorithm - Key generation algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey or CryptoKeyPair\n */\n generateKey(\n algorithm: RsaHashedKeyGenParams | EcKeyGenParams | AesKeyGenParams | HmacKeyGenParams,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey | CryptoKeyPair>;\n\n /**\n * Sign data using a private key.\n *\n * @param algorithm - Signing algorithm\n * @param key - Private key to sign with\n * @param data - Data to sign\n * @returns Promise resolving to the signature as ArrayBuffer\n */\n sign(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Verify a signature.\n *\n * @param algorithm - Signing algorithm\n * @param key - Public key to verify with\n * @param signature - Signature to verify\n * @param data - Data that was signed\n * @returns Promise resolving to true if valid, false otherwise\n */\n verify(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n signature: BufferSource,\n data: BufferSource\n ): Promise<boolean>;\n\n /**\n * Encrypt data.\n *\n * @param algorithm - Encryption algorithm\n * @param key - Encryption key\n * @param data - Data to encrypt\n * @returns Promise resolving to encrypted data as ArrayBuffer\n */\n encrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Decrypt data.\n *\n * @param algorithm - Decryption algorithm\n * @param key - Decryption key\n * @param data - Data to decrypt\n * @returns Promise resolving to decrypted data as ArrayBuffer\n */\n decrypt(\n algorithm: AlgorithmIdentifier,\n key: CryptoKey,\n data: BufferSource\n ): Promise<ArrayBuffer>;\n\n /**\n * Import a key from external data.\n *\n * @param format - Key format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param keyData - Key data\n * @param algorithm - Key algorithm\n * @param extractable - Whether the key can be exported\n * @param keyUsages - Allowed key usages\n * @returns Promise resolving to a CryptoKey\n */\n importKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n keyData: BufferSource | JsonWebKey,\n algorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Export a key.\n *\n * @param format - Export format (\"raw\", \"pkcs8\", \"spki\", \"jwk\")\n * @param key - Key to export\n * @returns Promise resolving to ArrayBuffer or JsonWebKey\n */\n exportKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey\n ): Promise<ArrayBuffer | JsonWebKey>;\n\n /**\n * Derive bits from a key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param length - Number of bits to derive\n * @returns Promise resolving to derived bits as ArrayBuffer\n */\n deriveBits(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n length: number\n ): Promise<ArrayBuffer>;\n\n /**\n * Derive a new key from a base key.\n *\n * @param algorithm - Derivation algorithm\n * @param baseKey - Base key for derivation\n * @param derivedKeyType - Type of key to derive\n * @param extractable - Whether the derived key can be exported\n * @param keyUsages - Allowed usages for derived key\n * @returns Promise resolving to a CryptoKey\n */\n deriveKey(\n algorithm: AlgorithmIdentifier,\n baseKey: CryptoKey,\n derivedKeyType: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n\n /**\n * Wrap a key for secure export.\n *\n * @param format - Key format\n * @param key - Key to wrap\n * @param wrappingKey - Key to wrap with\n * @param wrapAlgorithm - Wrapping algorithm\n * @returns Promise resolving to wrapped key as ArrayBuffer\n */\n wrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n key: CryptoKey,\n wrappingKey: CryptoKey,\n wrapAlgorithm: AlgorithmIdentifier\n ): Promise<ArrayBuffer>;\n\n /**\n * Unwrap a wrapped key.\n *\n * @param format - Key format\n * @param wrappedKey - Wrapped key data\n * @param unwrappingKey - Key to unwrap with\n * @param unwrapAlgorithm - Unwrapping algorithm\n * @param unwrappedKeyAlgorithm - Algorithm for the unwrapped key\n * @param extractable - Whether the unwrapped key can be exported\n * @param keyUsages - Allowed usages for unwrapped key\n * @returns Promise resolving to a CryptoKey\n */\n unwrapKey(\n format: \"raw\" | \"pkcs8\" | \"spki\" | \"jwk\",\n wrappedKey: BufferSource,\n unwrappingKey: CryptoKey,\n unwrapAlgorithm: AlgorithmIdentifier,\n unwrappedKeyAlgorithm: AlgorithmIdentifier,\n extractable: boolean,\n keyUsages: KeyUsage[]\n ): Promise<CryptoKey>;\n }\n\n /**\n * Crypto interface providing cryptographic functionality.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Crypto\n */\n interface Crypto {\n /**\n * SubtleCrypto interface for cryptographic operations.\n */\n readonly subtle: SubtleCrypto;\n\n /**\n * Fill a TypedArray with cryptographically random values.\n *\n * @param array - TypedArray to fill (max 65536 bytes)\n * @returns The same array, filled with random values\n *\n * @example\n * const arr = new Uint8Array(16);\n * crypto.getRandomValues(arr);\n */\n getRandomValues<T extends ArrayBufferView | null>(array: T): T;\n\n /**\n * Generate a random UUID v4.\n *\n * @returns A random UUID string\n *\n * @example\n * const uuid = crypto.randomUUID();\n * // \"550e8400-e29b-41d4-a716-446655440000\"\n */\n randomUUID(): string;\n }\n\n /**\n * Crypto object providing cryptographic functionality.\n */\n const crypto: Crypto;\n}\n";
|
|
61
68
|
readonly encoding: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-encoding\n *\n * These types define the globals injected by setupEncoding() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n */\n\nexport {};\n\ndeclare global {\n /**\n * Decodes a Base64-encoded string.\n *\n * @param encodedData - The Base64 string to decode\n * @returns The decoded string\n * @throws DOMException if the input is not valid Base64\n *\n * @example\n * atob(\"SGVsbG8=\"); // \"Hello\"\n */\n function atob(encodedData: string): string;\n\n /**\n * Encodes a string to Base64.\n *\n * @param stringToEncode - The string to encode (must contain only Latin1 characters)\n * @returns The Base64 encoded string\n * @throws DOMException if the string contains characters outside Latin1 range (0-255)\n *\n * @example\n * btoa(\"Hello\"); // \"SGVsbG8=\"\n */\n function btoa(stringToEncode: string): string;\n}\n";
|
|
62
69
|
readonly fetch: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fetch\n *\n * These types define the globals injected by setupFetch() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with serve()\n * type WebSocketData = { id: number; connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * if (request.url.includes(\"/ws\")) {\n * // server.upgrade knows data should be WebSocketData\n * server.upgrade(request, { data: { id: 123, connectedAt: Date.now() } });\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Hello!\");\n * },\n * websocket: {\n * // Type hint - specifies the type of ws.data\n * data: {} as WebSocketData,\n * message(ws, message) {\n * // ws.data is typed as WebSocketData\n * console.log(\"User\", ws.data.id, \"says:\", message);\n * ws.send(\"Echo: \" + message);\n * }\n * }\n * });\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // Standard Fetch API (from lib.dom)\n // ============================================\n\n /**\n * Headers class for HTTP headers manipulation.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers\n */\n const Headers: typeof globalThis.Headers;\n\n /**\n * Request class for HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Request\n */\n const Request: typeof globalThis.Request;\n\n /**\n * Response class for HTTP responses.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Response\n */\n const Response: typeof globalThis.Response;\n\n /**\n * AbortController for cancelling fetch requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortController\n */\n const AbortController: typeof globalThis.AbortController;\n\n /**\n * AbortSignal for listening to abort events.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal\n */\n const AbortSignal: typeof globalThis.AbortSignal;\n\n /**\n * FormData for constructing form data.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/FormData\n */\n const FormData: typeof globalThis.FormData;\n\n /**\n * Fetch function for making HTTP requests.\n * @see https://developer.mozilla.org/en-US/docs/Web/API/fetch\n */\n function fetch(\n input: RequestInfo | URL,\n init?: RequestInit\n ): Promise<Response>;\n\n // ============================================\n // QuickJS-specific: serve() API\n // ============================================\n\n /**\n * Server interface for handling WebSocket upgrades within serve() handlers.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface Server<T = unknown> {\n /**\n * Upgrade an HTTP request to a WebSocket connection.\n *\n * @param request - The incoming HTTP request to upgrade\n * @param options - Optional data to associate with the WebSocket connection\n * @returns true if upgrade will proceed, false otherwise\n *\n * @example\n * serve({\n * fetch(request, server) {\n * if (server.upgrade(request, { data: { userId: 123 } })) {\n * return new Response(null, { status: 101 });\n * }\n * return new Response(\"Upgrade failed\", { status: 400 });\n * }\n * });\n */\n upgrade(request: Request, options?: { data?: T }): boolean;\n }\n\n /**\n * ServerWebSocket interface for WebSocket connections within serve() handlers.\n *\n * @typeParam T - The type of data associated with this WebSocket connection\n */\n interface ServerWebSocket<T = unknown> {\n /**\n * User data associated with this connection.\n * Set via `server.upgrade(request, { data: ... })`.\n */\n readonly data: T;\n\n /**\n * Send a message to the client.\n *\n * @param message - The message to send (string, ArrayBuffer, or Uint8Array)\n */\n send(message: string | ArrayBuffer | Uint8Array): void;\n\n /**\n * Close the WebSocket connection.\n *\n * @param code - Optional close code (default: 1000)\n * @param reason - Optional close reason\n */\n close(code?: number, reason?: string): void;\n\n /**\n * WebSocket ready state.\n * - 0: CONNECTING\n * - 1: OPEN\n * - 2: CLOSING\n * - 3: CLOSED\n */\n readonly readyState: number;\n }\n\n /**\n * Options for the serve() function.\n *\n * @typeParam T - The type of data associated with WebSocket connections\n */\n interface ServeOptions<T = unknown> {\n /**\n * Handler for HTTP requests.\n *\n * @param request - The incoming HTTP request\n * @param server - Server interface for WebSocket upgrades\n * @returns Response or Promise resolving to Response\n */\n fetch(request: Request, server: Server<T>): Response | Promise<Response>;\n\n /**\n * WebSocket event handlers.\n */\n websocket?: {\n /**\n * Type hint for WebSocket data. The value is not used at runtime.\n * Specifies the type of `ws.data` for all handlers and `server.upgrade()`.\n *\n * @example\n * websocket: {\n * data: {} as { userId: string },\n * message(ws, message) {\n * // ws.data.userId is typed as string\n * }\n * }\n */\n data?: T;\n\n /**\n * Called when a WebSocket connection is opened.\n *\n * @param ws - The WebSocket connection\n */\n open?(ws: ServerWebSocket<T>): void | Promise<void>;\n\n /**\n * Called when a message is received.\n *\n * @param ws - The WebSocket connection\n * @param message - The received message (string or ArrayBuffer)\n */\n message?(\n ws: ServerWebSocket<T>,\n message: string | ArrayBuffer\n ): void | Promise<void>;\n\n /**\n * Called when the connection is closed.\n *\n * @param ws - The WebSocket connection\n * @param code - The close code\n * @param reason - The close reason\n */\n close?(\n ws: ServerWebSocket<T>,\n code: number,\n reason: string\n ): void | Promise<void>;\n\n /**\n * Called when an error occurs.\n *\n * @param ws - The WebSocket connection\n * @param error - The error that occurred\n */\n error?(ws: ServerWebSocket<T>, error: Error): void | Promise<void>;\n };\n }\n\n /**\n * Register an HTTP server handler in QuickJS.\n *\n * Only one serve() handler can be active at a time.\n * Calling serve() again replaces the previous handler.\n *\n * @param options - Server configuration including fetch handler and optional WebSocket handlers\n *\n * @example\n * type WsData = { connectedAt: number };\n *\n * serve({\n * fetch(request, server) {\n * const url = new URL(request.url);\n *\n * if (url.pathname === \"/ws\") {\n * if (server.upgrade(request, { data: { connectedAt: Date.now() } })) {\n * return new Response(null, { status: 101 });\n * }\n * }\n *\n * if (url.pathname === \"/api/hello\") {\n * return Response.json({ message: \"Hello!\" });\n * }\n *\n * return new Response(\"Not Found\", { status: 404 });\n * },\n * websocket: {\n * data: {} as WsData,\n * open(ws) {\n * console.log(\"Connected at:\", ws.data.connectedAt);\n * },\n * message(ws, message) {\n * ws.send(\"Echo: \" + message);\n * },\n * close(ws, code, reason) {\n * console.log(\"Closed:\", code, reason);\n * }\n * }\n * });\n */\n function serve<T = unknown>(options: ServeOptions<T>): void;\n}\n";
|
|
63
70
|
readonly fs: "/**\n * QuickJS Global Type Definitions for @ricsam/quickjs-fs\n *\n * These types define the globals injected by setupFs() into a QuickJS context.\n * Use these types to typecheck user code that will run inside QuickJS.\n *\n * @example\n * // Typecheck QuickJS code with file system access\n * const root = await fs.getDirectory(\"/data\");\n * const fileHandle = await root.getFileHandle(\"config.json\");\n * const file = await fileHandle.getFile();\n * const content = await file.text();\n */\n\nexport {};\n\ndeclare global {\n // ============================================\n // fs namespace - QuickJS-specific entry point\n // ============================================\n\n /**\n * File System namespace providing access to the file system.\n * This is the QuickJS-specific entry point (differs from browser's navigator.storage.getDirectory()).\n */\n namespace fs {\n /**\n * Get a directory handle for the given path.\n *\n * The host controls which paths are accessible. Invalid or unauthorized\n * paths will throw an error.\n *\n * @param path - The path to request from the host\n * @returns A promise resolving to a directory handle\n * @throws If the path is not allowed or doesn't exist\n *\n * @example\n * const root = await fs.getDirectory(\"/\");\n * const dataDir = await fs.getDirectory(\"/data\");\n */\n function getDirectory(path: string): Promise<FileSystemDirectoryHandle>;\n }\n\n // ============================================\n // File System Access API\n // ============================================\n\n /**\n * Base interface for file system handles.\n */\n interface FileSystemHandle {\n /**\n * The kind of handle: \"file\" or \"directory\".\n */\n readonly kind: \"file\" | \"directory\";\n\n /**\n * The name of the file or directory.\n */\n readonly name: string;\n\n /**\n * Compare two handles to check if they reference the same entry.\n *\n * @param other - Another FileSystemHandle to compare against\n * @returns true if both handles reference the same entry\n */\n isSameEntry(other: FileSystemHandle): Promise<boolean>;\n }\n\n /**\n * Handle for a file in the file system.\n */\n interface FileSystemFileHandle extends FileSystemHandle {\n /**\n * Always \"file\" for file handles.\n */\n readonly kind: \"file\";\n\n /**\n * Get the file contents as a File object.\n *\n * @returns A promise resolving to a File object\n *\n * @example\n * const file = await fileHandle.getFile();\n * const text = await file.text();\n */\n getFile(): Promise<File>;\n\n /**\n * Create a writable stream for writing to the file.\n *\n * @param options - Options for the writable stream\n * @returns A promise resolving to a writable stream\n *\n * @example\n * const writable = await fileHandle.createWritable();\n * await writable.write(\"Hello, World!\");\n * await writable.close();\n */\n createWritable(options?: {\n /**\n * If true, keeps existing file data. Otherwise, truncates the file.\n */\n keepExistingData?: boolean;\n }): Promise<FileSystemWritableFileStream>;\n }\n\n /**\n * Handle for a directory in the file system.\n */\n interface FileSystemDirectoryHandle extends FileSystemHandle {\n /**\n * Always \"directory\" for directory handles.\n */\n readonly kind: \"directory\";\n\n /**\n * Get a file handle within this directory.\n *\n * @param name - The name of the file\n * @param options - Options for getting the file handle\n * @returns A promise resolving to a file handle\n * @throws If the file doesn't exist and create is not true\n *\n * @example\n * const file = await dir.getFileHandle(\"data.json\");\n * const newFile = await dir.getFileHandle(\"output.txt\", { create: true });\n */\n getFileHandle(\n name: string,\n options?: {\n /**\n * If true, creates the file if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemFileHandle>;\n\n /**\n * Get a subdirectory handle within this directory.\n *\n * @param name - The name of the subdirectory\n * @param options - Options for getting the directory handle\n * @returns A promise resolving to a directory handle\n * @throws If the directory doesn't exist and create is not true\n *\n * @example\n * const subdir = await dir.getDirectoryHandle(\"logs\");\n * const newDir = await dir.getDirectoryHandle(\"cache\", { create: true });\n */\n getDirectoryHandle(\n name: string,\n options?: {\n /**\n * If true, creates the directory if it doesn't exist.\n */\n create?: boolean;\n }\n ): Promise<FileSystemDirectoryHandle>;\n\n /**\n * Remove a file or directory within this directory.\n *\n * @param name - The name of the entry to remove\n * @param options - Options for removal\n * @throws If the entry doesn't exist or cannot be removed\n *\n * @example\n * await dir.removeEntry(\"old-file.txt\");\n * await dir.removeEntry(\"old-dir\", { recursive: true });\n */\n removeEntry(\n name: string,\n options?: {\n /**\n * If true, removes directories recursively.\n */\n recursive?: boolean;\n }\n ): Promise<void>;\n\n /**\n * Resolve the path from this directory to a descendant handle.\n *\n * @param possibleDescendant - A handle that may be a descendant\n * @returns An array of path segments, or null if not a descendant\n *\n * @example\n * const path = await root.resolve(nestedFile);\n * // [\"subdir\", \"file.txt\"]\n */\n resolve(possibleDescendant: FileSystemHandle): Promise<string[] | null>;\n\n /**\n * Iterate over entries in this directory.\n *\n * @returns An async iterator of [name, handle] pairs\n *\n * @example\n * for await (const [name, handle] of dir.entries()) {\n * console.log(name, handle.kind);\n * }\n */\n entries(): AsyncIterableIterator<[string, FileSystemHandle]>;\n\n /**\n * Iterate over entry names in this directory.\n *\n * @returns An async iterator of names\n *\n * @example\n * for await (const name of dir.keys()) {\n * console.log(name);\n * }\n */\n keys(): AsyncIterableIterator<string>;\n\n /**\n * Iterate over handles in this directory.\n *\n * @returns An async iterator of handles\n *\n * @example\n * for await (const handle of dir.values()) {\n * console.log(handle.name, handle.kind);\n * }\n */\n values(): AsyncIterableIterator<FileSystemHandle>;\n\n /**\n * Async iterator support for directory entries.\n *\n * @example\n * for await (const [name, handle] of dir) {\n * console.log(name, handle.kind);\n * }\n */\n [Symbol.asyncIterator](): AsyncIterableIterator<[string, FileSystemHandle]>;\n }\n\n /**\n * Parameters for write operations on FileSystemWritableFileStream.\n */\n interface WriteParams {\n /**\n * The type of write operation.\n * - \"write\": Write data at the current position or specified position\n * - \"seek\": Move the file position\n * - \"truncate\": Truncate the file to a specific size\n */\n type: \"write\" | \"seek\" | \"truncate\";\n\n /**\n * The data to write (for \"write\" type).\n */\n data?: string | ArrayBuffer | Uint8Array | Blob;\n\n /**\n * The position to write at or seek to.\n */\n position?: number;\n\n /**\n * The size to truncate to (for \"truncate\" type).\n */\n size?: number;\n }\n\n /**\n * Writable stream for writing to a file.\n * Extends WritableStream with file-specific operations.\n */\n interface FileSystemWritableFileStream extends WritableStream<Uint8Array> {\n /**\n * Write data to the file.\n *\n * @param data - The data to write\n * @returns A promise that resolves when the write completes\n *\n * @example\n * await writable.write(\"Hello, World!\");\n * await writable.write(new Uint8Array([1, 2, 3]));\n * await writable.write({ type: \"write\", data: \"text\", position: 0 });\n */\n write(\n data: string | ArrayBuffer | Uint8Array | Blob | WriteParams\n ): Promise<void>;\n\n /**\n * Seek to a position in the file.\n *\n * @param position - The byte position to seek to\n * @returns A promise that resolves when the seek completes\n *\n * @example\n * await writable.seek(0); // Seek to beginning\n * await writable.write(\"Overwrite\");\n */\n seek(position: number): Promise<void>;\n\n /**\n * Truncate the file to a specific size.\n *\n * @param size - The size to truncate to\n * @returns A promise that resolves when the truncation completes\n *\n * @example\n * await writable.truncate(100); // Keep only first 100 bytes\n */\n truncate(size: number): Promise<void>;\n }\n}\n";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ricsam/quickjs-test-utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.17",
|
|
4
4
|
"main": "./dist/cjs/index.cjs",
|
|
5
5
|
"types": "./dist/types/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -20,10 +20,10 @@
|
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"quickjs-emscripten": "^0.31.0",
|
|
23
|
-
"@ricsam/quickjs-core": "^0.2.
|
|
24
|
-
"@ricsam/quickjs-fetch": "^0.2.
|
|
25
|
-
"@ricsam/quickjs-fs": "^0.2.
|
|
26
|
-
"@ricsam/quickjs-runtime": "^0.2.
|
|
23
|
+
"@ricsam/quickjs-core": "^0.2.13",
|
|
24
|
+
"@ricsam/quickjs-fetch": "^0.2.14",
|
|
25
|
+
"@ricsam/quickjs-fs": "^0.2.13",
|
|
26
|
+
"@ricsam/quickjs-runtime": "^0.2.16"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@ricsam/quickjs-fs": {
|