Skip to content

Commit 180dde4

Browse files
committed
- Fix: Ensure return after rejection (in get and count);
- Fix: Better type-checking for bad schema objects; - Fix: Polyfill `newVersion` for PhantomJS - API change (breaking)/Feature: Add `clearUnusedIndexes` option (defaults to `true`); - API change (breaking)/Feature: Destroy and rebuild stores or indexes if present with different options; - API addition: Support a `schemas` object keyed to version with values as `schema` objects. (Utilizes own `IdbImport` class, relying on own fork of `idb-schema` at least for now.); idb-schema callbacks will be passed db.js `Server` as second argument - API addition: Support a `schemaBuilder` callback which accepts an [idb-schema](http://github.com/treojs/idb-schema) object for incremental, versioned schema building and whose `addCallback` method will be passed an enhanced `upgradeneeded` event object with a `Server` object as a second argument for making db.js-style queries (e.g., to modify store content), albeit with certain limitations. Along with `schemas`, addresses issues #84/#109 - API addition: Support a `clearUnusedStores` property to conditionally avoid deleting old stores. - API addition: Add `db.del` alias of `db.delete` - API addition: Add `del()` alias on `Server` for parity with `idb-batch` (likely to use or adapt for multiple change transactions); - Feature: Change schema (and allow for `schemas`) to differentiate between "mixed", "whole", "idb-schema", and "merge" types with `schemaType` option (defaulting to `mixed` for `schema` and `whole` for `schemas`, maintaining prior behavior in backward-compatible manner); - Docs: Update `version` and `schema` to take `schemaBuilder` into account (and document `schemaBuilder`). - Docs: Expand on key behavior examples; - Docs: Indicate that `key` is optional too - Docs: Add mention of missing `limit` on `modify` - Refactoring: Use `const` where possible; - Refactoring: Change variable placement including reordering static variables according to type (built-in alias, IDB, immutables, cache) - Refactoring: Avoid try-catch for brevity if will throw in sync body of Promise (but denote which lines may throw) - Refactoring: simplify transaction building - Refactoring: Add `lang` attribute for Atom linter-jade package; - Code comment: `preventDefault` not only for Firefox. - Code comment: Clarify how old connections may be closed - Testing: Schema building tests - Testing: Add tests for caching - Testing: Add test:local and phantom on package.json scripts - Testing: Fix server-handler test (expect specific error) - Testing: Fix test-worker to deal with multiple babel-polyfill instances - Testing: Remove redundant bad-args test - Testing: Unregister service worker
1 parent 11b4b07 commit 180dde4

25 files changed

Lines changed: 17033 additions & 843 deletions

CHANGES.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# CHANGES
22

3+
## Schema version (unreleased)
4+
5+
- API change (breaking): Will delete unused indexes by default; set a new
6+
property `clearUnusedIndexes` if not desired (when using `schema` or
7+
`whole`-type `schema` objects within `schemas`)
8+
- API addition: Support a `clearUnusedStores` option property to
9+
conditionally avoid deleting old stores (when using `schema` or
10+
`whole`-type `schema` objects within `schemas`).
11+
- API addition: Support a `schemas` object. Its keys are the schema versions
12+
and its values are--if `schemaType` is `"mixed"` (the default, unless
13+
`schema` is used, in which case, it will be treated as `"whole"`)--arrays
14+
containing an object whose single key is the schema type for that version
15+
(either `"idb-schema"`, `"merge"`, or `"whole"`) and whose values are
16+
`schema` objects whose structure differs depending on the schema type.
17+
If `schemaType` is not `"mixed"` (`"whole"`, `"idb-schema"`, or `"merge"`),
18+
each `schemas` key will be a schema version and its value a single
19+
"schema object" (or, in the case of `"idb-schema"`, the function that
20+
will be passed the `IdbSchema` instance). Where an object is expected,
21+
one may also use a function which resolves to a valid object.
22+
- API addition: Support `moveFrom` and `copyFrom` for moving/copying a store
23+
wholesale to another new store.
24+
- API addition: Support a `schemaBuilder` callback which accepts an
25+
[idb-schema](http://github.com/treojs/idb-schema) object for incremental,
26+
versioned schema building and whose `addCallback` method will be
27+
passed an enhanced `upgradeneeded` event object that will be passed a
28+
`Server` object as its second argument for making db.js-style queries
29+
(e.g., to modify store content). This option differs from `schemas` used
30+
with `idb-schema` in that it adds the versions as well as stores and
31+
indexes programmatically. Addresses issues #84/#109
32+
- API addition: If there is an upgrade problem, one can use a `retry` method
33+
on the error event object
34+
- Fix: Add Promise rejection for `update()`.
35+
- Documentation: Update `version` to take `schemaBuilder` into account
36+
(and document `schemaBuilder`).
37+
338
## Unreleased
439

540
- Breaking change: Change `db.cmp()` to return a `Promise` to deliver
@@ -10,23 +45,24 @@
1045
- Deprecated: on `schema.indexes`, in place of the index `key` property,
1146
`keyPath` should be used.
1247
- API fix: Disallow `map` on itself (only one will be used anyways);
13-
- API addition: Add Server aliases, `put` and `delete`.
48+
- API addition: Add Server aliases, `put` and `delete` (or `del`) and `db.del`
49+
as a `db.delete` alias.
1450
- API change: Allow `desc`, `distinct`, `filter`, `keys`, `map`, `modify`
1551
on `limit`;
1652
- API change: Allow `limit` on `distinct`, `desc`, `keys`;
1753
- API change: Allow `{item:...}` without `key` for sake of unambiguity
1854
- API change: Allow `add`/`update` items to be of any value including
1955
`undefined` or `null`
2056
- API change: Allow Mongoifying of `add`/`update`/`remove` keys
21-
- API change: Disallow key in `count()` if null;
57+
- API change: Disallow key in `count()` if `null`;
2258
- Cross-browser support: Auto-wrap user-supplied `Server.error()` and
2359
`Server.addEventListener('error', ...)` handlers with `preventDefault`
2460
so as to avoid hard `ConstraintError` aborts in Firefox.
2561
- Cross-browser support: add `preventDefault` in error listener so that
2662
`onupgradeneeded` errors will not become reported in Firefox (though it
2763
will occur regardless)
2864
- Cross-browser support (minor): wrap `delete` `onblocked` event's
29-
`newVersion` (=null) with `Proxy` but avoid using using `Proxy`
65+
`newVersion` (=`null`) with `Proxy` but avoid using using `Proxy`
3066
if not present for sake of PhantomJS or older browsers (Firefox);
3167
could not wrap `oldVersion`, however.
3268
- Fix: Ensure there is a promise rejection for a bad schema callback,

Gruntfile.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = function (grunt) {
7676
},
7777

7878
eslint: {
79-
target: ['src/db.js', 'src/test-worker.js']
79+
target: ['src/db.js', 'src/test-worker.js', 'src/idb-import']
8080
},
8181

8282
babel: {
@@ -86,7 +86,8 @@ module.exports = function (grunt) {
8686
dist: {
8787
files: {
8888
'dist/db.js': 'src/db.js',
89-
'tests/test-worker.js': 'src/test-worker.js'
89+
'tests/test-worker.js': 'src/test-worker.js',
90+
'dist/idb-import.js': 'src/idb-import.js'
9091
}
9192
}
9293
},
@@ -101,6 +102,11 @@ module.exports = function (grunt) {
101102
standalone: 'db'
102103
}
103104
}
105+
},
106+
dest: {
107+
files: {
108+
'dist/idb-import.js': 'dist/idb-import.js'
109+
}
104110
}
105111
},
106112

@@ -117,6 +123,14 @@ module.exports = function (grunt) {
117123
'dist/db.min.js': ['dist/db.js']
118124
}
119125
},
126+
idbImport: {
127+
options: {
128+
sourceMapIn: 'dist/idb-import.js.map' // input sourcemap from a previous compilation
129+
},
130+
files: {
131+
'dist/idb-import.min.js': ['dist/idb-import.js']
132+
}
133+
},
120134
testworker: {
121135
options: {
122136
sourceMapIn: 'tests/test-worker.js.map' // input sourcemap from a previous compilation

0 commit comments

Comments
 (0)