kanbo-cli 0.1.3 → 0.2.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/cli.cjs +26 -46
- package/dist/cli.cjs.map +1 -1
- package/dist/lib/index.cjs +1 -259
- package/dist/lib/index.d.cts +15 -95
- package/dist/lib/index.d.mts +15 -95
- package/dist/lib/index.mjs +2 -256
- package/dist/lib/{manifest-mkDJmxt2.mjs → manifest-BwpC-4BO.mjs} +27 -47
- package/dist/lib/manifest-BwpC-4BO.mjs.map +1 -0
- package/dist/lib/{manifest-BBJIrMw7.cjs → manifest-RDyoGrVR.cjs} +27 -47
- package/dist/lib/manifest-RDyoGrVR.cjs.map +1 -0
- package/dist/lib/mcp/index.cjs +1 -1
- package/dist/lib/mcp/index.mjs +1 -1
- package/dist/lib/migrations-path-CZxVOgeD.cjs.map +1 -1
- package/dist/lib/migrations-path-Ciwan537.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/lib/index.cjs.map +0 -1
- package/dist/lib/index.mjs.map +0 -1
- package/dist/lib/manifest-BBJIrMw7.cjs.map +0 -1
- package/dist/lib/manifest-mkDJmxt2.mjs.map +0 -1
package/dist/lib/mcp/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_manifest = require("../manifest-
|
|
2
|
+
const require_manifest = require("../manifest-RDyoGrVR.cjs");
|
|
3
3
|
const require_migrations_path = require("../migrations-path-CZxVOgeD.cjs");
|
|
4
4
|
let zod = require("zod");
|
|
5
5
|
//#region src/mcp/http-transport.ts
|
package/dist/lib/mcp/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { G as normalizeStatusName, _ as projectKanboPullRequest, b as projectKanboSubCard, c as registerKanboTools, d as KANBO_MCP_INSTRUCTIONS, f as KANBO_CAPABILITIES_MARKDOWN_RESOURCE_URI, g as projectKanboColumn, h as projectKanboCard, i as KANBO_TOOL_NAMES, l as KANBO_TOOLS, m as registerKanboCapabilitiesResources, o as KANBO_MCP_SERVER_NAME, p as KANBO_CAPABILITIES_RESOURCE_URI, r as KANBO_TOOL_CLI_EQUIVALENTS, s as createKanboMcpServer, u as buildKanboTools, v as projectKanboRun, y as projectKanboSprint } from "../manifest-
|
|
1
|
+
import { G as normalizeStatusName, _ as projectKanboPullRequest, b as projectKanboSubCard, c as registerKanboTools, d as KANBO_MCP_INSTRUCTIONS, f as KANBO_CAPABILITIES_MARKDOWN_RESOURCE_URI, g as projectKanboColumn, h as projectKanboCard, i as KANBO_TOOL_NAMES, l as KANBO_TOOLS, m as registerKanboCapabilitiesResources, o as KANBO_MCP_SERVER_NAME, p as KANBO_CAPABILITIES_RESOURCE_URI, r as KANBO_TOOL_CLI_EQUIVALENTS, s as createKanboMcpServer, u as buildKanboTools, v as projectKanboRun, y as projectKanboSprint } from "../manifest-BwpC-4BO.mjs";
|
|
2
2
|
import { a as BoardError } from "../migrations-path-Ciwan537.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/mcp/http-transport.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations-path-CZxVOgeD.cjs","names":["join","existsSync"],"sources":["../../src/domain/errors.ts","../../src/schema-epoch.ts","../../src/migrations-path.ts"],"sourcesContent":["/**\n * Every failure the board itself can name. HTTP status codes are not part of\n * this list: what each code is over HTTP is `BOARD_ERROR_RESPONSES`\n * (`../serve/board-error-responses.ts`), the one table `kanbo serve` and any app\n * serving the board over HTTP answer with.\n
|
|
1
|
+
{"version":3,"file":"migrations-path-CZxVOgeD.cjs","names":["join","existsSync"],"sources":["../../src/domain/errors.ts","../../src/schema-epoch.ts","../../src/migrations-path.ts"],"sourcesContent":["/**\n * Every failure the board itself can name. HTTP status codes are not part of\n * this list: what each code is over HTTP is `BOARD_ERROR_RESPONSES`\n * (`../serve/board-error-responses.ts`), the one table `kanbo serve` and any app\n * serving the board over HTTP answer with.\n */\nexport type BoardErrorCode\n = | 'board_approval_requires_user'\n | 'board_column_rules_requires_user'\n | 'board_column_rules_unmet'\n | 'board_entry_rule_invalid'\n | 'board_execution_mode_locked'\n | 'board_pull_request_invalid'\n | 'board_pull_request_not_found'\n | 'board_pull_request_not_yours'\n | 'board_return_no_previous_column'\n | 'board_return_requires_user'\n | 'board_run_already_finished'\n | 'board_run_not_found'\n | 'board_run_session_ref_conflict'\n | 'board_run_session_ref_invalid'\n | 'board_run_session_ref_requires_user'\n | 'board_schema_outdated'\n | 'board_sprint_carry_invalid'\n | 'board_sprint_close_requires_user'\n | 'board_sprint_dates_invalid'\n | 'issue_comment_delete_requires_user'\n | 'issue_comment_not_found'\n | 'issue_context_ref_invalid_index'\n | 'issue_milestone_not_found'\n | 'issue_not_found'\n | 'issue_parent_not_found'\n | 'issue_parent_self_reference'\n | 'issue_relation_not_found'\n | 'issue_relation_self_reference'\n | 'issue_status_name_empty'\n | 'issue_status_not_found'\n | 'issue_status_reference_conflict'\n | 'issue_workspace_not_found'\n\n/** A board rule the caller broke, carrying the offending values in `details`. */\nexport class BoardError extends Error {\n readonly code: BoardErrorCode\n readonly details?: Record<string, unknown>\n\n constructor(code: BoardErrorCode, details?: Record<string, unknown>) {\n super(code)\n this.code = code\n this.details = details\n }\n}\n","/**\n * The board schema generation this build of the package speaks. A database\n * stamped with anything else was written by another version, and the migration\n * that would bring it forward belongs to whoever owns the database — never to a\n * reader.\n *\n * The number says nothing about which engine holds the board: a SQLite file and\n * a Postgres database at the same epoch carry the same logical schema, which is\n * why a change to one is only ever made together with the same change to the\n * other.\n */\nexport const BOARD_SCHEMA_EPOCH = 1\n\n/**\n * The tables a migration added to the board after epoch 1 was first written.\n *\n * A board that lacks one of these is not a database with no board in it — it\n * has every table the first migration made — but an older board of the same\n * epoch, which `kanbo migrate` (or, for a host app's own database, that app's migrations)\n * brings forward. `assertBoardSchema` names them apart from the founding tables\n * for exactly that reason: a host reads `missingTables` as \"no board here\" and\n * anything else as \"an older board\".\n */\nexport const BOARD_TABLES_ADDED_WITHIN_EPOCH = ['issue_pull_requests'] as const\n","import { existsSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Where this build keeps a board's migrations, whichever dialect is asking.\n *\n * The folder is found relative to the file asking for it, because the same code\n * runs from two layouts: from `src/<dialect>/` in a checkout, where the folder\n * sits at the package root, and from `dist/cli.cjs` in an installed build, where\n * the build has copied it in beside the bundle. The packaged command ships no\n * `node_modules` and no package root — `dist/` is the whole of it — so the copy\n * is the only migrations folder there is.\n *\n * Kept apart from the migrators on purpose: this is a packaging question, and\n * two dialects ask it about two folders. The caller passes its own `here`, so\n * the depth is the caller's rather than this file's.\n */\n\n/** What makes a candidate folder the migrations folder rather than an empty directory. */\nconst JOURNAL_FILE = join('meta', '_journal.json')\n\n/**\n * The first of the layouts that is actually there, as seen from `here`.\n *\n * Pure, and takes its own `exists`, so all three layouts can be asked about on\n * a machine that only has one of them. When none is there the source layout is\n * handed back, so the migrator's complaint names the folder a developer is\n * missing rather than one that only exists inside a packaged app.\n */\nexport function resolveBoardMigrationsPath(\n here: string,\n directory: string,\n exists: (folder: string) => boolean,\n): string {\n const candidates = [\n // src/<dialect>/ → the package root, in a checkout.\n join(here, '..', '..', directory),\n // dist/ → beside the bundle, in an installed build.\n join(here, directory),\n // dist/lib/<dialect>/ → the package root, one directory deeper than the\n // checkout layout because the library build nests each entry under its own\n // subpath. The package root is where the folder already lives — checked in\n // for a checkout, published under `files` for an installed tarball — so\n // this candidate names the same target as the first, not a new copy.\n join(here, '..', '..', '..', directory),\n ]\n return candidates.find(exists) ?? candidates[0]\n}\n\n/** Whether a candidate folder holds a drizzle journal — the real `exists` the two callers pass. */\nexport function hasMigrationJournal(folder: string): boolean {\n return existsSync(join(folder, JOURNAL_FILE))\n}\n"],"mappings":";;;;AAyCA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA;CAEA,YAAY,MAAsB,SAAmC;EACnE,MAAM,IAAI;EACV,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;;;;;;;;;;;;;;ACvCA,MAAa,qBAAqB;;;;;;;;;;;AAYlC,MAAa,kCAAkC,CAAC,qBAAqB;;;;;;;;;;;;;;;;;;ACJrE,MAAM,gBAAA,GAAeA,UAAAA,KAAAA,CAAK,QAAQ,eAAe;;;;;;;;;AAUjD,SAAgB,2BACd,MACA,WACA,QACQ;CACR,MAAM,aAAa;GAEjBA,GAAAA,UAAAA,KAAAA,CAAK,MAAM,MAAM,MAAM,SAAS;GAEhCA,GAAAA,UAAAA,KAAAA,CAAK,MAAM,SAAS;GAMpBA,GAAAA,UAAAA,KAAAA,CAAK,MAAM,MAAM,MAAM,MAAM,SAAS;CACxC;CACA,OAAO,WAAW,KAAK,MAAM,KAAK,WAAW;AAC/C;;AAGA,SAAgB,oBAAoB,QAAyB;CAC3D,QAAA,GAAOC,QAAAA,WAAAA,EAAAA,GAAWD,UAAAA,KAAAA,CAAK,QAAQ,YAAY,CAAC;AAC9C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrations-path-Ciwan537.mjs","names":[],"sources":["../../src/domain/errors.ts","../../src/schema-epoch.ts","../../src/migrations-path.ts"],"sourcesContent":["/**\n * Every failure the board itself can name. HTTP status codes are not part of\n * this list: what each code is over HTTP is `BOARD_ERROR_RESPONSES`\n * (`../serve/board-error-responses.ts`), the one table `kanbo serve` and any app\n * serving the board over HTTP answer with.\n
|
|
1
|
+
{"version":3,"file":"migrations-path-Ciwan537.mjs","names":[],"sources":["../../src/domain/errors.ts","../../src/schema-epoch.ts","../../src/migrations-path.ts"],"sourcesContent":["/**\n * Every failure the board itself can name. HTTP status codes are not part of\n * this list: what each code is over HTTP is `BOARD_ERROR_RESPONSES`\n * (`../serve/board-error-responses.ts`), the one table `kanbo serve` and any app\n * serving the board over HTTP answer with.\n */\nexport type BoardErrorCode\n = | 'board_approval_requires_user'\n | 'board_column_rules_requires_user'\n | 'board_column_rules_unmet'\n | 'board_entry_rule_invalid'\n | 'board_execution_mode_locked'\n | 'board_pull_request_invalid'\n | 'board_pull_request_not_found'\n | 'board_pull_request_not_yours'\n | 'board_return_no_previous_column'\n | 'board_return_requires_user'\n | 'board_run_already_finished'\n | 'board_run_not_found'\n | 'board_run_session_ref_conflict'\n | 'board_run_session_ref_invalid'\n | 'board_run_session_ref_requires_user'\n | 'board_schema_outdated'\n | 'board_sprint_carry_invalid'\n | 'board_sprint_close_requires_user'\n | 'board_sprint_dates_invalid'\n | 'issue_comment_delete_requires_user'\n | 'issue_comment_not_found'\n | 'issue_context_ref_invalid_index'\n | 'issue_milestone_not_found'\n | 'issue_not_found'\n | 'issue_parent_not_found'\n | 'issue_parent_self_reference'\n | 'issue_relation_not_found'\n | 'issue_relation_self_reference'\n | 'issue_status_name_empty'\n | 'issue_status_not_found'\n | 'issue_status_reference_conflict'\n | 'issue_workspace_not_found'\n\n/** A board rule the caller broke, carrying the offending values in `details`. */\nexport class BoardError extends Error {\n readonly code: BoardErrorCode\n readonly details?: Record<string, unknown>\n\n constructor(code: BoardErrorCode, details?: Record<string, unknown>) {\n super(code)\n this.code = code\n this.details = details\n }\n}\n","/**\n * The board schema generation this build of the package speaks. A database\n * stamped with anything else was written by another version, and the migration\n * that would bring it forward belongs to whoever owns the database — never to a\n * reader.\n *\n * The number says nothing about which engine holds the board: a SQLite file and\n * a Postgres database at the same epoch carry the same logical schema, which is\n * why a change to one is only ever made together with the same change to the\n * other.\n */\nexport const BOARD_SCHEMA_EPOCH = 1\n\n/**\n * The tables a migration added to the board after epoch 1 was first written.\n *\n * A board that lacks one of these is not a database with no board in it — it\n * has every table the first migration made — but an older board of the same\n * epoch, which `kanbo migrate` (or, for a host app's own database, that app's migrations)\n * brings forward. `assertBoardSchema` names them apart from the founding tables\n * for exactly that reason: a host reads `missingTables` as \"no board here\" and\n * anything else as \"an older board\".\n */\nexport const BOARD_TABLES_ADDED_WITHIN_EPOCH = ['issue_pull_requests'] as const\n","import { existsSync } from 'node:fs'\nimport { join } from 'node:path'\n\n/**\n * Where this build keeps a board's migrations, whichever dialect is asking.\n *\n * The folder is found relative to the file asking for it, because the same code\n * runs from two layouts: from `src/<dialect>/` in a checkout, where the folder\n * sits at the package root, and from `dist/cli.cjs` in an installed build, where\n * the build has copied it in beside the bundle. The packaged command ships no\n * `node_modules` and no package root — `dist/` is the whole of it — so the copy\n * is the only migrations folder there is.\n *\n * Kept apart from the migrators on purpose: this is a packaging question, and\n * two dialects ask it about two folders. The caller passes its own `here`, so\n * the depth is the caller's rather than this file's.\n */\n\n/** What makes a candidate folder the migrations folder rather than an empty directory. */\nconst JOURNAL_FILE = join('meta', '_journal.json')\n\n/**\n * The first of the layouts that is actually there, as seen from `here`.\n *\n * Pure, and takes its own `exists`, so all three layouts can be asked about on\n * a machine that only has one of them. When none is there the source layout is\n * handed back, so the migrator's complaint names the folder a developer is\n * missing rather than one that only exists inside a packaged app.\n */\nexport function resolveBoardMigrationsPath(\n here: string,\n directory: string,\n exists: (folder: string) => boolean,\n): string {\n const candidates = [\n // src/<dialect>/ → the package root, in a checkout.\n join(here, '..', '..', directory),\n // dist/ → beside the bundle, in an installed build.\n join(here, directory),\n // dist/lib/<dialect>/ → the package root, one directory deeper than the\n // checkout layout because the library build nests each entry under its own\n // subpath. The package root is where the folder already lives — checked in\n // for a checkout, published under `files` for an installed tarball — so\n // this candidate names the same target as the first, not a new copy.\n join(here, '..', '..', '..', directory),\n ]\n return candidates.find(exists) ?? candidates[0]\n}\n\n/** Whether a candidate folder holds a drizzle journal — the real `exists` the two callers pass. */\nexport function hasMigrationJournal(folder: string): boolean {\n return existsSync(join(folder, JOURNAL_FILE))\n}\n"],"mappings":";;;;AAyCA,IAAa,aAAb,cAAgC,MAAM;CACpC;CACA;CAEA,YAAY,MAAsB,SAAmC;EACnE,MAAM,IAAI;EACV,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;;;;;;;;;;;;;;ACvCA,MAAa,qBAAqB;;;;;;;;;;;AAYlC,MAAa,kCAAkC,CAAC,qBAAqB;;;;;;;;;;;;;;;;;;ACJrE,MAAM,eAAe,KAAK,QAAQ,eAAe;;;;;;;;;AAUjD,SAAgB,2BACd,MACA,WACA,QACQ;CACR,MAAM,aAAa;EAEjB,KAAK,MAAM,MAAM,MAAM,SAAS;EAEhC,KAAK,MAAM,SAAS;EAMpB,KAAK,MAAM,MAAM,MAAM,MAAM,SAAS;CACxC;CACA,OAAO,WAAW,KAAK,MAAM,KAAK,WAAW;AAC/C;;AAGA,SAAgB,oBAAoB,QAAyB;CAC3D,OAAO,WAAW,KAAK,QAAQ,YAAY,CAAC;AAC9C"}
|
package/package.json
CHANGED
package/dist/lib/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["currentUnixSeconds","BoardError"],"sources":["../../src/ops/board-copy.ts"],"sourcesContent":["import type { BoardStore } from '../board-store'\nimport { BoardError } from '../domain/errors'\nimport { currentUnixSeconds } from '../domain/time'\nimport type {\n Issue,\n IssueComment,\n IssueFieldChange,\n IssueMilestone,\n IssuePullRequest,\n IssueRelation,\n IssueRun,\n IssueStatus,\n} from '../sqlite/schema'\n\n/** How many rows of each kind a copy wrote into the target board. */\nexport interface BoardCopyCounts {\n statuses: number\n milestones: number\n issues: number\n comments: number\n runs: number\n relations: number\n fieldChanges: number\n /** Cards that carried refs, not rows: context refs are a column on the card. */\n contextRefs: number\n pullRequests: number\n}\n\n/** Everything one workspace has on a board, read before anything is written. */\nexport interface BoardSlice {\n statuses: IssueStatus[]\n milestones: IssueMilestone[]\n /** In an order where a card's parent always comes before it. */\n issues: Issue[]\n comments: IssueComment[]\n runs: IssueRun[]\n relations: IssueRelation[]\n fieldChanges: IssueFieldChange[]\n pullRequests: IssuePullRequest[]\n /** What reading it had to leave behind, said to a person. */\n warnings: string[]\n}\n\n/** Nothing copied — what a move that had nothing to move reports. */\nexport function emptyCopyCounts(): BoardCopyCounts {\n return { statuses: 0, milestones: 0, issues: 0, comments: 0, runs: 0, relations: 0, fieldChanges: 0, contextRefs: 0, pullRequests: 0 }\n}\n\n/**\n * Everything the workspace has on this board, read in one pass before a single\n * row is written anywhere.\n *\n * Links are collected by id because an edge is listed by both of the cards it\n * touches, and one reaching a card outside this workspace is left behind rather\n * than copied: the target holds this workspace's board and nothing else, so the\n * far end of that edge is not there to point at.\n */\nexport async function readBoardSlice(from: BoardStore, workspaceId: string): Promise<BoardSlice> {\n const warnings: string[] = []\n const statuses = await from.statuses.listByWorkspace(workspaceId)\n const milestones = await from.milestones.listByWorkspace(workspaceId)\n const issues = orderParentsFirst(await from.issues.listByWorkspace(workspaceId))\n const issueIds = new Set(issues.map(issue => issue.id))\n\n const comments: IssueComment[] = []\n const runs: IssueRun[] = []\n const relations = new Map<string, IssueRelation>()\n const fieldChanges: IssueFieldChange[] = []\n const pullRequests: IssuePullRequest[] = []\n const skippedRelations = new Set<string>()\n for (const issue of issues) {\n // The store's own order — insertion order on either engine, for runs, for\n // comments and for field changes alike — is the order they are written back\n // in. That is what keeps an attempt number, and the last word on a card,\n // reading the same after the move as before it.\n comments.push(...await from.comments.listByIssue(issue.id))\n runs.push(...await from.runs.listByIssue(issue.id))\n for (const relation of await from.relations.listByIssue(issue.id)) {\n if (issueIds.has(relation.sourceIssueId) && issueIds.has(relation.targetIssueId)) {\n relations.set(relation.id, relation)\n continue\n }\n skippedRelations.add(relation.id)\n }\n fieldChanges.push(...await from.fieldChanges.listByIssue(issue.id))\n pullRequests.push(...await from.pullRequests.listByIssue(issue.id))\n }\n if (skippedRelations.size > 0) {\n warnings.push(`${skippedRelations.size} links to cards in other workspaces were not moved`)\n }\n\n return { statuses, milestones, issues, comments, runs, relations: [...relations.values()], fieldChanges, pullRequests, warnings }\n}\n\n/**\n * Write a slice into the target board, in one transaction, and say what was\n * written and what a person should know about it — the slice's own warnings\n * first.\n *\n * It is idempotent by id. A row the target already has is left exactly as it\n * is and counted as already present, so a copy interrupted half-way is finished\n * by running it again, and a second run of a finished one copies nothing. A\n * clash that is not the same row — a column name or a card number the target\n * holds under another id — refuses the whole copy before its first insert\n * (`board_copy_conflict`, ruling 3-55).\n */\nexport async function writeBoardSlice(\n to: BoardStore,\n slice: BoardSlice,\n workspaceId: string,\n): Promise<{ copied: BoardCopyCounts, warnings: string[] }> {\n const warnings = [...slice.warnings]\n const copied = emptyCopyCounts()\n let alreadyPresent = 0\n\n await to.transaction(async (tx) => {\n await assertTheCopyFits(tx, slice, workspaceId)\n\n for (const status of slice.statuses) {\n if (await tx.statuses.findById(status.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.statuses.create(status)\n copied.statuses += 1\n }\n\n for (const milestone of slice.milestones) {\n if (await tx.milestones.findById(milestone.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.milestones.create(milestone)\n copied.milestones += 1\n }\n\n const movingIssueIds = new Set(slice.issues.map(issue => issue.id))\n for (const issue of slice.issues) {\n if (await tx.issues.findById(issue.id)) {\n alreadyPresent += 1\n continue\n }\n // A card whose parent is neither moving with it nor already on the target\n // would point at a row that is not there. The board's own rule is that a\n // parent which goes away leaves its children parentless, so that is what\n // happens here too — said out loud, because a person is losing a link.\n const parentIsReachable = issue.parentIssueId === null\n || movingIssueIds.has(issue.parentIssueId)\n || (await tx.issues.findById(issue.parentIssueId)) !== null\n if (!parentIsReachable) {\n warnings.push(`${issue.id} lost its parent card, which is not on this board`)\n }\n const { contextRefs, ...row } = issue\n await tx.issues.create({ ...row, parentIssueId: parentIsReachable ? issue.parentIssueId : null })\n copied.issues += 1\n if (contextRefs !== '[]') {\n await tx.contextRefs.replace(issue.id, contextRefs, issue.updatedAt)\n copied.contextRefs += 1\n }\n }\n\n for (const comment of slice.comments) {\n if (await tx.comments.findById(comment.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.comments.create(comment)\n copied.comments += 1\n }\n\n for (const run of slice.runs) {\n if (await tx.runs.findById(run.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.runs.create(run)\n copied.runs += 1\n }\n\n for (const relation of slice.relations) {\n if (await tx.relations.findById(relation.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.relations.create(relation)\n copied.relations += 1\n }\n\n // Field changes carry no lookup by id of their own — they are read a card\n // at a time — so what the target already has is read a card at a time too.\n const changesByIssue = new Map<string, IssueFieldChange[]>()\n for (const change of slice.fieldChanges) {\n changesByIssue.set(change.issueId, [...(changesByIssue.get(change.issueId) ?? []), change])\n }\n for (const [issueId, changes] of changesByIssue) {\n const present = new Set((await tx.fieldChanges.listByIssue(issueId)).map(change => change.id))\n for (const change of changes) {\n if (present.has(change.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.fieldChanges.create(change)\n copied.fieldChanges += 1\n }\n }\n\n // Pull request links, like field changes, are read a card at a time. One\n // the target holds under another id names the same pull request — `link`\n // hands back that standing row — so it is already present too.\n const linksByIssue = new Map<string, IssuePullRequest[]>()\n for (const link of slice.pullRequests) {\n linksByIssue.set(link.issueId, [...(linksByIssue.get(link.issueId) ?? []), link])\n }\n for (const [issueId, links] of linksByIssue) {\n const present = new Set((await tx.pullRequests.listByIssue(issueId)).map(link => link.id))\n for (const link of links) {\n if (present.has(link.id) || (await tx.pullRequests.link(link)).id !== link.id) {\n alreadyPresent += 1\n continue\n }\n copied.pullRequests += 1\n }\n }\n\n // One bump for the whole copy: a reader watching the target refetches once,\n // not once per card.\n await tx.meta.bumpRevision('board', currentUnixSeconds())\n })\n\n if (alreadyPresent > 0) {\n warnings.push(`${alreadyPresent} rows were already present on the target board and were left as they are`)\n }\n return { copied, warnings }\n}\n\n/**\n * Empty the slice off the board it was read from, in a transaction of its own.\n *\n * Only the cards, the columns and the milestones are named: comments, runs,\n * links, pull request links and the field-change history hang off a card by a\n * foreign key that cascades on both engines, so deleting the card takes them\n * with it.\n */\nexport async function deleteBoardSlice(from: BoardStore, slice: BoardSlice): Promise<void> {\n await from.transaction(async (tx) => {\n for (const issue of slice.issues) {\n await tx.issues.delete(issue.id)\n }\n for (const milestone of slice.milestones) {\n await tx.milestones.delete(milestone.id)\n }\n for (const status of slice.statuses) {\n await tx.statuses.delete(status.id)\n }\n await tx.meta.bumpRevision('board', currentUnixSeconds())\n })\n}\n\n/**\n * What a copy would collide with on the target, said before a row is written.\n *\n * The board carries two uniqueness rules that a *second* board of the same\n * workspace can break: a column's name within its workspace, and a card's\n * number within it. In practice it is the columns that collide: a standard set\n * created a second time carries the same names under new ids, while a card's id\n * is its key (`BST-001`), so two generations of card *number* 1 are two rows\n * with one id — which the copy treats as already present rather than as a\n * clash. The number check covers the case where they are not: a workspace whose\n * identifier changed between the two generations numbers from 1 again under\n * different ids.\n *\n * A row the target already has *by id* is not a collision — it is the\n * idempotent half of the copy, which is why the holder's id is compared rather\n * than merely counted. Milestones need no check: neither engine makes their\n * titles unique.\n */\nasync function assertTheCopyFits(tx: BoardStore, slice: BoardSlice, workspaceId: string): Promise<void> {\n const conflicts: { kind: 'card' | 'column', value: string | number, heldBy: string }[] = []\n\n const numbers = new Map((await tx.issues.listByWorkspace(workspaceId)).map(issue => [issue.number, issue.id]))\n for (const issue of slice.issues) {\n const holder = numbers.get(issue.number)\n if (holder !== undefined && holder !== issue.id) {\n conflicts.push({ kind: 'card', value: issue.number, heldBy: holder })\n }\n }\n\n const names = new Map((await tx.statuses.listByWorkspace(workspaceId)).map(status => [status.name, status.id]))\n for (const status of slice.statuses) {\n const holder = names.get(status.name)\n if (holder !== undefined && holder !== status.id) {\n conflicts.push({ kind: 'column', value: status.name, heldBy: holder })\n }\n }\n\n if (conflicts.length > 0) {\n throw new BoardError('board_copy_conflict', { workspaceId, conflicts })\n }\n}\n\n/**\n * The same cards, ordered so that a parent is always written before its\n * children. The column is a foreign key onto the same table, so any other order\n * writes a card pointing at one that is not there yet.\n */\nfunction orderParentsFirst(issues: Issue[]): Issue[] {\n const byId = new Map(issues.map(issue => [issue.id, issue]))\n const ordered: Issue[] = []\n const placed = new Set<string>()\n\n function place(issue: Issue, ancestors: Set<string>): void {\n if (placed.has(issue.id) || ancestors.has(issue.id)) {\n return\n }\n ancestors.add(issue.id)\n const parent = issue.parentIssueId === null ? undefined : byId.get(issue.parentIssueId)\n if (parent) {\n place(parent, ancestors)\n }\n placed.add(issue.id)\n ordered.push(issue)\n }\n\n for (const issue of issues) {\n place(issue, new Set())\n }\n return ordered\n}\n"],"mappings":";;;;;AA4CA,SAAgB,kBAAmC;CACjD,OAAO;EAAE,UAAU;EAAG,YAAY;EAAG,QAAQ;EAAG,UAAU;EAAG,MAAM;EAAG,WAAW;EAAG,cAAc;EAAG,aAAa;EAAG,cAAc;CAAE;AACvI;;;;;;;;;;AAWA,eAAsB,eAAe,MAAkB,aAA0C;CAC/F,MAAM,WAAqB,CAAC;CAC5B,MAAM,WAAW,MAAM,KAAK,SAAS,gBAAgB,WAAW;CAChE,MAAM,aAAa,MAAM,KAAK,WAAW,gBAAgB,WAAW;CACpE,MAAM,SAAS,kBAAkB,MAAM,KAAK,OAAO,gBAAgB,WAAW,CAAC;CAC/E,MAAM,WAAW,IAAI,IAAI,OAAO,KAAI,UAAS,MAAM,EAAE,CAAC;CAEtD,MAAM,WAA2B,CAAC;CAClC,MAAM,OAAmB,CAAC;CAC1B,MAAM,4BAAY,IAAI,IAA2B;CACjD,MAAM,eAAmC,CAAC;CAC1C,MAAM,eAAmC,CAAC;CAC1C,MAAM,mCAAmB,IAAI,IAAY;CACzC,KAAK,MAAM,SAAS,QAAQ;EAK1B,SAAS,KAAK,GAAG,MAAM,KAAK,SAAS,YAAY,MAAM,EAAE,CAAC;EAC1D,KAAK,KAAK,GAAG,MAAM,KAAK,KAAK,YAAY,MAAM,EAAE,CAAC;EAClD,KAAK,MAAM,YAAY,MAAM,KAAK,UAAU,YAAY,MAAM,EAAE,GAAG;GACjE,IAAI,SAAS,IAAI,SAAS,aAAa,KAAK,SAAS,IAAI,SAAS,aAAa,GAAG;IAChF,UAAU,IAAI,SAAS,IAAI,QAAQ;IACnC;GACF;GACA,iBAAiB,IAAI,SAAS,EAA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AAK;CACpB;CAEA,KAAK,MAAM,SAAS,QAClB,MAAM,uBAAO,IAAI,IAAI,CAAC;CAExB,OAAO;AACT"}
|
package/dist/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/ops/board-copy.ts"],"sourcesContent":["import type { BoardStore } from '../board-store'\nimport { BoardError } from '../domain/errors'\nimport { currentUnixSeconds } from '../domain/time'\nimport type {\n Issue,\n IssueComment,\n IssueFieldChange,\n IssueMilestone,\n IssuePullRequest,\n IssueRelation,\n IssueRun,\n IssueStatus,\n} from '../sqlite/schema'\n\n/** How many rows of each kind a copy wrote into the target board. */\nexport interface BoardCopyCounts {\n statuses: number\n milestones: number\n issues: number\n comments: number\n runs: number\n relations: number\n fieldChanges: number\n /** Cards that carried refs, not rows: context refs are a column on the card. */\n contextRefs: number\n pullRequests: number\n}\n\n/** Everything one workspace has on a board, read before anything is written. */\nexport interface BoardSlice {\n statuses: IssueStatus[]\n milestones: IssueMilestone[]\n /** In an order where a card's parent always comes before it. */\n issues: Issue[]\n comments: IssueComment[]\n runs: IssueRun[]\n relations: IssueRelation[]\n fieldChanges: IssueFieldChange[]\n pullRequests: IssuePullRequest[]\n /** What reading it had to leave behind, said to a person. */\n warnings: string[]\n}\n\n/** Nothing copied — what a move that had nothing to move reports. */\nexport function emptyCopyCounts(): BoardCopyCounts {\n return { statuses: 0, milestones: 0, issues: 0, comments: 0, runs: 0, relations: 0, fieldChanges: 0, contextRefs: 0, pullRequests: 0 }\n}\n\n/**\n * Everything the workspace has on this board, read in one pass before a single\n * row is written anywhere.\n *\n * Links are collected by id because an edge is listed by both of the cards it\n * touches, and one reaching a card outside this workspace is left behind rather\n * than copied: the target holds this workspace's board and nothing else, so the\n * far end of that edge is not there to point at.\n */\nexport async function readBoardSlice(from: BoardStore, workspaceId: string): Promise<BoardSlice> {\n const warnings: string[] = []\n const statuses = await from.statuses.listByWorkspace(workspaceId)\n const milestones = await from.milestones.listByWorkspace(workspaceId)\n const issues = orderParentsFirst(await from.issues.listByWorkspace(workspaceId))\n const issueIds = new Set(issues.map(issue => issue.id))\n\n const comments: IssueComment[] = []\n const runs: IssueRun[] = []\n const relations = new Map<string, IssueRelation>()\n const fieldChanges: IssueFieldChange[] = []\n const pullRequests: IssuePullRequest[] = []\n const skippedRelations = new Set<string>()\n for (const issue of issues) {\n // The store's own order — insertion order on either engine, for runs, for\n // comments and for field changes alike — is the order they are written back\n // in. That is what keeps an attempt number, and the last word on a card,\n // reading the same after the move as before it.\n comments.push(...await from.comments.listByIssue(issue.id))\n runs.push(...await from.runs.listByIssue(issue.id))\n for (const relation of await from.relations.listByIssue(issue.id)) {\n if (issueIds.has(relation.sourceIssueId) && issueIds.has(relation.targetIssueId)) {\n relations.set(relation.id, relation)\n continue\n }\n skippedRelations.add(relation.id)\n }\n fieldChanges.push(...await from.fieldChanges.listByIssue(issue.id))\n pullRequests.push(...await from.pullRequests.listByIssue(issue.id))\n }\n if (skippedRelations.size > 0) {\n warnings.push(`${skippedRelations.size} links to cards in other workspaces were not moved`)\n }\n\n return { statuses, milestones, issues, comments, runs, relations: [...relations.values()], fieldChanges, pullRequests, warnings }\n}\n\n/**\n * Write a slice into the target board, in one transaction, and say what was\n * written and what a person should know about it — the slice's own warnings\n * first.\n *\n * It is idempotent by id. A row the target already has is left exactly as it\n * is and counted as already present, so a copy interrupted half-way is finished\n * by running it again, and a second run of a finished one copies nothing. A\n * clash that is not the same row — a column name or a card number the target\n * holds under another id — refuses the whole copy before its first insert\n * (`board_copy_conflict`, ruling 3-55).\n */\nexport async function writeBoardSlice(\n to: BoardStore,\n slice: BoardSlice,\n workspaceId: string,\n): Promise<{ copied: BoardCopyCounts, warnings: string[] }> {\n const warnings = [...slice.warnings]\n const copied = emptyCopyCounts()\n let alreadyPresent = 0\n\n await to.transaction(async (tx) => {\n await assertTheCopyFits(tx, slice, workspaceId)\n\n for (const status of slice.statuses) {\n if (await tx.statuses.findById(status.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.statuses.create(status)\n copied.statuses += 1\n }\n\n for (const milestone of slice.milestones) {\n if (await tx.milestones.findById(milestone.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.milestones.create(milestone)\n copied.milestones += 1\n }\n\n const movingIssueIds = new Set(slice.issues.map(issue => issue.id))\n for (const issue of slice.issues) {\n if (await tx.issues.findById(issue.id)) {\n alreadyPresent += 1\n continue\n }\n // A card whose parent is neither moving with it nor already on the target\n // would point at a row that is not there. The board's own rule is that a\n // parent which goes away leaves its children parentless, so that is what\n // happens here too — said out loud, because a person is losing a link.\n const parentIsReachable = issue.parentIssueId === null\n || movingIssueIds.has(issue.parentIssueId)\n || (await tx.issues.findById(issue.parentIssueId)) !== null\n if (!parentIsReachable) {\n warnings.push(`${issue.id} lost its parent card, which is not on this board`)\n }\n const { contextRefs, ...row } = issue\n await tx.issues.create({ ...row, parentIssueId: parentIsReachable ? issue.parentIssueId : null })\n copied.issues += 1\n if (contextRefs !== '[]') {\n await tx.contextRefs.replace(issue.id, contextRefs, issue.updatedAt)\n copied.contextRefs += 1\n }\n }\n\n for (const comment of slice.comments) {\n if (await tx.comments.findById(comment.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.comments.create(comment)\n copied.comments += 1\n }\n\n for (const run of slice.runs) {\n if (await tx.runs.findById(run.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.runs.create(run)\n copied.runs += 1\n }\n\n for (const relation of slice.relations) {\n if (await tx.relations.findById(relation.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.relations.create(relation)\n copied.relations += 1\n }\n\n // Field changes carry no lookup by id of their own — they are read a card\n // at a time — so what the target already has is read a card at a time too.\n const changesByIssue = new Map<string, IssueFieldChange[]>()\n for (const change of slice.fieldChanges) {\n changesByIssue.set(change.issueId, [...(changesByIssue.get(change.issueId) ?? []), change])\n }\n for (const [issueId, changes] of changesByIssue) {\n const present = new Set((await tx.fieldChanges.listByIssue(issueId)).map(change => change.id))\n for (const change of changes) {\n if (present.has(change.id)) {\n alreadyPresent += 1\n continue\n }\n await tx.fieldChanges.create(change)\n copied.fieldChanges += 1\n }\n }\n\n // Pull request links, like field changes, are read a card at a time. One\n // the target holds under another id names the same pull request — `link`\n // hands back that standing row — so it is already present too.\n const linksByIssue = new Map<string, IssuePullRequest[]>()\n for (const link of slice.pullRequests) {\n linksByIssue.set(link.issueId, [...(linksByIssue.get(link.issueId) ?? []), link])\n }\n for (const [issueId, links] of linksByIssue) {\n const present = new Set((await tx.pullRequests.listByIssue(issueId)).map(link => link.id))\n for (const link of links) {\n if (present.has(link.id) || (await tx.pullRequests.link(link)).id !== link.id) {\n alreadyPresent += 1\n continue\n }\n copied.pullRequests += 1\n }\n }\n\n // One bump for the whole copy: a reader watching the target refetches once,\n // not once per card.\n await tx.meta.bumpRevision('board', currentUnixSeconds())\n })\n\n if (alreadyPresent > 0) {\n warnings.push(`${alreadyPresent} rows were already present on the target board and were left as they are`)\n }\n return { copied, warnings }\n}\n\n/**\n * Empty the slice off the board it was read from, in a transaction of its own.\n *\n * Only the cards, the columns and the milestones are named: comments, runs,\n * links, pull request links and the field-change history hang off a card by a\n * foreign key that cascades on both engines, so deleting the card takes them\n * with it.\n */\nexport async function deleteBoardSlice(from: BoardStore, slice: BoardSlice): Promise<void> {\n await from.transaction(async (tx) => {\n for (const issue of slice.issues) {\n await tx.issues.delete(issue.id)\n }\n for (const milestone of slice.milestones) {\n await tx.milestones.delete(milestone.id)\n }\n for (const status of slice.statuses) {\n await tx.statuses.delete(status.id)\n }\n await tx.meta.bumpRevision('board', currentUnixSeconds())\n })\n}\n\n/**\n * What a copy would collide with on the target, said before a row is written.\n *\n * The board carries two uniqueness rules that a *second* board of the same\n * workspace can break: a column's name within its workspace, and a card's\n * number within it. In practice it is the columns that collide: a standard set\n * created a second time carries the same names under new ids, while a card's id\n * is its key (`BST-001`), so two generations of card *number* 1 are two rows\n * with one id — which the copy treats as already present rather than as a\n * clash. The number check covers the case where they are not: a workspace whose\n * identifier changed between the two generations numbers from 1 again under\n * different ids.\n *\n * A row the target already has *by id* is not a collision — it is the\n * idempotent half of the copy, which is why the holder's id is compared rather\n * than merely counted. Milestones need no check: neither engine makes their\n * titles unique.\n */\nasync function assertTheCopyFits(tx: BoardStore, slice: BoardSlice, workspaceId: string): Promise<void> {\n const conflicts: { kind: 'card' | 'column', value: string | number, heldBy: string }[] = []\n\n const numbers = new Map((await tx.issues.listByWorkspace(workspaceId)).map(issue => [issue.number, issue.id]))\n for (const issue of slice.issues) {\n const holder = numbers.get(issue.number)\n if (holder !== undefined && holder !== issue.id) {\n conflicts.push({ kind: 'card', value: issue.number, heldBy: holder })\n }\n }\n\n const names = new Map((await tx.statuses.listByWorkspace(workspaceId)).map(status => [status.name, status.id]))\n for (const status of slice.statuses) {\n const holder = names.get(status.name)\n if (holder !== undefined && holder !== status.id) {\n conflicts.push({ kind: 'column', value: status.name, heldBy: holder })\n }\n }\n\n if (conflicts.length > 0) {\n throw new BoardError('board_copy_conflict', { workspaceId, conflicts })\n }\n}\n\n/**\n * The same cards, ordered so that a parent is always written before its\n * children. The column is a foreign key onto the same table, so any other order\n * writes a card pointing at one that is not there yet.\n */\nfunction orderParentsFirst(issues: Issue[]): Issue[] {\n const byId = new Map(issues.map(issue => [issue.id, issue]))\n const ordered: Issue[] = []\n const placed = new Set<string>()\n\n function place(issue: Issue, ancestors: Set<string>): void {\n if (placed.has(issue.id) || ancestors.has(issue.id)) {\n return\n }\n ancestors.add(issue.id)\n const parent = issue.parentIssueId === null ? undefined : byId.get(issue.parentIssueId)\n if (parent) {\n place(parent, ancestors)\n }\n placed.add(issue.id)\n ordered.push(issue)\n }\n\n for (const issue of issues) {\n place(issue, new Set())\n }\n return ordered\n}\n"],"mappings":";;;;AA4CA,SAAgB,kBAAmC;CACjD,OAAO;EAAE,UAAU;EAAG,YAAY;EAAG,QAAQ;EAAG,UAAU;EAAG,MAAM;EAAG,WAAW;EAAG,cAAc;EAAG,aAAa;E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