@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.
Files changed (63) hide show
  1. package/README.md +3 -0
  2. package/dist/auth.d.ts +16 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +3 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/channel.d.ts +6 -0
  7. package/dist/channel.d.ts.map +1 -0
  8. package/dist/channel.js +7 -0
  9. package/dist/channel.js.map +1 -0
  10. package/dist/client.d.ts +18 -0
  11. package/dist/client.d.ts.map +1 -0
  12. package/dist/client.js +7 -0
  13. package/dist/client.js.map +1 -0
  14. package/dist/context.d.ts +100 -0
  15. package/dist/context.d.ts.map +1 -0
  16. package/dist/context.js +39 -0
  17. package/dist/context.js.map +1 -0
  18. package/dist/fromAst.d.ts +4 -0
  19. package/dist/fromAst.d.ts.map +1 -0
  20. package/dist/fromAst.js +34 -0
  21. package/dist/fromAst.js.map +1 -0
  22. package/dist/function.d.ts +1 -0
  23. package/dist/function.d.ts.map +1 -0
  24. package/dist/function.js +1 -0
  25. package/dist/function.js.map +1 -0
  26. package/dist/functions.d.ts +181 -0
  27. package/dist/functions.d.ts.map +1 -0
  28. package/dist/functions.js +29 -0
  29. package/dist/functions.js.map +1 -0
  30. package/dist/geo.d.ts +36 -0
  31. package/dist/geo.d.ts.map +1 -0
  32. package/dist/geo.js +3 -0
  33. package/dist/geo.js.map +1 -0
  34. package/dist/index.d.ts +13 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +82 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/parseAst.d.ts +4 -0
  39. package/dist/parseAst.d.ts.map +1 -0
  40. package/dist/parseAst.js +34 -0
  41. package/dist/parseAst.js.map +1 -0
  42. package/dist/parseCode.d.ts +7 -0
  43. package/dist/parseCode.d.ts.map +1 -0
  44. package/dist/parseCode.js +44 -0
  45. package/dist/parseCode.js.map +1 -0
  46. package/dist/query.d.ts +7 -0
  47. package/dist/query.d.ts.map +1 -0
  48. package/dist/query.js +7 -0
  49. package/dist/query.js.map +1 -0
  50. package/dist/stream.d.ts +40 -0
  51. package/dist/stream.d.ts.map +1 -0
  52. package/dist/stream.js +63 -0
  53. package/dist/stream.js.map +1 -0
  54. package/dist/uws.d.ts +469 -0
  55. package/package.json +41 -0
  56. package/src/index.ts +107 -0
  57. package/src/parseCode.ts +53 -0
  58. package/test/examples/helloWorld/based.config.json +4 -0
  59. package/test/examples/helloWorld/index.ts +30 -0
  60. package/test/examples/query/based.config.json +4 -0
  61. package/test/examples/query/index.ts +28 -0
  62. package/test/types.ts +49 -0
  63. 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,4 @@
1
+ {
2
+ "name": "counter",
3
+ "type": "query"
4
+ }
@@ -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
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist",
6
+ "declarationMap": true
7
+ },
8
+ "include": ["src/**/*", "src/**/*.json"],
9
+ "exclude": ["node_modules", "test", "dist", "tmp", "examples"]
10
+ }