@wix/sdk-types 1.8.0 → 1.9.1

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.
@@ -16,7 +16,9 @@ function ServicePluginDefinition(componentType, methods) {
16
16
  methods
17
17
  };
18
18
  }
19
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
19
20
  export {
20
21
  EventDefinition,
22
+ SERVICE_PLUGIN_ERROR_TYPE,
21
23
  ServicePluginDefinition
22
24
  };
package/build/index.d.mts CHANGED
@@ -40,7 +40,7 @@ type APIMetadata = {
40
40
  };
41
41
  type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
42
42
 
43
- type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) => AuthenticationStrategy<Host, WithAuth>) | undefined = undefined> = {
43
+ type AuthenticationStrategy<Host = unknown> = {
44
44
  getAuthHeaders: (host: Host) => Promise<{
45
45
  headers: Record<string, string>;
46
46
  }> | {
@@ -52,7 +52,6 @@ type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) =>
52
52
  };
53
53
  valid: boolean;
54
54
  }>;
55
- withAuth?: WithAuth;
56
55
  };
57
56
  type BoundAuthenticationStrategy = {
58
57
  getAuthHeaders: () => Promise<{
@@ -105,5 +104,305 @@ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
105
104
  };
106
105
  declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
107
106
  type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
107
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
108
108
 
109
- export { type APIMetadata, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, EventDefinition, type EventHandler, type EventIdentity, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
109
+ type RequestContext = {
110
+ isSSR: boolean;
111
+ host: string;
112
+ protocol?: string;
113
+ };
114
+ type ResponseTransformer = (data: any, headers?: any) => any;
115
+ /**
116
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
117
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
118
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
119
+ */
120
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
121
+ type AmbassadorRequestOptions<T = any> = {
122
+ _?: T;
123
+ url?: string;
124
+ method?: Method;
125
+ params?: any;
126
+ data?: any;
127
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
128
+ };
129
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
130
+ __isAmbassador: boolean;
131
+ };
132
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
133
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
134
+
135
+ declare global {
136
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
137
+ interface SymbolConstructor {
138
+ readonly observable: symbol;
139
+ }
140
+ }
141
+
142
+ declare const emptyObjectSymbol: unique symbol;
143
+
144
+ /**
145
+ Represents a strictly empty plain object, the `{}` value.
146
+
147
+ 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)).
148
+
149
+ @example
150
+ ```
151
+ import type {EmptyObject} from 'type-fest';
152
+
153
+ // The following illustrates the problem with `{}`.
154
+ const foo1: {} = {}; // Pass
155
+ const foo2: {} = []; // Pass
156
+ const foo3: {} = 42; // Pass
157
+ const foo4: {} = {a: 1}; // Pass
158
+
159
+ // With `EmptyObject` only the first case is valid.
160
+ const bar1: EmptyObject = {}; // Pass
161
+ const bar2: EmptyObject = 42; // Fail
162
+ const bar3: EmptyObject = []; // Fail
163
+ const bar4: EmptyObject = {a: 1}; // Fail
164
+ ```
165
+
166
+ 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}.
167
+
168
+ @category Object
169
+ */
170
+ type EmptyObject = {[emptyObjectSymbol]?: never};
171
+
172
+ /**
173
+ Returns a boolean for whether the two given types are equal.
174
+
175
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
176
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
177
+
178
+ Use-cases:
179
+ - If you want to make a conditional branch based on the result of a comparison of two types.
180
+
181
+ @example
182
+ ```
183
+ import type {IsEqual} from 'type-fest';
184
+
185
+ // This type returns a boolean for whether the given array includes the given item.
186
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
187
+ type Includes<Value extends readonly any[], Item> =
188
+ Value extends readonly [Value[0], ...infer rest]
189
+ ? IsEqual<Value[0], Item> extends true
190
+ ? true
191
+ : Includes<rest, Item>
192
+ : false;
193
+ ```
194
+
195
+ @category Type Guard
196
+ @category Utilities
197
+ */
198
+ type IsEqual<A, B> =
199
+ (<G>() => G extends A ? 1 : 2) extends
200
+ (<G>() => G extends B ? 1 : 2)
201
+ ? true
202
+ : false;
203
+
204
+ /**
205
+ Filter out keys from an object.
206
+
207
+ Returns `never` if `Exclude` is strictly equal to `Key`.
208
+ Returns `never` if `Key` extends `Exclude`.
209
+ Returns `Key` otherwise.
210
+
211
+ @example
212
+ ```
213
+ type Filtered = Filter<'foo', 'foo'>;
214
+ //=> never
215
+ ```
216
+
217
+ @example
218
+ ```
219
+ type Filtered = Filter<'bar', string>;
220
+ //=> never
221
+ ```
222
+
223
+ @example
224
+ ```
225
+ type Filtered = Filter<'bar', 'foo'>;
226
+ //=> 'bar'
227
+ ```
228
+
229
+ @see {Except}
230
+ */
231
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
232
+
233
+ type ExceptOptions = {
234
+ /**
235
+ Disallow assigning non-specified properties.
236
+
237
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
238
+
239
+ @default false
240
+ */
241
+ requireExactProps?: boolean;
242
+ };
243
+
244
+ /**
245
+ Create a type from an object type without certain keys.
246
+
247
+ We recommend setting the `requireExactProps` option to `true`.
248
+
249
+ 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.
250
+
251
+ 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)).
252
+
253
+ @example
254
+ ```
255
+ import type {Except} from 'type-fest';
256
+
257
+ type Foo = {
258
+ a: number;
259
+ b: string;
260
+ };
261
+
262
+ type FooWithoutA = Except<Foo, 'a'>;
263
+ //=> {b: string}
264
+
265
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
266
+ //=> errors: 'a' does not exist in type '{ b: string; }'
267
+
268
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
269
+ //=> {a: number} & Partial<Record<"b", never>>
270
+
271
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
272
+ //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
273
+ ```
274
+
275
+ @category Object
276
+ */
277
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
278
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
279
+ } & (Options['requireExactProps'] extends true
280
+ ? Partial<Record<KeysType, never>>
281
+ : {});
282
+
283
+ /**
284
+ Extract the keys from a type where the value type of the key extends the given `Condition`.
285
+
286
+ Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
287
+
288
+ @example
289
+ ```
290
+ import type {ConditionalKeys} from 'type-fest';
291
+
292
+ interface Example {
293
+ a: string;
294
+ b: string | number;
295
+ c?: string;
296
+ d: {};
297
+ }
298
+
299
+ type StringKeysOnly = ConditionalKeys<Example, string>;
300
+ //=> 'a'
301
+ ```
302
+
303
+ To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
304
+
305
+ @example
306
+ ```
307
+ import type {ConditionalKeys} from 'type-fest';
308
+
309
+ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
310
+ //=> 'a' | 'c'
311
+ ```
312
+
313
+ @category Object
314
+ */
315
+ type ConditionalKeys<Base, Condition> = NonNullable<
316
+ // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
317
+ {
318
+ // Map through all the keys of the given base type.
319
+ [Key in keyof Base]:
320
+ // Pick only keys with types extending the given `Condition` type.
321
+ Base[Key] extends Condition
322
+ // Retain this key since the condition passes.
323
+ ? Key
324
+ // Discard this key since the condition fails.
325
+ : never;
326
+
327
+ // Convert the produced object into a union type of the keys which passed the conditional test.
328
+ }[keyof Base]
329
+ >;
330
+
331
+ /**
332
+ Exclude keys from a shape that matches the given `Condition`.
333
+
334
+ 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.
335
+
336
+ @example
337
+ ```
338
+ import type {Primitive, ConditionalExcept} from 'type-fest';
339
+
340
+ class Awesome {
341
+ name: string;
342
+ successes: number;
343
+ failures: bigint;
344
+
345
+ run() {}
346
+ }
347
+
348
+ type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
349
+ //=> {run: () => void}
350
+ ```
351
+
352
+ @example
353
+ ```
354
+ import type {ConditionalExcept} from 'type-fest';
355
+
356
+ interface Example {
357
+ a: string;
358
+ b: string | number;
359
+ c: () => void;
360
+ d: {};
361
+ }
362
+
363
+ type NonStringKeysOnly = ConditionalExcept<Example, string>;
364
+ //=> {b: string | number; c: () => void; d: {}}
365
+ ```
366
+
367
+ @category Object
368
+ */
369
+ type ConditionalExcept<Base, Condition> = Except<
370
+ Base,
371
+ ConditionalKeys<Base, Condition>
372
+ >;
373
+
374
+ /**
375
+ * Descriptors are objects that describe the API of a module, and the module
376
+ * can either be a REST module or a host module.
377
+ * This type is recursive, so it can describe nested modules.
378
+ */
379
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
380
+ [key: string]: Descriptors | PublicMetadata | any;
381
+ };
382
+ /**
383
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
384
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
385
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
386
+ * do not match the given host (as they will not work with the given host).
387
+ */
388
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
389
+ done: T;
390
+ recurse: T extends {
391
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
392
+ } ? 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<{
393
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
394
+ -1,
395
+ 0,
396
+ 1,
397
+ 2,
398
+ 3,
399
+ 4,
400
+ 5
401
+ ][Depth]> : never;
402
+ }, EmptyObject>;
403
+ }[Depth extends -1 ? 'done' : 'recurse'];
404
+ type PublicMetadata = {
405
+ PACKAGE_NAME?: string;
406
+ };
407
+
408
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
package/build/index.d.ts CHANGED
@@ -40,7 +40,7 @@ type APIMetadata = {
40
40
  };
41
41
  type BuildRESTFunction<T extends RESTFunctionDescriptor> = T extends RESTFunctionDescriptor<infer U> ? U : never;
42
42
 
43
- type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) => AuthenticationStrategy<Host, WithAuth>) | undefined = undefined> = {
43
+ type AuthenticationStrategy<Host = unknown> = {
44
44
  getAuthHeaders: (host: Host) => Promise<{
45
45
  headers: Record<string, string>;
46
46
  }> | {
@@ -52,7 +52,6 @@ type AuthenticationStrategy<Host = unknown, WithAuth extends ((...args: any) =>
52
52
  };
53
53
  valid: boolean;
54
54
  }>;
55
- withAuth?: WithAuth;
56
55
  };
57
56
  type BoundAuthenticationStrategy = {
58
57
  getAuthHeaders: () => Promise<{
@@ -105,5 +104,305 @@ type ServicePluginDefinition<Contract extends ServicePluginContract> = {
105
104
  };
106
105
  declare function ServicePluginDefinition<Contract extends ServicePluginContract>(componentType: string, methods: ServicePluginMethodMetadata[]): ServicePluginDefinition<Contract>;
107
106
  type BuildServicePluginDefinition<T extends ServicePluginDefinition<any>> = (implementation: T['__contract']) => void;
107
+ declare const SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
108
108
 
109
- export { type APIMetadata, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, EventDefinition, type EventHandler, type EventIdentity, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type RESTFunctionDescriptor, type RequestOptions, type RequestOptionsFactory, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
109
+ type RequestContext = {
110
+ isSSR: boolean;
111
+ host: string;
112
+ protocol?: string;
113
+ };
114
+ type ResponseTransformer = (data: any, headers?: any) => any;
115
+ /**
116
+ * Ambassador request options types are copied mostly from AxiosRequestConfig.
117
+ * They are copied and not imported to reduce the amount of dependencies (to reduce install time).
118
+ * https://github.com/axios/axios/blob/3f53eb6960f05a1f88409c4b731a40de595cb825/index.d.ts#L307-L315
119
+ */
120
+ type Method = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK';
121
+ type AmbassadorRequestOptions<T = any> = {
122
+ _?: T;
123
+ url?: string;
124
+ method?: Method;
125
+ params?: any;
126
+ data?: any;
127
+ transformResponse?: ResponseTransformer | ResponseTransformer[];
128
+ };
129
+ type AmbassadorFactory<Request, Response> = (payload: Request) => ((context: RequestContext) => AmbassadorRequestOptions<Response>) & {
130
+ __isAmbassador: boolean;
131
+ };
132
+ type AmbassadorFunctionDescriptor<Request = any, Response = any> = AmbassadorFactory<Request, Response>;
133
+ type BuildAmbassadorFunction<T extends AmbassadorFunctionDescriptor> = T extends AmbassadorFunctionDescriptor<infer Request, infer Response> ? (req: Request) => Promise<Response> : never;
134
+
135
+ declare global {
136
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged.
137
+ interface SymbolConstructor {
138
+ readonly observable: symbol;
139
+ }
140
+ }
141
+
142
+ declare const emptyObjectSymbol: unique symbol;
143
+
144
+ /**
145
+ Represents a strictly empty plain object, the `{}` value.
146
+
147
+ 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)).
148
+
149
+ @example
150
+ ```
151
+ import type {EmptyObject} from 'type-fest';
152
+
153
+ // The following illustrates the problem with `{}`.
154
+ const foo1: {} = {}; // Pass
155
+ const foo2: {} = []; // Pass
156
+ const foo3: {} = 42; // Pass
157
+ const foo4: {} = {a: 1}; // Pass
158
+
159
+ // With `EmptyObject` only the first case is valid.
160
+ const bar1: EmptyObject = {}; // Pass
161
+ const bar2: EmptyObject = 42; // Fail
162
+ const bar3: EmptyObject = []; // Fail
163
+ const bar4: EmptyObject = {a: 1}; // Fail
164
+ ```
165
+
166
+ 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}.
167
+
168
+ @category Object
169
+ */
170
+ type EmptyObject = {[emptyObjectSymbol]?: never};
171
+
172
+ /**
173
+ Returns a boolean for whether the two given types are equal.
174
+
175
+ @link https://github.com/microsoft/TypeScript/issues/27024#issuecomment-421529650
176
+ @link https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
177
+
178
+ Use-cases:
179
+ - If you want to make a conditional branch based on the result of a comparison of two types.
180
+
181
+ @example
182
+ ```
183
+ import type {IsEqual} from 'type-fest';
184
+
185
+ // This type returns a boolean for whether the given array includes the given item.
186
+ // `IsEqual` is used to compare the given array at position 0 and the given item and then return true if they are equal.
187
+ type Includes<Value extends readonly any[], Item> =
188
+ Value extends readonly [Value[0], ...infer rest]
189
+ ? IsEqual<Value[0], Item> extends true
190
+ ? true
191
+ : Includes<rest, Item>
192
+ : false;
193
+ ```
194
+
195
+ @category Type Guard
196
+ @category Utilities
197
+ */
198
+ type IsEqual<A, B> =
199
+ (<G>() => G extends A ? 1 : 2) extends
200
+ (<G>() => G extends B ? 1 : 2)
201
+ ? true
202
+ : false;
203
+
204
+ /**
205
+ Filter out keys from an object.
206
+
207
+ Returns `never` if `Exclude` is strictly equal to `Key`.
208
+ Returns `never` if `Key` extends `Exclude`.
209
+ Returns `Key` otherwise.
210
+
211
+ @example
212
+ ```
213
+ type Filtered = Filter<'foo', 'foo'>;
214
+ //=> never
215
+ ```
216
+
217
+ @example
218
+ ```
219
+ type Filtered = Filter<'bar', string>;
220
+ //=> never
221
+ ```
222
+
223
+ @example
224
+ ```
225
+ type Filtered = Filter<'bar', 'foo'>;
226
+ //=> 'bar'
227
+ ```
228
+
229
+ @see {Except}
230
+ */
231
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
232
+
233
+ type ExceptOptions = {
234
+ /**
235
+ Disallow assigning non-specified properties.
236
+
237
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
238
+
239
+ @default false
240
+ */
241
+ requireExactProps?: boolean;
242
+ };
243
+
244
+ /**
245
+ Create a type from an object type without certain keys.
246
+
247
+ We recommend setting the `requireExactProps` option to `true`.
248
+
249
+ 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.
250
+
251
+ 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)).
252
+
253
+ @example
254
+ ```
255
+ import type {Except} from 'type-fest';
256
+
257
+ type Foo = {
258
+ a: number;
259
+ b: string;
260
+ };
261
+
262
+ type FooWithoutA = Except<Foo, 'a'>;
263
+ //=> {b: string}
264
+
265
+ const fooWithoutA: FooWithoutA = {a: 1, b: '2'};
266
+ //=> errors: 'a' does not exist in type '{ b: string; }'
267
+
268
+ type FooWithoutB = Except<Foo, 'b', {requireExactProps: true}>;
269
+ //=> {a: number} & Partial<Record<"b", never>>
270
+
271
+ const fooWithoutB: FooWithoutB = {a: 1, b: '2'};
272
+ //=> errors at 'b': Type 'string' is not assignable to type 'undefined'.
273
+ ```
274
+
275
+ @category Object
276
+ */
277
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {requireExactProps: false}> = {
278
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
279
+ } & (Options['requireExactProps'] extends true
280
+ ? Partial<Record<KeysType, never>>
281
+ : {});
282
+
283
+ /**
284
+ Extract the keys from a type where the value type of the key extends the given `Condition`.
285
+
286
+ Internally this is used for the `ConditionalPick` and `ConditionalExcept` types.
287
+
288
+ @example
289
+ ```
290
+ import type {ConditionalKeys} from 'type-fest';
291
+
292
+ interface Example {
293
+ a: string;
294
+ b: string | number;
295
+ c?: string;
296
+ d: {};
297
+ }
298
+
299
+ type StringKeysOnly = ConditionalKeys<Example, string>;
300
+ //=> 'a'
301
+ ```
302
+
303
+ To support partial types, make sure your `Condition` is a union of undefined (for example, `string | undefined`) as demonstrated below.
304
+
305
+ @example
306
+ ```
307
+ import type {ConditionalKeys} from 'type-fest';
308
+
309
+ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
310
+ //=> 'a' | 'c'
311
+ ```
312
+
313
+ @category Object
314
+ */
315
+ type ConditionalKeys<Base, Condition> = NonNullable<
316
+ // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
317
+ {
318
+ // Map through all the keys of the given base type.
319
+ [Key in keyof Base]:
320
+ // Pick only keys with types extending the given `Condition` type.
321
+ Base[Key] extends Condition
322
+ // Retain this key since the condition passes.
323
+ ? Key
324
+ // Discard this key since the condition fails.
325
+ : never;
326
+
327
+ // Convert the produced object into a union type of the keys which passed the conditional test.
328
+ }[keyof Base]
329
+ >;
330
+
331
+ /**
332
+ Exclude keys from a shape that matches the given `Condition`.
333
+
334
+ 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.
335
+
336
+ @example
337
+ ```
338
+ import type {Primitive, ConditionalExcept} from 'type-fest';
339
+
340
+ class Awesome {
341
+ name: string;
342
+ successes: number;
343
+ failures: bigint;
344
+
345
+ run() {}
346
+ }
347
+
348
+ type ExceptPrimitivesFromAwesome = ConditionalExcept<Awesome, Primitive>;
349
+ //=> {run: () => void}
350
+ ```
351
+
352
+ @example
353
+ ```
354
+ import type {ConditionalExcept} from 'type-fest';
355
+
356
+ interface Example {
357
+ a: string;
358
+ b: string | number;
359
+ c: () => void;
360
+ d: {};
361
+ }
362
+
363
+ type NonStringKeysOnly = ConditionalExcept<Example, string>;
364
+ //=> {b: string | number; c: () => void; d: {}}
365
+ ```
366
+
367
+ @category Object
368
+ */
369
+ type ConditionalExcept<Base, Condition> = Except<
370
+ Base,
371
+ ConditionalKeys<Base, Condition>
372
+ >;
373
+
374
+ /**
375
+ * Descriptors are objects that describe the API of a module, and the module
376
+ * can either be a REST module or a host module.
377
+ * This type is recursive, so it can describe nested modules.
378
+ */
379
+ type Descriptors = RESTFunctionDescriptor | AmbassadorFunctionDescriptor | HostModule<any, any> | EventDefinition<any> | ServicePluginDefinition<any> | {
380
+ [key: string]: Descriptors | PublicMetadata | any;
381
+ };
382
+ /**
383
+ * This type takes in a descriptors object of a certain Host (including an `unknown` host)
384
+ * and returns an object with the same structure, but with all descriptors replaced with their API.
385
+ * Any non-descriptor properties are removed from the returned object, including descriptors that
386
+ * do not match the given host (as they will not work with the given host).
387
+ */
388
+ type BuildDescriptors<T extends Descriptors, H extends Host<any> | undefined, Depth extends number = 5> = {
389
+ done: T;
390
+ recurse: T extends {
391
+ __type: typeof SERVICE_PLUGIN_ERROR_TYPE;
392
+ } ? 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<{
393
+ [Key in keyof T]: T[Key] extends Descriptors ? BuildDescriptors<T[Key], H, [
394
+ -1,
395
+ 0,
396
+ 1,
397
+ 2,
398
+ 3,
399
+ 4,
400
+ 5
401
+ ][Depth]> : never;
402
+ }, EmptyObject>;
403
+ }[Depth extends -1 ? 'done' : 'recurse'];
404
+ type PublicMetadata = {
405
+ PACKAGE_NAME?: string;
406
+ };
407
+
408
+ export { type APIMetadata, type AmbassadorFactory, type AmbassadorFunctionDescriptor, type AmbassadorRequestOptions, type AuthenticationStrategy, type BaseEventMetadata, type BoundAuthenticationStrategy, type BuildAmbassadorFunction, type BuildDescriptors, type BuildEventDefinition, type BuildRESTFunction, type BuildServicePluginDefinition, type Descriptors, EventDefinition, type EventHandler, type EventIdentity, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
package/build/index.js CHANGED
@@ -21,6 +21,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
23
  EventDefinition: () => EventDefinition,
24
+ SERVICE_PLUGIN_ERROR_TYPE: () => SERVICE_PLUGIN_ERROR_TYPE,
24
25
  ServicePluginDefinition: () => ServicePluginDefinition
25
26
  });
26
27
  module.exports = __toCommonJS(src_exports);
@@ -43,8 +44,10 @@ function ServicePluginDefinition(componentType, methods) {
43
44
  methods
44
45
  };
45
46
  }
47
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
46
48
  // Annotate the CommonJS export names for ESM import in node:
47
49
  0 && (module.exports = {
48
50
  EventDefinition,
51
+ SERVICE_PLUGIN_ERROR_TYPE,
49
52
  ServicePluginDefinition
50
53
  });
package/build/index.mjs CHANGED
@@ -16,7 +16,9 @@ function ServicePluginDefinition(componentType, methods) {
16
16
  methods
17
17
  };
18
18
  }
19
+ var SERVICE_PLUGIN_ERROR_TYPE = "wix_spi_error";
19
20
  export {
20
21
  EventDefinition,
22
+ SERVICE_PLUGIN_ERROR_TYPE,
21
23
  ServicePluginDefinition
22
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-types",
3
- "version": "1.8.0",
3
+ "version": "1.9.1",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -32,6 +32,7 @@
32
32
  "eslint": "^8.56.0",
33
33
  "eslint-config-sdk": "0.0.0",
34
34
  "tsup": "^7.3.0",
35
+ "type-fest": "^4.9.0",
35
36
  "typescript": "^5.3.3"
36
37
  },
37
38
  "yoshiFlowLibrary": {
@@ -57,5 +58,5 @@
57
58
  "wallaby": {
58
59
  "autoDetect": true
59
60
  },
60
- "falconPackageHash": "48f0d7162f08bb7b5de9f622d6232edd13533a09d57216d579952474"
61
+ "falconPackageHash": "465a0202b573e8cf487e8525627eb258580b23924ef203c346d78f0a"
61
62
  }