@atscript/mongo 0.1.33 → 0.1.34
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.cjs +9 -26
- package/dist/index.d.ts +18 -8
- package/dist/index.mjs +10 -27
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -926,7 +926,7 @@ function _define_property(obj, key, value) {
|
|
|
926
926
|
else obj[key] = value;
|
|
927
927
|
return obj;
|
|
928
928
|
}
|
|
929
|
-
var AsMongo = class {
|
|
929
|
+
var AsMongo = class extends __atscript_utils_db.DbSpace {
|
|
930
930
|
get db() {
|
|
931
931
|
return this.client.db();
|
|
932
932
|
}
|
|
@@ -938,33 +938,16 @@ var AsMongo = class {
|
|
|
938
938
|
const list = await this.getCollectionsList();
|
|
939
939
|
return list.has(name);
|
|
940
940
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
this._ensureCreated(type, logger);
|
|
947
|
-
return this._tables.get(type);
|
|
948
|
-
}
|
|
949
|
-
_ensureCreated(type, logger) {
|
|
950
|
-
if (!this._adapters.has(type)) {
|
|
951
|
-
const adapter = new MongoAdapter(this.db, this);
|
|
952
|
-
const table = new __atscript_utils_db.AtscriptDbTable(type, adapter, logger || this.logger);
|
|
953
|
-
this._adapters.set(type, adapter);
|
|
954
|
-
this._tables.set(type, table);
|
|
955
|
-
}
|
|
941
|
+
/**
|
|
942
|
+
* Returns the MongoAdapter for the given type.
|
|
943
|
+
* Convenience accessor for Mongo-specific adapter operations.
|
|
944
|
+
*/ getAdapter(type) {
|
|
945
|
+
return super.getAdapter(type);
|
|
956
946
|
}
|
|
957
947
|
constructor(client, logger = NoopLogger) {
|
|
958
|
-
|
|
959
|
-
_define_property(this, "client", void 0);
|
|
960
|
-
|
|
961
|
-
_define_property(this, "_adapters", void 0);
|
|
962
|
-
_define_property(this, "_tables", void 0);
|
|
963
|
-
this.logger = logger;
|
|
964
|
-
this._adapters = new WeakMap();
|
|
965
|
-
this._tables = new WeakMap();
|
|
966
|
-
if (typeof client === "string") this.client = new mongodb.MongoClient(client);
|
|
967
|
-
else this.client = client;
|
|
948
|
+
const resolvedClient = typeof client === "string" ? new mongodb.MongoClient(client) : client;
|
|
949
|
+
super(() => new MongoAdapter(this.db, this), logger), _define_property(this, "client", void 0), _define_property(this, "collectionsList", void 0);
|
|
950
|
+
this.client = resolvedClient;
|
|
968
951
|
}
|
|
969
952
|
};
|
|
970
953
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TAtscriptAnnotatedType, TValidatorOptions, Validator, TValidatorPlugin, TMetadataMap } from '@atscript/typescript/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { DbSpace, getKeyProps, BaseDbAdapter, AtscriptDbTable, FilterExpr, TDbUpdateResult, TSearchIndexInfo, DbQuery, TDbInsertResult, TDbInsertManyResult, TDbDeleteResult } from '@atscript/utils-db';
|
|
3
3
|
import * as mongodb from 'mongodb';
|
|
4
4
|
import { MongoClient, Filter, UpdateFilter, Document, UpdateOptions, Db, Collection, AggregationCursor, ObjectId } from 'mongodb';
|
|
5
5
|
|
|
@@ -11,19 +11,29 @@ interface TGenericLogger {
|
|
|
11
11
|
debug(...messages: any[]): void;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* MongoDB database space — extends {@link DbSpace} with MongoDB-specific
|
|
16
|
+
* features (cached collection list, `Db` access, `MongoAdapter` factory).
|
|
17
|
+
*
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const asMongo = new AsMongo('mongodb://localhost:27017/mydb')
|
|
20
|
+
* const users = asMongo.getTable(UsersType)
|
|
21
|
+
* const posts = asMongo.getTable(PostsType)
|
|
22
|
+
* // Relation loading via $with works automatically
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
declare class AsMongo extends DbSpace {
|
|
16
26
|
readonly client: MongoClient;
|
|
17
27
|
constructor(client: string | MongoClient, logger?: TGenericLogger);
|
|
18
28
|
get db(): mongodb.Db;
|
|
19
29
|
protected collectionsList?: Promise<Set<string>>;
|
|
20
30
|
protected getCollectionsList(): Promise<Set<string>>;
|
|
21
31
|
collectionExists(name: string): Promise<boolean>;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Returns the MongoAdapter for the given type.
|
|
34
|
+
* Convenience accessor for Mongo-specific adapter operations.
|
|
35
|
+
*/
|
|
36
|
+
getAdapter(type: TAtscriptAnnotatedType): MongoAdapter;
|
|
27
37
|
}
|
|
28
38
|
|
|
29
39
|
/**
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseDbAdapter, DbSpace, getKeyProps, walkFilter } from "@atscript/utils-db";
|
|
2
2
|
import { MongoClient, ObjectId } from "mongodb";
|
|
3
3
|
import { defineAnnotatedType, isAnnotatedTypeOfPrimitive } from "@atscript/typescript/utils";
|
|
4
4
|
|
|
@@ -902,7 +902,7 @@ function _define_property(obj, key, value) {
|
|
|
902
902
|
else obj[key] = value;
|
|
903
903
|
return obj;
|
|
904
904
|
}
|
|
905
|
-
var AsMongo = class {
|
|
905
|
+
var AsMongo = class extends DbSpace {
|
|
906
906
|
get db() {
|
|
907
907
|
return this.client.db();
|
|
908
908
|
}
|
|
@@ -914,33 +914,16 @@ var AsMongo = class {
|
|
|
914
914
|
const list = await this.getCollectionsList();
|
|
915
915
|
return list.has(name);
|
|
916
916
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
this._ensureCreated(type, logger);
|
|
923
|
-
return this._tables.get(type);
|
|
924
|
-
}
|
|
925
|
-
_ensureCreated(type, logger) {
|
|
926
|
-
if (!this._adapters.has(type)) {
|
|
927
|
-
const adapter = new MongoAdapter(this.db, this);
|
|
928
|
-
const table = new AtscriptDbTable(type, adapter, logger || this.logger);
|
|
929
|
-
this._adapters.set(type, adapter);
|
|
930
|
-
this._tables.set(type, table);
|
|
931
|
-
}
|
|
917
|
+
/**
|
|
918
|
+
* Returns the MongoAdapter for the given type.
|
|
919
|
+
* Convenience accessor for Mongo-specific adapter operations.
|
|
920
|
+
*/ getAdapter(type) {
|
|
921
|
+
return super.getAdapter(type);
|
|
932
922
|
}
|
|
933
923
|
constructor(client, logger = NoopLogger) {
|
|
934
|
-
|
|
935
|
-
_define_property(this, "client", void 0);
|
|
936
|
-
|
|
937
|
-
_define_property(this, "_adapters", void 0);
|
|
938
|
-
_define_property(this, "_tables", void 0);
|
|
939
|
-
this.logger = logger;
|
|
940
|
-
this._adapters = new WeakMap();
|
|
941
|
-
this._tables = new WeakMap();
|
|
942
|
-
if (typeof client === "string") this.client = new MongoClient(client);
|
|
943
|
-
else this.client = client;
|
|
924
|
+
const resolvedClient = typeof client === "string" ? new MongoClient(client) : client;
|
|
925
|
+
super(() => new MongoAdapter(this.db, this), logger), _define_property(this, "client", void 0), _define_property(this, "collectionsList", void 0);
|
|
926
|
+
this.client = resolvedClient;
|
|
944
927
|
}
|
|
945
928
|
};
|
|
946
929
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/mongo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.34",
|
|
4
4
|
"description": "Mongodb plugin for atscript.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"atscript",
|
|
@@ -57,9 +57,9 @@
|
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"mongodb": "^6.17.0",
|
|
60
|
-
"@atscript/core": "^0.1.
|
|
61
|
-
"@atscript/
|
|
62
|
-
"@atscript/
|
|
60
|
+
"@atscript/core": "^0.1.34",
|
|
61
|
+
"@atscript/typescript": "^0.1.34",
|
|
62
|
+
"@atscript/utils-db": "^0.1.34"
|
|
63
63
|
},
|
|
64
64
|
"build": [
|
|
65
65
|
{},
|