remult 3.3.7 → 3.3.9
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/esm/postgres/schema-builder.js +3 -5
- package/esm/src/data-providers/json-entity-indexed-db-data-provider.js +56 -55
- package/package.json +1 -1
- package/postgres/schema-builder.js +3 -5
- package/src/data-providers/json-entity-indexed-db-data-provider.js +73 -99
- package/src/remult3/RepositoryImplementation.d.ts +2 -2
|
@@ -2,6 +2,8 @@ import { dbNamesOf, shouldCreateEntity, shouldNotCreateField, } from '../src/fil
|
|
|
2
2
|
import { isAutoIncrement } from '../src/remult3/RepositoryImplementation.js';
|
|
3
3
|
import { ValueConverters } from '../src/valueConverters.js';
|
|
4
4
|
export function postgresColumnSyntax(x, dbName) {
|
|
5
|
+
if (isAutoIncrement(x))
|
|
6
|
+
return dbName + ' serial';
|
|
5
7
|
let result = dbName;
|
|
6
8
|
if (x.valueType == Number) {
|
|
7
9
|
if (!x.valueConverter.fieldTypeInDb)
|
|
@@ -129,11 +131,7 @@ export class PostgresSchemaBuilder {
|
|
|
129
131
|
if (result.length != 0)
|
|
130
132
|
result += ',';
|
|
131
133
|
result += '\r\n ';
|
|
132
|
-
|
|
133
|
-
result += e.$dbNameOf(x) + ' serial';
|
|
134
|
-
else {
|
|
135
|
-
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
136
|
-
}
|
|
134
|
+
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
137
135
|
}
|
|
138
136
|
}
|
|
139
137
|
result += `,\r\n primary key (${entity.idMetadata.fields
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const connectionLostNames = new Set([
|
|
2
|
+
'InvalidStateError',
|
|
3
|
+
'UnknownError',
|
|
4
|
+
'AbortError',
|
|
5
|
+
]);
|
|
1
6
|
export class JsonEntityIndexedDbStorage {
|
|
2
7
|
dbName;
|
|
3
8
|
storeName;
|
|
@@ -8,66 +13,62 @@ export class JsonEntityIndexedDbStorage {
|
|
|
8
13
|
supportsRawJson = true;
|
|
9
14
|
//@internal
|
|
10
15
|
db;
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
resolve(null);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
});
|
|
16
|
+
getItem(entityDbName) {
|
|
17
|
+
return this.run('readonly', (s) => s.get(entityDbName));
|
|
18
|
+
}
|
|
19
|
+
setItem(entityDbName, json) {
|
|
20
|
+
return this.run('readwrite', (s) => s.put(json, entityDbName));
|
|
21
|
+
}
|
|
22
|
+
removeItem(entityDbName) {
|
|
23
|
+
return this.run('readwrite', (s) => s.delete(entityDbName));
|
|
24
|
+
}
|
|
25
|
+
clear() {
|
|
26
|
+
return this.run('readwrite', (s) => s.clear());
|
|
26
27
|
}
|
|
27
28
|
//@internal
|
|
28
|
-
async
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
request
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
request.onupgradeneeded = (event) => {
|
|
39
|
-
db = request.result;
|
|
40
|
-
db.createObjectStore(this.storeName);
|
|
41
|
-
};
|
|
29
|
+
async run(mode, op) {
|
|
30
|
+
const attempt = async () => {
|
|
31
|
+
const db = await this.init();
|
|
32
|
+
return new Promise((resolve, reject) => {
|
|
33
|
+
const tx = db.transaction([this.storeName], mode);
|
|
34
|
+
tx.onabort = () => reject(tx.error);
|
|
35
|
+
const request = op(tx.objectStore(this.storeName));
|
|
36
|
+
request.onerror = () => reject(request.error);
|
|
37
|
+
request.onsuccess = () => resolve(request.result ?? null);
|
|
42
38
|
});
|
|
39
|
+
};
|
|
40
|
+
try {
|
|
41
|
+
return await attempt();
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
if (!connectionLostNames.has(err?.name))
|
|
45
|
+
throw err;
|
|
46
|
+
this.db = undefined;
|
|
47
|
+
return await attempt();
|
|
43
48
|
}
|
|
44
|
-
return this.db;
|
|
45
|
-
}
|
|
46
|
-
async setItem(entityDbName, json) {
|
|
47
|
-
return new Promise(async (resolve, reject) => {
|
|
48
|
-
const transaction = (await this.init()).transaction([this.storeName], 'readwrite');
|
|
49
|
-
const store = transaction.objectStore(this.storeName);
|
|
50
|
-
const request = store.put(json, entityDbName);
|
|
51
|
-
request.onerror = (event) => reject(request.error);
|
|
52
|
-
request.onsuccess = (event) => resolve();
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
async removeItem(entityDbName) {
|
|
56
|
-
return new Promise(async (resolve, reject) => {
|
|
57
|
-
const transaction = (await this.init()).transaction([this.storeName], 'readwrite');
|
|
58
|
-
const store = transaction.objectStore(this.storeName);
|
|
59
|
-
const request = store.delete(entityDbName);
|
|
60
|
-
request.onerror = (_event) => reject(request.error);
|
|
61
|
-
request.onsuccess = (_event) => resolve();
|
|
62
|
-
});
|
|
63
49
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
request
|
|
70
|
-
request.
|
|
50
|
+
//@internal
|
|
51
|
+
async init() {
|
|
52
|
+
if (this.db)
|
|
53
|
+
return this.db;
|
|
54
|
+
this.db = await new Promise((resolve, reject) => {
|
|
55
|
+
const request = indexedDB.open(this.dbName, 1);
|
|
56
|
+
request.onerror = () => reject(request.error);
|
|
57
|
+
request.onupgradeneeded = () => request.result.createObjectStore(this.storeName);
|
|
58
|
+
request.onsuccess = () => {
|
|
59
|
+
const db = request.result;
|
|
60
|
+
const forget = () => {
|
|
61
|
+
if (this.db === db)
|
|
62
|
+
this.db = undefined;
|
|
63
|
+
};
|
|
64
|
+
db.onclose = forget;
|
|
65
|
+
db.onversionchange = () => {
|
|
66
|
+
db.close();
|
|
67
|
+
forget();
|
|
68
|
+
};
|
|
69
|
+
resolve(db);
|
|
70
|
+
};
|
|
71
71
|
});
|
|
72
|
+
return this.db;
|
|
72
73
|
}
|
|
73
74
|
}
|
package/package.json
CHANGED
|
@@ -7,6 +7,8 @@ var filter_consumer_bridge_to_sql_request_js_1 = require("../src/filter/filter-c
|
|
|
7
7
|
var RepositoryImplementation_js_1 = require("../src/remult3/RepositoryImplementation.js");
|
|
8
8
|
var valueConverters_js_1 = require("../src/valueConverters.js");
|
|
9
9
|
function postgresColumnSyntax(x, dbName) {
|
|
10
|
+
if ((0, RepositoryImplementation_js_1.isAutoIncrement)(x))
|
|
11
|
+
return dbName + ' serial';
|
|
10
12
|
var result = dbName;
|
|
11
13
|
if (x.valueType == Number) {
|
|
12
14
|
if (!x.valueConverter.fieldTypeInDb)
|
|
@@ -218,11 +220,7 @@ var PostgresSchemaBuilder = /** @class */ (function () {
|
|
|
218
220
|
if (result.length != 0)
|
|
219
221
|
result += ',';
|
|
220
222
|
result += '\r\n ';
|
|
221
|
-
|
|
222
|
-
result += e.$dbNameOf(x) + ' serial';
|
|
223
|
-
else {
|
|
224
|
-
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
225
|
-
}
|
|
223
|
+
result += postgresColumnSyntax(x, e.$dbNameOf(x));
|
|
226
224
|
}
|
|
227
225
|
}
|
|
228
226
|
}
|
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JsonEntityIndexedDbStorage = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
+
var connectionLostNames = new Set([
|
|
6
|
+
'InvalidStateError',
|
|
7
|
+
'UnknownError',
|
|
8
|
+
'AbortError',
|
|
9
|
+
]);
|
|
5
10
|
var JsonEntityIndexedDbStorage = /** @class */ (function () {
|
|
6
11
|
function JsonEntityIndexedDbStorage(dbName, storeName) {
|
|
7
12
|
if (dbName === void 0) { dbName = 'db'; }
|
|
@@ -11,31 +16,59 @@ var JsonEntityIndexedDbStorage = /** @class */ (function () {
|
|
|
11
16
|
this.supportsRawJson = true;
|
|
12
17
|
}
|
|
13
18
|
JsonEntityIndexedDbStorage.prototype.getItem = function (entityDbName) {
|
|
19
|
+
return this.run('readonly', function (s) { return s.get(entityDbName); });
|
|
20
|
+
};
|
|
21
|
+
JsonEntityIndexedDbStorage.prototype.setItem = function (entityDbName, json) {
|
|
22
|
+
return this.run('readwrite', function (s) {
|
|
23
|
+
return s.put(json, entityDbName);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
JsonEntityIndexedDbStorage.prototype.removeItem = function (entityDbName) {
|
|
27
|
+
return this.run('readwrite', function (s) { return s.delete(entityDbName); });
|
|
28
|
+
};
|
|
29
|
+
JsonEntityIndexedDbStorage.prototype.clear = function () {
|
|
30
|
+
return this.run('readwrite', function (s) { return s.clear(); });
|
|
31
|
+
};
|
|
32
|
+
//@internal
|
|
33
|
+
JsonEntityIndexedDbStorage.prototype.run = function (mode, op) {
|
|
14
34
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
35
|
+
var attempt, err_1;
|
|
15
36
|
var _this = this;
|
|
16
37
|
return tslib_1.__generator(this, function (_a) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return tslib_1.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
switch (_a.label) {
|
|
39
|
+
case 0:
|
|
40
|
+
attempt = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
41
|
+
var db;
|
|
42
|
+
var _this = this;
|
|
43
|
+
return tslib_1.__generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0: return [4 /*yield*/, this.init()];
|
|
46
|
+
case 1:
|
|
47
|
+
db = _a.sent();
|
|
48
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
49
|
+
var tx = db.transaction([_this.storeName], mode);
|
|
50
|
+
tx.onabort = function () { return reject(tx.error); };
|
|
51
|
+
var request = op(tx.objectStore(_this.storeName));
|
|
52
|
+
request.onerror = function () { return reject(request.error); };
|
|
53
|
+
request.onsuccess = function () { var _a; return resolve((_a = request.result) !== null && _a !== void 0 ? _a : null); };
|
|
54
|
+
})];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}); };
|
|
58
|
+
_a.label = 1;
|
|
59
|
+
case 1:
|
|
60
|
+
_a.trys.push([1, 3, , 5]);
|
|
61
|
+
return [4 /*yield*/, attempt()];
|
|
62
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
63
|
+
case 3:
|
|
64
|
+
err_1 = _a.sent();
|
|
65
|
+
if (!connectionLostNames.has(err_1 === null || err_1 === void 0 ? void 0 : err_1.name))
|
|
66
|
+
throw err_1;
|
|
67
|
+
this.db = undefined;
|
|
68
|
+
return [4 /*yield*/, attempt()];
|
|
69
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
70
|
+
case 5: return [2 /*return*/];
|
|
71
|
+
}
|
|
39
72
|
});
|
|
40
73
|
});
|
|
41
74
|
};
|
|
@@ -47,95 +80,36 @@ var JsonEntityIndexedDbStorage = /** @class */ (function () {
|
|
|
47
80
|
return tslib_1.__generator(this, function (_b) {
|
|
48
81
|
switch (_b.label) {
|
|
49
82
|
case 0:
|
|
50
|
-
if (
|
|
83
|
+
if (this.db)
|
|
84
|
+
return [2 /*return*/, this.db];
|
|
51
85
|
_a = this;
|
|
52
86
|
return [4 /*yield*/, new Promise(function (resolve, reject) {
|
|
53
|
-
var db;
|
|
54
87
|
var request = indexedDB.open(_this.dbName, 1);
|
|
55
|
-
request.onerror = function (
|
|
56
|
-
request.
|
|
57
|
-
|
|
58
|
-
resolve(db);
|
|
88
|
+
request.onerror = function () { return reject(request.error); };
|
|
89
|
+
request.onupgradeneeded = function () {
|
|
90
|
+
return request.result.createObjectStore(_this.storeName);
|
|
59
91
|
};
|
|
60
|
-
request.
|
|
61
|
-
db = request.result;
|
|
62
|
-
|
|
92
|
+
request.onsuccess = function () {
|
|
93
|
+
var db = request.result;
|
|
94
|
+
var forget = function () {
|
|
95
|
+
if (_this.db === db)
|
|
96
|
+
_this.db = undefined;
|
|
97
|
+
};
|
|
98
|
+
db.onclose = forget;
|
|
99
|
+
db.onversionchange = function () {
|
|
100
|
+
db.close();
|
|
101
|
+
forget();
|
|
102
|
+
};
|
|
103
|
+
resolve(db);
|
|
63
104
|
};
|
|
64
105
|
})];
|
|
65
106
|
case 1:
|
|
66
107
|
_a.db = _b.sent();
|
|
67
|
-
|
|
68
|
-
case 2: return [2 /*return*/, this.db];
|
|
108
|
+
return [2 /*return*/, this.db];
|
|
69
109
|
}
|
|
70
110
|
});
|
|
71
111
|
});
|
|
72
112
|
};
|
|
73
|
-
JsonEntityIndexedDbStorage.prototype.setItem = function (entityDbName, json) {
|
|
74
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
75
|
-
var _this = this;
|
|
76
|
-
return tslib_1.__generator(this, function (_a) {
|
|
77
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
78
|
-
var transaction, store, request;
|
|
79
|
-
return tslib_1.__generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, this.init()];
|
|
82
|
-
case 1:
|
|
83
|
-
transaction = (_a.sent()).transaction([this.storeName], 'readwrite');
|
|
84
|
-
store = transaction.objectStore(this.storeName);
|
|
85
|
-
request = store.put(json, entityDbName);
|
|
86
|
-
request.onerror = function (event) { return reject(request.error); };
|
|
87
|
-
request.onsuccess = function (event) { return resolve(); };
|
|
88
|
-
return [2 /*return*/];
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
}); })];
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
};
|
|
95
|
-
JsonEntityIndexedDbStorage.prototype.removeItem = function (entityDbName) {
|
|
96
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
97
|
-
var _this = this;
|
|
98
|
-
return tslib_1.__generator(this, function (_a) {
|
|
99
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
100
|
-
var transaction, store, request;
|
|
101
|
-
return tslib_1.__generator(this, function (_a) {
|
|
102
|
-
switch (_a.label) {
|
|
103
|
-
case 0: return [4 /*yield*/, this.init()];
|
|
104
|
-
case 1:
|
|
105
|
-
transaction = (_a.sent()).transaction([this.storeName], 'readwrite');
|
|
106
|
-
store = transaction.objectStore(this.storeName);
|
|
107
|
-
request = store.delete(entityDbName);
|
|
108
|
-
request.onerror = function (_event) { return reject(request.error); };
|
|
109
|
-
request.onsuccess = function (_event) { return resolve(); };
|
|
110
|
-
return [2 /*return*/];
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
}); })];
|
|
114
|
-
});
|
|
115
|
-
});
|
|
116
|
-
};
|
|
117
|
-
JsonEntityIndexedDbStorage.prototype.clear = function () {
|
|
118
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
119
|
-
var _this = this;
|
|
120
|
-
return tslib_1.__generator(this, function (_a) {
|
|
121
|
-
return [2 /*return*/, new Promise(function (resolve, reject) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
122
|
-
var transaction, store, request;
|
|
123
|
-
return tslib_1.__generator(this, function (_a) {
|
|
124
|
-
switch (_a.label) {
|
|
125
|
-
case 0: return [4 /*yield*/, this.init()];
|
|
126
|
-
case 1:
|
|
127
|
-
transaction = (_a.sent()).transaction([this.storeName], 'readwrite');
|
|
128
|
-
store = transaction.objectStore(this.storeName);
|
|
129
|
-
request = store.clear();
|
|
130
|
-
request.onerror = function (_event) { return reject(request.error); };
|
|
131
|
-
request.onsuccess = function (_event) { return resolve(); };
|
|
132
|
-
return [2 /*return*/];
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}); })];
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
113
|
return JsonEntityIndexedDbStorage;
|
|
140
114
|
}());
|
|
141
115
|
exports.JsonEntityIndexedDbStorage = JsonEntityIndexedDbStorage;
|
|
@@ -313,8 +313,8 @@ export declare class ValueListInfo<T extends ValueListItem> implements ValueConv
|
|
|
313
313
|
toJson(val: T): any;
|
|
314
314
|
fromDb(val: any): T;
|
|
315
315
|
toDb(val: T): any;
|
|
316
|
-
toInput(val: T, inputType
|
|
317
|
-
fromInput(val: string, inputType
|
|
316
|
+
toInput(val: T, inputType?: string): string;
|
|
317
|
+
fromInput(val: string, inputType?: string): T;
|
|
318
318
|
displayValue?(val: T): string;
|
|
319
319
|
fieldTypeInDb?: string;
|
|
320
320
|
inputType?: string;
|