Skip to content

Commit 279749c

Browse files
committed
Merge branch '0.21'
2 parents 93a318a + 7b3475d commit 279749c

File tree

28 files changed

+146
-18
lines changed

28 files changed

+146
-18
lines changed

packages/errors/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @kinobi-so/errors
22

3+
## 0.21.4
4+
5+
### Patch Changes
6+
7+
- Updated dependencies []:
8+
- @kinobi-so/node-types@0.21.4
9+
310
## 0.21.3
411

512
### Patch Changes

packages/errors/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinobi-so/errors",
3-
"version": "0.21.3",
3+
"version": "0.21.4",
44
"description": "Error management for Kinobi",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

packages/library/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# kinobi
22

3+
## 0.21.4
4+
5+
### Patch Changes
6+
7+
- [#181](https://github.com/kinobi-so/kinobi/pull/181) [`28f3d38`](https://github.com/kinobi-so/kinobi/commit/28f3d381f570859cbea1c72b7e352ad3e72db37f) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Fix TS bug on `accept` and `update` Kinobi function
8+
9+
- Updated dependencies []:
10+
- @kinobi-so/errors@0.21.4
11+
- @kinobi-so/nodes@0.21.4
12+
- @kinobi-so/validators@0.21.4
13+
- @kinobi-so/visitors@0.21.4
14+
315
## 0.21.3
416

517
### Patch Changes

packages/library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kinobi",
3-
"version": "0.21.3",
3+
"version": "0.21.4",
44
"description": "A Solana framework for building standardised programs",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

packages/library/src/kinobi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { assertIsNode, KinobiVersion, Node, RootNode } from '@kinobi-so/nodes';
44
import { visit, Visitor } from '@kinobi-so/visitors';
55

66
export interface Kinobi {
7-
accept<T>(visitor: Visitor<T>): T;
7+
accept<T>(visitor: Visitor<T, 'rootNode'>): T;
88
clone(): Kinobi;
99
getJson(): string;
1010
getRoot(): RootNode;
11-
update(visitor: Visitor<Node | null>): void;
11+
update(visitor: Visitor<Node | null, 'rootNode'>): void;
1212
}
1313

1414
export function createFromRoot(root: RootNode): Kinobi {
1515
let currentRoot = root;
1616
validateKinobiVersion(currentRoot.version);
1717
return {
18-
accept<T>(visitor: Visitor<T>): T {
18+
accept<T>(visitor: Visitor<T, 'rootNode'>): T {
1919
return visit(currentRoot, visitor);
2020
},
2121
clone(): Kinobi {
@@ -27,7 +27,7 @@ export function createFromRoot(root: RootNode): Kinobi {
2727
getRoot(): RootNode {
2828
return currentRoot;
2929
},
30-
update(visitor: Visitor<Node | null>): void {
30+
update(visitor: Visitor<Node | null, 'rootNode'>): void {
3131
const newRoot = visit(currentRoot, visitor);
3232
assertIsNode(newRoot, 'rootNode');
3333
currentRoot = newRoot;
Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect, test } from 'vitest';
22

3-
import { identityVisitor, rootNode } from '../src';
3+
import { createFromRoot, identityVisitor, programNode, rootNode, rootNodeVisitor, voidVisitor } from '../src';
44

55
test('it exports node helpers', () => {
66
expect(typeof rootNode).toBe('function');
@@ -9,3 +9,17 @@ test('it exports node helpers', () => {
99
test('it exports visitors', () => {
1010
expect(typeof identityVisitor).toBe('function');
1111
});
12+
13+
test('it accepts visitors', () => {
14+
const kinobi = createFromRoot(rootNode(programNode({ name: 'myProgram', publicKey: '1111' })));
15+
const visitor = voidVisitor(['rootNode']);
16+
const result = kinobi.accept(visitor) satisfies void;
17+
expect(typeof result).toBe('undefined');
18+
});
19+
20+
test('it updates the root node returned by visitors', () => {
21+
const kinobi = createFromRoot(rootNode(programNode({ name: 'myProgram', publicKey: '1111' })));
22+
const visitor = rootNodeVisitor(node => rootNode(programNode({ ...node.program, name: 'myTransformedProgram' })));
23+
kinobi.update(visitor) satisfies void;
24+
expect(kinobi.getRoot()).toEqual(rootNode(programNode({ name: 'myTransformedProgram', publicKey: '1111' })));
25+
});

packages/node-types/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# @kinobi-so/node-types
22

3+
## 0.21.4
4+
35
## 0.21.3
46

57
## 0.21.2

packages/node-types/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinobi-so/node-types",
3-
"version": "0.21.3",
3+
"version": "0.21.4",
44
"description": "Node specifications for the Kinobi standard",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

packages/nodes-from-anchor/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# @kinobi-so/nodes-from-anchor
22

3+
## 0.21.2
4+
5+
### Patch Changes
6+
7+
- Updated dependencies []:
8+
- @kinobi-so/errors@0.21.4
9+
- @kinobi-so/nodes@0.21.4
10+
- @kinobi-so/visitors@0.21.4
11+
312
## 0.21.1
413

514
### Patch Changes

packages/nodes-from-anchor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinobi-so/nodes-from-anchor",
3-
"version": "0.21.1",
3+
"version": "0.21.2",
44
"description": "Node specifications and helpers for the Kinobi standard",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

0 commit comments

Comments
 (0)