@wix/sdk-types 1.13.7 → 1.13.9

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
@@ -223,6 +223,46 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
223
223
  */
224
224
  type EmptyObject = {[emptyObjectSymbol]?: never};
225
225
 
226
+ /**
227
+ Extract all optional keys from the given type.
228
+
229
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
230
+
231
+ @example
232
+ ```
233
+ import type {OptionalKeysOf, Except} from 'type-fest';
234
+
235
+ interface User {
236
+ name: string;
237
+ surname: string;
238
+
239
+ luckyNumber?: number;
240
+ }
241
+
242
+ const REMOVE_FIELD = Symbol('remove field symbol');
243
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
244
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
245
+ };
246
+
247
+ const update1: UpdateOperation<User> = {
248
+ name: 'Alice'
249
+ };
250
+
251
+ const update2: UpdateOperation<User> = {
252
+ name: 'Bob',
253
+ luckyNumber: REMOVE_FIELD
254
+ };
255
+ ```
256
+
257
+ @category Utilities
258
+ */
259
+ type OptionalKeysOf<BaseType extends object> =
260
+ BaseType extends unknown // For distributing `BaseType`
261
+ ? (keyof {
262
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
263
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
264
+ : never; // Should never happen
265
+
226
266
  /**
227
267
  Extract all required keys from the given type.
228
268
 
@@ -247,11 +287,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
247
287
 
248
288
  @category Utilities
249
289
  */
250
- type RequiredKeysOf<BaseType extends object> = Exclude<{
251
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
252
- ? Key
253
- : never
254
- }[keyof BaseType], undefined>;
290
+ type RequiredKeysOf<BaseType extends object> =
291
+ BaseType extends unknown // For distributing `BaseType`
292
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
293
+ : never; // Should never happen
255
294
 
256
295
  /**
257
296
  Returns a boolean for whether the given type is `never`.
@@ -659,45 +698,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
659
698
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
660
699
  );
661
700
 
662
- /**
663
- Extract all optional keys from the given type.
664
-
665
- This is useful when you want to create a new type that contains different type values for the optional keys only.
666
-
667
- @example
668
- ```
669
- import type {OptionalKeysOf, Except} from 'type-fest';
670
-
671
- interface User {
672
- name: string;
673
- surname: string;
674
-
675
- luckyNumber?: number;
676
- }
677
-
678
- const REMOVE_FIELD = Symbol('remove field symbol');
679
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
680
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
681
- };
682
-
683
- const update1: UpdateOperation<User> = {
684
- name: 'Alice'
685
- };
686
-
687
- const update2: UpdateOperation<User> = {
688
- name: 'Bob',
689
- luckyNumber: REMOVE_FIELD
690
- };
691
- ```
692
-
693
- @category Utilities
694
- */
695
- type OptionalKeysOf<BaseType extends object> = Exclude<{
696
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
697
- ? never
698
- : Key
699
- }[keyof BaseType], undefined>;
700
-
701
701
  /**
702
702
  Merges user specified options with default options.
703
703
 
@@ -759,7 +759,11 @@ type ApplyDefaultOptions<
759
759
  IfNever<SpecifiedOptions, Defaults,
760
760
  Simplify<Merge<Defaults, {
761
761
  [Key in keyof SpecifiedOptions
762
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
762
+ as Key extends OptionalKeysOf<Options>
763
+ ? Extract<SpecifiedOptions[Key], undefined> extends never
764
+ ? Key
765
+ : never
766
+ : Key
763
767
  ]: SpecifiedOptions[Key]
764
768
  }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
765
769
  >>;
@@ -1057,4 +1061,60 @@ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalT
1057
1061
  alpha: true;
1058
1062
  } ? T : never;
1059
1063
 
1060
- 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 };
1064
+ /**
1065
+ * Extracts the first part of a dot-separated string.
1066
+ * @template T - The input string type
1067
+ * @example
1068
+ * // Returns "foo"
1069
+ * type Result = Head<"foo.bar.baz">
1070
+ */
1071
+ type Head<T extends string> = T extends `${infer First}.${string}` ? First : T;
1072
+ /**
1073
+ * Extracts everything after the first dot in a dot-separated string.
1074
+ * Returns 'never' if there is no dot.
1075
+ * @template T - The input string type
1076
+ * @example
1077
+ * // Returns "bar.baz"
1078
+ * type Result = Tail<"foo.bar.baz">
1079
+ */
1080
+ type Tail<T extends string> = T extends `${string}.${infer Rest}` ? Rest : never;
1081
+ /**
1082
+ * Extracts the element type from an array type, ensuring it's non-nullable.
1083
+ * Returns 'never' if the input type is not an array.
1084
+ * @template T - The potential array type
1085
+ * @example
1086
+ * // Returns string
1087
+ * type Result = OptionalArrayElementType<string[]>
1088
+ */
1089
+ type OptionalArrayElementType<T> = T extends (infer U)[] ? NonNullable<U> : never;
1090
+ /**
1091
+ * Creates a new type where specified dot-notation paths are made non-nullable,
1092
+ * while maintaining the original structure of the object.
1093
+ * The behavior is conditional based on the global SDK type mode.
1094
+ * @template T - The input object type
1095
+ * @template K - The dot-notation path(s) to make non-nullable
1096
+ * @example
1097
+ * // Makes user.name and user.profile.email non-nullable
1098
+ * type Result = NonNullablePaths<MyType, "user.name" | "user.profile.email">
1099
+ */
1100
+ type NonNullablePaths<T, K extends string> = T extends object ? {
1101
+ [P in K & keyof T]: NonNullable<T[P] extends readonly unknown[] | null | undefined ? NonNullablePaths<OptionalArrayElementType<T[P]>, Tail<Extract<K, `${P}.${string}`>>>[] : NonNullablePaths<T[P], Tail<Extract<K, `${P}.${string}`>>>>;
1102
+ } & {
1103
+ [P in keyof T as P extends K ? never : P]?: P extends Head<K> ? T[P] extends readonly unknown[] | null | undefined ? NonNullablePaths<OptionalArrayElementType<T[P]>, Tail<Extract<K, `${P}.${string}`>>>[] : NonNullablePaths<T[P], Tail<Extract<K, `${P}.${string}`>>> : T[P];
1104
+ } : T;
1105
+ declare global {
1106
+ /**
1107
+ * A global interface to set the type mode for the SDK.
1108
+ * @example
1109
+ * ```ts
1110
+ * declare global {
1111
+ * interface SDKTypeMode {
1112
+ * strict: true;
1113
+ * }
1114
+ * }
1115
+ */
1116
+ interface SDKTypeMode {
1117
+ }
1118
+ }
1119
+
1120
+ 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 NonNullablePaths, type OptionalArrayElementType, 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
@@ -223,6 +223,46 @@ Unfortunately, `Record<string, never>`, `Record<keyof any, never>` and `Record<n
223
223
  */
224
224
  type EmptyObject = {[emptyObjectSymbol]?: never};
225
225
 
226
+ /**
227
+ Extract all optional keys from the given type.
228
+
229
+ This is useful when you want to create a new type that contains different type values for the optional keys only.
230
+
231
+ @example
232
+ ```
233
+ import type {OptionalKeysOf, Except} from 'type-fest';
234
+
235
+ interface User {
236
+ name: string;
237
+ surname: string;
238
+
239
+ luckyNumber?: number;
240
+ }
241
+
242
+ const REMOVE_FIELD = Symbol('remove field symbol');
243
+ type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
244
+ [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
245
+ };
246
+
247
+ const update1: UpdateOperation<User> = {
248
+ name: 'Alice'
249
+ };
250
+
251
+ const update2: UpdateOperation<User> = {
252
+ name: 'Bob',
253
+ luckyNumber: REMOVE_FIELD
254
+ };
255
+ ```
256
+
257
+ @category Utilities
258
+ */
259
+ type OptionalKeysOf<BaseType extends object> =
260
+ BaseType extends unknown // For distributing `BaseType`
261
+ ? (keyof {
262
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never
263
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
264
+ : never; // Should never happen
265
+
226
266
  /**
227
267
  Extract all required keys from the given type.
228
268
 
@@ -247,11 +287,10 @@ const validator2 = createValidation<User>('surname', value => value.length < 25)
247
287
 
248
288
  @category Utilities
249
289
  */
250
- type RequiredKeysOf<BaseType extends object> = Exclude<{
251
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
252
- ? Key
253
- : never
254
- }[keyof BaseType], undefined>;
290
+ type RequiredKeysOf<BaseType extends object> =
291
+ BaseType extends unknown // For distributing `BaseType`
292
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>>
293
+ : never; // Should never happen
255
294
 
256
295
  /**
257
296
  Returns a boolean for whether the given type is `never`.
@@ -659,45 +698,6 @@ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (
659
698
  IsAny<T> extends true ? TypeIfAny : TypeIfNotAny
660
699
  );
661
700
 
662
- /**
663
- Extract all optional keys from the given type.
664
-
665
- This is useful when you want to create a new type that contains different type values for the optional keys only.
666
-
667
- @example
668
- ```
669
- import type {OptionalKeysOf, Except} from 'type-fest';
670
-
671
- interface User {
672
- name: string;
673
- surname: string;
674
-
675
- luckyNumber?: number;
676
- }
677
-
678
- const REMOVE_FIELD = Symbol('remove field symbol');
679
- type UpdateOperation<Entity extends object> = Except<Partial<Entity>, OptionalKeysOf<Entity>> & {
680
- [Key in OptionalKeysOf<Entity>]?: Entity[Key] | typeof REMOVE_FIELD;
681
- };
682
-
683
- const update1: UpdateOperation<User> = {
684
- name: 'Alice'
685
- };
686
-
687
- const update2: UpdateOperation<User> = {
688
- name: 'Bob',
689
- luckyNumber: REMOVE_FIELD
690
- };
691
- ```
692
-
693
- @category Utilities
694
- */
695
- type OptionalKeysOf<BaseType extends object> = Exclude<{
696
- [Key in keyof BaseType]: BaseType extends Record<Key, BaseType[Key]>
697
- ? never
698
- : Key
699
- }[keyof BaseType], undefined>;
700
-
701
701
  /**
702
702
  Merges user specified options with default options.
703
703
 
@@ -759,7 +759,11 @@ type ApplyDefaultOptions<
759
759
  IfNever<SpecifiedOptions, Defaults,
760
760
  Simplify<Merge<Defaults, {
761
761
  [Key in keyof SpecifiedOptions
762
- as Key extends OptionalKeysOf<Options> ? undefined extends SpecifiedOptions[Key] ? never : Key : Key
762
+ as Key extends OptionalKeysOf<Options>
763
+ ? Extract<SpecifiedOptions[Key], undefined> extends never
764
+ ? Key
765
+ : never
766
+ : Key
763
767
  ]: SpecifiedOptions[Key]
764
768
  }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
765
769
  >>;
@@ -1057,4 +1061,60 @@ type IsExposed<T, Scope extends Exposure> = Scope extends 'public' ? T : globalT
1057
1061
  alpha: true;
1058
1062
  } ? T : never;
1059
1063
 
1060
- 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 };
1064
+ /**
1065
+ * Extracts the first part of a dot-separated string.
1066
+ * @template T - The input string type
1067
+ * @example
1068
+ * // Returns "foo"
1069
+ * type Result = Head<"foo.bar.baz">
1070
+ */
1071
+ type Head<T extends string> = T extends `${infer First}.${string}` ? First : T;
1072
+ /**
1073
+ * Extracts everything after the first dot in a dot-separated string.
1074
+ * Returns 'never' if there is no dot.
1075
+ * @template T - The input string type
1076
+ * @example
1077
+ * // Returns "bar.baz"
1078
+ * type Result = Tail<"foo.bar.baz">
1079
+ */
1080
+ type Tail<T extends string> = T extends `${string}.${infer Rest}` ? Rest : never;
1081
+ /**
1082
+ * Extracts the element type from an array type, ensuring it's non-nullable.
1083
+ * Returns 'never' if the input type is not an array.
1084
+ * @template T - The potential array type
1085
+ * @example
1086
+ * // Returns string
1087
+ * type Result = OptionalArrayElementType<string[]>
1088
+ */
1089
+ type OptionalArrayElementType<T> = T extends (infer U)[] ? NonNullable<U> : never;
1090
+ /**
1091
+ * Creates a new type where specified dot-notation paths are made non-nullable,
1092
+ * while maintaining the original structure of the object.
1093
+ * The behavior is conditional based on the global SDK type mode.
1094
+ * @template T - The input object type
1095
+ * @template K - The dot-notation path(s) to make non-nullable
1096
+ * @example
1097
+ * // Makes user.name and user.profile.email non-nullable
1098
+ * type Result = NonNullablePaths<MyType, "user.name" | "user.profile.email">
1099
+ */
1100
+ type NonNullablePaths<T, K extends string> = T extends object ? {
1101
+ [P in K & keyof T]: NonNullable<T[P] extends readonly unknown[] | null | undefined ? NonNullablePaths<OptionalArrayElementType<T[P]>, Tail<Extract<K, `${P}.${string}`>>>[] : NonNullablePaths<T[P], Tail<Extract<K, `${P}.${string}`>>>>;
1102
+ } & {
1103
+ [P in keyof T as P extends K ? never : P]?: P extends Head<K> ? T[P] extends readonly unknown[] | null | undefined ? NonNullablePaths<OptionalArrayElementType<T[P]>, Tail<Extract<K, `${P}.${string}`>>>[] : NonNullablePaths<T[P], Tail<Extract<K, `${P}.${string}`>>> : T[P];
1104
+ } : T;
1105
+ declare global {
1106
+ /**
1107
+ * A global interface to set the type mode for the SDK.
1108
+ * @example
1109
+ * ```ts
1110
+ * declare global {
1111
+ * interface SDKTypeMode {
1112
+ * strict: true;
1113
+ * }
1114
+ * }
1115
+ */
1116
+ interface SDKTypeMode {
1117
+ }
1118
+ }
1119
+
1120
+ 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 NonNullablePaths, type OptionalArrayElementType, 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.13.7",
3
+ "version": "1.13.9",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Ronny Ringel",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "scripts": {
22
22
  "build": "tsup",
23
- "test": ":",
23
+ "test": "tsup --config tsup.test.config.ts",
24
24
  "lint": "eslint --max-warnings=0 .",
25
25
  "typecheck": "tsc --noEmit"
26
26
  },
@@ -31,12 +31,12 @@
31
31
  "@wix/monitoring-types": "^0.9.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@types/node": "^20.17.28",
34
+ "@types/node": "^20.17.30",
35
35
  "eslint": "^8.57.1",
36
36
  "eslint-config-sdk": "0.0.0",
37
37
  "tsup": "^7.3.0",
38
- "type-fest": "^4.38.0",
39
- "typescript": "^5.8.2"
38
+ "type-fest": "^4.39.1",
39
+ "typescript": "^5.8.3"
40
40
  },
41
41
  "eslintConfig": {
42
42
  "extends": "sdk"
@@ -58,5 +58,5 @@
58
58
  "wallaby": {
59
59
  "autoDetect": true
60
60
  },
61
- "falconPackageHash": "5688a2fb60ca00fdff1bb2246ee2332e1797a484df1b74e7181de008"
61
+ "falconPackageHash": "2fa1b5c41ad68972714dbbca1ce6e7c9151222df65273708160b69b8"
62
62
  }