@typedly/data-traits 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 typedly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,532 @@
1
+ <a href="https://github.com/typescript-package">
2
+ <img
3
+ src="https://avatars.githubusercontent.com/u/189665258?s=150&u=712e292bae048947d1f7d2020d7d38875c40e63a&v=4"
4
+ title="@typedly/data-traits - A TypeScript type definitions package for configurable data traits, providing various kinds of configurable data interfaces."
5
+ />
6
+ </a>
7
+
8
+ ## @typedly/data-traits
9
+
10
+ <!-- npm badge -->
11
+ [![npm version][package-npm-badge-svg]][package-npm-badge]
12
+ [![GitHub issues][package-badge-issues]][package-issues]
13
+ [![GitHub license][package-badge-license]][package-license]
14
+
15
+ <!-- GitHub badges -->
16
+ [![GitHub issues][package-badge-issues]][package-issues]
17
+ [![GitHub forks][package-badge-forks]][package-forks]
18
+ [![GitHub stars][package-badge-stars]][package-stars]
19
+ [![GitHub license][package-badge-license]][package-license]
20
+
21
+ <!-- Sponsors -->
22
+ [![GitHub Sponsors][github-badge-sponsor]][github-sponsor-link]
23
+ [![Patreon Sponsors][patreon-badge]][patreon-link]
24
+
25
+ A **TypeScript** type definitions package for configurable data traits, providing various kinds of configurable data interfaces.
26
+
27
+ ## Features
28
+
29
+ - **Adaptable**: Use custom adapters to define how data is stored and retrieved (localStorage, API, memory, etc.)
30
+ - **Cacheable**: Built-in caching support with configurable expiration and refresh capabilities
31
+ - **Cleanable**: Clear data, and cleanup resources
32
+ - **Cloneable**: Create deep, or shallow copies of data instances
33
+ - **Collection**: Base collection shape
34
+ - **Comparable**: Compare data instances for equality and ordering
35
+ - **Compressible**: Compress and decompress data
36
+ - **Configurable**: Flexible configuration system for customizing data behavior and constraints
37
+ - **Encryptable**: Encrypt and decrypt sensitive data with built-in security support
38
+ - **Exportable**: Export data to multiple formats (JSON, XML, CSV, etc.)
39
+ - **Freezable**: Control immutability by freezing and unfreezing data instances
40
+ - **Identifiable**: Identify data object by tag or `ID`
41
+ - **Indexable**: Access and manage data elements by numeric or key-based indices
42
+ - **Measurable**: Track data size, memory usage, and performance metrics
43
+ - **Mergeable**: Merge data from multiple sources with customizable merge strategies
44
+ - **Observable**: Subscribe to data changes with reactive programming support
45
+ - **Paginated**: Navigate large datasets with page-based chunking and iteration
46
+ - **Persistable**: Persist data to storage automatically with **save**/**load** capabilities
47
+ - **Printable**: Format and output data in human-readable formats for display or debugging
48
+ - **Queryable**: Query and filter complex data structures with predicate functions
49
+ - **Resettable**: Reset data to initial state and track modifications
50
+ - **Revertible**: Undo changes and revert to previous states with rollback support
51
+ - **Serializable**: Serialize and deserialize data values with async support
52
+ - **Timestamped**: Automatic tracking of creation, modification, and access times
53
+ - **Transformable**: Transform values with `map` and `flatMap` operations
54
+ - **Validatable**: Comprehensive validation system with custom validators and error reporting
55
+ - **Versionable**: Version control with history tracking, snapshots, and rollback support
56
+
57
+ ## Table of contents
58
+
59
+ - [Related packages](#related-packages)
60
+ - [Installation](#installation)
61
+ - [Api](#api)
62
+ - Interface
63
+ - [`Adaptable`](#adaptable)
64
+ - [`Cacheable`](#cacheable)
65
+ - [`Cleanable`](#cleanable)
66
+ - [`Cloneable`](#cloneable)
67
+ - [`Collection`](#collection)
68
+ - [`Comparable`](#comparable)
69
+ - [`Compressible`](#compressible)
70
+ - [`Configurable`](#configurable)
71
+ - [`Encryptable`](#encryptable)
72
+ - [`Exportable`](#exportable)
73
+ - [`Freezable`](#freezable)
74
+ - [`Identifiable`](#identifiable)
75
+ - [`Indexable`](#indexable)
76
+ - [`Measurable`](#measurable)
77
+ - [`Mergeable`](#mergeable)
78
+ - [`Observable`](#observable)
79
+ - [`Paginated`](#paginated)
80
+ - [`Persistable`](#persistable)
81
+ - [`Printable`](#printable)
82
+ - [`Queryable`](#queryable)
83
+ - [`Resettable`](#resettable)
84
+ - [`Revertible`](#revertible)
85
+ - [`Serializable`](#serializable)
86
+ - [`Timestamped`](#timestamped)
87
+ - [`Transformable`](#transformable)
88
+ - [`Validatable`](#validatable)
89
+ - [`Versionable`](#versionable)
90
+ - [Contributing](#contributing)
91
+ - [Support](#support)
92
+ - [Code of Conduct](#code-of-conduct)
93
+ - [Git](#git)
94
+ - [Commit](#commit)
95
+ - [Versioning](#versioning)
96
+ - [License](#license)
97
+ - [Packages](#packages)
98
+
99
+ ## Related packages
100
+
101
+ - **[@typedly/adaptable-data](https://github.com/typedly/adaptable-data)**: A **TypeScript** type definitions for data adapter.
102
+ - **[@typedly/collection](https://github.com/typedly/collection)**: A **TypeScript** type definitions package for data collections with customizable storage.
103
+ - **[@typedly/configurable-data](https://github.com/typedly/configurable-data)**: A **TypeScript** type definitions for configurable data.
104
+ - **[@typedly/data-adapter](https://github.com/typedly/data-adapter)**: A **TypeScript** type definitions for data adapter.
105
+ - **[@typedly/data](https://github.com/typedly/data)**: A **TypeScript** type definitions for [`@typescript-package/data`](https://github.com/typedly/data).
106
+ - **[@typescript-package/data](https://github.com/typescript-package/data)**: A lightweight **TypeScript** library for basic data management.
107
+ - **[@typescript-package/collection](https://github.com/typescript-package/collection)**: A lightweight **TypeScript** library for data collection.
108
+
109
+ ## Installation
110
+
111
+ ```bash
112
+ npm install @typedly/data-traits --save-peer
113
+ ```
114
+
115
+ ## Api
116
+
117
+ ```typescript
118
+ import {
119
+ // Interface.
120
+ Adaptable,
121
+ Cacheable,
122
+ Collection,
123
+ Comparable,
124
+ Compressible,
125
+ Configurable,
126
+ Encryptable,
127
+ Exportable,
128
+ Freezable,
129
+ Identifiable,
130
+ Indexable,
131
+ Measurable,
132
+ Mergeable,
133
+ Observable,
134
+ Paginated,
135
+ Persistable,
136
+ Printable,
137
+ Queryable,
138
+ Resettable,
139
+ Revertible,
140
+ Serializable,
141
+ Timestamped,
142
+ Transformable,
143
+ Validatable,
144
+ Versionable,
145
+ } from '@typedly/data-traits';
146
+ ```
147
+
148
+ ### Interface
149
+
150
+ ### `Adaptable`
151
+
152
+ The interface for adaptable data types, which can optionally use a data adapter to manage their value and behavior.
153
+
154
+ ```typescript
155
+ import { Adaptable } from '@typedly/data-traits';
156
+ ```
157
+
158
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/adaptable.trait.ts)
159
+
160
+ ### `Cacheable`
161
+
162
+ The interface for cacheable data types, which can be cached with an optional expiration time and invalidated or refreshed as needed.
163
+
164
+ ```typescript
165
+ import { Cacheable } from '@typedly/data-traits';
166
+ ```
167
+
168
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/cacheable.trait.ts)
169
+
170
+ ### `Cleanable`
171
+
172
+ Capability for objects that can be cleaned or cleared.
173
+
174
+ ```typescript
175
+ import { Cleanable } from '@typedly/data-traits';
176
+ ```
177
+
178
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/cleanable.trait.ts)
179
+
180
+ ### `Cloneable`
181
+
182
+ Capability for objects that can be cloned.
183
+
184
+ ```typescript
185
+ import { Cloneable } from '@typedly/data-traits';
186
+ ```
187
+
188
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/cloneable.trait.ts)
189
+
190
+ ### `Collection`
191
+
192
+ Comparable interface for data types that can be compared.
193
+
194
+ ```typescript
195
+ import { Collection } from '@typedly/data-traits';
196
+ ```
197
+
198
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/collection.trait.ts)
199
+
200
+ ### `Comparable`
201
+
202
+ Comparable interface for data types that can be compared.
203
+
204
+ ```typescript
205
+ import { Comparable } from '@typedly/data-traits';
206
+ ```
207
+
208
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/comparable.trait.ts)
209
+
210
+ ### `Compressible`
211
+
212
+ Interface for data types that can be compressed and decompressed, allowing for efficient storage and transmission of data.
213
+
214
+ ```typescript
215
+ import { Compressible } from '@typedly/data-traits';
216
+ ```
217
+
218
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/compressible.trait.ts)
219
+
220
+ ### `Configurable`
221
+
222
+ The interface for configurable data types, which can optionally have a configuration object.
223
+
224
+ ```typescript
225
+ import { Configurable } from '@typedly/data-traits';
226
+ ```
227
+
228
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/configurable.trait.ts)
229
+
230
+ ### `Encryptable`
231
+
232
+ Interface for data types that can be encrypted and decrypted.
233
+
234
+ ```typescript
235
+ import { Encryptable } from '@typedly/data-traits';
236
+ ```
237
+
238
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/encryptable.trait.ts)
239
+
240
+ ### `Exportable`
241
+
242
+ The interface for exportable data types, which can be exported to various formats.
243
+
244
+ ```typescript
245
+ import { Exportable } from '@typedly/data-traits';
246
+ ```
247
+
248
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/exportable.trait.ts)
249
+
250
+ ### `Freezable`
251
+
252
+ The interface for freezable data types, which can be frozen to prevent modifications and optionally unfrozen.
253
+
254
+ ```typescript
255
+ import { Freezable } from '@typedly/data-traits';
256
+ ```
257
+
258
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/freezable.trait.ts)
259
+
260
+ ### `Identifiable`
261
+
262
+ Trait for objects that have an ID or unique identifier.x
263
+
264
+ ```typescript
265
+ import { Identifiable } from '@typedly/data-traits';
266
+ ```
267
+
268
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/identifiable.trait.ts)
269
+
270
+ ### `Indexable`
271
+
272
+ Trait for objects that support indexing or retrieving by `numeric` or `string` index.
273
+
274
+ ```typescript
275
+ import { Indexable } from '@typedly/data-traits';
276
+ ```
277
+
278
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/indexable.trait.ts)
279
+
280
+ ### `Measurable`
281
+
282
+ Interface for data types that can be measured in terms of size and memory usage, allowing for efficient management of resources and optimization of performance.
283
+
284
+ ```typescript
285
+ import { Measurable } from '@typedly/data-traits';
286
+ ```
287
+
288
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/measurable.trait.ts)
289
+
290
+ ### `Mergeable`
291
+
292
+ The interface for mergeable data types, which can be combined with other instances of the same type using a defined strategy.
293
+
294
+ ```typescript
295
+ import { Mergeable } from '@typedly/data-traits';
296
+ ```
297
+
298
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/mergeable.trait.ts)
299
+
300
+ ### `Observable`
301
+
302
+ The interface for observable data types, which allow subscribers to be notified of changes to their value.
303
+
304
+ ```typescript
305
+ import { Observable } from '@typedly/data-traits';
306
+ ```
307
+
308
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/observable.trait.ts)
309
+
310
+ ### `Paginated`
311
+
312
+ Trait for objects that support pagination.
313
+
314
+ ```typescript
315
+ import { Paginated } from '@typedly/data-traits';
316
+ ```
317
+
318
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/paginated.trait.ts)
319
+
320
+ ### `Persistable`
321
+
322
+ Trait for objects that can be persisted and restored.
323
+
324
+ ```typescript
325
+ import { Persistable } from '@typedly/data-traits';
326
+ ```
327
+
328
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/persistable.trait.ts)
329
+
330
+ ### `Printable`
331
+
332
+ Trait for objects that can be printed as a `string` or in a formatted way.
333
+
334
+ ```typescript
335
+ import { Printable } from '@typedly/data-traits';
336
+ ```
337
+
338
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/printable.trait.ts)
339
+
340
+ ### `Queryable`
341
+
342
+ Interfaces for data types that can be queried using a defined query format, allowing for flexible and efficient retrieval of information based on specific criteria.
343
+
344
+ ```typescript
345
+ import { Queryable } from '@typedly/data-traits';
346
+ ```
347
+
348
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/queryable.trait.ts)
349
+
350
+ ### `Resettable`
351
+
352
+ Interface for data types that can be reset to an initial value and track if they have been modified (dirty state).
353
+
354
+ ```typescript
355
+ import { Resettable } from '@typedly/data-traits';
356
+ ```
357
+
358
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/resettable.trait.ts)
359
+
360
+ ### `Revertible`
361
+
362
+ Trait for objects that can revert or undo changes.
363
+
364
+ ```typescript
365
+ import { Revertible } from '@typedly/data-traits';
366
+ ```
367
+
368
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/revertible.trait.ts)
369
+
370
+ ### `Serializable`
371
+
372
+ Serializable interface for data types that can be serialized and deserialized.
373
+
374
+ ```typescript
375
+ import { Serializable } from '@typedly/data-traits';
376
+ ```
377
+
378
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/serializable.trait.ts)
379
+
380
+ ### `Timestamped`
381
+
382
+ Interface representing timestamped data.
383
+
384
+ ```typescript
385
+ import { Timestamped } from '@typedly/data-traits';
386
+ ```
387
+
388
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/timestamped.trait.ts)
389
+
390
+ ### `Transformable`
391
+
392
+ Transformable interface for data types that can be transformed.
393
+
394
+ ```typescript
395
+ import { Transformable } from '@typedly/data-traits';
396
+ ```
397
+
398
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/transformable.trait.ts)
399
+
400
+ ### `Validatable`
401
+
402
+ Interface for data types that can be validated with custom rules and track validation errors.
403
+
404
+ ```typescript
405
+ import { Validatable } from '@typedly/data-traits';
406
+ ```
407
+
408
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/validatable.trait.ts)
409
+
410
+ ### `Versionable`
411
+
412
+ The interface for versionable data types, which maintain a history of changes and can revert to previous versions.
413
+
414
+ ```typescript
415
+ import { Versionable } from '@typedly/data-traits';
416
+ ```
417
+
418
+ [Source](https://github.com/typedly/data-traits/blob/main/src/lib/versionable.trait.ts)
419
+
420
+ ## Contributing
421
+
422
+ Your contributions are valued! If you'd like to contribute, please feel free to submit a pull request. Help is always appreciated.
423
+
424
+ ## Support
425
+
426
+ If you find this package useful and would like to support its and general development, you can contribute through one of the following payment methods. Your support helps maintain the packages and continue adding new.
427
+
428
+ Support via:
429
+
430
+ - [4Fund](https://4fund.com/bruubs)
431
+ - [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
432
+ - [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
433
+ - [Ko-fi](https://ko-fi.com/sterblack)
434
+ - [OpenCollective](https://opencollective.com/sterblack)
435
+ - [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
436
+ - [PayPal](https://paypal.me/sterblack)
437
+ - [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
438
+ - ~~[Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)~~
439
+
440
+ or via Trust Wallet
441
+
442
+ - [BNB](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
443
+ - [BTC](https://link.trustwallet.com/send?coin=0&address=bc1qnf709336tfl57ta5mfkf4t9fndhx7agxvv9svn)
444
+ - [ETH](https://link.trustwallet.com/send?coin=60&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94)
445
+ - [USDT (BEP20)](https://link.trustwallet.com/send?coin=20000714&address=0xA0c22A2bc7E37C1d5992dFDFFeD5E6f9298E1b94&token_id=0x55d398326f99059fF775485246999027B3197955)
446
+ - [XLM](https://link.trustwallet.com/send?coin=148&address=GAFFFB7H3LG42O6JA63FJDRK4PP4JCNEOPHLGLLFH625X2KFYQ4UYVM4)
447
+
448
+ Thanks for your support!
449
+
450
+ ## Code of Conduct
451
+
452
+ By participating in this project, you agree to follow **[Code of Conduct](https://www.contributor-covenant.org/version/2/1/code_of_conduct/)**.
453
+
454
+ ## GIT
455
+
456
+ ### Commit
457
+
458
+ - [AngularJS Git Commit Message Conventions][git-commit-angular]
459
+ - [Karma Git Commit Msg][git-commit-karma]
460
+ - [Conventional Commits][git-commit-conventional]
461
+
462
+ ### Versioning
463
+
464
+ [Semantic Versioning 2.0.0][git-semver]
465
+
466
+ **Given a version number MAJOR.MINOR.PATCH, increment the:**
467
+
468
+ - MAJOR version when you make incompatible API changes,
469
+ - MINOR version when you add functionality in a backwards-compatible manner, and
470
+ - PATCH version when you make backwards-compatible bug fixes.
471
+
472
+ Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
473
+
474
+ **FAQ**
475
+ How should I deal with revisions in the 0.y.z initial development phase?
476
+
477
+ > The simplest thing to do is start your initial development release at 0.1.0 and then increment the minor version for each subsequent release.
478
+
479
+ How do I know when to release 1.0.0?
480
+
481
+ > If your software is being used in production, it should probably already be 1.0.0. If you have a stable API on which users have come to depend, you should be 1.0.0. If you’re worrying a lot about backwards compatibility, you should probably already be 1.0.0.
482
+
483
+ ## License
484
+
485
+ MIT © typedly ([license][package-license])
486
+
487
+ ## Packages
488
+
489
+ - **[@typedly/array](https://github.com/typedly/array)**: A **TypeScript** type definitions package to handle array-related operations.
490
+ - **[@typedly/callback](https://github.com/typedly/callback)**: A **TypeScript** type definitions package for asynchronous and synchronous callback functions of various types.
491
+ - **[@typedly/character](https://github.com/typedly/character)**: A **TypeScript** type definitions package for various character types.
492
+ - **[@typedly/context](https://github.com/typedly/context)**: A **TypeScript** type definitions package for context data structures.
493
+ - **[@typedly/descriptor](https://github.com/typedly/descriptor)**: A **TypeScript** type definitions package for property descriptor.
494
+ - **[@typedly/digit](https://github.com/typedly/digit)**: A **TypeScript** type definitions package for digit types.
495
+ - **[@typedly/letter](https://github.com/typedly/letter)**: A **TypeScript** type definitions package for handling letter types.
496
+ - **[@typedly/object](https://github.com/typedly/object)**: A **TypeScript** type definitions package to handle object-related operations.
497
+ - **[@typedly/payload](https://github.com/typedly/payload)**: A **TypeScript** type definitions package for payload data structures.
498
+ - **[@typedly/property](https://github.com/typedly/property)**: A **TypeScript** type definitions package to handle object property-related operations.
499
+ - **[@typedly/regexp](https://github.com/typedly/regexp)**: A **TypeScript** type definitions package for `RegExp`.
500
+ - **[@typedly/symbol](https://github.com/typedly/symbol)**: A **TypeScript** type definitions package for various symbols.
501
+
502
+ <!-- Funding -->
503
+ [github-badge-sponsor]: https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&link=https://github.com/sponsors/angular-package
504
+ [github-sponsor-link]: https://github.com/sponsors/angular-package
505
+ [patreon-badge]: https://img.shields.io/endpoint.svg?url=https%3A%2F%2Fshieldsio-patreon.vercel.app%2Fapi%3Fusername%3Dangularpackage%26type%3Dpatrons&style=flat
506
+ [patreon-link]: https://www.patreon.com/join/angularpackage/checkout?fan_landing=true&rid=0
507
+
508
+ <!-- This package: typedly -->
509
+ <!-- GitHub: badges -->
510
+ [package-badge-issues]: https://img.shields.io/github/issues/typedly/data-traits
511
+ [package-badge-forks]: https://img.shields.io/github/forks/typedly/data-traits
512
+ [package-badge-stars]: https://img.shields.io/github/stars/typedly/data-traits
513
+ [package-badge-license]: https://img.shields.io/github/license/typedly/data-traits
514
+ <!-- GitHub: badges links -->
515
+ [package-issues]: https://github.com/typedly/data-traits/issues
516
+ [package-forks]: https://github.com/typedly/data-traits/network
517
+ [package-license]: https://github.com/typedly/data-traits/blob/master/LICENSE
518
+ [package-stars]: https://github.com/typedly/data-traits/stargazers
519
+ <!-- This package -->
520
+
521
+ <!-- Package: typedly -->
522
+ <!-- npm -->
523
+ [package-npm-badge-svg]: https://badge.fury.io/js/@typedly%2Fdata-traits.svg
524
+ [package-npm-badge]: https://badge.fury.io/js/@typedly%2Fdata-traits
525
+
526
+ <!-- GIT -->
527
+ [git-semver]: http://semver.org/
528
+
529
+ <!-- GIT: commit -->
530
+ [git-commit-angular]: https://gist.github.com/stephenparish/9941e89d80e2bc58a153
531
+ [git-commit-karma]: http://karma-runner.github.io/0.10/dev/git-commit-msg.html
532
+ [git-commit-conventional]: https://www.conventionalcommits.org/en/v1.0.0/
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@typedly/data-traits",
3
+ "version": "1.0.0",
4
+ "author": "wwwdev.io <dev@wwwdev.io>",
5
+ "description": "A TypeScript type definitions package for configurable data traits, providing various kinds of configurable data interfaces.",
6
+ "license": "MIT",
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "registry": "https://registry.npmjs.org"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/typedly/data-traits.git"
14
+ },
15
+ "bugs": {
16
+ "url": "https://github.com/typedly/data-traits/issues"
17
+ },
18
+ "keywords": [
19
+ "@typedly",
20
+ "@typedly/data",
21
+ "@typedly/data-traits",
22
+ "Data Traits",
23
+ "Configurable Data",
24
+ "Adaptable Data",
25
+ "Comparable Data",
26
+ "Encryptable Data",
27
+ "Resettable Data",
28
+ "Serializable Data",
29
+ "Timestamped Data",
30
+ "Transformable Data",
31
+ "Validatable Data"
32
+ ],
33
+ "funding": [
34
+ {
35
+ "type": "stripe",
36
+ "url": "https://donate.stripe.com/dR614hfDZcJE3wAcMM"
37
+ },
38
+ {
39
+ "type": "Donorbox",
40
+ "url": "https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=once&amount=1"
41
+ },
42
+ {
43
+ "type": "Open Collective",
44
+ "url": "https://opencollective.com/sterblack"
45
+ },
46
+ {
47
+ "type": "Ko-fi",
48
+ "url": "https://ko-fi.com/sterblack"
49
+ },
50
+ {
51
+ "type": "4Fund",
52
+ "url": "https://4fund.com/bruubs"
53
+ },
54
+ {
55
+ "type": "paypal",
56
+ "url": "https://paypal.me/sterblack"
57
+ },
58
+ {
59
+ "type": "individual",
60
+ "url": "https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29"
61
+ }
62
+ ],
63
+ "sideEffects": false,
64
+ "typings": "types/typedly-data-traits.d.ts",
65
+ "exports": {
66
+ "./package.json": {
67
+ "default": "./package.json"
68
+ },
69
+ ".": {
70
+ "types": "./types/typedly-data-traits.d.ts",
71
+ "default": "./fesm2022/typedly-data-traits.mjs"
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,760 @@
1
+ import { AsyncReturn } from '@typedly/data';
2
+
3
+ /**
4
+ * @description The interface for adaptable data types, which can optionally use a data adapter to manage their value and behavior.
5
+ * @export
6
+ * @interface Adaptable
7
+ * @template [A=unknown] The adapter type, which can be `undefined`, defaults to `unknown`.
8
+ */
9
+ interface Adaptable<A = unknown> {
10
+ /**
11
+ * @description The adapter of data instance, which can be `undefined` if no adapter is used.
12
+ * @readonly
13
+ * @type {?A}
14
+ */
15
+ readonly adapter?: A;
16
+ /**
17
+ * @description Checks if the data instance has an adapter.
18
+ * @returns {boolean} True if an adapter is present, false otherwise.
19
+ */
20
+ hasAdapter?(): boolean;
21
+ }
22
+
23
+ /**
24
+ * @description The interface for cacheable data types, which can be cached with an optional expiration time and invalidated or refreshed as needed.
25
+ * @export
26
+ * @interface Cacheable
27
+ * @template T The data type.
28
+ * @template {boolean} [R=false] Whether the cache operations are asynchronous.
29
+ */
30
+ interface Cacheable<T, R extends boolean = false> {
31
+ /**
32
+ * @description Cache expiration time in milliseconds.
33
+ */
34
+ cacheDuration?: number;
35
+ /**
36
+ * @description Invalidates the cache.
37
+ * @returns {AsyncReturn<R, void>}
38
+ */
39
+ invalidateCache(): AsyncReturn<R, void>;
40
+ /**
41
+ * @description Whether the data is currently cached.
42
+ * @returns {boolean} True if the data is cached, false otherwise.
43
+ */
44
+ isCached(): boolean;
45
+ /**
46
+ * @description Refreshes cached data.
47
+ * @returns {AsyncReturn<R, T>} The refreshed data, allowing for chaining.
48
+ */
49
+ refresh(): AsyncReturn<R, T>;
50
+ }
51
+
52
+ /**
53
+ * @description Capability for objects that can be cleaned or cleared.
54
+ * @export
55
+ * @interface Cleanable
56
+ * @template {boolean} [R=false] Whether the cleanup and clear methods return a `Promise` or not.
57
+ */
58
+ interface Cleanable<R extends boolean = false> {
59
+ /**
60
+ * @description Cleans up resources (event listeners, timers, subscriptions).
61
+ * @returns {AsyncReturn<R, void>}
62
+ */
63
+ cleanup?(): AsyncReturn<R, void>;
64
+ /**
65
+ * @description Clears the current value, resetting to empty/default state.
66
+ * Does not destroy the instance - it remains usable.
67
+ * @returns {AsyncReturn<R, this>}
68
+ */
69
+ clear(): AsyncReturn<R, this>;
70
+ /**
71
+ * @description Checks if the data is empty/cleared.
72
+ * @returns {boolean}
73
+ */
74
+ isEmpty(): boolean;
75
+ }
76
+
77
+ /**
78
+ * @description Capability for objects that can be cloned.
79
+ * @export
80
+ * @interface Cloneable
81
+ * @template T The options type for customizing the cloning behavior.
82
+ * @template {boolean} [R=false] Whether the clone method returns a `Promise` or not.
83
+ */
84
+ interface Cloneable<O, R extends boolean = false> {
85
+ /**
86
+ * @description Creates a deep copy of this instance.
87
+ * @returns {AsyncReturn<R, this>}
88
+ */
89
+ clone(): AsyncReturn<R, this>;
90
+ /**
91
+ * @description Creates a shallow copy of this instance.
92
+ * @returns {AsyncReturn<R, this>}
93
+ */
94
+ shallowClone?(): AsyncReturn<R, this>;
95
+ /**
96
+ * @description Creates a deep copy with custom cloning options.
97
+ * @param {O} options Cloning configuration.
98
+ * @returns {AsyncReturn<R, this>}
99
+ */
100
+ cloneWith?(options: O): AsyncReturn<R, this>;
101
+ }
102
+
103
+ /**
104
+ * @description Trait for collection-like data types that can hold multiple items and provide methods for adding, deleting, and iterating over those items.
105
+ * @export
106
+ * @interface Collection
107
+ * @template E Element type contained in the collection.
108
+ * @template {boolean} [R=false] whether the methods return a `Promise` or not.
109
+ */
110
+ interface Collection<E, R extends boolean = false> extends Iterable<E>, AsyncIterable<E> {
111
+ /**
112
+ * @description The number of items in the collection.
113
+ * @returns {number}
114
+ */
115
+ readonly size: number;
116
+ /**
117
+ * @description Adds elements to the collection.
118
+ * @param {...E[]} element Element of type `E` to add.
119
+ * @returns {AsyncReturn<R, this>} The collection instance `this`, or in `Promise`.
120
+ */
121
+ add(...element: E[]): AsyncReturn<R, this>;
122
+ /**
123
+ * @description Deletes elements from the collection.
124
+ * @param {...E[]} element Element of type `E` to delete.
125
+ * @returns {AsyncReturn<R, boolean>} `true` if every element was successfully deleted, otherwise `false`.
126
+ */
127
+ delete(...element: E[]): AsyncReturn<R, boolean>;
128
+ /**
129
+ * @description Executes a provided function once for each collection element.
130
+ * @param {(element: E, collection: Collection<E, R>) => void} callbackfn Function to execute for each element.
131
+ * @param {?*} [thisArg] Value to use as `this` when executing `callbackfn`.
132
+ * @returns {AsyncReturn<R, this>}
133
+ */
134
+ forEach(callbackfn: (element: E, collection: Collection<E, R>) => void, thisArg?: any): AsyncReturn<R, this>;
135
+ /**
136
+ * @description Checks if every item exists in the collection.
137
+ * @param {...E[]} element Element of type `E` to check for existence.
138
+ * @returns {AsyncReturn<R, boolean>} `true` if every element exists, otherwise `false`.
139
+ */
140
+ has(...element: E[]): AsyncReturn<R, boolean>;
141
+ /**
142
+ * @description Converts the collection to an array of elements.
143
+ * @returns {AsyncReturn<R, E[]>} The array of elements, or in `Promise` if `R` is `true`.
144
+ */
145
+ toArray?(): AsyncReturn<R, E[]>;
146
+ }
147
+
148
+ /**
149
+ * @description Comparable interface for data types that can be compared.
150
+ * @export
151
+ * @interface Comparable
152
+ * @template T The data type.
153
+ */
154
+ interface Comparable<T> {
155
+ /**
156
+ * @description Compares this data with another.
157
+ * @param {T} other
158
+ * @returns {number} -1 if less, 0 if equal, 1 if greater
159
+ */
160
+ compare(other: T): number;
161
+ /**
162
+ * @description Checks if this data equals another.
163
+ * @param {T} other
164
+ * @returns {boolean}
165
+ */
166
+ equals(other: T): boolean;
167
+ }
168
+
169
+ /**
170
+ * @description Interface for data types that can be compressed and decompressed, allowing for efficient storage and transmission of data.
171
+ * @export
172
+ * @interface Compressible
173
+ * @template T The data type.
174
+ * @template [C=Uint8Array] The type of the compressed data, defaulting to `Uint8Array`.
175
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
176
+ */
177
+ interface Compressible<T, C = Uint8Array, R extends boolean = false> {
178
+ /**
179
+ * @description Compresses the data.
180
+ * @returns {AsyncReturn<R, C>} The compressed data, allowing for chaining.
181
+ */
182
+ compress(): AsyncReturn<R, C>;
183
+ /**
184
+ * @description Decompresses data.
185
+ * @param {C} compressed The compressed data.
186
+ * @returns {AsyncReturn<R, T>} The decompressed data.
187
+ */
188
+ decompress(compressed: C): AsyncReturn<R, T>;
189
+ /**
190
+ * @description Gets compression ratio.
191
+ * @returns {number} Ratio (0-1)
192
+ */
193
+ getCompressionRatio(): number;
194
+ }
195
+
196
+ /**
197
+ * @description The interface for configurable data types, which can optionally have a configuration object.
198
+ * @export
199
+ * @interface Configurable
200
+ * @template [C=unknown] The type of the configuration object.
201
+ */
202
+ interface Configurable<C = unknown> {
203
+ /**
204
+ * @description The configuration of the `Data` instance.
205
+ * @readonly
206
+ * @type {?C}
207
+ */
208
+ readonly configuration?: C;
209
+ }
210
+
211
+ /**
212
+ * @description Interface for data types that can be encrypted and decrypted.
213
+ * @export
214
+ * @interface Encryptable
215
+ * @template T The data to be encrypted/decrypted.
216
+ * @template [O=string] The type of the encryption key, defaulting to `string`.
217
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
218
+ */
219
+ interface Encryptable<T, O = string, R extends boolean = false> {
220
+ /**
221
+ * @description Decrypts the data with the given key.
222
+ * @param {string} encrypted Encrypted data.
223
+ * @param {?O} options Decryption options, typically the decryption key.
224
+ * @returns {AsyncReturn<R, T>}
225
+ */
226
+ decrypt(encrypted: string, options?: O): AsyncReturn<R, T>;
227
+ /**
228
+ * @description Encrypts the data with the given key.
229
+ * @param {?O} options Encryption options, typically the encryption key.
230
+ * @returns {AsyncReturn<R, string>}
231
+ */
232
+ encrypt(options?: O): AsyncReturn<R, string>;
233
+ /**
234
+ * @description Whether the data is currently encrypted.
235
+ * @returns {boolean} True if the data is encrypted, false otherwise.
236
+ */
237
+ isEncrypted(): boolean;
238
+ }
239
+
240
+ /**
241
+ * @description The interface for exportable data types, which can be exported to various formats.
242
+ * @export
243
+ * @interface Exportable
244
+ * @template T The data type.
245
+ * @template {boolean} [R=false] Whether the export operations are asynchronous.
246
+ */
247
+ interface Exportable<F, R extends boolean = false> {
248
+ /**
249
+ * @description Exports to custom format.
250
+ * @param {F} format The format to export to.
251
+ * @returns {AsyncReturn<R, string>}
252
+ */
253
+ export(format: F): AsyncReturn<R, string>;
254
+ /**
255
+ * @description Exports to CSV (if applicable).
256
+ * @returns {AsyncReturn<R, string>}
257
+ */
258
+ toCSV?(): AsyncReturn<R, string>;
259
+ /**
260
+ * @description Exports to JSON.
261
+ * @returns {AsyncReturn<R, string>}
262
+ */
263
+ toJSON(): AsyncReturn<R, string>;
264
+ /**
265
+ * @description Exports to XML.
266
+ * @returns {AsyncReturn<R, string>}
267
+ */
268
+ toXML?(): AsyncReturn<R, string>;
269
+ }
270
+
271
+ /**
272
+ * @description The interface for freezable data types, which can be frozen to prevent modifications and optionally unfrozen.
273
+ * @export
274
+ * @interface Freezable
275
+ * @template [T=any] The data type that can be frozen, used for optional checks in `isFrozen`.
276
+ * @template {boolean} [R=false] Whether the freeze/unfreeze operations are asynchronous.
277
+ */
278
+ interface Freezable<T = any, R extends boolean = false> {
279
+ /**
280
+ * @description Freezes the data, preventing modifications.
281
+ * @returns {AsyncReturn<R, this>} The instance after freezing, allowing for chaining.
282
+ */
283
+ freeze(): AsyncReturn<R, this>;
284
+ /**
285
+ * @description Whether the data is frozen.
286
+ * @param {?T} o Optional data to check if frozen, if supported by implementation.
287
+ * @returns {boolean} True if the data is frozen, false otherwise.
288
+ */
289
+ isFrozen(o?: T): boolean;
290
+ /**
291
+ * @description Unfreezes the data.
292
+ * @returns {AsyncReturn<R, this>} The instance after unfreezing, allowing for chaining.
293
+ */
294
+ unfreeze?(): AsyncReturn<R, this>;
295
+ }
296
+
297
+ /**
298
+ * @description Trait for objects that have an ID or unique identifier.
299
+ * @export
300
+ * @interface Identifiable
301
+ * @template [ID=string] The type of the unique identifier.
302
+ */
303
+ interface Identifiable<ID = string> {
304
+ /**
305
+ * @description The unique identifier of the object.
306
+ * @readonly
307
+ * @type {ID}
308
+ */
309
+ readonly id?: ID;
310
+ /**
311
+ * @description The string tag of the data instance.
312
+ * @readonly
313
+ * @type {?string}
314
+ */
315
+ readonly [Symbol.toStringTag]?: string;
316
+ }
317
+
318
+ /**
319
+ * @description Trait for objects that support indexing or retrieving by numeric or string index.
320
+ * @export
321
+ * @interface Indexable
322
+ * @template [E=any] The type of the items in indexed collection.
323
+ * @template [I=number | string] The type of the index, typically number for arrays or `string` for objects.
324
+ * @template {boolean} [R=false]
325
+ */
326
+ interface Indexable<E = any, I = number | string, R extends boolean = false> {
327
+ /**
328
+ * @description Number of items.
329
+ * @readonly
330
+ * @type {number}
331
+ */
332
+ readonly length: number;
333
+ /**
334
+ * @description Retrieves an item by its index.
335
+ * @param {I} index The index of the item.
336
+ * @returns {AsyncReturn<R, E | undefined>} The item at the specified index.
337
+ */
338
+ get(index: I): AsyncReturn<R, E | undefined>;
339
+ /**
340
+ * @description Checks if an item exists at the specified index.
341
+ * @param {I} index The index to check.
342
+ * @returns {AsyncReturn<R, boolean>} True if an item exists at the index, false otherwise.
343
+ */
344
+ has(index: I): AsyncReturn<R, boolean>;
345
+ /**
346
+ * @description Retrieves all items as an array.
347
+ * @returns {AsyncReturn<R, E[]>} An array of all items.
348
+ */
349
+ getAll(): AsyncReturn<R, E[]>;
350
+ /**
351
+ * @description Retrieves all indices as an array.
352
+ * @returns {AsyncReturn<R, I[]> } An array of all indices.
353
+ */
354
+ getIndices(): AsyncReturn<R, I[]>;
355
+ /**
356
+ * @description Retrieves all items along with their indices as an array of [index, item] pairs.
357
+ * @returns {AsyncReturn<R, Array<[I, E]>>} An array of [index, item] pairs.
358
+ */
359
+ entries(): AsyncReturn<R, Array<[I, E]>>;
360
+ /**
361
+ * @description Sets the value at the specified index.
362
+ * @param {I} index The index to set the value at.
363
+ * @param {E} value The value to set.
364
+ * @return {AsyncReturn<R, this>} The instance of the object after setting the value.
365
+ */
366
+ set(index: I, value: E): AsyncReturn<R, this>;
367
+ /**
368
+ * @description Deletes the value at the specified index.
369
+ * @param {I} index The index to delete the value from.
370
+ */
371
+ delete(index: I): AsyncReturn<R, this>;
372
+ /**
373
+ * @description Deletes the value at the specified indices.
374
+ * @param {...I[]} index The indices to delete the values from.
375
+ * @returns {AsyncReturn<R, this>} The instance of the object after deleting the values.
376
+ */
377
+ delete(...index: I[]): AsyncReturn<R, this>;
378
+ }
379
+
380
+ /**
381
+ * @description Interface for data types that can be measured in terms of size and memory usage, allowing for efficient management of resources and optimization of performance.
382
+ * @export
383
+ * @interface Measurable
384
+ */
385
+ interface Measurable {
386
+ /**
387
+ * @description Checks if data exceeds size limit.
388
+ * @param {number} limit Size limit in bytes.
389
+ * @returns {boolean}
390
+ */
391
+ exceedsLimit(limit: number): boolean;
392
+ /**
393
+ * @description Gets memory usage.
394
+ * @returns {number} Bytes
395
+ */
396
+ getMemoryUsage(): number;
397
+ /**
398
+ * @description Gets the size in bytes.
399
+ * @returns {number}
400
+ */
401
+ getSize(): number;
402
+ }
403
+
404
+ /**
405
+ * @description The interface for mergeable data types, which can be combined with other instances of the same type using a defined strategy.
406
+ * @export
407
+ * @interface Mergeable
408
+ * @template T The data type.
409
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
410
+ */
411
+ interface Mergeable<T, R extends boolean = false> {
412
+ /**
413
+ * @description Checks if can merge with another instance.
414
+ * @param {T} other The other data instance to check.
415
+ * @returns {boolean} Whether the instances can be merged.
416
+ */
417
+ canMerge(other: T): boolean;
418
+ /**
419
+ * @description Merges with another data instance.
420
+ * @param {T} other The other data instance to merge with.
421
+ * @param {(a: T, b: T) => T} strategy - Merge strategy
422
+ * @returns {AsyncReturn<R, this>}
423
+ */
424
+ merge(other: T, strategy?: (a: T, b: T) => T): AsyncReturn<R, this>;
425
+ }
426
+
427
+ /**
428
+ * @description The interface for observable data types, which allow subscribers to be notified of changes to their value.
429
+ * @export
430
+ * @interface Observable
431
+ * @template T The type of the value being observed.
432
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
433
+ * @template {L} [L=(value: T, previous?: T) => AsyncReturn<R, void>] The type of the listener function, defaulting to a function that takes the new value and optionally the previous value.
434
+ */
435
+ interface Observable<T, R extends boolean = false, L = (value: T, previous?: T) => AsyncReturn<R, void>> {
436
+ /**
437
+ * @description Notifies all subscribers of current value.
438
+ * @param {T} [value] The new value to notify subscribers with, if supported by implementation. If not provided, may notify with current value or simply trigger listeners.
439
+ * @returns {AsyncReturn<R, void>} Resolves when all subscribers have been notified, if asynchronous. Otherwise, returns `void`.
440
+ */
441
+ notify(value?: T): AsyncReturn<R, void>;
442
+ /**
443
+ * @description Subscribes to value changes.
444
+ * @param {L} listener Called when value changes
445
+ * @returns {() => void} Unsubscribe function
446
+ */
447
+ subscribe(listener: L): () => void;
448
+ /**
449
+ * @description Unsubscribes a specific listener.
450
+ * @param {L} listener The listener to remove.
451
+ */
452
+ unsubscribe(listener: L): void;
453
+ /**
454
+ * @description Removes all subscribers.
455
+ */
456
+ unsubscribeAll(): void;
457
+ }
458
+
459
+ /**
460
+ * @description Trait for objects that support pagination.
461
+ * @export
462
+ * @interface Paginated
463
+ * @template [T=unknown] The type of items in the paginated collection.
464
+ */
465
+ interface Paginated<T = unknown> {
466
+ /**
467
+ * @description Total number of pages.
468
+ * @readonly
469
+ * @type {number}
470
+ */
471
+ readonly pageCount: number;
472
+ /**
473
+ * @description Current page index, starting from 0.
474
+ * @readonly
475
+ * @type {number}
476
+ */
477
+ readonly pageIndex: number;
478
+ /**
479
+ * @description Number of items per page.
480
+ * @readonly
481
+ * @type {number}
482
+ */
483
+ readonly pageSize: number;
484
+ /**
485
+ * @description Returns the current page of items.
486
+ * @returns {T[]}
487
+ */
488
+ getPage(): T[];
489
+ /**
490
+ * @description Advances to the next page and returns its items.
491
+ * @returns {T[]}
492
+ */
493
+ nextPage(): T[];
494
+ /**
495
+ * @description Goes back to the previous page and returns its items.
496
+ * @returns {T[]}
497
+ */
498
+ previousPage(): T[];
499
+ }
500
+
501
+ /**
502
+ * @description Trait for objects that can be persisted and restored.
503
+ * @export
504
+ * @interface Persistable
505
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
506
+ */
507
+ interface Persistable<R extends boolean = false> {
508
+ /**
509
+ * @description Deletes the persisted data.
510
+ * @returns {AsyncReturn<R, this>}
511
+ */
512
+ delete(): AsyncReturn<R, this>;
513
+ /**
514
+ * @description Restores the object from storage or database.
515
+ * @returns {AsyncReturn<R, this>}
516
+ */
517
+ load(): AsyncReturn<R, this>;
518
+ /**
519
+ * @description Persists the object, e.g. to storage or database.
520
+ * @returns {AsyncReturn<R, this>}
521
+ */
522
+ save(): AsyncReturn<R, this>;
523
+ }
524
+
525
+ /**
526
+ * @description Trait for objects that can be printed as a string or in a formatted way.
527
+ * @export
528
+ * @interface Printable
529
+ */
530
+ interface Printable {
531
+ /**
532
+ * @description Prints the object to a string.
533
+ * @returns {string}
534
+ */
535
+ print(): string;
536
+ /**
537
+ * @description Optionally, pretty-prints the object.
538
+ * @returns {string}
539
+ */
540
+ prettyPrint?(): string;
541
+ }
542
+
543
+ /**
544
+ * @description Interfaces for data types that can be queried using a defined query format, allowing for flexible and efficient retrieval of information based on specific criteria.
545
+ * @export
546
+ * @interface Queryable
547
+ * @template T The data type.
548
+ * @template Q The query format (JSON query, GraphQL, predicate, etc.)
549
+ * @template {boolean} [R=false] Whether the operations are asynchronous, defaulting to `false`.
550
+ */
551
+ interface Queryable<T, Q, R extends boolean = false> {
552
+ /**
553
+ * @description Counts items matching the query.
554
+ * @param {Q} query The query object, structure depends on implementation.
555
+ * @returns {AsyncReturn<R, number>} The count of items matching the query.
556
+ */
557
+ count?(query: Q): AsyncReturn<R, number>;
558
+ /**
559
+ * @description Filters the data (if collection-like).
560
+ * @param {(item: T) => boolean} predicate - The predicate function to filter items.
561
+ * @returns {AsyncReturn<R, T[]>} The filtered results.
562
+ */
563
+ filter?(predicate: (item: T) => boolean): AsyncReturn<R, T[]>;
564
+ /**
565
+ * @description Finds a single item that matches the query.
566
+ * @param {Q} query The query object, structure depends on implementation.
567
+ * @returns {AsyncReturn<R, T | null>} The found item or `null` if not found.
568
+ */
569
+ findOne?(query: Q): AsyncReturn<R, T | null>;
570
+ /**
571
+ * @description Queries the data.
572
+ * @param {Q} query - The query object, structure depends on implementation.
573
+ * @returns {AsyncReturn<R, T[]>} The query results.
574
+ */
575
+ query(query: Q): AsyncReturn<R, T[]>;
576
+ }
577
+
578
+ /**
579
+ * @description Interface for data types that can be reset to an initial value and track if they have been modified (dirty state).
580
+ * @export
581
+ * @interface Resettable
582
+ * @template T The type of the value that can be reset.
583
+ * @template {boolean} [R=false] Whether the reset operation is asynchronous.
584
+ */
585
+ interface Resettable<T, R extends boolean = false> {
586
+ /**
587
+ * @description Gets the initial value.
588
+ * @returns {T} The initial value.
589
+ */
590
+ getInitialValue(): T;
591
+ /**
592
+ * @description Checks if data has been modified from initial state.
593
+ * @returns {boolean} True if modified (dirty), false if unchanged (clean).
594
+ */
595
+ isDirty(): boolean;
596
+ /**
597
+ * @description Resets to initial value.
598
+ * @returns {AsyncReturn<R, this>} The instance after reset, allowing for chaining.
599
+ */
600
+ reset(): AsyncReturn<R, this>;
601
+ }
602
+
603
+ /**
604
+ * @description Trait for objects that can revert or undo changes.
605
+ * @export
606
+ * @interface Revertible
607
+ * @template V The type of the version.
608
+ * @template {boolean} [R=false] Whether the revert operations are asynchronous.
609
+ */
610
+ interface Revertible<V = unknown, R extends boolean = false> {
611
+ /**
612
+ * @description Checks if the object can be reverted.
613
+ * @returns {boolean} True if revert is possible, false otherwise.
614
+ */
615
+ canRevert(): boolean;
616
+ /**
617
+ * @description Reverts the object to its previous state.
618
+ * @param {V} [version] The version to revert to. If not provided, reverts to the most recent previous version.
619
+ * @returns {AsyncReturn<R, this>} The reverted instance.
620
+ */
621
+ revert(version?: V): AsyncReturn<R, this>;
622
+ }
623
+
624
+ /**
625
+ * @description Serializable interface for data types that can be serialized and deserialized.
626
+ * @export
627
+ * @interface Serializable
628
+ * @template T The type of the value to be serialized and deserialized.
629
+ * @template {boolean} [R=false] The async flag, indicating whether the serialization and deserialization methods are asynchronous.
630
+ */
631
+ interface Serializable<T, R extends boolean = false> {
632
+ /**
633
+ * @description Serializes the data instance to a string.
634
+ * @returns {AsyncReturn<R, string>}
635
+ */
636
+ serialize(): AsyncReturn<R, string>;
637
+ /**
638
+ * @description Deserializes a string to a data instance.
639
+ * @param {string} data The string to be deserialized.
640
+ * @returns {AsyncReturn<R, T>}
641
+ */
642
+ deserialize(data: string): AsyncReturn<R, T>;
643
+ }
644
+
645
+ /**
646
+ * @description Interface representing timestamped data.
647
+ * @export
648
+ * @interface Timestamped
649
+ */
650
+ interface Timestamped {
651
+ /**
652
+ * @description When the data was created.
653
+ * @readonly
654
+ */
655
+ readonly createdAt: Date;
656
+ /**
657
+ * @description When the data was last modified.
658
+ * @readonly
659
+ */
660
+ readonly updatedAt: Date;
661
+ /**
662
+ * @description When the data was last accessed.
663
+ * @readonly
664
+ */
665
+ readonly accessedAt?: Date;
666
+ }
667
+
668
+ /**
669
+ * @description Transformable interface for data types that can be transformed.
670
+ * @export
671
+ * @interface Transformable
672
+ * @template T The type of the value to be transformed.
673
+ * @template {boolean} [R=false] The async flag, indicating whether the transformation methods are asynchronous.
674
+ */
675
+ interface Transformable<T, R extends boolean = false> {
676
+ /**
677
+ * @description Chains transformations with async support.
678
+ * @template U The transformed value type.
679
+ * @param {(value: T) => AsyncReturn<R, U>} fn Async transformation function.
680
+ * @returns {AsyncReturn<R, U>} The transformed value.
681
+ */
682
+ flatMap?<U>(fn: (value: T) => AsyncReturn<R, U>): AsyncReturn<R, U>;
683
+ /**
684
+ * @description Transforms the `Data` instance using the provided function.
685
+ * @template U The transformed value type.
686
+ * @param {(value: T) => U} fn The function to transform the `Data` instance.
687
+ * @returns {AsyncReturn<R, U>} The transformed `Data` instance.
688
+ */
689
+ map<U>(fn: (value: T) => U): AsyncReturn<R, U>;
690
+ }
691
+
692
+ /**
693
+ * @description Interface for data types that can be validated with custom rules and track validation errors.
694
+ * @export
695
+ * @interface Validatable
696
+ * @template T The data type.
697
+ * @template {boolean} [R=false] Whether the validation operations are asynchronous.
698
+ */
699
+ interface Validatable<T, R extends boolean = false> {
700
+ /**
701
+ * @description Gets validation errors if any.
702
+ * @returns {string[]} Array of error messages
703
+ */
704
+ getErrors(): string[];
705
+ /**
706
+ * @description Checks if the current value is valid without throwing.
707
+ * @returns {boolean} True if valid, false otherwise.
708
+ */
709
+ isValid(): boolean;
710
+ /**
711
+ * @description Sets a custom validator function.
712
+ * @param {(value: T) => boolean} validator The validator function to set.
713
+ * @returns {AsyncReturn<R, this>} The instance after setting the validator, allowing for chaining.
714
+ */
715
+ setValidator(validator: (value: T) => boolean): AsyncReturn<R, this>;
716
+ /**
717
+ * @description Validates the current value against defined rules.
718
+ * @returns {AsyncReturn<R, boolean>} True if valid, false otherwise.
719
+ */
720
+ validate(): AsyncReturn<R, boolean>;
721
+ }
722
+
723
+ /**
724
+ * @description The interface for versionable data types, which maintain a history of changes and can revert to previous versions.
725
+ * @export
726
+ * @interface Versionable
727
+ * @template T The data type.
728
+ * @template [V=unknown] The type of the version.
729
+ * @template {boolean} [R=false] Whether the versioning operations are asynchronous.
730
+ * @extends {Revertible<V, R>}
731
+ */
732
+ interface Versionable<T, V = unknown, R extends boolean = false> extends Revertible<V, R> {
733
+ /**
734
+ * @description Current version number.
735
+ * @readonly
736
+ */
737
+ readonly version: V;
738
+ /**
739
+ * @description Gets version history.
740
+ * @returns {Array<{version: V, value: T, timestamp: Date}>}
741
+ */
742
+ getHistory(): Array<{
743
+ version: V;
744
+ value: T;
745
+ timestamp: Date;
746
+ }>;
747
+ /**
748
+ * @description Reverts to a previous version.
749
+ * @param {V} version
750
+ * @returns {AsyncReturn<R, this>}
751
+ */
752
+ revert(version: V): AsyncReturn<R, this>;
753
+ /**
754
+ * @description Creates a snapshot of current state.
755
+ * @returns {AsyncReturn<R, T>}
756
+ */
757
+ snapshot(): AsyncReturn<R, T>;
758
+ }
759
+
760
+ export type { Adaptable, Cacheable, Cleanable, Cloneable, Collection, Comparable, Compressible, Configurable, Encryptable, Exportable, Freezable, Identifiable, Indexable, Measurable, Mergeable, Observable, Paginated, Persistable, Printable, Queryable, Resettable, Revertible, Serializable, Timestamped, Transformable, Validatable, Versionable };