@centia-io/sdk 0.0.43 → 0.0.44
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 +253 -115
- package/dist/centia-io-sdk.d.cts +119 -69
- package/dist/centia-io-sdk.d.cts.map +1 -1
- package/dist/centia-io-sdk.d.ts +119 -69
- package/dist/centia-io-sdk.d.ts.map +1 -1
- package/dist/centia-io-sdk.js +253 -116
- package/dist/centia-io-sdk.js.map +1 -1
- package/dist/centia-io-sdk.umd.js +1382 -1244
- package/package.json +36 -36
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;
|
|
@@ -297,6 +310,7 @@ var Gc2Service = class {
|
|
|
297
310
|
const path = `${this.host}/api/v4/oauth`;
|
|
298
311
|
return this.request(this.buildUrl(path), "POST", {
|
|
299
312
|
client_id: this.options.clientId,
|
|
313
|
+
client_secret: this.options.clientSecret,
|
|
300
314
|
grant_type: "password",
|
|
301
315
|
username,
|
|
302
316
|
password,
|
|
@@ -322,6 +336,12 @@ var Gc2Service = class {
|
|
|
322
336
|
|
|
323
337
|
//#endregion
|
|
324
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
|
+
*/
|
|
325
345
|
var CodeFlow = class {
|
|
326
346
|
constructor(options) {
|
|
327
347
|
this.options = options;
|
|
@@ -380,6 +400,12 @@ var CodeFlow = class {
|
|
|
380
400
|
|
|
381
401
|
//#endregion
|
|
382
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
|
+
*/
|
|
383
409
|
var PasswordFlow = class {
|
|
384
410
|
constructor(options) {
|
|
385
411
|
this.options = options;
|
|
@@ -394,7 +420,8 @@ var PasswordFlow = class {
|
|
|
394
420
|
setOptions({
|
|
395
421
|
clientId: this.options.clientId,
|
|
396
422
|
host: this.options.host,
|
|
397
|
-
redirectUri: ""
|
|
423
|
+
redirectUri: "",
|
|
424
|
+
clientSecret: this.options.clientSecret
|
|
398
425
|
});
|
|
399
426
|
}
|
|
400
427
|
signOut() {
|
|
@@ -409,6 +436,12 @@ var PasswordFlow = class {
|
|
|
409
436
|
|
|
410
437
|
//#endregion
|
|
411
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
|
+
*/
|
|
412
445
|
const getHeaders = async (contentType = "application/json") => {
|
|
413
446
|
if (!await isLogin(new Gc2Service(getOptions()))) return Promise.reject("Is not logged in");
|
|
414
447
|
const { accessToken } = getTokens();
|
|
@@ -424,6 +457,12 @@ var request_headers_default = getHeaders;
|
|
|
424
457
|
|
|
425
458
|
//#endregion
|
|
426
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
|
+
*/
|
|
427
466
|
const make = async (version, resource, method, payload, contentType = "application/json") => {
|
|
428
467
|
const options = getOptions();
|
|
429
468
|
let request = {
|
|
@@ -432,12 +471,19 @@ const make = async (version, resource, method, payload, contentType = "applicati
|
|
|
432
471
|
redirect: "manual"
|
|
433
472
|
};
|
|
434
473
|
if (payload) request.body = contentType === "application/json" ? JSON.stringify(payload) : payload;
|
|
435
|
-
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);
|
|
436
476
|
};
|
|
437
477
|
var make_request_default = make;
|
|
438
478
|
|
|
439
479
|
//#endregion
|
|
440
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
|
+
*/
|
|
441
487
|
const get = async (response, expectedCode) => {
|
|
442
488
|
let res = null;
|
|
443
489
|
let bodyText = "";
|
|
@@ -457,6 +503,12 @@ var get_response_default = get;
|
|
|
457
503
|
|
|
458
504
|
//#endregion
|
|
459
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
|
+
*/
|
|
460
512
|
var Sql = class {
|
|
461
513
|
async exec(request) {
|
|
462
514
|
return await get_response_default(await make_request_default("4", `sql`, "POST", request), 200);
|
|
@@ -465,14 +517,43 @@ var Sql = class {
|
|
|
465
517
|
|
|
466
518
|
//#endregion
|
|
467
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
|
+
*/
|
|
468
526
|
var Rpc = class {
|
|
469
527
|
async call(request) {
|
|
470
528
|
return await get_response_default(await make_request_default("4", `call`, "POST", request), 200);
|
|
471
529
|
}
|
|
472
530
|
};
|
|
473
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
|
+
|
|
474
549
|
//#endregion
|
|
475
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
|
+
*/
|
|
476
557
|
var Meta = class {
|
|
477
558
|
async query(rel) {
|
|
478
559
|
return await get_response_default(await make_request_default("3", `meta/${rel}`, "GET", null), 200);
|
|
@@ -481,6 +562,12 @@ var Meta = class {
|
|
|
481
562
|
|
|
482
563
|
//#endregion
|
|
483
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
|
+
*/
|
|
484
571
|
var Status = class {
|
|
485
572
|
isAuth() {
|
|
486
573
|
const tokens = getTokens();
|
|
@@ -493,6 +580,12 @@ var Status = class {
|
|
|
493
580
|
|
|
494
581
|
//#endregion
|
|
495
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
|
+
*/
|
|
496
589
|
var Claims = class {
|
|
497
590
|
get() {
|
|
498
591
|
const tokens = getTokens().accessToken;
|
|
@@ -502,6 +595,12 @@ var Claims = class {
|
|
|
502
595
|
|
|
503
596
|
//#endregion
|
|
504
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
|
+
*/
|
|
505
604
|
var Users = class {
|
|
506
605
|
async get(user) {
|
|
507
606
|
return await get_response_default(await make_request_default("4", `users/${user}`, "GET", null), 200);
|
|
@@ -510,6 +609,12 @@ var Users = class {
|
|
|
510
609
|
|
|
511
610
|
//#endregion
|
|
512
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
|
+
*/
|
|
513
618
|
var Ws = class {
|
|
514
619
|
constructor(options) {
|
|
515
620
|
this.options = options;
|
|
@@ -546,6 +651,12 @@ var Ws = class {
|
|
|
546
651
|
|
|
547
652
|
//#endregion
|
|
548
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
|
+
*/
|
|
549
660
|
var Stats = class {
|
|
550
661
|
async get() {
|
|
551
662
|
return await get_response_default(await make_request_default("4", `stats`, "GET", null), 200);
|
|
@@ -554,6 +665,12 @@ var Stats = class {
|
|
|
554
665
|
|
|
555
666
|
//#endregion
|
|
556
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
|
+
*/
|
|
557
674
|
var Tables = class {
|
|
558
675
|
async get(schema, table) {
|
|
559
676
|
return await get_response_default(await make_request_default("4", `schemas/${encodeURIComponent(schema)}/tables/${encodeURIComponent(table)}`, "GET", null), 200);
|
|
@@ -571,6 +688,12 @@ var Tables = class {
|
|
|
571
688
|
|
|
572
689
|
//#endregion
|
|
573
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
|
+
*/
|
|
574
697
|
function isPlainObject$1(v) {
|
|
575
698
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
576
699
|
}
|
|
@@ -632,6 +755,12 @@ function createApi() {
|
|
|
632
755
|
|
|
633
756
|
//#endregion
|
|
634
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
|
+
*/
|
|
635
764
|
var SignUp = class {
|
|
636
765
|
constructor(options) {
|
|
637
766
|
this.options = options;
|
|
@@ -1216,35 +1345,36 @@ var TableQueryImpl = class {
|
|
|
1216
1345
|
returning: []
|
|
1217
1346
|
};
|
|
1218
1347
|
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
|
-
|
|
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
|
+
};
|
|
1246
1377
|
};
|
|
1247
|
-
return state.returning.length ? req : req;
|
|
1248
1378
|
}
|
|
1249
1379
|
}();
|
|
1250
1380
|
}
|
|
@@ -1288,56 +1418,55 @@ var TableQueryImpl = class {
|
|
|
1288
1418
|
}
|
|
1289
1419
|
return this;
|
|
1290
1420
|
};
|
|
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}`);
|
|
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}`);
|
|
1327
1436
|
params[paramName] = value;
|
|
1328
1437
|
addTypeHintForParam(type_hints, paramName, col, value);
|
|
1329
1438
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
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
|
+
};
|
|
1339
1469
|
};
|
|
1340
|
-
return state.returning.length ? req : req;
|
|
1341
1470
|
}
|
|
1342
1471
|
}();
|
|
1343
1472
|
}
|
|
@@ -1372,46 +1501,45 @@ var TableQueryImpl = class {
|
|
|
1372
1501
|
}
|
|
1373
1502
|
return this;
|
|
1374
1503
|
};
|
|
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
|
-
|
|
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
|
+
}
|
|
1403
1532
|
}
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
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
|
+
};
|
|
1413
1542
|
};
|
|
1414
|
-
return state.returning.length ? req : req;
|
|
1415
1543
|
}
|
|
1416
1544
|
}();
|
|
1417
1545
|
}
|
|
@@ -1421,5 +1549,14 @@ function createSqlBuilder(schema) {
|
|
|
1421
1549
|
}
|
|
1422
1550
|
|
|
1423
1551
|
//#endregion
|
|
1424
|
-
|
|
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
|
+
|
|
1560
|
+
//#endregion
|
|
1561
|
+
export { Claims, CodeFlow, Gql, Meta, PasswordFlow, Rpc, SignUp, Sql, Stats, Status, Tables, Users, Ws, createApi, createSqlBuilder };
|
|
1425
1562
|
//# sourceMappingURL=centia-io-sdk.js.map
|