remult 0.15.2 → 0.15.3
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/remult-knex/index.js +4 -0
- package/esm/src/backend-tests/my-test.backend-spec.js +10 -0
- package/esm/src/context.d.ts +2 -2
- package/esm/src/context.js +12 -3
- package/esm/src/data-providers/sql-database.js +3 -0
- package/package.json +1 -1
- package/remult-knex/index.js +4 -0
- package/src/backend-tests/my-test.backend-spec.js +42 -0
- package/src/context.d.ts +2 -2
- package/src/context.js +12 -3
- package/src/data-providers/sql-database.js +3 -0
package/esm/remult-knex/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import { allEntities, Remult } from "../src/context";
|
|
|
5
5
|
import { isAutoIncrement } from "../src/remult3";
|
|
6
6
|
import { ValueConverters } from "../src/valueConverters";
|
|
7
7
|
import { CompoundIdField } from '../src/column';
|
|
8
|
+
import { Sort } from '../src/sort';
|
|
8
9
|
export class KnexDataProvider {
|
|
9
10
|
constructor(knex) {
|
|
10
11
|
this.knex = knex;
|
|
@@ -70,6 +71,9 @@ class KnexEntityDataProvider {
|
|
|
70
71
|
let r = await br.resolveWhere();
|
|
71
72
|
query.where(b => r.forEach(y => y(b)));
|
|
72
73
|
}
|
|
74
|
+
if (!options.orderBy) {
|
|
75
|
+
options.orderBy = Sort.createUniqueSort(this.entity, new Sort());
|
|
76
|
+
}
|
|
73
77
|
if (options.orderBy) {
|
|
74
78
|
query = query.orderBy(options.orderBy.Segments.map(s => ({
|
|
75
79
|
column: e.nameOf(s.field),
|
|
@@ -4,6 +4,16 @@ import { testKnexPGSqlImpl, testPostgresImplementation } from "./backend-databas
|
|
|
4
4
|
import { entityWithValidations } from "../shared-tests/entityWithValidations";
|
|
5
5
|
import { SqlDatabase } from "../data-providers/sql-database";
|
|
6
6
|
config();
|
|
7
|
+
testPostgresImplementation("default order by", async ({ createEntity }) => {
|
|
8
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
9
|
+
await s.update(1, { name: "updated name" });
|
|
10
|
+
expect((await s.find()).map(x => x.myId)).toEqual([1, 2, 3, 4]);
|
|
11
|
+
}, false);
|
|
12
|
+
testKnexPGSqlImpl("default order by", async ({ createEntity }) => {
|
|
13
|
+
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
14
|
+
await s.update(1, { name: "updated name" });
|
|
15
|
+
expect((await s.find()).map(x => x.myId)).toEqual([1, 2, 3, 4]);
|
|
16
|
+
}, false);
|
|
7
17
|
testPostgresImplementation("sql filter", async ({ createEntity }) => {
|
|
8
18
|
let s = await entityWithValidations.create4RowsInDp(createEntity);
|
|
9
19
|
expect((await s.find({
|
package/esm/src/context.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare class Remult {
|
|
|
40
40
|
/** Returns the current user's info */
|
|
41
41
|
get user(): UserInfo;
|
|
42
42
|
/** Set's the current user info */
|
|
43
|
-
setUser(info: UserInfo): Promise<void>;
|
|
43
|
+
setUser(info: UserInfo | undefined): Promise<void>;
|
|
44
44
|
private _user;
|
|
45
45
|
private _userChangeEvent;
|
|
46
46
|
/** Checks if a user was authenticated */
|
|
@@ -66,7 +66,7 @@ export declare class Remult {
|
|
|
66
66
|
*
|
|
67
67
|
* If no provider is specified, `fetch` will be used as an http provider
|
|
68
68
|
*/
|
|
69
|
-
constructor(provider?: HttpProvider | DataProvider);
|
|
69
|
+
constructor(provider?: HttpProvider | DataProvider | typeof fetch);
|
|
70
70
|
/** The api Base Url to be used in all remult calls. by default it's set to `/api`.
|
|
71
71
|
*
|
|
72
72
|
* Set this property in case you want to determine a non relative api url
|
package/esm/src/context.js
CHANGED
|
@@ -103,10 +103,17 @@ export class Remult {
|
|
|
103
103
|
this._dataSource = provider;
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
|
-
let http = provider;
|
|
107
106
|
let dataProvider;
|
|
108
|
-
if (
|
|
109
|
-
|
|
107
|
+
if (!dataProvider) {
|
|
108
|
+
let http = provider;
|
|
109
|
+
if (http && http.get && http.put && http.post && http.delete) {
|
|
110
|
+
dataProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(http);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!dataProvider) {
|
|
114
|
+
if (typeof provider === "function") {
|
|
115
|
+
dataProvider = new RestDataProviderHttpProviderUsingFetch(provider);
|
|
116
|
+
}
|
|
110
117
|
}
|
|
111
118
|
if (!dataProvider) {
|
|
112
119
|
dataProvider = new RestDataProviderHttpProviderUsingFetch();
|
|
@@ -147,6 +154,8 @@ export class Remult {
|
|
|
147
154
|
/** Set's the current user info */
|
|
148
155
|
async setUser(info) {
|
|
149
156
|
this._user = info;
|
|
157
|
+
if (this._user === null)
|
|
158
|
+
this._user = undefined;
|
|
150
159
|
let auth = info;
|
|
151
160
|
if (auth) {
|
|
152
161
|
if (!this._user.id && auth.sub)
|
|
@@ -127,6 +127,9 @@ class ActualSQLServerDataProvider {
|
|
|
127
127
|
if (options.limit) {
|
|
128
128
|
options.orderBy = Sort.createUniqueSort(this.entity, options.orderBy);
|
|
129
129
|
}
|
|
130
|
+
if (!options.orderBy) {
|
|
131
|
+
options.orderBy = Sort.createUniqueSort(this.entity, new Sort());
|
|
132
|
+
}
|
|
130
133
|
if (options.orderBy) {
|
|
131
134
|
let first = true;
|
|
132
135
|
let segs = [];
|
package/package.json
CHANGED
package/remult-knex/index.js
CHANGED
|
@@ -9,6 +9,7 @@ var context_1 = require("../src/context");
|
|
|
9
9
|
var remult3_1 = require("../src/remult3");
|
|
10
10
|
var valueConverters_1 = require("../src/valueConverters");
|
|
11
11
|
var column_1 = require("../src/column");
|
|
12
|
+
var sort_1 = require("../src/sort");
|
|
12
13
|
var KnexDataProvider = /** @class */ (function () {
|
|
13
14
|
function KnexDataProvider(knex) {
|
|
14
15
|
this.knex = knex;
|
|
@@ -129,6 +130,9 @@ var KnexEntityDataProvider = /** @class */ (function () {
|
|
|
129
130
|
query.where(function (b) { return r_1.forEach(function (y) { return y(b); }); });
|
|
130
131
|
_d.label = 3;
|
|
131
132
|
case 3:
|
|
133
|
+
if (!options.orderBy) {
|
|
134
|
+
options.orderBy = sort_1.Sort.createUniqueSort(this.entity, new sort_1.Sort());
|
|
135
|
+
}
|
|
132
136
|
if (options.orderBy) {
|
|
133
137
|
query = query.orderBy(options.orderBy.Segments.map(function (s) { return ({
|
|
134
138
|
column: e.nameOf(s.field),
|
|
@@ -7,6 +7,48 @@ var backend_database_test_setup_backend_spec_1 = require("./backend-database-tes
|
|
|
7
7
|
var entityWithValidations_1 = require("../shared-tests/entityWithValidations");
|
|
8
8
|
var sql_database_1 = require("../data-providers/sql-database");
|
|
9
9
|
dotenv_1.config();
|
|
10
|
+
backend_database_test_setup_backend_spec_1.testPostgresImplementation("default order by", function (_a) {
|
|
11
|
+
var createEntity = _a.createEntity;
|
|
12
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
13
|
+
var s, _b;
|
|
14
|
+
return tslib_1.__generator(this, function (_c) {
|
|
15
|
+
switch (_c.label) {
|
|
16
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
17
|
+
case 1:
|
|
18
|
+
s = _c.sent();
|
|
19
|
+
return [4 /*yield*/, s.update(1, { name: "updated name" })];
|
|
20
|
+
case 2:
|
|
21
|
+
_c.sent();
|
|
22
|
+
_b = expect;
|
|
23
|
+
return [4 /*yield*/, s.find()];
|
|
24
|
+
case 3:
|
|
25
|
+
_b.apply(void 0, [(_c.sent()).map(function (x) { return x.myId; })]).toEqual([1, 2, 3, 4]);
|
|
26
|
+
return [2 /*return*/];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}, false);
|
|
31
|
+
backend_database_test_setup_backend_spec_1.testKnexPGSqlImpl("default order by", function (_a) {
|
|
32
|
+
var createEntity = _a.createEntity;
|
|
33
|
+
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
34
|
+
var s, _b;
|
|
35
|
+
return tslib_1.__generator(this, function (_c) {
|
|
36
|
+
switch (_c.label) {
|
|
37
|
+
case 0: return [4 /*yield*/, entityWithValidations_1.entityWithValidations.create4RowsInDp(createEntity)];
|
|
38
|
+
case 1:
|
|
39
|
+
s = _c.sent();
|
|
40
|
+
return [4 /*yield*/, s.update(1, { name: "updated name" })];
|
|
41
|
+
case 2:
|
|
42
|
+
_c.sent();
|
|
43
|
+
_b = expect;
|
|
44
|
+
return [4 /*yield*/, s.find()];
|
|
45
|
+
case 3:
|
|
46
|
+
_b.apply(void 0, [(_c.sent()).map(function (x) { return x.myId; })]).toEqual([1, 2, 3, 4]);
|
|
47
|
+
return [2 /*return*/];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}, false);
|
|
10
52
|
backend_database_test_setup_backend_spec_1.testPostgresImplementation("sql filter", function (_a) {
|
|
11
53
|
var createEntity = _a.createEntity;
|
|
12
54
|
return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
package/src/context.d.ts
CHANGED
|
@@ -40,7 +40,7 @@ export declare class Remult {
|
|
|
40
40
|
/** Returns the current user's info */
|
|
41
41
|
get user(): UserInfo;
|
|
42
42
|
/** Set's the current user info */
|
|
43
|
-
setUser(info: UserInfo): Promise<void>;
|
|
43
|
+
setUser(info: UserInfo | undefined): Promise<void>;
|
|
44
44
|
private _user;
|
|
45
45
|
private _userChangeEvent;
|
|
46
46
|
/** Checks if a user was authenticated */
|
|
@@ -66,7 +66,7 @@ export declare class Remult {
|
|
|
66
66
|
*
|
|
67
67
|
* If no provider is specified, `fetch` will be used as an http provider
|
|
68
68
|
*/
|
|
69
|
-
constructor(provider?: HttpProvider | DataProvider);
|
|
69
|
+
constructor(provider?: HttpProvider | DataProvider | typeof fetch);
|
|
70
70
|
/** The api Base Url to be used in all remult calls. by default it's set to `/api`.
|
|
71
71
|
*
|
|
72
72
|
* Set this property in case you want to determine a non relative api url
|
package/src/context.js
CHANGED
|
@@ -154,10 +154,17 @@ var Remult = /** @class */ (function () {
|
|
|
154
154
|
this._dataSource = provider;
|
|
155
155
|
return;
|
|
156
156
|
}
|
|
157
|
-
var http = provider;
|
|
158
157
|
var dataProvider;
|
|
159
|
-
if (
|
|
160
|
-
|
|
158
|
+
if (!dataProvider) {
|
|
159
|
+
var http = provider;
|
|
160
|
+
if (http && http.get && http.put && http.post && http.delete) {
|
|
161
|
+
dataProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(http);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (!dataProvider) {
|
|
165
|
+
if (typeof provider === "function") {
|
|
166
|
+
dataProvider = new rest_data_provider_1.RestDataProviderHttpProviderUsingFetch(provider);
|
|
167
|
+
}
|
|
161
168
|
}
|
|
162
169
|
if (!dataProvider) {
|
|
163
170
|
dataProvider = new rest_data_provider_1.RestDataProviderHttpProviderUsingFetch();
|
|
@@ -207,6 +214,8 @@ var Remult = /** @class */ (function () {
|
|
|
207
214
|
switch (_a.label) {
|
|
208
215
|
case 0:
|
|
209
216
|
this._user = info;
|
|
217
|
+
if (this._user === null)
|
|
218
|
+
this._user = undefined;
|
|
210
219
|
auth = info;
|
|
211
220
|
if (auth) {
|
|
212
221
|
if (!this._user.id && auth.sub)
|
|
@@ -211,6 +211,9 @@ var ActualSQLServerDataProvider = /** @class */ (function () {
|
|
|
211
211
|
if (options.limit) {
|
|
212
212
|
options.orderBy = sort_1.Sort.createUniqueSort(this.entity, options.orderBy);
|
|
213
213
|
}
|
|
214
|
+
if (!options.orderBy) {
|
|
215
|
+
options.orderBy = sort_1.Sort.createUniqueSort(this.entity, new sort_1.Sort());
|
|
216
|
+
}
|
|
214
217
|
if (options.orderBy) {
|
|
215
218
|
first = true;
|
|
216
219
|
segs = [];
|