• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation. All rights reserved.
3Licensed under the Apache License, Version 2.0 (the "License"); you may not use
4this file except in compliance with the License. You may obtain a copy of the
5License at http://www.apache.org/licenses/LICENSE-2.0
6
7THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
8KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
9WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
10MERCHANTABLITY OR NON-INFRINGEMENT.
11
12See the Apache Version 2.0 License for specific language governing permissions
13and limitations under the License.
14***************************************************************************** */
15
16
17
18/// <reference no-default-lib="true"/>
19
20
21interface ProxyHandler<T extends object> {
22    /**
23     * A trap method for a function call.
24     * @param target The original callable object which is being proxied.
25     */
26    apply?(target: T, thisArg: any, argArray: any[]): any;
27
28    /**
29     * A trap for the `new` operator.
30     * @param target The original object which is being proxied.
31     * @param newTarget The constructor that was originally called.
32     */
33    construct?(target: T, argArray: any[], newTarget: Function): object;
34
35    /**
36     * A trap for `Object.defineProperty()`.
37     * @param target The original object which is being proxied.
38     * @returns A `Boolean` indicating whether or not the property has been defined.
39     */
40    defineProperty?(target: T, property: string | symbol, attributes: PropertyDescriptor): boolean;
41
42    /**
43     * A trap for the `delete` operator.
44     * @param target The original object which is being proxied.
45     * @param p The name or `Symbol` of the property to delete.
46     * @returns A `Boolean` indicating whether or not the property was deleted.
47     */
48    deleteProperty?(target: T, p: string | symbol): boolean;
49
50    /**
51     * A trap for getting a property value.
52     * @param target The original object which is being proxied.
53     * @param p The name or `Symbol` of the property to get.
54     * @param receiver The proxy or an object that inherits from the proxy.
55     */
56    get?(target: T, p: string | symbol, receiver: any): any;
57
58    /**
59     * A trap for `Object.getOwnPropertyDescriptor()`.
60     * @param target The original object which is being proxied.
61     * @param p The name of the property whose description should be retrieved.
62     */
63    getOwnPropertyDescriptor?(target: T, p: string | symbol): PropertyDescriptor | undefined;
64
65    /**
66     * A trap for the `[[GetPrototypeOf]]` internal method.
67     * @param target The original object which is being proxied.
68     */
69    getPrototypeOf?(target: T): object | null;
70
71    /**
72     * A trap for the `in` operator.
73     * @param target The original object which is being proxied.
74     * @param p The name or `Symbol` of the property to check for existence.
75     */
76    has?(target: T, p: string | symbol): boolean;
77
78    /**
79     * A trap for `Object.isExtensible()`.
80     * @param target The original object which is being proxied.
81     */
82    isExtensible?(target: T): boolean;
83
84    /**
85     * A trap for `Reflect.ownKeys()`.
86     * @param target The original object which is being proxied.
87     */
88    ownKeys?(target: T): ArrayLike<string | symbol>;
89
90    /**
91     * A trap for `Object.preventExtensions()`.
92     * @param target The original object which is being proxied.
93     */
94    preventExtensions?(target: T): boolean;
95
96    /**
97     * A trap for setting a property value.
98     * @param target The original object which is being proxied.
99     * @param p The name or `Symbol` of the property to set.
100     * @param receiver The object to which the assignment was originally directed.
101     * @returns A `Boolean` indicating whether or not the property was set.
102     */
103    set?(target: T, p: string | symbol, newValue: any, receiver: any): boolean;
104
105    /**
106     * A trap for `Object.setPrototypeOf()`.
107     * @param target The original object which is being proxied.
108     * @param newPrototype The object's new prototype or `null`.
109     */
110    setPrototypeOf?(target: T, v: object | null): boolean;
111}
112
113interface ProxyConstructor {
114    /**
115     * Creates a revocable Proxy object.
116     * @param target A target object to wrap with Proxy.
117     * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
118     */
119    revocable<T extends object>(target: T, handler: ProxyHandler<T>): { proxy: T; revoke: () => void; };
120
121    /**
122     * Creates a Proxy object. The Proxy object allows you to create an object that can be used in place of the
123     * original object, but which may redefine fundamental Object operations like getting, setting, and defining
124     * properties. Proxy objects are commonly used to log property accesses, validate, format, or sanitize inputs.
125     * @param target A target object to wrap with Proxy.
126     * @param handler An object whose properties define the behavior of Proxy when an operation is attempted on it.
127     */
128    new <T extends object>(target: T, handler: ProxyHandler<T>): T;
129}
130declare var Proxy: ProxyConstructor;
131