@teamkeel/functions-runtime 0.219.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/dist/index.d.ts +286 -0
- package/dist/index.js +25432 -0
- package/package.json +44 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
declare module '@teamkeel/functions-runtime/constraints' {
|
|
2
|
+
export type StringConstraint = string | {
|
|
3
|
+
startsWith?: string;
|
|
4
|
+
endsWith?: string;
|
|
5
|
+
oneOf?: string[];
|
|
6
|
+
contains?: string;
|
|
7
|
+
notEquals?: string;
|
|
8
|
+
equals?: string;
|
|
9
|
+
};
|
|
10
|
+
export type NumberConstraint = number | {
|
|
11
|
+
greaterThan?: number;
|
|
12
|
+
greaterThanOrEquals?: number;
|
|
13
|
+
lessThan?: number;
|
|
14
|
+
lessThanOrEquals?: number;
|
|
15
|
+
equals?: number;
|
|
16
|
+
notEquals?: number;
|
|
17
|
+
};
|
|
18
|
+
export type BooleanConstraint = boolean | {
|
|
19
|
+
equals?: boolean;
|
|
20
|
+
notEquals?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type DateConstraint = Date | {
|
|
23
|
+
equals?: Date;
|
|
24
|
+
before?: Date;
|
|
25
|
+
onOrBefore?: Date;
|
|
26
|
+
after?: Date;
|
|
27
|
+
onOrAfter?: Date;
|
|
28
|
+
};
|
|
29
|
+
export type EnumConstraint = StringConstraint;
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
declare module '@teamkeel/functions-runtime/db/query' {
|
|
33
|
+
export type SqlQueryParts = SqlQueryPart[];
|
|
34
|
+
export type SqlQueryPart = RawSql | SqlInput;
|
|
35
|
+
export type RawSql = {
|
|
36
|
+
type: "sql";
|
|
37
|
+
value: string;
|
|
38
|
+
};
|
|
39
|
+
export type SqlInput = {
|
|
40
|
+
type: "input";
|
|
41
|
+
value: any;
|
|
42
|
+
};
|
|
43
|
+
export function rawSql(sql: string): SqlQueryPart;
|
|
44
|
+
export function sqlIdentifier(identifier: string, identifierField?: string | null): SqlQueryPart;
|
|
45
|
+
export function sqlInput(input: any): SqlQueryPart;
|
|
46
|
+
export function sqlInputArray(inputs: any[]): SqlQueryPart[];
|
|
47
|
+
export function sqlAddSeparator(parts: SqlQueryPart[], separator: SqlQueryPart): SqlQueryPart[];
|
|
48
|
+
export function sqlAddSeparatorAndFlatten(parts: SqlQueryPart[][], separator: SqlQueryPart): SqlQueryPart[];
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
declare module '@teamkeel/functions-runtime/db/resolver' {
|
|
52
|
+
import { SqlQueryParts } from "@teamkeel/functions-runtime/db/query";
|
|
53
|
+
export interface QueryResolver {
|
|
54
|
+
runQuery(query: SqlQueryParts): Promise<QueryResult>;
|
|
55
|
+
}
|
|
56
|
+
export interface QueryResult {
|
|
57
|
+
rows: QueryResultRow[];
|
|
58
|
+
}
|
|
59
|
+
export interface QueryResultRow {
|
|
60
|
+
[column: string]: any;
|
|
61
|
+
}
|
|
62
|
+
export function queryResolverFromEnv(env: Record<string, string | undefined>): QueryResolver;
|
|
63
|
+
export class PgQueryResolver implements QueryResolver {
|
|
64
|
+
private readonly pool;
|
|
65
|
+
constructor(config: {
|
|
66
|
+
connectionString: string;
|
|
67
|
+
});
|
|
68
|
+
runQuery(query: SqlQueryParts): Promise<QueryResult>;
|
|
69
|
+
private toQuery;
|
|
70
|
+
}
|
|
71
|
+
export class AwsRdsDataClientQueryResolver implements QueryResolver {
|
|
72
|
+
private readonly client;
|
|
73
|
+
private readonly dbClusterResourceArn;
|
|
74
|
+
private readonly dbCredentialsSecretArn;
|
|
75
|
+
private readonly dbName;
|
|
76
|
+
constructor(config: {
|
|
77
|
+
region: string;
|
|
78
|
+
dbClusterResourceArn: string;
|
|
79
|
+
dbCredentialsSecretArn: string;
|
|
80
|
+
dbName: string;
|
|
81
|
+
});
|
|
82
|
+
runQuery(query: SqlQueryParts): Promise<QueryResult>;
|
|
83
|
+
private toQuery;
|
|
84
|
+
private toDataApiFormat;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
declare module '@teamkeel/functions-runtime/fetch/index' {
|
|
89
|
+
import { RequestInit } from "node-fetch";
|
|
90
|
+
type RequestOpts = Omit<RequestInit, "referrer">;
|
|
91
|
+
const _default: (uri: string, opts: RequestOpts) => Promise<import("node-fetch").Response>;
|
|
92
|
+
export default _default;
|
|
93
|
+
|
|
94
|
+
}
|
|
95
|
+
declare module '@teamkeel/functions-runtime/handler/index' {
|
|
96
|
+
import { Config } from "@teamkeel/functions-runtime/types";
|
|
97
|
+
const startRuntimeServer: ({ functions, api }: Config) => void;
|
|
98
|
+
export default startRuntimeServer;
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
declare module '@teamkeel/functions-runtime/index' {
|
|
102
|
+
import Query, { ChainableQuery } from "@teamkeel/functions-runtime/query";
|
|
103
|
+
import * as QueryConstraints from "@teamkeel/functions-runtime/constraints";
|
|
104
|
+
import Logger, { ConsoleTransport, Level as LogLevel } from "@teamkeel/functions-runtime/logger/index";
|
|
105
|
+
import { Identity } from "@teamkeel/functions-runtime/types";
|
|
106
|
+
export * from "@teamkeel/functions-runtime/returnTypes";
|
|
107
|
+
export * from "@teamkeel/functions-runtime/db/resolver";
|
|
108
|
+
import { queryResolverFromEnv } from "@teamkeel/functions-runtime/db/resolver";
|
|
109
|
+
export { Query, ChainableQuery, QueryConstraints, Logger, ConsoleTransport, LogLevel, Identity, queryResolverFromEnv, };
|
|
110
|
+
|
|
111
|
+
}
|
|
112
|
+
declare module '@teamkeel/functions-runtime/logger/index' {
|
|
113
|
+
export enum Level {
|
|
114
|
+
Info = "info",
|
|
115
|
+
Error = "error",
|
|
116
|
+
Debug = "debug",
|
|
117
|
+
Warn = "warn",
|
|
118
|
+
Success = "success"
|
|
119
|
+
}
|
|
120
|
+
export interface LoggerOptions {
|
|
121
|
+
transport?: Transport;
|
|
122
|
+
colorize?: boolean;
|
|
123
|
+
timestamps?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface Transport {
|
|
126
|
+
log: (msg: Msg, level: Level, options: LoggerOptions) => void;
|
|
127
|
+
}
|
|
128
|
+
export class ConsoleTransport implements Transport {
|
|
129
|
+
log: (msg: Msg, level: Level, options: LoggerOptions) => void;
|
|
130
|
+
}
|
|
131
|
+
type Msg = any;
|
|
132
|
+
export default class Logger {
|
|
133
|
+
private readonly options;
|
|
134
|
+
constructor(opts?: LoggerOptions);
|
|
135
|
+
log: (msg: Msg, level?: Level) => void;
|
|
136
|
+
}
|
|
137
|
+
export {};
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
declare module '@teamkeel/functions-runtime/query' {
|
|
141
|
+
import { Conditions, ChainedQueryOpts, QueryOpts, Input, OrderClauses } from "@teamkeel/functions-runtime/types";
|
|
142
|
+
import * as ReturnTypes from "@teamkeel/functions-runtime/returnTypes";
|
|
143
|
+
export class ChainableQuery<T extends IDer> {
|
|
144
|
+
private readonly tableName;
|
|
145
|
+
private readonly conditions;
|
|
146
|
+
private orderClauses;
|
|
147
|
+
private readonly queryResolver;
|
|
148
|
+
private readonly logger;
|
|
149
|
+
constructor({ tableName, queryResolver, conditions, logger, }: ChainedQueryOpts<T>);
|
|
150
|
+
orWhere: (conditions: Conditions<T>) => ChainableQuery<T>;
|
|
151
|
+
all: () => Promise<ReturnTypes.FunctionListResponse<T>>;
|
|
152
|
+
findOne: () => Promise<ReturnTypes.FunctionGetResponse<T>>;
|
|
153
|
+
order: (clauses: OrderClauses<T>) => ChainableQuery<T>;
|
|
154
|
+
private appendConditions;
|
|
155
|
+
private execute;
|
|
156
|
+
}
|
|
157
|
+
interface IDer {
|
|
158
|
+
id: string;
|
|
159
|
+
}
|
|
160
|
+
export default class Query<T extends IDer> {
|
|
161
|
+
private readonly tableName;
|
|
162
|
+
private readonly conditions;
|
|
163
|
+
private readonly queryResolver;
|
|
164
|
+
private readonly logger;
|
|
165
|
+
constructor({ tableName, queryResolver, logger }: QueryOpts);
|
|
166
|
+
create: (inputs: Partial<T>) => Promise<ReturnTypes.FunctionCreateResponse<T>>;
|
|
167
|
+
where: (conditions: Conditions<T>) => ChainableQuery<T>;
|
|
168
|
+
delete: (id: string) => Promise<ReturnTypes.FunctionDeleteResponse<T>>;
|
|
169
|
+
findOne: (conditions: Conditions<T>) => Promise<ReturnTypes.FunctionGetResponse<T>>;
|
|
170
|
+
update: (id: string, inputs: Input<T>) => Promise<ReturnTypes.FunctionUpdateResponse<T>>;
|
|
171
|
+
all: () => Promise<ReturnTypes.FunctionListResponse<T>>;
|
|
172
|
+
private execute;
|
|
173
|
+
}
|
|
174
|
+
export {};
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
declare module '@teamkeel/functions-runtime/queryBuilders/index' {
|
|
178
|
+
import { Conditions, Constraints, OrderClauses, OrderDirection } from "@teamkeel/functions-runtime/types";
|
|
179
|
+
import { SqlQueryParts } from "@teamkeel/functions-runtime/db/query";
|
|
180
|
+
export const buildSelectStatement: <T>(tableName: string, conditions: Partial<{ [K in keyof T]: Constraints<T[K]>; }>[], order?: Partial<Record<keyof T, OrderDirection>>, limit?: number) => SqlQueryParts;
|
|
181
|
+
export const buildCreateStatement: <T>(tableName: string, inputs: Partial<T>) => SqlQueryParts;
|
|
182
|
+
export const buildUpdateStatement: <T>(tableName: string, id: string, inputs: Partial<T>) => SqlQueryParts;
|
|
183
|
+
export const buildDeleteStatement: <T>(tableName: string, id: string) => SqlQueryParts;
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
declare module '@teamkeel/functions-runtime/returnTypes' {
|
|
187
|
+
export interface ValidationError {
|
|
188
|
+
field: string;
|
|
189
|
+
message: string;
|
|
190
|
+
code: string;
|
|
191
|
+
}
|
|
192
|
+
export interface ExecutionError {
|
|
193
|
+
message: string;
|
|
194
|
+
stack: string;
|
|
195
|
+
}
|
|
196
|
+
export type FunctionError = ValidationError | ExecutionError;
|
|
197
|
+
export interface FunctionCreateResponse<T> {
|
|
198
|
+
object?: T;
|
|
199
|
+
errors?: FunctionError[];
|
|
200
|
+
}
|
|
201
|
+
export interface FunctionGetResponse<T> {
|
|
202
|
+
object?: T;
|
|
203
|
+
errors?: FunctionError[];
|
|
204
|
+
}
|
|
205
|
+
export interface FunctionDeleteResponse<T> {
|
|
206
|
+
success: boolean;
|
|
207
|
+
errors?: FunctionError[];
|
|
208
|
+
}
|
|
209
|
+
export interface FunctionListResponse<T> {
|
|
210
|
+
collection: T[];
|
|
211
|
+
errors?: FunctionError[];
|
|
212
|
+
}
|
|
213
|
+
export interface FunctionUpdateResponse<T> {
|
|
214
|
+
object?: T;
|
|
215
|
+
errors?: FunctionError[];
|
|
216
|
+
}
|
|
217
|
+
export interface FunctionAuthenticateResponse {
|
|
218
|
+
identityId?: string;
|
|
219
|
+
identityCreated: boolean;
|
|
220
|
+
errors?: FunctionError[];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
}
|
|
224
|
+
declare module '@teamkeel/functions-runtime/staticAnalysis/analyse' {
|
|
225
|
+
export interface AnalyseOptions {
|
|
226
|
+
path: string;
|
|
227
|
+
}
|
|
228
|
+
const _default: (opts: AnalyseOptions) => Promise<import("@structured-types/api").PropTypes>;
|
|
229
|
+
export default _default;
|
|
230
|
+
|
|
231
|
+
}
|
|
232
|
+
declare module '@teamkeel/functions-runtime/staticAnalysis/cli' {
|
|
233
|
+
export {};
|
|
234
|
+
|
|
235
|
+
}
|
|
236
|
+
declare module '@teamkeel/functions-runtime/types' {
|
|
237
|
+
import { StringConstraint, BooleanConstraint, NumberConstraint, DateConstraint, EnumConstraint } from "@teamkeel/functions-runtime/constraints";
|
|
238
|
+
import { Logger } from "@teamkeel/functions-runtime/index";
|
|
239
|
+
import { QueryResolver } from "@teamkeel/functions-runtime/db/resolver";
|
|
240
|
+
export interface QueryOpts {
|
|
241
|
+
tableName: string;
|
|
242
|
+
queryResolver: QueryResolver;
|
|
243
|
+
logger: Logger;
|
|
244
|
+
}
|
|
245
|
+
export interface ChainedQueryOpts<T> extends QueryOpts {
|
|
246
|
+
conditions: Conditions<T>[];
|
|
247
|
+
}
|
|
248
|
+
export type Constraints<T> = T extends String ? StringConstraint : T extends Boolean ? BooleanConstraint : T extends Number ? NumberConstraint : T extends Date ? DateConstraint : EnumConstraint;
|
|
249
|
+
export type Input<T> = Record<keyof T, unknown>;
|
|
250
|
+
export type Conditions<T> = Partial<{
|
|
251
|
+
[K in keyof T]: Constraints<T[K]>;
|
|
252
|
+
}>;
|
|
253
|
+
export interface BuiltInFields {
|
|
254
|
+
id: string;
|
|
255
|
+
createdAt: Date;
|
|
256
|
+
updatedAt: Date;
|
|
257
|
+
}
|
|
258
|
+
export type OrderDirection = "ASC" | "DESC";
|
|
259
|
+
export type OrderClauses<T> = Partial<Record<keyof T, OrderDirection>>;
|
|
260
|
+
export interface Identity {
|
|
261
|
+
id: string;
|
|
262
|
+
email: string;
|
|
263
|
+
}
|
|
264
|
+
export interface CustomFunction {
|
|
265
|
+
call: any;
|
|
266
|
+
}
|
|
267
|
+
export interface Config {
|
|
268
|
+
functions: Record<string, CustomFunction>;
|
|
269
|
+
api: unknown;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
}
|
|
273
|
+
declare module '@teamkeel/functions-runtime/util/camelCaser' {
|
|
274
|
+
const _default: (input: string) => string;
|
|
275
|
+
export default _default;
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
declare module '@teamkeel/functions-runtime/util/snakeCaser' {
|
|
279
|
+
const _default: (input: string) => string;
|
|
280
|
+
export default _default;
|
|
281
|
+
|
|
282
|
+
}
|
|
283
|
+
declare module '@teamkeel/functions-runtime' {
|
|
284
|
+
import main = require('@teamkeel/functions-runtime/index');
|
|
285
|
+
export = main;
|
|
286
|
+
}
|