@0xsequence/catapult 1.3.9 → 1.3.11
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 +18 -0
- package/dist/lib/core/__tests__/json-integration.spec.js +22 -0
- package/dist/lib/core/__tests__/json-integration.spec.js.map +1 -1
- package/dist/lib/core/__tests__/resolver.spec.js +58 -0
- package/dist/lib/core/__tests__/resolver.spec.js.map +1 -1
- package/dist/lib/core/loader.d.ts.map +1 -1
- package/dist/lib/core/loader.js +0 -14
- package/dist/lib/core/loader.js.map +1 -1
- package/dist/lib/core/resolver.d.ts +4 -0
- package/dist/lib/core/resolver.d.ts.map +1 -1
- package/dist/lib/core/resolver.js +88 -0
- package/dist/lib/core/resolver.js.map +1 -1
- package/dist/lib/parsers/__tests__/job.spec.js +25 -2
- package/dist/lib/parsers/__tests__/job.spec.js.map +1 -1
- package/dist/lib/parsers/job.d.ts.map +1 -1
- package/dist/lib/parsers/job.js +31 -1
- package/dist/lib/parsers/job.js.map +1 -1
- package/dist/lib/std/templates/create4.yaml +172 -0
- package/dist/lib/types/values.d.ts +10 -1
- package/dist/lib/types/values.d.ts.map +1 -1
- package/dist/lib/utils/create4.d.ts +78 -0
- package/dist/lib/utils/create4.d.ts.map +1 -0
- package/dist/lib/utils/create4.js +237 -0
- package/dist/lib/utils/create4.js.map +1 -0
- package/package.json +13 -12
- package/src/lib/core/__tests__/json-integration.spec.ts +27 -2
- package/src/lib/core/__tests__/resolver.spec.ts +70 -2
- package/src/lib/core/loader.ts +0 -16
- package/src/lib/core/resolver.ts +114 -1
- package/src/lib/parsers/__tests__/job.spec.ts +27 -4
- package/src/lib/parsers/job.ts +44 -2
- package/src/lib/types/values.ts +12 -1
package/src/lib/parsers/job.ts
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
1
|
import { parse as parseYaml, YAMLParseError } from 'yaml'
|
|
2
|
-
import { Job, JobAction } from '../types'
|
|
2
|
+
import { Condition, Job, JobAction } from '../types'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Determines whether a raw YAML item is a valid Condition.
|
|
6
|
+
* Mirrors the validation logic used for templates so job-level
|
|
7
|
+
* skip conditions behave consistently.
|
|
8
|
+
*/
|
|
9
|
+
function isCondition(item: any): item is Condition {
|
|
10
|
+
if (!item || typeof item !== 'object' || typeof item.type !== 'string') {
|
|
11
|
+
return false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (['contract-exists', 'job-completed'].includes(item.type)) {
|
|
15
|
+
return true
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (item.type === 'basic-arithmetic') {
|
|
19
|
+
const op = item.arguments?.operation
|
|
20
|
+
return typeof op === 'string' && ['eq', 'neq', 'gt', 'lt', 'gte', 'lte'].includes(op)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false
|
|
24
|
+
}
|
|
3
25
|
|
|
4
26
|
/**
|
|
5
27
|
* Parses a YAML string defining a job into a structured `Job` object.
|
|
@@ -88,6 +110,24 @@ export function parseJob(yamlContent: string): Job {
|
|
|
88
110
|
throw new Error(`Invalid job "${rawObject.name}": "min_evm_version" must be a string if provided.`)
|
|
89
111
|
}
|
|
90
112
|
|
|
113
|
+
// --- Optional: validate job-level skip_condition and constants ---
|
|
114
|
+
if (rawObject.skip_condition !== undefined) {
|
|
115
|
+
if (!Array.isArray(rawObject.skip_condition)) {
|
|
116
|
+
throw new Error(`Invalid job "${rawObject.name}": "skip_condition" must be an array if provided.`)
|
|
117
|
+
}
|
|
118
|
+
for (const condition of rawObject.skip_condition) {
|
|
119
|
+
if (!isCondition(condition)) {
|
|
120
|
+
throw new Error(`Invalid job "${rawObject.name}": "skip_condition" contains an invalid condition entry.`)
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (rawObject.constants !== undefined) {
|
|
126
|
+
if (typeof rawObject.constants !== 'object' || rawObject.constants === null || Array.isArray(rawObject.constants)) {
|
|
127
|
+
throw new Error(`Invalid job "${rawObject.name}": "constants" field must be an object if provided.`)
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
91
131
|
// --- Construct and return the strongly-typed Job object ---
|
|
92
132
|
const job: Job = {
|
|
93
133
|
name: rawObject.name,
|
|
@@ -99,7 +139,9 @@ export function parseJob(yamlContent: string): Job {
|
|
|
99
139
|
only_networks: rawObject.only_networks,
|
|
100
140
|
skip_networks: rawObject.skip_networks,
|
|
101
141
|
min_evm_version: rawObject.min_evm_version,
|
|
102
|
-
deprecated: rawObject.deprecated === true
|
|
142
|
+
deprecated: rawObject.deprecated === true,
|
|
143
|
+
skip_condition: rawObject.skip_condition as Condition[] | undefined,
|
|
144
|
+
constants: rawObject.constants,
|
|
103
145
|
}
|
|
104
146
|
|
|
105
147
|
return job
|
package/src/lib/types/values.ts
CHANGED
|
@@ -100,6 +100,16 @@ export interface ResolveJsonValue {
|
|
|
100
100
|
arguments: Value<any>;
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
export interface SliceBytesValue {
|
|
104
|
+
type: 'slice-bytes';
|
|
105
|
+
arguments: {
|
|
106
|
+
value: BytesValue;
|
|
107
|
+
start?: Value<number | string>;
|
|
108
|
+
end?: Value<number | string>;
|
|
109
|
+
range?: Value<string>;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
103
113
|
/**
|
|
104
114
|
* A union of all possible value-resolver objects.
|
|
105
115
|
*/
|
|
@@ -115,7 +125,8 @@ export type ValueResolver =
|
|
|
115
125
|
| ContractExistsValue
|
|
116
126
|
| JobCompletedValue
|
|
117
127
|
| ReadJsonValue
|
|
118
|
-
| ResolveJsonValue
|
|
128
|
+
| ResolveJsonValue
|
|
129
|
+
| SliceBytesValue;
|
|
119
130
|
|
|
120
131
|
/**
|
|
121
132
|
* A generic value type that can be a primitive literal (string, number, boolean),
|