@aptly-as/sdk-nodejs 0.2.0 → 0.2.2
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/error/ResponseError.js +1 -1
- package/mongoose/mongoose.d.ts +11 -8
- package/mongoose/mongoose.js +14 -7
- package/package.json +1 -1
package/error/ResponseError.js
CHANGED
@@ -82,7 +82,7 @@ export class AptlyResponseError extends Error {
|
|
82
82
|
return this;
|
83
83
|
}
|
84
84
|
toString() {
|
85
|
-
return
|
85
|
+
return `${this.message}: ${this.detail}`;
|
86
86
|
}
|
87
87
|
res(_request, _response) {
|
88
88
|
throw new Error('AptlyResponseError res function has not been implemented.');
|
package/mongoose/mongoose.d.ts
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
type
|
3
|
-
|
4
|
-
|
5
|
-
export declare function
|
6
|
-
|
7
|
-
|
8
|
-
export declare function
|
9
|
-
export declare function
|
2
|
+
type MongooseId = mongoose.Types.ObjectId | string;
|
3
|
+
type MongooseDocument = mongoose.Document<mongoose.Types.ObjectId>;
|
4
|
+
type MongooseIdOrDocument = MongooseId | MongooseDocument;
|
5
|
+
export declare function getStringId<T extends string | {
|
6
|
+
_id: string;
|
7
|
+
} | null | undefined>(idOrDocument: T): string;
|
8
|
+
export declare function getObjectId(IdOrDocument?: MongooseIdOrDocument): mongoose.Types.ObjectId | null | undefined;
|
9
|
+
export declare function toObjectId(_id: MongooseId): mongoose.Types.ObjectId;
|
10
|
+
export declare function isId(_id?: MongooseId): boolean | RegExpMatchArray | null;
|
11
|
+
export declare function matchObjectId(a?: MongooseIdOrDocument, b?: MongooseIdOrDocument): boolean;
|
12
|
+
export declare function byObjectId(id?: MongooseIdOrDocument): (obj?: MongooseIdOrDocument) => boolean;
|
10
13
|
export {};
|
package/mongoose/mongoose.js
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
import mongoose from 'mongoose';
|
2
|
-
export function
|
2
|
+
export function getStringId(idOrDocument) {
|
3
|
+
if (!idOrDocument)
|
4
|
+
return '';
|
5
|
+
if (typeof idOrDocument === 'string')
|
6
|
+
return idOrDocument;
|
7
|
+
return String(idOrDocument._id);
|
8
|
+
}
|
9
|
+
export function getObjectId(IdOrDocument) {
|
3
10
|
if (!IdOrDocument)
|
4
11
|
return null;
|
5
12
|
if (IdOrDocument instanceof mongoose.Document) {
|
@@ -14,7 +21,7 @@ export function getId(IdOrDocument) {
|
|
14
21
|
}
|
15
22
|
return null;
|
16
23
|
}
|
17
|
-
export function
|
24
|
+
export function toObjectId(_id) {
|
18
25
|
if (typeof _id === 'string')
|
19
26
|
return new mongoose.Types.ObjectId(_id);
|
20
27
|
return _id;
|
@@ -24,15 +31,15 @@ export function isId(_id) {
|
|
24
31
|
return true;
|
25
32
|
return typeof _id === 'string' && _id.match(/^[a-fA-F0-9]{24}$/);
|
26
33
|
}
|
27
|
-
export function
|
34
|
+
export function matchObjectId(a, b) {
|
28
35
|
if (!a || !b)
|
29
36
|
return a === b;
|
30
|
-
const aa =
|
31
|
-
const bb =
|
37
|
+
const aa = getObjectId(a);
|
38
|
+
const bb = getObjectId(b);
|
32
39
|
if (!aa || !bb)
|
33
40
|
return aa === bb;
|
34
41
|
return aa.equals(bb);
|
35
42
|
}
|
36
|
-
export function
|
37
|
-
return (obj) =>
|
43
|
+
export function byObjectId(id) {
|
44
|
+
return (obj) => matchObjectId(obj, id);
|
38
45
|
}
|