@happyvertical/smrt-core 0.51.37 → 0.51.39
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/agents/build-knowledge.md +25 -0
- package/agents/generators.md +27 -0
- package/agents/schema-paths.md +11 -0
- package/dist/consumer-plugin/artifact-publication.d.ts +2 -0
- package/dist/consumer-plugin/artifact-publication.d.ts.map +1 -1
- package/dist/consumer-plugin/artifact-publication.js +15 -1
- package/dist/consumer-plugin/artifact-publication.js.map +1 -1
- package/dist/consumer-plugin/index.d.ts.map +1 -1
- package/dist/consumer-plugin/index.js +3 -3
- package/dist/consumer-plugin/index.js.map +1 -1
- package/dist/generators/mcp-runtime-template.d.ts +17 -0
- package/dist/generators/mcp-runtime-template.d.ts.map +1 -1
- package/dist/generators/mcp-runtime-template.js +27 -19
- package/dist/generators/mcp-runtime-template.js.map +1 -1
- package/dist/generators/mcp-tool-name.d.ts +17 -0
- package/dist/generators/mcp-tool-name.d.ts.map +1 -0
- package/dist/generators/mcp-tool-name.js +33 -0
- package/dist/generators/mcp-tool-name.js.map +1 -0
- package/dist/generators/mcp.d.ts +46 -1
- package/dist/generators/mcp.d.ts.map +1 -1
- package/dist/generators/mcp.js +105 -53
- package/dist/generators/mcp.js.map +1 -1
- package/dist/generators/tool-schema.d.ts +6 -0
- package/dist/generators/tool-schema.d.ts.map +1 -1
- package/dist/generators/tool-schema.js +8 -3
- package/dist/generators/tool-schema.js.map +1 -1
- package/dist/index.js +3 -1
- package/dist/knowledge.d.ts +2 -0
- package/dist/knowledge.d.ts.map +1 -1
- package/dist/knowledge.js +3 -1
- package/dist/knowledge.js.map +1 -1
- package/dist/manifest/discover-base-classes.js +2 -2
- package/dist/manifest/discover-base-classes.js.map +1 -1
- package/dist/manifest/discover-smrt-packages.d.ts.map +1 -1
- package/dist/manifest/discover-smrt-packages.js +3 -2
- package/dist/manifest/discover-smrt-packages.js.map +1 -1
- package/dist/manifest/generator.d.ts +7 -0
- package/dist/manifest/generator.d.ts.map +1 -1
- package/dist/manifest/generator.js +30 -15
- package/dist/manifest/generator.js.map +1 -1
- package/dist/manifest/manager.d.ts.map +1 -1
- package/dist/manifest/manager.js +6 -2
- package/dist/manifest/manager.js.map +1 -1
- package/dist/manifest/static-manifest.js +1 -1
- package/dist/manifest/static-manifest.js.map +1 -1
- package/dist/manifest/store.js +1 -1
- package/dist/manifest.json +1 -1
- package/dist/migrations/differ.d.ts +2 -0
- package/dist/migrations/differ.d.ts.map +1 -1
- package/dist/migrations/differ.js +35 -5
- package/dist/migrations/differ.js.map +1 -1
- package/dist/node_modules/.pnpm/{brace-expansion@5.0.9 → brace-expansion@5.0.11}/node_modules/brace-expansion/dist/esm/index.js +32 -19
- package/dist/node_modules/.pnpm/brace-expansion@5.0.11/node_modules/brace-expansion/dist/esm/index.js.map +1 -0
- package/dist/node_modules/.pnpm/minimatch@10.2.6/node_modules/minimatch/dist/esm/index.js +1 -1
- package/dist/scanner/types.d.ts +2 -0
- package/dist/scanner/types.d.ts.map +1 -1
- package/dist/scanner/types.js.map +1 -1
- package/dist/scripts/generate-manifest.js +44 -44
- package/dist/scripts/generate-test-manifest.js +49 -2
- package/dist/smrt-knowledge.json +9 -9
- package/dist/vite-plugin/index.d.ts.map +1 -1
- package/dist/vite-plugin/index.js +16 -6
- package/dist/vite-plugin/index.js.map +1 -1
- package/package.json +4 -4
- package/dist/node_modules/.pnpm/brace-expansion@5.0.9/node_modules/brace-expansion/dist/esm/index.js.map +0 -1
|
@@ -183,6 +183,8 @@ export declare class SchemaComparer {
|
|
|
183
183
|
private liveSchemas;
|
|
184
184
|
/** Convergence plan for this run; `null` on non-PostgreSQL engines. */
|
|
185
185
|
private uuidConvergence;
|
|
186
|
+
/** Parents created by this compare() batch, never a standalone compareTable(). */
|
|
187
|
+
private plannedTables;
|
|
186
188
|
/**
|
|
187
189
|
* Rename-pending advisory findings for this `compare()` run, keyed by
|
|
188
190
|
* table name (#2878). `compareTable()` reads from here when it is being
|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BAAsB,kBAAkB,CACtC,EAAE,EAAE,iBAAiB,EACrB,eAAe,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,EACjD,OAAO,GAAE,WAAgB,GACxB,OAAO,CAAC,UAAU,CAAC,CAGrB;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAI9D;AAUD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,EAAE,CAIzD;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,SAAS,YAAY,EAAE,GAAG,MAAM,EAAE,CAU5E"}
|
|
@@ -330,6 +330,8 @@ var SchemaComparer = class SchemaComparer {
|
|
|
330
330
|
liveSchemas = /* @__PURE__ */ new Map();
|
|
331
331
|
/** Convergence plan for this run; `null` on non-PostgreSQL engines. */
|
|
332
332
|
uuidConvergence = null;
|
|
333
|
+
/** Parents created by this compare() batch, never a standalone compareTable(). */
|
|
334
|
+
plannedTables = /* @__PURE__ */ new Map();
|
|
333
335
|
/**
|
|
334
336
|
* Rename-pending advisory findings for this `compare()` run, keyed by
|
|
335
337
|
* table name (#2878). `compareTable()` reads from here when it is being
|
|
@@ -401,6 +403,7 @@ var SchemaComparer = class SchemaComparer {
|
|
|
401
403
|
this.indexPredicateCache = null;
|
|
402
404
|
try {
|
|
403
405
|
const existingTables = await this.getExistingTables();
|
|
406
|
+
this.plannedTables = new Map(Object.entries(manifestSchemas).filter(([name, schema]) => !existingTables.has(name) && schema.tableName === name));
|
|
404
407
|
await this.prefetchLiveSchemas(Object.keys(manifestSchemas).filter((tableName) => existingTables.has(tableName)));
|
|
405
408
|
await this.precomputeIndexPredicates();
|
|
406
409
|
await this.precomputeRenameDataPending(manifestSchemas, existingTables);
|
|
@@ -432,6 +435,7 @@ var SchemaComparer = class SchemaComparer {
|
|
|
432
435
|
}
|
|
433
436
|
return diff;
|
|
434
437
|
} finally {
|
|
438
|
+
this.plannedTables.clear();
|
|
435
439
|
this.renameDataPendingCache = null;
|
|
436
440
|
this.indexPredicateCache = null;
|
|
437
441
|
}
|
|
@@ -722,11 +726,12 @@ var SchemaComparer = class SchemaComparer {
|
|
|
722
726
|
* `undefined` means the pair is compatible (or unknowable) and the ordinary
|
|
723
727
|
* add path applies.
|
|
724
728
|
*/
|
|
725
|
-
async describeForeignKeyTypeBlock(tableName, dbSchema, foreignKey) {
|
|
729
|
+
async describeForeignKeyTypeBlock(tableName, dbSchema, manifest, foreignKey) {
|
|
726
730
|
if (this.engine !== "postgres") return void 0;
|
|
727
731
|
const parentSchema = foreignKey.referencesTable === tableName ? dbSchema : await this.getLiveSchema(foreignKey.referencesTable);
|
|
728
|
-
const
|
|
729
|
-
const
|
|
732
|
+
const declaredType = (type) => type === void 0 ? void 0 : this.ddlStrategy.mapType(isValidSQLDataType(type) ? type : "TEXT");
|
|
733
|
+
const childType = dbSchema.columns[foreignKey.column]?.type ?? declaredType(manifest.columns[foreignKey.column]?.type);
|
|
734
|
+
const parentType = parentSchema?.columns[foreignKey.referencesColumn]?.type ?? declaredType(this.plannedTables.get(foreignKey.referencesTable)?.columns[foreignKey.referencesColumn]?.type);
|
|
730
735
|
if (!childType || !parentType) return void 0;
|
|
731
736
|
const plan = this.uuidConvergence;
|
|
732
737
|
if ((plan?.effectiveType(tableName, foreignKey.column) ?? this.normalizeType(childType)) === (plan?.effectiveType(foreignKey.referencesTable, foreignKey.referencesColumn) ?? this.normalizeType(parentType))) return void 0;
|
|
@@ -816,7 +821,7 @@ var SchemaComparer = class SchemaComparer {
|
|
|
816
821
|
});
|
|
817
822
|
continue;
|
|
818
823
|
}
|
|
819
|
-
const typeBlock = await this.describeForeignKeyTypeBlock(tableName, dbSchema, foreignKey);
|
|
824
|
+
const typeBlock = await this.describeForeignKeyTypeBlock(tableName, dbSchema, manifest, foreignKey);
|
|
820
825
|
if (typeBlock) {
|
|
821
826
|
const textNodes = manifest.columns[foreignKey.column]?.type === "UUID" && manifestSchemas[foreignKey.referencesTable]?.columns[foreignKey.referencesColumn]?.type === "UUID" ? [this.normalizeType(dbSchema.columns[foreignKey.column]?.type ?? "") === "TEXT" ? {
|
|
822
827
|
table: tableName,
|
|
@@ -839,7 +844,32 @@ var SchemaComparer = class SchemaComparer {
|
|
|
839
844
|
});
|
|
840
845
|
continue;
|
|
841
846
|
}
|
|
842
|
-
|
|
847
|
+
const plannedParent = this.liveSchemas.get(foreignKey.referencesTable) ? void 0 : this.plannedTables.get(foreignKey.referencesTable);
|
|
848
|
+
if (plannedParent) {
|
|
849
|
+
const parentColumn = plannedParent.columns[foreignKey.referencesColumn];
|
|
850
|
+
let childEmpty = false;
|
|
851
|
+
if (parentColumn) try {
|
|
852
|
+
const result = await this.db.query(`SELECT 1 FROM ${this.quoteIdentifier(tableName)} LIMIT 1`);
|
|
853
|
+
childEmpty = (Array.isArray(result) ? result : result.rows || []).length === 0;
|
|
854
|
+
} catch (error) {
|
|
855
|
+
throw new Error(`[SchemaComparer] Cannot prove ${tableName} empty for planned parent ${foreignKey.referencesTable}; refusing automatic constraint addition: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
856
|
+
}
|
|
857
|
+
if (!parentColumn || !childEmpty) {
|
|
858
|
+
changes.push({
|
|
859
|
+
type: "add_foreign_key",
|
|
860
|
+
table: tableName,
|
|
861
|
+
name: foreignKeyConstraintName(tableName, foreignKey),
|
|
862
|
+
foreignKey,
|
|
863
|
+
advisory: {
|
|
864
|
+
severity: "warning",
|
|
865
|
+
message: !parentColumn ? `Cannot add foreign key ${tableName}.${foreignKey.column}: planned parent ${foreignKey.referencesTable} has no column ${foreignKey.referencesColumn}. Correct the manifest, then rerun.` : `Cannot add foreign key ${tableName}.${foreignKey.column}: child table is not empty and planned parent ${foreignKey.referencesTable} does not exist yet. Create and populate the parent deliberately, then rerun the orphan preflight.`
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
continue;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
const childColumnExists = Boolean(dbSchema.columns[foreignKey.column]);
|
|
872
|
+
if (!plannedParent && childColumnExists && await this.foreignKeyHasOrphans(tableName, foreignKey, orphanOptions)) {
|
|
843
873
|
changes.push({
|
|
844
874
|
type: "add_foreign_key",
|
|
845
875
|
table: tableName,
|