mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
feat: implement bigint support across various components and enhance payload handling
This commit is contained in:
1 parent
a6eb30db47
commit
f484ce8602
8 files changed
+84
-14
No files matched your search
@@ -243,6 +243,10 @@ function generateSingleValue(field: Field): string | number | boolean | NestedNu
|
||||
return faker.number.int({ min, max });
|
||||
}
|
||||
|
||||
case 'bigint': {
|
||||
return faker.number.bigInt().toString();
|
||||
}
|
||||
|
||||
case 'double': {
|
||||
const floatAttr = field as Models.ColumnFloat;
|
||||
const min = isWithinSafeRange(floatAttr.min) ? floatAttr.min : 0;
|
||||
|
||||
+3
-3
@@ -64,7 +64,7 @@
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
import { buildRowUrl, isRelationship } from './rows/store';
|
||||
import { buildRowUrl, isRelationship, buildPayload } from './rows/store';
|
||||
import { chunks } from '$lib/helpers/array';
|
||||
import { Submit, trackEvent } from '$lib/actions/analytics';
|
||||
|
||||
@@ -346,7 +346,7 @@
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
rowId: row.$id,
|
||||
data: row
|
||||
data: buildPayload(columns, row as Record<string, unknown>)
|
||||
})
|
||||
)
|
||||
);
|
||||
@@ -358,7 +358,7 @@
|
||||
await tablesSDK.createRows({
|
||||
databaseId: page.params.database,
|
||||
tableId: page.params.table,
|
||||
rows
|
||||
rows: rows.map((row) => buildPayload(columns, row as Record<string, unknown>))
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+8
-2
@@ -2,6 +2,12 @@
|
||||
import { page } from '$app/state';
|
||||
import { sdk } from '$lib/stores/sdk';
|
||||
import type { Models } from '@appwrite.io/console';
|
||||
|
||||
function normalizeBigInt(value) {
|
||||
if (value === undefined) return undefined;
|
||||
if (value === null) return null;
|
||||
return BigInt(value);
|
||||
}
|
||||
|
||||
export async function submitBigInt(
|
||||
databaseId: string,
|
||||
@@ -16,7 +22,7 @@
|
||||
required: data.required,
|
||||
min: data.min,
|
||||
max: data.max,
|
||||
xdefault: data.default,
|
||||
xdefault: normalizeBigInt(data.default),
|
||||
array: data.array
|
||||
});
|
||||
}
|
||||
@@ -32,7 +38,7 @@
|
||||
tableId,
|
||||
key: originalKey,
|
||||
required: data.required,
|
||||
xdefault: data.default,
|
||||
xdefault: normalizeBigInt(data.default),
|
||||
min: data.min,
|
||||
max: data.max,
|
||||
newKey: data.key !== originalKey ? data.key : undefined
|
||||
|
||||
+3
-3
@@ -14,7 +14,7 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { tick } from 'svelte';
|
||||
import { isRelationship, isRelationshipToMany } from './store';
|
||||
import { isRelationship, isRelationshipToMany, buildPayload } from './store';
|
||||
import { hash } from '$lib/helpers/string';
|
||||
|
||||
type CreateRow = {
|
||||
@@ -70,7 +70,7 @@
|
||||
function prepareRowPayload(createRowObject: CreateRow): object {
|
||||
const { row, columns } = createRowObject;
|
||||
|
||||
const payload = structuredClone(row);
|
||||
const payload = structuredClone(row) as Record<string, unknown>;
|
||||
|
||||
for (const column of columns) {
|
||||
if (isRelationship(column) && !isRelationshipToMany(column)) {
|
||||
@@ -87,7 +87,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
return payload;
|
||||
return buildPayload(columns, payload);
|
||||
}
|
||||
|
||||
async function create(): Promise<boolean> {
|
||||
|
||||
+5
-2
@@ -14,7 +14,8 @@
|
||||
buildWildcardColumnsQuery,
|
||||
isRelationship,
|
||||
isRelationshipToMany,
|
||||
isSpatialType
|
||||
isSpatialType,
|
||||
buildPayload
|
||||
} from './store';
|
||||
import { Layout, Skeleton } from '@appwrite.io/pink-svelte';
|
||||
import { deepClone } from '$lib/helpers/object';
|
||||
@@ -142,11 +143,13 @@
|
||||
if (!row || !work) return;
|
||||
|
||||
try {
|
||||
const payload = buildPayload(table.fields, $work as Record<string, unknown>);
|
||||
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId: table.databaseId,
|
||||
tableId: table.$id,
|
||||
rowId: row.$id,
|
||||
data: $work,
|
||||
data: payload,
|
||||
permissions: $work.$permissions
|
||||
});
|
||||
|
||||
|
||||
+16
-3
@@ -10,7 +10,12 @@
|
||||
import { invalidate } from '$app/navigation';
|
||||
import { type Columns, PROHIBITED_ROW_KEYS } from '../store';
|
||||
import ColumnItem from './columns/columnItem.svelte';
|
||||
import { buildWildcardColumnsQuery, isRelationship, isRelationshipToMany } from './store';
|
||||
import {
|
||||
buildWildcardColumnsQuery,
|
||||
isRelationship,
|
||||
isRelationshipToMany,
|
||||
buildPayload
|
||||
} from './store';
|
||||
import { Accordion, Layout, Skeleton } from '@appwrite.io/pink-svelte';
|
||||
import { deepClone } from '$lib/helpers/object';
|
||||
import { preferences } from '$lib/stores/preferences';
|
||||
@@ -258,11 +263,15 @@
|
||||
const work = workData.get(rowId);
|
||||
|
||||
const workValue = get(work);
|
||||
const payload = buildPayload(
|
||||
relatedTable.fields,
|
||||
workValue as Record<string, unknown>
|
||||
);
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: relatedTable.$id,
|
||||
rowId: rowId,
|
||||
data: workValue,
|
||||
data: payload,
|
||||
permissions: workValue.$permissions
|
||||
});
|
||||
|
||||
@@ -276,13 +285,17 @@
|
||||
if (!work) return;
|
||||
|
||||
const workValue = get(work);
|
||||
const payload = buildPayload(
|
||||
relatedTable.fields,
|
||||
workValue as Record<string, unknown>
|
||||
);
|
||||
return sdk
|
||||
.forProject(page.params.region, page.params.project)
|
||||
.tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: relatedTable.$id,
|
||||
rowId: row.$id,
|
||||
data: workValue,
|
||||
data: payload,
|
||||
permissions: workValue.$permissions
|
||||
});
|
||||
});
|
||||
|
||||
+41
@@ -52,6 +52,47 @@ export function isSpatialType(
|
||||
return spatialTypes.includes(field.type.toLowerCase());
|
||||
}
|
||||
|
||||
function castBigIntValue(value: unknown): unknown {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (typeof value === 'bigint') {
|
||||
return value;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log({ value });
|
||||
return BigInt(value as string | number | boolean);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
export function buildPayload(
|
||||
fields: Field[] | undefined,
|
||||
row: Record<string, unknown>
|
||||
): Record<string, unknown> {
|
||||
const payload = structuredClone(row);
|
||||
|
||||
for (const field of fields ?? []) {
|
||||
if (field.type !== 'bigint') {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = payload[field.key];
|
||||
|
||||
if (field.array && Array.isArray(value)) {
|
||||
payload[field.key] = value.map((item) => castBigIntValue(item));
|
||||
continue;
|
||||
}
|
||||
|
||||
payload[field.key] = castBigIntValue(value);
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns select queries for all main and related fields in an `Entity`.
|
||||
*/
|
||||
|
||||
+4
-1
@@ -17,6 +17,7 @@
|
||||
buildWildcardColumnsQuery,
|
||||
isRelationship,
|
||||
isRelationshipToMany,
|
||||
buildPayload,
|
||||
isSpatialType,
|
||||
isTextType
|
||||
} from './rows/store';
|
||||
@@ -645,11 +646,13 @@
|
||||
|
||||
async function updateRowContents(row: Models.Row) {
|
||||
try {
|
||||
const payload = buildPayload(table.fields, row as Record<string, unknown>);
|
||||
|
||||
await sdk.forProject(page.params.region, page.params.project).tablesDB.updateRow({
|
||||
databaseId,
|
||||
tableId: table.$id,
|
||||
rowId: row.$id,
|
||||
data: row,
|
||||
data: payload,
|
||||
permissions: row.$permissions
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user