Skip to content

Commit

Permalink
0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jmdobry committed Apr 28, 2016
1 parent 6e4f348 commit 8a6924d
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
typings
node_modules
coverage
doc
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
##### 0.5.0 - 27 April 2016

###### Breaking changes
- `dist/js-data-adapter.d.ts` is now is ES6 module format

###### Backwards compatible changes
- Added `typings` field to `package.json`
- Added `typings.json`

##### 0.4.0 - 27 April 2016

- Added Typescript definitions
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,20 @@ npm i --save js-data js-data-adapter
Now extend the adapter:

```js
import {Adapter} from 'js-data-adapter'
// ES6
class MyAdapter extends Adapter {}
```

```js
var Adapter = require('js-data-adapter').Adapter
// Use Adapter.extend
var MyAdapter = Adapter.extend()
```

```js
var Adapter = require('js-data-adapter').Adapter

// Manually extend
function MyAdapter (opts) {
Adapter.call(this, opts)
Expand Down
151 changes: 73 additions & 78 deletions dist/js-data-adapter.d.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,75 @@
declare module JSDataAdapter {
interface IDict {
[key: string]: any;
}
interface IAdapterOpts extends IDict {
debug?: boolean,
raw?: boolean
}
class Response implements IDict {
data?: any
op: string
}
export class Adapter {
static version: {
full?: string
minor?: string
major?: string
patch?: string
alpha?: string | boolean
beta?: string | boolean
}
static extend(instanceProps?: IDict, classProps?: IDict): typeof Adapter
static Response: typeof Response
static noop(...any): Promise<any>
static noop2(...any): Promise<any>
static unique(any[]): any[]
debug: boolean
raw: boolean
constructor(opts?: IAdapterOpts): Adapter
afterCount(mapper: Mapper, props: IDict, opts: IDict, response: IDict | Response): any
afterCreate(mapper: Mapper, props: IDict, opts: IDict, response: IDict | Response): any
afterCreateMany(mapper: Mapper, props: IDict[], opts: IDict, response: IDict[] | Response): any
afterDestroy(mapper: Mapper, id: string | number, opts: IDict, response: void | Response): any
afterDestroyAll(mapper: Mapper, query: IDict, opts: IDict, response: void | Response): any
afterFind(mapper: Mapper, id: string | number, opts: IDict, response: IDict | Response): any
afterFindAll(mapper: Mapper, query: IDict, opts: IDict, response: IDict[] | Response): any
afterSum(mapper: Mapper, field: string, query: IDict, opts: IDict, response: number | Response): any
afterUpdate(mapper: Mapper, id: string | number, props: IDict, opts: IDict, response: IDict | Response): any
afterUpdateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict, response: IDict[] | Response): any
afterUpdateMany(mapper: Mapper, props: IDict[], opts: IDict, response: IDict[] | Response): any
beforeCount(mapper: Mapper, props: IDict, opts: IDict): any
beforeCreate(mapper: Mapper, props: IDict, opts: IDict): any
beforeCreateMany(mapper: Mapper, props: IDict[], opts: IDict): any
beforeDestroy(mapper: Mapper, id: string | number, opts: IDict): any
beforeDestroyAll(mapper: Mapper, query: IDict, opts: IDict): any
beforeFind(mapper: Mapper, id: string | number, opts: IDict): any
beforeFindAll(mapper: Mapper, query: IDict, opts: IDict): any
beforeSum(mapper: Mapper, field: string, query: IDict, opts: IDict): any
beforeUpdate(mapper: Mapper, id: string | number, props: IDict, opts: IDict): any
beforeUpdateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict): any
beforeUpdateMany(mapper: Mapper, props: IDict[], opts: IDict): any
dbg(...args: any[]): void
count(mapper: Mapper, props: IDict, opts: IDict): any
create(mapper: Mapper, props: IDict, opts: IDict): any
createMany(mapper: Mapper, props: IDict[], opts: IDict): any
destroy(mapper: Mapper, id: string | number, opts: IDict): any
destroyAll(mapper: Mapper, query: IDict, opts: IDict): any
find(mapper: Mapper, id: string | number, opts: IDict): any
findAll(mapper: Mapper, query: IDict, opts: IDict): any
loadBelongsTo(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasMany(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasManyLocalKeys(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasManyForeignKeys(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasOne(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
log(level: string, ...args: any[]): void
makeBelongsToForeignKey(mapper: Mapper, def: IDict, record: IDict): string
makeHasManyForeignKey(mapper: Mapper, def: IDict, record: IDict): string
makeHasManyLocalKeys(mapper: Mapper, def, IDict, record: IDict): string
makeHasManyForeignKeys(mapper: Mapper, def, IDict, record: IDict): string
sum(mapper: Mapper, field: string, query: IDict, opts: IDict): any
respond(response: Response, opts: IDict): IDict | Response
update(mapper: Mapper, id: string | number, props: IDict, opts: IDict): any
updateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict): any
updateMany(mapper: Mapper, props: IDict[], opts: IDict): any
}
}
import {Mapper} from 'js-data'

declare module 'js-data-adapter' {
export = JSDataAdapter.Adapter
interface IDict {
[key: string]: any
}
interface IAdapterOpts extends IDict {
debug?: boolean
raw?: boolean
}
export class Response implements IDict {
data: any
op: string
}
export class Adapter {
static version: {
full?: string
minor?: string
major?: string
patch?: string
alpha?: string | boolean
beta?: string | boolean
}
static extend(instanceProps?: IDict, classProps?: IDict): typeof Adapter
debug: boolean
raw: boolean
constructor(opts?: IAdapterOpts)
afterCount(mapper: Mapper, props: IDict, opts: IDict, response: IDict | Response): any
afterCreate(mapper: Mapper, props: IDict, opts: IDict, response: IDict | Response): any
afterCreateMany(mapper: Mapper, props: IDict[], opts: IDict, response: IDict[] | Response): any
afterDestroy(mapper: Mapper, id: string | number, opts: IDict, response: void | Response): any
afterDestroyAll(mapper: Mapper, query: IDict, opts: IDict, response: void | Response): any
afterFind(mapper: Mapper, id: string | number, opts: IDict, response: IDict | Response): any
afterFindAll(mapper: Mapper, query: IDict, opts: IDict, response: IDict[] | Response): any
afterSum(mapper: Mapper, field: string, query: IDict, opts: IDict, response: number | Response): any
afterUpdate(mapper: Mapper, id: string | number, props: IDict, opts: IDict, response: IDict | Response): any
afterUpdateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict, response: IDict[] | Response): any
afterUpdateMany(mapper: Mapper, props: IDict[], opts: IDict, response: IDict[] | Response): any
beforeCount(mapper: Mapper, props: IDict, opts: IDict): any
beforeCreate(mapper: Mapper, props: IDict, opts: IDict): any
beforeCreateMany(mapper: Mapper, props: IDict[], opts: IDict): any
beforeDestroy(mapper: Mapper, id: string | number, opts: IDict): any
beforeDestroyAll(mapper: Mapper, query: IDict, opts: IDict): any
beforeFind(mapper: Mapper, id: string | number, opts: IDict): any
beforeFindAll(mapper: Mapper, query: IDict, opts: IDict): any
beforeSum(mapper: Mapper, field: string, query: IDict, opts: IDict): any
beforeUpdate(mapper: Mapper, id: string | number, props: IDict, opts: IDict): any
beforeUpdateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict): any
beforeUpdateMany(mapper: Mapper, props: IDict[], opts: IDict): any
dbg(...args: any[]): void
count(mapper: Mapper, props: IDict, opts: IDict): any
create(mapper: Mapper, props: IDict, opts: IDict): any
createMany(mapper: Mapper, props: IDict[], opts: IDict): any
destroy(mapper: Mapper, id: string | number, opts: IDict): any
destroyAll(mapper: Mapper, query: IDict, opts: IDict): any
find(mapper: Mapper, id: string | number, opts: IDict): any
findAll(mapper: Mapper, query: IDict, opts: IDict): any
loadBelongsTo(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasMany(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasManyLocalKeys(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasManyForeignKeys(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
loadHasOne(mapper: Mapper, def, IDict, records: IDict | IDict[], __opts: IDict): Promise<any>
log(level: string, ...args: any[]): void
makeBelongsToForeignKey(mapper: Mapper, def: IDict, record: IDict): string
makeHasManyForeignKey(mapper: Mapper, def: IDict, record: IDict): string
makeHasManyLocalKeys(mapper: Mapper, def, IDict, record: IDict): string
makeHasManyForeignKeys(mapper: Mapper, def, IDict, record: IDict): string
sum(mapper: Mapper, field: string, query: IDict, opts: IDict): any
respond(response: Response, opts: IDict): IDict | Response
update(mapper: Mapper, id: string | number, props: IDict, opts: IDict): any
updateAll(mapper: Mapper, props: IDict, query: IDict, opts: IDict): any
updateMany(mapper: Mapper, props: IDict[], opts: IDict): any
}
export function noop(...any): Promise<any>
export function noop2(...any): Promise<any>
export function unique(array: any[]): any[]
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-data-adapter",
"description": "Base adapter class that all other js-data adapters extend.",
"version": "0.4.0",
"version": "0.5.0",
"homepage": "https://github.com/js-data/js-data-adapter",
"repository": {
"type": "git",
Expand All @@ -15,7 +15,8 @@
"dist/",
"src/",
"AUTHORS",
"CONTRIBUTORS"
"CONTRIBUTORS",
"typings.json"
],
"keywords": [
"js-data",
Expand Down
74 changes: 56 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
/**
* Registered as `js-data-adapter` in NPM.
*
* @module js-data-adapter
*/

import {utils} from 'js-data'

const noop = function (...args) {
/**
* @name module:js-data-adapter.noop
*/
export const noop = function (...args) {
const self = this
const opts = args[args.length - 1]
self.dbg(opts.op, ...args)
return utils.resolve()
}

const noop2 = function (...args) {
/**
* @name module:js-data-adapter.noop2
*/
export const noop2 = function (...args) {
const self = this
const opts = args[args.length - 2]
self.dbg(opts.op, ...args)
return utils.resolve()
}

const unique = function (array) {
/**
* @name module:js-data-adapter.unique
*/
export const unique = function (array) {
const seen = {}
const final = []
array.forEach(function (item) {
Expand All @@ -27,7 +42,10 @@ const unique = function (array) {
return final
}

const withoutRelations = function (mapper, props) {
/**
* @name module:js-data-adapter.withoutRelations
*/
export const withoutRelations = function (mapper, props) {
return utils.omit(props, mapper.relationFields || [])
}

Expand All @@ -51,6 +69,12 @@ const DEFAULTS = {
raw: false
}

/**
* {@link Adapter} class.
*
* @name module:js-data-adapter.Adapter
* @see Adapter
*/
/**
* Abstract class meant to be extended by adapters.
*
Expand All @@ -61,14 +85,17 @@ const DEFAULTS = {
* @param {boolean} [opts.raw=false] Whether to return a more detailed response
* object.
*/
function Adapter (opts) {
export function Adapter (opts) {
const self = this
opts || (opts = {})
utils.fillIn(opts, DEFAULTS)
utils.fillIn(self, opts)
}

Adapter.reserved = [
/**
* @name module:js-data-adapter.reserved
*/
export const reserved = [
'orderBy',
'sort',
'limit',
Expand All @@ -77,24 +104,41 @@ Adapter.reserved = [
'where'
]

/**
* {@link Response} class.
*
* @name module:js-data-adapter.Response
* @see Response
*/
/**
* Response object used when `raw` is `true`. May contain other fields in
* addition to `data`.
*
* @typedef {Object} Response
* @property {Object} data Response data.
* @property {string} op The operation for which the response was created.
* @class Response
*/
function Response (data, meta, op) {
export function Response (data, meta, op) {
const self = this
meta || (meta = {})

/**
* Response data.
*
* @name Response#data
* @type {*}
*/
self.data = data

utils.fillIn(self, meta)

/**
* The operation for which the response was created.
*
* @name Response#op
* @type {string}
*/
self.op = op
}

Adapter.Response = Response

/**
* Alternative to ES6 class syntax for extending `Adapter`.
*
Expand All @@ -108,10 +152,6 @@ Adapter.Response = Response
*/
Adapter.extend = utils.extend

Adapter.noop = noop
Adapter.noop2 = noop2
Adapter.unique = unique

utils.addHiddenPropsToTarget(Adapter.prototype, {
/**
* Lifecycle method method called by <a href="#count__anchor">count</a>.
Expand Down Expand Up @@ -1477,5 +1517,3 @@ utils.addHiddenPropsToTarget(Adapter.prototype, {
})
}
})

module.exports = Adapter
2 changes: 1 addition & 1 deletion test/mockAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var Adapter = require('../')
var Adapter = require('../').Adapter
var JSData = require('js-data')
var Collection = JSData.Collection
var utils = JSData.utils
Expand Down
9 changes: 9 additions & 0 deletions typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "js-data-adapter",
"version": false,
"main": "./dist/js-data-adapter.d.ts",
"ambientDependencies": {
"js-data": "npm:js-data",
"es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654"
}
}

0 comments on commit 8a6924d

Please sign in to comment.