@ember-data/model 5.5.0-alpha.9 → 5.5.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.md +19 -7
- package/README.md +21 -2
- package/addon-main.cjs +5 -0
- package/blueprints/model/index.js +18 -5
- package/blueprints/model-test/index.js +16 -10
- package/blueprints/model-test/qunit-files/__root__/__path__/__test__.js +4 -5
- package/dist/-private.js +3 -0
- package/{addon → dist}/-private.js.map +1 -1
- package/dist/has-many-BXU96bZ9.js +682 -0
- package/dist/has-many-BXU96bZ9.js.map +1 -0
- package/dist/hooks-o1U_cEA3.js +75 -0
- package/dist/hooks-o1U_cEA3.js.map +1 -0
- package/dist/hooks.js +2 -0
- package/{addon → dist}/hooks.js.map +1 -1
- package/dist/index.js +5 -0
- package/{addon → dist}/index.js.map +1 -1
- package/dist/migration-support.js +388 -0
- package/dist/migration-support.js.map +1 -0
- package/{addon/model-5a9ec6a9.js → dist/model-Dkk-TZlL.js} +2566 -2433
- package/dist/model-Dkk-TZlL.js.map +1 -0
- package/dist/schema-provider-DyG6fJXt.js +259 -0
- package/dist/schema-provider-DyG6fJXt.js.map +1 -0
- package/logos/NCC-1701-a-blue.svg +4 -0
- package/logos/NCC-1701-a-gold.svg +4 -0
- package/logos/NCC-1701-a-gold_100.svg +1 -0
- package/logos/NCC-1701-a-gold_base-64.txt +1 -0
- package/logos/NCC-1701-a.svg +4 -0
- package/logos/README.md +4 -0
- package/logos/docs-badge.svg +2 -0
- package/logos/ember-data-logo-dark.svg +12 -0
- package/logos/ember-data-logo-light.svg +12 -0
- package/logos/github-header.svg +444 -0
- package/logos/social1.png +0 -0
- package/logos/social2.png +0 -0
- package/logos/warp-drive-logo-dark.svg +4 -0
- package/logos/warp-drive-logo-gold.svg +4 -0
- package/package.json +62 -58
- package/unstable-preview-types/-private/attr.d.ts +175 -0
- package/unstable-preview-types/-private/attr.d.ts.map +1 -0
- package/unstable-preview-types/-private/attr.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/attr.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/belongs-to.d.ts +181 -0
- package/unstable-preview-types/-private/belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +8 -0
- package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +1 -0
- package/unstable-preview-types/-private/errors.d.ts +303 -0
- package/unstable-preview-types/-private/errors.d.ts.map +1 -0
- package/unstable-preview-types/-private/has-many.d.ts +169 -0
- package/unstable-preview-types/-private/has-many.d.ts.map +1 -0
- package/unstable-preview-types/-private/has-many.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/has-many.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/hooks.d.ts +13 -0
- package/unstable-preview-types/-private/hooks.d.ts.map +1 -0
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts +60 -0
- package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +1 -0
- package/unstable-preview-types/-private/model-for-mixin.d.ts +6 -0
- package/unstable-preview-types/-private/model-for-mixin.d.ts.map +1 -0
- package/unstable-preview-types/-private/model-methods.d.ts +37 -0
- package/unstable-preview-types/-private/model-methods.d.ts.map +1 -0
- package/unstable-preview-types/-private/model.d.ts +1303 -0
- package/unstable-preview-types/-private/model.d.ts.map +1 -0
- package/unstable-preview-types/-private/model.type-test.d.ts +4 -0
- package/unstable-preview-types/-private/model.type-test.d.ts.map +1 -0
- package/unstable-preview-types/-private/notify-changes.d.ts +8 -0
- package/unstable-preview-types/-private/notify-changes.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-belongs-to.d.ts +46 -0
- package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-many-array.d.ts +136 -0
- package/unstable-preview-types/-private/promise-many-array.d.ts.map +1 -0
- package/unstable-preview-types/-private/promise-proxy-base.d.ts +5 -0
- package/unstable-preview-types/-private/promise-proxy-base.d.ts.map +1 -0
- package/unstable-preview-types/-private/record-state.d.ts +80 -0
- package/unstable-preview-types/-private/record-state.d.ts.map +1 -0
- package/unstable-preview-types/-private/references/belongs-to.d.ts +506 -0
- package/unstable-preview-types/-private/references/belongs-to.d.ts.map +1 -0
- package/unstable-preview-types/-private/references/has-many.d.ts +518 -0
- package/unstable-preview-types/-private/references/has-many.d.ts.map +1 -0
- package/unstable-preview-types/-private/schema-provider.d.ts +65 -0
- package/unstable-preview-types/-private/schema-provider.d.ts.map +1 -0
- package/unstable-preview-types/-private/type-utils.d.ts +64 -0
- package/unstable-preview-types/-private/type-utils.d.ts.map +1 -0
- package/unstable-preview-types/-private/util.d.ts +8 -0
- package/unstable-preview-types/-private/util.d.ts.map +1 -0
- package/unstable-preview-types/-private.d.ts +13 -0
- package/unstable-preview-types/-private.d.ts.map +1 -0
- package/unstable-preview-types/hooks.d.ts +5 -0
- package/unstable-preview-types/hooks.d.ts.map +1 -0
- package/unstable-preview-types/index.d.ts +77 -0
- package/unstable-preview-types/index.d.ts.map +1 -0
- package/unstable-preview-types/migration-support.d.ts +271 -0
- package/unstable-preview-types/migration-support.d.ts.map +1 -0
- package/unstable-preview-types/migration-support.type-test.d.ts +4 -0
- package/unstable-preview-types/migration-support.type-test.d.ts.map +1 -0
- package/addon/-private.js +0 -2
- package/addon/has-many-76406f33.js +0 -321
- package/addon/has-many-76406f33.js.map +0 -1
- package/addon/hooks-dde806e1.js +0 -157
- package/addon/hooks-dde806e1.js.map +0 -1
- package/addon/hooks.js +0 -1
- package/addon/index.js +0 -3
- package/addon/model-5a9ec6a9.js.map +0 -1
- package/addon-main.js +0 -93
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare module '@ember-data/model/-private' {
|
|
2
|
+
export { attr } from '@ember-data/model/-private/attr';
|
|
3
|
+
export { belongsTo } from '@ember-data/model/-private/belongs-to';
|
|
4
|
+
export { hasMany } from '@ember-data/model/-private/has-many';
|
|
5
|
+
export { Model } from '@ember-data/model/-private/model';
|
|
6
|
+
export type { ModelStore } from '@ember-data/model/-private/model';
|
|
7
|
+
export { Errors } from '@ember-data/model/-private/errors';
|
|
8
|
+
export { RelatedCollection as ManyArray } from '@ember-data/store/-private';
|
|
9
|
+
export { PromiseBelongsTo } from '@ember-data/model/-private/promise-belongs-to';
|
|
10
|
+
export { PromiseManyArray } from '@ember-data/model/-private/promise-many-array';
|
|
11
|
+
export { lookupLegacySupport, LEGACY_SUPPORT } from '@ember-data/model/-private/legacy-relationships-support';
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=-private.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"-private.d.ts","sourceRoot":"","sources":["../src/-private.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,iBAAiB,IAAI,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAGjE,OAAO,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,yCAAyC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/// <reference path="./hooks.d.ts" />
|
|
2
|
+
/// <reference path="./migration-support.d.ts" />
|
|
3
|
+
/// <reference path="./-private.d.ts" />
|
|
4
|
+
/// <reference path="./migration-support.type-test.d.ts" />
|
|
5
|
+
/// <reference path="./-private/util.d.ts" />
|
|
6
|
+
/// <reference path="./-private/legacy-relationships-support.d.ts" />
|
|
7
|
+
/// <reference path="./-private/hooks.d.ts" />
|
|
8
|
+
/// <reference path="./-private/model.type-test.d.ts" />
|
|
9
|
+
/// <reference path="./-private/record-state.d.ts" />
|
|
10
|
+
/// <reference path="./-private/has-many.type-test.d.ts" />
|
|
11
|
+
/// <reference path="./-private/promise-many-array.d.ts" />
|
|
12
|
+
/// <reference path="./-private/has-many.d.ts" />
|
|
13
|
+
/// <reference path="./-private/belongs-to.type-test.d.ts" />
|
|
14
|
+
/// <reference path="./-private/attr.d.ts" />
|
|
15
|
+
/// <reference path="./-private/attr.type-test.d.ts" />
|
|
16
|
+
/// <reference path="./-private/promise-belongs-to.d.ts" />
|
|
17
|
+
/// <reference path="./-private/model.d.ts" />
|
|
18
|
+
/// <reference path="./-private/model-methods.d.ts" />
|
|
19
|
+
/// <reference path="./-private/belongs-to.d.ts" />
|
|
20
|
+
/// <reference path="./-private/type-utils.d.ts" />
|
|
21
|
+
/// <reference path="./-private/errors.d.ts" />
|
|
22
|
+
/// <reference path="./-private/model-for-mixin.d.ts" />
|
|
23
|
+
/// <reference path="./-private/notify-changes.d.ts" />
|
|
24
|
+
/// <reference path="./-private/promise-proxy-base.d.ts" />
|
|
25
|
+
/// <reference path="./-private/schema-provider.d.ts" />
|
|
26
|
+
/// <reference path="./-private/references/has-many.d.ts" />
|
|
27
|
+
/// <reference path="./-private/references/belongs-to.d.ts" />
|
|
28
|
+
/// <reference path="./-private/debug/assert-polymorphic-type.d.ts" />
|
|
29
|
+
declare module '@ember-data/model' {
|
|
30
|
+
/**
|
|
31
|
+
* This package provides a Presentation Model for resource data in an EmberData Cache.
|
|
32
|
+
*
|
|
33
|
+
* Models are defined as classes extending from `import Model from '@ember-data/model';` and the
|
|
34
|
+
* attributes and relationships on these classes are parsed at runtime to supply static "schema"
|
|
35
|
+
* to EmberData's SchemaService.
|
|
36
|
+
*
|
|
37
|
+
* Resource data for individual resources fetched from your API is presented to the UI via instances
|
|
38
|
+
* of the `Model`s you define. An instantiated `Model` is referred to as a `record`.
|
|
39
|
+
|
|
40
|
+
When we refer to the `ModelClass` as opposed to a `Model` or `Record` we are referring
|
|
41
|
+
specifically to the class definition and the static schema methods present on it.
|
|
42
|
+
|
|
43
|
+
When we refer to a `record` we refer to a specific class instance presenting
|
|
44
|
+
the resource data for a given `type` and `id`.
|
|
45
|
+
|
|
46
|
+
### Defining a Model
|
|
47
|
+
|
|
48
|
+
```app/models/person.js
|
|
49
|
+
import Model, { attr, belongsTo, hasMany } from '@ember-data/model';
|
|
50
|
+
|
|
51
|
+
export default class PersonModel extends Model {
|
|
52
|
+
@attr name;
|
|
53
|
+
|
|
54
|
+
@belongsTo('pet', { inverse: 'owners', async: false }) dog;
|
|
55
|
+
|
|
56
|
+
@hasMany('person', { inverse: 'friends', async: true }) friends;
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### modelName convention
|
|
61
|
+
|
|
62
|
+
By convention, the name of a given model (its `type`) matches the name
|
|
63
|
+
of the file in the `app/models` folder and should be lowercase, singular
|
|
64
|
+
and dasherized.
|
|
65
|
+
|
|
66
|
+
@module @ember-data/model
|
|
67
|
+
@main @ember-data/model
|
|
68
|
+
*/
|
|
69
|
+
export { Model as default, attr, belongsTo, hasMany } from '@ember-data/model/-private';
|
|
70
|
+
export type { PromiseBelongsTo as AsyncBelongsTo } from '@ember-data/model/-private/promise-belongs-to';
|
|
71
|
+
export type { PromiseManyArray as AsyncHasMany } from '@ember-data/model/-private/promise-many-array';
|
|
72
|
+
export type { RelatedCollection as ManyArray } from '@ember-data/store/-private';
|
|
73
|
+
export type { RelatedCollection as HasMany } from '@ember-data/store/-private';
|
|
74
|
+
export { instantiateRecord, teardownRecord, modelFor } from '@ember-data/model/-private/hooks';
|
|
75
|
+
export { ModelSchemaProvider } from '@ember-data/model/-private/schema-provider';
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,OAAO,EAAE,KAAK,IAAI,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAExE,YAAY,EAAE,gBAAgB,IAAI,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACxF,YAAY,EAAE,gBAAgB,IAAI,YAAY,EAAE,MAAM,+BAA+B,CAAC;AACtF,YAAY,EAAE,iBAAiB,IAAI,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACjF,YAAY,EAAE,iBAAiB,IAAI,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
declare module '@ember-data/model/migration-support' {
|
|
2
|
+
/**
|
|
3
|
+
* This module provides support for migrating away from @ember-data/model
|
|
4
|
+
* to @warp-drive/schema-record.
|
|
5
|
+
*
|
|
6
|
+
* It includes:
|
|
7
|
+
*
|
|
8
|
+
* - A `withDefaults` function to assist in creating a schema in LegacyMode
|
|
9
|
+
* - A `registerDerivations` function to register the derivations necessary to support LegacyMode
|
|
10
|
+
* - A `DelegatingSchemaService` that can be used to provide a schema service that works with both
|
|
11
|
+
* @ember-data/model and @warp-drive/schema-record simultaneously for migration purposes.
|
|
12
|
+
* - A `WithLegacy` type util that can be used to create a type that includes the legacy
|
|
13
|
+
* properties and methods of a record.
|
|
14
|
+
*
|
|
15
|
+
* Using LegacyMode features on a SchemaRecord *requires* the use of these derivations and schema
|
|
16
|
+
* additions. LegacyMode is not intended to be a long-term solution, but rather a stepping stone
|
|
17
|
+
* to assist in more rapidly adopting modern WarpDrive features.
|
|
18
|
+
*
|
|
19
|
+
* @module @ember-data/model/migration-support
|
|
20
|
+
* @main @ember-data/model/migration-support
|
|
21
|
+
*/
|
|
22
|
+
import type { Snapshot } from '@ember-data/legacy-compat/-private';
|
|
23
|
+
import type Store from '@ember-data/store';
|
|
24
|
+
import type { SchemaService } from '@ember-data/store/types';
|
|
25
|
+
import type { StableRecordIdentifier } from '@warp-drive/core-types';
|
|
26
|
+
import type { ChangedAttributesHash } from '@warp-drive/core-types/cache';
|
|
27
|
+
import type { ObjectValue } from '@warp-drive/core-types/json/raw';
|
|
28
|
+
import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
|
|
29
|
+
import type { Derivation, HashFn, Transformation } from '@warp-drive/core-types/schema/concepts';
|
|
30
|
+
import type { ArrayField, DerivedField, FieldSchema, GenericField, HashField, LegacyResourceSchema, ObjectField, ObjectSchema, ResourceSchema } from '@warp-drive/core-types/schema/fields';
|
|
31
|
+
import type { WithPartial } from '@warp-drive/core-types/utils';
|
|
32
|
+
import type { MinimalLegacyRecord } from '@ember-data/model/-private/model-methods';
|
|
33
|
+
import { belongsTo, hasMany } from '@ember-data/model/-private/model-methods';
|
|
34
|
+
import RecordState from '@ember-data/model/-private/record-state';
|
|
35
|
+
import type BelongsToReference from '@ember-data/model/-private/references/belongs-to';
|
|
36
|
+
import type HasManyReference from '@ember-data/model/-private/references/has-many';
|
|
37
|
+
import type { _MaybeBelongsToFields, MaybeHasManyFields } from '@ember-data/model/-private/type-utils';
|
|
38
|
+
export type WithLegacyDerivations<T extends TypedRecordInstance> = T & MinimalLegacyRecord & {
|
|
39
|
+
belongsTo: typeof belongsTo;
|
|
40
|
+
hasMany: typeof hasMany;
|
|
41
|
+
};
|
|
42
|
+
type AttributesSchema = ReturnType<Exclude<SchemaService['attributesDefinitionFor'], undefined>>;
|
|
43
|
+
type RelationshipsSchema = ReturnType<Exclude<SchemaService['relationshipsDefinitionFor'], undefined>>;
|
|
44
|
+
interface LegacyModeRecord<T extends TypedRecordInstance> {
|
|
45
|
+
id: string | null;
|
|
46
|
+
serialize(options?: Record<string, unknown>): unknown;
|
|
47
|
+
destroyRecord(options?: Record<string, unknown>): Promise<this>;
|
|
48
|
+
unloadRecord(): void;
|
|
49
|
+
changedAttributes(): ChangedAttributesHash;
|
|
50
|
+
rollbackAttributes(): void;
|
|
51
|
+
_createSnapshot(): Snapshot<T>;
|
|
52
|
+
save(options?: Record<string, unknown>): Promise<this>;
|
|
53
|
+
reload(options?: Record<string, unknown>): Promise<T>;
|
|
54
|
+
belongsTo<K extends _MaybeBelongsToFields<T>>(prop: K): BelongsToReference<T, K>;
|
|
55
|
+
hasMany<K extends MaybeHasManyFields<T>>(prop: K): HasManyReference<T, K>;
|
|
56
|
+
deleteRecord(): void;
|
|
57
|
+
adapterError: unknown;
|
|
58
|
+
constructor: {
|
|
59
|
+
modelName: TypeFromInstance<T>;
|
|
60
|
+
};
|
|
61
|
+
currentState: RecordState;
|
|
62
|
+
dirtyType: 'deleted' | 'created' | 'updated' | '';
|
|
63
|
+
errors: unknown;
|
|
64
|
+
hasDirtyAttributes: boolean;
|
|
65
|
+
isDeleted: boolean;
|
|
66
|
+
isEmpty: boolean;
|
|
67
|
+
isError: boolean;
|
|
68
|
+
isLoaded: boolean;
|
|
69
|
+
isLoading: boolean;
|
|
70
|
+
isDestroying: boolean;
|
|
71
|
+
isDestroyed: boolean;
|
|
72
|
+
isNew: boolean;
|
|
73
|
+
isSaving: boolean;
|
|
74
|
+
isValid: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A Type utility that enables quickly adding type information for the fields
|
|
78
|
+
* defined by `import { withDefaults } from '@ember-data/model/migration-support'`.
|
|
79
|
+
*
|
|
80
|
+
* Example:
|
|
81
|
+
*
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { withDefaults, WithLegacy } from '@ember-data/model/migration-support';
|
|
84
|
+
* import { Type } from '@warp-drive/core-types/symbols';
|
|
85
|
+
* import type { HasMany } from '@ember-data/model';
|
|
86
|
+
*
|
|
87
|
+
* export const UserSchema = withDefaults({
|
|
88
|
+
* type: 'user',
|
|
89
|
+
* fields: [
|
|
90
|
+
* { name: 'firstName', kind: 'attribute' },
|
|
91
|
+
* { name: 'lastName', kind: 'attribute' },
|
|
92
|
+
* { name: 'age', kind: 'attribute' },
|
|
93
|
+
* { name: 'friends',
|
|
94
|
+
* kind: 'hasMany',
|
|
95
|
+
* type: 'user',
|
|
96
|
+
* options: { inverse: 'friends', async: false }
|
|
97
|
+
* },
|
|
98
|
+
* { name: 'bestFriend',
|
|
99
|
+
* kind: 'belongsTo',
|
|
100
|
+
* type: 'user',
|
|
101
|
+
* options: { inverse: null, async: false }
|
|
102
|
+
* },
|
|
103
|
+
* ],
|
|
104
|
+
* });
|
|
105
|
+
*
|
|
106
|
+
* export type User = WithLegacy<{
|
|
107
|
+
* firstName: string;
|
|
108
|
+
* lastName: string;
|
|
109
|
+
* age: number;
|
|
110
|
+
* friends: HasMany<User>;
|
|
111
|
+
* bestFriend: User | null;
|
|
112
|
+
* [Type]: 'user';
|
|
113
|
+
* }>
|
|
114
|
+
* ```
|
|
115
|
+
*
|
|
116
|
+
* @typedoc
|
|
117
|
+
*/
|
|
118
|
+
export type WithLegacy<T extends TypedRecordInstance> = T & LegacyModeRecord<T>;
|
|
119
|
+
/**
|
|
120
|
+
* A function which adds the necessary fields to a schema and marks it as
|
|
121
|
+
* being in LegacyMode. This is used to support the legacy features of
|
|
122
|
+
* @ember-data/model while migrating to WarpDrive.
|
|
123
|
+
*
|
|
124
|
+
* Example:
|
|
125
|
+
*
|
|
126
|
+
* ```ts
|
|
127
|
+
* import { withDefaults, WithLegacy } from '@ember-data/model/migration-support';
|
|
128
|
+
* import { Type } from '@warp-drive/core-types/symbols';
|
|
129
|
+
* import type { HasMany } from '@ember-data/model';
|
|
130
|
+
*
|
|
131
|
+
* export const UserSchema = withDefaults({
|
|
132
|
+
* type: 'user',
|
|
133
|
+
* fields: [
|
|
134
|
+
* { name: 'firstName', kind: 'attribute' },
|
|
135
|
+
* { name: 'lastName', kind: 'attribute' },
|
|
136
|
+
* { name: 'age', kind: 'attribute' },
|
|
137
|
+
* { name: 'friends',
|
|
138
|
+
* kind: 'hasMany',
|
|
139
|
+
* type: 'user',
|
|
140
|
+
* options: { inverse: 'friends', async: false }
|
|
141
|
+
* },
|
|
142
|
+
* { name: 'bestFriend',
|
|
143
|
+
* kind: 'belongsTo',
|
|
144
|
+
* type: 'user',
|
|
145
|
+
* options: { inverse: null, async: false }
|
|
146
|
+
* },
|
|
147
|
+
* ],
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* export type User = WithLegacy<{
|
|
151
|
+
* firstName: string;
|
|
152
|
+
* lastName: string;
|
|
153
|
+
* age: number;
|
|
154
|
+
* friends: HasMany<User>;
|
|
155
|
+
* bestFriend: User | null;
|
|
156
|
+
* [Type]: 'user';
|
|
157
|
+
* }>
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* Using this function require registering the derivations
|
|
161
|
+
* it requires with the schema service.
|
|
162
|
+
*
|
|
163
|
+
* ```ts
|
|
164
|
+
* import { registerDerivations } from '@ember-data/model/migration-support';
|
|
165
|
+
*
|
|
166
|
+
* registerDerivations(schema);
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* @method withDefaults
|
|
170
|
+
* @for @ember-data/model/migration-support
|
|
171
|
+
* @static
|
|
172
|
+
* @param {LegacyResourceSchema} schema The schema to add legacy support to.
|
|
173
|
+
* @return {LegacyResourceSchema} The schema with legacy support added.
|
|
174
|
+
* @public
|
|
175
|
+
*/
|
|
176
|
+
export function withDefaults(schema: WithPartial<LegacyResourceSchema, 'legacy' | 'identity'>): LegacyResourceSchema;
|
|
177
|
+
/**
|
|
178
|
+
* A function which registers the necessary derivations to support
|
|
179
|
+
* the LegacyMode features of @ember-data/model while migrating to WarpDrive.
|
|
180
|
+
*
|
|
181
|
+
* This must be called in order to use the fields added by:
|
|
182
|
+
*
|
|
183
|
+
* ```ts
|
|
184
|
+
* import { withDefaults } from '@ember-data/model/migration-support';
|
|
185
|
+
* ```
|
|
186
|
+
*
|
|
187
|
+
* @method registerDerivations
|
|
188
|
+
* @for @ember-data/model/migration-support
|
|
189
|
+
* @static
|
|
190
|
+
* @param {SchemaService} schema The schema service to register the derivations with.
|
|
191
|
+
* @return {void}
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
export function registerDerivations(schema: SchemaService): void;
|
|
195
|
+
/**
|
|
196
|
+
* A class which provides a schema service that delegates between
|
|
197
|
+
* a primary schema service and one that supports legacy model
|
|
198
|
+
* classes as its schema source.
|
|
199
|
+
*
|
|
200
|
+
* When the primary schema service has a schema for the given
|
|
201
|
+
* resource, it will be used. Otherwise, the fallback schema
|
|
202
|
+
* service will be used.
|
|
203
|
+
*
|
|
204
|
+
* This can be used when incrementally migrating from Models to
|
|
205
|
+
* SchemaRecords by enabling unmigrated Models to continue to
|
|
206
|
+
* provide their own schema information to the application.
|
|
207
|
+
*
|
|
208
|
+
* ```ts
|
|
209
|
+
* import { DelegatingSchemaService } from '@ember-data/model/migration-support';
|
|
210
|
+
* import { SchemaService } from '@warp-drive/schema-record';
|
|
211
|
+
*
|
|
212
|
+
* class AppStore extends Store {
|
|
213
|
+
* createSchemaService() {
|
|
214
|
+
* const schema = new SchemaService();
|
|
215
|
+
* return new DelegatingSchemaService(this, schema);
|
|
216
|
+
* }
|
|
217
|
+
* }
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* All calls to register resources, derivations, transformations, hash functions
|
|
221
|
+
* etc. will be delegated to the primary schema service.
|
|
222
|
+
*
|
|
223
|
+
* @class DelegatingSchemaService
|
|
224
|
+
* @extends SchemaService
|
|
225
|
+
* @public
|
|
226
|
+
*/
|
|
227
|
+
export interface DelegatingSchemaService {
|
|
228
|
+
attributesDefinitionFor?(resource: StableRecordIdentifier | {
|
|
229
|
+
type: string;
|
|
230
|
+
}): AttributesSchema;
|
|
231
|
+
relationshipsDefinitionFor?(resource: StableRecordIdentifier | {
|
|
232
|
+
type: string;
|
|
233
|
+
}): RelationshipsSchema;
|
|
234
|
+
doesTypeExist?(type: string): boolean;
|
|
235
|
+
}
|
|
236
|
+
export class DelegatingSchemaService implements SchemaService {
|
|
237
|
+
_preferred: SchemaService;
|
|
238
|
+
_secondary: SchemaService;
|
|
239
|
+
constructor(store: Store, schema: SchemaService);
|
|
240
|
+
resourceTypes(): Readonly<string[]>;
|
|
241
|
+
hasResource(resource: StableRecordIdentifier | {
|
|
242
|
+
type: string;
|
|
243
|
+
}): boolean;
|
|
244
|
+
hasTrait(type: string): boolean;
|
|
245
|
+
resourceHasTrait(resource: StableRecordIdentifier | {
|
|
246
|
+
type: string;
|
|
247
|
+
}, trait: string): boolean;
|
|
248
|
+
fields(resource: StableRecordIdentifier | {
|
|
249
|
+
type: string;
|
|
250
|
+
}): Map<string, FieldSchema>;
|
|
251
|
+
transformation(field: GenericField | ObjectField | ArrayField | {
|
|
252
|
+
type: string;
|
|
253
|
+
}): Transformation;
|
|
254
|
+
hashFn(field: HashField | {
|
|
255
|
+
type: string;
|
|
256
|
+
}): HashFn;
|
|
257
|
+
derivation(field: DerivedField | {
|
|
258
|
+
type: string;
|
|
259
|
+
}): Derivation;
|
|
260
|
+
resource(resource: StableRecordIdentifier | {
|
|
261
|
+
type: string;
|
|
262
|
+
}): ResourceSchema | ObjectSchema;
|
|
263
|
+
registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
|
|
264
|
+
registerResource(schema: ResourceSchema | ObjectSchema): void;
|
|
265
|
+
registerTransformation(transform: Transformation): void;
|
|
266
|
+
registerDerivation<R, T, FM extends ObjectValue | null>(derivation: Derivation<R, T, FM>): void;
|
|
267
|
+
registerHashFn(hashFn: HashFn): void;
|
|
268
|
+
}
|
|
269
|
+
export {};
|
|
270
|
+
}
|
|
271
|
+
//# sourceMappingURL=migration-support.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration-support.d.ts","sourceRoot":"","sources":["../src/migration-support.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAC;AACnE,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAC;AAE3C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAG7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AACjG,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,SAAS,EACT,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,cAAc,EACf,MAAM,sCAAsC,CAAC;AAE9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGhE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EACL,SAAS,EAKT,OAAO,EAMR,MAAM,0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