@typedly/data 3.0.0 → 5.0.0-beta

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
@@ -25,13 +25,19 @@ A **TypeScript** type definitions package for [**@typescript-package/data**](htt
25
25
 
26
26
  - [Installation](#installation)
27
27
  - [Api](#api)
28
- - [Interface](#interface)
29
- - [`DataAdapter`](#dataadapter)
28
+ - [Constructor](#constructor)
29
+ - [`AdaptableDataConstructor`](#adaptabledataconstructor)
30
+ - [`DataAdapterConstructor`](#dataadapterconstructor)
30
31
  - [`DataConstructor`](#dataconstructor)
31
- - [`DataShape`](#datashape)
32
32
  - [`ValueConstructor`](#valueconstructor)
33
+ - [Interface](#interface)
34
+ - [`AdaptableDataShape`](#adaptabledatashape)
35
+ - [`DataAdapterShape`](#dataadaptershape)
36
+ - [`DataShape`](#datashape)
33
37
  - [`ValueShape`](#valueshape)
34
38
  - [Type](#type)
39
+ - [`AdaptableDataConstructorInput`](#adaptabledataconstructorinput)
40
+ - [`AdaptableDataConstructorTuple`](#adaptabledataconstructortuple)
35
41
  - [`AsyncReturn`](#asyncreturn)
36
42
  - [`DataConstructorInput`](#dataconstructorinput)
37
43
  - [`DataConstructorTuple`](#dataconstructortuple)
@@ -64,143 +70,111 @@ npm install @typedly/data --save-peer
64
70
 
65
71
  ```typescript
66
72
  import {
67
- // Interface.
68
- DataAdapter,
73
+ // Data adapter constructor.
74
+ DataAdapterConstructor,
75
+
76
+ // Data Constructor.
77
+ AdaptableDataConstructor,
69
78
  DataConstructor,
70
- DataShape,
79
+
80
+ // Value Constructor.
71
81
  ValueConstructor,
82
+
83
+ // Data adapter Interface.
84
+ DataAdapterShape,
85
+
86
+ // Data Interface.
87
+ AdaptableDataShape,
88
+ DataShape,
89
+
90
+ // Value Interface.
72
91
  ValueShape,
73
- // Type.
74
- AsyncReturn,
92
+
93
+ // Adaptable data constructor input and tuple.
94
+ AdaptableDataConstructorInput,
95
+ AdaptableDataConstructorTuple,
96
+
97
+ // Data constructor input and tuple.
75
98
  DataConstructorInput,
76
99
  DataConstructorTuple,
100
+
101
+ // Type.
102
+ AsyncReturn,
77
103
  IterValue
78
104
  } from '@typedly/data';
79
105
  ```
80
106
 
81
- ### Interface
107
+ ### Constructor
82
108
 
83
- #### `DataAdapter`
109
+ #### `AdaptableDataConstructor`
84
110
 
85
- The adapter interface for data types.
111
+ The constructor interface for data types with adapter.
86
112
 
87
113
  ```typescript
88
- import { DataAdapter } from '@typedly/data';
114
+ import { AdaptableDataConstructor } from '@typedly/data';
89
115
  ```
90
116
 
91
- [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-adapter.interface.ts)
117
+ [Source](https://github.com/typedly/data/blob/main/src/lib/constructor/lib/adaptable-data.constructor.ts)
118
+
119
+ #### `DataAdapterConstructor`
120
+
121
+ The constructor interface for data adapters.
122
+
123
+ ```typescript
124
+ import { DataAdapterConstructor } from '@typedly/data';
125
+ ```
126
+
127
+ [Source](https://github.com/typedly/data/blob/main/src/lib/constructor/lib/data-adapter.constructor.ts)
92
128
 
93
129
  #### `DataConstructor`
94
130
 
95
131
  The constructor interface for data types.
96
132
 
97
133
  ```typescript
98
- import { DataConstructor, DataShape } from '@typedly/data';
99
-
100
- // Import DataShape and DataConstructor.
101
- // Create a data class that implements `DataShape` of `Type`.
102
- export class ProfileData<
103
- Value extends { age: number, name: string }
104
- > implements DataShape<Value> {
105
-
106
- get value(): Value {
107
- return {
108
- age: this.#age,
109
- name: this.#name
110
- } as Value;
111
- }
112
-
113
- #age;
114
- #name;
115
- constructor(value: Value, ...args: any[]) {
116
- console.log(`Instantiated DataConstructor`, value, ...args);
117
- this.#age = value.age;
118
- this.#name = value.name;
119
- }
120
-
121
- set(value: Value): this { this.validate(value); return this; }
122
- clear(): this { return this; }
123
- destroy(): this { return this; }
124
- lock(): this { return this; };
125
- validate(value: Value): boolean {
126
- return true;
127
- }
128
- }
129
-
130
- // Create `ProfileClass` with customizable data.
131
- export class ProfileClass<
132
- Value extends { age: number, name: string },
133
- DataType extends DataShape<Value>,
134
- Args extends any[]
135
- > {
136
-
137
- public get age(): Value['age'] {
138
- return this.#data.value.age;
139
- }
140
-
141
- public get name(): Value['name'] {
142
- return this.#data.value.name;
143
- }
144
-
145
- public get data() {
146
- return this.#data;
147
- }
148
-
149
- #data: DataType;
150
-
151
- constructor(value: Value, dataCtor: DataConstructor<Value, DataType>);
152
- constructor(value: Value, dataCtor: [DataConstructor<Value, DataType>, ...Args]);
153
- constructor(value: Value, dataCtor: any) {
154
- // ...implementation
155
- console.log(`DataConstructor`, value, dataCtor[1]);
156
- this.#data = Array.isArray(dataCtor)
157
- ? new dataCtor[0](value, ...dataCtor.slice(1))
158
- : new dataCtor(value);
159
- }
160
- }
161
-
162
- // Initialize.
163
- // const frankProfile: ProfileClass<object, ProfileData<object>, any[]>
164
- const frankProfile = new ProfileClass({ age: 37, name: 'Frank' }, ProfileData);
165
-
166
- frankProfile.age; // 37
167
- frankProfile.name; // Frank
168
-
169
- // Set the data.
170
- frankProfile.data.set({ age: 37, name: 'Frank' });
171
- frankProfile.data.clear();
172
- frankProfile.data.lock();
173
- frankProfile.data.value;
134
+ import { DataConstructor } from '@typedly/data';
174
135
  ```
175
136
 
176
- [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-constructor.interface.ts)
137
+ [Source](https://github.com/typedly/data/blob/main/src/lib/constructor/lib/data.constructor.ts)
177
138
 
178
- #### `DataShape`
139
+ #### `ValueConstructor`
179
140
 
180
- The shape of a `Data` type.
141
+ ```typescript
142
+ import { ValueConstructor } from '@typedly/data';
143
+ ```
144
+
145
+ [Source](https://github.com/typedly/data/blob/main/src/lib/constructor/lib/value.constructor.ts)
146
+
147
+ ### Interface
148
+
149
+ #### `AdaptableDataShape`
150
+
151
+ The shape of a data type with optional adapter.
181
152
 
182
153
  ```typescript
183
- import { DataShape } from '@typedly/data';
154
+ import { AdaptableDataShape } from '@typedly/data';
155
+ ```
184
156
 
185
- class TestData implements DataShape<number> {
186
- get value(): number { return this.initialValue; }
187
- constructor(private initialValue: number) {}
188
- public clear(): this { return this; }
189
- public destroy(): this { return this; }
190
- public lock(): this { return this; }
191
- public set(value: number): this { return this; }
192
- }
157
+ [Source](https://github.com/typedly/data/blob/main/src/lib/interface/adaptable-data.shape.ts)
158
+
159
+ #### `DataAdapterShape`
160
+
161
+ The adapter interface for data types.
162
+
163
+ ```typescript
164
+ import { DataAdapterShape } from '@typedly/data';
193
165
  ```
194
166
 
195
- [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-shape.interface.ts)
167
+ [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-adapter.shape.ts)
196
168
 
197
- #### `ValueConstructor`
169
+ #### `DataShape`
170
+
171
+ The shape of a `Data` type.
198
172
 
199
173
  ```typescript
200
- import { ValueConstructor } from '@typedly/data';
174
+ import { DataShape } from '@typedly/data';
201
175
  ```
202
176
 
203
- [Source](https://github.com/typedly/data/blob/main/src/lib/interface/value-constructor.interface.ts)
177
+ [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data.shape.ts)
204
178
 
205
179
  #### `ValueShape`
206
180
 
@@ -214,6 +188,22 @@ import { ValueShape } from '@typedly/data';
214
188
 
215
189
  ### Type
216
190
 
191
+ #### `AdaptableDataConstructorInput`
192
+
193
+ ```typescript
194
+ import { AdaptableDataConstructorInput } from '@typedly/data';
195
+ ```
196
+
197
+ [Source](https://github.com/typedly/data/blob/main/src/lib/type/adaptable-data-constructor-input.type.ts)
198
+
199
+ #### `AdaptableDataConstructorTuple`
200
+
201
+ ```typescript
202
+ import { AdaptableDataConstructorTuple } from '@typedly/data';
203
+ ```
204
+
205
+ [Source](https://github.com/typedly/data/blob/main/src/lib/type/adaptable-data-constructor-tuple.type.ts)
206
+
217
207
  #### `AsyncReturn`
218
208
 
219
209
  The conditional return type for async methods.
@@ -254,124 +244,6 @@ import { IterValue } from '@typedly/data';
254
244
 
255
245
  [Source](https://github.com/typedly/data/blob/main/src/lib/type/iter-value.type.ts)
256
246
 
257
- ### Full example usage
258
-
259
- ```typescript
260
- import { DataConstructor, DataShape, ValueConstructor, ValueShape } from '@typedly/data';
261
-
262
- // Import ValueShape and ValueConstructor.
263
- // Create a profile data value.
264
- export class ProfileDataValue<
265
- Type extends { age: number, name: string },
266
- Args extends any[] = any[]
267
- > implements ValueShape<Type> {
268
- get value(): Type {
269
- return {
270
- age: this.#age,
271
- name: this.#name
272
- } as Type;
273
- }
274
-
275
- #age: Type['age'];
276
- #name: Type['name'];
277
-
278
- constructor(value: Type, ...args: Args) {
279
- console.log(`Instantiated ValueConstructor`, value, ...args);
280
- this.#age = value.age;
281
- this.#name = value.name;
282
- }
283
-
284
- set(value: Type): this { return this; }
285
- }
286
-
287
- export class ProfileDataOfValue<
288
- Value extends { age: number, name: string },
289
- Args extends any[] = any[],
290
- ValueInstance extends ValueShape<Value> = ProfileDataValue<Value, Args>,
291
- > implements DataShape<Value> {
292
-
293
- get value(): Value {
294
- return {
295
- } as Value;
296
- }
297
-
298
- get valueInstance(): ValueInstance {
299
- return this.#value;
300
- }
301
-
302
- #value;
303
- constructor(
304
- value: Value,
305
- valueCtor: ValueConstructor<Value, ValueInstance, Args> = ProfileDataValue<Value, Args> as any,
306
- ...args: Args
307
- ) {
308
- console.log(`Instantiated DataConstructor`, value, ...args);
309
- this.#value = new valueCtor(value, ...args);
310
- }
311
-
312
- set(value: Value): this { this.validate(value); return this; }
313
- clear(): this { return this; }
314
- destroy(): this { return this; }
315
- lock(): this { return this; };
316
- validate(value: Value): boolean {
317
- return true;
318
- }
319
- }
320
-
321
- // const profileDataOfValue: ProfileDataOfValue<{
322
- // age: number;
323
- // name: string;
324
- // }, ProfileDataValue<{
325
- // age: number;
326
- // name: string;
327
- // }, []>, []>
328
- const profileDataOfValue = new ProfileDataOfValue({
329
- age: 37,
330
- name: 'Mark'
331
- }, ProfileDataValue);
332
-
333
- const dataSymbol = Symbol('data');
334
-
335
- // Create `ProfileClass` with customizable data.
336
- export class ProfileClass<
337
- Value extends { age: number, name: string },
338
- DataType extends DataShape<Value>,
339
- Args extends any[]
340
- > {
341
-
342
- public get age(): Value['age'] {
343
- return this.#data.value.age;
344
- }
345
-
346
- public get name(): Value['name'] {
347
- return this.#data.value.name;
348
- }
349
-
350
- public get [dataSymbol]() {
351
- return this.#data;
352
- }
353
-
354
- #data: DataType;
355
-
356
- constructor(value: Value, dataCtor: DataConstructor<Value, DataType, Args>);
357
- constructor(value: Value, dataCtor: [DataConstructor<Value, DataType, Args>, ...Args]);
358
- constructor(value: Value, dataCtor: any) {
359
- // ...implementation
360
- console.log(`DataConstructor`, value, dataCtor[1]);
361
- this.#data = Array.isArray(dataCtor)
362
- ? new dataCtor[0](value, ...dataCtor.slice(1))
363
- : new dataCtor(value);
364
- }
365
- }
366
-
367
- const markProfile = new ProfileClass({ age: 37, name: 'Mark' }, ProfileDataOfValue);
368
-
369
- markProfile.age // 37
370
- markProfile.name // Mark
371
- markProfile[dataSymbol].value // { age, name }
372
- markProfile[dataSymbol].valueInstance.set({ age: 27, name: 'Frank' });
373
- ```
374
-
375
247
  ## Contributing
376
248
 
377
249
  Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
@@ -382,19 +254,23 @@ If you find this package useful and would like to support its and general develo
382
254
 
383
255
  Support via:
384
256
 
385
- - [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
386
- - [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
387
- - [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
257
+ - [4Fund](https://4fund.com/bruubs)
388
258
  - [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
259
+ - [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
260
+ - [Ko-fi](https://ko-fi.com/sterblack)
261
+ - [OpenCollective](https://opencollective.com/sterblack)
389
262
  - [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
263
+ - [PayPal](https://paypal.me/sterblack)
264
+ - [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
265
+ - ~~[Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)~~
390
266
 
391
267
  or via Trust Wallet
392
268
 
393
- - [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
394
- - [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
395
- - [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
396
- - [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
397
269
  - [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
270
+ - [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
271
+ - [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
272
+ - [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
273
+ - [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
398
274
 
399
275
  Thanks for your support!
400
276
 
@@ -437,6 +313,10 @@ MIT © typedly ([license][typedly-license])
437
313
 
438
314
  ## Related packages
439
315
 
316
+ - **[@typescript-package/collection](https://github.com/typescript-package/collection)**: A lightweight TypeScript library for data collection.
317
+
318
+ ## Packages
319
+
440
320
  - **[@typescript-package/chain-descriptor](https://github.com/typescript-package/chain-descriptor)**: A **TypeScript** library for chain property descriptor.
441
321
  - **[@typescript-package/controlled-descriptor](https://github.com/typescript-package/controlled-descriptor)**: A **TypeScript** library for controlled property descriptor.
442
322
  - **[@typescript-package/controller](https://github.com/typescript-package/controller)**: A **TypeScript** package with for various kind of controllers.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typedly/data",
3
- "version": "3.0.0",
3
+ "version": "5.0.0-beta",
4
4
  "author": "wwwdev.io <dev@wwwdev.io>",
5
5
  "description": "A TypeScript type definitions package for @typescript-package/data.",
6
6
  "license": "MIT",
@@ -28,7 +28,27 @@
28
28
  "url": "https://donate.stripe.com/dR614hfDZcJE3wAcMM"
29
29
  },
30
30
  {
31
- "type": "revolut",
31
+ "type": "Donorbox",
32
+ "url": "https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=once&amount=1"
33
+ },
34
+ {
35
+ "type": "Open Collective",
36
+ "url": "https://opencollective.com/sterblack"
37
+ },
38
+ {
39
+ "type": "Ko-fi",
40
+ "url": "https://ko-fi.com/sterblack"
41
+ },
42
+ {
43
+ "type": "4Fund",
44
+ "url": "https://4fund.com/bruubs"
45
+ },
46
+ {
47
+ "type": "paypal",
48
+ "url": "https://paypal.me/sterblack"
49
+ },
50
+ {
51
+ "type": "individual",
32
52
  "url": "https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29"
33
53
  }
34
54
  ],
@@ -1,30 +1,46 @@
1
1
  import { DataConstructor as DataConstructor$1 } from '@typedly/constructor';
2
2
 
3
+ type AdaptableDataConstructorTuple<A extends DataAdapterShape<T, C, R>, I extends AdaptableDataShape<A, T, C, R>, C extends {
4
+ async?: boolean;
5
+ } = A extends DataAdapterShape<any, infer V, any> ? V : any, T = A extends DataAdapterShape<infer U, any, any> ? U : any, R extends boolean = A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> = readonly [AdaptableDataConstructor<A, I, C, T, R, G>, ...G];
6
+
7
+ type AdaptableDataConstructorInput<A extends DataAdapterShape<T, C, R>, I extends AdaptableDataShape<A, T, C, R>, C extends {
8
+ async?: boolean;
9
+ } = A extends DataAdapterShape<any, infer V, any> ? V : any, T = A extends DataAdapterShape<infer U, any, any> ? U : any, R extends boolean = A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> = AdaptableDataConstructor<A, I, C, T, R, G> | AdaptableDataConstructorTuple<A, I, C, T, R, G>;
10
+
3
11
  /**
4
- * @description The conditional return type for async methods.
12
+ * @description The type to provide data constructor with arguments.
5
13
  * @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.
14
+ * @template {DataShape<T, C, R>} I The type of the data instance.
15
+ * @template {{ async?: boolean }} [C=I extends DataShape<any, infer V, any> ? V : any] The type of the configuration, inferred from I if possible.
16
+ * @template [T=I extends DataShape<infer U, any, any> ? U : any] The type of value instance, inferred from I if possible.
17
+ * @template {boolean} [R=I extends DataShape<T, C, infer U> ? U extends boolean ? U : false : false] The type of the readonly flag, inferred from I if possible.
18
+ * @template {readonly any[]} [G=any[]] The type of the arguments tuple.
8
19
  */
9
- type AsyncReturn<Async, T> = Async extends true ? Promise<T> : T;
20
+ type DataConstructorTuple<I extends DataShape<T, C, R>, C extends {
21
+ async?: boolean;
22
+ } = I extends DataShape<any, infer V, any> ? V : any, T = I extends DataShape<infer U, any, any> ? U : any, R extends boolean = I extends DataShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> = [DataConstructor<I, C, T, R, G>, ...G];
10
23
 
11
24
  /**
12
- * @description The type to provide data constructor with arguments.
25
+ * @description The input type for data constructors, with arguments support.
13
26
  * @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.
27
+ * @template {DataShape<T, C, R>} I The type of the data instance.
28
+ * @template {{ async?: boolean }} [C=I extends DataShape<any, infer V, any> ? V : any] The type of the configuration, inferred from I if possible.
29
+ * @template [T=I extends DataShape<infer U, any, any> ? U : any] The type of value instance, inferred from I if possible.
30
+ * @template {boolean} [R=I extends DataShape<T, C, infer U> ? U extends boolean ? U : false : false] The type of the readonly flag, inferred from I if possible.
31
+ * @template {readonly any[]} [G=any[]] The type of the arguments tuple.
17
32
  */
18
- type DataConstructorTuple<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = [DataConstructor<Value, Instance, Args>, ...Args];
33
+ type DataConstructorInput<I extends DataShape<T, C, R>, C extends {
34
+ async?: boolean;
35
+ } = I extends DataShape<any, infer V, any> ? V : any, T = I extends DataShape<infer U, any, any> ? U : any, R extends boolean = I extends DataShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> = DataConstructor<I, C, T, R, G> | DataConstructorTuple<I, C, T, R, G>;
19
36
 
20
37
  /**
21
- * @description The input type for data constructors, with arguments support.
38
+ * @description The conditional return type for async methods.
22
39
  * @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.
40
+ * @template Async The boolean flag indicating if the return type should be a Promise.
41
+ * @template T The type of the value to be returned.
26
42
  */
27
- type DataConstructorInput<Value, Instance extends DataShape<Value>, Args extends any[] = any[]> = DataConstructor<Value, Instance, Args> | DataConstructorTuple<Value, Instance, Args>;
43
+ type AsyncReturn<Async, T> = Async extends true ? Promise<T> : T;
28
44
 
29
45
  /**
30
46
  * @description The iterated value type.
@@ -34,45 +50,101 @@ type DataConstructorInput<Value, Instance extends DataShape<Value>, Args extends
34
50
  type IterValue<T> = T extends Iterable<infer U> ? U : T;
35
51
 
36
52
  /**
37
- * @description The shape of a `Data` type.
53
+ * @description The shape of a data type.
38
54
  * @export
39
55
  * @interface DataShape
40
56
  * @template T The value type.
41
- * @template {boolean} [Async=false] The `Promise` return type for methods.
57
+ * @template C The configuration type.
58
+ * @template {boolean} [R=C extends { async?: boolean } ? C['async'] extends boolean ? C['async'] : false : false] The `Promise` return type for methods.
42
59
  */
43
- interface DataShape<T, Async extends boolean = false> {
60
+ interface DataShape<T, C, R extends boolean = C extends {
61
+ async?: boolean;
62
+ } ? C['async'] extends boolean ? C['async'] : false : false> {
63
+ /**
64
+ * @description Indicates whether the methods return a `Promise`.
65
+ * @type {R}
66
+ */
67
+ async: R;
68
+ /**
69
+ * @description The configuration of the `Data` instance.
70
+ * @type {?C}
71
+ */
72
+ configuration?: C;
73
+ /**
74
+ * @description The value of the `Data` instance.
75
+ * @type {T}
76
+ */
44
77
  value: T;
45
- clear(): AsyncReturn<Async, this>;
46
- destroy(): AsyncReturn<Async, this>;
78
+ /**
79
+ * @description Clears the value of the `Data` instance.
80
+ * @returns {AsyncReturn<R, this>}
81
+ */
82
+ clear(): AsyncReturn<R, this>;
83
+ /**
84
+ * @description Destroys the `Data` instance, making it unusable.
85
+ * @returns {AsyncReturn<R, this>}
86
+ */
87
+ destroy(): AsyncReturn<R, this>;
88
+ /**
89
+ * @description Gets the value of the `Data` instance.
90
+ * @returns {AsyncReturn<R, T>}
91
+ */
92
+ getValue(): AsyncReturn<R, T>;
93
+ /**
94
+ * @description Locks the `Data` instance, preventing any further modifications to its value.
95
+ * @returns {this}
96
+ */
47
97
  lock(): this;
48
- set(value: T): AsyncReturn<Async, this>;
98
+ /**
99
+ * @description Sets the value of the `Data` instance.
100
+ * @param {T} value
101
+ * @returns {AsyncReturn<R, this>}
102
+ */
103
+ setValue(value: T): AsyncReturn<R, this>;
104
+ /**
105
+ * @description The string tag of the `Data` instance.
106
+ * @type {?string}
107
+ */
49
108
  [Symbol.toStringTag]?: string;
109
+ /**
110
+ * @description The iterator method for the `Data` instance, allowing it to be iterable.
111
+ * @returns {IterableIterator<IterValue<T>>}
112
+ */
50
113
  [Symbol.iterator]?(): IterableIterator<IterValue<T>>;
114
+ /**
115
+ * @description The asynchronous iterator method for the `Data` instance, allowing it to be asynchronously iterable.
116
+ * @returns {AsyncIterableIterator<IterValue<T>>}
117
+ */
51
118
  [Symbol.asyncIterator]?(): AsyncIterableIterator<IterValue<T>>;
52
119
  }
53
120
 
54
121
  /**
55
122
  * @description The adapter interface for data types.
56
123
  * @export
57
- * @interface DataAdapter
124
+ * @interface DataAdapterShape
58
125
  * @template T The type of the data value.
126
+ * @template C The type of the configuration object.
59
127
  * @template {boolean} [R=false] The type of the return values for methods.
60
- * @extends {DataShape<T, R>}
128
+ * @extends {DataShape<T, C, R>}
61
129
  */
62
- interface DataAdapter<T, R extends boolean = false> extends DataShape<T, R> {
130
+ interface DataAdapterShape<T, C, R extends boolean = C extends {
131
+ async?: boolean;
132
+ } ? C['async'] extends boolean ? C['async'] : false : false> extends DataShape<T, C, R> {
63
133
  version?: string;
64
134
  }
65
135
 
66
136
  /**
67
- * @description The constructor interface for data types.
137
+ * @description The shape of a data type with optional adapter.
68
138
  * @export
69
- * @interface DataConstructor
70
- * @template Value
71
- * @template {DataShape<Value>} Instance The instance.
72
- * @template {readonly any[]} [Args=any[]]
73
- * @extends {BaseDataConstructor<Value, DataShape<Value>, Instance, [...Args]>}
139
+ * @interface AdaptableDataShape
140
+ * @template {DataAdapterShape<T, C, any>} A The adapter type.
141
+ * @template [T=A extends DataAdapterShape<infer U, any, any> ? U : any] The value type.
142
+ * @template [C=A extends DataAdapterShape<any, infer V, any> ? V : any] The configuration type.
143
+ * @template {boolean} [R=A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false] The async flag.
144
+ * @extends {DataShape<T, C, R>}
74
145
  */
75
- interface DataConstructor<Value, Instance extends DataShape<Value>, Args extends readonly any[] = any[]> extends DataConstructor$1<Value, DataShape<Value>, Instance, [...Args]> {
146
+ interface AdaptableDataShape<A extends DataAdapterShape<T, C, any> | undefined = undefined, T = A extends DataAdapterShape<infer U, any, any> ? U : any, C = A extends DataAdapterShape<any, infer V, any> ? V : any, R extends boolean = A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false> extends DataShape<T, C, R> {
147
+ adapter?: A;
76
148
  }
77
149
 
78
150
  /**
@@ -86,16 +158,65 @@ interface ValueShape<Type> {
86
158
  set(value: Type): this;
87
159
  }
88
160
 
161
+ /**
162
+ * @description The constructor interface for data adapters.
163
+ * @export
164
+ * @interface DataAdapterConstructor
165
+ * @template {DataAdapterShape<T, C, R>} I The data adapter instance type.
166
+ * @template {{ async?: boolean }} [C=I extends DataAdapterShape<any, infer V, any> ? V : any] The configuration type, inferred from I if possible.
167
+ * @template [T=I extends DataAdapterShape<infer U, any, any> ? U : any] The underlying value type, inferred from I if possible.
168
+ * @template {boolean} [R=I extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false] The async flag, inferred from I if possible.
169
+ * @template {readonly any[]} [G=any[]] Additional arguments.
170
+ */
171
+ interface DataAdapterConstructor<I extends DataAdapterShape<T, C, R>, C extends {
172
+ async?: boolean;
173
+ } = I extends DataAdapterShape<any, infer V, any> ? V : any, T = I extends DataAdapterShape<infer U, any, any> ? U : any, R extends boolean = I extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> {
174
+ new (settings: C, value: T, ...args: G): I;
175
+ }
176
+
177
+ /**
178
+ * @description The constructor interface for data types with adapter.
179
+ * @export
180
+ * @interface AdaptableDataConstructor
181
+ * @template {DataAdapterShape<T, C, R>} A The data adapter instance type.
182
+ * @template {AdaptableDataShape<A, T, C, R>} I The data instance type.
183
+ * @template {{ async?: boolean }} [C=A extends DataAdapterShape<any, infer V, any> ? V : any] The configuration type, inferred from A if possible.
184
+ * @template [T=A extends DataAdapterShape<infer U, any, any> ? U : any] The underlying value type, inferred from A if possible.
185
+ * @template {boolean} [R=A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false] The async flag, inferred from A if possible.
186
+ * @template {readonly any[]} [G=any[]] The additional arguments type.
187
+ */
188
+ interface AdaptableDataConstructor<A extends DataAdapterShape<T, C, R>, I extends AdaptableDataShape<A, T, C, R>, C extends {
189
+ async?: boolean;
190
+ } = A extends DataAdapterShape<any, infer V, any> ? V : any, T = A extends DataAdapterShape<infer U, any, any> ? U : any, R extends boolean = A extends DataAdapterShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> {
191
+ new (settings: C, value: T, adapter: DataAdapterConstructor<A, C, T, R, G>, ...args: G): I;
192
+ }
193
+
194
+ /**
195
+ * @description The constructor interface for data types.
196
+ * @export
197
+ * @interface DataConstructor
198
+ * @template {DataShape<T, C, R>} I The data instance type.
199
+ * @template {{ async?: boolean }} C The configuration type, inferred from `I` if possible.
200
+ * @template T The underlying value type, inferred from `I` if possible.
201
+ * @template {boolean} [R=C['async'] extends boolean ? C['async'] : false] The async flag, inferred from `I` if possible.
202
+ * @template {readonly any[]} [G=any[]] Additional arguments.
203
+ */
204
+ interface DataConstructor<I extends DataShape<T, C, R>, C extends {
205
+ async?: boolean;
206
+ } = I extends DataShape<any, infer V, any> ? V : any, T = I extends DataShape<infer U, any, any> ? U : any, R extends boolean = I extends DataShape<T, C, infer U> ? U extends boolean ? U : false : false, G extends readonly any[] = any[]> {
207
+ new (settings: C, value: T, ...args: G): I;
208
+ }
209
+
89
210
  /**
90
211
  * @description The constructor for value in data for advanced customization.
91
212
  * @export
92
213
  * @interface ValueConstructor
93
- * @template Value The value type.
94
- * @template {ValueShape<Value>} Instance The instance.
95
- * @template {readonly any[]} [Args=any[]] Additional arguments passed to the constructor.
96
- * @extends {BaseDataConstructor<Value, ValueShape<Value>, Instance, [...Args]>}
214
+ * @template T The value type.
215
+ * @template {ValueShape<T>} I The instance.
216
+ * @template {readonly any[]} [G=any[]] Additional arguments passed to the constructor.
217
+ * @extends {BaseDataConstructor<T, ValueShape<T>, I, [...G]>}
97
218
  */
98
- interface ValueConstructor<Value, Instance extends ValueShape<Value>, Args extends readonly any[] = any[]> extends DataConstructor$1<Value, ValueShape<Value>, Instance, [...Args]> {
219
+ interface ValueConstructor<T, I extends ValueShape<T>, G extends readonly any[] = any[]> extends DataConstructor$1<T, ValueShape<T>, I, [...G]> {
99
220
  }
100
221
 
101
- export type { AsyncReturn, DataAdapter, DataConstructor, DataConstructorInput, DataConstructorTuple, DataShape, IterValue, ValueConstructor, ValueShape };
222
+ export type { AdaptableDataConstructor, AdaptableDataConstructorInput, AdaptableDataConstructorTuple, AdaptableDataShape, AsyncReturn, DataAdapterConstructor, DataAdapterShape, DataConstructor, DataConstructorInput, DataConstructorTuple, DataShape, IterValue, ValueConstructor, ValueShape };