mirror of
https://github.com/amark/gun.git
synced 2025-06-02 20:26:44 +00:00
New GUN typings (#1205)
* New GUN typings * Fixing comments * Gun schema is now supported Co-authored-by: dbaranov <dbaranov@bellintegrator.com>
This commit is contained in:
parent
1051e477ba
commit
d53d157f19
4
global.d.ts
vendored
4
global.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import { IGun } from './types/gun/IGun';
|
||||
declare global {
|
||||
var Gun: IGun;
|
||||
}
|
24
gun.d.ts
vendored
24
gun.d.ts
vendored
@ -1,3 +1,23 @@
|
||||
import { IGun } from './types/gun/IGun';
|
||||
import { IGun, LEX } from './types/gun';
|
||||
|
||||
declare const Gun: IGun;
|
||||
export = Gun;
|
||||
export default Gun;
|
||||
|
||||
import {} from './types/gun/IGun';
|
||||
declare module './types/gun/IGun' {
|
||||
export interface IGun {
|
||||
window: Window
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Gun: IGun;
|
||||
GUN: IGun;
|
||||
}
|
||||
|
||||
interface StringConstructor {
|
||||
match(t: string, o: LEX | string): boolean;
|
||||
random(length?: number, alphabet?: string): string;
|
||||
}
|
||||
}
|
||||
|
20
index.d.ts
vendored
20
index.d.ts
vendored
@ -1,3 +1,19 @@
|
||||
import { IGun } from './types/gun/IGun';
|
||||
export * from './types/gun';
|
||||
export * from './types/sea';
|
||||
|
||||
import { IGun, LEX } from './types/gun';
|
||||
import { ISEA } from './types/sea';
|
||||
|
||||
declare const Gun: IGun;
|
||||
export = Gun;
|
||||
export default Gun;
|
||||
|
||||
export const SEA: ISEA;
|
||||
|
||||
declare global {
|
||||
const Gun: IGun;
|
||||
|
||||
interface StringConstructor {
|
||||
match(t: string, o: LEX | string): boolean;
|
||||
random(length?: number, alphabet?: string): string;
|
||||
}
|
||||
}
|
||||
|
31
lib/later.d.ts
vendored
Normal file
31
lib/later.d.ts
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* > Warning: Dependency script for browser: <script src="/gun/lib/open.js"></script>`
|
||||
*
|
||||
* Exact timing is not guaranteed! Because it uses `setTimeout` underneath. Further, after
|
||||
* the timeout, it must then open and load the snapshot, this will likely add at least 1ms
|
||||
* to the delay. Experimental: If this is problematic, please report it, as we can modify
|
||||
* the implementation of later to be more precise.)
|
||||
*
|
||||
* If a process/browser has to restart, the timeout will not be called. Experimental: If
|
||||
* this behavior is needed, please report it, as it could be added to the implementation
|
||||
*
|
||||
* Say you save some data, but want to do something with it later, like expire it or refresh
|
||||
* it. Well, then later is for you! You could use this to easily implement a TTL or similar
|
||||
* behavior
|
||||
*
|
||||
* @param seconds the number of seconds you want to wait before firing the callback
|
||||
*/
|
||||
later(
|
||||
/**
|
||||
* @param data a safe snapshot of what you saved, including full depth documents or circular
|
||||
* graphs, without any of the metadata
|
||||
* @param key name of the data
|
||||
*/
|
||||
callback: (data: TNode, key: string) => void,
|
||||
seconds: number
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}
|
||||
}
|
13
lib/load.d.ts
vendored
Normal file
13
lib/load.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* > Warning: Dependency script for browser: <script src="/gun/lib/open.js"></script>`
|
||||
*
|
||||
* Loads the full object once. It is the same as open but with the behavior of once
|
||||
*/
|
||||
load(
|
||||
callback: (data: TNode) => void
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}
|
||||
}
|
17
lib/not.d.ts
vendored
Normal file
17
lib/not.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* > Warning: `.not` has no guarantees, since data could theoretically exist on an unrelated
|
||||
* peer that we have no knowledge of. If you only have one server, and data is synced
|
||||
* through it, then you have a pretty reasonable assurance that a not found means that
|
||||
* the data doesn't exist yet. Just be mindful of how you use it
|
||||
*
|
||||
* @param callack If there's reason to believe the data doesn't exist, the callback will be
|
||||
* invoked. This can be used as a check to prevent implicitly writing data
|
||||
*/
|
||||
not(
|
||||
callack: (key: string) => void
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}
|
||||
}
|
23
lib/open.d.ts
vendored
Normal file
23
lib/open.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* Note: This will automatically load everything it can find on the context. This may sound
|
||||
* convenient, but may be unnecessary and excessive - resulting in more bandwidth and
|
||||
* slower load times for larger data. It could also result in your entire database being
|
||||
* loaded, if your app is highly interconnected
|
||||
*
|
||||
* Open behaves very similarly to `gun.on`, except it gives you the full depth of a document
|
||||
* on every update. It also works with graphs, tables, or other data structures. Think of
|
||||
* it as opening up a live connection to a document
|
||||
*
|
||||
* @param callback The callback has 1 parameter, and will get called every time an update
|
||||
* happens anywhere in the full depth of the data. Unlike most of the API, open does not
|
||||
* give you a node. It gives you a copy of your data with all metadata removed. Updates to
|
||||
* the callback will return the same data, with changes modified onto it
|
||||
*/
|
||||
open(
|
||||
callback: (data: TNode) => void
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}
|
||||
}
|
57
lib/path.d.ts
vendored
Normal file
57
lib/path.d.ts
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
import { IGunChain, GunSchema } from '../types/gun';
|
||||
|
||||
import {} from '../types/gun/IGunInstance';
|
||||
declare module '../types/gun/IGunInstance' {
|
||||
export interface IGunInstance<TNode> {
|
||||
/**
|
||||
* > Warning: This extension was removed from core, you probably shouldn't be using it!
|
||||
*
|
||||
* Path does the same thing as get but has some conveniences built in
|
||||
*
|
||||
* Once you've changed the context, you can read, write, and path again from that field.
|
||||
* While you can just chain one path after another, it becomes verbose, so there are two
|
||||
* shorthand styles:
|
||||
* - dot format
|
||||
* - array format
|
||||
*
|
||||
* The dot notation can do some strange things if you're not expecting it. Under the hood,
|
||||
* everything is changed into a string, including floating point numbers. If you use a
|
||||
* decimal in your path, it will split into two paths...
|
||||
*
|
||||
* This can be especially confusing as the chain might never resolve to a value
|
||||
*/
|
||||
path<T extends GunSchema & Record<string, GunSchema>>(
|
||||
value: string | string[]
|
||||
): IGunChain<T, any, IGunInstance<TNode>, string>;
|
||||
}
|
||||
}
|
||||
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* > Warning: This extension was removed from core, you probably shouldn't be using it!
|
||||
*
|
||||
* > Warning: Not included by default! You must
|
||||
* include it yourself via `require('gun/lib/path.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/path.js"></script>`!
|
||||
*
|
||||
* Path does the same thing as get but has some conveniences built in
|
||||
*
|
||||
* Once you've changed the context, you can read, write, and path again from that field.
|
||||
* While you can just chain one path after another, it becomes verbose, so there are two
|
||||
* shorthand styles:
|
||||
* - dot format
|
||||
* - array format
|
||||
*
|
||||
* The dot notation can do some strange things if you're not expecting it. Under the hood,
|
||||
* everything is changed into a string, including floating point numbers. If you use a
|
||||
* decimal in your path, it will split into two paths...
|
||||
*
|
||||
* This can be especially confusing as the chain might never resolve to a value
|
||||
*/
|
||||
path<T extends GunSchema & Record<string, GunSchema>>(
|
||||
value: string | string[]
|
||||
): IGunChain<T, any, TGunInstance, string>;
|
||||
}
|
||||
}
|
105
lib/promise.d.ts
vendored
Normal file
105
lib/promise.d.ts
vendored
Normal file
@ -0,0 +1,105 @@
|
||||
import { IGunChain2TNode } from '../types/utils.d';
|
||||
import {
|
||||
GunCallbackOn,
|
||||
GunDataNode,
|
||||
GunMessagePut,
|
||||
GunOptionsOn,
|
||||
GunOptionsOnce,
|
||||
GunOptionsPut,
|
||||
IGunChain,
|
||||
GunSchema,
|
||||
GunSoul,
|
||||
} from '../types/gun';
|
||||
|
||||
import {} from '../types/gun/IGunInstance';
|
||||
declare module '../types/gun/IGunInstance' {
|
||||
export interface IGunInstance<TNode> {
|
||||
/**
|
||||
* @param value the data to save
|
||||
* @param options `put` options
|
||||
*/
|
||||
promPut<V extends TNode & Record<string, GunSchema>>(
|
||||
value: V,
|
||||
options: GunOptionsPut
|
||||
): Promise<{
|
||||
ref: IGunChain<TNode, IGunInstance<TNode>, IGunInstance<TNode>, ''>;
|
||||
ack: GunMessagePut;
|
||||
}>;
|
||||
}
|
||||
}
|
||||
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* @param value the data to save
|
||||
* @param options `put` options
|
||||
*/
|
||||
promPut<
|
||||
V extends
|
||||
| (TNode extends object ? Partial<TNode> : TNode)
|
||||
| GunSoul<TNode>
|
||||
| IGunChain<TNode, any, any, any>
|
||||
| IGunChain<NonNullable<TNode>, any, any, any>
|
||||
>(
|
||||
value: V,
|
||||
options: GunOptionsPut
|
||||
): Promise<{
|
||||
ref: IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
ack: GunMessagePut;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* @param value the data to save
|
||||
* @param options `put` options
|
||||
*/
|
||||
promSet<
|
||||
V extends Partial<N> | GunSoul<N> | IGunChain<N, any, any, any>,
|
||||
K extends keyof TNode & string,
|
||||
N extends TNode[K] & Record<string, GunSchema>
|
||||
>(
|
||||
value: V,
|
||||
options: GunOptionsPut
|
||||
): Promise<{
|
||||
ref: V extends GunSchema
|
||||
? IGunChain<
|
||||
N,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>
|
||||
: IGunChain<
|
||||
IGunChain2TNode<V>,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>;
|
||||
ack: GunMessagePut;
|
||||
}>;
|
||||
|
||||
/**
|
||||
* @param callback function to be called upon changes to data
|
||||
* @param options `put` options
|
||||
*/
|
||||
promOn<V extends TNode>(
|
||||
callback: GunCallbackOn<V, TKey>,
|
||||
options: GunOptionsOn
|
||||
): Promise<GunDataNode<V>>;
|
||||
|
||||
/**
|
||||
* @param limit due to promises resolving too fast if we do not set a timer we will not be
|
||||
* able receive any data back from gun before returning the promise works both following a
|
||||
* `Chain.get` and a `Chain.map` (limit only applies to map). If no limit is chosen,
|
||||
* defaults to 100 ms (quite sufficient to fetch about 2000 nodes or more)
|
||||
* @param options `once` options
|
||||
*/
|
||||
promOnce(
|
||||
limit: number,
|
||||
options: GunOptionsOnce
|
||||
): Promise<{
|
||||
ref: IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
data: GunDataNode<TNode>;
|
||||
key: keyof IGunChain2TNode<TChainParent> & string;
|
||||
}>;
|
||||
}
|
||||
}
|
15
lib/radisk.d.ts
vendored
Normal file
15
lib/radisk.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { IRadix } from './radix';
|
||||
|
||||
import {} from './radisk'
|
||||
declare module './radisk' {
|
||||
export const Radisk: IRadisk;
|
||||
export interface IRadisk {
|
||||
Radix: IRadix;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Radisk: IRadisk;
|
||||
}
|
||||
}
|
11
lib/radix.d.ts
vendored
Normal file
11
lib/radix.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
import {} from './radix'
|
||||
declare module './radix' {
|
||||
export const Radix: IRadix;
|
||||
export interface IRadix {}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
Radix: IRadix;
|
||||
}
|
||||
}
|
14
lib/rindexed.d.ts
vendored
Normal file
14
lib/rindexed.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
import {} from './rindexed'
|
||||
declare module './rindexed' {
|
||||
export const Store: IRindexedDB;
|
||||
export interface IRindexedDB {
|
||||
indexedDB: IRindexedDB;
|
||||
window: Window;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
RindexedDB: IRindexedDB;
|
||||
}
|
||||
}
|
2
lib/store.d.ts
vendored
Normal file
2
lib/store.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import {} from './store'
|
||||
declare module './store' {}
|
26
lib/then.d.ts
vendored
Normal file
26
lib/then.d.ts
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
import { GunDataNode, IGunChain } from '..';
|
||||
|
||||
import {} from '../types/gun/IGunChain';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* Could be buggy until official!
|
||||
*
|
||||
* Note: a gun chain is not promises! You must include and call `.then()` to promisify a gun
|
||||
* chain!
|
||||
*/
|
||||
then(): Promise<GunDataNode<TNode>>;
|
||||
|
||||
/**
|
||||
* Could be buggy until official!
|
||||
*
|
||||
* `.then()` has a cousin of `.promise()` which behaves the same way except that resolved
|
||||
* is an object in case you need more context or metadata
|
||||
*/
|
||||
promise(): Promise<{
|
||||
put: GunDataNode<TNode>;
|
||||
get: TKey;
|
||||
gun: IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}>;
|
||||
}
|
||||
}
|
23
lib/unset.d.ts
vendored
Normal file
23
lib/unset.d.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
import { GunSchema, GunSoul, IGunChain } from '..';
|
||||
|
||||
import {} from '../types/gun/IGunChain';
|
||||
import { IGunChain2TNode } from '../types/utils';
|
||||
declare module '../types/gun/IGunChain' {
|
||||
export interface IGunChain<TNode, TChainParent, TGunInstance, TKey> {
|
||||
/**
|
||||
* After you save some data in an unordered list, you may need to remove it
|
||||
*/
|
||||
unset<
|
||||
T extends Partial<V> | GunSoul<V> | IGunChain<V, any, any, any>,
|
||||
K extends keyof TNode & string,
|
||||
V extends TNode[K] & Record<string, GunSchema>
|
||||
>(
|
||||
node: IGunChain<
|
||||
IGunChain2TNode<T>,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
}
|
||||
}
|
2
lib/webrtc.d.ts
vendored
Normal file
2
lib/webrtc.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import {} from './webrtc'
|
||||
declare module './webrtc' {}
|
21
sea.d.ts
vendored
Normal file
21
sea.d.ts
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
import { ISEA } from './types/sea/ISEA';
|
||||
|
||||
import {} from './types/sea/ISEA';
|
||||
declare module './types/sea/ISEA' {
|
||||
export interface ISEA {
|
||||
window: Window
|
||||
}
|
||||
}
|
||||
|
||||
import {} from './types/gun/IGun';
|
||||
declare module './types/gun/IGun' {
|
||||
export interface IGun {
|
||||
SEA: ISEA;
|
||||
}
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
SEA: ISEA;
|
||||
}
|
||||
}
|
@ -4,14 +4,14 @@
|
||||
"declaration": true,
|
||||
},
|
||||
"include": [
|
||||
// only compile the type definitions by default.
|
||||
// That is, ignore the files in 'examples/**'
|
||||
"types/**.d.ts"
|
||||
// only compile the type definitions by default.
|
||||
// That is, ignore the files in 'examples/**'
|
||||
"**/*.d.ts"
|
||||
],
|
||||
"exclude": [
|
||||
// Among the type definitions, don't try to compile
|
||||
// the test file which implements bad types.
|
||||
// It implements bad types for testing purposes.
|
||||
"types/index.test-d.ts"
|
||||
"**/*.test-d.ts"
|
||||
]
|
||||
}
|
||||
|
7
types/gun/AckCallback.d.ts
vendored
7
types/gun/AckCallback.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
export declare type AckCallback = (ack: {
|
||||
err: string;
|
||||
ok: undefined;
|
||||
} | {
|
||||
err: undefined;
|
||||
ok: string;
|
||||
}) => void;
|
20
types/gun/AuthCallback.d.ts
vendored
20
types/gun/AuthCallback.d.ts
vendored
@ -1,20 +0,0 @@
|
||||
import { ISEAPair } from "../sea/ISEAPair";
|
||||
|
||||
export type AuthCallback = (ack: {
|
||||
ack: 2;
|
||||
ing: false,
|
||||
id: number,
|
||||
get: string;
|
||||
on: (tag:unknown , args:unknown, as: unknown) => unknown;
|
||||
put: {
|
||||
alias: string;
|
||||
auth: string;
|
||||
epub: string;
|
||||
pub: string;
|
||||
};
|
||||
sea: ISEAPair;
|
||||
err?: undefined;
|
||||
soul: string;
|
||||
} | {
|
||||
err: string;
|
||||
}) => void
|
9
types/gun/CreateCallback.d.ts
vendored
9
types/gun/CreateCallback.d.ts
vendored
@ -1,9 +0,0 @@
|
||||
export type CreateCallback = (ack: {
|
||||
ok: 0;
|
||||
pub: string;
|
||||
err?:undefined
|
||||
} | {
|
||||
ok?: 0;
|
||||
pub?: string;
|
||||
err: string;
|
||||
}) => any
|
18
types/gun/GunCallbackGet.d.ts
vendored
Normal file
18
types/gun/GunCallbackGet.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
import { GunDataNode, GunSchema, GunSoul } from '.';
|
||||
import { GunSoul2Soul } from '../utils';
|
||||
|
||||
type GunMessageGet<
|
||||
N extends GunSchema,
|
||||
K extends (keyof N & string) | GunSoul2Soul<GunSoul<N>>,
|
||||
V = K extends keyof N & string ? N[K] : N
|
||||
> = {
|
||||
/** key */
|
||||
get: K;
|
||||
/** value */
|
||||
put: GunDataNode<V extends GunSchema ? V : N>;
|
||||
};
|
||||
|
||||
export type GunCallbackGet<
|
||||
N extends GunSchema,
|
||||
K extends (keyof N & string) | GunSoul2Soul<GunSoul<N>>
|
||||
> = (ack: GunMessageGet<N, K>) => void;
|
7
types/gun/GunCallbackMap.d.ts
vendored
Normal file
7
types/gun/GunCallbackMap.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { GunDataNode, GunSchema } from '.';
|
||||
|
||||
export type GunCallbackMap<
|
||||
V extends N[K],
|
||||
K extends keyof N & string,
|
||||
N extends GunSchema
|
||||
> = (data: GunDataNode<V extends GunSchema ? V : never>, key: K) => any;
|
8
types/gun/GunCallbackOn.d.ts
vendored
Normal file
8
types/gun/GunCallbackOn.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { GunDataNode, GunHookMessagePut, IGunOnEvent, GunSchema } from '.';
|
||||
|
||||
export type GunCallbackOn<V extends GunSchema, K extends string> = (
|
||||
data: GunDataNode<V>,
|
||||
key: K,
|
||||
message: GunHookMessagePut,
|
||||
event: IGunOnEvent
|
||||
) => void;
|
6
types/gun/GunCallbackOnce.d.ts
vendored
Normal file
6
types/gun/GunCallbackOnce.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { GunDataNode, GunSchema } from '.';
|
||||
|
||||
export type GunCallbackOnce<V extends GunSchema, K extends string> = (
|
||||
data: GunDataNode<V>,
|
||||
key: K
|
||||
) => void;
|
11
types/gun/GunCallbackPut.d.ts
vendored
Normal file
11
types/gun/GunCallbackPut.d.ts
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
export type GunMessagePut =
|
||||
| {
|
||||
/** if there was an error during save */
|
||||
err: string;
|
||||
}
|
||||
| {
|
||||
/** if there was a success message (none is required though) */
|
||||
ok: { '': 1 };
|
||||
};
|
||||
|
||||
export type GunCallbackPut = (ack: GunMessagePut) => void;
|
16
types/gun/GunDataNode.d.ts
vendored
Normal file
16
types/gun/GunDataNode.d.ts
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
import { GunSchema, GunSoul, IGunMeta } from '.';
|
||||
|
||||
export type GunDataNode<T extends GunSchema> = T extends GunSchema & object
|
||||
? {
|
||||
[K in keyof T]: Exclude<
|
||||
T[K],
|
||||
string | number | boolean | null | undefined
|
||||
> extends never
|
||||
? T[K]
|
||||
:
|
||||
| GunSoul<
|
||||
Exclude<T[K], string | number | boolean | null | undefined>
|
||||
>
|
||||
| Exclude<T[K], object>;
|
||||
} & IGunMeta<T>
|
||||
: T;
|
6
types/gun/GunHookCallbackBye.d.ts
vendored
Normal file
6
types/gun/GunHookCallbackBye.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { IGunHookContext, GunPeer } from '.';
|
||||
|
||||
export type GunHookCallbackBye = (
|
||||
this: IGunHookContext<GunPeer>,
|
||||
peer: GunPeer
|
||||
) => void;
|
6
types/gun/GunHookCallbackCreate.d.ts
vendored
Normal file
6
types/gun/GunHookCallbackCreate.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { IGunHookContext, _GunRoot } from '.';
|
||||
|
||||
export type GunHookCallbackCreate = (
|
||||
this: IGunHookContext<_GunRoot>,
|
||||
root: _GunRoot
|
||||
) => void;
|
12
types/gun/GunHookCallbackGet.d.ts
vendored
Normal file
12
types/gun/GunHookCallbackGet.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { pany, IGunHookContext, GunNodeGet, _GunRoot } from '.';
|
||||
|
||||
type GunHookMessageGet<MessageExtension extends pany> = {
|
||||
$: { _: _GunRoot };
|
||||
'#': string;
|
||||
get: GunNodeGet;
|
||||
} & Partial<MessageExtension>;
|
||||
|
||||
export type GunHookCallackGet<MessageExtension extends pany> = (
|
||||
this: IGunHookContext<GunHookMessageGet<MessageExtension>>,
|
||||
message: GunHookMessageGet<MessageExtension>
|
||||
) => void;
|
6
types/gun/GunHookCallbackHi.d.ts
vendored
Normal file
6
types/gun/GunHookCallbackHi.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
import { IGunHookContext, GunPeer } from '.';
|
||||
|
||||
export type GunHookCallbackHi = (
|
||||
this: IGunHookContext<GunPeer>,
|
||||
peer: GunPeer
|
||||
) => void;
|
19
types/gun/GunHookCallbackIn.d.ts
vendored
Normal file
19
types/gun/GunHookCallbackIn.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
import { pany, IGunHookContext, GunDataNode, GunNodeGet, _GunRoot } from '.';
|
||||
|
||||
export type GunHookMessageIn<
|
||||
MessageExtension extends pany,
|
||||
MetaExtension extends pany
|
||||
> = {
|
||||
$: { _: _GunRoot };
|
||||
'#': string;
|
||||
get?: GunNodeGet;
|
||||
put?: { [nodePath: string]: GunDataNode<pany> & { _: MetaExtension } };
|
||||
} & Partial<MessageExtension>;
|
||||
|
||||
export type GunHookCallbackIn<
|
||||
MessageExtension extends pany,
|
||||
MetaExtension extends pany
|
||||
> = (
|
||||
this: IGunHookContext<GunHookMessageIn<MessageExtension, MetaExtension>>,
|
||||
message: GunHookMessageIn<MessageExtension, MetaExtension>
|
||||
) => void;
|
3
types/gun/GunHookCallbackOpt.d.ts
vendored
Normal file
3
types/gun/GunHookCallbackOpt.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { IGunHookContext, _GunRoot } from '.';
|
||||
|
||||
export type GunHookCallbackOpt = (this: IGunHookContext<_GunRoot>, root: _GunRoot) => void;
|
19
types/gun/GunHookCallbackOut.d.ts
vendored
Normal file
19
types/gun/GunHookCallbackOut.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
import { IGunHookContext, pany, GunDataNode, GunNodeGet, _GunRoot } from '.';
|
||||
|
||||
export type GunHookMessageOut<
|
||||
MessageExtension extends pany,
|
||||
MetaExtension extends pany
|
||||
> = {
|
||||
$: { _: _GunRoot };
|
||||
'#': string;
|
||||
get?: GunNodeGet;
|
||||
put?: { [nodePath: string]: GunDataNode<pany> & { _: MetaExtension } };
|
||||
} & Partial<MessageExtension>;
|
||||
|
||||
export type GunHookCallbackOut<
|
||||
MessageExtension extends pany,
|
||||
MetaExtension extends pany
|
||||
> = (
|
||||
this: IGunHookContext<GunHookMessageOut<MessageExtension, MetaExtension>>,
|
||||
message: GunHookMessageOut<MessageExtension, MetaExtension>
|
||||
) => void;
|
12
types/gun/GunHookCallbackPut.d.ts
vendored
Normal file
12
types/gun/GunHookCallbackPut.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
import { GunNodePut, IGunHookContext, _GunRoot } from '.';
|
||||
|
||||
type GunHookMessagePut = {
|
||||
$: { _: _GunRoot };
|
||||
'#'?: string;
|
||||
put: GunNodePut;
|
||||
};
|
||||
|
||||
export type GunHookCallbackPut = (
|
||||
this: IGunHookContext<GunHookMessagePut>,
|
||||
message: GunHookMessagePut
|
||||
) => void;
|
6
types/gun/GunNodeGet.d.ts
vendored
Normal file
6
types/gun/GunNodeGet.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export type GunNodeGet = {
|
||||
/** Node path */
|
||||
'#': string;
|
||||
/** Leaf name */
|
||||
'.': string;
|
||||
};
|
8
types/gun/GunNodePut.d.ts
vendored
Normal file
8
types/gun/GunNodePut.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { GunNodeGet, GunValueSimple } from '.';
|
||||
|
||||
export type GunNodePut = GunNodeGet & {
|
||||
/** Leaf value */
|
||||
':': GunValueSimple;
|
||||
/** Leaf timestamp */
|
||||
'>': number;
|
||||
};
|
37
types/gun/GunOptions.d.ts
vendored
Normal file
37
types/gun/GunOptions.d.ts
vendored
Normal file
@ -0,0 +1,37 @@
|
||||
export type GunOptions =
|
||||
| Partial<{
|
||||
/** Undocumented but mentioned. Write data to a JSON. */
|
||||
file: string;
|
||||
|
||||
/** Undocumented but mentioned. Create a websocket server */
|
||||
web: any;
|
||||
|
||||
/** Undocumented but mentioned. Amazon S3 */
|
||||
s3: {
|
||||
key: string;
|
||||
secret: string;
|
||||
bucket: string;
|
||||
region?: string;
|
||||
fakes3?: any;
|
||||
};
|
||||
|
||||
/** the URLs are properties, and the value is an empty object. */
|
||||
peers: string[] | Record<string, {}>;
|
||||
|
||||
/** default: true, creates and persists local (nodejs) data using Radisk. */
|
||||
radisk: boolean;
|
||||
|
||||
/** default: true, persists local (browser) data to localStorage. */
|
||||
localStorage: boolean;
|
||||
|
||||
/** uuid allows you to override the default 24 random alphanumeric soul generator with your own function. */
|
||||
uuid(): string;
|
||||
|
||||
/**
|
||||
* allows you to pass options to a 3rd party module. Their project README will likely list the exposed options
|
||||
* @see https://github.com/amark/gun/wiki/Modules
|
||||
*/
|
||||
[key: string]: any;
|
||||
}>
|
||||
| string
|
||||
| string[];
|
6
types/gun/GunOptionsOn.d.ts
vendored
Normal file
6
types/gun/GunOptionsOn.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export type GunOptionsOn = Partial<
|
||||
| {
|
||||
change: boolean;
|
||||
}
|
||||
| boolean
|
||||
>;
|
6
types/gun/GunOptionsOnce.d.ts
vendored
Normal file
6
types/gun/GunOptionsOnce.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export type GunOptionsOnce = Partial<{
|
||||
/**
|
||||
* controls the asynchronous timing
|
||||
*/
|
||||
wait: number;
|
||||
}>;
|
5
types/gun/GunOptionsPut.d.ts
vendored
Normal file
5
types/gun/GunOptionsPut.d.ts
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
export type GunOptionsPut = Partial<{
|
||||
opt: {
|
||||
/** certificate that gives other people write permission */ cert: string;
|
||||
};
|
||||
}>;
|
6
types/gun/GunPeer.d.ts
vendored
Normal file
6
types/gun/GunPeer.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export type GunPeer = {
|
||||
id: string;
|
||||
url: string;
|
||||
queue: string[];
|
||||
wire: null | WebSocket | RTCDataChannel;
|
||||
};
|
17
types/gun/GunSchema.d.ts
vendored
Normal file
17
types/gun/GunSchema.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import { GunValueSimple, IGunChain, IGunInstanceRoot } from '.';
|
||||
|
||||
interface IGunSchema {
|
||||
[key: string]:
|
||||
| Exclude<
|
||||
IGunSchema,
|
||||
IGunChain<any, any, any, any> | IGunInstanceRoot<any, any>
|
||||
>
|
||||
| GunValueSimple;
|
||||
}
|
||||
|
||||
export type GunSchema =
|
||||
| Exclude<
|
||||
IGunSchema,
|
||||
IGunChain<any, any, any, any> | IGunInstanceRoot<any, any>
|
||||
>
|
||||
| GunValueSimple;
|
4
types/gun/GunSoul.d.ts
vendored
Normal file
4
types/gun/GunSoul.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
import { GunSchema } from '.';
|
||||
export type GunSoul<_N extends GunSchema, Soul extends string = string> = {
|
||||
'#': Soul;
|
||||
};
|
1
types/gun/GunValueSimple.d.ts
vendored
Normal file
1
types/gun/GunValueSimple.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type GunValueSimple = string | number | boolean | null;
|
72
types/gun/IGun.d.ts
vendored
72
types/gun/IGun.d.ts
vendored
@ -1,45 +1,37 @@
|
||||
import { ISEA } from '../sea/ISEA';
|
||||
import { AckCallback } from './AckCallback';
|
||||
import { IGunConstructorOptions } from './IGunConstructorOptions';
|
||||
import { IGunDataType } from './IGunDataType';
|
||||
import { IGunInstance } from './IGunInstance';
|
||||
import { IGunReturnObject } from './IGunReturnObject';
|
||||
import {
|
||||
GunOptions,
|
||||
IGunInstance,
|
||||
_GunRoot,
|
||||
GunHookCallbackCreate,
|
||||
GunHookCallbackOpt,
|
||||
GunSchema,
|
||||
IGunChain,
|
||||
} from '.';
|
||||
|
||||
export interface IGun {
|
||||
/**
|
||||
* @description
|
||||
* no parameters creates a local datastore using the default persistence layer, either localStorage or Radisk.
|
||||
* @param options
|
||||
* passing a URL creates the above local datastore that also tries to sync with the URL.
|
||||
*
|
||||
* or you can pass in an array of URLs to sync with multiple peers.
|
||||
* DataType must be type not interface
|
||||
*/
|
||||
<DataType extends IGunDataType = IGunDataType>(options?: IGunConstructorOptions): IGunInstance<DataType,undefined>;
|
||||
new <DataType extends IGunDataType= IGunDataType>(options?: IGunConstructorOptions): IGunInstance<DataType,undefined>;
|
||||
readonly node: IGun;
|
||||
|
||||
/** @see https://gun.eco/docs/SEA */
|
||||
readonly SEA: ISEA;
|
||||
readonly version: string;
|
||||
readonly chain: IGunInstance<IGunDataType,undefined>;
|
||||
readonly log: {
|
||||
(...argv: any[]): void;
|
||||
once(...argv: any[]): void;
|
||||
off: boolean;
|
||||
};
|
||||
/** Returns true if data is a gun node, otherwise false. */
|
||||
is(anything: any): anything is IGunInstance<IGunDataType, undefined>;
|
||||
<TNode extends Record<string, GunSchema> = any>(options?: GunOptions): IGunInstance<TNode>;
|
||||
new <TNode extends Record<string, GunSchema> = any>(options?: GunOptions): IGunInstance<TNode>;
|
||||
|
||||
/**
|
||||
* Returns data's gun ID (instead of manually grabbing its metadata i.e. data["_"]["#"], which is faster but could change in the future)
|
||||
*
|
||||
* Returns undefined if data is not correct gun data.
|
||||
*/
|
||||
soul(data: IGunReturnObject<any, any>): string | undefined;
|
||||
/**
|
||||
* Returns GUN state timestamp
|
||||
*/
|
||||
state(): number;
|
||||
|
||||
/** Returns a "gun-ified" variant of the json input by injecting a new gun ID into the metadata field. */
|
||||
ify(json: any): any;
|
||||
chain: IGunChain<any> & IGunInstance<any>;
|
||||
|
||||
state():number
|
||||
}
|
||||
/**
|
||||
* Listener for a GUN instance creation
|
||||
*/
|
||||
on(
|
||||
event: 'create',
|
||||
callback: GunHookCallbackCreate
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Listener for a GUN options update
|
||||
*/
|
||||
on(
|
||||
event: 'opt',
|
||||
callback: GunHookCallbackOpt
|
||||
): void;
|
||||
}
|
||||
|
218
types/gun/IGunChain.d.ts
vendored
Normal file
218
types/gun/IGunChain.d.ts
vendored
Normal file
@ -0,0 +1,218 @@
|
||||
import {
|
||||
_GunRoot,
|
||||
GunCallbackPut,
|
||||
GunOptionsPut,
|
||||
LEXQuery,
|
||||
GunCallbackOn,
|
||||
GunOptionsOn,
|
||||
GunCallbackOnce,
|
||||
GunOptionsOnce,
|
||||
GunSchema,
|
||||
GunDataNode,
|
||||
GunCallbackGet,
|
||||
IGunInstanceRoot,
|
||||
GunSoul,
|
||||
GunCallbackMap,
|
||||
} from '.';
|
||||
import { IGunChain2TNode } from '../utils';
|
||||
|
||||
export interface IGunChain<
|
||||
TNode extends GunSchema,
|
||||
TChainParent extends
|
||||
| IGunChain<any, any, any, any>
|
||||
| IGunInstanceRoot<any, any> = any,
|
||||
TGunInstance extends IGunInstanceRoot<any, any> = any,
|
||||
TKey extends string = any
|
||||
> {
|
||||
_: _GunRoot;
|
||||
|
||||
/**
|
||||
* Save data into gun, syncing it with your connected peers
|
||||
*
|
||||
* @param value the data to save
|
||||
* @param callback an optional callback, invoked on each acknowledgment
|
||||
* @param options `put` options
|
||||
*/
|
||||
put<
|
||||
V extends
|
||||
| (TNode extends object ? Partial<TNode> : TNode)
|
||||
| GunSoul<TNode>
|
||||
| IGunChain<TNode, any, any, any>
|
||||
| IGunChain<NonNullable<TNode>, any, any, any>
|
||||
>(
|
||||
value: V,
|
||||
callback?: GunCallbackPut,
|
||||
options?: GunOptionsPut
|
||||
): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
|
||||
/**
|
||||
* Where to read data from
|
||||
*
|
||||
* @param key The key is the ID or property name of the data that you saved from
|
||||
* earlier (or that will be saved later)
|
||||
* @param callback The callback is a listener for read errors, not found, and updates.
|
||||
* It may be called multiple times for a single request, since gun uses a reactive
|
||||
* streaming architecture. Generally, you'll find `.not`, `.on`, and `.once` as more
|
||||
* convenient for every day use
|
||||
*/
|
||||
get<V extends N[K], K extends keyof N & string, N extends TNode>(
|
||||
key: K,
|
||||
callback?: GunCallbackGet<N, K>
|
||||
): V extends GunSchema
|
||||
? IGunChain<
|
||||
V,
|
||||
IGunChain<N, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Where to read data from
|
||||
*
|
||||
* @param query LEX query
|
||||
* @param callback The callback is a listener for read errors, not found, and updates.
|
||||
* It may be called multiple times for a single request, since gun uses a reactive
|
||||
* streaming architecture. Generally, you'll find `.not`, `.on`, and `.once` as more
|
||||
* convenient for every day use
|
||||
*/
|
||||
get<
|
||||
V extends N[K],
|
||||
K extends keyof TNode & string = keyof TNode & string,
|
||||
N extends TNode = TNode
|
||||
>(
|
||||
query: LEXQuery<K>,
|
||||
callback?: GunCallbackGet<N, TKey>
|
||||
): Record<K, V> extends GunSchema
|
||||
? IGunChain<Record<K, V>, TChainParent, TGunInstance, TKey>
|
||||
: never;
|
||||
|
||||
/**
|
||||
* Add a unique item to an unordered list. Works like a mathematical set, where each
|
||||
* item in the list is unique. If the item is added twice, it will be merged. This
|
||||
* means only objects, for now, are supported
|
||||
*
|
||||
* @param value the data to save
|
||||
* @param callback the callback is invoked exactly the same as `.put`, since `.set` is
|
||||
* just a convenience wrapper around `.put`
|
||||
*/
|
||||
set<
|
||||
V extends Partial<N> | GunSoul<N> | IGunChain<N, any, any, any>,
|
||||
K extends keyof TNode & string,
|
||||
N extends TNode[K] & Record<string, GunSchema>
|
||||
>(
|
||||
value: V,
|
||||
callback?: GunCallbackPut
|
||||
): V extends GunSchema
|
||||
? IGunChain<
|
||||
N,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>
|
||||
: IGunChain<
|
||||
IGunChain2TNode<V>,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>;
|
||||
|
||||
/**
|
||||
* Move up to the parent context on the chain. Every time a new chain is created, a
|
||||
* reference to the old context is kept to go back to
|
||||
*
|
||||
* @param amount The number of times you want to go back up the chain. `-1` will take you
|
||||
* to the root. `Infinity` is not yet supported in TypeScript
|
||||
*/
|
||||
back<GI extends TGunInstance>(amount: -1): GI;
|
||||
back<CP extends TChainParent>(): CP;
|
||||
back<N extends GunSchema>(): IGunChain<N, any, TGunInstance, string>;
|
||||
back<N extends GunSchema>(
|
||||
amount: number
|
||||
): IGunChain<N, any, TGunInstance, string>;
|
||||
|
||||
/**
|
||||
* Subscribe to updates and changes on a node or property in realtime
|
||||
*
|
||||
* @param callback Once initially and whenever the property or node you're focused on
|
||||
* changes, this callback is immediately fired with the data as it is at that point in
|
||||
* time. Once initially and whenever the property or node you're focused on changes,
|
||||
* this callback is immediately fired with the data as it is at that point in time
|
||||
* @param options currently, the only option is to filter out old data, and just be
|
||||
* given the changes. If you're listening to a node with 100 fields, and just one
|
||||
* changes, you'll instead be passed a node with a single property representing that
|
||||
* change rather than the full node every time
|
||||
*/
|
||||
on<V extends TNode>(
|
||||
callback?: GunCallbackOn<V, TKey>,
|
||||
options?: GunOptionsOn
|
||||
): IGunChain<V, TChainParent, TGunInstance, TKey>;
|
||||
|
||||
/**
|
||||
* Removes all listeners
|
||||
*/
|
||||
off(): IGunChain<TNode, TChainParent, TGunInstance, TKey>;
|
||||
|
||||
/**
|
||||
* Get the current data without subscribing to updates. Or undefined if it cannot be
|
||||
* found
|
||||
*
|
||||
* `.once` is synchronous and immediate (at extremely high performance) if the data has
|
||||
* already been loaded.
|
||||
*
|
||||
* `.once` is asynchronous and on a debounce timeout while data is still being loaded
|
||||
* - so it may be called completely out of order compared to other functions. This is
|
||||
* intended because gun streams partials of data, so once avoids firing immediately
|
||||
* because it may not represent the "complete" data set yet. You can control this
|
||||
* timeout with the wait option
|
||||
*
|
||||
* `.once` fires again if you update that node from within it
|
||||
*
|
||||
* @param callback The data is the value for that chain at that given point in time.
|
||||
* And the key is the last property name or ID of the node
|
||||
* @param options `once` options
|
||||
*/
|
||||
once<V extends TNode>(
|
||||
callback?: GunCallbackOnce<V, TKey>,
|
||||
options?: GunOptionsOnce
|
||||
): IGunChain<V, TChainParent, TGunInstance, TKey>;
|
||||
|
||||
/**
|
||||
* Iterates over each property and item on a node, passing it down the chain, behaving
|
||||
* like a forEach on your data. It also subscribes to every item as well and listens
|
||||
* for newly inserted items. It accepts one argument:
|
||||
* - a `callback` function that transforms the data as it passes through. If the data is
|
||||
* transformed to undefined it gets filtered out of the chain
|
||||
* - the `callback` gets two arguments (value, key) and will be called once for each
|
||||
* key value pair in the objects that are returned from map
|
||||
*
|
||||
* If your data is cyclic and has a lot of self-references, you may receive multiple
|
||||
* callbacks with the same result. For example: "Alice is both the president of the
|
||||
* company, the wife of Bob, and the friend to the cat." This would return 3 times:
|
||||
* ```
|
||||
* key: president value: alice,
|
||||
* key: wife value: alice,
|
||||
* key: friend value: alice
|
||||
* ```
|
||||
*
|
||||
* Here's a summary of .map() behavior depending on where it is on the chain:
|
||||
* - `users.map().on(cb)` subscribes to changes on every user and to users as they are
|
||||
* added.
|
||||
* - `users.map().once(cb)` gets each user once, including ones that are added over
|
||||
* time.
|
||||
* - `users.once().map().on(cb)` gets the user list once, but subscribes to changes on
|
||||
* each of those users (not added ones).
|
||||
* - `users.once().map().once(cb)` gets the user list once, gets each of those users
|
||||
* only once (not added ones).
|
||||
*/
|
||||
map<V extends N[K], K extends keyof N & string, N extends TNode>(
|
||||
callback?: GunCallbackMap<V, K, N>
|
||||
): V extends GunSchema
|
||||
? IGunChain<
|
||||
V,
|
||||
IGunChain<TNode, TChainParent, TGunInstance, TKey>,
|
||||
TGunInstance,
|
||||
K
|
||||
>
|
||||
: never;
|
||||
}
|
33
types/gun/IGunConstructorOptions.d.ts
vendored
33
types/gun/IGunConstructorOptions.d.ts
vendored
@ -1,33 +0,0 @@
|
||||
export type IGunConstructorOptions = Partial<{
|
||||
|
||||
/** Undocumented but mentioned. Write data to a JSON. */
|
||||
file: string;
|
||||
|
||||
/** Undocumented but mentioned. Create a websocket server */
|
||||
web: any;
|
||||
|
||||
/** Undocumented but mentioned. Amazon S3 */
|
||||
s3: {
|
||||
key: any;
|
||||
secret: any;
|
||||
bucket: any;
|
||||
};
|
||||
|
||||
/** the URLs are properties, and the value is an empty object. */
|
||||
peers: string[] | Record<string, {}>;
|
||||
|
||||
/** default: true, creates and persists local (nodejs) data using Radisk. */
|
||||
radisk: boolean;
|
||||
|
||||
/** default: true, persists local (browser) data to localStorage. */
|
||||
localStorage: boolean;
|
||||
|
||||
/** uuid allows you to override the default 24 random alphanumeric soul generator with your own function. */
|
||||
uuid(): string | number;
|
||||
|
||||
/**
|
||||
* allows you to pass options to a 3rd party module. Their project README will likely list the exposed options
|
||||
* @see https://github.com/amark/gun/wiki/Modules
|
||||
*/
|
||||
[key: string]: any;
|
||||
}> | string | string[];
|
8
types/gun/IGunDataType.d.ts
vendored
8
types/gun/IGunDataType.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
export type IGunDataType = {
|
||||
[P in string]: IGunDataType | string | number | boolean | null
|
||||
}&
|
||||
{
|
||||
[T in number]: IGunDataType | string | number | boolean | null
|
||||
}
|
||||
|
||||
export type IGunNodeDataType = IGunDataType | string | number | boolean | null
|
86
types/gun/IGunFinalTreeMethods.d.ts
vendored
86
types/gun/IGunFinalTreeMethods.d.ts
vendored
@ -1,86 +0,0 @@
|
||||
import { AckCallback } from "./AckCallback";
|
||||
import { AuthCallback } from "./AuthCallback";
|
||||
import { IGunDataType } from "./IGunDataType";
|
||||
import { IGunInstance } from "./IGunInstance";
|
||||
import { IGunReturnObject } from "./IGunReturnObject";
|
||||
|
||||
export interface IGunFinalTreeMethods<TValue, TKey, TSoul> {
|
||||
|
||||
not?(callback: (key: TKey) => void): IGunFinalTreeMethods<TValue, TKey, TSoul> ;
|
||||
/**
|
||||
* Say you save some data, but want to do something with it later, like expire it or refresh it.
|
||||
* Well, then `later` is for you! You could use this to easily implement a TTL or similar behavior.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/later.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/later.js"></script>`!
|
||||
*/
|
||||
later?(callback: (data: TValue, key: TKey) => void, seconds: number): IGunFinalTreeMethods<TValue, TKey, TSoul> ;
|
||||
off(): IGunFinalTreeMethods<TValue, TKey, TSoul> ;
|
||||
/* /**
|
||||
* Save data into gun, syncing it with your connected peers.
|
||||
*
|
||||
* * You cannot save primitive values at the root level.
|
||||
*
|
||||
* @param data You do not need to re-save the entire object every time,
|
||||
* gun will automatically merge your data into what already exists as a "partial" update.
|
||||
*
|
||||
* * `undefined`, `NaN`, `Infinity`, `array`, will be rejected.
|
||||
* * Traditional arrays are dangerous in real-time apps. Use `gun.set` instead.
|
||||
*
|
||||
* @param callback invoked on each acknowledgment
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
put(data: Partial<TValue>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunFinalTreeMethods<TValue, TKey, TSoul>
|
||||
|
||||
/**
|
||||
* Subscribe to updates and changes on a node or property in real-time.
|
||||
* @param option Currently, the only option is to filter out old data, and just be given the changes.
|
||||
* If you're listening to a node with 100 fields, and just one changes,
|
||||
* you'll instead be passed a node with a single property representing that change rather than the full node every time.
|
||||
* @param callback
|
||||
* Once initially and whenever the property or node you're focused on changes, this callback is immediately fired with the data as it is at that point in time.
|
||||
*
|
||||
* Since gun streams data, the callback will probably be called multiple times as new chunks come in.
|
||||
* To remove a listener call .off() on the same property or node.
|
||||
*/
|
||||
on(callback: (data: IGunReturnObject<TValue, TSoul>, key: TKey, _msg:any, _ev:any) => void, option?: {
|
||||
change: boolean;
|
||||
} | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunFinalTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Subscribe to database event.
|
||||
* @param eventName event name that you want listen to (currently only 'auth')
|
||||
* @param callback once event fire callback
|
||||
*/
|
||||
on(eventName: 'auth', cb: AuthCallback, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunFinalTreeMethods<TValue, TKey, TSoul>
|
||||
|
||||
/**
|
||||
* Get the current data without subscribing to updates. Or `undefined` if it cannot be found.
|
||||
* @returns In the document, it said the return value may change in the future. Don't rely on it.
|
||||
*/
|
||||
once(callback?: (data: IGunReturnObject<TValue, TSoul>, key: TKey) => void, option?: {
|
||||
wait: number;
|
||||
}): IGunFinalTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Open behaves very similarly to gun.on, except it gives you the **full depth of a document** on every update.
|
||||
* It also works with graphs, tables, or other data structures. Think of it as opening up a live connection to a document.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/open.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/open.js"></script>`!
|
||||
*/
|
||||
open?(callback: (data: IGunReturnObject<TValue, TSoul>) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<TValue>): IGunFinalTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Loads the full object once. It is the same as `open` but with the behavior of `once`.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/load.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/load.js"></script>`!
|
||||
*/
|
||||
load?(callback: (data: IGunReturnObject<TValue, TSoul>) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<TValue>): IGunFinalTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>
|
||||
|
||||
|
||||
/**goes back user chain */
|
||||
back(amount?:number) : IGunInstance<IGunDataType, string | undefined>
|
||||
|
||||
}
|
90
types/gun/IGunFinalUserTreeMethods.d.ts
vendored
90
types/gun/IGunFinalUserTreeMethods.d.ts
vendored
@ -1,90 +0,0 @@
|
||||
import { AckCallback } from "./AckCallback";
|
||||
import { AuthCallback } from "./AuthCallback";
|
||||
import { IGunDataType } from "./IGunDataType";
|
||||
import { IGunReturnObject } from "./IGunReturnObject";
|
||||
import { IGunUserInstance } from "./IGunUserInstance";
|
||||
|
||||
export interface IGunFinalUserTreeMethods<TValue, TKey, TSoul> {
|
||||
/**
|
||||
* check out https://gun.eco/docs/User#user-secret
|
||||
* save secret that only trusted users can read
|
||||
*
|
||||
*/
|
||||
not?(callback: (key: TKey) => void): IGunFinalUserTreeMethods<TValue, TKey, TSoul> ;
|
||||
/**
|
||||
* Say you save some data, but want to do something with it later, like expire it or refresh it.
|
||||
* Well, then `later` is for you! You could use this to easily implement a TTL or similar behavior.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/later.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/later.js"></script>`!
|
||||
*/
|
||||
later?(callback: (data: TValue, key: TKey) => void, seconds: number): IGunFinalUserTreeMethods<TValue, TKey, TSoul>;
|
||||
off(): IGunFinalUserTreeMethods<TValue, TKey, TSoul> ;
|
||||
/* /**
|
||||
* Save data into gun, syncing it with your connected peers.
|
||||
*
|
||||
* * You cannot save primitive values at the root level.
|
||||
*
|
||||
* @param data You do not need to re-save the entire object every time,
|
||||
* gun will automatically merge your data into what already exists as a "partial" update.
|
||||
*
|
||||
* * `undefined`, `NaN`, `Infinity`, `array`, will be rejected.
|
||||
* * Traditional arrays are dangerous in real-time apps. Use `gun.set` instead.
|
||||
*
|
||||
* @param callback invoked on each acknowledgment
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
put(data: Partial<TValue>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunFinalUserTreeMethods<TValue, TKey, TSoul>
|
||||
|
||||
/**
|
||||
* Subscribe to updates and changes on a node or property in real-time.
|
||||
* @param option Currently, the only option is to filter out old data, and just be given the changes.
|
||||
* If you're listening to a node with 100 fields, and just one changes,
|
||||
* you'll instead be passed a node with a single property representing that change rather than the full node every time.
|
||||
* @param callback
|
||||
* Once initially and whenever the property or node you're focused on changes, this callback is immediately fired with the data as it is at that point in time.
|
||||
*
|
||||
* Since gun streams data, the callback will probably be called multiple times as new chunks come in.
|
||||
* To remove a listener call .off() on the same property or node.
|
||||
*/
|
||||
on(callback: (data: IGunReturnObject<TValue, TSoul>, key: TKey, _msg:any, _ev:any) => void, option?: {
|
||||
change: boolean;
|
||||
} | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunFinalUserTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Subscribe to database event.
|
||||
* @param eventName event name that you want listen to (currently only 'auth')
|
||||
* @param callback once event fire callback
|
||||
*/
|
||||
on(eventName: 'auth', cb: AuthCallback, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any):IGunFinalUserTreeMethods<TValue, TKey, TSoul>
|
||||
|
||||
/**
|
||||
* Get the current data without subscribing to updates. Or `undefined` if it cannot be found.
|
||||
* @returns In the document, it said the return value may change in the future. Don't rely on it.
|
||||
*/
|
||||
once(callback?: (data: IGunReturnObject<TValue, TSoul>, key: TKey) => void, option?: {
|
||||
wait: number;
|
||||
}): IGunFinalUserTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Open behaves very similarly to gun.on, except it gives you the **full depth of a document** on every update.
|
||||
* It also works with graphs, tables, or other data structures. Think of it as opening up a live connection to a document.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/open.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/open.js"></script>`!
|
||||
*/
|
||||
open?(callback: (data: IGunReturnObject<TValue, TSoul>) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<TValue>): IGunFinalUserTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>;
|
||||
|
||||
/**
|
||||
* Loads the full object once. It is the same as `open` but with the behavior of `once`.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/load.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/load.js"></script>`!
|
||||
*/
|
||||
load?(callback: (data: IGunReturnObject<TValue, TSoul>) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<TValue>): IGunFinalUserTreeMethods<TValue, TKey, TSoul> | Promise<IGunReturnObject<TValue, TSoul>>
|
||||
|
||||
|
||||
/**goes back user chain */
|
||||
back(amount?:number) : IGunUserInstance<IGunDataType, string | undefined>
|
||||
secret(string: string, callback : (...args:unknown[])=> any): IGunFinalUserTreeMethods<TValue, TKey, TSoul>
|
||||
}
|
6
types/gun/IGunHookContext.d.ts
vendored
Normal file
6
types/gun/IGunHookContext.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export interface IGunHookContext<T> {
|
||||
off: () => void;
|
||||
to: {
|
||||
next: (subject: T) => void;
|
||||
};
|
||||
}
|
183
types/gun/IGunInstance.d.ts
vendored
183
types/gun/IGunInstance.d.ts
vendored
@ -1,181 +1,4 @@
|
||||
import { IGunInstanceRoot, GunSchema } from '.';
|
||||
|
||||
import { And } from "../shared/And";
|
||||
import { AckCallback } from "./AckCallback";
|
||||
import { AuthCallback } from "./AuthCallback";
|
||||
import { IGunConstructorOptions } from "./IGunConstructorOptions";
|
||||
import { IGunDataType, IGunNodeDataType } from "./IGunDataType";
|
||||
import { IGunFinalTreeMethods } from "./IGunFinalTreeMethods";
|
||||
import { IGunReturnObject } from "./IGunReturnObject";
|
||||
import { IGunTree } from "./IGunTree";
|
||||
import { IGunUserInstance } from "./IGunUserInstance";
|
||||
|
||||
|
||||
|
||||
|
||||
export interface IGunInstance<
|
||||
CurrentTreeDataType extends IGunNodeDataType,
|
||||
TSoul extends string | undefined
|
||||
>{
|
||||
|
||||
not?(callback: (key: TSoul) => void): IGunInstance<CurrentTreeDataType, TSoul> ;
|
||||
/**
|
||||
* Say you save some data, but want to do something with it later, like expire it or refresh it.
|
||||
* Well, then `later` is for you! You could use this to easily implement a TTL or similar behavior.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/later.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/later.js"></script>`!
|
||||
*/
|
||||
later?(callback: (data: CurrentTreeDataType, key: TSoul) => void, seconds: number): IGunInstance<CurrentTreeDataType, TSoul> ;
|
||||
off(): IGunInstance<CurrentTreeDataType, TSoul> ;
|
||||
/* /**
|
||||
* Save data into gun, syncing it with your connected peers.
|
||||
*
|
||||
* * You cannot save primitive values at the root level.
|
||||
*
|
||||
* @param data You do not need to re-save the entire object every time,
|
||||
* gun will automatically merge your data into what already exists as a "partial" update.
|
||||
*
|
||||
* * `undefined`, `NaN`, `Infinity`, `array`, will be rejected.
|
||||
* * Traditional arrays are dangerous in real-time apps. Use `gun.set` instead.
|
||||
*
|
||||
* @param callback invoked on each acknowledgment
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
put(data: Partial<CurrentTreeDataType>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunInstance<CurrentTreeDataType, TSoul>
|
||||
|
||||
/**
|
||||
* Subscribe to updates and changes on a node or property in real-time.
|
||||
* @param option Currently, the only option is to filter out old data, and just be given the changes.
|
||||
* If you're listening to a node with 100 fields, and just one changes,
|
||||
* you'll instead be passed a node with a single property representing that change rather than the full node every time.
|
||||
* @param callback
|
||||
* Once initially and whenever the property or node you're focused on changes, this callback is immediately fired with the data as it is at that point in time.
|
||||
*
|
||||
* Since gun streams data, the callback will probably be called multiple times as new chunks come in.
|
||||
* To remove a listener call .off() on the same property or node.
|
||||
*/
|
||||
on(callback: (data: IGunReturnObject<CurrentTreeDataType, TSoul>, key: TSoul, _msg:any, _ev:any) => void, option?: {
|
||||
change: boolean;
|
||||
} | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunInstance<CurrentTreeDataType, TSoul> | Promise<IGunReturnObject<CurrentTreeDataType, TSoul>>;
|
||||
|
||||
/**
|
||||
* Subscribe to database event.
|
||||
* @param eventName event name that you want listen to (currently only 'auth')
|
||||
* @param callback once event fire callback
|
||||
*/
|
||||
on(eventName: 'auth', cb: AuthCallback, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunInstance<CurrentTreeDataType, TSoul>
|
||||
|
||||
/**
|
||||
* Get the current data without subscribing to updates. Or `undefined` if it cannot be found.
|
||||
* @returns In the document, it said the return value may change in the future. Don't rely on it.
|
||||
*/
|
||||
once(callback?: (data: IGunReturnObject<CurrentTreeDataType, TSoul>, key: TSoul) => void, option?: {
|
||||
wait: number;
|
||||
}): IGunInstance<CurrentTreeDataType, TSoul>| Promise<IGunReturnObject<CurrentTreeDataType, TSoul>>;
|
||||
|
||||
/**
|
||||
* Open behaves very similarly to gun.on, except it gives you the **full depth of a document** on every update.
|
||||
* It also works with graphs, tables, or other data structures. Think of it as opening up a live connection to a document.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/open.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/open.js"></script>`!
|
||||
*/
|
||||
open?(callback: (data: IGunReturnObject<CurrentTreeDataType, TSoul>) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<CurrentTreeDataType>): IGunInstance<CurrentTreeDataType, TSoul> | Promise<IGunReturnObject<CurrentTreeDataType, TSoul>>;
|
||||
|
||||
/**
|
||||
* Loads the full object once. It is the same as `open` but with the behavior of `once`.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/load.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/load.js"></script>`!
|
||||
*/
|
||||
load?(callback: (data: IGunReturnObject<CurrentTreeDataType, TSoul>) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<CurrentTreeDataType>): IGunInstance<CurrentTreeDataType, TSoul> | Promise<IGunReturnObject<CurrentTreeDataType, TSoul>>
|
||||
|
||||
|
||||
/**goes back user chain */
|
||||
back(amount?:number) : IGunInstance<IGunDataType, string | undefined>
|
||||
/**
|
||||
* **.set does not mean 'set data', it means a Mathematical Set**
|
||||
*
|
||||
* Add a unique item to an unordered list.
|
||||
* `gun.set` works like a mathematical set, where each item in the list is unique.
|
||||
* If the item is added twice, it will be merged.
|
||||
*
|
||||
* **This means only objects, for now, are supported.**
|
||||
* @param data the object to add to the set
|
||||
* @param callback optional function to invoke when the operation is complete
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
set<K extends keyof CurrentTreeDataType>(data: CurrentTreeDataType[K], callback?: AckCallback | null, options?: { opt?: { cert?: string } }): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance<CurrentTreeDataType[K], string>: IGunFinalTreeMethods<CurrentTreeDataType[K], K, string>;
|
||||
|
||||
/**
|
||||
* Where to read data from.
|
||||
* @param key The key is the ID or property name of the data that you saved from earlier
|
||||
* (or that will be saved later).
|
||||
* * Note that if you use .put at any depth after a get it first reads the data and then writes, merging the data as a partial update.
|
||||
* @param callback You will usually be using gun.on or gun.once to actually retrieve your data,
|
||||
* not this callback (it is intended for more low-level control, for module and extensions).
|
||||
*
|
||||
* **Avoid use callback. The type in the document may be wrong.**
|
||||
*
|
||||
* **Here the type of callback respect to the actual behavior**
|
||||
*/
|
||||
get<K extends keyof CurrentTreeDataType>(key: K, callback?: (
|
||||
data: IGunReturnObject<CurrentTreeDataType[K], string>,
|
||||
key: K) => any):
|
||||
And< Promise<CurrentTreeDataType[K]>,
|
||||
CurrentTreeDataType[K] extends IGunDataType ?
|
||||
IGunInstance<CurrentTreeDataType[K], string> & IGunFinalTreeMethods<CurrentTreeDataType[K], K, string> :
|
||||
IGunDataType extends CurrentTreeDataType[K] ?
|
||||
IGunFinalTreeMethods<CurrentTreeDataType[K] , K, string> & IGunInstance<IGunDataType, string>
|
||||
: IGunFinalTreeMethods<CurrentTreeDataType[K], K, string>>
|
||||
|
||||
|
||||
map<T>(match: (data: CurrentTreeDataType) => T ): IGunFinalTreeMethods<T, keyof CurrentTreeDataType, string>
|
||||
/**
|
||||
* After you save some data in an unordered list, you may need to remove it.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/unset.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/unset.js"></script>`!
|
||||
*/
|
||||
unset?<K extends keyof CurrentTreeDataType>(data: K): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance<CurrentTreeDataType[K], string>: IGunFinalTreeMethods<CurrentTreeDataType[K], K, string>;
|
||||
|
||||
|
||||
/**
|
||||
* Map iterates over each property and item on a node, passing it down the chain,
|
||||
* behaving like a forEach on your data.
|
||||
* It also subscribes to every item as well and listens for newly inserted items.
|
||||
*/
|
||||
map(match: IGunTree): CurrentTreeDataType[keyof CurrentTreeDataType] extends IGunDataType? IGunInstance<CurrentTreeDataType[keyof CurrentTreeDataType], string> : IGunFinalTreeMethods<CurrentTreeDataType[keyof CurrentTreeDataType], keyof CurrentTreeDataType, string>
|
||||
|
||||
|
||||
opt(opt: IGunConstructorOptions): unknown
|
||||
/**
|
||||
*
|
||||
* Path does the same thing as `.get` but has some conveniences built in.
|
||||
* @deprecated This is not friendly with type system.
|
||||
*
|
||||
* **Warning**: This extension was removed from core, you probably shouldn't be using it!
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/path.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/path.js"></script>`!
|
||||
*/
|
||||
path?(path: string | string[]): unknown;
|
||||
|
||||
|
||||
/**
|
||||
* Subscribes to all future events that occur on the Timegraph and retrieve a specified number of old events
|
||||
*
|
||||
* **Warning**: The Timegraph extension isn't required by default, you would need to include at "gun/lib/time.js"
|
||||
*/
|
||||
time?<K extends keyof CurrentTreeDataType>(callback: (data: CurrentTreeDataType[K], key: K, time: number) => void, alsoReceiveNOldEvents?: number): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance<CurrentTreeDataType[K], string>: IGunFinalTreeMethods<CurrentTreeDataType[K], K, string>;
|
||||
|
||||
/** Pushes data to a Timegraph with it's time set to Gun.state()'s time */
|
||||
time?<K extends keyof CurrentTreeDataType>(data: CurrentTreeDataType[K]): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance<CurrentTreeDataType[K], string>: IGunFinalTreeMethods<CurrentTreeDataType[K], K, string>;
|
||||
|
||||
|
||||
/**
|
||||
* @param publicKey If you know a users publicKey you can get their user graph and see any unencrypted data they may have stored there.
|
||||
*/
|
||||
user<TUserGraph extends IGunDataType>(): IGunUserInstance<TUserGraph, undefined>
|
||||
user(publicKey: string): IGunUserInstance<CurrentTreeDataType, undefined>
|
||||
}
|
||||
export interface IGunInstance<TNode extends Record<string, GunSchema> = any>
|
||||
extends IGunInstanceRoot<TNode, IGunInstance<TNode>> {}
|
||||
|
71
types/gun/IGunInstanceHookHandler.d.ts
vendored
Normal file
71
types/gun/IGunInstanceHookHandler.d.ts
vendored
Normal file
@ -0,0 +1,71 @@
|
||||
import {
|
||||
GunHookCallbackCreate,
|
||||
GunHookCallbackPut,
|
||||
pany,
|
||||
GunHookCallackGet,
|
||||
GunHookCallbackOut,
|
||||
GunHookCallbackIn,
|
||||
GunHookCallbackBye,
|
||||
IGunHookContext,
|
||||
} from '.';
|
||||
|
||||
export interface IGunInstanceHookHandler {
|
||||
/**
|
||||
* Listener for the GUN instance creation
|
||||
*/
|
||||
on(event: 'create', callback: GunHookCallbackCreate): void;
|
||||
|
||||
/**
|
||||
* Listener for the GUN `put` event
|
||||
*/
|
||||
on(event: 'put', callback: GunHookCallbackPut): void;
|
||||
|
||||
/**
|
||||
* Listener for the GUN `get` event
|
||||
*
|
||||
* @template MessageExtension extension properties for message
|
||||
*/
|
||||
on<MessageExtension extends pany = pany>(
|
||||
event: 'get',
|
||||
callback: GunHookCallackGet<MessageExtension>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Listener for the GUN `out` event
|
||||
*
|
||||
* > NEVER PASS ARROW FUNCTIONS AS A CALLBACK OR YOU LOSE `this` CONTEXT!
|
||||
*
|
||||
* > NEVER FORGET TO CALL `this.to.next(message);` IF YOU WANT YOUR MESSAGE TO PASS
|
||||
*
|
||||
* @template MessageExtension extension properties for message
|
||||
* @template MetaExtension extension properties for meta data
|
||||
*/
|
||||
on<MessageExtension extends pany = pany, MetaExtension extends pany = pany>(
|
||||
event: 'out',
|
||||
callback: GunHookCallbackOut<MessageExtension, MetaExtension>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Listener for the GUN `in` event
|
||||
*
|
||||
* @template MessageExtension extension properties for message
|
||||
* @template MetaExtension extension properties for meta data
|
||||
*/
|
||||
on<MessageExtension extends pany = pany, MetaExtension extends pany = pany>(
|
||||
event: 'in',
|
||||
callback: GunHookCallbackIn<MessageExtension, MetaExtension>
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Listener for new peers
|
||||
*/
|
||||
on(
|
||||
event: 'hi',
|
||||
callback: (this: IGunHookContext<any>, peer: any) => void
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Listener for leaving peers
|
||||
*/
|
||||
on(event: 'bye', callback: GunHookCallbackBye): void;
|
||||
}
|
94
types/gun/IGunInstanceRoot.d.ts
vendored
Normal file
94
types/gun/IGunInstanceRoot.d.ts
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
import {
|
||||
_GunRoot,
|
||||
GunCallbackPut,
|
||||
GunOptionsPut,
|
||||
IGunChain,
|
||||
LEXQuery,
|
||||
GunOptions,
|
||||
IGunInstanceHookHandler,
|
||||
GunSchema,
|
||||
GunCallbackGet,
|
||||
GunSoul,
|
||||
} from '.';
|
||||
import { GunSoul2Soul, GunSoul2TNode } from '../utils';
|
||||
|
||||
export interface IGunInstanceRoot<
|
||||
TNode extends Record<string, GunSchema>,
|
||||
TGunInstance extends IGunInstanceRoot<TNode, any>
|
||||
> extends IGunInstanceHookHandler {
|
||||
_: _GunRoot;
|
||||
|
||||
/**
|
||||
* Save data into gun, syncing it with your connected peers
|
||||
*
|
||||
* @param value the data to save
|
||||
* @param callback an optional callback, invoked on each acknowledgment
|
||||
* @param options `put` options
|
||||
* @param options.cert certificate that gives other people write permission
|
||||
*/
|
||||
put<V extends Partial<TNode> & Record<string, GunSchema>>(
|
||||
value: V,
|
||||
callback?: GunCallbackPut,
|
||||
options?: GunOptionsPut
|
||||
): TGunInstance;
|
||||
|
||||
/**
|
||||
* Where to read data from
|
||||
*
|
||||
* @param soul The soul of an object that you saved from earlier
|
||||
* @param callback The callback is a listener for read errors, not found, and updates.
|
||||
* It may be called multiple times for a single request, since gun uses a reactive
|
||||
* streaming architecture. Generally, you'll find `.not`, `.on`, and `.once` as more
|
||||
* convenient for every day use
|
||||
*/
|
||||
get<
|
||||
V extends GunSoul2TNode<S>,
|
||||
S extends GunSoul<GunSchema>,
|
||||
N extends TNode
|
||||
>(
|
||||
soul: S,
|
||||
callback?: GunCallbackGet<N, GunSoul2Soul<S>>
|
||||
): IGunChain<V, TGunInstance, TGunInstance, GunSoul2Soul<S>>;
|
||||
|
||||
/**
|
||||
* Where to read data from
|
||||
*
|
||||
* @param key The key is the ID or property name of the data that you saved from
|
||||
* earlier (or that will be saved later)
|
||||
* @param callback The callback is a listener for read errors, not found, and updates.
|
||||
* It may be called multiple times for a single request, since gun uses a reactive
|
||||
* streaming architecture. Generally, you'll find `.not`, `.on`, and `.once` as more
|
||||
* convenient for every day use
|
||||
*/
|
||||
get<
|
||||
V extends N[K],
|
||||
K extends keyof N & string = keyof TNode & string,
|
||||
N extends TNode = TNode
|
||||
>(
|
||||
key: K,
|
||||
callback?: GunCallbackGet<N, K>
|
||||
): IGunChain<V, TGunInstance, TGunInstance, K>;
|
||||
|
||||
/**
|
||||
* Where to read data from
|
||||
*
|
||||
* @param query LEX query
|
||||
* @param callback The callback is a listener for read errors, not found, and updates.
|
||||
* It may be called multiple times for a single request, since gun uses a reactive
|
||||
* streaming architecture. Generally, you'll find `.not`, `.on`, and `.once` as more
|
||||
* convenient for every day use
|
||||
*/
|
||||
get<V extends N[K], K extends keyof N & string, N extends TNode = TNode>(
|
||||
query: LEXQuery<K>,
|
||||
callback?: GunCallbackGet<N, K>
|
||||
): IGunChain<V, TGunInstance, TGunInstance, K>;
|
||||
|
||||
/**
|
||||
* Change the configuration of the gun database instance
|
||||
*
|
||||
* @param options The options argument is the same object you pass to the constructor.
|
||||
* The options's properties replace those in the instance's configuration but
|
||||
* `options.peers` are added to peers known to the gun instance
|
||||
*/
|
||||
opt(options: GunOptions): void;
|
||||
}
|
8
types/gun/IGunMeta.d.ts
vendored
Normal file
8
types/gun/IGunMeta.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
export interface IGunMeta<T extends object> {
|
||||
_: {
|
||||
'#': string;
|
||||
'>': {
|
||||
[key in keyof T]: number;
|
||||
};
|
||||
};
|
||||
}
|
3
types/gun/IGunOnEvent.d.ts
vendored
Normal file
3
types/gun/IGunOnEvent.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export interface IGunOnEvent {
|
||||
off(): void;
|
||||
}
|
6
types/gun/IGunReturnObject.d.ts
vendored
6
types/gun/IGunReturnObject.d.ts
vendored
@ -1,6 +0,0 @@
|
||||
export declare type IGunReturnObject<TObject, TSoul> = (TObject & {
|
||||
_:{
|
||||
'#': TSoul,
|
||||
'>': TObject extends number |string|boolean?unknown : Record<keyof TObject, number>
|
||||
}
|
||||
})|undefined
|
10
types/gun/IGunTree.d.ts
vendored
10
types/gun/IGunTree.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
export interface IGunTree{
|
||||
"+"?:string|IGunTree,
|
||||
"#"?:string|IGunTree,
|
||||
"."?:string|IGunTree,
|
||||
"="?:string|IGunTree,
|
||||
"*"?:string|IGunTree,
|
||||
">"?:string|IGunTree,
|
||||
"<"?:string|IGunTree,
|
||||
'-'?:string|number|IGunTree
|
||||
}
|
232
types/gun/IGunUserInstance.d.ts
vendored
232
types/gun/IGunUserInstance.d.ts
vendored
@ -1,232 +0,0 @@
|
||||
import { ISEAPair } from "../sea/ISEAPair";
|
||||
import { And } from "../shared/And";
|
||||
import { AckCallback } from "./AckCallback";
|
||||
import { AuthCallback } from "./AuthCallback";
|
||||
import { CreateCallback } from "./CreateCallback";
|
||||
import { IGunConstructorOptions } from "./IGunConstructorOptions";
|
||||
import { IGunDataType, IGunNodeDataType } from "./IGunDataType";
|
||||
import { IGunFinalUserTreeMethods } from "./IGunFinalUserTreeMethods";
|
||||
import { IGunReturnObject } from "./IGunReturnObject";
|
||||
import { IGunTree } from "./IGunTree";
|
||||
|
||||
export interface IGunUserInstance<CurrentDataType extends IGunNodeDataType, TKey extends string | undefined> {
|
||||
/**
|
||||
* check out https://gun.eco/docs/User#user-secret
|
||||
* save secret that only trusted users can read
|
||||
*
|
||||
*/
|
||||
not?(callback: (key: TKey) => void): IGunUserInstance<CurrentDataType, TKey> ;
|
||||
/**
|
||||
* Say you save some data, but want to do something with it later, like expire it or refresh it.
|
||||
* Well, then `later` is for you! You could use this to easily implement a TTL or similar behavior.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/later.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/later.js"></script>`!
|
||||
*/
|
||||
later?(callback: (data: CurrentDataType, key: TKey) => void, seconds: number): IGunUserInstance<CurrentDataType, TKey> ;
|
||||
off(): IGunUserInstance<CurrentDataType, TKey> ;
|
||||
/* /**
|
||||
* Save data into gun, syncing it with your connected peers.
|
||||
*
|
||||
* * You cannot save primitive values at the root level.
|
||||
*
|
||||
* @param data You do not need to re-save the entire object every time,
|
||||
* gun will automatically merge your data into what already exists as a "partial" update.
|
||||
*
|
||||
* * `undefined`, `NaN`, `Infinity`, `array`, will be rejected.
|
||||
* * Traditional arrays are dangerous in real-time apps. Use `gun.set` instead.
|
||||
*
|
||||
* @param callback invoked on each acknowledgment
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
put(data: Partial<CurrentDataType>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }):IGunUserInstance<CurrentDataType, TKey>
|
||||
|
||||
/**
|
||||
* Subscribe to updates and changes on a node or property in real-time.
|
||||
* @param option Currently, the only option is to filter out old data, and just be given the changes.
|
||||
* If you're listening to a node with 100 fields, and just one changes,
|
||||
* you'll instead be passed a node with a single property representing that change rather than the full node every time.
|
||||
* @param callback
|
||||
* Once initially and whenever the property or node you're focused on changes, this callback is immediately fired with the data as it is at that point in time.
|
||||
*
|
||||
* Since gun streams data, the callback will probably be called multiple times as new chunks come in.
|
||||
* To remove a listener call .off() on the same property or node.
|
||||
*/
|
||||
on(callback: (data: IGunReturnObject<CurrentDataType, TKey>, key: TKey, _msg:any, _ev:any) => void, option?: {
|
||||
change: boolean;
|
||||
} | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunUserInstance<CurrentDataType, TKey> | Promise<IGunReturnObject<CurrentDataType, TKey>>;
|
||||
|
||||
/**
|
||||
* Subscribe to database event.
|
||||
* @param eventName event name that you want listen to (currently only 'auth')
|
||||
* @param callback once event fire callback
|
||||
*/
|
||||
on(eventName: 'auth', cb: AuthCallback, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any):IGunUserInstance<CurrentDataType, TKey>
|
||||
|
||||
/**
|
||||
* Get the current data without subscribing to updates. Or `undefined` if it cannot be found.
|
||||
* @returns In the document, it said the return value may change in the future. Don't rely on it.
|
||||
*/
|
||||
once(callback?: (data: IGunReturnObject<CurrentDataType, TKey>, key: TKey) => void, option?: {
|
||||
wait: number;
|
||||
}): IGunUserInstance<CurrentDataType, TKey> | Promise<IGunReturnObject<CurrentDataType, TKey>>;
|
||||
|
||||
/**
|
||||
* Open behaves very similarly to gun.on, except it gives you the **full depth of a document** on every update.
|
||||
* It also works with graphs, tables, or other data structures. Think of it as opening up a live connection to a document.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/open.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/open.js"></script>`!
|
||||
*/
|
||||
open?(callback: (data: IGunReturnObject<CurrentDataType, TKey>) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<CurrentDataType>): IGunUserInstance<CurrentDataType, TKey> | Promise<IGunReturnObject<CurrentDataType, TKey>>;
|
||||
|
||||
/**
|
||||
* Loads the full object once. It is the same as `open` but with the behavior of `once`.
|
||||
*
|
||||
* **Warning**: Not included by default! You must include it yourself via `require('gun/lib/load.js')` or
|
||||
* `<script src="https://cdn.jsdelivr.net/npm/gun/lib/load.js"></script>`!
|
||||
*/
|
||||
load?(callback: (data: IGunReturnObject<CurrentDataType, TKey>) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial<CurrentDataType>): IGunUserInstance<CurrentDataType, TKey> | Promise<IGunReturnObject<CurrentDataType, TKey>>
|
||||
|
||||
|
||||
/**goes back user chain */
|
||||
back(amount?:number) : IGunUserInstance<CurrentDataType, string>
|
||||
secret(string: string, callback : (...args:unknown[])=> any): IGunUserInstance<CurrentDataType, TKey>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
is?: {
|
||||
alias: string | ISEAPair
|
||||
epub: string
|
||||
pub: string
|
||||
}
|
||||
/**
|
||||
* Creates a new user and calls callback upon completion.
|
||||
* @param alias Username or Alias which can be used to find a user.
|
||||
* @param pass Passphrase that will be extended with PBKDF2 to make it a secure way to login.
|
||||
* @param cb Callback that is to be called upon creation of the user.
|
||||
* @param opt Option Object containing options for creation. (In gun options are added at end of syntax. opt is rarely used, hence is added at the end.)
|
||||
*/
|
||||
create(alias: string, pass: string, cb?: CreateCallback, opt?: {}): unknown;
|
||||
|
||||
/**
|
||||
* Creates a new user and calls callback upon completion.
|
||||
* @param pair User cryptographic pair
|
||||
* @param cb Callback that is to be called upon creation of the user.
|
||||
* @param opt Option Object containing options for creation. (In gun options are added at end of syntax. opt is rarely used, hence is added at the end.)
|
||||
*/
|
||||
create(pair: ISEAPair, cb?: AuthCallback, opt?: {}): unknown;
|
||||
|
||||
/**
|
||||
* Authenticates a user, previously created via User.create.
|
||||
* @param alias Username or Alias which can be used to find a user.
|
||||
* @param pass Passphrase for the user
|
||||
* @param cb Callback that is to be called upon authentication of the user.
|
||||
* @param opt Option Object containing options for authentication. (In gun options are added at end of syntax. opt is rarely used, hence is added at the end.)
|
||||
*/
|
||||
auth(alias: string, pass: string, cb?:AuthCallback, opt?: {}): unknown
|
||||
|
||||
/**
|
||||
* Authenticates a user, previously created via User.create.
|
||||
* @param pair Public/Private Key Pair
|
||||
* @param cb Callback that is to be called upon authentication of the user.
|
||||
* @param opt Option Object containing options for authentication. (In gun options are added at end of syntax. opt is rarely used, hence is added at the end.)
|
||||
*/
|
||||
auth(pair: ISEAPair, cb?: AuthCallback, opt?: {}): unknown;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Log out currently authenticated user. Parameters are unused in the current implementation.
|
||||
* @param opt unused in current implementation.
|
||||
* @param cb unused in current implementation.
|
||||
*/
|
||||
leave(opt?: never, cb?: never): unknown;
|
||||
|
||||
/**
|
||||
* Deletes a user from the current gun instance and propagates the delete to other peers.
|
||||
* @param alias Username or alias.
|
||||
* @param pass Passphrase for the user.
|
||||
* @param cb Callback that is called when the user was successfully deleted.
|
||||
*/
|
||||
delete(alias: string, pass: string, cb?: (ack: {
|
||||
ok: 0;
|
||||
}) => void): Promise<void>;
|
||||
|
||||
|
||||
/**
|
||||
* Where to read data from.
|
||||
* @param key The key is the ID or property name of the data that you saved from earlier
|
||||
* (or that will be saved later).
|
||||
* * Note that if you use .put at any depth after a get it first reads the data and then writes, merging the data as a partial update.
|
||||
* @param callback You will usually be using gun.on or gun.once to actually retrieve your data,
|
||||
* not this callback (it is intended for more low-level control, for module and extensions).
|
||||
*
|
||||
* **Avoid use callback. The type in the document may be wrong.**
|
||||
*
|
||||
* **Here the type of callback respect to the actual behavior**
|
||||
*/
|
||||
get<K extends keyof CurrentDataType>(key: K, callback?: (
|
||||
data: IGunReturnObject<CurrentDataType[K], string>,
|
||||
key: K) => any):
|
||||
And< Promise<CurrentDataType[K]>,
|
||||
CurrentDataType[K] extends IGunDataType ?
|
||||
IGunUserInstance<CurrentDataType[K], string> & IGunFinalUserTreeMethods<CurrentDataType[K], K, string> :
|
||||
IGunDataType extends CurrentDataType[K] ?
|
||||
IGunFinalUserTreeMethods<CurrentDataType[K], K, string> & IGunUserInstance< IGunDataType , string>
|
||||
: IGunFinalUserTreeMethods<CurrentDataType[K], K, string>>
|
||||
|
||||
/**
|
||||
* **.set does not mean 'set data', it means a Mathematical Set**
|
||||
*
|
||||
* Add a unique item to an unordered list.
|
||||
* `gun.set` works like a mathematical set, where each item in the list is unique.
|
||||
* If the item is added twice, it will be merged.
|
||||
*
|
||||
* **This means only objects, for now, are supported.**
|
||||
* @param data the object to add to the set
|
||||
* @param callback optional function to invoke when the operation is complete
|
||||
* @param options additional options (used for specifying certs)
|
||||
*/
|
||||
set<K extends keyof CurrentDataType>(data: CurrentDataType[K], callback?: AckCallback | null, options?: { opt?: { cert?: string } }): CurrentDataType[K] extends IGunDataType? IGunUserInstance<CurrentDataType[K], string>: IGunFinalUserTreeMethods<CurrentDataType[K], K, string> ;
|
||||
|
||||
|
||||
opt(opt: IGunConstructorOptions): unknown
|
||||
|
||||
/**
|
||||
* Recall saves a users credentials in sessionStorage of the browser. As long as the tab of your app is not closed the user stays logged in, even through page refreshes and reloads.
|
||||
* @param opt option object If you want to use browser sessionStorage to allow users to stay logged in as long as the session is open, set opt.sessionStorage to true
|
||||
* @param cb internally the callback is passed on to the user.auth function to log the user back in. Refer to user.auth for callback documentation.
|
||||
*/
|
||||
recall(opt?: {
|
||||
sessionStorage: boolean;
|
||||
}, cb?: AuthCallback): IGunUserInstance<CurrentDataType, TKey>;
|
||||
|
||||
map(match: IGunTree ): CurrentDataType[keyof CurrentDataType] extends IGunDataType? IGunUserInstance<CurrentDataType[keyof CurrentDataType], string> : IGunFinalUserTreeMethods<CurrentDataType[keyof CurrentDataType], keyof CurrentDataType, string>
|
||||
|
||||
|
||||
map<T>(match: (data: CurrentDataType) => T ): IGunFinalUserTreeMethods<T, keyof CurrentDataType, string>
|
||||
/**
|
||||
* Subscribes to all future events that occur on the Timegraph and retrieve a specified number of old events
|
||||
*
|
||||
* **Warning**: The Timegraph extension isn't required by default, you would need to include at "gun/lib/time.js"
|
||||
*/
|
||||
time?<K extends keyof CurrentDataType>(callback: (data: CurrentDataType[K], key: K, time: number) => void, alsoReceiveNOldEvents?: number): CurrentDataType[K] extends IGunDataType ? IGunUserInstance<CurrentDataType[K], string>: IGunFinalUserTreeMethods<CurrentDataType[K], K, string>;
|
||||
|
||||
/** Pushes data to a Timegraph with it's time set to Gun.state()'s time */
|
||||
time?<K extends keyof CurrentDataType>(data: CurrentDataType[K]): CurrentDataType[K] extends IGunDataType ? IGunUserInstance<CurrentDataType[K], string>: IGunFinalUserTreeMethods<CurrentDataType[K], K, string>;
|
||||
|
||||
|
||||
/**
|
||||
* @param publicKey If you know a users publicKey you can get their user graph and see any unencrypted data they may have stored there.
|
||||
*/
|
||||
user<TUserGraph extends IGunDataType>(): IGunUserInstance<TUserGraph, undefined>
|
||||
user(publicKey: string): IGunUserInstance<CurrentDataType, undefined>
|
||||
|
||||
|
||||
}
|
12
types/gun/LEX.d.ts
vendored
Normal file
12
types/gun/LEX.d.ts
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
export type LEX<T extends string = string> = {
|
||||
/** exact match */
|
||||
'='?: T;
|
||||
/** prefix match */
|
||||
'*'?: string;
|
||||
/** gte match */
|
||||
'>'?: string;
|
||||
/** lte match */
|
||||
'<'?: string;
|
||||
/** 1 for reverse */
|
||||
'-'?: number;
|
||||
};
|
3
types/gun/LEXQuery.d.ts
vendored
Normal file
3
types/gun/LEXQuery.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { LEX } from '.';
|
||||
|
||||
export type LEXQuery<T extends string = string> = { '.': LEX<T>; ':'?: number };
|
10
types/gun/_GunRoot.d.ts
vendored
Normal file
10
types/gun/_GunRoot.d.ts
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
import { GunOptions, IGunInstanceHookHandler } from '.';
|
||||
|
||||
export interface _GunRoot extends IGunInstanceHookHandler {
|
||||
$: { _: _GunRoot };
|
||||
|
||||
/**
|
||||
* Current GUN options
|
||||
*/
|
||||
opt: GunOptions;
|
||||
}
|
36
types/gun/index.d.ts
vendored
Normal file
36
types/gun/index.d.ts
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
export * from './_GunRoot';
|
||||
export * from './GunCallbackGet';
|
||||
export * from './GunCallbackMap';
|
||||
export * from './GunCallbackOn';
|
||||
export * from './GunCallbackOnce';
|
||||
export * from './GunCallbackPut';
|
||||
export * from './GunDataNode';
|
||||
export * from './GunHookCallbackBye';
|
||||
export * from './GunHookCallbackCreate';
|
||||
export * from './GunHookCallbackGet';
|
||||
export * from './GunHookCallbackHi';
|
||||
export * from './GunHookCallbackIn';
|
||||
export * from './GunHookCallbackOpt';
|
||||
export * from './GunHookCallbackOut';
|
||||
export * from './GunHookCallbackPut';
|
||||
export * from './GunNodeGet';
|
||||
export * from './GunNodePut';
|
||||
export * from './GunOptions';
|
||||
export * from './GunOptionsOn';
|
||||
export * from './GunOptionsOnce';
|
||||
export * from './GunOptionsPut';
|
||||
export * from './GunPeer';
|
||||
export * from './GunSoul';
|
||||
export * from './GunValueSimple';
|
||||
export * from './IGun';
|
||||
export * from './IGunChain';
|
||||
export * from './IGunHookContext';
|
||||
export * from './IGunInstance';
|
||||
export * from './IGunInstanceHookHandler';
|
||||
export * from './IGunInstanceRoot';
|
||||
export * from './IGunMeta';
|
||||
export * from './IGunOnEvent';
|
||||
export * from './GunSchema';
|
||||
export * from './LEX';
|
||||
export * from './LEXQuery';
|
||||
export * from './pany';
|
1
types/gun/pany.d.ts
vendored
Normal file
1
types/gun/pany.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type pany = Partial<any>;
|
2
types/index.d.ts
vendored
Normal file
2
types/index.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './gun';
|
||||
export * from './sea';
|
15
types/sea/GunCallbackUserAuth.d.ts
vendored
Normal file
15
types/sea/GunCallbackUserAuth.d.ts
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
import { GunUser, ISEAPair } from '..';
|
||||
|
||||
export type GunCallbackUserAuth = (
|
||||
ack:
|
||||
| {
|
||||
ack: 2;
|
||||
/** ~publicKeyOfUser */
|
||||
soul: string;
|
||||
/** ~publicKeyOfUser */
|
||||
get: string;
|
||||
put: GunUser;
|
||||
sea: ISEAPair;
|
||||
}
|
||||
| { err: string }
|
||||
) => void;
|
3
types/sea/GunCallbackUserCreate.d.ts
vendored
Normal file
3
types/sea/GunCallbackUserCreate.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
export type GunCallbackUserCreate = (
|
||||
ack: { ok: 0; pub: string } | { err: string }
|
||||
) => void;
|
7
types/sea/GunHookCallbackAuth.d.ts
vendored
Normal file
7
types/sea/GunHookCallbackAuth.d.ts
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
import { GunHookMessagePut, GunUser, IGunOnEvent } from '..';
|
||||
|
||||
export type GunHookCallbackAuth = (
|
||||
user: GunUser,
|
||||
message: GunHookMessagePut,
|
||||
event: IGunOnEvent
|
||||
) => void;
|
9
types/sea/GunUser.d.ts
vendored
Normal file
9
types/sea/GunUser.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
export type GunUser = {
|
||||
/** Username or Alias which can be used to find a user */
|
||||
alias: string;
|
||||
// auth: string;
|
||||
/** public key for encryption */
|
||||
epub: string;
|
||||
/** public key */
|
||||
pub: string;
|
||||
};
|
8
types/sea/IGun.d.ts
vendored
Normal file
8
types/sea/IGun.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { ISEA } from '.';
|
||||
|
||||
import {} from '../gun/IGun';
|
||||
declare module '../gun/IGun' {
|
||||
export interface IGun {
|
||||
SEA: ISEA;
|
||||
}
|
||||
}
|
27
types/sea/IGunInstance.d.ts
vendored
Normal file
27
types/sea/IGunInstance.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
import { IGunInstanceRoot, GunSchema, IGunUserInstance } from '..';
|
||||
|
||||
import {} from '../gun/IGunInstance';
|
||||
declare module '../gun/IGunInstance' {
|
||||
export interface IGunInstance<TNode> {
|
||||
user<
|
||||
UNode extends Record<string, GunSchema> = any,
|
||||
UNodeInstance extends IGunUserInstance<
|
||||
UNode,
|
||||
UNodeInstance,
|
||||
TNode,
|
||||
IGunInstanceRoot<TNode, IGunInstance<TNode>>
|
||||
> = any
|
||||
>(): IGunUserInstance<UNode, UNodeInstance, TNode, IGunInstanceRoot<TNode, IGunInstance<TNode>>>;
|
||||
user<
|
||||
UNode extends Record<string, GunSchema> = any,
|
||||
UNodeInstance extends IGunUserInstance<
|
||||
UNode,
|
||||
UNodeInstance,
|
||||
TNode,
|
||||
IGunInstanceRoot<TNode, IGunInstance<TNode>>
|
||||
> = any
|
||||
>(
|
||||
publicKey: string
|
||||
): IGunUserInstance<UNode, UNodeInstance, TNode, IGunInstanceRoot<TNode, IGunInstance<TNode>>>;
|
||||
}
|
||||
}
|
9
types/sea/IGunInstanceHookHandler.d.ts
vendored
Normal file
9
types/sea/IGunInstanceHookHandler.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
import { GunHookCallbackAuth } from '..';
|
||||
|
||||
import {} from '../gun/IGunInstanceHookHandler';
|
||||
declare module '../gun/IGunInstanceHookHandler' {
|
||||
export interface IGunInstanceHookHandler {
|
||||
/** Called upon successful user authentication */
|
||||
on(event: 'auth', callback: GunHookCallbackAuth): void;
|
||||
}
|
||||
}
|
27
types/sea/IGunInstanceRoot.d.ts
vendored
Normal file
27
types/sea/IGunInstanceRoot.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
import { GunSchema, IGunUserInstance } from '..';
|
||||
|
||||
import {} from '../gun/IGunInstanceRoot';
|
||||
declare module '../gun/IGunInstanceRoot' {
|
||||
export interface IGunInstanceRoot<TNode, TGunInstance> {
|
||||
user<
|
||||
UNode extends Record<string, GunSchema> = any,
|
||||
UNodeInstance extends IGunUserInstance<
|
||||
UNode,
|
||||
UNodeInstance,
|
||||
TNode,
|
||||
TGunInstance
|
||||
> = any
|
||||
>(): IGunUserInstance<UNode, UNodeInstance, TNode, TGunInstance>;
|
||||
user<
|
||||
UNode extends Record<string, GunSchema> = any,
|
||||
UNodeInstance extends IGunUserInstance<
|
||||
UNode,
|
||||
UNodeInstance,
|
||||
TNode,
|
||||
TGunInstance
|
||||
> = any
|
||||
>(
|
||||
publicKey: string
|
||||
): IGunUserInstance<UNode, UNodeInstance, TNode, TGunInstance>;
|
||||
}
|
||||
}
|
80
types/sea/IGunUserInstance.d.ts
vendored
Normal file
80
types/sea/IGunUserInstance.d.ts
vendored
Normal file
@ -0,0 +1,80 @@
|
||||
import {
|
||||
GunCallbackUserAuth,
|
||||
GunCallbackUserCreate,
|
||||
OptionsUserAuth,
|
||||
ISEAPair,
|
||||
OptionsUserRecall,
|
||||
IGunInstanceRoot,
|
||||
GunSchema,
|
||||
} from '..';
|
||||
import { IGunInstanceRoot2TGunInstance } from '../utils';
|
||||
|
||||
export interface IGunUserInstance<
|
||||
UNode extends Record<string, GunSchema> = any,
|
||||
UNodeInstance extends IGunUserInstance<
|
||||
UNode,
|
||||
UNodeInstance,
|
||||
TNode,
|
||||
TNodeInstanceRoot
|
||||
> = any,
|
||||
TNode extends Record<string, GunSchema> = any,
|
||||
TNodeInstanceRoot extends IGunInstanceRoot<TNode, any> = any
|
||||
> extends IGunInstanceRoot<UNode, UNodeInstance> {
|
||||
/** Creates a new user and calls callback upon completion
|
||||
* @param alias Username or Alias which can be used to find a user
|
||||
* @param password Passphrase that will be extended with PBKDF2
|
||||
* to make it a secure way to login
|
||||
* @param callback that is to be called upon creation of the user
|
||||
*/
|
||||
create(
|
||||
alias: string,
|
||||
password: string,
|
||||
callback: GunCallbackUserCreate
|
||||
): UNodeInstance;
|
||||
|
||||
/** Authenticates a user, previously created via User.create
|
||||
* @param pair Object containing the key pair of the user
|
||||
* @param callback that is to be called upon authentication of the user
|
||||
* @param options Options for authentication
|
||||
*/
|
||||
auth(
|
||||
pair: ISEAPair,
|
||||
callback?: GunCallbackUserAuth,
|
||||
options?: OptionsUserAuth
|
||||
): UNodeInstance;
|
||||
/** Authenticates a user, previously created via User.create
|
||||
* @param alias Username or Alias which can be used to find a user
|
||||
* @param password Passphrase for the user
|
||||
* @param callback that is to be called upon authentication of the user
|
||||
* @param options Options for authentication
|
||||
*/
|
||||
auth(
|
||||
alias: string,
|
||||
password: string,
|
||||
callback?: GunCallbackUserAuth,
|
||||
options?: OptionsUserAuth
|
||||
): UNodeInstance;
|
||||
|
||||
/** To check if you are currently logged in */
|
||||
is?: {
|
||||
alias: string | ISEAPair;
|
||||
/** public key for encryption */
|
||||
epub: string;
|
||||
/** public key */
|
||||
pub: string;
|
||||
};
|
||||
|
||||
/** Log out currently authenticated user
|
||||
* @returns A reference to the gun root chain
|
||||
*/
|
||||
leave(): IGunInstanceRoot2TGunInstance<TNodeInstanceRoot>;
|
||||
|
||||
/**
|
||||
* Saves a users credentials in sessionStorage of the browser.
|
||||
* As long as the tab of your app is not closed the user stays
|
||||
* logged in, even through page refreshes and reloads */
|
||||
recall(
|
||||
options: OptionsUserRecall,
|
||||
callback?: GunCallbackUserAuth
|
||||
): UNodeInstance;
|
||||
}
|
13
types/sea/IPolicy.d.ts
vendored
Normal file
13
types/sea/IPolicy.d.ts
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
import { LEX } from '..';
|
||||
|
||||
export interface IPolicy extends LEX {
|
||||
/** Path */
|
||||
'#'?: LEX;
|
||||
/** Key */
|
||||
'.'?: LEX;
|
||||
/**
|
||||
* Either Path string or Key string must
|
||||
* contain Certificate's Pub string
|
||||
*/
|
||||
'+'?: '*';
|
||||
}
|
233
types/sea/ISEA.d.ts
vendored
233
types/sea/ISEA.d.ts
vendored
@ -1,84 +1,163 @@
|
||||
import { ISEAPair } from "./ISEAPair";
|
||||
import { ISEAPolicy } from "./ISEAPolicy";
|
||||
/** @see https://gun.eco/docs/SEA */
|
||||
import { ISEAPair, Policy } from '.';
|
||||
|
||||
/**
|
||||
* Security, Encryption, and Authorization system used with GUN
|
||||
*/
|
||||
export interface ISEA {
|
||||
/** Last known error */
|
||||
err?: string;
|
||||
|
||||
/** If you want SEA to throw while in development, turn SEA.throw = true on, but please do not use this in production. */
|
||||
throw?: boolean;
|
||||
/**
|
||||
* This gives you a Proof of Work (POW) / Hashing of Data
|
||||
*
|
||||
* @param data The data to be hashed, work to be performed on
|
||||
* @param pair (salt) You can pass pair of keys to use as salt.
|
||||
* Salt will prevent others to pre-compute the work, so using
|
||||
* your public key is not a good idea. If it is not specified, it
|
||||
* will be random, which ruins your chance of ever being able to
|
||||
* re-derive the work deterministically
|
||||
* @param callback function to executed upon execution of proof
|
||||
* @param options default: `{ name: 'PBKDF2', encode: 'base64' }`
|
||||
* @returns a promise with a string - hash of data if successful,
|
||||
* otherwise - undefined
|
||||
*/
|
||||
work(
|
||||
data: any,
|
||||
pair?: ISEAPair | null,
|
||||
callback?: ((data: string | undefined) => void) | null,
|
||||
options?: {
|
||||
name?: 'SHA-256' | 'PBKDF2';
|
||||
encode?: 'base64' | 'utf8' | 'hex';
|
||||
salt?: any;
|
||||
hash?: string;
|
||||
length?: number;
|
||||
}
|
||||
): Promise<string | undefined>;
|
||||
|
||||
/** Last known error */
|
||||
err?: string;
|
||||
/**
|
||||
* This generates a cryptographically secure public/private key pair - be careful not to leak the private keys!
|
||||
* Note: API subject to change we may change the parameters to accept data and work, in addition to generation.
|
||||
* You will need this for most of SEA's API, see those method's examples.
|
||||
* The default cryptographic primitives for the asymmetric keys are ECDSA for signing and ECDH for encryption.
|
||||
*/
|
||||
pair(callback?: (data: ISEAPair) => void): Promise<ISEAPair>;
|
||||
|
||||
/**
|
||||
* This gives you a Proof of Work (POW) / Hashing of Data
|
||||
* @param data The data to be hashed, work to be performed on.
|
||||
* @param pair (salt) You can pass pair of keys to use as salt. Salt will prevent others to pre-compute the work,
|
||||
* so using your public key is not a good idea. If it is not specified, it will be random,
|
||||
* which ruins your chance of ever being able to re-derive the work deterministically
|
||||
* @param callback function to executed upon execution of proof
|
||||
* @param opt default: {name: 'PBKDF2', encode: 'base64'}
|
||||
*/
|
||||
work(data: any, pair?: any, callback?: (data: string | undefined) => void, opt?: Partial<{
|
||||
name: 'SHA-256' | 'PBKDF2';
|
||||
encode: 'base64' | 'base32' | 'base16';
|
||||
/** iterations to use on subtle.deriveBits */
|
||||
iterations: number;
|
||||
salt: any;
|
||||
hash: string;
|
||||
length: any;
|
||||
}>): Promise<string | undefined>;
|
||||
|
||||
/**
|
||||
* This generates a cryptographically secure public/private key pair - be careful not to leak the private keys!
|
||||
* Note: API subject to change we may change the parameters to accept data and work, in addition to generation.
|
||||
* You will need this for most of SEA's API, see those method's examples.
|
||||
* The default cryptographic primitives for the asymmetric keys are ECDSA for signing and ECDH for encryption.
|
||||
*/
|
||||
pair(cb?: (data: ISEAPair) => void, opt?: {}): Promise<ISEAPair | undefined>;
|
||||
|
||||
/**
|
||||
* Adds a signature to a message, for data that you want to prevent attackers tampering with.
|
||||
* @param data is the content that you want to prove is authorized.
|
||||
* @param pair is from .pair.
|
||||
*/
|
||||
sign(data: any, pair: { pub: string; priv: string }): Promise<string | undefined>;
|
||||
|
||||
/**
|
||||
* Gets the data if and only if the message can be verified as coming from the person you expect.
|
||||
* @param message is what comes from .sign.
|
||||
* @param pair from .pair or its public key text (pair.pub).
|
||||
*/
|
||||
verify<TMessage = unknown>(message: string, pair: { pub: string } | string): Promise<TMessage | undefined>;
|
||||
|
||||
/**
|
||||
* Takes some data that you want to keep secret and encrypts it so nobody else can read it.
|
||||
* @param data is the content that you want to encrypt.
|
||||
* @param pair from .pair or a passphrase you want to use as a cypher to encrypt with.
|
||||
*/
|
||||
encrypt(data: any, pair: { epriv: string } | string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Read the secret data, if and only if you are allowed to.
|
||||
* @param message is what comes from .encrypt.
|
||||
* @param pair from .pair or the passphrase to decypher the message.
|
||||
*/
|
||||
decrypt<TMessage=unknown>(message: any, pair: { epriv: string } | string): Promise<TMessage|undefined>;
|
||||
|
||||
/**
|
||||
* determine secret between users.
|
||||
* @param key public key of first user.
|
||||
* @param pair from .pair or the passphrase to decypher the message
|
||||
*/
|
||||
secret(key: string|{epub:string}, pair:{epriv:string, epub:string }, cb?: (arg: string|undefined)=>any, opt?:{ why?:string}) :Promise<string|undefined>
|
||||
/**
|
||||
* Adds a signature to a message, for data that you want to
|
||||
* prevent attackers tampering with. The default
|
||||
* cryptographic primitive signs a SHA256 fingerprint of the
|
||||
* data
|
||||
*
|
||||
* @param data the content that you want to prove is authorized
|
||||
* @param pair SEA pair
|
||||
*/
|
||||
sign(data: any, pair: { priv: string; pub: string }): Promise<string>;
|
||||
|
||||
/**
|
||||
* Do you want to allow others to write to parts of your own
|
||||
* organization's graph without sharing your keypair with
|
||||
* them? Then this feature is for you! With SEA.certify, you
|
||||
* can create a cryptographically signed Certificate that
|
||||
* gives other people write permission. A Certificate
|
||||
* describes WHO has the right to write to your graph, WHERE
|
||||
* they can write, and (pending security review) until WHEN.
|
||||
* The Certificate should not be encrypted because it must be
|
||||
* plain text so that it is interpretable by any and every
|
||||
* peer and machine in the network, so every peer enforces
|
||||
* the same security rules, whether it is a browser, phone,
|
||||
* IoT device, or relay
|
||||
*
|
||||
* @see https://gun.eco/docs/SEA.certify
|
||||
*
|
||||
* @param who Who the certificate is for. These are the people you allow to
|
||||
* write to your own graph
|
||||
* @param policy The rules of the Certificate
|
||||
* @param authority Certificate Authority or Certificate Issuer.
|
||||
* This is your priv, or your key pair
|
||||
* @param callback A callback function that runs after a
|
||||
* Certificate is created
|
||||
*/
|
||||
certify(
|
||||
who: '*' | string | string[] | { pub: string } | { pub: string }[],
|
||||
policy: Policy,
|
||||
authority: { priv: string; pub: string },
|
||||
callback?: () => void,
|
||||
options?: {
|
||||
/**
|
||||
* Certify other users to use your graph.
|
||||
* @param certificants users for certification.
|
||||
* @param policy policises for certificants permissions
|
||||
* @param authority user that gives rights
|
||||
* @param cb callback
|
||||
* @param opt options
|
||||
*/
|
||||
certify (certificants: string | string[] | { pub: string } | { pub: string }[], policy: ISEAPolicy, authority: { pub: string; priv: string }, cb?: (cert: string) => any | null, opt?:
|
||||
{ blacklist?: string, expiry?: number }): Promise<string |undefined>
|
||||
* A timestamp (ie. `Date.now() + 10000` or `Gun.state() + 10000`)
|
||||
* to set the Certificate to expire in the future
|
||||
*
|
||||
* If `options.expiry` IS NOT SET, the Certificate is valid PERMANENTLY, and this is
|
||||
* dangerous!
|
||||
*/
|
||||
expiry: number;
|
||||
}
|
||||
): Promise<string>;
|
||||
|
||||
/**
|
||||
* Gets the data if and only if the message can be verified
|
||||
* as coming from the person you expect
|
||||
*
|
||||
* @param message what comes from `.sign`
|
||||
* @param pair from `.pair` or its public key text (`pair.pub`)
|
||||
* @returns the data if and only if the message can be
|
||||
* verified as coming from the person you expect
|
||||
*/
|
||||
verify<T extends unknown = any>(
|
||||
message: string,
|
||||
pair: string | { pub: string } | string
|
||||
): Promise<T>;
|
||||
|
||||
/**
|
||||
* Takes some data that you want to keep secret and encrypts
|
||||
* it so nobody else can read it
|
||||
*
|
||||
* @param data the content that you want to encrypt
|
||||
* @param pair from `.pair` to use as a cypher to encrypt with
|
||||
*/
|
||||
encrypt(data: any, pair: { epriv: string }): Promise<string>;
|
||||
|
||||
/**
|
||||
* Takes some data that you want to keep secret and encrypts
|
||||
* it so nobody else can read it
|
||||
*
|
||||
* @param data the content that you want to encrypt
|
||||
* @param passphrase the passphrase you want to use as a cypher to encrypt with
|
||||
*/
|
||||
encrypt(data: any, passphrase: string): Promise<string>;
|
||||
|
||||
/**
|
||||
* Read the secret data, if and only if you are allowed to
|
||||
*
|
||||
* @param message what comes from `.encrypt`
|
||||
* @param pair from `.pair` to decypher the message
|
||||
*/
|
||||
decrypt<T extends unknown = any>(
|
||||
message: string,
|
||||
pair: { epriv: string }
|
||||
): Promise<T>;
|
||||
|
||||
/**
|
||||
* Read the secret data, if and only if you are allowed to
|
||||
*
|
||||
* @param message what comes from `.encrypt`
|
||||
* @param passphrase the passphrase to decypher the message
|
||||
*/
|
||||
decrypt<T extends unknown = any>(
|
||||
message: string,
|
||||
passphrase: string
|
||||
): Promise<T>;
|
||||
|
||||
/**
|
||||
* Derive shared secret from other's pub and my epub/epriv
|
||||
*
|
||||
* @param key other's public encryption key
|
||||
* @param pair encyption key pair from `.pair`
|
||||
* @param callback A callback function that runs after a secret is created
|
||||
*/
|
||||
secret(
|
||||
key: string | { epub: string },
|
||||
pair: { epriv: string; epub: string },
|
||||
callback?: (secret: string | undefined) => void
|
||||
): Promise<string | undefined>;
|
||||
}
|
||||
|
7
types/sea/ISEACertifyOptions.d.ts
vendored
7
types/sea/ISEACertifyOptions.d.ts
vendored
@ -1,7 +0,0 @@
|
||||
export interface ISEACertifyOptions{
|
||||
blacklist?: string | {
|
||||
read: string|{'#': string}
|
||||
write: string|{'#': string}
|
||||
}
|
||||
expiry?: number
|
||||
}
|
16
types/sea/ISEAPair.d.ts
vendored
16
types/sea/ISEAPair.d.ts
vendored
@ -1,6 +1,10 @@
|
||||
export declare interface ISEAPair {
|
||||
pub: string
|
||||
priv:string
|
||||
epub:string
|
||||
epriv:string
|
||||
}
|
||||
export interface ISEAPair {
|
||||
/** private key for encryption */
|
||||
epriv: string;
|
||||
/** public key for encryption */
|
||||
epub: string;
|
||||
/** private key */
|
||||
priv: string;
|
||||
/** public key */
|
||||
pub: string;
|
||||
}
|
||||
|
17
types/sea/ISEAPolicy.d.ts
vendored
17
types/sea/ISEAPolicy.d.ts
vendored
@ -1,17 +0,0 @@
|
||||
interface ISEAPolicyTree{
|
||||
"+"?:string|ISEAPolicyTree,
|
||||
"#"?:string|ISEAPolicyTree,
|
||||
"."?:string|ISEAPolicyTree,
|
||||
"="?:string|ISEAPolicyTree,
|
||||
"*"?:string|ISEAPolicyTree,
|
||||
">"?:string|ISEAPolicyTree,
|
||||
"<"?:string|ISEAPolicyTree
|
||||
}
|
||||
|
||||
|
||||
interface ISEAPolicySingle extends ISEAPolicyTree{
|
||||
read?:string |ISEAPolicyTree,
|
||||
write?:string|ISEAPolicyTree,
|
||||
}
|
||||
|
||||
export declare type ISEAPolicy = ISEAPolicySingle |string | string[] | ISEAPolicySingle[]
|
1
types/sea/OptionsUserAuth.d.ts
vendored
Normal file
1
types/sea/OptionsUserAuth.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type OptionsUserAuth = { change: 'newPassword' };
|
1
types/sea/OptionsUserRecall.d.ts
vendored
Normal file
1
types/sea/OptionsUserRecall.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export type OptionsUserRecall = { sessionStorage: boolean };
|
3
types/sea/Policy.d.ts
vendored
Normal file
3
types/sea/Policy.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
import { IPolicy } from '.';
|
||||
|
||||
export type Policy = string | IPolicy | (string | IPolicy)[];
|
14
types/sea/index.d.ts
vendored
Normal file
14
types/sea/index.d.ts
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
export * from './GunCallbackUserAuth';
|
||||
export * from './GunCallbackUserCreate';
|
||||
export * from './GunHookCallbackAuth';
|
||||
export * from './GunUser';
|
||||
export * from './IGun';
|
||||
export * from './IGunInstance';
|
||||
export * from './IGunInstanceHookHandler';
|
||||
export * from './IGunUserInstance';
|
||||
export * from './IPolicy';
|
||||
export * from './ISEA';
|
||||
export * from './ISEAPair';
|
||||
export * from './OptionsUserAuth';
|
||||
export * from './OptionsUserRecall';
|
||||
export * from './Policy';
|
1
types/shared/And.d.ts
vendored
1
types/shared/And.d.ts
vendored
@ -1 +0,0 @@
|
||||
export type And<A,B> = A & B
|
@ -1,6 +1,28 @@
|
||||
import Gun = require('../../index');
|
||||
Gun().get('users')
|
||||
/* now change the context to alice */
|
||||
.get('alice')
|
||||
.put({})
|
||||
.back().map(x=>x)
|
||||
import Gun from '../..';
|
||||
|
||||
new Gun<{ a: { b: number; c: number } }>()
|
||||
.get('a')
|
||||
.get('b')
|
||||
.back()
|
||||
.get('c')
|
||||
.once((c) => c.toFixed(2));
|
||||
|
||||
new Gun()
|
||||
.get<{ b: number; c: number }>('a')
|
||||
.get('b')
|
||||
.back()
|
||||
.get('c')
|
||||
.once((c) => c.toFixed(2));
|
||||
|
||||
new Gun()
|
||||
.get('a')
|
||||
.back<{ a: number; b: number }>()
|
||||
.get('b')
|
||||
.once((b) => b.toFixed(2));
|
||||
|
||||
new Gun()
|
||||
.get('a')
|
||||
.get('b')
|
||||
.back<{ a: number; c: number }>(-2)
|
||||
.get('c')
|
||||
.once((c) => c.toFixed(2));
|
||||
|
@ -1,14 +1,5 @@
|
||||
//import { expectError } from 'tsd';
|
||||
import Gun from '../..';
|
||||
|
||||
import Gun = require('../../index');
|
||||
new Gun<{ a: { b: number; c: number } }>().get('a').get('b');
|
||||
|
||||
|
||||
//Documentation should work
|
||||
|
||||
async function get(){
|
||||
const gun = new Gun();
|
||||
const alice = await gun.get('user').get('alice')
|
||||
|
||||
const gun2 = new Gun<{user:{alice:string}}>();
|
||||
const alice2 = (await gun2.get('user')).alice
|
||||
}
|
||||
new Gun().get<{ b: number; c: number }>('a').get('b');
|
||||
|
@ -1,15 +1,15 @@
|
||||
import Gun = require('../../index');
|
||||
import Gun from '../..';
|
||||
|
||||
Gun()
|
||||
Gun(['http://server1.com/gun', 'http://server2.com/gun']);
|
||||
Gun({
|
||||
new Gun();
|
||||
new Gun(['http://server1.com/gun', 'http://server2.com/gun']);
|
||||
new Gun({
|
||||
s3: {
|
||||
key: '',
|
||||
secret: '',
|
||||
bucket: ''
|
||||
bucket: '',
|
||||
},
|
||||
file: 'file/path.json',
|
||||
uuid() {
|
||||
return 'xxxxxx';
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@ -1,3 +1,11 @@
|
||||
import Gun = require('../../index');
|
||||
import Gun from '../..';
|
||||
|
||||
Gun().get('users').map(user => user.name === 'Mark'? user : undefined)
|
||||
new Gun<{ users: Record<string, { name: string }> }>()
|
||||
.get('users')
|
||||
.on()
|
||||
.map((user) => (user.name === 'Mark' ? user : undefined));
|
||||
|
||||
new Gun()
|
||||
.get<Record<string, { name: string }>>('users')
|
||||
.map((user) => (user.name === 'Mark' ? user : undefined))
|
||||
.once((user) => console.log(user.name));
|
||||
|
@ -1,23 +1,39 @@
|
||||
import Gun from '../..';
|
||||
|
||||
import Gun = require('../../index');
|
||||
const gun = Gun()
|
||||
var listenerHandler = (value, key, _msg, _ev) => {
|
||||
type TOnlinable = { online: boolean };
|
||||
|
||||
}
|
||||
const gun = new Gun<{
|
||||
users: Record<string, TOnlinable>;
|
||||
foo: TOnlinable;
|
||||
home: { lights: TOnlinable };
|
||||
}>();
|
||||
|
||||
Gun().on(listenerHandler)
|
||||
var listenerHandler = (_value, _key, _msg, _ev) => {};
|
||||
|
||||
// add listener to foo
|
||||
gun.get('foo').on(listenerHandler, true)
|
||||
gun.get('foo').on(listenerHandler, true);
|
||||
|
||||
// remove listener to foo
|
||||
gun.get('foo').off()
|
||||
gun.get('foo').off();
|
||||
|
||||
gun.get('users').get('username').on(function(user : any){
|
||||
gun
|
||||
.get('users')
|
||||
.get('username')
|
||||
.on(function (user) {
|
||||
// update in real-time
|
||||
if (user.online) {
|
||||
} else {
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
gun.get('home').get('lights').on(listenerHandler,true);
|
||||
gun.get('home').get('lights').on(listenerHandler, true);
|
||||
|
||||
new Gun()
|
||||
.get('home')
|
||||
.get('lights')
|
||||
.on<TOnlinable>(function (user) {
|
||||
// update in real-time
|
||||
if (user.online) {
|
||||
} else {
|
||||
}
|
||||
});
|
||||
|
@ -1,17 +1,35 @@
|
||||
import Gun from '../..';
|
||||
|
||||
import Gun = require('../../index');
|
||||
const gun= Gun()
|
||||
let view;
|
||||
gun.get('peer').get('userID').get('profile').once(function(profile){
|
||||
const gun = new Gun<{
|
||||
peer: { userID: { profile: {} } };
|
||||
IoT: { temperature: number };
|
||||
something: string;
|
||||
}>();
|
||||
|
||||
let view: any;
|
||||
|
||||
gun
|
||||
.get('peer')
|
||||
.get('userID')
|
||||
.get('profile')
|
||||
.once(function (profile) {
|
||||
// render it, but only once. No updates.
|
||||
view.show.user(profile)
|
||||
})
|
||||
|
||||
gun.get('IoT').get('temperature').once(function(number){
|
||||
view.show.temp(number)
|
||||
})
|
||||
view.show.user(profile);
|
||||
});
|
||||
|
||||
gun
|
||||
.get('IoT')
|
||||
.get('temperature')
|
||||
.once(function (number) {
|
||||
view.show.temp(number);
|
||||
});
|
||||
|
||||
gun.once(function(data, key) {
|
||||
gun.get('something').put('something')
|
||||
})
|
||||
gun.get('something').once(function (_data, _key) {
|
||||
gun.put({ something: 'something' });
|
||||
gun.get('something').put('something');
|
||||
});
|
||||
|
||||
new Gun().get('something').once<string>(function (data, _key) {
|
||||
gun.put({ something: data });
|
||||
gun.get('something').put(data);
|
||||
});
|
||||
|
@ -1,6 +1,7 @@
|
||||
import Gun = require('../../index');
|
||||
Gun().opt({
|
||||
uuid: function () {
|
||||
return Math.floor(Math.random() * 4294967296);
|
||||
}
|
||||
})
|
||||
import Gun from '../..';
|
||||
|
||||
new Gun().opt({
|
||||
uuid: function () {
|
||||
return Math.floor(Math.random() * 4294967296).toString();
|
||||
},
|
||||
});
|
||||
|
@ -1,12 +1,12 @@
|
||||
//import { expectError } from 'tsd';
|
||||
|
||||
import Gun = require('../../index');
|
||||
|
||||
import Gun from '../..';
|
||||
|
||||
//Documentation should work
|
||||
|
||||
const gun = new Gun();
|
||||
gun.get('user').put('alice')
|
||||
type User = { name: string };
|
||||
|
||||
const gun2 = new Gun<{user:{alice:string}}>();
|
||||
gun2.get('user').put({alice:"asd"})
|
||||
const gun = new Gun<{ user: User; user2: User }>();
|
||||
gun.get('user').put({ name: '' });
|
||||
gun.get('user').get('name').put(gun.get('user').get('name'));
|
||||
gun.get('user2').put(gun.get('user'));
|
||||
|
@ -1,4 +1,8 @@
|
||||
import Gun = require('../../index');
|
||||
const gun = Gun()
|
||||
var user = gun.get('alice').put({name: "Alice"})
|
||||
gun.get('users').set("sa");
|
||||
import Gun from '../..';
|
||||
|
||||
type User = { name: string };
|
||||
|
||||
const gun = new Gun<{ users: Record<string, User>; alice: User }>();
|
||||
const user = gun.get('alice').put({ name: 'Alice' });
|
||||
gun.get('users').set({ name: 'Bob' });
|
||||
gun.get('users').set(user).get('name').put('Sally');
|
||||
|
@ -1,14 +0,0 @@
|
||||
import Gun = require('../../index');
|
||||
const gun = Gun<ExampleState>()
|
||||
|
||||
type ExampleState={
|
||||
a:{
|
||||
b:{
|
||||
c:{
|
||||
d: Record<string,string>
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gun.get("a").get("b").get("c").get("d").get("anystring").on(x=>x.startsWith("some"))
|
@ -1,13 +1,9 @@
|
||||
|
||||
import Gun = require('../../index');
|
||||
|
||||
import Gun from '../..';
|
||||
|
||||
//Documentation should work
|
||||
|
||||
const gun = Gun()
|
||||
gun.on('auth', data => {
|
||||
const gun = new Gun();
|
||||
gun.on('auth', (_data) => {});
|
||||
|
||||
})
|
||||
|
||||
gun.user().auth("a","b")
|
||||
async () => gun.user().auth(await Gun.SEA.pair())
|
||||
gun.user().auth('a', 'b');
|
||||
async () => gun.user().auth(await Gun.SEA.pair());
|
||||
|
@ -1,8 +0,0 @@
|
||||
import Gun = require('../../index');
|
||||
|
||||
|
||||
//Documentation should work
|
||||
|
||||
const gun = Gun()
|
||||
|
||||
gun.user().delete('alias', 'pass', data => data)
|
@ -1,8 +1,7 @@
|
||||
import Gun = require('../../index');
|
||||
|
||||
import Gun from '../..';
|
||||
|
||||
//Documentation should work
|
||||
|
||||
const gun = Gun()
|
||||
const gun = new Gun();
|
||||
|
||||
gun.user().leave()
|
||||
gun.user().leave();
|
||||
|
@ -1,3 +1,4 @@
|
||||
import Gun = require('../../index');
|
||||
var gun = Gun();
|
||||
var user = gun.user().recall({sessionStorage: true});
|
||||
import Gun from '../..';
|
||||
|
||||
const gun = new Gun();
|
||||
gun.user().recall({ sessionStorage: true });
|
||||
|
@ -1,4 +0,0 @@
|
||||
import Gun = require('../../index');
|
||||
var gun = Gun();
|
||||
var user = gun.user().recall({sessionStorage: true});
|
||||
user.get('mysecrets').secret('string', data => data)
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user