@teamkeel/functions-runtime 0.460.0 → 0.460.1
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/dist/index.cjs +79 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -472,6 +472,20 @@ function isRichType(obj) {
|
|
|
472
472
|
}
|
|
473
473
|
__name(isRichType, "isRichType");
|
|
474
474
|
|
|
475
|
+
// src/jsonColumnValue.js
|
|
476
|
+
var JsonColumnValue = class {
|
|
477
|
+
static {
|
|
478
|
+
__name(this, "JsonColumnValue");
|
|
479
|
+
}
|
|
480
|
+
constructor(value) {
|
|
481
|
+
this.value = value;
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
function parseJsonColumnValue(value) {
|
|
485
|
+
return new JsonColumnValue(JSON.parse(value));
|
|
486
|
+
}
|
|
487
|
+
__name(parseJsonColumnValue, "parseJsonColumnValue");
|
|
488
|
+
|
|
475
489
|
// src/camelCasePlugin.js
|
|
476
490
|
var KeelCamelCasePlugin = class {
|
|
477
491
|
static {
|
|
@@ -479,41 +493,77 @@ var KeelCamelCasePlugin = class {
|
|
|
479
493
|
}
|
|
480
494
|
constructor(opt) {
|
|
481
495
|
this.opt = opt;
|
|
496
|
+
this.auditQueryIds = /* @__PURE__ */ new WeakSet();
|
|
482
497
|
this.CamelCasePlugin = new CamelCasePlugin({
|
|
483
498
|
...opt,
|
|
484
499
|
underscoreBeforeDigits: true
|
|
485
500
|
});
|
|
486
501
|
}
|
|
487
502
|
transformQuery(args) {
|
|
503
|
+
if (args.queryId && referencesTable(args.node, "keel_audit")) {
|
|
504
|
+
this.auditQueryIds.add(args.queryId);
|
|
505
|
+
}
|
|
488
506
|
return this.CamelCasePlugin.transformQuery(args);
|
|
489
507
|
}
|
|
490
508
|
async transformResult(args) {
|
|
491
509
|
if (args.result.rows && Array.isArray(args.result.rows)) {
|
|
510
|
+
const mapAuditJson = args.queryId && this.auditQueryIds.has(args.queryId);
|
|
492
511
|
return {
|
|
493
512
|
...args.result,
|
|
494
|
-
rows: args.result.rows.map((row) => this.mapRow(row))
|
|
513
|
+
rows: args.result.rows.map((row) => this.mapRow(row, { mapAuditJson }))
|
|
495
514
|
};
|
|
496
515
|
}
|
|
497
516
|
return args.result;
|
|
498
517
|
}
|
|
499
|
-
mapRow(row) {
|
|
518
|
+
mapRow(row, context7 = {}) {
|
|
500
519
|
return Object.keys(row).reduce((obj, key) => {
|
|
501
520
|
if (key.endsWith("__sequence")) {
|
|
502
521
|
return obj;
|
|
503
522
|
}
|
|
504
523
|
let value = row[key];
|
|
524
|
+
if (value instanceof JsonColumnValue) {
|
|
525
|
+
value = shouldMapJsonColumn(row, key, context7) && canMap(value.value, this.opt) ? this.mapRow(value.value, context7) : value.value;
|
|
526
|
+
obj[this.CamelCasePlugin.camelCase(key)] = value;
|
|
527
|
+
return obj;
|
|
528
|
+
}
|
|
505
529
|
if (Array.isArray(value)) {
|
|
506
530
|
value = value.map(
|
|
507
|
-
(it) => canMap(it, this.opt) ? this.mapRow(it) : it
|
|
531
|
+
(it) => canMap(it, this.opt) ? this.mapRow(it, context7) : it
|
|
508
532
|
);
|
|
509
533
|
} else if (canMap(value, this.opt)) {
|
|
510
|
-
value = this.mapRow(value);
|
|
534
|
+
value = this.mapRow(value, context7);
|
|
511
535
|
}
|
|
512
536
|
obj[this.CamelCasePlugin.camelCase(key)] = value;
|
|
513
537
|
return obj;
|
|
514
538
|
}, {});
|
|
515
539
|
}
|
|
516
540
|
};
|
|
541
|
+
function shouldMapJsonColumn(row, key, context7) {
|
|
542
|
+
return context7.mapAuditJson && key === "data" && "id" in row && "table_name" in row && "op" in row && "identity_id" in row && "trace_id" in row && "created_at" in row && "event_processed_at" in row;
|
|
543
|
+
}
|
|
544
|
+
__name(shouldMapJsonColumn, "shouldMapJsonColumn");
|
|
545
|
+
function referencesTable(node, tableName) {
|
|
546
|
+
if (!node || typeof node !== "object") {
|
|
547
|
+
return false;
|
|
548
|
+
}
|
|
549
|
+
if (node.kind === "IdentifierNode" && (node.name === tableName || node.name === "keelAudit")) {
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
if (node.kind === "RawNode" && Array.isArray(node.sqlFragments) && node.sqlFragments.some(
|
|
553
|
+
(fragment) => new RegExp(`(^|[^A-Za-z0-9_])${tableName}($|[^A-Za-z0-9_])`, "i").test(
|
|
554
|
+
fragment
|
|
555
|
+
)
|
|
556
|
+
)) {
|
|
557
|
+
return true;
|
|
558
|
+
}
|
|
559
|
+
return Object.values(node).some((value) => {
|
|
560
|
+
if (Array.isArray(value)) {
|
|
561
|
+
return value.some((item) => referencesTable(item, tableName));
|
|
562
|
+
}
|
|
563
|
+
return referencesTable(value, tableName);
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
__name(referencesTable, "referencesTable");
|
|
517
567
|
function canMap(obj, opt) {
|
|
518
568
|
return isPlainObject(obj) && !opt?.maintainNestedObjectKeys && !isRichType(obj);
|
|
519
569
|
}
|
|
@@ -914,6 +964,8 @@ function getDialect(connString) {
|
|
|
914
964
|
pgTypes.builtins.INTERVAL,
|
|
915
965
|
(val) => new Duration(val)
|
|
916
966
|
);
|
|
967
|
+
pgTypes.setTypeParser(pgTypes.builtins.JSON, parseJsonColumnValue);
|
|
968
|
+
pgTypes.setTypeParser(pgTypes.builtins.JSONB, parseJsonColumnValue);
|
|
917
969
|
const poolConfig = {
|
|
918
970
|
Client: InstrumentedClient,
|
|
919
971
|
// Increased idle time before closing a connection in the local pool (from 10s default).
|
|
@@ -948,6 +1000,8 @@ function getDialect(connString) {
|
|
|
948
1000
|
pgTypes.builtins.INTERVAL,
|
|
949
1001
|
(val) => new Duration(val)
|
|
950
1002
|
);
|
|
1003
|
+
neon.types.setTypeParser(pgTypes.builtins.JSON, parseJsonColumnValue);
|
|
1004
|
+
neon.types.setTypeParser(pgTypes.builtins.JSONB, parseJsonColumnValue);
|
|
951
1005
|
neon.neonConfig.webSocketConstructor = WebSocket;
|
|
952
1006
|
const pool = new InstrumentedNeonServerlessPool({
|
|
953
1007
|
// If connString is not passed fall back to reading from env var
|
|
@@ -3723,12 +3777,29 @@ async function applyElementGetData(content, data) {
|
|
|
3723
3777
|
return data;
|
|
3724
3778
|
}
|
|
3725
3779
|
__name(applyElementGetData, "applyElementGetData");
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3780
|
+
var ITERATOR_SCOPED_ELEMENT = /^([^[]+)\[(\d+)\]:(.+)$/;
|
|
3781
|
+
async function callbackFn(elements, elementPath, callbackName, data) {
|
|
3782
|
+
const scoped = ITERATOR_SCOPED_ELEMENT.exec(elementPath);
|
|
3783
|
+
let searchScope = elements;
|
|
3784
|
+
let elementName = elementPath;
|
|
3785
|
+
let iteratorName = null;
|
|
3786
|
+
if (scoped) {
|
|
3787
|
+
iteratorName = scoped[1];
|
|
3788
|
+
elementName = scoped[3];
|
|
3789
|
+
const iter = elements.find(
|
|
3790
|
+
(el) => el?.uiConfig?.__type === "ui.iterator" && el.uiConfig.name === iteratorName
|
|
3791
|
+
);
|
|
3792
|
+
if (!iter) {
|
|
3793
|
+
throw new Error(`Iterator with name ${iteratorName} not found`);
|
|
3794
|
+
}
|
|
3795
|
+
searchScope = iter.uiConfig.content;
|
|
3796
|
+
}
|
|
3797
|
+
const element = searchScope.find(
|
|
3798
|
+
(el) => el?.uiConfig && el.uiConfig.name === elementName
|
|
3729
3799
|
);
|
|
3730
3800
|
if (!element) {
|
|
3731
|
-
|
|
3801
|
+
const where = iteratorName ? ` in iterator ${iteratorName}` : "";
|
|
3802
|
+
throw new Error(`Element with name ${elementName} not found${where}`);
|
|
3732
3803
|
}
|
|
3733
3804
|
const cb = element[callbackName];
|
|
3734
3805
|
if (typeof cb !== "function") {
|