@livequery/mongoose 2.0.53 → 2.0.55
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.
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { LivequeryRequest, LivequeryBaseEntity, WebsocketSyncPayload } from '@livequery/types';
|
|
2
2
|
import mongoose, { Connection, Schema } from 'mongoose';
|
|
3
|
-
import { Subject } from 'rxjs
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
init: (routes: Array<{
|
|
3
|
+
import { Subject } from 'rxjs';
|
|
4
|
+
export type LivequeryDatasource<Config, RouteOptions> = Subject<WebsocketSyncPayload<LivequeryBaseEntity>> & {
|
|
5
|
+
init(config: Config, routes: Array<{
|
|
7
6
|
path: string;
|
|
7
|
+
method: number;
|
|
8
8
|
options: RouteOptions;
|
|
9
|
-
}>)
|
|
10
|
-
query
|
|
9
|
+
}>): Promise<void>;
|
|
10
|
+
query: (query: LivequeryRequest, options: RouteOptions) => Promise<any>;
|
|
11
11
|
};
|
|
12
12
|
export type MongooseDatasourceConfig = {
|
|
13
13
|
connections: {
|
|
@@ -21,16 +21,17 @@ export type RouteOptions<T = any> = {
|
|
|
21
21
|
db?: string | ((req: LivequeryRequest) => Promise<string> | string);
|
|
22
22
|
connection?: string | ((req: LivequeryRequest) => Promise<string> | string);
|
|
23
23
|
};
|
|
24
|
-
export declare class MongooseDatasource extends Subject<WebsocketSyncPayload<
|
|
24
|
+
export declare class MongooseDatasource extends Subject<WebsocketSyncPayload<LivequeryBaseEntity>> implements LivequeryDatasource<MongooseDatasourceConfig, RouteOptions> {
|
|
25
25
|
#private;
|
|
26
|
-
private config;
|
|
27
26
|
readonly refs: Map<string, Set<string>>;
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
config: MongooseDatasourceConfig;
|
|
28
|
+
routes: Map<string, RouteOptions<any>>;
|
|
29
|
+
init(config: MongooseDatasourceConfig, routes: Array<{
|
|
30
30
|
path: string;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
method: number;
|
|
32
|
+
options: RouteOptions;
|
|
33
|
+
}>): Promise<void>;
|
|
34
|
+
query(req: LivequeryRequest, options: RouteOptions): Promise<mongoose.mongo.DeleteResult | mongoose.UpdateWriteOpResult | {
|
|
34
35
|
items: any[];
|
|
35
36
|
summary: any;
|
|
36
37
|
has: {
|
|
@@ -54,8 +55,4 @@ export declare class MongooseDatasource extends Subject<WebsocketSyncPayload<any
|
|
|
54
55
|
} | {
|
|
55
56
|
item: any;
|
|
56
57
|
}>;
|
|
57
|
-
link(watcher: (routes: Array<{
|
|
58
|
-
path: string;
|
|
59
|
-
options: RouteOptions;
|
|
60
|
-
}>, config: MongooseDatasourceConfig) => Observable<WebsocketSyncPayload>): import("rxjs").Subscription;
|
|
61
58
|
}
|
|
@@ -2,20 +2,22 @@ import { Cursor } from './Cursor.js';
|
|
|
2
2
|
import { MongoQuery } from "./MongoQuery.js";
|
|
3
3
|
import { ObjectId } from 'bson';
|
|
4
4
|
import { SmartCache } from './SmartCache.js';
|
|
5
|
-
import { Subject } from 'rxjs
|
|
6
|
-
import { BehaviorSubject, switchMap } from 'rxjs';
|
|
5
|
+
import { Subject } from 'rxjs';
|
|
7
6
|
export class MongooseDatasource extends Subject {
|
|
8
|
-
config;
|
|
9
7
|
#schemas = new SmartCache();
|
|
10
8
|
#models = new SmartCache();
|
|
11
9
|
refs = new Map();
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
config;
|
|
11
|
+
routes;
|
|
12
|
+
async init(config, routes) {
|
|
14
13
|
this.config = config;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
this.routes = routes.reduce((p, c) => {
|
|
15
|
+
const set = p.get(c.path);
|
|
16
|
+
if (set && set.schema != c.options.schema)
|
|
17
|
+
throw new Error('Schema mismatch for route path "' + c.path + '"');
|
|
18
|
+
p.set(c.path, c.options);
|
|
19
|
+
return p;
|
|
20
|
+
}, new Map());
|
|
19
21
|
}
|
|
20
22
|
async query(req, options) {
|
|
21
23
|
const connection_name = typeof options.connection == 'function' ? await options.connection(req) : (options.connection || Object.keys(this.config.connections)[0] || 'default');
|
|
@@ -171,7 +173,4 @@ export class MongooseDatasource extends Subject {
|
|
|
171
173
|
...req.body ? { body: this.#convert(req.body, fields) } : {}
|
|
172
174
|
};
|
|
173
175
|
}
|
|
174
|
-
link(watcher) {
|
|
175
|
-
return this.#routes$.pipe(switchMap(routes => watcher(routes, this.config))).subscribe();
|
|
176
|
-
}
|
|
177
176
|
}
|
package/build/src/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './MongooseDatasource.js';
|
|
2
2
|
export * from './DataChangePayload.js';
|
package/build/src/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './MongooseDatasource.js';
|
|
2
2
|
export * from './DataChangePayload.js';
|
package/package.json
CHANGED