-
Notifications
You must be signed in to change notification settings - Fork 1
/
v2.js
125 lines (120 loc) · 4.82 KB
/
v2.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const OsduBaseService = require('../base');
/**
* Class that provides named access to OSDU V2 Storage endpoints
* - [Service Documentation]{@link https://community.opengroup.org/osdu/platform/system/storage/-/blob/master/docs/tutorial/StorageService.md}
* - [API Documentation]{@link https://community.opengroup.org/osdu/platform/system/storage/-/blob/master/docs/api/storage_openapi.yaml}
* @class
* @category Services
* @subcategory Storage
*/
class OsduV2StorageService extends OsduBaseService {
/**
* @constructor
* @param {BaseOsduClient} osdu_client - An implementation of the OSDU client class to broker communication with the OSDU API
* @param {string} data_partition - The data partition against which requests will be made
*/
constructor(osdu_client, data_partition) {
super(osdu_client, data_partition);
}
// Records
/**
* Get OSDU records for the specified ids
* @param {string[]} record_ids - Record identifiers of the OSDU records to retrieve
* @param {string[]} attributes - Attributes to return
* @returns {Object} The API Response
*/
async getRecords(record_ids, attributes = []) {
var requestBody = {
records: record_ids
};
if (attributes.length) {
requestBody.attributes = attributes;
}
return await this._client.post(`/api/storage/v2/query/records`, requestBody, this._dataPartition)
}
/**
* Get OSDU records for the specified id
* @param {string} record_id - Record identifier of the OSDU record to retrieve
* @returns {Object} The API Response
*/
async getRecord(record_id) {
return await this._client.get(`/api/storage/v2/records/${record_id}`, this._dataPartition);
}
/**
* Get OSDU record versions for the specified id
* @param {string} record_id - Record identifier of the OSDU record to retrieve version data
* @returns {Object} The API Response
*/
async getRecordVersions(record_id) {
return await this._client.get(`/api/storage/v2/records/versions/${record_id}`, this._dataPartition);
}
/**
* Get OSDU record for the specified id at the specified version
* @param {string} record_id - Record identifier of the OSDU record to retrieve
* @param {string} version - Version id to retrieve
* @returns {Object} The API Response
*/
async getRecordVersion(record_id, version) {
return await this._client.get(`/api/storage/v2/records/${record_id}/${version}`, this._dataPartition);
}
/**
* Upsert the provided records
* @param {Object[]} records - List of JSON representations of the records to upsert
* @returns {Object} The API Response
*/
async storeRecords(records) {
return await this._client.put(`/api/storage/v2/records`, records, this._dataPartition)
}
/**
* Delete OSDU record
* @param {string} record_id - Record identifier of the OSDU record to delete
* @returns {Object} The API Response
*/
async deleteRecord(record_id) {
return await this._client.delete(`/api/storage/v2/records/${record_id}`, this._dataPartition);
}
// Manifest
/**
* Ingest a manifest containing linked records
* @param {Object} manifest - JSON representation of the manifest to process and ingest
* @returns {Object} The API Response
*/
async ingestManifest(manifest) {
return await this._client.post(`/api/storage/v2/manifest`, manifest, this._dataPartition);
}
// Schemas
/**
* Retrieve a list of all supported record kinds
* @returns {Object} The API Response
*/
async queryAllKinds() {
return await this._client.get(`/api/storage/v2/query/kinds`, this._dataPartition);
}
/**
* Get OSDU schema for a given kind
* @param {string} kind - Name of the kind to retrieve the schema
* @returns {Object} The API Response
*/
async getSchema(kind) {
return await this._client.get(`/api/storage/v2/schemas/${kind}`, this._dataPartition);
}
/**
* Create a new schema to register a new kind
* @param {string} kind - Name of the new kind to create
* @param {Object} schema - JSON representation of the kind's schema
* @param {Object} ext - JSON representation of the schema extensions
* @returns {Object} The API Response
*/
async createSchema(kind, schema, ext) {
return await this._client.post(`/api/storage/v2/schemas`, { kind, schema, ext }, this._dataPartition);
}
/**
* Delete a kind and it's associated schema
* @param {string} kind - Name of the kind to delete
* @returns {Object} The API Response
*/
async deleteSchema(kind) {
return await this._client.delete(`/api/storage/v2/schemas/${kind}`, this._dataPartition);
}
}
module.exports = OsduV2StorageService;