ondc-code-generator 0.7.0 → 0.7.3
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/README.md +6 -0
- package/dist/bin/cli-tool.d.ts +70 -0
- package/dist/bin/cli-tool.js +310 -0
- package/dist/bin/cli.d.ts +2 -0
- package/dist/bin/cli.js +80 -0
- package/dist/generator/config-compiler.d.ts +1 -0
- package/dist/generator/config-compiler.js +10 -2
- package/dist/generator/generators/{golang → go}/go-ast.js +2 -2
- package/dist/generator/generators/go/go-generator.d.ts +13 -0
- package/dist/generator/generators/go/go-generator.js +322 -0
- package/dist/generator/generators/go/templates/api-tests.mustache +65 -0
- package/dist/generator/generators/go/templates/go-mod.mustache +3 -0
- package/dist/generator/generators/go/templates/index.mustache +34 -0
- package/dist/generator/generators/go/templates/json-normalizer.mustache +155 -0
- package/dist/generator/generators/go/templates/json-path-utils.mustache +63 -0
- package/dist/generator/generators/go/templates/storage-templates/api-save-utils.mustache +84 -0
- package/dist/generator/generators/go/templates/storage-templates/api-save.mustache +44 -0
- package/dist/generator/generators/go/templates/storage-templates/index.mustache +72 -0
- package/dist/generator/generators/go/templates/storage-templates/save-utils.mustache +75 -0
- package/dist/generator/generators/{golang → go}/templates/storage-templates/storage-interface.mustache +33 -22
- package/dist/generator/generators/go/templates/test-config.mustache +62 -0
- package/dist/generator/generators/go/templates/test-object.mustache +52 -0
- package/dist/generator/generators/go/templates/validation-code.mustache +66 -0
- package/dist/generator/generators/go/templates/validation-utils.mustache +321 -0
- package/dist/generator/generators/typescript/templates/index.mustache +1 -1
- package/dist/generator/generators/typescript/ts-generator.js +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/index.test.js +1 -0
- package/dist/types/build.d.ts +2 -0
- package/dist/types/compiler-types.d.ts +1 -1
- package/dist/types/compiler-types.js +1 -1
- package/dist/utils/fs-utils.d.ts +1 -0
- package/dist/utils/fs-utils.js +18 -34
- package/dist/utils/general-utils/string-utils.d.ts +1 -0
- package/dist/utils/general-utils/string-utils.js +11 -0
- package/package.json +5 -1
- package/alpha/possible-json-paths.json +0 -3734
- package/dist/generator/generators/golang/go-generator.d.ts +0 -23
- package/dist/generator/generators/golang/go-generator.js +0 -511
- package/dist/generator/generators/golang/templates/api-test.mustache +0 -48
- package/dist/generator/generators/golang/templates/json-normalizer.mustache +0 -46
- package/dist/generator/generators/golang/templates/json-path-utils.mustache +0 -21
- package/dist/generator/generators/golang/templates/storage-templates/api-save.mustache +0 -30
- package/dist/generator/generators/golang/templates/storage-templates/index.mustache +0 -41
- package/dist/generator/generators/golang/templates/storage-templates/save-utils.mustache +0 -37
- package/dist/generator/generators/golang/templates/storage-templates/storage-helpers.mustache +0 -51
- package/dist/generator/generators/golang/templates/storage-templates/storage-types.mustache +0 -15
- package/dist/generator/generators/golang/templates/test-config.mustache +0 -39
- package/dist/generator/generators/golang/templates/test-object.mustache +0 -39
- package/dist/generator/generators/golang/templates/validation-code.mustache +0 -51
- package/dist/generator/generators/golang/templates/validation-utils.mustache +0 -246
- /package/dist/generator/generators/{golang → go}/go-ast.d.ts +0 -0
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
package storageactions
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"L1_validations/interfaces"
|
|
6
|
-
"L1_validations/types"
|
|
7
|
-
)
|
|
8
|
-
|
|
9
|
-
// Perform{{functionName}}Save saves validation data based on the action
|
|
10
|
-
func Perform{{functionName}}Save(action, uniquePrefix string, payload map[string]interface{}, store interfaces.StorageInterface, config *types.StorageConfig) error {
|
|
11
|
-
completeConfig := types.DefaultStorageConfig()
|
|
12
|
-
if config != nil {
|
|
13
|
-
if config.RetryAttempts > 0 {
|
|
14
|
-
completeConfig.RetryAttempts = config.RetryAttempts
|
|
15
|
-
}
|
|
16
|
-
if config.RetryDelayMs > 0 {
|
|
17
|
-
completeConfig.RetryDelayMs = config.RetryDelayMs
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
switch action {
|
|
22
|
-
{{#actions}}
|
|
23
|
-
case "{{{action}}}":
|
|
24
|
-
return Store_{{{action}}}(uniquePrefix, payload, store, completeConfig)
|
|
25
|
-
{{/actions}}
|
|
26
|
-
default:
|
|
27
|
-
return fmt.Errorf("action not found: %s", action)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Perform{{functionName}}Load loads validation data based on the action
|
|
32
|
-
func Perform{{functionName}}Load(action, uniquePrefix string, store interfaces.StorageInterface) (map[string]interface{}, error) {
|
|
33
|
-
switch action {
|
|
34
|
-
{{#actions}}
|
|
35
|
-
case "{{{action}}}":
|
|
36
|
-
return LoadFor_{{{action}}}(uniquePrefix, store)
|
|
37
|
-
{{/actions}}
|
|
38
|
-
default:
|
|
39
|
-
return nil, fmt.Errorf("action not found: %s", action)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
package utils
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"time"
|
|
6
|
-
"L1_validations/interfaces"
|
|
7
|
-
"L1_validations/types"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
// SaveData saves data to storage with retry logic
|
|
11
|
-
func SaveData(uniquePrefix, key, saveData string, store interfaces.StorageInterface, config types.StorageConfig) error {
|
|
12
|
-
finalKey := key
|
|
13
|
-
retryTimes := config.RetryAttempts
|
|
14
|
-
delayMs := config.RetryDelayMs
|
|
15
|
-
attempts := 0
|
|
16
|
-
|
|
17
|
-
for attempts < retryTimes {
|
|
18
|
-
err := store.SaveKey(uniquePrefix, finalKey, saveData)
|
|
19
|
-
if err == nil {
|
|
20
|
-
return nil
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
attempts++
|
|
24
|
-
if attempts >= retryTimes {
|
|
25
|
-
return err
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
time.Sleep(time.Duration(delayMs) * time.Millisecond)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return fmt.Errorf("failed to save data after %d attempts", retryTimes)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// CreateKey creates a composite key from prefix and key
|
|
35
|
-
func CreateKey(uniquePrefix, key string) string {
|
|
36
|
-
return fmt.Sprintf("%s:%s", uniquePrefix, key)
|
|
37
|
-
}
|
package/dist/generator/generators/golang/templates/storage-templates/storage-helpers.mustache
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
package storageactions
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"encoding/json"
|
|
5
|
-
"time"
|
|
6
|
-
"L1_validations/utils"
|
|
7
|
-
"L1_validations/interfaces"
|
|
8
|
-
"L1_validations/types"
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
// SaveFunction saves a value from payload at specified path to storage
|
|
12
|
-
func SaveFunction(payload map[string]interface{}, uniquePrefix, key, path, action string, store interfaces.StorageInterface, config types.StorageConfig) error {
|
|
13
|
-
if path == "" || key == "_SELF" {
|
|
14
|
-
return nil
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
value := utils.GetJSONPath(payload, path)
|
|
18
|
-
|
|
19
|
-
data := map[string]interface{}{
|
|
20
|
-
"stored_from": action + "_action",
|
|
21
|
-
"key_path": path,
|
|
22
|
-
"value": value,
|
|
23
|
-
"timestamp": time.Now().Format(time.RFC3339),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
dataBytes, err := json.Marshal(data)
|
|
27
|
-
if err != nil {
|
|
28
|
-
return err
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return utils.SaveData(uniquePrefix, key, string(dataBytes), store, config)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// LoadFunction loads a value from storage by key
|
|
35
|
-
func LoadFunction(store interfaces.StorageInterface, uniquePrefix, key string) (interface{}, error) {
|
|
36
|
-
value, err := store.GetKey(uniquePrefix, key)
|
|
37
|
-
if err != nil {
|
|
38
|
-
return []interface{}{}, nil
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
var data map[string]interface{}
|
|
42
|
-
if err := json.Unmarshal([]byte(value), &data); err != nil {
|
|
43
|
-
return []interface{}{}, nil
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if val, ok := data["value"]; ok {
|
|
47
|
-
return val, nil
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return []interface{}{}, nil
|
|
51
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
package types
|
|
2
|
-
|
|
3
|
-
// StorageConfig holds configuration for storage retry behavior
|
|
4
|
-
type StorageConfig struct {
|
|
5
|
-
RetryAttempts int // Number of retry attempts for failed operations
|
|
6
|
-
RetryDelayMs int // Delay in milliseconds between retry attempts
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// DefaultStorageConfig returns the default storage configuration
|
|
10
|
-
func DefaultStorageConfig() StorageConfig {
|
|
11
|
-
return StorageConfig{
|
|
12
|
-
RetryAttempts: 3,
|
|
13
|
-
RetryDelayMs: 1000,
|
|
14
|
-
}
|
|
15
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
package types
|
|
2
|
-
|
|
3
|
-
import "L1_validations/interfaces"
|
|
4
|
-
|
|
5
|
-
// ValidationConfig holds configuration for validation execution
|
|
6
|
-
type ValidationConfig struct {
|
|
7
|
-
OnlyInvalid bool `json:"only_invalid"`
|
|
8
|
-
StandardLogs bool `json:"standard_logs"`
|
|
9
|
-
Debug bool `json:"_debug"`
|
|
10
|
-
HideParentErrors bool `json:"hide_parent_errors"`
|
|
11
|
-
StateFullValidations bool `json:"state_full_validations"`
|
|
12
|
-
Store interfaces.StorageInterface `json:"-"`
|
|
13
|
-
StorageConfig *StorageConfig `json:"storage_config,omitempty"`
|
|
14
|
-
UniqueKey string `json:"unique_key,omitempty"`
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// ValidationInput is the input structure for validation functions
|
|
18
|
-
type ValidationInput struct {
|
|
19
|
-
Payload map[string]interface{} `json:"payload"`
|
|
20
|
-
ExternalData map[string]interface{} `json:"external_data"`
|
|
21
|
-
Config ValidationConfig `json:"config"`
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// ValidationOutput represents a single validation result
|
|
25
|
-
type ValidationOutput struct {
|
|
26
|
-
TestName string `json:"test_name,omitempty"`
|
|
27
|
-
Valid bool `json:"valid"`
|
|
28
|
-
Code int `json:"code"`
|
|
29
|
-
Description string `json:"description,omitempty"`
|
|
30
|
-
DebugInfo map[string]interface{} `json:"_debug_info,omitempty"`
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ExternalData structure
|
|
34
|
-
type ExternalData struct {
|
|
35
|
-
{{#externalData}}
|
|
36
|
-
{{name}} interface{} `json:"{{name}}"`
|
|
37
|
-
{{/externalData}}
|
|
38
|
-
Self interface{} `json:"_SELF"`
|
|
39
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
func {{name}}(input types.ValidationInput) []types.ValidationOutput {
|
|
2
|
-
scope := utils.GetJSONPath(input.Payload, "{{{scopePath}}}")
|
|
3
|
-
subResults := []types.ValidationOutput{}
|
|
4
|
-
valid := true
|
|
5
|
-
|
|
6
|
-
for _, testObjRaw := range scope {
|
|
7
|
-
testObj, ok := testObjRaw.(map[string]interface{})
|
|
8
|
-
if !ok {
|
|
9
|
-
continue
|
|
10
|
-
}
|
|
11
|
-
testObj["_EXTERNAL"] = input.ExternalData
|
|
12
|
-
|
|
13
|
-
{{#variables}}
|
|
14
|
-
{{name}} {{#isAssignment}}={{/isAssignment}}{{^isAssignment}}:={{/isAssignment}} {{{value}}}
|
|
15
|
-
{{^isAssignment}}utils.UNUSED({{name}}){{/isAssignment}}
|
|
16
|
-
{{/variables}}
|
|
17
|
-
|
|
18
|
-
{{#hasContinue}}
|
|
19
|
-
skipCheck := {{{skipCheckStatement}}}
|
|
20
|
-
if skipCheck {
|
|
21
|
-
continue
|
|
22
|
-
}
|
|
23
|
-
{{/hasContinue}}
|
|
24
|
-
|
|
25
|
-
{{{validationCode}}}
|
|
26
|
-
// delete(testObj, "_EXTERNAL")
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return append([]types.ValidationOutput{
|
|
30
|
-
{
|
|
31
|
-
TestName: "{{testName}}",
|
|
32
|
-
Valid: valid,
|
|
33
|
-
Code: func() int { if valid { return {{successCode}} } else { return {{errorCode}} } }(),
|
|
34
|
-
DebugInfo: map[string]interface{}{
|
|
35
|
-
"fed_config": `{{{TEST_OBJECT}}}`,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
}, subResults...)
|
|
39
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{{#isNested}}
|
|
2
|
-
testFunctions := []func(types.ValidationInput) []types.ValidationOutput{
|
|
3
|
-
{{#names}}
|
|
4
|
-
{{name}},
|
|
5
|
-
{{/names}}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
allResults := []types.ValidationOutput{}
|
|
9
|
-
for _, fn := range testFunctions {
|
|
10
|
-
subResult := fn(input)
|
|
11
|
-
allResults = append(allResults, subResult...)
|
|
12
|
-
}
|
|
13
|
-
subResults = allResults
|
|
14
|
-
valid = true
|
|
15
|
-
for _, r := range subResults {
|
|
16
|
-
if !r.Valid {
|
|
17
|
-
valid = false
|
|
18
|
-
break
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
{{/isNested}}
|
|
23
|
-
|
|
24
|
-
{{^isNested}}
|
|
25
|
-
|
|
26
|
-
{{#isStateFull}}
|
|
27
|
-
validate := true
|
|
28
|
-
if input.Config.StateFullValidations {
|
|
29
|
-
validate = {{{returnStatement}}}
|
|
30
|
-
}
|
|
31
|
-
{{/isStateFull}}
|
|
32
|
-
|
|
33
|
-
{{^isStateFull}}
|
|
34
|
-
validate := {{{returnStatement}}}
|
|
35
|
-
{{/isStateFull}}
|
|
36
|
-
|
|
37
|
-
if !validate {
|
|
38
|
-
return []types.ValidationOutput{
|
|
39
|
-
{
|
|
40
|
-
TestName: "{{testName}}",
|
|
41
|
-
Valid: false,
|
|
42
|
-
Code: {{errorCode}},
|
|
43
|
-
Description: `{{{errorDescription}}}`,
|
|
44
|
-
DebugInfo: map[string]interface{}{
|
|
45
|
-
"fed_config": `{{{TEST_OBJECT}}}`,
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
{{/isNested}}
|
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
package utils
|
|
2
|
-
|
|
3
|
-
import (
|
|
4
|
-
"fmt"
|
|
5
|
-
"regexp"
|
|
6
|
-
"strconv"
|
|
7
|
-
"time"
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
// UNUSED suppresses "declared and not used" compiler errors
|
|
11
|
-
func UNUSED(x ...interface{}) {}
|
|
12
|
-
|
|
13
|
-
// toString converts interface{} to string representation
|
|
14
|
-
func toString(v interface{}) string {
|
|
15
|
-
if v == nil {
|
|
16
|
-
return "null"
|
|
17
|
-
}
|
|
18
|
-
return fmt.Sprintf("%v", v)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// AreUnique checks if all values in the slice are unique
|
|
22
|
-
func AreUnique(operand []interface{}) bool {
|
|
23
|
-
seen := make(map[string]bool)
|
|
24
|
-
for _, v := range operand {
|
|
25
|
-
s := toString(v)
|
|
26
|
-
if seen[s] {
|
|
27
|
-
return false
|
|
28
|
-
}
|
|
29
|
-
seen[s] = true
|
|
30
|
-
}
|
|
31
|
-
return true
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// ArePresent checks if there are no null, undefined, or empty strings in the slice
|
|
35
|
-
func ArePresent(operand []interface{}) bool {
|
|
36
|
-
return NoneIn(operand, []interface{}{"null", "undefined", ""}) && len(operand) > 0
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// AllIn checks if all values in left are present in right
|
|
40
|
-
func AllIn(left, right []interface{}) bool {
|
|
41
|
-
if len(left) == 0 && len(right) != 0 {
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
44
|
-
rightMap := make(map[string]bool)
|
|
45
|
-
for _, v := range right {
|
|
46
|
-
rightMap[toString(v)] = true
|
|
47
|
-
}
|
|
48
|
-
for _, v := range left {
|
|
49
|
-
if !rightMap[toString(v)] {
|
|
50
|
-
return false
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return true
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// AnyIn checks if any value in left is present in right
|
|
57
|
-
func AnyIn(left, right []interface{}) bool {
|
|
58
|
-
if len(left) == 0 && len(right) != 0 {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
rightMap := make(map[string]bool)
|
|
62
|
-
for _, v := range right {
|
|
63
|
-
rightMap[toString(v)] = true
|
|
64
|
-
}
|
|
65
|
-
for _, v := range left {
|
|
66
|
-
if rightMap[toString(v)] {
|
|
67
|
-
return true
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return false
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
// NoneIn checks if none of the values in left are present in right
|
|
74
|
-
func NoneIn(left, right []interface{}) bool {
|
|
75
|
-
rightMap := make(map[string]bool)
|
|
76
|
-
for _, v := range right {
|
|
77
|
-
rightMap[toString(v)] = true
|
|
78
|
-
}
|
|
79
|
-
for _, v := range left {
|
|
80
|
-
if rightMap[toString(v)] {
|
|
81
|
-
return false
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
return true
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// EqualTo checks if left and right are equal (same values in same order)
|
|
88
|
-
func EqualTo(left, right []interface{}) bool {
|
|
89
|
-
if len(left) != len(right) {
|
|
90
|
-
return false
|
|
91
|
-
}
|
|
92
|
-
for i, v := range left {
|
|
93
|
-
if toString(v) != toString(right[i]) {
|
|
94
|
-
return false
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return true
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// isISO8601 checks if a string is in ISO 8601 format
|
|
101
|
-
func isISO8601(s string) bool {
|
|
102
|
-
iso8601Regex := `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$`
|
|
103
|
-
matched, _ := regexp.MatchString(iso8601Regex, s)
|
|
104
|
-
if !matched {
|
|
105
|
-
return false
|
|
106
|
-
}
|
|
107
|
-
_, err := time.Parse(time.RFC3339, s)
|
|
108
|
-
return err == nil
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// isNumber checks if a string can be parsed as a number
|
|
112
|
-
func isNumber(s string) bool {
|
|
113
|
-
_, err := strconv.ParseFloat(s, 64)
|
|
114
|
-
return err == nil
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// areAllISO checks if all values in the slice are ISO 8601 dates
|
|
118
|
-
func areAllISO(arr []interface{}) bool {
|
|
119
|
-
for _, v := range arr {
|
|
120
|
-
if !isISO8601(toString(v)) {
|
|
121
|
-
return false
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
return true
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// areAllNumbers checks if all values in the slice are numbers
|
|
128
|
-
func areAllNumbers(arr []interface{}) bool {
|
|
129
|
-
for _, v := range arr {
|
|
130
|
-
if !isNumber(toString(v)) {
|
|
131
|
-
return false
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return true
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// GreaterThan checks if all values in left are greater than corresponding values in right
|
|
138
|
-
func GreaterThan(left, right []interface{}) bool {
|
|
139
|
-
if areAllISO(left) && areAllISO(right) {
|
|
140
|
-
leftDates := make([]time.Time, len(left))
|
|
141
|
-
rightDates := make([]time.Time, len(right))
|
|
142
|
-
|
|
143
|
-
for i, d := range left {
|
|
144
|
-
leftDates[i], _ = time.Parse(time.RFC3339, toString(d))
|
|
145
|
-
}
|
|
146
|
-
for i, d := range right {
|
|
147
|
-
rightDates[i], _ = time.Parse(time.RFC3339, toString(d))
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
for i, ld := range leftDates {
|
|
151
|
-
if i >= len(rightDates) {
|
|
152
|
-
continue
|
|
153
|
-
}
|
|
154
|
-
if !ld.After(rightDates[i]) {
|
|
155
|
-
return false
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return true
|
|
159
|
-
} else if areAllNumbers(left) && areAllNumbers(right) {
|
|
160
|
-
leftNumbers := make([]float64, len(left))
|
|
161
|
-
rightNumbers := make([]float64, len(right))
|
|
162
|
-
|
|
163
|
-
for i, n := range left {
|
|
164
|
-
leftNumbers[i], _ = strconv.ParseFloat(toString(n), 64)
|
|
165
|
-
}
|
|
166
|
-
for i, n := range right {
|
|
167
|
-
rightNumbers[i], _ = strconv.ParseFloat(toString(n), 64)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
for i, ln := range leftNumbers {
|
|
171
|
-
if i >= len(rightNumbers) {
|
|
172
|
-
continue
|
|
173
|
-
}
|
|
174
|
-
if ln <= rightNumbers[i] {
|
|
175
|
-
return false
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
return true
|
|
179
|
-
}
|
|
180
|
-
return false
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// LessThan checks if all values in left are less than corresponding values in right
|
|
184
|
-
func LessThan(left, right []interface{}) bool {
|
|
185
|
-
if areAllISO(left) && areAllISO(right) {
|
|
186
|
-
leftDates := make([]time.Time, len(left))
|
|
187
|
-
rightDates := make([]time.Time, len(right))
|
|
188
|
-
|
|
189
|
-
for i, d := range left {
|
|
190
|
-
leftDates[i], _ = time.Parse(time.RFC3339, toString(d))
|
|
191
|
-
}
|
|
192
|
-
for i, d := range right {
|
|
193
|
-
rightDates[i], _ = time.Parse(time.RFC3339, toString(d))
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
for i, ld := range leftDates {
|
|
197
|
-
if i >= len(rightDates) {
|
|
198
|
-
continue
|
|
199
|
-
}
|
|
200
|
-
if !ld.Before(rightDates[i]) {
|
|
201
|
-
return false
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return true
|
|
205
|
-
} else if areAllNumbers(left) && areAllNumbers(right) {
|
|
206
|
-
leftNumbers := make([]float64, len(left))
|
|
207
|
-
rightNumbers := make([]float64, len(right))
|
|
208
|
-
|
|
209
|
-
for i, n := range left {
|
|
210
|
-
leftNumbers[i], _ = strconv.ParseFloat(toString(n), 64)
|
|
211
|
-
}
|
|
212
|
-
for i, n := range right {
|
|
213
|
-
rightNumbers[i], _ = strconv.ParseFloat(toString(n), 64)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
for i, ln := range leftNumbers {
|
|
217
|
-
if i >= len(rightNumbers) {
|
|
218
|
-
continue
|
|
219
|
-
}
|
|
220
|
-
if ln >= rightNumbers[i] {
|
|
221
|
-
return false
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
return true
|
|
225
|
-
}
|
|
226
|
-
return false
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// FollowRegex checks if all values in left match all regex patterns in regexArray
|
|
230
|
-
func FollowRegex(left, regexArray []interface{}) bool {
|
|
231
|
-
if len(left) == 0 && len(regexArray) != 0 {
|
|
232
|
-
return false
|
|
233
|
-
}
|
|
234
|
-
for _, pattern := range regexArray {
|
|
235
|
-
re, err := regexp.Compile(toString(pattern))
|
|
236
|
-
if err != nil {
|
|
237
|
-
return false
|
|
238
|
-
}
|
|
239
|
-
for _, v := range left {
|
|
240
|
-
if !re.MatchString(toString(v)) {
|
|
241
|
-
return false
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return true
|
|
246
|
-
}
|
|
File without changes
|