@tanstack/db 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -0
- package/dist/cjs/SortedMap.cjs +140 -0
- package/dist/cjs/SortedMap.cjs.map +1 -0
- package/dist/cjs/SortedMap.d.cts +91 -0
- package/dist/cjs/collection.cjs +597 -0
- package/dist/cjs/collection.cjs.map +1 -0
- package/dist/cjs/collection.d.cts +176 -0
- package/dist/cjs/deferred.cjs +25 -0
- package/dist/cjs/deferred.cjs.map +1 -0
- package/dist/cjs/deferred.d.cts +20 -0
- package/dist/cjs/errors.cjs +10 -0
- package/dist/cjs/errors.cjs.map +1 -0
- package/dist/cjs/errors.d.cts +3 -0
- package/dist/cjs/index.cjs +33 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +9 -0
- package/dist/cjs/proxy.cjs +654 -0
- package/dist/cjs/proxy.cjs.map +1 -0
- package/dist/cjs/proxy.d.cts +59 -0
- package/dist/cjs/query/compiled-query.cjs +162 -0
- package/dist/cjs/query/compiled-query.cjs.map +1 -0
- package/dist/cjs/query/compiled-query.d.cts +22 -0
- package/dist/cjs/query/evaluators.cjs +146 -0
- package/dist/cjs/query/evaluators.cjs.map +1 -0
- package/dist/cjs/query/evaluators.d.cts +9 -0
- package/dist/cjs/query/extractors.cjs +122 -0
- package/dist/cjs/query/extractors.cjs.map +1 -0
- package/dist/cjs/query/extractors.d.cts +22 -0
- package/dist/cjs/query/functions.cjs +152 -0
- package/dist/cjs/query/functions.cjs.map +1 -0
- package/dist/cjs/query/functions.d.cts +21 -0
- package/dist/cjs/query/group-by.cjs +91 -0
- package/dist/cjs/query/group-by.cjs.map +1 -0
- package/dist/cjs/query/group-by.d.cts +40 -0
- package/dist/cjs/query/index.d.cts +5 -0
- package/dist/cjs/query/joins.cjs +155 -0
- package/dist/cjs/query/joins.cjs.map +1 -0
- package/dist/cjs/query/joins.d.cts +14 -0
- package/dist/cjs/query/key-by.cjs +43 -0
- package/dist/cjs/query/key-by.cjs.map +1 -0
- package/dist/cjs/query/key-by.d.cts +3 -0
- package/dist/cjs/query/order-by.cjs +229 -0
- package/dist/cjs/query/order-by.cjs.map +1 -0
- package/dist/cjs/query/order-by.d.cts +3 -0
- package/dist/cjs/query/pipeline-compiler.cjs +94 -0
- package/dist/cjs/query/pipeline-compiler.cjs.map +1 -0
- package/dist/cjs/query/pipeline-compiler.d.cts +9 -0
- package/dist/cjs/query/query-builder.cjs +314 -0
- package/dist/cjs/query/query-builder.cjs.map +1 -0
- package/dist/cjs/query/query-builder.d.cts +219 -0
- package/dist/cjs/query/schema.d.cts +98 -0
- package/dist/cjs/query/select.cjs +107 -0
- package/dist/cjs/query/select.cjs.map +1 -0
- package/dist/cjs/query/select.d.cts +3 -0
- package/dist/cjs/query/types.d.cts +188 -0
- package/dist/cjs/query/utils.cjs +154 -0
- package/dist/cjs/query/utils.cjs.map +1 -0
- package/dist/cjs/query/utils.d.cts +37 -0
- package/dist/cjs/transactions.cjs +137 -0
- package/dist/cjs/transactions.cjs.map +1 -0
- package/dist/cjs/transactions.d.cts +27 -0
- package/dist/cjs/types.d.cts +94 -0
- package/dist/cjs/utils.cjs +17 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +3 -0
- package/dist/esm/SortedMap.d.ts +91 -0
- package/dist/esm/SortedMap.js +140 -0
- package/dist/esm/SortedMap.js.map +1 -0
- package/dist/esm/collection.d.ts +176 -0
- package/dist/esm/collection.js +597 -0
- package/dist/esm/collection.js.map +1 -0
- package/dist/esm/deferred.d.ts +20 -0
- package/dist/esm/deferred.js +25 -0
- package/dist/esm/deferred.js.map +1 -0
- package/dist/esm/errors.d.ts +3 -0
- package/dist/esm/errors.js +10 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +33 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/proxy.d.ts +59 -0
- package/dist/esm/proxy.js +654 -0
- package/dist/esm/proxy.js.map +1 -0
- package/dist/esm/query/compiled-query.d.ts +22 -0
- package/dist/esm/query/compiled-query.js +162 -0
- package/dist/esm/query/compiled-query.js.map +1 -0
- package/dist/esm/query/evaluators.d.ts +9 -0
- package/dist/esm/query/evaluators.js +146 -0
- package/dist/esm/query/evaluators.js.map +1 -0
- package/dist/esm/query/extractors.d.ts +22 -0
- package/dist/esm/query/extractors.js +122 -0
- package/dist/esm/query/extractors.js.map +1 -0
- package/dist/esm/query/functions.d.ts +21 -0
- package/dist/esm/query/functions.js +152 -0
- package/dist/esm/query/functions.js.map +1 -0
- package/dist/esm/query/group-by.d.ts +40 -0
- package/dist/esm/query/group-by.js +91 -0
- package/dist/esm/query/group-by.js.map +1 -0
- package/dist/esm/query/index.d.ts +5 -0
- package/dist/esm/query/joins.d.ts +14 -0
- package/dist/esm/query/joins.js +155 -0
- package/dist/esm/query/joins.js.map +1 -0
- package/dist/esm/query/key-by.d.ts +3 -0
- package/dist/esm/query/key-by.js +43 -0
- package/dist/esm/query/key-by.js.map +1 -0
- package/dist/esm/query/order-by.d.ts +3 -0
- package/dist/esm/query/order-by.js +229 -0
- package/dist/esm/query/order-by.js.map +1 -0
- package/dist/esm/query/pipeline-compiler.d.ts +9 -0
- package/dist/esm/query/pipeline-compiler.js +94 -0
- package/dist/esm/query/pipeline-compiler.js.map +1 -0
- package/dist/esm/query/query-builder.d.ts +219 -0
- package/dist/esm/query/query-builder.js +314 -0
- package/dist/esm/query/query-builder.js.map +1 -0
- package/dist/esm/query/schema.d.ts +98 -0
- package/dist/esm/query/select.d.ts +3 -0
- package/dist/esm/query/select.js +107 -0
- package/dist/esm/query/select.js.map +1 -0
- package/dist/esm/query/types.d.ts +188 -0
- package/dist/esm/query/utils.d.ts +37 -0
- package/dist/esm/query/utils.js +154 -0
- package/dist/esm/query/utils.js.map +1 -0
- package/dist/esm/transactions.d.ts +27 -0
- package/dist/esm/transactions.js +137 -0
- package/dist/esm/transactions.js.map +1 -0
- package/dist/esm/types.d.ts +94 -0
- package/dist/esm/utils.d.ts +3 -0
- package/dist/esm/utils.js +17 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +57 -0
- package/src/SortedMap.ts +163 -0
- package/src/collection.ts +919 -0
- package/src/deferred.ts +47 -0
- package/src/errors.ts +6 -0
- package/src/index.ts +12 -0
- package/src/proxy.ts +1104 -0
- package/src/query/compiled-query.ts +193 -0
- package/src/query/evaluators.ts +222 -0
- package/src/query/extractors.ts +211 -0
- package/src/query/functions.ts +297 -0
- package/src/query/group-by.ts +137 -0
- package/src/query/index.ts +5 -0
- package/src/query/joins.ts +247 -0
- package/src/query/key-by.ts +61 -0
- package/src/query/order-by.ts +312 -0
- package/src/query/pipeline-compiler.ts +152 -0
- package/src/query/query-builder.ts +898 -0
- package/src/query/schema.ts +255 -0
- package/src/query/select.ts +173 -0
- package/src/query/types.ts +417 -0
- package/src/query/utils.ts +245 -0
- package/src/transactions.ts +198 -0
- package/src/types.ts +125 -0
- package/src/utils.ts +15 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Collection } from './collection.js';
|
|
2
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
3
|
+
import { Transaction } from './transactions.js';
|
|
4
|
+
export type TransactionState = `pending` | `persisting` | `completed` | `failed`;
|
|
5
|
+
/**
|
|
6
|
+
* Represents a pending mutation within a transaction
|
|
7
|
+
* Contains information about the original and modified data, as well as metadata
|
|
8
|
+
*/
|
|
9
|
+
export interface PendingMutation<T extends object = Record<string, unknown>> {
|
|
10
|
+
mutationId: string;
|
|
11
|
+
original: Record<string, unknown>;
|
|
12
|
+
modified: Record<string, unknown>;
|
|
13
|
+
changes: Record<string, unknown>;
|
|
14
|
+
key: string;
|
|
15
|
+
type: OperationType;
|
|
16
|
+
metadata: unknown;
|
|
17
|
+
syncMetadata: Record<string, unknown>;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
collection: Collection<T>;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Configuration options for creating a new transaction
|
|
24
|
+
*/
|
|
25
|
+
export type MutationFnParams = {
|
|
26
|
+
transaction: Transaction;
|
|
27
|
+
};
|
|
28
|
+
export type MutationFn = (params: MutationFnParams) => Promise<any>;
|
|
29
|
+
export interface TransactionConfig {
|
|
30
|
+
/** Unique identifier for the transaction */
|
|
31
|
+
id?: string;
|
|
32
|
+
autoCommit?: boolean;
|
|
33
|
+
mutationFn: MutationFn;
|
|
34
|
+
/** Custom metadata to associate with the transaction */
|
|
35
|
+
metadata?: Record<string, unknown>;
|
|
36
|
+
}
|
|
37
|
+
export type { Transaction };
|
|
38
|
+
type Value<TExtensions = never> = string | number | boolean | bigint | null | TExtensions | Array<Value<TExtensions>> | {
|
|
39
|
+
[key: string]: Value<TExtensions>;
|
|
40
|
+
};
|
|
41
|
+
export type Row<TExtensions = never> = Record<string, Value<TExtensions>>;
|
|
42
|
+
export type OperationType = `insert` | `update` | `delete`;
|
|
43
|
+
export interface SyncConfig<T extends object = Record<string, unknown>> {
|
|
44
|
+
sync: (params: {
|
|
45
|
+
collection: Collection<T>;
|
|
46
|
+
begin: () => void;
|
|
47
|
+
write: (message: ChangeMessage<T>) => void;
|
|
48
|
+
commit: () => void;
|
|
49
|
+
}) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Get the sync metadata for insert operations
|
|
52
|
+
* @returns Record containing primaryKey and relation information
|
|
53
|
+
*/
|
|
54
|
+
getSyncMetadata?: () => Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
export interface ChangeMessage<T extends object = Record<string, unknown>> {
|
|
57
|
+
key: string;
|
|
58
|
+
value: T;
|
|
59
|
+
previousValue?: T;
|
|
60
|
+
type: OperationType;
|
|
61
|
+
metadata?: Record<string, unknown>;
|
|
62
|
+
}
|
|
63
|
+
export interface OptimisticChangeMessage<T extends object = Record<string, unknown>> extends ChangeMessage<T> {
|
|
64
|
+
isActive?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The Standard Schema interface.
|
|
68
|
+
* This follows the standard-schema specification: https://github.com/standard-schema/standard-schema
|
|
69
|
+
*/
|
|
70
|
+
export type StandardSchema<T> = StandardSchemaV1 & {
|
|
71
|
+
"~standard": {
|
|
72
|
+
types?: {
|
|
73
|
+
input: T;
|
|
74
|
+
output: T;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Type alias for StandardSchema
|
|
80
|
+
*/
|
|
81
|
+
export type StandardSchemaAlias<T = unknown> = StandardSchema<T>;
|
|
82
|
+
export interface OperationConfig {
|
|
83
|
+
metadata?: Record<string, unknown>;
|
|
84
|
+
}
|
|
85
|
+
export interface InsertConfig {
|
|
86
|
+
key?: string | Array<string | undefined>;
|
|
87
|
+
metadata?: Record<string, unknown>;
|
|
88
|
+
}
|
|
89
|
+
export interface CollectionConfig<T extends object = Record<string, unknown>> {
|
|
90
|
+
id: string;
|
|
91
|
+
sync: SyncConfig<T>;
|
|
92
|
+
schema?: StandardSchema<T>;
|
|
93
|
+
}
|
|
94
|
+
export type ChangesPayload<T extends object = Record<string, unknown>> = Array<ChangeMessage<T>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
function getLockedObjects() {
|
|
2
|
+
return /* @__PURE__ */ new Set();
|
|
3
|
+
}
|
|
4
|
+
let globalVersion = 0;
|
|
5
|
+
function getGlobalVersion() {
|
|
6
|
+
return globalVersion;
|
|
7
|
+
}
|
|
8
|
+
function advanceGlobalVersion() {
|
|
9
|
+
console.log(`==== advancing global version`, globalVersion + 1);
|
|
10
|
+
return globalVersion++;
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
advanceGlobalVersion,
|
|
14
|
+
getGlobalVersion,
|
|
15
|
+
getLockedObjects
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function getLockedObjects(): Set<string> {\n // Stub implementation that returns an empty Set\n return new Set()\n}\n\nlet globalVersion = 0\n\nexport function getGlobalVersion(): number {\n return globalVersion\n}\n\nexport function advanceGlobalVersion(): number {\n console.log(`==== advancing global version`, globalVersion + 1)\n return globalVersion++\n}\n"],"names":[],"mappings":"AAAO,SAAS,mBAAgC;AAE9C,6BAAW,IAAI;AACjB;AAEA,IAAI,gBAAgB;AAEb,SAAS,mBAA2B;AAClC,SAAA;AACT;AAEO,SAAS,uBAA+B;AACrC,UAAA,IAAI,iCAAiC,gBAAgB,CAAC;AACvD,SAAA;AACT;"}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tanstack/db",
|
|
3
|
+
"description": "A reactive client store for building super fast apps on sync",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@electric-sql/d2ts": "^0.1.5",
|
|
7
|
+
"@standard-schema/spec": "^1.0.0",
|
|
8
|
+
"@tanstack/store": "^0.7.0"
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@vitest/coverage-istanbul": "^3.0.9"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/esm/index.d.ts",
|
|
17
|
+
"default": "./dist/esm/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/cjs/index.d.cts",
|
|
21
|
+
"default": "./dist/cjs/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"main": "dist/cjs/index.cjs",
|
|
31
|
+
"module": "dist/esm/index.js",
|
|
32
|
+
"packageManager": "pnpm@10.5.2",
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"typescript": ">=4.7"
|
|
35
|
+
},
|
|
36
|
+
"author": "Kyle Mathews",
|
|
37
|
+
"license": "MIT",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/TanStack/db.git",
|
|
41
|
+
"directory": "packages/db"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://tanstack.com/optimistic",
|
|
44
|
+
"keywords": [
|
|
45
|
+
"optimistic",
|
|
46
|
+
"typescript"
|
|
47
|
+
],
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "vite build",
|
|
50
|
+
"dev": "vite build --watch",
|
|
51
|
+
"lint": "eslint . --fix",
|
|
52
|
+
"test": "npx vitest --run"
|
|
53
|
+
},
|
|
54
|
+
"sideEffects": false,
|
|
55
|
+
"type": "module",
|
|
56
|
+
"types": "dist/esm/index.d.ts"
|
|
57
|
+
}
|
package/src/SortedMap.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Map implementation that keeps its entries sorted based on a comparator function
|
|
3
|
+
* @template TKey - The type of keys in the map
|
|
4
|
+
* @template TValue - The type of values in the map
|
|
5
|
+
*/
|
|
6
|
+
export class SortedMap<TKey, TValue> {
|
|
7
|
+
private map: Map<TKey, TValue>
|
|
8
|
+
private sortedKeys: Array<TKey>
|
|
9
|
+
private comparator: (a: TValue, b: TValue) => number
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new SortedMap instance
|
|
13
|
+
*
|
|
14
|
+
* @param comparator - Optional function to compare values for sorting
|
|
15
|
+
*/
|
|
16
|
+
constructor(comparator?: (a: TValue, b: TValue) => number) {
|
|
17
|
+
this.map = new Map<TKey, TValue>()
|
|
18
|
+
this.sortedKeys = []
|
|
19
|
+
this.comparator = comparator || this.defaultComparator
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Default comparator function used when none is provided
|
|
24
|
+
*
|
|
25
|
+
* @param a - First value to compare
|
|
26
|
+
* @param b - Second value to compare
|
|
27
|
+
* @returns -1 if a < b, 1 if a > b, 0 if equal
|
|
28
|
+
*/
|
|
29
|
+
private defaultComparator(a: TValue, b: TValue): number {
|
|
30
|
+
if (a < b) return -1
|
|
31
|
+
if (a > b) return 1
|
|
32
|
+
return 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Sets a key-value pair in the map and maintains sort order
|
|
37
|
+
*
|
|
38
|
+
* @param key - The key to set
|
|
39
|
+
* @param value - The value to associate with the key
|
|
40
|
+
* @returns This SortedMap instance for chaining
|
|
41
|
+
*/
|
|
42
|
+
set(key: TKey, value: TValue): this {
|
|
43
|
+
this.map.set(key, value)
|
|
44
|
+
|
|
45
|
+
if (!this.sortedKeys.includes(key)) {
|
|
46
|
+
this.sortedKeys.push(key)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Re-sort keys based on values
|
|
50
|
+
this.sortedKeys.sort((a, b) => {
|
|
51
|
+
const valueA = this.map.get(a)!
|
|
52
|
+
const valueB = this.map.get(b)!
|
|
53
|
+
return this.comparator(valueA, valueB)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
return this
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Gets a value by its key
|
|
61
|
+
*
|
|
62
|
+
* @param key - The key to look up
|
|
63
|
+
* @returns The value associated with the key, or undefined if not found
|
|
64
|
+
*/
|
|
65
|
+
get(key: TKey): TValue | undefined {
|
|
66
|
+
return this.map.get(key)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Removes a key-value pair from the map
|
|
71
|
+
*
|
|
72
|
+
* @param key - The key to remove
|
|
73
|
+
* @returns True if the key was found and removed, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
delete(key: TKey): boolean {
|
|
76
|
+
if (this.map.delete(key)) {
|
|
77
|
+
const index = this.sortedKeys.indexOf(key)
|
|
78
|
+
this.sortedKeys.splice(index, 1)
|
|
79
|
+
return true
|
|
80
|
+
}
|
|
81
|
+
return false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Checks if a key exists in the map
|
|
86
|
+
*
|
|
87
|
+
* @param key - The key to check
|
|
88
|
+
* @returns True if the key exists, false otherwise
|
|
89
|
+
*/
|
|
90
|
+
has(key: TKey): boolean {
|
|
91
|
+
return this.map.has(key)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Removes all key-value pairs from the map
|
|
96
|
+
*/
|
|
97
|
+
clear(): void {
|
|
98
|
+
this.map.clear()
|
|
99
|
+
this.sortedKeys = []
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Gets the number of key-value pairs in the map
|
|
104
|
+
*/
|
|
105
|
+
get size(): number {
|
|
106
|
+
return this.map.size
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Default iterator that returns entries in sorted order
|
|
111
|
+
*
|
|
112
|
+
* @returns An iterator for the map's entries
|
|
113
|
+
*/
|
|
114
|
+
*[Symbol.iterator](): IterableIterator<[TKey, TValue]> {
|
|
115
|
+
for (const key of this.sortedKeys) {
|
|
116
|
+
yield [key, this.map.get(key)!] as [TKey, TValue]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns an iterator for the map's entries in sorted order
|
|
122
|
+
*
|
|
123
|
+
* @returns An iterator for the map's entries
|
|
124
|
+
*/
|
|
125
|
+
entries(): IterableIterator<[TKey, TValue]> {
|
|
126
|
+
return this[Symbol.iterator]()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Returns an iterator for the map's keys in sorted order
|
|
131
|
+
*
|
|
132
|
+
* @returns An iterator for the map's keys
|
|
133
|
+
*/
|
|
134
|
+
keys(): IterableIterator<TKey> {
|
|
135
|
+
return this.sortedKeys[Symbol.iterator]()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns an iterator for the map's values in sorted order
|
|
140
|
+
*
|
|
141
|
+
* @returns An iterator for the map's values
|
|
142
|
+
*/
|
|
143
|
+
values(): IterableIterator<TValue> {
|
|
144
|
+
return function* (this: SortedMap<TKey, TValue>) {
|
|
145
|
+
for (const key of this.sortedKeys) {
|
|
146
|
+
yield this.map.get(key)!
|
|
147
|
+
}
|
|
148
|
+
}.call(this)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Executes a callback function for each key-value pair in the map in sorted order
|
|
153
|
+
*
|
|
154
|
+
* @param callbackfn - Function to execute for each entry
|
|
155
|
+
*/
|
|
156
|
+
forEach(
|
|
157
|
+
callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void
|
|
158
|
+
): void {
|
|
159
|
+
for (const key of this.sortedKeys) {
|
|
160
|
+
callbackfn(this.map.get(key)!, key, this.map)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|