@teamkeel/functions-runtime 0.436.0 → 0.437.0
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 +92 -188
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +96 -195
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -436,8 +436,6 @@ declare class RequestHeaders {
|
|
|
436
436
|
|
|
437
437
|
declare function handleRequest(request: any, config: any): Promise<any>;
|
|
438
438
|
|
|
439
|
-
declare function handleJob(request: any, config: any): Promise<any>;
|
|
440
|
-
|
|
441
439
|
declare function handleSubscriber(request: any, config: any): Promise<any>;
|
|
442
440
|
|
|
443
441
|
declare function handleRoute(request: any, config: any): Promise<any>;
|
|
@@ -1603,4 +1601,4 @@ type FlowListResult = {
|
|
|
1603
1601
|
};
|
|
1604
1602
|
};
|
|
1605
1603
|
|
|
1606
|
-
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FlowListOptions, type FlowListResult, type FlowRun, type FlowRunStatus, type FlowRunStep, FlowsAPI, type FuncWithConfig, type FunctionConfig, type Hardware, type IDWhereCondition, InlineFile, type ListResult, ModelAPI, NonRetriableError, type NullableHardware, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, type PartialPageInfo, Permissions, type Printer, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type Task, TaskAPI, type TaskCreateOptions, type TaskFlowFunction, type TaskStatus, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow,
|
|
1604
|
+
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FlowListOptions, type FlowListResult, type FlowRun, type FlowRunStatus, type FlowRunStep, FlowsAPI, type FuncWithConfig, type FunctionConfig, type Hardware, type IDWhereCondition, InlineFile, type ListResult, ModelAPI, NonRetriableError, type NullableHardware, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, type PartialPageInfo, Permissions, type Printer, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type Task, TaskAPI, type TaskCreateOptions, type TaskFlowFunction, type TaskStatus, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
package/dist/index.d.ts
CHANGED
|
@@ -436,8 +436,6 @@ declare class RequestHeaders {
|
|
|
436
436
|
|
|
437
437
|
declare function handleRequest(request: any, config: any): Promise<any>;
|
|
438
438
|
|
|
439
|
-
declare function handleJob(request: any, config: any): Promise<any>;
|
|
440
|
-
|
|
441
439
|
declare function handleSubscriber(request: any, config: any): Promise<any>;
|
|
442
440
|
|
|
443
441
|
declare function handleRoute(request: any, config: any): Promise<any>;
|
|
@@ -1603,4 +1601,4 @@ type FlowListResult = {
|
|
|
1603
1601
|
};
|
|
1604
1602
|
};
|
|
1605
1603
|
|
|
1606
|
-
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FlowListOptions, type FlowListResult, type FlowRun, type FlowRunStatus, type FlowRunStep, FlowsAPI, type FuncWithConfig, type FunctionConfig, type Hardware, type IDWhereCondition, InlineFile, type ListResult, ModelAPI, NonRetriableError, type NullableHardware, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, type PartialPageInfo, Permissions, type Printer, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type Task, TaskAPI, type TaskCreateOptions, type TaskFlowFunction, type TaskStatus, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow,
|
|
1604
|
+
export { type BooleanArrayQueryWhereCondition, type BooleanArrayWhereCondition, type BooleanWhereCondition, type ContextAPI, type DateArrayQueryWhereCondition, type DateArrayWhereCondition, type DateQueryInput, type DateWhereCondition, Duration, type DurationString, type DurationWhereCondition, ErrorPresets, type Errors, type ExtractStageKeys, File, type FlowConfig, type FlowConfigAPI, type FlowContext, type FlowFunction, type FlowListOptions, type FlowListResult, type FlowRun, type FlowRunStatus, type FlowRunStep, FlowsAPI, type FuncWithConfig, type FunctionConfig, type Hardware, type IDWhereCondition, InlineFile, type ListResult, ModelAPI, NonRetriableError, type NullableHardware, type NumberArrayQueryWhereCondition, type NumberArrayWhereCondition, type NumberWhereCondition, PERMISSION_STATE, type PageInfo, type PartialPageInfo, Permissions, type Printer, type RelativeDateString, RequestHeaders, type Response, RetryBackoffExponential, RetryBackoffLinear, RetryConstant, STEP_STATUS, STEP_TYPE, type SortDirection, type Step, type StringArrayQueryWhereCondition, type StringArrayWhereCondition, type StringWhereCondition, type Task, TaskAPI, type TaskCreateOptions, type TaskFlowFunction, type TaskStatus, type TimestampQueryInput, type UI, type UIApiResponses, checkBuiltInPermissions, createFlowContext, handleFlow, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
|
package/dist/index.js
CHANGED
|
@@ -1081,18 +1081,18 @@ var opMapping = {
|
|
|
1081
1081
|
notEquals: { op: "=", value: /* @__PURE__ */ __name((v) => sql2`NOT ${v}`, "value") }
|
|
1082
1082
|
}
|
|
1083
1083
|
};
|
|
1084
|
-
function applyWhereConditions(
|
|
1085
|
-
const conf =
|
|
1084
|
+
function applyWhereConditions(context5, qb, where = {}) {
|
|
1085
|
+
const conf = context5.tableConfig();
|
|
1086
1086
|
for (const key of Object.keys(where)) {
|
|
1087
1087
|
const v = where[key];
|
|
1088
1088
|
if (conf && conf[snakeCase(key)]) {
|
|
1089
1089
|
const rel = conf[snakeCase(key)];
|
|
1090
|
-
|
|
1091
|
-
qb = applyWhereConditions(
|
|
1090
|
+
context5.withJoin(rel.referencesTable, () => {
|
|
1091
|
+
qb = applyWhereConditions(context5, qb, v);
|
|
1092
1092
|
});
|
|
1093
1093
|
continue;
|
|
1094
1094
|
}
|
|
1095
|
-
const fieldName = `${
|
|
1095
|
+
const fieldName = `${context5.tableAlias()}.${snakeCase(key)}`;
|
|
1096
1096
|
if (Object.prototype.toString.call(v) !== "[object Object]") {
|
|
1097
1097
|
const operator = v === null || Array.isArray(v) ? sql2`is not distinct from` : "=";
|
|
1098
1098
|
qb = qb.where(fieldName, operator, sql2`${v}`);
|
|
@@ -1126,15 +1126,15 @@ function applyWhereConditions(context6, qb, where = {}) {
|
|
|
1126
1126
|
__name(applyWhereConditions, "applyWhereConditions");
|
|
1127
1127
|
|
|
1128
1128
|
// src/applyAdditionalQueryConstraints.js
|
|
1129
|
-
function applyLimit(
|
|
1129
|
+
function applyLimit(context5, qb, limit) {
|
|
1130
1130
|
return qb.limit(limit);
|
|
1131
1131
|
}
|
|
1132
1132
|
__name(applyLimit, "applyLimit");
|
|
1133
|
-
function applyOffset(
|
|
1133
|
+
function applyOffset(context5, qb, offset) {
|
|
1134
1134
|
return qb.offset(offset);
|
|
1135
1135
|
}
|
|
1136
1136
|
__name(applyOffset, "applyOffset");
|
|
1137
|
-
function applyOrderBy(
|
|
1137
|
+
function applyOrderBy(context5, qb, tableName, orderBy = {}) {
|
|
1138
1138
|
Object.entries(orderBy).forEach(([key, sortOrder]) => {
|
|
1139
1139
|
qb = qb.orderBy(`${tableName}.${snakeCase(key)}`, sortOrder.toLowerCase());
|
|
1140
1140
|
});
|
|
@@ -1143,41 +1143,41 @@ function applyOrderBy(context6, qb, tableName, orderBy = {}) {
|
|
|
1143
1143
|
__name(applyOrderBy, "applyOrderBy");
|
|
1144
1144
|
|
|
1145
1145
|
// src/applyJoins.js
|
|
1146
|
-
function applyJoins(
|
|
1147
|
-
const conf =
|
|
1146
|
+
function applyJoins(context5, qb, where) {
|
|
1147
|
+
const conf = context5.tableConfig();
|
|
1148
1148
|
if (!conf) {
|
|
1149
1149
|
return qb;
|
|
1150
1150
|
}
|
|
1151
|
-
const srcTable =
|
|
1151
|
+
const srcTable = context5.tableAlias();
|
|
1152
1152
|
for (const key of Object.keys(where)) {
|
|
1153
1153
|
const rel = conf[snakeCase(key)];
|
|
1154
1154
|
if (!rel) {
|
|
1155
1155
|
continue;
|
|
1156
1156
|
}
|
|
1157
1157
|
const targetTable = rel.referencesTable;
|
|
1158
|
-
if (
|
|
1158
|
+
if (context5.hasJoin(targetTable)) {
|
|
1159
1159
|
continue;
|
|
1160
1160
|
}
|
|
1161
|
-
|
|
1161
|
+
context5.withJoin(targetTable, () => {
|
|
1162
1162
|
switch (rel.relationshipType) {
|
|
1163
1163
|
case "hasMany":
|
|
1164
1164
|
qb = qb.innerJoin(
|
|
1165
|
-
`${targetTable} as ${
|
|
1165
|
+
`${targetTable} as ${context5.tableAlias()}`,
|
|
1166
1166
|
`${srcTable}.id`,
|
|
1167
|
-
`${
|
|
1167
|
+
`${context5.tableAlias()}.${rel.foreignKey}`
|
|
1168
1168
|
);
|
|
1169
1169
|
break;
|
|
1170
1170
|
case "belongsTo":
|
|
1171
1171
|
qb = qb.innerJoin(
|
|
1172
|
-
`${targetTable} as ${
|
|
1172
|
+
`${targetTable} as ${context5.tableAlias()}`,
|
|
1173
1173
|
`${srcTable}.${rel.foreignKey}`,
|
|
1174
|
-
`${
|
|
1174
|
+
`${context5.tableAlias()}.id`
|
|
1175
1175
|
);
|
|
1176
1176
|
break;
|
|
1177
1177
|
default:
|
|
1178
1178
|
throw new Error(`unknown relationshipType: ${rel.relationshipType}`);
|
|
1179
1179
|
}
|
|
1180
|
-
qb = applyJoins(
|
|
1180
|
+
qb = applyJoins(context5, qb, where[key]);
|
|
1181
1181
|
});
|
|
1182
1182
|
}
|
|
1183
1183
|
return qb;
|
|
@@ -1407,17 +1407,17 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1407
1407
|
* @param {import("./QueryContext").QueryContext} context
|
|
1408
1408
|
* @param {import("kysely").Kysely} db
|
|
1409
1409
|
*/
|
|
1410
|
-
constructor(tableName,
|
|
1410
|
+
constructor(tableName, context5, db) {
|
|
1411
1411
|
this._tableName = tableName;
|
|
1412
|
-
this._context =
|
|
1412
|
+
this._context = context5;
|
|
1413
1413
|
this._db = db;
|
|
1414
1414
|
this._modelName = upperCamelCase(this._tableName);
|
|
1415
1415
|
}
|
|
1416
1416
|
where(where) {
|
|
1417
|
-
const
|
|
1418
|
-
let builder = applyJoins(
|
|
1419
|
-
builder = applyWhereConditions(
|
|
1420
|
-
return new _QueryBuilder(this._tableName,
|
|
1417
|
+
const context5 = this._context.clone();
|
|
1418
|
+
let builder = applyJoins(context5, this._db, where);
|
|
1419
|
+
builder = applyWhereConditions(context5, builder, where);
|
|
1420
|
+
return new _QueryBuilder(this._tableName, context5, builder);
|
|
1421
1421
|
}
|
|
1422
1422
|
sql() {
|
|
1423
1423
|
return this._db.compile().sql;
|
|
@@ -1482,19 +1482,19 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1482
1482
|
const name = spanNameForModelAPI(this._modelName, "findMany");
|
|
1483
1483
|
const db = useDatabase();
|
|
1484
1484
|
return withSpan(name, async (span) => {
|
|
1485
|
-
const
|
|
1485
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1486
1486
|
let builder = db.selectFrom((qb) => {
|
|
1487
1487
|
return this._db.as(this._tableName);
|
|
1488
1488
|
}).selectAll();
|
|
1489
1489
|
if (params?.limit) {
|
|
1490
|
-
builder = applyLimit(
|
|
1490
|
+
builder = applyLimit(context5, builder, params.limit);
|
|
1491
1491
|
}
|
|
1492
1492
|
if (params?.offset) {
|
|
1493
|
-
builder = applyOffset(
|
|
1493
|
+
builder = applyOffset(context5, builder, params.offset);
|
|
1494
1494
|
}
|
|
1495
1495
|
if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
|
|
1496
1496
|
builder = applyOrderBy(
|
|
1497
|
-
|
|
1497
|
+
context5,
|
|
1498
1498
|
builder,
|
|
1499
1499
|
this._tableName,
|
|
1500
1500
|
params.orderBy
|
|
@@ -1528,7 +1528,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1528
1528
|
);
|
|
1529
1529
|
const db = useDatabase();
|
|
1530
1530
|
return withSpan(name, async (span) => {
|
|
1531
|
-
const
|
|
1531
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1532
1532
|
const isOffsetPagination = params.limit != null && params.limit > 0;
|
|
1533
1533
|
const isBackward = params.last != null && params.last > 0;
|
|
1534
1534
|
const DEFAULT_PAGE_SIZE = 50;
|
|
@@ -1576,7 +1576,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1576
1576
|
])
|
|
1577
1577
|
) : normalizedOrderBy;
|
|
1578
1578
|
builder = applyOrderBy(
|
|
1579
|
-
|
|
1579
|
+
context5,
|
|
1580
1580
|
builder,
|
|
1581
1581
|
this._tableName,
|
|
1582
1582
|
effectiveOrderBy
|
|
@@ -1649,10 +1649,10 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
1649
1649
|
}
|
|
1650
1650
|
}
|
|
1651
1651
|
if (limit != null) {
|
|
1652
|
-
builder = applyLimit(
|
|
1652
|
+
builder = applyLimit(context5, builder, limit);
|
|
1653
1653
|
}
|
|
1654
1654
|
if (isOffsetPagination && params.offset) {
|
|
1655
|
-
builder = applyOffset(
|
|
1655
|
+
builder = applyOffset(context5, builder, params.offset);
|
|
1656
1656
|
}
|
|
1657
1657
|
span.setAttribute("sql", builder.compile().sql);
|
|
1658
1658
|
let rows = await builder.execute();
|
|
@@ -1757,9 +1757,9 @@ var ModelAPI = class {
|
|
|
1757
1757
|
const db = useDatabase();
|
|
1758
1758
|
return withSpan(name, async (span) => {
|
|
1759
1759
|
let builder = db.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
|
|
1760
|
-
const
|
|
1761
|
-
builder = applyJoins(
|
|
1762
|
-
builder = applyWhereConditions(
|
|
1760
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1761
|
+
builder = applyJoins(context5, builder, where);
|
|
1762
|
+
builder = applyWhereConditions(context5, builder, where);
|
|
1763
1763
|
span.setAttribute("sql", builder.compile().sql);
|
|
1764
1764
|
const row = await builder.executeTakeFirst();
|
|
1765
1765
|
if (!row) {
|
|
@@ -1773,23 +1773,23 @@ var ModelAPI = class {
|
|
|
1773
1773
|
const db = useDatabase();
|
|
1774
1774
|
const where = params?.where || {};
|
|
1775
1775
|
return withSpan(name, async (span) => {
|
|
1776
|
-
const
|
|
1776
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1777
1777
|
let builder = db.selectFrom((qb) => {
|
|
1778
1778
|
let builder2 = qb.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
|
|
1779
|
-
builder2 = applyJoins(
|
|
1780
|
-
builder2 = applyWhereConditions(
|
|
1779
|
+
builder2 = applyJoins(context5, builder2, where);
|
|
1780
|
+
builder2 = applyWhereConditions(context5, builder2, where);
|
|
1781
1781
|
builder2 = builder2.as(this._tableName);
|
|
1782
1782
|
return builder2;
|
|
1783
1783
|
}).selectAll();
|
|
1784
1784
|
if (params?.limit) {
|
|
1785
|
-
builder = applyLimit(
|
|
1785
|
+
builder = applyLimit(context5, builder, params.limit);
|
|
1786
1786
|
}
|
|
1787
1787
|
if (params?.offset) {
|
|
1788
|
-
builder = applyOffset(
|
|
1788
|
+
builder = applyOffset(context5, builder, params.offset);
|
|
1789
1789
|
}
|
|
1790
1790
|
if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
|
|
1791
1791
|
builder = applyOrderBy(
|
|
1792
|
-
|
|
1792
|
+
context5,
|
|
1793
1793
|
builder,
|
|
1794
1794
|
this._tableName,
|
|
1795
1795
|
params.orderBy
|
|
@@ -1840,8 +1840,8 @@ var ModelAPI = class {
|
|
|
1840
1840
|
}
|
|
1841
1841
|
}
|
|
1842
1842
|
builder = builder.set(snakeCaseObject(row));
|
|
1843
|
-
const
|
|
1844
|
-
builder = applyWhereConditions(
|
|
1843
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1844
|
+
builder = applyWhereConditions(context5, builder, where);
|
|
1845
1845
|
span.setAttribute("sql", builder.compile().sql);
|
|
1846
1846
|
try {
|
|
1847
1847
|
const row2 = await builder.executeTakeFirstOrThrow();
|
|
@@ -1856,8 +1856,8 @@ var ModelAPI = class {
|
|
|
1856
1856
|
const db = useDatabase();
|
|
1857
1857
|
return withSpan(name, async (span) => {
|
|
1858
1858
|
let builder = db.deleteFrom(this._tableName).returning(["id"]);
|
|
1859
|
-
const
|
|
1860
|
-
builder = applyWhereConditions(
|
|
1859
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1860
|
+
builder = applyWhereConditions(context5, builder, where);
|
|
1861
1861
|
span.setAttribute("sql", builder.compile().sql);
|
|
1862
1862
|
try {
|
|
1863
1863
|
const row = await builder.executeTakeFirstOrThrow();
|
|
@@ -1870,10 +1870,10 @@ var ModelAPI = class {
|
|
|
1870
1870
|
where(where) {
|
|
1871
1871
|
const db = useDatabase();
|
|
1872
1872
|
let builder = db.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
|
|
1873
|
-
const
|
|
1874
|
-
builder = applyJoins(
|
|
1875
|
-
builder = applyWhereConditions(
|
|
1876
|
-
return new QueryBuilder(this._tableName,
|
|
1873
|
+
const context5 = new QueryContext([this._tableName], this._tableConfigMap);
|
|
1874
|
+
builder = applyJoins(context5, builder, where);
|
|
1875
|
+
builder = applyWhereConditions(context5, builder, where);
|
|
1876
|
+
return new QueryBuilder(this._tableName, context5, builder);
|
|
1877
1877
|
}
|
|
1878
1878
|
};
|
|
1879
1879
|
async function create(conn, tableName, tableConfigs, values) {
|
|
@@ -2701,7 +2701,6 @@ var PROTO_ACTION_TYPES = {
|
|
|
2701
2701
|
DELETE: "ACTION_TYPE_DELETE",
|
|
2702
2702
|
READ: "ACTION_TYPE_READ",
|
|
2703
2703
|
WRITE: "ACTION_TYPE_WRITE",
|
|
2704
|
-
JOB: "JOB_TYPE",
|
|
2705
2704
|
SUBSCRIBER: "SUBSCRIBER_TYPE",
|
|
2706
2705
|
FLOW: "FLOW_TYPE"
|
|
2707
2706
|
};
|
|
@@ -2878,7 +2877,7 @@ async function handleRequest(request, config) {
|
|
|
2878
2877
|
}
|
|
2879
2878
|
__name(handleRequest, "handleRequest");
|
|
2880
2879
|
|
|
2881
|
-
// src/
|
|
2880
|
+
// src/handleSubscriber.js
|
|
2882
2881
|
import {
|
|
2883
2882
|
createJSONRPCErrorResponse as createJSONRPCErrorResponse3,
|
|
2884
2883
|
createJSONRPCSuccessResponse as createJSONRPCSuccessResponse2,
|
|
@@ -2886,103 +2885,6 @@ import {
|
|
|
2886
2885
|
} from "json-rpc-2.0";
|
|
2887
2886
|
import * as opentelemetry3 from "@opentelemetry/api";
|
|
2888
2887
|
|
|
2889
|
-
// src/tryExecuteJob.js
|
|
2890
|
-
function tryExecuteJob({ db, permitted, request, functionConfig }, cb) {
|
|
2891
|
-
return withPermissions(permitted, async ({ getPermissionState }) => {
|
|
2892
|
-
let requiresTransaction = false;
|
|
2893
|
-
if (functionConfig?.dbTransaction !== void 0) {
|
|
2894
|
-
requiresTransaction = functionConfig.dbTransaction;
|
|
2895
|
-
}
|
|
2896
|
-
return withDatabase(db, requiresTransaction, async () => {
|
|
2897
|
-
await withAuditContext(request, async () => {
|
|
2898
|
-
return cb();
|
|
2899
|
-
});
|
|
2900
|
-
if (getPermissionState() === PERMISSION_STATE.UNPERMITTED) {
|
|
2901
|
-
throw new PermissionError(`Not permitted to access ${request.method}`);
|
|
2902
|
-
}
|
|
2903
|
-
});
|
|
2904
|
-
});
|
|
2905
|
-
}
|
|
2906
|
-
__name(tryExecuteJob, "tryExecuteJob");
|
|
2907
|
-
|
|
2908
|
-
// src/handleJob.js
|
|
2909
|
-
async function handleJob(request, config) {
|
|
2910
|
-
const activeContext = opentelemetry3.propagation.extract(
|
|
2911
|
-
opentelemetry3.context.active(),
|
|
2912
|
-
request.meta?.tracing
|
|
2913
|
-
);
|
|
2914
|
-
return opentelemetry3.context.with(activeContext, () => {
|
|
2915
|
-
return withSpan(request.method, async (span) => {
|
|
2916
|
-
let db = null;
|
|
2917
|
-
try {
|
|
2918
|
-
const { createJobContextAPI, jobs } = config;
|
|
2919
|
-
if (!jobs[request.method]) {
|
|
2920
|
-
const message = `job '${request.method}' does not exist or has not been implemented`;
|
|
2921
|
-
span.setStatus({
|
|
2922
|
-
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
2923
|
-
message
|
|
2924
|
-
});
|
|
2925
|
-
return createJSONRPCErrorResponse3(
|
|
2926
|
-
request.id,
|
|
2927
|
-
JSONRPCErrorCode2.MethodNotFound,
|
|
2928
|
-
message
|
|
2929
|
-
);
|
|
2930
|
-
}
|
|
2931
|
-
const ctx = createJobContextAPI({
|
|
2932
|
-
meta: request.meta
|
|
2933
|
-
});
|
|
2934
|
-
const permitted = request.meta && request.meta.permissionState.status === "granted" ? true : null;
|
|
2935
|
-
db = createDatabaseClient({
|
|
2936
|
-
connString: request.meta?.secrets?.KEEL_DB_CONN
|
|
2937
|
-
});
|
|
2938
|
-
const jobFunction = jobs[request.method];
|
|
2939
|
-
const actionType = PROTO_ACTION_TYPES.JOB;
|
|
2940
|
-
const functionConfig = jobFunction?.config ?? {};
|
|
2941
|
-
await tryExecuteJob(
|
|
2942
|
-
{ request, permitted, db, actionType, functionConfig },
|
|
2943
|
-
async () => {
|
|
2944
|
-
const inputs = parseInputs(request.params);
|
|
2945
|
-
return jobFunction(ctx, inputs);
|
|
2946
|
-
}
|
|
2947
|
-
);
|
|
2948
|
-
return createJSONRPCSuccessResponse2(request.id, null);
|
|
2949
|
-
} catch (e) {
|
|
2950
|
-
if (e instanceof Error) {
|
|
2951
|
-
span.recordException(e);
|
|
2952
|
-
span.setStatus({
|
|
2953
|
-
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
2954
|
-
message: e.message
|
|
2955
|
-
});
|
|
2956
|
-
return errorToJSONRPCResponse(request, e);
|
|
2957
|
-
}
|
|
2958
|
-
const message = JSON.stringify(e);
|
|
2959
|
-
span.setStatus({
|
|
2960
|
-
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
2961
|
-
message
|
|
2962
|
-
});
|
|
2963
|
-
return createJSONRPCErrorResponse3(
|
|
2964
|
-
request.id,
|
|
2965
|
-
RuntimeErrors.UnknownError,
|
|
2966
|
-
message
|
|
2967
|
-
);
|
|
2968
|
-
} finally {
|
|
2969
|
-
if (db) {
|
|
2970
|
-
await db.destroy();
|
|
2971
|
-
}
|
|
2972
|
-
}
|
|
2973
|
-
});
|
|
2974
|
-
});
|
|
2975
|
-
}
|
|
2976
|
-
__name(handleJob, "handleJob");
|
|
2977
|
-
|
|
2978
|
-
// src/handleSubscriber.js
|
|
2979
|
-
import {
|
|
2980
|
-
createJSONRPCErrorResponse as createJSONRPCErrorResponse4,
|
|
2981
|
-
createJSONRPCSuccessResponse as createJSONRPCSuccessResponse3,
|
|
2982
|
-
JSONRPCErrorCode as JSONRPCErrorCode3
|
|
2983
|
-
} from "json-rpc-2.0";
|
|
2984
|
-
import * as opentelemetry4 from "@opentelemetry/api";
|
|
2985
|
-
|
|
2986
2888
|
// src/tryExecuteSubscriber.js
|
|
2987
2889
|
function tryExecuteSubscriber({ request, db, functionConfig }, cb) {
|
|
2988
2890
|
let requiresTransaction = false;
|
|
@@ -2999,11 +2901,11 @@ __name(tryExecuteSubscriber, "tryExecuteSubscriber");
|
|
|
2999
2901
|
|
|
3000
2902
|
// src/handleSubscriber.js
|
|
3001
2903
|
async function handleSubscriber(request, config) {
|
|
3002
|
-
const activeContext =
|
|
3003
|
-
|
|
2904
|
+
const activeContext = opentelemetry3.propagation.extract(
|
|
2905
|
+
opentelemetry3.context.active(),
|
|
3004
2906
|
request.meta?.tracing
|
|
3005
2907
|
);
|
|
3006
|
-
return
|
|
2908
|
+
return opentelemetry3.context.with(activeContext, () => {
|
|
3007
2909
|
return withSpan(request.method, async (span) => {
|
|
3008
2910
|
let db = null;
|
|
3009
2911
|
try {
|
|
@@ -3011,12 +2913,12 @@ async function handleSubscriber(request, config) {
|
|
|
3011
2913
|
if (!subscribers[request.method]) {
|
|
3012
2914
|
const message = `subscriber '${request.method}' does not exist or has not been implemented`;
|
|
3013
2915
|
span.setStatus({
|
|
3014
|
-
code:
|
|
2916
|
+
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
3015
2917
|
message
|
|
3016
2918
|
});
|
|
3017
|
-
return
|
|
2919
|
+
return createJSONRPCErrorResponse3(
|
|
3018
2920
|
request.id,
|
|
3019
|
-
|
|
2921
|
+
JSONRPCErrorCode2.MethodNotFound,
|
|
3020
2922
|
message
|
|
3021
2923
|
);
|
|
3022
2924
|
}
|
|
@@ -3036,22 +2938,22 @@ async function handleSubscriber(request, config) {
|
|
|
3036
2938
|
return subscriberFunction(ctx, inputs);
|
|
3037
2939
|
}
|
|
3038
2940
|
);
|
|
3039
|
-
return
|
|
2941
|
+
return createJSONRPCSuccessResponse2(request.id, null);
|
|
3040
2942
|
} catch (e) {
|
|
3041
2943
|
if (e instanceof Error) {
|
|
3042
2944
|
span.recordException(e);
|
|
3043
2945
|
span.setStatus({
|
|
3044
|
-
code:
|
|
2946
|
+
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
3045
2947
|
message: e.message
|
|
3046
2948
|
});
|
|
3047
2949
|
return errorToJSONRPCResponse(request, e);
|
|
3048
2950
|
}
|
|
3049
2951
|
const message = JSON.stringify(e);
|
|
3050
2952
|
span.setStatus({
|
|
3051
|
-
code:
|
|
2953
|
+
code: opentelemetry3.SpanStatusCode.ERROR,
|
|
3052
2954
|
message
|
|
3053
2955
|
});
|
|
3054
|
-
return
|
|
2956
|
+
return createJSONRPCErrorResponse3(
|
|
3055
2957
|
request.id,
|
|
3056
2958
|
RuntimeErrors.UnknownError,
|
|
3057
2959
|
message
|
|
@@ -3068,17 +2970,17 @@ __name(handleSubscriber, "handleSubscriber");
|
|
|
3068
2970
|
|
|
3069
2971
|
// src/handleRoute.js
|
|
3070
2972
|
import {
|
|
3071
|
-
createJSONRPCErrorResponse as
|
|
3072
|
-
createJSONRPCSuccessResponse as
|
|
3073
|
-
JSONRPCErrorCode as
|
|
2973
|
+
createJSONRPCErrorResponse as createJSONRPCErrorResponse4,
|
|
2974
|
+
createJSONRPCSuccessResponse as createJSONRPCSuccessResponse3,
|
|
2975
|
+
JSONRPCErrorCode as JSONRPCErrorCode3
|
|
3074
2976
|
} from "json-rpc-2.0";
|
|
3075
|
-
import * as
|
|
2977
|
+
import * as opentelemetry4 from "@opentelemetry/api";
|
|
3076
2978
|
async function handleRoute(request, config) {
|
|
3077
|
-
const activeContext =
|
|
3078
|
-
|
|
2979
|
+
const activeContext = opentelemetry4.propagation.extract(
|
|
2980
|
+
opentelemetry4.context.active(),
|
|
3079
2981
|
request.meta?.tracing
|
|
3080
2982
|
);
|
|
3081
|
-
return
|
|
2983
|
+
return opentelemetry4.context.with(activeContext, () => {
|
|
3082
2984
|
return withSpan(request.method, async (span) => {
|
|
3083
2985
|
let db = null;
|
|
3084
2986
|
try {
|
|
@@ -3086,12 +2988,12 @@ async function handleRoute(request, config) {
|
|
|
3086
2988
|
if (!functions[request.method]) {
|
|
3087
2989
|
const message = `route function '${request.method}' does not exist or has not been implemented`;
|
|
3088
2990
|
span.setStatus({
|
|
3089
|
-
code:
|
|
2991
|
+
code: opentelemetry4.SpanStatusCode.ERROR,
|
|
3090
2992
|
message
|
|
3091
2993
|
});
|
|
3092
|
-
return
|
|
2994
|
+
return createJSONRPCErrorResponse4(
|
|
3093
2995
|
request.id,
|
|
3094
|
-
|
|
2996
|
+
JSONRPCErrorCode3.MethodNotFound,
|
|
3095
2997
|
message
|
|
3096
2998
|
);
|
|
3097
2999
|
}
|
|
@@ -3116,28 +3018,28 @@ async function handleRoute(request, config) {
|
|
|
3116
3018
|
if (result instanceof Error) {
|
|
3117
3019
|
span.recordException(result);
|
|
3118
3020
|
span.setStatus({
|
|
3119
|
-
code:
|
|
3021
|
+
code: opentelemetry4.SpanStatusCode.ERROR,
|
|
3120
3022
|
message: result.message
|
|
3121
3023
|
});
|
|
3122
3024
|
return errorToJSONRPCResponse(request, result);
|
|
3123
3025
|
}
|
|
3124
|
-
const response =
|
|
3026
|
+
const response = createJSONRPCSuccessResponse3(request.id, result);
|
|
3125
3027
|
return response;
|
|
3126
3028
|
} catch (e) {
|
|
3127
3029
|
if (e instanceof Error) {
|
|
3128
3030
|
span.recordException(e);
|
|
3129
3031
|
span.setStatus({
|
|
3130
|
-
code:
|
|
3032
|
+
code: opentelemetry4.SpanStatusCode.ERROR,
|
|
3131
3033
|
message: e.message
|
|
3132
3034
|
});
|
|
3133
3035
|
return errorToJSONRPCResponse(request, e);
|
|
3134
3036
|
}
|
|
3135
3037
|
const message = JSON.stringify(e);
|
|
3136
3038
|
span.setStatus({
|
|
3137
|
-
code:
|
|
3039
|
+
code: opentelemetry4.SpanStatusCode.ERROR,
|
|
3138
3040
|
message
|
|
3139
3041
|
});
|
|
3140
|
-
return
|
|
3042
|
+
return createJSONRPCErrorResponse4(
|
|
3141
3043
|
request.id,
|
|
3142
3044
|
RuntimeErrors.UnknownError,
|
|
3143
3045
|
message
|
|
@@ -3154,11 +3056,11 @@ __name(handleRoute, "handleRoute");
|
|
|
3154
3056
|
|
|
3155
3057
|
// src/handleFlow.ts
|
|
3156
3058
|
import {
|
|
3157
|
-
createJSONRPCErrorResponse as
|
|
3158
|
-
createJSONRPCSuccessResponse as
|
|
3159
|
-
JSONRPCErrorCode as
|
|
3059
|
+
createJSONRPCErrorResponse as createJSONRPCErrorResponse5,
|
|
3060
|
+
createJSONRPCSuccessResponse as createJSONRPCSuccessResponse4,
|
|
3061
|
+
JSONRPCErrorCode as JSONRPCErrorCode4
|
|
3160
3062
|
} from "json-rpc-2.0";
|
|
3161
|
-
import * as
|
|
3063
|
+
import * as opentelemetry5 from "@opentelemetry/api";
|
|
3162
3064
|
|
|
3163
3065
|
// src/tryExecuteFlow.js
|
|
3164
3066
|
function tryExecuteFlow(db, request, cb) {
|
|
@@ -4227,11 +4129,11 @@ __name(complete, "complete");
|
|
|
4227
4129
|
// src/handleFlow.ts
|
|
4228
4130
|
import { sentenceCase as sentenceCase2 } from "change-case";
|
|
4229
4131
|
async function handleFlow(request, config) {
|
|
4230
|
-
const activeContext =
|
|
4231
|
-
|
|
4132
|
+
const activeContext = opentelemetry5.propagation.extract(
|
|
4133
|
+
opentelemetry5.context.active(),
|
|
4232
4134
|
request.meta?.tracing
|
|
4233
4135
|
);
|
|
4234
|
-
return
|
|
4136
|
+
return opentelemetry5.context.with(activeContext, () => {
|
|
4235
4137
|
return withSpan(request.method, async (span) => {
|
|
4236
4138
|
span.setAttribute(KEEL_INTERNAL_ATTR, true);
|
|
4237
4139
|
let db = null;
|
|
@@ -4245,12 +4147,12 @@ async function handleFlow(request, config) {
|
|
|
4245
4147
|
if (!flows[request.method]) {
|
|
4246
4148
|
const message = `flow '${request.method}' does not exist or has not been implemented`;
|
|
4247
4149
|
span.setStatus({
|
|
4248
|
-
code:
|
|
4150
|
+
code: opentelemetry5.SpanStatusCode.ERROR,
|
|
4249
4151
|
message
|
|
4250
4152
|
});
|
|
4251
|
-
return
|
|
4153
|
+
return createJSONRPCErrorResponse5(
|
|
4252
4154
|
request.id,
|
|
4253
|
-
|
|
4155
|
+
JSONRPCErrorCode4.MethodNotFound,
|
|
4254
4156
|
message
|
|
4255
4157
|
);
|
|
4256
4158
|
}
|
|
@@ -4292,7 +4194,7 @@ async function handleFlow(request, config) {
|
|
|
4292
4194
|
} catch (e) {
|
|
4293
4195
|
if (e instanceof StepCreatedDisrupt) {
|
|
4294
4196
|
span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
|
|
4295
|
-
return
|
|
4197
|
+
return createJSONRPCSuccessResponse4(request.id, {
|
|
4296
4198
|
runId,
|
|
4297
4199
|
runCompleted: false,
|
|
4298
4200
|
config: flowConfig,
|
|
@@ -4301,12 +4203,12 @@ async function handleFlow(request, config) {
|
|
|
4301
4203
|
}
|
|
4302
4204
|
if (e instanceof CallbackDisrupt) {
|
|
4303
4205
|
if (e.error) {
|
|
4304
|
-
return
|
|
4206
|
+
return createJSONRPCErrorResponse5(request.id, 500, e.response);
|
|
4305
4207
|
}
|
|
4306
|
-
return
|
|
4208
|
+
return createJSONRPCSuccessResponse4(request.id, e.response);
|
|
4307
4209
|
}
|
|
4308
4210
|
if (e instanceof UIRenderDisrupt) {
|
|
4309
|
-
return
|
|
4211
|
+
return createJSONRPCSuccessResponse4(request.id, {
|
|
4310
4212
|
runId,
|
|
4311
4213
|
stepId: e.stepId,
|
|
4312
4214
|
config: flowConfig,
|
|
@@ -4316,19 +4218,19 @@ async function handleFlow(request, config) {
|
|
|
4316
4218
|
if (e instanceof Error) {
|
|
4317
4219
|
span.recordException(e);
|
|
4318
4220
|
span.setStatus({
|
|
4319
|
-
code:
|
|
4221
|
+
code: opentelemetry5.SpanStatusCode.ERROR,
|
|
4320
4222
|
message: e instanceof Error ? e.message : "unknown error"
|
|
4321
4223
|
});
|
|
4322
4224
|
}
|
|
4323
4225
|
if (e instanceof ExhuastedRetriesDisrupt) {
|
|
4324
|
-
return
|
|
4226
|
+
return createJSONRPCSuccessResponse4(request.id, {
|
|
4325
4227
|
runId,
|
|
4326
4228
|
runCompleted: true,
|
|
4327
4229
|
error: "flow failed due to exhausted step retries",
|
|
4328
4230
|
config: flowConfig
|
|
4329
4231
|
});
|
|
4330
4232
|
}
|
|
4331
|
-
return
|
|
4233
|
+
return createJSONRPCSuccessResponse4(request.id, {
|
|
4332
4234
|
runId,
|
|
4333
4235
|
runCompleted: true,
|
|
4334
4236
|
error: e instanceof Error ? e.message : "unknown error",
|
|
@@ -4356,7 +4258,7 @@ async function handleFlow(request, config) {
|
|
|
4356
4258
|
} else if (response) {
|
|
4357
4259
|
data = response;
|
|
4358
4260
|
}
|
|
4359
|
-
return
|
|
4261
|
+
return createJSONRPCSuccessResponse4(request.id, {
|
|
4360
4262
|
runId,
|
|
4361
4263
|
runCompleted: true,
|
|
4362
4264
|
data,
|
|
@@ -4366,17 +4268,17 @@ async function handleFlow(request, config) {
|
|
|
4366
4268
|
if (e instanceof Error) {
|
|
4367
4269
|
span.recordException(e);
|
|
4368
4270
|
span.setStatus({
|
|
4369
|
-
code:
|
|
4271
|
+
code: opentelemetry5.SpanStatusCode.ERROR,
|
|
4370
4272
|
message: e.message
|
|
4371
4273
|
});
|
|
4372
4274
|
return errorToJSONRPCResponse(request, e);
|
|
4373
4275
|
}
|
|
4374
4276
|
const message = JSON.stringify(e);
|
|
4375
4277
|
span.setStatus({
|
|
4376
|
-
code:
|
|
4278
|
+
code: opentelemetry5.SpanStatusCode.ERROR,
|
|
4377
4279
|
message
|
|
4378
4280
|
});
|
|
4379
|
-
return
|
|
4281
|
+
return createJSONRPCErrorResponse5(
|
|
4380
4282
|
request.id,
|
|
4381
4283
|
RuntimeErrors.UnknownError,
|
|
4382
4284
|
message
|
|
@@ -4418,7 +4320,6 @@ export {
|
|
|
4418
4320
|
checkBuiltInPermissions,
|
|
4419
4321
|
createFlowContext,
|
|
4420
4322
|
handleFlow,
|
|
4421
|
-
handleJob,
|
|
4422
4323
|
handleRequest,
|
|
4423
4324
|
handleRoute,
|
|
4424
4325
|
handleSubscriber,
|