@mkja/o-data 0.0.4 → 0.0.6
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/dist/index.d.ts +1 -1
- package/dist/index.js +6 -18
- package/dist/response.d.ts +4 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ declare class CollectionOperation<S extends Schema<S>, QE extends QueryableEntit
|
|
|
48
48
|
/**
|
|
49
49
|
* Query a collection of entities.
|
|
50
50
|
*/
|
|
51
|
-
query<Q extends CollectionQueryObject<QE, S>, O extends QueryOperationOptions>(q: Q, o?: O): Promise<CollectionQueryResponse<QE, Q, O>>;
|
|
51
|
+
query<Q extends CollectionQueryObject<QE, S>, O extends QueryOperationOptions>(q: Q, o?: O): Promise<CollectionQueryResponse<QE, Q, O, S>>;
|
|
52
52
|
/**
|
|
53
53
|
* Build the full URL for this operation.
|
|
54
54
|
*/
|
package/dist/index.js
CHANGED
|
@@ -91,13 +91,7 @@ export class OdataClient {
|
|
|
91
91
|
result: { error },
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
|
|
95
|
-
try {
|
|
96
|
-
result = await response.json();
|
|
97
|
-
}
|
|
98
|
-
catch {
|
|
99
|
-
result = {};
|
|
100
|
-
}
|
|
94
|
+
const result = response.status === 204 ? {} : await response.json();
|
|
101
95
|
return {
|
|
102
96
|
ok: true,
|
|
103
97
|
status: response.status,
|
|
@@ -144,7 +138,7 @@ class CollectionOperation {
|
|
|
144
138
|
const url = this.buildUrl(queryString);
|
|
145
139
|
const request = new Request(url);
|
|
146
140
|
const response = await this.#options.transport(request);
|
|
147
|
-
const data = await response.json();
|
|
141
|
+
const data = response.status === 204 || response.status === 304 ? {} : await response.json();
|
|
148
142
|
return {
|
|
149
143
|
ok: response.ok,
|
|
150
144
|
status: response.status,
|
|
@@ -168,7 +162,7 @@ class CollectionOperation {
|
|
|
168
162
|
async create(c, o) {
|
|
169
163
|
const request = buildCreateRequest(this.#path, c, o, this.#options.baseUrl, this.#entityset, this.#schema);
|
|
170
164
|
const response = await this.#options.transport(request);
|
|
171
|
-
const data = await response.json();
|
|
165
|
+
const data = response.status === 204 ? {} : await response.json();
|
|
172
166
|
return {
|
|
173
167
|
ok: response.ok,
|
|
174
168
|
status: response.status,
|
|
@@ -223,7 +217,7 @@ class SingleOperation {
|
|
|
223
217
|
const url = this.buildUrl(queryString);
|
|
224
218
|
const request = new Request(url);
|
|
225
219
|
const response = await this.#options.transport(request);
|
|
226
|
-
const data = await response.json();
|
|
220
|
+
const data = response.status === 204 || response.status === 304 ? {} : await response.json();
|
|
227
221
|
return {
|
|
228
222
|
ok: response.ok,
|
|
229
223
|
status: response.status,
|
|
@@ -247,7 +241,7 @@ class SingleOperation {
|
|
|
247
241
|
async update(u, o) {
|
|
248
242
|
const request = buildUpdateRequest(this.#path, u, o, this.#options.baseUrl, this.#entityset, this.#schema);
|
|
249
243
|
const response = await this.#options.transport(request);
|
|
250
|
-
const data = await response.json();
|
|
244
|
+
const data = response.status === 204 ? {} : await response.json();
|
|
251
245
|
return {
|
|
252
246
|
ok: response.ok,
|
|
253
247
|
status: response.status,
|
|
@@ -366,13 +360,7 @@ class SingleOperation {
|
|
|
366
360
|
result: { error },
|
|
367
361
|
};
|
|
368
362
|
}
|
|
369
|
-
|
|
370
|
-
try {
|
|
371
|
-
result = await response.json();
|
|
372
|
-
}
|
|
373
|
-
catch {
|
|
374
|
-
result = {};
|
|
375
|
-
}
|
|
363
|
+
const result = response.status === 204 ? {} : await response.json();
|
|
376
364
|
return {
|
|
377
365
|
ok: true,
|
|
378
366
|
status: response.status,
|
package/dist/response.d.ts
CHANGED
|
@@ -37,14 +37,12 @@ type ExtractQueryResultShape<E extends QueryableEntity, Q extends {
|
|
|
37
37
|
select?: readonly (keyof E['properties'])[];
|
|
38
38
|
expand?: Record<string, any>;
|
|
39
39
|
}, S extends Schema<S> = Schema<any>> = Pick<E['properties'], ExtractSelectKeys<E, Q>> & ExtractExpandShape<E, Q, S>;
|
|
40
|
-
export type CollectionQueryData<E extends QueryableEntity = any, Q extends CollectionQueryObject<E, any> = any, O = any
|
|
41
|
-
value: ExtractQueryResultShape<E, Q,
|
|
42
|
-
} & ODataMetadata : {
|
|
43
|
-
value: any[];
|
|
40
|
+
export type CollectionQueryData<E extends QueryableEntity = any, Q extends CollectionQueryObject<E, any> = any, O = any, Sch extends Schema<Sch> = Schema<any>> = {
|
|
41
|
+
value: ExtractQueryResultShape<E, Q, Sch>[];
|
|
44
42
|
} & ODataMetadata;
|
|
45
43
|
export type CollectionQueryError = ODataError;
|
|
46
|
-
export type CollectionQueryResponse<E extends QueryableEntity = any, Q extends CollectionQueryObject<E, any> = any, O = any> = ODataResponse<CollectionQueryData<E, Q, O>, CollectionQueryError> & {
|
|
47
|
-
next?: () => Promise<CollectionQueryResponse<E, Q, O>>;
|
|
44
|
+
export type CollectionQueryResponse<E extends QueryableEntity = any, Q extends CollectionQueryObject<E, any> = any, O = any, Sch extends Schema<Sch> = Schema<any>> = ODataResponse<CollectionQueryData<E, Q, O, Sch>, CollectionQueryError> & {
|
|
45
|
+
next?: () => Promise<CollectionQueryResponse<E, Q, O, Sch>>;
|
|
48
46
|
};
|
|
49
47
|
export type SingleQueryData<E extends QueryableEntity = any, Q extends SingleQueryObject<E, any> = any, S extends Schema<S> = Schema<any>> = ExtractQueryResultShape<E, Q, S> & ODataMetadata;
|
|
50
48
|
export type SingleQueryError = ODataError;
|