Skip to content

Commit e46c29e

Browse files
committed
refactor: ContractAnalyzer class
1 parent b4d3958 commit e46c29e

File tree

8 files changed

+1095
-872
lines changed

8 files changed

+1095
-872
lines changed

packages/parse/__tests__/ContractAnalyzer.multiFileSchema.test.ts

Lines changed: 154 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,61 @@ describe('ContractAnalyzer - Multi-File with Schema', () => {
4747
{
4848
name: 'getPoints',
4949
params: [],
50-
returnSchema: { type: 'array', items: {} },
50+
returnSchema: {
51+
type: 'array',
52+
items: {
53+
type: 'object',
54+
properties: {
55+
x: { type: 'number' },
56+
y: { type: 'number' },
57+
},
58+
required: ['x', 'y'],
59+
},
60+
},
5161
},
5262
]);
5363
expect(result.mutations).toEqual([
5464
{
5565
name: 'addPoint',
56-
params: [{ name: 'point', schema: {} }],
66+
params: [
67+
{
68+
name: 'point',
69+
schema: {
70+
type: 'object',
71+
properties: {
72+
x: { type: 'number' },
73+
y: { type: 'number' },
74+
},
75+
required: ['x', 'y'],
76+
},
77+
},
78+
],
5779
returnSchema: {},
5880
},
5981
{
6082
name: 'movePoint',
6183
params: [
6284
{ name: 'index', schema: { type: 'number' } },
63-
{ name: 'delta', schema: {} },
85+
{
86+
name: 'delta',
87+
schema: {
88+
type: 'object',
89+
properties: {
90+
x: { type: 'number' },
91+
y: { type: 'number' },
92+
},
93+
required: ['x', 'y'],
94+
},
95+
},
6496
],
65-
returnSchema: {},
97+
returnSchema: {
98+
type: 'object',
99+
properties: {
100+
x: { type: 'number' },
101+
y: { type: 'number' },
102+
},
103+
required: ['x', 'y'],
104+
},
66105
},
67106
]);
68107
});
@@ -538,7 +577,18 @@ describe('ContractAnalyzer - Multi-File with Schema', () => {
538577
name: 'getUser',
539578
params: [{ name: 'id', schema: { type: 'string' } }],
540579
returnSchema: {
541-
anyOf: [{}],
580+
anyOf: [
581+
{
582+
type: 'object',
583+
properties: {
584+
id: { type: 'string' },
585+
name: { type: 'string' },
586+
age: { type: 'number' },
587+
},
588+
required: ['id', 'name', 'age'],
589+
},
590+
{},
591+
],
542592
},
543593
},
544594
]);
@@ -548,17 +598,40 @@ describe('ContractAnalyzer - Multi-File with Schema', () => {
548598
params: [
549599
{
550600
name: 'userData',
551-
schema: {},
601+
schema: {
602+
type: 'object',
603+
properties: {
604+
id: { type: 'string' },
605+
name: { type: 'string' },
606+
age: { type: 'number' },
607+
},
608+
required: ['id', 'name', 'age'],
609+
},
552610
},
553611
],
554-
returnSchema: {},
612+
returnSchema: {
613+
type: 'object',
614+
properties: {
615+
id: { type: 'string' },
616+
name: { type: 'string' },
617+
age: { type: 'number' },
618+
},
619+
required: ['id', 'name', 'age'],
620+
},
555621
},
556622
{
557623
name: 'updateConfig',
558624
params: [
559625
{
560626
name: 'config',
561-
schema: {},
627+
schema: {
628+
type: 'object',
629+
properties: {
630+
debug: { type: 'boolean' },
631+
timeout: { type: 'number' },
632+
},
633+
required: ['debug'],
634+
},
562635
},
563636
],
564637
returnSchema: {},
@@ -681,7 +754,19 @@ describe('ContractAnalyzer - Multi-File with Schema', () => {
681754
expect(result.mutations).toEqual([
682755
{
683756
name: 'addItem',
684-
params: [{ name: 'item', schema: {} }],
757+
params: [
758+
{
759+
name: 'item',
760+
schema: {
761+
type: 'object',
762+
properties: {
763+
id: { type: 'string' },
764+
value: { type: 'number' },
765+
},
766+
required: ['id', 'value'],
767+
},
768+
},
769+
],
685770
returnSchema: {},
686771
},
687772
]);
@@ -736,19 +821,75 @@ describe('ContractAnalyzer - Multi-File with Schema', () => {
736821
{
737822
name: 'getProfile',
738823
params: [{ name: 'id', schema: { type: 'string' } }],
739-
returnSchema: {},
824+
returnSchema: {
825+
type: 'object',
826+
properties: {
827+
username: { type: 'string' },
828+
email: { type: 'string' },
829+
preferences: {
830+
type: 'object',
831+
properties: {
832+
theme: { type: 'string', enum: ['light', 'dark'] },
833+
notifications: { type: 'boolean' },
834+
},
835+
required: ['theme', 'notifications'],
836+
},
837+
},
838+
required: ['username', 'email', 'preferences'],
839+
},
740840
},
741841
]);
742842
expect(result.mutations).toEqual([
743843
{
744844
name: 'saveProfile',
745-
params: [{ name: 'profile', schema: {} }],
845+
params: [
846+
{
847+
name: 'profile',
848+
schema: {
849+
type: 'object',
850+
properties: {
851+
username: { type: 'string' },
852+
email: { type: 'string' },
853+
preferences: {
854+
type: 'object',
855+
properties: {
856+
theme: { type: 'string', enum: ['light', 'dark'] },
857+
notifications: { type: 'boolean' },
858+
},
859+
required: ['theme', 'notifications'],
860+
},
861+
},
862+
required: ['username', 'email', 'preferences'],
863+
},
864+
},
865+
],
746866
returnSchema: {},
747867
},
748868
{
749869
name: 'handleResponse',
750-
params: [{ name: 'response', schema: {} }],
751-
returnSchema: {},
870+
params: [
871+
{
872+
name: 'response',
873+
schema: {
874+
type: 'object',
875+
properties: {
876+
data: {},
877+
status: { type: 'number' },
878+
message: { type: 'string' },
879+
},
880+
required: ['data', 'status', 'message'],
881+
},
882+
},
883+
],
884+
returnSchema: {
885+
type: 'object',
886+
properties: {
887+
data: {},
888+
status: { type: 'number' },
889+
message: { type: 'string' },
890+
},
891+
required: ['data', 'status', 'message'],
892+
},
752893
},
753894
]);
754895
});

0 commit comments

Comments
 (0)