-
Notifications
You must be signed in to change notification settings - Fork 306
/
EntityProxy.js
69 lines (62 loc) · 2 KB
/
EntityProxy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/** @format */
"use strict";
const ODataMode = require("./../../core/Constants").ODataMode,
BaseProxy = require("./BaseProxy"),
InternalAzuriteError = require("./../../core/InternalAzuriteError");
class EntityProxy extends BaseProxy {
constructor(entity) {
super(entity);
this.partitionKey = entity.partitionKey;
this.rowKey = entity.rowKey;
this.etag = `${entity.odata.etag}`;
}
/**
* Returns the odata representation of the 'Entity' entity.
*
* @param {any} mode is (nometadata|minimalmetadata|fullmetadata)
* @returns
* @memberof EntityProxy
*/
odata(mode) {
const odata = super.odata(mode);
if (mode === ODataMode.FULL) {
odata["odata.etag"] = this._.odata.etag;
}
return odata;
}
/**
* Returns all attributes (including partition key, row key) of the entity, and
* depending on @param mode the odata type specifications.
*
* @param {any} mode is (nometadata|minimalmetadata|fullmetadata)
* @returns
* @memberof EntityProxy
*/
attribs(mode) {
// this is described here:
// https://docs.microsoft.com/en-us/rest/api/storageservices/payload-format-for-table-service-operations
let filteredAttribs = {};
if (mode === ODataMode.FULL) {
return this._.attribs; // also return the OData type specifications
} else if (mode === ODataMode.MINIMAL) {
// In case of no metadata we filter out most of the OData info and "Timestamp@odata.type"
for (const key of Object.keys(this._.attribs)) {
if (key.includes("Timestamp@odata.type")) {
continue;
}
filteredAttribs[key] = this._.attribs[key];
}
} else {
// In case of no metadata we filter out all the OData type specifications
const attribs = {};
for (const key of Object.keys(this._.attribs)) {
if (key.includes("@odata.type")) {
continue;
}
filteredAttribs[key] = this._.attribs[key];
}
}
return filteredAttribs;
}
}
module.exports = EntityProxy;