///////////// // WeakSet // ///////////// export type LinvailWeakSetPrototype = { has: (this: LinvailWeakSet, key: K) => boolean; delete: (this: LinvailWeakSet, key: K) => boolean; add: ( this: LinvailWeakSet, key: K2, ) => LinvailWeakSet; }; export type LinvailWeakSet = { __brand: "LinvailWeakSet"; __key: K; } & LinvailWeakSetPrototype; export type LinvailWeakSetConstructor = { new (keys?: K[]): LinvailWeakSet; readonly prototype: LinvailWeakSetPrototype; }; ///////////// // WeakMap // ///////////// export type LinvailWeakMapPrototype = { has: (this: LinvailWeakMap, key: K) => boolean; delete: (this: LinvailWeakMap, key: K) => boolean; get: (this: LinvailWeakMap, key: K) => V | undefined; set: ( this: LinvailWeakMap, key: K2, val: V2, ) => LinvailWeakMap; }; export type LinvailWeakMap = { __brand: "LinvailWeakMap"; __key: K; __val: V; } & LinvailWeakMapPrototype; export type LinvailWeakMapConstructor = { new (entries?: [K, V][]): LinvailWeakMap; readonly prototype: LinvailWeakMapPrototype; }; ///////// // Set // ///////// export type LinvailSetPrototype = { has: (this: LinvailSet, key: K) => boolean; delete: (this: LinvailSet, key: K) => boolean; add: (this: LinvailSet, key: K2) => LinvailSet; clear: (this: LinvailSet) => undefined; forEach: ( this: LinvailSet, callback: (this: T, key: K, val: K, set: LinvailSet) => void, this_arg?: T, ) => undefined; getSize: (this: LinvailSet) => number; }; export type LinvailSet = { __brand: "LinvailSet"; __key: K; } & LinvailSetPrototype; export type LinvailSetConstructor = { new (keys?: K[]): LinvailSet; readonly prototype: LinvailSetPrototype; }; ///////// // Map // ///////// export type LinvailMapPrototype = { getSize: (this: LinvailMap) => number; has: (this: LinvailMap, key: K) => boolean; delete: (this: LinvailMap, key: K) => boolean; get: (this: LinvailMap, key: K) => V | undefined; set: ( this: LinvailMap, key: K2, val: V2, ) => LinvailMap; clear: (this: LinvailMap) => undefined; forEach: ( this: LinvailMap, callback: (this: T, key: K, val: V, map: LinvailMap) => void, this_arg?: T, ) => undefined; }; export type LinvailMap = { __brand: "LinvailMap"; __key: K; __val: V; } & LinvailMapPrototype; export type LinvailMapConstructor = { new (entries?: [K, V][]): LinvailMap; readonly prototype: LinvailMapPrototype; }; ///////////// // Library // ///////////// export type Library = { /** * Bypass the membrane and dump the content of the given value. */ dir: (value: unknown) => undefined; /** * Differentiate values based on their provenance. */ is: (value1: unknown, value2: unknown) => boolean; /** * Refresh the provenance of the given value. */ refresh: (value: unknown) => unknown; /** * Similar to ES6 `WeakSet` but provenance-sensitive. */ WeakSet: LinvailWeakSetConstructor; /** * Similar to ES6 `WeakMap` but provenance-sensitive. */ WeakMap: LinvailWeakMapConstructor; /** * Similar to ES6 `Set` but provenance-sensitive. */ Set: LinvailSetConstructor; /** * Similar to ES6 `Map` but provenance-sensitive. */ Map: LinvailMapConstructor; };