@teamkeel/functions-runtime 0.412.0 → 0.413.0-next.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.
- package/dist/index.cjs +2772 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +733 -0
- package/dist/index.d.ts +733 -0
- package/dist/index.js +2747 -0
- package/dist/index.js.map +1 -0
- package/package.json +26 -5
- package/.env.test +0 -2
- package/compose.yaml +0 -10
- package/src/Duration.js +0 -40
- package/src/Duration.test.js +0 -34
- package/src/File.js +0 -295
- package/src/ModelAPI.js +0 -377
- package/src/ModelAPI.test.js +0 -1428
- package/src/QueryBuilder.js +0 -184
- package/src/QueryContext.js +0 -90
- package/src/RequestHeaders.js +0 -21
- package/src/TimePeriod.js +0 -89
- package/src/TimePeriod.test.js +0 -148
- package/src/applyAdditionalQueryConstraints.js +0 -22
- package/src/applyJoins.js +0 -67
- package/src/applyWhereConditions.js +0 -124
- package/src/auditing.js +0 -110
- package/src/auditing.test.js +0 -330
- package/src/camelCasePlugin.js +0 -52
- package/src/casing.js +0 -54
- package/src/casing.test.js +0 -56
- package/src/consts.js +0 -14
- package/src/database.js +0 -244
- package/src/errors.js +0 -160
- package/src/handleJob.js +0 -110
- package/src/handleJob.test.js +0 -270
- package/src/handleRequest.js +0 -153
- package/src/handleRequest.test.js +0 -463
- package/src/handleRoute.js +0 -112
- package/src/handleSubscriber.js +0 -105
- package/src/index.d.ts +0 -317
- package/src/index.js +0 -38
- package/src/parsing.js +0 -113
- package/src/parsing.test.js +0 -140
- package/src/permissions.js +0 -77
- package/src/permissions.test.js +0 -118
- package/src/tracing.js +0 -184
- package/src/tracing.test.js +0 -147
- package/src/tryExecuteFunction.js +0 -91
- package/src/tryExecuteJob.js +0 -29
- package/src/tryExecuteSubscriber.js +0 -17
- package/src/type-utils.js +0 -18
- package/vite.config.js +0 -7
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,733 @@
|
|
|
1
|
+
import * as kysely from 'kysely';
|
|
2
|
+
import { Kysely } from 'kysely';
|
|
3
|
+
export { default as KSUID } from 'ksuid';
|
|
4
|
+
import * as opentelemetry from '@opentelemetry/api';
|
|
5
|
+
|
|
6
|
+
declare namespace ErrorPresets {
|
|
7
|
+
export { NotFoundError$1 as NotFound };
|
|
8
|
+
export { BadRequestError as BadRequest };
|
|
9
|
+
export { UnknownError as Unknown };
|
|
10
|
+
}
|
|
11
|
+
declare class NotFoundError$1 extends Error {
|
|
12
|
+
constructor(message: any);
|
|
13
|
+
errorCode: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* QueryContext is used to store state about the current query, for example
|
|
18
|
+
* which joins have already been applied. It is used by applyJoins and
|
|
19
|
+
* applyWhereConditions to generate consistent table aliases for joins.
|
|
20
|
+
*
|
|
21
|
+
* This class has the concept of a "table path". This is just a list of tables, starting
|
|
22
|
+
* with some "root" table and ending with the table we're currently joining to. So
|
|
23
|
+
* for example if we started with a "product" table and joined from there to "order_item"
|
|
24
|
+
* and then to "order" and then to "customer" the table path would be:
|
|
25
|
+
* ["product", "order_item", "order", "customer"]
|
|
26
|
+
* At this point the "current" table is "customer" and it's alias would be:
|
|
27
|
+
* "product$order_item$order$customer"
|
|
28
|
+
*/
|
|
29
|
+
declare class QueryContext {
|
|
30
|
+
/**
|
|
31
|
+
* @param {string[]} tablePath This is the path from the "root" table to the "current table".
|
|
32
|
+
* @param {import("./ModelAPI").TableConfigMap} tableConfigMap
|
|
33
|
+
* @param {string[]} joins
|
|
34
|
+
*/
|
|
35
|
+
constructor(tablePath: string[], tableConfigMap: TableConfigMap, joins?: string[]);
|
|
36
|
+
_tablePath: string[];
|
|
37
|
+
_tableConfigMap: {
|
|
38
|
+
[x: string]: {
|
|
39
|
+
[x: string]: RelationshipConfig;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
_joins: string[];
|
|
43
|
+
clone(): QueryContext;
|
|
44
|
+
/**
|
|
45
|
+
* Returns true if, given the current table path, a join to the given
|
|
46
|
+
* table has already been added.
|
|
47
|
+
* @param {string} table
|
|
48
|
+
* @returns {boolean}
|
|
49
|
+
*/
|
|
50
|
+
hasJoin(table: string): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Adds table to the QueryContext's path and registers the join,
|
|
53
|
+
* calls fn, then pops the table off the path.
|
|
54
|
+
* @param {string} table
|
|
55
|
+
* @param {Function} fn
|
|
56
|
+
*/
|
|
57
|
+
withJoin(table: string, fn: Function): void;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the alias that will be used for the current table
|
|
60
|
+
* @returns {string}
|
|
61
|
+
*/
|
|
62
|
+
tableAlias(): string;
|
|
63
|
+
/**
|
|
64
|
+
* Returns the current table name
|
|
65
|
+
* @returns {string}
|
|
66
|
+
*/
|
|
67
|
+
tableName(): string;
|
|
68
|
+
/**
|
|
69
|
+
* Return the TableConfig for the current table
|
|
70
|
+
* @returns {import("./ModelAPI").TableConfig | undefined}
|
|
71
|
+
*/
|
|
72
|
+
tableConfig(): TableConfig | undefined;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
declare class QueryBuilder {
|
|
76
|
+
/**
|
|
77
|
+
* @param {string} tableName
|
|
78
|
+
* @param {import("./QueryContext").QueryContext} context
|
|
79
|
+
* @param {import("kysely").Kysely} db
|
|
80
|
+
*/
|
|
81
|
+
constructor(tableName: string, context: QueryContext, db: kysely.Kysely<any>);
|
|
82
|
+
_tableName: string;
|
|
83
|
+
_context: QueryContext;
|
|
84
|
+
_db: kysely.Kysely<any>;
|
|
85
|
+
_modelName: any;
|
|
86
|
+
where(where: any): QueryBuilder;
|
|
87
|
+
sql(): any;
|
|
88
|
+
update(values: any): Promise<any>;
|
|
89
|
+
delete(): Promise<any>;
|
|
90
|
+
findOne(): Promise<any>;
|
|
91
|
+
findMany(params: any): Promise<any>;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* TableConfig is an object where the keys are relationship field names
|
|
96
|
+
* (which don't exist in the database) and the values are RelationshipConfig
|
|
97
|
+
* objects describing that relationship.
|
|
98
|
+
*/
|
|
99
|
+
type RelationshipConfig = {
|
|
100
|
+
relationshipType: "belongsTo" | "hasMany";
|
|
101
|
+
foreignKey: string;
|
|
102
|
+
referencesTable: string;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* TableConfigMap is mapping of database table names to TableConfig objects
|
|
106
|
+
*/
|
|
107
|
+
type TableConfig = {
|
|
108
|
+
[x: string]: RelationshipConfig;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* RelationshipConfig is a simple representation of a model field that
|
|
112
|
+
* is a relationship. It is used by applyJoins and applyWhereConditions
|
|
113
|
+
* to build the correct query.
|
|
114
|
+
*/
|
|
115
|
+
type TableConfigMap = {
|
|
116
|
+
[x: string]: {
|
|
117
|
+
[x: string]: RelationshipConfig;
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* RelationshipConfig is a simple representation of a model field that
|
|
122
|
+
* is a relationship. It is used by applyJoins and applyWhereConditions
|
|
123
|
+
* to build the correct query.
|
|
124
|
+
* @typedef {{
|
|
125
|
+
* relationshipType: "belongsTo" | "hasMany",
|
|
126
|
+
* foreignKey: string,
|
|
127
|
+
* referencesTable: string,
|
|
128
|
+
* }} RelationshipConfig
|
|
129
|
+
*
|
|
130
|
+
* TableConfig is an object where the keys are relationship field names
|
|
131
|
+
* (which don't exist in the database) and the values are RelationshipConfig
|
|
132
|
+
* objects describing that relationship.
|
|
133
|
+
* @typedef {Object.<string, RelationshipConfig} TableConfig
|
|
134
|
+
*
|
|
135
|
+
* TableConfigMap is mapping of database table names to TableConfig objects
|
|
136
|
+
* @typedef {Object.<string, TableConfig>} TableConfigMap
|
|
137
|
+
*/
|
|
138
|
+
declare class ModelAPI {
|
|
139
|
+
/**
|
|
140
|
+
* @param {string} tableName The name of the table this API is for
|
|
141
|
+
* @param {Function} _ Used to be a function that returns the default values for a row in this table. No longer used.
|
|
142
|
+
* @param {TableConfigMap} tableConfigMap
|
|
143
|
+
*/
|
|
144
|
+
constructor(tableName: string, _: Function, tableConfigMap?: TableConfigMap);
|
|
145
|
+
_tableName: string;
|
|
146
|
+
_tableConfigMap: {
|
|
147
|
+
[x: string]: {
|
|
148
|
+
[x: string]: RelationshipConfig;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
_modelName: any;
|
|
152
|
+
create(values: any): Promise<any>;
|
|
153
|
+
findOne(where?: {}): Promise<any>;
|
|
154
|
+
findMany(params: any): Promise<any>;
|
|
155
|
+
update(where: any, values: any): Promise<any>;
|
|
156
|
+
delete(where: any): Promise<any>;
|
|
157
|
+
where(where: any): QueryBuilder;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface RequestHeadersMap {
|
|
161
|
+
[key: string]: string;
|
|
162
|
+
}
|
|
163
|
+
declare class RequestHeaders {
|
|
164
|
+
private _headers;
|
|
165
|
+
/**
|
|
166
|
+
* @param {{Object.<string, string>}} requestHeaders Map of request headers submitted from the client
|
|
167
|
+
*/
|
|
168
|
+
constructor(requestHeaders: RequestHeadersMap);
|
|
169
|
+
get: Headers["get"];
|
|
170
|
+
has: Headers["has"];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
declare function handleRequest(request: any, config: any): Promise<any>;
|
|
174
|
+
|
|
175
|
+
declare function handleJob(request: any, config: any): Promise<any>;
|
|
176
|
+
|
|
177
|
+
declare function handleSubscriber(request: any, config: any): Promise<any>;
|
|
178
|
+
|
|
179
|
+
declare function handleRoute(request: any, config: any): Promise<any>;
|
|
180
|
+
|
|
181
|
+
declare function handleFlow(request: any, config: any): Promise<any>;
|
|
182
|
+
|
|
183
|
+
declare function useDatabase(): Kysely<any>;
|
|
184
|
+
|
|
185
|
+
declare const PERMISSION_STATE: {
|
|
186
|
+
readonly UNKNOWN: "unknown";
|
|
187
|
+
readonly PERMITTED: "permitted";
|
|
188
|
+
readonly UNPERMITTED: "unpermitted";
|
|
189
|
+
};
|
|
190
|
+
type PermissionState = (typeof PERMISSION_STATE)[keyof typeof PERMISSION_STATE];
|
|
191
|
+
/**
|
|
192
|
+
* Permissions class for managing access control in the runtime
|
|
193
|
+
*/
|
|
194
|
+
declare class Permissions {
|
|
195
|
+
/**
|
|
196
|
+
* Explicitly permit access to an action
|
|
197
|
+
*/
|
|
198
|
+
allow(): void;
|
|
199
|
+
/**
|
|
200
|
+
* Explicitly deny access to an action
|
|
201
|
+
*/
|
|
202
|
+
deny(): never;
|
|
203
|
+
getState(): PermissionState;
|
|
204
|
+
}
|
|
205
|
+
interface CheckBuiltInPermissionsParams {
|
|
206
|
+
rows: any[];
|
|
207
|
+
permissionFns: Array<(rows: any[], ctx: any, db: any) => Promise<boolean>>;
|
|
208
|
+
ctx: any;
|
|
209
|
+
db: any;
|
|
210
|
+
functionName: string;
|
|
211
|
+
}
|
|
212
|
+
declare const checkBuiltInPermissions: ({ rows, permissionFns, ctx, db, functionName, }: CheckBuiltInPermissionsParams) => Promise<void>;
|
|
213
|
+
|
|
214
|
+
declare function getTracer(): opentelemetry.Tracer;
|
|
215
|
+
declare function withSpan(name: any, fn: any): Promise<any>;
|
|
216
|
+
declare function init(): void;
|
|
217
|
+
declare function forceFlush(): Promise<void>;
|
|
218
|
+
declare function spanNameForModelAPI(modelName: any, action: any): string;
|
|
219
|
+
|
|
220
|
+
declare const tracing_forceFlush: typeof forceFlush;
|
|
221
|
+
declare const tracing_getTracer: typeof getTracer;
|
|
222
|
+
declare const tracing_init: typeof init;
|
|
223
|
+
declare const tracing_spanNameForModelAPI: typeof spanNameForModelAPI;
|
|
224
|
+
declare const tracing_withSpan: typeof withSpan;
|
|
225
|
+
declare namespace tracing {
|
|
226
|
+
export { tracing_forceFlush as forceFlush, tracing_getTracer as getTracer, tracing_init as init, tracing_spanNameForModelAPI as spanNameForModelAPI, tracing_withSpan as withSpan };
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type MimeType = "application/json" | "application/gzip" | "application/pdf" | "application/rtf" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "application/vnd.openxmlformats-officedocument.presentationml.presentation" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/vnd.ms-excel" | "application/vnd.ms-powerpoint" | "application/msword" | "application/zip" | "application/xml" | "application/x-7z-compressed" | "application/x-tar" | "image/gif" | "image/jpeg" | "image/svg+xml" | "image/png" | "text/html" | "text/csv" | "text/javascript" | "text/plain" | "text/calendar" | (string & {});
|
|
230
|
+
type InlineFileConstructor = {
|
|
231
|
+
filename: string;
|
|
232
|
+
contentType: MimeType;
|
|
233
|
+
};
|
|
234
|
+
type FileDbRecord = {
|
|
235
|
+
key: string;
|
|
236
|
+
filename: string;
|
|
237
|
+
contentType: string;
|
|
238
|
+
size: number;
|
|
239
|
+
};
|
|
240
|
+
declare class InlineFile {
|
|
241
|
+
protected _filename: string;
|
|
242
|
+
protected _contentType: MimeType;
|
|
243
|
+
protected _contents: Blob | null;
|
|
244
|
+
constructor(input: InlineFileConstructor);
|
|
245
|
+
static fromDataURL(dataURL: string): InlineFile;
|
|
246
|
+
get size(): number;
|
|
247
|
+
get contentType(): string;
|
|
248
|
+
get filename(): string;
|
|
249
|
+
write(buffer: Buffer): void;
|
|
250
|
+
read(): Promise<Buffer>;
|
|
251
|
+
store(expires?: Date | null): Promise<File>;
|
|
252
|
+
}
|
|
253
|
+
declare class File extends InlineFile {
|
|
254
|
+
private _key;
|
|
255
|
+
private _size;
|
|
256
|
+
constructor(input: Partial<FileDbRecord>);
|
|
257
|
+
static fromDbRecord(input: FileDbRecord): File;
|
|
258
|
+
get size(): number;
|
|
259
|
+
get key(): string;
|
|
260
|
+
get isPublic(): boolean;
|
|
261
|
+
read(): Promise<Buffer>;
|
|
262
|
+
store(expires?: Date | null): Promise<File>;
|
|
263
|
+
getPresignedUrl(): Promise<URL>;
|
|
264
|
+
toDbRecord(): FileDbRecord;
|
|
265
|
+
toJSON(): FileDbRecord;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
declare class Duration {
|
|
269
|
+
private _typename;
|
|
270
|
+
private pgInterval;
|
|
271
|
+
private _interval;
|
|
272
|
+
constructor(postgresString: string);
|
|
273
|
+
static fromISOString(isoString: string): Duration;
|
|
274
|
+
toISOString(): string;
|
|
275
|
+
toPostgres(): string;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
type ElementDataType$3 = string | number | boolean | Date;
|
|
279
|
+
type UiElementSelectOne = <TValue extends ElementDataType$3, N extends string>(name: N, options?: BaseInputConfig<TValue> & {
|
|
280
|
+
options: ({
|
|
281
|
+
label: string;
|
|
282
|
+
value: TValue;
|
|
283
|
+
} | TValue)[];
|
|
284
|
+
}) => InputElementResponse<N, TValue>;
|
|
285
|
+
interface UiElementSelectOneApiResponse extends BaseUiInputResponse<"ui.select.single", ElementDataType$3> {
|
|
286
|
+
options: ({
|
|
287
|
+
label: string;
|
|
288
|
+
value: ElementDataType$3;
|
|
289
|
+
} | ElementDataType$3)[];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
type ElementDataType$2 = string;
|
|
293
|
+
type UiElementInputText = InputElement<ElementDataType$2, {
|
|
294
|
+
placeholder?: string;
|
|
295
|
+
multiline?: boolean;
|
|
296
|
+
maxLength?: number;
|
|
297
|
+
minLength?: number;
|
|
298
|
+
}>;
|
|
299
|
+
interface UiElementInputTextApiResponse extends BaseUiInputResponse<"ui.input.text", ElementDataType$2> {
|
|
300
|
+
placeholder?: string;
|
|
301
|
+
multiline?: boolean;
|
|
302
|
+
maxLength?: number;
|
|
303
|
+
minLength?: number;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
type ElementDataType$1 = number;
|
|
307
|
+
type UiElementInputNumber = InputElement<ElementDataType$1, {
|
|
308
|
+
placeholder?: number;
|
|
309
|
+
min?: number;
|
|
310
|
+
max?: number;
|
|
311
|
+
}>;
|
|
312
|
+
interface UiElementInputNumberApiResponse extends BaseUiInputResponse<"ui.input.number", ElementDataType$1> {
|
|
313
|
+
placeholder?: number;
|
|
314
|
+
min?: number;
|
|
315
|
+
max?: number;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
type ElementDataType = boolean;
|
|
319
|
+
type UiElementInputBoolean = InputElement<ElementDataType, {
|
|
320
|
+
mode?: "checkbox" | "switch";
|
|
321
|
+
}>;
|
|
322
|
+
interface UiElementInputBooleanApiResponse extends BaseUiInputResponse<"ui.input.boolean", ElementDataType> {
|
|
323
|
+
mode: "checkbox" | "switch";
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
type UiElementMarkdown = DisplayElement<{
|
|
327
|
+
content: string;
|
|
328
|
+
}>;
|
|
329
|
+
interface UiElementMarkdownApiResponse extends BaseUiDisplayResponse<"ui.display.markdown"> {
|
|
330
|
+
content: string;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
type TableData<T extends Record<string, any>> = {
|
|
334
|
+
data: T[];
|
|
335
|
+
columns?: Array<Extract<keyof T, string>>;
|
|
336
|
+
};
|
|
337
|
+
type UiElementTable = <const T extends Record<string, any>>(options: TableData<T>) => DisplayElementResponse;
|
|
338
|
+
interface UiElementTableApiResponse extends BaseUiDisplayResponse<"ui.display.table"> {
|
|
339
|
+
data: any[];
|
|
340
|
+
columns?: string[];
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
type UiElementDivider = DisplayElement<{}>;
|
|
344
|
+
interface UiElementDividerApiResponse extends BaseUiDisplayResponse<"ui.display.divider"> {
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
type UiPage<C extends FlowConfig> = <T extends UIElements, A extends PageActions[] = []>(name: string, options: {
|
|
348
|
+
stage?: ExtractStageKeys<C>;
|
|
349
|
+
title?: string;
|
|
350
|
+
description?: string;
|
|
351
|
+
content: T;
|
|
352
|
+
validate?: (data: ExtractFormData<T>) => Promise<true | string>;
|
|
353
|
+
actions?: A;
|
|
354
|
+
}) => A["length"] extends 0 ? ExtractFormData<T> : {
|
|
355
|
+
data: ExtractFormData<T>;
|
|
356
|
+
action: ActionValue<A[number]>;
|
|
357
|
+
};
|
|
358
|
+
type PageActions = string | {
|
|
359
|
+
label: string;
|
|
360
|
+
value: string;
|
|
361
|
+
mode?: "primary" | "secondary" | "destructive";
|
|
362
|
+
};
|
|
363
|
+
type ActionValue<T> = T extends string ? T : T extends {
|
|
364
|
+
value: infer V;
|
|
365
|
+
} ? V : never;
|
|
366
|
+
type ExtractFormData<T extends UIElements> = {
|
|
367
|
+
[K in Extract<T[number], InputElementResponse<string, any>>["name"]]: Extract<T[number], InputElementResponse<K, any>>["valueType"];
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
type UiElementImage = DisplayElement<{
|
|
371
|
+
url: string;
|
|
372
|
+
alt?: string;
|
|
373
|
+
size?: "thumbnail" | "small" | "medium" | "large" | "full";
|
|
374
|
+
title?: string;
|
|
375
|
+
}>;
|
|
376
|
+
interface UiElementImageApiResponse extends BaseUiDisplayResponse<"ui.display.image"> {
|
|
377
|
+
url: string;
|
|
378
|
+
alt?: string;
|
|
379
|
+
size?: "thumbnail" | "small" | "medium" | "large" | "full";
|
|
380
|
+
title?: string;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
type BannerMode = "info" | "warning" | "error" | "success";
|
|
384
|
+
type UiElementBanner = DisplayElement<{
|
|
385
|
+
title: string;
|
|
386
|
+
description: string;
|
|
387
|
+
mode?: BannerMode;
|
|
388
|
+
}>;
|
|
389
|
+
interface UiElementBannerApiResponse extends BaseUiDisplayResponse<"ui.display.banner"> {
|
|
390
|
+
title: string;
|
|
391
|
+
description: string;
|
|
392
|
+
mode: BannerMode;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
type UiElementHeader = DisplayElement<{
|
|
396
|
+
level: 1 | 2 | 3;
|
|
397
|
+
title?: string;
|
|
398
|
+
description?: string;
|
|
399
|
+
}>;
|
|
400
|
+
interface UiElementHeaderApiResponse extends BaseUiDisplayResponse<"ui.display.header"> {
|
|
401
|
+
level: number;
|
|
402
|
+
title: string;
|
|
403
|
+
description: string;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
type UiElementCode = DisplayElement<{
|
|
407
|
+
code: string;
|
|
408
|
+
language?: string;
|
|
409
|
+
}>;
|
|
410
|
+
interface UiElementCodeApiResponse extends BaseUiDisplayResponse<"ui.display.code"> {
|
|
411
|
+
code: string;
|
|
412
|
+
language?: string;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
type ImageConfig$1 = {
|
|
416
|
+
url: string;
|
|
417
|
+
alt?: string;
|
|
418
|
+
aspectRatio?: number;
|
|
419
|
+
fit?: "cover" | "contain";
|
|
420
|
+
};
|
|
421
|
+
type GridItem = {
|
|
422
|
+
title?: string;
|
|
423
|
+
description?: string;
|
|
424
|
+
image?: ImageConfig$1;
|
|
425
|
+
};
|
|
426
|
+
type GridOptions<T> = {
|
|
427
|
+
data: T[];
|
|
428
|
+
render: (data: T) => GridItem;
|
|
429
|
+
};
|
|
430
|
+
type UiElementGrid = <T extends any>(options: GridOptions<T>) => DisplayElementResponse;
|
|
431
|
+
interface UiElementGridApiResponse extends BaseUiDisplayResponse<"ui.display.grid"> {
|
|
432
|
+
data: any[];
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
type ImageConfig = {
|
|
436
|
+
url: string;
|
|
437
|
+
alt?: string;
|
|
438
|
+
fit?: "cover" | "contain";
|
|
439
|
+
};
|
|
440
|
+
type ListItem = {
|
|
441
|
+
title?: string;
|
|
442
|
+
description?: string;
|
|
443
|
+
image?: ImageConfig;
|
|
444
|
+
};
|
|
445
|
+
type ListOptions<T> = {
|
|
446
|
+
data: T[];
|
|
447
|
+
render: (data: T) => ListItem;
|
|
448
|
+
};
|
|
449
|
+
type UiElementList = <T extends any>(options: ListOptions<T>) => DisplayElementResponse;
|
|
450
|
+
interface UiElementListApiResponse extends BaseUiDisplayResponse<"ui.display.list"> {
|
|
451
|
+
data: any[];
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
interface UI<C extends FlowConfig> {
|
|
455
|
+
page: UiPage<C>;
|
|
456
|
+
display: UiDisplayElements;
|
|
457
|
+
inputs: UiInputsElements;
|
|
458
|
+
select: UiSelectElements;
|
|
459
|
+
}
|
|
460
|
+
type UiInputsElements = {
|
|
461
|
+
text: UiElementInputText;
|
|
462
|
+
number: UiElementInputNumber;
|
|
463
|
+
boolean: UiElementInputBoolean;
|
|
464
|
+
};
|
|
465
|
+
type UiSelectElements = {
|
|
466
|
+
single: UiElementSelectOne;
|
|
467
|
+
};
|
|
468
|
+
type UiDisplayElements = {
|
|
469
|
+
divider: UiElementDivider;
|
|
470
|
+
markdown: UiElementMarkdown;
|
|
471
|
+
header: UiElementHeader;
|
|
472
|
+
banner: UiElementBanner;
|
|
473
|
+
image: UiElementImage;
|
|
474
|
+
code: UiElementCode;
|
|
475
|
+
grid: UiElementGrid;
|
|
476
|
+
list: UiElementList;
|
|
477
|
+
table: UiElementTable;
|
|
478
|
+
};
|
|
479
|
+
type InputElement<TValueType, TConfig extends any = never> = <N extends string>(name: N, options?: BaseInputConfig<TValueType> & TConfig) => InputElementResponse<N, TValueType>;
|
|
480
|
+
type DisplayElement<TConfig extends any = never> = (options?: TConfig) => DisplayElementResponse;
|
|
481
|
+
type UIElements = (InputElementResponse<string, any> | DisplayElementResponse)[];
|
|
482
|
+
interface UIElementBase {
|
|
483
|
+
_type: string;
|
|
484
|
+
}
|
|
485
|
+
interface InputElementResponse<N extends string, V> extends UIElementBase {
|
|
486
|
+
_type: "input";
|
|
487
|
+
name: N;
|
|
488
|
+
valueType: V;
|
|
489
|
+
}
|
|
490
|
+
interface DisplayElementResponse extends UIElementBase {
|
|
491
|
+
_type: "display";
|
|
492
|
+
}
|
|
493
|
+
interface BaseInputConfig<T> {
|
|
494
|
+
label?: string;
|
|
495
|
+
defaultValue?: T;
|
|
496
|
+
helpText?: string;
|
|
497
|
+
optional?: boolean;
|
|
498
|
+
disabled?: boolean;
|
|
499
|
+
validate?: (data: T) => Promise<boolean | string>;
|
|
500
|
+
}
|
|
501
|
+
interface BaseUiInputResponse<K, TData> {
|
|
502
|
+
__type: K;
|
|
503
|
+
name: string;
|
|
504
|
+
label: string;
|
|
505
|
+
defaultValue?: TData;
|
|
506
|
+
helpText?: string;
|
|
507
|
+
optional?: boolean;
|
|
508
|
+
disabled?: boolean;
|
|
509
|
+
}
|
|
510
|
+
interface BaseUiDisplayResponse<K> {
|
|
511
|
+
__type: K;
|
|
512
|
+
}
|
|
513
|
+
type UIApiResponses = {
|
|
514
|
+
display: {
|
|
515
|
+
divider: UiElementDividerApiResponse;
|
|
516
|
+
markdown: UiElementMarkdownApiResponse;
|
|
517
|
+
header: UiElementHeaderApiResponse;
|
|
518
|
+
banner: UiElementBannerApiResponse;
|
|
519
|
+
image: UiElementImageApiResponse;
|
|
520
|
+
code: UiElementCodeApiResponse;
|
|
521
|
+
grid: UiElementGridApiResponse;
|
|
522
|
+
list: UiElementListApiResponse;
|
|
523
|
+
table: UiElementTableApiResponse;
|
|
524
|
+
};
|
|
525
|
+
input: {
|
|
526
|
+
text: UiElementInputTextApiResponse;
|
|
527
|
+
number: UiElementInputNumberApiResponse;
|
|
528
|
+
boolean: UiElementInputBooleanApiResponse;
|
|
529
|
+
};
|
|
530
|
+
select: {
|
|
531
|
+
single: UiElementSelectOneApiResponse;
|
|
532
|
+
};
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
interface FlowContext<C extends FlowConfig> {
|
|
536
|
+
step: Step<C>;
|
|
537
|
+
ui: UI<C>;
|
|
538
|
+
}
|
|
539
|
+
type Step<C extends FlowConfig> = <R>(name: string, options: {
|
|
540
|
+
stage?: ExtractStageKeys<C>;
|
|
541
|
+
maxRetries?: number;
|
|
542
|
+
timeoutInMs?: number;
|
|
543
|
+
}, fn: () => Promise<R> & {
|
|
544
|
+
catch: (errorHandler: (err: Error) => Promise<void> | void) => Promise<any>;
|
|
545
|
+
}) => Promise<R>;
|
|
546
|
+
interface FlowConfig {
|
|
547
|
+
stages?: StageConfig[];
|
|
548
|
+
title?: string;
|
|
549
|
+
description?: string;
|
|
550
|
+
}
|
|
551
|
+
type FlowFunction<C extends FlowConfig, I extends any = {}> = (ctx: FlowContext<C>, inputs: I) => Promise<void>;
|
|
552
|
+
type ExtractStageKeys<T extends FlowConfig> = T extends {
|
|
553
|
+
stages: infer S;
|
|
554
|
+
} ? S extends ReadonlyArray<infer U> ? U extends string ? U : U extends {
|
|
555
|
+
key: infer K extends string;
|
|
556
|
+
} ? K : never : never : never;
|
|
557
|
+
type StageConfig = string | {
|
|
558
|
+
key: string;
|
|
559
|
+
name: string;
|
|
560
|
+
description?: string;
|
|
561
|
+
initiallyHidden?: boolean;
|
|
562
|
+
};
|
|
563
|
+
declare function createFlowContext<C extends FlowConfig>(runId: string, data: any, spanId: string): FlowContext<C>;
|
|
564
|
+
|
|
565
|
+
declare function ksuid(): string;
|
|
566
|
+
|
|
567
|
+
type IDWhereCondition = {
|
|
568
|
+
equals?: string | null;
|
|
569
|
+
notEquals?: string | null;
|
|
570
|
+
oneOf?: string[] | null;
|
|
571
|
+
};
|
|
572
|
+
type StringWhereCondition = {
|
|
573
|
+
startsWith?: string | null;
|
|
574
|
+
endsWith?: string | null;
|
|
575
|
+
oneOf?: string[] | null;
|
|
576
|
+
contains?: string | null;
|
|
577
|
+
equals?: string | null;
|
|
578
|
+
notEquals?: string | null;
|
|
579
|
+
};
|
|
580
|
+
type BooleanWhereCondition = {
|
|
581
|
+
equals?: boolean | null;
|
|
582
|
+
notEquals?: boolean | null;
|
|
583
|
+
};
|
|
584
|
+
type NumberWhereCondition = {
|
|
585
|
+
greaterThan?: number | null;
|
|
586
|
+
greaterThanOrEquals?: number | null;
|
|
587
|
+
lessThan?: number | null;
|
|
588
|
+
lessThanOrEquals?: number | null;
|
|
589
|
+
equals?: number | null;
|
|
590
|
+
notEquals?: number | null;
|
|
591
|
+
};
|
|
592
|
+
type DurationWhereCondition = {
|
|
593
|
+
greaterThan?: DurationString | null;
|
|
594
|
+
greaterThanOrEquals?: DurationString | null;
|
|
595
|
+
lessThan?: DurationString | null;
|
|
596
|
+
lessThanOrEquals?: DurationString | null;
|
|
597
|
+
equals?: DurationString | null;
|
|
598
|
+
notEquals?: DurationString | null;
|
|
599
|
+
};
|
|
600
|
+
type DateWhereCondition = {
|
|
601
|
+
equals?: Date | string | null;
|
|
602
|
+
equalsRelative?: RelativeDateString | null;
|
|
603
|
+
before?: Date | string | null;
|
|
604
|
+
beforeRelative?: RelativeDateString | null;
|
|
605
|
+
onOrBefore?: Date | string | null;
|
|
606
|
+
after?: Date | string | null;
|
|
607
|
+
afterRelative?: RelativeDateString | null;
|
|
608
|
+
onOrAfter?: Date | string | null;
|
|
609
|
+
};
|
|
610
|
+
type DateQueryInput = {
|
|
611
|
+
equals?: string | null;
|
|
612
|
+
before?: string | null;
|
|
613
|
+
onOrBefore?: string | null;
|
|
614
|
+
after?: string | null;
|
|
615
|
+
onOrAfter?: string | null;
|
|
616
|
+
};
|
|
617
|
+
type TimestampQueryInput = {
|
|
618
|
+
before: string | null;
|
|
619
|
+
after: string | null;
|
|
620
|
+
equalsRelative?: RelativeDateString | null;
|
|
621
|
+
beforeRelative?: RelativeDateString | null;
|
|
622
|
+
afterRelative?: RelativeDateString | null;
|
|
623
|
+
};
|
|
624
|
+
type StringArrayWhereCondition = {
|
|
625
|
+
equals?: string[] | null;
|
|
626
|
+
notEquals?: string[] | null;
|
|
627
|
+
any?: StringArrayQueryWhereCondition | null;
|
|
628
|
+
all?: StringArrayQueryWhereCondition | null;
|
|
629
|
+
};
|
|
630
|
+
type StringArrayQueryWhereCondition = {
|
|
631
|
+
equals?: string | null;
|
|
632
|
+
notEquals?: string | null;
|
|
633
|
+
};
|
|
634
|
+
type NumberArrayWhereCondition = {
|
|
635
|
+
equals?: number[] | null;
|
|
636
|
+
notEquals?: number[] | null;
|
|
637
|
+
any?: NumberArrayQueryWhereCondition | null;
|
|
638
|
+
all?: NumberArrayQueryWhereCondition | null;
|
|
639
|
+
};
|
|
640
|
+
type NumberArrayQueryWhereCondition = {
|
|
641
|
+
greaterThan?: number | null;
|
|
642
|
+
greaterThanOrEquals?: number | null;
|
|
643
|
+
lessThan?: number | null;
|
|
644
|
+
lessThanOrEquals?: number | null;
|
|
645
|
+
equals?: number | null;
|
|
646
|
+
notEquals?: number | null;
|
|
647
|
+
};
|
|
648
|
+
type BooleanArrayWhereCondition = {
|
|
649
|
+
equals?: boolean[] | null;
|
|
650
|
+
notEquals?: boolean[] | null;
|
|
651
|
+
any?: BooleanArrayQueryWhereCondition | null;
|
|
652
|
+
all?: BooleanArrayQueryWhereCondition | null;
|
|
653
|
+
};
|
|
654
|
+
type BooleanArrayQueryWhereCondition = {
|
|
655
|
+
equals?: boolean | null;
|
|
656
|
+
notEquals?: boolean | null;
|
|
657
|
+
};
|
|
658
|
+
type DateArrayWhereCondition = {
|
|
659
|
+
equals?: Date[] | null;
|
|
660
|
+
notEquals?: Date[] | null;
|
|
661
|
+
any?: DateArrayQueryWhereCondition | null;
|
|
662
|
+
all?: DateArrayQueryWhereCondition | null;
|
|
663
|
+
};
|
|
664
|
+
type DateArrayQueryWhereCondition = {
|
|
665
|
+
greaterThan?: Date | null;
|
|
666
|
+
greaterThanOrEquals?: Date | null;
|
|
667
|
+
lessThan?: Date | null;
|
|
668
|
+
lessThanOrEquals?: number | null;
|
|
669
|
+
equals?: Date | null;
|
|
670
|
+
notEquals?: Date | null;
|
|
671
|
+
};
|
|
672
|
+
type ContextAPI = {
|
|
673
|
+
headers: RequestHeaders;
|
|
674
|
+
response: Response;
|
|
675
|
+
isAuthenticated: boolean;
|
|
676
|
+
now(): Date;
|
|
677
|
+
};
|
|
678
|
+
type Response = {
|
|
679
|
+
headers: Headers;
|
|
680
|
+
status?: number;
|
|
681
|
+
};
|
|
682
|
+
type PageInfo = {
|
|
683
|
+
startCursor: string;
|
|
684
|
+
endCursor: string;
|
|
685
|
+
totalCount: number;
|
|
686
|
+
hasNextPage: boolean;
|
|
687
|
+
count: number;
|
|
688
|
+
pageNumber?: number;
|
|
689
|
+
};
|
|
690
|
+
type SortDirection = "asc" | "desc" | "ASC" | "DESC";
|
|
691
|
+
declare class NotFoundError extends Error {
|
|
692
|
+
}
|
|
693
|
+
declare class BadRequestError$1 extends Error {
|
|
694
|
+
}
|
|
695
|
+
declare class UnknownError$1 extends Error {
|
|
696
|
+
}
|
|
697
|
+
type Errors = {
|
|
698
|
+
/**
|
|
699
|
+
* Returns a 404 HTTP status with an optional message.
|
|
700
|
+
* This error indicates that the requested resource could not be found.
|
|
701
|
+
*/
|
|
702
|
+
NotFound: typeof NotFoundError;
|
|
703
|
+
/**
|
|
704
|
+
* Returns a 400 HTTP status with an optional message.
|
|
705
|
+
* This error indicates that the request made by the client is invalid or malformed.
|
|
706
|
+
*/
|
|
707
|
+
BadRequest: typeof BadRequestError$1;
|
|
708
|
+
/**
|
|
709
|
+
* Returns a 500 HTTP status with an optional message.
|
|
710
|
+
* This error indicates that an unexpected condition was encountered, preventing the server from fulfilling the request.
|
|
711
|
+
*/
|
|
712
|
+
Unknown: typeof UnknownError$1;
|
|
713
|
+
};
|
|
714
|
+
type FunctionConfig = {
|
|
715
|
+
/**
|
|
716
|
+
* All DB calls within the function will be executed within a transaction.
|
|
717
|
+
* The transaction is rolled back if the function throws an error.
|
|
718
|
+
*/
|
|
719
|
+
dbTransaction?: boolean;
|
|
720
|
+
};
|
|
721
|
+
type FuncWithConfig<T> = T & {
|
|
722
|
+
config: FunctionConfig;
|
|
723
|
+
};
|
|
724
|
+
type unit = "year" | "years" | "month" | "months" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds";
|
|
725
|
+
type direction = "next" | "last";
|
|
726
|
+
type completed = "complete";
|
|
727
|
+
type value = number;
|
|
728
|
+
type RelativeDateString = "now" | "today" | "tomorrow" | "yesterday" | `this ${unit}` | `${direction} ${unit}` | `${direction} ${value} ${unit}` | `${direction} ${value} ${completed} ${unit}`;
|
|
729
|
+
type dateDuration = `${number}Y${number}M${number}D` | `${number}Y${number}M` | `${number}Y${number}D` | `${number}M${number}D` | `${number}Y` | `${number}M` | `${number}D`;
|
|
730
|
+
type timeDuration = `${number}H${number}M${number}S` | `${number}H${number}M` | `${number}M${number}S` | `${number}H${number}S` | `${number}H` | `${number}M` | `${number}S`;
|
|
731
|
+
type DurationString = `P${dateDuration}T${timeDuration}` | `P${dateDuration}` | `PT${timeDuration}`;
|
|
732
|
+
|
|
733
|
+
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowContext, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, ModelAPI, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, Permissions, type RelativeDateString, RequestHeaders, type Response, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|