@aptly-as/sdk-nodejs 0.1.1 → 0.2.0
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 +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/mongoose/mongoose.d.ts +10 -0
- package/mongoose/mongoose.js +38 -0
- package/package.json +5 -3
- package/tsconfig.prod.json +8 -0
package/error/ResponseError.js
CHANGED
@@ -74,7 +74,7 @@ export class AptlyResponseError extends Error {
|
|
74
74
|
message: this.message,
|
75
75
|
detail: this.detail,
|
76
76
|
link: this.link,
|
77
|
-
errors: this.errors
|
77
|
+
errors: this.errors.map((x) => x.toJSON(true)),
|
78
78
|
};
|
79
79
|
}
|
80
80
|
log() {
|
@@ -82,7 +82,7 @@ export class AptlyResponseError extends Error {
|
|
82
82
|
return this;
|
83
83
|
}
|
84
84
|
toString() {
|
85
|
-
return
|
85
|
+
return JSON.stringify(this.toJSON());
|
86
86
|
}
|
87
87
|
res(_request, _response) {
|
88
88
|
throw new Error('AptlyResponseError res function has not been implemented.');
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
import mongoose from 'mongoose';
|
2
|
+
type IdOrDocument = mongoose.Document | mongoose.Types.ObjectId | null | string | {
|
3
|
+
_id: string | mongoose.Types.ObjectId;
|
4
|
+
};
|
5
|
+
export declare function getId(IdOrDocument?: IdOrDocument): mongoose.Types.ObjectId | null | undefined;
|
6
|
+
export declare function toId(_id: string | mongoose.Types.ObjectId): mongoose.Types.ObjectId;
|
7
|
+
export declare function isId(_id?: string | mongoose.Types.ObjectId): boolean | RegExpMatchArray | null;
|
8
|
+
export declare function matchId(a?: IdOrDocument, b?: IdOrDocument): boolean;
|
9
|
+
export declare function byId(id?: IdOrDocument): (obj?: IdOrDocument) => boolean;
|
10
|
+
export {};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import mongoose from 'mongoose';
|
2
|
+
export function getId(IdOrDocument) {
|
3
|
+
if (!IdOrDocument)
|
4
|
+
return null;
|
5
|
+
if (IdOrDocument instanceof mongoose.Document) {
|
6
|
+
return IdOrDocument._id;
|
7
|
+
}
|
8
|
+
if (typeof IdOrDocument === 'string')
|
9
|
+
return new mongoose.Types.ObjectId(IdOrDocument);
|
10
|
+
if ('_id' in IdOrDocument) {
|
11
|
+
if (typeof IdOrDocument._id === 'string')
|
12
|
+
return new mongoose.Types.ObjectId(IdOrDocument._id);
|
13
|
+
return IdOrDocument._id;
|
14
|
+
}
|
15
|
+
return null;
|
16
|
+
}
|
17
|
+
export function toId(_id) {
|
18
|
+
if (typeof _id === 'string')
|
19
|
+
return new mongoose.Types.ObjectId(_id);
|
20
|
+
return _id;
|
21
|
+
}
|
22
|
+
export function isId(_id) {
|
23
|
+
if (_id instanceof mongoose.Types.ObjectId)
|
24
|
+
return true;
|
25
|
+
return typeof _id === 'string' && _id.match(/^[a-fA-F0-9]{24}$/);
|
26
|
+
}
|
27
|
+
export function matchId(a, b) {
|
28
|
+
if (!a || !b)
|
29
|
+
return a === b;
|
30
|
+
const aa = getId(a);
|
31
|
+
const bb = getId(b);
|
32
|
+
if (!aa || !bb)
|
33
|
+
return aa === bb;
|
34
|
+
return aa.equals(bb);
|
35
|
+
}
|
36
|
+
export function byId(id) {
|
37
|
+
return (obj) => matchId(obj, id);
|
38
|
+
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@aptly-as/sdk-nodejs",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.2.0",
|
4
4
|
"description": "Aptly SDK library for node.js applications",
|
5
5
|
"type": "module",
|
6
6
|
"main": "index.js",
|
@@ -11,19 +11,21 @@
|
|
11
11
|
"@vitest/ui": "^2.1.8",
|
12
12
|
"husky": "^9.1.7",
|
13
13
|
"lint-staged": "^15.2.11",
|
14
|
+
"mongoose": "^8.9.5",
|
14
15
|
"prettier": "^3.4.2",
|
15
16
|
"typescript": "^5.7.2",
|
16
17
|
"vitest": "^2.1.8"
|
17
18
|
},
|
18
19
|
"peerDependencies": {
|
19
|
-
"@aptly-as/types": "*"
|
20
|
+
"@aptly-as/types": "*",
|
21
|
+
"mongoose": "*"
|
20
22
|
},
|
21
23
|
"lint-staged": {
|
22
24
|
"**/*": "prettier --write --ignore-unknown"
|
23
25
|
},
|
24
26
|
"scripts": {
|
25
27
|
"start": "tsc --incremental --watch",
|
26
|
-
"build": "tsc",
|
28
|
+
"build": "tsc --project tsconfig.prod.json",
|
27
29
|
"test": "vitest",
|
28
30
|
"test:ui": "vitest --ui --api 9527",
|
29
31
|
"test:run": "vitest run",
|