mcbe-leveldb 1.0.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/DBUtils.js +114 -0
- package/DBUtils.js.map +1 -0
- package/DBUtils.ts +169 -0
- package/LevelUtils.js +1168 -0
- package/LevelUtils.js.map +1 -0
- package/LevelUtils.ts +1965 -0
- package/SNBTUtils.js +1374 -0
- package/SNBTUtils.js.map +1 -0
- package/SNBTUtils.ts +1725 -0
- package/__biome_data__.js +278 -0
- package/__biome_data__.js.map +1 -0
- package/__biome_data__.ts +277 -0
- package/index.js +6 -0
- package/index.js.map +1 -0
- package/index.ts +5 -0
- package/nbtSchemas.js +9211 -0
- package/nbtSchemas.js.map +1 -0
- package/nbtSchemas.ts +17213 -0
- package/package.json +60 -0
- package/tsconfig.json +24 -0
- package/tsconfig.production.json +25 -0
- package/types.d.ts +501 -0
- package/utils/JSONB.js +348 -0
- package/utils/JSONB.js.map +1 -0
- package/utils/JSONB.ts +566 -0
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcbe-leveldb",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.ts",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"prepublishOnly": "tsc -p ./tsconfig.production.json",
|
|
7
|
+
"postpublish": "node --experimental-transform-types development_scripts/postPublishCleanup.ts",
|
|
8
|
+
"generateNBTSchemaFromWikiData": "node --experimental-transform-types generation_scripts/generateNBTSchemaFromWikiData.ts",
|
|
9
|
+
"schemasTest": "node --experimental-transform-types test/schemas.test.ts"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"LevelDB",
|
|
13
|
+
"ldb",
|
|
14
|
+
"MCBE",
|
|
15
|
+
"MCPE",
|
|
16
|
+
"NodeJS",
|
|
17
|
+
"Minecraft Bedrock",
|
|
18
|
+
"Minecraft",
|
|
19
|
+
"Bedrock Edition",
|
|
20
|
+
"Pocket Edition"
|
|
21
|
+
],
|
|
22
|
+
"author": {
|
|
23
|
+
"email": "8crafteryt@gmail.com",
|
|
24
|
+
"name": "8Crafter",
|
|
25
|
+
"url": "https://www.8crafter.com"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"type": "module",
|
|
29
|
+
"description": "A utility module for easily working with Minecraft Bedrock Edition world data.",
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"prismarine-nbt": "^2.7.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"leveldb-zlib": "^1.2.0",
|
|
35
|
+
"@types/node": "^24.3.0"
|
|
36
|
+
},
|
|
37
|
+
"optionalDependencies": {
|
|
38
|
+
"leveldb-zlib": "^1.2.0"
|
|
39
|
+
},
|
|
40
|
+
"repository": {
|
|
41
|
+
"type": "git",
|
|
42
|
+
"url": "git+https://github.com/8Crafter-Studios/mcbe-leveldb.git"
|
|
43
|
+
},
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/8Crafter-Studios/mcbe-leveldb/issues",
|
|
46
|
+
"email": "8crafteryt@gmail.com"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/8Crafter-Studios/mcbe-leveldb",
|
|
49
|
+
"exports": {
|
|
50
|
+
".": {
|
|
51
|
+
"types": "./index.ts",
|
|
52
|
+
"default": "./index.js"
|
|
53
|
+
},
|
|
54
|
+
"./ts": {
|
|
55
|
+
"types": "./index.ts",
|
|
56
|
+
"default": "./index.ts"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
// "outDir": "./",
|
|
7
|
+
// "rootDir": "./",
|
|
8
|
+
"declaration": false,
|
|
9
|
+
// "declarationDir": "./",
|
|
10
|
+
"sourceMap": false,
|
|
11
|
+
"declarationMap": false,
|
|
12
|
+
"lib": ["ESNext"],
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"noUncheckedIndexedAccess": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"allowImportingTsExtensions": true,
|
|
20
|
+
"noEmit": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"skipLibCheck": true
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "esnext",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
// "outDir": "./",
|
|
7
|
+
// "rootDir": "./",
|
|
8
|
+
"declaration": false,
|
|
9
|
+
// "declarationDir": "./",
|
|
10
|
+
"sourceMap": true,
|
|
11
|
+
"declarationMap": false,
|
|
12
|
+
"lib": ["ESNext"],
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
"strict": true,
|
|
16
|
+
"noUncheckedIndexedAccess": true,
|
|
17
|
+
"resolveJsonModule": true,
|
|
18
|
+
"verbatimModuleSyntax": true,
|
|
19
|
+
"rewriteRelativeImportExtensions": true,
|
|
20
|
+
"noCheck": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"skipLibCheck": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["index.ts"]
|
|
25
|
+
}
|
package/types.d.ts
ADDED
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutates the type by removing the `readonly` modifier from all properties.
|
|
3
|
+
*
|
|
4
|
+
* @template T The type to mutate.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* type Original = { readonly name: string; readonly age: number };
|
|
9
|
+
* type Mutated = Mutable<Original>; // { name: string; age: number }
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export type Mutable<T> = {
|
|
13
|
+
-readonly [P in keyof T]: T[P];
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Mutates the type by removing the `readonly` modifier and the optional modifier (`?`) from all properties.
|
|
17
|
+
*
|
|
18
|
+
* @template T The type to mutate.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* type Original = { readonly name?: string; readonly age?: number };
|
|
23
|
+
* type Mutated = MutableRequired<Original>; // { name: string; age: number }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type MutableRequired<T> = {
|
|
27
|
+
-readonly [P in keyof T]-?: T[P];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Mutates the type by adding the `readonly` modifier and the optional modifier (`?`) to all properties.
|
|
31
|
+
*
|
|
32
|
+
* @template T The type to mutate.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* type Original = { name?: string; age?: number };
|
|
37
|
+
* type Mutated = ReadonlyPartial<Original>; // { readonly name?: string; readonly age?: number }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type ReadonlyPartial<T> = {
|
|
41
|
+
+readonly [P in keyof T]+?: T[P];
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Converts a union type to an intersection type.
|
|
45
|
+
*
|
|
46
|
+
* @template U The union type to convert.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* type Original = string | number;
|
|
51
|
+
* type Mutated = UnionToIntersection<Original>; // string & number
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never;
|
|
55
|
+
// type test1a = [name: number, id: `ID:${number}`, hi: "text"];
|
|
56
|
+
/**
|
|
57
|
+
* Pushes a value to the front of a tuple type.
|
|
58
|
+
*
|
|
59
|
+
* @template TailT The tail of the tuple.
|
|
60
|
+
* @template HeadT The head to push to the front.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* type Original = [number, string];
|
|
65
|
+
* type Mutated = PushFront<Original, boolean>; // [boolean, number, string]
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export type PushFront<TailT extends any[], HeadT> = ((head: HeadT, ...tail: TailT) => void) extends (...arr: infer ArrT) => void ? ArrT : never;
|
|
69
|
+
/* type NoRepetition<U extends string, ResultT extends any[] = []> = {
|
|
70
|
+
[k in U]: PushFront<ResultT, k> | NoRepetition<Exclude<U, k>, PushFront<ResultT, k>>;
|
|
71
|
+
}[U]; */
|
|
72
|
+
/**
|
|
73
|
+
* Creates a type that represents a string with no repeated characters.
|
|
74
|
+
*
|
|
75
|
+
* @template U The string to process.
|
|
76
|
+
* @template ResultT The result type, defaulting to an empty array.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```ts
|
|
80
|
+
* type Original = NoRepetition<"abc">; // ["a", "b", "c"]
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export type NoRepetition<U extends string, ResultT extends any[] = []> =
|
|
84
|
+
| ResultT
|
|
85
|
+
| {
|
|
86
|
+
[k in U]: NoRepetition<Exclude<U, k>, [k, ...ResultT]>;
|
|
87
|
+
}[U];
|
|
88
|
+
// Source: https://www.totaltypescript.com/tips/create-autocomplete-helper-which-allows-for-arbitrary-values
|
|
89
|
+
/**
|
|
90
|
+
* Creates a type that allows for autocomplete suggestions on a string type, while not giving errors for other values.
|
|
91
|
+
*
|
|
92
|
+
* @template T A union type of string literals to add to the autocomplete.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* // Will allow autocomplete for "abc", "b", and "def", and will not throw errors for other string values.
|
|
97
|
+
* type Original = LooseAutocomplete<"abc" | "b" | "def">; // "abc" | "b" | "def" | (Omit<string, "abc" | "b" | "def"> & string)
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export type LooseAutocomplete<T extends string> = T | (Omit<string, T> & string);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a type that allows for autocomplete suggestions on a custom type (can only be string, number, or symbol), while not giving errors for other values.
|
|
103
|
+
*
|
|
104
|
+
* @template U A union type that can contain string, number, and symbol, this will be the base type, anything not assignable to this WILL throw an error.
|
|
105
|
+
* @template T A union type of string literals and number literals to add to the autocomplete, string literals are only allowed if {@link U} contains string, and number literals are only allowed if {@link U} contains number.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* // Will allow autocomplete for "abc", "b", and "def", and will not throw errors for other string values.
|
|
110
|
+
* type Original = LooseAutocompleteB<string, "abc" | "b" | "def">; // "abc" | "b" | "def" | (Omit<string, "abc" | "b" | "def"> & string)
|
|
111
|
+
*
|
|
112
|
+
* // Will allow autocomplete for 1, 2, and 3, and will not throw errors for other number values.
|
|
113
|
+
* type Original = LooseAutocompleteB<number, 1 | 2 | 3>; // 1 | 2 | 3 | (Omit<number, 1 | 2 | 3> & number)
|
|
114
|
+
*
|
|
115
|
+
* // Will allow autocomplete for 1, 2, and 3, and will not throw errors for other number or string values.
|
|
116
|
+
* type Original = LooseAutocompleteB<number | string, 1 | 2 | 3>; // 1 | 2 | 3 | (Omit<number | string, 1 | 2 | 3> & (number | string))
|
|
117
|
+
*
|
|
118
|
+
* // Will allow autocomplete for "a", 45, and "fhsd", and will not throw errors for other number, symbol, or string values.
|
|
119
|
+
* type Original = LooseAutocompleteB<string | number | symbol, "a" | 45 | "fhsd">; // "a" | 45 | "fhsd" | (Omit<string | number | symbol, "a" | 45 | "fhsd"> & (string | number | symbol))
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export type LooseAutocompleteB<U extends string | number | symbol, T extends U> = T | (Omit<U, T> & U);
|
|
123
|
+
/**
|
|
124
|
+
* Splits a string into an array of characters.
|
|
125
|
+
*
|
|
126
|
+
* @template S The string to split.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* type Original = Split<"abc">; // ["a", "b", "c"]
|
|
131
|
+
* ```
|
|
132
|
+
*/
|
|
133
|
+
export type Split<S extends string> = S extends "" ? [] : S extends `${infer C}${infer R}` ? [C, ...Split<R>] : never;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Takes the first N elements from a tuple type.
|
|
137
|
+
*
|
|
138
|
+
* @template T The tuple type to take elements from.
|
|
139
|
+
* @template N The number of elements to take.
|
|
140
|
+
* @template Result The result type, defaulting to an empty array.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* type Original = TakeFirstNElements<[1, 2, 3, 4], 2>; // [1, 2]
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export type TakeFirstNElements<T extends any[], N extends number, Result extends any[] = []> = Result["length"] extends N
|
|
148
|
+
? Result
|
|
149
|
+
: T extends [infer First, ...infer Rest]
|
|
150
|
+
? TakeFirstNElements<Rest, N, [...Result, First]>
|
|
151
|
+
: Result;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Joins an array of strings into a single string.
|
|
155
|
+
*
|
|
156
|
+
* @template T The array of strings to join.
|
|
157
|
+
* @template J The separator to use, defaulting to an empty string.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* type Original = Join<["a", "bcc", "de"]>; // "abccde"
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export type Join<T extends string[], J extends string = ""> = T extends []
|
|
165
|
+
? ""
|
|
166
|
+
: T extends [infer Head, ...infer Tail]
|
|
167
|
+
? Head extends string
|
|
168
|
+
? `${Head}${Tail extends [string, ...string[]] ? J : ""}${Join<Tail extends string[] ? Tail : [], J>}`
|
|
169
|
+
: never
|
|
170
|
+
: never;
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Cuts the first N characters from a string.
|
|
174
|
+
*
|
|
175
|
+
* @template S The string to cut.
|
|
176
|
+
* @template N The number of characters to cut.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* type Original = CutFirstChars<"abcdef", 2>; // "cdef"
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export type CutFirstChars<S extends string, N extends number, SArray = TakeFirstNElements<Split<S>, N>> = Join<SArray extends string[] ? SArray : never>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Mutates the type by removing the optional modifier (`?`) from all properties.
|
|
187
|
+
*
|
|
188
|
+
* @template T The type to mutate.
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* ```ts
|
|
192
|
+
* type Original = { readonly name?: string; age?: number };
|
|
193
|
+
* type Mutated = MutableRequired<Original>; // { readonly name: string; age: number }
|
|
194
|
+
* ```
|
|
195
|
+
*/
|
|
196
|
+
export type Full<T> = {
|
|
197
|
+
[P in keyof T]-?: T[P];
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Mutates the type by making all properties `readonly`, recursively.
|
|
202
|
+
*
|
|
203
|
+
* @template T The type to mutate.
|
|
204
|
+
*
|
|
205
|
+
* @example
|
|
206
|
+
* ```ts
|
|
207
|
+
* type Original = { name: string; age: number }
|
|
208
|
+
* type Mutated = ReadonlyDeep<Original>; // { readonly name: string; readonly age: number }
|
|
209
|
+
* ```
|
|
210
|
+
*/
|
|
211
|
+
export type ReadonlyDeep<T> = {
|
|
212
|
+
readonly [P in keyof T]: ReadonlyDeep<T[P]>;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Mutates the type by removing the `readonly` modifier from all properties, recursively.
|
|
217
|
+
*
|
|
218
|
+
* @template T The type to mutate.
|
|
219
|
+
*
|
|
220
|
+
* @example
|
|
221
|
+
* ```ts
|
|
222
|
+
* type Original = { readonly name: string; readonly age: number };
|
|
223
|
+
* type Mutated = MutableDeep<Original>; // { name: string; age: number }
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export type MutableDeep<T> = {
|
|
227
|
+
-readonly [P in keyof T]: MutableDeep<T[P]>;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Mutates the type by making all properties optional and allowing for deep partials.
|
|
232
|
+
*
|
|
233
|
+
* @template T The type to mutate.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```ts
|
|
237
|
+
* type Original = { name: string; age: number }
|
|
238
|
+
* type Mutated = DeepPartial<Original>; // { name?: string; age?: number }
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export type DeepPartial<T> = T extends object
|
|
242
|
+
? {
|
|
243
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
244
|
+
}
|
|
245
|
+
: T;
|
|
246
|
+
export type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
247
|
+
export type ValueTypes<T> = T extends { [key: string]: infer U } ? U : never;
|
|
248
|
+
export type AllValues<T> = T extends { [key: string]: infer V } ? V : never;
|
|
249
|
+
export type KeyValuePairs<T> = {
|
|
250
|
+
[K in KeysOfUnion<T>]: AllValues<Extract<T, Record<K, any>>>;
|
|
251
|
+
};
|
|
252
|
+
/**
|
|
253
|
+
* @see https://stackoverflow.com/a/58986589
|
|
254
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
255
|
+
*/
|
|
256
|
+
export type ExcludeFromTuple<T extends readonly any[], E> = T extends [infer F, ...infer R]
|
|
257
|
+
? [F] extends [E]
|
|
258
|
+
? ExcludeFromTuple<R, E>
|
|
259
|
+
: [F, ...ExcludeFromTuple<R, E>]
|
|
260
|
+
: [];
|
|
261
|
+
export type IncludeFromTuple<T extends readonly any[], E> = T extends [infer F, ...infer R]
|
|
262
|
+
? [F] extends [E]
|
|
263
|
+
? [F, ...IncludeFromTuple<R, E>]
|
|
264
|
+
: IncludeFromTuple<R, E>
|
|
265
|
+
: [];
|
|
266
|
+
export type NullableArray<T extends any[] | readonly any[]> = T | [null, ...T] | [...T, null];
|
|
267
|
+
/**
|
|
268
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
269
|
+
*
|
|
270
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
271
|
+
*/
|
|
272
|
+
export type IfEquals<X, Y, A = X, B = never> = (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
276
|
+
*
|
|
277
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
278
|
+
*/
|
|
279
|
+
export type WritableKeys<T> = {
|
|
280
|
+
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, P>;
|
|
281
|
+
}[keyof T];
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
285
|
+
*
|
|
286
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
287
|
+
*/
|
|
288
|
+
export type ReadonlyKeys<T> = {
|
|
289
|
+
[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;
|
|
290
|
+
}[keyof T];
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
294
|
+
*
|
|
295
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
296
|
+
*/
|
|
297
|
+
export type RequiredKeys<T> = {
|
|
298
|
+
[K in keyof T]-?: NonNullable<unknown> extends { [P in K]: T[K] } ? never : K;
|
|
299
|
+
}[keyof T];
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
303
|
+
*
|
|
304
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
305
|
+
*/
|
|
306
|
+
export type OptionalKeys<T> = {
|
|
307
|
+
[K in keyof T]-?: NonNullable<unknown> extends { [P in K]: T[K] } ? K : never;
|
|
308
|
+
}[keyof T];
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @see https://stackoverflow.com/a/49579497/16872762
|
|
312
|
+
*
|
|
313
|
+
* @author jcalz <https://stackoverflow.com/users/2887218/jcalz>
|
|
314
|
+
*/
|
|
315
|
+
export type ExcludeOptionalProps<T> = Pick<T, RequiredKeys<T>>;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @author 8Crafter
|
|
319
|
+
*/
|
|
320
|
+
export type ExcludeRequiredProps<T> = Pick<T, OptionalKeys<T>>;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* @author 8Crafter
|
|
324
|
+
*/
|
|
325
|
+
export type ExcludeWritableProps<T> = Pick<T, ReadonlyKeys<T>>;
|
|
326
|
+
|
|
327
|
+
/**
|
|
328
|
+
* @author 8Crafter
|
|
329
|
+
*/
|
|
330
|
+
export type ExcludeReadonlyProps<T> = Pick<T, WritableKeys<T>>;
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* @author 8Crafter
|
|
334
|
+
*/
|
|
335
|
+
export type ExcludeMethods<T> = Pick<
|
|
336
|
+
T,
|
|
337
|
+
{
|
|
338
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : K;
|
|
339
|
+
}[keyof T]
|
|
340
|
+
>;
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* @author 8Crafter
|
|
344
|
+
*/
|
|
345
|
+
export type MergeObjectTypes<T> = { [key in keyof T]: T[key] };
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* @author 8Crafter
|
|
349
|
+
*/
|
|
350
|
+
export type DeepMergeObjectTypes<T> = {
|
|
351
|
+
[key in keyof T]: T[key] extends object ? MergeObjectTypes<T[key]> : T[key];
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* @author 8Crafter
|
|
356
|
+
*/
|
|
357
|
+
export type PropertyNamesWithPath<T> = T extends object
|
|
358
|
+
? {
|
|
359
|
+
[K in string & keyof T]: T[K] extends Date | undefined
|
|
360
|
+
? K // Stop recursion on Date
|
|
361
|
+
: T[K] extends Array<infer A> | undefined
|
|
362
|
+
? K | `${K & string}.${PropertyNamesWithPath<A>}` // On arrays, continue with the parameterized type
|
|
363
|
+
: K | `${K & string}.${PropertyNamesWithPath<T[K]>}`;
|
|
364
|
+
}[string & keyof T]
|
|
365
|
+
: never;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* @author 8Crafter
|
|
369
|
+
*/
|
|
370
|
+
export type PropertyNamesInner<T, U = keyof T> = T extends object
|
|
371
|
+
? {
|
|
372
|
+
[K in U & keyof T]: T[K] extends Date | undefined
|
|
373
|
+
? K // Stop recursion on Date
|
|
374
|
+
: T[K] extends Array<infer A> | undefined
|
|
375
|
+
? K | PropertyNamesInner<A> // On arrays, continue with the parameterized type
|
|
376
|
+
: K | PropertyNamesInner<T[K]>;
|
|
377
|
+
}[U & keyof T]
|
|
378
|
+
: never;
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* @author 8Crafter
|
|
382
|
+
*/
|
|
383
|
+
export type PropertyNames<T, U = string | number> = VerifyConstraint<PropertyNamesInner<T, U>, U>;
|
|
384
|
+
|
|
385
|
+
/**
|
|
386
|
+
* @author 8Crafter
|
|
387
|
+
*/
|
|
388
|
+
export type PropertyNamesWithPathWithoutOuterContainingProperties<T> = T extends object
|
|
389
|
+
? {
|
|
390
|
+
[K in string & keyof T]: T[K] extends Date | undefined
|
|
391
|
+
? K // Stop recursion on Date
|
|
392
|
+
: T[K] extends Array<infer A> | undefined
|
|
393
|
+
? K | `${K & string}.${PropertyNamesWithPathWithoutOuterContainingProperties<A>}` // On arrays, continue with the parameterized type
|
|
394
|
+
: (T[K] extends object ? never : K) | `${K & string}.${PropertyNamesWithPathWithoutOuterContainingProperties<T[K]>}`;
|
|
395
|
+
}[string & keyof T]
|
|
396
|
+
: never;
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @author 8Crafter
|
|
400
|
+
*/
|
|
401
|
+
export type PropertyNamesInnerWithoutOuterContainingProperties<T, U = keyof T> = T extends object
|
|
402
|
+
? {
|
|
403
|
+
[K in U & keyof T]: T[K] extends Date | undefined
|
|
404
|
+
? K // Stop recursion on Date
|
|
405
|
+
: T[K] extends Array<infer A> | undefined
|
|
406
|
+
? K | PropertyNamesInnerWithoutOuterContainingProperties<A> // On arrays, continue with the parameterized type
|
|
407
|
+
: (T[K] extends object ? never : K) | PropertyNamesInnerWithoutOuterContainingProperties<T[K]>;
|
|
408
|
+
}[U & keyof T]
|
|
409
|
+
: never;
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* @author 8Crafter
|
|
413
|
+
*/
|
|
414
|
+
export type PropertyNamesWithoutOuterContainingProperties<T, U = string | number> = VerifyConstraint<
|
|
415
|
+
PropertyNamesInnerWithoutOuterContainingProperties<T, U>,
|
|
416
|
+
U
|
|
417
|
+
>;
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @author 8Crafter
|
|
421
|
+
*/
|
|
422
|
+
export type PropertyPaths<T> = T extends object
|
|
423
|
+
? {
|
|
424
|
+
[K in (string | number) & keyof T]: T[K] extends Date | undefined
|
|
425
|
+
? [K] // Stop recursion on Date
|
|
426
|
+
: T[K] extends Array<infer A> | undefined
|
|
427
|
+
? [K] | [K, ...PropertyPaths<A>]
|
|
428
|
+
: [K] | [K, ...PropertyPaths<T[K]>];
|
|
429
|
+
}[(string | number) & keyof T]
|
|
430
|
+
: never;
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* @author 8Crafter
|
|
434
|
+
*/
|
|
435
|
+
export type PropertyPathsWithoutOuterContainingProperties<T> = T extends object
|
|
436
|
+
? {
|
|
437
|
+
[K in (string | number) & keyof T]: T[K] extends undefined
|
|
438
|
+
? never
|
|
439
|
+
: T[K] extends Date | undefined
|
|
440
|
+
? K // Stop recursion on Date
|
|
441
|
+
: T[K] extends Array<infer A> | undefined
|
|
442
|
+
?
|
|
443
|
+
| [K]
|
|
444
|
+
| [
|
|
445
|
+
K,
|
|
446
|
+
...(PropertyPathsWithoutOuterContainingProperties<A> extends any[]
|
|
447
|
+
? PropertyPathsWithoutOuterContainingProperties<A>
|
|
448
|
+
: [PropertyPathsWithoutOuterContainingProperties<A>])
|
|
449
|
+
]
|
|
450
|
+
:
|
|
451
|
+
| (T[K] extends object ? never : [K])
|
|
452
|
+
| [
|
|
453
|
+
K,
|
|
454
|
+
...(PropertyPathsWithoutOuterContainingProperties<T[K]> extends any[]
|
|
455
|
+
? PropertyPathsWithoutOuterContainingProperties<T[K]>
|
|
456
|
+
: [PropertyPathsWithoutOuterContainingProperties<T[K]>])
|
|
457
|
+
];
|
|
458
|
+
}[(string | number) & keyof T]
|
|
459
|
+
: never;
|
|
460
|
+
|
|
461
|
+
export type GetPropertyValueAtPath<T extends object, U extends PropertyPaths<T> | []> = U extends [infer K extends keyof T]
|
|
462
|
+
? T[K]
|
|
463
|
+
: U extends [infer K extends keyof T, ...infer R]
|
|
464
|
+
? GetPropertyValueAtPath<VerifyConstraint<T[K], object>, R extends PropertyPaths<VerifyConstraint<T[K], object>> ? R : []>
|
|
465
|
+
: T;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* @author 8Crafter
|
|
469
|
+
*/
|
|
470
|
+
export type VerifyConstraint<T, U> = T extends U ? T : never;
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* @author 8Crafter
|
|
474
|
+
*/
|
|
475
|
+
export type IncludesNever<T extends any[]> = {
|
|
476
|
+
[K in keyof T]: T[K] extends never ? unknown : never;
|
|
477
|
+
}[number] extends never
|
|
478
|
+
? false
|
|
479
|
+
: true;
|
|
480
|
+
|
|
481
|
+
export type NeverValueKeys<T extends object> = {
|
|
482
|
+
[K in keyof T]: T[K] extends never ? K : never;
|
|
483
|
+
}[keyof T];
|
|
484
|
+
|
|
485
|
+
export type OmitNeverValueKeys<T extends object> = Omit<T, NeverValueKeys<T>>;
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* @see https://stackoverflow.com/a/60822641/16872762
|
|
489
|
+
*/
|
|
490
|
+
export type ReturnTypeWithArgs<T extends (...args: any[]) => any, ARGS_T> = Extract<
|
|
491
|
+
T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; (...args: infer A3): infer R3; (...args: infer A4): infer R4 }
|
|
492
|
+
? [A1, R1] | [A2, R2] | [A3, R3] | [A4, R4]
|
|
493
|
+
: T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2; (...args: infer A3): infer R3 }
|
|
494
|
+
? [A1, R1] | [A2, R2] | [A3, R3]
|
|
495
|
+
: T extends { (...args: infer A1): infer R1; (...args: infer A2): infer R2 }
|
|
496
|
+
? [A1, R1] | [A2, R2]
|
|
497
|
+
: T extends { (...args: infer A1): infer R1 }
|
|
498
|
+
? [A1, R1]
|
|
499
|
+
: never,
|
|
500
|
+
[ARGS_T, any]
|
|
501
|
+
>[1];
|