@botpress/sdk 1.2.0 → 1.2.1

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.
@@ -1,12 +1,12 @@
1
1
 
2
- > @botpress/sdk@1.2.0 build /home/runner/work/botpress/botpress/packages/sdk
2
+ > @botpress/sdk@1.2.1 build /home/runner/work/botpress/botpress/packages/sdk
3
3
  > pnpm build:type && pnpm build:node
4
4
 
5
5
 
6
- > @botpress/sdk@1.2.0 build:type /home/runner/work/botpress/botpress/packages/sdk
6
+ > @botpress/sdk@1.2.1 build:type /home/runner/work/botpress/botpress/packages/sdk
7
7
  > tsc --emitDeclarationOnly --declaration
8
8
 
9
9
 
10
- > @botpress/sdk@1.2.0 build:node /home/runner/work/botpress/botpress/packages/sdk
10
+ > @botpress/sdk@1.2.1 build:node /home/runner/work/botpress/botpress/packages/sdk
11
11
  > ts-node -T build.ts
12
12
 
@@ -1,5 +1,5 @@
1
1
  import * as client from '@botpress/client';
2
- import { Join, UnionToIntersection, Merge, ValueOf, Split, Cast } from '../../utils/type-utils';
2
+ import { Join, UnionToIntersection, Merge, ValueOf, Split, Cast, ToSealedRecord } from '../../utils/type-utils';
3
3
  import { BaseBot } from '../generic';
4
4
  /**
5
5
  * 0. Definitions
@@ -17,48 +17,34 @@ export type IntegrationInstanceUserDefinition = IntegrationInstanceDefinition['u
17
17
  /**
18
18
  * 1. Enumerations
19
19
  */
20
- export type EnumerateActions<TBot extends BaseBot> = UnionToIntersection<{
20
+ type ActionKey<TIntegrationName extends string, TActionName extends string> = string extends TIntegrationName ? string : string extends TActionName ? string : Join<[TIntegrationName, ':', TActionName]>;
21
+ export type EnumerateActions<TBot extends BaseBot> = ToSealedRecord<UnionToIntersection<{
21
22
  [TIntegrationName in keyof TBot['integrations']]: {
22
- [TActionName in keyof TBot['integrations'][TIntegrationName]['actions'] as Join<[
23
- TIntegrationName,
24
- ':',
25
- TActionName
26
- ]>]: TBot['integrations'][TIntegrationName]['actions'][TActionName];
23
+ [TActionName in keyof TBot['integrations'][TIntegrationName]['actions'] as ActionKey<Cast<TIntegrationName, string>, Cast<TActionName, string>>]: TBot['integrations'][TIntegrationName]['actions'][TActionName];
27
24
  };
28
- }[keyof TBot['integrations']]>;
29
- export type EnumerateEvents<TBot extends BaseBot> = UnionToIntersection<{
25
+ }[keyof TBot['integrations']]> & {}>;
26
+ type EventKey<TIntegrationName extends string, TEventName extends string> = string extends TIntegrationName ? string : string extends TEventName ? string : Join<[TIntegrationName, ':', TEventName]>;
27
+ export type EnumerateEvents<TBot extends BaseBot> = ToSealedRecord<UnionToIntersection<{
30
28
  [TIntegrationName in keyof TBot['integrations']]: {
31
- [TEventName in keyof TBot['integrations'][TIntegrationName]['events'] as Join<[
32
- TIntegrationName,
33
- ':',
34
- TEventName
35
- ]>]: TBot['integrations'][TIntegrationName]['events'][TEventName];
29
+ [TEventName in keyof TBot['integrations'][TIntegrationName]['events'] as EventKey<Cast<TIntegrationName, string>, Cast<TEventName, string>>]: TBot['integrations'][TIntegrationName]['events'][TEventName];
36
30
  };
37
- }[keyof TBot['integrations']]> & (string extends keyof TBot['events'] ? {} : {
31
+ }[keyof TBot['integrations']]> & {
38
32
  [TEventName in keyof TBot['events']]: TBot['events'][TEventName];
39
- });
40
- export type EnumerateChannels<TBot extends BaseBot> = UnionToIntersection<{
33
+ }>;
34
+ type ChannelKey<TIntegrationName extends string, TChannelName extends string> = string extends TIntegrationName ? string : string extends TChannelName ? string : Join<[TIntegrationName, ':', TChannelName]>;
35
+ export type EnumerateChannels<TBot extends BaseBot> = ToSealedRecord<UnionToIntersection<{
41
36
  [TIntegrationName in keyof TBot['integrations']]: {
42
- [TChannelName in keyof TBot['integrations'][TIntegrationName]['channels'] as Join<[
43
- TIntegrationName,
44
- ':',
45
- TChannelName
46
- ]>]: TBot['integrations'][TIntegrationName]['channels'][TChannelName];
37
+ [TChannelName in keyof TBot['integrations'][TIntegrationName]['channels'] as ChannelKey<Cast<TIntegrationName, string>, Cast<TChannelName, string>>]: TBot['integrations'][TIntegrationName]['channels'][TChannelName];
47
38
  };
48
- }[keyof TBot['integrations']]>;
49
- export type EnumerateMessages<TBot extends BaseBot> = UnionToIntersection<{
39
+ }[keyof TBot['integrations']]> & {}>;
40
+ type MessageKey<TIntegrationName extends string, TChannelName extends string, TMessageName extends string> = string extends TIntegrationName ? string : string extends TChannelName ? string : string extends TMessageName ? string : Join<[TIntegrationName, ':', TChannelName, ':', TMessageName]>;
41
+ export type EnumerateMessages<TBot extends BaseBot> = ToSealedRecord<UnionToIntersection<{
50
42
  [TIntegrationName in keyof TBot['integrations']]: {
51
43
  [TChannelName in keyof TBot['integrations'][TIntegrationName]['channels']]: {
52
- [TMessageName in keyof TBot['integrations'][TIntegrationName]['channels'][TChannelName]['messages'] as Join<[
53
- TIntegrationName,
54
- ':',
55
- TChannelName,
56
- ':',
57
- TMessageName
58
- ]>]: TBot['integrations'][TIntegrationName]['channels'][TChannelName]['messages'][TMessageName];
44
+ [TMessageName in keyof TBot['integrations'][TIntegrationName]['channels'][TChannelName]['messages'] as MessageKey<Cast<TIntegrationName, string>, Cast<TChannelName, string>, Cast<TMessageName, string>>]: TBot['integrations'][TIntegrationName]['channels'][TChannelName]['messages'][TMessageName];
59
45
  };
60
46
  }[keyof TBot['integrations'][TIntegrationName]['channels']];
61
- }[keyof TBot['integrations']]>;
47
+ }[keyof TBot['integrations']]> & {}>;
62
48
  export type GetMessages<TBot extends BaseBot> = {
63
49
  [K in keyof EnumerateMessages<TBot> as Cast<Split<K, ':'>[2], string>]: EnumerateMessages<TBot>[K];
64
50
  };
@@ -81,3 +67,4 @@ export type MessageResponse<TBot extends BaseBot, TMessage extends keyof GetMess
81
67
  }>;
82
68
  }>;
83
69
  };
70
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,13 @@
1
1
  import { BaseIntegration } from '../integration/generic';
2
+ import * as utils from '../utils/type-utils';
2
3
  export type BaseIntegrations = Record<string, BaseIntegration>;
3
4
  export type BaseBot = {
4
5
  integrations: BaseIntegrations;
5
6
  events: Record<string, any>;
6
7
  states: Record<string, any>;
7
8
  };
9
+ export type MakeBot<B extends Partial<BaseBot>> = {
10
+ integrations: utils.Default<B['integrations'], BaseBot['integrations']>;
11
+ events: utils.Default<B['events'], BaseBot['events']>;
12
+ states: utils.Default<B['states'], BaseBot['states']>;
13
+ };
@@ -1,3 +1,4 @@
1
+ import * as utils from '../utils/type-utils';
1
2
  export type BaseIntegration = {
2
3
  name: string;
3
4
  version: string;
@@ -28,3 +29,20 @@ export type BaseIntegration = {
28
29
  };
29
30
  entities: Record<string, any>;
30
31
  };
32
+ export type MakeChannel<C extends Partial<BaseIntegration['channels'][string]>> = {
33
+ messages: utils.Default<C['messages'], BaseIntegration['channels'][string]['messages']>;
34
+ message: utils.Default<C['message'], BaseIntegration['channels'][string]['message']>;
35
+ conversation: utils.Default<C['conversation'], BaseIntegration['channels'][string]['conversation']>;
36
+ };
37
+ export type MakeIntegration<I extends Partial<BaseIntegration>> = {
38
+ name: utils.Default<I['name'], BaseIntegration['name']>;
39
+ version: utils.Default<I['version'], BaseIntegration['version']>;
40
+ configuration: utils.Default<I['configuration'], BaseIntegration['configuration']>;
41
+ configurations: utils.Default<I['configurations'], BaseIntegration['configurations']>;
42
+ actions: utils.Default<I['actions'], BaseIntegration['actions']>;
43
+ channels: utils.Default<I['channels'], BaseIntegration['channels']>;
44
+ events: utils.Default<I['events'], BaseIntegration['events']>;
45
+ states: utils.Default<I['states'], BaseIntegration['states']>;
46
+ user: utils.Default<I['user'], BaseIntegration['user']>;
47
+ entities: utils.Default<I['entities'], BaseIntegration['entities']>;
48
+ };
@@ -4,9 +4,18 @@ export type Cast<T, U> = T extends U ? T : U;
4
4
  export type Writable<T> = {
5
5
  -readonly [K in keyof T]: T[K];
6
6
  };
7
- export type Extends<T, U> = T extends U ? true : false;
7
+ export type Default<T, U> = undefined extends T ? U : T;
8
+ export type IsExtend<T, U> = T extends U ? true : false;
8
9
  export type IsEqual<T, U> = T extends U ? (U extends T ? true : false) : false;
9
- export type Expect<T extends true> = T;
10
+ export type AssertExtends<A, _B extends A> = true;
11
+ export type AssertTrue<_T extends true> = true;
12
+ export type AssertAll<_T extends true[]> = true;
10
13
  export type Join<S extends (string | number | symbol)[]> = S extends [infer H, ...infer T] ? `${Cast<H, string>}${Join<Cast<T, string[]>>}` : S extends [infer H] ? Cast<H, string> : '';
11
14
  export type Split<S extends string | number | symbol, D extends string> = S extends `${infer H}${D}${infer T}` ? [H, ...Split<Cast<T, string>, D>] : [S];
12
15
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
16
+ /**
17
+ * removes string index signature from Record
18
+ */
19
+ export type ToSealedRecord<R extends Record<string, any>> = {
20
+ [K in keyof R as string extends K ? never : K]: R[K];
21
+ };
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/sdk",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Botpress SDK",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",