Skip to content

Commit 0d4bf1e

Browse files
committed
better TS + lint
1 parent 7f4bc24 commit 0d4bf1e

19 files changed

+93
-217
lines changed

Diff for: .eslintrc

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,14 @@
1616
{
1717
"files": ["composables/*", "components/*", "app/*", "relay/*"],
1818
"excludedFiles": ["**/dist/*", "**/_dist/*"]
19-
}
19+
},
20+
{
21+
// enable the rule specifically for TypeScript files
22+
"files": ["*.ts", "*.tsx"],
23+
"parserOptions": {
24+
"parser": "@typescript-eslint/parser"
25+
}
26+
}
2027
],
2128
"parserOptions": {
2229
"ecmaVersion": "latest",
@@ -28,6 +35,9 @@
2835
],
2936
"rules": {
3037
"no-unused-vars": 0,
31-
"vue/multi-word-component-names": 0
38+
"vue/multi-word-component-names": 0,
39+
"@typescript-eslint/ban-ts-comment": {
40+
"ts-ignore": "allow-with-description"
41+
}
3242
}
3343
}

Diff for: .npmrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
strict-peer-dependencies=false
1+
strict-peer-dependencies=false
2+
shamefully-hoist=true

Diff for: app/jsconfig.json renamed to app/tsconfig.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"compilerOptions": {
3-
"target": "ESNext",
3+
"target": "ES2020",
44
"lib": ["DOM", "DOM.Iterable", "ESNext"],
55
"allowJs": true,
6-
"skipLibCheck": false,
6+
"skipLibCheck": true,
77
"esModuleInterop": false,
88
"allowSyntheticDefaultImports": true,
99
"strict": true,
@@ -14,7 +14,6 @@
1414
"isolatedModules": true,
1515
"noEmit": true,
1616
"baseUrl": "./",
17-
"jsx": "preserve",
1817
"paths": {
1918
"#composables": ["../composables/src/"],
2019
}

Diff for: components/src/docs/Composables.story.vue

-122
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,6 @@ This should prevent any Gun-Vue related code from running during build stage.
145145
<td><p>Read and write zip files</p>
146146
</td>
147147
</tr>
148-
<tr>
149-
<td><a href="#userelay">useRelay</a></td>
150-
<td><p>Relay connection management</p>
151-
</td>
152-
</tr>
153-
<tr>
154-
<td><a href="#userelays">useRelays</a></td>
155-
<td><p>Loads the <a href="https://github.com/amark/gun/wiki/volunteer.dht">list of active volunteer DHT gun nodes</a> and benchmarks ping for them</p>
156-
</td>
157-
</tr>
158148
<tr>
159149
<td><a href="#useworker">useWorker</a></td>
160150
<td><p>Worker wrapper for heavy functions</p>
@@ -502,118 +492,6 @@ Zips the whole post object
502492
| addFile | <code>function</code> | add a binary file to the zip |
503493
| downloadZip | <code>function</code> | initiate the download of the zip file |
504494

505-
<hr />
506-
507-
<a name="module_useRelay"></a>
508-
509-
## useRelay
510-
Relay connection management
511-
512-
513-
* [useRelay](#module_useRelay)
514-
* _static_
515-
* [.useRelay()](#module_useRelay.useRelay) ⇒ <code>useRelay</code>
516-
* _inner_
517-
* [~Relay](#module_useRelay..Relay) : <code>reactive</code>
518-
519-
### useRelay() ⇒ <code>useRelay</code>
520-
Peer server status monitor
521-
522-
**Example**
523-
```js
524-
import { useRelay } from '@gun-vue/composables';
525-
526-
const { relay, setPeer, resetPeer } = useRelay()
527-
```
528-
### Relay : <code>reactive</code>
529-
Peer server status reactive object
530-
531-
**Properties**
532-
533-
| Name | Type | Description |
534-
| --- | --- | --- |
535-
| host | <code>String</code> | the current peer server URL |
536-
| status | <code>String</code> | current connection status |
537-
| started | <code>Number</code> | the timestamp of server started current session |
538-
| pulse | <code>Number</code> | last received timestamp |
539-
| lag | <code>Number</code> | drift of the timestamp in ms |
540-
| diff | <code>Number</code> | age of the session in ms |
541-
| age | <code>String</code> | age of the session in human readable format |
542-
| blink | <code>Boolean</code> | a Boolean toggled every time the new pulse comes to drive animations |
543-
544-
**Example**
545-
```js
546-
{
547-
"peer": "https://etogun.glitch.me/gun",
548-
"host": "6db1edbb5aae",
549-
"status": "running",
550-
"started": 1642666725795,
551-
"pulse": 1642677007483,
552-
"lag": 8,
553-
"diff": 10281688,
554-
"age": "3h",
555-
"delay": 22,
556-
"blink": true
557-
}
558-
```
559-
<hr />
560-
561-
<a name="module_useRelays"></a>
562-
563-
## useRelays
564-
Loads the [list of active volunteer DHT gun nodes](https://github.com/amark/gun/wiki/volunteer.dht) and benchmarks ping for them
565-
566-
567-
* [useRelays](#module_useRelays)
568-
* _static_
569-
* [.loadRelays(loadRelaysOptions)](#module_useRelays.loadRelays) ⇒ <code>relays</code>
570-
* [.useRelays()](#module_useRelays.useRelays) ⇒ <code>useRelays</code>
571-
* _inner_
572-
* [~useRelays](#module_useRelays..useRelays) : <code>Object</code>
573-
* [~loadRelaysOptions](#module_useRelays..loadRelaysOptions) : <code>Object</code>
574-
* [~Relays](#module_useRelays..Relays) : <code>Array.&lt;Object&gt;</code>
575-
576-
### loadRelays(loadRelaysOptions) ⇒ <code>relays</code>
577-
Load the list of the relays
578-
579-
580-
| Param | Type |
581-
| --- | --- |
582-
| loadRelaysOptions | <code>Object</code> |
583-
584-
### useRelays() ⇒ <code>useRelays</code>
585-
Gets the list of actual gun relays and tool to update the list
586-
587-
**Example**
588-
```js
589-
import { useRelays } from '@gun-vue/composables'
590-
const { relays, errors, loadRelays } = useRelays()
591-
```
592-
### useRelays : <code>Object</code>
593-
**Properties**
594-
595-
| Name | Type |
596-
| --- | --- |
597-
| Relays | <code>Object</code> |
598-
| Errors | <code>Object</code> |
599-
| loadRelays | <code>function</code> |
600-
601-
### loadRelaysOptions : <code>Object</code>
602-
**Properties**
603-
604-
| Name | Type |
605-
| --- | --- |
606-
| source | <code>String</code> |
607-
608-
### Relays : <code>Array.&lt;Object&gt;</code>
609-
**Properties**
610-
611-
| Name | Type |
612-
| --- | --- |
613-
| hostname | <code>String</code> |
614-
| url | <code>String</code> |
615-
| ping | <code>Number</code> |
616-
617495
<hr />
618496

619497
<a name="module_useWorker"></a>

Diff for: components/tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"isolatedModules": true,
1515
"noEmit": true,
1616
"baseUrl": "./",
17-
"jsx": "preserve",
1817
"paths": {
1918
"@/*": ["./*"],
2019
"#composables": ["../composables/src/"],

Diff for: composables/src/account/Account.d.ts

-17
This file was deleted.
File renamed without changes.

Diff for: composables/src/account/useAccount.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ interface Profile {
77
name?: string
88
first_name?: string
99
last_name?: string
10-
birth_day?: string
11-
[key:string]:string | undefined
10+
birth_day?: string
11+
[key: string]: string | undefined
1212
}
1313

1414
interface Account {
@@ -17,15 +17,17 @@ interface Account {
1717
pulse: number
1818
blink: boolean
1919
profile: Profile
20-
petname?: string
21-
[key:string]: any
20+
petname?: string
21+
db?: object
22+
[key: string]: string | ComputedRef | number | Profile | boolean | Ref | object
2223
}
2324

2425
import { useGun, useUser, SEA } from "../index.js";
2526
import { useColor } from "../ui/index.js";
2627
import { computed, ComputedRef, reactive, Ref, ref } from "vue";
2728
import ms from "ms";
2829

30+
2931
const colorDeep = useColor("deep");
3032

3133
/**
@@ -67,15 +69,15 @@ export function useAccount(pub = ref(), { TIMEOUT = 10000 } = {}) {
6769
const { user } = useUser()
6870
const account = computed(() => {
6971

70-
const acc:Account = reactive({
71-
pub:pub.value,
72+
const acc: Account = reactive({
73+
pub: pub.value,
7274
color: computed(() => (pub.value ? colorDeep.hex(pub.value) : "gray")),
7375
profile: {
7476
name: "",
7577
},
7678
pulse: 0,
7779
lastSeen: computed(() => {
78-
let time = Date.now() - acc.pulse;
80+
const time = Date.now() - acc.pulse;
7981
if (time > TIMEOUT) {
8082
return ms(time);
8183
} else {
@@ -87,7 +89,7 @@ export function useAccount(pub = ref(), { TIMEOUT = 10000 } = {}) {
8789
});
8890

8991
if (user.is) {
90-
gun.user().get('petnames').get(pub.value).on(async(d:string) => {
92+
gun.user().get('petnames').get(pub.value).on(async (d: string) => {
9193
acc.petname = await SEA.decrypt(d, user.pair())
9294
})
9395
}
@@ -104,7 +106,7 @@ export function useAccount(pub = ref(), { TIMEOUT = 10000 } = {}) {
104106
.back()
105107
.get("profile")
106108
.map()
107-
.on((data:string, key:string) => {
109+
.on((data: string, key: string) => {
108110
acc.profile[key] = data;
109111
});
110112
return acc;
@@ -114,7 +116,7 @@ export function useAccount(pub = ref(), { TIMEOUT = 10000 } = {}) {
114116
}
115117

116118

117-
export async function setPetname(pub:string, name:string) {
119+
export async function setPetname(pub: string, name: string) {
118120
const { user } = useUser()
119121
if (!user.is) return
120122
const gun = useGun();
File renamed without changes.

Diff for: composables/src/gun/useGun.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Gun DB initialization and basic methods
33
* @module useGun
44
*/
5-
import type {IGun, IGunInstance} from 'gun'
5+
import type { IGunInstance } from 'gun'
66

77
import Gun from "gun/gun";
88
import "gun/lib/then";
@@ -53,7 +53,7 @@ export function useGun(options: object = { localStorage: false }): IGunInstance
5353
* get a secondary Gun instance for certificate management
5454
*/
5555

56-
export function useGun2(options: object = { localStorage: false }):IGunInstance {
56+
export function useGun2(options: object = { localStorage: false }): IGunInstance {
5757
if (!gun2) {
5858
gun2 = Gun({ peers: [peer.value], ...options });
5959
gunInstances.push(gun2)
@@ -73,7 +73,7 @@ export { default as SEA } from "gun/sea.js";
7373
* @function soul
7474
*/
7575

76-
// @ts-ignore
76+
// @ts-ignore: Incorrect GUN types
7777
export const soul = Gun?.node?.soul;
7878

7979
/**
@@ -82,7 +82,7 @@ export const soul = Gun?.node?.soul;
8282
* @function genUUID
8383
*/
8484

85-
// @ts-ignore
86-
export const genUUID:Function = Gun?.text?.random;
85+
// @ts-ignore: Incorrect Gun types
86+
export const genUUID: (num: number) => string = Gun?.text?.random;
8787

8888

Diff for: composables/src/gun/useRelay.js renamed to composables/src/gun/useRelay.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
import { useGun } from '.'
77
import { computed, reactive, watch } from 'vue'
8+
import type { Ref } from 'vue'
89
import { useStorage } from "@vueuse/core";
910
import ms from 'ms'
10-
import { defaultPeer } from '..';
1111

12+
const defaultPeer = "https://gun.defucc.me/gun";
1213

13-
export const peer = useStorage("peer", defaultPeer);
14+
export const peer: Ref = useStorage("peer", defaultPeer);
1415

1516
/**
1617
* @typedef {reactive} Relay Peer server status reactive object
@@ -37,7 +38,19 @@ export const peer = useStorage("peer", defaultPeer);
3738
* }
3839
*/
3940

40-
export const relay = reactive({
41+
interface Relay {
42+
peer: string
43+
host: string
44+
status: string
45+
pulse: number
46+
lag: number
47+
started: number
48+
diff: number
49+
age: string
50+
blink: boolean
51+
}
52+
53+
export const relay: Relay = reactive({
4154
list: [],
4255
peer: peer.value,
4356
host: new URL(peer.value).hostname,
@@ -59,7 +72,7 @@ watch(
5972
},
6073
)
6174

62-
function setPeer(url) {
75+
function setPeer(url: string) {
6376
peer.value = url
6477
window.location.reload()
6578
}
@@ -79,13 +92,15 @@ function resetPeer() {
7992
*
8093
* const { relay, setPeer, resetPeer } = useRelay()
8194
*/
82-
export function useRelay() {
95+
export function useRelay(): { relay: Relay, setPeer: (url: string) => void, resetPeer: () => void } {
8396
const gun = useGun()
8497
if (relay.pulse == 0) {
8598
gun
8699
.get(relay.host)
87100
.map()
88-
.on((d, k) => {
101+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
102+
//@ts-ignore
103+
.on((d: string, k: string) => {
89104
relay[k] = d
90105
})
91106
}

0 commit comments

Comments
 (0)