@typedly/data 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -103,7 +103,7 @@ export class ProfileData<
103
103
  Value extends { age: number, name: string }
104
104
  > implements DataShape<Value> {
105
105
 
106
- get value(): Value {
106
+ public get value(): Value {
107
107
  return {
108
108
  age: this.#age,
109
109
  name: this.#name
@@ -118,13 +118,12 @@ export class ProfileData<
118
118
  this.#name = value.name;
119
119
  }
120
120
 
121
- set(value: Value): this { this.validate(value); return this; }
122
- clear(): this { return this; }
123
- destroy(): this { return this; }
124
- lock(): this { return this; };
125
- validate(value: Value): boolean {
126
- return true;
127
- }
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; }
128
127
  }
129
128
 
130
129
  // Create `ProfileClass` with customizable data.
@@ -167,10 +166,16 @@ frankProfile.age; // 37
167
166
  frankProfile.name; // Frank
168
167
 
169
168
  // Set the data.
170
- frankProfile.data.set({ age: 37, name: 'Frank' });
169
+ frankProfile.data.setValue({ age: 37, name: 'Frank' });
171
170
  frankProfile.data.clear();
172
171
  frankProfile.data.lock();
173
172
  frankProfile.data.value;
173
+
174
+ // Initialize with arguments.
175
+ const markProfile = new ProfileClass(
176
+ { age: 27, name: 'Mark' },
177
+ [ProfileData, 'private', true]
178
+ );
174
179
  ```
175
180
 
176
181
  [Source](https://github.com/typedly/data/blob/main/src/lib/interface/data-constructor.interface.ts)
@@ -182,13 +187,17 @@ The shape of a `Data` type.
182
187
  ```typescript
183
188
  import { DataShape } from '@typedly/data';
184
189
 
185
- class TestData implements DataShape<number> {
186
- get value(): number { return this.initialValue; }
187
- constructor(private initialValue: number) {}
188
- public clear(): this { return this; }
189
- public destroy(): this { return this; }
190
- public lock(): this { return this; }
191
- public set(value: number): this { return this; }
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
+ }
192
201
  }
193
202
  ```
194
203
 
@@ -309,7 +318,10 @@ export class ProfileDataOfValue<
309
318
  this.#value = new valueCtor(value, ...args);
310
319
  }
311
320
 
312
- set(value: Value): this { this.validate(value); return this; }
321
+ setValue(value: Value): this { this.validate(value); return this; }
322
+ getValue(): Value {
323
+ return this.#value.value;
324
+ }
313
325
  clear(): this { return this; }
314
326
  destroy(): this { return this; }
315
327
  lock(): this { return this; };
@@ -383,10 +395,11 @@ If you find this package useful and would like to support its and general develo
383
395
  Support via:
384
396
 
385
397
  - [Stripe](https://donate.stripe.com/dR614hfDZcJE3wAcMM)
386
- - [Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)
398
+ - ~~[Revolut](https://checkout.revolut.com/pay/048b10a3-0e10-42c8-a917-e3e9cb4c8e29)~~
387
399
  - [GitHub](https://github.com/sponsors/angular-package/sponsorships?sponsor=sciborrudnicki&tier_id=83618)
388
400
  - [DonorBox](https://donorbox.org/become-a-sponsor-to-the-angular-package?default_interval=o)
389
401
  - [Patreon](https://www.patreon.com/checkout/angularpackage?rid=0&fan_landing=true&view_as=public)
402
+ - [4Fund](https://4fund.com/bruubs)
390
403
 
391
404
  or via Trust Wallet
392
405
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typedly/data",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "author": "wwwdev.io <dev@wwwdev.io>",
5
5
  "description": "A TypeScript type definitions package for @typescript-package/data.",
6
6
  "license": "MIT",
@@ -44,8 +44,9 @@ interface DataShape<T, Async extends boolean = false> {
44
44
  value: T;
45
45
  clear(): AsyncReturn<Async, this>;
46
46
  destroy(): AsyncReturn<Async, this>;
47
+ getValue(): AsyncReturn<Async, T>;
47
48
  lock(): this;
48
- set(value: T): AsyncReturn<Async, this>;
49
+ setValue(value: T): AsyncReturn<Async, this>;
49
50
  [Symbol.toStringTag]?: string;
50
51
  [Symbol.iterator]?(): IterableIterator<IterValue<T>>;
51
52
  [Symbol.asyncIterator]?(): AsyncIterableIterator<IterValue<T>>;