suparisma 1.1.1 → 1.1.2
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.
|
@@ -248,19 +248,23 @@ export function buildFilterString<T>(where?: T): string | undefined {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
if ('gt' in advancedOps && advancedOps.gt !== undefined) {
|
|
251
|
-
|
|
251
|
+
const value = advancedOps.gt instanceof Date ? advancedOps.gt.toISOString() : advancedOps.gt;
|
|
252
|
+
filters.push(\`\${key}=gt.\${value}\`);
|
|
252
253
|
}
|
|
253
254
|
|
|
254
255
|
if ('gte' in advancedOps && advancedOps.gte !== undefined) {
|
|
255
|
-
|
|
256
|
+
const value = advancedOps.gte instanceof Date ? advancedOps.gte.toISOString() : advancedOps.gte;
|
|
257
|
+
filters.push(\`\${key}=gte.\${value}\`);
|
|
256
258
|
}
|
|
257
259
|
|
|
258
260
|
if ('lt' in advancedOps && advancedOps.lt !== undefined) {
|
|
259
|
-
|
|
261
|
+
const value = advancedOps.lt instanceof Date ? advancedOps.lt.toISOString() : advancedOps.lt;
|
|
262
|
+
filters.push(\`\${key}=lt.\${value}\`);
|
|
260
263
|
}
|
|
261
264
|
|
|
262
265
|
if ('lte' in advancedOps && advancedOps.lte !== undefined) {
|
|
263
|
-
|
|
266
|
+
const value = advancedOps.lte instanceof Date ? advancedOps.lte.toISOString() : advancedOps.lte;
|
|
267
|
+
filters.push(\`\${key}=lte.\${value}\`);
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
if ('in' in advancedOps && advancedOps.in?.length) {
|
|
@@ -345,23 +349,31 @@ function applyConditionGroup<T>(
|
|
|
345
349
|
}
|
|
346
350
|
|
|
347
351
|
if ('gt' in advancedOps && advancedOps.gt !== undefined) {
|
|
352
|
+
// Convert Date objects to ISO strings for Supabase
|
|
353
|
+
const value = advancedOps.gt instanceof Date ? advancedOps.gt.toISOString() : advancedOps.gt;
|
|
348
354
|
// @ts-ignore: Supabase typing issue
|
|
349
|
-
filteredQuery = filteredQuery.gt(key,
|
|
355
|
+
filteredQuery = filteredQuery.gt(key, value);
|
|
350
356
|
}
|
|
351
357
|
|
|
352
358
|
if ('gte' in advancedOps && advancedOps.gte !== undefined) {
|
|
359
|
+
// Convert Date objects to ISO strings for Supabase
|
|
360
|
+
const value = advancedOps.gte instanceof Date ? advancedOps.gte.toISOString() : advancedOps.gte;
|
|
353
361
|
// @ts-ignore: Supabase typing issue
|
|
354
|
-
filteredQuery = filteredQuery.gte(key,
|
|
362
|
+
filteredQuery = filteredQuery.gte(key, value);
|
|
355
363
|
}
|
|
356
364
|
|
|
357
365
|
if ('lt' in advancedOps && advancedOps.lt !== undefined) {
|
|
366
|
+
// Convert Date objects to ISO strings for Supabase
|
|
367
|
+
const value = advancedOps.lt instanceof Date ? advancedOps.lt.toISOString() : advancedOps.lt;
|
|
358
368
|
// @ts-ignore: Supabase typing issue
|
|
359
|
-
filteredQuery = filteredQuery.lt(key,
|
|
369
|
+
filteredQuery = filteredQuery.lt(key, value);
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
if ('lte' in advancedOps && advancedOps.lte !== undefined) {
|
|
373
|
+
// Convert Date objects to ISO strings for Supabase
|
|
374
|
+
const value = advancedOps.lte instanceof Date ? advancedOps.lte.toISOString() : advancedOps.lte;
|
|
363
375
|
// @ts-ignore: Supabase typing issue
|
|
364
|
-
filteredQuery = filteredQuery.lte(key,
|
|
376
|
+
filteredQuery = filteredQuery.lte(key, value);
|
|
365
377
|
}
|
|
366
378
|
|
|
367
379
|
if ('in' in advancedOps && advancedOps.in?.length) {
|
|
@@ -458,13 +470,17 @@ export function applyFilter<T>(
|
|
|
458
470
|
} else if ('not' in advancedOps && advancedOps.not !== undefined) {
|
|
459
471
|
orFilters.push(\`\${key}.neq.\${advancedOps.not}\`);
|
|
460
472
|
} else if ('gt' in advancedOps && advancedOps.gt !== undefined) {
|
|
461
|
-
|
|
473
|
+
const value = advancedOps.gt instanceof Date ? advancedOps.gt.toISOString() : advancedOps.gt;
|
|
474
|
+
orFilters.push(\`\${key}.gt.\${value}\`);
|
|
462
475
|
} else if ('gte' in advancedOps && advancedOps.gte !== undefined) {
|
|
463
|
-
|
|
476
|
+
const value = advancedOps.gte instanceof Date ? advancedOps.gte.toISOString() : advancedOps.gte;
|
|
477
|
+
orFilters.push(\`\${key}.gte.\${value}\`);
|
|
464
478
|
} else if ('lt' in advancedOps && advancedOps.lt !== undefined) {
|
|
465
|
-
|
|
479
|
+
const value = advancedOps.lt instanceof Date ? advancedOps.lt.toISOString() : advancedOps.lt;
|
|
480
|
+
orFilters.push(\`\${key}.lt.\${value}\`);
|
|
466
481
|
} else if ('lte' in advancedOps && advancedOps.lte !== undefined) {
|
|
467
|
-
|
|
482
|
+
const value = advancedOps.lte instanceof Date ? advancedOps.lte.toISOString() : advancedOps.lte;
|
|
483
|
+
orFilters.push(\`\${key}.lte.\${value}\`);
|
|
468
484
|
} else if ('in' in advancedOps && advancedOps.in?.length) {
|
|
469
485
|
orFilters.push(\`\${key}.in.(\${advancedOps.in.join(',')})\`);
|
|
470
486
|
} else if ('contains' in advancedOps && advancedOps.contains !== undefined) {
|
|
@@ -528,6 +544,18 @@ function matchesFilter<T>(record: any, filter: T): boolean {
|
|
|
528
544
|
}
|
|
529
545
|
}
|
|
530
546
|
|
|
547
|
+
// Helper function to convert values to comparable format for date/time comparisons
|
|
548
|
+
const getComparableValue = (value: any): any => {
|
|
549
|
+
if (value instanceof Date) {
|
|
550
|
+
return value.getTime();
|
|
551
|
+
}
|
|
552
|
+
if (typeof value === 'string' && value.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/)) {
|
|
553
|
+
// ISO date string
|
|
554
|
+
return new Date(value).getTime();
|
|
555
|
+
}
|
|
556
|
+
return value;
|
|
557
|
+
};
|
|
558
|
+
|
|
531
559
|
// Helper function to check individual field conditions
|
|
532
560
|
const checkFieldConditions = (conditions: any): boolean => {
|
|
533
561
|
for (const [key, value] of Object.entries(conditions)) {
|
|
@@ -547,19 +575,27 @@ function matchesFilter<T>(record: any, filter: T): boolean {
|
|
|
547
575
|
}
|
|
548
576
|
|
|
549
577
|
if ('gt' in advancedOps && advancedOps.gt !== undefined) {
|
|
550
|
-
|
|
578
|
+
const recordComparable = getComparableValue(recordValue);
|
|
579
|
+
const filterComparable = getComparableValue(advancedOps.gt);
|
|
580
|
+
if (!(recordComparable > filterComparable)) return false;
|
|
551
581
|
}
|
|
552
582
|
|
|
553
583
|
if ('gte' in advancedOps && advancedOps.gte !== undefined) {
|
|
554
|
-
|
|
584
|
+
const recordComparable = getComparableValue(recordValue);
|
|
585
|
+
const filterComparable = getComparableValue(advancedOps.gte);
|
|
586
|
+
if (!(recordComparable >= filterComparable)) return false;
|
|
555
587
|
}
|
|
556
588
|
|
|
557
589
|
if ('lt' in advancedOps && advancedOps.lt !== undefined) {
|
|
558
|
-
|
|
590
|
+
const recordComparable = getComparableValue(recordValue);
|
|
591
|
+
const filterComparable = getComparableValue(advancedOps.lt);
|
|
592
|
+
if (!(recordComparable < filterComparable)) return false;
|
|
559
593
|
}
|
|
560
594
|
|
|
561
595
|
if ('lte' in advancedOps && advancedOps.lte !== undefined) {
|
|
562
|
-
|
|
596
|
+
const recordComparable = getComparableValue(recordValue);
|
|
597
|
+
const filterComparable = getComparableValue(advancedOps.lte);
|
|
598
|
+
if (!(recordComparable <= filterComparable)) return false;
|
|
563
599
|
}
|
|
564
600
|
|
|
565
601
|
if ('in' in advancedOps && advancedOps.in?.length) {
|
|
@@ -1518,7 +1554,20 @@ export function createSuparismaHook<
|
|
|
1518
1554
|
setLoading(true);
|
|
1519
1555
|
setError(null);
|
|
1520
1556
|
|
|
1521
|
-
const now = new Date()
|
|
1557
|
+
const now = new Date();
|
|
1558
|
+
|
|
1559
|
+
// Helper function to convert Date objects to ISO strings for database
|
|
1560
|
+
const convertDatesForDatabase = (obj: any): any => {
|
|
1561
|
+
const result: any = {};
|
|
1562
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1563
|
+
if (value instanceof Date) {
|
|
1564
|
+
result[key] = value.toISOString();
|
|
1565
|
+
} else {
|
|
1566
|
+
result[key] = value;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
return result;
|
|
1570
|
+
};
|
|
1522
1571
|
|
|
1523
1572
|
// Apply default values from schema
|
|
1524
1573
|
const appliedDefaults: Record<string, any> = {};
|
|
@@ -1529,7 +1578,7 @@ export function createSuparismaHook<
|
|
|
1529
1578
|
if (!(field in data)) {
|
|
1530
1579
|
// Parse the default value based on its type
|
|
1531
1580
|
if (defaultValue.includes('now()') || defaultValue.includes('now')) {
|
|
1532
|
-
appliedDefaults[field] = now;
|
|
1581
|
+
appliedDefaults[field] = now.toISOString(); // Database expects ISO string
|
|
1533
1582
|
} else if (defaultValue.includes('uuid()') || defaultValue.includes('uuid')) {
|
|
1534
1583
|
appliedDefaults[field] = crypto.randomUUID();
|
|
1535
1584
|
} else if (defaultValue.includes('cuid()') || defaultValue.includes('cuid')) {
|
|
@@ -1550,13 +1599,13 @@ export function createSuparismaHook<
|
|
|
1550
1599
|
}
|
|
1551
1600
|
}
|
|
1552
1601
|
|
|
1553
|
-
const itemWithDefaults = {
|
|
1602
|
+
const itemWithDefaults = convertDatesForDatabase({
|
|
1554
1603
|
...appliedDefaults, // Apply schema defaults first
|
|
1555
1604
|
...data, // Then user data (overrides defaults)
|
|
1556
|
-
// Use the actual field names from Prisma
|
|
1557
|
-
...(hasCreatedAt ? { [createdAtField]: now } : {}),
|
|
1558
|
-
...(hasUpdatedAt ? { [updatedAtField]: now } : {})
|
|
1559
|
-
};
|
|
1605
|
+
// Use the actual field names from Prisma - convert Date to ISO string for database
|
|
1606
|
+
...(hasCreatedAt ? { [createdAtField]: now.toISOString() } : {}),
|
|
1607
|
+
...(hasUpdatedAt ? { [updatedAtField]: now.toISOString() } : {})
|
|
1608
|
+
});
|
|
1560
1609
|
|
|
1561
1610
|
const { data: result, error } = await supabase
|
|
1562
1611
|
.from(tableName)
|
|
@@ -1624,17 +1673,30 @@ export function createSuparismaHook<
|
|
|
1624
1673
|
throw new Error('A unique identifier is required');
|
|
1625
1674
|
}
|
|
1626
1675
|
|
|
1627
|
-
const now = new Date()
|
|
1676
|
+
const now = new Date();
|
|
1677
|
+
|
|
1678
|
+
// Helper function to convert Date objects to ISO strings for database
|
|
1679
|
+
const convertDatesForDatabase = (obj: any): any => {
|
|
1680
|
+
const result: any = {};
|
|
1681
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
1682
|
+
if (value instanceof Date) {
|
|
1683
|
+
result[key] = value.toISOString();
|
|
1684
|
+
} else {
|
|
1685
|
+
result[key] = value;
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
return result;
|
|
1689
|
+
};
|
|
1628
1690
|
|
|
1629
1691
|
// We do not apply default values for updates
|
|
1630
1692
|
// Default values are only for creation, not for updates,
|
|
1631
1693
|
// as existing records already have these values set
|
|
1632
1694
|
|
|
1633
|
-
const itemWithDefaults = {
|
|
1695
|
+
const itemWithDefaults = convertDatesForDatabase({
|
|
1634
1696
|
...params.data,
|
|
1635
|
-
// Use the actual updatedAt field name from Prisma
|
|
1636
|
-
...(hasUpdatedAt ? { [updatedAtField]: now } : {})
|
|
1637
|
-
};
|
|
1697
|
+
// Use the actual updatedAt field name from Prisma - convert Date to ISO string for database
|
|
1698
|
+
...(hasUpdatedAt ? { [updatedAtField]: now.toISOString() } : {})
|
|
1699
|
+
});
|
|
1638
1700
|
|
|
1639
1701
|
const { data, error } = await supabase
|
|
1640
1702
|
.from(tableName)
|
|
@@ -69,7 +69,7 @@ function generateModelTypesFile(model) {
|
|
|
69
69
|
baseType = 'boolean';
|
|
70
70
|
break;
|
|
71
71
|
case 'DateTime':
|
|
72
|
-
baseType = '
|
|
72
|
+
baseType = 'Date'; // Proper Date type for DateTime fields
|
|
73
73
|
break;
|
|
74
74
|
case 'Json':
|
|
75
75
|
baseType = 'any'; // Or a more specific structured type if available
|
package/package.json
CHANGED