@radatek/microserver 2.2.0 → 2.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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * MicroServer
3
- * @version 2.2.0
3
+ * @version 2.2.2
4
4
  * @package @radatek/microserver
5
5
  * @copyright Darius Kisonas 2022
6
6
  * @license MIT
@@ -798,7 +798,7 @@ export declare class MicroCollection {
798
798
  /** Query document with query filter */
799
799
  protected queryDocument(query?: Query, data?: Document): Document;
800
800
  /** Count all documents */
801
- count(): Promise<number>;
801
+ countDocuments(): Promise<number>;
802
802
  /** Find one matching document */
803
803
  findOne(query: Query): Promise<Document | undefined>;
804
804
  /** Find all matching documents */
@@ -808,10 +808,18 @@ export declare class MicroCollection {
808
808
  /** Insert one document */
809
809
  insertOne(doc: Document): Promise<Document>;
810
810
  /** Insert multiple documents */
811
- insert(docs: Document[]): Promise<Document[]>;
811
+ insertMany(docs: Document[]): Promise<Document[]>;
812
812
  /** Delete one matching document */
813
813
  deleteOne(query: Query): Promise<void>;
814
814
  /** Delete all matching documents */
815
815
  deleteMany(query: Query): Promise<number>;
816
+ updateOne(query: Query, doc: Document, options?: FindOptions): Promise<{
817
+ upsertedId: any;
818
+ modifiedCount: number;
819
+ }>;
820
+ updateMany(query: Query, update: any, options?: FindOptions): Promise<{
821
+ upsertedId: any;
822
+ modifiedCount: number;
823
+ }>;
816
824
  }
817
825
 
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * MicroServer
3
- * @version 2.2.0
3
+ * @version 2.2.2
4
4
  * @package @radatek/microserver
5
5
  * @copyright Darius Kisonas 2022
6
6
  * @license MIT
@@ -833,6 +833,10 @@ export class Controller {
833
833
  method = keyMatch[1];
834
834
  url = keyMatch[2].startsWith('/') ? keyMatch[2] : ('/' + prefix + keyMatch[2]);
835
835
  }
836
+ if (!url && !method) {
837
+ method = 'GET';
838
+ url = '/' + prefix + key;
839
+ }
836
840
  if (!method)
837
841
  return;
838
842
  let autoAcl = method.toLowerCase();
@@ -970,6 +974,8 @@ export class Router extends EventEmitter {
970
974
  name = 'param:' + name;
971
975
  idx = 5;
972
976
  }
977
+ if (name === 'json')
978
+ return (req, res) => res.isJson = true;
973
979
  if (idx >= 0) {
974
980
  const v = name.slice(idx + 1);
975
981
  const type = name.slice(0, idx);
@@ -1686,7 +1692,7 @@ export class MicroServer extends EventEmitter {
1686
1692
  }
1687
1693
  /** Add router hook, alias to `server.router.hook(url, ...args)` */
1688
1694
  hook(url, ...args) {
1689
- this.router.hook(url, args.filter((o) => o));
1695
+ this.router.hook(url, ...args.filter((o) => o));
1690
1696
  return this;
1691
1697
  }
1692
1698
  }
@@ -2981,7 +2987,7 @@ export class MicroCollection {
2981
2987
  return data;
2982
2988
  }
2983
2989
  /** Count all documents */
2984
- async count() {
2990
+ async countDocuments() {
2985
2991
  await this.checkReady();
2986
2992
  return Object.keys(this.data).length;
2987
2993
  }
@@ -3082,7 +3088,7 @@ export class MicroCollection {
3082
3088
  return doc;
3083
3089
  }
3084
3090
  /** Insert multiple documents */
3085
- async insert(docs) {
3091
+ async insertMany(docs) {
3086
3092
  await this.checkReady();
3087
3093
  docs.forEach(doc => {
3088
3094
  if (doc._id && this.data[doc._id])
@@ -3117,4 +3123,27 @@ export class MicroCollection {
3117
3123
  });
3118
3124
  return count;
3119
3125
  }
3126
+ async updateOne(query, doc, options) {
3127
+ const count = await this.findAndModify({
3128
+ query,
3129
+ update: doc,
3130
+ upsert: options?.upsert,
3131
+ limit: 1
3132
+ });
3133
+ return {
3134
+ upsertedId: undefined,
3135
+ modifiedCount: count
3136
+ };
3137
+ }
3138
+ async updateMany(query, update, options) {
3139
+ const count = await this.findAndModify({
3140
+ ...options,
3141
+ query,
3142
+ update
3143
+ });
3144
+ return {
3145
+ upsertedId: undefined,
3146
+ modifiedCount: count
3147
+ };
3148
+ }
3120
3149
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@radatek/microserver",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "HTTP MicroServer",
5
5
  "author": "Darius Kisonas",
6
6
  "license": "MIT",
@@ -11,19 +11,11 @@
11
11
  "httpserver"
12
12
  ],
13
13
  "type": "module",
14
- "main": "microserver.ts",
15
- "files": [
16
- "dist"
17
- ],
14
+ "main": "microserver.js",
15
+ "module": "microserver.js",
16
+ "types": "microserver.d.ts",
18
17
  "repository": {
19
18
  "type": "git",
20
19
  "url": "git+https://github.com/radateklt/microserver.git"
21
- },
22
- "devDependencies": {
23
- "@types/node": "^22.19.0"
24
- },
25
- "scripts": {
26
- "build": "pnpm --package typescript dlx tsc -d -m nodenext -t es2021 microserver.ts --outDir dist && sed -Ei 's/\\\"use strict\\\";\\n\\n//g' dist/microserver.js && sed -Ei ':a;N;$!ba;s/\\n +private _[^\\n]+//g;s/export \\{\\};//g' dist/microserver.d.ts",
27
- "test": "node test.ts"
28
20
  }
29
21
  }