rest-on-couch-client
Advanced tools
Comparing version 3.2.0 to 3.3.0
# Changelog | ||
## [3.3.0](https://www.github.com/cheminfo/rest-on-couch-client/compare/v3.2.0...v3.3.0) (2021-08-30) | ||
### Features | ||
* add getView to Roc ([43b560f](https://www.github.com/cheminfo/rest-on-couch-client/commit/43b560f00301415b30b1fc12e095a6b6f5ac18bf)), closes [#14](https://www.github.com/cheminfo/rest-on-couch-client/issues/14) | ||
## [3.2.0](https://www.github.com/cheminfo/rest-on-couch-client/compare/v3.1.0...v3.2.0) (2021-08-25) | ||
@@ -4,0 +11,0 @@ |
@@ -29,2 +29,15 @@ import { RocClientError, RocHTTPError } from '../Error'; | ||
} | ||
export class FakeView { | ||
roc; | ||
options; | ||
viewName; | ||
constructor(roc, viewName, options) { | ||
this.viewName = viewName; | ||
this.options = options; | ||
this.roc = roc; | ||
} | ||
async fetch() { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
export class FakeDocument extends BaseRocDocument { | ||
@@ -86,4 +99,3 @@ roc; | ||
for (const attachment of deleteAttachments) { | ||
const att = this.roc.data.documents[this.uuid].revisions[0] | ||
._attachments; | ||
const att = this.roc.data.documents[this.uuid].revisions[0]._attachments; | ||
if (!att || !att[attachment]) { | ||
@@ -201,2 +213,5 @@ throw new RocClientError('attachment to delete does not exist'); | ||
} | ||
getView(viewName, options = {}) { | ||
return new FakeView(this, viewName, options); | ||
} | ||
getReduceQuery(viewName) { | ||
@@ -203,0 +218,0 @@ return new FakeReduceQuery(this, viewName); |
@@ -6,2 +6,3 @@ import axios from 'axios'; | ||
import RocDocument from './RocDocument'; | ||
import View from './View'; | ||
function createAxios(url, accessToken) { | ||
@@ -64,2 +65,5 @@ return axios.create({ | ||
} | ||
getView(viewName, options = {}) { | ||
return new View(viewName, options, createAxios(new URL(`_view/${viewName}`, this.dbUrl).href, this.accessToken)); | ||
} | ||
async getUser() { | ||
@@ -66,0 +70,0 @@ const response = await this.request.get('auth/session'); |
@@ -6,3 +6,3 @@ /// <reference types="node" /> | ||
import BaseRocQuery from '../base/BaseRocQuery'; | ||
import { IDocument, IFetchAttachmentOptions, INewAttachment, INewDocument, IQueryOptions, IQueryResult, IReduceQueryResult } from '../types'; | ||
import { IDocument, IFetchAttachmentOptions, INewAttachment, INewDocument, IQueryOptions, IQueryResult, IReduceQueryResult, IViewOptions, IViewResult } from '../types'; | ||
export interface IFakeRocData { | ||
@@ -39,2 +39,9 @@ documents: { | ||
} | ||
export declare class FakeView<ContentType = any> { | ||
protected roc: FakeRoc; | ||
protected options: IViewOptions; | ||
readonly viewName: string; | ||
constructor(roc: FakeRoc, viewName: string, options: IViewOptions); | ||
fetch(): Promise<IViewResult<ContentType>>; | ||
} | ||
export declare class FakeDocument extends BaseRocDocument { | ||
@@ -59,2 +66,3 @@ protected roc: FakeRoc; | ||
getQuery<KeyType = any, ValueType = any>(viewName: string, options?: IQueryOptions): FakeQuery<KeyType, ValueType>; | ||
getView<ContentType = any>(viewName: string, options?: IViewOptions): FakeView<ContentType>; | ||
getReduceQuery<KeyType = any, ValueType = any>(viewName: string): FakeReduceQuery<KeyType, ValueType>; | ||
@@ -61,0 +69,0 @@ create(newDocument: INewDocument): Promise<FakeDocument>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FakeRoc = exports.FakeDocument = exports.FakeReduceQuery = exports.FakeQuery = void 0; | ||
exports.FakeRoc = exports.FakeDocument = exports.FakeView = exports.FakeReduceQuery = exports.FakeQuery = void 0; | ||
const Error_1 = require("../Error"); | ||
@@ -34,2 +34,16 @@ const base_1 = require("../base"); | ||
exports.FakeReduceQuery = FakeReduceQuery; | ||
class FakeView { | ||
roc; | ||
options; | ||
viewName; | ||
constructor(roc, viewName, options) { | ||
this.viewName = viewName; | ||
this.options = options; | ||
this.roc = roc; | ||
} | ||
async fetch() { | ||
throw new Error('not implemented'); | ||
} | ||
} | ||
exports.FakeView = FakeView; | ||
class FakeDocument extends BaseRocDocument_1.default { | ||
@@ -91,4 +105,3 @@ roc; | ||
for (const attachment of deleteAttachments) { | ||
const att = this.roc.data.documents[this.uuid].revisions[0] | ||
._attachments; | ||
const att = this.roc.data.documents[this.uuid].revisions[0]._attachments; | ||
if (!att || !att[attachment]) { | ||
@@ -207,2 +220,5 @@ throw new Error_1.RocClientError('attachment to delete does not exist'); | ||
} | ||
getView(viewName, options = {}) { | ||
return new FakeView(this, viewName, options); | ||
} | ||
getReduceQuery(viewName) { | ||
@@ -209,0 +225,0 @@ return new FakeReduceQuery(this, viewName); |
@@ -5,4 +5,5 @@ import { BaseRocReduceQuery } from '../base'; | ||
import BaseRocQuery from '../base/BaseRocQuery'; | ||
import { ICouchUser, ICouchUserGroup, INewDocument, IQueryOptions, IReduceQueryOptions } from '../types'; | ||
import { ICouchUser, ICouchUserGroup, INewDocument, IQueryOptions, IReduceQueryOptions, IViewOptions } from '../types'; | ||
import RocDocument from './RocDocument'; | ||
import View from './View'; | ||
export interface IRocConfig { | ||
@@ -24,4 +25,5 @@ url: string; | ||
getReduceQuery<KeyType = any, ValueType = any>(viewName: string, options?: IReduceQueryOptions): BaseRocReduceQuery<KeyType, ValueType>; | ||
getView<KeyType = any, ContentType = any>(viewName: string, options?: IViewOptions<KeyType>): View<ContentType>; | ||
getUser(): Promise<ICouchUser>; | ||
getUserGroups(): Promise<ICouchUserGroup[]>; | ||
} |
@@ -8,2 +8,3 @@ "use strict"; | ||
const RocDocument_1 = require("./RocDocument"); | ||
const View_1 = require("./View"); | ||
function createAxios(url, accessToken) { | ||
@@ -66,2 +67,5 @@ return axios_1.default.create({ | ||
} | ||
getView(viewName, options = {}) { | ||
return new View_1.default(viewName, options, createAxios(new URL(`_view/${viewName}`, this.dbUrl).href, this.accessToken)); | ||
} | ||
async getUser() { | ||
@@ -68,0 +72,0 @@ const response = await this.request.get('auth/session'); |
@@ -37,6 +37,6 @@ "use strict"; | ||
if (deleteAttachments !== undefined) { | ||
newDoc = utils_1.deleteInlineUploads(newDoc, deleteAttachments); | ||
newDoc = (0, utils_1.deleteInlineUploads)(newDoc, deleteAttachments); | ||
} | ||
if (newAttachments !== undefined) { | ||
newDoc = await utils_1.addInlineUploads(newDoc, newAttachments); | ||
newDoc = await (0, utils_1.addInlineUploads)(newDoc, newAttachments); | ||
} | ||
@@ -43,0 +43,0 @@ // Send the new doc |
@@ -15,3 +15,3 @@ "use strict"; | ||
})); | ||
const newEntry = immer_1.produce(entry, (draft) => { | ||
const newEntry = (0, immer_1.produce)(entry, (draft) => { | ||
for (let i = 0; i < attachments.length; i++) { | ||
@@ -29,3 +29,3 @@ const newAttachment = { | ||
function deleteInlineUploads(entry, attachmentNames) { | ||
return immer_1.produce(entry, (draft) => { | ||
return (0, immer_1.produce)(entry, (draft) => { | ||
for (const name of attachmentNames) { | ||
@@ -32,0 +32,0 @@ delete draft._attachments[name]; |
@@ -70,12 +70,12 @@ /// <reference types="node" /> | ||
} | ||
export interface ICouchViewBase { | ||
startKey?: any; | ||
endKey?: any; | ||
key?: any; | ||
export interface ICouchViewBase<KeyType> { | ||
startKey?: KeyType; | ||
endKey?: KeyType; | ||
key?: KeyType; | ||
} | ||
export interface IQueryOptions extends ICouchViewBase { | ||
export interface IQueryOptions<KeyType = any> extends ICouchViewBase<KeyType> { | ||
mine?: boolean; | ||
include_docs?: boolean; | ||
} | ||
export interface IReduceQueryOptions extends ICouchViewBase { | ||
export interface IReduceQueryOptions<KeyType = any> extends ICouchViewBase<KeyType> { | ||
group?: boolean; | ||
@@ -93,2 +93,11 @@ groupLevel?: number; | ||
} | ||
export declare type IViewResult<ContentType = Record<string, any>> = Array<IDocument<ContentType>>; | ||
export interface IViewOptions<KeyType = any> { | ||
limit?: number; | ||
descending?: boolean; | ||
attachments?: boolean; | ||
key?: KeyType; | ||
startKey?: KeyType; | ||
endKey?: KeyType; | ||
} | ||
export interface IReduceQueryResult<KeyType = any, ValueType = any> { | ||
@@ -95,0 +104,0 @@ key: KeyType; |
{ | ||
"name": "rest-on-couch-client", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "A nodejs / browser client for rest-on-couch backend", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
226328
58
5085