@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.cjs
CHANGED
|
@@ -530,6 +530,20 @@ function isRichType(obj) {
|
|
|
530
530
|
}
|
|
531
531
|
__name(isRichType, "isRichType");
|
|
532
532
|
|
|
533
|
+
// src/jsonColumnValue.js
|
|
534
|
+
var JsonColumnValue = class {
|
|
535
|
+
static {
|
|
536
|
+
__name(this, "JsonColumnValue");
|
|
537
|
+
}
|
|
538
|
+
constructor(value) {
|
|
539
|
+
this.value = value;
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
function parseJsonColumnValue(value) {
|
|
543
|
+
return new JsonColumnValue(JSON.parse(value));
|
|
544
|
+
}
|
|
545
|
+
__name(parseJsonColumnValue, "parseJsonColumnValue");
|
|
546
|
+
|
|
533
547
|
// src/camelCasePlugin.js
|
|
534
548
|
var KeelCamelCasePlugin = class {
|
|
535
549
|
static {
|
|
@@ -537,41 +551,77 @@ var KeelCamelCasePlugin = class {
|
|
|
537
551
|
}
|
|
538
552
|
constructor(opt) {
|
|
539
553
|
this.opt = opt;
|
|
554
|
+
this.auditQueryIds = /* @__PURE__ */ new WeakSet();
|
|
540
555
|
this.CamelCasePlugin = new import_kysely2.CamelCasePlugin({
|
|
541
556
|
...opt,
|
|
542
557
|
underscoreBeforeDigits: true
|
|
543
558
|
});
|
|
544
559
|
}
|
|
545
560
|
transformQuery(args) {
|
|
561
|
+
if (args.queryId && referencesTable(args.node, "keel_audit")) {
|
|
562
|
+
this.auditQueryIds.add(args.queryId);
|
|
563
|
+
}
|
|
546
564
|
return this.CamelCasePlugin.transformQuery(args);
|
|
547
565
|
}
|
|
548
566
|
async transformResult(args) {
|
|
549
567
|
if (args.result.rows && Array.isArray(args.result.rows)) {
|
|
568
|
+
const mapAuditJson = args.queryId && this.auditQueryIds.has(args.queryId);
|
|
550
569
|
return {
|
|
551
570
|
...args.result,
|
|
552
|
-
rows: args.result.rows.map((row) => this.mapRow(row))
|
|
571
|
+
rows: args.result.rows.map((row) => this.mapRow(row, { mapAuditJson }))
|
|
553
572
|
};
|
|
554
573
|
}
|
|
555
574
|
return args.result;
|
|
556
575
|
}
|
|
557
|
-
mapRow(row) {
|
|
576
|
+
mapRow(row, context7 = {}) {
|
|
558
577
|
return Object.keys(row).reduce((obj, key) => {
|
|
559
578
|
if (key.endsWith("__sequence")) {
|
|
560
579
|
return obj;
|
|
561
580
|
}
|
|
562
581
|
let value = row[key];
|
|
582
|
+
if (value instanceof JsonColumnValue) {
|
|
583
|
+
value = shouldMapJsonColumn(row, key, context7) && canMap(value.value, this.opt) ? this.mapRow(value.value, context7) : value.value;
|
|
584
|
+
obj[this.CamelCasePlugin.camelCase(key)] = value;
|
|
585
|
+
return obj;
|
|
586
|
+
}
|
|
563
587
|
if (Array.isArray(value)) {
|
|
564
588
|
value = value.map(
|
|
565
|
-
(it) => canMap(it, this.opt) ? this.mapRow(it) : it
|
|
589
|
+
(it) => canMap(it, this.opt) ? this.mapRow(it, context7) : it
|
|
566
590
|
);
|
|
567
591
|
} else if (canMap(value, this.opt)) {
|
|
568
|
-
value = this.mapRow(value);
|
|
592
|
+
value = this.mapRow(value, context7);
|
|
569
593
|
}
|
|
570
594
|
obj[this.CamelCasePlugin.camelCase(key)] = value;
|
|
571
595
|
return obj;
|
|
572
596
|
}, {});
|
|
573
597
|
}
|
|
574
598
|
};
|
|
599
|
+
function shouldMapJsonColumn(row, key, context7) {
|
|
600
|
+
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;
|
|
601
|
+
}
|
|
602
|
+
__name(shouldMapJsonColumn, "shouldMapJsonColumn");
|
|
603
|
+
function referencesTable(node, tableName) {
|
|
604
|
+
if (!node || typeof node !== "object") {
|
|
605
|
+
return false;
|
|
606
|
+
}
|
|
607
|
+
if (node.kind === "IdentifierNode" && (node.name === tableName || node.name === "keelAudit")) {
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
if (node.kind === "RawNode" && Array.isArray(node.sqlFragments) && node.sqlFragments.some(
|
|
611
|
+
(fragment) => new RegExp(`(^|[^A-Za-z0-9_])${tableName}($|[^A-Za-z0-9_])`, "i").test(
|
|
612
|
+
fragment
|
|
613
|
+
)
|
|
614
|
+
)) {
|
|
615
|
+
return true;
|
|
616
|
+
}
|
|
617
|
+
return Object.values(node).some((value) => {
|
|
618
|
+
if (Array.isArray(value)) {
|
|
619
|
+
return value.some((item) => referencesTable(item, tableName));
|
|
620
|
+
}
|
|
621
|
+
return referencesTable(value, tableName);
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
__name(referencesTable, "referencesTable");
|
|
575
625
|
function canMap(obj, opt) {
|
|
576
626
|
return isPlainObject(obj) && !opt?.maintainNestedObjectKeys && !isRichType(obj);
|
|
577
627
|
}
|
|
@@ -972,6 +1022,8 @@ function getDialect(connString) {
|
|
|
972
1022
|
import_pg.types.builtins.INTERVAL,
|
|
973
1023
|
(val) => new Duration(val)
|
|
974
1024
|
);
|
|
1025
|
+
import_pg.types.setTypeParser(import_pg.types.builtins.JSON, parseJsonColumnValue);
|
|
1026
|
+
import_pg.types.setTypeParser(import_pg.types.builtins.JSONB, parseJsonColumnValue);
|
|
975
1027
|
const poolConfig = {
|
|
976
1028
|
Client: InstrumentedClient,
|
|
977
1029
|
// Increased idle time before closing a connection in the local pool (from 10s default).
|
|
@@ -1006,6 +1058,8 @@ function getDialect(connString) {
|
|
|
1006
1058
|
import_pg.types.builtins.INTERVAL,
|
|
1007
1059
|
(val) => new Duration(val)
|
|
1008
1060
|
);
|
|
1061
|
+
neon.types.setTypeParser(import_pg.types.builtins.JSON, parseJsonColumnValue);
|
|
1062
|
+
neon.types.setTypeParser(import_pg.types.builtins.JSONB, parseJsonColumnValue);
|
|
1009
1063
|
neon.neonConfig.webSocketConstructor = import_ws.default;
|
|
1010
1064
|
const pool = new InstrumentedNeonServerlessPool({
|
|
1011
1065
|
// If connString is not passed fall back to reading from env var
|
|
@@ -3758,12 +3812,29 @@ async function applyElementGetData(content, data) {
|
|
|
3758
3812
|
return data;
|
|
3759
3813
|
}
|
|
3760
3814
|
__name(applyElementGetData, "applyElementGetData");
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3815
|
+
var ITERATOR_SCOPED_ELEMENT = /^([^[]+)\[(\d+)\]:(.+)$/;
|
|
3816
|
+
async function callbackFn(elements, elementPath, callbackName, data) {
|
|
3817
|
+
const scoped = ITERATOR_SCOPED_ELEMENT.exec(elementPath);
|
|
3818
|
+
let searchScope = elements;
|
|
3819
|
+
let elementName = elementPath;
|
|
3820
|
+
let iteratorName = null;
|
|
3821
|
+
if (scoped) {
|
|
3822
|
+
iteratorName = scoped[1];
|
|
3823
|
+
elementName = scoped[3];
|
|
3824
|
+
const iter = elements.find(
|
|
3825
|
+
(el) => el?.uiConfig?.__type === "ui.iterator" && el.uiConfig.name === iteratorName
|
|
3826
|
+
);
|
|
3827
|
+
if (!iter) {
|
|
3828
|
+
throw new Error(`Iterator with name ${iteratorName} not found`);
|
|
3829
|
+
}
|
|
3830
|
+
searchScope = iter.uiConfig.content;
|
|
3831
|
+
}
|
|
3832
|
+
const element = searchScope.find(
|
|
3833
|
+
(el) => el?.uiConfig && el.uiConfig.name === elementName
|
|
3764
3834
|
);
|
|
3765
3835
|
if (!element) {
|
|
3766
|
-
|
|
3836
|
+
const where = iteratorName ? ` in iterator ${iteratorName}` : "";
|
|
3837
|
+
throw new Error(`Element with name ${elementName} not found${where}`);
|
|
3767
3838
|
}
|
|
3768
3839
|
const cb = element[callbackName];
|
|
3769
3840
|
if (typeof cb !== "function") {
|