@fachkraftfreund/n8n-nodes-supabase 1.2.5 → 1.2.7
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.
|
@@ -244,7 +244,7 @@ class Supabase {
|
|
|
244
244
|
displayOptions: {
|
|
245
245
|
show: {
|
|
246
246
|
resource: ['database'],
|
|
247
|
-
operation: ['create', 'read', 'update', 'delete', 'upsert'
|
|
247
|
+
operation: ['create', 'read', 'update', 'delete', 'upsert'],
|
|
248
248
|
},
|
|
249
249
|
},
|
|
250
250
|
},
|
|
@@ -261,7 +261,7 @@ class Supabase {
|
|
|
261
261
|
displayOptions: {
|
|
262
262
|
show: {
|
|
263
263
|
resource: ['database'],
|
|
264
|
-
operation: ['create', 'read', 'update', 'delete', 'upsert'],
|
|
264
|
+
operation: ['create', 'read', 'update', 'delete', 'upsert', 'findOrCreate'],
|
|
265
265
|
},
|
|
266
266
|
},
|
|
267
267
|
},
|
|
@@ -551,6 +551,19 @@ class Supabase {
|
|
|
551
551
|
},
|
|
552
552
|
],
|
|
553
553
|
},
|
|
554
|
+
{
|
|
555
|
+
displayName: 'Return All',
|
|
556
|
+
name: 'returnAll',
|
|
557
|
+
type: 'boolean',
|
|
558
|
+
default: false,
|
|
559
|
+
description: 'Whether to return all results or limit the number of results',
|
|
560
|
+
displayOptions: {
|
|
561
|
+
show: {
|
|
562
|
+
resource: ['database'],
|
|
563
|
+
operation: ['read'],
|
|
564
|
+
},
|
|
565
|
+
},
|
|
566
|
+
},
|
|
554
567
|
{
|
|
555
568
|
displayName: 'Limit',
|
|
556
569
|
name: 'limit',
|
|
@@ -561,6 +574,7 @@ class Supabase {
|
|
|
561
574
|
show: {
|
|
562
575
|
resource: ['database'],
|
|
563
576
|
operation: ['read'],
|
|
577
|
+
returnAll: [false],
|
|
564
578
|
},
|
|
565
579
|
},
|
|
566
580
|
},
|
|
@@ -574,6 +588,7 @@ class Supabase {
|
|
|
574
588
|
show: {
|
|
575
589
|
resource: ['database'],
|
|
576
590
|
operation: ['read'],
|
|
591
|
+
returnAll: [false],
|
|
577
592
|
},
|
|
578
593
|
},
|
|
579
594
|
},
|
|
@@ -100,7 +100,7 @@ async function handleRead(supabase, itemIndex) {
|
|
|
100
100
|
const filters = this.getNodeParameter('filters.filter', itemIndex, []);
|
|
101
101
|
for (const filter of filters) {
|
|
102
102
|
const operator = (0, supabaseClient_1.convertFilterOperator)(filter.operator);
|
|
103
|
-
query = query.filter(filter.column, operator, filter.value);
|
|
103
|
+
query = query.filter(filter.column, operator, (0, supabaseClient_1.normalizeFilterValue)(filter.operator, filter.value));
|
|
104
104
|
}
|
|
105
105
|
}
|
|
106
106
|
else {
|
|
@@ -111,7 +111,7 @@ async function handleRead(supabase, itemIndex) {
|
|
|
111
111
|
for (const [column, condition] of Object.entries(filters)) {
|
|
112
112
|
if (typeof condition === 'object' && condition !== null) {
|
|
113
113
|
const [operator, value] = Object.entries(condition)[0];
|
|
114
|
-
query = query.filter(column, (0, supabaseClient_1.convertFilterOperator)(operator), value);
|
|
114
|
+
query = query.filter(column, (0, supabaseClient_1.convertFilterOperator)(operator), (0, supabaseClient_1.normalizeFilterValue)(operator, value));
|
|
115
115
|
}
|
|
116
116
|
else {
|
|
117
117
|
query = query.eq(column, condition);
|
|
@@ -127,29 +127,88 @@ async function handleRead(supabase, itemIndex) {
|
|
|
127
127
|
for (const sortField of sort) {
|
|
128
128
|
query = query.order(sortField.column, { ascending: sortField.ascending });
|
|
129
129
|
}
|
|
130
|
-
const
|
|
131
|
-
const offset = this.getNodeParameter('offset', itemIndex, undefined);
|
|
132
|
-
if (limit !== undefined) {
|
|
133
|
-
query = query.limit(limit);
|
|
134
|
-
}
|
|
135
|
-
if (offset !== undefined) {
|
|
136
|
-
query = query.range(offset, offset + (limit || 1000) - 1);
|
|
137
|
-
}
|
|
138
|
-
const { data, error, count } = await query;
|
|
139
|
-
if (error) {
|
|
140
|
-
throw new Error((0, supabaseClient_1.formatSupabaseError)(error));
|
|
141
|
-
}
|
|
130
|
+
const returnAll = this.getNodeParameter('returnAll', itemIndex, false);
|
|
142
131
|
const returnData = [];
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
|
|
132
|
+
if (returnAll) {
|
|
133
|
+
const batchSize = 1000;
|
|
134
|
+
let offset = 0;
|
|
135
|
+
let hasMore = true;
|
|
136
|
+
while (hasMore) {
|
|
137
|
+
let batchQuery = supabase.from(table).select(returnFields && returnFields !== '*' ? returnFields : '*', { count: 'exact' });
|
|
138
|
+
const batchFilterMode = this.getNodeParameter('filterMode', itemIndex, 'simple');
|
|
139
|
+
if (batchFilterMode === 'simple') {
|
|
140
|
+
const batchFilters = this.getNodeParameter('filters.conditions', itemIndex, []);
|
|
141
|
+
for (const filter of batchFilters) {
|
|
142
|
+
if (filter.column && filter.value !== undefined) {
|
|
143
|
+
batchQuery = batchQuery.eq(filter.column, filter.value);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const batchAdvancedFilters = this.getNodeParameter('advancedFilters', itemIndex, '');
|
|
149
|
+
if (batchAdvancedFilters) {
|
|
150
|
+
try {
|
|
151
|
+
const parsed = JSON.parse(batchAdvancedFilters);
|
|
152
|
+
for (const condition of parsed) {
|
|
153
|
+
const { column, operator, value } = condition;
|
|
154
|
+
if (operator) {
|
|
155
|
+
batchQuery = batchQuery.filter(column, (0, supabaseClient_1.convertFilterOperator)(operator), (0, supabaseClient_1.normalizeFilterValue)(operator, value));
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
batchQuery = batchQuery.eq(column, condition);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch {
|
|
163
|
+
throw new Error('Invalid advanced filters JSON');
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
const batchSort = this.getNodeParameter('sort.sortField', itemIndex, []);
|
|
168
|
+
for (const sortField of batchSort) {
|
|
169
|
+
batchQuery = batchQuery.order(sortField.column, { ascending: sortField.ascending });
|
|
170
|
+
}
|
|
171
|
+
batchQuery = batchQuery.range(offset, offset + batchSize - 1);
|
|
172
|
+
const { data: batchData, error: batchError } = await batchQuery;
|
|
173
|
+
if (batchError) {
|
|
174
|
+
throw new Error((0, supabaseClient_1.formatSupabaseError)(batchError));
|
|
175
|
+
}
|
|
176
|
+
if (Array.isArray(batchData)) {
|
|
177
|
+
for (const row of batchData) {
|
|
178
|
+
returnData.push({ json: row });
|
|
179
|
+
}
|
|
180
|
+
hasMore = batchData.length === batchSize;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
hasMore = false;
|
|
184
|
+
}
|
|
185
|
+
offset += batchSize;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
const limit = this.getNodeParameter('limit', itemIndex, undefined);
|
|
190
|
+
const offset = this.getNodeParameter('offset', itemIndex, undefined);
|
|
191
|
+
if (limit !== undefined) {
|
|
192
|
+
query = query.limit(limit);
|
|
193
|
+
}
|
|
194
|
+
if (offset !== undefined) {
|
|
195
|
+
query = query.range(offset, offset + (limit || 1000) - 1);
|
|
196
|
+
}
|
|
197
|
+
const { data, error } = await query;
|
|
198
|
+
if (error) {
|
|
199
|
+
throw new Error((0, supabaseClient_1.formatSupabaseError)(error));
|
|
200
|
+
}
|
|
201
|
+
if (Array.isArray(data)) {
|
|
202
|
+
for (const row of data) {
|
|
203
|
+
returnData.push({ json: row });
|
|
204
|
+
}
|
|
146
205
|
}
|
|
147
206
|
}
|
|
148
207
|
if (returnData.length === 0) {
|
|
149
208
|
returnData.push({
|
|
150
209
|
json: {
|
|
151
210
|
data: [],
|
|
152
|
-
count:
|
|
211
|
+
count: 0,
|
|
153
212
|
operation: 'read',
|
|
154
213
|
table,
|
|
155
214
|
message: 'No records found',
|
|
@@ -185,7 +244,7 @@ async function handleUpdate(supabase, itemIndex) {
|
|
|
185
244
|
const filters = this.getNodeParameter('filters.filter', itemIndex, []);
|
|
186
245
|
for (const filter of filters) {
|
|
187
246
|
const operator = (0, supabaseClient_1.convertFilterOperator)(filter.operator);
|
|
188
|
-
query = query.filter(filter.column, operator, filter.value);
|
|
247
|
+
query = query.filter(filter.column, operator, (0, supabaseClient_1.normalizeFilterValue)(filter.operator, filter.value));
|
|
189
248
|
}
|
|
190
249
|
const { data, error } = await query.select();
|
|
191
250
|
if (error) {
|
|
@@ -203,7 +262,7 @@ async function handleDelete(supabase, itemIndex) {
|
|
|
203
262
|
}
|
|
204
263
|
for (const filter of filters) {
|
|
205
264
|
const operator = (0, supabaseClient_1.convertFilterOperator)(filter.operator);
|
|
206
|
-
query = query.filter(filter.column, operator, filter.value);
|
|
265
|
+
query = query.filter(filter.column, operator, (0, supabaseClient_1.normalizeFilterValue)(filter.operator, filter.value));
|
|
207
266
|
}
|
|
208
267
|
const { data, error } = await query.select();
|
|
209
268
|
if (error) {
|
|
@@ -11,3 +11,4 @@ export declare function sanitizeColumnName(columnName: string): string;
|
|
|
11
11
|
export declare function validateTableName(tableName: string): void;
|
|
12
12
|
export declare function validateColumnName(columnName: string): void;
|
|
13
13
|
export declare function convertFilterOperator(operator: string): string;
|
|
14
|
+
export declare function normalizeFilterValue(operator: string, value: string | number | boolean | null): string | number | boolean | null;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.convertFilterOperator = exports.validateColumnName = exports.validateTableName = exports.sanitizeColumnName = exports.isNetworkError = exports.isAuthError = exports.formatSupabaseError = exports.getDatabaseUrl = exports.getStorageUrl = exports.validateCredentials = exports.createSupabaseClient = void 0;
|
|
3
|
+
exports.normalizeFilterValue = exports.convertFilterOperator = exports.validateColumnName = exports.validateTableName = exports.sanitizeColumnName = exports.isNetworkError = exports.isAuthError = exports.formatSupabaseError = exports.getDatabaseUrl = exports.getStorageUrl = exports.validateCredentials = exports.createSupabaseClient = void 0;
|
|
4
4
|
const supabase_js_1 = require("@supabase/supabase-js");
|
|
5
5
|
function createSupabaseClient(credentials) {
|
|
6
6
|
const client = (0, supabase_js_1.createClient)(credentials.host, credentials.serviceKey, {
|
|
@@ -136,3 +136,14 @@ function convertFilterOperator(operator) {
|
|
|
136
136
|
return operatorMap[operator] || 'eq';
|
|
137
137
|
}
|
|
138
138
|
exports.convertFilterOperator = convertFilterOperator;
|
|
139
|
+
function normalizeFilterValue(operator, value) {
|
|
140
|
+
if (operator === 'in' && typeof value === 'string') {
|
|
141
|
+
const trimmed = value.trim();
|
|
142
|
+
if (!trimmed.startsWith('(')) {
|
|
143
|
+
return `(${trimmed})`;
|
|
144
|
+
}
|
|
145
|
+
return trimmed;
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
exports.normalizeFilterValue = normalizeFilterValue;
|
package/package.json
CHANGED