@zinaid/types 0.0.1 → 0.0.3
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 +3 -0
- package/package.json +32 -4
- package/src/arrays.d.ts +34 -0
- package/src/collections.d.ts +2 -0
- package/src/data.d.ts +19 -0
- package/src/index.d.ts +10 -0
- package/src/models.d.ts +43 -0
- package/src/objects.d.ts +8 -0
- package/src/pagination.d.ts +43 -0
- package/src/path-type.d.ts +74 -0
- package/src/responses.d.ts +25 -0
- package/src/strings.d.ts +3 -0
- package/src/utils.d.ts +0 -0
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,21 +1,49 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zinaid/types",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "Utility TypeScript types for @zinaid packages and Laravel HTTP responses.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "src/index.d.ts",
|
|
7
7
|
"keywords": [],
|
|
8
8
|
"author": "",
|
|
9
9
|
"license": "MIT",
|
|
10
|
+
"sideEffects": false,
|
|
10
11
|
"files": [
|
|
11
|
-
"
|
|
12
|
+
"src"
|
|
12
13
|
],
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
15
16
|
"types": "./src/index.d.ts"
|
|
16
17
|
},
|
|
17
|
-
"
|
|
18
|
-
"types": "./src
|
|
18
|
+
"./arrays": {
|
|
19
|
+
"types": "./src/arrays.d.ts"
|
|
20
|
+
},
|
|
21
|
+
"./collections": {
|
|
22
|
+
"types": "./src/collections.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./data": {
|
|
25
|
+
"types": "./src/data.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./models": {
|
|
28
|
+
"types": "./src/models.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./objects": {
|
|
31
|
+
"types": "./src/objects.d.ts"
|
|
32
|
+
},
|
|
33
|
+
"./pagination": {
|
|
34
|
+
"types": "./src/pagination.d.ts"
|
|
35
|
+
},
|
|
36
|
+
"./path-type": {
|
|
37
|
+
"types": "./src/path-type.d.ts"
|
|
38
|
+
},
|
|
39
|
+
"./responses": {
|
|
40
|
+
"types": "./src/responses.d.ts"
|
|
41
|
+
},
|
|
42
|
+
"./strings": {
|
|
43
|
+
"types": "./src/strings.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./utils": {
|
|
46
|
+
"types": "./src/utils.d.ts"
|
|
19
47
|
}
|
|
20
48
|
},
|
|
21
49
|
"scripts": {
|
package/src/arrays.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface Arrayable<TValue> {
|
|
2
|
+
toArray(): TValue[];
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export interface ArrayAccess<TValue> {
|
|
6
|
+
offsetExists(offset: number | string): boolean;
|
|
7
|
+
offsetGet(offset: number | string): TValue | undefined;
|
|
8
|
+
offsetSet(offset: number | string, value: TValue): void;
|
|
9
|
+
offsetUnset(offset: number | string): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ArrayInnerValue<X> = X extends ReadonlyArray<infer U> ? U : never;
|
|
13
|
+
|
|
14
|
+
export type ArrayItems<T> = T[] | Array<T>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper type to check if an array is mutable (not readonly)
|
|
18
|
+
*/
|
|
19
|
+
type IsMutableArray<T> = T extends readonly unknown[]
|
|
20
|
+
? T extends unknown[]
|
|
21
|
+
? true
|
|
22
|
+
: false
|
|
23
|
+
: false;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Helper type to add a value to an array type.
|
|
27
|
+
* Excludes readonly arrays as they cannot be mutated.
|
|
28
|
+
*/
|
|
29
|
+
export type AddToArray<T extends unknown[], V> =
|
|
30
|
+
IsMutableArray<T> extends true
|
|
31
|
+
? T extends Array<infer U>
|
|
32
|
+
? Array<U | V>
|
|
33
|
+
: never
|
|
34
|
+
: never;
|
package/src/data.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type DataItems<TValue, TKey extends PropertyKey = PropertyKey> =
|
|
2
|
+
| TValue[]
|
|
3
|
+
| Record<TKey, TValue>;
|
|
4
|
+
|
|
5
|
+
export interface Countable {
|
|
6
|
+
count(): number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IteratorAggregate<TValue, TKey> {
|
|
10
|
+
getIterator(): IterableIterator<[TKey, TValue]>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Jsonable {
|
|
14
|
+
toJson(): string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface JsonSerializable {
|
|
18
|
+
jsonSerialize(): unknown;
|
|
19
|
+
}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type * from "./arrays";
|
|
2
|
+
export type * from "./collections";
|
|
3
|
+
export type * from "./data";
|
|
4
|
+
export type * from "./models";
|
|
5
|
+
export type * from "./objects";
|
|
6
|
+
export type * from "./pagination";
|
|
7
|
+
export type * from "./path-type";
|
|
8
|
+
export type * from "./responses";
|
|
9
|
+
export type * from "./strings";
|
|
10
|
+
export type * from "./utils";
|
package/src/models.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface Model {
|
|
2
|
+
id?: string | number;
|
|
3
|
+
[key: string]: unknown;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export interface Timestamps {
|
|
7
|
+
created_at: string | null;
|
|
8
|
+
updated_at: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface SoftDeletes {
|
|
12
|
+
deleted_at: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TimestampModel extends Model, Timestamps {}
|
|
16
|
+
export interface SoftDeleteModel extends Model, SoftDeletes {}
|
|
17
|
+
export interface AllTimestampsModel extends Model, Timestamps, SoftDeletes {}
|
|
18
|
+
|
|
19
|
+
export type AsCount<T extends string> = `${T}_count`;
|
|
20
|
+
export type AsMax<T extends string> = `${T}_max`;
|
|
21
|
+
export type AsMin<T extends string> = `${T}_min`;
|
|
22
|
+
export type AsSum<T extends string> = `${T}_sum`;
|
|
23
|
+
export type AsAvg<T extends string> = `${T}_avg`;
|
|
24
|
+
export type AsExists<T extends string> = `${T}_exists`;
|
|
25
|
+
|
|
26
|
+
export type WithCount<Relations extends string> = {
|
|
27
|
+
[K in Relations as AsCount<K>]: number;
|
|
28
|
+
};
|
|
29
|
+
export type WithMax<Relations extends string> = {
|
|
30
|
+
[K in Relations as AsMax<K>]: number | null;
|
|
31
|
+
};
|
|
32
|
+
export type WithMin<Relations extends string> = {
|
|
33
|
+
[K in Relations as AsMin<K>]: number | null;
|
|
34
|
+
};
|
|
35
|
+
export type WithSum<Relations extends string> = {
|
|
36
|
+
[K in Relations as AsSum<K>]: number | null;
|
|
37
|
+
};
|
|
38
|
+
export type WithAvg<Relations extends string> = {
|
|
39
|
+
[K in Relations as AsAvg<K>]: number | null;
|
|
40
|
+
};
|
|
41
|
+
export type WithExists<Relations extends string> = {
|
|
42
|
+
[K in Relations as AsExists<K>]: boolean;
|
|
43
|
+
};
|
package/src/objects.d.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export interface SimplePaginator<T> {
|
|
2
|
+
current_page: number;
|
|
3
|
+
data: T[];
|
|
4
|
+
first_page_url: string;
|
|
5
|
+
from: number;
|
|
6
|
+
next_page_url: string | null;
|
|
7
|
+
path: string;
|
|
8
|
+
per_page: number;
|
|
9
|
+
prev_page_url: string | null;
|
|
10
|
+
to: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface LengthAwarePaginator<T> {
|
|
14
|
+
current_page: number;
|
|
15
|
+
data: T[];
|
|
16
|
+
first_page_url: string;
|
|
17
|
+
from: number;
|
|
18
|
+
last_page: number;
|
|
19
|
+
last_page_url: string;
|
|
20
|
+
links: PaginatorLink[];
|
|
21
|
+
next_page_url: string | null;
|
|
22
|
+
path: string;
|
|
23
|
+
per_page: number;
|
|
24
|
+
prev_page_url: string | null;
|
|
25
|
+
to: number;
|
|
26
|
+
total: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface CursorPaginator<T> {
|
|
30
|
+
data: T[];
|
|
31
|
+
path: string;
|
|
32
|
+
per_page: number;
|
|
33
|
+
next_cursor: string | null;
|
|
34
|
+
next_page_url: string | null;
|
|
35
|
+
prev_cursor: string | null;
|
|
36
|
+
prev_page_url: string | null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PaginatorLink {
|
|
40
|
+
url: string | null;
|
|
41
|
+
label: string;
|
|
42
|
+
active: boolean;
|
|
43
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A key used to access a path in an object or array.
|
|
3
|
+
*/
|
|
4
|
+
export type PathKey = number | string | null | undefined;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A set of keys used to access a path in an object or array.
|
|
8
|
+
*/
|
|
9
|
+
export type PathKeys = number | string | null | undefined | Array<PathKey>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Unwraps a value or function that returns a value.
|
|
13
|
+
*/
|
|
14
|
+
export type UnwrapFn<T> = T extends (...args: unknown[]) => infer R ? R : T;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper to get array element type
|
|
18
|
+
*/
|
|
19
|
+
type ArrayElement<T> = T extends readonly (infer U)[] ? U : never;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Helper to check if a type is an array
|
|
23
|
+
*/
|
|
24
|
+
type IsArray<T> = T extends readonly unknown[] ? true : false;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Helper to check if a type is a tuple with at least one element
|
|
28
|
+
*/
|
|
29
|
+
type IsTuple<T> = T extends readonly [unknown, ...unknown[]]
|
|
30
|
+
? true
|
|
31
|
+
: T extends readonly []
|
|
32
|
+
? true
|
|
33
|
+
: false;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Helper to get element at specific index in tuple
|
|
37
|
+
* For unions of tuples, returns the union of elements at that index
|
|
38
|
+
*/
|
|
39
|
+
type TupleElement<
|
|
40
|
+
T extends readonly unknown[],
|
|
41
|
+
N extends number,
|
|
42
|
+
> = T extends readonly unknown[]
|
|
43
|
+
? N extends keyof T
|
|
44
|
+
? T[N]
|
|
45
|
+
: ArrayElement<T>
|
|
46
|
+
: never;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Gets the type of a value at a given path in an object or array.
|
|
50
|
+
* Supports dot notation (a.b.c) and array indexing (a.0.b).
|
|
51
|
+
*/
|
|
52
|
+
export type GetFieldType<
|
|
53
|
+
T,
|
|
54
|
+
P extends string | number,
|
|
55
|
+
TDefault = never,
|
|
56
|
+
> = P extends keyof T
|
|
57
|
+
? T[P]
|
|
58
|
+
: P extends `${infer First}.${infer Rest}`
|
|
59
|
+
? First extends keyof T
|
|
60
|
+
? GetFieldType<T[First], Rest, TDefault>
|
|
61
|
+
: First extends `${infer N extends number}`
|
|
62
|
+
? IsArray<T> extends true
|
|
63
|
+
? T extends readonly unknown[]
|
|
64
|
+
? GetFieldType<T[N], Rest, TDefault>
|
|
65
|
+
: TDefault
|
|
66
|
+
: TDefault
|
|
67
|
+
: TDefault
|
|
68
|
+
: P extends `${infer N extends number}`
|
|
69
|
+
? IsArray<T> extends true
|
|
70
|
+
? T extends readonly unknown[]
|
|
71
|
+
? T[N]
|
|
72
|
+
: TDefault
|
|
73
|
+
: TDefault
|
|
74
|
+
: TDefault;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PaginatorLink } from "./pagination";
|
|
2
|
+
|
|
3
|
+
export interface JsonResourceMeta {
|
|
4
|
+
current_page: number;
|
|
5
|
+
from: number;
|
|
6
|
+
last_page: number;
|
|
7
|
+
links: PaginatorLink[];
|
|
8
|
+
path: string;
|
|
9
|
+
per_page: number;
|
|
10
|
+
to: number;
|
|
11
|
+
total: number;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface JsonResourceLinks {
|
|
15
|
+
first: string | null;
|
|
16
|
+
last: string | null;
|
|
17
|
+
prev: string | null;
|
|
18
|
+
next: string | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface JsonResource<T> {
|
|
22
|
+
data: T[];
|
|
23
|
+
meta: JsonResourceMeta;
|
|
24
|
+
links: JsonResourceLinks;
|
|
25
|
+
}
|
package/src/strings.d.ts
ADDED
package/src/utils.d.ts
ADDED
|
File without changes
|