json-api-models
Advanced tools
Comparing version
@@ -25,3 +25,3 @@ import { JsonApiResource, SchemaCollection } from './types'; | ||
} | ||
type ProxiedModel<Schema extends JsonApiResource, Schemas extends SchemaCollection> = Schema & Schema['attributes'] & { | ||
type ProxiedModel<Schema extends JsonApiResource, Schemas extends SchemaCollection> = Schema & Schema['attributes'] & (Schema['relationships'] extends Record<string, never> | undefined ? {} : { | ||
[Property in keyof NonNullable<Schema['relationships']>]?: NonNullable<NonNullable<Schema['relationships']>[Property]> extends { | ||
@@ -34,3 +34,3 @@ data?: infer Data; | ||
}[] ? ModelForType<RelatedType, Schemas>[] : null : never; | ||
}; | ||
}); | ||
export type Model<Schema extends JsonApiResource = JsonApiResource, Schemas extends SchemaCollection = SchemaCollection> = JsonApiResource<Schema['type']> & ModelBase<Schema, Schemas> & ProxiedModel<Schema, Schemas>; | ||
@@ -37,0 +37,0 @@ export declare const Model: new <Schema extends JsonApiResource = JsonApiResource, Schemas extends SchemaCollection = SchemaCollection>(data: JsonApiResource<Schema['type']>, store: Store<Schemas>) => Model<Schema, Schemas>; |
{ | ||
"name": "json-api-models", | ||
"description": "A lightweight layer for working with JSON:API data.", | ||
"version": "0.2.0-beta.9", | ||
"version": "0.2.0-beta.10", | ||
"author": "Toby Zerner", | ||
@@ -54,3 +54,4 @@ "license": "MIT", | ||
"singleQuote": true | ||
} | ||
}, | ||
"packageManager": "pnpm@9.1.0+sha512.67f5879916a9293e5cf059c23853d571beaf4f753c707f40cb22bed5fb1578c6aad3b6c4107ccb3ba0b35be003eb621a16471ac836c87beb53f9d54bb4612724" | ||
} |
@@ -115,13 +115,20 @@ import { JsonApiResource, SchemaCollection } from './types'; | ||
> = Schema & | ||
Schema['attributes'] & { | ||
[Property in keyof NonNullable<Schema['relationships']>]?: NonNullable< | ||
NonNullable<Schema['relationships']>[Property] | ||
> extends { data?: infer Data } | ||
? Data extends { type: infer RelatedType extends string } | ||
? ModelForType<RelatedType, Schemas> | undefined | ||
: Data extends { type: infer RelatedType extends string }[] | ||
? ModelForType<RelatedType, Schemas>[] | ||
: null | ||
: never; | ||
}; | ||
Schema['attributes'] & | ||
(Schema['relationships'] extends Record<string, never> | undefined | ||
? {} | ||
: { | ||
[Property in keyof NonNullable< | ||
Schema['relationships'] | ||
>]?: NonNullable< | ||
NonNullable<Schema['relationships']>[Property] | ||
> extends { data?: infer Data } | ||
? Data extends { type: infer RelatedType extends string } | ||
? ModelForType<RelatedType, Schemas> | undefined | ||
: Data extends { | ||
type: infer RelatedType extends string; | ||
}[] | ||
? ModelForType<RelatedType, Schemas>[] | ||
: null | ||
: never; | ||
}); | ||
@@ -128,0 +135,0 @@ export type Model< |
25917
1.94%363
1.97%