@teamkeel/functions-runtime 0.438.0 → 0.439.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 CHANGED
@@ -51,6 +51,7 @@ __export(index_exports, {
51
51
  checkBuiltInPermissions: () => checkBuiltInPermissions,
52
52
  createFlowContext: () => createFlowContext,
53
53
  handleFlow: () => handleFlow,
54
+ handleJob: () => handleJob,
54
55
  handleRequest: () => handleRequest,
55
56
  handleRoute: () => handleRoute,
56
57
  handleSubscriber: () => handleSubscriber,
@@ -1132,18 +1133,18 @@ var opMapping = {
1132
1133
  notEquals: { op: "=", value: /* @__PURE__ */ __name((v) => import_kysely4.sql`NOT ${v}`, "value") }
1133
1134
  }
1134
1135
  };
1135
- function applyWhereConditions(context5, qb, where = {}) {
1136
- const conf = context5.tableConfig();
1136
+ function applyWhereConditions(context6, qb, where = {}) {
1137
+ const conf = context6.tableConfig();
1137
1138
  for (const key of Object.keys(where)) {
1138
1139
  const v = where[key];
1139
1140
  if (conf && conf[(0, import_change_case.snakeCase)(key)]) {
1140
1141
  const rel = conf[(0, import_change_case.snakeCase)(key)];
1141
- context5.withJoin(rel.referencesTable, () => {
1142
- qb = applyWhereConditions(context5, qb, v);
1142
+ context6.withJoin(rel.referencesTable, () => {
1143
+ qb = applyWhereConditions(context6, qb, v);
1143
1144
  });
1144
1145
  continue;
1145
1146
  }
1146
- const fieldName = `${context5.tableAlias()}.${(0, import_change_case.snakeCase)(key)}`;
1147
+ const fieldName = `${context6.tableAlias()}.${(0, import_change_case.snakeCase)(key)}`;
1147
1148
  if (Object.prototype.toString.call(v) !== "[object Object]") {
1148
1149
  const operator = v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=";
1149
1150
  qb = qb.where(fieldName, operator, import_kysely4.sql`${v}`);
@@ -1177,15 +1178,15 @@ function applyWhereConditions(context5, qb, where = {}) {
1177
1178
  __name(applyWhereConditions, "applyWhereConditions");
1178
1179
 
1179
1180
  // src/applyAdditionalQueryConstraints.js
1180
- function applyLimit(context5, qb, limit) {
1181
+ function applyLimit(context6, qb, limit) {
1181
1182
  return qb.limit(limit);
1182
1183
  }
1183
1184
  __name(applyLimit, "applyLimit");
1184
- function applyOffset(context5, qb, offset) {
1185
+ function applyOffset(context6, qb, offset) {
1185
1186
  return qb.offset(offset);
1186
1187
  }
1187
1188
  __name(applyOffset, "applyOffset");
1188
- function applyOrderBy(context5, qb, tableName, orderBy = {}) {
1189
+ function applyOrderBy(context6, qb, tableName, orderBy = {}) {
1189
1190
  Object.entries(orderBy).forEach(([key, sortOrder]) => {
1190
1191
  qb = qb.orderBy(`${tableName}.${(0, import_change_case.snakeCase)(key)}`, sortOrder.toLowerCase());
1191
1192
  });
@@ -1194,41 +1195,41 @@ function applyOrderBy(context5, qb, tableName, orderBy = {}) {
1194
1195
  __name(applyOrderBy, "applyOrderBy");
1195
1196
 
1196
1197
  // src/applyJoins.js
1197
- function applyJoins(context5, qb, where) {
1198
- const conf = context5.tableConfig();
1198
+ function applyJoins(context6, qb, where) {
1199
+ const conf = context6.tableConfig();
1199
1200
  if (!conf) {
1200
1201
  return qb;
1201
1202
  }
1202
- const srcTable = context5.tableAlias();
1203
+ const srcTable = context6.tableAlias();
1203
1204
  for (const key of Object.keys(where)) {
1204
1205
  const rel = conf[(0, import_change_case.snakeCase)(key)];
1205
1206
  if (!rel) {
1206
1207
  continue;
1207
1208
  }
1208
1209
  const targetTable = rel.referencesTable;
1209
- if (context5.hasJoin(targetTable)) {
1210
+ if (context6.hasJoin(targetTable)) {
1210
1211
  continue;
1211
1212
  }
1212
- context5.withJoin(targetTable, () => {
1213
+ context6.withJoin(targetTable, () => {
1213
1214
  switch (rel.relationshipType) {
1214
1215
  case "hasMany":
1215
1216
  qb = qb.innerJoin(
1216
- `${targetTable} as ${context5.tableAlias()}`,
1217
+ `${targetTable} as ${context6.tableAlias()}`,
1217
1218
  `${srcTable}.id`,
1218
- `${context5.tableAlias()}.${rel.foreignKey}`
1219
+ `${context6.tableAlias()}.${rel.foreignKey}`
1219
1220
  );
1220
1221
  break;
1221
1222
  case "belongsTo":
1222
1223
  qb = qb.innerJoin(
1223
- `${targetTable} as ${context5.tableAlias()}`,
1224
+ `${targetTable} as ${context6.tableAlias()}`,
1224
1225
  `${srcTable}.${rel.foreignKey}`,
1225
- `${context5.tableAlias()}.id`
1226
+ `${context6.tableAlias()}.id`
1226
1227
  );
1227
1228
  break;
1228
1229
  default:
1229
1230
  throw new Error(`unknown relationshipType: ${rel.relationshipType}`);
1230
1231
  }
1231
- qb = applyJoins(context5, qb, where[key]);
1232
+ qb = applyJoins(context6, qb, where[key]);
1232
1233
  });
1233
1234
  }
1234
1235
  return qb;
@@ -1458,17 +1459,17 @@ var QueryBuilder = class _QueryBuilder {
1458
1459
  * @param {import("./QueryContext").QueryContext} context
1459
1460
  * @param {import("kysely").Kysely} db
1460
1461
  */
1461
- constructor(tableName, context5, db) {
1462
+ constructor(tableName, context6, db) {
1462
1463
  this._tableName = tableName;
1463
- this._context = context5;
1464
+ this._context = context6;
1464
1465
  this._db = db;
1465
1466
  this._modelName = upperCamelCase(this._tableName);
1466
1467
  }
1467
1468
  where(where) {
1468
- const context5 = this._context.clone();
1469
- let builder = applyJoins(context5, this._db, where);
1470
- builder = applyWhereConditions(context5, builder, where);
1471
- return new _QueryBuilder(this._tableName, context5, builder);
1469
+ const context6 = this._context.clone();
1470
+ let builder = applyJoins(context6, this._db, where);
1471
+ builder = applyWhereConditions(context6, builder, where);
1472
+ return new _QueryBuilder(this._tableName, context6, builder);
1472
1473
  }
1473
1474
  sql() {
1474
1475
  return this._db.compile().sql;
@@ -1533,19 +1534,19 @@ var QueryBuilder = class _QueryBuilder {
1533
1534
  const name = spanNameForModelAPI(this._modelName, "findMany");
1534
1535
  const db = useDatabase();
1535
1536
  return withSpan(name, async (span) => {
1536
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1537
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1537
1538
  let builder = db.selectFrom((qb) => {
1538
1539
  return this._db.as(this._tableName);
1539
1540
  }).selectAll();
1540
1541
  if (params?.limit) {
1541
- builder = applyLimit(context5, builder, params.limit);
1542
+ builder = applyLimit(context6, builder, params.limit);
1542
1543
  }
1543
1544
  if (params?.offset) {
1544
- builder = applyOffset(context5, builder, params.offset);
1545
+ builder = applyOffset(context6, builder, params.offset);
1545
1546
  }
1546
1547
  if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
1547
1548
  builder = applyOrderBy(
1548
- context5,
1549
+ context6,
1549
1550
  builder,
1550
1551
  this._tableName,
1551
1552
  params.orderBy
@@ -1579,7 +1580,7 @@ var QueryBuilder = class _QueryBuilder {
1579
1580
  );
1580
1581
  const db = useDatabase();
1581
1582
  return withSpan(name, async (span) => {
1582
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1583
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1583
1584
  const isOffsetPagination = params.limit != null && params.limit > 0;
1584
1585
  const isBackward = params.last != null && params.last > 0;
1585
1586
  const DEFAULT_PAGE_SIZE = 50;
@@ -1627,7 +1628,7 @@ var QueryBuilder = class _QueryBuilder {
1627
1628
  ])
1628
1629
  ) : normalizedOrderBy;
1629
1630
  builder = applyOrderBy(
1630
- context5,
1631
+ context6,
1631
1632
  builder,
1632
1633
  this._tableName,
1633
1634
  effectiveOrderBy
@@ -1700,10 +1701,10 @@ var QueryBuilder = class _QueryBuilder {
1700
1701
  }
1701
1702
  }
1702
1703
  if (limit != null) {
1703
- builder = applyLimit(context5, builder, limit);
1704
+ builder = applyLimit(context6, builder, limit);
1704
1705
  }
1705
1706
  if (isOffsetPagination && params.offset) {
1706
- builder = applyOffset(context5, builder, params.offset);
1707
+ builder = applyOffset(context6, builder, params.offset);
1707
1708
  }
1708
1709
  span.setAttribute("sql", builder.compile().sql);
1709
1710
  let rows = await builder.execute();
@@ -1808,9 +1809,9 @@ var ModelAPI = class {
1808
1809
  const db = useDatabase();
1809
1810
  return withSpan(name, async (span) => {
1810
1811
  let builder = db.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
1811
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1812
- builder = applyJoins(context5, builder, where);
1813
- builder = applyWhereConditions(context5, builder, where);
1812
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1813
+ builder = applyJoins(context6, builder, where);
1814
+ builder = applyWhereConditions(context6, builder, where);
1814
1815
  span.setAttribute("sql", builder.compile().sql);
1815
1816
  const row = await builder.executeTakeFirst();
1816
1817
  if (!row) {
@@ -1824,23 +1825,23 @@ var ModelAPI = class {
1824
1825
  const db = useDatabase();
1825
1826
  const where = params?.where || {};
1826
1827
  return withSpan(name, async (span) => {
1827
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1828
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1828
1829
  let builder = db.selectFrom((qb) => {
1829
1830
  let builder2 = qb.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
1830
- builder2 = applyJoins(context5, builder2, where);
1831
- builder2 = applyWhereConditions(context5, builder2, where);
1831
+ builder2 = applyJoins(context6, builder2, where);
1832
+ builder2 = applyWhereConditions(context6, builder2, where);
1832
1833
  builder2 = builder2.as(this._tableName);
1833
1834
  return builder2;
1834
1835
  }).selectAll();
1835
1836
  if (params?.limit) {
1836
- builder = applyLimit(context5, builder, params.limit);
1837
+ builder = applyLimit(context6, builder, params.limit);
1837
1838
  }
1838
1839
  if (params?.offset) {
1839
- builder = applyOffset(context5, builder, params.offset);
1840
+ builder = applyOffset(context6, builder, params.offset);
1840
1841
  }
1841
1842
  if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
1842
1843
  builder = applyOrderBy(
1843
- context5,
1844
+ context6,
1844
1845
  builder,
1845
1846
  this._tableName,
1846
1847
  params.orderBy
@@ -1891,8 +1892,8 @@ var ModelAPI = class {
1891
1892
  }
1892
1893
  }
1893
1894
  builder = builder.set(snakeCaseObject(row));
1894
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1895
- builder = applyWhereConditions(context5, builder, where);
1895
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1896
+ builder = applyWhereConditions(context6, builder, where);
1896
1897
  span.setAttribute("sql", builder.compile().sql);
1897
1898
  try {
1898
1899
  const row2 = await builder.executeTakeFirstOrThrow();
@@ -1907,8 +1908,8 @@ var ModelAPI = class {
1907
1908
  const db = useDatabase();
1908
1909
  return withSpan(name, async (span) => {
1909
1910
  let builder = db.deleteFrom(this._tableName).returning(["id"]);
1910
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1911
- builder = applyWhereConditions(context5, builder, where);
1911
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1912
+ builder = applyWhereConditions(context6, builder, where);
1912
1913
  span.setAttribute("sql", builder.compile().sql);
1913
1914
  try {
1914
1915
  const row = await builder.executeTakeFirstOrThrow();
@@ -1921,10 +1922,10 @@ var ModelAPI = class {
1921
1922
  where(where) {
1922
1923
  const db = useDatabase();
1923
1924
  let builder = db.selectFrom(this._tableName).distinctOn(`${this._tableName}.id`).selectAll(this._tableName);
1924
- const context5 = new QueryContext([this._tableName], this._tableConfigMap);
1925
- builder = applyJoins(context5, builder, where);
1926
- builder = applyWhereConditions(context5, builder, where);
1927
- return new QueryBuilder(this._tableName, context5, builder);
1925
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1926
+ builder = applyJoins(context6, builder, where);
1927
+ builder = applyWhereConditions(context6, builder, where);
1928
+ return new QueryBuilder(this._tableName, context6, builder);
1928
1929
  }
1929
1930
  };
1930
1931
  async function create(conn, tableName, tableConfigs, values) {
@@ -2748,6 +2749,7 @@ var PROTO_ACTION_TYPES = {
2748
2749
  DELETE: "ACTION_TYPE_DELETE",
2749
2750
  READ: "ACTION_TYPE_READ",
2750
2751
  WRITE: "ACTION_TYPE_WRITE",
2752
+ JOB: "JOB_TYPE",
2751
2753
  SUBSCRIBER: "SUBSCRIBER_TYPE",
2752
2754
  FLOW: "FLOW_TYPE"
2753
2755
  };
@@ -2924,10 +2926,103 @@ async function handleRequest(request, config) {
2924
2926
  }
2925
2927
  __name(handleRequest, "handleRequest");
2926
2928
 
2927
- // src/handleSubscriber.js
2929
+ // src/handleJob.js
2928
2930
  var import_json_rpc_23 = require("json-rpc-2.0");
2929
2931
  var opentelemetry3 = __toESM(require("@opentelemetry/api"), 1);
2930
2932
 
2933
+ // src/tryExecuteJob.js
2934
+ function tryExecuteJob({ db, permitted, request, functionConfig }, cb) {
2935
+ return withPermissions(permitted, async ({ getPermissionState }) => {
2936
+ let requiresTransaction = false;
2937
+ if (functionConfig?.dbTransaction !== void 0) {
2938
+ requiresTransaction = functionConfig.dbTransaction;
2939
+ }
2940
+ return withDatabase(db, requiresTransaction, async () => {
2941
+ await withAuditContext(request, async () => {
2942
+ return cb();
2943
+ });
2944
+ if (getPermissionState() === PERMISSION_STATE.UNPERMITTED) {
2945
+ throw new PermissionError(`Not permitted to access ${request.method}`);
2946
+ }
2947
+ });
2948
+ });
2949
+ }
2950
+ __name(tryExecuteJob, "tryExecuteJob");
2951
+
2952
+ // src/handleJob.js
2953
+ async function handleJob(request, config) {
2954
+ const activeContext = opentelemetry3.propagation.extract(
2955
+ opentelemetry3.context.active(),
2956
+ request.meta?.tracing
2957
+ );
2958
+ return opentelemetry3.context.with(activeContext, () => {
2959
+ return withSpan(request.method, async (span) => {
2960
+ let db = null;
2961
+ try {
2962
+ const { createJobContextAPI, jobs } = config;
2963
+ if (!jobs[request.method]) {
2964
+ const message = `job '${request.method}' does not exist or has not been implemented`;
2965
+ span.setStatus({
2966
+ code: opentelemetry3.SpanStatusCode.ERROR,
2967
+ message
2968
+ });
2969
+ return (0, import_json_rpc_23.createJSONRPCErrorResponse)(
2970
+ request.id,
2971
+ import_json_rpc_23.JSONRPCErrorCode.MethodNotFound,
2972
+ message
2973
+ );
2974
+ }
2975
+ const ctx = createJobContextAPI({
2976
+ meta: request.meta
2977
+ });
2978
+ const permitted = request.meta && request.meta.permissionState.status === "granted" ? true : null;
2979
+ db = createDatabaseClient({
2980
+ connString: request.meta?.secrets?.KEEL_DB_CONN
2981
+ });
2982
+ const jobFunction = jobs[request.method];
2983
+ const actionType = PROTO_ACTION_TYPES.JOB;
2984
+ const functionConfig = jobFunction?.config ?? {};
2985
+ await tryExecuteJob(
2986
+ { request, permitted, db, actionType, functionConfig },
2987
+ async () => {
2988
+ const inputs = parseInputs(request.params);
2989
+ return jobFunction(ctx, inputs);
2990
+ }
2991
+ );
2992
+ return (0, import_json_rpc_23.createJSONRPCSuccessResponse)(request.id, null);
2993
+ } catch (e) {
2994
+ if (e instanceof Error) {
2995
+ span.recordException(e);
2996
+ span.setStatus({
2997
+ code: opentelemetry3.SpanStatusCode.ERROR,
2998
+ message: e.message
2999
+ });
3000
+ return errorToJSONRPCResponse(request, e);
3001
+ }
3002
+ const message = JSON.stringify(e);
3003
+ span.setStatus({
3004
+ code: opentelemetry3.SpanStatusCode.ERROR,
3005
+ message
3006
+ });
3007
+ return (0, import_json_rpc_23.createJSONRPCErrorResponse)(
3008
+ request.id,
3009
+ RuntimeErrors.UnknownError,
3010
+ message
3011
+ );
3012
+ } finally {
3013
+ if (db) {
3014
+ await db.destroy();
3015
+ }
3016
+ }
3017
+ });
3018
+ });
3019
+ }
3020
+ __name(handleJob, "handleJob");
3021
+
3022
+ // src/handleSubscriber.js
3023
+ var import_json_rpc_24 = require("json-rpc-2.0");
3024
+ var opentelemetry4 = __toESM(require("@opentelemetry/api"), 1);
3025
+
2931
3026
  // src/tryExecuteSubscriber.js
2932
3027
  function tryExecuteSubscriber({ request, db, functionConfig }, cb) {
2933
3028
  let requiresTransaction = false;
@@ -2944,11 +3039,11 @@ __name(tryExecuteSubscriber, "tryExecuteSubscriber");
2944
3039
 
2945
3040
  // src/handleSubscriber.js
2946
3041
  async function handleSubscriber(request, config) {
2947
- const activeContext = opentelemetry3.propagation.extract(
2948
- opentelemetry3.context.active(),
3042
+ const activeContext = opentelemetry4.propagation.extract(
3043
+ opentelemetry4.context.active(),
2949
3044
  request.meta?.tracing
2950
3045
  );
2951
- return opentelemetry3.context.with(activeContext, () => {
3046
+ return opentelemetry4.context.with(activeContext, () => {
2952
3047
  return withSpan(request.method, async (span) => {
2953
3048
  let db = null;
2954
3049
  try {
@@ -2956,12 +3051,12 @@ async function handleSubscriber(request, config) {
2956
3051
  if (!subscribers[request.method]) {
2957
3052
  const message = `subscriber '${request.method}' does not exist or has not been implemented`;
2958
3053
  span.setStatus({
2959
- code: opentelemetry3.SpanStatusCode.ERROR,
3054
+ code: opentelemetry4.SpanStatusCode.ERROR,
2960
3055
  message
2961
3056
  });
2962
- return (0, import_json_rpc_23.createJSONRPCErrorResponse)(
3057
+ return (0, import_json_rpc_24.createJSONRPCErrorResponse)(
2963
3058
  request.id,
2964
- import_json_rpc_23.JSONRPCErrorCode.MethodNotFound,
3059
+ import_json_rpc_24.JSONRPCErrorCode.MethodNotFound,
2965
3060
  message
2966
3061
  );
2967
3062
  }
@@ -2981,22 +3076,22 @@ async function handleSubscriber(request, config) {
2981
3076
  return subscriberFunction(ctx, inputs);
2982
3077
  }
2983
3078
  );
2984
- return (0, import_json_rpc_23.createJSONRPCSuccessResponse)(request.id, null);
3079
+ return (0, import_json_rpc_24.createJSONRPCSuccessResponse)(request.id, null);
2985
3080
  } catch (e) {
2986
3081
  if (e instanceof Error) {
2987
3082
  span.recordException(e);
2988
3083
  span.setStatus({
2989
- code: opentelemetry3.SpanStatusCode.ERROR,
3084
+ code: opentelemetry4.SpanStatusCode.ERROR,
2990
3085
  message: e.message
2991
3086
  });
2992
3087
  return errorToJSONRPCResponse(request, e);
2993
3088
  }
2994
3089
  const message = JSON.stringify(e);
2995
3090
  span.setStatus({
2996
- code: opentelemetry3.SpanStatusCode.ERROR,
3091
+ code: opentelemetry4.SpanStatusCode.ERROR,
2997
3092
  message
2998
3093
  });
2999
- return (0, import_json_rpc_23.createJSONRPCErrorResponse)(
3094
+ return (0, import_json_rpc_24.createJSONRPCErrorResponse)(
3000
3095
  request.id,
3001
3096
  RuntimeErrors.UnknownError,
3002
3097
  message
@@ -3012,14 +3107,14 @@ async function handleSubscriber(request, config) {
3012
3107
  __name(handleSubscriber, "handleSubscriber");
3013
3108
 
3014
3109
  // src/handleRoute.js
3015
- var import_json_rpc_24 = require("json-rpc-2.0");
3016
- var opentelemetry4 = __toESM(require("@opentelemetry/api"), 1);
3110
+ var import_json_rpc_25 = require("json-rpc-2.0");
3111
+ var opentelemetry5 = __toESM(require("@opentelemetry/api"), 1);
3017
3112
  async function handleRoute(request, config) {
3018
- const activeContext = opentelemetry4.propagation.extract(
3019
- opentelemetry4.context.active(),
3113
+ const activeContext = opentelemetry5.propagation.extract(
3114
+ opentelemetry5.context.active(),
3020
3115
  request.meta?.tracing
3021
3116
  );
3022
- return opentelemetry4.context.with(activeContext, () => {
3117
+ return opentelemetry5.context.with(activeContext, () => {
3023
3118
  return withSpan(request.method, async (span) => {
3024
3119
  let db = null;
3025
3120
  try {
@@ -3027,12 +3122,12 @@ async function handleRoute(request, config) {
3027
3122
  if (!functions[request.method]) {
3028
3123
  const message = `route function '${request.method}' does not exist or has not been implemented`;
3029
3124
  span.setStatus({
3030
- code: opentelemetry4.SpanStatusCode.ERROR,
3125
+ code: opentelemetry5.SpanStatusCode.ERROR,
3031
3126
  message
3032
3127
  });
3033
- return (0, import_json_rpc_24.createJSONRPCErrorResponse)(
3128
+ return (0, import_json_rpc_25.createJSONRPCErrorResponse)(
3034
3129
  request.id,
3035
- import_json_rpc_24.JSONRPCErrorCode.MethodNotFound,
3130
+ import_json_rpc_25.JSONRPCErrorCode.MethodNotFound,
3036
3131
  message
3037
3132
  );
3038
3133
  }
@@ -3057,28 +3152,28 @@ async function handleRoute(request, config) {
3057
3152
  if (result instanceof Error) {
3058
3153
  span.recordException(result);
3059
3154
  span.setStatus({
3060
- code: opentelemetry4.SpanStatusCode.ERROR,
3155
+ code: opentelemetry5.SpanStatusCode.ERROR,
3061
3156
  message: result.message
3062
3157
  });
3063
3158
  return errorToJSONRPCResponse(request, result);
3064
3159
  }
3065
- const response = (0, import_json_rpc_24.createJSONRPCSuccessResponse)(request.id, result);
3160
+ const response = (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, result);
3066
3161
  return response;
3067
3162
  } catch (e) {
3068
3163
  if (e instanceof Error) {
3069
3164
  span.recordException(e);
3070
3165
  span.setStatus({
3071
- code: opentelemetry4.SpanStatusCode.ERROR,
3166
+ code: opentelemetry5.SpanStatusCode.ERROR,
3072
3167
  message: e.message
3073
3168
  });
3074
3169
  return errorToJSONRPCResponse(request, e);
3075
3170
  }
3076
3171
  const message = JSON.stringify(e);
3077
3172
  span.setStatus({
3078
- code: opentelemetry4.SpanStatusCode.ERROR,
3173
+ code: opentelemetry5.SpanStatusCode.ERROR,
3079
3174
  message
3080
3175
  });
3081
- return (0, import_json_rpc_24.createJSONRPCErrorResponse)(
3176
+ return (0, import_json_rpc_25.createJSONRPCErrorResponse)(
3082
3177
  request.id,
3083
3178
  RuntimeErrors.UnknownError,
3084
3179
  message
@@ -3094,8 +3189,8 @@ async function handleRoute(request, config) {
3094
3189
  __name(handleRoute, "handleRoute");
3095
3190
 
3096
3191
  // src/handleFlow.ts
3097
- var import_json_rpc_25 = require("json-rpc-2.0");
3098
- var opentelemetry5 = __toESM(require("@opentelemetry/api"), 1);
3192
+ var import_json_rpc_26 = require("json-rpc-2.0");
3193
+ var opentelemetry6 = __toESM(require("@opentelemetry/api"), 1);
3099
3194
 
3100
3195
  // src/tryExecuteFlow.js
3101
3196
  function tryExecuteFlow(db, request, cb) {
@@ -4164,11 +4259,11 @@ __name(complete, "complete");
4164
4259
  // src/handleFlow.ts
4165
4260
  var import_change_case3 = require("change-case");
4166
4261
  async function handleFlow(request, config) {
4167
- const activeContext = opentelemetry5.propagation.extract(
4168
- opentelemetry5.context.active(),
4262
+ const activeContext = opentelemetry6.propagation.extract(
4263
+ opentelemetry6.context.active(),
4169
4264
  request.meta?.tracing
4170
4265
  );
4171
- return opentelemetry5.context.with(activeContext, () => {
4266
+ return opentelemetry6.context.with(activeContext, () => {
4172
4267
  return withSpan(request.method, async (span) => {
4173
4268
  span.setAttribute(KEEL_INTERNAL_ATTR, true);
4174
4269
  let db = null;
@@ -4182,12 +4277,12 @@ async function handleFlow(request, config) {
4182
4277
  if (!flows[request.method]) {
4183
4278
  const message = `flow '${request.method}' does not exist or has not been implemented`;
4184
4279
  span.setStatus({
4185
- code: opentelemetry5.SpanStatusCode.ERROR,
4280
+ code: opentelemetry6.SpanStatusCode.ERROR,
4186
4281
  message
4187
4282
  });
4188
- return (0, import_json_rpc_25.createJSONRPCErrorResponse)(
4283
+ return (0, import_json_rpc_26.createJSONRPCErrorResponse)(
4189
4284
  request.id,
4190
- import_json_rpc_25.JSONRPCErrorCode.MethodNotFound,
4285
+ import_json_rpc_26.JSONRPCErrorCode.MethodNotFound,
4191
4286
  message
4192
4287
  );
4193
4288
  }
@@ -4229,7 +4324,7 @@ async function handleFlow(request, config) {
4229
4324
  } catch (e) {
4230
4325
  if (e instanceof StepCreatedDisrupt) {
4231
4326
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4232
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, {
4327
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
4233
4328
  runId,
4234
4329
  runCompleted: false,
4235
4330
  config: flowConfig,
@@ -4238,12 +4333,12 @@ async function handleFlow(request, config) {
4238
4333
  }
4239
4334
  if (e instanceof CallbackDisrupt) {
4240
4335
  if (e.error) {
4241
- return (0, import_json_rpc_25.createJSONRPCErrorResponse)(request.id, 500, e.response);
4336
+ return (0, import_json_rpc_26.createJSONRPCErrorResponse)(request.id, 500, e.response);
4242
4337
  }
4243
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, e.response);
4338
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, e.response);
4244
4339
  }
4245
4340
  if (e instanceof UIRenderDisrupt) {
4246
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, {
4341
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
4247
4342
  runId,
4248
4343
  stepId: e.stepId,
4249
4344
  config: flowConfig,
@@ -4253,19 +4348,19 @@ async function handleFlow(request, config) {
4253
4348
  if (e instanceof Error) {
4254
4349
  span.recordException(e);
4255
4350
  span.setStatus({
4256
- code: opentelemetry5.SpanStatusCode.ERROR,
4351
+ code: opentelemetry6.SpanStatusCode.ERROR,
4257
4352
  message: e instanceof Error ? e.message : "unknown error"
4258
4353
  });
4259
4354
  }
4260
4355
  if (e instanceof ExhuastedRetriesDisrupt) {
4261
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, {
4356
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
4262
4357
  runId,
4263
4358
  runCompleted: true,
4264
4359
  error: "flow failed due to exhausted step retries",
4265
4360
  config: flowConfig
4266
4361
  });
4267
4362
  }
4268
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, {
4363
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
4269
4364
  runId,
4270
4365
  runCompleted: true,
4271
4366
  error: e instanceof Error ? e.message : "unknown error",
@@ -4293,7 +4388,7 @@ async function handleFlow(request, config) {
4293
4388
  } else if (response) {
4294
4389
  data = response;
4295
4390
  }
4296
- return (0, import_json_rpc_25.createJSONRPCSuccessResponse)(request.id, {
4391
+ return (0, import_json_rpc_26.createJSONRPCSuccessResponse)(request.id, {
4297
4392
  runId,
4298
4393
  runCompleted: true,
4299
4394
  data,
@@ -4303,17 +4398,17 @@ async function handleFlow(request, config) {
4303
4398
  if (e instanceof Error) {
4304
4399
  span.recordException(e);
4305
4400
  span.setStatus({
4306
- code: opentelemetry5.SpanStatusCode.ERROR,
4401
+ code: opentelemetry6.SpanStatusCode.ERROR,
4307
4402
  message: e.message
4308
4403
  });
4309
4404
  return errorToJSONRPCResponse(request, e);
4310
4405
  }
4311
4406
  const message = JSON.stringify(e);
4312
4407
  span.setStatus({
4313
- code: opentelemetry5.SpanStatusCode.ERROR,
4408
+ code: opentelemetry6.SpanStatusCode.ERROR,
4314
4409
  message
4315
4410
  });
4316
- return (0, import_json_rpc_25.createJSONRPCErrorResponse)(
4411
+ return (0, import_json_rpc_26.createJSONRPCErrorResponse)(
4317
4412
  request.id,
4318
4413
  RuntimeErrors.UnknownError,
4319
4414
  message
@@ -4356,6 +4451,7 @@ __name(ksuid, "ksuid");
4356
4451
  checkBuiltInPermissions,
4357
4452
  createFlowContext,
4358
4453
  handleFlow,
4454
+ handleJob,
4359
4455
  handleRequest,
4360
4456
  handleRoute,
4361
4457
  handleSubscriber,