@based/type-gen 0.0.1
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/README.md +3 -0
- package/dist/auth.d.ts +16 -0
- package/dist/auth.d.ts.map +1 -0
- package/dist/auth.js +3 -0
- package/dist/auth.js.map +1 -0
- package/dist/channel.d.ts +6 -0
- package/dist/channel.d.ts.map +1 -0
- package/dist/channel.js +7 -0
- package/dist/channel.js.map +1 -0
- package/dist/client.d.ts +18 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +7 -0
- package/dist/client.js.map +1 -0
- package/dist/context.d.ts +100 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +39 -0
- package/dist/context.js.map +1 -0
- package/dist/fromAst.d.ts +4 -0
- package/dist/fromAst.d.ts.map +1 -0
- package/dist/fromAst.js +34 -0
- package/dist/fromAst.js.map +1 -0
- package/dist/function.d.ts +1 -0
- package/dist/function.d.ts.map +1 -0
- package/dist/function.js +1 -0
- package/dist/function.js.map +1 -0
- package/dist/functions.d.ts +181 -0
- package/dist/functions.d.ts.map +1 -0
- package/dist/functions.js +29 -0
- package/dist/functions.js.map +1 -0
- package/dist/geo.d.ts +36 -0
- package/dist/geo.d.ts.map +1 -0
- package/dist/geo.js +3 -0
- package/dist/geo.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/parseAst.d.ts +4 -0
- package/dist/parseAst.d.ts.map +1 -0
- package/dist/parseAst.js +34 -0
- package/dist/parseAst.js.map +1 -0
- package/dist/parseCode.d.ts +7 -0
- package/dist/parseCode.d.ts.map +1 -0
- package/dist/parseCode.js +44 -0
- package/dist/parseCode.js.map +1 -0
- package/dist/query.d.ts +7 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +7 -0
- package/dist/query.js.map +1 -0
- package/dist/stream.d.ts +40 -0
- package/dist/stream.d.ts.map +1 -0
- package/dist/stream.js +63 -0
- package/dist/stream.js.map +1 -0
- package/dist/uws.d.ts +469 -0
- package/package.json +41 -0
- package/src/index.ts +107 -0
- package/src/parseCode.ts +53 -0
- package/test/examples/helloWorld/based.config.json +4 -0
- package/test/examples/helloWorld/index.ts +30 -0
- package/test/examples/query/based.config.json +4 -0
- package/test/examples/query/index.ts +28 -0
- package/test/types.ts +49 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BasedFunction } from '@based/functions'
|
|
2
|
+
|
|
3
|
+
type Flap<T extends string> = {
|
|
4
|
+
bla: T
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const helloWorld: BasedFunction<
|
|
8
|
+
{
|
|
9
|
+
msg: string
|
|
10
|
+
gurt: number
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
bla: number
|
|
14
|
+
msg: string
|
|
15
|
+
f: Flap<'snurp'>
|
|
16
|
+
}
|
|
17
|
+
> = async (based, payload) => {
|
|
18
|
+
return { msg: 'hello ' + payload.msg, bla: 0, f: { bla: 'snurp' } }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default helloWorld
|
|
22
|
+
|
|
23
|
+
/*
|
|
24
|
+
import type HelloWorld from '../../type-gen/test/examples/helloWorld/index.ts'
|
|
25
|
+
call(
|
|
26
|
+
name: 'hello-world',
|
|
27
|
+
payload: Parameters<typeof HelloWorld>[1],
|
|
28
|
+
opts?: CallOptions
|
|
29
|
+
): ReturnType<typeof HelloWorld>
|
|
30
|
+
*/
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BasedQueryFunction } from '@based/functions'
|
|
2
|
+
|
|
3
|
+
const counter: BasedQueryFunction<
|
|
4
|
+
{
|
|
5
|
+
msg: string
|
|
6
|
+
gurt: number
|
|
7
|
+
} | void,
|
|
8
|
+
{ cnt: number }
|
|
9
|
+
> = async (based, payload, update) => {
|
|
10
|
+
let cnt = 0
|
|
11
|
+
const timer = setInterval(() => {
|
|
12
|
+
update({ cnt: ++cnt })
|
|
13
|
+
}, 100)
|
|
14
|
+
return () => {
|
|
15
|
+
clearInterval(timer)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default counter
|
|
20
|
+
|
|
21
|
+
/*
|
|
22
|
+
import type HelloWorld from '../../type-gen/test/examples/helloWorld/index.ts'
|
|
23
|
+
call(
|
|
24
|
+
name: 'hello-world',
|
|
25
|
+
payload: Parameters<typeof HelloWorld>[1],
|
|
26
|
+
opts?: CallOptions
|
|
27
|
+
): Parameters<Parameters<typeof HelloWorld>[2]>[0],
|
|
28
|
+
*/
|
package/test/types.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { updateTypes } from '../src'
|
|
3
|
+
import { join } from 'path'
|
|
4
|
+
import based from '@based/client'
|
|
5
|
+
import { readFile } from 'fs-extra'
|
|
6
|
+
|
|
7
|
+
test.serial('Generare types file from examples', async (t) => {
|
|
8
|
+
const result = await updateTypes([
|
|
9
|
+
{
|
|
10
|
+
config: require('./examples/helloWorld/based.config.json'),
|
|
11
|
+
path: join(__dirname, '/examples/helloWorld/index.ts'),
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
config: require('./examples/query/based.config.json'),
|
|
15
|
+
path: join(__dirname, '/examples/query/index.ts'),
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
config: { name: 'db:set', type: 'function' },
|
|
19
|
+
payload: 'any',
|
|
20
|
+
result: 'any',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
config: { name: 'db:update-schema', type: 'function' },
|
|
24
|
+
payload: 'any',
|
|
25
|
+
result: 'any',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
config: { name: 'db', type: 'query' },
|
|
29
|
+
payload: 'any',
|
|
30
|
+
result: 'any',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
config: { name: 'db:schema', type: 'query' },
|
|
34
|
+
payload: 'any',
|
|
35
|
+
result: 'any',
|
|
36
|
+
},
|
|
37
|
+
])
|
|
38
|
+
|
|
39
|
+
const file = await readFile(join(__dirname, '../../client/dist/index.d.ts'), {
|
|
40
|
+
encoding: 'utf-8',
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
t.true(result)
|
|
44
|
+
t.true(file.includes('counter'))
|
|
45
|
+
t.true(file.includes('db:schema'))
|
|
46
|
+
t.true(file.includes('db:update-schema'))
|
|
47
|
+
t.true(file.includes('db:set'))
|
|
48
|
+
t.true(file.includes('hello-world'))
|
|
49
|
+
})
|
package/tsconfig.json
ADDED