From 3ca7dd5d3c06f90880b130a0d7bb8e532a8d1db1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 12:57:35 +0000 Subject: [PATCH 1/2] chore(deps): update typescript to 7.0.2 - tsconfig: moduleResolution "node" (node10) was removed in TS 7, use "bundler" - tsconfig.types: set rootDir explicitly, required by TS 7 - replace ts-node with tsx for test:unit, ts-node needs the JS compiler API which TypeScript 7 (native) no longer ships Supersedes https://github.com/pubkey/rxdb-server/pull/435 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011tSB1DTtshhws3G3f12vSt --- config/tsconfig.types.json | 1 + package.json | 6 +- src/index.d.ts | 1 + src/plugins/adapter-express/index.d.ts | 6 ++ src/plugins/client-rest/index.d.ts | 22 +++++ src/plugins/client-rest/utils.d.ts | 2 + src/plugins/replication-server/helpers.d.ts | 2 + src/plugins/replication-server/index.d.ts | 21 +++++ src/plugins/replication-server/types.d.ts | 21 +++++ src/plugins/server/endpoint-replication.d.ts | 25 ++++++ src/plugins/server/endpoint-rest.d.ts | 21 +++++ src/plugins/server/helper.d.ts | 25 ++++++ src/plugins/server/index.d.ts | 8 ++ src/plugins/server/performance-test.d.ts | 43 ++++++++++ src/plugins/server/rx-server.d.ts | 45 ++++++++++ src/plugins/server/types.d.ts | 88 ++++++++++++++++++++ src/utils.d.ts | 1 + test/unit/perf-rest-set.ts | 4 +- tsconfig.json | 2 +- 19 files changed, 338 insertions(+), 6 deletions(-) create mode 100644 src/index.d.ts create mode 100644 src/plugins/adapter-express/index.d.ts create mode 100644 src/plugins/client-rest/index.d.ts create mode 100644 src/plugins/client-rest/utils.d.ts create mode 100644 src/plugins/replication-server/helpers.d.ts create mode 100644 src/plugins/replication-server/index.d.ts create mode 100644 src/plugins/replication-server/types.d.ts create mode 100644 src/plugins/server/endpoint-replication.d.ts create mode 100644 src/plugins/server/endpoint-rest.d.ts create mode 100644 src/plugins/server/helper.d.ts create mode 100644 src/plugins/server/index.d.ts create mode 100644 src/plugins/server/performance-test.d.ts create mode 100644 src/plugins/server/rx-server.d.ts create mode 100644 src/plugins/server/types.d.ts create mode 100644 src/utils.d.ts diff --git a/config/tsconfig.types.json b/config/tsconfig.types.json index 7a6200f3..7f95a7ff 100644 --- a/config/tsconfig.types.json +++ b/config/tsconfig.types.json @@ -4,6 +4,7 @@ "compilerOptions": { "module": "es2022", "outDir": "../dist/types", + "rootDir": "../src", "declaration": true, "emitDeclarationOnly": true, "declarationMap": false, diff --git a/package.json b/package.json index 50b4447d..2c30fca8 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "build:bundle": "rimraf -rf rxdb-server.tgz && npx yarn@1.22.10 pack ./ --filename ./rxdb-server.tgz", "version": "node ./scripts/version.js", "check-types": "npm run build && tsc", - "test:unit": "npm run build && mocha --require ts-node/register ./test/unit.test.ts --bail --exit", + "test:unit": "npm run build && mocha --import=tsx ./test/unit.test.ts --bail --exit", "test:integration:init": "(cd ./scripts && bash test-integration-init.sh)", "test:integration:memory": "(cd test-integration && npm run transpile && npm run test:node:memory)", "test:integration:foundationdb": "(cd test-integration && npm run transpile && npm run test:node:foundationdb)", @@ -105,7 +105,7 @@ "rimraf": "6.1.3", "rxdb": "https://github.com/pubkey/rxdb/archive/5e03fdd02c1324efa52fe9965accd302abaa8b62.tar.gz", "rxjs": "7.8.2", - "ts-node": "10.9.2", - "typescript": "5.9.3" + "tsx": "4.23.15", + "typescript": "7.0.2" } } diff --git a/src/index.d.ts b/src/index.d.ts new file mode 100644 index 00000000..553e585e --- /dev/null +++ b/src/index.d.ts @@ -0,0 +1 @@ +export declare function wrongImport(): void; diff --git a/src/plugins/adapter-express/index.d.ts b/src/plugins/adapter-express/index.d.ts new file mode 100644 index 00000000..f41fe997 --- /dev/null +++ b/src/plugins/adapter-express/index.d.ts @@ -0,0 +1,6 @@ +import type { RxServerAdapter } from '../server/types'; +import type { Express } from 'express'; +import { Request, Response } from 'express'; +import { Server as HttpServer } from 'http'; +export declare const HTTP_SERVER_BY_EXPRESS: WeakMap>; +export declare const RxServerAdapterExpress: RxServerAdapter; diff --git a/src/plugins/client-rest/index.d.ts b/src/plugins/client-rest/index.d.ts new file mode 100644 index 00000000..62756cb5 --- /dev/null +++ b/src/plugins/client-rest/index.d.ts @@ -0,0 +1,22 @@ +import { ById, MangoQuery } from 'rxdb/plugins/core'; +import { Observable } from 'rxjs'; +import { EventSource } from 'eventsource'; +export declare class RxRestClient { + readonly endpointUrl: string; + headers: ById; + readonly eventSource: typeof EventSource | any; + constructor(endpointUrl: string, headers?: ById, eventSource?: typeof EventSource | any); + setHeaders(headers: ById): void; + handleError(response: any): void; + query(query: MangoQuery): Promise<{ + documents: RxDocType[]; + }>; + observeQuery(query: MangoQuery): Observable; + get(ids: string[]): Promise<{ + documents: RxDocType[]; + }>; + set(docs: RxDocType[]): Promise; + delete(ids: string[]): Promise; +} +export declare function createRestClient(endpointUrl: string, headers: ById, eventSource?: typeof EventSource | any): RxRestClient; +export * from './utils.ts'; diff --git a/src/plugins/client-rest/utils.d.ts b/src/plugins/client-rest/utils.d.ts new file mode 100644 index 00000000..f22b4f32 --- /dev/null +++ b/src/plugins/client-rest/utils.d.ts @@ -0,0 +1,2 @@ +import { ById } from 'rxdb/plugins/core'; +export declare function postRequest(url: string, body: any, headers?: ById): Promise; diff --git a/src/plugins/replication-server/helpers.d.ts b/src/plugins/replication-server/helpers.d.ts new file mode 100644 index 00000000..09059397 --- /dev/null +++ b/src/plugins/replication-server/helpers.d.ts @@ -0,0 +1,2 @@ +import type { RxServerReplicationState } from './index.ts'; +export declare function parseResponse(replicationState: RxServerReplicationState, fetchResponse: Response): Promise; diff --git a/src/plugins/replication-server/index.d.ts b/src/plugins/replication-server/index.d.ts new file mode 100644 index 00000000..d3e32a4a --- /dev/null +++ b/src/plugins/replication-server/index.d.ts @@ -0,0 +1,21 @@ +import { RxCollection, ReplicationPullOptions, ReplicationPushOptions, ById } from 'rxdb/plugins/core'; +import { RxReplicationState } from 'rxdb/plugins/replication'; +import { Subject } from 'rxjs'; +import type { RxServerCheckpoint, ServerSyncOptions } from './types.ts'; +export * from './types.ts'; +export declare class RxServerReplicationState extends RxReplicationState { + readonly replicationIdentifier: string; + readonly collection: RxCollection; + readonly pull?: ReplicationPullOptions; + readonly push?: ReplicationPushOptions; + readonly live: boolean; + retryTime: number; + autoStart: boolean; + headers: ById; + readonly outdatedClient$: Subject; + readonly unauthorized$: Subject; + readonly forbidden$: Subject; + constructor(replicationIdentifier: string, collection: RxCollection, pull?: ReplicationPullOptions, push?: ReplicationPushOptions, live?: boolean, retryTime?: number, autoStart?: boolean, headers?: ById); + setHeaders(headers: ById): void; +} +export declare function replicateServer(options: ServerSyncOptions): RxServerReplicationState; diff --git a/src/plugins/replication-server/types.d.ts b/src/plugins/replication-server/types.d.ts new file mode 100644 index 00000000..0ce199b9 --- /dev/null +++ b/src/plugins/replication-server/types.d.ts @@ -0,0 +1,21 @@ +import type { ReplicationOptions, ReplicationPullOptions, ReplicationPushOptions, RxStorageDefaultCheckpoint } from 'rxdb/plugins/core'; +export type ServerSyncPullOptions = Omit, 'handler' | 'stream$'> & {}; +export type ServerSyncPushOptions = Omit, 'handler'> & {}; +export type ServerSyncOptions = Omit, 'pull' | 'push'> & { + url: string; + headers?: { + [k: string]: string; + }; + pull?: ServerSyncPullOptions; + push?: ServerSyncPushOptions; + /** + * If the EventSource API is not available + * on the runtime, pass an own implementation here. + * Mostly used with the "eventsource" npm package on Node.js. + */ + eventSource?: typeof EventSource | any; +}; +export type RxServerCheckpoint = { + id: string; + lwt: number; +}; diff --git a/src/plugins/server/endpoint-replication.d.ts b/src/plugins/server/endpoint-replication.d.ts new file mode 100644 index 00000000..44fcfd1a --- /dev/null +++ b/src/plugins/server/endpoint-replication.d.ts @@ -0,0 +1,25 @@ +import { RxCollection, RxReplicationHandler, StringKeys } from 'rxdb/plugins/core'; +import type { RxServer } from './rx-server.ts'; +import type { RxServerChangeValidator, RxServerEndpoint, RxServerQueryModifier } from './types.ts'; +export type RxReplicationEndpointMessageType = { + id: string; + method: StringKeys> | 'auth'; + params: any[]; +}; +export declare class RxServerReplicationEndpoint implements RxServerEndpoint { + readonly server: RxServer; + readonly name: string; + readonly collection: RxCollection; + readonly serverOnlyFields: string[]; + readonly cors?: string | undefined; + readonly type = "replication"; + readonly urlPath: string; + readonly changeValidator: RxServerChangeValidator; + readonly queryModifier: RxServerQueryModifier; + constructor(server: RxServer, name: string, collection: RxCollection, queryModifier: RxServerQueryModifier, changeValidator: RxServerChangeValidator, serverOnlyFields: string[], cors?: string | undefined); +} +/** + * "block" the previous version urls and send a 426 on them so that + * the clients know they must update. + */ +export declare function blockPreviousReplicationVersionPaths(server: RxServer, path: string, currentVersion: number): void; diff --git a/src/plugins/server/endpoint-rest.d.ts b/src/plugins/server/endpoint-rest.d.ts new file mode 100644 index 00000000..c4bb2d79 --- /dev/null +++ b/src/plugins/server/endpoint-rest.d.ts @@ -0,0 +1,21 @@ +import { RxCollection } from 'rxdb/plugins/core'; +import type { RxServer } from './rx-server.ts'; +import type { RxServerChangeValidator, RxServerEndpoint, RxServerQueryModifier } from './types.ts'; +export declare const REST_PATHS: readonly ['query', 'query/observe', 'get', 'set', 'delete']; +export declare class RxServerRestEndpoint implements RxServerEndpoint { + readonly server: RxServer; + readonly name: string; + readonly collection: RxCollection; + readonly serverOnlyFields: string[]; + readonly cors?: string | undefined; + readonly type = "rest"; + readonly urlPath: string; + readonly changeValidator: RxServerChangeValidator; + readonly queryModifier: RxServerQueryModifier; + constructor(server: RxServer, name: string, collection: RxCollection, queryModifier: RxServerQueryModifier, changeValidator: RxServerChangeValidator, serverOnlyFields: string[], cors?: string | undefined); +} +/** + * "block" the previous version urls and send a 426 on them so that + * the clients know they must update. + */ +export declare function blockPreviousReplicationVersionPathsRest(server: RxServer, path: string, currentVersion: number): void; diff --git a/src/plugins/server/helper.d.ts b/src/plugins/server/helper.d.ts new file mode 100644 index 00000000..7689e473 --- /dev/null +++ b/src/plugins/server/helper.d.ts @@ -0,0 +1,25 @@ +import { RxServer } from './rx-server'; +import type { RxServerAuthData, RxServerEndpoint } from './types'; +import { MangoQuerySelector, RxDocumentData } from 'rxdb/plugins/core'; +export declare function setCors(server: RxServer, path: string, cors?: string): void; +export declare function getAuthDataByRequest(server: RxServer, request: RequestType, response: ResponseType): Promise | false>; +export declare function getDocAllowedMatcher(endpoint: RxServerEndpoint, authData: RxServerAuthData): any; +export declare function docContainsServerOnlyFields(serverOnlyFields: string[], doc: any): string | undefined; +/** + * Returns a function that strips the given server-only fields from a client + * document. This is used when accepting a NEW document from a client write to + * make sure that server-only fields cannot be populated by the client. + * + * Unlike {@link removeServerOnlyFieldsMonad} this does not assign undefined to + * RxDB internal meta fields (`_meta`, `_rev`, `_attachments`) so the result can + * be safely passed to `RxCollection.insert()`. + */ +export declare function stripServerOnlyFieldsMonad(serverOnlyFields: string[]): (docData: RxDocType | RxDocumentData) => any; +export declare function removeServerOnlyFieldsMonad(serverOnlyFields: string[]): (docData?: RxDocType | RxDocumentData) => any; +export declare function mergeServerDocumentFieldsMonad(serverOnlyFields: string[]): (clientDoc: RxDocType | RxDocumentData, serverDoc?: RxDocType | RxDocumentData) => any; +/** + * $regex queries are dangerous because they can dos-attack the server. + * + * @param selector + */ +export declare function doesContainRegexQuerySelector(selector: MangoQuerySelector | any): boolean; diff --git a/src/plugins/server/index.d.ts b/src/plugins/server/index.d.ts new file mode 100644 index 00000000..04ecde0b --- /dev/null +++ b/src/plugins/server/index.d.ts @@ -0,0 +1,8 @@ +import { RxServer } from './rx-server.ts'; +import { RxServerOptions } from './types.ts'; +export * from './types.ts'; +export * from './endpoint-replication.ts'; +export * from './endpoint-rest.ts'; +export * from './helper.ts'; +export * from './performance-test.ts'; +export declare function createRxServer(options: RxServerOptions): Promise>; diff --git a/src/plugins/server/performance-test.d.ts b/src/plugins/server/performance-test.d.ts new file mode 100644 index 00000000..aaa2e24e --- /dev/null +++ b/src/plugins/server/performance-test.d.ts @@ -0,0 +1,43 @@ +/** + * A reusable performance test suite for RxDB server adapters. + * This function can be exported and used by consumers who + * create custom adapters to verify their performance characteristics. + */ +import type { RxDatabase } from 'rxdb/plugins/core'; +import type { RxServerAdapter } from './types.ts'; +export type PerformanceTestResult = { + /** Name of the test case */ + name: string; + /** Total time in milliseconds */ + timeMs: number; + /** Number of operations performed */ + opsCount: number; + /** Calculated operations per second */ + opsPerSecond: number; +}; +export type PerformanceTestOptions = { + adapter: RxServerAdapter; + /** + * Function that creates a fresh RxDatabase instance. + * Must return a database that can be closed after each test. + */ + createDatabase: () => Promise; + /** + * Function that resolves an available port for the server. + */ + getPort: () => Promise; + /** + * Number of documents to use for each test. + * [default=30] + */ + batchSize?: number; +}; +/** + * Runs a set of performance tests against the given adapter. + * Each test creates its own server and collection, measures + * the time for the operations, and tears down afterwards. + * + * Returns an array of results that callers can assert against + * or log for comparison purposes. + */ +export declare function performanceTest(options: PerformanceTestOptions): Promise; diff --git a/src/plugins/server/rx-server.d.ts b/src/plugins/server/rx-server.d.ts new file mode 100644 index 00000000..261aca32 --- /dev/null +++ b/src/plugins/server/rx-server.d.ts @@ -0,0 +1,45 @@ +import type { RxCollection, RxDatabase } from 'rxdb/plugins/core'; +import { RxServerReplicationEndpoint } from './endpoint-replication.ts'; +import type { RxServerAdapter, RxServerAuthHandler, RxServerChangeValidator, RxServerEndpoint, RxServerOptions, RxServerQueryModifier } from './types.ts'; +import { RxServerRestEndpoint } from './endpoint-rest.ts'; +export declare class RxServer { + readonly options: RxServerOptions; + readonly authHandler: RxServerAuthHandler; + readonly serverApp: ServerAppType; + readonly cors: string; + readonly endpoints: RxServerEndpoint[]; + private closeFn; + listenPromise?: Promise; + readonly database: RxDatabase; + readonly adapter: RxServerAdapter; + constructor(options: RxServerOptions, authHandler: RxServerAuthHandler, serverApp: ServerAppType, cors?: string); + private ensureNotStarted; + addReplicationEndpoint(opts: { + name: string; + collection: RxCollection; + queryModifier?: RxServerQueryModifier; + changeValidator?: RxServerChangeValidator; + /** + * Set a origin for allowed CORS requests. + * Overwrites the cors option of the server. + * [default='*'] + */ + cors?: '*' | string; + serverOnlyFields?: string[]; + }): RxServerReplicationEndpoint; + addRestEndpoint(opts: { + name: string; + collection: RxCollection; + queryModifier?: RxServerQueryModifier; + changeValidator?: RxServerChangeValidator; + /** + * Set a origin for allowed CORS requests. + * Overwrites the cors option of the server. + * [default='*'] + */ + cors?: '*' | string; + serverOnlyFields?: string[]; + }): RxServerRestEndpoint; + start(): Promise; + close(): Promise; +} diff --git a/src/plugins/server/types.d.ts b/src/plugins/server/types.d.ts new file mode 100644 index 00000000..24557049 --- /dev/null +++ b/src/plugins/server/types.d.ts @@ -0,0 +1,88 @@ +import type { FilledMangoQuery, RxDatabase, RxReplicationWriteToMasterRow, MaybePromise, RxCollection } from 'rxdb/plugins/core'; +import { IncomingHttpHeaders } from 'http'; +export type RxServerOptions = { + database: RxDatabase; + adapter: RxServerAdapter; + serverApp?: ServerAppType; + authHandler?: RxServerAuthHandler; + appOptions?: any; + /** + * [default=localhost] + */ + hostname?: 'localhost' | '0.0.0.0' | string; + port: number; + /** + * Set a origin for allowed CORS requests. + * Can be overwritten by the cors option of the endpoints. + * [default='*'] + */ + cors?: '*' | string; +}; +export type RxServerRouteHandler = (req: RequestType, res: ResponseType, next?: any) => MaybePromise; +export type RxServerAdapter = { + create(): Promise; + get(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; + post(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; + all(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; + setCors(app: ServerAppType, path: string, cors: string): MaybePromise; + getRequestBody(req: RequestType): any; + getRequestHeaders(req: RequestType): { + [k: string]: string; + }; + getRequestQuery(req: RequestType): any; + onRequestClose(req: RequestType, handler: () => void): void; + setResponseHeader(res: ResponseType, name: string, value: string): void; + endResponseJson(res: ResponseType, data: any): void; + endResponse(res: ResponseType): void; + responseWrite(res: ResponseType, data: string): void; + setSSEHeaders(res: ResponseType): void; + closeConnection(res: ResponseType, code: number, message: string): void; + listen(app: ServerAppType, port: number, hostname: string): Promise; + closeAllConnections(app: ServerAppType): MaybePromise; + close(app: ServerAppType): Promise; +}; +export type RxServerAuthData = { + data: AuthType; + validUntil: number; +}; +/** + * Returns the auth state by the given request headers. + * Throws if auth not valid. + */ +export type RxServerAuthHandler = (headers: IncomingHttpHeaders) => MaybePromise>; +/** + * Modifies a given query in a way to limit the results + * to what the authenticated user is allowed to see. + * For example the query selector + * input: { + * selector: { + * myField: { $gt: 100 } + * } + * } + * could be modified to restrict the results to only return + * documents that are "owned" by the user + * return: { + * selector: { + * myField: { $gt: 100 }, + * userId: { $eq: authData.userId } + * } + * } + * + * + */ +export type RxServerQueryModifier = (authData: RxServerAuthData, query: FilledMangoQuery) => FilledMangoQuery; +/** + * Validates if a given change is allowed to be performed on the server. + * Returns true if allowed, false if not. + * If a client tries to make a non-allowed change, + * the client will be disconnected. + */ +export type RxServerChangeValidator = (authData: RxServerAuthData, change: RxReplicationWriteToMasterRow) => boolean; +export interface RxServerEndpoint { + collection: RxCollection; + name: string; + type: 'replication' | 'rest' | string; + urlPath: string; + queryModifier?: RxServerQueryModifier; + changeValidator?: RxServerChangeValidator; +} diff --git a/src/utils.d.ts b/src/utils.d.ts new file mode 100644 index 00000000..1322b3df --- /dev/null +++ b/src/utils.d.ts @@ -0,0 +1 @@ +export declare function customFetchWithFixedHeaders(headers: any): (url: string | URL, options?: any) => Promise; diff --git a/test/unit/perf-rest-set.ts b/test/unit/perf-rest-set.ts index 716bd20b..79837be6 100644 --- a/test/unit/perf-rest-set.ts +++ b/test/unit/perf-rest-set.ts @@ -4,9 +4,9 @@ * that was changed by the overwrite-protection fix. * * Run with: - * npx ts-node --esm ./test/unit/perf-rest-set.ts + * npx tsx ./test/unit/perf-rest-set.ts * or - * npx mocha --require ts-node/register ./test/unit/perf-rest-set.ts --exit + * npx mocha --import=tsx ./test/unit/perf-rest-set.ts --exit */ import { addRxPlugin, diff --git a/tsconfig.json b/tsconfig.json index eb6c2d8d..dfb3ae9a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "target": "es2022", // Search under node_modules for non-relative imports. // https://www.youtube.com/watch?v=H91aqUHn8sE - "moduleResolution": "node", + "moduleResolution": "bundler", // "module": "NodeNext", // Process & infer types from .js files. "allowJs": false, From 6963a0f92ea0a8070ce04d2eef18f44399baa5ec Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 12 Oct 2026 12:58:05 +0000 Subject: [PATCH 2/2] chore: remove accidentally committed .d.ts files from src Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_011tSB1DTtshhws3G3f12vSt --- src/index.d.ts | 1 - src/plugins/adapter-express/index.d.ts | 6 -- src/plugins/client-rest/index.d.ts | 22 ----- src/plugins/client-rest/utils.d.ts | 2 - src/plugins/replication-server/helpers.d.ts | 2 - src/plugins/replication-server/index.d.ts | 21 ----- src/plugins/replication-server/types.d.ts | 21 ----- src/plugins/server/endpoint-replication.d.ts | 25 ------ src/plugins/server/endpoint-rest.d.ts | 21 ----- src/plugins/server/helper.d.ts | 25 ------ src/plugins/server/index.d.ts | 8 -- src/plugins/server/performance-test.d.ts | 43 ---------- src/plugins/server/rx-server.d.ts | 45 ---------- src/plugins/server/types.d.ts | 88 -------------------- src/utils.d.ts | 1 - 15 files changed, 331 deletions(-) delete mode 100644 src/index.d.ts delete mode 100644 src/plugins/adapter-express/index.d.ts delete mode 100644 src/plugins/client-rest/index.d.ts delete mode 100644 src/plugins/client-rest/utils.d.ts delete mode 100644 src/plugins/replication-server/helpers.d.ts delete mode 100644 src/plugins/replication-server/index.d.ts delete mode 100644 src/plugins/replication-server/types.d.ts delete mode 100644 src/plugins/server/endpoint-replication.d.ts delete mode 100644 src/plugins/server/endpoint-rest.d.ts delete mode 100644 src/plugins/server/helper.d.ts delete mode 100644 src/plugins/server/index.d.ts delete mode 100644 src/plugins/server/performance-test.d.ts delete mode 100644 src/plugins/server/rx-server.d.ts delete mode 100644 src/plugins/server/types.d.ts delete mode 100644 src/utils.d.ts diff --git a/src/index.d.ts b/src/index.d.ts deleted file mode 100644 index 553e585e..00000000 --- a/src/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function wrongImport(): void; diff --git a/src/plugins/adapter-express/index.d.ts b/src/plugins/adapter-express/index.d.ts deleted file mode 100644 index f41fe997..00000000 --- a/src/plugins/adapter-express/index.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import type { RxServerAdapter } from '../server/types'; -import type { Express } from 'express'; -import { Request, Response } from 'express'; -import { Server as HttpServer } from 'http'; -export declare const HTTP_SERVER_BY_EXPRESS: WeakMap>; -export declare const RxServerAdapterExpress: RxServerAdapter; diff --git a/src/plugins/client-rest/index.d.ts b/src/plugins/client-rest/index.d.ts deleted file mode 100644 index 62756cb5..00000000 --- a/src/plugins/client-rest/index.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { ById, MangoQuery } from 'rxdb/plugins/core'; -import { Observable } from 'rxjs'; -import { EventSource } from 'eventsource'; -export declare class RxRestClient { - readonly endpointUrl: string; - headers: ById; - readonly eventSource: typeof EventSource | any; - constructor(endpointUrl: string, headers?: ById, eventSource?: typeof EventSource | any); - setHeaders(headers: ById): void; - handleError(response: any): void; - query(query: MangoQuery): Promise<{ - documents: RxDocType[]; - }>; - observeQuery(query: MangoQuery): Observable; - get(ids: string[]): Promise<{ - documents: RxDocType[]; - }>; - set(docs: RxDocType[]): Promise; - delete(ids: string[]): Promise; -} -export declare function createRestClient(endpointUrl: string, headers: ById, eventSource?: typeof EventSource | any): RxRestClient; -export * from './utils.ts'; diff --git a/src/plugins/client-rest/utils.d.ts b/src/plugins/client-rest/utils.d.ts deleted file mode 100644 index f22b4f32..00000000 --- a/src/plugins/client-rest/utils.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import { ById } from 'rxdb/plugins/core'; -export declare function postRequest(url: string, body: any, headers?: ById): Promise; diff --git a/src/plugins/replication-server/helpers.d.ts b/src/plugins/replication-server/helpers.d.ts deleted file mode 100644 index 09059397..00000000 --- a/src/plugins/replication-server/helpers.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -import type { RxServerReplicationState } from './index.ts'; -export declare function parseResponse(replicationState: RxServerReplicationState, fetchResponse: Response): Promise; diff --git a/src/plugins/replication-server/index.d.ts b/src/plugins/replication-server/index.d.ts deleted file mode 100644 index d3e32a4a..00000000 --- a/src/plugins/replication-server/index.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { RxCollection, ReplicationPullOptions, ReplicationPushOptions, ById } from 'rxdb/plugins/core'; -import { RxReplicationState } from 'rxdb/plugins/replication'; -import { Subject } from 'rxjs'; -import type { RxServerCheckpoint, ServerSyncOptions } from './types.ts'; -export * from './types.ts'; -export declare class RxServerReplicationState extends RxReplicationState { - readonly replicationIdentifier: string; - readonly collection: RxCollection; - readonly pull?: ReplicationPullOptions; - readonly push?: ReplicationPushOptions; - readonly live: boolean; - retryTime: number; - autoStart: boolean; - headers: ById; - readonly outdatedClient$: Subject; - readonly unauthorized$: Subject; - readonly forbidden$: Subject; - constructor(replicationIdentifier: string, collection: RxCollection, pull?: ReplicationPullOptions, push?: ReplicationPushOptions, live?: boolean, retryTime?: number, autoStart?: boolean, headers?: ById); - setHeaders(headers: ById): void; -} -export declare function replicateServer(options: ServerSyncOptions): RxServerReplicationState; diff --git a/src/plugins/replication-server/types.d.ts b/src/plugins/replication-server/types.d.ts deleted file mode 100644 index 0ce199b9..00000000 --- a/src/plugins/replication-server/types.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { ReplicationOptions, ReplicationPullOptions, ReplicationPushOptions, RxStorageDefaultCheckpoint } from 'rxdb/plugins/core'; -export type ServerSyncPullOptions = Omit, 'handler' | 'stream$'> & {}; -export type ServerSyncPushOptions = Omit, 'handler'> & {}; -export type ServerSyncOptions = Omit, 'pull' | 'push'> & { - url: string; - headers?: { - [k: string]: string; - }; - pull?: ServerSyncPullOptions; - push?: ServerSyncPushOptions; - /** - * If the EventSource API is not available - * on the runtime, pass an own implementation here. - * Mostly used with the "eventsource" npm package on Node.js. - */ - eventSource?: typeof EventSource | any; -}; -export type RxServerCheckpoint = { - id: string; - lwt: number; -}; diff --git a/src/plugins/server/endpoint-replication.d.ts b/src/plugins/server/endpoint-replication.d.ts deleted file mode 100644 index 44fcfd1a..00000000 --- a/src/plugins/server/endpoint-replication.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RxCollection, RxReplicationHandler, StringKeys } from 'rxdb/plugins/core'; -import type { RxServer } from './rx-server.ts'; -import type { RxServerChangeValidator, RxServerEndpoint, RxServerQueryModifier } from './types.ts'; -export type RxReplicationEndpointMessageType = { - id: string; - method: StringKeys> | 'auth'; - params: any[]; -}; -export declare class RxServerReplicationEndpoint implements RxServerEndpoint { - readonly server: RxServer; - readonly name: string; - readonly collection: RxCollection; - readonly serverOnlyFields: string[]; - readonly cors?: string | undefined; - readonly type = "replication"; - readonly urlPath: string; - readonly changeValidator: RxServerChangeValidator; - readonly queryModifier: RxServerQueryModifier; - constructor(server: RxServer, name: string, collection: RxCollection, queryModifier: RxServerQueryModifier, changeValidator: RxServerChangeValidator, serverOnlyFields: string[], cors?: string | undefined); -} -/** - * "block" the previous version urls and send a 426 on them so that - * the clients know they must update. - */ -export declare function blockPreviousReplicationVersionPaths(server: RxServer, path: string, currentVersion: number): void; diff --git a/src/plugins/server/endpoint-rest.d.ts b/src/plugins/server/endpoint-rest.d.ts deleted file mode 100644 index c4bb2d79..00000000 --- a/src/plugins/server/endpoint-rest.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { RxCollection } from 'rxdb/plugins/core'; -import type { RxServer } from './rx-server.ts'; -import type { RxServerChangeValidator, RxServerEndpoint, RxServerQueryModifier } from './types.ts'; -export declare const REST_PATHS: readonly ['query', 'query/observe', 'get', 'set', 'delete']; -export declare class RxServerRestEndpoint implements RxServerEndpoint { - readonly server: RxServer; - readonly name: string; - readonly collection: RxCollection; - readonly serverOnlyFields: string[]; - readonly cors?: string | undefined; - readonly type = "rest"; - readonly urlPath: string; - readonly changeValidator: RxServerChangeValidator; - readonly queryModifier: RxServerQueryModifier; - constructor(server: RxServer, name: string, collection: RxCollection, queryModifier: RxServerQueryModifier, changeValidator: RxServerChangeValidator, serverOnlyFields: string[], cors?: string | undefined); -} -/** - * "block" the previous version urls and send a 426 on them so that - * the clients know they must update. - */ -export declare function blockPreviousReplicationVersionPathsRest(server: RxServer, path: string, currentVersion: number): void; diff --git a/src/plugins/server/helper.d.ts b/src/plugins/server/helper.d.ts deleted file mode 100644 index 7689e473..00000000 --- a/src/plugins/server/helper.d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { RxServer } from './rx-server'; -import type { RxServerAuthData, RxServerEndpoint } from './types'; -import { MangoQuerySelector, RxDocumentData } from 'rxdb/plugins/core'; -export declare function setCors(server: RxServer, path: string, cors?: string): void; -export declare function getAuthDataByRequest(server: RxServer, request: RequestType, response: ResponseType): Promise | false>; -export declare function getDocAllowedMatcher(endpoint: RxServerEndpoint, authData: RxServerAuthData): any; -export declare function docContainsServerOnlyFields(serverOnlyFields: string[], doc: any): string | undefined; -/** - * Returns a function that strips the given server-only fields from a client - * document. This is used when accepting a NEW document from a client write to - * make sure that server-only fields cannot be populated by the client. - * - * Unlike {@link removeServerOnlyFieldsMonad} this does not assign undefined to - * RxDB internal meta fields (`_meta`, `_rev`, `_attachments`) so the result can - * be safely passed to `RxCollection.insert()`. - */ -export declare function stripServerOnlyFieldsMonad(serverOnlyFields: string[]): (docData: RxDocType | RxDocumentData) => any; -export declare function removeServerOnlyFieldsMonad(serverOnlyFields: string[]): (docData?: RxDocType | RxDocumentData) => any; -export declare function mergeServerDocumentFieldsMonad(serverOnlyFields: string[]): (clientDoc: RxDocType | RxDocumentData, serverDoc?: RxDocType | RxDocumentData) => any; -/** - * $regex queries are dangerous because they can dos-attack the server. - * - * @param selector - */ -export declare function doesContainRegexQuerySelector(selector: MangoQuerySelector | any): boolean; diff --git a/src/plugins/server/index.d.ts b/src/plugins/server/index.d.ts deleted file mode 100644 index 04ecde0b..00000000 --- a/src/plugins/server/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { RxServer } from './rx-server.ts'; -import { RxServerOptions } from './types.ts'; -export * from './types.ts'; -export * from './endpoint-replication.ts'; -export * from './endpoint-rest.ts'; -export * from './helper.ts'; -export * from './performance-test.ts'; -export declare function createRxServer(options: RxServerOptions): Promise>; diff --git a/src/plugins/server/performance-test.d.ts b/src/plugins/server/performance-test.d.ts deleted file mode 100644 index aaa2e24e..00000000 --- a/src/plugins/server/performance-test.d.ts +++ /dev/null @@ -1,43 +0,0 @@ -/** - * A reusable performance test suite for RxDB server adapters. - * This function can be exported and used by consumers who - * create custom adapters to verify their performance characteristics. - */ -import type { RxDatabase } from 'rxdb/plugins/core'; -import type { RxServerAdapter } from './types.ts'; -export type PerformanceTestResult = { - /** Name of the test case */ - name: string; - /** Total time in milliseconds */ - timeMs: number; - /** Number of operations performed */ - opsCount: number; - /** Calculated operations per second */ - opsPerSecond: number; -}; -export type PerformanceTestOptions = { - adapter: RxServerAdapter; - /** - * Function that creates a fresh RxDatabase instance. - * Must return a database that can be closed after each test. - */ - createDatabase: () => Promise; - /** - * Function that resolves an available port for the server. - */ - getPort: () => Promise; - /** - * Number of documents to use for each test. - * [default=30] - */ - batchSize?: number; -}; -/** - * Runs a set of performance tests against the given adapter. - * Each test creates its own server and collection, measures - * the time for the operations, and tears down afterwards. - * - * Returns an array of results that callers can assert against - * or log for comparison purposes. - */ -export declare function performanceTest(options: PerformanceTestOptions): Promise; diff --git a/src/plugins/server/rx-server.d.ts b/src/plugins/server/rx-server.d.ts deleted file mode 100644 index 261aca32..00000000 --- a/src/plugins/server/rx-server.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { RxCollection, RxDatabase } from 'rxdb/plugins/core'; -import { RxServerReplicationEndpoint } from './endpoint-replication.ts'; -import type { RxServerAdapter, RxServerAuthHandler, RxServerChangeValidator, RxServerEndpoint, RxServerOptions, RxServerQueryModifier } from './types.ts'; -import { RxServerRestEndpoint } from './endpoint-rest.ts'; -export declare class RxServer { - readonly options: RxServerOptions; - readonly authHandler: RxServerAuthHandler; - readonly serverApp: ServerAppType; - readonly cors: string; - readonly endpoints: RxServerEndpoint[]; - private closeFn; - listenPromise?: Promise; - readonly database: RxDatabase; - readonly adapter: RxServerAdapter; - constructor(options: RxServerOptions, authHandler: RxServerAuthHandler, serverApp: ServerAppType, cors?: string); - private ensureNotStarted; - addReplicationEndpoint(opts: { - name: string; - collection: RxCollection; - queryModifier?: RxServerQueryModifier; - changeValidator?: RxServerChangeValidator; - /** - * Set a origin for allowed CORS requests. - * Overwrites the cors option of the server. - * [default='*'] - */ - cors?: '*' | string; - serverOnlyFields?: string[]; - }): RxServerReplicationEndpoint; - addRestEndpoint(opts: { - name: string; - collection: RxCollection; - queryModifier?: RxServerQueryModifier; - changeValidator?: RxServerChangeValidator; - /** - * Set a origin for allowed CORS requests. - * Overwrites the cors option of the server. - * [default='*'] - */ - cors?: '*' | string; - serverOnlyFields?: string[]; - }): RxServerRestEndpoint; - start(): Promise; - close(): Promise; -} diff --git a/src/plugins/server/types.d.ts b/src/plugins/server/types.d.ts deleted file mode 100644 index 24557049..00000000 --- a/src/plugins/server/types.d.ts +++ /dev/null @@ -1,88 +0,0 @@ -import type { FilledMangoQuery, RxDatabase, RxReplicationWriteToMasterRow, MaybePromise, RxCollection } from 'rxdb/plugins/core'; -import { IncomingHttpHeaders } from 'http'; -export type RxServerOptions = { - database: RxDatabase; - adapter: RxServerAdapter; - serverApp?: ServerAppType; - authHandler?: RxServerAuthHandler; - appOptions?: any; - /** - * [default=localhost] - */ - hostname?: 'localhost' | '0.0.0.0' | string; - port: number; - /** - * Set a origin for allowed CORS requests. - * Can be overwritten by the cors option of the endpoints. - * [default='*'] - */ - cors?: '*' | string; -}; -export type RxServerRouteHandler = (req: RequestType, res: ResponseType, next?: any) => MaybePromise; -export type RxServerAdapter = { - create(): Promise; - get(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; - post(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; - all(app: ServerAppType, path: string, handler: RxServerRouteHandler): void; - setCors(app: ServerAppType, path: string, cors: string): MaybePromise; - getRequestBody(req: RequestType): any; - getRequestHeaders(req: RequestType): { - [k: string]: string; - }; - getRequestQuery(req: RequestType): any; - onRequestClose(req: RequestType, handler: () => void): void; - setResponseHeader(res: ResponseType, name: string, value: string): void; - endResponseJson(res: ResponseType, data: any): void; - endResponse(res: ResponseType): void; - responseWrite(res: ResponseType, data: string): void; - setSSEHeaders(res: ResponseType): void; - closeConnection(res: ResponseType, code: number, message: string): void; - listen(app: ServerAppType, port: number, hostname: string): Promise; - closeAllConnections(app: ServerAppType): MaybePromise; - close(app: ServerAppType): Promise; -}; -export type RxServerAuthData = { - data: AuthType; - validUntil: number; -}; -/** - * Returns the auth state by the given request headers. - * Throws if auth not valid. - */ -export type RxServerAuthHandler = (headers: IncomingHttpHeaders) => MaybePromise>; -/** - * Modifies a given query in a way to limit the results - * to what the authenticated user is allowed to see. - * For example the query selector - * input: { - * selector: { - * myField: { $gt: 100 } - * } - * } - * could be modified to restrict the results to only return - * documents that are "owned" by the user - * return: { - * selector: { - * myField: { $gt: 100 }, - * userId: { $eq: authData.userId } - * } - * } - * - * - */ -export type RxServerQueryModifier = (authData: RxServerAuthData, query: FilledMangoQuery) => FilledMangoQuery; -/** - * Validates if a given change is allowed to be performed on the server. - * Returns true if allowed, false if not. - * If a client tries to make a non-allowed change, - * the client will be disconnected. - */ -export type RxServerChangeValidator = (authData: RxServerAuthData, change: RxReplicationWriteToMasterRow) => boolean; -export interface RxServerEndpoint { - collection: RxCollection; - name: string; - type: 'replication' | 'rest' | string; - urlPath: string; - queryModifier?: RxServerQueryModifier; - changeValidator?: RxServerChangeValidator; -} diff --git a/src/utils.d.ts b/src/utils.d.ts deleted file mode 100644 index 1322b3df..00000000 --- a/src/utils.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function customFetchWithFixedHeaders(headers: any): (url: string | URL, options?: any) => Promise;