@constructive-io/schema-builder 0.2.0 → 0.2.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.
Files changed (131) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/card-widths-CmIxkRfh.cjs +28 -0
  3. package/dist/card-widths-CmIxkRfh.cjs.map +1 -0
  4. package/dist/card-widths-pI4Kw4Xz.js +22 -0
  5. package/dist/card-widths-pI4Kw4Xz.js.map +1 -0
  6. package/dist/core-WwCS0CKu.cjs +66 -0
  7. package/dist/core-WwCS0CKu.cjs.map +1 -0
  8. package/dist/core-kx6KjxE5.js +49 -0
  9. package/dist/core-kx6KjxE5.js.map +1 -0
  10. package/dist/core.cjs +14 -212
  11. package/dist/core.d.cts +3 -54
  12. package/dist/core.d.ts +3 -54
  13. package/dist/core.js +3 -200
  14. package/dist/create-table-card-BzNKfpXO.cjs +7726 -0
  15. package/dist/create-table-card-BzNKfpXO.cjs.map +1 -0
  16. package/dist/create-table-card-pZ0Aq6rr.js +7685 -0
  17. package/dist/create-table-card-pZ0Aq6rr.js.map +1 -0
  18. package/dist/delete-confirm-dialog-Ch4tWj6B.cjs +42 -0
  19. package/dist/delete-confirm-dialog-Ch4tWj6B.cjs.map +1 -0
  20. package/dist/delete-confirm-dialog-K0AWE643.js +37 -0
  21. package/dist/delete-confirm-dialog-K0AWE643.js.map +1 -0
  22. package/dist/empty-state-card-DMn8ADRq.cjs +62 -0
  23. package/dist/empty-state-card-DMn8ADRq.cjs.map +1 -0
  24. package/dist/empty-state-card-Dnn36JVH.js +57 -0
  25. package/dist/empty-state-card-Dnn36JVH.js.map +1 -0
  26. package/dist/fields.cjs +8 -7763
  27. package/dist/fields.d.cts +39 -39
  28. package/dist/fields.d.ts +39 -39
  29. package/dist/fields.js +2 -7735
  30. package/dist/generated-types-DZMUyNBH.d.cts +27 -0
  31. package/dist/generated-types-DZMUyNBH.d.ts +27 -0
  32. package/dist/index-9h0EROdb.d.cts +56 -0
  33. package/dist/index-CwQ9QpxA.d.ts +7 -0
  34. package/dist/index-DOWB1UBK.d.cts +56 -0
  35. package/dist/index-DOWB1UBK.d.ts +56 -0
  36. package/dist/index-Dgb_e3AP.d.cts +7 -0
  37. package/dist/index-p_NegPQ5.d.ts +56 -0
  38. package/dist/index.cjs +736 -13712
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +4 -10
  41. package/dist/index.d.ts +4 -10
  42. package/dist/index.js +725 -13680
  43. package/dist/index.js.map +1 -1
  44. package/dist/indexes-view-CJ1WQKdp.js +736 -0
  45. package/dist/indexes-view-CJ1WQKdp.js.map +1 -0
  46. package/dist/indexes-view-peIv6QUZ.cjs +759 -0
  47. package/dist/indexes-view-peIv6QUZ.cjs.map +1 -0
  48. package/dist/indexes.cjs +6 -1041
  49. package/dist/indexes.d.cts +27 -27
  50. package/dist/indexes.d.ts +27 -27
  51. package/dist/indexes.js +2 -1016
  52. package/dist/invalidate-database-entities-9DsT5NlP.cjs +2862 -0
  53. package/dist/invalidate-database-entities-9DsT5NlP.cjs.map +1 -0
  54. package/dist/invalidate-database-entities-CmmOT3S0.js +2559 -0
  55. package/dist/invalidate-database-entities-CmmOT3S0.js.map +1 -0
  56. package/dist/keyboard-activation-BQiV0scm.js +13 -0
  57. package/dist/keyboard-activation-BQiV0scm.js.map +1 -0
  58. package/dist/keyboard-activation-D-L0IU6Y.cjs +19 -0
  59. package/dist/keyboard-activation-D-L0IU6Y.cjs.map +1 -0
  60. package/dist/policies-view-BRbpbyB6.js +1018 -0
  61. package/dist/policies-view-BRbpbyB6.js.map +1 -0
  62. package/dist/policies-view-H1HTjpmv.cjs +1023 -0
  63. package/dist/policies-view-H1HTjpmv.cjs.map +1 -0
  64. package/dist/policies.cjs +10 -5939
  65. package/dist/policies.d.cts +55 -50
  66. package/dist/policies.d.ts +55 -50
  67. package/dist/policies.js +4 -5911
  68. package/dist/policy-config-form-BwyK7DGV.js +2502 -0
  69. package/dist/policy-config-form-BwyK7DGV.js.map +1 -0
  70. package/dist/policy-config-form-CefFo6Fw.cjs +2629 -0
  71. package/dist/policy-config-form-CefFo6Fw.cjs.map +1 -0
  72. package/dist/policy-types-D_sYWb-b.d.cts +81 -0
  73. package/dist/policy-types-D_sYWb-b.d.ts +81 -0
  74. package/dist/query-BmN_qO0W.js +171 -0
  75. package/dist/query-BmN_qO0W.js.map +1 -0
  76. package/dist/query-DU-KZleN.cjs +212 -0
  77. package/dist/query-DU-KZleN.cjs.map +1 -0
  78. package/dist/relationships-view-B5TAcPHU.cjs +2452 -0
  79. package/dist/relationships-view-B5TAcPHU.cjs.map +1 -0
  80. package/dist/relationships-view-DbwFh5r-.js +2417 -0
  81. package/dist/relationships-view-DbwFh5r-.js.map +1 -0
  82. package/dist/relationships.cjs +9 -4328
  83. package/dist/relationships.d.cts +93 -92
  84. package/dist/relationships.d.ts +93 -92
  85. package/dist/relationships.js +2 -4300
  86. package/dist/rolldown-runtime-D_qnwXdH.cjs +35 -0
  87. package/dist/schema-builder-sidebar-Ctu621Vw.cjs +604 -0
  88. package/dist/schema-builder-sidebar-Ctu621Vw.cjs.map +1 -0
  89. package/dist/schema-builder-sidebar-VR-Ctidc.js +593 -0
  90. package/dist/schema-builder-sidebar-VR-Ctidc.js.map +1 -0
  91. package/dist/table-editor-C-hHz3DJ.cjs +1935 -0
  92. package/dist/table-editor-C-hHz3DJ.cjs.map +1 -0
  93. package/dist/table-editor-IVp3B4nG.js +1906 -0
  94. package/dist/table-editor-IVp3B4nG.js.map +1 -0
  95. package/dist/tables.cjs +6 -5643
  96. package/dist/tables.d.cts +22 -21
  97. package/dist/tables.d.ts +22 -21
  98. package/dist/tables.js +3 -5618
  99. package/dist/testing.cjs +63 -62
  100. package/dist/testing.cjs.map +1 -1
  101. package/dist/testing.d.cts +4 -4
  102. package/dist/testing.d.ts +4 -4
  103. package/dist/testing.js +62 -61
  104. package/dist/testing.js.map +1 -1
  105. package/dist/types-GUrH1Qny.d.cts +200 -0
  106. package/dist/types-GUrH1Qny.d.ts +200 -0
  107. package/dist/use-update-table-C7v3gRyG.cjs +291 -0
  108. package/dist/use-update-table-C7v3gRyG.cjs.map +1 -0
  109. package/dist/use-update-table-Dz6knGoH.js +244 -0
  110. package/dist/use-update-table-Dz6knGoH.js.map +1 -0
  111. package/package.json +6 -6
  112. package/dist/core.cjs.map +0 -1
  113. package/dist/core.js.map +0 -1
  114. package/dist/fields.cjs.map +0 -1
  115. package/dist/fields.js.map +0 -1
  116. package/dist/generated-types-CnAlqHU_.d.cts +0 -25
  117. package/dist/generated-types-CnAlqHU_.d.ts +0 -25
  118. package/dist/indexes.cjs.map +0 -1
  119. package/dist/indexes.js.map +0 -1
  120. package/dist/policies.cjs.map +0 -1
  121. package/dist/policies.js.map +0 -1
  122. package/dist/policy-types-CEYAR5TN.d.cts +0 -79
  123. package/dist/policy-types-CEYAR5TN.d.ts +0 -79
  124. package/dist/relationships.cjs.map +0 -1
  125. package/dist/relationships.js.map +0 -1
  126. package/dist/tables.cjs.map +0 -1
  127. package/dist/tables.js.map +0 -1
  128. package/dist/types-Du86atZ8.d.cts +0 -199
  129. package/dist/types-Du86atZ8.d.ts +0 -199
  130. package/dist/types-bX2dCrdl.d.cts +0 -52
  131. package/dist/types-bX2dCrdl.d.ts +0 -52
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.1](https://github.com/constructive-io/blocks/compare/@constructive-io/schema-builder@0.2.0...@constructive-io/schema-builder@0.2.1) (2026-07-29)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **packages:** migrate builds to tsdown ([844c578](https://github.com/constructive-io/blocks/commit/844c5786e0892146805b41638e646307d377661f))
12
+
13
+
14
+
15
+
16
+
6
17
  # 0.2.0 (2026-07-29)
7
18
 
8
19
 
@@ -0,0 +1,28 @@
1
+ 'use client';
2
+
3
+ //#region src/schema/schema-builder-core/lib/stack/card-widths.ts
4
+ /**
5
+ * Standard card widths for Stack cards.
6
+ * Use these for consistency across the app.
7
+ */
8
+ const CARD_WIDTHS = {
9
+ /** Narrow forms, simple lists (360px) */
10
+ narrow: 360,
11
+ /** Default for most forms (480px) */
12
+ medium: 480,
13
+ /** Complex forms, editors with multiple sections (560px) */
14
+ wide: 560,
15
+ /** Large editors, multi-column layouts (720px) */
16
+ extraWide: 720,
17
+ /** Near full-width for complex UIs */
18
+ fullish: "90vw"
19
+ };
20
+
21
+ //#endregion
22
+ Object.defineProperty(exports, 'CARD_WIDTHS', {
23
+ enumerable: true,
24
+ get: function () {
25
+ return CARD_WIDTHS;
26
+ }
27
+ });
28
+ //# sourceMappingURL=card-widths-CmIxkRfh.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card-widths-CmIxkRfh.cjs","names":[],"sources":["../src/schema/schema-builder-core/lib/stack/card-widths.ts"],"mappings":";;;;;;;AAIA,MAAa,cAAc;;CAE1B,QAAQ;;CAER,QAAQ;;CAER,MAAM;;CAEN,WAAW;;CAEX,SAAS;AACV"}
@@ -0,0 +1,22 @@
1
+ 'use client';
2
+ //#region src/schema/schema-builder-core/lib/stack/card-widths.ts
3
+ /**
4
+ * Standard card widths for Stack cards.
5
+ * Use these for consistency across the app.
6
+ */
7
+ const CARD_WIDTHS = {
8
+ /** Narrow forms, simple lists (360px) */
9
+ narrow: 360,
10
+ /** Default for most forms (480px) */
11
+ medium: 480,
12
+ /** Complex forms, editors with multiple sections (560px) */
13
+ wide: 560,
14
+ /** Large editors, multi-column layouts (720px) */
15
+ extraWide: 720,
16
+ /** Near full-width for complex UIs */
17
+ fullish: "90vw"
18
+ };
19
+
20
+ //#endregion
21
+ export { CARD_WIDTHS as t };
22
+ //# sourceMappingURL=card-widths-pI4Kw4Xz.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"card-widths-pI4Kw4Xz.js","names":[],"sources":["../src/schema/schema-builder-core/lib/stack/card-widths.ts"],"mappings":";;;;;;AAIA,MAAa,cAAc;;CAE1B,QAAQ;;CAER,QAAQ;;CAER,MAAM;;CAEN,WAAW;;CAEX,SAAS;AACV"}
@@ -0,0 +1,66 @@
1
+ 'use client';
2
+ const require_query = require('./query-DU-KZleN.cjs');
3
+ let _tanstack_react_query = require("@tanstack/react-query");
4
+
5
+ //#region src/core/mutation.ts
6
+ function useSchemaBuilderMutation(feature, operation, options = {}) {
7
+ const { adapter, scope, onInvalidate } = require_query.useSchemaBuilder();
8
+ const queryClient = (0, _tanstack_react_query.useQueryClient)();
9
+ const operationFn = adapter[feature][operation];
10
+ if (typeof operationFn !== "function") throw new Error(`SchemaBuilder adapter is missing ${feature}.${operation}`);
11
+ const { selection, ...mutationOptions } = options;
12
+ const hostOnSuccess = mutationOptions.onSuccess;
13
+ return (0, _tanstack_react_query.useMutation)({
14
+ ...mutationOptions,
15
+ mutationFn: (variables) => operationFn(variables, {
16
+ scope,
17
+ selection
18
+ }),
19
+ onSuccess: async (data, variables, onMutateResult, context) => {
20
+ await queryClient.invalidateQueries({ queryKey: require_query.schemaBuilderQueryKey(scope, "core", "").slice(0, 4) });
21
+ onInvalidate?.({
22
+ scope,
23
+ feature,
24
+ operation
25
+ });
26
+ await hostOnSuccess?.(data, variables, onMutateResult, context);
27
+ }
28
+ });
29
+ }
30
+
31
+ //#endregion
32
+ //#region src/types.ts
33
+ const DEFAULT_SCHEMA_BUILDER_PREFERENCES = {
34
+ sidebarSectionsExpanded: {
35
+ app: true,
36
+ system: false
37
+ },
38
+ showSystemTablesInSidebar: false,
39
+ showSystemTablesInVisualizer: false,
40
+ sidebarPinned: false,
41
+ typesLibraryExpanded: true
42
+ };
43
+ function defineSchemaBuilderAdapter(adapter) {
44
+ return adapter;
45
+ }
46
+
47
+ //#endregion
48
+ Object.defineProperty(exports, 'DEFAULT_SCHEMA_BUILDER_PREFERENCES', {
49
+ enumerable: true,
50
+ get: function () {
51
+ return DEFAULT_SCHEMA_BUILDER_PREFERENCES;
52
+ }
53
+ });
54
+ Object.defineProperty(exports, 'defineSchemaBuilderAdapter', {
55
+ enumerable: true,
56
+ get: function () {
57
+ return defineSchemaBuilderAdapter;
58
+ }
59
+ });
60
+ Object.defineProperty(exports, 'useSchemaBuilderMutation', {
61
+ enumerable: true,
62
+ get: function () {
63
+ return useSchemaBuilderMutation;
64
+ }
65
+ });
66
+ //# sourceMappingURL=core-WwCS0CKu.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-WwCS0CKu.cjs","names":["useSchemaBuilder","schemaBuilderQueryKey"],"sources":["../src/core/mutation.ts","../src/types.ts"],"mappings":";;;;;AA8BA,SAAgB,yBAKd,SACA,WACA,UAA2D,CAAC,GACf;CAC7C,MAAM,EAAE,SAAS,OAAO,iBAAiBA,+BAAiB;CAC1D,MAAM,wDAA6B;CAEnC,MAAM,cADa,QAAQ,QACG,CAAC;CAE/B,IAAI,OAAO,gBAAgB,YACzB,MAAM,IAAI,MAAM,oCAAoC,QAAQ,GAAG,WAAW;CAG5E,MAAM,EAAE,WAAW,GAAG,oBAAoB;CAC1C,MAAM,gBAAgB,gBAAgB;CAEtC,8CAAmB;EACjB,GAAG;EACH,aAAa,cACX,YAAY,WAAW;GAAE;GAAO;EAAU,CAAC;EAC7C,WAAW,OAAO,MAAM,WAAW,gBAAgB,YAAY;GAC7D,MAAM,YAAY,kBAAkB,EAClC,UAAUC,oCAAsB,OAAO,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAC/D,CAAC;GACD,eAAe;IAAE;IAAO;IAAS;GAAU,CAAC;GAC5C,MAAM,gBAAgB,MAAM,WAAW,gBAAgB,OAAO;EAChE;CACF,CAAC;AACH;;;;ACxCA,MAAa,qCAAyE;CACpF,yBAAyB;EACvB,KAAK;EACL,QAAQ;CACV;CACA,2BAA2B;CAC3B,8BAA8B;CAC9B,eAAe;CACf,sBAAsB;AACxB;AAiNA,SAAgB,2BAAkE,SAA6B;CAC7G,OAAO;AACT"}
@@ -0,0 +1,49 @@
1
+ 'use client';
2
+ import { i as useSchemaBuilder, t as schemaBuilderQueryKey } from "./query-BmN_qO0W.js";
3
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
4
+
5
+ //#region src/core/mutation.ts
6
+ function useSchemaBuilderMutation(feature, operation, options = {}) {
7
+ const { adapter, scope, onInvalidate } = useSchemaBuilder();
8
+ const queryClient = useQueryClient();
9
+ const operationFn = adapter[feature][operation];
10
+ if (typeof operationFn !== "function") throw new Error(`SchemaBuilder adapter is missing ${feature}.${operation}`);
11
+ const { selection, ...mutationOptions } = options;
12
+ const hostOnSuccess = mutationOptions.onSuccess;
13
+ return useMutation({
14
+ ...mutationOptions,
15
+ mutationFn: (variables) => operationFn(variables, {
16
+ scope,
17
+ selection
18
+ }),
19
+ onSuccess: async (data, variables, onMutateResult, context) => {
20
+ await queryClient.invalidateQueries({ queryKey: schemaBuilderQueryKey(scope, "core", "").slice(0, 4) });
21
+ onInvalidate?.({
22
+ scope,
23
+ feature,
24
+ operation
25
+ });
26
+ await hostOnSuccess?.(data, variables, onMutateResult, context);
27
+ }
28
+ });
29
+ }
30
+
31
+ //#endregion
32
+ //#region src/types.ts
33
+ const DEFAULT_SCHEMA_BUILDER_PREFERENCES = {
34
+ sidebarSectionsExpanded: {
35
+ app: true,
36
+ system: false
37
+ },
38
+ showSystemTablesInSidebar: false,
39
+ showSystemTablesInVisualizer: false,
40
+ sidebarPinned: false,
41
+ typesLibraryExpanded: true
42
+ };
43
+ function defineSchemaBuilderAdapter(adapter) {
44
+ return adapter;
45
+ }
46
+
47
+ //#endregion
48
+ export { defineSchemaBuilderAdapter as n, useSchemaBuilderMutation as r, DEFAULT_SCHEMA_BUILDER_PREFERENCES as t };
49
+ //# sourceMappingURL=core-kx6KjxE5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core-kx6KjxE5.js","names":[],"sources":["../src/core/mutation.ts","../src/types.ts"],"mappings":";;;;;AA8BA,SAAgB,yBAKd,SACA,WACA,UAA2D,CAAC,GACf;CAC7C,MAAM,EAAE,SAAS,OAAO,iBAAiB,iBAAiB;CAC1D,MAAM,cAAc,eAAe;CAEnC,MAAM,cADa,QAAQ,QACG,CAAC;CAE/B,IAAI,OAAO,gBAAgB,YACzB,MAAM,IAAI,MAAM,oCAAoC,QAAQ,GAAG,WAAW;CAG5E,MAAM,EAAE,WAAW,GAAG,oBAAoB;CAC1C,MAAM,gBAAgB,gBAAgB;CAEtC,OAAO,YAAY;EACjB,GAAG;EACH,aAAa,cACX,YAAY,WAAW;GAAE;GAAO;EAAU,CAAC;EAC7C,WAAW,OAAO,MAAM,WAAW,gBAAgB,YAAY;GAC7D,MAAM,YAAY,kBAAkB,EAClC,UAAU,sBAAsB,OAAO,QAAQ,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC,EAC/D,CAAC;GACD,eAAe;IAAE;IAAO;IAAS;GAAU,CAAC;GAC5C,MAAM,gBAAgB,MAAM,WAAW,gBAAgB,OAAO;EAChE;CACF,CAAC;AACH;;;;ACxCA,MAAa,qCAAyE;CACpF,yBAAyB;EACvB,KAAK;EACL,QAAQ;CACV;CACA,2BAA2B;CAC3B,8BAA8B;CAC9B,eAAe;CACf,sBAAsB;AACxB;AAiNA,SAAgB,2BAAkE,SAA6B;CAC7G,OAAO;AACT"}
package/dist/core.cjs CHANGED
@@ -1,213 +1,15 @@
1
1
  'use client';
2
- 'use strict';
3
-
4
- var react = require('react');
5
- var zustand = require('zustand');
6
- var vanilla = require('zustand/vanilla');
7
- var jsxRuntime = require('react/jsx-runtime');
8
- var reactQuery = require('@tanstack/react-query');
9
-
10
- function getSchemaBuilderScopeKey(scope) {
11
- return [scope.orgId, scope.databaseId, scope.userId ?? "anonymous"].join(":");
12
- }
13
- function createSchemaBuilderStore(scope, preferences, activeTab, selectedTableId = null) {
14
- return vanilla.createStore((set, get) => ({
15
- scopeKey: getSchemaBuilderScopeKey(scope),
16
- selectedTableId,
17
- selectedFieldId: null,
18
- currentDatabaseApi: null,
19
- preferences,
20
- activeTab,
21
- setSelectedTableId: (selectedTableId2) => set({
22
- selectedTableId: selectedTableId2,
23
- selectedFieldId: selectedTableId2 === get().selectedTableId ? get().selectedFieldId : null
24
- }),
25
- setSelectedFieldId: (selectedFieldId) => set({ selectedFieldId }),
26
- setCurrentDatabaseApi: (currentDatabaseApi) => set({ currentDatabaseApi }),
27
- replacePreferences: (nextPreferences) => set({ preferences: nextPreferences }),
28
- replaceActiveTab: (nextActiveTab) => set({ activeTab: nextActiveTab }),
29
- replaceScope: (nextScope) => {
30
- const nextScopeKey = getSchemaBuilderScopeKey(nextScope);
31
- if (nextScopeKey === get().scopeKey) return;
32
- set({
33
- scopeKey: nextScopeKey,
34
- selectedTableId: null,
35
- selectedFieldId: null,
36
- currentDatabaseApi: null
37
- });
38
- }
39
- }));
40
- }
41
- var CORE_TAB_IDS = /* @__PURE__ */ new Set(["editor", "relationships", "indexes", "security"]);
42
- var EMPTY_TABS = [];
43
- var SchemaBuilderContext = react.createContext(null);
44
- function validateExtensionTabs(tabs) {
45
- const seen = new Set(CORE_TAB_IDS);
46
- for (const tab of tabs) {
47
- if (!tab.id.trim()) throw new Error("SchemaBuilder extension tab ids cannot be empty");
48
- if (seen.has(tab.id)) {
49
- throw new Error(`Duplicate SchemaBuilder tab id: ${tab.id}`);
50
- }
51
- seen.add(tab.id);
52
- }
53
- }
54
- function SchemaBuilderProvider({
55
- children,
56
- tabs = EMPTY_TABS,
57
- ...host
58
- }) {
59
- const [store] = react.useState(
60
- () => createSchemaBuilderStore(
61
- host.scope,
62
- host.preferences,
63
- host.activeTab,
64
- host.selectedTableId ?? null
65
- )
66
- );
67
- const validatedTabs = react.useMemo(() => {
68
- validateExtensionTabs(tabs);
69
- return tabs;
70
- }, [tabs]);
71
- react.useEffect(() => {
72
- store.getState().replaceScope(host.scope);
73
- }, [host.scope, store]);
74
- react.useEffect(() => {
75
- store.getState().replacePreferences(host.preferences);
76
- }, [host.preferences, store]);
77
- react.useEffect(() => {
78
- store.getState().replaceActiveTab(host.activeTab);
79
- }, [host.activeTab, store]);
80
- react.useEffect(() => {
81
- if (host.selectedTableId !== void 0) {
82
- store.getState().setSelectedTableId(host.selectedTableId);
83
- }
84
- }, [host.scope, host.selectedTableId, store]);
85
- const setActiveTab = react.useCallback(
86
- (tabId) => {
87
- const extension = validatedTabs.find((tab) => tab.id === tabId);
88
- if (!CORE_TAB_IDS.has(tabId) && !extension) {
89
- throw new Error(`Unknown SchemaBuilder tab id: ${tabId}`);
90
- }
91
- void extension?.preload?.();
92
- store.getState().replaceActiveTab(tabId);
93
- host.onActiveTabChange(tabId);
94
- },
95
- [host.onActiveTabChange, store, validatedTabs]
96
- );
97
- const setPreferences = react.useCallback(
98
- (update) => {
99
- const current = store.getState().preferences;
100
- const next = typeof update === "function" ? update(current) : update;
101
- store.getState().replacePreferences(next);
102
- host.onPreferencesChange(next);
103
- },
104
- [host.onPreferencesChange, store]
105
- );
106
- const selectTable = react.useCallback(
107
- (tableId, tableName) => {
108
- store.getState().setSelectedTableId(tableId);
109
- host.onSelectedTableChange?.({ tableId, tableName: tableName ?? null });
110
- },
111
- [host.onSelectedTableChange, store]
112
- );
113
- const selectField = react.useCallback(
114
- (fieldId) => store.getState().setSelectedFieldId(fieldId),
115
- [store]
116
- );
117
- const value = react.useMemo(
118
- () => ({
119
- ...host,
120
- tabs: validatedTabs,
121
- store,
122
- setActiveTab,
123
- setPreferences,
124
- selectTable,
125
- selectField
126
- }),
127
- [host, selectField, selectTable, setActiveTab, setPreferences, store, validatedTabs]
128
- );
129
- return /* @__PURE__ */ jsxRuntime.jsx(SchemaBuilderContext.Provider, { value, children });
130
- }
131
- function useSchemaBuilder() {
132
- const value = react.useContext(SchemaBuilderContext);
133
- if (!value) throw new Error("SchemaBuilderProvider is missing");
134
- return value;
135
- }
136
- function useSchemaBuilderStore(selector) {
137
- const { store } = useSchemaBuilder();
138
- return zustand.useStore(store, selector);
139
- }
140
- function schemaBuilderQueryKey(scope, feature, operation, variables = {}) {
141
- return [
142
- "@constructive-io/schema-builder",
143
- scope.orgId,
144
- scope.databaseId,
145
- scope.userId ?? null,
146
- feature,
147
- operation,
148
- variables
149
- ];
150
- }
151
- function useSchemaBuilderQuery(feature, operation, variables = {}, options = {}) {
152
- const { adapter, scope } = useSchemaBuilder();
153
- const capability = adapter[feature];
154
- const operationFn = capability[operation];
155
- if (typeof operationFn !== "function") {
156
- throw new Error(`SchemaBuilder adapter is missing ${feature}.${operation}`);
157
- }
158
- return reactQuery.useQuery({
159
- ...options,
160
- queryKey: schemaBuilderQueryKey(scope, feature, operation, variables),
161
- queryFn: ({ signal }) => operationFn(variables, { scope, signal })
162
- });
163
- }
164
- function useSchemaBuilderMutation(feature, operation, options = {}) {
165
- const { adapter, scope, onInvalidate } = useSchemaBuilder();
166
- const queryClient = reactQuery.useQueryClient();
167
- const capability = adapter[feature];
168
- const operationFn = capability[operation];
169
- if (typeof operationFn !== "function") {
170
- throw new Error(`SchemaBuilder adapter is missing ${feature}.${operation}`);
171
- }
172
- const { selection, ...mutationOptions } = options;
173
- const hostOnSuccess = mutationOptions.onSuccess;
174
- return reactQuery.useMutation({
175
- ...mutationOptions,
176
- mutationFn: (variables) => operationFn(variables, { scope, selection }),
177
- onSuccess: async (data, variables, onMutateResult, context) => {
178
- await queryClient.invalidateQueries({
179
- queryKey: schemaBuilderQueryKey(scope, "core", "").slice(0, 4)
180
- });
181
- onInvalidate?.({ scope, feature, operation });
182
- await hostOnSuccess?.(data, variables, onMutateResult, context);
183
- }
184
- });
185
- }
186
-
187
- // src/types.ts
188
- var DEFAULT_SCHEMA_BUILDER_PREFERENCES = {
189
- sidebarSectionsExpanded: {
190
- app: true,
191
- system: false
192
- },
193
- showSystemTablesInSidebar: false,
194
- showSystemTablesInVisualizer: false,
195
- sidebarPinned: false,
196
- typesLibraryExpanded: true
197
- };
198
- function defineSchemaBuilderAdapter(adapter) {
199
- return adapter;
200
- }
201
-
202
- exports.DEFAULT_SCHEMA_BUILDER_PREFERENCES = DEFAULT_SCHEMA_BUILDER_PREFERENCES;
203
- exports.SchemaBuilderProvider = SchemaBuilderProvider;
204
- exports.createSchemaBuilderStore = createSchemaBuilderStore;
205
- exports.defineSchemaBuilderAdapter = defineSchemaBuilderAdapter;
206
- exports.getSchemaBuilderScopeKey = getSchemaBuilderScopeKey;
207
- exports.schemaBuilderQueryKey = schemaBuilderQueryKey;
208
- exports.useSchemaBuilder = useSchemaBuilder;
209
- exports.useSchemaBuilderMutation = useSchemaBuilderMutation;
210
- exports.useSchemaBuilderQuery = useSchemaBuilderQuery;
211
- exports.useSchemaBuilderStore = useSchemaBuilderStore;
212
- //# sourceMappingURL=core.cjs.map
213
- //# sourceMappingURL=core.cjs.map
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
3
+ const require_query = require('./query-DU-KZleN.cjs');
4
+ const require_core = require('./core-WwCS0CKu.cjs');
5
+
6
+ exports.DEFAULT_SCHEMA_BUILDER_PREFERENCES = require_core.DEFAULT_SCHEMA_BUILDER_PREFERENCES;
7
+ exports.SchemaBuilderProvider = require_query.SchemaBuilderProvider;
8
+ exports.createSchemaBuilderStore = require_query.createSchemaBuilderStore;
9
+ exports.defineSchemaBuilderAdapter = require_core.defineSchemaBuilderAdapter;
10
+ exports.getSchemaBuilderScopeKey = require_query.getSchemaBuilderScopeKey;
11
+ exports.schemaBuilderQueryKey = require_query.schemaBuilderQueryKey;
12
+ exports.useSchemaBuilder = require_query.useSchemaBuilder;
13
+ exports.useSchemaBuilderMutation = require_core.useSchemaBuilderMutation;
14
+ exports.useSchemaBuilderQuery = require_query.useSchemaBuilderQuery;
15
+ exports.useSchemaBuilderStore = require_query.useSchemaBuilderStore;
package/dist/core.d.cts CHANGED
@@ -1,54 +1,3 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { StoreApi } from 'zustand/vanilla';
4
- import { r as SchemaBuilderPreferences, v as SchemaBuilderScope, i as SchemaBuilderHostOptions, f as SchemaBuilderFeature, C as SchemaBuilderVariables, a as SchemaBuilderAdapter, o as SchemaBuilderOperationContext } from './types-Du86atZ8.cjs';
5
- export { D as DEFAULT_SCHEMA_BUILDER_PREFERENCES, b as SchemaBuilderCollection, c as SchemaBuilderColorMode, d as SchemaBuilderCoreCapabilities, e as SchemaBuilderCoreTabId, g as SchemaBuilderField, j as SchemaBuilderIndex, l as SchemaBuilderInvalidationEvent, m as SchemaBuilderNavigationTarget, n as SchemaBuilderOperation, q as SchemaBuilderPolicy, s as SchemaBuilderRelationship, u as SchemaBuilderSchema, w as SchemaBuilderSidebarSections, x as SchemaBuilderTab, y as SchemaBuilderTabRenderContext, z as SchemaBuilderTable, E as defineSchemaBuilderAdapter } from './types-Du86atZ8.cjs';
6
- import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
7
-
8
- interface SchemaBuilderStoreState {
9
- scopeKey: string;
10
- selectedTableId: string | null;
11
- selectedFieldId: string | null;
12
- currentDatabaseApi: unknown | null;
13
- preferences: SchemaBuilderPreferences;
14
- activeTab: string;
15
- setSelectedTableId: (tableId: string | null) => void;
16
- setSelectedFieldId: (fieldId: string | null) => void;
17
- setCurrentDatabaseApi: (api: unknown | null) => void;
18
- replacePreferences: (preferences: SchemaBuilderPreferences) => void;
19
- replaceActiveTab: (tabId: string) => void;
20
- replaceScope: (scope: SchemaBuilderScope) => void;
21
- }
22
- declare function getSchemaBuilderScopeKey(scope: SchemaBuilderScope): string;
23
- declare function createSchemaBuilderStore(scope: SchemaBuilderScope, preferences: SchemaBuilderPreferences, activeTab: string, selectedTableId?: string | null): StoreApi<SchemaBuilderStoreState>;
24
-
25
- interface SchemaBuilderContextValue extends SchemaBuilderHostOptions {
26
- store: StoreApi<SchemaBuilderStoreState>;
27
- setActiveTab: (tabId: string) => void;
28
- setPreferences: (preferences: SchemaBuilderPreferences | ((current: SchemaBuilderPreferences) => SchemaBuilderPreferences)) => void;
29
- selectTable: (tableId: string | null, tableName?: string | null) => void;
30
- selectField: (fieldId: string | null) => void;
31
- }
32
- interface SchemaBuilderProviderProps extends SchemaBuilderHostOptions {
33
- children: ReactNode;
34
- }
35
- declare function SchemaBuilderProvider({ children, tabs, ...host }: SchemaBuilderProviderProps): react.JSX.Element;
36
- declare function useSchemaBuilder(): SchemaBuilderContextValue;
37
- declare function useSchemaBuilderStore<T>(selector: (state: SchemaBuilderStoreState) => T): T;
38
-
39
- type FeatureOperation$1<TFeature extends SchemaBuilderFeature> = Extract<keyof SchemaBuilderAdapter[TFeature], string>;
40
- declare function schemaBuilderQueryKey(scope: {
41
- orgId: string;
42
- databaseId: string;
43
- userId?: string | null;
44
- }, feature: SchemaBuilderFeature, operation: string, variables?: SchemaBuilderVariables): readonly ["@constructive-io/schema-builder", string, string, string | null, keyof SchemaBuilderAdapter, string, object];
45
- declare function useSchemaBuilderQuery<TData = unknown, TFeature extends SchemaBuilderFeature = SchemaBuilderFeature>(feature: TFeature, operation: FeatureOperation$1<TFeature>, variables?: SchemaBuilderVariables, options?: Omit<UseQueryOptions<TData, Error, TData, ReturnType<typeof schemaBuilderQueryKey>>, 'queryKey' | 'queryFn'>): UseQueryResult<TData, Error>;
46
-
47
- type FeatureOperation<TFeature extends SchemaBuilderFeature> = Extract<keyof SchemaBuilderAdapter[TFeature], string>;
48
- type SchemaBuilderMutationOptions<TData, TVariables, TContext = unknown> = UseMutationOptions<TData, Error, TVariables, TContext> & {
49
- /** Result fields required by generated GraphQL adapters for this mutation. */
50
- selection?: SchemaBuilderOperationContext['selection'];
51
- };
52
- declare function useSchemaBuilderMutation<TData = unknown, TVariables extends SchemaBuilderVariables = SchemaBuilderVariables, TFeature extends SchemaBuilderFeature = SchemaBuilderFeature>(feature: TFeature, operation: FeatureOperation<TFeature>, options?: SchemaBuilderMutationOptions<TData, TVariables>): UseMutationResult<TData, Error, TVariables>;
53
-
54
- export { SchemaBuilderAdapter, type SchemaBuilderContextValue, SchemaBuilderFeature, SchemaBuilderHostOptions, type SchemaBuilderMutationOptions, SchemaBuilderOperationContext, SchemaBuilderPreferences, SchemaBuilderProvider, type SchemaBuilderProviderProps, SchemaBuilderScope, type SchemaBuilderStoreState, SchemaBuilderVariables, createSchemaBuilderStore, getSchemaBuilderScopeKey, schemaBuilderQueryKey, useSchemaBuilder, useSchemaBuilderMutation, useSchemaBuilderQuery, useSchemaBuilderStore };
1
+ import { C as SchemaBuilderSchema, D as SchemaBuilderTabRenderContext, E as SchemaBuilderTab, M as defineSchemaBuilderAdapter, O as SchemaBuilderTable, T as SchemaBuilderSidebarSections, a as SchemaBuilderCoreCapabilities, c as SchemaBuilderField, d as SchemaBuilderIndex, g as SchemaBuilderOperationContext, h as SchemaBuilderOperation, i as SchemaBuilderColorMode, j as SchemaBuilderVariables, m as SchemaBuilderNavigationTarget, n as SchemaBuilderAdapter, o as SchemaBuilderCoreTabId, p as SchemaBuilderInvalidationEvent, r as SchemaBuilderCollection, s as SchemaBuilderFeature, t as DEFAULT_SCHEMA_BUILDER_PREFERENCES, u as SchemaBuilderHostOptions, v as SchemaBuilderPolicy, w as SchemaBuilderScope, x as SchemaBuilderRelationship, y as SchemaBuilderPreferences } from "./types-GUrH1Qny.cjs";
2
+ import { a as SchemaBuilderContextValue, c as useSchemaBuilder, d as createSchemaBuilderStore, f as getSchemaBuilderScopeKey, i as useSchemaBuilderQuery, l as useSchemaBuilderStore, n as useSchemaBuilderMutation, o as SchemaBuilderProvider, r as schemaBuilderQueryKey, s as SchemaBuilderProviderProps, t as SchemaBuilderMutationOptions, u as SchemaBuilderStoreState } from "./index-9h0EROdb.cjs";
3
+ export { DEFAULT_SCHEMA_BUILDER_PREFERENCES, type SchemaBuilderAdapter, type SchemaBuilderCollection, type SchemaBuilderColorMode, type SchemaBuilderContextValue, type SchemaBuilderCoreCapabilities, type SchemaBuilderCoreTabId, type SchemaBuilderFeature, type SchemaBuilderField, type SchemaBuilderHostOptions, type SchemaBuilderIndex, type SchemaBuilderInvalidationEvent, type SchemaBuilderMutationOptions, type SchemaBuilderNavigationTarget, type SchemaBuilderOperation, type SchemaBuilderOperationContext, type SchemaBuilderPolicy, type SchemaBuilderPreferences, SchemaBuilderProvider, type SchemaBuilderProviderProps, type SchemaBuilderRelationship, type SchemaBuilderSchema, type SchemaBuilderScope, type SchemaBuilderSidebarSections, type SchemaBuilderStoreState, type SchemaBuilderTab, type SchemaBuilderTabRenderContext, type SchemaBuilderTable, type SchemaBuilderVariables, createSchemaBuilderStore, defineSchemaBuilderAdapter, getSchemaBuilderScopeKey, schemaBuilderQueryKey, useSchemaBuilder, useSchemaBuilderMutation, useSchemaBuilderQuery, useSchemaBuilderStore };
package/dist/core.d.ts CHANGED
@@ -1,54 +1,3 @@
1
- import * as react from 'react';
2
- import { ReactNode } from 'react';
3
- import { StoreApi } from 'zustand/vanilla';
4
- import { r as SchemaBuilderPreferences, v as SchemaBuilderScope, i as SchemaBuilderHostOptions, f as SchemaBuilderFeature, C as SchemaBuilderVariables, a as SchemaBuilderAdapter, o as SchemaBuilderOperationContext } from './types-Du86atZ8.js';
5
- export { D as DEFAULT_SCHEMA_BUILDER_PREFERENCES, b as SchemaBuilderCollection, c as SchemaBuilderColorMode, d as SchemaBuilderCoreCapabilities, e as SchemaBuilderCoreTabId, g as SchemaBuilderField, j as SchemaBuilderIndex, l as SchemaBuilderInvalidationEvent, m as SchemaBuilderNavigationTarget, n as SchemaBuilderOperation, q as SchemaBuilderPolicy, s as SchemaBuilderRelationship, u as SchemaBuilderSchema, w as SchemaBuilderSidebarSections, x as SchemaBuilderTab, y as SchemaBuilderTabRenderContext, z as SchemaBuilderTable, E as defineSchemaBuilderAdapter } from './types-Du86atZ8.js';
6
- import { UseQueryOptions, UseQueryResult, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
7
-
8
- interface SchemaBuilderStoreState {
9
- scopeKey: string;
10
- selectedTableId: string | null;
11
- selectedFieldId: string | null;
12
- currentDatabaseApi: unknown | null;
13
- preferences: SchemaBuilderPreferences;
14
- activeTab: string;
15
- setSelectedTableId: (tableId: string | null) => void;
16
- setSelectedFieldId: (fieldId: string | null) => void;
17
- setCurrentDatabaseApi: (api: unknown | null) => void;
18
- replacePreferences: (preferences: SchemaBuilderPreferences) => void;
19
- replaceActiveTab: (tabId: string) => void;
20
- replaceScope: (scope: SchemaBuilderScope) => void;
21
- }
22
- declare function getSchemaBuilderScopeKey(scope: SchemaBuilderScope): string;
23
- declare function createSchemaBuilderStore(scope: SchemaBuilderScope, preferences: SchemaBuilderPreferences, activeTab: string, selectedTableId?: string | null): StoreApi<SchemaBuilderStoreState>;
24
-
25
- interface SchemaBuilderContextValue extends SchemaBuilderHostOptions {
26
- store: StoreApi<SchemaBuilderStoreState>;
27
- setActiveTab: (tabId: string) => void;
28
- setPreferences: (preferences: SchemaBuilderPreferences | ((current: SchemaBuilderPreferences) => SchemaBuilderPreferences)) => void;
29
- selectTable: (tableId: string | null, tableName?: string | null) => void;
30
- selectField: (fieldId: string | null) => void;
31
- }
32
- interface SchemaBuilderProviderProps extends SchemaBuilderHostOptions {
33
- children: ReactNode;
34
- }
35
- declare function SchemaBuilderProvider({ children, tabs, ...host }: SchemaBuilderProviderProps): react.JSX.Element;
36
- declare function useSchemaBuilder(): SchemaBuilderContextValue;
37
- declare function useSchemaBuilderStore<T>(selector: (state: SchemaBuilderStoreState) => T): T;
38
-
39
- type FeatureOperation$1<TFeature extends SchemaBuilderFeature> = Extract<keyof SchemaBuilderAdapter[TFeature], string>;
40
- declare function schemaBuilderQueryKey(scope: {
41
- orgId: string;
42
- databaseId: string;
43
- userId?: string | null;
44
- }, feature: SchemaBuilderFeature, operation: string, variables?: SchemaBuilderVariables): readonly ["@constructive-io/schema-builder", string, string, string | null, keyof SchemaBuilderAdapter, string, object];
45
- declare function useSchemaBuilderQuery<TData = unknown, TFeature extends SchemaBuilderFeature = SchemaBuilderFeature>(feature: TFeature, operation: FeatureOperation$1<TFeature>, variables?: SchemaBuilderVariables, options?: Omit<UseQueryOptions<TData, Error, TData, ReturnType<typeof schemaBuilderQueryKey>>, 'queryKey' | 'queryFn'>): UseQueryResult<TData, Error>;
46
-
47
- type FeatureOperation<TFeature extends SchemaBuilderFeature> = Extract<keyof SchemaBuilderAdapter[TFeature], string>;
48
- type SchemaBuilderMutationOptions<TData, TVariables, TContext = unknown> = UseMutationOptions<TData, Error, TVariables, TContext> & {
49
- /** Result fields required by generated GraphQL adapters for this mutation. */
50
- selection?: SchemaBuilderOperationContext['selection'];
51
- };
52
- declare function useSchemaBuilderMutation<TData = unknown, TVariables extends SchemaBuilderVariables = SchemaBuilderVariables, TFeature extends SchemaBuilderFeature = SchemaBuilderFeature>(feature: TFeature, operation: FeatureOperation<TFeature>, options?: SchemaBuilderMutationOptions<TData, TVariables>): UseMutationResult<TData, Error, TVariables>;
53
-
54
- export { SchemaBuilderAdapter, type SchemaBuilderContextValue, SchemaBuilderFeature, SchemaBuilderHostOptions, type SchemaBuilderMutationOptions, SchemaBuilderOperationContext, SchemaBuilderPreferences, SchemaBuilderProvider, type SchemaBuilderProviderProps, SchemaBuilderScope, type SchemaBuilderStoreState, SchemaBuilderVariables, createSchemaBuilderStore, getSchemaBuilderScopeKey, schemaBuilderQueryKey, useSchemaBuilder, useSchemaBuilderMutation, useSchemaBuilderQuery, useSchemaBuilderStore };
1
+ import { C as SchemaBuilderSchema, D as SchemaBuilderTabRenderContext, E as SchemaBuilderTab, M as defineSchemaBuilderAdapter, O as SchemaBuilderTable, T as SchemaBuilderSidebarSections, a as SchemaBuilderCoreCapabilities, c as SchemaBuilderField, d as SchemaBuilderIndex, g as SchemaBuilderOperationContext, h as SchemaBuilderOperation, i as SchemaBuilderColorMode, j as SchemaBuilderVariables, m as SchemaBuilderNavigationTarget, n as SchemaBuilderAdapter, o as SchemaBuilderCoreTabId, p as SchemaBuilderInvalidationEvent, r as SchemaBuilderCollection, s as SchemaBuilderFeature, t as DEFAULT_SCHEMA_BUILDER_PREFERENCES, u as SchemaBuilderHostOptions, v as SchemaBuilderPolicy, w as SchemaBuilderScope, x as SchemaBuilderRelationship, y as SchemaBuilderPreferences } from "./types-GUrH1Qny.js";
2
+ import { a as SchemaBuilderContextValue, c as useSchemaBuilder, d as createSchemaBuilderStore, f as getSchemaBuilderScopeKey, i as useSchemaBuilderQuery, l as useSchemaBuilderStore, n as useSchemaBuilderMutation, o as SchemaBuilderProvider, r as schemaBuilderQueryKey, s as SchemaBuilderProviderProps, t as SchemaBuilderMutationOptions, u as SchemaBuilderStoreState } from "./index-p_NegPQ5.js";
3
+ export { DEFAULT_SCHEMA_BUILDER_PREFERENCES, type SchemaBuilderAdapter, type SchemaBuilderCollection, type SchemaBuilderColorMode, type SchemaBuilderContextValue, type SchemaBuilderCoreCapabilities, type SchemaBuilderCoreTabId, type SchemaBuilderFeature, type SchemaBuilderField, type SchemaBuilderHostOptions, type SchemaBuilderIndex, type SchemaBuilderInvalidationEvent, type SchemaBuilderMutationOptions, type SchemaBuilderNavigationTarget, type SchemaBuilderOperation, type SchemaBuilderOperationContext, type SchemaBuilderPolicy, type SchemaBuilderPreferences, SchemaBuilderProvider, type SchemaBuilderProviderProps, type SchemaBuilderRelationship, type SchemaBuilderSchema, type SchemaBuilderScope, type SchemaBuilderSidebarSections, type SchemaBuilderStoreState, type SchemaBuilderTab, type SchemaBuilderTabRenderContext, type SchemaBuilderTable, type SchemaBuilderVariables, createSchemaBuilderStore, defineSchemaBuilderAdapter, getSchemaBuilderScopeKey, schemaBuilderQueryKey, useSchemaBuilder, useSchemaBuilderMutation, useSchemaBuilderQuery, useSchemaBuilderStore };