supabase-typed-query 0.11.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/README.md +39 -0
- package/dist/index.js +60 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +60 -12
- package/dist/index.mjs.map +1 -1
- package/dist/src/entity/core.d.ts +18 -7
- package/dist/src/entity/core.d.ts.map +1 -1
- package/dist/src/entity/types.d.ts +20 -5
- package/dist/src/entity/types.d.ts.map +1 -1
- package/dist/src/query/Query.d.ts +63 -64
- package/dist/src/query/Query.d.ts.map +1 -1
- package/dist/src/query/QueryBuilder.d.ts +13 -2
- package/dist/src/query/QueryBuilder.d.ts.map +1 -1
- package/dist/src/query/index.d.ts +2 -2
- package/dist/src/query/index.d.ts.map +1 -1
- package/dist/src/query/rpc.d.ts +6 -2
- package/dist/src/query/rpc.d.ts.map +1 -1
- package/dist/src/types.d.ts +10 -6
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +6 -6
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]) =>
|
|
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
|
-
|
|
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) => {
|
|
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 }],
|
|
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) {
|
|
899
|
+
function createGetItemsQuery(client, name, whereConditions, is, wherein, order, softDeleteMode, schema, comparison, not) {
|
|
871
900
|
return createQuery(
|
|
872
901
|
client,
|
|
873
902
|
name,
|
|
@@ -879,7 +908,9 @@ function createGetItemsQuery(client, name, whereConditions, is, wherein, order,
|
|
|
879
908
|
mode: softDeleteMode,
|
|
880
909
|
appliedByDefault: true
|
|
881
910
|
},
|
|
882
|
-
schema
|
|
911
|
+
schema,
|
|
912
|
+
comparison,
|
|
913
|
+
not
|
|
883
914
|
);
|
|
884
915
|
}
|
|
885
916
|
function createAddItemsMutation(client, name, items, schema) {
|
|
@@ -935,7 +966,20 @@ function makeGetItem(client, name, softDeleteMode, schema) {
|
|
|
935
966
|
};
|
|
936
967
|
}
|
|
937
968
|
function makeGetItems(client, name, softDeleteMode, schema) {
|
|
938
|
-
return function getItems({
|
|
969
|
+
return function getItems({
|
|
970
|
+
where,
|
|
971
|
+
is,
|
|
972
|
+
wherein,
|
|
973
|
+
order,
|
|
974
|
+
gte,
|
|
975
|
+
gt,
|
|
976
|
+
lte,
|
|
977
|
+
lt,
|
|
978
|
+
neq,
|
|
979
|
+
like,
|
|
980
|
+
ilike,
|
|
981
|
+
not
|
|
982
|
+
} = {}) {
|
|
939
983
|
return createGetItemsQuery(
|
|
940
984
|
client,
|
|
941
985
|
name,
|
|
@@ -944,7 +988,9 @@ function makeGetItems(client, name, softDeleteMode, schema) {
|
|
|
944
988
|
wherein,
|
|
945
989
|
order,
|
|
946
990
|
softDeleteMode,
|
|
947
|
-
schema
|
|
991
|
+
schema,
|
|
992
|
+
{ gte, gt, lte, lt, neq, like, ilike },
|
|
993
|
+
not
|
|
948
994
|
);
|
|
949
995
|
};
|
|
950
996
|
}
|
|
@@ -962,7 +1008,7 @@ function makePartitionedGetItem(client, name, partitionField, softDeleteMode, sc
|
|
|
962
1008
|
};
|
|
963
1009
|
}
|
|
964
1010
|
function makePartitionedGetItems(client, name, partitionField, softDeleteMode, schema) {
|
|
965
|
-
return function getItems(partitionKey, { where, is, wherein, order } = {}) {
|
|
1011
|
+
return function getItems(partitionKey, { where, is, wherein, order, gte, gt, lte, lt, neq, like, ilike, not } = {}) {
|
|
966
1012
|
const whereConditions = buildWhereWithPartition(partitionField, partitionKey, where);
|
|
967
1013
|
return createGetItemsQuery(
|
|
968
1014
|
client,
|
|
@@ -972,7 +1018,9 @@ function makePartitionedGetItems(client, name, partitionField, softDeleteMode, s
|
|
|
972
1018
|
wherein,
|
|
973
1019
|
order,
|
|
974
1020
|
softDeleteMode,
|
|
975
|
-
schema
|
|
1021
|
+
schema,
|
|
1022
|
+
{ gte, gt, lte, lt, neq, like, ilike },
|
|
1023
|
+
not
|
|
976
1024
|
);
|
|
977
1025
|
};
|
|
978
1026
|
}
|