Skip to content

Commit 9088a01

Browse files
add context to args
1 parent d063627 commit 9088a01

9 files changed

+44
-39
lines changed

.husky/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
yarn lint

package.json

+4-8
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@
2828
"lint": "yarn lint:eslint && yarn lint:format",
2929
"lint:eslint": "eslint . --ext .ts,.js --fix",
3030
"lint:format": "prettier --write '**/*.{ts,js,json,md,yml}'",
31-
"prepack": "yarn test && yarn build"
31+
"prepack": "yarn test && yarn build",
32+
"prepare": "husky install"
3233
},
3334
"dependencies": {
3435
"@azure/functions": "1.2.3",
35-
"@devprotocol/khaos-core": "1.3.0",
36+
"@devprotocol/khaos-core": "^1.4.0",
3637
"@devprotocol/util-ts": "2.2.1",
3738
"bent": "7.3.12",
3839
"ramda": "0.27.1",
@@ -59,7 +60,7 @@
5960
"eslint-plugin-functional": "3.1.0",
6061
"esm": "3.2.25",
6162
"fs-extra": "10.0.0",
62-
"husky": "6.0.0",
63+
"husky": "^6.0.0",
6364
"ipfs-http-client": "49.0.4",
6465
"p-queue": "6.6.2",
6566
"prettier": "2.3.1",
@@ -82,11 +83,6 @@
8283
}
8384
}
8485
},
85-
"husky": {
86-
"hooks": {
87-
"pre-commit": "yarn lint"
88-
}
89-
},
9086
"repository": {
9187
"type": "git",
9288
"url": "git+https://github.com/dev-protocol/khaos-functions.git"

v0/callFunctions.test.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { callFunctions } from './callFunctions'
33
import * as example from '../functions/example'
44

55
test('Returns `abi` when the passed options.method is "abi"', async (t) => {
6-
const res = await callFunctions(example, { id: '', method: 'abi' } as any)
6+
const res = await callFunctions(example, {} as any, { id: '', method: 'abi' } as any)
77
t.is(res, example.abi)
88
})
99

1010
test('Calls `addresses` when the passed options.method is "addresses"', async (t) => {
11-
const res = await callFunctions(example, {
11+
const res = await callFunctions(example, {} as any, {
1212
id: '',
1313
method: 'addresses',
1414
options: { network: 'mainnet' },
@@ -17,7 +17,7 @@ test('Calls `addresses` when the passed options.method is "addresses"', async (t
1717
})
1818

1919
test('Calls `authorize` when the passed options.method is "authorize"', async (t) => {
20-
const res = await callFunctions(example, {
20+
const res = await callFunctions(example, {} as any, {
2121
id: '',
2222
method: 'authorize',
2323
options: { message: '', secret: '', request: {} as any },
@@ -26,7 +26,7 @@ test('Calls `authorize` when the passed options.method is "authorize"', async (t
2626
})
2727

2828
test('Calls `oraclize` when the passed options.method is "oraclize"', async (t) => {
29-
const res = await callFunctions(example, {
29+
const res = await callFunctions(example, {} as any, {
3030
id: '',
3131
method: 'oraclize',
3232
options: {
@@ -47,7 +47,7 @@ test('Calls `oraclize` when the passed options.method is "oraclize"', async (t)
4747
})
4848

4949
test('Calls `event` when the passed options.method is "event"', async (t) => {
50-
const res = await callFunctions(example, {
50+
const res = await callFunctions(example, {} as any, {
5151
id: '',
5252
method: 'event',
5353
options: {
@@ -58,7 +58,7 @@ test('Calls `event` when the passed options.method is "event"', async (t) => {
5858
})
5959

6060
test('Calls `pack` when the passed options.method is "pack"', async (t) => {
61-
const res = await callFunctions(example, {
61+
const res = await callFunctions(example, {} as any, {
6262
id: '',
6363
method: 'pack',
6464
options: {
@@ -74,15 +74,15 @@ test('Calls `pack` when the passed options.method is "pack"', async (t) => {
7474

7575
test('Returns undefined when the passed options.method is "addresses" but options.options is not passed', async (t) => {
7676
t.is(
77-
await callFunctions(example, {
77+
await callFunctions(example, {} as any, {
7878
id: '',
7979
method: 'addresses',
8080
options: { network: undefined },
8181
}),
8282
undefined
8383
)
8484
t.is(
85-
await callFunctions(example, {
85+
await callFunctions(example, {} as any, {
8686
id: '',
8787
method: 'addresses',
8888
}),
@@ -92,39 +92,39 @@ test('Returns undefined when the passed options.method is "addresses" but option
9292

9393
test('Returns undefined when the passed options.method is "authorize" but options.options is not passed', async (t) => {
9494
t.is(
95-
await callFunctions(example, {
95+
await callFunctions(example, {} as any, {
9696
id: '',
9797
method: 'authorize',
9898
options: { message: '', secret: '', request: undefined },
9999
}),
100100
undefined
101101
)
102102
t.is(
103-
await callFunctions(example, {
103+
await callFunctions(example, {} as any, {
104104
id: '',
105105
method: 'authorize',
106106
options: { message: '', secret: undefined, request: {} as any },
107107
}),
108108
undefined
109109
)
110110
t.is(
111-
await callFunctions(example, {
111+
await callFunctions(example, {} as any, {
112112
id: '',
113113
method: 'authorize',
114114
options: { message: undefined, secret: '', request: {} as any },
115115
}),
116116
undefined
117117
)
118118
t.is(
119-
await callFunctions(example, {
119+
await callFunctions(example, {} as any, {
120120
id: '',
121121
method: 'authorize',
122122
options: { message: undefined, secret: undefined, request: undefined },
123123
}),
124124
undefined
125125
)
126126
t.is(
127-
await callFunctions(example, {
127+
await callFunctions(example, {} as any, {
128128
id: '',
129129
method: 'authorize',
130130
}),
@@ -134,7 +134,7 @@ test('Returns undefined when the passed options.method is "authorize" but option
134134

135135
test('Returns undefined when the passed options.method is "oraclize" but options.options is not passed', async (t) => {
136136
t.is(
137-
await callFunctions(example, {
137+
await callFunctions(example, {} as any, {
138138
id: '',
139139
method: 'oraclize',
140140
options: {
@@ -150,7 +150,7 @@ test('Returns undefined when the passed options.method is "oraclize" but options
150150
undefined
151151
)
152152
t.is(
153-
await callFunctions(example, {
153+
await callFunctions(example, {} as any, {
154154
id: '',
155155
method: 'oraclize',
156156
options: {
@@ -162,7 +162,7 @@ test('Returns undefined when the passed options.method is "oraclize" but options
162162
undefined
163163
)
164164
t.is(
165-
await callFunctions(example, {
165+
await callFunctions(example, {} as any, {
166166
id: '',
167167
method: 'oraclize',
168168
options: {
@@ -178,7 +178,7 @@ test('Returns undefined when the passed options.method is "oraclize" but options
178178
undefined
179179
)
180180
t.is(
181-
await callFunctions(example, {
181+
await callFunctions(example, {} as any, {
182182
id: '',
183183
method: 'oraclize',
184184
options: {
@@ -190,7 +190,7 @@ test('Returns undefined when the passed options.method is "oraclize" but options
190190
undefined
191191
)
192192
t.is(
193-
await callFunctions(example, {
193+
await callFunctions(example, {} as any, {
194194
id: '',
195195
method: 'oraclize',
196196
}),
@@ -200,7 +200,7 @@ test('Returns undefined when the passed options.method is "oraclize" but options
200200

201201
test('Returns undefined when the passed options.method is "event" but options.options is not passed', async (t) => {
202202
t.is(
203-
await callFunctions(example, {
203+
await callFunctions(example, {} as any, {
204204
id: '',
205205
method: 'event',
206206
options: {
@@ -210,7 +210,7 @@ test('Returns undefined when the passed options.method is "event" but options.op
210210
undefined
211211
)
212212
t.is(
213-
await callFunctions(example, {
213+
await callFunctions(example, {} as any, {
214214
id: '',
215215
method: 'event',
216216
}),
@@ -220,7 +220,7 @@ test('Returns undefined when the passed options.method is "event" but options.op
220220

221221
test('Returns undefined when the passed options.method is "pack" but options.options is not passed', async (t) => {
222222
t.is(
223-
await callFunctions(example, {
223+
await callFunctions(example, {} as any, {
224224
id: '',
225225
method: 'pack',
226226
options: {
@@ -230,7 +230,7 @@ test('Returns undefined when the passed options.method is "pack" but options.opt
230230
undefined
231231
)
232232
t.is(
233-
await callFunctions(example, {
233+
await callFunctions(example, {} as any, {
234234
id: '',
235235
method: 'pack',
236236
}),

v0/callFunctions.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Context } from '@azure/functions'
12
import { Functions } from '@devprotocol/khaos-core'
23
import { UndefinedOr, whenDefined, whenDefinedAll } from '@devprotocol/util-ts'
34
import {
@@ -28,6 +29,7 @@ export const callFunctions: CallFunctions<V0Options> = async <
2829
T extends V0Options
2930
>(
3031
f: Functions,
32+
context: Context,
3133
options: T
3234
): Promise<
3335
UndefinedOr<
@@ -69,7 +71,7 @@ export const callFunctions: CallFunctions<V0Options> = async <
6971
always(
7072
whenDefined(
7173
(options as AddressesOptions)?.options?.network,
72-
(network) => f.addresses({ network })
74+
(network) => f.addresses({ network, context })
7375
)
7476
),
7577
],

v0/index.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let importFunctionsStub: SinonStub<
1515
ReturnType<typeof importFunctions['importFunctions']>
1616
>
1717
let callFunctionsSpy: SinonSpy<
18-
[Functions, V0Options],
18+
[Functions, Context, V0Options],
1919
ReturnType<typeof callFunctions['callFunctions']>
2020
>
2121
const importFunctionsSpy = spy(() => Promise.resolve(example))
@@ -46,10 +46,10 @@ test.serial(
4646
async (t) => {
4747
const test = `${Math.random()}`
4848
const expected = { id: 'example', test }
49-
await func((undefined as unknown) as Context, {
49+
await func({log: true} as any, {
5050
body: expected,
5151
})
52-
t.deepEqual(callFunctionsSpy.getCall(0).args, [example, expected as any])
52+
t.deepEqual(callFunctionsSpy.getCall(0).args, [example, {log: true}, expected as any])
5353
t.is(callFunctionsSpy.callCount, 1)
5454
}
5555
)

v0/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const httpTrigger: AzureFunction = async (
1313

1414
const funtions = await whenDefined(id, (x) => importFunctions(x))
1515
const data = await whenDefined(funtions, (f) =>
16-
callFunctions(f, { id, ...props })
16+
callFunctions(f, context, { id, ...props })
1717
)
1818
const body: V0Results<V0Options> = { data }
1919

v0/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Context } from '@azure/functions'
12
import {
23
Abi,
34
FunctionAddressesOptions,
@@ -14,6 +15,7 @@ import { AsyncReturnType, Merge, SetOptional } from 'type-fest'
1415

1516
export type CallFunctions<T extends V0Options> = (
1617
f: Functions,
18+
context: Context,
1719
options: T
1820
) => Promise<
1921
UndefinedOr<

yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@
7070
dependencies:
7171
arrify "^1.0.1"
7272

73-
"@devprotocol/khaos-core@1.3.0":
74-
version "1.3.0"
75-
resolved "https://registry.yarnpkg.com/@devprotocol/khaos-core/-/khaos-core-1.3.0.tgz#35e8b4e3d46cee81c406a034562f7bb2d09c9e68"
76-
integrity sha512-qy5nw/naCjiB2ba7KwSgJn2zgTbd4XzkJ+OpxbDZFkWu5WUk/tWVdjtpgGi0CnX48X9uyMI5FEN9wqptl+MBWw==
73+
"@devprotocol/khaos-core@^1.4.0":
74+
version "1.4.0"
75+
resolved "https://registry.yarnpkg.com/@devprotocol/khaos-core/-/khaos-core-1.4.0.tgz#51ab3fad76aab735f5b32d63054d4a09a4449cec"
76+
integrity sha512-CEsTyytMoBEqjQuvEJI3z7Kj+mp/4rEqvfSbjcVbZ6jIEiSM5n0ezmtf4CKLPPL0Wz0ZG/fQ6JQrPS4UnYnZ+Q==
7777
dependencies:
7878
"@azure/functions" "^1.2.3"
7979
"@devprotocol/util-ts" "2.2.1"

0 commit comments

Comments
 (0)