Skip to content

Commit 6d1f44e

Browse files
committed
Add usage of variable operations in ReturnValueTest and ConditionVariable to schema-docs via script.
1 parent 134ed21 commit 6d1f44e

File tree

5 files changed

+55
-21
lines changed

5 files changed

+55
-21
lines changed

packages/taco/schema-docs/condition-schemas.md

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,12 @@ _(\*) Required._
249249

250250
_Object containing the following properties:_
251251

252-
| Property | Type |
253-
| :-------------------- | :-------------------------------------------------------------- |
254-
| `index` | `number` (_int, ≥0_) |
255-
| **`comparator`** (\*) | `'==' \| '>' \| '<' \| '>=' \| '<=' \| '!=' \| 'in' \| '!in'` |
256-
| **`value`** (\*) | [BlockchainParamOrContextParam](#blockchainparamorcontextparam) |
252+
| Property | Description | Type |
253+
| :-------------------- | :---------------------------------------------------------------------- | :----------------------------------------------------------------- |
254+
| `index` | | `number` (_int, ≥0_) |
255+
| **`comparator`** (\*) | | `'==' \| '>' \| '<' \| '>=' \| '<=' \| '!=' \| 'in' \| '!in'` |
256+
| `operations` | Optional operations to perform on the obtained result before comparison | _Array of at least 1 [VariableOperation](#variableoperation) item_ |
257+
| **`value`** (\*) | | [BlockchainParamOrContextParam](#blockchainparamorcontextparam) |
257258

258259
_(\*) Required._
259260

@@ -263,11 +264,12 @@ Test to perform on a value. Supports comparison operators like ==, >, <, >=, <=,
263264

264265
_Object containing the following properties:_
265266

266-
| Property | Type |
267-
| :-------------------- | :------------------------------------------------------------ |
268-
| `index` | `number` (_int, ≥0_) |
269-
| **`comparator`** (\*) | `'==' \| '>' \| '<' \| '>=' \| '<=' \| '!=' \| 'in' \| '!in'` |
270-
| **`value`** (\*) | [ParamOrContextParam](#paramorcontextparam) |
267+
| Property | Description | Type |
268+
| :-------------------- | :---------------------------------------------------------------------- | :----------------------------------------------------------------- |
269+
| `index` | | `number` (_int, ≥0_) |
270+
| **`comparator`** (\*) | | `'==' \| '>' \| '<' \| '>=' \| '<=' \| '!=' \| 'in' \| '!in'` |
271+
| `operations` | Optional operations to perform on the obtained result before comparison | _Array of at least 1 [VariableOperation](#variableoperation) item_ |
272+
| **`value`** (\*) | | [ParamOrContextParam](#paramorcontextparam) |
271273

272274
_(\*) Required._
273275

@@ -291,10 +293,11 @@ _(\*) Required._
291293

292294
_Object containing the following properties:_
293295

294-
| Property | Type |
295-
| :------------------- | :---------------------------- |
296-
| **`varName`** (\*) | [PlainString](#plainstring) |
297-
| **`condition`** (\*) | [AnyCondition](#anycondition) |
296+
| Property | Description | Type |
297+
| :------------------- | :-------------------------------------------------------------------------------- | :----------------------------------------------------------------- |
298+
| **`varName`** (\*) | Any string that is not a Context Parameter i.e. does not start with `:`. | [PlainString](#plainstring) |
299+
| **`condition`** (\*) | | [AnyCondition](#anycondition) |
300+
| `operations` | Optional operations to perform on the obtained condition result before storing it | _Array of at least 1 [VariableOperation](#variableoperation) item_ |
298301

299302
_(\*) Required._
300303

@@ -360,6 +363,19 @@ _Object containing the following properties:_
360363

361364
_(\*) Required._
362365

366+
## VariableOperation
367+
368+
An operation that can be performed on an obtained result.
369+
370+
_Object containing the following properties:_
371+
372+
| Property | Type |
373+
| :------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
374+
| **`operation`** (\*) | `'+=' \| '-=' \| '*=' \| '/=' \| '%=' \| '^=' \| 'index' \| 'round' \| 'abs' \| 'avg' \| 'ceil' \| 'ethToWei' \| 'floor' \| 'len' \| 'max' \| 'min' \| 'sum' \| 'weiToEth' \| 'bool' \| 'float' \| ...` |
375+
| `value` | [ParamOrContextParam](#paramorcontextparam) |
376+
377+
_(\*) Required._
378+
363379
## TimeCondition
364380

365381
_Object containing the following properties:_

packages/taco/src/conditions/schemas/export-for-zod-doc-gen.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ export * from './rpc';
2323
export * from './sequential';
2424
export * from './signing';
2525
export * from './time';
26+
export * from './variable-operation';

packages/taco/src/conditions/schemas/return-value-test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ import { variableOperationSchema } from './variable-operation';
99
const returnValueTestBaseSchema = z.object({
1010
index: z.number().int().nonnegative().optional(),
1111
comparator: z.enum(['==', '>', '<', '>=', '<=', '!=', 'in', '!in']),
12-
operations: z.array(variableOperationSchema).min(1).optional(),
12+
operations: z
13+
.array(variableOperationSchema)
14+
.min(1)
15+
.optional()
16+
.describe(
17+
'Optional operations to perform on the obtained result before comparison',
18+
),
1319
});
1420

1521
const requireNonEmptyArrayIfComparatorIsIn = (data: {

packages/taco/src/conditions/schemas/sequential.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,23 @@ const noDuplicateVarNames = (condition: ConditionProps): boolean => {
5151
export const SequentialConditionType = 'sequential';
5252

5353
export const conditionVariableSchema: z.ZodSchema = z.lazy(() =>
54-
z.object({
55-
varName: plainStringSchema,
56-
condition: anyConditionSchema,
57-
operations: z.array(variableOperationSchema).min(1).optional(),
58-
}),
54+
z
55+
.object({
56+
varName: plainStringSchema,
57+
condition: anyConditionSchema,
58+
operations: z
59+
.array(variableOperationSchema)
60+
.min(1)
61+
.optional()
62+
.describe(
63+
'Optional operations to perform on the obtained condition result before storing it',
64+
),
65+
})
66+
.describe(
67+
'Executes a condition and stores the result as a variable within a sequential condition.',
68+
),
5969
);
70+
6071
export type ConditionVariableProps = z.infer<typeof conditionVariableSchema>;
6172

6273
export const sequentialConditionSchema: z.ZodSchema = baseConditionSchema

packages/taco/src/conditions/schemas/variable-operation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ export const variableOperationSchema = z
8282
path: ['value'],
8383
},
8484
)
85-
.describe('An operation that can be performed on an obtained variable.');
85+
.describe('An operation that can be performed on an obtained result.');

0 commit comments

Comments
 (0)