@robosystems/core 0.22.2 → 0.22.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robosystems/core",
3
- "version": "0.22.2",
3
+ "version": "0.22.3",
4
4
  "description": "Shared React core for the RoboSystems apps",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -46,8 +46,8 @@ export declare function useGraphCreation(): {
46
46
  instance_tier?: string;
47
47
  schema_extensions?: string[];
48
48
  /**
49
- * Generic graphs only: the node/relationship schema to apply. When
50
- * omitted, a generic graph is created with an empty schema.
49
+ * Generic graphs only, and required for them: the node/relationship
50
+ * schema to apply, with at least one node.
51
51
  */
52
52
  custom_schema?: Record<string, unknown>;
53
53
  create_entity?: boolean;
@@ -76,7 +76,7 @@ export declare function useGraphCreation(): {
76
76
  tags?: string[];
77
77
  instance_tier?: string;
78
78
  schema_extensions?: string[];
79
- custom_schema?: Record<string, unknown>;
79
+ custom_schema: Record<string, unknown>;
80
80
  org_id?: string;
81
81
  }) => Promise<any>;
82
82
  startMonitoring: (operationId: string, options?: {
@@ -126,17 +126,16 @@ export function useOperationMonitoring() {
126
126
  reset });
127
127
  }
128
128
  /**
129
- * The schema sent for a generic graph: the caller's, or an empty one named
130
- * after the graph (a bare database the user fills in later).
129
+ * The schema of a generic graph. A graph cannot be provisioned without a node
130
+ * table, so a missing schema or one with no nodes is refused before any request.
131
131
  */
132
132
  function genericSchema(graphData) {
133
- if (graphData.custom_schema)
134
- return graphData.custom_schema;
135
- const name = graphData.graph_name
136
- .toLowerCase()
137
- .replace(/[^a-z0-9]+/g, '_')
138
- .replace(/^_+|_+$/g, '') || 'custom_graph';
139
- return { name, nodes: [], relationships: [] };
133
+ var _a;
134
+ const nodes = (_a = graphData.custom_schema) === null || _a === void 0 ? void 0 : _a.nodes;
135
+ if (!graphData.custom_schema || !Array.isArray(nodes) || nodes.length === 0) {
136
+ throw new Error('A generic graph needs a schema that defines at least one node.');
137
+ }
138
+ return graphData.custom_schema;
140
139
  }
141
140
  /**
142
141
  * Hook for graph creation using the new unified endpoint
@@ -148,6 +147,9 @@ export function useGraphCreation() {
148
147
  var _a, _b, _c, _d;
149
148
  setIsCreating(true);
150
149
  try {
150
+ const customSchema = graphData.graph_type === 'generic'
151
+ ? genericSchema(graphData)
152
+ : undefined;
151
153
  // Check if billing is enabled and user needs to complete checkout
152
154
  let billingData = null;
153
155
  if (graphData.org_id) {
@@ -176,9 +178,7 @@ export function useGraphCreation() {
176
178
  description: graphData.description,
177
179
  tags: graphData.tags,
178
180
  schema_extensions: graphData.schema_extensions,
179
- custom_schema: graphData.graph_type === 'generic'
180
- ? genericSchema(graphData)
181
- : undefined,
181
+ custom_schema: customSchema,
182
182
  create_entity: graphData.create_entity,
183
183
  entity_name: graphData.entity_name,
184
184
  entity_identifier: graphData.entity_identifier,
@@ -229,8 +229,8 @@ export function useGraphCreation() {
229
229
  };
230
230
  // A generic graph is defined by its schema; the API requires either
231
231
  // a custom_schema or an initial_entity.
232
- if (graphData.graph_type === 'generic') {
233
- requestBody.custom_schema = genericSchema(graphData);
232
+ if (customSchema) {
233
+ requestBody.custom_schema = customSchema;
234
234
  }
235
235
  // Add initial_entity for entity or company graphs
236
236
  if (graphData.graph_type === 'entity' && graphData.entity_name) {