New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rest-on-couch-client

Package Overview
Dependencies
Maintainers
4
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rest-on-couch-client - npm Package Compare versions

Comparing version 2.2.4 to 2.3.0

13

History.md

@@ -0,1 +1,14 @@

## [2.3.0](https://github.com/cheminfo/rest-on-couch-client/compare/v2.2.4...v2.3.0) (2020-12-04)
### Features
* add hasRight method on document ([c6ee61a](https://github.com/cheminfo/rest-on-couch-client/commit/c6ee61a14aff664bab8302654c510d38cd3efaf4))
* make RocDocument a generic type ([bf59c56](https://github.com/cheminfo/rest-on-couch-client/commit/bf59c5682fbeeaa39962fdee77b2ce813c854592))
### Bug Fixes
* correct computation of attachment url ([4cf5f94](https://github.com/cheminfo/rest-on-couch-client/commit/4cf5f941cf01035dc88e43c8d7445f5c24d25617))
## [2.2.4](https://github.com/cheminfo/rest-on-couch-client/compare/v2.2.1...v2.2.4) (2020-09-15)

@@ -2,0 +15,0 @@

2

lib-es6/base/BaseRocDocument.js

@@ -31,3 +31,3 @@ import { RocClientError } from '../Error';

name,
url: `${this.getBaseUrl()}${doc._id}/${name}`,
url: `${this.getBaseUrl()}${name}`,
};

@@ -34,0 +34,0 @@ }

@@ -5,25 +5,31 @@ import sampleToc from './sampleToc';

documents: {
uuid1: [
{
_id: 'uuid1',
_rev: '1-db302401f0df79e06b79f10f79c1f0f9',
$id: 'uuid1',
$type: 'entry',
$content: {},
$modificationDate: 0,
$creationDate: 0,
$lastModification: 'test@test.com',
$kind: 'kind',
$owners: ['test@test.com'],
_attachments: {
attachment1: {
digest: 'digest',
content_type: 'text/plain',
revpos: 1,
length: 4,
stub: true,
uuid1: {
revisions: [
{
_id: 'uuid1',
_rev: '1-db302401f0df79e06b79f10f79c1f0f9',
$id: 'uuid1',
$type: 'entry',
$content: {},
$modificationDate: 0,
$creationDate: 0,
$lastModification: 'test@test.com',
$kind: 'kind',
$owners: ['test@test.com'],
_attachments: {
attachment1: {
digest: 'digest',
content_type: 'text/plain',
revpos: 1,
length: 4,
stub: true,
},
},
},
],
rights: {
read: true,
write: false,
},
],
},
},

@@ -30,0 +36,0 @@ attachments: {

@@ -61,3 +61,3 @@ import { randomBytes } from 'crypto';

async fetch(rev) {
const revs = this.roc.data.documents[this.uuid];
const revs = this.roc.data.documents[this.uuid].revisions;
if (!revs) {

@@ -84,3 +84,4 @@ throw new RocHTTPError(404, 'document not found');

for (const attachment of deleteAttachments) {
const att = this.roc.data.documents[this.uuid][0]._attachments;
const att = this.roc.data.documents[this.uuid].revisions[0]
._attachments;
if (!att || !att[attachment]) {

@@ -122,3 +123,3 @@ throw new RocClientError('attachment to delete does not exist');

};
this.roc.data.documents[this.uuid].push(newDocument);
this.roc.data.documents[this.uuid].revisions.push(newDocument);
this.value = newDocument;

@@ -143,4 +144,10 @@ return newDocument;

}
async hasRight(right) {
if (this.value === undefined) {
await this.fetch();
}
return Boolean(this.roc.data.documents[this.uuid].rights[right]);
}
getBaseUrl() {
return `https://${this.roc.fakeHost}/db/${this.roc.fakeDatabase}/entry/`;
return `https://${this.roc.fakeHost}/db/${this.roc.fakeDatabase}/entry/${this.uuid}/`;
}

@@ -161,3 +168,3 @@ saveAttachment(uuid, name, data) {

function getNewRevisionMeta(oldRev) {
const revMatch = oldRev.match(/^(\d+)/);
const revMatch = /^(\d+)/.exec(oldRev);
let oldInc;

@@ -184,5 +191,7 @@ if (!revMatch) {

}
// @ts-ignore
getDocument(uuid) {
return new FakeDocument(this, uuid);
}
// @ts-ignore
getQuery(viewName, options = {}) {

@@ -194,2 +203,3 @@ return new FakeQuery(this, viewName, options);

}
// @ts-ignore
async create(newDocument) {

@@ -210,5 +220,8 @@ const uuid = randomBytes(16).toString('hex');

if (!this.data.documents[uuid]) {
this.data.documents[uuid] = [];
this.data.documents[uuid] = {
revisions: [],
rights: {},
};
}
this.data.documents[uuid].push(document);
this.data.documents[uuid].revisions.push(document);
return new FakeDocument(this, document);

@@ -215,0 +228,0 @@ }

@@ -50,2 +50,6 @@ import BaseRocDocument from '../base/BaseRocDocument';

}
async hasRight(right) {
const response = await this.request.get(`_rights/${right}`);
return response.data;
}
getBaseUrl() {

@@ -52,0 +56,0 @@ return this.request.defaults.baseURL || '';

@@ -7,6 +7,6 @@ import { ICouchUser, INewDocument, IQueryOptions, IReduceQueryOptions } from '../types';

abstract getUser(): Promise<ICouchUser>;
abstract getDocument(uuid: string): BaseRocDocument;
abstract getQuery<KeyType = any, ValueType = any>(viewName: string, options?: IQueryOptions): BaseRocQuery<KeyType, ValueType>;
abstract getDocument<ContentType = Record<string, any>>(uuid: string): BaseRocDocument<ContentType>;
abstract getQuery<KeyType = any, ValueType = any, ContentType = Record<string, any>>(viewName: string, options?: IQueryOptions): BaseRocQuery<KeyType, ValueType, ContentType>;
abstract getReduceQuery<KeyType = any, ValueType = any>(viewName: string, options?: IReduceQueryOptions): BaseRocReduceQuery<KeyType, ValueType>;
abstract create(newDocument: INewDocument): Promise<BaseRocDocument>;
abstract create<ContentType = Record<string, any>>(newDocument: INewDocument<ContentType>): Promise<BaseRocDocument<ContentType>>;
}
/// <reference types="node" />
import { IAttachment, IDocument, IFetchAttachmentOptions, INewAttachment } from '../types';
export default abstract class BaseRocDocument {
export default abstract class BaseRocDocument<ContentType = Record<string, any>> {
uuid: string;
rev?: string;
protected value?: IDocument;
protected value?: IDocument<ContentType>;
constructor(uuid: string);

@@ -11,8 +11,9 @@ getAttachmentList(): IAttachment[];

abstract fetchAttachment(name: string, options?: IFetchAttachmentOptions): Promise<Buffer | string>;
abstract fetch(rev?: string): Promise<IDocument>;
abstract update(content: Record<string, any>, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument>;
abstract fetch(rev?: string): Promise<IDocument<ContentType>>;
abstract update(content: ContentType, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument<ContentType>>;
abstract addGroups(groups: string | string[]): Promise<string[]>;
getValue(): IDocument;
toJSON(): IDocument;
abstract hasRight(right: string): Promise<boolean>;
getValue(): IDocument<ContentType>;
toJSON(): IDocument<ContentType>;
protected abstract getBaseUrl(): string;
}

@@ -33,3 +33,3 @@ "use strict";

name,
url: `${this.getBaseUrl()}${doc._id}/${name}`,
url: `${this.getBaseUrl()}${name}`,
};

@@ -36,0 +36,0 @@ }

import { IQueryOptions, IQueryResult, PromisedQueryResult } from '../types';
export default abstract class BaseRocQuery<KeyType = any, ValueType = any> {
export default abstract class BaseRocQuery<KeyType = any, ValueType = any, ContentType = Record<string, any>> {
readonly viewName: string;
protected baseOptions: IQueryOptions;
constructor(viewName: string, options: IQueryOptions);
then(resolve: (value: Array<IQueryResult<KeyType, ValueType>>) => void, reject: (error: Error) => void): void;
abstract fetch(options?: IQueryOptions): PromisedQueryResult<KeyType, ValueType>;
then(resolve: (value: Array<IQueryResult<KeyType, ValueType, ContentType>>) => void, reject: (error: Error) => void): void;
abstract fetch(options?: IQueryOptions): PromisedQueryResult<KeyType, ValueType, ContentType>;
}

@@ -8,25 +8,31 @@ "use strict";

documents: {
uuid1: [
{
_id: 'uuid1',
_rev: '1-db302401f0df79e06b79f10f79c1f0f9',
$id: 'uuid1',
$type: 'entry',
$content: {},
$modificationDate: 0,
$creationDate: 0,
$lastModification: 'test@test.com',
$kind: 'kind',
$owners: ['test@test.com'],
_attachments: {
attachment1: {
digest: 'digest',
content_type: 'text/plain',
revpos: 1,
length: 4,
stub: true,
uuid1: {
revisions: [
{
_id: 'uuid1',
_rev: '1-db302401f0df79e06b79f10f79c1f0f9',
$id: 'uuid1',
$type: 'entry',
$content: {},
$modificationDate: 0,
$creationDate: 0,
$lastModification: 'test@test.com',
$kind: 'kind',
$owners: ['test@test.com'],
_attachments: {
attachment1: {
digest: 'digest',
content_type: 'text/plain',
revpos: 1,
length: 4,
stub: true,
},
},
},
],
rights: {
read: true,
write: false,
},
],
},
},

@@ -33,0 +39,0 @@ attachments: {

@@ -9,3 +9,8 @@ /// <reference types="node" />

documents: {
[key: string]: IDocument[];
[key: string]: {
revisions: IDocument[];
rights: {
[key: string]: boolean;
};
};
};

@@ -18,3 +23,3 @@ attachments: {

query: {
[key: string]: IQueryResult[];
[key: string]: IQueryResult<any, any, Record<string, any>>[];
};

@@ -25,6 +30,6 @@ reducer?: {

}
export declare class FakeQuery<A, B> extends BaseRocQuery {
export declare class FakeQuery<A, B> extends BaseRocQuery<A, B, Record<string, any>> {
protected roc: FakeRoc;
constructor(roc: FakeRoc, viewName: string, baseOptions: IQueryOptions);
fetch(): Promise<Array<IQueryResult<A, B>>>;
fetch(): Promise<Array<IQueryResult<A, B, Record<string, any>>>>;
}

@@ -40,5 +45,6 @@ export declare class FakeReduceQuery<A, B> extends BaseRocReduceQuery {

fetchAttachment(name: string, options?: IFetchAttachmentOptions): Promise<string | Buffer>;
fetch(rev?: string): Promise<IDocument>;
update(content: Record<string, any>, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument>;
fetch(rev?: string): Promise<IDocument<Record<string, any>>>;
update(content: Record<string, any>, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument<Record<string, any>>>;
addGroups(groups: string | string[]): Promise<string[]>;
hasRight(right: string): Promise<boolean>;
protected getBaseUrl(): string;

@@ -45,0 +51,0 @@ private saveAttachment;

@@ -66,3 +66,3 @@ "use strict";

async fetch(rev) {
const revs = this.roc.data.documents[this.uuid];
const revs = this.roc.data.documents[this.uuid].revisions;
if (!revs) {

@@ -89,3 +89,4 @@ throw new Error_1.RocHTTPError(404, 'document not found');

for (const attachment of deleteAttachments) {
const att = this.roc.data.documents[this.uuid][0]._attachments;
const att = this.roc.data.documents[this.uuid].revisions[0]
._attachments;
if (!att || !att[attachment]) {

@@ -127,3 +128,3 @@ throw new Error_1.RocClientError('attachment to delete does not exist');

};
this.roc.data.documents[this.uuid].push(newDocument);
this.roc.data.documents[this.uuid].revisions.push(newDocument);
this.value = newDocument;

@@ -148,4 +149,10 @@ return newDocument;

}
async hasRight(right) {
if (this.value === undefined) {
await this.fetch();
}
return Boolean(this.roc.data.documents[this.uuid].rights[right]);
}
getBaseUrl() {
return `https://${this.roc.fakeHost}/db/${this.roc.fakeDatabase}/entry/`;
return `https://${this.roc.fakeHost}/db/${this.roc.fakeDatabase}/entry/${this.uuid}/`;
}

@@ -167,3 +174,3 @@ saveAttachment(uuid, name, data) {

function getNewRevisionMeta(oldRev) {
const revMatch = oldRev.match(/^(\d+)/);
const revMatch = /^(\d+)/.exec(oldRev);
let oldInc;

@@ -190,5 +197,7 @@ if (!revMatch) {

}
// @ts-ignore
getDocument(uuid) {
return new FakeDocument(this, uuid);
}
// @ts-ignore
getQuery(viewName, options = {}) {

@@ -200,2 +209,3 @@ return new FakeQuery(this, viewName, options);

}
// @ts-ignore
async create(newDocument) {

@@ -216,5 +226,8 @@ const uuid = crypto_1.randomBytes(16).toString('hex');

if (!this.data.documents[uuid]) {
this.data.documents[uuid] = [];
this.data.documents[uuid] = {
revisions: [],
rights: {},
};
}
this.data.documents[uuid].push(document);
this.data.documents[uuid].revisions.push(document);
return new FakeDocument(this, document);

@@ -221,0 +234,0 @@ }

import { AxiosInstance } from 'axios';
import BaseRocQuery from '../base/BaseRocQuery';
import { IQueryOptions, PromisedQueryResult } from '../types';
export default class Query<A, B> extends BaseRocQuery {
export default class Query<A, B, ContentType> extends BaseRocQuery<A, B, ContentType> {
private request;
constructor(viewName: string, options: IQueryOptions, request: AxiosInstance);
fetch(options?: IQueryOptions): PromisedQueryResult<A, B>;
fetch(options?: IQueryOptions): PromisedQueryResult<A, B, ContentType>;
}

@@ -17,7 +17,7 @@ import { BaseRocReduceQuery } from '../base';

constructor(config: IRocConfig);
create(newDocument: INewDocument): Promise<BaseRocDocument>;
getDocument(uuid: string): RocDocument;
getQuery<KeyType = any, ValueType = any>(viewName: string, options?: IQueryOptions): BaseRocQuery<KeyType, ValueType>;
create<ContentType>(newDocument: INewDocument<ContentType>): Promise<BaseRocDocument<ContentType>>;
getDocument<ContentType = Record<string, any>>(uuid: string): RocDocument<ContentType>;
getQuery<KeyType = any, ValueType = any, ContentType = Record<string, any>>(viewName: string, options?: IQueryOptions): BaseRocQuery<KeyType, ValueType, ContentType>;
getReduceQuery<KeyType = any, ValueType = any>(viewName: string, options?: IReduceQueryOptions): BaseRocReduceQuery<KeyType, ValueType>;
getUser(): Promise<ICouchUser>;
}

@@ -5,11 +5,12 @@ /// <reference types="node" />

import { IDocument, IFetchAttachmentOptions, INewAttachment } from '../types';
export default class RocDocument extends BaseRocDocument {
export default class RocDocument<ContentType = Record<string, any>> extends BaseRocDocument<ContentType> {
private request;
constructor(uuid: string, request: AxiosInstance);
fetchAttachment(name: string, options?: IFetchAttachmentOptions): Promise<Buffer | string>;
fetch(rev?: string): Promise<IDocument>;
update(content: Record<string, any>, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument>;
fetch(rev?: string): Promise<IDocument<ContentType>>;
update(content: ContentType, newAttachments?: INewAttachment[], deleteAttachments?: string[]): Promise<IDocument<ContentType>>;
addGroups(): Promise<string[]>;
hasRight(right: string): Promise<any>;
protected getBaseUrl(): string;
private _fetchIfUnfetched;
}

@@ -52,2 +52,6 @@ "use strict";

}
async hasRight(right) {
const response = await this.request.get(`_rights/${right}`);
return response.data;
}
getBaseUrl() {

@@ -54,0 +58,0 @@ return this.request.defaults.baseURL || '';

import { IDocumentDraft, INewAttachment } from '../types';
export declare function addInlineUploads(entry: IDocumentDraft, attachments: INewAttachment[]): Promise<IDocumentDraft>;
export declare function deleteInlineUploads(entry: IDocumentDraft, attachmentNames: string[]): IDocumentDraft;
export declare function addInlineUploads<ContentType>(entry: IDocumentDraft<ContentType>, attachments: INewAttachment[]): Promise<IDocumentDraft<ContentType>>;
export declare function deleteInlineUploads<ContentType>(entry: IDocumentDraft<ContentType>, attachmentNames: string[]): IDocumentDraft<ContentType>;

@@ -13,5 +13,5 @@ /// <reference types="node" />

}
export interface INewDocument {
export interface INewDocument<ContentType = Record<string, any>> {
$id: any;
$content: Record<string, any>;
$content: ContentType;
$kind: string;

@@ -24,3 +24,3 @@ $owners: string[];

}
export interface IBaseDocument extends INewDocument, INewRevisionMeta {
export interface IBaseDocument<ContentType = Record<string, any>> extends INewDocument<ContentType>, INewRevisionMeta {
_id: string;

@@ -31,3 +31,3 @@ $type: 'entry' | 'group';

}
export interface IDocument extends IBaseDocument {
export interface IDocument<ContentType = Record<string, any>> extends IBaseDocument<ContentType> {
_attachments: {

@@ -37,3 +37,3 @@ [key: string]: ICouchAttachmentStub;

}
export interface IDocumentDraft extends IBaseDocument {
export interface IDocumentDraft<ContentType = Record<string, any>> extends IBaseDocument<ContentType> {
_attachments: {

@@ -90,6 +90,6 @@ [key: string]: ICouchAttachment | ICouchInlineAttachment;

}
export interface IQueryResult<KeyType = any, ValueType = any> {
export interface IQueryResult<KeyType = any, ValueType = any, ContentType = Record<string, any>> {
id: string;
key: KeyType;
doc?: IDocument;
doc?: IDocument<ContentType>;
value: ValueType;

@@ -101,3 +101,3 @@ }

}
export declare type PromisedQueryResult<KeyType, ValueType> = Promise<Array<IQueryResult<KeyType, ValueType>>>;
export declare type PromisedQueryResult<KeyType, ValueType, ContentType> = Promise<Array<IQueryResult<KeyType, ValueType, ContentType>>>;
export declare type PromisedReduceQueryResult<KeyType, ValueType> = Promise<Array<IReduceQueryResult<KeyType, ValueType>>>;

@@ -104,0 +104,0 @@ export interface ICouchUser {

{
"name": "rest-on-couch-client",
"version": "2.2.4",
"version": "2.3.0",
"description": "A nodejs / browser client for rest-on-couch backend",

@@ -13,2 +13,3 @@ "main": "./lib/index.js",

"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-es6",

@@ -18,3 +19,3 @@ "eslint": "eslint src --ext ts",

"prepare": "npm run tsc",
"test": "npm run test-only && npm run eslint",
"test": "npm run test-coverage && npm run eslint && npm run check-types",
"test-only": "jest",

@@ -42,15 +43,15 @@ "test-coverage": "jest --coverage",

"devDependencies": {
"@types/jest": "^26.0.13",
"eslint": "^7.9.0",
"eslint-config-cheminfo-typescript": "^7.0.0",
"jest": "^26.4.2",
"prettier": "^2.1.1",
"@types/jest": "^26.0.16",
"eslint": "^7.14.0",
"eslint-config-cheminfo-typescript": "^8.0.5",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"ts-jest": "^26.3.0",
"typescript": "^4.0.2"
"ts-jest": "^26.4.4",
"typescript": "^4.1.2"
},
"dependencies": {
"@types/node": "^14.10.1",
"axios": "^0.20.0",
"immer": "^7.0.9"
"@types/node": "^14.14.10",
"axios": "^0.21.0",
"immer": "^8.0.0"
},

@@ -57,0 +58,0 @@ "prettier": {

# rest-on-couch-client
Rest-on-couch client for Node.js
[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![npm download][download-image]][download-url]
Rest-on-couch client for Node.js and browsers.
## License
[MIT](./LICENSE)
[npm-image]: https://img.shields.io/npm/v/rest-on-couch-client.svg
[npm-url]: https://npmjs.org/package/rest-on-couch-client
[ci-image]: https://github.com/cheminfo/rest-on-couch-client/workflows/Node.js%20CI/badge.svg?branch=master
[ci-url]: https://github.com/cheminfo/rest-on-couch-client/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/rest-on-couch-client.svg
[download-url]: https://npmjs.org/package/rest-on-couch-client

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc