@svadmin/sanity 0.8.0 → 0.9.0
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.
- package/package.json +1 -1
- package/src/data-provider.ts +7 -7
package/package.json
CHANGED
package/src/data-provider.ts
CHANGED
|
@@ -72,41 +72,41 @@ export function createSanityDataProvider(projectId: string, dataset: string, tok
|
|
|
72
72
|
query(`*[${where}]${orderStr}[${start}...${end}]`),
|
|
73
73
|
query(`count(*[${where}])`),
|
|
74
74
|
]);
|
|
75
|
-
return { data: ((data as SanityDoc[]) ?? []).map((d) => ({ ...d, id: d._id })) as T[], total: (total as number) ?? 0 };
|
|
75
|
+
return { data: ((data as SanityDoc[]) ?? []).map((d) => ({ ...d, id: d._id })) as unknown as unknown as T[], total: (total as number) ?? 0 };
|
|
76
76
|
},
|
|
77
77
|
|
|
78
78
|
async getOne<T extends BaseRecord = BaseRecord>({ resource, id }: GetOneParams): Promise<GetOneResult<T>> {
|
|
79
79
|
const raw = await query(`*[_type == "${resource}" && _id == $id][0]`, { id });
|
|
80
80
|
const data = raw as SanityDoc;
|
|
81
|
-
return { data: { ...data, id: data._id } as T };
|
|
81
|
+
return { data: { ...data, id: data._id } as unknown as unknown as T };
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
async create<T extends BaseRecord = BaseRecord>({ resource, variables }: CreateParams): Promise<CreateResult<T>> {
|
|
85
85
|
const doc = { _type: resource, ...(variables as Record<string, unknown>) };
|
|
86
86
|
const result = await mutate([{ create: doc }]);
|
|
87
87
|
const id = result.results?.[0]?.id;
|
|
88
|
-
return { data: { ...(variables as Record<string, unknown>), id, _id: id } as unknown as T };
|
|
88
|
+
return { data: { ...(variables as Record<string, unknown>), id, _id: id } as unknown as unknown as T };
|
|
89
89
|
},
|
|
90
90
|
|
|
91
91
|
async update<T extends BaseRecord = BaseRecord>({ resource, id, variables }: UpdateParams): Promise<UpdateResult<T>> {
|
|
92
92
|
await mutate([{ patch: { id, set: variables } }]);
|
|
93
|
-
return { data: { ...(variables as Record<string, unknown>), id, _id: id } as unknown as T };
|
|
93
|
+
return { data: { ...(variables as Record<string, unknown>), id, _id: id } as unknown as unknown as T };
|
|
94
94
|
},
|
|
95
95
|
|
|
96
96
|
async deleteOne<T extends BaseRecord = BaseRecord>({ resource, id }: DeleteParams): Promise<DeleteResult<T>> {
|
|
97
97
|
await mutate([{ delete: { id } }]);
|
|
98
|
-
return { data: { id } as T };
|
|
98
|
+
return { data: { id } as unknown as unknown as T };
|
|
99
99
|
},
|
|
100
100
|
|
|
101
101
|
async getMany<T extends BaseRecord = BaseRecord>({ resource, ids }: GetManyParams): Promise<GetManyResult<T>> {
|
|
102
102
|
const data = await query(`*[_type == "${resource}" && _id in $ids]`, { ids });
|
|
103
|
-
return { data: ((data as SanityDoc[]) ?? []).map((d) => ({ ...d, id: d._id })) as T[] };
|
|
103
|
+
return { data: ((data as SanityDoc[]) ?? []).map((d) => ({ ...d, id: d._id })) as unknown as unknown as T[] };
|
|
104
104
|
},
|
|
105
105
|
|
|
106
106
|
async custom<T = unknown>({ url, method, payload, headers: h }: CustomParams): Promise<CustomResult<T>> {
|
|
107
107
|
const res = await fetch(url, { method: method.toUpperCase(), headers: { ...headers, ...h }, body: payload ? JSON.stringify(payload) : undefined });
|
|
108
108
|
if (!res.ok) throw new Error(`Custom request failed: ${res.status}`);
|
|
109
|
-
return { data: (await res.json()) as T };
|
|
109
|
+
return { data: (await res.json()) as unknown as T };
|
|
110
110
|
},
|
|
111
111
|
};
|
|
112
112
|
}
|