From 395c2b8f980bf316805d509077f0eedd0926aa37 Mon Sep 17 00:00:00 2001 From: MaciejDot <48295177+MaciejDot@users.noreply.github.com> Date: Sat, 30 Oct 2021 08:15:02 +0200 Subject: [PATCH] partly repair gun types (#1154) * partly repair gun types * added types tests --- .gitignore | 1 + global.d.ts | 4 +- gun.d.ts | 6 +- index.d.ts | 4 +- types/chain.d.ts | 308 ------------------ types/gun/AckCallback.d.ts | 7 + types/gun/AuthCallback.d.ts | 20 ++ types/gun/CreateCallback.d.ts | 9 + types/gun/IGun.d.ts | 45 +++ .../IGunConstructorOptions.d.ts} | 72 ++-- types/gun/IGunDataType.d.ts | 8 + types/gun/IGunFinalTreeMethods.d.ts | 86 +++++ types/gun/IGunFinalUserTreeMethods.d.ts | 90 +++++ types/gun/IGunInstance.d.ts | 181 ++++++++++ types/gun/IGunReturnObject.d.ts | 6 + types/gun/IGunTree.d.ts | 10 + types/gun/IGunUserInstance.d.ts | 232 +++++++++++++ types/index.test-d.ts | 121 ------- types/{static/sea.d.ts => sea/ISEA.d.ts} | 150 +++++---- types/sea/ISEACertifyOptions.d.ts | 7 + types/sea/ISEAPair.d.ts | 6 + types/sea/ISEAPolicy.d.ts | 17 + types/shared/And.d.ts | 1 + types/static.d.ts | 28 -- types/static/node.d.ts | 17 - types/test/gun-back.test-d.ts | 6 + types/test/gun-get.test-d.ts | 14 + types/test/gun-instance.test-d.ts | 15 + types/test/gun-map.test-d.ts | 3 + types/test/gun-on.test-d.ts | 23 ++ types/test/gun-once.test-d.ts | 17 + types/test/gun-opt.test-d.ts | 6 + types/test/gun-put.test-d.ts | 12 + types/test/gun-set.test-d.ts | 4 + types/test/gun-typed.test-d.ts | 14 + types/test/gun-user-auth.test-d.ts | 13 + types/test/gun-user-delete.test-d.ts | 8 + types/test/gun-user-leave.test-d.ts | 8 + types/test/gun-user-recall.test-d.ts | 3 + types/test/gun-user-secret.test-d.ts | 4 + types/test/gun-user.test-d.ts | 3 + types/test/sea-certify.test-d.ts | 29 ++ types/test/sea.test-d.ts | 28 ++ types/types.d.ts | 52 --- 44 files changed, 1060 insertions(+), 638 deletions(-) delete mode 100644 types/chain.d.ts create mode 100644 types/gun/AckCallback.d.ts create mode 100644 types/gun/AuthCallback.d.ts create mode 100644 types/gun/CreateCallback.d.ts create mode 100644 types/gun/IGun.d.ts rename types/{options.d.ts => gun/IGunConstructorOptions.d.ts} (74%) create mode 100644 types/gun/IGunDataType.d.ts create mode 100644 types/gun/IGunFinalTreeMethods.d.ts create mode 100644 types/gun/IGunFinalUserTreeMethods.d.ts create mode 100644 types/gun/IGunInstance.d.ts create mode 100644 types/gun/IGunReturnObject.d.ts create mode 100644 types/gun/IGunTree.d.ts create mode 100644 types/gun/IGunUserInstance.d.ts delete mode 100644 types/index.test-d.ts rename types/{static/sea.d.ts => sea/ISEA.d.ts} (67%) create mode 100644 types/sea/ISEACertifyOptions.d.ts create mode 100644 types/sea/ISEAPair.d.ts create mode 100644 types/sea/ISEAPolicy.d.ts create mode 100644 types/shared/And.d.ts delete mode 100644 types/static.d.ts delete mode 100644 types/static/node.d.ts create mode 100644 types/test/gun-back.test-d.ts create mode 100644 types/test/gun-get.test-d.ts create mode 100644 types/test/gun-instance.test-d.ts create mode 100644 types/test/gun-map.test-d.ts create mode 100644 types/test/gun-on.test-d.ts create mode 100644 types/test/gun-once.test-d.ts create mode 100644 types/test/gun-opt.test-d.ts create mode 100644 types/test/gun-put.test-d.ts create mode 100644 types/test/gun-set.test-d.ts create mode 100644 types/test/gun-typed.test-d.ts create mode 100644 types/test/gun-user-auth.test-d.ts create mode 100644 types/test/gun-user-delete.test-d.ts create mode 100644 types/test/gun-user-leave.test-d.ts create mode 100644 types/test/gun-user-recall.test-d.ts create mode 100644 types/test/gun-user-secret.test-d.ts create mode 100644 types/test/gun-user.test-d.ts create mode 100644 types/test/sea-certify.test-d.ts create mode 100644 types/test/sea.test-d.ts delete mode 100644 types/types.d.ts diff --git a/.gitignore b/.gitignore index 8658485f..f00f27d2 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,6 @@ isolate*.log .localStorage /types/**/*.ts !/types/**/*.d.ts +!/types/**/*.test-d.ts /gun.ts /temp/ \ No newline at end of file diff --git a/global.d.ts b/global.d.ts index e23dbe2d..ffb1799c 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,4 +1,4 @@ -import { IGunStatic } from './types/static'; +import { IGun } from './types/gun/IGun'; declare global { - var Gun: IGunStatic; + var Gun: IGun; } diff --git a/gun.d.ts b/gun.d.ts index 7bbe17cd..7cd5f72a 100644 --- a/gun.d.ts +++ b/gun.d.ts @@ -1,3 +1,3 @@ -import { IGunStatic } from './types/static'; -declare const Gun: IGunStatic; -export = Gun; +import { IGun } from './types/gun/IGun'; +declare const Gun: IGun; +export = Gun; \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 1ce189c2..0db8a5f8 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,3 @@ -import { IGunStatic } from './types/static'; -declare const Gun: IGunStatic; +import { IGun } from './types/gun/IGun'; +declare const Gun: IGun; export = Gun; diff --git a/types/chain.d.ts b/types/chain.d.ts deleted file mode 100644 index aefcd94a..00000000 --- a/types/chain.d.ts +++ /dev/null @@ -1,308 +0,0 @@ -import { AlwaysDisallowedType, DisallowPrimitives, AckCallback, Saveable, IGunCryptoKeyPair } from './types'; -import { IGunConstructorOptions } from './options'; - -declare type ITSResolvable = R | PromiseLike; - -export interface IGunChainReference, ReferenceKey = any, IsTop extends 'pre_root' | 'root' | false = false> { - - /** - * 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>>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunChainReference; - - /** - * **.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(data: Partial>>, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunChainReference; - - /** - * 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(key: Exclude>, callback?: ( - /** the raw data. Internal node of gun. Will not typed here. */ - paramA: Record<'gun' | '$' | 'root' | 'id' | 'back' | 'on' | 'tag' | 'get' | 'soul' | 'ack' | 'put', any>, - /** the key, ID, or property name of the data. */ - paramB: Record<'off' | 'to' | 'next' | 'the' | 'on' | 'as' | 'back' | 'rid' | 'id', any>) => void): IGunChainReference; - - /** - * 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. - * @returns No mention in the document, behavior as `ChainReference` - */ - opt(options: IGunConstructorOptions): IGunChainReference; - - /** - * 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` or `Infinity` will take you to the root. - * @returns Impossible to determinate final type. You must cast it by yourself. - */ - back(amount?: number): IGunChainReference; - - /** - * 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: DisallowPrimitives>, key: ReferenceKey) => void, option?: { - change: boolean; - } | boolean): IGunChainReference; - - /** - * 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: (DisallowPrimitives>>) | undefined, key: ReferenceKey) => void, option?: { - wait: number; - }): IGunChainReference; - - /** - * 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(callback?: (value: DataType, key: string) => DataType | undefined): IGunChainReference; - - /** - * Undocumented, but extremely useful and mentioned in the document - * - * Remove **all** listener on this node. - */ - off(): void; - - /** - * - * 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 - * ``! - */ - path?(path: string | string[]): IGunChainReference; - - /** - * Handle cases where data can't be found. - * - * **Warning**: Not included by default! You must include it yourself via `require('gun/lib/not.js')` or - * ``! - */ - not?(callback: (key: ReferenceKey) => void): IGunChainReference; - - /** - * 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 - * ``! - */ - open?(callback: (data: DataType) => void): IGunChainReference; - - /** - * 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 - * ``! - */ - load?(callback: (data: DataType) => void): IGunChainReference; - - /** - * Returns a promise for you to use. - * - * **Warning**: Not included by default! You must include it yourself via `require('gun/lib/then.js')` or - * ``! - */ - // then?(onfulfilled: (value: TResult1) => ITSResolvable): Promise; - // then?(): Promise; - - /** - * Returns a promise for you to use. - * - * **Warning**: Not included by default! You must include it yourself via `require('gun/lib/then.js')` or - * ``! - */ - promise?; - key: ReferenceKey; - gun: IGunChainReference; - }>(onfulfilled: (value: TResult1) => ITSResolvable): Promise; - promise?; - key: ReferenceKey; - gun: IGunChainReference; - }>(): Promise; - - /** - * bye lets you change data after that browser peer disconnects. - * This is useful for games and status messages, - * that if a player leaves you can remove them from the game or set a user's status to "away". - * - * **Warning**: Not included by default! You must include it yourself via `require('gun/lib/bye.js')` or - * ``! - */ - bye?(): { - put(data: Saveable): void; - }; - - /** - * 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 - * ``! - */ - later?(callback: (this: IGunChainReference, data: Record, key: ReferenceKey) => void, seconds: number): IGunChainReference; - - /** - * 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 - * ``! - */ - unset?(data: K): IGunChainReference; - - /** - * 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?(callback: (data: DataType[K], key: ReferenceKey, time: number) => void, alsoReceiveNOldEvents?: number): IGunChainReference; - - /** Pushes data to a Timegraph with it's time set to Gun.state()'s time */ - time?(data: DataType[K]): void; - - /** - * 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?: (ack: { - ok: 0; - pub: string; - } | { - err: string; - }) => void, opt?: {}): IGunChainReference; - - /** - * 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?: (ack: { - ack: 2; - get: string; - on: (...args: [unknown, unknown, unknown]) => unknown; - put: { - alias: string; - auth: any; - epub: string; - pub: string; - }; - sea: IGunCryptoKeyPair; - soul: string; - } | { - err: string; - }) => void, opt?: {}): IGunChainReference; - - /** - * 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: CryptoKeyPair, cb?: (ack: { - ack: 2; - get: string; - on: (...args: [unknown, unknown, unknown]) => unknown; - put: { - alias: string; - auth: any; - epub: string; - pub: string; - }; - sea: IGunCryptoKeyPair; - soul: string; - } | { - err: string; - }) => void, opt?: {}): IGunChainReference; - - /** - * Returns the key pair in the form of an object as below. - */ - pair(): IGunCryptoKeyPair; - - /** - * 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): IGunChainReference; - - /** - * 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; - - /** - * 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?: Parameters[2]): IGunChainReference; - - /** - * @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(publicKey?: string): IGunChainReference; -} diff --git a/types/gun/AckCallback.d.ts b/types/gun/AckCallback.d.ts new file mode 100644 index 00000000..936080e4 --- /dev/null +++ b/types/gun/AckCallback.d.ts @@ -0,0 +1,7 @@ +export declare type AckCallback = (ack: { + err: string; + ok: undefined; +} | { + err: undefined; + ok: string; +}) => void; \ No newline at end of file diff --git a/types/gun/AuthCallback.d.ts b/types/gun/AuthCallback.d.ts new file mode 100644 index 00000000..291a0ff1 --- /dev/null +++ b/types/gun/AuthCallback.d.ts @@ -0,0 +1,20 @@ +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 \ No newline at end of file diff --git a/types/gun/CreateCallback.d.ts b/types/gun/CreateCallback.d.ts new file mode 100644 index 00000000..f5ad3d29 --- /dev/null +++ b/types/gun/CreateCallback.d.ts @@ -0,0 +1,9 @@ +export type CreateCallback = (ack: { + ok: 0; + pub: string; + err?:undefined +} | { + ok?: 0; + pub?: string; + err: string; +}) => any \ No newline at end of file diff --git a/types/gun/IGun.d.ts b/types/gun/IGun.d.ts new file mode 100644 index 00000000..d8bf183b --- /dev/null +++ b/types/gun/IGun.d.ts @@ -0,0 +1,45 @@ +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'; + +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 + */ + (options?: IGunConstructorOptions): IGunInstance; + new (options?: IGunConstructorOptions): IGunInstance; + readonly node: IGun; + + /** @see https://gun.eco/docs/SEA */ + readonly SEA: ISEA; + readonly version: string; + readonly chain: IGunInstance; + 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; + + /** + * 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): string | undefined; + + /** Returns a "gun-ified" variant of the json input by injecting a new gun ID into the metadata field. */ + ify(json: any): any; + + state():number +} \ No newline at end of file diff --git a/types/options.d.ts b/types/gun/IGunConstructorOptions.d.ts similarity index 74% rename from types/options.d.ts rename to types/gun/IGunConstructorOptions.d.ts index b56b2603..cfe97e00 100644 --- a/types/options.d.ts +++ b/types/gun/IGunConstructorOptions.d.ts @@ -1,39 +1,33 @@ -/** - * options['module name'] allows you to pass options to a 3rd party module. - * Their project README will likely list the exposed options - * https://github.com/amark/gun/wiki/Modules - */ -export interface IGunConstructorOptions extends 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; - - /** 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; -}> { -} +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; + + /** 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[]; \ No newline at end of file diff --git a/types/gun/IGunDataType.d.ts b/types/gun/IGunDataType.d.ts new file mode 100644 index 00000000..52917aa8 --- /dev/null +++ b/types/gun/IGunDataType.d.ts @@ -0,0 +1,8 @@ +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 diff --git a/types/gun/IGunFinalTreeMethods.d.ts b/types/gun/IGunFinalTreeMethods.d.ts new file mode 100644 index 00000000..54337b17 --- /dev/null +++ b/types/gun/IGunFinalTreeMethods.d.ts @@ -0,0 +1,86 @@ +import { AckCallback } from "./AckCallback"; +import { AuthCallback } from "./AuthCallback"; +import { IGunDataType } from "./IGunDataType"; +import { IGunInstance } from "./IGunInstance"; +import { IGunReturnObject } from "./IGunReturnObject"; + +export interface IGunFinalTreeMethods { + + not?(callback: (key: TKey) => void): IGunFinalTreeMethods ; + /** + * 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 + * ``! + */ + later?(callback: (data: TValue, key: TKey) => void, seconds: number): IGunFinalTreeMethods ; + off(): IGunFinalTreeMethods ; + /* /** + * 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, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunFinalTreeMethods + + /** + * 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, key: TKey, _msg:any, _ev:any) => void, option?: { + change: boolean; + } | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunFinalTreeMethods | Promise>; + + /** + * 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 + + /** + * 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, key: TKey) => void, option?: { + wait: number; + }): IGunFinalTreeMethods | Promise>; + + /** + * 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 + * ``! + */ + open?(callback: (data: IGunReturnObject) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunFinalTreeMethods | Promise>; + + /** + * 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 + * ``! + */ + load?(callback: (data: IGunReturnObject) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunFinalTreeMethods | Promise> + + + /**goes back user chain */ + back(amount?:number) : IGunInstance + +} \ No newline at end of file diff --git a/types/gun/IGunFinalUserTreeMethods.d.ts b/types/gun/IGunFinalUserTreeMethods.d.ts new file mode 100644 index 00000000..1ec51405 --- /dev/null +++ b/types/gun/IGunFinalUserTreeMethods.d.ts @@ -0,0 +1,90 @@ +import { AckCallback } from "./AckCallback"; +import { AuthCallback } from "./AuthCallback"; +import { IGunDataType } from "./IGunDataType"; +import { IGunReturnObject } from "./IGunReturnObject"; +import { IGunUserInstance } from "./IGunUserInstance"; + +export interface IGunFinalUserTreeMethods { + /** + * check out https://gun.eco/docs/User#user-secret + * save secret that only trusted users can read + * + */ + not?(callback: (key: TKey) => void): IGunFinalUserTreeMethods ; + /** + * 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 + * ``! + */ + later?(callback: (data: TValue, key: TKey) => void, seconds: number): IGunFinalUserTreeMethods; + off(): IGunFinalUserTreeMethods ; + /* /** + * 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, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunFinalUserTreeMethods + + /** + * 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, key: TKey, _msg:any, _ev:any) => void, option?: { + change: boolean; + } | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunFinalUserTreeMethods | Promise>; + + /** + * 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 + + /** + * 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, key: TKey) => void, option?: { + wait: number; + }): IGunFinalUserTreeMethods | Promise>; + + /** + * 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 + * ``! + */ + open?(callback: (data: IGunReturnObject) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunFinalUserTreeMethods | Promise>; + + /** + * 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 + * ``! + */ + load?(callback: (data: IGunReturnObject) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunFinalUserTreeMethods | Promise> + + + /**goes back user chain */ + back(amount?:number) : IGunUserInstance +secret(string: string, callback : (...args:unknown[])=> any): IGunFinalUserTreeMethods +} \ No newline at end of file diff --git a/types/gun/IGunInstance.d.ts b/types/gun/IGunInstance.d.ts new file mode 100644 index 00000000..60bc4457 --- /dev/null +++ b/types/gun/IGunInstance.d.ts @@ -0,0 +1,181 @@ + +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 ; + /** + * 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 + * ``! + */ + later?(callback: (data: CurrentTreeDataType, key: TSoul) => void, seconds: number): IGunInstance ; + off(): IGunInstance ; + /* /** + * 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, callback?: AckCallback | null, options?: { opt?: { cert?: string } }): IGunInstance + + /** + * 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, key: TSoul, _msg:any, _ev:any) => void, option?: { + change: boolean; + } | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunInstance | Promise>; + + /** + * 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 + + /** + * 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, key: TSoul) => void, option?: { + wait: number; + }): IGunInstance| Promise>; + + /** + * 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 + * ``! + */ + open?(callback: (data: IGunReturnObject) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunInstance | Promise>; + + /** + * 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 + * ``! + */ + load?(callback: (data: IGunReturnObject) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunInstance | Promise> + + + /**goes back user chain */ + back(amount?:number) : IGunInstance +/** + * **.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(data: CurrentTreeDataType[K], callback?: AckCallback | null, options?: { opt?: { cert?: string } }): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance: IGunFinalTreeMethods; + +/** + * 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(key: K, callback?: ( + data: IGunReturnObject, + key: K) => any): + And< Promise, + CurrentTreeDataType[K] extends IGunDataType ? + IGunInstance & IGunFinalTreeMethods : + IGunDataType extends CurrentTreeDataType[K] ? + IGunFinalTreeMethods & IGunInstance + : IGunFinalTreeMethods> + + +map(match: (data: CurrentTreeDataType) => T ): IGunFinalTreeMethods + /** + * 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 + * ``! + */ + unset?(data: K): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance: IGunFinalTreeMethods; + + +/** + * 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 : IGunFinalTreeMethods + + +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 + * ``! + */ +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?(callback: (data: CurrentTreeDataType[K], key: K, time: number) => void, alsoReceiveNOldEvents?: number): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance: IGunFinalTreeMethods; + +/** Pushes data to a Timegraph with it's time set to Gun.state()'s time */ +time?(data: CurrentTreeDataType[K]): CurrentTreeDataType[K] extends IGunDataType ? IGunInstance: IGunFinalTreeMethods; + + +/** + * @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(): IGunUserInstance + user(publicKey: string): IGunUserInstance +} \ No newline at end of file diff --git a/types/gun/IGunReturnObject.d.ts b/types/gun/IGunReturnObject.d.ts new file mode 100644 index 00000000..057b0181 --- /dev/null +++ b/types/gun/IGunReturnObject.d.ts @@ -0,0 +1,6 @@ +export declare type IGunReturnObject = (TObject & { + _:{ + '#': TSoul, + '>': TObject extends number |string|boolean?unknown : Record + } +})|undefined \ No newline at end of file diff --git a/types/gun/IGunTree.d.ts b/types/gun/IGunTree.d.ts new file mode 100644 index 00000000..2a76291f --- /dev/null +++ b/types/gun/IGunTree.d.ts @@ -0,0 +1,10 @@ +export interface IGunTree{ + "+"?:string|IGunTree, + "#"?:string|IGunTree, + "."?:string|IGunTree, + "="?:string|IGunTree, + "*"?:string|IGunTree, + ">"?:string|IGunTree, + "<"?:string|IGunTree, + '-'?:string|number|IGunTree +} \ No newline at end of file diff --git a/types/gun/IGunUserInstance.d.ts b/types/gun/IGunUserInstance.d.ts new file mode 100644 index 00000000..f0895fe7 --- /dev/null +++ b/types/gun/IGunUserInstance.d.ts @@ -0,0 +1,232 @@ +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 { + /** + * check out https://gun.eco/docs/User#user-secret + * save secret that only trusted users can read + * + */ + not?(callback: (key: TKey) => void): IGunUserInstance ; + /** + * 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 + * ``! + */ + later?(callback: (data: CurrentDataType, key: TKey) => void, seconds: number): IGunUserInstance ; + off(): IGunUserInstance ; + /* /** + * 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, callback?: AckCallback | null, options?: { opt?: { cert?: string } }):IGunUserInstance + + /** + * 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, key: TKey, _msg:any, _ev:any) => void, option?: { + change: boolean; + } | boolean, eas?:{$?:any, subs?: unknown[] | { push(arg: unknown) }}, as?:any): IGunUserInstance | Promise>; + + /** + * 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 + + /** + * 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, key: TKey) => void, option?: { + wait: number; + }): IGunUserInstance | Promise>; + + /** + * 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 + * ``! + */ + open?(callback: (data: IGunReturnObject) => any, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunUserInstance | Promise>; + + /** + * 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 + * ``! + */ + load?(callback: (data: IGunReturnObject) => void, opt?: { at?: any, key?: any, doc?: any, ids?: any, any?: any, meta?: any, ev?: { off?: () => {} } }, at?: Partial): IGunUserInstance | Promise> + + + /**goes back user chain */ + back(amount?:number) : IGunUserInstance + secret(string: string, callback : (...args:unknown[])=> any): IGunUserInstance + + + + + + + + + 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; + + +/** + * 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(key: K, callback?: ( + data: IGunReturnObject, + key: K) => any): + And< Promise, + CurrentDataType[K] extends IGunDataType ? + IGunUserInstance & IGunFinalUserTreeMethods : + IGunDataType extends CurrentDataType[K] ? + IGunFinalUserTreeMethods & IGunUserInstance< IGunDataType , string> + : IGunFinalUserTreeMethods> + +/** + * **.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(data: CurrentDataType[K], callback?: AckCallback | null, options?: { opt?: { cert?: string } }): CurrentDataType[K] extends IGunDataType? IGunUserInstance: IGunFinalUserTreeMethods ; + + + 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; + + map(match: IGunTree ): CurrentDataType[keyof CurrentDataType] extends IGunDataType? IGunUserInstance : IGunFinalUserTreeMethods + + + map(match: (data: CurrentDataType) => T ): IGunFinalUserTreeMethods +/** + * 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?(callback: (data: CurrentDataType[K], key: K, time: number) => void, alsoReceiveNOldEvents?: number): CurrentDataType[K] extends IGunDataType ? IGunUserInstance: IGunFinalUserTreeMethods; + + /** Pushes data to a Timegraph with it's time set to Gun.state()'s time */ + time?(data: CurrentDataType[K]): CurrentDataType[K] extends IGunDataType ? IGunUserInstance: IGunFinalUserTreeMethods; + + +/** + * @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(): IGunUserInstance + user(publicKey: string): IGunUserInstance + + +} \ No newline at end of file diff --git a/types/index.test-d.ts b/types/index.test-d.ts deleted file mode 100644 index 5dfbfd42..00000000 --- a/types/index.test-d.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { expectError } from 'tsd'; - -import Gun = require('../index'); - -Gun(['http://server1.com/gun', 'http://server2.com/gun']); -Gun({ - s3: { - key: '', - secret: '', - bucket: '' - }, - file: 'file/path.json', - uuid() { - return 'xxxxxx'; - } -}); - -interface AppState { - object: { - num: number; - str: string; - /** Comment test */ - bool: boolean; - specstr: 'a' | 'b'; - obj: { - arr2: Record; - }; - }; - chatRoom: Record; -} - -const app = new Gun(); - -// Put and get something that was previously put -app.get('object') - .get('bool') - .put(true); -app.get('object') - .get('num') - .put(1); -app.get('object').put({ - bool: true -}); - -// Set and get something that was inserted using `set`. -const appSet = app.get('object') - .get('obj') - .get('arr2'); -appSet.set({ foo: 1, bar: '2' }); -// getting an auto-generated key may return an undefined value. -appSet.get('stringIdentifier').once(a => a?.foo); - -expectError( - app.get('object') - .get('bool') - .put(1)); - -app.get('object').on(data => { - data.bool; -}); - -app.get('object').off(); - -app.get('object').once(data => { - if (data) data.bool; -}); - -async function name() { - const data = await app.get('object').promise!(); - data.put.bool; -} - -app.get('chatRoom').time!({ by: 'A', message: 'Hello' }); - -app.get('chatRoom').time!(msg => { - msg.by; -}, 20); - -expectError( - app.get('object').time!({ a: 1 })); - -class X { - val: string = 'someString'; - b() { } -} - -interface BadState { - // Top level primitives - a: 1; - b: { - // Ban functions - c: () => void; - // Ban class - d: typeof X; - // Recursive check for banned types - e: { - f: () => void; - }; - }; - // Filter, remove functions on prototype. - c: X; -} - -const bad = new Gun(); - -expectError( - bad.get('a').put(1)); - -expectError(bad.get('b') - .get('c') - .put(() => { })); - -expectError(bad.get('b') - .get('d') - .put(X)); - -expectError( - bad.get('b').put({ c: () => { }, d: X, e: { f: () => { } } })); - -expectError( - bad.get('c').put(new X())); \ No newline at end of file diff --git a/types/static/sea.d.ts b/types/sea/ISEA.d.ts similarity index 67% rename from types/static/sea.d.ts rename to types/sea/ISEA.d.ts index 1f4eb2c2..ac4c47e8 100644 --- a/types/static/sea.d.ts +++ b/types/sea/ISEA.d.ts @@ -1,66 +1,84 @@ -import { IGunCryptoKeyPair } from "../types"; - -/** @see https://gun.eco/docs/SEA */ -export interface IGunStaticSEA { - - /** If you want SEA to throw while in development, turn SEA.throw = true on, but please do not use this in production. */ - throw?: boolean; - - /** Last known error */ - err?: Error; - - /** - * 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; - - /** - * 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: IGunCryptoKeyPair) => void, opt?: {}): Promise; - - /** - * 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; - - /** - * 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(message: any, pair: { pub: string } | string): Promise; - - /** - * 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; - - /** - * 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(message: any, pair: { epriv: string } | string): Promise; -} +import { ISEAPair } from "./ISEAPair"; +import { ISEAPolicy } from "./ISEAPolicy"; +/** @see https://gun.eco/docs/SEA */ +export interface ISEA { + + /** If you want SEA to throw while in development, turn SEA.throw = true on, but please do not use this in production. */ + throw?: boolean; + + /** Last known error */ + err?: string; + + /** + * 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; + + /** + * 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; + + /** + * 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; + + /** + * 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(message: string, pair: { pub: string } | string): Promise; + + /** + * 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; + + /** + * 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(message: any, pair: { epriv: string } | string): Promise; + + /** + * 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 + + /** + * 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 +} diff --git a/types/sea/ISEACertifyOptions.d.ts b/types/sea/ISEACertifyOptions.d.ts new file mode 100644 index 00000000..f2c95b28 --- /dev/null +++ b/types/sea/ISEACertifyOptions.d.ts @@ -0,0 +1,7 @@ +export interface ISEACertifyOptions{ + blacklist?: string | { + read: string|{'#': string} + write: string|{'#': string} + } + expiry?: number +} \ No newline at end of file diff --git a/types/sea/ISEAPair.d.ts b/types/sea/ISEAPair.d.ts new file mode 100644 index 00000000..59d38c81 --- /dev/null +++ b/types/sea/ISEAPair.d.ts @@ -0,0 +1,6 @@ +export declare interface ISEAPair { + pub: string + priv:string + epub:string + epriv:string +} \ No newline at end of file diff --git a/types/sea/ISEAPolicy.d.ts b/types/sea/ISEAPolicy.d.ts new file mode 100644 index 00000000..6f67577e --- /dev/null +++ b/types/sea/ISEAPolicy.d.ts @@ -0,0 +1,17 @@ +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[] \ No newline at end of file diff --git a/types/shared/And.d.ts b/types/shared/And.d.ts new file mode 100644 index 00000000..ee724d55 --- /dev/null +++ b/types/shared/And.d.ts @@ -0,0 +1 @@ +export type And = A & B \ No newline at end of file diff --git a/types/static.d.ts b/types/static.d.ts deleted file mode 100644 index 051e1485..00000000 --- a/types/static.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { IGunChainReference } from './chain'; -import { IGunConstructorOptions } from './options'; -import { IGunStaticNode } from './static/node'; -import { IGunStaticSEA } from './static/sea'; -export interface IGunStatic { - - /** - * @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. - */ - (options?: string | string[] | IGunConstructorOptions): IGunChainReference; - new (options?: string | string[] | IGunConstructorOptions): IGunChainReference; - readonly node: IGunStaticNode; - - /** @see https://gun.eco/docs/SEA */ - readonly SEA: IGunStaticSEA; - readonly version: string; - readonly chain: IGunChainReference; - readonly log: { - (...argv: any[]): void; - once(...argv: any[]): void; - off: boolean; - }; -} diff --git a/types/static/node.d.ts b/types/static/node.d.ts deleted file mode 100644 index 66570dc0..00000000 --- a/types/static/node.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { IGunChainReference } from '../chain'; - -export interface IGunStaticNode { - - /** Returns true if data is a gun node, otherwise false. */ - is(anything: any): anything is IGunChainReference; - - /** - * 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: IGunChainReference): string; - - /** Returns a "gun-ified" variant of the json input by injecting a new gun ID into the metadata field. */ - ify(json: any): any; -} diff --git a/types/test/gun-back.test-d.ts b/types/test/gun-back.test-d.ts new file mode 100644 index 00000000..abb4507a --- /dev/null +++ b/types/test/gun-back.test-d.ts @@ -0,0 +1,6 @@ +import Gun = require('../../index'); +Gun().get('users') + /* now change the context to alice */ + .get('alice') + .put({}) + .back().map(x=>x) \ No newline at end of file diff --git a/types/test/gun-get.test-d.ts b/types/test/gun-get.test-d.ts new file mode 100644 index 00000000..52c1daa0 --- /dev/null +++ b/types/test/gun-get.test-d.ts @@ -0,0 +1,14 @@ +//import { expectError } from 'tsd'; + +import Gun = require('../../index'); + + +//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 +} diff --git a/types/test/gun-instance.test-d.ts b/types/test/gun-instance.test-d.ts new file mode 100644 index 00000000..52d3e893 --- /dev/null +++ b/types/test/gun-instance.test-d.ts @@ -0,0 +1,15 @@ +import Gun = require('../../index'); + +Gun() +Gun(['http://server1.com/gun', 'http://server2.com/gun']); +Gun({ + s3: { + key: '', + secret: '', + bucket: '' + }, + file: 'file/path.json', + uuid() { + return 'xxxxxx'; + } +}); \ No newline at end of file diff --git a/types/test/gun-map.test-d.ts b/types/test/gun-map.test-d.ts new file mode 100644 index 00000000..b084d498 --- /dev/null +++ b/types/test/gun-map.test-d.ts @@ -0,0 +1,3 @@ +import Gun = require('../../index'); + +Gun().get('users').map(user => user.name === 'Mark'? user : undefined) \ No newline at end of file diff --git a/types/test/gun-on.test-d.ts b/types/test/gun-on.test-d.ts new file mode 100644 index 00000000..1486d1cd --- /dev/null +++ b/types/test/gun-on.test-d.ts @@ -0,0 +1,23 @@ + +import Gun = require('../../index'); +const gun = Gun() +var listenerHandler = (value, key, _msg, _ev) => { + +} + +Gun().on(listenerHandler) + +// add listener to foo +gun.get('foo').on(listenerHandler, true) + +// remove listener to foo +gun.get('foo').off() + +gun.get('users').get('username').on(function(user : any){ + // update in real-time + if (user.online) { + } else { + } + }) + + gun.get('home').get('lights').on(listenerHandler,true); \ No newline at end of file diff --git a/types/test/gun-once.test-d.ts b/types/test/gun-once.test-d.ts new file mode 100644 index 00000000..919c9a5e --- /dev/null +++ b/types/test/gun-once.test-d.ts @@ -0,0 +1,17 @@ + +import Gun = require('../../index'); +const gun= Gun() +let view; +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) + }) + + + gun.once(function(data, key) { + gun.get('something').put('something') + }) \ No newline at end of file diff --git a/types/test/gun-opt.test-d.ts b/types/test/gun-opt.test-d.ts new file mode 100644 index 00000000..179ea470 --- /dev/null +++ b/types/test/gun-opt.test-d.ts @@ -0,0 +1,6 @@ +import Gun = require('../../index'); +Gun().opt({ + uuid: function () { + return Math.floor(Math.random() * 4294967296); + } + }) \ No newline at end of file diff --git a/types/test/gun-put.test-d.ts b/types/test/gun-put.test-d.ts new file mode 100644 index 00000000..1a5b40c4 --- /dev/null +++ b/types/test/gun-put.test-d.ts @@ -0,0 +1,12 @@ +//import { expectError } from 'tsd'; + +import Gun = require('../../index'); + + +//Documentation should work + + const gun = new Gun(); + gun.get('user').put('alice') + + const gun2 = new Gun<{user:{alice:string}}>(); + gun2.get('user').put({alice:"asd"}) diff --git a/types/test/gun-set.test-d.ts b/types/test/gun-set.test-d.ts new file mode 100644 index 00000000..0dd35ec1 --- /dev/null +++ b/types/test/gun-set.test-d.ts @@ -0,0 +1,4 @@ +import Gun = require('../../index'); +const gun = Gun() +var user = gun.get('alice').put({name: "Alice"}) +gun.get('users').set("sa"); \ No newline at end of file diff --git a/types/test/gun-typed.test-d.ts b/types/test/gun-typed.test-d.ts new file mode 100644 index 00000000..6d7437cd --- /dev/null +++ b/types/test/gun-typed.test-d.ts @@ -0,0 +1,14 @@ +import Gun = require('../../index'); +const gun = Gun() + +type ExampleState={ + a:{ + b:{ + c:{ + d: Record + } + } + } +} + +gun.get("a").get("b").get("c").get("d").get("anystring").on(x=>x.startsWith("some")) \ No newline at end of file diff --git a/types/test/gun-user-auth.test-d.ts b/types/test/gun-user-auth.test-d.ts new file mode 100644 index 00000000..fe19194b --- /dev/null +++ b/types/test/gun-user-auth.test-d.ts @@ -0,0 +1,13 @@ + +import Gun = require('../../index'); + + +//Documentation should work + +const gun = Gun() +gun.on('auth', data => { + +}) + +gun.user().auth("a","b") +async () => gun.user().auth(await Gun.SEA.pair()) \ No newline at end of file diff --git a/types/test/gun-user-delete.test-d.ts b/types/test/gun-user-delete.test-d.ts new file mode 100644 index 00000000..55437d68 --- /dev/null +++ b/types/test/gun-user-delete.test-d.ts @@ -0,0 +1,8 @@ +import Gun = require('../../index'); + + +//Documentation should work + +const gun = Gun() + +gun.user().delete('alias', 'pass', data => data) \ No newline at end of file diff --git a/types/test/gun-user-leave.test-d.ts b/types/test/gun-user-leave.test-d.ts new file mode 100644 index 00000000..b52c253f --- /dev/null +++ b/types/test/gun-user-leave.test-d.ts @@ -0,0 +1,8 @@ +import Gun = require('../../index'); + + +//Documentation should work + +const gun = Gun() + +gun.user().leave() \ No newline at end of file diff --git a/types/test/gun-user-recall.test-d.ts b/types/test/gun-user-recall.test-d.ts new file mode 100644 index 00000000..15da62da --- /dev/null +++ b/types/test/gun-user-recall.test-d.ts @@ -0,0 +1,3 @@ +import Gun = require('../../index'); +var gun = Gun(); +var user = gun.user().recall({sessionStorage: true}); \ No newline at end of file diff --git a/types/test/gun-user-secret.test-d.ts b/types/test/gun-user-secret.test-d.ts new file mode 100644 index 00000000..4ed90012 --- /dev/null +++ b/types/test/gun-user-secret.test-d.ts @@ -0,0 +1,4 @@ +import Gun = require('../../index'); +var gun = Gun(); +var user = gun.user().recall({sessionStorage: true}); +user.get('mysecrets').secret('string', data => data) \ No newline at end of file diff --git a/types/test/gun-user.test-d.ts b/types/test/gun-user.test-d.ts new file mode 100644 index 00000000..a49ac39e --- /dev/null +++ b/types/test/gun-user.test-d.ts @@ -0,0 +1,3 @@ +import Gun = require('../../index'); +var gun = Gun(); +gun.user("publicKey").once(console.log) \ No newline at end of file diff --git a/types/test/sea-certify.test-d.ts b/types/test/sea-certify.test-d.ts new file mode 100644 index 00000000..842b2f3e --- /dev/null +++ b/types/test/sea-certify.test-d.ts @@ -0,0 +1,29 @@ +import Gun = require('../../index'); + +/*Documentation example*/ +async function certify(){ + const SEA = Gun.SEA; + const gun = Gun(); + const user = gun.user(); + var Alice = await SEA.pair() + var AliceHusband = await SEA.pair() + var Bob = await SEA.pair() + var Dave = await SEA.pair() + + // Alice wants to allow Bob and Dave to use write to her "inbox" and "stories" UNTIL TOMORROW + // On Alice's side: + var certificate = await SEA.certify([Bob.pub, Dave.pub], [{"*": "inbox", "+": "*"}, {"*": "stories"}], Alice, null, {expiry: Gun.state()+(60*60*24*1000), blacklist: 'blacklist'}) + + // Now on Bob/Dave's side, they can write to Alice's graph using gun.put: + gun.get('~'+Alice.pub).get('inbox').get('deeper'+Bob.pub).put('hello world', null, {opt: {cert: certificate}}) // {opt: {cert: certificate}} is how you use Certificate in gun.put + + // Now Alice wants to revoke access of Bob. She has TWO OPTIONS. OPTION 1 is to manage the blacklist by herself. + user.get('blacklist').get(Bob.pub).put(true) // OPTION 1: She directly manages her blacklist, in her graph. + + // OPTION 2: Alice could point the blacklist to her husband's graph: + user.get('blacklist').put({'#': '~'+AliceHusband.pub+'/blacklist'}) + + // Now on AliceHusband's side, HE can add Bob to his blacklist: + user.get('blacklist').get(Bob.pub).put(true) + +} \ No newline at end of file diff --git a/types/test/sea.test-d.ts b/types/test/sea.test-d.ts new file mode 100644 index 00000000..b3c10f82 --- /dev/null +++ b/types/test/sea.test-d.ts @@ -0,0 +1,28 @@ +import Gun = require('../../index'); +const SEA = Gun.SEA +;(async () => { +var pair = await SEA.pair(); +var enc = await SEA.encrypt('hello self', pair); +var data = await SEA.sign(enc, pair); +console.log(data); +var msg = await SEA.verify(data, pair.pub); +var dec = await SEA.decrypt(msg, pair); +var proof = await SEA.work(dec, pair); +var check = await SEA.work('hello self', pair); +console.log(dec); +console.log(proof === check); +// now let's share private data with someone: +var alice = await SEA.pair(); +var bob = await SEA.pair(); +var enc = await SEA.encrypt('shared data', await SEA.secret(bob.epub, alice)); +await SEA.decrypt(enc, await SEA.secret(alice.epub, bob)); +// `.secret` is Elliptic-curve Diffie–Hellman +// Bob allows Alice to write to part of his graph, he creates a certificate for Alice +var certificate = await SEA.certify(alice.pub, ["^AliceOnly.*"], bob) +// Alice logs in +const gun = Gun(); +await gun.user().auth(alice); +// and uses the certificate +await gun.get('~'+bob.pub).get('AliceOnly').get('do-not-tell-anyone').put(enc, null, {opt: {cert: certificate}}) +await gun.get('~'+bob.pub).get('AliceOnly').get('do-not-tell-anyone').once(console.log) // return 'enc' +})(); \ No newline at end of file diff --git a/types/types.d.ts b/types/types.d.ts deleted file mode 100644 index 37d1e440..00000000 --- a/types/types.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { IGunChainReference } from './chain'; - -export declare type ArrayOf = T extends Array ? U : never; - -export declare type DisallowArray = Exclude>; - -/** These types cannot be stored on Gun (functions and classes) */ -export declare type AlwaysDisallowedType = T extends (...args: any[]) => void ? never - : T extends { new(...args: any[]): any; } ? never - : AccessObject; - -export declare type AccessObject = T extends object ? { - [key in keyof T]: (AlwaysDisallowedType extends never ? never : AccessObject); -} : T; - -/** These types cannot be stored on Gun's root level */ -export declare type DisallowPrimitives = Open extends false ? T - : T extends string ? never - : T extends number ? never - : T extends boolean ? never - : T extends null ? never - : T extends undefined ? never - : T; - -export declare type Saveable = Partial | string | number | boolean | null | IGunChainReference; - -export declare type AckCallback = (ack: { - err: Error; - ok: any; -} | { - err: undefined; - ok: string; -}) => void; - -export declare type IGunCryptoKeyPair = Record<'pub' | 'priv' | 'epub' | 'epriv', string>; - -export interface IGunRecordNodeRawBase { - '#': string; -} - -export interface IGunRecordNodeRawExtra extends IGunRecordNodeRawBase { - '>': Record; -} - -export interface IGunRecordNodeRaw { - '_': IGunRecordNodeRawExtra; -} - -export declare type IGunRecordNode = { - [K in keyof DataType]: IGunRecordNodeRawBase; -} & IGunRecordNodeRaw; -export declare type IGunRecordData = DataType & IGunRecordNodeRaw;