@ember-data/model 5.6.0-alpha.5 → 5.6.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.
Files changed (74) hide show
  1. package/addon-main.cjs +1 -1
  2. package/dist/-private.js +1 -2
  3. package/dist/hooks.js +1 -2
  4. package/dist/index.js +1 -667
  5. package/dist/migration-support.js +1 -381
  6. package/package.json +7 -31
  7. package/unstable-preview-types/-private.d.ts +3 -8
  8. package/unstable-preview-types/hooks.d.ts +3 -4
  9. package/unstable-preview-types/index.d.ts +31 -66
  10. package/unstable-preview-types/migration-support.d.ts +21 -263
  11. package/dist/-private.js.map +0 -1
  12. package/dist/errors-DsUSZ9m8.js +0 -2605
  13. package/dist/errors-DsUSZ9m8.js.map +0 -1
  14. package/dist/hooks-rXIjX2-H.js +0 -74
  15. package/dist/hooks-rXIjX2-H.js.map +0 -1
  16. package/dist/hooks.js.map +0 -1
  17. package/dist/index.js.map +0 -1
  18. package/dist/migration-support.js.map +0 -1
  19. package/dist/schema-provider-B6-5uzxP.js +0 -2229
  20. package/dist/schema-provider-B6-5uzxP.js.map +0 -1
  21. package/unstable-preview-types/-private/attr.d.ts +0 -167
  22. package/unstable-preview-types/-private/attr.d.ts.map +0 -1
  23. package/unstable-preview-types/-private/attr.type-test.d.ts +0 -4
  24. package/unstable-preview-types/-private/attr.type-test.d.ts.map +0 -1
  25. package/unstable-preview-types/-private/belongs-to.d.ts +0 -175
  26. package/unstable-preview-types/-private/belongs-to.d.ts.map +0 -1
  27. package/unstable-preview-types/-private/belongs-to.type-test.d.ts +0 -4
  28. package/unstable-preview-types/-private/belongs-to.type-test.d.ts.map +0 -1
  29. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts +0 -8
  30. package/unstable-preview-types/-private/debug/assert-polymorphic-type.d.ts.map +0 -1
  31. package/unstable-preview-types/-private/errors.d.ts +0 -292
  32. package/unstable-preview-types/-private/errors.d.ts.map +0 -1
  33. package/unstable-preview-types/-private/has-many.d.ts +0 -166
  34. package/unstable-preview-types/-private/has-many.d.ts.map +0 -1
  35. package/unstable-preview-types/-private/has-many.type-test.d.ts +0 -4
  36. package/unstable-preview-types/-private/has-many.type-test.d.ts.map +0 -1
  37. package/unstable-preview-types/-private/hooks.d.ts +0 -13
  38. package/unstable-preview-types/-private/hooks.d.ts.map +0 -1
  39. package/unstable-preview-types/-private/legacy-relationships-support.d.ts +0 -60
  40. package/unstable-preview-types/-private/legacy-relationships-support.d.ts.map +0 -1
  41. package/unstable-preview-types/-private/model-for-mixin.d.ts +0 -6
  42. package/unstable-preview-types/-private/model-for-mixin.d.ts.map +0 -1
  43. package/unstable-preview-types/-private/model-methods.d.ts +0 -37
  44. package/unstable-preview-types/-private/model-methods.d.ts.map +0 -1
  45. package/unstable-preview-types/-private/model.d.ts +0 -1272
  46. package/unstable-preview-types/-private/model.d.ts.map +0 -1
  47. package/unstable-preview-types/-private/model.type-test.d.ts +0 -4
  48. package/unstable-preview-types/-private/model.type-test.d.ts.map +0 -1
  49. package/unstable-preview-types/-private/notify-changes.d.ts +0 -8
  50. package/unstable-preview-types/-private/notify-changes.d.ts.map +0 -1
  51. package/unstable-preview-types/-private/promise-belongs-to.d.ts +0 -42
  52. package/unstable-preview-types/-private/promise-belongs-to.d.ts.map +0 -1
  53. package/unstable-preview-types/-private/promise-many-array.d.ts +0 -128
  54. package/unstable-preview-types/-private/promise-many-array.d.ts.map +0 -1
  55. package/unstable-preview-types/-private/promise-proxy-base.d.ts +0 -5
  56. package/unstable-preview-types/-private/promise-proxy-base.d.ts.map +0 -1
  57. package/unstable-preview-types/-private/record-state.d.ts +0 -80
  58. package/unstable-preview-types/-private/record-state.d.ts.map +0 -1
  59. package/unstable-preview-types/-private/references/belongs-to.d.ts +0 -497
  60. package/unstable-preview-types/-private/references/belongs-to.d.ts.map +0 -1
  61. package/unstable-preview-types/-private/references/has-many.d.ts +0 -506
  62. package/unstable-preview-types/-private/references/has-many.d.ts.map +0 -1
  63. package/unstable-preview-types/-private/schema-provider.d.ts +0 -65
  64. package/unstable-preview-types/-private/schema-provider.d.ts.map +0 -1
  65. package/unstable-preview-types/-private/type-utils.d.ts +0 -59
  66. package/unstable-preview-types/-private/type-utils.d.ts.map +0 -1
  67. package/unstable-preview-types/-private/util.d.ts +0 -8
  68. package/unstable-preview-types/-private/util.d.ts.map +0 -1
  69. package/unstable-preview-types/-private.d.ts.map +0 -1
  70. package/unstable-preview-types/hooks.d.ts.map +0 -1
  71. package/unstable-preview-types/index.d.ts.map +0 -1
  72. package/unstable-preview-types/migration-support.d.ts.map +0 -1
  73. package/unstable-preview-types/migration-support.type-test.d.ts +0 -4
  74. package/unstable-preview-types/migration-support.type-test.d.ts.map +0 -1
@@ -1,265 +1,23 @@
1
1
  declare module '@ember-data/model/migration-support' {
2
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
20
- */
21
- import type { Snapshot } from '@ember-data/legacy-compat/-private';
22
- import type Store from '@ember-data/store';
23
- import type { SchemaService } from '@ember-data/store/types';
24
- import type { StableRecordIdentifier } from '@warp-drive/core-types';
25
- import type { ChangedAttributesHash } from '@warp-drive/core-types/cache';
26
- import type { ObjectValue } from '@warp-drive/core-types/json/raw';
27
- import type { TypedRecordInstance, TypeFromInstance } from '@warp-drive/core-types/record';
28
- import type { Derivation, HashFn, Transformation } from '@warp-drive/core-types/schema/concepts';
29
- import type { ArrayField, DerivedField, FieldSchema, GenericField, HashField, LegacyResourceSchema, ObjectField, ObjectSchema, ResourceSchema } from '@warp-drive/core-types/schema/fields';
30
- import type { WithPartial } from '@warp-drive/core-types/utils';
31
- import type { MinimalLegacyRecord } from '@ember-data/model/-private/model-methods';
32
- import { belongsTo, hasMany } from '@ember-data/model/-private/model-methods';
33
- import RecordState from '@ember-data/model/-private/record-state';
34
- import type BelongsToReference from '@ember-data/model/-private/references/belongs-to';
35
- import type HasManyReference from '@ember-data/model/-private/references/has-many';
36
- import type { _MaybeBelongsToFields, MaybeHasManyFields } from '@ember-data/model/-private/type-utils';
37
- export type WithLegacyDerivations<T extends TypedRecordInstance> = T & MinimalLegacyRecord & {
38
- belongsTo: typeof belongsTo;
39
- hasMany: typeof hasMany;
40
- };
41
- type AttributesSchema = ReturnType<Exclude<SchemaService['attributesDefinitionFor'], undefined>>;
42
- type RelationshipsSchema = ReturnType<Exclude<SchemaService['relationshipsDefinitionFor'], undefined>>;
43
- interface LegacyModeRecord<T extends TypedRecordInstance> {
44
- id: string | null;
45
- serialize(options?: Record<string, unknown>): unknown;
46
- destroyRecord(options?: Record<string, unknown>): Promise<this>;
47
- unloadRecord(): void;
48
- changedAttributes(): ChangedAttributesHash;
49
- rollbackAttributes(): void;
50
- _createSnapshot(): Snapshot<T>;
51
- save(options?: Record<string, unknown>): Promise<this>;
52
- reload(options?: Record<string, unknown>): Promise<T>;
53
- belongsTo<K extends _MaybeBelongsToFields<T>>(prop: K): BelongsToReference<T, K>;
54
- hasMany<K extends MaybeHasManyFields<T>>(prop: K): HasManyReference<T, K>;
55
- deleteRecord(): void;
56
- adapterError: unknown;
57
- constructor: {
58
- modelName: TypeFromInstance<T>;
59
- };
60
- currentState: RecordState;
61
- dirtyType: 'deleted' | 'created' | 'updated' | '';
62
- errors: unknown;
63
- hasDirtyAttributes: boolean;
64
- isDeleted: boolean;
65
- isEmpty: boolean;
66
- isError: boolean;
67
- isLoaded: boolean;
68
- isLoading: boolean;
69
- isDestroying: boolean;
70
- isDestroyed: boolean;
71
- isNew: boolean;
72
- isSaving: boolean;
73
- isValid: boolean;
74
- }
75
- /**
76
- * A Type utility that enables quickly adding type information for the fields
77
- * defined by `import { withDefaults } from '@ember-data/model/migration-support'`.
78
- *
79
- * Example:
80
- *
81
- * ```ts
82
- * import { withDefaults, WithLegacy } from '@ember-data/model/migration-support';
83
- * import { Type } from '@warp-drive/core-types/symbols';
84
- * import type { HasMany } from '@ember-data/model';
85
- *
86
- * export const UserSchema = withDefaults({
87
- * type: 'user',
88
- * fields: [
89
- * { name: 'firstName', kind: 'attribute' },
90
- * { name: 'lastName', kind: 'attribute' },
91
- * { name: 'age', kind: 'attribute' },
92
- * { name: 'friends',
93
- * kind: 'hasMany',
94
- * type: 'user',
95
- * options: { inverse: 'friends', async: false }
96
- * },
97
- * { name: 'bestFriend',
98
- * kind: 'belongsTo',
99
- * type: 'user',
100
- * options: { inverse: null, async: false }
101
- * },
102
- * ],
103
- * });
104
- *
105
- * export type User = WithLegacy<{
106
- * firstName: string;
107
- * lastName: string;
108
- * age: number;
109
- * friends: HasMany<User>;
110
- * bestFriend: User | null;
111
- * [Type]: 'user';
112
- * }>
113
- * ```
114
- *
115
- */
116
- export type WithLegacy<T extends TypedRecordInstance> = T & LegacyModeRecord<T>;
117
- /**
118
- * A function which adds the necessary fields to a schema and marks it as
119
- * being in LegacyMode. This is used to support the legacy features of
120
- * @ember-data/model while migrating to WarpDrive.
121
- *
122
- * Example:
123
- *
124
- * ```ts
125
- * import { withDefaults, WithLegacy } from '@ember-data/model/migration-support';
126
- * import { Type } from '@warp-drive/core-types/symbols';
127
- * import type { HasMany } from '@ember-data/model';
128
- *
129
- * export const UserSchema = withDefaults({
130
- * type: 'user',
131
- * fields: [
132
- * { name: 'firstName', kind: 'attribute' },
133
- * { name: 'lastName', kind: 'attribute' },
134
- * { name: 'age', kind: 'attribute' },
135
- * { name: 'friends',
136
- * kind: 'hasMany',
137
- * type: 'user',
138
- * options: { inverse: 'friends', async: false }
139
- * },
140
- * { name: 'bestFriend',
141
- * kind: 'belongsTo',
142
- * type: 'user',
143
- * options: { inverse: null, async: false }
144
- * },
145
- * ],
146
- * });
147
- *
148
- * export type User = WithLegacy<{
149
- * firstName: string;
150
- * lastName: string;
151
- * age: number;
152
- * friends: HasMany<User>;
153
- * bestFriend: User | null;
154
- * [Type]: 'user';
155
- * }>
156
- * ```
157
- *
158
- * Using this function require registering the derivations
159
- * it requires with the schema service.
160
- *
161
- * ```ts
162
- * import { registerDerivations } from '@ember-data/model/migration-support';
163
- *
164
- * registerDerivations(schema);
165
- * ```
166
- *
167
- * @param {LegacyResourceSchema} schema The schema to add legacy support to.
168
- * @return {LegacyResourceSchema} The schema with legacy support added.
169
- * @public
170
- */
171
- export function withDefaults(schema: WithPartial<LegacyResourceSchema, 'legacy' | 'identity'>): LegacyResourceSchema;
172
- /**
173
- * A function which registers the necessary derivations to support
174
- * the LegacyMode features of @ember-data/model while migrating to WarpDrive.
175
- *
176
- * This must be called in order to use the fields added by:
177
- *
178
- * ```ts
179
- * import { withDefaults } from '@ember-data/model/migration-support';
180
- * ```
181
- *
182
- * @param {SchemaService} schema The schema service to register the derivations with.
183
- * @return {void}
184
- * @public
185
- */
186
- export function registerDerivations(schema: SchemaService): void;
187
- /**
188
- * A class which provides a schema service that delegates between
189
- * a primary schema service and one that supports legacy model
190
- * classes as its schema source.
191
- *
192
- * When the primary schema service has a schema for the given
193
- * resource, it will be used. Otherwise, the fallback schema
194
- * service will be used.
195
- *
196
- * This can be used when incrementally migrating from Models to
197
- * SchemaRecords by enabling unmigrated Models to continue to
198
- * provide their own schema information to the application.
199
- *
200
- * ```ts
201
- * import { DelegatingSchemaService } from '@ember-data/model/migration-support';
202
- * import { SchemaService } from '@warp-drive/schema-record';
203
- *
204
- * class AppStore extends Store {
205
- * createSchemaService() {
206
- * const schema = new SchemaService();
207
- * return new DelegatingSchemaService(this, schema);
208
- * }
209
- * }
210
- * ```
211
- *
212
- * All calls to register resources, derivations, transformations, hash functions
213
- * etc. will be delegated to the primary schema service.
214
- *
215
- * @class DelegatingSchemaService
216
- * @public
217
- */
218
- export interface DelegatingSchemaService {
219
- attributesDefinitionFor?(resource: StableRecordIdentifier | {
220
- type: string;
221
- }): AttributesSchema;
222
- relationshipsDefinitionFor?(resource: StableRecordIdentifier | {
223
- type: string;
224
- }): RelationshipsSchema;
225
- doesTypeExist?(type: string): boolean;
226
- }
227
- export class DelegatingSchemaService implements SchemaService {
228
- _preferred: SchemaService;
229
- _secondary: SchemaService;
230
- constructor(store: Store, schema: SchemaService);
231
- isDelegated(resource: StableRecordIdentifier | {
232
- type: string;
233
- }): boolean;
234
- resourceTypes(): Readonly<string[]>;
235
- hasResource(resource: StableRecordIdentifier | {
236
- type: string;
237
- }): boolean;
238
- hasTrait(type: string): boolean;
239
- resourceHasTrait(resource: StableRecordIdentifier | {
240
- type: string;
241
- }, trait: string): boolean;
242
- fields(resource: StableRecordIdentifier | {
243
- type: string;
244
- }): Map<string, FieldSchema>;
245
- transformation(field: GenericField | ObjectField | ArrayField | {
246
- type: string;
247
- }): Transformation;
248
- hashFn(field: HashField | {
249
- type: string;
250
- }): HashFn;
251
- derivation(field: DerivedField | {
252
- type: string;
253
- }): Derivation;
254
- resource(resource: StableRecordIdentifier | {
255
- type: string;
256
- }): ResourceSchema | ObjectSchema;
257
- registerResources(schemas: Array<ResourceSchema | ObjectSchema>): void;
258
- registerResource(schema: ResourceSchema | ObjectSchema): void;
259
- registerTransformation(transform: Transformation): void;
260
- registerDerivation<R, T, FM extends ObjectValue | null>(derivation: Derivation<R, T, FM>): void;
261
- registerHashFn(hashFn: HashFn): void;
262
- }
263
- export {};
264
- }
265
- //# sourceMappingURL=migration-support.d.ts.map
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
20
+ */
21
+ export * from "@warp-drive/legacy/model/migration-support";
22
+
23
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"-private.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}