@constructive-io/sheets 0.4.1 → 0.6.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 +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
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
3
|
createSheetsExecute,
|
|
4
|
-
createSheetsUpload
|
|
5
|
-
|
|
4
|
+
createSheetsUpload,
|
|
5
|
+
sheetsQueryKeys
|
|
6
|
+
} from "./chunk-ZETPUEXH.js";
|
|
6
7
|
import {
|
|
7
8
|
useSheetsContext,
|
|
8
9
|
useSheetsStore,
|
|
9
10
|
useSheetsStoreApi
|
|
10
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KOZAW264.js";
|
|
11
12
|
import {
|
|
12
13
|
BOOLEAN_TYPES,
|
|
13
14
|
DATE_TIME_TYPES,
|
|
@@ -26,28 +27,73 @@ import {
|
|
|
26
27
|
sheetsLogger
|
|
27
28
|
} from "./chunk-X7DHTSOX.js";
|
|
28
29
|
|
|
29
|
-
// src/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
// src/row-identity.ts
|
|
31
|
+
import {
|
|
32
|
+
assessTableWriteCapability,
|
|
33
|
+
resolveRowIdentity,
|
|
34
|
+
rowIdentityToPrimaryKey,
|
|
35
|
+
serializeRowIdentity
|
|
36
|
+
} from "@constructive-io/data";
|
|
37
|
+
function isLegacyScalarId(primaryKey) {
|
|
38
|
+
const entries = Object.entries(primaryKey);
|
|
39
|
+
return entries.length === 1 && entries[0][0] === "id" && (typeof entries[0][1] === "string" || typeof entries[0][1] === "number");
|
|
40
|
+
}
|
|
41
|
+
function resolveSheetsRowIdentity(table, row) {
|
|
42
|
+
const resolution = resolveRowIdentity(table, row);
|
|
43
|
+
if (resolution.status === "read-only") {
|
|
44
|
+
return { status: "unavailable", reason: "no-primary-key" };
|
|
45
|
+
}
|
|
46
|
+
if (resolution.status === "invalid-row") {
|
|
47
|
+
return { status: "unavailable", reason: "invalid-row" };
|
|
48
|
+
}
|
|
49
|
+
const primaryKey = rowIdentityToPrimaryKey(resolution.identity);
|
|
50
|
+
return {
|
|
51
|
+
status: "identified",
|
|
52
|
+
identifier: isLegacyScalarId(primaryKey) ? primaryKey.id : primaryKey,
|
|
53
|
+
primaryKey,
|
|
54
|
+
key: serializeRowIdentity(resolution.identity)
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function resolveSheetsIdentifier(table, identifier) {
|
|
58
|
+
const row = typeof identifier === "object" && identifier !== null ? identifier : { id: identifier };
|
|
59
|
+
return resolveSheetsRowIdentity(table, row);
|
|
60
|
+
}
|
|
61
|
+
function sheetsIdentifierToWhere(table, identifier) {
|
|
62
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
63
|
+
if (resolution.status !== "identified") return null;
|
|
64
|
+
return Object.fromEntries(
|
|
65
|
+
Object.entries(resolution.primaryKey).map(([field, value]) => [field, { equalTo: value }])
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
function sheetsIdentifierCacheKey(table, identifier) {
|
|
69
|
+
const resolution = resolveSheetsIdentifier(table, identifier);
|
|
70
|
+
if (resolution.status !== "identified") return null;
|
|
71
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
72
|
+
}
|
|
73
|
+
function sheetsRowKey(table, row, index) {
|
|
74
|
+
const resolution = resolveSheetsRowIdentity(table, row);
|
|
75
|
+
if (resolution.status === "identified") {
|
|
76
|
+
return typeof resolution.identifier === "object" ? resolution.key : String(resolution.identifier);
|
|
77
|
+
}
|
|
78
|
+
return `${table.schemaName ?? ""}:${table.name}:row:${index}`;
|
|
79
|
+
}
|
|
80
|
+
function getSheetsWriteCapability(table) {
|
|
81
|
+
return table ? assessTableWriteCapability(table) : null;
|
|
82
|
+
}
|
|
83
|
+
function canRunSheetsMutation(capability, operation) {
|
|
84
|
+
if (!capability || capability.status !== "mutable") return false;
|
|
85
|
+
return capability.operations[operation];
|
|
86
|
+
}
|
|
87
|
+
function assertSheetsMutationAllowed(table, operation) {
|
|
88
|
+
const capability = assessTableWriteCapability(table);
|
|
89
|
+
if (capability.status === "read-only") {
|
|
90
|
+
throw new Error(`Table '${table.name}' is read-only because it has no primary key.`);
|
|
91
|
+
}
|
|
92
|
+
if (!capability.operations[operation]) {
|
|
93
|
+
const article = operation === "update" ? "an" : "a";
|
|
94
|
+
throw new Error(`Table '${table.name}' does not expose ${article} ${operation} mutation.`);
|
|
95
|
+
}
|
|
34
96
|
}
|
|
35
|
-
var sheetsQueryKeys = {
|
|
36
|
-
root: ["sheets"],
|
|
37
|
-
scope: (scope) => ["sheets", scope],
|
|
38
|
-
meta: (scope) => [...sheetsQueryKeys.scope(scope), "meta"],
|
|
39
|
-
typeFields: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "type-fields", typeName],
|
|
40
|
-
enumValues: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "enum-values", typeName],
|
|
41
|
-
relations: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "relations", tableName],
|
|
42
|
-
table: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "table", tableName],
|
|
43
|
-
tableRows: (scope, tableName, options) => [...sheetsQueryKeys.table(scope, tableName), "rows", options],
|
|
44
|
-
tableRow: (scope, tableName, id) => [...sheetsQueryKeys.table(scope, tableName), "row", id],
|
|
45
|
-
tableCount: (scope, tableName, where) => [...sheetsQueryKeys.table(scope, tableName), "count", where],
|
|
46
|
-
infiniteTable: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "infinite-table", tableName],
|
|
47
|
-
infiniteTablePage: (scope, tableName, pageIndex, options) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "page", pageIndex, options],
|
|
48
|
-
infiniteTableTotalCount: (scope, tableName, where) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "totalCount", where],
|
|
49
|
-
cursorTable: (scope, tableName, options) => [...sheetsQueryKeys.scope(scope), "cursor-table", tableName, options]
|
|
50
|
-
};
|
|
51
97
|
|
|
52
98
|
// src/hooks/use-sheets-table.ts
|
|
53
99
|
import { useMemo } from "react";
|
|
@@ -58,321 +104,92 @@ import { useQuery } from "@tanstack/react-query";
|
|
|
58
104
|
|
|
59
105
|
// src/adapter/postgraphile-adapter.ts
|
|
60
106
|
import {
|
|
107
|
+
META_CONTRACT_INTROSPECTION_DOCUMENT,
|
|
108
|
+
META_DOCUMENT,
|
|
109
|
+
SCHEMA_INTROSPECTION_QUERY,
|
|
110
|
+
analyzeSchemaIntrospectionCompatibility,
|
|
111
|
+
assertMetaContract,
|
|
112
|
+
assertMetaQuery,
|
|
61
113
|
buildPostGraphileCreate,
|
|
62
114
|
buildPostGraphileDelete,
|
|
63
115
|
buildPostGraphileUpdate,
|
|
64
116
|
buildSelect,
|
|
117
|
+
createError,
|
|
118
|
+
normalizeSchemaEnumInputValues,
|
|
65
119
|
prepareCreateInput,
|
|
66
120
|
prepareUpdateInput,
|
|
67
121
|
toCamelCasePlural,
|
|
68
122
|
toCamelCaseSingular,
|
|
69
123
|
toCreateMutationName,
|
|
70
124
|
toPatchFieldName,
|
|
71
|
-
toUpdateMutationName
|
|
72
|
-
TypedDocumentString
|
|
125
|
+
toUpdateMutationName
|
|
73
126
|
} from "@constructive-io/data";
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
name
|
|
119
|
-
type {
|
|
120
|
-
gqlType
|
|
121
|
-
isArray
|
|
122
|
-
pgType
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
constraints {
|
|
127
|
-
primaryKey {
|
|
128
|
-
name
|
|
129
|
-
fields {
|
|
130
|
-
name
|
|
131
|
-
type {
|
|
132
|
-
gqlType
|
|
133
|
-
isArray
|
|
134
|
-
pgType
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
unique {
|
|
139
|
-
name
|
|
140
|
-
fields {
|
|
141
|
-
name
|
|
142
|
-
type {
|
|
143
|
-
gqlType
|
|
144
|
-
isArray
|
|
145
|
-
pgType
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
foreignKey {
|
|
150
|
-
name
|
|
151
|
-
fields {
|
|
152
|
-
name
|
|
153
|
-
type {
|
|
154
|
-
gqlType
|
|
155
|
-
isArray
|
|
156
|
-
pgType
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
refFields {
|
|
160
|
-
name
|
|
161
|
-
type {
|
|
162
|
-
gqlType
|
|
163
|
-
isArray
|
|
164
|
-
pgType
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
refTable {
|
|
168
|
-
name
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
foreignKeyConstraints {
|
|
173
|
-
name
|
|
174
|
-
fields {
|
|
175
|
-
name
|
|
176
|
-
type {
|
|
177
|
-
gqlType
|
|
178
|
-
isArray
|
|
179
|
-
pgType
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
refFields {
|
|
183
|
-
name
|
|
184
|
-
type {
|
|
185
|
-
gqlType
|
|
186
|
-
isArray
|
|
187
|
-
pgType
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
refTable {
|
|
191
|
-
name
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
primaryKeyConstraints {
|
|
195
|
-
name
|
|
196
|
-
fields {
|
|
197
|
-
name
|
|
198
|
-
type {
|
|
199
|
-
gqlType
|
|
200
|
-
isArray
|
|
201
|
-
pgType
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
uniqueConstraints {
|
|
206
|
-
name
|
|
207
|
-
fields {
|
|
208
|
-
name
|
|
209
|
-
type {
|
|
210
|
-
gqlType
|
|
211
|
-
isArray
|
|
212
|
-
pgType
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
relations {
|
|
217
|
-
belongsTo {
|
|
218
|
-
fieldName
|
|
219
|
-
isUnique
|
|
220
|
-
keys {
|
|
221
|
-
name
|
|
222
|
-
type {
|
|
223
|
-
gqlType
|
|
224
|
-
isArray
|
|
225
|
-
pgType
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
references {
|
|
229
|
-
name
|
|
230
|
-
}
|
|
231
|
-
type
|
|
232
|
-
}
|
|
233
|
-
has {
|
|
234
|
-
fieldName
|
|
235
|
-
isUnique
|
|
236
|
-
keys {
|
|
237
|
-
name
|
|
238
|
-
type {
|
|
239
|
-
gqlType
|
|
240
|
-
isArray
|
|
241
|
-
pgType
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
referencedBy {
|
|
245
|
-
name
|
|
246
|
-
}
|
|
247
|
-
type
|
|
248
|
-
}
|
|
249
|
-
hasOne {
|
|
250
|
-
fieldName
|
|
251
|
-
isUnique
|
|
252
|
-
keys {
|
|
253
|
-
name
|
|
254
|
-
type {
|
|
255
|
-
gqlType
|
|
256
|
-
isArray
|
|
257
|
-
pgType
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
referencedBy {
|
|
261
|
-
name
|
|
262
|
-
}
|
|
263
|
-
type
|
|
264
|
-
}
|
|
265
|
-
hasMany {
|
|
266
|
-
fieldName
|
|
267
|
-
isUnique
|
|
268
|
-
keys {
|
|
269
|
-
name
|
|
270
|
-
type {
|
|
271
|
-
gqlType
|
|
272
|
-
isArray
|
|
273
|
-
pgType
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
referencedBy {
|
|
277
|
-
name
|
|
278
|
-
}
|
|
279
|
-
type
|
|
280
|
-
}
|
|
281
|
-
manyToMany {
|
|
282
|
-
fieldName
|
|
283
|
-
junctionLeftConstraint {
|
|
284
|
-
name
|
|
285
|
-
fields {
|
|
286
|
-
name
|
|
287
|
-
type {
|
|
288
|
-
gqlType
|
|
289
|
-
isArray
|
|
290
|
-
pgType
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
refFields {
|
|
294
|
-
name
|
|
295
|
-
type {
|
|
296
|
-
gqlType
|
|
297
|
-
isArray
|
|
298
|
-
pgType
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
refTable {
|
|
302
|
-
name
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
junctionLeftKeyAttributes {
|
|
306
|
-
name
|
|
307
|
-
type {
|
|
308
|
-
gqlType
|
|
309
|
-
isArray
|
|
310
|
-
pgType
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
junctionRightConstraint {
|
|
314
|
-
name
|
|
315
|
-
fields {
|
|
316
|
-
name
|
|
317
|
-
type {
|
|
318
|
-
gqlType
|
|
319
|
-
isArray
|
|
320
|
-
pgType
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
refFields {
|
|
324
|
-
name
|
|
325
|
-
type {
|
|
326
|
-
gqlType
|
|
327
|
-
isArray
|
|
328
|
-
pgType
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
refTable {
|
|
332
|
-
name
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
junctionRightKeyAttributes {
|
|
336
|
-
name
|
|
337
|
-
type {
|
|
338
|
-
gqlType
|
|
339
|
-
isArray
|
|
340
|
-
pgType
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
junctionTable {
|
|
344
|
-
name
|
|
345
|
-
}
|
|
346
|
-
leftKeyAttributes {
|
|
347
|
-
name
|
|
348
|
-
type {
|
|
349
|
-
gqlType
|
|
350
|
-
isArray
|
|
351
|
-
pgType
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
rightKeyAttributes {
|
|
355
|
-
name
|
|
356
|
-
type {
|
|
357
|
-
gqlType
|
|
358
|
-
isArray
|
|
359
|
-
pgType
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
rightTable {
|
|
363
|
-
name
|
|
364
|
-
}
|
|
365
|
-
type
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
`);
|
|
127
|
+
var compatibilityChecks = /* @__PURE__ */ new WeakMap();
|
|
128
|
+
var enumMappings = /* @__PURE__ */ new WeakMap();
|
|
129
|
+
async function ensureCurrentMetaContract(execute) {
|
|
130
|
+
const cached = compatibilityChecks.get(execute);
|
|
131
|
+
if (cached) return cached;
|
|
132
|
+
const check = execute(META_CONTRACT_INTROSPECTION_DOCUMENT).then(
|
|
133
|
+
(result) => {
|
|
134
|
+
assertMetaContract(result);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
compatibilityChecks.set(execute, check);
|
|
138
|
+
try {
|
|
139
|
+
await check;
|
|
140
|
+
} catch (error) {
|
|
141
|
+
if (compatibilityChecks.get(execute) === check) compatibilityChecks.delete(execute);
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function hasDeclaredEnums(meta) {
|
|
146
|
+
return Boolean(meta._meta?.tables?.some(
|
|
147
|
+
(table) => table?.fields?.some((field) => Boolean(field?.enumValues?.name))
|
|
148
|
+
));
|
|
149
|
+
}
|
|
150
|
+
function schemaCompatibilityError(missingPaths) {
|
|
151
|
+
const detail = missingPaths.length > 0 ? ` Missing: ${missingPaths.join(", ")}.` : "";
|
|
152
|
+
return createError.badRequest(
|
|
153
|
+
`The GraphQL schema does not match the enum values declared by Constructive _meta.${detail}`,
|
|
154
|
+
"SCHEMA_INTROSPECTION_INCOMPATIBLE"
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
function normalizeMutationEnums(ctx, input, execute) {
|
|
158
|
+
const hasEnumInput = ctx.table.fields.some(
|
|
159
|
+
(field) => Boolean(field.enumValues?.length) && Object.prototype.hasOwnProperty.call(input, field.name)
|
|
160
|
+
);
|
|
161
|
+
if (!hasEnumInput) return input;
|
|
162
|
+
const mappings = enumMappings.get(execute);
|
|
163
|
+
if (!mappings) {
|
|
164
|
+
throw createError.badRequest(
|
|
165
|
+
"Enum schema mappings are unavailable. Load table metadata before mutating enum fields.",
|
|
166
|
+
"ENUM_MAPPING_UNAVAILABLE"
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
return normalizeSchemaEnumInputValues(input, ctx.table, mappings);
|
|
170
|
+
}
|
|
372
171
|
function createPostGraphileAdapter() {
|
|
373
172
|
return {
|
|
374
173
|
async fetchMeta(execute) {
|
|
375
|
-
|
|
174
|
+
await ensureCurrentMetaContract(execute);
|
|
175
|
+
const meta = await execute(META_DOCUMENT);
|
|
176
|
+
assertMetaQuery(meta);
|
|
177
|
+
if (!hasDeclaredEnums(meta)) {
|
|
178
|
+
enumMappings.set(execute, []);
|
|
179
|
+
return meta;
|
|
180
|
+
}
|
|
181
|
+
try {
|
|
182
|
+
const introspection = await execute(SCHEMA_INTROSPECTION_QUERY);
|
|
183
|
+
const analysis = analyzeSchemaIntrospectionCompatibility(introspection, meta);
|
|
184
|
+
if (analysis.status !== "compatible") {
|
|
185
|
+
throw schemaCompatibilityError(analysis.missingPaths);
|
|
186
|
+
}
|
|
187
|
+
enumMappings.set(execute, analysis.enumMappings);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
enumMappings.delete(execute);
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
return meta;
|
|
376
193
|
},
|
|
377
194
|
async listRows(ctx, query, execute) {
|
|
378
195
|
const { table, allTables, tableName } = ctx;
|
|
@@ -396,7 +213,6 @@ function createPostGraphileAdapter() {
|
|
|
396
213
|
const directData = connection || [];
|
|
397
214
|
return {
|
|
398
215
|
rows: transformRelationData(directData, table),
|
|
399
|
-
// Non-Relay direct-array response: page length only, not a full filtered count.
|
|
400
216
|
totalCount: directData.length
|
|
401
217
|
};
|
|
402
218
|
},
|
|
@@ -407,7 +223,11 @@ function createPostGraphileAdapter() {
|
|
|
407
223
|
fieldSelection: options.fieldSelection || "display"
|
|
408
224
|
});
|
|
409
225
|
const singularName = toCamelCaseSingular(tableName, table);
|
|
410
|
-
const sanitizedData =
|
|
226
|
+
const sanitizedData = normalizeMutationEnums(
|
|
227
|
+
ctx,
|
|
228
|
+
prepareCreateInput(data),
|
|
229
|
+
execute
|
|
230
|
+
);
|
|
411
231
|
const variables = {
|
|
412
232
|
input: {
|
|
413
233
|
[singularName]: sanitizedData
|
|
@@ -426,13 +246,12 @@ function createPostGraphileAdapter() {
|
|
|
426
246
|
});
|
|
427
247
|
const patchFieldName = toPatchFieldName(tableName, table);
|
|
428
248
|
const sanitizedPatch = prepareUpdateInput(patch);
|
|
429
|
-
if (Object.keys(sanitizedPatch).length === 0)
|
|
430
|
-
|
|
431
|
-
}
|
|
249
|
+
if (Object.keys(sanitizedPatch).length === 0) return null;
|
|
250
|
+
const normalizedPatch = normalizeMutationEnums(ctx, sanitizedPatch, execute);
|
|
432
251
|
const variables = {
|
|
433
252
|
input: {
|
|
434
|
-
id,
|
|
435
|
-
[patchFieldName]:
|
|
253
|
+
...typeof id === "object" ? id : { id },
|
|
254
|
+
[patchFieldName]: normalizedPatch
|
|
436
255
|
}
|
|
437
256
|
};
|
|
438
257
|
const result = await execute(doc, variables);
|
|
@@ -480,7 +299,7 @@ function useSheetsMeta(options = {}) {
|
|
|
480
299
|
|
|
481
300
|
// src/hooks/use-sheets-table.ts
|
|
482
301
|
import { cleanTable } from "@constructive-io/data";
|
|
483
|
-
import { createError } from "@constructive-io/data";
|
|
302
|
+
import { createError as createError2 } from "@constructive-io/data";
|
|
484
303
|
import {
|
|
485
304
|
buildSelect as buildSelect2,
|
|
486
305
|
toCamelCasePlural as toCamelCasePlural2,
|
|
@@ -490,8 +309,8 @@ import {
|
|
|
490
309
|
|
|
491
310
|
// src/hooks/relation-field-resolution.ts
|
|
492
311
|
import { toCamelCase, toPascalCase, pluralize, singularize } from "inflekt";
|
|
493
|
-
import { TypedDocumentString
|
|
494
|
-
var TypeFieldsDoc = new
|
|
312
|
+
import { TypedDocumentString } from "@constructive-io/data";
|
|
313
|
+
var TypeFieldsDoc = new TypedDocumentString(`
|
|
495
314
|
query TypeFields($typeName: String!) {
|
|
496
315
|
__type(name: $typeName) {
|
|
497
316
|
fields {
|
|
@@ -659,8 +478,8 @@ async function getTypeFieldSet(table, scopeKey, queryClient, execute) {
|
|
|
659
478
|
}
|
|
660
479
|
|
|
661
480
|
// src/hooks/orderby-enum-resolution.ts
|
|
662
|
-
import { TypedDocumentString as
|
|
663
|
-
var EnumValuesDoc = new
|
|
481
|
+
import { TypedDocumentString as TypedDocumentString2 } from "@constructive-io/data";
|
|
482
|
+
var EnumValuesDoc = new TypedDocumentString2(`
|
|
664
483
|
query EnumValues($typeName: String!) {
|
|
665
484
|
__type(name: $typeName) {
|
|
666
485
|
enumValues {
|
|
@@ -695,13 +514,6 @@ async function validateOrderByVariables(variables, table, scopeKey, queryClient,
|
|
|
695
514
|
}
|
|
696
515
|
|
|
697
516
|
// src/hooks/use-sheets-table.ts
|
|
698
|
-
function extractRowId(row) {
|
|
699
|
-
if (!row || typeof row !== "object") {
|
|
700
|
-
return null;
|
|
701
|
-
}
|
|
702
|
-
const candidate = row.id;
|
|
703
|
-
return typeof candidate === "string" || typeof candidate === "number" ? candidate : null;
|
|
704
|
-
}
|
|
705
517
|
function transformRelationData(data, table) {
|
|
706
518
|
if (!data) return [];
|
|
707
519
|
if (!Array.isArray(data)) return data;
|
|
@@ -765,14 +577,33 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
765
577
|
const { execute, scopeKey } = useSheetsContext();
|
|
766
578
|
const { data: meta } = useSheetsMeta();
|
|
767
579
|
const adapter = useSheetsAdapter();
|
|
768
|
-
const
|
|
580
|
+
const metaTables = useMemo(() => {
|
|
769
581
|
if (!meta?._meta?.tables) return [];
|
|
770
|
-
return meta._meta.tables.filter((candidate) => candidate != null)
|
|
582
|
+
return meta._meta.tables.filter((candidate) => candidate != null);
|
|
771
583
|
}, [meta]);
|
|
584
|
+
const tables = useMemo(() => metaTables.map(cleanTable), [metaTables]);
|
|
772
585
|
const table = useMemo(
|
|
773
586
|
() => tables.find((candidate) => candidate.name === tableName) ?? null,
|
|
774
587
|
[tables, tableName]
|
|
775
588
|
);
|
|
589
|
+
const tableMeta = useMemo(
|
|
590
|
+
() => metaTables.find((candidate) => candidate.name === tableName) ?? null,
|
|
591
|
+
[metaTables, tableName]
|
|
592
|
+
);
|
|
593
|
+
const resolveIdentifier = (identifier) => {
|
|
594
|
+
if (!tableMeta) throw createError2.notFound(`Table '${tableName}' not found`);
|
|
595
|
+
const resolution = resolveSheetsIdentifier(tableMeta, identifier);
|
|
596
|
+
if (resolution.status !== "identified") {
|
|
597
|
+
throw createError2.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
598
|
+
}
|
|
599
|
+
return resolution.identifier;
|
|
600
|
+
};
|
|
601
|
+
const rowCacheKey = (row) => {
|
|
602
|
+
if (!tableMeta || !row) return null;
|
|
603
|
+
const resolution = resolveSheetsRowIdentity(tableMeta, row);
|
|
604
|
+
if (resolution.status !== "identified") return null;
|
|
605
|
+
return typeof resolution.identifier === "object" ? resolution.key : resolution.identifier;
|
|
606
|
+
};
|
|
776
607
|
const { enabled = true, select: fieldSelection, mutationOptions = {}, ...queryOptions } = options;
|
|
777
608
|
const finalQueryOptions = {
|
|
778
609
|
...queryOptions,
|
|
@@ -787,7 +618,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
787
618
|
queryKey: sheetsTableQueryKeys.tableRows(scopeKey, tableName, finalQueryOptions),
|
|
788
619
|
queryFn: async () => {
|
|
789
620
|
if (!table) {
|
|
790
|
-
throw
|
|
621
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
791
622
|
}
|
|
792
623
|
const variables = transformToPostGraphileVariables(table, finalQueryOptions);
|
|
793
624
|
const [relationFieldMap] = await Promise.all([
|
|
@@ -829,9 +660,10 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
829
660
|
const createMutation = useMutation({
|
|
830
661
|
mutationKey: sheetsTableMutationKeys.create(scopeKey, tableName),
|
|
831
662
|
mutationFn: async (data2) => {
|
|
832
|
-
if (!table) {
|
|
833
|
-
throw
|
|
663
|
+
if (!table || !tableMeta) {
|
|
664
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
834
665
|
}
|
|
666
|
+
assertSheetsMutationAllowed(tableMeta, "create");
|
|
835
667
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
836
668
|
const createdRow = await adapter.createRow({ table, allTables, tableName }, data2, execute, {
|
|
837
669
|
...mutationOptions,
|
|
@@ -842,20 +674,22 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
842
674
|
onSuccess: ({ createdRow }) => {
|
|
843
675
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
844
676
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
845
|
-
const
|
|
846
|
-
if (
|
|
847
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
677
|
+
const createdRowKey = rowCacheKey(createdRow);
|
|
678
|
+
if (createdRowKey !== null) {
|
|
679
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, createdRowKey), createdRow);
|
|
848
680
|
}
|
|
849
681
|
}
|
|
850
682
|
});
|
|
851
683
|
const updateMutation = useMutation({
|
|
852
684
|
mutationKey: sheetsTableMutationKeys.update(scopeKey, tableName),
|
|
853
685
|
mutationFn: async ({ id, patch }) => {
|
|
854
|
-
if (!table) {
|
|
855
|
-
throw
|
|
686
|
+
if (!table || !tableMeta) {
|
|
687
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
856
688
|
}
|
|
689
|
+
assertSheetsMutationAllowed(tableMeta, "update");
|
|
690
|
+
const mutationIdentifier = resolveIdentifier(id);
|
|
857
691
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
858
|
-
const updatedRow = await adapter.updateRow({ table, allTables, tableName },
|
|
692
|
+
const updatedRow = await adapter.updateRow({ table, allTables, tableName }, mutationIdentifier, patch, execute, {
|
|
859
693
|
...mutationOptions,
|
|
860
694
|
fieldSelection: mutationOptions.fieldSelection || fieldSelection || "display"
|
|
861
695
|
});
|
|
@@ -870,6 +704,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
870
704
|
onMutate: async ({ id, patch }) => {
|
|
871
705
|
const tablePrefix = sheetsTableQueryKeys.table(scopeKey, tableName);
|
|
872
706
|
await queryClient.cancelQueries({ queryKey: tablePrefix });
|
|
707
|
+
const targetKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, id) : null;
|
|
873
708
|
const isRowsKey = (key) => key[key.length - 2] === "rows";
|
|
874
709
|
const previousRows = queryClient.getQueriesData({ queryKey: tablePrefix }).filter(([key]) => isRowsKey(key));
|
|
875
710
|
for (const [key] of previousRows) {
|
|
@@ -877,7 +712,7 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
877
712
|
if (!old) return old;
|
|
878
713
|
let changed = false;
|
|
879
714
|
const rows = old.rows.map((row) => {
|
|
880
|
-
if (
|
|
715
|
+
if (targetKey !== null && rowCacheKey(row) === targetKey) {
|
|
881
716
|
changed = true;
|
|
882
717
|
return { ...row, ...patch };
|
|
883
718
|
}
|
|
@@ -893,42 +728,49 @@ function useSheetsTable(tableName, options = {}) {
|
|
|
893
728
|
},
|
|
894
729
|
onSuccess: ({ updatedRow }) => {
|
|
895
730
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
896
|
-
const
|
|
897
|
-
if (
|
|
898
|
-
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
731
|
+
const updatedRowKey = rowCacheKey(updatedRow);
|
|
732
|
+
if (updatedRowKey !== null) {
|
|
733
|
+
queryClient.setQueryData(sheetsTableQueryKeys.tableRow(scopeKey, tableName, updatedRowKey), updatedRow);
|
|
899
734
|
}
|
|
900
735
|
}
|
|
901
736
|
});
|
|
902
737
|
const deleteMutation = useMutation({
|
|
903
738
|
mutationKey: sheetsTableMutationKeys.delete(scopeKey, tableName),
|
|
904
739
|
mutationFn: async (idOrPk) => {
|
|
905
|
-
if (!table) {
|
|
906
|
-
throw
|
|
740
|
+
if (!table || !tableMeta) {
|
|
741
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
907
742
|
}
|
|
743
|
+
assertSheetsMutationAllowed(tableMeta, "delete");
|
|
744
|
+
const mutationIdentifier = resolveIdentifier(idOrPk);
|
|
908
745
|
const allTables = meta?._meta?.tables ? meta._meta.tables.filter((t) => t != null).map(cleanTable) : [];
|
|
909
|
-
await adapter.deleteRow({ table, allTables, tableName },
|
|
746
|
+
await adapter.deleteRow({ table, allTables, tableName }, mutationIdentifier, execute, mutationOptions);
|
|
910
747
|
return { deletedId: idOrPk, __rawResult: {} };
|
|
911
748
|
},
|
|
912
749
|
onSuccess: ({ deletedId }) => {
|
|
913
750
|
queryClient.invalidateQueries({ queryKey: sheetsTableQueryKeys.table(scopeKey, tableName) });
|
|
914
751
|
queryClient.invalidateQueries({ queryKey: sheetsQueryKeys.infiniteTable(scopeKey, tableName) });
|
|
915
|
-
|
|
752
|
+
const deletedRowKey = tableMeta ? sheetsIdentifierCacheKey(tableMeta, deletedId) : null;
|
|
753
|
+
if (deletedRowKey !== null) {
|
|
916
754
|
queryClient.removeQueries({
|
|
917
|
-
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName,
|
|
755
|
+
queryKey: sheetsTableQueryKeys.tableRow(scopeKey, tableName, deletedRowKey)
|
|
918
756
|
});
|
|
919
757
|
}
|
|
920
758
|
}
|
|
921
759
|
});
|
|
922
760
|
const findOne = async (id) => {
|
|
923
|
-
if (!table) {
|
|
924
|
-
throw
|
|
761
|
+
if (!table || !tableMeta) {
|
|
762
|
+
throw createError2.notFound(`Table '${tableName}' not found`);
|
|
763
|
+
}
|
|
764
|
+
const where = sheetsIdentifierToWhere(tableMeta, id);
|
|
765
|
+
if (!where) {
|
|
766
|
+
throw createError2.badRequest(`Cannot resolve a primary-key identity for table '${tableName}'.`);
|
|
925
767
|
}
|
|
926
768
|
const doc = buildSelect2(table, tables, {
|
|
927
|
-
where
|
|
769
|
+
where,
|
|
928
770
|
limit: 1
|
|
929
771
|
});
|
|
930
772
|
const variables = transformToPostGraphileVariables(table, {
|
|
931
|
-
where
|
|
773
|
+
where,
|
|
932
774
|
limit: 1
|
|
933
775
|
});
|
|
934
776
|
const result = await execute(doc, variables);
|
|
@@ -1702,7 +1544,7 @@ import { useInfiniteQuery, useQueryClient as useQueryClient3 } from "@tanstack/r
|
|
|
1702
1544
|
import {
|
|
1703
1545
|
cleanTable as cleanTable3
|
|
1704
1546
|
} from "@constructive-io/data";
|
|
1705
|
-
import { createError as
|
|
1547
|
+
import { createError as createError3 } from "@constructive-io/data";
|
|
1706
1548
|
import { toOrderByEnumValue as toOrderByEnumValue2 } from "@constructive-io/data";
|
|
1707
1549
|
function useSheetsTableCursor(tableName, options = {}) {
|
|
1708
1550
|
const queryClient = useQueryClient3();
|
|
@@ -1743,7 +1585,7 @@ function useSheetsTableCursor(tableName, options = {}) {
|
|
|
1743
1585
|
queryKey: sheetsQueryKeys.cursorTable(scopeKey, tableName, stableOptions),
|
|
1744
1586
|
queryFn: async ({ pageParam }) => {
|
|
1745
1587
|
if (!table) {
|
|
1746
|
-
throw
|
|
1588
|
+
throw createError3.notFound(`Table '${tableName}' not found`);
|
|
1747
1589
|
}
|
|
1748
1590
|
const cursor = pageParam;
|
|
1749
1591
|
const variableOptions = {
|
|
@@ -1996,7 +1838,7 @@ function ArrayEditorDom({ value, onCommit, onCancel }) {
|
|
|
1996
1838
|
// src/grid-dom/editors/date-editor.tsx
|
|
1997
1839
|
import { lazy, Suspense } from "react";
|
|
1998
1840
|
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1999
|
-
var DateEditor = lazy(() => import("./date-editor-
|
|
1841
|
+
var DateEditor = lazy(() => import("./date-editor-QT47WY5T.js").then((m) => ({ default: m.DateEditor })));
|
|
2000
1842
|
function DateEditorDom({ value, cell, onCommit, onCancel }) {
|
|
2001
1843
|
const cellType = cell.meta?.cellType;
|
|
2002
1844
|
const dateType = cellType && DATE_TIME_TYPES.has(cellType) ? cellType : void 0;
|
|
@@ -2700,14 +2542,17 @@ var ImageEditor = ({
|
|
|
2700
2542
|
toast.info({ message: "Creating row..." });
|
|
2701
2543
|
setUploadState("submitting-draft");
|
|
2702
2544
|
const result = await onSubmitDraft();
|
|
2703
|
-
|
|
2704
|
-
|
|
2545
|
+
const createdId = result.createdRow?.id;
|
|
2546
|
+
if (typeof createdId !== "string" && typeof createdId !== "number") {
|
|
2547
|
+
throw new Error("Image uploads require a scalar id primary key.");
|
|
2548
|
+
}
|
|
2549
|
+
committedRecordIdRef.current = createdId;
|
|
2705
2550
|
toast.info({ message: `Uploading ${noun}...` });
|
|
2706
2551
|
setUploadState("uploading");
|
|
2707
2552
|
const uploadResult = await executeFieldUpload(
|
|
2708
2553
|
tableName,
|
|
2709
2554
|
fieldName,
|
|
2710
|
-
|
|
2555
|
+
createdId,
|
|
2711
2556
|
selectedFile,
|
|
2712
2557
|
config.endpoint,
|
|
2713
2558
|
getToken,
|
|
@@ -3528,7 +3373,7 @@ function parseValue(text) {
|
|
|
3528
3373
|
if (trimmed === "") return null;
|
|
3529
3374
|
return Number(trimmed);
|
|
3530
3375
|
}
|
|
3531
|
-
function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
3376
|
+
function NumberEditorDom({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
3532
3377
|
const [text, setText] = useState9(() => initialText != null ? initialText : seedText(value));
|
|
3533
3378
|
const escapedRef = useRef8(false);
|
|
3534
3379
|
const parsed = parseValue(text);
|
|
@@ -3565,6 +3410,7 @@ function NumberEditorDom({ value, initialText, onCommit, onCancel }) {
|
|
|
3565
3410
|
/* @__PURE__ */ jsx16(
|
|
3566
3411
|
"input",
|
|
3567
3412
|
{
|
|
3413
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
3568
3414
|
value: text,
|
|
3569
3415
|
onChange: (e) => setText(e.target.value),
|
|
3570
3416
|
onKeyDown: handleKeyDown,
|
|
@@ -4191,7 +4037,7 @@ function RelationEditorDom({
|
|
|
4191
4037
|
import { useRef as useRef11, useState as useState12 } from "react";
|
|
4192
4038
|
import { Button as Button9 } from "@constructive-io/ui/button";
|
|
4193
4039
|
import { jsx as jsx20, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
4194
|
-
function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
4040
|
+
function TextEditor({ value, initialText, colKey, fieldMeta, onCommit, onCancel }) {
|
|
4195
4041
|
const [text, setText] = useState12(() => initialText != null ? initialText : String(value ?? ""));
|
|
4196
4042
|
const escapedRef = useRef11(false);
|
|
4197
4043
|
function handleKeyDown(e) {
|
|
@@ -4217,6 +4063,7 @@ function TextEditor({ value, initialText, onCommit, onCancel }) {
|
|
|
4217
4063
|
/* @__PURE__ */ jsx20(
|
|
4218
4064
|
"input",
|
|
4219
4065
|
{
|
|
4066
|
+
"aria-label": `Edit ${fieldMeta?.name ?? colKey}`,
|
|
4220
4067
|
value: text,
|
|
4221
4068
|
onChange: (e) => setText(e.target.value),
|
|
4222
4069
|
onKeyDown: handleKeyDown,
|
|
@@ -4507,10 +4354,15 @@ function resolveNativeEditor(typeKey, consumer) {
|
|
|
4507
4354
|
}
|
|
4508
4355
|
|
|
4509
4356
|
export {
|
|
4510
|
-
isSheetsScopeKey,
|
|
4511
|
-
sheetsQueryKeys,
|
|
4512
4357
|
resolveRelationFieldMap,
|
|
4513
4358
|
validateOrderByVariables,
|
|
4359
|
+
resolveSheetsRowIdentity,
|
|
4360
|
+
resolveSheetsIdentifier,
|
|
4361
|
+
sheetsIdentifierToWhere,
|
|
4362
|
+
sheetsIdentifierCacheKey,
|
|
4363
|
+
sheetsRowKey,
|
|
4364
|
+
getSheetsWriteCapability,
|
|
4365
|
+
canRunSheetsMutation,
|
|
4514
4366
|
sheetsTableQueryKeys,
|
|
4515
4367
|
transformToPostGraphileVariables,
|
|
4516
4368
|
useSheetsTable,
|
|
@@ -4530,4 +4382,4 @@ export {
|
|
|
4530
4382
|
DOM_EDITOR_REGISTRY,
|
|
4531
4383
|
resolveNativeEditor
|
|
4532
4384
|
};
|
|
4533
|
-
//# sourceMappingURL=chunk-
|
|
4385
|
+
//# sourceMappingURL=chunk-LR64FLWO.js.map
|