@inkeep/agents-core 0.41.2 → 0.42.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/dist/api-client/base-client.d.ts +87 -8
- package/dist/api-client/base-client.js +174 -1
- package/dist/api-client/eval-api-client.d.ts +47 -0
- package/dist/api-client/eval-api-client.js +65 -0
- package/dist/api-client/index.d.ts +4 -0
- package/dist/api-client/index.js +5 -0
- package/dist/api-client/manage-api-client.d.ts +34 -0
- package/dist/api-client/manage-api-client.js +104 -0
- package/dist/auth/auth.d.ts +86 -20
- package/dist/auth/auth.js +55 -1
- package/dist/auth/authz/client.d.ts +81 -0
- package/dist/auth/authz/client.js +189 -0
- package/dist/auth/authz/config.d.ts +76 -0
- package/dist/auth/authz/config.js +76 -0
- package/dist/auth/authz/index.d.ts +5 -0
- package/dist/auth/authz/index.js +6 -0
- package/dist/auth/authz/permissions.d.ts +57 -0
- package/dist/auth/authz/permissions.js +83 -0
- package/dist/auth/authz/sync.d.ts +85 -0
- package/dist/auth/authz/sync.js +237 -0
- package/dist/auth/permissions.d.ts +13 -13
- package/dist/auth/permissions.js +2 -181
- package/dist/client-exports.d.ts +8 -3
- package/dist/client-exports.js +3 -2
- package/dist/constants/context-breakdown.d.ts +61 -0
- package/dist/constants/context-breakdown.js +124 -0
- package/dist/constants/otel-attributes.d.ts +4 -0
- package/dist/constants/otel-attributes.js +4 -0
- package/dist/context/ContextConfig.d.ts +2 -2
- package/dist/context/ContextConfig.js +3 -3
- package/dist/context/TemplateEngine.js +0 -1
- package/dist/context/index.d.ts +1 -5
- package/dist/context/index.js +1 -5
- package/dist/credential-stuffer/CredentialStuffer.d.ts +1 -1
- package/dist/data-access/index.d.ts +34 -26
- package/dist/data-access/index.js +34 -26
- package/dist/data-access/manage/agentFull.d.ts +36 -0
- package/dist/data-access/{agentFull.js → manage/agentFull.js} +205 -7
- package/dist/data-access/{agents.d.ts → manage/agents.d.ts} +23 -22
- package/dist/data-access/{agents.js → manage/agents.js} +52 -7
- package/dist/data-access/{artifactComponents.d.ts → manage/artifactComponents.d.ts} +21 -21
- package/dist/data-access/{artifactComponents.js → manage/artifactComponents.js} +5 -5
- package/dist/data-access/{contextConfigs.d.ts → manage/contextConfigs.d.ts} +14 -14
- package/dist/data-access/{contextConfigs.js → manage/contextConfigs.js} +3 -3
- package/dist/data-access/{credentialReferences.d.ts → manage/credentialReferences.d.ts} +17 -17
- package/dist/data-access/{credentialReferences.js → manage/credentialReferences.js} +2 -2
- package/dist/data-access/{dataComponents.d.ts → manage/dataComponents.d.ts} +20 -20
- package/dist/data-access/{dataComponents.js → manage/dataComponents.js} +7 -7
- package/dist/data-access/manage/evalConfig.d.ts +221 -0
- package/dist/data-access/manage/evalConfig.js +275 -0
- package/dist/data-access/{externalAgents.d.ts → manage/externalAgents.d.ts} +16 -16
- package/dist/data-access/{externalAgents.js → manage/externalAgents.js} +2 -2
- package/dist/data-access/{functionTools.d.ts → manage/functionTools.d.ts} +65 -15
- package/dist/data-access/{functionTools.js → manage/functionTools.js} +90 -8
- package/dist/data-access/{functions.d.ts → manage/functions.d.ts} +9 -9
- package/dist/data-access/{functions.js → manage/functions.js} +3 -3
- package/dist/data-access/manage/projectFull.d.ts +38 -0
- package/dist/data-access/{projectFull.js → manage/projectFull.js} +64 -65
- package/dist/data-access/manage/projectLifecycle.d.ts +119 -0
- package/dist/data-access/manage/projectLifecycle.js +234 -0
- package/dist/data-access/manage/projects.d.ts +75 -0
- package/dist/data-access/{projects.js → manage/projects.js} +15 -16
- package/dist/data-access/{subAgentExternalAgentRelations.d.ts → manage/subAgentExternalAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentExternalAgentRelations.js → manage/subAgentExternalAgentRelations.js} +2 -2
- package/dist/data-access/{subAgentRelations.d.ts → manage/subAgentRelations.d.ts} +29 -29
- package/dist/data-access/{subAgentRelations.js → manage/subAgentRelations.js} +3 -3
- package/dist/data-access/{subAgentTeamAgentRelations.d.ts → manage/subAgentTeamAgentRelations.d.ts} +19 -19
- package/dist/data-access/{subAgentTeamAgentRelations.js → manage/subAgentTeamAgentRelations.js} +2 -2
- package/dist/data-access/{subAgents.d.ts → manage/subAgents.d.ts} +13 -13
- package/dist/data-access/{subAgents.js → manage/subAgents.js} +4 -4
- package/dist/data-access/{tools.d.ts → manage/tools.d.ts} +26 -19
- package/dist/data-access/{tools.js → manage/tools.js} +57 -35
- package/dist/data-access/manage/triggers.d.ts +80 -0
- package/dist/data-access/manage/triggers.js +81 -0
- package/dist/data-access/{apiKeys.d.ts → runtime/apiKeys.d.ts} +17 -17
- package/dist/data-access/{apiKeys.js → runtime/apiKeys.js} +3 -3
- package/dist/data-access/runtime/cascade-delete.d.ts +77 -0
- package/dist/data-access/runtime/cascade-delete.js +111 -0
- package/dist/data-access/{contextCache.d.ts → runtime/contextCache.d.ts} +13 -13
- package/dist/data-access/{contextCache.js → runtime/contextCache.js} +5 -5
- package/dist/data-access/{conversations.d.ts → runtime/conversations.d.ts} +68 -19
- package/dist/data-access/{conversations.js → runtime/conversations.js} +13 -7
- package/dist/data-access/runtime/evalRuns.d.ts +120 -0
- package/dist/data-access/runtime/evalRuns.js +168 -0
- package/dist/data-access/{ledgerArtifacts.d.ts → runtime/ledgerArtifacts.d.ts} +13 -13
- package/dist/data-access/{ledgerArtifacts.js → runtime/ledgerArtifacts.js} +3 -3
- package/dist/data-access/{messages.d.ts → runtime/messages.d.ts} +15 -15
- package/dist/data-access/{messages.js → runtime/messages.js} +2 -2
- package/dist/data-access/{organizations.d.ts → runtime/organizations.d.ts} +16 -7
- package/dist/data-access/{organizations.js → runtime/organizations.js} +15 -3
- package/dist/data-access/runtime/projects.d.ts +62 -0
- package/dist/data-access/runtime/projects.js +90 -0
- package/dist/data-access/runtime/tasks.d.ts +55 -0
- package/dist/data-access/{tasks.js → runtime/tasks.js} +2 -2
- package/dist/data-access/runtime/triggerInvocations.d.ts +62 -0
- package/dist/data-access/runtime/triggerInvocations.js +54 -0
- package/dist/data-access/runtime/users.d.ts +19 -0
- package/dist/data-access/{users.js → runtime/users.js} +2 -2
- package/dist/data-access/validation.d.ts +4 -4
- package/dist/data-access/validation.js +1 -1
- package/dist/db/clean.d.ts +8 -4
- package/dist/db/clean.js +14 -105
- package/dist/db/delete.d.ts +1 -1
- package/dist/db/delete.js +7 -10
- package/dist/db/manage/dolt-cleanup.d.ts +51 -0
- package/dist/db/manage/dolt-cleanup.js +132 -0
- package/dist/db/manage/manage-client.d.ts +26 -0
- package/dist/db/manage/manage-client.js +68 -0
- package/dist/db/{schema.d.ts → manage/manage-schema.d.ts} +1459 -1285
- package/dist/db/{schema.js → manage/manage-schema.js} +433 -341
- package/dist/db/manage/test-manage-client.d.ts +27 -0
- package/dist/db/manage/test-manage-client.js +68 -0
- package/dist/db/runtime/runtime-client.d.ts +20 -0
- package/dist/db/runtime/runtime-client.js +30 -0
- package/dist/db/runtime/runtime-schema.d.ts +2834 -0
- package/dist/db/runtime/runtime-schema.js +483 -0
- package/dist/db/runtime/test-runtime-client.d.ts +27 -0
- package/dist/db/{test-client.js → runtime/test-runtime-client.js} +11 -25
- package/dist/dolt/branch.d.ts +62 -0
- package/dist/dolt/branch.js +82 -0
- package/dist/dolt/branches-api.d.ts +108 -0
- package/dist/dolt/branches-api.js +162 -0
- package/dist/dolt/commit.d.ts +94 -0
- package/dist/dolt/commit.js +103 -0
- package/dist/dolt/diff.d.ts +27 -0
- package/dist/dolt/diff.js +21 -0
- package/dist/dolt/index.d.ts +10 -0
- package/dist/dolt/index.js +11 -0
- package/dist/dolt/merge.d.ts +63 -0
- package/dist/dolt/merge.js +81 -0
- package/dist/dolt/migrate-all-branches.d.ts +4 -0
- package/dist/dolt/migrate-all-branches.js +78 -0
- package/dist/dolt/migrate-dolt.d.ts +1 -0
- package/dist/dolt/migrate-dolt.js +22 -0
- package/dist/dolt/ref-helpers.d.ts +19 -0
- package/dist/dolt/ref-helpers.js +65 -0
- package/dist/dolt/ref-middleware.d.ts +82 -0
- package/dist/dolt/ref-middleware.js +217 -0
- package/dist/dolt/ref-scope.d.ts +101 -0
- package/dist/dolt/ref-scope.js +231 -0
- package/dist/dolt/schema-sync.d.ts +134 -0
- package/dist/dolt/schema-sync.js +246 -0
- package/dist/env.d.ts +6 -4
- package/dist/env.js +3 -2
- package/dist/index.d.ts +71 -44
- package/dist/index.js +74 -47
- package/dist/types/entities.d.ts +81 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/utility.d.ts +45 -4
- package/dist/utils/JsonTransformer.d.ts +44 -0
- package/dist/utils/JsonTransformer.js +112 -0
- package/dist/utils/apiKeys.d.ts +5 -1
- package/dist/utils/apiKeys.js +11 -1
- package/dist/utils/colors.d.ts +34 -0
- package/dist/utils/colors.js +49 -0
- package/dist/utils/credential-store-utils.d.ts +1 -1
- package/dist/utils/format-messages.d.ts +1 -1
- package/dist/utils/index.d.ts +7 -3
- package/dist/utils/index.js +7 -3
- package/dist/utils/internal-service-auth.d.ts +79 -0
- package/dist/utils/internal-service-auth.js +140 -0
- package/dist/utils/jwt-helpers.d.ts +56 -0
- package/dist/utils/jwt-helpers.js +90 -0
- package/dist/utils/service-token-auth.d.ts +9 -27
- package/dist/utils/service-token-auth.js +48 -96
- package/dist/utils/template-interpolation.d.ts +22 -0
- package/dist/utils/template-interpolation.js +62 -0
- package/dist/utils/third-party-mcp-servers/composio-client.js +23 -23
- package/dist/utils/trigger-auth.d.ts +62 -0
- package/dist/utils/trigger-auth.js +125 -0
- package/dist/validation/agentFull.js +2 -4
- package/dist/validation/dolt-schemas.d.ts +49 -0
- package/dist/validation/dolt-schemas.js +44 -0
- package/dist/validation/drizzle-schema-helpers.d.ts +4 -26
- package/dist/validation/drizzle-schema-helpers.js +5 -151
- package/dist/validation/index.d.ts +4 -3
- package/dist/validation/index.js +3 -2
- package/dist/validation/schemas.d.ts +17647 -4789
- package/dist/validation/schemas.js +328 -11
- package/drizzle/manage/0000_tearful_rhodey.sql +414 -0
- package/drizzle/manage/0001_broken_wendell_vaughn.sql +19 -0
- package/drizzle/manage/0002_bent_sunfire.sql +1 -0
- package/drizzle/manage/meta/0000_snapshot.json +2987 -0
- package/drizzle/manage/meta/0001_snapshot.json +3115 -0
- package/drizzle/manage/meta/0002_snapshot.json +3115 -0
- package/drizzle/manage/meta/_journal.json +27 -0
- package/drizzle/runtime/0008_silly_preak.sql +127 -0
- package/drizzle/runtime/0009_freezing_leo.sql +17 -0
- package/drizzle/runtime/meta/0008_snapshot.json +2263 -0
- package/drizzle/runtime/meta/0009_snapshot.json +2397 -0
- package/drizzle/{meta → runtime/meta}/_journal.json +14 -0
- package/package.json +48 -15
- package/dist/context/ContextFetcher.d.ts +0 -73
- package/dist/context/ContextFetcher.js +0 -291
- package/dist/context/ContextResolver.d.ts +0 -60
- package/dist/context/ContextResolver.js +0 -278
- package/dist/context/context.d.ts +0 -27
- package/dist/context/context.js +0 -128
- package/dist/context/contextCache.d.ts +0 -58
- package/dist/context/contextCache.js +0 -177
- package/dist/data-access/agentFull.d.ts +0 -33
- package/dist/data-access/projectFull.d.ts +0 -32
- package/dist/data-access/projects.d.ts +0 -71
- package/dist/data-access/tasks.d.ts +0 -45
- package/dist/data-access/users.d.ts +0 -19
- package/dist/db/client.d.ts +0 -20
- package/dist/db/client.js +0 -28
- package/dist/db/test-client.d.ts +0 -31
- package/dist/middleware/contextValidation.d.ts +0 -46
- package/dist/middleware/contextValidation.js +0 -280
- package/dist/middleware/index.d.ts +0 -2
- package/dist/middleware/index.js +0 -3
- package/dist/utils/execution.d.ts +0 -22
- package/dist/utils/execution.js +0 -25
- /package/drizzle/{0000_exotic_mysterio.sql → runtime/0000_exotic_mysterio.sql} +0 -0
- /package/drizzle/{0001_calm_sheva_callister.sql → runtime/0001_calm_sheva_callister.sql} +0 -0
- /package/drizzle/{0002_puzzling_goblin_queen.sql → runtime/0002_puzzling_goblin_queen.sql} +0 -0
- /package/drizzle/{0003_sweet_human_robot.sql → runtime/0003_sweet_human_robot.sql} +0 -0
- /package/drizzle/{0004_cuddly_shooting_star.sql → runtime/0004_cuddly_shooting_star.sql} +0 -0
- /package/drizzle/{0005_reflective_starfox.sql → runtime/0005_reflective_starfox.sql} +0 -0
- /package/drizzle/{0006_stale_thaddeus_ross.sql → runtime/0006_stale_thaddeus_ross.sql} +0 -0
- /package/drizzle/{0007_slim_karma.sql → runtime/0007_slim_karma.sql} +0 -0
- /package/drizzle/{meta → runtime/meta}/0000_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0001_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0003_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0005_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0006_snapshot.json +0 -0
- /package/drizzle/{meta → runtime/meta}/0007_snapshot.json +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { doltHashOf } from "./commit.js";
|
|
2
|
+
import { resolveRef } from "./ref-helpers.js";
|
|
3
|
+
import { sql } from "drizzle-orm";
|
|
4
|
+
import { logger } from "@composio/core";
|
|
5
|
+
|
|
6
|
+
//#region src/dolt/branch.ts
|
|
7
|
+
/**
|
|
8
|
+
* Create a new branch
|
|
9
|
+
*/
|
|
10
|
+
const doltBranch = (db) => async (params) => {
|
|
11
|
+
if (params.startPoint) {
|
|
12
|
+
const startPointHash = await doltHashOf(db)({ revision: params.startPoint });
|
|
13
|
+
await db.execute(sql.raw(`SELECT DOLT_BRANCH('${params.name}', '${startPointHash}')`));
|
|
14
|
+
} else await db.execute(sql.raw(`SELECT DOLT_BRANCH('${params.name}')`));
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Delete a branch
|
|
18
|
+
*/
|
|
19
|
+
const doltDeleteBranch = (db) => async (params) => {
|
|
20
|
+
const flag = params.force ? "-D" : "-d";
|
|
21
|
+
await db.execute(sql.raw(`SELECT DOLT_BRANCH('${flag}', '${params.name}')`));
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Rename a branch
|
|
25
|
+
*/
|
|
26
|
+
const doltRenameBranch = (db) => async (params) => {
|
|
27
|
+
await db.execute(sql.raw(`SELECT DOLT_BRANCH('-m', '${params.oldName}', '${params.newName}')`));
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* List all branches
|
|
31
|
+
*/
|
|
32
|
+
const doltListBranches = (db) => async () => {
|
|
33
|
+
return (await db.execute(sql`SELECT * FROM dolt_branches`)).rows;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Check if a branch exists
|
|
37
|
+
*/
|
|
38
|
+
const doltBranchExists = (db) => async (params) => {
|
|
39
|
+
return (await db.execute(sql.raw(`SELECT * FROM dolt_branches WHERE name = '${params.name}'`))).rows.length > 0;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Checkout a branch or create and checkout a new branch
|
|
43
|
+
*/
|
|
44
|
+
const doltCheckout = (db) => async (params) => {
|
|
45
|
+
params.create ? await db.execute(sql.raw(`SELECT DOLT_CHECKOUT('-b', '${params.branch}')`)) : await db.execute(sql.raw(`SELECT DOLT_CHECKOUT('${params.branch}')`));
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Get the currently active branch
|
|
49
|
+
*/
|
|
50
|
+
const doltActiveBranch = (db) => async () => {
|
|
51
|
+
return (await db.execute(sql`SELECT ACTIVE_BRANCH() as branch`)).rows[0]?.branch;
|
|
52
|
+
};
|
|
53
|
+
const doltGetBranchNamespace = (scopes) => () => {
|
|
54
|
+
return `${scopes.tenantId}_${scopes.projectId}_${scopes.branchName}`;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Create a branch if it doesn't exist, handling race conditions gracefully.
|
|
58
|
+
* If multiple concurrent requests try to create the same branch, only one will succeed.
|
|
59
|
+
*/
|
|
60
|
+
const ensureBranchExists = async (db, branchName) => {
|
|
61
|
+
if (await resolveRef(db)(branchName)) {
|
|
62
|
+
logger.debug({ branchName }, "Branch already exists, skipping creation");
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
await doltBranch(db)({ name: branchName });
|
|
67
|
+
logger.debug({ branchName }, "Branch created successfully");
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (await resolveRef(db)(branchName)) {
|
|
70
|
+
logger.debug({ branchName }, "Branch creation failed but branch exists (concurrent creation), continuing");
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
logger.error({
|
|
74
|
+
branchName,
|
|
75
|
+
error
|
|
76
|
+
}, "Branch creation failed and branch does not exist");
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { doltActiveBranch, doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches, doltRenameBranch, ensureBranchExists };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { BranchInfo } from "../validation/dolt-schemas.js";
|
|
2
|
+
import { AgentScopeConfig, ProjectScopeConfig } from "../types/utility.js";
|
|
3
|
+
import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
|
|
4
|
+
|
|
5
|
+
//#region src/dolt/branches-api.d.ts
|
|
6
|
+
declare const MAIN_BRANCH_SUFFIX = "main";
|
|
7
|
+
/**
|
|
8
|
+
* Get the tenant-scoped main branch name
|
|
9
|
+
*/
|
|
10
|
+
declare const getTenantMainBranch: (tenantId: string) => string;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a branch name (without tenant/project prefix) is a protected branch
|
|
13
|
+
*/
|
|
14
|
+
declare const isProtectedBranchName: (branchName: string) => boolean;
|
|
15
|
+
type CreateBranchParams = {
|
|
16
|
+
tenantId: string;
|
|
17
|
+
projectId: string;
|
|
18
|
+
name: string;
|
|
19
|
+
/** Branch to create from. Defaults to tenant main branch. */
|
|
20
|
+
from?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether to sync schema on the source branch before creating.
|
|
23
|
+
* This ensures the new branch starts with the latest schema from main.
|
|
24
|
+
* Default: true
|
|
25
|
+
*/
|
|
26
|
+
syncSchemaOnSource?: boolean;
|
|
27
|
+
};
|
|
28
|
+
type DeleteBranchParams = {
|
|
29
|
+
tenantId: string;
|
|
30
|
+
projectId: string;
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
type GetBranchParams = {
|
|
34
|
+
tenantId: string;
|
|
35
|
+
projectId: string;
|
|
36
|
+
name: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Parameters for checking out a branch with optional schema sync
|
|
40
|
+
*/
|
|
41
|
+
type CheckoutBranchParams = {
|
|
42
|
+
/** The full branch name (e.g., "tenant1_project1_main") */
|
|
43
|
+
branchName: string;
|
|
44
|
+
/** Whether to sync schema from main after checkout. Default: true */
|
|
45
|
+
syncSchema?: boolean;
|
|
46
|
+
/** Whether to auto-commit pending changes before schema sync. Default: false */
|
|
47
|
+
autoCommitPending?: boolean;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Result of a branch checkout operation
|
|
51
|
+
*/
|
|
52
|
+
type CheckoutBranchResult = {
|
|
53
|
+
/** The full branch name that was checked out */
|
|
54
|
+
branchName: string;
|
|
55
|
+
/** The commit hash of the branch after checkout (and potential schema sync) */
|
|
56
|
+
hash: string;
|
|
57
|
+
/** Result of the schema sync operation */
|
|
58
|
+
schemaSync: {
|
|
59
|
+
/** Whether schema sync was performed */
|
|
60
|
+
performed: boolean;
|
|
61
|
+
/** Whether there were schema differences */
|
|
62
|
+
hadDifferences: boolean;
|
|
63
|
+
/** Error message if schema sync failed */
|
|
64
|
+
error?: string;
|
|
65
|
+
/** The merge commit hash if schema was synced */
|
|
66
|
+
mergeCommitHash?: string;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Checkout a branch with optional schema synchronization from main.
|
|
71
|
+
*
|
|
72
|
+
* This function:
|
|
73
|
+
* 1. Checks out the specified branch
|
|
74
|
+
* 2. If syncSchema is true (default), checks for schema differences from main
|
|
75
|
+
* 3. If differences exist, merges schema from main into the branch
|
|
76
|
+
*
|
|
77
|
+
* @param db - Database client
|
|
78
|
+
* @returns Function that takes checkout params and returns checkout result
|
|
79
|
+
*/
|
|
80
|
+
declare const checkoutBranch: (db: AgentsManageDatabaseClient) => (params: CheckoutBranchParams) => Promise<CheckoutBranchResult>;
|
|
81
|
+
/**
|
|
82
|
+
* Create a new branch with optional schema synchronization.
|
|
83
|
+
*
|
|
84
|
+
* This function:
|
|
85
|
+
* 1. Optionally syncs schema on the source branch from main (default: true)
|
|
86
|
+
* 2. Creates a new branch from the source branch
|
|
87
|
+
*
|
|
88
|
+
* By syncing schema on the source branch first, we ensure the new branch
|
|
89
|
+
* starts with the latest schema, avoiding schema conflicts later.
|
|
90
|
+
*/
|
|
91
|
+
declare const createBranch: (db: AgentsManageDatabaseClient) => (params: CreateBranchParams) => Promise<BranchInfo>;
|
|
92
|
+
/**
|
|
93
|
+
* Delete a branch
|
|
94
|
+
*/
|
|
95
|
+
declare const deleteBranch: (db: AgentsManageDatabaseClient) => (params: DeleteBranchParams) => Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Get a single branch
|
|
98
|
+
*/
|
|
99
|
+
declare const getBranch: (db: AgentsManageDatabaseClient) => (params: GetBranchParams) => Promise<BranchInfo | null>;
|
|
100
|
+
/**
|
|
101
|
+
* List all branches for a project
|
|
102
|
+
* Returns only project-specific branches (e.g., {tenantId}_{projectId}_main, {tenantId}_{projectId}_feature-x)
|
|
103
|
+
* Does NOT include the tenant_main branch as that's an organizational branch, not a project development branch
|
|
104
|
+
*/
|
|
105
|
+
declare const listBranches: (db: AgentsManageDatabaseClient) => (params: ProjectScopeConfig) => Promise<BranchInfo[]>;
|
|
106
|
+
declare const listBranchesForAgent: (db: AgentsManageDatabaseClient) => (params: AgentScopeConfig) => Promise<BranchInfo[]>;
|
|
107
|
+
//#endregion
|
|
108
|
+
export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent };
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { SCHEMA_SOURCE_BRANCH, ensureSchemaSync, getSchemaDiff, syncSchemaFromMain } from "./schema-sync.js";
|
|
2
|
+
import { doltBranch, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches } from "./branch.js";
|
|
3
|
+
import { sql } from "drizzle-orm";
|
|
4
|
+
|
|
5
|
+
//#region src/dolt/branches-api.ts
|
|
6
|
+
const MAIN_BRANCH_SUFFIX = "main";
|
|
7
|
+
/**
|
|
8
|
+
* Get the tenant-scoped main branch name
|
|
9
|
+
*/
|
|
10
|
+
const getTenantMainBranch = (tenantId) => `${tenantId}_${MAIN_BRANCH_SUFFIX}`;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a branch name (without tenant/project prefix) is a protected branch
|
|
13
|
+
*/
|
|
14
|
+
const isProtectedBranchName = (branchName) => {
|
|
15
|
+
return branchName === MAIN_BRANCH_SUFFIX;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Checkout a branch with optional schema synchronization from main.
|
|
19
|
+
*
|
|
20
|
+
* This function:
|
|
21
|
+
* 1. Checks out the specified branch
|
|
22
|
+
* 2. If syncSchema is true (default), checks for schema differences from main
|
|
23
|
+
* 3. If differences exist, merges schema from main into the branch
|
|
24
|
+
*
|
|
25
|
+
* @param db - Database client
|
|
26
|
+
* @returns Function that takes checkout params and returns checkout result
|
|
27
|
+
*/
|
|
28
|
+
const checkoutBranch = (db) => async (params) => {
|
|
29
|
+
const { branchName, syncSchema = true, autoCommitPending = false } = params;
|
|
30
|
+
const branch = (await doltListBranches(db)()).find((b) => b.name === branchName);
|
|
31
|
+
if (!branch) throw new Error(`Branch '${branchName}' not found`);
|
|
32
|
+
await doltCheckout(db)({ branch: branchName });
|
|
33
|
+
let schemaSyncResult = {
|
|
34
|
+
synced: false,
|
|
35
|
+
hadDifferences: false
|
|
36
|
+
};
|
|
37
|
+
if (syncSchema && branchName !== SCHEMA_SOURCE_BRANCH) schemaSyncResult = await ensureSchemaSync(db)({
|
|
38
|
+
autoSync: true,
|
|
39
|
+
autoCommitPending
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
branchName,
|
|
43
|
+
hash: (await doltListBranches(db)()).find((b) => b.name === branchName)?.hash ?? branch.hash,
|
|
44
|
+
schemaSync: {
|
|
45
|
+
performed: schemaSyncResult.synced,
|
|
46
|
+
hadDifferences: schemaSyncResult.hadDifferences,
|
|
47
|
+
error: schemaSyncResult.error,
|
|
48
|
+
mergeCommitHash: schemaSyncResult.mergeCommitHash
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Create a new branch with optional schema synchronization.
|
|
54
|
+
*
|
|
55
|
+
* This function:
|
|
56
|
+
* 1. Optionally syncs schema on the source branch from main (default: true)
|
|
57
|
+
* 2. Creates a new branch from the source branch
|
|
58
|
+
*
|
|
59
|
+
* By syncing schema on the source branch first, we ensure the new branch
|
|
60
|
+
* starts with the latest schema, avoiding schema conflicts later.
|
|
61
|
+
*/
|
|
62
|
+
const createBranch = (db) => async (params) => {
|
|
63
|
+
const { tenantId, projectId, name, from, syncSchemaOnSource = true } = params;
|
|
64
|
+
if (!name || name.trim() === "") throw new Error("Branch name cannot be empty");
|
|
65
|
+
const fullName = doltGetBranchNamespace({
|
|
66
|
+
tenantId,
|
|
67
|
+
projectId,
|
|
68
|
+
branchName: name
|
|
69
|
+
})();
|
|
70
|
+
if ((await doltListBranches(db)()).some((b) => b.name === fullName)) throw new Error(`Branch '${name}' already exists`);
|
|
71
|
+
let fromFullBranchName;
|
|
72
|
+
if (from && from !== MAIN_BRANCH_SUFFIX) fromFullBranchName = doltGetBranchNamespace({
|
|
73
|
+
tenantId,
|
|
74
|
+
projectId,
|
|
75
|
+
branchName: from
|
|
76
|
+
})();
|
|
77
|
+
else fromFullBranchName = getTenantMainBranch(tenantId);
|
|
78
|
+
if (syncSchemaOnSource && fromFullBranchName !== SCHEMA_SOURCE_BRANCH) {
|
|
79
|
+
if ((await getSchemaDiff(db)(fromFullBranchName)).length > 0) {
|
|
80
|
+
await doltCheckout(db)({ branch: fromFullBranchName });
|
|
81
|
+
const syncResult = await syncSchemaFromMain(db)({ autoCommitPending: true });
|
|
82
|
+
if (syncResult.error && !syncResult.synced) throw new Error(`Failed to sync schema on source branch '${fromFullBranchName}': ${syncResult.error}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
await doltBranch(db)({
|
|
86
|
+
name: fullName,
|
|
87
|
+
startPoint: fromFullBranchName
|
|
88
|
+
});
|
|
89
|
+
const newBranch = (await doltListBranches(db)()).find((b) => b.name === fullName);
|
|
90
|
+
if (!newBranch) throw new Error("Failed to create branch");
|
|
91
|
+
return {
|
|
92
|
+
baseName: name,
|
|
93
|
+
fullName,
|
|
94
|
+
hash: newBranch.hash
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Delete a branch
|
|
99
|
+
*/
|
|
100
|
+
const deleteBranch = (db) => async (params) => {
|
|
101
|
+
const { tenantId, projectId, name } = params;
|
|
102
|
+
if (isProtectedBranchName(name)) throw new Error(`Cannot delete protected branch '${name}'`);
|
|
103
|
+
const fullName = doltGetBranchNamespace({
|
|
104
|
+
tenantId,
|
|
105
|
+
projectId,
|
|
106
|
+
branchName: name
|
|
107
|
+
})();
|
|
108
|
+
if (!(await doltListBranches(db)()).some((b) => b.name === fullName)) throw new Error(`Branch '${name}' not found`);
|
|
109
|
+
await doltDeleteBranch(db)({ name: fullName });
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Get a single branch
|
|
113
|
+
*/
|
|
114
|
+
const getBranch = (db) => async (params) => {
|
|
115
|
+
const { tenantId, projectId, name } = params;
|
|
116
|
+
const fullName = doltGetBranchNamespace({
|
|
117
|
+
tenantId,
|
|
118
|
+
projectId,
|
|
119
|
+
branchName: name
|
|
120
|
+
})();
|
|
121
|
+
const branch = (await doltListBranches(db)()).find((b) => b.name === fullName);
|
|
122
|
+
if (!branch) return null;
|
|
123
|
+
return {
|
|
124
|
+
baseName: name,
|
|
125
|
+
fullName,
|
|
126
|
+
hash: branch.hash
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* List all branches for a project
|
|
131
|
+
* Returns only project-specific branches (e.g., {tenantId}_{projectId}_main, {tenantId}_{projectId}_feature-x)
|
|
132
|
+
* Does NOT include the tenant_main branch as that's an organizational branch, not a project development branch
|
|
133
|
+
*/
|
|
134
|
+
const listBranches = (db) => async (params) => {
|
|
135
|
+
const { tenantId, projectId } = params;
|
|
136
|
+
const allBranches = await doltListBranches(db)();
|
|
137
|
+
const prefix = `${tenantId}_${projectId}_`;
|
|
138
|
+
return allBranches.filter((b) => b.name.startsWith(prefix)).map((b) => ({
|
|
139
|
+
baseName: b.name.substring(prefix.length),
|
|
140
|
+
fullName: b.name,
|
|
141
|
+
hash: b.hash
|
|
142
|
+
}));
|
|
143
|
+
};
|
|
144
|
+
const listBranchesForAgent = (db) => async (params) => {
|
|
145
|
+
const { tenantId, projectId, agentId } = params;
|
|
146
|
+
const allBranches = await listBranches(db)({
|
|
147
|
+
tenantId,
|
|
148
|
+
projectId
|
|
149
|
+
});
|
|
150
|
+
const branches = [];
|
|
151
|
+
for (const branch of allBranches) try {
|
|
152
|
+
const result = await db.execute(sql.raw(`SELECT id FROM agent AS OF '${branch.fullName}' WHERE id = '${agentId}'`));
|
|
153
|
+
console.log(result);
|
|
154
|
+
if (result.rows.length > 0) branches.push(branch);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.debug(`Failed to query agent ${agentId} on branch ${branch.fullName}:`, error);
|
|
157
|
+
}
|
|
158
|
+
return branches;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
//#endregion
|
|
162
|
+
export { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/dolt/commit.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Stage all changes for commit
|
|
7
|
+
* params: { tables?: string[] }
|
|
8
|
+
* tables: array of table names to stage
|
|
9
|
+
* if no tables are specified, all changes are staged
|
|
10
|
+
*/
|
|
11
|
+
declare const doltAdd: (db: AgentsManageDatabaseClient) => (params?: {
|
|
12
|
+
tables?: string[];
|
|
13
|
+
}) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Commit staged changes
|
|
16
|
+
* params: { message: string; author?: { name: string; email: string } }
|
|
17
|
+
* message: commit message
|
|
18
|
+
* author: commit author
|
|
19
|
+
* author is optional, if not provided, the commit will be committed with the default author
|
|
20
|
+
*/
|
|
21
|
+
declare const doltCommit: (db: AgentsManageDatabaseClient) => (params: {
|
|
22
|
+
message: string;
|
|
23
|
+
author?: {
|
|
24
|
+
name: string;
|
|
25
|
+
email: string;
|
|
26
|
+
};
|
|
27
|
+
}) => Promise<string>;
|
|
28
|
+
declare const doltAddAndCommit: (db: AgentsManageDatabaseClient) => (params: {
|
|
29
|
+
message: string;
|
|
30
|
+
author?: {
|
|
31
|
+
name: string;
|
|
32
|
+
email: string;
|
|
33
|
+
};
|
|
34
|
+
}) => Promise<string>;
|
|
35
|
+
/**
|
|
36
|
+
* Get commit log
|
|
37
|
+
*/
|
|
38
|
+
declare const doltLog: (db: AgentsManageDatabaseClient) => (params?: {
|
|
39
|
+
revision?: string;
|
|
40
|
+
limit?: number;
|
|
41
|
+
}) => Promise<{
|
|
42
|
+
commit_hash: string;
|
|
43
|
+
committer: string;
|
|
44
|
+
email: string;
|
|
45
|
+
date: Date;
|
|
46
|
+
message: string;
|
|
47
|
+
}[]>;
|
|
48
|
+
/**
|
|
49
|
+
* Reset staged or working changes
|
|
50
|
+
*/
|
|
51
|
+
declare const doltReset: (db: AgentsManageDatabaseClient) => (params?: {
|
|
52
|
+
hard?: boolean;
|
|
53
|
+
tables?: string[];
|
|
54
|
+
}) => Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Get status of working changes
|
|
57
|
+
*/
|
|
58
|
+
declare const doltStatus: (db: AgentsManageDatabaseClient) => () => Promise<{
|
|
59
|
+
table_name: string;
|
|
60
|
+
staged: boolean;
|
|
61
|
+
status: string;
|
|
62
|
+
}[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get hash of a commit/branch
|
|
65
|
+
*/
|
|
66
|
+
declare const doltHashOf: (db: AgentsManageDatabaseClient) => (params: {
|
|
67
|
+
revision: string;
|
|
68
|
+
}) => Promise<string>;
|
|
69
|
+
/**
|
|
70
|
+
* Create a tag
|
|
71
|
+
*/
|
|
72
|
+
declare const doltTag: (db: AgentsManageDatabaseClient) => (params: {
|
|
73
|
+
name: string;
|
|
74
|
+
message?: string;
|
|
75
|
+
revision?: string;
|
|
76
|
+
}) => Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Delete a tag
|
|
79
|
+
*/
|
|
80
|
+
declare const doltDeleteTag: (db: AgentsManageDatabaseClient) => (params: {
|
|
81
|
+
name: string;
|
|
82
|
+
}) => Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* List all tags
|
|
85
|
+
*/
|
|
86
|
+
declare const doltListTags: (db: AgentsManageDatabaseClient) => () => Promise<{
|
|
87
|
+
tag_name: string;
|
|
88
|
+
tag_hash: string;
|
|
89
|
+
tagger: string;
|
|
90
|
+
date: Date;
|
|
91
|
+
message: string;
|
|
92
|
+
}[]>;
|
|
93
|
+
//#endregion
|
|
94
|
+
export { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { doltListBranches } from "./branch.js";
|
|
2
|
+
import { sql } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
//#region src/dolt/commit.ts
|
|
5
|
+
/**
|
|
6
|
+
* Stage all changes for commit
|
|
7
|
+
* params: { tables?: string[] }
|
|
8
|
+
* tables: array of table names to stage
|
|
9
|
+
* if no tables are specified, all changes are staged
|
|
10
|
+
*/
|
|
11
|
+
const doltAdd = (db) => async (params = {}) => {
|
|
12
|
+
if (!params.tables || params.tables.length === 0) await db.execute(sql`SELECT DOLT_ADD('-A')`);
|
|
13
|
+
else {
|
|
14
|
+
const tableParams = params.tables.map((t) => `'${t}'`).join(", ");
|
|
15
|
+
console.log(tableParams);
|
|
16
|
+
await db.execute(sql.raw(`SELECT DOLT_ADD(${tableParams})`));
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Commit staged changes
|
|
21
|
+
* params: { message: string; author?: { name: string; email: string } }
|
|
22
|
+
* message: commit message
|
|
23
|
+
* author: commit author
|
|
24
|
+
* author is optional, if not provided, the commit will be committed with the default author
|
|
25
|
+
*/
|
|
26
|
+
const doltCommit = (db) => async (params) => {
|
|
27
|
+
const args = [];
|
|
28
|
+
args.push("'-a'");
|
|
29
|
+
args.push("'-m'", `'${params.message.replace(/'/g, "''")}'`);
|
|
30
|
+
if (params.author) args.push("'--author'", `'${params.author.name} <${params.author.email}>'`);
|
|
31
|
+
await db.execute(sql.raw(`SELECT DOLT_COMMIT(${args.join(", ")})`));
|
|
32
|
+
return "Commit successful";
|
|
33
|
+
};
|
|
34
|
+
const doltAddAndCommit = (db) => async (params) => {
|
|
35
|
+
await doltAdd(db)({});
|
|
36
|
+
return doltCommit(db)(params);
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Get commit log
|
|
40
|
+
*/
|
|
41
|
+
const doltLog = (db) => async (params) => {
|
|
42
|
+
let query = sql`SELECT * FROM DOLT_LOG()`;
|
|
43
|
+
if (params?.revision) query = sql.raw(`SELECT * FROM DOLT_LOG('${params.revision}')`);
|
|
44
|
+
let rows = (await db.execute(query)).rows;
|
|
45
|
+
if (params?.limit) rows = rows.slice(0, params.limit);
|
|
46
|
+
return rows;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Reset staged or working changes
|
|
50
|
+
*/
|
|
51
|
+
const doltReset = (db) => async (params) => {
|
|
52
|
+
if (params?.hard) await db.execute(sql`SELECT DOLT_RESET('--hard')`);
|
|
53
|
+
else if (params?.tables && params.tables.length > 0) {
|
|
54
|
+
const tableParams = params.tables.map((t) => `'${t}'`).join(", ");
|
|
55
|
+
await db.execute(sql.raw(`SELECT DOLT_RESET(${tableParams})`));
|
|
56
|
+
} else await db.execute(sql`SELECT DOLT_RESET()`);
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Get status of working changes
|
|
60
|
+
*/
|
|
61
|
+
const doltStatus = (db) => async () => {
|
|
62
|
+
return (await db.execute(sql`SELECT * FROM dolt_status`)).rows;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Get hash of a commit/branch
|
|
66
|
+
*/
|
|
67
|
+
const doltHashOf = (db) => async (params) => {
|
|
68
|
+
if (/^[0-9a-v]{32}$/.test(params.revision)) return params.revision;
|
|
69
|
+
if ((await doltListBranches(db)()).some((b) => b.name === params.revision)) {
|
|
70
|
+
const commitHash = (await db.execute(sql.raw(`SELECT commit_hash FROM DOLT_LOG('${params.revision}') LIMIT 1`))).rows[0]?.commit_hash;
|
|
71
|
+
if (!commitHash) throw new Error(`Could not find commit hash for branch '${params.revision}'`);
|
|
72
|
+
return commitHash;
|
|
73
|
+
}
|
|
74
|
+
const tag = (await doltListTags(db)()).find((t) => t.tag_name === params.revision);
|
|
75
|
+
if (tag) return tag.tag_hash;
|
|
76
|
+
const hash = (await db.execute(sql.raw(`SELECT DOLT_HASHOF('${params.revision}') as hash`))).rows[0]?.hash;
|
|
77
|
+
if (!hash) throw new Error(`Could not find commit hash for revision '${params.revision}'`);
|
|
78
|
+
return hash;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Create a tag
|
|
82
|
+
*/
|
|
83
|
+
const doltTag = (db) => async (params) => {
|
|
84
|
+
const args = [`'${params.name}'`];
|
|
85
|
+
if (params.message) args.push("'-m'", `'${params.message.replace(/'/g, "''")}'`);
|
|
86
|
+
if (params.revision) args.push(`'${params.revision}'`);
|
|
87
|
+
await db.execute(sql.raw(`SELECT DOLT_TAG(${args.join(", ")})`));
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Delete a tag
|
|
91
|
+
*/
|
|
92
|
+
const doltDeleteTag = (db) => async (params) => {
|
|
93
|
+
await db.execute(sql.raw(`SELECT DOLT_TAG('-d', '${params.name}')`));
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* List all tags
|
|
97
|
+
*/
|
|
98
|
+
const doltListTags = (db) => async () => {
|
|
99
|
+
return (await db.execute(sql`SELECT * FROM dolt_tags`)).rows;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AgentsManageDatabaseClient } from "../db/manage/manage-client.js";
|
|
2
|
+
|
|
3
|
+
//#region src/dolt/diff.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get diff between two commits/branches
|
|
7
|
+
*/
|
|
8
|
+
declare const doltDiff: (db: AgentsManageDatabaseClient) => (params: {
|
|
9
|
+
fromRevision: string;
|
|
10
|
+
toRevision: string;
|
|
11
|
+
tableName: string;
|
|
12
|
+
}) => Promise<any[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Get diff summary between two commits/branches
|
|
15
|
+
*/
|
|
16
|
+
declare const doltDiffSummary: (db: AgentsManageDatabaseClient) => (params: {
|
|
17
|
+
fromRevision: string;
|
|
18
|
+
toRevision: string;
|
|
19
|
+
tableName?: string;
|
|
20
|
+
}) => Promise<{
|
|
21
|
+
table_name: string;
|
|
22
|
+
diff_type: string;
|
|
23
|
+
data_change: boolean;
|
|
24
|
+
schema_change: boolean;
|
|
25
|
+
}[]>;
|
|
26
|
+
//#endregion
|
|
27
|
+
export { doltDiff, doltDiffSummary };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { sql } from "drizzle-orm";
|
|
2
|
+
|
|
3
|
+
//#region src/dolt/diff.ts
|
|
4
|
+
/**
|
|
5
|
+
* Get diff between two commits/branches
|
|
6
|
+
*/
|
|
7
|
+
const doltDiff = (db) => async (params) => {
|
|
8
|
+
return (await db.execute(sql.raw(`SELECT * FROM DOLT_DIFF('${params.fromRevision}', '${params.toRevision}', '${params.tableName}')`))).rows;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Get diff summary between two commits/branches
|
|
12
|
+
*/
|
|
13
|
+
const doltDiffSummary = (db) => async (params) => {
|
|
14
|
+
let query;
|
|
15
|
+
if (params.tableName) query = sql.raw(`SELECT * FROM DOLT_DIFF_SUMMARY('${params.fromRevision}', '${params.toRevision}', '${params.tableName}')`);
|
|
16
|
+
else query = sql.raw(`SELECT * FROM DOLT_DIFF_SUMMARY('${params.fromRevision}', '${params.toRevision}')`);
|
|
17
|
+
return (await db.execute(query)).rows;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
//#endregion
|
|
21
|
+
export { doltDiff, doltDiffSummary };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { branchScopes, doltActiveBranch, doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches, doltRenameBranch, ensureBranchExists } from "./branch.js";
|
|
2
|
+
import { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, GetBranchParams, MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent } from "./branches-api.js";
|
|
3
|
+
import { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag } from "./commit.js";
|
|
4
|
+
import { doltDiff, doltDiffSummary } from "./diff.js";
|
|
5
|
+
import { doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
|
|
6
|
+
import { RefType, checkoutRef, getCurrentBranchOrCommit, getProjectMainResolvedRef, getProjectScopedRef, getTenantScopedRef, isRefWritable, isValidCommitHash, resolveRef } from "./ref-helpers.js";
|
|
7
|
+
import { RefContext, RefMiddlewareOptions, createRefMiddleware, createWriteProtectionMiddleware, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
|
|
8
|
+
import { NestedRefScopeError, WithRefOptions, getCurrentRefScope, getRefScopedDb, isInRefScope, withRef } from "./ref-scope.js";
|
|
9
|
+
import { EnsureSchemaSyncOptions, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, syncSchemaFromMain } from "./schema-sync.js";
|
|
10
|
+
export { CheckoutBranchParams, CheckoutBranchResult, CreateBranchParams, DeleteBranchParams, EnsureSchemaSyncOptions, GetBranchParams, MAIN_BRANCH_SUFFIX, NestedRefScopeError, RefContext, RefMiddlewareOptions, RefType, SCHEMA_SOURCE_BRANCH, SchemaDiff, SchemaSyncOptions, SchemaSyncResult, WithRefOptions, areBranchesSchemaCompatible, branchScopes, checkoutBranch, checkoutRef, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, isInRefScope, isProtectedBranchName, isRefWritable, isValidCommitHash, listBranches, listBranchesForAgent, refMiddlewareFactory, resolveRef, syncSchemaFromMain, withRef, writeProtectionMiddlewareFactory };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { doltAdd, doltAddAndCommit, doltCommit, doltDeleteTag, doltHashOf, doltListTags, doltLog, doltReset, doltStatus, doltTag } from "./commit.js";
|
|
2
|
+
import { doltAbortMerge, doltConflicts, doltMerge, doltMergeStatus, doltResolveConflicts, doltSchemaConflicts, doltTableConflicts } from "./merge.js";
|
|
3
|
+
import { SCHEMA_SOURCE_BRANCH, areBranchesSchemaCompatible, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getSchemaDiff, hasSchemaDifferences, hasUncommittedChanges, syncSchemaFromMain } from "./schema-sync.js";
|
|
4
|
+
import { MAIN_BRANCH_SUFFIX, checkoutBranch, createBranch, deleteBranch, getBranch, getTenantMainBranch, isProtectedBranchName, listBranches, listBranchesForAgent } from "./branches-api.js";
|
|
5
|
+
import { checkoutRef, getCurrentBranchOrCommit, getProjectMainResolvedRef, getProjectScopedRef, getTenantScopedRef, isRefWritable, isValidCommitHash, resolveRef } from "./ref-helpers.js";
|
|
6
|
+
import { doltActiveBranch, doltBranch, doltBranchExists, doltCheckout, doltDeleteBranch, doltGetBranchNamespace, doltListBranches, doltRenameBranch, ensureBranchExists } from "./branch.js";
|
|
7
|
+
import { doltDiff, doltDiffSummary } from "./diff.js";
|
|
8
|
+
import { createRefMiddleware, createWriteProtectionMiddleware, refMiddlewareFactory, writeProtectionMiddlewareFactory } from "./ref-middleware.js";
|
|
9
|
+
import { NestedRefScopeError, getCurrentRefScope, getRefScopedDb, isInRefScope, withRef } from "./ref-scope.js";
|
|
10
|
+
|
|
11
|
+
export { MAIN_BRANCH_SUFFIX, NestedRefScopeError, SCHEMA_SOURCE_BRANCH, areBranchesSchemaCompatible, checkoutBranch, checkoutRef, createBranch, createRefMiddleware, createWriteProtectionMiddleware, deleteBranch, doltAbortMerge, doltActiveBranch, doltAdd, doltAddAndCommit, doltBranch, doltBranchExists, doltCheckout, doltCommit, doltConflicts, doltDeleteBranch, doltDeleteTag, doltDiff, doltDiffSummary, doltGetBranchNamespace, doltHashOf, doltListBranches, doltListTags, doltLog, doltMerge, doltMergeStatus, doltRenameBranch, doltReset, doltResolveConflicts, doltSchemaConflicts, doltStatus, doltTableConflicts, doltTag, ensureBranchExists, ensureSchemaSync, formatSchemaDiffSummary, getActiveBranch, getBranch, getCurrentBranchOrCommit, getCurrentRefScope, getProjectMainResolvedRef, getProjectScopedRef, getRefScopedDb, getSchemaDiff, getTenantMainBranch, getTenantScopedRef, hasSchemaDifferences, hasUncommittedChanges, isInRefScope, isProtectedBranchName, isRefWritable, isValidCommitHash, listBranches, listBranchesForAgent, refMiddlewareFactory, resolveRef, syncSchemaFromMain, withRef, writeProtectionMiddlewareFactory };
|