@warp-drive/schema-record 5.8.0-beta.0 → 5.8.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 CHANGED
@@ -23,9 +23,9 @@
23
23
  - ⚛️ Universal
24
24
  - ☢️ Reactive
25
25
 
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. The shape of the object and the transformation of raw cache data into its reactive form is controlled by a resource schema. Resource schemas are simple JSON, allowing them to be defined and delivered from anywhere.
26
+ SchemaRecord is a reactive object that transforms raw data from an [associated cache](https://github.com/warp-drive-data/warp-drive/blob/main/packages/core-types/src/cache.ts) into reactive data backed by Signals. The shape of the object and the transformation of raw cache data into its reactive form is controlled by a resource schema. Resource schemas are simple JSON, allowing them to be defined and delivered from anywhere.
27
27
 
28
- The capabilities that SchemaRecord brings to [*Warp***Drive**](https://github.com/emberjs/data/) will simplify even the most complex parts of your app's state management.
28
+ The capabilities that SchemaRecord brings to [*Warp***Drive**](https://github.com/warp-drive-data/warp-drive/) will simplify even the most complex parts of your app's state management.
29
29
 
30
30
  ## Installation
31
31
 
@@ -48,8 +48,8 @@ pnpm add @warp-drive/schema-record
48
48
  ## Getting Started
49
49
 
50
50
  If this package is how you are first learning about WarpDrive/EmberData, we
51
- recommend starting with learning about [Requests](https://github.com/emberjs/data/blob/main/packages/request/README.md)
52
- and the [Store](https://github.com/emberjs/data/blob/main/packages/store/README.md).
51
+ recommend starting with learning about [Requests](https://github.com/warp-drive-data/warp-drive/blob/main/packages/request/README.md)
52
+ and the [Store](https://github.com/warp-drive-data/warp-drive/blob/main/packages/store/README.md).
53
53
 
54
54
  ## 🚀 Setup
55
55
 
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@warp-drive/schema-record",
3
- "version": "5.8.0-beta.0",
3
+ "version": "5.8.0-beta.1",
4
4
  "description": "Schema Driven Resource Presentation for WarpDrive and EmberData",
5
5
  "keywords": [
6
6
  "ember-addon"
7
7
  ],
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+ssh://git@github.com:emberjs/data.git",
10
+ "url": "git+ssh://git@github.com:warp-drive-data/warp-drive.git",
11
11
  "directory": "packages/schema-record"
12
12
  },
13
13
  "license": "MIT",
@@ -1,342 +1,8 @@
1
1
  /// <reference path="./-private.d.ts" />
2
2
  declare module '@warp-drive/schema-record' {
3
3
  /**
4
- * <h3 align="center">Your Data, Managed.</h3>
5
- * <p align="center">🌲 Get back to Nature 🐿️ Or shipping 💚</p>
6
- *
7
- * SchemaRecord is a reactive object that transforms raw data from an {@link Cache | associated cache}
8
- * into reactive data backed by Signals. The shape of the object and the transformation of raw cache data into its
9
- * reactive form is controlled by a resource schema. Resource schemas are simple JSON, allowing them to be defined
10
- * and delivered from anywhere.
11
- *
12
- * The capabilities that SchemaRecord brings to [*Warp***Drive**](https://github.com/emberjs/data/)
13
- * will simplify even the most complex parts of your app's state management.
14
- *
15
- * ## Installation
16
- *
17
- * Install using your javascript package manager of choice. For instance
18
- * with [pnpm](https://pnpm.io/)
19
- *
20
- * ```sh
21
- * pnpm add @warp-drive/schema-record
22
- * ```
23
- *
24
- *
25
- * ---
26
- *
27
- *
28
- * ## Getting Started
29
- *
30
- * If this package is how you are first learning about WarpDrive/EmberData, we
31
- * recommend starting with learning about [Requests](../modules/@ember-data%2Frequest)
32
- * and the [Store](../modules/@ember-data%2Fstore).
33
- *
34
- *
35
- * ---
36
- *
37
- *
38
- * ## 🚀 Setup
39
- *
40
- * SchemaRecord integrates with WarpDrive via the Store's resource lifecycle hooks.
41
- * When WarpDrive needs to create a new record instance to give reactive access to
42
- * a resource in the cache, it calls `instantiateRecord`. When it no longer needs
43
- * that instance, it will call `teardownRecord`.
44
- *
45
- * ```diff
46
- * import Store from '@ember-data/store';
47
- * +import { instantiateRecord, teardownRecord, registerDerivations, SchemaService } from '@warp-drive/schema-record';
48
- *
49
- * class AppStore extends Store {
50
- *
51
- * + createSchemaService() {
52
- * + const schema = new SchemaService();
53
- * + registerDerivations(schema);
54
- * + return schema;
55
- * + }
56
- *
57
- * + instantiateRecord(identifier, createArgs) {
58
- * + return instantiateRecord(this, identifier, createArgs);
59
- * + }
60
- *
61
- * + teardownRecord(record) {
62
- * + return teardownRecord(record);
63
- * + }
64
- * }
65
- * ```
66
- *
67
- * Any Store API that returns a record instance will use the `instantiateRecord`
68
- * hook configured above to instantiate a SchemaRecord once this is in place.
69
- * After that, its up to you what SchemaRecord can do.
70
- *
71
- *
72
- * ---
73
- *
74
- *
75
- * ## Start Using
76
- *
77
- * ### Modes
78
- *
79
- * SchemaRecord has two modes: `legacy` and `polaris`.
80
- *
81
- * **LegacyMode** can be used to emulate the behaviors and capabilities of EmberData's `Model` class,
82
- * and because there is little distinction between Model and SchemaRecord in LegacyMode we refer
83
- * to both of these approaches as LegacyMode. This mode is the default experience in V5.
84
- *
85
- * In LegacyMode:
86
- *
87
- * - records are mutable
88
- * - local changes immediately reflect app wide
89
- * - records have all the APIs of Model (references, state props, currentState, methods etc)
90
- * - the continued use of `@ember-data/model` and `@ember-data/legacy-compat` packages is required (though most imports from them can be removed)
91
- * - `async: true` relationships are supported (but not recommended outside of [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
92
- *
93
- * ---
94
- *
95
- * **PolarisMode** is an upcoming suite of features that will become the default experience in V6.
96
- *
97
- * In PolarisMode:
98
- *
99
- * - records are immutable, unless creating a new resource or explicitly checking out a record for editing
100
- * - local changes are isolated until committed, displaying only via the editable version of the record
101
- * - records have a more limited API, focused on only what is in their schema.
102
- * - some common operations may have more friction to perform because intended utilities are not yet available
103
- * - `async: true` relationships are not supported (see [LinksMode](https://github.com/emberjs/data/blob/main/guides/relationships/features/links-mode.md))
104
- * - `@ember-data/model` and `@ember-data/legacy-compat` packages are not required
105
- *
106
- * These modes are interopable. The reactive object (record) for a resource in PolarisMode can relate to
107
- * a record in LegacyMode and vice-versa. This interopability is true whether the record in LegacyMode is
108
- * a SchemaRecord or a Model.
109
- *
110
- * ---
111
- *
112
- * ### About
113
- *
114
- * SchemaRecord is a reactive object that transforms raw data from an associated
115
- * cache into reactive data backed by Signals.
116
- *
117
- * The shape of the object and the transformation of raw cache data into its
118
- * reactive form is controlled by a resource schema.
119
- *
120
- * For instance, lets say your API is a [{JSON:API}](https://jsonapi.org) and your store is using
121
- * the Cache provided by [@ember-data/json-api](../modules/@ember-data%2Fjson-api), and a request
122
- * returns the following raw data:
123
- *
124
- * ```ts
125
- * {
126
- * data: {
127
- * type: 'user',
128
- * id: '1',
129
- * attributes: { firstName: 'Chris', lastName: 'Thoburn' },
130
- * relationships: { pets: { data: [{ type: 'dog', id: '1' }] }}
131
- * },
132
- * included: [
133
- * {
134
- * type: 'dog',
135
- * id: '1',
136
- * attributes: { name: 'Rey' },
137
- * relationships: { owner: { data: { type: 'user', id: '1' }}}
138
- * }
139
- * ]
140
- * }
141
- * ```
142
- *
143
- * We could describe the `'user'` and `'dog'` resources in the above payload
144
- * with the following schemas:
145
- *
146
- * ```ts
147
- * store.schema.registerResources([
148
- * {
149
- * type: 'user',
150
- * identity: { type: '@id', name: 'id' },
151
- * fields: [
152
- * {
153
- * type: '@identity',
154
- * name: '$type',
155
- * kind: 'derived',
156
- * options: { key: 'type' },
157
- * },
158
- * { kind: 'field', name: 'firstName' },
159
- * { kind: 'field', name: 'lastName' },
160
- * {
161
- * kind: 'derived',
162
- * name: 'name',
163
- * type: 'concat',
164
- * options: { fields: ['firstName', 'lastName'], separator: ' ' }
165
- * },
166
- * {
167
- * kind: 'hasMany',
168
- * name: 'pets',
169
- * type: 'pet',
170
- * options: {
171
- * async: false,
172
- * inverse: 'owner',
173
- * polymorphic: true,
174
- * linksMode: true,
175
- * }
176
- * }
177
- * ]
178
- * },
179
- * {
180
- * type: 'dog',
181
- * identity: { type: '@id', name: 'id' },
182
- * fields: [
183
- * {
184
- * type: '@identity',
185
- * name: '$type',
186
- * kind: 'derived',
187
- * options: { key: 'type' },
188
- * },
189
- * { kind: 'field', name: 'name' },
190
- * {
191
- * kind: 'belongsTo',
192
- * name: 'owner',
193
- * type: 'user',
194
- * options: {
195
- * async: false,
196
- * inverse: 'pets',
197
- * as: 'pet',
198
- * linksMode: true,
199
- * }
200
- * }
201
- * ]
202
- * }
203
- * ]);
204
- * ```
205
- *
206
- * With these schemas in place, the reactive objects that the store would
207
- * provide us whenever we encountered a `'user'` or a `'dog'` would be:
208
- *
209
- * ```ts
210
- *
211
- * interface Pet {
212
- * readonly id: string;
213
- * readonly owner: User;
214
- * }
215
- *
216
- * interface Dog extends Pet {
217
- * readonly $type: 'dog';
218
- * readonly name: string;
219
- * }
220
- *
221
- * interface EditableUser {
222
- * readonly $type: 'user';
223
- * readonly id: string;
224
- * firstName: string;
225
- * lastName: string;
226
- * readonly name: string;
227
- * pets: Array<Dog | Pet>;
228
- * }
229
- *
230
- * interface User {
231
- * readonly $type: 'user';
232
- * readonly id: string;
233
- * readonly firstName: string;
234
- * readonly lastName: string;
235
- * readonly name: string;
236
- * readonly pets: Readonly<Array<Dog | Pet>>;
237
- * [Checkout](): Promise<EditableUser>
238
- * }>
239
- * ```
240
- *
241
- * Note how based on the schema the reactive object we receive is able to produce
242
- * `name` on user (despite no name field being in the cache), provide `$type`
243
- * pulled from the identity of the resource, and flatten the individual attributes
244
- * and relationships onto the record for easier use.
245
- *
246
- * Notice also how we typed this object with `readonly`. This is because while
247
- * SchemaRecord instances are ***deeply reactive***, they are also ***immutable***.
248
- *
249
- * We can mutate a SchemaRecord only be explicitly asking permission to do so, and
250
- * in the process gaining access to an editable copy. The immutable version will
251
- * not show any in-process edits made to this editable copy.
252
- *
253
- * ```ts
254
- * import { Checkout } from '@warp-drive/schema-record';
255
- *
256
- * const editable = await user[Checkout]();
257
- * ```
258
- *
259
- * ---
260
- *
261
- * ### Utilities
262
- *
263
- * SchemaRecord provides a schema builder that simplifies setting up a couple of
264
- * conventional fields like identity and `$type`. We can rewrite the schema
265
- * definition above using this utility like so:
266
- *
267
- * ```ts
268
- * import { withDefaults } from '@warp-drive/schema-record';
269
- *
270
- * store.schema.registerResources([
271
- * withDefaults({
272
- * type: 'user',
273
- * fields: [
274
- * { kind: 'field', name: 'firstName' },
275
- * { kind: 'field', name: 'lastName' },
276
- * {
277
- * kind: 'derived',
278
- * name: 'name',
279
- * type: 'concat',
280
- * options: { fields: ['firstName', 'lastName'], separator: ' ' }
281
- * },
282
- * {
283
- * kind: 'hasMany',
284
- * name: 'pets',
285
- * type: 'pet',
286
- * options: {
287
- * async: false,
288
- * inverse: 'owner',
289
- * polymorphic: true,
290
- * linksMode: true,
291
- * resetOnRemoteUpdate: false,
292
- * }
293
- * }
294
- * ]
295
- * }),
296
- * withDefaults({
297
- * type: 'dog',
298
- * fields: [
299
- * { kind: 'field', name: 'name' },
300
- * {
301
- * kind: 'belongsTo',
302
- * name: 'owner',
303
- * type: 'user',
304
- * options: {
305
- * async: false,
306
- * inverse: 'pets',
307
- * as: 'pet',
308
- * linksMode: true,
309
- * resetOnRemoteUpdate: false,
310
- * }
311
- * }
312
- * ]
313
- * })
314
- * ]);
315
- * ```
316
- *
317
- * Additionally, `@warp-drive/core-types` provides several utilities for type-checking and narrowing schemas.
318
- *
319
- * - {@link PolarisResourceSchema}
320
- * - {@link LegacyResourceSchema}
321
- * - {@link ObjectSchema}
322
- * - {@link resourceSchema}
323
- * - {@link objectSchema}
324
- * - {@link isResourceSchema}
325
- * - {@link isLegacyResourceSchema}
326
- *
327
- * ---
328
- *
329
- * ### Field Schemas
330
- *
331
- * LegacyMode
332
- *
333
- * - {@link LegacyModeFieldSchema}
334
-
335
- * PolarisMode
336
- *
337
- * - {@link PolarisModeFieldSchema}
338
- *
339
4
  * @module
5
+ * @mergeModuleWith <project>
340
6
  */
341
7
  export { instantiateRecord, teardownRecord, type Transformation, SchemaService, withDefaults, fromIdentity, registerDerivations, type ReactiveResource as SchemaRecord, Checkout } from "@warp-drive/core/reactive";
342
8