anote-server-libs 0.2.3 → 0.2.7

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
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModelDao = exports.promiseAllStepN = void 0;
3
+ exports.ModelDao = exports.Dao = exports.promiseAllStepN = void 0;
4
4
  function promiseAllStepN(n, list) {
5
5
  if (!list || !list.length)
6
6
  return Promise.resolve([]);
@@ -74,13 +74,6 @@ class Dao {
74
74
  return request.query('UPDATE ' + this.table + ' SET ' + this.updateDefinition + ' WHERE id=@' + (this.nFields + 1)).then(() => instance.id);
75
75
  }
76
76
  }
77
- replace(instance, client) {
78
- if (instance.archivedOn)
79
- return Promise.reject('Record archived!');
80
- return this.create({ ...instance, replaced_id: instance.id }, client).then(id => {
81
- return this.archive(instance.id, id, client).then(() => id);
82
- });
83
- }
84
77
  create(instance, client) {
85
78
  instance.createdOn = instance.updatedOn = new Date();
86
79
  if (this.pool) {
@@ -117,6 +110,7 @@ class Dao {
117
110
  }));
118
111
  }
119
112
  }
113
+ exports.Dao = Dao;
120
114
  class ModelDao extends Dao {
121
115
  get(id, client, lock = true) {
122
116
  if (this.pool) {
@@ -224,6 +218,13 @@ class ModelDao extends Dao {
224
218
  return request.query('UPDATE ' + this.table + ' SET "archivedOn"=now(),replaced_by_id=@1 WHERE id=@2');
225
219
  }
226
220
  }
221
+ replace(instance, client) {
222
+ if (instance.archivedOn)
223
+ return Promise.reject('Record archived!');
224
+ return this.create({ ...instance, replaced_id: instance.id }, client).then(id => {
225
+ return this.archive(instance.id, id, client).then(() => id);
226
+ });
227
+ }
227
228
  delete(id, client) {
228
229
  if (this.pool) {
229
230
  return client.query('DELETE FROM ' + this.table + ' WHERE id=$1', [id]);
@@ -58,7 +58,7 @@ export interface ViewCount<T> {
58
58
  count: number;
59
59
  }
60
60
 
61
- abstract class Dao<R, T extends Model<R>> implements ModelRepr {
61
+ export abstract class Dao<R, T extends Model<R>> implements ModelRepr {
62
62
  constructor(protected pool: Pool, protected poolMssql: ConnectionPool, protected logger: Logger, public table: string, protected nFields: number,
63
63
  protected updateDefinition: string) {
64
64
  }
@@ -96,13 +96,6 @@ abstract class Dao<R, T extends Model<R>> implements ModelRepr {
96
96
  }
97
97
  }
98
98
 
99
- replace(this: ModelDao<R, T>, instance: T, client: ClientBase | Transaction): Promise<R> {
100
- if((<any>instance).archivedOn) return Promise.reject('Record archived!');
101
- return this.create({...instance, replaced_id: instance.id}, client).then(id => {
102
- return this.archive(instance.id, id, client).then(() => id);
103
- });
104
- }
105
-
106
99
  create(instance: T, client?: ClientBase | Transaction): Promise<R> {
107
100
  (<any>instance).createdOn = instance.updatedOn = new Date();
108
101
  if(this.pool) {
@@ -247,6 +240,13 @@ export abstract class ModelDao<R, T extends Model<R>> extends Dao<R, T> {
247
240
  }
248
241
  }
249
242
 
243
+ replace(instance: T, client: ClientBase | Transaction): Promise<R> {
244
+ if((<any>instance).archivedOn) return Promise.reject('Record archived!');
245
+ return this.create({...instance, replaced_id: instance.id}, client).then(id => {
246
+ return this.archive(instance.id, id, client).then(() => id);
247
+ });
248
+ }
249
+
250
250
  delete(id: R, client: ClientBase | Transaction): Promise<any> {
251
251
  if(this.pool) {
252
252
  return (<ClientBase>client).query('DELETE FROM ' + this.table + ' WHERE id=$1', [id]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "anote-server-libs",
3
- "version": "0.2.3",
3
+ "version": "0.2.7",
4
4
  "description": "Helpers for express-TS servers",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -24,10 +24,10 @@
24
24
  "pg": "8.7.3"
25
25
  },
26
26
  "peerDependencies": {
27
- "express": "4.17.2",
28
- "jsonschema": "1.4.0",
29
- "node-forge": "1.2.1",
30
- "winston": "3.5.1"
27
+ "express": "^4.17.3",
28
+ "jsonschema": "^1.4.0",
29
+ "node-forge": "^1.2.1",
30
+ "winston": "3.6.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@types/express": "4.17.13",