@wix/echo 1.0.40 → 1.0.42
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 -2
- package/type-bundles/context.bundle.d.ts +467 -57
- package/type-bundles/index.bundle.d.ts +467 -57
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
type HostModule<T, H extends Host> = {
|
|
1
|
+
type HostModule$1<T, H extends Host$1> = {
|
|
2
2
|
__type: 'host';
|
|
3
3
|
create(host: H): T;
|
|
4
4
|
};
|
|
5
|
-
type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
|
|
6
|
-
type Host<Environment = unknown> = {
|
|
5
|
+
type HostModuleAPI$1<T extends HostModule$1<any, any>> = T extends HostModule$1<infer U, any> ? U : never;
|
|
6
|
+
type Host$1<Environment = unknown> = {
|
|
7
7
|
channel: {
|
|
8
8
|
observeState(callback: (props: unknown, environment: Environment) => unknown): {
|
|
9
9
|
disconnect: () => void;
|
|
@@ -36,92 +36,92 @@ type Host<Environment = unknown> = {
|
|
|
36
36
|
};
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
|
|
40
|
-
interface HttpClient {
|
|
41
|
-
request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
|
|
39
|
+
type RESTFunctionDescriptor$1<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient$1) => T;
|
|
40
|
+
interface HttpClient$1 {
|
|
41
|
+
request<TResponse, TData = any>(req: RequestOptionsFactory$1<TResponse, TData>): Promise<HttpResponse$1<TResponse>>;
|
|
42
42
|
fetchWithAuth: typeof fetch;
|
|
43
43
|
wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
|
|
44
44
|
getActiveToken?: () => string | undefined;
|
|
45
45
|
}
|
|
46
|
-
type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
|
|
47
|
-
type HttpResponse<T = any> = {
|
|
46
|
+
type RequestOptionsFactory$1<TResponse = any, TData = any> = (context: any) => RequestOptions$1<TResponse, TData>;
|
|
47
|
+
type HttpResponse$1<T = any> = {
|
|
48
48
|
data: T;
|
|
49
49
|
status: number;
|
|
50
50
|
statusText: string;
|
|
51
51
|
headers: any;
|
|
52
52
|
request?: any;
|
|
53
53
|
};
|
|
54
|
-
type RequestOptions<_TResponse = any, Data = any> = {
|
|
54
|
+
type RequestOptions$1<_TResponse = any, Data = any> = {
|
|
55
55
|
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
56
56
|
url: string;
|
|
57
57
|
data?: Data;
|
|
58
58
|
params?: URLSearchParams;
|
|
59
|
-
} & APIMetadata;
|
|
60
|
-
type APIMetadata = {
|
|
59
|
+
} & APIMetadata$1;
|
|
60
|
+
type APIMetadata$1 = {
|
|
61
61
|
methodFqn?: string;
|
|
62
62
|
entityFqdn?: string;
|
|
63
63
|
packageName?: string;
|
|
64
64
|
};
|
|
65
|
-
type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
|
|
66
|
-
type EventDefinition$
|
|
65
|
+
type BuildRESTFunction$1<T extends RESTFunctionDescriptor$1> = T extends RESTFunctionDescriptor$1<infer U> ? U : never;
|
|
66
|
+
type EventDefinition$2<Payload = unknown, Type extends string = string> = {
|
|
67
67
|
__type: 'event-definition';
|
|
68
68
|
type: Type;
|
|
69
69
|
isDomainEvent?: boolean;
|
|
70
70
|
transformations?: (envelope: unknown) => Payload;
|
|
71
71
|
__payload: Payload;
|
|
72
72
|
};
|
|
73
|
-
declare function EventDefinition$
|
|
74
|
-
type EventHandler$
|
|
75
|
-
type BuildEventDefinition$
|
|
73
|
+
declare function EventDefinition$2<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$2<Payload, Type>;
|
|
74
|
+
type EventHandler$2<T extends EventDefinition$2> = (payload: T['__payload']) => void | Promise<void>;
|
|
75
|
+
type BuildEventDefinition$2<T extends EventDefinition$2<any, string>> = (handler: EventHandler$2<T>) => void;
|
|
76
76
|
|
|
77
|
-
type ServicePluginMethodInput = {
|
|
77
|
+
type ServicePluginMethodInput$1 = {
|
|
78
78
|
request: any;
|
|
79
79
|
metadata: any;
|
|
80
80
|
};
|
|
81
|
-
type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
|
|
82
|
-
type ServicePluginMethodMetadata = {
|
|
81
|
+
type ServicePluginContract$1 = Record<string, (payload: ServicePluginMethodInput$1) => unknown | Promise<unknown>>;
|
|
82
|
+
type ServicePluginMethodMetadata$1 = {
|
|
83
83
|
name: string;
|
|
84
84
|
primaryHttpMappingPath: string;
|
|
85
85
|
transformations: {
|
|
86
|
-
fromREST: (...args: unknown[]) => ServicePluginMethodInput;
|
|
86
|
+
fromREST: (...args: unknown[]) => ServicePluginMethodInput$1;
|
|
87
87
|
toREST: (...args: unknown[]) => unknown;
|
|
88
88
|
};
|
|
89
89
|
};
|
|
90
|
-
type ServicePluginDefinition<Contract extends ServicePluginContract> = {
|
|
90
|
+
type ServicePluginDefinition$1<Contract extends ServicePluginContract$1> = {
|
|
91
91
|
__type: 'service-plugin-definition';
|
|
92
92
|
componentType: string;
|
|
93
|
-
methods: ServicePluginMethodMetadata[];
|
|
93
|
+
methods: ServicePluginMethodMetadata$1[];
|
|
94
94
|
__contract: Contract;
|
|
95
95
|
};
|
|
96
|
-
declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
|
|
97
|
-
type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
|
|
98
|
-
declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
|
|
96
|
+
declare function ServicePluginDefinition$1<Contract extends ServicePluginContract$1>(componentType: string, methods: ServicePluginMethodMetadata$1[]): ServicePluginDefinition$1<Contract>;
|
|
97
|
+
type BuildServicePluginDefinition$1<T extends ServicePluginDefinition$1<any>> = (implementation: T['__contract']) => void;
|
|
98
|
+
declare const SERVICE_PLUGIN_ERROR_TYPE$1 = "wix_spi_error";
|
|
99
99
|
|
|
100
|
-
type RequestContext = {
|
|
100
|
+
type RequestContext$1 = {
|
|
101
101
|
isSSR: boolean;
|
|
102
102
|
host: string;
|
|
103
103
|
protocol?: string;
|
|
104
104
|
};
|
|
105
|
-
type ResponseTransformer = (data: any, headers?: any) => any;
|
|
105
|
+
type ResponseTransformer$1 = (data: any, headers?: any) => any;
|
|
106
106
|
/**
|
|
107
107
|
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
108
108
|
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
109
109
|
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
110
110
|
*/
|
|
111
|
-
type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
112
|
-
type AmbassadorRequestOptions<T = any> = {
|
|
111
|
+
type Method$1 = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
112
|
+
type AmbassadorRequestOptions$1<T = any> = {
|
|
113
113
|
_?: T;
|
|
114
114
|
url?: string;
|
|
115
|
-
method?: Method;
|
|
115
|
+
method?: Method$1;
|
|
116
116
|
params?: any;
|
|
117
117
|
data?: any;
|
|
118
|
-
transformResponse?: ResponseTransformer | ResponseTransformer[];
|
|
118
|
+
transformResponse?: ResponseTransformer$1 | ResponseTransformer$1[];
|
|
119
119
|
};
|
|
120
|
-
type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
|
|
120
|
+
type AmbassadorFactory$1<Request, Response> = (payload: Request) => ((context: RequestContext$1) => AmbassadorRequestOptions$1<Response>) & {
|
|
121
121
|
__isAmbassador: boolean;
|
|
122
122
|
};
|
|
123
|
-
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
124
|
-
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
123
|
+
type AmbassadorFunctionDescriptor$1<Request = any, Response = any> = AmbassadorFactory$1<Request, Response>;
|
|
124
|
+
type BuildAmbassadorFunction$1<T extends AmbassadorFunctionDescriptor$1> = T extends AmbassadorFunctionDescriptor$1<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
125
125
|
|
|
126
126
|
declare global {
|
|
127
127
|
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
@@ -130,7 +130,7 @@ declare global {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
declare const emptyObjectSymbol: unique symbol;
|
|
133
|
+
declare const emptyObjectSymbol$1: unique symbol;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
Represents a strictly empty plain object, the `{}` value.
|
|
@@ -158,7 +158,7 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
|
|
|
158
158
|
|
|
159
159
|
@category Object
|
|
160
160
|
*/
|
|
161
|
-
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
161
|
+
type EmptyObject$1 = {[emptyObjectSymbol$1]?: never};
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
Returns a boolean for whether the two given types are equal.
|
|
@@ -186,7 +186,7 @@ type Includes<Value extends readonly any[], Item> =
|
|
|
186
186
|
@category Type Guard
|
|
187
187
|
@category Utilities
|
|
188
188
|
*/
|
|
189
|
-
type IsEqual<A, B> =
|
|
189
|
+
type IsEqual$1<A, B> =
|
|
190
190
|
(<G>() => G extends A ? 1 : 2) extends
|
|
191
191
|
(<G>() => G extends B ? 1 : 2)
|
|
192
192
|
? true
|
|
@@ -219,9 +219,9 @@ type Filtered = Filter<'bar', 'foo'>;
|
|
|
219
219
|
|
|
220
220
|
@see {Except}
|
|
221
221
|
*/
|
|
222
|
-
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
222
|
+
type Filter$1<KeyType, ExcludeType> = IsEqual$1<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
223
223
|
|
|
224
|
-
type ExceptOptions = {
|
|
224
|
+
type ExceptOptions$1 = {
|
|
225
225
|
/**
|
|
226
226
|
Disallow assigning non-specified properties.
|
|
227
227
|
|
|
@@ -265,8 +265,8 @@ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
|
265
265
|
|
|
266
266
|
@category Object
|
|
267
267
|
*/
|
|
268
|
-
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
|
|
269
|
-
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
268
|
+
type Except$1<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions$1 = {requireExactProps: false}> = {
|
|
269
|
+
[KeyType in keyof ObjectType as Filter$1<KeyType, KeysType>]: ObjectType[KeyType];
|
|
270
270
|
} & (Options['requireExactProps'] extends true
|
|
271
271
|
? Partial<Record<KeysType, never>>
|
|
272
272
|
: {});
|
|
@@ -303,7 +303,7 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
|
303
303
|
|
|
304
304
|
@category Object
|
|
305
305
|
*/
|
|
306
|
-
type ConditionalKeys<Base, Condition> = NonNullable<
|
|
306
|
+
type ConditionalKeys$1<Base, Condition> = NonNullable<
|
|
307
307
|
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
308
308
|
{
|
|
309
309
|
// Map through all the keys of the given base type.
|
|
@@ -357,9 +357,9 @@ type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
|
357
357
|
|
|
358
358
|
@category Object
|
|
359
359
|
*/
|
|
360
|
-
type ConditionalExcept<Base, Condition> = Except<
|
|
360
|
+
type ConditionalExcept$1<Base, Condition> = Except$1<
|
|
361
361
|
Base,
|
|
362
|
-
ConditionalKeys<Base, Condition>
|
|
362
|
+
ConditionalKeys$1<Base, Condition>
|
|
363
363
|
>;
|
|
364
364
|
|
|
365
365
|
/**
|
|
@@ -367,8 +367,8 @@ ConditionalKeys<Base, Condition>
|
|
|
367
367
|
* can either be a REST module or a host module.
|
|
368
368
|
* This type is recursive, so it can describe nested modules.
|
|
369
369
|
*/
|
|
370
|
-
type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition$
|
|
371
|
-
[key: string]: Descriptors | PublicMetadata | any;
|
|
370
|
+
type Descriptors$1 = RESTFunctionDescriptor$1 | AmbassadorFunctionDescriptor$1 | HostModule$1<any, any> | EventDefinition$2<any> | ServicePluginDefinition$1<any> | {
|
|
371
|
+
[key: string]: Descriptors$1 | PublicMetadata$1 | any;
|
|
372
372
|
};
|
|
373
373
|
/**
|
|
374
374
|
* This type takes in a descriptors object of a certain Host (including an `unknown` host)
|
|
@@ -376,12 +376,12 @@ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostM
|
|
|
376
376
|
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
377
377
|
* do not match the given host (as they will not work with the given host).
|
|
378
378
|
*/
|
|
379
|
-
type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
|
|
379
|
+
type BuildDescriptors$1<T extends Descriptors$1, H extends Host$1<any> | undefined, Depth extends number = 5> = {
|
|
380
380
|
done: T;
|
|
381
381
|
recurse: T extends {
|
|
382
|
-
__type: typeof SERVICE_PLUGIN_ERROR_TYPE;
|
|
383
|
-
} ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition$
|
|
384
|
-
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
|
|
382
|
+
__type: typeof SERVICE_PLUGIN_ERROR_TYPE$1;
|
|
383
|
+
} ? 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<{
|
|
384
|
+
[Key in keyof T]: T[Key] extends Descriptors$1 ? BuildDescriptors$1<T[Key], H, [
|
|
385
385
|
-1,
|
|
386
386
|
0,
|
|
387
387
|
1,
|
|
@@ -390,9 +390,9 @@ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, De
|
|
|
390
390
|
4,
|
|
391
391
|
5
|
|
392
392
|
][Depth]> : never;
|
|
393
|
-
}, EmptyObject>;
|
|
393
|
+
}, EmptyObject$1>;
|
|
394
394
|
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
395
|
-
type PublicMetadata = {
|
|
395
|
+
type PublicMetadata$1 = {
|
|
396
396
|
PACKAGE_NAME?: string;
|
|
397
397
|
};
|
|
398
398
|
|
|
@@ -404,9 +404,9 @@ declare global {
|
|
|
404
404
|
* A type used to create concerete types from SDK descriptors in
|
|
405
405
|
* case a contextual client is available.
|
|
406
406
|
*/
|
|
407
|
-
type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
|
|
408
|
-
host: Host;
|
|
409
|
-
} ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
|
|
407
|
+
type MaybeContext$1<T extends Descriptors$1> = globalThis.ContextualClient extends {
|
|
408
|
+
host: Host$1;
|
|
409
|
+
} ? BuildDescriptors$1<T, globalThis.ContextualClient['host']> : T;
|
|
410
410
|
|
|
411
411
|
interface CalculateMessage {
|
|
412
412
|
/** result of the calculation */
|
|
@@ -449,13 +449,13 @@ interface CalculateIdentifiers {
|
|
|
449
449
|
operation: CalculateOperation;
|
|
450
450
|
}
|
|
451
451
|
|
|
452
|
-
declare function calculate$1(httpClient: HttpClient): CalculateSignature;
|
|
452
|
+
declare function calculate$1(httpClient: HttpClient$1): CalculateSignature;
|
|
453
453
|
interface CalculateSignature {
|
|
454
454
|
/** */
|
|
455
455
|
(identifiers: CalculateIdentifiers): Promise<CalculateResponse & CalculateResponseNonNullableFields>;
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
-
declare const calculate: MaybeContext<BuildRESTFunction<typeof calculate$1> & typeof calculate$1>;
|
|
458
|
+
declare const calculate: MaybeContext$1<BuildRESTFunction$1<typeof calculate$1> & typeof calculate$1>;
|
|
459
459
|
|
|
460
460
|
type index_d$1_CalculateIdentifiers = CalculateIdentifiers;
|
|
461
461
|
type index_d$1_CalculateMessage = CalculateMessage;
|
|
@@ -469,6 +469,416 @@ declare namespace index_d$1 {
|
|
|
469
469
|
export { type index_d$1_CalculateIdentifiers as CalculateIdentifiers, type index_d$1_CalculateMessage as CalculateMessage, index_d$1_CalculateOperation as CalculateOperation, type index_d$1_CalculateRequest as CalculateRequest, type index_d$1_CalculateResponse as CalculateResponse, type index_d$1_CalculateResponseNonNullableFields as CalculateResponseNonNullableFields, index_d$1_calculate as calculate };
|
|
470
470
|
}
|
|
471
471
|
|
|
472
|
+
type HostModule<T, H extends Host> = {
|
|
473
|
+
__type: 'host';
|
|
474
|
+
create(host: H): T;
|
|
475
|
+
};
|
|
476
|
+
type HostModuleAPI<T extends HostModule<any, any>> = T extends HostModule<infer U, any> ? U : never;
|
|
477
|
+
type Host<Environment = unknown> = {
|
|
478
|
+
channel: {
|
|
479
|
+
observeState(callback: (props: unknown, environment: Environment) => unknown): {
|
|
480
|
+
disconnect: () => void;
|
|
481
|
+
} | Promise<{
|
|
482
|
+
disconnect: () => void;
|
|
483
|
+
}>;
|
|
484
|
+
};
|
|
485
|
+
environment?: Environment;
|
|
486
|
+
/**
|
|
487
|
+
* Optional bast url to use for API requests, for example `www.wixapis.com`
|
|
488
|
+
*/
|
|
489
|
+
apiBaseUrl?: string;
|
|
490
|
+
/**
|
|
491
|
+
* Possible data to be provided by every host, for cross cutting concerns
|
|
492
|
+
* like internationalization, billing, etc.
|
|
493
|
+
*/
|
|
494
|
+
essentials?: {
|
|
495
|
+
/**
|
|
496
|
+
* The language of the currently viewed session
|
|
497
|
+
*/
|
|
498
|
+
language?: string;
|
|
499
|
+
/**
|
|
500
|
+
* The locale of the currently viewed session
|
|
501
|
+
*/
|
|
502
|
+
locale?: string;
|
|
503
|
+
/**
|
|
504
|
+
* Any headers that should be passed through to the API requests
|
|
505
|
+
*/
|
|
506
|
+
passThroughHeaders?: Record<string, string>;
|
|
507
|
+
};
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
type RESTFunctionDescriptor<T extends (...args: any[]) => any = (...args: any[]) => any> = (httpClient: HttpClient) => T;
|
|
511
|
+
interface HttpClient {
|
|
512
|
+
request<TResponse, TData = any>(req: RequestOptionsFactory<TResponse, TData>): Promise<HttpResponse<TResponse>>;
|
|
513
|
+
fetchWithAuth: typeof fetch;
|
|
514
|
+
wixAPIFetch: (relativeUrl: string, options: RequestInit) => Promise<Response>;
|
|
515
|
+
getActiveToken?: () => string | undefined;
|
|
516
|
+
}
|
|
517
|
+
type RequestOptionsFactory<TResponse = any, TData = any> = (context: any) => RequestOptions<TResponse, TData>;
|
|
518
|
+
type HttpResponse<T = any> = {
|
|
519
|
+
data: T;
|
|
520
|
+
status: number;
|
|
521
|
+
statusText: string;
|
|
522
|
+
headers: any;
|
|
523
|
+
request?: any;
|
|
524
|
+
};
|
|
525
|
+
type RequestOptions<_TResponse = any, Data = any> = {
|
|
526
|
+
method: 'POST' | 'GET' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
527
|
+
url: string;
|
|
528
|
+
data?: Data;
|
|
529
|
+
params?: URLSearchParams;
|
|
530
|
+
} & APIMetadata;
|
|
531
|
+
type APIMetadata = {
|
|
532
|
+
methodFqn?: string;
|
|
533
|
+
entityFqdn?: string;
|
|
534
|
+
packageName?: string;
|
|
535
|
+
};
|
|
536
|
+
type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
|
|
537
|
+
type EventDefinition$1<Payload = unknown, Type extends string = string> = {
|
|
538
|
+
__type: 'event-definition';
|
|
539
|
+
type: Type;
|
|
540
|
+
isDomainEvent?: boolean;
|
|
541
|
+
transformations?: (envelope: unknown) => Payload;
|
|
542
|
+
__payload: Payload;
|
|
543
|
+
};
|
|
544
|
+
declare function EventDefinition$1<Type extends string>(type: Type, isDomainEvent?: boolean, transformations?: (envelope: any) => unknown): <Payload = unknown>() => EventDefinition$1<Payload, Type>;
|
|
545
|
+
type EventHandler$1<T extends EventDefinition$1> = (payload: T['__payload']) => void | Promise<void>;
|
|
546
|
+
type BuildEventDefinition$1<T extends EventDefinition$1<any, string>> = (handler: EventHandler$1<T>) => void;
|
|
547
|
+
|
|
548
|
+
type ServicePluginMethodInput = {
|
|
549
|
+
request: any;
|
|
550
|
+
metadata: any;
|
|
551
|
+
};
|
|
552
|
+
type ServicePluginContract = Record<string, (payload: ServicePluginMethodInput) => unknown | Promise<unknown>>;
|
|
553
|
+
type ServicePluginMethodMetadata = {
|
|
554
|
+
name: string;
|
|
555
|
+
primaryHttpMappingPath: string;
|
|
556
|
+
transformations: {
|
|
557
|
+
fromREST: (...args: unknown[]) => ServicePluginMethodInput;
|
|
558
|
+
toREST: (...args: unknown[]) => unknown;
|
|
559
|
+
};
|
|
560
|
+
};
|
|
561
|
+
type ServicePluginDefinition<Contract extends ServicePluginContract> = {
|
|
562
|
+
__type: 'service-plugin-definition';
|
|
563
|
+
componentType: string;
|
|
564
|
+
methods: ServicePluginMethodMetadata[];
|
|
565
|
+
__contract: Contract;
|
|
566
|
+
};
|
|
567
|
+
declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
|
|
568
|
+
type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
|
|
569
|
+
declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
|
|
570
|
+
|
|
571
|
+
type RequestContext = {
|
|
572
|
+
isSSR: boolean;
|
|
573
|
+
host: string;
|
|
574
|
+
protocol?: string;
|
|
575
|
+
};
|
|
576
|
+
type ResponseTransformer = (data: any, headers?: any) => any;
|
|
577
|
+
/**
|
|
578
|
+
* Ambassador request options types are copied mostly from AxiosRequestConfig.
|
|
579
|
+
* They are copied and not imported to reduce the amount of dependencies (to reduce install time).
|
|
580
|
+
* https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
|
|
581
|
+
*/
|
|
582
|
+
type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
|
|
583
|
+
type AmbassadorRequestOptions<T = any> = {
|
|
584
|
+
_?: T;
|
|
585
|
+
url?: string;
|
|
586
|
+
method?: Method;
|
|
587
|
+
params?: any;
|
|
588
|
+
data?: any;
|
|
589
|
+
transformResponse?: ResponseTransformer | ResponseTransformer[];
|
|
590
|
+
};
|
|
591
|
+
type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
|
|
592
|
+
__isAmbassador: boolean;
|
|
593
|
+
};
|
|
594
|
+
type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
|
|
595
|
+
type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
|
|
596
|
+
|
|
597
|
+
declare global {
|
|
598
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
|
|
599
|
+
interface SymbolConstructor {
|
|
600
|
+
readonly observable: symbol;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
declare const emptyObjectSymbol: unique symbol;
|
|
605
|
+
|
|
606
|
+
/**
|
|
607
|
+
Represents a strictly empty plain object, the `{}` value.
|
|
608
|
+
|
|
609
|
+
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)).
|
|
610
|
+
|
|
611
|
+
@example
|
|
612
|
+
```
|
|
613
|
+
import type {EmptyObject} from 'type-fest';
|
|
614
|
+
|
|
615
|
+
// The following illustrates the problem with `{}`.
|
|
616
|
+
const foo1: {} = {}; // Pass
|
|
617
|
+
const foo2: {} = []; // Pass
|
|
618
|
+
const foo3: {} = 42; // Pass
|
|
619
|
+
const foo4: {} = {a: 1}; // Pass
|
|
620
|
+
|
|
621
|
+
// With `EmptyObject` only the first case is valid.
|
|
622
|
+
const bar1: EmptyObject = {}; // Pass
|
|
623
|
+
const bar2: EmptyObject = 42; // Fail
|
|
624
|
+
const bar3: EmptyObject = []; // Fail
|
|
625
|
+
const bar4: EmptyObject = {a: 1}; // Fail
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
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}.
|
|
629
|
+
|
|
630
|
+
@category Object
|
|
631
|
+
*/
|
|
632
|
+
type EmptyObject = {[emptyObjectSymbol]?: never};
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
Returns a boolean for whether the two given types are equal.
|
|
636
|
+
|
|
637
|
+
@link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
|
|
638
|
+
@link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
|
|
639
|
+
|
|
640
|
+
Use-cases:
|
|
641
|
+
- If you want to make a conditional branch based on the result of a comparison of two types.
|
|
642
|
+
|
|
643
|
+
@example
|
|
644
|
+
```
|
|
645
|
+
import type {IsEqual} from 'type-fest';
|
|
646
|
+
|
|
647
|
+
// This type returns a boolean for whether the given array includes the given item.
|
|
648
|
+
// `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
|
|
649
|
+
type Includes<Value extends readonly any[], Item> =
|
|
650
|
+
Value extends readonly [Value[0], ...infer rest]
|
|
651
|
+
? IsEqual<Value[0], Item> extends true
|
|
652
|
+
? true
|
|
653
|
+
: Includes<rest, Item>
|
|
654
|
+
: false;
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
@category Type Guard
|
|
658
|
+
@category Utilities
|
|
659
|
+
*/
|
|
660
|
+
type IsEqual<A, B> =
|
|
661
|
+
(<G>() => G extends A ? 1 : 2) extends
|
|
662
|
+
(<G>() => G extends B ? 1 : 2)
|
|
663
|
+
? true
|
|
664
|
+
: false;
|
|
665
|
+
|
|
666
|
+
/**
|
|
667
|
+
Filter out keys from an object.
|
|
668
|
+
|
|
669
|
+
Returns `never` if `Exclude` is strictly equal to `Key`.
|
|
670
|
+
Returns `never` if `Key` extends `Exclude`.
|
|
671
|
+
Returns `Key` otherwise.
|
|
672
|
+
|
|
673
|
+
@example
|
|
674
|
+
```
|
|
675
|
+
type Filtered = Filter<'foo', 'foo'>;
|
|
676
|
+
//=> never
|
|
677
|
+
```
|
|
678
|
+
|
|
679
|
+
@example
|
|
680
|
+
```
|
|
681
|
+
type Filtered = Filter<'bar', string>;
|
|
682
|
+
//=> never
|
|
683
|
+
```
|
|
684
|
+
|
|
685
|
+
@example
|
|
686
|
+
```
|
|
687
|
+
type Filtered = Filter<'bar', 'foo'>;
|
|
688
|
+
//=> 'bar'
|
|
689
|
+
```
|
|
690
|
+
|
|
691
|
+
@see {Except}
|
|
692
|
+
*/
|
|
693
|
+
type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
|
|
694
|
+
|
|
695
|
+
type ExceptOptions = {
|
|
696
|
+
/**
|
|
697
|
+
Disallow assigning non-specified properties.
|
|
698
|
+
|
|
699
|
+
Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
|
|
700
|
+
|
|
701
|
+
@default false
|
|
702
|
+
*/
|
|
703
|
+
requireExactProps?: boolean;
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
Create a type from an object type without certain keys.
|
|
708
|
+
|
|
709
|
+
We recommend setting the `requireExactProps` option to `true`.
|
|
710
|
+
|
|
711
|
+
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.
|
|
712
|
+
|
|
713
|
+
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)).
|
|
714
|
+
|
|
715
|
+
@example
|
|
716
|
+
```
|
|
717
|
+
import type {Except} from 'type-fest';
|
|
718
|
+
|
|
719
|
+
type Foo = {
|
|
720
|
+
a: number;
|
|
721
|
+
b: string;
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
type FooWithoutA = Except<Foo, 'a'>;
|
|
725
|
+
//=> {b: string}
|
|
726
|
+
|
|
727
|
+
const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
|
|
728
|
+
//=> errors: 'a' does not exist in type '{ b: string; }'
|
|
729
|
+
|
|
730
|
+
type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
|
|
731
|
+
//=> {a: number} & Partial<Record<"b", never>>
|
|
732
|
+
|
|
733
|
+
const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
|
|
734
|
+
//=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
|
|
735
|
+
```
|
|
736
|
+
|
|
737
|
+
@category Object
|
|
738
|
+
*/
|
|
739
|
+
type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
|
|
740
|
+
[KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
|
|
741
|
+
} & (Options['requireExactProps'] extends true
|
|
742
|
+
? Partial<Record<KeysType, never>>
|
|
743
|
+
: {});
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
Extract the keys from a type where the value type of the key extends the given `Condition`.
|
|
747
|
+
|
|
748
|
+
Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
|
|
749
|
+
|
|
750
|
+
@example
|
|
751
|
+
```
|
|
752
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
753
|
+
|
|
754
|
+
interface Example {
|
|
755
|
+
a: string;
|
|
756
|
+
b: string | number;
|
|
757
|
+
c?: string;
|
|
758
|
+
d: {};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
type StringKeysOnly = ConditionalKeys<Example, string>;
|
|
762
|
+
//=> 'a'
|
|
763
|
+
```
|
|
764
|
+
|
|
765
|
+
To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
|
|
766
|
+
|
|
767
|
+
@example
|
|
768
|
+
```
|
|
769
|
+
import type {ConditionalKeys} from 'type-fest';
|
|
770
|
+
|
|
771
|
+
type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
|
|
772
|
+
//=> 'a' | 'c'
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
@category Object
|
|
776
|
+
*/
|
|
777
|
+
type ConditionalKeys<Base, Condition> = NonNullable<
|
|
778
|
+
// Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
|
|
779
|
+
{
|
|
780
|
+
// Map through all the keys of the given base type.
|
|
781
|
+
[Key in keyof Base]:
|
|
782
|
+
// Pick only keys with types extending the given `Condition` type.
|
|
783
|
+
Base[Key] extends Condition
|
|
784
|
+
// Retain this key since the condition passes.
|
|
785
|
+
? Key
|
|
786
|
+
// Discard this key since the condition fails.
|
|
787
|
+
: never;
|
|
788
|
+
|
|
789
|
+
// Convert the produced object into a union type of the keys which passed the conditional test.
|
|
790
|
+
}[keyof Base]
|
|
791
|
+
>;
|
|
792
|
+
|
|
793
|
+
/**
|
|
794
|
+
Exclude keys from a shape that matches the given `Condition`.
|
|
795
|
+
|
|
796
|
+
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.
|
|
797
|
+
|
|
798
|
+
@example
|
|
799
|
+
```
|
|
800
|
+
import type {Primitive, ConditionalExcept} from 'type-fest';
|
|
801
|
+
|
|
802
|
+
class Awesome {
|
|
803
|
+
name: string;
|
|
804
|
+
successes: number;
|
|
805
|
+
failures: bigint;
|
|
806
|
+
|
|
807
|
+
run() {}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
|
|
811
|
+
//=> {run: () => void}
|
|
812
|
+
```
|
|
813
|
+
|
|
814
|
+
@example
|
|
815
|
+
```
|
|
816
|
+
import type {ConditionalExcept} from 'type-fest';
|
|
817
|
+
|
|
818
|
+
interface Example {
|
|
819
|
+
a: string;
|
|
820
|
+
b: string | number;
|
|
821
|
+
c: () => void;
|
|
822
|
+
d: {};
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
type NonStringKeysOnly = ConditionalExcept<Example, string>;
|
|
826
|
+
//=> {b: string | number; c: () => void; d: {}}
|
|
827
|
+
```
|
|
828
|
+
|
|
829
|
+
@category Object
|
|
830
|
+
*/
|
|
831
|
+
type ConditionalExcept<Base, Condition> = Except<
|
|
832
|
+
Base,
|
|
833
|
+
ConditionalKeys<Base, Condition>
|
|
834
|
+
>;
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Descriptors are objects that describe the API of a module, and the module
|
|
838
|
+
* can either be a REST module or a host module.
|
|
839
|
+
* This type is recursive, so it can describe nested modules.
|
|
840
|
+
*/
|
|
841
|
+
type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition$1<any> | ServicePluginDefinition<any> | {
|
|
842
|
+
[key: string]: Descriptors | PublicMetadata | any;
|
|
843
|
+
};
|
|
844
|
+
/**
|
|
845
|
+
* This type takes in a descriptors object of a certain Host (including an `unknown` host)
|
|
846
|
+
* and returns an object with the same structure, but with all descriptors replaced with their API.
|
|
847
|
+
* Any non-descriptor properties are removed from the returned object, including descriptors that
|
|
848
|
+
* do not match the given host (as they will not work with the given host).
|
|
849
|
+
*/
|
|
850
|
+
type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
|
|
851
|
+
done: T;
|
|
852
|
+
recurse: T extends {
|
|
853
|
+
__type: typeof SERVICE_PLUGIN_ERROR_TYPE;
|
|
854
|
+
} ? never : T extends AmbassadorFunctionDescriptor ? BuildAmbassadorFunction<T> : T extends RESTFunctionDescriptor ? BuildRESTFunction<T> : T extends EventDefinition$1<any> ? BuildEventDefinition$1<T> : T extends ServicePluginDefinition<any> ? BuildServicePluginDefinition<T> : T extends HostModule<any, any> ? HostModuleAPI<T> : ConditionalExcept<{
|
|
855
|
+
[Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
|
|
856
|
+
-1,
|
|
857
|
+
0,
|
|
858
|
+
1,
|
|
859
|
+
2,
|
|
860
|
+
3,
|
|
861
|
+
4,
|
|
862
|
+
5
|
|
863
|
+
][Depth]> : never;
|
|
864
|
+
}, EmptyObject>;
|
|
865
|
+
}[Depth extends -1 ? 'done' : 'recurse'];
|
|
866
|
+
type PublicMetadata = {
|
|
867
|
+
PACKAGE_NAME?: string;
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
declare global {
|
|
871
|
+
interface ContextualClient {
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* A type used to create concerete types from SDK descriptors in
|
|
876
|
+
* case a contextual client is available.
|
|
877
|
+
*/
|
|
878
|
+
type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
|
|
879
|
+
host: Host;
|
|
880
|
+
} ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
|
|
881
|
+
|
|
472
882
|
interface MessageItem {
|
|
473
883
|
/** inner_message comment from EchoMessage proto def */
|
|
474
884
|
innerMessage?: string;
|