Skip to content

Commit 98f2459

Browse files
authored
Improve types (#10)
1 parent d65eb09 commit 98f2459

File tree

3 files changed

+83
-72
lines changed

3 files changed

+83
-72
lines changed

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@8base/functions-types",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "Types for 8base Custom Functions",
55
"author": "8base",
66
"license": "MIT",
@@ -10,11 +10,8 @@
1010
"typecheck": "tsc --noEmit",
1111
"postversion": "git push --follow-tags"
1212
},
13-
"devDependencies": {
14-
"typescript": "^4.0.3"
15-
},
1613
"dependencies": {
17-
"@graphql-typed-document-node/core": "^3.1.0",
18-
"graphql": "^15.3.0"
14+
"@graphql-typed-document-node/core": "^3.2.0",
15+
"graphql": "^15.8.0"
1916
}
2017
}

types/index.d.ts

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
import { DocumentNode } from "graphql";
22
import { TypedDocumentNode } from "@graphql-typed-document-node/core";
33

4+
export type AnyObject = Record<string, any>;
5+
export type HttpHeaders = Record<string, string | undefined>;
6+
7+
export interface IDBObject {
8+
id: string;
9+
createdAt: Date;
10+
updatedAt: Date;
11+
deletedAt: number;
12+
createdById: string | null;
13+
}
14+
415
export type GqlRequest = <
5-
ResultT = Record<string, any>,
6-
VariablesT = Record<string, any>
16+
ResultT = AnyObject,
17+
VariablesT = AnyObject
718
>(
8-
query: DocumentNode | TypedDocumentNode<ResultT, VariablesT>,
19+
query: string | DocumentNode | TypedDocumentNode<ResultT, VariablesT>,
920
variables?: VariablesT,
1021
options?: {
1122
checkPermissions?: boolean;
12-
headers?: Record<string, any>;
23+
headers?: HttpHeaders
1324
}
1425
) => Promise<ResultT>;
1526

1627
export type FunctionContext = {
1728
api: {
1829
gqlRequest: GqlRequest;
30+
url: string;
1931
};
2032
invokeFunction: <
2133
ResponseT extends InvokeFunctionResponse = InvokeFunctionResponse,
22-
ArgsT = Record<string, any>
34+
ArgsT = AnyObject
2335
>(
2436
name: string,
2537
args?: ArgsT,
@@ -28,6 +40,7 @@ export type FunctionContext = {
2840
workspaceId: string;
2941
environmentId: string;
3042
environmentName: string;
43+
userId?: string | null;
3144
};
3245

3346
export type InvokeFunctionResponse<ResultT = any> = {
@@ -37,97 +50,103 @@ export type InvokeFunctionResponse<ResultT = any> = {
3750
};
3851

3952
export type FunctionEvent<
40-
DataT = Record<string, any>,
41-
ExtendObjectT = Record<string, any>
53+
DataT = AnyObject,
54+
ExtendObjectT = AnyObject
4255
> = {
4356
data: DataT;
4457
body: string;
45-
headers: Record<string, string | undefined>;
58+
headers: HttpHeaders;
4659
} & ExtendObjectT;
4760

4861
export type FunctionResponse<
49-
DataT = Record<string, any>,
50-
ExtendObjectT = Record<string, any>,
51-
ErrorT = Record<string, any>
62+
DataT = AnyObject,
63+
ExtendObjectT = AnyObject,
64+
ErrorT = AnyObject
5265
> = Promise<(FunctionResponseObject<DataT, ErrorT> & ExtendObjectT) | void>;
5366

5467
export type FunctionResponseObject<
55-
DataT = Record<string, any>,
56-
ErrorT = Record<string, any>
68+
DataT = AnyObject,
69+
ErrorT = AnyObject
5770
> = {
5871
data?: DataT;
5972
errors?: ErrorT[];
6073
};
6174

62-
export type TriggerResponse<DataT = Record<string, any>> =
63-
FunctionResponseObject<DataT>;
64-
6575
export type BeforeCreateTriggerFunctionEvent<
66-
DataT = Record<string, any>,
67-
ExtendObjectT = Record<string, any>
76+
DataT = AnyObject,
77+
ExtendObjectT = AnyObject
6878
> = {
6979
data: DataT;
70-
headers: Record<string, string | undefined>;
80+
headers: HttpHeaders;
7181
} & ExtendObjectT;
7282

7383
export type BeforeUpdateTriggerFunctionEvent<
74-
DataT = Record<string, any>,
75-
FilterT = Record<string, any>,
76-
OriginalObjectT = Record<string, any>,
77-
ExtendObjectT = Record<string, any>
84+
DataT = AnyObject,
85+
OriginalObjectT = AnyObject,
86+
FilterT = AnyObject,
87+
ExtendObjectT = AnyObject
7888
> = {
7989
data: DataT;
80-
filter: FilterT;
81-
originalObject: OriginalObjectT & { id: string };
82-
headers: Record<string, string | undefined>;
90+
filter?: FilterT;
91+
force?: boolean;
92+
destroyDetached?: boolean;
93+
originalObject: OriginalObjectT & IDBObject;
94+
headers: HttpHeaders;
8395
} & ExtendObjectT;
8496

8597
export type BeforeDeleteTriggerFunctionEvent<
86-
FilterT = Record<string, any>,
87-
OriginalObjectT = Record<string, any>,
88-
ExtendObjectT = Record<string, any>
98+
OriginalObjectT = AnyObject,
99+
FilterT = AnyObject,
100+
ExtendObjectT = AnyObject
89101
> = {
90102
filter: FilterT;
91-
originalObject: OriginalObjectT & { id: string };
92-
headers: Record<string, string | undefined>;
103+
force?: boolean;
104+
destroyDeleted?: boolean;
105+
originalObject: OriginalObjectT & IDBObject;
106+
headers: HttpHeaders;
93107
} & ExtendObjectT;
94108

95109
export type AfterCreateTriggerFunctionEvent<
96-
DataT = Record<string, any>,
97-
OriginalDataT = Record<string, any>,
98-
ExtendObjectT = Record<string, any>
110+
DataT = AnyObject,
111+
OriginalDataT = AnyObject,
112+
ExtendObjectT = AnyObject
99113
> = {
100-
data: DataT & { id: string };
114+
data: DataT & IDBObject;
101115
originalData: OriginalDataT;
102-
body: string;
103-
headers: Record<string, string | undefined>;
116+
headers: HttpHeaders;
104117
} & ExtendObjectT;
105118

106119
export type AfterUpdateTriggerFunctionEvent<
107-
DataT = Record<string, any>,
108-
OriginalDataT = Record<string, any>,
109-
OriginalObjectT = Record<string, any>,
110-
ExtendObjectT = Record<string, any>
120+
DataT = AnyObject,
121+
OriginalDataT = AnyObject,
122+
OriginalObjectT = AnyObject,
123+
ExtendObjectT = AnyObject
111124
> = {
112-
data: DataT & { id: string };
125+
data: DataT & IDBObject;
113126
originalData: OriginalDataT;
114-
originalObject: OriginalObjectT & { id: string };
115-
headers: Record<string, string | undefined>;
127+
originalObject: OriginalObjectT & IDBObject;
128+
headers: HttpHeaders;
116129
} & ExtendObjectT;
117130

118131
export type AfterDeleteTriggerFunctionEvent<
119-
DataT = Record<string, any>,
120-
OriginalDataT = Record<string, any>,
121-
OriginalObjectT = Record<string, any>,
122-
ExtendObjectT = Record<string, any>
132+
DataT = AnyObject,
133+
OriginalDataT = AnyObject,
134+
OriginalObjectT = AnyObject,
135+
ExtendObjectT = AnyObject
123136
> = {
124-
data: DataT & { id: string };
125-
originalData: OriginalDataT;
126-
originalObject: OriginalObjectT & { id: string };
127-
headers: Record<string, string | undefined>;
137+
data: DataT & IDBObject;
138+
originalObject: OriginalObjectT & IDBObject;
139+
headers: HttpHeaders;
128140
} & ExtendObjectT;
129141

142+
export type WebhookFunctionEvent<T extends string = string> = {
143+
body: string;
144+
headers: HttpHeaders;
145+
pathParameters?: Record<T, string | undefined>;
146+
};
147+
130148
export type WebhookResponse = {
131149
statusCode: number;
150+
headers?: HttpHeaders;
132151
body?: string;
133152
};

yarn.lock

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@
22
# yarn lockfile v1
33

44

5-
"@graphql-typed-document-node/core@^3.1.0":
6-
version "3.1.0"
7-
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.0.tgz#0eee6373e11418bfe0b5638f654df7a4ca6a3950"
8-
integrity sha512-wYn6r8zVZyQJ6rQaALBEln5B1pzxb9shV5Ef97kTvn6yVGrqyXVnDqnU24MXnFubR+rZjBY9NWuxX3FB2sTsjg==
9-
10-
graphql@^15.3.0:
11-
version "15.3.0"
12-
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.3.0.tgz#3ad2b0caab0d110e3be4a5a9b2aa281e362b5278"
13-
integrity sha512-GTCJtzJmkFLWRfFJuoo9RWWa/FfamUHgiFosxi/X1Ani4AVWbeyBenZTNX6dM+7WSbbFfTo/25eh0LLkwHMw2w==
14-
15-
typescript@^4.0.3:
16-
version "4.0.3"
17-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.3.tgz#153bbd468ef07725c1df9c77e8b453f8d36abba5"
18-
integrity sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==
5+
"@graphql-typed-document-node/core@^3.2.0":
6+
version "3.2.0"
7+
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.2.0.tgz#5f3d96ec6b2354ad6d8a28bf216a1d97b5426861"
8+
integrity sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==
9+
10+
graphql@^15.8.0:
11+
version "15.8.0"
12+
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.8.0.tgz#33410e96b012fa3bdb1091cc99a94769db212b38"
13+
integrity sha512-5gghUc24tP9HRznNpV2+FIoq3xKkj5dTQqf4v0CpdPbFVwFkWoxOM+o+2OC9ZSvjEMTjfmG9QT+gcvggTwW1zw==

0 commit comments

Comments
 (0)