-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.d.ts
143 lines (134 loc) · 3.26 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Type definitions for @pipcook/boa
type BytesObject = any;
type KeywordArguments = any;
type WithStmtCallback = (ctx: PyObject) => any;
// Boa Interface
declare const GetOwnershipSymbol: unique symbol;
declare const PyGetAttrSymbol: unique symbol;
declare const PySetAttrSymbol: unique symbol;
declare const PyGetItemSymbol: unique symbol;
declare const PySetItemSymbol: unique symbol;
/**
* Python Object.
*/
declare interface PyObject {
/**
* returns the string representation of the python object.
*/
toString(): string;
/**
* returns the JSON object.
*/
toJSON(): object;
/**
* Shortcut for slicing object.
* @param start
* @param end
* @param step
*/
slice(start?: number, end?: number, step?: number): PyObject;
/**
* Get the ownership of this object for main thread.
*/
[GetOwnershipSymbol](): any;
/**
* Get the attribute of this python object.
* @param k
*/
[PyGetAttrSymbol](k: any): any;
/**
* Set the attribute of this python object.
* @param k
* @param v
*/
[PySetAttrSymbol](k: any, v: any): any;
/**
* Get the item of this python object.
* @param k
*/
[PyGetItemSymbol](k: any): any;
/**
* Set the item of this python object.
* @param k
* @param v
*/
[PySetItemSymbol](k: any, v: any): any;
// The followings are Proxy-related fields.
// TODO(Yorkie): returns the specific types.
/**
* Proxy object access.
*/
[key: string]: any;
/**
* Proxy array access.
*/
[key: number]: any;
/**
* Proxy function call.
*/
(...args: any[]): any;
}
/**
* https://docs.python.org/3.8/library/functions.html#func-list
*/
declare interface PyBuiltins extends PyObject {
// TODO(Yorkie): generated by Python interface.
}
/**
* This is a wrapper for shared Python object, just like
* v8's `SharedArrayBuffer`.
*/
declare class SharedObject {
constructor(o: PyObject);
}
interface BoaInterface {
/**
* Reset the Python module environment, it clears the `sys.modules`, and
* add the given search paths if provided.
* @param extraSearchPath
*/
setenv(extraSearchPath: string): void;
/**
* Import a Python module.
* @param name the module name.
*/
import(name: string): PyObject;
/**
* Get the builtins
*/
builtins(): PyBuiltins;
/**
* Create a bytes object.
* @param data the input data.
*/
bytes(data: string): BytesObject;
/**
* Create a keyword arguments objects.
* @param input the kwargs input.
*/
kwargs(input: object): KeywordArguments;
/**
* With-statement function, See:
* https://docs.python.org/3/reference/compound_stmts.html#the-with-statement
* @param ctx
* @param fn
*/
with(ctx: PyObject, fn: WithStmtCallback): Promise<any>;
/**
* Evaluate a Python expression.
* @param strs the template string.
* @param args
*/
eval(strs: TemplateStringsArray | string[] | string, ...args: any[]): PyObject;
// internal interfaces.
symbols: {
GetOwnershipSymbol: typeof GetOwnershipSymbol;
PyGetAttrSymbol: typeof PyGetAttrSymbol;
PySetAttrSymbol: typeof PySetAttrSymbol;
PyGetItemSymbol: typeof PyGetItemSymbol;
PySetItemSymbol: typeof PySetItemSymbol;
};
SharedObject: typeof SharedObject;
}
declare const api: BoaInterface;
export = api;