@@ -696,13 +696,18 @@ class Contains<CardT extends FieldDefConstructor> implements Field<CardT, any> {
696
696
serialize(
697
697
value : InstanceType <CardT >,
698
698
doc : JSONAPISingleResourceDocument ,
699
+ _visited : Set <string >,
700
+ opts ? : SerializeOpts ,
699
701
): JSONAPIResource {
700
- let serialized: JSONAPISingleResourceDocument [' data' ] & {
701
- meta: Record <string , any >;
702
- } = callSerializeHook (this .card , value , doc );
703
702
if (primitive in this .card ) {
703
+ let serialized: JSONAPISingleResourceDocument [' data' ] & {
704
+ meta: Record <string , any >;
705
+ } = callSerializeHook (this .card , value , doc , undefined , opts );
704
706
return { attributes: { [this .name ]: serialized } };
705
707
} else {
708
+ let serialized: JSONAPISingleResourceDocument [' data' ] & {
709
+ meta: Record <string , any >;
710
+ } = callSerializeHook (this .card , value , doc );
706
711
let resource: JSONAPIResource = {
707
712
attributes: {
708
713
[this .name ]: serialized ?.attributes ,
@@ -2299,8 +2304,9 @@ async function getDeserializedValue<CardT extends BaseDefConstructor>({
2299
2304
export interface SerializeOpts {
2300
2305
includeComputeds? : boolean ;
2301
2306
includeUnrenderedFields? : boolean ;
2302
- maybeRelativeURL ? : (( possibleURL : string ) => string ) | null ; // setting this to null will force all URL's to be absolute
2307
+ useAbsoluteURL ? : boolean ;
2303
2308
omitFields? : [typeof BaseDef ];
2309
+ maybeRelativeURL? : (possibleURL : string ) => string ;
2304
2310
}
2305
2311
2306
2312
function serializeCardResource(
@@ -2309,7 +2315,10 @@ function serializeCardResource(
2309
2315
opts ? : SerializeOpts ,
2310
2316
visited : Set <string > = new Set (),
2311
2317
): LooseCardResource {
2312
- let adoptsFrom = identifyCard (model .constructor , opts ?.maybeRelativeURL );
2318
+ let adoptsFrom = identifyCard (
2319
+ model .constructor ,
2320
+ opts ?.useAbsoluteURL ? undefined : opts ?.maybeRelativeURL ,
2321
+ );
2313
2322
if (! adoptsFrom ) {
2314
2323
throw new Error (` bug: could not identify card: ${model .constructor .name } ` );
2315
2324
}
@@ -2346,28 +2355,22 @@ export function serializeCard(
2346
2355
let modelRelativeTo = model [relativeTo ];
2347
2356
let data = serializeCardResource (model , doc , {
2348
2357
... opts ,
2349
- // if opts.maybeRelativeURL is null that is our indication
2350
- // that the caller wants all the URL's to be absolute
2351
- ... (opts ?.maybeRelativeURL !== null
2352
- ? {
2353
- maybeRelativeURL(possibleURL : string ) {
2354
- let url = maybeURL (possibleURL , modelRelativeTo );
2355
- if (! url ) {
2356
- throw new Error (
2357
- ` could not determine url from '${maybeRelativeURL }' relative to ${modelRelativeTo } ` ,
2358
- );
2359
- }
2360
- if (! modelRelativeTo ) {
2361
- return url .href ;
2362
- }
2363
- const realmURLString = getCardMeta (model , ' realmURL' );
2364
- const realmURL = realmURLString
2365
- ? new URL (realmURLString )
2366
- : undefined ;
2367
- return maybeRelativeURL (url , modelRelativeTo , realmURL );
2368
- },
2358
+ ... {
2359
+ maybeRelativeURL(possibleURL : string ) {
2360
+ let url = maybeURL (possibleURL , modelRelativeTo );
2361
+ if (! url ) {
2362
+ throw new Error (
2363
+ ` could not determine url from '${maybeRelativeURL }' relative to ${modelRelativeTo } ` ,
2364
+ );
2369
2365
}
2370
- : {}),
2366
+ if (! modelRelativeTo ) {
2367
+ return url .href ;
2368
+ }
2369
+ const realmURLString = getCardMeta (model , ' realmURL' );
2370
+ const realmURL = realmURLString ? new URL (realmURLString ) : undefined ;
2371
+ return maybeRelativeURL (url , modelRelativeTo , realmURL );
2372
+ },
2373
+ },
2371
2374
});
2372
2375
merge (doc , { data });
2373
2376
if (! isSingleCardDocument (doc )) {
@@ -3150,7 +3153,9 @@ export class Box<T> {
3150
3153
type ElementType <T > = T extends (infer V )[] ? V : never ;
3151
3154
3152
3155
function makeRelativeURL(maybeURL : string , opts ? : SerializeOpts ): string {
3153
- return opts ?.maybeRelativeURL ? opts .maybeRelativeURL (maybeURL ) : maybeURL ;
3156
+ return opts ?.maybeRelativeURL && ! opts ?.useAbsoluteURL
3157
+ ? opts .maybeRelativeURL (maybeURL )
3158
+ : maybeURL ;
3154
3159
}
3155
3160
3156
3161
declare module ' ember-provide-consume-context/context-registry' {
0 commit comments