@darthrommy/microcms-client v0.5.1
@darthrommy/microcms-client
This is UNOFFICIAL
This is an UNOFFICIAL microCMS client library based on the microcms-ts-sdk types.
Plus, I am NOT a microcms-js-sdk maintainer nor a microcms-ts-sdk developer.
Being unable to guarantee that the APIs are always compatible with the official ones, I highly recommend you to use the latest microcms-js-sdk.
Notes
Since v0.4.0, API is no longer compatible with that of microcms-js-sdk. But I keep the following sentences as a changelog.
For <0.4.0
The APIs are almost the same as that of
microcms-js-sdk, but a few things are different.
getListDetails→getListItemI found the name
getListDetailsa bit confusing, so I renamed it togetListItem.No
getAPIThe
getAPI is omitted in this library, because more specific APIs(getList,getObject,getListItem) exist.Standard
FetchAPIWhile the
microcms-js-sdkusescross-fetchas the default fetch method, this library uses the standardfetch()as the default. However, like the official one, this method can be customized by configuring thecustomFetchoption in thecreateClientargument.createClient({ serviceDomain: string; apiKey: string; customFetch?: typeof fetch })
Changed ResolveDepthResponse type definition
The original ResolveDepthResponse(see microcms-ts-sdk) definition is:
type ResolveDepthResponse<T, Depth extends number = 1> = MicroCMSListContent & {
[K in keyof T]: T[K] extends infer Prop
? Prop extends MicroCMSRelation<infer R>
? Depth extends 0
? MicroCMSContentId
: ResolveDepthResponse<NonNullable<R>, DecrementNum<Depth>>
: Prop extends MicroCMSRelation<infer R>[]
? Depth extends 0
? MicroCMSContentId[]
: ResolveDepthResponse<NonNullable<R>, DecrementNum<Depth>>[]
: Prop
: never;
};However, there is one point that I do not like.
MicroCMSListContent & {
[K in keyof T]: T[K]...
}With this MicroCMSListContent &, the return type inference looks like:
const { contents } = await client.getList({
endpoint: "some-endpoint",
queries: { fields: ["name"] }, // only need "name" property
});
//typeof contents
{
name: string;
publishedAt: string; // actually does not exists
createdAt: string; // this
revisedAt?: string; // also this
updatedAt?: string; // and this too
}[]This is different from actual return type { name: string }[]. So I modified this type to:
+ type ResolveDepthResponse<ContentType, Depth extends number = 1> = {
- type ResolveDepthResponse<T, Depth extends number = 1> = MicroCMSListContent & {License
This software contains productions distributed under the Apache License 2.0.