-
Notifications
You must be signed in to change notification settings - Fork 0
✨ Let a workflow definition name one section of its document #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+401
−6
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -16,17 +16,35 @@ | |||
| */ | ||||
|
|
||||
| import { Err, Ok, type Result } from "effection"; | ||||
| import { isCanonicalDocumentTarget } from "@executablemd/core"; | ||||
| import type { Json } from "@executablemd/durable-streams"; | ||||
| import { WorkflowDefinitionError } from "./errors.ts"; | ||||
| import { describe, parseMembers, parseStringMember, requireMemberNames } from "./members.ts"; | ||||
| import { | ||||
| describe, | ||||
| type Members, | ||||
| parseMembers, | ||||
| parseStringMember, | ||||
| requireMemberNames, | ||||
| } from "./members.ts"; | ||||
|
|
||||
| /** A document at a path inside one immutable Git object. */ | ||||
| /** | ||||
| * A document at a path inside one immutable Git object, optionally projected to | ||||
| * one of its sections. | ||||
| * | ||||
| * `targetPath` is the *resolved exact* canonical document target, never the | ||||
| * selector a caller wrote: two callers may spell one request differently, and a | ||||
| * glob re-resolved against a different checkout would name a different section. | ||||
| * Absent, it identifies the whole document — which is what a whole-document | ||||
| * workflow is, not a legacy spelling of a targeted one. | ||||
| */ | ||||
| export interface GitWorkflowDefinitionV1 { | ||||
| readonly version: 1; | ||||
| readonly kind: "git"; | ||||
| readonly objectFormat: "sha1" | "sha256"; | ||||
| readonly objectId: string; | ||||
| readonly rootDocumentPath: string; | ||||
| /** One exact canonical document target, without a leading `#`. */ | ||||
| readonly targetPath?: string; | ||||
| } | ||||
|
|
||||
| /** Every descriptor this build understands. */ | ||||
|
|
@@ -38,7 +56,14 @@ const OBJECT_ID_LENGTHS: Readonly<Record<GitWorkflowDefinitionV1["objectFormat"] | |||
| sha256: 64, | ||||
| }; | ||||
|
|
||||
| const MEMBER_NAMES = ["version", "kind", "objectFormat", "objectId", "rootDocumentPath"]; | ||||
| const MEMBER_NAMES = [ | ||||
| "version", | ||||
| "kind", | ||||
| "objectFormat", | ||||
| "objectId", | ||||
| "rootDocumentPath", | ||||
| "targetPath", | ||||
| ]; | ||||
|
|
||||
| function fail(reason: string, path: string): Error { | ||||
| return new WorkflowDefinitionError(reason, path); | ||||
|
|
@@ -77,6 +102,7 @@ function parseDefinition(value: unknown): WorkflowDefinition { | |||
| } | ||||
|
|
||||
| const objectFormat = parseObjectFormat(members.get("objectFormat")); | ||||
| const targetPath = parseTargetPath(members); | ||||
|
|
||||
| return { | ||||
| version: 1, | ||||
|
|
@@ -86,9 +112,39 @@ function parseDefinition(value: unknown): WorkflowDefinition { | |||
| rootDocumentPath: parseRootDocumentPath( | ||||
| parseStringMember(members, "rootDocumentPath", "$", fail), | ||||
| ), | ||||
| ...(targetPath === undefined ? {} : { targetPath }), | ||||
| }; | ||||
| } | ||||
|
|
||||
| /** | ||||
| * The exact target this descriptor names, if it names one. | ||||
| * | ||||
| * Presence is the member being written at all, not its value: a descriptor that | ||||
| * wrote `targetPath` and gave it `undefined` or `null` asked for a target and | ||||
| * failed to say which, which is not the same as asking for the whole document. | ||||
| * | ||||
| * What counts as canonical is core's own predicate, not a rule restated here. | ||||
| * Identity that two packages define separately is identity they can disagree | ||||
| * about, and this member is compared against targets the document layer | ||||
| * produced. | ||||
| */ | ||||
| function parseTargetPath(members: Members): string | undefined { | ||||
| if (!members.has("targetPath")) { | ||||
| return undefined; | ||||
| } | ||||
| const path = "$.targetPath"; | ||||
| const value = members.get("targetPath"); | ||||
| if (typeof value !== "string") { | ||||
| throw fail(`expected a string, found ${describe(value)}`, path); | ||||
| } | ||||
| // Deliberately says nothing about the target it read: a canonical target | ||||
| // encodes heading text, and heading text is document content. | ||||
| if (!isCanonicalDocumentTarget(value)) { | ||||
| throw fail("expected one exact canonical document target", path); | ||||
| } | ||||
| return value; | ||||
| } | ||||
|
|
||||
| /** | ||||
| * The descriptor as a plain JSON value. | ||||
| * | ||||
|
|
@@ -103,6 +159,10 @@ export function definitionToJson(definition: WorkflowDefinition): Json { | |||
| objectFormat: definition.objectFormat, | ||||
| objectId: definition.objectId, | ||||
| rootDocumentPath: definition.rootDocumentPath, | ||||
| // Written only when there is one. An untargeted definition that stored an | ||||
| // explicit absence would parse back as a descriptor that asked for a target | ||||
| // and failed to name it. | ||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant comment — restates what the code does.
Suggested change
|
||||
| ...(definition.targetPath === undefined ? {} : { targetPath: definition.targetPath }), | ||||
| }; | ||||
| } | ||||
|
|
||||
|
|
||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant comment — restates what the code does.