ondc-code-generator 0.8.8 → 0.8.9

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.
Files changed (109) hide show
  1. package/README.md +1 -1
  2. package/alpha/page/index.html +6137 -0
  3. package/alpha/page/style.css +204 -0
  4. package/alpha/readme.md +5939 -0
  5. package/alpha/validPaths.json +14351 -0
  6. package/alpha/validationpkg/examples/search.json +143 -0
  7. package/alpha/validationpkg/examples_output/search/case-001/output.json +12 -0
  8. package/alpha/validationpkg/go.mod +8 -0
  9. package/alpha/validationpkg/go.sum +4 -0
  10. package/dist/bin/cli.js +2 -0
  11. package/dist/generator/config-compiler.js +4 -0
  12. package/dist/types/compiler-types.d.ts +2 -1
  13. package/dist/types/compiler-types.js +1 -0
  14. package/docs/jval-dsl.md +913 -0
  15. package/package.json +1 -1
  16. package/alpha/golang/newPkg/go.mod +0 -3
  17. package/alpha/golang/newPkg/jsonvalidations/cancel.go +0 -1289
  18. package/alpha/golang/newPkg/jsonvalidations/confirm.go +0 -9121
  19. package/alpha/golang/newPkg/jsonvalidations/init.go +0 -4864
  20. package/alpha/golang/newPkg/jsonvalidations/issue.go +0 -4868
  21. package/alpha/golang/newPkg/jsonvalidations/on_cancel.go +0 -7111
  22. package/alpha/golang/newPkg/jsonvalidations/on_confirm.go +0 -8903
  23. package/alpha/golang/newPkg/jsonvalidations/on_init.go +0 -4445
  24. package/alpha/golang/newPkg/jsonvalidations/on_issue.go +0 -2828
  25. package/alpha/golang/newPkg/jsonvalidations/on_issue_status.go +0 -1938
  26. package/alpha/golang/newPkg/jsonvalidations/on_search.go +0 -3356
  27. package/alpha/golang/newPkg/jsonvalidations/on_status.go +0 -8129
  28. package/alpha/golang/newPkg/jsonvalidations/on_track.go +0 -1415
  29. package/alpha/golang/newPkg/jsonvalidations/on_update.go +0 -8700
  30. package/alpha/golang/newPkg/jsonvalidations/search.go +0 -3585
  31. package/alpha/golang/newPkg/jsonvalidations/status.go +0 -1073
  32. package/alpha/golang/newPkg/jsonvalidations/track.go +0 -1073
  33. package/alpha/golang/newPkg/jsonvalidations/update.go +0 -3012
  34. package/alpha/golang/newPkg/main-validator.go +0 -196
  35. package/alpha/golang/newPkg/main-validator_test.go +0 -165
  36. package/alpha/golang/newPkg/storageutils/api_save_utils.go +0 -83
  37. package/alpha/golang/newPkg/storageutils/cancel.go +0 -30
  38. package/alpha/golang/newPkg/storageutils/confirm.go +0 -30
  39. package/alpha/golang/newPkg/storageutils/index.go +0 -132
  40. package/alpha/golang/newPkg/storageutils/init.go +0 -30
  41. package/alpha/golang/newPkg/storageutils/issue.go +0 -30
  42. package/alpha/golang/newPkg/storageutils/on_cancel.go +0 -30
  43. package/alpha/golang/newPkg/storageutils/on_confirm.go +0 -30
  44. package/alpha/golang/newPkg/storageutils/on_init.go +0 -30
  45. package/alpha/golang/newPkg/storageutils/on_issue.go +0 -30
  46. package/alpha/golang/newPkg/storageutils/on_issue_status.go +0 -30
  47. package/alpha/golang/newPkg/storageutils/on_search.go +0 -30
  48. package/alpha/golang/newPkg/storageutils/on_status.go +0 -30
  49. package/alpha/golang/newPkg/storageutils/on_track.go +0 -30
  50. package/alpha/golang/newPkg/storageutils/on_update.go +0 -30
  51. package/alpha/golang/newPkg/storageutils/save_utils.go +0 -75
  52. package/alpha/golang/newPkg/storageutils/search.go +0 -30
  53. package/alpha/golang/newPkg/storageutils/status.go +0 -30
  54. package/alpha/golang/newPkg/storageutils/track.go +0 -30
  55. package/alpha/golang/newPkg/storageutils/update.go +0 -30
  56. package/alpha/golang/validationpkg/go.mod +0 -3
  57. package/alpha/golang/validationpkg/validationutils/json_normalizer.go +0 -152
  58. package/alpha/golang/validationpkg/validationutils/json_path_utils.go +0 -173
  59. package/alpha/golang/validationpkg/validationutils/storage-interface.go +0 -107
  60. package/alpha/golang/validationpkg/validationutils/test-config.go +0 -69
  61. package/alpha/golang/validationpkg/validationutils/validation_utils.go +0 -429
  62. /package/alpha/{golang → docs}/page/index.html +0 -0
  63. /package/alpha/{golang → docs}/page/style.css +0 -0
  64. /package/alpha/{golang → docs}/readme.md +0 -0
  65. /package/alpha/{golang → docs}/validPaths.json +0 -0
  66. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/cancel.go +0 -0
  67. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/confirm.go +0 -0
  68. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/init.go +0 -0
  69. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/issue.go +0 -0
  70. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_cancel.go +0 -0
  71. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_confirm.go +0 -0
  72. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_init.go +0 -0
  73. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_issue.go +0 -0
  74. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_issue_status.go +0 -0
  75. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_search.go +0 -0
  76. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_status.go +0 -0
  77. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_track.go +0 -0
  78. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/on_update.go +0 -0
  79. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/search.go +0 -0
  80. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/status.go +0 -0
  81. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/track.go +0 -0
  82. /package/alpha/{golang/validationpkg → validationpkg}/jsonvalidations/update.go +0 -0
  83. /package/alpha/{golang/validationpkg → validationpkg}/main-validator.go +0 -0
  84. /package/alpha/{golang/validationpkg → validationpkg}/main-validator_test.go +0 -0
  85. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/api_save_utils.go +0 -0
  86. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/cancel.go +0 -0
  87. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/confirm.go +0 -0
  88. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/index.go +0 -0
  89. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/init.go +0 -0
  90. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/issue.go +0 -0
  91. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_cancel.go +0 -0
  92. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_confirm.go +0 -0
  93. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_init.go +0 -0
  94. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_issue.go +0 -0
  95. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_issue_status.go +0 -0
  96. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_search.go +0 -0
  97. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_status.go +0 -0
  98. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_track.go +0 -0
  99. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/on_update.go +0 -0
  100. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/save_utils.go +0 -0
  101. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/search.go +0 -0
  102. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/status.go +0 -0
  103. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/track.go +0 -0
  104. /package/alpha/{golang/validationpkg → validationpkg}/storageutils/update.go +0 -0
  105. /package/alpha/{golang/newPkg → validationpkg}/validationutils/json_normalizer.go +0 -0
  106. /package/alpha/{golang/newPkg → validationpkg}/validationutils/json_path_utils.go +0 -0
  107. /package/alpha/{golang/newPkg → validationpkg}/validationutils/storage-interface.go +0 -0
  108. /package/alpha/{golang/newPkg → validationpkg}/validationutils/test-config.go +0 -0
  109. /package/alpha/{golang/newPkg → validationpkg}/validationutils/validation_utils.go +0 -0
@@ -1,173 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package validationutils
4
-
5
- import (
6
- "fmt"
7
- "strings"
8
- "sync"
9
-
10
- "github.com/AsaiYusuke/jsonpath"
11
- )
12
-
13
- // Global cache for parsed JSONPath functions
14
- var (
15
- pathParserCache = make(map[string]func(interface{}) ([]interface{}, error))
16
- parserCacheMu sync.RWMutex
17
- cacheHits uint64
18
- cacheMisses uint64
19
- statsMu sync.Mutex
20
- )
21
-
22
- // getOrParseJSONPath retrieves a cached parser or parses and caches a new one
23
- func getOrParseJSONPath(path string) (func(interface{}) ([]interface{}, error), error) {
24
- // Try to get from cache first (read lock for fast concurrent reads)
25
- parserCacheMu.RLock()
26
- parser, exists := pathParserCache[path]
27
- parserCacheMu.RUnlock()
28
-
29
- if exists {
30
- // Cache hit - use existing parser
31
- statsMu.Lock()
32
- cacheHits++
33
- statsMu.Unlock()
34
- return parser, nil
35
- }
36
-
37
- // Cache miss - need to parse
38
- statsMu.Lock()
39
- cacheMisses++
40
- statsMu.Unlock()
41
-
42
- // Acquire write lock to add to cache
43
- parserCacheMu.Lock()
44
- defer parserCacheMu.Unlock()
45
-
46
- // Double-check after acquiring write lock (another goroutine might have added it)
47
- if parser, exists := pathParserCache[path]; exists {
48
- return parser, nil
49
- }
50
-
51
- // Parse the JSONPath expression
52
- parser, err := jsonpath.Parse(path)
53
- if err != nil {
54
- return nil, fmt.Errorf("failed to parse JSONPath %s: %w", path, err)
55
- }
56
-
57
- // Cache it for future use
58
- pathParserCache[path] = parser
59
- return parser, nil
60
- }
61
-
62
- // GetParserCacheStats returns cache statistics
63
- func GetParserCacheStats() (hits, misses uint64, size int) {
64
- statsMu.Lock()
65
- h, m := cacheHits, cacheMisses
66
- statsMu.Unlock()
67
-
68
- parserCacheMu.RLock()
69
- s := len(pathParserCache)
70
- parserCacheMu.RUnlock()
71
-
72
- return h, m, s
73
- }
74
-
75
- // ClearParserCache clears the cache (useful for testing)
76
- func ClearParserCache() {
77
- parserCacheMu.Lock()
78
- pathParserCache = make(map[string]func(interface{}) ([]interface{}, error))
79
- parserCacheMu.Unlock()
80
-
81
- statsMu.Lock()
82
- cacheHits = 0
83
- cacheMisses = 0
84
- statsMu.Unlock()
85
- }
86
-
87
- // isListOfStringsOrNull checks if the variable is a slice containing only strings or nil values
88
- func isListOfStringsOrNull(variable interface{}) bool {
89
- slice, ok := variable.([]interface{})
90
- if !ok {
91
- return false
92
- }
93
-
94
- for _, item := range slice {
95
- if item == nil {
96
- continue
97
- }
98
- if _, isString := item.(string); !isString {
99
- return false
100
- }
101
- }
102
- return true
103
- }
104
-
105
- // GetJsonPath queries a payload using JSONPath and returns the results
106
- func GetJsonPath(payload interface{}, path string, flattenResult bool) []interface{} {
107
- resolvedPath, resolvedData, err := resolveJSONPathData(path, payload)
108
- if err != nil {
109
- // fmt.Printf("Error resolving JSONPath %s: %v\n", path, err)
110
- return []interface{}{}
111
- }
112
-
113
- // Get or parse the JSONPath - uses cache if available
114
- parser, err := getOrParseJSONPath(resolvedPath)
115
- if err != nil {
116
- // fmt.Printf("Error parsing JSONPath %s: %v\n", resolvedPath, err)
117
- return []interface{}{}
118
- }
119
-
120
- // Execute the parsed JSONPath function
121
- result, err := parser(resolvedData)
122
- if err != nil {
123
- // fmt.Printf("Error retrieving JSONPath %s: %v\n", resolvedPath, err)
124
- return []interface{}{}
125
- }
126
-
127
- // Result is already []interface{}
128
- output := result
129
-
130
- if len(output) == 0 {
131
- return []interface{}{}
132
- }
133
-
134
- if isListOfStringsOrNull(output) {
135
- for i, item := range output {
136
- if item == nil {
137
- output[i] = "null"
138
- }
139
- }
140
- }
141
-
142
- if flattenResult {
143
- output = flattenSlice(output)
144
- }
145
-
146
- return output
147
- }
148
-
149
- // flattenSlice recursively flattens nested slices
150
- func flattenSlice(slice []interface{}) []interface{} {
151
- result := make([]interface{}, 0)
152
- for _, item := range slice {
153
- if nestedSlice, ok := item.([]interface{}); ok {
154
- result = append(result, flattenSlice(nestedSlice)...)
155
- } else {
156
- result = append(result, item)
157
- }
158
- }
159
- return result
160
- }
161
-
162
- func resolveJSONPathData(path string, data interface{}) (string, interface{}, error) {
163
- if input, ok := data.(ValidationInput); ok {
164
- if strings.HasPrefix(path, "$._EXTERNAL._SELF") {
165
- resolvedPath := strings.Replace(path, "$._EXTERNAL._SELF", "$", 1)
166
- return resolvedPath, input.ExternalData["_SELF"], nil
167
- } else if strings.HasPrefix(path, "$._EXTERNAL") {
168
- resolvedPath := strings.Replace(path, "$._EXTERNAL", "$", 1)
169
- return resolvedPath, input.ExternalData, nil
170
- }
171
- }
172
- return path, data, nil
173
- }
@@ -1,107 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package validationutils
4
-
5
- // StorageInterface provides a standardized abstraction layer for storage operations
6
- // that can be implemented by different storage backends (Redis, Memory, File, etc.).
7
- //
8
- // Implementation Notes:
9
- // - Keys should be strings and values are stored as strings
10
- // - Implementations should handle serialization/deserialization as needed
11
- // - Prefix-based operations allow for namespacing and bulk operations
12
- //
13
- // Example:
14
- //
15
- // type RedisStorage struct {
16
- // client *redis.Client
17
- // }
18
- //
19
- // func (r *RedisStorage) SaveKey(uniquePrefix, key, value string) error {
20
- // fullKey := fmt.Sprintf("%s:%s", uniquePrefix, key)
21
- // return r.client.Set(ctx, fullKey, value, 0).Err()
22
- // }
23
- //
24
- // storage := &RedisStorage{client: redisClient}
25
- // userData, _ := json.Marshal(user)
26
- // storage.SaveKey("app1", "user:123", string(userData))
27
- type StorageInterface interface {
28
- // SaveKey saves a key-value pair to storage with a unique prefix for namespacing.
29
- //
30
- // Parameters:
31
- // - uniquePrefix: A unique identifier/namespace prefix to prevent key collisions
32
- // - key: The unique identifier for the stored value within the prefix namespace
33
- // - value: The string value to store
34
- //
35
- // Returns error if the operation fails
36
- //
37
- // Example:
38
- // sessionData, _ := json.Marshal(session)
39
- // err := storage.SaveKey("app1", "session:abc123", string(sessionData))
40
- SaveKey(uniquePrefix string, key string, value string) error
41
-
42
- // GetKey retrieves a value by its key from storage within a specific namespace.
43
- //
44
- // Parameters:
45
- // - uniquePrefix: The unique identifier/namespace prefix used when storing
46
- // - key: The unique identifier for the value to retrieve within the prefix namespace
47
- //
48
- // Returns the stored value and error if the key does not exist
49
- //
50
- // Example:
51
- // sessionData, err := storage.GetKey("app1", "session:abc123")
52
- // if err != nil {
53
- // // handle key not found
54
- // }
55
- GetKey(uniquePrefix string, key string) (string, error)
56
-
57
- // DeleteKey removes a key-value pair from storage within a specific namespace.
58
- //
59
- // Parameters:
60
- // - uniquePrefix: The unique identifier/namespace prefix used when storing
61
- // - key: The unique identifier for the value to delete within the prefix namespace
62
- //
63
- // Returns error if the operation fails
64
- //
65
- // Example:
66
- // err := storage.DeleteKey("app1", "session:abc123")
67
- DeleteKey(uniquePrefix string, key string) error
68
-
69
- // ListKeys lists all keys within a specific namespace/prefix.
70
- //
71
- // Parameters:
72
- // - uniquePrefix: The unique identifier/namespace prefix to list keys from
73
- //
74
- // Returns an array of keys within that namespace
75
- //
76
- // Example:
77
- // app1Keys, err := storage.ListKeys("app1")
78
- // // Returns keys stored under the "app1" namespace
79
- // // e.g., []string{"session:abc123", "user:456", "config:settings"}
80
- ListKeys(uniquePrefix string) ([]string, error)
81
-
82
- // ClearStorage clears all stored data from the storage backend.
83
- //
84
- // WARNING: This operation is destructive and cannot be undone.
85
- // Use with caution, especially in production environments.
86
- //
87
- // Returns error if the operation fails
88
- //
89
- // Example:
90
- // err := storage.ClearStorage() // All data is now removed
91
- ClearStorage() error
92
-
93
- // KeyExists checks if a key exists in storage within a specific namespace.
94
- //
95
- // Parameters:
96
- // - uniquePrefix: The unique identifier/namespace prefix to check within
97
- // - key: The unique identifier to check for existence within the prefix namespace
98
- //
99
- // Returns true if the key exists, false otherwise
100
- //
101
- // Example:
102
- // exists, err := storage.KeyExists("app1", "user:123")
103
- // if err == nil && exists {
104
- // userData, _ := storage.GetKey("app1", "user:123")
105
- // }
106
- KeyExists(uniquePrefix string, key string) (bool, error)
107
- }
@@ -1,69 +0,0 @@
1
- // Code generated by github.com/ONDC-Official/automation-validation-compiler, DO NOT EDIT.
2
-
3
- package validationutils
4
-
5
- // ValidationConfig holds configuration options for running validation routines.
6
- type ValidationConfig struct {
7
- // StateFullValidations enables stateful validations that may depend on previous data
8
- StateFullValidations bool
9
- // SkipTests is a list of test names to be skipped during validation
10
- SkipTests []string
11
- // UniqueKey is an optional unique key for the validation instance
12
- UniqueKey *string
13
- // Store is an optional implementation of StorageInterface for persisting data across validations
14
- Store StorageInterface
15
- // OnlyInvalid if true, only invalid results will be returned
16
- OnlyInvalid bool
17
- // HideParentErrors hides nested error details if set to true
18
- HideParentErrors bool
19
- // Debug enables debug mode for additional diagnostic information
20
- Debug bool
21
- // SkipTestsDict is an internal map for quick lookup of tests to skip
22
- SkipTestsDict map[string]bool
23
- }
24
-
25
- // ValidationOutput represents the output of a validation run.
26
- // Each element corresponds to a single validation test result.
27
- type ValidationOutput struct {
28
- // TestName is the name of the validation test
29
- TestName string `json:"testName"`
30
- // Valid indicates whether the test passed (true) or failed (false)
31
- Valid bool `json:"valid"`
32
- // Code is a numeric code representing the result or error type
33
- Code int `json:"code"`
34
- // Description provides additional details about the test result
35
- Description string `json:"description,omitempty"`
36
- // DebugInfo contains diagnostic information useful for debugging
37
- DebugInfo *DebugInfo `json:"_debugInfo,omitempty"`
38
- }
39
-
40
- // DebugInfo contains diagnostic information for validation results
41
- type DebugInfo struct {
42
- // FedConfig is the configuration used to generate the validation
43
- FedConfig interface{} `json:"fedConfig"`
44
- }
45
-
46
- // ExternalData holds external data references for validation as a map structure.
47
- //
48
- // Expected keys:
49
- // - "_SELF": (interface{}) The current validation context object
50
- //
51
- // Example usage:
52
- //
53
- // data := ExternalData{
54
- // "_SELF": currentObject,
55
- // }
56
- type ExternalData = map[string]interface{}
57
-
58
- // ValidationInput represents the input data for validation functions
59
- type ValidationInput struct {
60
- Payload interface{} `json:"payload"`
61
- ExternalData ExternalData `json:"_EXTERNAL,omitempty"`
62
- Config ValidationConfig `json:"_CONFIG,omitempty"`
63
- }
64
-
65
- // TestFunction is a function type that takes ValidationInput and returns a slice of ValidationOutput
66
- type TestFunction func(input ValidationInput) ([]ValidationOutput, error)
67
-
68
- // TestFunctionArray is a slice of test functions
69
- type TestFunctionArray []TestFunction