@xaendar/types 0.10.7 → 0.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.
@@ -0,0 +1,271 @@
1
+ /**
2
+ * An abstract constructor function type that can accept any number of arguments
3
+ * and return an instance of the specified type.
4
+ */
5
+ export declare type AbstractConstructor<T extends object = object, Statics extends Record<string, unknown> | undefined = undefined> = (abstract new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
6
+
7
+ /**
8
+ * Represents a class accessor decorator function.
9
+ *
10
+ * Note: the `context` parameter uses `Field` (not `ReturnTypeField`) because
11
+ * `ClassAccessorDecoratorContext` is tied to the original field type.
12
+ *
13
+ * @template Class - The class that owns the decorated accessor.
14
+ * @template Value - The original type of the accessor's value.
15
+ * @template ActualValue - The type returned/set by the replacement accessor (defaults to `InitialValue`).
16
+ */
17
+ export declare type AccessorDecorator<Class extends object, Value = unknown> = (value: ClassAccessorDecoratorValue<Value>, context: ClassAccessorDecoratorContext<Class, Value>) => {
18
+ /**
19
+ * Replacement getter returning a value of `Value`.
20
+ */
21
+ get?(this: Class): Value;
22
+ /**
23
+ * Replacement setter accepting a value of `Value`.
24
+ */
25
+ set?(this: Class, value: Value): void;
26
+ /**
27
+ * Initializer called with the original field value; should return a `Value`.
28
+ */
29
+ init?(this: Class, initialValue: Value): Value;
30
+ } | void;
31
+
32
+ /**
33
+ * A function type that can accept any number of arguments and return a promise of any type.
34
+ */
35
+ export declare type AsyncFunction<Arguments extends any[] = any[], ReturnType = void> = Arguments extends Array<any> ? (...args: Arguments) => Promise<ReturnType> : () => Promise<ReturnType>;
36
+
37
+ /**
38
+ * Flattens the display of an intersection or mapped type so that IDEs show
39
+ * the resolved property list instead of the raw intersection expression.
40
+ *
41
+ * Useful for improving hover information on complex composed types.
42
+ *
43
+ * @template T - The object type to beautify.
44
+ *
45
+ * @example
46
+ * type Merged = Beautify<{ a: string } & { b: number }>;
47
+ * // Hovering shows: { a: string; b: number }
48
+ */
49
+ export declare type Beautify<T extends Object> = {
50
+ [K in keyof T]: T[K];
51
+ } & {};
52
+
53
+ /**
54
+ * Represents the accessor descriptor passed to a class accessor decorator,
55
+ * containing the original `get` and `set` methods of the decorated accessor.
56
+ *
57
+ * @template Field - The type of the accessor's value.
58
+ */
59
+ export declare type ClassAccessorDecoratorValue<Field = unknown> = {
60
+ /**
61
+ * Returns the current value of the accessor.
62
+ */
63
+ get(this: unknown): Field;
64
+ /**
65
+ * Sets the value of the accessor.
66
+ */
67
+ set(this: unknown, value: Field): void;
68
+ };
69
+
70
+ /**
71
+ * Represents a TC39 stage-3 class decorator function.
72
+ *
73
+ * Receives the class constructor and its decorator context and may return a
74
+ * replacement constructor or `void` to leave the original unchanged.
75
+ *
76
+ * @template T - The instance type of the decorated class.
77
+ * @template Statics - Optional static members of the class.
78
+ */
79
+ declare type ClassDecorator_2<T extends Object, Statics extends {
80
+ [key: string]: any;
81
+ } = {
82
+ [key: string]: any;
83
+ }> = (klass: Constructor<T, Statics>, context: ClassDecoratorContext) => void;
84
+ export { ClassDecorator_2 as ClassDecorator }
85
+
86
+ /**
87
+ * A constructor function type that can accept any number of arguments and return an instance of any type.
88
+ */
89
+ export declare type Constructor<T extends object = object, Statics extends Record<string, unknown> | undefined = undefined> = (new (...args: any[]) => T) & (Statics extends undefined ? object : Statics);
90
+
91
+ /**
92
+ * Recursively checks whether a string literal type contains a specific
93
+ * single-character substring.
94
+ *
95
+ * Resolves to `true` if `Contains` is found anywhere in `String`,
96
+ * or `false` if it is absent.
97
+ *
98
+ * @template String - The string literal type to inspect.
99
+ * @template Contains - The single character to search for.
100
+ *
101
+ * @example
102
+ * type HasMinus = ContainsChar<'-1', '-'>; // true
103
+ * type HasDot = ContainsChar<'42', '.'>; // false
104
+ */
105
+ export declare type ContainsChar<String extends string, Contains extends string> = String extends `${infer First}${infer Rest}` ? First extends Contains ? true : ContainsChar<Rest, Contains> : false;
106
+
107
+ /**
108
+ * A strongly-typed key/value map where every value is optional.
109
+ *
110
+ * Useful as a looser alternative to `Record<K, V>` when not all keys
111
+ * are guaranteed to be present.
112
+ *
113
+ * @template Key - The allowed key type. Must be a string or number.
114
+ * @template Value - The type of each value. Defaults to `string`.
115
+ *
116
+ * @example
117
+ * const headers: Dictionary<string, string> = { 'Content-Type': 'application/json' };
118
+ */
119
+ export declare type Dictionary<Key extends string | number, Value = string> = {
120
+ [K in Key]?: Value;
121
+ };
122
+
123
+ /**
124
+ * Represents a TC39 stage-3 class field decorator function.
125
+ *
126
+ * Receives the initial `undefined` value and the field decorator context.
127
+ * Returns an initializer that maps the declared field value to its stored
128
+ * (possibly transformed) representation.
129
+ *
130
+ * @template Class - The class that owns the decorated field.
131
+ * @template Field - The declared type of the field.
132
+ * @template ReturnType - The type the initializer transforms the value into. Defaults to `Field`.
133
+ */
134
+ export declare type FieldDecorator<Class extends Object, Field, ReturnType = Field> = (field: undefined, context: ClassFieldDecoratorContext<Class, Field>) => ((value: Field) => ReturnType);
135
+
136
+ /**
137
+ * A function type that can accept any number of arguments and return any type.
138
+ */
139
+ declare type Function_2<Arguments extends any[] = any[], ReturnType = void> = Arguments extends Array<any> ? (...args: Arguments) => ReturnType : () => ReturnType;
140
+ export { Function_2 as Function }
141
+
142
+ /**
143
+ * Represents a TC39 stage-3 class method decorator function.
144
+ *
145
+ * Receives the original method and its decorator context, and may return a
146
+ * replacement method or `void` to leave the original unchanged.
147
+ *
148
+ * @template T - The class that owns the decorated method.
149
+ * @template Method - The type of the method being decorated.
150
+ */
151
+ declare type MethodDecorator_2<T extends Object, Method extends Function_2> = (value: Method, context: ClassMethodDecoratorContext<T, Method>) => Method | void;
152
+ export { MethodDecorator_2 as MethodDecorator }
153
+
154
+ /**
155
+ * Removes the `readonly` modifier from every property of an object type,
156
+ * producing a fully mutable version.
157
+ *
158
+ * The inverse of `Readonly<T>`.
159
+ *
160
+ * @template T - The object type whose properties should become mutable.
161
+ *
162
+ * @example
163
+ * type MutablePoint = Mutable<{ readonly x: number; readonly y: number }>;
164
+ * // { x: number; y: number }
165
+ */
166
+ export declare type Mutable<T extends Object> = {
167
+ -readonly [P in keyof T]: T[P];
168
+ };
169
+
170
+ /**
171
+ * An async function type that accepts no arguments and returns a promise of the specified type.
172
+ * @template ReturnType - The type that the promise resolves to (defaults to void)
173
+ * @example
174
+ * type FetchUser = NoArgsAsyncFunction<User>;
175
+ * const fetchUser: FetchUser = async () => await api.getUser();
176
+ */
177
+ export declare type NoArgsAsyncFunction<ReturnType = void> = () => Promise<ReturnType>;
178
+
179
+ /**
180
+ * An async function type that accepts arguments but always resolves to void.
181
+ */
182
+ export declare type NoArgsAsyncVoidFunction = () => Promise<void>;
183
+
184
+ /**
185
+ * A function type that accepts no arguments and returns a value of the specified type.
186
+ * Also known as a 'thunk' in functional programming.
187
+ * @template ReturnType - The return type of the function (defaults to void)
188
+ * @example
189
+ * type GetUser = NoArgsFunction<User>;
190
+ * const getUser: GetUser = () => ({ id: 1, name: 'John' });
191
+ */
192
+ export declare type NoArgsFunction<ReturnType = void> = () => ReturnType;
193
+
194
+ /**
195
+ * A function type that accepts arguments but always returns void.
196
+ */
197
+ export declare type NoArgsVoidFunction = () => void;
198
+
199
+ /**
200
+ * Resolves to `Value` when it is a positive integer, or `never` otherwise.
201
+ *
202
+ * Rejects negative numbers (contain `'-'`) and non-integer numbers (contain `'.'`).
203
+ * Useful as a compile-time constraint for length or count parameters.
204
+ *
205
+ * @template Value - The numeric literal to validate.
206
+ *
207
+ * @example
208
+ * type Valid = PositiveInteger<5>; // 5
209
+ * type Invalid = PositiveInteger<-1>; // never
210
+ * type Float = PositiveInteger<1.5>; // never
211
+ */
212
+ export declare type PositiveInteger<Value extends number> = ContainsChar<`${Value}`, '-'> extends true ? never : ContainsChar<`${Value}`, '.'> extends true ? never : Value;
213
+
214
+ /**
215
+ * Creates a type from `T` where at least one of the specified `Keys` must
216
+ * be provided, while the remaining keys stay optional.
217
+ *
218
+ * Useful for option bags where a minimum of one field is required to avoid
219
+ * ambiguous or meaningless configurations.
220
+ *
221
+ * @template T - The base object type.
222
+ * @template Keys - The subset of keys of which at least one must be present.
223
+ * Defaults to all keys of `T`.
224
+ *
225
+ * @example
226
+ * type SearchParams = RequireOne<{ query?: string; id?: number }>;
227
+ * // Valid: { query: 'foo' } | { id: 42 } | { query: 'foo', id: 42 }
228
+ * // Invalid: {} (TypeScript error)
229
+ */
230
+ export declare type RequireOne<T extends Object, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyof T, Keys>> & {
231
+ [K in Keys]-?: Required<Pick<T, K>> & Partial<Pick<T, Exclude<Keys, K>>>;
232
+ }[Keys];
233
+
234
+ /**
235
+ * Constructs a fixed-length tuple of type `TupleType` with exactly `Length`
236
+ * elements.
237
+ *
238
+ * Resolves to `never` when `Length` is not a positive integer.
239
+ *
240
+ * @template Length - The number of elements. Must be a positive integer.
241
+ * @template TupleType - The element type. Defaults to `number`.
242
+ * @template Acc - Internal accumulator (do not provide manually).
243
+ *
244
+ * @example
245
+ * type Three = TupleOfLength<3, string>; // [string, string, string]
246
+ * type Bad = TupleOfLength<0, string>; // never
247
+ */
248
+ export declare type TupleOfLength<Length extends number, TupleType = number, Acc extends TupleType[] = []> = PositiveInteger<Length> extends never ? never : Acc['length'] extends Length ? Acc : TupleOfLength<Length, TupleType, [...Acc, TupleType]>;
249
+
250
+ /**
251
+ * An async function type that accepts arguments but always resolves to void.
252
+ * Typically used for async callbacks or side-effect functions.
253
+ * @template Arguments - The types of the function arguments
254
+ * @example
255
+ * type OnUserChangeAsync = VoidAsyncFunction<[user: User]>;
256
+ * const handleUserChangeAsync: OnUserChangeAsync = async (user) => await api.logChange(user);
257
+ */
258
+ export declare type VoidAsyncFunction<Arguments extends any[] = any[]> = (...args: Arguments) => Promise<void>;
259
+
260
+ /**
261
+ * A function type that accepts arguments but always returns void.
262
+ * Typically used for callbacks, event handlers, or side-effect functions.
263
+ * @template Arguments - The types of the function arguments
264
+ * @example
265
+ * type OnUserChange = VoidFunction<[user: User]>;
266
+ * const handleUserChange: OnUserChange = (user) => console.log(user);
267
+ */
268
+ declare type VoidFunction_2<Arguments extends any[] = any[]> = (...args: Arguments) => void;
269
+ export { VoidFunction_2 as VoidFunction }
270
+
271
+ export { }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xaendar/types",
3
- "version": "0.10.7",
3
+ "version": "0.11.0",
4
4
  "description": "A library containing common types shared across packages and consumers",
5
5
  "sideEffects": false,
6
6
  "type": "module",