2022-01-20 02:10:16 -05:00
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
2020-04-30 11:23:40 -04:00
/// <reference no-default-lib="true" />
/// <reference lib="deno.ns" />
declare namespace Deno {
2022-03-11 17:07:02 -05:00
export interface BenchDefinition {
fn : ( ) = > void | Promise < void > ;
name : string ;
ignore? : boolean ;
2022-04-20 15:06:39 -04:00
/ * * G r o u p n a m e f o r t h e b e n c h m a r k .
* Grouped benchmarks produce a time summary * /
group? : string ;
/ * * B e n c h m a r k s h o u l d b e u s e d a s t h e b a s e l i n e f o r o t h e r b e n c h m a r k s
* If there are multiple baselines in a group , the first one is used as the baseline * /
baseline? : boolean ;
2022-03-11 17:07:02 -05:00
/ * * I f a t l e a s t o n e b e n c h h a s ` o n l y ` s e t t o t r u e , o n l y r u n b e n c h e s t h a t h a v e
* ` only ` set to true and fail the bench suite . * /
only? : boolean ;
/ * * E n s u r e t h e b e n c h c a s e d o e s n o t p r e m a t u r e l y c a u s e t h e p r o c e s s t o e x i t ,
* for example via a call to ` Deno.exit ` . Defaults to true . * /
sanitizeExit? : boolean ;
/ * * S p e c i f i e s t h e p e r m i s s i o n s t h a t s h o u l d b e u s e d t o r u n t h e b e n c h .
* Set this to "inherit" to keep the calling thread ' s permissions .
* Set this to "none" to revoke all permissions .
*
* Defaults to "inherit" .
* /
permissions? : Deno.PermissionOptions ;
}
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required .
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( {
* name : "example test" ,
* fn ( ) : void {
* assertEquals ( "world" , "world" ) ;
* } ,
* } ) ;
*
* Deno . bench ( {
* name : "example ignored test" ,
* ignore : Deno.build.os === "windows" ,
* fn ( ) : void {
* // This test is ignored only on Windows machines
* } ,
* } ) ;
*
* Deno . bench ( {
* name : "example async test" ,
* async fn() {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* }
* } ) ;
* ` ` `
* /
export function bench ( t : BenchDefinition ) : void ;
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required .
*
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( "My test description" , ( ) : void = > {
* assertEquals ( "hello" , "hello" ) ;
* } ) ;
*
* Deno . bench ( "My async test description" , async ( ) : Promise < void > = > {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* } ) ;
* ` ` `
* /
export function bench (
name : string ,
fn : ( ) = > void | Promise < void > ,
) : void ;
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required . Declared function must have a name .
*
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( function myTestName ( ) : void {
* assertEquals ( "hello" , "hello" ) ;
* } ) ;
*
* Deno . bench ( async function myOtherTestName ( ) : Promise < void > {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* } ) ;
* ` ` `
* /
export function bench ( fn : ( ) = > void | Promise < void > ) : void ;
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required .
*
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( "My test description" , { permissions : { read : true } } , ( ) : void = > {
* assertEquals ( "hello" , "hello" ) ;
* } ) ;
*
* Deno . bench ( "My async test description" , { permissions : { read : false } } , async ( ) : Promise < void > = > {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* } ) ;
* ` ` `
* /
export function bench (
name : string ,
options : Omit < BenchDefinition , " fn " | " name " > ,
fn : ( ) = > void | Promise < void > ,
) : void ;
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required .
*
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( { name : "My test description" , permissions : { read : true } } , ( ) : void = > {
* assertEquals ( "hello" , "hello" ) ;
* } ) ;
*
* Deno . bench ( { name : "My async test description" , permissions : { read : false } } , async ( ) : Promise < void > = > {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* } ) ;
* ` ` `
* /
export function bench (
options : Omit < BenchDefinition , " fn " > ,
fn : ( ) = > void | Promise < void > ,
) : void ;
/ * * R e g i s t e r a b e n c h w h i c h w i l l b e r u n w h e n ` d e n o b e n c h ` i s u s e d o n t h e c o m m a n d
* line and the containing module looks like a bench module .
* ` fn ` can be async if required . Declared function must have a name .
*
* ` ` ` ts
* import { assert , fail , assertEquals } from "https://deno.land/std/testing/asserts.ts" ;
*
* Deno . bench ( { permissions : { read : true } } , function myTestName ( ) : void {
* assertEquals ( "hello" , "hello" ) ;
* } ) ;
*
* Deno . bench ( { permissions : { read : false } } , async function myOtherTestName ( ) : Promise < void > {
* const decoder = new TextDecoder ( "utf-8" ) ;
* const data = await Deno . readFile ( "hello_world.txt" ) ;
* assertEquals ( decoder . decode ( data ) , "Hello world" ) ;
* } ) ;
* ` ` `
* /
export function bench (
options : Omit < BenchDefinition , " fn " | " name " > ,
fn : ( ) = > void | Promise < void > ,
) : void ;
2020-04-30 11:23:40 -04:00
/ * *
* * * UNSTABLE * * : New API , yet to be vetted . This API is under consideration to
* determine if permissions are required to call it .
*
* Retrieve the process umask . If ` mask ` is provided , sets the process umask .
* This call always returns what the umask was before the call .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* console . log ( Deno . umask ( ) ) ; // e.g. 18 (0o022)
* const prevUmaskValue = Deno . umask ( 0 o077 ) ; // e.g. 18 (0o022)
* console . log ( Deno . umask ( ) ) ; // e.g. 63 (0o077)
* ` ` `
2020-04-30 11:23:40 -04:00
*
* NOTE : This API is not implemented on Windows
* /
export function umask ( mask? : number ) : number ;
2020-07-10 10:07:12 -04:00
/ * * * * U N S T A B L E * * : N e w A P I , y e t t o b e v e t t e d .
*
* Gets the size of the console as columns / rows .
*
* ` ` ` ts
2020-08-10 23:22:10 -04:00
* const { columns , rows } = Deno . consoleSize ( Deno . stdout . rid ) ;
2020-07-10 10:07:12 -04:00
* ` ` `
* /
export function consoleSize (
2020-07-14 15:24:17 -04:00
rid : number ,
2020-07-10 10:07:12 -04:00
) : {
columns : number ;
rows : number ;
} ;
2020-06-03 13:46:09 -04:00
/ * * * * U n s t a b l e * * T h e r e a r e q u e s t i o n s a r o u n d w h i c h p e r m i s s i o n t h i s n e e d s . A n d
* maybe should be renamed ( loadAverage ? )
*
* Returns an array containing the 1 , 5 , and 15 minute load averages . The
2020-04-30 11:23:40 -04:00
* load average is a measure of CPU and IO utilization of the last one , five ,
* and 15 minute periods expressed as a fractional number . Zero means there
* is no load . On Windows , the three values are always the same and represent
* the current load , not the 1 , 5 and 15 minute load averages .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* console . log ( Deno . loadavg ( ) ) ; // e.g. [ 0.71, 0.44, 0.44 ]
* ` ` `
2020-04-30 11:23:40 -04:00
*
* Requires ` allow-env ` permission .
* /
export function loadavg ( ) : number [ ] ;
2020-06-03 13:46:09 -04:00
/ * * * * U n s t a b l e * * n e w A P I . y e t t o b e v e t t e d . U n d e r c o n s i d e r a t i o n t o p o s s i b l y m o v e t o
* Deno . build or Deno . versions and if it should depend sys - info , which may not
* be desireable .
*
* Returns the release version of the Operating System .
2020-04-30 11:23:40 -04:00
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* console . log ( Deno . osRelease ( ) ) ;
* ` ` `
2020-04-30 11:23:40 -04:00
*
* Requires ` allow-env ` permission .
* /
export function osRelease ( ) : string ;
2020-09-19 17:30:59 -04:00
/ * * * * U n s t a b l e * * n e w A P I . y e t t o b e v e t t e d .
2020-09-10 04:38:17 -04:00
*
* Displays the total amount of free and used physical and swap memory in the
* system , as well as the buffers and caches used by the kernel .
2020-09-19 17:30:59 -04:00
*
2020-09-10 04:38:17 -04:00
* This is similar to the ` free ` command in Linux
*
* ` ` ` ts
* console . log ( Deno . systemMemoryInfo ( ) ) ;
* ` ` `
*
* Requires ` allow-env ` permission .
* /
export function systemMemoryInfo ( ) : SystemMemoryInfo ;
export interface SystemMemoryInfo {
/** Total installed memory */
total : number ;
/** Unused memory */
free : number ;
/ * * E s t i m a t i o n o f h o w m u c h m e m o r y i s a v a i l a b l e f o r s t a r t i n g n e w
* applications , without swapping . Unlike the data provided by the cache or
* free fields , this field takes into account page cache and also that not
* all reclaimable memory slabs will be reclaimed due to items being in use
* /
available : number ;
/** Memory used by kernel buffers */
buffers : number ;
/** Memory used by the page cache and slabs */
cached : number ;
/** Total swap memory */
swapTotal : number ;
/** Unused swap memory */
swapFree : number ;
}
2022-01-24 04:39:28 -05:00
/** The information of the network interface */
export interface NetworkInterfaceInfo {
/** The network interface name */
name : string ;
/** The IP protocol version */
family : "IPv4" | "IPv6" ;
/** The IP address */
address : string ;
/** The netmask */
netmask : string ;
/** The IPv6 scope id or null */
scopeid : number | null ;
/** The CIDR range */
cidr : string ;
/** The MAC address */
mac : string ;
}
/ * * * * U n s t a b l e * * n e w A P I . y e t t o b e v e t t e d .
*
* Returns an array of the network interface informations .
*
* ` ` ` ts
* console . log ( Deno . networkInterfaces ( ) ) ;
* ` ` `
*
* Requires ` allow-env ` permission .
* /
export function networkInterfaces ( ) : NetworkInterfaceInfo [ ] ;
2022-01-31 00:44:19 -05:00
/ * * * * U n s t a b l e * * n e w A P I . y e t t o b e v e t t e d .
*
* Returns the user id of the process on POSIX platforms . Returns null on windows .
*
* ` ` ` ts
* console . log ( Deno . getUid ( ) ) ;
* ` ` `
*
* Requires ` allow-env ` permission .
* /
export function getUid ( ) : number | null ;
2022-05-31 04:42:44 -04:00
/ * * * * U n s t a b l e * * n e w A P I . y e t t o b e v e t t e d .
*
* Returns the group id of the process on POSIX platforms . Returns null on windows .
*
* ` ` ` ts
* console . log ( Deno . getGid ( ) ) ;
* ` ` `
*
* Requires ` allow-env ` permission .
* /
export function getGid ( ) : number | null ;
2022-01-24 04:39:28 -05:00
2022-06-20 22:50:33 -04:00
/** All plain number types for interfacing with foreign functions */
type NativeNumberType =
2021-08-06 17:28:10 -04:00
| "u8"
| "i8"
| "u16"
| "i16"
| "u32"
| "i32"
2022-06-20 22:50:33 -04:00
| "f32"
| "f64" ;
/** All BigInt number type sfor interfacing with foreign functions */
type NativeBigIntType =
2021-08-06 17:28:10 -04:00
| "u64"
| "i64"
| "usize"
2022-06-20 22:50:33 -04:00
| "isize" ;
type NativePointerType = "pointer" ;
2021-08-06 17:28:10 -04:00
2022-06-20 22:50:33 -04:00
type NativeFunctionType = "function" ;
type NativeVoidType = "void" ;
/** All possible types for interfacing with foreign functions */
export type NativeType =
| NativeNumberType
| NativeBigIntType
| NativePointerType
| NativeFunctionType ;
export type NativeResultType = NativeType | NativeVoidType ;
/** Type conversion for foreign symbol parameters and unsafe callback return types */
type ToNativeType < T extends NativeType = NativeType > = T extends
NativeNumberType ? number
: T extends NativeBigIntType ? bigint | number
: T extends NativePointerType ? TypedArray | bigint | null
: T extends NativeFunctionType ? bigint | null
: never ;
/** Type conversion for unsafe callback return types */
type ToNativeResultType < T extends NativeResultType = NativeResultType > =
T extends NativeType ? ToNativeType < T >
: T extends NativeVoidType ? void
: never ;
type ToNativeParameterTypes < T extends readonly NativeType [ ] > = T extends
readonly [ ] ? [ ]
: T extends readonly [
infer U extends NativeType ,
. . . ( infer V extends NativeType [ ] ) ,
] ? [ ToNativeType < U > , . . . ToNativeParameterTypes < V > ]
: never ;
/** Type conversion for foreign symbol return types and unsafe callback parameters */
type FromNativeType < T extends NativeType = NativeType > = T extends
NativeNumberType ? number
: T extends NativeBigIntType | NativePointerType | NativeFunctionType
? bigint
: never ;
/** Type conversion for foregin symbol return types */
type FromNativeResultType < T extends NativeResultType = NativeResultType > =
T extends NativeType ? FromNativeType < T >
: T extends NativeVoidType ? void
: never ;
type FromNativeParameterTypes < T extends readonly NativeType [ ] > = T extends
readonly [ ] ? [ ]
: T extends readonly [
infer U extends NativeType ,
. . . ( infer V extends NativeType [ ] ) ,
] ? [ FromNativeType < U > , . . . FromNativeParameterTypes < V > ]
: never ;
2022-06-20 07:06:04 -04:00
2021-08-06 17:28:10 -04:00
/** A foreign function as defined by its parameter and result types */
2022-01-10 10:33:25 -05:00
export interface ForeignFunction <
2022-06-20 22:50:33 -04:00
Parameters extends readonly NativeType [ ] = readonly NativeType [ ] ,
Result extends NativeResultType = NativeResultType ,
2022-01-10 10:33:25 -05:00
NonBlocking extends boolean = boolean ,
> {
2022-01-11 01:21:16 -05:00
/** Name of the symbol, defaults to the key name in symbols object. */
name? : string ;
2022-01-10 10:33:25 -05:00
parameters : Parameters ;
result : Result ;
2021-10-11 09:09:11 -04:00
/** When true, function calls will run on a dedicated blocking thread and will return a Promise resolving to the `result`. */
2022-01-10 10:33:25 -05:00
nonblocking? : NonBlocking ;
2021-08-06 17:28:10 -04:00
}
2022-02-18 07:21:19 -05:00
export interface ForeignStatic < Type extends NativeType = NativeType > {
/** Name of the symbol, defaults to the key name in symbols object. */
name? : string ;
2022-06-20 22:50:33 -04:00
type : Type ;
2022-02-18 07:21:19 -05:00
}
/** A foreign library interface descriptor */
export interface ForeignLibraryInterface {
[ name : string ] : ForeignFunction | ForeignStatic ;
2022-01-10 10:33:25 -05:00
}
2022-02-18 07:21:19 -05:00
/** Infers a foreign symbol */
type StaticForeignSymbol < T extends ForeignFunction | ForeignStatic > =
2022-06-20 22:50:33 -04:00
T extends ForeignFunction ? FromForeignFunction < T >
: T extends ForeignStatic ? FromNativeType < T [ " type " ] >
2022-02-18 07:21:19 -05:00
: never ;
2022-01-10 10:33:25 -05:00
2022-06-20 22:50:33 -04:00
type FromForeignFunction < T extends ForeignFunction > = T [ "parameters" ] extends
readonly [ ] ? ( ) = > StaticForeignSymbolReturnType < T >
: (
. . . args : ToNativeParameterTypes < T [ " parameters " ] >
) = > StaticForeignSymbolReturnType < T > ;
type StaticForeignSymbolReturnType < T extends ForeignFunction > =
ConditionalAsync < T [ " nonblocking " ] , FromNativeResultType < T [ " result " ] > > ;
2022-01-10 10:33:25 -05:00
type ConditionalAsync < IsAsync extends boolean | undefined , T > =
IsAsync extends true ? Promise < T > : T ;
2022-02-18 07:21:19 -05:00
/** Infers a foreign library interface */
type StaticForeignLibraryInterface < T extends ForeignLibraryInterface > = {
[ K in keyof T ] : StaticForeignSymbol < T [ K ] > ;
2022-01-10 10:33:25 -05:00
} ;
2021-12-15 09:41:49 -05:00
type TypedArray =
| Int8Array
| Uint8Array
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array
| BigInt64Array
| BigUint64Array ;
/ * * * * U N S T A B L E * * : U n s a f e a n d n e w A P I , b e w a r e !
*
* An unsafe pointer to a memory location for passing and returning pointers to and from the ffi
* /
export class UnsafePointer {
/ * *
* Return the direct memory pointer to the typed array in memory
* /
2022-06-20 09:38:10 -04:00
static of ( value : Deno.UnsafeCallback | TypedArray ) : bigint ;
2021-12-15 09:41:49 -05:00
}
/ * * * * U N S T A B L E * * : U n s a f e a n d n e w A P I , b e w a r e !
*
* An unsafe pointer view to a memory location as specified by the ` pointer `
* value . The ` UnsafePointerView ` API mimics the standard built in interface
* ` DataView ` for accessing the underlying types at an memory location
* ( numbers , strings and raw bytes ) .
* /
export class UnsafePointerView {
2022-06-20 09:38:10 -04:00
constructor ( pointer : bigint ) ;
2021-12-15 09:41:49 -05:00
2022-06-20 09:38:10 -04:00
pointer : bigint ;
2021-12-15 09:41:49 -05:00
/** Gets an unsigned 8-bit integer at the specified byte offset from the pointer. */
getUint8 ( offset? : number ) : number ;
/** Gets a signed 8-bit integer at the specified byte offset from the pointer. */
getInt8 ( offset? : number ) : number ;
/** Gets an unsigned 16-bit integer at the specified byte offset from the pointer. */
getUint16 ( offset? : number ) : number ;
/** Gets a signed 16-bit integer at the specified byte offset from the pointer. */
getInt16 ( offset? : number ) : number ;
/** Gets an unsigned 32-bit integer at the specified byte offset from the pointer. */
getUint32 ( offset? : number ) : number ;
/** Gets a signed 32-bit integer at the specified byte offset from the pointer. */
getInt32 ( offset? : number ) : number ;
/** Gets an unsigned 64-bit integer at the specified byte offset from the pointer. */
getBigUint64 ( offset? : number ) : bigint ;
/** Gets a signed 64-bit integer at the specified byte offset from the pointer. */
getBigInt64 ( offset? : number ) : bigint ;
/** Gets a signed 32-bit float at the specified byte offset from the pointer. */
getFloat32 ( offset? : number ) : number ;
/** Gets a signed 64-bit float at the specified byte offset from the pointer. */
getFloat64 ( offset? : number ) : number ;
/** Gets a C string (null terminated string) at the specified byte offset from the pointer. */
getCString ( offset? : number ) : string ;
/** Gets an ArrayBuffer of length `byteLength` at the specified byte offset from the pointer. */
getArrayBuffer ( byteLength : number , offset? : number ) : ArrayBuffer ;
/** Copies the memory of the pointer into a typed array. Length is determined from the typed array's `byteLength`. Also takes optional offset from the pointer. */
copyInto ( destination : TypedArray , offset? : number ) : void ;
}
2022-01-12 06:38:26 -05:00
/ * *
* * * UNSTABLE * * : Unsafe and new API , beware !
*
* An unsafe pointer to a function , for calling functions that are not
* present as symbols .
* /
export class UnsafeFnPointer < Fn extends ForeignFunction > {
2022-06-20 09:38:10 -04:00
pointer : bigint ;
2022-01-12 06:38:26 -05:00
definition : Fn ;
2022-06-20 09:38:10 -04:00
constructor ( pointer : bigint , definition : Fn ) ;
2022-01-12 06:38:26 -05:00
2022-06-20 22:50:33 -04:00
call : FromForeignFunction < Fn > ;
2022-01-12 06:38:26 -05:00
}
2022-06-20 07:06:04 -04:00
export interface UnsafeCallbackDefinition <
Parameters extends readonly NativeType [ ] = readonly NativeType [ ] ,
2022-06-20 22:50:33 -04:00
Result extends NativeResultType = NativeResultType ,
2022-06-20 07:06:04 -04:00
> {
parameters : Parameters ;
result : Result ;
}
type UnsafeCallbackFunction <
Parameters extends readonly NativeType [ ] = readonly NativeType [ ] ,
2022-06-20 22:50:33 -04:00
Result extends NativeResultType = NativeResultType ,
> = Parameters extends readonly [ ] ? ( ) = > ToNativeResultType < Result > : (
. . . args : FromNativeParameterTypes < Parameters >
) = > ToNativeResultType < Result > ;
2022-06-20 07:06:04 -04:00
/ * *
* * * UNSTABLE * * : Unsafe and new API , beware !
*
* An unsafe function pointer for passing JavaScript functions
* as C function pointers to ffi calls .
*
* The function pointer remains valid until the ` close() ` method is called .
* /
export class UnsafeCallback <
2022-06-20 22:50:33 -04:00
Definition extends UnsafeCallbackDefinition = UnsafeCallbackDefinition ,
2022-06-20 07:06:04 -04:00
> {
constructor (
2022-06-20 22:50:33 -04:00
definition : Definition ,
callback : UnsafeCallbackFunction <
Definition [ "parameters" ] ,
Definition [ "result" ]
> ,
2022-06-20 07:06:04 -04:00
) ;
2022-06-20 09:38:10 -04:00
pointer : bigint ;
2022-06-20 22:50:33 -04:00
definition : Definition ;
callback : UnsafeCallbackFunction <
Definition [ "parameters" ] ,
Definition [ "result" ]
> ;
2022-06-20 07:06:04 -04:00
close ( ) : void ;
}
2021-08-06 17:28:10 -04:00
/** A dynamic library resource */
2022-02-18 07:21:19 -05:00
export interface DynamicLibrary < S extends ForeignLibraryInterface > {
/** All of the registered library along with functions for calling them */
symbols : StaticForeignLibraryInterface < S > ;
2021-08-06 17:28:10 -04:00
close ( ) : void ;
}
2021-12-15 09:41:49 -05:00
/ * * * * U N S T A B L E * * : U n s a f e a n d n e w A P I , b e w a r e !
2021-07-11 21:12:26 -04:00
*
2021-08-06 17:28:10 -04:00
* Opens a dynamic library and registers symbols
2021-07-11 21:12:26 -04:00
* /
2022-02-18 07:21:19 -05:00
export function dlopen < S extends ForeignLibraryInterface > (
2021-08-24 09:09:00 -04:00
filename : string | URL ,
2021-08-06 17:28:10 -04:00
symbols : S ,
) : DynamicLibrary < S > ;
2021-07-11 21:12:26 -04:00
2020-04-30 11:23:40 -04:00
/** The log category for a diagnostic message. */
export enum DiagnosticCategory {
2020-09-12 05:53:57 -04:00
Warning = 0 ,
Error = 1 ,
Suggestion = 2 ,
Message = 3 ,
2020-04-30 11:23:40 -04:00
}
export interface DiagnosticMessageChain {
2021-08-24 11:53:38 -04:00
messageText : string ;
2020-04-30 11:23:40 -04:00
category : DiagnosticCategory ;
code : number ;
next? : DiagnosticMessageChain [ ] ;
}
2020-09-12 05:53:57 -04:00
export interface Diagnostic {
2020-04-30 11:23:40 -04:00
/** A string message summarizing the diagnostic. */
2020-09-12 05:53:57 -04:00
messageText? : string ;
2020-04-30 11:23:40 -04:00
/** An ordered array of further diagnostics. */
messageChain? : DiagnosticMessageChain ;
/ * * I n f o r m a t i o n r e l a t e d t o t h e d i a g n o s t i c . T h i s i s p r e s e n t w h e n t h e r e i s a
* suggestion or other additional diagnostic information * /
2020-09-12 05:53:57 -04:00
relatedInformation? : Diagnostic [ ] ;
2020-04-30 11:23:40 -04:00
/** The text of the source line related to the diagnostic. */
sourceLine? : string ;
2020-09-12 05:53:57 -04:00
source? : string ;
/** The start position of the error. Zero based index. */
start ? : {
line : number ;
character : number ;
} ;
/** The end position of the error. Zero based index. */
end ? : {
line : number ;
character : number ;
} ;
/** The filename of the resource related to the diagnostic message. */
fileName? : string ;
2020-04-30 11:23:40 -04:00
/** The category of the diagnostic. */
category : DiagnosticCategory ;
/** A number identifier. */
code : number ;
}
2020-11-30 11:08:03 -05:00
export type SetRawOptions = {
cbreak : boolean ;
} ;
2020-04-30 11:23:40 -04:00
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d
*
* Set TTY to be under raw mode or not . In raw mode , characters are read and
* returned as is , without being processed . All special processing of
* characters by the terminal is disabled , including echoing input characters .
* Reading from a TTY device in raw mode is faster than reading from a TTY
* device in canonical mode .
*
2020-11-30 11:08:03 -05:00
* The ` cbreak ` option can be used to indicate that characters that correspond
* to a signal should still be generated . When disabling raw mode , this option
* is ignored . This functionality currently only works on Linux and Mac OS .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
2021-05-13 08:20:55 -04:00
* Deno . setRaw ( Deno . stdin . rid , true , { cbreak : true } ) ;
2020-05-16 15:23:48 -04:00
* ` ` `
2020-04-30 11:23:40 -04:00
* /
2020-11-30 11:08:03 -05:00
export function setRaw (
rid : number ,
mode : boolean ,
options? : SetRawOptions ,
) : void ;
2020-04-30 11:23:40 -04:00
/ * * * * U N S T A B L E * * : n e e d s i n v e s t i g a t i o n i n t o h i g h p r e c i s i o n t i m e .
*
* Synchronously changes the access ( ` atime ` ) and modification ( ` mtime ` ) times
* of a file system object referenced by ` path ` . Given times are either in
* seconds ( UNIX epoch time ) or as ` Date ` objects .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* Deno . utimeSync ( "myfile.txt" , 1556495550 , new Date ( ) ) ;
* ` ` `
2020-04-30 11:23:40 -04:00
*
* Requires ` allow-write ` permission . * /
export function utimeSync (
2021-05-31 14:05:57 -04:00
path : string | URL ,
2020-04-30 11:23:40 -04:00
atime : number | Date ,
2020-07-14 15:24:17 -04:00
mtime : number | Date ,
2020-04-30 11:23:40 -04:00
) : void ;
/ * * * * U N S T A B L E * * : n e e d s i n v e s t i g a t i o n i n t o h i g h p r e c i s i o n t i m e .
*
* Changes the access ( ` atime ` ) and modification ( ` mtime ` ) times of a file
* system object referenced by ` path ` . Given times are either in seconds
* ( UNIX epoch time ) or as ` Date ` objects .
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* await Deno . utime ( "myfile.txt" , 1556495550 , new Date ( ) ) ;
* ` ` `
2020-04-30 11:23:40 -04:00
*
* Requires ` allow-write ` permission . * /
export function utime (
2021-05-31 14:05:57 -04:00
path : string | URL ,
2020-04-30 11:23:40 -04:00
atime : number | Date ,
2020-07-14 15:24:17 -04:00
mtime : number | Date ,
2020-04-30 11:23:40 -04:00
) : Promise < void > ;
2021-08-04 15:47:43 -04:00
export function run <
T extends RunOptions & {
clearEnv? : boolean ;
2021-09-13 13:26:23 -04:00
gid? : number ;
uid? : number ;
2021-08-04 15:47:43 -04:00
} = RunOptions & {
clearEnv? : boolean ;
2021-09-13 13:26:23 -04:00
gid? : number ;
uid? : number ;
2021-08-04 15:47:43 -04:00
} ,
> ( opt : T ) : Process < T > ;
2020-06-03 13:46:09 -04:00
/ * * * * U N S T A B L E * * : N e w A P I , y e t t o b e v e t t e d . A d d i t i o n a l c o n s i d e r a t i o n i s s t i l l
* necessary around the permissions required .
*
* Get the ` hostname ` of the machine the Deno process is running on .
2020-05-09 12:44:35 -04:00
*
2020-05-16 15:23:48 -04:00
* ` ` ` ts
* console . log ( Deno . hostname ( ) ) ;
* ` ` `
2020-05-09 12:44:35 -04:00
*
* Requires ` allow-env ` permission .
* /
export function hostname ( ) : string ;
2020-06-10 23:00:29 -04:00
2020-08-05 14:44:03 -04:00
/ * * * * U N S T A B L E * * : N e w A P I , y e t t o b e v e t t e d .
* A custom HttpClient for use with ` fetch ` .
2020-08-10 16:41:51 -04:00
*
2020-08-05 14:44:03 -04:00
* ` ` ` ts
2021-09-30 03:26:15 -04:00
* const caCert = await Deno . readTextFile ( "./ca.pem" ) ;
* const client = Deno . createHttpClient ( { caCerts : [ caCert ] } ) ;
2020-08-05 14:44:03 -04:00
* const req = await fetch ( "https://myserver.com" , { client } ) ;
* ` ` `
* /
export class HttpClient {
rid : number ;
close ( ) : void ;
}
/ * * * * U N S T A B L E * * : N e w A P I , y e t t o b e v e t t e d .
* The options used when creating a [ HttpClient ] .
* /
2021-04-09 20:41:59 -04:00
export interface CreateHttpClientOptions {
2021-09-30 03:26:15 -04:00
/ * * A l i s t o f r o o t c e r t i f i c a t e s t h a t w i l l b e u s e d i n a d d i t i o n t o t h e
* default root certificates to verify the peer ' s certificate .
*
* Must be in PEM format . * /
caCerts? : string [ ] ;
/** A HTTP proxy to use for new connections. */
2021-06-21 23:21:57 -04:00
proxy? : Proxy ;
2021-09-30 03:26:15 -04:00
/** PEM formatted client certificate chain. */
2021-08-25 08:25:12 -04:00
certChain? : string ;
2021-09-30 03:26:15 -04:00
/** PEM formatted (RSA or PKCS8) private key of client certificate. */
2021-08-25 08:25:12 -04:00
privateKey? : string ;
2021-06-21 23:21:57 -04:00
}
export interface Proxy {
url : string ;
basicAuth? : BasicAuth ;
}
export interface BasicAuth {
username : string ;
password : string ;
2020-08-05 14:44:03 -04:00
}
/ * * * * U N S T A B L E * * : N e w A P I , y e t t o b e v e t t e d .
* Create a custom HttpClient for to use with ` fetch ` .
2020-08-10 16:41:51 -04:00
*
2020-08-05 14:44:03 -04:00
* ` ` ` ts
2021-09-30 03:26:15 -04:00
* const caCert = await Deno . readTextFile ( "./ca.pem" ) ;
* const client = Deno . createHttpClient ( { caCerts : [ caCert ] } ) ;
2021-06-21 23:21:57 -04:00
* const response = await fetch ( "https://myserver.com" , { client } ) ;
* ` ` `
*
* ` ` ` ts
* const client = Deno . createHttpClient ( { proxy : { url : "http://myproxy.com:8080" } } ) ;
* const response = await fetch ( "https://myserver.com" , { client } ) ;
2020-08-05 14:44:03 -04:00
* ` ` `
* /
export function createHttpClient (
options : CreateHttpClientOptions ,
) : HttpClient ;
2020-08-31 14:29:43 -04:00
/ * * * * U N S T A B L E * * : n e e d s i n v e s t i g a t i o n i n t o h i g h p r e c i s i o n t i m e .
*
* Synchronously changes the access ( ` atime ` ) and modification ( ` mtime ` ) times
* of a file stream resource referenced by ` rid ` . Given times are either in
* seconds ( UNIX epoch time ) or as ` Date ` objects .
*
* ` ` ` ts
2021-04-01 17:53:31 -04:00
* const file = Deno . openSync ( "file.txt" , { create : true , write : true } ) ;
2020-08-31 14:29:43 -04:00
* Deno . futimeSync ( file . rid , 1556495550 , new Date ( ) ) ;
* ` ` `
* /
export function futimeSync (
rid : number ,
atime : number | Date ,
mtime : number | Date ,
) : void ;
/ * * * * U N S T A B L E * * : n e e d s i n v e s t i g a t i o n i n t o h i g h p r e c i s i o n t i m e .
*
* Changes the access ( ` atime ` ) and modification ( ` mtime ` ) times of a file
* stream resource referenced by ` rid ` . Given times are either in seconds
* ( UNIX epoch time ) or as ` Date ` objects .
*
* ` ` ` ts
2021-04-01 17:53:31 -04:00
* const file = await Deno . open ( "file.txt" , { create : true , write : true } ) ;
2020-08-31 14:29:43 -04:00
* await Deno . futime ( file . rid , 1556495550 , new Date ( ) ) ;
* ` ` `
* /
export function futime (
rid : number ,
atime : number | Date ,
mtime : number | Date ,
) : Promise < void > ;
2020-10-15 21:06:31 -04:00
2021-08-31 05:25:15 -04:00
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* A generic transport listener for message - oriented protocols . * /
export interface DatagramConn extends AsyncIterable < [ Uint8Array , Addr ] > {
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Waits for and resolves to the next message to the ` UDPConn ` . * /
receive ( p? : Uint8Array ) : Promise < [ Uint8Array , Addr ] > ;
/ * * U N S T A B L E : n e w A P I , y e t t o b e v e t t e d .
*
* Sends a message to the target . * /
send ( p : Uint8Array , addr : Addr ) : Promise < number > ;
/ * * U N S T A B L E : n e w A P I , y e t t o b e v e t t e d .
*
* Close closes the socket . Any pending message promises will be rejected
* with errors . * /
close ( ) : void ;
/** Return the address of the `UDPConn`. */
readonly addr : Addr ;
[ Symbol . asyncIterator ] ( ) : AsyncIterableIterator < [ Uint8Array , Addr ] > ;
}
export interface UnixListenOptions {
/** A Path to the Unix Socket. */
path : string ;
}
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Listen announces on the local transport address .
*
* ` ` ` ts
* const listener = Deno . listen ( { path : "/foo/bar.sock" , transport : "unix" } )
* ` ` `
*
* Requires ` allow-read ` and ` allow-write ` permission . * /
export function listen (
options : UnixListenOptions & { transport : "unix" } ,
) : Listener ;
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d
*
* Listen announces on the local transport address .
*
* ` ` ` ts
* const listener1 = Deno . listenDatagram ( {
* port : 80 ,
* transport : "udp"
* } ) ;
* const listener2 = Deno . listenDatagram ( {
* hostname : "golang.org" ,
* port : 80 ,
* transport : "udp"
* } ) ;
* ` ` `
*
* Requires ` allow-net ` permission . * /
export function listenDatagram (
options : ListenOptions & { transport : "udp" } ,
) : DatagramConn ;
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d
*
* Listen announces on the local transport address .
*
* ` ` ` ts
* const listener = Deno . listenDatagram ( {
* path : "/foo/bar.sock" ,
* transport : "unixpacket"
* } ) ;
* ` ` `
*
* Requires ` allow-read ` and ` allow-write ` permission . * /
export function listenDatagram (
options : UnixListenOptions & { transport : "unixpacket" } ,
) : DatagramConn ;
export interface UnixConnectOptions {
transport : "unix" ;
path : string ;
}
/ * * * * U N S T A B L E * * : T h e u n i x s o c k e t t r a n s p o r t i s u n s t a b l e a s a n e w A P I y e t t o
* be vetted . The TCP transport is considered stable .
*
* Connects to the hostname ( default is "127.0.0.1" ) and port on the named
* transport ( default is "tcp" ) , and resolves to the connection ( ` Conn ` ) .
*
* ` ` ` ts
* const conn1 = await Deno . connect ( { port : 80 } ) ;
* const conn2 = await Deno . connect ( { hostname : "192.0.2.1" , port : 80 } ) ;
* const conn3 = await Deno . connect ( { hostname : "[2001:db8::1]" , port : 80 } ) ;
* const conn4 = await Deno . connect ( { hostname : "golang.org" , port : 80 , transport : "tcp" } ) ;
* const conn5 = await Deno . connect ( { path : "/foo/bar.sock" , transport : "unix" } ) ;
* ` ` `
*
* Requires ` allow-net ` permission for "tcp" and ` allow-read ` for "unix" . * /
export function connect (
2022-02-27 09:18:30 -05:00
options : ConnectOptions ,
) : Promise < TcpConn > ;
export function connect (
options : UnixConnectOptions ,
2022-03-04 14:33:13 -05:00
) : Promise < UnixConn > ;
2021-08-31 05:25:15 -04:00
2021-09-30 03:26:15 -04:00
export interface ConnectTlsOptions {
2021-08-31 05:25:15 -04:00
/** PEM formatted client certificate chain. */
2021-09-30 03:26:15 -04:00
certChain? : string ;
2021-08-31 05:25:15 -04:00
/** PEM formatted (RSA or PKCS8) private key of client certificate. */
2021-09-30 03:26:15 -04:00
privateKey? : string ;
2021-11-26 13:59:53 -05:00
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Application - Layer Protocol Negotiation ( ALPN ) protocols supported by
* the client . If not specified , no ALPN extension will be included in the
* TLS handshake .
* /
alpnProtocols? : string [ ] ;
}
export interface TlsHandshakeInfo {
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Contains the ALPN protocol selected during negotiation with the server .
* If no ALPN protocol selected , returns ` null ` .
* /
alpnProtocol : string | null ;
}
export interface TlsConn extends Conn {
/ * * R u n s t h e c l i e n t o r s e r v e r h a n d s h a k e p r o t o c o l t o c o m p l e t i o n i f t h a t h a s
* not happened yet . Calling this method is optional ; the TLS handshake
* will be completed automatically as soon as data is sent or received . * /
handshake ( ) : Promise < TlsHandshakeInfo > ;
2021-08-31 05:25:15 -04:00
}
/ * * * * U N S T A B L E * * N e w A P I , y e t t o b e v e t t e d .
2021-09-02 18:28:12 -04:00
*
* Create a TLS connection with an attached client certificate .
*
* ` ` ` ts
* const conn = await Deno . connectTls ( {
* hostname : "deno.land" ,
* port : 443 ,
* certChain : "---- BEGIN CERTIFICATE ----\n ..." ,
* privateKey : "---- BEGIN PRIVATE KEY ----\n ..." ,
* } ) ;
* ` ` `
*
* Requires ` allow-net ` permission .
* /
2021-10-26 16:27:47 -04:00
export function connectTls ( options : ConnectTlsOptions ) : Promise < TlsConn > ;
2021-08-31 05:25:15 -04:00
export interface ListenTlsOptions {
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Application - Layer Protocol Negotiation ( ALPN ) protocols to announce to
* the client . If not specified , no ALPN extension will be included in the
* TLS handshake .
* /
alpnProtocols? : string [ ] ;
}
2021-09-19 08:46:54 -04:00
2021-11-26 13:59:53 -05:00
export interface StartTlsOptions {
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Application - Layer Protocol Negotiation ( ALPN ) protocols to announce to
* the client . If not specified , no ALPN extension will be included in the
* TLS handshake .
* /
alpnProtocols? : string [ ] ;
}
2022-03-22 23:04:20 -04:00
export interface Listener extends AsyncIterable < Conn > {
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Make the listener block the event loop from finishing .
*
* Note : the listener blocks the event loop from finishing by default .
* This method is only meaningful after ` .unref() ` is called .
* /
ref ( ) : void ;
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Make the listener not block the event loop from finishing .
* /
unref ( ) : void ;
}
2021-09-19 08:46:54 -04:00
/ * * * * U N S T A B L E * * : N e w A P I s h o u l d b e t e s t e d f i r s t .
*
* Acquire an advisory file - system lock for the provided file . ` exclusive `
* defaults to ` false ` .
* /
export function flock ( rid : number , exclusive? : boolean ) : Promise < void > ;
/ * * * * U N S T A B L E * * : N e w A P I s h o u l d b e t e s t e d f i r s t .
*
* Acquire an advisory file - system lock for the provided file . ` exclusive `
* defaults to ` false ` .
* /
export function flockSync ( rid : number , exclusive? : boolean ) : void ;
/ * * * * U N S T A B L E * * : N e w A P I s h o u l d b e t e s t e d f i r s t .
*
* Release an advisory file - system lock for the provided file .
* /
export function funlock ( rid : number ) : Promise < void > ;
/ * * * * U N S T A B L E * * : N e w A P I s h o u l d b e t e s t e d f i r s t .
*
* Release an advisory file - system lock for the provided file .
* /
export function funlockSync ( rid : number ) : void ;
2021-12-09 03:00:55 -05:00
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Make the timer of the given id blocking the event loop from finishing
* /
export function refTimer ( id : number ) : void ;
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e d .
*
* Make the timer of the given id not blocking the event loop from finishing
* /
export function unrefTimer ( id : number ) : void ;
2022-03-16 09:54:18 -04:00
/ * * * * U N S T A B L E * * : n e w A P I , y e t t o b e v e t t e r .
*
* Allows to "hijack" a connection that the request is associated with .
* Can be used to implement protocols that build on top of HTTP ( eg .
* WebSockets ) .
*
* The returned promise returns underlying connection and first packet
* received . The promise shouldn ' t be awaited before responding to the
* ` request ` , otherwise event loop might deadlock .
* /
export function upgradeHttp (
request : Request ,
) : Promise < [ Deno . Conn , Uint8Array ] > ;
2022-04-20 18:20:33 -04:00
export interface SpawnOptions {
/** Arguments to pass to the process. */
args? : string [ ] ;
/ * *
* The working directory of the process .
* If not specified , the cwd of the parent process is used .
* /
cwd? : string | URL ;
/ * *
* Clear environmental variables from parent process .
* Doesn ' t guarantee that only ` opt.env ` variables are present ,
* as the OS may set environmental variables for processes .
* /
clearEnv? : boolean ;
/** Environmental variables to pass to the subprocess. */
env? : Record < string , string > ;
/ * *
* Sets the child process ’ s user ID . This translates to a setuid call
* in the child process . Failure in the setuid call will cause the spawn to fail .
* /
uid? : number ;
/** Similar to `uid`, but sets the group ID of the child process. */
gid? : number ;
2022-05-11 01:59:39 -04:00
/ * *
* An AbortSignal that allows closing the process using the corresponding
* AbortController by sending the process a SIGTERM signal .
* Not Supported by execSync .
* /
signal? : AbortSignal ;
2022-04-20 18:20:33 -04:00
/** Defaults to "null". */
stdin ? : "piped" | "inherit" | "null" ;
/** Defaults to "piped". */
stdout ? : "piped" | "inherit" | "null" ;
/** Defaults to "piped". */
stderr ? : "piped" | "inherit" | "null" ;
}
/ * *
* Spawns a child process .
*
* If stdin is set to "piped" , the stdin WritableStream needs to be closed manually .
*
* ` ` ` ts
* const child = Deno . spawnChild ( Deno . execPath ( ) , {
* args : [
* "eval" ,
* "console.log('Hello World')" ,
* ] ,
* stdin : "piped" ,
* } ) ;
*
* // open a file and pipe the subprocess output to it.
* child . stdout . pipeTo ( Deno . openSync ( "output" ) . writable ) ;
*
* // manually close stdin
* child . stdin . close ( ) ;
* const status = await child . status ;
* ` ` `
* /
export function spawnChild < T extends SpawnOptions = SpawnOptions > (
command : string | URL ,
options? : T ,
) : Child < T > ;
export class Child < T extends SpawnOptions > {
readonly stdin : T [ "stdin" ] extends "piped" ? WritableStream < Uint8Array >
: null ;
readonly stdout : T [ "stdout" ] extends "inherit" | "null" ? null
: ReadableStream < Uint8Array > ;
readonly stderr : T [ "stderr" ] extends "inherit" | "null" ? null
: ReadableStream < Uint8Array > ;
readonly pid : number ;
/** Get the status of the child. */
readonly status : Promise < ChildStatus > ;
/** Waits for the child to exit completely, returning all its output and status. */
output ( ) : Promise < SpawnOutput < T > > ;
2022-05-19 08:05:57 -04:00
/** Kills the process with given Signal. Defaults to SIGTERM. */
kill ( signo? : Signal ) : void ;
2022-04-20 18:20:33 -04:00
}
/ * *
* Executes a subprocess , waiting for it to finish and
* collecting all of its output .
2022-04-24 11:21:22 -04:00
* Will throw an error if ` stdin: "piped" ` is passed .
2022-04-20 18:20:33 -04:00
*
* ` ` ` ts
* const { status , stdout , stderr } = await Deno . spawn ( Deno . execPath ( ) , {
* args : [
* "eval" ,
* "console.log('hello'); console.error('world')" ,
* ] ,
* } ) ;
* console . assert ( status . code === 0 ) ;
* console . assert ( "hello\n" === new TextDecoder ( ) . decode ( stdout ) ) ;
* console . assert ( "world\n" === new TextDecoder ( ) . decode ( stderr ) ) ;
* ` ` `
* /
export function spawn < T extends SpawnOptions = SpawnOptions > (
command : string | URL ,
options? : T ,
) : Promise < SpawnOutput < T > > ;
/ * *
* Synchronously executes a subprocess , waiting for it to finish and
* collecting all of its output .
2022-04-24 11:21:22 -04:00
* Will throw an error if ` stdin: "piped" ` is passed .
2022-04-20 18:20:33 -04:00
*
2022-04-21 08:36:57 -04:00
* ` ` ` ts
2022-04-20 18:20:33 -04:00
* const { status , stdout , stderr } = Deno . spawnSync ( Deno . execPath ( ) , {
* args : [
* "eval" ,
* "console.log('hello'); console.error('world')" ,
* ] ,
* } ) ;
* console . assert ( status . code === 0 ) ;
* console . assert ( "hello\n" === new TextDecoder ( ) . decode ( stdout ) ) ;
* console . assert ( "world\n" === new TextDecoder ( ) . decode ( stderr ) ) ;
* ` ` `
* /
export function spawnSync < T extends SpawnOptions = SpawnOptions > (
command : string | URL ,
options? : T ,
) : SpawnOutput < T > ;
export type ChildStatus =
| {
success : true ;
code : 0 ;
signal : null ;
}
| {
success : false ;
code : number ;
2022-05-20 20:04:18 -04:00
signal : Signal | null ;
2022-04-20 18:20:33 -04:00
} ;
export interface SpawnOutput < T extends SpawnOptions > {
status : ChildStatus ;
stdout : T [ "stdout" ] extends "inherit" | "null" ? null : Uint8Array ;
stderr : T [ "stderr" ] extends "inherit" | "null" ? null : Uint8Array ;
}
2020-04-30 11:23:40 -04:00
}
2020-08-05 14:44:03 -04:00
declare function fetch (
input : Request | URL | string ,
init? : RequestInit & { client : Deno.HttpClient } ,
) : Promise < Response > ;
2021-01-29 08:15:59 -05:00
declare interface WorkerOptions {
/ * * U N S T A B L E : N e w A P I .
*
2022-03-24 11:27:24 -04:00
* Configure permissions options to change the level of access the worker will
* have . By default it will have no permissions . Note that the permissions
2021-01-29 08:15:59 -05:00
* of a worker can 't be extended beyond its parent' s permissions reach .
* - "inherit" will take the permissions of the thread the worker is created in
2022-03-24 11:27:24 -04:00
* - "none" will use the default behavior and have no permission
2021-01-29 08:15:59 -05:00
* - You can provide a list of routes relative to the file the worker
* is created in to limit the access of the worker ( read / write permissions only )
*
* Example :
*
* ` ` ` ts
* // mod.ts
* const worker = new Worker (
* new URL ( "deno_worker.ts" , import . meta . url ) . href , {
* type : "module" ,
* deno : {
* permissions : {
* read : true ,
* } ,
* } ,
* }
* ) ;
* ` ` `
* /
2022-05-17 16:27:17 -04:00
deno ? : {
2021-01-29 08:15:59 -05:00
/** Set to `"none"` to disable all the permissions in the worker. */
2022-03-10 19:35:33 -05:00
permissions? : Deno.PermissionOptions ;
2021-01-29 08:15:59 -05:00
} ;
}
2021-08-09 18:28:17 -04:00
declare interface WebSocketStreamOptions {
protocols? : string [ ] ;
signal? : AbortSignal ;
2022-01-05 11:41:44 -05:00
headers? : HeadersInit ;
2021-08-09 18:28:17 -04:00
}
declare interface WebSocketConnection {
readable : ReadableStream < string | Uint8Array > ;
writable : WritableStream < string | Uint8Array > ;
extensions : string ;
protocol : string ;
}
declare interface WebSocketCloseInfo {
code? : number ;
reason? : string ;
}
declare class WebSocketStream {
constructor ( url : string , options? : WebSocketStreamOptions ) ;
url : string ;
connection : Promise < WebSocketConnection > ;
closed : Promise < WebSocketCloseInfo > ;
close ( closeInfo? : WebSocketCloseInfo ) : void ;
}