@typedly/data 4.0.0 → 5.0.0-beta.1
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 +137 -262
- package/package.json +22 -2
- package/types/typedly-data.d.ts +149 -48
package/README.md
CHANGED
|
@@ -18,25 +18,34 @@ A **TypeScript** type definitions package for [**@typescript-package/data**](htt
|
|
|
18
18
|
|
|
19
19
|
## Features
|
|
20
20
|
|
|
21
|
-
- **Adapter**: Optional data adapter to customize managing underlying data.
|
|
21
|
+
- **Adapter**: Optional data adapter to customize managing underlying data available under the [`@typedly/adaptable-data`](https://github.com/typedly/data-adapter).
|
|
22
|
+
- **Configurable**: Configurable data shape available under the [`@typedly/configurable-data`](https://github.com/typedly/configurable-data).
|
|
23
|
+
- **Traits**: Extended customization by traits, such as `Configurable`, `Adaptable`, `Serializable`, and `Transformable` under the [`@typedly/data-traits`](https://github.com/typedly/data-traits) package.
|
|
22
24
|
- **Shape**: The default shape for data of any `T` type with conditional async.
|
|
23
25
|
|
|
24
26
|
## Table of contents
|
|
25
27
|
|
|
28
|
+
- [Related packages](#related-packages)
|
|
26
29
|
- [Installation](#installation)
|
|
27
30
|
- [Api](#api)
|
|
28
|
-
- [
|
|
29
|
-
- [`DataAdapter`](#dataadapter)
|
|
30
|
-
- [`DataConstructor`](#dataconstructor)
|
|
31
|
-
- [`DataShape`](#datashape)
|
|
32
|
-
- [`ValueConstructor`](#valueconstructor)
|
|
33
|
-
- [`ValueShape`](#valueshape)
|
|
34
|
-
- [Type](#type)
|
|
31
|
+
- [Data](#data)
|
|
35
32
|
- [`AsyncReturn`](#asyncreturn)
|
|
33
|
+
- [`DataConfig`](#dataconfig)
|
|
36
34
|
- [`DataConstructorInput`](#dataconstructorinput)
|
|
37
35
|
- [`DataConstructorTuple`](#dataconstructortuple)
|
|
36
|
+
- [`DataConstructor`](#dataconstructor)
|
|
37
|
+
- [`DataSettings`](#datasettings)
|
|
38
|
+
- [`DataShape`](#datashape)
|
|
39
|
+
- [Inference](#inference)
|
|
40
|
+
- [`InferAsyncOf`](#inferasyncof)
|
|
41
|
+
- [`InferAsync`](#inferasync)
|
|
42
|
+
- [`InferValue`](#infervalue)
|
|
43
|
+
- [Iterable](#iterable)
|
|
38
44
|
- [`IterValue`](#itervalue)
|
|
39
|
-
- [
|
|
45
|
+
- [`IterableElement`](#itervalue)
|
|
46
|
+
- [Value](#value)
|
|
47
|
+
- [`ValueConstructor`](#valueconstructor)
|
|
48
|
+
- [`ValueShape`](#valueshape)
|
|
40
49
|
- [Contributing](#contributing)
|
|
41
50
|
- [Support](#support)
|
|
42
51
|
- [Code of Conduct](#code-of-conduct)
|
|
@@ -44,7 +53,17 @@ A **TypeScript** type definitions package for [**@typescript-package/data**](htt
|
|
|
44
53
|
- [Commit](#commit)
|
|
45
54
|
- [Versioning](#versioning)
|
|
46
55
|
- [License](#license)
|
|
47
|
-
- [
|
|
56
|
+
- [Packages](#packages)
|
|
57
|
+
|
|
58
|
+
## Related packages
|
|
59
|
+
|
|
60
|
+
- **[@typedly/adaptable-data](https://github.com/typedly/adaptable-data)**: A **TypeScript** type definitions for data adapter.
|
|
61
|
+
- **[@typedly/collection](https://github.com/typedly/collection)**: A **TypeScript** type definitions package for data collections with customizable storage.
|
|
62
|
+
- **[@typedly/configurable-data](https://github.com/typedly/configurable-data)**: A **TypeScript** type definitions for configurable data.
|
|
63
|
+
- **[@typedly/data-adapter](https://github.com/typedly/data-adapter)**: A **TypeScript** type definitions for data adapter.
|
|
64
|
+
- **[@typedly/data-traits](https://github.com/typedly/data-traits)**: A **TypeScript** type definitions for data traits.
|
|
65
|
+
- **[@typescript-package/data](https://github.com/typescript-package/data)**: A lightweight **TypeScript** library for basic data management.
|
|
66
|
+
- **[@typescript-package/collection](https://github.com/typescript-package/collection)**: A lightweight **TypeScript** library for data collection.
|
|
48
67
|
|
|
49
68
|
## Installation
|
|
50
69
|
|
|
@@ -64,164 +83,88 @@ npm install @typedly/data --save-peer
|
|
|
64
83
|
|
|
65
84
|
```typescript
|
|
66
85
|
import {
|
|
67
|
-
//
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
86
|
+
// Inference.
|
|
87
|
+
InferAsync,
|
|
88
|
+
InferAsyncOf,
|
|
89
|
+
InferValue,
|
|
90
|
+
|
|
91
|
+
// Iterable.
|
|
92
|
+
IterValue,
|
|
93
|
+
IterableElement,
|
|
94
|
+
|
|
95
|
+
// Return types
|
|
74
96
|
AsyncReturn,
|
|
97
|
+
// Config
|
|
98
|
+
DataConfig,
|
|
99
|
+
// Input types
|
|
75
100
|
DataConstructorInput,
|
|
76
101
|
DataConstructorTuple,
|
|
77
|
-
|
|
102
|
+
|
|
103
|
+
// Iterable
|
|
104
|
+
IterValue,
|
|
105
|
+
IterableElement,
|
|
106
|
+
|
|
107
|
+
// Value.
|
|
108
|
+
ValueConstructor,
|
|
109
|
+
ValueShape,
|
|
78
110
|
} from '@typedly/data';
|
|
79
111
|
```
|
|
80
112
|
|
|
81
|
-
###
|
|
113
|
+
### Inference
|
|
82
114
|
|
|
83
|
-
#### `
|
|
115
|
+
#### `InferAsyncOf`
|
|
84
116
|
|
|
85
|
-
|
|
117
|
+
Infers the async flag from a tuple of arguments, returning true if any of the arguments has an async flag set to true.
|
|
86
118
|
|
|
87
119
|
```typescript
|
|
88
|
-
import {
|
|
120
|
+
import { InferAsync } from '@typedly/data';
|
|
89
121
|
```
|
|
90
122
|
|
|
91
|
-
[Source](https://github.com/typedly/data/blob/main/src/
|
|
123
|
+
[Source](https://github.com/typedly/data/blob/main/src/inference/infer-async-of.type.ts)
|
|
92
124
|
|
|
93
|
-
#### `
|
|
125
|
+
#### `InferAsync`
|
|
94
126
|
|
|
95
|
-
|
|
127
|
+
Infers the async flag from the settings `DataSettings` or shape `DataShape`.
|
|
96
128
|
|
|
97
129
|
```typescript
|
|
98
|
-
import {
|
|
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
|
-
);
|
|
130
|
+
import { InferAsync } from '@typedly/data';
|
|
179
131
|
```
|
|
180
132
|
|
|
181
|
-
[Source](https://github.com/typedly/data/blob/main/src/
|
|
133
|
+
[Source](https://github.com/typedly/data/blob/main/src/inference/infer-async.type.ts)
|
|
182
134
|
|
|
183
|
-
#### `
|
|
135
|
+
#### `InferValue`
|
|
184
136
|
|
|
185
|
-
|
|
137
|
+
Infers the value type from a data shape interface.
|
|
186
138
|
|
|
187
139
|
```typescript
|
|
188
|
-
import {
|
|
189
|
-
|
|
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
|
-
}
|
|
140
|
+
import { InferAsync } from '@typedly/data';
|
|
202
141
|
```
|
|
203
142
|
|
|
204
|
-
[Source](https://github.com/typedly/data/blob/main/src/
|
|
143
|
+
[Source](https://github.com/typedly/data/blob/main/src/inference/infer-value.type.ts)
|
|
205
144
|
|
|
206
|
-
|
|
145
|
+
### Iterable
|
|
146
|
+
|
|
147
|
+
#### `IterElement`
|
|
148
|
+
|
|
149
|
+
The iterate element type.
|
|
207
150
|
|
|
208
151
|
```typescript
|
|
209
|
-
import {
|
|
152
|
+
import { IterElement } from '@typedly/data';
|
|
210
153
|
```
|
|
211
154
|
|
|
212
|
-
[Source](https://github.com/typedly/data/blob/main/src/
|
|
155
|
+
[Source](https://github.com/typedly/data/blob/main/src/iterable/iter-element.type.ts)
|
|
213
156
|
|
|
214
|
-
#### `
|
|
157
|
+
#### `IterValue`
|
|
215
158
|
|
|
216
|
-
The
|
|
159
|
+
The iterated value type.
|
|
217
160
|
|
|
218
161
|
```typescript
|
|
219
|
-
import {
|
|
162
|
+
import { IterValue } from '@typedly/data';
|
|
220
163
|
```
|
|
221
164
|
|
|
222
|
-
[Source](https://github.com/typedly/data/blob/main/src/
|
|
165
|
+
[Source](https://github.com/typedly/data/blob/main/src/iterable/iter-value.type.ts)
|
|
223
166
|
|
|
224
|
-
###
|
|
167
|
+
### Data
|
|
225
168
|
|
|
226
169
|
#### `AsyncReturn`
|
|
227
170
|
|
|
@@ -233,6 +176,16 @@ import { AsyncReturn } from '@typedly/data';
|
|
|
233
176
|
|
|
234
177
|
[Source](https://github.com/typedly/data/blob/main/src/lib/type/async-return.type.ts)
|
|
235
178
|
|
|
179
|
+
#### `DataConfig`
|
|
180
|
+
|
|
181
|
+
The type for the data configuration, which can be either a full configuration object of `C` or just an async flag.
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { DataConfig } from '@typedly/data';
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
[Source](https://github.com/typedly/data/blob/main/src/lib/type/data.config.ts)
|
|
188
|
+
|
|
236
189
|
#### `DataConstructorInput`
|
|
237
190
|
|
|
238
191
|
The input type for data constructors, with arguments support.
|
|
@@ -253,137 +206,56 @@ import { DataConstructorTuple } from '@typedly/data';
|
|
|
253
206
|
|
|
254
207
|
[Source](https://github.com/typedly/data/blob/main/src/lib/type/data-constructor-tuple.type.ts)
|
|
255
208
|
|
|
256
|
-
#### `
|
|
209
|
+
#### `DataConstructor`
|
|
257
210
|
|
|
258
|
-
The
|
|
211
|
+
The constructor interface for data types.
|
|
259
212
|
|
|
260
213
|
```typescript
|
|
261
|
-
import {
|
|
214
|
+
import { DataConstructor } from '@typedly/data';
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
[Source](https://github.com/typedly/data/blob/main/src/lib/interface/lib/data.constructor.ts)
|
|
218
|
+
|
|
219
|
+
#### `DataSettings`
|
|
220
|
+
|
|
221
|
+
The settings for a data type.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { DataSettings } from '@typedly/data';
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
[Source](https://github.com/typedly/data/blob/main/src/lib/interface/lib/data.settings.ts)
|
|
228
|
+
|
|
229
|
+
#### `DataShape`
|
|
230
|
+
|
|
231
|
+
The shape of a `Data` type.
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
import { DataShape } from '@typedly/data';
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
[Source](https://github.com/typedly/data/blob/main/src/lib/interface/data.shape.ts)
|
|
238
|
+
|
|
239
|
+
### Value
|
|
240
|
+
|
|
241
|
+
#### `ValueConstructor`
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
import { ValueConstructor } from '@typedly/data';
|
|
262
245
|
```
|
|
263
246
|
|
|
264
|
-
[Source](https://github.com/typedly/data/blob/main/src/lib/
|
|
247
|
+
[Source](https://github.com/typedly/data/blob/main/src/value/lib/value.constructor.ts)
|
|
248
|
+
|
|
249
|
+
#### `ValueShape`
|
|
265
250
|
|
|
266
|
-
|
|
251
|
+
The shape of a `Value` type.
|
|
267
252
|
|
|
268
253
|
```typescript
|
|
269
|
-
import {
|
|
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' });
|
|
254
|
+
import { ValueShape } from '@typedly/data';
|
|
385
255
|
```
|
|
386
256
|
|
|
257
|
+
[Source](https://github.com/typedly/data/blob/main/src/value/lib/value-shape.interface.ts)
|
|
258
|
+
|
|
387
259
|
## Contributing
|
|
388
260
|
|
|
389
261
|
Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
|
|
@@ -394,20 +266,23 @@ If you find this package useful and would like to support its and general develo
|
|
|
394
266
|
|
|
395
267
|
Support via:
|
|
396
268
|
|
|
397
|
-
- [
|
|
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)
|
|
269
|
+
- [4Fund](https://4fund.com/bruubs)
|
|
400
270
|
- [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
|
|
271
|
+
- [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
|
|
272
|
+
- [Ko-fi](https://ko-fi.com/sterblack)
|
|
273
|
+
- [OpenCollective](https://opencollective.com/sterblack)
|
|
401
274
|
- [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
|
|
402
|
-
- [
|
|
275
|
+
- [PayPal](https://paypal.me/sterblack)
|
|
276
|
+
- [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
|
|
277
|
+
- ~~[Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)~~
|
|
403
278
|
|
|
404
279
|
or via Trust Wallet
|
|
405
280
|
|
|
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
281
|
- [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
|
|
282
|
+
- [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
|
|
283
|
+
- [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
|
|
284
|
+
- [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
|
|
285
|
+
- [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
|
|
411
286
|
|
|
412
287
|
Thanks for your support!
|
|
413
288
|
|
|
@@ -448,7 +323,7 @@ How do I know when to release 1.0.0?
|
|
|
448
323
|
|
|
449
324
|
MIT © typedly ([license][typedly-license])
|
|
450
325
|
|
|
451
|
-
##
|
|
326
|
+
## Packages
|
|
452
327
|
|
|
453
328
|
- **[@typescript-package/chain-descriptor](https://github.com/typescript-package/chain-descriptor)**: A **TypeScript** library for chain property descriptor.
|
|
454
329
|
- **[@typescript-package/controlled-descriptor](https://github.com/typescript-package/controlled-descriptor)**: A **TypeScript** library for controlled property descriptor.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typedly/data",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-beta.1",
|
|
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": "
|
|
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
|
],
|
package/types/typedly-data.d.ts
CHANGED
|
@@ -1,102 +1,203 @@
|
|
|
1
1
|
import { DataConstructor as DataConstructor$1 } from '@typedly/constructor';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* @description The
|
|
4
|
+
* @description The settings for a data type.
|
|
5
5
|
* @export
|
|
6
|
-
* @
|
|
7
|
-
* @template
|
|
6
|
+
* @interface DataSettings
|
|
7
|
+
* @template {boolean} [R=false] The async flag.
|
|
8
|
+
*/
|
|
9
|
+
interface DataSettings<R extends boolean = false> {
|
|
10
|
+
/**
|
|
11
|
+
* @description Optional async flag to indicate whether the data type is asynchronous.
|
|
12
|
+
* @default false
|
|
13
|
+
* @type {?R}
|
|
14
|
+
*/
|
|
15
|
+
async?: R;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @description The type for the data configuration, which can be either a full configuration object of `C` or just an async flag.
|
|
20
|
+
* @export
|
|
21
|
+
* @template {DataSettings<R> | undefined} C The type of the settings for configuration.
|
|
22
|
+
* @template {boolean} [R=InferAsync<C>] The type of the async flag.
|
|
8
23
|
*/
|
|
9
|
-
type
|
|
24
|
+
type DataConfig<C extends DataSettings<R> | undefined, R extends boolean = InferAsync<C>> = C extends DataSettings<R> ? Required<C> : {
|
|
25
|
+
async: R;
|
|
26
|
+
};
|
|
10
27
|
|
|
11
28
|
/**
|
|
12
29
|
* @description The type to provide data constructor with arguments.
|
|
13
30
|
* @export
|
|
14
|
-
* @template
|
|
15
|
-
* @template
|
|
16
|
-
* @template {
|
|
31
|
+
* @template {DataShape<T, R>} I The type of the data instance.
|
|
32
|
+
* @template [T=InferValue<I>] The type of value instance, inferred from I if possible.
|
|
33
|
+
* @template {boolean} [R=InferAsync<I>] The type of the readonly flag, inferred from I if possible.
|
|
34
|
+
* @template {readonly any[]} [G=[]] The type of the arguments tuple.
|
|
17
35
|
*/
|
|
18
|
-
type DataConstructorTuple<
|
|
36
|
+
type DataConstructorTuple<I extends DataShape<T, R>, T = InferValue<I>, R extends boolean = InferAsync<I>, G extends readonly any[] = []> = [DataConstructor<I, T, R, G>, ...G];
|
|
19
37
|
|
|
20
38
|
/**
|
|
21
39
|
* @description The input type for data constructors, with arguments support.
|
|
22
40
|
* @export
|
|
23
|
-
* @template
|
|
24
|
-
* @template {DataShape<
|
|
25
|
-
* @template
|
|
41
|
+
* @template {DataShape<T, C, R>} I The type of the data instance.
|
|
42
|
+
* @template {{ async?: boolean }} [C=I extends DataShape<any, infer V, any> ? V : any] The type of the configuration, inferred from I if possible.
|
|
43
|
+
* @template [T=I extends DataShape<infer U, any, any> ? U : any] The type of value instance, inferred from I if possible.
|
|
44
|
+
* @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.
|
|
45
|
+
* @template {readonly any[]} [G=[]] The type of the arguments tuple.
|
|
46
|
+
*/
|
|
47
|
+
type DataConstructorInput<I extends DataShape<T, R>, T = I extends DataShape<infer U, any> ? U : any, R extends boolean = InferAsync<I>, G extends readonly any[] = []> = DataConstructor<I, T, R, G> | DataConstructorTuple<I, T, R, G>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description The conditional return type for async methods.
|
|
51
|
+
* @export
|
|
52
|
+
* @template {boolean} R The boolean flag indicating if the return type should be a `Promise`.
|
|
53
|
+
* @template T The type of the value to be returned.
|
|
26
54
|
*/
|
|
27
|
-
type
|
|
55
|
+
type AsyncReturn<R extends boolean, T> = R extends true ? Promise<T> : T;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @description The iterate element type.
|
|
59
|
+
* @export
|
|
60
|
+
* @template T The type of the iterable.
|
|
61
|
+
*/
|
|
62
|
+
type IterableElement<T> = T extends Iterable<infer U> ? U : T;
|
|
28
63
|
|
|
29
64
|
/**
|
|
30
65
|
* @description The iterated value type.
|
|
31
66
|
* @export
|
|
32
67
|
* @template T The type of iterated value constrained by the `Iterable` type.
|
|
33
68
|
*/
|
|
34
|
-
type IterValue<T> =
|
|
69
|
+
type IterValue<T> = IterableElement<T>;
|
|
35
70
|
|
|
36
71
|
/**
|
|
37
|
-
* @description The shape of a
|
|
72
|
+
* @description The shape of a data type.
|
|
38
73
|
* @export
|
|
39
74
|
* @interface DataShape
|
|
40
75
|
* @template T The value type.
|
|
41
|
-
* @template {boolean} [
|
|
76
|
+
* @template {boolean} [R=false] The async flag.
|
|
42
77
|
*/
|
|
43
|
-
interface DataShape<T,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
78
|
+
interface DataShape<T, R extends boolean = false> {
|
|
79
|
+
/**
|
|
80
|
+
* @description Indicates whether the methods return a `Promise`.
|
|
81
|
+
* @readonly
|
|
82
|
+
* @type {R}
|
|
83
|
+
*/
|
|
84
|
+
readonly async: R;
|
|
85
|
+
/**
|
|
86
|
+
* @description The value of the `Data` instance.
|
|
87
|
+
* @readonly
|
|
88
|
+
* @type {T}
|
|
89
|
+
*/
|
|
90
|
+
readonly value: T;
|
|
91
|
+
/**
|
|
92
|
+
* @description Clears the value of the `Data` instance.
|
|
93
|
+
* @returns {AsyncReturn<R, this>}
|
|
94
|
+
*/
|
|
95
|
+
clear(): AsyncReturn<R, this>;
|
|
96
|
+
/**
|
|
97
|
+
* @description Destroys the `Data` instance, making it unusable.
|
|
98
|
+
* @returns {AsyncReturn<R, this>}
|
|
99
|
+
*/
|
|
100
|
+
destroy(): AsyncReturn<R, this>;
|
|
101
|
+
/**
|
|
102
|
+
* @description Gets the value of the `Data` instance.
|
|
103
|
+
* @returns {AsyncReturn<R, T>}
|
|
104
|
+
*/
|
|
105
|
+
getValue(): AsyncReturn<R, T>;
|
|
106
|
+
/**
|
|
107
|
+
* @description Locks the `Data` instance, preventing any further modifications to its value.
|
|
108
|
+
* @returns {AsyncReturn<R, this>} The `Data` instance at the time of locking.
|
|
109
|
+
*/
|
|
110
|
+
lock(): AsyncReturn<R, this>;
|
|
111
|
+
/**
|
|
112
|
+
* @description Sets the value of the `Data` instance.
|
|
113
|
+
* @param {T} value
|
|
114
|
+
* @returns {AsyncReturn<R, this>}
|
|
115
|
+
*/
|
|
116
|
+
setValue(value: T): AsyncReturn<R, this>;
|
|
117
|
+
/**
|
|
118
|
+
* @description The string tag of the `Data` instance.
|
|
119
|
+
* @readonly
|
|
120
|
+
* @type {?string}
|
|
121
|
+
*/
|
|
122
|
+
readonly [Symbol.toStringTag]?: string;
|
|
123
|
+
/**
|
|
124
|
+
* @description The iterator method for the `Data` instance, allowing it to be iterable.
|
|
125
|
+
* @returns {IterableIterator<IterValue<T>>}
|
|
126
|
+
*/
|
|
51
127
|
[Symbol.iterator]?(): IterableIterator<IterValue<T>>;
|
|
128
|
+
/**
|
|
129
|
+
* @description The asynchronous iterator method for the `Data` instance, allowing it to be asynchronously iterable.
|
|
130
|
+
* @returns {AsyncIterableIterator<IterValue<T>>}
|
|
131
|
+
*/
|
|
52
132
|
[Symbol.asyncIterator]?(): AsyncIterableIterator<IterValue<T>>;
|
|
53
133
|
}
|
|
54
134
|
|
|
55
135
|
/**
|
|
56
|
-
* @description The
|
|
136
|
+
* @description The constructor interface for data types.
|
|
57
137
|
* @export
|
|
58
|
-
* @interface
|
|
59
|
-
* @template T
|
|
60
|
-
* @template
|
|
61
|
-
* @
|
|
138
|
+
* @interface DataConstructor
|
|
139
|
+
* @template {DataShape<T, R>} I The data instance type.
|
|
140
|
+
* @template [T=InferValue<I>] The data type inferred from `I`.
|
|
141
|
+
* @template {boolean} [R=InferAsync<I>] The async flag, inferred from `I` if possible.
|
|
142
|
+
* @template {readonly any[]} [G=[]] Additional arguments.
|
|
62
143
|
*/
|
|
63
|
-
interface
|
|
64
|
-
|
|
144
|
+
interface DataConstructor<I extends DataShape<T, R>, T = InferValue<I>, R extends boolean = InferAsync<I>, G extends readonly any[] = []> {
|
|
145
|
+
new (
|
|
146
|
+
/** The optional initial value for the data instance. */
|
|
147
|
+
value: T,
|
|
148
|
+
/** Additional arguments for the constructor. */
|
|
149
|
+
...args: G): I;
|
|
65
150
|
}
|
|
66
151
|
|
|
67
152
|
/**
|
|
68
|
-
* @description
|
|
153
|
+
* @description Infers the async flag from the settings `DataSettings` or shape `DataShape`.
|
|
69
154
|
* @export
|
|
70
|
-
* @
|
|
71
|
-
* @template
|
|
72
|
-
* @template {DataShape<Value>} Instance The instance.
|
|
73
|
-
* @template {readonly any[]} [Args=any[]]
|
|
74
|
-
* @extends {BaseDataConstructor<Value, DataShape<Value>, Instance, [...Args]>}
|
|
155
|
+
* @template T The type of the configuration object.
|
|
156
|
+
* @template F The default async flag if it cannot be inferred from T.
|
|
75
157
|
*/
|
|
76
|
-
|
|
77
|
-
|
|
158
|
+
type InferAsync<T = undefined, F = false> = T extends DataSettings<infer R extends boolean> ? R : T extends DataShape<any, infer R extends boolean> ? R : F;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @description Infers the async flag from a tuple of arguments, returning true if any of the arguments has an async flag set to true.
|
|
162
|
+
* @export
|
|
163
|
+
* @template {readonly any[]} A The tuple of arguments to infer the async flag from.
|
|
164
|
+
* @template [F=false] The default async flag value if the tuple is empty.
|
|
165
|
+
*/
|
|
166
|
+
type InferAsyncOf<A extends readonly any[], F = false> = A extends [infer Head, ...infer Tail] ? InferAsync<Head> extends true ? true : InferAsyncOf<Tail> : F;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* @description Infers the value type from a data shape interface.
|
|
170
|
+
* It checks if the input type `I` extends `DataShape` and extracts the value type accordingly.
|
|
171
|
+
* If none of the conditions match, it returns the fallback type `F`.
|
|
172
|
+
* @export
|
|
173
|
+
* @template I The data shape type.
|
|
174
|
+
* @template [F=any] The fallback type if inference fails.
|
|
175
|
+
*/
|
|
176
|
+
type InferValue<I, F = any> = I extends DataShape<infer T> ? T : I extends {
|
|
177
|
+
value?: infer V;
|
|
178
|
+
} ? V : F;
|
|
78
179
|
|
|
79
180
|
/**
|
|
80
181
|
* @description The value shape.
|
|
81
182
|
* @export
|
|
82
183
|
* @interface ValueShape
|
|
83
|
-
* @template
|
|
184
|
+
* @template T The type of value.
|
|
84
185
|
*/
|
|
85
|
-
interface ValueShape<
|
|
86
|
-
get value():
|
|
87
|
-
set(value:
|
|
186
|
+
interface ValueShape<T> {
|
|
187
|
+
get value(): T;
|
|
188
|
+
set(value: T): this;
|
|
88
189
|
}
|
|
89
190
|
|
|
90
191
|
/**
|
|
91
192
|
* @description The constructor for value in data for advanced customization.
|
|
92
193
|
* @export
|
|
93
194
|
* @interface ValueConstructor
|
|
94
|
-
* @template
|
|
95
|
-
* @template {ValueShape<
|
|
96
|
-
* @template {readonly any[]} [
|
|
97
|
-
* @extends {BaseDataConstructor<
|
|
195
|
+
* @template T The value type.
|
|
196
|
+
* @template {ValueShape<T>} I The instance.
|
|
197
|
+
* @template {readonly any[]} [G=any[]] Additional arguments passed to the constructor.
|
|
198
|
+
* @extends {BaseDataConstructor<T, ValueShape<T>, I, [...G]>}
|
|
98
199
|
*/
|
|
99
|
-
interface ValueConstructor<
|
|
200
|
+
interface ValueConstructor<T, I extends ValueShape<T>, G extends readonly any[] = any[]> extends DataConstructor$1<T, ValueShape<T>, I, [...G]> {
|
|
100
201
|
}
|
|
101
202
|
|
|
102
|
-
export type { AsyncReturn,
|
|
203
|
+
export type { AsyncReturn, DataConfig, DataConstructor, DataConstructorInput, DataConstructorTuple, DataSettings, DataShape, InferAsync, InferAsyncOf, InferValue, IterValue, IterableElement, ValueConstructor, ValueShape };
|