@budibase/backend-core 3.2.39 → 3.2.40

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.js CHANGED
@@ -16928,7 +16928,23 @@ function runQuery(docs, query) {
16928
16928
  if (docValue && typeof docValue === "object" && typeof testValue === "string") {
16929
16929
  return docValue._id === testValue;
16930
16930
  }
16931
- return docValue === testValue;
16931
+ if (docValue === testValue) {
16932
+ return true;
16933
+ }
16934
+ if (docValue == null && testValue != null) {
16935
+ return false;
16936
+ }
16937
+ if (docValue != null && testValue == null) {
16938
+ return false;
16939
+ }
16940
+ const leftDate = (0, import_dayjs.default)(docValue);
16941
+ if (leftDate.isValid()) {
16942
+ const rightDate = (0, import_dayjs.default)(testValue);
16943
+ if (rightDate.isValid()) {
16944
+ return leftDate.isSame(rightDate);
16945
+ }
16946
+ }
16947
+ return false;
16932
16948
  };
16933
16949
  const not = (f) => (...args) => !f(...args);
16934
16950
  const equalMatch = match("equal" /* EQUAL */, _valueMatches);
@@ -21143,7 +21159,7 @@ function isDocumentConflictError(error) {
21143
21159
  var DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`;
21144
21160
  var ROW_ID_REGEX = /^\[.*]$/g;
21145
21161
  var ENCODED_SPACE = encodeURIComponent(" ");
21146
- var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/;
21162
+ var ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}.\d{3}Z)?$/;
21147
21163
  var TIME_REGEX = /^(?:\d{2}:)?(?:\d{2}:)(?:\d{2})$/;
21148
21164
  function isExternalTableID(tableId) {
21149
21165
  return tableId.startsWith("datasource" /* DATASOURCE */ + SEPARATOR);
@@ -21245,15 +21261,7 @@ function isInvalidISODateString(str) {
21245
21261
  return isNaN(d.getTime());
21246
21262
  }
21247
21263
  function isValidISODateString(str) {
21248
- const trimmedValue = str.trim();
21249
- if (!ISO_DATE_REGEX.test(trimmedValue)) {
21250
- return false;
21251
- }
21252
- let d = new Date(trimmedValue);
21253
- if (isNaN(d.getTime())) {
21254
- return false;
21255
- }
21256
- return d.toISOString() === trimmedValue;
21264
+ return ISO_DATE_REGEX.test(str.trim());
21257
21265
  }
21258
21266
  function isValidFilter(value) {
21259
21267
  return value != null && value !== "";
@@ -29045,7 +29053,11 @@ async function errorHandling(ctx, next) {
29045
29053
  };
29046
29054
  }
29047
29055
  if (environment_default.isTest() && ctx.headers["x-budibase-include-stacktrace"]) {
29048
- error.stack = err.stack;
29056
+ let rootErr = err;
29057
+ while (rootErr.cause) {
29058
+ rootErr = rootErr.cause;
29059
+ }
29060
+ error.stack = rootErr.stack;
29049
29061
  }
29050
29062
  ctx.body = error;
29051
29063
  }
@@ -30068,16 +30080,6 @@ var InternalBuilder = class {
30068
30080
  }
30069
30081
  return parts.join(".");
30070
30082
  }
30071
- isFullSelectStatementRequired() {
30072
- for (let column of Object.values(this.table.schema)) {
30073
- if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(column)) {
30074
- return true;
30075
- } else if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(column)) {
30076
- return true;
30077
- }
30078
- }
30079
- return false;
30080
- }
30081
30083
  generateSelectStatement() {
30082
30084
  const { table, resource } = this.query;
30083
30085
  if (!resource || !resource.fields || resource.fields.length === 0) {
@@ -30085,10 +30087,7 @@ var InternalBuilder = class {
30085
30087
  }
30086
30088
  const alias = this.getTableName(table);
30087
30089
  const schema = this.table.schema;
30088
- if (!this.isFullSelectStatementRequired()) {
30089
- return [this.knex.raw("??", [`${alias}.*`])];
30090
- }
30091
- return resource.fields.map((field) => {
30090
+ const tableFields = resource.fields.map((field) => {
30092
30091
  const parts = field.split(/\./g);
30093
30092
  let table2 = void 0;
30094
30093
  let column = parts[0];
@@ -30097,7 +30096,8 @@ var InternalBuilder = class {
30097
30096
  column = parts.slice(1).join(".");
30098
30097
  }
30099
30098
  return { table: table2, column, field };
30100
- }).filter(({ table: table2 }) => !table2 || table2 === alias).map(({ table: table2, column, field }) => {
30099
+ }).filter(({ table: table2 }) => !table2 || table2 === alias);
30100
+ return tableFields.map(({ table: table2, column, field }) => {
30101
30101
  const columnSchema = schema[column];
30102
30102
  if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(columnSchema)) {
30103
30103
  return this.knex.raw(`??::money::numeric as ??`, [
@@ -30491,13 +30491,24 @@ var InternalBuilder = class {
30491
30491
  filters.oneOf,
30492
30492
  "oneOf" /* ONE_OF */,
30493
30493
  (q, key, array) => {
30494
+ const schema = this.getFieldSchema(key);
30495
+ const values2 = Array.isArray(array) ? array : [array];
30494
30496
  if (shouldOr) {
30495
30497
  q = q.or;
30496
30498
  }
30497
30499
  if (this.client === "oracledb" /* ORACLE */) {
30498
30500
  key = this.convertClobs(key);
30501
+ } else if (this.client === "sqlite3" /* SQL_LITE */ && schema?.type === "datetime" /* DATETIME */ && schema.dateOnly) {
30502
+ for (const value of values2) {
30503
+ if (value != null) {
30504
+ q = q.or.whereLike(key, `${value.toISOString().slice(0, 10)}%`);
30505
+ } else {
30506
+ q = q.or.whereNull(key);
30507
+ }
30508
+ }
30509
+ return q;
30499
30510
  }
30500
- return q.whereIn(key, Array.isArray(array) ? array : [array]);
30511
+ return q.whereIn(key, values2);
30501
30512
  },
30502
30513
  (q, key, array) => {
30503
30514
  if (shouldOr) {
@@ -30544,6 +30555,14 @@ var InternalBuilder = class {
30544
30555
  let rawKey = key;
30545
30556
  let high = value.high;
30546
30557
  let low = value.low;
30558
+ if (this.client === "sqlite3" /* SQL_LITE */ && schema?.type === "datetime" /* DATETIME */ && schema.dateOnly) {
30559
+ if (high != null) {
30560
+ high = `${high.toISOString().slice(0, 10)}T23:59:59.999Z`;
30561
+ }
30562
+ if (low != null) {
30563
+ low = low.toISOString().slice(0, 10);
30564
+ }
30565
+ }
30547
30566
  if (this.client === "oracledb" /* ORACLE */) {
30548
30567
  rawKey = this.convertClobs(key);
30549
30568
  } else if (this.client === "sqlite3" /* SQL_LITE */ && schema?.type === "bigint" /* BIGINT */) {
@@ -30568,6 +30587,7 @@ var InternalBuilder = class {
30568
30587
  }
30569
30588
  if (filters.equal) {
30570
30589
  iterate(filters.equal, "equal" /* EQUAL */, (q, key, value) => {
30590
+ const schema = this.getFieldSchema(key);
30571
30591
  if (shouldOr) {
30572
30592
  q = q.or;
30573
30593
  }
@@ -30584,6 +30604,12 @@ var InternalBuilder = class {
30584
30604
  subq.whereNotNull(identifier).andWhere(identifier, value)
30585
30605
  )
30586
30606
  );
30607
+ } else if (this.client === "sqlite3" /* SQL_LITE */ && schema?.type === "datetime" /* DATETIME */ && schema.dateOnly) {
30608
+ if (value != null) {
30609
+ return q.whereLike(key, `${value.toISOString().slice(0, 10)}%`);
30610
+ } else {
30611
+ return q.whereNull(key);
30612
+ }
30587
30613
  } else {
30588
30614
  return q.whereRaw(`COALESCE(?? = ?, FALSE)`, [
30589
30615
  this.rawQuotedIdentifier(key),
@@ -30594,6 +30620,7 @@ var InternalBuilder = class {
30594
30620
  }
30595
30621
  if (filters.notEqual) {
30596
30622
  iterate(filters.notEqual, "notEqual" /* NOT_EQUAL */, (q, key, value) => {
30623
+ const schema = this.getFieldSchema(key);
30597
30624
  if (shouldOr) {
30598
30625
  q = q.or;
30599
30626
  }
@@ -30607,6 +30634,12 @@ var InternalBuilder = class {
30607
30634
  return q.where(
30608
30635
  (subq) => subq.not.whereNull(identifier).and.where(identifier, "!=", value)
30609
30636
  ).or.whereNull(identifier);
30637
+ } else if (this.client === "sqlite3" /* SQL_LITE */ && schema?.type === "datetime" /* DATETIME */ && schema.dateOnly) {
30638
+ if (value != null) {
30639
+ return q.not.whereLike(key, `${value.toISOString().slice(0, 10)}%`).or.whereNull(key);
30640
+ } else {
30641
+ return q.not.whereNull(key);
30642
+ }
30610
30643
  } else {
30611
30644
  return q.whereRaw(`COALESCE(?? != ?, TRUE)`, [
30612
30645
  this.rawQuotedIdentifier(key),
@@ -30859,6 +30892,9 @@ var InternalBuilder = class {
30859
30892
  const fieldList = relationshipFields.map(
30860
30893
  (field) => this.buildJsonField(relatedTable, field)
30861
30894
  );
30895
+ if (!fieldList.length) {
30896
+ continue;
30897
+ }
30862
30898
  const fieldListFormatted = fieldList.map((f) => {
30863
30899
  const separator = this.client === "oracledb" /* ORACLE */ ? " VALUE " : ",";
30864
30900
  return this.knex.raw(`?${separator}??`, [f[0], f[1]]).toString();
@@ -30882,7 +30918,7 @@ var InternalBuilder = class {
30882
30918
  this.rawQuotedIdentifier(correlatedFrom)
30883
30919
  );
30884
30920
  const standardWrap = (select) => {
30885
- subQuery = subQuery.select(`${toAlias}.*`).limit(getRelationshipLimit());
30921
+ subQuery = subQuery.select(relationshipFields).limit(getRelationshipLimit());
30886
30922
  return knex3.select(select).from({
30887
30923
  [toAlias]: subQuery
30888
30924
  });
@@ -31048,7 +31084,7 @@ var InternalBuilder = class {
31048
31084
  return query.upsert(parsedBody);
31049
31085
  }
31050
31086
  read(opts = {}) {
31051
- let { operation, filters, paginate, relationships, table } = this.query;
31087
+ const { operation, filters, paginate, relationships, table } = this.query;
31052
31088
  const { limits } = opts;
31053
31089
  let query = this.qualifiedKnex();
31054
31090
  let foundOffset = null;
@@ -31087,7 +31123,7 @@ var InternalBuilder = class {
31087
31123
  if (relationships?.length && aggregations.length === 0) {
31088
31124
  const mainTable = this.query.tableAliases?.[table.name] || table.name;
31089
31125
  const cte = this.addSorting(
31090
- this.knex.with("paginated", query).select(this.generateSelectStatement()).from({
31126
+ this.knex.with("paginated", query.clone().clearSelect().select("*")).select(this.generateSelectStatement()).from({
31091
31127
  [mainTable]: "paginated"
31092
31128
  })
31093
31129
  );