Skip to content

Commit

Permalink
Feature/versioning (#19)
Browse files Browse the repository at this point in the history
* Change versioning structure

* Updated readme and release notes

* Fixing integration tests

* Add dataset and schema services

* Version and readme update

* Tyypo fix
  • Loading branch information
pbradshawusc authored Mar 11, 2021
1 parent 9df79a2 commit 8861413
Show file tree
Hide file tree
Showing 58 changed files with 1,347 additions and 317 deletions.
106 changes: 62 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ A simple node client/service for the [OSDU](https://community.opengroup.org/osdu
## Contents

- [Service](#service)
* [OsduR2Service](#osdur2service)
+ [Currently supported methods](#r2-currently-supported-methods)
* [OsduService](#osduservice)
+ [Currently supported methods](#currently-supported-methods)
- [Clients](#clients)
* [SimpleOsduClient](#simpleosduclient)
* [AwsOsduClient](#awsosduclient)
Expand All @@ -30,42 +30,60 @@ A simple node client/service for the [OSDU](https://community.opengroup.org/osdu

Choose the service that matches your OSDU application instance version.

### OsduR2Service
### OsduService

Service to encapsulate the OSDU R2 application endpoints. Provides
Service to encapsulate the OSDU application endpoints. Provides
named access to the below supported OSDU methods, all in an async
manner.

#### R2 currently supported methods

- [search](service/R2/query.js)
- query
- queryWithPaging
- queryAll
- [storage](service/R2/storage.js)
- getRecords
- getRecord
- getRecordVersions
- getRecordVersion
- storeRecords
- deleteRecord
- ingestManifest
- queryAllKinds
- getSchema
- createSchema
- deleteSchema
- [delivery](service/R2/delivery.js)
- getSignedUrls
- [legal](service/R2/legal.js)
- listLegalTags
- getLegalTags
- validateLegalTags
- getLegalTag
- getLegalTagProperties
- createLegalTag
- updateLegalTag
- deleteLegalTag
- [entitlements](service/R2/entitlements.js)
#### Currently supported methods

- [search](src/service/query/index.js)
- [v2](src/service/query/v2.js)
- query
- queryWithPaging
- queryAll
- [storage](src/service/storage/index.js)
- [v2](src/service/storage/v2.js)
- getRecords
- getRecord
- getRecordVersions
- getRecordVersion
- storeRecords
- deleteRecord
- ingestManifest
- queryAllKinds
- getSchema
- createSchema
- deleteSchema
- [delivery](src/service/delivery/index.js)
- [v2](src/service/delivery/v2.js)
- getSignedUrls
- [legal](src/service/legal/index.js)
- [v1](src/service/legal/v1.js)
- listLegalTags
- getLegalTags
- validateLegalTags
- getLegalTag
- getLegalTagProperties
- createLegalTag
- updateLegalTag
- deleteLegalTag
- [entitlements](src/service/entitlements/index.js)
- [dataset](src/service/dataset/index.js)
- [v1](src/service/dataset/v1.js)
- getDatasetRegistry
- getDatasetRegistries
- registerDatasets
- getStorageInstructions
- getRetrievalInstructions
- getMultipleRetrievalInstructions
- [schema](src/service/schema/index.js)
- [v1](src/service/schema/v1.js)
- createSchema
- updateSchema
- listSchemasByFilter
- getSchema

## Clients

Expand Down Expand Up @@ -191,24 +209,24 @@ var osduClient = new AWSOsduClient({
});
```

### Using the OsduR2Service
### Using the OsduService

Below are just a few usage examples using the OsduR2Service. See [integration and unit tests](tests) for more copmrehensive usage examples.
Below are just a few usage examples using the OsduService. See [integration and unit tests](tests) for more copmrehensive usage examples.

Instantiating the service is as simple as passing in the client and the data partition you wish to operate on. For
more information regarding creating an OSDU client, please see [Instantiating the SimpleOsduClient](#instantiating-the-simpleosduclient) or [Instantiating the AwsOsduClient](#instantiating-the-awsosduclient)

```javascript
const { OsduR2Service } = require('osdujs');
const { OsduService } = require('osdujs');

var client = createOSDUClient();
var osduService = new OsduR2Service(client, 'opendes');
var osduService = new OsduService(client, 'opendes');
```

#### Search for records by query

```javascript
var queryResults = await osduService.QueryService.query(
var queryResults = await osduService.QueryService.V2.query(
(new OsduQueryBuilder())
.kind('opendes:osdu:*:*')
.build()
Expand All @@ -223,7 +241,7 @@ For result sets larger than 1,000 records, use the query with paging method to p
Initially:

```javascript
var queryResults = await osduService.QueryService.queryWithPaging(
var queryResults = await osduService.QueryService.V2.queryWithPaging(
(new OsduQueryBuilder())
.kind('opendes:osdu:*:*')
.build()
Expand All @@ -235,7 +253,7 @@ With an existing cursor:

```javascript
const cursor = "cursor";
var queryResults = await osduService.QueryService.queryWithPaging(
var queryResults = await osduService.QueryService.V2.queryWithPaging(
(new OsduQueryBuilder())
.kind('opendes:osdu:*:*')
.build(),
Expand All @@ -249,7 +267,7 @@ var queryResults = await osduService.QueryService.queryWithPaging(
For result sets larger than 1,000 records, use the query all method to pull all records.

```javascript
var queryResults = await osduService.QueryService.queryAll(
var queryResults = await osduService.QueryService.V2.queryAll(
(new OsduQueryBuilder())
.kind('opendes:osdu:*:*')
.build()
Expand All @@ -261,7 +279,7 @@ var queryResults = await osduService.QueryService.queryAll(

```javascript
const record_id = 'opendes:doc:123456789';
var record = await osduService.StorageService.getRecord(record_id);
var record = await osduService.StorageService.V2.getRecord(record_id);
// { id: 'opendes:doc:123456789', kind: ..., data: {...}, acl: {...}, .... }
```

Expand All @@ -272,6 +290,6 @@ const fs = require('fs');
const new_or_updated_record = JSON.parse(
fs.readFileSync('./record-123.json').toString()
);
var record = await osduService.StorageService.storeRecords([new_or_updated_record]);
var record = await osduService.StorageService.V2.storeRecords([new_or_updated_record]);
// { recordCount: 1, recordIds: [...], skippedRecordIds: [] }
```
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "osdujs",
"version": "1.0.3",
"version": "2.0.0",
"description": "Nodejs client and service to interact with OSDU applications",
"repository": {
"type": "git",
Expand Down
8 changes: 8 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Release Notes

## `2.0.0`

**Release Date**: 2021-3-10

Changed versioning structure of classes to be service version based rather than OSDU release version based.

Addition of dataset and schema services for R3 compatibility

## `1.0.3`

**Release Date**: 2021-2-2
Expand Down
3 changes: 2 additions & 1 deletion src/models/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
...require('./query')
...require('./query'),
...require('./schema')
}
1 change: 1 addition & 0 deletions src/models/schema/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports.OsduSchemaQueryBuilder = require('./osduSchemaQueryBuilder');
170 changes: 170 additions & 0 deletions src/models/schema/osduSchemaQueryBuilder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/**
* Class to build OSDU schema query bodies with friendly names for each available option
* - Note that querys built with this builder must at minimum specify the [kind]{@link OsduQueryBuilder#kind}
*
* @class
* @category Models
* @subcategory Schema
*/
class OsduSchemaQueryBuilder {
/** @constructor */
constructor() {
}

// Setters
/**
* Pass an optional string to search for a specific authority
* - Accepts wildcards `*`
* @param {string} authority - The OSDU authority with which to filter the search
*/
authority(authority) {
this._authority = authority;
return this;
}

/**
* Pass an optional string to search for a specific source
* - Accepts wildcards `*`
* @param {string} source - The OSDU source with which to filter the search
*/
source(source) {
this._source = source;
return this;
}

/**
* Pass an optional string to search for a specific entityType
* - Accepts wildcards `*`
* @param {string} entityType - The OSDU entityType with which to filter the search
*/
entityType(entityType) {
this._entityType = entityType;
return this;
}

/**
* Pass an optional string to search for a specific schemaVersionMajor
* - Accepts wildcards `*`
* @param {string|number} schemaVersionMajor - The OSDU schemaVersionMajor with which to filter the search
*/
schemaVersionMajor(schemaVersionMajor) {
this._schemaVersionMajor = schemaVersionMajor;
return this;
}

/**
* Pass an optional string to search for a specific schemaVersionMinor
* - Accepts wildcards `*`
* @param {string|number} schemaVersionMinor - The OSDU schemaVersionMinor with which to filter the search
*/
schemaVersionMinor(schemaVersionMinor) {
this._schemaVersionMinor = schemaVersionMinor;
return this;
}

/**
* The schema status specification
* - Accepts only valid status `PUBLISHED`, `DEVELOPMENT`, or `OBSOLETE`
* @param {('PUBLISHED'|'DEVELOPMENT'|'OBSOLETE')} status - The OSDU status with which to filter the search
*/
status(status) {
if (![
"PUBLISHED",
"DEVELOPMENT",
"OBSOLETE"
].contains(status)) {
throw new Error(`Invalid status type ${status} in Osdu Schema Query Builder`);
}
this._status = status;
return this;
}

/**
* The scope or schema visibility specification
* - Accepts only valid status `INTERNAL` or `SHARED`
* @param {('INTERNAL'|'SHARED')} status - The OSDU scope with which to filter the search
*/
scope(scope) {
if (![
"SHARED",
"INTERNAL"
].contains(scope)) {
throw new Error(`Invalid scope type ${scope} in Osdu Schema Query Builder`);
}
this._scope = scope;
return this;
}

/**
* If True, only return the latest version
* @param {boolean} latestVersion - Whether to retrieve only the latest version
*/
latestVersion(latestVersion) {
this._latestVersion = !!latestVersion ? "True" : "False";
return this;
}

/**
* Maximum number of schema records to return
* @param {number} limit - The integer number of records to return
*/
limit(limit) {
this._limit = limit;
return this;
}

/**
* Number of records to skip for pagination
* @param {number} offset - The integer number of records to skip
*/
offset(offset) {
this._offset = offset;
return this;
}

// Build
/**
* Construct the query request query string based on the attributes set
* @returns {string} The query string that is passed to the schema query request
*/
build() {
var queryString = "?";

if (this._authority) {
queryString += `&authority=${this._authority}`;
}
if (this._source) {
queryString += `&source=${this._source}`;
}
if (this._entityType) {
queryString += `&entityType=${this._entityType}`;
}
if (this._schemaVersionMajor) {
queryString += `&schemaVersionMajor=${this._schemaVersionMajor}`;
}
if (this._schemaVersionMinor) {
queryString += `&schemaVersionMinor=${this._schemaVersionMinor}`;
}
if (this._status) {
queryString += `&status=${this._status}`;
}
if (this._scope) {
queryString += `&scope=${this._scope}`;
}
if (this._latestVersion) {
queryString += `&latestVersion=${this._latestVersion}`;
}
if (this._limit) {
queryString += `&limit=${this._limit}`;
}
if (this._offset) {
queryString += `&offset=${this._offset}`;
}

queryString = queryString.substr(0, queryString.count-1);

return queryString;
}
}

module.exports = OsduSchemaQueryBuilder;
Loading

0 comments on commit 8861413

Please sign in to comment.