@tanglemedia/svelte-starter-directus-api 4.1.3 → 5.0.1
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.
|
@@ -32,7 +32,7 @@ export declare class DirectusApiAdapter<Schema extends SchemaShape = SchemaShape
|
|
|
32
32
|
patch<T>(collection: Path, key: ApiId, query?: Record<string, unknown>): Promise<ApiResponse<T>>;
|
|
33
33
|
post<T>(collection: Path, data: AnyObject, query?: Record<string, unknown>): Promise<ApiResponse<T>>;
|
|
34
34
|
delete<T>(collection: Path, key?: ApiId): Promise<ApiResponse<T>>;
|
|
35
|
-
put<T extends object, R = T>(collection: Path, key?: ApiId, payload?: AnyObject): Promise<ApiResponse<R>>;
|
|
35
|
+
put<T extends object, R = T>(collection: Path, key?: ApiId, payload?: AnyObject, query?: Record<string, unknown>): Promise<ApiResponse<R>>;
|
|
36
36
|
upload<T>(path: string | undefined, data: FormData): Promise<ApiResponse<T>>;
|
|
37
37
|
createMany<T, R = T>(path: Path, body: ApiCreateManyQuery<T>): Promise<ApiResponse<R[], Response, AnyObject>>;
|
|
38
38
|
updateMany<T, R = T>(path: Path, body: ApiUpdateManyQuery<T>): Promise<ApiResponse<R[], Response, AnyObject>>;
|
|
@@ -128,9 +128,9 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
128
128
|
const data = await this.directus.request(deleteItem(collection, key));
|
|
129
129
|
return this.transformResponse({ data }, 202);
|
|
130
130
|
}
|
|
131
|
-
async put(collection, key, payload) {
|
|
131
|
+
async put(collection, key, payload, query) {
|
|
132
132
|
if (key) {
|
|
133
|
-
const data = (await this.directus.request(updateItem(collection, key, payload)));
|
|
133
|
+
const data = (await this.directus.request(updateItem(collection, key, payload, query)));
|
|
134
134
|
return this.transformResponse({ data }, 201);
|
|
135
135
|
}
|
|
136
136
|
else {
|
|
@@ -144,14 +144,14 @@ export class DirectusApiAdapter extends ApiAdapterAbstract {
|
|
|
144
144
|
return this.transformResponse({ data: response }, 201);
|
|
145
145
|
}
|
|
146
146
|
async createMany(path, body) {
|
|
147
|
-
const data = await this.directus.request(createItems(path, body.data));
|
|
147
|
+
const data = await this.directus.request(createItems(path, body.data, body?.query));
|
|
148
148
|
return this.transformResponse({ data }, 200);
|
|
149
149
|
}
|
|
150
150
|
async updateMany(path, body) {
|
|
151
151
|
if (!body.ids) {
|
|
152
152
|
throw Error('You must provide an array of keys to update');
|
|
153
153
|
}
|
|
154
|
-
const data = await this.directus.request(updateItems(path, body.ids || [], body.data));
|
|
154
|
+
const data = await this.directus.request(updateItems(path, body.ids || [], body.data, body?.query));
|
|
155
155
|
return this.transformResponse({ data }, 200);
|
|
156
156
|
}
|
|
157
157
|
async deleteMany(path, body) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanglemedia/svelte-starter-directus-api",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"types": "src/index.ts",
|
|
6
6
|
"description": "directus API wrapper for all the directus sdk functionality",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"vite": "^5.4.8",
|
|
37
37
|
"vitest": "^2.1.2",
|
|
38
38
|
"@internal/eslint-config": "0.0.0",
|
|
39
|
-
"@tanglemedia/svelte-starter-core": "0.
|
|
39
|
+
"@tanglemedia/svelte-starter-core": "1.0.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@directus/sdk": "18.0.1",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"@sveltejs/kit": ">=2 <3",
|
|
49
|
-
"@tanglemedia/svelte-starter-core": ">=0.
|
|
49
|
+
"@tanglemedia/svelte-starter-core": ">=1.0.0",
|
|
50
50
|
"svelte": ">=4 <5"
|
|
51
51
|
},
|
|
52
52
|
"scripts": {
|
|
@@ -232,10 +232,13 @@ export class DirectusApiAdapter<
|
|
|
232
232
|
public async put<T extends object, R = T>(
|
|
233
233
|
collection: Path,
|
|
234
234
|
key?: ApiId,
|
|
235
|
-
payload?: AnyObject
|
|
235
|
+
payload?: AnyObject,
|
|
236
|
+
query?: Record<string, unknown>
|
|
236
237
|
): Promise<ApiResponse<R>> {
|
|
237
238
|
if (key) {
|
|
238
|
-
const data = (await this.directus.request<T>(
|
|
239
|
+
const data = (await this.directus.request<T>(
|
|
240
|
+
updateItem(collection, key, payload, query)
|
|
241
|
+
)) as R;
|
|
239
242
|
return this.transformResponse({ data }, 201);
|
|
240
243
|
} else {
|
|
241
244
|
console.error(`Error updating all ${collection}: no key specified`);
|
|
@@ -250,7 +253,7 @@ export class DirectusApiAdapter<
|
|
|
250
253
|
}
|
|
251
254
|
|
|
252
255
|
async createMany<T, R = T>(path: Path, body: ApiCreateManyQuery<T>) {
|
|
253
|
-
const data = await this.directus.request<T>(createItems(path, body.data));
|
|
256
|
+
const data = await this.directus.request<T>(createItems(path, body.data, body?.query));
|
|
254
257
|
return this.transformResponse<R[]>({ data }, 200);
|
|
255
258
|
}
|
|
256
259
|
|
|
@@ -258,7 +261,9 @@ export class DirectusApiAdapter<
|
|
|
258
261
|
if (!body.ids) {
|
|
259
262
|
throw Error('You must provide an array of keys to update');
|
|
260
263
|
}
|
|
261
|
-
const data = await this.directus.request<T>(
|
|
264
|
+
const data = await this.directus.request<T>(
|
|
265
|
+
updateItems(path, body.ids || [], body.data, body?.query)
|
|
266
|
+
);
|
|
262
267
|
return this.transformResponse<R[]>({ data }, 200);
|
|
263
268
|
}
|
|
264
269
|
|