Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore

This file was deleted.

34 changes: 0 additions & 34 deletions .eslintrc.yml

This file was deleted.

15 changes: 9 additions & 6 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
with:
node-version: 20.x
node-version: 22.x
- name: Install dependencies
run: npm install
- name: Run ESLint
run: npm run eslint
- name: Check types
run: npm run check-types
- name: Test package
uses: zakodium/test-package-action@v1
test:
services:
couchdb:
Expand Down Expand Up @@ -50,16 +52,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 22.x, 24.x]
node-version: [22.x, 24.x]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
uses: actions/setup-node@v6
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test-coverage
- name: Send coverage report to Codecov
if: ${{ matrix.node-version == '22.x' }}
uses: codecov/codecov-action@v5
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ build/Release
node_modules
jspm_packages

# Optional npm cache directory
# Cache
.npm
.eslintcache

# Optional REPL history
.node_repl_history

lib
lib-es6
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CHANGELOG.md
6 changes: 4 additions & 2 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ services:
COUCHDB_USER: admin
COUCHDB_PASSWORD: admin
ports:
- 5984:5984
- 127.0.0.1:5984:5984
rest-on-couch:
build: ./rest-on-couch
ports:
- 4000:4000
- 127.0.0.1:4000:4000
env_file:
- .env.test
depends_on:
- couchdb
43 changes: 43 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { defineConfig, globalIgnores } from 'eslint/config';
import ts from 'eslint-config-zakodium/ts';
import vitest from 'eslint-config-zakodium/vitest-ts';

export default defineConfig(
globalIgnores(['rest-on-couch/**', 'lib/**']),
ts,
vitest,
{
files: ['**/*.ts'],
rules: {
camelcase: 'off',
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/naming-convention': [
'error',
{ selector: ['typeLike'], format: ['PascalCase'] },
{ selector: ['variable'], format: ['camelCase', 'UPPER_CASE'] },
{ selector: ['function'], format: ['camelCase', 'PascalCase'] },
{
selector: [
'method',
'classProperty',
'classMethod',
'parameterProperty',
'accessor',
'typeProperty',
'typeMethod',
],
format: ['camelCase', 'snake_case'],
leadingUnderscore: 'allow',
},
{
selector: [
'objectLiteralProperty',
'objectLiteralMethod',
'enumMember',
],
format: null,
},
],
},
},
);
53 changes: 25 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@
"name": "rest-on-couch-client",
"version": "6.0.0",
"description": "A nodejs / browser client for rest-on-couch backend",
"main": "./lib/index.js",
"module": "./lib-es6/index.js",
"type": "module",
"exports": {
".": "./lib/index.js"
},
"types": "./lib/index.d.ts",
"files": [
"lib",
"lib-es6"
"lib"
],
"scripts": {
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-es6",
"eslint": "eslint src --ext ts",
"clean": "rimraf lib",
"eslint": "eslint . --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepare": "npm run tsc",
"prettier": "prettier --check .",
"prettier-write": "prettier --write .",
"test": "npm run test-coverage && npm run eslint && npm run check-types",
"test-only": "jest --runInBand",
"test-coverage": "jest --coverage --runInBand",
"test-watch": "jest --runInBand --watch",
"tsc": "npm run clean && npm run tsc-es5 && npm run tsc-es6",
"tsc-es5": "tsc",
"tsc-es6": "tsc --project tsconfig.es6.json"
"test-only": "vitest run",
"test-coverage": "vitest run --coverage",
"test-watch": "vitest",
"tsc": "npm run clean && tsc --project tsconfig.build.json"
},
"repository": {
"type": "git",
Expand All @@ -34,24 +35,20 @@
"url": "https://github.com/cheminfo/rest-on-couch-client/issues"
},
"homepage": "https://github.com/cheminfo/rest-on-couch-client#readme",
"jest": {
"preset": "ts-jest",
"testEnvironment": "node"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^18.17.1",
"eslint": "^8.13.0",
"eslint-config-zakodium": "^10.0.0",
"jest": "^30.0.4",
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
"ts-jest": "^29.4.0",
"typescript": "^5.8.3"
"@types/node": "^22.19.7",
"@vitest/coverage-v8": "^4.0.18",
"@zakodium/tsconfig": "^1.0.2",
"eslint": "^9.39.2",
"eslint-config-zakodium": "^19.1.0",
"prettier": "^3.8.1",
"rimraf": "^6.1.2",
"typescript": "^5.9.3",
"vitest": "^4.0.18"
},
"dependencies": {
"axios": "^1.10.0",
"immer": "^10.1.1"
"axios": "^1.13.3",
"immer": "^11.1.3"
},
"prettier": {
"arrowParens": "always",
Expand All @@ -61,6 +58,6 @@
"trailingComma": "all"
},
"volta": {
"node": "20.19.3"
"node": "22.22.0"
}
}
7 changes: 2 additions & 5 deletions rest-on-couch/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
FROM ghcr.io/cheminfo/rest-on-couch:15

# Install system packages
RUN apt-get update && apt-get install -y vim
FROM ghcr.io/cheminfo/rest-on-couch:19

# Copy ROC scripts
COPY wait.sh start.sh create_db.sh /
Expand All @@ -11,4 +8,4 @@ RUN chmod +x /wait.sh /start.sh /create_db.sh
COPY home /rest-on-couch/


CMD ["/start.sh"]
CMD ["/start.sh"]
1 change: 1 addition & 0 deletions rest-on-couch/home/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
username: 'rest-on-couch',
superAdministrators: ['admin@goodyear.com'],
password: process.env.COUCHDB_ROC_SERVER_PASSWORD,
adminPassword: process.env.COUCHDB_ROC_ADMIN_PASSWORD,
logLevel: 'TRACE',
// Make sure logged audit actions get the ip address from 'X-Forwarded-For' header
proxy: true,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './roc';
export * from './types';
export * from './helpers';
export * from './roc/index.ts';
export * from './types.ts';
export * from './helpers.ts';
7 changes: 3 additions & 4 deletions src/roc/Find.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { AxiosInstance } from 'axios';
import type { AxiosInstance } from 'axios';

import {
import type {
IFindOptions,
IFindQueryResult,
PromisedFindQueryResult,
RocAxiosRequestOptions,
} from '../types';
} from '../types.ts';

export default class Find<ResultType> {
public readonly viewName: string;
protected baseOptions: IFindOptions;
private request: AxiosInstance;
public constructor(options: IFindOptions, request: AxiosInstance) {
Expand Down
8 changes: 4 additions & 4 deletions src/roc/Query.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { AxiosInstance } from 'axios';
import type { AxiosInstance } from 'axios';

import { IQueryResult } from '..';
import {
import type { IQueryResult } from '../index.ts';
import type {
IQueryOptions,
PromisedQueryResult,
RocAxiosRequestOptions,
} from '../types';
} from '../types.ts';

export default class Query<KeyType, ValueType, ContentType> {
public readonly viewName: string;
Expand Down
8 changes: 4 additions & 4 deletions src/roc/ReduceQuery.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AxiosInstance } from 'axios';
import type { AxiosInstance } from 'axios';

import { IReduceQueryResult } from '..';
import {
import type { IReduceQueryResult } from '../index.ts';
import type {
IReduceQueryOptions,
IRocReduceQueryParams,
PromisedReduceQueryResult,
RocAxiosRequestOptions,
} from '../types';
} from '../types.ts';

export default class ReduceQuery<KeyType = unknown, ValueType = unknown> {
public readonly viewName: string;
Expand Down
22 changes: 12 additions & 10 deletions src/roc/Roc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import axios, { AxiosInstance } from 'axios';
import type { AxiosInstance } from 'axios';
import axios from 'axios';

import { ICouchGroupInfo, IEntryDocument } from '..';
import {
import type { ICouchGroupInfo, IEntryDocument } from '../index.ts';
import type {
ICouchUser,
ICouchUserGroup,
IFindOptions,
Expand All @@ -12,13 +13,14 @@ import {
IViewOptions,
Ok,
RocAxiosRequestOptions,
} from '../types';

import Find from './Find';
import Query from './Query';
import ReduceQuery from './ReduceQuery';
import RocDocument, { RocDocumentOptions } from './RocDocument';
import View from './View';
} from '../types.ts';

import Find from './Find.ts';
import Query from './Query.ts';
import ReduceQuery from './ReduceQuery.ts';
import type { RocDocumentOptions } from './RocDocument.ts';
import RocDocument from './RocDocument.ts';
import View from './View.ts';

export interface IRocConfig {
url: string;
Expand Down
16 changes: 9 additions & 7 deletions src/roc/RocDocument.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { AxiosInstance } from 'axios';
import type { AxiosInstance } from 'axios';

import { FetchAttachmentType, IAttachment } from '..';
import { RocClientError } from '../Error';
import {
import { RocClientError } from '../Error.ts';
import type { FetchAttachmentType, IAttachment } from '../index.ts';
import type {
IEntryDocument,
IEntryDocumentDraft,
INewAttachment,
RocAxiosRequestOptions,
} from '../types';
} from '../types.ts';
import { assert } from '../util/assert.ts';

import { addInlineUploads, deleteInlineUploads } from './utils';
import { addInlineUploads, deleteInlineUploads } from './utils.ts';

export interface RocDocumentOptions {
allowAttachmentOverwrite: boolean;
Expand Down Expand Up @@ -78,13 +79,14 @@ export default class RocDocument<
deleteAttachments?: string[],
axiosOptions?: RocAxiosRequestOptions,
): Promise<IEntryDocument<ContentType, IdType>> {
if (typeof content === 'object' && '_id' in content) {
if (content && typeof content === 'object' && '_id' in content) {
throw new Error(
'Your content contains an _id proprerty. This is probably an error since you should not pass the entire document, only $content',
);
}

await this._fetchIfUnfetched();
assert(this.value, 'Unreachable: fetched value is undefined');
let newDoc: IEntryDocumentDraft<ContentType, IdType> = {
...this.value,
$content: content,
Expand Down
Loading