remult 0.15.0 → 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-express.d.ts +1 -1
- package/esm/remult-fastify.d.ts +2 -2
- package/esm/remult-fresh.d.ts +1 -1
- package/esm/remult-knex/index.js +4 -0
- package/esm/server/expressBridge.d.ts +5 -5
- package/esm/server/expressBridge.js +5 -2
- 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 +65 -65
- package/remult-express.d.ts +1 -1
- package/remult-fastify.d.ts +2 -2
- package/remult-fresh.d.ts +1 -1
- package/remult-knex/index.js +4 -0
- package/server/expressBridge.d.ts +5 -5
- package/server/expressBridge.js +5 -2
- 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/postgres/postgresColumnSyntax.d.ts +0 -2
- package/esm/postgres/postgresColumnSyntax.js +0 -30
- package/esm/remult-middleware.d.ts +0 -2
- package/esm/remult-middleware.js +0 -65
- package/esm/server/register-actions-on-server.d.ts +0 -3
- package/esm/server/register-actions-on-server.js +0 -24
- package/esm/server/register-entities-on-server.d.ts +0 -3
- package/esm/server/register-entities-on-server.js +0 -15
- package/esm/valueConverters.d.ts +0 -12
- package/esm/valueConverters.js +0 -169
- package/postgres/postgresColumnSyntax.d.ts +0 -2
- package/postgres/postgresColumnSyntax.js +0 -34
- package/remult-middleware.d.ts +0 -2
- package/remult-middleware.js +0 -70
- package/server/register-actions-on-server.d.ts +0 -3
- package/server/register-actions-on-server.js +0 -50
- package/server/register-entities-on-server.d.ts +0 -3
- package/server/register-entities-on-server.js +0 -19
- package/valueConverters.d.ts +0 -12
- package/valueConverters.js +0 -168
package/esm/remult-express.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { RemultServer, RemultServerOptions } from './server/expressBridge';
|
|
3
|
-
export declare function remultExpress(options?: RemultServerOptions & {
|
|
3
|
+
export declare function remultExpress(options?: RemultServerOptions<express.Request> & {
|
|
4
4
|
bodyParser?: boolean;
|
|
5
5
|
bodySizeLimit?: string;
|
|
6
6
|
}): express.RequestHandler & RemultServer;
|
package/esm/remult-fastify.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { FastifyPluginCallback } from 'fastify';
|
|
1
|
+
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
|
|
2
2
|
import { RemultServer, RemultServerOptions } from './server/expressBridge';
|
|
3
|
-
export declare function remultFastify(options: RemultServerOptions): FastifyPluginCallback & RemultServer;
|
|
3
|
+
export declare function remultFastify(options: RemultServerOptions<FastifyRequest>): FastifyPluginCallback & RemultServer;
|
package/esm/remult-fresh.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RemultServerOptions, GenericRequest } from "./server/expressBridge";
|
|
2
2
|
import { Remult } from "./src/context";
|
|
3
|
-
export declare function remultFresh(options: RemultServerOptions
|
|
3
|
+
export declare function remultFresh<RequestType extends GenericRequest>(options: RemultServerOptions<RequestType>, response: FreshResponse): RemultFresh;
|
|
4
4
|
export interface RemultFresh {
|
|
5
5
|
getRemult(req: GenericRequest): Promise<Remult>;
|
|
6
6
|
openApiDoc(options: {
|
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,23 +4,23 @@ import { Remult, UserInfo } from '../src/context';
|
|
|
4
4
|
import { ClassType } from '../classType';
|
|
5
5
|
import { Repository } from '../src/remult3';
|
|
6
6
|
import { IdEntity } from '../src/id-entity';
|
|
7
|
-
export
|
|
7
|
+
export interface RemultServerOptions<RequestType extends GenericRequest> {
|
|
8
8
|
/** Sets a database connection for Remult.
|
|
9
9
|
*
|
|
10
10
|
* @see [Connecting to a Database](https://remult.dev/docs/databases.html).
|
|
11
11
|
*/
|
|
12
12
|
dataProvider?: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
13
13
|
queueStorage?: QueueStorage;
|
|
14
|
-
initRequest?: (remult: Remult, origReq:
|
|
15
|
-
getUser?: (request:
|
|
14
|
+
initRequest?: (remult: Remult, origReq: RequestType) => Promise<void>;
|
|
15
|
+
getUser?: (request: RequestType) => Promise<UserInfo>;
|
|
16
16
|
initApi?: (remult: Remult) => void | Promise<void>;
|
|
17
17
|
logApiEndPoints?: boolean;
|
|
18
18
|
defaultGetLimit?: number;
|
|
19
19
|
entities?: ClassType<any>[];
|
|
20
20
|
controllers?: ClassType<any>[];
|
|
21
21
|
rootPath?: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function createRemultServer(options?: RemultServerOptions): RemultServer;
|
|
22
|
+
}
|
|
23
|
+
export declare function createRemultServer<RequestType extends GenericRequest = GenericRequest>(options?: RemultServerOptions<RequestType>): RemultServer;
|
|
24
24
|
export declare type GenericRequestHandler = (req: GenericRequest, res: GenericResponse, next: VoidFunction) => void;
|
|
25
25
|
export interface ServerHandleResponse {
|
|
26
26
|
data?: any;
|
|
@@ -4,10 +4,13 @@ import { DataApi, serializeError } from '../src/data-api';
|
|
|
4
4
|
import { allEntities, Remult } from '../src/context';
|
|
5
5
|
import { Entity, Fields, getEntityKey } from '../src/remult3';
|
|
6
6
|
import { IdEntity } from '../src/id-entity';
|
|
7
|
+
;
|
|
7
8
|
export function createRemultServer(options) {
|
|
8
9
|
if (!options) {
|
|
9
10
|
options = {};
|
|
10
11
|
}
|
|
12
|
+
if (options.logApiEndPoints === undefined)
|
|
13
|
+
options.logApiEndPoints = true;
|
|
11
14
|
actionInfo.runningOnServer = true;
|
|
12
15
|
if (options.defaultGetLimit) {
|
|
13
16
|
DataApi.defaultGetLimit = options.defaultGetLimit;
|
|
@@ -112,7 +115,7 @@ class RemultServerImplementation {
|
|
|
112
115
|
add(key, dataApiFactory, r) {
|
|
113
116
|
let myRoute = this.options.rootPath + '/' + key;
|
|
114
117
|
if (this.options.logApiEndPoints)
|
|
115
|
-
console.log(myRoute);
|
|
118
|
+
console.log("[remult] " + myRoute);
|
|
116
119
|
r.route(myRoute)
|
|
117
120
|
.get(this.process((c, req, res) => dataApiFactory(c).httpGet(res, req))).put(this.process(async (c, req, res, orig) => dataApiFactory(c).put(res, '', orig.body)))
|
|
118
121
|
.delete(this.process(async (c, req, res, orig) => dataApiFactory(c).delete(res, '')))
|
|
@@ -169,7 +172,7 @@ class RemultServerImplementation {
|
|
|
169
172
|
})();
|
|
170
173
|
this.backendMethodsOpenApi.push({ path: myUrl, allowed, tag });
|
|
171
174
|
if (this.options.logApiEndPoints)
|
|
172
|
-
console.log(myUrl);
|
|
175
|
+
console.log("[remult] " + myUrl);
|
|
173
176
|
if (queue) {
|
|
174
177
|
this.hasQueue = true;
|
|
175
178
|
this.queue.mapQueuedAction(myUrl, what);
|
|
@@ -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
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "remult",
|
|
3
|
+
"version": "0.15.3",
|
|
4
|
+
"description": "A CRUD framework for full-stack TypeScript",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
|
+
"homepage": "https://remult.dev/",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/remult/remult.git",
|
|
12
|
+
"directory": "projects/core"
|
|
13
|
+
},
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Noam Honig"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"uuid": "^8.3.2",
|
|
20
|
+
"reflect-metadata": "^0.1.13",
|
|
21
|
+
"tslib": "^2.3.1"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"require": "./index.js",
|
|
26
|
+
"import": "./esm/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./remult-express": {
|
|
29
|
+
"require": "./remult-express.js",
|
|
30
|
+
"import": "./esm/remult-express.js"
|
|
31
|
+
},
|
|
32
|
+
"./server": {
|
|
33
|
+
"require": "./server/index.js",
|
|
34
|
+
"import": "./esm/server/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./remult-fastify": {
|
|
37
|
+
"require": "./remult-fastify.js",
|
|
38
|
+
"import": "./esm/remult-fastify.js"
|
|
39
|
+
},
|
|
40
|
+
"./remult-fresh": {
|
|
41
|
+
"require": "./remult-fresh.js",
|
|
42
|
+
"import": "./esm/remult-fresh.js"
|
|
43
|
+
},
|
|
44
|
+
"./postgres": {
|
|
45
|
+
"require": "./postgres/index.js",
|
|
46
|
+
"import": "./esm/postgres/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./postgres/schema-builder": {
|
|
49
|
+
"require": "./postgres/schema-builder.js",
|
|
50
|
+
"import": "./esm/postgres/schema-builder.js"
|
|
51
|
+
},
|
|
52
|
+
"./remult-knex": {
|
|
53
|
+
"require": "./remult-knex/index.js",
|
|
54
|
+
"import": "./esm/remult-knex/index.js"
|
|
55
|
+
},
|
|
56
|
+
"./remult-mongo": {
|
|
57
|
+
"require": "./remult-mongo.js",
|
|
58
|
+
"import": "./esm/remult-mongo.js"
|
|
59
|
+
},
|
|
60
|
+
"./graphql": {
|
|
61
|
+
"require": "./graphql.js",
|
|
62
|
+
"import": "./esm/graphql.js"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/remult-express.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as express from 'express';
|
|
2
2
|
import { RemultServer, RemultServerOptions } from './server/expressBridge';
|
|
3
|
-
export declare function remultExpress(options?: RemultServerOptions & {
|
|
3
|
+
export declare function remultExpress(options?: RemultServerOptions<express.Request> & {
|
|
4
4
|
bodyParser?: boolean;
|
|
5
5
|
bodySizeLimit?: string;
|
|
6
6
|
}): express.RequestHandler & RemultServer;
|
package/remult-fastify.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { FastifyPluginCallback } from 'fastify';
|
|
1
|
+
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
|
|
2
2
|
import { RemultServer, RemultServerOptions } from './server/expressBridge';
|
|
3
|
-
export declare function remultFastify(options: RemultServerOptions): FastifyPluginCallback & RemultServer;
|
|
3
|
+
export declare function remultFastify(options: RemultServerOptions<FastifyRequest>): FastifyPluginCallback & RemultServer;
|
package/remult-fresh.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RemultServerOptions, GenericRequest } from "./server/expressBridge";
|
|
2
2
|
import { Remult } from "./src/context";
|
|
3
|
-
export declare function remultFresh(options: RemultServerOptions
|
|
3
|
+
export declare function remultFresh<RequestType extends GenericRequest>(options: RemultServerOptions<RequestType>, response: FreshResponse): RemultFresh;
|
|
4
4
|
export interface RemultFresh {
|
|
5
5
|
getRemult(req: GenericRequest): Promise<Remult>;
|
|
6
6
|
openApiDoc(options: {
|
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),
|
|
@@ -4,23 +4,23 @@ import { Remult, UserInfo } from '../src/context';
|
|
|
4
4
|
import { ClassType } from '../classType';
|
|
5
5
|
import { Repository } from '../src/remult3';
|
|
6
6
|
import { IdEntity } from '../src/id-entity';
|
|
7
|
-
export
|
|
7
|
+
export interface RemultServerOptions<RequestType extends GenericRequest> {
|
|
8
8
|
/** Sets a database connection for Remult.
|
|
9
9
|
*
|
|
10
10
|
* @see [Connecting to a Database](https://remult.dev/docs/databases.html).
|
|
11
11
|
*/
|
|
12
12
|
dataProvider?: DataProvider | Promise<DataProvider> | (() => Promise<DataProvider | undefined>);
|
|
13
13
|
queueStorage?: QueueStorage;
|
|
14
|
-
initRequest?: (remult: Remult, origReq:
|
|
15
|
-
getUser?: (request:
|
|
14
|
+
initRequest?: (remult: Remult, origReq: RequestType) => Promise<void>;
|
|
15
|
+
getUser?: (request: RequestType) => Promise<UserInfo>;
|
|
16
16
|
initApi?: (remult: Remult) => void | Promise<void>;
|
|
17
17
|
logApiEndPoints?: boolean;
|
|
18
18
|
defaultGetLimit?: number;
|
|
19
19
|
entities?: ClassType<any>[];
|
|
20
20
|
controllers?: ClassType<any>[];
|
|
21
21
|
rootPath?: string;
|
|
22
|
-
}
|
|
23
|
-
export declare function createRemultServer(options?: RemultServerOptions): RemultServer;
|
|
22
|
+
}
|
|
23
|
+
export declare function createRemultServer<RequestType extends GenericRequest = GenericRequest>(options?: RemultServerOptions<RequestType>): RemultServer;
|
|
24
24
|
export declare type GenericRequestHandler = (req: GenericRequest, res: GenericResponse, next: VoidFunction) => void;
|
|
25
25
|
export interface ServerHandleResponse {
|
|
26
26
|
data?: any;
|
package/server/expressBridge.js
CHANGED
|
@@ -7,11 +7,14 @@ var data_api_1 = require("../src/data-api");
|
|
|
7
7
|
var context_1 = require("../src/context");
|
|
8
8
|
var remult3_1 = require("../src/remult3");
|
|
9
9
|
var id_entity_1 = require("../src/id-entity");
|
|
10
|
+
;
|
|
10
11
|
function createRemultServer(options) {
|
|
11
12
|
var _this = this;
|
|
12
13
|
if (!options) {
|
|
13
14
|
options = {};
|
|
14
15
|
}
|
|
16
|
+
if (options.logApiEndPoints === undefined)
|
|
17
|
+
options.logApiEndPoints = true;
|
|
15
18
|
server_action_1.actionInfo.runningOnServer = true;
|
|
16
19
|
if (options.defaultGetLimit) {
|
|
17
20
|
data_api_1.DataApi.defaultGetLimit = options.defaultGetLimit;
|
|
@@ -162,7 +165,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
162
165
|
var _this = this;
|
|
163
166
|
var myRoute = this.options.rootPath + '/' + key;
|
|
164
167
|
if (this.options.logApiEndPoints)
|
|
165
|
-
console.log(myRoute);
|
|
168
|
+
console.log("[remult] " + myRoute);
|
|
166
169
|
r.route(myRoute)
|
|
167
170
|
.get(this.process(function (c, req, res) {
|
|
168
171
|
return dataApiFactory(c).httpGet(res, req);
|
|
@@ -265,7 +268,7 @@ var RemultServerImplementation = /** @class */ (function () {
|
|
|
265
268
|
})();
|
|
266
269
|
_this.backendMethodsOpenApi.push({ path: myUrl, allowed: allowed, tag: tag });
|
|
267
270
|
if (_this.options.logApiEndPoints)
|
|
268
|
-
console.log(myUrl);
|
|
271
|
+
console.log("[remult] " + myUrl);
|
|
269
272
|
if (queue) {
|
|
270
273
|
_this.hasQueue = true;
|
|
271
274
|
_this.queue.mapQueuedAction(myUrl, what);
|
|
@@ -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 = [];
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ValueConverters } from '../valueConverters';
|
|
2
|
-
export function postgresColumnSyntax(x, dbName) {
|
|
3
|
-
let result = dbName;
|
|
4
|
-
if (x.valueType == Number) {
|
|
5
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
6
|
-
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
7
|
-
else
|
|
8
|
-
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
9
|
-
}
|
|
10
|
-
else if (x.valueType == Date) {
|
|
11
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
12
|
-
if (x.valueConverter == ValueConverters.DateOnly)
|
|
13
|
-
result += " date";
|
|
14
|
-
else
|
|
15
|
-
result += " timestamp";
|
|
16
|
-
else
|
|
17
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
18
|
-
}
|
|
19
|
-
else if (x.valueType == Boolean)
|
|
20
|
-
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
21
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
22
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
23
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
24
|
-
result += " default 0 not null";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
else
|
|
28
|
-
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
29
|
-
return result;
|
|
30
|
-
}
|
package/esm/remult-middleware.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { remultMiddlewareBase } from './server/expressBridge';
|
|
2
|
-
export function remultMiddleware(options) {
|
|
3
|
-
const m = new middleware();
|
|
4
|
-
let app = Object.assign((req, res, next) => m.handleRequest(req, res, next), {
|
|
5
|
-
route: (path) => m.route(path)
|
|
6
|
-
});
|
|
7
|
-
return remultMiddlewareBase(app, options);
|
|
8
|
-
}
|
|
9
|
-
class middleware {
|
|
10
|
-
constructor() {
|
|
11
|
-
this.map = new Map();
|
|
12
|
-
}
|
|
13
|
-
route(path) {
|
|
14
|
-
//consider using:
|
|
15
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
16
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
17
|
-
let r = path.toLowerCase();
|
|
18
|
-
let m = new Map();
|
|
19
|
-
this.map.set(r, m);
|
|
20
|
-
const route = {
|
|
21
|
-
get: (h) => {
|
|
22
|
-
m.set("get", h);
|
|
23
|
-
return route;
|
|
24
|
-
},
|
|
25
|
-
put: (h) => {
|
|
26
|
-
m.set("put", h);
|
|
27
|
-
return route;
|
|
28
|
-
},
|
|
29
|
-
post: (h) => {
|
|
30
|
-
m.set("post", h);
|
|
31
|
-
return route;
|
|
32
|
-
},
|
|
33
|
-
delete: (h) => {
|
|
34
|
-
m.set("delete", h);
|
|
35
|
-
return route;
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return route;
|
|
39
|
-
}
|
|
40
|
-
handleRequest(req, res, next) {
|
|
41
|
-
let lowerPath = req.path.toLowerCase();
|
|
42
|
-
let m = this.map.get(lowerPath);
|
|
43
|
-
if (m) {
|
|
44
|
-
let h = m.get(req.method.toLowerCase());
|
|
45
|
-
if (h) {
|
|
46
|
-
h(req, res, next);
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
let idPosition = req.path.lastIndexOf('/');
|
|
51
|
-
if (idPosition >= 0) {
|
|
52
|
-
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
53
|
-
m = this.map.get(lowerPath);
|
|
54
|
-
if (m) {
|
|
55
|
-
let h = m.get(req.method.toLowerCase());
|
|
56
|
-
if (h) {
|
|
57
|
-
req.params.id = req.path.substring(idPosition + 1);
|
|
58
|
-
h(req, res, next);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
next();
|
|
64
|
-
}
|
|
65
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { serverActionField, actionInfo, classBackendMethodsArray } from '../src/server-action';
|
|
2
|
-
export function registerActionsOnServer(area, controllers) {
|
|
3
|
-
var addAction = (a) => {
|
|
4
|
-
let x = a[serverActionField];
|
|
5
|
-
if (!x) {
|
|
6
|
-
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
7
|
-
}
|
|
8
|
-
area.addAction(x);
|
|
9
|
-
};
|
|
10
|
-
actionInfo.runningOnServer = true;
|
|
11
|
-
if (controllers && controllers.length > 0) {
|
|
12
|
-
for (const c of controllers) {
|
|
13
|
-
let z = c[classBackendMethodsArray];
|
|
14
|
-
if (z)
|
|
15
|
-
for (const a of z) {
|
|
16
|
-
addAction(a);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
else
|
|
21
|
-
actionInfo.allActions.forEach((a) => {
|
|
22
|
-
addAction(a);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { getEntityKey } from "../src/remult3";
|
|
2
|
-
import { allEntities } from "../src/context";
|
|
3
|
-
import { DataApi } from "../src/data-api";
|
|
4
|
-
export function registerEntitiesOnServer(area, entities) {
|
|
5
|
-
if (!entities)
|
|
6
|
-
entities = allEntities;
|
|
7
|
-
//add Api Entries
|
|
8
|
-
entities.forEach(e => {
|
|
9
|
-
let key = getEntityKey(e);
|
|
10
|
-
if (key != undefined)
|
|
11
|
-
area.add(key, c => {
|
|
12
|
-
return new DataApi(c.repo(e), c);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
}
|
package/esm/valueConverters.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ValueConverter } from "./src/column-interfaces";
|
|
2
|
-
export declare class ValueConverters {
|
|
3
|
-
static readonly Date: ValueConverter<Date>;
|
|
4
|
-
static readonly DateOnly: ValueConverter<Date>;
|
|
5
|
-
static readonly DateOnlyString: ValueConverter<Date>;
|
|
6
|
-
static readonly Boolean: ValueConverter<Boolean>;
|
|
7
|
-
static readonly Number: ValueConverter<number>;
|
|
8
|
-
static readonly Integer: ValueConverter<number>;
|
|
9
|
-
static readonly Default: ValueConverter<any>;
|
|
10
|
-
static readonly JsonString: ValueConverter<any>;
|
|
11
|
-
static readonly JsonValue: ValueConverter<any>;
|
|
12
|
-
}
|
package/esm/valueConverters.js
DELETED
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { InputTypes } from "./inputTypes";
|
|
2
|
-
export class ValueConverters {
|
|
3
|
-
}
|
|
4
|
-
ValueConverters.Date = {
|
|
5
|
-
toJson: (val) => {
|
|
6
|
-
if (!val)
|
|
7
|
-
return '';
|
|
8
|
-
if (typeof (val) === "string")
|
|
9
|
-
val = new Date(val);
|
|
10
|
-
if (val instanceof Date) {
|
|
11
|
-
return val.toISOString();
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
console.log("ToJsonError", val);
|
|
15
|
-
throw new Error("Expected date but got val");
|
|
16
|
-
}
|
|
17
|
-
},
|
|
18
|
-
fromJson: (val) => {
|
|
19
|
-
if (val == undefined)
|
|
20
|
-
return undefined;
|
|
21
|
-
if (val == '')
|
|
22
|
-
return undefined;
|
|
23
|
-
if (val.startsWith('0000-00-00'))
|
|
24
|
-
return undefined;
|
|
25
|
-
return new Date(Date.parse(val));
|
|
26
|
-
},
|
|
27
|
-
toDb: x => x,
|
|
28
|
-
fromDb: x => x,
|
|
29
|
-
fromInput: x => ValueConverters.Date.fromJson(x),
|
|
30
|
-
toInput: x => ValueConverters.Date.toJson(x),
|
|
31
|
-
displayValue: (val) => {
|
|
32
|
-
if (!val)
|
|
33
|
-
return '';
|
|
34
|
-
return val.toLocaleString();
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
ValueConverters.DateOnly = {
|
|
38
|
-
fromInput: x => ValueConverters.DateOnly.fromJson(x),
|
|
39
|
-
toInput: x => ValueConverters.DateOnly.toJson(x),
|
|
40
|
-
toJson: (val) => {
|
|
41
|
-
var d = val;
|
|
42
|
-
if (typeof d === "string" || typeof (d) === "number")
|
|
43
|
-
d = new Date(d);
|
|
44
|
-
if (!d || d == null)
|
|
45
|
-
return null;
|
|
46
|
-
if (d.getHours() == 0)
|
|
47
|
-
return new Date(d.valueOf() - d.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
|
|
48
|
-
else
|
|
49
|
-
return d.toISOString().substring(0, 10);
|
|
50
|
-
},
|
|
51
|
-
fromJson: (value) => {
|
|
52
|
-
if (!value || value == '' || value == '0000-00-00')
|
|
53
|
-
return null;
|
|
54
|
-
let d = new Date(Date.parse(value));
|
|
55
|
-
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
|
|
56
|
-
return d;
|
|
57
|
-
},
|
|
58
|
-
inputType: InputTypes.date,
|
|
59
|
-
toDb: (val) => {
|
|
60
|
-
if (!val)
|
|
61
|
-
return null;
|
|
62
|
-
return ValueConverters.DateOnly.fromJson(ValueConverters.DateOnly.toJson(val));
|
|
63
|
-
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
64
|
-
,
|
|
65
|
-
fromDb: (val) => {
|
|
66
|
-
var d = val;
|
|
67
|
-
if (!d)
|
|
68
|
-
return null;
|
|
69
|
-
return val;
|
|
70
|
-
},
|
|
71
|
-
fieldTypeInDb: 'date',
|
|
72
|
-
displayValue: (value) => {
|
|
73
|
-
if (!value)
|
|
74
|
-
return '';
|
|
75
|
-
return value.toLocaleDateString(undefined);
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
ValueConverters.DateOnlyString = {
|
|
79
|
-
...ValueConverters.DateOnly,
|
|
80
|
-
toDb: (d) => {
|
|
81
|
-
let val = ValueConverters.DateOnly.toJson(d);
|
|
82
|
-
if (!val)
|
|
83
|
-
return undefined;
|
|
84
|
-
return val.replace(/-/g, '');
|
|
85
|
-
},
|
|
86
|
-
fromDb: (val) => {
|
|
87
|
-
if (val === null)
|
|
88
|
-
return null;
|
|
89
|
-
if (!val)
|
|
90
|
-
return undefined;
|
|
91
|
-
return new Date(val.substring(0, 4) + '-' + val.substring(4, 6) + '-' + val.substring(6, 8));
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
ValueConverters.Boolean = {
|
|
95
|
-
toDb: (val) => val,
|
|
96
|
-
inputType: InputTypes.checkbox,
|
|
97
|
-
fromDb: (value) => {
|
|
98
|
-
return ValueConverters.Boolean.fromJson(value);
|
|
99
|
-
},
|
|
100
|
-
fromJson: value => {
|
|
101
|
-
if (typeof value === "boolean")
|
|
102
|
-
return value;
|
|
103
|
-
if (value !== undefined && value !== null) {
|
|
104
|
-
return value.toString().trim().toLowerCase() == 'true';
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
},
|
|
108
|
-
toJson: x => x,
|
|
109
|
-
fromInput: x => ValueConverters.Boolean.fromJson(x),
|
|
110
|
-
toInput: x => ValueConverters.Boolean.toJson(x)
|
|
111
|
-
};
|
|
112
|
-
ValueConverters.Number = {
|
|
113
|
-
fromDb: value => {
|
|
114
|
-
if (value === null)
|
|
115
|
-
return null;
|
|
116
|
-
if (value !== undefined)
|
|
117
|
-
return +value;
|
|
118
|
-
return undefined;
|
|
119
|
-
},
|
|
120
|
-
toDb: value => value,
|
|
121
|
-
fromJson: value => ValueConverters.Number.fromDb(value),
|
|
122
|
-
toJson: value => ValueConverters.Number.toDb(value),
|
|
123
|
-
fromInput: (x, type) => {
|
|
124
|
-
let r = +x;
|
|
125
|
-
if (!x)
|
|
126
|
-
return undefined;
|
|
127
|
-
return r;
|
|
128
|
-
},
|
|
129
|
-
toInput: (x, type) => {
|
|
130
|
-
return x?.toString();
|
|
131
|
-
},
|
|
132
|
-
inputType: InputTypes.number
|
|
133
|
-
};
|
|
134
|
-
ValueConverters.Integer = {
|
|
135
|
-
...ValueConverters.Number,
|
|
136
|
-
toJson: value => {
|
|
137
|
-
let val = ValueConverters.Number.toDb(value);
|
|
138
|
-
if (!val)
|
|
139
|
-
return val;
|
|
140
|
-
return +(+val).toFixed(0);
|
|
141
|
-
},
|
|
142
|
-
toDb: value => ValueConverters.Integer.toJson(value),
|
|
143
|
-
fieldTypeInDb: 'integer'
|
|
144
|
-
};
|
|
145
|
-
ValueConverters.Default = {
|
|
146
|
-
fromJson: x => x,
|
|
147
|
-
toJson: x => x,
|
|
148
|
-
fromDb: x => ValueConverters.JsonString.fromDb(x),
|
|
149
|
-
toDb: x => ValueConverters.JsonString.toDb(x),
|
|
150
|
-
fromInput: x => ValueConverters.Default.fromJson(x),
|
|
151
|
-
toInput: x => ValueConverters.Default.toJson(x)
|
|
152
|
-
};
|
|
153
|
-
ValueConverters.JsonString = {
|
|
154
|
-
fromJson: x => x,
|
|
155
|
-
toJson: x => x,
|
|
156
|
-
fromDb: x => x == null ? null : x ? JSON.parse(ValueConverters.JsonString.fromJson(x)) : undefined,
|
|
157
|
-
toDb: x => x !== undefined ? x === null ? null : JSON.stringify(ValueConverters.JsonString.toJson(x)) : undefined,
|
|
158
|
-
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
159
|
-
toInput: x => ValueConverters.JsonString.toJson(x)
|
|
160
|
-
};
|
|
161
|
-
ValueConverters.JsonValue = {
|
|
162
|
-
fromJson: x => x,
|
|
163
|
-
toJson: x => x,
|
|
164
|
-
fromDb: x => x,
|
|
165
|
-
toDb: x => x,
|
|
166
|
-
fromInput: x => ValueConverters.JsonString.fromJson(x),
|
|
167
|
-
toInput: x => ValueConverters.JsonString.toJson(x),
|
|
168
|
-
fieldTypeInDb: 'json'
|
|
169
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.postgresColumnSyntax = void 0;
|
|
4
|
-
var valueConverters_1 = require("../valueConverters");
|
|
5
|
-
function postgresColumnSyntax(x, dbName) {
|
|
6
|
-
var result = dbName;
|
|
7
|
-
if (x.valueType == Number) {
|
|
8
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
9
|
-
result += " numeric" + (x.allowNull ? "" : " default 0 not null");
|
|
10
|
-
else
|
|
11
|
-
result += " " + x.valueConverter.fieldTypeInDb + (x.allowNull ? "" : " default 0 not null");
|
|
12
|
-
}
|
|
13
|
-
else if (x.valueType == Date) {
|
|
14
|
-
if (!x.valueConverter.fieldTypeInDb)
|
|
15
|
-
if (x.valueConverter == valueConverters_1.ValueConverters.DateOnly)
|
|
16
|
-
result += " date";
|
|
17
|
-
else
|
|
18
|
-
result += " timestamp";
|
|
19
|
-
else
|
|
20
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
21
|
-
}
|
|
22
|
-
else if (x.valueType == Boolean)
|
|
23
|
-
result += " boolean" + (x.allowNull ? "" : " default false not null");
|
|
24
|
-
else if (x.valueConverter.fieldTypeInDb) {
|
|
25
|
-
result += " " + x.valueConverter.fieldTypeInDb;
|
|
26
|
-
if (!x.allowNull && x.valueConverter.fieldTypeInDb == 'integer') {
|
|
27
|
-
result += " default 0 not null";
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
else
|
|
31
|
-
result += " varchar" + (x.allowNull ? "" : " default '' not null");
|
|
32
|
-
return result;
|
|
33
|
-
}
|
|
34
|
-
exports.postgresColumnSyntax = postgresColumnSyntax;
|
package/remult-middleware.d.ts
DELETED
package/remult-middleware.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.remultMiddleware = void 0;
|
|
4
|
-
var expressBridge_1 = require("./server/expressBridge");
|
|
5
|
-
function remultMiddleware(options) {
|
|
6
|
-
var m = new middleware();
|
|
7
|
-
var app = Object.assign(function (req, res, next) { return m.handleRequest(req, res, next); }, {
|
|
8
|
-
route: function (path) { return m.route(path); }
|
|
9
|
-
});
|
|
10
|
-
return expressBridge_1.remultMiddlewareBase(app, options);
|
|
11
|
-
}
|
|
12
|
-
exports.remultMiddleware = remultMiddleware;
|
|
13
|
-
var middleware = /** @class */ (function () {
|
|
14
|
-
function middleware() {
|
|
15
|
-
this.map = new Map();
|
|
16
|
-
}
|
|
17
|
-
middleware.prototype.route = function (path) {
|
|
18
|
-
//consider using:
|
|
19
|
-
//* https://raw.githubusercontent.com/cmorten/opine/main/src/utils/pathToRegex.ts
|
|
20
|
-
//* https://github.com/pillarjs/path-to-regexp
|
|
21
|
-
var r = path.toLowerCase();
|
|
22
|
-
var m = new Map();
|
|
23
|
-
this.map.set(r, m);
|
|
24
|
-
var route = {
|
|
25
|
-
get: function (h) {
|
|
26
|
-
m.set("get", h);
|
|
27
|
-
return route;
|
|
28
|
-
},
|
|
29
|
-
put: function (h) {
|
|
30
|
-
m.set("put", h);
|
|
31
|
-
return route;
|
|
32
|
-
},
|
|
33
|
-
post: function (h) {
|
|
34
|
-
m.set("post", h);
|
|
35
|
-
return route;
|
|
36
|
-
},
|
|
37
|
-
delete: function (h) {
|
|
38
|
-
m.set("delete", h);
|
|
39
|
-
return route;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
return route;
|
|
43
|
-
};
|
|
44
|
-
middleware.prototype.handleRequest = function (req, res, next) {
|
|
45
|
-
var lowerPath = req.path.toLowerCase();
|
|
46
|
-
var m = this.map.get(lowerPath);
|
|
47
|
-
if (m) {
|
|
48
|
-
var h = m.get(req.method.toLowerCase());
|
|
49
|
-
if (h) {
|
|
50
|
-
h(req, res, next);
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
var idPosition = req.path.lastIndexOf('/');
|
|
55
|
-
if (idPosition >= 0) {
|
|
56
|
-
lowerPath = req.path.substring(0, idPosition) + '/:id';
|
|
57
|
-
m = this.map.get(lowerPath);
|
|
58
|
-
if (m) {
|
|
59
|
-
var h = m.get(req.method.toLowerCase());
|
|
60
|
-
if (h) {
|
|
61
|
-
req.params.id = req.path.substring(idPosition + 1);
|
|
62
|
-
h(req, res, next);
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
next();
|
|
68
|
-
};
|
|
69
|
-
return middleware;
|
|
70
|
-
}());
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerActionsOnServer = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var server_action_1 = require("../src/server-action");
|
|
6
|
-
function registerActionsOnServer(area, controllers) {
|
|
7
|
-
var e_1, _a, e_2, _b;
|
|
8
|
-
var addAction = function (a) {
|
|
9
|
-
var x = a[server_action_1.serverActionField];
|
|
10
|
-
if (!x) {
|
|
11
|
-
throw 'failed to set server action, did you forget the BackendMethod Decorator?';
|
|
12
|
-
}
|
|
13
|
-
area.addAction(x);
|
|
14
|
-
};
|
|
15
|
-
server_action_1.actionInfo.runningOnServer = true;
|
|
16
|
-
if (controllers && controllers.length > 0) {
|
|
17
|
-
try {
|
|
18
|
-
for (var controllers_1 = tslib_1.__values(controllers), controllers_1_1 = controllers_1.next(); !controllers_1_1.done; controllers_1_1 = controllers_1.next()) {
|
|
19
|
-
var c = controllers_1_1.value;
|
|
20
|
-
var z = c[server_action_1.classBackendMethodsArray];
|
|
21
|
-
if (z)
|
|
22
|
-
try {
|
|
23
|
-
for (var z_1 = (e_2 = void 0, tslib_1.__values(z)), z_1_1 = z_1.next(); !z_1_1.done; z_1_1 = z_1.next()) {
|
|
24
|
-
var a = z_1_1.value;
|
|
25
|
-
addAction(a);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
29
|
-
finally {
|
|
30
|
-
try {
|
|
31
|
-
if (z_1_1 && !z_1_1.done && (_b = z_1.return)) _b.call(z_1);
|
|
32
|
-
}
|
|
33
|
-
finally { if (e_2) throw e_2.error; }
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
38
|
-
finally {
|
|
39
|
-
try {
|
|
40
|
-
if (controllers_1_1 && !controllers_1_1.done && (_a = controllers_1.return)) _a.call(controllers_1);
|
|
41
|
-
}
|
|
42
|
-
finally { if (e_1) throw e_1.error; }
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
else
|
|
46
|
-
server_action_1.actionInfo.allActions.forEach(function (a) {
|
|
47
|
-
addAction(a);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
exports.registerActionsOnServer = registerActionsOnServer;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.registerEntitiesOnServer = void 0;
|
|
4
|
-
var remult3_1 = require("../src/remult3");
|
|
5
|
-
var context_1 = require("../src/context");
|
|
6
|
-
var data_api_1 = require("../src/data-api");
|
|
7
|
-
function registerEntitiesOnServer(area, entities) {
|
|
8
|
-
if (!entities)
|
|
9
|
-
entities = context_1.allEntities;
|
|
10
|
-
//add Api Entries
|
|
11
|
-
entities.forEach(function (e) {
|
|
12
|
-
var key = remult3_1.getEntityKey(e);
|
|
13
|
-
if (key != undefined)
|
|
14
|
-
area.add(key, function (c) {
|
|
15
|
-
return new data_api_1.DataApi(c.repo(e), c);
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
exports.registerEntitiesOnServer = registerEntitiesOnServer;
|
package/valueConverters.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ValueConverter } from "./src/column-interfaces";
|
|
2
|
-
export declare class ValueConverters {
|
|
3
|
-
static readonly Date: ValueConverter<Date>;
|
|
4
|
-
static readonly DateOnly: ValueConverter<Date>;
|
|
5
|
-
static readonly DateOnlyString: ValueConverter<Date>;
|
|
6
|
-
static readonly Boolean: ValueConverter<Boolean>;
|
|
7
|
-
static readonly Number: ValueConverter<number>;
|
|
8
|
-
static readonly Integer: ValueConverter<number>;
|
|
9
|
-
static readonly Default: ValueConverter<any>;
|
|
10
|
-
static readonly JsonString: ValueConverter<any>;
|
|
11
|
-
static readonly JsonValue: ValueConverter<any>;
|
|
12
|
-
}
|
package/valueConverters.js
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ValueConverters = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
|
-
var inputTypes_1 = require("./inputTypes");
|
|
6
|
-
var ValueConverters = /** @class */ (function () {
|
|
7
|
-
function ValueConverters() {
|
|
8
|
-
}
|
|
9
|
-
ValueConverters.Date = {
|
|
10
|
-
toJson: function (val) {
|
|
11
|
-
if (!val)
|
|
12
|
-
return '';
|
|
13
|
-
if (typeof (val) === "string")
|
|
14
|
-
val = new Date(val);
|
|
15
|
-
if (val instanceof Date) {
|
|
16
|
-
return val.toISOString();
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
console.log("ToJsonError", val);
|
|
20
|
-
throw new Error("Expected date but got val");
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
fromJson: function (val) {
|
|
24
|
-
if (val == undefined)
|
|
25
|
-
return undefined;
|
|
26
|
-
if (val == '')
|
|
27
|
-
return undefined;
|
|
28
|
-
if (val.startsWith('0000-00-00'))
|
|
29
|
-
return undefined;
|
|
30
|
-
return new Date(Date.parse(val));
|
|
31
|
-
},
|
|
32
|
-
toDb: function (x) { return x; },
|
|
33
|
-
fromDb: function (x) { return x; },
|
|
34
|
-
fromInput: function (x) { return ValueConverters.Date.fromJson(x); },
|
|
35
|
-
toInput: function (x) { return ValueConverters.Date.toJson(x); },
|
|
36
|
-
displayValue: function (val) {
|
|
37
|
-
if (!val)
|
|
38
|
-
return '';
|
|
39
|
-
return val.toLocaleString();
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
ValueConverters.DateOnly = {
|
|
43
|
-
fromInput: function (x) { return ValueConverters.DateOnly.fromJson(x); },
|
|
44
|
-
toInput: function (x) { return ValueConverters.DateOnly.toJson(x); },
|
|
45
|
-
toJson: function (val) {
|
|
46
|
-
var d = val;
|
|
47
|
-
if (typeof d === "string" || typeof (d) === "number")
|
|
48
|
-
d = new Date(d);
|
|
49
|
-
if (!d || d == null)
|
|
50
|
-
return null;
|
|
51
|
-
if (d.getHours() == 0)
|
|
52
|
-
return new Date(d.valueOf() - d.getTimezoneOffset() * 60000).toISOString().substring(0, 10);
|
|
53
|
-
else
|
|
54
|
-
return d.toISOString().substring(0, 10);
|
|
55
|
-
},
|
|
56
|
-
fromJson: function (value) {
|
|
57
|
-
if (!value || value == '' || value == '0000-00-00')
|
|
58
|
-
return null;
|
|
59
|
-
var d = new Date(Date.parse(value));
|
|
60
|
-
d.setMinutes(d.getMinutes() + d.getTimezoneOffset());
|
|
61
|
-
return d;
|
|
62
|
-
},
|
|
63
|
-
inputType: inputTypes_1.InputTypes.date,
|
|
64
|
-
toDb: function (val) {
|
|
65
|
-
if (!val)
|
|
66
|
-
return null;
|
|
67
|
-
return ValueConverters.DateOnly.fromJson(ValueConverters.DateOnly.toJson(val));
|
|
68
|
-
} //when using date storage, the database expects and returns a date local and every where else we reflect on date iso
|
|
69
|
-
,
|
|
70
|
-
fromDb: function (val) {
|
|
71
|
-
var d = val;
|
|
72
|
-
if (!d)
|
|
73
|
-
return null;
|
|
74
|
-
return val;
|
|
75
|
-
},
|
|
76
|
-
fieldTypeInDb: 'date',
|
|
77
|
-
displayValue: function (value) {
|
|
78
|
-
if (!value)
|
|
79
|
-
return '';
|
|
80
|
-
return value.toLocaleDateString(undefined);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
ValueConverters.DateOnlyString = tslib_1.__assign(tslib_1.__assign({}, ValueConverters.DateOnly), { toDb: function (d) {
|
|
84
|
-
var val = ValueConverters.DateOnly.toJson(d);
|
|
85
|
-
if (!val)
|
|
86
|
-
return undefined;
|
|
87
|
-
return val.replace(/-/g, '');
|
|
88
|
-
}, fromDb: function (val) {
|
|
89
|
-
if (val === null)
|
|
90
|
-
return null;
|
|
91
|
-
if (!val)
|
|
92
|
-
return undefined;
|
|
93
|
-
return new Date(val.substring(0, 4) + '-' + val.substring(4, 6) + '-' + val.substring(6, 8));
|
|
94
|
-
} });
|
|
95
|
-
ValueConverters.Boolean = {
|
|
96
|
-
toDb: function (val) { return val; },
|
|
97
|
-
inputType: inputTypes_1.InputTypes.checkbox,
|
|
98
|
-
fromDb: function (value) {
|
|
99
|
-
return ValueConverters.Boolean.fromJson(value);
|
|
100
|
-
},
|
|
101
|
-
fromJson: function (value) {
|
|
102
|
-
if (typeof value === "boolean")
|
|
103
|
-
return value;
|
|
104
|
-
if (value !== undefined && value !== null) {
|
|
105
|
-
return value.toString().trim().toLowerCase() == 'true';
|
|
106
|
-
}
|
|
107
|
-
return value;
|
|
108
|
-
},
|
|
109
|
-
toJson: function (x) { return x; },
|
|
110
|
-
fromInput: function (x) { return ValueConverters.Boolean.fromJson(x); },
|
|
111
|
-
toInput: function (x) { return ValueConverters.Boolean.toJson(x); }
|
|
112
|
-
};
|
|
113
|
-
ValueConverters.Number = {
|
|
114
|
-
fromDb: function (value) {
|
|
115
|
-
if (value === null)
|
|
116
|
-
return null;
|
|
117
|
-
if (value !== undefined)
|
|
118
|
-
return +value;
|
|
119
|
-
return undefined;
|
|
120
|
-
},
|
|
121
|
-
toDb: function (value) { return value; },
|
|
122
|
-
fromJson: function (value) { return ValueConverters.Number.fromDb(value); },
|
|
123
|
-
toJson: function (value) { return ValueConverters.Number.toDb(value); },
|
|
124
|
-
fromInput: function (x, type) {
|
|
125
|
-
var r = +x;
|
|
126
|
-
if (!x)
|
|
127
|
-
return undefined;
|
|
128
|
-
return r;
|
|
129
|
-
},
|
|
130
|
-
toInput: function (x, type) {
|
|
131
|
-
return x === null || x === void 0 ? void 0 : x.toString();
|
|
132
|
-
},
|
|
133
|
-
inputType: inputTypes_1.InputTypes.number
|
|
134
|
-
};
|
|
135
|
-
ValueConverters.Integer = tslib_1.__assign(tslib_1.__assign({}, ValueConverters.Number), { toJson: function (value) {
|
|
136
|
-
var val = ValueConverters.Number.toDb(value);
|
|
137
|
-
if (!val)
|
|
138
|
-
return val;
|
|
139
|
-
return +(+val).toFixed(0);
|
|
140
|
-
}, toDb: function (value) { return ValueConverters.Integer.toJson(value); }, fieldTypeInDb: 'integer' });
|
|
141
|
-
ValueConverters.Default = {
|
|
142
|
-
fromJson: function (x) { return x; },
|
|
143
|
-
toJson: function (x) { return x; },
|
|
144
|
-
fromDb: function (x) { return ValueConverters.JsonString.fromDb(x); },
|
|
145
|
-
toDb: function (x) { return ValueConverters.JsonString.toDb(x); },
|
|
146
|
-
fromInput: function (x) { return ValueConverters.Default.fromJson(x); },
|
|
147
|
-
toInput: function (x) { return ValueConverters.Default.toJson(x); }
|
|
148
|
-
};
|
|
149
|
-
ValueConverters.JsonString = {
|
|
150
|
-
fromJson: function (x) { return x; },
|
|
151
|
-
toJson: function (x) { return x; },
|
|
152
|
-
fromDb: function (x) { return x == null ? null : x ? JSON.parse(ValueConverters.JsonString.fromJson(x)) : undefined; },
|
|
153
|
-
toDb: function (x) { return x !== undefined ? x === null ? null : JSON.stringify(ValueConverters.JsonString.toJson(x)) : undefined; },
|
|
154
|
-
fromInput: function (x) { return ValueConverters.JsonString.fromJson(x); },
|
|
155
|
-
toInput: function (x) { return ValueConverters.JsonString.toJson(x); }
|
|
156
|
-
};
|
|
157
|
-
ValueConverters.JsonValue = {
|
|
158
|
-
fromJson: function (x) { return x; },
|
|
159
|
-
toJson: function (x) { return x; },
|
|
160
|
-
fromDb: function (x) { return x; },
|
|
161
|
-
toDb: function (x) { return x; },
|
|
162
|
-
fromInput: function (x) { return ValueConverters.JsonString.fromJson(x); },
|
|
163
|
-
toInput: function (x) { return ValueConverters.JsonString.toJson(x); },
|
|
164
|
-
fieldTypeInDb: 'json'
|
|
165
|
-
};
|
|
166
|
-
return ValueConverters;
|
|
167
|
-
}());
|
|
168
|
-
exports.ValueConverters = ValueConverters;
|