@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.
@@ -82,7 +82,7 @@ export class AptlyResponseError extends Error {
82
82
  return this;
83
83
  }
84
84
  toString() {
85
- return JSON.stringify(this.toJSON());
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.');
@@ -1,10 +1,13 @@
1
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;
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 {};
@@ -1,5 +1,12 @@
1
1
  import mongoose from 'mongoose';
2
- export function getId(IdOrDocument) {
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 toId(_id) {
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 matchId(a, b) {
34
+ export function matchObjectId(a, b) {
28
35
  if (!a || !b)
29
36
  return a === b;
30
- const aa = getId(a);
31
- const bb = getId(b);
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 byId(id) {
37
- return (obj) => matchId(obj, id);
43
+ export function byObjectId(id) {
44
+ return (obj) => matchObjectId(obj, id);
38
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aptly-as/sdk-nodejs",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Aptly SDK library for node.js applications",
5
5
  "type": "module",
6
6
  "main": "index.js",