@constructive-io/sheets 0.4.1 → 0.6.1
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 +19 -24
- package/dist/advanced.cjs +250 -405
- package/dist/advanced.cjs.map +1 -1
- package/dist/advanced.d.cts +9 -10
- package/dist/advanced.d.ts +9 -10
- package/dist/advanced.js +3 -3
- package/dist/auth.cjs +10 -10
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +5 -4
- package/dist/auth.d.ts +5 -4
- package/dist/auth.js +3 -3
- package/dist/{chunk-GLVZSPV2.js → chunk-4EZ6A23C.js} +4 -3
- package/dist/chunk-4EZ6A23C.js.map +1 -0
- package/dist/{chunk-3BNOZQIJ.js → chunk-KKAWMVEG.js} +11 -11
- package/dist/chunk-KKAWMVEG.js.map +1 -0
- package/dist/{chunk-FG2LRZP5.js → chunk-KOZAW264.js} +4 -3
- package/dist/chunk-KOZAW264.js.map +1 -0
- package/dist/{chunk-BWJVRYJT.js → chunk-KVPVEXWB.js} +40 -17
- package/dist/chunk-KVPVEXWB.js.map +1 -0
- package/dist/{chunk-BWKB52JB.js → chunk-LR64FLWO.js} +231 -379
- package/dist/chunk-LR64FLWO.js.map +1 -0
- package/dist/{chunk-SDKHWE7G.js → chunk-ZETPUEXH.js} +27 -2
- package/dist/chunk-ZETPUEXH.js.map +1 -0
- package/dist/{date-editor-CXKKGNL6.js → date-editor-QT47WY5T.js} +5 -3
- package/dist/date-editor-QT47WY5T.js.map +1 -0
- package/dist/{editor-props-M6Dh0P9f.d.ts → grid-cell-types-C3ARj148.d.cts} +70 -62
- package/dist/{editor-props-M6Dh0P9f.d.cts → grid-cell-types-C3ARj148.d.ts} +70 -62
- package/dist/index.cjs +564 -493
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +86 -35
- package/dist/index.d.ts +86 -35
- package/dist/index.js +264 -72
- package/dist/index.js.map +1 -1
- package/dist/{sheets-context-9u9r7Bs0.d.ts → sheets-context-B03WDhZ9.d.cts} +13 -6
- package/dist/{sheets-context-BjGIHocT.d.cts → sheets-context-DmVCOgiX.d.ts} +13 -6
- package/dist/styles.css +6 -0
- package/dist/testing.cjs +99 -33
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +11 -7
- package/dist/testing.d.ts +11 -7
- package/dist/testing.js +34 -8
- package/dist/testing.js.map +1 -1
- package/package.json +15 -16
- package/dist/chunk-3BNOZQIJ.js.map +0 -1
- package/dist/chunk-BWJVRYJT.js.map +0 -1
- package/dist/chunk-BWKB52JB.js.map +0 -1
- package/dist/chunk-FG2LRZP5.js.map +0 -1
- package/dist/chunk-GLVZSPV2.js.map +0 -1
- package/dist/chunk-SDKHWE7G.js.map +0 -1
- package/dist/date-editor-CXKKGNL6.js.map +0 -1
package/dist/advanced.cjs
CHANGED
|
@@ -377,8 +377,10 @@ var init_date_editor = __esm({
|
|
|
377
377
|
const isDateTimeType = dateType === "datetime" || dateType === "timestamptz";
|
|
378
378
|
const handleDateSelect = (0, import_react3.useCallback)(
|
|
379
379
|
(dateValue2) => {
|
|
380
|
-
|
|
381
|
-
const
|
|
380
|
+
if (Array.isArray(dateValue2)) return;
|
|
381
|
+
const selectedValue = dateValue2;
|
|
382
|
+
setSelectedDate(selectedValue);
|
|
383
|
+
const jsDate = dateValueToDate(selectedValue);
|
|
382
384
|
if (jsDate) {
|
|
383
385
|
if (isDateTimeType && currentDateValue) {
|
|
384
386
|
const currentDate = new Date(currentDateValue);
|
|
@@ -1623,20 +1625,20 @@ function useSheetsStoreApi() {
|
|
|
1623
1625
|
// src/hooks/use-sheets-upload.ts
|
|
1624
1626
|
var import_react12 = require("react");
|
|
1625
1627
|
var import_react_query3 = require("@tanstack/react-query");
|
|
1626
|
-
var
|
|
1628
|
+
var import_data11 = require("@constructive-io/data");
|
|
1627
1629
|
|
|
1628
1630
|
// src/hooks/use-sheets-meta.ts
|
|
1629
1631
|
var import_react_query2 = require("@tanstack/react-query");
|
|
1630
1632
|
|
|
1631
1633
|
// src/adapter/postgraphile-adapter.ts
|
|
1632
|
-
var
|
|
1634
|
+
var import_data7 = require("@constructive-io/data");
|
|
1633
1635
|
|
|
1634
1636
|
// src/hooks/use-sheets-table.ts
|
|
1635
1637
|
var import_react11 = require("react");
|
|
1636
1638
|
var import_react_query = require("@tanstack/react-query");
|
|
1637
|
-
var import_data3 = require("@constructive-io/data");
|
|
1638
1639
|
var import_data4 = require("@constructive-io/data");
|
|
1639
1640
|
var import_data5 = require("@constructive-io/data");
|
|
1641
|
+
var import_data6 = require("@constructive-io/data");
|
|
1640
1642
|
|
|
1641
1643
|
// src/hooks/query-keys.ts
|
|
1642
1644
|
var sheetsQueryKeys = {
|
|
@@ -1862,14 +1864,56 @@ async function validateOrderByVariables(variables, table, scopeKey, queryClient,
|
|
|
1862
1864
|
}
|
|
1863
1865
|
}
|
|
1864
1866
|
|
|
1865
|
-
// src/
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1867
|
+
// src/row-identity.ts
|
|
1868
|
+
var import_data3 = require("@constructive-io/data");
|
|
1869
|
+
function isLegacyScalarId(primaryKey) {
|
|
1870
|
+
const entries = Object.entries(primaryKey);
|
|
1871
|
+
return entries.length === 1 && entries[0][0] === "id" && (typeof entries[0][1] === "string" || typeof entries[0][1] === "number");
|
|
1872
|
+
}
|
|
1873
|
+
function resolveSheetsRowIdentity(table, row) {
|
|
1874
|
+
const resolution = (0, import_data3.resolveRowIdentity)(table, row);
|
|
1875
|
+
if (resolution.status === "read-only") {
|
|
1876
|
+
return { status: "unavailable", reason: "no-primary-key" };
|
|
1877
|
+
}
|
|
1878
|
+
if (resolution.status === "invalid-row") {
|
|
1879
|
+
return { status: "unavailable", reason: "invalid-row" };
|
|
1880
|
+
}
|
|
1881
|
+
const primaryKey = (0, import_data3.rowIdentityToPrimaryKey)(resolution.identity);
|
|
1882
|
+
return {
|
|
1883
|
+
status: "identified",
|
|
1884
|
+
identifier: isLegacyScalarId(primaryKey) ? primaryKey.id : primaryKey,
|
|
1885
|
+
primaryKey,
|
|
1886
|
+
key: (0, import_data3.serializeRowIdentity)(resolution.identity)
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
function resolveSheetsIdentifier(table, identifier) {
|
|
1890
|
+
const row = typeof identifier === "object" && identifier !== null ? identifier : { id: identifier };
|
|
1891
|
+
return resolveSheetsRowIdentity(table, row);
|
|
1892
|
+
}
|
|
1893
|
+
function sheetsIdentifierToWhere(table, identifier) {
|
|
1894
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
1895
|
+
if (resolution.status !== "identified") return null;
|
|
1896
|
+
return Object.fromEntries(
|
|
1897
|
+
Object.entries(resolution.primaryKey).map(([field, value]) => [field, { equalTo: value }])
|
|
1898
|
+
);
|
|
1899
|
+
}
|
|
1900
|
+
function sheetsIdentifierCacheKey(table, identifier) {
|
|
1901
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
1902
|
+
if (resolution.status !== "identified") return null;
|
|
1903
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
1904
|
+
}
|
|
1905
|
+
function assertSheetsMutationAllowed(table, operation) {
|
|
1906
|
+
const capability = (0, import_data3.assessTableWriteCapability)(table);
|
|
1907
|
+
if (capability.status === "read-only") {
|
|
1908
|
+
throw new Error(`Table '${table.name}' is read-only because it has no primary key.`);
|
|
1909
|
+
}
|
|
1910
|
+
if (!capability.operations[operation]) {
|
|
1911
|
+
const article = operation === "update" ? "an" : "a";
|
|
1912
|
+
throw new Error(`Table '${table.name}' does not expose ${article} ${operation} mutation.`);
|
|
1869
1913
|
}
|
|
1870
|
-
const candidate = row.id;
|
|
1871
|
-
return typeof candidate === "string" || typeof candidate === "number" ? candidate : null;
|
|
1872
1914
|
}
|
|
1915
|
+
|
|
1916
|
+
// src/hooks/use-sheets-table.ts
|
|
1873
1917
|
function transformRelationData(data, table) {
|
|
1874
1918
|
if (!data) return [];
|
|
1875
1919
|
if (!Array.isArray(data)) return data;
|
|
@@ -1921,7 +1965,7 @@ function transformToPostGraphileVariables(table, options = {}) {
|
|
|
1921
1965
|
}
|
|
1922
1966
|
if (options.orderBy && options.orderBy.length > 0) {
|
|
1923
1967
|
const availableFields = new Set(table.fields.map((field) => field.name));
|
|
1924
|
-
variables.orderBy = options.orderBy.filter(({ field }) => availableFields.has(field)).map(({ field, direction }) => (0,
|
|
1968
|
+
variables.orderBy = options.orderBy.filter(({ field }) => availableFields.has(field)).map(({ field, direction }) => (0, import_data6.toOrderByEnumValue)(field, direction));
|
|
1925
1969
|
}
|
|
1926
1970
|
if (options.where) {
|
|
1927
1971
|
variables.where = options.where;
|
|
@@ -1933,14 +1977,33 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
1933
1977
|
const { execute, scopeKey } = useSheetsContext();
|
|
1934
1978
|
const { data: meta } = useSheetsMeta();
|
|
1935
1979
|
const adapter = useSheetsAdapter();
|
|
1936
|
-
const
|
|
1980
|
+
const metaTables = (0, import_react11.useMemo)(() => {
|
|
1937
1981
|
if (!meta?._meta?.tables) return [];
|
|
1938
|
-
return meta._meta.tables.filter((candidate) => candidate != null)
|
|
1982
|
+
return meta._meta.tables.filter((candidate) => candidate != null);
|
|
1939
1983
|
}, [meta]);
|
|
1984
|
+
const tables = (0, import_react11.useMemo)(() => metaTables.map(import_data4.cleanTable), [metaTables]);
|
|
1940
1985
|
const table = (0, import_react11.useMemo)(
|
|
1941
1986
|
() => tables.find((candidate) => candidate.name === tableName) ?? null,
|
|
1942
1987
|
[tables, tableName]
|
|
1943
1988
|
);
|
|
1989
|
+
const tableMeta = (0, import_react11.useMemo)(
|
|
1990
|
+
() => metaTables.find((candidate) => candidate.name === tableName) ?? null,
|
|
1991
|
+
[metaTables, tableName]
|
|
1992
|
+
);
|
|
1993
|
+
const resolveIdentifier = (identifier) => {
|
|
1994
|
+
if (!tableMeta) throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
1995
|
+
const resolution = resolveSheetsIdentifier(tableMeta, identifier);
|
|
1996
|
+
if (resolution.status !== "identified") {
|
|
1997
|
+
throw import_data5.createError.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
1998
|
+
}
|
|
1999
|
+
return resolution.identifier;
|
|
2000
|
+
};
|
|
2001
|
+
const rowCacheKey = (row) => {
|
|
2002
|
+
if (!tableMeta || !row) return null;
|
|
2003
|
+
const resolution = resolveSheetsRowIdentity(tableMeta, row);
|
|
2004
|
+
if (resolution.status !== "identified") return null;
|
|
2005
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
2006
|
+
};
|
|
1944
2007
|
const { enabled = true, select: fieldSelection, mutationOptions = {}, ...queryOptions } = options;
|
|
1945
2008
|
const finalQueryOptions = {
|
|
1946
2009
|
...queryOptions,
|
|
@@ -1955,7 +2018,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
1955
2018
|
queryKey: sheetsTableQueryKeys.tableRows(scopeKey, tableName, finalQueryOptions),
|
|
1956
2019
|
queryFn: async () => {
|
|
1957
2020
|
if (!table) {
|
|
1958
|
-
throw
|
|
2021
|
+
throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
1959
2022
|
}
|
|
1960
2023
|
const variables = transformToPostGraphileVariables(table, finalQueryOptions);
|
|
1961
2024
|
const [relationFieldMap] = await Promise.all([
|
|
@@ -1971,7 +2034,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
1971
2034
|
const validatedOrderByEnum = new Set(variables.orderBy ?? []);
|
|
1972
2035
|
const availableOrderByFields = new Set(table.fields.map((field) => field.name));
|
|
1973
2036
|
const validatedOrderBy = finalQueryOptions.orderBy?.filter(
|
|
1974
|
-
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0,
|
|
2037
|
+
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0, import_data6.toOrderByEnumValue)(field, direction))
|
|
1975
2038
|
);
|
|
1976
2039
|
const { rows, totalCount: totalCount2 } = await adapter.listRows(
|
|
1977
2040
|
{ table, allTables: tables, tableName },
|
|
@@ -1997,10 +2060,11 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
1997
2060
|
const createMutation = (0, import_react_query.useMutation)({
|
|
1998
2061
|
mutationKey: sheetsTableMutationKeys.create(scopeKey, tableName),
|
|
1999
2062
|
mutationFn: async (data2) => {
|
|
2000
|
-
if (!table) {
|
|
2001
|
-
throw
|
|
2063
|
+
if (!table || !tableMeta) {
|
|
2064
|
+
throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
2002
2065
|
}
|
|
2003
|
-
|
|
2066
|
+
assertSheetsMutationAllowed(tableMeta, "create");
|
|
2067
|
+
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(import_data4.cleanTable) : [];
|
|
2004
2068
|
const createdRow = await adapter.createRow({ table, allTables, tableName }, data2, execute, {
|
|
2005
2069
|
...mutationOptions,
|
|
2006
2070
|
fieldSelection: mutationOptions.fieldSelection || fieldSelection || "display"
|
|
@@ -2010,20 +2074,22 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
2010
2074
|
onSuccess: ({ createdRow }) => {
|
|
2011
2075
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
2012
2076
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
2013
|
-
const
|
|
2014
|
-
if (
|
|
2015
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
2077
|
+
const createdRowKey = rowCacheKey(createdRow);
|
|
2078
|
+
if (createdRowKey !== null) {
|
|
2079
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, createdRowKey), createdRow);
|
|
2016
2080
|
}
|
|
2017
2081
|
}
|
|
2018
2082
|
});
|
|
2019
2083
|
const updateMutation = (0, import_react_query.useMutation)({
|
|
2020
2084
|
mutationKey: sheetsTableMutationKeys.update(scopeKey, tableName),
|
|
2021
2085
|
mutationFn: async ({ id, patch }) => {
|
|
2022
|
-
if (!table) {
|
|
2023
|
-
throw
|
|
2086
|
+
if (!table || !tableMeta) {
|
|
2087
|
+
throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
2024
2088
|
}
|
|
2025
|
-
|
|
2026
|
-
const
|
|
2089
|
+
assertSheetsMutationAllowed(tableMeta, "update");
|
|
2090
|
+
const mutationIdentifier = resolveIdentifier(id);
|
|
2091
|
+
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(import_data4.cleanTable) : [];
|
|
2092
|
+
const updatedRow = await adapter.updateRow({ table, allTables, tableName }, mutationIdentifier, patch, execute, {
|
|
2027
2093
|
...mutationOptions,
|
|
2028
2094
|
fieldSelection: mutationOptions.fieldSelection || fieldSelection || "display"
|
|
2029
2095
|
});
|
|
@@ -2038,6 +2104,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
2038
2104
|
onMutate: async ({ id, patch }) => {
|
|
2039
2105
|
const tablePrefix = sheetsTableQueryKeys.table(scopeKey, tableName);
|
|
2040
2106
|
await queryClient.cancelQueries({ queryKey: tablePrefix });
|
|
2107
|
+
const targetKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, id) : null;
|
|
2041
2108
|
const isRowsKey = (key) => key[key.length - 2] === "rows";
|
|
2042
2109
|
const previousRows = queryClient.getQueriesData({ queryKey: tablePrefix }).filter(([key]) => isRowsKey(key));
|
|
2043
2110
|
for (const [key] of previousRows) {
|
|
@@ -2045,7 +2112,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
2045
2112
|
if (!old) return old;
|
|
2046
2113
|
let changed = false;
|
|
2047
2114
|
const rows = old.rows.map((row) => {
|
|
2048
|
-
if (
|
|
2115
|
+
if (targetKey !== null && rowCacheKey(row) === targetKey) {
|
|
2049
2116
|
changed = true;
|
|
2050
2117
|
return { ...row, ...patch };
|
|
2051
2118
|
}
|
|
@@ -2061,51 +2128,58 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
2061
2128
|
},
|
|
2062
2129
|
onSuccess: ({ updatedRow }) => {
|
|
2063
2130
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
2064
|
-
const
|
|
2065
|
-
if (
|
|
2066
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
2131
|
+
const updatedRowKey = rowCacheKey(updatedRow);
|
|
2132
|
+
if (updatedRowKey !== null) {
|
|
2133
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, updatedRowKey), updatedRow);
|
|
2067
2134
|
}
|
|
2068
2135
|
}
|
|
2069
2136
|
});
|
|
2070
2137
|
const deleteMutation = (0, import_react_query.useMutation)({
|
|
2071
2138
|
mutationKey: sheetsTableMutationKeys.delete(scopeKey, tableName),
|
|
2072
2139
|
mutationFn: async (idOrPk) => {
|
|
2073
|
-
if (!table) {
|
|
2074
|
-
throw
|
|
2140
|
+
if (!table || !tableMeta) {
|
|
2141
|
+
throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
2075
2142
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2143
|
+
assertSheetsMutationAllowed(tableMeta, "delete");
|
|
2144
|
+
const mutationIdentifier = resolveIdentifier(idOrPk);
|
|
2145
|
+
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(import_data4.cleanTable) : [];
|
|
2146
|
+
await adapter.deleteRow({ table, allTables, tableName }, mutationIdentifier, execute, mutationOptions);
|
|
2078
2147
|
return { deletedId: idOrPk, __rawResult: {} };
|
|
2079
2148
|
},
|
|
2080
2149
|
onSuccess: ({ deletedId }) => {
|
|
2081
2150
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
2082
2151
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
2083
|
-
|
|
2152
|
+
const deletedRowKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, deletedId) : null;
|
|
2153
|
+
if (deletedRowKey !== null) {
|
|
2084
2154
|
queryClient.removeQueries({
|
|
2085
|
-
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
2155
|
+
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName, deletedRowKey)
|
|
2086
2156
|
});
|
|
2087
2157
|
}
|
|
2088
2158
|
}
|
|
2089
2159
|
});
|
|
2090
2160
|
const findOne = async (id) => {
|
|
2091
|
-
if (!table) {
|
|
2092
|
-
throw
|
|
2161
|
+
if (!table || !tableMeta) {
|
|
2162
|
+
throw import_data5.createError.notFound(`Table '${tableName}' not found`);
|
|
2163
|
+
}
|
|
2164
|
+
const where = sheetsIdentifierToWhere(tableMeta, id);
|
|
2165
|
+
if (!where) {
|
|
2166
|
+
throw import_data5.createError.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
2093
2167
|
}
|
|
2094
|
-
const doc = (0,
|
|
2095
|
-
where
|
|
2168
|
+
const doc = (0, import_data6.buildSelect)(table, tables, {
|
|
2169
|
+
where,
|
|
2096
2170
|
limit: 1
|
|
2097
2171
|
});
|
|
2098
2172
|
const variables = transformToPostGraphileVariables(table, {
|
|
2099
|
-
where
|
|
2173
|
+
where,
|
|
2100
2174
|
limit: 1
|
|
2101
2175
|
});
|
|
2102
2176
|
const result = await execute(doc, variables);
|
|
2103
|
-
const singularName = (0,
|
|
2177
|
+
const singularName = (0, import_data6.toCamelCaseSingular)(tableName, table);
|
|
2104
2178
|
const singularData = result[singularName];
|
|
2105
2179
|
if (singularData && typeof singularData === "object") {
|
|
2106
2180
|
return singularData;
|
|
2107
2181
|
}
|
|
2108
|
-
const queryTableName = (0,
|
|
2182
|
+
const queryTableName = (0, import_data6.toCamelCasePlural)(tableName, table);
|
|
2109
2183
|
const data2 = result[queryTableName];
|
|
2110
2184
|
if (data2 && typeof data2 === "object" && "nodes" in data2) {
|
|
2111
2185
|
const nodes = data2.nodes || [];
|
|
@@ -2146,319 +2220,83 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
2146
2220
|
}
|
|
2147
2221
|
|
|
2148
2222
|
// src/adapter/postgraphile-adapter.ts
|
|
2149
|
-
var
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
name
|
|
2194
|
-
type {
|
|
2195
|
-
gqlType
|
|
2196
|
-
isArray
|
|
2197
|
-
pgType
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
constraints {
|
|
2202
|
-
primaryKey {
|
|
2203
|
-
name
|
|
2204
|
-
fields {
|
|
2205
|
-
name
|
|
2206
|
-
type {
|
|
2207
|
-
gqlType
|
|
2208
|
-
isArray
|
|
2209
|
-
pgType
|
|
2210
|
-
}
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
unique {
|
|
2214
|
-
name
|
|
2215
|
-
fields {
|
|
2216
|
-
name
|
|
2217
|
-
type {
|
|
2218
|
-
gqlType
|
|
2219
|
-
isArray
|
|
2220
|
-
pgType
|
|
2221
|
-
}
|
|
2222
|
-
}
|
|
2223
|
-
}
|
|
2224
|
-
foreignKey {
|
|
2225
|
-
name
|
|
2226
|
-
fields {
|
|
2227
|
-
name
|
|
2228
|
-
type {
|
|
2229
|
-
gqlType
|
|
2230
|
-
isArray
|
|
2231
|
-
pgType
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
refFields {
|
|
2235
|
-
name
|
|
2236
|
-
type {
|
|
2237
|
-
gqlType
|
|
2238
|
-
isArray
|
|
2239
|
-
pgType
|
|
2240
|
-
}
|
|
2241
|
-
}
|
|
2242
|
-
refTable {
|
|
2243
|
-
name
|
|
2244
|
-
}
|
|
2245
|
-
}
|
|
2246
|
-
}
|
|
2247
|
-
foreignKeyConstraints {
|
|
2248
|
-
name
|
|
2249
|
-
fields {
|
|
2250
|
-
name
|
|
2251
|
-
type {
|
|
2252
|
-
gqlType
|
|
2253
|
-
isArray
|
|
2254
|
-
pgType
|
|
2255
|
-
}
|
|
2256
|
-
}
|
|
2257
|
-
refFields {
|
|
2258
|
-
name
|
|
2259
|
-
type {
|
|
2260
|
-
gqlType
|
|
2261
|
-
isArray
|
|
2262
|
-
pgType
|
|
2263
|
-
}
|
|
2264
|
-
}
|
|
2265
|
-
refTable {
|
|
2266
|
-
name
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
primaryKeyConstraints {
|
|
2270
|
-
name
|
|
2271
|
-
fields {
|
|
2272
|
-
name
|
|
2273
|
-
type {
|
|
2274
|
-
gqlType
|
|
2275
|
-
isArray
|
|
2276
|
-
pgType
|
|
2277
|
-
}
|
|
2278
|
-
}
|
|
2279
|
-
}
|
|
2280
|
-
uniqueConstraints {
|
|
2281
|
-
name
|
|
2282
|
-
fields {
|
|
2283
|
-
name
|
|
2284
|
-
type {
|
|
2285
|
-
gqlType
|
|
2286
|
-
isArray
|
|
2287
|
-
pgType
|
|
2288
|
-
}
|
|
2289
|
-
}
|
|
2290
|
-
}
|
|
2291
|
-
relations {
|
|
2292
|
-
belongsTo {
|
|
2293
|
-
fieldName
|
|
2294
|
-
isUnique
|
|
2295
|
-
keys {
|
|
2296
|
-
name
|
|
2297
|
-
type {
|
|
2298
|
-
gqlType
|
|
2299
|
-
isArray
|
|
2300
|
-
pgType
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
references {
|
|
2304
|
-
name
|
|
2305
|
-
}
|
|
2306
|
-
type
|
|
2307
|
-
}
|
|
2308
|
-
has {
|
|
2309
|
-
fieldName
|
|
2310
|
-
isUnique
|
|
2311
|
-
keys {
|
|
2312
|
-
name
|
|
2313
|
-
type {
|
|
2314
|
-
gqlType
|
|
2315
|
-
isArray
|
|
2316
|
-
pgType
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
referencedBy {
|
|
2320
|
-
name
|
|
2321
|
-
}
|
|
2322
|
-
type
|
|
2323
|
-
}
|
|
2324
|
-
hasOne {
|
|
2325
|
-
fieldName
|
|
2326
|
-
isUnique
|
|
2327
|
-
keys {
|
|
2328
|
-
name
|
|
2329
|
-
type {
|
|
2330
|
-
gqlType
|
|
2331
|
-
isArray
|
|
2332
|
-
pgType
|
|
2333
|
-
}
|
|
2334
|
-
}
|
|
2335
|
-
referencedBy {
|
|
2336
|
-
name
|
|
2337
|
-
}
|
|
2338
|
-
type
|
|
2339
|
-
}
|
|
2340
|
-
hasMany {
|
|
2341
|
-
fieldName
|
|
2342
|
-
isUnique
|
|
2343
|
-
keys {
|
|
2344
|
-
name
|
|
2345
|
-
type {
|
|
2346
|
-
gqlType
|
|
2347
|
-
isArray
|
|
2348
|
-
pgType
|
|
2349
|
-
}
|
|
2350
|
-
}
|
|
2351
|
-
referencedBy {
|
|
2352
|
-
name
|
|
2353
|
-
}
|
|
2354
|
-
type
|
|
2355
|
-
}
|
|
2356
|
-
manyToMany {
|
|
2357
|
-
fieldName
|
|
2358
|
-
junctionLeftConstraint {
|
|
2359
|
-
name
|
|
2360
|
-
fields {
|
|
2361
|
-
name
|
|
2362
|
-
type {
|
|
2363
|
-
gqlType
|
|
2364
|
-
isArray
|
|
2365
|
-
pgType
|
|
2366
|
-
}
|
|
2367
|
-
}
|
|
2368
|
-
refFields {
|
|
2369
|
-
name
|
|
2370
|
-
type {
|
|
2371
|
-
gqlType
|
|
2372
|
-
isArray
|
|
2373
|
-
pgType
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
refTable {
|
|
2377
|
-
name
|
|
2378
|
-
}
|
|
2379
|
-
}
|
|
2380
|
-
junctionLeftKeyAttributes {
|
|
2381
|
-
name
|
|
2382
|
-
type {
|
|
2383
|
-
gqlType
|
|
2384
|
-
isArray
|
|
2385
|
-
pgType
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
junctionRightConstraint {
|
|
2389
|
-
name
|
|
2390
|
-
fields {
|
|
2391
|
-
name
|
|
2392
|
-
type {
|
|
2393
|
-
gqlType
|
|
2394
|
-
isArray
|
|
2395
|
-
pgType
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
refFields {
|
|
2399
|
-
name
|
|
2400
|
-
type {
|
|
2401
|
-
gqlType
|
|
2402
|
-
isArray
|
|
2403
|
-
pgType
|
|
2404
|
-
}
|
|
2405
|
-
}
|
|
2406
|
-
refTable {
|
|
2407
|
-
name
|
|
2408
|
-
}
|
|
2409
|
-
}
|
|
2410
|
-
junctionRightKeyAttributes {
|
|
2411
|
-
name
|
|
2412
|
-
type {
|
|
2413
|
-
gqlType
|
|
2414
|
-
isArray
|
|
2415
|
-
pgType
|
|
2416
|
-
}
|
|
2417
|
-
}
|
|
2418
|
-
junctionTable {
|
|
2419
|
-
name
|
|
2420
|
-
}
|
|
2421
|
-
leftKeyAttributes {
|
|
2422
|
-
name
|
|
2423
|
-
type {
|
|
2424
|
-
gqlType
|
|
2425
|
-
isArray
|
|
2426
|
-
pgType
|
|
2427
|
-
}
|
|
2428
|
-
}
|
|
2429
|
-
rightKeyAttributes {
|
|
2430
|
-
name
|
|
2431
|
-
type {
|
|
2432
|
-
gqlType
|
|
2433
|
-
isArray
|
|
2434
|
-
pgType
|
|
2435
|
-
}
|
|
2436
|
-
}
|
|
2437
|
-
rightTable {
|
|
2438
|
-
name
|
|
2439
|
-
}
|
|
2440
|
-
type
|
|
2441
|
-
}
|
|
2442
|
-
}
|
|
2443
|
-
}
|
|
2444
|
-
}
|
|
2445
|
-
}
|
|
2446
|
-
`);
|
|
2223
|
+
var compatibilityChecks = /* @__PURE__ */ new WeakMap();
|
|
2224
|
+
var enumMappings = /* @__PURE__ */ new WeakMap();
|
|
2225
|
+
async function ensureCurrentMetaContract(execute) {
|
|
2226
|
+
const cached = compatibilityChecks.get(execute);
|
|
2227
|
+
if (cached) return cached;
|
|
2228
|
+
const check = execute(import_data7.META_CONTRACT_INTROSPECTION_DOCUMENT).then(
|
|
2229
|
+
(result) => {
|
|
2230
|
+
(0, import_data7.assertMetaContract)(result);
|
|
2231
|
+
}
|
|
2232
|
+
);
|
|
2233
|
+
compatibilityChecks.set(execute, check);
|
|
2234
|
+
try {
|
|
2235
|
+
await check;
|
|
2236
|
+
} catch (error) {
|
|
2237
|
+
if (compatibilityChecks.get(execute) === check) compatibilityChecks.delete(execute);
|
|
2238
|
+
throw error;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
function hasDeclaredEnums(meta) {
|
|
2242
|
+
return Boolean(meta._meta?.tables?.some(
|
|
2243
|
+
(table) => table?.fields?.some((field) => Boolean(field?.enumValues?.name))
|
|
2244
|
+
));
|
|
2245
|
+
}
|
|
2246
|
+
function schemaCompatibilityError(missingPaths) {
|
|
2247
|
+
const detail = missingPaths.length > 0 ? ` Missing: ${missingPaths.join(", ")}.` : "";
|
|
2248
|
+
return import_data7.createError.badRequest(
|
|
2249
|
+
`The GraphQL schema does not match the enum values declared by Constructive _meta.${detail}`,
|
|
2250
|
+
"SCHEMA_INTROSPECTION_INCOMPATIBLE"
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
function normalizeMutationEnums(ctx, input, execute) {
|
|
2254
|
+
const hasEnumInput = ctx.table.fields.some(
|
|
2255
|
+
(field) => Boolean(field.enumValues?.length) && Object.prototype.hasOwnProperty.call(input, field.name)
|
|
2256
|
+
);
|
|
2257
|
+
if (!hasEnumInput) return input;
|
|
2258
|
+
const mappings = enumMappings.get(execute);
|
|
2259
|
+
if (!mappings) {
|
|
2260
|
+
throw import_data7.createError.badRequest(
|
|
2261
|
+
"Enum schema mappings are unavailable. Load table metadata before mutating enum fields.",
|
|
2262
|
+
"ENUM_MAPPING_UNAVAILABLE"
|
|
2263
|
+
);
|
|
2264
|
+
}
|
|
2265
|
+
return (0, import_data7.normalizeSchemaEnumInputValues)(input, ctx.table, mappings);
|
|
2266
|
+
}
|
|
2447
2267
|
function createPostGraphileAdapter() {
|
|
2448
2268
|
return {
|
|
2449
2269
|
async fetchMeta(execute) {
|
|
2450
|
-
|
|
2270
|
+
await ensureCurrentMetaContract(execute);
|
|
2271
|
+
const meta = await execute(import_data7.META_DOCUMENT);
|
|
2272
|
+
(0, import_data7.assertMetaQuery)(meta);
|
|
2273
|
+
if (!hasDeclaredEnums(meta)) {
|
|
2274
|
+
enumMappings.set(execute, []);
|
|
2275
|
+
return meta;
|
|
2276
|
+
}
|
|
2277
|
+
try {
|
|
2278
|
+
const introspection = await execute(import_data7.SCHEMA_INTROSPECTION_QUERY);
|
|
2279
|
+
const analysis = (0, import_data7.analyzeSchemaIntrospectionCompatibility)(introspection, meta);
|
|
2280
|
+
if (analysis.status !== "compatible") {
|
|
2281
|
+
throw schemaCompatibilityError(analysis.missingPaths);
|
|
2282
|
+
}
|
|
2283
|
+
enumMappings.set(execute, analysis.enumMappings);
|
|
2284
|
+
} catch (error) {
|
|
2285
|
+
enumMappings.delete(execute);
|
|
2286
|
+
throw error;
|
|
2287
|
+
}
|
|
2288
|
+
return meta;
|
|
2451
2289
|
},
|
|
2452
2290
|
async listRows(ctx, query, execute) {
|
|
2453
2291
|
const { table, allTables, tableName } = ctx;
|
|
2454
2292
|
const { relationFieldMap, ...queryOptions } = query;
|
|
2455
2293
|
const variables = transformToPostGraphileVariables(table, queryOptions);
|
|
2456
|
-
const doc = (0,
|
|
2294
|
+
const doc = (0, import_data7.buildSelect)(table, allTables, {
|
|
2457
2295
|
...queryOptions,
|
|
2458
2296
|
relationFieldMap
|
|
2459
2297
|
});
|
|
2460
2298
|
const result = await execute(doc, variables);
|
|
2461
|
-
const queryTableName = (0,
|
|
2299
|
+
const queryTableName = (0, import_data7.toCamelCasePlural)(tableName, table);
|
|
2462
2300
|
const connection = result[queryTableName];
|
|
2463
2301
|
if (connection && typeof connection === "object" && "nodes" in connection) {
|
|
2464
2302
|
const nodes = connection.nodes || [];
|
|
@@ -2471,54 +2309,56 @@ function createPostGraphileAdapter() {
|
|
|
2471
2309
|
const directData = connection || [];
|
|
2472
2310
|
return {
|
|
2473
2311
|
rows: transformRelationData(directData, table),
|
|
2474
|
-
// Non-Relay direct-array response: page length only, not a full filtered count.
|
|
2475
2312
|
totalCount: directData.length
|
|
2476
2313
|
};
|
|
2477
2314
|
},
|
|
2478
2315
|
async createRow(ctx, data, execute, options = {}) {
|
|
2479
2316
|
const { table, allTables, tableName } = ctx;
|
|
2480
|
-
const doc = (0,
|
|
2317
|
+
const doc = (0, import_data7.buildPostGraphileCreate)(table, allTables, {
|
|
2481
2318
|
...options,
|
|
2482
2319
|
fieldSelection: options.fieldSelection || "display"
|
|
2483
2320
|
});
|
|
2484
|
-
const singularName = (0,
|
|
2485
|
-
const sanitizedData = (
|
|
2321
|
+
const singularName = (0, import_data7.toCamelCaseSingular)(tableName, table);
|
|
2322
|
+
const sanitizedData = normalizeMutationEnums(
|
|
2323
|
+
ctx,
|
|
2324
|
+
(0, import_data7.prepareCreateInput)(data),
|
|
2325
|
+
execute
|
|
2326
|
+
);
|
|
2486
2327
|
const variables = {
|
|
2487
2328
|
input: {
|
|
2488
2329
|
[singularName]: sanitizedData
|
|
2489
2330
|
}
|
|
2490
2331
|
};
|
|
2491
2332
|
const result = await execute(doc, variables);
|
|
2492
|
-
const mutationName = (0,
|
|
2333
|
+
const mutationName = (0, import_data7.toCreateMutationName)(tableName, table);
|
|
2493
2334
|
const createdRow = result[mutationName]?.[singularName] ?? null;
|
|
2494
2335
|
return createdRow;
|
|
2495
2336
|
},
|
|
2496
2337
|
async updateRow(ctx, id, patch, execute, options = {}) {
|
|
2497
2338
|
const { table, allTables, tableName } = ctx;
|
|
2498
|
-
const doc = (0,
|
|
2339
|
+
const doc = (0, import_data7.buildPostGraphileUpdate)(table, allTables, {
|
|
2499
2340
|
...options,
|
|
2500
2341
|
fieldSelection: options.fieldSelection || "display"
|
|
2501
2342
|
});
|
|
2502
|
-
const patchFieldName = (0,
|
|
2503
|
-
const sanitizedPatch = (0,
|
|
2504
|
-
if (Object.keys(sanitizedPatch).length === 0)
|
|
2505
|
-
|
|
2506
|
-
}
|
|
2343
|
+
const patchFieldName = (0, import_data7.toPatchFieldName)(tableName, table);
|
|
2344
|
+
const sanitizedPatch = (0, import_data7.prepareUpdateInput)(patch);
|
|
2345
|
+
if (Object.keys(sanitizedPatch).length === 0) return null;
|
|
2346
|
+
const normalizedPatch = normalizeMutationEnums(ctx, sanitizedPatch, execute);
|
|
2507
2347
|
const variables = {
|
|
2508
2348
|
input: {
|
|
2509
|
-
id,
|
|
2510
|
-
[patchFieldName]:
|
|
2349
|
+
...typeof id === "object" ? id : { id },
|
|
2350
|
+
[patchFieldName]: normalizedPatch
|
|
2511
2351
|
}
|
|
2512
2352
|
};
|
|
2513
2353
|
const result = await execute(doc, variables);
|
|
2514
|
-
const mutationName = (0,
|
|
2515
|
-
const singularName = (0,
|
|
2354
|
+
const mutationName = (0, import_data7.toUpdateMutationName)(tableName, table);
|
|
2355
|
+
const singularName = (0, import_data7.toCamelCaseSingular)(tableName, table);
|
|
2516
2356
|
const updatedRow = result[mutationName]?.[singularName] ?? null;
|
|
2517
2357
|
return updatedRow;
|
|
2518
2358
|
},
|
|
2519
2359
|
async deleteRow(ctx, id, execute, options = {}) {
|
|
2520
2360
|
const { table, allTables } = ctx;
|
|
2521
|
-
const doc = (0,
|
|
2361
|
+
const doc = (0, import_data7.buildPostGraphileDelete)(table, allTables, options);
|
|
2522
2362
|
const variables = {
|
|
2523
2363
|
input: typeof id === "object" ? id : { id }
|
|
2524
2364
|
};
|
|
@@ -2554,18 +2394,18 @@ function useSheetsMeta(options = {}) {
|
|
|
2554
2394
|
}
|
|
2555
2395
|
|
|
2556
2396
|
// src/hooks/use-sheets-upload.ts
|
|
2557
|
-
var
|
|
2397
|
+
var import_data12 = require("@constructive-io/data");
|
|
2558
2398
|
|
|
2559
2399
|
// src/context/sheets-execute.ts
|
|
2560
2400
|
var import_graphql2 = require("graphql");
|
|
2561
|
-
var
|
|
2401
|
+
var import_data9 = require("@constructive-io/data");
|
|
2562
2402
|
|
|
2563
2403
|
// src/context/sheets-upload-presigned.ts
|
|
2564
2404
|
var import_graphql = require("graphql");
|
|
2565
|
-
var
|
|
2405
|
+
var import_data8 = require("@constructive-io/data");
|
|
2566
2406
|
async function sha256HexFromBuffer(buffer) {
|
|
2567
2407
|
if (!globalThis.crypto?.subtle) {
|
|
2568
|
-
throw
|
|
2408
|
+
throw import_data8.createError.badRequest("Web Crypto (crypto.subtle) is unavailable; cannot hash file for upload.");
|
|
2569
2409
|
}
|
|
2570
2410
|
const digest = await crypto.subtle.digest("SHA-256", buffer);
|
|
2571
2411
|
const bytes = new Uint8Array(digest);
|
|
@@ -2583,7 +2423,7 @@ function discoverUploadCapability(endpoint, execute) {
|
|
|
2583
2423
|
const data = await execute((0, import_graphql.getIntrospectionQuery)());
|
|
2584
2424
|
const schema = data?.__schema;
|
|
2585
2425
|
if (!schema) {
|
|
2586
|
-
throw
|
|
2426
|
+
throw import_data8.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2587
2427
|
}
|
|
2588
2428
|
return resolveUploadCapability(schema);
|
|
2589
2429
|
})();
|
|
@@ -2641,7 +2481,7 @@ function resolveUploadCapability(schema) {
|
|
|
2641
2481
|
}
|
|
2642
2482
|
}
|
|
2643
2483
|
if (!upload) {
|
|
2644
|
-
throw
|
|
2484
|
+
throw import_data8.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2645
2485
|
}
|
|
2646
2486
|
const downloadById = resolveDownloadByIdField(schema, typeByName, queryType, upload.uploadFieldName);
|
|
2647
2487
|
return {
|
|
@@ -2678,7 +2518,7 @@ function resolveDownloadByIdField(schema, typeByName, queryType, uploadFieldName
|
|
|
2678
2518
|
const fileTypeName = fileTypesWithDownloadUrl.has(preferred) ? preferred : [...fileTypesWithDownloadUrl][0];
|
|
2679
2519
|
return { fileByIdField: "node", fileByIdArgName: "nodeId", fileTypeName };
|
|
2680
2520
|
}
|
|
2681
|
-
throw
|
|
2521
|
+
throw import_data8.createError.badRequest("Uploads are not enabled for this endpoint.");
|
|
2682
2522
|
}
|
|
2683
2523
|
function resolveConnectionDownloadField(typeByName, queryType, fileTypesWithDownloadUrl, uploadFieldName) {
|
|
2684
2524
|
const EQUALITY_OPERATORS = ["equalTo", "eq"];
|
|
@@ -2762,7 +2602,7 @@ async function callUploadOp(execute, cap, input) {
|
|
|
2762
2602
|
});
|
|
2763
2603
|
const payload = data?.[cap.uploadFieldName];
|
|
2764
2604
|
if (!payload) {
|
|
2765
|
-
throw
|
|
2605
|
+
throw import_data8.createError.badRequest("Upload failed: no payload returned from upload mutation.");
|
|
2766
2606
|
}
|
|
2767
2607
|
return payload;
|
|
2768
2608
|
}
|
|
@@ -2780,11 +2620,11 @@ async function presignedPut(url, buffer, contentType, onProgress) {
|
|
|
2780
2620
|
body: buffer
|
|
2781
2621
|
});
|
|
2782
2622
|
} catch (error) {
|
|
2783
|
-
throw
|
|
2623
|
+
throw import_data8.createError.network(error instanceof Error ? error : void 0);
|
|
2784
2624
|
}
|
|
2785
2625
|
if (!response.ok) {
|
|
2786
2626
|
const body = await response.text().catch(() => "");
|
|
2787
|
-
throw
|
|
2627
|
+
throw import_data8.createError.badRequest(`Upload failed: ${response.status} ${response.statusText}${body ? ` \u2014 ${body}` : ""}`);
|
|
2788
2628
|
}
|
|
2789
2629
|
onProgress?.({ loaded: total, total, percentage: 100 });
|
|
2790
2630
|
}
|
|
@@ -2807,16 +2647,16 @@ function putWithXHR(url, buffer, contentType, total, onProgress) {
|
|
|
2807
2647
|
onProgress({ loaded: total, total, percentage: 100 });
|
|
2808
2648
|
resolve();
|
|
2809
2649
|
} else {
|
|
2810
|
-
reject(
|
|
2650
|
+
reject(import_data8.createError.badRequest(`Upload failed: ${xhr.status} ${xhr.statusText}${xhr.responseText ? ` \u2014 ${xhr.responseText}` : ""}`));
|
|
2811
2651
|
}
|
|
2812
2652
|
});
|
|
2813
|
-
xhr.addEventListener("error", () => reject(
|
|
2653
|
+
xhr.addEventListener("error", () => reject(import_data8.createError.network()));
|
|
2814
2654
|
xhr.send(buffer);
|
|
2815
2655
|
});
|
|
2816
2656
|
}
|
|
2817
2657
|
function toGlobalId(typeName, id) {
|
|
2818
2658
|
if (typeof btoa !== "function") {
|
|
2819
|
-
throw
|
|
2659
|
+
throw import_data8.createError.badRequest("Cannot encode the file node id: btoa is unavailable in this environment.");
|
|
2820
2660
|
}
|
|
2821
2661
|
return btoa(JSON.stringify([typeName, id]));
|
|
2822
2662
|
}
|
|
@@ -2836,7 +2676,7 @@ async function fetchDownloadUrl(execute, cap, fileId) {
|
|
|
2836
2676
|
const node = data2?.[cap.fileByIdField];
|
|
2837
2677
|
const url2 = node?.downloadUrl;
|
|
2838
2678
|
if (!url2) {
|
|
2839
|
-
throw
|
|
2679
|
+
throw import_data8.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2840
2680
|
}
|
|
2841
2681
|
return url2;
|
|
2842
2682
|
}
|
|
@@ -2862,7 +2702,7 @@ async function fetchDownloadUrl(execute, cap, fileId) {
|
|
|
2862
2702
|
const conn = data2?.[cap.fileByIdField];
|
|
2863
2703
|
const url2 = conn?.[nodesField]?.[0]?.downloadUrl;
|
|
2864
2704
|
if (!url2) {
|
|
2865
|
-
throw
|
|
2705
|
+
throw import_data8.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2866
2706
|
}
|
|
2867
2707
|
return url2;
|
|
2868
2708
|
}
|
|
@@ -2879,13 +2719,13 @@ async function fetchDownloadUrl(execute, cap, fileId) {
|
|
|
2879
2719
|
const file = data?.[cap.fileByIdField];
|
|
2880
2720
|
const url = file?.downloadUrl;
|
|
2881
2721
|
if (!url) {
|
|
2882
|
-
throw
|
|
2722
|
+
throw import_data8.createError.badRequest("Upload succeeded but no downloadUrl was returned for the file.");
|
|
2883
2723
|
}
|
|
2884
2724
|
return url;
|
|
2885
2725
|
}
|
|
2886
2726
|
|
|
2887
2727
|
// src/context/sheets-execute.ts
|
|
2888
|
-
var
|
|
2728
|
+
var import_data10 = require("@constructive-io/data");
|
|
2889
2729
|
function documentToString(document2) {
|
|
2890
2730
|
if (typeof document2 === "string") return document2;
|
|
2891
2731
|
if (document2 instanceof String) return document2.toString();
|
|
@@ -2893,7 +2733,7 @@ function documentToString(document2) {
|
|
|
2893
2733
|
return (0, import_graphql2.print)(document2);
|
|
2894
2734
|
}
|
|
2895
2735
|
if (document2 === null || document2 === void 0) {
|
|
2896
|
-
throw
|
|
2736
|
+
throw import_data9.createError.badRequest("Invalid GraphQL document: null or undefined");
|
|
2897
2737
|
}
|
|
2898
2738
|
return String(document2);
|
|
2899
2739
|
}
|
|
@@ -2908,18 +2748,18 @@ function parseGraphQLResponse(response, onAuthError) {
|
|
|
2908
2748
|
const message = error.message || "GraphQL query failed";
|
|
2909
2749
|
if (code === "UNAUTHENTICATED" || hasAuthMessage(message)) {
|
|
2910
2750
|
onAuthError?.();
|
|
2911
|
-
return
|
|
2751
|
+
return import_data9.createError.unauthorized("Authentication required. Please log in again.");
|
|
2912
2752
|
}
|
|
2913
2753
|
if (code === "FORBIDDEN") {
|
|
2914
|
-
return
|
|
2754
|
+
return import_data9.createError.forbidden("You do not have permission to perform this action.");
|
|
2915
2755
|
}
|
|
2916
|
-
return
|
|
2756
|
+
return import_data9.createError.graphql(message, code);
|
|
2917
2757
|
}
|
|
2918
2758
|
function createSheetsExecute(config, getToken) {
|
|
2919
2759
|
return async (document2, variables) => {
|
|
2920
2760
|
const url = config.endpoint;
|
|
2921
2761
|
if (!url) {
|
|
2922
|
-
throw
|
|
2762
|
+
throw import_data9.createError.badRequest("No GraphQL endpoint configured.");
|
|
2923
2763
|
}
|
|
2924
2764
|
const token = getToken();
|
|
2925
2765
|
const headers = {
|
|
@@ -2940,29 +2780,29 @@ function createSheetsExecute(config, getToken) {
|
|
|
2940
2780
|
})
|
|
2941
2781
|
});
|
|
2942
2782
|
} catch (error) {
|
|
2943
|
-
throw
|
|
2783
|
+
throw import_data9.createError.network(error instanceof Error ? error : void 0);
|
|
2944
2784
|
}
|
|
2945
2785
|
if (!response.ok) {
|
|
2946
2786
|
const { status, statusText } = response;
|
|
2947
2787
|
if (status === 401) {
|
|
2948
2788
|
config.onAuthError?.();
|
|
2949
|
-
throw
|
|
2789
|
+
throw import_data9.createError.unauthorized("Authentication required. Please log in again.");
|
|
2950
2790
|
}
|
|
2951
2791
|
if (status === 403) {
|
|
2952
|
-
throw
|
|
2792
|
+
throw import_data9.createError.forbidden("You do not have permission to perform this action.");
|
|
2953
2793
|
}
|
|
2954
2794
|
if (status === 404) {
|
|
2955
|
-
throw
|
|
2795
|
+
throw import_data9.createError.notFound("The requested endpoint does not exist.");
|
|
2956
2796
|
}
|
|
2957
2797
|
try {
|
|
2958
2798
|
const body = await response.json();
|
|
2959
2799
|
if (body.errors?.length) {
|
|
2960
|
-
throw
|
|
2800
|
+
throw import_data9.createError.graphql(body.errors[0].message || `Request failed: ${status}`, body.errors[0].extensions?.code);
|
|
2961
2801
|
}
|
|
2962
2802
|
} catch (e) {
|
|
2963
|
-
if (e instanceof
|
|
2803
|
+
if (e instanceof import_data9.DataError) throw e;
|
|
2964
2804
|
}
|
|
2965
|
-
throw
|
|
2805
|
+
throw import_data9.createError.badRequest(`Request failed: ${status} ${statusText}`);
|
|
2966
2806
|
}
|
|
2967
2807
|
const result = await response.json();
|
|
2968
2808
|
const graphqlError = parseGraphQLResponse(result, config.onAuthError);
|
|
@@ -2976,7 +2816,7 @@ function createSheetsUpload(config, getToken) {
|
|
|
2976
2816
|
const execute = config.execute ?? createSheetsExecute(config, getToken);
|
|
2977
2817
|
return async (file, _path, options) => {
|
|
2978
2818
|
if (!config.endpoint) {
|
|
2979
|
-
throw
|
|
2819
|
+
throw import_data9.createError.badRequest("No GraphQL endpoint configured.");
|
|
2980
2820
|
}
|
|
2981
2821
|
const bucketKey = config.upload?.bucketKey ?? "public";
|
|
2982
2822
|
const contentType = file.type || "application/octet-stream";
|
|
@@ -2992,7 +2832,7 @@ function createSheetsUpload(config, getToken) {
|
|
|
2992
2832
|
});
|
|
2993
2833
|
if (!payload.deduplicated) {
|
|
2994
2834
|
if (!payload.uploadUrl) {
|
|
2995
|
-
throw
|
|
2835
|
+
throw import_data9.createError.badRequest("Upload failed: server returned no uploadUrl for a non-deduplicated file.");
|
|
2996
2836
|
}
|
|
2997
2837
|
await presignedPut(payload.uploadUrl, buffer, contentType, options?.onProgress);
|
|
2998
2838
|
} else {
|
|
@@ -3013,10 +2853,10 @@ function createSheetsUpload(config, getToken) {
|
|
|
3013
2853
|
// src/hooks/use-sheets-upload.ts
|
|
3014
2854
|
function resolveUploadNaming(tableName, table) {
|
|
3015
2855
|
return {
|
|
3016
|
-
mutationName: (0,
|
|
3017
|
-
singularName: (0,
|
|
3018
|
-
patchFieldName: (0,
|
|
3019
|
-
updateInputTypeName: (0,
|
|
2856
|
+
mutationName: (0, import_data12.toUpdateMutationName)(tableName, table),
|
|
2857
|
+
singularName: (0, import_data12.toCamelCaseSingular)(tableName, table),
|
|
2858
|
+
patchFieldName: (0, import_data12.toPatchFieldName)(tableName, table),
|
|
2859
|
+
updateInputTypeName: (0, import_data12.toUpdateInputTypeName)(tableName)
|
|
3020
2860
|
};
|
|
3021
2861
|
}
|
|
3022
2862
|
function resolveTransport(endpoint, getToken, options) {
|
|
@@ -3093,7 +2933,7 @@ function useSheetsFieldUpload(tableName, fieldName, recordId, options = {}) {
|
|
|
3093
2933
|
const table = (0, import_react12.useMemo)(() => {
|
|
3094
2934
|
if (!meta?._meta?.tables) return null;
|
|
3095
2935
|
const candidate = meta._meta.tables.find((item) => item?.name === tableName);
|
|
3096
|
-
return candidate ? (0,
|
|
2936
|
+
return candidate ? (0, import_data11.cleanTable)(candidate) : null;
|
|
3097
2937
|
}, [meta, tableName]);
|
|
3098
2938
|
const resolvedNaming = (0, import_react12.useMemo)(() => resolveUploadNaming(tableName, table), [tableName, table]);
|
|
3099
2939
|
const getToken = (0, import_react12.useMemo)(() => {
|
|
@@ -3449,14 +3289,17 @@ var ImageEditor = ({
|
|
|
3449
3289
|
import_toast.toast.info({ message: "Creating row..." });
|
|
3450
3290
|
setUploadState("submitting-draft");
|
|
3451
3291
|
const result = await onSubmitDraft();
|
|
3452
|
-
|
|
3453
|
-
|
|
3292
|
+
const createdId = result.createdRow?.id;
|
|
3293
|
+
if (typeof createdId !== "string" && typeof createdId !== "number") {
|
|
3294
|
+
throw new Error("Image uploads require a scalar id primary key.");
|
|
3295
|
+
}
|
|
3296
|
+
committedRecordIdRef.current = createdId;
|
|
3454
3297
|
import_toast.toast.info({ message: `Uploading ${noun}...` });
|
|
3455
3298
|
setUploadState("uploading");
|
|
3456
3299
|
const uploadResult = await executeFieldUpload(
|
|
3457
3300
|
tableName,
|
|
3458
3301
|
fieldName,
|
|
3459
|
-
|
|
3302
|
+
createdId,
|
|
3460
3303
|
selectedFile,
|
|
3461
3304
|
config.endpoint,
|
|
3462
3305
|
getToken,
|
|
@@ -4285,7 +4128,7 @@ function parseValue(text) {
|
|
|
4285
4128
|
if (trimmed === "") return null;
|
|
4286
4129
|
return Number(trimmed);
|
|
4287
4130
|
}
|
|
4288
|
-
function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
4131
|
+
function NumberEditorDom({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
4289
4132
|
const [text, setText] = (0, import_react21.useState)(() => initialText != null ? initialText : seedText(value));
|
|
4290
4133
|
const escapedRef = (0, import_react21.useRef)(false);
|
|
4291
4134
|
const parsed = parseValue(text);
|
|
@@ -4322,6 +4165,7 @@ function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
|
4322
4165
|
/* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
|
|
4323
4166
|
"input",
|
|
4324
4167
|
{
|
|
4168
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
4325
4169
|
value: text,
|
|
4326
4170
|
onChange: (e) => setText(e.target.value),
|
|
4327
4171
|
onKeyDown: handleKeyDown,
|
|
@@ -4347,9 +4191,9 @@ var import_react_query5 = require("@tanstack/react-query");
|
|
|
4347
4191
|
// src/hooks/use-sheets-table-cursor.ts
|
|
4348
4192
|
var import_react22 = require("react");
|
|
4349
4193
|
var import_react_query4 = require("@tanstack/react-query");
|
|
4350
|
-
var import_data12 = require("@constructive-io/data");
|
|
4351
4194
|
var import_data13 = require("@constructive-io/data");
|
|
4352
4195
|
var import_data14 = require("@constructive-io/data");
|
|
4196
|
+
var import_data15 = require("@constructive-io/data");
|
|
4353
4197
|
function useSheetsTableCursor(tableName, options = {}) {
|
|
4354
4198
|
const queryClient = (0, import_react_query4.useQueryClient)();
|
|
4355
4199
|
const { execute, scopeKey } = useSheetsContext();
|
|
@@ -4357,7 +4201,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4357
4201
|
const adapter = useSheetsAdapter();
|
|
4358
4202
|
const tables = (0, import_react22.useMemo)(() => {
|
|
4359
4203
|
if (!meta?._meta?.tables) return [];
|
|
4360
|
-
return meta._meta.tables.filter((candidate) => candidate != null).map((metaTable) => (0,
|
|
4204
|
+
return meta._meta.tables.filter((candidate) => candidate != null).map((metaTable) => (0, import_data13.cleanTable)(metaTable));
|
|
4361
4205
|
}, [meta]);
|
|
4362
4206
|
const table = (0, import_react22.useMemo)(
|
|
4363
4207
|
() => tables.find((candidate) => candidate.name === tableName) ?? null,
|
|
@@ -4389,7 +4233,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4389
4233
|
queryKey: sheetsQueryKeys.cursorTable(scopeKey, tableName, stableOptions),
|
|
4390
4234
|
queryFn: async ({ pageParam }) => {
|
|
4391
4235
|
if (!table) {
|
|
4392
|
-
throw
|
|
4236
|
+
throw import_data14.createError.notFound(`Table '${tableName}' not found`);
|
|
4393
4237
|
}
|
|
4394
4238
|
const cursor = pageParam;
|
|
4395
4239
|
const variableOptions = {
|
|
@@ -4412,7 +4256,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
4412
4256
|
const validatedOrderByEnum = new Set(variables.orderBy ?? []);
|
|
4413
4257
|
const availableOrderByFields = new Set(table.fields.map((field) => field.name));
|
|
4414
4258
|
const validatedOrderBy = orderBy?.filter(
|
|
4415
|
-
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0,
|
|
4259
|
+
({ field, direction }) => availableOrderByFields.has(field) && validatedOrderByEnum.has((0, import_data15.toOrderByEnumValue)(field, direction))
|
|
4416
4260
|
);
|
|
4417
4261
|
const res = await adapter.listRows(
|
|
4418
4262
|
{ table, allTables: tables, tableName },
|
|
@@ -5074,7 +4918,7 @@ var import_button11 = require("@constructive-io/ui/button");
|
|
|
5074
4918
|
init_overlay_presets();
|
|
5075
4919
|
init_cn();
|
|
5076
4920
|
var import_jsx_runtime23 = require("react/jsx-runtime");
|
|
5077
|
-
function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
4921
|
+
function TextEditor({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
5078
4922
|
const [text, setText] = (0, import_react26.useState)(() => initialText != null ? initialText : String(value ?? ""));
|
|
5079
4923
|
const escapedRef = (0, import_react26.useRef)(false);
|
|
5080
4924
|
function handleKeyDown(e) {
|
|
@@ -5100,6 +4944,7 @@ function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
|
5100
4944
|
/* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
|
|
5101
4945
|
"input",
|
|
5102
4946
|
{
|
|
4947
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
5103
4948
|
value: text,
|
|
5104
4949
|
onChange: (e) => setText(e.target.value),
|
|
5105
4950
|
onKeyDown: handleKeyDown,
|