Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Add missing Key type #68

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
191 changes: 189 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import type Key from './key'

export type AwaitIterable<T> = Iterable<T> | AsyncIterable<T>
export type Await<T> = Promise<T> | T
export interface Pair {
Expand All @@ -18,6 +16,195 @@ export interface Batch {
delete: (key: Key) => void
commit: (options?: Options) => Promise<void>
}

// interface Key {
// _buf: Uint8Array

// /**
// * 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<string>} 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

type Key = any

export type { Key }

export interface Datastore {
open: () => Promise<void>
close: () => Promise<void>
Expand Down