@evolu/common 7.4.1 → 8.0.0-next.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 +4 -61
- package/dist/src/Array.d.ts +343 -102
- package/dist/src/Array.d.ts.map +1 -1
- package/dist/src/Array.js +181 -85
- package/dist/src/Assert.d.ts +57 -11
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +47 -11
- package/dist/src/BigInt.d.ts +6 -1
- package/dist/src/BigInt.d.ts.map +1 -1
- package/dist/src/BigInt.js +5 -0
- package/dist/src/Brand.d.ts +40 -12
- package/dist/src/Brand.d.ts.map +1 -1
- package/dist/src/Brand.js +5 -0
- package/dist/src/Buffer.d.ts +6 -1
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +7 -2
- package/dist/src/Cache.d.ts +10 -2
- package/dist/src/Cache.d.ts.map +1 -1
- package/dist/src/Cache.js +6 -0
- package/dist/src/Callbacks.d.ts +10 -7
- package/dist/src/Callbacks.d.ts.map +1 -1
- package/dist/src/Callbacks.js +23 -13
- package/dist/src/Console.d.ts +361 -69
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +217 -117
- package/dist/src/Crypto.d.ts +70 -21
- package/dist/src/Crypto.d.ts.map +1 -1
- package/dist/src/Crypto.js +72 -27
- package/dist/src/Eq.d.ts +22 -2
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +21 -1
- package/dist/src/Error.d.ts +23 -12
- package/dist/src/Error.d.ts.map +1 -1
- package/dist/src/Error.js +27 -11
- package/dist/src/Function.d.ts +128 -56
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +118 -14
- package/dist/src/Identicon.d.ts +5 -0
- package/dist/src/Identicon.d.ts.map +1 -1
- package/dist/src/Identicon.js +6 -1
- package/dist/src/Lookup.d.ts +162 -0
- package/dist/src/Lookup.d.ts.map +1 -0
- package/dist/src/Lookup.js +200 -0
- package/dist/src/Microtask.d.ts +21 -0
- package/dist/src/Microtask.d.ts.map +1 -0
- package/dist/src/Microtask.js +37 -0
- package/dist/src/Number.d.ts +18 -4
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +23 -1
- package/dist/src/Object.d.ts +110 -5
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +108 -5
- package/dist/src/Option.d.ts +58 -0
- package/dist/src/Option.d.ts.map +1 -0
- package/dist/src/Option.js +43 -0
- package/dist/src/Order.d.ts +5 -0
- package/dist/src/Order.d.ts.map +1 -1
- package/dist/src/Order.js +8 -3
- package/dist/src/Platform.d.ts +36 -2
- package/dist/src/Platform.d.ts.map +1 -1
- package/dist/src/Platform.js +10 -6
- package/dist/src/Polyfills.d.ts +29 -0
- package/dist/src/Polyfills.d.ts.map +1 -0
- package/dist/src/Polyfills.js +329 -0
- package/dist/src/Random.d.ts +18 -7
- package/dist/src/Random.d.ts.map +1 -1
- package/dist/src/Random.js +9 -7
- package/dist/src/Redacted.d.ts +7 -4
- package/dist/src/Redacted.d.ts.map +1 -1
- package/dist/src/Redacted.js +5 -0
- package/dist/src/Ref.d.ts +31 -16
- package/dist/src/Ref.d.ts.map +1 -1
- package/dist/src/Ref.js +35 -7
- package/dist/src/RefCount.d.ts +62 -0
- package/dist/src/RefCount.d.ts.map +1 -0
- package/dist/src/RefCount.js +83 -0
- package/dist/src/Relation.d.ts +84 -29
- package/dist/src/Relation.d.ts.map +1 -1
- package/dist/src/Relation.js +83 -105
- package/dist/src/Resource.d.ts +263 -0
- package/dist/src/Resource.d.ts.map +1 -0
- package/dist/src/Resource.js +389 -0
- package/dist/src/Result.d.ts +390 -374
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +142 -70
- package/dist/src/Schedule.d.ts +953 -0
- package/dist/src/Schedule.d.ts.map +1 -0
- package/dist/src/Schedule.js +1199 -0
- package/dist/src/Set.d.ts +181 -0
- package/dist/src/Set.d.ts.map +1 -0
- package/dist/src/Set.js +137 -0
- package/dist/src/Skiplist.d.ts +6 -1
- package/dist/src/Skiplist.d.ts.map +1 -1
- package/dist/src/Skiplist.js +5 -0
- package/dist/src/Sqlite.d.ts +160 -60
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +290 -190
- package/dist/src/Store.d.ts +36 -28
- package/dist/src/Store.d.ts.map +1 -1
- package/dist/src/Store.js +55 -15
- package/dist/src/String.d.ts +5 -0
- package/dist/src/String.d.ts.map +1 -1
- package/dist/src/String.js +5 -0
- package/dist/src/Task.d.ts +2274 -423
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +1499 -348
- package/dist/src/Test.d.ts +150 -0
- package/dist/src/Test.d.ts.map +1 -0
- package/dist/src/Test.js +97 -0
- package/dist/src/Time.d.ts +202 -48
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +199 -88
- package/dist/src/Tracer.d.ts +48 -0
- package/dist/src/Tracer.d.ts.map +1 -0
- package/dist/src/Tracer.js +6 -0
- package/dist/src/Type.d.ts +587 -209
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +370 -240
- package/dist/src/Types.d.ts +160 -6
- package/dist/src/Types.d.ts.map +1 -1
- package/dist/src/Types.js +22 -2
- package/dist/src/WebSocket.d.ts +130 -58
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/WebSocket.js +274 -113
- package/dist/src/Worker.d.ts +245 -60
- package/dist/src/Worker.d.ts.map +1 -1
- package/dist/src/Worker.js +220 -64
- package/dist/src/index.d.ts +25 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +19 -3
- package/dist/src/local-first/Db.d.ts +24 -213
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +621 -293
- package/dist/src/local-first/Error.d.ts +12 -0
- package/dist/src/local-first/Error.d.ts.map +1 -0
- package/dist/src/local-first/Error.js +6 -0
- package/dist/src/local-first/Evolu.d.ts +330 -285
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +472 -402
- package/dist/src/local-first/LocalAuth.d.ts +10 -10
- package/dist/src/local-first/LocalAuth.d.ts.map +1 -1
- package/dist/src/local-first/LocalAuth.js +6 -1
- package/dist/src/local-first/Owner.d.ts +70 -27
- package/dist/src/local-first/Owner.d.ts.map +1 -1
- package/dist/src/local-first/Owner.js +27 -14
- package/dist/src/local-first/Protocol.d.ts +58 -50
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +253 -155
- package/dist/src/local-first/Query.d.ts +133 -43
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +139 -90
- package/dist/src/local-first/Relay.d.ts +34 -49
- package/dist/src/local-first/Relay.d.ts.map +1 -1
- package/dist/src/local-first/Relay.js +59 -177
- package/dist/src/local-first/Schema.d.ts +139 -144
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +78 -163
- package/dist/src/local-first/Shared.d.ts +125 -0
- package/dist/src/local-first/Shared.d.ts.map +1 -0
- package/dist/src/local-first/Shared.js +569 -0
- package/dist/src/local-first/Storage.d.ts +54 -58
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +127 -179
- package/dist/src/local-first/Timestamp.d.ts +28 -35
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +24 -25
- package/dist/src/local-first/index.d.ts +2 -15
- package/dist/src/local-first/index.d.ts.map +1 -1
- package/dist/src/local-first/index.js +2 -15
- package/package.json +37 -24
- package/src/Array.ts +467 -106
- package/src/Assert.ts +87 -12
- package/src/BigInt.ts +7 -1
- package/src/Brand.ts +41 -12
- package/src/Buffer.ts +10 -4
- package/src/Cache.ts +11 -2
- package/src/Callbacks.ts +33 -23
- package/src/Console.ts +567 -178
- package/src/Crypto.ts +111 -62
- package/src/Eq.ts +30 -3
- package/src/Error.ts +50 -34
- package/src/Function.ts +140 -68
- package/src/Identicon.ts +7 -1
- package/src/Lookup.ts +429 -0
- package/src/Microtask.ts +58 -0
- package/src/Number.ts +40 -7
- package/src/Object.ts +155 -16
- package/src/Option.ts +74 -0
- package/src/Order.ts +11 -3
- package/src/Platform.ts +43 -7
- package/src/Polyfills.ts +520 -0
- package/src/Random.ts +25 -11
- package/src/Redacted.ts +8 -4
- package/src/Ref.ts +72 -21
- package/src/RefCount.ts +170 -0
- package/src/Relation.ts +188 -136
- package/src/Resource.ts +864 -0
- package/src/Result.ts +548 -381
- package/src/Schedule.ts +1471 -0
- package/src/Set.ts +247 -0
- package/src/Skiplist.ts +7 -1
- package/src/Sqlite.ts +409 -304
- package/src/Store.ts +94 -48
- package/src/String.ts +6 -0
- package/src/Task.ts +3696 -740
- package/src/Test.ts +202 -0
- package/src/Time.ts +357 -147
- package/src/Tracer.ts +54 -0
- package/src/Type.ts +866 -430
- package/src/Types.ts +202 -7
- package/src/WebSocket.ts +404 -167
- package/src/Worker.ts +527 -147
- package/src/index.ts +74 -3
- package/src/local-first/Db.ts +867 -597
- package/src/local-first/Error.ts +17 -0
- package/src/local-first/Evolu.ts +884 -824
- package/src/local-first/LocalAuth.ts +10 -10
- package/src/local-first/Owner.ts +94 -42
- package/src/local-first/Protocol.ts +441 -307
- package/src/local-first/Query.ts +243 -194
- package/src/local-first/Relay.ts +119 -273
- package/src/local-first/Schema.ts +284 -394
- package/src/local-first/Shared.ts +932 -0
- package/src/local-first/Storage.ts +211 -283
- package/src/local-first/Timestamp.ts +38 -45
- package/src/local-first/index.ts +2 -16
- package/dist/src/Instances.d.ts +0 -34
- package/dist/src/Instances.d.ts.map +0 -1
- package/dist/src/Instances.js +0 -44
- package/dist/src/Resources.d.ts +0 -118
- package/dist/src/Resources.d.ts.map +0 -1
- package/dist/src/Resources.js +0 -197
- package/dist/src/local-first/Platform.d.ts +0 -25
- package/dist/src/local-first/Platform.d.ts.map +0 -1
- package/dist/src/local-first/Platform.js +0 -1
- package/dist/src/local-first/Public.d.ts +0 -22
- package/dist/src/local-first/Public.d.ts.map +0 -1
- package/dist/src/local-first/Public.js +0 -15
- package/dist/src/local-first/PublicKysely.d.ts +0 -148
- package/dist/src/local-first/PublicKysely.d.ts.map +0 -1
- package/dist/src/local-first/PublicKysely.js +0 -184
- package/dist/src/local-first/Sync.d.ts +0 -112
- package/dist/src/local-first/Sync.d.ts.map +0 -1
- package/dist/src/local-first/Sync.js +0 -526
- package/src/Instances.ts +0 -92
- package/src/Resources.ts +0 -367
- package/src/local-first/Platform.ts +0 -27
- package/src/local-first/Public.ts +0 -42
- package/src/local-first/PublicKysely.ts +0 -239
- package/src/local-first/Sync.ts +0 -949
package/src/Types.ts
CHANGED
|
@@ -1,10 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TypeScript utility types
|
|
2
|
+
* TypeScript utility types.
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import * as Kysely from "kysely";
|
|
8
|
+
import type { TypeName } from "./Type.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A function that receives a value and returns nothing.
|
|
12
|
+
*
|
|
13
|
+
* Use for event handlers, observers, and async completion handlers.
|
|
14
|
+
*
|
|
15
|
+
* ### Example
|
|
16
|
+
*
|
|
17
|
+
* ```ts
|
|
18
|
+
* const onComplete: Callback<string> = (value) => console.log(value);
|
|
19
|
+
* const queue = new Set<Callback<Result<Data, Error>>>();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type Callback<T> = (value: T) => void;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A function that receives a value and optionally returns a teardown function.
|
|
26
|
+
*
|
|
27
|
+
* Use for subscriptions or callbacks that need abort-time teardown.
|
|
28
|
+
*
|
|
29
|
+
* ### Example
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const subscribe: CallbackWithTeardown<EventSource> = (source) => {
|
|
33
|
+
* source.start();
|
|
34
|
+
* return () => source.stop();
|
|
35
|
+
* };
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export type CallbackWithTeardown<T> = (value: T) => void | (() => void);
|
|
8
39
|
|
|
9
40
|
/**
|
|
10
41
|
* Checks a condition on a value and returns a boolean.
|
|
@@ -114,12 +145,6 @@ export type NullablePartial<
|
|
|
114
145
|
NP = Pick<T, Exclude<keyof T, NK>> & Partial<Pick<T, NK>>,
|
|
115
146
|
> = { [K in keyof NP]: NP[K] };
|
|
116
147
|
|
|
117
|
-
/**
|
|
118
|
-
* A type alias for `never` that is used intentionally when casting is not
|
|
119
|
-
* needed and unit tests exist to ensure correctness.
|
|
120
|
-
*/
|
|
121
|
-
export type IntentionalNever = never;
|
|
122
|
-
|
|
123
148
|
/**
|
|
124
149
|
* String, number, bigint, boolean, undefined, null
|
|
125
150
|
*
|
|
@@ -147,6 +172,16 @@ export type WidenLiteral<T extends Literal> = T extends string
|
|
|
147
172
|
? bigint
|
|
148
173
|
: T;
|
|
149
174
|
|
|
175
|
+
/**
|
|
176
|
+
* Removes `readonly` modifier from all properties of a type.
|
|
177
|
+
*
|
|
178
|
+
* Useful for constructing immutable objects step-by-step (e.g. builder pattern)
|
|
179
|
+
* before casting them back to the readonly type.
|
|
180
|
+
*/
|
|
181
|
+
export type Mutable<T> = {
|
|
182
|
+
-readonly [P in keyof T]: T[P];
|
|
183
|
+
};
|
|
184
|
+
|
|
150
185
|
/**
|
|
151
186
|
* Simplify an intersection type into a single mapped type.
|
|
152
187
|
*
|
|
@@ -173,3 +208,163 @@ export type Simplify<T> = Kysely.Simplify<T>;
|
|
|
173
208
|
*/
|
|
174
209
|
export type PartialProp<T, K extends keyof T> = Omit<T, K> &
|
|
175
210
|
Partial<Pick<T, K>>;
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* A value that can be awaited.
|
|
214
|
+
*
|
|
215
|
+
* Use when a function may complete synchronously or asynchronously depending on
|
|
216
|
+
* runtime conditions (e.g., cache hit vs network fetch).
|
|
217
|
+
*
|
|
218
|
+
* ### Example
|
|
219
|
+
*
|
|
220
|
+
* ```ts
|
|
221
|
+
* const getData = (id: string): Awaitable<Data> => {
|
|
222
|
+
* const cached = cache.get(id);
|
|
223
|
+
* if (cached) return cached; // Sync path
|
|
224
|
+
* return fetchData(id); // Async path
|
|
225
|
+
* };
|
|
226
|
+
*
|
|
227
|
+
* // Always works
|
|
228
|
+
* const data = await getData(id);
|
|
229
|
+
*
|
|
230
|
+
* // Or optimize for sync path
|
|
231
|
+
* const result = getData(id);
|
|
232
|
+
* const data = isPromiseLike(result) ? await result : result;
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
export type Awaitable<T> = T | PromiseLike<T>;
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Type guard to check if a value is a {@link PromiseLike}.
|
|
239
|
+
*
|
|
240
|
+
* Use with {@link Awaitable} to conditionally `await` only when necessary,
|
|
241
|
+
* avoiding microtask overhead for synchronous values.
|
|
242
|
+
*
|
|
243
|
+
* ### Example
|
|
244
|
+
*
|
|
245
|
+
* ```ts
|
|
246
|
+
* const validate = (id: string): Awaitable<boolean> => {
|
|
247
|
+
* const cached = cache.get(id);
|
|
248
|
+
* if (cached !== undefined) return cached; // Sync path
|
|
249
|
+
* return fetchValidation(id); // Async path
|
|
250
|
+
* };
|
|
251
|
+
*
|
|
252
|
+
* const result = validate(id);
|
|
253
|
+
* const isValid = isPromiseLike(result) ? await result : result;
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
export const isPromiseLike = <T>(
|
|
257
|
+
value: Awaitable<T>,
|
|
258
|
+
): value is PromiseLike<T> =>
|
|
259
|
+
typeof (value as PromiseLike<T> | null | undefined)?.then === "function";
|
|
260
|
+
|
|
261
|
+
/** Single digit 0-9. Useful for template literal type validation. */
|
|
262
|
+
export type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
263
|
+
|
|
264
|
+
/** Digit 1-9. Useful for template literal type validation. */
|
|
265
|
+
export type Digit1To9 = Exclude<Digit, "0">;
|
|
266
|
+
|
|
267
|
+
/** Numeric string 1-6. Useful for days validation. */
|
|
268
|
+
export type Digit1To6 = "1" | "2" | "3" | "4" | "5" | "6";
|
|
269
|
+
|
|
270
|
+
/** Numeric string 1-23. Useful for hours validation. */
|
|
271
|
+
export type Digit1To23 =
|
|
272
|
+
| Digit1To9 // 1-9
|
|
273
|
+
| `1${Digit}` // 10-19
|
|
274
|
+
| `2${"0" | "1" | "2" | "3"}`; // 20-23
|
|
275
|
+
|
|
276
|
+
/** Numeric string 1-51. Useful for weeks validation. */
|
|
277
|
+
export type Digit1To51 =
|
|
278
|
+
| Digit1To9 // 1-9
|
|
279
|
+
| `${"1" | "2" | "3" | "4"}${Digit}` // 10-49
|
|
280
|
+
| `5${"0" | "1"}`; // 50-51
|
|
281
|
+
|
|
282
|
+
/** Numeric string 1-99. Useful for years validation. */
|
|
283
|
+
export type Digit1To99 =
|
|
284
|
+
| Digit1To9 // 1-9
|
|
285
|
+
| `${Digit1To9}${Digit}`; // 10-99
|
|
286
|
+
|
|
287
|
+
/** Numeric string 1-59. Useful for minutes, seconds validation. */
|
|
288
|
+
export type Digit1To59 =
|
|
289
|
+
| Digit1To9 // 1-9
|
|
290
|
+
| `1${Digit}` // 10-19
|
|
291
|
+
| `2${Digit}` // 20-29
|
|
292
|
+
| `3${Digit}` // 30-39
|
|
293
|
+
| `4${Digit}` // 40-49
|
|
294
|
+
| `5${Digit}`; // 50-59
|
|
295
|
+
|
|
296
|
+
/** Numeric literal 1-99. */
|
|
297
|
+
export type Int1To99 = NumberFromString<Digit1To99>;
|
|
298
|
+
|
|
299
|
+
/** Numeric literal 1-100. */
|
|
300
|
+
export type Int1To100 = Int1To99 | 100;
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Parses a numeric literal type from a string literal.
|
|
304
|
+
*
|
|
305
|
+
* Used by {@link Int1To99}.
|
|
306
|
+
*/
|
|
307
|
+
export type NumberFromString<T extends string> =
|
|
308
|
+
T extends `${infer N extends number}` ? N : never;
|
|
309
|
+
|
|
310
|
+
/** Converts a union to an intersection. */
|
|
311
|
+
export type UnionToIntersection<U> = (
|
|
312
|
+
U extends unknown ? (k: U) => void : never
|
|
313
|
+
) extends (k: infer I) => void
|
|
314
|
+
? I
|
|
315
|
+
: never;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Removes keys from each member of a union.
|
|
319
|
+
*
|
|
320
|
+
* Use when {@link Omit} would collapse a discriminated union into a single
|
|
321
|
+
* shared shape.
|
|
322
|
+
*
|
|
323
|
+
* ### Example
|
|
324
|
+
*
|
|
325
|
+
* ```ts
|
|
326
|
+
* type Event =
|
|
327
|
+
* | { type: "a"; a: string; shared: number }
|
|
328
|
+
* | { type: "b"; b: number; shared: number };
|
|
329
|
+
*
|
|
330
|
+
* type Payload = DistributiveOmit<Event, "shared">;
|
|
331
|
+
* // { type: "a"; a: string } | { type: "b"; b: number }
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
export type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
|
|
335
|
+
? Omit<T, K>
|
|
336
|
+
: never;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Extracts members of a discriminated union by their `type` literal.
|
|
340
|
+
*
|
|
341
|
+
* Constrains `TType` to valid `type` values, so typos fail at the type argument
|
|
342
|
+
* instead of silently producing `never`.
|
|
343
|
+
*
|
|
344
|
+
* ### Example
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* type Message =
|
|
348
|
+
* | { readonly type: "Create"; readonly id: string }
|
|
349
|
+
* | { readonly type: "Delete"; readonly id: string };
|
|
350
|
+
*
|
|
351
|
+
* type CreateMessage = ExtractType<Message, "Create">;
|
|
352
|
+
* // { readonly type: "Create"; readonly id: string }
|
|
353
|
+
*
|
|
354
|
+
* // Type error: "Cretae" is not a valid Message type
|
|
355
|
+
* type _Typo = ExtractType<Message, "Cretae">;
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export type ExtractType<
|
|
359
|
+
TUnion extends { readonly type: TypeName },
|
|
360
|
+
TType extends TUnion["type"],
|
|
361
|
+
> = Extract<TUnion, { readonly type: TType }>;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Constrains `T` to only contain keys not present in `Existing`.
|
|
365
|
+
*
|
|
366
|
+
* Use as a generic constraint to prevent overriding existing properties.
|
|
367
|
+
*/
|
|
368
|
+
export type NewKeys<T, Existing> = {
|
|
369
|
+
[K in keyof T]: K extends keyof Existing ? never : T[K];
|
|
370
|
+
};
|