@teamkeel/functions-runtime 0.455.2 → 0.456.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
@@ -208,7 +208,10 @@ var KeelCamelCasePlugin = class {
208
208
  }
209
209
  constructor(opt) {
210
210
  this.opt = opt;
211
- this.CamelCasePlugin = new import_kysely2.CamelCasePlugin(opt);
211
+ this.CamelCasePlugin = new import_kysely2.CamelCasePlugin({
212
+ ...opt,
213
+ underscoreBeforeDigits: true
214
+ });
212
215
  }
213
216
  transformQuery(args) {
214
217
  return this.CamelCasePlugin.transformQuery(args);
@@ -1049,17 +1052,30 @@ var import_kysely4 = require("kysely");
1049
1052
 
1050
1053
  // src/casing.js
1051
1054
  var import_change_case = require("change-case");
1055
+ var splitRegexp = [
1056
+ /([a-z0-9])([A-Z])/g,
1057
+ /([A-Z])([A-Z][a-z])/g,
1058
+ /([a-zA-Z])([0-9])/g
1059
+ ];
1060
+ function camelCaseTransform(input, index) {
1061
+ if (index === 0) return input.toLowerCase();
1062
+ const firstChar = input.charAt(0);
1063
+ const lowerChars = input.substr(1).toLowerCase();
1064
+ return `${firstChar.toUpperCase()}${lowerChars}`;
1065
+ }
1066
+ __name(camelCaseTransform, "camelCaseTransform");
1067
+ function snakeCase(str) {
1068
+ return (0, import_change_case.snakeCase)(str, { splitRegexp });
1069
+ }
1070
+ __name(snakeCase, "snakeCase");
1071
+ function camelCase(str) {
1072
+ return (0, import_change_case.camelCase)(str, { transform: camelCaseTransform, splitRegexp });
1073
+ }
1074
+ __name(camelCase, "camelCase");
1052
1075
  function camelCaseObject(obj = {}) {
1053
1076
  const r = {};
1054
1077
  for (const key of Object.keys(obj)) {
1055
- r[(0, import_change_case.camelCase)(key, {
1056
- transform: camelCaseTransform,
1057
- splitRegexp: [
1058
- /([a-z0-9])([A-Z])/g,
1059
- /([A-Z])([A-Z][a-z])/g,
1060
- /([a-zA-Z])([0-9])/g
1061
- ]
1062
- })] = obj[key];
1078
+ r[camelCase(key)] = obj[key];
1063
1079
  }
1064
1080
  return r;
1065
1081
  }
@@ -1067,29 +1083,16 @@ __name(camelCaseObject, "camelCaseObject");
1067
1083
  function snakeCaseObject(obj) {
1068
1084
  const r = {};
1069
1085
  for (const key of Object.keys(obj)) {
1070
- r[(0, import_change_case.snakeCase)(key, {
1071
- splitRegexp: [
1072
- /([a-z0-9])([A-Z])/g,
1073
- /([A-Z])([A-Z][a-z])/g,
1074
- /([a-zA-Z])([0-9])/g
1075
- ]
1076
- })] = obj[key];
1086
+ r[snakeCase(key)] = obj[key];
1077
1087
  }
1078
1088
  return r;
1079
1089
  }
1080
1090
  __name(snakeCaseObject, "snakeCaseObject");
1081
1091
  function upperCamelCase(s) {
1082
- s = (0, import_change_case.camelCase)(s);
1092
+ s = camelCase(s);
1083
1093
  return s[0].toUpperCase() + s.substring(1);
1084
1094
  }
1085
1095
  __name(upperCamelCase, "upperCamelCase");
1086
- function camelCaseTransform(input, index) {
1087
- if (index === 0) return input.toLowerCase();
1088
- const firstChar = input.charAt(0);
1089
- const lowerChars = input.substr(1).toLowerCase();
1090
- return `${firstChar.toUpperCase()}${lowerChars}`;
1091
- }
1092
- __name(camelCaseTransform, "camelCaseTransform");
1093
1096
 
1094
1097
  // src/TimePeriod.js
1095
1098
  var TimePeriod = class _TimePeriod {
@@ -1238,14 +1241,14 @@ function applyWhereConditions(context7, qb, where = {}) {
1238
1241
  const conf = context7.tableConfig();
1239
1242
  for (const key of Object.keys(where)) {
1240
1243
  const v = where[key];
1241
- if (conf && conf[(0, import_change_case.snakeCase)(key)]) {
1242
- const rel = conf[(0, import_change_case.snakeCase)(key)];
1244
+ if (conf && conf[snakeCase(key)]) {
1245
+ const rel = conf[snakeCase(key)];
1243
1246
  context7.withJoin(rel.referencesTable, () => {
1244
1247
  qb = applyWhereConditions(context7, qb, v);
1245
1248
  });
1246
1249
  continue;
1247
1250
  }
1248
- const fieldName = `${context7.tableAlias()}.${(0, import_change_case.snakeCase)(key)}`;
1251
+ const fieldName = `${context7.tableAlias()}.${snakeCase(key)}`;
1249
1252
  if (Object.prototype.toString.call(v) !== "[object Object]") {
1250
1253
  const operator = v === null || Array.isArray(v) ? import_kysely4.sql`is not distinct from` : "=";
1251
1254
  qb = qb.where(fieldName, operator, import_kysely4.sql`${v}`);
@@ -1291,7 +1294,7 @@ function applyOffset(context7, qb, offset) {
1291
1294
  __name(applyOffset, "applyOffset");
1292
1295
  function applyOrderBy(context7, qb, tableName, orderBy = {}) {
1293
1296
  Object.entries(orderBy).forEach(([key, sortOrder]) => {
1294
- qb = qb.orderBy(`${tableName}.${(0, import_change_case.snakeCase)(key)}`, sortOrder.toLowerCase());
1297
+ qb = qb.orderBy(`${tableName}.${snakeCase(key)}`, sortOrder.toLowerCase());
1295
1298
  });
1296
1299
  return qb;
1297
1300
  }
@@ -1305,7 +1308,7 @@ function applyJoins(context7, qb, where) {
1305
1308
  }
1306
1309
  const srcTable = context7.tableAlias();
1307
1310
  for (const key of Object.keys(where)) {
1308
- const rel = conf[(0, import_change_case.snakeCase)(key)];
1311
+ const rel = conf[snakeCase(key)];
1309
1312
  if (!rel) {
1310
1313
  continue;
1311
1314
  }
@@ -1745,7 +1748,7 @@ var QueryBuilder = class _QueryBuilder {
1745
1748
  const cursor = isBackward ? params.before : params.after;
1746
1749
  if (cursor) {
1747
1750
  const primaryField = orderByFields[0];
1748
- const primaryFieldCol = (0, import_change_case.snakeCase)(primaryField.field);
1751
+ const primaryFieldCol = snakeCase(primaryField.field);
1749
1752
  const cursorLookup = await db.selectFrom((qb) => this._db.as(this._tableName)).select([primaryFieldCol, "id"]).where(`${this._tableName}.id`, "=", cursor).limit(1).executeTakeFirst();
1750
1753
  if (cursorLookup) {
1751
1754
  const primaryValue = cursorLookup[primaryFieldCol];
@@ -1823,7 +1826,7 @@ var QueryBuilder = class _QueryBuilder {
1823
1826
  } else if (limit != null && results.length === limit && results.length > 0) {
1824
1827
  const lastResult = results[results.length - 1];
1825
1828
  const primaryField = orderByFields[0];
1826
- const primaryFieldCol = (0, import_change_case.snakeCase)(primaryField.field);
1829
+ const primaryFieldCol = snakeCase(primaryField.field);
1827
1830
  const primaryValue = lastResult[primaryField.field];
1828
1831
  const lastId = lastResult.id;
1829
1832
  const primaryOp = primaryField.direction === "asc" ? ">" : "<";
@@ -2377,7 +2380,7 @@ var TaskAPI = class _TaskAPI {
2377
2380
  */
2378
2381
  constructor(taskName, tableConfigMap = {}, identity = null, authToken = null) {
2379
2382
  this._taskName = taskName;
2380
- this._tableName = (0, import_change_case.snakeCase)(taskName);
2383
+ this._tableName = snakeCase(taskName);
2381
2384
  this._tableConfigMap = tableConfigMap;
2382
2385
  this._identity = identity;
2383
2386
  this._authToken = authToken;