@@ -66,7 +66,7 @@ export interface GenericField {
66
66
*
67
67
* @typedoc
68
68
*/
69
- export interface AliasField {
69
+ export interface LegacyAliasField {
70
70
kind : 'alias' ;
71
71
name : string ;
72
72
type : null ; // should always be null
@@ -82,13 +82,104 @@ export interface AliasField {
82
82
| SchemaObjectField
83
83
| ArrayField
84
84
| SchemaArrayField
85
- | ResourceField
86
- | CollectionField
85
+ // | ResourceField
86
+ // | CollectionField
87
87
| LegacyAttributeField
88
88
| LegacyBelongsToField
89
89
| LegacyHasManyField ;
90
90
}
91
91
92
+ /**
93
+ * A field that can be used to alias one key to another
94
+ * key present in the cache version of the resource.
95
+ *
96
+ * Unlike DerivedField, an AliasField may write to its
97
+ * source when a record is in an editable mode.
98
+ *
99
+ * AliasFields may utilize a transform, specified by type,
100
+ * to pre/post process the field.
101
+ *
102
+ * An AliasField may also specify a `kind` via options.
103
+ * `kind` may be any other valid field kind other than
104
+ *
105
+ * - `@hash`
106
+ * - `@id`
107
+ * - `@local`
108
+ * - `derived`
109
+ *
110
+ * This allows an AliasField to rename any field in the cache.
111
+ *
112
+ * Alias fields are generally intended to be used to support migrating
113
+ * between different schemas, though there are times where they are useful
114
+ * as a form of advanced derivation when used with a transform. For instance,
115
+ * an AliasField could be used to expose both a string and a Date version of the
116
+ * same field, with both being capable of being written to.
117
+ *
118
+ * @typedoc
119
+ */
120
+ export interface PolarisAliasField {
121
+ kind : 'alias' ;
122
+ name : string ;
123
+ type : null ; // should always be null
124
+
125
+ /**
126
+ * The field def for which this is an alias.
127
+ *
128
+ * @typedoc
129
+ */
130
+ options :
131
+ | GenericField
132
+ | ObjectField
133
+ | SchemaObjectField
134
+ | ArrayField
135
+ | SchemaArrayField
136
+ // | ResourceField
137
+ // | CollectionField
138
+ | LinksModeBelongsToField
139
+ | LinksModeHasManyField ;
140
+ }
141
+
142
+ /**
143
+ * A field that can be used to alias one key to another
144
+ * key present in the cache version of the resource.
145
+ *
146
+ * Unlike DerivedField, an AliasField may write to its
147
+ * source when a record is in an editable mode.
148
+ *
149
+ * AliasFields may utilize a transform, specified by type,
150
+ * to pre/post process the field.
151
+ *
152
+ * An AliasField may also specify a `kind` via options.
153
+ * `kind` may be any other valid field kind other than
154
+ *
155
+ * - `@hash`
156
+ * - `@id`
157
+ * - `@local`
158
+ * - `derived`
159
+ *
160
+ * This allows an AliasField to rename any field in the cache.
161
+ *
162
+ * Alias fields are generally intended to be used to support migrating
163
+ * between different schemas, though there are times where they are useful
164
+ * as a form of advanced derivation when used with a transform. For instance,
165
+ * an AliasField could be used to expose both a string and a Date version of the
166
+ * same field, with both being capable of being written to.
167
+ *
168
+ * @typedoc
169
+ */
170
+ export interface ObjectAliasField {
171
+ kind : 'alias' ;
172
+ name : string ;
173
+ type : null ; // should always be null
174
+
175
+ /**
176
+ * The field def for which this is an alias.
177
+ *
178
+ * @typedoc
179
+ */
180
+ options : GenericField | ObjectField | SchemaObjectField | ArrayField | SchemaArrayField ;
181
+ }
182
+
92
183
/**
93
184
* Represents a field whose value is the primary
94
185
* key of the resource.
@@ -1178,7 +1269,7 @@ export interface LinksModeHasManyField {
1178
1269
*/
1179
1270
export type LegacyModeFieldSchema =
1180
1271
| GenericField
1181
- | AliasField
1272
+ | LegacyAliasField
1182
1273
| LocalField
1183
1274
| ObjectField
1184
1275
| SchemaObjectField
@@ -1198,7 +1289,7 @@ export type LegacyModeFieldSchema =
1198
1289
*/
1199
1290
export type PolarisModeFieldSchema =
1200
1291
| GenericField
1201
- | AliasField
1292
+ | PolarisAliasField
1202
1293
| LocalField
1203
1294
| ObjectField
1204
1295
| SchemaObjectField
@@ -1223,7 +1314,8 @@ export type PolarisModeFieldSchema =
1223
1314
*/
1224
1315
export type FieldSchema =
1225
1316
| GenericField
1226
- | AliasField
1317
+ | LegacyAliasField
1318
+ | PolarisAliasField
1227
1319
| LocalField
1228
1320
| ObjectField
1229
1321
| SchemaObjectField
@@ -1246,7 +1338,7 @@ export type FieldSchema =
1246
1338
*/
1247
1339
export type ObjectFieldSchema =
1248
1340
| GenericField
1249
- | AliasField
1341
+ | ObjectAliasField
1250
1342
| LocalField
1251
1343
| ObjectField
1252
1344
| SchemaObjectField
@@ -1494,5 +1586,28 @@ export function isResourceSchema(schema: ResourceSchema | ObjectSchema): schema
1494
1586
return schema ?. identity ?. kind === '@id' ;
1495
1587
}
1496
1588
1497
- export type LegacyFieldSchema = LegacyAttributeField | LegacyBelongsToField | LegacyHasManyField ;
1498
- export type LegacyRelationshipSchema = LegacyBelongsToField | LegacyHasManyField ;
1589
+ /**
1590
+ * A type utility to narrow a schema to LegacyResourceSchema
1591
+ *
1592
+ * @method isLegacyResourceSchema
1593
+ * @static
1594
+ * @for @warp -drive/core-types
1595
+ * @param schema
1596
+ * @returns {boolean }
1597
+ * @public
1598
+ */
1599
+ export function isLegacyResourceSchema ( schema : ResourceSchema | ObjectSchema ) : schema is LegacyResourceSchema {
1600
+ return isResourceSchema ( schema ) && schema . legacy === true ;
1601
+ }
1602
+
1603
+ export type LegacyField =
1604
+ | LegacyAttributeField
1605
+ | LegacyBelongsToField
1606
+ | LegacyHasManyField
1607
+ | LinksModeBelongsToField
1608
+ | LinksModeHasManyField ;
1609
+ export type LegacyRelationshipField =
1610
+ | LegacyBelongsToField
1611
+ | LegacyHasManyField
1612
+ | LinksModeBelongsToField
1613
+ | LinksModeHasManyField ;
0 commit comments