@typedly/data 4.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,152 +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
- public 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
- public clear(): this { return this; }
122
- public destroy(): this { return this; }
123
- public lock(): this { return this; };
124
- public getValue(): Value { return this.value; }
125
- public setValue(value: Value): this { this.validate(value); return this; }
126
- public validate(value: Value): boolean { return true; }
127
- }
128
-
129
- // Create `ProfileClass` with customizable data.
130
- export class ProfileClass<
131
- Value extends { age: number, name: string },
132
- DataType extends DataShape<Value>,
133
- Args extends any[]
134
- > {
135
-
136
- public get age(): Value['age'] {
137
- return this.#data.value.age;
138
- }
139
-
140
- public get name(): Value['name'] {
141
- return this.#data.value.name;
142
- }
143
-
144
- public get data() {
145
- return this.#data;
146
- }
147
-
148
- #data: DataType;
149
-
150
- constructor(value: Value, dataCtor: DataConstructor<Value, DataType>);
151
- constructor(value: Value, dataCtor: [DataConstructor<Value, DataType>, ...Args]);
152
- constructor(value: Value, dataCtor: any) {
153
- // ...implementation
154
- console.log(`DataConstructor`, value, dataCtor[1]);
155
- this.#data = Array.isArray(dataCtor)
156
- ? new dataCtor[0](value, ...dataCtor.slice(1))
157
- : new dataCtor(value);
158
- }
159
- }
160
-
161
- // Initialize.
162
- // const frankProfile: ProfileClass<object, ProfileData<object>, any[]>
163
- const frankProfile = new ProfileClass({ age: 37, name: 'Frank' }, ProfileData);
164
-
165
- frankProfile.age; // 37
166
- frankProfile.name; // Frank
167
-
168
- // Set the data.
169
- frankProfile.data.setValue({ age: 37, name: 'Frank' });
170
- frankProfile.data.clear();
171
- frankProfile.data.lock();
172
- frankProfile.data.value;
173
-
174
- // Initialize with arguments.
175
- const markProfile = new ProfileClass(
176
- { age: 27, name: 'Mark' },
177
- [ProfileData, 'private', true]
178
- );
134
+ import { DataConstructor } from '@typedly/data';
179
135
  ```
180
136
 
181
- [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)
182
138
 
183
- #### `DataShape`
139
+ #### `ValueConstructor`
184
140
 
185
- 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.
186
152
 
187
153
  ```typescript
188
- import { DataShape } from '@typedly/data';
154
+ import { AdaptableDataShape } from '@typedly/data';
155
+ ```
156
+
157
+ [Source](https://github.com/typedly/data/blob/main/src/lib/interface/adaptable-data.shape.ts)
158
+
159
+ #### `DataAdapterShape`
189
160
 
190
- // Create a simple data class with value as property.
191
- export class TestData<Type> implements DataShape<Type> {
192
- get value(): Type { return 27 as Type; }
193
- clear(): this { return this; }
194
- destroy(): this { return this; }
195
- getValue(): Type { return 27 as Type; }
196
- lock(): this { return this; };
197
- setValue(value: Type): this { return this; }
198
- constructor(value: Type, ...args: any[]) {
199
- console.log(`Instantiated DataConstructor`, value, ...args);
200
- }
201
- }
161
+ The adapter interface for data types.
162
+
163
+ ```typescript
164
+ import { DataAdapterShape } from '@typedly/data';
202
165
  ```
203
166
 
204
- [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)
205
168
 
206
- #### `ValueConstructor`
169
+ #### `DataShape`
170
+
171
+ The shape of a `Data` type.
207
172
 
208
173
  ```typescript
209
- import { ValueConstructor } from '@typedly/data';
174
+ import { DataShape } from '@typedly/data';
210
175
  ```
211
176
 
212
- [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)
213
178
 
214
179
  #### `ValueShape`
215
180
 
@@ -223,6 +188,22 @@ import { ValueShape } from '@typedly/data';
223
188
 
224
189
  ### Type
225
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
+
226
207
  #### `AsyncReturn`
227
208
 
228
209
  The conditional return type for async methods.
@@ -263,127 +244,6 @@ import { IterValue } from '@typedly/data';
263
244
 
264
245
  [Source](https://github.com/typedly/data/blob/main/src/lib/type/iter-value.type.ts)
265
246
 
266
- ### Full example usage
267
-
268
- ```typescript
269
- import { DataConstructor, DataShape, ValueConstructor, ValueShape } from '@typedly/data';
270
-
271
- // Import ValueShape and ValueConstructor.
272
- // Create a profile data value.
273
- export class ProfileDataValue<
274
- Type extends { age: number, name: string },
275
- Args extends any[] = any[]
276
- > implements ValueShape<Type> {
277
- get value(): Type {
278
- return {
279
- age: this.#age,
280
- name: this.#name
281
- } as Type;
282
- }
283
-
284
- #age: Type['age'];
285
- #name: Type['name'];
286
-
287
- constructor(value: Type, ...args: Args) {
288
- console.log(`Instantiated ValueConstructor`, value, ...args);
289
- this.#age = value.age;
290
- this.#name = value.name;
291
- }
292
-
293
- set(value: Type): this { return this; }
294
- }
295
-
296
- export class ProfileDataOfValue<
297
- Value extends { age: number, name: string },
298
- Args extends any[] = any[],
299
- ValueInstance extends ValueShape<Value> = ProfileDataValue<Value, Args>,
300
- > implements DataShape<Value> {
301
-
302
- get value(): Value {
303
- return {
304
- } as Value;
305
- }
306
-
307
- get valueInstance(): ValueInstance {
308
- return this.#value;
309
- }
310
-
311
- #value;
312
- constructor(
313
- value: Value,
314
- valueCtor: ValueConstructor<Value, ValueInstance, Args> = ProfileDataValue<Value, Args> as any,
315
- ...args: Args
316
- ) {
317
- console.log(`Instantiated DataConstructor`, value, ...args);
318
- this.#value = new valueCtor(value, ...args);
319
- }
320
-
321
- setValue(value: Value): this { this.validate(value); return this; }
322
- getValue(): Value {
323
- return this.#value.value;
324
- }
325
- clear(): this { return this; }
326
- destroy(): this { return this; }
327
- lock(): this { return this; };
328
- validate(value: Value): boolean {
329
- return true;
330
- }
331
- }
332
-
333
- // const profileDataOfValue: ProfileDataOfValue<{
334
- // age: number;
335
- // name: string;
336
- // }, ProfileDataValue<{
337
- // age: number;
338
- // name: string;
339
- // }, []>, []>
340
- const profileDataOfValue = new ProfileDataOfValue({
341
- age: 37,
342
- name: 'Mark'
343
- }, ProfileDataValue);
344
-
345
- const dataSymbol = Symbol('data');
346
-
347
- // Create `ProfileClass` with customizable data.
348
- export class ProfileClass<
349
- Value extends { age: number, name: string },
350
- DataType extends DataShape<Value>,
351
- Args extends any[]
352
- > {
353
-
354
- public get age(): Value['age'] {
355
- return this.#data.value.age;
356
- }
357
-
358
- public get name(): Value['name'] {
359
- return this.#data.value.name;
360
- }
361
-
362
- public get [dataSymbol]() {
363
- return this.#data;
364
- }
365
-
366
- #data: DataType;
367
-
368
- constructor(value: Value, dataCtor: DataConstructor<Value, DataType, Args>);
369
- constructor(value: Value, dataCtor: [DataConstructor<Value, DataType, Args>, ...Args]);
370
- constructor(value: Value, dataCtor: any) {
371
- // ...implementation
372
- console.log(`DataConstructor`, value, dataCtor[1]);
373
- this.#data = Array.isArray(dataCtor)
374
- ? new dataCtor[0](value, ...dataCtor.slice(1))
375
- : new dataCtor(value);
376
- }
377
- }
378
-
379
- const markProfile = new ProfileClass({ age: 37, name: 'Mark' }, ProfileDataOfValue);
380
-
381
- markProfile.age // 37
382
- markProfile.name // Mark
383
- markProfile[dataSymbol].value // { age, name }
384
- markProfile[dataSymbol].valueInstance.set({ age: 27, name: 'Frank' });
385
- ```
386
-
387
247
  ## Contributing
388
248
 
389
249
  Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
@@ -394,20 +254,23 @@ If you find this package useful and would like to support its and general develo
394
254
 
395
255
  Support via:
396
256
 
397
- - [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
398
- - ~~[Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)~~
399
- - [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
257
+ - [4Fund](https://4fund.com/bruubs)
400
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)
401
262
  - [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
402
- - [4Fund](https://4fund.com/bruubs)
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)~~
403
266
 
404
267
  or via Trust Wallet
405
268
 
406
- - [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
407
- - [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
408
- - [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
409
- - [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
410
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)
411
274
 
412
275
  Thanks for your support!
413
276
 
@@ -450,6 +313,10 @@ MIT © typedly ([license][typedly-license])
450
313
 
451
314
  ## Related packages
452
315
 
316
+ - **[@typescript-package/collection](https://github.com/typescript-package/collection)**: A lightweight TypeScript library for data collection.
317
+
318
+ ## Packages
319
+
453
320
  - **[@typescript-package/chain-descriptor](https://github.com/typescript-package/chain-descriptor)**: A **TypeScript** library for chain property descriptor.
454
321
  - **[@typescript-package/controlled-descriptor](https://github.com/typescript-package/controlled-descriptor)**: A **TypeScript** library for controlled property descriptor.
455
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": "4.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,46 +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>;
47
- getValue(): AsyncReturn<Async, T>;
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
+ */
48
97
  lock(): this;
49
- setValue(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
+ */
50
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
+ */
51
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
+ */
52
118
  [Symbol.asyncIterator]?(): AsyncIterableIterator<IterValue<T>>;
53
119
  }
54
120
 
55
121
  /**
56
122
  * @description The adapter interface for data types.
57
123
  * @export
58
- * @interface DataAdapter
124
+ * @interface DataAdapterShape
59
125
  * @template T The type of the data value.
126
+ * @template C The type of the configuration object.
60
127
  * @template {boolean} [R=false] The type of the return values for methods.
61
- * @extends {DataShape<T, R>}
128
+ * @extends {DataShape<T, C, R>}
62
129
  */
63
- 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> {
64
133
  version?: string;
65
134
  }
66
135
 
67
136
  /**
68
- * @description The constructor interface for data types.
137
+ * @description The shape of a data type with optional adapter.
69
138
  * @export
70
- * @interface DataConstructor
71
- * @template Value
72
- * @template {DataShape<Value>} Instance The instance.
73
- * @template {readonly any[]} [Args=any[]]
74
- * @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>}
75
145
  */
76
- 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;
77
148
  }
78
149
 
79
150
  /**
@@ -87,16 +158,65 @@ interface ValueShape<Type> {
87
158
  set(value: Type): this;
88
159
  }
89
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
+
90
210
  /**
91
211
  * @description The constructor for value in data for advanced customization.
92
212
  * @export
93
213
  * @interface ValueConstructor
94
- * @template Value The value type.
95
- * @template {ValueShape<Value>} Instance The instance.
96
- * @template {readonly any[]} [Args=any[]] Additional arguments passed to the constructor.
97
- * @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]>}
98
218
  */
99
- 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]> {
100
220
  }
101
221
 
102
- 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 };