-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtypes.d.ts
More file actions
59 lines (52 loc) · 1.69 KB
/
types.d.ts
File metadata and controls
59 lines (52 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Type definitions for Compactr
* Schema based serialization made easy
*/
declare module 'compactr' {
export const schema: (schema: SchemaDefinition, options?: SchemaOptions) => SchemaInstance;
export interface SchemaInstance {
/**
* Encodes data according to the schema
* @param data The data to be encoded
* @param options The options for the encoding
* @returns The encoded buffer
*/
write(data: any, options?: WriteOptions): Buffer
/**
* Returns the byte sizes of a data object, for insight or troubleshooting
* @param data The data to extract size information of
* @returns The detailed sizes information
*/
sizes(data: any): Record<string, any>
/**
* Reads data from a buffer and decodes it according to the schema
* @param buffer The buffer to decode
* @param options The options for the decoding
* @returns The decoded data
*/
read(buffer: Buffer | number[]): any
}
export interface SchemaFieldDefinition {
type?: 'boolean' | 'integer' | 'number' | 'string' | 'array' | 'object'
format?: 'int32' | 'int64' | 'float' | 'double' | 'uuid' | 'ipv4' | 'ipv6' | 'date' | 'date-time' | 'binary'
nullable?: boolean
count?: number
size?: number
schema?: SchemaDefinition
properties?: SchemaDefinition
items?: SchemaFieldDefinition
oneOf?: SchemaFieldDefinition[]
anyOf?: SchemaFieldDefinition[]
$ref?: string
}
export interface SchemaDefinition {
[key: string]: SchemaFieldDefinition
}
export interface SchemaOptions {
schemas?: { [key: string]: SchemaFieldDefinition }
}
export interface WriteOptions {
coerse?: boolean
validate?: boolean
}
}