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