mcbe-leveldb 1.10.2 → 1.11.0

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/Changelog.md CHANGED
@@ -1,3 +1,9 @@
1
+ # v1.11.0
2
+
3
+ ## Additions
4
+
5
+ - Added a generator variant of the `getKeysOfTypes` function: `getKeysOfTypesG`.
6
+
1
7
  # v1.10.2
2
8
 
3
9
  ## Fixes
package/DBUtils.d.ts CHANGED
@@ -43,6 +43,39 @@ export declare function getKeysOfTypes<T extends DBEntryContentType[] | readonly
43
43
  export declare function getKeysOfTypes<T extends DBEntryContentType[] | readonly DBEntryContentType[], TArrayBuffer extends ArrayBufferLike>(dbKeys: Buffer<TArrayBuffer>[], types: T): {
44
44
  [key in T[number]]: Buffer<TArrayBuffer>[];
45
45
  };
46
+ /**
47
+ * Gets the keys from the LevelDB with one of the specified content types.
48
+ *
49
+ * @template T The content types to look for.
50
+ * @param db The LevelDB. Should match the type of the {@link LevelDB} class from the {@link https://www.npmjs.com/package/@8crafter/leveldb-zlib | @8crafter/leveldb-zlib} package. It does not have to be the one from that package, as long as the types match.
51
+ * @param types The {@link DBEntryContentType | content types} to look for.
52
+ * @returns An object mapping each of the specified content types to the keys from the LevelDB with that content type, the keys are in Buffer format, this is because some keys contain binary data like chunk indices.
53
+ */
54
+ export declare function getKeysOfTypesG<T extends DBEntryContentType[] | readonly DBEntryContentType[]>(db: LevelDB, types: T): AsyncGenerator<{
55
+ count: number;
56
+ results: {
57
+ [key in T[number]]: Buffer<ArrayBuffer>[];
58
+ };
59
+ }, {
60
+ [key in T[number]]: Buffer<ArrayBuffer>[];
61
+ }>;
62
+ /**
63
+ * Gets the keys from the list of LevelDB keys with one of the specified content types.
64
+ *
65
+ * @template T The content types to look for.
66
+ * @template TArrayBuffer The type of the buffers.
67
+ * @param dbKeys The LevelDB keys. Should be an array of Buffers.
68
+ * @param types The {@link DBEntryContentType | content types} to look for.
69
+ * @returns An object mapping each of the specified content types to the keys from the provided LevelDB keys array with that content type, the keys are in Buffer format, this is because some keys contain binary data like chunk indices.
70
+ */
71
+ export declare function getKeysOfTypesG<T extends DBEntryContentType[] | readonly DBEntryContentType[], TArrayBuffer extends ArrayBufferLike>(dbKeys: Buffer<TArrayBuffer>[], types: T): Generator<{
72
+ count: number;
73
+ results: {
74
+ [key in T[number]]: Buffer<TArrayBuffer>[];
75
+ };
76
+ }, {
77
+ [key in T[number]]: Buffer<TArrayBuffer>[];
78
+ }>;
46
79
  /**
47
80
  * Gets a player's name from their UUID.
48
81
  *
package/DBUtils.js CHANGED
@@ -35,6 +35,37 @@ export function getKeysOfTypes(dbOrDBKeys, types) {
35
35
  resolve(results);
36
36
  })());
37
37
  }
38
+ export function getKeysOfTypesG(dbOrDBKeys, types) {
39
+ const results = {};
40
+ var count = 0;
41
+ types.forEach((contentType) => {
42
+ results[contentType] = [];
43
+ });
44
+ if (Array.isArray(dbOrDBKeys)) {
45
+ return (function* getKeysOfTypesGInner() {
46
+ for (const key of dbOrDBKeys) {
47
+ const contentType = getContentTypeFromDBKey(key);
48
+ if (types.includes(contentType)) {
49
+ results[contentType].push(key);
50
+ count++;
51
+ }
52
+ yield { count, results };
53
+ }
54
+ return results;
55
+ })();
56
+ }
57
+ return (async function* getKeysOfTypesGInner() {
58
+ for await (const [rawKey, _value] of dbOrDBKeys.getIterator({ keys: true, keyAsBuffer: true, values: false })) {
59
+ const contentType = getContentTypeFromDBKey(rawKey);
60
+ if (types.includes(contentType)) {
61
+ results[contentType].push(rawKey);
62
+ count++;
63
+ }
64
+ yield { count, results };
65
+ }
66
+ return results;
67
+ })();
68
+ }
38
69
  /**
39
70
  * Gets a player's name from their UUID.
40
71
  *
package/DBUtils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"DBUtils.js","sourceRoot":"","sources":["DBUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAA2B,MAAM,iBAAiB,CAAC;AACnF,OAAO,GAAG,MAA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AG,KAAK,UAAU,IAAI,EAAE;oBAAE,SAAS;gBACvC,MAAM,oBAAoB,GAAqE,sBAAsB,CAAC,GAAG,CAAS,CAAC;gBACnI,IAAI,oBAAoB,CAAC,IAAI,KAAK,QAAQ;oBAAE,SAAS;gBACrD,IAAI,CAAC;oBACD,MAAM,IAAI,GAAQ,KAAK,CAAC,KAAK,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAAC;oBAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;wBAAE,OAAO,IAAI,CAAC,IAAI,CAAC;gBACrG,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACT,SAAS;gBACb,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ,CAAC"}
package/DBUtils.ts CHANGED
@@ -93,6 +93,68 @@ export function getKeysOfTypes<T extends DBEntryContentType[] | readonly DBEntry
93
93
  );
94
94
  }
95
95
 
96
+ /**
97
+ * Gets the keys from the LevelDB with one of the specified content types.
98
+ *
99
+ * @template T The content types to look for.
100
+ * @param db The LevelDB. Should match the type of the {@link LevelDB} class from the {@link https://www.npmjs.com/package/@8crafter/leveldb-zlib | @8crafter/leveldb-zlib} package. It does not have to be the one from that package, as long as the types match.
101
+ * @param types The {@link DBEntryContentType | content types} to look for.
102
+ * @returns An object mapping each of the specified content types to the keys from the LevelDB with that content type, the keys are in Buffer format, this is because some keys contain binary data like chunk indices.
103
+ */
104
+ export function getKeysOfTypesG<T extends DBEntryContentType[] | readonly DBEntryContentType[]>(
105
+ db: LevelDB,
106
+ types: T
107
+ ): AsyncGenerator<{ count: number; results: { [key in T[number]]: Buffer<ArrayBuffer>[] } }, { [key in T[number]]: Buffer<ArrayBuffer>[] }>;
108
+ /**
109
+ * Gets the keys from the list of LevelDB keys with one of the specified content types.
110
+ *
111
+ * @template T The content types to look for.
112
+ * @template TArrayBuffer The type of the buffers.
113
+ * @param dbKeys The LevelDB keys. Should be an array of Buffers.
114
+ * @param types The {@link DBEntryContentType | content types} to look for.
115
+ * @returns An object mapping each of the specified content types to the keys from the provided LevelDB keys array with that content type, the keys are in Buffer format, this is because some keys contain binary data like chunk indices.
116
+ */
117
+ export function getKeysOfTypesG<T extends DBEntryContentType[] | readonly DBEntryContentType[], TArrayBuffer extends ArrayBufferLike>(
118
+ dbKeys: Buffer<TArrayBuffer>[],
119
+ types: T
120
+ ): Generator<{ count: number; results: { [key in T[number]]: Buffer<TArrayBuffer>[] } }, { [key in T[number]]: Buffer<TArrayBuffer>[] }>;
121
+ export function getKeysOfTypesG<T extends DBEntryContentType[] | readonly DBEntryContentType[]>(
122
+ dbOrDBKeys: LevelDB | Buffer[],
123
+ types: T
124
+ ):
125
+ | AsyncGenerator<{ count: number; results: { [key in T[number]]: Buffer<ArrayBuffer>[] } }, { [key in T[number]]: Buffer<ArrayBuffer>[] }>
126
+ | Generator<{ count: number; results: { [key in T[number]]: Buffer<ArrayBuffer>[] } }, { [key in T[number]]: Buffer[] }> {
127
+ const results = {} as { [key in T[number]]: Buffer<any>[] };
128
+ var count = 0;
129
+ types.forEach((contentType: T[number]): void => {
130
+ results[contentType] = [];
131
+ });
132
+ if (Array.isArray(dbOrDBKeys)) {
133
+ return (function* getKeysOfTypesGInner() {
134
+ for (const key of dbOrDBKeys) {
135
+ const contentType: DBEntryContentType = getContentTypeFromDBKey(key);
136
+ if (types.includes(contentType)) {
137
+ results[contentType as T[number]].push(key);
138
+ count++;
139
+ }
140
+ yield { count, results };
141
+ }
142
+ return results;
143
+ })();
144
+ }
145
+ return (async function* getKeysOfTypesGInner() {
146
+ for await (const [rawKey, _value] of dbOrDBKeys.getIterator({ keys: true, keyAsBuffer: true, values: false })) {
147
+ const contentType: DBEntryContentType = getContentTypeFromDBKey(rawKey);
148
+ if (types.includes(contentType)) {
149
+ results[contentType as T[number]].push(rawKey);
150
+ count++;
151
+ }
152
+ yield { count, results };
153
+ }
154
+ return results;
155
+ })();
156
+ }
157
+
96
158
  /**
97
159
  * Gets a player's name from their UUID.
98
160
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcbe-leveldb",
3
- "version": "1.10.2",
3
+ "version": "1.11.0",
4
4
  "main": "index.ts",
5
5
  "scripts": {
6
6
  "prepublishOnly": "tsc -p ./tsconfig.production.json",