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