@samebase/alchemy-convex 0.44.0 → 0.45.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/lib/cli.js CHANGED
@@ -88,8 +88,9 @@ const boxName = ({ name, resourceType, rows: [first] }) => {
88
88
  };
89
89
  /**
90
90
  A box of the tree: its name with the labels of its line as code, its type and schedule, and its link
91
- on the next line unless the link is the stage address. Below it, in a list: the boxes that it uses, the rows folded into it, and
92
- the boxes that share a resource with it. A repeated box has only its name.
91
+ on the next line unless the link is the stage address. Below it, in a list: the boxes that it uses,
92
+ its bindings that name no box, the rows folded into it, and the boxes that share a resource with it.
93
+ A repeated box has only its name.
93
94
  */
94
95
  const treeNode = (node, address) => {
95
96
  const { box, labels, repeated } = node;
@@ -98,6 +99,7 @@ const treeNode = (node, address) => {
98
99
  const linkLine = box.link === null || box.link === address ? "" : `<br><sub>${link(box.link, hostOf(box.link))}</sub>`;
99
100
  const below = [
100
101
  ...node.children.map((child) => treeNode(child, address)),
102
+ ...box.bindings.filter((binding) => binding.box === null).map((binding) => `<code>${escapeHtml(binding.name)}</code> <sub>${escapeHtml([binding.kind, binding.target].filter((part) => part !== null).join(", "))}</sub>`),
101
103
  ...box.folded.map((row) => `<sub>${escapeHtml(`${row.logicalId}, ${resourceTypeUI(row.resourceType).name}`)}</sub>`),
102
104
  ...node.shared.map((text) => `<sub>${escapeHtml(text)}</sub>`)
103
105
  ];
package/lib/cli.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.js","names":[],"sources":["../src/StackComment.ts","../src/cli.ts"],"sourcesContent":["// The command `alchemy-convex stack-comment`: one comment on a pull request with the stacks of the\n// repository, read from the state store after the deploys.\n//\n// A stack sees only itself, so a comment that a stack declares cannot show the other stacks of the\n// repository. This command runs as a step after them and reads each stack of the repository that\n// has the stage `pr-<number>`: by the repository id of the stage's run record, or, for a stage\n// without a version 2 record, by the name `owner/name` or `owner/name/<folder>`. A stack without\n// that stage has no card. A run replaces the whole body, so the last run shows the newest state.\n//\n// The rows of a card are the boxes of `stageDiagram` from `@samebase/alchemy-kit/stack`, the model\n// of Samebase's stack diagram. Alchemy state holds secrets in clear text, and that model keeps no\n// secret of a row.\n//\n// GitHub keeps a fixed set of HTML in a comment and removes `style` and `class`, so every choice of\n// the markup is a fact about the sanitizer or the CSS of github.com:\n// - A table has `display: block` and `width: max-content`, so a `width` on it does nothing. The\n// spacer, a floated image one pixel high in a block of its own, gives every card one width, and\n// it shrinks on a narrow page.\n// - The CSS colors the even rows of a group, so each row has its own `tbody`.\n// - An HTML block ends at a blank line, so a table has none and is not indented.\n// - A bare image links to its raw file, and one link around an image and text underlines the space\n// between them, so the icon and the name are two links to one place.\n// - An image with `height` gets a gray background, so each icon is square and has only `width`.\n// - `align=\"middle\"` is `-webkit-baseline-middle` in Chrome, which is below the text.\n// `align=\"absmiddle\"` is the CSS value `middle`.\nimport { State } from \"alchemy/State\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport { RUN_RECORD_KEY, runRecord } from \"@samebase/alchemy-kit/run-record\";\nimport {\n boxSubtitle,\n stageDiagram,\n stageTree,\n type DiagramBox,\n type StageDiagram,\n type StageTreeNode,\n} from \"@samebase/alchemy-kit/stack\";\nimport { resourceTypeUI } from \"@samebase/alchemy-kit/ui\";\n\n/** The first text of the comment, which finds it again. */\nconst MARKER = \"<!-- samebase-stacks -->\";\n\n/** GitHub does not proxy this host, so a new icon needs no purge of its image cache. */\nconst ICONS =\n \"https://raw.githubusercontent.com/samebase/samebase/main/packages/alchemy-convex/assets/stack-comment\";\n\nconst GITHUB_API = \"https://api.github.com\";\n\n/** The fields of the run record that a card shows. */\nconst StageOutput = Schema.Struct({\n [RUN_RECORD_KEY]: Schema.Struct({\n headCommit: Schema.String,\n runUrl: Schema.NullOr(Schema.String),\n recordedAt: Schema.String,\n }),\n});\n\n/** The part of a stage output that says which repository deployed it. */\nconst RepositoryOfOutput = Schema.Struct({\n [RUN_RECORD_KEY]: Schema.Struct({\n version: Schema.Literal(2),\n repositoryId: Schema.String,\n stackFile: Schema.String,\n }),\n});\n\nexport interface StackCard {\n readonly name: string;\n /** The folder of the stack file in the repository, \"\" at the root. */\n readonly folder: string;\n readonly stage: string;\n readonly diagram: StageDiagram;\n readonly run: typeof StageOutput.Type | null;\n}\n\nexport class StackCommentError extends Schema.TaggedError<StackCommentError>()(\n \"StackCommentError\",\n { reason: Schema.String },\n) {\n override get message() {\n return `The stack comment cannot be updated: ${this.reason}`;\n }\n}\n\n/**\n * The cards of the stacks of the repository that have `stage`, in name order. A stage with a version\n * 2 record belongs to the repository of its `repositoryId`, under any stack name; any other stage\n * belongs to the stacks named `repository` or `repository/<folder>`.\n */\nexport const readStackCards = ({\n repository,\n repositoryId,\n stage,\n}: {\n repository: string;\n repositoryId: string;\n stage: string;\n}) =>\n Effect.gen(function* () {\n const state = yield* yield* State;\n const cards: StackCard[] = [];\n for (const name of yield* state.listStacks()) {\n if (!(yield* state.listStages(name)).includes(stage)) {\n continue;\n }\n const request = { stack: name, stage };\n const output = yield* state.getOutput(request);\n const underName = name === repository || name.startsWith(`${repository}/`);\n const record = Option.map(\n Schema.decodeUnknownOption(RepositoryOfOutput)(output),\n (decoded) => decoded[RUN_RECORD_KEY],\n );\n if (Option.isSome(record) ? record.value.repositoryId !== repositoryId : !underName) {\n continue;\n }\n const rows = yield* Effect.forEach(yield* state.list(request), (fqn) =>\n state.get({ ...request, fqn }).pipe(Effect.map((row) => ({ fqn, state: row }))),\n );\n cards.push({\n name,\n folder:\n underName || Option.isNone(record)\n ? name.slice(repository.length + 1)\n : record.value.stackFile.split(\"/\").slice(0, -1).join(\"/\"),\n stage,\n diagram: stageDiagram(rows),\n run: Schema.is(StageOutput)(output) ? output : null,\n });\n }\n return cards;\n });\n\nconst escapeHtml = (text: string) =>\n text\n .replaceAll(\"&\", \"&amp;\")\n .replaceAll(\"<\", \"&lt;\")\n .replaceAll(\">\", \"&gt;\")\n .replaceAll('\"', \"&quot;\");\n\nconst link = (href: string, text: string) => `<a href=\"${escapeHtml(href)}\">${text}</a>`;\n\nconst hostOf = (url: string) => escapeHtml(new URL(url).host);\n\n/** The icon file of a resource type, in `ICONS`. A box of any other type has no icon. */\nconst ICON_FILES = new Map([\n [\"Convex.Deployment\", \"convex\"],\n [\"Cloudflare.Worker\", \"worker\"],\n [\"Cloudflare.R2.Bucket\", \"r2\"],\n]);\n\n/** The name of a box, as a link to its dashboard page when it has one. */\nconst boxName = ({ name, resourceType, rows: [first] }: DiagramBox) => {\n const icon = ICON_FILES.get(resourceType);\n const image =\n icon === undefined\n ? null\n : `<img src=\"${ICONS}/${icon}.svg\" width=\"16\" align=\"absmiddle\" alt=\"\">`;\n const text = escapeHtml(name);\n const href = first.dashboard?.href;\n if (href === undefined) {\n return image === null ? text : `${image} ${text}`;\n }\n return image === null ? link(href, text) : `${link(href, image)} ${link(href, text)}`;\n};\n\n/**\nA box of the tree: its name with the labels of its line as code, its type and schedule, and its link\non the next line unless the link is the stage address. Below it, in a list: the boxes that it uses, the rows folded into it, and\nthe boxes that share a resource with it. A repeated box has only its name.\n*/\nconst treeNode = (node: StageTreeNode, address: string | null): string => {\n const { box, labels, repeated } = node;\n const title = `${boxName(box)}${labels.map((label) => ` <code>${escapeHtml(label)}</code>`).join(\"\")}`;\n if (repeated) {\n return title;\n }\n const linkLine =\n box.link === null || box.link === address\n ? \"\"\n : `<br><sub>${link(box.link, hostOf(box.link))}</sub>`;\n const below = [\n ...node.children.map((child) => treeNode(child, address)),\n ...box.folded.map(\n (row) =>\n `<sub>${escapeHtml(`${row.logicalId}, ${resourceTypeUI(row.resourceType).name}`)}</sub>`,\n ),\n ...node.shared.map((text) => `<sub>${escapeHtml(text)}</sub>`),\n ];\n const list =\n below.length === 0 ? \"\" : `<ul>${below.map((item) => `<li>${item}</li>`).join(\"\")}</ul>`;\n return `${title} <sub>${escapeHtml(boxSubtitle(box))}</sub>${linkLine}${list}`;\n};\n\n/** Where a stage serves: its Convex app, else the first box with a link. */\nconst addressOf = ({ boxes }: StageDiagram) =>\n (boxes.find((box) => box.resourceType === \"Convex.Deployment\") ?? boxes.find((box) => box.link))\n ?.link ?? null;\n\nconst runLine = ({ run }: StackCard) => {\n if (run === null) {\n return \"\";\n }\n const { headCommit, recordedAt, runUrl } = run[RUN_RECORD_KEY];\n const commit = escapeHtml(headCommit.slice(0, 7));\n const time = `${recordedAt.slice(0, 16).replace(\"T\", \" \")} UTC`;\n return `<br><sub>${runUrl === null ? commit : link(runUrl, commit)} ${escapeHtml(time)}</sub>`;\n};\n\nconst SPACER = `<div><img src=\"${ICONS}/spacer.svg\" width=\"460\" align=\"left\" alt=\"\"></div>`;\n\n/** `alone`: the one card of the repository. A card at the root then has no folder, as on the repository page. */\nconst renderCard = (card: StackCard, alone: boolean) => {\n const { folder } = card;\n const heading = [\n folder === \"\" && alone ? \"\" : `<b>${escapeHtml(folder || \"/\")}</b> `,\n `<sub>${escapeHtml(card.stage)}</sub>`,\n ].join(\"\");\n const address = addressOf(card.diagram);\n const addressLine = address === null ? \"\" : `<br>${link(address, hostOf(address))}`;\n const rows = stageTree(card.diagram)\n .map((node) => `<tbody><tr><td>${treeNode(node, address)}</td></tr></tbody>`)\n .join(\"\\n\");\n return `<table>\n<tbody><tr><td>${SPACER}${heading}${addressLine}${runLine(card)}</td></tr></tbody>\n${rows}\n</table>`;\n};\n\nexport const renderStackComment = (cards: readonly StackCard[]) => `${MARKER}\n${cards.map((card) => renderCard(card, cards.length === 1)).join(\"\\n\\n\")}\n`;\n\nconst Comments = Schema.Array(Schema.Struct({ id: Schema.Number, body: Schema.String }));\nconst SavedComment = Schema.Struct({ html_url: Schema.String });\n\nconst github = (token: string, path: string, init: { method: string; body?: string }) =>\n Effect.tryPromise({\n try: async (): Promise<unknown> => {\n const response = await fetch(`${GITHUB_API}${path}`, {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n },\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n return await response.json();\n },\n catch: (error) =>\n new StackCommentError({\n reason: `GitHub ${init.method} ${path} failed (${error instanceof Error ? error.message : String(error)})`,\n }),\n });\n\nconst decode =\n <S extends Schema.Codec<unknown, unknown>>(schema: S, what: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => new StackCommentError({ reason: `GitHub gave a bad ${what}` })),\n );\n\nconst findComment = (token: string, path: string) =>\n Effect.gen(function* () {\n for (let page = 1; ; page += 1) {\n const comments = yield* github(token, `${path}?per_page=100&page=${page}`, {\n method: \"GET\",\n }).pipe(Effect.flatMap(decode(Comments, \"comment list\")));\n const comment = comments.find(({ body }) => body.startsWith(MARKER));\n if (comment !== undefined || comments.length < 100) {\n return comment;\n }\n }\n });\n\n/** Replaces the body of the comment of this command, or posts it on the first run, and gives its URL. */\nexport const saveStackComment = (args: {\n readonly token: string;\n readonly repository: string;\n readonly pullRequest: number;\n readonly body: string;\n}) =>\n Effect.gen(function* () {\n const { body, pullRequest, repository, token } = args;\n const comments = `/repos/${repository}/issues/${pullRequest}/comments`;\n const comment = yield* findComment(token, comments);\n const reply = yield* comment === undefined\n ? github(token, comments, { method: \"POST\", body: JSON.stringify({ body }) })\n : github(token, `/repos/${repository}/issues/comments/${comment.id}`, {\n method: \"PATCH\",\n body: JSON.stringify({ body }),\n });\n const saved = yield* decode(SavedComment, \"comment\")(reply);\n return saved.html_url;\n });\n\n/** The step of a workflow: the run record names the repository and the pull request of the run. */\nexport const updateStackComment = Effect.gen(function* () {\n const {\n pullRequest,\n repositoryId,\n repositoryName: repository,\n } = yield* runRecord({ cwd: process.cwd(), env: process.env });\n if (pullRequest === null) {\n return yield* new StackCommentError({ reason: \"this run has no pull request\" });\n }\n const token = process.env[\"GITHUB_TOKEN\"];\n if (token === undefined || token === \"\") {\n return yield* new StackCommentError({ reason: \"GITHUB_TOKEN is not set\" });\n }\n const cards = yield* readStackCards({ repository, repositoryId, stage: `pr-${pullRequest}` });\n return yield* saveStackComment({\n token,\n repository,\n pullRequest,\n body: renderStackComment(cards),\n });\n});\n","#!/usr/bin/env node\n// The command of the package:\n//\n// alchemy-convex stack-comment\n//\n// stack-comment runs as a step of a pull request workflow after the deploys, and keeps one comment\n// with the stacks of the repository: see src/StackComment.ts. It needs GITHUB_TOKEN, and reads the\n// store of the team of CONVEX_ACCESS_TOKEN or of the Convex CLI login.\nimport { parseArgs } from \"node:util\";\nimport * as NodeServices from \"@effect/platform-node/NodeServices\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport { updateStackComment } from \"./StackComment.ts\";\nimport { state } from \"./State.ts\";\n\nconst { positionals } = parseArgs({ allowPositionals: true, options: {} });\nconst USAGE = `Usage:\n alchemy-convex stack-comment`;\n\nconst stackComment = updateStackComment.pipe(\n Effect.tap((url) => Effect.sync(() => console.log(url))),\n Effect.provide(state().pipe(Layer.provide(NodeServices.layer))),\n);\n\nif (positionals.join(\" \") !== \"stack-comment\") {\n console.error(USAGE);\n process.exit(1);\n}\n\nawait Effect.runPromise(stackComment).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;AAyCA,MAAM,SAAS;;AAGf,MAAM,QACJ;AAEF,MAAM,aAAa;;AAGnB,MAAM,cAAc,OAAO,OAAO,GAC/B,iBAAiB,OAAO,OAAO;CAC9B,YAAY,OAAO;CACnB,QAAQ,OAAO,OAAO,OAAO,MAAM;CACnC,YAAY,OAAO;AACrB,CAAC,EACH,CAAC;;AAGD,MAAM,qBAAqB,OAAO,OAAO,GACtC,iBAAiB,OAAO,OAAO;CAC9B,SAAS,OAAO,QAAQ,CAAC;CACzB,cAAc,OAAO;CACrB,WAAW,OAAO;AACpB,CAAC,EACH,CAAC;AAWD,IAAa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CAChC,CAAC;AACH,CAAC;;;AClTD,MAAM,EAAE,gBAAgB,UAAU;CAAE,kBAAkB;CAAM,SAAS,CAAC;AAAE,CAAC;AACzE,MAAM,QAAQ;;AAGd,MAAM,eAAe,mBAAmB,KACtC,OAAO,KAAK,QAAQ,OAAO,WAAW,QAAQ,IAAI,GAAG,CAAC,CAAC,GACvD,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,MAAM,QAAQ,aAAa,KAAK,CAAC,CAAC,CAChE;AAEA,IAAI,YAAY,KAAK,GAAG,MAAM,iBAAiB;CAC7C,QAAQ,MAAM,KAAK;CACnB,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,OAAO,WAAW,YAAY,CAAC,CAAC,OAAO,UAAmB;CAC9D,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
1
+ {"version":3,"file":"cli.js","names":[],"sources":["../src/StackComment.ts","../src/cli.ts"],"sourcesContent":["// The command `alchemy-convex stack-comment`: one comment on a pull request with the stacks of the\n// repository, read from the state store after the deploys.\n//\n// A stack sees only itself, so a comment that a stack declares cannot show the other stacks of the\n// repository. This command runs as a step after them and reads each stack of the repository that\n// has the stage `pr-<number>`: by the repository id of the stage's run record, or, for a stage\n// without a version 2 record, by the name `owner/name` or `owner/name/<folder>`. A stack without\n// that stage has no card. A run replaces the whole body, so the last run shows the newest state.\n//\n// The rows of a card are the boxes of `stageDiagram` from `@samebase/alchemy-kit/stack`, the model\n// of Samebase's stack diagram. Alchemy state holds secrets in clear text, and that model keeps no\n// secret of a row.\n//\n// GitHub keeps a fixed set of HTML in a comment and removes `style` and `class`, so every choice of\n// the markup is a fact about the sanitizer or the CSS of github.com:\n// - A table has `display: block` and `width: max-content`, so a `width` on it does nothing. The\n// spacer, a floated image one pixel high in a block of its own, gives every card one width, and\n// it shrinks on a narrow page.\n// - The CSS colors the even rows of a group, so each row has its own `tbody`.\n// - An HTML block ends at a blank line, so a table has none and is not indented.\n// - A bare image links to its raw file, and one link around an image and text underlines the space\n// between them, so the icon and the name are two links to one place.\n// - An image with `height` gets a gray background, so each icon is square and has only `width`.\n// - `align=\"middle\"` is `-webkit-baseline-middle` in Chrome, which is below the text.\n// `align=\"absmiddle\"` is the CSS value `middle`.\nimport { State } from \"alchemy/State\";\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport { RUN_RECORD_KEY, runRecord } from \"@samebase/alchemy-kit/run-record\";\nimport {\n boxSubtitle,\n stageDiagram,\n stageTree,\n type DiagramBox,\n type StageDiagram,\n type StageTreeNode,\n} from \"@samebase/alchemy-kit/stack\";\nimport { resourceTypeUI } from \"@samebase/alchemy-kit/ui\";\n\n/** The first text of the comment, which finds it again. */\nconst MARKER = \"<!-- samebase-stacks -->\";\n\n/** GitHub does not proxy this host, so a new icon needs no purge of its image cache. */\nconst ICONS =\n \"https://raw.githubusercontent.com/samebase/samebase/main/packages/alchemy-convex/assets/stack-comment\";\n\nconst GITHUB_API = \"https://api.github.com\";\n\n/** The fields of the run record that a card shows. */\nconst StageOutput = Schema.Struct({\n [RUN_RECORD_KEY]: Schema.Struct({\n headCommit: Schema.String,\n runUrl: Schema.NullOr(Schema.String),\n recordedAt: Schema.String,\n }),\n});\n\n/** The part of a stage output that says which repository deployed it. */\nconst RepositoryOfOutput = Schema.Struct({\n [RUN_RECORD_KEY]: Schema.Struct({\n version: Schema.Literal(2),\n repositoryId: Schema.String,\n stackFile: Schema.String,\n }),\n});\n\nexport interface StackCard {\n readonly name: string;\n /** The folder of the stack file in the repository, \"\" at the root. */\n readonly folder: string;\n readonly stage: string;\n readonly diagram: StageDiagram;\n readonly run: typeof StageOutput.Type | null;\n}\n\nexport class StackCommentError extends Schema.TaggedError<StackCommentError>()(\n \"StackCommentError\",\n { reason: Schema.String },\n) {\n override get message() {\n return `The stack comment cannot be updated: ${this.reason}`;\n }\n}\n\n/**\n * The cards of the stacks of the repository that have `stage`, in name order. A stage with a version\n * 2 record belongs to the repository of its `repositoryId`, under any stack name; any other stage\n * belongs to the stacks named `repository` or `repository/<folder>`.\n */\nexport const readStackCards = ({\n repository,\n repositoryId,\n stage,\n}: {\n repository: string;\n repositoryId: string;\n stage: string;\n}) =>\n Effect.gen(function* () {\n const state = yield* yield* State;\n const cards: StackCard[] = [];\n for (const name of yield* state.listStacks()) {\n if (!(yield* state.listStages(name)).includes(stage)) {\n continue;\n }\n const request = { stack: name, stage };\n const output = yield* state.getOutput(request);\n const underName = name === repository || name.startsWith(`${repository}/`);\n const record = Option.map(\n Schema.decodeUnknownOption(RepositoryOfOutput)(output),\n (decoded) => decoded[RUN_RECORD_KEY],\n );\n if (Option.isSome(record) ? record.value.repositoryId !== repositoryId : !underName) {\n continue;\n }\n const rows = yield* Effect.forEach(yield* state.list(request), (fqn) =>\n state.get({ ...request, fqn }).pipe(Effect.map((row) => ({ fqn, state: row }))),\n );\n cards.push({\n name,\n folder:\n underName || Option.isNone(record)\n ? name.slice(repository.length + 1)\n : record.value.stackFile.split(\"/\").slice(0, -1).join(\"/\"),\n stage,\n diagram: stageDiagram(rows),\n run: Schema.is(StageOutput)(output) ? output : null,\n });\n }\n return cards;\n });\n\nconst escapeHtml = (text: string) =>\n text\n .replaceAll(\"&\", \"&amp;\")\n .replaceAll(\"<\", \"&lt;\")\n .replaceAll(\">\", \"&gt;\")\n .replaceAll('\"', \"&quot;\");\n\nconst link = (href: string, text: string) => `<a href=\"${escapeHtml(href)}\">${text}</a>`;\n\nconst hostOf = (url: string) => escapeHtml(new URL(url).host);\n\n/** The icon file of a resource type, in `ICONS`. A box of any other type has no icon. */\nconst ICON_FILES = new Map([\n [\"Convex.Deployment\", \"convex\"],\n [\"Cloudflare.Worker\", \"worker\"],\n [\"Cloudflare.R2.Bucket\", \"r2\"],\n]);\n\n/** The name of a box, as a link to its dashboard page when it has one. */\nconst boxName = ({ name, resourceType, rows: [first] }: DiagramBox) => {\n const icon = ICON_FILES.get(resourceType);\n const image =\n icon === undefined\n ? null\n : `<img src=\"${ICONS}/${icon}.svg\" width=\"16\" align=\"absmiddle\" alt=\"\">`;\n const text = escapeHtml(name);\n const href = first.dashboard?.href;\n if (href === undefined) {\n return image === null ? text : `${image} ${text}`;\n }\n return image === null ? link(href, text) : `${link(href, image)} ${link(href, text)}`;\n};\n\n/**\nA box of the tree: its name with the labels of its line as code, its type and schedule, and its link\non the next line unless the link is the stage address. Below it, in a list: the boxes that it uses,\nits bindings that name no box, the rows folded into it, and the boxes that share a resource with it.\nA repeated box has only its name.\n*/\nconst treeNode = (node: StageTreeNode, address: string | null): string => {\n const { box, labels, repeated } = node;\n const title = `${boxName(box)}${labels.map((label) => ` <code>${escapeHtml(label)}</code>`).join(\"\")}`;\n if (repeated) {\n return title;\n }\n const linkLine =\n box.link === null || box.link === address\n ? \"\"\n : `<br><sub>${link(box.link, hostOf(box.link))}</sub>`;\n const below = [\n ...node.children.map((child) => treeNode(child, address)),\n ...box.bindings\n .filter((binding) => binding.box === null)\n .map(\n (binding) =>\n `<code>${escapeHtml(binding.name)}</code> <sub>${escapeHtml([binding.kind, binding.target].filter((part) => part !== null).join(\", \"))}</sub>`,\n ),\n ...box.folded.map(\n (row) =>\n `<sub>${escapeHtml(`${row.logicalId}, ${resourceTypeUI(row.resourceType).name}`)}</sub>`,\n ),\n ...node.shared.map((text) => `<sub>${escapeHtml(text)}</sub>`),\n ];\n const list =\n below.length === 0 ? \"\" : `<ul>${below.map((item) => `<li>${item}</li>`).join(\"\")}</ul>`;\n return `${title} <sub>${escapeHtml(boxSubtitle(box))}</sub>${linkLine}${list}`;\n};\n\n/** Where a stage serves: its Convex app, else the first box with a link. */\nconst addressOf = ({ boxes }: StageDiagram) =>\n (boxes.find((box) => box.resourceType === \"Convex.Deployment\") ?? boxes.find((box) => box.link))\n ?.link ?? null;\n\nconst runLine = ({ run }: StackCard) => {\n if (run === null) {\n return \"\";\n }\n const { headCommit, recordedAt, runUrl } = run[RUN_RECORD_KEY];\n const commit = escapeHtml(headCommit.slice(0, 7));\n const time = `${recordedAt.slice(0, 16).replace(\"T\", \" \")} UTC`;\n return `<br><sub>${runUrl === null ? commit : link(runUrl, commit)} ${escapeHtml(time)}</sub>`;\n};\n\nconst SPACER = `<div><img src=\"${ICONS}/spacer.svg\" width=\"460\" align=\"left\" alt=\"\"></div>`;\n\n/** `alone`: the one card of the repository. A card at the root then has no folder, as on the repository page. */\nconst renderCard = (card: StackCard, alone: boolean) => {\n const { folder } = card;\n const heading = [\n folder === \"\" && alone ? \"\" : `<b>${escapeHtml(folder || \"/\")}</b> `,\n `<sub>${escapeHtml(card.stage)}</sub>`,\n ].join(\"\");\n const address = addressOf(card.diagram);\n const addressLine = address === null ? \"\" : `<br>${link(address, hostOf(address))}`;\n const rows = stageTree(card.diagram)\n .map((node) => `<tbody><tr><td>${treeNode(node, address)}</td></tr></tbody>`)\n .join(\"\\n\");\n return `<table>\n<tbody><tr><td>${SPACER}${heading}${addressLine}${runLine(card)}</td></tr></tbody>\n${rows}\n</table>`;\n};\n\nexport const renderStackComment = (cards: readonly StackCard[]) => `${MARKER}\n${cards.map((card) => renderCard(card, cards.length === 1)).join(\"\\n\\n\")}\n`;\n\nconst Comments = Schema.Array(Schema.Struct({ id: Schema.Number, body: Schema.String }));\nconst SavedComment = Schema.Struct({ html_url: Schema.String });\n\nconst github = (token: string, path: string, init: { method: string; body?: string }) =>\n Effect.tryPromise({\n try: async (): Promise<unknown> => {\n const response = await fetch(`${GITHUB_API}${path}`, {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n },\n });\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n return await response.json();\n },\n catch: (error) =>\n new StackCommentError({\n reason: `GitHub ${init.method} ${path} failed (${error instanceof Error ? error.message : String(error)})`,\n }),\n });\n\nconst decode =\n <S extends Schema.Codec<unknown, unknown>>(schema: S, what: string) =>\n (value: unknown) =>\n Schema.decodeUnknownEffect(schema)(value).pipe(\n Effect.mapError(() => new StackCommentError({ reason: `GitHub gave a bad ${what}` })),\n );\n\nconst findComment = (token: string, path: string) =>\n Effect.gen(function* () {\n for (let page = 1; ; page += 1) {\n const comments = yield* github(token, `${path}?per_page=100&page=${page}`, {\n method: \"GET\",\n }).pipe(Effect.flatMap(decode(Comments, \"comment list\")));\n const comment = comments.find(({ body }) => body.startsWith(MARKER));\n if (comment !== undefined || comments.length < 100) {\n return comment;\n }\n }\n });\n\n/** Replaces the body of the comment of this command, or posts it on the first run, and gives its URL. */\nexport const saveStackComment = (args: {\n readonly token: string;\n readonly repository: string;\n readonly pullRequest: number;\n readonly body: string;\n}) =>\n Effect.gen(function* () {\n const { body, pullRequest, repository, token } = args;\n const comments = `/repos/${repository}/issues/${pullRequest}/comments`;\n const comment = yield* findComment(token, comments);\n const reply = yield* comment === undefined\n ? github(token, comments, { method: \"POST\", body: JSON.stringify({ body }) })\n : github(token, `/repos/${repository}/issues/comments/${comment.id}`, {\n method: \"PATCH\",\n body: JSON.stringify({ body }),\n });\n const saved = yield* decode(SavedComment, \"comment\")(reply);\n return saved.html_url;\n });\n\n/** The step of a workflow: the run record names the repository and the pull request of the run. */\nexport const updateStackComment = Effect.gen(function* () {\n const {\n pullRequest,\n repositoryId,\n repositoryName: repository,\n } = yield* runRecord({ cwd: process.cwd(), env: process.env });\n if (pullRequest === null) {\n return yield* new StackCommentError({ reason: \"this run has no pull request\" });\n }\n const token = process.env[\"GITHUB_TOKEN\"];\n if (token === undefined || token === \"\") {\n return yield* new StackCommentError({ reason: \"GITHUB_TOKEN is not set\" });\n }\n const cards = yield* readStackCards({ repository, repositoryId, stage: `pr-${pullRequest}` });\n return yield* saveStackComment({\n token,\n repository,\n pullRequest,\n body: renderStackComment(cards),\n });\n});\n","#!/usr/bin/env node\n// The command of the package:\n//\n// alchemy-convex stack-comment\n//\n// stack-comment runs as a step of a pull request workflow after the deploys, and keeps one comment\n// with the stacks of the repository: see src/StackComment.ts. It needs GITHUB_TOKEN, and reads the\n// store of the team of CONVEX_ACCESS_TOKEN or of the Convex CLI login.\nimport { parseArgs } from \"node:util\";\nimport * as NodeServices from \"@effect/platform-node/NodeServices\";\nimport * as Effect from \"effect/Effect\";\nimport * as Layer from \"effect/Layer\";\nimport { updateStackComment } from \"./StackComment.ts\";\nimport { state } from \"./State.ts\";\n\nconst { positionals } = parseArgs({ allowPositionals: true, options: {} });\nconst USAGE = `Usage:\n alchemy-convex stack-comment`;\n\nconst stackComment = updateStackComment.pipe(\n Effect.tap((url) => Effect.sync(() => console.log(url))),\n Effect.provide(state().pipe(Layer.provide(NodeServices.layer))),\n);\n\nif (positionals.join(\" \") !== \"stack-comment\") {\n console.error(USAGE);\n process.exit(1);\n}\n\nawait Effect.runPromise(stackComment).catch((error: unknown) => {\n console.error(error instanceof Error ? error.message : String(error));\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;AAyCA,MAAM,SAAS;;AAGf,MAAM,QACJ;AAEF,MAAM,aAAa;;AAGnB,MAAM,cAAc,OAAO,OAAO,GAC/B,iBAAiB,OAAO,OAAO;CAC9B,YAAY,OAAO;CACnB,QAAQ,OAAO,OAAO,OAAO,MAAM;CACnC,YAAY,OAAO;AACrB,CAAC,EACH,CAAC;;AAGD,MAAM,qBAAqB,OAAO,OAAO,GACtC,iBAAiB,OAAO,OAAO;CAC9B,SAAS,OAAO,QAAQ,CAAC;CACzB,cAAc,OAAO;CACrB,WAAW,OAAO;AACpB,CAAC,EACH,CAAC;AAWD,IAAa,oBAAb,cAAuC,OAAO,YAA+B,CAAC,CAC5E,qBACA,EAAE,QAAQ,OAAO,OAAO,CAC1B,CAAC,CAAC;CACA,IAAa,UAAU;EACrB,OAAO,wCAAwC,KAAK;CACtD;AACF;;;;;;AAOA,MAAa,kBAAkB,EAC7B,YACA,cACA,YAMA,OAAO,IAAI,aAAa;CAC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AAM,mBAAmB,KAAK;CAChC,CAAC;AACH,CAAC;;;ACzTD,MAAM,EAAE,gBAAgB,UAAU;CAAE,kBAAkB;CAAM,SAAS,CAAC;AAAE,CAAC;AACzE,MAAM,QAAQ;;AAGd,MAAM,eAAe,mBAAmB,KACtC,OAAO,KAAK,QAAQ,OAAO,WAAW,QAAQ,IAAI,GAAG,CAAC,CAAC,GACvD,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,MAAM,QAAQ,aAAa,KAAK,CAAC,CAAC,CAChE;AAEA,IAAI,YAAY,KAAK,GAAG,MAAM,iBAAiB;CAC7C,QAAQ,MAAM,KAAK;CACnB,QAAQ,KAAK,CAAC;AAChB;AAEA,MAAM,OAAO,WAAW,YAAY,CAAC,CAAC,OAAO,UAAmB;CAC9D,QAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,CAAC;CACpE,QAAQ,KAAK,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@samebase/alchemy-convex",
3
- "version": "0.44.0",
3
+ "version": "0.45.0",
4
4
  "description": "The Convex plane for Alchemy v2: projects, deployments, environment variables, and the push of the functions",
5
5
  "keywords": [
6
6
  "alchemy",
@@ -50,7 +50,7 @@
50
50
  },
51
51
  "dependencies": {
52
52
  "@convex-dev/platform": "0.1.11",
53
- "@samebase/alchemy-kit": "^0.6.0"
53
+ "@samebase/alchemy-kit": "^0.7.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@alchemy.run/cloudflare": "2.0.0-beta.87",
@@ -166,8 +166,9 @@ const boxName = ({ name, resourceType, rows: [first] }: DiagramBox) => {
166
166
 
167
167
  /**
168
168
  A box of the tree: its name with the labels of its line as code, its type and schedule, and its link
169
- on the next line unless the link is the stage address. Below it, in a list: the boxes that it uses, the rows folded into it, and
170
- the boxes that share a resource with it. A repeated box has only its name.
169
+ on the next line unless the link is the stage address. Below it, in a list: the boxes that it uses,
170
+ its bindings that name no box, the rows folded into it, and the boxes that share a resource with it.
171
+ A repeated box has only its name.
171
172
  */
172
173
  const treeNode = (node: StageTreeNode, address: string | null): string => {
173
174
  const { box, labels, repeated } = node;
@@ -181,6 +182,12 @@ const treeNode = (node: StageTreeNode, address: string | null): string => {
181
182
  : `<br><sub>${link(box.link, hostOf(box.link))}</sub>`;
182
183
  const below = [
183
184
  ...node.children.map((child) => treeNode(child, address)),
185
+ ...box.bindings
186
+ .filter((binding) => binding.box === null)
187
+ .map(
188
+ (binding) =>
189
+ `<code>${escapeHtml(binding.name)}</code> <sub>${escapeHtml([binding.kind, binding.target].filter((part) => part !== null).join(", "))}</sub>`,
190
+ ),
184
191
  ...box.folded.map(
185
192
  (row) =>
186
193
  `<sub>${escapeHtml(`${row.logicalId}, ${resourceTypeUI(row.resourceType).name}`)}</sub>`,