@teamkeel/functions-runtime 0.438.0 → 0.438.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.d.cts CHANGED
@@ -436,6 +436,8 @@ 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
+
439
441
  declare function handleSubscriber(request: any, config: any): Promise<any>;
440
442
 
441
443
  declare function handleRoute(request: any, config: any): Promise<any>;
@@ -1601,4 +1603,4 @@ type FlowListResult = {
1601
1603
  };
1602
1604
  };
1603
1605
 
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 };
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, handleJob, handleRequest, handleRoute, handleSubscriber, ksuid, tracing, useDatabase };
package/dist/index.d.ts CHANGED
@@ -436,6 +436,8 @@ 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
+
439
441
  declare function handleSubscriber(request: any, config: any): Promise<any>;
440
442
 
441
443
  declare function handleRoute(request: any, config: any): Promise<any>;
@@ -1601,4 +1603,4 @@ type FlowListResult = {
1601
1603
  };
1602
1604
  };
1603
1605
 
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 };
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, handleJob, 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(context5, qb, where = {}) {
1085
- const conf = context5.tableConfig();
1084
+ function applyWhereConditions(context6, qb, where = {}) {
1085
+ const conf = context6.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
- context5.withJoin(rel.referencesTable, () => {
1091
- qb = applyWhereConditions(context5, qb, v);
1090
+ context6.withJoin(rel.referencesTable, () => {
1091
+ qb = applyWhereConditions(context6, qb, v);
1092
1092
  });
1093
1093
  continue;
1094
1094
  }
1095
- const fieldName = `${context5.tableAlias()}.${snakeCase(key)}`;
1095
+ const fieldName = `${context6.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(context5, qb, where = {}) {
1126
1126
  __name(applyWhereConditions, "applyWhereConditions");
1127
1127
 
1128
1128
  // src/applyAdditionalQueryConstraints.js
1129
- function applyLimit(context5, qb, limit) {
1129
+ function applyLimit(context6, qb, limit) {
1130
1130
  return qb.limit(limit);
1131
1131
  }
1132
1132
  __name(applyLimit, "applyLimit");
1133
- function applyOffset(context5, qb, offset) {
1133
+ function applyOffset(context6, qb, offset) {
1134
1134
  return qb.offset(offset);
1135
1135
  }
1136
1136
  __name(applyOffset, "applyOffset");
1137
- function applyOrderBy(context5, qb, tableName, orderBy = {}) {
1137
+ function applyOrderBy(context6, 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(context5, qb, tableName, orderBy = {}) {
1143
1143
  __name(applyOrderBy, "applyOrderBy");
1144
1144
 
1145
1145
  // src/applyJoins.js
1146
- function applyJoins(context5, qb, where) {
1147
- const conf = context5.tableConfig();
1146
+ function applyJoins(context6, qb, where) {
1147
+ const conf = context6.tableConfig();
1148
1148
  if (!conf) {
1149
1149
  return qb;
1150
1150
  }
1151
- const srcTable = context5.tableAlias();
1151
+ const srcTable = context6.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 (context5.hasJoin(targetTable)) {
1158
+ if (context6.hasJoin(targetTable)) {
1159
1159
  continue;
1160
1160
  }
1161
- context5.withJoin(targetTable, () => {
1161
+ context6.withJoin(targetTable, () => {
1162
1162
  switch (rel.relationshipType) {
1163
1163
  case "hasMany":
1164
1164
  qb = qb.innerJoin(
1165
- `${targetTable} as ${context5.tableAlias()}`,
1165
+ `${targetTable} as ${context6.tableAlias()}`,
1166
1166
  `${srcTable}.id`,
1167
- `${context5.tableAlias()}.${rel.foreignKey}`
1167
+ `${context6.tableAlias()}.${rel.foreignKey}`
1168
1168
  );
1169
1169
  break;
1170
1170
  case "belongsTo":
1171
1171
  qb = qb.innerJoin(
1172
- `${targetTable} as ${context5.tableAlias()}`,
1172
+ `${targetTable} as ${context6.tableAlias()}`,
1173
1173
  `${srcTable}.${rel.foreignKey}`,
1174
- `${context5.tableAlias()}.id`
1174
+ `${context6.tableAlias()}.id`
1175
1175
  );
1176
1176
  break;
1177
1177
  default:
1178
1178
  throw new Error(`unknown relationshipType: ${rel.relationshipType}`);
1179
1179
  }
1180
- qb = applyJoins(context5, qb, where[key]);
1180
+ qb = applyJoins(context6, 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, context5, db) {
1410
+ constructor(tableName, context6, db) {
1411
1411
  this._tableName = tableName;
1412
- this._context = context5;
1412
+ this._context = context6;
1413
1413
  this._db = db;
1414
1414
  this._modelName = upperCamelCase(this._tableName);
1415
1415
  }
1416
1416
  where(where) {
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);
1417
+ const context6 = this._context.clone();
1418
+ let builder = applyJoins(context6, this._db, where);
1419
+ builder = applyWhereConditions(context6, builder, where);
1420
+ return new _QueryBuilder(this._tableName, context6, 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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1485
+ const context6 = 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(context5, builder, params.limit);
1490
+ builder = applyLimit(context6, builder, params.limit);
1491
1491
  }
1492
1492
  if (params?.offset) {
1493
- builder = applyOffset(context5, builder, params.offset);
1493
+ builder = applyOffset(context6, builder, params.offset);
1494
1494
  }
1495
1495
  if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
1496
1496
  builder = applyOrderBy(
1497
- context5,
1497
+ context6,
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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1531
+ const context6 = 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
- context5,
1579
+ context6,
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(context5, builder, limit);
1652
+ builder = applyLimit(context6, builder, limit);
1653
1653
  }
1654
1654
  if (isOffsetPagination && params.offset) {
1655
- builder = applyOffset(context5, builder, params.offset);
1655
+ builder = applyOffset(context6, 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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1761
- builder = applyJoins(context5, builder, where);
1762
- builder = applyWhereConditions(context5, builder, where);
1760
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1761
+ builder = applyJoins(context6, builder, where);
1762
+ builder = applyWhereConditions(context6, 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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1776
+ const context6 = 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(context5, builder2, where);
1780
- builder2 = applyWhereConditions(context5, builder2, where);
1779
+ builder2 = applyJoins(context6, builder2, where);
1780
+ builder2 = applyWhereConditions(context6, builder2, where);
1781
1781
  builder2 = builder2.as(this._tableName);
1782
1782
  return builder2;
1783
1783
  }).selectAll();
1784
1784
  if (params?.limit) {
1785
- builder = applyLimit(context5, builder, params.limit);
1785
+ builder = applyLimit(context6, builder, params.limit);
1786
1786
  }
1787
1787
  if (params?.offset) {
1788
- builder = applyOffset(context5, builder, params.offset);
1788
+ builder = applyOffset(context6, builder, params.offset);
1789
1789
  }
1790
1790
  if (params?.orderBy !== void 0 && Object.keys(params?.orderBy).length > 0) {
1791
1791
  builder = applyOrderBy(
1792
- context5,
1792
+ context6,
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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1844
- builder = applyWhereConditions(context5, builder, where);
1843
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1844
+ builder = applyWhereConditions(context6, 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 context5 = new QueryContext([this._tableName], this._tableConfigMap);
1860
- builder = applyWhereConditions(context5, builder, where);
1859
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1860
+ builder = applyWhereConditions(context6, 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 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);
1873
+ const context6 = new QueryContext([this._tableName], this._tableConfigMap);
1874
+ builder = applyJoins(context6, builder, where);
1875
+ builder = applyWhereConditions(context6, builder, where);
1876
+ return new QueryBuilder(this._tableName, context6, builder);
1877
1877
  }
1878
1878
  };
1879
1879
  async function create(conn, tableName, tableConfigs, values) {
@@ -2701,6 +2701,7 @@ 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",
2704
2705
  SUBSCRIBER: "SUBSCRIBER_TYPE",
2705
2706
  FLOW: "FLOW_TYPE"
2706
2707
  };
@@ -2877,7 +2878,7 @@ async function handleRequest(request, config) {
2877
2878
  }
2878
2879
  __name(handleRequest, "handleRequest");
2879
2880
 
2880
- // src/handleSubscriber.js
2881
+ // src/handleJob.js
2881
2882
  import {
2882
2883
  createJSONRPCErrorResponse as createJSONRPCErrorResponse3,
2883
2884
  createJSONRPCSuccessResponse as createJSONRPCSuccessResponse2,
@@ -2885,6 +2886,103 @@ import {
2885
2886
  } from "json-rpc-2.0";
2886
2887
  import * as opentelemetry3 from "@opentelemetry/api";
2887
2888
 
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
+
2888
2986
  // src/tryExecuteSubscriber.js
2889
2987
  function tryExecuteSubscriber({ request, db, functionConfig }, cb) {
2890
2988
  let requiresTransaction = false;
@@ -2901,11 +2999,11 @@ __name(tryExecuteSubscriber, "tryExecuteSubscriber");
2901
2999
 
2902
3000
  // src/handleSubscriber.js
2903
3001
  async function handleSubscriber(request, config) {
2904
- const activeContext = opentelemetry3.propagation.extract(
2905
- opentelemetry3.context.active(),
3002
+ const activeContext = opentelemetry4.propagation.extract(
3003
+ opentelemetry4.context.active(),
2906
3004
  request.meta?.tracing
2907
3005
  );
2908
- return opentelemetry3.context.with(activeContext, () => {
3006
+ return opentelemetry4.context.with(activeContext, () => {
2909
3007
  return withSpan(request.method, async (span) => {
2910
3008
  let db = null;
2911
3009
  try {
@@ -2913,12 +3011,12 @@ async function handleSubscriber(request, config) {
2913
3011
  if (!subscribers[request.method]) {
2914
3012
  const message = `subscriber '${request.method}' does not exist or has not been implemented`;
2915
3013
  span.setStatus({
2916
- code: opentelemetry3.SpanStatusCode.ERROR,
3014
+ code: opentelemetry4.SpanStatusCode.ERROR,
2917
3015
  message
2918
3016
  });
2919
- return createJSONRPCErrorResponse3(
3017
+ return createJSONRPCErrorResponse4(
2920
3018
  request.id,
2921
- JSONRPCErrorCode2.MethodNotFound,
3019
+ JSONRPCErrorCode3.MethodNotFound,
2922
3020
  message
2923
3021
  );
2924
3022
  }
@@ -2938,22 +3036,22 @@ async function handleSubscriber(request, config) {
2938
3036
  return subscriberFunction(ctx, inputs);
2939
3037
  }
2940
3038
  );
2941
- return createJSONRPCSuccessResponse2(request.id, null);
3039
+ return createJSONRPCSuccessResponse3(request.id, null);
2942
3040
  } catch (e) {
2943
3041
  if (e instanceof Error) {
2944
3042
  span.recordException(e);
2945
3043
  span.setStatus({
2946
- code: opentelemetry3.SpanStatusCode.ERROR,
3044
+ code: opentelemetry4.SpanStatusCode.ERROR,
2947
3045
  message: e.message
2948
3046
  });
2949
3047
  return errorToJSONRPCResponse(request, e);
2950
3048
  }
2951
3049
  const message = JSON.stringify(e);
2952
3050
  span.setStatus({
2953
- code: opentelemetry3.SpanStatusCode.ERROR,
3051
+ code: opentelemetry4.SpanStatusCode.ERROR,
2954
3052
  message
2955
3053
  });
2956
- return createJSONRPCErrorResponse3(
3054
+ return createJSONRPCErrorResponse4(
2957
3055
  request.id,
2958
3056
  RuntimeErrors.UnknownError,
2959
3057
  message
@@ -2970,17 +3068,17 @@ __name(handleSubscriber, "handleSubscriber");
2970
3068
 
2971
3069
  // src/handleRoute.js
2972
3070
  import {
2973
- createJSONRPCErrorResponse as createJSONRPCErrorResponse4,
2974
- createJSONRPCSuccessResponse as createJSONRPCSuccessResponse3,
2975
- JSONRPCErrorCode as JSONRPCErrorCode3
3071
+ createJSONRPCErrorResponse as createJSONRPCErrorResponse5,
3072
+ createJSONRPCSuccessResponse as createJSONRPCSuccessResponse4,
3073
+ JSONRPCErrorCode as JSONRPCErrorCode4
2976
3074
  } from "json-rpc-2.0";
2977
- import * as opentelemetry4 from "@opentelemetry/api";
3075
+ import * as opentelemetry5 from "@opentelemetry/api";
2978
3076
  async function handleRoute(request, config) {
2979
- const activeContext = opentelemetry4.propagation.extract(
2980
- opentelemetry4.context.active(),
3077
+ const activeContext = opentelemetry5.propagation.extract(
3078
+ opentelemetry5.context.active(),
2981
3079
  request.meta?.tracing
2982
3080
  );
2983
- return opentelemetry4.context.with(activeContext, () => {
3081
+ return opentelemetry5.context.with(activeContext, () => {
2984
3082
  return withSpan(request.method, async (span) => {
2985
3083
  let db = null;
2986
3084
  try {
@@ -2988,12 +3086,12 @@ async function handleRoute(request, config) {
2988
3086
  if (!functions[request.method]) {
2989
3087
  const message = `route function '${request.method}' does not exist or has not been implemented`;
2990
3088
  span.setStatus({
2991
- code: opentelemetry4.SpanStatusCode.ERROR,
3089
+ code: opentelemetry5.SpanStatusCode.ERROR,
2992
3090
  message
2993
3091
  });
2994
- return createJSONRPCErrorResponse4(
3092
+ return createJSONRPCErrorResponse5(
2995
3093
  request.id,
2996
- JSONRPCErrorCode3.MethodNotFound,
3094
+ JSONRPCErrorCode4.MethodNotFound,
2997
3095
  message
2998
3096
  );
2999
3097
  }
@@ -3018,28 +3116,28 @@ async function handleRoute(request, config) {
3018
3116
  if (result instanceof Error) {
3019
3117
  span.recordException(result);
3020
3118
  span.setStatus({
3021
- code: opentelemetry4.SpanStatusCode.ERROR,
3119
+ code: opentelemetry5.SpanStatusCode.ERROR,
3022
3120
  message: result.message
3023
3121
  });
3024
3122
  return errorToJSONRPCResponse(request, result);
3025
3123
  }
3026
- const response = createJSONRPCSuccessResponse3(request.id, result);
3124
+ const response = createJSONRPCSuccessResponse4(request.id, result);
3027
3125
  return response;
3028
3126
  } catch (e) {
3029
3127
  if (e instanceof Error) {
3030
3128
  span.recordException(e);
3031
3129
  span.setStatus({
3032
- code: opentelemetry4.SpanStatusCode.ERROR,
3130
+ code: opentelemetry5.SpanStatusCode.ERROR,
3033
3131
  message: e.message
3034
3132
  });
3035
3133
  return errorToJSONRPCResponse(request, e);
3036
3134
  }
3037
3135
  const message = JSON.stringify(e);
3038
3136
  span.setStatus({
3039
- code: opentelemetry4.SpanStatusCode.ERROR,
3137
+ code: opentelemetry5.SpanStatusCode.ERROR,
3040
3138
  message
3041
3139
  });
3042
- return createJSONRPCErrorResponse4(
3140
+ return createJSONRPCErrorResponse5(
3043
3141
  request.id,
3044
3142
  RuntimeErrors.UnknownError,
3045
3143
  message
@@ -3056,11 +3154,11 @@ __name(handleRoute, "handleRoute");
3056
3154
 
3057
3155
  // src/handleFlow.ts
3058
3156
  import {
3059
- createJSONRPCErrorResponse as createJSONRPCErrorResponse5,
3060
- createJSONRPCSuccessResponse as createJSONRPCSuccessResponse4,
3061
- JSONRPCErrorCode as JSONRPCErrorCode4
3157
+ createJSONRPCErrorResponse as createJSONRPCErrorResponse6,
3158
+ createJSONRPCSuccessResponse as createJSONRPCSuccessResponse5,
3159
+ JSONRPCErrorCode as JSONRPCErrorCode5
3062
3160
  } from "json-rpc-2.0";
3063
- import * as opentelemetry5 from "@opentelemetry/api";
3161
+ import * as opentelemetry6 from "@opentelemetry/api";
3064
3162
 
3065
3163
  // src/tryExecuteFlow.js
3066
3164
  function tryExecuteFlow(db, request, cb) {
@@ -4129,11 +4227,11 @@ __name(complete, "complete");
4129
4227
  // src/handleFlow.ts
4130
4228
  import { sentenceCase as sentenceCase2 } from "change-case";
4131
4229
  async function handleFlow(request, config) {
4132
- const activeContext = opentelemetry5.propagation.extract(
4133
- opentelemetry5.context.active(),
4230
+ const activeContext = opentelemetry6.propagation.extract(
4231
+ opentelemetry6.context.active(),
4134
4232
  request.meta?.tracing
4135
4233
  );
4136
- return opentelemetry5.context.with(activeContext, () => {
4234
+ return opentelemetry6.context.with(activeContext, () => {
4137
4235
  return withSpan(request.method, async (span) => {
4138
4236
  span.setAttribute(KEEL_INTERNAL_ATTR, true);
4139
4237
  let db = null;
@@ -4147,12 +4245,12 @@ async function handleFlow(request, config) {
4147
4245
  if (!flows[request.method]) {
4148
4246
  const message = `flow '${request.method}' does not exist or has not been implemented`;
4149
4247
  span.setStatus({
4150
- code: opentelemetry5.SpanStatusCode.ERROR,
4248
+ code: opentelemetry6.SpanStatusCode.ERROR,
4151
4249
  message
4152
4250
  });
4153
- return createJSONRPCErrorResponse5(
4251
+ return createJSONRPCErrorResponse6(
4154
4252
  request.id,
4155
- JSONRPCErrorCode4.MethodNotFound,
4253
+ JSONRPCErrorCode5.MethodNotFound,
4156
4254
  message
4157
4255
  );
4158
4256
  }
@@ -4194,7 +4292,7 @@ async function handleFlow(request, config) {
4194
4292
  } catch (e) {
4195
4293
  if (e instanceof StepCreatedDisrupt) {
4196
4294
  span.setAttribute(KEEL_INTERNAL_ATTR, KEEL_INTERNAL_CHILDREN);
4197
- return createJSONRPCSuccessResponse4(request.id, {
4295
+ return createJSONRPCSuccessResponse5(request.id, {
4198
4296
  runId,
4199
4297
  runCompleted: false,
4200
4298
  config: flowConfig,
@@ -4203,12 +4301,12 @@ async function handleFlow(request, config) {
4203
4301
  }
4204
4302
  if (e instanceof CallbackDisrupt) {
4205
4303
  if (e.error) {
4206
- return createJSONRPCErrorResponse5(request.id, 500, e.response);
4304
+ return createJSONRPCErrorResponse6(request.id, 500, e.response);
4207
4305
  }
4208
- return createJSONRPCSuccessResponse4(request.id, e.response);
4306
+ return createJSONRPCSuccessResponse5(request.id, e.response);
4209
4307
  }
4210
4308
  if (e instanceof UIRenderDisrupt) {
4211
- return createJSONRPCSuccessResponse4(request.id, {
4309
+ return createJSONRPCSuccessResponse5(request.id, {
4212
4310
  runId,
4213
4311
  stepId: e.stepId,
4214
4312
  config: flowConfig,
@@ -4218,19 +4316,19 @@ async function handleFlow(request, config) {
4218
4316
  if (e instanceof Error) {
4219
4317
  span.recordException(e);
4220
4318
  span.setStatus({
4221
- code: opentelemetry5.SpanStatusCode.ERROR,
4319
+ code: opentelemetry6.SpanStatusCode.ERROR,
4222
4320
  message: e instanceof Error ? e.message : "unknown error"
4223
4321
  });
4224
4322
  }
4225
4323
  if (e instanceof ExhuastedRetriesDisrupt) {
4226
- return createJSONRPCSuccessResponse4(request.id, {
4324
+ return createJSONRPCSuccessResponse5(request.id, {
4227
4325
  runId,
4228
4326
  runCompleted: true,
4229
4327
  error: "flow failed due to exhausted step retries",
4230
4328
  config: flowConfig
4231
4329
  });
4232
4330
  }
4233
- return createJSONRPCSuccessResponse4(request.id, {
4331
+ return createJSONRPCSuccessResponse5(request.id, {
4234
4332
  runId,
4235
4333
  runCompleted: true,
4236
4334
  error: e instanceof Error ? e.message : "unknown error",
@@ -4258,7 +4356,7 @@ async function handleFlow(request, config) {
4258
4356
  } else if (response) {
4259
4357
  data = response;
4260
4358
  }
4261
- return createJSONRPCSuccessResponse4(request.id, {
4359
+ return createJSONRPCSuccessResponse5(request.id, {
4262
4360
  runId,
4263
4361
  runCompleted: true,
4264
4362
  data,
@@ -4268,17 +4366,17 @@ async function handleFlow(request, config) {
4268
4366
  if (e instanceof Error) {
4269
4367
  span.recordException(e);
4270
4368
  span.setStatus({
4271
- code: opentelemetry5.SpanStatusCode.ERROR,
4369
+ code: opentelemetry6.SpanStatusCode.ERROR,
4272
4370
  message: e.message
4273
4371
  });
4274
4372
  return errorToJSONRPCResponse(request, e);
4275
4373
  }
4276
4374
  const message = JSON.stringify(e);
4277
4375
  span.setStatus({
4278
- code: opentelemetry5.SpanStatusCode.ERROR,
4376
+ code: opentelemetry6.SpanStatusCode.ERROR,
4279
4377
  message
4280
4378
  });
4281
- return createJSONRPCErrorResponse5(
4379
+ return createJSONRPCErrorResponse6(
4282
4380
  request.id,
4283
4381
  RuntimeErrors.UnknownError,
4284
4382
  message
@@ -4320,6 +4418,7 @@ export {
4320
4418
  checkBuiltInPermissions,
4321
4419
  createFlowContext,
4322
4420
  handleFlow,
4421
+ handleJob,
4323
4422
  handleRequest,
4324
4423
  handleRoute,
4325
4424
  handleSubscriber,