@teamkeel/functions-runtime 0.411.0 → 0.412.0-next.2

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.
Files changed (49) hide show
  1. package/dist/index.d.mts +340 -0
  2. package/dist/index.d.ts +340 -0
  3. package/dist/index.js +3093 -0
  4. package/dist/index.js.map +1 -0
  5. package/dist/index.mjs +3097 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +23 -5
  8. package/.env.test +0 -2
  9. package/compose.yaml +0 -10
  10. package/src/Duration.js +0 -40
  11. package/src/Duration.test.js +0 -34
  12. package/src/File.js +0 -295
  13. package/src/ModelAPI.js +0 -377
  14. package/src/ModelAPI.test.js +0 -1428
  15. package/src/QueryBuilder.js +0 -184
  16. package/src/QueryContext.js +0 -90
  17. package/src/RequestHeaders.js +0 -21
  18. package/src/TimePeriod.js +0 -89
  19. package/src/TimePeriod.test.js +0 -148
  20. package/src/applyAdditionalQueryConstraints.js +0 -22
  21. package/src/applyJoins.js +0 -67
  22. package/src/applyWhereConditions.js +0 -124
  23. package/src/auditing.js +0 -110
  24. package/src/auditing.test.js +0 -330
  25. package/src/camelCasePlugin.js +0 -52
  26. package/src/casing.js +0 -54
  27. package/src/casing.test.js +0 -56
  28. package/src/consts.js +0 -14
  29. package/src/database.js +0 -244
  30. package/src/errors.js +0 -160
  31. package/src/handleJob.js +0 -110
  32. package/src/handleJob.test.js +0 -270
  33. package/src/handleRequest.js +0 -153
  34. package/src/handleRequest.test.js +0 -463
  35. package/src/handleRoute.js +0 -112
  36. package/src/handleSubscriber.js +0 -105
  37. package/src/index.d.ts +0 -317
  38. package/src/index.js +0 -38
  39. package/src/parsing.js +0 -113
  40. package/src/parsing.test.js +0 -140
  41. package/src/permissions.js +0 -77
  42. package/src/permissions.test.js +0 -118
  43. package/src/tracing.js +0 -184
  44. package/src/tracing.test.js +0 -147
  45. package/src/tryExecuteFunction.js +0 -91
  46. package/src/tryExecuteJob.js +0 -29
  47. package/src/tryExecuteSubscriber.js +0 -17
  48. package/src/type-utils.js +0 -18
  49. package/vite.config.js +0 -7
@@ -0,0 +1,340 @@
1
+ type IDWhereCondition = {
2
+ equals?: string | null;
3
+ notEquals?: string | null;
4
+ oneOf?: string[] | null;
5
+ };
6
+ type StringWhereCondition = {
7
+ startsWith?: string | null;
8
+ endsWith?: string | null;
9
+ oneOf?: string[] | null;
10
+ contains?: string | null;
11
+ equals?: string | null;
12
+ notEquals?: string | null;
13
+ };
14
+ type BooleanWhereCondition = {
15
+ equals?: boolean | null;
16
+ notEquals?: boolean | null;
17
+ };
18
+ type NumberWhereCondition = {
19
+ greaterThan?: number | null;
20
+ greaterThanOrEquals?: number | null;
21
+ lessThan?: number | null;
22
+ lessThanOrEquals?: number | null;
23
+ equals?: number | null;
24
+ notEquals?: number | null;
25
+ };
26
+ type DurationWhereCondition = {
27
+ greaterThan?: DurationString | null;
28
+ greaterThanOrEquals?: DurationString | null;
29
+ lessThan?: DurationString | null;
30
+ lessThanOrEquals?: DurationString | null;
31
+ equals?: DurationString | null;
32
+ notEquals?: DurationString | null;
33
+ };
34
+ type DateWhereCondition = {
35
+ equals?: Date | string | null;
36
+ equalsRelative?: RelativeDateString | null;
37
+ before?: Date | string | null;
38
+ beforeRelative?: RelativeDateString | null;
39
+ onOrBefore?: Date | string | null;
40
+ after?: Date | string | null;
41
+ afterRelative?: RelativeDateString | null;
42
+ onOrAfter?: Date | string | null;
43
+ };
44
+ type DateQueryInput = {
45
+ equals?: string | null;
46
+ before?: string | null;
47
+ onOrBefore?: string | null;
48
+ after?: string | null;
49
+ onOrAfter?: string | null;
50
+ };
51
+ type TimestampQueryInput = {
52
+ before: string | null;
53
+ after: string | null;
54
+ equalsRelative?: RelativeDateString | null;
55
+ beforeRelative?: RelativeDateString | null;
56
+ afterRelative?: RelativeDateString | null;
57
+ };
58
+ type StringArrayWhereCondition = {
59
+ equals?: string[] | null;
60
+ notEquals?: string[] | null;
61
+ any?: StringArrayQueryWhereCondition | null;
62
+ all?: StringArrayQueryWhereCondition | null;
63
+ };
64
+ type StringArrayQueryWhereCondition = {
65
+ equals?: string | null;
66
+ notEquals?: string | null;
67
+ };
68
+ type NumberArrayWhereCondition = {
69
+ equals?: number[] | null;
70
+ notEquals?: number[] | null;
71
+ any?: NumberArrayQueryWhereCondition | null;
72
+ all?: NumberArrayQueryWhereCondition | null;
73
+ };
74
+ type NumberArrayQueryWhereCondition = {
75
+ greaterThan?: number | null;
76
+ greaterThanOrEquals?: number | null;
77
+ lessThan?: number | null;
78
+ lessThanOrEquals?: number | null;
79
+ equals?: number | null;
80
+ notEquals?: number | null;
81
+ };
82
+ type BooleanArrayWhereCondition = {
83
+ equals?: boolean[] | null;
84
+ notEquals?: boolean[] | null;
85
+ any?: BooleanArrayQueryWhereCondition | null;
86
+ all?: BooleanArrayQueryWhereCondition | null;
87
+ };
88
+ type BooleanArrayQueryWhereCondition = {
89
+ equals?: boolean | null;
90
+ notEquals?: boolean | null;
91
+ };
92
+ type DateArrayWhereCondition = {
93
+ equals?: Date[] | null;
94
+ notEquals?: Date[] | null;
95
+ any?: DateArrayQueryWhereCondition | null;
96
+ all?: DateArrayQueryWhereCondition | null;
97
+ };
98
+ type DateArrayQueryWhereCondition = {
99
+ greaterThan?: Date | null;
100
+ greaterThanOrEquals?: Date | null;
101
+ lessThan?: Date | null;
102
+ lessThanOrEquals?: number | null;
103
+ equals?: Date | null;
104
+ notEquals?: Date | null;
105
+ };
106
+ type ContextAPI = {
107
+ headers: RequestHeaders;
108
+ response: Response;
109
+ isAuthenticated: boolean;
110
+ now(): Date;
111
+ };
112
+ type Response = {
113
+ headers: Headers;
114
+ status?: number;
115
+ };
116
+ type PageInfo = {
117
+ startCursor: string;
118
+ endCursor: string;
119
+ totalCount: number;
120
+ hasNextPage: boolean;
121
+ count: number;
122
+ pageNumber?: number;
123
+ };
124
+ 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 & {});
125
+ type InlineFileConstructor = {
126
+ filename: string;
127
+ contentType: MimeType;
128
+ };
129
+ declare class InlineFile {
130
+ constructor(input: InlineFileConstructor);
131
+ static fromDataURL(url: string): InlineFile;
132
+ read(): Promise<Buffer>;
133
+ write(data: Buffer): void;
134
+ store(expires?: Date, isPublic?: boolean): Promise<File>;
135
+ get filename(): string;
136
+ get contentType(): string;
137
+ get size(): number;
138
+ }
139
+ declare class File extends InlineFile {
140
+ get key(): string;
141
+ get isPublic(): boolean;
142
+ getPresignedUrl(): Promise<URL>;
143
+ static fromDbRecord(input: FileDbRecord): File;
144
+ toDbRecord(): FileDbRecord;
145
+ }
146
+ type FileDbRecord = {
147
+ key: string;
148
+ filename: string;
149
+ contentType: string;
150
+ size: number;
151
+ };
152
+ declare class Duration {
153
+ constructor(postgresString: string);
154
+ static fromISOString(iso: DurationString): Duration;
155
+ toISOString(): DurationString;
156
+ toPostgres(): string;
157
+ }
158
+ type SortDirection = "asc" | "desc" | "ASC" | "DESC";
159
+ type RequestHeaders = Omit<Headers, "append" | "delete" | "set">;
160
+ declare class Permissions {
161
+ constructor();
162
+ allow(): void;
163
+ deny(): never;
164
+ }
165
+ declare class NotFoundError extends Error {
166
+ }
167
+ declare class BadRequestError extends Error {
168
+ }
169
+ declare class UnknownError extends Error {
170
+ }
171
+ type Errors = {
172
+ /**
173
+ * Returns a 404 HTTP status with an optional message.
174
+ * This error indicates that the requested resource could not be found.
175
+ */
176
+ NotFound: typeof NotFoundError;
177
+ /**
178
+ * Returns a 400 HTTP status with an optional message.
179
+ * This error indicates that the request made by the client is invalid or malformed.
180
+ */
181
+ BadRequest: typeof BadRequestError;
182
+ /**
183
+ * Returns a 500 HTTP status with an optional message.
184
+ * This error indicates that an unexpected condition was encountered, preventing the server from fulfilling the request.
185
+ */
186
+ Unknown: typeof UnknownError;
187
+ };
188
+ type FunctionConfig = {
189
+ /**
190
+ * All DB calls within the function will be executed within a transaction.
191
+ * The transaction is rolled back if the function throws an error.
192
+ */
193
+ dbTransaction?: boolean;
194
+ };
195
+ type FuncWithConfig<T> = T & {
196
+ config: FunctionConfig;
197
+ };
198
+ type unit = "year" | "years" | "month" | "months" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds";
199
+ type direction = "next" | "last";
200
+ type completed = "complete";
201
+ type value = number;
202
+ type RelativeDateString = "now" | "today" | "tomorrow" | "yesterday" | `this ${unit}` | `${direction} ${unit}` | `${direction} ${value} ${unit}` | `${direction} ${value} ${completed} ${unit}`;
203
+ 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`;
204
+ 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`;
205
+ type DurationString = `P${dateDuration}T${timeDuration}` | `P${dateDuration}` | `PT${timeDuration}`;
206
+ type FileWriteTypes = InlineFile | File;
207
+
208
+ type ElementDataType$3 = string | number | boolean | Date;
209
+ type UiElementSelectOne = <TValue extends ElementDataType$3, N extends string>(name: N, options?: BaseInputConfig<TValue> & {
210
+ options: ({
211
+ label: string;
212
+ value: TValue;
213
+ } | TValue)[];
214
+ }) => InputElementResponse<N, TValue>;
215
+
216
+ type ElementDataType$2 = string;
217
+ type UiElementInputText = InputElement<ElementDataType$2, {
218
+ placeholder?: string;
219
+ multiline?: boolean;
220
+ maxLength?: number;
221
+ minLength?: number;
222
+ }>;
223
+
224
+ type ElementDataType$1 = number;
225
+ type UiElementInputNumber = InputElement<ElementDataType$1, {
226
+ placeholder?: number;
227
+ min?: number;
228
+ max?: number;
229
+ }>;
230
+
231
+ type ElementDataType = boolean;
232
+ type UiElementInputBoolean = InputElement<ElementDataType, {
233
+ mode?: "checkbox" | "switch";
234
+ }>;
235
+
236
+ type UiElementMarkdown = DisplayElement<{
237
+ content: string;
238
+ }>;
239
+
240
+ type UiElementTable = DisplayElement<{
241
+ data: any[];
242
+ columns: string[];
243
+ }>;
244
+
245
+ type UiElementDivider = DisplayElement<{}>;
246
+
247
+ type UiPage<C extends FlowConfig> = <T extends UIElements, A extends PageActions[] = []>(options: {
248
+ stage?: ExtractStageKeys<C>;
249
+ title?: string;
250
+ description?: string;
251
+ content: T;
252
+ validate?: (data: ExtractFormData<T>) => Promise<true | string>;
253
+ actions?: A;
254
+ }) => A["length"] extends 0 ? ExtractFormData<T> : {
255
+ data: ExtractFormData<T>;
256
+ action: ActionValue<A[number]>;
257
+ };
258
+ type PageActions = string | {
259
+ label: string;
260
+ value: string;
261
+ mode?: "primary" | "secondary" | "destructive";
262
+ };
263
+ type ActionValue<T> = T extends string ? T : T extends {
264
+ value: infer V;
265
+ } ? V : never;
266
+ type ExtractFormData<T extends UIElements> = {
267
+ [K in Extract<T[number], InputElementResponse<string, any>>["name"]]: Extract<T[number], InputElementResponse<K, any>>["valueType"];
268
+ };
269
+ type ExtractStageKeys<T extends FlowConfig> = T extends {
270
+ stages: infer S;
271
+ } ? S extends ReadonlyArray<infer U> ? U extends string ? U : U extends {
272
+ key: infer K extends string;
273
+ } ? K : never : never : never;
274
+
275
+ interface UI<C extends FlowConfig> {
276
+ page: UiPage<C>;
277
+ display: UiDisplayElements;
278
+ inputs: UiInputsElements;
279
+ select: UiSelectElements;
280
+ }
281
+ type UiInputsElements = {
282
+ text: UiElementInputText;
283
+ number: UiElementInputNumber;
284
+ boolean: UiElementInputBoolean;
285
+ };
286
+ type UiSelectElements = {
287
+ single: UiElementSelectOne;
288
+ };
289
+ type UiDisplayElements = {
290
+ divider: UiElementDivider;
291
+ markdown: UiElementMarkdown;
292
+ table: UiElementTable;
293
+ };
294
+ type InputElement<TValueType, TConfig extends any = never> = <N extends string>(name: N, options?: BaseInputConfig<TValueType> & TConfig) => InputElementResponse<N, TValueType>;
295
+ type DisplayElement<TConfig extends any = never> = (options?: TConfig) => DisplayElementResponse;
296
+ type UIElements = (InputElementResponse<string, any> | DisplayElementResponse)[];
297
+ interface UIElementBase {
298
+ _type: string;
299
+ }
300
+ interface InputElementResponse<N extends string, V> extends UIElementBase {
301
+ _type: "input";
302
+ name: N;
303
+ valueType: V;
304
+ }
305
+ interface DisplayElementResponse extends UIElementBase {
306
+ _type: "display";
307
+ }
308
+ interface BaseInputConfig<T> {
309
+ label?: string;
310
+ defaultValue?: T;
311
+ helpText?: string;
312
+ optional?: boolean;
313
+ disabled?: boolean;
314
+ validate?: (data: T) => Promise<boolean | string>;
315
+ }
316
+
317
+ interface StepContext<C extends FlowConfig> {
318
+ step: <R = any>(name: string, fn: () => Promise<R>, opts?: Opts) => Promise<R> & {
319
+ catch: (errorHandler: (err: Error) => Promise<void> | void) => Promise<any>;
320
+ };
321
+ ui: UI<C>;
322
+ }
323
+ interface FlowConfig {
324
+ stages?: StageConfig[];
325
+ title?: string;
326
+ description?: string;
327
+ }
328
+ type FlowFunction<C extends FlowConfig, I extends any = {}> = (ctx: StepContext<C>, inputs: I) => Promise<void>;
329
+ type StageConfig = string | {
330
+ key: string;
331
+ name: string;
332
+ description?: string;
333
+ initiallyHidden?: boolean;
334
+ };
335
+ type Opts = {
336
+ maxRetries?: number;
337
+ timeoutInMs?: number;
338
+ };
339
+
340
+ export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, type Errors, File, type FileDbRecord, type FileWriteTypes, type FlowConfig, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, type InlineFileConstructor, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, type PageInfo, Permissions, type RelativeDateString, type RequestHeaders, type Response, type SortDirection, type StepContext, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI };
@@ -0,0 +1,340 @@
1
+ type IDWhereCondition = {
2
+ equals?: string | null;
3
+ notEquals?: string | null;
4
+ oneOf?: string[] | null;
5
+ };
6
+ type StringWhereCondition = {
7
+ startsWith?: string | null;
8
+ endsWith?: string | null;
9
+ oneOf?: string[] | null;
10
+ contains?: string | null;
11
+ equals?: string | null;
12
+ notEquals?: string | null;
13
+ };
14
+ type BooleanWhereCondition = {
15
+ equals?: boolean | null;
16
+ notEquals?: boolean | null;
17
+ };
18
+ type NumberWhereCondition = {
19
+ greaterThan?: number | null;
20
+ greaterThanOrEquals?: number | null;
21
+ lessThan?: number | null;
22
+ lessThanOrEquals?: number | null;
23
+ equals?: number | null;
24
+ notEquals?: number | null;
25
+ };
26
+ type DurationWhereCondition = {
27
+ greaterThan?: DurationString | null;
28
+ greaterThanOrEquals?: DurationString | null;
29
+ lessThan?: DurationString | null;
30
+ lessThanOrEquals?: DurationString | null;
31
+ equals?: DurationString | null;
32
+ notEquals?: DurationString | null;
33
+ };
34
+ type DateWhereCondition = {
35
+ equals?: Date | string | null;
36
+ equalsRelative?: RelativeDateString | null;
37
+ before?: Date | string | null;
38
+ beforeRelative?: RelativeDateString | null;
39
+ onOrBefore?: Date | string | null;
40
+ after?: Date | string | null;
41
+ afterRelative?: RelativeDateString | null;
42
+ onOrAfter?: Date | string | null;
43
+ };
44
+ type DateQueryInput = {
45
+ equals?: string | null;
46
+ before?: string | null;
47
+ onOrBefore?: string | null;
48
+ after?: string | null;
49
+ onOrAfter?: string | null;
50
+ };
51
+ type TimestampQueryInput = {
52
+ before: string | null;
53
+ after: string | null;
54
+ equalsRelative?: RelativeDateString | null;
55
+ beforeRelative?: RelativeDateString | null;
56
+ afterRelative?: RelativeDateString | null;
57
+ };
58
+ type StringArrayWhereCondition = {
59
+ equals?: string[] | null;
60
+ notEquals?: string[] | null;
61
+ any?: StringArrayQueryWhereCondition | null;
62
+ all?: StringArrayQueryWhereCondition | null;
63
+ };
64
+ type StringArrayQueryWhereCondition = {
65
+ equals?: string | null;
66
+ notEquals?: string | null;
67
+ };
68
+ type NumberArrayWhereCondition = {
69
+ equals?: number[] | null;
70
+ notEquals?: number[] | null;
71
+ any?: NumberArrayQueryWhereCondition | null;
72
+ all?: NumberArrayQueryWhereCondition | null;
73
+ };
74
+ type NumberArrayQueryWhereCondition = {
75
+ greaterThan?: number | null;
76
+ greaterThanOrEquals?: number | null;
77
+ lessThan?: number | null;
78
+ lessThanOrEquals?: number | null;
79
+ equals?: number | null;
80
+ notEquals?: number | null;
81
+ };
82
+ type BooleanArrayWhereCondition = {
83
+ equals?: boolean[] | null;
84
+ notEquals?: boolean[] | null;
85
+ any?: BooleanArrayQueryWhereCondition | null;
86
+ all?: BooleanArrayQueryWhereCondition | null;
87
+ };
88
+ type BooleanArrayQueryWhereCondition = {
89
+ equals?: boolean | null;
90
+ notEquals?: boolean | null;
91
+ };
92
+ type DateArrayWhereCondition = {
93
+ equals?: Date[] | null;
94
+ notEquals?: Date[] | null;
95
+ any?: DateArrayQueryWhereCondition | null;
96
+ all?: DateArrayQueryWhereCondition | null;
97
+ };
98
+ type DateArrayQueryWhereCondition = {
99
+ greaterThan?: Date | null;
100
+ greaterThanOrEquals?: Date | null;
101
+ lessThan?: Date | null;
102
+ lessThanOrEquals?: number | null;
103
+ equals?: Date | null;
104
+ notEquals?: Date | null;
105
+ };
106
+ type ContextAPI = {
107
+ headers: RequestHeaders;
108
+ response: Response;
109
+ isAuthenticated: boolean;
110
+ now(): Date;
111
+ };
112
+ type Response = {
113
+ headers: Headers;
114
+ status?: number;
115
+ };
116
+ type PageInfo = {
117
+ startCursor: string;
118
+ endCursor: string;
119
+ totalCount: number;
120
+ hasNextPage: boolean;
121
+ count: number;
122
+ pageNumber?: number;
123
+ };
124
+ 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 & {});
125
+ type InlineFileConstructor = {
126
+ filename: string;
127
+ contentType: MimeType;
128
+ };
129
+ declare class InlineFile {
130
+ constructor(input: InlineFileConstructor);
131
+ static fromDataURL(url: string): InlineFile;
132
+ read(): Promise<Buffer>;
133
+ write(data: Buffer): void;
134
+ store(expires?: Date, isPublic?: boolean): Promise<File>;
135
+ get filename(): string;
136
+ get contentType(): string;
137
+ get size(): number;
138
+ }
139
+ declare class File extends InlineFile {
140
+ get key(): string;
141
+ get isPublic(): boolean;
142
+ getPresignedUrl(): Promise<URL>;
143
+ static fromDbRecord(input: FileDbRecord): File;
144
+ toDbRecord(): FileDbRecord;
145
+ }
146
+ type FileDbRecord = {
147
+ key: string;
148
+ filename: string;
149
+ contentType: string;
150
+ size: number;
151
+ };
152
+ declare class Duration {
153
+ constructor(postgresString: string);
154
+ static fromISOString(iso: DurationString): Duration;
155
+ toISOString(): DurationString;
156
+ toPostgres(): string;
157
+ }
158
+ type SortDirection = "asc" | "desc" | "ASC" | "DESC";
159
+ type RequestHeaders = Omit<Headers, "append" | "delete" | "set">;
160
+ declare class Permissions {
161
+ constructor();
162
+ allow(): void;
163
+ deny(): never;
164
+ }
165
+ declare class NotFoundError extends Error {
166
+ }
167
+ declare class BadRequestError extends Error {
168
+ }
169
+ declare class UnknownError extends Error {
170
+ }
171
+ type Errors = {
172
+ /**
173
+ * Returns a 404 HTTP status with an optional message.
174
+ * This error indicates that the requested resource could not be found.
175
+ */
176
+ NotFound: typeof NotFoundError;
177
+ /**
178
+ * Returns a 400 HTTP status with an optional message.
179
+ * This error indicates that the request made by the client is invalid or malformed.
180
+ */
181
+ BadRequest: typeof BadRequestError;
182
+ /**
183
+ * Returns a 500 HTTP status with an optional message.
184
+ * This error indicates that an unexpected condition was encountered, preventing the server from fulfilling the request.
185
+ */
186
+ Unknown: typeof UnknownError;
187
+ };
188
+ type FunctionConfig = {
189
+ /**
190
+ * All DB calls within the function will be executed within a transaction.
191
+ * The transaction is rolled back if the function throws an error.
192
+ */
193
+ dbTransaction?: boolean;
194
+ };
195
+ type FuncWithConfig<T> = T & {
196
+ config: FunctionConfig;
197
+ };
198
+ type unit = "year" | "years" | "month" | "months" | "day" | "days" | "hour" | "hours" | "minute" | "minutes" | "second" | "seconds";
199
+ type direction = "next" | "last";
200
+ type completed = "complete";
201
+ type value = number;
202
+ type RelativeDateString = "now" | "today" | "tomorrow" | "yesterday" | `this ${unit}` | `${direction} ${unit}` | `${direction} ${value} ${unit}` | `${direction} ${value} ${completed} ${unit}`;
203
+ 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`;
204
+ 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`;
205
+ type DurationString = `P${dateDuration}T${timeDuration}` | `P${dateDuration}` | `PT${timeDuration}`;
206
+ type FileWriteTypes = InlineFile | File;
207
+
208
+ type ElementDataType$3 = string | number | boolean | Date;
209
+ type UiElementSelectOne = <TValue extends ElementDataType$3, N extends string>(name: N, options?: BaseInputConfig<TValue> & {
210
+ options: ({
211
+ label: string;
212
+ value: TValue;
213
+ } | TValue)[];
214
+ }) => InputElementResponse<N, TValue>;
215
+
216
+ type ElementDataType$2 = string;
217
+ type UiElementInputText = InputElement<ElementDataType$2, {
218
+ placeholder?: string;
219
+ multiline?: boolean;
220
+ maxLength?: number;
221
+ minLength?: number;
222
+ }>;
223
+
224
+ type ElementDataType$1 = number;
225
+ type UiElementInputNumber = InputElement<ElementDataType$1, {
226
+ placeholder?: number;
227
+ min?: number;
228
+ max?: number;
229
+ }>;
230
+
231
+ type ElementDataType = boolean;
232
+ type UiElementInputBoolean = InputElement<ElementDataType, {
233
+ mode?: "checkbox" | "switch";
234
+ }>;
235
+
236
+ type UiElementMarkdown = DisplayElement<{
237
+ content: string;
238
+ }>;
239
+
240
+ type UiElementTable = DisplayElement<{
241
+ data: any[];
242
+ columns: string[];
243
+ }>;
244
+
245
+ type UiElementDivider = DisplayElement<{}>;
246
+
247
+ type UiPage<C extends FlowConfig> = <T extends UIElements, A extends PageActions[] = []>(options: {
248
+ stage?: ExtractStageKeys<C>;
249
+ title?: string;
250
+ description?: string;
251
+ content: T;
252
+ validate?: (data: ExtractFormData<T>) => Promise<true | string>;
253
+ actions?: A;
254
+ }) => A["length"] extends 0 ? ExtractFormData<T> : {
255
+ data: ExtractFormData<T>;
256
+ action: ActionValue<A[number]>;
257
+ };
258
+ type PageActions = string | {
259
+ label: string;
260
+ value: string;
261
+ mode?: "primary" | "secondary" | "destructive";
262
+ };
263
+ type ActionValue<T> = T extends string ? T : T extends {
264
+ value: infer V;
265
+ } ? V : never;
266
+ type ExtractFormData<T extends UIElements> = {
267
+ [K in Extract<T[number], InputElementResponse<string, any>>["name"]]: Extract<T[number], InputElementResponse<K, any>>["valueType"];
268
+ };
269
+ type ExtractStageKeys<T extends FlowConfig> = T extends {
270
+ stages: infer S;
271
+ } ? S extends ReadonlyArray<infer U> ? U extends string ? U : U extends {
272
+ key: infer K extends string;
273
+ } ? K : never : never : never;
274
+
275
+ interface UI<C extends FlowConfig> {
276
+ page: UiPage<C>;
277
+ display: UiDisplayElements;
278
+ inputs: UiInputsElements;
279
+ select: UiSelectElements;
280
+ }
281
+ type UiInputsElements = {
282
+ text: UiElementInputText;
283
+ number: UiElementInputNumber;
284
+ boolean: UiElementInputBoolean;
285
+ };
286
+ type UiSelectElements = {
287
+ single: UiElementSelectOne;
288
+ };
289
+ type UiDisplayElements = {
290
+ divider: UiElementDivider;
291
+ markdown: UiElementMarkdown;
292
+ table: UiElementTable;
293
+ };
294
+ type InputElement<TValueType, TConfig extends any = never> = <N extends string>(name: N, options?: BaseInputConfig<TValueType> & TConfig) => InputElementResponse<N, TValueType>;
295
+ type DisplayElement<TConfig extends any = never> = (options?: TConfig) => DisplayElementResponse;
296
+ type UIElements = (InputElementResponse<string, any> | DisplayElementResponse)[];
297
+ interface UIElementBase {
298
+ _type: string;
299
+ }
300
+ interface InputElementResponse<N extends string, V> extends UIElementBase {
301
+ _type: "input";
302
+ name: N;
303
+ valueType: V;
304
+ }
305
+ interface DisplayElementResponse extends UIElementBase {
306
+ _type: "display";
307
+ }
308
+ interface BaseInputConfig<T> {
309
+ label?: string;
310
+ defaultValue?: T;
311
+ helpText?: string;
312
+ optional?: boolean;
313
+ disabled?: boolean;
314
+ validate?: (data: T) => Promise<boolean | string>;
315
+ }
316
+
317
+ interface StepContext<C extends FlowConfig> {
318
+ step: <R = any>(name: string, fn: () => Promise<R>, opts?: Opts) => Promise<R> & {
319
+ catch: (errorHandler: (err: Error) => Promise<void> | void) => Promise<any>;
320
+ };
321
+ ui: UI<C>;
322
+ }
323
+ interface FlowConfig {
324
+ stages?: StageConfig[];
325
+ title?: string;
326
+ description?: string;
327
+ }
328
+ type FlowFunction<C extends FlowConfig, I extends any = {}> = (ctx: StepContext<C>, inputs: I) => Promise<void>;
329
+ type StageConfig = string | {
330
+ key: string;
331
+ name: string;
332
+ description?: string;
333
+ initiallyHidden?: boolean;
334
+ };
335
+ type Opts = {
336
+ maxRetries?: number;
337
+ timeoutInMs?: number;
338
+ };
339
+
340
+ export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, type Errors, File, type FileDbRecord, type FileWriteTypes, type FlowConfig, type FlowFunction, type FuncWithConfig, type FunctionConfig, type IDWhereCondition, InlineFile, type InlineFileConstructor, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, type PageInfo, Permissions, type RelativeDateString, type RequestHeaders, type Response, type SortDirection, type StepContext, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type TimestampQueryInput, type UI };