-
Notifications
You must be signed in to change notification settings - Fork 174
feat(numscript): immutable append-only versioned library (EN-1288) #1529
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
Open
Azorlogh
wants to merge
13
commits into
release/v3.0
Choose a base branch
from
feat/numscript-versions-restore
base: release/v3.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c8be0c1
feat(numscript): immutable append-only versioned library (EN-1288)
Azorlogh 3b10292
fix(numscript): address review findings on the rescoped library
Azorlogh 63b5c41
fix(numscript): require explicit --version on ledgerctl numscripts save
Azorlogh d40c15e
fix(numscript): reject same-version content edits in ledgers config diff
Azorlogh 723fbc3
docs(numscript): correct stale NumscriptReference version-resolution …
Azorlogh ce31f17
fix(numscript): reject non-canonical semver versions
Azorlogh ab8c2ee
fix(numscript): validate version in ledgers config diff
Azorlogh ed24571
fix(numscript): reject downgrade in ledgers config diff
Azorlogh c1da3a2
fix(check): flag surplus numscript rows under archiving
Azorlogh 3b9b2c0
fix(numscript): error on numscript removal in ledgers config diff
Azorlogh ec06057
fix(check): derive baseline numscript latest from content, not the st…
Azorlogh 6e1d8cd
chore(proto): drop numscript delete/restore reservations (RULE 12)
Azorlogh 6128f9f
chore(numscript): scrub remaining alpha-model leftovers
Azorlogh 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| package numscripts | ||
|
|
||
| import ( | ||
| "github.com/pterm/pterm" | ||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/formancehq/ledger/v3/cmd/ledgerctl/cmdutil" | ||
| "github.com/formancehq/ledger/v3/internal/proto/servicepb" | ||
| ) | ||
|
|
||
| // NewVersionsCommand creates the numscripts versions command. | ||
| func NewVersionsCommand() *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "versions <name>", | ||
| Short: "List every stored version of a numscript", | ||
| Long: `List the current latest version (the greatest stored semver) and every | ||
| stored version of a numscript, highest semver first. | ||
|
|
||
| Examples: | ||
| ledgerctl numscripts versions transfer --ledger myledger`, | ||
| Args: cobra.ExactArgs(1), | ||
| ValidArgsFunction: cobra.NoFileCompletions, | ||
| RunE: runVersions, | ||
| } | ||
|
|
||
| cmdutil.AddConsistencyFlags(cmd) | ||
| cmdutil.AddOutputFlags(cmd) | ||
| cmd.Flags().Duration("timeout", cmdutil.DefaultTimeout, "Request timeout") | ||
|
|
||
| return cmd | ||
| } | ||
|
|
||
| func runVersions(cmd *cobra.Command, args []string) error { | ||
| name := args[0] | ||
|
|
||
| client, conn, err := cmdutil.GetClient(cmd) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| defer func() { _ = conn.Close() }() | ||
|
|
||
| ledgerFlag, _ := cmd.Flags().GetString("ledger") | ||
| ledgerName, err := cmdutil.SelectLedger(cmd, client, ledgerFlag) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| ctx, cancel := cmdutil.GetContext(cmd) | ||
| defer cancel() | ||
|
|
||
| resp, err := client.ListNumscriptVersions(ctx, &servicepb.ListNumscriptVersionsRequest{ | ||
| Ledger: ledgerName, | ||
| Name: name, | ||
| Read: cmdutil.BuildReadOptions(cmdutil.GetConsistencyFlags(cmd)), | ||
| }) | ||
| if err != nil { | ||
| return cmdutil.FormatGRPCError("failed to list numscript versions", err) | ||
| } | ||
|
|
||
| versions := resp.GetVersions() | ||
|
|
||
| if handled, err := cmdutil.EncodeStructured(cmd, resp); handled || err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if len(versions) == 0 { | ||
| pterm.Info.Printfln("No versions stored for numscript %s on ledger %s.", name, ledgerName) | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| pterm.Printf("Latest: %s\n\n", pterm.Cyan(resp.GetLatestVersion())) | ||
|
|
||
| tableData := pterm.TableData{ | ||
| {"VERSION", "CREATED AT"}, | ||
| } | ||
|
|
||
| for _, v := range versions { | ||
| createdAt := "" | ||
| if v.GetCreatedAt() != nil { | ||
| createdAt = v.GetCreatedAt().AsTime().Format("2006-01-02T15:04:05Z07:00") | ||
| } | ||
|
|
||
| tableData = append(tableData, []string{ | ||
| v.GetVersion(), | ||
| createdAt, | ||
| }) | ||
| } | ||
|
|
||
| if err := pterm.DefaultTable.WithHasHeader().WithData(tableData).Render(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| pterm.Println() | ||
|
|
||
| return nil | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.