@wix/sdk-types 1.12.8 → 1.13.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.
package/build/index.d.mts CHANGED
@@ -334,6 +334,65 @@ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends Excep
334
334
  ? Partial<Record<KeysType, never>>
335
335
  : {});
336
336
 
337
+ /**
338
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
339
+
340
+ @example
341
+ ```
342
+ import type {Simplify} from 'type-fest';
343
+
344
+ type PositionProps = {
345
+ top: number;
346
+ left: number;
347
+ };
348
+
349
+ type SizeProps = {
350
+ width: number;
351
+ height: number;
352
+ };
353
+
354
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
355
+ type Props = Simplify<PositionProps & SizeProps>;
356
+ ```
357
+
358
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
359
+
360
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
361
+
362
+ @example
363
+ ```
364
+ import type {Simplify} from 'type-fest';
365
+
366
+ interface SomeInterface {
367
+ foo: number;
368
+ bar?: string;
369
+ baz: number | undefined;
370
+ }
371
+
372
+ type SomeType = {
373
+ foo: number;
374
+ bar?: string;
375
+ baz: number | undefined;
376
+ };
377
+
378
+ const literal = {foo: 123, bar: 'hello', baz: 456};
379
+ const someType: SomeType = literal;
380
+ const someInterface: SomeInterface = literal;
381
+
382
+ function fn(object: Record<string, unknown>): void {}
383
+
384
+ fn(literal); // Good: literal object type is sealed
385
+ fn(someType); // Good: type is sealed
386
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
387
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
388
+ ```
389
+
390
+ @link https://github.com/microsoft/TypeScript/issues/15300
391
+ @see SimplifyDeep
392
+ @category Object
393
+ */
394
+ type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
395
+
337
396
  /**
338
397
  Returns a boolean for whether the given type is `never`.
339
398
 
@@ -535,4 +594,56 @@ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
535
594
  host: Host;
536
595
  } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
537
596
 
538
- 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 HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
597
+ /**
598
+ * Expose fields based on the current exposure toggle.
599
+ * @param T - The type to expose fields from.
600
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
601
+ * @example Exposure toggle not set:
602
+ * ```ts
603
+ * type MyType = {
604
+ * publicField: string;
605
+ * alphaField: string;
606
+ * };
607
+ *
608
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
609
+ * // ExposedType = { publicField: string; }
610
+ * ```
611
+ * @example Exposure toggle set to alpha:
612
+ * ```ts
613
+ * declare global {
614
+ * interface SDKExposureToggle {
615
+ * alpha: true;
616
+ * }
617
+ * }
618
+ *
619
+ * type MyType = {
620
+ * publicField: string;
621
+ * alphaField: string;
622
+ * };
623
+ *
624
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
625
+ * // ExposedType = { publicField: string; alphaField: string; }
626
+ */
627
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
628
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
629
+ }>;
630
+ declare global {
631
+ /**
632
+ * A global interface to set the exposure toggle for the SDK.
633
+ * @example
634
+ * ```ts
635
+ * declare global {
636
+ * interface SDKExposureToggle {
637
+ * alpha: true;
638
+ * }
639
+ * }
640
+ */
641
+ interface SDKExposureToggle {
642
+ }
643
+ }
644
+ type Exposure = 'alpha' | 'public';
645
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
646
+ alpha: true;
647
+ } ? T : never;
648
+
649
+ 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 ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
package/build/index.d.ts CHANGED
@@ -334,6 +334,65 @@ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends Excep
334
334
  ? Partial<Record<KeysType, never>>
335
335
  : {});
336
336
 
337
+ /**
338
+ Useful to flatten the type output to improve type hints shown in editors. And also to transform an interface into a type to aide with assignability.
339
+
340
+ @example
341
+ ```
342
+ import type {Simplify} from 'type-fest';
343
+
344
+ type PositionProps = {
345
+ top: number;
346
+ left: number;
347
+ };
348
+
349
+ type SizeProps = {
350
+ width: number;
351
+ height: number;
352
+ };
353
+
354
+ // In your editor, hovering over `Props` will show a flattened object with all the properties.
355
+ type Props = Simplify<PositionProps & SizeProps>;
356
+ ```
357
+
358
+ Sometimes it is desired to pass a value as a function argument that has a different type. At first inspection it may seem assignable, and then you discover it is not because the `value`'s type definition was defined as an interface. In the following example, `fn` requires an argument of type `Record<string, unknown>`. If the value is defined as a literal, then it is assignable. And if the `value` is defined as type using the `Simplify` utility the value is assignable. But if the `value` is defined as an interface, it is not assignable because the interface is not sealed and elsewhere a non-string property could be added to the interface.
359
+
360
+ If the type definition must be an interface (perhaps it was defined in a third-party npm package), then the `value` can be defined as `const value: Simplify<SomeInterface> = ...`. Then `value` will be assignable to the `fn` argument. Or the `value` can be cast as `Simplify<SomeInterface>` if you can't re-declare the `value`.
361
+
362
+ @example
363
+ ```
364
+ import type {Simplify} from 'type-fest';
365
+
366
+ interface SomeInterface {
367
+ foo: number;
368
+ bar?: string;
369
+ baz: number | undefined;
370
+ }
371
+
372
+ type SomeType = {
373
+ foo: number;
374
+ bar?: string;
375
+ baz: number | undefined;
376
+ };
377
+
378
+ const literal = {foo: 123, bar: 'hello', baz: 456};
379
+ const someType: SomeType = literal;
380
+ const someInterface: SomeInterface = literal;
381
+
382
+ function fn(object: Record<string, unknown>): void {}
383
+
384
+ fn(literal); // Good: literal object type is sealed
385
+ fn(someType); // Good: type is sealed
386
+ fn(someInterface); // Error: Index signature for type 'string' is missing in type 'someInterface'. Because `interface` can be re-opened
387
+ fn(someInterface as Simplify<SomeInterface>); // Good: transform an `interface` into a `type`
388
+ ```
389
+
390
+ @link https://github.com/microsoft/TypeScript/issues/15300
391
+ @see SimplifyDeep
392
+ @category Object
393
+ */
394
+ type Simplify<T> = {[KeyType in keyof T]: T[KeyType]} & {};
395
+
337
396
  /**
338
397
  Returns a boolean for whether the given type is `never`.
339
398
 
@@ -535,4 +594,56 @@ type MaybeContext<T extends Descriptors> = globalThis.ContextualClient extends {
535
594
  host: Host;
536
595
  } ? BuildDescriptors<T, globalThis.ContextualClient['host']> : T;
537
596
 
538
- 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 HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
597
+ /**
598
+ * Expose fields based on the current exposure toggle.
599
+ * @param T - The type to expose fields from.
600
+ * @param FieldsScope - A map of fields to their exposure scope, missing fields are considered public.
601
+ * @example Exposure toggle not set:
602
+ * ```ts
603
+ * type MyType = {
604
+ * publicField: string;
605
+ * alphaField: string;
606
+ * };
607
+ *
608
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
609
+ * // ExposedType = { publicField: string; }
610
+ * ```
611
+ * @example Exposure toggle set to alpha:
612
+ * ```ts
613
+ * declare global {
614
+ * interface SDKExposureToggle {
615
+ * alpha: true;
616
+ * }
617
+ * }
618
+ *
619
+ * type MyType = {
620
+ * publicField: string;
621
+ * alphaField: string;
622
+ * };
623
+ *
624
+ * type ExposedType = ExposeFieldsBasedOnToggle<MyType, { alphaField: 'alpha' }>;
625
+ * // ExposedType = { publicField: string; alphaField: string; }
626
+ */
627
+ type ExposeFieldsBasedOnToggle<T extends Record<string, any>, FieldsScope extends Partial<Record<keyof T, Exposure>>> = Simplify<{
628
+ [K in keyof T as IsExposed<K, FieldsScope[K] extends Exposure ? FieldsScope[K] : 'public'>]: T[K];
629
+ }>;
630
+ declare global {
631
+ /**
632
+ * A global interface to set the exposure toggle for the SDK.
633
+ * @example
634
+ * ```ts
635
+ * declare global {
636
+ * interface SDKExposureToggle {
637
+ * alpha: true;
638
+ * }
639
+ * }
640
+ */
641
+ interface SDKExposureToggle {
642
+ }
643
+ }
644
+ type Exposure = 'alpha' | 'public';
645
+ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalThis.SDKExposureToggle extends {
646
+ alpha: true;
647
+ } ? T : never;
648
+
649
+ 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 ExposeFieldsBasedOnToggle, type HTTPMethod, type Host, type HostModule, type HostModuleAPI, type HttpClient, type HttpResponse, type MaybeContext, type Method, type PublicMetadata, type RESTFunctionDescriptor, type RequestContext, type RequestOptions, type RequestOptionsFactory, type RestModuleMeta, SERVICE_PLUGIN_ERROR_TYPE, type ServicePluginContract, ServicePluginDefinition, type ServicePluginMethodInput, type ServicePluginMethodMetadata };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/sdk-types",
3
- "version": "1.12.8",
3
+ "version": "1.13.0",
4
4
  "license": "UNLICENSED",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -58,5 +58,5 @@
58
58
  "wallaby": {
59
59
  "autoDetect": true
60
60
  },
61
- "falconPackageHash": "63b5f65cadbdc43d77cb40e3bcfb19670a4185b479de5316ea38bf58"
61
+ "falconPackageHash": "d5217e053bcbd31cbd1e1df8a6961bd38ab9ab0a5d54fd9ac456c89c"
62
62
  }