From 7864e20df567ab57cc05b982f72e1b76f24308ff Mon Sep 17 00:00:00 2001 From: Robert Kiel Date: Tue, 2 Feb 2021 06:11:32 +0100 Subject: [PATCH 1/4] add key type --- src/types.ts | 226 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 199 insertions(+), 27 deletions(-) diff --git a/src/types.ts b/src/types.ts index 267932b..55d3bad 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,26 +1,198 @@ -import type Key from './key' - -export type AwaitIterable = Iterable | AsyncIterable -export type Await = Promise | T +export type AwaitIterable = Iterable | AsyncIterable; +export type Await = Promise | T; export interface Pair { - key: Key - value: Uint8Array + key: Key; + value: Uint8Array; } /** * Options for async operations. */ export interface Options { - signal?: AbortSignal + signal?: AbortSignal; } export interface Batch { - put: (key: Key, value: Uint8Array) => void - delete: (key: Key) => void - commit: (options?: Options) => Promise + put: (key: Key, value: Uint8Array) => void; + delete: (key: Key) => void; + commit: (options?: Options) => Promise; } + +interface Key { + /** + * Convert to the string representation + * @returns {string} + */ + toString(encoding: "utf8" | "utf-8" | string): string; + /** + * Return the Uint8Array representation of the key + */ + uint8Array(): Uint8Array; + /** + * Return string representation of the key + */ + [Symbol.toStringTag]: string; + /** + * Cleanup the current key + */ + clean(): void; + /** + * Check if the given key is sorted lower than ourself. + */ + less(key: Key): boolean; + /** + * Returns the key with all parts in reversed order. + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse() + * // => Key('/Actor:JohnCleese/MontyPython/Comedy') + * ``` + */ + reverse(): Key; + /** + * Returns the `namespaces` making up this Key. + */ + namespaces(): string[]; + + /** Returns the "base" namespace of this key. + * + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').baseNamespace() + * // => 'Actor:JohnCleese' + * ``` + */ + baseNamespace(): string; + /** + * Returns the `list` representation of this key. + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').list() + * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese'] + * ``` + */ + list(): string[]; + + /** + * Returns the "type" of this key (value of last namespace). + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').type() + * // => 'Actor' + * ``` + */ + type(): string; + /** + * Returns the "name" of this key (field of last namespace). + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').name() + * // => 'JohnCleese' + * ``` + */ + name(): string; + /** + * Returns an "instance" of this type key (appends value to namespace). + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor').instance('JohnClesse') + * // => Key('/Comedy/MontyPython/Actor:JohnCleese') + * ``` + */ + instance(s: string): Key; + /** + * Returns the "path" of this key (parent + type). + * @example + * ```js + * new Key('/Comedy/MontyPython/Actor:JohnCleese').path() + * // => Key('/Comedy/MontyPython/Actor') + * ``` + */ + path(): Key; + /** + * Returns the `parent` Key of this Key. + * @example + * ```js + * new Key("/Comedy/MontyPython/Actor:JohnCleese").parent() + * // => Key("/Comedy/MontyPython") + * ``` + */ + parent(): Key; + /** + * Returns the `child` Key of this Key. + * @example + * ```js + * new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese')) + * // => Key('/Comedy/MontyPython/Actor:JohnCleese') + * ``` + */ + child(key: Key): Key; + /** + * Returns whether this key is a prefix of `other` + * @example + * ```js + * new Key('/Comedy').isAncestorOf('/Comedy/MontyPython') + * // => true + * ``` + */ + isAncestorOf(other: unknown): boolean; + /** + * Returns whether this key is a contains another as prefix. + * @example + * ```js + * new Key('/Comedy/MontyPython').isDecendantOf('/Comedy') + * // => true + * ``` + */ + isDecendantOf(other: unknown): boolean; + /** + * Checks if this key has only one namespace. + */ + isTopLevel(): boolean; + + /** + * Concats one or more Keys into one new Key. + */ + concat(...keys: Key[]): Key; +} + +interface KeyConstructor { + new (s: string | Uint8Array, clean?: boolean): Key; + /** + * Constructs a key out of a namespace array. + * + * @param {Array} list - The array of namespaces + * @returns {Key} + * + * @example + * ```js + * Key.withNamespaces(['one', 'two']) + * // => Key('/one/two') + * ``` + */ + withNamespaces(list: string[]): Key; + + /** + * Returns a randomly (uuid) generated key. + * + * @returns {Key} + * + * @example + * ```js + * Key.random() + * // => Key('/f98719ea086343f7b71f32ea9d9d521d') + * ``` + */ + random(): Key; + isKey(value: any): value is Key; +} + +declare var Key: KeyConstructor; + +export type { Key }; + export interface Datastore { - open: () => Promise - close: () => Promise + open: () => Promise; + close: () => Promise; /** * Store the passed value under the passed key * @@ -30,7 +202,7 @@ export interface Datastore { * await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) * ``` */ - put: (key: Key, val: Uint8Array, options?: Options) => Promise + put: (key: Key, val: Uint8Array, options?: Options) => Promise; /** * Retrieve the value stored under the given key * @@ -41,7 +213,7 @@ export interface Datastore { * // => got content: datastore * ``` */ - get: (key: Key, options?: Options) => Promise + get: (key: Key, options?: Options) => Promise; /** * Check for the existence of a value for the passed key * @@ -56,7 +228,7 @@ export interface Datastore { *} *``` */ - has: (key: Key, options?: Options) => Promise + has: (key: Key, options?: Options) => Promise; /** * Remove the record for the passed key * @@ -67,7 +239,7 @@ export interface Datastore { * console.log('deleted awesome content :(') * ``` */ - delete: (key: Key, options?: Options) => Promise + delete: (key: Key, options?: Options) => Promise; /** * Store the given key/value pairs * @@ -83,7 +255,7 @@ export interface Datastore { putMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable + ) => AsyncIterable; /** * Retrieve values for the passed keys * @@ -98,7 +270,7 @@ export interface Datastore { getMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable + ) => AsyncIterable; /** * Remove values for the passed keys * @@ -115,7 +287,7 @@ export interface Datastore { deleteMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable + ) => AsyncIterable; /** * This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. * @@ -131,7 +303,7 @@ export interface Datastore { * console.log('put 100 values') * ``` */ - batch: () => Batch + batch: () => Batch; /** * Query the store. * @@ -145,14 +317,14 @@ export interface Datastore { * console.log('ALL THE VALUES', list) * ``` */ - query: (q: Query, options?: Options) => AsyncIterable + query: (q: Query, options?: Options) => AsyncIterable; } export interface Query { - prefix?: string - filters?: Array<(item: Pair) => boolean> - orders?: Array<(items: Pair[]) => Await> - limit?: number - offset?: number - keysOnly?: boolean + prefix?: string; + filters?: Array<(item: Pair) => boolean>; + orders?: Array<(items: Pair[]) => Await>; + limit?: number; + offset?: number; + keysOnly?: boolean; } From f7e15e03b8e23ea0b1d050133d118564d1cf072c Mon Sep 17 00:00:00 2001 From: Robert Kiel Date: Tue, 2 Feb 2021 06:17:41 +0100 Subject: [PATCH 2/4] fix style --- src/types.ts | 111 ++++++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 50 deletions(-) diff --git a/src/types.ts b/src/types.ts index 55d3bad..ce4682d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,57 +1,59 @@ -export type AwaitIterable = Iterable | AsyncIterable; -export type Await = Promise | T; +export type AwaitIterable = Iterable | AsyncIterable +export type Await = Promise | T export interface Pair { - key: Key; - value: Uint8Array; + key: Key + value: Uint8Array } /** * Options for async operations. */ export interface Options { - signal?: AbortSignal; + signal?: AbortSignal } export interface Batch { - put: (key: Key, value: Uint8Array) => void; - delete: (key: Key) => void; - commit: (options?: Options) => Promise; + put: (key: Key, value: Uint8Array) => void + delete: (key: Key) => void + commit: (options?: Options) => Promise } interface Key { /** * Convert to the string representation + * * @returns {string} */ - toString(encoding: "utf8" | "utf-8" | string): string; + toString: (encoding: 'utf8' | 'utf-8' | string) => string /** * Return the Uint8Array representation of the key */ - uint8Array(): Uint8Array; + uint8Array: () => Uint8Array /** * Return string representation of the key */ - [Symbol.toStringTag]: string; + [Symbol.toStringTag]: string /** * Cleanup the current key */ - clean(): void; + clean: () => void /** * Check if the given key is sorted lower than ourself. */ - less(key: Key): boolean; + less: (key: Key) => boolean /** * Returns the key with all parts in reversed order. + * * @example * ```js * new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse() * // => Key('/Actor:JohnCleese/MontyPython/Comedy') * ``` */ - reverse(): Key; + reverse: () => Key /** * Returns the `namespaces` making up this Key. */ - namespaces(): string[]; + namespaces: () => string[] /** Returns the "base" namespace of this key. * @@ -61,102 +63,111 @@ interface Key { * // => 'Actor:JohnCleese' * ``` */ - baseNamespace(): string; + baseNamespace: () => string /** * Returns the `list` representation of this key. + * * @example * ```js * new Key('/Comedy/MontyPython/Actor:JohnCleese').list() * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese'] * ``` */ - list(): string[]; + list: () => string[] /** * Returns the "type" of this key (value of last namespace). + * * @example * ```js * new Key('/Comedy/MontyPython/Actor:JohnCleese').type() * // => 'Actor' * ``` */ - type(): string; + type: () => string /** * Returns the "name" of this key (field of last namespace). + * * @example * ```js * new Key('/Comedy/MontyPython/Actor:JohnCleese').name() * // => 'JohnCleese' * ``` */ - name(): string; + name: () => string /** * Returns an "instance" of this type key (appends value to namespace). + * * @example * ```js * new Key('/Comedy/MontyPython/Actor').instance('JohnClesse') * // => Key('/Comedy/MontyPython/Actor:JohnCleese') * ``` */ - instance(s: string): Key; + instance: (s: string) => Key /** * Returns the "path" of this key (parent + type). + * * @example * ```js * new Key('/Comedy/MontyPython/Actor:JohnCleese').path() * // => Key('/Comedy/MontyPython/Actor') * ``` */ - path(): Key; + path: () => Key /** * Returns the `parent` Key of this Key. + * * @example * ```js * new Key("/Comedy/MontyPython/Actor:JohnCleese").parent() * // => Key("/Comedy/MontyPython") * ``` */ - parent(): Key; + parent: () => Key /** * Returns the `child` Key of this Key. + * * @example * ```js * new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese')) * // => Key('/Comedy/MontyPython/Actor:JohnCleese') * ``` */ - child(key: Key): Key; + child: (key: Key) => Key /** * Returns whether this key is a prefix of `other` + * * @example * ```js * new Key('/Comedy').isAncestorOf('/Comedy/MontyPython') * // => true * ``` */ - isAncestorOf(other: unknown): boolean; + isAncestorOf: (other: unknown) => boolean /** * Returns whether this key is a contains another as prefix. + * * @example * ```js * new Key('/Comedy/MontyPython').isDecendantOf('/Comedy') * // => true * ``` */ - isDecendantOf(other: unknown): boolean; + isDecendantOf: (other: unknown) => boolean /** * Checks if this key has only one namespace. */ - isTopLevel(): boolean; + isTopLevel: () => boolean /** * Concats one or more Keys into one new Key. */ - concat(...keys: Key[]): Key; + concat: (...keys: Key[]) => Key } interface KeyConstructor { - new (s: string | Uint8Array, clean?: boolean): Key; + new (s: string | Uint8Array, clean?: boolean): Key /** * Constructs a key out of a namespace array. * @@ -169,7 +180,7 @@ interface KeyConstructor { * // => Key('/one/two') * ``` */ - withNamespaces(list: string[]): Key; + withNamespaces: (list: string[]) => Key /** * Returns a randomly (uuid) generated key. @@ -182,17 +193,17 @@ interface KeyConstructor { * // => Key('/f98719ea086343f7b71f32ea9d9d521d') * ``` */ - random(): Key; - isKey(value: any): value is Key; + random: () => Key + isKey: (value: any) => value is Key } -declare var Key: KeyConstructor; +declare var Key: KeyConstructor -export type { Key }; +export type { Key } export interface Datastore { - open: () => Promise; - close: () => Promise; + open: () => Promise + close: () => Promise /** * Store the passed value under the passed key * @@ -202,7 +213,7 @@ export interface Datastore { * await store.put([{ key: new Key('awesome'), value: new Uint8Array([0, 1, 2, 3]) }]) * ``` */ - put: (key: Key, val: Uint8Array, options?: Options) => Promise; + put: (key: Key, val: Uint8Array, options?: Options) => Promise /** * Retrieve the value stored under the given key * @@ -213,7 +224,7 @@ export interface Datastore { * // => got content: datastore * ``` */ - get: (key: Key, options?: Options) => Promise; + get: (key: Key, options?: Options) => Promise /** * Check for the existence of a value for the passed key * @@ -228,7 +239,7 @@ export interface Datastore { *} *``` */ - has: (key: Key, options?: Options) => Promise; + has: (key: Key, options?: Options) => Promise /** * Remove the record for the passed key * @@ -239,7 +250,7 @@ export interface Datastore { * console.log('deleted awesome content :(') * ``` */ - delete: (key: Key, options?: Options) => Promise; + delete: (key: Key, options?: Options) => Promise /** * Store the given key/value pairs * @@ -255,7 +266,7 @@ export interface Datastore { putMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable; + ) => AsyncIterable /** * Retrieve values for the passed keys * @@ -270,7 +281,7 @@ export interface Datastore { getMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable; + ) => AsyncIterable /** * Remove values for the passed keys * @@ -287,7 +298,7 @@ export interface Datastore { deleteMany: ( source: AwaitIterable, options?: Options - ) => AsyncIterable; + ) => AsyncIterable /** * This will return an object with which you can chain multiple operations together, with them only being executed on calling `commit`. * @@ -303,7 +314,7 @@ export interface Datastore { * console.log('put 100 values') * ``` */ - batch: () => Batch; + batch: () => Batch /** * Query the store. * @@ -317,14 +328,14 @@ export interface Datastore { * console.log('ALL THE VALUES', list) * ``` */ - query: (q: Query, options?: Options) => AsyncIterable; + query: (q: Query, options?: Options) => AsyncIterable } export interface Query { - prefix?: string; - filters?: Array<(item: Pair) => boolean>; - orders?: Array<(items: Pair[]) => Await>; - limit?: number; - offset?: number; - keysOnly?: boolean; + prefix?: string + filters?: Array<(item: Pair) => boolean> + orders?: Array<(items: Pair[]) => Await> + limit?: number + offset?: number + keysOnly?: boolean } From ea2b19d412124008e36d0d15ba9663bfea21f860 Mon Sep 17 00:00:00 2001 From: Robert Kiel Date: Tue, 2 Feb 2021 10:55:12 +0100 Subject: [PATCH 3/4] workaround --- src/types.ts | 354 ++++++++++++++++++++++++++------------------------- 1 file changed, 179 insertions(+), 175 deletions(-) diff --git a/src/types.ts b/src/types.ts index ce4682d..c4e5351 100644 --- a/src/types.ts +++ b/src/types.ts @@ -17,187 +17,191 @@ export interface Batch { commit: (options?: Options) => Promise } -interface Key { - /** - * Convert to the string representation - * - * @returns {string} - */ - toString: (encoding: 'utf8' | 'utf-8' | string) => string - /** - * Return the Uint8Array representation of the key - */ - uint8Array: () => Uint8Array - /** - * Return string representation of the key - */ - [Symbol.toStringTag]: string - /** - * Cleanup the current key - */ - clean: () => void - /** - * Check if the given key is sorted lower than ourself. - */ - less: (key: Key) => boolean - /** - * Returns the key with all parts in reversed order. - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse() - * // => Key('/Actor:JohnCleese/MontyPython/Comedy') - * ``` - */ - reverse: () => Key - /** - * Returns the `namespaces` making up this Key. - */ - namespaces: () => string[] +// interface Key { +// _buf: Uint8Array - /** Returns the "base" namespace of this key. - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').baseNamespace() - * // => 'Actor:JohnCleese' - * ``` - */ - baseNamespace: () => string - /** - * Returns the `list` representation of this key. - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').list() - * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese'] - * ``` - */ - list: () => string[] +// /** +// * Convert to the string representation +// * +// * @returns {string} +// */ +// toString: (encoding: 'utf8' | 'utf-8' | string) => string +// /** +// * Return the Uint8Array representation of the key +// */ +// uint8Array: () => Uint8Array +// /** +// * Return string representation of the key +// */ +// [Symbol.toStringTag]: string +// /** +// * Cleanup the current key +// */ +// clean: () => void +// /** +// * Check if the given key is sorted lower than ourself. +// */ +// less: (key: Key) => boolean +// /** +// * Returns the key with all parts in reversed order. +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse() +// * // => Key('/Actor:JohnCleese/MontyPython/Comedy') +// * ``` +// */ +// reverse: () => Key +// /** +// * Returns the `namespaces` making up this Key. +// */ +// namespaces: () => string[] - /** - * Returns the "type" of this key (value of last namespace). - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').type() - * // => 'Actor' - * ``` - */ - type: () => string - /** - * Returns the "name" of this key (field of last namespace). - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').name() - * // => 'JohnCleese' - * ``` - */ - name: () => string - /** - * Returns an "instance" of this type key (appends value to namespace). - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor').instance('JohnClesse') - * // => Key('/Comedy/MontyPython/Actor:JohnCleese') - * ``` - */ - instance: (s: string) => Key - /** - * Returns the "path" of this key (parent + type). - * - * @example - * ```js - * new Key('/Comedy/MontyPython/Actor:JohnCleese').path() - * // => Key('/Comedy/MontyPython/Actor') - * ``` - */ - path: () => Key - /** - * Returns the `parent` Key of this Key. - * - * @example - * ```js - * new Key("/Comedy/MontyPython/Actor:JohnCleese").parent() - * // => Key("/Comedy/MontyPython") - * ``` - */ - parent: () => Key - /** - * Returns the `child` Key of this Key. - * - * @example - * ```js - * new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese')) - * // => Key('/Comedy/MontyPython/Actor:JohnCleese') - * ``` - */ - child: (key: Key) => Key - /** - * Returns whether this key is a prefix of `other` - * - * @example - * ```js - * new Key('/Comedy').isAncestorOf('/Comedy/MontyPython') - * // => true - * ``` - */ - isAncestorOf: (other: unknown) => boolean - /** - * Returns whether this key is a contains another as prefix. - * - * @example - * ```js - * new Key('/Comedy/MontyPython').isDecendantOf('/Comedy') - * // => true - * ``` - */ - isDecendantOf: (other: unknown) => boolean - /** - * Checks if this key has only one namespace. - */ - isTopLevel: () => boolean +// /** Returns the "base" namespace of this key. +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').baseNamespace() +// * // => 'Actor:JohnCleese' +// * ``` +// */ +// baseNamespace: () => string +// /** +// * Returns the `list` representation of this key. +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').list() +// * // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese'] +// * ``` +// */ +// list: () => string[] - /** - * Concats one or more Keys into one new Key. - */ - concat: (...keys: Key[]) => Key -} +// /** +// * Returns the "type" of this key (value of last namespace). +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').type() +// * // => 'Actor' +// * ``` +// */ +// type: () => string +// /** +// * Returns the "name" of this key (field of last namespace). +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').name() +// * // => 'JohnCleese' +// * ``` +// */ +// name: () => string +// /** +// * Returns an "instance" of this type key (appends value to namespace). +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor').instance('JohnClesse') +// * // => Key('/Comedy/MontyPython/Actor:JohnCleese') +// * ``` +// */ +// instance: (s: string) => Key +// /** +// * Returns the "path" of this key (parent + type). +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython/Actor:JohnCleese').path() +// * // => Key('/Comedy/MontyPython/Actor') +// * ``` +// */ +// path: () => Key +// /** +// * Returns the `parent` Key of this Key. +// * +// * @example +// * ```js +// * new Key("/Comedy/MontyPython/Actor:JohnCleese").parent() +// * // => Key("/Comedy/MontyPython") +// * ``` +// */ +// parent: () => Key +// /** +// * Returns the `child` Key of this Key. +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese')) +// * // => Key('/Comedy/MontyPython/Actor:JohnCleese') +// * ``` +// */ +// child: (key: Key) => Key +// /** +// * Returns whether this key is a prefix of `other` +// * +// * @example +// * ```js +// * new Key('/Comedy').isAncestorOf('/Comedy/MontyPython') +// * // => true +// * ``` +// */ +// isAncestorOf: (other: unknown) => boolean +// /** +// * Returns whether this key is a contains another as prefix. +// * +// * @example +// * ```js +// * new Key('/Comedy/MontyPython').isDecendantOf('/Comedy') +// * // => true +// * ``` +// */ +// isDecendantOf: (other: unknown) => boolean +// /** +// * Checks if this key has only one namespace. +// */ +// isTopLevel: () => boolean -interface KeyConstructor { - new (s: string | Uint8Array, clean?: boolean): Key - /** - * Constructs a key out of a namespace array. - * - * @param {Array} list - The array of namespaces - * @returns {Key} - * - * @example - * ```js - * Key.withNamespaces(['one', 'two']) - * // => Key('/one/two') - * ``` - */ - withNamespaces: (list: string[]) => Key +// /** +// * Concats one or more Keys into one new Key. +// */ +// concat: (...keys: Key[]) => Key +// } - /** - * Returns a randomly (uuid) generated key. - * - * @returns {Key} - * - * @example - * ```js - * Key.random() - * // => Key('/f98719ea086343f7b71f32ea9d9d521d') - * ``` - */ - random: () => Key - isKey: (value: any) => value is Key -} +// interface KeyConstructor { +// new (s: string | Uint8Array, clean?: boolean): Key +// /** +// * Constructs a key out of a namespace array. +// * +// * @param {Array} list - The array of namespaces +// * @returns {Key} +// * +// * @example +// * ```js +// * Key.withNamespaces(['one', 'two']) +// * // => Key('/one/two') +// * ``` +// */ +// withNamespaces: (list: string[]) => Key + +// /** +// * Returns a randomly (uuid) generated key. +// * +// * @returns {Key} +// * +// * @example +// * ```js +// * Key.random() +// * // => Key('/f98719ea086343f7b71f32ea9d9d521d') +// * ``` +// */ +// random: () => Key +// isKey: (value: any) => value is Key +// } + +// declare var Key: KeyConstructor -declare var Key: KeyConstructor +type Key = any export type { Key } From 6e8eb3a7d185915eefc3e4126cf311a45a0b6792 Mon Sep 17 00:00:00 2001 From: Robert Kiel Date: Tue, 2 Feb 2021 11:01:43 +0100 Subject: [PATCH 4/4] finish workaround --- src/key.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/key.js b/src/key.js index 9ebb86f..ccd4d7c 100644 --- a/src/key.js +++ b/src/key.js @@ -25,6 +25,10 @@ const pathSep = pathSepB[0] * - `new Key('/Comedy/MontyPython/Sketch:CheeseShop/Character:Mousebender')` * */ +/** + * @class Key + * @implements {Key} + */ class Key { /** * @param {string | Uint8Array} s