remult 0.22.10 → 0.22.11-exp2.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.
@@ -2,8 +2,8 @@ import type { JsonEntityStorage } from '../index';
2
2
  import { JsonDataProvider } from '../index';
3
3
  export declare class JsonEntityFileStorage implements JsonEntityStorage {
4
4
  private folderPath;
5
- getItem(entityDbName: string): string;
6
- setItem(entityDbName: string, json: string): void;
5
+ getItem(entityDbName: string): Promise<string>;
6
+ setItem(entityDbName: string, json: string): Promise<void>;
7
7
  constructor(folderPath: string);
8
8
  }
9
9
  export declare class JsonFileDataProvider extends JsonDataProvider {
@@ -1,16 +1,18 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
1
  import { JsonDataProvider } from '../index';
4
2
  export class JsonEntityFileStorage {
5
3
  folderPath;
6
- getItem(entityDbName) {
4
+ async getItem(entityDbName) {
5
+ const path = await import('path');
6
+ const fs = await import('fs');
7
7
  let fn = path.join(this.folderPath, entityDbName) + '.json';
8
8
  if (fs.existsSync(fn)) {
9
9
  return fs.readFileSync(fn).toString();
10
10
  }
11
11
  return undefined;
12
12
  }
13
- setItem(entityDbName, json) {
13
+ async setItem(entityDbName, json) {
14
+ const path = await import('path');
15
+ const fs = await import('fs');
14
16
  if (!fs.existsSync(this.folderPath)) {
15
17
  fs.mkdirSync(this.folderPath);
16
18
  }
@@ -1,8 +1,8 @@
1
1
  import type { DataProvider, EntityDataProvider } from '../data-interfaces';
2
2
  import type { EntityMetadata } from '../remult3/remult3';
3
3
  export interface JsonEntityStorage {
4
- getItem(entityDbName: string): string | null;
5
- setItem(entityDbName: string, json: string): any;
4
+ getItem(entityDbName: string): Promise<string | null>;
5
+ setItem(entityDbName: string, json: string): Promise<void>;
6
6
  }
7
7
  export declare class JsonDataProvider implements DataProvider {
8
8
  private storage;
@@ -21,11 +21,11 @@ class JsonEntityDataProvider {
21
21
  async loadEntityData(what) {
22
22
  let data = [];
23
23
  let dbName = await this.entity.getDbName();
24
- let s = this.helper.getItem(dbName);
24
+ let s = await this.helper.getItem(dbName);
25
25
  if (s)
26
26
  data = JSON.parse(s);
27
27
  let dp = new ArrayEntityDataProvider(this.entity, data);
28
- return what(dp, () => this.helper.setItem(dbName, JSON.stringify(data, undefined, 2)));
28
+ return what(dp, async () => await this.helper.setItem(dbName, JSON.stringify(data, undefined, 2)));
29
29
  }
30
30
  p = Promise.resolve();
31
31
  find(options) {
@@ -35,20 +35,20 @@ class JsonEntityDataProvider {
35
35
  return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.count(where))));
36
36
  }
37
37
  update(id, data) {
38
- return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.update(id, data).then((x) => {
39
- save();
38
+ return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.update(id, data).then(async (x) => {
39
+ await save();
40
40
  return x;
41
41
  }))));
42
42
  }
43
43
  delete(id) {
44
- return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.delete(id).then((x) => {
45
- save();
44
+ return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.delete(id).then(async (x) => {
45
+ await save();
46
46
  return x;
47
47
  }))));
48
48
  }
49
49
  async insert(data) {
50
- return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.insert(data).then((x) => {
51
- save();
50
+ return (this.p = this.p.then(() => this.loadEntityData((dp, save) => dp.insert(data).then(async (x) => {
51
+ await save();
52
52
  return x;
53
53
  }))));
54
54
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.22.10",
3
+ "version": "0.22.11-exp2.0",
4
4
  "description": "A CRUD framework for full-stack TypeScript",
5
5
  "types": "index.d.ts",
6
6
  "module": "esm/index.js",
@@ -2,8 +2,8 @@ import type { JsonEntityStorage } from '../index';
2
2
  import { JsonDataProvider } from '../index';
3
3
  export declare class JsonEntityFileStorage implements JsonEntityStorage {
4
4
  private folderPath;
5
- getItem(entityDbName: string): string;
6
- setItem(entityDbName: string, json: string): void;
5
+ getItem(entityDbName: string): Promise<string>;
6
+ setItem(entityDbName: string, json: string): Promise<void>;
7
7
  constructor(folderPath: string);
8
8
  }
9
9
  export declare class JsonFileDataProvider extends JsonDataProvider {
@@ -2,25 +2,49 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.JsonFileDataProvider = exports.JsonEntityFileStorage = void 0;
4
4
  var tslib_1 = require("tslib");
5
- var fs = tslib_1.__importStar(require("fs"));
6
- var path = tslib_1.__importStar(require("path"));
7
5
  var index_1 = require("../index");
8
6
  var JsonEntityFileStorage = /** @class */ (function () {
9
7
  function JsonEntityFileStorage(folderPath) {
10
8
  this.folderPath = folderPath;
11
9
  }
12
10
  JsonEntityFileStorage.prototype.getItem = function (entityDbName) {
13
- var fn = path.join(this.folderPath, entityDbName) + '.json';
14
- if (fs.existsSync(fn)) {
15
- return fs.readFileSync(fn).toString();
16
- }
17
- return undefined;
11
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
12
+ var path, fs, fn;
13
+ return tslib_1.__generator(this, function (_a) {
14
+ switch (_a.label) {
15
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('path')); })];
16
+ case 1:
17
+ path = _a.sent();
18
+ return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('fs')); })];
19
+ case 2:
20
+ fs = _a.sent();
21
+ fn = path.join(this.folderPath, entityDbName) + '.json';
22
+ if (fs.existsSync(fn)) {
23
+ return [2 /*return*/, fs.readFileSync(fn).toString()];
24
+ }
25
+ return [2 /*return*/, undefined];
26
+ }
27
+ });
28
+ });
18
29
  };
19
30
  JsonEntityFileStorage.prototype.setItem = function (entityDbName, json) {
20
- if (!fs.existsSync(this.folderPath)) {
21
- fs.mkdirSync(this.folderPath);
22
- }
23
- return fs.writeFileSync(path.join(this.folderPath, entityDbName) + '.json', json);
31
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
32
+ var path, fs;
33
+ return tslib_1.__generator(this, function (_a) {
34
+ switch (_a.label) {
35
+ case 0: return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('path')); })];
36
+ case 1:
37
+ path = _a.sent();
38
+ return [4 /*yield*/, Promise.resolve().then(function () { return tslib_1.__importStar(require('fs')); })];
39
+ case 2:
40
+ fs = _a.sent();
41
+ if (!fs.existsSync(this.folderPath)) {
42
+ fs.mkdirSync(this.folderPath);
43
+ }
44
+ return [2 /*return*/, fs.writeFileSync(path.join(this.folderPath, entityDbName) + '.json', json)];
45
+ }
46
+ });
47
+ });
24
48
  };
25
49
  return JsonEntityFileStorage;
26
50
  }());
@@ -1,8 +1,8 @@
1
1
  import type { DataProvider, EntityDataProvider } from '../data-interfaces';
2
2
  import type { EntityMetadata } from '../remult3/remult3';
3
3
  export interface JsonEntityStorage {
4
- getItem(entityDbName: string): string | null;
5
- setItem(entityDbName: string, json: string): any;
4
+ getItem(entityDbName: string): Promise<string | null>;
5
+ setItem(entityDbName: string, json: string): Promise<void>;
6
6
  }
7
7
  export declare class JsonDataProvider implements DataProvider {
8
8
  private storage;
@@ -42,13 +42,18 @@ var JsonEntityDataProvider = /** @class */ (function () {
42
42
  return [4 /*yield*/, this.entity.getDbName()];
43
43
  case 1:
44
44
  dbName = _a.sent();
45
- s = this.helper.getItem(dbName);
45
+ return [4 /*yield*/, this.helper.getItem(dbName)];
46
+ case 2:
47
+ s = _a.sent();
46
48
  if (s)
47
49
  data = JSON.parse(s);
48
50
  dp = new array_entity_data_provider_1.ArrayEntityDataProvider(this.entity, data);
49
- return [2 /*return*/, what(dp, function () {
50
- return _this.helper.setItem(dbName, JSON.stringify(data, undefined, 2));
51
- })];
51
+ return [2 /*return*/, what(dp, function () { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
52
+ switch (_a.label) {
53
+ case 0: return [4 /*yield*/, this.helper.setItem(dbName, JSON.stringify(data, undefined, 2))];
54
+ case 1: return [2 /*return*/, _a.sent()];
55
+ }
56
+ }); }); })];
52
57
  }
53
58
  });
54
59
  });
@@ -69,10 +74,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
69
74
  var _this = this;
70
75
  return (this.p = this.p.then(function () {
71
76
  return _this.loadEntityData(function (dp, save) {
72
- return dp.update(id, data).then(function (x) {
73
- save();
74
- return x;
75
- });
77
+ return dp.update(id, data).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
78
+ return tslib_1.__generator(this, function (_a) {
79
+ switch (_a.label) {
80
+ case 0: return [4 /*yield*/, save()];
81
+ case 1:
82
+ _a.sent();
83
+ return [2 /*return*/, x];
84
+ }
85
+ });
86
+ }); });
76
87
  });
77
88
  }));
78
89
  };
@@ -80,10 +91,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
80
91
  var _this = this;
81
92
  return (this.p = this.p.then(function () {
82
93
  return _this.loadEntityData(function (dp, save) {
83
- return dp.delete(id).then(function (x) {
84
- save();
85
- return x;
86
- });
94
+ return dp.delete(id).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
95
+ return tslib_1.__generator(this, function (_a) {
96
+ switch (_a.label) {
97
+ case 0: return [4 /*yield*/, save()];
98
+ case 1:
99
+ _a.sent();
100
+ return [2 /*return*/, x];
101
+ }
102
+ });
103
+ }); });
87
104
  });
88
105
  }));
89
106
  };
@@ -93,10 +110,16 @@ var JsonEntityDataProvider = /** @class */ (function () {
93
110
  return tslib_1.__generator(this, function (_a) {
94
111
  return [2 /*return*/, (this.p = this.p.then(function () {
95
112
  return _this.loadEntityData(function (dp, save) {
96
- return dp.insert(data).then(function (x) {
97
- save();
98
- return x;
99
- });
113
+ return dp.insert(data).then(function (x) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
114
+ return tslib_1.__generator(this, function (_a) {
115
+ switch (_a.label) {
116
+ case 0: return [4 /*yield*/, save()];
117
+ case 1:
118
+ _a.sent();
119
+ return [2 /*return*/, x];
120
+ }
121
+ });
122
+ }); });
100
123
  });
101
124
  }))];
102
125
  });