@wix/sdk-types 1.7.3 → 1.9.0

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