Skip to content

Commit

Permalink
feat: add generator set
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Nov 19, 2024
1 parent 7023481 commit 18d7e1c
Show file tree
Hide file tree
Showing 43 changed files with 712 additions and 403 deletions.
46 changes: 46 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,52 @@ To perform this operation, you must be authenticated by means of one of the foll
Authorization ( Scopes: ledger:read )
</aside>

## Read in memory metrics

<a id="opIdgetMetrics"></a>

> Code samples
```http
GET http://localhost:8080/_/metrics HTTP/1.1
Host: localhost:8080
Accept: application/json
```

`GET /_/metrics`

> Example responses
> 200 Response
```json
{
"property1": null,
"property2": null
}
```

<h3 id="read-in-memory-metrics-responses">Responses</h3>

|Status|Meaning|Description|Schema|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|OK|Inline|
|default|Default|Error|[V2ErrorResponse](#schemav2errorresponse)|

<h3 id="read-in-memory-metrics-responseschema">Response Schema</h3>

Status Code **200**

|Name|Type|Required|Restrictions|Description|
|---|---|---|---|---|
|» **additionalProperties**|any|false|none|none|

<aside class="warning">
To perform this operation, you must be authenticated by means of one of the following methods:
Authorization ( Scopes: ledger:read )
</aside>

<h1 id="ledger-api-ledger-v2">ledger.v2</h1>

## List ledgers
Expand Down
120 changes: 8 additions & 112 deletions internal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ import "github.com/formancehq/ledger/internal"
- [type ErrInvalidLedgerName](<#ErrInvalidLedgerName>)
- [func \(e ErrInvalidLedgerName\) Error\(\) string](<#ErrInvalidLedgerName.Error>)
- [func \(e ErrInvalidLedgerName\) Is\(err error\) bool](<#ErrInvalidLedgerName.Is>)
- [type FeatureSet](<#FeatureSet>)
- [func \(f FeatureSet\) Match\(features FeatureSet\) bool](<#FeatureSet.Match>)
- [func \(f FeatureSet\) SortedKeys\(\) \[\]string](<#FeatureSet.SortedKeys>)
- [func \(f FeatureSet\) String\(\) string](<#FeatureSet.String>)
- [func \(f FeatureSet\) With\(feature, value string\) FeatureSet](<#FeatureSet.With>)
- [type Ledger](<#Ledger>)
- [func MustNewWithDefault\(name string\) Ledger](<#MustNewWithDefault>)
- [func New\(name string, configuration Configuration\) \(\*Ledger, error\)](<#New>)
Expand Down Expand Up @@ -116,40 +111,20 @@ import "github.com/formancehq/ledger/internal"

## Constants

<a name="FeatureMovesHistory"></a>
<a name="MetaTargetTypeAccount"></a>

```go
const (
// FeatureMovesHistory is used to define if the ledger has to save funds movements history.
// Value is either ON or OFF
FeatureMovesHistory = "MOVES_HISTORY"
// FeatureMovesHistoryPostCommitEffectiveVolumes is used to define if the pvce property of funds movements history
// has to be updated with back dated transaction.
// Value is either SYNC or DISABLED.
// todo: depends on FeatureMovesHistory (dependency should be checked)
FeatureMovesHistoryPostCommitEffectiveVolumes = "MOVES_HISTORY_POST_COMMIT_EFFECTIVE_VOLUMES"
// FeatureHashLogs is used to defined it the logs has to be hashed.
FeatureHashLogs = "HASH_LOGS"
// FeatureAccountMetadataHistory is used to defined it the account metadata must be historized.
FeatureAccountMetadataHistory = "ACCOUNT_METADATA_HISTORY"
// FeatureTransactionMetadataHistory is used to defined it the transaction metadata must be historized.
FeatureTransactionMetadataHistory = "TRANSACTION_METADATA_HISTORY"
// FeatureIndexAddressSegments is used to defined it we want to index segments of accounts address.
// Without this feature, the ledger will not allow filtering on partial account address.
FeatureIndexAddressSegments = "INDEX_ADDRESS_SEGMENTS"
// FeatureIndexTransactionAccounts is used to defined it we want to index accounts used in a transaction.
FeatureIndexTransactionAccounts = "INDEX_TRANSACTION_ACCOUNTS"

DefaultBucket = "_default"
MetaTargetTypeAccount = "ACCOUNT"
MetaTargetTypeTransaction = "TRANSACTION"
)
```

<a name="MetaTargetTypeAccount"></a>
<a name="DefaultBucket"></a>

```go
const (
MetaTargetTypeAccount = "ACCOUNT"
MetaTargetTypeTransaction = "TRANSACTION"
DefaultBucket = "_default"
)
```

Expand All @@ -163,40 +138,6 @@ const (

## Variables

<a name="DefaultFeatures"></a>

```go
var (
DefaultFeatures = FeatureSet{
FeatureMovesHistory: "ON",
FeatureMovesHistoryPostCommitEffectiveVolumes: "SYNC",
FeatureHashLogs: "SYNC",
FeatureAccountMetadataHistory: "SYNC",
FeatureTransactionMetadataHistory: "SYNC",
FeatureIndexAddressSegments: "ON",
FeatureIndexTransactionAccounts: "ON",
}
MinimalFeatureSet = FeatureSet{
FeatureMovesHistory: "OFF",
FeatureMovesHistoryPostCommitEffectiveVolumes: "DISABLED",
FeatureHashLogs: "DISABLED",
FeatureAccountMetadataHistory: "DISABLED",
FeatureTransactionMetadataHistory: "DISABLED",
FeatureIndexAddressSegments: "OFF",
FeatureIndexTransactionAccounts: "OFF",
}
FeatureConfigurations = map[string][]string{
FeatureMovesHistory: {"ON", "OFF"},
FeatureMovesHistoryPostCommitEffectiveVolumes: {"SYNC", "DISABLED"},
FeatureHashLogs: {"SYNC", "DISABLED"},
FeatureAccountMetadataHistory: {"SYNC", "DISABLED"},
FeatureTransactionMetadataHistory: {"SYNC", "DISABLED"},
FeatureIndexAddressSegments: {"ON", "OFF"},
FeatureIndexTransactionAccounts: {"ON", "OFF"},
}
)
```

<a name="Zero"></a>

```go
Expand Down Expand Up @@ -281,9 +222,9 @@ type BalancesByAssetsByAccounts map[string]BalancesByAssets

```go
type Configuration struct {
Bucket string `json:"bucket" bun:"bucket,type:varchar(255)"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb"`
Features FeatureSet `json:"features" bun:"features,type:jsonb"`
Bucket string `json:"bucket" bun:"bucket,type:varchar(255)"`
Metadata metadata.Metadata `json:"metadata" bun:"metadata,type:jsonb"`
Features features.FeatureSet `json:"features" bun:"features,type:jsonb"`
}
```

Expand Down Expand Up @@ -433,51 +374,6 @@ func (e ErrInvalidLedgerName) Is(err error) bool



<a name="FeatureSet"></a>
## type FeatureSet



```go
type FeatureSet map[string]string
```

<a name="FeatureSet.Match"></a>
### func \(FeatureSet\) Match

```go
func (f FeatureSet) Match(features FeatureSet) bool
```



<a name="FeatureSet.SortedKeys"></a>
### func \(FeatureSet\) SortedKeys

```go
func (f FeatureSet) SortedKeys() []string
```



<a name="FeatureSet.String"></a>
### func \(FeatureSet\) String

```go
func (f FeatureSet) String() string
```



<a name="FeatureSet.With"></a>
### func \(FeatureSet\) With

```go
func (f FeatureSet) With(feature, value string) FeatureSet
```



<a name="Ledger"></a>
## type Ledger

Expand Down
2 changes: 1 addition & 1 deletion internal/api/common/mocks.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/system/controller.go -destination mocks_system_controller_test.go -package common --mock_names Controller=SystemController . Controller
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/ledger/controller.go -destination mocks_ledger_controller_test.go -package common --mock_names Controller=LedgerController . Controller
package common
package common
2 changes: 1 addition & 1 deletion internal/api/v1/mocks.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/system/controller.go -destination mocks_system_controller_test.go -package v1 --mock_names Controller=SystemController . Controller
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/ledger/controller.go -destination mocks_ledger_controller_test.go -package v1 --mock_names Controller=LedgerController . Controller
package v1
package v1
2 changes: 1 addition & 1 deletion internal/api/v2/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ func getPaginatedQueryOptionsOfFiltersForVolumes(r *http.Request) (*ledgercontro
return pointer.For(ledgercontroller.NewPaginatedQueryOptions(*filtersForVolumes).
WithPageSize(pageSize).
WithQueryBuilder(qb)), nil
}
}
16 changes: 8 additions & 8 deletions internal/api/v2/errors.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package v2

const (
ErrConflict = "CONFLICT"
ErrInsufficientFund = "INSUFFICIENT_FUND"
ErrValidation = "VALIDATION"
ErrAlreadyRevert = "ALREADY_REVERT"
ErrNoPostings = "NO_POSTINGS"
ErrCompilationFailed = "COMPILATION_FAILED"
ErrMetadataOverride = "METADATA_OVERRIDE"
ErrBulkSizeExceeded = "BULK_SIZE_EXCEEDED"
ErrConflict = "CONFLICT"
ErrInsufficientFund = "INSUFFICIENT_FUND"
ErrValidation = "VALIDATION"
ErrAlreadyRevert = "ALREADY_REVERT"
ErrNoPostings = "NO_POSTINGS"
ErrCompilationFailed = "COMPILATION_FAILED"
ErrMetadataOverride = "METADATA_OVERRIDE"
ErrBulkSizeExceeded = "BULK_SIZE_EXCEEDED"
ErrLedgerAlreadyExists = "LEDGER_ALREADY_EXISTS"

ErrInterpreterParse = "INTERPRETER_PARSE"
Expand Down
2 changes: 1 addition & 1 deletion internal/api/v2/mocks.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/system/controller.go -destination mocks_system_controller_test.go -package v2 --mock_names Controller=SystemController . Controller
//go:generate mockgen -write_source_comment=false -write_package_comment=false -source ../../controller/ledger/controller.go -destination mocks_ledger_controller_test.go -package v2 --mock_names Controller=LedgerController . Controller
package v2
package v2
3 changes: 2 additions & 1 deletion internal/controller/ledger/controller_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"github.com/formancehq/ledger/pkg/features"
"math/big"
"reflect"

Expand Down Expand Up @@ -210,7 +211,7 @@ func (ctrl *DefaultController) importLog(ctx context.Context, sqlTx TX, log ledg
return fmt.Errorf("failed to insert log: %w", err)
}

if ctrl.ledger.HasFeature(ledger.FeatureHashLogs, "SYNC") {
if ctrl.ledger.HasFeature(features.FeatureHashLogs, "SYNC") {
if !reflect.DeepEqual(log.Hash, logCopy.Hash) {
return newErrInvalidHash(log.ID, logCopy.Hash, log.Hash)
}
Expand Down
3 changes: 2 additions & 1 deletion internal/controller/system/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package system

import (
"context"
"github.com/formancehq/ledger/pkg/features"
"reflect"
"time"

Expand Down Expand Up @@ -89,7 +90,7 @@ func (ctrl *DefaultController) CreateLedger(ctx context.Context, name string, co
configuration.SetDefaults()

if !ctrl.enableFeatures {
if !reflect.DeepEqual(configuration.Features, ledger.DefaultFeatures) {
if !reflect.DeepEqual(configuration.Features, features.DefaultFeatures) {
return ErrExperimentalFeaturesDisabled
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controller/system/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

var (
ErrLedgerAlreadyExists = errors.New("ledger already exists")
ErrLedgerAlreadyExists = errors.New("ledger already exists")
ErrExperimentalFeaturesDisabled = errors.New("experimental features are disabled")
)

Expand All @@ -27,4 +27,4 @@ func newErrInvalidLedgerConfiguration(err error) ErrInvalidLedgerConfiguration {
return ErrInvalidLedgerConfiguration{
err: err,
}
}
}
2 changes: 1 addition & 1 deletion internal/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ func (e ErrInvalidBucketName) Is(err error) bool {

func newErrInvalidBucketName(bucket string, err error) ErrInvalidBucketName {
return ErrInvalidBucketName{err: err, bucket: bucket}
}
}
Loading

0 comments on commit 18d7e1c

Please sign in to comment.