@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
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { DocumentNode } from 'graphql';
|
|
4
|
-
import { TypedDocumentString,
|
|
5
|
-
import {
|
|
4
|
+
import { TypedDocumentString, FieldSelection, CleanTable, MetaQuery, MutationOptions } from '@constructive-io/data';
|
|
5
|
+
import { b as CellType, S as SheetsCell, C as CellCreationMetadata, c as CellCategory, E as EditorProps } from './grid-cell-types-C3ARj148.cjs';
|
|
6
6
|
|
|
7
7
|
type ExecutableDocument = TypedDocumentString<any, any> | DocumentNode | string | unknown;
|
|
8
8
|
type SheetsExecuteFn = <T = unknown>(document: ExecutableDocument, variables?: Record<string, unknown>) => Promise<T>;
|
|
@@ -165,7 +165,7 @@ interface AdapterListResult<T = Record<string, unknown>> {
|
|
|
165
165
|
pageInfo?: AdapterPageInfo;
|
|
166
166
|
}
|
|
167
167
|
interface SheetsBackendAdapter {
|
|
168
|
-
/** Introspect the schema. Default adapter runs the
|
|
168
|
+
/** Introspect the schema. Default adapter validates and runs the July 2026 `_meta` contract. */
|
|
169
169
|
fetchMeta(execute: SheetsExecuteFn): Promise<MetaQuery>;
|
|
170
170
|
/** Read a page of rows, flattening relation connections into arrays. */
|
|
171
171
|
listRows<T = Record<string, unknown>>(ctx: AdapterTableContext, query: AdapterListQuery, execute: SheetsExecuteFn): Promise<AdapterListResult<T>>;
|
|
@@ -180,6 +180,12 @@ interface SheetsBackendAdapter {
|
|
|
180
180
|
interface SheetsAuthEmbedded {
|
|
181
181
|
mode: 'embedded';
|
|
182
182
|
getToken: () => string | null;
|
|
183
|
+
/**
|
|
184
|
+
* Stable, non-secret identity used to isolate cached data between users.
|
|
185
|
+
* Hosts should return the authenticated user/session id, never the token.
|
|
186
|
+
* When omitted, the provider uses an opaque key that changes with the token.
|
|
187
|
+
*/
|
|
188
|
+
getIdentityKey?: () => string | null;
|
|
183
189
|
}
|
|
184
190
|
interface SheetsAuthStandalone {
|
|
185
191
|
mode: 'standalone';
|
|
@@ -230,8 +236,9 @@ interface SheetsContextValue {
|
|
|
230
236
|
interface SheetsScopeKey {
|
|
231
237
|
databaseId: string | null;
|
|
232
238
|
endpoint: string;
|
|
239
|
+
identityKey: string | null;
|
|
233
240
|
}
|
|
234
|
-
declare const SheetsContext:
|
|
241
|
+
declare const SheetsContext: react.Context<SheetsContextValue | null>;
|
|
235
242
|
declare function useSheetsContext(): SheetsContextValue;
|
|
236
243
|
|
|
237
|
-
export { type
|
|
244
|
+
export { type AdapterListQuery as A, type CellProps as C, type SheetsExecuteFn as S, type SheetsUploadFn as a, type SheetsConfig as b, type CellTypeDefinition as c, type SheetsCellRenderContext as d, type CellTypeMatchInput as e, type SheetsScopeKey as f, type SheetsBackendAdapter as g, type AdapterListResult as h, type AdapterPageInfo as i, type AdapterTableContext as j, type CellColumnDescriptor as k, type CellTypePlugin as l, type SheetsAuthEmbedded as m, type SheetsAuthStandalone as n, SheetsContext as o, type SheetsContextValue as p, type SheetsLogger as q, createSheetsExecute as r, createSheetsUpload as s, defineCellType as t, useSheetsContext as u };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import { QueryClient } from '@tanstack/react-query';
|
|
3
3
|
import { DocumentNode } from 'graphql';
|
|
4
|
-
import { TypedDocumentString,
|
|
5
|
-
import {
|
|
4
|
+
import { TypedDocumentString, FieldSelection, CleanTable, MetaQuery, MutationOptions } from '@constructive-io/data';
|
|
5
|
+
import { b as CellType, S as SheetsCell, C as CellCreationMetadata, c as CellCategory, E as EditorProps } from './grid-cell-types-C3ARj148.js';
|
|
6
6
|
|
|
7
7
|
type ExecutableDocument = TypedDocumentString<any, any> | DocumentNode | string | unknown;
|
|
8
8
|
type SheetsExecuteFn = <T = unknown>(document: ExecutableDocument, variables?: Record<string, unknown>) => Promise<T>;
|
|
@@ -165,7 +165,7 @@ interface AdapterListResult<T = Record<string, unknown>> {
|
|
|
165
165
|
pageInfo?: AdapterPageInfo;
|
|
166
166
|
}
|
|
167
167
|
interface SheetsBackendAdapter {
|
|
168
|
-
/** Introspect the schema. Default adapter runs the
|
|
168
|
+
/** Introspect the schema. Default adapter validates and runs the July 2026 `_meta` contract. */
|
|
169
169
|
fetchMeta(execute: SheetsExecuteFn): Promise<MetaQuery>;
|
|
170
170
|
/** Read a page of rows, flattening relation connections into arrays. */
|
|
171
171
|
listRows<T = Record<string, unknown>>(ctx: AdapterTableContext, query: AdapterListQuery, execute: SheetsExecuteFn): Promise<AdapterListResult<T>>;
|
|
@@ -180,6 +180,12 @@ interface SheetsBackendAdapter {
|
|
|
180
180
|
interface SheetsAuthEmbedded {
|
|
181
181
|
mode: 'embedded';
|
|
182
182
|
getToken: () => string | null;
|
|
183
|
+
/**
|
|
184
|
+
* Stable, non-secret identity used to isolate cached data between users.
|
|
185
|
+
* Hosts should return the authenticated user/session id, never the token.
|
|
186
|
+
* When omitted, the provider uses an opaque key that changes with the token.
|
|
187
|
+
*/
|
|
188
|
+
getIdentityKey?: () => string | null;
|
|
183
189
|
}
|
|
184
190
|
interface SheetsAuthStandalone {
|
|
185
191
|
mode: 'standalone';
|
|
@@ -230,8 +236,9 @@ interface SheetsContextValue {
|
|
|
230
236
|
interface SheetsScopeKey {
|
|
231
237
|
databaseId: string | null;
|
|
232
238
|
endpoint: string;
|
|
239
|
+
identityKey: string | null;
|
|
233
240
|
}
|
|
234
|
-
declare const SheetsContext:
|
|
241
|
+
declare const SheetsContext: react.Context<SheetsContextValue | null>;
|
|
235
242
|
declare function useSheetsContext(): SheetsContextValue;
|
|
236
243
|
|
|
237
|
-
export { type
|
|
244
|
+
export { type AdapterListQuery as A, type CellProps as C, type SheetsExecuteFn as S, type SheetsUploadFn as a, type SheetsConfig as b, type CellTypeDefinition as c, type SheetsCellRenderContext as d, type CellTypeMatchInput as e, type SheetsScopeKey as f, type SheetsBackendAdapter as g, type AdapterListResult as h, type AdapterPageInfo as i, type AdapterTableContext as j, type CellColumnDescriptor as k, type CellTypePlugin as l, type SheetsAuthEmbedded as m, type SheetsAuthStandalone as n, SheetsContext as o, type SheetsContextValue as p, type SheetsLogger as q, createSheetsExecute as r, createSheetsUpload as s, defineCellType as t, useSheetsContext as u };
|
package/dist/styles.css
ADDED
package/dist/testing.cjs
CHANGED
|
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var testing_exports = {};
|
|
23
23
|
__export(testing_exports, {
|
|
24
24
|
MockSheetsProvider: () => MockSheetsProvider,
|
|
25
|
+
createMetaContractFixture: () => createMetaContractFixture,
|
|
25
26
|
createMockExecute: () => createMockExecute,
|
|
26
27
|
usersFixture: () => usersFixture
|
|
27
28
|
});
|
|
@@ -31,11 +32,12 @@ module.exports = __toCommonJS(testing_exports);
|
|
|
31
32
|
var import_react4 = require("react");
|
|
32
33
|
var import_graphql3 = require("graphql");
|
|
33
34
|
var import_react_query2 = require("@tanstack/react-query");
|
|
34
|
-
var
|
|
35
|
+
var import_data7 = require("@constructive-io/data");
|
|
35
36
|
|
|
36
37
|
// src/context/sheets-provider.tsx
|
|
37
38
|
var import_react3 = require("react");
|
|
38
39
|
var import_react_query = require("@tanstack/react-query");
|
|
40
|
+
var import_zustand2 = require("zustand");
|
|
39
41
|
|
|
40
42
|
// src/context/sheets-context.ts
|
|
41
43
|
var import_react = require("react");
|
|
@@ -879,8 +881,8 @@ function toCleanTables(meta) {
|
|
|
879
881
|
const tables = meta?._meta?.tables ?? [];
|
|
880
882
|
return tables.filter((table) => table != null).map((table) => (0, import_data5.cleanTable)(table));
|
|
881
883
|
}
|
|
882
|
-
function firstFieldName(
|
|
883
|
-
return
|
|
884
|
+
function firstFieldName(fields2) {
|
|
885
|
+
return fields2[0]?.name;
|
|
884
886
|
}
|
|
885
887
|
function findForeignKeyInRelatedTable(currentTableName, relatedTableName, allTables, rawMetaTables) {
|
|
886
888
|
const relatedTable = allTables.find((t) => t.name === relatedTableName);
|
|
@@ -1044,8 +1046,9 @@ function createSheetsStore() {
|
|
|
1044
1046
|
isAuthenticated: false,
|
|
1045
1047
|
accessToken: null,
|
|
1046
1048
|
expiresAt: null,
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
+
identityKey: null,
|
|
1050
|
+
setAuthenticated: (token, expiresAt, identityKey = null) => set({ isAuthenticated: true, accessToken: token, expiresAt, identityKey }),
|
|
1051
|
+
setUnauthenticated: () => set({ isAuthenticated: false, accessToken: null, expiresAt: null, identityKey: null })
|
|
1049
1052
|
}));
|
|
1050
1053
|
}
|
|
1051
1054
|
var SheetsStoreContext = (0, import_react2.createContext)(null);
|
|
@@ -1071,6 +1074,7 @@ function getStoredToken(databaseId) {
|
|
|
1071
1074
|
if (!raw) return null;
|
|
1072
1075
|
const parsed = JSON.parse(raw);
|
|
1073
1076
|
if (!parsed.accessToken || !parsed.expiresAt) return null;
|
|
1077
|
+
if (parsed.identityKey != null && typeof parsed.identityKey !== "string") return null;
|
|
1074
1078
|
return parsed;
|
|
1075
1079
|
} catch {
|
|
1076
1080
|
return null;
|
|
@@ -1095,13 +1099,35 @@ function setSheetsLocale(locale) {
|
|
|
1095
1099
|
active2 = locale || DEFAULT_LOCALE;
|
|
1096
1100
|
}
|
|
1097
1101
|
|
|
1102
|
+
// src/hooks/query-keys.ts
|
|
1103
|
+
var sheetsQueryKeys = {
|
|
1104
|
+
root: ["sheets"],
|
|
1105
|
+
scope: (scope) => ["sheets", scope],
|
|
1106
|
+
meta: (scope) => [...sheetsQueryKeys.scope(scope), "meta"],
|
|
1107
|
+
typeFields: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "type-fields", typeName],
|
|
1108
|
+
enumValues: (scope, typeName) => [...sheetsQueryKeys.scope(scope), "enum-values", typeName],
|
|
1109
|
+
relations: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "relations", tableName],
|
|
1110
|
+
table: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "table", tableName],
|
|
1111
|
+
tableRows: (scope, tableName, options) => [...sheetsQueryKeys.table(scope, tableName), "rows", options],
|
|
1112
|
+
tableRow: (scope, tableName, id) => [...sheetsQueryKeys.table(scope, tableName), "row", id],
|
|
1113
|
+
tableCount: (scope, tableName, where) => [...sheetsQueryKeys.table(scope, tableName), "count", where],
|
|
1114
|
+
infiniteTable: (scope, tableName) => [...sheetsQueryKeys.scope(scope), "infinite-table", tableName],
|
|
1115
|
+
infiniteTablePage: (scope, tableName, pageIndex, options) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "page", pageIndex, options],
|
|
1116
|
+
infiniteTableTotalCount: (scope, tableName, where) => [...sheetsQueryKeys.infiniteTable(scope, tableName), "totalCount", where],
|
|
1117
|
+
cursorTable: (scope, tableName, options) => [...sheetsQueryKeys.scope(scope), "cursor-table", tableName, options]
|
|
1118
|
+
};
|
|
1119
|
+
|
|
1098
1120
|
// src/context/sheets-provider.tsx
|
|
1099
1121
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
1100
1122
|
function SheetsProvider({ config, children }) {
|
|
1123
|
+
const providerInstanceId = (0, import_react3.useId)();
|
|
1101
1124
|
const storeRef = (0, import_react3.useRef)(null);
|
|
1102
1125
|
if (!storeRef.current) {
|
|
1103
1126
|
storeRef.current = createSheetsStore();
|
|
1104
1127
|
}
|
|
1128
|
+
const store = storeRef.current;
|
|
1129
|
+
const standaloneIdentityKey = (0, import_zustand2.useStore)(store, (state) => state.identityKey);
|
|
1130
|
+
const standaloneAccessToken = (0, import_zustand2.useStore)(store, (state) => state.accessToken);
|
|
1105
1131
|
setSheetsLogger(config.logger);
|
|
1106
1132
|
setSheetsLocale(config.locale);
|
|
1107
1133
|
(0, import_react3.useEffect)(() => {
|
|
@@ -1109,24 +1135,24 @@ function SheetsProvider({ config, children }) {
|
|
|
1109
1135
|
setSheetsLocale(config.locale);
|
|
1110
1136
|
}, [config.logger, config.locale]);
|
|
1111
1137
|
(0, import_react3.useEffect)(() => {
|
|
1112
|
-
const
|
|
1113
|
-
if (!
|
|
1138
|
+
const store2 = storeRef.current?.getState();
|
|
1139
|
+
if (!store2) return;
|
|
1114
1140
|
if (config.auth.mode !== "standalone") {
|
|
1115
|
-
|
|
1141
|
+
store2.setUnauthenticated();
|
|
1116
1142
|
return;
|
|
1117
1143
|
}
|
|
1118
1144
|
const databaseId = config.databaseId || "default";
|
|
1119
1145
|
const stored = getStoredToken(databaseId);
|
|
1120
1146
|
if (!stored) {
|
|
1121
|
-
|
|
1147
|
+
store2.setUnauthenticated();
|
|
1122
1148
|
return;
|
|
1123
1149
|
}
|
|
1124
1150
|
const expiresAt = new Date(stored.expiresAt);
|
|
1125
1151
|
if (expiresAt > /* @__PURE__ */ new Date()) {
|
|
1126
|
-
|
|
1152
|
+
store2.setAuthenticated(stored.accessToken, stored.expiresAt, stored.identityKey ?? null);
|
|
1127
1153
|
return;
|
|
1128
1154
|
}
|
|
1129
|
-
|
|
1155
|
+
store2.setUnauthenticated();
|
|
1130
1156
|
}, [config.auth.mode, config.databaseId]);
|
|
1131
1157
|
const internalQueryClient = (0, import_react3.useMemo)(
|
|
1132
1158
|
() => new import_react_query.QueryClient({
|
|
@@ -1145,8 +1171,8 @@ function SheetsProvider({ config, children }) {
|
|
|
1145
1171
|
if (config.auth.mode === "embedded") {
|
|
1146
1172
|
return config.auth.getToken;
|
|
1147
1173
|
}
|
|
1148
|
-
return () =>
|
|
1149
|
-
}, [config.auth]);
|
|
1174
|
+
return () => store.getState().accessToken ?? null;
|
|
1175
|
+
}, [config.auth, store]);
|
|
1150
1176
|
const execute = (0, import_react3.useMemo)(() => {
|
|
1151
1177
|
if (config.execute) return config.execute;
|
|
1152
1178
|
return createSheetsExecute(config, getToken);
|
|
@@ -1155,18 +1181,47 @@ function SheetsProvider({ config, children }) {
|
|
|
1155
1181
|
if (config.executeUpload) return config.executeUpload;
|
|
1156
1182
|
return createSheetsUpload(config, getToken);
|
|
1157
1183
|
}, [config, getToken]);
|
|
1184
|
+
const configuredIdentityKey = config.auth.mode === "embedded" ? config.auth.getIdentityKey?.() ?? null : standaloneIdentityKey;
|
|
1185
|
+
const activeToken = config.auth.mode === "embedded" ? config.auth.getToken() : standaloneAccessToken;
|
|
1186
|
+
const authGenerationRef = (0, import_react3.useRef)({ mode: config.auth.mode, token: activeToken, generation: 0 });
|
|
1187
|
+
if (authGenerationRef.current.mode !== config.auth.mode || authGenerationRef.current.token !== activeToken) {
|
|
1188
|
+
authGenerationRef.current = {
|
|
1189
|
+
mode: config.auth.mode,
|
|
1190
|
+
token: activeToken,
|
|
1191
|
+
generation: authGenerationRef.current.generation + 1
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
const identityKey = configuredIdentityKey ?? `anonymous:${providerInstanceId}:${authGenerationRef.current.generation}`;
|
|
1158
1195
|
const scopeKey = (0, import_react3.useMemo)(
|
|
1159
1196
|
() => ({
|
|
1160
1197
|
databaseId: config.databaseId ?? null,
|
|
1161
|
-
endpoint: config.endpoint
|
|
1198
|
+
endpoint: config.endpoint,
|
|
1199
|
+
identityKey
|
|
1162
1200
|
}),
|
|
1163
|
-
[config.databaseId, config.endpoint]
|
|
1201
|
+
[config.databaseId, config.endpoint, identityKey]
|
|
1164
1202
|
);
|
|
1203
|
+
(0, import_react3.useEffect)(() => {
|
|
1204
|
+
return () => {
|
|
1205
|
+
void queryClient.cancelQueries({ queryKey: sheetsQueryKeys.scope(scopeKey) });
|
|
1206
|
+
};
|
|
1207
|
+
}, [queryClient, scopeKey]);
|
|
1165
1208
|
const contextValue = (0, import_react3.useMemo)(
|
|
1166
1209
|
() => ({ config, execute, executeUpload, scopeKey }),
|
|
1167
1210
|
[config, execute, executeUpload, scopeKey]
|
|
1168
1211
|
);
|
|
1169
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetsStoreContext.Provider, { value:
|
|
1212
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_query.QueryClientProvider, { client: queryClient, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetsStoreContext.Provider, { value: store, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SheetsContext.Provider, { value: contextValue, children }) }) });
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
// src/testing/meta-contract-fixture.ts
|
|
1216
|
+
var import_data6 = require("@constructive-io/data");
|
|
1217
|
+
var fields = (names) => names.map((name) => ({ name }));
|
|
1218
|
+
function createMetaContractFixture() {
|
|
1219
|
+
return Object.fromEntries(
|
|
1220
|
+
Object.entries(import_data6.META_CONTRACT_REQUIREMENTS).map(([alias, requirement]) => [
|
|
1221
|
+
alias,
|
|
1222
|
+
{ name: requirement.typeName, fields: fields(requirement.fields) }
|
|
1223
|
+
])
|
|
1224
|
+
);
|
|
1170
1225
|
}
|
|
1171
1226
|
|
|
1172
1227
|
// src/testing/mock-sheets-provider.tsx
|
|
@@ -1179,9 +1234,10 @@ function documentToString2(document) {
|
|
|
1179
1234
|
}
|
|
1180
1235
|
return String(document ?? "");
|
|
1181
1236
|
}
|
|
1182
|
-
function buildMetaField(field) {
|
|
1237
|
+
function buildMetaField(field, primaryKeyFields) {
|
|
1183
1238
|
return {
|
|
1184
1239
|
name: field.name,
|
|
1240
|
+
isPrimaryKey: primaryKeyFields.has(field.name),
|
|
1185
1241
|
isNotNull: false,
|
|
1186
1242
|
hasDefault: false,
|
|
1187
1243
|
type: {
|
|
@@ -1195,26 +1251,33 @@ function buildMetaField(field) {
|
|
|
1195
1251
|
};
|
|
1196
1252
|
}
|
|
1197
1253
|
function buildMetaTable(table) {
|
|
1254
|
+
const primaryKeyFields = table.primaryKeyFields ?? (table.fields.some((field) => field.name === "id") ? ["id"] : []);
|
|
1255
|
+
const primaryKeySet = new Set(primaryKeyFields);
|
|
1256
|
+
const primaryKeyMetaFields = table.fields.filter((field) => primaryKeySet.has(field.name)).map((field) => buildMetaField(field, primaryKeySet));
|
|
1198
1257
|
return {
|
|
1199
1258
|
name: table.name,
|
|
1200
1259
|
schemaName: "public",
|
|
1201
1260
|
query: {
|
|
1202
|
-
all: (0,
|
|
1203
|
-
create: (0,
|
|
1204
|
-
delete: (0,
|
|
1205
|
-
one: (0,
|
|
1206
|
-
update: (0,
|
|
1261
|
+
all: (0, import_data7.toCamelCasePlural)(table.name),
|
|
1262
|
+
create: (0, import_data7.toCreateMutationName)(table.name),
|
|
1263
|
+
delete: (0, import_data7.toDeleteMutationName)(table.name),
|
|
1264
|
+
one: (0, import_data7.toCamelCaseSingular)(table.name),
|
|
1265
|
+
update: (0, import_data7.toUpdateMutationName)(table.name)
|
|
1207
1266
|
},
|
|
1208
|
-
fields: table.fields.map(buildMetaField),
|
|
1267
|
+
fields: table.fields.map((field) => buildMetaField(field, primaryKeySet)),
|
|
1209
1268
|
inflection: {
|
|
1210
|
-
allRows: (0,
|
|
1211
|
-
connection: (0,
|
|
1269
|
+
allRows: (0, import_data7.toCamelCasePlural)(table.name),
|
|
1270
|
+
connection: (0, import_data7.toCamelCasePlural)(table.name),
|
|
1212
1271
|
tableType: table.name
|
|
1213
1272
|
},
|
|
1214
1273
|
indexes: [],
|
|
1215
|
-
constraints: {
|
|
1274
|
+
constraints: {
|
|
1275
|
+
primaryKey: primaryKeyMetaFields.length > 0 ? { name: `${table.name}_pkey`, fields: primaryKeyMetaFields } : null,
|
|
1276
|
+
unique: [],
|
|
1277
|
+
foreignKey: []
|
|
1278
|
+
},
|
|
1216
1279
|
foreignKeyConstraints: [],
|
|
1217
|
-
primaryKeyConstraints: [],
|
|
1280
|
+
primaryKeyConstraints: primaryKeyMetaFields.length > 0 ? [{ name: `${table.name}_pkey`, fields: primaryKeyMetaFields }] : [],
|
|
1218
1281
|
uniqueConstraints: [],
|
|
1219
1282
|
relations: { belongsTo: [], has: [], hasOne: [], hasMany: [], manyToMany: [] }
|
|
1220
1283
|
};
|
|
@@ -1227,7 +1290,7 @@ function buildMetaResponse(tables) {
|
|
|
1227
1290
|
};
|
|
1228
1291
|
}
|
|
1229
1292
|
function buildListResponse(table) {
|
|
1230
|
-
const field = (0,
|
|
1293
|
+
const field = (0, import_data7.toCamelCasePlural)(table.name);
|
|
1231
1294
|
return {
|
|
1232
1295
|
[field]: {
|
|
1233
1296
|
nodes: table.rows,
|
|
@@ -1287,13 +1350,13 @@ function findMutationTable(query, tables) {
|
|
|
1287
1350
|
let best = null;
|
|
1288
1351
|
for (const table of tables) {
|
|
1289
1352
|
const candidates = [
|
|
1290
|
-
{ op: "create", mutationName: (0,
|
|
1291
|
-
{ op: "update", mutationName: (0,
|
|
1292
|
-
{ op: "delete", mutationName: (0,
|
|
1353
|
+
{ op: "create", mutationName: (0, import_data7.toCreateMutationName)(table.name) },
|
|
1354
|
+
{ op: "update", mutationName: (0, import_data7.toUpdateMutationName)(table.name) },
|
|
1355
|
+
{ op: "delete", mutationName: (0, import_data7.toDeleteMutationName)(table.name) }
|
|
1293
1356
|
];
|
|
1294
1357
|
for (const c of candidates) {
|
|
1295
1358
|
if (query.includes(c.mutationName) && (!best || c.mutationName.length > best.mutationName.length)) {
|
|
1296
|
-
best = { table, op: c.op, mutationName: c.mutationName, singular: (0,
|
|
1359
|
+
best = { table, op: c.op, mutationName: c.mutationName, singular: (0, import_data7.toCamelCaseSingular)(table.name) };
|
|
1297
1360
|
}
|
|
1298
1361
|
}
|
|
1299
1362
|
}
|
|
@@ -1303,7 +1366,7 @@ function findListTable(query, tables) {
|
|
|
1303
1366
|
let best = null;
|
|
1304
1367
|
let bestLen = 0;
|
|
1305
1368
|
for (const table of tables) {
|
|
1306
|
-
const plural = (0,
|
|
1369
|
+
const plural = (0, import_data7.toCamelCasePlural)(table.name);
|
|
1307
1370
|
if (query.includes(plural) && plural.length > bestLen) {
|
|
1308
1371
|
best = table;
|
|
1309
1372
|
bestLen = plural.length;
|
|
@@ -1319,6 +1382,9 @@ function createMockExecute(opts) {
|
|
|
1319
1382
|
}
|
|
1320
1383
|
const execute = async (document, variables) => {
|
|
1321
1384
|
const query = documentToString2(document);
|
|
1385
|
+
if (query.includes("ConstructiveMetaContract")) {
|
|
1386
|
+
return createMetaContractFixture();
|
|
1387
|
+
}
|
|
1322
1388
|
if (isMetaQuery(query)) {
|
|
1323
1389
|
return buildMetaResponse(opts.tables);
|
|
1324
1390
|
}
|