@typedly/data 2.0.0 → 3.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/README.md CHANGED
@@ -16,18 +16,26 @@
16
16
 
17
17
  A **TypeScript** type definitions package for [**@typescript-package/data**](https://github.com/typescript-package/data).
18
18
 
19
+ ## Features
20
+
21
+ - **Adapter**: Optional data adapter to customize managing underlying data.
22
+ - **Shape**: The default shape for data of any `T` type with conditional async.
23
+
19
24
  ## Table of contents
20
25
 
21
26
  - [Installation](#installation)
22
27
  - [Api](#api)
23
28
  - [Interface](#interface)
29
+ - [`DataAdapter`](#dataadapter)
24
30
  - [`DataConstructor`](#dataconstructor)
25
31
  - [`DataShape`](#datashape)
26
32
  - [`ValueConstructor`](#valueconstructor)
27
33
  - [`ValueShape`](#valueshape)
28
34
  - [Type](#type)
35
+ - [`AsyncReturn`](#asyncreturn)
29
36
  - [`DataConstructorInput`](#dataconstructorinput)
30
37
  - [`DataConstructorTuple`](#dataconstructortuple)
38
+ - [`IterValue`](#itervalue)
31
39
  - [Full example usage](#full-example-usage)
32
40
  - [Contributing](#contributing)
33
41
  - [Support](#support)
@@ -57,18 +65,31 @@ npm install @typedly/data --save-peer
57
65
  ```typescript
58
66
  import {
59
67
  // Interface.
68
+ DataAdapter,
60
69
  DataConstructor,
61
70
  DataShape,
62
71
  ValueConstructor,
63
72
  ValueShape,
64
73
  // Type.
74
+ AsyncReturn,
65
75
  DataConstructorInput,
66
76
  DataConstructorTuple,
77
+ IterValue
67
78
  } from '@typedly/data';
68
79
  ```
69
80
 
70
81
  ### Interface
71
82
 
83
+ #### `DataAdapter`
84
+
85
+ The adapter interface for data types.
86
+
87
+ ```typescript
88
+ import { DataAdapter } from '@typedly/data';
89
+ ```
90
+
91
+ [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-adapter.interface.ts)
92
+
72
93
  #### `DataConstructor`
73
94
 
74
95
  The constructor interface for data types.
@@ -193,6 +214,16 @@ import { ValueShape } from '@typedly/data';
193
214
 
194
215
  ### Type
195
216
 
217
+ #### `AsyncReturn`
218
+
219
+ The conditional return type for async methods.
220
+
221
+ ```typescript
222
+ import { AsyncReturn } from '@typedly/data';
223
+ ```
224
+
225
+ [Source](https://github.com/typedly/data/blob/main/src/lib/type/async-return.type.ts)
226
+
196
227
  #### `DataConstructorInput`
197
228
 
198
229
  The input type for data constructors, with arguments support.
@@ -213,6 +244,16 @@ import { DataConstructorTuple } from '@typedly/data';
213
244
 
214
245
  [Source](https://github.com/typedly/data/blob/main/src/lib/type/data-constructor-tuple.type.ts)
215
246
 
247
+ #### `IterValue`
248
+
249
+ The iterated value type.
250
+
251
+ ```typescript
252
+ import { IterValue } from '@typedly/data';
253
+ ```
254
+
255
+ [Source](https://github.com/typedly/data/blob/main/src/lib/type/iter-value.type.ts)
256
+
216
257
  ### Full example usage
217
258
 
218
259
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typedly/data",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "author": "wwwdev.io <dev@wwwdev.io>",
5
5
  "description": "A TypeScript type definitions package for @typescript-package/data.",
6
6
  "license": "MIT",
@@ -33,13 +33,13 @@
33
33
  }
34
34
  ],
35
35
  "sideEffects": false,
36
- "typings": "index.d.ts",
36
+ "typings": "types/typedly-data.d.ts",
37
37
  "exports": {
38
38
  "./package.json": {
39
39
  "default": "./package.json"
40
40
  },
41
41
  ".": {
42
- "types": "./index.d.ts",
42
+ "types": "./types/typedly-data.d.ts",
43
43
  "default": "./fesm2022/typedly-data.mjs"
44
44
  }
45
45
  }
@@ -1,17 +1,66 @@
1
1
  import { DataConstructor as DataConstructor$1 } from '@typedly/constructor';
2
2
 
3
+ /**
4
+ * @description The conditional return type for async methods.
5
+ * @export
6
+ * @template Async The boolean flag indicating if the return type should be a Promise.
7
+ * @template T The type of the value to be returned.
8
+ */
9
+ type AsyncReturn<Async, T> = Async extends true ? Promise<T> : T;
10
+
11
+ /**
12
+ * @description The type to provide data constructor with arguments.
13
+ * @export
14
+ * @template Value The value type.
15
+ * @template {DataShape<Value>} Instance The shape of the instance.
16
+ * @template {any[]} [Args=any[]] Additional Arguments passed to the instance.
17
+ */
18
+ type DataConstructorTuple<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = [DataConstructor<Value, Instance, Args>, ...Args];
19
+
20
+ /**
21
+ * @description The input type for data constructors, with arguments support.
22
+ * @export
23
+ * @template Value The value type.
24
+ * @template {DataShape<Value>} Instance The data instance type.
25
+ * @template {any[]} [Args=any[]] The arguments to pass to instance.
26
+ */
27
+ type DataConstructorInput<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = DataConstructor<Value, Instance, Args> | DataConstructorTuple<Value, Instance, Args>;
28
+
29
+ /**
30
+ * @description The iterated value type.
31
+ * @export
32
+ * @template T The type of iterated value constrained by the `Iterable` type.
33
+ */
34
+ type IterValue<T> = T extends Iterable<infer U> ? U : T;
35
+
3
36
  /**
4
37
  * @description The shape of a `Data` type.
5
38
  * @export
6
39
  * @interface DataShape
7
- * @template Value The value type.
40
+ * @template T The value type.
41
+ * @template {boolean} [Async=false] The `Promise` return type for methods.
8
42
  */
9
- interface DataShape<Value> {
10
- get value(): Value;
11
- clear(): this;
12
- destroy(): this;
43
+ interface DataShape<T, Async extends boolean = false> {
44
+ value: T;
45
+ clear(): AsyncReturn<Async, this>;
46
+ destroy(): AsyncReturn<Async, this>;
13
47
  lock(): this;
14
- set(value: Value): this;
48
+ set(value: T): AsyncReturn<Async, this>;
49
+ [Symbol.toStringTag]?: string;
50
+ [Symbol.iterator]?(): IterableIterator<IterValue<T>>;
51
+ [Symbol.asyncIterator]?(): AsyncIterableIterator<IterValue<T>>;
52
+ }
53
+
54
+ /**
55
+ * @description The adapter interface for data types.
56
+ * @export
57
+ * @interface DataAdapter
58
+ * @template T The type of the data value.
59
+ * @template {boolean} [R=false] The type of the return values for methods.
60
+ * @extends {DataShape<T, R>}
61
+ */
62
+ interface DataAdapter<T, R extends boolean = false> extends DataShape<T, R> {
63
+ version?: string;
15
64
  }
16
65
 
17
66
  /**
@@ -49,22 +98,4 @@ interface ValueShape<Type> {
49
98
  interface ValueConstructor<Value, Instance extends ValueShape<Value>, Args extends readonly any[] = any[]> extends DataConstructor$1<Value, ValueShape<Value>, Instance, [...Args]> {
50
99
  }
51
100
 
52
- /**
53
- * @description The type to provide data constructor with arguments.
54
- * @export
55
- * @template Value The value type.
56
- * @template {DataShape<Value>} Instance The shape of the instance.
57
- * @template {any[]} [Args=any[]] Additional Arguments passed to the instance.
58
- */
59
- type DataConstructorTuple<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = [DataConstructor<Value, Instance, Args>, ...Args];
60
-
61
- /**
62
- * @description The input type for data constructors, with arguments support.
63
- * @export
64
- * @template Value The value type.
65
- * @template {DataShape<Value>} Instance The data instance type.
66
- * @template {any[]} [Args=any[]] The arguments to pass to instance.
67
- */
68
- type DataConstructorInput<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = DataConstructor<Value, Instance, Args> | DataConstructorTuple<Value, Instance, Args>;
69
-
70
- export type { DataConstructor, DataConstructorInput, DataConstructorTuple, DataShape, ValueConstructor, ValueShape };
101
+ export type { AsyncReturn, DataAdapter, DataConstructor, DataConstructorInput, DataConstructorTuple, DataShape, IterValue, ValueConstructor, ValueShape };