Skip to content

Commit e8ccf00

Browse files
committed
add test, exit beta
1 parent 73706c4 commit e8ccf00

24 files changed

+10608
-16507
lines changed

.github/workflows/all-except-main-push.yml

-7
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,5 @@ jobs:
1616
- run: npm run lint --fix
1717
- run: npm run pretty-quick
1818
- run: npm test
19-
# env:
20-
# PROJECT_ID: ${{ secrets.PROJECT_ID }}
2119
- run: npm run build
22-
# - run: npm run link
23-
# - run: npm run b-tsc
24-
# - run: npm run b-test
25-
# env:
26-
# PROJECT_ID: ${{ secrets.PROJECT_ID }}
2720
- uses: codecov/codecov-action@v2

.github/workflows/all-pull-request.yml

-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,5 @@ jobs:
1515
- run: npm run lint --fix
1616
- run: npm run pretty-quick
1717
- run: npm test
18-
# env:
19-
# PROJECT_ID: ${{ secrets.PROJECT_ID }}
2018
- run: npm run build
21-
# - run: npm run link
22-
# - run: npm run b-tsc
23-
# - run: npm run b-test
24-
# env:
25-
# PROJECT_ID: ${{ secrets.PROJECT_ID }}
2619
- uses: codecov/codecov-action@v2

.github/workflows/main.yml

-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,3 @@ jobs:
1818
- run: npm publish
1919
env:
2020
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
21-
# - run: npm run p-reinstall
22-
# - run: npm run p-test
23-
# env:
24-
# PROJECT_ID: ${{ secrets.PROJECT_ID }}

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
.env.test.local
2020
.env.production.local
2121
/.config
22-
.env
2322
/.parcel-cache
23+
24+
# env
25+
env.json
26+
.env
2427
.firebaserc

.husky/pre-commit

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@
33

44
npm run lint --fix
55
npm run pretty-quick
6-
npm run build
7-
npm run d-test
8-
# npm run d-b-test
6+
npm run d-test

.npmignore

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,16 @@ tsconfig.json
2222
.eslintrc.js
2323
.prettierrc.js
2424
babel.config.js
25-
.env
2625
jest.config.doc.js
2726
tsconfig.doc.json
2827
lgtm.yml
2928
tsconfig.prod.json
3029

30+
# env
31+
env.json
32+
.env
33+
.firebaserc
34+
3135
# types
3236
/types/**/*
3337
!/types/**/*.ts
@@ -41,5 +45,4 @@ CHANGELOG.md
4145
package-lock.json
4246
firebase.json
4347
.eslintignore
44-
.firebaserc
4548
note.txt

README.md

+122-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<div align="center">
66
<img src="https://raw.githubusercontent.com/tylim88/Firelord/main/img/ozai.png" width="200px"/>
7-
<h1>FireCall 烈火唤(Beta)</h1>
7+
<h1>FireCall 烈火唤</h1>
88
</div>
99

1010
<div align="center">
@@ -39,6 +39,54 @@
3939
src="https://img.shields.io/badge/gzipped-2KB-brightgreen"
4040
alt="package size"
4141
/>
42+
&nbsp;
43+
<a href="https://github.com/tylim88/FireCall/actions" target="_blank">
44+
<img
45+
src="https://github.com/tylim88/FireCall/workflows/Main/badge.svg"
46+
alt="github action"
47+
/>
48+
</a>
49+
&nbsp;
50+
<a href="https://codecov.io/gh/tylim88/FireCall" target="_blank">
51+
<img
52+
src="https://codecov.io/gh/tylim88/FireCall/branch/main/graph/badge.svg"
53+
alt="code coverage"
54+
/>
55+
</a>
56+
&nbsp;
57+
<a href="https://github.com/tylim88/FireCall/issues" target="_blank">
58+
<img
59+
alt="GitHub issues"
60+
src="https://img.shields.io/github/issues-raw/tylim88/FireCall"
61+
></img>
62+
</a>
63+
&nbsp;
64+
<a href="https://snyk.io/test/github/tylim88/FirelordJS" target="_blank">
65+
<img
66+
src="https://snyk.io/test/github/tylim88/FirelordJS/badge.svg"
67+
alt="code coverage"
68+
/>
69+
</a>
70+
&nbsp;
71+
<a
72+
href="https://lgtm.com/projects/g/tylim88/FireCall/alerts/"
73+
target="_blank"
74+
>
75+
<img
76+
alt="Total alerts"
77+
src="https://img.shields.io/lgtm/alerts/g/tylim88/FireCall.svg?logo=lgtm&logoWidth=18"
78+
/>
79+
</a>
80+
&nbsp;
81+
<a
82+
href="https://lgtm.com/projects/g/tylim88/FireCall/context:javascript"
83+
target="_blank"
84+
>
85+
<img
86+
alt="Language grade: JavaScript"
87+
src="https://img.shields.io/lgtm/grade/javascript/g/tylim88/FireCall.svg?logo=lgtm&logoWidth=18"
88+
/>
89+
</a>
4290
<br/>
4391
<br/>
4492
<p>🔥 Write callable functions systematically like a Firelord. No more chaotic error handling, no more unsafe endpoint data type, no more messy validation. Be the Master of Fire you always wanted to be.</p>
@@ -64,6 +112,8 @@ Ensuring:
64112

65113
Optional: For maximum benefit, please use [FireCaller](https://github.com/tylim88/firecaller) in front end.
66114

115+
support [firebase-functions-test](#firebase-function-test):
116+
67117
## Why Do You Need This? What Is The Problem FireCall Trying To Solve?
68118

69119
When coding a callable function (or any endpoint in general), we need to deal with 5 basic errors, which is basically 99% of your errors, the rest are system errors.
@@ -92,7 +142,7 @@ Long thing short, FireCall make sure that there is only one way to do stuff and
92142

93143
## Related Projects
94144

95-
1. [FirelordJS](https://github.com/tylim88/Firelordjs) - Typescript wrapper for Firestore Web V9
145+
1. [FirelordJS](https://github.com/tylim88/FireCall) - Typescript wrapper for Firestore Web V9
96146
2. [Firelord](https://github.com/tylim88/Firelord) - Typescript wrapper for Firestore Admin
97147
3. [Firelordrn](https://github.com/tylim88/firelordrn) - Typescript wrapper for Firestore React Native
98148
4. [FireLaw](https://github.com/tylim88/firelaw) - Write Firestore security rule with Typescript, utilizing Firelord type engine.
@@ -233,6 +283,76 @@ exp(allFunc).forEach(func => {
233283
})
234284
```
235285

286+
## Firebase Function Test
287+
288+
You can use FireCall with [firebase-functions-test](https://firebase.google.com/docs/functions/unit-testing):
289+
290+
ok test example:
291+
292+
```ts
293+
const wrapped = test.wrap(
294+
onCall(
295+
schema,
296+
{
297+
route: 'private',
298+
},
299+
async () => {
300+
return { code: 'ok', data: 'okie' }
301+
}
302+
).onCall
303+
)
304+
await expect(wrapped('123', { auth: { uid: '123' } })).resolves.toEqual('okie')
305+
```
306+
307+
error tests examples:
308+
309+
```ts
310+
const wrapped = test.wrap(
311+
onCall(
312+
schema,
313+
{
314+
route: 'private',
315+
},
316+
() => {
317+
return { code: 'cancelled', message: 'cancelled' }
318+
}
319+
).onCall
320+
)
321+
await expect(wrapped('123', { auth: { uid: '123' } })).rejects.toEqual(
322+
new functions.https.HttpsError('cancelled', 'cancelled')
323+
)
324+
325+
const wrapped = test.wrap(
326+
onCall(
327+
schema,
328+
{
329+
route: 'private',
330+
},
331+
async () => {
332+
return { code: 'ok', data: 'okRes' }
333+
}
334+
).onCall
335+
)
336+
await expect(wrapped('123')).rejects.toEqual(
337+
new functions.https.HttpsError('unauthenticated', 'Please Login First')
338+
)
339+
```
340+
341+
## Const Assertion
342+
343+
You can use const assertion if the handler is returning response from another callback, example from the transaction.
344+
345+
```ts
346+
import { onCall } from 'firecall'
347+
348+
export const someFun = onCall(someSchema, { route: 'private' }, async () => {
349+
// return the transaction
350+
return await db.runTransaction(async transaction => {
351+
return { code: 'ok', data: null } as const // do const assertion here
352+
})
353+
})
354+
```
355+
236356
## Function Builder
237357

238358
If you need custom setting for you function like changing ram or region, you can pass function builder to `onCall` config.
@@ -295,21 +415,6 @@ Whatever object literal the function return and(empty object = nothing to log) g
295415

296416
`logType` props is an optional prop that set the type of your log, by default it is `error`.
297417

298-
## Const Assertion
299-
300-
You can use const assertion if the handler is returning response from another callback, example from the transaction.
301-
302-
```ts
303-
import { onCall } from 'firecall'
304-
305-
export const someFun = onCall(someSchema, { route: 'private' }, async () => {
306-
// return the transaction
307-
return await db.runTransaction(async transaction => {
308-
return { code: 'ok', data: null } as const // do const assertion here
309-
})
310-
})
311-
```
312-
313418
## Change Built In Error Message
314419

315420
Here is how you change the built in error message:

babel.config.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
presets: [
3+
'@babel/preset-typescript',
4+
[
5+
'@babel/preset-env',
6+
{
7+
targets: {
8+
node: 'current',
9+
},
10+
},
11+
],
12+
],
13+
}

functions/.eslintrc.js

-34
This file was deleted.

functions/.gitignore

-12
This file was deleted.

functions/babel.config.js

-21
This file was deleted.

functions/jest.config.js

-12
This file was deleted.

0 commit comments

Comments
 (0)