import type Express from 'express'; import type * as Db from '../database-layer/db.js'; import type { Model } from '../config-loader/config-loader.js'; import type { AnyObject, RequiredField } from './common-types.js'; import type { PickDeferred, Resource } from '@balena/abstract-sql-to-typescript'; declare global { namespace Express { interface Request { tx?: Db.Tx; batch?: uriParser.UnparsedRequest[]; } } } type LFModel = any[]; import * as AbstractSQLCompiler from '@balena/abstract-sql-compiler'; declare const sbvrTypes: { 'Big Integer': typeof import("@balena/sbvr-types/out/types/big-integer.js"); 'Big Serial': typeof import("@balena/sbvr-types/out/types/big-serial.js"); Boolean: typeof import("@balena/sbvr-types/out/types/boolean.js"); 'Case Insensitive Text': typeof import("@balena/sbvr-types/out/types/case-insensitive-text.js"); Color: typeof import("@balena/sbvr-types/out/types/color.js"); ConceptType: typeof import("@balena/sbvr-types/out/types/concept-type.js"); 'Date Time': typeof import("@balena/sbvr-types/out/types/date-time.js"); 'Date Time Range': typeof import("@balena/sbvr-types/out/types/date-time-range.js"); Date: typeof import("@balena/sbvr-types/out/types/date.js"); File: typeof import("@balena/sbvr-types/out/types/file.js"); ForeignKey: typeof import("@balena/sbvr-types/out/types/foreign-key.js"); Hashed: typeof import("@balena/sbvr-types/out/types/hashed.js"); Integer: typeof import("@balena/sbvr-types/out/types/integer.js"); Interval: typeof import("@balena/sbvr-types/out/types/interval.js"); JSON: typeof import("@balena/sbvr-types/out/types/json.js"); Real: typeof import("@balena/sbvr-types/out/types/real.js"); Serial: typeof import("@balena/sbvr-types/out/types/serial.js"); SHA: typeof import("@balena/sbvr-types/out/types/sha.js"); 'Short Text': typeof import("@balena/sbvr-types/out/types/short-text.js"); Text: typeof import("@balena/sbvr-types/out/types/text.js"); Time: typeof import("@balena/sbvr-types/out/types/time.js"); WebResource: typeof import("@balena/sbvr-types/out/types/web-resource.js"); }; import type { ActionParams, ODataOptions, Params } from 'pinejs-client-core'; import { PinejsClientCore, type PromiseResultTypes } from 'pinejs-client-core'; import { generateODataMetadata } from '../odata-metadata/odata-metadata-generator.js'; import type DevModel from './dev.js'; import * as permissions from './permissions.js'; import { HttpError } from './errors.js'; import * as uriParser from './uri-parser.js'; export type { ODataRequest } from './uri-parser.js'; import { type HookArgs } from './hooks.js'; export { type HookReq, type HookArgs, type HookResponse, type Hooks, addPureHook, addSideEffectHook, } from './hooks.js'; export declare let db: Db.Database; export { sbvrTypes }; export { resolveOdataBind } from './abstract-sql.js'; import { translateAbstractSqlModel } from './translations.js'; import { type MigrationExecutionResult } from '../migrator/utils.js'; export type ExecutableModel = RequiredField | RequiredField; interface CompiledModel { vocab: string; translateTo?: string; resourceRenames?: ReturnType; se?: string | undefined; lf?: LFModel | undefined; abstractSql: AbstractSQLCompiler.AbstractSqlModel; sql?: AbstractSQLCompiler.SqlModel; odataMetadata: ReturnType; } export interface Actor { permissions?: string[]; } export interface User extends Actor { id?: number; actor: number; } export interface ApiKey extends Actor { key: string; actor: number; } export interface Response { statusCode: number; headers?: { [headerName: string]: any; } | undefined; body?: AnyObject | string; } export type ModelExecutionResult = undefined | { migrationExecutionResult?: MigrationExecutionResult; }; export declare const resolveSynonym: (request: Pick) => string; export declare const resolveNavigationResource: (request: Pick, navigationName: string) => string; export declare const isModelNew: (tx: Db.Tx, modelName: string) => Promise; export declare const generateLfModel: (seModel: string) => LFModel; export declare const generateAbstractSqlModel: (lfModel: LFModel) => AbstractSQLCompiler.AbstractSqlModel; export declare const generateSqlModel: (abstractSql: AbstractSQLCompiler.AbstractSqlModel, targetDatabaseEngine: AbstractSQLCompiler.Engines) => AbstractSQLCompiler.SqlModel; export declare function generateModels(model: ExecutableModel & { translateTo?: undefined; }, targetDatabaseEngine: AbstractSQLCompiler.Engines): RequiredField; export declare function generateModels(model: ExecutableModel, targetDatabaseEngine: AbstractSQLCompiler.Engines): CompiledModel; export declare const executeModel: (tx: Db.Tx, model: ExecutableModel) => Promise; export declare const executeModels: (tx: Db.Tx, execModels: ExecutableModel[]) => Promise; export declare const postExecuteModels: (tx: Db.Tx) => Promise; export declare const runRule: (vocab: string, rule: string) => Promise; export type Passthrough = AnyObject & { req?: { user?: User; }; tx?: Db.Tx; }; export declare class PinejsClient extends PinejsClientCore { _request({ method, url, body, tx, req, custom, }: { method: string; url: string; body?: AnyObject; tx?: Db.Tx; req?: permissions.PermissionReq; custom?: AnyObject; }): Promise; post(params: { resource: TResource; } & ActionParams & Omit, 'method' | 'url' | 'body'>): Promise; post(params: { resource: TResource; options?: Params['options'] & { returnResource?: true; }; } & Params): Promise>; post(params: { resource: TResource; options: Params['options'] & { returnResource: boolean; }; } & Params): Promise>; compileAuth(params: { modelName: string; access: string; resource: TResource; options?: Pick, '$filter'>; }): string; } export interface API { [vocab: string]: PinejsClient; } export declare const api: API; export declare const logger: { [vocab: string]: Console; }; export declare const runURI: (method: string, uri: string, body?: AnyObject, tx?: Db.Tx, req?: permissions.PermissionReq, custom?: AnyObject) => Promise; export declare const getAbstractSqlModel: (request: Pick) => AbstractSQLCompiler.AbstractSqlModel; export declare const getAffectedIds: (args: HookArgs & { tx: Db.Tx; }) => Promise; export declare const getModel: (vocabulary: string) => CompiledModel & { versions: string[]; modelExecutionResult?: ModelExecutionResult; }; export declare const getApiRoot: (req: Express.Request) => string | undefined; export declare const handleODataRequest: Express.Handler; declare const handleErrorFns: Array<(req: Express.Request, err: HttpError) => void>; export declare const onHandleHttpError: (fn: (typeof handleErrorFns)[number]) => void; export declare const handleHttpErrors: (req: Express.Request, res: Express.Response, err: Error) => boolean; export interface API { [devModelConfig.apiRoot]: PinejsClient; } declare const devModelConfig: { readonly apiRoot: "dev"; readonly modelText: string; readonly logging: { readonly log: false; }; readonly migrations: { readonly '11.0.0-modified-at': "\n\t\t\tALTER TABLE \"model\"\n\t\t\tADD COLUMN IF NOT EXISTS \"modified at\" TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL;\n\t\t"; readonly '15.0.0-data-types': ($tx: Db.Tx, sbvrUtils: typeof import("./sbvr-utils.js")) => Promise; readonly '22.0.0-timestamps': ($tx: Db.Tx, sbvrUtils: typeof import("./sbvr-utils.js")) => Promise; }; }; export declare const setup: (_app: Express.Application, $db: Db.Database) => Promise; export declare const postSetup: (_app: Express.Application, $db: Db.Database) => Promise;