@wix/sdk-types 1.12.2 → 1.12.4

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/build/index.d.mts CHANGED
@@ -12,6 +12,10 @@ type Host<Environment = unknown> = {
12
12
  }>;
13
13
  };
14
14
  environment?: Environment;
15
+ /**
16
+ * Optional name of the environment, use for logging
17
+ */
18
+ name?: string;
15
19
  /**
16
20
  * Optional bast url to use for API requests, for example `www.wixapis.com`
17
21
  */
@@ -311,6 +315,72 @@ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends Excep
311
315
  ? Partial<Record<KeysType, never>>
312
316
  : {});
313
317
 
318
+ /**
319
+ Returns a boolean for whether the given type is `never`.
320
+
321
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
322
+ @link https://stackoverflow.com/a/53984913/10292952
323
+ @link https://www.zhenghao.io/posts/ts-never
324
+
325
+ Useful in type utilities, such as checking if something does not occur.
326
+
327
+ @example
328
+ ```
329
+ import type {IsNever, And} from 'type-fest';
330
+
331
+ // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
332
+ type AreStringsEqual<A extends string, B extends string> =
333
+ And<
334
+ IsNever<Exclude<A, B>> extends true ? true : false,
335
+ IsNever<Exclude<B, A>> extends true ? true : false
336
+ >;
337
+
338
+ type EndIfEqual<I extends string, O extends string> =
339
+ AreStringsEqual<I, O> extends true
340
+ ? never
341
+ : void;
342
+
343
+ function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
344
+ if (input === output) {
345
+ process.exit(0);
346
+ }
347
+ }
348
+
349
+ endIfEqual('abc', 'abc');
350
+ //=> never
351
+
352
+ endIfEqual('abc', '123');
353
+ //=> void
354
+ ```
355
+
356
+ @category Type Guard
357
+ @category Utilities
358
+ */
359
+ type IsNever<T> = [T] extends [never] ? true : false;
360
+
361
+ /**
362
+ An if-else-like type that resolves depending on whether the given type is `never`.
363
+
364
+ @see {@link IsNever}
365
+
366
+ @example
367
+ ```
368
+ import type {IfNever} from 'type-fest';
369
+
370
+ type ShouldBeTrue = IfNever<never>;
371
+ //=> true
372
+
373
+ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
374
+ //=> 'bar'
375
+ ```
376
+
377
+ @category Type Guard
378
+ @category Utilities
379
+ */
380
+ type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
381
+ IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
382
+ );
383
+
314
384
  /**
315
385
  Extract the keys from a type where the value type of the key extends the given `Condition`.
316
386
 
@@ -343,21 +413,19 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
343
413
 
344
414
  @category Object
345
415
  */
346
- type ConditionalKeys<Base, Condition> = NonNullable<
347
- // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
416
+ type ConditionalKeys<Base, Condition> =
348
417
  {
349
418
  // Map through all the keys of the given base type.
350
- [Key in keyof Base]:
419
+ [Key in keyof Base]-?:
351
420
  // Pick only keys with types extending the given `Condition` type.
352
421
  Base[Key] extends Condition
353
- // Retain this key since the condition passes.
354
- ? Key
422
+ // Retain this key
423
+ // If the value for the key extends never, only include it if `Condition` also extends never
424
+ ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
355
425
  // Discard this key since the condition fails.
356
426
  : never;
357
-
358
427
  // Convert the produced object into a union type of the keys which passed the conditional test.
359
- }[keyof Base]
360
- >;
428
+ }[keyof Base];
361
429
 
362
430
  /**
363
431
  Exclude keys from a shape that matches the given `Condition`.
package/build/index.d.ts CHANGED
@@ -12,6 +12,10 @@ type Host<Environment = unknown> = {
12
12
  }>;
13
13
  };
14
14
  environment?: Environment;
15
+ /**
16
+ * Optional name of the environment, use for logging
17
+ */
18
+ name?: string;
15
19
  /**
16
20
  * Optional bast url to use for API requests, for example `www.wixapis.com`
17
21
  */
@@ -311,6 +315,72 @@ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends Excep
311
315
  ? Partial<Record<KeysType, never>>
312
316
  : {});
313
317
 
318
+ /**
319
+ Returns a boolean for whether the given type is `never`.
320
+
321
+ @link https://github.com/microsoft/TypeScript/issues/31751#issuecomment-498526919
322
+ @link https://stackoverflow.com/a/53984913/10292952
323
+ @link https://www.zhenghao.io/posts/ts-never
324
+
325
+ Useful in type utilities, such as checking if something does not occur.
326
+
327
+ @example
328
+ ```
329
+ import type {IsNever, And} from 'type-fest';
330
+
331
+ // https://github.com/andnp/SimplyTyped/blob/master/src/types/strings.ts
332
+ type AreStringsEqual<A extends string, B extends string> =
333
+ And<
334
+ IsNever<Exclude<A, B>> extends true ? true : false,
335
+ IsNever<Exclude<B, A>> extends true ? true : false
336
+ >;
337
+
338
+ type EndIfEqual<I extends string, O extends string> =
339
+ AreStringsEqual<I, O> extends true
340
+ ? never
341
+ : void;
342
+
343
+ function endIfEqual<I extends string, O extends string>(input: I, output: O): EndIfEqual<I, O> {
344
+ if (input === output) {
345
+ process.exit(0);
346
+ }
347
+ }
348
+
349
+ endIfEqual('abc', 'abc');
350
+ //=> never
351
+
352
+ endIfEqual('abc', '123');
353
+ //=> void
354
+ ```
355
+
356
+ @category Type Guard
357
+ @category Utilities
358
+ */
359
+ type IsNever<T> = [T] extends [never] ? true : false;
360
+
361
+ /**
362
+ An if-else-like type that resolves depending on whether the given type is `never`.
363
+
364
+ @see {@link IsNever}
365
+
366
+ @example
367
+ ```
368
+ import type {IfNever} from 'type-fest';
369
+
370
+ type ShouldBeTrue = IfNever<never>;
371
+ //=> true
372
+
373
+ type ShouldBeBar = IfNever<'not never', 'foo', 'bar'>;
374
+ //=> 'bar'
375
+ ```
376
+
377
+ @category Type Guard
378
+ @category Utilities
379
+ */
380
+ type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (
381
+ IsNever<T> extends true ? TypeIfNever : TypeIfNotNever
382
+ );
383
+
314
384
  /**
315
385
  Extract the keys from a type where the value type of the key extends the given `Condition`.
316
386
 
@@ -343,21 +413,19 @@ type StringKeysAndUndefined = ConditionalKeys<Example, string | undefined>;
343
413
 
344
414
  @category Object
345
415
  */
346
- type ConditionalKeys<Base, Condition> = NonNullable<
347
- // Wrap in `NonNullable` to strip away the `undefined` type from the produced union.
416
+ type ConditionalKeys<Base, Condition> =
348
417
  {
349
418
  // Map through all the keys of the given base type.
350
- [Key in keyof Base]:
419
+ [Key in keyof Base]-?:
351
420
  // Pick only keys with types extending the given `Condition` type.
352
421
  Base[Key] extends Condition
353
- // Retain this key since the condition passes.
354
- ? Key
422
+ // Retain this key
423
+ // If the value for the key extends never, only include it if `Condition` also extends never
424
+ ? IfNever<Base[Key], IfNever<Condition, Key, never>, Key>
355
425
  // Discard this key since the condition fails.
356
426
  : never;
357
-
358
427
  // Convert the produced object into a union type of the keys which passed the conditional test.
359
- }[keyof Base]
360
- >;
428
+ }[keyof Base];
361
429
 
362
430
  /**
363
431
  Exclude keys from a shape that matches the given `Condition`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-types",
3
- "version": "1.12.2",
3
+ "version": "1.12.4",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -12,8 +12,7 @@
12
12
  "sideEffects": false,
13
13
  "types": "build/index.d.ts",
14
14
  "files": [
15
- "build",
16
- "enable-all-context-types.d.ts"
15
+ "build"
17
16
  ],
18
17
  "publishConfig": {
19
18
  "registry": "https://registry.npmjs.org/",
@@ -29,12 +28,12 @@
29
28
  "*.{js,ts}": "yarn lint"
30
29
  },
31
30
  "devDependencies": {
32
- "@types/node": "^20.10.6",
33
- "eslint": "^8.56.0",
31
+ "@types/node": "^20.17.1",
32
+ "eslint": "^8.57.1",
34
33
  "eslint-config-sdk": "0.0.0",
35
34
  "tsup": "^7.3.0",
36
- "type-fest": "^4.9.0",
37
- "typescript": "^5.3.3"
35
+ "type-fest": "^4.26.1",
36
+ "typescript": "^5.6.3"
38
37
  },
39
38
  "yoshiFlowLibrary": {
40
39
  "buildEsmWithBabel": true
@@ -59,5 +58,5 @@
59
58
  "wallaby": {
60
59
  "autoDetect": true
61
60
  },
62
- "falconPackageHash": "d792d8c125ad82e0e2f2102bf625213e93dd91dfc8255b91a58a222a"
61
+ "falconPackageHash": "8469d4de3131c4bcc8fc47df34db04866cf00b50a23e8a32eb180346"
63
62
  }
@@ -1,8 +0,0 @@
1
- // eslint-disable-next-line require-extensions/require-extensions
2
- import type { Host } from './build/index.d.ts';
3
-
4
- declare global {
5
- interface ContextualClient {
6
- host: Host;
7
- }
8
- }