@centia-io/sdk 0.0.42 → 0.0.43
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/LICENSE +21 -21
- package/README.md +570 -570
- package/dist/centia-io-sdk.cjs +115 -252
- package/dist/centia-io-sdk.d.cts +67 -117
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +67 -117
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +116 -252
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +1244 -1381
- package/package.json +36 -36
package/dist/centia-io-sdk.js
CHANGED
|
@@ -79,12 +79,6 @@ function getStorage() {
|
|
|
79
79
|
|
|
80
80
|
//#endregion
|
|
81
81
|
//#region src/util/utils.ts
|
|
82
|
-
/**
|
|
83
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
84
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
85
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
86
|
-
*
|
|
87
|
-
*/
|
|
88
82
|
const generatePkceChallenge = async () => {
|
|
89
83
|
const generateRandomString = () => {
|
|
90
84
|
const array = new Uint32Array(28);
|
|
@@ -166,8 +160,7 @@ const setOptions = (options) => {
|
|
|
166
160
|
getStorage().setItem("gc2_options", JSON.stringify({
|
|
167
161
|
"clientId": options.clientId,
|
|
168
162
|
"host": options.host,
|
|
169
|
-
"redirectUri": options.redirectUri
|
|
170
|
-
"clientSecret": options.clientSecret || null
|
|
163
|
+
"redirectUri": options.redirectUri
|
|
171
164
|
}));
|
|
172
165
|
};
|
|
173
166
|
const getOptions = () => {
|
|
@@ -194,12 +187,6 @@ const clearNonce = () => {
|
|
|
194
187
|
|
|
195
188
|
//#endregion
|
|
196
189
|
//#region src/services/gc2.services.ts
|
|
197
|
-
/**
|
|
198
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
199
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
200
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
201
|
-
*
|
|
202
|
-
*/
|
|
203
190
|
var Gc2Service = class {
|
|
204
191
|
constructor(options) {
|
|
205
192
|
this.options = options;
|
|
@@ -335,12 +322,6 @@ var Gc2Service = class {
|
|
|
335
322
|
|
|
336
323
|
//#endregion
|
|
337
324
|
//#region src/CodeFlow.ts
|
|
338
|
-
/**
|
|
339
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
340
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
341
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
342
|
-
*
|
|
343
|
-
*/
|
|
344
325
|
var CodeFlow = class {
|
|
345
326
|
constructor(options) {
|
|
346
327
|
this.options = options;
|
|
@@ -399,12 +380,6 @@ var CodeFlow = class {
|
|
|
399
380
|
|
|
400
381
|
//#endregion
|
|
401
382
|
//#region src/PasswordFlow.ts
|
|
402
|
-
/**
|
|
403
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
404
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
405
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
406
|
-
*
|
|
407
|
-
*/
|
|
408
383
|
var PasswordFlow = class {
|
|
409
384
|
constructor(options) {
|
|
410
385
|
this.options = options;
|
|
@@ -419,8 +394,7 @@ var PasswordFlow = class {
|
|
|
419
394
|
setOptions({
|
|
420
395
|
clientId: this.options.clientId,
|
|
421
396
|
host: this.options.host,
|
|
422
|
-
redirectUri: ""
|
|
423
|
-
clientSecret: this.options.clientSecret
|
|
397
|
+
redirectUri: ""
|
|
424
398
|
});
|
|
425
399
|
}
|
|
426
400
|
signOut() {
|
|
@@ -435,12 +409,6 @@ var PasswordFlow = class {
|
|
|
435
409
|
|
|
436
410
|
//#endregion
|
|
437
411
|
//#region src/util/request-headers.ts
|
|
438
|
-
/**
|
|
439
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
440
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
441
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
442
|
-
*
|
|
443
|
-
*/
|
|
444
412
|
const getHeaders = async (contentType = "application/json") => {
|
|
445
413
|
if (!await isLogin(new Gc2Service(getOptions()))) return Promise.reject("Is not logged in");
|
|
446
414
|
const { accessToken } = getTokens();
|
|
@@ -456,12 +424,6 @@ var request_headers_default = getHeaders;
|
|
|
456
424
|
|
|
457
425
|
//#endregion
|
|
458
426
|
//#region src/util/make-request.ts
|
|
459
|
-
/**
|
|
460
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
461
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
462
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
463
|
-
*
|
|
464
|
-
*/
|
|
465
427
|
const make = async (version, resource, method, payload, contentType = "application/json") => {
|
|
466
428
|
const options = getOptions();
|
|
467
429
|
let request = {
|
|
@@ -470,19 +432,12 @@ const make = async (version, resource, method, payload, contentType = "applicati
|
|
|
470
432
|
redirect: "manual"
|
|
471
433
|
};
|
|
472
434
|
if (payload) request.body = contentType === "application/json" ? JSON.stringify(payload) : payload;
|
|
473
|
-
|
|
474
|
-
else return await fetch(options.host + `/api/${resource}`, request);
|
|
435
|
+
return await fetch(options.host + `/api/v${version}/${resource}`, request);
|
|
475
436
|
};
|
|
476
437
|
var make_request_default = make;
|
|
477
438
|
|
|
478
439
|
//#endregion
|
|
479
440
|
//#region src/util/get-response.ts
|
|
480
|
-
/**
|
|
481
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
482
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
483
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
484
|
-
*
|
|
485
|
-
*/
|
|
486
441
|
const get = async (response, expectedCode) => {
|
|
487
442
|
let res = null;
|
|
488
443
|
let bodyText = "";
|
|
@@ -502,12 +457,6 @@ var get_response_default = get;
|
|
|
502
457
|
|
|
503
458
|
//#endregion
|
|
504
459
|
//#region src/Sql.ts
|
|
505
|
-
/**
|
|
506
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
507
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
508
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
509
|
-
*
|
|
510
|
-
*/
|
|
511
460
|
var Sql = class {
|
|
512
461
|
async exec(request) {
|
|
513
462
|
return await get_response_default(await make_request_default("4", `sql`, "POST", request), 200);
|
|
@@ -516,43 +465,14 @@ var Sql = class {
|
|
|
516
465
|
|
|
517
466
|
//#endregion
|
|
518
467
|
//#region src/Rpc.ts
|
|
519
|
-
/**
|
|
520
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
521
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
522
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
523
|
-
*
|
|
524
|
-
*/
|
|
525
468
|
var Rpc = class {
|
|
526
469
|
async call(request) {
|
|
527
470
|
return await get_response_default(await make_request_default("4", `call`, "POST", request), 200);
|
|
528
471
|
}
|
|
529
472
|
};
|
|
530
473
|
|
|
531
|
-
//#endregion
|
|
532
|
-
//#region src/Gql.ts
|
|
533
|
-
/**
|
|
534
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
535
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
536
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
537
|
-
*
|
|
538
|
-
*/
|
|
539
|
-
var Gql = class {
|
|
540
|
-
constructor(schema) {
|
|
541
|
-
this.schema = schema;
|
|
542
|
-
}
|
|
543
|
-
async request(request) {
|
|
544
|
-
return await get_response_default(await make_request_default(null, `graphql/schema/${this.schema}`, "POST", request), 200);
|
|
545
|
-
}
|
|
546
|
-
};
|
|
547
|
-
|
|
548
474
|
//#endregion
|
|
549
475
|
//#region src/Meta.ts
|
|
550
|
-
/**
|
|
551
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
552
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
553
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
554
|
-
*
|
|
555
|
-
*/
|
|
556
476
|
var Meta = class {
|
|
557
477
|
async query(rel) {
|
|
558
478
|
return await get_response_default(await make_request_default("3", `meta/${rel}`, "GET", null), 200);
|
|
@@ -561,12 +481,6 @@ var Meta = class {
|
|
|
561
481
|
|
|
562
482
|
//#endregion
|
|
563
483
|
//#region src/Status.ts
|
|
564
|
-
/**
|
|
565
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
566
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
567
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
568
|
-
*
|
|
569
|
-
*/
|
|
570
484
|
var Status = class {
|
|
571
485
|
isAuth() {
|
|
572
486
|
const tokens = getTokens();
|
|
@@ -579,12 +493,6 @@ var Status = class {
|
|
|
579
493
|
|
|
580
494
|
//#endregion
|
|
581
495
|
//#region src/Claims.ts
|
|
582
|
-
/**
|
|
583
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
584
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
585
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
586
|
-
*
|
|
587
|
-
*/
|
|
588
496
|
var Claims = class {
|
|
589
497
|
get() {
|
|
590
498
|
const tokens = getTokens().accessToken;
|
|
@@ -594,12 +502,6 @@ var Claims = class {
|
|
|
594
502
|
|
|
595
503
|
//#endregion
|
|
596
504
|
//#region src/Users.ts
|
|
597
|
-
/**
|
|
598
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
599
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
600
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
601
|
-
*
|
|
602
|
-
*/
|
|
603
505
|
var Users = class {
|
|
604
506
|
async get(user) {
|
|
605
507
|
return await get_response_default(await make_request_default("4", `users/${user}`, "GET", null), 200);
|
|
@@ -608,12 +510,6 @@ var Users = class {
|
|
|
608
510
|
|
|
609
511
|
//#endregion
|
|
610
512
|
//#region src/Ws.ts
|
|
611
|
-
/**
|
|
612
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
613
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
614
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
615
|
-
*
|
|
616
|
-
*/
|
|
617
513
|
var Ws = class {
|
|
618
514
|
constructor(options) {
|
|
619
515
|
this.options = options;
|
|
@@ -650,12 +546,6 @@ var Ws = class {
|
|
|
650
546
|
|
|
651
547
|
//#endregion
|
|
652
548
|
//#region src/Stats.ts
|
|
653
|
-
/**
|
|
654
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
655
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
656
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
657
|
-
*
|
|
658
|
-
*/
|
|
659
549
|
var Stats = class {
|
|
660
550
|
async get() {
|
|
661
551
|
return await get_response_default(await make_request_default("4", `stats`, "GET", null), 200);
|
|
@@ -664,12 +554,6 @@ var Stats = class {
|
|
|
664
554
|
|
|
665
555
|
//#endregion
|
|
666
556
|
//#region src/Tables.ts
|
|
667
|
-
/**
|
|
668
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
669
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
670
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
671
|
-
*
|
|
672
|
-
*/
|
|
673
557
|
var Tables = class {
|
|
674
558
|
async get(schema, table) {
|
|
675
559
|
return await get_response_default(await make_request_default("4", `schemas/${encodeURIComponent(schema)}/tables/${encodeURIComponent(table)}`, "GET", null), 200);
|
|
@@ -687,12 +571,6 @@ var Tables = class {
|
|
|
687
571
|
|
|
688
572
|
//#endregion
|
|
689
573
|
//#region src/Api.ts
|
|
690
|
-
/**
|
|
691
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
692
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
693
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
694
|
-
*
|
|
695
|
-
*/
|
|
696
574
|
function isPlainObject$1(v) {
|
|
697
575
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
698
576
|
}
|
|
@@ -754,12 +632,6 @@ function createApi() {
|
|
|
754
632
|
|
|
755
633
|
//#endregion
|
|
756
634
|
//#region src/SignUp.ts
|
|
757
|
-
/**
|
|
758
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
759
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
760
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
761
|
-
*
|
|
762
|
-
*/
|
|
763
635
|
var SignUp = class {
|
|
764
636
|
constructor(options) {
|
|
765
637
|
this.options = options;
|
|
@@ -1344,36 +1216,35 @@ var TableQueryImpl = class {
|
|
|
1344
1216
|
returning: []
|
|
1345
1217
|
};
|
|
1346
1218
|
return new class {
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1375
|
-
};
|
|
1219
|
+
returning(cols) {
|
|
1220
|
+
state.returning = cols || [];
|
|
1221
|
+
return this;
|
|
1222
|
+
}
|
|
1223
|
+
toSql() {
|
|
1224
|
+
const colsArr = [];
|
|
1225
|
+
const vals = [];
|
|
1226
|
+
const params = {};
|
|
1227
|
+
const type_hints = {};
|
|
1228
|
+
let p = 0;
|
|
1229
|
+
for (const key in state.values) {
|
|
1230
|
+
const value = state.values[key];
|
|
1231
|
+
const col = findColumn(table, key);
|
|
1232
|
+
p += 1;
|
|
1233
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1234
|
+
colsArr.push(`"${key}"`);
|
|
1235
|
+
vals.push(`:${paramName}`);
|
|
1236
|
+
params[paramName] = value;
|
|
1237
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1238
|
+
}
|
|
1239
|
+
const parts = [];
|
|
1240
|
+
parts.push(`insert into "${schema.name}"."${table.name}" (${colsArr.join(", ")}) values (${vals.join(", ")})`);
|
|
1241
|
+
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1242
|
+
const req = {
|
|
1243
|
+
q: parts.join(" "),
|
|
1244
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1245
|
+
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1376
1246
|
};
|
|
1247
|
+
return state.returning.length ? req : req;
|
|
1377
1248
|
}
|
|
1378
1249
|
}();
|
|
1379
1250
|
}
|
|
@@ -1417,55 +1288,56 @@ var TableQueryImpl = class {
|
|
|
1417
1288
|
}
|
|
1418
1289
|
return this;
|
|
1419
1290
|
};
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1291
|
+
}
|
|
1292
|
+
returning(cols) {
|
|
1293
|
+
state.returning = cols || [];
|
|
1294
|
+
return this;
|
|
1295
|
+
}
|
|
1296
|
+
toSql() {
|
|
1297
|
+
const params = {};
|
|
1298
|
+
const type_hints = {};
|
|
1299
|
+
let p = 0;
|
|
1300
|
+
const setParts = [];
|
|
1301
|
+
for (const key in state.values) {
|
|
1302
|
+
const value = state.values[key];
|
|
1303
|
+
const col = findColumn(table, key);
|
|
1304
|
+
p += 1;
|
|
1305
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1306
|
+
setParts.push(`"${key}" = :${paramName}`);
|
|
1307
|
+
params[paramName] = value;
|
|
1308
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1309
|
+
}
|
|
1310
|
+
const whereClauses = [];
|
|
1311
|
+
for (const key in state.where) {
|
|
1312
|
+
const value = state.where[key];
|
|
1313
|
+
const col = findColumn(table, key);
|
|
1314
|
+
p += 1;
|
|
1315
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1316
|
+
if (value === null) {
|
|
1317
|
+
if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
|
|
1318
|
+
whereClauses.push(`"${key}" is null`);
|
|
1319
|
+
} else if (Array.isArray(value) && !isArrayShapedGeomScalarValue(col, value)) {
|
|
1320
|
+
validateInArrayValues(col, key, value, "in");
|
|
1321
|
+
whereClauses.push(`"${key}" = ANY(:${paramName})`);
|
|
1322
|
+
params[paramName] = value;
|
|
1323
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1324
|
+
} else {
|
|
1325
|
+
validateScalarForColumn(col, value, `column ${key}`);
|
|
1326
|
+
whereClauses.push(`"${key}" = :${paramName}`);
|
|
1435
1327
|
params[paramName] = value;
|
|
1436
1328
|
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1437
1329
|
}
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
} else if (Array.isArray(value) && !isArrayShapedGeomScalarValue(col, value)) {
|
|
1448
|
-
validateInArrayValues(col, key, value, "in");
|
|
1449
|
-
whereClauses.push(`"${key}" = ANY(:${paramName})`);
|
|
1450
|
-
params[paramName] = value;
|
|
1451
|
-
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1452
|
-
} else {
|
|
1453
|
-
validateScalarForColumn(col, value, `column ${key}`);
|
|
1454
|
-
whereClauses.push(`"${key}" = :${paramName}`);
|
|
1455
|
-
params[paramName] = value;
|
|
1456
|
-
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1457
|
-
}
|
|
1458
|
-
}
|
|
1459
|
-
const parts = [];
|
|
1460
|
-
parts.push(`update "${schema.name}"."${table.name}" set ${setParts.join(", ")}`);
|
|
1461
|
-
if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
|
|
1462
|
-
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1463
|
-
return {
|
|
1464
|
-
q: parts.join(" "),
|
|
1465
|
-
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1466
|
-
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1467
|
-
};
|
|
1330
|
+
}
|
|
1331
|
+
const parts = [];
|
|
1332
|
+
parts.push(`update "${schema.name}"."${table.name}" set ${setParts.join(", ")}`);
|
|
1333
|
+
if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
|
|
1334
|
+
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1335
|
+
const req = {
|
|
1336
|
+
q: parts.join(" "),
|
|
1337
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1338
|
+
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1468
1339
|
};
|
|
1340
|
+
return state.returning.length ? req : req;
|
|
1469
1341
|
}
|
|
1470
1342
|
}();
|
|
1471
1343
|
}
|
|
@@ -1500,45 +1372,46 @@ var TableQueryImpl = class {
|
|
|
1500
1372
|
}
|
|
1501
1373
|
return this;
|
|
1502
1374
|
};
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
}
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1375
|
+
}
|
|
1376
|
+
returning(cols) {
|
|
1377
|
+
state.returning = cols || [];
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
toSql() {
|
|
1381
|
+
const params = {};
|
|
1382
|
+
const type_hints = {};
|
|
1383
|
+
let p = 0;
|
|
1384
|
+
const whereClauses = [];
|
|
1385
|
+
for (const key in state.where) {
|
|
1386
|
+
const value = state.where[key];
|
|
1387
|
+
const col = findColumn(table, key);
|
|
1388
|
+
p += 1;
|
|
1389
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1390
|
+
if (value === null) {
|
|
1391
|
+
if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
|
|
1392
|
+
whereClauses.push(`"${key}" is null`);
|
|
1393
|
+
} else if (Array.isArray(value)) {
|
|
1394
|
+
validateInArrayValues(col, key, value, "in");
|
|
1395
|
+
whereClauses.push(`"${key}" = ANY(:${paramName})`);
|
|
1396
|
+
params[paramName] = value;
|
|
1397
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1398
|
+
} else {
|
|
1399
|
+
validateScalarForColumn(col, value, `column ${key}`);
|
|
1400
|
+
whereClauses.push(`"${key}" = :${paramName}`);
|
|
1401
|
+
params[paramName] = value;
|
|
1402
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1531
1403
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1404
|
+
}
|
|
1405
|
+
const parts = [];
|
|
1406
|
+
parts.push(`delete from "${schema.name}"."${table.name}"`);
|
|
1407
|
+
if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
|
|
1408
|
+
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1409
|
+
const req = {
|
|
1410
|
+
q: parts.join(" "),
|
|
1411
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1412
|
+
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1541
1413
|
};
|
|
1414
|
+
return state.returning.length ? req : req;
|
|
1542
1415
|
}
|
|
1543
1416
|
}();
|
|
1544
1417
|
}
|
|
@@ -1548,14 +1421,5 @@ function createSqlBuilder(schema) {
|
|
|
1548
1421
|
}
|
|
1549
1422
|
|
|
1550
1423
|
//#endregion
|
|
1551
|
-
|
|
1552
|
-
/**
|
|
1553
|
-
* @author Martin Høgh <mh@mapcentia.com>
|
|
1554
|
-
* @copyright 2013-2026 MapCentia ApS
|
|
1555
|
-
* @license https://opensource.org/license/mit The MIT License
|
|
1556
|
-
*
|
|
1557
|
-
*/
|
|
1558
|
-
|
|
1559
|
-
//#endregion
|
|
1560
|
-
export { Claims, CodeFlow, Gql, Meta, PasswordFlow, Rpc, SignUp, Sql, Stats, Status, Tables, Users, Ws, createApi, createSqlBuilder };
|
|
1424
|
+
export { Claims, CodeFlow, Meta, PasswordFlow, Rpc, SignUp, Sql, Stats, Status, Tables, Users, Ws, createApi, createSqlBuilder };
|
|
1561
1425
|
//# sourceMappingURL=centia-io-sdk.js.map
|