galbe 0.7.0 → 0.9.0
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/bin/commands/build.ts +42 -25
- package/bin/commands/dev.ts +8 -6
- package/bin/commands/generate/client.ts +26 -15
- package/bin/commands/generate/code/openapi.parser.ts +92 -57
- package/bin/commands/generate/code.ts +14 -13
- package/bin/commands/generate/spec.ts +2 -2
- package/bin/res/cli.template.js +13 -13
- package/bin/res/client.template.ts +26 -16
- package/bin/util.ts +11 -8
- package/docs/context.md +5 -1
- package/docs/error-handler.md +24 -13
- package/docs/routes.md +3 -0
- package/package.json +1 -1
- package/src/extras/spec/openapi.serializer.ts +25 -20
- package/src/index.ts +44 -4
- package/src/parser.ts +17 -12
- package/src/routes.ts +99 -91
- package/src/server.ts +7 -5
- package/src/types.ts +41 -21
- package/src/util.ts +21 -7
- package/src/validator.ts +16 -16
- package/test/parser.test.ts +38 -38
- package/test/requests.test.ts +8 -5
- package/test/router.test.ts +2 -2
package/test/parser.test.ts
CHANGED
|
@@ -232,7 +232,7 @@ describe('parser', () => {
|
|
|
232
232
|
body: {
|
|
233
233
|
headers: {
|
|
234
234
|
'neg-number': 'Required',
|
|
235
|
-
'boolean-true': "
|
|
235
|
+
'boolean-true': "Not a valid boolean. Should be 'true' or 'false'"
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -259,9 +259,9 @@ describe('parser', () => {
|
|
|
259
259
|
status: 400,
|
|
260
260
|
body: {
|
|
261
261
|
params: {
|
|
262
|
-
p2: '
|
|
263
|
-
p3: '
|
|
264
|
-
p4: "
|
|
262
|
+
p2: 'Not a valid number',
|
|
263
|
+
p3: 'Not a valid integer',
|
|
264
|
+
p4: "Not a valid boolean. Should be 'true' or 'false'"
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
}
|
|
@@ -291,8 +291,8 @@ describe('parser', () => {
|
|
|
291
291
|
status: 400,
|
|
292
292
|
body: {
|
|
293
293
|
query: {
|
|
294
|
-
p2: '
|
|
295
|
-
p3: "
|
|
294
|
+
p2: 'Not a valid number',
|
|
295
|
+
p3: "Not a valid boolean. Should be 'true' or 'false'",
|
|
296
296
|
p4: 'Required'
|
|
297
297
|
}
|
|
298
298
|
}
|
|
@@ -400,9 +400,9 @@ describe('parser', () => {
|
|
|
400
400
|
resp: {
|
|
401
401
|
body: {
|
|
402
402
|
ba: 'Not a valid byteArray',
|
|
403
|
-
string: '
|
|
404
|
-
number: '
|
|
405
|
-
bool: "
|
|
403
|
+
string: 'Not a valid string',
|
|
404
|
+
number: 'Not a valid number',
|
|
405
|
+
bool: "Not a valid boolean. Should be 'true' or 'false'",
|
|
406
406
|
object: 'Expected an object, not an array',
|
|
407
407
|
array: 'Not a valid array',
|
|
408
408
|
null: 'Expected null value got ',
|
|
@@ -496,10 +496,10 @@ describe('parser', () => {
|
|
|
496
496
|
resp: {
|
|
497
497
|
body: {
|
|
498
498
|
string: 'Multiple values found',
|
|
499
|
-
number: '
|
|
500
|
-
bool: "
|
|
501
|
-
literal: '
|
|
502
|
-
union: '
|
|
499
|
+
number: 'Not a valid number',
|
|
500
|
+
bool: "Not a valid boolean. Should be 'true' or 'false'",
|
|
501
|
+
literal: 'Not a valid value',
|
|
502
|
+
union: 'Could not be parsed to any of [number, boolean]'
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
}
|
|
@@ -538,7 +538,7 @@ describe('parser', () => {
|
|
|
538
538
|
status: 200,
|
|
539
539
|
type: 'object',
|
|
540
540
|
resp: {
|
|
541
|
-
ba:
|
|
541
|
+
ba: {},
|
|
542
542
|
string: '',
|
|
543
543
|
number: 0,
|
|
544
544
|
bool: false,
|
|
@@ -556,7 +556,7 @@ describe('parser', () => {
|
|
|
556
556
|
status: 200,
|
|
557
557
|
type: 'object',
|
|
558
558
|
resp: {
|
|
559
|
-
ba: new Uint8Array([72, 101, 108, 108, 111]),
|
|
559
|
+
ba: Object.fromEntries(new Uint8Array([72, 101, 108, 108, 111]).entries()),
|
|
560
560
|
string: 'Mom!',
|
|
561
561
|
number: 42,
|
|
562
562
|
bool: true,
|
|
@@ -576,7 +576,7 @@ describe('parser', () => {
|
|
|
576
576
|
status: 400,
|
|
577
577
|
type: 'object',
|
|
578
578
|
resp: {
|
|
579
|
-
body: { numArray: '
|
|
579
|
+
body: { numArray: 'Not a valid number' }
|
|
580
580
|
}
|
|
581
581
|
}
|
|
582
582
|
},
|
|
@@ -588,7 +588,7 @@ describe('parser', () => {
|
|
|
588
588
|
status: 400,
|
|
589
589
|
resp: {
|
|
590
590
|
body: {
|
|
591
|
-
literal: '
|
|
591
|
+
literal: 'Not a valid value'
|
|
592
592
|
}
|
|
593
593
|
}
|
|
594
594
|
}
|
|
@@ -782,10 +782,10 @@ describe('parser', () => {
|
|
|
782
782
|
resp: {
|
|
783
783
|
body: {
|
|
784
784
|
string: 'Multiple values found',
|
|
785
|
-
number: '
|
|
786
|
-
bool: "
|
|
787
|
-
literal: '
|
|
788
|
-
union: '
|
|
785
|
+
number: 'Not a valid number',
|
|
786
|
+
bool: "Not a valid boolean. Should be 'true' or 'false'",
|
|
787
|
+
literal: 'Not a valid value',
|
|
788
|
+
union: 'Could not be parsed to any of [number, boolean]'
|
|
789
789
|
}
|
|
790
790
|
}
|
|
791
791
|
}
|
|
@@ -823,7 +823,7 @@ describe('parser', () => {
|
|
|
823
823
|
type: 'AsyncIterator',
|
|
824
824
|
resp: [
|
|
825
825
|
{
|
|
826
|
-
content:
|
|
826
|
+
content: {},
|
|
827
827
|
headers: {
|
|
828
828
|
name: 'ba'
|
|
829
829
|
}
|
|
@@ -885,7 +885,7 @@ describe('parser', () => {
|
|
|
885
885
|
type: 'AsyncIterator',
|
|
886
886
|
resp: [
|
|
887
887
|
{
|
|
888
|
-
content: Uint8Array.from('Hello', c => c.charCodeAt(0)),
|
|
888
|
+
content: Object.fromEntries(Uint8Array.from('Hello', c => c.charCodeAt(0)).entries()),
|
|
889
889
|
headers: {
|
|
890
890
|
name: 'ba'
|
|
891
891
|
}
|
|
@@ -973,7 +973,7 @@ describe('parser', () => {
|
|
|
973
973
|
status: 400,
|
|
974
974
|
resp: {
|
|
975
975
|
body: {
|
|
976
|
-
number: '
|
|
976
|
+
number: 'Not a valid number'
|
|
977
977
|
}
|
|
978
978
|
}
|
|
979
979
|
}
|
|
@@ -1199,9 +1199,9 @@ describe('parser', () => {
|
|
|
1199
1199
|
status: 400,
|
|
1200
1200
|
body: {
|
|
1201
1201
|
query: {
|
|
1202
|
-
int: '
|
|
1203
|
-
num: '
|
|
1204
|
-
str: ['
|
|
1202
|
+
int: 'Is less or equal to 10',
|
|
1203
|
+
num: 'Is greater or equal to 42',
|
|
1204
|
+
str: ['Length is too large (8 char max)', 'Does not match pattern /^a.*z/']
|
|
1205
1205
|
}
|
|
1206
1206
|
}
|
|
1207
1207
|
}
|
|
@@ -1239,17 +1239,17 @@ describe('parser', () => {
|
|
|
1239
1239
|
)
|
|
1240
1240
|
expect(type).toBe(
|
|
1241
1241
|
`{` +
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1242
|
+
`'boolean':boolean;` +
|
|
1243
|
+
`'byteArray':Uint8Array;` +
|
|
1244
|
+
`'number':number;` +
|
|
1245
|
+
`'integer':number;` +
|
|
1246
|
+
`'string':string;` +
|
|
1247
|
+
`'any':any;` +
|
|
1248
|
+
`'literal':'literal';` +
|
|
1249
|
+
`'array':Array<string>;` +
|
|
1250
|
+
`'object':{'foo':string};` +
|
|
1251
|
+
`'union':number|string` +
|
|
1252
|
+
`}`
|
|
1253
1253
|
)
|
|
1254
1254
|
})
|
|
1255
1255
|
})
|
package/test/requests.test.ts
CHANGED
|
@@ -486,7 +486,7 @@ describe('requests', () => {
|
|
|
486
486
|
{
|
|
487
487
|
body: 'test',
|
|
488
488
|
schema: 'stream/ba',
|
|
489
|
-
expected: { status: 200, type: 'AsyncIterator', resp:
|
|
489
|
+
expected: { status: 200, type: 'AsyncIterator', resp: Object.fromEntries([116, 101, 115, 116].entries()) }
|
|
490
490
|
},
|
|
491
491
|
{ body: 'test', schema: 'stream/str', expected: { status: 200, type: 'AsyncIterator', resp: 'test' } },
|
|
492
492
|
{ body: 'test', schema: 'stream/form', expected: { status: 400 } },
|
|
@@ -504,9 +504,12 @@ describe('requests', () => {
|
|
|
504
504
|
|
|
505
505
|
let respBody = (await resp.json()) as { type: string; content: any }
|
|
506
506
|
|
|
507
|
+
console.log(respBody)
|
|
508
|
+
|
|
507
509
|
expect(resp.status).toBe(expected.status)
|
|
508
510
|
if (expected.type) expect(respBody.type).toEqual(expected.type)
|
|
509
511
|
if (respBody.type === 'object' && expected.resp === null) expect(respBody.content).toBeNull
|
|
512
|
+
// else if (respBody.type === 'AsyncIterator') expect(new Uint8Array(Object.values(respBody.content))).toEqual(expected.resp)
|
|
510
513
|
else expect(respBody.content).toEqual(expected.resp)
|
|
511
514
|
}
|
|
512
515
|
})
|
|
@@ -549,7 +552,7 @@ describe('requests', () => {
|
|
|
549
552
|
body: 'test',
|
|
550
553
|
type: contentType,
|
|
551
554
|
schema: 'stream/ba',
|
|
552
|
-
expected: { status: 200, type: 'AsyncIterator', resp: new Uint8Array([116, 101, 115, 116]) }
|
|
555
|
+
expected: { status: 200, type: 'AsyncIterator', resp: Object.fromEntries(new Uint8Array([116, 101, 115, 116]).entries()) }
|
|
553
556
|
},
|
|
554
557
|
{
|
|
555
558
|
body: 'test',
|
|
@@ -625,7 +628,7 @@ describe('requests', () => {
|
|
|
625
628
|
body: 'test',
|
|
626
629
|
type: contentType,
|
|
627
630
|
schema: 'stream/ba',
|
|
628
|
-
expected: { status: 200, type: 'AsyncIterator', resp: new Uint8Array([116, 101, 115, 116]) }
|
|
631
|
+
expected: { status: 200, type: 'AsyncIterator', resp: Object.fromEntries(new Uint8Array([116, 101, 115, 116]).entries()) }
|
|
629
632
|
},
|
|
630
633
|
{
|
|
631
634
|
body: 'test',
|
|
@@ -695,7 +698,7 @@ describe('requests', () => {
|
|
|
695
698
|
body: 'test',
|
|
696
699
|
type: contentType,
|
|
697
700
|
schema: 'stream/ba',
|
|
698
|
-
expected: { status: 200, type: 'AsyncIterator', resp: new Uint8Array([116, 101, 115, 116]) }
|
|
701
|
+
expected: { status: 200, type: 'AsyncIterator', resp: Object.fromEntries(new Uint8Array([116, 101, 115, 116]).entries()) }
|
|
699
702
|
},
|
|
700
703
|
{
|
|
701
704
|
body: 'test',
|
|
@@ -743,7 +746,7 @@ describe('requests', () => {
|
|
|
743
746
|
body: strBody,
|
|
744
747
|
type: contentType,
|
|
745
748
|
schema: 'stream/ba',
|
|
746
|
-
expected: { status: 200, type: 'AsyncIterator', resp: Uint8Array.from(strBody, c => c.charCodeAt(0)) }
|
|
749
|
+
expected: { status: 200, type: 'AsyncIterator', resp: Object.fromEntries(Uint8Array.from(strBody, c => c.charCodeAt(0)).entries()) }
|
|
747
750
|
},
|
|
748
751
|
{
|
|
749
752
|
body: strBody,
|
package/test/router.test.ts
CHANGED
|
@@ -125,7 +125,7 @@ describe('router', () => {
|
|
|
125
125
|
} catch (err: any) {
|
|
126
126
|
expect(err).toBeInstanceOf(NotFoundError)
|
|
127
127
|
expect(err.status).toBe(404)
|
|
128
|
-
expect(err.payload).toBe('Not
|
|
128
|
+
expect(err.payload).toBe('Not Found')
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
try {
|
|
@@ -134,7 +134,7 @@ describe('router', () => {
|
|
|
134
134
|
} catch (err: any) {
|
|
135
135
|
expect(err).toBeInstanceOf(NotFoundError)
|
|
136
136
|
expect(err.status).toBe(404)
|
|
137
|
-
expect(err.payload).toBe('Not
|
|
137
|
+
expect(err.payload).toBe('Not Found')
|
|
138
138
|
}
|
|
139
139
|
})
|
|
140
140
|
|