1- /*!
2- * js-data-localstorage
3- * @version 2.2.0 - Homepage <http://www.js-data.io/docs/dslocalstorageadapter>
4- * @author Jason Dobry <[email protected] > 5- * @copyright (c) 2014-2015 Jason Dobry
6- * @license MIT <https://github.com/js-data/js-data-localstorage/blob/master/LICENSE>
7- *
8- * @overview localStorage adapter for js-data.
9- */
101( function webpackUniversalModuleDefinition ( root , factory ) {
112 if ( typeof exports === 'object' && typeof module === 'object' )
123 module . exports = factory ( require ( "js-data" ) ) ;
@@ -138,11 +129,13 @@ return /******/ (function(modules) { // webpackBootstrap
138129 _createClass ( DSLocalStorageAdapter , [ {
139130 key : 'getPath' ,
140131 value : function getPath ( resourceConfig , options ) {
132+ options = options || { } ;
141133 return DSUtils . makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . name ) ;
142134 }
143135 } , {
144136 key : 'getIdPath' ,
145137 value : function getIdPath ( resourceConfig , options , id ) {
138+ options = options || { } ;
146139 return DSUtils . makePath ( options . basePath || this . defaults . basePath || resourceConfig . basePath , resourceConfig . endpoint , id ) ;
147140 }
148141 } , {
@@ -168,14 +161,32 @@ return /******/ (function(modules) { // webpackBootstrap
168161 key : 'ensureId' ,
169162 value : function ensureId ( id , resourceConfig , options ) {
170163 var ids = this . getIds ( resourceConfig , options ) ;
171- ids [ id ] = 1 ;
164+ if ( DSUtils . isArray ( id ) ) {
165+ if ( ! id . length ) {
166+ return ;
167+ }
168+ DSUtils . forEach ( id , function ( _id ) {
169+ ids [ _id ] = 1 ;
170+ } ) ;
171+ } else {
172+ ids [ id ] = 1 ;
173+ }
172174 this . saveKeys ( ids , resourceConfig , options ) ;
173175 }
174176 } , {
175177 key : 'removeId' ,
176178 value : function removeId ( id , resourceConfig , options ) {
177179 var ids = this . getIds ( resourceConfig , options ) ;
178- delete ids [ id ] ;
180+ if ( DSUtils . isArray ( id ) ) {
181+ if ( ! id . length ) {
182+ return ;
183+ }
184+ DSUtils . forEach ( id , function ( _id ) {
185+ delete ids [ _id ] ;
186+ } ) ;
187+ } else {
188+ delete ids [ id ] ;
189+ }
179190 this . saveKeys ( ids , resourceConfig , options ) ;
180191 }
181192 } , {
@@ -458,16 +469,36 @@ return /******/ (function(modules) { // webpackBootstrap
458469 } ) ;
459470 } ) ;
460471 }
472+ } , {
473+ key : 'createMany' ,
474+ value : function createMany ( resourceConfig , items , options ) {
475+ var _this7 = this ;
476+
477+ return createTask ( function ( resolve , reject ) {
478+ queueTask ( function ( ) {
479+ var tasks = [ ] ;
480+ var ids = [ ] ;
481+ DSUtils . forEach ( items , function ( attrs ) {
482+ var id = attrs [ resourceConfig . idAttribute ] = attrs [ resourceConfig . idAttribute ] || guid ( ) ;
483+ ids . push ( id ) ;
484+ options = options || { } ;
485+ tasks . push ( _this7 . PUT ( DSUtils . makePath ( _this7 . getIdPath ( resourceConfig , options , id ) ) , DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) ) ;
486+ } ) ;
487+ _this7 . ensureId ( ids , resourceConfig , options ) ;
488+ return DSUtils . Promise . all ( tasks ) . then ( resolve ) . catch ( reject ) ;
489+ } ) ;
490+ } ) ;
491+ }
461492 } , {
462493 key : 'update' ,
463494 value : function update ( resourceConfig , id , attrs , options ) {
464- var _this7 = this ;
495+ var _this8 = this ;
465496
466497 return createTask ( function ( resolve , reject ) {
467498 queueTask ( function ( ) {
468499 options = options || { } ;
469- _this7 . PUT ( _this7 . getIdPath ( resourceConfig , options , id ) , DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) . then ( function ( item ) {
470- _this7 . ensureId ( item [ resourceConfig . idAttribute ] , resourceConfig , options ) ;
500+ _this8 . PUT ( _this8 . getIdPath ( resourceConfig , options , id ) , DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) . then ( function ( item ) {
501+ _this8 . ensureId ( item [ resourceConfig . idAttribute ] , resourceConfig , options ) ;
471502 resolve ( item ) ;
472503 } ) . catch ( reject ) ;
473504 } ) ;
@@ -476,26 +507,26 @@ return /******/ (function(modules) { // webpackBootstrap
476507 } , {
477508 key : 'updateAll' ,
478509 value : function updateAll ( resourceConfig , attrs , params , options ) {
479- var _this8 = this ;
510+ var _this9 = this ;
480511
481512 return this . findAll ( resourceConfig , params , options ) . then ( function ( items ) {
482513 var tasks = [ ] ;
483514 DSUtils . forEach ( items , function ( item ) {
484- return tasks . push ( _this8 . update ( resourceConfig , item [ resourceConfig . idAttribute ] , DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) , options ) ) ;
515+ return tasks . push ( _this9 . update ( resourceConfig , item [ resourceConfig . idAttribute ] , DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) , options ) ) ;
485516 } ) ;
486517 return DSUtils . Promise . all ( tasks ) ;
487518 } ) ;
488519 }
489520 } , {
490521 key : 'destroy' ,
491522 value : function destroy ( resourceConfig , id , options ) {
492- var _this9 = this ;
523+ var _this10 = this ;
493524
494525 return createTask ( function ( resolve , reject ) {
495526 queueTask ( function ( ) {
496527 options = options || { } ;
497- _this9 . DEL ( _this9 . getIdPath ( resourceConfig , options , id ) ) . then ( function ( ) {
498- return _this9 . removeId ( id , resourceConfig . name , options ) ;
528+ _this10 . DEL ( _this10 . getIdPath ( resourceConfig , options , id ) ) . then ( function ( ) {
529+ return _this10 . removeId ( id , resourceConfig , options ) ;
499530 } ) . then ( function ( ) {
500531 return resolve ( null ) ;
501532 } , reject ) ;
@@ -505,14 +536,17 @@ return /******/ (function(modules) { // webpackBootstrap
505536 } , {
506537 key : 'destroyAll' ,
507538 value : function destroyAll ( resourceConfig , params , options ) {
508- var _this10 = this ;
539+ var _this11 = this ;
509540
510541 return this . findAll ( resourceConfig , params , options ) . then ( function ( items ) {
511- var tasks = [ ] ;
542+ var ids = [ ] ;
512543 DSUtils . forEach ( items , function ( item ) {
513- return tasks . push ( _this10 . destroy ( resourceConfig , item [ resourceConfig . idAttribute ] , options ) ) ;
544+ var id = item [ resourceConfig . idAttribute ] ;
545+ ids . push ( id ) ;
546+ _this11 . storage . removeItem ( _this11 . getIdPath ( resourceConfig , options , id ) ) ;
514547 } ) ;
515- return DSUtils . Promise . all ( tasks ) ;
548+ _this11 . removeId ( ids , resourceConfig , options ) ;
549+ return ids ;
516550 } ) ;
517551 }
518552 } ] ) ;
@@ -521,12 +555,12 @@ return /******/ (function(modules) { // webpackBootstrap
521555 } ) ( ) ;
522556
523557 DSLocalStorageAdapter . version = {
524- full : '2.2.0 ' ,
525- major : parseInt ( '2 ' , 10 ) ,
526- minor : parseInt ( '2 ' , 10 ) ,
527- patch : parseInt ( '0 ' , 10 ) ,
528- alpha : true ? 'false ' : false ,
529- beta : true ? 'false ' : false
558+ full : '<%= pkg.version %> ' ,
559+ major : parseInt ( '<%= major %> ' , 10 ) ,
560+ minor : parseInt ( '<%= minor %> ' , 10 ) ,
561+ patch : parseInt ( '<%= patch %> ' , 10 ) ,
562+ alpha : true ? '<%= alpha %> ' : false ,
563+ beta : true ? '<%= beta %> ' : false
530564 } ;
531565
532566 module . exports = DSLocalStorageAdapter ;
0 commit comments