@livequery/mongoose 2.0.51 → 2.0.52
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/build/src/MongooseDatasource.d.ts +22 -7
- package/build/src/MongooseDatasource.js +6 -14
- package/build/src/index.d.ts +1 -2
- package/build/src/index.js +0 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/build/src/RouteOptions.d.ts +0 -7
- package/build/src/RouteOptions.js +0 -1
|
@@ -1,14 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import mongoose, { Connection } from 'mongoose';
|
|
1
|
+
import { LivequeryRequest, LivequeryBaseEntity, WebsocketSyncPayload } from '@livequery/types';
|
|
2
|
+
import mongoose, { Connection, Schema } from 'mongoose';
|
|
4
3
|
import { Subject } from 'rxjs/internal/Subject';
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { Observable } from 'rxjs';
|
|
5
|
+
export type LivequeryDatasource<Config, RouteOptions> = Observable<WebsocketSyncPayload<LivequeryBaseEntity>> & {
|
|
6
|
+
init?: (config: Config, options: Array<{
|
|
7
|
+
path: string;
|
|
8
|
+
options: RouteOptions;
|
|
9
|
+
}>) => Promise<void>;
|
|
10
|
+
query?: (query: LivequeryRequest, config: Config, options: RouteOptions) => any;
|
|
7
11
|
};
|
|
8
|
-
export
|
|
12
|
+
export type MongooseDatasourceConfig = {
|
|
13
|
+
connections: {
|
|
14
|
+
[key: string]: Connection;
|
|
15
|
+
};
|
|
16
|
+
databases: string[];
|
|
17
|
+
};
|
|
18
|
+
export type RouteOptions<T = any> = {
|
|
19
|
+
realtime?: boolean;
|
|
20
|
+
schema: Schema<T>;
|
|
21
|
+
db?: string | ((req: LivequeryRequest) => Promise<string> | string);
|
|
22
|
+
};
|
|
23
|
+
export declare class MongooseDatasource extends Subject<WebsocketSyncPayload<any>> implements LivequeryDatasource<MongooseDatasourceConfig, RouteOptions> {
|
|
9
24
|
#private;
|
|
10
25
|
readonly refs: Map<string, Set<string>>;
|
|
11
|
-
query(
|
|
26
|
+
query(req: LivequeryRequest, config: MongooseDatasourceConfig, options: RouteOptions): Promise<mongoose.mongo.DeleteResult | mongoose.UpdateWriteOpResult | {
|
|
12
27
|
items: any[];
|
|
13
28
|
summary: any;
|
|
14
29
|
has: {
|
|
@@ -7,18 +7,16 @@ export class MongooseDatasource extends Subject {
|
|
|
7
7
|
#schemas = new SmartCache();
|
|
8
8
|
#models = new SmartCache();
|
|
9
9
|
refs = new Map();
|
|
10
|
-
async query(
|
|
11
|
-
const db = typeof
|
|
12
|
-
const schema =
|
|
10
|
+
async query(req, config, options) {
|
|
11
|
+
const db = typeof options.db == 'function' ? await options.db(req) : options.db || process.env.DB_NAME || 'main';
|
|
12
|
+
const schema = options.schema;
|
|
13
13
|
const collection_name = schema.options.collection;
|
|
14
14
|
const model = await this.#models.get(`${db}|${collection_name}`, async () => {
|
|
15
|
-
return
|
|
15
|
+
return config.connections[db].model(collection_name, schema, collection_name);
|
|
16
16
|
});
|
|
17
|
-
const query = await this.normalizeRef(
|
|
18
|
-
if (query.method == 'get')
|
|
19
|
-
config.realtime && this.#log(query, model);
|
|
17
|
+
const query = await this.normalizeRef(req, schema);
|
|
18
|
+
if (query.method == 'get')
|
|
20
19
|
return await this.#get(query, model);
|
|
21
|
-
}
|
|
22
20
|
if (query.method == 'post')
|
|
23
21
|
return this.#post(query, model);
|
|
24
22
|
if (query.method == 'put')
|
|
@@ -29,12 +27,6 @@ export class MongooseDatasource extends Subject {
|
|
|
29
27
|
return this.#del(query, model);
|
|
30
28
|
throw { status: 500, code: 'INVAILD_METHOD', message: 'Invaild method' };
|
|
31
29
|
}
|
|
32
|
-
#log(req, model) {
|
|
33
|
-
const _ = this.refs.get(model.collection.name);
|
|
34
|
-
const set = _ || new Set();
|
|
35
|
-
set.add(req.collection_ref);
|
|
36
|
-
!_ && this.refs.set(model.collection.name, set);
|
|
37
|
-
}
|
|
38
30
|
async #get(req, model) {
|
|
39
31
|
const { limit, items, count, has, summary } = await MongoQuery.query(req, model);
|
|
40
32
|
const current = items.length;
|
package/build/src/index.d.ts
CHANGED
package/build/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../src/cursor.ts","../src/datachangepayload.ts","../src/mongoquery.ts","../src/mongoosedatasource.ts","../src/
|
|
1
|
+
{"root":["../src/cursor.ts","../src/datachangepayload.ts","../src/mongoquery.ts","../src/mongoosedatasource.ts","../src/smartcache.ts","../src/index.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"repository": {
|
|
7
7
|
"url": "git@github.com:livequery/mongoose.git"
|
|
8
8
|
},
|
|
9
|
-
"version": "2.0.
|
|
9
|
+
"version": "2.0.52",
|
|
10
10
|
"description": "Mongoose datasource mapping for @livequery ecosystem",
|
|
11
11
|
"main": "./build/src/index.js",
|
|
12
12
|
"types": "./build/src/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build": "rm -rf build; tsc -b .",
|
|
33
33
|
"deploy": "rm -rf build && yarn build; git add .; git commit -m \"Update\"; git push origin master; npm publish --access public"
|
|
34
34
|
},
|
|
35
|
-
"
|
|
35
|
+
"peerDependencies": {
|
|
36
36
|
"bson": "*",
|
|
37
37
|
"mongoose": "^8.6.2"
|
|
38
38
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|