@wix/motion 1.0.45 → 1.0.47
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/package.json +5 -5
- package/type-bundles/context.bundle.d.ts +1272 -35
- package/type-bundles/index.bundle.d.ts +1272 -35
|
@@ -1,39 +1,127 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
type HostModule$2<T, H extends Host$2> = {
|
|
2
|
+
__type: 'host';
|
|
3
|
+
create(host: H): T;
|
|
4
|
+
};
|
|
5
|
+
type HostModuleAPI$2<T extends HostModule$2<any, any>> = T extends HostModule$2<infer U, any> ? U : never;
|
|
6
|
+
type Host$2<Environment = unknown> = {
|
|
7
|
+
channel: {
|
|
8
|
+
observeState(callback: (props: unknown, environment: Environment) => unknown): {
|
|
9
|
+
disconnect: () => void;
|
|
10
|
+
} | Promise<{
|
|
11
|
+
disconnect: () => void;
|
|
12
|
+
}>;
|
|
13
|
+
};
|
|
14
|
+
environment?: Environment;
|
|
15
|
+
/**
|
|
16
|
+
* Optional bast url to use for API requests, for example `www.wixapis.com`
|
|
17
|
+
*/
|
|
18
|
+
apiBaseUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Possible data to be provided by every host, for cross cutting concerns
|
|
21
|
+
* like internationalization, billing, etc.
|
|
22
|
+
*/
|
|
23
|
+
essentials?: {
|
|
24
|
+
/**
|
|
25
|
+
* The language of the currently viewed session
|
|
26
|
+
*/
|
|
27
|
+
language?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The locale of the currently viewed session
|
|
30
|
+
*/
|
|
31
|
+
locale?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Any headers that should be passed through to the API requests
|
|
34
|
+
*/
|
|
35
|
+
passThroughHeaders?: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type RESTFunctionDescriptor$2<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient$2) => T;
|
|
40
|
+
interface HttpClient$2 {
|
|
41
|
+
request<TResponse, TData = any>(req: RequestOptionsFactory$2<TResponse, TData>): Promise<HttpResponse$2<TResponse>>;
|
|
4
42
|
fetchWithAuth: typeof fetch;
|
|
5
43
|
wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
|
|
44
|
+
getActiveToken?: () => string | undefined;
|
|
6
45
|
}
|
|
7
|
-
type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
|
|
8
|
-
type HttpResponse<T = any> = {
|
|
46
|
+
type RequestOptionsFactory$2<TResponse = any, TData = any> = (context: any) => RequestOptions$2<TResponse, TData>;
|
|
47
|
+
type HttpResponse$2<T = any> = {
|
|
9
48
|
data: T;
|
|
10
49
|
status: number;
|
|
11
50
|
statusText: string;
|
|
12
51
|
headers: any;
|
|
13
52
|
request?: any;
|
|
14
53
|
};
|
|
15
|
-
type RequestOptions<_TResponse = any, Data = any> = {
|
|
54
|
+
type RequestOptions$2<_TResponse = any, Data = any> = {
|
|
16
55
|
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
17
56
|
url: string;
|
|
18
57
|
data?: Data;
|
|
19
58
|
params?: URLSearchParams;
|
|
20
|
-
} & APIMetadata;
|
|
21
|
-
type APIMetadata = {
|
|
59
|
+
} & APIMetadata$2;
|
|
60
|
+
type APIMetadata$2 = {
|
|
22
61
|
methodFqn?: string;
|
|
23
62
|
entityFqdn?: string;
|
|
24
63
|
packageName?: string;
|
|
25
64
|
};
|
|
26
|
-
type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
|
|
27
|
-
type EventDefinition<Payload = unknown, Type extends string = string> = {
|
|
65
|
+
type BuildRESTFunction$2<T extends RESTFunctionDescriptor$2> = T extends RESTFunctionDescriptor$2<infer U> ? U : never;
|
|
66
|
+
type EventDefinition$4<Payload = unknown, Type extends string = string> = {
|
|
28
67
|
__type: 'event-definition';
|
|
29
68
|
type: Type;
|
|
30
69
|
isDomainEvent?: boolean;
|
|
31
70
|
transformations?: (envelope: unknown) => Payload;
|
|
32
71
|
__payload: Payload;
|
|
33
72
|
};
|
|
34
|
-
declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
|
|
35
|
-
type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
|
|
36
|
-
type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
|
|
73
|
+
declare function EventDefinition$4<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$4<Payload, Type>;
|
|
74
|
+
type EventHandler$4<T extends EventDefinition$4> = (payload: T['__payload']) => void | Promise<void>;
|
|
75
|
+
type BuildEventDefinition$4<T extends EventDefinition$4<any, string>> = (handler: EventHandler$4<T>) => void;
|
|
76
|
+
|
|
77
|
+
type ServicePluginMethodInput$2 = {
|
|
78
|
+
request: any;
|
|
79
|
+
metadata: any;
|
|
80
|
+
};
|
|
81
|
+
type ServicePluginContract$2 = Record<string, (payload: ServicePluginMethodInput$2) => unknown | Promise<unknown>>;
|
|
82
|
+
type ServicePluginMethodMetadata$2 = {
|
|
83
|
+
name: string;
|
|
84
|
+
primaryHttpMappingPath: string;
|
|
85
|
+
transformations: {
|
|
86
|
+
fromREST: (...args: unknown[]) => ServicePluginMethodInput$2;
|
|
87
|
+
toREST: (...args: unknown[]) => unknown;
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
type ServicePluginDefinition$2<Contract extends ServicePluginContract$2> = {
|
|
91
|
+
__type: 'service-plugin-definition';
|
|
92
|
+
componentType: string;
|
|
93
|
+
methods: ServicePluginMethodMetadata$2[];
|
|
94
|
+
__contract: Contract;
|
|
95
|
+
};
|
|
96
|
+
declare function ServicePluginDefinition$2<Contract extends ServicePluginContract$2>(componentType: string, methods: ServicePluginMethodMetadata$2[]): ServicePluginDefinition$2<Contract>;
|
|
97
|
+
type BuildServicePluginDefinition$2<T extends ServicePluginDefinition$2<any>> = (implementation: T['__contract']) => void;
|
|
98
|
+
declare const SERVICE_PLUGIN_ERROR_TYPE$2 = "wix_spi_error";
|
|
99
|
+
|
|
100
|
+
type RequestContext$2 = {
|
|
101
|
+
isSSR: boolean;
|
|
102
|
+
host: string;
|
|
103
|
+
protocol?: string;
|
|
104
|
+
};
|
|
105
|
+
type ResponseTransformer$2 = (data: any, headers?: any) => any;
|
|
106
|
+
/**
|
|
107
|
+
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
108
|
+
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
109
|
+
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
110
|
+
*/
|
|
111
|
+
type Method$2 = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
112
|
+
type AmbassadorRequestOptions$2<T = any> = {
|
|
113
|
+
_?: T;
|
|
114
|
+
url?: string;
|
|
115
|
+
method?: Method$2;
|
|
116
|
+
params?: any;
|
|
117
|
+
data?: any;
|
|
118
|
+
transformResponse?: ResponseTransformer$2 | ResponseTransformer$2[];
|
|
119
|
+
};
|
|
120
|
+
type AmbassadorFactory$2<Request, Response> = (payload: Request) => ((context: RequestContext$2) => AmbassadorRequestOptions$2<Response>) & {
|
|
121
|
+
__isAmbassador: boolean;
|
|
122
|
+
};
|
|
123
|
+
type AmbassadorFunctionDescriptor$2<Request = any, Response = any> = AmbassadorFactory$2<Request, Response>;
|
|
124
|
+
type BuildAmbassadorFunction$2<T extends AmbassadorFunctionDescriptor$2> = T extends AmbassadorFunctionDescriptor$2<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
37
125
|
|
|
38
126
|
declare global {
|
|
39
127
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
@@ -42,10 +130,303 @@ declare global {
|
|
|
42
130
|
}
|
|
43
131
|
}
|
|
44
132
|
|
|
133
|
+
declare const emptyObjectSymbol$2: unique symbol;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
137
|
+
|
|
138
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
139
|
+
|
|
140
|
+
@example
|
|
141
|
+
```
|
|
142
|
+
import type {EmptyObject} from 'type-fest';
|
|
143
|
+
|
|
144
|
+
// The following illustrates the problem with `{}`.
|
|
145
|
+
const foo1: {} = {}; // Pass
|
|
146
|
+
const foo2: {} = []; // Pass
|
|
147
|
+
const foo3: {} = 42; // Pass
|
|
148
|
+
const foo4: {} = {a: 1}; // Pass
|
|
149
|
+
|
|
150
|
+
// With `EmptyObject` only the first case is valid.
|
|
151
|
+
const bar1: EmptyObject = {}; // Pass
|
|
152
|
+
const bar2: EmptyObject = 42; // Fail
|
|
153
|
+
const bar3: EmptyObject = []; // Fail
|
|
154
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
158
|
+
|
|
159
|
+
@category Object
|
|
160
|
+
*/
|
|
161
|
+
type EmptyObject$2 = {[emptyObjectSymbol$2]?: never};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
Returns a boolean for whether the two given types are equal.
|
|
165
|
+
|
|
166
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
167
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
168
|
+
|
|
169
|
+
Use-cases:
|
|
170
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
171
|
+
|
|
172
|
+
@example
|
|
173
|
+
```
|
|
174
|
+
import type {IsEqual} from 'type-fest';
|
|
175
|
+
|
|
176
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
177
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
178
|
+
type Includes<Value extends readonly any[], Item> =
|
|
179
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
180
|
+
? IsEqual<Value[0], Item> extends true
|
|
181
|
+
? true
|
|
182
|
+
: Includes<rest, Item>
|
|
183
|
+
: false;
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
@category Type Guard
|
|
187
|
+
@category Utilities
|
|
188
|
+
*/
|
|
189
|
+
type IsEqual$2<A, B> =
|
|
190
|
+
(<G>() => G extends A ? 1 : 2) extends
|
|
191
|
+
(<G>() => G extends B ? 1 : 2)
|
|
192
|
+
? true
|
|
193
|
+
: false;
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
Filter out keys from an object.
|
|
197
|
+
|
|
198
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
199
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
200
|
+
Returns `Key` otherwise.
|
|
201
|
+
|
|
202
|
+
@example
|
|
203
|
+
```
|
|
204
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
205
|
+
//=> never
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
@example
|
|
209
|
+
```
|
|
210
|
+
type Filtered = Filter<'bar', string>;
|
|
211
|
+
//=> never
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
@example
|
|
215
|
+
```
|
|
216
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
217
|
+
//=> 'bar'
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
@see {Except}
|
|
221
|
+
*/
|
|
222
|
+
type Filter$2<KeyType, ExcludeType> = IsEqual$2<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
223
|
+
|
|
224
|
+
type ExceptOptions$2 = {
|
|
225
|
+
/**
|
|
226
|
+
Disallow assigning non-specified properties.
|
|
227
|
+
|
|
228
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
229
|
+
|
|
230
|
+
@default false
|
|
231
|
+
*/
|
|
232
|
+
requireExactProps?: boolean;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
Create a type from an object type without certain keys.
|
|
237
|
+
|
|
238
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
239
|
+
|
|
240
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
241
|
+
|
|
242
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
243
|
+
|
|
244
|
+
@example
|
|
245
|
+
```
|
|
246
|
+
import type {Except} from 'type-fest';
|
|
247
|
+
|
|
248
|
+
type Foo = {
|
|
249
|
+
a: number;
|
|
250
|
+
b: string;
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
254
|
+
//=> {b: string}
|
|
255
|
+
|
|
256
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
257
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
258
|
+
|
|
259
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
260
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
261
|
+
|
|
262
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
263
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
@category Object
|
|
267
|
+
*/
|
|
268
|
+
type Except$2<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions$2 = {requireExactProps: false}> = {
|
|
269
|
+
[KeyType in keyof ObjectType as Filter$2<KeyType, KeysType>]: ObjectType[KeyType];
|
|
270
|
+
} & (Options['requireExactProps'] extends true
|
|
271
|
+
? Partial<Record<KeysType, never>>
|
|
272
|
+
: {});
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
276
|
+
|
|
277
|
+
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
|
278
|
+
|
|
279
|
+
@example
|
|
280
|
+
```
|
|
281
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
282
|
+
|
|
283
|
+
interface Example {
|
|
284
|
+
a: string;
|
|
285
|
+
b: string | number;
|
|
286
|
+
c?: string;
|
|
287
|
+
d: {};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
type StringKeysOnly = ConditionalKeys<Example, string>;
|
|
291
|
+
//=> 'a'
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
|
295
|
+
|
|
296
|
+
@example
|
|
297
|
+
```
|
|
298
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
299
|
+
|
|
300
|
+
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
301
|
+
//=> 'a' | 'c'
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
@category Object
|
|
305
|
+
*/
|
|
306
|
+
type ConditionalKeys$2<Base, Condition> = NonNullable<
|
|
307
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
308
|
+
{
|
|
309
|
+
// Map through all the keys of the given base type.
|
|
310
|
+
[Key in keyof Base]:
|
|
311
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
312
|
+
Base[Key] extends Condition
|
|
313
|
+
// Retain this key since the condition passes.
|
|
314
|
+
? Key
|
|
315
|
+
// Discard this key since the condition fails.
|
|
316
|
+
: never;
|
|
317
|
+
|
|
318
|
+
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
319
|
+
}[keyof Base]
|
|
320
|
+
>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
Exclude keys from a shape that matches the given `Condition`.
|
|
324
|
+
|
|
325
|
+
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
|
326
|
+
|
|
327
|
+
@example
|
|
328
|
+
```
|
|
329
|
+
import type {Primitive, ConditionalExcept} from 'type-fest';
|
|
330
|
+
|
|
331
|
+
class Awesome {
|
|
332
|
+
name: string;
|
|
333
|
+
successes: number;
|
|
334
|
+
failures: bigint;
|
|
335
|
+
|
|
336
|
+
run() {}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
|
340
|
+
//=> {run: () => void}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
@example
|
|
344
|
+
```
|
|
345
|
+
import type {ConditionalExcept} from 'type-fest';
|
|
346
|
+
|
|
347
|
+
interface Example {
|
|
348
|
+
a: string;
|
|
349
|
+
b: string | number;
|
|
350
|
+
c: () => void;
|
|
351
|
+
d: {};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
355
|
+
//=> {b: string | number; c: () => void; d: {}}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
@category Object
|
|
359
|
+
*/
|
|
360
|
+
type ConditionalExcept$2<Base, Condition> = Except$2<
|
|
361
|
+
Base,
|
|
362
|
+
ConditionalKeys$2<Base, Condition>
|
|
363
|
+
>;
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Descriptors are objects that describe the API of a module, and the module
|
|
367
|
+
* can either be a REST module or a host module.
|
|
368
|
+
* This type is recursive, so it can describe nested modules.
|
|
369
|
+
*/
|
|
370
|
+
type Descriptors$2 = RESTFunctionDescriptor$2 | AmbassadorFunctionDescriptor$2 | HostModule$2<any, any> | EventDefinition$4<any> | ServicePluginDefinition$2<any> | {
|
|
371
|
+
[key: string]: Descriptors$2 | PublicMetadata$2 | any;
|
|
372
|
+
};
|
|
373
|
+
/**
|
|
374
|
+
* This type takes in a descriptors object of a certain Host (including an `unknown` host)
|
|
375
|
+
* and returns an object with the same structure, but with all descriptors replaced with their API.
|
|
376
|
+
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
377
|
+
* do not match the given host (as they will not work with the given host).
|
|
378
|
+
*/
|
|
379
|
+
type BuildDescriptors$2<T extends Descriptors$2, H extends Host$2<any> | undefined, Depth extends number = 5> = {
|
|
380
|
+
done: T;
|
|
381
|
+
recurse: T extends {
|
|
382
|
+
__type: typeof SERVICE_PLUGIN_ERROR_TYPE$2;
|
|
383
|
+
} ? never : T extends AmbassadorFunctionDescriptor$2 ? BuildAmbassadorFunction$2<T> : T extends RESTFunctionDescriptor$2 ? BuildRESTFunction$2<T> : T extends EventDefinition$4<any> ? BuildEventDefinition$4<T> : T extends ServicePluginDefinition$2<any> ? BuildServicePluginDefinition$2<T> : T extends HostModule$2<any, any> ? HostModuleAPI$2<T> : ConditionalExcept$2<{
|
|
384
|
+
[Key in keyof T]: T[Key] extends Descriptors$2 ? BuildDescriptors$2<T[Key], H, [
|
|
385
|
+
-1,
|
|
386
|
+
0,
|
|
387
|
+
1,
|
|
388
|
+
2,
|
|
389
|
+
3,
|
|
390
|
+
4,
|
|
391
|
+
5
|
|
392
|
+
][Depth]> : never;
|
|
393
|
+
}, EmptyObject$2>;
|
|
394
|
+
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
395
|
+
type PublicMetadata$2 = {
|
|
396
|
+
PACKAGE_NAME?: string;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
declare global {
|
|
400
|
+
interface ContextualClient {
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* A type used to create concerete types from SDK descriptors in
|
|
405
|
+
* case a contextual client is available.
|
|
406
|
+
*/
|
|
407
|
+
type MaybeContext$2<T extends Descriptors$2> = globalThis.ContextualClient extends {
|
|
408
|
+
host: Host$2;
|
|
409
|
+
} ? BuildDescriptors$2<T, globalThis.ContextualClient['host']> : T;
|
|
410
|
+
|
|
45
411
|
interface AlarmMessage {
|
|
46
412
|
_id?: string;
|
|
47
413
|
seconds?: number;
|
|
48
414
|
}
|
|
415
|
+
interface Dispatched$1 {
|
|
416
|
+
/** the message someone says */
|
|
417
|
+
echo?: EchoMessage$1;
|
|
418
|
+
}
|
|
419
|
+
interface EchoMessage$1 {
|
|
420
|
+
/** message comment from EchoMessage proto def, with special comment */
|
|
421
|
+
message?: string;
|
|
422
|
+
/** messages_list comment from EchoMessage proto def */
|
|
423
|
+
messagesList?: MessageItem$1[];
|
|
424
|
+
_id?: string;
|
|
425
|
+
}
|
|
426
|
+
interface MessageItem$1 {
|
|
427
|
+
/** inner_message comment from EchoMessage proto def */
|
|
428
|
+
innerMessage?: string;
|
|
429
|
+
}
|
|
49
430
|
interface AlarmRequest {
|
|
50
431
|
seconds: number;
|
|
51
432
|
someString?: string;
|
|
@@ -260,28 +641,46 @@ interface UpdateAlarm {
|
|
|
260
641
|
seconds?: number;
|
|
261
642
|
}
|
|
262
643
|
|
|
263
|
-
declare function alarm$1(httpClient: HttpClient): AlarmSignature;
|
|
644
|
+
declare function alarm$1(httpClient: HttpClient$2): AlarmSignature;
|
|
264
645
|
interface AlarmSignature {
|
|
265
646
|
/**
|
|
266
647
|
* sets up an alarm after {seconds}
|
|
267
648
|
*/
|
|
268
649
|
(seconds: number, options?: AlarmOptions | undefined): Promise<AlarmResponse>;
|
|
269
650
|
}
|
|
270
|
-
declare function updateAlarm$1(httpClient: HttpClient): UpdateAlarmSignature;
|
|
651
|
+
declare function updateAlarm$1(httpClient: HttpClient$2): UpdateAlarmSignature;
|
|
271
652
|
interface UpdateAlarmSignature {
|
|
272
653
|
/**
|
|
273
654
|
* sets up an existing alarm with id {id}
|
|
274
655
|
*/
|
|
275
656
|
(_id: string, alarm: UpdateAlarm): Promise<UpdateAlarmResponse & UpdateAlarmResponseNonNullableFields>;
|
|
276
657
|
}
|
|
277
|
-
declare const onAlarmTriggered$1: EventDefinition<AlarmTriggeredEnvelope, "wix.alarm.v1.alarm_alarm_triggered">;
|
|
278
|
-
declare const onAlarmSnoozed$1: EventDefinition<AlarmSnoozedEnvelope, "wix.alarm.v1.alarm_alarm_snoozed">;
|
|
279
|
-
declare const onAlarmDeleted$1: EventDefinition<AlarmDeletedEnvelope, "wix.alarm.v1.alarm_alarm_deleted">;
|
|
658
|
+
declare const onAlarmTriggered$1: EventDefinition$4<AlarmTriggeredEnvelope, "wix.alarm.v1.alarm_alarm_triggered">;
|
|
659
|
+
declare const onAlarmSnoozed$1: EventDefinition$4<AlarmSnoozedEnvelope, "wix.alarm.v1.alarm_alarm_snoozed">;
|
|
660
|
+
declare const onAlarmDeleted$1: EventDefinition$4<AlarmDeletedEnvelope, "wix.alarm.v1.alarm_alarm_deleted">;
|
|
280
661
|
|
|
281
|
-
|
|
662
|
+
type EventDefinition$3<Payload = unknown, Type extends string = string> = {
|
|
663
|
+
__type: 'event-definition';
|
|
664
|
+
type: Type;
|
|
665
|
+
isDomainEvent?: boolean;
|
|
666
|
+
transformations?: (envelope: unknown) => Payload;
|
|
667
|
+
__payload: Payload;
|
|
668
|
+
};
|
|
669
|
+
declare function EventDefinition$3<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$3<Payload, Type>;
|
|
670
|
+
type EventHandler$3<T extends EventDefinition$3> = (payload: T['__payload']) => void | Promise<void>;
|
|
671
|
+
type BuildEventDefinition$3<T extends EventDefinition$3<any, string>> = (handler: EventHandler$3<T>) => void;
|
|
672
|
+
|
|
673
|
+
declare global {
|
|
674
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
675
|
+
interface SymbolConstructor {
|
|
676
|
+
readonly observable: symbol;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
282
679
|
|
|
283
|
-
declare
|
|
284
|
-
|
|
680
|
+
declare function createEventModule$1<T extends EventDefinition$3<any, string>>(eventDefinition: T): BuildEventDefinition$3<T> & T;
|
|
681
|
+
|
|
682
|
+
declare const alarm: MaybeContext$2<BuildRESTFunction$2<typeof alarm$1> & typeof alarm$1>;
|
|
683
|
+
declare const updateAlarm: MaybeContext$2<BuildRESTFunction$2<typeof updateAlarm$1> & typeof updateAlarm$1>;
|
|
285
684
|
|
|
286
685
|
type _publicOnAlarmTriggeredType = typeof onAlarmTriggered$1;
|
|
287
686
|
/**
|
|
@@ -326,8 +725,418 @@ declare const context$2_onAlarmSnoozed: typeof onAlarmSnoozed;
|
|
|
326
725
|
declare const context$2_onAlarmTriggered: typeof onAlarmTriggered;
|
|
327
726
|
declare const context$2_updateAlarm: typeof updateAlarm;
|
|
328
727
|
declare namespace context$2 {
|
|
329
|
-
export { type ActionEvent$2 as ActionEvent, type context$2_AlarmDeleted as AlarmDeleted, type context$2_AlarmDeletedEnvelope as AlarmDeletedEnvelope, type context$2_AlarmMessage as AlarmMessage, type context$2_AlarmOptions as AlarmOptions, type context$2_AlarmRequest as AlarmRequest, type context$2_AlarmRequestRequiredFields as AlarmRequestRequiredFields, type context$2_AlarmResponse as AlarmResponse, type context$2_AlarmSnoozed as AlarmSnoozed, type context$2_AlarmSnoozedEnvelope as AlarmSnoozedEnvelope, type context$2_AlarmTriggered as AlarmTriggered, type context$2_AlarmTriggeredEnvelope as AlarmTriggeredEnvelope, type BaseEventMetadata$1 as BaseEventMetadata, type DomainEvent$2 as DomainEvent, type DomainEventBodyOneOf$2 as DomainEventBodyOneOf, type EntityCreatedEvent$2 as EntityCreatedEvent, type EntityDeletedEvent$2 as EntityDeletedEvent, type EntityUpdatedEvent$2 as EntityUpdatedEvent, type EventMetadata$1 as EventMetadata, type IdentificationData$2 as IdentificationData, type IdentificationDataIdOneOf$2 as IdentificationDataIdOneOf, type MessageEnvelope$2 as MessageEnvelope, type RestoreInfo$2 as RestoreInfo, type context$2_UpdateAlarm as UpdateAlarm, type context$2_UpdateAlarmRequest as UpdateAlarmRequest, type context$2_UpdateAlarmRequestRequiredFields as UpdateAlarmRequestRequiredFields, type context$2_UpdateAlarmResponse as UpdateAlarmResponse, type context$2_UpdateAlarmResponseNonNullableFields as UpdateAlarmResponseNonNullableFields, WebhookIdentityType$2 as WebhookIdentityType, type context$2__publicOnAlarmDeletedType as _publicOnAlarmDeletedType, type context$2__publicOnAlarmSnoozedType as _publicOnAlarmSnoozedType, type context$2__publicOnAlarmTriggeredType as _publicOnAlarmTriggeredType, context$2_alarm as alarm, context$2_onAlarmDeleted as onAlarmDeleted, context$2_onAlarmSnoozed as onAlarmSnoozed, context$2_onAlarmTriggered as onAlarmTriggered, onAlarmDeleted$1 as publicOnAlarmDeleted, onAlarmSnoozed$1 as publicOnAlarmSnoozed, onAlarmTriggered$1 as publicOnAlarmTriggered, context$2_updateAlarm as updateAlarm };
|
|
728
|
+
export { type ActionEvent$2 as ActionEvent, type context$2_AlarmDeleted as AlarmDeleted, type context$2_AlarmDeletedEnvelope as AlarmDeletedEnvelope, type context$2_AlarmMessage as AlarmMessage, type context$2_AlarmOptions as AlarmOptions, type context$2_AlarmRequest as AlarmRequest, type context$2_AlarmRequestRequiredFields as AlarmRequestRequiredFields, type context$2_AlarmResponse as AlarmResponse, type context$2_AlarmSnoozed as AlarmSnoozed, type context$2_AlarmSnoozedEnvelope as AlarmSnoozedEnvelope, type context$2_AlarmTriggered as AlarmTriggered, type context$2_AlarmTriggeredEnvelope as AlarmTriggeredEnvelope, type BaseEventMetadata$1 as BaseEventMetadata, type Dispatched$1 as Dispatched, type DomainEvent$2 as DomainEvent, type DomainEventBodyOneOf$2 as DomainEventBodyOneOf, type EchoMessage$1 as EchoMessage, type EntityCreatedEvent$2 as EntityCreatedEvent, type EntityDeletedEvent$2 as EntityDeletedEvent, type EntityUpdatedEvent$2 as EntityUpdatedEvent, type EventMetadata$1 as EventMetadata, type IdentificationData$2 as IdentificationData, type IdentificationDataIdOneOf$2 as IdentificationDataIdOneOf, type MessageEnvelope$2 as MessageEnvelope, type MessageItem$1 as MessageItem, type RestoreInfo$2 as RestoreInfo, type context$2_UpdateAlarm as UpdateAlarm, type context$2_UpdateAlarmRequest as UpdateAlarmRequest, type context$2_UpdateAlarmRequestRequiredFields as UpdateAlarmRequestRequiredFields, type context$2_UpdateAlarmResponse as UpdateAlarmResponse, type context$2_UpdateAlarmResponseNonNullableFields as UpdateAlarmResponseNonNullableFields, WebhookIdentityType$2 as WebhookIdentityType, type context$2__publicOnAlarmDeletedType as _publicOnAlarmDeletedType, type context$2__publicOnAlarmSnoozedType as _publicOnAlarmSnoozedType, type context$2__publicOnAlarmTriggeredType as _publicOnAlarmTriggeredType, context$2_alarm as alarm, context$2_onAlarmDeleted as onAlarmDeleted, context$2_onAlarmSnoozed as onAlarmSnoozed, context$2_onAlarmTriggered as onAlarmTriggered, onAlarmDeleted$1 as publicOnAlarmDeleted, onAlarmSnoozed$1 as publicOnAlarmSnoozed, onAlarmTriggered$1 as publicOnAlarmTriggered, context$2_updateAlarm as updateAlarm };
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
type HostModule$1<T, H extends Host$1> = {
|
|
732
|
+
__type: 'host';
|
|
733
|
+
create(host: H): T;
|
|
734
|
+
};
|
|
735
|
+
type HostModuleAPI$1<T extends HostModule$1<any, any>> = T extends HostModule$1<infer U, any> ? U : never;
|
|
736
|
+
type Host$1<Environment = unknown> = {
|
|
737
|
+
channel: {
|
|
738
|
+
observeState(callback: (props: unknown, environment: Environment) => unknown): {
|
|
739
|
+
disconnect: () => void;
|
|
740
|
+
} | Promise<{
|
|
741
|
+
disconnect: () => void;
|
|
742
|
+
}>;
|
|
743
|
+
};
|
|
744
|
+
environment?: Environment;
|
|
745
|
+
/**
|
|
746
|
+
* Optional bast url to use for API requests, for example `www.wixapis.com`
|
|
747
|
+
*/
|
|
748
|
+
apiBaseUrl?: string;
|
|
749
|
+
/**
|
|
750
|
+
* Possible data to be provided by every host, for cross cutting concerns
|
|
751
|
+
* like internationalization, billing, etc.
|
|
752
|
+
*/
|
|
753
|
+
essentials?: {
|
|
754
|
+
/**
|
|
755
|
+
* The language of the currently viewed session
|
|
756
|
+
*/
|
|
757
|
+
language?: string;
|
|
758
|
+
/**
|
|
759
|
+
* The locale of the currently viewed session
|
|
760
|
+
*/
|
|
761
|
+
locale?: string;
|
|
762
|
+
/**
|
|
763
|
+
* Any headers that should be passed through to the API requests
|
|
764
|
+
*/
|
|
765
|
+
passThroughHeaders?: Record<string, string>;
|
|
766
|
+
};
|
|
767
|
+
};
|
|
768
|
+
|
|
769
|
+
type RESTFunctionDescriptor$1<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient$1) => T;
|
|
770
|
+
interface HttpClient$1 {
|
|
771
|
+
request<TResponse, TData = any>(req: RequestOptionsFactory$1<TResponse, TData>): Promise<HttpResponse$1<TResponse>>;
|
|
772
|
+
fetchWithAuth: typeof fetch;
|
|
773
|
+
wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
|
|
774
|
+
getActiveToken?: () => string | undefined;
|
|
330
775
|
}
|
|
776
|
+
type RequestOptionsFactory$1<TResponse = any, TData = any> = (context: any) => RequestOptions$1<TResponse, TData>;
|
|
777
|
+
type HttpResponse$1<T = any> = {
|
|
778
|
+
data: T;
|
|
779
|
+
status: number;
|
|
780
|
+
statusText: string;
|
|
781
|
+
headers: any;
|
|
782
|
+
request?: any;
|
|
783
|
+
};
|
|
784
|
+
type RequestOptions$1<_TResponse = any, Data = any> = {
|
|
785
|
+
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
786
|
+
url: string;
|
|
787
|
+
data?: Data;
|
|
788
|
+
params?: URLSearchParams;
|
|
789
|
+
} & APIMetadata$1;
|
|
790
|
+
type APIMetadata$1 = {
|
|
791
|
+
methodFqn?: string;
|
|
792
|
+
entityFqdn?: string;
|
|
793
|
+
packageName?: string;
|
|
794
|
+
};
|
|
795
|
+
type BuildRESTFunction$1<T extends RESTFunctionDescriptor$1> = T extends RESTFunctionDescriptor$1<infer U> ? U : never;
|
|
796
|
+
type EventDefinition$2<Payload = unknown, Type extends string = string> = {
|
|
797
|
+
__type: 'event-definition';
|
|
798
|
+
type: Type;
|
|
799
|
+
isDomainEvent?: boolean;
|
|
800
|
+
transformations?: (envelope: unknown) => Payload;
|
|
801
|
+
__payload: Payload;
|
|
802
|
+
};
|
|
803
|
+
declare function EventDefinition$2<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$2<Payload, Type>;
|
|
804
|
+
type EventHandler$2<T extends EventDefinition$2> = (payload: T['__payload']) => void | Promise<void>;
|
|
805
|
+
type BuildEventDefinition$2<T extends EventDefinition$2<any, string>> = (handler: EventHandler$2<T>) => void;
|
|
806
|
+
|
|
807
|
+
type ServicePluginMethodInput$1 = {
|
|
808
|
+
request: any;
|
|
809
|
+
metadata: any;
|
|
810
|
+
};
|
|
811
|
+
type ServicePluginContract$1 = Record<string, (payload: ServicePluginMethodInput$1) => unknown | Promise<unknown>>;
|
|
812
|
+
type ServicePluginMethodMetadata$1 = {
|
|
813
|
+
name: string;
|
|
814
|
+
primaryHttpMappingPath: string;
|
|
815
|
+
transformations: {
|
|
816
|
+
fromREST: (...args: unknown[]) => ServicePluginMethodInput$1;
|
|
817
|
+
toREST: (...args: unknown[]) => unknown;
|
|
818
|
+
};
|
|
819
|
+
};
|
|
820
|
+
type ServicePluginDefinition$1<Contract extends ServicePluginContract$1> = {
|
|
821
|
+
__type: 'service-plugin-definition';
|
|
822
|
+
componentType: string;
|
|
823
|
+
methods: ServicePluginMethodMetadata$1[];
|
|
824
|
+
__contract: Contract;
|
|
825
|
+
};
|
|
826
|
+
declare function ServicePluginDefinition$1<Contract extends ServicePluginContract$1>(componentType: string, methods: ServicePluginMethodMetadata$1[]): ServicePluginDefinition$1<Contract>;
|
|
827
|
+
type BuildServicePluginDefinition$1<T extends ServicePluginDefinition$1<any>> = (implementation: T['__contract']) => void;
|
|
828
|
+
declare const SERVICE_PLUGIN_ERROR_TYPE$1 = "wix_spi_error";
|
|
829
|
+
|
|
830
|
+
type RequestContext$1 = {
|
|
831
|
+
isSSR: boolean;
|
|
832
|
+
host: string;
|
|
833
|
+
protocol?: string;
|
|
834
|
+
};
|
|
835
|
+
type ResponseTransformer$1 = (data: any, headers?: any) => any;
|
|
836
|
+
/**
|
|
837
|
+
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
838
|
+
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
839
|
+
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
840
|
+
*/
|
|
841
|
+
type Method$1 = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
842
|
+
type AmbassadorRequestOptions$1<T = any> = {
|
|
843
|
+
_?: T;
|
|
844
|
+
url?: string;
|
|
845
|
+
method?: Method$1;
|
|
846
|
+
params?: any;
|
|
847
|
+
data?: any;
|
|
848
|
+
transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
|
|
849
|
+
};
|
|
850
|
+
type AmbassadorFactory$1<Request, Response> = (payload: Request) => ((context: RequestContext$1) => AmbassadorRequestOptions$1<Response>) & {
|
|
851
|
+
__isAmbassador: boolean;
|
|
852
|
+
};
|
|
853
|
+
type AmbassadorFunctionDescriptor$1<Request = any, Response = any> = AmbassadorFactory$1<Request, Response>;
|
|
854
|
+
type BuildAmbassadorFunction$1<T extends AmbassadorFunctionDescriptor$1> = T extends AmbassadorFunctionDescriptor$1<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
855
|
+
|
|
856
|
+
declare global {
|
|
857
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
858
|
+
interface SymbolConstructor {
|
|
859
|
+
readonly observable: symbol;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
declare const emptyObjectSymbol$1: unique symbol;
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
867
|
+
|
|
868
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
869
|
+
|
|
870
|
+
@example
|
|
871
|
+
```
|
|
872
|
+
import type {EmptyObject} from 'type-fest';
|
|
873
|
+
|
|
874
|
+
// The following illustrates the problem with `{}`.
|
|
875
|
+
const foo1: {} = {}; // Pass
|
|
876
|
+
const foo2: {} = []; // Pass
|
|
877
|
+
const foo3: {} = 42; // Pass
|
|
878
|
+
const foo4: {} = {a: 1}; // Pass
|
|
879
|
+
|
|
880
|
+
// With `EmptyObject` only the first case is valid.
|
|
881
|
+
const bar1: EmptyObject = {}; // Pass
|
|
882
|
+
const bar2: EmptyObject = 42; // Fail
|
|
883
|
+
const bar3: EmptyObject = []; // Fail
|
|
884
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
885
|
+
```
|
|
886
|
+
|
|
887
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
888
|
+
|
|
889
|
+
@category Object
|
|
890
|
+
*/
|
|
891
|
+
type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
|
|
892
|
+
|
|
893
|
+
/**
|
|
894
|
+
Returns a boolean for whether the two given types are equal.
|
|
895
|
+
|
|
896
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
897
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
898
|
+
|
|
899
|
+
Use-cases:
|
|
900
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
901
|
+
|
|
902
|
+
@example
|
|
903
|
+
```
|
|
904
|
+
import type {IsEqual} from 'type-fest';
|
|
905
|
+
|
|
906
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
907
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
908
|
+
type Includes<Value extends readonly any[], Item> =
|
|
909
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
910
|
+
? IsEqual<Value[0], Item> extends true
|
|
911
|
+
? true
|
|
912
|
+
: Includes<rest, Item>
|
|
913
|
+
: false;
|
|
914
|
+
```
|
|
915
|
+
|
|
916
|
+
@category Type Guard
|
|
917
|
+
@category Utilities
|
|
918
|
+
*/
|
|
919
|
+
type IsEqual$1<A, B> =
|
|
920
|
+
(<G>() => G extends A ? 1 : 2) extends
|
|
921
|
+
(<G>() => G extends B ? 1 : 2)
|
|
922
|
+
? true
|
|
923
|
+
: false;
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
Filter out keys from an object.
|
|
927
|
+
|
|
928
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
929
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
930
|
+
Returns `Key` otherwise.
|
|
931
|
+
|
|
932
|
+
@example
|
|
933
|
+
```
|
|
934
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
935
|
+
//=> never
|
|
936
|
+
```
|
|
937
|
+
|
|
938
|
+
@example
|
|
939
|
+
```
|
|
940
|
+
type Filtered = Filter<'bar', string>;
|
|
941
|
+
//=> never
|
|
942
|
+
```
|
|
943
|
+
|
|
944
|
+
@example
|
|
945
|
+
```
|
|
946
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
947
|
+
//=> 'bar'
|
|
948
|
+
```
|
|
949
|
+
|
|
950
|
+
@see {Except}
|
|
951
|
+
*/
|
|
952
|
+
type Filter$1<KeyType, ExcludeType> = IsEqual$1<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
953
|
+
|
|
954
|
+
type ExceptOptions$1 = {
|
|
955
|
+
/**
|
|
956
|
+
Disallow assigning non-specified properties.
|
|
957
|
+
|
|
958
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
959
|
+
|
|
960
|
+
@default false
|
|
961
|
+
*/
|
|
962
|
+
requireExactProps?: boolean;
|
|
963
|
+
};
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
Create a type from an object type without certain keys.
|
|
967
|
+
|
|
968
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
969
|
+
|
|
970
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
971
|
+
|
|
972
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
973
|
+
|
|
974
|
+
@example
|
|
975
|
+
```
|
|
976
|
+
import type {Except} from 'type-fest';
|
|
977
|
+
|
|
978
|
+
type Foo = {
|
|
979
|
+
a: number;
|
|
980
|
+
b: string;
|
|
981
|
+
};
|
|
982
|
+
|
|
983
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
984
|
+
//=> {b: string}
|
|
985
|
+
|
|
986
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
987
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
988
|
+
|
|
989
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
990
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
991
|
+
|
|
992
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
993
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
994
|
+
```
|
|
995
|
+
|
|
996
|
+
@category Object
|
|
997
|
+
*/
|
|
998
|
+
type Except$1<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions$1 = {requireExactProps: false}> = {
|
|
999
|
+
[KeyType in keyof ObjectType as Filter$1<KeyType, KeysType>]: ObjectType[KeyType];
|
|
1000
|
+
} & (Options['requireExactProps'] extends true
|
|
1001
|
+
? Partial<Record<KeysType, never>>
|
|
1002
|
+
: {});
|
|
1003
|
+
|
|
1004
|
+
/**
|
|
1005
|
+
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
1006
|
+
|
|
1007
|
+
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
|
1008
|
+
|
|
1009
|
+
@example
|
|
1010
|
+
```
|
|
1011
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
1012
|
+
|
|
1013
|
+
interface Example {
|
|
1014
|
+
a: string;
|
|
1015
|
+
b: string | number;
|
|
1016
|
+
c?: string;
|
|
1017
|
+
d: {};
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
type StringKeysOnly = ConditionalKeys<Example, string>;
|
|
1021
|
+
//=> 'a'
|
|
1022
|
+
```
|
|
1023
|
+
|
|
1024
|
+
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
|
1025
|
+
|
|
1026
|
+
@example
|
|
1027
|
+
```
|
|
1028
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
1029
|
+
|
|
1030
|
+
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
1031
|
+
//=> 'a' | 'c'
|
|
1032
|
+
```
|
|
1033
|
+
|
|
1034
|
+
@category Object
|
|
1035
|
+
*/
|
|
1036
|
+
type ConditionalKeys$1<Base, Condition> = NonNullable<
|
|
1037
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
1038
|
+
{
|
|
1039
|
+
// Map through all the keys of the given base type.
|
|
1040
|
+
[Key in keyof Base]:
|
|
1041
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
1042
|
+
Base[Key] extends Condition
|
|
1043
|
+
// Retain this key since the condition passes.
|
|
1044
|
+
? Key
|
|
1045
|
+
// Discard this key since the condition fails.
|
|
1046
|
+
: never;
|
|
1047
|
+
|
|
1048
|
+
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
1049
|
+
}[keyof Base]
|
|
1050
|
+
>;
|
|
1051
|
+
|
|
1052
|
+
/**
|
|
1053
|
+
Exclude keys from a shape that matches the given `Condition`.
|
|
1054
|
+
|
|
1055
|
+
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
|
1056
|
+
|
|
1057
|
+
@example
|
|
1058
|
+
```
|
|
1059
|
+
import type {Primitive, ConditionalExcept} from 'type-fest';
|
|
1060
|
+
|
|
1061
|
+
class Awesome {
|
|
1062
|
+
name: string;
|
|
1063
|
+
successes: number;
|
|
1064
|
+
failures: bigint;
|
|
1065
|
+
|
|
1066
|
+
run() {}
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
|
1070
|
+
//=> {run: () => void}
|
|
1071
|
+
```
|
|
1072
|
+
|
|
1073
|
+
@example
|
|
1074
|
+
```
|
|
1075
|
+
import type {ConditionalExcept} from 'type-fest';
|
|
1076
|
+
|
|
1077
|
+
interface Example {
|
|
1078
|
+
a: string;
|
|
1079
|
+
b: string | number;
|
|
1080
|
+
c: () => void;
|
|
1081
|
+
d: {};
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
1085
|
+
//=> {b: string | number; c: () => void; d: {}}
|
|
1086
|
+
```
|
|
1087
|
+
|
|
1088
|
+
@category Object
|
|
1089
|
+
*/
|
|
1090
|
+
type ConditionalExcept$1<Base, Condition> = Except$1<
|
|
1091
|
+
Base,
|
|
1092
|
+
ConditionalKeys$1<Base, Condition>
|
|
1093
|
+
>;
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* Descriptors are objects that describe the API of a module, and the module
|
|
1097
|
+
* can either be a REST module or a host module.
|
|
1098
|
+
* This type is recursive, so it can describe nested modules.
|
|
1099
|
+
*/
|
|
1100
|
+
type Descriptors$1 = RESTFunctionDescriptor$1 | AmbassadorFunctionDescriptor$1 | HostModule$1<any, any> | EventDefinition$2<any> | ServicePluginDefinition$1<any> | {
|
|
1101
|
+
[key: string]: Descriptors$1 | PublicMetadata$1 | any;
|
|
1102
|
+
};
|
|
1103
|
+
/**
|
|
1104
|
+
* This type takes in a descriptors object of a certain Host (including an `unknown` host)
|
|
1105
|
+
* and returns an object with the same structure, but with all descriptors replaced with their API.
|
|
1106
|
+
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
1107
|
+
* do not match the given host (as they will not work with the given host).
|
|
1108
|
+
*/
|
|
1109
|
+
type BuildDescriptors$1<T extends Descriptors$1, H extends Host$1<any> | undefined, Depth extends number = 5> = {
|
|
1110
|
+
done: T;
|
|
1111
|
+
recurse: T extends {
|
|
1112
|
+
__type: typeof SERVICE_PLUGIN_ERROR_TYPE$1;
|
|
1113
|
+
} ? never : T extends AmbassadorFunctionDescriptor$1 ? BuildAmbassadorFunction$1<T> : T extends RESTFunctionDescriptor$1 ? BuildRESTFunction$1<T> : T extends EventDefinition$2<any> ? BuildEventDefinition$2<T> : T extends ServicePluginDefinition$1<any> ? BuildServicePluginDefinition$1<T> : T extends HostModule$1<any, any> ? HostModuleAPI$1<T> : ConditionalExcept$1<{
|
|
1114
|
+
[Key in keyof T]: T[Key] extends Descriptors$1 ? BuildDescriptors$1<T[Key], H, [
|
|
1115
|
+
-1,
|
|
1116
|
+
0,
|
|
1117
|
+
1,
|
|
1118
|
+
2,
|
|
1119
|
+
3,
|
|
1120
|
+
4,
|
|
1121
|
+
5
|
|
1122
|
+
][Depth]> : never;
|
|
1123
|
+
}, EmptyObject$1>;
|
|
1124
|
+
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
1125
|
+
type PublicMetadata$1 = {
|
|
1126
|
+
PACKAGE_NAME?: string;
|
|
1127
|
+
};
|
|
1128
|
+
|
|
1129
|
+
declare global {
|
|
1130
|
+
interface ContextualClient {
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
/**
|
|
1134
|
+
* A type used to create concerete types from SDK descriptors in
|
|
1135
|
+
* case a contextual client is available.
|
|
1136
|
+
*/
|
|
1137
|
+
type MaybeContext$1<T extends Descriptors$1> = globalThis.ContextualClient extends {
|
|
1138
|
+
host: Host$1;
|
|
1139
|
+
} ? BuildDescriptors$1<T, globalThis.ContextualClient['host']> : T;
|
|
331
1140
|
|
|
332
1141
|
interface MessageItem {
|
|
333
1142
|
/** inner_message comment from EchoMessage proto def */
|
|
@@ -541,7 +1350,7 @@ interface EchoOptions {
|
|
|
541
1350
|
someDate?: Date;
|
|
542
1351
|
}
|
|
543
1352
|
|
|
544
|
-
declare function echo$1(httpClient: HttpClient): EchoSignature;
|
|
1353
|
+
declare function echo$1(httpClient: HttpClient$1): EchoSignature;
|
|
545
1354
|
interface EchoSignature {
|
|
546
1355
|
/**
|
|
547
1356
|
* echo given arg1 and arg2
|
|
@@ -551,11 +1360,29 @@ interface EchoSignature {
|
|
|
551
1360
|
*/
|
|
552
1361
|
(arg1: string, options?: EchoOptions | undefined): Promise<string>;
|
|
553
1362
|
}
|
|
554
|
-
declare const onEchoDispatched$1: EventDefinition<EchoDispatchedEnvelope, "wix.metroinspector.v1.echo_dispatched">;
|
|
1363
|
+
declare const onEchoDispatched$1: EventDefinition$2<EchoDispatchedEnvelope, "wix.metroinspector.v1.echo_dispatched">;
|
|
555
1364
|
|
|
556
|
-
|
|
1365
|
+
type EventDefinition$1<Payload = unknown, Type extends string = string> = {
|
|
1366
|
+
__type: 'event-definition';
|
|
1367
|
+
type: Type;
|
|
1368
|
+
isDomainEvent?: boolean;
|
|
1369
|
+
transformations?: (envelope: unknown) => Payload;
|
|
1370
|
+
__payload: Payload;
|
|
1371
|
+
};
|
|
1372
|
+
declare function EventDefinition$1<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$1<Payload, Type>;
|
|
1373
|
+
type EventHandler$1<T extends EventDefinition$1> = (payload: T['__payload']) => void | Promise<void>;
|
|
1374
|
+
type BuildEventDefinition$1<T extends EventDefinition$1<any, string>> = (handler: EventHandler$1<T>) => void;
|
|
1375
|
+
|
|
1376
|
+
declare global {
|
|
1377
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
1378
|
+
interface SymbolConstructor {
|
|
1379
|
+
readonly observable: symbol;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
557
1382
|
|
|
558
|
-
declare
|
|
1383
|
+
declare function createEventModule<T extends EventDefinition$1<any, string>>(eventDefinition: T): BuildEventDefinition$1<T> & T;
|
|
1384
|
+
|
|
1385
|
+
declare const echo: MaybeContext$1<BuildRESTFunction$1<typeof echo$1> & typeof echo$1>;
|
|
559
1386
|
|
|
560
1387
|
type _publicOnEchoDispatchedType = typeof onEchoDispatched$1;
|
|
561
1388
|
/**
|
|
@@ -581,6 +1408,416 @@ declare namespace context$1 {
|
|
|
581
1408
|
export { type ActionEvent$1 as ActionEvent, type context$1_BaseEventMetadata as BaseEventMetadata, type context$1_Dispatched as Dispatched, type DomainEvent$1 as DomainEvent, type DomainEventBodyOneOf$1 as DomainEventBodyOneOf, type context$1_EchoDispatchedEnvelope as EchoDispatchedEnvelope, type context$1_EchoMessage as EchoMessage, type context$1_EchoOptions as EchoOptions, type context$1_EchoRequest as EchoRequest, type context$1_EchoRequestRequiredFields as EchoRequestRequiredFields, type context$1_EchoResponse as EchoResponse, type context$1_EchoResponseNonNullableFields as EchoResponseNonNullableFields, type EntityCreatedEvent$1 as EntityCreatedEvent, type EntityDeletedEvent$1 as EntityDeletedEvent, type EntityUpdatedEvent$1 as EntityUpdatedEvent, type context$1_EventMetadata as EventMetadata, type IdentificationData$1 as IdentificationData, type IdentificationDataIdOneOf$1 as IdentificationDataIdOneOf, type MessageEnvelope$1 as MessageEnvelope, type context$1_MessageItem as MessageItem, type RestoreInfo$1 as RestoreInfo, WebhookIdentityType$1 as WebhookIdentityType, type context$1__publicOnEchoDispatchedType as _publicOnEchoDispatchedType, context$1_echo as echo, context$1_onEchoDispatched as onEchoDispatched, onEchoDispatched$1 as publicOnEchoDispatched };
|
|
582
1409
|
}
|
|
583
1410
|
|
|
1411
|
+
type HostModule<T, H extends Host> = {
|
|
1412
|
+
__type: 'host';
|
|
1413
|
+
create(host: H): T;
|
|
1414
|
+
};
|
|
1415
|
+
type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
|
|
1416
|
+
type Host<Environment = unknown> = {
|
|
1417
|
+
channel: {
|
|
1418
|
+
observeState(callback: (props: unknown, environment: Environment) => unknown): {
|
|
1419
|
+
disconnect: () => void;
|
|
1420
|
+
} | Promise<{
|
|
1421
|
+
disconnect: () => void;
|
|
1422
|
+
}>;
|
|
1423
|
+
};
|
|
1424
|
+
environment?: Environment;
|
|
1425
|
+
/**
|
|
1426
|
+
* Optional bast url to use for API requests, for example `www.wixapis.com`
|
|
1427
|
+
*/
|
|
1428
|
+
apiBaseUrl?: string;
|
|
1429
|
+
/**
|
|
1430
|
+
* Possible data to be provided by every host, for cross cutting concerns
|
|
1431
|
+
* like internationalization, billing, etc.
|
|
1432
|
+
*/
|
|
1433
|
+
essentials?: {
|
|
1434
|
+
/**
|
|
1435
|
+
* The language of the currently viewed session
|
|
1436
|
+
*/
|
|
1437
|
+
language?: string;
|
|
1438
|
+
/**
|
|
1439
|
+
* The locale of the currently viewed session
|
|
1440
|
+
*/
|
|
1441
|
+
locale?: string;
|
|
1442
|
+
/**
|
|
1443
|
+
* Any headers that should be passed through to the API requests
|
|
1444
|
+
*/
|
|
1445
|
+
passThroughHeaders?: Record<string, string>;
|
|
1446
|
+
};
|
|
1447
|
+
};
|
|
1448
|
+
|
|
1449
|
+
type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
|
|
1450
|
+
interface HttpClient {
|
|
1451
|
+
request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
|
|
1452
|
+
fetchWithAuth: typeof fetch;
|
|
1453
|
+
wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
|
|
1454
|
+
getActiveToken?: () => string | undefined;
|
|
1455
|
+
}
|
|
1456
|
+
type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
|
|
1457
|
+
type HttpResponse<T = any> = {
|
|
1458
|
+
data: T;
|
|
1459
|
+
status: number;
|
|
1460
|
+
statusText: string;
|
|
1461
|
+
headers: any;
|
|
1462
|
+
request?: any;
|
|
1463
|
+
};
|
|
1464
|
+
type RequestOptions<_TResponse = any, Data = any> = {
|
|
1465
|
+
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
1466
|
+
url: string;
|
|
1467
|
+
data?: Data;
|
|
1468
|
+
params?: URLSearchParams;
|
|
1469
|
+
} & APIMetadata;
|
|
1470
|
+
type APIMetadata = {
|
|
1471
|
+
methodFqn?: string;
|
|
1472
|
+
entityFqdn?: string;
|
|
1473
|
+
packageName?: string;
|
|
1474
|
+
};
|
|
1475
|
+
type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
|
|
1476
|
+
type EventDefinition<Payload = unknown, Type extends string = string> = {
|
|
1477
|
+
__type: 'event-definition';
|
|
1478
|
+
type: Type;
|
|
1479
|
+
isDomainEvent?: boolean;
|
|
1480
|
+
transformations?: (envelope: unknown) => Payload;
|
|
1481
|
+
__payload: Payload;
|
|
1482
|
+
};
|
|
1483
|
+
declare function EventDefinition<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition<Payload, Type>;
|
|
1484
|
+
type EventHandler<T extends EventDefinition> = (payload: T['__payload']) => void | Promise<void>;
|
|
1485
|
+
type BuildEventDefinition<T extends EventDefinition<any, string>> = (handler: EventHandler<T>) => void;
|
|
1486
|
+
|
|
1487
|
+
type ServicePluginMethodInput = {
|
|
1488
|
+
request: any;
|
|
1489
|
+
metadata: any;
|
|
1490
|
+
};
|
|
1491
|
+
type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
|
|
1492
|
+
type ServicePluginMethodMetadata = {
|
|
1493
|
+
name: string;
|
|
1494
|
+
primaryHttpMappingPath: string;
|
|
1495
|
+
transformations: {
|
|
1496
|
+
fromREST: (...args: unknown[]) => ServicePluginMethodInput;
|
|
1497
|
+
toREST: (...args: unknown[]) => unknown;
|
|
1498
|
+
};
|
|
1499
|
+
};
|
|
1500
|
+
type ServicePluginDefinition<Contract extends ServicePluginContract> = {
|
|
1501
|
+
__type: 'service-plugin-definition';
|
|
1502
|
+
componentType: string;
|
|
1503
|
+
methods: ServicePluginMethodMetadata[];
|
|
1504
|
+
__contract: Contract;
|
|
1505
|
+
};
|
|
1506
|
+
declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
|
|
1507
|
+
type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
|
|
1508
|
+
declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
|
|
1509
|
+
|
|
1510
|
+
type RequestContext = {
|
|
1511
|
+
isSSR: boolean;
|
|
1512
|
+
host: string;
|
|
1513
|
+
protocol?: string;
|
|
1514
|
+
};
|
|
1515
|
+
type ResponseTransformer = (data: any, headers?: any) => any;
|
|
1516
|
+
/**
|
|
1517
|
+
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
1518
|
+
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
1519
|
+
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
1520
|
+
*/
|
|
1521
|
+
type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
1522
|
+
type AmbassadorRequestOptions<T = any> = {
|
|
1523
|
+
_?: T;
|
|
1524
|
+
url?: string;
|
|
1525
|
+
method?: Method;
|
|
1526
|
+
params?: any;
|
|
1527
|
+
data?: any;
|
|
1528
|
+
transformResponse?: ResponseTransformer | ResponseTransformer[];
|
|
1529
|
+
};
|
|
1530
|
+
type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
|
|
1531
|
+
__isAmbassador: boolean;
|
|
1532
|
+
};
|
|
1533
|
+
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
1534
|
+
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
1535
|
+
|
|
1536
|
+
declare global {
|
|
1537
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
1538
|
+
interface SymbolConstructor {
|
|
1539
|
+
readonly observable: symbol;
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
1544
|
+
|
|
1545
|
+
/**
|
|
1546
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
1547
|
+
|
|
1548
|
+
When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)).
|
|
1549
|
+
|
|
1550
|
+
@example
|
|
1551
|
+
```
|
|
1552
|
+
import type {EmptyObject} from 'type-fest';
|
|
1553
|
+
|
|
1554
|
+
// The following illustrates the problem with `{}`.
|
|
1555
|
+
const foo1: {} = {}; // Pass
|
|
1556
|
+
const foo2: {} = []; // Pass
|
|
1557
|
+
const foo3: {} = 42; // Pass
|
|
1558
|
+
const foo4: {} = {a: 1}; // Pass
|
|
1559
|
+
|
|
1560
|
+
// With `EmptyObject` only the first case is valid.
|
|
1561
|
+
const bar1: EmptyObject = {}; // Pass
|
|
1562
|
+
const bar2: EmptyObject = 42; // Fail
|
|
1563
|
+
const bar3: EmptyObject = []; // Fail
|
|
1564
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
1565
|
+
```
|
|
1566
|
+
|
|
1567
|
+
Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<never, never>` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}.
|
|
1568
|
+
|
|
1569
|
+
@category Object
|
|
1570
|
+
*/
|
|
1571
|
+
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
1572
|
+
|
|
1573
|
+
/**
|
|
1574
|
+
Returns a boolean for whether the two given types are equal.
|
|
1575
|
+
|
|
1576
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
1577
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
1578
|
+
|
|
1579
|
+
Use-cases:
|
|
1580
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
1581
|
+
|
|
1582
|
+
@example
|
|
1583
|
+
```
|
|
1584
|
+
import type {IsEqual} from 'type-fest';
|
|
1585
|
+
|
|
1586
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
1587
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
1588
|
+
type Includes<Value extends readonly any[], Item> =
|
|
1589
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
1590
|
+
? IsEqual<Value[0], Item> extends true
|
|
1591
|
+
? true
|
|
1592
|
+
: Includes<rest, Item>
|
|
1593
|
+
: false;
|
|
1594
|
+
```
|
|
1595
|
+
|
|
1596
|
+
@category Type Guard
|
|
1597
|
+
@category Utilities
|
|
1598
|
+
*/
|
|
1599
|
+
type IsEqual<A, B> =
|
|
1600
|
+
(<G>() => G extends A ? 1 : 2) extends
|
|
1601
|
+
(<G>() => G extends B ? 1 : 2)
|
|
1602
|
+
? true
|
|
1603
|
+
: false;
|
|
1604
|
+
|
|
1605
|
+
/**
|
|
1606
|
+
Filter out keys from an object.
|
|
1607
|
+
|
|
1608
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
1609
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
1610
|
+
Returns `Key` otherwise.
|
|
1611
|
+
|
|
1612
|
+
@example
|
|
1613
|
+
```
|
|
1614
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
1615
|
+
//=> never
|
|
1616
|
+
```
|
|
1617
|
+
|
|
1618
|
+
@example
|
|
1619
|
+
```
|
|
1620
|
+
type Filtered = Filter<'bar', string>;
|
|
1621
|
+
//=> never
|
|
1622
|
+
```
|
|
1623
|
+
|
|
1624
|
+
@example
|
|
1625
|
+
```
|
|
1626
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
1627
|
+
//=> 'bar'
|
|
1628
|
+
```
|
|
1629
|
+
|
|
1630
|
+
@see {Except}
|
|
1631
|
+
*/
|
|
1632
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
1633
|
+
|
|
1634
|
+
type ExceptOptions = {
|
|
1635
|
+
/**
|
|
1636
|
+
Disallow assigning non-specified properties.
|
|
1637
|
+
|
|
1638
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
1639
|
+
|
|
1640
|
+
@default false
|
|
1641
|
+
*/
|
|
1642
|
+
requireExactProps?: boolean;
|
|
1643
|
+
};
|
|
1644
|
+
|
|
1645
|
+
/**
|
|
1646
|
+
Create a type from an object type without certain keys.
|
|
1647
|
+
|
|
1648
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
1649
|
+
|
|
1650
|
+
This type is a stricter version of [`Omit`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-5.html#the-omit-helper-type). The `Omit` type does not restrict the omitted keys to be keys present on the given type, while `Except` does. The benefits of a stricter type are avoiding typos and allowing the compiler to pick up on rename refactors automatically.
|
|
1651
|
+
|
|
1652
|
+
This type was proposed to the TypeScript team, which declined it, saying they prefer that libraries implement stricter versions of the built-in types ([microsoft/TypeScript#30825](https://github.com/microsoft/TypeScript/issues/30825#issuecomment-523668235)).
|
|
1653
|
+
|
|
1654
|
+
@example
|
|
1655
|
+
```
|
|
1656
|
+
import type {Except} from 'type-fest';
|
|
1657
|
+
|
|
1658
|
+
type Foo = {
|
|
1659
|
+
a: number;
|
|
1660
|
+
b: string;
|
|
1661
|
+
};
|
|
1662
|
+
|
|
1663
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
1664
|
+
//=> {b: string}
|
|
1665
|
+
|
|
1666
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
1667
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
1668
|
+
|
|
1669
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
1670
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
1671
|
+
|
|
1672
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
1673
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
1674
|
+
```
|
|
1675
|
+
|
|
1676
|
+
@category Object
|
|
1677
|
+
*/
|
|
1678
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
|
|
1679
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
1680
|
+
} & (Options['requireExactProps'] extends true
|
|
1681
|
+
? Partial<Record<KeysType, never>>
|
|
1682
|
+
: {});
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
1686
|
+
|
|
1687
|
+
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
|
1688
|
+
|
|
1689
|
+
@example
|
|
1690
|
+
```
|
|
1691
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
1692
|
+
|
|
1693
|
+
interface Example {
|
|
1694
|
+
a: string;
|
|
1695
|
+
b: string | number;
|
|
1696
|
+
c?: string;
|
|
1697
|
+
d: {};
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
type StringKeysOnly = ConditionalKeys<Example, string>;
|
|
1701
|
+
//=> 'a'
|
|
1702
|
+
```
|
|
1703
|
+
|
|
1704
|
+
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
|
1705
|
+
|
|
1706
|
+
@example
|
|
1707
|
+
```
|
|
1708
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
1709
|
+
|
|
1710
|
+
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
1711
|
+
//=> 'a' | 'c'
|
|
1712
|
+
```
|
|
1713
|
+
|
|
1714
|
+
@category Object
|
|
1715
|
+
*/
|
|
1716
|
+
type ConditionalKeys<Base, Condition> = NonNullable<
|
|
1717
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
1718
|
+
{
|
|
1719
|
+
// Map through all the keys of the given base type.
|
|
1720
|
+
[Key in keyof Base]:
|
|
1721
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
1722
|
+
Base[Key] extends Condition
|
|
1723
|
+
// Retain this key since the condition passes.
|
|
1724
|
+
? Key
|
|
1725
|
+
// Discard this key since the condition fails.
|
|
1726
|
+
: never;
|
|
1727
|
+
|
|
1728
|
+
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
1729
|
+
}[keyof Base]
|
|
1730
|
+
>;
|
|
1731
|
+
|
|
1732
|
+
/**
|
|
1733
|
+
Exclude keys from a shape that matches the given `Condition`.
|
|
1734
|
+
|
|
1735
|
+
This is useful when you want to create a new type with a specific set of keys from a shape. For example, you might want to exclude all the primitive properties from a class and form a new shape containing everything but the primitive properties.
|
|
1736
|
+
|
|
1737
|
+
@example
|
|
1738
|
+
```
|
|
1739
|
+
import type {Primitive, ConditionalExcept} from 'type-fest';
|
|
1740
|
+
|
|
1741
|
+
class Awesome {
|
|
1742
|
+
name: string;
|
|
1743
|
+
successes: number;
|
|
1744
|
+
failures: bigint;
|
|
1745
|
+
|
|
1746
|
+
run() {}
|
|
1747
|
+
}
|
|
1748
|
+
|
|
1749
|
+
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
|
1750
|
+
//=> {run: () => void}
|
|
1751
|
+
```
|
|
1752
|
+
|
|
1753
|
+
@example
|
|
1754
|
+
```
|
|
1755
|
+
import type {ConditionalExcept} from 'type-fest';
|
|
1756
|
+
|
|
1757
|
+
interface Example {
|
|
1758
|
+
a: string;
|
|
1759
|
+
b: string | number;
|
|
1760
|
+
c: () => void;
|
|
1761
|
+
d: {};
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
1765
|
+
//=> {b: string | number; c: () => void; d: {}}
|
|
1766
|
+
```
|
|
1767
|
+
|
|
1768
|
+
@category Object
|
|
1769
|
+
*/
|
|
1770
|
+
type ConditionalExcept<Base, Condition> = Except<
|
|
1771
|
+
Base,
|
|
1772
|
+
ConditionalKeys<Base, Condition>
|
|
1773
|
+
>;
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* Descriptors are objects that describe the API of a module, and the module
|
|
1777
|
+
* can either be a REST module or a host module.
|
|
1778
|
+
* This type is recursive, so it can describe nested modules.
|
|
1779
|
+
*/
|
|
1780
|
+
type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
|
|
1781
|
+
[key: string]: Descriptors | PublicMetadata | any;
|
|
1782
|
+
};
|
|
1783
|
+
/**
|
|
1784
|
+
* This type takes in a descriptors object of a certain Host (including an `unknown` host)
|
|
1785
|
+
* and returns an object with the same structure, but with all descriptors replaced with their API.
|
|
1786
|
+
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
1787
|
+
* do not match the given host (as they will not work with the given host).
|
|
1788
|
+
*/
|
|
1789
|
+
type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
|
|
1790
|
+
done: T;
|
|
1791
|
+
recurse: T extends {
|
|
1792
|
+
__type: typeof SERVICE_PLUGIN_ERROR_TYPE;
|
|
1793
|
+
} ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition<any> ? BuildEventDefinition<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
1794
|
+
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
|
|
1795
|
+
-1,
|
|
1796
|
+
0,
|
|
1797
|
+
1,
|
|
1798
|
+
2,
|
|
1799
|
+
3,
|
|
1800
|
+
4,
|
|
1801
|
+
5
|
|
1802
|
+
][Depth]> : never;
|
|
1803
|
+
}, EmptyObject>;
|
|
1804
|
+
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
1805
|
+
type PublicMetadata = {
|
|
1806
|
+
PACKAGE_NAME?: string;
|
|
1807
|
+
};
|
|
1808
|
+
|
|
1809
|
+
declare global {
|
|
1810
|
+
interface ContextualClient {
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
/**
|
|
1814
|
+
* A type used to create concerete types from SDK descriptors in
|
|
1815
|
+
* case a contextual client is available.
|
|
1816
|
+
*/
|
|
1817
|
+
type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
|
|
1818
|
+
host: Host;
|
|
1819
|
+
} ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
|
|
1820
|
+
|
|
584
1821
|
/** Physical address */
|
|
585
1822
|
interface Address extends AddressStreetOneOf {
|
|
586
1823
|
/** Street name and number. */
|
|
@@ -1276,15 +2513,15 @@ interface BulkDeleteProductsSignature {
|
|
|
1276
2513
|
(productIds: string[]): Promise<BulkDeleteProductsResponse & BulkDeleteProductsResponseNonNullableFields>;
|
|
1277
2514
|
}
|
|
1278
2515
|
|
|
1279
|
-
declare const createProduct: BuildRESTFunction<typeof createProduct$1> & typeof createProduct$1
|
|
1280
|
-
declare const deleteProduct: BuildRESTFunction<typeof deleteProduct$1> & typeof deleteProduct$1
|
|
1281
|
-
declare const updateProduct: BuildRESTFunction<typeof updateProduct$1> & typeof updateProduct$1
|
|
1282
|
-
declare const getProduct: BuildRESTFunction<typeof getProduct$1> & typeof getProduct$1
|
|
1283
|
-
declare const getProductsStartWith: BuildRESTFunction<typeof getProductsStartWith$1> & typeof getProductsStartWith$1
|
|
1284
|
-
declare const queryProducts: BuildRESTFunction<typeof queryProducts$1> & typeof queryProducts$1
|
|
1285
|
-
declare const bulkCreateProducts: BuildRESTFunction<typeof bulkCreateProducts$1> & typeof bulkCreateProducts$1
|
|
1286
|
-
declare const bulkUpdateProducts: BuildRESTFunction<typeof bulkUpdateProducts$1> & typeof bulkUpdateProducts$1
|
|
1287
|
-
declare const bulkDeleteProducts: BuildRESTFunction<typeof bulkDeleteProducts$1> & typeof bulkDeleteProducts$1
|
|
2516
|
+
declare const createProduct: MaybeContext<BuildRESTFunction<typeof createProduct$1> & typeof createProduct$1>;
|
|
2517
|
+
declare const deleteProduct: MaybeContext<BuildRESTFunction<typeof deleteProduct$1> & typeof deleteProduct$1>;
|
|
2518
|
+
declare const updateProduct: MaybeContext<BuildRESTFunction<typeof updateProduct$1> & typeof updateProduct$1>;
|
|
2519
|
+
declare const getProduct: MaybeContext<BuildRESTFunction<typeof getProduct$1> & typeof getProduct$1>;
|
|
2520
|
+
declare const getProductsStartWith: MaybeContext<BuildRESTFunction<typeof getProductsStartWith$1> & typeof getProductsStartWith$1>;
|
|
2521
|
+
declare const queryProducts: MaybeContext<BuildRESTFunction<typeof queryProducts$1> & typeof queryProducts$1>;
|
|
2522
|
+
declare const bulkCreateProducts: MaybeContext<BuildRESTFunction<typeof bulkCreateProducts$1> & typeof bulkCreateProducts$1>;
|
|
2523
|
+
declare const bulkUpdateProducts: MaybeContext<BuildRESTFunction<typeof bulkUpdateProducts$1> & typeof bulkUpdateProducts$1>;
|
|
2524
|
+
declare const bulkDeleteProducts: MaybeContext<BuildRESTFunction<typeof bulkDeleteProducts$1> & typeof bulkDeleteProducts$1>;
|
|
1288
2525
|
|
|
1289
2526
|
type context_ActionEvent = ActionEvent;
|
|
1290
2527
|
type context_Address = Address;
|