@rivascva/dt-idl 1.1.112 → 1.1.113

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/go/auth/jwt.go CHANGED
@@ -17,15 +17,12 @@ func ValidateToken(token string, secret string) (*jwt.Token, ValidationError) {
17
17
  // validate the token
18
18
  parsedToken, err := parser.Parse(token, func(t *jwt.Token) (any, error) { return []byte(secret), nil })
19
19
  if err != nil {
20
- return nil, fmt.Errorf("unable to validate the token: %w", err)
20
+ return nil, ErrorInvalidToken
21
21
  }
22
22
 
23
23
  // validate the token expiration time
24
24
  expirationTime, err := parsedToken.Claims.GetExpirationTime()
25
- if err != nil {
26
- return nil, fmt.Errorf("failed to get the expiration time from the token: %w", err)
27
- }
28
- if expirationTime.Before(time.Now()) {
25
+ if err != nil || expirationTime.Before(time.Now()) {
29
26
  return nil, ErrorExpiredToken
30
27
  }
31
28
 
package/go/auth/models.go CHANGED
@@ -24,6 +24,8 @@ var approvedServices = []string{"dt-trade-service", "dt-portfolio-service", "dt-
24
24
  type ValidationError = error
25
25
 
26
26
  var (
27
+ // ErrorInvalidToken is returned when a token is invalid.
28
+ ErrorInvalidToken ValidationError = errors.New("invalid token")
27
29
  // ErrorExpiredToken is returned when a token is expired.
28
30
  ErrorExpiredToken ValidationError = errors.New("expired token")
29
31
  )
@@ -0,0 +1,41 @@
1
+ package psql
2
+
3
+ import (
4
+ "github.com/Masterminds/squirrel"
5
+ )
6
+
7
+ // sq is a PostgreSQL query statement builder.
8
+ var sq = squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar)
9
+
10
+ // returnAllSuffix is a PostgreSQL suffix that returns all affected rows.
11
+ const returnAllSuffix = "RETURNING *"
12
+
13
+ // Entries represents the database column/value entries.
14
+ type Entries = map[string]any
15
+
16
+ // Where is for the where selector.
17
+ type Where = any
18
+
19
+ // Equal is for the equal syntax in where selectors.
20
+ type Equal = squirrel.Eq
21
+
22
+ // NotEqual is for the not equal syntax in where selectors.
23
+ type NotEqual = squirrel.NotEq
24
+
25
+ // LessThan is for the less than syntax in where selectors.
26
+ type LessThan = squirrel.Lt
27
+
28
+ // LessThanEqual is for the less than or equal syntax in where selectors.
29
+ type LessThanEqual = squirrel.LtOrEq
30
+
31
+ // GreaterThan is for the greater than syntax in where selectors.
32
+ type GreaterThan = squirrel.Gt
33
+
34
+ // GreaterThanEqual is for the greater than or equal syntax in where selectors.
35
+ type GreaterThanEqual = squirrel.GtOrEq
36
+
37
+ // Like is for the like syntax in where selectors.
38
+ type Like = squirrel.Like
39
+
40
+ // NotLike is for the not like syntax in where selectors.
41
+ type NotLike = squirrel.NotLike
@@ -0,0 +1,81 @@
1
+ package psql
2
+
3
+ import (
4
+ "reflect"
5
+ )
6
+
7
+ // GetEntries gets the database column/value entries from the given struct.
8
+ // It extracts the column names from the "db" tag in the struct.
9
+ // Omits the given database columns.
10
+ func GetEntries(v any, omit ...string) Entries {
11
+ // convert the struct into a reflect value
12
+ values := reflect.ValueOf(v)
13
+ types := values.Type()
14
+
15
+ // initiate helper variables
16
+ numFields := values.NumField()
17
+ entries := make(Entries, numFields)
18
+
19
+ // fill the entries map
20
+ for i := range numFields {
21
+ tag := types.Field(i).Tag.Get("db")
22
+ val := values.Field(i).Interface()
23
+ entries[tag] = val
24
+ }
25
+
26
+ // delete any omitted columns
27
+ for _, tag := range omit {
28
+ delete(entries, tag)
29
+ }
30
+
31
+ return entries
32
+ }
33
+
34
+ // GetSelectAllQuery builds and returns the query and arguments to perform a select all query on the given table.
35
+ // Provide a where map to specify which rows to select. A nil value will select all rows.
36
+ func GetSelectAllQuery(table string, where ...Where) (string, []any, error) {
37
+ builder := sq.Select("*").From(table)
38
+ for _, mp := range where {
39
+ builder = builder.Where(mp)
40
+ }
41
+ return builder.ToSql()
42
+ }
43
+
44
+ // GetSelectColumnQuery builds and returns the query and arguments to perform a select column query on the given table.
45
+ // Provide a where map to specify which rows to select. A nil value will select all rows.
46
+ func GetSelectColumnQuery(table string, column string, where ...Where) (string, []any, error) {
47
+ builder := sq.Select(column).From(table)
48
+ for _, mp := range where {
49
+ builder = builder.Where(mp)
50
+ }
51
+ return builder.ToSql()
52
+ }
53
+
54
+ // GetInsertQuery builds and returns the query and arguments to perform an insert query on the given table.
55
+ // Get the table entries using the "GetEntries" method.
56
+ func GetInsertQuery(table string, entries Entries) (string, []any, error) {
57
+ builder := sq.Insert(table).SetMap(entries).Suffix(returnAllSuffix)
58
+ return builder.ToSql()
59
+ }
60
+
61
+ // GetUpdateQuery builds and returns the query and arguments to perform an update query on the given table.
62
+ // Provide a where map to specify which rows to update.
63
+ // Get the table entries using the "GetEntries" method.
64
+ func GetUpdateQuery(table string, entries Entries, where ...Where) (string, []any, error) {
65
+ builder := sq.Update(table).SetMap(entries)
66
+ for _, mp := range where {
67
+ builder = builder.Where(mp)
68
+ }
69
+ builder = builder.Suffix(returnAllSuffix)
70
+ return builder.ToSql()
71
+ }
72
+
73
+ // GetDeleteQuery builds and returns the query and arguments to perform a delete query on the given table.
74
+ // Provide a where map to specify which rows to delete.
75
+ func GetDeleteQuery(table string, where ...Where) (string, []any, error) {
76
+ builder := sq.Delete(table)
77
+ for _, mp := range where {
78
+ builder = builder.Where(mp)
79
+ }
80
+ return builder.ToSql()
81
+ }
package/go.mod CHANGED
@@ -3,6 +3,12 @@ module github.com/RivasCVA/dt-idl
3
3
  go 1.23
4
4
 
5
5
  require (
6
+ github.com/Masterminds/squirrel v1.5.4
6
7
  github.com/golang-jwt/jwt/v5 v5.2.2
7
8
  github.com/google/uuid v1.6.0
8
9
  )
10
+
11
+ require (
12
+ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
13
+ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
14
+ )
package/go.sum CHANGED
@@ -1,4 +1,16 @@
1
+ github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
2
+ github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
3
+ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4
+ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1
5
  github.com/golang-jwt/jwt/v5 v5.2.2 h1:Rl4B7itRWVtYIHFrSNd7vhTiz9UpLdi6gZhZ3wEeDy8=
2
6
  github.com/golang-jwt/jwt/v5 v5.2.2/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
3
7
  github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
4
8
  github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9
+ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 h1:SOEGU9fKiNWd/HOJuq6+3iTQz8KNCLtVX6idSoTLdUw=
10
+ github.com/lann/builder v0.0.0-20180802200727-47ae307949d0/go.mod h1:dXGbAdH5GtBTC4WfIxhKZfyBF/HBFgRZSWwZ9g/He9o=
11
+ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 h1:P6pPBnrTSX3DEVR4fDembhRWSsG5rVo6hYhAB/ADZrk=
12
+ github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0/go.mod h1:vmVJ0l/dxyfGW6FmdpVm2joNMFikkuWg0EoCKLGUMNw=
13
+ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14
+ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15
+ github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
16
+ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rivascva/dt-idl",
3
- "version": "1.1.112",
3
+ "version": "1.1.113",
4
4
  "description": "Dream Trade - Interface Definition Language",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",