@warp-drive/schema-record 5.4.0-alpha.150 → 5.4.0-alpha.151
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 +30 -16
- package/dist/index.js +54 -3
- package/dist/index.js.map +1 -1
- package/package.json +15 -15
- package/unstable-preview-types/-private/schema.d.ts +46 -0
- package/unstable-preview-types/-private/schema.d.ts.map +1 -1
- package/unstable-preview-types/index.d.ts +337 -0
- package/unstable-preview-types/index.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
<p align="center">
|
|
2
2
|
<img
|
|
3
3
|
class="project-logo"
|
|
4
|
-
src="./logos/
|
|
5
|
-
alt="WarpDrive"
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
src="./logos/github-header.svg#gh-light-mode-only"
|
|
5
|
+
alt="WarpDrive | Boldly go where no app has gone before"
|
|
6
|
+
title="WarpDrive | Boldly go where no app has gone before"
|
|
7
|
+
/>
|
|
8
8
|
<img
|
|
9
9
|
class="project-logo"
|
|
10
|
-
src="./logos/
|
|
11
|
-
alt="WarpDrive"
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
src="./logos/github-header.svg#gh-dark-mode-only"
|
|
11
|
+
alt="WarpDrive | Boldly go where no app has gone before"
|
|
12
|
+
title="WarpDrive | Boldly go where no app has gone before"
|
|
13
|
+
/>
|
|
14
14
|
</p>
|
|
15
15
|
|
|
16
16
|
<h3 align="center">Your Data, Managed.</h3>
|
|
17
17
|
<p align="center">🌲 Get back to Nature 🐿️ Or shipping 💚</p>
|
|
18
18
|
|
|
19
|
-
SchemaRecord is:
|
|
20
|
-
|
|
21
19
|
- ⚡️ Fast
|
|
22
20
|
- 📦 Tiny
|
|
23
21
|
- ✨ Optimized
|
|
@@ -25,11 +23,15 @@ SchemaRecord is:
|
|
|
25
23
|
- ⚛️ Universal
|
|
26
24
|
- ☢️ Reactive
|
|
27
25
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
26
|
+
SchemaRecord is a reactive object that transforms raw data from an [associated cache](https://github.com/emberjs/data/blob/main/packages/core-types/src/cache.ts) into reactive data backed by Signals.
|
|
27
|
+
|
|
28
|
+
The shape of the object and the transformation of raw cache data into its
|
|
29
|
+
reactive form is controlled by a resource schema.
|
|
30
|
+
|
|
31
|
+
Resource schemas are simple JSON, allowing them to be defined and delivered from anywhere.
|
|
32
|
+
|
|
33
|
+
The capabilities that SchemaRecord brings to [*Warp***Drive**](https://github.com/emberjs/data/)
|
|
34
|
+
will simplify even the most complex parts of your app's state management.
|
|
33
35
|
|
|
34
36
|
## Installation
|
|
35
37
|
|
|
@@ -150,7 +152,8 @@ store.registerSchemas([
|
|
|
150
152
|
options: {
|
|
151
153
|
async: false,
|
|
152
154
|
inverse: 'owner',
|
|
153
|
-
polymorphic: true
|
|
155
|
+
polymorphic: true,
|
|
156
|
+
linksMode: true,
|
|
154
157
|
}
|
|
155
158
|
}
|
|
156
159
|
]
|
|
@@ -174,6 +177,7 @@ store.registerSchemas([
|
|
|
174
177
|
async: false,
|
|
175
178
|
inverse: 'pets',
|
|
176
179
|
as: 'pet',
|
|
180
|
+
linksMode: true,
|
|
177
181
|
}
|
|
178
182
|
}
|
|
179
183
|
]
|
|
@@ -286,6 +290,16 @@ store.registerSchemas([
|
|
|
286
290
|
]);
|
|
287
291
|
```
|
|
288
292
|
|
|
293
|
+
Additionally, `@warp-drive/core-types` provides several utilities for type-checking and narrowing schemas.
|
|
294
|
+
|
|
295
|
+
- (type) [PolarisResourceSchema]()
|
|
296
|
+
- (type) [LegacyResourceSchema]()
|
|
297
|
+
- (type) [ObjectSchema]()
|
|
298
|
+
- [resourceSchema]()
|
|
299
|
+
- [objectSchema]()
|
|
300
|
+
- [isResourceSchema]()
|
|
301
|
+
- [isLegacyResourceSchema]()
|
|
302
|
+
|
|
289
303
|
|
|
290
304
|
### Field Schemas
|
|
291
305
|
|
package/dist/index.js
CHANGED
|
@@ -1418,6 +1418,10 @@ function teardownRecord(record) {
|
|
|
1418
1418
|
assertSchemaRecord(record);
|
|
1419
1419
|
record[Destroy]();
|
|
1420
1420
|
}
|
|
1421
|
+
|
|
1422
|
+
/**
|
|
1423
|
+
* @module @warp-drive/schema-record
|
|
1424
|
+
*/
|
|
1421
1425
|
const Support = getOrSetGlobal('Support', new WeakMap());
|
|
1422
1426
|
const ConstructorField = {
|
|
1423
1427
|
type: '@constructor',
|
|
@@ -1459,6 +1463,13 @@ _constructor[Type] = '@constructor';
|
|
|
1459
1463
|
/**
|
|
1460
1464
|
* Utility for constructing a ResourceSchema with the recommended fields
|
|
1461
1465
|
* for the Polaris experience.
|
|
1466
|
+
*
|
|
1467
|
+
* @method withDefaults
|
|
1468
|
+
* @for @warp-drive/schema-record
|
|
1469
|
+
* @static
|
|
1470
|
+
* @public
|
|
1471
|
+
* @param schema
|
|
1472
|
+
* @return {ResourceSchema}
|
|
1462
1473
|
*/
|
|
1463
1474
|
function withDefaults(schema) {
|
|
1464
1475
|
schema.identity = schema.identity || DefaultIdentityField;
|
|
@@ -1470,6 +1481,32 @@ function withDefaults(schema) {
|
|
|
1470
1481
|
schema.fields.push(ConstructorField);
|
|
1471
1482
|
return schema;
|
|
1472
1483
|
}
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
* A derivation that computes its value from the
|
|
1487
|
+
* record's identity.
|
|
1488
|
+
*
|
|
1489
|
+
* It can be used via a derived field definition like:
|
|
1490
|
+
*
|
|
1491
|
+
* ```ts
|
|
1492
|
+
* {
|
|
1493
|
+
* kind: 'derived',
|
|
1494
|
+
* name: 'id',
|
|
1495
|
+
* type: '@identity',
|
|
1496
|
+
* options: { key: 'id' }
|
|
1497
|
+
* }
|
|
1498
|
+
* ```
|
|
1499
|
+
*
|
|
1500
|
+
* Valid keys are `'id'`, `'lid'`, `'type'`, and `'^'`.
|
|
1501
|
+
*
|
|
1502
|
+
* `^` returns the entire identifier object.
|
|
1503
|
+
*
|
|
1504
|
+
* @method fromIdentity
|
|
1505
|
+
* @for @warp-drive/schema-record
|
|
1506
|
+
* @static
|
|
1507
|
+
* @public
|
|
1508
|
+
*/
|
|
1509
|
+
|
|
1473
1510
|
function fromIdentity(record, options, key) {
|
|
1474
1511
|
const identifier = record[Identifier];
|
|
1475
1512
|
macroCondition(getGlobalConfig().WarpDrive.env.DEBUG) ? (test => {
|
|
@@ -1485,6 +1522,16 @@ function fromIdentity(record, options, key) {
|
|
|
1485
1522
|
return options.key === '^' ? identifier : identifier[options.key];
|
|
1486
1523
|
}
|
|
1487
1524
|
fromIdentity[Type] = '@identity';
|
|
1525
|
+
|
|
1526
|
+
/**
|
|
1527
|
+
* Registers the default derivations for the SchemaRecord
|
|
1528
|
+
*
|
|
1529
|
+
* @method registerDerivations
|
|
1530
|
+
* @for @warp-drive/schema-record
|
|
1531
|
+
* @static
|
|
1532
|
+
* @public
|
|
1533
|
+
* @param {SchemaService} schema
|
|
1534
|
+
*/
|
|
1488
1535
|
function registerDerivations(schema) {
|
|
1489
1536
|
schema.registerDerivation(fromIdentity);
|
|
1490
1537
|
schema.registerDerivation(_constructor);
|
|
@@ -1493,9 +1540,7 @@ function registerDerivations(schema) {
|
|
|
1493
1540
|
* Wraps a derivation in a new function with Derivation signature but that looks
|
|
1494
1541
|
* up the value in the cache before recomputing.
|
|
1495
1542
|
*
|
|
1496
|
-
* @
|
|
1497
|
-
* @param options
|
|
1498
|
-
* @param prop
|
|
1543
|
+
* @internal
|
|
1499
1544
|
*/
|
|
1500
1545
|
function makeCachedDerivation(derivation) {
|
|
1501
1546
|
const memoizedDerivation = (record, options, prop) => {
|
|
@@ -1512,6 +1557,12 @@ function makeCachedDerivation(derivation) {
|
|
|
1512
1557
|
memoizedDerivation[Type] = derivation[Type];
|
|
1513
1558
|
return memoizedDerivation;
|
|
1514
1559
|
}
|
|
1560
|
+
/**
|
|
1561
|
+
* A SchemaService designed to work with dynamically registered schemas.
|
|
1562
|
+
*
|
|
1563
|
+
* @class SchemaService
|
|
1564
|
+
* @public
|
|
1565
|
+
*/
|
|
1515
1566
|
class SchemaService {
|
|
1516
1567
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1517
1568
|
|