supabase-typed-query 0.12.0 → 0.13.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.mjs CHANGED
@@ -68,7 +68,7 @@ const QueryBuilder = (client, config) => {
68
68
  return finalQuery;
69
69
  };
70
70
  const applyCondition = (query2, condition) => {
71
- const { where, is, wherein, gt, gte, lt, lte, neq, like, ilike } = condition;
71
+ const { where, is, wherein, gt, gte, lt, lte, neq, like, ilike, not } = condition;
72
72
  const processedWhere = {};
73
73
  const extractedOperators = {};
74
74
  if (where) {
@@ -182,10 +182,18 @@ const QueryBuilder = (client, config) => {
182
182
  const queryWithGte = Object.keys(mergedGte).length > 0 ? Object.entries(mergedGte).reduce((q, [key, value]) => q.gte(key, value), queryWithGt) : queryWithGt;
183
183
  const queryWithLt = Object.keys(mergedLt).length > 0 ? Object.entries(mergedLt).reduce((q, [key, value]) => q.lt(key, value), queryWithGte) : queryWithGte;
184
184
  const queryWithLte = Object.keys(mergedLte).length > 0 ? Object.entries(mergedLte).reduce((q, [key, value]) => q.lte(key, value), queryWithLt) : queryWithLt;
185
- const queryWithNeq = Object.keys(mergedNeq).length > 0 ? Object.entries(mergedNeq).reduce((q, [key, value]) => q.neq(key, value), queryWithLte) : queryWithLte;
185
+ const queryWithNeq = Object.keys(mergedNeq).length > 0 ? Object.entries(mergedNeq).reduce((q, [key, value]) => {
186
+ if (value === null) {
187
+ log.warn(`neq: null is deprecated. Use not: { is: { ${key}: null } } for IS NOT NULL`);
188
+ return q.not(key, "is", null);
189
+ }
190
+ return q.neq(key, value);
191
+ }, queryWithLte) : queryWithLte;
186
192
  const queryWithLike = Object.keys(mergedLike).length > 0 ? Object.entries(mergedLike).reduce((q, [key, pattern]) => q.like(key, pattern), queryWithNeq) : queryWithNeq;
187
193
  const queryWithIlike = Object.keys(mergedIlike).length > 0 ? Object.entries(mergedIlike).reduce((q, [key, pattern]) => q.ilike(key, pattern), queryWithLike) : queryWithLike;
188
- return queryWithIlike;
194
+ const queryWithNotIs = not?.is ? Object.entries(not.is).reduce((q, [key, value]) => q.not(key, "is", value), queryWithIlike) : queryWithIlike;
195
+ const queryWithNot = not?.in ? Object.entries(not.in).reduce((q, [key, values]) => q.not(key, "in", values), queryWithNotIs) : queryWithNotIs;
196
+ return queryWithNot;
189
197
  };
190
198
  const applyOrConditions = (query2, conditions) => {
191
199
  const selectQuery = query2.select("*");
@@ -222,7 +230,8 @@ const QueryBuilder = (client, config) => {
222
230
  return {
223
231
  where: newWhere,
224
232
  is: condition.is,
225
- wherein: condition.wherein
233
+ wherein: condition.wherein,
234
+ not: condition.not
226
235
  };
227
236
  })
228
237
  );
@@ -286,6 +295,7 @@ const QueryBuilder = (client, config) => {
286
295
  if (condition.neq) {
287
296
  Object.entries(condition.neq).forEach(([key, value]) => {
288
297
  if (value === null) {
298
+ log.warn(`neq: null is deprecated. Use not: { is: { ${key}: null } } for IS NOT NULL`);
289
299
  parts.push(`${key}.not.is.null`);
290
300
  } else {
291
301
  parts.push(`${key}.neq."${value}"`);
@@ -302,6 +312,25 @@ const QueryBuilder = (client, config) => {
302
312
  parts.push(`${key}.ilike."${pattern}"`);
303
313
  });
304
314
  }
315
+ if (condition.not) {
316
+ if (condition.not.is) {
317
+ Object.entries(condition.not.is).forEach(([key, value]) => {
318
+ if (value === null) {
319
+ parts.push(`${key}.not.is.null`);
320
+ } else {
321
+ parts.push(`${key}.not.is.${value}`);
322
+ }
323
+ });
324
+ }
325
+ if (condition.not.in) {
326
+ Object.entries(condition.not.in).forEach(([key, values]) => {
327
+ if (values && Array.isArray(values) && values.length > 0) {
328
+ const valueList = values.map((v) => `"${v}"`).join(",");
329
+ parts.push(`${key}.not.in.(${valueList})`);
330
+ }
331
+ });
332
+ }
333
+ }
305
334
  return parts.join(",");
306
335
  }).filter((condition) => condition.length > 0);
307
336
  const finalQuery = orConditions.length > 0 ? queryWithCommon.or(orConditions.join(",")) : queryWithCommon;
@@ -554,10 +583,10 @@ const createMappedQuery = (sourceQuery, mapFn) => {
554
583
  }
555
584
  };
556
585
  };
557
- const createQuery = (client, table, where = {}, is, wherein, order, softDeleteConfig, schema, comparison) => {
586
+ const createQuery = (client, table, where = {}, is, wherein, order, softDeleteConfig, schema, comparison, not) => {
558
587
  const config = {
559
588
  table,
560
- conditions: [{ where, is, wherein, ...comparison }],
589
+ conditions: [{ where, is, wherein, ...comparison, not }],
561
590
  order,
562
591
  softDeleteMode: softDeleteConfig?.mode,
563
592
  softDeleteAppliedByDefault: softDeleteConfig?.appliedByDefault,
@@ -867,7 +896,7 @@ function createGetItemQuery(client, name, whereConditions, is, softDeleteMode, s
867
896
  schema
868
897
  );
869
898
  }
870
- function createGetItemsQuery(client, name, whereConditions, is, wherein, order, softDeleteMode, schema, comparison) {
899
+ function createGetItemsQuery(client, name, whereConditions, is, wherein, order, softDeleteMode, schema, comparison, not) {
871
900
  return createQuery(
872
901
  client,
873
902
  name,
@@ -880,7 +909,8 @@ function createGetItemsQuery(client, name, whereConditions, is, wherein, order,
880
909
  appliedByDefault: true
881
910
  },
882
911
  schema,
883
- comparison
912
+ comparison,
913
+ not
884
914
  );
885
915
  }
886
916
  function createAddItemsMutation(client, name, items, schema) {
@@ -947,7 +977,8 @@ function makeGetItems(client, name, softDeleteMode, schema) {
947
977
  lt,
948
978
  neq,
949
979
  like,
950
- ilike
980
+ ilike,
981
+ not
951
982
  } = {}) {
952
983
  return createGetItemsQuery(
953
984
  client,
@@ -958,7 +989,8 @@ function makeGetItems(client, name, softDeleteMode, schema) {
958
989
  order,
959
990
  softDeleteMode,
960
991
  schema,
961
- { gte, gt, lte, lt, neq, like, ilike }
992
+ { gte, gt, lte, lt, neq, like, ilike },
993
+ not
962
994
  );
963
995
  };
964
996
  }
@@ -976,7 +1008,7 @@ function makePartitionedGetItem(client, name, partitionField, softDeleteMode, sc
976
1008
  };
977
1009
  }
978
1010
  function makePartitionedGetItems(client, name, partitionField, softDeleteMode, schema) {
979
- return function getItems(partitionKey, { where, is, wherein, order, gte, gt, lte, lt, neq, like, ilike } = {}) {
1011
+ return function getItems(partitionKey, { where, is, wherein, order, gte, gt, lte, lt, neq, like, ilike, not } = {}) {
980
1012
  const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
981
1013
  return createGetItemsQuery(
982
1014
  client,
@@ -987,7 +1019,8 @@ function makePartitionedGetItems(client, name, partitionField, softDeleteMode, s
987
1019
  order,
988
1020
  softDeleteMode,
989
1021
  schema,
990
- { gte, gt, lte, lt, neq, like, ilike }
1022
+ { gte, gt, lte, lt, neq, like, ilike },
1023
+ not
991
1024
  );
992
1025
  };
993
1026
  }