@retailcrm/embed-ui-v1-types 0.5.23-alpha.2 → 0.5.23-alpha.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/context-doc.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import type { ContextSchema } from './context'
2
2
  import type { TranslationList } from './doc'
3
3
 
4
+ export type ObjectDescription<T extends object> = {
5
+ [K in keyof T]: TranslationList
6
+ }
7
+
4
8
  export type ContextSchemaDescription<S extends ContextSchema> = {
5
9
  [K in keyof S]: {
6
10
  description: TranslationList;
package/context.d.ts CHANGED
@@ -1,12 +1,22 @@
1
- import type { If, IsTilda, Maybe } from './scaffolding'
2
-
3
- export type Field<Type, Readonly extends boolean = false> = {
4
- accepts (value: unknown): value is Type;
5
- defaults (): Type;
1
+ import type {
2
+ AnyFunction,
3
+ AnyFunctionList,
4
+ If,
5
+ IsTilda,
6
+ Maybe,
7
+ MaybePromise,
8
+ Pojo,
9
+ Predicate,
10
+ Scalar,
11
+ } from './scaffolding'
12
+
13
+ export type Field<T, Readonly extends boolean = false> = {
14
+ accepts (value: unknown): value is T;
15
+ defaults (): T;
6
16
  readonly: Readonly;
7
17
  }
8
18
 
9
- export type ReadonlyField<Type = unknown> = Field<Type, true>
19
+ export type ReadonlyField<T = unknown> = Field<T, true>
10
20
 
11
21
  export type TypeOf<F> = F extends Field<infer T>
12
22
  ? T
@@ -28,8 +38,6 @@ export type ContextSchemaList = {
28
38
  [key: string]: ContextSchema;
29
39
  }
30
40
 
31
- export type ContextSchemaMap = ContextSchemaList
32
-
33
41
  export type Context<S extends ContextSchema> = {
34
42
  [F in keyof S]: TypeOf<S[F]>;
35
43
  }
@@ -210,4 +218,33 @@ export type CustomFieldAccessor = {
210
218
  code: string,
211
219
  handler: (value: CustomFieldType) => void
212
220
  ): void | (() => void);
213
- }
221
+ }
222
+
223
+ export type Action<F> = F extends (...args: infer A) => infer R
224
+ ? A extends Array<Scalar | Pojo>
225
+ ? R extends MaybePromise<infer RR> ? (...args: A) => Promise<RR> : never
226
+ : never
227
+ : never;
228
+
229
+ export type ActionList<S extends ActionSchema> = {
230
+ [M in keyof S]: Action<ExtractFunction<S[M]>>;
231
+ } extends infer O ? O : never;
232
+
233
+ export type ActionAccepts<Fn> = Fn extends (...args: infer A) => unknown ? A : never;
234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
235
+ export type ActionExpects<Fn> = Fn extends (...args: any) => infer R ? R extends Promise<infer RR> ? RR : R : never;
236
+ export type ActionDescriptor<Fn extends AnyFunction> = {
237
+ accepts: Predicate<ActionAccepts<Fn>> & { members: {name: string, type: string}[] };
238
+ expects: Predicate<ActionExpects<Fn>> & { type: string };
239
+ }
240
+
241
+ export type ExtractFunction<T> = T extends {
242
+ accepts: Predicate<infer A>;
243
+ expects: Predicate<infer R>;
244
+ }
245
+ ? (...args: A) => R
246
+ : never;
247
+
248
+ export type ActionSchema<L extends AnyFunctionList = AnyFunctionList> = {
249
+ [M in keyof L]: ActionDescriptor<L[M]>;
250
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@retailcrm/embed-ui-v1-types",
3
3
  "description": "Basic types declarations for RetailCRM JS API",
4
4
  "type": "module",
5
- "version": "0.5.23-alpha.2",
5
+ "version": "0.5.23-alpha.4",
6
6
  "license": "MIT",
7
7
  "author": "RetailDriverLLC <integration@retailcrm.ru>",
8
8
  "repository": "git@github.com:retailcrm/embed-ui.git",
package/scaffolding.d.ts CHANGED
@@ -1,12 +1,28 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export type AnyFunction = (...args: any[]) => any
3
+ export type AnyFunctionList = { [name: string]: AnyFunction; }
4
+
1
5
  export type IsExact<A, B> = A extends B ? (B extends A ? true : false) : false;
2
6
  export type IsTilda<A> = IsExact<A, '~'>;
3
7
 
4
8
  export type If<Condition, Then, Else> = Condition extends true ? Then : Else;
5
9
 
6
10
  export type Maybe<T> = T | null
11
+ export type MaybePromise<T> = T | Promise<T>
12
+
13
+ export type None = Record<string, never>
14
+
15
+ export type Scalar = string | number | boolean | null | undefined
16
+ export type Pojo = {
17
+ [key: string]: Scalar | Pojo | Array<Scalar | Pojo>
18
+ }
19
+
20
+ export type Predicate<T = unknown> = (value: unknown) => value is T
21
+
22
+ export type Simplify<T> = { [K in keyof T]: T[K] }
7
23
 
8
24
  export type UnionToArray<T, U = T> = [T] extends [never]
9
25
  ? []
10
26
  : T extends T
11
27
  ? [T, ...UnionToArray<Exclude<U, T>>]
12
- : []
28
+ : []