@restura/core 1.9.2 → 2.0.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 +138 -42
- package/dist/index.js +1583 -1071
- package/dist/index.js.map +1 -1
- package/package.json +3 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,22 @@
|
|
|
1
|
-
import { TransportTargetOptions, SerializerFn, DestinationStream } from 'pino';
|
|
2
|
-
import { z } from 'zod';
|
|
3
1
|
import { UUID } from 'crypto';
|
|
4
2
|
import * as express from 'express';
|
|
5
3
|
import { IncomingHttpHeaders } from 'http2';
|
|
4
|
+
import { z } from 'zod';
|
|
6
5
|
import { QueryResultRow, QueryConfigValues, QueryResult, PoolConfig, Pool, ClientConfig, Client } from 'pg';
|
|
7
6
|
import peg from 'pegjs';
|
|
8
7
|
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
trace: LogFunction;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
type ErrorSerializerFactory = (baseSerializer: SerializerFn) => SerializerFn;
|
|
25
|
-
declare const loggerConfigSchema: z.ZodObject<{
|
|
26
|
-
level: z.ZodDefault<z.ZodEnum<{
|
|
27
|
-
fatal: "fatal";
|
|
28
|
-
error: "error";
|
|
29
|
-
warn: "warn";
|
|
30
|
-
info: "info";
|
|
31
|
-
debug: "debug";
|
|
32
|
-
silly: "silly";
|
|
33
|
-
trace: "trace";
|
|
34
|
-
}>>;
|
|
35
|
-
transports: z.ZodOptional<z.ZodArray<z.ZodCustom<TransportTargetOptions<Record<string, any>>, TransportTargetOptions<Record<string, any>>>>>;
|
|
36
|
-
serializers: z.ZodOptional<z.ZodObject<{
|
|
37
|
-
err: z.ZodOptional<z.ZodCustom<ErrorSerializerFactory, ErrorSerializerFactory>>;
|
|
38
|
-
}, z.core.$strip>>;
|
|
39
|
-
stream: z.ZodOptional<z.ZodCustom<DestinationStream, DestinationStream>>;
|
|
40
|
-
}, z.core.$strip>;
|
|
41
|
-
type LoggerConfigSchema = z.infer<typeof loggerConfigSchema>;
|
|
8
|
+
type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace';
|
|
9
|
+
interface ResturaLogger {
|
|
10
|
+
readonly level: LogLevel;
|
|
11
|
+
fatal(msg: unknown, ...args: unknown[]): void;
|
|
12
|
+
error(msg: unknown, ...args: unknown[]): void;
|
|
13
|
+
warn(msg: unknown, ...args: unknown[]): void;
|
|
14
|
+
info(msg: unknown, ...args: unknown[]): void;
|
|
15
|
+
debug(msg: unknown, ...args: unknown[]): void;
|
|
16
|
+
trace(msg: unknown, ...args: unknown[]): void;
|
|
17
|
+
}
|
|
18
|
+
declare const logger: ResturaLogger;
|
|
19
|
+
declare function setLogger(impl: ResturaLogger): void;
|
|
42
20
|
|
|
43
21
|
/**
|
|
44
22
|
* @deprecated This is used for passing around until we finally get to the sending externally
|
|
@@ -394,6 +372,73 @@ declare const customRouteSchema: z.ZodObject<{
|
|
|
394
372
|
}, z.core.$strict>;
|
|
395
373
|
type CustomRouteData = z.infer<typeof customRouteSchema>;
|
|
396
374
|
type RouteData = CustomRouteData | StandardRouteData;
|
|
375
|
+
declare const columnDataSchema: z.ZodObject<{
|
|
376
|
+
name: z.ZodString;
|
|
377
|
+
type: z.ZodUnion<readonly [z.ZodEnum<{
|
|
378
|
+
SMALLINT: "SMALLINT";
|
|
379
|
+
INTEGER: "INTEGER";
|
|
380
|
+
BIGINT: "BIGINT";
|
|
381
|
+
DECIMAL: "DECIMAL";
|
|
382
|
+
NUMERIC: "NUMERIC";
|
|
383
|
+
REAL: "REAL";
|
|
384
|
+
"DOUBLE PRECISION": "DOUBLE PRECISION";
|
|
385
|
+
SERIAL: "SERIAL";
|
|
386
|
+
BIGSERIAL: "BIGSERIAL";
|
|
387
|
+
}>, z.ZodEnum<{
|
|
388
|
+
CHAR: "CHAR";
|
|
389
|
+
VARCHAR: "VARCHAR";
|
|
390
|
+
TEXT: "TEXT";
|
|
391
|
+
BYTEA: "BYTEA";
|
|
392
|
+
}>, z.ZodEnum<{
|
|
393
|
+
DATE: "DATE";
|
|
394
|
+
TIMESTAMP: "TIMESTAMP";
|
|
395
|
+
TIMESTAMPTZ: "TIMESTAMPTZ";
|
|
396
|
+
TIME: "TIME";
|
|
397
|
+
INTERVAL: "INTERVAL";
|
|
398
|
+
}>, z.ZodEnum<{
|
|
399
|
+
JSON: "JSON";
|
|
400
|
+
JSONB: "JSONB";
|
|
401
|
+
}>, z.ZodEnum<{
|
|
402
|
+
SMALLINT: "SMALLINT";
|
|
403
|
+
INTEGER: "INTEGER";
|
|
404
|
+
BIGINT: "BIGINT";
|
|
405
|
+
DECIMAL: "DECIMAL";
|
|
406
|
+
BOOLEAN: "BOOLEAN";
|
|
407
|
+
TINYINT: "TINYINT";
|
|
408
|
+
MEDIUMINT: "MEDIUMINT";
|
|
409
|
+
FLOAT: "FLOAT";
|
|
410
|
+
DOUBLE: "DOUBLE";
|
|
411
|
+
}>, z.ZodEnum<{
|
|
412
|
+
CHAR: "CHAR";
|
|
413
|
+
VARCHAR: "VARCHAR";
|
|
414
|
+
TEXT: "TEXT";
|
|
415
|
+
JSON: "JSON";
|
|
416
|
+
TINYTEXT: "TINYTEXT";
|
|
417
|
+
TINYBLOB: "TINYBLOB";
|
|
418
|
+
BLOB: "BLOB";
|
|
419
|
+
MEDIUMTEXT: "MEDIUMTEXT";
|
|
420
|
+
MEDIUMBLOB: "MEDIUMBLOB";
|
|
421
|
+
LONGTEXT: "LONGTEXT";
|
|
422
|
+
LONGBLOB: "LONGBLOB";
|
|
423
|
+
ENUM: "ENUM";
|
|
424
|
+
}>, z.ZodEnum<{
|
|
425
|
+
DATE: "DATE";
|
|
426
|
+
TIMESTAMP: "TIMESTAMP";
|
|
427
|
+
TIME: "TIME";
|
|
428
|
+
DATETIME: "DATETIME";
|
|
429
|
+
}>]>;
|
|
430
|
+
isNullable: z.ZodBoolean;
|
|
431
|
+
roles: z.ZodArray<z.ZodString>;
|
|
432
|
+
scopes: z.ZodArray<z.ZodString>;
|
|
433
|
+
comment: z.ZodOptional<z.ZodString>;
|
|
434
|
+
default: z.ZodOptional<z.ZodString>;
|
|
435
|
+
value: z.ZodOptional<z.ZodString>;
|
|
436
|
+
isPrimary: z.ZodOptional<z.ZodBoolean>;
|
|
437
|
+
isUnique: z.ZodOptional<z.ZodBoolean>;
|
|
438
|
+
hasAutoIncrement: z.ZodOptional<z.ZodBoolean>;
|
|
439
|
+
length: z.ZodOptional<z.ZodNumber>;
|
|
440
|
+
}, z.core.$strict>;
|
|
441
|
+
type ColumnData = z.infer<typeof columnDataSchema>;
|
|
397
442
|
declare const tableDataSchema: z.ZodObject<{
|
|
398
443
|
name: z.ZodString;
|
|
399
444
|
columns: z.ZodArray<z.ZodObject<{
|
|
@@ -1016,7 +1061,9 @@ declare class ResturaEngine {
|
|
|
1016
1061
|
* @param app - The Express application instance to initialize with Restura.
|
|
1017
1062
|
* @returns A promise that resolves when the initialization is complete.
|
|
1018
1063
|
*/
|
|
1019
|
-
init(app: express.Express, authenticationHandler: AuthenticateHandler, psqlConnectionPool: PsqlPool
|
|
1064
|
+
init(app: express.Express, authenticationHandler: AuthenticateHandler, psqlConnectionPool: PsqlPool, options?: {
|
|
1065
|
+
logger?: ResturaLogger;
|
|
1066
|
+
}): Promise<void>;
|
|
1020
1067
|
/**
|
|
1021
1068
|
* Determines if a given endpoint is public based on the HTTP method and full URL. This
|
|
1022
1069
|
* is determined on whether the endpoint in the schema has no roles or scopes assigned to it.
|
|
@@ -1140,7 +1187,6 @@ declare class PsqlEngine extends SqlEngine {
|
|
|
1140
1187
|
private handleTrigger;
|
|
1141
1188
|
createDatabaseFromSchema(schema: ResturaSchema, connection: PsqlPool): Promise<string>;
|
|
1142
1189
|
generateDatabaseSchemaFromSchema(schema: ResturaSchema): string;
|
|
1143
|
-
private getNewPublicSchemaAndScratchPool;
|
|
1144
1190
|
diffDatabaseToSchema(schema: ResturaSchema): Promise<string>;
|
|
1145
1191
|
protected createNestedSelect(req: RsRequest<unknown>, schema: ResturaSchema, item: ResponseData, routeData: StandardRouteData, sqlParams: string[]): string;
|
|
1146
1192
|
protected executeCreateRequest(req: RsRequest<unknown>, routeData: StandardRouteData, schema: ResturaSchema): Promise<DynamicObject>;
|
|
@@ -1161,12 +1207,62 @@ declare class PsqlEngine extends SqlEngine {
|
|
|
1161
1207
|
protected generateGroupBy(routeData: StandardRouteData): string;
|
|
1162
1208
|
protected generateOrderBy(req: RsRequest<unknown>, routeData: StandardRouteData): string;
|
|
1163
1209
|
protected generateWhereClause(req: RsRequest<unknown>, where: WhereData[], routeData: StandardRouteData | CustomRouteData, sqlParams: string[]): string;
|
|
1164
|
-
private createUpdateTrigger;
|
|
1165
|
-
private createDeleteTrigger;
|
|
1166
|
-
private createInsertTriggers;
|
|
1167
|
-
private schemaToPsqlType;
|
|
1168
1210
|
}
|
|
1169
1211
|
|
|
1212
|
+
interface DbColumn {
|
|
1213
|
+
name: string;
|
|
1214
|
+
udtName: string;
|
|
1215
|
+
isNullable: boolean;
|
|
1216
|
+
columnDefault: string | null;
|
|
1217
|
+
characterMaximumLength: number | null;
|
|
1218
|
+
numericPrecision: number | null;
|
|
1219
|
+
numericScale: number | null;
|
|
1220
|
+
}
|
|
1221
|
+
interface DbIndex {
|
|
1222
|
+
name: string;
|
|
1223
|
+
tableName: string;
|
|
1224
|
+
isUnique: boolean;
|
|
1225
|
+
isPrimary: boolean;
|
|
1226
|
+
columns: string[];
|
|
1227
|
+
order: 'ASC' | 'DESC';
|
|
1228
|
+
where: string | null;
|
|
1229
|
+
}
|
|
1230
|
+
interface DbForeignKey {
|
|
1231
|
+
name: string;
|
|
1232
|
+
tableName: string;
|
|
1233
|
+
column: string;
|
|
1234
|
+
refTable: string;
|
|
1235
|
+
refColumn: string;
|
|
1236
|
+
onDelete: string;
|
|
1237
|
+
onUpdate: string;
|
|
1238
|
+
}
|
|
1239
|
+
interface DbCheckConstraint {
|
|
1240
|
+
name: string;
|
|
1241
|
+
tableName: string;
|
|
1242
|
+
expression: string;
|
|
1243
|
+
}
|
|
1244
|
+
interface DbTable {
|
|
1245
|
+
name: string;
|
|
1246
|
+
columns: DbColumn[];
|
|
1247
|
+
indexes: DbIndex[];
|
|
1248
|
+
foreignKeys: DbForeignKey[];
|
|
1249
|
+
checkConstraints: DbCheckConstraint[];
|
|
1250
|
+
}
|
|
1251
|
+
interface DbSnapshot {
|
|
1252
|
+
tables: DbTable[];
|
|
1253
|
+
}
|
|
1254
|
+
declare function introspectDatabase(pool: PsqlPool): Promise<DbSnapshot>;
|
|
1255
|
+
declare function diffSchemaToDatabase(schema: ResturaSchema, snapshot: DbSnapshot): string[];
|
|
1256
|
+
|
|
1257
|
+
declare const systemUser: RequesterDetails;
|
|
1258
|
+
declare function schemaToPsqlType(column: ColumnData): string;
|
|
1259
|
+
declare function createInsertTriggerSql(tableName: string, notify: ResturaSchema['database'][0]['notify']): string;
|
|
1260
|
+
declare function createUpdateTriggerSql(tableName: string, notify: ResturaSchema['database'][0]['notify']): string;
|
|
1261
|
+
declare function createDeleteTriggerSql(tableName: string, notify: ResturaSchema['database'][0]['notify']): string;
|
|
1262
|
+
declare function generateDatabaseSchemaFromSchema(schema: ResturaSchema): string;
|
|
1263
|
+
declare function getNewPublicSchemaAndScratchPool(targetPool: PsqlPool, scratchDbName: string): Promise<PsqlPool>;
|
|
1264
|
+
declare function diffDatabaseToSchema(schema: ResturaSchema, targetPool: PsqlPool, scratchDbName: string): Promise<string>;
|
|
1265
|
+
|
|
1170
1266
|
declare class PsqlTransaction extends PsqlConnection {
|
|
1171
1267
|
clientConfig: ClientConfig;
|
|
1172
1268
|
client: Client;
|
|
@@ -1244,4 +1340,4 @@ declare function SQL(strings: TemplateStringsArray, ...values: unknown[]): strin
|
|
|
1244
1340
|
*/
|
|
1245
1341
|
declare function toSqlLiteral(value: unknown): string;
|
|
1246
1342
|
|
|
1247
|
-
export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticatedRequesterDetails, type ConjunctionTypes, type DatabaseActionData, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type
|
|
1343
|
+
export { type ActionColumnChangeData, type ActionColumnChangeFilter, type ActionRowDeleteData, type ActionRowDeleteFilter, type ActionRowInsertData, type ActionRowInsertFilter, type ApiMethod, type AsyncExpressApplication, type AuthenticateHandler, type AuthenticatedRequesterDetails, type ConjunctionTypes, type DatabaseActionData, type DbCheckConstraint, type DbColumn, type DbForeignKey, type DbIndex, type DbSnapshot, type DbTable, type DynamicObject, type ErrorCode, type EventType, HtmlStatusCodes, type LogLevel, type MatchTypes, type MutationType, type OnValidAuthenticationCallback, type PageQuery, PsqlConnection, PsqlEngine, PsqlPool, PsqlTransaction, type QueryMetadata, type RequesterDetails, type ResturaConfigSchema, type ResturaLogger, type ResturaSchema, RsError, type RsErrorData, type RsErrorInternalData, type RsHeaders, type RsPagedResponseData, type RsRequest, type RsResponse, type RsResponseData, type RsRouteHandler, SQL, type SchemaChangeValue, type SchemaPreview, type SqlMutationData, type StandardOrderTypes, type TriggerResult, apiGenerator, createDeleteTriggerSql, createInsertTriggerSql, createUpdateTriggerSql, diffDatabaseToSchema, diffSchemaToDatabase, escapeColumnName, eventManager, filterPsqlParser, generateDatabaseSchemaFromSchema, getNewPublicSchemaAndScratchPool, insertObjectQuery, introspectDatabase, isSchemaValid, isValueNumber, logger, modelGenerator, questionMarksToOrderedParams, restura, resturaGlobalTypesGenerator, resturaSchema, schemaToPsqlType, setLogger, systemUser, toSqlLiteral, updateObjectQuery };
|