Skip to content

Commit

Permalink
Merge 3b1d2f2 into e2482b7
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley committed Apr 22, 2020
2 parents e2482b7 + 3b1d2f2 commit 0104e7c
Show file tree
Hide file tree
Showing 22 changed files with 1,682 additions and 975 deletions.
13 changes: 11 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@
"curly": 2,
"linebreak-style": [2, "unix"],
"no-console": 0,
"no-unused-vars": [2, { "vars": "all", "args": "none" }],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": [
"error",
{
"vars": "all",
"args": "none",
"ignoreRestSiblings": false
}
],
"no-var": 2,
"prefer-const": 1,
"semi": [2, "always"]
Expand All @@ -20,5 +28,6 @@
"node": true
},
"extends": ["prettier/@typescript-eslint"],
"root": true
"root": true,
"plugins": ["@typescript-eslint/eslint-plugin"]
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text eol=lf
*.png -text
66 changes: 55 additions & 11 deletions package-lock.json

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

11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"dist": "cross-env NODE_ENV=production rollup -c && npm run dist:fx",
"dist:dev": "rollup -c && npm run dist:fx",
"dist:fx": "ts-node --skip-project bin/dist-fx.ts",
"lint": "eslint src test",
"lint": "eslint \"src/**/*.{js,ts}\" \"test/**/*.{js,ts}\"",
"publish-demo": "npm run dist-prod && cp dist/kinto.js demo/kinto.js && gh-pages -d demo",
"publish-to-npm": "npm run dist && npm run build && npm publish",
"report-coverage": "npm run test-cover && ./node_modules/coveralls/bin/coveralls.js < ./coverage/lcov.info",
Expand Down Expand Up @@ -135,13 +135,20 @@
},
"dependencies": {
"btoa": "^1.1.2",
"kinto-http": "^5.0.0-alpha.2",
"kinto-http": "^5.0.0-alpha.3",
"uuid": "^7.0.0"
},
"devDependencies": {
"@types/btoa": "^1.2.3",
"@types/chai": "^4.2.7",
"@types/chai-as-promised": "^7.1.2",
"@types/mocha": "^5.2.7",
"@types/shelljs": "^0.8.6",
"@types/sinon": "^7.5.1",
"@types/uuid": "^3.4.6",
"@typescript-eslint/eslint-plugin": "^2.2.0",
"@typescript-eslint/parser": "^2.2.0",
"atob": "^2.1.2",
"chai": "^4.0.1",
"chai-as-promised": "^7.0.0",
"co-task": "^1.0.0",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function ignoreInput(list) {
}

const geckoBuild = {
input: "./src/index.fx.js",
input: "./src/index.fx.ts",
output: [
{
file: "dist/temp.js",
Expand All @@ -36,7 +36,7 @@ const geckoBuild = {
};

const browserBuild = {
input: "./src/index.js",
input: "./src/index.ts",
output: [
{
file: "dist/kinto.min.js",
Expand Down
42 changes: 36 additions & 6 deletions src/KintoBase.js → src/KintoBase.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,33 @@
"use strict";

import { EventEmitter } from "events";
import Api from "kinto-http";
import Collection from "./collection";
import BaseAdapter from "./adapters/base";
import IDB from "./adapters/IDB";
import { IdSchema, RemoteTransformer, Hooks } from "./types";

const DEFAULT_BUCKET_NAME = "default";
const DEFAULT_REMOTE = "http://localhost:8888/v1";
const DEFAULT_RETRY = 1;

export interface KintoBaseOptions {
remote?: string;
bucket?: string;
events?: EventEmitter;
adapter?: typeof IDB;
adapterOptions?: object;
headers?: Record<string, string>;
retry?: number;
requestMode?: RequestMode;
timeout?: number;
}

/**
* KintoBase class.
*/
export default class KintoBase {
private _options: KintoBaseOptions;
private _api: Api | null;
public events?: EventEmitter;
/**
* Provides a public access to the base adapter class. Users can create a
* custom DB adapter by extending {@link BaseAdapter}.
Expand Down Expand Up @@ -52,7 +69,7 @@ export default class KintoBase {
*
* @param {Object} options The options object.
*/
constructor(options = {}) {
constructor(options: KintoBaseOptions = {}) {
const defaults = {
bucket: DEFAULT_BUCKET_NAME,
remote: DEFAULT_REMOTE,
Expand All @@ -71,6 +88,10 @@ export default class KintoBase {
this.events = this._options.events;
}

get ApiClass(): typeof Api {
throw new Error("ApiClass() must be implemented by subclasses.");
}

/**
* The kinto HTTP client instance.
* @type {KintoClient}
Expand All @@ -86,7 +107,7 @@ export default class KintoBase {
} = this._options;

if (!this._api) {
this._api = new this.ApiClass(remote, {
this._api = new this.ApiClass(remote!, {
events,
headers,
requestMode,
Expand All @@ -110,7 +131,16 @@ export default class KintoBase {
* @param {Object} [options.localFields] Array<Field> (default: `[]`])
* @return {Collection}
*/
collection(collName, options = {}) {
collection<T extends { id: string } = any>(
collName: string,
options: {
adapter?: typeof IDB;
idSchema?: IdSchema;
remoteTransformers?: RemoteTransformer[];
hooks?: Hooks<T>;
localFields?: string[];
} = {}
) {
if (!collName) {
throw new Error("missing collection name");
}
Expand All @@ -120,7 +150,7 @@ export default class KintoBase {
};
const { idSchema, remoteTransformers, hooks, localFields } = options;

return new Collection(bucket, collName, this, {
return new Collection<T>(bucket!, collName, this, {
events,
adapter,
adapterOptions,
Expand Down

0 comments on commit 0104e7c

Please sign in to comment.