@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.js
CHANGED
|
@@ -79,6 +79,12 @@ 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
|
+
*/
|
|
82
88
|
const generatePkceChallenge = async () => {
|
|
83
89
|
const generateRandomString = () => {
|
|
84
90
|
const array = new Uint32Array(28);
|
|
@@ -160,7 +166,8 @@ const setOptions = (options) => {
|
|
|
160
166
|
getStorage().setItem("gc2_options", JSON.stringify({
|
|
161
167
|
"clientId": options.clientId,
|
|
162
168
|
"host": options.host,
|
|
163
|
-
"redirectUri": options.redirectUri
|
|
169
|
+
"redirectUri": options.redirectUri,
|
|
170
|
+
"clientSecret": options.clientSecret || null
|
|
164
171
|
}));
|
|
165
172
|
};
|
|
166
173
|
const getOptions = () => {
|
|
@@ -187,6 +194,12 @@ const clearNonce = () => {
|
|
|
187
194
|
|
|
188
195
|
//#endregion
|
|
189
196
|
//#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
|
+
*/
|
|
190
203
|
var Gc2Service = class {
|
|
191
204
|
constructor(options) {
|
|
192
205
|
this.options = options;
|
|
@@ -322,6 +335,12 @@ var Gc2Service = class {
|
|
|
322
335
|
|
|
323
336
|
//#endregion
|
|
324
337
|
//#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
|
+
*/
|
|
325
344
|
var CodeFlow = class {
|
|
326
345
|
constructor(options) {
|
|
327
346
|
this.options = options;
|
|
@@ -380,6 +399,12 @@ var CodeFlow = class {
|
|
|
380
399
|
|
|
381
400
|
//#endregion
|
|
382
401
|
//#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
|
+
*/
|
|
383
408
|
var PasswordFlow = class {
|
|
384
409
|
constructor(options) {
|
|
385
410
|
this.options = options;
|
|
@@ -394,7 +419,8 @@ var PasswordFlow = class {
|
|
|
394
419
|
setOptions({
|
|
395
420
|
clientId: this.options.clientId,
|
|
396
421
|
host: this.options.host,
|
|
397
|
-
redirectUri: ""
|
|
422
|
+
redirectUri: "",
|
|
423
|
+
clientSecret: this.options.clientSecret
|
|
398
424
|
});
|
|
399
425
|
}
|
|
400
426
|
signOut() {
|
|
@@ -409,6 +435,12 @@ var PasswordFlow = class {
|
|
|
409
435
|
|
|
410
436
|
//#endregion
|
|
411
437
|
//#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
|
+
*/
|
|
412
444
|
const getHeaders = async (contentType = "application/json") => {
|
|
413
445
|
if (!await isLogin(new Gc2Service(getOptions()))) return Promise.reject("Is not logged in");
|
|
414
446
|
const { accessToken } = getTokens();
|
|
@@ -424,6 +456,12 @@ var request_headers_default = getHeaders;
|
|
|
424
456
|
|
|
425
457
|
//#endregion
|
|
426
458
|
//#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
|
+
*/
|
|
427
465
|
const make = async (version, resource, method, payload, contentType = "application/json") => {
|
|
428
466
|
const options = getOptions();
|
|
429
467
|
let request = {
|
|
@@ -432,12 +470,19 @@ const make = async (version, resource, method, payload, contentType = "applicati
|
|
|
432
470
|
redirect: "manual"
|
|
433
471
|
};
|
|
434
472
|
if (payload) request.body = contentType === "application/json" ? JSON.stringify(payload) : payload;
|
|
435
|
-
return await fetch(options.host + `/api/v${version}/${resource}`, request);
|
|
473
|
+
if (version !== null) return await fetch(options.host + `/api/v${version}/${resource}`, request);
|
|
474
|
+
else return await fetch(options.host + `/api/${resource}`, request);
|
|
436
475
|
};
|
|
437
476
|
var make_request_default = make;
|
|
438
477
|
|
|
439
478
|
//#endregion
|
|
440
479
|
//#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
|
+
*/
|
|
441
486
|
const get = async (response, expectedCode) => {
|
|
442
487
|
let res = null;
|
|
443
488
|
let bodyText = "";
|
|
@@ -457,6 +502,12 @@ var get_response_default = get;
|
|
|
457
502
|
|
|
458
503
|
//#endregion
|
|
459
504
|
//#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
|
+
*/
|
|
460
511
|
var Sql = class {
|
|
461
512
|
async exec(request) {
|
|
462
513
|
return await get_response_default(await make_request_default("4", `sql`, "POST", request), 200);
|
|
@@ -465,14 +516,43 @@ var Sql = class {
|
|
|
465
516
|
|
|
466
517
|
//#endregion
|
|
467
518
|
//#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
|
+
*/
|
|
468
525
|
var Rpc = class {
|
|
469
526
|
async call(request) {
|
|
470
527
|
return await get_response_default(await make_request_default("4", `call`, "POST", request), 200);
|
|
471
528
|
}
|
|
472
529
|
};
|
|
473
530
|
|
|
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
|
+
|
|
474
548
|
//#endregion
|
|
475
549
|
//#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
|
+
*/
|
|
476
556
|
var Meta = class {
|
|
477
557
|
async query(rel) {
|
|
478
558
|
return await get_response_default(await make_request_default("3", `meta/${rel}`, "GET", null), 200);
|
|
@@ -481,6 +561,12 @@ var Meta = class {
|
|
|
481
561
|
|
|
482
562
|
//#endregion
|
|
483
563
|
//#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
|
+
*/
|
|
484
570
|
var Status = class {
|
|
485
571
|
isAuth() {
|
|
486
572
|
const tokens = getTokens();
|
|
@@ -493,6 +579,12 @@ var Status = class {
|
|
|
493
579
|
|
|
494
580
|
//#endregion
|
|
495
581
|
//#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
|
+
*/
|
|
496
588
|
var Claims = class {
|
|
497
589
|
get() {
|
|
498
590
|
const tokens = getTokens().accessToken;
|
|
@@ -502,6 +594,12 @@ var Claims = class {
|
|
|
502
594
|
|
|
503
595
|
//#endregion
|
|
504
596
|
//#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
|
+
*/
|
|
505
603
|
var Users = class {
|
|
506
604
|
async get(user) {
|
|
507
605
|
return await get_response_default(await make_request_default("4", `users/${user}`, "GET", null), 200);
|
|
@@ -510,6 +608,12 @@ var Users = class {
|
|
|
510
608
|
|
|
511
609
|
//#endregion
|
|
512
610
|
//#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
|
+
*/
|
|
513
617
|
var Ws = class {
|
|
514
618
|
constructor(options) {
|
|
515
619
|
this.options = options;
|
|
@@ -546,6 +650,12 @@ var Ws = class {
|
|
|
546
650
|
|
|
547
651
|
//#endregion
|
|
548
652
|
//#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
|
+
*/
|
|
549
659
|
var Stats = class {
|
|
550
660
|
async get() {
|
|
551
661
|
return await get_response_default(await make_request_default("4", `stats`, "GET", null), 200);
|
|
@@ -554,6 +664,12 @@ var Stats = class {
|
|
|
554
664
|
|
|
555
665
|
//#endregion
|
|
556
666
|
//#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
|
+
*/
|
|
557
673
|
var Tables = class {
|
|
558
674
|
async get(schema, table) {
|
|
559
675
|
return await get_response_default(await make_request_default("4", `schemas/${encodeURIComponent(schema)}/tables/${encodeURIComponent(table)}`, "GET", null), 200);
|
|
@@ -571,6 +687,12 @@ var Tables = class {
|
|
|
571
687
|
|
|
572
688
|
//#endregion
|
|
573
689
|
//#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
|
+
*/
|
|
574
696
|
function isPlainObject$1(v) {
|
|
575
697
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
576
698
|
}
|
|
@@ -632,6 +754,12 @@ function createApi() {
|
|
|
632
754
|
|
|
633
755
|
//#endregion
|
|
634
756
|
//#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
|
+
*/
|
|
635
763
|
var SignUp = class {
|
|
636
764
|
constructor(options) {
|
|
637
765
|
this.options = options;
|
|
@@ -1216,35 +1344,36 @@ var TableQueryImpl = class {
|
|
|
1216
1344
|
returning: []
|
|
1217
1345
|
};
|
|
1218
1346
|
return new class {
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
const
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1347
|
+
constructor() {
|
|
1348
|
+
this.returning = (cols) => {
|
|
1349
|
+
state.returning = cols || [];
|
|
1350
|
+
return this;
|
|
1351
|
+
};
|
|
1352
|
+
this.toSql = () => {
|
|
1353
|
+
const cols = [];
|
|
1354
|
+
const vals = [];
|
|
1355
|
+
const params = {};
|
|
1356
|
+
const type_hints = {};
|
|
1357
|
+
let p = 0;
|
|
1358
|
+
for (const key in state.values) {
|
|
1359
|
+
const value = state.values[key];
|
|
1360
|
+
const col = findColumn(table, key);
|
|
1361
|
+
p += 1;
|
|
1362
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1363
|
+
cols.push(`"${key}"`);
|
|
1364
|
+
vals.push(`:${paramName}`);
|
|
1365
|
+
params[paramName] = value;
|
|
1366
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1367
|
+
}
|
|
1368
|
+
const parts = [];
|
|
1369
|
+
parts.push(`insert into "${schema.name}"."${table.name}" (${cols.join(", ")}) values (${vals.join(", ")})`);
|
|
1370
|
+
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1371
|
+
return {
|
|
1372
|
+
q: parts.join(" "),
|
|
1373
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1374
|
+
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1375
|
+
};
|
|
1246
1376
|
};
|
|
1247
|
-
return state.returning.length ? req : req;
|
|
1248
1377
|
}
|
|
1249
1378
|
}();
|
|
1250
1379
|
}
|
|
@@ -1288,56 +1417,55 @@ var TableQueryImpl = class {
|
|
|
1288
1417
|
}
|
|
1289
1418
|
return this;
|
|
1290
1419
|
};
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
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}`);
|
|
1420
|
+
this.returning = (cols) => {
|
|
1421
|
+
state.returning = cols || [];
|
|
1422
|
+
return this;
|
|
1423
|
+
};
|
|
1424
|
+
this.toSql = () => {
|
|
1425
|
+
const params = {};
|
|
1426
|
+
const type_hints = {};
|
|
1427
|
+
let p = 0;
|
|
1428
|
+
const setParts = [];
|
|
1429
|
+
for (const key in state.values) {
|
|
1430
|
+
const value = state.values[key];
|
|
1431
|
+
const col = findColumn(table, key);
|
|
1432
|
+
p += 1;
|
|
1433
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1434
|
+
setParts.push(`"${key}" = :${paramName}`);
|
|
1327
1435
|
params[paramName] = value;
|
|
1328
1436
|
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1329
1437
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1438
|
+
const whereClauses = [];
|
|
1439
|
+
for (const key in state.where) {
|
|
1440
|
+
const value = state.where[key];
|
|
1441
|
+
const col = findColumn(table, key);
|
|
1442
|
+
p += 1;
|
|
1443
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1444
|
+
if (value === null) {
|
|
1445
|
+
if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
|
|
1446
|
+
whereClauses.push(`"${key}" is null`);
|
|
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
|
+
};
|
|
1339
1468
|
};
|
|
1340
|
-
return state.returning.length ? req : req;
|
|
1341
1469
|
}
|
|
1342
1470
|
}();
|
|
1343
1471
|
}
|
|
@@ -1372,46 +1500,45 @@ var TableQueryImpl = class {
|
|
|
1372
1500
|
}
|
|
1373
1501
|
return this;
|
|
1374
1502
|
};
|
|
1375
|
-
|
|
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
|
-
|
|
1503
|
+
this.returning = (cols) => {
|
|
1504
|
+
state.returning = cols || [];
|
|
1505
|
+
return this;
|
|
1506
|
+
};
|
|
1507
|
+
this.toSql = () => {
|
|
1508
|
+
const params = {};
|
|
1509
|
+
const type_hints = {};
|
|
1510
|
+
let p = 0;
|
|
1511
|
+
const whereClauses = [];
|
|
1512
|
+
for (const key in state.where) {
|
|
1513
|
+
const value = state.where[key];
|
|
1514
|
+
const col = findColumn(table, key);
|
|
1515
|
+
p += 1;
|
|
1516
|
+
const paramName = `${table.name}_${key}_${p}`;
|
|
1517
|
+
if (value === null) {
|
|
1518
|
+
if (!col.is_nullable) throw new Error(`Column ${table.name}.${key} is not nullable; cannot compare to null`);
|
|
1519
|
+
whereClauses.push(`"${key}" is null`);
|
|
1520
|
+
} else if (Array.isArray(value)) {
|
|
1521
|
+
validateInArrayValues(col, key, value, "in");
|
|
1522
|
+
whereClauses.push(`"${key}" = ANY(:${paramName})`);
|
|
1523
|
+
params[paramName] = value;
|
|
1524
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1525
|
+
} else {
|
|
1526
|
+
validateScalarForColumn(col, value, `column ${key}`);
|
|
1527
|
+
whereClauses.push(`"${key}" = :${paramName}`);
|
|
1528
|
+
params[paramName] = value;
|
|
1529
|
+
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1530
|
+
}
|
|
1403
1531
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1532
|
+
const parts = [];
|
|
1533
|
+
parts.push(`delete from "${schema.name}"."${table.name}"`);
|
|
1534
|
+
if (whereClauses.length) parts.push("where " + whereClauses.join(" and "));
|
|
1535
|
+
if (state.returning.length) parts.push("returning " + state.returning.join(", "));
|
|
1536
|
+
return {
|
|
1537
|
+
q: parts.join(" "),
|
|
1538
|
+
params: Object.keys(params).length > 0 ? params : void 0,
|
|
1539
|
+
type_hints: Object.keys(type_hints).length ? type_hints : void 0
|
|
1540
|
+
};
|
|
1413
1541
|
};
|
|
1414
|
-
return state.returning.length ? req : req;
|
|
1415
1542
|
}
|
|
1416
1543
|
}();
|
|
1417
1544
|
}
|
|
@@ -1421,5 +1548,14 @@ function createSqlBuilder(schema) {
|
|
|
1421
1548
|
}
|
|
1422
1549
|
|
|
1423
1550
|
//#endregion
|
|
1424
|
-
|
|
1551
|
+
//#region src/index.ts
|
|
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 };
|
|
1425
1561
|
//# sourceMappingURL=centia-io-sdk.js.map
|