remult 3.0.0-next.1 → 3.0.0-next.2
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/src/buildRestDataProvider.js +2 -26
- package/esm/src/data-providers/rest-data-provider-using-fetch.js +78 -0
- package/esm/src/data-providers/rest-data-provider.js +1 -78
- package/esm/src/data-providers/retry.js +25 -0
- package/esm/src/filter/entityDbName.js +18 -0
- package/esm/src/filter/fieldDbName.js +40 -0
- package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +2 -58
- package/esm/src/remult3/RepositoryImplementation.js +2 -1
- package/esm/src/validators.js +1 -1
- package/package.json +1 -1
- package/src/buildRestDataProvider.d.ts +0 -1
- package/src/buildRestDataProvider.js +6 -46
- package/src/data-providers/rest-data-provider-using-fetch.d.ts +13 -0
- package/src/data-providers/rest-data-provider-using-fetch.js +119 -0
- package/src/data-providers/rest-data-provider.d.ts +0 -12
- package/src/data-providers/rest-data-provider.js +1 -115
- package/src/data-providers/retry.d.ts +1 -0
- package/src/data-providers/retry.js +44 -0
- package/src/filter/entityDbName.d.ts +2 -0
- package/src/filter/entityDbName.js +32 -0
- package/src/filter/fieldDbName.d.ts +3 -0
- package/src/filter/fieldDbName.js +58 -0
- package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +0 -2
- package/src/filter/filter-consumer-bridge-to-sql-request.js +4 -86
- package/src/remult3/RepositoryImplementation.js +4 -3
- package/src/validators.js +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider.js';
|
|
2
|
-
import {
|
|
1
|
+
import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider-using-fetch.js';
|
|
2
|
+
import { retry } from './data-providers/retry.js';
|
|
3
3
|
export function buildRestDataProvider(provider) {
|
|
4
4
|
if (!provider)
|
|
5
5
|
return new RestDataProviderHttpProviderUsingFetch();
|
|
@@ -40,30 +40,6 @@ export class HttpProviderBridgeToRestDataProviderHttpProvider {
|
|
|
40
40
|
return await retry(() => toPromise(this.http.get(url)));
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
export async function retry(what) {
|
|
44
|
-
let i = 0;
|
|
45
|
-
while (true) {
|
|
46
|
-
try {
|
|
47
|
-
return await what();
|
|
48
|
-
}
|
|
49
|
-
catch (err) {
|
|
50
|
-
if ((err.message?.startsWith('Error occurred while trying to proxy') ||
|
|
51
|
-
err.message?.startsWith('Error occured while trying to proxy') ||
|
|
52
|
-
err.message?.includes('http proxy error') ||
|
|
53
|
-
err.message?.startsWith('Gateway Timeout') ||
|
|
54
|
-
err.status == 500) &&
|
|
55
|
-
i++ < flags.error500RetryCount) {
|
|
56
|
-
await new Promise((res, req) => {
|
|
57
|
-
setTimeout(() => {
|
|
58
|
-
res({});
|
|
59
|
-
}, 500);
|
|
60
|
-
});
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
throw err;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
43
|
export function toPromise(p) {
|
|
68
44
|
let r;
|
|
69
45
|
if (p['toPromise'] !== undefined) {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { retry } from './retry.js';
|
|
2
|
+
export class RestDataProviderHttpProviderUsingFetch {
|
|
3
|
+
fetch;
|
|
4
|
+
constructor(fetch) {
|
|
5
|
+
this.fetch = fetch;
|
|
6
|
+
}
|
|
7
|
+
async get(url) {
|
|
8
|
+
return await retry(async () => this.myFetch(url).then((r) => {
|
|
9
|
+
return r;
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
put(url, data) {
|
|
13
|
+
return this.myFetch(url, {
|
|
14
|
+
method: 'put',
|
|
15
|
+
body: JSON.stringify(data),
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
delete(url) {
|
|
19
|
+
return this.myFetch(url, { method: 'delete' });
|
|
20
|
+
}
|
|
21
|
+
async post(url, data) {
|
|
22
|
+
return await retry(() => this.myFetch(url, {
|
|
23
|
+
method: 'post',
|
|
24
|
+
body: JSON.stringify(data),
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
myFetch(url, options) {
|
|
28
|
+
const headers = {};
|
|
29
|
+
if (options?.body)
|
|
30
|
+
headers['Content-type'] = 'application/json';
|
|
31
|
+
if (typeof window !== 'undefined' &&
|
|
32
|
+
typeof window.document !== 'undefined' &&
|
|
33
|
+
typeof (window.document.cookie !== 'undefined'))
|
|
34
|
+
for (const cookie of window.document.cookie.split(';')) {
|
|
35
|
+
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
36
|
+
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return (this.fetch || fetch)(url, {
|
|
40
|
+
credentials: 'include',
|
|
41
|
+
method: options?.method,
|
|
42
|
+
body: options?.body,
|
|
43
|
+
headers,
|
|
44
|
+
})
|
|
45
|
+
.then((response) => {
|
|
46
|
+
return onSuccess(response);
|
|
47
|
+
})
|
|
48
|
+
.catch(async (error) => {
|
|
49
|
+
let r = await error;
|
|
50
|
+
throw r;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function onSuccess(response) {
|
|
55
|
+
if (response.status == 204)
|
|
56
|
+
return;
|
|
57
|
+
if (response.status >= 200 && response.status < 300)
|
|
58
|
+
return response.json();
|
|
59
|
+
else {
|
|
60
|
+
throw response
|
|
61
|
+
.json()
|
|
62
|
+
.then((x) => {
|
|
63
|
+
return {
|
|
64
|
+
...x,
|
|
65
|
+
message: x.message || response.statusText,
|
|
66
|
+
url: response.url,
|
|
67
|
+
status: response.status,
|
|
68
|
+
};
|
|
69
|
+
})
|
|
70
|
+
.catch(() => {
|
|
71
|
+
throw {
|
|
72
|
+
message: response.statusText,
|
|
73
|
+
url: response.url,
|
|
74
|
+
status: response.status,
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UrlBuilder } from '../../urlBuilder.js';
|
|
2
|
-
import { buildRestDataProvider
|
|
2
|
+
import { buildRestDataProvider } from '../buildRestDataProvider.js';
|
|
3
3
|
import { customUrlToken, Filter } from '../filter/filter-interfaces.js';
|
|
4
4
|
import { getRelationFieldInfo } from '../remult3/relationInfoMember.js';
|
|
5
5
|
import { remultStatic } from '../remult-static.js';
|
|
@@ -284,83 +284,6 @@ export class RestEntityDataProvider {
|
|
|
284
284
|
.then((y) => y.map((y) => this.translateFromJson(y)));
|
|
285
285
|
}
|
|
286
286
|
}
|
|
287
|
-
export class RestDataProviderHttpProviderUsingFetch {
|
|
288
|
-
fetch;
|
|
289
|
-
constructor(fetch) {
|
|
290
|
-
this.fetch = fetch;
|
|
291
|
-
}
|
|
292
|
-
async get(url) {
|
|
293
|
-
return await retry(async () => this.myFetch(url).then((r) => {
|
|
294
|
-
return r;
|
|
295
|
-
}));
|
|
296
|
-
}
|
|
297
|
-
put(url, data) {
|
|
298
|
-
return this.myFetch(url, {
|
|
299
|
-
method: 'put',
|
|
300
|
-
body: JSON.stringify(data),
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
delete(url) {
|
|
304
|
-
return this.myFetch(url, { method: 'delete' });
|
|
305
|
-
}
|
|
306
|
-
async post(url, data) {
|
|
307
|
-
return await retry(() => this.myFetch(url, {
|
|
308
|
-
method: 'post',
|
|
309
|
-
body: JSON.stringify(data),
|
|
310
|
-
}));
|
|
311
|
-
}
|
|
312
|
-
myFetch(url, options) {
|
|
313
|
-
const headers = {};
|
|
314
|
-
if (options?.body)
|
|
315
|
-
headers['Content-type'] = 'application/json';
|
|
316
|
-
if (typeof window !== 'undefined' &&
|
|
317
|
-
typeof window.document !== 'undefined' &&
|
|
318
|
-
typeof (window.document.cookie !== 'undefined'))
|
|
319
|
-
for (const cookie of window.document.cookie.split(';')) {
|
|
320
|
-
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
321
|
-
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return (this.fetch || fetch)(url, {
|
|
325
|
-
credentials: 'include',
|
|
326
|
-
method: options?.method,
|
|
327
|
-
body: options?.body,
|
|
328
|
-
headers,
|
|
329
|
-
})
|
|
330
|
-
.then((response) => {
|
|
331
|
-
return onSuccess(response);
|
|
332
|
-
})
|
|
333
|
-
.catch(async (error) => {
|
|
334
|
-
let r = await error;
|
|
335
|
-
throw r;
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
function onSuccess(response) {
|
|
340
|
-
if (response.status == 204)
|
|
341
|
-
return;
|
|
342
|
-
if (response.status >= 200 && response.status < 300)
|
|
343
|
-
return response.json();
|
|
344
|
-
else {
|
|
345
|
-
throw response
|
|
346
|
-
.json()
|
|
347
|
-
.then((x) => {
|
|
348
|
-
return {
|
|
349
|
-
...x,
|
|
350
|
-
message: x.message || response.statusText,
|
|
351
|
-
url: response.url,
|
|
352
|
-
status: response.status,
|
|
353
|
-
};
|
|
354
|
-
})
|
|
355
|
-
.catch(() => {
|
|
356
|
-
throw {
|
|
357
|
-
message: response.statusText,
|
|
358
|
-
url: response.url,
|
|
359
|
-
status: response.status,
|
|
360
|
-
};
|
|
361
|
-
});
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
287
|
export function addFilterToUrlAndReturnTrueIfSuccessful(filter, url) {
|
|
365
288
|
for (const key in filter) {
|
|
366
289
|
if (Object.prototype.hasOwnProperty.call(filter, key)) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { flags } from '../remult3/remult3.js';
|
|
2
|
+
export async function retry(what) {
|
|
3
|
+
let i = 0;
|
|
4
|
+
while (true) {
|
|
5
|
+
try {
|
|
6
|
+
return await what();
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
if ((err.message?.startsWith('Error occurred while trying to proxy') ||
|
|
10
|
+
err.message?.startsWith('Error occured while trying to proxy') ||
|
|
11
|
+
err.message?.includes('http proxy error') ||
|
|
12
|
+
err.message?.startsWith('Gateway Timeout') ||
|
|
13
|
+
err.status == 500) &&
|
|
14
|
+
i++ < flags.error500RetryCount) {
|
|
15
|
+
await new Promise((res, req) => {
|
|
16
|
+
setTimeout(() => {
|
|
17
|
+
res({});
|
|
18
|
+
}, 500);
|
|
19
|
+
});
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
throw err;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export async function entityDbName(metadata, wrapIdentifier = (x) => x) {
|
|
2
|
+
if (metadata.options.sqlExpression) {
|
|
3
|
+
if (typeof metadata.options.sqlExpression === 'string')
|
|
4
|
+
return metadata.options.sqlExpression;
|
|
5
|
+
else if (typeof metadata.options.sqlExpression === 'function') {
|
|
6
|
+
const prev = metadata.options.sqlExpression;
|
|
7
|
+
try {
|
|
8
|
+
metadata.options.sqlExpression =
|
|
9
|
+
"recursive sqlExpression call for entity '" + metadata.key + "'. ";
|
|
10
|
+
return await prev(metadata);
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
metadata.options.sqlExpression = prev;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
return wrapIdentifier(metadata.dbName);
|
|
18
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getRelationFieldInfo } from '../remult3/relationInfoMember.js';
|
|
2
|
+
const sqlExpressionInProgressKey = Symbol.for(`sqlExpressionInProgressKey`);
|
|
3
|
+
export async function fieldDbName(f, meta, wrapIdentifier = (x) => x, forceSqlExpression = false) {
|
|
4
|
+
try {
|
|
5
|
+
if (f.options.sqlExpression) {
|
|
6
|
+
let result;
|
|
7
|
+
if (typeof f.options.sqlExpression === 'function') {
|
|
8
|
+
if (f[sqlExpressionInProgressKey] && !forceSqlExpression) {
|
|
9
|
+
return "recursive sqlExpression call for field '" + f.key + "'. \0";
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
;
|
|
13
|
+
f[sqlExpressionInProgressKey] = true;
|
|
14
|
+
result = await f.options.sqlExpression(meta);
|
|
15
|
+
if (!result.includes('\0'))
|
|
16
|
+
f.options.sqlExpression = () => result;
|
|
17
|
+
}
|
|
18
|
+
finally {
|
|
19
|
+
delete f[sqlExpressionInProgressKey];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else
|
|
23
|
+
result = f.options.sqlExpression;
|
|
24
|
+
if (!result)
|
|
25
|
+
return f.dbName;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
const rel = getRelationFieldInfo(f);
|
|
29
|
+
let field = rel?.type === 'toOne' &&
|
|
30
|
+
f.options.field;
|
|
31
|
+
if (field) {
|
|
32
|
+
let fInfo = meta.fields.find(field);
|
|
33
|
+
if (fInfo)
|
|
34
|
+
return fieldDbName(fInfo, meta, wrapIdentifier, forceSqlExpression);
|
|
35
|
+
}
|
|
36
|
+
return wrapIdentifier(f.dbName);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SqlDatabase } from '../data-providers/sql-database.js';
|
|
2
2
|
import { remult } from '../remult-proxy.js';
|
|
3
3
|
import { getEntityMetadata } from '../remult3/RepositoryImplementation.js';
|
|
4
|
-
import {
|
|
4
|
+
import { entityDbName } from './entityDbName.js';
|
|
5
|
+
import { fieldDbName } from './fieldDbName.js';
|
|
5
6
|
export class FilterConsumerBridgeToSqlRequest {
|
|
6
7
|
r;
|
|
7
8
|
nameProvider;
|
|
@@ -260,60 +261,3 @@ async function internalDbNamesOf(repo, wrapIdentifierOrOptions, forceSqlExpressi
|
|
|
260
261
|
}
|
|
261
262
|
return result;
|
|
262
263
|
}
|
|
263
|
-
export async function entityDbName(metadata, wrapIdentifier = (x) => x) {
|
|
264
|
-
if (metadata.options.sqlExpression) {
|
|
265
|
-
if (typeof metadata.options.sqlExpression === 'string')
|
|
266
|
-
return metadata.options.sqlExpression;
|
|
267
|
-
else if (typeof metadata.options.sqlExpression === 'function') {
|
|
268
|
-
const prev = metadata.options.sqlExpression;
|
|
269
|
-
try {
|
|
270
|
-
metadata.options.sqlExpression =
|
|
271
|
-
"recursive sqlExpression call for entity '" + metadata.key + "'. ";
|
|
272
|
-
return await prev(metadata);
|
|
273
|
-
}
|
|
274
|
-
finally {
|
|
275
|
-
metadata.options.sqlExpression = prev;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
return wrapIdentifier(metadata.dbName);
|
|
280
|
-
}
|
|
281
|
-
const sqlExpressionInProgressKey = Symbol.for(`sqlExpressionInProgressKey`);
|
|
282
|
-
export async function fieldDbName(f, meta, wrapIdentifier = (x) => x, forceSqlExpression = false) {
|
|
283
|
-
try {
|
|
284
|
-
if (f.options.sqlExpression) {
|
|
285
|
-
let result;
|
|
286
|
-
if (typeof f.options.sqlExpression === 'function') {
|
|
287
|
-
if (f[sqlExpressionInProgressKey] && !forceSqlExpression) {
|
|
288
|
-
return "recursive sqlExpression call for field '" + f.key + "'. \0";
|
|
289
|
-
}
|
|
290
|
-
try {
|
|
291
|
-
;
|
|
292
|
-
f[sqlExpressionInProgressKey] = true;
|
|
293
|
-
result = await f.options.sqlExpression(meta);
|
|
294
|
-
if (!result.includes('\0'))
|
|
295
|
-
f.options.sqlExpression = () => result;
|
|
296
|
-
}
|
|
297
|
-
finally {
|
|
298
|
-
delete f[sqlExpressionInProgressKey];
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
else
|
|
302
|
-
result = f.options.sqlExpression;
|
|
303
|
-
if (!result)
|
|
304
|
-
return f.dbName;
|
|
305
|
-
return result;
|
|
306
|
-
}
|
|
307
|
-
const rel = getRelationFieldInfo(f);
|
|
308
|
-
let field = rel?.type === 'toOne' &&
|
|
309
|
-
f.options.field;
|
|
310
|
-
if (field) {
|
|
311
|
-
let fInfo = meta.fields.find(field);
|
|
312
|
-
if (fInfo)
|
|
313
|
-
return fieldDbName(fInfo, meta, wrapIdentifier, forceSqlExpression);
|
|
314
|
-
}
|
|
315
|
-
return wrapIdentifier(f.dbName);
|
|
316
|
-
}
|
|
317
|
-
finally {
|
|
318
|
-
}
|
|
319
|
-
}
|
|
@@ -14,7 +14,8 @@ import { __updateEntityBasedOnWhere } from './__updateEntityBasedOnWhere.js';
|
|
|
14
14
|
import { getRelationFieldInfo, } from './relationInfoMember.js';
|
|
15
15
|
import { RelationLoader } from './relation-loader.js';
|
|
16
16
|
import { getInternalKey, } from './repository-internals.js';
|
|
17
|
-
import { entityDbName
|
|
17
|
+
import { entityDbName } from '../filter/entityDbName.js';
|
|
18
|
+
import { fieldDbName } from '../filter/fieldDbName.js';
|
|
18
19
|
import { remultStatic } from '../remult-static.js';
|
|
19
20
|
import { Validators } from '../validators.js';
|
|
20
21
|
import { addValidator } from './addValidator.js';
|
package/esm/src/validators.js
CHANGED
package/package.json
CHANGED
|
@@ -9,7 +9,6 @@ export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements
|
|
|
9
9
|
put(url: string, data: any): Promise<any>;
|
|
10
10
|
get(url: string): Promise<any>;
|
|
11
11
|
}
|
|
12
|
-
export declare function retry<T>(what: () => Promise<T>): Promise<T>;
|
|
13
12
|
export declare function toPromise<T>(p: Promise<T> | {
|
|
14
13
|
toPromise(): Promise<T>;
|
|
15
14
|
}): Promise<any>;
|
|
@@ -3,15 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.HttpProviderBridgeToRestDataProviderHttpProvider = void 0;
|
|
4
4
|
exports.buildRestDataProvider = buildRestDataProvider;
|
|
5
5
|
exports.isExternalHttpProvider = isExternalHttpProvider;
|
|
6
|
-
exports.retry = retry;
|
|
7
6
|
exports.toPromise = toPromise;
|
|
8
7
|
exports.processHttpException = processHttpException;
|
|
9
8
|
var tslib_1 = require("tslib");
|
|
10
|
-
var
|
|
11
|
-
var
|
|
9
|
+
var rest_data_provider_using_fetch_js_1 = require("./data-providers/rest-data-provider-using-fetch.js");
|
|
10
|
+
var retry_js_1 = require("./data-providers/retry.js");
|
|
12
11
|
function buildRestDataProvider(provider) {
|
|
13
12
|
if (!provider)
|
|
14
|
-
return new
|
|
13
|
+
return new rest_data_provider_using_fetch_js_1.RestDataProviderHttpProviderUsingFetch();
|
|
15
14
|
var httpDataProvider;
|
|
16
15
|
if (!httpDataProvider) {
|
|
17
16
|
if (isExternalHttpProvider(provider)) {
|
|
@@ -20,7 +19,7 @@ function buildRestDataProvider(provider) {
|
|
|
20
19
|
}
|
|
21
20
|
if (!httpDataProvider) {
|
|
22
21
|
if (typeof provider === 'function') {
|
|
23
|
-
httpDataProvider = new
|
|
22
|
+
httpDataProvider = new rest_data_provider_using_fetch_js_1.RestDataProviderHttpProviderUsingFetch(provider);
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
return httpDataProvider;
|
|
@@ -40,7 +39,7 @@ var HttpProviderBridgeToRestDataProviderHttpProvider = /** @class */ (function (
|
|
|
40
39
|
var _this = this;
|
|
41
40
|
return tslib_1.__generator(this, function (_a) {
|
|
42
41
|
switch (_a.label) {
|
|
43
|
-
case 0: return [4 /*yield*/, retry(function () { return toPromise(_this.http.post(url, data)); })];
|
|
42
|
+
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () { return toPromise(_this.http.post(url, data)); })];
|
|
44
43
|
case 1: return [2 /*return*/, _a.sent()];
|
|
45
44
|
}
|
|
46
45
|
});
|
|
@@ -57,7 +56,7 @@ var HttpProviderBridgeToRestDataProviderHttpProvider = /** @class */ (function (
|
|
|
57
56
|
var _this = this;
|
|
58
57
|
return tslib_1.__generator(this, function (_a) {
|
|
59
58
|
switch (_a.label) {
|
|
60
|
-
case 0: return [4 /*yield*/, retry(function () { return toPromise(_this.http.get(url)); })];
|
|
59
|
+
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () { return toPromise(_this.http.get(url)); })];
|
|
61
60
|
case 1: return [2 /*return*/, _a.sent()];
|
|
62
61
|
}
|
|
63
62
|
});
|
|
@@ -66,45 +65,6 @@ var HttpProviderBridgeToRestDataProviderHttpProvider = /** @class */ (function (
|
|
|
66
65
|
return HttpProviderBridgeToRestDataProviderHttpProvider;
|
|
67
66
|
}());
|
|
68
67
|
exports.HttpProviderBridgeToRestDataProviderHttpProvider = HttpProviderBridgeToRestDataProviderHttpProvider;
|
|
69
|
-
function retry(what) {
|
|
70
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
71
|
-
var i, err_1;
|
|
72
|
-
var _a, _b, _c, _d;
|
|
73
|
-
return tslib_1.__generator(this, function (_e) {
|
|
74
|
-
switch (_e.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
i = 0;
|
|
77
|
-
_e.label = 1;
|
|
78
|
-
case 1:
|
|
79
|
-
if (!true) return [3 /*break*/, 8];
|
|
80
|
-
_e.label = 2;
|
|
81
|
-
case 2:
|
|
82
|
-
_e.trys.push([2, 4, , 7]);
|
|
83
|
-
return [4 /*yield*/, what()];
|
|
84
|
-
case 3: return [2 /*return*/, _e.sent()];
|
|
85
|
-
case 4:
|
|
86
|
-
err_1 = _e.sent();
|
|
87
|
-
if (!((((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith('Error occurred while trying to proxy')) ||
|
|
88
|
-
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith('Error occured while trying to proxy')) ||
|
|
89
|
-
((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes('http proxy error')) ||
|
|
90
|
-
((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith('Gateway Timeout')) ||
|
|
91
|
-
err_1.status == 500) &&
|
|
92
|
-
i++ < remult3_js_1.flags.error500RetryCount)) return [3 /*break*/, 6];
|
|
93
|
-
return [4 /*yield*/, new Promise(function (res, req) {
|
|
94
|
-
setTimeout(function () {
|
|
95
|
-
res({});
|
|
96
|
-
}, 500);
|
|
97
|
-
})];
|
|
98
|
-
case 5:
|
|
99
|
-
_e.sent();
|
|
100
|
-
return [3 /*break*/, 1];
|
|
101
|
-
case 6: throw err_1;
|
|
102
|
-
case 7: return [3 /*break*/, 1];
|
|
103
|
-
case 8: return [2 /*return*/];
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
68
|
function toPromise(p) {
|
|
109
69
|
var _this = this;
|
|
110
70
|
var r;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { RestDataProviderHttpProvider } from '../data-interfaces.js';
|
|
2
|
+
export declare class RestDataProviderHttpProviderUsingFetch implements RestDataProviderHttpProvider {
|
|
3
|
+
private fetch?;
|
|
4
|
+
constructor(fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>) | undefined);
|
|
5
|
+
get(url: string): Promise<any>;
|
|
6
|
+
put(url: string, data: any): Promise<any>;
|
|
7
|
+
delete(url: string): Promise<any>;
|
|
8
|
+
post(url: string, data: any): Promise<any>;
|
|
9
|
+
myFetch(url: string, options?: {
|
|
10
|
+
method?: string;
|
|
11
|
+
body?: string;
|
|
12
|
+
}): Promise<any>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RestDataProviderHttpProviderUsingFetch = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var retry_js_1 = require("./retry.js");
|
|
6
|
+
var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
7
|
+
function RestDataProviderHttpProviderUsingFetch(fetch) {
|
|
8
|
+
this.fetch = fetch;
|
|
9
|
+
}
|
|
10
|
+
RestDataProviderHttpProviderUsingFetch.prototype.get = function (url) {
|
|
11
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
12
|
+
var _this = this;
|
|
13
|
+
return tslib_1.__generator(this, function (_a) {
|
|
14
|
+
switch (_a.label) {
|
|
15
|
+
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
16
|
+
return tslib_1.__generator(this, function (_a) {
|
|
17
|
+
return [2 /*return*/, this.myFetch(url).then(function (r) {
|
|
18
|
+
return r;
|
|
19
|
+
})];
|
|
20
|
+
});
|
|
21
|
+
}); })];
|
|
22
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
RestDataProviderHttpProviderUsingFetch.prototype.put = function (url, data) {
|
|
28
|
+
return this.myFetch(url, {
|
|
29
|
+
method: 'put',
|
|
30
|
+
body: JSON.stringify(data),
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
RestDataProviderHttpProviderUsingFetch.prototype.delete = function (url) {
|
|
34
|
+
return this.myFetch(url, { method: 'delete' });
|
|
35
|
+
};
|
|
36
|
+
RestDataProviderHttpProviderUsingFetch.prototype.post = function (url, data) {
|
|
37
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
38
|
+
var _this = this;
|
|
39
|
+
return tslib_1.__generator(this, function (_a) {
|
|
40
|
+
switch (_a.label) {
|
|
41
|
+
case 0: return [4 /*yield*/, (0, retry_js_1.retry)(function () {
|
|
42
|
+
return _this.myFetch(url, {
|
|
43
|
+
method: 'post',
|
|
44
|
+
body: JSON.stringify(data),
|
|
45
|
+
});
|
|
46
|
+
})];
|
|
47
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
RestDataProviderHttpProviderUsingFetch.prototype.myFetch = function (url, options) {
|
|
53
|
+
var e_1, _a;
|
|
54
|
+
var _this = this;
|
|
55
|
+
var headers = {};
|
|
56
|
+
if (options === null || options === void 0 ? void 0 : options.body)
|
|
57
|
+
headers['Content-type'] = 'application/json';
|
|
58
|
+
if (typeof window !== 'undefined' &&
|
|
59
|
+
typeof window.document !== 'undefined' &&
|
|
60
|
+
typeof (window.document.cookie !== 'undefined'))
|
|
61
|
+
try {
|
|
62
|
+
for (var _b = tslib_1.__values(window.document.cookie.split(';')), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
63
|
+
var cookie = _c.value;
|
|
64
|
+
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
65
|
+
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
70
|
+
finally {
|
|
71
|
+
try {
|
|
72
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
73
|
+
}
|
|
74
|
+
finally { if (e_1) throw e_1.error; }
|
|
75
|
+
}
|
|
76
|
+
return (this.fetch || fetch)(url, {
|
|
77
|
+
credentials: 'include',
|
|
78
|
+
method: options === null || options === void 0 ? void 0 : options.method,
|
|
79
|
+
body: options === null || options === void 0 ? void 0 : options.body,
|
|
80
|
+
headers: headers,
|
|
81
|
+
})
|
|
82
|
+
.then(function (response) {
|
|
83
|
+
return onSuccess(response);
|
|
84
|
+
})
|
|
85
|
+
.catch(function (error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
86
|
+
var r;
|
|
87
|
+
return tslib_1.__generator(this, function (_a) {
|
|
88
|
+
switch (_a.label) {
|
|
89
|
+
case 0: return [4 /*yield*/, error];
|
|
90
|
+
case 1:
|
|
91
|
+
r = _a.sent();
|
|
92
|
+
throw r;
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}); });
|
|
96
|
+
};
|
|
97
|
+
return RestDataProviderHttpProviderUsingFetch;
|
|
98
|
+
}());
|
|
99
|
+
exports.RestDataProviderHttpProviderUsingFetch = RestDataProviderHttpProviderUsingFetch;
|
|
100
|
+
function onSuccess(response) {
|
|
101
|
+
if (response.status == 204)
|
|
102
|
+
return;
|
|
103
|
+
if (response.status >= 200 && response.status < 300)
|
|
104
|
+
return response.json();
|
|
105
|
+
else {
|
|
106
|
+
throw response
|
|
107
|
+
.json()
|
|
108
|
+
.then(function (x) {
|
|
109
|
+
return tslib_1.__assign(tslib_1.__assign({}, x), { message: x.message || response.statusText, url: response.url, status: response.status });
|
|
110
|
+
})
|
|
111
|
+
.catch(function () {
|
|
112
|
+
throw {
|
|
113
|
+
message: response.statusText,
|
|
114
|
+
url: response.url,
|
|
115
|
+
status: response.status,
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -39,17 +39,5 @@ export declare class RestEntityDataProvider implements EntityDataProvider, Proxy
|
|
|
39
39
|
insert(data: any): Promise<any>;
|
|
40
40
|
insertMany(data: any[]): Promise<any[]>;
|
|
41
41
|
}
|
|
42
|
-
export declare class RestDataProviderHttpProviderUsingFetch implements RestDataProviderHttpProvider {
|
|
43
|
-
private fetch?;
|
|
44
|
-
constructor(fetch?: ((input: RequestInfo, init?: RequestInit) => Promise<Response>) | undefined);
|
|
45
|
-
get(url: string): Promise<any>;
|
|
46
|
-
put(url: string, data: any): Promise<any>;
|
|
47
|
-
delete(url: string): Promise<any>;
|
|
48
|
-
post(url: string, data: any): Promise<any>;
|
|
49
|
-
myFetch(url: string, options?: {
|
|
50
|
-
method?: string;
|
|
51
|
-
body?: string;
|
|
52
|
-
}): Promise<any>;
|
|
53
|
-
}
|
|
54
42
|
export declare function addFilterToUrlAndReturnTrueIfSuccessful(filter: any, url: UrlBuilder): boolean;
|
|
55
43
|
export declare const liveQueryAction = "liveQuery-";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.liveQueryAction = exports.
|
|
3
|
+
exports.liveQueryAction = exports.RestEntityDataProvider = exports.RestDataProvider = void 0;
|
|
4
4
|
exports.buildFullUrl = buildFullUrl;
|
|
5
5
|
exports.findOptionsToJson = findOptionsToJson;
|
|
6
6
|
exports.findOptionsFromJson = findOptionsFromJson;
|
|
@@ -411,120 +411,6 @@ var RestEntityDataProvider = /** @class */ (function () {
|
|
|
411
411
|
return RestEntityDataProvider;
|
|
412
412
|
}());
|
|
413
413
|
exports.RestEntityDataProvider = RestEntityDataProvider;
|
|
414
|
-
var RestDataProviderHttpProviderUsingFetch = /** @class */ (function () {
|
|
415
|
-
function RestDataProviderHttpProviderUsingFetch(fetch) {
|
|
416
|
-
this.fetch = fetch;
|
|
417
|
-
}
|
|
418
|
-
RestDataProviderHttpProviderUsingFetch.prototype.get = function (url) {
|
|
419
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
420
|
-
var _this = this;
|
|
421
|
-
return tslib_1.__generator(this, function (_a) {
|
|
422
|
-
switch (_a.label) {
|
|
423
|
-
case 0: return [4 /*yield*/, (0, buildRestDataProvider_js_1.retry)(function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
424
|
-
return tslib_1.__generator(this, function (_a) {
|
|
425
|
-
return [2 /*return*/, this.myFetch(url).then(function (r) {
|
|
426
|
-
return r;
|
|
427
|
-
})];
|
|
428
|
-
});
|
|
429
|
-
}); })];
|
|
430
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
431
|
-
}
|
|
432
|
-
});
|
|
433
|
-
});
|
|
434
|
-
};
|
|
435
|
-
RestDataProviderHttpProviderUsingFetch.prototype.put = function (url, data) {
|
|
436
|
-
return this.myFetch(url, {
|
|
437
|
-
method: 'put',
|
|
438
|
-
body: JSON.stringify(data),
|
|
439
|
-
});
|
|
440
|
-
};
|
|
441
|
-
RestDataProviderHttpProviderUsingFetch.prototype.delete = function (url) {
|
|
442
|
-
return this.myFetch(url, { method: 'delete' });
|
|
443
|
-
};
|
|
444
|
-
RestDataProviderHttpProviderUsingFetch.prototype.post = function (url, data) {
|
|
445
|
-
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
446
|
-
var _this = this;
|
|
447
|
-
return tslib_1.__generator(this, function (_a) {
|
|
448
|
-
switch (_a.label) {
|
|
449
|
-
case 0: return [4 /*yield*/, (0, buildRestDataProvider_js_1.retry)(function () {
|
|
450
|
-
return _this.myFetch(url, {
|
|
451
|
-
method: 'post',
|
|
452
|
-
body: JSON.stringify(data),
|
|
453
|
-
});
|
|
454
|
-
})];
|
|
455
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
456
|
-
}
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
};
|
|
460
|
-
RestDataProviderHttpProviderUsingFetch.prototype.myFetch = function (url, options) {
|
|
461
|
-
var e_6, _a;
|
|
462
|
-
var _this = this;
|
|
463
|
-
var headers = {};
|
|
464
|
-
if (options === null || options === void 0 ? void 0 : options.body)
|
|
465
|
-
headers['Content-type'] = 'application/json';
|
|
466
|
-
if (typeof window !== 'undefined' &&
|
|
467
|
-
typeof window.document !== 'undefined' &&
|
|
468
|
-
typeof (window.document.cookie !== 'undefined'))
|
|
469
|
-
try {
|
|
470
|
-
for (var _b = tslib_1.__values(window.document.cookie.split(';')), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
471
|
-
var cookie = _c.value;
|
|
472
|
-
if (cookie.trim().startsWith('XSRF-TOKEN=')) {
|
|
473
|
-
headers['X-XSRF-TOKEN'] = cookie.split('=')[1];
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
478
|
-
finally {
|
|
479
|
-
try {
|
|
480
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
481
|
-
}
|
|
482
|
-
finally { if (e_6) throw e_6.error; }
|
|
483
|
-
}
|
|
484
|
-
return (this.fetch || fetch)(url, {
|
|
485
|
-
credentials: 'include',
|
|
486
|
-
method: options === null || options === void 0 ? void 0 : options.method,
|
|
487
|
-
body: options === null || options === void 0 ? void 0 : options.body,
|
|
488
|
-
headers: headers,
|
|
489
|
-
})
|
|
490
|
-
.then(function (response) {
|
|
491
|
-
return onSuccess(response);
|
|
492
|
-
})
|
|
493
|
-
.catch(function (error) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
494
|
-
var r;
|
|
495
|
-
return tslib_1.__generator(this, function (_a) {
|
|
496
|
-
switch (_a.label) {
|
|
497
|
-
case 0: return [4 /*yield*/, error];
|
|
498
|
-
case 1:
|
|
499
|
-
r = _a.sent();
|
|
500
|
-
throw r;
|
|
501
|
-
}
|
|
502
|
-
});
|
|
503
|
-
}); });
|
|
504
|
-
};
|
|
505
|
-
return RestDataProviderHttpProviderUsingFetch;
|
|
506
|
-
}());
|
|
507
|
-
exports.RestDataProviderHttpProviderUsingFetch = RestDataProviderHttpProviderUsingFetch;
|
|
508
|
-
function onSuccess(response) {
|
|
509
|
-
if (response.status == 204)
|
|
510
|
-
return;
|
|
511
|
-
if (response.status >= 200 && response.status < 300)
|
|
512
|
-
return response.json();
|
|
513
|
-
else {
|
|
514
|
-
throw response
|
|
515
|
-
.json()
|
|
516
|
-
.then(function (x) {
|
|
517
|
-
return tslib_1.__assign(tslib_1.__assign({}, x), { message: x.message || response.statusText, url: response.url, status: response.status });
|
|
518
|
-
})
|
|
519
|
-
.catch(function () {
|
|
520
|
-
throw {
|
|
521
|
-
message: response.statusText,
|
|
522
|
-
url: response.url,
|
|
523
|
-
status: response.status,
|
|
524
|
-
};
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
414
|
function addFilterToUrlAndReturnTrueIfSuccessful(filter, url) {
|
|
529
415
|
for (var key in filter) {
|
|
530
416
|
if (Object.prototype.hasOwnProperty.call(filter, key)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function retry<T>(what: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.retry = retry;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var remult3_js_1 = require("../remult3/remult3.js");
|
|
6
|
+
function retry(what) {
|
|
7
|
+
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
8
|
+
var i, err_1;
|
|
9
|
+
var _a, _b, _c, _d;
|
|
10
|
+
return tslib_1.__generator(this, function (_e) {
|
|
11
|
+
switch (_e.label) {
|
|
12
|
+
case 0:
|
|
13
|
+
i = 0;
|
|
14
|
+
_e.label = 1;
|
|
15
|
+
case 1:
|
|
16
|
+
if (!true) return [3 /*break*/, 8];
|
|
17
|
+
_e.label = 2;
|
|
18
|
+
case 2:
|
|
19
|
+
_e.trys.push([2, 4, , 7]);
|
|
20
|
+
return [4 /*yield*/, what()];
|
|
21
|
+
case 3: return [2 /*return*/, _e.sent()];
|
|
22
|
+
case 4:
|
|
23
|
+
err_1 = _e.sent();
|
|
24
|
+
if (!((((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith('Error occurred while trying to proxy')) ||
|
|
25
|
+
((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith('Error occured while trying to proxy')) ||
|
|
26
|
+
((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.includes('http proxy error')) ||
|
|
27
|
+
((_d = err_1.message) === null || _d === void 0 ? void 0 : _d.startsWith('Gateway Timeout')) ||
|
|
28
|
+
err_1.status == 500) &&
|
|
29
|
+
i++ < remult3_js_1.flags.error500RetryCount)) return [3 /*break*/, 6];
|
|
30
|
+
return [4 /*yield*/, new Promise(function (res, req) {
|
|
31
|
+
setTimeout(function () {
|
|
32
|
+
res({});
|
|
33
|
+
}, 500);
|
|
34
|
+
})];
|
|
35
|
+
case 5:
|
|
36
|
+
_e.sent();
|
|
37
|
+
return [3 /*break*/, 1];
|
|
38
|
+
case 6: throw err_1;
|
|
39
|
+
case 7: return [3 /*break*/, 1];
|
|
40
|
+
case 8: return [2 /*return*/];
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.entityDbName = entityDbName;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
function entityDbName(metadata_1) {
|
|
6
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (metadata, wrapIdentifier) {
|
|
7
|
+
var prev;
|
|
8
|
+
if (wrapIdentifier === void 0) { wrapIdentifier = function (x) { return x; }; }
|
|
9
|
+
return tslib_1.__generator(this, function (_a) {
|
|
10
|
+
switch (_a.label) {
|
|
11
|
+
case 0:
|
|
12
|
+
if (!metadata.options.sqlExpression) return [3 /*break*/, 5];
|
|
13
|
+
if (!(typeof metadata.options.sqlExpression === 'string')) return [3 /*break*/, 1];
|
|
14
|
+
return [2 /*return*/, metadata.options.sqlExpression];
|
|
15
|
+
case 1:
|
|
16
|
+
if (!(typeof metadata.options.sqlExpression === 'function')) return [3 /*break*/, 5];
|
|
17
|
+
prev = metadata.options.sqlExpression;
|
|
18
|
+
_a.label = 2;
|
|
19
|
+
case 2:
|
|
20
|
+
_a.trys.push([2, , 4, 5]);
|
|
21
|
+
metadata.options.sqlExpression =
|
|
22
|
+
"recursive sqlExpression call for entity '" + metadata.key + "'. ";
|
|
23
|
+
return [4 /*yield*/, prev(metadata)];
|
|
24
|
+
case 3: return [2 /*return*/, _a.sent()];
|
|
25
|
+
case 4:
|
|
26
|
+
metadata.options.sqlExpression = prev;
|
|
27
|
+
return [7 /*endfinally*/];
|
|
28
|
+
case 5: return [2 /*return*/, wrapIdentifier(metadata.dbName)];
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { EntityMetadata } from "../remult3/remult3.js";
|
|
2
|
+
import type { FieldMetadata } from '../column-interfaces.js';
|
|
3
|
+
export declare function fieldDbName(f: FieldMetadata, meta: EntityMetadata, wrapIdentifier?: (name: string) => string, forceSqlExpression?: boolean): Promise<string>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fieldDbName = fieldDbName;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var relationInfoMember_js_1 = require("../remult3/relationInfoMember.js");
|
|
6
|
+
var sqlExpressionInProgressKey = Symbol.for("sqlExpressionInProgressKey");
|
|
7
|
+
function fieldDbName(f_1, meta_1) {
|
|
8
|
+
return tslib_1.__awaiter(this, arguments, void 0, function (f, meta, wrapIdentifier, forceSqlExpression) {
|
|
9
|
+
var result_1, rel, field, fInfo;
|
|
10
|
+
if (wrapIdentifier === void 0) { wrapIdentifier = function (x) { return x; }; }
|
|
11
|
+
if (forceSqlExpression === void 0) { forceSqlExpression = false; }
|
|
12
|
+
return tslib_1.__generator(this, function (_a) {
|
|
13
|
+
switch (_a.label) {
|
|
14
|
+
case 0:
|
|
15
|
+
_a.trys.push([0, , 8, 9]);
|
|
16
|
+
if (!f.options.sqlExpression) return [3 /*break*/, 7];
|
|
17
|
+
if (!(typeof f.options.sqlExpression === 'function')) return [3 /*break*/, 5];
|
|
18
|
+
if (f[sqlExpressionInProgressKey] && !forceSqlExpression) {
|
|
19
|
+
return [2 /*return*/, "recursive sqlExpression call for field '" + f.key + "'. \0"];
|
|
20
|
+
}
|
|
21
|
+
_a.label = 1;
|
|
22
|
+
case 1:
|
|
23
|
+
_a.trys.push([1, , 3, 4]);
|
|
24
|
+
;
|
|
25
|
+
f[sqlExpressionInProgressKey] = true;
|
|
26
|
+
return [4 /*yield*/, f.options.sqlExpression(meta)];
|
|
27
|
+
case 2:
|
|
28
|
+
result_1 = _a.sent();
|
|
29
|
+
if (!result_1.includes('\0'))
|
|
30
|
+
f.options.sqlExpression = function () { return result_1; };
|
|
31
|
+
return [3 /*break*/, 4];
|
|
32
|
+
case 3:
|
|
33
|
+
delete f[sqlExpressionInProgressKey];
|
|
34
|
+
return [7 /*endfinally*/];
|
|
35
|
+
case 4: return [3 /*break*/, 6];
|
|
36
|
+
case 5:
|
|
37
|
+
result_1 = f.options.sqlExpression;
|
|
38
|
+
_a.label = 6;
|
|
39
|
+
case 6:
|
|
40
|
+
if (!result_1)
|
|
41
|
+
return [2 /*return*/, f.dbName];
|
|
42
|
+
return [2 /*return*/, result_1];
|
|
43
|
+
case 7:
|
|
44
|
+
rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(f);
|
|
45
|
+
field = (rel === null || rel === void 0 ? void 0 : rel.type) === 'toOne' &&
|
|
46
|
+
f.options.field;
|
|
47
|
+
if (field) {
|
|
48
|
+
fInfo = meta.fields.find(field);
|
|
49
|
+
if (fInfo)
|
|
50
|
+
return [2 /*return*/, fieldDbName(fInfo, meta, wrapIdentifier, forceSqlExpression)];
|
|
51
|
+
}
|
|
52
|
+
return [2 /*return*/, wrapIdentifier(f.dbName)];
|
|
53
|
+
case 8: return [7 /*endfinally*/];
|
|
54
|
+
case 9: return [2 /*return*/];
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
@@ -84,5 +84,3 @@ export interface dbNamesOfOptions {
|
|
|
84
84
|
}
|
|
85
85
|
export declare function dbNamesOf<entityType>(repo: EntityMetadataOverloads<entityType>, wrapIdentifierOrOptions?: ((name: string) => string) | dbNamesOfOptions): Promise<EntityDbNames<entityType>>;
|
|
86
86
|
export declare function dbNamesOfWithForceSqlExpression<entityType>(repo: EntityMetadataOverloads<entityType>, wrapIdentifierOrOptions?: ((name: string) => string) | dbNamesOfOptions): Promise<EntityDbNames<entityType>>;
|
|
87
|
-
export declare function entityDbName(metadata: EntityMetadata, wrapIdentifier?: (name: string) => string): Promise<string>;
|
|
88
|
-
export declare function fieldDbName(f: FieldMetadata, meta: EntityMetadata, wrapIdentifier?: (name: string) => string, forceSqlExpression?: boolean): Promise<string>;
|
|
@@ -6,13 +6,12 @@ exports.shouldNotCreateField = shouldNotCreateField;
|
|
|
6
6
|
exports.shouldCreateEntity = shouldCreateEntity;
|
|
7
7
|
exports.dbNamesOf = dbNamesOf;
|
|
8
8
|
exports.dbNamesOfWithForceSqlExpression = dbNamesOfWithForceSqlExpression;
|
|
9
|
-
exports.entityDbName = entityDbName;
|
|
10
|
-
exports.fieldDbName = fieldDbName;
|
|
11
9
|
var tslib_1 = require("tslib");
|
|
12
10
|
var sql_database_js_1 = require("../data-providers/sql-database.js");
|
|
13
11
|
var remult_proxy_js_1 = require("../remult-proxy.js");
|
|
14
12
|
var RepositoryImplementation_js_1 = require("../remult3/RepositoryImplementation.js");
|
|
15
|
-
var
|
|
13
|
+
var entityDbName_js_1 = require("./entityDbName.js");
|
|
14
|
+
var fieldDbName_js_1 = require("./fieldDbName.js");
|
|
16
15
|
var FilterConsumerBridgeToSqlRequest = /** @class */ (function () {
|
|
17
16
|
function FilterConsumerBridgeToSqlRequest(r, nameProvider) {
|
|
18
17
|
this.r = r;
|
|
@@ -379,7 +378,7 @@ function internalDbNamesOf(repo_1, wrapIdentifierOrOptions_1) {
|
|
|
379
378
|
if (!options.wrapIdentifier)
|
|
380
379
|
options.wrapIdentifier = function (x) { return x; };
|
|
381
380
|
_c = {};
|
|
382
|
-
return [4 /*yield*/, entityDbName(meta, options.wrapIdentifier)];
|
|
381
|
+
return [4 /*yield*/, (0, entityDbName_js_1.entityDbName)(meta, options.wrapIdentifier)];
|
|
383
382
|
case 1:
|
|
384
383
|
result = (_c.$entityName = _e.sent(),
|
|
385
384
|
_c.toString = function () { return result.$entityName; },
|
|
@@ -401,7 +400,7 @@ function internalDbNamesOf(repo_1, wrapIdentifierOrOptions_1) {
|
|
|
401
400
|
case 3:
|
|
402
401
|
if (!!_b.done) return [3 /*break*/, 6];
|
|
403
402
|
field = _b.value;
|
|
404
|
-
return [4 /*yield*/, fieldDbName(field, meta, options.wrapIdentifier, forceSqlExpression)];
|
|
403
|
+
return [4 /*yield*/, (0, fieldDbName_js_1.fieldDbName)(field, meta, options.wrapIdentifier, forceSqlExpression)];
|
|
405
404
|
case 4:
|
|
406
405
|
r = _e.sent();
|
|
407
406
|
if (!field.options.sqlExpression)
|
|
@@ -432,84 +431,3 @@ function internalDbNamesOf(repo_1, wrapIdentifierOrOptions_1) {
|
|
|
432
431
|
});
|
|
433
432
|
});
|
|
434
433
|
}
|
|
435
|
-
function entityDbName(metadata_1) {
|
|
436
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (metadata, wrapIdentifier) {
|
|
437
|
-
var prev;
|
|
438
|
-
if (wrapIdentifier === void 0) { wrapIdentifier = function (x) { return x; }; }
|
|
439
|
-
return tslib_1.__generator(this, function (_a) {
|
|
440
|
-
switch (_a.label) {
|
|
441
|
-
case 0:
|
|
442
|
-
if (!metadata.options.sqlExpression) return [3 /*break*/, 5];
|
|
443
|
-
if (!(typeof metadata.options.sqlExpression === 'string')) return [3 /*break*/, 1];
|
|
444
|
-
return [2 /*return*/, metadata.options.sqlExpression];
|
|
445
|
-
case 1:
|
|
446
|
-
if (!(typeof metadata.options.sqlExpression === 'function')) return [3 /*break*/, 5];
|
|
447
|
-
prev = metadata.options.sqlExpression;
|
|
448
|
-
_a.label = 2;
|
|
449
|
-
case 2:
|
|
450
|
-
_a.trys.push([2, , 4, 5]);
|
|
451
|
-
metadata.options.sqlExpression =
|
|
452
|
-
"recursive sqlExpression call for entity '" + metadata.key + "'. ";
|
|
453
|
-
return [4 /*yield*/, prev(metadata)];
|
|
454
|
-
case 3: return [2 /*return*/, _a.sent()];
|
|
455
|
-
case 4:
|
|
456
|
-
metadata.options.sqlExpression = prev;
|
|
457
|
-
return [7 /*endfinally*/];
|
|
458
|
-
case 5: return [2 /*return*/, wrapIdentifier(metadata.dbName)];
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
var sqlExpressionInProgressKey = Symbol.for("sqlExpressionInProgressKey");
|
|
464
|
-
function fieldDbName(f_1, meta_1) {
|
|
465
|
-
return tslib_1.__awaiter(this, arguments, void 0, function (f, meta, wrapIdentifier, forceSqlExpression) {
|
|
466
|
-
var result_1, rel, field, fInfo;
|
|
467
|
-
if (wrapIdentifier === void 0) { wrapIdentifier = function (x) { return x; }; }
|
|
468
|
-
if (forceSqlExpression === void 0) { forceSqlExpression = false; }
|
|
469
|
-
return tslib_1.__generator(this, function (_a) {
|
|
470
|
-
switch (_a.label) {
|
|
471
|
-
case 0:
|
|
472
|
-
_a.trys.push([0, , 8, 9]);
|
|
473
|
-
if (!f.options.sqlExpression) return [3 /*break*/, 7];
|
|
474
|
-
if (!(typeof f.options.sqlExpression === 'function')) return [3 /*break*/, 5];
|
|
475
|
-
if (f[sqlExpressionInProgressKey] && !forceSqlExpression) {
|
|
476
|
-
return [2 /*return*/, "recursive sqlExpression call for field '" + f.key + "'. \0"];
|
|
477
|
-
}
|
|
478
|
-
_a.label = 1;
|
|
479
|
-
case 1:
|
|
480
|
-
_a.trys.push([1, , 3, 4]);
|
|
481
|
-
;
|
|
482
|
-
f[sqlExpressionInProgressKey] = true;
|
|
483
|
-
return [4 /*yield*/, f.options.sqlExpression(meta)];
|
|
484
|
-
case 2:
|
|
485
|
-
result_1 = _a.sent();
|
|
486
|
-
if (!result_1.includes('\0'))
|
|
487
|
-
f.options.sqlExpression = function () { return result_1; };
|
|
488
|
-
return [3 /*break*/, 4];
|
|
489
|
-
case 3:
|
|
490
|
-
delete f[sqlExpressionInProgressKey];
|
|
491
|
-
return [7 /*endfinally*/];
|
|
492
|
-
case 4: return [3 /*break*/, 6];
|
|
493
|
-
case 5:
|
|
494
|
-
result_1 = f.options.sqlExpression;
|
|
495
|
-
_a.label = 6;
|
|
496
|
-
case 6:
|
|
497
|
-
if (!result_1)
|
|
498
|
-
return [2 /*return*/, f.dbName];
|
|
499
|
-
return [2 /*return*/, result_1];
|
|
500
|
-
case 7:
|
|
501
|
-
rel = (0, relationInfoMember_js_1.getRelationFieldInfo)(f);
|
|
502
|
-
field = (rel === null || rel === void 0 ? void 0 : rel.type) === 'toOne' &&
|
|
503
|
-
f.options.field;
|
|
504
|
-
if (field) {
|
|
505
|
-
fInfo = meta.fields.find(field);
|
|
506
|
-
if (fInfo)
|
|
507
|
-
return [2 /*return*/, fieldDbName(fInfo, meta, wrapIdentifier, forceSqlExpression)];
|
|
508
|
-
}
|
|
509
|
-
return [2 /*return*/, wrapIdentifier(f.dbName)];
|
|
510
|
-
case 8: return [7 /*endfinally*/];
|
|
511
|
-
case 9: return [2 /*return*/];
|
|
512
|
-
}
|
|
513
|
-
});
|
|
514
|
-
});
|
|
515
|
-
}
|
|
@@ -30,7 +30,8 @@ var __updateEntityBasedOnWhere_js_1 = require("./__updateEntityBasedOnWhere.js")
|
|
|
30
30
|
var relationInfoMember_js_1 = require("./relationInfoMember.js");
|
|
31
31
|
var relation_loader_js_1 = require("./relation-loader.js");
|
|
32
32
|
var repository_internals_js_1 = require("./repository-internals.js");
|
|
33
|
-
var
|
|
33
|
+
var entityDbName_js_1 = require("../filter/entityDbName.js");
|
|
34
|
+
var fieldDbName_js_1 = require("../filter/fieldDbName.js");
|
|
34
35
|
var remult_static_js_1 = require("../remult-static.js");
|
|
35
36
|
var validators_js_1 = require("../validators.js");
|
|
36
37
|
var addValidator_js_1 = require("./addValidator.js");
|
|
@@ -3433,7 +3434,7 @@ var columnDefsImpl = /** @class */ (function () {
|
|
|
3433
3434
|
columnDefsImpl.prototype.getDbName = function () {
|
|
3434
3435
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
3435
3436
|
return tslib_1.__generator(this, function (_a) {
|
|
3436
|
-
return [2 /*return*/, (0,
|
|
3437
|
+
return [2 /*return*/, (0, fieldDbName_js_1.fieldDbName)(this, this.entityDefs)];
|
|
3437
3438
|
});
|
|
3438
3439
|
});
|
|
3439
3440
|
};
|
|
@@ -3624,7 +3625,7 @@ var EntityFullInfo = /** @class */ (function () {
|
|
|
3624
3625
|
return this.remult.repo(this.entityType).getEntityRef(tslib_1.__assign({}, item));
|
|
3625
3626
|
};
|
|
3626
3627
|
EntityFullInfo.prototype.getDbName = function () {
|
|
3627
|
-
return (0,
|
|
3628
|
+
return (0, entityDbName_js_1.entityDbName)(this);
|
|
3628
3629
|
};
|
|
3629
3630
|
return EntityFullInfo;
|
|
3630
3631
|
}());
|
package/src/validators.js
CHANGED
|
@@ -8,7 +8,7 @@ exports.createValueValidatorWithArgs = createValueValidatorWithArgs;
|
|
|
8
8
|
exports.createValidatorWithArgs = createValidatorWithArgs;
|
|
9
9
|
exports.getEnumValues = getEnumValues;
|
|
10
10
|
var tslib_1 = require("tslib");
|
|
11
|
-
var
|
|
11
|
+
var relationInfoMember_js_1 = require("../src/remult3/relationInfoMember.js");
|
|
12
12
|
/**
|
|
13
13
|
* Class containing various field validators.
|
|
14
14
|
*/
|
|
@@ -24,7 +24,7 @@ var Validators = /** @class */ (function () {
|
|
|
24
24
|
return tslib_1.__generator(_a, function (_b) {
|
|
25
25
|
return [2 /*return*/, !e.valueIsNull() &&
|
|
26
26
|
e.value !== '' &&
|
|
27
|
-
(e.value !== undefined || (0,
|
|
27
|
+
(e.value !== undefined || (0, relationInfoMember_js_1.getRelationFieldInfo)(e.metadata) !== undefined)];
|
|
28
28
|
});
|
|
29
29
|
}); }, 'Should not be empty');
|
|
30
30
|
/**
|