@sevtech/kit 20.3.3 → 21.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/misc/index.d.ts CHANGED
@@ -60,7 +60,7 @@ type ID = `${number}` | number;
60
60
  type UUID = `${string}-${string}-${string}-${string}-${string}`;
61
61
  /**
62
62
  * Тип конструктора класса
63
- */
63
+ */
64
64
  type ConstructorTypeOf<T> = new (...args: SafeAny[]) => T;
65
65
  /**
66
66
  * Все примитивные типы TypeScript
@@ -81,7 +81,7 @@ type Primitive = string | number | bigint | boolean | symbol | null | undefined;
81
81
  * type T = ExtractType<string[]>; // string
82
82
  * type T = ExtractType<Set<number>>; // number
83
83
  */
84
- type ExtractType<T> = T extends (Array<infer U> | Set<infer U> | Map<PropertyKey, infer U> | WeakMap<WeakKey, infer U> | WeakSet<infer U> | Record<PropertyKey, infer U>) ? U : never;
84
+ type ExtractType<T> = T extends WeakSet<infer U> ? U : T extends Array<infer U> | Set<infer U> | Map<PropertyKey, infer U> | WeakMap<WeakKey, infer U> | Record<PropertyKey, infer U> ? U : never;
85
85
 
86
86
  /**
87
87
  * Допустимые CSS единицы измерения
@@ -235,7 +235,7 @@ declare function coalesce<Arg>(...args: Arg[]): NonNullable<Arg> | null;
235
235
  * safeFnCall(console.log, 'test') // выводит 'test'
236
236
  * safeFnCall(undefined, 'test') // undefined
237
237
  */
238
- declare function safeFnCall<Fn extends ((...args: SafeAny[]) => SafeAny)>(fn: Fn | undefined, ...args: Parameters<Fn>): ReturnType<Fn> | undefined;
238
+ declare function safeFnCall<Fn extends (...args: SafeAny[]) => SafeAny>(fn: Fn | undefined, ...args: Parameters<Fn>): ReturnType<Fn> | undefined;
239
239
  /**
240
240
  * Преобразует значение или массив значений в массив
241
241
  * @example
@@ -288,27 +288,58 @@ declare function safeParseJSON<ReturnType, Fallback = null>(json: string | null,
288
288
 
289
289
  /**
290
290
  * Типизированная обёртка для Object.keys()
291
+ * @description
292
+ * Возвращает только собственные перечисляемые ключи: унаследованные,
293
+ * неперечисляемые и символьные пропускаются - как в Object.keys().
291
294
  * @example
292
295
  * objectKeys({ a: 1, b: 2 }) // ['a', 'b'] с типом ('a' | 'b')[]
293
296
  * objectKeys([1, 2, 3]) // ['0', '1', '2'] с типом string[]
294
- * objectKeys('test') // [] с типом string[]
295
- * objectKeys(null) // Ошибка типа
297
+ * objectKeys('test') // ['0', '1', '2', '3'] с типом string[]
298
+ * objectKeys(null) // тип never, в рантайме TypeError
296
299
  */
297
300
  declare function objectKeys<T extends Nil>(object: T): never;
298
301
  declare function objectKeys<T extends Primitive | SafeAny[]>(object: T): string[];
299
- declare function objectKeys<T extends Record<PropertyKey, SafeAny>>(object: T): Array<keyof T>;
302
+ declare function objectKeys<T extends Record<PropertyKey, SafeAny>>(object: T): Array<Exclude<keyof T, symbol>>;
303
+ /** Ключи, которые попадают в Object.entries(): символьные пропускаются. */
304
+ type EntryKey<T> = Exclude<keyof T, symbol>;
305
+ /**
306
+ * Пары [ключ, значение] с сохранением связи конкретного ключа с типом его
307
+ * значения. Ключ приводится к строке — Object.entries() возвращает строки.
308
+ */
309
+ type ObjectEntry<T> = {
310
+ [Key in EntryKey<T>]-?: [`${Key}`, T[Key]];
311
+ }[EntryKey<T>];
300
312
  /**
301
313
  * Типизированная обёртка для Object.entries()
314
+ * @description
315
+ * - Сохраняет связь конкретного ключа с типом его значения
316
+ * - Символьные ключи пропускаются, числовые приводятся к строкам - как в Object.entries()
317
+ * - Set и Map возвращают [] - их содержимое не лежит в собственных свойствах
318
+ *
319
+ * Связь ключа и значения доступна при сужении по ключу, но теряется при
320
+ * деструктуризации - это ограничение TypeScript:
321
+ * ```ts
322
+ * for (const entry of objectEntries({ a: 1, b: '2' })) {
323
+ * if (entry[0] === 'a') entry[1]; // number
324
+ * else entry[1]; // string
325
+ * }
326
+ *
327
+ * objectEntries({ a: 1, b: '2' }).map(([key, value]) => value); // string | number
328
+ * ```
329
+ *
302
330
  * @example
303
331
  * objectEntries({ a: 1, b: '2' }) // [['a', 1], ['b', '2']] с типом (['a', number] | ['b', string])[]
332
+ * objectEntries({ 1: 'a' }) // [['1', 'a']] с типом ['1', string][]
304
333
  * objectEntries([10, 20]) // [['0', 10], ['1', 20]] с типом [string, number][]
334
+ * objectEntries('ab') // [['0', 'a'], ['1', 'b']] с типом [string, string][]
305
335
  * objectEntries(new Set([1,2])) // [] с типом []
306
- * objectEntries('test') // [] с типом []
336
+ * objectEntries(null) // тип never, в рантайме TypeError
307
337
  */
308
338
  declare function objectEntries<T extends Nil>(object: T): never;
339
+ declare function objectEntries<T extends string>(object: T): [string, string][];
309
340
  declare function objectEntries<T extends Set<SafeAny> | Map<SafeAny, SafeAny> | Primitive>(object: T): [];
310
- declare function objectEntries<T extends SafeAny[]>(object: T): [string, keyof T][];
311
- declare function objectEntries<T extends Record<Readonly<string>, SafeAny>>(object: T): Array<[keyof T, T[keyof T]]>;
341
+ declare function objectEntries<T extends SafeAny[]>(object: T): [string, T[number]][];
342
+ declare function objectEntries<T extends Record<Readonly<string>, SafeAny>>(object: T): ObjectEntry<T>[];
312
343
  declare function objectEntries<T>(object: Record<string, T> | ArrayLike<T>): [string, T][];
313
344
 
314
345
  /**
@@ -396,9 +427,7 @@ declare function isEmptyArray<T>(data: unknown): data is T[];
396
427
  * }
397
428
  */
398
429
  declare function isNonEmptyArray<T>(data: unknown): data is T[];
399
- type PlainObject<T> = [
400
- unknown
401
- ] extends [T] ? Record<PropertyKey, unknown> : T extends object ? T extends Iterable<SafeAny> ? never : T : never;
430
+ type PlainObject<T> = [unknown] extends [T] ? Record<PropertyKey, unknown> : T extends object ? T extends Iterable<SafeAny> ? never : T : never;
402
431
  /**
403
432
  * Проверяет, является ли значение простым объектом (не массивом, не классом)
404
433
  * @example
@@ -1,8 +1,9 @@
1
1
  import { Observable, Subscriber } from 'rxjs';
2
2
  import { Route } from '@angular/router';
3
- import { ComponentRef, OutputRef, QueryList, InputSignalWithTransform, InjectionToken, ViewContainerRef } from '@angular/core';
3
+ import { ComponentRef, OutputRef, QueryList, InputSignalWithTransform, InjectionToken, ViewContainerRef, Provider } from '@angular/core';
4
4
  import { FormArray, FormControl, FormGroup, FormRecord } from '@angular/forms';
5
5
  import { NgComponentOutlet } from '@angular/common';
6
+ import { MaybeArray } from '@sevtech/kit/misc';
6
7
 
7
8
  /**
8
9
  * Создаёт Observable который эмитит при изменении размеров элемента
@@ -195,5 +196,32 @@ declare function isComponentRef<Instance>(data: unknown): data is ComponentRef<I
195
196
  */
196
197
  declare function isComponentOutlet(data: unknown): data is NgComponentOutlet;
197
198
 
198
- export { htmlBooleanAttribute, isComponentOutlet, isComponentRef, isFormArray, isFormControl, isFormGroup, isFormRecord, isViewContainer, resizeObservable };
199
- export type { DataRoute, DataRoutes, ExtractAsync, ExtractComponentRef, ExtractFormArray, ExtractFormControl, ExtractFormGroup, ExtractFormRecord, ExtractOutputs, ExtractQueryList, ExtractSignalInputs, ExtractTokenType, MaybeAsync };
199
+ /** Публичный маркер: объект-«фича», возвращаемый withXxx()-функциями. */
200
+ interface KitFeature<TKind extends number = number> {
201
+ readonly ɵkind: TKind;
202
+ readonly ɵproviders: Provider[];
203
+ }
204
+ /**
205
+ * Создаёт withXxx()-функцию: связывает вид фичи с фабрикой её провайдеров.
206
+ * @description Вид задаётся локальным `const enum`, поэтому фича одного
207
+ * модуля не пройдёт в `provide*` другого.
208
+ * @example
209
+ * const enum FeatureKind { Prefix }
210
+ *
211
+ * export const withPrefix = defineKitFeature(
212
+ * FeatureKind.Prefix,
213
+ * (prefix: string) => ({ provide: API_PREFIX, useValue: prefix }),
214
+ * );
215
+ */
216
+ declare function defineKitFeature<Kind extends number, Args extends unknown[]>(kind: Kind, build: (...args: Args) => MaybeArray<Provider>): (...args: Args) => KitFeature<Kind>;
217
+ /** Собирает Provider[] со всех переданных KitFeature-объектов. */
218
+ declare function collectFeatureProviders(...items: unknown[]): Provider[];
219
+ /**
220
+ * Резолвит Provider[] для параметра, который может быть
221
+ * либо «сырым» конфигом, либо уже готовой KitFeature (тогда пропускается —
222
+ * её обработает collectFeatureProviders).
223
+ */
224
+ declare function resolveConfigProviders<TConfig>(config: TConfig, handler: (config: Exclude<TConfig, KitFeature>) => MaybeArray<Provider>): Provider[];
225
+
226
+ export { collectFeatureProviders, defineKitFeature, htmlBooleanAttribute, isComponentOutlet, isComponentRef, isFormArray, isFormControl, isFormGroup, isFormRecord, isViewContainer, resizeObservable, resolveConfigProviders };
227
+ export type { DataRoute, DataRoutes, ExtractAsync, ExtractComponentRef, ExtractFormArray, ExtractFormControl, ExtractFormGroup, ExtractFormRecord, ExtractOutputs, ExtractQueryList, ExtractSignalInputs, ExtractTokenType, KitFeature, MaybeAsync };
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@sevtech/kit",
3
- "version": "20.3.3",
3
+ "version": "21.0.0",
4
4
  "sideEffects": false,
5
- "publishConfig": {
6
- "access": "public"
7
- },
8
5
  "dependencies": {
9
6
  "tslib": "^2.3.0"
10
7
  },
@@ -12,8 +9,8 @@
12
9
  "@angular/common": "^20.0.0",
13
10
  "@angular/core": "^20.0.0",
14
11
  "@angular/forms": "^20.0.0",
15
- "@angular/router": "^20.0.0",
16
12
  "@angular/platform-browser": "^20.0.0",
13
+ "@angular/router": "^20.0.0",
17
14
  "@ngx-translate/core": "^17.0.0",
18
15
  "@ngx-translate/http-loader": "17.0.0",
19
16
  "primeng": "^20.0.0",
@@ -26,10 +23,10 @@
26
23
  "@angular/core": {
27
24
  "optional": true
28
25
  },
29
- "@angular/platform-browser": {
26
+ "@angular/forms": {
30
27
  "optional": true
31
28
  },
32
- "@angular/forms": {
29
+ "@angular/platform-browser": {
33
30
  "optional": true
34
31
  },
35
32
  "@angular/router": {
@@ -48,6 +45,9 @@
48
45
  "optional": true
49
46
  }
50
47
  },
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
51
  "module": "fesm2022/sevtech-kit.mjs",
52
52
  "typings": "index.d.ts",
53
53
  "exports": {